remove deprecated learn_skill function and configuration

This commit is contained in:
Enno Rehling 2016-03-24 22:31:07 +01:00
parent f55168e7de
commit 547532bc63
5 changed files with 17 additions and 45 deletions

View File

@ -49,7 +49,7 @@
"recruit.allow_merge": true,
"study.expensivemigrants": true,
"study.speedup": 2,
"study.from_use": 0.4,
"study.produceexp": 12,
"world.era": 3,
"rules.reserve.twophase": true,
"rules.owners.force_leave": false,

View File

@ -212,7 +212,7 @@ static void test_monsters_learn_exp(CuTest * tc)
skill* sk;
create_monsters(&f, &f2, &u, &m);
config_set("study.from_use", "1");
config_set("study.produceexp", "30");
u_setrace(u, u_race(m));
produceexp(u, SK_MELEE, u->number);

View File

@ -790,23 +790,22 @@ int study_cmd(unit * u, order * ord)
return 0;
}
static double produceexp_chance(void) {
return config_get_flt("study.from_use", 1.0 / 3);
static int produceexp_days(void) {
return config_get_int("study.produceexp", 10);
}
void produceexp_ex(struct unit *u, skill_t sk, int n, bool(*learn)(unit *, skill_t, double))
void produceexp_ex(struct unit *u, skill_t sk, int n, learn_fun learn)
{
if (n != 0 && (is_monsters(u->faction) || playerrace(u_race(u)))) {
double chance = produceexp_chance();
if (chance > 0.0F) {
learn(u, sk, (n * chance) / u->number);
}
assert(u && n <= u->number);
if (n > 0 && (is_monsters(u->faction) || playerrace(u_race(u)))) {
int days = produceexp_days();
learn(u, sk, days * n / u->number);
}
}
void produceexp(struct unit *u, skill_t sk, int n)
{
produceexp_ex(u, sk, n, learn_skill_depr);
produceexp_ex(u, sk, n, learn_skill);
}
#ifndef NO_TESTS
@ -816,31 +815,6 @@ void inject_learn(learn_fun fun) {
inject_learn_fun = fun;
}
#endif
bool learn_skill_depr(unit * u, skill_t sk, double learn_chance)
{
skill *sv = u->skills;
if (learn_chance < 1.0 && rng_int() % 10000 >= learn_chance * 10000)
if (!chance(learn_chance)) // FIXME: this nested if looks as if we are rolling twice!
return false;
while (sv != u->skills + u->skill_size) {
assert(sv->weeks > 0);
if (sv->id == sk) {
if (sv->weeks <= 1) {
sk_set(sv, sv->level + 1);
}
else {
sv->weeks--;
}
return true;
}
++sv;
}
sv = add_skill(u, sk);
sk_set(sv, 1);
return true;
}
void learn_skill(unit *u, skill_t sk, int days) {
int leveldays = STUDYDAYS * u->number;
int weeks = 0;

View File

@ -41,11 +41,10 @@ extern "C" {
#endif
#define STUDYDAYS 30
bool learn_skill_depr(struct unit *u, skill_t sk, double chance);
void learn_skill(struct unit *u, skill_t sk, int days);
void produceexp(struct unit *u, skill_t sk, int n);
void produceexp_ex(struct unit *u, skill_t sk, int n, bool(*learn)(struct unit *, skill_t, double));
void produceexp_ex(struct unit *u, skill_t sk, int n, learn_fun learn);
void demon_skillchange(struct unit *u);

View File

@ -141,16 +141,14 @@ static void test_study_bug_2194(CuTest *tc) {
static CuTest *g_tc;
static bool cb_learn_one(unit *u, skill_t sk, double chance) {
static void cb_learn_one(unit *u, skill_t sk, int days) {
CuAssertIntEquals(g_tc, SK_ALCHEMY, sk);
CuAssertDblEquals(g_tc, 0.5 / u->number, chance, 0.01);
return false;
CuAssertIntEquals(g_tc, 10, days);
}
static bool cb_learn_two(unit *u, skill_t sk, double chance) {
static void cb_learn_two(unit *u, skill_t sk, int days) {
CuAssertIntEquals(g_tc, SK_ALCHEMY, sk);
CuAssertDblEquals(g_tc, 2 * 0.5 / u->number, chance, 0.01);
return false;
CuAssertIntEquals(g_tc, 20, days);
}
static void test_produceexp(CuTest *tc) {
@ -159,7 +157,8 @@ static void test_produceexp(CuTest *tc) {
g_tc = tc;
test_cleanup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
config_set("study.from_use", "0.5");
scale_number(u, 2);
config_set("study.produceexp", "20");
produceexp_ex(u, SK_ALCHEMY, 1, cb_learn_one);
produceexp_ex(u, SK_ALCHEMY, 2, cb_learn_two);
test_cleanup();