diff --git a/src/mkobj.c b/src/mkobj.c index 2f93d43c8..a7687ca8a 100644 --- a/src/mkobj.c +++ b/src/mkobj.c @@ -3189,7 +3189,7 @@ mon_obj_sanity(struct monst *monlist, const char *mesg) for (mon = monlist; mon; mon = mon->nmon) { if (DEADMONSTER(mon)) continue; - mwep = MON_WEP(mon); + mwep = MON_WEP(mon); /* mon->mw */ if (mwep) { if (!mcarried(mwep)) insane_object(mwep, mfmt1, mesg, mon); @@ -3209,6 +3209,18 @@ mon_obj_sanity(struct monst *monlist, const char *mesg) if (obj->in_use || obj->bypass || obj->nomerge || (obj->otyp == BOULDER && obj->next_boulder)) insane_obj_bits(obj, mon); + if (obj == mwep) + mwep = (struct obj *) 0; + } + if (mwep) { + /* this is a monster check rather than an object check, but doing + it here avoids making an extra pass through mon's minvent; + if the full pass through that list hasn't reset mwep to Null, + then mwep isn't in that list where it should be */ + impossible("monst (%s: %u) wielding %s (%u) not in %s inventory", + pmname(mon->data, Mgender(mon)), mon->m_id, + safe_typename(mwep->otyp), mwep->o_id, mhis(mon)); + } } } diff --git a/src/mon.c b/src/mon.c index 92a71c12a..ade679695 100644 --- a/src/mon.c +++ b/src/mon.c @@ -233,19 +233,6 @@ sanity_check_single_mon( mtmp->m_id, distu(mtmp->mx, mtmp->my)); #endif } - if (MON_WEP(mtmp)) { /* mtmp->mw */ - struct obj *o; - - for (o = mtmp->minvent; o; o = o->nobj) - if (o == MON_WEP(mtmp)) - break; - if (!o) { - o = MON_WEP(mtmp); - impossible("monst (%s: %u) wielding %s (%u) not in inventory", - pmname(mtmp->data, Mgender(mtmp)), mtmp->m_id, - safe_typename(o->otyp), o->o_id); - } - } } void