]> granicus.if.org Git - nethack/commitdiff
Fix checking monster moving into a trap return value
authorPasi Kallinen <paxed@alt.org>
Fri, 4 Mar 2022 14:42:11 +0000 (16:42 +0200)
committerPasi Kallinen <paxed@alt.org>
Fri, 4 Mar 2022 14:42:15 +0000 (16:42 +0200)
When I added a new trap return value, this was one place that
should've checked it.

This was really annoying to debug - it manifested as a temp level
file loading error, because a monster moved on to a level teleport
trap, which zeroes out (mx, my), then later in the monster movement,
a web spinner created a web at (0,0), and then hero leaving the level,
the traps were saved into the level file ... and when loaded, the code
thought a trap with x == 0 meant there were no more traps.

src/monmove.c

index f0ead084e00bcd6245c090b15f4902149337bdc9..9b5803123e98ca6cd0f1647b754ea25e643e59e4 100644 (file)
@@ -1441,6 +1441,8 @@ m_move(register struct monst* mtmp, register int after)
                 didseeit = canseeit;
 
         if (mmoved == MMOVE_MOVED) {
+            int trapret;
+
             /* normal monster move will already have <nix,niy>,
                but pet dog_move() with 'goto postmov' won't */
             nix = mtmp->mx, niy = mtmp->my;
@@ -1475,7 +1477,8 @@ m_move(register struct monst* mtmp, register int after)
             }
 
             newsym(omx, omy); /* update the old position */
-            if (mintrap(mtmp, NO_TRAP_FLAGS) == Trap_Killed_Mon) {
+            trapret = mintrap(mtmp, NO_TRAP_FLAGS);
+            if (trapret == Trap_Killed_Mon || trapret == Trap_Moved_Mon) {
                 if (mtmp->mx)
                     newsym(mtmp->mx, mtmp->my);
                 return 2; /* it died */