]> granicus.if.org Git - nethack/commitdiff
fix github issue #564 - unicorn vs displaced hero
authorPatR <rankin@nethack.org>
Sat, 7 Aug 2021 00:59:53 +0000 (17:59 -0700)
committerPatR <rankin@nethack.org>
Sat, 7 Aug 2021 00:59:53 +0000 (17:59 -0700)
Unicorns attempted to avoid being in direct line with the hero's
actual location even when displacement causes unicorn to think hero
was at some other spot.  Change to avoid lining up with presumed
location even if that leaves the monster lined up with the hero.

While in mon.c, reorder the static function declarations near the
beginning of the file to match their order within it.

Fixes #564

doc/fixes37.0
src/mon.c

index 27f016a4a79649d864437e7cc06c761f80b30709..f59316e82aac81f87e7a088496f9af3e4ef93012 100644 (file)
@@ -775,6 +775,8 @@ using bhitpos in flooreffects to handle erosion damage broke its original use
 restore previous behavior of the 'altmeta' option (only wait for a second
        character when getting a command keystroke, not other key input)
 baby gold dragons weren't able to grow into adult gold dragons
+when hero is displaced, make monsters who try to stay out of direct line do so
+       with spot where they think the hero is rather than where he really is
 
 curses: 'msg_window' option wasn't functional for curses unless the binary
        also included tty support
index 1bebe1f53de3b969b6017cfa9e7d3f2b62352416..1122385c0f9713e6cf1fbad823542f3f1a05ae55 100644 (file)
--- a/src/mon.c
+++ b/src/mon.c
@@ -7,26 +7,26 @@
 #include "mfndpos.h"
 #include <ctype.h>
 
-static void sanity_check_single_mon(struct monst *, boolean,
-                                    const char *);
-static boolean restrap(struct monst *);
+static void sanity_check_single_mon(struct monst *, boolean, const char *);
+static struct obj *make_corpse(struct monst *, unsigned);
+static int minliquid_core(struct monst *);
+static boolean monlineu(struct monst *, int, int);
 static long mm_2way_aggression(struct monst *, struct monst *);
 static long mm_aggression(struct monst *, struct monst *);
 static long mm_displacement(struct monst *, struct monst *);
-static int pick_animal(void);
-static void kill_eggs(struct obj *);
-static int pickvampshape(struct monst *);
-static boolean isspecmon(struct monst *);
-static boolean validspecmon(struct monst *, int);
-static struct permonst *accept_newcham_form(struct monst *, int);
-static struct obj *make_corpse(struct monst *, unsigned);
-static int minliquid_core(struct monst *);
 static void m_detach(struct monst *, struct permonst *);
 static void set_mon_min_mhpmax(struct monst *, int);
 static void lifesaved_monster(struct monst *);
 static void migrate_mon(struct monst *, xchar, xchar);
 static boolean ok_to_obliterate(struct monst *);
 static void deal_with_overcrowding(struct monst *);
+static boolean restrap(struct monst *);
+static int pick_animal(void);
+static int pickvampshape(struct monst *);
+static boolean isspecmon(struct monst *);
+static boolean validspecmon(struct monst *, int);
+static struct permonst *accept_newcham_form(struct monst *, int);
+static void kill_eggs(struct obj *);
 
 #define LEVEL_SPECIFIC_NOCORPSE(mdat) \
     (Is_rogue_level(&u.uz)            \
@@ -1658,6 +1658,13 @@ can_carry(struct monst* mtmp, struct obj* otmp)
     return iquan;
 }
 
+/* is <nx,ny> in direct line with where 'mon' thinks hero is? */
+static boolean
+monlineu(struct monst *mon, int nx, int ny)
+{
+    return online2(nx, ny, mon->mux, mon->muy);
+}
+
 /* return flags based on monster data, for mfndpos() */
 long
 mon_allowflags(struct monst* mtmp)
@@ -1909,7 +1916,7 @@ mfndpos(
                         continue;
                     info[cnt] |= ALLOW_ROCK;
                 }
-                if (monseeu && onlineu(nx, ny)) {
+                if (monseeu && monlineu(mon, nx, ny)) {
                     if (flag & NOTONL)
                         continue;
                     info[cnt] |= NOTONL;
@@ -3159,8 +3166,8 @@ ok_to_obliterate(struct monst* mtmp)
 void
 elemental_clog(struct monst* mon)
 {
-    int m_lev = 0;
     static long msgmv = 0L;
+    int m_lev = 0;
     struct monst *mtmp, *m1, *m2, *m3, *m4, *m5, *zm;
 
     if (In_endgame(&u.uz)) {
@@ -4245,7 +4252,8 @@ newcham(
     }
     /* we need this one whether msg is true or not */
     Strcpy(l_oldname, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
-                               has_mgivenname(mtmp) ? SUPPRESS_SADDLE : 0, FALSE));
+                               has_mgivenname(mtmp) ? SUPPRESS_SADDLE : 0,
+                               FALSE));
 
     /* mdat = 0 -> caller wants a random monster shape */
     if (mdat == 0) {
@@ -4278,7 +4286,8 @@ newcham(
      * polymorphed, so dropping rank for mplayers seems reasonable.
      */
     if (In_endgame(&u.uz) && is_mplayer(olddata)
-        && has_mgivenname(mtmp) && (p = strstr(MGIVENNAME(mtmp), " the ")) != 0)
+        && has_mgivenname(mtmp)
+        && (p = strstr(MGIVENNAME(mtmp), " the ")) != 0)
         *p = '\0';
 
     if (mtmp->wormno) { /* throw tail away */