]> granicus.if.org Git - nethack/commitdiff
hunger checks
authorPatR <rankin@nethack.org>
Fri, 4 Sep 2020 21:31:44 +0000 (14:31 -0700)
committerPatR <rankin@nethack.org>
Fri, 4 Sep 2020 21:31:44 +0000 (14:31 -0700)
Eliminate the feasibility of micro-managing ring hunger by swapping
back and forth between a pair of rings of slow digestion.  Wearing
one at a time causes normal ring hunger (wearing both at once just
increases such hunger), but being able to put on the second ring
and take off the first just before the 1 out of 20 turns where it
affects hunger, then vice versa a few turns later, is an insanely
tedious way to avoid any hunger at all, made possible by the 'time'
option.  Make the turns where extra hunger get imposed be randomized
so that that can't be done reliably.

Also closes githib issue #336:  hunger caused by melee attacking
adds ring and amulet hunger a second time for that turn.  That has
always been intentional behavior; now the amount varies for any
given attack due to the randomization, but on average is the same
as before.

Closes #336

doc/fixes37.0
src/eat.c

index b1236e9798ee9291046b17f095aaaddfcb4f4ce2..dc210bd01cf0b044f933835450e71d5cef5a972f 100644 (file)
@@ -1,4 +1,4 @@
-NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.296 $ $NHDT-Date: 1599184888 2020/09/04 02:01:28 $
+NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.297 $ $NHDT-Date: 1599255099 2020/09/04 21:31:39 $
 
 General Fixes and Modified Features
 -----------------------------------
@@ -249,6 +249,7 @@ end of game inventory disclosure passed an inappropriate argument to the
        noticeable but not harmful for X11, and slightly harmful for Qt
 turning into slime rendered hero as slime one turn too soon
 avoid potential infinite loop if hangup occurs at ring "right or left?" prompt
+randomize the turns where accessories and extrinsics affect nutrition
 
 
 Fixes to 3.7.0-x Problems that Were Exposed Via git Repository
index a4a670df1a4dab7e85d7bc8653c6578cb9f1ed53..620f9e277661a61cdbe8050e6e05ad3a4afda6ef 100644 (file)
--- a/src/eat.c
+++ b/src/eat.c
@@ -1,4 +1,4 @@
-/* NetHack 3.7 eat.c   $NHDT-Date: 1596498165 2020/08/03 23:42:45 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.231 $ */
+/* NetHack 3.7 eat.c   $NHDT-Date: 1599255099 2020/09/04 21:31:39 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.232 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2012. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -2811,6 +2811,8 @@ bite()
 void
 gethungry()
 {
+    long accessorytime;
+
     if (u.uinvulnerable)
         return; /* you don't feel hungrier */
 
@@ -2825,14 +2827,25 @@ gethungry()
         && !Slow_digestion)
         u.uhunger--; /* ordinary food consumption */
 
-    if (g.moves % 2) { /* odd turns */
+    /*
+     * 3.7:  trigger is randomized instead of (moves % N).  Makes
+     * ring juggling (using the 'time' option to see the turn counter
+     * in order to time swapping of a pair of rings of slow digestion,
+     * wearing one on one hand, then putting on the other and taking
+     * off the first, then vice versa, over and over and over and ...
+     * to avoid any hunger from wearing a ring) become ineffective.
+     * Also causes melee-induced hunger to vary from turn-based hunger
+     * instead of just replicating that.
+     */
+    accessorytime = g.moves + (long) rn2(20);
+    if (accessorytime % 2L) { /* odd */
         /* Regeneration uses up food, unless due to an artifact */
         if ((HRegeneration & ~FROMFORM)
             || (ERegeneration & ~(W_ARTI | W_WEP)))
             u.uhunger--;
         if (near_capacity() > SLT_ENCUMBER)
             u.uhunger--;
-    } else { /* even turns */
+    } else { /* even */
         if (Hunger)
             u.uhunger--;
         /* Conflict uses up food too */
@@ -2851,7 +2864,7 @@ gethungry()
          * cancellation") if hero doesn't have protection from some
          * other source (cloak or second ring).
          */
-        switch ((int) (g.moves % 20)) { /* note: use even cases only */
+        switch ((int) (accessorytime % 20L)) { /* note: use even cases only */
         case 4:
             if (uleft && uleft->otyp != MEAT_RING
                 /* more hungry if +/- is nonzero or +/- doesn't apply or