xref: /original-bsd/games/sail/extern.h (revision b4971bb3)
1 /*
2  * Copyright (c) 1983, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)extern.h	8.1 (Berkeley) 05/31/93
8  */
9 
10 #include <stdio.h>
11 #include <signal.h>
12 #include <ctype.h>
13 #include <setjmp.h>
14 #include "machdep.h"
15 
16 	/* program mode */
17 int mode;
18 jmp_buf restart;
19 #define MODE_PLAYER	1
20 #define MODE_DRIVER	2
21 #define MODE_LOGGER	3
22 
23 	/* command line flags */
24 char debug;				/* -D */
25 char randomize;				/* -x, give first available ship */
26 char longfmt;				/* -l, print score in long format */
27 char nobells;				/* -b, don't ring bell before Signal */
28 
29 	/* other initial modes */
30 char issetuid;				/* running setuid */
31 
32 #define die()		((rand() >> 3) % 6 + 1)
33 #define sqr(a)		((a) * (a))
34 #define abs(a)		((a) > 0 ? (a) : -(a))
35 #define min(a,b)	((a) < (b) ? (a) : (b))
36 
37 #define grappled(a)	((a)->file->ngrap)
38 #define fouled(a)	((a)->file->nfoul)
39 #define snagged(a)	(grappled(a) + fouled(a))
40 
41 #define grappled2(a, b)	((a)->file->grap[(b)->file->index].sn_count)
42 #define fouled2(a, b)	((a)->file->foul[(b)->file->index].sn_count)
43 #define snagged2(a, b)	(grappled2(a, b) + fouled2(a, b))
44 
45 #define Xgrappled2(a, b) ((a)->file->grap[(b)->file->index].sn_turn < turn-1 ? grappled2(a, b) : 0)
46 #define Xfouled2(a, b)	((a)->file->foul[(b)->file->index].sn_turn < turn-1 ? fouled2(a, b) : 0)
47 #define Xsnagged2(a, b)	(Xgrappled2(a, b) + Xfouled2(a, b))
48 
49 #define cleangrapple(a, b, c)	Cleansnag(a, b, c, 1)
50 #define cleanfoul(a, b, c)	Cleansnag(a, b, c, 2)
51 #define cleansnag(a, b, c)	Cleansnag(a, b, c, 3)
52 
53 #define sterncolour(sp)	((sp)->file->stern+'0'-((sp)->file->captured?10:0))
54 #define sternrow(sp)	((sp)->file->row + dr[(sp)->file->dir])
55 #define sterncol(sp)	((sp)->file->col + dc[(sp)->file->dir])
56 
57 #define capship(sp)	((sp)->file->captured?(sp)->file->captured:(sp))
58 
59 #define readyname(r)	((r) & R_LOADING ? '*' : ((r) & R_INITIAL ? '!' : ' '))
60 
61 /* loadL and loadR, should match loadname[] */
62 #define L_EMPTY		0		/* should be 0, don't change */
63 #define L_GRAPE		1
64 #define L_CHAIN		2
65 #define L_ROUND		3
66 #define L_DOUBLE	4
67 #define L_EXPLODE	5
68 
69 /*
70  * readyL and readyR, these are bits, except R_EMPTY
71  */
72 #define R_EMPTY		0		/* not loaded and not loading */
73 #define R_LOADING	1		/* loading */
74 #define R_DOUBLE	2		/* loading double */
75 #define R_LOADED	4		/* loaded */
76 #define R_INITIAL	8		/* loaded initial */
77 
78 #define HULL		0
79 #define RIGGING		1
80 
81 #define W_CAPTAIN	1
82 #define W_CAPTURED	2
83 #define W_CLASS		3
84 #define W_CREW		4
85 #define W_DBP		5
86 #define W_DRIFT		6
87 #define W_EXPLODE	7
88 #define W_FILE		8
89 #define W_FOUL		9
90 #define W_GUNL		10
91 #define W_GUNR		11
92 #define W_HULL		12
93 #define W_MOVE		13
94 #define W_OBP		14
95 #define W_PCREW		15
96 #define W_UNFOUL	16
97 #define W_POINTS	17
98 #define W_QUAL		18
99 #define W_UNGRAP	19
100 #define W_RIGG		20
101 #define W_COL		21
102 #define W_DIR		22
103 #define W_ROW		23
104 #define W_SIGNAL	24
105 #define W_SINK		25
106 #define W_STRUCK	26
107 #define W_TA		27
108 #define W_ALIVE		28
109 #define W_TURN		29
110 #define W_WIND		30
111 #define W_FS		31
112 #define W_GRAP		32
113 #define W_RIG1		33
114 #define W_RIG2		34
115 #define W_RIG3		35
116 #define W_RIG4		36
117 #define W_BEGIN		37
118 #define W_END		38
119 #define W_DDEAD		39
120 
121 #define NLOG 10
122 struct logs {
123 	char l_name[20];
124 	int l_uid;
125 	int l_shipnum;
126 	int l_gamenum;
127 	int l_netpoints;
128 };
129 
130 struct BP {
131 	short turnsent;
132 	struct ship *toship;
133 	short mensent;
134 };
135 
136 struct snag {
137 	short sn_count;
138 	short sn_turn;
139 };
140 
141 #define NSCENE	nscene
142 #define NSHIP	10
143 #define NBP	3
144 
145 #define NNATION	8
146 #define N_A	0
147 #define N_B	1
148 #define N_S	2
149 #define N_F	3
150 #define N_J	4
151 #define N_D	5
152 #define N_K	6
153 #define N_O	7
154 
155 struct File {
156 	int index;
157 	char captain[20];		/* 0 */
158 	short points;			/* 20 */
159 	char loadL;			/* 22 */
160 	char loadR;			/* 24 */
161 	char readyL;			/* 26 */
162 	char readyR;			/* 28 */
163 	struct BP OBP[NBP];		/* 30 */
164 	struct BP DBP[NBP];		/* 48 */
165 	char struck;			/* 66 */
166 	struct ship *captured;		/* 68 */
167 	short pcrew;			/* 70 */
168 	char movebuf[10];		/* 72 */
169 	char drift;			/* 82 */
170 	short nfoul;
171 	short ngrap;
172 	struct snag foul[NSHIP];	/* 84 */
173 	struct snag grap[NSHIP];	/* 124 */
174 	char RH;			/* 224 */
175 	char RG;			/* 226 */
176 	char RR;			/* 228 */
177 	char FS;			/* 230 */
178 	char explode;			/* 232 */
179 	char sink;			/* 234 */
180 	char dir;
181 	short col;
182 	short row;
183 	char loadwith;
184 	char stern;
185 };
186 
187 struct ship {
188 	char *shipname;			/* 0 */
189 	struct shipspecs *specs;	/* 2 */
190 	char nationality;		/* 4 */
191 	short shiprow;			/* 6 */
192 	short shipcol;			/* 8 */
193 	char shipdir;			/* 10 */
194 	struct File *file;		/* 12 */
195 };
196 
197 struct scenario {
198 	char winddir;			/* 0 */
199 	char windspeed;			/* 2 */
200 	char windchange;		/* 4 */
201 	char vessels;			/* 12 */
202 	char *name;			/* 14 */
203 	struct ship ship[NSHIP];	/* 16 */
204 };
205 struct scenario scene[];
206 int nscene;
207 
208 struct shipspecs {
209 	char bs;
210 	char fs;
211 	char ta;
212 	short guns;
213 	char class;
214 	char hull;
215 	char qual;
216 	char crew1;
217 	char crew2;
218 	char crew3;
219 	char gunL;
220 	char gunR;
221 	char carL;
222 	char carR;
223 	char rig1;
224 	char rig2;
225 	char rig3;
226 	char rig4;
227 	short pts;
228 };
229 struct shipspecs specs[];
230 
231 struct scenario *cc;		/* the current scenario */
232 struct ship *ls;		/* &cc->ship[cc->vessels] */
233 
234 #define SHIP(s)		(&cc->ship[s])
235 #define foreachship(sp)	for ((sp) = cc->ship; (sp) < ls; (sp)++)
236 
237 struct windeffects {
238 	char A, B, C, D;
239 };
240 struct windeffects WET[7][6];
241 
242 struct Tables {
243 	char H, G, C, R;
244 };
245 struct Tables RigTable[11][6];
246 struct Tables HullTable[11][6];
247 
248 char AMMO[9][4];
249 char HDT[9][10];
250 char HDTrake[9][10];
251 char QUAL[9][5];
252 char MT[9][3];
253 
254 char *countryname[];
255 char *classname[];
256 char *directionname[];
257 char *qualname[];
258 char loadname[];
259 
260 char rangeofshot[];
261 
262 char dr[], dc[];
263 
264 int winddir;
265 int windspeed;
266 int turn;
267 int game;
268 int alive;
269 int people;
270 char hasdriver;
271 
272 char *info();
273 char *quality();
274 double arctan();
275 char *saywhat();
276 struct ship *closestenemy();
277 
278 char *calloc();
279 char *rindex();
280 char *strcpy();
281 char *strcat();
282 char *strncpy();
283 char *getenv();
284 char *gets();
285