fix github issue #106 - polymorph panic

Fixes #106

If dipping a worn amulet into a potion of polymorph turns it into an
amulet of change, the game panics while trying to use up that amulet
when the new one hasn't replaced the old one in inventory yet.  Simply
reordering the relevant code isn't sufficient to fix things:  once it
is in inventory and can be successfully used up, later code would end
up deferencing a stale pointer because it was unaware of the deletion.
This commit is contained in:
PatR
2018-06-17 16:59:58 -07:00
parent 78fca9bef0
commit 4bce58f665
5 changed files with 52 additions and 27 deletions

View File

@@ -29,7 +29,8 @@ const struct worn {
{ W_TOOL, &ublindf },
{ W_BALL, &uball },
{ W_CHAIN, &uchain },
{ 0, 0 } };
{ 0, 0 }
};
/* This only allows for one blocking item per property */
#define w_blocks(o, m) \
@@ -142,6 +143,19 @@ register struct obj *obj;
update_inventory();
}
/* return item worn in slot indiciated by wornmask; needed by poly_obj() */
struct obj *
wearmask_to_obj(wornmask)
long wornmask;
{
const struct worn *wp;
for (wp = worn; wp->w_mask; wp++)
if (wp->w_mask & wornmask)
return *wp->w_obj;
return (struct obj *) 0;
}
/* return a bitmask of the equipment slot(s) a given item might be worn in */
long
wearslot(obj)