From: Pasi Kallinen Date: Fri, 18 Mar 2022 16:33:32 +0000 (+0200) Subject: Fix dmonsfree pending when hero was hit with drain-life artifact X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=81ef433def1807a317ac92787bbc9d0d876c106c;p=nethack Fix dmonsfree pending when hero was hit with drain-life artifact When a monster hit hero with an artifact with drain-life attack (Stormbringer or The Staff of Aesculapius), and hero lost a level and hero had more max hp in the lower xp level, the math made the attacker lose hp. This could put the monster hp in the negative, causing "dmonsfree: 1 removed doesn't match 0 pending" --- diff --git a/src/artifact.c b/src/artifact.c index 18d981b21..7e3ca12a2 100644 --- a/src/artifact.c +++ b/src/artifact.c @@ -1589,7 +1589,7 @@ artifact_hit(struct monst *magr, struct monst *mdef, struct obj *otmp, } losexp("life drainage"); if (magr && magr->mhp < magr->mhpmax) { - magr->mhp += (oldhpmax - u.uhpmax + 1) / 2; + magr->mhp += (abs(oldhpmax - u.uhpmax) + 1) / 2; if (magr->mhp > magr->mhpmax) magr->mhp = magr->mhpmax; }