- report_building() faster

- indentation cleanup
This commit is contained in:
Enno Rehling 2006-02-20 21:24:09 +00:00
parent b7552f0d06
commit 2ab8cc7564
4 changed files with 197 additions and 196 deletions

View File

@ -4051,7 +4051,6 @@ processorders (void)
puts(" - Neue Nummern"); puts(" - Neue Nummern");
renumber(); renumber();
for (r = regions;r;r=r->next) reorder_owners(r); for (r = regions;r;r=r->next) reorder_owners(r);
puts(" - Attribute altern"); puts(" - Attribute altern");

View File

@ -244,26 +244,26 @@ report_spell(FILE * F, spell *sp, const struct locale * lang)
int dh = 0; int dh = 0;
char * bufp; char * bufp;
rnl(F); rnl(F);
centre(F, spell_name(sp, lang), true); centre(F, spell_name(sp, lang), true);
rnl(F); rnl(F);
rparagraph(F, LOC(lang, "nr_spell_description"), 0, 0, 0); rparagraph(F, LOC(lang, "nr_spell_description"), 0, 0, 0);
rparagraph(F, spell_info(sp, lang), 2, 0, 0); rparagraph(F, spell_info(sp, lang), 2, 0, 0);
bufp = buf; bufp = buf;
bufp += strxcpy(bufp, LOC(lang, "nr_spell_type")); bufp += strxcpy(bufp, LOC(lang, "nr_spell_type"));
*bufp++ = ' '; *bufp++ = ' ';
if (sp->sptyp & PRECOMBATSPELL) { if (sp->sptyp & PRECOMBATSPELL) {
bufp += strxcpy(bufp, "Präkampfzauber"); bufp += strxcpy(bufp, "Präkampfzauber");
} else if (sp->sptyp & COMBATSPELL) { } else if (sp->sptyp & COMBATSPELL) {
bufp += strxcpy(bufp, "Kampfzauber"); bufp += strxcpy(bufp, "Kampfzauber");
} else if (sp->sptyp & POSTCOMBATSPELL) { } else if (sp->sptyp & POSTCOMBATSPELL) {
bufp += strxcpy(bufp, "Postkampfzauber"); bufp += strxcpy(bufp, "Postkampfzauber");
} else { } else {
bufp += strxcpy(bufp, "Normaler Zauber"); bufp += strxcpy(bufp, "Normaler Zauber");
} }
rparagraph(F, buf, 0, 0, 0); rparagraph(F, buf, 0, 0, 0);
sprintf(buf, "%s %d", LOC(lang, "nr_spell_level"), sp->level); sprintf(buf, "%s %d", LOC(lang, "nr_spell_level"), sp->level);
rparagraph(F, buf, 0, 0, 0); rparagraph(F, buf, 0, 0, 0);
@ -546,40 +546,40 @@ rps_nowrap(FILE * F, const char *s)
static void static void
rpunit(FILE * F, const faction * f, const unit * u, int indent, int mode) rpunit(FILE * F, const faction * f, const unit * u, int indent, int mode)
{ {
attrib *a_otherfaction; attrib *a_otherfaction;
char marker; char marker;
int dh; int dh;
boolean isbattle = (boolean)(mode == see_battle); boolean isbattle = (boolean)(mode == see_battle);
if(u->race == new_race[RC_SPELL]) return;
if (u->race == new_race[RC_SPELL]) return;
{ {
rnl(F); rnl(F);
dh = bufunit(f, u, indent, mode); dh = bufunit(f, u, indent, mode);
} }
a_otherfaction = a_find(u->attribs, &at_otherfaction); a_otherfaction = a_find(u->attribs, &at_otherfaction);
if(u->faction == f) { if (u->faction == f) {
marker = '*'; marker = '*';
} else { } else {
if(a_otherfaction && f != u->faction && get_otherfaction(a_otherfaction) == f if (a_otherfaction && f != u->faction && get_otherfaction(a_otherfaction) == f
&& !fval(u, UFL_PARTEITARNUNG)) { && !fval(u, UFL_PARTEITARNUNG)) {
marker = '!'; marker = '!';
} else { } else {
if(dh && !fval(u, UFL_PARTEITARNUNG)) { if (dh && !fval(u, UFL_PARTEITARNUNG)) {
marker = '+'; marker = '+';
} else { } else {
marker = '-'; marker = '-';
} }
} }
} }
rparagraph(F, buf, indent, 0, marker); rparagraph(F, buf, indent, 0, marker);
if(!isbattle){
print_curses(F, f, u, TYP_UNIT, indent);
}
if (!isbattle) {
print_curses(F, f, u, TYP_UNIT, indent);
}
} }
static void static void
@ -1603,18 +1603,18 @@ list_address(FILE * F, const faction * uf, const faction_list * seenfactions)
void void
report_building(FILE *F, const region * r, const building * b, const faction * f, int mode) report_building(FILE *F, const region * r, const building * b, const faction * f, int mode)
{ {
int i; int i;
unit *u; unit *u;
const char * bname; const char * bname;
const struct locale * lang = NULL; const struct locale * lang = NULL;
const building_type * type = b->type; const building_type * type = b->type;
static const struct building_type * bt_illusion; static const struct building_type * bt_illusion;
if (!bt_illusion) bt_illusion = bt_find("illusion"); if (!bt_illusion) bt_illusion = bt_find("illusion");
if (f) lang = f->locale; if (f) lang = f->locale;
sprintf(buf, "%s, %s %d, ", buildingname(b), LOC(f->locale, "nr_size"), sprintf(buf, "%s, %s %d, ", buildingname(b), LOC(f->locale, "nr_size"),
b->size); b->size);
if (b->type==bt_illusion) { if (b->type==bt_illusion) {
attrib * a = a_find(b->attribs, &at_icastle); attrib * a = a_find(b->attribs, &at_icastle);
@ -1635,32 +1635,33 @@ report_building(FILE *F, const region * r, const building * b, const faction * f
} }
} }
if (b->size < type->maxsize) { if (b->size < type->maxsize) {
scat(" (im Bau)"); scat(" (im Bau)");
} }
if (b->besieged > 0 && mode>=see_lighthouse) {
scat(", belagert von ");
icat(b->besieged);
scat(" Personen ");
if (b->besieged >= b->size * SIEGEFACTOR) {
scat("(abgeschnitten)");
} else {
scat("(unvollständig belagert)");
}
}
i = 0;
if (b->display && b->display[0]) {
scat("; ");
scat(b->display);
i = b->display[strlen(b->display) - 1];
}
if (b->besieged > 0 && mode>=see_lighthouse) {
scat(", belagert von ");
icat(b->besieged);
scat(" Personen ");
if (b->besieged >= b->size * SIEGEFACTOR) {
scat("(abgeschnitten)");
} else {
scat("(unvollständig belagert)");
}
}
i = 0;
if (b->display && b->display[0]) {
scat("; ");
scat(b->display);
i = b->display[strlen(b->display) - 1];
}
#ifdef WDW_PYRAMID #ifdef WDW_PYRAMID
if (i != '!' && i != '?' && i != '.') if (i != '!' && i != '?' && i != '.') {
scat(", "); scat(", ");
}
if (b->type == bt_find("pyramid")) { if (b->type == bt_find("pyramid")) {
unit * owner = buildingowner(r, b); unit * owner = buildingowner(r, b);
scat("Größenstufe "); scat("Größenstufe ");
@ -1707,25 +1708,28 @@ report_building(FILE *F, const region * r, const building * b, const faction * f
#else #else
if (i != '!' && i != '?' && i != '.') if (i != '!' && i != '?' && i != '.')
scat("."); scat(".");
#endif #endif
rparagraph(F, buf, 2, 0, 0); rparagraph(F, buf, 2, 0, 0);
if (mode<see_lighthouse) return; if (mode<see_lighthouse) return;
print_curses(F, f, b, TYP_BUILDING, 4); print_curses(F, f, b, TYP_BUILDING, 4);
for (u = r->units; u; u = u->next) for (u = r->units; u; u = u->next) {
if (u->building == b && fval(u, UFL_OWNER)) { if (u->building == b) {
rpunit(F, f, u, 6, mode); assert(fval(u, UFL_OWNER) || !"you must call reorder_owners() first!");
break; rpunit(F, f, u, 6, mode);
} u = u->next;
for (u = r->units; u; u = u->next) break;
if (u->building == b && !fval(u, UFL_OWNER)) }
rpunit(F, f, u, 6, mode); }
for (;u!=NULL && u->building==b;u=u->next) {
rpunit(F, f, u, 6, mode);
}
} }
int int

View File

@ -2947,92 +2947,92 @@ add_income(unit * u, int type, int want, int qty)
void void
reorder_owners(region * r) reorder_owners(region * r)
{ {
unit ** up=&r->units, ** useek; unit ** up=&r->units, ** useek;
building * b=NULL; building * b=NULL;
ship * sh=NULL; ship * sh=NULL;
#ifndef NDEBUG #ifndef NDEBUG
size_t len = listlen(r->units); size_t len = listlen(r->units);
#endif #endif
for (b = r->buildings;b;b=b->next) { for (b = r->buildings;b;b=b->next) {
unit ** ubegin = up; unit ** ubegin = up;
unit ** uend = up; unit ** uend = up;
useek = up;
while (*useek) {
unit * u = *useek;
if (u->building==b) {
unit ** insert;
if (fval(u, UFL_OWNER)) {
unit * nu = *ubegin;
insert = ubegin;
if (nu!=u && nu->building==u->building && fval(nu, UFL_OWNER)) {
log_error(("[reorder_owners] %s hat mehrere Besitzer mit UFL_OWNER.\n", buildingname(nu->building)));
freset(nu, UFL_OWNER);
}
}
else insert = uend;
if (insert != useek) {
*useek = u->next; /* raus aus der liste */
u->next = *insert;
*insert = u;
}
if (insert==uend) uend=&u->next;
}
if (*useek==u) useek = &u->next;
}
up = uend;
}
useek = up; useek=up;
while (*useek) { while (*useek) {
unit * u = *useek; unit * u = *useek;
if (u->building==b) { assert(!u->building);
unit ** insert; if (u->ship==NULL) {
if (fval(u, UFL_OWNER)) { if (fval(u, UFL_OWNER)) {
unit * nu = *ubegin; log_warning(("[reorder_owners] Einheit %s war Besitzer von nichts.\n", unitname(u)));
insert=ubegin; freset(u, UFL_OWNER);
if (nu!=u && nu->building==u->building && fval(nu, UFL_OWNER)) { }
log_error(("[reorder_owners] %s hat mehrere Besitzer mit UFL_OWNER.\n", buildingname(nu->building))); if (useek!=up) {
freset(nu, UFL_OWNER); *useek = u->next; /* raus aus der liste */
} u->next = *up;
} *up = u;
else insert = uend; }
if (insert!=useek) { up = &u->next;
*useek = u->next; /* raus aus der liste */ }
u->next = *insert; if (*useek==u) useek = &u->next;
*insert = u; }
}
if (insert==uend) uend=&u->next; for (sh = r->ships;sh;sh=sh->next) {
} unit ** ubegin = up;
if (*useek==u) useek = &u->next; unit ** uend = up;
}
up = uend; useek = up;
} while (*useek) {
unit * u = *useek;
useek=up; if (u->ship==sh) {
while (*useek) { unit ** insert;
unit * u = *useek; if (fval(u, UFL_OWNER)) {
assert(!u->building); unit * nu = *ubegin;
if (u->ship==NULL) { insert = ubegin;
if (fval(u, UFL_OWNER)) { if (nu!=u && nu->ship==u->ship && fval(nu, UFL_OWNER)) {
log_warning(("[reorder_owners] Einheit %s war Besitzer von nichts.\n", unitname(u))); log_error(("[reorder_owners] %s hat mehrere Besitzer mit UFL_OWNER.\n", shipname(nu->ship)));
freset(u, UFL_OWNER); freset(nu, UFL_OWNER);
} }
if (useek!=up) { }
*useek = u->next; /* raus aus der liste */ else insert = uend;
u->next = *up; if (insert!=useek) {
*up = u; *useek = u->next; /* raus aus der liste */
} u->next = *insert;
up = &u->next; *insert = u;
} }
if (*useek==u) useek = &u->next; if (insert==uend) uend=&u->next;
} }
if (*useek==u) useek = &u->next;
for (sh = r->ships;sh;sh=sh->next) { }
unit ** ubegin = up; up = uend;
unit ** uend = up; }
useek = up;
while (*useek) {
unit * u = *useek;
if (u->ship==sh) {
unit ** insert;
if (fval(u, UFL_OWNER)) {
unit * nu = *ubegin;
insert = ubegin;
if (nu!=u && nu->ship==u->ship && fval(nu, UFL_OWNER)) {
log_error(("[reorder_owners] %s hat mehrere Besitzer mit UFL_OWNER.\n", shipname(nu->ship)));
freset(nu, UFL_OWNER);
}
}
else insert = uend;
if (insert!=useek) {
*useek = u->next; /* raus aus der liste */
u->next = *insert;
*insert = u;
}
if (insert==uend) uend=&u->next;
}
if (*useek==u) useek = &u->next;
}
up = uend;
}
#ifndef NDEBUG #ifndef NDEBUG
assert(len==listlen(r->units)); assert(len==listlen(r->units));
#endif #endif
} }

View File

@ -276,45 +276,43 @@ r_insectstalled(const region * r)
const char * const char *
rc_name(const race * rc, int n) rc_name(const race * rc, int n)
{ {
return mkname("race", rc->_name[n]); return mkname("race", rc->_name[n]);
} }
const char * const char *
raceprefix(const unit *u) raceprefix(const unit *u)
{ {
const attrib * asource = u->faction->attribs; const attrib * asource = u->faction->attribs;
if (fval(u, UFL_GROUP)) { if (fval(u, UFL_GROUP)) {
const attrib * agroup = agroup = a_findc(u->attribs, &at_group); const attrib * agroup = agroup = a_findc(u->attribs, &at_group);
if (agroup!=NULL) asource = ((const group *)(agroup->data.v))->attribs; if (agroup!=NULL) asource = ((const group *)(agroup->data.v))->attribs;
} }
return get_prefix(asource); return get_prefix(asource);
} }
const char * const char *
racename(const struct locale *loc, const unit *u, const race * rc) racename(const struct locale *loc, const unit *u, const race * rc)
{ {
const char * prefix = raceprefix(u); const char * prefix = raceprefix(u);
attrib * asyn = a_find(u->faction->attribs, &at_synonym); attrib * asyn = a_find(u->faction->attribs, &at_synonym);
if (prefix!=NULL) { if (prefix!=NULL) {
static char lbuf[80]; static char lbuf[80];
char * s = lbuf; char * s = lbuf;
strcpy(lbuf, locale_string(loc, mkname("prefix", prefix))); strcpy(lbuf, locale_string(loc, mkname("prefix", prefix)));
s += strlen(lbuf); s += strlen(lbuf);
if (asyn!=NULL) { if (asyn!=NULL) {
strcpy(s, locale_string(loc, strcpy(s, LOC(loc, ((frace_synonyms *)(asyn->data.v))->synonyms[u->number != 1]));
((frace_synonyms *)(asyn->data.v))->synonyms[u->number != 1])); } else {
} else { strcpy(s, LOC(loc, rc_name(rc, u->number != 1)));
strcpy(s, LOC(loc, rc_name(rc, u->number != 1))); }
} s[0] = (char)tolower(s[0]);
s[0] = (char)tolower(s[0]); return lbuf;
return lbuf; } else if (asyn!=NULL) {
} else if (asyn!=NULL) { return(LOC(loc, ((frace_synonyms *)(asyn->data.v))->synonyms[u->number != 1]));
return(locale_string(loc, }
((frace_synonyms *)(asyn->data.v))->synonyms[u->number != 1])); return LOC(loc, rc_name(rc, u->number != 1));
}
return LOC(loc, rc_name(rc, u->number != 1));
} }
static void static void