From 810744a27dfb6413bf345befd4f5a441f26deb9a Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Tue, 26 Jul 2022 23:17:54 +0300 Subject: [PATCH] Fix knockbacked monster migrating or killed Fix a case where a monster knocked back another monster into a trap, and the trap either killed or migrated the monster, then the actual damage dealing later could try to detach the already detached monster. If the monster migrated, the monster is gone before the damage from the hit is dealt to the monster. --- src/mhitm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mhitm.c b/src/mhitm.c index 0118bc95b..7bdd48495 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -947,7 +947,11 @@ mdamagem(struct monst *magr, struct monst *mdef, mhitm_adtyping(magr, mattk, mdef, &mhm); - (void) mhitm_knockback(magr, mdef, mattk, &mhm.hitflags, (MON_WEP(magr) != 0)); + if (mhitm_knockback(magr, mdef, mattk, &mhm.hitflags, + (MON_WEP(magr) != 0)) + && ((mhm.hitflags & MM_DEF_DIED) != 0 + || (mdef->mstate & (MON_DETACH|MON_MIGRATING|MON_LIMBO)) != 0)) + return mhm.hitflags; if (mhm.done) return mhm.hitflags;