9 #define NDWARVES 6 /* number of dwarves */
10 #define PIRATE NDWARVES /* must be NDWARVES-1 when zero-origin */
11 #define DALTLC LOC_NUGGET /* alternate dwarf location */
12 #define MINTRS 50 /* index of lowest reasure */
13 #define MAXTRS 79 /* index of highest reasure */
14 #define MAXPARMS 25 /* Max parameters for speak() */
15 #define INVLIMIT 7 /* inverntory limit (# of objects) */
16 #define INTRANSITIVE -1 /* illegal object number */
17 #define SPECIALBASE 300 /* base number of special rooms */
18 #define GAMELIMIT 330 /* base limit of turns */
19 #define NOVICELIMIT 1000 /* limit of turns for novice */
20 #define WARNTIME 30 /* late game starts at game.limit-this */
21 #define PANICTIME 15 /* time left after closing */
22 #define BATTERYLIFE 2500 /* turn limit increment from batteries */
24 typedef long token_t; /* word token - someday this will be char[TOKLEN+1] */
25 typedef long vocab_t; /* index into a vocabulary array */
28 unsigned long lcg_a, lcg_c, lcg_m, lcg_x;
36 bool clshnt; /* has player read the clue in the endgame? */
37 bool closed; /* whether we're all the way closed */
38 bool closng; /* whether it's closing time yet */
49 bool lmwarn; /* has player been warned about lamp going dim? */
52 bool novice; /* asked for instructions at start-up? */
57 bool panic; /* has player found out he's trapped in the cave? */
64 bool wzdark; /* whether the loc he's leaving was dark */
66 long abbrev[LOCSIZ + 1];
67 long atloc[LOCSIZ + 1];
68 long dseen[NDWARVES + 1];
69 long dloc[NDWARVES + 1];
70 long odloc[NDWARVES + 1];
71 long fixed[NOBJECTS + 1];
72 long link[NOBJECTS * 2 + 1];
73 long place[NOBJECTS + 1];
74 long hinted[HINT_COUNT];
75 long hintlc[HINT_COUNT];
76 long prop[NOBJECTS + 1];
79 extern struct game_t game;
81 extern long LNLENG, LNPOSN;
82 extern char rawbuf[LINESIZE], INLINE[LINESIZE + 1];
83 extern const char ascii_to_advent[];
84 extern const char advent_to_ascii[];
86 extern bool oldstyle, editline, prompt;
88 /* b is not needed for POSIX but harmless */
89 #define READ_MODE "rb"
90 #define WRITE_MODE "wb"
91 extern void* xmalloc(size_t size);
92 extern char* xstrdup(const char*);
93 extern void packed_to_token(long, char token[]);
94 extern void token_to_packed(char token[], long*);
95 extern void vspeak(const char*, va_list);
96 extern bool wordeq(token_t, token_t);
97 extern bool wordempty(token_t);
98 extern void wordclear(token_t *);
99 extern void speak(const char*, ...);
100 extern void pspeak(vocab_t, int, ...);
101 extern void rspeak(vocab_t, ...);
102 extern bool GETIN(FILE *, token_t*, token_t*, token_t*, token_t*);
103 extern void echo_input(FILE*, char*, char*);
104 extern char* get_input(void);
105 extern bool YES(const char*, const char*, const char*);
106 extern long GETTXT(bool, bool, bool);
107 extern token_t MAKEWD(long);
108 extern long VOCAB(long, long);
109 extern void JUGGLE(long);
110 extern void MOVE(long, long);
111 extern long PUT(long, long, long);
112 extern void CARRY(long, long);
113 extern void DROP(long, long);
114 extern long ATDWRF(long);
115 extern long SETBIT(long);
116 extern bool TSTBIT(long, int);
117 extern long RNDVOC(long, long);
118 extern bool MAPLIN(FILE *);
119 extern void DATIME(long*, long*);
121 enum termination {endgame, quitgame, scoregame};
123 extern void set_seed(long);
124 extern unsigned long get_next_lcg_value(void);
125 extern long randrange(long);
126 extern long score(enum termination);
127 extern void terminate(enum termination) __attribute__((noreturn));
128 extern int suspend(void);
129 extern int resume(void);
130 extern int restore(FILE *);
133 * MOD(N,M) = Arithmetic modulus
134 * AT(OBJ) = true if on either side of two-placed object
135 * CNDBIT(L,N) = true if COND(L) has bit n set (bit 0 is units bit)
136 * DARK(LOC) = true if location "LOC" is dark
137 * FORCED(LOC) = true if LOC moves without asking for input (COND=2)
138 * FOREST(LOC) = true if LOC is part of the forest
139 * GSTONE(OBJ) = true if OBJ is a gemstone
140 * HERE(OBJ) = true if the OBJ is at "LOC" (or is being carried)
141 * LIQUID() = object number of liquid in bottle
142 * LIQLOC(LOC) = object number of liquid (if any) at LOC
143 * PCT(N) = true N% of the time (N integer from 0 to 100)
144 * TOTING(OBJ) = true if the OBJ is being carried */
146 #define DESTROY(N) MOVE(N, LOC_NOWHERE)
147 #define MOD(N,M) ((N) % (M))
148 #define TOTING(OBJ) (game.place[OBJ] == CARRIED)
149 #define AT(OBJ) (game.place[OBJ] == game.loc || game.fixed[OBJ] == game.loc)
150 #define HERE(OBJ) (AT(OBJ) || TOTING(OBJ))
151 #define LIQ2(PBOTL) ((1-(PBOTL))*WATER+((PBOTL)/2)*(WATER+OIL))
152 #define LIQUID() (LIQ2(game.prop[BOTTLE]<0 ? -1-game.prop[BOTTLE] : game.prop[BOTTLE]))
153 #define LIQLOC(LOC) (LIQ2((MOD(COND[LOC]/2*2,8)-5)*MOD(COND[LOC]/4,2)+1))
154 #define CNDBIT(L,N) (TSTBIT(COND[L],N))
155 #define FORCED(LOC) (COND[LOC] == 2)
156 #define DARK(DUMMY) ((!CNDBIT(game.loc,LIGHT)) && (game.prop[LAMP] == 0 || !HERE(LAMP)))
157 #define PCT(N) (randrange(100) < (N))
158 #define GSTONE(OBJ) ((OBJ) == EMERALD || (OBJ) == RUBY || (OBJ) == AMBER || (OBJ) == SAPPH)
159 #define FOREST(LOC) ((LOC) >= LOC_FOREST1 && (LOC) <= LOC_FOREST22)
160 #define VOCWRD(LETTRS,SECT) (VOCAB(MAKEWD(LETTRS),SECT))
161 #define SPECIAL(LOC) ((LOC) > SPECIALBASE)
163 /* The following two functions were added to fix a bug (game.clock1 decremented
164 * while in forest). They should probably be replaced by using another
165 * "cond" bit. For now, however, a quick fix... OUTSID(LOC) is true if
166 * LOC is outside, INDEEP(LOC) is true if LOC is "deep" in the cave (hall
167 * of mists or deeper). Note special kludges for "Foof!" locs. */
169 #define OUTSID(LOC) ((LOC) <= LOC_GRATE || FOREST(LOC) || (LOC) == PLAC[SAPPH] || (LOC) == LOC_FOOF2 || (LOC) == LOC_FOOF4)
170 #define INDEEP(LOC) ((LOC) >= LOC_MISTHALL && !OUTSID(LOC) && (LOC) != LOC_FOOF1)
172 /* vocabulary items */
173 extern long AMBER, ATTACK, AXE, BACK, BATTERY, BEAR,
174 BIRD, BLOOD, BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST,
175 CLAM, COINS, DOOR, DPRSSN, DRAGON, DWARF, EGGS,
176 EMERALD, ENTER, ENTRNC, FIND, FISSURE, FOOD, GRATE, HINT, INVENT,
177 JADE, KEYS, KNIFE, LAMP, LOCK, LOOK, MAGAZINE, MESSAG, MIRROR, NUGGET, NUL,
178 OGRE, OIL, OYSTER, PANIC, PEARL, PILLOW, PLANT, PLANT2, PYRAMID,
179 RESER, ROD, ROD2, RUBY, RUG, SAPPH, SAY, SIGN, SNAKE,
180 STEPS, STICK, STREAM, THROW, TRIDENT, TROLL, TROLL2,
181 URN, VASE, VEND, VOLCANO, WATER;
183 enum speechpart {unknown, intransitive, transitive};
186 enum speechpart part;
193 void initialise(void);
194 int action(FILE *input, struct command_t *command);
196 /* Phase codes for action returns.
197 * These were at one time FORTRAN line numbers.
198 * The values don't matter, but perturb their order at your peril.
200 #define GO_TERMINATE 2
203 #define GO_CLEAROBJ 2012
204 #define GO_CHECKHINT 2600
205 #define GO_CHECKFOO 2607
206 #define GO_DIRECTION 2620
207 #define GO_LOOKUP 2630
208 #define GO_WORD2 2800
209 #define GO_SPECIALS 1900
210 #define GO_UNKNOWN 8000
211 #define GO_ACTION 40000
212 #define GO_DWARFWAKE 19000
214 /* Symbols for cond bits */
215 #define LIGHT 0 /* Light */
216 #define OILY 1 /* If bit 2 is on: on for oil, off for water */
217 #define FLUID 2 /* Liquid asset, see bit 1 */
218 #define NOARRR 3 /* Pirate doesn't go here unless following player */
219 #define NOBACK 4 /* Cannot use "back" to move away */
220 /* Bits past 10 indicate areas of interest to "hint" routines */
221 #define HBASE 10 /* Base for location hint bits */
222 #define HCAVE 11 /* Trying to get into cave */
223 #define HBIRD 12 /* Trying to catch bird */
224 #define HSNAKE 13 /* Trying to deal with snake */
225 #define HMAZE 14 /* Lost in maze */
226 #define HDARK 15 /* Pondering dark room */
227 #define HWITT 16 /* At Witt's End */
228 #define HCLIFF 17 /* Cliff with urn */
229 #define HWOODS 18 /* Lost in forest */
230 #define HOGRE 19 /* Trying to deal with ogre */
231 #define HJADE 20 /* Found all treasures except jade */
233 /* Special object statuses in game.place - can also be a location number (> 0) */
234 #define CARRIED -1 /* Player is toting it */
236 /* hack to ignore GCC Unused Result */
237 #define IGNORE(r) do{if (r){}}while(0)
240 * FIXME: These constants should be replaced by strings, at their usage sites.
241 * They are sixbit-packed representations of vocabulary words. This, and code
242 * left in misc.c, is the only place left in the runtime that knows about
245 #define WORD_AXE 12405
246 #define WORD_BATTERY 201202005
247 #define WORD_BEAR 2050118
248 #define WORD_BIRD 2091804
249 #define WORD_BLOOD 212151504
250 #define WORD_BOTTLE 215202012
251 #define WORD_CAGE 3010705
252 #define WORD_CATCH 301200308
253 #define WORD_CAVITY 301220920
254 #define WORD_CHASM 308011913
255 #define WORD_CLAM 3120113
256 #define WORD_DOOR 4151518
257 #define WORD_DRAGON 418010715
258 #define WORD_DWARF 423011806
259 #define WORD_FISSURE 609191921
260 #define WORD_FOOD 6151504
262 #define WORD_GRATE 718012005
263 #define WORD_KEYS 11052519
264 #define WORD_KNIFE 1114090605
265 #define WORD_LAMP 12011316
266 #define WORD_MAGAZINE 1301070126
267 #define WORD_MESSAG 1305191901
268 #define WORD_MIRROR 1309181815
269 #define WORD_OGRE 15071805
270 #define WORD_OIL 150912
271 #define WORD_OYSTER 1525192005
272 #define WORD_PILLOW 1609121215
273 #define WORD_PLANT 1612011420
274 #define WORD_POUR 16152118
275 #define WORD_RESER 1805190518
276 #define WORD_ROD 181504
277 #define WORD_SIGN 19090714
278 #define WORD_SNAKE 1914011105
279 #define WORD_STEPS 1920051619
280 #define WORD_TROLL 2018151212
281 #define WORD_URN 211814
282 #define WORD_VEND 1755140409
283 #define WORD_VOLCANO 1765120301
284 #define WORD_WATER 1851200518
285 #define WORD_AMBER 113020518
286 #define WORD_CHAIN 308010914
287 #define WORD_CHEST 308051920
288 #define WORD_COINS 315091419
289 #define WORD_EGGS 5070719
290 #define WORD_EMERALD 513051801
291 #define WORD_JADE 10010405
292 #define WORD_NUGGET 7151204
293 #define WORD_PEARL 1605011812
294 #define WORD_PYRAMID 1625180113
295 #define WORD_RUBY 18210225
296 #define WORD_RUG 182107
297 #define WORD_SAPPH 1901161608
298 #define WORD_TRIDENT 2018090405
299 #define WORD_VASE 22011905
300 #define WORD_BACK 2010311
301 #define WORD_CAVE 3012205
302 #define WORD_DPRSSN 405161805
303 #define WORD_ENTER 514200518
304 #define WORD_ENTRNC 514201801
305 #define WORD_LOOK 12151511
306 #define WORD_NUL 14211212
307 #define WORD_STREAM 1920180501
308 #define WORD_FIND 6091404
309 #define WORD_INVENT 914220514
310 #define WORD_LOCK 12150311
311 #define WORD_SAY 190125
312 #define WORD_THROW 2008181523
313 #define WORD_WEST 23051920
314 #define WORD_YES 250519
315 #define WORD_YINIT 25