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