From 2a8013f3f9b085e1a3c2dbf3a4df20ecb9e6942f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 25 Mar 2016 17:05:01 +0100 Subject: [PATCH] fix bug 2194, poorly --- src/study.c | 10 ++++--- src/study.test.c | 70 ++++++++++++++++++++++++++++-------------------- 2 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/study.c b/src/study.c index 9b3dfc10c..f0a27606c 100644 --- a/src/study.c +++ b/src/study.c @@ -280,7 +280,7 @@ int teach_cmd(unit * u, struct order *ord) static const curse_type *gbdream_ct = NULL; plane *pl; region *r = u->region; - skill_t sk = NOSKILL; + skill_t sk_academy = NOSKILL; int teaching, i, j, count, academy = 0; if (gbdream_ct == 0) @@ -322,6 +322,7 @@ int teach_cmd(unit * u, struct order *ord) #if TEACH_ALL if (getparam(u->faction->locale) == P_ANY) { + skill_t sk; unit *student; skill_t teachskill[MAXSKILLS]; int t = 0; @@ -380,6 +381,7 @@ int teach_cmd(unit * u, struct order *ord) init_order(ord); while (!parser_end()) { + skill_t sk; unit *u2; bool feedback; @@ -472,15 +474,15 @@ int teach_cmd(unit * u, struct order *ord) continue; } } - + sk_academy = sk; teaching -= teach_unit(u, u2, teaching, sk, false, &academy); } new_order = create_order(K_TEACH, u->faction->locale, "%s", zOrder); replace_order(&u->orders, ord, new_order); free_order(new_order); /* parse_order & set_order have each increased the refcount */ } - if (academy) { - academy_teaching_bonus(u, sk, academy); + if (academy && sk_academy!=NOSKILL) { + academy_teaching_bonus(u, sk_academy, academy); } return 0; } diff --git a/src/study.test.c b/src/study.test.c index 5859f9aa9..729981145 100644 --- a/src/study.test.c +++ b/src/study.test.c @@ -20,6 +20,34 @@ #include +#define MAXLOG 4 +typedef struct log_entry { + unit *u; + skill_t sk; + int days; +} log_entry; + +static log_entry log_learners[MAXLOG]; +static int log_size; + +static void log_learn(unit *u, skill_t sk, int days) { + if (log_size < MAXLOG) { + log_entry * entry = &log_learners[log_size++]; + entry->u = u; + entry->sk = sk; + entry->days = days; + } +} + +void learn_inject(void) { + log_size = 0; + inject_learn(log_learn); +} + +void learn_reset(void) { + inject_learn(0); +} + typedef struct { unit *u; unit *teachers[2]; @@ -134,8 +162,20 @@ static void test_study_bug_2194(CuTest *tc) { i_change(&u1->items, get_resourcetype(R_SILVER)->itype, 50); i_change(&u2->items, get_resourcetype(R_SILVER)->itype, 50); b->flags = BLD_WORKING; + learn_inject(); teach_cmd(u, u->thisorder); + learn_reset(); + CuAssertPtrEquals(tc, u, log_learners[0].u); + CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk); + CuAssertIntEquals(tc, 1, log_size); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "teach_asgood")); + + free_order(u->thisorder); + u->thisorder = create_order(K_TEACH, loc, itoa36(u2->no)); + learn_inject(); + teach_cmd(u, u->thisorder); + learn_reset(); + CuAssertIntEquals(tc, 0, log_size); test_cleanup(); } @@ -164,34 +204,6 @@ static void test_produceexp(CuTest *tc) { test_cleanup(); } -#define MAXLOG 4 -typedef struct log_entry { - unit *u; - skill_t sk; - int days; -} log_entry; - -static log_entry log_learners[MAXLOG]; -static int log_size; - -static void log_learn(unit *u, skill_t sk, int days) { - if (log_size < MAXLOG) { - log_entry * entry = &log_learners[log_size++]; - entry->u = u; - entry->sk = sk; - entry->days = days; - } -} - -void learn_inject(void) { - log_size = 0; - inject_learn(log_learn); -} - -void learn_reset(void) { - inject_learn(0); -} - static void test_academy_building(CuTest *tc) { unit *u, *u1, *u2; struct locale * loc; @@ -507,6 +519,6 @@ CuSuite *get_study_suite(void) SUITE_ADD_TEST(suite, test_produceexp); SUITE_ADD_TEST(suite, test_academy_building); SUITE_ADD_TEST(suite, test_demon_skillchanges); - DISABLE_TEST(suite, test_study_bug_2194); + SUITE_ADD_TEST(suite, test_study_bug_2194); return suite; }