2015-07-09 13:24:21 +02:00
|
|
|
#include <platform.h>
|
|
|
|
|
|
|
|
#include "study.h"
|
|
|
|
|
2016-12-11 21:21:50 +01:00
|
|
|
#include <kernel/ally.h>
|
2015-08-06 20:48:14 +02:00
|
|
|
#include <kernel/config.h>
|
2016-03-13 13:31:54 +01:00
|
|
|
#include <kernel/building.h>
|
2015-07-09 13:24:21 +02:00
|
|
|
#include <kernel/faction.h>
|
2016-03-04 20:50:58 +01:00
|
|
|
#include <kernel/item.h>
|
2015-07-09 13:24:21 +02:00
|
|
|
#include <kernel/order.h>
|
2016-03-13 13:31:54 +01:00
|
|
|
#include <kernel/race.h>
|
2016-01-28 16:00:36 +01:00
|
|
|
#include <kernel/region.h>
|
2016-03-13 13:31:54 +01:00
|
|
|
#include <kernel/unit.h>
|
2018-09-29 11:37:17 +02:00
|
|
|
#include <kernel/attrib.h>
|
2016-03-04 20:50:58 +01:00
|
|
|
#include <util/rand.h>
|
2015-07-09 13:24:21 +02:00
|
|
|
#include <util/message.h>
|
|
|
|
#include <util/language.h>
|
|
|
|
#include <util/base36.h>
|
|
|
|
#include <tests.h>
|
|
|
|
|
2016-12-11 21:29:07 +01:00
|
|
|
#include <CuTest.h>
|
2017-01-26 18:58:29 +01:00
|
|
|
#include <selist.h>
|
2016-12-11 21:29:07 +01:00
|
|
|
|
2015-07-09 13:24:21 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
2016-03-25 17:05:01 +01:00
|
|
|
#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);
|
|
|
|
}
|
|
|
|
|
2015-07-09 13:24:21 +02:00
|
|
|
typedef struct {
|
|
|
|
unit *u;
|
|
|
|
unit *teachers[2];
|
|
|
|
} study_fixture;
|
|
|
|
|
2018-01-13 08:51:40 +01:00
|
|
|
static void setup_study(void) {
|
2018-10-28 21:28:05 +01:00
|
|
|
test_setup();
|
|
|
|
mt_create_error(178);
|
|
|
|
mt_create_error(65);
|
|
|
|
mt_create_va(mt_new("teach_asgood", NULL),
|
|
|
|
"unit:unit", "region:region", "command:order", "student:unit", MT_NEW_END);
|
2018-05-18 19:58:49 +02:00
|
|
|
mt_create_va(mt_new("studycost", NULL),
|
|
|
|
"unit:unit", "region:region", "cost:int", "skill:int", MT_NEW_END);
|
|
|
|
mt_create_va(mt_new("teach_teacher", NULL),
|
|
|
|
"teacher:unit", "student:unit", "skill:int", "level:int", MT_NEW_END);
|
|
|
|
mt_create_va(mt_new("teach_student", NULL),
|
|
|
|
"teacher:unit", "student:unit", "skill:int", MT_NEW_END);
|
2018-01-13 08:51:40 +01:00
|
|
|
}
|
|
|
|
|
2016-03-04 20:50:58 +01:00
|
|
|
static void setup_locale(struct locale *lang) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAXSKILLS; ++i) {
|
|
|
|
if (!locale_getstring(lang, mkname("skill", skillnames[i])))
|
|
|
|
locale_setstring(lang, mkname("skill", skillnames[i]), skillnames[i]);
|
|
|
|
}
|
|
|
|
init_skills(lang);
|
|
|
|
}
|
|
|
|
|
2018-01-13 08:51:40 +01:00
|
|
|
static void setup_teacher(study_fixture *fix, skill_t sk) {
|
2015-07-09 13:24:21 +02:00
|
|
|
struct region * r;
|
|
|
|
struct faction *f;
|
|
|
|
struct locale *lang;
|
|
|
|
|
|
|
|
assert(fix);
|
2018-10-28 21:28:05 +01:00
|
|
|
setup_study();
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("study.random_progress", "0");
|
2018-01-14 09:38:26 +01:00
|
|
|
r = test_create_region(0, 0, NULL);
|
|
|
|
f = test_create_faction(NULL);
|
2017-03-10 21:29:37 +01:00
|
|
|
f->locale = lang = test_create_locale();
|
2016-03-04 20:50:58 +01:00
|
|
|
setup_locale(lang);
|
2015-07-09 13:24:21 +02:00
|
|
|
fix->u = test_create_unit(f, r);
|
|
|
|
assert(fix->u);
|
2018-07-14 15:56:44 +02:00
|
|
|
fix->u->thisorder = create_order(K_STUDY, f->locale, skillnames[sk]);
|
2015-07-09 13:24:21 +02:00
|
|
|
|
|
|
|
fix->teachers[0] = test_create_unit(f, r);
|
|
|
|
assert(fix->teachers[0]);
|
2018-07-14 15:56:44 +02:00
|
|
|
fix->teachers[0]->thisorder = create_order(K_TEACH, f->locale, itoa36(fix->u->no));
|
2015-07-09 13:24:21 +02:00
|
|
|
|
|
|
|
fix->teachers[1] = test_create_unit(f, r);
|
|
|
|
assert(fix->teachers[1]);
|
2018-07-14 15:56:44 +02:00
|
|
|
fix->teachers[1]->thisorder = create_order(K_TEACH, f->locale, itoa36(fix->u->no));
|
2016-01-12 06:46:51 +01:00
|
|
|
test_clear_messages(f);
|
2015-07-09 13:24:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_study_no_teacher(CuTest *tc) {
|
|
|
|
study_fixture fix;
|
|
|
|
skill *sv;
|
|
|
|
|
2018-01-13 08:51:40 +01:00
|
|
|
setup_teacher(&fix, SK_CROSSBOW);
|
2015-07-09 13:24:21 +02:00
|
|
|
study_cmd(fix.u, fix.u->thisorder);
|
|
|
|
CuAssertPtrNotNull(tc, sv = unit_skill(fix.u, SK_CROSSBOW));
|
|
|
|
CuAssertIntEquals(tc, 1, sv->level);
|
|
|
|
CuAssertIntEquals(tc, 2, sv->weeks);
|
2018-07-14 15:56:44 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, test_get_last_message(fix.u->faction->msgs));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-07-09 13:24:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_study_with_teacher(CuTest *tc) {
|
|
|
|
study_fixture fix;
|
|
|
|
skill *sv;
|
|
|
|
|
2018-01-13 08:51:40 +01:00
|
|
|
setup_teacher(&fix, SK_CROSSBOW);
|
2015-07-09 13:24:21 +02:00
|
|
|
set_level(fix.teachers[0], SK_CROSSBOW, TEACHDIFFERENCE);
|
|
|
|
teach_cmd(fix.teachers[0], fix.teachers[0]->thisorder);
|
2018-07-14 15:56:44 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, test_get_last_message(fix.u->faction->msgs));
|
2015-07-09 13:24:21 +02:00
|
|
|
study_cmd(fix.u, fix.u->thisorder);
|
|
|
|
CuAssertPtrNotNull(tc, sv = unit_skill(fix.u, SK_CROSSBOW));
|
|
|
|
CuAssertIntEquals(tc, 1, sv->level);
|
|
|
|
CuAssertIntEquals(tc, 1, sv->weeks);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-07-09 13:24:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_study_with_bad_teacher(CuTest *tc) {
|
|
|
|
study_fixture fix;
|
|
|
|
skill *sv;
|
|
|
|
|
2018-01-13 08:51:40 +01:00
|
|
|
setup_teacher(&fix, SK_CROSSBOW);
|
2015-07-09 13:24:21 +02:00
|
|
|
teach_cmd(fix.teachers[0], fix.teachers[0]->thisorder);
|
2016-03-04 20:50:58 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(fix.u->faction->msgs, "teach_asgood"));
|
2015-07-09 13:24:21 +02:00
|
|
|
study_cmd(fix.u, fix.u->thisorder);
|
|
|
|
CuAssertPtrNotNull(tc, sv = unit_skill(fix.u, SK_CROSSBOW));
|
|
|
|
CuAssertIntEquals(tc, 1, sv->level);
|
|
|
|
CuAssertIntEquals(tc, 2, sv->weeks);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-07-09 13:24:21 +02:00
|
|
|
}
|
|
|
|
|
2016-03-04 20:50:58 +01:00
|
|
|
static void test_study_bug_2194(CuTest *tc) {
|
|
|
|
unit *u, *u1, *u2;
|
|
|
|
struct locale * loc;
|
|
|
|
building * b;
|
|
|
|
|
2018-10-28 21:28:05 +01:00
|
|
|
setup_study();
|
2016-03-04 20:50:58 +01:00
|
|
|
random_source_inject_constant(0.0);
|
|
|
|
init_resources();
|
2017-03-10 21:29:37 +01:00
|
|
|
loc = test_create_locale();
|
2016-03-04 20:50:58 +01:00
|
|
|
setup_locale(loc);
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2016-03-04 20:50:58 +01:00
|
|
|
scale_number(u, 2);
|
|
|
|
set_level(u, SK_CROSSBOW, TEACHDIFFERENCE);
|
|
|
|
u->faction->locale = loc;
|
|
|
|
u1 = test_create_unit(u->faction, u->region);
|
|
|
|
scale_number(u1, 17);
|
|
|
|
u1->thisorder = create_order(K_STUDY, loc, skillnames[SK_CROSSBOW]);
|
|
|
|
u2 = test_create_unit(u->faction, u->region);
|
|
|
|
scale_number(u2, 3);
|
|
|
|
u2->thisorder = create_order(K_STUDY, loc, skillnames[SK_MAGIC]);
|
|
|
|
u->thisorder = create_order(K_TEACH, loc, "%s %s", itoa36(u1->no), itoa36(u2->no));
|
|
|
|
b = test_create_building(u->region, test_create_buildingtype("academy"));
|
|
|
|
b->size = 22;
|
|
|
|
u_set_building(u, b);
|
|
|
|
u_set_building(u1, b);
|
|
|
|
u_set_building(u2, b);
|
|
|
|
i_change(&u1->items, get_resourcetype(R_SILVER)->itype, 50);
|
|
|
|
i_change(&u2->items, get_resourcetype(R_SILVER)->itype, 50);
|
2016-08-21 20:12:28 +02:00
|
|
|
b->flags = BLD_MAINTAINED;
|
2016-03-25 17:05:01 +01:00
|
|
|
learn_inject();
|
2016-03-04 20:50:58 +01:00
|
|
|
teach_cmd(u, u->thisorder);
|
2016-03-25 17:05:01 +01:00
|
|
|
learn_reset();
|
|
|
|
CuAssertPtrEquals(tc, u, log_learners[0].u);
|
|
|
|
CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk);
|
|
|
|
CuAssertIntEquals(tc, 1, log_size);
|
2016-03-04 20:50:58 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "teach_asgood"));
|
2016-03-25 17:05:01 +01:00
|
|
|
|
|
|
|
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);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-03-04 20:50:58 +01:00
|
|
|
}
|
|
|
|
|
2016-03-08 14:09:22 +01:00
|
|
|
static CuTest *g_tc;
|
|
|
|
|
2016-03-24 22:31:07 +01:00
|
|
|
static void cb_learn_one(unit *u, skill_t sk, int days) {
|
2016-03-08 14:09:22 +01:00
|
|
|
CuAssertIntEquals(g_tc, SK_ALCHEMY, sk);
|
2017-08-04 15:17:18 +02:00
|
|
|
CuAssertIntEquals(g_tc, 20, days);
|
2016-03-08 14:09:22 +01:00
|
|
|
}
|
|
|
|
|
2016-03-24 22:31:07 +01:00
|
|
|
static void cb_learn_two(unit *u, skill_t sk, int days) {
|
2016-03-08 14:09:22 +01:00
|
|
|
CuAssertIntEquals(g_tc, SK_ALCHEMY, sk);
|
2017-08-04 15:17:18 +02:00
|
|
|
CuAssertIntEquals(g_tc, 40, days);
|
2016-03-08 14:09:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_produceexp(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
|
|
|
|
g_tc = tc;
|
2018-10-28 21:28:05 +01:00
|
|
|
setup_study();
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2016-03-24 22:31:07 +01:00
|
|
|
scale_number(u, 2);
|
|
|
|
config_set("study.produceexp", "20");
|
2016-03-08 14:09:22 +01:00
|
|
|
produceexp_ex(u, SK_ALCHEMY, 1, cb_learn_one);
|
|
|
|
produceexp_ex(u, SK_ALCHEMY, 2, cb_learn_two);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-03-08 14:09:22 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 23:20:05 +01:00
|
|
|
static void test_academy_building(CuTest *tc) {
|
|
|
|
unit *u, *u1, *u2;
|
|
|
|
struct locale * loc;
|
|
|
|
building * b;
|
|
|
|
message * msg;
|
|
|
|
|
2018-10-28 21:28:05 +01:00
|
|
|
setup_study();
|
2018-05-18 19:58:49 +02:00
|
|
|
mt_create_va(mt_new("teach_asgood", NULL),
|
|
|
|
"unit:unit", "region:region", "command:order", "student:unit", MT_NEW_END);
|
2016-03-09 23:20:05 +01:00
|
|
|
|
|
|
|
random_source_inject_constant(0.0);
|
|
|
|
init_resources();
|
2017-03-10 21:29:37 +01:00
|
|
|
loc = test_create_locale();
|
2016-03-09 23:20:05 +01:00
|
|
|
setup_locale(loc);
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2016-03-09 23:20:05 +01:00
|
|
|
scale_number(u, 2);
|
|
|
|
set_level(u, SK_CROSSBOW, TEACHDIFFERENCE);
|
|
|
|
u->faction->locale = loc;
|
|
|
|
u1 = test_create_unit(u->faction, u->region);
|
|
|
|
scale_number(u1, 15);
|
|
|
|
u1->thisorder = create_order(K_STUDY, loc, skillnames[SK_CROSSBOW]);
|
|
|
|
u2 = test_create_unit(u->faction, u->region);
|
|
|
|
scale_number(u2, 5);
|
|
|
|
u2->thisorder = create_order(K_STUDY, loc, skillnames[SK_CROSSBOW]);
|
|
|
|
set_level(u2, SK_CROSSBOW, 1);
|
|
|
|
u->thisorder = create_order(K_TEACH, loc, "%s %s", itoa36(u1->no), itoa36(u2->no));
|
|
|
|
b = test_create_building(u->region, test_create_buildingtype("academy"));
|
|
|
|
b->size = 22;
|
|
|
|
u_set_building(u, b);
|
|
|
|
u_set_building(u1, b);
|
|
|
|
u_set_building(u2, b);
|
|
|
|
i_change(&u1->items, get_resourcetype(R_SILVER)->itype, 50);
|
|
|
|
i_change(&u2->items, get_resourcetype(R_SILVER)->itype, 50);
|
2016-08-21 20:12:28 +02:00
|
|
|
b->flags = BLD_MAINTAINED;
|
2016-03-23 11:56:17 +01:00
|
|
|
learn_inject();
|
2016-03-09 23:20:05 +01:00
|
|
|
teach_cmd(u, u->thisorder);
|
2016-03-23 11:56:17 +01:00
|
|
|
learn_reset();
|
2016-03-09 23:20:05 +01:00
|
|
|
CuAssertPtrNotNull(tc, msg = test_find_messagetype(u->faction->msgs, "teach_asgood"));
|
|
|
|
CuAssertPtrEquals(tc, u, (unit *)(msg)->parameters[0].v);
|
|
|
|
CuAssertPtrEquals(tc, u2, (unit *)(msg)->parameters[3].v);
|
2016-03-24 13:44:29 +01:00
|
|
|
|
2016-03-09 23:20:05 +01:00
|
|
|
CuAssertPtrEquals(tc, u, log_learners[0].u);
|
|
|
|
CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk);
|
2017-08-04 15:17:18 +02:00
|
|
|
CuAssertIntEquals(tc, u1->number, log_learners[0].days);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-03-09 23:20:05 +01:00
|
|
|
}
|
|
|
|
|
2017-09-02 03:12:02 +02:00
|
|
|
/*
|
|
|
|
u0 (1) TEACH u3 (1) u1 (9/10)
|
|
|
|
u (2) TEACH u1 (1/10)
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void test_academy_bonus(CuTest *tc) {
|
|
|
|
unit *u, *u0, *u1, *u3;
|
|
|
|
struct locale * loc;
|
|
|
|
building * b;
|
|
|
|
|
2018-01-13 08:51:40 +01:00
|
|
|
setup_study();
|
2017-09-02 03:12:02 +02:00
|
|
|
|
|
|
|
random_source_inject_constant(0.0);
|
|
|
|
init_resources();
|
|
|
|
loc = test_create_locale();
|
|
|
|
setup_locale(loc);
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2017-09-02 03:12:02 +02:00
|
|
|
u->faction->locale = loc;
|
|
|
|
|
2018-01-14 09:38:26 +01:00
|
|
|
u0 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2017-09-02 03:12:02 +02:00
|
|
|
set_level(u, SK_CROSSBOW, TEACHDIFFERENCE);
|
|
|
|
set_level(u0, SK_CROSSBOW, TEACHDIFFERENCE);
|
|
|
|
|
|
|
|
u1 = test_create_unit(u->faction, u->region);
|
|
|
|
u3 = test_create_unit(u->faction, u->region);
|
|
|
|
u0->thisorder = create_order(K_TEACH, loc, "%s %s", itoa36(u3->no), itoa36(u1->no));
|
2018-07-14 15:56:44 +02:00
|
|
|
u->thisorder = create_order(K_TEACH, loc, itoa36(u1->no));
|
2017-09-02 03:12:02 +02:00
|
|
|
u1->thisorder = create_order(K_STUDY, loc, skillnames[SK_CROSSBOW]);
|
|
|
|
u3->thisorder = create_order(K_STUDY, loc, skillnames[SK_CROSSBOW]);
|
|
|
|
|
|
|
|
b = test_create_building(u->region, test_create_buildingtype("academy"));
|
|
|
|
b->size = 25;
|
|
|
|
u_set_building(u, b);
|
|
|
|
u_set_building(u0, b);
|
|
|
|
u_set_building(u1, b);
|
|
|
|
u_set_building(u3, b);
|
|
|
|
|
|
|
|
scale_number(u, 2);
|
|
|
|
scale_number(u1, 9);
|
|
|
|
scale_number(u3, 2);
|
|
|
|
i_change(&u1->items, get_resourcetype(R_SILVER)->itype, 5000);
|
|
|
|
b->flags = BLD_MAINTAINED;
|
|
|
|
|
|
|
|
learn_inject();
|
|
|
|
teach_cmd(u0, u0->thisorder);
|
|
|
|
teach_cmd(u, u->thisorder);
|
|
|
|
study_cmd(u1, u1->thisorder);
|
|
|
|
study_cmd(u3, u3->thisorder);
|
|
|
|
|
|
|
|
CuAssertIntEquals(tc, 4, log_size);
|
|
|
|
CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk);
|
|
|
|
CuAssertPtrEquals(tc, u0, log_learners[0].u);
|
|
|
|
CuAssertIntEquals(tc, 10, log_learners[0].days);
|
|
|
|
CuAssertPtrEquals(tc, u, log_learners[1].u);
|
|
|
|
CuAssertIntEquals(tc, 1, log_learners[1].days);
|
|
|
|
CuAssertPtrEquals(tc, u1, log_learners[2].u);
|
|
|
|
CuAssertIntEquals(tc, 720, log_learners[2].days);
|
|
|
|
CuAssertPtrEquals(tc, u3, log_learners[3].u);
|
|
|
|
CuAssertIntEquals(tc, 160, log_learners[3].days);
|
|
|
|
learn_reset();
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-09-02 03:12:02 +02:00
|
|
|
}
|
|
|
|
|
2016-03-13 13:42:26 +01:00
|
|
|
void test_learn_skill_single(CuTest *tc) {
|
2016-03-12 14:52:33 +01:00
|
|
|
unit *u;
|
|
|
|
skill *sv;
|
2018-10-28 21:28:05 +01:00
|
|
|
|
|
|
|
setup_study();
|
2016-03-13 19:13:58 +01:00
|
|
|
config_set("study.random_progress", "0");
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2016-03-12 14:52:33 +01:00
|
|
|
learn_skill(u, SK_ALCHEMY, STUDYDAYS);
|
|
|
|
CuAssertPtrNotNull(tc, sv = u->skills);
|
|
|
|
CuAssertIntEquals(tc, SK_ALCHEMY, sv->id);
|
|
|
|
CuAssertIntEquals(tc, 1, sv->level);
|
|
|
|
CuAssertIntEquals(tc, 2, sv->weeks);
|
|
|
|
learn_skill(u, SK_ALCHEMY, STUDYDAYS);
|
|
|
|
CuAssertIntEquals(tc, 1, sv->weeks);
|
|
|
|
learn_skill(u, SK_ALCHEMY, STUDYDAYS * 2);
|
|
|
|
CuAssertIntEquals(tc, 2, sv->level);
|
2016-03-13 19:13:58 +01:00
|
|
|
CuAssertIntEquals(tc, 2, sv->weeks);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-03-12 14:52:33 +01:00
|
|
|
}
|
|
|
|
|
2016-03-13 13:42:26 +01:00
|
|
|
void test_learn_skill_multi(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
skill *sv;
|
2018-10-28 21:28:05 +01:00
|
|
|
|
|
|
|
setup_study();
|
2016-03-13 19:13:58 +01:00
|
|
|
config_set("study.random_progress", "0");
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2016-03-13 13:42:26 +01:00
|
|
|
scale_number(u, 10);
|
|
|
|
learn_skill(u, SK_ALCHEMY, STUDYDAYS * u->number);
|
|
|
|
CuAssertPtrNotNull(tc, sv = u->skills);
|
|
|
|
CuAssertIntEquals(tc, SK_ALCHEMY, sv->id);
|
|
|
|
CuAssertIntEquals(tc, 1, sv->level);
|
|
|
|
CuAssertIntEquals(tc, 2, sv->weeks);
|
|
|
|
learn_skill(u, SK_ALCHEMY, STUDYDAYS * u->number);
|
|
|
|
CuAssertIntEquals(tc, 1, sv->weeks);
|
|
|
|
learn_skill(u, SK_ALCHEMY, STUDYDAYS * u->number * 2);
|
|
|
|
CuAssertIntEquals(tc, 2, sv->level);
|
2016-03-13 19:13:58 +01:00
|
|
|
CuAssertIntEquals(tc, 2, sv->weeks);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-03-13 13:42:26 +01:00
|
|
|
}
|
|
|
|
|
2016-03-23 11:56:17 +01:00
|
|
|
static void test_demon_skillchanges(CuTest *tc) {
|
2016-03-13 13:31:54 +01:00
|
|
|
unit * u;
|
2016-09-20 20:27:41 +02:00
|
|
|
const race * rc;
|
2018-10-28 21:28:05 +01:00
|
|
|
|
|
|
|
setup_study();
|
2016-03-13 13:31:54 +01:00
|
|
|
rc = test_create_race("demon");
|
2016-09-20 20:27:41 +02:00
|
|
|
CuAssertPtrEquals(tc, (void *)rc, (void *)get_race(RC_DAEMON));
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, NULL));
|
2016-03-13 13:31:54 +01:00
|
|
|
CuAssertPtrNotNull(tc, u);
|
|
|
|
set_level(u, SK_CROSSBOW, 1);
|
|
|
|
demon_skillchange(u);
|
2017-02-18 21:15:14 +01:00
|
|
|
/* TODO: sensing here */
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-03-13 13:31:54 +01:00
|
|
|
}
|
|
|
|
|
2016-03-23 11:56:17 +01:00
|
|
|
static void test_study_cmd(CuTest *tc) {
|
|
|
|
unit *u;
|
2018-10-28 21:28:05 +01:00
|
|
|
|
|
|
|
setup_study();
|
2016-03-23 11:56:17 +01:00
|
|
|
init_resources();
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2016-03-23 12:05:01 +01:00
|
|
|
u->thisorder = create_order(K_STUDY, u->faction->locale, "CROSSBOW");
|
2016-03-23 11:56:17 +01:00
|
|
|
learn_inject();
|
|
|
|
study_cmd(u, u->thisorder);
|
|
|
|
learn_reset();
|
|
|
|
CuAssertPtrEquals(tc, u, log_learners[0].u);
|
2016-03-23 12:05:01 +01:00
|
|
|
CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk);
|
2016-03-23 12:13:29 +01:00
|
|
|
CuAssertIntEquals(tc, STUDYDAYS, log_learners[0].days);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-03-23 12:13:29 +01:00
|
|
|
}
|
|
|
|
|
2016-09-11 11:02:04 +02:00
|
|
|
static void test_study_magic(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
faction *f;
|
|
|
|
const struct locale *lang;
|
2017-12-29 15:58:12 +01:00
|
|
|
const struct item_type *itype;
|
2016-09-11 11:02:04 +02:00
|
|
|
|
2018-01-13 08:51:40 +01:00
|
|
|
setup_study();
|
2016-09-11 11:02:04 +02:00
|
|
|
init_resources();
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
2016-09-11 11:02:04 +02:00
|
|
|
lang = f->locale;
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(f, test_create_region(0, 0, NULL));
|
2018-07-14 15:56:44 +02:00
|
|
|
u->thisorder = create_order(K_STUDY, lang, skillnames[SK_MAGIC]);
|
2017-12-29 15:58:12 +01:00
|
|
|
itype = test_create_silver();
|
|
|
|
|
|
|
|
CuAssertIntEquals(tc, -1, study_cmd(u, u->thisorder));
|
2016-09-11 11:02:04 +02:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error178"));
|
|
|
|
free_order(u->thisorder);
|
|
|
|
|
|
|
|
test_clear_messages(f);
|
|
|
|
u->thisorder = create_order(K_STUDY, lang, "%s %s", skillnames[SK_MAGIC], magic_school[M_GWYRRD]);
|
2017-12-29 15:58:12 +01:00
|
|
|
CuAssertIntEquals(tc, 0, study_cmd(u, u->thisorder));
|
2016-09-11 11:02:04 +02:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error65"));
|
|
|
|
|
|
|
|
test_clear_messages(f);
|
2017-12-29 15:58:12 +01:00
|
|
|
i_change(&u->items, itype, 100);
|
|
|
|
CuAssertIntEquals(tc, 0, study_cmd(u, u->thisorder));
|
2016-09-11 11:02:04 +02:00
|
|
|
CuAssertIntEquals(tc, M_GWYRRD, f->magiegebiet);
|
2017-12-29 15:58:12 +01:00
|
|
|
CuAssertIntEquals(tc, 0, i_get(u->items, itype));
|
2018-11-18 21:47:14 +01:00
|
|
|
CuAssertPtrNotNull(tc, get_mage(u));
|
2018-07-14 15:56:44 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error65"));
|
2018-11-18 21:47:14 +01:00
|
|
|
CuAssertIntEquals(tc, M_GWYRRD, unit_get_magic(u));
|
2016-09-11 11:02:04 +02:00
|
|
|
|
2017-12-29 15:58:12 +01:00
|
|
|
test_teardown();
|
|
|
|
}
|
2016-09-11 11:02:04 +02:00
|
|
|
|
2017-12-29 15:58:12 +01:00
|
|
|
static void test_study_cost_magic(CuTest *tc) {
|
2018-01-07 15:26:17 +01:00
|
|
|
unit * u;
|
|
|
|
|
2018-01-13 08:51:40 +01:00
|
|
|
setup_study();
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2018-01-07 15:26:17 +01:00
|
|
|
|
|
|
|
CuAssertIntEquals(tc, 100, study_cost(u, SK_MAGIC));
|
|
|
|
set_level(u, SK_MAGIC, 1);
|
|
|
|
CuAssertIntEquals(tc, 200, study_cost(u, SK_MAGIC));
|
|
|
|
set_level(u, SK_MAGIC, 2);
|
|
|
|
CuAssertIntEquals(tc, 350, study_cost(u, SK_MAGIC));
|
|
|
|
set_level(u, SK_MAGIC, 29);
|
|
|
|
CuAssertIntEquals(tc, 23300, study_cost(u, SK_MAGIC));
|
|
|
|
set_level(u, SK_MAGIC, 27);
|
|
|
|
CuAssertIntEquals(tc, 20350, study_cost(u, SK_MAGIC));
|
|
|
|
|
2017-12-29 15:58:12 +01:00
|
|
|
config_set("skills.cost.magic", "100");
|
2018-01-07 15:26:17 +01:00
|
|
|
CuAssertIntEquals(tc, 2*20350, study_cost(u, SK_MAGIC));
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-09-11 11:02:04 +02:00
|
|
|
}
|
|
|
|
|
2016-03-23 12:13:29 +01:00
|
|
|
static void test_study_cost(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
const struct item_type *itype;
|
2016-09-11 11:02:04 +02:00
|
|
|
|
2018-01-13 08:51:40 +01:00
|
|
|
setup_study();
|
2017-12-29 15:58:12 +01:00
|
|
|
|
|
|
|
itype = test_create_silver();
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2016-03-23 12:13:29 +01:00
|
|
|
scale_number(u, 2);
|
2016-09-11 11:02:04 +02:00
|
|
|
u->thisorder = create_order(K_STUDY, u->faction->locale, skillnames[SK_ALCHEMY]);
|
2017-12-29 15:58:12 +01:00
|
|
|
|
|
|
|
CuAssertIntEquals(tc, 200, study_cost(u, SK_ALCHEMY));
|
|
|
|
config_set("skills.cost.alchemy", "50");
|
|
|
|
CuAssertIntEquals(tc, 50, study_cost(u, SK_ALCHEMY));
|
|
|
|
|
2016-03-23 12:13:29 +01:00
|
|
|
i_change(&u->items, itype, u->number * study_cost(u, SK_ALCHEMY));
|
|
|
|
learn_inject();
|
|
|
|
study_cmd(u, u->thisorder);
|
|
|
|
learn_reset();
|
|
|
|
CuAssertPtrEquals(tc, u, log_learners[0].u);
|
|
|
|
CuAssertIntEquals(tc, SK_ALCHEMY, log_learners[0].sk);
|
2017-08-04 15:17:18 +02:00
|
|
|
CuAssertIntEquals(tc, STUDYDAYS * u->number, log_learners[0].days);
|
2016-03-23 12:13:29 +01:00
|
|
|
CuAssertIntEquals(tc, 0, i_get(u->items, itype));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-03-23 12:05:01 +01:00
|
|
|
}
|
|
|
|
|
2017-01-29 11:06:08 +01:00
|
|
|
static void test_teach_magic(CuTest *tc) {
|
|
|
|
unit *u, *ut;
|
|
|
|
faction *f;
|
|
|
|
const struct item_type *itype;
|
|
|
|
|
2018-01-13 08:51:40 +01:00
|
|
|
setup_study();
|
2017-01-29 11:06:08 +01:00
|
|
|
init_resources();
|
|
|
|
itype = get_resourcetype(R_SILVER)->itype;
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
2017-01-29 11:06:08 +01:00
|
|
|
f->magiegebiet = M_GWYRRD;
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(f, test_create_region(0, 0, NULL));
|
2018-07-14 15:56:44 +02:00
|
|
|
u->thisorder = create_order(K_STUDY, f->locale, skillnames[SK_MAGIC]);
|
2017-01-29 11:06:08 +01:00
|
|
|
i_change(&u->items, itype, study_cost(u, SK_MAGIC));
|
|
|
|
ut = test_create_unit(f, u->region);
|
|
|
|
set_level(ut, SK_MAGIC, TEACHDIFFERENCE);
|
|
|
|
create_mage(ut, M_GWYRRD);
|
2018-07-14 15:56:44 +02:00
|
|
|
ut->thisorder = create_order(K_TEACH, f->locale, itoa36(u->no));
|
2017-01-29 11:06:08 +01:00
|
|
|
learn_inject();
|
|
|
|
teach_cmd(ut, ut->thisorder);
|
|
|
|
study_cmd(u, u->thisorder);
|
|
|
|
learn_reset();
|
|
|
|
CuAssertPtrEquals(tc, u, log_learners[0].u);
|
|
|
|
CuAssertIntEquals(tc, SK_MAGIC, log_learners[0].sk);
|
2017-08-04 15:17:18 +02:00
|
|
|
CuAssertIntEquals(tc, STUDYDAYS * 2, log_learners[0].days);
|
2017-01-29 11:06:08 +01:00
|
|
|
CuAssertIntEquals(tc, 0, i_get(u->items, itype));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-01-29 11:06:08 +01:00
|
|
|
}
|
|
|
|
|
2016-03-23 12:05:01 +01:00
|
|
|
static void test_teach_cmd(CuTest *tc) {
|
|
|
|
unit *u, *ut;
|
2018-10-28 21:28:05 +01:00
|
|
|
|
|
|
|
setup_study();
|
2016-03-23 12:05:01 +01:00
|
|
|
init_resources();
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2016-03-23 12:05:01 +01:00
|
|
|
scale_number(u, 10);
|
|
|
|
u->thisorder = create_order(K_STUDY, u->faction->locale, "CROSSBOW");
|
|
|
|
ut = test_create_unit(u->faction, u->region);
|
|
|
|
set_level(ut, SK_CROSSBOW, TEACHDIFFERENCE);
|
|
|
|
ut->thisorder = create_order(K_TEACH, u->faction->locale, itoa36(u->no));
|
|
|
|
learn_inject();
|
|
|
|
teach_cmd(ut, ut->thisorder);
|
|
|
|
study_cmd(u, u->thisorder);
|
|
|
|
learn_reset();
|
|
|
|
CuAssertPtrEquals(tc, u, log_learners[0].u);
|
|
|
|
CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk);
|
2017-08-04 15:17:18 +02:00
|
|
|
CuAssertIntEquals(tc, STUDYDAYS * 2 * u->number, log_learners[0].days);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-03-23 12:13:29 +01:00
|
|
|
}
|
|
|
|
|
2016-03-23 13:18:14 +01:00
|
|
|
static void test_teach_two(CuTest *tc) {
|
|
|
|
unit *u1, *u2, *ut;
|
2018-10-28 21:28:05 +01:00
|
|
|
|
|
|
|
setup_study();
|
2016-03-23 13:18:14 +01:00
|
|
|
init_resources();
|
2018-01-14 09:38:26 +01:00
|
|
|
u1 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2016-03-23 13:18:14 +01:00
|
|
|
scale_number(u1, 5);
|
|
|
|
u1->thisorder = create_order(K_STUDY, u1->faction->locale, "CROSSBOW");
|
|
|
|
u2 = test_create_unit(u1->faction, u1->region);
|
|
|
|
scale_number(u2, 5);
|
|
|
|
u2->thisorder = create_order(K_STUDY, u2->faction->locale, "CROSSBOW");
|
|
|
|
ut = test_create_unit(u1->faction, u1->region);
|
|
|
|
set_level(ut, SK_CROSSBOW, TEACHDIFFERENCE);
|
|
|
|
ut->thisorder = create_order(K_TEACH, ut->faction->locale, "%s %s", itoa36(u1->no), itoa36(u2->no));
|
|
|
|
learn_inject();
|
|
|
|
teach_cmd(ut, ut->thisorder);
|
|
|
|
study_cmd(u1, u1->thisorder);
|
|
|
|
study_cmd(u2, u2->thisorder);
|
|
|
|
learn_reset();
|
|
|
|
CuAssertPtrEquals(tc, u1, log_learners[0].u);
|
|
|
|
CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk);
|
|
|
|
CuAssertIntEquals(tc, STUDYDAYS * 2 * u1->number, log_learners[0].days);
|
|
|
|
CuAssertPtrEquals(tc, u2, log_learners[1].u);
|
|
|
|
CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[1].sk);
|
|
|
|
CuAssertIntEquals(tc, STUDYDAYS * 2 * u2->number, log_learners[1].days);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-03-23 13:18:14 +01:00
|
|
|
}
|
|
|
|
|
2016-03-23 21:14:13 +01:00
|
|
|
static void test_teach_two_skills(CuTest *tc) {
|
|
|
|
unit *u1, *u2, *ut;
|
|
|
|
faction *f;
|
|
|
|
region *r;
|
|
|
|
|
2018-10-28 21:28:05 +01:00
|
|
|
setup_study();
|
2016-03-23 21:14:13 +01:00
|
|
|
init_resources();
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
|
|
|
r = test_create_region(0, 0, NULL);
|
2016-03-23 21:14:13 +01:00
|
|
|
u1 = test_create_unit(f, r);
|
|
|
|
scale_number(u1, 5);
|
|
|
|
u1->thisorder = create_order(K_STUDY, f->locale, "CROSSBOW");
|
|
|
|
u2 = test_create_unit(f, r);
|
|
|
|
scale_number(u2, 5);
|
|
|
|
u2->thisorder = create_order(K_STUDY, f->locale, "ENTERTAINMENT");
|
|
|
|
ut = test_create_unit(f, r);
|
|
|
|
set_level(ut, SK_ENTERTAINMENT, TEACHDIFFERENCE);
|
|
|
|
set_level(ut, SK_CROSSBOW, TEACHDIFFERENCE);
|
|
|
|
ut->thisorder = create_order(K_TEACH, f->locale, "%s %s", itoa36(u1->no), itoa36(u2->no));
|
|
|
|
learn_inject();
|
|
|
|
teach_cmd(ut, ut->thisorder);
|
|
|
|
study_cmd(u1, u1->thisorder);
|
|
|
|
study_cmd(u2, u2->thisorder);
|
|
|
|
learn_reset();
|
|
|
|
CuAssertPtrEquals(tc, u1, log_learners[0].u);
|
|
|
|
CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk);
|
|
|
|
CuAssertIntEquals(tc, STUDYDAYS * 2 * u1->number, log_learners[0].days);
|
|
|
|
CuAssertPtrEquals(tc, u2, log_learners[1].u);
|
|
|
|
CuAssertIntEquals(tc, SK_ENTERTAINMENT, log_learners[1].sk);
|
|
|
|
CuAssertIntEquals(tc, STUDYDAYS * 2 * u2->number, log_learners[1].days);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-03-23 21:14:13 +01:00
|
|
|
}
|
|
|
|
|
2016-03-23 16:51:23 +01:00
|
|
|
static void test_teach_one_to_many(CuTest *tc) {
|
2016-03-23 12:13:29 +01:00
|
|
|
unit *u, *ut;
|
2018-10-28 21:28:05 +01:00
|
|
|
|
|
|
|
setup_study();
|
2016-03-23 12:13:29 +01:00
|
|
|
init_resources();
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2016-03-23 12:13:29 +01:00
|
|
|
scale_number(u, 20);
|
|
|
|
u->thisorder = create_order(K_STUDY, u->faction->locale, "CROSSBOW");
|
|
|
|
ut = test_create_unit(u->faction, u->region);
|
|
|
|
set_level(ut, SK_CROSSBOW, TEACHDIFFERENCE);
|
|
|
|
ut->thisorder = create_order(K_TEACH, u->faction->locale, itoa36(u->no));
|
|
|
|
learn_inject();
|
|
|
|
teach_cmd(ut, ut->thisorder);
|
|
|
|
study_cmd(u, u->thisorder);
|
|
|
|
learn_reset();
|
|
|
|
CuAssertPtrEquals(tc, u, log_learners[0].u);
|
|
|
|
CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk);
|
|
|
|
CuAssertIntEquals(tc, STUDYDAYS * 10 + STUDYDAYS * u->number, log_learners[0].days);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-03-23 11:56:17 +01:00
|
|
|
}
|
|
|
|
|
2016-03-23 16:51:23 +01:00
|
|
|
static void test_teach_many_to_one(CuTest *tc) {
|
|
|
|
unit *u, *u1, *u2;
|
2016-12-11 21:21:50 +01:00
|
|
|
|
2018-10-28 21:28:05 +01:00
|
|
|
setup_study();
|
2016-03-23 16:51:23 +01:00
|
|
|
init_resources();
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2016-03-23 16:51:23 +01:00
|
|
|
scale_number(u, 20);
|
|
|
|
u->thisorder = create_order(K_STUDY, u->faction->locale, "CROSSBOW");
|
|
|
|
u1 = test_create_unit(u->faction, u->region);
|
|
|
|
set_level(u1, SK_CROSSBOW, TEACHDIFFERENCE);
|
|
|
|
u1->thisorder = create_order(K_TEACH, u->faction->locale, itoa36(u->no));
|
|
|
|
u2 = test_create_unit(u->faction, u->region);
|
|
|
|
set_level(u2, SK_CROSSBOW, TEACHDIFFERENCE);
|
|
|
|
u2->thisorder = create_order(K_TEACH, u->faction->locale, itoa36(u->no));
|
|
|
|
learn_inject();
|
|
|
|
teach_cmd(u1, u1->thisorder);
|
|
|
|
teach_cmd(u2, u2->thisorder);
|
|
|
|
study_cmd(u, u->thisorder);
|
|
|
|
learn_reset();
|
|
|
|
CuAssertPtrEquals(tc, u, log_learners[0].u);
|
|
|
|
CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk);
|
|
|
|
CuAssertIntEquals(tc, 2 * STUDYDAYS * u->number, log_learners[0].days);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-03-23 16:51:23 +01:00
|
|
|
}
|
|
|
|
|
2016-12-11 21:21:50 +01:00
|
|
|
static void test_teach_message(CuTest *tc) {
|
|
|
|
unit *u, *u1, *u2;
|
|
|
|
attrib *a;
|
|
|
|
teaching_info *teach;
|
|
|
|
|
2018-10-28 21:28:05 +01:00
|
|
|
setup_study();
|
2016-12-11 21:21:50 +01:00
|
|
|
init_resources();
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2016-12-11 21:21:50 +01:00
|
|
|
scale_number(u, 20);
|
|
|
|
u->thisorder = create_order(K_STUDY, u->faction->locale, "CROSSBOW");
|
2018-01-14 09:38:26 +01:00
|
|
|
u1 = test_create_unit(test_create_faction(NULL), u->region);
|
2016-12-11 21:21:50 +01:00
|
|
|
set_level(u1, SK_CROSSBOW, TEACHDIFFERENCE);
|
|
|
|
u1->thisorder = create_order(K_TEACH, u->faction->locale, itoa36(u->no));
|
2018-01-14 09:38:26 +01:00
|
|
|
u2 = test_create_unit(test_create_faction(NULL), u->region);
|
2018-10-26 19:47:50 +02:00
|
|
|
ally_set(&u->faction->allies, u2->faction, HELP_GUARD);
|
2016-12-11 21:21:50 +01:00
|
|
|
set_level(u2, SK_CROSSBOW, TEACHDIFFERENCE);
|
|
|
|
u2->thisorder = create_order(K_TEACH, u->faction->locale, itoa36(u->no));
|
|
|
|
CuAssertTrue(tc, !alliedunit(u, u1->faction, HELP_GUARD));
|
|
|
|
CuAssertTrue(tc, alliedunit(u, u2->faction, HELP_GUARD));
|
|
|
|
teach_cmd(u1, u1->thisorder);
|
|
|
|
teach_cmd(u2, u2->thisorder);
|
|
|
|
a = a_find(u->attribs, &at_learning);
|
|
|
|
CuAssertPtrNotNull(tc, a);
|
|
|
|
CuAssertPtrNotNull(tc, a->data.v);
|
|
|
|
teach = (teaching_info *)a->data.v;
|
|
|
|
CuAssertPtrNotNull(tc, teach->teachers);
|
2017-09-02 15:50:03 +02:00
|
|
|
CuAssertIntEquals(tc, 600, teach->days);
|
2017-01-26 18:58:29 +01:00
|
|
|
CuAssertIntEquals(tc, 2, selist_length(teach->teachers));
|
|
|
|
CuAssertPtrEquals(tc, u1, selist_get(teach->teachers, 0));
|
|
|
|
CuAssertPtrEquals(tc, u2, selist_get(teach->teachers, 1));
|
2016-12-11 21:21:50 +01:00
|
|
|
study_cmd(u, u->thisorder);
|
|
|
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(u1->faction->msgs, "teach_teacher"));
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u2->faction->msgs, "teach_teacher"));
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "teach_student"));
|
|
|
|
a = a_find(u->attribs, &at_learning);
|
|
|
|
CuAssertPtrEquals(tc, NULL, a);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-12-11 21:21:50 +01:00
|
|
|
}
|
|
|
|
|
2016-03-23 16:51:23 +01:00
|
|
|
static void test_teach_many_to_many(CuTest *tc) {
|
|
|
|
unit *s1, *s2, *t1, *t2;
|
|
|
|
region *r;
|
|
|
|
faction *f;
|
|
|
|
|
2018-10-28 21:28:05 +01:00
|
|
|
setup_study();
|
2016-03-23 16:51:23 +01:00
|
|
|
init_resources();
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
|
|
|
r = test_create_region(0, 0, NULL);
|
2016-03-23 16:51:23 +01:00
|
|
|
s1 = test_create_unit(f, r);
|
|
|
|
scale_number(s1, 20);
|
|
|
|
s1->thisorder = create_order(K_STUDY, f->locale, "CROSSBOW");
|
|
|
|
s2 = test_create_unit(f, r);
|
|
|
|
scale_number(s2, 10);
|
|
|
|
s2->thisorder = create_order(K_STUDY, f->locale, "CROSSBOW");
|
|
|
|
|
|
|
|
t1 = test_create_unit(f, r);
|
|
|
|
set_level(t1, SK_CROSSBOW, TEACHDIFFERENCE);
|
|
|
|
t1->thisorder = create_order(K_TEACH, f->locale, "%s %s", itoa36(s1->no), itoa36(s2->no));
|
|
|
|
t2 = test_create_unit(f, r);
|
|
|
|
scale_number(t2, 2);
|
|
|
|
set_level(t2, SK_CROSSBOW, TEACHDIFFERENCE);
|
|
|
|
t2->thisorder = create_order(K_TEACH, f->locale, "%s %s", itoa36(s1->no), itoa36(s2->no));
|
|
|
|
learn_inject();
|
|
|
|
teach_cmd(t1, t1->thisorder);
|
|
|
|
teach_cmd(t2, t2->thisorder);
|
|
|
|
study_cmd(s1, s1->thisorder);
|
|
|
|
study_cmd(s2, s2->thisorder);
|
|
|
|
learn_reset();
|
|
|
|
CuAssertPtrEquals(tc, s1, log_learners[0].u);
|
|
|
|
CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk);
|
|
|
|
CuAssertIntEquals(tc, 2 * STUDYDAYS * s1->number, log_learners[0].days);
|
|
|
|
CuAssertPtrEquals(tc, s2, log_learners[1].u);
|
|
|
|
CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[1].sk);
|
|
|
|
CuAssertIntEquals(tc, 2 * STUDYDAYS * s2->number, log_learners[1].days);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-03-23 16:51:23 +01:00
|
|
|
}
|
|
|
|
|
2015-07-09 13:24:21 +02:00
|
|
|
CuSuite *get_study_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
2016-03-23 11:56:17 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_study_cmd);
|
2016-03-23 12:13:29 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_study_cost);
|
2017-12-29 15:58:12 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_study_cost_magic);
|
2016-09-11 11:02:04 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_study_magic);
|
2016-03-23 12:05:01 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_teach_cmd);
|
2017-01-29 11:06:08 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_teach_magic);
|
2016-03-23 13:18:14 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_teach_two);
|
2016-03-23 16:51:23 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_teach_one_to_many);
|
|
|
|
SUITE_ADD_TEST(suite, test_teach_many_to_one);
|
|
|
|
SUITE_ADD_TEST(suite, test_teach_many_to_many);
|
2016-12-11 21:21:50 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_teach_message);
|
2016-03-23 21:14:13 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_teach_two_skills);
|
2016-03-13 13:42:26 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_learn_skill_single);
|
|
|
|
SUITE_ADD_TEST(suite, test_learn_skill_multi);
|
2015-07-09 13:24:21 +02:00
|
|
|
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);
|
2016-03-08 14:09:22 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_produceexp);
|
2016-03-09 23:20:05 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_academy_building);
|
2017-09-02 03:12:02 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_academy_bonus);
|
2016-03-13 13:31:54 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_demon_skillchanges);
|
2016-03-25 17:05:01 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_study_bug_2194);
|
2015-07-09 13:24:21 +02:00
|
|
|
return suite;
|
|
|
|
}
|