2014-08-26 20:06:28 +02:00
|
|
|
#include <platform.h>
|
|
|
|
#include <kernel/config.h>
|
2015-05-06 17:36:20 +02:00
|
|
|
#include <kernel/curse.h>
|
|
|
|
#include <kernel/item.h>
|
2015-11-02 14:56:58 +01:00
|
|
|
#include <kernel/building.h>
|
2015-05-06 17:36:20 +02:00
|
|
|
#include <kernel/faction.h>
|
|
|
|
#include <kernel/order.h>
|
|
|
|
#include <kernel/race.h>
|
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/spell.h>
|
2014-12-09 06:45:21 +01:00
|
|
|
#include <util/base36.h>
|
|
|
|
#include <util/language.h>
|
2015-05-06 17:36:20 +02:00
|
|
|
#include <util/attrib.h>
|
|
|
|
#include <spells/regioncurse.h>
|
|
|
|
#include <alchemy.h>
|
|
|
|
#include <laws.h>
|
|
|
|
#include <spells.h>
|
2014-08-26 20:06:28 +02:00
|
|
|
#include "unit.h"
|
|
|
|
|
|
|
|
#include <CuTest.h>
|
|
|
|
#include <tests.h>
|
|
|
|
|
2014-12-09 06:45:21 +01:00
|
|
|
#include <stdio.h>
|
2014-08-26 20:06:28 +02:00
|
|
|
#include <stdlib.h>
|
2014-12-09 06:45:21 +01:00
|
|
|
#include <string.h>
|
2014-08-26 20:06:28 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
2014-10-16 07:34:09 +02:00
|
|
|
static void test_remove_empty_units(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
int uid;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
test_create_world();
|
|
|
|
|
|
|
|
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
|
|
|
uid = u->no;
|
|
|
|
remove_empty_units();
|
|
|
|
CuAssertPtrNotNull(tc, findunit(uid));
|
|
|
|
u->number = 0;
|
|
|
|
remove_empty_units();
|
|
|
|
CuAssertPtrEquals(tc, 0, findunit(uid));
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_remove_empty_units_in_region(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
int uid;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
test_create_world();
|
|
|
|
|
|
|
|
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
2016-09-11 20:09:48 +02:00
|
|
|
u = test_create_unit(u->faction, u->region);
|
|
|
|
CuAssertPtrNotNull(tc, u->nextF);
|
2014-10-16 07:34:09 +02:00
|
|
|
uid = u->no;
|
|
|
|
remove_empty_units_in_region(u->region);
|
|
|
|
CuAssertPtrNotNull(tc, findunit(uid));
|
|
|
|
u->number = 0;
|
|
|
|
remove_empty_units_in_region(u->region);
|
|
|
|
CuAssertPtrEquals(tc, 0, findunit(uid));
|
2016-09-11 20:09:48 +02:00
|
|
|
CuAssertPtrEquals(tc, 0, u->nextF);
|
2014-10-16 07:34:09 +02:00
|
|
|
CuAssertPtrEquals(tc, 0, u->region);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-10-16 08:06:44 +02:00
|
|
|
static void test_remove_units_without_faction(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
int uid;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
test_create_world();
|
|
|
|
|
|
|
|
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
|
|
|
uid = u->no;
|
|
|
|
u_setfaction(u, 0);
|
|
|
|
remove_empty_units_in_region(u->region);
|
|
|
|
CuAssertPtrEquals(tc, 0, findunit(uid));
|
|
|
|
CuAssertIntEquals(tc, 0, u->number);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_remove_units_with_dead_faction(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
int uid;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
test_create_world();
|
|
|
|
|
|
|
|
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
|
|
|
uid = u->no;
|
2016-01-11 11:54:45 +01:00
|
|
|
u->faction->_alive = false;
|
2014-10-16 08:06:44 +02:00
|
|
|
remove_empty_units_in_region(u->region);
|
|
|
|
CuAssertPtrEquals(tc, 0, findunit(uid));
|
|
|
|
CuAssertIntEquals(tc, 0, u->number);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_remove_units_ignores_spells(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
int uid;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
test_create_world();
|
|
|
|
|
2016-09-20 20:27:41 +02:00
|
|
|
u = create_unit(findregion(0, 0), test_create_faction(test_create_race("human")), 1, test_create_race("spell"), 0, 0, 0);
|
2014-10-16 08:06:44 +02:00
|
|
|
uid = u->no;
|
|
|
|
u->number = 0;
|
|
|
|
u->age = 1;
|
|
|
|
remove_empty_units_in_region(u->region);
|
|
|
|
CuAssertPtrNotNull(tc, findunit(uid));
|
|
|
|
CuAssertPtrNotNull(tc, u->region);
|
|
|
|
u->age = 0;
|
|
|
|
remove_empty_units_in_region(u->region);
|
|
|
|
CuAssertPtrEquals(tc, 0, findunit(uid));
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-08-26 20:06:28 +02:00
|
|
|
static void test_scale_number(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
const struct potion_type *ptype;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
test_create_world();
|
|
|
|
ptype = new_potiontype(it_get_or_create(rt_get_or_create("hodor")), 1);
|
|
|
|
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
|
|
|
change_effect(u, ptype, 1);
|
|
|
|
CuAssertIntEquals(tc, 1, u->number);
|
2015-11-09 19:43:51 +01:00
|
|
|
CuAssertIntEquals(tc, 20, u->hp);
|
2014-08-26 20:06:28 +02:00
|
|
|
CuAssertIntEquals(tc, 1, get_effect(u, ptype));
|
|
|
|
scale_number(u, 2);
|
|
|
|
CuAssertIntEquals(tc, 2, u->number);
|
2015-11-09 19:43:51 +01:00
|
|
|
CuAssertIntEquals(tc, 40, u->hp);
|
2014-08-26 20:06:28 +02:00
|
|
|
CuAssertIntEquals(tc, 2, get_effect(u, ptype));
|
|
|
|
set_level(u, SK_ALCHEMY, 1);
|
|
|
|
scale_number(u, 0);
|
|
|
|
CuAssertIntEquals(tc, 0, get_level(u, SK_ALCHEMY));
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-12-09 06:45:21 +01:00
|
|
|
static void test_unit_name(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
char name[32];
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
test_create_world();
|
|
|
|
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
|
|
|
unit_setname(u, "Hodor");
|
|
|
|
_snprintf(name, sizeof(name), "Hodor (%s)", itoa36(u->no));
|
|
|
|
CuAssertStrEquals(tc, name, unitname(u));
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_unit_name_from_race(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
char name[32];
|
|
|
|
struct locale *lang;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
test_create_world();
|
|
|
|
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
|
|
|
unit_setname(u, NULL);
|
|
|
|
lang = get_or_create_locale("de");
|
2014-12-09 07:20:36 +01:00
|
|
|
locale_setstring(lang, rc_name_s(u->_race, NAME_SINGULAR), "Mensch");
|
|
|
|
locale_setstring(lang, rc_name_s(u->_race, NAME_PLURAL), "Menschen");
|
2014-12-09 06:45:21 +01:00
|
|
|
|
|
|
|
_snprintf(name, sizeof(name), "Mensch (%s)", itoa36(u->no));
|
|
|
|
CuAssertStrEquals(tc, name, unitname(u));
|
2015-02-11 07:55:35 +01:00
|
|
|
CuAssertStrEquals(tc, "Mensch", unit_getname(u));
|
2014-12-09 06:45:21 +01:00
|
|
|
|
|
|
|
u->number = 2;
|
|
|
|
_snprintf(name, sizeof(name), "Menschen (%s)", itoa36(u->no));
|
|
|
|
CuAssertStrEquals(tc, name, unitname(u));
|
2015-02-11 07:55:35 +01:00
|
|
|
CuAssertStrEquals(tc, "Menschen", unit_getname(u));
|
2014-12-09 06:45:21 +01:00
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-12-09 07:20:36 +01:00
|
|
|
static void test_update_monster_name(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
struct locale *lang;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
test_create_world();
|
|
|
|
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
|
|
|
lang = get_or_create_locale("de");
|
|
|
|
locale_setstring(lang, rc_name_s(u->_race, NAME_SINGULAR), "Mensch");
|
|
|
|
locale_setstring(lang, rc_name_s(u->_race, NAME_PLURAL), "Menschen");
|
|
|
|
|
|
|
|
unit_setname(u, "Hodor");
|
2014-12-09 07:44:26 +01:00
|
|
|
CuAssertTrue(tc, !unit_name_equals_race(u));
|
|
|
|
|
|
|
|
unit_setname(u, "Menschling");
|
|
|
|
CuAssertTrue(tc, !unit_name_equals_race(u));
|
|
|
|
|
|
|
|
unit_setname(u, rc_name_s(u->_race, NAME_SINGULAR));
|
|
|
|
CuAssertTrue(tc, unit_name_equals_race(u));
|
|
|
|
|
|
|
|
unit_setname(u, rc_name_s(u->_race, NAME_PLURAL));
|
|
|
|
CuAssertTrue(tc, unit_name_equals_race(u));
|
2014-12-09 07:20:36 +01:00
|
|
|
|
|
|
|
unit_setname(u, "Mensch");
|
2014-12-09 07:44:26 +01:00
|
|
|
CuAssertTrue(tc, unit_name_equals_race(u));
|
2014-12-09 07:20:36 +01:00
|
|
|
|
|
|
|
unit_setname(u, "Menschen");
|
2014-12-09 07:44:26 +01:00
|
|
|
CuAssertTrue(tc, unit_name_equals_race(u));
|
2014-12-09 07:20:36 +01:00
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2015-02-11 22:41:10 +01:00
|
|
|
static void test_names(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
test_create_world();
|
|
|
|
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
|
|
|
|
|
|
|
unit_setname(u, "Hodor");
|
|
|
|
unit_setid(u, 5);
|
|
|
|
CuAssertStrEquals(tc, "Hodor", unit_getname(u));
|
|
|
|
CuAssertStrEquals(tc, "Hodor (5)", unitname(u));
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2015-02-11 16:47:26 +01:00
|
|
|
static void test_default_name(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
struct locale* lang;
|
|
|
|
char buf[32], compare[32];
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
test_create_world();
|
|
|
|
lang = get_or_create_locale("de");
|
2016-04-09 19:10:51 +02:00
|
|
|
locale_setstring(lang, "unitdefault", "Zweiheit");
|
2015-02-11 16:47:26 +01:00
|
|
|
|
|
|
|
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
|
|
|
|
|
|
|
default_name(u, buf, sizeof(buf));
|
|
|
|
|
2016-04-09 19:10:51 +02:00
|
|
|
sprintf(compare, "Zweiheit %s", itoa36(u->no));
|
2015-02-11 16:47:26 +01:00
|
|
|
CuAssertStrEquals(tc, compare, buf);
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2015-08-26 08:22:51 +02:00
|
|
|
static int cb_skillmod(const unit *u, const region *r, skill_t sk, int level) {
|
|
|
|
unused_arg(u);
|
|
|
|
unused_arg(r);
|
|
|
|
unused_arg(sk);
|
|
|
|
return level + 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_skillmod(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
attrib *a;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
|
|
|
set_level(u, SK_ARMORER, 5);
|
2015-08-29 15:00:59 +02:00
|
|
|
CuAssertIntEquals(tc, 5, effskill(u, SK_ARMORER, 0));
|
2015-08-26 08:22:51 +02:00
|
|
|
|
|
|
|
a_add(&u->attribs, a = make_skillmod(SK_ARMORER, SMF_ALWAYS, 0, 2.0, 0));
|
2015-08-29 15:00:59 +02:00
|
|
|
CuAssertIntEquals(tc, 10, effskill(u, SK_ARMORER, 0));
|
2015-08-26 08:22:51 +02:00
|
|
|
a_remove(&u->attribs, a);
|
|
|
|
|
2015-08-26 08:36:25 +02:00
|
|
|
a_add(&u->attribs, a = make_skillmod(NOSKILL, SMF_ALWAYS, 0, 2.0, 0)); // NOSKILL means any skill
|
2015-08-29 15:00:59 +02:00
|
|
|
CuAssertIntEquals(tc, 10, effskill(u, SK_ARMORER, 0));
|
2015-08-26 08:36:25 +02:00
|
|
|
a_remove(&u->attribs, a);
|
|
|
|
|
2015-08-26 08:22:51 +02:00
|
|
|
a_add(&u->attribs, a = make_skillmod(SK_ARMORER, SMF_ALWAYS, 0, 0, 2));
|
2015-08-29 15:00:59 +02:00
|
|
|
CuAssertIntEquals(tc, 7, effskill(u, SK_ARMORER, 0));
|
2015-08-26 08:22:51 +02:00
|
|
|
a_remove(&u->attribs, a);
|
|
|
|
|
|
|
|
a_add(&u->attribs, a = make_skillmod(SK_ARMORER, SMF_ALWAYS, cb_skillmod, 0, 0));
|
2015-08-29 15:00:59 +02:00
|
|
|
CuAssertIntEquals(tc, 8, effskill(u, SK_ARMORER, 0));
|
2015-08-26 08:22:51 +02:00
|
|
|
a_remove(&u->attribs, a);
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_skill_hunger(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
|
|
|
set_level(u, SK_ARMORER, 6);
|
|
|
|
set_level(u, SK_SAILING, 6);
|
|
|
|
fset(u, UFL_HUNGER);
|
2015-08-29 15:00:59 +02:00
|
|
|
CuAssertIntEquals(tc, 3, effskill(u, SK_ARMORER, 0));
|
|
|
|
CuAssertIntEquals(tc, 5, effskill(u, SK_SAILING, 0));
|
2015-08-26 08:22:51 +02:00
|
|
|
set_level(u, SK_SAILING, 2);
|
2015-08-29 15:00:59 +02:00
|
|
|
CuAssertIntEquals(tc, 1, effskill(u, SK_SAILING, 0));
|
2015-08-26 08:42:45 +02:00
|
|
|
test_cleanup();
|
2015-08-26 08:22:51 +02:00
|
|
|
}
|
2015-05-06 17:36:20 +02:00
|
|
|
|
2015-08-26 08:36:25 +02:00
|
|
|
static void test_skill_familiar(CuTest *tc) {
|
|
|
|
unit *mag, *fam;
|
|
|
|
region *r;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
|
|
|
|
// setup two units
|
|
|
|
mag = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
|
|
|
fam = test_create_unit(mag->faction, test_create_region(0, 0, 0));
|
|
|
|
set_level(fam, SK_PERCEPTION, 6);
|
2015-08-29 15:00:59 +02:00
|
|
|
CuAssertIntEquals(tc, 6, effskill(fam, SK_PERCEPTION, 0));
|
2015-08-26 08:36:25 +02:00
|
|
|
set_level(mag, SK_PERCEPTION, 6);
|
2015-08-29 15:00:59 +02:00
|
|
|
CuAssertIntEquals(tc, 6, effskill(mag, SK_PERCEPTION, 0));
|
2015-08-26 08:36:25 +02:00
|
|
|
|
|
|
|
// make them mage and familiar to each other
|
|
|
|
CuAssertIntEquals(tc, true, create_newfamiliar(mag, fam));
|
|
|
|
|
|
|
|
// when they are in the same region, the mage gets half their skill as a bonus
|
2015-08-29 15:00:59 +02:00
|
|
|
CuAssertIntEquals(tc, 6, effskill(fam, SK_PERCEPTION, 0));
|
|
|
|
CuAssertIntEquals(tc, 9, effskill(mag, SK_PERCEPTION, 0));
|
2015-08-26 08:36:25 +02:00
|
|
|
|
|
|
|
// when they are further apart, divide bonus by distance
|
|
|
|
r = test_create_region(3, 0, 0);
|
|
|
|
move_unit(fam, r, &r->units);
|
2015-08-29 15:00:59 +02:00
|
|
|
CuAssertIntEquals(tc, 7, effskill(mag, SK_PERCEPTION, 0));
|
2015-08-26 08:42:45 +02:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_age_familiar(CuTest *tc) {
|
|
|
|
unit *mag, *fam;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
|
|
|
|
// setup two units
|
|
|
|
mag = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
|
|
|
fam = test_create_unit(mag->faction, test_create_region(0, 0, 0));
|
|
|
|
CuAssertPtrEquals(tc, 0, get_familiar(mag));
|
|
|
|
CuAssertPtrEquals(tc, 0, get_familiar_mage(fam));
|
|
|
|
CuAssertIntEquals(tc, true, create_newfamiliar(mag, fam));
|
|
|
|
CuAssertPtrEquals(tc, fam, get_familiar(mag));
|
|
|
|
CuAssertPtrEquals(tc, mag, get_familiar_mage(fam));
|
2015-12-16 22:18:44 +01:00
|
|
|
a_age(&fam->attribs, fam);
|
|
|
|
a_age(&mag->attribs, mag);
|
2015-08-26 08:42:45 +02:00
|
|
|
CuAssertPtrEquals(tc, fam, get_familiar(mag));
|
|
|
|
CuAssertPtrEquals(tc, mag, get_familiar_mage(fam));
|
|
|
|
set_number(fam, 0);
|
2015-12-16 22:18:44 +01:00
|
|
|
a_age(&mag->attribs, mag);
|
2015-08-26 08:42:45 +02:00
|
|
|
CuAssertPtrEquals(tc, 0, get_familiar(mag));
|
|
|
|
test_cleanup();
|
2015-08-26 08:36:25 +02:00
|
|
|
}
|
|
|
|
|
2015-11-02 14:56:58 +01:00
|
|
|
static void test_inside_building(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
building *b;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
|
|
|
b = test_create_building(u->region, 0);
|
|
|
|
|
|
|
|
b->size = 1;
|
|
|
|
scale_number(u, 1);
|
|
|
|
CuAssertPtrEquals(tc, 0, inside_building(u));
|
|
|
|
u->building = b;
|
|
|
|
CuAssertPtrEquals(tc, b, inside_building(u));
|
|
|
|
scale_number(u, 2);
|
|
|
|
CuAssertPtrEquals(tc, 0, inside_building(u));
|
|
|
|
b->size = 2;
|
|
|
|
CuAssertPtrEquals(tc, b, inside_building(u));
|
2015-11-02 15:05:54 +01:00
|
|
|
u = test_create_unit(u->faction, u->region);
|
|
|
|
u->building = b;
|
|
|
|
CuAssertPtrEquals(tc, 0, inside_building(u));
|
|
|
|
b->size = 3;
|
|
|
|
CuAssertPtrEquals(tc, b, inside_building(u));
|
2015-11-02 14:56:58 +01:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2015-11-24 19:53:27 +01:00
|
|
|
static void test_limited_skills(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
test_cleanup();
|
|
|
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
|
|
|
CuAssertIntEquals(tc, false, has_limited_skills(u));
|
|
|
|
set_level(u, SK_ENTERTAINMENT, 1);
|
|
|
|
CuAssertIntEquals(tc, false, has_limited_skills(u));
|
|
|
|
u->skills->id = SK_ALCHEMY;
|
|
|
|
CuAssertIntEquals(tc, true, has_limited_skills(u));
|
|
|
|
u->skills->id = SK_MAGIC;
|
|
|
|
CuAssertIntEquals(tc, true, has_limited_skills(u));
|
|
|
|
u->skills->id = SK_TACTICS;
|
|
|
|
CuAssertIntEquals(tc, true, has_limited_skills(u));
|
|
|
|
u->skills->id = SK_HERBALISM;
|
|
|
|
CuAssertIntEquals(tc, true, has_limited_skills(u));
|
|
|
|
u->skills->id = SK_SPY;
|
|
|
|
CuAssertIntEquals(tc, true, has_limited_skills(u));
|
|
|
|
u->skills->id = SK_TAXING;
|
|
|
|
CuAssertIntEquals(tc, false, has_limited_skills(u));
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2016-09-02 09:29:52 +02:00
|
|
|
static void test_unit_description(CuTest *tc) {
|
|
|
|
race *rc;
|
|
|
|
unit *u;
|
|
|
|
test_setup();
|
|
|
|
rc = test_create_race("hodor");
|
|
|
|
u = test_create_unit(test_create_faction(rc), test_create_region(0,0,0));
|
|
|
|
CuAssertPtrEquals(tc, 0, u->display);
|
|
|
|
CuAssertStrEquals(tc, 0, u_description(u, u->faction->locale));
|
|
|
|
u->display = _strdup("Hodor");
|
|
|
|
CuAssertStrEquals(tc, "Hodor", u_description(u, NULL));
|
|
|
|
CuAssertStrEquals(tc, "Hodor", u_description(u, u->faction->locale));
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2016-09-11 19:39:35 +02:00
|
|
|
static void test_remove_unit(CuTest *tc) {
|
|
|
|
region *r;
|
2016-09-18 11:39:04 +02:00
|
|
|
unit *u1, *u2;
|
2016-09-11 19:39:35 +02:00
|
|
|
faction *f;
|
|
|
|
int uno;
|
|
|
|
const resource_type *rtype;
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
init_resources();
|
|
|
|
rtype = get_resourcetype(R_SILVER);
|
|
|
|
r = test_create_region(0, 0, 0);
|
|
|
|
f = test_create_faction(0);
|
2016-09-18 11:39:04 +02:00
|
|
|
u2 = test_create_unit(f, r);
|
|
|
|
u1 = test_create_unit(f, r);
|
|
|
|
CuAssertPtrEquals(tc, u1, f->units);
|
|
|
|
CuAssertPtrEquals(tc, u2, u1->nextF);
|
|
|
|
CuAssertPtrEquals(tc, u1, u2->prevF);
|
|
|
|
CuAssertPtrEquals(tc, 0, u2->nextF);
|
|
|
|
uno = u1->no;
|
2016-09-11 19:39:35 +02:00
|
|
|
region_setresource(r, rtype, 0);
|
2016-09-18 11:39:04 +02:00
|
|
|
i_change(&u1->items, rtype->itype, 100);
|
|
|
|
remove_unit(&r->units, u1);
|
|
|
|
CuAssertIntEquals(tc, 0, u1->number);
|
|
|
|
CuAssertPtrEquals(tc, 0, u1->region);
|
|
|
|
// money is given to a survivor:
|
|
|
|
CuAssertPtrEquals(tc, 0, u1->items);
|
|
|
|
CuAssertIntEquals(tc, 0, region_getresource(r, rtype));
|
|
|
|
CuAssertIntEquals(tc, 100, i_get(u2->items, rtype->itype));
|
|
|
|
|
|
|
|
// unit is removed from f->units:
|
|
|
|
CuAssertPtrEquals(tc, 0, u1->nextF);
|
|
|
|
CuAssertPtrEquals(tc, u2, f->units);
|
|
|
|
CuAssertPtrEquals(tc, 0, u2->nextF);
|
|
|
|
CuAssertPtrEquals(tc, 0, u2->prevF);
|
|
|
|
// unit is no longer in r->units:
|
|
|
|
CuAssertPtrEquals(tc, u2, r->units);
|
|
|
|
CuAssertPtrEquals(tc, 0, u2->next);
|
|
|
|
|
|
|
|
// unit is in deleted_units:
|
2016-09-11 19:39:35 +02:00
|
|
|
CuAssertPtrEquals(tc, 0, findunit(uno));
|
|
|
|
CuAssertPtrEquals(tc, f, dfindhash(uno));
|
2016-09-18 11:39:04 +02:00
|
|
|
|
|
|
|
remove_unit(&r->units, u2);
|
|
|
|
// no survivor, give money to peasants:
|
|
|
|
CuAssertIntEquals(tc, 100, region_getresource(r, rtype));
|
|
|
|
// there are now no more units:
|
|
|
|
CuAssertPtrEquals(tc, 0, r->units);
|
|
|
|
CuAssertPtrEquals(tc, 0, f->units);
|
2016-09-11 19:39:35 +02:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-08-26 20:06:28 +02:00
|
|
|
CuSuite *get_unit_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_scale_number);
|
2016-09-02 09:29:52 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_unit_description);
|
2014-12-09 06:45:21 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_unit_name);
|
|
|
|
SUITE_ADD_TEST(suite, test_unit_name_from_race);
|
2014-12-09 07:20:36 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_update_monster_name);
|
2016-09-11 19:39:35 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_remove_unit);
|
2014-10-16 07:34:09 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_remove_empty_units);
|
2014-10-16 08:06:44 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_remove_units_ignores_spells);
|
|
|
|
SUITE_ADD_TEST(suite, test_remove_units_without_faction);
|
|
|
|
SUITE_ADD_TEST(suite, test_remove_units_with_dead_faction);
|
2014-10-16 07:34:09 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_remove_empty_units_in_region);
|
2015-02-11 22:41:10 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_names);
|
2015-02-11 16:47:26 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_default_name);
|
2015-08-26 08:22:51 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_skillmod);
|
|
|
|
SUITE_ADD_TEST(suite, test_skill_hunger);
|
2015-08-26 08:36:25 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_skill_familiar);
|
2015-08-26 08:42:45 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_age_familiar);
|
2015-11-02 14:56:58 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_inside_building);
|
2015-11-24 19:53:27 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_limited_skills);
|
2014-08-26 20:06:28 +02:00
|
|
|
return suite;
|
|
|
|
}
|