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