2012-06-03 22:39:42 +02:00
|
|
|
#include <platform.h>
|
2011-03-16 04:00:54 +01:00
|
|
|
#include "market.h"
|
|
|
|
#include "tests.h"
|
|
|
|
|
|
|
|
#include <kernel/building.h>
|
|
|
|
#include <kernel/config.h>
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
#include <kernel/item.h>
|
|
|
|
#include <kernel/race.h>
|
|
|
|
#include <kernel/region.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/terrain.h>
|
2011-03-16 04:00:54 +01:00
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
|
|
|
#include <util/language.h>
|
|
|
|
|
2012-05-31 04:17:08 +02:00
|
|
|
#include <CuTest.h>
|
2012-05-18 18:19:46 +02:00
|
|
|
#include <tests.h>
|
|
|
|
|
2011-03-16 04:00:54 +01:00
|
|
|
#include <stdlib.h>
|
2014-12-30 23:34:24 +01:00
|
|
|
#include <string.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2012-05-19 20:26:46 +02:00
|
|
|
static void test_market_curse(CuTest * tc)
|
2011-03-07 08:02:35 +01:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
region *r;
|
|
|
|
building *b;
|
|
|
|
unit *u;
|
|
|
|
faction *f;
|
|
|
|
int x, y;
|
|
|
|
const terrain_type *terrain;
|
|
|
|
item_type *htype, *ltype;
|
|
|
|
luxury_type *lux;
|
|
|
|
building_type *btype;
|
|
|
|
|
|
|
|
free_gamedata();
|
|
|
|
test_cleanup();
|
|
|
|
test_create_world();
|
|
|
|
|
|
|
|
htype = test_create_itemtype("herb");
|
|
|
|
htype->flags |= ITF_HERB;
|
|
|
|
htype->rtype->flags |= (RTF_ITEM | RTF_POOLED);
|
|
|
|
|
|
|
|
ltype = test_create_itemtype("balm");
|
|
|
|
ltype->rtype->flags |= (RTF_ITEM | RTF_POOLED);
|
|
|
|
lux = new_luxurytype(ltype, 0);
|
|
|
|
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.region_owners", "1");
|
2015-01-30 20:37:14 +01:00
|
|
|
|
|
|
|
btype = (building_type *)calloc(1, sizeof(building_type));
|
2017-01-10 16:31:05 +01:00
|
|
|
btype->_name = strdup("market");
|
2015-01-30 20:37:14 +01:00
|
|
|
bt_register(btype);
|
|
|
|
|
|
|
|
terrain = get_terrain("plain");
|
|
|
|
|
|
|
|
for (x = 0; x != 3; ++x) {
|
|
|
|
for (y = 0; y != 3; ++y) {
|
|
|
|
r = findregion(x, y);
|
|
|
|
if (!r) {
|
|
|
|
r = test_create_region(x, y, terrain);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
terraform_region(r, terrain);
|
|
|
|
}
|
|
|
|
rsetpeasants(r, 5000);
|
|
|
|
r_setdemand(r, lux, 0);
|
|
|
|
rsetherbtype(r, htype);
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
r = findregion(1, 1);
|
|
|
|
b = test_create_building(r, btype);
|
2016-08-21 20:12:28 +02:00
|
|
|
b->flags |= BLD_MAINTAINED;
|
2015-01-30 20:37:14 +01:00
|
|
|
b->size = b->type->maxsize;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
f = test_create_faction(0);
|
|
|
|
u = test_create_unit(f, r);
|
|
|
|
u_set_building(u, b);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
do_markets();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
CuAssertIntEquals(tc, 70, i_get(u->items, htype));
|
|
|
|
CuAssertIntEquals(tc, 35, i_get(u->items, ltype));
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
CuSuite *get_market_suite(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_market_curse);
|
|
|
|
return suite;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|