diff --git a/src/kernel/config.c b/src/kernel/config.c index e343b9628..8d90098f5 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -94,7 +94,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include @@ -521,68 +520,6 @@ int alliedunit(const unit * u, const faction * f2, int mode) } return 0; } - -int count_faction(const faction * f, int flags) -{ - unit *u; - int n = 0; - for (u = f->units; u; u = u->nextF) { - const race *rc = u_race(u); - int x = (flags&COUNT_UNITS) ? 1 : u->number; - if (f->race != rc) { - if (!playerrace(rc)) { - if (flags&COUNT_MONSTERS) { - n += x; - } - } - else if (flags&COUNT_MIGRANTS) { - if (!is_cursed(u->attribs, C_SLAVE, 0)) { - n += x; - } - } - } - else if (flags&COUNT_DEFAULT) { - n += x; - } - } - return n; -} - -int count_units(const faction * f) -{ - return count_faction(f, COUNT_ALL | COUNT_UNITS); -} -int count_all(const faction * f) -{ - return count_faction(f, COUNT_ALL); -} -int count_migrants(const faction * f) -{ - return count_faction(f, COUNT_MIGRANTS); -} - -int count_maxmigrants(const faction * f) -{ - static int migrants = -1; - - if (migrants < 0) { - migrants = config_get_int("rules.migrants.max", INT_MAX); - } - if (migrants == INT_MAX) { - int x = 0; - if (f->race == get_race(RC_HUMAN)) { - int nsize = count_all(f); - if (nsize > 0) { - x = (int)(log10(nsize / 50.0) * 20); - if (x < 0) - x = 0; - } - } - return x; - } - return migrants; -} - void parse(keyword_t kword, int(*dofun) (unit *, struct order *), bool thisorder) { diff --git a/src/kernel/config.h b/src/kernel/config.h index b39807a33..14cfa6d2c 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -119,18 +119,6 @@ struct param; #define GIVE_DEFAULT (GIVE_SELF|GIVE_PEASANTS|GIVE_LUXURIES|GIVE_HERBS|GIVE_GOODS) int rule_give(void); -#define COUNT_MONSTERS 0x01 -#define COUNT_MIGRANTS 0x02 -#define COUNT_DEFAULT 0x04 -#define COUNT_ALL 0x07 -#define COUNT_UNITS 0x10 - - int count_faction(const struct faction * f, int flags); - int count_migrants(const struct faction * f); - int count_maxmigrants(const struct faction * f); - int count_all(const struct faction * f); - int count_units(const struct faction * f); - bool has_limited_skills(const struct unit *u); const struct race *findrace(const char *, const struct locale *); diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 28d50ff76..597e45b30 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "alliance.h" #include "ally.h" +#include "curse.h" #include "equipment.h" #include "group.h" #include "item.h" @@ -54,10 +55,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* libc includes */ #include -#include -#include -#include #include +#include +#include +#include +#include faction *factions; @@ -712,3 +714,66 @@ void faction_setorigin(faction * f, int id, int x, int y) addlist(&f->ursprung, ur); } + +int count_faction(const faction * f, int flags) +{ + unit *u; + int n = 0; + for (u = f->units; u; u = u->nextF) { + const race *rc = u_race(u); + int x = (flags&COUNT_UNITS) ? 1 : u->number; + if (f->race != rc) { + if (!playerrace(rc)) { + if (flags&COUNT_MONSTERS) { + n += x; + } + } + else if (flags&COUNT_MIGRANTS) { + if (!is_cursed(u->attribs, C_SLAVE, 0)) { + n += x; + } + } + } + else if (flags&COUNT_DEFAULT) { + n += x; + } + } + return n; +} + +int count_units(const faction * f) +{ + return count_faction(f, COUNT_ALL | COUNT_UNITS); +} + +int count_all(const faction * f) +{ + return count_faction(f, COUNT_ALL); +} + +int count_migrants(const faction * f) +{ + return count_faction(f, COUNT_MIGRANTS); +} + +int count_maxmigrants(const faction * f) +{ + static int migrants = -1; + + if (migrants < 0) { + migrants = config_get_int("rules.migrants.max", INT_MAX); + } + if (migrants == INT_MAX) { + int x = 0; + if (f->race == get_race(RC_HUMAN)) { + int nsize = count_all(f); + if (nsize > 0) { + x = (int)(log10(nsize / 50.0) * 20); + if (x < 0) + x = 0; + } + } + return x; + } + return migrants; +} diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 16b26c5f9..afeef37d3 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -162,6 +162,19 @@ extern "C" { int count_skill(struct faction *f, skill_t sk); bool faction_id_is_unused(int); +#define COUNT_MONSTERS 0x01 +#define COUNT_MIGRANTS 0x02 +#define COUNT_DEFAULT 0x04 +#define COUNT_ALL 0x07 +#define COUNT_UNITS 0x10 + + int count_faction(const struct faction * f, int flags); + int count_migrants(const struct faction * f); + int count_maxmigrants(const struct faction * f); + int count_all(const struct faction * f); + int count_units(const struct faction * f); + + #ifdef __cplusplus } #endif