diff --git a/src/kernel/config.c b/src/kernel/config.c index 135df78c5..d78362f3c 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -867,21 +867,29 @@ bool rule_stealth_other(void) bool rule_stealth_anon(void) { - int rule = config_get_int("stealth.faction.anon", 1); + static int rule, config; + if (config_changed(&config)) { + rule = config_get_int("stealth.faction.anon", 1); + } return rule != 0; } bool rule_region_owners(void) { - int rule = config_get_int("rules.region_owners", 0); + static int rule, config; + if (config_changed(&config)) { + rule = config_get_int("rules.region_owners", 0); + } return rule != 0; } int rule_blessed_harvest(void) { - int rule = config_get_int("rules.blessed_harvest.flags", - HARVEST_WORK); - assert(rule >= 0); + static int rule, config; + if (config_changed(&config)) { + rule = config_get_int("rules.blessed_harvest.flags", HARVEST_WORK); + assert(rule >= 0); + } return rule; } @@ -1053,7 +1061,12 @@ int entertainmoney(const region * r) int rule_give(void) { - return config_get_int("rules.give.flags", GIVE_DEFAULT); + static int config; + static int rule; + if (config_changed(&config)) { + rule = config_get_int("rules.give.flags", GIVE_DEFAULT); + } + return rule; } bool markets_module(void) diff --git a/src/kernel/config.test.c b/src/kernel/config.test.c index c8fc84a1a..405587443 100644 --- a/src/kernel/config.test.c +++ b/src/kernel/config.test.c @@ -204,6 +204,26 @@ static void test_config_cache(CuTest *tc) { } static void test_rules(CuTest *tc) { + CuAssertIntEquals(tc, HARVEST_WORK, rule_blessed_harvest()); + config_set("rules.blessed_harvest.flags", "15"); + CuAssertIntEquals(tc, 15, rule_blessed_harvest()); + + CuAssertTrue(tc, !rule_region_owners()); + config_set("rules.region_owners", "1"); + CuAssertTrue(tc, rule_region_owners()); + + CuAssertTrue(tc, rule_stealth_anon()); + config_set("stealth.faction.anon", "0"); + CuAssertTrue(tc, !rule_stealth_anon()); + + CuAssertTrue(tc, rule_stealth_other()); + config_set("stealth.faction.other", "0"); + CuAssertTrue(tc, !rule_stealth_other()); + + CuAssertIntEquals(tc, GIVE_DEFAULT, rule_give()); + config_set("rules.give.flags", "15"); + CuAssertIntEquals(tc, 15, rule_give()); + CuAssertIntEquals(tc, 0, rule_alliance_limit()); config_set("rules.limit.alliance", "1"); CuAssertIntEquals(tc, 1, rule_alliance_limit());