extern.h revision 1.1 1 /*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)externs.h 8.1 (Berkeley) 5/31/93
34 */
35
36 #include <stdio.h>
37 #include <signal.h>
38 #include <ctype.h>
39 #include <setjmp.h>
40 #include "machdep.h"
41
42 /* program mode */
43 int mode;
44 jmp_buf restart;
45 #define MODE_PLAYER 1
46 #define MODE_DRIVER 2
47 #define MODE_LOGGER 3
48
49 /* command line flags */
50 char debug; /* -D */
51 char randomize; /* -x, give first available ship */
52 char longfmt; /* -l, print score in long format */
53 char nobells; /* -b, don't ring bell before Signal */
54
55 /* other initial modes */
56 char issetuid; /* running setuid */
57
58 #define die() ((rand() >> 3) % 6 + 1)
59 #define sqr(a) ((a) * (a))
60 #define abs(a) ((a) > 0 ? (a) : -(a))
61 #define min(a,b) ((a) < (b) ? (a) : (b))
62
63 #define grappled(a) ((a)->file->ngrap)
64 #define fouled(a) ((a)->file->nfoul)
65 #define snagged(a) (grappled(a) + fouled(a))
66
67 #define grappled2(a, b) ((a)->file->grap[(b)->file->index].sn_count)
68 #define fouled2(a, b) ((a)->file->foul[(b)->file->index].sn_count)
69 #define snagged2(a, b) (grappled2(a, b) + fouled2(a, b))
70
71 #define Xgrappled2(a, b) ((a)->file->grap[(b)->file->index].sn_turn < turn-1 ? grappled2(a, b) : 0)
72 #define Xfouled2(a, b) ((a)->file->foul[(b)->file->index].sn_turn < turn-1 ? fouled2(a, b) : 0)
73 #define Xsnagged2(a, b) (Xgrappled2(a, b) + Xfouled2(a, b))
74
75 #define cleangrapple(a, b, c) Cleansnag(a, b, c, 1)
76 #define cleanfoul(a, b, c) Cleansnag(a, b, c, 2)
77 #define cleansnag(a, b, c) Cleansnag(a, b, c, 3)
78
79 #define sterncolour(sp) ((sp)->file->stern+'0'-((sp)->file->captured?10:0))
80 #define sternrow(sp) ((sp)->file->row + dr[(sp)->file->dir])
81 #define sterncol(sp) ((sp)->file->col + dc[(sp)->file->dir])
82
83 #define capship(sp) ((sp)->file->captured?(sp)->file->captured:(sp))
84
85 #define readyname(r) ((r) & R_LOADING ? '*' : ((r) & R_INITIAL ? '!' : ' '))
86
87 /* loadL and loadR, should match loadname[] */
88 #define L_EMPTY 0 /* should be 0, don't change */
89 #define L_GRAPE 1
90 #define L_CHAIN 2
91 #define L_ROUND 3
92 #define L_DOUBLE 4
93 #define L_EXPLODE 5
94
95 /*
96 * readyL and readyR, these are bits, except R_EMPTY
97 */
98 #define R_EMPTY 0 /* not loaded and not loading */
99 #define R_LOADING 1 /* loading */
100 #define R_DOUBLE 2 /* loading double */
101 #define R_LOADED 4 /* loaded */
102 #define R_INITIAL 8 /* loaded initial */
103
104 #define HULL 0
105 #define RIGGING 1
106
107 #define W_CAPTAIN 1
108 #define W_CAPTURED 2
109 #define W_CLASS 3
110 #define W_CREW 4
111 #define W_DBP 5
112 #define W_DRIFT 6
113 #define W_EXPLODE 7
114 #define W_FILE 8
115 #define W_FOUL 9
116 #define W_GUNL 10
117 #define W_GUNR 11
118 #define W_HULL 12
119 #define W_MOVE 13
120 #define W_OBP 14
121 #define W_PCREW 15
122 #define W_UNFOUL 16
123 #define W_POINTS 17
124 #define W_QUAL 18
125 #define W_UNGRAP 19
126 #define W_RIGG 20
127 #define W_COL 21
128 #define W_DIR 22
129 #define W_ROW 23
130 #define W_SIGNAL 24
131 #define W_SINK 25
132 #define W_STRUCK 26
133 #define W_TA 27
134 #define W_ALIVE 28
135 #define W_TURN 29
136 #define W_WIND 30
137 #define W_FS 31
138 #define W_GRAP 32
139 #define W_RIG1 33
140 #define W_RIG2 34
141 #define W_RIG3 35
142 #define W_RIG4 36
143 #define W_BEGIN 37
144 #define W_END 38
145 #define W_DDEAD 39
146
147 #define NLOG 10
148 struct logs {
149 char l_name[20];
150 int l_uid;
151 int l_shipnum;
152 int l_gamenum;
153 int l_netpoints;
154 };
155
156 struct BP {
157 short turnsent;
158 struct ship *toship;
159 short mensent;
160 };
161
162 struct snag {
163 short sn_count;
164 short sn_turn;
165 };
166
167 #define NSCENE nscene
168 #define NSHIP 10
169 #define NBP 3
170
171 #define NNATION 8
172 #define N_A 0
173 #define N_B 1
174 #define N_S 2
175 #define N_F 3
176 #define N_J 4
177 #define N_D 5
178 #define N_K 6
179 #define N_O 7
180
181 struct File {
182 int index;
183 char captain[20]; /* 0 */
184 short points; /* 20 */
185 char loadL; /* 22 */
186 char loadR; /* 24 */
187 char readyL; /* 26 */
188 char readyR; /* 28 */
189 struct BP OBP[NBP]; /* 30 */
190 struct BP DBP[NBP]; /* 48 */
191 char struck; /* 66 */
192 struct ship *captured; /* 68 */
193 short pcrew; /* 70 */
194 char movebuf[10]; /* 72 */
195 char drift; /* 82 */
196 short nfoul;
197 short ngrap;
198 struct snag foul[NSHIP]; /* 84 */
199 struct snag grap[NSHIP]; /* 124 */
200 char RH; /* 224 */
201 char RG; /* 226 */
202 char RR; /* 228 */
203 char FS; /* 230 */
204 char explode; /* 232 */
205 char sink; /* 234 */
206 char dir;
207 short col;
208 short row;
209 char loadwith;
210 char stern;
211 };
212
213 struct ship {
214 char *shipname; /* 0 */
215 struct shipspecs *specs; /* 2 */
216 char nationality; /* 4 */
217 short shiprow; /* 6 */
218 short shipcol; /* 8 */
219 char shipdir; /* 10 */
220 struct File *file; /* 12 */
221 };
222
223 struct scenario {
224 char winddir; /* 0 */
225 char windspeed; /* 2 */
226 char windchange; /* 4 */
227 char vessels; /* 12 */
228 char *name; /* 14 */
229 struct ship ship[NSHIP]; /* 16 */
230 };
231 struct scenario scene[];
232 int nscene;
233
234 struct shipspecs {
235 char bs;
236 char fs;
237 char ta;
238 short guns;
239 char class;
240 char hull;
241 char qual;
242 char crew1;
243 char crew2;
244 char crew3;
245 char gunL;
246 char gunR;
247 char carL;
248 char carR;
249 char rig1;
250 char rig2;
251 char rig3;
252 char rig4;
253 short pts;
254 };
255 struct shipspecs specs[];
256
257 struct scenario *cc; /* the current scenario */
258 struct ship *ls; /* &cc->ship[cc->vessels] */
259
260 #define SHIP(s) (&cc->ship[s])
261 #define foreachship(sp) for ((sp) = cc->ship; (sp) < ls; (sp)++)
262
263 struct windeffects {
264 char A, B, C, D;
265 };
266 struct windeffects WET[7][6];
267
268 struct Tables {
269 char H, G, C, R;
270 };
271 struct Tables RigTable[11][6];
272 struct Tables HullTable[11][6];
273
274 char AMMO[9][4];
275 char HDT[9][10];
276 char HDTrake[9][10];
277 char QUAL[9][5];
278 char MT[9][3];
279
280 char *countryname[];
281 char *classname[];
282 char *directionname[];
283 char *qualname[];
284 char loadname[];
285
286 char rangeofshot[];
287
288 char dr[], dc[];
289
290 int winddir;
291 int windspeed;
292 int turn;
293 int game;
294 int alive;
295 int people;
296 char hasdriver;
297
298 char *info();
299 char *quality();
300 double arctan();
301 char *saywhat();
302 struct ship *closestenemy();
303
304 char *calloc();
305 char *rindex();
306 char *strcpy();
307 char *strcat();
308 char *strncpy();
309 char *getenv();
310 char *gets();
311