Skip to content

Commit 80d964c

Browse files
committed
Fix: mselftouch call was not guarded by a "lost gloves" check
xNetHack adds a mselftouch call in extract_from_minvent to handle cases like someone's glass gauntlets shattering and resulting in them handling a cockatrice corpse. But it was called every time a monster lost an inventory item without first checking whether the monster was actually losing gloves. (mselftouch itself, somewhat unintuitively, does not check whether the monster is still wearing gloves, an assumption I made explicit in a comment in this commit.) As a result, a monster could get insta-petrified while losing *any* inventory item while wielding a cockatrice corpse even if their gloves should have still protected them. This commit fixes that issue by only calling mselftouch in extract_from_minvent if the gloves are what's being extracted.
1 parent 7f1721f commit 80d964c

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

src/trap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3962,6 +3962,8 @@ mselftouch(
39623962
{
39633963
struct obj *mwep = MON_WEP(mon);
39643964

3965+
/* assume caller has already checked that mon is not wearing gloves, to
3966+
* avoid calling which_armor in this function */
39653967
if (mwep && mwep->otyp == CORPSE && touch_petrifies(&mons[mwep->corpsenm])
39663968
&& !resists_ston(mon)) {
39673969
if (cansee(mon->mx, mon->my)) {

src/worn.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,8 @@ extract_from_minvent(
14521452
if (do_extrinsics) {
14531453
update_mon_extrinsics(mon, obj, FALSE, silently);
14541454
}
1455-
mselftouch(mon, NULL, !svc.context.mon_moving);
1455+
if (unwornmask & W_ARMG)
1456+
mselftouch(mon, NULL, !svc.context.mon_moving);
14561457
}
14571458
mon->misc_worn_check &= ~unwornmask;
14581459
/* give monster a chance to wear other equipment on its next

0 commit comments

Comments
 (0)