From a713779f3482ef64933aec97714c87018e1a07ba Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Sun, 21 Mar 2021 14:25:42 +0100 Subject: [PATCH] Gesang der Verwirrung bringt Buchhaltung durcheinander --- scripts/tests/spells.lua | 58 ++++++++++++++++++++++++++++++++++++++++ src/battle.c | 6 ++--- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/scripts/tests/spells.lua b/scripts/tests/spells.lua index d72851017..665776057 100644 --- a/scripts/tests/spells.lua +++ b/scripts/tests/spells.lua @@ -138,3 +138,61 @@ function test_appeasement_break_guard() assert_equal(5, u2.status) assert_equal(false, u2.guard) end + +local function create_cp_mage(f, r) + local u2 = unit.create(f, r, 1) + u2.race = 'human' + u2.magic = 'cerddor' + u2:set_skill('magic', 20) + u2.aura = 100 + u2:add_spell('song_of_confusion') + u2:add_spell('frighten') + u2.status = 3 + return u2 +end + +local function create_cp_front(f, r) + local u2 = unit.create(f, r, 1000) + u2:set_skill('melee', 20) + u2:set_skill('stamina', 3) + u2:add_item('axe', u2.number) + u2:add_item('plate', u2.number) + u2:add_item('shield', u2.number) + u2.hp = u2.hp_max * u2.number + return u2 +end + +function test_confusion_and_panic() + f = faction.create('demon', "confusion@eressea.de", "de") + f2 = faction.create('demon') + for y = 1, 10 do + local u1, u2, u3, u4, r + r = region.create(0, 2*y, 'plain') + u1 = create_cp_front(f, r) + u2 = create_cp_mage(f, r) + u3 = create_cp_mage(f, r) + u2:add_order('KAMPFZAUBER STUFE 10 "Gesang der Angst"') + u3:add_order('KAMPFZAUBER STUFE 10 "Gesang der Verwirrung"') + create_cp_mage(f, r) + + local u4 = create_cp_front(f2, r) + create_cp_mage(f2, r) + create_cp_mage(f2, r) + create_cp_mage(f2, r) + + for ux in r.units do + for uy in r.units do + if ux.faction ~= uy.faction then + ux:add_order("ATTACKIERE " .. itoa36(uy.id)) + end + end + end + end + for i = 1,10 do + process_orders() + end + + -- should not produce "select_enemies has a bug" +-- init_reports() +-- write_reports() +end diff --git a/src/battle.c b/src/battle.c index 9ce60200f..e5f8ce38f 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1425,7 +1425,7 @@ count_enemies(battle * b, const fighter * af, int minrow, int maxrow, int sr = statusrow(af->status); side *as = af->side; - if (b->alive == b->fast.alive && as == b->fast.side && sr == b->fast.status + /*if (b->alive == b->fast.alive && as == b->fast.side && sr == b->fast.status && minrow == b->fast.minrow && maxrow == b->fast.maxrow) { if (b->fast.enemies[select] >= 0) { return b->fast.enemies[select]; @@ -1436,7 +1436,7 @@ count_enemies(battle * b, const fighter * af, int minrow, int maxrow, } } } - else if (select != SELECT_FIND || b->alive != b->fast.alive) { + else*/ if (select != SELECT_FIND || b->alive != b->fast.alive) { b->fast.side = as; b->fast.status = sr; b->fast.minrow = minrow; @@ -2437,7 +2437,7 @@ troop select_ally(fighter * af, int minrow, int maxrow, int allytype) dt.fighter = df; return dt; } - allies -= df->alive; + allies -= (df->alive - df->removed); } } }