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