forked from github/server
fix bug 2194, poorly
This commit is contained in:
parent
5c9aaa6245
commit
2a8013f3f9
10
src/study.c
10
src/study.c
|
@ -280,7 +280,7 @@ int teach_cmd(unit * u, struct order *ord)
|
||||||
static const curse_type *gbdream_ct = NULL;
|
static const curse_type *gbdream_ct = NULL;
|
||||||
plane *pl;
|
plane *pl;
|
||||||
region *r = u->region;
|
region *r = u->region;
|
||||||
skill_t sk = NOSKILL;
|
skill_t sk_academy = NOSKILL;
|
||||||
int teaching, i, j, count, academy = 0;
|
int teaching, i, j, count, academy = 0;
|
||||||
|
|
||||||
if (gbdream_ct == 0)
|
if (gbdream_ct == 0)
|
||||||
|
@ -322,6 +322,7 @@ int teach_cmd(unit * u, struct order *ord)
|
||||||
|
|
||||||
#if TEACH_ALL
|
#if TEACH_ALL
|
||||||
if (getparam(u->faction->locale) == P_ANY) {
|
if (getparam(u->faction->locale) == P_ANY) {
|
||||||
|
skill_t sk;
|
||||||
unit *student;
|
unit *student;
|
||||||
skill_t teachskill[MAXSKILLS];
|
skill_t teachskill[MAXSKILLS];
|
||||||
int t = 0;
|
int t = 0;
|
||||||
|
@ -380,6 +381,7 @@ int teach_cmd(unit * u, struct order *ord)
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
|
|
||||||
while (!parser_end()) {
|
while (!parser_end()) {
|
||||||
|
skill_t sk;
|
||||||
unit *u2;
|
unit *u2;
|
||||||
bool feedback;
|
bool feedback;
|
||||||
|
|
||||||
|
@ -472,15 +474,15 @@ int teach_cmd(unit * u, struct order *ord)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sk_academy = sk;
|
||||||
teaching -= teach_unit(u, u2, teaching, sk, false, &academy);
|
teaching -= teach_unit(u, u2, teaching, sk, false, &academy);
|
||||||
}
|
}
|
||||||
new_order = create_order(K_TEACH, u->faction->locale, "%s", zOrder);
|
new_order = create_order(K_TEACH, u->faction->locale, "%s", zOrder);
|
||||||
replace_order(&u->orders, ord, new_order);
|
replace_order(&u->orders, ord, new_order);
|
||||||
free_order(new_order); /* parse_order & set_order have each increased the refcount */
|
free_order(new_order); /* parse_order & set_order have each increased the refcount */
|
||||||
}
|
}
|
||||||
if (academy) {
|
if (academy && sk_academy!=NOSKILL) {
|
||||||
academy_teaching_bonus(u, sk, academy);
|
academy_teaching_bonus(u, sk_academy, academy);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,34 @@
|
||||||
|
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
|
|
||||||
|
#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 {
|
typedef struct {
|
||||||
unit *u;
|
unit *u;
|
||||||
unit *teachers[2];
|
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(&u1->items, get_resourcetype(R_SILVER)->itype, 50);
|
||||||
i_change(&u2->items, get_resourcetype(R_SILVER)->itype, 50);
|
i_change(&u2->items, get_resourcetype(R_SILVER)->itype, 50);
|
||||||
b->flags = BLD_WORKING;
|
b->flags = BLD_WORKING;
|
||||||
|
learn_inject();
|
||||||
teach_cmd(u, u->thisorder);
|
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"));
|
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();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,34 +204,6 @@ static void test_produceexp(CuTest *tc) {
|
||||||
test_cleanup();
|
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) {
|
static void test_academy_building(CuTest *tc) {
|
||||||
unit *u, *u1, *u2;
|
unit *u, *u1, *u2;
|
||||||
struct locale * loc;
|
struct locale * loc;
|
||||||
|
@ -507,6 +519,6 @@ CuSuite *get_study_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_produceexp);
|
SUITE_ADD_TEST(suite, test_produceexp);
|
||||||
SUITE_ADD_TEST(suite, test_academy_building);
|
SUITE_ADD_TEST(suite, test_academy_building);
|
||||||
SUITE_ADD_TEST(suite, test_demon_skillchanges);
|
SUITE_ADD_TEST(suite, test_demon_skillchanges);
|
||||||
DISABLE_TEST(suite, test_study_bug_2194);
|
SUITE_ADD_TEST(suite, test_study_bug_2194);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue