score wrapping band-aid

This patch simply keeps the score from wrapping by capping it at LONG_MAX.
If someone wants to change the score to be unsigned, some changes will
need to be made to tweak this code (and use ULONG_MAX instead).
I'm assuming that our platforms all have limits.h.
This commit is contained in:
cohrs
2004-03-26 18:28:28 +00:00
parent e424ca4ba3
commit 607f63e5fd
4 changed files with 40 additions and 23 deletions

View File

@@ -3,6 +3,7 @@
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
#include <limits.h>
STATIC_DCL long FDECL(newuexp, (int));
STATIC_DCL int FDECL(enermod, (int));
@@ -99,8 +100,16 @@ void
more_experienced(exp, rexp)
register int exp, rexp;
{
u.uexp += exp;
u.urexp += 4*exp + rexp;
long newexp = u.uexp + exp;
long rexpincr = 4*exp + rexp;
long newrexp = u.urexp + rexpincr;
/* cap experience and score on wraparound */
if (newexp < 0 && exp > 0) newexp = LONG_MAX;
if (newrexp < 0 && rexpincr > 0) newrexp = LONG_MAX;
u.uexp = newexp;
u.urexp = newrexp;
if(exp
#ifdef SCORE_ON_BOTL
|| flags.showscore