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
235struct 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};
249extern struct room dayfile[];
250extern struct room nightfile[];
251extern struct room *location;
252
253 /* object characteristics */
254extern const char   *const objdes[NUMOFOBJECTS];
255extern const char   *const objsht[NUMOFOBJECTS];
256extern const char   *const ouch[NUMOFINJURIES];
257extern const int     objwt[NUMOFOBJECTS];
258extern const int     objcumber[NUMOFOBJECTS];
259extern const int     objflags[NUMOFOBJECTS];
260
261 /* current input line */
262#define WORDLEN 15
263#define NWORD	20		/* words per line */
264extern char    words[NWORD][WORDLEN];
265extern int     wordvalue[NWORD];
266extern int     wordtype[NWORD];
267extern int     wordcount, wordnumber;
268extern int     stop_cypher;	/* continue parsing the current line? */
269
270 /* state of the game */
271extern int     ourtime;
272extern int     position;
273extern int     direction;
274extern int     left, right, ahead, back;
275extern int     ourclock, fuel, torps;
276extern int     carrying, encumber;
277extern int     rythmn;
278extern int     followfight;
279extern int     ate;
280extern int     snooze;
281extern int     meetgirl;
282extern int     followgod;
283extern int     godready;
284extern int     win;
285extern int     wintime;
286extern int     tempwiz;
287extern int     matchlight;
288extern int     matchcount;
289extern int     loved;
290extern int     pleasure, power, ego;
291extern int     WEIGHT;
292extern int     CUMBER;
293extern int     notes[NUMOFNOTES];
294extern unsigned int inven[NUMOFWORDS];
295extern unsigned int wear[NUMOFWORDS];
296extern char    beenthere[NUMOFROOMS+1];
297extern char    injuries[NUMOFINJURIES];
298extern int     verbose;
299
300extern const char *username;
301
302struct wlist {
303	const char   *string;
304	int     value, article;
305	struct wlist *next;
306};
307extern struct wlist wlist[];
308
309struct objs {
310	short room;
311	short obj;
312};
313extern const struct objs dayobjs[];
314extern const struct objs nightobjs[];
315
316void bury(void);
317int card(const char *, int);
318void chime(void);
319void convert(int);
320void crash(void);
321int cypher(void);
322__dead void die(int);
323void dig(void);
324void dooropen(void);
325int draw(void);
326void drink(void);
327int drive(void);
328int drop(const char *);
329int eat(void);
330int fight(int, int);
331int follow(void);
332char *getcom(char *, int, const char *, const char *);
333char *getword(char *, char *, int);
334int give(void);
335int inc_wordnumber(const char *, const char *);
336void initialize(const char *);
337int jump(void);
338void kiss(void);
339int land(void);
340int launch(void);
341void light(void);
342__dead void live(void);
343void love(void);
344int moveplayer(int, int);
345void murder(void);
346void newlocation(void);
347void news(void);
348void newway(int);
349void open_score_file(void);
350void parse(void);
351void post(char);
352void printobjs(void);
353int put(void);
354int puton(void);
355const char *rate(void);
356void ravage(void);
357void restore(const char *);
358int ride(void);
359void save(const char *);
360char *save_file_name(const char *);
361int shoot(void);
362int take(unsigned int[]);
363int takeoff(void);
364int throw(const char *);
365const char *truedirec(int, char);
366int ucard(const unsigned int *);
367void undress(void);
368int use(void);
369int visual(void);
370int wearit(void);
371void whichway(struct room);
372void wordinit(void);
373void writedes(void);
374int zzz(void);
375