Split deadbook undead pacify effect into separate function

Also make the monster chain iterator functions more robust,
in case the called function changes the next monster pointer.
This commit is contained in:
Pasi Kallinen
2023-10-28 19:01:46 +03:00
parent 204cf6bf10
commit 638c487c59
2 changed files with 31 additions and 26 deletions
+9 -6
View File
@@ -4125,9 +4125,10 @@ iter_mons_safe(boolean (*func)(struct monst *))
void
iter_mons(void (*func)(struct monst *))
{
struct monst *mtmp;
struct monst *mtmp, *mtmp2;
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
for (mtmp = fmon; mtmp; mtmp = mtmp2) {
mtmp2 = mtmp->nmon;
if (DEADMONSTER(mtmp) || mon_offmap(mtmp))
continue;
func(mtmp);
@@ -4140,9 +4141,10 @@ iter_mons(void (*func)(struct monst *))
struct monst *
get_iter_mons(boolean (*func)(struct monst *))
{
struct monst *mtmp;
struct monst *mtmp, *mtmp2;
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
for (mtmp = fmon; mtmp; mtmp = mtmp2) {
mtmp2 = mtmp->nmon;
if (DEADMONSTER(mtmp) || mon_offmap(mtmp))
continue;
if (func(mtmp))
@@ -4158,9 +4160,10 @@ struct monst *
get_iter_mons_xy(boolean (*func)(struct monst *, coordxy, coordxy),
coordxy x, coordxy y)
{
struct monst *mtmp;
struct monst *mtmp, *mtmp2;
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
for (mtmp = fmon; mtmp; mtmp = mtmp2) {
mtmp2 = mtmp->nmon;
if (DEADMONSTER(mtmp) || mon_offmap(mtmp))
continue;
if (func(mtmp, x, y))