]> granicus.if.org Git - nethack/commitdiff
simplify unpunish()
authorPatR <rankin@nethack.org>
Sat, 11 Jun 2022 07:11:48 +0000 (00:11 -0700)
committerPatR <rankin@nethack.org>
Sat, 11 Jun 2022 07:11:48 +0000 (00:11 -0700)
unpunish() duplicated much of delobj() in order to use dealloc_obj().
Switch to delobj().  That required a fix to feel_location() when it
was called by savebones() after vision is turned disabled.

src/display.c
src/read.c

index 839d99c1a9a0dada9fe827c049f40f037fe6d2cc..4a6e20aa39ec0a91fb4e6aee551f4406b64a865d 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 display.c       $NHDT-Date: 1652391730 2022/05/12 21:42:10 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.183 $ */
+/* NetHack 3.7 display.c       $NHDT-Date: 1654931503 2022/06/11 07:11:43 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.184 $ */
 /* Copyright (c) Dean Luick, with acknowledgements to Kevin Darcy */
 /* and Dave Cohrs, 1990.                                          */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -769,19 +769,25 @@ feel_location(xchar x, xchar y)
              * something has been dropped on the ball/chain.  If the bit is
              * not cleared, then when the ball/chain is moved it will drop
              * the wrong glyph.
+             *
+             * Note: during unpunish() we can be called by delobj() when
+             * destroying uchain while uball hasn't been cleared yet (so
+             * Punished will still yield True but uchain might not be part
+             * of the floor list anymore).
              */
-            if (uchain->ox == x && uchain->oy == y) {
-                if (g.level.objects[x][y] == uchain)
-                    u.bc_felt |= BC_CHAIN;
-                else
-                    u.bc_felt &= ~BC_CHAIN; /* do not feel the chain */
-            }
-            if (!carried(uball) && uball->ox == x && uball->oy == y) {
-                if (g.level.objects[x][y] == uball)
-                    u.bc_felt |= BC_BALL;
-                else
-                    u.bc_felt &= ~BC_BALL; /* do not feel the ball */
-            }
+            if (uchain && uchain->where == OBJ_FLOOR
+                && uchain->ox == x && uchain->oy == y
+                && g.level.objects[x][y] == uchain)
+                u.bc_felt |= BC_CHAIN;
+            else
+                u.bc_felt &= ~BC_CHAIN; /* do not feel the chain */
+
+            if (uball && uball->where == OBJ_FLOOR
+                && uball->ox == x && uball->oy == y
+                && g.level.objects[x][y] == uball)
+                u.bc_felt |= BC_BALL;
+            else
+                u.bc_felt &= ~BC_BALL; /* do not feel the ball */
         }
 
         /* Floor spaces are dark if unlit.  Corridors are dark if unlit. */
index 620ef14aff0af0140b0ed9ed47e2b4429d1c8a12..bf1ade8a8b65c7e4786b79d52e4e4a2cb022a41b 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 read.c  $NHDT-Date: 1637992351 2021/11/27 05:52:31 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.229 $ */
+/* NetHack 3.7 read.c  $NHDT-Date: 1654931501 2022/06/11 07:11:41 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.257 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2012. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -2833,11 +2833,10 @@ unpunish(void)
     struct obj *savechain = uchain;
 
     /* chain goes away */
-    obj_extract_self(uchain);
-    maybe_unhide_at(uchain->ox, uchain->oy);
-    newsym(uchain->ox, uchain->oy);
     setworn((struct obj *) 0, W_CHAIN); /* sets 'uchain' to Null */
-    dealloc_obj(savechain);
+    /* for floor, unhides monster hidden under chain, calls newsym() */
+    delobj(savechain);
+
     /* the chain is gone but the no longer attached ball persists */
     setworn((struct obj *) 0, W_BALL); /* sets 'uball' to Null */
 }