forked from github/server
eliminate more static variable configuration caching
This commit is contained in:
parent
7e27928d17
commit
bc936bf019
|
@ -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,21 +146,17 @@ bool ExpensiveMigrants(void)
|
||||||
*/
|
*/
|
||||||
int AllianceAuto(void)
|
int AllianceAuto(void)
|
||||||
{
|
{
|
||||||
static int value = -1;
|
int value;
|
||||||
static int gamecookie = -1;
|
const char *str = get_param(global.parameters, "alliance.auto");
|
||||||
if (value < 0 || gamecookie != global.cookie) {
|
value = 0;
|
||||||
const char *str = get_param(global.parameters, "alliance.auto");
|
if (str != NULL) {
|
||||||
gamecookie = global.cookie;
|
char *sstr = _strdup(str);
|
||||||
value = 0;
|
char *tok = strtok(sstr, " ");
|
||||||
if (str != NULL) {
|
while (tok) {
|
||||||
char *sstr = _strdup(str);
|
value |= ally_flag(tok, -1);
|
||||||
char *tok = strtok(sstr, " ");
|
tok = strtok(NULL, " ");
|
||||||
while (tok) {
|
|
||||||
value |= ally_flag(tok, -1);
|
|
||||||
tok = strtok(NULL, " ");
|
|
||||||
}
|
|
||||||
free(sstr);
|
|
||||||
}
|
}
|
||||||
|
free(sstr);
|
||||||
}
|
}
|
||||||
return value & HelpMask();
|
return value & HelpMask();
|
||||||
}
|
}
|
||||||
|
@ -185,65 +169,49 @@ int AllianceAuto(void)
|
||||||
*/
|
*/
|
||||||
int HelpMask(void)
|
int HelpMask(void)
|
||||||
{
|
{
|
||||||
static int rule = -1;
|
const char *str = get_param(global.parameters, "rules.help.mask");
|
||||||
static int gamecookie = -1;
|
int rule = 0;
|
||||||
if (rule < 0 || gamecookie != global.cookie) {
|
if (str != NULL) {
|
||||||
const char *str = get_param(global.parameters, "rules.help.mask");
|
char *sstr = _strdup(str);
|
||||||
gamecookie = global.cookie;
|
char *tok = strtok(sstr, " ");
|
||||||
rule = 0;
|
while (tok) {
|
||||||
if (str != NULL) {
|
rule |= ally_flag(tok, -1);
|
||||||
char *sstr = _strdup(str);
|
tok = strtok(NULL, " ");
|
||||||
char *tok = strtok(sstr, " ");
|
|
||||||
while (tok) {
|
|
||||||
rule |= ally_flag(tok, -1);
|
|
||||||
tok = strtok(NULL, " ");
|
|
||||||
}
|
|
||||||
free(sstr);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
rule = HELP_ALL;
|
|
||||||
}
|
}
|
||||||
|
free(sstr);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rule = HELP_ALL;
|
||||||
}
|
}
|
||||||
return rule;
|
return rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AllianceRestricted(void)
|
int AllianceRestricted(void)
|
||||||
{
|
{
|
||||||
static int rule = -1;
|
const char *str = get_param(global.parameters, "alliance.restricted");
|
||||||
static int gamecookie = -1;
|
int rule = 0;
|
||||||
if (rule < 0 || gamecookie != global.cookie) {
|
if (str != NULL) {
|
||||||
const char *str = get_param(global.parameters, "alliance.restricted");
|
char *sstr = _strdup(str);
|
||||||
gamecookie = global.cookie;
|
char *tok = strtok(sstr, " ");
|
||||||
rule = 0;
|
while (tok) {
|
||||||
if (str != NULL) {
|
rule |= ally_flag(tok, -1);
|
||||||
char *sstr = _strdup(str);
|
tok = strtok(NULL, " ");
|
||||||
char *tok = strtok(sstr, " ");
|
|
||||||
while (tok) {
|
|
||||||
rule |= ally_flag(tok, -1);
|
|
||||||
tok = strtok(NULL, " ");
|
|
||||||
}
|
|
||||||
free(sstr);
|
|
||||||
}
|
}
|
||||||
rule &= HelpMask();
|
free(sstr);
|
||||||
}
|
}
|
||||||
|
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)
|
||||||
|
@ -498,7 +466,7 @@ static int ally_mode(const ally * sf, int mode)
|
||||||
|
|
||||||
int
|
int
|
||||||
alliedgroup(const struct plane *pl, const struct faction *f,
|
alliedgroup(const struct plane *pl, const struct faction *f,
|
||||||
const struct faction *f2, const struct ally *sf, int mode)
|
const struct faction *f2, const struct ally *sf, int mode)
|
||||||
{
|
{
|
||||||
while (sf && sf->faction != f2)
|
while (sf && sf->faction != f2)
|
||||||
sf = sf->next;
|
sf = sf->next;
|
||||||
|
@ -522,7 +490,7 @@ const struct faction *f2, const struct ally *sf, int mode)
|
||||||
|
|
||||||
int
|
int
|
||||||
alliedfaction(const struct plane *pl, const struct faction *f,
|
alliedfaction(const struct plane *pl, const struct faction *f,
|
||||||
const struct faction *f2, int mode)
|
const struct faction *f2, int mode)
|
||||||
{
|
{
|
||||||
return alliedgroup(pl, f, f2, f->allies, mode);
|
return alliedgroup(pl, f, f2, f->allies, mode);
|
||||||
}
|
}
|
||||||
|
@ -1076,7 +1044,7 @@ void free_params(struct param **pp) {
|
||||||
const char *get_param(const struct param *p, const char *key)
|
const char *get_param(const struct param *p, const char *key)
|
||||||
{
|
{
|
||||||
void *match;
|
void *match;
|
||||||
if (p && cb_find_prefix(&p->cb, key, strlen(key)+1, &match, 1, 0) > 0) {
|
if (p && cb_find_prefix(&p->cb, key, strlen(key) + 1, &match, 1, 0) > 0) {
|
||||||
cb_get_kv_ex(match, &match);
|
cb_get_kv_ex(match, &match);
|
||||||
return (const char *)match;
|
return (const char *)match;
|
||||||
}
|
}
|
||||||
|
@ -1345,7 +1313,7 @@ bool rule_stealth_anon(void)
|
||||||
gamecookie = global.cookie;
|
gamecookie = global.cookie;
|
||||||
assert(rule >= 0);
|
assert(rule >= 0);
|
||||||
}
|
}
|
||||||
return rule!=0;
|
return rule != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rule_region_owners(void)
|
bool rule_region_owners(void)
|
||||||
|
@ -1357,7 +1325,7 @@ bool rule_region_owners(void)
|
||||||
gamecookie = global.cookie;
|
gamecookie = global.cookie;
|
||||||
assert(rule >= 0);
|
assert(rule >= 0);
|
||||||
}
|
}
|
||||||
return rule!=0;
|
return rule != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rule_auto_taxation(void)
|
bool rule_auto_taxation(void)
|
||||||
|
@ -1380,7 +1348,7 @@ int rule_blessed_harvest(void)
|
||||||
if (rule < 0 || gamecookie != global.cookie) {
|
if (rule < 0 || gamecookie != global.cookie) {
|
||||||
rule =
|
rule =
|
||||||
get_param_int(global.parameters, "rules.blessed_harvest.flags",
|
get_param_int(global.parameters, "rules.blessed_harvest.flags",
|
||||||
HARVEST_WORK);
|
HARVEST_WORK);
|
||||||
gamecookie = global.cookie;
|
gamecookie = global.cookie;
|
||||||
assert(rule >= 0);
|
assert(rule >= 0);
|
||||||
}
|
}
|
||||||
|
@ -1420,7 +1388,7 @@ bool rule_transfermen(void)
|
||||||
gamecookie = global.cookie;
|
gamecookie = global.cookie;
|
||||||
assert(rule >= 0);
|
assert(rule >= 0);
|
||||||
}
|
}
|
||||||
return rule!=0;
|
return rule != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -1632,7 +1600,7 @@ order *default_order(const struct locale *lang)
|
||||||
order *result = 0;
|
order *result = 0;
|
||||||
assert(i < MAXLOCALES);
|
assert(i < MAXLOCALES);
|
||||||
|
|
||||||
if (default_keyword!=NOKEYWORD) {
|
if (default_keyword != NOKEYWORD) {
|
||||||
return create_order(default_keyword, lang, 0);
|
return create_order(default_keyword, lang, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue