Unify code for extracting an object from a monster's inventory
The code for doing this (basically an obj_extract_self() call plus handling if the object was worn or wielded) was duplicated all over, and inconsistent - for instance, though all of them updated the monster's misc_worn_check to indicate it was no longer wearing something in whatever slot, only one call also set the bit that flags the monster to consider putting on other gear afterwards. Under a new function, extract_from_minvent, all this extra handling is checked in one function, which can simply replace the obj_extract_self call. A few callers (such as stealing) have some common code *after* the object is extracted and some other things happen such as message printing, such as calling mselftouch if the object was worn gloves. extract_from_minvent does not handle these cases.
This commit is contained in:
34
src/uhitm.c
34
src/uhitm.c
@@ -1626,22 +1626,14 @@ steal_it(struct monst *mdef, struct attack *mattk)
|
||||
mpickobj(mdef, gold), gold = 0;
|
||||
if (!Upolyd)
|
||||
break; /* no longer have ability to steal */
|
||||
unwornmask = otmp->owornmask;
|
||||
/* take the object away from the monster */
|
||||
obj_extract_self(otmp);
|
||||
if ((unwornmask = otmp->owornmask) != 0L) {
|
||||
mdef->misc_worn_check &= ~unwornmask;
|
||||
if (otmp->owornmask & W_WEP)
|
||||
setmnotwielded(mdef, otmp);
|
||||
otmp->owornmask = 0L;
|
||||
update_mon_intrinsics(mdef, otmp, FALSE, FALSE);
|
||||
/* give monster a chance to wear other equipment on its next
|
||||
move instead of waiting until it picks something up */
|
||||
mdef->misc_worn_check |= I_SPECIAL;
|
||||
|
||||
if (otmp == ustealo) /* special message for final item */
|
||||
pline("%s finishes taking off %s suit.", Monnam(mdef),
|
||||
mhis(mdef));
|
||||
}
|
||||
extract_from_minvent(mdef, otmp, TRUE, FALSE);
|
||||
/* special message for final item; no need to check owornmask because
|
||||
* ustealo is only set on objects with (owornmask & W_ARM) */
|
||||
if (otmp == ustealo)
|
||||
pline("%s finishes taking off %s suit.", Monnam(mdef),
|
||||
mhis(mdef));
|
||||
/* give the object to the character */
|
||||
otmp = hold_another_object(otmp, "You snatched but dropped %s.",
|
||||
doname(otmp), "You steal: ");
|
||||
@@ -3917,17 +3909,7 @@ mhitm_ad_sedu(struct monst *magr, struct attack *mattk, struct monst *mdef,
|
||||
if (u.usteed == mdef && obj == which_armor(mdef, W_SADDLE))
|
||||
/* "You can no longer ride <steed>." */
|
||||
dismount_steed(DISMOUNT_POLY);
|
||||
obj_extract_self(obj);
|
||||
if (obj->owornmask) {
|
||||
mdef->misc_worn_check &= ~obj->owornmask;
|
||||
if (obj->owornmask & W_WEP)
|
||||
mwepgone(mdef);
|
||||
obj->owornmask = 0L;
|
||||
update_mon_intrinsics(mdef, obj, FALSE, FALSE);
|
||||
/* give monster a chance to wear other equipment on its next
|
||||
move instead of waiting until it picks something up */
|
||||
mdef->misc_worn_check |= I_SPECIAL;
|
||||
}
|
||||
extract_from_minvent(mdef, obj, TRUE, FALSE);
|
||||
/* add_to_minv() might free 'obj' [if it merges] */
|
||||
if (g.vis)
|
||||
Strcpy(onambuf, doname(obj));
|
||||
|
||||
Reference in New Issue
Block a user