From 5977ca51b5fa5e4c4ee3cae5bbfc63dd8debaca0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 15 Dec 2017 17:16:00 +0100 Subject: [PATCH] tests for insects, prepare for bug 1841 another test for appeasement, fix guard bug 2389 --- scripts/tests/common.lua | 13 ++++++ scripts/tests/e2/init.lua | 1 + scripts/tests/e2/insects.lua | 83 ++++++++++++++++++++++++++++++++++++ scripts/tests/spells.lua | 30 ++++++++++++- src/spells/combatspells.c | 2 +- 5 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 scripts/tests/e2/insects.lua diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index d0a419109..d76c2cfdf 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -1147,3 +1147,16 @@ function test_route_pause() assert_equal("ROUTE P O W", u:get_order(0)) assert_equal(r1, u.region) end + +function test_bug_2393_cart() + local r1 = region.create(0, 0, "plain") + local r2 = region.create(1, 0, "plain") + local f = faction.create("human", "cart@example.com") + local u = unit.create(f, r1, 2) + u:add_order("NACH O") + u:add_item('stone', 2) + u:add_item('horse', 2) + u:add_item('cart', 1) + process_orders() + assert_equal(r1, u.region) +end diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 222723082..d8d21a5c8 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -1,3 +1,4 @@ +require 'tests.e2.insects' require 'tests.e2.spells' require 'tests.e2.buildings' require 'tests.e2.production' diff --git a/scripts/tests/e2/insects.lua b/scripts/tests/e2/insects.lua new file mode 100644 index 000000000..374bedff8 --- /dev/null +++ b/scripts/tests/e2/insects.lua @@ -0,0 +1,83 @@ +require "lunit" + +module("tests.e2.insects", package.seeall, lunit.testcase) + +function setup() + eressea.free_game() + eressea.settings.set("rules.food.flags", "4") + eressea.settings.set("nmr.timeout", "0") + eressea.settings.set("NewbieImmunity", "0") +end + +function test_move_to_glacier() + local r = region.create(0, 0, "plain") + local r2 = region.create(1, 0, "glacier") + local f = faction.create("insect", "insect@eressea.de", "de") + local u = unit.create(f, r, 1) + + u:clear_orders() + u:add_order("NACH OST") + process_orders() + assert_equal(r, u.region) +end + +function test_sail_into_glacier() + local r = region.create(0, 0, "ocean") + local r2 = region.create(1, 0, "glacier") + local f = faction.create("insect", "insect@eressea.de", "de") + local u1 = unit.create(f, r, 1, 'human') + local u2 = unit.create(f, r, 1, 'insect') + + u1.ship = ship.create(r, 'boat') + u1:set_skill("sailing", 10) + u1:clear_orders() + u1:add_order("NACH OST") + u2.ship = u1.ship + process_orders() + assert_equal(r, u2.region) +end + +function test_recruit_in_winter() + local r = region.create(0, 0, "plain") + local f = faction.create("insect", "insect@eressea.de", "de") + local u = unit.create(f, r, 1) + + u:add_item('money', 1000) + u:clear_orders() + u:add_order("REKRUTIERE 1") + set_turn(1010) + process_orders() + assert_equal('winter', get_season(get_turn())) + assert_equal(1, u.number) + + u:clear_orders() + u:add_order("REKRUTIERE 1") + set_turn(1011) + process_orders() + assert_equal('spring', get_season(get_turn())) + assert_equal(2, u.number) +end + +function test_recruit_in_desert() + local r = region.create(0, 0, "desert") + local f = faction.create("insect", "insect@eressea.de", "de") + local u = unit.create(f, r, 1) + + u:add_item('money', 1000) + u:clear_orders() + u:add_order("REKRUTIERE 1") + set_turn(1010) + process_orders() + assert_equal('winter', get_season(get_turn())) + assert_equal(2, u.number) +end + +function bug_1841_test_hunger_in_glacier() + local r = region.create(0, 0, "glacier") + local f = faction.create("insect", "insect@eressea.de", "de") + local u = unit.create(f, r, 1) + + local flags = u.flags + process_orders() + assert_equal(flags+2048, u.flags) +end diff --git a/scripts/tests/spells.lua b/scripts/tests/spells.lua index 1a8442f2e..de56472c3 100644 --- a/scripts/tests/spells.lua +++ b/scripts/tests/spells.lua @@ -81,7 +81,7 @@ function test_create_dreameye() assert_equal(amax - 5, u.aura_max) end -function test_appeasement() +function test_appeasement_can_move() local u1, u2, r1, r2, uno r1 = region.create(0, 0, 'plain') r2 = region.create(1, 0, 'plain') @@ -102,4 +102,32 @@ function test_appeasement() u2 = get_unit(uno) assert_not_nil(u2) assert_equal(r2, u2.region) + assert_equal(5, u2.status) +end + +function test_appeasement_break_guard() + local u1, u2, r1, r2, uno + r1 = region.create(0, 0, 'plain') + r2 = region.create(1, 0, 'plain') + u2 = unit.create(faction.create('human'), r1, 1) + u2.race = 'elf' + u2.name = 'Angsthase' + u2.magic = 'gwyrrd' + u2.guard = true + u2.status = 1 + u2:set_skill('magic', 5) + u2.aura = 10 + u2:add_spell('appeasement') + u2:add_order('BEWACHE') + u2:add_order('KAMPFZAUBER STUFE 1 Friedenslied') + uno = u2.id + u1 = unit.create(faction.create('human'), r1, 1) + u1:set_skill('polearm', 5) + u1:add_order('ATTACKIERE ' .. itoa36(uno)) + process_orders() + u2 = get_unit(uno) + assert_not_nil(u2) + assert_equal(r1, u2.region) + assert_equal(5, u2.status) + assert_equal(false, u2.guard) end diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 8c139fb9c..688a389cb 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -1279,7 +1279,7 @@ int sp_appeasement(struct castorder * co) } /* und bewachen nicht */ setguard(mage, false); - /* irgendwie den langen befehl sperren */ + setstatus(mage, ST_FLEE); /* wir tun so, als w�re die Person geflohen */ fi->flags |= FIG_NOLOOT;