]> granicus.if.org Git - nethack/commitdiff
Saving grace
authorPasi Kallinen <paxed@alt.org>
Fri, 3 Mar 2023 15:37:02 +0000 (17:37 +0200)
committerPasi Kallinen <paxed@alt.org>
Fri, 3 Mar 2023 15:38:48 +0000 (17:38 +0200)
Once per game, if receiving a killing blow from above 90% HP,
allow the hero to survive with 1 HP.

doc/fixes3-7-0.txt
include/extern.h
include/patchlevel.h
include/you.h
src/hack.c
src/mhitu.c

index 21c667045df286bb1b0e732e6325d1edc6239e10..0bbd643f1725ecf0c207171c1698ab584587bf69 100644 (file)
@@ -1115,6 +1115,7 @@ give feedback when some types of damage are avoided due to MC (aka negation)
 feedback if a named, shape-shifted vampire reverted to original shape rather
        than dying when engulfed could say "Dracula turns into Dracula"
 adjust archeologist and valkyrie starting intrinsics
+once per game if receiving killing blow from near-full hp, leave 1 hp
 
 
 Fixes to 3.7.0-x Problems that Were Exposed Via git Repository
index 2d141e8f11fdde59ae56c587bf7e7bda5a2cd8b6..743967d2486f64c320a57607b460f7790da810e5 100644 (file)
@@ -987,6 +987,7 @@ extern int monster_nearby(void);
 extern void end_running(boolean);
 extern void nomul(int);
 extern void unmul(const char *);
+extern int saving_grace(int);
 extern void losehp(int, const char *, schar);
 extern int weight_cap(void);
 extern int inv_weight(void);
index 2c35824f5dce369f8a982733167429715c6191e9..05d9cc8dd565dee8d2f87027eb37f78f828c1bf4 100644 (file)
@@ -17,7 +17,7 @@
  * Incrementing EDITLEVEL can be used to force invalidation of old bones
  * and save files.
  */
-#define EDITLEVEL 75
+#define EDITLEVEL 76
 
 /*
  * Development status possibilities.
index c85db2581eb23b7d257d12e19d46a0c951dfcc1c..2c252aac110a7af7a3315b8c48260fd290959fcb 100644 (file)
@@ -419,7 +419,7 @@ struct you {
     Bitfield(uinvulnerable, 1); /* you're invulnerable (praying) */
     Bitfield(uburied, 1);       /* you're buried */
     Bitfield(uedibility, 1);    /* blessed food detect; sense unsafe food */
-    /* 1 free bit! */
+    Bitfield(usaving_grace, 1); /* prevents death once */
 
     unsigned udg_cnt;           /* how long you have been demigod */
     struct u_event uevent;      /* certain events have happened */
index eade9a4d99979a3238ad36c33bcebdbafc68737e..60cf2fc72b4c41c04bf2bb0b13d60d8ff51824f6 100644 (file)
@@ -3711,6 +3711,19 @@ maybe_wail(void)
     }
 }
 
+/* once per game, if receiving a killing blow from above 90% HP,
+   allow the hero to survive with 1 HP */
+int
+saving_grace(int dmg)
+{
+    if (!u.usaving_grace && (u.uhp <= dmg)
+        && (u.uhp * 100 / u.uhpmax) > 90) {
+        dmg = u.uhp - 1;
+        u.usaving_grace = TRUE; /* used up */
+    }
+    return dmg;
+}
+
 void
 losehp(int n, const char *knam, schar k_format)
 {
@@ -3734,6 +3747,7 @@ losehp(int n, const char *knam, schar k_format)
         return;
     }
 
+    n = saving_grace(n);
     u.uhp -= n;
     if (u.uhp > u.uhpmax)
         u.uhpmax = u.uhp; /* perhaps n was negative */
index 9d4e9ee6ef4cf9be73e05750359e6509ddee46da..71c6ced2c780bf17712583259e580d308155dd9a 100644 (file)
@@ -1753,6 +1753,7 @@ mdamageu(struct monst *mtmp, int n)
         if (u.mh < 1)
             rehumanize();
     } else {
+        n = saving_grace(n);
         u.uhp -= n;
         if (u.uhp < 1)
             done_in_by(mtmp, DIED);