]> granicus.if.org Git - nethack/commitdiff
Fix: lookaround trap detection
authorMichael Meyer <me@entrez.cc>
Thu, 28 Jul 2022 16:04:34 +0000 (12:04 -0400)
committerPasi Kallinen <paxed@alt.org>
Wed, 10 Aug 2022 17:01:22 +0000 (20:01 +0300)
Whether a trap exists is independent on the underlying terrain type, so
putting a check for traps in a block structured like

| if (IS_ROCK(levl[x][y].typ) || levl[x][y].typ == ROOM)
|     ; /* do nothing */
| else if (levl[x][y].typ == CORR)
|     do_corridor();
| else if ((trap = t_at(x, y)))
|     avoid_trap(trap);

would mean that the check for traps only happens on terrain other than
normal room and corridor spots.  As a result, it wasn't being evaluated
in most places where traps might actually occur.

Move the test for traps outside of the terrain type evaluation if/else
series, so that it happens independent of terrain (and remove the
'continue' so it doesn't preclue evaluation of the terrain).

Once the rule actually started coming into play, it became clear the
avoid_moving_on_trap message was being printed in cases where the hero
didn't actually stop (i.e. shift-dir runmode, the "if you must" case),
so I also modified the value for that parameter so it will match the
situations where the hero stops running.

src/hack.c

index 653e8924131fd5952a254f3118214ab4adea64a9..e85939985bff2608ce88367fa625bbc08ba93844 100644 (file)
@@ -3361,6 +3361,14 @@ lookaround(void)
             if (x == u.ux - u.dx && y == u.uy - u.dy)
                 continue;
 
+            /* stop for traps, sometimes */
+            if (avoid_moving_on_trap(x, y, (infront && g.context.run > 1))) {
+                if (g.context.run == 1)
+                    goto bcorr; /* if you must */
+                if (infront)
+                    goto stop;
+            }
+
             /* more uninteresting terrain */
             if (IS_ROCK(levl[x][y].typ) || levl[x][y].typ == ROOM
                 || IS_AIR(levl[x][y].typ) || levl[x][y].typ == ICE) {
@@ -3406,12 +3414,6 @@ lookaround(void)
                     corrct++;
                 }
                 continue;
-            } else if (avoid_moving_on_trap(x, y, infront)) {
-                if (g.context.run == 1)
-                    goto bcorr; /* if you must */
-                if (infront)
-                    goto stop;
-                continue;
             } else if (is_pool_or_lava(x, y)) {
                 if (infront && avoid_moving_on_liquid(x, y, TRUE))
                     goto stop;