11/* vim:set cin ft=c sw=4 sts=4 ts=8 et ai cino=Ls\:0t0(0 : -*- mode:c;fill-column:80;tab-width:8;c-basic-offset:4;indent-tabs-mode:nil;c-file-style:"k&r" -*-*/
2- /* Last modified by Fredrik Ljungdahl, 2015-10-02 */
2+ /* Last modified by Alex Smith, 2017-06-29 */
33/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
44/* NetHack may be freely redistributed. See license for details. */
55
@@ -859,7 +859,7 @@ test_move(int ux, int uy, int dx, int dy, int dz, int mode,
859859 pline ("Your body is too large to fit through." );
860860 return FALSE;
861861 }
862- if (invent && (inv_weight () + weight_cap () > 600 )) {
862+ if (invent && (inv_weight_total () > 600 )) {
863863 if (mode == DO_MOVE )
864864 pline ("You are carrying too much to get through." );
865865 return FALSE;
@@ -905,7 +905,7 @@ test_move(int ux, int uy, int dx, int dy, int dz, int mode,
905905 /* Can we be blocked by a boulder? */
906906 if (!throws_rocks (youmonst .data ) &&
907907 !(verysmall (youmonst .data ) && !u .usteed ) &&
908- !((!invent || inv_weight () <= -850 ) && !u .usteed )) {
908+ !((!invent || inv_weight_over_cap () <= -850 ) && !u .usteed )) {
909909 /* We assume we can move boulders when we're at a distance from them.
910910 When it comes to actually do the move, resolve_uim() may replace the
911911 move with a #pushboulder command. If it doesn't, the move fails
@@ -3099,12 +3099,8 @@ weight_cap(void)
30993099 return (int )carrcap ;
31003100}
31013101
3102- static int wc ; /* current weight_cap(); valid after call to inv_weight() */
3103-
3104- /* returns how far beyond the normal capacity the player is currently. */
3105- /* inv_weight() is negative if the player is below normal capacity. */
31063102int
3107- inv_weight (void )
3103+ inv_weight_total (void )
31083104{
31093105 struct obj * otmp = invent ;
31103106 int wt = 0 ;
@@ -3116,18 +3112,27 @@ inv_weight(void)
31163112 wt += otmp -> owt ;
31173113 otmp = otmp -> nobj ;
31183114 }
3119- wc = weight_cap ();
3120- return wt - wc ;
3115+ return wt ;
3116+ }
3117+
3118+ /* Returns how far beyond the normal capacity the player is currently. Negative
3119+ if the player is below normal capacity. */
3120+ int
3121+ inv_weight_over_cap (void )
3122+ {
3123+ return inv_weight_total () - weight_cap ();
31213124}
31223125
3126+
31233127/*
31243128 * Returns 0 if below normal capacity, or the number of "capacity units"
31253129 * over the normal capacity the player is loaded. Max is 5.
31263130 */
31273131int
31283132calc_capacity (int xtra_wt )
31293133{
3130- int cap , wt = inv_weight () + xtra_wt ;
3134+ int wc = weight_cap ();
3135+ int cap , wt = inv_weight_total () + xtra_wt - wc ;
31313136
31323137 if (wt <= 0 )
31333138 return UNENCUMBERED ;
@@ -3146,9 +3151,9 @@ near_capacity(void)
31463151int
31473152max_capacity (void )
31483153{
3149- int wt = inv_weight ();
3154+ int wt = inv_weight_over_cap ();
31503155
3151- return wt - (2 * wc );
3156+ return wt - (2 * weight_cap () );
31523157}
31533158
31543159boolean
0 commit comments