Bug 2407: do not cache study_cost(SK_MAGIC).

This commit is contained in:
Enno Rehling 2018-01-07 15:26:17 +01:00
parent 8e9ffa2d2b
commit 2cf20dd6e2
2 changed files with 20 additions and 4 deletions

View File

@ -140,7 +140,8 @@ int study_cost(struct unit *u, skill_t sk)
int next_level = 1 + (u ? get_level(u, sk) : 0);
/* Die Magiekosten betragen 50+Summe(50*Stufe) */
/* 'Stufe' ist dabei die naechste zu erreichende Stufe */
cost = 50 * (1 + ((next_level + 1) * next_level / 2));
cost = config_get_int("skills.cost.magic", 50);
return cost * (1 + ((next_level + next_level * next_level) / 2));
}
else switch (sk) {
case SK_SPY:

View File

@ -418,11 +418,26 @@ static void test_study_magic(CuTest *tc) {
}
static void test_study_cost_magic(CuTest *tc) {
unit * u;
const struct item_type *itype;
test_setup();
config_set("skills.cost.magic", "50");
CuAssertIntEquals(tc, 50, study_cost(NULL, SK_MAGIC));
itype = test_create_silver();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
CuAssertIntEquals(tc, 100, study_cost(u, SK_MAGIC));
set_level(u, SK_MAGIC, 1);
CuAssertIntEquals(tc, 200, study_cost(u, SK_MAGIC));
set_level(u, SK_MAGIC, 2);
CuAssertIntEquals(tc, 350, study_cost(u, SK_MAGIC));
set_level(u, SK_MAGIC, 29);
CuAssertIntEquals(tc, 23300, study_cost(u, SK_MAGIC));
set_level(u, SK_MAGIC, 27);
CuAssertIntEquals(tc, 20350, study_cost(u, SK_MAGIC));
config_set("skills.cost.magic", "100");
CuAssertIntEquals(tc, 100, study_cost(NULL, SK_MAGIC));
CuAssertIntEquals(tc, 2*20350, study_cost(u, SK_MAGIC));
test_teardown();
}