From 90aded3648747179de91b6df9a50bcf670ae715c Mon Sep 17 00:00:00 2001 From: PatR Date: Sun, 7 Nov 2021 13:27:44 -0800 Subject: [PATCH] weight of gold I had wizweight On when testing glob changes and noticed |Slasher drops a gold piece (0 aum). Coins are supposed to weigh 1/100 of a unit, and the calculation rounds rather than simply truncates any fraction, but that still yielded 0 for quantities of 1..49. Force any non-zero stack of gold to weigh at least 1 unit. Also, add a check for attempting to weigh a quantity 0 or less (of anything, not only for gold) just in case. --- doc/fixes37.0 | 1 + src/mkobj.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/fixes37.0 b/doc/fixes37.0 index 63319edb8..6b9dcab1b 100644 --- a/doc/fixes37.0 +++ b/doc/fixes37.0 @@ -678,6 +678,7 @@ prevent normal monster activity from picking up the mines' luckstone or the Sokoban amulet/bag before hero has done so; relying on scare monster and/or engraved Elbereth wasn't sufficient to guard the Sokoban prize proceed a little further into dochat() if hero is deaf +stacks of 1 to 49 gold pieces weighed 0 Fixes to 3.7.0-x Problems that Were Exposed Via git Repository diff --git a/src/mkobj.c b/src/mkobj.c index a420074f1..2552548d0 100644 --- a/src/mkobj.c +++ b/src/mkobj.c @@ -1654,6 +1654,11 @@ weight(struct obj *obj) { int wt = (int) objects[obj->otyp].oc_weight; + if (obj->quan < 1L) { + impossible("Calculating weight of %ld %s?", + obj->quan, simpleonames(obj)); + return 0; + } /* glob absorpsion means that merging globs accumulates weight while quantity stays 1, so update 'wt' to reflect that, unless owt is 0, when we assume this is a brand new glob so use objects[].oc_weight */ @@ -1699,7 +1704,9 @@ weight(struct obj *obj) } else if (obj->oclass == FOOD_CLASS && obj->oeaten) { return eaten_stat((int) obj->quan * wt, obj); } else if (obj->oclass == COIN_CLASS) { - return (int) ((obj->quan + 50L) / 100L); + /* 3.7: always weigh at least 1 unit; used to yield 0 for 1..49 */ + wt = (int) ((obj->quan + 50L) / 100L); + return max(wt, 1); } else if (obj->otyp == HEAVY_IRON_BALL && obj->owt != 0) { return (int) obj->owt; /* kludge for "very" heavy iron ball */ } else if (obj->otyp == CANDELABRUM_OF_INVOCATION && obj->spe) {