From: Michael Meyer Date: Thu, 28 Jul 2022 16:04:34 +0000 (-0400) Subject: Fix: lookaround trap detection X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=94e8141c01f6ebf5e3beabb2e69e5861d60f0a04;p=nethack Fix: lookaround trap detection 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. --- diff --git a/src/hack.c b/src/hack.c index 653e89241..e85939985 100644 --- a/src/hack.c +++ b/src/hack.c @@ -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;