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