removing units (versteinern) cleaned up and now invalidates the fast-cache so the assert shouldn't trigger any more.

This commit is contained in:
Enno Rehling 2007-03-04 21:52:13 +00:00
parent e7e0ef994b
commit 07cb8d1fad
3 changed files with 26 additions and 12 deletions

View File

@ -817,7 +817,7 @@ rmfighter(fighter *df, int i)
} }
void static void
rmtroop(troop dt) rmtroop(troop dt)
{ {
fighter *df = dt.fighter; fighter *df = dt.fighter;
@ -835,6 +835,24 @@ rmtroop(troop dt)
void void
remove_troop(troop dt) remove_troop(troop dt)
{
fighter * df = dt.fighter;
struct person p = df->person[dt.index];
battle * b = df->side->battle;
#ifdef FASTCOUNT
b->fast.alive = -1; /* invalidate cached value */
#endif
#ifdef FASTROW
b->rowcache.alive = -1; /* invalidate cached value */
#endif
++df->removed;
++df->side->removed;
df->person[dt.index] = df->person[df->alive-df->removed];
df->person[df->alive - df->removed] = p;
}
void
kill_troop(troop dt)
{ {
fighter * df = dt.fighter; fighter * df = dt.fighter;
unit * du = df->unit; unit * du = df->unit;
@ -1211,7 +1229,7 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile)
if (rng_int() % 4 < 1) i_change(pitm, itype, -1); if (rng_int() % 4 < 1) i_change(pitm, itype, -1);
} }
} }
remove_troop(dt); kill_troop(dt);
return true; return true;
} }
@ -3687,7 +3705,7 @@ flee(const troop dt)
fig->run.hp += fig->person[dt.index].hp; fig->run.hp += fig->person[dt.index].hp;
++fig->run.number; ++fig->run.number;
remove_troop(dt); kill_troop(dt);
} }
#ifdef DELAYED_OFFENSE #ifdef DELAYED_OFFENSE

View File

@ -254,7 +254,8 @@ extern "C" {
extern fighter * make_fighter(struct battle * b, struct unit * u, side * s, boolean attack); extern fighter * make_fighter(struct battle * b, struct unit * u, side * s, boolean attack);
extern int statusrow(int status); extern int statusrow(int status);
extern void drain_exp(struct unit *u, int d); extern void drain_exp(struct unit *u, int d);
extern void rmtroop(troop dt); extern void kill_troop(troop dt);
extern void remove_troop(troop dt); /* not the same as the badly named rmtroop */
extern boolean is_attacker(const fighter * fig); extern boolean is_attacker(const fighter * fig);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -184,16 +184,11 @@ sp_versteinern(fighter * fi, int level, double power, spell * sp)
while (force && stoned < enemies) { while (force && stoned < enemies) {
troop dt = select_enemy(fi, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE); troop dt = select_enemy(fi, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE);
fighter * df = dt.fighter; unit * du = dt.fighter->unit;
unit * du = df->unit;
if (is_magic_resistant(mage, du, 0) == false) { if (is_magic_resistant(mage, du, 0) == false) {
/* person ans ende hinter die lebenden schieben */ /* person ans ende hinter die lebenden schieben */
struct person p = dt.fighter->person[dt.index]; remove_troop(dt);
++dt.fighter->removed;
++dt.fighter->side->removed;
++stoned; ++stoned;
dt.fighter->person[dt.index] = dt.fighter->person[df->alive-df->removed];
dt.fighter->person[(df->alive - df->removed)] = p;
} }
--force; --force;
} }
@ -528,7 +523,7 @@ sp_mindblast(fighter * fi, int level, double power, spell * sp)
reduce_skill(du, sv, n); reduce_skill(du, sv, n);
} else { } else {
/* Keine Skills mehr, Einheit töten */ /* Keine Skills mehr, Einheit töten */
rmtroop(dt); kill_troop(dt);
++killed; ++killed;
} }
--enemies; --enemies;