xref: /openbsd/games/battlestar/extern.h (revision f3c23159)
1 /*	$OpenBSD: extern.h,v 1.23 2022/08/08 17:57:05 op Exp $	*/
2 /*	$NetBSD: extern.h,v 1.5 1995/04/24 12:22:18 cgd Exp $	*/
3 
4 /*
5  * Copyright (c) 1983, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *	@(#)extern.h	8.1 (Berkeley) 5/31/93
33  */
34 
35 #include <sys/types.h>
36 
37 #define BITS (8 * sizeof (int))
38 
39 #define OUTSIDE		(position > 68 && position < 246 && position != 218)
40 #define rnd(x)		arc4random_uniform(x)
41 #define max(a,b)	((a) < (b) ? (b) : (a))
42 #define TestBit(array, index)	(array[index/BITS] & (1U << (index % BITS)))
43 #define SetBit(array, index)	(array[index/BITS] |= (1U << (index % BITS)))
44 #define ClearBit(array, index)	(array[index/BITS] &= ~(1U << (index % BITS)))
45 /*
46  * These macros yield words to use with objects (followed but not preceded
47  * by spaces, or with no spaces if the expansion is the empty string).
48  */
49 #define A_OR_AN(n)		(objflags[(n)] & OBJ_AN ? "an " : "a ")
50 #define IS_PLURAL(n)	(objflags[(n)] & OBJ_PLURAL)
51 #define A_OR_AN_OR_THE(n)	(IS_PLURAL((n)) ? "the " : A_OR_AN((n)))
52 #define A_OR_AN_OR_BLANK(n)	(IS_PLURAL((n)) ? "" : A_OR_AN((n)))
53 #define IS_OR_ARE(n)		(IS_PLURAL((n)) ? "are " : "is ")
54 
55  /* well known rooms */
56 #define FINAL	275
57 #define GARDEN	197
58 #define POOLS	126
59 #define DOCK	93
60 
61  /* word types */
62 #define VERB	0
63 #define OBJECT  1
64 #define NOUNS	2
65 #define PREPS	3
66 #define ADJS	4
67 #define CONJ	5
68 
69  /* words numbers */
70 #define KNIFE		0
71 #define SWORD		1
72 #define LAND		2
73 #define WOODSMAN 	3
74 #define TWO_HANDED	4
75 #define CLEAVER		5
76 #define BROAD		6
77 #define MAIL		7
78 #define HELM		8
79 #define SHIELD		9
80 #define MAID		10
81 #define BODY		10
82 #define VIPER		11
83 #define LAMPON		12
84 #define SHOES		13
85 #define CYLON		14
86 #define PAJAMAS		15
87 #define ROBE		16
88 #define AMULET		17
89 #define MEDALION	18
90 #define TALISMAN	19
91 #define DEADWOOD	20
92 #define MALLET		21
93 #define LASER		22
94 #define BATHGOD		23
95 #define NORMGOD		24
96 #define GRENADE		25
97 #define CHAIN		26
98 #define ROPE		27
99 #define LEVIS		28
100 #define MACE		29
101 #define SHOVEL		30
102 #define HALBERD		31
103 #define COMPASS		32
104 #define CRASH		33
105 #define ELF		34
106 #define FOOT		35
107 #define COINS		36
108 #define MATCHES		37
109 #define MAN		38
110 #define PAPAYAS		39
111 #define PINEAPPLE	40
112 #define KIWI		41
113 #define COCONUTS	42
114 #define MANGO		43
115 #define RING		44
116 #define POTION		45
117 #define BRACELET	46
118 #define GIRL		47
119 #define GIRLTALK	48
120 #define DARK		49
121 #define TIMER		50
122 #define CHAR		53
123 #define BOMB		54
124 #define DEADGOD		55
125 #define DEADTIME	56
126 #define DEADNATIVE	57
127 #define NATIVE		58
128 #define HORSE		59
129 #define CAR		60
130 #define POT		61
131 #define BAR		62
132 #define BLOCK		63
133 #define NUMOFOBJECTS	64
134  /* non-objects below */
135 #define UP	1000
136 #define DOWN	1001
137 #define AHEAD	1002
138 #define BACK	1003
139 #define RIGHT	1004
140 #define LEFT	1005
141 #define TAKE	1006
142 #define USE	1007
143 #define LOOK	1008
144 #define QUIT	1009
145 #define NORTH	1010
146 #define SOUTH	1011
147 #define EAST	1012
148 #define WEST	1013
149 #define SU	1014
150 #define DROP	1015
151 #define TAKEOFF	1016
152 #define DRAW	1017
153 #define PUTON	1018
154 #define WEARIT	1019
155 #define PUT	1020
156 #define INVEN	1021
157 #define EVERYTHING 1022
158 #define AND	1023
159 #define KILL	1024
160 #define RAVAGE	1025
161 #define UNDRESS	1026
162 #define THROW	1027
163 #define LAUNCH	1028
164 #define LANDIT	1029
165 #define LIGHT	1030
166 #define FOLLOW	1031
167 #define KISS	1032
168 #define LOVE	1033
169 #define GIVE	1034
170 #define SMITE	1035
171 #define SHOOT	1036
172 #define ON	1037
173 #define OFF	1038
174 #define TIME	1039
175 #define SLEEP	1040
176 #define DIG	1041
177 #define EAT	1042
178 #define SWIM	1043
179 #define DRINK	1044
180 #define DOOR	1045
181 #define SAVE	1046
182 #define RIDE	1047
183 #define DRIVE	1048
184 #define SCORE	1049
185 #define BURY	1050
186 #define JUMP	1051
187 #define KICK	1052
188 #define OPEN	1053
189 #define VERBOSE	1054
190 #define BRIEF	1055
191 #define AUXVERB 1056
192 
193  /* injuries */
194 #define ARM	6		/* broken arm */
195 #define RIBS	7		/* broken ribs */
196 #define SPINE	9		/* broken back */
197 #define SKULL	11		/* fractured skull */
198 #define INCISE	10		/* deep incisions */
199 #define NECK	12		/* broken NECK */
200 #define NUMOFINJURIES 13
201 
202  /* notes */
203 #define CANTLAUNCH	0
204 #define LAUNCHED	1
205 #define CANTSEE		2
206 #define CANTMOVE	3
207 #define JINXED		4
208 #define DUG		5
209 #define NUMOFNOTES	6
210 
211  /* number of times room description shown */
212 #define ROOMDESC	3
213 
214  /* fundamental constants */
215 #define NUMOFROOMS	275
216 #define NUMOFWORDS	((NUMOFOBJECTS + BITS - 1) / BITS)
217 #define LINELENGTH	81
218 
219 #define TODAY		0
220 #define TONIGHT		1
221 #define CYCLE		100
222 
223  /* initial variable values */
224 #define TANKFULL	250
225 #define TORPEDOES	10
226 #define MAXWEIGHT	60
227 #define MAXCUMBER	10
228 
229 /* Flags for objects */
230 #define OBJ_PLURAL	1
231 #define OBJ_AN		2
232 #define OBJ_PERSON	4
233 #define OBJ_NONOBJ	8	/* footsteps, asteroids, etc. */
234 
235 struct room {
236 	const char   *name;
237 	int     link[8];
238 #define north	link[0]
239 #define south	link[1]
240 #define east	link[2]
241 #define west	link[3]
242 #define up	link[4]
243 #define access	link[5]
244 #define down	link[6]
245 #define flyhere	link[7]
246 	const char   *desc;
247 	unsigned int objects[NUMOFWORDS];
248 };
249 extern struct room dayfile[];
250 extern struct room nightfile[];
251 extern struct room *location;
252 
253  /* object characteristics */
254 extern const char   *const objdes[NUMOFOBJECTS];
255 extern const char   *const objsht[NUMOFOBJECTS];
256 extern const char   *const ouch[NUMOFINJURIES];
257 extern const int     objwt[NUMOFOBJECTS];
258 extern const int     objcumber[NUMOFOBJECTS];
259 extern const int     objflags[NUMOFOBJECTS];
260 
261  /* current input line */
262 #define WORDLEN 15
263 #define NWORD	20		/* words per line */
264 extern char    words[NWORD][WORDLEN];
265 extern int     wordvalue[NWORD];
266 extern int     wordtype[NWORD];
267 extern int     wordcount, wordnumber;
268 extern int     stop_cypher;	/* continue parsing the current line? */
269 
270  /* state of the game */
271 extern int     ourtime;
272 extern int     position;
273 extern int     direction;
274 extern int     left, right, ahead, back;
275 extern int     ourclock, fuel, torps;
276 extern int     carrying, encumber;
277 extern int     rythmn;
278 extern int     followfight;
279 extern int     ate;
280 extern int     snooze;
281 extern int     meetgirl;
282 extern int     followgod;
283 extern int     godready;
284 extern int     win;
285 extern int     wintime;
286 extern int     tempwiz;
287 extern int     matchlight;
288 extern int     matchcount;
289 extern int     loved;
290 extern int     pleasure, power, ego;
291 extern int     WEIGHT;
292 extern int     CUMBER;
293 extern int     notes[NUMOFNOTES];
294 extern unsigned int inven[NUMOFWORDS];
295 extern unsigned int wear[NUMOFWORDS];
296 extern char    beenthere[NUMOFROOMS+1];
297 extern char    injuries[NUMOFINJURIES];
298 extern int     verbose;
299 
300 extern const char *username;
301 
302 struct wlist {
303 	const char   *string;
304 	int     value, article;
305 	struct wlist *next;
306 };
307 extern struct wlist wlist[];
308 
309 struct objs {
310 	short room;
311 	short obj;
312 };
313 extern const struct objs dayobjs[];
314 extern const struct objs nightobjs[];
315 
316 void bury(void);
317 int card(const char *, int);
318 void chime(void);
319 void convert(int);
320 void crash(void);
321 int cypher(void);
322 __dead void die(int);
323 void dig(void);
324 void dooropen(void);
325 int draw(void);
326 void drink(void);
327 int drive(void);
328 int drop(const char *);
329 int eat(void);
330 int fight(int, int);
331 int follow(void);
332 char *getcom(char *, int, const char *, const char *);
333 char *getword(char *, char *, int);
334 int give(void);
335 int inc_wordnumber(const char *, const char *);
336 void initialize(const char *);
337 int jump(void);
338 void kiss(void);
339 int land(void);
340 int launch(void);
341 void light(void);
342 __dead void live(void);
343 void love(void);
344 int moveplayer(int, int);
345 void murder(void);
346 void newlocation(void);
347 void news(void);
348 void newway(int);
349 void open_score_file(void);
350 void parse(void);
351 void post(char);
352 void printobjs(void);
353 int put(void);
354 int puton(void);
355 const char *rate(void);
356 void ravage(void);
357 void restore(const char *);
358 int ride(void);
359 void save(const char *);
360 char *save_file_name(const char *);
361 int shoot(void);
362 int take(unsigned int[]);
363 int takeoff(void);
364 int throw(const char *);
365 const char *truedirec(int, char);
366 int ucard(const unsigned int *);
367 void undress(void);
368 int use(void);
369 int visual(void);
370 int wearit(void);
371 void whichway(struct room);
372 void wordinit(void);
373 void writedes(void);
374 int zzz(void);
375