#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 */
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 */
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) {
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) {
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;
}
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 ? '.' : '!');
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);
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 {
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) {
/* 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
/* 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);
}
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)) {
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,
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 ? '!' : '.');
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);
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;
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) {
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
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) {
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 */
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
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));
}
/* 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) {
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++;
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;
&& 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, "")
/* 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
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");
}
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
} 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");
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))) {
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)));
}
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++;
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;
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;
}
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");
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));
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) {
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);
}
}
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");
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" : "");
}
}
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;
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
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);
/* 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 */
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
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) {
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;