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