2015-05-24 07:17:23 +02:00
|
|
|
#include <platform.h>
|
|
|
|
|
|
|
|
#include "xerewards.h"
|
2016-03-08 15:13:49 +01:00
|
|
|
#include "study.h"
|
2017-12-27 22:26:50 +01:00
|
|
|
#include "magic.h"
|
2015-05-24 07:17:23 +02:00
|
|
|
|
2017-12-27 22:26:50 +01:00
|
|
|
#include <kernel/faction.h>
|
2015-05-24 07:17:23 +02:00
|
|
|
#include <kernel/item.h>
|
|
|
|
#include <kernel/pool.h>
|
|
|
|
#include <kernel/region.h>
|
2017-12-27 22:26:50 +01:00
|
|
|
#include <kernel/unit.h>
|
2015-05-24 07:17:23 +02:00
|
|
|
|
|
|
|
#include <tests.h>
|
|
|
|
#include <CuTest.h>
|
|
|
|
|
|
|
|
static void test_manacrystal(CuTest *tc) {
|
2017-12-27 22:26:50 +01:00
|
|
|
struct item_type *itype;
|
|
|
|
unit *u;
|
2018-01-14 17:08:46 +01:00
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_setup();
|
2017-12-27 22:26:50 +01:00
|
|
|
|
2020-11-14 17:12:36 +01:00
|
|
|
u = test_create_unit(test_create_faction(), test_create_plain(0, 0));
|
2017-12-27 22:26:50 +01:00
|
|
|
itype = test_create_itemtype("manacrystal");
|
|
|
|
change_resource(u, itype->rtype, 1);
|
|
|
|
CuAssertIntEquals(tc, -1, use_manacrystal(u, itype, 1, NULL));
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error295"));
|
|
|
|
test_clear_messages(u->faction);
|
2018-11-18 21:53:45 +01:00
|
|
|
create_mage(u, M_GWYRRD);
|
2017-12-27 22:26:50 +01:00
|
|
|
set_level(u, SK_MAGIC, 5);
|
|
|
|
CuAssertIntEquals(tc, 0, get_spellpoints(u));
|
|
|
|
CuAssertIntEquals(tc, 1, use_manacrystal(u, itype, 1, NULL));
|
|
|
|
CuAssertIntEquals(tc, 25, get_spellpoints(u));
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "manacrystal_use"));
|
|
|
|
test_clear_messages(u->faction);
|
|
|
|
set_level(u, SK_MAGIC, 8);
|
|
|
|
CuAssertIntEquals(tc, 1, use_manacrystal(u, itype, 1, NULL));
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "manacrystal_use"));
|
|
|
|
CuAssertIntEquals(tc, 25 + 33, get_spellpoints(u));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-05-24 07:17:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_skillpotion(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
const struct item_type *itype;
|
2018-02-25 17:58:45 +01:00
|
|
|
skill* pSkill;
|
2015-11-01 17:38:12 +01:00
|
|
|
int initialWeeks_Entertainment = 0;
|
|
|
|
int initialWeeks_Stamina = 0;
|
|
|
|
int initialWeeks_Magic = 0;
|
2015-05-24 07:17:23 +02:00
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_setup();
|
2020-11-14 17:12:36 +01:00
|
|
|
u = test_create_unit(test_create_faction(), test_create_plain(0, 0));
|
2015-05-24 07:17:23 +02:00
|
|
|
itype = test_create_itemtype("skillpotion");
|
|
|
|
change_resource(u, itype->rtype, 2);
|
2015-10-31 19:03:15 +01:00
|
|
|
|
2020-09-11 21:28:29 +02:00
|
|
|
change_skill_days(u, SK_ENTERTAINMENT, STUDYDAYS * u->number);
|
2015-11-01 17:38:12 +01:00
|
|
|
pSkill = unit_skill(u, SK_ENTERTAINMENT);
|
|
|
|
sk_set(pSkill, 5);
|
2015-11-07 13:52:18 +01:00
|
|
|
initialWeeks_Entertainment = pSkill->weeks = 4;
|
2015-10-31 19:03:15 +01:00
|
|
|
|
2020-09-11 21:28:29 +02:00
|
|
|
change_skill_days(u, SK_STAMINA, STUDYDAYS * u->number);
|
2015-11-01 17:38:12 +01:00
|
|
|
pSkill = unit_skill(u, SK_STAMINA);
|
|
|
|
sk_set(pSkill, 5);
|
2015-11-07 13:52:18 +01:00
|
|
|
initialWeeks_Stamina = pSkill->weeks = 4;
|
2015-10-31 19:03:15 +01:00
|
|
|
|
2020-09-11 21:28:29 +02:00
|
|
|
change_skill_days(u, SK_MAGIC, STUDYDAYS * u->number);
|
2015-11-01 17:38:12 +01:00
|
|
|
pSkill = unit_skill(u, SK_MAGIC);
|
|
|
|
sk_set(pSkill, 5);
|
2015-11-07 13:52:18 +01:00
|
|
|
initialWeeks_Magic = pSkill->weeks = 4;
|
2015-10-31 19:03:15 +01:00
|
|
|
|
2015-05-24 07:17:23 +02:00
|
|
|
CuAssertIntEquals(tc, 1, use_skillpotion(u, itype, 1, NULL));
|
2015-10-31 19:03:15 +01:00
|
|
|
|
2015-11-01 17:38:12 +01:00
|
|
|
pSkill = unit_skill(u, SK_ENTERTAINMENT);
|
|
|
|
CuAssertIntEquals(tc, initialWeeks_Entertainment - 3, pSkill->weeks);
|
2015-10-31 19:03:15 +01:00
|
|
|
|
2015-11-01 17:38:12 +01:00
|
|
|
pSkill = unit_skill(u, SK_STAMINA);
|
|
|
|
CuAssertIntEquals(tc, initialWeeks_Stamina - 3, pSkill->weeks);
|
2015-10-31 19:03:15 +01:00
|
|
|
|
2015-11-01 17:38:12 +01:00
|
|
|
pSkill = unit_skill(u, SK_MAGIC);
|
|
|
|
CuAssertIntEquals(tc, initialWeeks_Magic - 3, pSkill->weeks);
|
2015-10-31 19:03:15 +01:00
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-05-24 07:17:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CuSuite *get_xerewards_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_manacrystal);
|
|
|
|
SUITE_ADD_TEST(suite, test_skillpotion);
|
|
|
|
return suite;
|
|
|
|
}
|
|
|
|
|