diff --git a/res/e3a/races.xml b/res/e3a/races.xml
index 8b0cfae6d..cbcac8576 100644
--- a/res/e3a/races.xml
+++ b/res/e3a/races.xml
@@ -732,7 +732,7 @@
-
+
@@ -750,7 +750,7 @@
-
+
@@ -767,7 +767,7 @@
-
+
@@ -783,7 +783,7 @@
-
+
@@ -797,7 +797,7 @@
-
+
@@ -812,7 +812,7 @@
-
+
diff --git a/res/eressea/races.xml b/res/eressea/races.xml
index 986e2b85f..69eda9557 100644
--- a/res/eressea/races.xml
+++ b/res/eressea/races.xml
@@ -983,7 +983,7 @@
-
+
@@ -1000,7 +1000,7 @@
-
+
@@ -1016,7 +1016,7 @@
-
+
@@ -1031,7 +1031,7 @@
-
+
@@ -1044,7 +1044,7 @@
-
+
@@ -1058,7 +1058,7 @@
-
+
diff --git a/scripts/tests/e2/e2features.lua b/scripts/tests/e2/e2features.lua
index 1a4047d63..ffe3266e3 100644
--- a/scripts/tests/e2/e2features.lua
+++ b/scripts/tests/e2/e2features.lua
@@ -408,3 +408,19 @@ end
function test_calendar_season_2328()
assert_equal("fall", get_season(1026))
end
+
+function test_give_to_other_okay()
+ -- can give a person to another faction
+ eressea.settings.set("GiveRestriction", "0")
+ local r = region.create(0, 0, "plain")
+ local f1 = faction.create("human")
+ local f2 = faction.create("human")
+
+ local u1 = unit.create(f1, r, 2, "human")
+ local u2 = unit.create(f2, r, 1, "human")
+ u2:add_order("KONTAKTIERE " .. itoa36(u1.id))
+ u1:add_order("GIB " .. itoa36(u2.id) .. " 1 PERSON")
+ process_orders()
+ assert_equal(1, u1.number)
+ assert_equal(2, u2.number)
+end
diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua
index 7fbc0eb95..fd2f0b423 100644
--- a/scripts/tests/e2/init.lua
+++ b/scripts/tests/e2/init.lua
@@ -21,3 +21,4 @@ require 'tests.process'
require 'tests.xmas'
require 'tests.production'
require 'tests.spells'
+require 'tests.undead'
diff --git a/scripts/tests/e3/init.lua b/scripts/tests/e3/init.lua
index fc0586f89..04b7da4a2 100644
--- a/scripts/tests/e3/init.lua
+++ b/scripts/tests/e3/init.lua
@@ -14,3 +14,4 @@ require 'tests.items'
require 'tests.magicbag'
require 'tests.process'
require 'tests.production'
+require 'tests.undead'
diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua
index 7eb2f13a3..92e02f29b 100644
--- a/scripts/tests/e3/rules.lua
+++ b/scripts/tests/e3/rules.lua
@@ -991,3 +991,20 @@ function test_bug2187()
set_rule("rules.food.flags", "4")
end
+
+
+function test_give_to_other_fails()
+ -- E3: cannot give a person to another faction
+ local r = region.create(0, 0, "plain")
+ local f1 = faction.create("human")
+ local f2 = faction.create("human")
+
+ local u1 = unit.create(f1, r, 2, "human")
+ local u2 = unit.create(f2, r, 1, "human")
+ -- u2:add_order("HELFE " .. itoa36(f1.id) .. " GIB")
+ u2:add_order("KONTAKTIERE " .. itoa36(u1.id))
+ u1:add_order("GIB " .. itoa36(u2.id) .. " 1 PERSON")
+ process_orders()
+ assert_equal(2, u1.number)
+ assert_equal(1, u2.number)
+end
diff --git a/scripts/tests/undead.lua b/scripts/tests/undead.lua
new file mode 100644
index 000000000..420709973
--- /dev/null
+++ b/scripts/tests/undead.lua
@@ -0,0 +1,113 @@
+require "lunit"
+
+module("tests.undead", package.seeall, lunit.testcase)
+
+function setup()
+ eressea.free_game()
+ eressea.settings.set("nmr.timeout", "0")
+ eressea.settings.set("NewbieImmunity", "0")
+ eressea.settings.set("rules.food.flags", "4")
+ eressea.settings.set("rules.encounters", "0")
+ eressea.settings.set("rules.peasants.growth", "1")
+ eressea.settings.set("study.random_progress", "0")
+ eressea.settings.set("GiveRestriction", "0")
+end
+
+function test_give_undead_to_self()
+ -- generic undead cannot be given
+ local r = region.create(0, 0, "plain")
+ local f = faction.create("human")
+ local u1 = unit.create(f, r, 2, "undead")
+ local u2 = unit.create(f, r, 1, "undead")
+ u1:add_order("GIB " .. itoa36(u2.id) .. " 1 PERSON")
+ process_orders()
+ assert_equal(2, u1.number)
+ assert_equal(1, u2.number)
+end
+
+function test_give_self_undead_fail()
+ -- disallow giving basic undead units
+ local r = region.create(0, 0, "plain")
+ local f = faction.create("human")
+ local u1 = unit.create(f, r, 2, "undead")
+ local u2 = unit.create(f, r, 1, "undead")
+ u1:add_order("GIB " .. itoa36(u2.id) .. " 1 PERSON")
+ process_orders()
+ assert_equal(2, u1.number)
+ assert_equal(1, u2.number)
+end
+
+local function setup_give_self(race)
+ local r = region.create(0, 0, "plain")
+ local f = faction.create("human")
+ local u1 = unit.create(f, r, 2, race)
+ local u2 = unit.create(f, r, 1, race)
+ u1:add_order("GIB " .. itoa36(u2.id) .. " 1 PERSON")
+ return u1, u2
+end
+
+local function setup_give_other(race)
+ local r = region.create(0, 0, "plain")
+ local f1 = faction.create("human")
+ local f2 = faction.create("human")
+ local u1 = unit.create(f1, r, 2, race)
+ local u2 = unit.create(f2, r, 1, race)
+ u2:add_order("KONTAKTIERE " .. itoa36(u1.id))
+ u1:add_order("GIB " .. itoa36(u2.id) .. " 1 PERSON")
+ return u1, u2
+end
+
+function test_give_other_zombie_fail()
+ u1, u2 = setup_give_other("zombie")
+ process_orders()
+ assert_equal(2, u1.number)
+ assert_equal(1, u2.number)
+end
+
+function test_give_self_zombie_okay()
+ -- allow giving zombie units to own units of same race
+ u1, u2 = setup_give_self("zombie")
+ process_orders()
+ assert_equal(1, u1.number)
+ assert_equal(2, u2.number)
+end
+
+function test_give_self_skeleton_okay()
+ -- allow giving skeleton units to own units of same race
+ u1, u2 = setup_give_self("skeleton")
+ process_orders()
+ assert_equal(1, u1.number)
+ assert_equal(2, u2.number)
+end
+
+function test_give_self_ghoul_okay()
+ -- allow giving ghoul units to own units of same race
+ u1, u2 = setup_give_self("ghoul")
+ process_orders()
+ assert_equal(1, u1.number)
+ assert_equal(2, u2.number)
+end
+
+function test_give_self_ghast_okay()
+ -- allow giving ghast units to own units of same race
+ u1, u2 = setup_give_self("ghast")
+ process_orders()
+ assert_equal(1, u1.number)
+ assert_equal(2, u2.number)
+end
+
+function test_give_self_juju_okay()
+ -- allow giving juju units to own units of same race
+ u1, u2 = setup_give_self("juju")
+ process_orders()
+ assert_equal(1, u1.number)
+ assert_equal(2, u2.number)
+end
+
+function test_give_self_skeletonlord_okay()
+ -- allow giving skeletonlord units to own units of same race
+ u1, u2 = setup_give_self("skeletonlord")
+ process_orders()
+ assert_equal(1, u1.number)
+ assert_equal(2, u2.number)
+end