From 6fb23af66a2b2e14ceb88132a9686f1644189098 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 14 Jan 2015 17:49:48 +0100 Subject: [PATCH] test that ships are encumbered by money. define money in XML, not just in code. --- res/core/common/items.xml | 4 ++++ scripts/tests/e3/rules.lua | 19 +++++++++++++++++++ src/kernel/item.c | 1 - src/kernel/item.test.c | 22 ++++++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/res/core/common/items.xml b/res/core/common/items.xml index d867a3126..c8910e695 100644 --- a/res/core/common/items.xml +++ b/res/core/common/items.xml @@ -1,6 +1,10 @@ + + + + diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua index 5350df169..57c19522d 100644 --- a/scripts/tests/e3/rules.lua +++ b/scripts/tests/e3/rules.lua @@ -729,6 +729,25 @@ function test_silver_weight_stops_movement() assert_equal(r2, u1.region) end +function test_silver_weight_stops_ship() + local r1 = region.create(1, 1, "ocean") + local r2 = region.create(2, 1, "ocean") + region.create(3, 1, "ocean") + local f1 = faction.create("noreply@eressea.de", "human", "de") + local u1 = unit.create(f1, r1, 1) + u1:set_skill("sailing", 3) + local s1 = ship.create(r1, "canoe") + u1.ship = s1 + u1:clear_orders() + u1:add_order("NACH OST") + u1:add_item("money", 2000) + process_orders() + assert_equal(r2, u1.region) + u1:add_item("money", 1) + process_orders() + assert_equal(r2, u1.region) +end + function test_building_owner_can_enter_ship() local r1 = region.create(1, 2, "plain") local f1 = faction.create("noreply@eressea.de", "human", "de") diff --git a/src/kernel/item.c b/src/kernel/item.c index 1592d1a93..b09ea1b67 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -960,7 +960,6 @@ void init_resources(void) rtype->uchange = res_changeitem; rtype->itype = it_get_or_create(rtype); rtype->itype->give = give_money; - rtype->itype->weight = 1; // R_PERMAURA rtype = rt_get_or_create(resourcenames[R_PERMAURA]); diff --git a/src/kernel/item.test.c b/src/kernel/item.test.c index dcb7ca878..981edf641 100644 --- a/src/kernel/item.test.c +++ b/src/kernel/item.test.c @@ -143,6 +143,27 @@ static void test_fix_demand(CuTest *tc) { test_cleanup(); } +static void test_core_resources(CuTest *tc) { + resource_type * rtype; + test_cleanup(); + init_resources(); + CuAssertPtrNotNull(tc, rtype = rt_find("money")); + CuAssertPtrNotNull(tc, rtype->itype); + CuAssertPtrNotNull(tc, rtype->uchange); + CuAssertPtrNotNull(tc, rtype->itype->give); + CuAssertPtrNotNull(tc, rtype = rt_find("peasant")); + CuAssertPtrEquals(tc, 0, rtype->itype); + CuAssertPtrNotNull(tc, rtype = rt_find("person")); + CuAssertPtrEquals(tc, 0, rtype->itype); + CuAssertPtrNotNull(tc, rtype = rt_find("permaura")); + CuAssertPtrEquals(tc, 0, rtype->itype); + CuAssertPtrNotNull(tc, rtype = rt_find("hp")); + CuAssertPtrEquals(tc, 0, rtype->itype); + CuAssertPtrNotNull(tc, rtype = rt_find("aura")); + CuAssertPtrEquals(tc, 0, rtype->itype); + test_cleanup(); +} + CuSuite *get_item_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -153,5 +174,6 @@ CuSuite *get_item_suite(void) SUITE_ADD_TEST(suite, test_finditemtype); SUITE_ADD_TEST(suite, test_findresourcetype); SUITE_ADD_TEST(suite, test_fix_demand); + SUITE_ADD_TEST(suite, test_core_resources); return suite; }