2014-06-14 02:35:43 +02:00
|
|
|
require "lunit"
|
|
|
|
|
|
|
|
module("tests.ships", package.seeall, lunit.testcase)
|
|
|
|
|
|
|
|
function setup()
|
|
|
|
eressea.free_game()
|
|
|
|
eressea.settings.set("nmr.removenewbie", "0")
|
|
|
|
eressea.settings.set("nmr.timeout", "0")
|
2014-06-17 07:19:19 +02:00
|
|
|
eressea.settings.set("rules.ships.storms", "0")
|
2014-06-14 02:35:43 +02:00
|
|
|
conf = [[{
|
|
|
|
"races": {
|
|
|
|
"human" : {},
|
|
|
|
"insect" : {}
|
|
|
|
},
|
|
|
|
"ships" : {
|
2014-06-17 07:19:19 +02:00
|
|
|
"boat" : {
|
|
|
|
"construction" : {
|
|
|
|
"maxsize" : 5
|
|
|
|
},
|
2014-06-18 07:06:54 +02:00
|
|
|
"coasts" : [ "plain" ],
|
2014-06-17 07:19:19 +02:00
|
|
|
"range" : 3
|
|
|
|
}
|
2014-06-14 02:35:43 +02:00
|
|
|
},
|
|
|
|
"buildings" : {
|
|
|
|
"harbour" : {}
|
|
|
|
},
|
|
|
|
"terrains" : {
|
2014-06-18 07:06:54 +02:00
|
|
|
"ocean": { "flags" : [ "sea", "sail" ] },
|
|
|
|
"plain": { "flags" : [ "land", "walk", "sail" ] },
|
|
|
|
"glacier": { "flags" : [ "land", "walk" ] }
|
2014-06-17 07:19:19 +02:00
|
|
|
},
|
|
|
|
"directions" : {
|
|
|
|
"de" : {
|
|
|
|
"east" : "OSTEN",
|
|
|
|
"west" : "WESTEN"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"keywords" : {
|
|
|
|
"de" : {
|
|
|
|
"move" : "NACH"
|
|
|
|
}
|
2014-06-14 02:35:43 +02:00
|
|
|
}
|
|
|
|
}]]
|
|
|
|
|
2014-06-17 17:46:22 +02:00
|
|
|
eressea.config.reset()
|
2014-06-14 02:35:43 +02:00
|
|
|
eressea.config.parse(conf)
|
|
|
|
end
|
|
|
|
|
2014-06-18 07:06:54 +02:00
|
|
|
function test_sail_oceans()
|
2014-06-16 07:17:08 +02:00
|
|
|
local r1 = region.create(0, 0, "ocean")
|
|
|
|
local r2 = region.create(1, 0, "ocean")
|
|
|
|
local f = faction.create("test@example.com", "human", "de")
|
|
|
|
local u = unit.create(f, r1, 1)
|
|
|
|
u.ship = ship.create(r1, "boat")
|
2014-06-17 07:19:19 +02:00
|
|
|
u.ship.size = 5
|
2014-06-16 07:17:08 +02:00
|
|
|
u:set_skill("sailing", 10)
|
|
|
|
u:add_order("NACH O")
|
|
|
|
process_orders()
|
|
|
|
assert_equal(r2, u.region)
|
|
|
|
end
|
|
|
|
|
2014-06-18 07:06:54 +02:00
|
|
|
function test_sail_to_shore()
|
2014-06-14 02:35:43 +02:00
|
|
|
local ocean = region.create(1, 0, "ocean")
|
2014-06-18 07:06:54 +02:00
|
|
|
local shore = region.create(0, 0, "plain")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, ocean, 1)
|
|
|
|
u.ship = ship.create(ocean, "boat")
|
|
|
|
u:set_skill("sailing", 10)
|
|
|
|
u:add_order("NACH W")
|
|
|
|
process_orders()
|
|
|
|
|
|
|
|
assert_equal(shore, u.region)
|
|
|
|
end
|
2014-06-14 02:35:43 +02:00
|
|
|
|
2014-06-18 07:06:54 +02:00
|
|
|
function test_sail_to_forbidden_shore()
|
|
|
|
local ocean = region.create(1, 0, "ocean")
|
|
|
|
local shore = region.create(0, 0, "glacier")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, ocean, 1)
|
|
|
|
u.ship = ship.create(ocean, "boat")
|
|
|
|
u:set_skill("sailing", 10)
|
|
|
|
u:add_order("NACH W")
|
2014-06-14 02:35:43 +02:00
|
|
|
process_orders()
|
|
|
|
|
2014-06-18 07:06:54 +02:00
|
|
|
assert_equal(ocean, u.region)
|
2014-06-14 02:35:43 +02:00
|
|
|
end
|
|
|
|
|
2014-06-18 08:10:55 +02:00
|
|
|
function test_sail_into_harbour()
|
|
|
|
local ocean = region.create(1, 0, "ocean")
|
|
|
|
local shore = region.create(0, 0, "glacier")
|
|
|
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
|
|
|
local u = unit.create(f, ocean, 1)
|
|
|
|
u.name = "Sailor"
|
|
|
|
u.ship = ship.create(ocean, "boat")
|
|
|
|
u:set_skill("sailing", 10)
|
|
|
|
u:add_order("NACH W")
|
|
|
|
local b = building.create(shore, "harbour")
|
|
|
|
assert_not_nil(b)
|
|
|
|
process_orders()
|
2014-06-14 02:35:43 +02:00
|
|
|
|
2014-06-18 08:10:55 +02:00
|
|
|
assert_equal(shore, u.region)
|
|
|
|
end
|