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