From 9ca1c5fb5696af5d730a278444e83b26a1c1464c Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sun, 7 May 2023 22:02:01 +0300 Subject: [PATCH] Fix dmonsfree warning caused by knockback When a monster being attacked was knocked back into a level teleport trap, the attacker could still hit the defender. If the second hit then killed the defender, this could result in dmonsfree warning. --- include/monst.h | 2 ++ src/mhitm.c | 3 +++ src/mon.c | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/monst.h b/include/monst.h index 86ab245e8..080039ece 100644 --- a/include/monst.h +++ b/include/monst.h @@ -241,6 +241,8 @@ struct monst { #define engulfing_u(mon) (u.uswallow && (u.ustuck == (mon))) #define helpless(mon) ((mon)->msleeping || !(mon)->mcanmove) +#define mon_offmap(mon) (((mon)->mstate & (MON_DETACH|MON_MIGRATING|MON_LIMBO|MON_OFFMAP)) != 0) + /* Get the maximum difficulty monsters that can currently be generated, given the current level difficulty and the hero's level. */ #define monmax_difficulty(levdif) (((levdif) + u.ulevel) / 2) diff --git a/src/mhitm.c b/src/mhitm.c index 53de130ca..0eee0e3d8 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -559,6 +559,9 @@ mattackm(register struct monst *magr, register struct monst *mdef) /* return if aggressor can no longer attack */ if (helpless(magr)) return res[i]; + /* eg. defender was knocked into a level teleport trap */ + if (mon_offmap(mdef)) + return res[i]; if (res[i] & M_ATTK_HIT) struck = 1; /* at least one hit */ } /* for (;i < NATTK;) loop */ diff --git a/src/mon.c b/src/mon.c index f5249f68c..46010b9ba 100644 --- a/src/mon.c +++ b/src/mon.c @@ -989,7 +989,7 @@ movemon_singlemon(struct monst *mtmp) return FALSE; /* monster isn't on this map anymore */ - if ((mtmp->mstate & (MON_DETACH|MON_MIGRATING|MON_LIMBO|MON_OFFMAP)) != 0) + if (mon_offmap(mtmp)) return FALSE; /* Find a monster that we have not treated yet. */