From c2ddd2a7c23a40c0ff8f77a5006fbfa785c1ba76 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Wed, 24 Jan 2024 17:55:36 +0200 Subject: [PATCH] Fix some object weight problems There were few places where the object weight was not updated: - container when the contents were broken by impact - starting to eat but getting stopped by rotten food - using lua, container when putting an object inside it - when a single egg of a larger stack hatched --- src/dokick.c | 5 ++++- src/eat.c | 2 ++ src/nhlobj.c | 1 + src/timeout.c | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/dokick.c b/src/dokick.c index e0735771f..8d2501f35 100644 --- a/src/dokick.c +++ b/src/dokick.c @@ -411,7 +411,7 @@ container_impact_dmg( struct monst *shkp; struct obj *otmp, *otmp2; long loss = 0L; - boolean costly, insider, frominv; + boolean costly, insider, frominv, wchange = FALSE; /* only consider normal containers */ if (!Is_container(obj) || !Has_contents(obj) || Is_mbag(obj)) @@ -462,8 +462,11 @@ container_impact_dmg( } /* contents of this container are no longer known */ obj->cknown = 0; + wchange = TRUE; } } + if (wchange) + obj->owt = weight(obj); if (costly && loss) { if (!insider) { You("caused %ld %s worth of damage!", loss, currency(loss)); diff --git a/src/eat.c b/src/eat.c index 1b4f1c373..77d64f5f0 100644 --- a/src/eat.c +++ b/src/eat.c @@ -2950,6 +2950,8 @@ doeat(void) if (!dont_start) start_eating(otmp, already_partly_eaten); + else + otmp->owt = weight(otmp); return ECMD_TIME; } diff --git a/src/nhlobj.c b/src/nhlobj.c index 619af7de0..092cc60e7 100644 --- a/src/nhlobj.c +++ b/src/nhlobj.c @@ -129,6 +129,7 @@ l_obj_add_to_container(lua_State *L) lo->obj = otmp; lo->obj->lua_ref_cnt += refs; } + lobox->obj->owt = weight(lobox->obj); return 0; } diff --git a/src/timeout.c b/src/timeout.c index c329e6b37..e6f3e0569 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -1118,6 +1118,7 @@ hatch_egg(anything *arg, long timeout) /* still some eggs left */ /* Instead of ordinary egg timeout use a short one */ attach_egg_hatch_timeout(egg, (long) rnd(12)); + egg->owt = weight(egg); } else if (carried(egg)) { useup(egg); } else {