1 /* $NetBSD: extern.h,v 1.34 2009/03/15 03:33:56 dholland Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * @(#)externs.h 8.1 (Berkeley) 5/31/93
34 #include <sys/types.h>
45 /* command line flags */
46 extern int randomize
; /* -x, give first available ship */
47 extern int longfmt
; /* -l, print score in long format */
48 extern int nobells
; /* -b, don't ring bell before Signal */
50 /* other initial modes */
54 #define dieroll() ((random()) % 6 + 1)
55 #define sqr(a) ((a) * (a))
56 #define min(a,b) ((a) < (b) ? (a) : (b))
58 #define grappled(a) ((a)->file->ngrap)
59 #define fouled(a) ((a)->file->nfoul)
60 #define snagged(a) (grappled(a) + fouled(a))
62 #define grappled2(a, b) ((a)->file->grap[(b)->file->index].sn_count)
63 #define fouled2(a, b) ((a)->file->foul[(b)->file->index].sn_count)
64 #define snagged2(a, b) (grappled2(a, b) + fouled2(a, b))
66 #define Xgrappled2(a, b) ((a)->file->grap[(b)->file->index].sn_turn < turn-1 \
67 ? grappled2(a, b) : 0)
68 #define Xfouled2(a, b) ((a)->file->foul[(b)->file->index].sn_turn < turn-1 \
70 #define Xsnagged2(a, b) (Xgrappled2(a, b) + Xfouled2(a, b))
72 #define cleangrapple(a, b, c) Cleansnag(a, b, c, 1)
73 #define cleanfoul(a, b, c) Cleansnag(a, b, c, 2)
74 #define cleansnag(a, b, c) Cleansnag(a, b, c, 3)
76 #define sterncolour(sp) ((sp)->file->stern+'0'-((sp)->file->captured ? 10 : 0))
77 #define sternrow(sp) ((sp)->file->row + dr[(sp)->file->dir])
78 #define sterncol(sp) ((sp)->file->col + dc[(sp)->file->dir])
80 #define capship(sp) ((sp)->file->captured?(sp)->file->captured:(sp))
82 #define readyname(r) ((r) & R_LOADING ? '*' : ((r) & R_INITIAL ? '!' : ' '))
84 /* loadL and loadR, should match loadname[] */
85 #define L_EMPTY 0 /* should be 0, don't change */
93 * readyL and readyR, these are bits, except R_EMPTY
95 #define R_EMPTY 0 /* not loaded and not loading */
96 #define R_LOADING 1 /* loading */
97 #define R_DOUBLE 2 /* loading double */
98 #define R_LOADED 4 /* loaded */
99 #define R_INITIAL 8 /* loaded initial */
124 #define NSCENE nscene
140 char captain
[20]; /* 0 */
141 short points
; /* 20 */
142 unsigned char loadL
; /* 22 */
143 unsigned char loadR
; /* 24 */
144 unsigned char readyL
; /* 26 */
145 unsigned char readyR
; /* 28 */
146 struct BP OBP
[NBP
]; /* 30 */
147 struct BP DBP
[NBP
]; /* 48 */
148 char struck
; /* 66 */
149 struct ship
*captured
; /* 68 */
150 short pcrew
; /* 70 */
151 char movebuf
[10]; /* 72 */
155 struct snag foul
[NSHIP
]; /* 84 */
156 struct snag grap
[NSHIP
]; /* 124 */
161 char explode
; /* 232 */
171 const char *shipname
; /* 0 */
172 struct shipspecs
*specs
; /* 2 */
173 unsigned char nationality
; /* 4 */
174 short shiprow
; /* 6 */
175 short shipcol
; /* 8 */
176 char shipdir
; /* 10 */
177 struct File
*file
; /* 12 */
181 char winddir
; /* 0 */
182 char windspeed
; /* 2 */
183 char windchange
; /* 4 */
184 unsigned char vessels
; /* 12 */
185 const char *name
; /* 14 */
186 struct ship ship
[NSHIP
]; /* 16 */
188 extern struct scenario scene
[];
213 extern struct scenario
*cc
; /* the current scenario */
214 extern struct ship
*ls
; /* &cc->ship[cc->vessels] */
216 #define SHIP(s) (&cc->ship[s])
217 #define foreachship(sp) for ((sp) = cc->ship; (sp) < ls; (sp)++)
222 extern const struct windeffects WET
[7][6];
227 extern const struct Tables RigTable
[11][6];
228 extern const struct Tables HullTable
[11][6];
230 extern const char AMMO
[9][4];
231 extern const char HDT
[9][10];
232 extern const char HDTrake
[9][10];
233 extern const char QUAL
[9][5];
234 extern const char MT
[9][3];
236 extern const char *const countryname
[];
237 extern const char *const classname
[];
238 extern const char *const directionname
[];
239 extern const char *const qualname
[];
240 extern const char loadname
[];
242 extern const char rangeofshot
[];
244 extern const char dr
[], dc
[];
247 extern int windspeed
;
252 extern int hasdriver
;
255 void table(struct ship
*, struct ship
*, int, int, int, int);
256 void Cleansnag(struct ship
*, struct ship
*, int, int);
260 void boardcomp(void);
262 void compcombat(void);
266 void thinkofgrapples(void);
268 void prizecheck(void);
269 void closeon(struct ship
*, struct ship
*, char *, size_t, int, int, bool);
273 void sendbp(struct ship
*, struct ship
*, int, int);
274 int is_toughmelee(struct ship
*, struct ship
*, int, int);
276 void checksails(void);
279 void ungrap(struct ship
*, struct ship
*);
280 void grap(struct ship
*, struct ship
*);
283 void subtract(struct ship
*, struct ship
*, int, int [3], int);
284 int mensent(struct ship
*, struct ship
*, int[3], struct ship
**, int *, int);
290 int maxturns(struct ship
*, bool *);
291 int maxmove(struct ship
*, int, int);
297 int range(struct ship
*, struct ship
*);
298 struct ship
*closestenemy(struct ship
*, int, int);
299 int gunsbear(struct ship
*, struct ship
*);
300 int portside(struct ship
*, struct ship
*, int);
301 int colours(struct ship
*);
302 void logger(struct ship
*);
305 int meleeing(struct ship
*, struct ship
*);
306 int boarding(struct ship
*, int);
307 void unboard(struct ship
*, struct ship
*, int);
310 void leave(int) __attribute__((__noreturn__
));
311 void choke(int) __attribute__((__noreturn__
));
316 void play(void) __attribute__((__noreturn__
));
319 void acceptcombat(void);
320 void grapungrap(void);
321 void unfoulplayer(void);
324 void changesail(void);
325 void acceptsignal(void);
327 const char *saywhat(struct ship
*, int);
328 void eyeball(struct ship
*);
331 void acceptmove(void);
332 void acceptboard(void);
336 void loadplayer(void);
339 void initscreen(void);
340 void cleanupscreen(void);
341 void Signal(const char *, struct ship
*, ...)
342 __attribute__((__format__(__printf__
,1,3)));
343 void Msg(const char *, ...)
344 __attribute__((__format__(__printf__
,1,2)));
345 int sgetch(const char *, struct ship
*, int);
346 void sgetstr(const char *, char *, int);
347 void centerview(void);
351 void rightview(void);
357 void fmtship(char *, size_t, const char *, struct ship
*);
358 void makesignal(struct ship
*, const char *, struct ship
*, ...)
359 __attribute__((__format__(__printf__
,2,4)));
360 void makemsg(struct ship
*, const char *, ...)
361 __attribute__((__format__(__printf__
,2,3)));
362 int sync_exists(int);
364 void sync_close(int);
367 void send_captain(struct ship
*ship
, const char *astr
);
368 void send_captured(struct ship
*ship
, long a
);
369 void send_class(struct ship
*ship
, long a
);
370 void send_crew(struct ship
*ship
, long a
, long b
, long c
);
371 void send_dbp(struct ship
*ship
, long a
, long b
, long c
, long d
);
372 void send_drift(struct ship
*ship
, long a
);
373 void send_explode(struct ship
*ship
, long a
);
374 void send_foul(struct ship
*ship
, long a
);
375 void send_gunl(struct ship
*ship
, long a
, long b
);
376 void send_gunr(struct ship
*ship
, long a
, long b
);
377 void send_hull(struct ship
*ship
, long a
);
378 void send_move(struct ship
*ship
, const char *astr
);
379 void send_obp(struct ship
*ship
, long a
, long b
, long c
, long d
);
380 void send_pcrew(struct ship
*ship
, long a
);
381 void send_unfoul(struct ship
*ship
, long a
, long b
);
382 void send_points(struct ship
*ship
, long a
);
383 void send_qual(struct ship
*ship
, long a
);
384 void send_ungrap(struct ship
*ship
, long a
, long b
);
385 void send_rigg(struct ship
*ship
, long a
, long b
, long c
, long d
);
386 void send_col(struct ship
*ship
, long a
);
387 void send_dir(struct ship
*ship
, long a
);
388 void send_row(struct ship
*ship
, long a
);
389 void send_signal(struct ship
*ship
, const char *astr
);
390 void send_sink(struct ship
*ship
, long a
);
391 void send_struck(struct ship
*ship
, long a
);
392 void send_ta(struct ship
*ship
, long a
);
393 void send_alive(void);
394 void send_turn(long a
);
395 void send_wind(long a
, long b
);
396 void send_fs(struct ship
*ship
, long a
);
397 void send_grap(struct ship
*ship
, long a
);
398 void send_rig1(struct ship
*ship
, long a
);
399 void send_rig2(struct ship
*ship
, long a
);
400 void send_rig3(struct ship
*ship
, long a
);
401 void send_rig4(struct ship
*ship
, long a
);
402 void send_begin(struct ship
*ship
);
403 void send_end(struct ship
*ship
);
404 void send_ddead(void);