2020-05-03 16:52:40 +02:00
|
|
|
local tcname = 'tests.movement'
|
2020-04-19 21:35:48 +02:00
|
|
|
local lunit = require("lunit")
|
|
|
|
if _VERSION >= 'Lua 5.2' then
|
2020-05-03 16:52:40 +02:00
|
|
|
_ENV = module(tcname , 'seeall')
|
2020-04-19 21:35:48 +02:00
|
|
|
else
|
2020-05-03 16:52:40 +02:00
|
|
|
module(tcname, lunit.testcase, package.seeall)
|
2020-04-19 21:35:48 +02:00
|
|
|
end
|
2014-08-07 13:19:19 +02:00
|
|
|
|
|
|
|
function setup()
|
|
|
|
eressea.free_game()
|
|
|
|
eressea.settings.set("nmr.timeout", "0")
|
|
|
|
eressea.settings.set("rules.ships.storms", "0")
|
|
|
|
conf = [[{
|
|
|
|
"races": {
|
|
|
|
"human" : {
|
|
|
|
"speed" : 1,
|
|
|
|
"weight" : 1000,
|
|
|
|
"capacity" : 1500,
|
|
|
|
"flags" : [ "walk" ]
|
|
|
|
},
|
|
|
|
"troll" : {}
|
|
|
|
},
|
|
|
|
"items" : {
|
|
|
|
"horse" : {
|
|
|
|
"capacity" : 7000,
|
|
|
|
"weight" : 5000,
|
|
|
|
"flags" : [ "big", "animal" ]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"terrains" : {
|
|
|
|
"ocean": { "flags" : [ "sea", "sail" ] },
|
|
|
|
"plain": { "flags" : [ "land", "walk", "sail" ] },
|
|
|
|
"glacier": { "flags" : [ "land", "walk" ] }
|
|
|
|
},
|
|
|
|
"directions" : {
|
|
|
|
"de" : {
|
|
|
|
"east" : "OSTEN",
|
|
|
|
"west" : "WESTEN"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"keywords" : {
|
|
|
|
"de" : {
|
|
|
|
"move" : "NACH"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}]]
|
|
|
|
|
|
|
|
eressea.config.reset()
|
|
|
|
eressea.config.parse(conf)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_walk_to_land()
|
|
|
|
local r1 = region.create(0, 0, "plain")
|
|
|
|
local r2 = region.create(1, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "walk@example.com", "de")
|
2014-08-07 13:19:19 +02:00
|
|
|
local u = unit.create(f, r1, 1)
|
|
|
|
u:add_order("NACH O")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(r2, u.region)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_walk_into_ocean_fails()
|
|
|
|
local r1 = region.create(0, 0, "plain")
|
|
|
|
local r2 = region.create(1, 0, "ocean")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "test@example.com", "de")
|
2014-08-07 13:19:19 +02:00
|
|
|
local u = unit.create(f, r1, 1)
|
|
|
|
u:add_order("NACH O")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(r1, u.region)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_walk_distance()
|
|
|
|
local r1 = region.create(0, 0, "plain")
|
|
|
|
local r2 = region.create(1, 0, "plain")
|
|
|
|
region.create(2, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "test@example.com", "de")
|
2014-08-07 13:19:19 +02:00
|
|
|
local u = unit.create(f, r1, 1)
|
|
|
|
u:add_order("NACH O O")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(r2, u.region)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_ride_max_distance()
|
|
|
|
local r1 = region.create(0, 0, "plain")
|
|
|
|
local r2 = region.create(2, 0, "plain")
|
|
|
|
region.create(1, 0, "plain")
|
|
|
|
region.create(3, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "test@example.com", "de")
|
2014-08-07 13:19:19 +02:00
|
|
|
local u = unit.create(f, r1, 1)
|
|
|
|
u:add_item("horse", 1)
|
|
|
|
u:set_skill("riding", 2)
|
|
|
|
u:add_order("NACH O O O")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(r2, u.region, "should ride exactly two hexes")
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_ride_over_capacity_leads_horse()
|
|
|
|
local r1 = region.create(0, 0, "plain")
|
|
|
|
local r2 = region.create(1, 0, "plain")
|
|
|
|
region.create(2, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "test@example.com", "de")
|
2014-08-07 13:19:19 +02:00
|
|
|
local u = unit.create(f, r1, 3)
|
|
|
|
u:add_item("horse", 1)
|
|
|
|
u:set_skill("riding", 2)
|
|
|
|
u:add_order("NACH O O")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(r2, u.region)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_ride_no_skill_leads_horse()
|
|
|
|
local r1 = region.create(0, 0, "plain")
|
|
|
|
local r2 = region.create(1, 0, "plain")
|
|
|
|
region.create(2, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "test@example.com", "de")
|
2014-08-07 13:19:19 +02:00
|
|
|
local u = unit.create(f, r1, 1)
|
|
|
|
u:add_item("horse", 1)
|
|
|
|
u:add_order("NACH O O")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(r2, u.region)
|
|
|
|
end
|