forked from github/server
fix number of units in the report header
This commit is contained in:
parent
2c4cae4c7e
commit
535a9e6e53
5 changed files with 88 additions and 52 deletions
|
@ -1196,19 +1196,40 @@ void update_lighthouse(building * lh)
|
|||
int count_all(const faction * f)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
int n = 0;
|
||||
unit *u;
|
||||
for (u = f->units; u; u = u->nextF) {
|
||||
if (playerrace(u_race(u))) {
|
||||
n += u->number;
|
||||
assert(f == u->faction);
|
||||
unit *u;
|
||||
int np = 0, n = 0;
|
||||
for (u = f->units; u; u = u->nextF) {
|
||||
assert(f == u->faction);
|
||||
n += u->number;
|
||||
if (playerrace(u_race(u))) {
|
||||
np += u->number;
|
||||
}
|
||||
}
|
||||
if (f->num_people != np) {
|
||||
log_error("# of people in %s is != num_people: %d should be %d.\n", factionid(f), f->num_people, np);
|
||||
}
|
||||
if (f->num_total != n) {
|
||||
log_error("# of men in %s is != num_total: %d should be %d.\n", factionid(f), f->num_total, n);
|
||||
}
|
||||
}
|
||||
if (f->num_people != n) {
|
||||
log_error("# of people in %s is != num_people: %d should be %d.\n", factionid(f), f->num_people, n);
|
||||
}
|
||||
#endif
|
||||
return f->num_people;
|
||||
return (f->flags & FFL_NPC) ? f->num_total : f->num_people;
|
||||
}
|
||||
|
||||
int count_units(const faction * f)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
unit *u;
|
||||
int n = 0, np = 0;
|
||||
for (u = f->units; u; u = u->nextF) {
|
||||
++n;
|
||||
if (playerrace(u_race(u))) ++np;
|
||||
}
|
||||
n = (f->flags & FFL_NPC) ? n : np;
|
||||
if (f->no_units && n != f->no_units) {
|
||||
log_warning("# of units in %s is != no_units: %d should be %d.\n", factionid(f), f->no_units, n);
|
||||
}
|
||||
#endif
|
||||
return n;
|
||||
}
|
||||
|
||||
int count_migrants(const faction * f)
|
||||
|
|
|
@ -256,9 +256,10 @@ extern "C" {
|
|||
extern int rule_alliance_limit(void);
|
||||
extern int rule_faction_limit(void);
|
||||
|
||||
extern int count_all(const struct faction *f);
|
||||
extern int count_migrants(const struct faction *f);
|
||||
extern int count_maxmigrants(const struct faction *f);
|
||||
int count_units(const struct faction * f);
|
||||
int count_all(const struct faction *f);
|
||||
int count_migrants(const struct faction *f);
|
||||
int count_maxmigrants(const struct faction *f);
|
||||
|
||||
extern bool has_limited_skills(const struct unit *u);
|
||||
extern const struct race *findrace(const char *, const struct locale *);
|
||||
|
@ -449,7 +450,7 @@ extern "C" {
|
|||
extern struct attrib_type at_guard;
|
||||
extern void free_gamedata(void);
|
||||
#if 1 /* disable to count all units */
|
||||
# define count_unit(u) playerrace(u_race(u))
|
||||
# define count_unit(u) (u->number>0 && playerrace(u_race(u)))
|
||||
#else
|
||||
# define count_unit(u) 1
|
||||
#endif
|
||||
|
|
|
@ -112,7 +112,7 @@ faction *get_monsters(void)
|
|||
if (!monsters) {
|
||||
faction *f;
|
||||
for (f = factions; f; f = f->next) {
|
||||
if (f->flags & FFL_NPC) {
|
||||
if ((f->flags & FFL_NPC) && !(f->flags & FFL_DEFENDER)) {
|
||||
return monsters = f;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1070,43 +1070,51 @@ struct building *inside_building(const struct unit *u)
|
|||
|
||||
void u_setfaction(unit * u, faction * f)
|
||||
{
|
||||
int cnt = u->number;
|
||||
int cnt = u->number;
|
||||
if (u->faction == f)
|
||||
return;
|
||||
if (u->faction) {
|
||||
if (count_unit(u)) {
|
||||
--u->faction->no_units;
|
||||
}
|
||||
set_number(u, 0);
|
||||
join_group(u, NULL);
|
||||
free_orders(&u->orders);
|
||||
set_order(&u->thisorder, NULL);
|
||||
|
||||
if (u->faction == f)
|
||||
return;
|
||||
if (u->faction) {
|
||||
set_number(u, 0);
|
||||
if (count_unit(u))
|
||||
--u->faction->no_units;
|
||||
join_group(u, NULL);
|
||||
free_orders(&u->orders);
|
||||
set_order(&u->thisorder, NULL);
|
||||
if (u->nextF) {
|
||||
u->nextF->prevF = u->prevF;
|
||||
}
|
||||
if (u->prevF) {
|
||||
u->prevF->nextF = u->nextF;
|
||||
}
|
||||
else {
|
||||
u->faction->units = u->nextF;
|
||||
}
|
||||
}
|
||||
|
||||
if (u->nextF)
|
||||
u->nextF->prevF = u->prevF;
|
||||
if (u->prevF)
|
||||
u->prevF->nextF = u->nextF;
|
||||
else
|
||||
u->faction->units = u->nextF;
|
||||
}
|
||||
if (f != NULL) {
|
||||
if (f->units) {
|
||||
f->units->prevF = u;
|
||||
}
|
||||
u->prevF = NULL;
|
||||
u->nextF = f->units;
|
||||
f->units = u;
|
||||
}
|
||||
else {
|
||||
u->nextF = NULL;
|
||||
}
|
||||
|
||||
if (f != NULL) {
|
||||
if (f->units)
|
||||
f->units->prevF = u;
|
||||
u->prevF = NULL;
|
||||
u->nextF = f->units;
|
||||
f->units = u;
|
||||
} else
|
||||
u->nextF = NULL;
|
||||
|
||||
u->faction = f;
|
||||
if (u->region)
|
||||
update_interval(f, u->region);
|
||||
if (cnt && f) {
|
||||
set_number(u, cnt);
|
||||
if (count_unit(u))
|
||||
++f->no_units;
|
||||
}
|
||||
u->faction = f;
|
||||
if (u->region) {
|
||||
update_interval(f, u->region);
|
||||
}
|
||||
if (cnt) {
|
||||
set_number(u, cnt);
|
||||
}
|
||||
if (f && count_unit(u)) {
|
||||
++f->no_units;
|
||||
}
|
||||
}
|
||||
|
||||
/* vorsicht Sprüche können u->number == RS_FARVISION haben! */
|
||||
|
|
10
src/report.c
10
src/report.c
|
@ -2199,8 +2199,14 @@ report_plaintext(const char *filename, report_context * ctx,
|
|||
f->num_people = no_people;
|
||||
}
|
||||
#else
|
||||
no_units = f->no_units;
|
||||
no_people = f->num_people;
|
||||
no_units = count_units(f);
|
||||
no_people = count_all(f);
|
||||
if (f->flags & FFL_NPC) {
|
||||
no_people = f->num_total;
|
||||
}
|
||||
else {
|
||||
no_people = f->num_people;
|
||||
}
|
||||
#endif
|
||||
m = msg_message("nr_population", "population units", no_people, no_units);
|
||||
nr_render(m, f->locale, buf, sizeof(buf), f);
|
||||
|
|
Loading…
Reference in a new issue