]> granicus.if.org Git - nethack/commitdiff
yet another shrink_glob fix...
authorPatR <rankin@nethack.org>
Thu, 2 Dec 2021 01:05:27 +0000 (17:05 -0800)
committerPatR <rankin@nethack.org>
Thu, 2 Dec 2021 01:05:27 +0000 (17:05 -0800)
When catching up for lost time spent on another level, globs inside
containers that shrank away to nothing didn't need to have those
containers' weight explicitly adjusted because obj_extract_self()
does that, so yesterday I removed the unneeded container_weight()
call.  However, ones that shrank only partially did need to have
their containers' weights adjusted and that wasn't being done.
The weight would be brought up to date within 25 or so turns when
the contained glob's next shrink_glob event took place.  Until then
attempting to pick up the container by hero or monster, or to pick
up something else by a monster already carrying it, could have been
impacted by the weight discrepancy.

src/mkobj.c

index d3456dcd5cdf612b5249cf9a169505e51386a95b..afd757acf40cb733e685cc71736e73961642799e 100644 (file)
@@ -1367,12 +1367,19 @@ shrink_glob(
             delta = (delta + 2L) / 3L;
 
         if (delta >= (long) obj->owt) {
-            /* no newsym() or message here; forthcoming map update for
+            /* gone; no newsym() or message here--forthcoming map update for
                level arrival is all that's needed */
-            obj_extract_self(obj); /* if contained, updates container's owt */
+            obj_extract_self(obj); /* if contained, also updates container's
+                                    * weight (recursively when nested) */
             obfree(obj, (struct obj *) 0);
         } else {
+            /* shrank but not gone; reduce remaining weight */
             obj->owt -= (unsigned) delta;
+            /* won't be in container carried by hero but might be in floor one
+               or one carried by monster; if so, update container's weight */
+            if (contnr)
+                container_weight(contnr);
+            /* resume regular shrinking */
             start_glob_timeout(obj, moddelta);
         }
         return;