From: PatR Date: Sun, 14 Nov 2021 07:45:47 +0000 (-0800) Subject: shrink_glob nitpicking X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a94650159e35321c19e6eb694f8907c827a23f8c;p=nethack shrink_glob nitpicking 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. --- diff --git a/src/mkobj.c b/src/mkobj.c index d8e7988a3..438be9436 100644 --- a/src/mkobj.c +++ b/src/mkobj.c @@ -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