Commit | Line | Data |
---|---|---|
261fa12c | 1 | /* |
1e008c14 | 2 | * Copyright (c) 1983 Regents of the University of California. |
c0ca48ec | 3 | * All rights reserved. |
1e008c14 | 4 | * |
b2e7427f | 5 | * %sccs.include.redist.c% |
c0ca48ec | 6 | * |
b2e7427f | 7 | * @(#)extern.h 5.4 (Berkeley) %G% |
b5f0675e EW |
8 | */ |
9 | ||
261fa12c CL |
10 | #include <stdio.h> |
11 | #include <signal.h> | |
12 | #include <ctype.h> | |
ba28d9ed | 13 | #include <setjmp.h> |
261fa12c CL |
14 | #include "machdep.h" |
15 | ||
ba28d9ed EW |
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 */ | |
33873692 EW |
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 */ | |
ba28d9ed EW |
28 | |
29 | /* other initial modes */ | |
30 | char issetuid; /* running setuid */ | |
31 | ||
b3a57661 EW |
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 | ||
6ca45914 EW |
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) | |
b3a57661 | 52 | |
2a43399b | 53 | #define sterncolour(sp) ((sp)->file->stern+'0'-((sp)->file->captured?10:0)) |
b3a57661 EW |
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 | |
261fa12c | 68 | |
b3a57661 EW |
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 | |
6ca45914 | 93 | #define W_MOVE 13 |
b3a57661 EW |
94 | #define W_OBP 14 |
95 | #define W_PCREW 15 | |
6ca45914 | 96 | #define W_UNFOUL 16 |
b3a57661 EW |
97 | #define W_POINTS 17 |
98 | #define W_QUAL 18 | |
6ca45914 | 99 | #define W_UNGRAP 19 |
b3a57661 | 100 | #define W_RIGG 20 |
6ca45914 EW |
101 | #define W_COL 21 |
102 | #define W_DIR 22 | |
103 | #define W_ROW 23 | |
b3a57661 EW |
104 | #define W_SIGNAL 24 |
105 | #define W_SINK 25 | |
106 | #define W_STRUCK 26 | |
107 | #define W_TA 27 | |
6c17b19a | 108 | #define W_ALIVE 28 |
b3a57661 EW |
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 | |
6c17b19a EW |
117 | #define W_BEGIN 37 |
118 | #define W_END 38 | |
8606f36c | 119 | #define W_DDEAD 39 |
261fa12c | 120 | |
8606f36c | 121 | #define NLOG 10 |
261fa12c | 122 | struct logs { |
b3a57661 EW |
123 | char l_name[20]; |
124 | int l_uid; | |
125 | int l_shipnum; | |
126 | int l_gamenum; | |
127 | int l_netpoints; | |
261fa12c CL |
128 | }; |
129 | ||
2016bd8e | 130 | struct BP { |
1eda8103 | 131 | short turnsent; |
b3a57661 | 132 | struct ship *toship; |
1eda8103 | 133 | short mensent; |
261fa12c CL |
134 | }; |
135 | ||
2016bd8e | 136 | struct snag { |
6ca45914 EW |
137 | short sn_count; |
138 | short sn_turn; | |
261fa12c CL |
139 | }; |
140 | ||
d95a9c3b | 141 | #define NSCENE nscene |
b3a57661 EW |
142 | #define NSHIP 10 |
143 | #define NBP 3 | |
144 | ||
d95a9c3b | 145 | #define NNATION 8 |
b3a57661 EW |
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 | |
d95a9c3b EW |
151 | #define N_D 5 |
152 | #define N_K 6 | |
153 | #define N_O 7 | |
261fa12c | 154 | |
2016bd8e | 155 | struct File { |
6ca45914 | 156 | int index; |
b3a57661 | 157 | char captain[20]; /* 0 */ |
1eda8103 EW |
158 | short points; /* 20 */ |
159 | char loadL; /* 22 */ | |
160 | char loadR; /* 24 */ | |
161 | char readyL; /* 26 */ | |
162 | char readyR; /* 28 */ | |
b3a57661 EW |
163 | struct BP OBP[NBP]; /* 30 */ |
164 | struct BP DBP[NBP]; /* 48 */ | |
1eda8103 | 165 | char struck; /* 66 */ |
b3a57661 | 166 | struct ship *captured; /* 68 */ |
1eda8103 | 167 | short pcrew; /* 70 */ |
6ca45914 | 168 | char movebuf[10]; /* 72 */ |
1eda8103 | 169 | char drift; /* 82 */ |
6ca45914 EW |
170 | short nfoul; |
171 | short ngrap; | |
172 | struct snag foul[NSHIP]; /* 84 */ | |
173 | struct snag grap[NSHIP]; /* 124 */ | |
1eda8103 EW |
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; | |
261fa12c CL |
185 | }; |
186 | ||
b3a57661 EW |
187 | struct ship { |
188 | char *shipname; /* 0 */ | |
189 | struct shipspecs *specs; /* 2 */ | |
1eda8103 EW |
190 | char nationality; /* 4 */ |
191 | short shiprow; /* 6 */ | |
192 | short shipcol; /* 8 */ | |
193 | char shipdir; /* 10 */ | |
b3a57661 EW |
194 | struct File *file; /* 12 */ |
195 | }; | |
261fa12c CL |
196 | |
197 | struct scenario { | |
1eda8103 EW |
198 | char winddir; /* 0 */ |
199 | char windspeed; /* 2 */ | |
200 | char windchange; /* 4 */ | |
1eda8103 | 201 | char vessels; /* 12 */ |
b3a57661 EW |
202 | char *name; /* 14 */ |
203 | struct ship ship[NSHIP]; /* 16 */ | |
261fa12c | 204 | }; |
d95a9c3b EW |
205 | struct scenario scene[]; |
206 | int nscene; | |
261fa12c CL |
207 | |
208 | struct shipspecs { | |
1eda8103 EW |
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; | |
261fa12c | 228 | }; |
2016bd8e | 229 | struct shipspecs specs[]; |
261fa12c | 230 | |
b3a57661 EW |
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 | ||
2016bd8e | 237 | struct windeffects { |
1eda8103 | 238 | char A, B, C, D; |
2016bd8e EW |
239 | }; |
240 | struct windeffects WET[7][6]; | |
241 | ||
242 | struct Tables { | |
1eda8103 | 243 | char H, G, C, R; |
2016bd8e EW |
244 | }; |
245 | struct Tables RigTable[11][6]; | |
246 | struct Tables HullTable[11][6]; | |
261fa12c | 247 | |
1eda8103 EW |
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]; | |
261fa12c | 253 | |
b3a57661 EW |
254 | char *countryname[]; |
255 | char *classname[]; | |
256 | char *directionname[]; | |
257 | char *qualname[]; | |
258 | char loadname[]; | |
259 | ||
1eda8103 | 260 | char rangeofshot[]; |
b3a57661 EW |
261 | |
262 | char dr[], dc[]; | |
263 | ||
6c17b19a EW |
264 | int winddir; |
265 | int windspeed; | |
266 | int turn; | |
b3a57661 | 267 | int game; |
6c17b19a EW |
268 | int alive; |
269 | int people; | |
8606f36c | 270 | char hasdriver; |
261fa12c | 271 | |
261fa12c | 272 | char *info(); |
261fa12c | 273 | char *quality(); |
261fa12c | 274 | double arctan(); |
b3a57661 EW |
275 | char *saywhat(); |
276 | struct ship *closestenemy(); | |
277 | ||
278 | char *calloc(); | |
ba28d9ed | 279 | char *rindex(); |
b3a57661 EW |
280 | char *strcpy(); |
281 | char *strcat(); | |
282 | char *strncpy(); | |
283 | char *getenv(); | |
284 | char *gets(); |