]> granicus.if.org Git - nethack/commitdiff
Unify mfndpos monster movement flags
authorPasi Kallinen <paxed@alt.org>
Sat, 28 Nov 2020 10:48:09 +0000 (12:48 +0200)
committerPasi Kallinen <paxed@alt.org>
Sat, 28 Nov 2020 10:49:18 +0000 (12:49 +0200)
include/extern.h
src/dogmove.c
src/mon.c
src/monmove.c
src/priest.c

index f2e2ba258649e0a145cea42100bcb1ad013ccdfb..3be154e704b2069b8fc81f76802231536a9b02b4 100644 (file)
@@ -1482,6 +1482,7 @@ E boolean FDECL(mpickstuff, (struct monst *, const char *));
 E int FDECL(curr_mon_load, (struct monst *));
 E int FDECL(max_mon_load, (struct monst *));
 E int FDECL(can_carry, (struct monst *, struct obj *));
+E long FDECL(mon_allowflags, (struct monst *));
 E int FDECL(mfndpos, (struct monst *, coord *, long *, long));
 E boolean FDECL(monnear, (struct monst *, int, int));
 E void NDECL(dmonsfree);
index 30a2f8725928939e8aa72406eefa2aaf18b3a888..e4f8f4513c1d2d1d1a8c4c078dd102f9036f0e15 100644 (file)
@@ -934,17 +934,7 @@ int after; /* this is extra fast monster movement */
     if (appr == -2)
         return 0;
 
