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