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