+/*
+ * Saving and resuming.
+ *
+ * (ESR) This replaces a bunch of particularly nasty FORTRAN-derived code;
+ * see the history.adoc file in the source distribution for discussion.
+ *
+ * Copyright (c) 1977, 2005 by Will Crowther and Don Woods
+ * Copyright (c) 2017 by Eric S. Raymond
+ * SPDX-License-Identifier: BSD-2-clause
+ */
+
#include <stdlib.h>
#include <string.h>
#include <editline/readline.h>
#include "advent.h"
#include "dungeon.h"
-/*
- * (ESR) This replaces a bunch of particularly nasty FORTRAN-derived code;
- * see the history.adoc file in the source distribution for discussion.
- */
-
#define VRSION 28 /* bump on save format change */
/*
valgame->lcg_x %= LCG_M;
}
+ /* Check for RNG underflow. Transpose */
+ if (valgame->lcg_x < LCG_M) {
+ valgame->lcg_x = LCG_M + (valgame->lcg_x % LCG_M);
+ }
+
/* Bounds check for locations */
if ( valgame->chloc < -1 || valgame->chloc > NLOCATIONS ||
valgame->chloc2 < -1 || valgame->chloc2 > NLOCATIONS ||
- valgame->loc < -1 || valgame->loc > NLOCATIONS ||
- valgame->newloc < -1 || valgame->newloc > NLOCATIONS ||
- valgame->oldloc < -1 || valgame->oldloc > NLOCATIONS ||
- valgame->oldlc2 < -1 || valgame->oldlc2 > NLOCATIONS) {
+ valgame->loc < 0 || valgame->loc > NLOCATIONS ||
+ valgame->newloc < 0 || valgame->newloc > NLOCATIONS ||
+ valgame->oldloc < 0 || valgame->oldloc > NLOCATIONS ||
+ valgame->oldlc2 < 0 || valgame->oldlc2 > NLOCATIONS) {
return false;
}
/* Bounds check for location arrays */