- indentation fixes

- statistics beautification
This commit is contained in:
Enno Rehling 2006-01-29 14:05:28 +00:00
parent 7819848524
commit 7a3ca3ce5b
3 changed files with 262 additions and 258 deletions

View File

@ -349,7 +349,7 @@ centre(FILE * F, const char *s, boolean breaking)
static void static void
rparagraph(FILE *F, const char *s, int indent, char mark) rparagraph(FILE *F, const char *s, int indent, char mark)
{ {
static const char * spaces = " "; static const char * spaces = " ";
size_t length = REPORTWIDTH - indent; size_t length = REPORTWIDTH - indent;
const char * end = s; const char * end = s;
@ -388,8 +388,8 @@ rparagraph(FILE *F, const char *s, int indent, char mark)
static void static void
report_spell(FILE * F, spell *sp, const struct locale * lang) report_spell(FILE * F, spell *sp, const struct locale * lang)
{ {
int k, itemanz, costtyp; int k, itemanz, costtyp;
int dh = 0; int dh = 0;
char * bufp; char * bufp;
rnl(F); rnl(F);
@ -947,163 +947,166 @@ eval_trail(struct opstack ** stack, const void * userdata) /* (int, int) -> int
static void static void
describe(FILE * F, const region * r, int partial, faction * f) describe(FILE * F, const region * r, int partial, faction * f)
{ {
int n; int n;
boolean dh; boolean dh;
direction_t d; direction_t d;
int trees; int trees;
int ytrees; int ytrees;
attrib *a; attrib *a;
const char *tname; const char *tname;
struct edge { struct edge {
struct edge * next; struct edge * next;
char * name; char * name;
boolean transparent; boolean transparent;
boolean block; boolean block;
boolean exist[MAXDIRECTIONS]; boolean exist[MAXDIRECTIONS];
direction_t lastd; direction_t lastd;
} * edges = NULL, * e; } * edges = NULL, * e;
boolean see[MAXDIRECTIONS]; boolean see[MAXDIRECTIONS];
char * bufp = buf; char * bufp = buf;
for (d = 0; d != MAXDIRECTIONS; d++) { for (d = 0; d != MAXDIRECTIONS; d++) {
/* Nachbarregionen, die gesehen werden, ermitteln */ /* Nachbarregionen, die gesehen werden, ermitteln */
region *r2 = rconnect(r, d); region *r2 = rconnect(r, d);
border *b; border *b;
see[d] = true; see[d] = true;
if (!r2) continue; if (!r2) continue;
for (b=get_borders(r, r2);b;) { for (b=get_borders(r, r2);b;) {
struct edge * e = edges; struct edge * e = edges;
boolean transparent = b->type->transparent(b, f); boolean transparent = b->type->transparent(b, f);
const char * name = b->type->name(b, r, f, GF_DETAILED|GF_ARTICLE); const char * name = b->type->name(b, r, f, GF_DETAILED|GF_ARTICLE);
if (!transparent) see[d] = false; if (!transparent) see[d] = false;
if (!see_border(b, f, r)) { if (!see_border(b, f, r)) {
b = b->next; b = b->next;
continue; continue;
} }
while (e && (e->transparent != transparent || strcmp(name,e->name))) e = e->next; while (e && (e->transparent != transparent || strcmp(name,e->name))) e = e->next;
if (!e) { if (!e) {
e = calloc(sizeof(struct edge), 1); e = calloc(sizeof(struct edge), 1);
e->name = strdup(name); e->name = strdup(name);
e->transparent = transparent; e->transparent = transparent;
e->next = edges; e->next = edges;
edges = e; edges = e;
} }
e->lastd=d; e->lastd=d;
e->exist[d] = true; e->exist[d] = true;
b = b->next; b = b->next;
} }
} }
bufp += f_regionid(r, f, bufp, sizeof(buf)-(bufp-buf)); bufp += f_regionid(r, f, bufp, sizeof(buf)-(bufp-buf));
if (partial == 1) { if (partial == 1) {
bufp += strxcpy(bufp, " (durchgereist)"); bufp += strxcpy(bufp, " (durchgereist)");
} }
else if (partial == 3) { else if (partial == 3) {
bufp += strxcpy(bufp, " (benachbart)"); bufp += strxcpy(bufp, " (benachbart)");
} }
else if (partial == 2) { else if (partial == 2) {
bufp += strxcpy(bufp, " (vom Turm erblickt)"); bufp += strxcpy(bufp, " (vom Turm erblickt)");
} }
/* Terrain */ /* Terrain */
bufp += strxcpy(bufp, ", "); bufp += strxcpy(bufp, ", ");
if(is_cursed(r->attribs,C_MAELSTROM, 0)) if (is_cursed(r->attribs,C_MAELSTROM, 0)) {
tname = "maelstrom"; tname = "maelstrom";
else { } else {
tname = terrain_name(r); tname = terrain_name(r);
} }
bufp += strxcpy(bufp, LOC(f->locale, tname)); bufp += strxcpy(bufp, LOC(f->locale, tname));
/* Bäume */ /* Bäume */
trees = rtrees(r,2); trees = rtrees(r,2);
ytrees = rtrees(r,1); ytrees = rtrees(r,1);
if (production(r)) { if (production(r)) {
if (trees > 0 || ytrees > 0) { if (trees > 0 || ytrees > 0) {
bufp += sprintf(bufp, ", %d/%d ", trees, ytrees); bufp += sprintf(bufp, ", %d/%d ", trees, ytrees);
if (fval(r, RF_MALLORN)) { if (fval(r, RF_MALLORN)) {
if (trees == 1) if (trees == 1) {
bufp += strxcpy(bufp, LOC(f->locale, "nr_mallorntree")); bufp += strxcpy(bufp, LOC(f->locale, "nr_mallorntree"));
else } else {
bufp += strxcpy(bufp, LOC(f->locale, "nr_mallorntree_p")); bufp += strxcpy(bufp, LOC(f->locale, "nr_mallorntree_p"));
} }
else if (trees == 1) }
bufp += strxcpy(bufp, LOC(f->locale, "nr_tree")); else if (trees == 1) {
else bufp += strxcpy(bufp, LOC(f->locale, "nr_tree"));
bufp += strxcpy(bufp, LOC(f->locale, "nr_tree_p")); } else {
} bufp += strxcpy(bufp, LOC(f->locale, "nr_tree_p"));
} }
}
}
/* iron & stone */ /* iron & stone */
if (partial == 0 && f != (faction *) NULL) { if (partial == 0 && f != (faction *) NULL) {
struct rawmaterial * res; struct rawmaterial * res;
for (res=r->resources;res;res=res->next) { for (res=r->resources;res;res=res->next) {
int level = -1; int level = -1;
int visible = -1; int visible = -1;
int maxskill = 0; int maxskill = 0;
const item_type * itype = resource2item(res->type->rtype); const item_type * itype = resource2item(res->type->rtype);
if (res->type->visible==NULL) { if (res->type->visible==NULL) {
visible = res->amount; visible = res->amount;
level = res->level + itype->construction->minskill - 1; level = res->level + itype->construction->minskill - 1;
} else { } else {
const unit * u; const unit * u;
for (u=r->units; visible!=res->amount && u!=NULL; u=u->next) { for (u=r->units; visible!=res->amount && u!=NULL; u=u->next) {
if (u->faction == f) { if (u->faction == f) {
int s = eff_skill(u, itype->construction->skill, r); int s = eff_skill(u, itype->construction->skill, r);
if (s>maxskill) { if (s>maxskill) {
if (s>=itype->construction->minskill) { if (s>=itype->construction->minskill) {
level = res->level + itype->construction->minskill - 1; level = res->level + itype->construction->minskill - 1;
} }
maxskill = s; maxskill = s;
visible = res->type->visible(res, maxskill); visible = res->type->visible(res, maxskill);
} }
} }
} }
} }
if (level>=0 && visible >= 0) { if (level>=0 && visible >= 0) {
bufp += snprintf(bufp, sizeof(buf)-(bufp-buf), ", %d %s/%d", bufp += snprintf(bufp, sizeof(buf)-(bufp-buf), ", %d %s/%d",
visible, LOC(f->locale, res->type->name), visible, LOC(f->locale, res->type->name),
res->level + itype->construction->minskill - 1); res->level + itype->construction->minskill - 1);
} }
} }
} }
/* peasants & silver */ /* peasants & silver */
if (rpeasants(r)) { if (rpeasants(r)) {
int n = rpeasants(r); int n = rpeasants(r);
bufp += sprintf(bufp, ", %d", n); bufp += sprintf(bufp, ", %d", n);
if(fval(r, RF_ORCIFIED)) { if(fval(r, RF_ORCIFIED)) {
strcpy(bufp++, " "); strcpy(bufp++, " ");
bufp += strxcpy(bufp, LOC(f->locale, n==1?"rc_orc":"rc_orc_p")); bufp += strxcpy(bufp, LOC(f->locale, n==1?"rc_orc":"rc_orc_p"));
} else { } else {
strcpy(bufp++, " "); strcpy(bufp++, " ");
bufp += strxcpy(bufp, LOC(f->locale, n==1?"peasant":"peasant_p")); bufp += strxcpy(bufp, LOC(f->locale, n==1?"peasant":"peasant_p"));
} }
if (rmoney(r) && partial == 0) { if (rmoney(r) && partial == 0) {
bufp += sprintf(bufp, ", %d ", rmoney(r)); bufp += sprintf(bufp, ", %d ", rmoney(r));
bufp += strxcpy(bufp, LOC(f->locale, resourcename(oldresourcetype[R_SILVER], rmoney(r)!=1))); bufp += strxcpy(bufp, LOC(f->locale, resourcename(oldresourcetype[R_SILVER], rmoney(r)!=1)));
} }
} }
/* Pferde */ /* Pferde */
if (rhorses(r)) { if (rhorses(r)) {
bufp += sprintf(bufp, ", %d ", rhorses(r)); bufp += sprintf(bufp, ", %d ", rhorses(r));
bufp += strxcpy(bufp, LOC(f->locale, resourcename(oldresourcetype[R_HORSE], (rhorses(r)>1)?GR_PLURAL:0))); bufp += strxcpy(bufp, LOC(f->locale, resourcename(oldresourcetype[R_HORSE], (rhorses(r)>1)?GR_PLURAL:0)));
} }
strcpy(bufp++, "."); strcpy(bufp++, ".");
if (r->display && r->display[0]) { if (r->display && r->display[0]) {
strcpy(bufp++, " "); strcpy(bufp++, " ");
bufp += strxcpy(bufp, r->display); bufp += strxcpy(bufp, r->display);
n = r->display[strlen(r->display) - 1]; n = r->display[strlen(r->display) - 1];
if (n != '!' && n != '?' && n != '.') if (n != '!' && n != '?' && n != '.') {
strcpy(bufp++, "."); strcpy(bufp++, ".");
} }
}
{ {
const faction * owner = region_owner(r); const faction * owner = region_owner(r);
@ -1242,76 +1245,76 @@ describe(FILE * F, const region * r, int partial, faction * f)
static void static void
statistics(FILE * F, const region * r, const faction * f) statistics(FILE * F, const region * r, const faction * f)
{ {
const unit *u; const unit *u;
int number, p; int number, p;
message * m; message * m;
item *itm, *items = NULL; item *itm, *items = NULL;
p = rpeasants(r); p = rpeasants(r);
number = 0; number = 0;
/* zählen */ /* zählen */
for (u = r->units; u; u = u->next) for (u = r->units; u; u = u->next) {
if (u->faction == f && u->race != new_race[RC_SPELL]) { if (u->faction == f && u->race != new_race[RC_SPELL]) {
for (itm=u->items;itm;itm=itm->next) { for (itm=u->items;itm;itm=itm->next) {
i_change(&items, itm->type, itm->number); i_change(&items, itm->type, itm->number);
}
number += u->number;
}
/* Ausgabe */
rnl(F);
m = msg_message("nr_stat_header", "region", r);
nr_render(m, f->locale, buf, sizeof(buf), f);
rps(F, buf);
msg_release(m);
rnl(F);
/* Region */
if (fval(r->terrain, LAND_REGION) && rmoney(r)) {
m = msg_message("nr_stat_maxentertainment", "max", entertainmoney(r));
nr_render(m, f->locale, buf, sizeof(buf), f);
rps(F, buf);
msg_release(m);
}
if (production(r) && (!fval(r->terrain, SEA_REGION) || f->race == new_race[RC_AQUARIAN])) {
m = msg_message("nr_stat_salary", "max", wage(r, f, f->race));
nr_render(m, f->locale, buf, sizeof(buf), f);
rps(F, buf);
msg_release(m);
}
if (p) {
m = msg_message("nr_stat_recruits", "max", p / RECRUITFRACTION);
nr_render(m, f->locale, buf, sizeof(buf), f);
rps(F, buf);
msg_release(m);
if (!TradeDisabled()) {
if (buildingtype_exists(r, bt_find("caravan"))) {
m = msg_message("nr_stat_luxuries", "max",
(p * 2) / TRADE_FRACTION);
} else {
m = msg_message("nr_stat_luxuries", "max",
p / TRADE_FRACTION);
}
nr_render(m, f->locale, buf, sizeof(buf), f);
rps(F, buf);
msg_release(m);
} }
number += u->number;
} }
/* Info über Einheiten */ }
/* Ausgabe */
rnl(F);
m = msg_message("nr_stat_header", "region", r);
nr_render(m, f->locale, buf, sizeof(buf), f);
msg_release(m);
rparagraph(F, buf, 0, 0);
rnl(F);
m = msg_message("nr_stat_people", "max", number); /* Region */
if (fval(r->terrain, LAND_REGION) && rmoney(r)) {
m = msg_message("nr_stat_maxentertainment", "max", entertainmoney(r));
nr_render(m, f->locale, buf, sizeof(buf), f); nr_render(m, f->locale, buf, sizeof(buf), f);
rps(F, buf); rparagraph(F, buf, 2, 0);
msg_release(m);
}
if (production(r) && (!fval(r->terrain, SEA_REGION) || f->race == new_race[RC_AQUARIAN])) {
m = msg_message("nr_stat_salary", "max", wage(r, f, f->race));
nr_render(m, f->locale, buf, sizeof(buf), f);
rparagraph(F, buf, 2, 0);
msg_release(m);
}
if (p) {
m = msg_message("nr_stat_recruits", "max", p / RECRUITFRACTION);
nr_render(m, f->locale, buf, sizeof(buf), f);
rparagraph(F, buf, 2, 0);
msg_release(m); msg_release(m);
for (itm = items; itm; itm=itm->next) { if (!TradeDisabled()) {
sprintf(buf, "%s: %d", if (buildingtype_exists(r, bt_find("caravan"))) {
LOC(f->locale, resourcename(itm->type->rtype, GR_PLURAL)), m = msg_message("nr_stat_luxuries", "max",
itm->number); (p * 2) / TRADE_FRACTION);
rps(F, buf); } else {
m = msg_message("nr_stat_luxuries", "max",
p / TRADE_FRACTION);
}
nr_render(m, f->locale, buf, sizeof(buf), f);
rparagraph(F, buf, 2, 0);
msg_release(m);
} }
while (items) i_free(i_remove(&items, items)); }
/* Info über Einheiten */
m = msg_message("nr_stat_people", "max", number);
nr_render(m, f->locale, buf, sizeof(buf), f);
rparagraph(F, buf, 2, 0);
msg_release(m);
for (itm = items; itm; itm=itm->next) {
sprintf(buf, "%s: %d",
LOC(f->locale, resourcename(itm->type->rtype, GR_PLURAL)),
itm->number);
rparagraph(F, buf, 2, 0);
}
while (items) i_free(i_remove(&items, items));
} }
static void static void
@ -2135,40 +2138,40 @@ report_plaintext(const char * filename, report_context * ctx)
anyunits = 0; anyunits = 0;
for (r=ctx->first;r!=ctx->last;r=r->next) { for (r=ctx->first;r!=ctx->last;r=r->next) {
boolean unit_in_region = false; boolean unit_in_region = false;
boolean durchgezogen_in_region = false; boolean durchgezogen_in_region = false;
int turm_sieht_region = false; int turm_sieht_region = false;
seen_region * sd = find_seen(ctx->seen, r); seen_region * sd = find_seen(ctx->seen, r);
if (sd==NULL) continue; if (sd==NULL) continue;
switch (sd->mode) { switch (sd->mode) {
case see_lighthouse: case see_lighthouse:
turm_sieht_region = true; turm_sieht_region = true;
break; break;
case see_far: case see_far:
break; break;
case see_travel: case see_travel:
durchgezogen_in_region = true; durchgezogen_in_region = true;
break; break;
case see_unit: case see_unit:
unit_in_region = true; unit_in_region = true;
anyunits = true; anyunits = true;
break; break;
default: default:
continue; continue;
} }
r = sd->r; r = sd->r;
/* Beschreibung */ /* Beschreibung */
if (unit_in_region) { if (unit_in_region) {
describe(F, r, 0, f); describe(F, r, 0, f);
if (!TradeDisabled() && !fval(r->terrain, SEA_REGION) && rpeasants(r)/TRADE_FRACTION > 0) { if (!TradeDisabled() && !fval(r->terrain, SEA_REGION) && rpeasants(r)/TRADE_FRACTION > 0) {
rnl(F); rnl(F);
prices(F, r, f); prices(F, r, f);
} }
guards(F, r, f); guards(F, r, f);
durchreisende(F, r, f); durchreisende(F, r, f);
} }
else { else {
if (sd->mode==see_far) { if (sd->mode==see_far) {
describe(F, r, 3, f); describe(F, r, 3, f);

View File

@ -336,10 +336,11 @@ create_mage(unit * u, magic_t mtyp)
sc_mage *mage; sc_mage *mage;
attrib *a; attrib *a;
#ifndef NDEBUG
a = a_find(u->attribs, &at_mage); a = a_find(u->attribs, &at_mage);
assert(a==NULL); if (a!=NULL) {
#endif mage = a->data.v;
assert(mage->spells==NULL && mage->magietyp == mtyp);
}
a = a_add(&u->attribs, a_new(&at_mage)); a = a_add(&u->attribs, a_new(&at_mage));
mage = a->data.v; mage = a->data.v;

View File

@ -464,9 +464,9 @@
<type> <type>
<arg name="max" type="int"/> <arg name="max" type="int"/>
</type> </type>
<text locale="de">"Rekruten: max. $int($max) Bauern."</text> <text locale="de">"Rekruten: max. $int($max) Bauern"</text>
<text locale="en">"Recruits: $int($max) peasants."</text> <text locale="en">"Recruits: $int($max) peasants"</text>
<text locale="fr">"Recruits: $int($max) peasants."</text> <text locale="fr">"Recruits: $int($max) peasants"</text>
</message> </message>
<message name="nr_score" section="nr"> <message name="nr_score" section="nr">
<type> <type>