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