From 1fd3bb661f82c5f76b2f2924afec92bb0cc42b18 Mon Sep 17 00:00:00 2001 From: PatR Date: Tue, 25 Feb 2025 09:54:14 -0800 Subject: [PATCH] fix issue #1378 - brain eaten after flayer's death Issue reported by Umbire: if a mind flayer got turned to stone by hitting a hero who is polymorphed into a cockatrice and the first tentacle drain missed but a subsequent one hit, any remaining ones would keep being applied even though the mind flayer was dead. This works but doesn't feel right to me. A more substantial change to mhitm_ad_drin() didn't work as expected so I've settled for this. Fixes #1378 --- src/eat.c | 8 +++++++- src/mhitu.c | 9 +++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/eat.c b/src/eat.c index a73cf2080..b15f36ade 100644 --- a/src/eat.c +++ b/src/eat.c @@ -1,4 +1,4 @@ -/* NetHack 3.7 eat.c $NHDT-Date: 1715177703 2024/05/08 14:15:03 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.334 $ */ +/* NetHack 3.7 eat.c $NHDT-Date: 1740534854 2025/02/25 17:54:14 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.344 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */ /* NetHack may be freely redistributed. See license for details. */ @@ -610,6 +610,12 @@ eat_brains( boolean give_nutrit = FALSE; int result = M_ATTK_HIT, xtra_dmg = rnd(10); + /* previous tentacle attack might have triggered fatal passive + counterattack [callers ought to be updated to avoid this situation] */ + if (magr != &gy.youmonst && DEADMONSTER(magr)) { + return M_ATTK_AGR_DIED; + } + if (noncorporeal(pd)) { if (visflag) pline("%s brain is unharmed.", diff --git a/src/mhitu.c b/src/mhitu.c index 904321a51..32cb68a14 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -1,4 +1,4 @@ -/* NetHack 3.7 mhitu.c $NHDT-Date: 1721844072 2024/07/24 18:01:12 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.318 $ */ +/* NetHack 3.7 mhitu.c $NHDT-Date: 1740534854 2025/02/25 17:54:14 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.327 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */ /* NetHack may be freely redistributed. See license for details. */ @@ -486,7 +486,9 @@ mattacku(struct monst *mtmp) if (!ranged) nomul(0); - if (DEADMONSTER(mtmp) || (Underwater && !is_swimmer(mtmp->data))) + if (DEADMONSTER(mtmp)) + return 1; + if (Underwater && !is_swimmer(mtmp->data)) return 0; /* If swallowed, can only be affected by u.ustuck */ @@ -741,6 +743,9 @@ mattacku(struct monst *mtmp) for (i = 0; i < NATTK; i++) { sum[i] = M_ATTK_MISS; + /* counterattack against attack [i-1] might have been fatal */ + if (DEADMONSTER(mtmp)) + return 1; if (i > 0) { /* recalc in case prior attack moved hero; mtmp doesn't make another attempt to guess your location but might have