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