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