1/*	$NetBSD: extern.h,v 1.37 2011/08/26 06:18:18 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 <sys/types.h>
35#include <stdbool.h>
36
37#include "machdep.h"
38
39	/* program mode */
40extern int mode;
41#define MODE_PLAYER	1
42#define MODE_DRIVER	2
43#define MODE_LOGGER	3
44
45	/* command line flags */
46extern bool randomize;			/* -x, give first available ship */
47extern bool longfmt;			/* -l, print score in long format */
48extern bool nobells;			/* -b, don't ring bell before Signal */
49
50	/* other initial data */
51extern gid_t gid;
52extern gid_t egid;
53#define MAXNAMESIZE	20
54extern char myname[MAXNAMESIZE];
55
56#define dieroll()		((random()) % 6 + 1)
57#define sqr(a)		((a) * (a))
58#define min(a,b)	((a) < (b) ? (a) : (b))
59
60#define grappled(a)	((a)->file->ngrap)
61#define fouled(a)	((a)->file->nfoul)
62#define snagged(a)	(grappled(a) + fouled(a))
63
64#define grappled2(a, b)	((a)->file->grap[(b)->file->index].sn_count)
65#define fouled2(a, b)	((a)->file->foul[(b)->file->index].sn_count)
66#define snagged2(a, b)	(grappled2(a, b) + fouled2(a, b))
67
68#define Xgrappled2(a, b) ((a)->file->grap[(b)->file->index].sn_turn < turn-1 \
69			  ? grappled2(a, b) : 0)
70#define Xfouled2(a, b)	((a)->file->foul[(b)->file->index].sn_turn < turn-1 \
71			 ? fouled2(a, b) : 0)
72#define Xsnagged2(a, b)	(Xgrappled2(a, b) + Xfouled2(a, b))
73
74#define cleangrapple(a, b, c)	Cleansnag(a, b, c, 1)
75#define cleanfoul(a, b, c)	Cleansnag(a, b, c, 2)
76#define cleansnag(a, b, c)	Cleansnag(a, b, c, 3)
77
78#define sterncolour(sp)	((sp)->file->stern+'0'-((sp)->file->captured ? 10 : 0))
79#define sternrow(sp)	((sp)->file->row + dr[(sp)->file->dir])
80#define sterncol(sp)	((sp)->file->col + dc[(sp)->file->dir])
81
82#define capship(sp)	((sp)->file->captured?(sp)->file->captured:(sp))
83
84#define readyname(r)	((r) & R_LOADING ? '*' : ((r) & R_INITIAL ? '!' : ' '))
85
86/* loadL and loadR, should match loadname[] */
87#define L_EMPTY		0		/* should be 0, don't change */
88#define L_GRAPE		1
89#define L_CHAIN		2
90#define L_ROUND		3
91#define L_DOUBLE	4
92#define L_EXPLODE	5
93
94/*
95 * readyL and readyR, these are bits, except R_EMPTY
96 */
97#define R_EMPTY		0		/* not loaded and not loading */
98#define R_LOADING	1		/* loading */
99#define R_DOUBLE	2		/* loading double */
100#define R_LOADED	4		/* loaded */
101#define R_INITIAL	8		/* loaded initial */
102
103#define HULL		0
104#define RIGGING		1
105
106#define NLOG 10
107struct logs {
108	char l_name[MAXNAMESIZE];
109	int l_uid;
110	int l_shipnum;
111	int l_gamenum;
112	int l_netpoints;
113};
114
115struct BP {
116	struct ship *toship;
117	short turnsent;
118	short mensent;
119};
120
121struct snag {
122	short sn_count;
123	short sn_turn;
124};
125
126#define NSCENE	/*nscene*/ 32
127#define NSHIP	10
128#define NBP	3
129
130#define NNATION	8
131#define N_A	0
132#define N_B	1
133#define N_S	2
134#define N_F	3
135#define N_J	4
136#define N_D	5
137#define N_K	6
138#define N_O	7
139
140struct File {
141	int index;
142	char captain[MAXNAMESIZE];	/* 0 */
143	short points;			/* 20 */
144	unsigned char loadL;		/* 22 */
145	unsigned char loadR;		/* 24 */
146	unsigned char readyL;		/* 26 */
147	unsigned char readyR;		/* 28 */
148	struct BP OBP[NBP];		/* 30 */
149	struct BP DBP[NBP];		/* 48 */
150	char struck;			/* 66 */
151	struct ship *captured;		/* 68 */
152	short pcrew;			/* 70 */
153	char movebuf[10];		/* 72 */
154	char drift;			/* 82 */
155	short nfoul;
156	short ngrap;
157	struct snag foul[NSHIP];	/* 84 */
158	struct snag grap[NSHIP];	/* 124 */
159	char RH;			/* 224 */
160	char RG;			/* 226 */
161	char RR;			/* 228 */
162	char FS;			/* 230 */
163	char explode;			/* 232 */
164	char sink;			/* 234 */
165	unsigned char dir;
166	short col;
167	short row;
168	char loadwith;
169	char stern;
170};
171
172struct ship {
173	const char *shipname;		/* 0 */
174	struct shipspecs *specs;	/* 2 */
175	unsigned char nationality;	/* 4 */
176	short shiprow;			/* 6 */
177	short shipcol;			/* 8 */
178	char shipdir;			/* 10 */
179	struct File *file;		/* 12 */
180};
181
182struct scenario {
183	char winddir;			/* 0 */
184	char windspeed;			/* 2 */
185	char windchange;		/* 4 */
186	unsigned char vessels;		/* 12 */
187	const char *name;		/* 14 */
188	struct ship ship[NSHIP];	/* 16 */
189};
190extern struct scenario scene[NSCENE];
191extern int nscene;
192
193struct shipspecs {
194	char bs;
195	char fs;
196	char ta;
197	short guns;
198	unsigned char class;
199	char hull;
200	unsigned char qual;
201	char crew1;
202	char crew2;
203	char crew3;
204	char gunL;
205	char gunR;
206	char carL;
207	char carR;
208	int rig1;
209	int rig2;
210	int rig3;
211	int rig4;
212	short pts;
213};
214
215extern struct scenario *cc;		/* the current scenario */
216extern struct ship *ls;		/* &cc->ship[cc->vessels] */
217
218#define SHIP(s)		(&cc->ship[s])
219#define foreachship(sp)	for ((sp) = cc->ship; (sp) < ls; (sp)++)
220
221struct windeffects {
222	char A, B, C, D;
223};
224extern const struct windeffects WET[7][6];
225
226struct Tables {
227	char H, G, C, R;
228};
229extern const struct Tables RigTable[11][6];
230extern const struct Tables HullTable[11][6];
231
232extern const char AMMO[9][4];
233extern const char HDT[9][10];
234extern const char HDTrake[9][10];
235extern const char QUAL[9][5];
236extern const char MT[9][3];
237
238extern const char *const countryname[];
239extern const char *const shortclassname[];
240extern const char *const classname[];
241extern const char *const directionname[];
242extern const char *const qualname[];
243extern const char loadname[];
244
245extern const char rangeofshot[];
246
247extern const char dr[], dc[];
248
249extern int winddir;
250extern int windspeed;
251extern int turn;
252extern int game;
253extern int alive;
254extern int people;
255extern int hasdriver;
256
257
258/* assorted.c */
259void table(struct ship *, struct ship *, int, int, int, int);
260void Cleansnag(struct ship *, struct ship *, int, int);
261
262/* dr_1.c */
263void unfoul(void);
264void boardcomp(void);
265void resolve(void);
266void compcombat(void);
267int next(void);
268
269/* dr_2.c */
270void thinkofgrapples(void);
271void checkup(void);
272void prizecheck(void);
273void closeon(struct ship *, struct ship *, char *, size_t, int, int, bool);
274
275/* dr_3.c */
276void moveall(void);
277void sendbp(struct ship *, struct ship *, int, int);
278int is_toughmelee(struct ship *, struct ship *, int, int);
279void reload(void);
280void checksails(void);
281
282/* dr_4.c */
283void ungrap(struct ship *, struct ship *);
284void grap(struct ship *, struct ship *);
285
286/* dr_5.c */
287void subtract(struct ship *, struct ship *, int, int [3], int);
288int mensent(struct ship *, struct ship *, int[3], struct ship **, int *, int);
289
290/* dr_main.c */
291int dr_main(void);
292void startdriver(void);
293
294/* game.c */
295int maxturns(struct ship *, bool *);
296int maxmove(struct ship *, int, int);
297
298/* lo_main.c */
299void lo_curses(void);
300int lo_main(void);
301
302/* misc.c */
303int range(struct ship *, struct ship *);
304struct ship *closestenemy(struct ship *, int, int);
305int gunsbear(struct ship *, struct ship *);
306int portside(struct ship *, struct ship *, int);
307int colours(struct ship *);
308void logger(struct ship *);
309
310/* parties.c */
311int meleeing(struct ship *, struct ship *);
312int boarding(struct ship *, int);
313void unboard(struct ship *, struct ship *, int);
314
315/* pl_1.c */
316void leave(int) __dead;
317void choke(int) __dead;
318void child(int);
319
320/* pl_2.c */
321void newturn(int);
322void play(void) __dead;
323
324/* pl_3.c */
325void acceptcombat(void);
326void grapungrap(void);
327void unfoulplayer(void);
328
329/* pl_4.c */
330void changesail(void);
331void acceptsignal(void);
332void lookout(void);
333const char *saywhat(struct ship *, int);
334void eyeball(struct ship *);
335
336/* pl_5.c */
337void acceptmove(void);
338void acceptboard(void);
339
340/* pl_6.c */
341void repair(void);
342void loadplayer(void);
343
344/* pl_7.c */
345void initscreen(void);
346void cleanupscreen(void);
347void Signal(const char *, struct ship *, ...) __printflike(1,3);
348void Msg(const char *, ...) __printflike(1,2);
349int sgetch(const char *, struct ship *, int);
350void sgetstr(const char *, char *, int);
351void centerview(void);
352void upview(void);
353void downview(void);
354void leftview(void);
355void rightview(void);
356void startup(void);
357
358/* pl_main.c */
359void pl_main_init(void);
360void pl_main_uninit(void);
361__dead void pl_main(void);
362
363/* sync.c */
364void fmtship(char *, size_t, const char *, struct ship *);
365void makesignal(struct ship *, const char *, struct ship *, ...)
366	__printflike(2,4);
367void makemsg(struct ship *, const char *, ...) __printflike(2, 3);
368int sync_exists(int);
369int sync_open(void);
370void sync_close(int);
371int Sync(void);
372
373void send_captain(struct ship *ship, const char *astr);
374void send_captured(struct ship *ship, long a);
375void send_class(struct ship *ship, long a);
376void send_crew(struct ship *ship, long a, long b, long c);
377void send_dbp(struct ship *ship, long a, long b, long c, long d);
378void send_drift(struct ship *ship, long a);
379void send_explode(struct ship *ship, long a);
380void send_foul(struct ship *ship, long a);
381void send_gunl(struct ship *ship, long a, long b);
382void send_gunr(struct ship *ship, long a, long b);
383void send_hull(struct ship *ship, long a);
384void send_move(struct ship *ship, const char *astr);
385void send_obp(struct ship *ship, long a, long b, long c, long d);
386void send_pcrew(struct ship *ship, long a);
387void send_unfoul(struct ship *ship, long a, long b);
388void send_points(struct ship *ship, long a);
389void send_qual(struct ship *ship, long a);
390void send_ungrap(struct ship *ship, long a, long b);
391void send_rigg(struct ship *ship, long a, long b, long c, long d);
392void send_col(struct ship *ship, long a);
393void send_dir(struct ship *ship, long a);
394void send_row(struct ship *ship, long a);
395void send_signal(struct ship *ship, const char *astr);
396void send_sink(struct ship *ship, long a);
397void send_struck(struct ship *ship, long a);
398void send_ta(struct ship *ship, long a);
399void send_alive(void);
400void send_turn(long a);
401void send_wind(long a, long b);
402void send_fs(struct ship *ship, long a);
403void send_grap(struct ship *ship, long a);
404void send_rig1(struct ship *ship, long a);
405void send_rig2(struct ship *ship, long a);
406void send_rig3(struct ship *ship, long a);
407void send_rig4(struct ship *ship, long a);
408void send_begin(struct ship *ship);
409void send_end(struct ship *ship);
410void send_ddead(void);
411