From 0b036557c099379526ce41764b02ef0fa858a391 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Jan 2018 18:13:42 +0100 Subject: [PATCH] test that mistletoe users survive attacks. --- scripts/tests/items.lua | 15 ++++++++++++++- src/battle.c | 10 ++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/scripts/tests/items.lua b/scripts/tests/items.lua index fb6a754f5..1e39ee676 100644 --- a/scripts/tests/items.lua +++ b/scripts/tests/items.lua @@ -15,7 +15,6 @@ function test_use_mistletoe() local r = region.create(0, 0, "plain") local f = faction.create("human") local u = unit.create(f, r, 1) - u.name = 'Miraculix' u:add_item('mistletoe', 3) u:add_order("BENUTZEN 2 Mistelzweig") process_orders() @@ -24,6 +23,20 @@ function test_use_mistletoe() assert_equal(1, f:count_msg_type('use_item')) end +function test_mistletoe_survive() + local r = region.create(0, 0, "plain") + local u = unit.create(faction.create("human"), r, 1) + local u2 = unit.create(faction.create("human"), r, 1) + local uno = u.id + u:add_item('mistletoe', 2) + u:add_order("BENUTZEN 2 Mistelzweig") + u2:add_order('ATTACKIERE ' .. itoa36(uno)) + process_orders() + u = get_unit(uno) + assert_not_nil(u) + assert_equal(1, u:effect('mistletoe')) +end + function test_dreameye() local r = region.create(0, 0, "plain") local f = faction.create("human") diff --git a/src/battle.c b/src/battle.c index b0e931214..29dcbaa5b 100644 --- a/src/battle.c +++ b/src/battle.c @@ -142,11 +142,14 @@ static int rule_tactics_formula; static int rule_nat_armor; static int rule_cavalry_mode; static int rule_vampire; +static const item_type *it_mistletoe; /** initialize rules from configuration. */ static void init_rules(void) { + it_mistletoe = it_find("mistletoe"); + rule_nat_armor = config_get_int("rules.combat.nat_armor", 0); rule_tactics_formula = config_get_int("rules.tactics.formula", 0); rule_goblin_bonus = config_get_int("rules.combat.goblinbonus", 10); @@ -3354,11 +3357,10 @@ static int join_battle(battle * b, unit * u, bool attack, fighter ** cp) fighter *fc = NULL; if (!attack && u->attribs) { - const item_type *itype = it_find("mistletoe"); - if (itype) { - int effect = get_effect(u, itype); + if (it_mistletoe) { + int effect = get_effect(u, it_mistletoe); if (effect >= u->number) { - change_effect(u, itype, -u->number); + change_effect(u, it_mistletoe, -u->number); *cp = NULL; return false; }