Audit rloc()

Most of the time, rloc() is used for teleporting monsters and it's not a
big deal if they can't find somewhere to go. In a few cases, it is. I
went through all the callsites and made calls to rloc() not cause
impossible()s if they don't need to.

Fixes a bug/suite of bugs reported by ais523.
This commit is contained in:
Sean Hunt
2015-05-24 21:40:33 +09:00
committed by nhmall
parent 80703597c0
commit a67759cbc3
12 changed files with 29 additions and 29 deletions

View File

@@ -886,7 +886,7 @@ struct obj *obj;
freeinv(obj); freeinv(obj);
(void) mpickobj(mtmp, obj); (void) mpickobj(mtmp, obj);
if (!tele_restrict(mtmp)) if (!tele_restrict(mtmp))
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
} else if (!is_unicorn(mtmp->data) && !humanoid(mtmp->data) } else if (!is_unicorn(mtmp->data) && !humanoid(mtmp->data)
&& (!mtmp->minvis || perceives(mtmp->data)) && rn2(5)) { && (!mtmp->minvis || perceives(mtmp->data)) && rn2(5)) {
if (vis) if (vis)

View File

@@ -63,7 +63,7 @@ boolean waslit, rockit;
return; /* don't cover the portal */ return; /* don't cover the portal */
if ((mtmp = m_at(x, y)) != 0) /* make sure crucial monsters survive */ if ((mtmp = m_at(x, y)) != 0) /* make sure crucial monsters survive */
if (!passes_walls(mtmp->data)) if (!passes_walls(mtmp->data))
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
} else if (lev->typ == ROOM) } else if (lev->typ == ROOM)
return; return;

View File

@@ -1655,7 +1655,7 @@ nopick:
if (!Blind) if (!Blind)
pline1(buf); pline1(buf);
if (!tele_restrict(mon)) if (!tele_restrict(mon))
(void) rloc(mon, FALSE); (void) rloc(mon, TRUE);
return (ret); return (ret);
} }

View File

@@ -1017,7 +1017,7 @@ register struct attack *mattk;
if (vis) if (vis)
Strcpy(mdef_Monnam, Monnam(mdef)); Strcpy(mdef_Monnam, Monnam(mdef));
mdef->mstrategy &= ~STRAT_WAITFORU; mdef->mstrategy &= ~STRAT_WAITFORU;
(void) rloc(mdef, FALSE); (void) rloc(mdef, TRUE);
if (vis && !canspotmon(mdef) && mdef != u.usteed) if (vis && !canspotmon(mdef) && mdef != u.usteed)
pline("%s suddenly disappears!", mdef_Monnam); pline("%s suddenly disappears!", mdef_Monnam);
} }
@@ -1139,7 +1139,7 @@ register struct attack *mattk;
pline("%s steals some gold from %s.", buf, mon_nam(mdef)); pline("%s steals some gold from %s.", buf, mon_nam(mdef));
} }
if (!tele_restrict(magr)) { if (!tele_restrict(magr)) {
(void) rloc(magr, FALSE); (void) rloc(magr, TRUE);
if (vis && !canspotmon(magr)) if (vis && !canspotmon(magr))
pline("%s suddenly disappears!", buf); pline("%s suddenly disappears!", buf);
} }
@@ -1202,7 +1202,7 @@ register struct attack *mattk;
return (MM_DEF_DIED return (MM_DEF_DIED
| (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED));
if (pa->mlet == S_NYMPH && !tele_restrict(magr)) { if (pa->mlet == S_NYMPH && !tele_restrict(magr)) {
(void) rloc(magr, FALSE); (void) rloc(magr, TRUE);
if (vis && !canspotmon(magr)) if (vis && !canspotmon(magr))
pline("%s suddenly disappears!", buf); pline("%s suddenly disappears!", buf);
} }

View File

@@ -1265,7 +1265,7 @@ register struct attack *mattk;
: "makes some remarks about how difficult theft is " : "makes some remarks about how difficult theft is "
"lately"); "lately");
if (!tele_restrict(mtmp)) if (!tele_restrict(mtmp))
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
return 3; return 3;
} else if (mtmp->mcan) { } else if (mtmp->mcan) {
if (!Blind) { if (!Blind) {
@@ -1276,7 +1276,7 @@ register struct attack *mattk;
} }
if (rn2(3)) { if (rn2(3)) {
if (!tele_restrict(mtmp)) if (!tele_restrict(mtmp))
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
return 3; return 3;
} }
break; break;
@@ -1289,7 +1289,7 @@ register struct attack *mattk;
break; break;
default: default:
if (!is_animal(mtmp->data) && !tele_restrict(mtmp)) if (!is_animal(mtmp->data) && !tele_restrict(mtmp))
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
if (is_animal(mtmp->data) && *buf) { if (is_animal(mtmp->data) && *buf) {
if (canseemon(mtmp)) if (canseemon(mtmp))
pline("%s tries to %s away with %s.", Monnam(mtmp), pline("%s tries to %s away with %s.", Monnam(mtmp),
@@ -1392,7 +1392,7 @@ register struct attack *mattk;
return 2; return 2;
} else if (!rn2(33)) { } else if (!rn2(33)) {
if (!tele_restrict(mtmp)) if (!tele_restrict(mtmp))
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
monflee(mtmp, d(3, 6), TRUE, FALSE); monflee(mtmp, d(3, 6), TRUE, FALSE);
return 3; return 3;
} }
@@ -2381,7 +2381,7 @@ register struct monst *mon;
verbalize("You're such a %s; I wish...", verbalize("You're such a %s; I wish...",
flags.female ? "sweet lady" : "nice guy"); flags.female ? "sweet lady" : "nice guy");
if (!tele_restrict(mon)) if (!tele_restrict(mon))
(void) rloc(mon, FALSE); (void) rloc(mon, TRUE);
return 1; return 1;
} }
if (u.ualign.type == A_CHAOTIC) if (u.ualign.type == A_CHAOTIC)
@@ -2503,7 +2503,7 @@ register struct monst *mon;
if (!rn2(25)) if (!rn2(25))
mon->mcan = 1; /* monster is worn out */ mon->mcan = 1; /* monster is worn out */
if (!tele_restrict(mon)) if (!tele_restrict(mon))
(void) rloc(mon, FALSE); (void) rloc(mon, TRUE);
return 1; return 1;
} }

