]> granicus.if.org Git - nethack/commitdiff
Monsters try to escape from boulder forts
authorPasi Kallinen <paxed@alt.org>
Sat, 20 Aug 2022 18:49:51 +0000 (21:49 +0300)
committerPasi Kallinen <paxed@alt.org>
Sat, 20 Aug 2022 18:49:55 +0000 (21:49 +0300)
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
include/extern.h
src/monmove.c
src/muse.c

index 67d36cd91fce4087792ec1ae66d07b603d1d956a..4c596004c07347c5402c390ff86bca21fda9bf01 100644 (file)
@@ -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
index 54f4270b11316836390ba2f978bca2afe9ae5f72..d60e45f6476ecb82b8386971336ae048c8232a85 100644 (file)
@@ -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 *);
index a36fa4134d1975d35edab8ef9c043980fa44d07d..cd41829ec88b85b9b8ed976d970fa4fe3a2e7b5d 100644 (file)
@@ -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;
index c4943780de40487b08ad73421eec634fa9c18880..9b0fa86fe82b8e98bf70cb6dc76660768d2d811e 100644 (file)
@@ -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) {