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