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)
|
int count_all(const faction * f)
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
int n = 0;
|
unit *u;
|
||||||
unit *u;
|
int np = 0, n = 0;
|
||||||
for (u = f->units; u; u = u->nextF) {
|
for (u = f->units; u; u = u->nextF) {
|
||||||
if (playerrace(u_race(u))) {
|
assert(f == u->faction);
|
||||||
n += u->number;
|
n += u->number;
|
||||||
assert(f == u->faction);
|
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
|
#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)
|
int count_migrants(const faction * f)
|
||||||
|
|
|
@ -256,9 +256,10 @@ extern "C" {
|
||||||
extern int rule_alliance_limit(void);
|
extern int rule_alliance_limit(void);
|
||||||
extern int rule_faction_limit(void);
|
extern int rule_faction_limit(void);
|
||||||
|
|
||||||
extern int count_all(const struct faction *f);
|
int count_units(const struct faction * f);
|
||||||
extern int count_migrants(const struct faction *f);
|
int count_all(const struct faction *f);
|
||||||
extern int count_maxmigrants(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 bool has_limited_skills(const struct unit *u);
|
||||||
extern const struct race *findrace(const char *, const struct locale *);
|
extern const struct race *findrace(const char *, const struct locale *);
|
||||||
|
@ -449,7 +450,7 @@ extern "C" {
|
||||||
extern struct attrib_type at_guard;
|
extern struct attrib_type at_guard;
|
||||||
extern void free_gamedata(void);
|
extern void free_gamedata(void);
|
||||||
#if 1 /* disable to count all units */
|
#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
|
#else
|
||||||
# define count_unit(u) 1
|
# define count_unit(u) 1
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -112,7 +112,7 @@ faction *get_monsters(void)
|
||||||
if (!monsters) {
|
if (!monsters) {
|
||||||
faction *f;
|
faction *f;
|
||||||
for (f = factions; f; f = f->next) {
|
for (f = factions; f; f = f->next) {
|
||||||
if (f->flags & FFL_NPC) {
|
if ((f->flags & FFL_NPC) && !(f->flags & FFL_DEFENDER)) {
|
||||||
return monsters = f;
|
return monsters = f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1070,43 +1070,51 @@ struct building *inside_building(const struct unit *u)
|
||||||
|
|
||||||
void u_setfaction(unit * u, faction * f)
|
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)
|
if (u->nextF) {
|
||||||
return;
|
u->nextF->prevF = u->prevF;
|
||||||
if (u->faction) {
|
}
|
||||||
set_number(u, 0);
|
if (u->prevF) {
|
||||||
if (count_unit(u))
|
u->prevF->nextF = u->nextF;
|
||||||
--u->faction->no_units;
|
}
|
||||||
join_group(u, NULL);
|
else {
|
||||||
free_orders(&u->orders);
|
u->faction->units = u->nextF;
|
||||||
set_order(&u->thisorder, NULL);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (u->nextF)
|
if (f != NULL) {
|
||||||
u->nextF->prevF = u->prevF;
|
if (f->units) {
|
||||||
if (u->prevF)
|
f->units->prevF = u;
|
||||||
u->prevF->nextF = u->nextF;
|
}
|
||||||
else
|
u->prevF = NULL;
|
||||||
u->faction->units = u->nextF;
|
u->nextF = f->units;
|
||||||
}
|
f->units = u;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
u->nextF = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (f != NULL) {
|
u->faction = f;
|
||||||
if (f->units)
|
if (u->region) {
|
||||||
f->units->prevF = u;
|
update_interval(f, u->region);
|
||||||
u->prevF = NULL;
|
}
|
||||||
u->nextF = f->units;
|
if (cnt) {
|
||||||
f->units = u;
|
set_number(u, cnt);
|
||||||
} else
|
}
|
||||||
u->nextF = NULL;
|
if (f && count_unit(u)) {
|
||||||
|
++f->no_units;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vorsicht Sprüche können u->number == RS_FARVISION haben! */
|
/* 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;
|
f->num_people = no_people;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
no_units = f->no_units;
|
no_units = count_units(f);
|
||||||
no_people = f->num_people;
|
no_people = count_all(f);
|
||||||
|
if (f->flags & FFL_NPC) {
|
||||||
|
no_people = f->num_total;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
no_people = f->num_people;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
m = msg_message("nr_population", "population units", no_people, no_units);
|
m = msg_message("nr_population", "population units", no_people, no_units);
|
||||||
nr_render(m, f->locale, buf, sizeof(buf), f);
|
nr_render(m, f->locale, buf, sizeof(buf), f);
|
||||||
|
|
Loading…
Reference in a new issue