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:
26
src/end.c
26
src/end.c
@@ -10,8 +10,12 @@
|
||||
#ifndef NO_SIGNAL
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#include "dlb.h"
|
||||
|
||||
/* add b to long a, convert wraparound to max value */
|
||||
#define nowrap_add(a, b) (a = ((a + b) < 0 ? LONG_MAX : (a + b)))
|
||||
|
||||
/* these probably ought to be generated by makedefs, like LAST_GEM */
|
||||
#define FIRST_GEM DILITHIUM_CRYSTAL
|
||||
#define FIRST_AMULET AMULET_OF_ESP
|
||||
@@ -538,7 +542,7 @@ winid endwin;
|
||||
value = arti_cost(otmp); /* zorkmid value */
|
||||
points = value * 5 / 2; /* score value */
|
||||
if (counting) {
|
||||
u.urexp += points;
|
||||
nowrap_add(u.urexp, points);
|
||||
} else {
|
||||
makeknown(otmp->otyp);
|
||||
otmp->known = otmp->dknown = otmp->bknown = otmp->rknown = 1;
|
||||
@@ -567,6 +571,7 @@ int how;
|
||||
boolean bones_ok, have_windows = iflags.window_inited;
|
||||
struct obj *corpse = (struct obj *)0;
|
||||
long umoney;
|
||||
long tmp;
|
||||
|
||||
if (how == TRICKED) {
|
||||
if (killer.name[0]) {
|
||||
@@ -721,7 +726,6 @@ die:
|
||||
|
||||
/* calculate score, before creating bones [container gold] */
|
||||
{
|
||||
long tmp;
|
||||
int deepest = deepest_lev_reached(FALSE);
|
||||
|
||||
#ifndef GOLDOBJ
|
||||
@@ -738,11 +742,11 @@ die:
|
||||
tmp = 0L;
|
||||
if (how < PANICKED)
|
||||
tmp -= tmp / 10L;
|
||||
u.urexp += tmp;
|
||||
u.urexp += 50L * (long)(deepest - 1);
|
||||
tmp += 50L * (long)(deepest - 1);
|
||||
if (deepest > 20)
|
||||
u.urexp += 1000L * (long)((deepest > 30) ? 10 : deepest - 20);
|
||||
if (how == ASCENDED) u.urexp *= 2L;
|
||||
tmp += 1000L * (long)((deepest > 30) ? 10 : deepest - 20);
|
||||
nowrap_add(u.urexp, tmp);
|
||||
if (how == ASCENDED) nowrap_add(u.urexp, u.urexp);
|
||||
}
|
||||
|
||||
if (bones_ok) {
|
||||
@@ -819,9 +823,11 @@ die:
|
||||
/* add points for collected valuables */
|
||||
for (val = valuables; val->list; val++)
|
||||
for (i = 0; i < val->size; i++)
|
||||
if (val->list[i].count != 0L)
|
||||
u.urexp += val->list[i].count
|
||||
if (val->list[i].count != 0L) {
|
||||
tmp = val->list[i].count
|
||||
* (long)objects[val->list[i].typ].oc_cost;
|
||||
nowrap_add(u.urexp, tmp);
|
||||
}
|
||||
|
||||
/* count the points for artifacts */
|
||||
artifact_score(invent, TRUE, endwin);
|
||||
@@ -835,7 +841,7 @@ die:
|
||||
if (Schroedingers_cat) {
|
||||
int mhp, m_lev = adj_lev(&mons[PM_HOUSECAT]);
|
||||
mhp = d(m_lev, 8);
|
||||
u.urexp += mhp;
|
||||
nowrap_add(u.urexp, mhp);
|
||||
if (!done_stopprint)
|
||||
Strcat(eos(pbuf), " and Schroedinger's cat");
|
||||
}
|
||||
@@ -844,7 +850,7 @@ die:
|
||||
if (!done_stopprint)
|
||||
Sprintf(eos(pbuf), " and %s", mon_nam(mtmp));
|
||||
if (mtmp->mtame)
|
||||
u.urexp += mtmp->mhp;
|
||||
nowrap_add(u.urexp, mtmp->mhp);
|
||||
mtmp = mtmp->nmon;
|
||||
}
|
||||
if (!done_stopprint) putstr(endwin, 0, pbuf);
|
||||
|
||||
Reference in New Issue
Block a user