gi.invalid_obj -> hands_obj

This commit is contained in:
nhmall
2023-11-11 19:49:38 -05:00
parent 47bca92e6c
commit 76d328d86a
15 changed files with 40 additions and 34 deletions
+2 -1
View File
@@ -468,7 +468,6 @@ struct instance_globals_i {
boolean in_mk_themerooms; boolean in_mk_themerooms;
/* new */ /* new */
struct obj invalid_obj;
boolean havestate; boolean havestate;
unsigned long magic; /* validate that structure layout is preserved */ unsigned long magic; /* validate that structure layout is preserved */
@@ -1149,6 +1148,8 @@ struct const_globals {
extern const struct const_globals cg; extern const struct const_globals cg;
extern struct obj hands_obj;
#endif /* DECL_H */ #endif /* DECL_H */
+1 -1
View File
@@ -2564,7 +2564,7 @@ use_grease(struct obj *obj)
consume_obj_charge(obj, TRUE); consume_obj_charge(obj, TRUE);
oldglib = (int) (Glib & TIMEOUT); oldglib = (int) (Glib & TIMEOUT);
if (otmp != &gi.invalid_obj) { if (otmp != &hands_obj) {
You("cover %s with a thick layer of grease.", yname(otmp)); You("cover %s with a thick layer of grease.", yname(otmp));
otmp->greased = 1; otmp->greased = 1;
if (obj->cursed && !nohands(gy.youmonst.data)) { if (obj->cursed && !nohands(gy.youmonst.data)) {
+2 -1
View File
@@ -440,7 +440,6 @@ const struct instance_globals_i g_init_i = {
UNDEFINED_PTR, /* id_map */ UNDEFINED_PTR, /* id_map */
/* sp_lev.c */ /* sp_lev.c */
FALSE, /* in_mk_themerooms */ FALSE, /* in_mk_themerooms */
DUMMY, /* invalid_obj */
TRUE, /* havestate*/ TRUE, /* havestate*/
IVMAGIC /* i_magic to validate that structure layout has been preserved */ IVMAGIC /* i_magic to validate that structure layout has been preserved */
@@ -1059,6 +1058,8 @@ decl_globals_init(void)
gu.urace = urace_init_data; gu.urace = urace_init_data;
} }
/* fields in 'hands_obj' don't matter, just its distinct address */
struct obj hands_obj = DUMMY;
/* gcc 12.2's static analyzer thinks that some fields of gc.context.victual /* gcc 12.2's static analyzer thinks that some fields of gc.context.victual
are uninitialized when compiling 'bite(eat.c)' but that's impossible; are uninitialized when compiling 'bite(eat.c)' but that's impossible;
+3 -3
View File
@@ -2719,8 +2719,8 @@ doeat(void)
} }
} }
/* from floorfood(), &gi.invalid_obj means iron bars at current spot */ /* from floorfood(), &hands_obj means iron bars at current spot */
if (otmp == &gi.invalid_obj) { if (otmp == &hands_obj) {
/* hero in metallivore form is eating [diggable] iron bars /* hero in metallivore form is eating [diggable] iron bars
at current location so skip the other assorted checks; at current location so skip the other assorted checks;
operates as if digging rather than via the eat occupation */ operates as if digging rather than via the eat occupation */
@@ -3507,7 +3507,7 @@ floorfood(
c = yn_function(qbuf, ynqchars, 'n', TRUE); c = yn_function(qbuf, ynqchars, 'n', TRUE);
} }
if (c == 'y') if (c == 'y')
return &gi.invalid_obj; return &hands_obj;
else if (c == 'q') else if (c == 'q')
return (struct obj *) 0; return (struct obj *) 0;
++getobj_else; ++getobj_else;
+4 -4
View File
@@ -532,7 +532,7 @@ doengrave(void)
if (!otmp) /* otmp == cg.zeroobj if fingers */ if (!otmp) /* otmp == cg.zeroobj if fingers */
return ECMD_CANCEL; return ECMD_CANCEL;
if (otmp == &gi.invalid_obj) { if (otmp == &hands_obj) {
Strcat(strcpy(fbuf, "your "), body_part(FINGERTIP)); Strcat(strcpy(fbuf, "your "), body_part(FINGERTIP));
writer = fbuf; writer = fbuf;
} else { } else {
@@ -563,7 +563,7 @@ doengrave(void)
return ECMD_OK; return ECMD_OK;
} }
if (IS_GRAVE(levl[u.ux][u.uy].typ)) { if (IS_GRAVE(levl[u.ux][u.uy].typ)) {
if (otmp == &gi.invalid_obj) { /* using only finger */ if (otmp == &hands_obj) { /* using only finger */
You("would only make a small smudge on the %s.", You("would only make a small smudge on the %s.",
surface(u.ux, u.uy)); surface(u.ux, u.uy));
return ECMD_OK; return ECMD_OK;
@@ -1024,7 +1024,7 @@ doengrave(void)
} }
/* Tell adventurer what is going on */ /* Tell adventurer what is going on */
if (otmp != &gi.invalid_obj) if (otmp != &hands_obj)
You("%s the %s with %s.", everb, eloc, doname(otmp)); You("%s the %s with %s.", everb, eloc, doname(otmp));
else else
You("%s the %s with your %s.", everb, eloc, body_part(FINGERTIP)); You("%s the %s with your %s.", everb, eloc, body_part(FINGERTIP));
@@ -1131,7 +1131,7 @@ engrave(void)
} }
/* Stylus might have been taken out of inventory and destroyed somehow. /* Stylus might have been taken out of inventory and destroyed somehow.
* Not safe to dereference stylus until after this. */ * Not safe to dereference stylus until after this. */
if (gc.context.engraving.stylus == &gi.invalid_obj) { /* bare finger */ if (gc.context.engraving.stylus == &hands_obj) { /* bare finger */
stylus = (struct obj *) 0; stylus = (struct obj *) 0;
} else { } else {
for (stylus = gi.invent; stylus; stylus = stylus->nobj) { for (stylus = gi.invent; stylus; stylus = stylus->nobj) {
+2 -2
View File
@@ -3880,7 +3880,7 @@ fopen_wizkit_file(void)
static void static void
wizkit_addinv(struct obj *obj) wizkit_addinv(struct obj *obj)
{ {
if (!obj || obj == &gi.invalid_obj) if (!obj || obj == &hands_obj)
return; return;
/* subset of starting inventory pre-ID */ /* subset of starting inventory pre-ID */
@@ -3912,7 +3912,7 @@ proc_wizkit_line(char *buf)
otmp = readobjnam(buf, (struct obj *) 0); otmp = readobjnam(buf, (struct obj *) 0);
if (otmp) { if (otmp) {
if (otmp != &gi.invalid_obj) if (otmp != &hands_obj)
wizkit_addinv(otmp); wizkit_addinv(otmp);
} else { } else {
/* .60 limits output line width to 79 chars */ /* .60 limits output line width to 79 chars */
+2 -2
View File
@@ -391,7 +391,7 @@ void
dipfountain(struct obj *obj) dipfountain(struct obj *obj)
{ {
int er = ER_NOTHING; int er = ER_NOTHING;
boolean is_hands = (obj == &gi.invalid_obj); boolean is_hands = (obj == &hands_obj);
if (Levitation) { if (Levitation) {
floating_above("fountain"); floating_above("fountain");
@@ -705,7 +705,7 @@ dipsink(struct obj *obj)
{ {
boolean try_call = FALSE, boolean try_call = FALSE,
not_looted_yet = (levl[u.ux][u.uy].looted & S_LRING) == 0, not_looted_yet = (levl[u.ux][u.uy].looted & S_LRING) == 0,
is_hands = (obj == &gi.invalid_obj || (uarmg && obj == uarmg)); is_hands = (obj == &hands_obj || (uarmg && obj == uarmg));
if (!rn2(not_looted_yet ? 25 : 15)) { if (!rn2(not_looted_yet ? 25 : 15)) {
/* can't rely on using sink for unlimited scroll blanking; however, /* can't rely on using sink for unlimited scroll blanking; however,
+5 -5
View File
@@ -1527,13 +1527,13 @@ any_obj_ok(struct obj *obj)
* getobj returns: * getobj returns:
* struct obj *xxx: object to do something with. * struct obj *xxx: object to do something with.
* (struct obj *) 0 error return: no object. * (struct obj *) 0 error return: no object.
* &gi.invalid_obj explicitly no object (as in w-). * &hands_obj explicitly no object (as in w-).
* The obj_ok callback should not have side effects (apart from * The obj_ok callback should not have side effects (apart from
* abnormal-behavior things like impossible calls); it can be called multiple * abnormal-behavior things like impossible calls); it can be called multiple
* times on the same object during the execution of this function. * times on the same object during the execution of this function.
* Callbacks' argument is either a valid object pointer or a null pointer, * Callbacks' argument is either a valid object pointer or a null pointer,
* which represents the validity of doing that action on HANDS_SYM. getobj * which represents the validity of doing that action on HANDS_SYM. getobj
* won't call it with &gi.invalid_obj, so its behavior can be undefined in that * won't call it with &hands_obj, so its behavior can be undefined in that
* case. * case.
*/ */
struct obj * struct obj *
@@ -1579,7 +1579,7 @@ getobj(
/* check whether the hands/self choice is suitable */ /* check whether the hands/self choice is suitable */
v = (*obj_ok)((struct obj *) 0); v = (*obj_ok)((struct obj *) 0);
if (v == GETOBJ_SUGGEST || v == GETOBJ_DOWNPLAY) if (v == GETOBJ_SUGGEST || v == GETOBJ_DOWNPLAY)
otmp = &gi.invalid_obj; otmp = &hands_obj;
} else { } else {
/* there could be more than one match if key is '#'; /* there could be more than one match if key is '#';
take first one which passes the obj_ok callback */ take first one which passes the obj_ok callback */
@@ -1742,7 +1742,7 @@ getobj(
if (ilet == HANDS_SYM) { /* '-' */ if (ilet == HANDS_SYM) { /* '-' */
if (!allownone) if (!allownone)
mime_action(word); mime_action(word);
return (allownone ? &gi.invalid_obj : (struct obj *) 0); return (allownone ? &hands_obj : (struct obj *) 0);
} }
redo_menu: redo_menu:
/* since gold is now kept in inventory, we need to do processing for /* since gold is now kept in inventory, we need to do processing for
@@ -1778,7 +1778,7 @@ getobj(
continue; continue;
} }
if (ilet == HANDS_SYM) if (ilet == HANDS_SYM)
return &gi.invalid_obj; return &hands_obj;
if (ilet == '\033') { if (ilet == '\033') {
if (flags.verbose) if (flags.verbose)
pline1(Never_mind); pline1(Never_mind);
+4
View File
@@ -2631,6 +2631,10 @@ dealloc_obj(struct obj *obj)
panic("dealloc_obj with nobj"); panic("dealloc_obj with nobj");
if (obj->cobj) if (obj->cobj)
panic("dealloc_obj with cobj"); panic("dealloc_obj with cobj");
if (obj == &hands_obj) {
impossible("dealloc_obj with hands_obj");
return;
}
/* free up any timers attached to the object */ /* free up any timers attached to the object */
if (obj->timed) if (obj->timed)
+1 -1
View File
@@ -2886,7 +2886,7 @@ munslime(struct monst *mon, boolean by_you)
} }
} }
if (t && t->ttyp == FIRE_TRAP) if (t && t->ttyp == FIRE_TRAP)
return muse_unslime(mon, &gi.invalid_obj, t, by_you); return muse_unslime(mon, &hands_obj, t, by_you);
} /* MUSE */ } /* MUSE */
+4 -4
View File
@@ -3266,7 +3266,7 @@ wizterrainwish(struct _readobjnam_data *d)
(trap != MAGIC_PORTAL) ? "" : " to nowhere"); (trap != MAGIC_PORTAL) ? "" : " to nowhere");
} else } else
pline("Creation of %s failed.", an(tname)); pline("Creation of %s failed.", an(tname));
return &gi.invalid_obj; return &hands_obj;
} }
/* furniture and terrain (use at your own risk; can clobber stairs /* furniture and terrain (use at your own risk; can clobber stairs
@@ -3540,7 +3540,7 @@ wizterrainwish(struct _readobjnam_data *d)
} }
if (madeterrain || badterrain) { if (madeterrain || badterrain) {
/* cast 'const' away; caller won't modify this */ /* cast 'const' away; caller won't modify this */
return &gi.invalid_obj; return &hands_obj;
} }
return (struct obj *) 0; return (struct obj *) 0;
@@ -4495,7 +4495,7 @@ readobjnam_postparse3(struct _readobjnam_data *d)
* Return something wished for. Specifying a null pointer for * Return something wished for. Specifying a null pointer for
* the user request string results in a random object. Otherwise, * the user request string results in a random object. Otherwise,
* if asking explicitly for "nothing" (or "nil") return no_wish; * if asking explicitly for "nothing" (or "nil") return no_wish;
* if not an object return &gi.invalid_obj; if an error (no matching object), * if not an object return &hands_obj; if an error (no matching object),
* return null. * return null.
*/ */
struct obj * struct obj *
@@ -4960,7 +4960,7 @@ readobjnam(char *bp, struct obj *no_wish)
|| (d.otmp->oartifact && rn2(nartifact_exist()) > 1)) && !wizard) { || (d.otmp->oartifact && rn2(nartifact_exist()) > 1)) && !wizard) {
artifact_exists(d.otmp, safe_oname(d.otmp), FALSE, ONAME_NO_FLAGS); artifact_exists(d.otmp, safe_oname(d.otmp), FALSE, ONAME_NO_FLAGS);
obfree(d.otmp, (struct obj *) 0); obfree(d.otmp, (struct obj *) 0);
d.otmp = &gi.invalid_obj; d.otmp = &hands_obj;
pline("For a moment, you feel %s in your %s, but it disappears!", pline("For a moment, you feel %s in your %s, but it disappears!",
something, makeplural(body_part(HAND))); something, makeplural(body_part(HAND)));
return d.otmp; return d.otmp;
+2 -2
View File
@@ -2246,7 +2246,7 @@ dodip(void)
if (inaccessible_equipment(obj, "dip", FALSE)) if (inaccessible_equipment(obj, "dip", FALSE))
return ECMD_OK; return ECMD_OK;
is_hands = (obj == &gi.invalid_obj); is_hands = (obj == &hands_obj);
shortestname = (is_hands || is_plural(obj) || pair_of(obj)) ? "them" shortestname = (is_hands || is_plural(obj) || pair_of(obj)) ? "them"
: "it"; : "it";
drink_ok_extra = 0; drink_ok_extra = 0;
@@ -2381,7 +2381,7 @@ potion_dip(struct obj *obj, struct obj *potion)
pline("That is a potion bottle, not a Klein bottle!"); pline("That is a potion bottle, not a Klein bottle!");
return ECMD_OK; return ECMD_OK;
} }
if (obj == &gi.invalid_obj) { if (obj == &hands_obj) {
You("can't fit your %s into the mouth of the bottle!", You("can't fit your %s into the mouth of the bottle!",
body_part(HAND)); body_part(HAND));
return ECMD_OK; return ECMD_OK;
+4 -4
View File
@@ -509,7 +509,7 @@ select_rwep(struct monst *mtmp)
char mlet = mtmp->data->mlet; char mlet = mtmp->data->mlet;
gp.propellor = &gi.invalid_obj; gp.propellor = &hands_obj;
Oselect(EGG); /* cockatrice egg */ Oselect(EGG); /* cockatrice egg */
if (mlet == S_KOP) /* pies are first choice for Kops */ if (mlet == S_KOP) /* pies are first choice for Kops */
Oselect(CREAM_PIE); Oselect(CREAM_PIE);
@@ -568,7 +568,7 @@ select_rwep(struct monst *mtmp)
} }
/* KMH -- This belongs here so darts will work */ /* KMH -- This belongs here so darts will work */
gp.propellor = &gi.invalid_obj; gp.propellor = &hands_obj;
prop = objects[rwep[i]].oc_skill; prop = objects[rwep[i]].oc_skill;
if (prop < 0) { if (prop < 0) {
@@ -593,7 +593,7 @@ select_rwep(struct monst *mtmp)
gp.propellor = 0; gp.propellor = 0;
} }
/* propellor = obj, propellor to use /* propellor = obj, propellor to use
* propellor = &gi.invalid_obj, doesn't need a propellor * propellor = &hands_obj, doesn't need a propellor
* propellor = 0, needed one and didn't have one * propellor = 0, needed one and didn't have one
*/ */
if (gp.propellor != 0) { if (gp.propellor != 0) {
@@ -788,7 +788,7 @@ mon_wield_item(struct monst *mon)
mon_nam(mon)); mon_nam(mon));
return 0; return 0;
} }
if (obj && obj != &gi.invalid_obj) { if (obj && obj != &hands_obj) {
struct obj *mw_tmp = MON_WEP(mon); struct obj *mw_tmp = MON_WEP(mon);
if (mw_tmp && mw_tmp->otyp == obj->otyp) { if (mw_tmp && mw_tmp->otyp == obj->otyp) {
+2 -2
View File
@@ -384,7 +384,7 @@ dowield(void)
} }
/* Handle no object, or object in other slot */ /* Handle no object, or object in other slot */
if (wep == &gi.invalid_obj) { if (wep == &hands_obj) {
wep = (struct obj *) 0; wep = (struct obj *) 0;
} else if (wep == uswapwep) { } else if (wep == uswapwep) {
return doswapweapon(); return doswapweapon();
@@ -516,7 +516,7 @@ doquiver_core(const char *verb) /* "ready" or "fire" */
if (!newquiver) { if (!newquiver) {
/* Cancelled */ /* Cancelled */
return ECMD_CANCEL; return ECMD_CANCEL;
} else if (newquiver == &gi.invalid_obj) { /* no object */ } else if (newquiver == &hands_obj) { /* no object */
/* Explicitly nothing */ /* Explicitly nothing */
if (uquiver) { if (uquiver) {
You("now have no ammunition readied."); You("now have no ammunition readied.");
+2 -2
View File
@@ -5981,7 +5981,7 @@ makewish(void)
} }
/* /*
* Note: if they wished for and got a non-object successfully, * Note: if they wished for and got a non-object successfully,
* otmp == &gi.invalid_obj. That includes an artifact which has been * otmp == &hands_obj. That includes an artifact which has been
* denied. Wishing for "nothing" requires a separate value to remain * denied. Wishing for "nothing" requires a separate value to remain
* distinct. * distinct.
*/ */
@@ -6000,7 +6000,7 @@ makewish(void)
to retain wishless conduct */ to retain wishless conduct */
livelog_printf(LL_WISH, "declined to make a wish"); livelog_printf(LL_WISH, "declined to make a wish");
return; return;
} else if (otmp == &gi.invalid_obj) { } else if (otmp == &hands_obj) {
/* wizard mode terrain wish: skip livelogging, etc */ /* wizard mode terrain wish: skip livelogging, etc */
return; return;
} }