Fix freeing monsters not on map

Sometimes we free the monster data, but the monster is not on the
map - usually this happens if the map is full of monsters and a new one
is migrated on the level.

Make m_detach check the monster x coordinate, so it knows not to touch the map
if the monster isn't on it.
This commit is contained in:
Pasi Kallinen
2018-11-17 19:26:49 +02:00
parent a58571a475
commit 878ac24037
3 changed files with 15 additions and 4 deletions

View File

@@ -464,6 +464,7 @@ fail_mon_placement:
}
(void) mkcorpstat(CORPSE, (struct monst *) 0, mtmp->data, xlocale,
ylocale, CORPSTAT_NONE);
mtmp->mx = mtmp->my = -1; /* for mongone, mon is not anywhere */
mongone(mtmp);
}
}

View File

@@ -418,7 +418,8 @@ struct mail_info *info;
/* zip back to starting location */
go_back:
(void) md_rush(md, start.x, start.y);
if (!md_rush(md, start.x, start.y))
md->mx = md->my = -1; /* for mongone, md is not on map */
mongone(md);
/* deliver some classes of messages even if no daemon ever shows up */
give_up:

View File

@@ -1745,6 +1745,8 @@ m_detach(mtmp, mptr)
struct monst *mtmp;
struct permonst *mptr; /* reflects mtmp->data _prior_ to mtmp's death */
{
boolean onmap = (mtmp->mx > -1);
if (mtmp == context.polearm.hitmon)
context.polearm.hitmon = 0;
if (mtmp->mleashed)
@@ -1753,14 +1755,21 @@ struct permonst *mptr; /* reflects mtmp->data _prior_ to mtmp's death */
mtmp->mtrapped = 0;
mtmp->mhp = 0; /* simplify some tests: force mhp to 0 */
relobj(mtmp, 0, FALSE);
remove_monster(mtmp->mx, mtmp->my);
if (onmap) {
if (mtmp->wormno)
remove_worm(mtmp);
else
remove_monster(mtmp->mx, mtmp->my);
}
if (emits_light(mptr))
del_light_source(LS_MONSTER, monst_to_any(mtmp));
if (mtmp->m_ap_type)
seemimic(mtmp);
newsym(mtmp->mx, mtmp->my);
if (onmap)
newsym(mtmp->mx, mtmp->my);
unstuck(mtmp);
fill_pit(mtmp->mx, mtmp->my);
if (onmap)
fill_pit(mtmp->mx, mtmp->my);
if (mtmp->isshk)
shkgone(mtmp);