From b0f3371147383c72aa024be3e2b30d0702069485 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sat, 20 Aug 2022 21:49:51 +0300 Subject: [PATCH] Monsters try to escape from boulder forts If a monster cannot move, for example because it's being blocked off by boulders or walls, it will try to escape by some method - such as a wand or scroll of teleportation. --- doc/fixes3-7-0.txt | 1 + include/extern.h | 2 +- src/monmove.c | 7 +++++-- src/muse.c | 25 ++++++++++++++----------- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index 67d36cd91..4c596004c 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -1012,6 +1012,7 @@ if a pet gelatinous cube eats a container, treat it the same as when a hostile when breaking a wand of sleep hits the hero with the explosion, don't describe that as "the sleep ray hits you" expose fuz tester to wizard-mode as #fuzzer extended command +monsters which cannot move due to boulders or walls try to escape Fixes to 3.7.0-x Problems that Were Exposed Via git Repository diff --git a/include/extern.h b/include/extern.h index 54f4270b1..d60e45f64 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1766,7 +1766,7 @@ extern boolean hits_bars(struct obj **, coordxy, coordxy, coordxy, coordxy, int, /* ### muse.c ### */ -extern boolean find_defensive(struct monst *); +extern boolean find_defensive(struct monst *, boolean); extern int use_defensive(struct monst *); extern int rnd_defensive_item(struct monst *); extern boolean find_offensive(struct monst *); diff --git a/src/monmove.c b/src/monmove.c index a36fa4134..cd41829ec 100644 --- a/src/monmove.c +++ b/src/monmove.c @@ -645,7 +645,7 @@ dochug(register struct monst* mtmp) distfleeck(mtmp, &inrange, &nearby, &scared); /* search for and potentially use defensive or miscellaneous items. */ - if (find_defensive(mtmp)) { + if (find_defensive(mtmp, FALSE)) { if (use_defensive(mtmp) != 0) return 1; } else if (find_misc(mtmp)) { @@ -1391,8 +1391,11 @@ m_move(register struct monst* mtmp, register int after) coord poss[9]; cnt = mfndpos(mtmp, poss, info, flag); - if (cnt == 0) + if (cnt == 0) { + if (find_defensive(mtmp, TRUE)) + (void) use_defensive(mtmp); return MMOVE_NOMOVES; + } chcnt = 0; jcnt = min(MTSZ, cnt - 1); chi = -1; diff --git a/src/muse.c b/src/muse.c index c4943780d..9b0fa86fe 100644 --- a/src/muse.c +++ b/src/muse.c @@ -350,7 +350,7 @@ m_sees_sleepy_soldier(struct monst *mtmp) /* Select a defensive item/action for a monster. Returns TRUE iff one is found. */ boolean -find_defensive(struct monst* mtmp) +find_defensive(struct monst* mtmp, boolean tryescape) { struct obj *obj; struct trap *t; @@ -365,7 +365,7 @@ find_defensive(struct monst* mtmp) if (is_animal(mtmp->data) || mindless(mtmp->data)) return FALSE; - if (dist2(x, y, mtmp->mux, mtmp->muy) > 25) + if (!tryescape && dist2(x, y, mtmp->mux, mtmp->muy) > 25) return FALSE; if (u.uswallow && stuck) return FALSE; @@ -448,17 +448,20 @@ find_defensive(struct monst* mtmp) } } - fraction = u.ulevel < 10 ? 5 : u.ulevel < 14 ? 4 : 3; - if (mtmp->mhp >= mtmp->mhpmax - || (mtmp->mhp >= 10 && mtmp->mhp * fraction >= mtmp->mhpmax)) - return FALSE; + if (!tryescape) { + /* do we try to heal? */ + fraction = u.ulevel < 10 ? 5 : u.ulevel < 14 ? 4 : 3; + if (mtmp->mhp >= mtmp->mhpmax + || (mtmp->mhp >= 10 && mtmp->mhp * fraction >= mtmp->mhpmax)) + return FALSE; - if (mtmp->mpeaceful) { - if (!nohands(mtmp->data)) { - if (m_use_healing(mtmp)) - return TRUE; + if (mtmp->mpeaceful) { + if (!nohands(mtmp->data)) { + if (m_use_healing(mtmp)) + return TRUE; + } + return FALSE; } - return FALSE; } if (stuck || immobile) {