diff --git a/res/config-example.xml b/res/config-example.xml
index 18ce55011..8a298e716 100644
--- a/res/config-example.xml
+++ b/res/config-example.xml
@@ -13,7 +13,8 @@
-
+
+
diff --git a/scripts/example/modules.lua b/scripts/example/modules.lua
index 9d62abb01..81b285902 100644
--- a/scripts/example/modules.lua
+++ b/scripts/example/modules.lua
@@ -2,6 +2,7 @@ require "example.rules"
local srcpath = config.source_dir
tests = {
+ srcpath .. '/example/scripts/tests/rules.lua',
srcpath .. '/shared/scripts/tests/common.lua',
srcpath .. '/shared/scripts/tests/bson.lua',
}
diff --git a/scripts/tests/rules.lua b/scripts/tests/rules.lua
new file mode 100644
index 000000000..1ddb6d1fc
--- /dev/null
+++ b/scripts/tests/rules.lua
@@ -0,0 +1,98 @@
+require "lunit"
+
+module("tests.rules", package.seeall, lunit.testcase)
+
+function setup()
+ free_game()
+ settings.set("nmr.removenewbie", "0")
+ settings.set("nmr.timeout", "0")
+ settings.set("NewbieImmunity", "0")
+end
+
+function test_landing1()
+ local ocean = region.create(1, 0, "ocean")
+ local r = region.create(0, 0, "plain")
+ local f = faction.create("noreply@eressea.de", "insects", "de")
+ local f2 = faction.create("noreply@eressea.de", "human", "de")
+ local s = ship.create(ocean, "longboat")
+ local u1 = unit.create(f, ocean, 1)
+ local u2 = unit.create(f2, r, 1)
+ assert_not_nil(u2)
+ u1:add_item("money", 1000)
+ u2:add_item("money", 1000)
+
+ u1.ship = s
+ u1:set_skill("sailing", 10)
+ u1:clear_orders()
+ u1:add_order("NACH w")
+ process_orders()
+
+ assert_equal(r.id, u1.region.id) -- the plain case: okay
+end
+
+function test_landing2()
+ local ocean = region.create(1, 0, "ocean")
+ local r = region.create(0, 0, "glacier")
+ local harbour = building.create(r, "harbour")
+ harbour.size = 25
+ local f = faction.create("noreply@eressea.de", "human", "de")
+ local f2 = faction.create("noreply@eressea.de", "human", "de")
+ local s = ship.create(ocean, "longboat")
+ local u1 = unit.create(f, ocean, 1)
+ local u2 = unit.create(f2, r, 1)
+ assert_not_nil(u2)
+ u1:add_item("money", 1000)
+ u2:add_item("money", 1000)
+
+ u1.ship = s
+ u1:set_skill("sailing", 10)
+ u1:clear_orders()
+ u1:add_order("NACH w")
+ process_orders()
+
+ assert_equal(r.id, u1.region.id) -- glacier with harbour -- okay
+end
+
+function test_landing3()
+ local ocean = region.create(1, 0, "ocean")
+ local r = region.create(0, 0, "glacier")
+ local f = faction.create("noreply@eressea.de", "human", "de")
+ local f2 = faction.create("noreply@eressea.de", "human", "de")
+ local s = ship.create(ocean, "longboat")
+ local u1 = unit.create(f, ocean, 1)
+ local u2 = unit.create(f2, r, 1)
+ assert_not_nil(u2)
+ u1:add_item("money", 1000)
+ u2:add_item("money", 1000)
+
+ u1.ship = s
+ u1:set_skill("sailing", 10)
+ u1:clear_orders()
+ u1:add_order("NACH w")
+ process_orders()
+
+ assert_equal(ocean.id, u1.region.id) -- cannot land in glacier without harbour
+end
+
+function test_landing3()
+ local ocean = region.create(1, 0, "ocean")
+ local r = region.create(0, 0, "glacier")
+ local harbour = building.create(r, "harbour")
+ harbour.size = 25
+ local f = faction.create("noreply@eressea.de", "insects", "de")
+ local f2 = faction.create("noreply@eressea.de", "human", "de")
+ local s = ship.create(ocean, "longboat")
+ local u1 = unit.create(f, ocean, 1)
+ local u2 = unit.create(f2, r, 1)
+ assert_not_nil(u2)
+ u1:add_item("money", 1000)
+ u2:add_item("money", 1000)
+
+ u1.ship = s
+ u1:set_skill("sailing", 10)
+ u1:clear_orders()
+ u1:add_order("NACH w")
+ process_orders()
+
+ assert_equal(ocean.id, u1.region.id) -- insects cannot land in glaciers
+end