More monster location sanity checks

Placing a monster over already existing one will now complain.
Define EXTRA_SANITY_CHECKS to check monster removal too.
This commit is contained in:
Pasi Kallinen
2018-11-19 22:38:10 +02:00
parent 5acddebb3c
commit b54dda5624
6 changed files with 26 additions and 2 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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.",