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.
This commit is contained in:
Michael Meyer
2022-07-28 12:04:34 -04:00
committed by Pasi Kallinen
parent ce0107aff9
commit 94e8141c01

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