Massaged test files. Fixes issue #41
static int seed(verb_t verb, const char *arg)
/* Set seed */
{
static int seed(verb_t verb, const char *arg)
/* Set seed */
{
+ int32_t seed = strtol(arg, NULL, 10);
speak(actions[verb].message, seed);
set_seed(seed);
--game.turns;
speak(actions[verb].message, seed);
set_seed(seed);
--game.turns;
#include <stdlib.h>
#include <stdbool.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdarg.h>
+/* LCG PRNG parameters tested against
+ * Knuth vol. 2. by the original authors */
+#define LCG_A 1093
+#define LCG_C 221587
+#define LCG_M 1048576
+
#define LINESIZE 1024
#define TOKLEN 5 // № sigificant characters in a token */
#define NDWARVES 6 // number of dwarves
#define LINESIZE 1024
#define TOKLEN 5 // № sigificant characters in a token */
#define NDWARVES 6 // number of dwarves
typedef long turn_t; // turn counter or threshold */
struct game_t {
typedef long turn_t; // turn counter or threshold */
struct game_t {
- unsigned long lcg_a, lcg_c, lcg_m, lcg_x;
long abbnum; // How often to print long descriptions
score_t bonus; // What kind of finishing bonus we are getting
loc_t chloc; // pirate chest location
long abbnum; // How often to print long descriptions
score_t bonus; // What kind of finishing bonus we are getting
loc_t chloc; // pirate chest location
bool clshnt; // has player read the clue in the endgame?
bool closed; // whether we're all the way closed
bool closng; // whether it's closing time yet
bool clshnt; // has player read the clue in the endgame?
bool closed; // whether we're all the way closed
bool closng; // whether it's closing time yet
+ bool lmwarn; // has player been warned about lamp going dim?
+ bool novice; // asked for instructions at start-up?
+ bool panic; // has player found out he's trapped?
+ bool wzdark; // whether the loc he's leaving was dark
+ bool blooded; // has player drunk of dragon's blood?
long conds; // min value for cond[loc] if loc has any hints
long detail; // level of detail in descriptions
long conds; // min value for cond[loc] if loc has any hints
long detail; // level of detail in descriptions
long iwest; // # times he's said "west" instead of "w"
long knfloc; // knife location; 0 if none, -1 after caveat
turn_t limit; // lifetime of lamp
long iwest; // # times he's said "west" instead of "w"
long knfloc; // knife location; 0 if none, -1 after caveat
turn_t limit; // lifetime of lamp
- bool lmwarn; // has player been warned about lamp going dim?
loc_t loc; // where player is now
loc_t newloc; // where player is going
loc_t loc; // where player is now
loc_t newloc; // where player is going
- bool novice; // asked for instructions at start-up?
turn_t numdie; // number of times killed so far
loc_t oldloc; // where player was
loc_t oldlc2; // where player was two moves ago
obj_t oldobj; // last object player handled
turn_t numdie; // number of times killed so far
loc_t oldloc; // where player was
loc_t oldlc2; // where player was two moves ago
obj_t oldobj; // last object player handled
- bool panic; // has player found out he's trapped?
long saved; // point penalty for saves
long tally; // count of treasures gained
long thresh; // current threshold for endgame scoring tier
turn_t trndex; // FIXME: not used, remove on next format bump
turn_t trnluz; // # points lost so far due to turns used
turn_t turns; // counts commands given (ignores yes/no)
long saved; // point penalty for saves
long tally; // count of treasures gained
long thresh; // current threshold for endgame scoring tier
turn_t trndex; // FIXME: not used, remove on next format bump
turn_t trnluz; // # points lost so far due to turns used
turn_t turns; // counts commands given (ignores yes/no)
- bool wzdark; // whether the loc he's leaving was dark
char zzword[TOKLEN + 1]; // randomly generated magic word from bird
char zzword[TOKLEN + 1]; // randomly generated magic word from bird
- bool blooded; // has player drunk of dragon's blood?
long abbrev[NLOCATIONS + 1]; // has location been seen?
long atloc[NLOCATIONS + 1]; // head of object linked list per location
long dseen[NDWARVES + 1]; // true if dwarf has seen him
long abbrev[NLOCATIONS + 1]; // has location been seen?
long atloc[NLOCATIONS + 1]; // head of object linked list per location
long dseen[NDWARVES + 1]; // true if dwarf has seen him
extern int atdwrf(loc_t);
extern long setbit(int);
extern bool tstbit(long, int);
extern int atdwrf(loc_t);
extern long setbit(int);
extern bool tstbit(long, int);
-extern void set_seed(long);
-extern long randrange(long);
+extern void set_seed(int32_t);
+extern int32_t randrange(int32_t);
extern long score(enum termination);
extern void terminate(enum termination) __attribute__((noreturn));
extern long score(enum termination);
extern void terminate(enum termination) __attribute__((noreturn));
-extern int savefile(FILE *, long);
+extern int savefile(FILE *, int32_t);
extern int suspend(void);
extern int resume(void);
extern int restore(FILE *);
extern int suspend(void);
extern int resume(void);
extern int restore(FILE *);
.loc = LOC_START,
.limit = GAMELIMIT,
.foobar = WORD_EMPTY,
.loc = LOC_START,
.limit = GAMELIMIT,
.foobar = WORD_EMPTY,
-
- /* Initialize our LCG PRNG with parameters tested against
- * Knuth vol. 2. by the original authors */
- .lcg_a = 1093,
- .lcg_c = 221587,
- .lcg_m = 1048576,
#include <sys/time.h>
#include <ctype.h>
#include <editline/readline.h>
#include <sys/time.h>
#include <ctype.h>
#include <editline/readline.h>
#include "advent.h"
#include "dungeon.h"
#include "advent.h"
#include "dungeon.h"
i++;
// Integer specifier.
if (msg[i] == 'd') {
i++;
// Integer specifier.
if (msg[i] == 'd') {
- long arg = va_arg(ap, long);
- int ret = snprintf(renderp, size, "%ld", arg);
+ int32_t arg = va_arg(ap, int32_t);
+ int ret = snprintf(renderp, size, "%" PRId32, arg);
if (ret < size) {
renderp += ret;
size -= ret;
if (ret < size) {
renderp += ret;
size -= ret;
return (mask & (1 << bit)) != 0;
}
return (mask & (1 << bit)) != 0;
}
-void set_seed(long seedval)
+void set_seed(int32_t seedval)
- game.lcg_x = (unsigned long) seedval % game.lcg_m;
+ game.lcg_x = (uint32_t) seedval % LCG_M;
// once seed is set, we need to generate the Z`ZZZ word
for (int i = 0; i < 5; ++i) {
// once seed is set, we need to generate the Z`ZZZ word
for (int i = 0; i < 5; ++i) {
-static unsigned long get_next_lcg_value(void)
+static int32_t get_next_lcg_value(void)
/* Return the LCG's current value, and then iterate it. */
{
/* Return the LCG's current value, and then iterate it. */
{
- unsigned long old_x = game.lcg_x;
- game.lcg_x = (game.lcg_a * game.lcg_x + game.lcg_c) % game.lcg_m;
+ int32_t old_x = game.lcg_x;
+ game.lcg_x = (LCG_A * game.lcg_x + LCG_C) % LCG_M;
-long randrange(long range)
+int32_t randrange(int32_t range)
/* Return a random integer from [0, range). */
{
/* Return a random integer from [0, range). */
{
- return range * get_next_lcg_value() / game.lcg_m;
+ return range * get_next_lcg_value() / LCG_M;
#include <string.h>
#include <editline/readline.h>
#include <time.h>
#include <string.h>
#include <editline/readline.h>
#include <time.h>
#include "advent.h"
#include "dungeon.h"
#include "advent.h"
#include "dungeon.h"
* see the history.adoc file in the source distribution for discussion.
*/
* see the history.adoc file in the source distribution for discussion.
*/
-#define VRSION 27 /* bump on save format change */
+#define VRSION 28 /* bump on save format change */
/*
* If you change the first three members, the resume function may not properly
/*
* If you change the first three members, the resume function may not properly
* when you do that.
*/
struct save_t {
* when you do that.
*/
struct save_t {
- long savetime;
- long mode; /* not used, must be present for version detection */
- long version;
+ int64_t savetime;
+ int32_t mode; /* not used, must be present for version detection */
+ int32_t version;
struct game_t game;
};
struct save_t save;
#define IGNORE(r) do{if (r){}}while(0)
struct game_t game;
};
struct save_t save;
#define IGNORE(r) do{if (r){}}while(0)
-int savefile(FILE *fp, long version)
+int savefile(FILE *fp, int32_t version)
/* Save game to file. No input or output from user. */
{
save.savetime = time(NULL);
/* Save game to file. No input or output from user. */
{
save.savetime = time(NULL);
- /* Prevent RNG substitution. Why we are saving PRNG parameters? */
-
- if (valgame->lcg_a != game.lcg_a || valgame->lcg_c != game.lcg_c || valgame->lcg_m != game.lcg_m) {
- return false;
- }
-
/* Check for RNG overflow. Truncate */
/* Check for RNG overflow. Truncate */
- if (valgame->lcg_x >= game.lcg_m) {
- valgame->lcg_x %= game.lcg_m;
+ if (valgame->lcg_x >= LCG_M) {
+ valgame->lcg_x %= LCG_M;
}
/* Bounds check for locations */
}
/* Bounds check for locations */
-/* end */
\ No newline at end of file
Can't open file y, try again.
I'm sorry, but that Adventure was begun using Version -133.-7 of the
Can't open file y, try again.
I'm sorry, but that Adventure was begun using Version -133.-7 of the
-save file format, and this program uses Version 2.7. You must find an instance
+save file format, and this program uses Version 2.8. You must find an instance
using that other version in order to resume that Adventure.
You're in front of building.
using that other version in order to resume that Adventure.
You're in front of building.