]> granicus.if.org Git - nethack/commitdiff
shrink_glob nitpicking
authorPatR <rankin@nethack.org>
Sun, 14 Nov 2021 07:45:47 +0000 (23:45 -0800)
committerPatR <rankin@nethack.org>
Sun, 14 Nov 2021 07:45:47 +0000 (23:45 -0800)
For a glob in a container carried by the hero, shrinking away to
nothing would have indirectly updated the container's weight when
obj_extract_self() was called, then the 'old_top_owt' value would
never be different from current topcontnr->owt.  That only matters
for the shrink-but-not-gone case and could only happen for the gone
case so didn't result in anything noticeably wrong.  But fix it to
match the comment about weight not being adjusted yet.

src/mkobj.c

index d8e7988a3ac53ed02eacf34793595879de620dc4..438be943636ced8bd5882b20bdc4e510cd6fb395 100644 (file)
@@ -1438,11 +1438,6 @@ shrink_glob(
                   gone ? "dissippates completely" : "shrinks");
         updinv = TRUE;
     } else if (contnr) {
-        /* if obj->owt has dropped to 0, weight() will assume that this is a
-           brand new glob and use 20 instead; that would yield an incorrect
-           total weight for enclosing container(s), so take it out now */
-        if (gone)
-            obj_extract_self(obj);
         /* when in a container, it might be nested so find outermost one */
         topcontnr = contnr;
         while (topcontnr->where == OBJ_CONTAINED)
@@ -1450,8 +1445,15 @@ shrink_glob(
         /* obj's weight has been reduced, but weight(s) of enclosing
            container(s) haven't been adjusted for that yet */
         old_top_owt = topcontnr->owt;
-        /* update those weights now; recursively updates nested containers */
-        container_weight(contnr);
+        /* update those weights now; recursively updates nested containers
+           (extracting from a container does that automatically); if obj->owt
+           has dropped to 0, weight() will assume that this is a brand new
+           glob and use 20 instead; that would yield an incorrect total
+           weight for enclosing container(s), so take 'gone' glob out now */
+        if (gone)
+            obj_extract_self(obj);
+        else
+            container_weight(contnr);
 
         if (topcontnr->where == OBJ_INVENT) {
             /* for regular containers, the weight will always be reduced