From 60efb12d7023c73280d737ebe8f7c2344e751452 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 11 Jun 2017 14:43:46 +0200 Subject: [PATCH 1/3] Zombies koennen Personen gebn --- res/e3a/races.xml | 2 +- res/eressea/races.xml | 2 +- scripts/tests/e2/e2features.lua | 16 ++++++++ scripts/tests/e2/init.lua | 1 + scripts/tests/e3/init.lua | 1 + scripts/tests/e3/rules.lua | 17 +++++++++ scripts/tests/undead.lua | 66 +++++++++++++++++++++++++++++++++ 7 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 scripts/tests/undead.lua diff --git a/res/e3a/races.xml b/res/e3a/races.xml index 8b0cfae6d..349b60a09 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -783,7 +783,7 @@ - + diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 986e2b85f..56c0c541b 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -1031,7 +1031,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..1ed94620b --- /dev/null +++ b/scripts/tests/undead.lua @@ -0,0 +1,66 @@ +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 + +function test_give_other_zombie_fail() + -- cannot give undead units 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, "zombie") + local u2 = unit.create(f2, r, 1, "zombie") + u2:add_order("KONTAKTIERE " .. itoa36(u1.id)) + u1:add_order("GIB " .. itoa36(u2.id) .. " 1 PERSON") + -- TODO: Migranten blockieren das derzeit, nicht Untoten-Eigenschaften + process_orders() + assert_equal(2, u1.number) + assert_equal(1, u2.number) +end + +function test_give_self_zombie_okay() + -- allow giving undead units to own units of same race + local r = region.create(0, 0, "plain") + local f = faction.create("human") + local u1 = unit.create(f, r, 2, "zombie") + local u2 = unit.create(f, r, 1, "zombie") + u1:add_order("GIB " .. itoa36(u2.id) .. " 1 PERSON") + process_orders() + assert_equal(1, u1.number) + assert_equal(2, u2.number) +end From 2107a84b0d47693a84f28399c7fa5f5ee360309c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 9 Jul 2017 15:25:33 +0200 Subject: [PATCH 2/3] also allow GIVE for ghouls and skeletons. --- res/e3a/races.xml | 4 ++-- res/eressea/races.xml | 4 ++-- scripts/tests/undead.lua | 26 +++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/res/e3a/races.xml b/res/e3a/races.xml index 349b60a09..48162aa26 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -750,7 +750,7 @@ - + @@ -812,7 +812,7 @@ - + diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 56c0c541b..2af45fc60 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -1000,7 +1000,7 @@ - + @@ -1058,7 +1058,7 @@ - + diff --git a/scripts/tests/undead.lua b/scripts/tests/undead.lua index 1ed94620b..121701b1e 100644 --- a/scripts/tests/undead.lua +++ b/scripts/tests/undead.lua @@ -54,7 +54,7 @@ function test_give_other_zombie_fail() end function test_give_self_zombie_okay() - -- allow giving undead units to own units of same race + -- allow giving zombie units to own units of same race local r = region.create(0, 0, "plain") local f = faction.create("human") local u1 = unit.create(f, r, 2, "zombie") @@ -64,3 +64,27 @@ function test_give_self_zombie_okay() 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 + local r = region.create(0, 0, "plain") + local f = faction.create("human") + local u1 = unit.create(f, r, 2, "skeleton") + local u2 = unit.create(f, r, 1, "skeleton") + u1:add_order("GIB " .. itoa36(u2.id) .. " 1 PERSON") + 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 + local r = region.create(0, 0, "plain") + local f = faction.create("human") + local u1 = unit.create(f, r, 2, "ghoul") + local u2 = unit.create(f, r, 1, "ghoul") + u1:add_order("GIB " .. itoa36(u2.id) .. " 1 PERSON") + process_orders() + assert_equal(1, u1.number) + assert_equal(2, u2.number) +end From 8344f41a709a0b3c67795a631d19c0af3c9363a3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 15 Jul 2017 12:28:26 +0200 Subject: [PATCH 3/3] allow GIVE for juju, ghast, skelord, too. make the tests nicer. --- res/e3a/races.xml | 6 ++-- res/eressea/races.xml | 6 ++-- scripts/tests/undead.lua | 65 +++++++++++++++++++++++++++------------- 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/res/e3a/races.xml b/res/e3a/races.xml index 48162aa26..cbcac8576 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -732,7 +732,7 @@ - + @@ -767,7 +767,7 @@ - + @@ -797,7 +797,7 @@ - + diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 2af45fc60..69eda9557 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -983,7 +983,7 @@ - + @@ -1016,7 +1016,7 @@ - + @@ -1044,7 +1044,7 @@ - + diff --git a/scripts/tests/undead.lua b/scripts/tests/undead.lua index 121701b1e..420709973 100644 --- a/scripts/tests/undead.lua +++ b/scripts/tests/undead.lua @@ -37,17 +37,28 @@ function test_give_self_undead_fail() assert_equal(1, u2.number) end -function test_give_other_zombie_fail() - -- cannot give undead units to another faction +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, "zombie") - local u2 = unit.create(f2, r, 1, "zombie") + 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") - -- TODO: Migranten blockieren das derzeit, nicht Untoten-Eigenschaften + 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) @@ -55,11 +66,7 @@ end function test_give_self_zombie_okay() -- allow giving zombie units to own units of same race - local r = region.create(0, 0, "plain") - local f = faction.create("human") - local u1 = unit.create(f, r, 2, "zombie") - local u2 = unit.create(f, r, 1, "zombie") - u1:add_order("GIB " .. itoa36(u2.id) .. " 1 PERSON") + u1, u2 = setup_give_self("zombie") process_orders() assert_equal(1, u1.number) assert_equal(2, u2.number) @@ -67,11 +74,7 @@ end function test_give_self_skeleton_okay() -- allow giving skeleton units to own units of same race - local r = region.create(0, 0, "plain") - local f = faction.create("human") - local u1 = unit.create(f, r, 2, "skeleton") - local u2 = unit.create(f, r, 1, "skeleton") - u1:add_order("GIB " .. itoa36(u2.id) .. " 1 PERSON") + u1, u2 = setup_give_self("skeleton") process_orders() assert_equal(1, u1.number) assert_equal(2, u2.number) @@ -79,11 +82,31 @@ end function test_give_self_ghoul_okay() -- allow giving ghoul units to own units of same race - local r = region.create(0, 0, "plain") - local f = faction.create("human") - local u1 = unit.create(f, r, 2, "ghoul") - local u2 = unit.create(f, r, 1, "ghoul") - u1:add_order("GIB " .. itoa36(u2.id) .. " 1 PERSON") + 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)