test and cache all the rules!

This commit is contained in:
Enno Rehling 2016-09-11 15:54:03 +02:00
parent 86ef225ccb
commit 49ccb3825f
2 changed files with 39 additions and 6 deletions

View File

@ -867,21 +867,29 @@ bool rule_stealth_other(void)
bool rule_stealth_anon(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; return rule != 0;
} }
bool rule_region_owners(void) 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; return rule != 0;
} }
int rule_blessed_harvest(void) int rule_blessed_harvest(void)
{ {
int rule = config_get_int("rules.blessed_harvest.flags", static int rule, config;
HARVEST_WORK); if (config_changed(&config)) {
assert(rule >= 0); rule = config_get_int("rules.blessed_harvest.flags", HARVEST_WORK);
assert(rule >= 0);
}
return rule; return rule;
} }
@ -1053,7 +1061,12 @@ int entertainmoney(const region * r)
int rule_give(void) 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) bool markets_module(void)

View File

@ -204,6 +204,26 @@ static void test_config_cache(CuTest *tc) {
} }
static void test_rules(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()); CuAssertIntEquals(tc, 0, rule_alliance_limit());
config_set("rules.limit.alliance", "1"); config_set("rules.limit.alliance", "1");
CuAssertIntEquals(tc, 1, rule_alliance_limit()); CuAssertIntEquals(tc, 1, rule_alliance_limit());