View File

@@ -245,7 +245,7 @@ register struct monst *mtmp;
pline("%s says, \"Good hunting, %s.\"", Amonnam(mtmp), pline("%s says, \"Good hunting, %s.\"", Amonnam(mtmp),
flags.female ? "Sister" : "Brother"); flags.female ? "Sister" : "Brother");
if (!tele_restrict(mtmp)) if (!tele_restrict(mtmp))
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
return (1); return (1);
} }
cash = money_cnt(invent); cash = money_cnt(invent);

View File

@@ -386,7 +386,7 @@ register struct monst *mtmp;
/* some monsters teleport */ /* some monsters teleport */
if (mtmp->mflee && !rn2(40) && can_teleport(mdat) && !mtmp->iswiz if (mtmp->mflee && !rn2(40) && can_teleport(mdat) && !mtmp->iswiz
&& !level.flags.noteleport) { && !level.flags.noteleport) {
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
return (0); return (0);
} }
if (mdat->msound == MS_SHRIEK && !um_dist(mtmp->mx, mtmp->my, 1)) if (mdat->msound == MS_SHRIEK && !um_dist(mtmp->mx, mtmp->my, 1))
@@ -439,7 +439,7 @@ register struct monst *mtmp;
if (is_demon(youmonst.data)) { if (is_demon(youmonst.data)) {
/* "Good hunting, brother" */ /* "Good hunting, brother" */
if (!tele_restrict(mtmp)) if (!tele_restrict(mtmp))
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
} else { } else {
mtmp->minvis = mtmp->perminvis = 0; mtmp->minvis = mtmp->perminvis = 0;
/* Why? For the same reason in real demon talk */ /* Why? For the same reason in real demon talk */
@@ -821,7 +821,7 @@ register int after;
if (ptr == &mons[PM_TENGU] && !rn2(5) && !mtmp->mcan if (ptr == &mons[PM_TENGU] && !rn2(5) && !mtmp->mcan
&& !tele_restrict(mtmp)) { && !tele_restrict(mtmp)) {
if (mtmp->mhp < 7 || mtmp->mpeaceful || rn2(2)) if (mtmp->mhp < 7 || mtmp->mpeaceful || rn2(2))
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
else else
mnexto(mtmp); mnexto(mtmp);
mmoved = 1; mmoved = 1;
@@ -1192,7 +1192,7 @@ not_special:
worm_move(mtmp); worm_move(mtmp);
} else { } else {
if (is_unicorn(ptr) && rn2(2) && !tele_restrict(mtmp)) { if (is_unicorn(ptr) && rn2(2) && !tele_restrict(mtmp)) {
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
return (1); return (1);
} }
if (mtmp->wormno) if (mtmp->wormno)

View File

@@ -646,7 +646,7 @@ struct monst *mtmp;
} }
if (oseen && how) if (oseen && how)
makeknown(how); makeknown(how);
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
return 2; return 2;
case MUSE_WAN_TELEPORTATION: case MUSE_WAN_TELEPORTATION:
zap_oseen = oseen; zap_oseen = oseen;
@@ -1238,7 +1238,7 @@ register struct obj *otmp;
if (cansee(mtmp->mx, mtmp->my)) if (cansee(mtmp->mx, mtmp->my))
pline("%s resists the magic!", Monnam(mtmp)); pline("%s resists the magic!", Monnam(mtmp));
} else if (!tele_restrict(mtmp)) } else if (!tele_restrict(mtmp))
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
} }
break; break;
case WAN_CANCELLATION: case WAN_CANCELLATION:

