Home | History | Annotate | Line # | Download | only in sail
extern.h revision 1.3
      1 /*	$NetBSD: extern.h,v 1.3 1997/04/19 07:35:33 thorpej 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 "machdep.h"
     44 
     45 	/* program mode */
     46 int mode;
     47 jmp_buf restart;
     48 #define MODE_PLAYER	1
     49 #define MODE_DRIVER	2
     50 #define MODE_LOGGER	3
     51 
     52 	/* command line flags */
     53 char debug;				/* -D */
     54 char randomize;				/* -x, give first available ship */
     55 char longfmt;				/* -l, print score in long format */
     56 char nobells;				/* -b, don't ring bell before Signal */
     57 
     58 	/* other initial modes */
     59 char issetuid;				/* running setuid */
     60 
     61 #define die()		((rand() >> 3) % 6 + 1)
     62 #define sqr(a)		((a) * (a))
     63 #define abs(a)		((a) > 0 ? (a) : -(a))
     64 #define min(a,b)	((a) < (b) ? (a) : (b))
     65 
     66 #define grappled(a)	((a)->file->ngrap)
     67 #define fouled(a)	((a)->file->nfoul)
     68 #define snagged(a)	(grappled(a) + fouled(a))
     69 
     70 #define grappled2(a, b)	((a)->file->grap[(b)->file->index].sn_count)
     71 #define fouled2(a, b)	((a)->file->foul[(b)->file->index].sn_count)
     72 #define snagged2(a, b)	(grappled2(a, b) + fouled2(a, b))
     73 
     74 #define Xgrappled2(a, b) ((a)->file->grap[(b)->file->index].sn_turn < turn-1 ? grappled2(a, b) : 0)
     75 #define Xfouled2(a, b)	((a)->file->foul[(b)->file->index].sn_turn < turn-1 ? fouled2(a, b) : 0)
     76 #define Xsnagged2(a, b)	(Xgrappled2(a, b) + Xfouled2(a, b))
     77 
     78 #define cleangrapple(a, b, c)	Cleansnag(a, b, c, 1)
     79 #define cleanfoul(a, b, c)	Cleansnag(a, b, c, 2)
     80 #define cleansnag(a, b, c)	Cleansnag(a, b, c, 3)
     81 
     82 #define sterncolour(sp)	((sp)->file->stern+'0'-((sp)->file->captured?10:0))
     83 #define sternrow(sp)	((sp)->file->row + dr[(sp)->file->dir])
     84 #define sterncol(sp)	((sp)->file->col + dc[(sp)->file->dir])
     85 
     86 #define capship(sp)	((sp)->file->captured?(sp)->file->captured:(sp))
     87 
     88 #define readyname(r)	((r) & R_LOADING ? '*' : ((r) & R_INITIAL ? '!' : ' '))
     89 
     90 /* loadL and loadR, should match loadname[] */
     91 #define L_EMPTY		0		/* should be 0, don't change */
     92 #define L_GRAPE		1
     93 #define L_CHAIN		2
     94 #define L_ROUND		3
     95 #define L_DOUBLE	4
     96 #define L_EXPLODE	5
     97 
     98 /*
     99  * readyL and readyR, these are bits, except R_EMPTY
    100  */
    101 #define R_EMPTY		0		/* not loaded and not loading */
    102 #define R_LOADING	1		/* loading */
    103 #define R_DOUBLE	2		/* loading double */
    104 #define R_LOADED	4		/* loaded */
    105 #define R_INITIAL	8		/* loaded initial */
    106 
    107 #define HULL		0
    108 #define RIGGING		1
    109 
    110 #define W_CAPTAIN	1
    111 #define W_CAPTURED	2
    112 #define W_CLASS		3
    113 #define W_CREW		4
    114 #define W_DBP		5
    115 #define W_DRIFT		6
    116 #define W_EXPLODE	7
    117 #define W_FILE		8
    118 #define W_FOUL		9
    119 #define W_GUNL		10
    120 #define W_GUNR		11
    121 #define W_HULL		12
    122 #define W_MOVE		13
    123 #define W_OBP		14
    124 #define W_PCREW		15
    125 #define W_UNFOUL	16
    126 #define W_POINTS	17
    127 #define W_QUAL		18
    128 #define W_UNGRAP	19
    129 #define W_RIGG		20
    130 #define W_COL		21
    131 #define W_DIR		22
    132 #define W_ROW		23
    133 #define W_SIGNAL	24
    134 #define W_SINK		25
    135 #define W_STRUCK	26
    136 #define W_TA		27
    137 #define W_ALIVE		28
    138 #define W_TURN		29
    139 #define W_WIND		30
    140 #define W_FS		31
    141 #define W_GRAP		32
    142 #define W_RIG1		33
    143 #define W_RIG2		34
    144 #define W_RIG3		35
    145 #define W_RIG4		36
    146 #define W_BEGIN		37
    147 #define W_END		38
    148 #define W_DDEAD		39
    149 
    150 #define NLOG 10
    151 struct logs {
    152 	char l_name[20];
    153 	int l_uid;
    154 	int l_shipnum;
    155 	int l_gamenum;
    156 	int l_netpoints;
    157 };
    158 
    159 struct BP {
    160 	short turnsent;
    161 	struct ship *toship;
    162 	short mensent;
    163 };
    164 
    165 struct snag {
    166 	short sn_count;
    167 	short sn_turn;
    168 };
    169 
    170 #define NSCENE	nscene
    171 #define NSHIP	10
    172 #define NBP	3
    173 
    174 #define NNATION	8
    175 #define N_A	0
    176 #define N_B	1
    177 #define N_S	2
    178 #define N_F	3
    179 #define N_J	4
    180 #define N_D	5
    181 #define N_K	6
    182 #define N_O	7
    183 
    184 struct File {
    185 	int index;
    186 	char captain[20];		/* 0 */
    187 	short points;			/* 20 */
    188 	char loadL;			/* 22 */
    189 	char loadR;			/* 24 */
    190 	char readyL;			/* 26 */
    191 	char readyR;			/* 28 */
    192 	struct BP OBP[NBP];		/* 30 */
    193 	struct BP DBP[NBP];		/* 48 */
    194 	char struck;			/* 66 */
    195 	struct ship *captured;		/* 68 */
    196 	short pcrew;			/* 70 */
    197 	char movebuf[10];		/* 72 */
    198 	char drift;			/* 82 */
    199 	short nfoul;
    200 	short ngrap;
    201 	struct snag foul[NSHIP];	/* 84 */
    202 	struct snag grap[NSHIP];	/* 124 */
    203 	char RH;			/* 224 */
    204 	char RG;			/* 226 */
    205 	char RR;			/* 228 */
    206 	char FS;			/* 230 */
    207 	char explode;			/* 232 */
    208 	char sink;			/* 234 */
    209 	char dir;
    210 	short col;
    211 	short row;
    212 	char loadwith;
    213 	char stern;
    214 };
    215 
    216 struct ship {
    217 	char *shipname;			/* 0 */
    218 	struct shipspecs *specs;	/* 2 */
    219 	char nationality;		/* 4 */
    220 	short shiprow;			/* 6 */
    221 	short shipcol;			/* 8 */
    222 	char shipdir;			/* 10 */
    223 	struct File *file;		/* 12 */
    224 };
    225 
    226 struct scenario {
    227 	char winddir;			/* 0 */
    228 	char windspeed;			/* 2 */
    229 	char windchange;		/* 4 */
    230 	char vessels;			/* 12 */
    231 	char *name;			/* 14 */
    232 	struct ship ship[NSHIP];	/* 16 */
    233 };
    234 struct scenario scene[];
    235 int nscene;
    236 
    237 struct shipspecs {
    238 	char bs;
    239 	char fs;
    240 	char ta;
    241 	short guns;
    242 	char class;
    243 	char hull;
    244 	char qual;
    245 	char crew1;
    246 	char crew2;
    247 	char crew3;
    248 	char gunL;
    249 	char gunR;
    250 	char carL;
    251 	char carR;
    252 	int rig1;
    253 	int rig2;
    254 	int rig3;
    255 	int rig4;
    256 	short pts;
    257 };
    258 struct shipspecs specs[];
    259 
    260 struct scenario *cc;		/* the current scenario */
    261 struct ship *ls;		/* &cc->ship[cc->vessels] */
    262 
    263 #define SHIP(s)		(&cc->ship[s])
    264 #define foreachship(sp)	for ((sp) = cc->ship; (sp) < ls; (sp)++)
    265 
    266 struct windeffects {
    267 	char A, B, C, D;
    268 };
    269 struct windeffects WET[7][6];
    270 
    271 struct Tables {
    272 	char H, G, C, R;
    273 };
    274 struct Tables RigTable[11][6];
    275 struct Tables HullTable[11][6];
    276 
    277 char AMMO[9][4];
    278 char HDT[9][10];
    279 char HDTrake[9][10];
    280 char QUAL[9][5];
    281 char MT[9][3];
    282 
    283 char *countryname[];
    284 char *classname[];
    285 char *directionname[];
    286 char *qualname[];
    287 char loadname[];
    288 
    289 char rangeofshot[];
    290 
    291 char dr[], dc[];
    292 
    293 int winddir;
    294 int windspeed;
    295 int turn;
    296 int game;
    297 int alive;
    298 int people;
    299 char hasdriver;
    300 
    301 char *info();
    302 char *quality();
    303 double arctan();
    304 char *saywhat();
    305 struct ship *closestenemy();
    306 
    307 char *calloc();
    308 char *rindex();
    309 char *strcpy();
    310 char *strcat();
    311 char *strncpy();
    312 char *getenv();
    313 char *gets();
    314