From 58031920dc6a9fff297a317ccb65de3cdfd90957 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Thu, 11 Jan 2024 19:19:00 +0200 Subject: [PATCH] Fix monsters using escape items unnecessarily Monsters were using escape items when they couldn't move due to being surrounded by other monsters. This was most evident in Fort Ludios, where the alarm woke up all the monsters and they would then read all the teleport scrolls. Usually this doesn't matter, as special rooms full of monsters are asleep. Hardcode this fix for the Ludios only, otherwise you could trap two monsters next to each other in a boulder fort, and they would be happy to stay in there... --- src/muse.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/muse.c b/src/muse.c index 4d381495b..3a5849be8 100644 --- a/src/muse.c +++ b/src/muse.c @@ -22,6 +22,7 @@ static void mquaffmsg(struct monst *, struct obj *); static boolean m_use_healing(struct monst *); static boolean m_sees_sleepy_soldier(struct monst *); static void m_tele(struct monst *, boolean, boolean, int); +static boolean m_next2m(struct monst *); static void reveal_trap(struct trap *, boolean); static boolean linedup_chk_corpse(coordxy, coordxy); static void m_use_undead_turning(struct monst *, struct obj *); @@ -398,6 +399,26 @@ m_tele( } } +/* return TRUE if monster mtmp has another monster next to it */ +static boolean +m_next2m(struct monst *mtmp) +{ + coordxy x, y; + struct monst *m2; + + if (DEADMONSTER(mtmp) || mon_offmap(mtmp)) + return FALSE; + + for (x = mtmp->mx - 1; x <= mtmp->mx + 1; x++) + for (y = mtmp->my - 1; y <= mtmp->my + 1; y++) { + if (!isok(x,y)) + continue; + if ((m2 = m_at(x, y)) && m2 != mtmp) + return TRUE; + } + return FALSE; +} + /* Select a defensive item/action for a monster. Returns TRUE iff one is found. */ boolean @@ -418,6 +439,9 @@ find_defensive(struct monst *mtmp, boolean tryescape) return FALSE; if (!tryescape && dist2(x, y, mtmp->mux, mtmp->muy) > 25) return FALSE; + if (tryescape && Is_knox(&u.uz) + && !next2u(mtmp->mx, mtmp->my) && m_next2m(mtmp)) + return FALSE; if (u.uswallow && stuck) return FALSE;