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

@@ -509,7 +509,7 @@ select_rwep(struct monst *mtmp)
char mlet = mtmp->data->mlet;
gp.propellor = (struct obj *) &cg.zeroobj;
gp.propellor = &gi.invalid_obj;
Oselect(EGG); /* cockatrice egg */
if (mlet == S_KOP) /* pies are first choice for Kops */
Oselect(CREAM_PIE);
@@ -568,7 +568,7 @@ select_rwep(struct monst *mtmp)
}
/* KMH -- This belongs here so darts will work */
gp.propellor = (struct obj *) &cg.zeroobj;
gp.propellor = &gi.invalid_obj;
prop = objects[rwep[i]].oc_skill;
if (prop < 0) {
@@ -593,7 +593,7 @@ select_rwep(struct monst *mtmp)
gp.propellor = 0;
}
/* propellor = obj, propellor to use
* propellor = &cg.zeroobj, doesn't need a propellor
* propellor = &gi.invalid_obj, doesn't need a propellor
* propellor = 0, needed one and didn't have one
*/
if (gp.propellor != 0) {
@@ -788,7 +788,7 @@ mon_wield_item(struct monst *mon)
mon_nam(mon));
return 0;
}
if (obj && obj != &cg.zeroobj) {
if (obj && obj != &gi.invalid_obj) {
struct obj *mw_tmp = MON_WEP(mon);
if (mw_tmp && mw_tmp->otyp == obj->otyp) {