Merge branch 'stm2-confusion_and_panic' into develop

This commit is contained in:
Enno Rehling 2021-03-24 21:19:06 +01:00
commit 5b1d787102
4 changed files with 61 additions and 64 deletions

View File

@ -334,32 +334,3 @@ function test_astral_disruption_default_level()
assert_nil(r5:get_curse("astralblock"))
assert_equal(r, uh.region)
end
function test_dream_magician_dies()
local u1, u2, r, f, f2
r = region.create(0, 0, 'plain')
f = faction.create('human', "dreamer@eressea.de", "de")
u1 = unit.create(f, r, 1)
u1:set_skill("melee", 1)
u2 = unit.create(f, r, 1)
u2.magic = 'illaun'
u2:set_skill('magic', 20)
u2.aura = 100
u2:add_spell('gooddreams')
u2:add_order('ZAUBERE STUFE 10 "Schöne Träume"')
f2 = faction.create('human')
u3 = unit.create(f2, r, 1000)
assert_equal(1, u1:eff_skill("melee"))
process_orders()
assert_equal(2, u1:eff_skill("melee"))
u2.number = 0
assert_equal(1, u1:eff_skill("melee"))
process_orders()
-- u2 is dead
assert_nil(get_unit(u2.id))
assert_equal(1, u1:eff_skill("melee"))
end

View File

@ -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

View File

@ -878,7 +878,6 @@ void remove_troop(troop dt)
fighter *df = dt.fighter;
struct person p = df->person[dt.index];
battle *b = df->side->battle;
b->fast.alive = -1; /* invalidate cached value */
b->rowcache.alive = -1; /* invalidate cached value */
++df->removed;
++df->side->removed;
@ -1419,35 +1418,11 @@ count_enemies_i(battle * b, const fighter * af, int minrow, int maxrow,
}
int
count_enemies(battle * b, const fighter * af, int minrow, int maxrow,
count_enemies(battle *b, const fighter *af, int minrow, int maxrow,
int select)
{
int sr = statusrow(af->status);
side *as = af->side;
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];
}
else if (select & SELECT_FIND) {
if (b->fast.enemies[select - SELECT_FIND] >= 0) {
return b->fast.enemies[select - SELECT_FIND];
}
}
}
else if (select != SELECT_FIND || b->alive != b->fast.alive) {
b->fast.side = as;
b->fast.status = sr;
b->fast.minrow = minrow;
b->fast.alive = b->alive;
b->fast.maxrow = maxrow;
memset(b->fast.enemies, -1, sizeof(b->fast.enemies));
}
if (maxrow >= FIRST_ROW) {
int i = count_enemies_i(b, af, minrow, maxrow, select);
b->fast.enemies[select] = i;
return i;
return count_enemies_i(b, af, minrow, maxrow, select);
}
return 0;
}
@ -2437,7 +2412,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);
}
}
}

View File

@ -93,13 +93,6 @@ extern "C" {
int row;
int result;
} rowcache;
struct {
struct side *side;
int status;
int alive;
int minrow, maxrow;
int enemies[8];
} fast;
} battle;
typedef struct weapon {