2017-12-29 06:13:28 +01:00
|
|
|
|
#ifdef _MSC_VER
|
2012-06-03 22:39:42 +02:00
|
|
|
|
#include <platform.h>
|
2017-12-29 06:13:28 +01:00
|
|
|
|
#endif
|
2014-07-06 08:06:51 +02:00
|
|
|
|
#include <kernel/config.h>
|
2012-05-27 17:38:17 +02:00
|
|
|
|
#include "economy.h"
|
|
|
|
|
|
2014-07-06 05:14:11 +02:00
|
|
|
|
#include <util/message.h>
|
2015-02-16 20:39:50 +01:00
|
|
|
|
#include <kernel/building.h>
|
|
|
|
|
#include <kernel/item.h>
|
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
|
#include <kernel/messages.h>
|
|
|
|
|
#include <kernel/order.h>
|
|
|
|
|
#include <kernel/pool.h>
|
2014-07-06 05:14:11 +02:00
|
|
|
|
#include <kernel/race.h>
|
2012-05-27 17:38:17 +02:00
|
|
|
|
#include <kernel/region.h>
|
2017-02-15 20:50:45 +01:00
|
|
|
|
#include <kernel/resources.h>
|
2012-05-27 17:38:17 +02:00
|
|
|
|
#include <kernel/ship.h>
|
2014-07-06 05:14:11 +02:00
|
|
|
|
#include <kernel/terrain.h>
|
2017-11-05 17:00:40 +01:00
|
|
|
|
#include <kernel/terrainid.h>
|
2015-02-16 20:39:50 +01:00
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
|
2018-09-29 11:37:17 +02:00
|
|
|
|
#include <kernel/attrib.h>
|
2015-02-16 20:39:50 +01:00
|
|
|
|
#include <util/language.h>
|
2017-12-29 06:13:28 +01:00
|
|
|
|
#include <util/macros.h>
|
2012-05-27 17:38:17 +02:00
|
|
|
|
|
2012-05-31 04:17:08 +02:00
|
|
|
|
#include <CuTest.h>
|
2012-05-27 17:38:17 +02:00
|
|
|
|
#include <tests.h>
|
2015-11-14 15:32:31 +01:00
|
|
|
|
#include <assert.h>
|
2012-05-27 17:38:17 +02:00
|
|
|
|
|
|
|
|
|
static void test_give_control_building(CuTest * tc)
|
|
|
|
|
{
|
2014-07-06 05:14:11 +02:00
|
|
|
|
unit *u1, *u2;
|
|
|
|
|
building *b;
|
|
|
|
|
struct faction *f;
|
|
|
|
|
region *r;
|
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_setup();
|
2018-01-14 09:38:26 +01:00
|
|
|
|
f = test_create_faction(NULL);
|
|
|
|
|
r = test_create_region(0, 0, NULL);
|
2018-01-14 09:58:45 +01:00
|
|
|
|
b = test_create_building(r, NULL);
|
2014-07-06 05:14:11 +02:00
|
|
|
|
u1 = test_create_unit(f, r);
|
|
|
|
|
u_set_building(u1, b);
|
|
|
|
|
u2 = test_create_unit(f, r);
|
|
|
|
|
u_set_building(u2, b);
|
|
|
|
|
CuAssertPtrEquals(tc, u1, building_owner(b));
|
|
|
|
|
give_control(u1, u2);
|
|
|
|
|
CuAssertPtrEquals(tc, u2, building_owner(b));
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2012-05-27 17:38:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void test_give_control_ship(CuTest * tc)
|
|
|
|
|
{
|
2014-07-06 05:14:11 +02:00
|
|
|
|
unit *u1, *u2;
|
|
|
|
|
ship *sh;
|
|
|
|
|
struct faction *f;
|
|
|
|
|
region *r;
|
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_setup();
|
2018-01-14 09:38:26 +01:00
|
|
|
|
f = test_create_faction(NULL);
|
|
|
|
|
r = test_create_region(0, 0, NULL);
|
2018-01-14 09:58:45 +01:00
|
|
|
|
sh = test_create_ship(r, NULL);
|
2014-07-06 05:14:11 +02:00
|
|
|
|
u1 = test_create_unit(f, r);
|
|
|
|
|
u_set_ship(u1, sh);
|
|
|
|
|
u2 = test_create_unit(f, r);
|
|
|
|
|
u_set_ship(u2, sh);
|
|
|
|
|
CuAssertPtrEquals(tc, u1, ship_owner(sh));
|
|
|
|
|
give_control(u1, u2);
|
|
|
|
|
CuAssertPtrEquals(tc, u2, ship_owner(sh));
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2014-07-06 05:14:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-06 06:12:34 +02:00
|
|
|
|
struct steal {
|
2014-07-06 05:14:11 +02:00
|
|
|
|
struct unit *u;
|
|
|
|
|
struct region *r;
|
|
|
|
|
struct faction *f;
|
2014-07-06 06:12:34 +02:00
|
|
|
|
};
|
2014-07-06 05:14:11 +02:00
|
|
|
|
|
2014-11-03 08:33:07 +01:00
|
|
|
|
static void setup_steal(struct steal *env, struct terrain_type *ter, struct race *rc) {
|
2014-07-06 06:12:34 +02:00
|
|
|
|
env->r = test_create_region(0, 0, ter);
|
|
|
|
|
env->f = test_create_faction(rc);
|
|
|
|
|
env->u = test_create_unit(env->f, env->r);
|
2014-07-06 05:14:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void test_steal_okay(CuTest * tc) {
|
2014-07-06 06:12:34 +02:00
|
|
|
|
struct steal env;
|
2014-07-06 05:14:11 +02:00
|
|
|
|
race *rc;
|
2014-11-03 08:33:07 +01:00
|
|
|
|
struct terrain_type *ter;
|
2018-05-19 20:53:51 +02:00
|
|
|
|
message *msg;
|
2014-07-06 05:14:11 +02:00
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_setup();
|
2014-07-06 05:14:11 +02:00
|
|
|
|
ter = test_create_terrain("plain", LAND_REGION);
|
|
|
|
|
rc = test_create_race("human");
|
|
|
|
|
rc->flags = 0;
|
2014-07-06 06:12:34 +02:00
|
|
|
|
setup_steal(&env, ter, rc);
|
2018-05-19 20:53:51 +02:00
|
|
|
|
CuAssertPtrEquals(tc, NULL, msg = steal_message(env.u, 0));
|
2018-05-19 21:01:10 +02:00
|
|
|
|
assert(!msg);
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2014-07-06 05:14:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void test_steal_nosteal(CuTest * tc) {
|
2014-07-06 06:12:34 +02:00
|
|
|
|
struct steal env;
|
2014-07-06 05:14:11 +02:00
|
|
|
|
race *rc;
|
|
|
|
|
terrain_type *ter;
|
|
|
|
|
message *msg;
|
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_setup();
|
2014-07-06 05:14:11 +02:00
|
|
|
|
ter = test_create_terrain("plain", LAND_REGION);
|
|
|
|
|
rc = test_create_race("human");
|
|
|
|
|
rc->flags = RCF_NOSTEAL;
|
2014-07-06 06:12:34 +02:00
|
|
|
|
setup_steal(&env, ter, rc);
|
2017-12-04 20:01:08 +01:00
|
|
|
|
CuAssertPtrNotNull(tc, msg = steal_message(env.u, 0));
|
2014-07-06 05:14:11 +02:00
|
|
|
|
msg_release(msg);
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2014-07-06 05:14:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void test_steal_ocean(CuTest * tc) {
|
2014-07-06 06:12:34 +02:00
|
|
|
|
struct steal env;
|
2014-07-06 05:14:11 +02:00
|
|
|
|
race *rc;
|
|
|
|
|
terrain_type *ter;
|
|
|
|
|
message *msg;
|
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_setup();
|
2014-07-06 05:14:11 +02:00
|
|
|
|
ter = test_create_terrain("ocean", SEA_REGION);
|
|
|
|
|
rc = test_create_race("human");
|
2014-07-06 06:12:34 +02:00
|
|
|
|
setup_steal(&env, ter, rc);
|
2017-12-04 20:01:08 +01:00
|
|
|
|
CuAssertPtrNotNull(tc, msg = steal_message(env.u, 0));
|
2014-07-06 05:14:11 +02:00
|
|
|
|
msg_release(msg);
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2012-05-27 17:38:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-16 20:39:50 +01:00
|
|
|
|
static struct unit *create_recruiter(void) {
|
|
|
|
|
region *r;
|
|
|
|
|
faction *f;
|
|
|
|
|
unit *u;
|
|
|
|
|
const resource_type* rtype;
|
|
|
|
|
|
2017-03-11 14:22:21 +01:00
|
|
|
|
r=test_create_region(0, 0, NULL);
|
2015-02-16 20:39:50 +01:00
|
|
|
|
rsetpeasants(r, 999);
|
2017-03-11 14:22:21 +01:00
|
|
|
|
f = test_create_faction(NULL);
|
2015-02-16 20:39:50 +01:00
|
|
|
|
u = test_create_unit(f, r);
|
|
|
|
|
rtype = get_resourcetype(R_SILVER);
|
|
|
|
|
change_resource(u, rtype, 1000);
|
|
|
|
|
return u;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-14 11:25:44 +01:00
|
|
|
|
static void setup_production(void) {
|
|
|
|
|
init_resources();
|
2018-10-28 21:28:05 +01:00
|
|
|
|
mt_create_feedback("error_cannotmake");
|
2018-05-18 19:58:49 +02:00
|
|
|
|
mt_create_va(mt_new("produce", NULL), "unit:unit", "region:region", "amount:int", "wanted:int", "resource:resource", MT_NEW_END);
|
|
|
|
|
mt_create_va(mt_new("income", NULL), "unit:unit", "region:region", "amount:int", "wanted:int", "mode:int", MT_NEW_END);
|
|
|
|
|
mt_create_va(mt_new("buy", NULL), "unit:unit", "money:int", MT_NEW_END);
|
|
|
|
|
mt_create_va(mt_new("buyamount", NULL), "unit:unit", "amount:int", "resource:resource", MT_NEW_END);
|
2018-01-14 11:25:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-16 20:39:50 +01:00
|
|
|
|
static void test_heroes_dont_recruit(CuTest * tc) {
|
|
|
|
|
unit *u;
|
|
|
|
|
|
2017-03-11 14:22:21 +01:00
|
|
|
|
test_setup();
|
2018-01-14 11:25:44 +01:00
|
|
|
|
setup_production();
|
2015-02-16 20:39:50 +01:00
|
|
|
|
u = create_recruiter();
|
2017-03-11 14:22:21 +01:00
|
|
|
|
|
2015-02-16 20:39:50 +01:00
|
|
|
|
fset(u, UFL_HERO);
|
2015-10-13 15:45:38 +02:00
|
|
|
|
unit_addorder(u, create_order(K_RECRUIT, default_locale, "1"));
|
2015-02-16 20:39:50 +01:00
|
|
|
|
|
|
|
|
|
economics(u->region);
|
|
|
|
|
|
|
|
|
|
CuAssertIntEquals(tc, 1, u->number);
|
2015-08-17 19:35:07 +02:00
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error_herorecruit"));
|
2015-02-16 20:39:50 +01:00
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2015-02-16 20:39:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void test_normals_recruit(CuTest * tc) {
|
|
|
|
|
unit *u;
|
|
|
|
|
|
2017-03-11 14:22:21 +01:00
|
|
|
|
test_setup();
|
2018-01-14 11:25:44 +01:00
|
|
|
|
setup_production();
|
2015-02-16 20:39:50 +01:00
|
|
|
|
u = create_recruiter();
|
2015-10-13 15:45:38 +02:00
|
|
|
|
unit_addorder(u, create_order(K_RECRUIT, default_locale, "1"));
|
2015-02-16 20:39:50 +01:00
|
|
|
|
|
|
|
|
|
economics(u->region);
|
|
|
|
|
|
|
|
|
|
CuAssertIntEquals(tc, 2, u->number);
|
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2015-02-16 20:39:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-05 17:00:40 +01:00
|
|
|
|
/**
|
|
|
|
|
* Create any terrain types that are used by the trade rules.
|
|
|
|
|
*
|
|
|
|
|
* This should prevent newterrain from returning NULL.
|
|
|
|
|
*/
|
|
|
|
|
static void setup_terrains(CuTest *tc) {
|
|
|
|
|
test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION | FLY_INTO);
|
|
|
|
|
test_create_terrain("ocean", SEA_REGION | SWIM_INTO | FLY_INTO);
|
|
|
|
|
test_create_terrain("swamp", LAND_REGION | WALK_INTO | FLY_INTO);
|
|
|
|
|
test_create_terrain("desert", LAND_REGION | WALK_INTO | FLY_INTO);
|
2017-11-05 19:15:43 +01:00
|
|
|
|
test_create_terrain("mountain", LAND_REGION | WALK_INTO | FLY_INTO);
|
2017-11-05 17:00:40 +01:00
|
|
|
|
init_terrains();
|
2017-11-05 19:15:43 +01:00
|
|
|
|
CuAssertPtrNotNull(tc, newterrain(T_MOUNTAIN));
|
2017-11-05 17:00:40 +01:00
|
|
|
|
CuAssertPtrNotNull(tc, newterrain(T_OCEAN));
|
|
|
|
|
CuAssertPtrNotNull(tc, newterrain(T_PLAIN));
|
|
|
|
|
CuAssertPtrNotNull(tc, newterrain(T_SWAMP));
|
|
|
|
|
CuAssertPtrNotNull(tc, newterrain(T_DESERT));
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-05 15:11:02 +01:00
|
|
|
|
static region *setup_trade_region(CuTest *tc, const struct terrain_type *terrain) {
|
|
|
|
|
region *r;
|
|
|
|
|
item_type *it_luxury;
|
|
|
|
|
struct locale * lang = default_locale;
|
|
|
|
|
|
2018-01-19 16:59:52 +01:00
|
|
|
|
new_luxurytype(it_luxury = test_create_itemtype("balm"), 5);
|
2017-11-05 15:11:02 +01:00
|
|
|
|
locale_setstring(lang, it_luxury->rtype->_name, it_luxury->rtype->_name);
|
|
|
|
|
CuAssertStrEquals(tc, it_luxury->rtype->_name, LOC(lang, resourcename(it_luxury->rtype, 0)));
|
|
|
|
|
|
2018-01-19 16:59:52 +01:00
|
|
|
|
new_luxurytype(it_luxury = test_create_itemtype("jewel"), 5);
|
2017-11-05 15:11:02 +01:00
|
|
|
|
locale_setstring(lang, it_luxury->rtype->_name, it_luxury->rtype->_name);
|
|
|
|
|
CuAssertStrEquals(tc, it_luxury->rtype->_name, LOC(lang, resourcename(it_luxury->rtype, 0)));
|
|
|
|
|
|
|
|
|
|
r = test_create_region(0, 0, terrain);
|
2018-01-19 16:59:52 +01:00
|
|
|
|
setluxuries(r, it_luxury->rtype->ltype);
|
2017-11-05 15:11:02 +01:00
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unit *setup_trade_unit(CuTest *tc, region *r, const struct race *rc) {
|
|
|
|
|
unit *u;
|
|
|
|
|
|
|
|
|
|
UNUSED_ARG(tc);
|
|
|
|
|
u = test_create_unit(test_create_faction(rc), r);
|
|
|
|
|
set_level(u, SK_TRADE, 2);
|
|
|
|
|
return u;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void test_trade_insect(CuTest *tc) {
|
2017-11-20 08:24:56 +01:00
|
|
|
|
/* Insekten k<>nnen in W<>sten und S<>mpfen auch ohne Burgen handeln. */
|
2017-11-05 15:11:02 +01:00
|
|
|
|
unit *u;
|
|
|
|
|
region *r;
|
|
|
|
|
const item_type *it_luxury;
|
|
|
|
|
const item_type *it_silver;
|
|
|
|
|
|
|
|
|
|
test_setup();
|
2018-01-14 11:25:44 +01:00
|
|
|
|
setup_production();
|
2017-11-05 15:14:54 +01:00
|
|
|
|
test_create_locale();
|
2017-11-05 17:00:40 +01:00
|
|
|
|
setup_terrains(tc);
|
2017-11-05 19:15:43 +01:00
|
|
|
|
r = setup_trade_region(tc, get_terrain("swamp"));
|
2017-11-05 16:43:01 +01:00
|
|
|
|
init_terrains();
|
2017-11-05 15:11:02 +01:00
|
|
|
|
|
|
|
|
|
it_luxury = r_luxury(r);
|
|
|
|
|
CuAssertPtrNotNull(tc, it_luxury);
|
2017-11-05 15:14:54 +01:00
|
|
|
|
it_silver = get_resourcetype(R_SILVER)->itype;
|
2017-11-05 15:11:02 +01:00
|
|
|
|
|
|
|
|
|
u = setup_trade_unit(tc, r, test_create_race("insect"));
|
|
|
|
|
unit_addorder(u, create_order(K_BUY, u->faction->locale, "1 %s",
|
|
|
|
|
LOC(u->faction->locale, resourcename(it_luxury->rtype, 0))));
|
|
|
|
|
|
2018-05-18 15:34:21 +02:00
|
|
|
|
test_set_item(u, it_silver, 10);
|
2017-11-20 08:24:56 +01:00
|
|
|
|
CuAssertPtrEquals(tc, r, u->region);
|
|
|
|
|
CuAssertPtrEquals(tc, (void *)it_luxury, (void *)r_luxury(u->region));
|
2017-11-05 15:11:02 +01:00
|
|
|
|
produce(u->region);
|
2018-03-04 20:03:13 +01:00
|
|
|
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(u->faction->msgs, "error119"));
|
2017-11-05 15:11:02 +01:00
|
|
|
|
CuAssertIntEquals(tc, 1, get_item(u, it_luxury));
|
|
|
|
|
CuAssertIntEquals(tc, 5, get_item(u, it_silver));
|
2017-11-05 19:15:43 +01:00
|
|
|
|
|
|
|
|
|
terraform_region(r, get_terrain("swamp"));
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2017-11-05 15:11:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-04 20:10:05 +01:00
|
|
|
|
static void test_buy_cmd(CuTest *tc) {
|
|
|
|
|
region * r;
|
|
|
|
|
unit *u;
|
|
|
|
|
building *b;
|
|
|
|
|
const resource_type *rt_silver;
|
2017-11-05 15:14:54 +01:00
|
|
|
|
const item_type *it_luxury;
|
2017-11-04 20:10:05 +01:00
|
|
|
|
test_setup();
|
2018-01-14 11:25:44 +01:00
|
|
|
|
setup_production();
|
2017-11-05 15:14:54 +01:00
|
|
|
|
test_create_locale();
|
2017-11-05 17:00:40 +01:00
|
|
|
|
setup_terrains(tc);
|
2017-11-05 16:43:01 +01:00
|
|
|
|
r = setup_trade_region(tc, test_create_terrain("swamp", LAND_REGION));
|
|
|
|
|
init_terrains();
|
2017-11-05 15:14:54 +01:00
|
|
|
|
|
|
|
|
|
it_luxury = r_luxury(r);
|
|
|
|
|
CuAssertPtrNotNull(tc, it_luxury);
|
2017-11-04 20:10:05 +01:00
|
|
|
|
rt_silver = get_resourcetype(R_SILVER);
|
|
|
|
|
CuAssertPtrNotNull(tc, rt_silver);
|
|
|
|
|
CuAssertPtrNotNull(tc, rt_silver->itype);
|
|
|
|
|
|
|
|
|
|
u = test_create_unit(test_create_faction(NULL), r);
|
2017-11-05 15:14:54 +01:00
|
|
|
|
unit_addorder(u, create_order(K_BUY, u->faction->locale, "1 %s", LOC(u->faction->locale, resourcename(it_luxury->rtype, 0))));
|
2018-05-18 15:34:21 +02:00
|
|
|
|
test_set_item(u, rt_silver->itype, 1000);
|
2017-11-04 20:10:05 +01:00
|
|
|
|
|
|
|
|
|
produce(r);
|
|
|
|
|
CuAssertPtrNotNullMsg(tc, "trading requires a castle", test_find_messagetype(u->faction->msgs, "error119"));
|
|
|
|
|
test_clear_messages(u->faction);
|
|
|
|
|
freset(u, UFL_LONGACTION);
|
|
|
|
|
|
|
|
|
|
b = test_create_building(r, test_create_buildingtype("castle"));
|
|
|
|
|
produce(r);
|
|
|
|
|
CuAssertPtrNotNullMsg(tc, "castle must have size >=2", test_find_messagetype(u->faction->msgs, "error119"));
|
|
|
|
|
test_clear_messages(u->faction);
|
|
|
|
|
freset(u, UFL_LONGACTION);
|
|
|
|
|
|
|
|
|
|
b->size = 2;
|
|
|
|
|
produce(r);
|
|
|
|
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(u->faction->msgs, "error119"));
|
|
|
|
|
CuAssertPtrNotNullMsg(tc, "traders need SK_TRADE skill", test_find_messagetype(u->faction->msgs, "error102"));
|
|
|
|
|
test_clear_messages(u->faction);
|
|
|
|
|
freset(u, UFL_LONGACTION);
|
|
|
|
|
|
|
|
|
|
/* at last, the happy case: */
|
|
|
|
|
set_level(u, SK_TRADE, 1);
|
|
|
|
|
produce(r);
|
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "buy"));
|
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "buyamount"));
|
2017-11-05 15:14:54 +01:00
|
|
|
|
CuAssertIntEquals(tc, 1, get_item(u, it_luxury));
|
2017-11-04 20:10:05 +01:00
|
|
|
|
CuAssertIntEquals(tc, 995, get_item(u, rt_silver->itype));
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2017-11-04 20:10:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-03 15:25:03 +01:00
|
|
|
|
static void arm_unit(unit *u) {
|
|
|
|
|
item_type *it_sword;
|
|
|
|
|
|
|
|
|
|
it_sword = test_create_itemtype("sword");
|
|
|
|
|
new_weapontype(it_sword, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE);
|
|
|
|
|
i_change(&u->items, it_sword, u->number);
|
|
|
|
|
set_level(u, SK_MELEE, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-14 15:32:31 +01:00
|
|
|
|
static void test_tax_cmd(CuTest *tc) {
|
|
|
|
|
order *ord;
|
|
|
|
|
faction *f;
|
|
|
|
|
region *r;
|
|
|
|
|
unit *u;
|
2018-02-03 15:25:03 +01:00
|
|
|
|
item_type *silver;
|
2017-12-04 20:01:08 +01:00
|
|
|
|
econ_request *taxorders = 0;
|
2015-11-14 15:32:31 +01:00
|
|
|
|
|
2017-03-11 14:22:21 +01:00
|
|
|
|
test_setup();
|
2018-01-14 11:25:44 +01:00
|
|
|
|
setup_production();
|
2015-11-26 18:48:21 +01:00
|
|
|
|
config_set("taxing.perlevel", "20");
|
2015-11-14 15:32:31 +01:00
|
|
|
|
f = test_create_faction(NULL);
|
2017-03-11 14:22:21 +01:00
|
|
|
|
r = test_create_region(0, 0, NULL);
|
2015-11-14 15:32:31 +01:00
|
|
|
|
assert(r && f);
|
|
|
|
|
u = test_create_unit(f, r);
|
|
|
|
|
|
|
|
|
|
ord = create_order(K_TAX, f->locale, "");
|
|
|
|
|
assert(ord);
|
|
|
|
|
|
|
|
|
|
tax_cmd(u, ord, &taxorders);
|
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error48"));
|
|
|
|
|
test_clear_messages(u->faction);
|
|
|
|
|
|
|
|
|
|
silver = get_resourcetype(R_SILVER)->itype;
|
|
|
|
|
|
2018-02-03 15:25:03 +01:00
|
|
|
|
arm_unit(u);
|
2015-11-14 15:32:31 +01:00
|
|
|
|
|
|
|
|
|
tax_cmd(u, ord, &taxorders);
|
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error_no_tax_skill"));
|
|
|
|
|
test_clear_messages(u->faction);
|
|
|
|
|
|
|
|
|
|
set_level(u, SK_TAXING, 1);
|
|
|
|
|
tax_cmd(u, ord, &taxorders);
|
2018-10-14 11:48:21 +02:00
|
|
|
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(u->faction->msgs, "error_no_tax_skill"));
|
2015-11-14 15:32:31 +01:00
|
|
|
|
CuAssertPtrNotNull(tc, taxorders);
|
|
|
|
|
|
2015-12-07 17:59:50 +01:00
|
|
|
|
rsetmoney(r, 11);
|
2015-11-14 15:32:31 +01:00
|
|
|
|
expandtax(r, taxorders);
|
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "income"));
|
2015-11-14 17:14:38 +01:00
|
|
|
|
/* taxing is in multiples of 10 */
|
|
|
|
|
CuAssertIntEquals(tc, 10, i_get(u->items, silver));
|
2015-11-14 15:32:31 +01:00
|
|
|
|
test_clear_messages(u->faction);
|
|
|
|
|
i_change(&u->items, silver, -i_get(u->items, silver));
|
|
|
|
|
|
2015-12-07 17:59:50 +01:00
|
|
|
|
rsetmoney(r, 1000);
|
2015-11-14 15:32:31 +01:00
|
|
|
|
taxorders = 0;
|
|
|
|
|
tax_cmd(u, ord, &taxorders);
|
|
|
|
|
expandtax(r, taxorders);
|
|
|
|
|
CuAssertIntEquals(tc, 20, i_get(u->items, silver));
|
|
|
|
|
test_clear_messages(u->faction);
|
|
|
|
|
|
|
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2015-11-14 15:32:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-14 11:58:22 +01:00
|
|
|
|
static void setup_economy(void) {
|
2018-05-18 19:58:49 +02:00
|
|
|
|
mt_create_va(mt_new("recruit", NULL), "unit:unit", "region:region", "amount:int", "want:int", MT_NEW_END);
|
|
|
|
|
mt_create_va(mt_new("maintenance", NULL), "unit:unit", "building:building", MT_NEW_END);
|
|
|
|
|
mt_create_va(mt_new("maintenancefail", NULL), "unit:unit", "building:building", MT_NEW_END);
|
|
|
|
|
mt_create_va(mt_new("maintenance_nowork", NULL), "building:building", MT_NEW_END);
|
|
|
|
|
mt_create_va(mt_new("maintenance_noowner", NULL), "building:building", MT_NEW_END);
|
2018-01-14 11:25:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-01 18:34:38 +02:00
|
|
|
|
/**
|
|
|
|
|
* see https://bugs.eressea.de/view.php?id=2234
|
|
|
|
|
*/
|
2016-08-21 20:01:30 +02:00
|
|
|
|
static void test_maintain_buildings(CuTest *tc) {
|
|
|
|
|
region *r;
|
|
|
|
|
building *b;
|
|
|
|
|
building_type *btype;
|
|
|
|
|
unit *u;
|
2016-09-27 08:25:58 +02:00
|
|
|
|
faction *f;
|
2016-08-21 20:01:30 +02:00
|
|
|
|
maintenance *req;
|
|
|
|
|
item_type *itype;
|
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_setup();
|
2018-01-14 11:58:22 +01:00
|
|
|
|
setup_economy();
|
2016-08-21 20:01:30 +02:00
|
|
|
|
btype = test_create_buildingtype("Hort");
|
|
|
|
|
btype->maxsize = 10;
|
2018-01-14 09:38:26 +01:00
|
|
|
|
r = test_create_region(0, 0, NULL);
|
|
|
|
|
f = test_create_faction(NULL);
|
2016-09-27 08:25:58 +02:00
|
|
|
|
u = test_create_unit(f, r);
|
2016-08-21 20:01:30 +02:00
|
|
|
|
b = test_create_building(r, btype);
|
|
|
|
|
itype = test_create_itemtype("money");
|
|
|
|
|
b->size = btype->maxsize;
|
|
|
|
|
u_set_building(u, b);
|
|
|
|
|
|
2017-02-18 21:15:14 +01:00
|
|
|
|
/* this building has no upkeep, it just works: */
|
2016-08-21 20:01:30 +02:00
|
|
|
|
b->flags = 0;
|
2016-08-21 20:04:51 +02:00
|
|
|
|
maintain_buildings(r);
|
2016-08-21 20:01:30 +02:00
|
|
|
|
CuAssertIntEquals(tc, BLD_MAINTAINED, fval(b, BLD_MAINTAINED));
|
2018-10-14 11:48:21 +02:00
|
|
|
|
CuAssertPtrEquals(tc, NULL, f->msgs);
|
|
|
|
|
CuAssertPtrEquals(tc, NULL, r->msgs);
|
2016-08-21 20:01:30 +02:00
|
|
|
|
|
|
|
|
|
req = calloc(2, sizeof(maintenance));
|
|
|
|
|
req[0].number = 100;
|
|
|
|
|
req[0].rtype = itype->rtype;
|
|
|
|
|
btype->maintenance = req;
|
|
|
|
|
|
2017-02-18 21:15:14 +01:00
|
|
|
|
/* we cannot afford to pay: */
|
2016-08-21 20:01:30 +02:00
|
|
|
|
b->flags = 0;
|
2016-08-21 20:04:51 +02:00
|
|
|
|
maintain_buildings(r);
|
2016-08-21 20:01:30 +02:00
|
|
|
|
CuAssertIntEquals(tc, 0, fval(b, BLD_MAINTAINED));
|
2016-10-01 18:34:38 +02:00
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "maintenancefail"));
|
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(r->msgs, "maintenance_nowork"));
|
|
|
|
|
test_clear_messagelist(&f->msgs);
|
|
|
|
|
test_clear_messagelist(&r->msgs);
|
2016-09-27 15:02:22 +02:00
|
|
|
|
|
2017-02-18 21:15:14 +01:00
|
|
|
|
/* we can afford to pay: */
|
2016-08-21 20:01:30 +02:00
|
|
|
|
i_change(&u->items, itype, 100);
|
|
|
|
|
b->flags = 0;
|
2016-08-21 20:04:51 +02:00
|
|
|
|
maintain_buildings(r);
|
2016-08-21 20:01:30 +02:00
|
|
|
|
CuAssertIntEquals(tc, BLD_MAINTAINED, fval(b, BLD_MAINTAINED));
|
|
|
|
|
CuAssertIntEquals(tc, 0, i_get(u->items, itype));
|
2018-10-14 11:48:21 +02:00
|
|
|
|
CuAssertPtrEquals(tc, NULL, r->msgs);
|
|
|
|
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "maintenance_nowork"));
|
2016-09-27 15:40:03 +02:00
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "maintenance"));
|
2016-10-01 18:34:38 +02:00
|
|
|
|
test_clear_messagelist(&f->msgs);
|
2016-08-21 20:01:30 +02:00
|
|
|
|
|
2017-02-18 21:15:14 +01:00
|
|
|
|
/* this building has no owner, it doesn't work: */
|
2016-08-21 20:01:30 +02:00
|
|
|
|
u_set_building(u, NULL);
|
|
|
|
|
b->flags = 0;
|
2016-08-21 20:04:51 +02:00
|
|
|
|
maintain_buildings(r);
|
2016-08-21 20:01:30 +02:00
|
|
|
|
CuAssertIntEquals(tc, 0, fval(b, BLD_MAINTAINED));
|
2018-10-14 11:48:21 +02:00
|
|
|
|
CuAssertPtrEquals(tc, NULL, f->msgs);
|
2016-09-27 08:25:58 +02:00
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(r->msgs, "maintenance_noowner"));
|
2016-10-01 18:34:38 +02:00
|
|
|
|
test_clear_messagelist(&r->msgs);
|
2016-08-21 20:01:30 +02:00
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2016-08-21 20:01:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-18 11:34:54 +02:00
|
|
|
|
static void test_recruit(CuTest *tc) {
|
|
|
|
|
unit *u;
|
|
|
|
|
faction *f;
|
|
|
|
|
|
|
|
|
|
test_setup();
|
2018-01-14 11:58:22 +01:00
|
|
|
|
setup_economy();
|
2018-01-14 09:38:26 +01:00
|
|
|
|
f = test_create_faction(NULL);
|
|
|
|
|
u = test_create_unit(f, test_create_region(0, 0, NULL));
|
2016-09-18 11:34:54 +02:00
|
|
|
|
CuAssertIntEquals(tc, 1, u->number);
|
2017-03-12 12:53:10 +01:00
|
|
|
|
CuAssertIntEquals(tc, 1, f->num_people);
|
|
|
|
|
CuAssertIntEquals(tc, 1, f->num_units);
|
2016-09-18 11:34:54 +02:00
|
|
|
|
add_recruits(u, 1, 1);
|
|
|
|
|
CuAssertIntEquals(tc, 2, u->number);
|
2017-03-12 12:53:10 +01:00
|
|
|
|
CuAssertIntEquals(tc, 2, f->num_people);
|
|
|
|
|
CuAssertIntEquals(tc, 1, f->num_units);
|
2016-09-18 11:34:54 +02:00
|
|
|
|
CuAssertPtrEquals(tc, u, f->units);
|
|
|
|
|
CuAssertPtrEquals(tc, NULL, u->nextF);
|
|
|
|
|
CuAssertPtrEquals(tc, NULL, u->prevF);
|
2016-09-18 13:49:34 +02:00
|
|
|
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "recruit"));
|
|
|
|
|
add_recruits(u, 1, 2);
|
|
|
|
|
CuAssertIntEquals(tc, 3, u->number);
|
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "recruit"));
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2016-09-18 11:34:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-02 14:31:00 +02:00
|
|
|
|
static void test_recruit_insect(CuTest *tc) {
|
|
|
|
|
unit *u;
|
|
|
|
|
faction *f;
|
|
|
|
|
message * msg;
|
|
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
|
test_create_calendar();
|
2018-09-13 16:16:32 +02:00
|
|
|
|
test_create_terrain("desert", -1);
|
2018-08-02 14:31:00 +02:00
|
|
|
|
f = test_create_faction(test_create_race("insect"));
|
|
|
|
|
u = test_create_unit(f, test_create_region(0, 0, NULL));
|
|
|
|
|
u->thisorder = create_order(K_RECRUIT, f->locale, "%d", 1);
|
|
|
|
|
|
|
|
|
|
msg = can_recruit(u, f->race, u->thisorder, 1083); /* Autumn */
|
|
|
|
|
CuAssertPtrEquals(tc, NULL, msg);
|
|
|
|
|
|
|
|
|
|
msg = can_recruit(u, f->race, u->thisorder, 1084); /* Insects, Winter */
|
|
|
|
|
CuAssertPtrNotNull(tc, msg);
|
|
|
|
|
msg_release(msg);
|
|
|
|
|
|
|
|
|
|
u->flags |= UFL_WARMTH;
|
|
|
|
|
msg = can_recruit(u, f->race, u->thisorder, 1084); /* Insects, potion, Winter */
|
|
|
|
|
CuAssertPtrEquals(tc, NULL, msg);
|
|
|
|
|
|
|
|
|
|
u->flags = 0;
|
|
|
|
|
msg = can_recruit(u, NULL, u->thisorder, 1084); /* Other races, Winter */
|
|
|
|
|
CuAssertPtrEquals(tc, NULL, msg);
|
|
|
|
|
|
|
|
|
|
test_teardown();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 09:14:49 +02:00
|
|
|
|
static void test_income(CuTest *tc)
|
|
|
|
|
{
|
|
|
|
|
race *rc;
|
|
|
|
|
unit *u;
|
|
|
|
|
test_setup();
|
|
|
|
|
rc = test_create_race("nerd");
|
2018-01-14 09:38:26 +01:00
|
|
|
|
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, NULL));
|
2016-10-04 09:14:49 +02:00
|
|
|
|
CuAssertIntEquals(tc, 20, income(u));
|
|
|
|
|
u->number = 5;
|
|
|
|
|
CuAssertIntEquals(tc, 100, income(u));
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2016-10-04 09:14:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-02 14:43:53 +02:00
|
|
|
|
static void test_modify_material(CuTest *tc) {
|
|
|
|
|
unit *u;
|
|
|
|
|
struct item_type *itype;
|
|
|
|
|
resource_type *rtype;
|
|
|
|
|
resource_mod *mod;
|
|
|
|
|
|
|
|
|
|
test_setup();
|
2018-01-14 11:25:44 +01:00
|
|
|
|
setup_production();
|
2017-04-02 14:43:53 +02:00
|
|
|
|
|
2018-01-14 09:38:26 +01:00
|
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2017-04-02 14:43:53 +02:00
|
|
|
|
set_level(u, SK_WEAPONSMITH, 1);
|
|
|
|
|
|
|
|
|
|
/* the unit's race gets 2x savings on iron used to produce goods */
|
|
|
|
|
itype = test_create_itemtype("iron");
|
|
|
|
|
rtype = itype->rtype;
|
|
|
|
|
mod = rtype->modifiers = calloc(2, sizeof(resource_mod));
|
|
|
|
|
mod[0].type = RMT_USE_SAVE;
|
|
|
|
|
mod[0].value = frac_make(2, 1);
|
2018-04-29 13:46:17 +02:00
|
|
|
|
mod[0].race_mask = rc_mask(u_race(u));
|
2017-04-02 14:43:53 +02:00
|
|
|
|
|
|
|
|
|
itype = test_create_itemtype("sword");
|
|
|
|
|
make_item(u, itype, 1);
|
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error_cannotmake"));
|
|
|
|
|
CuAssertIntEquals(tc, 0, get_item(u, itype));
|
|
|
|
|
test_clear_messages(u->faction);
|
|
|
|
|
itype->construction = calloc(1, sizeof(construction));
|
|
|
|
|
itype->construction->skill = SK_WEAPONSMITH;
|
|
|
|
|
itype->construction->minskill = 1;
|
|
|
|
|
itype->construction->maxsize = 1;
|
|
|
|
|
itype->construction->reqsize = 1;
|
|
|
|
|
itype->construction->materials = calloc(2, sizeof(requirement));
|
|
|
|
|
itype->construction->materials[0].rtype = rtype;
|
|
|
|
|
itype->construction->materials[0].number = 2;
|
|
|
|
|
|
2018-05-18 15:34:21 +02:00
|
|
|
|
test_set_item(u, rtype->itype, 1); /* 1 iron should get us 1 sword */
|
2017-04-02 14:43:53 +02:00
|
|
|
|
make_item(u, itype, 1);
|
|
|
|
|
CuAssertIntEquals(tc, 1, get_item(u, itype));
|
|
|
|
|
CuAssertIntEquals(tc, 0, get_item(u, rtype->itype));
|
|
|
|
|
|
|
|
|
|
u_setrace(u, test_create_race("smurf"));
|
2018-05-18 15:34:21 +02:00
|
|
|
|
test_set_item(u, rtype->itype, 2); /* 2 iron should be required now */
|
2017-04-02 14:43:53 +02:00
|
|
|
|
make_item(u, itype, 1);
|
|
|
|
|
CuAssertIntEquals(tc, 2, get_item(u, itype));
|
|
|
|
|
CuAssertIntEquals(tc, 0, get_item(u, rtype->itype));
|
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2017-04-02 14:43:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void test_modify_skill(CuTest *tc) {
|
|
|
|
|
unit *u;
|
|
|
|
|
struct item_type *itype;
|
|
|
|
|
/* building_type *btype; */
|
|
|
|
|
resource_type *rtype;
|
|
|
|
|
resource_mod *mod;
|
|
|
|
|
|
|
|
|
|
test_setup();
|
2018-01-14 11:25:44 +01:00
|
|
|
|
setup_production();
|
2017-04-02 14:43:53 +02:00
|
|
|
|
|
2018-01-14 09:38:26 +01:00
|
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2017-04-02 14:43:53 +02:00
|
|
|
|
set_level(u, SK_WEAPONSMITH, 1);
|
|
|
|
|
|
|
|
|
|
itype = test_create_itemtype("iron");
|
|
|
|
|
rtype = itype->rtype;
|
|
|
|
|
|
|
|
|
|
itype = test_create_itemtype("sword");
|
|
|
|
|
make_item(u, itype, 1);
|
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error_cannotmake"));
|
|
|
|
|
CuAssertIntEquals(tc, 0, get_item(u, itype));
|
|
|
|
|
test_clear_messages(u->faction);
|
|
|
|
|
itype->construction = calloc(1, sizeof(construction));
|
|
|
|
|
itype->construction->skill = SK_WEAPONSMITH;
|
|
|
|
|
itype->construction->minskill = 1;
|
|
|
|
|
itype->construction->maxsize = -1;
|
|
|
|
|
itype->construction->reqsize = 1;
|
|
|
|
|
itype->construction->materials = calloc(2, sizeof(requirement));
|
|
|
|
|
itype->construction->materials[0].rtype = rtype;
|
|
|
|
|
itype->construction->materials[0].number = 1;
|
|
|
|
|
|
|
|
|
|
/* our race gets a +1 bonus to the item's production skill */
|
|
|
|
|
mod = itype->rtype->modifiers = calloc(2, sizeof(resource_mod));
|
|
|
|
|
mod[0].type = RMT_PROD_SKILL;
|
|
|
|
|
mod[0].value.sa[0] = SK_WEAPONSMITH;
|
|
|
|
|
mod[0].value.sa[1] = 1;
|
2018-04-29 13:46:17 +02:00
|
|
|
|
mod[0].race_mask = rc_mask(u_race(u));
|
2017-04-02 14:43:53 +02:00
|
|
|
|
|
2018-05-18 15:34:21 +02:00
|
|
|
|
test_set_item(u, rtype->itype, 2); /* 2 iron should get us 2 swords */
|
2017-04-02 14:43:53 +02:00
|
|
|
|
make_item(u, itype, 2);
|
|
|
|
|
CuAssertIntEquals(tc, 2, get_item(u, itype));
|
|
|
|
|
CuAssertIntEquals(tc, 0, get_item(u, rtype->itype));
|
|
|
|
|
|
|
|
|
|
mod[0].value.sa[0] = NOSKILL; /* match any skill */
|
2018-05-18 15:34:21 +02:00
|
|
|
|
test_set_item(u, rtype->itype, 2);
|
2017-04-02 14:43:53 +02:00
|
|
|
|
make_item(u, itype, 2);
|
|
|
|
|
CuAssertIntEquals(tc, 4, get_item(u, itype));
|
|
|
|
|
CuAssertIntEquals(tc, 0, get_item(u, rtype->itype));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
u_setrace(u, test_create_race("smurf"));
|
2018-05-18 15:34:21 +02:00
|
|
|
|
test_set_item(u, rtype->itype, 2);
|
2017-04-02 14:43:53 +02:00
|
|
|
|
make_item(u, itype, 1); /* only enough skill to make 1 now */
|
|
|
|
|
CuAssertIntEquals(tc, 5, get_item(u, itype));
|
|
|
|
|
CuAssertIntEquals(tc, 1, get_item(u, rtype->itype));
|
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2017-04-02 14:43:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void test_modify_production(CuTest *tc) {
|
2017-02-15 17:09:23 +01:00
|
|
|
|
unit *u;
|
|
|
|
|
struct item_type *itype;
|
|
|
|
|
const struct resource_type *rt_silver;
|
2017-02-15 20:50:45 +01:00
|
|
|
|
resource_type *rtype;
|
2017-02-17 21:45:10 +01:00
|
|
|
|
double d = 0.6;
|
2017-02-15 17:09:23 +01:00
|
|
|
|
|
|
|
|
|
test_setup();
|
2018-01-14 11:25:44 +01:00
|
|
|
|
setup_production();
|
2017-02-15 20:50:45 +01:00
|
|
|
|
|
|
|
|
|
/* make items from other items (turn silver to stone) */
|
2017-02-15 17:09:23 +01:00
|
|
|
|
rt_silver = get_resourcetype(R_SILVER);
|
2017-02-15 20:50:45 +01:00
|
|
|
|
itype = test_create_itemtype("stone");
|
|
|
|
|
rtype = itype->rtype;
|
2018-01-14 09:58:45 +01:00
|
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2017-02-15 17:09:23 +01:00
|
|
|
|
make_item(u, itype, 1);
|
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error_cannotmake"));
|
|
|
|
|
CuAssertIntEquals(tc, 0, get_item(u, itype));
|
|
|
|
|
test_clear_messages(u->faction);
|
|
|
|
|
itype->construction = calloc(1, sizeof(construction));
|
|
|
|
|
itype->construction->skill = SK_ALCHEMY;
|
|
|
|
|
itype->construction->minskill = 1;
|
|
|
|
|
itype->construction->maxsize = 1;
|
|
|
|
|
itype->construction->reqsize = 1;
|
|
|
|
|
itype->construction->materials = calloc(2, sizeof(requirement));
|
|
|
|
|
itype->construction->materials[0].rtype = rt_silver;
|
|
|
|
|
itype->construction->materials[0].number = 1;
|
|
|
|
|
set_level(u, SK_ALCHEMY, 1);
|
2018-05-18 15:34:21 +02:00
|
|
|
|
test_set_item(u, rt_silver->itype, 1);
|
2017-02-15 17:09:23 +01:00
|
|
|
|
make_item(u, itype, 1);
|
|
|
|
|
CuAssertIntEquals(tc, 1, get_item(u, itype));
|
|
|
|
|
CuAssertIntEquals(tc, 0, get_item(u, rt_silver->itype));
|
2017-02-15 20:50:45 +01:00
|
|
|
|
|
|
|
|
|
/* make level-based raw materials, no materials used in construction */
|
|
|
|
|
free(itype->construction->materials);
|
|
|
|
|
itype->construction->materials = 0;
|
|
|
|
|
rtype->flags |= RTF_LIMITED;
|
2017-02-25 21:24:47 +01:00
|
|
|
|
rmt_create(rtype);
|
2017-03-22 20:37:09 +01:00
|
|
|
|
add_resource(u->region, 1, 300, 150, rtype); /* there are 300 stones at level 1 */
|
|
|
|
|
CuAssertIntEquals(tc, 300, region_getresource(u->region, rtype));
|
2017-02-15 20:50:45 +01:00
|
|
|
|
set_level(u, SK_ALCHEMY, 10);
|
|
|
|
|
|
|
|
|
|
make_item(u, itype, 10);
|
|
|
|
|
split_allocations(u->region);
|
|
|
|
|
CuAssertIntEquals(tc, 11, get_item(u, itype));
|
2017-03-22 20:37:09 +01:00
|
|
|
|
CuAssertIntEquals(tc, 290, region_getresource(u->region, rtype)); /* used 10 stones to make 10 stones */
|
2017-02-15 20:50:45 +01:00
|
|
|
|
|
2017-08-09 19:39:29 +02:00
|
|
|
|
rtype->modifiers = calloc(3, sizeof(resource_mod));
|
2017-04-02 14:43:53 +02:00
|
|
|
|
rtype->modifiers[0].type = RMT_PROD_SAVE;
|
2018-04-29 13:46:17 +02:00
|
|
|
|
rtype->modifiers[0].race_mask = rc_mask(u->_race);
|
2017-02-26 13:55:19 +01:00
|
|
|
|
rtype->modifiers[0].value.sa[0] = (short)(0.5+100*d);
|
|
|
|
|
rtype->modifiers[0].value.sa[1] = 100;
|
2017-08-09 19:39:29 +02:00
|
|
|
|
rtype->modifiers[1].type = RMT_END;
|
2017-02-15 20:50:45 +01:00
|
|
|
|
make_item(u, itype, 10);
|
|
|
|
|
split_allocations(u->region);
|
|
|
|
|
CuAssertIntEquals(tc, 21, get_item(u, itype));
|
2017-03-22 20:37:09 +01:00
|
|
|
|
CuAssertIntEquals(tc, 284, region_getresource(u->region, rtype)); /* 60% saving = 6 stones make 10 stones */
|
2017-02-16 20:26:34 +01:00
|
|
|
|
|
2017-02-18 11:19:42 +01:00
|
|
|
|
make_item(u, itype, 1);
|
|
|
|
|
split_allocations(u->region);
|
|
|
|
|
CuAssertIntEquals(tc, 22, get_item(u, itype));
|
2017-03-22 20:37:09 +01:00
|
|
|
|
CuAssertIntEquals(tc, 283, region_getresource(u->region, rtype)); /* no free lunches */
|
2017-02-18 11:19:42 +01:00
|
|
|
|
|
2017-03-11 14:41:25 +01:00
|
|
|
|
rtype->modifiers[0].value = frac_make(1, 2);
|
2017-03-02 19:21:11 +01:00
|
|
|
|
make_item(u, itype, 6);
|
|
|
|
|
split_allocations(u->region);
|
|
|
|
|
CuAssertIntEquals(tc, 28, get_item(u, itype));
|
2017-03-22 20:37:09 +01:00
|
|
|
|
CuAssertIntEquals(tc, 280, region_getresource(u->region, rtype)); /* 50% saving = 3 stones make 6 stones */
|
2017-03-02 19:21:11 +01:00
|
|
|
|
|
2017-04-02 14:43:53 +02:00
|
|
|
|
rtype->modifiers[0].type = RMT_PROD_REQUIRE;
|
2018-04-29 13:46:17 +02:00
|
|
|
|
rtype->modifiers[0].race_mask = 0;
|
2017-02-26 13:55:19 +01:00
|
|
|
|
rtype->modifiers[0].btype = bt_get_or_create("mine");
|
2017-03-11 14:41:25 +01:00
|
|
|
|
|
2017-04-02 14:43:53 +02:00
|
|
|
|
test_clear_messages(u->faction);
|
2017-02-16 20:26:34 +01:00
|
|
|
|
make_item(u, itype, 10);
|
2017-04-02 14:43:53 +02:00
|
|
|
|
CuAssertIntEquals(tc, 28, get_item(u, itype));
|
2017-05-06 15:53:21 +02:00
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "building_needed"));
|
2017-02-16 20:26:34 +01:00
|
|
|
|
|
2017-04-02 14:43:53 +02:00
|
|
|
|
rtype->modifiers[0].type = RMT_PROD_REQUIRE;
|
2018-04-29 13:46:17 +02:00
|
|
|
|
rtype->modifiers[0].race_mask = rc_mask(test_create_race("smurf"));
|
2017-04-02 14:43:53 +02:00
|
|
|
|
rtype->modifiers[0].btype = NULL;
|
|
|
|
|
|
|
|
|
|
test_clear_messages(u->faction);
|
|
|
|
|
make_item(u, itype, 10);
|
|
|
|
|
CuAssertIntEquals(tc, 28, get_item(u, itype));
|
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error117"));
|
|
|
|
|
|
|
|
|
|
rtype->modifiers[1].type = RMT_PROD_REQUIRE;
|
2018-04-29 13:46:17 +02:00
|
|
|
|
rtype->modifiers[1].race_mask = rc_mask(u_race(u));
|
2017-04-02 14:43:53 +02:00
|
|
|
|
rtype->modifiers[1].btype = NULL;
|
2017-08-09 19:39:29 +02:00
|
|
|
|
rtype->modifiers[2].type = RMT_END;
|
2017-04-02 14:43:53 +02:00
|
|
|
|
|
|
|
|
|
test_clear_messages(u->faction);
|
|
|
|
|
make_item(u, itype, 10);
|
|
|
|
|
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
|
|
|
|
split_allocations(u->region);
|
|
|
|
|
CuAssertIntEquals(tc, 38, get_item(u, itype));
|
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2017-02-15 17:09:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-03 15:25:03 +01:00
|
|
|
|
static void test_loot(CuTest *tc) {
|
|
|
|
|
unit *u;
|
|
|
|
|
faction *f;
|
|
|
|
|
item_type *it_silver;
|
|
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
|
setup_production();
|
2018-10-28 21:28:05 +01:00
|
|
|
|
mt_create_error(48); /* unit is unarmed */
|
2018-02-03 15:25:03 +01:00
|
|
|
|
it_silver = test_create_silver();
|
|
|
|
|
config_set("rules.enable_loot", "1");
|
|
|
|
|
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
|
|
|
|
|
u->thisorder = create_order(K_LOOT, f->locale, NULL);
|
|
|
|
|
produce(u->region);
|
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error48")); /* unit is unarmed */
|
|
|
|
|
test_clear_messages(f);
|
|
|
|
|
arm_unit(u);
|
|
|
|
|
produce(u->region);
|
2018-10-28 21:28:05 +01:00
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "income"));
|
2018-02-03 15:25:03 +01:00
|
|
|
|
CuAssertIntEquals(tc, 2 * TAXFRACTION, i_get(u->items, it_silver));
|
|
|
|
|
CuAssertIntEquals(tc, UFL_LONGACTION | UFL_NOTMOVING, fval(u, UFL_LONGACTION | UFL_NOTMOVING));
|
|
|
|
|
test_teardown();
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-03 20:24:16 +01:00
|
|
|
|
static void test_expand_production(CuTest *tc) {
|
|
|
|
|
econ_request *orders;
|
2018-02-03 20:45:19 +01:00
|
|
|
|
econ_request **results = NULL;
|
2018-02-03 20:24:16 +01:00
|
|
|
|
region *r;
|
|
|
|
|
unit *u;
|
|
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
|
orders = calloc(1, sizeof(econ_request));
|
|
|
|
|
orders->qty = 2;
|
|
|
|
|
orders->unit = u = test_create_unit(test_create_faction(NULL), r = test_create_region(0, 0, NULL));
|
|
|
|
|
orders->next = NULL;
|
|
|
|
|
|
|
|
|
|
u->n = 1; /* will be overwritten */
|
|
|
|
|
CuAssertIntEquals(tc, 2, expand_production(r, orders, &results));
|
|
|
|
|
CuAssertPtrNotNull(tc, results);
|
2018-02-03 20:45:19 +01:00
|
|
|
|
CuAssertPtrEquals(tc, u, results[0]->unit);
|
|
|
|
|
CuAssertPtrEquals(tc, u, results[1]->unit);
|
2018-02-03 20:24:16 +01:00
|
|
|
|
CuAssertIntEquals(tc, 0, u->n);
|
2018-05-19 20:53:51 +02:00
|
|
|
|
free(results);
|
2018-02-03 20:24:16 +01:00
|
|
|
|
test_teardown();
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-27 17:38:17 +02:00
|
|
|
|
CuSuite *get_economy_suite(void)
|
|
|
|
|
{
|
2014-07-06 05:14:11 +02:00
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
|
SUITE_ADD_TEST(suite, test_give_control_building);
|
|
|
|
|
SUITE_ADD_TEST(suite, test_give_control_ship);
|
2016-10-04 09:14:49 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_income);
|
2017-04-02 14:43:53 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_modify_production);
|
|
|
|
|
SUITE_ADD_TEST(suite, test_modify_skill);
|
|
|
|
|
SUITE_ADD_TEST(suite, test_modify_material);
|
2014-07-06 05:14:11 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_steal_okay);
|
|
|
|
|
SUITE_ADD_TEST(suite, test_steal_ocean);
|
|
|
|
|
SUITE_ADD_TEST(suite, test_steal_nosteal);
|
2015-02-16 20:39:50 +01:00
|
|
|
|
SUITE_ADD_TEST(suite, test_normals_recruit);
|
|
|
|
|
SUITE_ADD_TEST(suite, test_heroes_dont_recruit);
|
2015-11-14 15:32:31 +01:00
|
|
|
|
SUITE_ADD_TEST(suite, test_tax_cmd);
|
2017-11-04 20:10:05 +01:00
|
|
|
|
SUITE_ADD_TEST(suite, test_buy_cmd);
|
2017-11-05 15:11:02 +01:00
|
|
|
|
SUITE_ADD_TEST(suite, test_trade_insect);
|
2016-08-21 20:01:30 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_maintain_buildings);
|
2016-09-18 11:34:54 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_recruit);
|
2018-08-02 14:31:00 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_recruit_insect);
|
2018-02-03 15:25:03 +01:00
|
|
|
|
SUITE_ADD_TEST(suite, test_loot);
|
2018-02-03 20:24:16 +01:00
|
|
|
|
SUITE_ADD_TEST(suite, test_expand_production);
|
2014-07-06 05:14:11 +02:00
|
|
|
|
return suite;
|
2012-05-27 17:38:17 +02:00
|
|
|
|
}
|