server/tests/movement.lua

118 lines
3.3 KiB
Lua
Raw Normal View History

2014-06-25 23:30:24 +02:00
require "lunit"
module("tests.movement", package.seeall, lunit.testcase)
function setup()
eressea.free_game()
eressea.settings.set("nmr.removenewbie", "0")
eressea.settings.set("nmr.timeout", "0")
eressea.settings.set("rules.ships.storms", "0")
conf = [[{
"races": {
"human" : {
"speed" : 1,
"weight" : 1000,
"capacity" : 1500,
"flags" : [ "walk" ]
},
2014-06-25 23:30:24 +02:00
"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")
local f = faction.create("walk@example.com", "human", "de")
2014-06-25 23:30:24 +02:00
local u = unit.create(f, r1, 1)
u:add_order("NACH O")
process_orders()
assert_equal(r2, u.region)
end
2014-06-27 08:41:07 +02:00
function test_walk_into_ocean_fails()
2014-06-25 23:30:24 +02:00
local r1 = region.create(0, 0, "plain")
local r2 = region.create(1, 0, "ocean")
local f = faction.create("test@example.com", "human", "de")
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")
2014-06-27 08:41:07 +02:00
region.create(2, 0, "plain")
2014-06-25 23:30:24 +02:00
local f = faction.create("test@example.com", "human", "de")
local u = unit.create(f, r1, 1)
u:add_order("NACH O O")
process_orders()
assert_equal(r2, u.region)
end
2014-06-27 08:41:07 +02:00
function test_ride_max_distance()
2014-06-25 23:30:24 +02:00
local r1 = region.create(0, 0, "plain")
2014-06-27 08:41:07 +02:00
local r2 = region.create(2, 0, "plain")
region.create(1, 0, "plain")
region.create(3, 0, "plain")
2014-06-25 23:30:24 +02:00
local f = faction.create("test@example.com", "human", "de")
local u = unit.create(f, r1, 1)
u:add_item("horse", 1)
u:set_skill("riding", 2)
2014-06-27 08:41:07 +02:00
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")
local f = faction.create("test@example.com", "human", "de")
local u = unit.create(f, r1, 3)
u:add_item("horse", 1)
u:set_skill("riding", 2)
2014-06-25 23:30:24 +02:00
u:add_order("NACH O O")
process_orders()
2014-06-27 08:41:07 +02:00
assert_equal(r2, u.region)
2014-06-25 23:30:24 +02:00
end
2014-06-27 08:41:07 +02:00
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")
local f = faction.create("test@example.com", "human", "de")
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