2020-04-19 21:35:48 +02:00
|
|
|
local lunit = require("lunit")
|
|
|
|
if _VERSION >= 'Lua 5.2' then
|
|
|
|
_ENV = module("tests.laws", 'seeall')
|
|
|
|
else
|
|
|
|
module("tests.laws", 'seeall')
|
|
|
|
end
|
2015-06-19 13:17:01 +02:00
|
|
|
|
|
|
|
function setup()
|
|
|
|
eressea.free_game()
|
|
|
|
conf = [[{
|
|
|
|
"races": {
|
2018-05-10 22:20:28 +02:00
|
|
|
"human" : { "flags" : [ "player" ] }
|
2015-06-19 13:17:01 +02:00
|
|
|
},
|
|
|
|
"terrains" : {
|
|
|
|
"plain": { "flags" : [ "land", "walk", "sail" ] }
|
|
|
|
},
|
|
|
|
"keywords" : {
|
|
|
|
"de": {
|
|
|
|
"attack" : "ATTACKIERE",
|
|
|
|
"maketemp" : "MACHETEMP",
|
|
|
|
"end" : "ENDE",
|
2017-03-25 10:37:13 +01:00
|
|
|
"use" : "BENUTZEN",
|
2015-06-19 13:17:01 +02:00
|
|
|
"recruit" : "REKRUTIERE"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"buildings" : {
|
|
|
|
"castle" : {}
|
|
|
|
}
|
|
|
|
}]]
|
|
|
|
|
|
|
|
eressea.config.reset()
|
|
|
|
eressea.config.parse(conf)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_force_leave_on()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f1 = faction.create("human", "owner@eressea.de")
|
|
|
|
local f2 = faction.create("human", "guest@eressea.de")
|
2015-06-19 13:17:01 +02:00
|
|
|
local u1 = unit.create(f1, r, 1)
|
|
|
|
local u2 = unit.create(f2, r, 1)
|
|
|
|
local b1 = building.create(r, "castle")
|
|
|
|
u1.building = b1
|
|
|
|
u2.building = b1
|
|
|
|
eressea.settings.set("rules.owners.force_leave", "2")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(b1, u1.building)
|
|
|
|
assert_equal(nil, u2.building)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_force_leave_off()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f1 = faction.create("human", "owner@eressea.de")
|
|
|
|
local f2 = faction.create("human", "guest@eressea.de")
|
2015-06-19 13:17:01 +02:00
|
|
|
local u1 = unit.create(f1, r, 1)
|
|
|
|
local u2 = unit.create(f2, r, 1)
|
|
|
|
local b1 = building.create(r, "castle")
|
|
|
|
u1.building = b1
|
|
|
|
u2.building = b1
|
|
|
|
eressea.settings.set("rules.owners.force_leave", "0")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(b1, u1.building)
|
|
|
|
assert_equal(b1, u2.building)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_make_temp()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2018-05-10 22:20:28 +02:00
|
|
|
local f1 = faction.create("human", "temp@eressea.de", "de")
|
2015-06-19 13:17:01 +02:00
|
|
|
local u1 = unit.create(f1, r, 10)
|
|
|
|
local u, u2
|
|
|
|
|
|
|
|
u1.building = building.create(r, "castle")
|
|
|
|
u1.status = 1
|
|
|
|
u1:clear_orders()
|
|
|
|
u1:add_order("MACHETEMP 1 Hodor")
|
|
|
|
u1:add_order("REKRUTIERE 1")
|
|
|
|
u1:add_order("ENDE")
|
|
|
|
process_orders()
|
|
|
|
for u in r.units do
|
|
|
|
if u~=u1 then
|
|
|
|
u2 = u
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
assert_not_equal(nil, u2)
|
|
|
|
assert_not_equal(nil, u2.building)
|
|
|
|
assert_equal(1, u2.number)
|
|
|
|
assert_equal(1, u2.status)
|
|
|
|
assert_equal("Hodor", u2.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_force_leave_postcombat()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f1 = faction.create("human", "owner@eressea.de", "de")
|
|
|
|
local f2 = faction.create("human", "guest@eressea.de", "de")
|
2015-06-19 13:17:01 +02:00
|
|
|
local u1 = unit.create(f1, r, 10)
|
|
|
|
local u2 = unit.create(f2, r, 10)
|
|
|
|
local u, u3
|
|
|
|
local b1 = building.create(r, "castle")
|
|
|
|
u1.building = b1
|
|
|
|
u2.building = b1
|
|
|
|
eressea.settings.set("rules.owners.force_leave", "1")
|
2017-01-23 21:35:01 +01:00
|
|
|
eressea.settings.set("NewbieImmunity", "0")
|
2015-06-19 13:17:01 +02:00
|
|
|
u1:clear_orders()
|
|
|
|
u1:add_order("ATTACKIERE " .. itoa36(u2.id))
|
|
|
|
u2:clear_orders()
|
|
|
|
u2:add_order("MACHETEMP 2 Hodor")
|
|
|
|
u2:add_order("REKRUTIERE 1")
|
|
|
|
u2:add_order("ENDE")
|
|
|
|
process_orders()
|
|
|
|
for u in r.units do
|
|
|
|
if u~=u1 and u~=u2 then
|
|
|
|
u3 = u
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
assert_not_equal(nil, u3)
|
2017-01-23 21:35:01 +01:00
|
|
|
assert_equal(nil, u2.building)
|
2015-06-19 13:17:01 +02:00
|
|
|
assert_equal(nil, u3.building)
|
|
|
|
assert_equal(1, u3.number)
|
|
|
|
end
|
2020-04-19 21:35:48 +02:00
|
|
|
|