]> granicus.if.org Git - nethack/commitdiff
Couple more monster iterator uses
authorPasi Kallinen <paxed@alt.org>
Mon, 25 Apr 2022 09:53:04 +0000 (12:53 +0300)
committerPasi Kallinen <paxed@alt.org>
Mon, 25 Apr 2022 09:53:04 +0000 (12:53 +0300)
src/dig.c
src/dog.c

index 05c3e7afd758356b8305ab78d14262a7ec36f64e..79278548e79d3b7361314d4d86e18238fe6de24b 100644 (file)
--- a/src/dig.c
+++ b/src/dig.c
@@ -10,6 +10,7 @@ static void mkcavepos(xchar, xchar, int, boolean, boolean);
 static void mkcavearea(boolean);
 static int dig(void);
 static void dig_up_grave(coord *);
+static boolean watchman_canseeu(struct monst *);
 static int adj_pit_checks(coord *, char *);
 static void pit_flow(struct trap *, schar);
 static boolean furniture_handled(int, int, boolean);
@@ -1203,6 +1204,15 @@ use_pick_axe2(struct obj *obj)
     return ECMD_TIME;
 }
 
+static boolean
+watchman_canseeu(struct monst *mtmp)
+{
+    if (is_watch(mtmp->data) && mtmp->mcansee && m_canseeu(mtmp)
+        && couldsee(mtmp->mx, mtmp->my) && mtmp->mpeaceful)
+        return TRUE;
+    return FALSE;
+}
+
 /*
  * Town Watchmen frown on damage to the town walls, trees or fountains.
  * It's OK to dig holes in the ground, however.
@@ -1217,15 +1227,8 @@ watch_dig(struct monst *mtmp, xchar x, xchar y, boolean zap)
     if (in_town(x, y)
         && (closed_door(x, y) || lev->typ == SDOOR || IS_WALL(lev->typ)
             || IS_FOUNTAIN(lev->typ) || IS_TREE(lev->typ))) {
-        if (!mtmp) {
-            for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
-                if (DEADMONSTER(mtmp))
-                    continue;
-                if (is_watch(mtmp->data) && mtmp->mcansee && m_canseeu(mtmp)
-                    && couldsee(mtmp->mx, mtmp->my) && mtmp->mpeaceful)
-                    break;
-            }
-        }
+        if (!mtmp)
+            mtmp = get_iter_mons(watchman_canseeu);
 
         if (mtmp) {
             if (zap || g.context.digging.warned) {
index 7690aac8f18eacdd4c8f20a5990ceac88f83681c..ad20f6637bc077a4ab26befd6e4da3621192dc47 100644 (file)
--- a/src/dog.c
+++ b/src/dog.c
@@ -6,6 +6,7 @@
 #include "hack.h"
 
 static int pet_type(void);
+static void set_mon_lastmove(struct monst *);
 
 void
 newedog(struct monst *mtmp)
@@ -200,20 +201,18 @@ makedog(void)
     return  mtmp;
 }
 
+static void
+set_mon_lastmove(struct monst *mtmp)
+{
+    mtmp->mlstmv = g.moves;
+}
+
 /* record `last move time' for all monsters prior to level save so that
    mon_arrive() can catch up for lost time when they're restored later */
 void
 update_mlstmv(void)
 {
-    struct monst *mon;
-
-    /* monst->mlstmv used to be updated every time `monst' actually moved,
-       but that is no longer the case so we just do a blanket assignment */
-    for (mon = fmon; mon; mon = mon->nmon) {
-        if (DEADMONSTER(mon))
-            continue;
-        mon->mlstmv = g.moves;
-    }
+    iter_mons(set_mon_lastmove);
 }
 
 void