From b2d981e5778015339d4f29d475c7f6af0245a1a2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 3 Jul 2015 13:04:11 +0200 Subject: [PATCH] improved tests for DESTROY, fix destroy-after-attack --- scripts/tests/e2/destroy.lua | 46 +++++++++++++++++++++++++++++++++++ scripts/tests/e2/init.lua | 1 + scripts/tests/e2/movement.lua | 14 ----------- src/kernel/build.c | 5 ++++ 4 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 scripts/tests/e2/destroy.lua diff --git a/scripts/tests/e2/destroy.lua b/scripts/tests/e2/destroy.lua new file mode 100644 index 000000000..258146941 --- /dev/null +++ b/scripts/tests/e2/destroy.lua @@ -0,0 +1,46 @@ +require "lunit" + +module("tests.e2.destroy", package.seeall, lunit.testcase) + +function setup() + eressea.free_game() + eressea.settings.set("NewbieImmunity", "0") +end + +function test_dont_move_after_destroy() + local r1 = region.create(0, 0, "plain") + local r2 = region.create(1, 0, "plain") + local f = faction.create("test@example.com", "human", "de") + local u = unit.create(f, r1, 1) + u.building = building.create(u.region, "castle") + u:clear_orders() + u:add_order("NACH O") + u:add_order("ZERSTOERE " .. itoa36(u.building.id)) + process_orders() + assert_equal(r1, u.region) + assert_equal(nil, u.building) +end + +function test_dont_destroy_after_attack() + local r1 = region.create(0, 0, "plain") + local u = unit.create(faction.create("one@example.com", "human", "de"), r1, 10) + local u2 = unit.create(faction.create("two@example.com", "human", "de"), r1, 1) + u.building = building.create(u.region, "castle") + u:clear_orders() + u:add_order("ATTACKIERE " .. itoa36(u2.id)) + u:add_order("ZERSTOERE " .. itoa36(u.building.id)) + process_orders() + assert_not_nil(u.building) +end + +function test_destroy_is_long() + local r1 = region.create(0, 0, "plain") + local u = unit.create(faction.create("one@example.com", "human", "de"), r1, 10) + u.building = building.create(u.region, "castle") + u:clear_orders() + u:add_order("LERNE Unterhaltung") + u:add_order("ZERSTOERE " .. itoa36(u.building.id)) + process_orders() + assert_equal(0, u:get_skill("entertainment")) + assert_equal(nil, u.building) +end diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index a1ad73422..32199b257 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -2,6 +2,7 @@ require 'tests.e2.undead' require 'tests.e2.shiplanding' require 'tests.e2.e2features' require 'tests.e2.movement' +require 'tests.e2.destroy' require 'tests.e2.guard' require 'tests.e2.stealth' require 'tests.orders' diff --git a/scripts/tests/e2/movement.lua b/scripts/tests/e2/movement.lua index e05715590..ef62873d8 100644 --- a/scripts/tests/e2/movement.lua +++ b/scripts/tests/e2/movement.lua @@ -84,17 +84,3 @@ function test_follow_ship() assert_equal(2, u1.region.x) assert_equal(2, u2.region.x) end - -function test_dont_move_after_destroy() - local r1 = region.create(0, 0, "plain") - local r2 = region.create(1, 0, "plain") - local f = faction.create("test@example.com", "human", "de") - local u = unit.create(f, r1, 1) - u.building = building.create(r1, "castle") - u:clear_orders() - u:add_order("NACH O") - u:add_order("ZERSTOERE " .. itoa36(u.building.id)) - process_orders() - assert_equal(r1, u.region) - assert_equal(nil, u.building) -end diff --git a/src/kernel/build.c b/src/kernel/build.c index ab8d520d1..fcb116741 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -153,6 +153,11 @@ int destroy_cmd(unit * u, struct order *ord) if (u->number < 1) return 0; + if (fval(u, UFL_LONGACTION)) { + cmistake(u, ord, 52, MSG_PRODUCE); + return 0; + } + init_order(ord); s = gettoken(token, sizeof(token));