clean up config.c, remove static configuration caching

This commit is contained in:
Enno Rehling 2015-11-21 18:13:16 +01:00
parent bc936bf019
commit 990fda6234
6 changed files with 33 additions and 93 deletions

View File

@ -3134,6 +3134,12 @@ static void peasant_taxes(region * r)
} }
} }
static bool rule_auto_taxation(void)
{
int rule = get_param_int(global.parameters, "rules.economy.taxation", 0);
return rule != 0;
}
void produce(struct region *r) void produce(struct region *r)
{ {
request workers[MAX_WORKERS]; request workers[MAX_WORKERS];

View File

@ -233,6 +233,12 @@ static bool can_give_men(const unit *u, order *ord, message **msg) {
return false; return false;
} }
static bool rule_transfermen(void)
{
int rule = get_param_int(global.parameters, "rules.transfermen", 1);
return rule != 0;
}
message * give_men(int n, unit * u, unit * u2, struct order *ord) message * give_men(int n, unit * u, unit * u2, struct order *ord)
{ {
ship *sh; ship *sh;

View File

@ -216,26 +216,13 @@ int LongHunger(const struct unit *u)
int SkillCap(skill_t sk) int SkillCap(skill_t sk)
{ {
static int gamecookie = -1; if (sk == SK_MAGIC) return 0; /* no caps on magic */
static int rule = -1; return get_param_int(global.parameters, "skill.maxlevel", 0);
if (sk == SK_MAGIC)
return 0; /* no caps on magic */
if (rule < 0 || gamecookie != global.cookie) {
gamecookie = global.cookie;
rule = get_param_int(global.parameters, "skill.maxlevel", 0);
}
return rule;
} }
int NMRTimeout(void) int NMRTimeout(void)
{ {
static int gamecookie = -1; return get_param_int(global.parameters, "nmr.timeout", 0);
static int rule = -1;
if (rule < 0 || gamecookie != global.cookie) {
gamecookie = global.cookie;
rule = get_param_int(global.parameters, "nmr.timeout", 0);
}
return rule;
} }
race_t old_race(const struct race * rc) race_t old_race(const struct race * rc)
@ -1294,103 +1281,44 @@ int cmp_current_owner(const building * b, const building * a)
bool rule_stealth_other(void) bool rule_stealth_other(void)
{ {
static int gamecookie = -1; int rule = get_param_int(global.parameters, "stealth.faction.other", 1);
static int rule = -1;
if (rule < 0 || gamecookie != global.cookie) {
rule = get_param_int(global.parameters, "stealth.faction.other", 1);
gamecookie = global.cookie;
assert(rule >= 0);
}
return rule != 0; return rule != 0;
} }
bool rule_stealth_anon(void) bool rule_stealth_anon(void)
{ {
static int gamecookie = -1; int rule = get_param_int(global.parameters, "stealth.faction.anon", 1);
static int rule = -1;
if (rule < 0 || gamecookie != global.cookie) {
rule = get_param_int(global.parameters, "stealth.faction.anon", 1);
gamecookie = global.cookie;
assert(rule >= 0);
}
return rule != 0; return rule != 0;
} }
bool rule_region_owners(void) bool rule_region_owners(void)
{ {
static int gamecookie = -1; int rule = get_param_int(global.parameters, "rules.region_owners", 0);
static int rule = -1;
if (rule < 0 || gamecookie != global.cookie) {
rule = get_param_int(global.parameters, "rules.region_owners", 0);
gamecookie = global.cookie;
assert(rule >= 0);
}
return rule != 0; return rule != 0;
} }
bool rule_auto_taxation(void)
{
static int gamecookie = -1;
static int rule = -1;
if (rule < 0 || gamecookie != global.cookie) {
rule =
get_param_int(global.parameters, "rules.economy.taxation", 0);
gamecookie = global.cookie;
assert(rule >= 0);
}
return rule;
}
int rule_blessed_harvest(void) int rule_blessed_harvest(void)
{ {
static int gamecookie = -1; int rule = get_param_int(global.parameters, "rules.blessed_harvest.flags",
static int rule = -1;
if (rule < 0 || gamecookie != global.cookie) {
rule =
get_param_int(global.parameters, "rules.blessed_harvest.flags",
HARVEST_WORK); HARVEST_WORK);
gamecookie = global.cookie;
assert(rule >= 0); assert(rule >= 0);
}
return rule; return rule;
} }
int rule_alliance_limit(void) int rule_alliance_limit(void)
{ {
static int gamecookie = -1; int rule = get_param_int(global.parameters, "rules.limit.alliance", 0);
static int rule = -1;
if (rule < 0 || gamecookie != global.cookie) {
rule = get_param_int(global.parameters, "rules.limit.alliance", 0);
gamecookie = global.cookie;
assert(rule >= 0); assert(rule >= 0);
}
return rule; return rule;
} }
int rule_faction_limit(void) int rule_faction_limit(void)
{ {
static int gamecookie = -1; int rule = get_param_int(global.parameters, "rules.limit.faction", 0);
static int rule = -1;
if (rule < 0 || gamecookie != global.cookie) {
rule = get_param_int(global.parameters, "rules.limit.faction", 0);
gamecookie = global.cookie;
assert(rule >= 0); assert(rule >= 0);
}
return rule; return rule;
} }
bool rule_transfermen(void)
{
static int gamecookie = -1;
static int rule = -1;
if (rule < 0 || gamecookie != global.cookie) {
rule = get_param_int(global.parameters, "rules.transfermen", 1);
gamecookie = global.cookie;
assert(rule >= 0);
}
return rule != 0;
}
static int static int
default_wage(const region * r, const faction * f, const race * rc, int in_turn) default_wage(const region * r, const faction * f, const race * rc, int in_turn)
{ {

View File

@ -151,7 +151,6 @@ extern "C" {
int cmp_current_owner(const struct building *b, int cmp_current_owner(const struct building *b,
const struct building *bother); const struct building *bother);
bool rule_transfermen(void);
bool rule_region_owners(void); bool rule_region_owners(void);
bool rule_stealth_other(void); // units can pretend to be another faction, TARNE PARTEI <no> bool rule_stealth_other(void); // units can pretend to be another faction, TARNE PARTEI <no>
bool rule_stealth_anon(void); // units can anonymize their faction, TARNE PARTEI [NICHT] bool rule_stealth_anon(void); // units can anonymize their faction, TARNE PARTEI [NICHT]
@ -160,7 +159,6 @@ extern "C" {
#define HARVEST_WORK 0x00 #define HARVEST_WORK 0x00
#define HARVEST_TAXES 0x01 #define HARVEST_TAXES 0x01
int rule_blessed_harvest(void); int rule_blessed_harvest(void);
bool rule_auto_taxation(void);
#define GIVE_SELF 1 #define GIVE_SELF 1
#define GIVE_PEASANTS 2 #define GIVE_PEASANTS 2
#define GIVE_LUXURIES 4 #define GIVE_LUXURIES 4

View File

@ -1366,7 +1366,7 @@ int eff_skill(const unit * u, const skill *sv, const region *r)
if (mlevel > 0) { if (mlevel > 0) {
int skillcap = SkillCap(sv->id); int skillcap = SkillCap(sv->id);
if (skillcap && mlevel > skillcap) { if (skillcap>0 && mlevel > skillcap) {
return skillcap; return skillcap;
} }
return mlevel; return mlevel;

View File

@ -343,7 +343,8 @@ int teach_cmd(unit * u, struct order *ord)
for (student = r->units; teaching && student; student = student->next) { for (student = r->units; teaching && student; student = student->next) {
if (LongHunger(student)) { if (LongHunger(student)) {
continue; continue;
} else if (student->faction == u->faction) { }
else if (student->faction == u->faction) {
if (getkeyword(student->thisorder) == K_STUDY) { if (getkeyword(student->thisorder) == K_STUDY) {
/* Input ist nun von student->thisorder !! */ /* Input ist nun von student->thisorder !! */
init_order(student->thisorder); init_order(student->thisorder);
@ -534,7 +535,7 @@ static double study_speedup(unit * u, skill_t s, study_rule_t rule)
int study_cmd(unit * u, order * ord) int study_cmd(unit * u, order * ord)
{ {
region *r = u->region; region *r = u->region;
int p; int p, cap;
magic_t mtyp; magic_t mtyp;
int l; int l;
int studycost, days; int studycost, days;
@ -569,7 +570,8 @@ int study_cmd(unit * u, order * ord)
cmistake(u, ord, 77, MSG_EVENT); cmistake(u, ord, 77, MSG_EVENT);
return 0; return 0;
} }
if (SkillCap(sk) && SkillCap(sk) <= effskill(u, sk, 0)) { cap = SkillCap(sk);
if (cap > 0 && cap <= effskill(u, sk, 0)) {
cmistake(u, ord, 771, MSG_EVENT); cmistake(u, ord, 771, MSG_EVENT);
return 0; return 0;
} }