extern.h revision 1.14 1 1.14 jsm /* $NetBSD: extern.h,v 1.14 2000/02/09 22:27:55 jsm Exp $ */
2 1.2 tls
3 1.1 tls /*
4 1.1 tls * Copyright (c) 1983, 1993
5 1.1 tls * The Regents of the University of California. All rights reserved.
6 1.1 tls *
7 1.1 tls * Redistribution and use in source and binary forms, with or without
8 1.1 tls * modification, are permitted provided that the following conditions
9 1.1 tls * are met:
10 1.1 tls * 1. Redistributions of source code must retain the above copyright
11 1.1 tls * notice, this list of conditions and the following disclaimer.
12 1.1 tls * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 tls * notice, this list of conditions and the following disclaimer in the
14 1.1 tls * documentation and/or other materials provided with the distribution.
15 1.1 tls * 3. All advertising materials mentioning features or use of this software
16 1.1 tls * must display the following acknowledgement:
17 1.1 tls * This product includes software developed by the University of
18 1.1 tls * California, Berkeley and its contributors.
19 1.1 tls * 4. Neither the name of the University nor the names of its contributors
20 1.1 tls * may be used to endorse or promote products derived from this software
21 1.1 tls * without specific prior written permission.
22 1.1 tls *
23 1.1 tls * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 tls * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 tls * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 tls * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 tls * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 tls * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 tls * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 tls * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 tls * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 tls * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 tls * SUCH DAMAGE.
34 1.1 tls *
35 1.1 tls * @(#)externs.h 8.1 (Berkeley) 5/31/93
36 1.1 tls */
37 1.1 tls
38 1.1 tls #include <stdio.h>
39 1.1 tls #include <signal.h>
40 1.2 tls #include <string.h>
41 1.1 tls #include <ctype.h>
42 1.1 tls #include <setjmp.h>
43 1.14 jsm #include <sys/types.h>
44 1.1 tls #include "machdep.h"
45 1.1 tls
46 1.1 tls /* program mode */
47 1.13 jsm extern int mode;
48 1.13 jsm extern jmp_buf restart;
49 1.1 tls #define MODE_PLAYER 1
50 1.1 tls #define MODE_DRIVER 2
51 1.1 tls #define MODE_LOGGER 3
52 1.1 tls
53 1.1 tls /* command line flags */
54 1.13 jsm extern char debug; /* -D */
55 1.13 jsm extern char randomize; /* -x, give first available ship */
56 1.13 jsm extern char longfmt; /* -l, print score in long format */
57 1.13 jsm extern char nobells; /* -b, don't ring bell before Signal */
58 1.1 tls
59 1.1 tls /* other initial modes */
60 1.14 jsm extern gid_t gid;
61 1.14 jsm extern gid_t egid;
62 1.1 tls
63 1.1 tls #define die() ((rand() >> 3) % 6 + 1)
64 1.1 tls #define sqr(a) ((a) * (a))
65 1.1 tls #define abs(a) ((a) > 0 ? (a) : -(a))
66 1.1 tls #define min(a,b) ((a) < (b) ? (a) : (b))
67 1.1 tls
68 1.1 tls #define grappled(a) ((a)->file->ngrap)
69 1.1 tls #define fouled(a) ((a)->file->nfoul)
70 1.1 tls #define snagged(a) (grappled(a) + fouled(a))
71 1.1 tls
72 1.1 tls #define grappled2(a, b) ((a)->file->grap[(b)->file->index].sn_count)
73 1.1 tls #define fouled2(a, b) ((a)->file->foul[(b)->file->index].sn_count)
74 1.1 tls #define snagged2(a, b) (grappled2(a, b) + fouled2(a, b))
75 1.1 tls
76 1.1 tls #define Xgrappled2(a, b) ((a)->file->grap[(b)->file->index].sn_turn < turn-1 ? grappled2(a, b) : 0)
77 1.1 tls #define Xfouled2(a, b) ((a)->file->foul[(b)->file->index].sn_turn < turn-1 ? fouled2(a, b) : 0)
78 1.1 tls #define Xsnagged2(a, b) (Xgrappled2(a, b) + Xfouled2(a, b))
79 1.1 tls
80 1.1 tls #define cleangrapple(a, b, c) Cleansnag(a, b, c, 1)
81 1.1 tls #define cleanfoul(a, b, c) Cleansnag(a, b, c, 2)
82 1.1 tls #define cleansnag(a, b, c) Cleansnag(a, b, c, 3)
83 1.1 tls
84 1.1 tls #define sterncolour(sp) ((sp)->file->stern+'0'-((sp)->file->captured?10:0))
85 1.1 tls #define sternrow(sp) ((sp)->file->row + dr[(sp)->file->dir])
86 1.1 tls #define sterncol(sp) ((sp)->file->col + dc[(sp)->file->dir])
87 1.1 tls
88 1.1 tls #define capship(sp) ((sp)->file->captured?(sp)->file->captured:(sp))
89 1.1 tls
90 1.1 tls #define readyname(r) ((r) & R_LOADING ? '*' : ((r) & R_INITIAL ? '!' : ' '))
91 1.1 tls
92 1.1 tls /* loadL and loadR, should match loadname[] */
93 1.1 tls #define L_EMPTY 0 /* should be 0, don't change */
94 1.1 tls #define L_GRAPE 1
95 1.1 tls #define L_CHAIN 2
96 1.1 tls #define L_ROUND 3
97 1.1 tls #define L_DOUBLE 4
98 1.1 tls #define L_EXPLODE 5
99 1.1 tls
100 1.1 tls /*
101 1.1 tls * readyL and readyR, these are bits, except R_EMPTY
102 1.1 tls */
103 1.1 tls #define R_EMPTY 0 /* not loaded and not loading */
104 1.1 tls #define R_LOADING 1 /* loading */
105 1.1 tls #define R_DOUBLE 2 /* loading double */
106 1.1 tls #define R_LOADED 4 /* loaded */
107 1.1 tls #define R_INITIAL 8 /* loaded initial */
108 1.1 tls
109 1.1 tls #define HULL 0
110 1.1 tls #define RIGGING 1
111 1.1 tls
112 1.1 tls #define W_CAPTAIN 1
113 1.1 tls #define W_CAPTURED 2
114 1.1 tls #define W_CLASS 3
115 1.1 tls #define W_CREW 4
116 1.1 tls #define W_DBP 5
117 1.1 tls #define W_DRIFT 6
118 1.1 tls #define W_EXPLODE 7
119 1.1 tls #define W_FILE 8
120 1.1 tls #define W_FOUL 9
121 1.1 tls #define W_GUNL 10
122 1.1 tls #define W_GUNR 11
123 1.1 tls #define W_HULL 12
124 1.1 tls #define W_MOVE 13
125 1.1 tls #define W_OBP 14
126 1.1 tls #define W_PCREW 15
127 1.1 tls #define W_UNFOUL 16
128 1.1 tls #define W_POINTS 17
129 1.1 tls #define W_QUAL 18
130 1.1 tls #define W_UNGRAP 19
131 1.1 tls #define W_RIGG 20
132 1.1 tls #define W_COL 21
133 1.1 tls #define W_DIR 22
134 1.1 tls #define W_ROW 23
135 1.1 tls #define W_SIGNAL 24
136 1.1 tls #define W_SINK 25
137 1.1 tls #define W_STRUCK 26
138 1.1 tls #define W_TA 27
139 1.1 tls #define W_ALIVE 28
140 1.1 tls #define W_TURN 29
141 1.1 tls #define W_WIND 30
142 1.1 tls #define W_FS 31
143 1.1 tls #define W_GRAP 32
144 1.1 tls #define W_RIG1 33
145 1.1 tls #define W_RIG2 34
146 1.1 tls #define W_RIG3 35
147 1.1 tls #define W_RIG4 36
148 1.1 tls #define W_BEGIN 37
149 1.1 tls #define W_END 38
150 1.1 tls #define W_DDEAD 39
151 1.1 tls
152 1.1 tls #define NLOG 10
153 1.1 tls struct logs {
154 1.1 tls char l_name[20];
155 1.1 tls int l_uid;
156 1.1 tls int l_shipnum;
157 1.1 tls int l_gamenum;
158 1.1 tls int l_netpoints;
159 1.1 tls };
160 1.1 tls
161 1.1 tls struct BP {
162 1.1 tls short turnsent;
163 1.1 tls struct ship *toship;
164 1.1 tls short mensent;
165 1.1 tls };
166 1.1 tls
167 1.1 tls struct snag {
168 1.1 tls short sn_count;
169 1.1 tls short sn_turn;
170 1.1 tls };
171 1.1 tls
172 1.1 tls #define NSCENE nscene
173 1.1 tls #define NSHIP 10
174 1.1 tls #define NBP 3
175 1.1 tls
176 1.1 tls #define NNATION 8
177 1.1 tls #define N_A 0
178 1.1 tls #define N_B 1
179 1.1 tls #define N_S 2
180 1.1 tls #define N_F 3
181 1.1 tls #define N_J 4
182 1.1 tls #define N_D 5
183 1.1 tls #define N_K 6
184 1.1 tls #define N_O 7
185 1.1 tls
186 1.1 tls struct File {
187 1.1 tls int index;
188 1.1 tls char captain[20]; /* 0 */
189 1.1 tls short points; /* 20 */
190 1.4 christos unsigned char loadL; /* 22 */
191 1.4 christos unsigned char loadR; /* 24 */
192 1.4 christos unsigned char readyL; /* 26 */
193 1.4 christos unsigned char readyR; /* 28 */
194 1.1 tls struct BP OBP[NBP]; /* 30 */
195 1.1 tls struct BP DBP[NBP]; /* 48 */
196 1.1 tls char struck; /* 66 */
197 1.1 tls struct ship *captured; /* 68 */
198 1.1 tls short pcrew; /* 70 */
199 1.1 tls char movebuf[10]; /* 72 */
200 1.1 tls char drift; /* 82 */
201 1.1 tls short nfoul;
202 1.1 tls short ngrap;
203 1.1 tls struct snag foul[NSHIP]; /* 84 */
204 1.1 tls struct snag grap[NSHIP]; /* 124 */
205 1.1 tls char RH; /* 224 */
206 1.1 tls char RG; /* 226 */
207 1.1 tls char RR; /* 228 */
208 1.1 tls char FS; /* 230 */
209 1.1 tls char explode; /* 232 */
210 1.1 tls char sink; /* 234 */
211 1.4 christos unsigned char dir;
212 1.1 tls short col;
213 1.1 tls short row;
214 1.1 tls char loadwith;
215 1.1 tls char stern;
216 1.1 tls };
217 1.1 tls
218 1.1 tls struct ship {
219 1.10 jsm const char *shipname; /* 0 */
220 1.1 tls struct shipspecs *specs; /* 2 */
221 1.4 christos unsigned char nationality; /* 4 */
222 1.1 tls short shiprow; /* 6 */
223 1.1 tls short shipcol; /* 8 */
224 1.1 tls char shipdir; /* 10 */
225 1.1 tls struct File *file; /* 12 */
226 1.1 tls };
227 1.1 tls
228 1.1 tls struct scenario {
229 1.1 tls char winddir; /* 0 */
230 1.1 tls char windspeed; /* 2 */
231 1.1 tls char windchange; /* 4 */
232 1.4 christos unsigned char vessels; /* 12 */
233 1.10 jsm const char *name; /* 14 */
234 1.1 tls struct ship ship[NSHIP]; /* 16 */
235 1.1 tls };
236 1.6 mrg extern struct scenario scene[];
237 1.13 jsm extern int nscene;
238 1.1 tls
239 1.1 tls struct shipspecs {
240 1.1 tls char bs;
241 1.1 tls char fs;
242 1.1 tls char ta;
243 1.1 tls short guns;
244 1.4 christos unsigned char class;
245 1.1 tls char hull;
246 1.4 christos unsigned char qual;
247 1.1 tls char crew1;
248 1.1 tls char crew2;
249 1.1 tls char crew3;
250 1.1 tls char gunL;
251 1.1 tls char gunR;
252 1.1 tls char carL;
253 1.1 tls char carR;
254 1.3 thorpej int rig1;
255 1.3 thorpej int rig2;
256 1.3 thorpej int rig3;
257 1.3 thorpej int rig4;
258 1.1 tls short pts;
259 1.1 tls };
260 1.6 mrg extern struct shipspecs specs[];
261 1.1 tls
262 1.13 jsm extern struct scenario *cc; /* the current scenario */
263 1.13 jsm extern struct ship *ls; /* &cc->ship[cc->vessels] */
264 1.1 tls
265 1.1 tls #define SHIP(s) (&cc->ship[s])
266 1.1 tls #define foreachship(sp) for ((sp) = cc->ship; (sp) < ls; (sp)++)
267 1.1 tls
268 1.1 tls struct windeffects {
269 1.1 tls char A, B, C, D;
270 1.1 tls };
271 1.13 jsm extern const struct windeffects WET[7][6];
272 1.1 tls
273 1.1 tls struct Tables {
274 1.1 tls char H, G, C, R;
275 1.1 tls };
276 1.13 jsm extern const struct Tables RigTable[11][6];
277 1.13 jsm extern const struct Tables HullTable[11][6];
278 1.1 tls
279 1.13 jsm extern const char AMMO[9][4];
280 1.13 jsm extern const char HDT[9][10];
281 1.13 jsm extern const char HDTrake[9][10];
282 1.13 jsm extern const char QUAL[9][5];
283 1.13 jsm extern const char MT[9][3];
284 1.10 jsm
285 1.10 jsm extern const char *const countryname[];
286 1.10 jsm extern const char *const classname[];
287 1.10 jsm extern const char *const directionname[];
288 1.10 jsm extern const char *const qualname[];
289 1.10 jsm extern const char loadname[];
290 1.1 tls
291 1.10 jsm extern const char rangeofshot[];
292 1.1 tls
293 1.10 jsm extern const char dr[], dc[];
294 1.1 tls
295 1.13 jsm extern int winddir;
296 1.13 jsm extern int windspeed;
297 1.13 jsm extern int turn;
298 1.13 jsm extern int game;
299 1.13 jsm extern int alive;
300 1.13 jsm extern int people;
301 1.13 jsm extern char hasdriver;
302 1.1 tls
303 1.4 christos /* assorted.c */
304 1.4 christos void table __P((int, int, int, struct ship *, struct ship *, int));
305 1.4 christos void Cleansnag __P((struct ship *, struct ship *, int, int));
306 1.4 christos
307 1.4 christos /* dr_1.c */
308 1.4 christos void unfoul __P((void));
309 1.4 christos void boardcomp __P((void));
310 1.4 christos int fightitout __P((struct ship *, struct ship *, int));
311 1.4 christos void resolve __P((void));
312 1.4 christos void compcombat __P((void));
313 1.4 christos int next __P((void));
314 1.4 christos
315 1.4 christos /* dr_2.c */
316 1.4 christos void thinkofgrapples __P((void));
317 1.4 christos void checkup __P((void));
318 1.4 christos void prizecheck __P((void));
319 1.12 jsm int str_end __P((const char *));
320 1.4 christos void closeon __P((struct ship *, struct ship *, char[], int, int, int));
321 1.4 christos int score __P((char[], struct ship *, struct ship *, int));
322 1.10 jsm void move_ship __P((const char *, struct ship *, unsigned char *, short *, short *, char *));
323 1.4 christos void try __P((char[], char [], int, int, int, int, int, struct ship *,
324 1.4 christos struct ship *, int *, int));
325 1.4 christos void rmend __P((char *));
326 1.4 christos
327 1.4 christos /* dr_3.c */
328 1.4 christos void moveall __P((void));
329 1.4 christos int stillmoving __P((int));
330 1.12 jsm int is_isolated __P((struct ship *));
331 1.4 christos int push __P((struct ship *, struct ship *));
332 1.4 christos void step __P((int, struct ship *, char *));
333 1.4 christos void sendbp __P((struct ship *, struct ship *, int, int));
334 1.12 jsm int is_toughmelee __P((struct ship *, struct ship *, int, int));
335 1.4 christos void reload __P((void));
336 1.4 christos void checksails __P((void));
337 1.4 christos
338 1.4 christos /* dr_4.c */
339 1.4 christos void ungrap __P((struct ship *, struct ship *));
340 1.4 christos void grap __P((struct ship *, struct ship *));
341 1.4 christos
342 1.4 christos /* dr_5.c */
343 1.4 christos void subtract __P((struct ship *, int, int [3], struct ship *, int));
344 1.4 christos int mensent __P((struct ship *, struct ship *, int[3], struct ship **, int *,
345 1.4 christos int));
346 1.4 christos
347 1.4 christos /* dr_main.c */
348 1.4 christos int dr_main __P((void));
349 1.4 christos
350 1.4 christos /* game.c */
351 1.4 christos int maxturns __P((struct ship *, char *));
352 1.4 christos int maxmove __P((struct ship *, int, int));
353 1.4 christos
354 1.4 christos /* lo_main.c */
355 1.4 christos int lo_main __P((void));
356 1.4 christos
357 1.4 christos /* misc.c */
358 1.4 christos int range __P((struct ship *, struct ship *));
359 1.4 christos struct ship *closestenemy __P((struct ship *, int, int));
360 1.4 christos int angle __P((int, int));
361 1.4 christos int gunsbear __P((struct ship *, struct ship *));
362 1.4 christos int portside __P((struct ship *, struct ship *, int));
363 1.4 christos int colours __P((struct ship *));
364 1.4 christos void logger __P((struct ship *));
365 1.4 christos
366 1.4 christos /* parties.c */
367 1.4 christos int meleeing __P((struct ship *, struct ship *));
368 1.4 christos int boarding __P((struct ship *, int));
369 1.4 christos void unboard __P((struct ship *, struct ship *, int));
370 1.4 christos
371 1.4 christos /* pl_1.c */
372 1.8 hubertf void leave __P((int)) __attribute__((__noreturn__));
373 1.8 hubertf void choke __P((int)) __attribute__((__noreturn__));
374 1.4 christos void child __P((int));
375 1.4 christos
376 1.4 christos /* pl_2.c */
377 1.11 jsm void play __P((void)) __attribute__((__noreturn__));
378 1.4 christos
379 1.4 christos /* pl_3.c */
380 1.4 christos void acceptcombat __P((void));
381 1.4 christos void grapungrap __P((void));
382 1.4 christos void unfoulplayer __P((void));
383 1.4 christos
384 1.4 christos /* pl_4.c */
385 1.4 christos void changesail __P((void));
386 1.4 christos void acceptsignal __P((void));
387 1.4 christos void lookout __P((void));
388 1.10 jsm const char *saywhat __P((struct ship *, int));
389 1.4 christos void eyeball __P((struct ship *));
390 1.4 christos
391 1.4 christos /* pl_5.c */
392 1.4 christos void acceptmove __P((void));
393 1.4 christos void acceptboard __P((void));
394 1.4 christos void parties __P((int[3], struct ship *, int, int));
395 1.4 christos
396 1.4 christos /* pl_6.c */
397 1.4 christos void repair __P((void));
398 1.4 christos int turned __P((void));
399 1.4 christos void loadplayer __P((void));
400 1.4 christos
401 1.4 christos /* pl_7.c */
402 1.4 christos void initscreen __P((void));
403 1.4 christos void cleanupscreen __P((void));
404 1.4 christos void newturn __P((int));
405 1.5 christos void Signal __P((const char *, struct ship *, ...))
406 1.5 christos __attribute__((__format__(__printf__,1,3)));
407 1.5 christos void Msg __P((const char *, ...))
408 1.5 christos __attribute__((__format__(__printf__,1,2)));
409 1.4 christos void Scroll __P((void));
410 1.10 jsm void prompt __P((const char *, struct ship *));
411 1.4 christos void endprompt __P((int));
412 1.10 jsm int sgetch __P((const char *, struct ship *, int));
413 1.10 jsm void sgetstr __P((const char *, char *, int));
414 1.4 christos void draw_screen __P((void));
415 1.4 christos void draw_view __P((void));
416 1.4 christos void draw_turn __P((void));
417 1.4 christos void draw_stat __P((void));
418 1.4 christos void draw_slot __P((void));
419 1.4 christos void draw_board __P((void));
420 1.4 christos void centerview __P((void));
421 1.4 christos void upview __P((void));
422 1.4 christos void downview __P((void));
423 1.4 christos void leftview __P((void));
424 1.4 christos void rightview __P((void));
425 1.4 christos void adjustview __P((void));
426 1.4 christos
427 1.4 christos /* pl_main.c */
428 1.4 christos int pl_main __P((void));
429 1.4 christos void initialize __P((void));
430 1.4 christos
431 1.4 christos /* sync.c */
432 1.4 christos void fmtship __P((char *, size_t, const char *, struct ship *));
433 1.5 christos void makesignal __P((struct ship *, const char *, struct ship *, ...))
434 1.5 christos __attribute__((__format__(__printf__,2,4)));
435 1.5 christos void makemsg __P((struct ship *, const char *, ...))
436 1.5 christos __attribute__((__format__(__printf__,2,3)));
437 1.4 christos int sync_exists __P((int));
438 1.4 christos int sync_open __P((void));
439 1.4 christos void sync_close __P((int));
440 1.9 hubertf void Write __P((int, struct ship *, long, long, long, long));
441 1.9 hubertf void Writestr __P((int, struct ship *, const char *));
442 1.4 christos int Sync __P((void));
443 1.9 hubertf int sync_update __P((int, struct ship *, const char *, long, long, long, long));
444