Remove more disused macros.
[open-adventure.git] / advent.h
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdbool.h>
4 #include <stdarg.h>
5
6 #include "dungeon.h"
7
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
22 typedef long token_t;  // word token - someday this will be char[TOKLEN+1]
23 typedef long vocab_t;  // index into a vocabulary array */
24
25 enum bugtype {
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
36 };
37
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)
41
42 struct game_t {
43     unsigned long lcg_a, lcg_c, lcg_m, lcg_x;
44     long abbnum;                 // How often to print non-abbreviated descriptions
45     long blklin;
46     long bonus;
47     long chloc;
48     long chloc2;
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
55     long detail;
56     long dflag;
57     long dkill;
58     long dtotal;
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?
65     long loc;
66     long newloc;
67     bool novice;                 // asked for instructions at start-up?
68     long numdie;                 // number of times killed so far
69     long oldloc;
70     long oldlc2;
71     long oldobj;
72     bool panic;                  // has player found out he's trapped in the cave?
73     long saved;                  // point penalty for saves
74     long tally;
75     long thresh;
76     long trndex;
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];
90     long hinted[NHINTS];
91     long hintlc[NHINTS];
92     long prop[NOBJECTS + 1];
93 };
94
95 extern struct game_t game;
96
97 extern FILE *logfp;
98 extern bool oldstyle, editline, prompt;
99
100 enum speaktype {touch, look, hear, study, change};
101
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 bool GETIN(FILE *, token_t*, token_t*, token_t*, token_t*);
118 extern void echo_input(FILE*, char*, char*);
119 extern int word_count(char*);
120 extern char* get_input(void);
121 extern bool silent_yes(void);
122 extern bool yes(const char*, const char*, const char*);
123 extern long GETTXT(bool, bool, bool);
124 extern token_t MAKEWD(long);
125 extern long vocab(long, long);
126 extern int get_motion_vocab_id(const char*);
127 extern int get_object_vocab_id(const char*);
128 extern int get_action_vocab_id(const char*);
129 extern int get_special_vocab_id(const char*);
130 extern long get_vocab_id(const char*);
131 extern void juggle(long);
132 extern void move(long, long);
133 extern long put(long, long, long);
134 extern void carry(long, long);
135 extern void drop(long, long);
136 extern long atdwrf(long);
137 extern long setbit(long);
138 extern bool tstbit(long, int);
139 extern long rndvoc(long, long);
140 extern void make_zzword(char*);
141 extern bool MAPLIN(FILE *);
142 extern void datime(long*, long*);
143
144 enum termination {endgame, quitgame, scoregame};
145
146 extern void set_seed(long);
147 extern unsigned long get_next_lcg_value(void);
148 extern long randrange(long);
149 extern long score(enum termination);
150 extern void terminate(enum termination) __attribute__((noreturn));
151 extern int savefile(FILE *, long);
152 extern int suspend(void);
153 extern int resume(void);
154 extern int restore(FILE *);
155
156 /*
157  *  MOD(N,M)    = Arithmetic modulus
158  *  AT(OBJ)     = true if on either side of two-placed object
159  *  CNDBIT(L,N) = true if COND(L) has bit n set (bit 0 is units bit)
160  *  DARK(LOC)   = true if location "LOC" is dark
161  *  FORCED(LOC) = true if LOC moves without asking for input (COND=2)
162  *  FOREST(LOC) = true if LOC is part of the forest
163  *  GSTONE(OBJ) = true if OBJ is a gemstone
164  *  HERE(OBJ)   = true if the OBJ is at "LOC" (or is being carried)
165  *  LIQUID()    = object number of liquid in bottle
166  *  LIQLOC(LOC) = object number of liquid (if any) at LOC
167  *  PCT(N)      = true N% of the time (N integer from 0 to 100)
168  *  TOTING(OBJ) = true if the OBJ is being carried */
169
170 #define DESTROY(N)   move(N, LOC_NOWHERE)
171 #define MOD(N,M)     ((N) % (M))
172 #define TOTING(OBJ)  (game.place[OBJ] == CARRIED)
173 #define AT(OBJ)      (game.place[OBJ] == game.loc || game.fixed[OBJ] == game.loc)
174 #define HERE(OBJ)    (AT(OBJ) || TOTING(OBJ))
175 #define LIQ2(PBOTL)  ((1-(PBOTL))*WATER+((PBOTL)/2)*(WATER+OIL))
176 #define LIQUID()     (LIQ2(game.prop[BOTTLE]<0 ? -1-game.prop[BOTTLE] : game.prop[BOTTLE]))
177 #define LIQLOC(LOC)  (LIQ2((MOD(conditions[LOC]/2*2,8)-5)*MOD(conditions[LOC]/4,2)+1))
178 #define CNDBIT(L,N)  (tstbit(conditions[L],N))
179 #define FORCED(LOC)  CNDBIT(LOC, COND_FORCED)
180 #define DARK(DUMMY)  ((!tstbit(conditions[game.loc],COND_LIT)) && (game.prop[LAMP] == LAMP_DARK || !HERE(LAMP)))
181 #define PCT(N)       (randrange(100) < (N))
182 #define GSTONE(OBJ)  ((OBJ) == EMERALD || (OBJ) == RUBY || (OBJ) == AMBER || (OBJ) == SAPPH)
183 #define FOREST(LOC)  CNDBIT(LOC, COND_FOREST)
184 #define SPECIAL(LOC) ((LOC) > SPECIALBASE)
185 #define OUTSID(LOC)  (CNDBIT(LOC, COND_ABOVE) || FOREST(LOC))
186
187 #define INDEEP(LOC)  ((LOC) >= LOC_MISTHALL && !OUTSID(LOC))
188
189 enum speechpart {unknown, intransitive, transitive};
190
191 struct command_t {
192     enum speechpart part;
193     vocab_t verb;
194     vocab_t obj;
195     token_t wd1, wd1x;
196     token_t wd2, wd2x;
197 };
198
199 void initialise(void);
200 int action(struct command_t *command);
201
202 /* Phase codes for action returns.
203  * These were at one time FORTRAN line numbers.
204  * The values don't matter, but perturb their order at your peril.
205  */
206 #define GO_TERMINATE 2
207 #define GO_MOVE      8
208 #define GO_TOP       2000
209 #define GO_CLEAROBJ  2012
210 #define GO_CHECKHINT 2600
211 #define GO_CHECKFOO  2607
212 #define GO_DIRECTION 2620
213 #define GO_LOOKUP    2630
214 #define GO_WORD2     2800
215 #define GO_SPECIALS  1900
216 #define GO_UNKNOWN   8000
217 #define GO_ACTION    40000
218 #define GO_DWARFWAKE 19000
219
220 /* Special object statuses in game.place - can also be a location number (> 0) */
221 #define CARRIED                -1        /* Player is toting it */
222
223 /* hack to ignore GCC Unused Result */
224 #define IGNORE(r) do{if (r){}}while(0)
225
226 /* end */