diff --git a/src/alchemy.c b/src/alchemy.c index 5e369a3e1..cf4dc6f73 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -123,9 +123,14 @@ static void end_potion(unit * u, const potion_type * ptype, int amount) } static int potion_water_of_life(unit * u, region *r, int amount) { + static int config; + static int tree_type, tree_count; int wood = 0; - int tree_type = config_get_int("rules.magic.wol_type", 1); - int tree_count = config_get_int("rules.magic.wol_effect", 10); + + if (config_changed(&config)) { + tree_type = config_get_int("rules.magic.wol_type", 1); + tree_count = config_get_int("rules.magic.wol_effect", 10); + } /* mallorn is required to make mallorn forests, wood for regular ones */ if (fval(r, RF_MALLORN)) { wood = use_pooled(u, rt_find("mallorn"), diff --git a/src/battle.c b/src/battle.c index 3ab117c2a..4686a942a 100644 --- a/src/battle.c +++ b/src/battle.c @@ -141,6 +141,7 @@ static int rule_goblin_bonus; static int rule_tactics_formula; static int rule_nat_armor; static int rule_cavalry_mode; +static int rule_vampire; static const curse_type *peace_ct, *slave_ct, *calm_ct; @@ -159,6 +160,7 @@ static void init_rules(void) rule_anon_battle = config_get_int("rules.stealth.anon_battle", 1) != 0; rule_cavalry_mode = config_get_int("rules.cavalry.mode", 1); rule_cavalry_skill = config_get_int("rules.cavalry.skill", 2); + rule_vampire = config_get_int("rules.combat.demon_vampire", 0); rule_loot = config_get_int("rules.combat.loot", LOOT_MONSTERS | LOOT_OTHERS | LOOT_KEEPLOOT); /* new formula to calculate to-hit-chance */ @@ -1009,11 +1011,10 @@ const char *rel_dam(int dam, int hp) static void vampirism(troop at, int damage) { - int vampire = config_get_int("rules.combat.demon_vampire", 0); - if (vampire > 0) { - int gain = damage / vampire; - int chance = damage - vampire * gain; - if (chance > 0 && (rng_int() % vampire < chance)) + if (rule_vampire > 0) { + int gain = damage / rule_vampire; + int chance = damage - rule_vampire * gain; + if (chance > 0 && (rng_int() % rule_vampire < chance)) ++gain; if (gain > 0) { int maxhp = unit_max_hp(at.fighter->unit); diff --git a/src/kernel/build.c b/src/kernel/build.c index 6bea3e6b4..6bc953241 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -419,8 +419,9 @@ int value) int roqf_factor(void) { - int value = -1; - if (value < 0) { + static int config; + static int value; + if (config_changed(&config)) { value = config_get_int("rules.economy.roqf", 10); } return value; diff --git a/src/kernel/build.test.c b/src/kernel/build.test.c index c0775051e..9ea473725 100644 --- a/src/kernel/build.test.c +++ b/src/kernel/build.test.c @@ -394,10 +394,19 @@ static void test_build_destroy_cmd(CuTest *tc) { test_cleanup(); } +static void test_build_roqf_factor(CuTest *tc) { + test_setup(); + CuAssertIntEquals(tc, 10, roqf_factor()); + config_set("rules.economy.roqf", "50"); + CuAssertIntEquals(tc, 50, roqf_factor()); + test_cleanup(); +} + CuSuite *get_build_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_build_limits); + SUITE_ADD_TEST(suite, test_build_roqf_factor); SUITE_ADD_TEST(suite, test_build_failure_low_skill); SUITE_ADD_TEST(suite, test_build_failure_missing_skill); SUITE_ADD_TEST(suite, test_build_requires_materials); diff --git a/src/kernel/config.c b/src/kernel/config.c index 481a68220..135df78c5 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -1097,6 +1097,7 @@ bool config_token(const char *key, const char *tok) { void free_config(void) { global.functions.wage = NULL; free_params(&configuration); + ++config_cache_key; } /** releases all memory associated with the game state. diff --git a/src/kernel/config.h b/src/kernel/config.h index 8e0bd72e5..74565e25e 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -64,7 +64,6 @@ struct param; int lovar(double xpct_x2); /* returns a value between [0..xpct_2], generated with two dice */ - int distribute(int old, int new_value, int n); void init_locale(struct locale *lang); int forbiddenid(int id); diff --git a/src/kernel/config.test.c b/src/kernel/config.test.c index a5bad30c7..c8fc84a1a 100644 --- a/src/kernel/config.test.c +++ b/src/kernel/config.test.c @@ -198,6 +198,8 @@ static void test_config_cache(CuTest *tc) { config_set("hodor", "0"); CuAssertTrue(tc, config_changed(&key)); CuAssertTrue(tc, !config_changed(&key)); + free_config(); + CuAssertTrue(tc, config_changed(&key)); test_cleanup(); } diff --git a/src/laws.c b/src/laws.c index 197433bfa..19078353e 100755 --- a/src/laws.c +++ b/src/laws.c @@ -776,6 +776,8 @@ void demographics(void) region *r; static int last_weeks_season = -1; static int current_season = -1; + int plant_rules = config_get_int("rules.grow.formula", 2); + const struct building_type *bt_harbour = bt_find("harbour"); if (current_season < 0) { gamedate date; @@ -793,11 +795,10 @@ void demographics(void) /* die Nachfrage nach Produkten steigt. */ struct demand *dmd; if (r->land) { - int plant_rules = config_get_int("rules.grow.formula", 2); for (dmd = r->land->demands; dmd; dmd = dmd->next) { if (dmd->value > 0 && dmd->value < MAXDEMAND) { float rise = DMRISE; - if (buildingtype_exists(r, bt_find("harbour"), true)) + if (buildingtype_exists(r, bt_harbour, true)) rise = DMRISEHAFEN; if (rng_double() < rise) ++dmd->value;