]> granicus.if.org Git - nethack/commitdiff
restful sleep bit (trunk only)
authornethack.rankin <nethack.rankin>
Tue, 27 May 2008 04:49:43 +0000 (04:49 +0000)
committernethack.rankin <nethack.rankin>
Tue, 27 May 2008 04:49:43 +0000 (04:49 +0000)
     A change yesterday made putting on an amulet of restful sleep avoid
clobbering the timeout from having already eaten one, only replace it if
the new timeout is shorter.  This does the inverse; when eating one, if
you're already sleepy from also wearing that type of amulet, only replace
the timeout if new one is shorter.  And don't clobber the other intrinsic
bits with FROMOUTSIDE, just add it to whatever ones might already be set.
Neither should have any observable effect on game play, so no fixes entry.

src/eat.c

index 7faac3a6aa360297c290521889f562deb9c05cb5..3f683fce711e360f1e8435129fc21761dcce5662 100644 (file)
--- a/src/eat.c
+++ b/src/eat.c
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)eat.c      3.5     2007/03/19      */
+/*     SCCS Id: @(#)eat.c      3.5     2008/05/26      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -1945,9 +1945,16 @@ struct obj *otmp;
                choke(otmp);
                break;
            case AMULET_OF_RESTFUL_SLEEP: /* another bad idea! */
+             {
+               long newnap = (long)rnd(100), oldnap = (HSleeping & TIMEOUT);
+
                if (!(HSleeping & FROMOUTSIDE))
                    accessory_has_effect(otmp);
-               HSleeping = FROMOUTSIDE | rnd(100);
+               HSleeping |= FROMOUTSIDE;
+               /* might also be wearing one; use shorter of two timeouts */
+               if (newnap < oldnap || oldnap == 0L)
+                   HSleeping = (HSleeping & ~TIMEOUT) | newnap;
+             }
                break;
            case RIN_SUSTAIN_ABILITY:
            case AMULET_OF_LIFE_SAVING: