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:
copperwater
2021-01-24 16:39:33 -05:00
parent 7b357463d3
commit ee7664684a
9 changed files with 65 additions and 110 deletions

View File

@@ -1878,21 +1878,11 @@ remove_object(struct obj* otmp)
void
discard_minvent(struct monst* mtmp, boolean uncreate_artifacts)
{
struct obj *otmp, *mwep = MON_WEP(mtmp);
boolean keeping_mon = !DEADMONSTER(mtmp);
struct obj *otmp;
while ((otmp = mtmp->minvent) != 0) {
/* this has now become very similar to m_useupall()... */
obj_extract_self(otmp);
if (otmp->owornmask) {
if (keeping_mon) {
if (otmp == mwep)
mwepgone(mtmp), mwep = 0;
mtmp->misc_worn_check &= ~otmp->owornmask;
update_mon_intrinsics(mtmp, otmp, FALSE, TRUE);
}
otmp->owornmask = 0L; /* obfree() expects this */
}
extract_from_minvent(mtmp, otmp, TRUE, TRUE);
if (uncreate_artifacts && otmp->oartifact)
artifact_exists(otmp, safe_oname(otmp), FALSE);
obfree(otmp, (struct obj *) 0); /* dealloc_obj() isn't sufficient */