extern.h revision 1.36 1 1.36 dholland /* $NetBSD: extern.h,v 1.36 2010/08/06 09:14:40 dholland Exp $ */
2 1.2 tls
3 1.1 tls /*
4 1.1 tls * Copyright (c) 1983, 1993
5 1.1 tls * The Regents of the University of California. All rights reserved.
6 1.1 tls *
7 1.1 tls * Redistribution and use in source and binary forms, with or without
8 1.1 tls * modification, are permitted provided that the following conditions
9 1.1 tls * are met:
10 1.1 tls * 1. Redistributions of source code must retain the above copyright
11 1.1 tls * notice, this list of conditions and the following disclaimer.
12 1.1 tls * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 tls * notice, this list of conditions and the following disclaimer in the
14 1.1 tls * documentation and/or other materials provided with the distribution.
15 1.25 agc * 3. Neither the name of the University nor the names of its contributors
16 1.1 tls * may be used to endorse or promote products derived from this software
17 1.1 tls * without specific prior written permission.
18 1.1 tls *
19 1.1 tls * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.1 tls * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 tls * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 tls * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.1 tls * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 tls * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 tls * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 tls * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 tls * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 tls * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 tls * SUCH DAMAGE.
30 1.1 tls *
31 1.1 tls * @(#)externs.h 8.1 (Berkeley) 5/31/93
32 1.1 tls */
33 1.1 tls
34 1.26 jsm #include <sys/types.h>
35 1.31 dholland #include <stdbool.h>
36 1.26 jsm
37 1.1 tls #include "machdep.h"
38 1.1 tls
39 1.1 tls /* program mode */
40 1.13 jsm extern int mode;
41 1.1 tls #define MODE_PLAYER 1
42 1.1 tls #define MODE_DRIVER 2
43 1.1 tls #define MODE_LOGGER 3
44 1.1 tls
45 1.1 tls /* command line flags */
46 1.36 dholland extern bool randomize; /* -x, give first available ship */
47 1.36 dholland extern bool longfmt; /* -l, print score in long format */
48 1.36 dholland extern bool nobells; /* -b, don't ring bell before Signal */
49 1.1 tls
50 1.36 dholland /* other initial data */
51 1.14 jsm extern gid_t gid;
52 1.14 jsm extern gid_t egid;
53 1.36 dholland #define MAXNAMESIZE 20
54 1.36 dholland extern char myname[MAXNAMESIZE];
55 1.1 tls
56 1.17 jwise #define dieroll() ((random()) % 6 + 1)
57 1.1 tls #define sqr(a) ((a) * (a))
58 1.1 tls #define min(a,b) ((a) < (b) ? (a) : (b))
59 1.1 tls
60 1.1 tls #define grappled(a) ((a)->file->ngrap)
61 1.1 tls #define fouled(a) ((a)->file->nfoul)
62 1.1 tls #define snagged(a) (grappled(a) + fouled(a))
63 1.1 tls
64 1.1 tls #define grappled2(a, b) ((a)->file->grap[(b)->file->index].sn_count)
65 1.1 tls #define fouled2(a, b) ((a)->file->foul[(b)->file->index].sn_count)
66 1.1 tls #define snagged2(a, b) (grappled2(a, b) + fouled2(a, b))
67 1.1 tls
68 1.30 dholland #define Xgrappled2(a, b) ((a)->file->grap[(b)->file->index].sn_turn < turn-1 \
69 1.30 dholland ? grappled2(a, b) : 0)
70 1.30 dholland #define Xfouled2(a, b) ((a)->file->foul[(b)->file->index].sn_turn < turn-1 \
71 1.30 dholland ? fouled2(a, b) : 0)
72 1.1 tls #define Xsnagged2(a, b) (Xgrappled2(a, b) + Xfouled2(a, b))
73 1.1 tls
74 1.1 tls #define cleangrapple(a, b, c) Cleansnag(a, b, c, 1)
75 1.1 tls #define cleanfoul(a, b, c) Cleansnag(a, b, c, 2)
76 1.1 tls #define cleansnag(a, b, c) Cleansnag(a, b, c, 3)
77 1.1 tls
78 1.30 dholland #define sterncolour(sp) ((sp)->file->stern+'0'-((sp)->file->captured ? 10 : 0))
79 1.1 tls #define sternrow(sp) ((sp)->file->row + dr[(sp)->file->dir])
80 1.1 tls #define sterncol(sp) ((sp)->file->col + dc[(sp)->file->dir])
81 1.1 tls
82 1.1 tls #define capship(sp) ((sp)->file->captured?(sp)->file->captured:(sp))
83 1.1 tls
84 1.1 tls #define readyname(r) ((r) & R_LOADING ? '*' : ((r) & R_INITIAL ? '!' : ' '))
85 1.1 tls
86 1.1 tls /* loadL and loadR, should match loadname[] */
87 1.1 tls #define L_EMPTY 0 /* should be 0, don't change */
88 1.1 tls #define L_GRAPE 1
89 1.1 tls #define L_CHAIN 2
90 1.1 tls #define L_ROUND 3
91 1.1 tls #define L_DOUBLE 4
92 1.1 tls #define L_EXPLODE 5
93 1.1 tls
94 1.1 tls /*
95 1.1 tls * readyL and readyR, these are bits, except R_EMPTY
96 1.1 tls */
97 1.1 tls #define R_EMPTY 0 /* not loaded and not loading */
98 1.1 tls #define R_LOADING 1 /* loading */
99 1.1 tls #define R_DOUBLE 2 /* loading double */
100 1.1 tls #define R_LOADED 4 /* loaded */
101 1.1 tls #define R_INITIAL 8 /* loaded initial */
102 1.1 tls
103 1.1 tls #define HULL 0
104 1.1 tls #define RIGGING 1
105 1.1 tls
106 1.1 tls #define NLOG 10
107 1.1 tls struct logs {
108 1.36 dholland char l_name[MAXNAMESIZE];
109 1.1 tls int l_uid;
110 1.1 tls int l_shipnum;
111 1.1 tls int l_gamenum;
112 1.1 tls int l_netpoints;
113 1.1 tls };
114 1.1 tls
115 1.1 tls struct BP {
116 1.28 abs struct ship *toship;
117 1.1 tls short turnsent;
118 1.1 tls short mensent;
119 1.1 tls };
120 1.1 tls
121 1.1 tls struct snag {
122 1.1 tls short sn_count;
123 1.1 tls short sn_turn;
124 1.1 tls };
125 1.1 tls
126 1.36 dholland #define NSCENE /*nscene*/ 32
127 1.1 tls #define NSHIP 10
128 1.1 tls #define NBP 3
129 1.1 tls
130 1.1 tls #define NNATION 8
131 1.1 tls #define N_A 0
132 1.1 tls #define N_B 1
133 1.1 tls #define N_S 2
134 1.1 tls #define N_F 3
135 1.1 tls #define N_J 4
136 1.1 tls #define N_D 5
137 1.1 tls #define N_K 6
138 1.1 tls #define N_O 7
139 1.1 tls
140 1.1 tls struct File {
141 1.1 tls int index;
142 1.36 dholland char captain[MAXNAMESIZE]; /* 0 */
143 1.1 tls short points; /* 20 */
144 1.4 christos unsigned char loadL; /* 22 */
145 1.4 christos unsigned char loadR; /* 24 */
146 1.4 christos unsigned char readyL; /* 26 */
147 1.4 christos unsigned char readyR; /* 28 */
148 1.1 tls struct BP OBP[NBP]; /* 30 */
149 1.1 tls struct BP DBP[NBP]; /* 48 */
150 1.1 tls char struck; /* 66 */
151 1.1 tls struct ship *captured; /* 68 */
152 1.1 tls short pcrew; /* 70 */
153 1.1 tls char movebuf[10]; /* 72 */
154 1.1 tls char drift; /* 82 */
155 1.1 tls short nfoul;
156 1.1 tls short ngrap;
157 1.1 tls struct snag foul[NSHIP]; /* 84 */
158 1.1 tls struct snag grap[NSHIP]; /* 124 */
159 1.1 tls char RH; /* 224 */
160 1.1 tls char RG; /* 226 */
161 1.1 tls char RR; /* 228 */
162 1.1 tls char FS; /* 230 */
163 1.1 tls char explode; /* 232 */
164 1.1 tls char sink; /* 234 */
165 1.4 christos unsigned char dir;
166 1.1 tls short col;
167 1.1 tls short row;
168 1.1 tls char loadwith;
169 1.1 tls char stern;
170 1.1 tls };
171 1.1 tls
172 1.1 tls struct ship {
173 1.10 jsm const char *shipname; /* 0 */
174 1.1 tls struct shipspecs *specs; /* 2 */
175 1.4 christos unsigned char nationality; /* 4 */
176 1.1 tls short shiprow; /* 6 */
177 1.1 tls short shipcol; /* 8 */
178 1.1 tls char shipdir; /* 10 */
179 1.1 tls struct File *file; /* 12 */
180 1.1 tls };
181 1.1 tls
182 1.1 tls struct scenario {
183 1.1 tls char winddir; /* 0 */
184 1.1 tls char windspeed; /* 2 */
185 1.1 tls char windchange; /* 4 */
186 1.4 christos unsigned char vessels; /* 12 */
187 1.10 jsm const char *name; /* 14 */
188 1.1 tls struct ship ship[NSHIP]; /* 16 */
189 1.1 tls };
190 1.36 dholland extern struct scenario scene[NSCENE];
191 1.13 jsm extern int nscene;
192 1.1 tls
193 1.1 tls struct shipspecs {
194 1.1 tls char bs;
195 1.1 tls char fs;
196 1.1 tls char ta;
197 1.1 tls short guns;
198 1.4 christos unsigned char class;
199 1.1 tls char hull;
200 1.4 christos unsigned char qual;
201 1.1 tls char crew1;
202 1.1 tls char crew2;
203 1.1 tls char crew3;
204 1.1 tls char gunL;
205 1.1 tls char gunR;
206 1.1 tls char carL;
207 1.1 tls char carR;
208 1.3 thorpej int rig1;
209 1.3 thorpej int rig2;
210 1.3 thorpej int rig3;
211 1.3 thorpej int rig4;
212 1.1 tls short pts;
213 1.1 tls };
214 1.1 tls
215 1.13 jsm extern struct scenario *cc; /* the current scenario */
216 1.13 jsm extern struct ship *ls; /* &cc->ship[cc->vessels] */
217 1.1 tls
218 1.1 tls #define SHIP(s) (&cc->ship[s])
219 1.1 tls #define foreachship(sp) for ((sp) = cc->ship; (sp) < ls; (sp)++)
220 1.1 tls
221 1.1 tls struct windeffects {
222 1.1 tls char A, B, C, D;
223 1.1 tls };
224 1.13 jsm extern const struct windeffects WET[7][6];
225 1.1 tls
226 1.1 tls struct Tables {
227 1.1 tls char H, G, C, R;
228 1.1 tls };
229 1.13 jsm extern const struct Tables RigTable[11][6];
230 1.13 jsm extern const struct Tables HullTable[11][6];
231 1.1 tls
232 1.13 jsm extern const char AMMO[9][4];
233 1.13 jsm extern const char HDT[9][10];
234 1.13 jsm extern const char HDTrake[9][10];
235 1.13 jsm extern const char QUAL[9][5];
236 1.13 jsm extern const char MT[9][3];
237 1.10 jsm
238 1.10 jsm extern const char *const countryname[];
239 1.36 dholland extern const char *const shortclassname[];
240 1.10 jsm extern const char *const classname[];
241 1.10 jsm extern const char *const directionname[];
242 1.10 jsm extern const char *const qualname[];
243 1.10 jsm extern const char loadname[];
244 1.1 tls
245 1.10 jsm extern const char rangeofshot[];
246 1.1 tls
247 1.10 jsm extern const char dr[], dc[];
248 1.1 tls
249 1.13 jsm extern int winddir;
250 1.13 jsm extern int windspeed;
251 1.13 jsm extern int turn;
252 1.13 jsm extern int game;
253 1.13 jsm extern int alive;
254 1.13 jsm extern int people;
255 1.23 jwise extern int hasdriver;
256 1.1 tls
257 1.36 dholland
258 1.4 christos /* assorted.c */
259 1.30 dholland void table(struct ship *, struct ship *, int, int, int, int);
260 1.30 dholland void Cleansnag(struct ship *, struct ship *, int, int);
261 1.4 christos
262 1.4 christos /* dr_1.c */
263 1.30 dholland void unfoul(void);
264 1.30 dholland void boardcomp(void);
265 1.30 dholland void resolve(void);
266 1.30 dholland void compcombat(void);
267 1.30 dholland int next(void);
268 1.4 christos
269 1.4 christos /* dr_2.c */
270 1.30 dholland void thinkofgrapples(void);
271 1.30 dholland void checkup(void);
272 1.30 dholland void prizecheck(void);
273 1.31 dholland void closeon(struct ship *, struct ship *, char *, size_t, int, int, bool);
274 1.4 christos
275 1.4 christos /* dr_3.c */
276 1.30 dholland void moveall(void);
277 1.30 dholland void sendbp(struct ship *, struct ship *, int, int);
278 1.30 dholland int is_toughmelee(struct ship *, struct ship *, int, int);
279 1.30 dholland void reload(void);
280 1.30 dholland void checksails(void);
281 1.4 christos
282 1.4 christos /* dr_4.c */
283 1.30 dholland void ungrap(struct ship *, struct ship *);
284 1.30 dholland void grap(struct ship *, struct ship *);
285 1.4 christos
286 1.4 christos /* dr_5.c */
287 1.30 dholland void subtract(struct ship *, struct ship *, int, int [3], int);
288 1.30 dholland int mensent(struct ship *, struct ship *, int[3], struct ship **, int *, int);
289 1.4 christos
290 1.4 christos /* dr_main.c */
291 1.30 dholland int dr_main(void);
292 1.36 dholland void startdriver(void);
293 1.4 christos
294 1.4 christos /* game.c */
295 1.31 dholland int maxturns(struct ship *, bool *);
296 1.30 dholland int maxmove(struct ship *, int, int);
297 1.4 christos
298 1.4 christos /* lo_main.c */
299 1.36 dholland void lo_curses(void);
300 1.30 dholland int lo_main(void);
301 1.4 christos
302 1.4 christos /* misc.c */
303 1.30 dholland int range(struct ship *, struct ship *);
304 1.30 dholland struct ship *closestenemy(struct ship *, int, int);
305 1.30 dholland int gunsbear(struct ship *, struct ship *);
306 1.30 dholland int portside(struct ship *, struct ship *, int);
307 1.30 dholland int colours(struct ship *);
308 1.30 dholland void logger(struct ship *);
309 1.4 christos
310 1.4 christos /* parties.c */
311 1.30 dholland int meleeing(struct ship *, struct ship *);
312 1.30 dholland int boarding(struct ship *, int);
313 1.30 dholland void unboard(struct ship *, struct ship *, int);
314 1.4 christos
315 1.4 christos /* pl_1.c */
316 1.30 dholland void leave(int) __attribute__((__noreturn__));
317 1.30 dholland void choke(int) __attribute__((__noreturn__));
318 1.30 dholland void child(int);
319 1.4 christos
320 1.4 christos /* pl_2.c */
321 1.34 dholland void newturn(int);
322 1.30 dholland void play(void) __attribute__((__noreturn__));
323 1.4 christos
324 1.4 christos /* pl_3.c */
325 1.30 dholland void acceptcombat(void);
326 1.30 dholland void grapungrap(void);
327 1.30 dholland void unfoulplayer(void);
328 1.4 christos
329 1.4 christos /* pl_4.c */
330 1.30 dholland void changesail(void);
331 1.30 dholland void acceptsignal(void);
332 1.30 dholland void lookout(void);
333 1.30 dholland const char *saywhat(struct ship *, int);
334 1.30 dholland void eyeball(struct ship *);
335 1.4 christos
336 1.4 christos /* pl_5.c */
337 1.30 dholland void acceptmove(void);
338 1.30 dholland void acceptboard(void);
339 1.4 christos
340 1.4 christos /* pl_6.c */
341 1.30 dholland void repair(void);
342 1.30 dholland void loadplayer(void);
343 1.4 christos
344 1.4 christos /* pl_7.c */
345 1.30 dholland void initscreen(void);
346 1.30 dholland void cleanupscreen(void);
347 1.30 dholland void Signal(const char *, struct ship *, ...)
348 1.5 christos __attribute__((__format__(__printf__,1,3)));
349 1.30 dholland void Msg(const char *, ...)
350 1.5 christos __attribute__((__format__(__printf__,1,2)));
351 1.30 dholland int sgetch(const char *, struct ship *, int);
352 1.30 dholland void sgetstr(const char *, char *, int);
353 1.30 dholland void centerview(void);
354 1.30 dholland void upview(void);
355 1.30 dholland void downview(void);
356 1.30 dholland void leftview(void);
357 1.30 dholland void rightview(void);
358 1.36 dholland void startup(void);
359 1.4 christos
360 1.4 christos /* pl_main.c */
361 1.36 dholland void pl_main_init(void);
362 1.36 dholland void pl_main_uninit(void);
363 1.36 dholland void pl_main(void);
364 1.4 christos
365 1.4 christos /* sync.c */
366 1.30 dholland void fmtship(char *, size_t, const char *, struct ship *);
367 1.30 dholland void makesignal(struct ship *, const char *, struct ship *, ...)
368 1.5 christos __attribute__((__format__(__printf__,2,4)));
369 1.30 dholland void makemsg(struct ship *, const char *, ...)
370 1.5 christos __attribute__((__format__(__printf__,2,3)));
371 1.30 dholland int sync_exists(int);
372 1.30 dholland int sync_open(void);
373 1.30 dholland void sync_close(int);
374 1.30 dholland int Sync(void);
375 1.32 dholland
376 1.32 dholland void send_captain(struct ship *ship, const char *astr);
377 1.32 dholland void send_captured(struct ship *ship, long a);
378 1.32 dholland void send_class(struct ship *ship, long a);
379 1.32 dholland void send_crew(struct ship *ship, long a, long b, long c);
380 1.32 dholland void send_dbp(struct ship *ship, long a, long b, long c, long d);
381 1.32 dholland void send_drift(struct ship *ship, long a);
382 1.32 dholland void send_explode(struct ship *ship, long a);
383 1.32 dholland void send_foul(struct ship *ship, long a);
384 1.32 dholland void send_gunl(struct ship *ship, long a, long b);
385 1.32 dholland void send_gunr(struct ship *ship, long a, long b);
386 1.32 dholland void send_hull(struct ship *ship, long a);
387 1.32 dholland void send_move(struct ship *ship, const char *astr);
388 1.32 dholland void send_obp(struct ship *ship, long a, long b, long c, long d);
389 1.32 dholland void send_pcrew(struct ship *ship, long a);
390 1.32 dholland void send_unfoul(struct ship *ship, long a, long b);
391 1.32 dholland void send_points(struct ship *ship, long a);
392 1.32 dholland void send_qual(struct ship *ship, long a);
393 1.32 dholland void send_ungrap(struct ship *ship, long a, long b);
394 1.32 dholland void send_rigg(struct ship *ship, long a, long b, long c, long d);
395 1.32 dholland void send_col(struct ship *ship, long a);
396 1.32 dholland void send_dir(struct ship *ship, long a);
397 1.32 dholland void send_row(struct ship *ship, long a);
398 1.32 dholland void send_signal(struct ship *ship, const char *astr);
399 1.32 dholland void send_sink(struct ship *ship, long a);
400 1.32 dholland void send_struck(struct ship *ship, long a);
401 1.32 dholland void send_ta(struct ship *ship, long a);
402 1.32 dholland void send_alive(void);
403 1.32 dholland void send_turn(long a);
404 1.32 dholland void send_wind(long a, long b);
405 1.32 dholland void send_fs(struct ship *ship, long a);
406 1.32 dholland void send_grap(struct ship *ship, long a);
407 1.32 dholland void send_rig1(struct ship *ship, long a);
408 1.32 dholland void send_rig2(struct ship *ship, long a);
409 1.32 dholland void send_rig3(struct ship *ship, long a);
410 1.32 dholland void send_rig4(struct ship *ship, long a);
411 1.32 dholland void send_begin(struct ship *ship);
412 1.32 dholland void send_end(struct ship *ship);
413 1.32 dholland void send_ddead(void);
414