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 newspeak(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 void score(enum termination);
118 extern int suspend(FILE *);
119 extern int resume(FILE *);
120 extern int restore(FILE *);
123 * MOD(N,M) = Arithmetic modulus
124 * AT(OBJ) = true if on either side of two-placed object
125 * CNDBIT(L,N) = true if COND(L) has bit n set (bit 0 is units bit)
126 * DARK(LOC) = true if location "LOC" is dark
127 * FORCED(LOC) = true if LOC moves without asking for input (COND=2)
128 * FOREST(LOC) = true if LOC is part of the forest
129 * GSTONE(OBJ) = true if OBJ is a gemstone
130 * HERE(OBJ) = true if the OBJ is at "LOC" (or is being carried)
131 * LIQUID() = object number of liquid in bottle
132 * LIQLOC(LOC) = object number of liquid (if any) at LOC
133 * PCT(N) = true N% of the time (N integer from 0 to 100)
134 * TOTING(OBJ) = true if the OBJ is being carried */
136 #define DESTROY(N) MOVE(N, NOWHERE)
137 #define MOD(N,M) ((N) % (M))
138 #define TOTING(OBJ) (game.place[OBJ] == CARRIED)
139 #define AT(OBJ) (game.place[OBJ] == game.loc || game.fixed[OBJ] == game.loc)
140 #define HERE(OBJ) (AT(OBJ) || TOTING(OBJ))
141 #define LIQ2(PBOTL) ((1-(PBOTL))*WATER+((PBOTL)/2)*(WATER+OIL))
142 #define LIQUID() (LIQ2(game.prop[BOTTLE]<0 ? -1-game.prop[BOTTLE] : game.prop[BOTTLE]))
143 #define LIQLOC(LOC) (LIQ2((MOD(COND[LOC]/2*2,8)-5)*MOD(COND[LOC]/4,2)+1))
144 #define CNDBIT(L,N) (TSTBIT(COND[L],N))
145 #define FORCED(LOC) (COND[LOC] == 2)
146 #define DARK(DUMMY) ((!CNDBIT(game.loc,LIGHT)) && (game.prop[LAMP] == 0 || !HERE(LAMP)))
147 #define PCT(N) (randrange(100) < (N))
148 #define GSTONE(OBJ) ((OBJ) == EMRALD || (OBJ) == RUBY || (OBJ) == AMBER || (OBJ) == SAPPH)
149 #define FOREST(LOC) ((LOC) >= LOC_FOREST1 && (LOC) <= LOC_FOREST22)
150 #define VOCWRD(LETTRS,SECT) (VOCAB(MAKEWD(LETTRS),SECT))
151 #define SPECIAL(LOC) ((LOC) > SPECIALBASE)
153 /* The following two functions were added to fix a bug (game.clock1 decremented
154 * while in forest). They should probably be replaced by using another
155 * "cond" bit. For now, however, a quick fix... OUTSID(LOC) is true if
156 * LOC is outside, INDEEP(LOC) is true if LOC is "deep" in the cave (hall
157 * of mists or deeper). Note special kludges for "Foof!" locs. */
159 #define OUTSID(LOC) ((LOC) <= LOC_GRATE || FOREST(LOC) || (LOC) == PLAC[SAPPH] || (LOC) == LOC_FOOF2 || (LOC) == LOC_FOOF4)
160 #define INDEEP(LOC) ((LOC) >= LOC_MISTHALL && !OUTSID(LOC) && (LOC) != LOC_FOOF1)
162 /* vocabulary items */
163 extern long AMBER, ATTACK, AXE, BACK, BATTER, BEAR,
164 BIRD, BLOOD, BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST,
165 CLAM, COINS, DOOR, DPRSSN, DRAGON, DWARF, EGGS,
166 EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOD, GRATE, HINT, INVENT,
167 JADE, KEYS, KNIFE, LAMP, LOCK, LOOK, MAGZIN, MESSAG, MIRROR, NUGGET, NUL,
168 OGRE, OIL, OYSTER, PANIC, PEARL, PILLOW, PLANT, PLANT2, PYRAM,
169 RESER, ROD, ROD2, RUBY, RUG, SAPPH, SAY, SIGN, SNAKE,
170 STEPS, STICK, STREAM, THROW, TRIDNT, TROLL, TROLL2,
171 URN, VASE, VEND, VOLCAN, WATER;
173 enum speechpart {unknown, intransitive, transitive};
175 void initialise(void);
176 int action(FILE *input, enum speechpart part, long verb, token_t obj);
178 /* Phase codes for action returns.
179 * These were at one time FORTRAN line numbers.
180 * The values don't matter, but perturb their order at your peril.
182 #define GO_TERMINATE 2
185 #define GO_CLEAROBJ 2012
186 #define GO_CHECKHINT 2600
187 #define GO_CHECKFOO 2607
188 #define GO_CLOSEJUMP 2610
189 #define GO_DIRECTION 2620
190 #define GO_LOOKUP 2630
191 #define GO_WORD2 2800
192 #define GO_SPECIALS 1900
193 #define GO_UNKNOWN 8000
194 #define GO_ACTION 40000
195 #define GO_DWARFWAKE 19000
197 /* Symbols for cond bits */
198 #define LIGHT 0 /* Light */
199 #define OILY 1 /* If bit 2 is on: on for oil, off for water */
200 #define FLUID 2 /* Liquid asset, see bit 1 */
201 #define NOARRR 3 /* Pirate doesn't go here unless following player */
202 #define NOBACK 4 /* Cannot use "back" to move away */
203 /* Bits past 10 indicate areas of interest to "hint" routines */
204 #define HBASE 10 /* Base for location hint bitss */
205 #define HCAVE 11 /* Trying to get into cave */
206 #define HBIRD 12 /* Trying to catch bird */
207 #define HSNAKE 13 /* Trying to deal with snake */
208 #define HMAZE 14 /* Lost in maze */
209 #define HDARK 15 /* Pondering dark room */
210 #define HWITT 16 /* At Witt's End */
211 #define HCLIFF 17 /* Cliff with urn */
212 #define HWOODS 18 /* Lost in forest */
213 #define HOGRE 19 /* Trying to deal with ogre */
214 #define HJADE 20 /* Found all treasures except jade */
216 /* Special object statuses in game.place - can also be a location number (> 0) */
217 #define CARRIED -1 /* Player is toting it */
218 #define NOWHERE 0 /* It's destroyed */
220 /* hack to ignore GCC Unused Result */
221 #define IGNORE(r) do{if (r){}}while(0)