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