Add m_next2u, analogous to m_next2m and next2u

This commit is contained in:
Pasi Kallinen
2024-01-19 21:53:25 +02:00
parent b6bc3ef698
commit 57747535af
15 changed files with 36 additions and 34 deletions
+2
View File
@@ -540,6 +540,8 @@ struct _hitmon_data {
/* point px,py is adjacent to (or same location as) hero */ /* point px,py is adjacent to (or same location as) hero */
#define next2u(px,py) (distu((px),(py)) <= 2) #define next2u(px,py) (distu((px),(py)) <= 2)
/* is monster on top of or next to hero? */
#define m_next2u(m) (distu((m)->mx,(m)->my) <= 2)
/* hero at (x,y)? */ /* hero at (x,y)? */
#define u_at(x,y) ((x) == u.ux && (y) == u.uy) #define u_at(x,y) ((x) == u.ux && (y) == u.uy)
+2 -2
View File
@@ -870,9 +870,9 @@ static boolean
mleashed_next2u(struct monst *mtmp) mleashed_next2u(struct monst *mtmp)
{ {
if (mtmp->mleashed) { if (mtmp->mleashed) {
if (!next2u(mtmp->mx, mtmp->my)) if (!m_next2u(mtmp))
mnexto(mtmp, RLOC_NOMSG); mnexto(mtmp, RLOC_NOMSG);
if (!next2u(mtmp->mx, mtmp->my)) { if (!m_next2u(mtmp)) {
struct obj *otmp = get_mleash(mtmp); struct obj *otmp = get_mleash(mtmp);
if (!otmp) { if (!otmp) {
+1 -1
View File
@@ -2267,7 +2267,7 @@ distant_monnam(
unless you're adjacent (overridden for hallucination which does unless you're adjacent (overridden for hallucination which does
its own obfuscation) */ its own obfuscation) */
if (mon->data == &mons[PM_HIGH_CLERIC] && !Hallucination if (mon->data == &mons[PM_HIGH_CLERIC] && !Hallucination
&& Is_astralevel(&u.uz) && !next2u(mon->mx, mon->my)) { && Is_astralevel(&u.uz) && !m_next2u(mon)) {
Strcpy(outbuf, article == ARTICLE_THE ? "the " : ""); Strcpy(outbuf, article == ARTICLE_THE ? "the " : "");
Strcat(outbuf, mon->female ? "high priestess" : "high priest"); Strcat(outbuf, mon->female ? "high priestess" : "high priest");
} else { } else {
+1 -1
View File
@@ -2435,7 +2435,7 @@ escape_from_sticky_mon(coordxy x, coordxy y)
if (u.ustuck && (x != u.ustuck->mx || y != u.ustuck->my)) { if (u.ustuck && (x != u.ustuck->mx || y != u.ustuck->my)) {
struct monst *mtmp; struct monst *mtmp;
if (!next2u(u.ustuck->mx, u.ustuck->my)) { if (!m_next2u(u.ustuck)) {
/* perhaps it fled (or was teleported or ... ) */ /* perhaps it fled (or was teleported or ... ) */
set_ustuck((struct monst *) 0); set_ustuck((struct monst *) 0);
} else if (sticks(gy.youmonst.data)) { } else if (sticks(gy.youmonst.data)) {
+1 -1
View File
@@ -416,7 +416,7 @@ newmail(struct mail_info *info)
if (info->response_cmd) if (info->response_cmd)
new_omailcmd(obj, info->response_cmd); new_omailcmd(obj, info->response_cmd);
if (!next2u(md->mx, md->my)) { if (!m_next2u(md)) {
SetVoice(md, 0, 80, 0); SetVoice(md, 0, 80, 0);
verbalize("Catch!"); verbalize("Catch!");
} }
+7 -7
View File
@@ -475,7 +475,7 @@ mattacku(register struct monst *mtmp)
/* Your steed won't attack you */ /* Your steed won't attack you */
return 0; return 0;
/* Orcs like to steal and eat horses and the like */ /* Orcs like to steal and eat horses and the like */
if (!rn2(is_orc(mtmp->data) ? 2 : 4) && next2u(mtmp->mx, mtmp->my)) { if (!rn2(is_orc(mtmp->data) ? 2 : 4) && m_next2u(mtmp)) {
/* attack your steed instead; 'bhitpos' and 'notonhead' are /* attack your steed instead; 'bhitpos' and 'notonhead' are
already set from tagetting hero */ already set from tagetting hero */
i = mattackm(mtmp, u.usteed); i = mattackm(mtmp, u.usteed);
@@ -483,7 +483,7 @@ mattacku(register struct monst *mtmp)
return 1; return 1;
/* make sure steed is still alive and within range */ /* make sure steed is still alive and within range */
if ((i & M_ATTK_DEF_DIED) != 0 || !u.usteed if ((i & M_ATTK_DEF_DIED) != 0 || !u.usteed
|| !next2u(mtmp->mx, mtmp->my)) || !m_next2u(mtmp))
return 0; return 0;
/* Let your steed retaliate */ /* Let your steed retaliate */
gb.bhitpos.x = mtmp->mx, gb.bhitpos.y = mtmp->my; gb.bhitpos.x = mtmp->mx, gb.bhitpos.y = mtmp->my;
@@ -828,7 +828,7 @@ mattacku(register struct monst *mtmp)
mon_currwep = MON_WEP(mtmp); mon_currwep = MON_WEP(mtmp);
if (mon_currwep) { if (mon_currwep) {
boolean bash = (is_pole(mon_currwep) boolean bash = (is_pole(mon_currwep)
&& next2u(mtmp->mx, mtmp->my)); && m_next2u(mtmp));
hittmp = hitval(mon_currwep, &gy.youmonst); hittmp = hitval(mon_currwep, &gy.youmonst);
tmp += hittmp; tmp += hittmp;
@@ -1989,7 +1989,7 @@ doseduce(struct monst *mon)
Ring_gone(uright); Ring_gone(uright);
/* ring removal might cause loss of levitation which could /* ring removal might cause loss of levitation which could
drop hero onto trap that transports hero somewhere else */ drop hero onto trap that transports hero somewhere else */
if (u.utotype || !next2u(mon->mx, mon->my)) if (u.utotype || !m_next2u(mon))
return 1; return 1;
setworn(ring, RIGHT_RING); setworn(ring, RIGHT_RING);
} else if (uleft && uleft->otyp != RIN_ADORNMENT) { } else if (uleft && uleft->otyp != RIN_ADORNMENT) {
@@ -1997,7 +1997,7 @@ doseduce(struct monst *mon)
pline("%s replaces %s with %s.", pline("%s replaces %s with %s.",
Who, yname(uleft), yname(ring)); Who, yname(uleft), yname(ring));
Ring_gone(uleft); Ring_gone(uleft);
if (u.utotype || !next2u(mon->mx, mon->my)) if (u.utotype || !m_next2u(mon))
return 1; return 1;
setworn(ring, LEFT_RING); setworn(ring, LEFT_RING);
} else } else
@@ -2030,7 +2030,7 @@ doseduce(struct monst *mon)
and changing location, so hero might not be adjacent to seducer and changing location, so hero might not be adjacent to seducer
any more (mayberem() has its own adjacency test so we don't need any more (mayberem() has its own adjacency test so we don't need
to check after each potential removal) */ to check after each potential removal) */
if (u.utotype || !next2u(mon->mx, mon->my)) if (u.utotype || !m_next2u(mon))
return 1; return 1;
if (uarm || uarmc) { if (uarm || uarmc) {
@@ -2208,7 +2208,7 @@ mayberem(struct monst *mon,
return; return;
/* removal of a previous item might have sent the hero elsewhere /* removal of a previous item might have sent the hero elsewhere
(loss of levitation that leads to landing on a transport trap) */ (loss of levitation that leads to landing on a transport trap) */
if (u.utotype || !next2u(mon->mx, mon->my)) if (u.utotype || !m_next2u(mon))
return; return;
/* being deaf overrides confirmation prompt for high charisma */ /* being deaf overrides confirmation prompt for high charisma */
+4 -4
View File
@@ -1068,7 +1068,7 @@ movemon_singlemon(struct monst *mtmp)
if (mtmp->mundetected) if (mtmp->mundetected)
return FALSE; return FALSE;
} else if (mtmp->data->mlet == S_EEL && !mtmp->mundetected } else if (mtmp->data->mlet == S_EEL && !mtmp->mundetected
&& (mtmp->mflee || !next2u(mtmp->mx, mtmp->my)) && (mtmp->mflee || !m_next2u(mtmp))
&& !canseemon(mtmp) && !rn2(4)) { && !canseemon(mtmp) && !rn2(4)) {
/* some eels end up stuck in isolated pools, where they /* some eels end up stuck in isolated pools, where they
can't--or at least won't--move, so they never reach can't--or at least won't--move, so they never reach
@@ -3124,7 +3124,7 @@ void
set_ustuck(struct monst *mtmp) set_ustuck(struct monst *mtmp)
{ {
if (iflags.sanity_check || iflags.debug_fuzzer) { if (iflags.sanity_check || iflags.debug_fuzzer) {
if (mtmp && !next2u(mtmp->mx, mtmp->my)) if (mtmp && !m_next2u(mtmp))
impossible("Sticking to %s at distu %d?", impossible("Sticking to %s at distu %d?",
mon_nam(mtmp), mdistu(mtmp)); mon_nam(mtmp), mdistu(mtmp));
} }
@@ -4257,7 +4257,7 @@ restrap(struct monst *mtmp)
/* can't hide on ceiling if there isn't one */ /* can't hide on ceiling if there isn't one */
|| (ceiling_hider(mtmp->data) && !has_ceiling(&u.uz)) || (ceiling_hider(mtmp->data) && !has_ceiling(&u.uz))
/* won't hide when adjacent to hero */ /* won't hide when adjacent to hero */
|| (sensemon(mtmp) && next2u(mtmp->mx, mtmp->my))) || (sensemon(mtmp) && m_next2u(mtmp)))
return FALSE; return FALSE;
if (mtmp->data->mlet == S_MIMIC) { if (mtmp->data->mlet == S_MIMIC) {
@@ -5268,7 +5268,7 @@ angry_guards(boolean silent)
if (is_watch(mtmp->data) && mtmp->mpeaceful) { if (is_watch(mtmp->data) && mtmp->mpeaceful) {
ct++; ct++;
if (canspotmon(mtmp) && mtmp->mcanmove) { if (canspotmon(mtmp) && mtmp->mcanmove) {
if (next2u(mtmp->mx, mtmp->my)) if (m_next2u(mtmp))
nct++; nct++;
else else
sct++; sct++;
+1 -1
View File
@@ -827,7 +827,7 @@ dochug(register struct monst* mtmp)
break; break;
case MMOVE_MOVED: /* monster moved */ case MMOVE_MOVED: /* monster moved */
/* if confused grabber has wandered off, let go */ /* if confused grabber has wandered off, let go */
if (mtmp == u.ustuck && !next2u(mtmp->mx, mtmp->my)) if (mtmp == u.ustuck && !m_next2u(mtmp))
unstuck(mtmp); unstuck(mtmp);
if (grounded(mdat)) if (grounded(mdat))
disturb_buried_zombies(mtmp->mx, mtmp->my); disturb_buried_zombies(mtmp->mx, mtmp->my);
+2 -2
View File
@@ -443,7 +443,7 @@ find_defensive(struct monst *mtmp, boolean tryescape)
if (!tryescape && dist2(x, y, mtmp->mux, mtmp->muy) > 25) if (!tryescape && dist2(x, y, mtmp->mux, mtmp->muy) > 25)
return FALSE; return FALSE;
if (tryescape && Is_knox(&u.uz) if (tryescape && Is_knox(&u.uz)
&& !next2u(mtmp->mx, mtmp->my) && m_next2m(mtmp)) && !m_next2u(mtmp) && m_next2m(mtmp))
return FALSE; return FALSE;
if (u.uswallow && stuck) if (u.uswallow && stuck)
return FALSE; return FALSE;
@@ -2084,7 +2084,7 @@ find_misc(struct monst *mtmp)
&& uwep && !rn2(5) && obj == MON_WEP(mtmp) && uwep && !rn2(5) && obj == MON_WEP(mtmp)
/* hero's location must be known and adjacent */ /* hero's location must be known and adjacent */
&& u_at(mtmp->mux, mtmp->muy) && u_at(mtmp->mux, mtmp->muy)
&& next2u(mtmp->mx, mtmp->my) && m_next2u(mtmp)
/* don't bother if it can't work (this doesn't /* don't bother if it can't work (this doesn't
prevent cursed weapons from being targeted) */ prevent cursed weapons from being targeted) */
&& !u.uswallow && !u.uswallow
+1 -1
View File
@@ -364,7 +364,7 @@ priestname(
/* same as distant_monnam(), more or less... */ /* same as distant_monnam(), more or less... */
if (do_hallu || !high_priest || reveal_high_priest if (do_hallu || !high_priest || reveal_high_priest
|| !Is_astralevel(&u.uz) || !Is_astralevel(&u.uz)
|| next2u(mon->mx, mon->my) || gp.program_state.gameover) { || m_next2u(mon) || gp.program_state.gameover) {
Strcat(pname, " of "); Strcat(pname, " of ");
Strcat(pname, halu_gname(mon_aligntyp(mon))); Strcat(pname, halu_gname(mon_aligntyp(mon)));
} }
+6 -6
View File
@@ -1454,7 +1454,7 @@ dopay(void)
for (shkp = next_shkp(fmon, FALSE); shkp; for (shkp = next_shkp(fmon, FALSE); shkp;
shkp = next_shkp(shkp->nmon, FALSE)) { shkp = next_shkp(shkp->nmon, FALSE)) {
sk++; sk++;
if (next2u(shkp->mx, shkp->my)) { if (m_next2u(shkp)) {
/* next to an irate shopkeeper? prioritize that */ /* next to an irate shopkeeper? prioritize that */
if (nxtm && ANGRY(nxtm)) if (nxtm && ANGRY(nxtm))
continue; continue;
@@ -1495,7 +1495,7 @@ dopay(void)
shkp = next_shkp(shkp->nmon, FALSE)) shkp = next_shkp(shkp->nmon, FALSE))
if (canspotmon(shkp)) if (canspotmon(shkp))
break; break;
if (shkp != resident && !next2u(shkp->mx, shkp->my)) { if (shkp != resident && !m_next2u(shkp)) {
pline("%s is not near enough to receive your payment.", pline("%s is not near enough to receive your payment.",
Shknam(shkp)); Shknam(shkp));
return ECMD_OK; return ECMD_OK;
@@ -1533,7 +1533,7 @@ dopay(void)
pline("%s is not interested in your payment.", Monnam(mtmp)); pline("%s is not interested in your payment.", Monnam(mtmp));
return ECMD_OK; return ECMD_OK;
} }
if (mtmp != resident && !next2u(mtmp->mx, mtmp->my)) { if (mtmp != resident && !m_next2u(mtmp)) {
pline("%s is too far to receive your payment.", Shknam(mtmp)); pline("%s is too far to receive your payment.", Shknam(mtmp));
return ECMD_OK; return ECMD_OK;
} }
@@ -2088,7 +2088,7 @@ inherits(
takes[0] = '\0'; takes[0] = '\0';
if (helpless(shkp)) if (helpless(shkp))
Strcat(takes, "wakes up and "); Strcat(takes, "wakes up and ");
if (!next2u(shkp->mx, shkp->my)) if (!m_next2u(shkp))
Strcat(takes, "comes and "); Strcat(takes, "comes and ");
Strcat(takes, "takes"); Strcat(takes, "takes");
@@ -4505,10 +4505,10 @@ shopdig(int fall)
return; return;
#endif #endif
} }
if (!next2u(shkp->mx, shkp->my)) { if (!m_next2u(shkp)) {
mnexto(shkp, RLOC_MSG); mnexto(shkp, RLOC_MSG);
/* for some reason the shopkeeper can't come next to you */ /* for some reason the shopkeeper can't come next to you */
if (!next2u(shkp->mx, shkp->my)) { if (!m_next2u(shkp)) {
if (lang == 2) if (lang == 2)
pline("%s curses you in anger and frustration!", pline("%s curses you in anger and frustration!",
Shknam(shkp)); Shknam(shkp));
+1 -1
View File
@@ -1603,7 +1603,7 @@ rloc_to_core(
if (u.uswallow) { if (u.uswallow) {
u_on_newpos(mtmp->mx, mtmp->my); u_on_newpos(mtmp->mx, mtmp->my);
docrt(); docrt();
} else if (!next2u(mtmp->mx, mtmp->my)) { } else if (!m_next2u(mtmp)) {
unstuck(mtmp); unstuck(mtmp);
} }
} }
+1 -1
View File
@@ -5829,7 +5829,7 @@ openholdingtrap(
pline("%s%s opens.", upstart(strcpy(buf, which)), trapdescr); pline("%s%s opens.", upstart(strcpy(buf, which)), trapdescr);
} }
/* might pacify monster if adjacent */ /* might pacify monster if adjacent */
if (rn2(2) && next2u(mon->mx, mon->my)) if (rn2(2) && m_next2u(mon))
reward_untrap(t, mon); reward_untrap(t, mon);
} }
return TRUE; return TRUE;
+5 -5
View File
@@ -234,7 +234,7 @@ attack_checks(
if (M_AP_TYPE(mtmp) && !Protection_from_shape_changers) { if (M_AP_TYPE(mtmp) && !Protection_from_shape_changers) {
if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK) if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK)
/* applied pole-arm attack is too far to get stuck */ /* applied pole-arm attack is too far to get stuck */
&& next2u(mtmp->mx, mtmp->my)) && m_next2u(mtmp))
set_ustuck(mtmp); set_ustuck(mtmp);
} }
/* #H7329 - if hero is on engraved "Elbereth", this will end up /* #H7329 - if hero is on engraved "Elbereth", this will end up
@@ -1940,7 +1940,7 @@ shade_miss(
if (verbose if (verbose
&& ((youdef || cansee(mdef->mx, mdef->my) || sensemon(mdef)) && ((youdef || cansee(mdef->mx, mdef->my) || sensemon(mdef))
|| (magr == &gy.youmonst && next2u(mdef->mx, mdef->my)))) { || (magr == &gy.youmonst && m_next2u(mdef)))) {
static const char harmlessly_thru[] = " harmlessly through "; static const char harmlessly_thru[] = " harmlessly through ";
what = (!obj || shade_aware(obj)) ? "attack" : cxname(obj); what = (!obj || shade_aware(obj)) ? "attack" : cxname(obj);
@@ -3215,7 +3215,7 @@ mhitm_ad_stck(
if (magr == &gy.youmonst) { if (magr == &gy.youmonst) {
/* uhitm */ /* uhitm */
if (!negated && !sticks(pd) && next2u(mdef->mx, mdef->my)) { if (!negated && !sticks(pd) && m_next2u(mdef)) {
set_ustuck(mdef); /* it's now stuck to you */ set_ustuck(mdef); /* it's now stuck to you */
if (barbs) if (barbs)
Your("barbs stick to %s!", y_monnam(mdef)); Your("barbs stick to %s!", y_monnam(mdef));
@@ -5266,7 +5266,7 @@ hmonas(struct monst *mon)
boolean monster_survived; boolean monster_survived;
/* not used here but umpteen mhitm_ad_xxxx() need this */ /* not used here but umpteen mhitm_ad_xxxx() need this */
gv.vis = (canseemon(mon) || next2u(mon->mx, mon->my)); gv.vis = (canseemon(mon) || m_next2u(mon));
/* with just one touch/claw/weapon attack, both rings matter; /* with just one touch/claw/weapon attack, both rings matter;
with more than one, alternate right and left when checking with more than one, alternate right and left when checking
@@ -6024,7 +6024,7 @@ stumble_onto_mimic(struct monst *mtmp)
if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK) if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK)
/* must be adjacent; attack via polearm could be from farther away */ /* must be adjacent; attack via polearm could be from farther away */
&& next2u(mtmp->mx, mtmp->my)) && m_next2u(mtmp))
set_ustuck(mtmp); set_ustuck(mtmp);
if (Blind) { if (Blind) {
+1 -1
View File
@@ -94,7 +94,7 @@ amulet(void)
continue; continue;
if (mtmp->iswiz && mtmp->msleeping && !rn2(40)) { if (mtmp->iswiz && mtmp->msleeping && !rn2(40)) {
mtmp->msleeping = 0; mtmp->msleeping = 0;
if (!next2u(mtmp->mx, mtmp->my)) if (!m_next2u(mtmp))
You( You(
"get the creepy feeling that somebody noticed your taking the Amulet."); "get the creepy feeling that somebody noticed your taking the Amulet.");
return; return;