]> granicus.if.org Git - nethack/commitdiff
fix #2236 - bag of holding weight
authornethack.rankin <nethack.rankin>
Sat, 9 Apr 2011 00:30:59 +0000 (00:30 +0000)
committernethack.rankin <nethack.rankin>
Sat, 9 Apr 2011 00:30:59 +0000 (00:30 +0000)
     From a bug report, the weight of a non-cursed bag
of holding would be off by 1 when the weight of contents was a multiple
of 2 (for uncursed) or of 4 (for blessed), since the round off handling
added 1 when it shouldn't in those cases.  Mainly noticeable when empty;
the extra 1 unit made it be twice as heavy as it should have been.

     Probably never noticed in actual play.  He has implemented a patch
which shows weights as part of an object's formatted description, making
this stand out.  Supposedly the Vulture's Eye interface also added a
patch like that a farily long time ago; I wonder why nobody using it ever
noticed.  (Maybe the weight was suppressed for bags of holding there?)

doc/fixes34.4
src/mkobj.c
src/pickup.c

index f68b797bbc2bb8a1bcca7b6df8102cf433690bd1..f26efe0b2c84d141c5f88d5863646adb1c53784a 100644 (file)
@@ -401,6 +401,7 @@ some actions taken when blind would yield "Wait!  That's a monster!" (for a
 when polymorphed into an opposite sex monster, if you then become a new
        human while failing to polymorph into something else, you'd be told
        "you feel like a new man" for female or "a new woman" for male  
+the weight of a non-cursed bag of holding was sometimes off by 1 unit
 
 
 Platform- and/or Interface-Specific Fixes
index 428d0c0736779d8952d40f82ba23396d910c3219..aaf82ba8415897ac92c3ba02feada8501f5e3eaf 100644 (file)
@@ -1169,20 +1169,16 @@ register struct obj *obj;
                 *      Bag status      Weight of contents
                 *      ----------      ------------------
                 *      cursed                  2x
-                *      blessed                 x/4 + 1
-                *      otherwise               x/2 + 1
+                *      blessed                 x/4 [rounded up: (x+3)/4]
+                *      otherwise               x/2 [rounded up: (x+1)/2]
                 *
                 *  The macro DELTA_CWT in pickup.c also implements these
                 *  weight equations.
-                *
-                *  Note:  The above checks are performed in the given order.
-                *         this means that if an object is both blessed and
-                *         cursed (not supposed to happen), it will be treated
-                *         as cursed.
                 */
                if (obj->otyp == BAG_OF_HOLDING)
                    cwt = obj->cursed ? (cwt * 2) :
-                                       (1 + (cwt / (obj->blessed ? 4 : 2)));
+                         obj->blessed ? ((cwt + 3) / 4) :
+                                         ((cwt + 1) / 2);
 
                return wt + cwt;
        }
index 7ad1d21c53dc1ad89073cc98d40cad8a233effd9..0871b8ff915a4686d1a8fa55e51ebea989645ee4 100644 (file)
@@ -57,7 +57,7 @@ STATIC_DCL void FDECL(tipcontainer, (struct obj *));
  */
 #define DELTA_CWT(cont,obj)            \
     ((cont)->cursed ? (obj)->owt * 2 : \
-                     1 + ((obj)->owt / ((cont)->blessed ? 4 : 2)))
+     (cont)->blessed ? ((obj)->owt + 3) / 4 : ((obj)->owt + 1) / 2)
 #define GOLD_WT(n)             (((n) + 50L) / 100L)
 /* if you can figure this out, give yourself a hearty pat on the back... */
 #define GOLD_CAPACITY(w,n)     (((w) * -100L) - ((n) + 50L) - 1L)