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.
22 typedef long token_t; // word token - someday this will be char[TOKLEN+1]
23 typedef long vocab_t; // index into a vocabulary array */
26 SPECIAL_TRAVEL_500_GT_L_GT_300_EXCEEDS_GOTO_LIST = 20, // 20
27 VOCABULARY_TYPE_N_OVER_1000_NOT_BETWEEN_0_AND_3 = 22, // 22
28 INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST, // 23
29 TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST, // 24
30 CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION, // 25
31 LOCATION_HAS_NO_TRAVEL_ENTRIES, // 26
32 HINT_NUMBER_EXCEEDS_GOTO_LIST, // 27
33 TOO_MANY_PARAMETERS_GIVEN_TO_SETPRM, // 28
34 SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN=99, // 99
35 ACTION_RETURNED_PHASE_CODE_BEYOND_END_OF_SWITCH, // 100
38 /* Alas, declaring this static confuses the coverage analyzer */
39 void bug(enum bugtype, const char *) __attribute__((__noreturn__));
40 #define BUG(x) bug(x, #x)
43 unsigned long lcg_a, lcg_c, lcg_m, lcg_x;
44 long abbnum; // How often to print non-abbreviated descriptions
49 long clock1; // # turns from finding last treasure till closing
50 long clock2; // # turns from first warning till blinding flash
51 bool clshnt; // has player read the clue in the endgame?
52 bool closed; // whether we're all the way closed
53 bool closng; // whether it's closing time yet
54 long conds; // min value for cond(loc) if loc has any hints
59 long foobar; // current progress in saying "FEE FIE FOE FOO".
60 long holdng; // number of objects being carried
61 long iwest; // How many times he's said "west" instead of "w"
62 long knfloc; // 0 if no knife here, loc if knife , -1 after caveat
63 long limit; // lifetime of lamp (not set here)
64 bool lmwarn; // has player been warned about lamp going dim?
67 bool novice; // asked for instructions at start-up?
68 long numdie; // number of times killed so far
72 bool panic; // has player found out he's trapped in the cave?
73 long saved; // point penalty for saves
77 long trnluz; // # points lost so far due to number of turns used
78 long turns; // how many commands he's given (ignores yes/no)
79 bool wzdark; // whether the loc he's leaving was dark
80 char zzword[6]; // randomly generated magic word from bird
81 bool blooded; // has player drunk of dragon's blood?
82 long abbrev[NLOCATIONS + 1];
83 long atloc[NLOCATIONS + 1];
84 long dseen[NDWARVES + 1];
85 long dloc[NDWARVES + 1];
86 long odloc[NDWARVES + 1];
87 long fixed[NOBJECTS + 1];
88 long link[NOBJECTS * 2 + 1];
89 long place[NOBJECTS + 1];
92 long prop[NOBJECTS + 1];
95 extern struct game_t game;
98 extern bool oldstyle, editline, prompt;
100 enum speaktype {touch, look, hear, study, change};
102 /* b is not needed for POSIX but harmless */
103 #define READ_MODE "rb"
104 #define WRITE_MODE "wb"
105 extern char* xstrdup(const char* s);
106 extern void* xmalloc(size_t size);
107 extern void packed_to_token(long, char token[]);
108 extern long token_to_packed(const char token[6]);
109 extern void tokenize(char*, long tokens[4]);
110 extern void vspeak(const char*, va_list);
111 extern bool wordeq(token_t, token_t);
112 extern bool wordempty(token_t);
113 extern void wordclear(token_t *);
114 extern void speak(const char*, ...);
115 extern void pspeak(vocab_t, enum speaktype, int, ...);
116 extern void rspeak(vocab_t, ...);
117 extern void echo_input(FILE*, char*, char*);
118 extern int word_count(char*);
119 extern char* get_input(void);
120 extern bool silent_yes(void);
121 extern bool yes(const char*, const char*, const char*);
122 extern int get_motion_vocab_id(const char*);
123 extern int get_object_vocab_id(const char*);
124 extern int get_action_vocab_id(const char*);
125 extern int get_special_vocab_id(const char*);
126 extern long get_vocab_id(const char*);
127 extern void juggle(long);
128 extern void move(long, long);
129 extern long put(long, long, long);
130 extern void carry(long, long);
131 extern void drop(long, long);
132 extern long atdwrf(long);
133 extern long setbit(long);
134 extern bool tstbit(long, int);
135 extern void make_zzword(char*);
136 extern void datime(long*, long*);
138 enum termination {endgame, quitgame, scoregame};
140 extern void set_seed(long);
141 extern unsigned long get_next_lcg_value(void);
142 extern long randrange(long);
143 extern long score(enum termination);
144 extern void terminate(enum termination) __attribute__((noreturn));
145 extern int savefile(FILE *, long);
146 extern int suspend(void);
147 extern int resume(void);
148 extern int restore(FILE *);
151 * MOD(N,M) = Arithmetic modulus
152 * AT(OBJ) = true if on either side of two-placed object
153 * CNDBIT(L,N) = true if COND(L) has bit n set (bit 0 is units bit)
154 * DARK(LOC) = true if location "LOC" is dark
155 * FORCED(LOC) = true if LOC moves without asking for input (COND=2)
156 * FOREST(LOC) = true if LOC is part of the forest
157 * GSTONE(OBJ) = true if OBJ is a gemstone
158 * HERE(OBJ) = true if the OBJ is at "LOC" (or is being carried)
159 * LIQUID() = object number of liquid in bottle
160 * LIQLOC(LOC) = object number of liquid (if any) at LOC
161 * PCT(N) = true N% of the time (N integer from 0 to 100)
162 * TOTING(OBJ) = true if the OBJ is being carried */
164 #define DESTROY(N) move(N, LOC_NOWHERE)
165 #define MOD(N,M) ((N) % (M))
166 #define TOTING(OBJ) (game.place[OBJ] == CARRIED)
167 #define AT(OBJ) (game.place[OBJ] == game.loc || game.fixed[OBJ] == game.loc)
168 #define HERE(OBJ) (AT(OBJ) || TOTING(OBJ))
169 #define LIQ2(PBOTL) ((1-(PBOTL))*WATER+((PBOTL)/2)*(WATER+OIL))
170 #define LIQUID() (LIQ2(game.prop[BOTTLE]<0 ? -1-game.prop[BOTTLE] : game.prop[BOTTLE]))
171 #define LIQLOC(LOC) (LIQ2((MOD(conditions[LOC]/2*2,8)-5)*MOD(conditions[LOC]/4,2)+1))
172 #define CNDBIT(L,N) (tstbit(conditions[L],N))
173 #define FORCED(LOC) CNDBIT(LOC, COND_FORCED)
174 #define DARK(DUMMY) ((!tstbit(conditions[game.loc],COND_LIT)) && (game.prop[LAMP] == LAMP_DARK || !HERE(LAMP)))
175 #define PCT(N) (randrange(100) < (N))
176 #define GSTONE(OBJ) ((OBJ) == EMERALD || (OBJ) == RUBY || (OBJ) == AMBER || (OBJ) == SAPPH)
177 #define FOREST(LOC) CNDBIT(LOC, COND_FOREST)
178 #define SPECIAL(LOC) ((LOC) > SPECIALBASE)
179 #define OUTSID(LOC) (CNDBIT(LOC, COND_ABOVE) || FOREST(LOC))
181 #define INDEEP(LOC) ((LOC) >= LOC_MISTHALL && !OUTSID(LOC))
183 enum speechpart {unknown, intransitive, transitive};
186 enum speechpart part;
193 void initialise(void);
194 int action(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 /* Special object statuses in game.place - can also be a location number (> 0) */
215 #define CARRIED -1 /* Player is toting it */
217 /* hack to ignore GCC Unused Result */
218 #define IGNORE(r) do{if (r){}}while(0)