From 547532bc63d319fdbb987ce709346d342dc9846e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 24 Mar 2016 22:31:07 +0100 Subject: [PATCH] remove deprecated learn_skill function and configuration --- conf/e4/config.json | 2 +- src/monsters.test.c | 2 +- src/study.c | 42 ++++++++---------------------------------- src/study.h | 3 +-- src/study.test.c | 13 ++++++------- 5 files changed, 17 insertions(+), 45 deletions(-) diff --git a/conf/e4/config.json b/conf/e4/config.json index 12da61937..345558dff 100644 --- a/conf/e4/config.json +++ b/conf/e4/config.json @@ -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, diff --git a/src/monsters.test.c b/src/monsters.test.c index 1ccd1d18d..a7a4d9b18 100644 --- a/src/monsters.test.c +++ b/src/monsters.test.c @@ -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); diff --git a/src/study.c b/src/study.c index c9fccca39..9b3dfc10c 100644 --- a/src/study.c +++ b/src/study.c @@ -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; diff --git a/src/study.h b/src/study.h index f9b0fcdc2..8bc4a7577 100644 --- a/src/study.h +++ b/src/study.h @@ -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); diff --git a/src/study.test.c b/src/study.test.c index ad0dc7721..5859f9aa9 100644 --- a/src/study.test.c +++ b/src/study.test.c @@ -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();