]> granicus.if.org Git - nethack/commitdiff
glob weight recalc
authorPatR <rankin@nethack.org>
Fri, 5 Feb 2016 23:46:24 +0000 (15:46 -0800)
committerPatR <rankin@nethack.org>
Fri, 5 Feb 2016 23:46:24 +0000 (15:46 -0800)
weight() didn't know how to calculate a glob's weight.  When one glob
absorbs another, that isn't used, but when the hero eats part of a
glob, it is, and the result was incorrect.

src/eat.c
src/mkobj.c

index 9601e1cdb6f75fdd97b2f373023679262b5c5506..269fcaf28ea6118ee6e0b9534847c34aea1d7bdf 100644 (file)
--- a/src/eat.c
+++ b/src/eat.c
@@ -1,4 +1,4 @@
-/* NetHack 3.6 eat.c   $NHDT-Date: 1454061992 2016/01/29 10:06:32 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.162 $ */
+/* NetHack 3.6 eat.c   $NHDT-Date: 1454715969 2016/02/05 23:46:09 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.163 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -312,7 +312,7 @@ struct obj *otmp;
         costly_alteration(otmp, COST_BITE);
         otmp->oeaten = (otmp->otyp == CORPSE) ? mons[otmp->corpsenm].cnutrit
                            : otmp->globby ? otmp->owt
-                               : objects[otmp->otyp].oc_nutrition;
+                               : (unsigned) objects[otmp->otyp].oc_nutrition;
     }
 
     if (carried(otmp)) {
@@ -2558,7 +2558,7 @@ doeat()
     /* re-calc the nutrition */
     basenutrit = (otmp->otyp == CORPSE) ? mons[otmp->corpsenm].cnutrit
                      : otmp->globby ? otmp->owt
-                         : objects[otmp->otyp].oc_nutrition;
+                         : (unsigned) objects[otmp->otyp].oc_nutrition;
 
     debugpline3(
      "before rounddiv: victual.reqtime == %d, oeaten == %d, basenutrit == %d",
@@ -3042,9 +3042,9 @@ struct obj *obj;
     long uneaten_amt, full_amount;
 
     uneaten_amt = (long) obj->oeaten;
-    full_amount = (obj->otyp == CORPSE) ? (long) mons[obj->corpsenm].cnutrit
-                      : obj->globby ? obj->owt
-                          : (long) objects[obj->otyp].oc_nutrition;
+    full_amount = (long) ((obj->otyp == CORPSE) ? mons[obj->corpsenm].cnutrit
+                            : obj->globby ? obj->owt
+                               : (unsigned) objects[obj->otyp].oc_nutrition);
     if (uneaten_amt > full_amount) {
         impossible(
           "partly eaten food (%ld) more nutritious than untouched food (%ld)",
index ef0af3eec851aa780d64525c0c36465ace1e1252..6cb87e40bc77543ee2c5ab3f5aff02ee4e39312d 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 mkobj.c $NHDT-Date: 1454061995 2016/01/29 10:06:35 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.117 $ */
+/* NetHack 3.6 mkobj.c $NHDT-Date: 1454715975 2016/02/05 23:46:15 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.119 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -1342,6 +1342,11 @@ register struct obj *obj;
 {
     int wt = objects[obj->otyp].oc_weight;
 
+    /* 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 */
+    if (obj->globby && obj->owt > 0)
+        wt = obj->owt;
     if (SchroedingersBox(obj))
         wt += mons[PM_HOUSECAT].cwt;
     if (Is_container(obj) || obj->otyp == STATUE) {