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