fix #H7677 - guard placed twice at <0,0>

"Placing monster over another?" warning was triggered for vault guard
by an earlier change which made m_detach() stop removing monsters at
<0,*> from level.monsters[][].  So one guard would replace another at
<0,0> for however many guards were created, and memory for all but
the last one would be lost.

This involved a lot of flailing about and the patch includes various
things would could have been discarded.  One or two extended monster
sanity checks are included, plus a couple of debugpline()'s for
tracking guard movement.
This commit is contained in:
PatR
2018-12-12 01:54:33 -08:00
parent cf89253358
commit 9952049a75
4 changed files with 90 additions and 49 deletions
+21 -8
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mon.c $NHDT-Date: 1543455827 2018/11/29 01:43:47 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.272 $ */
/* NetHack 3.6 mon.c $NHDT-Date: 1544608467 2018/12/12 09:54:27 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.273 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Derek S. Ray, 2015. */
/* NetHack may be freely redistributed. See license for details. */
@@ -48,8 +48,6 @@ struct monst *mtmp;
boolean chk_geno;
const char *msg;
{
if (DEADMONSTER(mtmp))
return;
if (mtmp->data < &mons[LOW_PM] || mtmp->data >= &mons[NUMMONS]) {
impossible("illegal mon data %s; mnum=%d (%s)",
fmt_ptr((genericptr_t) mtmp->data), mtmp->mnum, msg);
@@ -61,6 +59,13 @@ const char *msg;
mtmp->mnum, mndx, msg);
mtmp->mnum = mndx;
}
if (DEADMONSTER(mtmp)) {
/* bad if not fmons list or if not vault guard */
if (strcmp(msg, "fmon") || !mtmp->isgd)
impossible("dead monster on %s; %s at <%d,%d>",
msg, mons[mndx].mname, mtmp->mx, mtmp->my);
return;
}
if (chk_geno && (mvitals[mndx].mvflags & G_GENOD) != 0)
impossible("genocided %s in play (%s)", mons[mndx].mname, msg);
}
@@ -85,8 +90,9 @@ mon_sanity_check()
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
sanity_check_single_mon(mtmp, TRUE, "fmon");
if (DEADMONSTER(mtmp))
if (DEADMONSTER(mtmp) && !mtmp->isgd)
continue;
x = mtmp->mx, y = mtmp->my;
if (!isok(x, y) && !(mtmp->isgd && x == 0 && y == 0)) {
impossible("mon (%s) claims to be at <%d,%d>?",
@@ -713,10 +719,17 @@ movemon()
break;
}
nmtmp = mtmp->nmon;
/* one dead monster needs to perform a move after death:
vault guard whose temporary corridor is still on the map */
if (mtmp->isgd && !mtmp->mx && DEADMONSTER(mtmp))
/* one dead monster needs to perform a move after death: vault
guard whose temporary corridor is still on the map; live
guards who have led the hero back to civilization get moved
off the map too; gd_move() decides whether the temporary
corridor can be removed and guard discarded (via clearing
mon->isgd flag so that dmonsfree() will get rid of mon) */
if (mtmp->isgd && !mtmp->mx) {
/* parked at <0,0>; eventually isgd should get set to false */
(void) gd_move(mtmp);
continue;
}
if (DEADMONSTER(mtmp))
continue;
@@ -1766,7 +1779,7 @@ 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);
if (onmap) {
if (onmap || mtmp == level.monsters[0][0]) {
if (mtmp->wormno)
remove_worm(mtmp);
else