]> granicus.if.org Git - nethack/commitdiff
stabilize loss of gold
authorPatR <rankin@nethack.org>
Sat, 2 May 2015 01:01:12 +0000 (18:01 -0700)
committerPatR <rankin@nethack.org>
Sat, 2 May 2015 01:01:12 +0000 (18:01 -0700)
When gold is stolen by a leprechaun or lost when being "overwhelmed
by an urge to take a bath" while dipping in a fountain, if you had
99 gold pieces or less, you'd lose all of it (in the bath case, only
if it was at least 10 to start with), but if you had 100 or more,
you would lose a random amount which could be as little as 1.  And
in the bath case, if the random amount was less than 10, you would
lose nothing but be told that "you lost some of your money in the
fountain".  After this change, it is still possible to lose less
when starting with more, but not as likely and not as extreme a case
as maybe losing only 1 when starting with thousands.

The fountain-dip bath case has code to handle mutiple denominations
of coins, possibly the only place in the program where that exists.
I've left that alone although it should probably be taken out....

src/steal.c

index f803ae4dae24022be3d2728a61047dc37cafac85..e3f09f5245209a83e6309456ed466eb6cc5b8670 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.5 steal.c $NHDT-Date$  $NHDT-Branch$:$NHDT-Revision$ */
+/* NetHack 3.5 steal.c $NHDT-Date: 1430528463 2015/05/02 01:01:03 $  $NHDT-Branch: master $:$NHDT-Revision: 1.53 $ */
 /* NetHack 3.5 steal.c $Date: 2012/02/05 04:26:48 $  $Revision: 1.41 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -23,15 +23,31 @@ register struct obj *otmp;
 }
 
 long           /* actually returns something that fits in an int */
-somegold(umoney)
-long umoney;
+somegold(lmoney)
+long lmoney;
 {
 #ifdef LINT    /* long conv. ok */
-       return(0L);
+    int igold = 0;
 #else
-       return (long)( (umoney < 100) ? umoney :
-               (umoney > 10000) ? rnd(10000) : rnd((int) umoney) );
+    int igold = (lmoney >= (long)LARGEST_INT) ? LARGEST_INT : (int)lmoney;
 #endif
+
+    if (igold < 50)
+       ;       /* all gold */
+    else if (igold < 100)
+       igold = rn1(igold - 25 + 1, 25);
+    else if (igold < 500)
+       igold = rn1(igold - 50 + 1, 50);
+    else if (igold < 1000)
+       igold = rn1(igold - 100 + 1, 100);
+    else if (igold < 5000)
+       igold = rn1(igold - 500 + 1, 500);
+    else if (igold < 10000)
+       igold = rn1(igold - 1000 + 1, 1000);
+    else
+       igold = rn1(igold - 5000 + 1, 5000);
+
+    return (long)igold;
 }
 
 /*