eliminate more static variable configuration caching

This commit is contained in:
Enno Rehling 2015-11-21 13:52:47 +01:00
parent 7e27928d17
commit bc936bf019
1 changed files with 43 additions and 75 deletions

View File

@ -110,13 +110,7 @@ int turn = -1;
int NewbieImmunity(void) int NewbieImmunity(void)
{ {
static int value = -1; return get_param_int(global.parameters, "NewbieImmunity", 0);
static int gamecookie = -1;
if (value < 0 || gamecookie != global.cookie) {
gamecookie = global.cookie;
value = get_param_int(global.parameters, "NewbieImmunity", 0);
}
return value;
} }
bool IsImmune(const faction * f) bool IsImmune(const faction * f)
@ -143,13 +137,7 @@ static int ally_flag(const char *s, int help_mask)
bool ExpensiveMigrants(void) bool ExpensiveMigrants(void)
{ {
static int value = -1; return get_param_int(global.parameters, "study.expensivemigrants", 0) != 0;
static int gamecookie = -1;
if (value < 0 || gamecookie != global.cookie) {
gamecookie = global.cookie;
value = get_param_int(global.parameters, "study.expensivemigrants", 0);
}
return value != 0;
} }
/** Specifies automatic alliance modes. /** Specifies automatic alliance modes.
@ -158,11 +146,8 @@ bool ExpensiveMigrants(void)
*/ */
int AllianceAuto(void) int AllianceAuto(void)
{ {
static int value = -1; int value;
static int gamecookie = -1;
if (value < 0 || gamecookie != global.cookie) {
const char *str = get_param(global.parameters, "alliance.auto"); const char *str = get_param(global.parameters, "alliance.auto");
gamecookie = global.cookie;
value = 0; value = 0;
if (str != NULL) { if (str != NULL) {
char *sstr = _strdup(str); char *sstr = _strdup(str);
@ -173,7 +158,6 @@ int AllianceAuto(void)
} }
free(sstr); free(sstr);
} }
}
return value & HelpMask(); return value & HelpMask();
} }
@ -185,12 +169,8 @@ int AllianceAuto(void)
*/ */
int HelpMask(void) int HelpMask(void)
{ {
static int rule = -1;
static int gamecookie = -1;
if (rule < 0 || gamecookie != global.cookie) {
const char *str = get_param(global.parameters, "rules.help.mask"); const char *str = get_param(global.parameters, "rules.help.mask");
gamecookie = global.cookie; int rule = 0;
rule = 0;
if (str != NULL) { if (str != NULL) {
char *sstr = _strdup(str); char *sstr = _strdup(str);
char *tok = strtok(sstr, " "); char *tok = strtok(sstr, " ");
@ -203,18 +183,13 @@ int HelpMask(void)
else { else {
rule = HELP_ALL; rule = HELP_ALL;
} }
}
return rule; return rule;
} }
int AllianceRestricted(void) int AllianceRestricted(void)
{ {
static int rule = -1;
static int gamecookie = -1;
if (rule < 0 || gamecookie != global.cookie) {
const char *str = get_param(global.parameters, "alliance.restricted"); const char *str = get_param(global.parameters, "alliance.restricted");
gamecookie = global.cookie; int rule = 0;
rule = 0;
if (str != NULL) { if (str != NULL) {
char *sstr = _strdup(str); char *sstr = _strdup(str);
char *tok = strtok(sstr, " "); char *tok = strtok(sstr, " ");
@ -225,25 +200,18 @@ int AllianceRestricted(void)
free(sstr); free(sstr);
} }
rule &= HelpMask(); rule &= HelpMask();
}
return rule; return rule;
} }
int LongHunger(const struct unit *u) int LongHunger(const struct unit *u)
{ {
static int gamecookie = -1;
static int rule = -1;
if (u != NULL) { if (u != NULL) {
if (!fval(u, UFL_HUNGER)) if (!fval(u, UFL_HUNGER))
return false; return false;
if (u_race(u) == get_race(RC_DAEMON)) if (u_race(u) == get_race(RC_DAEMON))
return false; return false;
} }
if (rule < 0 || gamecookie != global.cookie) { return get_param_int(global.parameters, "hunger.long", 0);
gamecookie = global.cookie;
rule = get_param_int(global.parameters, "hunger.long", 0);
}
return rule;
} }
int SkillCap(skill_t sk) int SkillCap(skill_t sk)