Skip to content

Commit 34cfc62

Browse files
author
Alex Smith
committed
Globals purge: wc
1 parent 55c3274 commit 34cfc62

File tree

9 files changed

+37
-31
lines changed

9 files changed

+37
-31
lines changed

libnethack/include/extern.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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 Alex Smith, 2015-07-22 */
2+
/* Last modified by Alex Smith, 2017-06-29 */
33
/* Copyright (c) Steve Creps, 1988. */
44
/* NetHack may be freely redistributed. See license for details. */
55

@@ -645,7 +645,8 @@ extern void lookaround(enum u_interaction_mode);
645645
extern int monster_nearby(void);
646646
extern void losehp(int, const char *);
647647
extern int weight_cap(void);
648-
extern int inv_weight(void);
648+
extern int inv_weight_over_cap(void);
649+
extern int inv_weight_total(void);
649650
extern int near_capacity(void);
650651
extern int calc_capacity(int);
651652
extern int max_capacity(void);

libnethack/src/cmd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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 Alex Smith, 2015-10-11 */
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

@@ -868,7 +868,7 @@ doattributes(const struct nh_cmd_arg *arg)
868868
add_menutext(&menu, buf);
869869

870870
wc = weight_cap();
871-
buf = msgprintf("%-10s: %ld (", "burden", wc + inv_weight());
871+
buf = msgprintf("%-10s: %ld (", "burden", inv_weight_total());
872872

873873
switch (calc_capacity(wc / 4)) {
874874
case UNENCUMBERED:

libnethack/src/do.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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 Alex Smith, 2015-07-20 */
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

@@ -821,7 +821,7 @@ doup(void)
821821
return 1;
822822
}
823823
if (near_capacity() > SLT_ENCUMBER) {
824-
/* No levitation check; inv_weight() already allows for it */
824+
/* No levitation check; the weight check already allows for it */
825825
pline("Your load is too heavy to climb the %s.",
826826
level->locations[u.ux][u.uy].typ == STAIRS ? "stairs" : "ladder");
827827
return 1;

libnethack/src/dokick.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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 Alex Smith, 2015-07-12 */
2+
/* Last modified by Alex Smith, 2017-06-29 */
33
/* Copyright (c) Izchak Miller, Mike Stephenson, Steve Linhart, 1989. */
44
/* NetHack may be freely redistributed. See license for details. */
55

@@ -210,7 +210,7 @@ kick_monster(xchar x, xchar y, schar dx, schar dy)
210210
return attack_status;
211211
}
212212

213-
i = -inv_weight();
213+
i = -inv_weight_over_cap();
214214
j = weight_cap();
215215

216216
if (i < (j * 3) / 10) {
@@ -810,7 +810,7 @@ dokick(const struct nh_cmd_arg *arg)
810810
if (Is_airlevel(&u.uz) || Levitation) {
811811
int range;
812812

813-
range = ((int)youmonst.data->cwt + (weight_cap() + inv_weight()));
813+
range = ((int)youmonst.data->cwt + inv_weight_total());
814814
if (range < 1)
815815
range = 1; /* divide by zero avoidance */
816816
range = (3 * (int)mdat->cwt) / range;

libnethack/src/dothrow.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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 Alex Smith, 2015-05-19 */
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

@@ -474,7 +474,7 @@ hurtle_step(void *arg, int x, int y)
474474
}
475475
if ((u.ux - x) && (u.uy - y) && bad_rock(youmonst.data, u.ux, y) &&
476476
bad_rock(youmonst.data, x, u.uy)) {
477-
boolean too_much = (invent && (inv_weight() + weight_cap() > 600));
477+
boolean too_much = (invent && (inv_weight_total() > 600));
478478

479479
/* Move at a diagonal. */
480480
if (bigmonst(youmonst.data) || too_much) {

libnethack/src/hack.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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. */
31063102
int
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
*/
31273131
int
31283132
calc_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)
31463151
int
31473152
max_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

31543159
boolean

libnethack/src/timeout.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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 Alex Smith, 2015-07-22 */
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

@@ -320,7 +320,7 @@ nh_timeout(void)
320320
/* The more you are carrying the more likely you are to
321321
make noise when you fumble. Adjustments to this number
322322
must be thoroughly play tested. */
323-
if ((inv_weight() > -500)) {
323+
if ((inv_weight_over_cap() > -500)) {
324324
pline("You make a lot of noise!");
325325
wake_nearby(FALSE);
326326
}

libnethack/src/trap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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 Alex Smith, 2015-10-11 */
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

@@ -3249,7 +3249,7 @@ try_disarm(struct trap *ttmp, boolean force_failure, schar dx, schar dy)
32493249
/* duplicate tight-space checks from test_move */
32503250
if (dx && dy && bad_rock(youmonst.data, u.ux, ttmp->ty) &&
32513251
bad_rock(youmonst.data, ttmp->tx, u.uy)) {
3252-
if ((invent && (inv_weight() + weight_cap() > 600)) ||
3252+
if ((invent && (inv_weight_total() > 600)) ||
32533253
bigmonst(youmonst.data)) {
32543254
/* don't allow untrap if they can't get thru to it */
32553255
pline("You are unable to reach the %s!", trapexplain[ttype - 1]);
@@ -3524,7 +3524,7 @@ help_monster_out(struct monst *mtmp, struct trap *ttmp)
35243524
}
35253525

35263526
/* is the monster too heavy? */
3527-
wt = inv_weight() + mtmp->data->cwt;
3527+
wt = inv_weight_over_cap() + mtmp->data->cwt;
35283528
if (!try_lift(mtmp, ttmp, wt, FALSE))
35293529
return 1;
35303530

libnethack/src/u_init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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 Alex Smith, 2015-06-15 */
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

@@ -851,7 +851,7 @@ u_init_inv_skills(void)
851851
}
852852

853853
/* make sure you can carry all you have - especially for Tourists */
854-
while (inv_weight() > 0) {
854+
while (inv_weight_over_cap() > 0) {
855855
if (adjattrib(A_STR, 1, TRUE))
856856
continue;
857857
if (adjattrib(A_CON, 1, TRUE))

0 commit comments

Comments
 (0)