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