2016-08-23 07:38:44 +02:00
|
|
|
#include <platform.h>
|
2016-08-22 21:27:24 +02:00
|
|
|
#include <tests.h>
|
|
|
|
#include "volcano.h"
|
|
|
|
|
2016-08-28 11:05:34 +02:00
|
|
|
#include <kernel/faction.h>
|
2016-08-23 07:38:44 +02:00
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/terrain.h>
|
2016-08-28 11:05:34 +02:00
|
|
|
#include <kernel/unit.h>
|
2016-08-27 09:29:01 +02:00
|
|
|
#include <kernel/messages.h>
|
2016-08-23 07:44:17 +02:00
|
|
|
|
|
|
|
#include <util/attrib.h>
|
|
|
|
|
|
|
|
#include <attributes/reduceproduction.h>
|
|
|
|
|
2016-08-22 21:27:24 +02:00
|
|
|
#include <CuTest.h>
|
|
|
|
|
|
|
|
static void test_volcano_update(CuTest *tc) {
|
2016-08-23 07:38:44 +02:00
|
|
|
region *r;
|
2016-08-28 15:06:57 +02:00
|
|
|
message *m;
|
2016-08-23 07:38:44 +02:00
|
|
|
const struct terrain_type *t_volcano, *t_active;
|
|
|
|
|
2016-09-08 08:12:26 +02:00
|
|
|
test_setup();
|
2018-02-25 17:18:30 +01:00
|
|
|
mt_register(mt_new_va("volcanostopsmoke", "region:region", MT_NEW_END));
|
2016-08-23 07:38:44 +02:00
|
|
|
t_volcano = test_create_terrain("volcano", LAND_REGION);
|
|
|
|
t_active = test_create_terrain("activevolcano", LAND_REGION);
|
|
|
|
r = test_create_region(0, 0, t_active);
|
2016-08-23 07:44:17 +02:00
|
|
|
a_add(&r->attribs, make_reduceproduction(25, 10));
|
2016-08-23 07:53:29 +02:00
|
|
|
|
2016-08-22 21:27:24 +02:00
|
|
|
volcano_update();
|
2016-08-28 15:06:57 +02:00
|
|
|
CuAssertPtrNotNull(tc, m = test_find_messagetype(r->msgs, "volcanostopsmoke"));
|
|
|
|
CuAssertPtrEquals(tc, r, m->parameters[0].v);
|
2016-08-23 07:38:44 +02:00
|
|
|
CuAssertPtrEquals(tc, (void *)t_volcano, (void *)r->terrain);
|
2016-08-23 07:53:29 +02:00
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-08-23 07:53:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_volcano_outbreak(CuTest *tc) {
|
2016-08-26 18:26:26 +02:00
|
|
|
region *r, *rn;
|
2016-08-28 11:05:34 +02:00
|
|
|
unit *u1, *u2;
|
|
|
|
faction *f;
|
2016-08-27 09:29:01 +02:00
|
|
|
message *m;
|
2016-08-23 07:53:29 +02:00
|
|
|
const struct terrain_type *t_volcano, *t_active;
|
|
|
|
|
2016-09-08 08:12:26 +02:00
|
|
|
test_setup();
|
2018-02-25 17:18:30 +01:00
|
|
|
mt_register(mt_new_va("volcanooutbreak", "regionv:region", "regionn:region", MT_NEW_END));
|
|
|
|
mt_register(mt_new_va("volcanooutbreaknn", "region:region", MT_NEW_END));
|
|
|
|
mt_register(mt_new_va("volcano_dead", "unit:unit", "region:region", "dead:int", MT_NEW_END));
|
2016-08-23 07:53:29 +02:00
|
|
|
t_volcano = test_create_terrain("volcano", LAND_REGION);
|
|
|
|
t_active = test_create_terrain("activevolcano", LAND_REGION);
|
|
|
|
r = test_create_region(0, 0, t_active);
|
2016-08-26 18:26:26 +02:00
|
|
|
rn = test_create_region(1, 0, t_volcano);
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
2016-08-28 11:05:34 +02:00
|
|
|
u1 = test_create_unit(f, r);
|
|
|
|
u1->hp = u1->number;
|
|
|
|
u2 = test_create_unit(f, rn);
|
|
|
|
u2->hp = u2->number;
|
2016-08-26 18:26:26 +02:00
|
|
|
|
|
|
|
volcano_outbreak(r, rn);
|
2016-08-27 09:29:01 +02:00
|
|
|
CuAssertPtrEquals(tc, (void *)t_active, (void *)r->terrain);
|
2016-08-26 18:26:26 +02:00
|
|
|
CuAssertIntEquals(tc, 0, rtrees(r, 0));
|
|
|
|
CuAssertIntEquals(tc, 0, rtrees(r, 1));
|
|
|
|
CuAssertIntEquals(tc, 0, rtrees(r, 2));
|
2016-08-28 11:05:34 +02:00
|
|
|
CuAssertPtrNotNull(tc, a_find(r->attribs, &at_reduceproduction));
|
|
|
|
CuAssertPtrNotNull(tc, a_find(rn->attribs, &at_reduceproduction));
|
|
|
|
|
2016-08-27 09:29:01 +02:00
|
|
|
CuAssertPtrNotNull(tc, m = test_find_messagetype(rn->msgs, "volcanooutbreak"));
|
|
|
|
CuAssertPtrEquals(tc, r, m->parameters[0].v);
|
|
|
|
CuAssertPtrEquals(tc, rn, m->parameters[1].v);
|
2016-08-23 07:53:29 +02:00
|
|
|
|
2017-12-25 21:55:50 +01:00
|
|
|
CuAssertPtrNotNull(tc, m = test_find_messagetype(f->msgs, "volcanooutbreaknn"));
|
|
|
|
CuAssertPtrEquals(tc, r, m->parameters[0].v);
|
|
|
|
|
2016-08-28 11:05:34 +02:00
|
|
|
CuAssertPtrNotNull(tc, m = test_find_messagetype_ex(f->msgs, "volcano_dead", NULL));
|
2016-08-28 11:08:41 +02:00
|
|
|
CuAssertPtrEquals(tc, u1, m->parameters[0].v);
|
|
|
|
CuAssertPtrEquals(tc, r, m->parameters[1].v);
|
|
|
|
CuAssertIntEquals(tc, 1, m->parameters[2].i);
|
2016-08-28 11:05:34 +02:00
|
|
|
CuAssertPtrNotNull(tc, m = test_find_messagetype_ex(f->msgs, "volcano_dead", m));
|
2016-08-28 11:08:41 +02:00
|
|
|
CuAssertPtrEquals(tc, u2, m->parameters[0].v);
|
|
|
|
CuAssertPtrEquals(tc, r, m->parameters[1].v);
|
|
|
|
CuAssertIntEquals(tc, 1, m->parameters[2].i);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-08-22 21:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CuSuite *get_volcano_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_volcano_update);
|
2016-08-23 07:53:29 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_volcano_outbreak);
|
2016-08-22 21:27:24 +02:00
|
|
|
return suite;
|
|
|
|
}
|