]> granicus.if.org Git - nethack/commitdiff
Unify probing an object chain
authorPasi Kallinen <paxed@alt.org>
Mon, 25 Apr 2022 15:11:32 +0000 (18:11 +0300)
committerPasi Kallinen <paxed@alt.org>
Mon, 25 Apr 2022 15:11:32 +0000 (18:11 +0300)
src/zap.c

index 06509cd8666464f2e3bf17ec079fd2ad115573ca..2d7c702992e2b509301f831319ee56ce9356dfb9 100644 (file)
--- a/src/zap.c
+++ b/src/zap.c
@@ -12,6 +12,7 @@
  */
 #define MAGIC_COOKIE 1000
 
+static void probe_objchain(struct obj *);
 static boolean zombie_can_dig(xchar x, xchar y);
 static void polyuse(struct obj *, int, int);
 static void create_polymon(struct obj *, int);
@@ -508,24 +509,28 @@ release_hold(void)
     }
 }
 
+static void
+probe_objchain(struct obj *otmp)
+{
+    for (; otmp; otmp = otmp->nobj) {
+        otmp->dknown = 1; /* treat as "seen" */
+        if (Is_container(otmp) || otmp->otyp == STATUE) {
+            otmp->lknown = 1;
+            if (!SchroedingersBox(otmp))
+                otmp->cknown = 1;
+        }
+    }
+}
+
 void
 probe_monster(struct monst *mtmp)
 {
-    struct obj *otmp;
-
     mstatusline(mtmp);
     if (g.notonhead)
         return; /* don't show minvent for long worm tail */
 
     if (mtmp->minvent) {
-        for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) {
-            otmp->dknown = 1; /* treat as "seen" */
-            if (Is_container(otmp) || otmp->otyp == STATUE) {
-                otmp->lknown = 1;
-                if (!SchroedingersBox(otmp))
-                    otmp->cknown = 1;
-            }
-        }
+        probe_objchain(mtmp->minvent);
         (void) display_minventory(mtmp, MINV_ALL | MINV_NOLET | PICK_NONE,
                                   (char *) 0);
     } else {
@@ -2701,22 +2706,12 @@ zapyourself(struct obj *obj, boolean ordinary)
     case SPE_DETECT_UNSEEN:
     case WAN_NOTHING:
         break;
-    case WAN_PROBING: {
-        struct obj *otmp;
-
-        for (otmp = g.invent; otmp; otmp = otmp->nobj) {
-            otmp->dknown = 1;
-            if (Is_container(otmp) || otmp->otyp == STATUE) {
-                otmp->lknown = 1;
-                if (!SchroedingersBox(otmp))
-                    otmp->cknown = 1;
-            }
-        }
+    case WAN_PROBING:
+        probe_objchain(g.invent);
         update_inventory();
         learn_it = TRUE;
         ustatusline();
         break;
-    }
     case SPE_STONE_TO_FLESH: {
         struct obj *otmp, *onxt;
         boolean didmerge;