diff --git a/src/alchemy.c b/src/alchemy.c index 86f6e6bb6..5419be4ee 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "alchemy.h" #include "move.h" #include "skill.h" +#include "study.h" #include #include diff --git a/src/economy.c b/src/economy.c index 6311d0c3a..2156744b0 100644 --- a/src/economy.c +++ b/src/economy.c @@ -28,6 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "laws.h" #include "randenc.h" #include "spy.h" +#include "study.h" #include "move.h" #include "monster.h" #include "morale.h" diff --git a/src/kernel/build.c b/src/kernel/build.c index 98ca2b28e..3d4fb6a17 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -23,6 +23,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "alchemy.h" #include "direction.h" #include "move.h" +#include "study.h" #include "laws.h" #include "skill.h" #include "lighthouse.h" diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 5fc797e25..411c460e7 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -28,7 +28,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "curse.h" #include "item.h" #include "move.h" -#include "monster.h" #include "order.h" #include "plane.h" #include "race.h" @@ -1892,25 +1891,6 @@ bool unit_can_study(const unit *u) { return !((u_race(u)->flags & RCF_NOLEARN) || fval(u, UFL_WERE)); } -static double produceexp_chance(void) { - return config_get_flt("study.from_use", 1.0 / 3); -} - -void produceexp_ex(struct unit *u, skill_t sk, int n, bool(*learn)(unit *, skill_t, double)) -{ - 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); - } - } -} - -void produceexp(struct unit *u, skill_t sk, int n) -{ - produceexp_ex(u, sk, n, learn_skill); -} - /* ID's für Einheiten und Zauber */ int newunitid(void) { diff --git a/src/kernel/unit.h b/src/kernel/unit.h index 36abb1cf3..835b5264b 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -162,9 +162,6 @@ extern "C" { struct skill *unit_skill(const struct unit *u, skill_t id); bool has_skill(const unit * u, skill_t sk); int effskill(const struct unit *u, skill_t sk, const struct region *r); - int SkillCap(skill_t sk); - void produceexp(struct unit *u, skill_t sk, int n); - void produceexp_ex(struct unit *u, skill_t sk, int n, bool (*learn)(unit *, skill_t, double)); void set_level(struct unit *u, skill_t id, int level); int get_level(const struct unit *u, skill_t id); diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index 474d839ee..807a27327 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -341,32 +341,6 @@ static void test_age_familiar(CuTest *tc) { test_cleanup(); } -static CuTest *g_tc; - -static bool cb_learn_one(unit *u, skill_t sk, double chance) { - CuAssertIntEquals(g_tc, SK_ALCHEMY, sk); - CuAssertDblEquals(g_tc, 0.5 / u->number, chance, 0.01); - return false; -} - -static bool cb_learn_two(unit *u, skill_t sk, double chance) { - CuAssertIntEquals(g_tc, SK_ALCHEMY, sk); - CuAssertDblEquals(g_tc, 2 * 0.5 / u->number, chance, 0.01); - return false; -} - -static void test_produceexp(CuTest *tc) { - unit *u; - - 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"); - produceexp_ex(u, SK_ALCHEMY, 1, cb_learn_one); - produceexp_ex(u, SK_ALCHEMY, 2, cb_learn_two); - test_cleanup(); -} - static void test_inside_building(CuTest *tc) { unit *u; building *b; @@ -433,7 +407,6 @@ CuSuite *get_unit_suite(void) SUITE_ADD_TEST(suite, test_skill_familiar); SUITE_ADD_TEST(suite, test_age_familiar); SUITE_ADD_TEST(suite, test_inside_building); - SUITE_ADD_TEST(suite, test_produceexp); SUITE_ADD_TEST(suite, test_limited_skills); return suite; } diff --git a/src/magic.c b/src/magic.c index e7d94ac25..d24612e06 100644 --- a/src/magic.c +++ b/src/magic.c @@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "magic.h" #include "skill.h" +#include "study.h" #include "laws.h" #include diff --git a/src/monsters.c b/src/monsters.c index 634c6db54..40f42f2f1 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -26,6 +26,7 @@ #include "monster.h" #include "laws.h" #include "keyword.h" +#include "study.h" /* triggers includes */ #include diff --git a/src/monsters.test.c b/src/monsters.test.c index 9fce059f2..c619ecf2a 100644 --- a/src/monsters.test.c +++ b/src/monsters.test.c @@ -13,6 +13,7 @@ #include "monster.h" #include "guard.h" #include "skill.h" +#include "study.h" #include diff --git a/src/move.c b/src/move.c index 456610866..e602b073c 100644 --- a/src/move.c +++ b/src/move.c @@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "move.h" #include "laws.h" #include "reports.h" +#include "study.h" #include "alchemy.h" #include "travelthru.h" #include "vortex.h" diff --git a/src/spy.c b/src/spy.c index e25ff1e85..9b8fe4601 100644 --- a/src/spy.c +++ b/src/spy.c @@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "laws.h" #include "move.h" #include "reports.h" +#include "study.h" /* kernel includes */ #include diff --git a/src/study.c b/src/study.c index 9335519a6..b7ea62786 100644 --- a/src/study.c +++ b/src/study.c @@ -23,6 +23,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "study.h" #include "move.h" +#include "monster.h" #include "alchemy.h" #include @@ -804,3 +805,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); +} + +void produceexp_ex(struct unit *u, skill_t sk, int n, bool(*learn)(unit *, skill_t, double)) +{ + 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); + } + } +} + +void produceexp(struct unit *u, skill_t sk, int n) +{ + produceexp_ex(u, sk, n, learn_skill); +} diff --git a/src/study.h b/src/study.h index 1feb55921..859080b60 100644 --- a/src/study.h +++ b/src/study.h @@ -26,13 +26,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif - extern int teach_cmd(struct unit *u, struct order *ord); - extern int study_cmd(struct unit *u, struct order *ord); + int teach_cmd(struct unit *u, struct order *ord); + int study_cmd(struct unit *u, struct order *ord); - extern magic_t getmagicskill(const struct locale *lang); - extern bool is_migrant(struct unit *u); - extern int study_cost(struct unit *u, skill_t talent); + magic_t getmagicskill(const struct locale *lang); + bool is_migrant(struct unit *u); + int study_cost(struct unit *u, skill_t talent); + 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)); #define MAXTEACHERS 20 typedef struct teaching_info { struct unit *teachers[MAXTEACHERS]; diff --git a/src/study.test.c b/src/study.test.c index babfc8859..e79a35412 100644 --- a/src/study.test.c +++ b/src/study.test.c @@ -136,12 +136,39 @@ static void test_study_bug_2194(CuTest *tc) { test_cleanup(); } +static CuTest *g_tc; + +static bool cb_learn_one(unit *u, skill_t sk, double chance) { + CuAssertIntEquals(g_tc, SK_ALCHEMY, sk); + CuAssertDblEquals(g_tc, 0.5 / u->number, chance, 0.01); + return false; +} + +static bool cb_learn_two(unit *u, skill_t sk, double chance) { + CuAssertIntEquals(g_tc, SK_ALCHEMY, sk); + CuAssertDblEquals(g_tc, 2 * 0.5 / u->number, chance, 0.01); + return false; +} + +static void test_produceexp(CuTest *tc) { + unit *u; + + 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"); + produceexp_ex(u, SK_ALCHEMY, 1, cb_learn_one); + produceexp_ex(u, SK_ALCHEMY, 2, cb_learn_two); + test_cleanup(); +} + CuSuite *get_study_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_study_no_teacher); SUITE_ADD_TEST(suite, test_study_with_teacher); SUITE_ADD_TEST(suite, test_study_with_bad_teacher); + SUITE_ADD_TEST(suite, test_produceexp); DISABLE_TEST(suite, test_study_bug_2194); return suite; }