mon->mhp manipulation

I've hunted for other instances where monster hit points were set
to zero or less without calling the routine that kills off the
monster (see recent mon_unslime() vs zhitm()) and didn't find any
for mhp subtraction.  I haven't checked for direct assignment yet.

For a while I thought I'd found several cases where a monster was
intended to be killed but got left with positive hit points, but
it turned out that lifesaved_monster(), of all places, was setting
them to zero.  I've moved that to its callers so that it isn't so
well hidden.  And changed several ''if ((mon->mhp -= dmg) <= 0)''
into separate subtraction and 'if' just so the mhp manipulation is
a bit more visible.

I think the only actual change here is the message for monster
being killed by lava, where glass golems now melt instead of burn.
This commit is contained in:
PatR
2016-05-21 18:25:16 -07:00
parent 29e9179ca5
commit c1bfa1360f
7 changed files with 49 additions and 28 deletions

View File

@@ -514,14 +514,19 @@ register struct monst *mtmp;
*/
if (!is_clinger(mtmp->data) && !likes_lava(mtmp->data)) {
if (!resists_fire(mtmp)) {
if (cansee(mtmp->mx, mtmp->my))
if (cansee(mtmp->mx, mtmp->my)) {
struct attack *dummy = &mtmp->data->mattk[0];
const char *how = on_fire(mtmp->data, dummy);
pline("%s %s.", Monnam(mtmp),
mtmp->data == &mons[PM_WATER_ELEMENTAL]
? "boils away"
: "burns to a crisp");
!strcmp(how, "boiling") ? "boils away"
: !strcmp(how, "melting") ? "melts away"
: "burns to a crisp");
}
mondead(mtmp);
} else {
if (--mtmp->mhp < 1) {
mtmp->mhp -= 1;
if (mtmp->mhp < 1) {
if (cansee(mtmp->mx, mtmp->my))
pline("%s surrenders to the fire.", Monnam(mtmp));
mondead(mtmp);
@@ -1775,8 +1780,8 @@ struct monst *mtmp;
/* genocided monster can't be life-saved */
if (cansee(mtmp->mx, mtmp->my))
pline("Unfortunately, %s is still genocided...", mon_nam(mtmp));
mtmp->mhp = 0;
}
mtmp->mhp = 0;
}
void
@@ -1786,6 +1791,7 @@ register struct monst *mtmp;
struct permonst *mptr;
int tmp;
mtmp->mhp = 0; /* in case caller hasn't done this */
lifesaved_monster(mtmp);
if (mtmp->mhp > 0)
return;
@@ -2028,6 +2034,7 @@ struct monst *mdef;
* put inventory in it, and we have to check for lifesaving before
* making the statue....
*/
mdef->mhp = 0; /* in case caller hasn't done this */
lifesaved_monster(mdef);
if (mdef->mhp > 0)
return;
@@ -2167,6 +2174,7 @@ int xkill_flags; /* 1: suppress message, 2: suppress corpse, 4: pacifist */
nocorpse = (xkill_flags & XKILL_NOCORPSE) != 0,
noconduct = (xkill_flags & XKILL_NOCONDUCT) != 0;
mtmp->mhp = 0; /* caller will usually have already done this */
if (!noconduct) /* KMH, conduct */
u.uconduct.killer++;