From b5624e6a8ac32f07851cce93bf5ef74fe6aae9fc Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 8 Jan 2019 19:51:42 +0100 Subject: [PATCH] Some tests for WORK and wages. --- scripts/tests/e2/production.lua | 85 ++++++++++++++++++++++++++++++++- src/bind_region.c | 19 ++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) diff --git a/scripts/tests/e2/production.lua b/scripts/tests/e2/production.lua index 852d8f629..80d3447d2 100644 --- a/scripts/tests/e2/production.lua +++ b/scripts/tests/e2/production.lua @@ -108,7 +108,7 @@ end function test_build_boat_high_skill() local r = region.create(0, 0, "plain") - local f = faction.create("human", "skillz@example.com") + local f = faction.create("human") local u = unit.create(f, r, 1) u:set_skill("shipcraft", 5) -- humans get +1 u:add_item("log", 10) @@ -118,3 +118,86 @@ function test_build_boat_high_skill() assert_equal(5, u.ship.size) assert_equal(5, u:get_item('log')) end + +function test_work() + eressea.settings.set("rules.peasants.growth.factor", "0") + local r = region.create(0, 0, "plain") + r:set_resource('peasant', 1) + r:set_resource('tree', 0) + local f = faction.create("human") + local u = unit.create(f, r, 1) + u:add_order('ARBEITE') + r:set_resource('money', 0) + + process_orders() + assert_equal(10, u:get_item('money')) + assert_equal(1, r:get_resource('money')) + b = building.create(r, 'castle') + + b.size = 2 + r:set_resource('money', 0) + u:add_item('money', -u:get_item('money')) + process_orders() + assert_equal(10, u:get_item('money')) + assert_equal(1, r:get_resource('money')) + + b.size = 10 + r:set_resource('money', 0) + u:add_item('money', -u:get_item('money')) + process_orders() + assert_equal(11, u:get_item('money')) + assert_equal(2, r:get_resource('money')) + + b.size = 50 + r:set_resource('money', 0) + u:add_item('money', -u:get_item('money')) + process_orders() + assert_equal(12, u:get_item('money')) + assert_equal(3, r:get_resource('money')) + + r:set_resource('money', 0) + u:add_item('money', -u:get_item('money')) + b.size = 250 + process_orders() + assert_equal(13, u:get_item('money')) + assert_equal(4, r:get_resource('money')) + + r:set_resource('money', 0) + u:add_item('money', -u:get_item('money')) + b.size = 1250 + process_orders() + assert_equal(14, u:get_item('money')) + assert_equal(5, r:get_resource('money')) + + r:set_resource('money', 0) + u:add_item('money', -u:get_item('money')) + b.size = 6250 + process_orders() + assert_equal(15, u:get_item('money')) + assert_equal(6, r:get_resource('money')) +end + +function test_blessed_harvest() + eressea.settings.set("rules.peasants.growth.factor", "0") + local r = region.create(0, 0, "plain") + r:set_resource('peasant', 1) + r:set_resource('tree', 0) + local f = faction.create("human") + local u = unit.create(f, r, 1) + u:add_order('ARBEITE') + r:set_resource('money', 0) + r:add_curse('blessedharvest', nil, 2, 1, 1) -- duration, force, effect + + process_orders() + assert_equal(10, u:get_item('money')) -- only peasants benefit + assert_equal(2, r:get_resource('money')) -- peasants work +1 + + b = building.create(r, 'castle') + b.size = 6250 + r:set_resource('money', 0) + u:add_item('money', -u:get_item('money')) + assert_equal(1, r:get_curse('blessedharvest')) + process_orders() + assert_equal(15, u:get_item('money')) -- only peasants get +1 + assert_equal(7, r:get_resource('money')) -- peasants get +1 +end diff --git a/src/bind_region.c b/src/bind_region.c index 4a466b46f..414752cf6 100644 --- a/src/bind_region.c +++ b/src/bind_region.c @@ -699,6 +699,24 @@ static int tolua_distance(lua_State * L) return 1; } +static int tolua_region_add_curse(lua_State *L) { + region *r = (region *)tolua_tousertype(L, 1, NULL); + const char *name = tolua_tostring(L, 2, NULL); + const curse_type *ctype = ct_find(name); + if (ctype) { + unit *u = (unit *)tolua_tousertype(L, 3, NULL); + int duration = (int)tolua_tonumber(L, 4, 1); + double vigour = tolua_tonumber(L, 5, 0.0); + int effect = (int)tolua_tonumber(L, 6, vigour/2); + curse * c = create_curse(u, &r->attribs, ctype, vigour, duration, effect, 0); + if (c) { + lua_pushinteger(L, c->no); + return 1; + } + } + return 0; +} + static int tolua_region_get_curse(lua_State *L) { region *self = (region *)tolua_tousertype(L, 1, NULL); const char *name = tolua_tostring(L, 2, NULL); @@ -741,6 +759,7 @@ void tolua_region_open(lua_State * L) tolua_function(L, TOLUA_CAST "count_msg_type", tolua_region_count_msg_type); + tolua_function(L, TOLUA_CAST "add_curse", &tolua_region_add_curse); tolua_function(L, TOLUA_CAST "get_curse", &tolua_region_get_curse); tolua_function(L, TOLUA_CAST "has_attrib", &tolua_region_has_attrib); /* flags */