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 MAXPARMS 25 // Max parameters for speak()
13 #define INVLIMIT 7 // inverntory limit (# of objects)
14 #define INTRANSITIVE -1 // illegal object number
15 #define SPECIALBASE 300 // base number of special rooms
16 #define GAMELIMIT 330 // base limit of turns
17 #define NOVICELIMIT 1000 // limit of turns for novice
18 #define WARNTIME 30 // late game starts at game.limit-this
19 #define FLASHTIME 50 // turns from first warning till blinding flash
20 #define PANICTIME 15 // time left after closing
21 #define BATTERYLIFE 2500 // turn limit increment from batteries
22 #define WORD_NOT_FOUND -1 // "Word not found" flag value for the vocab hash functions.
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 SPECIAL_TRAVEL_500_GT_L_GT_300_EXCEEDS_GOTO_LIST = 20, // 20
29 VOCABULARY_TYPE_N_OVER_1000_NOT_BETWEEN_0_AND_3 = 22, // 22
30 INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST, // 23
31 TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST, // 24
32 CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION, // 25
33 LOCATION_HAS_NO_TRAVEL_ENTRIES, // 26
34 HINT_NUMBER_EXCEEDS_GOTO_LIST, // 27
35 TOO_MANY_PARAMETERS_GIVEN_TO_SETPRM, // 28
36 SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN=99, // 99
37 ACTION_RETURNED_PHASE_CODE_BEYOND_END_OF_SWITCH, // 100
40 /* Alas, declaring this static confuses the coverage analyzer */
41 void bug(enum bugtype, const char *) __attribute__((__noreturn__));
42 #define BUG(x) bug(x, #x)
45 unsigned long lcg_a, lcg_c, lcg_m, lcg_x;
46 long abbnum; // How often to print non-abbreviated descriptions
51 long clock1; // # turns from finding last treasure till closing
52 long clock2; // # turns from first warning till blinding flash
53 bool clshnt; // has player read the clue in the endgame?
54 bool closed; // whether we're all the way closed
55 bool closng; // whether it's closing time yet
56 long conds; // min value for cond(loc) if loc has any hints
61 long foobar; // current progress in saying "FEE FIE FOE FOO".
62 long holdng; // number of objects being carried
63 long iwest; // How many times he's said "west" instead of "w"
64 long knfloc; // 0 if no knife here, loc if knife , -1 after caveat
65 long limit; // lifetime of lamp (not set here)
66 bool lmwarn; // has player been warned about lamp going dim?
69 bool novice; // asked for instructions at start-up?
70 long numdie; // number of times killed so far
74 bool panic; // has player found out he's trapped in the cave?
75 long saved; // point penalty for saves
79 long trnluz; // # points lost so far due to number of turns used
80 long turns; // how many commands he's given (ignores yes/no)
81 bool wzdark; // whether the loc he's leaving was dark
82 char zzword[6]; // randomly generated magic word from bird
83 bool blooded; // has player drunk of dragon's blood?
84 long abbrev[NLOCATIONS + 1];
85 long atloc[NLOCATIONS + 1];
86 long dseen[NDWARVES + 1];
87 long dloc[NDWARVES + 1];
88 long odloc[NDWARVES + 1];
89 long fixed[NOBJECTS + 1];
90 long link[NOBJECTS * 2 + 1];
91 long place[NOBJECTS + 1];
94 long prop[NOBJECTS + 1];
97 extern struct game_t game;
100 extern bool oldstyle, editline, prompt;
102 enum speaktype {touch, look, hear, study, change};
104 /* b is not needed for POSIX but harmless */
105 #define READ_MODE "rb"
106 #define WRITE_MODE "wb"
107 extern char* xstrdup(const char* s);
108 extern void* xmalloc(size_t size);
109 extern void packed_to_token(long, char token[]);
110 extern long token_to_packed(const char token[6]);
111 extern void tokenize(char*, long tokens[4]);
112 extern void vspeak(const char*, va_list);
113 extern bool wordeq(token_t, token_t);
114 extern bool wordempty(token_t);
115 extern void wordclear(token_t *);
116 extern void speak(const char*, ...);
117 extern void pspeak(vocab_t, enum speaktype, int, ...);
118 extern void rspeak(vocab_t, ...);
119 extern bool GETIN(FILE *, token_t*, token_t*, token_t*, token_t*);
120 extern void echo_input(FILE*, char*, char*);
121 extern int word_count(char*);
122 extern char* get_input(void);
123 extern bool silent_yes(void);
124 extern bool yes(const char*, const char*, const char*);
125 extern long GETTXT(bool, bool, bool);
126 extern token_t MAKEWD(long);
127 extern long vocab(long, long);
128 extern int get_motion_vocab_id(const char*);
129 extern int get_object_vocab_id(const char*);
130 extern int get_action_vocab_id(const char*);
131 extern int get_special_vocab_id(const char*);
132 extern long get_vocab_id(const char*);
133 extern void juggle(long);
134 extern void move(long, long);
135 extern long put(long, long, long);
136 extern void carry(long, long);
137 extern void drop(long, long);
138 extern long atdwrf(long);
139 extern long setbit(long);
140 extern bool tstbit(long, int);
141 extern long rndvoc(long, long);
142 extern void make_zzword(char*);
143 extern bool MAPLIN(FILE *);
144 extern void datime(long*, long*);
146 enum termination {endgame, quitgame, scoregame};
148 extern void set_seed(long);
149 extern unsigned long get_next_lcg_value(void);
150 extern long randrange(long);
151 extern long score(enum termination);
152 extern void terminate(enum termination) __attribute__((noreturn));
153 extern int savefile(FILE *, long);
154 extern int suspend(void);
155 extern int resume(void);
156 extern int restore(FILE *);
159 * MOD(N,M) = Arithmetic modulus
160 * AT(OBJ) = true if on either side of two-placed object
161 * CNDBIT(L,N) = true if COND(L) has bit n set (bit 0 is units bit)
162 * DARK(LOC) = true if location "LOC" is dark
163 * FORCED(LOC) = true if LOC moves without asking for input (COND=2)
164 * FOREST(LOC) = true if LOC is part of the forest
165 * GSTONE(OBJ) = true if OBJ is a gemstone
166 * HERE(OBJ) = true if the OBJ is at "LOC" (or is being carried)
167 * LIQUID() = object number of liquid in bottle
168 * LIQLOC(LOC) = object number of liquid (if any) at LOC
169 * PCT(N) = true N% of the time (N integer from 0 to 100)
170 * TOTING(OBJ) = true if the OBJ is being carried */
172 #define DESTROY(N) move(N, LOC_NOWHERE)
173 #define MOD(N,M) ((N) % (M))
174 #define TOTING(OBJ) (game.place[OBJ] == CARRIED)
175 #define AT(OBJ) (game.place[OBJ] == game.loc || game.fixed[OBJ] == game.loc)
176 #define HERE(OBJ) (AT(OBJ) || TOTING(OBJ))
177 #define LIQ2(PBOTL) ((1-(PBOTL))*WATER+((PBOTL)/2)*(WATER+OIL))
178 #define LIQUID() (LIQ2(game.prop[BOTTLE]<0 ? -1-game.prop[BOTTLE] : game.prop[BOTTLE]))
179 #define LIQLOC(LOC) (LIQ2((MOD(conditions[LOC]/2*2,8)-5)*MOD(conditions[LOC]/4,2)+1))
180 #define CNDBIT(L,N) (tstbit(conditions[L],N))
181 #define FORCED(LOC) CNDBIT(LOC, COND_FORCED)
182 #define DARK(DUMMY) ((!tstbit(conditions[game.loc],COND_LIT)) && (game.prop[LAMP] == LAMP_DARK || !HERE(LAMP)))
183 #define PCT(N) (randrange(100) < (N))
184 #define GSTONE(OBJ) ((OBJ) == EMERALD || (OBJ) == RUBY || (OBJ) == AMBER || (OBJ) == SAPPH)
185 #define FOREST(LOC) CNDBIT(LOC, COND_FOREST)
186 #define SPECIAL(LOC) ((LOC) > SPECIALBASE)
187 #define OUTSID(LOC) (CNDBIT(LOC, COND_ABOVE) || FOREST(LOC))
189 #define INDEEP(LOC) ((LOC) >= LOC_MISTHALL && !OUTSID(LOC))
191 enum speechpart {unknown, intransitive, transitive};
194 enum speechpart part;
201 void initialise(void);
202 int action(struct command_t *command);
204 /* Phase codes for action returns.
205 * These were at one time FORTRAN line numbers.
206 * The values don't matter, but perturb their order at your peril.
208 #define GO_TERMINATE 2
211 #define GO_CLEAROBJ 2012
212 #define GO_CHECKHINT 2600
213 #define GO_CHECKFOO 2607
214 #define GO_DIRECTION 2620
215 #define GO_LOOKUP 2630
216 #define GO_WORD2 2800
217 #define GO_SPECIALS 1900
218 #define GO_UNKNOWN 8000
219 #define GO_ACTION 40000
220 #define GO_DWARFWAKE 19000
222 /* Special object statuses in game.place - can also be a location number (> 0) */
223 #define CARRIED -1 /* Player is toting it */
225 /* hack to ignore GCC Unused Result */
226 #define IGNORE(r) do{if (r){}}while(0)