2010-08-08 10:06:34 +02:00
|
|
|
require "lunit"
|
|
|
|
|
2010-11-01 03:46:08 +01:00
|
|
|
local function _test_create_ship(r)
|
2011-03-07 06:49:01 +01:00
|
|
|
local s = ship.create(r, config.ships[1])
|
2010-11-01 03:46:08 +01:00
|
|
|
return s
|
|
|
|
end
|
|
|
|
|
2011-03-09 00:25:51 +01:00
|
|
|
local function _test_unique_btype()
|
|
|
|
local utype = nil
|
|
|
|
for i = 1, #config.buildings do
|
|
|
|
bt = config.buildings[i]
|
2011-03-09 06:06:38 +01:00
|
|
|
if ((config.get_building(bt).flags / 4) % 2) ~= 0 then -- #define BTF_UNIQUE 0x04
|
|
|
|
if ((config.get_building(bt).flags / 2) % 2) == 0 then -- #define BTF_NOBUILD 0x02
|
2011-03-09 00:25:51 +01:00
|
|
|
utype = bt
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return utype
|
|
|
|
end
|
|
|
|
|
2010-11-01 07:31:56 +01:00
|
|
|
local function one_unit(r, f)
|
2010-08-08 10:06:34 +02:00
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
u:add_item("money", u.number * 100)
|
|
|
|
u:clear_orders()
|
|
|
|
return u
|
|
|
|
end
|
|
|
|
|
2010-11-01 07:31:56 +01:00
|
|
|
local function two_units(r, f1, f2)
|
2010-08-08 10:06:34 +02:00
|
|
|
return one_unit(r, f1), one_unit(r, f2)
|
|
|
|
end
|
|
|
|
|
2010-11-01 07:31:56 +01:00
|
|
|
local function two_factions()
|
2010-08-08 10:06:34 +02:00
|
|
|
local f1 = faction.create("noreply@eressea.de", "human", "de")
|
2011-02-27 09:36:38 +01:00
|
|
|
local f2 = faction.create("noreply@eressea.de", "elf", "de")
|
2010-08-08 10:06:34 +02:00
|
|
|
return f1, f2
|
|
|
|
end
|
|
|
|
|
2012-06-05 16:36:05 +02:00
|
|
|
module("tests.eressea.common", package.seeall, lunit.testcase)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2010-11-01 07:31:56 +01:00
|
|
|
function setup()
|
2012-06-07 04:29:36 +02:00
|
|
|
eressea.free_game()
|
|
|
|
eressea.write_game("free.dat")
|
|
|
|
eressea.settings.set("nmr.removenewbie", "0")
|
|
|
|
eressea.settings.set("nmr.timeout", "0")
|
|
|
|
eressea.settings.set("NewbieImmunity", "0")
|
|
|
|
eressea.settings.set("rules.economy.food", "4")
|
2010-11-01 07:31:56 +01:00
|
|
|
end
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
function DISABLE_test_eventbus_fire()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r)
|
|
|
|
|
|
|
|
function compare_f(u, event, f)
|
|
|
|
assert_equal(u.faction, f)
|
|
|
|
end
|
|
|
|
eventbus.register(u, "weird", compare_f)
|
|
|
|
eventbus.fire(u, "weird", f)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_fleeing_units_can_be_transported()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local r1 = region.create(1, 0, "plain")
|
|
|
|
local f1, f2 = two_factions()
|
|
|
|
local u1, u2 = two_units(r, f1, f2)
|
|
|
|
local u3 = one_unit(r, f2)
|
|
|
|
u1.number = 100
|
|
|
|
u1:add_order("ATTACKIEREN " .. itoa36(u2.id))
|
|
|
|
u2.number = 100
|
|
|
|
u2:add_order("FAHREN " .. itoa36(u3.id))
|
2011-03-09 14:44:31 +01:00
|
|
|
u2:add_order("KAEMPFE FLIEHE")
|
2010-08-08 10:06:34 +02:00
|
|
|
u3.number = 100
|
|
|
|
u3:add_order("KAEMPFE FLIEHE")
|
|
|
|
u3:add_order("TRANSPORT " .. itoa36(u2.id))
|
|
|
|
u3:add_order("NACH O ")
|
|
|
|
u3:set_skill("riding", 2)
|
|
|
|
u3:add_item("horse", u2.number)
|
|
|
|
u3:add_order("KAEMPFE FLIEHE")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(u3.region.id, r1.id, "transporter did not move")
|
|
|
|
assert_equal(u2.region.id, r1.id, "transported unit did not move")
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_plane()
|
|
|
|
local pl = plane.create(0, -3, -3, 7, 7)
|
|
|
|
local nx, ny = plane.normalize(pl, 4, 4)
|
|
|
|
assert_equal(nx, -3, "normalization failed")
|
|
|
|
assert_equal(ny, -3, "normalization failed")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
f.id = atoi36("tpla")
|
|
|
|
local r, x, y
|
|
|
|
for x = -3, 3 do for y = -3, 3 do
|
|
|
|
r = region.create(x, y, "plain")
|
2011-03-09 06:06:38 +01:00
|
|
|
if x==y then
|
2010-08-08 10:06:34 +02:00
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
end
|
|
|
|
end end
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_pure()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
assert_not_equal(nil, r)
|
|
|
|
assert_equal(r, get_region(0, 0))
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_read_write()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r)
|
|
|
|
u.number = 2
|
|
|
|
local fno = f.id
|
|
|
|
local uno = u.id
|
|
|
|
local result = 0
|
|
|
|
assert_equal(r.terrain, "plain")
|
2012-06-07 04:29:36 +02:00
|
|
|
result = eressea.write_game("test_read_write.dat")
|
2010-08-08 10:06:34 +02:00
|
|
|
assert_equal(result, 0)
|
|
|
|
assert_not_equal(get_region(0, 0), nil)
|
|
|
|
assert_not_equal(get_faction(fno), nil)
|
|
|
|
assert_not_equal(get_unit(uno), nil)
|
|
|
|
r = nil
|
|
|
|
f = nil
|
|
|
|
u = nil
|
2012-06-07 04:29:36 +02:00
|
|
|
eressea.free_game()
|
2010-08-08 10:06:34 +02:00
|
|
|
assert_equal(get_region(0, 0), nil)
|
|
|
|
assert_equal(nil, get_faction(fno))
|
|
|
|
assert_equal(nil, get_unit(uno))
|
2012-06-07 04:29:36 +02:00
|
|
|
result = eressea.read_game("test_read_write.dat")
|
2010-08-08 10:06:34 +02:00
|
|
|
assert_equal(0, result)
|
|
|
|
assert_not_equal(nil, get_region(0, 0))
|
|
|
|
assert_not_equal(nil, get_faction(fno))
|
|
|
|
assert_not_equal(nil, get_unit(uno))
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_gmtool()
|
|
|
|
local r1 = region.create(1, 0, "plain")
|
|
|
|
local r2 = region.create(1, 1, "plain")
|
|
|
|
local r3 = region.create(1, 2, "plain")
|
|
|
|
gmtool.open()
|
|
|
|
gmtool.select(r1, true)
|
|
|
|
gmtool.select_at(0, 1, true)
|
|
|
|
gmtool.select(r2, true)
|
|
|
|
gmtool.select_at(0, 2, true)
|
|
|
|
gmtool.select(r3, false)
|
|
|
|
gmtool.select(r3, true)
|
|
|
|
gmtool.select_at(0, 3, false)
|
|
|
|
gmtool.select(r3, false)
|
|
|
|
|
|
|
|
local selections = 0
|
|
|
|
for r in gmtool.get_selection() do
|
|
|
|
selections=selections+1
|
|
|
|
end
|
|
|
|
assert_equal(2, selections)
|
|
|
|
assert_equal(nil, gmtool.get_cursor())
|
|
|
|
|
|
|
|
gmtool.close()
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_faction()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
assert(f)
|
|
|
|
f.info = "Spazz"
|
|
|
|
assert(f.info=="Spazz")
|
|
|
|
f:add_item("donotwant", 42)
|
|
|
|
f:add_item("stone", 42)
|
|
|
|
f:add_item("sword", 42)
|
|
|
|
local items = 0
|
|
|
|
for u in f.items do
|
|
|
|
items = items + 1
|
|
|
|
end
|
|
|
|
assert(items==2)
|
|
|
|
unit.create(f, r)
|
|
|
|
unit.create(f, r)
|
|
|
|
local units = 0
|
|
|
|
for u in f.units do
|
|
|
|
units = units + 1
|
|
|
|
end
|
|
|
|
assert(units==2)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_unit()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r)
|
|
|
|
u.number = 20
|
|
|
|
u.name = "Enno"
|
|
|
|
assert(u.name=="Enno")
|
|
|
|
u.info = "Spazz"
|
|
|
|
assert(u.info=="Spazz")
|
|
|
|
u:add_item("sword", 4)
|
|
|
|
assert(u:get_item("sword")==4)
|
|
|
|
assert(u:get_pooled("sword")==4)
|
|
|
|
u:use_pooled("sword", 2)
|
|
|
|
assert(u:get_item("sword")==2)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_region()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
r:set_resource("horse", 42)
|
|
|
|
r:set_resource("money", 45)
|
|
|
|
r:set_resource("peasant", 200)
|
|
|
|
assert(r:get_resource("horse") == 42)
|
|
|
|
assert(r:get_resource("money") == 45)
|
|
|
|
assert(r:get_resource("peasant") == 200)
|
|
|
|
r.name = nil
|
|
|
|
r.info = nil
|
|
|
|
assert(r.name=="")
|
|
|
|
assert(r.info=="")
|
|
|
|
r.name = "Alabasterheim"
|
|
|
|
r.info = "Hier wohnen die siebzehn Zwerge"
|
|
|
|
assert(tostring(r) == "Alabasterheim (0,0)")
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_building()
|
|
|
|
local u
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local b = building.create(r, "castle")
|
|
|
|
u = unit.create(f, r)
|
|
|
|
u.number = 1
|
|
|
|
u.building = b
|
|
|
|
u = unit.create(f, r)
|
|
|
|
u.number = 2
|
|
|
|
-- u.building = b
|
|
|
|
u = unit.create(f, r)
|
|
|
|
u.number = 3
|
|
|
|
u.building = b
|
|
|
|
local units = 0
|
|
|
|
for u in b.units do
|
|
|
|
units = units + 1
|
|
|
|
end
|
|
|
|
assert(units==2)
|
|
|
|
local r2 = region.create(0, 1, "plain")
|
|
|
|
assert(b.region==r)
|
|
|
|
b.region = r2
|
|
|
|
assert(b.region==r2)
|
|
|
|
assert(r2.buildings()==b)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_message()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r)
|
|
|
|
local msg = message.create("item_create_spell")
|
|
|
|
msg:set_unit("mage", u)
|
|
|
|
msg:set_int("number", 1)
|
|
|
|
msg:set_resource("item", "sword")
|
|
|
|
msg:send_region(r)
|
|
|
|
msg:send_faction(f)
|
|
|
|
|
|
|
|
return msg
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_hashtable()
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
f.objects:set("enno", "smart guy")
|
|
|
|
f.objects:set("age", 10)
|
|
|
|
assert(f.objects:get("jesus") == nil)
|
|
|
|
assert(f.objects:get("enno") == "smart guy")
|
|
|
|
assert(f.objects:get("age") == 10)
|
|
|
|
f.objects:set("age", nil)
|
|
|
|
assert(f.objects:get("age") == nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_events()
|
|
|
|
local fail = 1
|
|
|
|
local function msg_handler(u, evt)
|
|
|
|
str = evt:get(0)
|
|
|
|
u2 = evt:get(1)
|
|
|
|
assert(u2~=nil)
|
|
|
|
assert(str=="Du Elf stinken")
|
|
|
|
message_unit(u, u2, "thanks unit, i got your message: " .. str)
|
|
|
|
message_faction(u, u2.faction, "thanks faction, i got your message: " .. str)
|
|
|
|
message_region(u, "thanks region, i got your message: " .. str)
|
|
|
|
fail = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
plain = region.create(0, 0, "plain")
|
|
|
|
skill = 8
|
|
|
|
|
2011-02-27 09:36:38 +01:00
|
|
|
f = faction.create("noreply@eressea.de", "elf", "de")
|
2010-08-08 10:06:34 +02:00
|
|
|
f.age = 20
|
|
|
|
|
|
|
|
u = unit.create(f, plain)
|
|
|
|
u.number = 1
|
|
|
|
u:add_item("money", u.number*100)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("NUMMER PARTEI test")
|
|
|
|
u:add_handler("message", msg_handler)
|
|
|
|
msg = "BOTSCHAFT EINHEIT " .. itoa36(u.id) .. " Du~Elf~stinken"
|
|
|
|
f = faction.create("noreply@eressea.de", "elf", "de")
|
|
|
|
f.age = 20
|
|
|
|
|
|
|
|
u = unit.create(f, plain)
|
|
|
|
u.number = 1
|
|
|
|
u:add_item("money", u.number*100)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("NUMMER PARTEI eviL")
|
|
|
|
u:add_order(msg)
|
|
|
|
process_orders()
|
|
|
|
assert(fail==0)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_recruit2()
|
2011-03-07 06:49:01 +01:00
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r)
|
|
|
|
u.number = 1
|
|
|
|
u:add_item("money", 2000)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("MACHE TEMP 1")
|
|
|
|
u:add_order("REKRUTIERE 1 Elf")
|
|
|
|
u:add_order("REKRUTIERE 1 Mensch")
|
|
|
|
u:add_order("REKRUTIERE 1")
|
|
|
|
process_orders()
|
2010-08-08 10:06:34 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function test_guard()
|
|
|
|
region.create(1, 0, "plain")
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f1 = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
f1.age = 20
|
|
|
|
local u1 = unit.create(f1, r, 1)
|
|
|
|
u1:add_item("sword", 10)
|
|
|
|
u1:add_item("money", 10)
|
|
|
|
u1:set_skill("melee", 10)
|
|
|
|
u1:clear_orders()
|
|
|
|
u1:add_order("NACH O")
|
|
|
|
|
|
|
|
local f2 = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
f2.age = 20
|
|
|
|
local u2 = unit.create(f2, r, 1)
|
|
|
|
local u3 = unit.create(f2, r, 1)
|
|
|
|
local b = building.create(r, "castle")
|
|
|
|
b.size = 10
|
|
|
|
u2.building = b
|
|
|
|
u3.building = b
|
|
|
|
u2:clear_orders()
|
|
|
|
u2:add_order("ATTACKIEREN " .. itoa36(u1.id)) -- you will die...
|
|
|
|
u2:add_item("money", 100)
|
|
|
|
u3:add_item("money", 100)
|
|
|
|
process_orders()
|
|
|
|
assert_equal(r.id, u1.region.id, "unit may not move after combat")
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_recruit()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r)
|
|
|
|
u.number = 1
|
|
|
|
local n = 3
|
|
|
|
r:set_resource("peasant", 200)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_item("money", 110*n+20)
|
|
|
|
u:add_order("REKRUTIERE " .. n)
|
|
|
|
process_orders()
|
|
|
|
assert(u.number == n+1)
|
|
|
|
local p = r:get_resource("peasant")
|
|
|
|
assert(p<200 and p>=200-n)
|
|
|
|
-- assert(u:get_item("money")==10)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_produce()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
u:clear_orders()
|
2011-03-07 06:49:01 +01:00
|
|
|
local sword = config.get_resource('sword')
|
|
|
|
u:set_skill(sword.build_skill_name, 3)
|
2011-03-04 20:38:36 +01:00
|
|
|
u:add_item("iron", 10)
|
2010-08-08 10:06:34 +02:00
|
|
|
u:add_item("money", u.number * 10)
|
|
|
|
u:add_order("MACHE Schwert")
|
|
|
|
process_orders()
|
2011-03-07 06:49:01 +01:00
|
|
|
assert_equal(10-3/sword.build_skill_min*sword.materials['iron'], u:get_item("iron"))
|
|
|
|
assert_equal(3/sword.build_skill_min, u:get_item("sword"))
|
2010-08-08 10:06:34 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function test_work()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
u:add_item("money", u.number * 10) -- humans cost 10
|
|
|
|
u:set_skill("herbalism", 5)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("ARBEITEN")
|
|
|
|
process_orders()
|
|
|
|
assert(u:get_item("money")>=10)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_upkeep()
|
2012-06-07 04:29:36 +02:00
|
|
|
eressea.settings.set("rules.economy.food", "0")
|
2010-11-01 07:31:56 +01:00
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 5)
|
|
|
|
u:add_item("money", u.number * 11)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("LERNE Waffenbau")
|
|
|
|
process_orders()
|
|
|
|
assert(u:get_item("money")==u.number)
|
2010-08-08 10:06:34 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function test_id()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
f.id = atoi36("42")
|
|
|
|
assert(get_faction(42)~=f)
|
|
|
|
assert(get_faction("42")==f)
|
|
|
|
assert(get_faction(atoi36("42"))==f)
|
|
|
|
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
u.id = atoi36("42")
|
|
|
|
assert(get_unit(42)~=u)
|
|
|
|
assert(get_unit("42")==u)
|
|
|
|
assert(get_unit(atoi36("42"))==u)
|
|
|
|
|
|
|
|
local b = building.create(r, "castle")
|
|
|
|
-- <not working> b.id = atoi36("42")
|
|
|
|
local fortytwo = itoa36(b.id)
|
|
|
|
assert(get_building(fortytwo)==b)
|
|
|
|
assert(get_building(atoi36(fortytwo))==b)
|
|
|
|
|
2010-11-01 03:46:08 +01:00
|
|
|
local s = _test_create_ship(r)
|
2011-03-06 11:27:37 +01:00
|
|
|
assert_not_nil(s)
|
2010-08-08 10:06:34 +02:00
|
|
|
-- <not working> s.id = atoi36("42")
|
|
|
|
local fortytwo = itoa36(s.id)
|
|
|
|
assert(get_ship(fortytwo)==s)
|
|
|
|
assert(get_ship(atoi36(fortytwo))==s)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_herbalism()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
u:add_item("money", u.number * 100)
|
|
|
|
u:set_skill("herbalism", 5)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("MACHE Samen")
|
|
|
|
process_orders()
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_mallorn()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
r:set_flag(1, false) -- not mallorn
|
|
|
|
r:set_resource("tree", 100)
|
|
|
|
assert(r:get_resource("tree")==100)
|
|
|
|
local m = region.create(0, 0, "plain")
|
2011-03-04 20:38:36 +01:00
|
|
|
m:set_flag(1, true) -- mallorn
|
2010-08-08 10:06:34 +02:00
|
|
|
m:set_resource("tree", 100)
|
|
|
|
assert(m:get_resource("tree")==100)
|
|
|
|
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
|
|
|
|
local u1 = unit.create(f, r, 1)
|
|
|
|
u1:add_item("money", u1.number * 100)
|
|
|
|
u1:set_skill("forestry", 2)
|
|
|
|
u1:clear_orders()
|
|
|
|
u1:add_order("MACHE HOLZ")
|
|
|
|
|
|
|
|
local u2 = unit.create(f, m, 1)
|
|
|
|
u2:add_item("money", u2.number * 100)
|
|
|
|
u2:set_skill("forestry", 2)
|
|
|
|
u2:clear_orders()
|
|
|
|
u2:add_order("MACHE HOLZ")
|
|
|
|
|
|
|
|
local u3 = unit.create(f, m, 1)
|
|
|
|
u3:add_item("money", u3.number * 100)
|
|
|
|
u3:set_skill("forestry", 2)
|
|
|
|
u3:clear_orders()
|
|
|
|
u3:add_order("MACHE Mallorn")
|
2011-03-04 20:38:36 +01:00
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
process_orders()
|
2011-03-04 20:38:36 +01:00
|
|
|
|
2012-05-20 03:21:38 +02:00
|
|
|
assert_equal(2, u1:get_item("log"))
|
|
|
|
assert_equal(2, u2:get_item("log"))
|
2011-03-07 06:49:01 +01:00
|
|
|
local mallorn_cfg = config.get_resource("mallorn")
|
|
|
|
if mallorn_cfg then
|
2012-05-20 03:21:38 +02:00
|
|
|
assert_equal(1, u3:get_item("mallorn"))
|
2011-03-04 20:38:36 +01:00
|
|
|
else
|
|
|
|
assert_equal(-1, u3:get_item("mallorn"))
|
|
|
|
assert_equal(0, u3:get_item("log"))
|
|
|
|
end
|
2010-08-08 10:06:34 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function test_coordinate_translation()
|
|
|
|
local pl = plane.create(1, 500, 500, 1001, 1001) -- astralraum
|
|
|
|
local pe = plane.create(1, -8761, 3620, 23, 23) -- eternath
|
|
|
|
local r = region.create(1000, 1000, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
assert_not_equal(nil, r)
|
|
|
|
assert_equal(r.x, 1000)
|
|
|
|
assert_equal(r.y, 1000)
|
|
|
|
local nx, ny = plane.normalize(pl, r.x, r.y)
|
|
|
|
assert_equal(nx, 1000)
|
|
|
|
assert_equal(ny, 1000)
|
|
|
|
local r1 = region.create(500, 500, "plain")
|
|
|
|
f:set_origin(r1)
|
|
|
|
nx, ny = f:normalize(r1)
|
|
|
|
assert_equal(0, nx)
|
|
|
|
assert_equal(0, ny)
|
|
|
|
local r0 = region.create(0, 0, "plain")
|
|
|
|
nx, ny = f:normalize(r0)
|
|
|
|
assert_equal(0, nx)
|
|
|
|
assert_equal(0, ny)
|
|
|
|
nx, ny = f:normalize(r)
|
|
|
|
assert_equal(500, nx)
|
|
|
|
assert_equal(500, ny)
|
|
|
|
local rn = region.create(1010, 1010, "plain")
|
|
|
|
nx, ny = f:normalize(rn)
|
|
|
|
assert_equal(-491, nx)
|
|
|
|
assert_equal(-491, ny)
|
|
|
|
|
|
|
|
local re = region.create(-8760, 3541, "plain") -- eternath
|
|
|
|
nx, ny = f:normalize(rn)
|
|
|
|
assert_equal(-491, nx)
|
|
|
|
assert_equal(-491, ny)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_control()
|
|
|
|
local u1, u2 = two_units(region.create(0, 0, "plain"), two_factions())
|
|
|
|
local r = u1.region
|
|
|
|
local b = building.create(r, "castle")
|
|
|
|
u1.building = b
|
|
|
|
u2.building = b
|
|
|
|
assert_equal(u1, b.owner)
|
|
|
|
u1:clear_orders()
|
|
|
|
u1:add_order("GIB " .. itoa36(u2.id) .. " KOMMANDO")
|
|
|
|
u1:add_order("VERLASSE")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(u2, b.owner)
|
|
|
|
end
|
|
|
|
|
2010-11-01 03:34:55 +01:00
|
|
|
function test_store_unit()
|
2010-08-08 10:06:34 +02:00
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
2010-11-01 03:34:55 +01:00
|
|
|
local fid = f.id
|
2010-08-08 10:06:34 +02:00
|
|
|
u:add_item("money", u.number * 100)
|
2011-02-27 08:51:17 +01:00
|
|
|
local filename = config.basepath .. "/data/test.unit.dat"
|
|
|
|
store = storage.create(filename, "wb")
|
2010-08-08 10:06:34 +02:00
|
|
|
assert_not_equal(store, nil)
|
|
|
|
store:write_unit(u)
|
|
|
|
store:close()
|
2012-06-07 04:29:36 +02:00
|
|
|
eressea.free_game()
|
2010-08-08 10:06:34 +02:00
|
|
|
-- recreate world:
|
|
|
|
r = region.create(0, 0, "plain")
|
|
|
|
f = faction.create("noreply@eressea.de", "human", "de")
|
2010-11-01 03:34:55 +01:00
|
|
|
f.id = fid
|
2011-02-27 08:51:17 +01:00
|
|
|
store = storage.create(filename, "rb")
|
|
|
|
assert_not_nil(store)
|
2010-08-08 10:06:34 +02:00
|
|
|
u = store:read_unit()
|
|
|
|
store:close()
|
|
|
|
assert(u)
|
|
|
|
assert(u:get_item("money") == u.number * 100)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_building_other()
|
|
|
|
local r = region.create(0,0, "plain")
|
|
|
|
local f1 = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local f2 = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local b = building.create(r, "castle")
|
|
|
|
b.size = 10
|
|
|
|
local u1 = unit.create(f1, r, 3)
|
|
|
|
u1.building = b
|
|
|
|
u1:add_item("money", 100)
|
|
|
|
|
|
|
|
local u2 = unit.create(f2, r, 3)
|
|
|
|
u2:set_skill("building", 10)
|
|
|
|
u2:add_item("money", 100)
|
|
|
|
u2:add_item("stone", 100)
|
|
|
|
u2:clear_orders()
|
|
|
|
u2:add_order("MACHEN BURG " .. itoa36(b.id))
|
|
|
|
process_orders()
|
|
|
|
assert_not_equal(10, b.size)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_config()
|
|
|
|
assert_not_equal(nil, config.basepath)
|
|
|
|
assert_not_equal(nil, config.locales)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_guard_resources()
|
|
|
|
-- this is not quite http://bugs.eressea.de/view.php?id=1756
|
|
|
|
local r = region.create(0,0, "mountain")
|
|
|
|
local f1 = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
f1.age=20
|
|
|
|
local f2 = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
f2.age=20
|
|
|
|
local u1 = unit.create(f1, r, 1)
|
|
|
|
u1:add_item("money", 100)
|
|
|
|
u1:set_skill("melee", 3)
|
|
|
|
u1:add_item("sword", 1)
|
|
|
|
u1:clear_orders()
|
|
|
|
u1:add_order("BEWACHEN")
|
|
|
|
|
|
|
|
local u2 = unit.create(f2, r, 1)
|
|
|
|
u2:add_item("money", 100)
|
|
|
|
u2:set_skill("mining", 3)
|
|
|
|
u2:clear_orders()
|
|
|
|
u2:add_order("MACHEN EISEN")
|
|
|
|
|
|
|
|
process_orders()
|
|
|
|
local iron = u2:get_item("iron")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(iron, u2:get_item("iron"))
|
|
|
|
end
|
|
|
|
|
|
|
|
local function is_flag_set(flags, flag)
|
|
|
|
return math.mod(flags, flag*2) - math.mod(flags, flag) == flag;
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_hero_hero_transfer()
|
|
|
|
local r = region.create(0,0, "mountain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
f.age=20
|
|
|
|
local UFL_HERO = 128
|
|
|
|
|
|
|
|
local u1 = unit.create(f, r, 1)
|
|
|
|
local u2 = unit.create(f, r, 1)
|
|
|
|
u1:add_item("money", 10000)
|
|
|
|
u1.flags = u1.flags + UFL_HERO
|
|
|
|
u2.flags = u2.flags + UFL_HERO
|
|
|
|
u1:clear_orders()
|
|
|
|
u1:add_order("GIB " .. itoa36(u2.id) .. " 1 PERSONEN")
|
|
|
|
u1:add_order("REKRUTIEREN 1")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(1, u1.number)
|
|
|
|
assert_equal(2, u2.number)
|
|
|
|
assert_false(is_flag_set(u1.flags, 128), 128, "recruiting into an empty hero unit should not create a hero")
|
|
|
|
assert_true(is_flag_set(u2.flags, 128), 128, "unit is not a hero?")
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_hero_normal_transfer()
|
|
|
|
local r = region.create(0,0, "mountain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
f.age=20
|
|
|
|
local UFL_HERO = 128
|
|
|
|
|
|
|
|
local u1 = unit.create(f, r, 1)
|
|
|
|
local u2 = unit.create(f, r, 1)
|
|
|
|
u1:add_item("money", 10000)
|
|
|
|
u1.flags = u1.flags + UFL_HERO
|
|
|
|
u1:clear_orders()
|
|
|
|
u1:add_order("GIB " .. itoa36(u2.id) .. " 1 PERSONEN")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(1, u1.number)
|
|
|
|
assert_equal(1, u2.number)
|
|
|
|
assert_true(is_flag_set(u1.flags, 128), "unit is not a hero?")
|
|
|
|
assert_false(is_flag_set(u2.flags, 128), "unit turned into a hero")
|
|
|
|
end
|
2010-08-17 08:55:53 +02:00
|
|
|
|
|
|
|
function test_expensive_skills_cost_money()
|
|
|
|
local r = region.create(0,0, "mountain")
|
2010-08-28 22:41:02 +02:00
|
|
|
local f = faction.create("noreply@eressea.de", "elf", "de")
|
2010-08-17 08:55:53 +02:00
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
u:add_item("money", 10000)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("LERNEN MAGIE Gwyrrd")
|
|
|
|
process_orders()
|
2010-10-09 08:39:16 +02:00
|
|
|
assert_equal(9900, u:get_item("money"))
|
2010-08-17 08:55:53 +02:00
|
|
|
assert_equal(1, u:get_skill("magic"))
|
|
|
|
end
|
2010-10-09 08:39:16 +02:00
|
|
|
|
|
|
|
function test_food_is_consumed()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
u:add_item("money", 100)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("LERNEN Reiten") -- don't work
|
2012-06-07 04:29:36 +02:00
|
|
|
eressea.settings.set("rules.economy.food", "4")
|
2010-10-09 08:39:16 +02:00
|
|
|
process_orders()
|
|
|
|
assert_equal(100, u:get_item("money"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_food_can_override()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
u:add_item("money", 100)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("LERNEN Reiten") -- don't work
|
2012-06-07 04:29:36 +02:00
|
|
|
eressea.settings.set("rules.economy.food", "0")
|
2010-10-09 08:39:16 +02:00
|
|
|
process_orders()
|
|
|
|
assert_equal(90, u:get_item("money"))
|
|
|
|
end
|
2010-11-01 03:34:55 +01:00
|
|
|
|
|
|
|
function test_swim_and_survive()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
f.nam = "chaos"
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
process_orders()
|
|
|
|
r.terrain = "ocean"
|
2010-11-01 03:46:08 +01:00
|
|
|
local s = _test_create_ship(r)
|
2010-11-01 03:34:55 +01:00
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("BETRETE SCHIFF " .. itoa36(s.id))
|
|
|
|
process_orders()
|
|
|
|
assert_equal(u.number, 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_swim_and_die()
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
local uid = u.id
|
|
|
|
process_orders()
|
|
|
|
r.terrain = "ocean"
|
|
|
|
u = get_unit(uid)
|
|
|
|
assert_not_equal(get_unit(uid), nil)
|
|
|
|
process_orders()
|
|
|
|
assert_equal(get_unit(uid), nil)
|
|
|
|
end
|
2010-11-01 07:31:56 +01:00
|
|
|
|
|
|
|
function test_ride_with_horse()
|
|
|
|
region.create(1, 0, "plain")
|
|
|
|
region.create(2, 0, "plain")
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
u:add_item("horse", 1)
|
2011-03-07 06:49:01 +01:00
|
|
|
local horse_cfg = config.get_resource("horse")
|
|
|
|
u:add_item("sword", (horse_cfg.capacity - u.weight)/100)
|
2010-11-01 07:31:56 +01:00
|
|
|
u:set_skill("riding", 2)
|
|
|
|
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("NACH O O")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(u.region.x, 2)
|
|
|
|
|
|
|
|
u:add_item("sword", 1)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("NACH W W")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(u.region.x, 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_ride_with_horses_and_cart()
|
|
|
|
region.create(1, 0, "plain")
|
|
|
|
region.create(2, 0, "plain")
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
2011-03-07 06:49:01 +01:00
|
|
|
local horse_cfg = config.get_resource("horse")
|
|
|
|
local cart_cfg = config.get_resource("cart")
|
|
|
|
local sword_cfg = config.get_resource("sword")
|
|
|
|
|
2010-11-01 07:31:56 +01:00
|
|
|
u:set_skill("riding", 3)
|
|
|
|
|
2011-03-07 06:49:01 +01:00
|
|
|
local capacity = (horse_cfg.capacity-horse_cfg.weight)*2 - u.weight
|
|
|
|
if cart_cfg~=nil then
|
|
|
|
capacity = capacity + cart_cfg.capacity-cart_cfg.weight
|
2011-03-04 20:38:36 +01:00
|
|
|
end
|
2011-03-07 06:49:01 +01:00
|
|
|
u:add_item("sword", capacity / sword_cfg.weight)
|
2011-03-04 20:38:36 +01:00
|
|
|
|
2011-03-07 06:49:01 +01:00
|
|
|
u:add_item("horse", 1)
|
2011-03-09 06:06:38 +01:00
|
|
|
if cart_cfg~=nil then
|
2011-03-07 06:49:01 +01:00
|
|
|
-- we need 2 horses for a cart, so this should fail:
|
|
|
|
u:add_item("cart", 1)
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("NACH O O")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(0, u.region.x)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- here is your second horse, milord:
|
2011-03-04 20:38:36 +01:00
|
|
|
u:add_item("horse", 1)
|
|
|
|
assert_equal(2, u:get_item("horse"))
|
|
|
|
|
2010-11-01 07:31:56 +01:00
|
|
|
-- ride
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("NACH O O")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(2, u.region.x)
|
|
|
|
|
|
|
|
-- walk
|
2011-03-07 06:49:01 +01:00
|
|
|
u:add_item("sword", 1000/sword_cfg.weight)
|
2010-11-01 07:31:56 +01:00
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("NACH W W")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(1, u.region.x)
|
|
|
|
|
2011-03-07 06:49:01 +01:00
|
|
|
-- make this fellow too heavy
|
|
|
|
u:add_item("sword", 1000/sword_cfg.weight)
|
2010-11-01 07:31:56 +01:00
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("NACH W W")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(1, u.region.x)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_walk_and_carry_the_cart()
|
|
|
|
region.create(1, 0, "plain")
|
|
|
|
local r = region.create(2, 0, "plain")
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 10)
|
|
|
|
u:add_item("cart", 1)
|
|
|
|
|
|
|
|
-- walk
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("NACH O O")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(1, u.region.x)
|
|
|
|
end
|
2010-11-06 05:21:49 +01:00
|
|
|
|
2011-02-19 15:13:24 +01:00
|
|
|
module("tests.report", package.seeall, lunit.testcase)
|
2010-11-06 05:21:49 +01:00
|
|
|
|
|
|
|
function setup()
|
2012-06-07 04:29:36 +02:00
|
|
|
eressea.free_game()
|
|
|
|
eressea.settings.set("nmr.removenewbie", "0")
|
|
|
|
eressea.settings.set("nmr.timeout", "0")
|
|
|
|
eressea.settings.set("rules.economy.food", "4")
|
2010-11-06 05:21:49 +01:00
|
|
|
end
|
|
|
|
|
2010-11-06 06:54:29 +01:00
|
|
|
local function find_in_report(f, pattern, extension)
|
|
|
|
extension = extension or "nr"
|
2012-05-26 03:50:14 +02:00
|
|
|
local filename = config.reportpath .. "/" .. get_turn() .. "-" .. itoa36(f.id) .. "." .. extension
|
2010-11-06 05:21:49 +01:00
|
|
|
local report = io.open(filename, 'rt');
|
2011-02-27 08:51:17 +01:00
|
|
|
assert_not_nil(report)
|
2010-11-06 05:21:49 +01:00
|
|
|
t = report:read("*all")
|
|
|
|
report:close()
|
2010-11-06 06:54:29 +01:00
|
|
|
|
|
|
|
local start, _ = string.find(t, pattern)
|
2010-11-06 05:21:49 +01:00
|
|
|
-- posix.unlink(filename)
|
2010-11-06 06:54:29 +01:00
|
|
|
return start~=nil
|
|
|
|
end
|
|
|
|
|
2010-11-06 05:21:49 +01:00
|
|
|
function test_coordinates_no_plane()
|
|
|
|
local r = region.create(0, 0, "mountain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
init_reports()
|
2010-11-12 05:11:19 +01:00
|
|
|
write_report(f)
|
|
|
|
assert_true(find_in_report(f, r.name .. " %(0,0%), Berg"))
|
2010-11-06 05:21:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function test_coordinates_named_plane()
|
|
|
|
local p = plane.create(0, -3, -3, 7, 7, "Hell")
|
|
|
|
local r = region.create(0, 0, "mountain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
init_reports()
|
2010-11-12 05:11:19 +01:00
|
|
|
write_report(f)
|
|
|
|
assert_true(find_in_report(f, r.name .. " %(0,0,Hell%), Berg"))
|
2010-11-06 05:21:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function test_coordinates_unnamed_plane()
|
|
|
|
local p = plane.create(0, -3, -3, 7, 7)
|
|
|
|
local r = region.create(0, 0, "mountain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
init_reports()
|
2010-11-12 05:11:19 +01:00
|
|
|
write_report(f)
|
|
|
|
assert_true(find_in_report(f, r.name .. " %(0,0%), Berg"))
|
2010-11-06 05:21:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function test_coordinates_noname_plane()
|
|
|
|
local p = plane.create(0, -3, -3, 7, 7, "")
|
|
|
|
local r = region.create(0, 0, "mountain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
init_reports()
|
2010-11-12 05:11:19 +01:00
|
|
|
write_report(f)
|
|
|
|
assert_true(find_in_report(f, r.name .. " %(0,0%), Berg"))
|
2010-11-06 05:21:49 +01:00
|
|
|
end
|
2010-11-06 06:54:29 +01:00
|
|
|
|
2011-04-24 21:19:34 +02:00
|
|
|
function test_lighthouse()
|
|
|
|
local r = region.create(0, 0, "mountain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
region.create(1, 0, "mountain")
|
|
|
|
region.create(2, 0, "ocean")
|
|
|
|
region.create(0, 1, "firewall")
|
|
|
|
region.create(3, 0, "mountain")
|
|
|
|
region.create(4, 0, "plain")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
local b = building.create(r, "lighthouse")
|
|
|
|
b.size = 100
|
|
|
|
u.building = b
|
|
|
|
u:set_skill("perception", 9)
|
|
|
|
u:add_item("money", 1000)
|
|
|
|
assert_not_nil(b)
|
|
|
|
|
|
|
|
init_reports()
|
|
|
|
write_report(f)
|
|
|
|
assert_true(find_in_report(f, " %(1,0%) %(vom Turm erblickt%)"))
|
|
|
|
assert_true(find_in_report(f, " %(2,0%) %(vom Turm erblickt%)"))
|
|
|
|
assert_true(find_in_report(f, " %(3,0%) %(vom Turm erblickt%)"))
|
|
|
|
|
|
|
|
assert_false(find_in_report(f, " %(0,0%) %(vom Turm erblickt%)"))
|
|
|
|
assert_false(find_in_report(f, " %(0,1%) %(vom Turm erblickt%)"))
|
|
|
|
assert_false(find_in_report(f, " %(4,0%) %(vom Turm erblickt%)"))
|
|
|
|
end
|
|
|
|
|
2011-02-19 15:13:24 +01:00
|
|
|
module("tests.parser", package.seeall, lunit.testcase)
|
2010-11-06 06:54:29 +01:00
|
|
|
|
|
|
|
function setup()
|
2012-06-07 04:29:36 +02:00
|
|
|
eressea.free_game()
|
|
|
|
eressea.write_game("free.dat")
|
|
|
|
eressea.settings.set("rules.economy.food", "4") -- FOOD_IS_FREE
|
2010-11-06 06:54:29 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function test_parser()
|
|
|
|
local r = region.create(0, 0, "mountain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
2011-02-27 08:51:17 +01:00
|
|
|
local filename = config.basepath .. "/data/orders.txt"
|
2010-11-06 06:54:29 +01:00
|
|
|
|
|
|
|
local file = io.open(filename, "w+")
|
2011-02-27 08:51:17 +01:00
|
|
|
assert_not_nil(file)
|
2010-11-06 06:54:29 +01:00
|
|
|
file:write('ERESSEA ' .. itoa36(f.id) .. ' "' .. f.password .. '"\n')
|
|
|
|
file:write('EINHEIT ' .. itoa36(u.id) .. "\n")
|
2012-06-07 04:29:36 +02:00
|
|
|
file:write("BENENNEN EINHEIT 'Goldene Herde'\n")
|
2010-11-06 06:54:29 +01:00
|
|
|
file:close()
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
eressea.read_orders(filename)
|
2010-11-06 06:54:29 +01:00
|
|
|
process_orders()
|
2012-06-07 04:29:36 +02:00
|
|
|
assert_equal("Goldene Herde", u.name)
|
2010-11-06 06:54:29 +01:00
|
|
|
end
|
|
|
|
|
2012-06-07 20:59:26 +02:00
|
|
|
function test_bug_1922()
|
|
|
|
-- see http://bugs.eressea.de/view.php?id=1922
|
|
|
|
local r = region.create(0, 0, "ocean")
|
|
|
|
local r2 = region.create(1, 0, "plain")
|
|
|
|
r2:set_flag(2) -- region should not be accessible
|
|
|
|
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
|
|
|
|
local s = _test_create_ship(r)
|
|
|
|
|
2012-06-07 04:29:36 +02:00
|
|
|
eressea.settings.set("rules.ship.drifting","0") -- ships are not drifting
|
|
|
|
eressea.settings.set("rules.economy.food","4") -- does not need silver
|
2012-06-07 20:59:26 +02:00
|
|
|
|
|
|
|
u.ship = s
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("NACH O")
|
|
|
|
u:set_skill("sailing",120) -- supadupa captain able to drive a trireme
|
|
|
|
process_orders()
|
2012-06-09 09:18:17 +02:00
|
|
|
assert_not_equal(r2.id, u.region.id) -- unit should not reach r2.
|
2012-06-07 20:59:26 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function test_bug_1922_by_foot()
|
|
|
|
-- see http://bugs.eressea.de/view.php?id=1922
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
local r2 = region.create(1, 0, "plain")
|
|
|
|
r2:set_flag(2) -- region should not be accessible
|
|
|
|
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
|
2012-06-07 04:29:36 +02:00
|
|
|
eressea.settings.set("rules.economy.food","4") -- does not need silver
|
2012-06-07 20:59:26 +02:00
|
|
|
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("NACH O")
|
|
|
|
|
|
|
|
process_orders()
|
2012-06-09 09:18:17 +02:00
|
|
|
assert_not_equal(r2.id, u.region.id) -- unit should not reach r2.
|
2012-06-07 20:59:26 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2010-11-06 06:54:29 +01:00
|
|
|
function test_bug_1814()
|
|
|
|
-- see http://bugs.eressea.de/view.php?id=1814
|
|
|
|
local r = region.create(0, 0, "mountain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
2011-02-27 08:51:17 +01:00
|
|
|
local filename = config.basepath .. "/data/1814.txt"
|
2010-11-06 06:54:29 +01:00
|
|
|
|
|
|
|
local file = io.open(filename, "w+")
|
|
|
|
file:write('ERESSEA ' .. itoa36(f.id) .. ' "' .. f.password .. '"\n')
|
|
|
|
file:write('EINHEIT ' .. itoa36(u.id) .. "\n")
|
|
|
|
file:write("; parse error follows: '\n")
|
|
|
|
file:write("; ARBEITE\n")
|
|
|
|
file:close()
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
eressea.read_orders(filename)
|
2010-11-06 06:54:29 +01:00
|
|
|
process_orders()
|
|
|
|
init_reports()
|
2010-11-12 05:11:19 +01:00
|
|
|
write_report(f)
|
2010-11-06 06:54:29 +01:00
|
|
|
assert_false(find_in_report(f, "Der Befehl wurde nicht erkannt", "cr"))
|
|
|
|
end
|
2010-11-12 05:11:19 +01:00
|
|
|
|
|
|
|
function test_bug_1679()
|
|
|
|
-- see http://bugs.eressea.de/view.php?id=1679
|
|
|
|
local r = region.create(0, 0, "mountain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
2011-02-27 08:51:17 +01:00
|
|
|
local filename = config.basepath .. "/data/1679.txt"
|
2010-11-12 05:11:19 +01:00
|
|
|
|
|
|
|
local file = io.open(filename, "w+")
|
|
|
|
file:write('ERESSEA ' .. itoa36(f.id) .. ' "' .. f.password .. '"\n')
|
|
|
|
file:write('EINHEIT ' .. itoa36(u.id) .. "\n")
|
|
|
|
file:write("NACH W\n")
|
|
|
|
file:write("ARBEITEN\n")
|
|
|
|
file:close()
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
eressea.read_orders(filename)
|
2010-11-12 05:11:19 +01:00
|
|
|
process_orders()
|
|
|
|
init_reports()
|
|
|
|
write_report(f)
|
|
|
|
assert_true(find_in_report(f, "Die Einheit kann keine weiteren langen Befehle", "cr"))
|
|
|
|
assert_true(find_in_report(f, "entdeckt, dass es keinen Weg nach Westen gibt"))
|
|
|
|
end
|
2011-02-06 08:41:14 +01:00
|
|
|
|
2011-03-09 00:25:51 +01:00
|
|
|
function test_building_unique0()
|
|
|
|
local r = region.create(0, 0, "mountain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 20)
|
|
|
|
local f2 = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u2 = unit.create(f2, r, 20)
|
|
|
|
local utype = _test_unique_btype()
|
|
|
|
|
2011-03-09 06:06:38 +01:00
|
|
|
if utype ~= nil then
|
2011-03-09 00:25:51 +01:00
|
|
|
assert_equal("harbour", utype)
|
|
|
|
u:set_skill("building", 20)
|
|
|
|
u:add_item("log", 10000)
|
|
|
|
u:add_item("iron", 10000)
|
|
|
|
u:add_item("stone", 10000)
|
|
|
|
u:add_item("money", 10000)
|
|
|
|
u2:set_skill("building", 20)
|
|
|
|
u2:add_item("log", 10000)
|
|
|
|
u2:add_item("iron", 10000)
|
|
|
|
u2:add_item("stone", 10000)
|
|
|
|
u2:add_item("money", 10000)
|
|
|
|
|
|
|
|
-- build two harbours in one go
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("MACHEN ".. translate(utype))
|
|
|
|
u2:clear_orders()
|
|
|
|
u2:add_order("MACHEN ".. translate(utype))
|
|
|
|
process_orders()
|
|
|
|
assert_not_nil(r.buildings)
|
|
|
|
bcount = 0
|
|
|
|
for bs in r.buildings do
|
|
|
|
assert_equal(1, string.find(bs.name, translate(utype)))
|
2011-03-09 06:06:38 +01:00
|
|
|
if bs.size >= config.get_building(utype).maxsize then
|
2011-03-09 00:25:51 +01:00
|
|
|
bcount = bcount + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
assert_equal(1, bcount) -- only one should be completed
|
|
|
|
else
|
|
|
|
-- fail() -- no unique building in rules
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_building_unique()
|
|
|
|
local r = region.create(0, 0, "mountain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, r, 20)
|
|
|
|
local f2 = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u2 = unit.create(f2, r, 20)
|
|
|
|
local utype = _test_unique_btype()
|
|
|
|
|
2011-03-09 06:06:38 +01:00
|
|
|
if utype ~= nil then
|
2011-03-09 00:25:51 +01:00
|
|
|
u:set_skill("building", 20)
|
|
|
|
u:add_item("log", 10000)
|
|
|
|
u:add_item("iron", 10000)
|
|
|
|
u:add_item("stone", 10000)
|
|
|
|
u:add_item("money", 10000)
|
|
|
|
u2:set_skill("building", 20)
|
|
|
|
u2:add_item("log", 10000)
|
|
|
|
u2:add_item("iron", 10000)
|
|
|
|
u2:add_item("stone", 10000)
|
|
|
|
u2:add_item("money", 10000)
|
|
|
|
|
|
|
|
-- start building two harbours
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("MACHEN 1 Hafen")
|
|
|
|
u2:clear_orders()
|
|
|
|
u2:add_order("MACHEN 1 Hafen")
|
|
|
|
process_orders()
|
|
|
|
-- finish building partial harbours
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("MACHEN ".. translate("harbour"))
|
|
|
|
u2:clear_orders()
|
|
|
|
u2:add_order("MACHEN Hafen")
|
|
|
|
process_orders()
|
2011-03-09 06:06:38 +01:00
|
|
|
if r.buildings == nil then
|
|
|
|
process_orders()
|
2011-03-09 00:25:51 +01:00
|
|
|
end
|
|
|
|
assert_not_nil(r.buildings)
|
|
|
|
bcount = 0
|
|
|
|
local h1 = nil
|
|
|
|
for bs in r.buildings do
|
2011-03-09 06:06:38 +01:00
|
|
|
if h1 == nil then
|
2011-03-09 00:25:51 +01:00
|
|
|
h1 = bs.name
|
|
|
|
else
|
|
|
|
assert_equal(h1, bs.name)
|
|
|
|
end
|
|
|
|
assert_equal(1, string.find(bs.name, "Hafen"))
|
2011-03-09 14:44:31 +01:00
|
|
|
if bs.size >= config.get_building(utype).maxsize then
|
2011-03-09 00:25:51 +01:00
|
|
|
bcount = bcount + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
assert_equal(1, bcount) -- only one should be completed
|
|
|
|
end
|
|
|
|
end
|
2012-06-09 00:13:13 +02:00
|
|
|
|
|
|
|
function test_bug_1875_use_normal()
|
|
|
|
-- see http://bugs.eressea.de/view.php?id=1875
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
r:set_resource("peasant", 0)
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
eressea.settings.set("rules.economy.food", "0") -- food is not free
|
2012-06-09 00:13:13 +02:00
|
|
|
|
|
|
|
local f = faction.create("noreply@eressea.de", "demon", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
|
|
|
|
u:add_item("peasantblood", 1)
|
|
|
|
u:add_order("BENUTZE 1 Bauernblut")
|
|
|
|
|
|
|
|
assert_equal(1, u:get_item("peasantblood"))
|
|
|
|
assert_equal(0, u:get_potion("peasantblood"))
|
|
|
|
|
|
|
|
process_orders()
|
|
|
|
|
|
|
|
assert_equal(0, u:get_item("peasantblood"))
|
|
|
|
assert_equal(0, r:get_resource("peasant"))
|
|
|
|
assert_equal(99, u:get_potion("peasantblood")) -- unit used one peasantblood effect
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_bug_1875_use_help()
|
|
|
|
-- see http://bugs.eressea.de/view.php?id=1875
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
r:set_resource("peasant", 0)
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
eressea.settings.set("rules.economy.food", "0") -- food is not free
|
2012-06-09 00:13:13 +02:00
|
|
|
|
|
|
|
local f = faction.create("noreply@eressea.de", "demon", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
local u2 = unit.create(f, r, 1)
|
|
|
|
|
|
|
|
u:add_item("peasantblood", 1)
|
|
|
|
u:add_order("BENUTZE 1 Bauernblut")
|
|
|
|
|
|
|
|
assert_equal(1, u:get_item("peasantblood"))
|
|
|
|
assert_equal(0, u:get_potion("peasantblood"))
|
|
|
|
assert_equal(0, u2:get_item("peasantblood"))
|
|
|
|
assert_equal(0, u2:get_potion("peasantblood"))
|
|
|
|
|
|
|
|
process_orders()
|
|
|
|
|
|
|
|
assert_equal(0, u:get_item("peasantblood"))
|
|
|
|
assert_equal(0, r:get_resource("peasant"))
|
|
|
|
assert_equal(0, u2:get_potion("peasantblood")) -- first unit helps this unit
|
|
|
|
assert_equal(98, u:get_potion("peasantblood")) -- unit uses one peasantblood effect
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_bug_1875_use_own_first()
|
|
|
|
-- see http://bugs.eressea.de/view.php?id=1875
|
|
|
|
local r = region.create(0, 0, "plain")
|
|
|
|
r:set_resource("peasant", 0)
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
eressea.settings.set("rules.economy.food", "0") -- food is not free
|
2012-06-09 00:13:13 +02:00
|
|
|
|
|
|
|
local f = faction.create("noreply@eressea.de", "demon", "de")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
local u2 = unit.create(f, r, 1)
|
|
|
|
|
|
|
|
u:add_item("peasantblood", 1)
|
|
|
|
u:add_order("BENUTZE 1 Bauernblut")
|
|
|
|
u2:add_item("peasantblood", 1)
|
|
|
|
u2:add_order("BENUTZE 1 Bauernblut")
|
|
|
|
|
|
|
|
assert_equal(1, u:get_item("peasantblood"))
|
|
|
|
assert_equal(0, u:get_potion("peasantblood"))
|
|
|
|
assert_equal(1, u2:get_item("peasantblood"))
|
|
|
|
assert_equal(0, u2:get_potion("peasantblood"))
|
|
|
|
|
|
|
|
process_orders()
|
|
|
|
|
|
|
|
assert_equal(0, u:get_item("peasantblood"))
|
|
|
|
assert_equal(0, r:get_resource("peasant"))
|
|
|
|
assert_equal(99, u:get_potion("peasantblood")) -- unit uses one peasantblood effect
|
|
|
|
assert_equal(99, u2:get_potion("peasantblood")) -- u2 uses its own effect before u's
|
|
|
|
end
|