WIP: test production guarding.

ents are not working, because they rely on being part of the monster faction? bad!
This commit is contained in:
Enno Rehling 2016-10-26 11:33:41 +02:00
parent 91ae9245ca
commit e0a6618199
3 changed files with 103 additions and 1 deletions

View File

@ -13,3 +13,4 @@ require 'tests.storage'
require 'tests.magicbag'
require 'tests.process'
require 'tests.xmas'
require 'tests.economy'

94
scripts/tests/economy.lua Normal file
View File

@ -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

View File

@ -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);
}