8 #define NDWARVES 6 // number of dwarves
9 #define PIRATE NDWARVES // must be NDWARVES-1 when zero-origin
10 #define DALTLC LOC_NUGGET // alternate dwarf location
11 #define INVLIMIT 7 // inverntory limit (# of objects)
12 #define INTRANSITIVE -1 // illegal object number
13 #define SPECIALBASE 300 // base number of special rooms
14 #define GAMELIMIT 330 // base limit of turns
15 #define NOVICELIMIT 1000 // limit of turns for novice
16 #define WARNTIME 30 // late game starts at game.limit-this
17 #define FLASHTIME 50 // turns from first warning till blinding flash
18 #define PANICTIME 15 // time left after closing
19 #define BATTERYLIFE 2500 // turn limit increment from batteries
20 #define WORD_NOT_FOUND -1 // "Word not found" flag value for the vocab hash functions.
21 #define CARRIED -1 // Player is toting it
22 #define READ_MODE "rb" // b is not needed for POSIX but harmless
23 #define WRITE_MODE "wb" // b is not needed for POSIX but harmless
26 * MOD(N,M) = Arithmetic modulus
27 * AT(OBJ) = true if on either side of two-placed object
28 * CNDBIT(L,N) = true if COND(L) has bit n set (bit 0 is units bit)
29 * DARK(LOC) = true if location "LOC" is dark
30 * FORCED(LOC) = true if LOC moves without asking for input (COND=2)
31 * FOREST(LOC) = true if LOC is part of the forest
32 * GSTONE(OBJ) = true if OBJ is a gemstone
33 * HERE(OBJ) = true if the OBJ is at "LOC" (or is being carried)
34 * LIQUID() = object number of liquid in bottle
35 * LIQLOC(LOC) = object number of liquid (if any) at LOC
36 * PCT(N) = true N% of the time (N integer from 0 to 100)
37 * TOTING(OBJ) = true if the OBJ is being carried */
38 #define DESTROY(N) move(N, LOC_NOWHERE)
39 #define MOD(N,M) ((N) % (M))
40 #define TOTING(OBJ) (game.place[OBJ] == CARRIED)
41 #define AT(OBJ) (game.place[OBJ] == game.loc || game.fixed[OBJ] == game.loc)
42 #define HERE(OBJ) (AT(OBJ) || TOTING(OBJ))
43 #define LIQ2(PBOTL) ((1-(PBOTL))*WATER+((PBOTL)/2)*(WATER+OIL))
44 #define LIQUID() (LIQ2(game.prop[BOTTLE]<0 ? -1-game.prop[BOTTLE] : game.prop[BOTTLE]))
45 #define LIQLOC(LOC) (LIQ2((MOD(conditions[LOC]/2*2,8)-5)*MOD(conditions[LOC]/4,2)+1))
46 #define CNDBIT(L,N) (tstbit(conditions[L],N))
47 #define FORCED(LOC) CNDBIT(LOC, COND_FORCED)
48 #define DARK(DUMMY) ((!tstbit(conditions[game.loc],COND_LIT)) && (game.prop[LAMP] == LAMP_DARK || !HERE(LAMP)))
49 #define PCT(N) (randrange(100) < (N))
50 #define GSTONE(OBJ) ((OBJ) == EMERALD || (OBJ) == RUBY || (OBJ) == AMBER || (OBJ) == SAPPH)
51 #define FOREST(LOC) CNDBIT(LOC, COND_FOREST)
52 #define SPECIAL(LOC) ((LOC) > SPECIALBASE)
53 #define OUTSID(LOC) (CNDBIT(LOC, COND_ABOVE) || FOREST(LOC))
54 #define INDEEP(LOC) ((LOC) >= LOC_MISTHALL && !OUTSID(LOC))
55 #define BUG(x) bug(x, #x)
58 SPECIAL_TRAVEL_500_GT_L_GT_300_EXCEEDS_GOTO_LIST,
59 VOCABULARY_TYPE_N_OVER_1000_NOT_BETWEEN_0_AND_3,
60 INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST,
61 TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST,
62 CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION,
63 LOCATION_HAS_NO_TRAVEL_ENTRIES,
64 HINT_NUMBER_EXCEEDS_GOTO_LIST,
65 SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN,
66 ACTION_RETURNED_PHASE_CODE_BEYOND_END_OF_SWITCH,
69 enum speaktype {touch, look, hear, study, change};
71 enum termination {endgame, quitgame, scoregame};
73 enum speechpart {unknown, intransitive, transitive};
75 /* Phase codes for action returns.
76 * These were at one time FORTRAN line numbers.
77 * The values don't matter, but perturb their order at your peril.
95 typedef long token_t; // word token - someday this will be char[TOKLEN+1]
96 typedef long vocab_t; // index into a vocabulary array */
99 unsigned long lcg_a, lcg_c, lcg_m, lcg_x;
100 long abbnum; // How often to print non-abbreviated descriptions
105 long clock1; // # turns from finding last treasure till closing
106 long clock2; // # turns from first warning till blinding flash
107 bool clshnt; // has player read the clue in the endgame?
108 bool closed; // whether we're all the way closed
109 bool closng; // whether it's closing time yet
110 long conds; // min value for cond(loc) if loc has any hints
115 long foobar; // current progress in saying "FEE FIE FOE FOO".
116 long holdng; // number of objects being carried
117 long iwest; // How many times he's said "west" instead of "w"
118 long knfloc; // 0 if no knife here, loc if knife , -1 after caveat
119 long limit; // lifetime of lamp (not set here)
120 bool lmwarn; // has player been warned about lamp going dim?
123 bool novice; // asked for instructions at start-up?
124 long numdie; // number of times killed so far
128 bool panic; // has player found out he's trapped in the cave?
129 long saved; // point penalty for saves
133 long trnluz; // # points lost so far due to number of turns used
134 long turns; // how many commands he's given (ignores yes/no)
135 bool wzdark; // whether the loc he's leaving was dark
136 char zzword[6]; // randomly generated magic word from bird
137 bool blooded; // has player drunk of dragon's blood?
138 long abbrev[NLOCATIONS + 1];
139 long atloc[NLOCATIONS + 1];
140 long dseen[NDWARVES + 1];
141 long dloc[NDWARVES + 1];
142 long odloc[NDWARVES + 1];
143 long fixed[NOBJECTS + 1];
144 long link[NOBJECTS * 2 + 1];
145 long place[NOBJECTS + 1];
148 long prop[NOBJECTS + 1];
152 enum speechpart part;
159 extern struct game_t game;
161 extern bool oldstyle, editline, prompt;
163 extern char* xstrdup(const char* s);
164 extern void* xmalloc(size_t size);
165 extern void packed_to_token(long, char token[]);
166 extern long token_to_packed(const char token[6]);
167 extern void tokenize(char*, long tokens[4]);
168 extern void vspeak(const char*, va_list);
169 extern bool wordeq(token_t, token_t);
170 extern bool wordempty(token_t);
171 extern void wordclear(token_t *);
172 extern void speak(const char*, ...);
173 extern void pspeak(vocab_t, enum speaktype, int, ...);
174 extern void rspeak(vocab_t, ...);
175 extern void echo_input(FILE*, char*, char*);
176 extern int word_count(char*);
177 extern char* get_input(void);
178 extern bool silent_yes(void);
179 extern bool yes(const char*, const char*, const char*);
180 extern int get_motion_vocab_id(const char*);
181 extern int get_object_vocab_id(const char*);
182 extern int get_action_vocab_id(const char*);
183 extern int get_special_vocab_id(const char*);
184 extern long get_vocab_id(const char*);
185 extern void juggle(long);
186 extern void move(long, long);
187 extern long put(long, long, long);
188 extern void carry(long, long);
189 extern void drop(long, long);
190 extern long atdwrf(long);
191 extern long setbit(long);
192 extern bool tstbit(long, int);
193 extern void make_zzword(char*);
194 extern void datime(long*, long*);
195 extern void set_seed(long);
196 extern unsigned long get_next_lcg_value(void);
197 extern long randrange(long);
198 extern long score(enum termination);
199 extern void terminate(enum termination) __attribute__((noreturn));
200 extern int savefile(FILE *, long);
201 extern int suspend(void);
202 extern int resume(void);
203 extern int restore(FILE *);
204 extern void initialise(void);
205 extern int action(struct command_t *command);
207 /* Alas, declaring this static confuses the coverage analyzer */
208 void bug(enum bugtype, const char *) __attribute__((__noreturn__));