Don't iterate over off-map monsters

This commit is contained in:
Pasi Kallinen
2023-10-16 11:28:01 +03:00
parent 00f45d62ae
commit 72016b1f17
+5 -5
View File
@@ -4092,8 +4092,8 @@ normal_shape(struct monst *mon)
} }
} }
/* iterate all monsters on the level, even dead ones, calling func /* iterate all monsters on the level, even dead or off-map ones,
for each monster. if func returns TRUE, stop iterating. calling func for each monster. if func returns TRUE, stop iterating.
safe for list deletions and insertions, and guarantees safe for list deletions and insertions, and guarantees
calling func once per monster in the list. */ calling func once per monster in the list. */
void void
@@ -4128,7 +4128,7 @@ iter_mons(void (*func)(struct monst *))
struct monst *mtmp; struct monst *mtmp;
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
if (DEADMONSTER(mtmp)) if (DEADMONSTER(mtmp) || mon_offmap(mtmp))
continue; continue;
func(mtmp); func(mtmp);
} }
@@ -4143,7 +4143,7 @@ get_iter_mons(boolean (*func)(struct monst *))
struct monst *mtmp; struct monst *mtmp;
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
if (DEADMONSTER(mtmp)) if (DEADMONSTER(mtmp) || mon_offmap(mtmp))
continue; continue;
if (func(mtmp)) if (func(mtmp))
return mtmp; return mtmp;
@@ -4161,7 +4161,7 @@ get_iter_mons_xy(boolean (*func)(struct monst *, coordxy, coordxy),
struct monst *mtmp; struct monst *mtmp;
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
if (DEADMONSTER(mtmp)) if (DEADMONSTER(mtmp) || mon_offmap(mtmp))
continue; continue;
if (func(mtmp, x, y)) if (func(mtmp, x, y))
return mtmp; return mtmp;