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