replace some weight-related magic numbers

adds a header file include/nhconst.h  (I'm open to a better name)
This commit is contained in:
nhmall
2025-03-19 13:29:58 -04:00
parent 00a5d811ee
commit a943c4c10b
19 changed files with 118 additions and 86 deletions

View File

@@ -275,7 +275,7 @@ flooreffects(
* noise. Stuff dropped near fountains always misses */
if ((Blind || (Levitation || Flying)) && !Deaf && u_at(x, y)) {
if (!Underwater) {
if (weight(obj) > 9) {
if (weight(obj) > WT_SPLASH_THRESHOLD) {
pline("Splash!");
} else if (Levitation || Flying) {
pline("Plop!");

View File

@@ -823,7 +823,7 @@ hurtle_step(genericptr_t arg, coordxy x, coordxy y)
&& bad_rock(gy.youmonst.data, u.ux, y)
&& bad_rock(gy.youmonst.data, x, u.uy)) {
boolean too_much = (gi.invent
&& (inv_weight() + weight_cap() > 600));
&& (inv_weight() + weight_cap() > WT_TOOMUCH_DIAGONAL));
if (bigmonst(gy.youmonst.data) || too_much) {
why = "wedging into a narrow crevice";
@@ -1347,7 +1347,7 @@ toss_up(struct obj *obj, boolean hitsroof)
&dmg, rn1(18, 2));
if (!dmg) { /* probably wasn't a weapon; base damage on weight */
dmg = ((int) obj->owt + 99) / 100;
dmg = ((int) obj->owt + (WT_TO_DMG - 1)) / WT_TO_DMG;
dmg = (dmg <= 1) ? 1 : rnd(dmg);
if (dmg > 6)
dmg = 6;
@@ -1770,7 +1770,8 @@ throwit(struct obj *obj,
|| (is_lava(gb.bhitpos.x, gb.bhitpos.y)
&& !is_flammable(obj))) {
Soundeffect(se_splash, 50);
pline((weight(obj) > 9) ? "Splash!" : "Plop!");
pline((weight(obj) > WT_SPLASH_THRESHOLD)
? "Splash!" : "Plop!");
}
}
if (flooreffects(obj, gb.bhitpos.x, gb.bhitpos.y, "fall")) {

View File

@@ -135,7 +135,8 @@ revive_nasty(coordxy x, coordxy y, const char *msg)
return revived;
}
#define squeezeablylightinvent() (!gi.invent || inv_weight() <= -850)
#define squeezeablylightinvent() (!gi.invent \
|| inv_weight() <= (WT_SQUEEZABLE_INV * -1))
/* can hero move onto a spot containing one or more boulders?
used for m<dir> and travel and during boulder push failure */
@@ -4195,7 +4196,8 @@ weight_cap(void)
functions enough in that situation to enhance carrying capacity */
BLevitation &= ~I_SPECIAL;
carrcap = 25 * (ACURRSTR + ACURR(A_CON)) + 50;
carrcap = (WT_WEIGHTCAP_STRCON * (ACURRSTR + ACURR(A_CON)))
+ WT_WEIGHTCAP_SPARE;
if (Upolyd) {
/* consistent with can_carry() in mon.c */
if (gy.youmonst.data->mlet == S_NYMPH)
@@ -4216,9 +4218,9 @@ weight_cap(void)
carrcap = MAX_CARR_CAP;
if (!Flying) {
if (EWounded_legs & LEFT_SIDE)
carrcap -= 100;
carrcap -= WT_WOUNDEDLEG_REDUCT;
if (EWounded_legs & RIGHT_SIDE)
carrcap -= 100;
carrcap -= WT_WOUNDEDLEG_REDUCT;
}
}

View File

@@ -4,6 +4,7 @@
/* NetHack may be freely redistributed. See license for details. */
#include "config.h"
#include "nhconst.h"
#include "permonst.h"
#include "wintype.h"
#include "sym.h"

View File

@@ -1439,10 +1439,10 @@ hit_bars(
if (your_fault && (otmp->otyp == WAR_HAMMER
|| otmp->otyp == HEAVY_IRON_BALL)) {
/* iron ball isn't a weapon or wep-tool so doesn't use obj->spe;
weight is normally 480 but can be increased by increments
of 160 (scrolls of punishment read while already punished) */
weight is normally 48000 but can be increased by increments
of 16000 (scrolls of punishment read while already punished) */
int spe = ((otmp->otyp == HEAVY_IRON_BALL) /* 3+ for iron ball */
? ((int) otmp->owt / IRON_BALL_W_INCR)
? ((int) otmp->owt / WT_IRON_BALL_INCR)
: otmp->spe);
/* chance: used in saving throw for the bars; more likely to
break those when 'chance' is _lower_; acurrstr(): 3..25 */

View File

@@ -3,6 +3,7 @@
/* NetHack may be freely redistributed. See license for details. */
#include "config.h"
#include "nhconst.h"
#include "obj.h"
#include "prop.h"

View File

@@ -5357,7 +5357,7 @@ readobjnam(char *bp, struct obj *no_wish)
}
d.otmp->owt = weight(d.otmp);
if (d.very && d.otmp->otyp == HEAVY_IRON_BALL)
d.otmp->owt += IRON_BALL_W_INCR;
d.otmp->owt += WT_IRON_BALL_INCR;
return d.otmp;
}

View File

@@ -2938,7 +2938,7 @@ punish(struct obj *sobj)
You("are being punished for your misbehavior!");
if (Punished) {
Your("iron ball gets heavier.");
uball->owt += IRON_BALL_W_INCR * (1 + cursed_levy);
uball->owt += WT_IRON_BALL_INCR * (1 + cursed_levy);
return;
}
if (amorphous(gy.youmonst.data) || is_whirly(gy.youmonst.data)

View File

@@ -910,7 +910,7 @@ nh_timeout(void)
* are to make noise when you fumble. Adjustments
* to this number must be thoroughly play tested.
*/
if ((inv_weight() > -500)) {
if ((inv_weight() > (WT_NOISY_INV * -1))) {
if (!Deaf)
You("make a lot of noise!");
wake_nearby(FALSE);

View File

@@ -5366,7 +5366,7 @@ try_disarm(
/* duplicate tight-space checks from test_move */
if (u.dx && u.dy && bad_rock(gy.youmonst.data, u.ux, ttmp->ty)
&& bad_rock(gy.youmonst.data, ttmp->tx, u.uy)) {
if ((gi.invent && (inv_weight() + weight_cap() > 600))
if ((gi.invent && (inv_weight() + weight_cap() > WT_TOOMUCH_DIAGONAL))
|| bigmonst(gy.youmonst.data)) {
/* don't allow untrap if they can't get thru to it */
You("are unable to reach the %s!", trapname(ttype, FALSE));

View File

@@ -310,7 +310,7 @@ dmgval(struct obj *otmp, struct monst *mon)
int wt = (int) objects[HEAVY_IRON_BALL].oc_weight;
if ((int) otmp->owt > wt) {
wt = ((int) otmp->owt - wt) / IRON_BALL_W_INCR;
wt = ((int) otmp->owt - wt) / WT_IRON_BALL_INCR;
tmp += rnd(4 * wt);
if (tmp > 25)
tmp = 25; /* objects[].oc_wldam */