9 #define PIRATE NDWARVES /* must be NDWARVES-1 when zero-origin */
10 #define DALTLC LOC_NUGGET /* alternate dwarf location */
15 #define INTRANSITIVE -1 /* illegal object number */
16 #define SPECIALBASE 300 /* base number of special rooms */
17 #define WARNTIME 30 /* late game starts at game.limit-this */
18 #define PANICTIME 15 /* time left after closing */
20 typedef long token_t; /* word token - someday this will be char[TOKLEN+1] */
21 typedef long vocab_t; /* index into a vocabulary array */
24 unsigned long lcg_a, lcg_c, lcg_m, lcg_x;
62 long abbrev[LOCSIZ+1];
64 long dseen[NDWARVES+1];
65 long dloc[NDWARVES+1];
66 long odloc[NDWARVES+1];
67 long fixed[NOBJECTS+1];
68 long link[NOBJECTS*2 + 1];
69 long place[NOBJECTS+1];
70 long hinted[HNTSIZ+1];
71 long hintlc[HNTSIZ+1];
72 long prop[NOBJECTS+1];
75 extern struct game_t game;
77 extern long LNLENG, LNPOSN, PARMS[];
78 extern char rawbuf[LINESIZE], INLINE[LINESIZE+1];
79 extern const char ascii_to_advent[];
80 extern const char advent_to_ascii[];
82 extern bool oldstyle, editline, prompt;
84 /* b is not needed for POSIX but harmless */
85 #define READ_MODE "rb"
86 #define WRITE_MODE "wb"
87 extern void* xmalloc(size_t size);
88 extern char* xstrdup(const char*);
89 extern void packed_to_token(long, char token[]);
90 extern void speak(const char*);
91 extern void PSPEAK(vocab_t,int);
92 extern void RSPEAK(vocab_t);
93 extern void SETPRM(long,long,long);
94 extern bool GETIN(FILE *,token_t*,token_t*,token_t*,token_t*);
95 extern void echo_input(FILE*, char*, char*);
96 extern char* get_input(void);
97 extern bool YES(const char*, const char*, const char*);
98 extern long GETTXT(bool,bool,bool);
99 extern token_t MAKEWD(long);
100 extern long VOCAB(long,long);
101 extern void JUGGLE(long);
102 extern void MOVE(long,long);
103 extern long PUT(long,long,long);
104 extern void CARRY(long,long);
105 extern void DROP(long,long);
106 extern long ATDWRF(long);
107 extern long SETBIT(long);
108 extern bool TSTBIT(long,int);
109 extern long RNDVOC(long,long);
110 extern bool MAPLIN(FILE *);
111 extern void DATIME(long*, long*);
113 enum termination {endgame, quitgame, scoregame};
115 extern void set_seed(long);
116 extern unsigned long get_next_lcg_value(void);
117 extern long randrange(long);
118 extern long score(enum termination);
119 extern void terminate(enum termination) __attribute__((noreturn));
120 extern int suspend(void);
121 extern int resume(void);
122 extern int restore(FILE *);
125 * MOD(N,M) = Arithmetic modulus
126 * AT(OBJ) = true if on either side of two-placed object
127 * CNDBIT(L,N) = true if COND(L) has bit n set (bit 0 is units bit)
128 * DARK(LOC) = true if location "LOC" is dark
129 * FORCED(LOC) = true if LOC moves without asking for input (COND=2)
130 * FOREST(LOC) = true if LOC is part of the forest
131 * GSTONE(OBJ) = true if OBJ is a gemstone
132 * HERE(OBJ) = true if the OBJ is at "LOC" (or is being carried)
133 * LIQUID() = object number of liquid in bottle
134 * LIQLOC(LOC) = object number of liquid (if any) at LOC
135 * PCT(N) = true N% of the time (N integer from 0 to 100)
136 * TOTING(OBJ) = true if the OBJ is being carried */
138 #define DESTROY(N) MOVE(N, NOWHERE)
139 #define MOD(N,M) ((N) % (M))
140 #define TOTING(OBJ) (game.place[OBJ] == CARRIED)
141 #define AT(OBJ) (game.place[OBJ] == game.loc || game.fixed[OBJ] == game.loc)
142 #define HERE(OBJ) (AT(OBJ) || TOTING(OBJ))
143 #define LIQ2(PBOTL) ((1-(PBOTL))*WATER+((PBOTL)/2)*(WATER+OIL))
144 #define LIQUID() (LIQ2(game.prop[BOTTLE]<0 ? -1-game.prop[BOTTLE] : game.prop[BOTTLE]))
145 #define LIQLOC(LOC) (LIQ2((MOD(COND[LOC]/2*2,8)-5)*MOD(COND[LOC]/4,2)+1))
146 #define CNDBIT(L,N) (TSTBIT(COND[L],N))
147 #define FORCED(LOC) (COND[LOC] == 2)
148 #define DARK(DUMMY) ((!CNDBIT(game.loc,LIGHT)) && (game.prop[LAMP] == 0 || !HERE(LAMP)))
149 #define PCT(N) (randrange(100) < (N))
150 #define GSTONE(OBJ) ((OBJ) == EMERALD || (OBJ) == RUBY || (OBJ) == AMBER || (OBJ) == SAPPH)
151 #define FOREST(LOC) ((LOC) >= LOC_FOREST1 && (LOC) <= LOC_FOREST22)
152 #define VOCWRD(LETTRS,SECT) (VOCAB(MAKEWD(LETTRS),SECT))
153 #define SPECIAL(LOC) ((LOC) > SPECIALBASE)
155 /* The following two functions were added to fix a bug (game.clock1 decremented
156 * while in forest). They should probably be replaced by using another
157 * "cond" bit. For now, however, a quick fix... OUTSID(LOC) is true if
158 * LOC is outside, INDEEP(LOC) is true if LOC is "deep" in the cave (hall
159 * of mists or deeper). Note special kludges for "Foof!" locs. */
161 #define OUTSID(LOC) ((LOC) <= LOC_GRATE || FOREST(LOC) || (LOC) == PLAC[SAPPH] || (LOC) == LOC_FOOF2 || (LOC) == LOC_FOOF4)
162 #define INDEEP(LOC) ((LOC) >= LOC_MISTHALL && !OUTSID(LOC) && (LOC) != LOC_FOOF1)
164 /* vocabulary items */
165 extern long AMBER, ATTACK, AXE, BACK, BATTERY, BEAR,
166 BIRD, BLOOD, BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST,
167 CLAM, COINS, DOOR, DPRSSN, DRAGON, DWARF, EGGS,
168 EMERALD, ENTER, ENTRNC, FIND, FISSURE, FOOD, GRATE, HINT, INVENT,
169 JADE, KEYS, KNIFE, LAMP, LOCK, LOOK, MAGAZINE, MESSAG, MIRROR, NUGGET, NUL,
170 OGRE, OIL, OYSTER, PANIC, PEARL, PILLOW, PLANT, PLANT2, PYRAMID,
171 RESER, ROD, ROD2, RUBY, RUG, SAPPH, SAY, SIGN, SNAKE,
172 STEPS, STICK, STREAM, THROW, TRIDENT, TROLL, TROLL2,
173 URN, VASE, VEND, VOLCANO, WATER;
175 enum speechpart {unknown, intransitive, transitive};
177 void initialise(void);
178 int action(FILE *input, enum speechpart part, long verb, token_t obj);
180 /* Phase codes for action returns.
181 * These were at one time FORTRAN line numbers.
182 * The values don't matter, but perturb their order at your peril.
184 #define GO_TERMINATE 2
187 #define GO_CLEAROBJ 2012
188 #define GO_CHECKHINT 2600
189 #define GO_CHECKFOO 2607
190 #define GO_CLOSEJUMP 2610
191 #define GO_DIRECTION 2620
192 #define GO_LOOKUP 2630
193 #define GO_WORD2 2800
194 #define GO_SPECIALS 1900
195 #define GO_UNKNOWN 8000
196 #define GO_ACTION 40000
197 #define GO_DWARFWAKE 19000
199 /* Symbols for cond bits */
200 #define LIGHT 0 /* Light */
201 #define OILY 1 /* If bit 2 is on: on for oil, off for water */
202 #define FLUID 2 /* Liquid asset, see bit 1 */
203 #define NOARRR 3 /* Pirate doesn't go here unless following player */
204 #define NOBACK 4 /* Cannot use "back" to move away */
205 /* Bits past 10 indicate areas of interest to "hint" routines */
206 #define HBASE 10 /* Base for location hint bitss */
207 #define HCAVE 11 /* Trying to get into cave */
208 #define HBIRD 12 /* Trying to catch bird */
209 #define HSNAKE 13 /* Trying to deal with snake */
210 #define HMAZE 14 /* Lost in maze */
211 #define HDARK 15 /* Pondering dark room */
212 #define HWITT 16 /* At Witt's End */
213 #define HCLIFF 17 /* Cliff with urn */
214 #define HWOODS 18 /* Lost in forest */
215 #define HOGRE 19 /* Trying to deal with ogre */
216 #define HJADE 20 /* Found all treasures except jade */
218 /* Special object statuses in game.place - can also be a location number (> 0) */
219 #define CARRIED -1 /* Player is toting it */
220 #define NOWHERE 0 /* It's destroyed */
222 /* hack to ignore GCC Unused Result */
223 #define IGNORE(r) do{if (r){}}while(0)