add some more local caching.

This commit is contained in:
Enno Rehling 2016-09-11 12:48:00 +02:00
parent f75be76ee1
commit 86ef225ccb
8 changed files with 31 additions and 12 deletions

View File

@ -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"),

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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.

View File

@ -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);

View File

@ -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();
}

View File

@ -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;