Fix: vampire shapeshifting in a door

Someone mentioned in #nethack today that a vampire had turned into a fog
cloud, moved under a door, then turned back into a vampire while still
sharing a space with a closed door.  There already existed some code
intended to prevent this in cases where the vampire is killed in one
form and revives in another, but voluntary transformations (from
decide_to_shapeshift) weren't included.  The existing code in mondead
and vamp_stone also apparently missed a minor edge case: because the
code between the definition of in_door and its use included an expels
call, it would be outdated/incorrect in cases where expels() placed the
fog cloud onto a closed door.
This commit is contained in:
Michael Meyer
2022-06-08 20:23:24 -04:00
parent f710a3175f
commit bc2427167a
+15 -9
View File
@@ -2494,7 +2494,7 @@ lifesaved_monster(struct monst* mtmp)
DISABLE_WARNING_FORMAT_NONLITERAL DISABLE_WARNING_FORMAT_NONLITERAL
void void
mondead(register struct monst* mtmp) mondead(struct monst *mtmp)
{ {
struct permonst *mptr; struct permonst *mptr;
boolean be_sad; boolean be_sad;
@@ -2516,13 +2516,11 @@ mondead(register struct monst* mtmp)
&& !(g.mvitals[mndx].mvflags & G_GENOD)) { && !(g.mvitals[mndx].mvflags & G_GENOD)) {
coord new_xy; coord new_xy;
char buf[BUFSZ]; char buf[BUFSZ];
boolean in_door = (amorphous(mtmp->data)
&& closed_door(mtmp->mx, mtmp->my)),
/* alternate message phrasing for some monster types */ /* alternate message phrasing for some monster types */
spec_mon = (nonliving(mtmp->data) boolean spec_mon = (nonliving(mtmp->data)
|| noncorporeal(mtmp->data) || noncorporeal(mtmp->data)
|| amorphous(mtmp->data)), || amorphous(mtmp->data)),
spec_death = (g.disintegested /* disintegrated or digested */ spec_death = (g.disintegested /* disintegrated/digested */
|| noncorporeal(mtmp->data) || noncorporeal(mtmp->data)
|| amorphous(mtmp->data)); || amorphous(mtmp->data));
int x = mtmp->mx, y = mtmp->my; int x = mtmp->mx, y = mtmp->my;
@@ -2546,7 +2544,9 @@ mondead(register struct monst* mtmp)
else else
uunstick(); uunstick();
} }
if (in_door) { /* if fog cloud is on a closed door space, move it to a more
appropriate spot for its intended new form */
if (amorphous(mtmp->data) && closed_door(mtmp->mx, mtmp->my)) {
if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx]))
rloc_to(mtmp, new_xy.x, new_xy.y); rloc_to(mtmp, new_xy.x, new_xy.y);
} }
@@ -3230,8 +3230,6 @@ vamp_stone(struct monst* mtmp)
if (mndx >= LOW_PM && mndx != monsndx(mtmp->data) if (mndx >= LOW_PM && mndx != monsndx(mtmp->data)
&& !(g.mvitals[mndx].mvflags & G_GENOD)) { && !(g.mvitals[mndx].mvflags & G_GENOD)) {
char buf[BUFSZ]; char buf[BUFSZ];
boolean in_door = (amorphous(mtmp->data)
&& closed_door(mtmp->mx, mtmp->my));
/* construct a format string before transformation */ /* construct a format string before transformation */
Sprintf(buf, "The lapidifying %s %s %s", Sprintf(buf, "The lapidifying %s %s %s",
@@ -3249,7 +3247,7 @@ vamp_stone(struct monst* mtmp)
/* this can happen if previously a fog cloud */ /* this can happen if previously a fog cloud */
if (engulfing_u(mtmp)) if (engulfing_u(mtmp))
expels(mtmp, mtmp->data, FALSE); expels(mtmp, mtmp->data, FALSE);
if (in_door) { if (amorphous(mtmp->data) && closed_door(mtmp->mx, mtmp->my)) {
coord new_xy; coord new_xy;
if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) { if (enexto(&new_xy, mtmp->mx, mtmp->my, &mons[mndx])) {
@@ -4123,6 +4121,14 @@ decide_to_shapeshift(struct monst* mon, int shiftflags)
dochng = (ptr != mon->data); dochng = (ptr != mon->data);
} }
} }
if (dochng && amorphous(mon->data)
&& closed_door(mon->mx, mon->my)) {
coord new_xy;
if (enexto(&new_xy, mon->mx, mon->my, ptr)) {
rloc_to(mon, new_xy.x, new_xy.y);
}
}
} else { } else {
if (mon->mhp >= 9 * mon->mhpmax / 10 && !rn2(6) if (mon->mhp >= 9 * mon->mhpmax / 10 && !rn2(6)
&& (!canseemon(mon) && (!canseemon(mon)