From 72016b1f1752bc07a6b92407956eceba2f893498 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Mon, 16 Oct 2023 11:28:01 +0300 Subject: [PATCH] Don't iterate over off-map monsters --- src/mon.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mon.c b/src/mon.c index 945c2190f..ea374b55a 100644 --- a/src/mon.c +++ b/src/mon.c @@ -4092,8 +4092,8 @@ normal_shape(struct monst *mon) } } -/* iterate all monsters on the level, even dead ones, calling func - for each monster. if func returns TRUE, stop iterating. +/* iterate all monsters on the level, even dead or off-map ones, + calling func for each monster. if func returns TRUE, stop iterating. safe for list deletions and insertions, and guarantees calling func once per monster in the list. */ void @@ -4128,7 +4128,7 @@ iter_mons(void (*func)(struct monst *)) struct monst *mtmp; for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) + if (DEADMONSTER(mtmp) || mon_offmap(mtmp)) continue; func(mtmp); } @@ -4143,7 +4143,7 @@ get_iter_mons(boolean (*func)(struct monst *)) struct monst *mtmp; for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) + if (DEADMONSTER(mtmp) || mon_offmap(mtmp)) continue; if (func(mtmp)) return mtmp; @@ -4161,7 +4161,7 @@ get_iter_mons_xy(boolean (*func)(struct monst *, coordxy, coordxy), struct monst *mtmp; for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp)) + if (DEADMONSTER(mtmp) || mon_offmap(mtmp)) continue; if (func(mtmp, x, y)) return mtmp;