]> granicus.if.org Git - nethack/commitdiff
Use macro for a location next to hero
authorPasi Kallinen <paxed@alt.org>
Sat, 12 Feb 2022 09:05:07 +0000 (11:05 +0200)
committerPasi Kallinen <paxed@alt.org>
Sat, 12 Feb 2022 09:05:10 +0000 (11:05 +0200)
23 files changed:
include/you.h
src/apply.c
src/dig.c
src/display.c
src/do.c
src/do_name.c
src/dothrow.c
src/explode.c
src/hack.c
src/mail.c
src/makemon.c
src/mhitu.c
src/mon.c
src/monmove.c
src/muse.c
src/pager.c
src/priest.c
src/shk.c
src/sounds.c
src/teleport.c
src/trap.c
src/uhitm.c
src/wizard.c

index 39312314a5ffee74d5d772da811dfbf3d7f8b7d9..8b3adaff343d69620673e27a12fa7fc36595bea5 100644 (file)
@@ -484,4 +484,7 @@ struct you {
 #define Upolyd (u.umonnum != u.umonster)
 #define Ugender ((Upolyd ? u.mfemale : flags.female) ? 1 : 0)
 
+/* point px,py is adjacent to (or same location as) hero */
+#define next2u(px,py) (distu((px),(py)) <= 2)
+
 #endif /* YOU_H */
index b7ffd6f35d48916ec8678481ce9e4eda3fed39f6..4ef07611074463159fc28ab8cad736c47ceaf28e 100644 (file)
@@ -503,7 +503,7 @@ use_magic_whistle(struct obj *obj)
                 if (M_AP_TYPE(mtmp))
                     seemimic(mtmp);
                 omx = mtmp->mx, omy = mtmp->my;
-                if (distu(omx, omy) > 2)
+                if (!next2u(omx, omy))
                     mnexto(mtmp, RLOC_MSG);
                 if (mtmp->mx != omx || mtmp->my != omy) {
                     mtmp->mundetected = 0; /* reveal non-mimic hider */
@@ -728,9 +728,9 @@ next_to_u(void)
         if (DEADMONSTER(mtmp))
             continue;
         if (mtmp->mleashed) {
-            if (distu(mtmp->mx, mtmp->my) > 2)
+            if (!next2u(mtmp->mx, mtmp->my))
                 mnexto(mtmp, RLOC_NOMSG);
-            if (distu(mtmp->mx, mtmp->my) > 2) {
+            if (!next2u(mtmp->mx, mtmp->my)) {
                 for (otmp = g.invent; otmp; otmp = otmp->nobj)
                     if (otmp->otyp == LEASH
                         && (unsigned) otmp->leashmon == mtmp->m_id) {
index fb3c38239c2bb1b1bb82c494442cca0c16d8847f..d96eeb944ce672bca492e350cfd34ca91f6e5933 100644 (file)
--- a/src/dig.c
+++ b/src/dig.c
@@ -240,7 +240,7 @@ dig(void)
     if (u.uswallow || !uwep || (!ispick && !is_axe(uwep))
         || !on_level(&g.context.digging.level, &u.uz)
         || ((g.context.digging.down ? (dpx != u.ux || dpy != u.uy)
-                                  : (distu(dpx, dpy) > 2))))
+                                  : !next2u(dpx, dpy))))
         return 0;
 
     if (g.context.digging.down) {
index 5a7ee14e1811d59e1a87c0a2a4bf4d7a3eabecd2..fc20048fc88b952a9372b3d289e82f8cf6d4c102 100644 (file)
@@ -756,7 +756,7 @@ newsym(register int x, register int y)
     if (Underwater && !Is_waterlevel(&u.uz)) {
         /* when underwater, don't do anything unless <x,y> is an
            adjacent water or lava or ice position */
-        if (!(is_pool_or_lava(x, y) || is_ice(x, y)) || distu(x, y) > 2)
+        if (!(is_pool_or_lava(x, y) || is_ice(x, y)) || !next2u(x, y))
             return;
     }
 
index 9588fd91fd2e58c8e9013c9b6ee21e9a61147175..481c12ca080bab943fa89ef47759c27279399e4f 100644 (file)
--- a/src/do.c
+++ b/src/do.c
@@ -111,7 +111,7 @@ boulder_hits_pool(struct obj *otmp, int rx, int ry, boolean pushing)
                 docrt();
                 g.vision_full_recalc = 1;
                 You("find yourself on dry land again!");
-            } else if (lava && distu(rx, ry) <= 2) {
+            } else if (lava && next2u(rx, ry)) {
                 int dmg;
                 You("are hit by molten %s%c",
                     hliquid("lava"), Fire_resistance ? '.' : '!');
@@ -1267,7 +1267,7 @@ u_collide_m(struct monst *mtmp)
        or else the monster to any nearby location.  Prior to 3.3.0
        the latter was done unconditionally. */
     if (!rn2(2) && enexto(&cc, u.ux, u.uy, g.youmonst.data)
-        && distu(cc.x, cc.y) <= 2)
+        && next2u(cc.x, cc.y))
         u_on_newpos(cc.x, cc.y); /*[maybe give message here?]*/
     else
         mnexto(mtmp, RLOC_NOMSG);
index 91f71a0e97e1c0117e934deedbcff21d9bdd4c1d..a35970845192e8ba6c1ee76a1683f18c5e17a1ba 100644 (file)
@@ -2046,7 +2046,7 @@ distant_monnam(struct monst *mon,
        unless you're adjacent (overridden for hallucination which does
        its own obfuscation) */
     if (mon->data == &mons[PM_HIGH_CLERIC] && !Hallucination
-        && Is_astralevel(&u.uz) && distu(mon->mx, mon->my) > 2) {
+        && Is_astralevel(&u.uz) && !next2u(mon->mx, mon->my)) {
         Strcpy(outbuf, article == ARTICLE_THE ? "the " : "");
         Strcat(outbuf, mon->female ? "high priestess" : "high priest");
     } else {
index f4b5aaead319e29d119f3d065b20a99c0be43320..4b19cfe6ac2cb4e75034cf24a4d50df8609fdbd1 100644 (file)
@@ -2186,7 +2186,7 @@ breakobj(
         obj->in_use = 1; /* in case it's fatal */
         if (obj->otyp == POT_OIL && obj->lamplit) {
             explode_oil(obj, x, y);
-        } else if (distu(x, y) <= 2) {
+        } else if (next2u(x, y)) {
             if (!breathless(g.youmonst.data) || haseyes(g.youmonst.data)) {
                 /* wet towel protects both eyes and breathing */
                 if (obj->otyp != POT_WATER && !Half_gas_damage) {
index 84da15f952457a6867e3d06fdbacdf864cae2c7a..d2419870d6b6aebdea71d82a174d181ed05e35bc 100644 (file)
@@ -457,7 +457,7 @@ explode(
                     /* if grabber is reaching into hero's spot and
                        hero's spot is within explosion radius, grabber
                        gets hit by double damage */
-                    if (grabbed && mtmp == u.ustuck && distu(x, y) <= 2)
+                    if (grabbed && mtmp == u.ustuck && next2u(x, y))
                         mdam *= 2;
                     /* being resistant to opposite type of damage makes
                        target more vulnerable to current type of damage
index b15811c62c46289a42415e7e122807272275ff36..ef61908bdb586e5d36ed5f7ff801447df3e086c0 100644 (file)
@@ -1084,7 +1084,7 @@ findtravelpath(int mode)
     /* if travel to adjacent, reachable location, use normal movement rules */
     if ((mode == TRAVP_TRAVEL || mode == TRAVP_VALID) && g.context.travel1
         /* was '&& distmin(u.ux, u.uy, u.tx, u.ty) == 1' */
-        && distu(u.tx, u.ty) <= 2 /* one step away */
+        && next2u(u.tx, u.ty) /* one step away */
         /* handle restricted diagonals */
         && crawl_destination(u.tx, u.ty)) {
         end_running(FALSE);
@@ -1689,7 +1689,7 @@ domove_core(void)
         }
 
         if (u.ustuck && (x != u.ustuck->mx || y != u.ustuck->my)) {
-            if (distu(u.ustuck->mx, u.ustuck->my) > 2) {
+            if (!next2u(u.ustuck->mx, u.ustuck->my)) {
                 /* perhaps it fled (or was teleported or ... ) */
                 set_ustuck((struct monst *) 0);
             } else if (sticks(g.youmonst.data)) {
index 417f88a1520762d38af5610972f2a1ea1bf69f9f..6fceff2a999763b4dde8a8323a3c8a55718573f3 100644 (file)
@@ -413,7 +413,7 @@ newmail(struct mail_info *info)
         if (info->response_cmd)
             new_omailcmd(obj, info->response_cmd);
 
-        if (distu(md->mx, md->my) > 2)
+        if (!next2u(md->mx, md->my))
             verbalize("Catch!");
         display_nhwindow(WIN_MESSAGE, FALSE);
         obj = hold_another_object(obj, "Oops!", (const char *) 0,
index 103c946c8d95ad41d2da43ac80e0e5e1c0b6158e..6489bfeed7bd2c99e4d872b035205764fd9848f2 100644 (file)
@@ -1430,7 +1430,7 @@ makemon(register struct permonst *ptr,
             if (what)
                 Norep("%s%s appears%s%c", what,
                       exclaim ? " suddenly" : "",
-                      distu(x, y) <= 2 ? " next to you"
+                      next2u(x, y) ? " next to you"
                       : (distu(x, y) <= (BOLT_LIM * BOLT_LIM)) ? " close by"
                         : "",
                       exclaim ? '!' : '.');
index fa73bb196f319ebaa9e61f808a0e44d705c81111..59e208a835d630e8a72b337ebc9486fb96757c4a 100644 (file)
@@ -429,14 +429,14 @@ mattacku(register struct monst *mtmp)
             return 0;
         /* Orcs like to steal and eat horses and the like */
         if (!rn2(is_orc(mtmp->data) ? 2 : 4)
-            && distu(mtmp->mx, mtmp->my) <= 2) {
+            && next2u(mtmp->mx, mtmp->my)) {
             /* Attack your steed instead */
             i = mattackm(mtmp, u.usteed);
             if ((i & MM_AGR_DIED))
                 return 1;
             /* make sure steed is still alive and within range */
             if ((i & MM_DEF_DIED) || !u.usteed
-                || distu(mtmp->mx, mtmp->my) > 2)
+                || !next2u(mtmp->mx, mtmp->my))
                 return 0;
             /* Let your steed retaliate */
             return !!(mattackm(u.usteed, mtmp) & MM_DEF_DIED);
@@ -760,7 +760,7 @@ mattacku(register struct monst *mtmp)
                     mon_currwep = MON_WEP(mtmp);
                     if (mon_currwep) {
                         boolean bash = (is_pole(mon_currwep)
-                                        && distu(mtmp->mx, mtmp->my) <= 2);
+                                        && next2u(mtmp->mx, mtmp->my));
 
                         hittmp = hitval(mon_currwep, &g.youmonst);
                         tmp += hittmp;
@@ -1854,7 +1854,7 @@ doseduce(struct monst *mon)
                 Ring_gone(uright);
                 /* ring removal might cause loss of levitation which could
                    drop hero onto trap that transports hero somewhere else */
-                if (u.utotype || distu(mon->mx, mon->my) > 2)
+                if (u.utotype || !next2u(mon->mx, mon->my))
                     return 1;
                 setworn(ring, RIGHT_RING);
             } else if (uleft && uleft->otyp != RIN_ADORNMENT) {
@@ -1862,7 +1862,7 @@ doseduce(struct monst *mon)
                 pline("%s replaces %s with %s.",
                       Who, yname(uleft), yname(ring));
                 Ring_gone(uleft);
-                if (u.utotype || distu(mon->mx, mon->my) > 2)
+                if (u.utotype || !next2u(mon->mx, mon->my))
                     return 1;
                 setworn(ring, LEFT_RING);
             } else
@@ -1895,7 +1895,7 @@ doseduce(struct monst *mon)
        and changing location, so hero might not be adjacent to seducer
        any more (mayberem() has its own adjacency test so we don't need
        to check after each potential removal) */
-    if (u.utotype || distu(mon->mx, mon->my) > 2)
+    if (u.utotype || !next2u(mon->mx, mon->my))
         return 1;
 
     if (uarm || uarmc) {
@@ -2071,7 +2071,7 @@ mayberem(struct monst *mon,
         return;
     /* removal of a previous item might have sent the hero elsewhere
        (loss of levitation that leads to landing on a transport trap) */
-    if (u.utotype || distu(mon->mx, mon->my) > 2)
+    if (u.utotype || !next2u(mon->mx, mon->my))
         return;
 
     /* being deaf overrides confirmation prompt for high charisma */
index 03f6a763a9733d798244244c6e65d8cba2d3276b..01957a4700a46405dffb06dfccf7dde1079d44e2 100644 (file)
--- a/src/mon.c
+++ b/src/mon.c
@@ -1024,7 +1024,7 @@ movemon(void)
             if (mtmp->mundetected)
                 continue;
         } else if (mtmp->data->mlet == S_EEL && !mtmp->mundetected
-                   && (mtmp->mflee || distu(mtmp->mx, mtmp->my) > 2)
+                   && (mtmp->mflee || !next2u(mtmp->mx, mtmp->my))
                    && !canseemon(mtmp) && !rn2(4)) {
             /* some eels end up stuck in isolated pools, where they
                can't--or at least won't--move, so they never reach
@@ -2846,7 +2846,7 @@ void
 set_ustuck(struct monst* mtmp)
 {
     if (iflags.sanity_check || iflags.debug_fuzzer) {
-        if (mtmp && distu(mtmp->mx, mtmp->my) > 2)
+        if (mtmp && !next2u(mtmp->mx, mtmp->my))
             impossible("Sticking to %s at distu %d?",
                        mon_nam(mtmp), distu(mtmp->mx, mtmp->my));
     }
@@ -3803,7 +3803,7 @@ restrap(struct monst *mtmp)
         /* can't hide while trapped except in pits */
         || (mtmp->mtrapped && (t = t_at(mtmp->mx, mtmp->my)) != 0
             && !is_pit(t->ttyp))
-        || (sensemon(mtmp) && distu(mtmp->mx, mtmp->my) <= 2))
+        || (sensemon(mtmp) && next2u(mtmp->mx, mtmp->my)))
         return FALSE;
 
     if (mtmp->data->mlet == S_MIMIC) {
@@ -4704,7 +4704,7 @@ angry_guards(boolean silent)
         if (is_watch(mtmp->data) && mtmp->mpeaceful) {
             ct++;
             if (canspotmon(mtmp) && mtmp->mcanmove) {
-                if (distu(mtmp->mx, mtmp->my) <= 2)
+                if (next2u(mtmp->mx, mtmp->my))
                     nct++;
                 else
                     sct++;
index 83e3b1e3028ff623097adbd7c70d1623addafe5b..eb64718579ba5a12499d69080097120dffd39287 100644 (file)
@@ -728,7 +728,7 @@ dochug(register struct monst* mtmp)
                 if (u.uswallow)
                     return mattacku(mtmp);
                 /* if confused grabber has wandered off, let go */
-                if (distu(mtmp->mx, mtmp->my) > 2)
+                if (!next2u(mtmp->mx, mtmp->my))
                     unstuck(mtmp);
             }
             return 0;
index a3e8c58fd10b926e3978f501edf8aa52fd560fab..a450e499ac6e1433a31cb451eb418908d00a4372 100644 (file)
@@ -1855,7 +1855,7 @@ find_misc(struct monst* mtmp)
             && uwep && !rn2(5) && obj == MON_WEP(mtmp)
             /* hero's location must be known and adjacent */
             && mtmp->mux == u.ux && mtmp->muy == u.uy
-            && distu(mtmp->mx, mtmp->my) <= 2
+            && next2u(mtmp->mx, mtmp->my)
             /* don't bother if it can't work (this doesn't
                prevent cursed weapons from being targetted) */
             && (canletgo(uwep, "")
index 9d5184280c57a0764201c5bdf38f5d5f4fde0fd8..3cd79f30575b01acc327421f8b465de5dec44cee 100644 (file)
@@ -276,7 +276,7 @@ object_from_map(int glyph, int x, int y, struct obj **obj_p)
     /* if located at adjacent spot, mark it as having been seen up close
        (corpse type will be known even if dknown is 0, so we don't need a
        touch check for cockatrice corpse--we're looking without touching) */
-    if (otmp && distu(x, y) <= 2 && !Blind && !Hallucination
+    if (otmp && next2u(x, y) && !Blind && !Hallucination
         /* redundant: we only look for an object which matches current
            glyph among floor and buried objects; when !Blind, any buried
            object's glyph will have been replaced by whatever is present
@@ -589,7 +589,7 @@ lookat(int x, int y, char *buf, char *monbuf)
         if (Underwater && !Is_waterlevel(&u.uz)) {
             /* "unknown" == previously mapped but not visible when
                submerged; better terminology appreciated... */
-            Strcpy(buf, (distu(x, y) <= 2) ? "land" : "unknown");
+            Strcpy(buf, (next2u(x, y)) ? "land" : "unknown");
         } else {
             Strcpy(buf, "unexplored area");
         }
@@ -607,7 +607,7 @@ lookat(int x, int y, char *buf, char *monbuf)
             Sprintf(buf, "%s %saltar",
                     /* like endgame high priests, endgame high altars
                        are only recognizable when immediately adjacent */
-                    (Is_astralevel(&u.uz) && distu(x, y) > 2)
+                    (Is_astralevel(&u.uz) && !next2u(x, y))
                         ? "aligned"
                         : align_str(algn),
                     ((amsk & AM_SHRINE) != 0
@@ -640,7 +640,7 @@ lookat(int x, int y, char *buf, char *monbuf)
             } else if (Underwater && !Is_waterlevel(&u.uz)) {
                 /* "unknown" == previously mapped but not visible when
                    submerged; better terminology appreciated... */
-                Strcpy(buf, (distu(x, y) <= 2) ? "land" : "unknown");
+                Strcpy(buf, (next2u(x, y)) ? "land" : "unknown");
                 break;
             } else if (levl[x][y].typ == STONE || levl[x][y].typ == SCORR) {
                 Strcpy(buf, "stone");
@@ -1100,7 +1100,7 @@ do_screen_description(coord cc, boolean looked, int sym, char *out_str,
     x_str = 0;
     if (!looked) {
         ; /* skip special handling */
-    } else if (((u.uswallow || submerged) && distu(cc.x, cc.y) > 2)
+    } else if (((u.uswallow || submerged) && !next2u(cc.x, cc.y))
                /* detection showing some category, so mostly background */
                || ((iflags.terrainmode & (TER_DETECT | TER_MAP)) == TER_DETECT
                    && glyph == cmap_to_glyph(S_stone))) {
index c14ce42619ddd2957d18fa1e71e3494ecf246334..885078a7e31f8d14d971cdeec8ae17f929ac088e 100644 (file)
@@ -359,7 +359,7 @@ priestname(
     Strcat(pname, what);
     /* same as distant_monnam(), more or less... */
     if (do_hallu || !high_priest || !Is_astralevel(&u.uz)
-        || distu(mon->mx, mon->my) <= 2 || g.program_state.gameover) {
+        || next2u(mon->mx, mon->my) || g.program_state.gameover) {
         Strcat(pname, " of ");
         Strcat(pname, halu_gname(mon_aligntyp(mon)));
     }
index 9f9c4be8c8212334bcd7b2fff7e3dda2cf493452..d1d1cf0fc5ed00b1b762a43ef6b7d90e2995a02b 100644 (file)
--- a/src/shk.c
+++ b/src/shk.c
@@ -1247,7 +1247,7 @@ dopay(void)
     for (shkp = next_shkp(fmon, FALSE); shkp;
          shkp = next_shkp(shkp->nmon, FALSE)) {
         sk++;
-        if (ANGRY(shkp) && distu(shkp->mx, shkp->my) <= 2)
+        if (ANGRY(shkp) && next2u(shkp->mx, shkp->my))
             nxtm = shkp;
         if (canspotmon(shkp))
             seensk++;
@@ -1283,7 +1283,7 @@ dopay(void)
              shkp = next_shkp(shkp->nmon, FALSE))
             if (canspotmon(shkp))
                 break;
-        if (shkp != resident && distu(shkp->mx, shkp->my) > 2) {
+        if (shkp != resident && !next2u(shkp->mx, shkp->my)) {
             pline("%s is not near enough to receive your payment.",
                   Shknam(shkp));
             return ECMD_OK;
@@ -1321,7 +1321,7 @@ dopay(void)
             pline("%s is not interested in your payment.", Monnam(mtmp));
             return ECMD_OK;
         }
-        if (mtmp != resident && distu(mtmp->mx, mtmp->my) > 2) {
+        if (mtmp != resident && !next2u(mtmp->mx, mtmp->my)) {
             pline("%s is too far to receive your payment.", Shknam(mtmp));
             return ECMD_OK;
         }
@@ -1836,7 +1836,7 @@ inherits(struct monst* shkp, int numsk, int croaked, boolean silently)
         takes[0] = '\0';
         if (!shkp->mcanmove || shkp->msleeping)
             Strcat(takes, "wakes up and ");
-        if (distu(shkp->mx, shkp->my) > 2)
+        if (!next2u(shkp->mx, shkp->my))
             Strcat(takes, "comes and ");
         Strcat(takes, "takes");
 
@@ -4070,10 +4070,10 @@ shopdig(register int fall)
             return;
 #endif
         }
-        if (distu(shkp->mx, shkp->my) > 2) {
+        if (!next2u(shkp->mx, shkp->my)) {
             mnexto(shkp, RLOC_MSG);
             /* for some reason the shopkeeper can't come next to you */
-            if (distu(shkp->mx, shkp->my) > 2) {
+            if (!next2u(shkp->mx, shkp->my)) {
                 if (lang == 2)
                     pline("%s curses you in anger and frustration!",
                           Shknam(shkp));
index 04de94c5c0b2d3d272d093830e94e0c6f79e58ab..2f8c6e04330925111b5e6a5e6e95196fe91a612e 100644 (file)
@@ -1337,7 +1337,7 @@ tiphat(void)
 
             pline("%s %s%s%s at you...", Monnam(mtmp), reaction[which],
                   twice ? " and " : "", twice ? reaction[twice] : "");
-        } else if (distu(x, y) <= 2 && !Deaf && domonnoise(mtmp)) {
+        } else if (next2u(x, y) && !Deaf && domonnoise(mtmp)) {
             if (!vismon)
                 map_invisible(x, y);
         } else if (vismon) {
index df0a19ad509fda0e05407f73c0d2c481931a8c9c..5df5d1dfdfd7a0b6c7c60fd4bc140b7cfda6b09f 100644 (file)
@@ -1251,7 +1251,7 @@ rloc_to_core(struct monst* mtmp,
         if (u.uswallow) {
             u_on_newpos(mtmp->mx, mtmp->my);
             docrt();
-        } else if (distu(mtmp->mx, mtmp->my) > 2) {
+        } else if (!next2u(mtmp->mx, mtmp->my)) {
            unstuck(mtmp);
         }
     }
@@ -1264,7 +1264,7 @@ rloc_to_core(struct monst* mtmp,
         if (telemsg && (couldsee(x, y) || sensemon(mtmp))) {
             pline("%s vanishes and reappears%s.",
                   Monnam(mtmp),
-                  distu(x, y) <= 2 ? " next to you"
+                  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");
@@ -1273,7 +1273,7 @@ rloc_to_core(struct monst* mtmp,
                   appearmsg ? Amonnam(mtmp) : Monnam(mtmp),
                   appearmsg ? "suddenly " : "",
                   !Blind ? "appears" : "arrives",
-                  distu(x, y) <= 2 ? " next to you"
+                  next2u(x, y) ? " next to you"
                   : (distu(x, y) <= (BOLT_LIM * BOLT_LIM)) ? " close by" : "");
         }
     }
index 9e60060d3e533ab6c3899630c245a244fac880fe..2cce9d5482d777dd3524dd52c02184c4578054ac 100644 (file)
@@ -5178,7 +5178,7 @@ openholdingtrap(
                 pline("%s%s opens.", upstart(strcpy(buf, which)), trapdescr);
         }
         /* might pacify monster if adjacent */
-        if (rn2(2) && distu(mon->mx, mon->my) <= 2)
+        if (rn2(2) && next2u(mon->mx, mon->my))
             reward_untrap(t, mon);
     }
     return TRUE;
index 71b34b02880ccd620fdcbce40b1321c4c7aa9fa7..63141a423fd177d125c0eed012aef18dd131d89e 100644 (file)
@@ -170,7 +170,7 @@ attack_checks(
         if (M_AP_TYPE(mtmp) && !Protection_from_shape_changers) {
             if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK)
                 /* applied pole-arm attack is too far to get stuck */
-                && distu(mtmp->mx, mtmp->my) <= 2)
+                && next2u(mtmp->mx, mtmp->my))
                 set_ustuck(mtmp);
         }
         /* #H7329 - if hero is on engraved "Elbereth", this will end up
@@ -1564,7 +1564,7 @@ shade_miss(struct monst *magr, struct monst *mdef, struct obj *obj,
 
     if (verbose
         && ((youdef || cansee(mdef->mx, mdef->my) || sensemon(mdef))
-            || (magr == &g.youmonst && distu(mdef->mx, mdef->my) <= 2))) {
+            || (magr == &g.youmonst && next2u(mdef->mx, mdef->my)))) {
         static const char harmlessly_thru[] = " harmlessly through ";
 
         what = (!obj || shade_aware(obj)) ? "attack" : cxname(obj);
@@ -2843,7 +2843,7 @@ mhitm_ad_stck(
         /* since hero can't be cancelled, only defender's armor applies */
         boolean negated = !(rn2(10) >= 3 * armpro);
 
-        if (!negated && !sticks(pd) && distu(mdef->mx, mdef->my) <= 2)
+        if (!negated && !sticks(pd) && next2u(mdef->mx, mdef->my))
             set_ustuck(mdef); /* it's now stuck to you */
     } else if (mdef == &g.youmonst) {
         /* mhitu */
@@ -4613,7 +4613,7 @@ hmonas(struct monst *mon)
     boolean monster_survived;
 
     /* not used here but umpteen mhitm_ad_xxxx() need this */
-    g.vis = (canseemon(mon) || distu(mon->mx, mon->my) <= 2);
+    g.vis = (canseemon(mon) || next2u(mon->mx, mon->my));
 
     /* with just one touch/claw/weapon attack, both rings matter;
        with more than one, alternate right and left when checking
@@ -5340,7 +5340,7 @@ stumble_onto_mimic(struct monst *mtmp)
 
     if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK)
         /* must be adjacent; attack via polearm could be from farther away */
-        && distu(mtmp->mx, mtmp->my) <= 2)
+        && next2u(mtmp->mx, mtmp->my))
         set_ustuck(mtmp);
 
     if (Blind) {
index 309b03a009558cb0348d7055e8605ad2fd70b654..5fde5060db745f9b934dc045410ac01ab87c0cc9 100644 (file)
@@ -91,7 +91,7 @@ amulet(void)
             continue;
         if (mtmp->iswiz && mtmp->msleeping && !rn2(40)) {
             mtmp->msleeping = 0;
-            if (distu(mtmp->mx, mtmp->my) > 2)
+            if (!next2u(mtmp->mx, mtmp->my))
                 You(
       "get the creepy feeling that somebody noticed your taking the Amulet.");
             return;