hit points sanity checks

This commit is contained in:
PatR
2024-05-25 17:48:17 -07:00
parent 537fd6dd74
commit 6b750cb551
3 changed files with 26 additions and 11 deletions

View File

@@ -75,23 +75,20 @@ sanity_check_single_mon(
mtmp->mnum, mndx, msg);
mtmp->mnum = mndx;
}
#if 0 /*
* Gremlins don't obey the (mhpmax >= m_lev) rule so disable
* this check, at least for the time being. We could skip it
* when the cloned flag is set, but the original gremlin would
* still be an issue.
*/
/* check before DEADMONSTER() because dead monsters should still
have sane mhpmax */
if (mtmp->mhpmax < 1
/* Gremlins don't obey the (mhpmax >= m_lev) rule so disable
* this check, at least for the time being. We could skip it
* when the cloned flag is set, but the original gremlin would
* still be an issue.
|| mtmp->mhpmax < (int) mtmp->m_lev
*/
|| mtmp->mhp > mtmp->mhpmax)
impossible(
"%s: level %d monster #%u [%s] has %d cur HP, %d max HP",
msg, (int) mtmp->m_lev,
impossible("%s: level %d %s #%u [%s] has %d cur HP, %d max HP",
msg, (int) mtmp->m_lev, mptr->pmnames[NEUTRAL],
mtmp->m_id, fmt_ptr((genericptr_t) mtmp),
mtmp->mhp, mtmp->mhpmax);
#endif
if (DEADMONSTER(mtmp)) {
#if 0
/* bad if not fmon list or if not vault guard */

View File

@@ -2832,7 +2832,7 @@ split_mon(
mtmp2 = (u.mh > 1) ? cloneu() : (struct monst *) 0;
if (mtmp2) {
/* mtmp2 has been created with mhpmax = u.mhmax, mhp = u.mh / 2,
and u.mh -= mtmp2->mhpmax; these reductions for both max hp
and u.mh -= mtmp2->mhp; these reductions for both max hp
can't make either of them exceed corresponding current hp */
mtmp2->mhpmax = u.mhmax / 2;
u.mhmax -= mtmp2->mhpmax;

View File

@@ -1401,6 +1401,24 @@ you_sanity_check(void)
if (u.ustuck != mtmp)
impossible("sanity_check: you over monster");
}
/* [should we also check for (u.uhp < 1), (Upolyd && u.mh < 1),
and (u.uen < 0) here?] */
if (u.uhp > u.uhpmax) {
impossible("current hero health (%d) better than maximum? (%d)",
u.uhp, u.uhpmax);
u.uhp = u.uhpmax;
}
if (Upolyd && u.mh > u.mhmax) {
impossible(
"current hero health as monster (%d) better than maximum? (%d)",
u.mh, u.mhmax);
u.mh = u.mhmax;
}
if (u.uen > u.uenmax) {
impossible("current hero energy (%d) better than maximum? (%d)",
u.uen, u.uenmax);
u.uen = u.uenmax;
}
check_wornmask_slots();
(void) check_invent_gold("invent");