From: Pasi Kallinen Date: Mon, 19 Nov 2018 20:38:10 +0000 (+0200) Subject: More monster location sanity checks X-Git-Tag: nmake-explicit-path~157 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b54dda56241f128b11076ffd17d8c211942478da;p=nethack More monster location sanity checks Placing a monster over already existing one will now complain. Define EXTRA_SANITY_CHECKS to check monster removal too. --- diff --git a/include/rm.h b/include/rm.h index 7fd41c47c..93362d67b 100644 --- a/include/rm.h +++ b/include/rm.h @@ -629,8 +629,19 @@ extern dlevel_t level; /* structure describing the current level */ #define MON_BURIED_AT(x, y) \ (level.monsters[x][y] != (struct monst *) 0 \ && (level.monsters[x][y])->mburied) +#if EXTRA_SANITY_CHECKS +#define place_worm_seg(m, x, y) do { \ + if (level.monsters[x][y] && level.monsters[x][y] != m) impossible("place_worm_seg over mon"); \ + level.monsters[x][y] = m; \ + } while(0) +#define remove_monster(x, y) do { \ + if (!level.monsters[x][y]) impossible("no monster to remove"); \ + level.monsters[x][y] = (struct monst *) 0; \ + } while(0) +#else #define place_worm_seg(m, x, y) level.monsters[x][y] = m #define remove_monster(x, y) level.monsters[x][y] = (struct monst *) 0 +#endif #define m_at(x, y) (MON_AT(x, y) ? level.monsters[x][y] : (struct monst *) 0) #define m_buried_at(x, y) \ (MON_BURIED_AT(x, y) ? level.monsters[x][y] : (struct monst *) 0) diff --git a/src/mail.c b/src/mail.c index 6427cf8cd..8e3eec8f7 100644 --- a/src/mail.c +++ b/src/mail.c @@ -336,19 +336,21 @@ register int tx, ty; /* destination of mail daemon */ else if (fx == u.ux && fy == u.uy) verbalize("Excuse me."); + if (mon) + remove_monster(fx, fy); place_monster(md, fx, fy); /* put md down */ newsym(fx, fy); /* see it */ flush_screen(0); /* make sure md shows up */ delay_output(); /* wait a little bit */ /* Remove md from the dungeon. Restore original mon, if necessary. */ + remove_monster(fx, fy); if (mon) { if ((mon->mx != fx) || (mon->my != fy)) place_worm_seg(mon, fx, fy); else place_monster(mon, fx, fy); - } else - remove_monster(fx, fy); + } newsym(fx, fy); } @@ -357,9 +359,11 @@ register int tx, ty; /* destination of mail daemon */ * very unlikely). If one exists, then have the md leave in disgust. */ if ((mon = m_at(fx, fy)) != 0) { + remove_monster(fx, fy); place_monster(md, fx, fy); /* display md with text below */ newsym(fx, fy); verbalize("This place's too crowded. I'm outta here."); + remove_monster(fx, fy); if ((mon->mx != fx) || (mon->my != fy)) /* put mon back */ place_worm_seg(mon, fx, fy); diff --git a/src/mhitm.c b/src/mhitm.c index ba322a8ca..774e9a56e 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -725,6 +725,7 @@ register struct attack *mattk; * but don't leave it on the screen. Move the aggressor to the * defender's position. */ + remove_monster(dx, dy); remove_monster(ax, ay); place_monster(magr, dx, dy); newsym(ax, ay); /* erase old position */ diff --git a/src/save.c b/src/save.c index d7827fcfd..bca03c49e 100644 --- a/src/save.c +++ b/src/save.c @@ -536,6 +536,11 @@ skip_lots: saveobjchn(fd, level.buriedobjlist, mode); saveobjchn(fd, billobjs, mode); if (release_data(mode)) { + int x,y; + + for (y = 0; y < ROWNO; y++) + for (x = 0; x < COLNO; x++) + level.monsters[x][y] = 0; fmon = 0; ftrap = 0; fobj = 0; diff --git a/src/steed.c b/src/steed.c index 6b940c26e..61f252a4c 100644 --- a/src/steed.c +++ b/src/steed.c @@ -704,6 +704,8 @@ int x, y; (mon == u.usteed) ? "steed" : "defunct monster"); return; } + if (level.monsters[x][y]) + impossible("placing monster over another?"); mon->mx = x, mon->my = y; level.monsters[x][y] = mon; } diff --git a/src/worm.c b/src/worm.c index b2bf598dc..4e9d144b1 100644 --- a/src/worm.c +++ b/src/worm.c @@ -383,6 +383,7 @@ struct obj *weap; /* Sometimes the tail end dies. */ if (!new_worm) { + place_worm_seg(worm, x, y); /* place the "head" segment back */ if (context.mon_moving) { if (canspotmon(worm)) pline("Part of %s tail has been cut off.",