From 6b750cb551f3d90692802a9a800d1dcb45e704be Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 25 May 2024 17:48:17 -0700 Subject: [PATCH] hit points sanity checks --- src/mon.c | 17 +++++++---------- src/potion.c | 2 +- src/wizcmds.c | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/mon.c b/src/mon.c index b028308bc..f4666b151 100644 --- a/src/mon.c +++ b/src/mon.c @@ -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 */ diff --git a/src/potion.c b/src/potion.c index c0c4df819..d97f274a9 100644 --- a/src/potion.c +++ b/src/potion.c @@ -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; diff --git a/src/wizcmds.c b/src/wizcmds.c index cf8fc75e9..f4f3006f2 100644 --- a/src/wizcmds.c +++ b/src/wizcmds.c @@ -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");