-
-#include "common.h"
-
-#define LINESIZE 100
-#define NDWARVES 6 /* number of dwarves */
-#define PIRATE NDWARVES /* must be NDWARVES-1 when zero-origin */
-#define DALTLC LOC_NUGGET /* alternate dwarf location */
-#define MINTRS 50 /* index of lowest reasure */
-#define MAXTRS 79 /* index of highest reasure */
-#define MAXPARMS 25 /* Max parameters for speak() */
-#define INVLIMIT 7 /* inverntory limit (# of objects) */
-#define INTRANSITIVE -1 /* illegal object number */
-#define SPECIALBASE 300 /* base number of special rooms */
-#define GAMELIMIT 330 /* base limit of turns */
-#define NOVICELIMIT 1000 /* limit of turns for novice */
-#define WARNTIME 30 /* late game starts at game.limit-this */
-#define PANICTIME 15 /* time left after closing */
-#define BATTERYLIFE 2500 /* turn limit increment from batteries */
-
-typedef long token_t; /* word token - someday this will be char[TOKLEN+1] */
-typedef long vocab_t; /* index into a vocabulary array */
-
-struct game_t {
- unsigned long lcg_a, lcg_c, lcg_m, lcg_x;
- long abbnum;
- long blklin;
- long bonus;
- long chloc;
- long chloc2;
- long clock1;
- long clock2;
- 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 */
- long conds;
- long detail;
- long dflag;
- long dkill;
- long dtotal;
- long foobar;
- long holdng;
- long iwest;
- long knfloc;
- long limit;
- bool lmwarn; /* has player been warned about lamp going dim? */
- long loc;
- long newloc;
- bool novice; /* asked for instructions at start-up? */
- long numdie;
- long oldloc;
- long oldlc2;
- long oldobj;
- bool panic; /* has player found out he's trapped in the cave? */
- long saved;
- long tally;
- long thresh;
- long trndex;
- long trnluz;
- long turns;
- bool wzdark; /* whether the loc he's leaving was dark */
- long zzword;
- long abbrev[LOCSIZ + 1];
- long atloc[LOCSIZ + 1];
- long dseen[NDWARVES + 1];
- long dloc[NDWARVES + 1];
- long odloc[NDWARVES + 1];
- long fixed[NOBJECTS + 1];
- long link[NOBJECTS * 2 + 1];
- long place[NOBJECTS + 1];
- long hinted[HNTSIZ + 1];
- long hintlc[HNTSIZ + 1];
- long prop[NOBJECTS + 1];
-};
-
-extern struct game_t game;
-
-extern long LNLENG, LNPOSN, PARMS[];
-extern char rawbuf[LINESIZE], INLINE[LINESIZE + 1];
-extern const char ascii_to_advent[];
-extern const char advent_to_ascii[];
-extern FILE *logfp;
-extern bool oldstyle, editline, prompt;
-
-/* b is not needed for POSIX but harmless */
-#define READ_MODE "rb"
-#define WRITE_MODE "wb"
-extern void* xmalloc(size_t size);
-extern char* xstrdup(const char*);
-extern void packed_to_token(long, char token[]);
-extern void token_to_packed(char token[], long);
-extern void speak(const char*);
-extern bool wordeq(token_t, token_t);
-extern bool wordempty(token_t);
-extern void wordclear(token_t *);
-extern void PSPEAK(vocab_t, int);
-extern void RSPEAK(vocab_t);
-extern void SETPRM(long, long, long);
-extern bool GETIN(FILE *, token_t*, token_t*, token_t*, token_t*);
-extern void echo_input(FILE*, char*, char*);
-extern char* get_input(void);
-extern bool YES(const char*, const char*, const char*);
-extern long GETTXT(bool, bool, bool);
-extern token_t MAKEWD(long);
-extern long VOCAB(long, long);
-extern void JUGGLE(long);
-extern void MOVE(long, long);
-extern long PUT(long, long, long);
-extern void CARRY(long, long);
-extern void DROP(long, long);
-extern long ATDWRF(long);
-extern long SETBIT(long);
-extern bool TSTBIT(long, int);
-extern long RNDVOC(long, long);
-extern bool MAPLIN(FILE *);
-extern void DATIME(long*, long*);
-
-enum termination {endgame, quitgame, scoregame};
-
-extern void set_seed(long);
-extern unsigned long get_next_lcg_value(void);
-extern long randrange(long);
-extern long score(enum termination);
-extern void terminate(enum termination) __attribute__((noreturn));
-extern int suspend(void);
-extern int resume(void);
-extern int restore(FILE *);
+#include <stdarg.h>
+#include <inttypes.h>
+
+#include "dungeon.h"
+
+/* LCG PRNG parameters tested against
+ * Knuth vol. 2. by the original authors */
+#define LCG_A 1093L
+#define LCG_C 221587L
+#define LCG_M 1048576L
+
+#define LINESIZE 1024
+#define TOKLEN 5 // № sigificant characters in a token */
+#define NDWARVES 6 // number of dwarves
+#define PIRATE NDWARVES // must be NDWARVES-1 when zero-origin
+#define DALTLC LOC_NUGGET // alternate dwarf location
+#define INVLIMIT 7 // inverntory limit (№ of objects)
+#define INTRANSITIVE -1 // illegal object number
+#define GAMELIMIT 330 // base limit of turns
+#define NOVICELIMIT 1000 // limit of turns for novice
+#define WARNTIME 30 // late game starts at game.limit-this
+#define FLASHTIME 50 // turns from first warning till blinding flash
+#define PANICTIME 15 // time left after closing
+#define BATTERYLIFE 2500 // turn limit increment from batteries
+#define WORD_NOT_FOUND -1 // "Word not found" flag value for the vocab hash functions.
+#define WORD_EMPTY 0 // "Word empty" flag value for the vocab hash functions
+#define CARRIED -1 // Player is toting it
+#define READ_MODE "rb" // b is not needed for POSIX but harmless
+#define WRITE_MODE "wb" // b is not needed for POSIX but harmless
+
+/* Special object-state values - integers > 0 are object-specific */
+#define STATE_NOTFOUND -1 // 'Not found" state of treasures */
+#define STATE_FOUND 0 // After discovered, before messed with
+#define STATE_IN_CAVITY 1 // State value common to all gemstones
+
+/* Special fixed object-state values - integers > 0 are location */
+#define IS_FIXED -1
+#define IS_FREE 0
+
+/* Map a state property value to a negative range, where the object cannot be
+ * picked up but the value can be recovered later. Avoid colliding with -1,
+ * which has its own meaning. */
+#define STASHED(obj) (-1 - game.prop[obj])