From 8212ddd69ebfebed5c2f47f4672b1fbc1ed1bad6 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Tue, 6 Oct 2015 18:47:52 +0300 Subject: [PATCH] setmnotwielded should always MON_NOWEP Instead of making the caller remember to use MON_NOWEP, make setmnotwielded handle that automatically. This fixes the "bad monster weapon restore" errors I've been seeing. Also adds sanity checks for this. --- src/dig.c | 4 +--- src/mkobj.c | 12 ++++++++++-- src/mthrowu.c | 4 +--- src/uhitm.c | 5 +---- src/weapon.c | 4 ++-- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/dig.c b/src/dig.c index 2fbabb631..a88db9e61 100644 --- a/src/dig.c +++ b/src/dig.c @@ -1973,10 +1973,8 @@ long timeout; /* unused */ stop_occupation(); } } else if (obj->where == OBJ_MINVENT && obj->owornmask) { - if (obj == MON_WEP(obj->ocarry)) { + if (obj == MON_WEP(obj->ocarry)) setmnotwielded(obj->ocarry, obj); - MON_NOWEP(obj->ocarry); - } } else if (obj->where == OBJ_MIGRATING) { /* clear destination flag so that obfree()'s check for freeing a worn object doesn't get a false hit */ diff --git a/src/mkobj.c b/src/mkobj.c index a65d51f61..c88410ff8 100644 --- a/src/mkobj.c +++ b/src/mkobj.c @@ -2156,9 +2156,16 @@ struct monst *monlist; const char *mesg; { struct monst *mon; - struct obj *obj; + struct obj *obj, *mwep; - for (mon = monlist; mon; mon = mon->nmon) + for (mon = monlist; mon; mon = mon->nmon) { + mwep = MON_WEP(mon); + if (mwep) { + if (!mcarried(mwep)) + insane_object(mwep, mfmt1, mesg, mon); + if (mwep->ocarry != mon) + insane_object(mwep, mfmt2, mesg, mon); + } for (obj = mon->minvent; obj; obj = obj->nobj) { if (obj->where != OBJ_MINVENT) insane_object(obj, mfmt1, mesg, mon); @@ -2166,6 +2173,7 @@ const char *mesg; insane_object(obj, mfmt2, mesg, mon); check_contained(obj, mesg); } + } } /* This must stay consistent with the defines in obj.h. */ diff --git a/src/mthrowu.c b/src/mthrowu.c index bf01f0358..ad4d7625b 100644 --- a/src/mthrowu.c +++ b/src/mthrowu.c @@ -282,10 +282,8 @@ struct obj *obj; /* missile (or stack providing it) */ /* not possibly_unwield, which checks the object's */ /* location, not its existence */ - if (MON_WEP(mon) == obj) { + if (MON_WEP(mon) == obj) setmnotwielded(mon, obj); - MON_NOWEP(mon); - } obj_extract_self(obj); singleobj = obj; obj = (struct obj *) 0; diff --git a/src/uhitm.c b/src/uhitm.c index 0f578c1ce..83d3163e4 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -670,7 +670,6 @@ int thrown; /* HMON_xxx (0 => hand-to-hand, other => ranged) */ * the percentage chance is (1/20)*(50/100).] */ setmnotwielded(mon, monwep); - MON_NOWEP(mon); mon->weapon_check = NEED_WEAPON; pline("%s from the force of your blow!", Yobjnam2(monwep, "shatter")); @@ -1349,10 +1348,8 @@ struct attack *mattk; obj_extract_self(otmp); if ((unwornmask = otmp->owornmask) != 0L) { mdef->misc_worn_check &= ~unwornmask; - if (otmp->owornmask & W_WEP) { + if (otmp->owornmask & W_WEP) setmnotwielded(mdef, otmp); - MON_NOWEP(mdef); - } otmp->owornmask = 0L; update_mon_intrinsics(mdef, otmp, FALSE, FALSE); diff --git a/src/weapon.c b/src/weapon.c index fc677a74e..9e77e5a2a 100644 --- a/src/weapon.c +++ b/src/weapon.c @@ -582,7 +582,6 @@ boolean polyspot; } if (!attacktype(mon->data, AT_WEAP)) { setmnotwielded(mon, mw_tmp); - MON_NOWEP(mon); mon->weapon_check = NO_WEAPON_WANTED; obj_extract_self(obj); if (cansee(mon->mx, mon->my)) { @@ -735,7 +734,6 @@ struct monst *mon; if (mwep) { setmnotwielded(mon, mwep); - MON_NOWEP(mon); mon->weapon_check = NEED_WEAPON; } } @@ -1443,6 +1441,8 @@ register struct obj *obj; s_suffix(mon_nam(mon)), mbodypart(mon, HAND), otense(obj, "stop")); } + if (MON_WEP(mon) == obj) + MON_NOWEP(mon); obj->owornmask &= ~W_WEP; }