2015-05-06 17:36:20 +02:00
|
|
|
#include <platform.h>
|
2017-05-24 08:18:55 +02:00
|
|
|
|
|
|
|
#include "spells.h"
|
2017-10-10 18:45:44 +02:00
|
|
|
#include "teleport.h"
|
2017-05-24 08:18:55 +02:00
|
|
|
|
2015-05-06 17:36:20 +02:00
|
|
|
#include <kernel/config.h>
|
|
|
|
#include <kernel/curse.h>
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
#include <kernel/order.h>
|
2017-10-10 18:45:44 +02:00
|
|
|
#include <kernel/plane.h>
|
2016-09-25 13:01:51 +02:00
|
|
|
#include <kernel/race.h>
|
2015-05-06 17:36:20 +02:00
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/spell.h>
|
|
|
|
#include <kernel/unit.h>
|
2018-09-29 11:37:17 +02:00
|
|
|
#include <kernel/attrib.h>
|
2018-01-14 11:58:22 +01:00
|
|
|
#include <util/language.h>
|
|
|
|
#include <util/message.h>
|
2015-05-06 17:36:20 +02:00
|
|
|
#include <spells/regioncurse.h>
|
2017-05-24 08:18:55 +02:00
|
|
|
|
|
|
|
#include <attributes/attributes.h>
|
2015-05-06 17:36:20 +02:00
|
|
|
|
|
|
|
#include <CuTest.h>
|
|
|
|
#include <tests.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2015-08-07 18:30:02 +02:00
|
|
|
static void test_good_dreams(CuTest *tc) {
|
2015-05-06 17:36:20 +02:00
|
|
|
struct region *r;
|
|
|
|
struct faction *f1, *f2;
|
|
|
|
unit *u1, *u2;
|
|
|
|
int level;
|
2015-10-13 23:02:01 +02:00
|
|
|
castorder co;
|
2017-02-18 21:15:14 +01:00
|
|
|
curse *curse;
|
|
|
|
|
|
|
|
test_setup();
|
2015-05-06 17:36:20 +02:00
|
|
|
test_create_world();
|
2015-08-07 18:30:02 +02:00
|
|
|
r = findregion(0, 0);
|
2018-01-14 09:38:26 +01:00
|
|
|
f1 = test_create_faction(NULL);
|
|
|
|
f2 = test_create_faction(NULL);
|
2015-05-06 17:36:20 +02:00
|
|
|
u1 = test_create_unit(f1, r);
|
|
|
|
u2 = test_create_unit(f2, r);
|
|
|
|
|
2015-11-02 17:09:16 +01:00
|
|
|
test_create_castorder(&co, u1, 10, 10., 0, NULL);
|
2015-08-07 13:26:41 +02:00
|
|
|
|
2015-10-13 23:02:01 +02:00
|
|
|
level = sp_gooddreams(&co);
|
2015-05-06 17:36:20 +02:00
|
|
|
CuAssertIntEquals(tc, 10, level);
|
2017-08-21 20:18:19 +02:00
|
|
|
curse = get_curse(r->attribs, &ct_gbdream);
|
2015-05-06 17:36:20 +02:00
|
|
|
CuAssertTrue(tc, curse && curse->duration > 1);
|
|
|
|
CuAssertTrue(tc, curse->effect == 1);
|
|
|
|
|
2015-12-16 22:18:44 +01:00
|
|
|
a_age(&r->attribs, r);
|
2015-08-07 13:26:41 +02:00
|
|
|
CuAssertIntEquals_Msg(tc, "good dreams give +1 to allies", 1, get_modifier(u1, SK_MELEE, 11, r, false));
|
|
|
|
CuAssertIntEquals_Msg(tc, "good dreams have no effect on non-allies", 0, get_modifier(u2, SK_MELEE, 11, r, false));
|
2015-10-14 12:23:58 +02:00
|
|
|
free_castorder(&co);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-08-07 18:30:02 +02:00
|
|
|
}
|
2015-05-06 17:36:20 +02:00
|
|
|
|
2015-08-07 18:30:02 +02:00
|
|
|
static void test_dreams(CuTest *tc) {
|
|
|
|
struct region *r;
|
|
|
|
struct faction *f1, *f2;
|
|
|
|
unit *u1, *u2;
|
2015-10-13 23:02:01 +02:00
|
|
|
castorder co;
|
2015-05-06 17:36:20 +02:00
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_setup();
|
|
|
|
r = test_create_region(0, 0, NULL);
|
2018-01-14 09:38:26 +01:00
|
|
|
f1 = test_create_faction(NULL);
|
|
|
|
f2 = test_create_faction(NULL);
|
2015-08-07 18:30:02 +02:00
|
|
|
u1 = test_create_unit(f1, r);
|
|
|
|
u2 = test_create_unit(f2, r);
|
|
|
|
|
2015-11-02 17:09:16 +01:00
|
|
|
test_create_castorder(&co, u1, 10, 10., 0, NULL);
|
2015-05-06 17:36:20 +02:00
|
|
|
|
2015-10-13 23:02:01 +02:00
|
|
|
sp_gooddreams(&co);
|
|
|
|
sp_baddreams(&co);
|
2015-12-16 22:18:44 +01:00
|
|
|
a_age(&r->attribs, r);
|
2015-08-07 13:26:41 +02:00
|
|
|
CuAssertIntEquals_Msg(tc, "good dreams in same region as bad dreams", 1, get_modifier(u1, SK_MELEE, 11, r, false));
|
|
|
|
CuAssertIntEquals_Msg(tc, "bad dreams in same region as good dreams", -1, get_modifier(u2, SK_MELEE, 11, r, false));
|
2015-05-06 17:36:20 +02:00
|
|
|
|
2015-10-13 23:02:01 +02:00
|
|
|
free_castorder(&co);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-05-06 17:36:20 +02:00
|
|
|
}
|
|
|
|
|
2015-08-07 18:30:02 +02:00
|
|
|
static void test_bad_dreams(CuTest *tc) {
|
|
|
|
struct region *r;
|
|
|
|
struct faction *f1, *f2;
|
|
|
|
unit *u1, *u2;
|
|
|
|
int level;
|
2015-10-13 23:02:01 +02:00
|
|
|
castorder co;
|
2017-02-18 21:15:14 +01:00
|
|
|
curse *curse;
|
|
|
|
|
|
|
|
test_setup();
|
2015-08-07 18:30:02 +02:00
|
|
|
test_create_world();
|
|
|
|
r = findregion(0, 0);
|
2018-01-14 09:38:26 +01:00
|
|
|
f1 = test_create_faction(NULL);
|
|
|
|
f2 = test_create_faction(NULL);
|
2015-08-07 18:30:02 +02:00
|
|
|
u1 = test_create_unit(f1, r);
|
|
|
|
u2 = test_create_unit(f2, r);
|
|
|
|
|
2015-11-02 17:09:16 +01:00
|
|
|
test_create_castorder(&co, u1, 10, 10., 0, NULL);
|
2015-08-07 18:30:02 +02:00
|
|
|
|
2015-10-13 23:02:01 +02:00
|
|
|
level = sp_baddreams(&co);
|
2015-08-07 18:30:02 +02:00
|
|
|
CuAssertIntEquals(tc, 10, level);
|
2017-08-21 20:18:19 +02:00
|
|
|
curse = get_curse(r->attribs, &ct_gbdream);
|
2015-08-07 18:30:02 +02:00
|
|
|
CuAssertTrue(tc, curse && curse->duration > 1);
|
|
|
|
CuAssertTrue(tc, curse->effect == -1);
|
|
|
|
|
2015-12-16 22:18:44 +01:00
|
|
|
a_age(&r->attribs, r);
|
2015-08-07 18:30:02 +02:00
|
|
|
CuAssertIntEquals_Msg(tc, "bad dreams have no effect on allies", 0, get_modifier(u1, SK_MELEE, 11, r, false));
|
|
|
|
CuAssertIntEquals_Msg(tc, "bad dreams give -1 to non-allies", -1, get_modifier(u2, SK_MELEE, 11, r, false));
|
|
|
|
|
2015-10-13 23:02:01 +02:00
|
|
|
free_castorder(&co);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-08-07 18:30:02 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 18:45:44 +02:00
|
|
|
static void test_view_reality(CuTest *tc) {
|
|
|
|
region *r, *ra;
|
|
|
|
faction *f;
|
|
|
|
unit *u;
|
|
|
|
castorder co;
|
|
|
|
|
|
|
|
test_setup();
|
2018-05-18 19:58:49 +02:00
|
|
|
mt_create_va(mt_new("spell_astral_only", NULL),
|
|
|
|
"unit:unit", "region:region", "command:order", MT_NEW_END);
|
|
|
|
mt_create_va(mt_new("viewreality_effect", NULL),
|
|
|
|
"unit:unit", MT_NEW_END);
|
2017-10-10 18:45:44 +02:00
|
|
|
r = test_create_region(0, 0, NULL);
|
|
|
|
ra = test_create_region(real2tp(r->x), real2tp(r->y), NULL);
|
|
|
|
ra->_plane = get_astralplane();
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
2017-10-10 18:45:44 +02:00
|
|
|
u = test_create_unit(f, r);
|
|
|
|
|
|
|
|
test_create_castorder(&co, u, 10, 10., 0, NULL);
|
|
|
|
CuAssertIntEquals(tc, -1, get_observer(r, f));
|
|
|
|
CuAssertIntEquals(tc, 0, sp_viewreality(&co));
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "spell_astral_only"));
|
|
|
|
free_castorder(&co);
|
|
|
|
|
|
|
|
test_clear_messagelist(&f->msgs);
|
|
|
|
move_unit(u, ra, NULL);
|
|
|
|
|
|
|
|
test_create_castorder(&co, u, 9, 10., 0, NULL);
|
|
|
|
CuAssertIntEquals(tc, -1, get_observer(r, f));
|
|
|
|
CuAssertIntEquals(tc, 9, sp_viewreality(&co));
|
|
|
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "spell_astral_only"));
|
|
|
|
CuAssertIntEquals(tc, 4, get_observer(r, f));
|
|
|
|
CuAssertPtrEquals(tc, f, (void *)ra->individual_messages->viewer);
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(ra->individual_messages->msgs, "viewreality_effect"));
|
|
|
|
free_castorder(&co);
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-10-10 18:45:44 +02:00
|
|
|
}
|
|
|
|
|
2016-09-25 13:01:51 +02:00
|
|
|
static void test_watch_region(CuTest *tc) {
|
|
|
|
region *r;
|
|
|
|
faction *f;
|
|
|
|
test_setup();
|
2018-01-14 09:38:26 +01:00
|
|
|
r = test_create_region(0, 0, NULL);
|
|
|
|
f = test_create_faction(NULL);
|
2016-09-25 13:01:51 +02:00
|
|
|
CuAssertIntEquals(tc, -1, get_observer(r, f));
|
2017-05-24 08:18:55 +02:00
|
|
|
set_observer(r, f, 0, 2);
|
2016-09-25 13:01:51 +02:00
|
|
|
CuAssertIntEquals(tc, 0, get_observer(r, f));
|
2017-05-24 08:18:55 +02:00
|
|
|
set_observer(r, f, 10, 2);
|
2016-09-25 13:01:51 +02:00
|
|
|
CuAssertIntEquals(tc, 10, get_observer(r, f));
|
|
|
|
CuAssertIntEquals(tc, RF_OBSERVER, fval(r, RF_OBSERVER));
|
|
|
|
CuAssertPtrNotNull(tc, r->attribs);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-09-25 13:01:51 +02:00
|
|
|
}
|
|
|
|
|
2015-05-06 17:36:20 +02:00
|
|
|
CuSuite *get_spells_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
2016-09-25 13:01:51 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_watch_region);
|
2017-10-10 18:45:44 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_view_reality);
|
2015-08-07 18:30:02 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_good_dreams);
|
|
|
|
SUITE_ADD_TEST(suite, test_bad_dreams);
|
2015-05-06 17:36:20 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_dreams);
|
|
|
|
return suite;
|
|
|
|
}
|