2011-03-09 06:16:47 +01:00
|
|
|
#include <platform.h>
|
|
|
|
#include "laws.h"
|
2015-06-20 14:28:16 +02:00
|
|
|
#include "battle.h"
|
2016-11-01 22:11:10 +01:00
|
|
|
#include "guard.h"
|
2016-12-23 18:05:38 +01:00
|
|
|
#include "monsters.h"
|
2011-03-09 06:16:47 +01:00
|
|
|
|
2014-10-30 07:50:01 +01:00
|
|
|
#include <kernel/ally.h>
|
2017-03-11 20:03:49 +01:00
|
|
|
#include <kernel/alliance.h>
|
2011-03-09 06:16:47 +01:00
|
|
|
#include <kernel/config.h>
|
|
|
|
#include <kernel/building.h>
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
#include <kernel/item.h>
|
2015-02-01 19:14:06 +01:00
|
|
|
#include <kernel/messages.h>
|
2014-07-20 06:19:21 +02:00
|
|
|
#include <kernel/order.h>
|
2011-03-09 06:16:47 +01:00
|
|
|
#include <kernel/race.h>
|
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/ship.h>
|
|
|
|
#include <kernel/terrain.h>
|
2017-11-05 17:00:40 +01:00
|
|
|
#include <kernel/terrainid.h>
|
2011-03-09 06:16:47 +01:00
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
2015-02-01 19:14:06 +01:00
|
|
|
#include <util/attrib.h>
|
2014-12-17 21:31:02 +01:00
|
|
|
#include <util/base36.h>
|
2011-03-09 06:16:47 +01:00
|
|
|
#include <util/language.h>
|
2015-01-13 07:43:30 +01:00
|
|
|
#include <util/message.h>
|
2015-01-14 22:33:58 +01:00
|
|
|
#include <util/rand.h>
|
2011-03-09 06:16:47 +01:00
|
|
|
|
2012-05-31 04:17:08 +02:00
|
|
|
#include <CuTest.h>
|
2011-03-09 06:16:47 +01:00
|
|
|
#include <tests.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-20 06:19:21 +02:00
|
|
|
#include <assert.h>
|
2014-12-17 21:31:02 +01:00
|
|
|
#include <stdio.h>
|
2016-06-06 23:45:11 +02:00
|
|
|
#include <string.h>
|
2014-07-20 06:19:21 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void test_new_building_can_be_renamed(CuTest * tc)
|
|
|
|
{
|
2014-10-14 18:32:04 +02:00
|
|
|
region *r;
|
|
|
|
building *b;
|
2010-08-08 12:04:08 +02:00
|
|
|
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
|
|
|
test_create_locale();
|
|
|
|
r = test_create_region(0, 0, 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2017-03-10 21:29:37 +01:00
|
|
|
b = test_create_building(r, NULL);
|
2014-10-14 18:32:04 +02:00
|
|
|
CuAssertTrue(tc, !renamed_building(b));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void test_rename_building(CuTest * tc)
|
|
|
|
{
|
2014-10-14 18:32:04 +02:00
|
|
|
region *r;
|
|
|
|
building *b;
|
|
|
|
unit *u;
|
|
|
|
faction *f;
|
|
|
|
building_type *btype;
|
2010-08-11 08:33:38 +02:00
|
|
|
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2017-03-10 21:43:36 +01:00
|
|
|
test_create_locale();
|
2017-03-10 21:29:37 +01:00
|
|
|
btype = test_create_buildingtype("castle");
|
|
|
|
r = test_create_region(0, 0, 0);
|
2014-10-14 18:32:04 +02:00
|
|
|
b = new_building(btype, r, default_locale);
|
|
|
|
f = test_create_faction(NULL);
|
|
|
|
u = test_create_unit(f, r);
|
|
|
|
u_set_building(u, b);
|
2010-08-11 08:33:38 +02:00
|
|
|
|
2014-10-14 18:32:04 +02:00
|
|
|
rename_building(u, NULL, b, "Villa Nagel");
|
|
|
|
CuAssertStrEquals(tc, "Villa Nagel", b->name);
|
2014-10-29 21:08:16 +01:00
|
|
|
CuAssertTrue(tc, renamed_building(b));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2010-08-11 08:33:38 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void test_rename_building_twice(CuTest * tc)
|
|
|
|
{
|
2014-10-14 18:32:04 +02:00
|
|
|
region *r;
|
|
|
|
unit *u;
|
|
|
|
faction *f;
|
2014-10-30 07:50:01 +01:00
|
|
|
building *b;
|
2014-10-14 18:32:04 +02:00
|
|
|
building_type *btype;
|
2010-08-18 07:32:36 +02:00
|
|
|
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2017-03-10 21:43:36 +01:00
|
|
|
test_create_locale();
|
2017-03-10 21:29:37 +01:00
|
|
|
btype = test_create_buildingtype("castle");
|
|
|
|
r = test_create_region(0, 0, 0);
|
2014-10-14 18:32:04 +02:00
|
|
|
b = new_building(btype, r, default_locale);
|
|
|
|
f = test_create_faction(NULL);
|
|
|
|
u = test_create_unit(f, r);
|
|
|
|
u_set_building(u, b);
|
2010-08-18 07:32:36 +02:00
|
|
|
|
2014-10-14 18:32:04 +02:00
|
|
|
rename_building(u, NULL, b, "Villa Nagel");
|
|
|
|
CuAssertStrEquals(tc, "Villa Nagel", b->name);
|
2010-08-18 07:32:36 +02:00
|
|
|
|
2014-10-14 18:32:04 +02:00
|
|
|
rename_building(u, NULL, b, "Villa Kunterbunt");
|
|
|
|
CuAssertStrEquals(tc, "Villa Kunterbunt", b->name);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2010-08-18 07:32:36 +02:00
|
|
|
}
|
|
|
|
|
2014-10-30 07:50:01 +01:00
|
|
|
static void test_contact(CuTest * tc)
|
|
|
|
{
|
|
|
|
region *r;
|
|
|
|
unit *u1, *u2, *u3;
|
|
|
|
building *b;
|
|
|
|
building_type *btype;
|
2014-10-31 15:13:05 +01:00
|
|
|
ally *al;
|
2014-10-30 07:50:01 +01:00
|
|
|
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2017-03-10 21:43:36 +01:00
|
|
|
test_create_locale();
|
2017-03-10 21:29:37 +01:00
|
|
|
btype = test_create_buildingtype("castle");
|
|
|
|
r = test_create_region(0, 0, 0);
|
2014-10-30 07:50:01 +01:00
|
|
|
b = new_building(btype, r, default_locale);
|
|
|
|
u1 = test_create_unit(test_create_faction(0), r);
|
|
|
|
u2 = test_create_unit(test_create_faction(0), r);
|
|
|
|
u3 = test_create_unit(test_create_faction(0), r);
|
|
|
|
set_level(u3, SK_PERCEPTION, 2);
|
|
|
|
usetsiege(u3, b);
|
|
|
|
b->besieged = 1;
|
|
|
|
CuAssertIntEquals(tc, 1, can_contact(r, u1, u2));
|
|
|
|
|
|
|
|
u_set_building(u1, b);
|
|
|
|
CuAssertIntEquals(tc, 0, can_contact(r, u1, u2));
|
2014-10-31 15:13:05 +01:00
|
|
|
al = ally_add(&u1->faction->allies, u2->faction);
|
|
|
|
al->status = HELP_ALL;
|
2014-10-30 07:50:01 +01:00
|
|
|
CuAssertIntEquals(tc, HELP_GIVE, can_contact(r, u1, u2));
|
|
|
|
u_set_building(u2, b);
|
|
|
|
CuAssertIntEquals(tc, 1, can_contact(r, u1, u2));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-10-30 07:50:01 +01:00
|
|
|
}
|
|
|
|
|
2014-11-21 16:39:49 +01:00
|
|
|
static void test_enter_building(CuTest * tc)
|
|
|
|
{
|
|
|
|
unit *u;
|
|
|
|
region *r;
|
|
|
|
building *b;
|
|
|
|
race * rc;
|
|
|
|
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2017-03-10 21:43:36 +01:00
|
|
|
test_create_locale();
|
2017-03-10 21:29:37 +01:00
|
|
|
r = test_create_region(0, 0, 0);
|
2017-03-10 21:43:36 +01:00
|
|
|
rc = test_create_race("human");
|
2014-11-21 16:39:49 +01:00
|
|
|
u = test_create_unit(test_create_faction(rc), r);
|
2017-03-10 21:29:37 +01:00
|
|
|
b = test_create_building(r, test_create_buildingtype("castle"));
|
2014-11-21 16:39:49 +01:00
|
|
|
|
|
|
|
rc->flags = RCF_WALK;
|
|
|
|
u->building = 0;
|
2014-11-21 17:13:45 +01:00
|
|
|
CuAssertIntEquals(tc, 1, enter_building(u, NULL, b->no, false));
|
2014-11-21 16:39:49 +01:00
|
|
|
CuAssertPtrEquals(tc, b, u->building);
|
|
|
|
|
|
|
|
rc->flags = RCF_FLY;
|
|
|
|
u->building = 0;
|
2014-11-21 17:13:45 +01:00
|
|
|
CuAssertIntEquals(tc, 1, enter_building(u, NULL, b->no, false));
|
2014-11-21 16:39:49 +01:00
|
|
|
CuAssertPtrEquals(tc, b, u->building);
|
|
|
|
|
|
|
|
rc->flags = RCF_SWIM;
|
|
|
|
u->building = 0;
|
2014-11-21 17:13:45 +01:00
|
|
|
CuAssertIntEquals(tc, 0, enter_building(u, NULL, b->no, false));
|
2014-11-21 16:39:49 +01:00
|
|
|
CuAssertPtrEquals(tc, 0, u->building);
|
2014-11-21 17:13:45 +01:00
|
|
|
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
|
|
|
|
|
|
|
CuAssertIntEquals(tc, 0, enter_building(u, NULL, b->no, true));
|
|
|
|
CuAssertPtrNotNull(tc, u->faction->msgs);
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-11-21 17:13:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_enter_ship(CuTest * tc)
|
|
|
|
{
|
|
|
|
unit *u;
|
|
|
|
region *r;
|
|
|
|
ship *sh;
|
|
|
|
race * rc;
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_setup();
|
2014-11-21 17:13:45 +01:00
|
|
|
|
2017-12-27 22:30:07 +01:00
|
|
|
r = test_create_region(0, 0, NULL);
|
|
|
|
rc = test_create_race("smurf");
|
2014-11-21 17:13:45 +01:00
|
|
|
u = test_create_unit(test_create_faction(rc), r);
|
2017-12-27 22:30:07 +01:00
|
|
|
sh = test_create_ship(r, NULL);
|
2014-11-21 17:13:45 +01:00
|
|
|
|
|
|
|
rc->flags = RCF_WALK;
|
|
|
|
u->ship = 0;
|
|
|
|
CuAssertIntEquals(tc, 1, enter_ship(u, NULL, sh->no, false));
|
|
|
|
CuAssertPtrEquals(tc, sh, u->ship);
|
|
|
|
|
|
|
|
rc->flags = RCF_FLY;
|
|
|
|
u->ship = 0;
|
|
|
|
CuAssertIntEquals(tc, 1, enter_ship(u, NULL, sh->no, false));
|
|
|
|
CuAssertPtrEquals(tc, sh, u->ship);
|
|
|
|
|
|
|
|
rc->flags = RCF_CANSAIL;
|
|
|
|
u->ship = 0;
|
|
|
|
CuAssertIntEquals(tc, 1, enter_ship(u, NULL, sh->no, false));
|
|
|
|
CuAssertPtrEquals(tc, sh, u->ship);
|
|
|
|
|
|
|
|
rc->flags = RCF_SWIM;
|
|
|
|
u->ship = 0;
|
|
|
|
CuAssertIntEquals(tc, 0, enter_ship(u, NULL, sh->no, false));
|
|
|
|
CuAssertPtrEquals(tc, 0, u->ship);
|
|
|
|
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
|
|
|
|
|
|
|
CuAssertIntEquals(tc, 0, enter_ship(u, NULL, sh->no, true));
|
|
|
|
CuAssertPtrNotNull(tc, u->faction->msgs);
|
2014-11-21 16:39:49 +01:00
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-11-21 16:39:49 +01:00
|
|
|
}
|
|
|
|
|
2014-12-20 22:18:38 +01:00
|
|
|
static void test_display_cmd(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
faction *f;
|
|
|
|
region *r;
|
|
|
|
order *ord;
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_setup();
|
2014-12-20 22:18:38 +01:00
|
|
|
r = test_create_region(0, 0, test_create_terrain("plain", LAND_REGION));
|
|
|
|
f = test_create_faction(0);
|
|
|
|
assert(r && f);
|
|
|
|
u = test_create_unit(f, r);
|
|
|
|
assert(u);
|
|
|
|
|
2016-03-23 22:24:11 +01:00
|
|
|
ord = create_order(K_DISPLAY, f->locale, "%s Hodor", LOC(f->locale, parameters[P_UNIT]));
|
2014-12-20 22:18:38 +01:00
|
|
|
CuAssertIntEquals(tc, 0, display_cmd(u, ord));
|
|
|
|
CuAssertStrEquals(tc, "Hodor", u->display);
|
|
|
|
free_order(ord);
|
|
|
|
|
2016-03-23 22:24:11 +01:00
|
|
|
ord = create_order(K_DISPLAY, f->locale, LOC(f->locale, parameters[P_UNIT]));
|
2014-12-20 22:18:38 +01:00
|
|
|
CuAssertIntEquals(tc, 0, display_cmd(u, ord));
|
|
|
|
CuAssertPtrEquals(tc, NULL, u->display);
|
|
|
|
free_order(ord);
|
|
|
|
|
2017-01-25 21:03:08 +01:00
|
|
|
ord = create_order(K_DISPLAY, f->locale, "%s Hodor", LOC(f->locale, parameters[P_REGION]));
|
|
|
|
CuAssertIntEquals(tc, 0, display_cmd(u, ord));
|
2017-09-16 07:58:57 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, r->land->display);
|
2017-01-25 21:03:08 +01:00
|
|
|
free_order(ord);
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-12-20 22:18:38 +01:00
|
|
|
}
|
|
|
|
|
2015-06-19 07:53:11 +02:00
|
|
|
static void test_rule_force_leave(CuTest *tc) {
|
2017-03-11 12:57:02 +01:00
|
|
|
test_setup();
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.owners.force_leave", "0");
|
2015-06-19 07:53:11 +02:00
|
|
|
CuAssertIntEquals(tc, false, rule_force_leave(FORCE_LEAVE_ALL));
|
|
|
|
CuAssertIntEquals(tc, false, rule_force_leave(FORCE_LEAVE_POSTCOMBAT));
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.owners.force_leave", "1");
|
2015-06-19 07:53:11 +02:00
|
|
|
CuAssertIntEquals(tc, false, rule_force_leave(FORCE_LEAVE_ALL));
|
|
|
|
CuAssertIntEquals(tc, true, rule_force_leave(FORCE_LEAVE_POSTCOMBAT));
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.owners.force_leave", "2");
|
2015-06-19 07:53:11 +02:00
|
|
|
CuAssertIntEquals(tc, true, rule_force_leave(FORCE_LEAVE_ALL));
|
|
|
|
CuAssertIntEquals(tc, false, rule_force_leave(FORCE_LEAVE_POSTCOMBAT));
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.owners.force_leave", "3");
|
2015-06-19 07:53:11 +02:00
|
|
|
CuAssertIntEquals(tc, true, rule_force_leave(FORCE_LEAVE_ALL));
|
|
|
|
CuAssertIntEquals(tc, true, rule_force_leave(FORCE_LEAVE_POSTCOMBAT));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-06-19 07:53:11 +02:00
|
|
|
}
|
|
|
|
|
2015-01-05 18:14:55 +01:00
|
|
|
static void test_force_leave_buildings(CuTest *tc) {
|
|
|
|
ally *al;
|
|
|
|
region *r;
|
|
|
|
unit *u1, *u2, *u3;
|
|
|
|
building * b;
|
2017-03-11 12:57:02 +01:00
|
|
|
|
|
|
|
test_setup();
|
2018-01-12 21:15:21 +01:00
|
|
|
mt_register(mt_new_va("force_leave_building", "unit:unit", "owner:unit", "building:building", NULL));
|
2015-01-05 18:14:55 +01:00
|
|
|
r = test_create_region(0, 0, test_create_terrain("plain", LAND_REGION));
|
|
|
|
u1 = test_create_unit(test_create_faction(NULL), r);
|
|
|
|
u2 = test_create_unit(u1->faction, r);
|
|
|
|
u3 = test_create_unit(test_create_faction(NULL), r);
|
|
|
|
b = test_create_building(r, NULL);
|
|
|
|
u_set_building(u1, b);
|
|
|
|
building_set_owner(u1);
|
|
|
|
u_set_building(u2, b);
|
|
|
|
u_set_building(u3, b);
|
2015-06-20 14:28:16 +02:00
|
|
|
force_leave(r, NULL);
|
|
|
|
CuAssertPtrEquals_Msg(tc, "owner should not be forced to leave", b, u1->building);
|
2015-01-05 18:14:55 +01:00
|
|
|
CuAssertPtrEquals_Msg(tc, "same faction should not be forced to leave", b, u2->building);
|
|
|
|
CuAssertPtrEquals_Msg(tc, "non-allies should be forced to leave", NULL, u3->building);
|
2018-01-12 21:15:21 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u3->faction->msgs, "force_leave_building"));
|
2015-01-05 18:14:55 +01:00
|
|
|
|
|
|
|
u_set_building(u3, b);
|
|
|
|
al = ally_add(&u1->faction->allies, u3->faction);
|
|
|
|
al->status = HELP_GUARD;
|
2015-06-20 14:28:16 +02:00
|
|
|
force_leave(r, NULL);
|
2015-01-05 18:14:55 +01:00
|
|
|
CuAssertPtrEquals_Msg(tc, "allies should not be forced to leave", b, u3->building);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-01-05 18:14:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_force_leave_ships(CuTest *tc) {
|
|
|
|
region *r;
|
|
|
|
unit *u1, *u2;
|
|
|
|
ship *sh;
|
2017-03-11 12:57:02 +01:00
|
|
|
|
|
|
|
test_setup();
|
2018-01-12 21:15:21 +01:00
|
|
|
mt_register(mt_new_va("force_leave_ship", "unit:unit", "owner:unit", "ship:ship", NULL));
|
2015-01-05 18:14:55 +01:00
|
|
|
r = test_create_region(0, 0, test_create_terrain("plain", LAND_REGION));
|
|
|
|
u1 = test_create_unit(test_create_faction(NULL), r);
|
|
|
|
u2 = test_create_unit(test_create_faction(NULL), r);
|
|
|
|
sh = test_create_ship(r, NULL);
|
|
|
|
u_set_ship(u1, sh);
|
|
|
|
u_set_ship(u2, sh);
|
|
|
|
ship_set_owner(u1);
|
2015-06-20 14:28:16 +02:00
|
|
|
force_leave(r, NULL);
|
2015-01-05 18:14:55 +01:00
|
|
|
CuAssertPtrEquals_Msg(tc, "non-allies should be forced to leave", NULL, u2->ship);
|
2018-01-12 21:15:21 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u2->faction->msgs, "force_leave_ship"));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-01-05 18:14:55 +01:00
|
|
|
}
|
|
|
|
|
2015-01-05 22:09:08 +01:00
|
|
|
static void test_force_leave_ships_on_ocean(CuTest *tc) {
|
|
|
|
region *r;
|
|
|
|
unit *u1, *u2;
|
|
|
|
ship *sh;
|
2017-03-11 12:57:02 +01:00
|
|
|
|
|
|
|
test_setup();
|
2017-12-27 22:38:14 +01:00
|
|
|
r = test_create_ocean(0, 0);
|
2015-01-05 22:09:08 +01:00
|
|
|
u1 = test_create_unit(test_create_faction(NULL), r);
|
|
|
|
u2 = test_create_unit(test_create_faction(NULL), r);
|
|
|
|
sh = test_create_ship(r, NULL);
|
|
|
|
u_set_ship(u1, sh);
|
|
|
|
u_set_ship(u2, sh);
|
|
|
|
ship_set_owner(u1);
|
2015-06-20 14:28:16 +02:00
|
|
|
force_leave(r, NULL);
|
2015-01-05 22:09:08 +01:00
|
|
|
CuAssertPtrEquals_Msg(tc, "no forcing out of ships on oceans", sh, u2->ship);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-01-05 22:09:08 +01:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void test_fishing_feeds_2_people(CuTest * tc)
|
|
|
|
{
|
2017-12-27 22:38:14 +01:00
|
|
|
const item_type *itype;
|
2014-06-25 07:44:05 +02:00
|
|
|
region *r;
|
|
|
|
faction *f;
|
|
|
|
unit *u;
|
|
|
|
ship *sh;
|
2014-10-14 18:32:04 +02:00
|
|
|
|
2017-03-11 12:57:02 +01:00
|
|
|
test_setup();
|
2017-12-27 22:38:14 +01:00
|
|
|
r = test_create_ocean(0, 0);
|
2014-10-14 18:32:04 +02:00
|
|
|
f = test_create_faction(NULL);
|
2014-06-25 07:44:05 +02:00
|
|
|
u = test_create_unit(f, r);
|
2017-12-27 22:38:14 +01:00
|
|
|
sh = test_create_ship(r, NULL);
|
2014-06-25 07:44:05 +02:00
|
|
|
u_set_ship(u, sh);
|
2017-12-27 22:38:14 +01:00
|
|
|
itype = test_create_silver();
|
|
|
|
i_change(&u->items, itype, 42);
|
2014-10-14 18:32:04 +02:00
|
|
|
|
2014-06-25 07:44:05 +02:00
|
|
|
scale_number(u, 1);
|
|
|
|
sh->flags |= SF_FISHING;
|
|
|
|
get_food(r);
|
2017-12-27 22:38:14 +01:00
|
|
|
CuAssertIntEquals(tc, 42, i_get(u->items, itype));
|
2014-06-25 07:44:05 +02:00
|
|
|
|
|
|
|
scale_number(u, 2);
|
|
|
|
sh->flags |= SF_FISHING;
|
|
|
|
get_food(r);
|
2017-12-27 22:38:14 +01:00
|
|
|
CuAssertIntEquals(tc, 42, i_get(u->items, itype));
|
2014-06-25 07:44:05 +02:00
|
|
|
|
|
|
|
scale_number(u, 3);
|
|
|
|
sh->flags |= SF_FISHING;
|
|
|
|
get_food(r);
|
2017-12-27 22:38:14 +01:00
|
|
|
CuAssertIntEquals(tc, 32, i_get(u->items, itype));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void test_fishing_does_not_give_goblins_money(CuTest * tc)
|
|
|
|
{
|
2017-12-27 22:38:14 +01:00
|
|
|
const item_type *itype;
|
2014-06-25 07:44:05 +02:00
|
|
|
region *r;
|
|
|
|
faction *f;
|
|
|
|
unit *u;
|
|
|
|
ship *sh;
|
2014-10-14 18:32:04 +02:00
|
|
|
|
2017-03-11 12:57:02 +01:00
|
|
|
test_setup();
|
2017-12-27 22:38:14 +01:00
|
|
|
itype = test_create_silver();
|
2014-10-14 18:32:04 +02:00
|
|
|
|
2017-12-27 22:38:14 +01:00
|
|
|
r = test_create_ocean(0, 0);
|
2014-10-14 18:32:04 +02:00
|
|
|
f = test_create_faction(NULL);
|
2014-06-25 07:44:05 +02:00
|
|
|
u = test_create_unit(f, r);
|
2017-12-27 22:38:14 +01:00
|
|
|
sh = test_create_ship(r, NULL);
|
2014-06-25 07:44:05 +02:00
|
|
|
u_set_ship(u, sh);
|
2017-12-27 22:38:14 +01:00
|
|
|
i_change(&u->items, itype, 42);
|
2014-06-25 07:44:05 +02:00
|
|
|
|
|
|
|
scale_number(u, 2);
|
|
|
|
sh->flags |= SF_FISHING;
|
|
|
|
get_food(r);
|
2017-12-27 22:38:14 +01:00
|
|
|
CuAssertIntEquals(tc, 42, i_get(u->items, itype));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void test_fishing_gets_reset(CuTest * tc)
|
|
|
|
{
|
2017-12-27 22:38:14 +01:00
|
|
|
const item_type *itype;
|
2014-06-25 07:44:05 +02:00
|
|
|
region *r;
|
|
|
|
faction *f;
|
|
|
|
unit *u;
|
|
|
|
ship *sh;
|
2014-10-14 18:32:04 +02:00
|
|
|
|
2017-03-11 12:57:02 +01:00
|
|
|
test_setup();
|
2017-12-27 22:38:14 +01:00
|
|
|
itype = test_create_silver();
|
|
|
|
|
|
|
|
r = test_create_ocean(0, 0);
|
2014-10-14 18:32:04 +02:00
|
|
|
f = test_create_faction(NULL);
|
2014-06-25 07:44:05 +02:00
|
|
|
u = test_create_unit(f, r);
|
2017-12-27 22:38:14 +01:00
|
|
|
sh = test_create_ship(r, NULL);
|
2014-06-25 07:44:05 +02:00
|
|
|
u_set_ship(u, sh);
|
2017-12-27 22:38:14 +01:00
|
|
|
i_change(&u->items, itype, 42);
|
2014-10-14 18:32:04 +02:00
|
|
|
|
2014-06-25 07:44:05 +02:00
|
|
|
scale_number(u, 1);
|
|
|
|
sh->flags |= SF_FISHING;
|
|
|
|
get_food(r);
|
2017-12-27 22:38:14 +01:00
|
|
|
CuAssertIntEquals(tc, 42, i_get(u->items, itype));
|
2014-10-14 18:32:04 +02:00
|
|
|
|
2014-06-25 07:44:05 +02:00
|
|
|
scale_number(u, 1);
|
|
|
|
get_food(r);
|
2017-12-27 22:38:14 +01:00
|
|
|
CuAssertIntEquals(tc, 32, i_get(u->items, itype));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void test_unit_limit(CuTest * tc)
|
|
|
|
{
|
2017-03-11 12:57:02 +01:00
|
|
|
test_setup();
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.limit.faction", "250");
|
2014-10-14 18:32:04 +02:00
|
|
|
CuAssertIntEquals(tc, 250, rule_faction_limit());
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.limit.faction", "200");
|
2014-10-14 18:32:04 +02:00
|
|
|
CuAssertIntEquals(tc, 200, rule_faction_limit());
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.limit.alliance", "250");
|
2014-10-14 18:32:04 +02:00
|
|
|
CuAssertIntEquals(tc, 250, rule_alliance_limit());
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2017-10-01 15:08:26 +02:00
|
|
|
static void test_maketemp(CuTest * tc)
|
|
|
|
{
|
|
|
|
faction *f;
|
|
|
|
unit *u, *u2;
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
f = test_create_faction(NULL);
|
|
|
|
u = test_create_unit(f, test_create_region(0, 0, NULL));
|
|
|
|
|
|
|
|
u->orders = create_order(K_MAKETEMP, f->locale, "1");
|
|
|
|
u->orders->next = create_order(K_ENTERTAIN, f->locale, NULL);
|
|
|
|
u->orders->next->next = create_order(K_END, f->locale, NULL);
|
|
|
|
u->orders->next->next->next = create_order(K_TAX, f->locale, NULL);
|
|
|
|
|
|
|
|
new_units();
|
|
|
|
CuAssertIntEquals(tc, 2, f->num_units);
|
|
|
|
CuAssertPtrNotNull(tc, u2 = u->next);
|
|
|
|
CuAssertPtrNotNull(tc, u2->orders);
|
|
|
|
CuAssertPtrEquals(tc, NULL, u2->orders->next);
|
|
|
|
CuAssertIntEquals(tc, K_ENTERTAIN, getkeyword(u2->orders));
|
|
|
|
|
|
|
|
CuAssertPtrNotNull(tc, u->orders);
|
|
|
|
CuAssertPtrEquals(tc, NULL, u->orders->next);
|
|
|
|
CuAssertIntEquals(tc, K_TAX, getkeyword(u->orders));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-10-01 15:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_maketemp_default_order(CuTest * tc)
|
|
|
|
{
|
|
|
|
faction *f;
|
|
|
|
unit *u, *u2;
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
config_set("orders.default", "work");
|
|
|
|
f = test_create_faction(NULL);
|
|
|
|
u = test_create_unit(f, test_create_region(0, 0, NULL));
|
|
|
|
|
|
|
|
new_units();
|
|
|
|
CuAssertIntEquals(tc, 1, f->num_units);
|
|
|
|
|
|
|
|
u->orders = create_order(K_MAKETEMP, f->locale, "1");
|
|
|
|
u->orders->next = create_order(K_END, f->locale, NULL);
|
|
|
|
u->orders->next->next = create_order(K_TAX, f->locale, NULL);
|
|
|
|
|
|
|
|
new_units();
|
|
|
|
CuAssertIntEquals(tc, 2, f->num_units);
|
|
|
|
CuAssertPtrNotNull(tc, u2 = u->next);
|
|
|
|
CuAssertPtrNotNull(tc, u2->orders);
|
|
|
|
CuAssertPtrEquals(tc, NULL, u2->orders->next);
|
|
|
|
CuAssertIntEquals(tc, K_WORK, getkeyword(u2->orders));
|
|
|
|
|
|
|
|
CuAssertPtrNotNull(tc, u->orders);
|
|
|
|
CuAssertPtrEquals(tc, NULL, u->orders->next);
|
|
|
|
CuAssertIntEquals(tc, K_TAX, getkeyword(u->orders));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-10-01 15:08:26 +02:00
|
|
|
}
|
|
|
|
|
2017-03-11 20:03:49 +01:00
|
|
|
static void test_limit_new_units(CuTest * tc)
|
|
|
|
{
|
|
|
|
faction *f;
|
|
|
|
unit *u;
|
|
|
|
alliance *al;
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
al = makealliance(1, "Hodor");
|
|
|
|
f = test_create_faction(NULL);
|
|
|
|
u = test_create_unit(f, test_create_region(0, 0, NULL));
|
|
|
|
CuAssertIntEquals(tc, 1, f->num_units);
|
|
|
|
CuAssertIntEquals(tc, 1, f->num_people);
|
|
|
|
scale_number(u, 10);
|
|
|
|
CuAssertIntEquals(tc, 10, f->num_people);
|
|
|
|
config_set("rules.limit.faction", "2");
|
|
|
|
|
|
|
|
u->orders = create_order(K_MAKETEMP, f->locale, "1");
|
|
|
|
new_units();
|
|
|
|
CuAssertPtrNotNull(tc, u->next);
|
|
|
|
CuAssertIntEquals(tc, 2, f->num_units);
|
|
|
|
|
2017-10-01 15:08:26 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, u->orders);
|
|
|
|
u->orders = create_order(K_MAKETEMP, f->locale, "1");
|
2017-03-11 20:03:49 +01:00
|
|
|
new_units();
|
|
|
|
CuAssertIntEquals(tc, 2, f->num_units);
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "too_many_units_in_faction"));
|
|
|
|
|
|
|
|
setalliance(f, al);
|
|
|
|
|
|
|
|
config_set("rules.limit.faction", "3");
|
|
|
|
config_set("rules.limit.alliance", "2");
|
|
|
|
|
2017-10-01 15:08:26 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, u->orders);
|
|
|
|
u->orders = create_order(K_MAKETEMP, f->locale, "1");
|
2017-03-11 20:03:49 +01:00
|
|
|
new_units();
|
|
|
|
CuAssertIntEquals(tc, 2, f->num_units);
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "too_many_units_in_alliance"));
|
|
|
|
|
|
|
|
config_set("rules.limit.alliance", "3");
|
|
|
|
u = test_create_unit(test_create_faction(NULL), u->region);
|
|
|
|
setalliance(u->faction, al);
|
|
|
|
|
2017-10-01 15:08:26 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, u->orders);
|
|
|
|
u->orders = create_order(K_MAKETEMP, f->locale, "1");
|
2017-03-11 20:03:49 +01:00
|
|
|
new_units();
|
|
|
|
CuAssertIntEquals(tc, 2, f->num_units);
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "too_many_units_in_alliance"));
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-03-11 20:03:49 +01:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void test_cannot_create_unit_above_limit(CuTest * tc)
|
|
|
|
{
|
2014-10-14 18:32:04 +02:00
|
|
|
faction *f;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2017-03-11 12:57:02 +01:00
|
|
|
test_setup();
|
2014-10-14 18:32:04 +02:00
|
|
|
test_create_world();
|
|
|
|
f = test_create_faction(NULL);
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.limit.faction", "4");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-10-14 18:32:04 +02:00
|
|
|
CuAssertIntEquals(tc, 0, checkunitnumber(f, 4));
|
|
|
|
CuAssertIntEquals(tc, 2, checkunitnumber(f, 5));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.limit.alliance", "3");
|
2014-10-14 18:32:04 +02:00
|
|
|
CuAssertIntEquals(tc, 0, checkunitnumber(f, 3));
|
|
|
|
CuAssertIntEquals(tc, 1, checkunitnumber(f, 4));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-07-20 06:19:21 +02:00
|
|
|
static void test_reserve_cmd(CuTest *tc) {
|
|
|
|
unit *u1, *u2;
|
|
|
|
faction *f;
|
|
|
|
region *r;
|
|
|
|
order *ord;
|
|
|
|
const resource_type *rtype;
|
|
|
|
|
2017-03-11 12:57:02 +01:00
|
|
|
test_setup();
|
2014-07-20 06:19:21 +02:00
|
|
|
test_create_world();
|
|
|
|
|
|
|
|
rtype = get_resourcetype(R_SILVER);
|
|
|
|
assert(rtype && rtype->itype);
|
2014-10-14 18:32:04 +02:00
|
|
|
f = test_create_faction(NULL);
|
2014-07-20 06:19:21 +02:00
|
|
|
r = findregion(0, 0);
|
|
|
|
assert(r && f);
|
|
|
|
u1 = test_create_unit(f, r);
|
|
|
|
u2 = test_create_unit(f, r);
|
|
|
|
assert(u1 && u2);
|
2014-12-17 19:53:19 +01:00
|
|
|
ord = create_order(K_RESERVE, f->locale, "200 SILBER");
|
2014-07-20 06:19:21 +02:00
|
|
|
assert(ord);
|
|
|
|
i_change(&u1->items, rtype->itype, 100);
|
|
|
|
i_change(&u2->items, rtype->itype, 100);
|
|
|
|
CuAssertIntEquals(tc, 200, reserve_cmd(u1, ord));
|
|
|
|
CuAssertIntEquals(tc, 200, i_get(u1->items, rtype->itype));
|
|
|
|
CuAssertIntEquals(tc, 0, i_get(u2->items, rtype->itype));
|
2015-10-13 15:45:38 +02:00
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-07-20 06:19:21 +02:00
|
|
|
}
|
|
|
|
|
2014-12-17 19:53:19 +01:00
|
|
|
struct pay_fixture {
|
|
|
|
unit *u1;
|
|
|
|
unit *u2;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void setup_pay_cmd(struct pay_fixture *fix) {
|
|
|
|
faction *f;
|
|
|
|
region *r;
|
|
|
|
building *b;
|
2014-12-17 21:31:02 +01:00
|
|
|
building_type *btcastle;
|
2014-12-17 19:53:19 +01:00
|
|
|
|
|
|
|
test_create_world();
|
|
|
|
f = test_create_faction(NULL);
|
|
|
|
r = findregion(0, 0);
|
|
|
|
assert(r && f);
|
2017-03-10 21:29:37 +01:00
|
|
|
btcastle = test_create_buildingtype("castle");
|
2017-04-29 19:21:48 +02:00
|
|
|
btcastle->taxes = 100;
|
2014-12-17 21:31:02 +01:00
|
|
|
b = test_create_building(r, btcastle);
|
2014-12-17 19:53:19 +01:00
|
|
|
assert(b);
|
|
|
|
fix->u1 = test_create_unit(f, r);
|
|
|
|
fix->u2 = test_create_unit(f, r);
|
|
|
|
assert(fix->u1 && fix->u2);
|
|
|
|
u_set_building(fix->u1, b);
|
|
|
|
u_set_building(fix->u2, b);
|
|
|
|
assert(building_owner(b) == fix->u1);
|
|
|
|
test_translate_param(f->locale, P_NOT, "NOT");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_pay_cmd(CuTest *tc) {
|
|
|
|
struct pay_fixture fix;
|
|
|
|
order *ord;
|
|
|
|
faction *f;
|
|
|
|
building *b;
|
|
|
|
|
2017-03-11 12:57:02 +01:00
|
|
|
test_setup();
|
2014-12-17 19:53:19 +01:00
|
|
|
setup_pay_cmd(&fix);
|
|
|
|
b = fix.u1->building;
|
|
|
|
f = fix.u1->faction;
|
|
|
|
|
|
|
|
ord = create_order(K_PAY, f->locale, "NOT");
|
|
|
|
assert(ord);
|
|
|
|
CuAssertIntEquals(tc, 0, pay_cmd(fix.u1, ord));
|
|
|
|
CuAssertIntEquals(tc, BLD_DONTPAY, b->flags&BLD_DONTPAY);
|
2015-10-13 15:45:38 +02:00
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-12-17 19:53:19 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 21:31:02 +01:00
|
|
|
static void test_pay_cmd_other_building(CuTest *tc) {
|
|
|
|
struct pay_fixture fix;
|
|
|
|
order *ord;
|
|
|
|
faction *f;
|
|
|
|
building *b;
|
|
|
|
|
2016-09-11 11:02:04 +02:00
|
|
|
test_setup();
|
2014-12-17 21:31:02 +01:00
|
|
|
setup_pay_cmd(&fix);
|
|
|
|
f = fix.u1->faction;
|
2017-03-10 21:29:37 +01:00
|
|
|
/* lighthouse is not in the test locale, so we're using castle */
|
|
|
|
b = test_create_building(fix.u1->region, test_create_buildingtype("lighthouse"));
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.region_owners", "1");
|
|
|
|
config_set("rules.region_owner_pay_building", "lighthouse");
|
2014-12-17 21:31:02 +01:00
|
|
|
update_owners(b->region);
|
|
|
|
|
2017-01-07 21:19:58 +01:00
|
|
|
ord = create_order(K_PAY, f->locale, "NOT %s", itoa36(b->no));
|
2014-12-17 21:31:02 +01:00
|
|
|
assert(ord);
|
|
|
|
CuAssertPtrEquals(tc, fix.u1, building_owner(b));
|
|
|
|
CuAssertIntEquals(tc, 0, pay_cmd(fix.u1, ord));
|
|
|
|
CuAssertIntEquals(tc, BLD_DONTPAY, b->flags&BLD_DONTPAY);
|
2015-10-13 15:45:38 +02:00
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-12-17 21:31:02 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 19:53:19 +01:00
|
|
|
static void test_pay_cmd_must_be_owner(CuTest *tc) {
|
|
|
|
struct pay_fixture fix;
|
|
|
|
order *ord;
|
|
|
|
faction *f;
|
|
|
|
building *b;
|
|
|
|
|
2017-03-11 12:57:02 +01:00
|
|
|
test_setup();
|
2014-12-17 19:53:19 +01:00
|
|
|
setup_pay_cmd(&fix);
|
|
|
|
b = fix.u1->building;
|
|
|
|
f = fix.u1->faction;
|
|
|
|
|
|
|
|
ord = create_order(K_PAY, f->locale, "NOT");
|
|
|
|
assert(ord);
|
|
|
|
CuAssertIntEquals(tc, 0, pay_cmd(fix.u2, ord));
|
|
|
|
CuAssertIntEquals(tc, 0, b->flags&BLD_DONTPAY);
|
2015-10-13 15:45:38 +02:00
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-12-17 19:53:19 +01:00
|
|
|
}
|
|
|
|
|
2014-08-23 06:45:20 +02:00
|
|
|
static void test_new_units(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
faction *f;
|
|
|
|
region *r;
|
|
|
|
const struct locale *loc;
|
2015-10-13 15:45:38 +02:00
|
|
|
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2014-10-14 18:32:04 +02:00
|
|
|
f = test_create_faction(NULL);
|
2017-03-10 21:29:37 +01:00
|
|
|
r = test_create_region(0, 0, NULL);
|
2014-08-23 06:45:20 +02:00
|
|
|
assert(r && f);
|
|
|
|
u = test_create_unit(f, r);
|
|
|
|
assert(u && !u->next);
|
2017-03-10 21:29:37 +01:00
|
|
|
loc = test_create_locale();
|
2014-08-23 06:45:20 +02:00
|
|
|
assert(loc);
|
2015-10-13 15:45:38 +02:00
|
|
|
u->orders = create_order(K_MAKETEMP, loc, "hurr");
|
2014-08-23 06:45:20 +02:00
|
|
|
new_units();
|
2016-08-21 12:38:25 +02:00
|
|
|
CuAssertPtrNotNull(tc, u = u->next);
|
|
|
|
CuAssertIntEquals(tc, UFL_ISNEW, fval(u, UFL_ISNEW));
|
|
|
|
CuAssertIntEquals(tc, 0, u->number);
|
|
|
|
CuAssertIntEquals(tc, 0, u->age);
|
|
|
|
CuAssertPtrEquals(tc, f, u->faction);
|
|
|
|
CuAssertStrEquals(tc, "EINHEIT hurr", u->_name);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-08-23 06:45:20 +02:00
|
|
|
}
|
|
|
|
|
2014-10-14 18:32:04 +02:00
|
|
|
typedef struct guard_fixture {
|
|
|
|
unit * u;
|
|
|
|
} guard_fixture;
|
|
|
|
|
|
|
|
void setup_guard(guard_fixture *fix, bool armed) {
|
|
|
|
region *r;
|
|
|
|
faction *f;
|
|
|
|
unit * u;
|
|
|
|
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2014-10-14 18:32:04 +02:00
|
|
|
|
|
|
|
f = test_create_faction(NULL);
|
2017-03-10 21:29:37 +01:00
|
|
|
r = test_create_region(0, 0, NULL);
|
2014-10-14 18:32:04 +02:00
|
|
|
assert(r && f);
|
|
|
|
u = test_create_unit(f, r);
|
|
|
|
fset(u, UFL_GUARD);
|
|
|
|
u->status = ST_FIGHT;
|
|
|
|
|
|
|
|
if (armed) {
|
|
|
|
item_type *itype;
|
|
|
|
itype = it_get_or_create(rt_get_or_create("sword"));
|
2017-12-17 10:16:56 +01:00
|
|
|
new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE);
|
2014-10-14 18:32:04 +02:00
|
|
|
i_change(&u->items, itype, 1);
|
2017-12-17 10:16:56 +01:00
|
|
|
set_level(u, SK_MELEE, 1);
|
2014-10-14 18:32:04 +02:00
|
|
|
}
|
|
|
|
fix->u = u;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_update_guards(CuTest *tc) {
|
|
|
|
guard_fixture fix;
|
|
|
|
|
|
|
|
setup_guard(&fix, true);
|
|
|
|
|
|
|
|
update_guards();
|
|
|
|
CuAssertTrue(tc, fval(fix.u, UFL_GUARD));
|
|
|
|
freset(fix.u, UFL_GUARD);
|
|
|
|
update_guards();
|
|
|
|
CuAssertTrue(tc, !fval(fix.u, UFL_GUARD));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-10-14 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_newbie_cannot_guard(CuTest *tc) {
|
|
|
|
guard_fixture fix;
|
|
|
|
|
|
|
|
setup_guard(&fix, true);
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("NewbieImmunity", "4");
|
2014-10-14 18:32:04 +02:00
|
|
|
CuAssertTrue(tc, IsImmune(fix.u->faction));
|
2015-11-23 15:35:26 +01:00
|
|
|
CuAssertIntEquals(tc, E_GUARD_NEWBIE, can_start_guarding(fix.u));
|
2014-10-14 18:32:04 +02:00
|
|
|
update_guards();
|
|
|
|
CuAssertTrue(tc, !fval(fix.u, UFL_GUARD));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-10-14 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_unarmed_cannot_guard(CuTest *tc) {
|
|
|
|
guard_fixture fix;
|
|
|
|
|
|
|
|
setup_guard(&fix, false);
|
2015-11-23 15:35:26 +01:00
|
|
|
CuAssertIntEquals(tc, E_GUARD_UNARMED, can_start_guarding(fix.u));
|
2014-10-14 18:32:04 +02:00
|
|
|
update_guards();
|
|
|
|
CuAssertTrue(tc, !fval(fix.u, UFL_GUARD));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-10-14 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_unarmed_races_can_guard(CuTest *tc) {
|
|
|
|
guard_fixture fix;
|
|
|
|
race * rc;
|
|
|
|
|
|
|
|
setup_guard(&fix, false);
|
2014-12-08 22:06:05 +01:00
|
|
|
rc = rc_get_or_create(fix.u->_race->_name);
|
2015-11-16 18:41:52 +01:00
|
|
|
fset(rc, RCF_UNARMEDGUARD);
|
2015-11-23 15:35:26 +01:00
|
|
|
CuAssertIntEquals(tc, E_GUARD_OK, can_start_guarding(fix.u));
|
|
|
|
update_guards();
|
|
|
|
CuAssertTrue(tc, fval(fix.u, UFL_GUARD));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-11-23 15:35:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_monsters_can_guard(CuTest *tc) {
|
|
|
|
guard_fixture fix;
|
|
|
|
|
|
|
|
setup_guard(&fix, false);
|
|
|
|
u_setfaction(fix.u, get_or_create_monsters());
|
|
|
|
CuAssertIntEquals(tc, E_GUARD_OK, can_start_guarding(fix.u));
|
2014-10-14 18:32:04 +02:00
|
|
|
update_guards();
|
|
|
|
CuAssertTrue(tc, fval(fix.u, UFL_GUARD));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-10-14 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
2017-12-17 10:16:56 +01:00
|
|
|
static void test_unskilled_cannot_guard(CuTest *tc) {
|
2014-10-14 18:32:04 +02:00
|
|
|
guard_fixture fix;
|
|
|
|
|
|
|
|
setup_guard(&fix, true);
|
2017-12-17 10:16:56 +01:00
|
|
|
set_level(fix.u, SK_MELEE, 0);
|
2015-11-23 15:35:26 +01:00
|
|
|
CuAssertIntEquals(tc, E_GUARD_UNARMED, can_start_guarding(fix.u));
|
2014-10-14 18:32:04 +02:00
|
|
|
update_guards();
|
|
|
|
CuAssertTrue(tc, !fval(fix.u, UFL_GUARD));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-10-14 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_fleeing_cannot_guard(CuTest *tc) {
|
|
|
|
guard_fixture fix;
|
|
|
|
|
|
|
|
setup_guard(&fix, true);
|
|
|
|
fix.u->status = ST_FLEE;
|
2015-11-23 15:35:26 +01:00
|
|
|
CuAssertIntEquals(tc, E_GUARD_FLEEING, can_start_guarding(fix.u));
|
2014-10-14 18:32:04 +02:00
|
|
|
update_guards();
|
|
|
|
CuAssertTrue(tc, !fval(fix.u, UFL_GUARD));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-10-14 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
2014-07-20 06:19:21 +02:00
|
|
|
static void test_reserve_self(CuTest *tc) {
|
|
|
|
unit *u1, *u2;
|
|
|
|
faction *f;
|
|
|
|
region *r;
|
|
|
|
order *ord;
|
|
|
|
const resource_type *rtype;
|
|
|
|
const struct locale *loc;
|
|
|
|
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
|
|
|
init_resources();
|
2014-07-20 06:19:21 +02:00
|
|
|
|
|
|
|
rtype = get_resourcetype(R_SILVER);
|
|
|
|
assert(rtype && rtype->itype);
|
2014-10-14 18:32:04 +02:00
|
|
|
f = test_create_faction(NULL);
|
2017-03-10 21:29:37 +01:00
|
|
|
r = test_create_region(0, 0, 0);
|
2014-07-20 06:19:21 +02:00
|
|
|
assert(r && f);
|
|
|
|
u1 = test_create_unit(f, r);
|
|
|
|
u2 = test_create_unit(f, r);
|
|
|
|
assert(u1 && u2);
|
2017-03-10 21:29:37 +01:00
|
|
|
loc = test_create_locale();
|
2014-07-20 06:19:21 +02:00
|
|
|
assert(loc);
|
|
|
|
ord = create_order(K_RESERVE, loc, "200 SILBER");
|
|
|
|
assert(ord);
|
|
|
|
i_change(&u1->items, rtype->itype, 100);
|
|
|
|
i_change(&u2->items, rtype->itype, 100);
|
|
|
|
CuAssertIntEquals(tc, 100, reserve_self(u1, ord));
|
|
|
|
CuAssertIntEquals(tc, 100, i_get(u1->items, rtype->itype));
|
|
|
|
CuAssertIntEquals(tc, 100, i_get(u2->items, rtype->itype));
|
2015-10-13 15:45:38 +02:00
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-07-20 06:19:21 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 17:40:04 +01:00
|
|
|
static void statistic_test(CuTest *tc, int peasants, int luck, int maxp,
|
2015-02-01 19:14:06 +01:00
|
|
|
double variance, int min_value, int max_value) {
|
2015-05-24 11:32:16 +02:00
|
|
|
int effect;
|
|
|
|
|
|
|
|
effect = peasant_luck_effect(peasants, luck, maxp, variance);
|
|
|
|
CuAssertTrue(tc, min_value <= effect);
|
|
|
|
CuAssertTrue(tc, max_value >= effect);
|
2015-01-30 17:40:04 +01:00
|
|
|
}
|
|
|
|
|
2015-02-01 19:14:06 +01:00
|
|
|
static void test_peasant_luck_effect(CuTest *tc) {
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2015-01-30 17:40:04 +01:00
|
|
|
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.peasants.peasantluck.factor", "10");
|
|
|
|
config_set("rules.peasants.growth.factor", "0.001");
|
2015-01-30 17:40:04 +01:00
|
|
|
|
2015-02-01 19:14:06 +01:00
|
|
|
statistic_test(tc, 100, 0, 1000, 0, 0, 0);
|
2015-01-30 22:11:33 +01:00
|
|
|
statistic_test(tc, 100, 2, 1000, 0, 1, 1);
|
2015-05-24 13:12:23 +02:00
|
|
|
statistic_test(tc, 1000, 400, 1000, 0, 3, 3);
|
2015-02-01 19:14:06 +01:00
|
|
|
statistic_test(tc, 1000, 1000, 2000, .5, 1, 501);
|
2015-01-30 17:40:04 +01:00
|
|
|
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.peasants.growth.factor", "1");
|
2015-01-30 22:11:33 +01:00
|
|
|
statistic_test(tc, 1000, 1000, 1000, 0, 501, 501);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-02-01 19:14:06 +01:00
|
|
|
}
|
|
|
|
|
2017-11-05 17:00:40 +01:00
|
|
|
/**
|
|
|
|
* Create any terrain types that are used by demographics.
|
|
|
|
*
|
|
|
|
* This should prevent newterrain from returning NULL.
|
|
|
|
*/
|
|
|
|
static void setup_terrains(CuTest *tc) {
|
|
|
|
test_create_terrain("volcano", SEA_REGION | SWIM_INTO | FLY_INTO);
|
|
|
|
test_create_terrain("activevolcano", LAND_REGION | WALK_INTO | FLY_INTO);
|
|
|
|
init_terrains();
|
|
|
|
CuAssertPtrNotNull(tc, newterrain(T_VOLCANO));
|
|
|
|
CuAssertPtrNotNull(tc, newterrain(T_VOLCANO_SMOKING));
|
|
|
|
}
|
|
|
|
|
2015-02-01 19:14:06 +01:00
|
|
|
static void test_luck_message(CuTest *tc) {
|
|
|
|
region* r;
|
2017-02-18 21:15:14 +01:00
|
|
|
attrib *a;
|
2015-10-14 12:05:29 +02:00
|
|
|
|
2017-02-18 21:15:14 +01:00
|
|
|
test_setup();
|
2018-01-13 22:46:02 +01:00
|
|
|
mt_register(mt_new_va("peasantluck_success", "births:int", 0));
|
2017-11-05 17:00:40 +01:00
|
|
|
setup_terrains(tc);
|
2015-02-01 19:14:06 +01:00
|
|
|
r = test_create_region(0, 0, NULL);
|
|
|
|
rsetpeasants(r, 1);
|
|
|
|
|
|
|
|
demographics();
|
|
|
|
|
|
|
|
CuAssertPtrEquals_Msg(tc, "unexpected message", (void *)NULL, r->msgs);
|
|
|
|
|
2017-02-18 21:15:14 +01:00
|
|
|
a = (attrib *)a_find(r->attribs, &at_peasantluck);
|
2015-02-01 19:14:06 +01:00
|
|
|
if (!a)
|
|
|
|
a = a_add(&r->attribs, a_new(&at_peasantluck));
|
|
|
|
a->data.i += 10;
|
|
|
|
|
|
|
|
demographics();
|
|
|
|
|
2015-08-17 19:35:07 +02:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(r->msgs, "peasantluck_success"));
|
2015-02-01 19:14:06 +01:00
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-01-30 17:40:04 +01:00
|
|
|
}
|
|
|
|
|
2015-10-13 13:56:58 +02:00
|
|
|
static unit * setup_name_cmd(void) {
|
|
|
|
faction *f;
|
|
|
|
|
2017-02-18 21:15:14 +01:00
|
|
|
test_setup();
|
2018-01-13 22:46:02 +01:00
|
|
|
mt_register(mt_new_va("renamed_building_seen", "renamer:unit", "region:region", "building:building", 0));
|
|
|
|
mt_register(mt_new_va("renamed_building_notseen", "region:region", "building:building", 0));
|
2015-10-13 13:56:58 +02:00
|
|
|
f = test_create_faction(0);
|
|
|
|
return test_create_unit(f, test_create_region(0, 0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_name_unit(CuTest *tc) {
|
|
|
|
unit *u;
|
2016-03-23 22:24:11 +01:00
|
|
|
faction *f;
|
2015-10-13 13:56:58 +02:00
|
|
|
order *ord;
|
|
|
|
|
|
|
|
u = setup_name_cmd();
|
2016-03-23 22:24:11 +01:00
|
|
|
f = u->faction;
|
|
|
|
ord = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_UNIT]));
|
2015-10-13 13:56:58 +02:00
|
|
|
name_cmd(u, ord);
|
|
|
|
CuAssertStrEquals(tc, "Hodor", u->_name);
|
2015-10-13 14:27:42 +02:00
|
|
|
free_order(ord);
|
|
|
|
|
2016-03-23 22:24:11 +01:00
|
|
|
ord = create_order(K_NAME, f->locale, LOC(f->locale, parameters[P_UNIT]));
|
2015-10-13 14:27:42 +02:00
|
|
|
name_cmd(u, ord);
|
2016-03-23 22:24:11 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error84"));
|
2015-10-13 14:27:42 +02:00
|
|
|
CuAssertStrEquals(tc, "Hodor", u->_name);
|
|
|
|
free_order(ord);
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-10-13 13:56:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_name_region(CuTest *tc) {
|
|
|
|
unit *u;
|
2016-03-23 22:24:11 +01:00
|
|
|
faction *f;
|
2015-10-13 13:56:58 +02:00
|
|
|
order *ord;
|
|
|
|
|
|
|
|
u = setup_name_cmd();
|
2016-03-23 22:24:11 +01:00
|
|
|
f = u->faction;
|
2015-10-13 13:56:58 +02:00
|
|
|
|
2016-03-23 22:24:11 +01:00
|
|
|
ord = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_REGION]));
|
2017-01-25 20:57:54 +01:00
|
|
|
u_set_building(u, test_create_building(u->region, 0));
|
2015-10-13 13:56:58 +02:00
|
|
|
name_cmd(u, ord);
|
|
|
|
CuAssertStrEquals(tc, "Hodor", u->region->land->name);
|
2015-10-13 14:27:42 +02:00
|
|
|
free_order(ord);
|
|
|
|
|
2016-03-23 22:24:11 +01:00
|
|
|
ord = create_order(K_NAME, f->locale, LOC(f->locale, parameters[P_REGION]));
|
2015-10-13 14:27:42 +02:00
|
|
|
name_cmd(u, ord);
|
2016-03-23 22:24:11 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error84"));
|
2015-10-13 14:27:42 +02:00
|
|
|
CuAssertStrEquals(tc, "Hodor", u->region->land->name);
|
|
|
|
free_order(ord);
|
2015-10-13 13:56:58 +02:00
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-10-13 13:56:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_name_building(CuTest *tc) {
|
2017-11-12 15:12:45 +01:00
|
|
|
unit *uo, *u, *ux;
|
2016-03-23 22:24:11 +01:00
|
|
|
faction *f;
|
2015-10-13 13:56:58 +02:00
|
|
|
|
|
|
|
u = setup_name_cmd();
|
2017-11-12 15:12:45 +01:00
|
|
|
u->building = test_create_building(u->region, 0);
|
2016-03-23 22:24:11 +01:00
|
|
|
f = u->faction;
|
2017-11-12 15:12:45 +01:00
|
|
|
uo = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
|
|
|
u_set_building(uo, u->building);
|
|
|
|
ux = test_create_unit(f, test_create_region(0, 0, NULL));
|
|
|
|
u_set_building(ux, u->building);
|
2015-10-13 13:56:58 +02:00
|
|
|
|
2017-11-12 15:12:45 +01:00
|
|
|
u->thisorder = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_BUILDING]));
|
2015-10-13 13:56:58 +02:00
|
|
|
|
2017-11-12 15:12:45 +01:00
|
|
|
building_set_owner(uo);
|
|
|
|
name_cmd(u, u->thisorder);
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error148"));
|
|
|
|
test_clear_messages(f);
|
|
|
|
|
|
|
|
building_set_owner(u);
|
|
|
|
name_cmd(u, u->thisorder);
|
2015-10-13 13:56:58 +02:00
|
|
|
CuAssertStrEquals(tc, "Hodor", u->building->name);
|
2015-10-13 14:27:42 +02:00
|
|
|
|
2017-11-12 15:12:45 +01:00
|
|
|
building_setname(u->building, "Home");
|
|
|
|
building_set_owner(ux);
|
|
|
|
name_cmd(u, u->thisorder);
|
|
|
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error148"));
|
|
|
|
CuAssertStrEquals(tc, "Hodor", u->building->name);
|
|
|
|
|
|
|
|
test_clear_messages(f);
|
|
|
|
free_order(u->thisorder);
|
|
|
|
u->thisorder = create_order(K_NAME, f->locale, LOC(f->locale, parameters[P_BUILDING]));
|
|
|
|
name_cmd(u, u->thisorder);
|
2016-03-23 22:24:11 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error84"));
|
2015-10-13 14:27:42 +02:00
|
|
|
CuAssertStrEquals(tc, "Hodor", u->building->name);
|
|
|
|
|
|
|
|
/* TODO: test BTF_NAMECHANGE:
|
2015-10-13 13:56:58 +02:00
|
|
|
btype->flags |= BTF_NAMECHANGE;
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error278"));
|
|
|
|
test_clear_messages(u->faction);
|
|
|
|
name_cmd(u, ord); */
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-10-13 13:56:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_name_ship(CuTest *tc) {
|
2017-11-12 14:59:44 +01:00
|
|
|
unit *uo, *u, *ux;
|
2016-03-23 22:24:11 +01:00
|
|
|
faction *f;
|
2015-10-13 13:56:58 +02:00
|
|
|
|
|
|
|
u = setup_name_cmd();
|
|
|
|
u->ship = test_create_ship(u->region, 0);
|
2017-11-12 15:09:57 +01:00
|
|
|
f = u->faction;
|
2017-11-12 14:59:44 +01:00
|
|
|
uo = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2017-11-12 15:09:57 +01:00
|
|
|
u_set_ship(uo, u->ship);
|
2017-11-12 14:59:44 +01:00
|
|
|
ux = test_create_unit(f, test_create_region(0, 0, NULL));
|
2017-11-12 15:09:57 +01:00
|
|
|
u_set_ship(ux, u->ship);
|
2015-10-13 14:27:42 +02:00
|
|
|
|
2017-11-12 14:59:44 +01:00
|
|
|
u->thisorder = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_SHIP]));
|
|
|
|
|
|
|
|
ship_set_owner(uo);
|
|
|
|
name_cmd(u, u->thisorder);
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error12"));
|
|
|
|
test_clear_messages(f);
|
|
|
|
|
2017-11-12 15:09:57 +01:00
|
|
|
ship_set_owner(u);
|
|
|
|
name_cmd(u, u->thisorder);
|
2015-10-13 13:56:58 +02:00
|
|
|
CuAssertStrEquals(tc, "Hodor", u->ship->name);
|
2015-10-13 14:27:42 +02:00
|
|
|
|
2017-11-12 15:09:57 +01:00
|
|
|
ship_setname(u->ship, "Titanic");
|
2017-11-12 14:59:44 +01:00
|
|
|
ship_set_owner(ux);
|
|
|
|
name_cmd(u, u->thisorder);
|
|
|
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error12"));
|
|
|
|
CuAssertStrEquals(tc, "Hodor", u->ship->name);
|
|
|
|
|
2017-11-12 15:05:17 +01:00
|
|
|
test_clear_messages(f);
|
|
|
|
free_order(u->thisorder);
|
|
|
|
u->thisorder = create_order(K_NAME, f->locale, LOC(f->locale, parameters[P_SHIP]));
|
|
|
|
name_cmd(u, u->thisorder);
|
2016-03-23 22:24:11 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error84"));
|
2015-10-13 14:27:42 +02:00
|
|
|
CuAssertStrEquals(tc, "Hodor", u->ship->name);
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-10-13 13:56:58 +02:00
|
|
|
}
|
|
|
|
|
2015-08-05 00:03:30 +02:00
|
|
|
static void test_long_order_normal(CuTest *tc) {
|
2017-02-18 21:15:14 +01:00
|
|
|
/* TODO: write more tests */
|
2015-08-04 23:04:00 +02:00
|
|
|
unit *u;
|
2015-08-05 00:03:30 +02:00
|
|
|
order *ord;
|
2015-10-13 15:45:38 +02:00
|
|
|
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2015-08-04 23:04:00 +02:00
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
2015-08-05 00:03:30 +02:00
|
|
|
fset(u, UFL_MOVED);
|
|
|
|
fset(u, UFL_LONGACTION);
|
2015-10-13 15:45:38 +02:00
|
|
|
unit_addorder(u, ord = create_order(K_MOVE, u->faction->locale, 0));
|
2015-08-05 00:03:30 +02:00
|
|
|
update_long_order(u);
|
2017-10-08 12:39:41 +02:00
|
|
|
CuAssertIntEquals(tc, ord->id, u->thisorder->id);
|
2015-08-05 00:03:30 +02:00
|
|
|
CuAssertIntEquals(tc, 0, fval(u, UFL_MOVED));
|
|
|
|
CuAssertIntEquals(tc, 0, fval(u, UFL_LONGACTION));
|
|
|
|
CuAssertPtrNotNull(tc, u->orders);
|
|
|
|
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
|
|
|
CuAssertPtrEquals(tc, 0, u->old_orders);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-08-05 00:03:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_long_order_none(CuTest *tc) {
|
2017-02-18 21:15:14 +01:00
|
|
|
/* TODO: write more tests */
|
2015-08-05 00:03:30 +02:00
|
|
|
unit *u;
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2015-08-05 00:03:30 +02:00
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
2015-08-04 23:04:00 +02:00
|
|
|
update_long_order(u);
|
|
|
|
CuAssertPtrEquals(tc, 0, u->thisorder);
|
|
|
|
CuAssertPtrEquals(tc, 0, u->orders);
|
2015-08-05 00:03:30 +02:00
|
|
|
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-08-05 00:03:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_long_order_cast(CuTest *tc) {
|
2017-02-18 21:15:14 +01:00
|
|
|
/* TODO: write more tests */
|
2015-08-05 00:03:30 +02:00
|
|
|
unit *u;
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2015-08-05 00:03:30 +02:00
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
|
|
|
unit_addorder(u, create_order(K_CAST, u->faction->locale, 0));
|
|
|
|
unit_addorder(u, create_order(K_CAST, u->faction->locale, 0));
|
|
|
|
update_long_order(u);
|
|
|
|
CuAssertPtrEquals(tc, 0, u->thisorder);
|
|
|
|
CuAssertPtrNotNull(tc, u->orders);
|
|
|
|
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-08-05 00:03:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_long_order_buy_sell(CuTest *tc) {
|
2017-02-18 21:15:14 +01:00
|
|
|
/* TODO: write more tests */
|
2015-08-05 00:03:30 +02:00
|
|
|
unit *u;
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2015-08-05 00:03:30 +02:00
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
|
|
|
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
|
|
|
|
unit_addorder(u, create_order(K_SELL, u->faction->locale, 0));
|
|
|
|
unit_addorder(u, create_order(K_SELL, u->faction->locale, 0));
|
|
|
|
update_long_order(u);
|
|
|
|
CuAssertPtrEquals(tc, 0, u->thisorder);
|
|
|
|
CuAssertPtrNotNull(tc, u->orders);
|
|
|
|
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-08-05 00:03:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_long_order_multi_long(CuTest *tc) {
|
2017-02-18 21:15:14 +01:00
|
|
|
/* TODO: write more tests */
|
2015-08-05 00:03:30 +02:00
|
|
|
unit *u;
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2015-08-05 00:03:30 +02:00
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
|
|
|
unit_addorder(u, create_order(K_MOVE, u->faction->locale, 0));
|
|
|
|
unit_addorder(u, create_order(K_DESTROY, u->faction->locale, 0));
|
|
|
|
update_long_order(u);
|
|
|
|
CuAssertPtrNotNull(tc, u->thisorder);
|
|
|
|
CuAssertPtrNotNull(tc, u->orders);
|
2015-08-15 20:25:36 +02:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error52"));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-08-05 00:03:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_long_order_multi_buy(CuTest *tc) {
|
2017-02-18 21:15:14 +01:00
|
|
|
/* TODO: write more tests */
|
2015-08-05 00:03:30 +02:00
|
|
|
unit *u;
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2015-08-05 00:03:30 +02:00
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
|
|
|
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
|
|
|
|
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
|
|
|
|
update_long_order(u);
|
|
|
|
CuAssertPtrEquals(tc, 0, u->thisorder);
|
|
|
|
CuAssertPtrNotNull(tc, u->orders);
|
2015-08-15 20:25:36 +02:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error52"));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-08-05 00:03:30 +02:00
|
|
|
}
|
|
|
|
|
2015-08-05 10:25:25 +02:00
|
|
|
static void test_long_order_multi_sell(CuTest *tc) {
|
2017-02-18 21:15:14 +01:00
|
|
|
/* TODO: write more tests */
|
2015-08-05 10:25:25 +02:00
|
|
|
unit *u;
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2015-08-05 10:25:25 +02:00
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
|
|
|
unit_addorder(u, create_order(K_SELL, u->faction->locale, 0));
|
|
|
|
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
|
|
|
|
unit_addorder(u, create_order(K_SELL, u->faction->locale, 0));
|
|
|
|
update_long_order(u);
|
|
|
|
CuAssertPtrEquals(tc, 0, u->thisorder);
|
|
|
|
CuAssertPtrNotNull(tc, u->orders);
|
|
|
|
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-08-05 10:25:25 +02:00
|
|
|
}
|
|
|
|
|
2015-08-05 00:03:30 +02:00
|
|
|
static void test_long_order_buy_cast(CuTest *tc) {
|
2017-02-18 21:15:14 +01:00
|
|
|
/* TODO: write more tests */
|
2015-08-05 00:03:30 +02:00
|
|
|
unit *u;
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2015-08-05 00:03:30 +02:00
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
|
|
|
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
|
|
|
|
unit_addorder(u, create_order(K_CAST, u->faction->locale, 0));
|
|
|
|
update_long_order(u);
|
|
|
|
CuAssertPtrEquals(tc, 0, u->thisorder);
|
|
|
|
CuAssertPtrNotNull(tc, u->orders);
|
2015-08-15 20:25:36 +02:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error52"));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-08-05 00:03:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_long_order_hungry(CuTest *tc) {
|
|
|
|
unit *u;
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("hunger.long", "1");
|
2015-08-05 00:03:30 +02:00
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
|
|
|
fset(u, UFL_HUNGER);
|
|
|
|
unit_addorder(u, create_order(K_MOVE, u->faction->locale, 0));
|
|
|
|
unit_addorder(u, create_order(K_DESTROY, u->faction->locale, 0));
|
2016-04-09 19:05:28 +02:00
|
|
|
config_set("orders.default", "work");
|
2015-08-05 00:03:30 +02:00
|
|
|
update_long_order(u);
|
|
|
|
CuAssertIntEquals(tc, K_WORK, getkeyword(u->thisorder));
|
|
|
|
CuAssertPtrNotNull(tc, u->orders);
|
|
|
|
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-08-04 23:04:00 +02:00
|
|
|
}
|
|
|
|
|
2015-08-05 12:19:17 +02:00
|
|
|
static void test_ally_cmd_errors(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
int fid;
|
|
|
|
order *ord;
|
|
|
|
|
2016-11-11 01:59:43 +01:00
|
|
|
test_setup();
|
2015-08-05 12:19:17 +02:00
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
|
|
|
fid = u->faction->no + 1;
|
|
|
|
CuAssertPtrEquals(tc, 0, findfaction(fid));
|
|
|
|
|
|
|
|
ord = create_order(K_ALLY, u->faction->locale, itoa36(fid));
|
|
|
|
ally_cmd(u, ord);
|
2015-08-15 20:25:36 +02:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error66"));
|
2015-08-05 12:19:17 +02:00
|
|
|
free_order(ord);
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-08-05 12:19:17 +02:00
|
|
|
}
|
|
|
|
|
2016-11-11 01:59:43 +01:00
|
|
|
static void test_name_cmd(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
faction *f;
|
2017-11-06 20:38:28 +01:00
|
|
|
alliance *al;
|
2016-11-11 01:59:43 +01:00
|
|
|
order *ord;
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0));
|
2017-11-06 20:38:28 +01:00
|
|
|
setalliance(f, al = makealliance(42, ""));
|
2016-11-11 01:59:43 +01:00
|
|
|
|
|
|
|
ord = create_order(K_NAME, f->locale, "%s ' Ho\tdor '", LOC(f->locale, parameters[P_UNIT]));
|
|
|
|
name_cmd(u, ord);
|
|
|
|
CuAssertStrEquals(tc, "Hodor", u->_name);
|
|
|
|
free_order(ord);
|
|
|
|
|
|
|
|
ord = create_order(K_NAME, f->locale, "%s ' Ho\tdor '", LOC(f->locale, parameters[P_FACTION]));
|
|
|
|
name_cmd(u, ord);
|
|
|
|
CuAssertStrEquals(tc, "Hodor", f->name);
|
|
|
|
free_order(ord);
|
|
|
|
|
2016-11-11 14:00:04 +01:00
|
|
|
ord = create_order(K_NAME, f->locale, "%s ' Ho\tdor '", LOC(f->locale, parameters[P_SHIP]));
|
|
|
|
u->ship = test_create_ship(u->region, 0);
|
2016-11-11 02:07:11 +01:00
|
|
|
name_cmd(u, ord);
|
2016-11-11 14:00:04 +01:00
|
|
|
CuAssertStrEquals(tc, "Hodor", u->ship->name);
|
|
|
|
free_order(ord);
|
|
|
|
|
|
|
|
ord = create_order(K_NAME, f->locale, "%s ' Ho\tdor '", LOC(f->locale, parameters[P_BUILDING]));
|
2017-01-25 20:57:54 +01:00
|
|
|
u_set_building(u, test_create_building(u->region, 0));
|
2016-11-11 02:07:11 +01:00
|
|
|
name_cmd(u, ord);
|
2016-11-11 14:00:04 +01:00
|
|
|
CuAssertStrEquals(tc, "Hodor", u->building->name);
|
|
|
|
free_order(ord);
|
|
|
|
|
|
|
|
ord = create_order(K_NAME, f->locale, "%s ' Ho\tdor '", LOC(f->locale, parameters[P_REGION]));
|
|
|
|
name_cmd(u, ord);
|
2016-11-11 02:07:11 +01:00
|
|
|
CuAssertStrEquals(tc, "Hodor", u->region->land->name);
|
|
|
|
free_order(ord);
|
|
|
|
|
2017-11-06 20:38:28 +01:00
|
|
|
ord = create_order(K_NAME, f->locale, "%s ' Ho\tdor '", LOC(f->locale, parameters[P_ALLIANCE]));
|
|
|
|
name_cmd(u, ord);
|
|
|
|
CuAssertStrEquals(tc, "Hodor", al->name);
|
|
|
|
free_order(ord);
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-11-11 01:59:43 +01:00
|
|
|
}
|
|
|
|
|
2017-01-25 20:57:54 +01:00
|
|
|
static void test_name_cmd_2274(CuTest *tc) {
|
|
|
|
unit *u1, *u2, *u3;
|
|
|
|
faction *f;
|
|
|
|
region *r;
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
r = test_create_region(0, 0, 0);
|
|
|
|
u1 = test_create_unit(test_create_faction(0), r);
|
|
|
|
u2 = test_create_unit(test_create_faction(0), r);
|
|
|
|
u3 = test_create_unit(u2->faction, r);
|
|
|
|
u_set_building(u1, test_create_building(r, NULL));
|
|
|
|
u1->building->size = 10;
|
|
|
|
u_set_building(u2, test_create_building(r, NULL));
|
|
|
|
u2->building->size = 20;
|
|
|
|
|
|
|
|
f = u2->faction;
|
|
|
|
u2->thisorder = create_order(K_NAME, f->locale, "%s Heimat", LOC(f->locale, parameters[P_REGION]));
|
|
|
|
name_cmd(u2, u2->thisorder);
|
|
|
|
CuAssertStrEquals(tc, "Heimat", r->land->name);
|
|
|
|
f = u3->faction;
|
|
|
|
u3->thisorder = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_REGION]));
|
|
|
|
name_cmd(u3, u3->thisorder);
|
|
|
|
CuAssertStrEquals(tc, "Hodor", r->land->name);
|
|
|
|
f = u1->faction;
|
|
|
|
u1->thisorder = create_order(K_NAME, f->locale, "%s notallowed", LOC(f->locale, parameters[P_REGION]));
|
|
|
|
name_cmd(u1, u1->thisorder);
|
|
|
|
CuAssertStrEquals(tc, "Hodor", r->land->name);
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-01-25 20:57:54 +01:00
|
|
|
}
|
|
|
|
|
2015-08-05 12:19:17 +02:00
|
|
|
static void test_ally_cmd(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
faction * f;
|
|
|
|
order *ord;
|
|
|
|
|
2016-11-11 01:59:43 +01:00
|
|
|
test_setup();
|
2015-08-05 12:19:17 +02:00
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
|
|
|
f = test_create_faction(0);
|
2016-01-12 06:46:51 +01:00
|
|
|
|
2016-03-23 22:24:11 +01:00
|
|
|
ord = create_order(K_ALLY, f->locale, "%s", itoa36(f->no));
|
2015-08-05 12:19:17 +02:00
|
|
|
ally_cmd(u, ord);
|
|
|
|
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
|
|
|
CuAssertIntEquals(tc, HELP_ALL, alliedfaction(0, u->faction, f, HELP_ALL));
|
|
|
|
free_order(ord);
|
|
|
|
|
2016-03-23 22:24:11 +01:00
|
|
|
ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_NOT]));
|
2015-08-05 12:19:17 +02:00
|
|
|
ally_cmd(u, ord);
|
|
|
|
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
|
|
|
CuAssertIntEquals(tc, 0, alliedfaction(0, u->faction, f, HELP_ALL));
|
|
|
|
free_order(ord);
|
|
|
|
|
2016-03-23 22:24:11 +01:00
|
|
|
ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_GUARD]));
|
2015-08-05 12:19:17 +02:00
|
|
|
ally_cmd(u, ord);
|
|
|
|
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
|
|
|
CuAssertIntEquals(tc, HELP_GUARD, alliedfaction(0, u->faction, f, HELP_ALL));
|
|
|
|
free_order(ord);
|
|
|
|
|
2016-03-23 22:24:11 +01:00
|
|
|
ord = create_order(K_ALLY, f->locale, "%s %s %s", itoa36(f->no), LOC(f->locale, parameters[P_GUARD]), LOC(f->locale, parameters[P_NOT]));
|
2015-08-05 12:19:17 +02:00
|
|
|
ally_cmd(u, ord);
|
|
|
|
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
|
|
|
CuAssertIntEquals(tc, 0, alliedfaction(0, u->faction, f, HELP_ALL));
|
|
|
|
free_order(ord);
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-08-05 12:19:17 +02:00
|
|
|
}
|
|
|
|
|
2015-10-10 22:50:15 +02:00
|
|
|
static void test_nmr_warnings(CuTest *tc) {
|
2015-08-15 20:25:36 +02:00
|
|
|
faction *f1, *f2;
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2018-01-13 08:51:40 +01:00
|
|
|
mt_register(mt_new_va("nmr_warning", 0));
|
|
|
|
mt_register(mt_new_va("nmr_warning_final", 0));
|
|
|
|
mt_register(mt_new_va("warn_dropout", "faction:faction", "turn:int", 0));
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("nmr.timeout", "3");
|
2015-08-15 20:25:36 +02:00
|
|
|
f1 = test_create_faction(0);
|
|
|
|
f2 = test_create_faction(0);
|
|
|
|
f2->age = 2;
|
|
|
|
f2->lastorders = 1;
|
|
|
|
turn = 3;
|
|
|
|
CuAssertIntEquals(tc, 0, f1->age);
|
|
|
|
nmr_warnings();
|
|
|
|
CuAssertPtrNotNull(tc, f1->msgs);
|
2016-01-12 06:46:51 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f1->msgs, "nmr_warning"));
|
2015-08-15 20:25:36 +02:00
|
|
|
CuAssertPtrNotNull(tc, f2->msgs);
|
2016-01-12 06:46:51 +01:00
|
|
|
CuAssertPtrNotNull(tc, f2->msgs->begin);
|
2015-08-15 20:25:36 +02:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f2->msgs, "nmr_warning"));
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f2->msgs, "nmr_warning_final"));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-08-15 20:25:36 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 12:38:05 +02:00
|
|
|
static unit * setup_mail_cmd(void) {
|
2015-10-10 22:50:15 +02:00
|
|
|
faction *f;
|
|
|
|
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2018-01-13 08:51:40 +01:00
|
|
|
mt_register(mt_new_va("regionmessage", "region:region", "sender:unit", "string:string", 0));
|
|
|
|
mt_register(mt_new_va("unitmessage", "region:region", "sender:unit", "string:string", "unit:unit", 0));
|
|
|
|
mt_register(mt_new_va("mail_result", "message:string", "unit:unit", 0));
|
2015-10-10 22:50:15 +02:00
|
|
|
f = test_create_faction(0);
|
2015-10-11 12:38:05 +02:00
|
|
|
return test_create_unit(f, test_create_region(0, 0, 0));
|
|
|
|
}
|
|
|
|
|
2015-10-11 12:44:22 +02:00
|
|
|
static void test_mail_unit(CuTest *tc) {
|
2015-10-11 12:38:05 +02:00
|
|
|
order *ord;
|
|
|
|
unit *u;
|
2016-03-23 22:24:11 +01:00
|
|
|
faction *f;
|
2015-10-11 12:38:05 +02:00
|
|
|
|
|
|
|
u = setup_mail_cmd();
|
2016-03-23 22:24:11 +01:00
|
|
|
f = u->faction;
|
|
|
|
ord = create_order(K_MAIL, f->locale, "%s %s 'Hodor!'", LOC(f->locale, parameters[P_UNIT]), itoa36(u->no));
|
2015-10-10 22:50:15 +02:00
|
|
|
mail_cmd(u, ord);
|
2016-03-23 22:24:11 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "unitmessage"));
|
2015-10-13 15:45:38 +02:00
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-10-10 22:50:15 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 12:52:13 +02:00
|
|
|
static void test_mail_faction(CuTest *tc) {
|
|
|
|
order *ord;
|
|
|
|
unit *u;
|
2016-03-23 22:24:11 +01:00
|
|
|
faction *f;
|
2015-10-11 12:52:13 +02:00
|
|
|
|
|
|
|
u = setup_mail_cmd();
|
2016-03-23 22:24:11 +01:00
|
|
|
f = u->faction;
|
|
|
|
ord = create_order(K_MAIL, f->locale, "%s %s 'Hodor!'", LOC(f->locale, parameters[P_FACTION]), itoa36(u->faction->no));
|
2015-10-11 12:52:13 +02:00
|
|
|
mail_cmd(u, ord);
|
2016-03-23 22:24:11 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "regionmessage"));
|
2015-10-13 15:45:38 +02:00
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-10-11 12:52:13 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 12:44:22 +02:00
|
|
|
static void test_mail_region(CuTest *tc) {
|
|
|
|
order *ord;
|
|
|
|
unit *u;
|
2016-03-23 22:24:11 +01:00
|
|
|
faction *f;
|
2015-10-11 12:44:22 +02:00
|
|
|
|
|
|
|
u = setup_mail_cmd();
|
2016-03-23 22:24:11 +01:00
|
|
|
f = u->faction;
|
|
|
|
ord = create_order(K_MAIL, f->locale, "%s 'Hodor!'", LOC(f->locale, parameters[P_REGION]), itoa36(u->no));
|
2015-10-11 12:44:22 +02:00
|
|
|
mail_cmd(u, ord);
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->region->msgs, "mail_result"));
|
2015-10-13 15:45:38 +02:00
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-10-11 12:44:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_mail_unit_no_msg(CuTest *tc) {
|
2015-10-10 22:50:15 +02:00
|
|
|
unit *u;
|
2016-03-23 22:24:11 +01:00
|
|
|
faction *f;
|
2015-10-10 22:50:15 +02:00
|
|
|
order *ord;
|
|
|
|
|
2015-10-11 12:38:05 +02:00
|
|
|
u = setup_mail_cmd();
|
2016-03-23 22:24:11 +01:00
|
|
|
f = u->faction;
|
|
|
|
ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_UNIT]), itoa36(u->no));
|
2015-10-10 22:50:15 +02:00
|
|
|
mail_cmd(u, ord);
|
2016-03-23 22:24:11 +01:00
|
|
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "unitmessage"));
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30"));
|
2015-10-13 15:45:38 +02:00
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-10-10 22:50:15 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 12:52:13 +02:00
|
|
|
static void test_mail_faction_no_msg(CuTest *tc) {
|
|
|
|
unit *u;
|
2016-03-23 22:24:11 +01:00
|
|
|
faction *f;
|
2015-10-11 12:52:13 +02:00
|
|
|
order *ord;
|
|
|
|
|
|
|
|
u = setup_mail_cmd();
|
2016-03-23 22:24:11 +01:00
|
|
|
f = u->faction;
|
|
|
|
ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_FACTION]), itoa36(f->no));
|
2015-10-11 12:52:13 +02:00
|
|
|
mail_cmd(u, ord);
|
2016-03-23 22:24:11 +01:00
|
|
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "regionmessage"));
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30"));
|
2015-10-13 15:45:38 +02:00
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-10-11 12:52:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_mail_faction_no_target(CuTest *tc) {
|
|
|
|
unit *u;
|
2016-03-23 22:24:11 +01:00
|
|
|
faction *f;
|
2015-10-11 12:52:13 +02:00
|
|
|
order *ord;
|
|
|
|
|
|
|
|
u = setup_mail_cmd();
|
2016-03-23 22:24:11 +01:00
|
|
|
f = u->faction;
|
|
|
|
ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_FACTION]), itoa36(f->no+1));
|
2015-10-11 12:52:13 +02:00
|
|
|
mail_cmd(u, ord);
|
2016-03-23 22:24:11 +01:00
|
|
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "regionmessage"));
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error66"));
|
2015-10-13 15:45:38 +02:00
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-10-11 12:52:13 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 12:44:22 +02:00
|
|
|
static void test_mail_region_no_msg(CuTest *tc) {
|
|
|
|
unit *u;
|
2016-03-23 22:24:11 +01:00
|
|
|
faction *f;
|
2015-10-11 12:44:22 +02:00
|
|
|
order *ord;
|
|
|
|
|
|
|
|
u = setup_mail_cmd();
|
2016-03-23 22:24:11 +01:00
|
|
|
f = u->faction;
|
|
|
|
ord = create_order(K_MAIL, f->locale, LOC(f->locale, parameters[P_REGION]));
|
2015-10-11 12:44:22 +02:00
|
|
|
mail_cmd(u, ord);
|
|
|
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(u->region->msgs, "mail_result"));
|
2016-03-23 22:24:11 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30"));
|
2015-10-13 15:45:38 +02:00
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-10-11 12:44:22 +02:00
|
|
|
}
|
|
|
|
|
2015-11-05 15:16:52 +01:00
|
|
|
static void test_show_without_item(CuTest *tc)
|
|
|
|
{
|
2015-11-07 14:27:48 +01:00
|
|
|
region *r;
|
|
|
|
faction *f;
|
2015-11-05 15:16:52 +01:00
|
|
|
unit *u;
|
|
|
|
order *ord;
|
|
|
|
item_type *itype;
|
2015-11-06 12:08:12 +01:00
|
|
|
struct locale *loc;
|
2015-11-05 15:16:52 +01:00
|
|
|
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2018-01-13 22:46:02 +01:00
|
|
|
mt_register(mt_new_va("displayitem", "weight:int", "item:resource", "description:string", 0));
|
2015-11-07 15:18:23 +01:00
|
|
|
|
2015-11-07 14:27:48 +01:00
|
|
|
loc = get_or_create_locale("de");
|
2016-01-28 16:00:36 +01:00
|
|
|
locale_setstring(loc, parameters[P_ANY], "ALLE");
|
|
|
|
init_parameters(loc);
|
2015-11-07 14:27:48 +01:00
|
|
|
|
|
|
|
r = test_create_region(0, 0, test_create_terrain("testregion", LAND_REGION));
|
|
|
|
f = test_create_faction(test_create_race("human"));
|
|
|
|
u = test_create_unit(f, r);
|
2015-11-05 20:10:51 +01:00
|
|
|
|
2015-11-05 15:16:52 +01:00
|
|
|
itype = it_get_or_create(rt_get_or_create("testitem"));
|
2017-03-10 21:43:36 +01:00
|
|
|
|
|
|
|
ord = create_order(K_RESHOW, f->locale, "testname");
|
2015-11-05 15:16:52 +01:00
|
|
|
|
|
|
|
reshow_cmd(u, ord);
|
2017-03-10 21:43:36 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error21"));
|
2016-03-23 22:24:11 +01:00
|
|
|
test_clear_messages(f);
|
2015-11-05 15:16:52 +01:00
|
|
|
|
2015-11-06 12:08:12 +01:00
|
|
|
locale_setstring(loc, "testitem", "testname");
|
|
|
|
locale_setstring(loc, "iteminfo::testitem", "testdescription");
|
2017-03-10 21:43:36 +01:00
|
|
|
|
2015-11-05 15:16:52 +01:00
|
|
|
reshow_cmd(u, ord);
|
2017-03-10 21:43:36 +01:00
|
|
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error21"));
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error36"));
|
2016-03-23 22:24:11 +01:00
|
|
|
test_clear_messages(f);
|
2015-11-05 15:16:52 +01:00
|
|
|
|
2017-03-10 21:43:36 +01:00
|
|
|
i_add(&(u->items), i_new(itype, 1));
|
2015-11-05 15:16:52 +01:00
|
|
|
reshow_cmd(u, ord);
|
2017-03-10 21:43:36 +01:00
|
|
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error21"));
|
|
|
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error36"));
|
2016-03-23 22:24:11 +01:00
|
|
|
test_clear_messages(f);
|
2015-11-05 15:16:52 +01:00
|
|
|
|
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-11-05 15:16:52 +01:00
|
|
|
}
|
|
|
|
|
2016-06-06 23:39:40 +02:00
|
|
|
static void test_show_race(CuTest *tc) {
|
|
|
|
order *ord;
|
|
|
|
race * rc;
|
|
|
|
unit *u;
|
|
|
|
struct locale *loc;
|
|
|
|
message * msg;
|
|
|
|
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
2016-06-06 23:39:40 +02:00
|
|
|
|
|
|
|
mt_register(mt_new_va("msg_event", "string:string", 0));
|
|
|
|
test_create_race("human");
|
|
|
|
rc = test_create_race("elf");
|
|
|
|
|
|
|
|
loc = get_or_create_locale("de");
|
|
|
|
locale_setstring(loc, "race::elf_p", "Elfen");
|
|
|
|
locale_setstring(loc, "race::elf", "Elf");
|
|
|
|
locale_setstring(loc, "race::human_p", "Menschen");
|
|
|
|
locale_setstring(loc, "race::human", "Mensch");
|
|
|
|
init_locale(loc);
|
|
|
|
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0));
|
|
|
|
u->faction->locale = loc;
|
|
|
|
|
|
|
|
ord = create_order(K_RESHOW, loc, "Mensch");
|
|
|
|
reshow_cmd(u, ord);
|
|
|
|
CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "error21") != NULL);
|
|
|
|
CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "msg_event") == NULL);
|
|
|
|
test_clear_messages(u->faction);
|
|
|
|
free_order(ord);
|
|
|
|
|
|
|
|
ord = create_order(K_RESHOW, loc, "Elf");
|
|
|
|
reshow_cmd(u, ord);
|
|
|
|
CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "error21") == NULL);
|
|
|
|
msg = test_find_messagetype(u->faction->msgs, "msg_event");
|
|
|
|
CuAssertPtrNotNull(tc, msg);
|
|
|
|
CuAssertTrue(tc, memcmp("Elf:", msg->parameters[0].v, 4) == 0);
|
|
|
|
test_clear_messages(u->faction);
|
|
|
|
free_order(ord);
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-06-06 23:39:40 +02:00
|
|
|
}
|
|
|
|
|
2016-06-11 16:50:55 +02:00
|
|
|
static void test_show_both(CuTest *tc) {
|
|
|
|
order *ord;
|
|
|
|
race * rc;
|
|
|
|
unit *u;
|
|
|
|
struct locale *loc;
|
|
|
|
message * msg;
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_setup();
|
2016-06-11 16:50:55 +02:00
|
|
|
mt_register(mt_new_va("msg_event", "string:string", 0));
|
|
|
|
mt_register(mt_new_va("displayitem", "weight:int", "item:resource", "description:string", 0));
|
|
|
|
rc = test_create_race("elf");
|
|
|
|
test_create_itemtype("elvenhorse");
|
|
|
|
|
|
|
|
loc = get_or_create_locale("de");
|
|
|
|
locale_setstring(loc, "elvenhorse", "Elfenpferd");
|
|
|
|
locale_setstring(loc, "elvenhorse_p", "Elfenpferde");
|
|
|
|
locale_setstring(loc, "iteminfo::elvenhorse", "Hiyaa!");
|
|
|
|
locale_setstring(loc, "race::elf_p", "Elfen");
|
|
|
|
locale_setstring(loc, "race::elf", "Elf");
|
|
|
|
init_locale(loc);
|
|
|
|
|
|
|
|
CuAssertPtrNotNull(tc, finditemtype("elf", loc));
|
|
|
|
CuAssertPtrNotNull(tc, findrace("elf", loc));
|
|
|
|
|
|
|
|
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0));
|
|
|
|
u->faction->locale = loc;
|
|
|
|
i_change(&u->items, finditemtype("elfenpferd", loc), 1);
|
|
|
|
ord = create_order(K_RESHOW, loc, "Elf");
|
|
|
|
reshow_cmd(u, ord);
|
|
|
|
CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "error36") == NULL);
|
|
|
|
msg = test_find_messagetype(u->faction->msgs, "msg_event");
|
|
|
|
CuAssertPtrNotNull(tc, msg);
|
|
|
|
CuAssertTrue(tc, memcmp("Elf:", msg->parameters[0].v, 4) == 0);
|
|
|
|
msg = test_find_messagetype(u->faction->msgs, "displayitem");
|
|
|
|
CuAssertPtrNotNull(tc, msg);
|
|
|
|
CuAssertTrue(tc, memcmp("Hiyaa!", msg->parameters[2].v, 4) == 0);
|
|
|
|
test_clear_messages(u->faction);
|
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-06-11 16:50:55 +02:00
|
|
|
}
|
|
|
|
|
2015-12-07 19:41:34 +01:00
|
|
|
static void test_immigration(CuTest * tc)
|
|
|
|
{
|
|
|
|
region *r;
|
|
|
|
double inject[] = { 1 };
|
|
|
|
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
|
|
|
r = test_create_region(0, 0, 0);
|
2015-12-07 19:41:34 +01:00
|
|
|
|
|
|
|
rsetpeasants(r, 0);
|
|
|
|
config_set("rules.economy.repopulate_maximum", 0);
|
|
|
|
|
|
|
|
random_source_inject_constant(0);
|
|
|
|
|
|
|
|
immigration();
|
|
|
|
CuAssertIntEquals(tc, 0, rpeasants(r));
|
|
|
|
|
|
|
|
random_source_inject_constant(1);
|
|
|
|
|
|
|
|
immigration();
|
|
|
|
CuAssertIntEquals(tc, 2, rpeasants(r));
|
|
|
|
|
|
|
|
random_source_inject_array(inject, 2);
|
|
|
|
|
2017-03-16 16:07:52 +01:00
|
|
|
config_set("rules.wage.function", "0");
|
2015-12-07 19:41:34 +01:00
|
|
|
immigration();
|
|
|
|
CuAssertIntEquals(tc, 2, rpeasants(r));
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-12-07 19:41:34 +01:00
|
|
|
}
|
|
|
|
|
2016-02-28 16:11:51 +01:00
|
|
|
static void test_demon_hunger(CuTest * tc)
|
|
|
|
{
|
|
|
|
const resource_type *rtype;
|
|
|
|
region *r;
|
|
|
|
race *rc;
|
|
|
|
faction *f;
|
|
|
|
unit *u;
|
|
|
|
|
2017-03-10 21:29:37 +01:00
|
|
|
test_setup();
|
|
|
|
init_resources();
|
|
|
|
r = test_create_region(0, 0, 0);
|
2016-02-28 16:11:51 +01:00
|
|
|
rc = test_create_race("demon");
|
|
|
|
f = test_create_faction(rc);
|
|
|
|
u = test_create_unit(f, r);
|
|
|
|
u->hp = 999;
|
|
|
|
|
2017-12-17 14:06:40 +01:00
|
|
|
config_set("hunger.demon.peasant_tolerance", "1");
|
2016-02-28 16:11:51 +01:00
|
|
|
|
|
|
|
rtype = get_resourcetype(R_SILVER);
|
|
|
|
i_change(&u->items, rtype->itype, 30);
|
|
|
|
scale_number(u, 1);
|
|
|
|
rsetpeasants(r, 0);
|
|
|
|
|
|
|
|
get_food(r);
|
|
|
|
|
|
|
|
CuAssertIntEquals(tc, 20, i_get(u->items, rtype->itype));
|
|
|
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "malnourish"));
|
|
|
|
|
2017-12-17 14:06:40 +01:00
|
|
|
config_set("hunger.demon.peasant_tolerance", "0");
|
2016-02-28 16:11:51 +01:00
|
|
|
|
|
|
|
get_food(r);
|
|
|
|
|
|
|
|
CuAssertIntEquals(tc, 10, i_get(u->items, rtype->itype));
|
2018-01-12 21:15:21 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "malnourish"));
|
2016-02-28 20:34:37 +01:00
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-02-28 16:11:51 +01:00
|
|
|
}
|
|
|
|
|
2016-10-25 00:04:33 +02:00
|
|
|
static void test_armedmen(CuTest *tc) {
|
2017-02-18 21:15:14 +01:00
|
|
|
/* TODO: test RCF_NOWEAPONS and SK_WEAPONLESS */
|
2016-10-25 00:04:33 +02:00
|
|
|
unit *u;
|
|
|
|
item_type *it_sword;
|
2016-10-25 15:01:54 +02:00
|
|
|
weapon_type *wtype;
|
2016-10-25 00:04:33 +02:00
|
|
|
test_setup();
|
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
|
|
|
it_sword = test_create_itemtype("sword");
|
2017-12-17 10:16:56 +01:00
|
|
|
wtype = new_weapontype(it_sword, 0, frac_make(1, 2), 0, 0, 0, 0, SK_MELEE);
|
2016-10-25 00:04:33 +02:00
|
|
|
CuAssertIntEquals(tc, 0, armedmen(u, false));
|
|
|
|
CuAssertIntEquals(tc, 0, armedmen(u, true));
|
|
|
|
set_level(u, SK_MELEE, 1);
|
|
|
|
CuAssertIntEquals(tc, 0, armedmen(u, false));
|
|
|
|
i_change(&u->items, it_sword, 1);
|
|
|
|
CuAssertIntEquals(tc, 1, armedmen(u, false));
|
|
|
|
i_change(&u->items, it_sword, 1);
|
|
|
|
CuAssertIntEquals(tc, 1, armedmen(u, false));
|
2016-10-25 00:13:57 +02:00
|
|
|
scale_number(u, 2);
|
|
|
|
set_level(u, SK_MELEE, 1);
|
|
|
|
CuAssertIntEquals(tc, 2, armedmen(u, false));
|
2016-10-25 00:04:33 +02:00
|
|
|
set_level(u, SK_MELEE, 0);
|
|
|
|
CuAssertIntEquals(tc, 0, armedmen(u, false));
|
2016-10-25 15:01:54 +02:00
|
|
|
set_level(u, SK_MELEE, 1);
|
|
|
|
i_change(&u->items, it_sword, -1);
|
|
|
|
CuAssertIntEquals(tc, 1, armedmen(u, false));
|
|
|
|
wtype->flags |= WTF_SIEGE;
|
|
|
|
CuAssertIntEquals(tc, 0, armedmen(u, false));
|
|
|
|
CuAssertIntEquals(tc, 1, armedmen(u, true));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-10-25 00:04:33 +02:00
|
|
|
}
|
|
|
|
|
2017-10-13 18:41:29 +02:00
|
|
|
static void test_cansee(CuTest *tc) {
|
|
|
|
unit *u, *u2;
|
2017-10-15 20:20:43 +02:00
|
|
|
|
2017-10-13 18:41:29 +02:00
|
|
|
test_setup();
|
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
|
|
|
u2 = test_create_unit(test_create_faction(0), u->region);
|
2017-10-15 20:20:43 +02:00
|
|
|
|
|
|
|
CuAssertTrue(tc, cansee(u->faction, u->region, u2, 0));
|
2017-10-13 18:41:29 +02:00
|
|
|
|
|
|
|
set_level(u2, SK_STEALTH, 1);
|
2017-10-15 20:20:43 +02:00
|
|
|
CuAssertTrue(tc, !cansee(u->faction, u->region, u2, 0));
|
|
|
|
|
2017-10-13 18:41:29 +02:00
|
|
|
set_level(u, SK_PERCEPTION, 1);
|
2017-10-15 20:20:43 +02:00
|
|
|
CuAssertTrue(tc, cansee(u->faction, u->region, u2, 0));
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-10-13 19:32:31 +02:00
|
|
|
}
|
|
|
|
|
2017-10-15 20:20:43 +02:00
|
|
|
static void test_cansee_ring(CuTest *tc) {
|
2017-10-13 19:07:57 +02:00
|
|
|
unit *u, *u2;
|
2017-10-15 20:20:43 +02:00
|
|
|
item_type *itype[2];
|
2017-10-13 19:07:57 +02:00
|
|
|
|
|
|
|
test_setup();
|
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
|
|
|
u2 = test_create_unit(test_create_faction(0), u->region);
|
|
|
|
scale_number(u2, 2);
|
|
|
|
|
|
|
|
itype[0] = test_create_itemtype("roi");
|
2017-10-15 20:20:43 +02:00
|
|
|
itype[1] = test_create_itemtype("aots");
|
2017-10-13 19:07:57 +02:00
|
|
|
CuAssertPtrNotNull(tc, get_resourcetype(R_RING_OF_INVISIBILITY));
|
2017-10-15 20:20:43 +02:00
|
|
|
CuAssertPtrEquals(tc, itype[0]->rtype, (void *)get_resourcetype(R_RING_OF_INVISIBILITY));
|
2017-10-13 19:07:57 +02:00
|
|
|
CuAssertPtrNotNull(tc, get_resourcetype(R_AMULET_OF_TRUE_SEEING));
|
2017-10-15 20:20:43 +02:00
|
|
|
CuAssertPtrEquals(tc, itype[1]->rtype, (void *)get_resourcetype(R_AMULET_OF_TRUE_SEEING));
|
2017-10-13 19:07:57 +02:00
|
|
|
|
2017-10-15 20:20:43 +02:00
|
|
|
CuAssertTrue(tc, cansee(u->faction, u->region, u2, 0));
|
2017-10-13 19:07:57 +02:00
|
|
|
|
2017-10-15 20:20:43 +02:00
|
|
|
/* a single ring is not enough to hide two people */
|
2017-10-13 19:07:57 +02:00
|
|
|
i_change(&u2->items, itype[0], 1);
|
2017-10-15 20:20:43 +02:00
|
|
|
CuAssertTrue(tc, cansee(u->faction, u->region, u2, 0));
|
2017-10-13 19:07:57 +02:00
|
|
|
|
2017-10-15 20:20:43 +02:00
|
|
|
/* two rings can hide two people */
|
2017-10-13 19:07:57 +02:00
|
|
|
i_change(&u2->items, itype[0], 1);
|
2017-10-15 20:20:43 +02:00
|
|
|
CuAssertTrue(tc, !cansee(u->faction, u->region, u2, 0));
|
2017-10-13 19:07:57 +02:00
|
|
|
|
2017-10-15 20:20:43 +02:00
|
|
|
/* one amulet negates one of the two rings */
|
|
|
|
i_change(&u->items, itype[1], 1);
|
|
|
|
CuAssertTrue(tc, cansee(u->faction, u->region, u2, 0));
|
2017-10-13 18:41:29 +02:00
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-10-13 18:41:29 +02:00
|
|
|
}
|
|
|
|
|
2017-10-15 20:20:43 +02:00
|
|
|
static void test_cansee_sphere(CuTest *tc) {
|
|
|
|
unit *u, *u2;
|
|
|
|
item_type *itype[2];
|
|
|
|
|
2016-10-25 00:04:33 +02:00
|
|
|
test_setup();
|
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
2017-10-15 20:20:43 +02:00
|
|
|
u2 = test_create_unit(test_create_faction(0), u->region);
|
|
|
|
|
|
|
|
itype[0] = test_create_itemtype("sphereofinv");
|
|
|
|
itype[1] = test_create_itemtype("aots");
|
|
|
|
CuAssertPtrNotNull(tc, get_resourcetype(R_SPHERE_OF_INVISIBILITY));
|
|
|
|
CuAssertPtrEquals(tc, itype[0]->rtype, (void *)get_resourcetype(R_SPHERE_OF_INVISIBILITY));
|
|
|
|
CuAssertPtrNotNull(tc, get_resourcetype(R_AMULET_OF_TRUE_SEEING));
|
|
|
|
CuAssertPtrEquals(tc, itype[1]->rtype, (void *)get_resourcetype(R_AMULET_OF_TRUE_SEEING));
|
|
|
|
|
|
|
|
CuAssertTrue(tc, cansee(u->faction, u->region, u2, 0));
|
|
|
|
|
|
|
|
/* a single sphere can hide 100 people */
|
|
|
|
scale_number(u2, 100);
|
|
|
|
i_change(&u2->items, itype[0], 1);
|
|
|
|
CuAssertTrue(tc, !cansee(u->faction, u->region, u2, 0));
|
|
|
|
|
|
|
|
/* one single amulet negates it? */
|
|
|
|
i_change(&u->items, itype[1], 1);
|
|
|
|
CuAssertTrue(tc, cansee(u->faction, u->region, u2, 0));
|
|
|
|
|
|
|
|
/* number of people inside the sphere does not matter? */
|
|
|
|
scale_number(u2, 99);
|
|
|
|
CuAssertTrue(tc, cansee(u->faction, u->region, u2, 0));
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-10-25 00:04:33 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
CuSuite *get_laws_suite(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-10-14 18:32:04 +02:00
|
|
|
CuSuite *suite = CuSuiteNew();
|
2017-10-01 15:08:26 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_maketemp_default_order);
|
|
|
|
SUITE_ADD_TEST(suite, test_maketemp);
|
2015-08-15 20:25:36 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_nmr_warnings);
|
2015-08-05 12:19:17 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_ally_cmd);
|
2016-11-11 01:59:43 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_name_cmd);
|
2017-01-25 20:57:54 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_name_cmd_2274);
|
2017-11-12 15:05:17 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_name_unit);
|
|
|
|
SUITE_ADD_TEST(suite, test_name_region);
|
|
|
|
SUITE_ADD_TEST(suite, test_name_building);
|
|
|
|
SUITE_ADD_TEST(suite, test_name_ship);
|
2015-08-05 12:19:17 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_ally_cmd_errors);
|
2015-08-05 00:03:30 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_long_order_normal);
|
|
|
|
SUITE_ADD_TEST(suite, test_long_order_none);
|
|
|
|
SUITE_ADD_TEST(suite, test_long_order_cast);
|
|
|
|
SUITE_ADD_TEST(suite, test_long_order_buy_sell);
|
|
|
|
SUITE_ADD_TEST(suite, test_long_order_multi_long);
|
|
|
|
SUITE_ADD_TEST(suite, test_long_order_multi_buy);
|
2015-08-05 10:25:25 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_long_order_multi_sell);
|
2015-08-05 00:03:30 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_long_order_buy_cast);
|
|
|
|
SUITE_ADD_TEST(suite, test_long_order_hungry);
|
2014-10-14 18:32:04 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_new_building_can_be_renamed);
|
|
|
|
SUITE_ADD_TEST(suite, test_rename_building);
|
|
|
|
SUITE_ADD_TEST(suite, test_rename_building_twice);
|
|
|
|
SUITE_ADD_TEST(suite, test_fishing_feeds_2_people);
|
|
|
|
SUITE_ADD_TEST(suite, test_fishing_does_not_give_goblins_money);
|
|
|
|
SUITE_ADD_TEST(suite, test_fishing_gets_reset);
|
|
|
|
SUITE_ADD_TEST(suite, test_unit_limit);
|
2017-03-11 20:03:49 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_limit_new_units);
|
2014-10-14 18:32:04 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_update_guards);
|
|
|
|
SUITE_ADD_TEST(suite, test_newbie_cannot_guard);
|
|
|
|
SUITE_ADD_TEST(suite, test_unarmed_cannot_guard);
|
|
|
|
SUITE_ADD_TEST(suite, test_unarmed_races_can_guard);
|
2015-11-23 15:35:26 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_monsters_can_guard);
|
2014-10-14 18:32:04 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_fleeing_cannot_guard);
|
2017-12-17 10:16:56 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_unskilled_cannot_guard);
|
2014-10-14 18:32:04 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_reserve_self);
|
|
|
|
SUITE_ADD_TEST(suite, test_reserve_cmd);
|
2014-12-17 19:53:19 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_pay_cmd);
|
2014-12-17 21:31:02 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_pay_cmd_other_building);
|
2014-12-17 19:53:19 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_pay_cmd_must_be_owner);
|
2014-10-14 18:32:04 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_new_units);
|
|
|
|
SUITE_ADD_TEST(suite, test_cannot_create_unit_above_limit);
|
2014-10-30 07:50:01 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_contact);
|
2014-11-21 16:39:49 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_enter_building);
|
2014-11-21 17:13:45 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_enter_ship);
|
2014-12-20 22:18:38 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_display_cmd);
|
2015-06-19 07:53:11 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_rule_force_leave);
|
2015-01-05 18:14:55 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_force_leave_buildings);
|
|
|
|
SUITE_ADD_TEST(suite, test_force_leave_ships);
|
2015-01-05 22:09:08 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_force_leave_ships_on_ocean);
|
2015-01-30 17:40:04 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_peasant_luck_effect);
|
2015-10-11 12:44:22 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_mail_unit);
|
2015-10-11 12:52:13 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_mail_faction);
|
2015-10-11 12:44:22 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_mail_region);
|
|
|
|
SUITE_ADD_TEST(suite, test_mail_unit_no_msg);
|
2015-10-11 12:52:13 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_mail_faction_no_msg);
|
2015-10-11 12:44:22 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_mail_region_no_msg);
|
2015-10-11 12:52:13 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_mail_faction_no_target);
|
2015-10-13 13:32:27 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_luck_message);
|
2015-11-05 15:16:52 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_show_without_item);
|
2016-06-06 23:39:40 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_show_race);
|
2016-06-11 16:50:55 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_show_both);
|
2015-12-07 19:41:34 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_immigration);
|
2016-02-28 16:11:51 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_demon_hunger);
|
2016-10-25 00:04:33 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_armedmen);
|
2017-10-13 18:41:29 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_cansee);
|
2017-10-15 20:20:43 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_cansee_ring);
|
|
|
|
SUITE_ADD_TEST(suite, test_cansee_sphere);
|
2015-01-05 22:09:08 +01:00
|
|
|
|
2014-10-14 18:32:04 +02:00
|
|
|
return suite;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|