-    allowflags = ALLOW_M | ALLOW_TRAPS | ALLOW_SSM | ALLOW_SANCT;
-    if (passes_walls(mtmp->data))
-        allowflags |= (ALLOW_ROCK | ALLOW_WALL);
-    if (passes_bars(mtmp->data))
-        allowflags |= ALLOW_BARS;
-    if (throws_rocks(mtmp->data))
-        allowflags |= ALLOW_ROCK;
-    if (is_displacer(mtmp->data))
-        allowflags |= ALLOW_MDISP;
     if (Conflict && !resist(mtmp, RING_CLASS, 0, 0)) {
-        allowflags |= ALLOW_U;
         if (!has_edog) {
             /* Guardian angel refuses to be conflicted; rather,
              * it disappears, angrily, and sends in some nasties
@@ -960,18 +950,7 @@ int after; /* this is extra fast monster movement */
         You("get released!");
     }
 #endif
-    if (!nohands(mtmp->data) && !verysmall(mtmp->data)) {
-        allowflags |= OPENDOOR;
-        if (monhaskey(mtmp, TRUE))
-            allowflags |= UNLOCKDOOR;
-        /* note:  the Wizard and Riders can unlock doors without a key;
-           they won't use that ability if someone manages to tame them */
-    }
-    if (is_giant(mtmp->data))
-        allowflags |= BUSTDOOR;
-    if (tunnels(mtmp->data)
-        && !Is_rogue_level(&u.uz)) /* same restriction as m_move() */
-        allowflags |= ALLOW_DIG;
+    allowflags = mon_allowflags(mtmp);
     cnt = mfndpos(mtmp, poss, info, allowflags);
 
     /* Normally dogs don't step on cursed items, but if they have no
index 476b36ce6b677dfc001f6b99e04a590c82410283..38a2992c6651913a87ece26d80a8945c4edcdf9d 100644 (file)
--- a/src/mon.c
+++ b/src/mon.c
@@ -1541,6 +1541,65 @@ struct obj *otmp;
     return iquan;
 }
 
+/* return flags based on monster data, for mfndpos() */
+long
+mon_allowflags(mtmp)
+struct monst *mtmp;
+{
+    long flags = 0L;
+    boolean can_open = !(nohands(mtmp->data) || verysmall(mtmp->data));
+    boolean can_unlock = ((can_open && monhaskey(mtmp, TRUE))
+                          || mtmp->iswiz || is_rider(mtmp->data));
+    boolean doorbuster = is_giant(mtmp->data);
+
+    if (mtmp->mtame)
+        flags |= ALLOW_M | ALLOW_TRAPS | ALLOW_SANCT | ALLOW_SSM;
+    else if (mtmp->mpeaceful)
+        flags |= ALLOW_SANCT | ALLOW_SSM;
+    else
+        flags |= ALLOW_U;
+    if (Conflict && !resist(mtmp, RING_CLASS, 0, 0))
+        flags |= ALLOW_U;
+    if (mtmp->isshk)
+        flags |= ALLOW_SSM;
+    if (mtmp->ispriest)
+        flags |= ALLOW_SSM | ALLOW_SANCT;
+    if (passes_walls(mtmp->data))
+        flags |= (ALLOW_ROCK | ALLOW_WALL);
+    if (throws_rocks(mtmp->data))
+        flags |= ALLOW_ROCK;
+    if (tunnels(mtmp->data)
+        && !Is_rogue_level(&u.uz)) /* same restriction as m_move() */
+        flags |= ALLOW_DIG;
+    if (doorbuster)
+        flags |= BUSTDOOR;
+    if (can_open)
+        flags |= OPENDOOR;
+    if (can_unlock)
+        flags |= UNLOCKDOOR;
+    if (passes_bars(mtmp->data))
+        flags |= ALLOW_BARS;
+    if (is_displacer(mtmp->data))
+        flags |= ALLOW_MDISP;
+    if (is_minion(mtmp->data) || is_rider(mtmp->data))
+        flags |= ALLOW_SANCT;
+    /* unicorn may not be able to avoid hero on a noteleport level */
+    if (is_unicorn(mtmp->data) && !noteleport_level(mtmp))
+        flags |= NOTONL;
+    if (passes_walls(mtmp->data))
+        flags |= (ALLOW_WALL | ALLOW_ROCK);
+    if (passes_bars(mtmp->data))
+        flags |= ALLOW_BARS;
+    if (is_human(mtmp->data) || mtmp->data == &mons[PM_MINOTAUR])
+        flags |= ALLOW_SSM;
+    if ((is_undead(mtmp->data) && mtmp->data->mlet != S_GHOST) || is_vampshifter(mtmp))
+        flags |= NOGARLIC;
+    if (throws_rocks(mtmp->data))
+        flags |= ALLOW_ROCK;
+
+    return flags;
+}
+
 /* return number of acceptable neighbour positions */
 int
 mfndpos(mon, poss, info, flag)
index 00986f4fb35540241b70e0b174da17f0389c01be..dc64ae9d2657904dd8edbb7f7f96f7799092f801 100644 (file)
@@ -1173,34 +1173,7 @@ register int after;
 
     nix = omx;
     niy = omy;
-    flag = 0L;
-    if (mtmp->mpeaceful && (!Conflict || resist(mtmp, RING_CLASS, 0, 0)))
-        flag |= (ALLOW_SANCT | ALLOW_SSM);
-    else
-        flag |= ALLOW_U;
-    if (is_minion(ptr) || is_rider(ptr))
-        flag |= ALLOW_SANCT;
-    /* unicorn may not be able to avoid hero on a noteleport level */
-    if (is_unicorn(ptr) && !noteleport_level(mtmp))
-        flag |= NOTONL;
-    if (passes_walls(ptr))
-        flag |= (ALLOW_WALL | ALLOW_ROCK);
-    if (passes_bars(ptr))
-        flag |= ALLOW_BARS;
-    if (can_tunnel)
-        flag |= ALLOW_DIG;
-    if (is_human(ptr) || ptr == &mons[PM_MINOTAUR])
-        flag |= ALLOW_SSM;
-    if ((is_undead(ptr) && ptr->mlet != S_GHOST) || is_vampshifter(mtmp))
-        flag |= NOGARLIC;
-    if (throws_rocks(ptr))
-        flag |= ALLOW_ROCK;
-    if (can_open)
-        flag |= OPENDOOR;
-    if (can_unlock)
-        flag |= UNLOCKDOOR;
-    if (doorbuster)
-        flag |= BUSTDOOR;
+    flag = mon_allowflags(mtmp);
     {
         register int i, j, nx, ny, nearer;
         int jcnt, cnt;
index f7a8b0c49d015b30f6e7594fecba1e1225dd484d..3b0c6c1e5bd57f16b5b93b2211cd4b9838250328 100644 (file)
@@ -67,23 +67,7 @@ register xchar omx, omy, gx, gy;
 
     nix = omx;
     niy = omy;
-    if (mtmp->isshk)
-        allowflags = ALLOW_SSM;
-    else
-        allowflags = ALLOW_SSM | ALLOW_SANCT;
-    if (passes_walls(mtmp->data))
-        allowflags |= (ALLOW_ROCK | ALLOW_WALL);
-    if (throws_rocks(mtmp->data))
-        allowflags |= ALLOW_ROCK;
-    if (tunnels(mtmp->data))
-        allowflags |= ALLOW_DIG;
-    if (!nohands(mtmp->data) && !verysmall(mtmp->data)) {
-        allowflags |= OPENDOOR;
-        if (monhaskey(mtmp, TRUE))
-            allowflags |= UNLOCKDOOR;
-    }
-    if (is_giant(mtmp->data))
-        allowflags |= BUSTDOOR;
+    allowflags = mon_allowflags(mtmp);
     cnt = mfndpos(mtmp, poss, info, allowflags);
 
     if (mtmp->isshk && avoid && uondoor) { /* perhaps we cannot avoid him */