use gi.invalid_obj instead of cg.zeroobj

cg.zeroobj was originally added (under its previous unprefixed name)
for providing a one-line way to zero out the fields of a struct obj.

    struct obj tempobj;
    tempobj = cg.zeroobj;

    initfn(struct obj *otmp)
    {
        if (otmp)
            *otmp = cg.zeroobj;
    }

More recently, the address of cg.zeroobj began to be used as a return
flag to indicate some things, but the 'const struct obj zeroobj' wasn't
an ideal fit for the purpose and required a number of casts, including
casting away const.

Provide a better fitting variable (gi.invalid_obj) and eliminate a
number of casts.
This commit is contained in:
nhmall
2023-11-10 11:07:49 -05:00
parent 17dd51d922
commit 314a2a9489
14 changed files with 35 additions and 30 deletions

View File

@@ -2720,7 +2720,7 @@ doeat(void)
}
/* from floorfood(), &zeroobj means iron bars at current spot */
if (otmp == &cg.zeroobj) {
if (otmp == &gi.invalid_obj) {
/* hero in metallivore form is eating [diggable] iron bars
at current location so skip the other assorted checks;
operates as if digging rather than via the eat occupation */
@@ -3507,7 +3507,7 @@ floorfood(
c = yn_function(qbuf, ynqchars, 'n', TRUE);
}
if (c == 'y')
return (struct obj *) &cg.zeroobj; /* csst away 'const' */
return (struct obj *) &gi.invalid_obj; /* csst away 'const' */
else if (c == 'q')
return (struct obj *) 0;
++getobj_else;