]> granicus.if.org Git - nethack/commitdiff
Use function for combined str/hp loss from poison
authorMichael Meyer <me@entrez.cc>
Tue, 4 Oct 2022 21:52:01 +0000 (17:52 -0400)
committerPatR <rankin@nethack.org>
Sat, 8 Oct 2022 23:29:56 +0000 (16:29 -0700)
Since losestr and losehp calls go together most of the time, this feels
like it probably makes more sense than repeating the killer name/format
twice in a row all over the place.

include/extern.h
src/attrib.c
src/eat.c
src/fountain.c
src/spell.c

index 2f7e2b3c820ae90eb3fffd39e4649d670ac3871d..85c0afd0924a476fe2d9f86a9f15d113f5227719 100644 (file)
@@ -115,6 +115,7 @@ extern struct obj *has_magic_key(struct monst *);
 extern boolean adjattrib(int, int, int);
 extern void gainstr(struct obj *, int, boolean);
 extern void losestr(int, const char *, schar);
+extern void poison_strdmg(int, int, const char *, schar);
 extern void poisontell(int, boolean);
 extern void poisoned(const char *, int, const char *, int, boolean);
 extern void change_luck(schar);
index e74abd3e28c9c66c57dc892e21fb15a531d54397..8dd57b29140a0ce79d6775562a1803c35e2e0eb1 100644 (file)
@@ -241,6 +241,14 @@ losestr(int num, const char *knam, schar k_format)
     (void) adjattrib(A_STR, -num, 1);
 }
 
+/* combined strength loss and damage from some poisons */
+void
+poison_strdmg(int strloss, int dmg, const char *knam, schar k_format)
+{
+    losestr(strloss, knam, k_format);
+    losehp(dmg, knam, k_format);
+}
+
 static const struct poison_effect_message {
     void (*delivery_func)(const char *, ...);
     const char *effect_msg;
index c7108eafa6752027b6ec13eabc9afdd31c49f024..bfd567006151dbfc2cf7790ed6e6c552d2875964 100644 (file)
--- a/src/eat.c
+++ b/src/eat.c
@@ -1815,9 +1815,9 @@ eatcorpse(struct obj *otmp)
         tp++;
         pline("Ecch - that must have been poisonous!");
         if (!Poison_resistance) {
-            const char *knam = !glob ? "poisonous corpse" : "poisonous glob";
-            losestr(rnd(4), knam, KILLED_BY_AN);
-            losehp(rnd(15), knam, KILLED_BY_AN);
+            poison_strdmg(rnd(4), rnd(15),
+                          !glob ? "poisonous corpse" : "poisonous glob",
+                          KILLED_BY_AN);
         } else
             You("seem unaffected by the poison.");
 
@@ -2753,9 +2753,7 @@ doeat(void)
         if (otmp->oclass == WEAPON_CLASS && otmp->opoisoned) {
             pline("Ecch - that must have been poisonous!");
             if (!Poison_resistance) {
-                const char *knam = xname(otmp);
-                losestr(rnd(4), knam, KILLED_BY_AN);
-                losehp(rnd(15), knam, KILLED_BY_AN);
+                poison_strdmg(rnd(4), rnd(15), xname(otmp), KILLED_BY_AN);
             } else
                 You("seem unaffected by the poison.");
         } else if (!nodelicious) {
index 8791f39b34650e95d95039ace2ddc6e3e9f8ae90..d965b0a0a8199e26516ce81da94033ab1e5e075f 100644 (file)
@@ -292,8 +292,8 @@ drinkfountain(void)
                 losehp(rnd(4), "unrefrigerated sip of juice", KILLED_BY_AN);
                 break;
             }
-            losestr(rn1(4, 3), "contaminated water", KILLED_BY);
-            losehp(rnd(10), "contaminated water", KILLED_BY);
+            poison_strdmg(rn1(4, 3), rnd(10), "contaminated water",
+                          KILLED_BY);
             exercise(A_CON, FALSE);
             break;
         case 22: /* Fountain of snakes! */
index d72e42dde10533cb9407c59e09a5b60f6acbff33..248ec0685b2ed0821558e39aadbfd6315a7c3f13 100644 (file)
@@ -152,10 +152,9 @@ cursed_book(struct obj* bp)
         /* temp disable in_use; death should not destroy the book */
         was_in_use = bp->in_use;
         bp->in_use = FALSE;
-        losestr(Poison_resistance ? rn1(2, 1) : rn1(4, 3),
-                "contact-poisoned spellbook", KILLED_BY_AN);
-        losehp(rnd(Poison_resistance ? 6 : 10), "contact-poisoned spellbook",
-               KILLED_BY_AN);
+        poison_strdmg(Poison_resistance ? rn1(2, 1) : rn1(4, 3),
+                      rnd(Poison_resistance ? 6 : 10),
+                      "contact-poisoned spellbook", KILLED_BY_AN);
         bp->in_use = was_in_use;
         break;
     case 6: