Use macro for a location next to hero

This commit is contained in:
Pasi Kallinen
2022-02-12 11:05:07 +02:00
parent 2b4cf04281
commit 91e2d3633e
23 changed files with 53 additions and 50 deletions

View 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 */

View 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) {

View File

@@ -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) {

View 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;
}

View File

@@ -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);

View 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 {

View 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) {

View 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

View 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)) {

View 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,

View 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 ? '!' : '.');

View 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 */

View File

@@ -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++;

View 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;

View 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, "")

View 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))) {

View 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)));
}

View File

@@ -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));

View 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) {

View 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" : "");
}
}

View 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;

View 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) {

View 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;