2010-08-08 09:40:42 +02:00
|
|
|
require "lunit"
|
|
|
|
|
2017-04-25 16:47:26 +02:00
|
|
|
module("tests.e3.buildings", package.seeall, lunit.testcase )
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
|
|
function setup()
|
2014-12-31 21:07:42 +01:00
|
|
|
eressea.game.reset()
|
2015-11-12 16:09:26 +01:00
|
|
|
eressea.settings.set("rules.food.flags", "4")
|
|
|
|
end
|
|
|
|
|
|
|
|
function teardown()
|
|
|
|
eressea.settings.set("rules.food.flags", "0")
|
2010-08-08 09:40:42 +02:00
|
|
|
end
|
|
|
|
|
2017-04-25 16:47:26 +02:00
|
|
|
function test_castle_names()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local b = building.create(r, "castle")
|
|
|
|
|
|
|
|
assert_equal("site", b:get_typename(1))
|
|
|
|
assert_equal("site", b:get_typename(9))
|
|
|
|
assert_equal("fortification", b:get_typename(10))
|
|
|
|
assert_equal("fortification", b:get_typename(49))
|
|
|
|
assert_equal("tower", b:get_typename(50))
|
|
|
|
assert_equal("tower", b:get_typename(249))
|
|
|
|
assert_equal("castle", b:get_typename(250))
|
|
|
|
assert_equal("castle", b:get_typename(1249))
|
|
|
|
assert_equal("fortress", b:get_typename(1250))
|
|
|
|
assert_equal("fortress", b:get_typename(6249))
|
|
|
|
assert_equal("citadel", b:get_typename(6250))
|
|
|
|
end
|
|
|
|
|
2017-02-14 20:30:24 +01:00
|
|
|
function test_build_watch()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "e3build@eressea.de", "de")
|
2017-02-14 20:30:24 +01:00
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
|
|
|
|
u.number = 20
|
|
|
|
u:add_item("log", 20)
|
|
|
|
u.id = 42
|
|
|
|
|
|
|
|
u:set_skill("building", 1)
|
|
|
|
u:add_order("MACHE Wache")
|
|
|
|
process_orders()
|
|
|
|
assert_not_nil(u.building)
|
|
|
|
assert_equal(5, u.building.size)
|
|
|
|
|
|
|
|
u:set_skill("building", 2)
|
|
|
|
u:add_order("MACHE Wache " .. itoa36(u.building.id))
|
|
|
|
process_orders()
|
|
|
|
assert_not_nil(u.building)
|
|
|
|
assert_equal(10, u.building.size)
|
|
|
|
end
|
|
|
|
|
2017-04-25 16:47:26 +02:00
|
|
|
function test_watch_names()
|
2017-02-14 19:57:31 +01:00
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local b = building.create(r, "watch")
|
|
|
|
|
|
|
|
assert_equal("scaffolding", b:get_typename(1))
|
|
|
|
assert_equal("scaffolding", b:get_typename(4))
|
|
|
|
assert_equal("guardhouse", b:get_typename(5))
|
|
|
|
assert_equal("guardhouse", b:get_typename(9))
|
|
|
|
assert_equal("guardtower", b:get_typename(10))
|
|
|
|
end
|
|
|
|
|
2010-08-08 09:40:42 +02:00
|
|
|
function test_small_castles()
|
2017-02-14 19:57:31 +01:00
|
|
|
local r = region.create(0, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f1 = faction.create("human", "noreply@eressea.de", "de")
|
2017-02-14 19:57:31 +01:00
|
|
|
local u1 = unit.create(f1, r, 1)
|
2017-03-17 22:31:59 +01:00
|
|
|
local f2 = faction.create("halfling", "noreply@eressea.de", "de")
|
2017-02-14 19:57:31 +01:00
|
|
|
local u2 = unit.create(f2, r, 1)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
2017-02-14 19:57:31 +01:00
|
|
|
local b = building.create(r, "castle")
|
|
|
|
u2.building = b
|
|
|
|
u1.building = b
|
2010-08-08 09:40:42 +02:00
|
|
|
|
2017-02-14 19:57:31 +01:00
|
|
|
b.owner = u2
|
|
|
|
assert_equal("site", b:get_typename(7))
|
|
|
|
assert_equal("fortification", b:get_typename(8))
|
|
|
|
b.owner = u1
|
|
|
|
assert_equal("site", b:get_typename(9))
|
|
|
|
assert_equal("fortification", b:get_typename(10))
|
2010-08-08 09:40:42 +02:00
|
|
|
end
|
2015-07-08 16:11:25 +02:00
|
|
|
|
|
|
|
function test_build_normal()
|
2017-02-14 19:57:31 +01:00
|
|
|
local r = region.create(0, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "noreply@eressea.de", "de")
|
2017-02-14 19:57:31 +01:00
|
|
|
local u = unit.create(f, r, 1)
|
2015-07-08 16:11:25 +02:00
|
|
|
u:clear_orders()
|
|
|
|
u:add_item("stone", 10)
|
|
|
|
u:set_skill("building", 10)
|
|
|
|
u:add_order("MACHE BURG")
|
|
|
|
process_orders()
|
|
|
|
assert_not_nil(u.building)
|
|
|
|
assert_equal(10, u.building.size)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_build_packice()
|
2017-02-14 19:57:31 +01:00
|
|
|
local r = region.create(0, 0, "packice")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "packice@eressea.de", "de")
|
2017-02-14 19:57:31 +01:00
|
|
|
local u = unit.create(f, r, 1)
|
2015-07-08 16:11:25 +02:00
|
|
|
u:clear_orders()
|
|
|
|
u:add_item("stone", 10)
|
|
|
|
u:set_skill("building", 10)
|
|
|
|
u:add_order("MACHE BURG")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(nil, u.building)
|
|
|
|
end
|
2015-11-06 20:59:45 +01:00
|
|
|
|
|
|
|
function test_build_castle_stages()
|
|
|
|
local r = region.create(0,0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "castle@eressea.de", "de")
|
2015-11-06 20:59:45 +01:00
|
|
|
local u = unit.create(f, r, 1000)
|
|
|
|
local b = building.create(r, "castle")
|
|
|
|
|
|
|
|
u:add_item("stone", 1000)
|
|
|
|
|
|
|
|
u:set_skill("building", 1)
|
|
|
|
u:clear_orders()
|
|
|
|
|
|
|
|
u:add_order("MACHE BURG " .. itoa36(b.id))
|
|
|
|
process_orders()
|
|
|
|
assert_equal(10, b.size)
|
|
|
|
|
|
|
|
u:set_skill("building", 3)
|
|
|
|
u:clear_orders()
|
|
|
|
|
|
|
|
u:add_order("MACHE BURG " .. itoa36(b.id))
|
|
|
|
process_orders()
|
|
|
|
assert_equal(250, b.size)
|
|
|
|
end
|