]> granicus.if.org Git - nethack/commitdiff
dochugw(mon, X)
authorPatR <rankin@nethack.org>
Sat, 7 May 2022 16:11:09 +0000 (09:11 -0700)
committerPatR <rankin@nethack.org>
Sat, 7 May 2022 16:11:09 +0000 (09:11 -0700)
Reverse the sense of dochugw()'s new 'X' argument. Use True for the
usual case and False for the special case rather than the other way
around.

Call the special case variant when a monster teleports so that hero
stops occupation if the monster jumps to a position where it becomes
a threat.

src/makemon.c
src/mon.c
src/monmove.c
src/teleport.c

index 61f6ca255dafbdc2d86d804801e80495636b113f..dd6e3b439a689a8de5951a8bbc13926e7025d04a 100644 (file)
@@ -1458,7 +1458,7 @@ makemon(
         }
         /* if discernable and a threat, stop fiddling while Rome burns */
         if (g.occupation)
-            (void) dochugw(mtmp, TRUE);
+            (void) dochugw(mtmp, FALSE);
 
         /* TODO: unify with teleport appears msg */
     }
index 603cc437055a3fdda26b2cce3c805792762b0d6f..2686c3e981bcf0fa085e386f14c8df576afb2e86 100644 (file)
--- a/src/mon.c
+++ b/src/mon.c
@@ -1064,7 +1064,7 @@ movemon(void)
                 && fightm(mtmp))
                 continue; /* mon might have died */
         }
-        if (dochugw(mtmp, FALSE)) /* otherwise just move the monster */
+        if (dochugw(mtmp, TRUE)) /* otherwise just move the monster */
             continue;
     }
 
index 722dfb7b533aaa913700804eeb96313b64a65247..aed2ab2654d947fb34c4c85a9ebb49096ece29d1 100644 (file)
@@ -113,14 +113,15 @@ watch_on_duty(register struct monst* mtmp)
 int
 dochugw(
     register struct monst *mtmp,
-    boolean dontchug) /* True: monster was just created, or maybe it has
-                       * teleported; perform stop-what-you're-doing-if-close-
-                       * enough-to-be-a-threat check but don't move mtmp */
+    boolean chug) /* True: monster is moving;
+                   * False: monster was just created or has teleported
+                   * so perform stop-what-you're-doing-if-close-enough-
+                   * to-be-a-threat check but don't move mtmp */
 {
-    int x = mtmp->mx, y = mtmp->my;
-    boolean already_saw_mon = ((dontchug || !g.occupation) ? 0
-                               : canspotmon(mtmp));
-    int rd = dontchug ? 0 : dochug(mtmp);
+    int x = mtmp->mx, y = mtmp->my; /* 'mtmp's location before dochug() */
+    /* skip canspotmon() if occupation is Null */
+    boolean already_saw_mon = (chug && g.occupation) ? canspotmon(mtmp) : 0;
+    int rd = chug ? dochug(mtmp) : 0;
 
     /*
      * A similar check is in monster_nearby() in hack.c.
index 82d49e425263dd4286de25264d0b7618b0c61b58..71fd3777773769fa8e8e565bd294658d2ee9caf9 100644 (file)
@@ -1324,15 +1324,16 @@ rloc_to_core(
                   Monnam(mtmp),
                   next2u(x, y) ? " next to you"
                   : (distu(x, y) <= (BOLT_LIM * BOLT_LIM)) ? " close by"
-                  : (distu(x, y) < distu(oldx, oldy)) ? " closer to you"
-                  : " further away");
+                    : (distu(x, y) < distu(oldx, oldy)) ? " closer to you"
+                      : " further away");
         } else {
             pline("%s %s%s%s!",
                   appearmsg ? Amonnam(mtmp) : Monnam(mtmp),
                   appearmsg ? "suddenly " : "",
                   !Blind ? "appears" : "arrives",
                   next2u(x, y) ? " next to you"
-                  : (distu(x, y) <= (BOLT_LIM * BOLT_LIM)) ? " close by" : "");
+                  : (distu(x, y) <= (BOLT_LIM * BOLT_LIM)) ? " close by"
+                    : "");
         }
     }
 
@@ -1342,6 +1343,10 @@ rloc_to_core(
     if (resident_shk && !inhishop(mtmp))
         make_angry_shk(mtmp, oldx, oldy);
 
+    /* if hero is busy, maybe stop occupation */
+    if (g.occupation)
+        (void) dochugw(mtmp, FALSE);
+
     /* trapped monster teleported away */
     if (mtmp->mtrapped && !mtmp->wormno)
         (void) mintrap(mtmp, NO_TRAP_FLAGS);