forked from github/server
some more config lookup caching
This commit is contained in:
parent
c606a9ac4d
commit
423e293745
|
@ -133,19 +133,21 @@ attrib_type at_npcfaction = {
|
|||
*/
|
||||
int HelpMask(void)
|
||||
{
|
||||
const char *str = config_get("rules.help.mask");
|
||||
int rule = 0;
|
||||
if (str != NULL) {
|
||||
char *sstr = _strdup(str);
|
||||
char *tok = strtok(sstr, " ");
|
||||
while (tok) {
|
||||
rule |= ally_flag(tok, -1);
|
||||
tok = strtok(NULL, " ");
|
||||
static int config, rule = 0;
|
||||
if (config_changed(&config)) {
|
||||
const char *str = config_get("rules.help.mask");
|
||||
if (str != NULL) {
|
||||
char *sstr = _strdup(str);
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -731,7 +731,7 @@ int create_directories(void) {
|
|||
|
||||
double get_param_flt(const struct param *p, const char *key, double def)
|
||||
{
|
||||
const char *str = get_param(p, key);
|
||||
const char *str = p ? get_param(p, key) : NULL;
|
||||
return str ? atof(str) : def;
|
||||
}
|
||||
|
||||
|
@ -862,7 +862,10 @@ int cmp_current_owner(const building * b, const building * a)
|
|||
|
||||
bool rule_stealth_other(void)
|
||||
{
|
||||
int rule = config_get_int("stealth.faction.other", 1);
|
||||
static int rule, config;
|
||||
if (config_changed(&config)) {
|
||||
rule = config_get_int("stealth.faction.other", 1);
|
||||
}
|
||||
return rule != 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -796,14 +796,26 @@ attrib_type at_maxmagicians = {
|
|||
|
||||
int max_magicians(const faction * f)
|
||||
{
|
||||
int m = config_get_int("rules.maxskills.magic", MAXMAGICIANS);
|
||||
attrib *a;
|
||||
static int rule, config, rc_cache;
|
||||
static const race *rc_elf;
|
||||
int m;
|
||||
|
||||
if ((a = a_find(f->attribs, &at_maxmagicians)) != NULL) {
|
||||
m = a->data.i;
|
||||
if (config_changed(&config)) {
|
||||
rule = config_get_int("rules.maxskills.magic", MAXMAGICIANS);
|
||||
}
|
||||
if (f->race == get_race(RC_ELF))
|
||||
m = rule;
|
||||
if (f->attribs) {
|
||||
attrib *a = a_find(f->attribs, &at_maxmagicians);
|
||||
if (a) {
|
||||
m = a->data.i;
|
||||
}
|
||||
}
|
||||
if (rc_changed(&rc_cache)) {
|
||||
rc_elf = get_race(RC_ELF);
|
||||
}
|
||||
if (f->race == rc_elf) {
|
||||
++m;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
|
|
|
@ -184,9 +184,13 @@ void sk_set(skill * sv, int level)
|
|||
sv->level = level;
|
||||
}
|
||||
|
||||
static int rule_random_progress(void)
|
||||
static bool rule_random_progress(void)
|
||||
{
|
||||
return config_get_int("study.random_progress", 1);
|
||||
static int rule, config;
|
||||
if (config_changed(&config)) {
|
||||
rule = config_get_int("study.random_progress", 1);
|
||||
}
|
||||
return rule != 0;
|
||||
}
|
||||
|
||||
int skill_weeks(int level)
|
||||
|
|
|
@ -883,15 +883,16 @@ void leave_building(unit * u)
|
|||
|
||||
bool can_leave(unit * u)
|
||||
{
|
||||
int rule_leave;
|
||||
static int config;
|
||||
static bool rule_leave;
|
||||
|
||||
if (!u->building) {
|
||||
return true;
|
||||
}
|
||||
|
||||
rule_leave = config_get_int("rules.move.owner_leave", 0);
|
||||
|
||||
if (rule_leave != 0 && u->building && u == building_owner(u->building)) {
|
||||
if (config_changed(&config)) {
|
||||
rule_leave = config_get_int("rules.move.owner_leave", 0) != 0;
|
||||
}
|
||||
if (rule_leave && u->building && u == building_owner(u->building)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -1721,9 +1722,13 @@ int unit_max_hp(const unit * u)
|
|||
{
|
||||
int h;
|
||||
double p;
|
||||
int rule_stamina = config_get_int("rules.stamina", STAMINA_AFFECTS_HP);
|
||||
static int config;
|
||||
static int rule_stamina;
|
||||
h = u_race(u)->hitpoints;
|
||||
|
||||
if (config_changed(&config)) {
|
||||
rule_stamina = config_get_int("rules.stamina", STAMINA_AFFECTS_HP);
|
||||
}
|
||||
if (rule_stamina & 1) {
|
||||
p = pow(effskill(u, SK_STAMINA, u->region) / 2.0, 1.5) * 0.2;
|
||||
h += (int)(h * p + 0.5);
|
||||
|
|
|
@ -225,7 +225,11 @@ static void free_mage(attrib * a)
|
|||
|
||||
bool FactionSpells(void)
|
||||
{
|
||||
return config_get_int("rules.magic.factionlist", 0) != 0;
|
||||
static int config, rule;
|
||||
if (config_changed(&config)) {
|
||||
rule = config_get_int("rules.magic.factionlist", 0);
|
||||
}
|
||||
return rule != 0;
|
||||
}
|
||||
|
||||
void read_spells(struct quicklist **slistp, magic_t mtype,
|
||||
|
|
|
@ -84,7 +84,12 @@ static void give_peasants(unit *u, const item_type *itype, int reduce) {
|
|||
}
|
||||
|
||||
static double random_move_chance(void) {
|
||||
return config_get_flt("rules.monsters.random_move_chance", MOVECHANCE);
|
||||
static double rule;
|
||||
static int config;
|
||||
if (config_changed(&config)) {
|
||||
rule = config_get_flt("rules.monsters.random_move_chance", MOVECHANCE);
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
static void reduce_weight(unit * u)
|
||||
|
|
12
src/study.c
12
src/study.c
|
@ -800,7 +800,11 @@ int study_cmd(unit * u, order * ord)
|
|||
}
|
||||
|
||||
static int produceexp_days(void) {
|
||||
return config_get_int("study.produceexp", 10);
|
||||
static int config, rule;
|
||||
if (config_changed(&config)) {
|
||||
rule = config_get_int("study.produceexp", 10);
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
void produceexp_ex(struct unit *u, skill_t sk, int n, learn_fun learn)
|
||||
|
@ -863,7 +867,11 @@ void demon_skillchange(unit *u)
|
|||
|
||||
if (fval(u, UFL_HUNGER)) {
|
||||
/* hungry demons only go down, never up in skill */
|
||||
int rule_hunger = config_get_int("hunger.demon.skill", 0) != 0;
|
||||
static int config;
|
||||
static bool rule_hunger;
|
||||
if (config_changed(&config)) {
|
||||
rule_hunger = config_get_int("hunger.demon.skill", 0) != 0;
|
||||
}
|
||||
if (rule_hunger) {
|
||||
upchance = 0;
|
||||
downchance = 15;
|
||||
|
|
|
@ -176,8 +176,12 @@ bool is_astral(const region * r)
|
|||
plane *get_astralplane(void)
|
||||
{
|
||||
plane *astralspace = 0;
|
||||
int rule_astralplane = config_get_int("modules.astralspace", 1);
|
||||
|
||||
static int config;
|
||||
static bool rule_astralplane;
|
||||
|
||||
if (config_changed(&config)) {
|
||||
rule_astralplane = config_get_int("modules.astralspace", 1) != 0;
|
||||
}
|
||||
if (!rule_astralplane) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue