]> granicus.if.org Git - nethack/commitdiff
PR #892 - one more try...
authorPatR <rankin@nethack.org>
Mon, 10 Oct 2022 23:46:33 +0000 (16:46 -0700)
committernhmall <nhmall@nethack.org>
Sat, 15 Oct 2022 16:28:53 +0000 (12:28 -0400)
Try again to make losestr() do what's intended.  If it would take
strength below 3, it takes away HP and max HP instead.  If hero is
poly'd, those come from the hero-as-monst values.  If hero was
poly'd but isn't any more, hero-as-monst died and rehumanized as
previous self; leave max HP alone.  If hero wasn't poly'd, take
HP and max HP from their usual values, but don't take max HP below
the threshold of minimum max HP (experience level times 1).  The old
check for max HP going below minimum can't happen anymore, unless
hero was below that threshold already (which shouldn't happen; if it
does somehow, don't punish hero further).

If this still isn't right, I'll throw up my hands and my lunch.

src/attrib.c

index 0db15de8a36f80f05e071354b789c9678351d0ff..5b20419affe640b9ebd5fc19d1b9368766374f15 100644 (file)
@@ -223,27 +223,38 @@ losestr(int num, const char *knam, schar k_format)
         --num;
         amt = rn1(4, 3); /* (0..(4-1))+3 => 3..6; used to use flat 6 here */
         dmg += amt;
-        if (Upolyd) {
-            u.mhmax -= min(amt, u.mhmax - 1);
-        } else {
-            setuhpmax(u.uhpmax - amt);
-        }
-        g.context.botl = TRUE;
     }
     if (dmg) {
+        boolean waspolyd = Upolyd;
+
         /* in case damage is fatal and caller didn't supply killer reason */
         if (!knam || !*knam) {
             knam = "terminal frailty";
             k_format = KILLED_BY;
         }
         losehp(dmg, knam, k_format);
-    }
 
-    if (u.uhpmax < uhpmin) {
+        if (Upolyd) {
+            /* if still polymorhed, reduce you-as-monst maxHP; never below 1 */
+            u.mhmax -= min(dmg, u.mhmax - 1);
+        } else if (waspolyd) {
+            ; /* rehumanization was triggered; don't reduce no-polyd HP */
+        } else {
+            /* not polymorphed; reduce max HP, but not below below uhpmin */
+            if (u.uhpmax > uhpmin)
+                setuhpmax(max(u.uhpmax - dmg, uhpmin));
+        }
+        g.context.botl = TRUE;
+    }
+#if 0   /* only possible if uhpmax was already less than uhpmin */
+    if (!Upolyd && u.uhpmax < uhpmin) {
         setuhpmax(min(olduhpmax, uhpmin));
         if (!Drain_resistance)
             losexp(NULL); /* won't be fatal when no 'drainer' is supplied */
     }
+#else
+    nhUse(olduhpmax);
+#endif
     (void) adjattrib(A_STR, -num, 1);
 }