View File

@@ -116,7 +116,7 @@ register struct monst *mtmp;
(Levitation || Flying) ? "beneath" : "between", whose, what); (Levitation || Flying) ? "beneath" : "between", whose, what);
if (!ygold || !rn2(5)) { if (!ygold || !rn2(5)) {
if (!tele_restrict(mtmp)) if (!tele_restrict(mtmp))
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
monflee(mtmp, 0, FALSE, FALSE); monflee(mtmp, 0, FALSE, FALSE);
} }
} else if (ygold) { } else if (ygold) {
@@ -131,7 +131,7 @@ register struct monst *mtmp;
add_to_minv(mtmp, ygold); add_to_minv(mtmp, ygold);
Your("purse feels lighter."); Your("purse feels lighter.");
if (!tele_restrict(mtmp)) if (!tele_restrict(mtmp))
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
monflee(mtmp, 0, FALSE, FALSE); monflee(mtmp, 0, FALSE, FALSE);
context.botl = 1; context.botl = 1;
} }
@@ -164,7 +164,7 @@ stealarm(VOID_ARGS)
so we don't set mavenge bit here. */ so we don't set mavenge bit here. */
monflee(mtmp, 0, FALSE, FALSE); monflee(mtmp, 0, FALSE, FALSE);
if (!tele_restrict(mtmp)) if (!tele_restrict(mtmp))
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
break; break;
} }
} }
@@ -554,7 +554,7 @@ struct monst *mtmp;
(void) mpickobj(mtmp, otmp); /* may merge and free otmp */ (void) mpickobj(mtmp, otmp); /* may merge and free otmp */
pline("%s stole %s!", Monnam(mtmp), doname(otmp)); pline("%s stole %s!", Monnam(mtmp), doname(otmp));
if (can_teleport(mtmp->data) && !tele_restrict(mtmp)) if (can_teleport(mtmp->data) && !tele_restrict(mtmp))
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
} }
} }

View File

@@ -1068,7 +1068,7 @@ struct monst *mtmp;
rloc_to(mtmp, c.x, c.y); rloc_to(mtmp, c.x, c.y);
return; return;
} }
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
} }
boolean boolean
@@ -1105,7 +1105,7 @@ int in_sight;
if (trap->once) if (trap->once)
mvault_tele(mtmp); mvault_tele(mtmp);
else else
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
if (in_sight) { if (in_sight) {
if (canseemon(mtmp)) if (canseemon(mtmp))
@@ -1333,12 +1333,12 @@ boolean give_feedback;
if (give_feedback) if (give_feedback)
You("are no longer inside %s!", mon_nam(mtmp)); You("are no longer inside %s!", mon_nam(mtmp));
unstuck(mtmp); unstuck(mtmp);
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
} else if (is_rider(mtmp->data) && rn2(13) } else if (is_rider(mtmp->data) && rn2(13)
&& enexto(&cc, u.ux, u.uy, mtmp->data)) && enexto(&cc, u.ux, u.uy, mtmp->data))
rloc_to(mtmp, cc.x, cc.y); rloc_to(mtmp, cc.x, cc.y);
else else
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
return TRUE; return TRUE;
} }

View File

@@ -614,7 +614,7 @@ register struct monst *grd;
if (u_carry_gold) { /* player teleported */ if (u_carry_gold) { /* player teleported */
m = grd->mx; m = grd->mx;
n = grd->my; n = grd->my;
(void) rloc(grd, FALSE); (void) rloc(grd, TRUE);
levl[m][n].typ = egrd->fakecorr[0].ftyp; levl[m][n].typ = egrd->fakecorr[0].ftyp;
newsym(m, n); newsym(m, n);
grd->mpeaceful = 0; grd->mpeaceful = 0;

View File

@@ -326,7 +326,7 @@ register struct monst *mtmp;
if (In_W_tower(mtmp->mx, mtmp->my, &u.uz) if (In_W_tower(mtmp->mx, mtmp->my, &u.uz)
|| (mtmp->iswiz && !xupstair && !mon_has_amulet(mtmp))) { || (mtmp->iswiz && !xupstair && !mon_has_amulet(mtmp))) {
if (!rn2(3 + mtmp->mhp / 10)) if (!rn2(3 + mtmp->mhp / 10))
(void) rloc(mtmp, FALSE); (void) rloc(mtmp, TRUE);
} else if (xupstair } else if (xupstair
&& (mtmp->mx != xupstair || mtmp->my != yupstair)) { && (mtmp->mx != xupstair || mtmp->my != yupstair)) {
(void) mnearto(mtmp, xupstair, yupstair, TRUE); (void) mnearto(mtmp, xupstair, yupstair, TRUE);