From e0a661819946b7bcb3fe0ddf25160eac09012274 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 26 Oct 2016 11:33:41 +0200 Subject: [PATCH] WIP: test production guarding. ents are not working, because they rely on being part of the monster faction? bad! --- scripts/tests/e2/init.lua | 1 + scripts/tests/economy.lua | 94 +++++++++++++++++++++++++++++++++++++++ src/bind_monsters.c | 9 +++- 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 scripts/tests/economy.lua diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 2fdad1898..9e9163256 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -13,3 +13,4 @@ require 'tests.storage' require 'tests.magicbag' require 'tests.process' require 'tests.xmas' +require 'tests.economy' diff --git a/scripts/tests/economy.lua b/scripts/tests/economy.lua new file mode 100644 index 000000000..f528f16d2 --- /dev/null +++ b/scripts/tests/economy.lua @@ -0,0 +1,94 @@ +require "lunit" + +module("tests.economy", package.seeall, lunit.testcase) + +function setup() + eressea.free_game() + eressea.settings.set("NewbieImmunity", "0") + eressea.settings.set("study.produceexp", "0") + eressea.settings.set("nmr.timeout", "0") + eressea.settings.set("rules.food.flags", "4") -- FOOD_IS_FREE + eressea.settings.set("rules.encounters", "0") +end + +function test_no_guards() + local r = region.create(0, 0, "plain") + r:set_resource("tree", 100) + local u = unit.create(faction.create("human"), r) + u:set_skill("forestry", 1) + u:add_order("MACHE HOLZ") + process_orders() + assert_equal(1, u:get_item("log")) + process_orders() + assert_equal(2, u:get_item("log")) +end + +function test_elf_guards_trees() + local r = region.create(0, 0, "plain") + r:set_resource("tree", 100) + local u = unit.create(faction.create("human"), r) + u:set_skill("forestry", 1) + local guard = unit.create(faction.create("elf"), r, 1, "elf") + guard:add_order("BEWACHEN") -- fails, because unarmed + u:add_order("MACHE HOLZ") + process_orders() + assert_equal(1, u:get_item("log")) + guard:add_item("sword", 1) + guard:set_skill("melee", 1) + guard:add_order("BEWACHEN") -- success + process_orders() + -- GUARD starts after MAKE: + assert_equal(2, u:get_item("log")) + process_orders() + -- GUARD was active this turn: + assert_equal(2, u:get_item("log")) +end + +function test_catapults_dont_guard() + local r = region.create(0, 0, "plain") + r:set_resource("tree", 100) + local u = unit.create(faction.create("human"), r) + u:set_skill("forestry", 1) + local guard = unit.create(faction.create("elf"), r, 1, "elf") + guard:add_order("BEWACHEN") + u:add_order("MACHE HOLZ") + process_orders() + assert_equal(1, u:get_item("log")) + guard:add_item("catapult", 1) + guard:set_skill("catapult", 1) + guard:add_order("BEWACHEN") + process_orders() + -- GUARD starts after MAKE: + assert_equal(2, u:get_item("log")) + process_orders() + -- GUARD was active this turn, but catapults do not count: + assert_equal(3, u:get_item("log")) +end + +function test_ent_guards_trees() + local r = region.create(0, 0, "plain") + r:set_resource("tree", 100) + local u = unit.create(faction.create("human"), r) + u:set_skill("forestry", 1) + local guard = unit.create(get_monsters(), r, 1, "ent") + guard:add_order("BEWACHEN") + u:add_order("MACHE HOLZ") + process_orders() + assert_equal(1, u:get_item("log")) + process_orders() + assert_equal(1, u:get_item("log")) +end + +function test_ironkeeper_guards_iron() + local r = region.create(0, 0, "plain") + r:set_resource("iron", 100) + local u = unit.create(faction.create("human"), r) + u:set_skill("mining", 1) + local guard = unit.create(faction.create("mountainguard"), r, 1, "mountainguard") + guard:add_order("BEWACHEN") + u:add_order("MACHE EISEN") + process_orders() + assert_equal(1, u:get_item("iron")) + process_orders() + assert_equal(1, u:get_item("iron")) +end diff --git a/src/bind_monsters.c b/src/bind_monsters.c index 271045491..3e3f24bee 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -47,6 +47,12 @@ static int tolua_spawn_dragons(lua_State * L) return 0; } +static int tolua_get_monsters(lua_State * L) +{ + tolua_pushusertype(L, get_monsters(), "faction"); + return 1; +} + static int tolua_spawn_undead(lua_State * L) { spawn_undead(); @@ -90,7 +96,8 @@ void bind_monsters(struct lua_State *L) tolua_function(L, TOLUA_CAST "plan_monsters", tolua_planmonsters); tolua_function(L, TOLUA_CAST "spawn_undead", tolua_spawn_undead); tolua_function(L, TOLUA_CAST "spawn_dragons", tolua_spawn_dragons); - tolua_function(L, TOLUA_CAST "fix_familiars", &fix_familiars); + tolua_function(L, TOLUA_CAST "fix_familiars", fix_familiars); + tolua_function(L, TOLUA_CAST "get_monsters", tolua_get_monsters); } tolua_endmodule(L); }