Home | History | Annotate | Line # | Download | only in trek
trek.h revision 1.3
      1 /*	$NetBSD: trek.h,v 1.3 1995/04/22 10:59:36 cgd Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1980, 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  *	@(#)trek.h	8.1 (Berkeley) 5/31/93
     36  */
     37 
     38 /*
     39 **  Global Declarations
     40 **
     41 **	Virtually all non-local variable declarations are made in this
     42 **	file.  Exceptions are those things which are initialized, which
     43 **	are defined in "externs.c", and things which are local to one
     44 **	program file.
     45 **
     46 **	So far as I know, nothing in here must be preinitialized to
     47 **	zero.
     48 **
     49 **	You may have problems from the loader if you move this to a
     50 **	different machine.  These things actually get allocated in each
     51 **	source file, which UNIX allows; however, you may (on other
     52 **	systems) have to change everything in here to be "extern" and
     53 **	actually allocate stuff in "externs.c"
     54 */
     55 
     56 /* external function definitions */
     57 extern double	franf();	/* floating random number function */
     58 extern double	sqrt();		/* square root */
     59 extern double	sin(), cos();	/* trig functions */
     60 extern double	atan2();	/* fancy arc tangent function */
     61 extern double	log();		/* log base e */
     62 extern double	pow();		/* power function */
     63 extern double	fabs();		/* absolute value function */
     64 extern double	exp();		/* exponential function */
     65 
     66 /*********************  GALAXY  **************************/
     67 
     68 /* galactic parameters */
     69 # define	NSECTS		10	/* dimensions of quadrant in sectors */
     70 # define	NQUADS		8	/* dimension of galazy in quadrants */
     71 # define	NINHAB		32	/* number of quadrants which are inhabited */
     72 
     73 struct quad		/* definition for each quadrant */
     74 {
     75 	char	bases;		/* number of bases in this quadrant */
     76 	char	klings;		/* number of Klingons in this quadrant */
     77 	char	holes;		/* number of black holes in this quadrant */
     78 	int	scanned;	/* star chart entry (see below) */
     79 	char	stars;		/* number of stars in this quadrant */
     80 	char	qsystemname;	/* starsystem name (see below) */
     81 };
     82 
     83 # define	Q_DISTRESSED	0200
     84 # define	Q_SYSTEM	077
     85 
     86 /*  systemname conventions:
     87  *	1 -> NINHAB	index into Systemname table for live system.
     88  *	+ Q_DISTRESSED	distressed starsystem -- systemname & Q_SYSTEM
     89  *			is the index into the Event table which will
     90  *			have the system name
     91  *	0		dead or nonexistent starsystem
     92  *
     93  *  starchart ("scanned") conventions:
     94  *	0 -> 999	taken as is
     95  *	-1		not yet scanned ("...")
     96  *	1000		supernova ("///")
     97  *	1001		starbase + ??? (".1.")
     98 */
     99 
    100 /* ascii names of systems */
    101 extern char	*Systemname[NINHAB];
    102 
    103 /* quadrant definition */
    104 struct quad	Quad[NQUADS][NQUADS];
    105 
    106 /* defines for sector map  (below) */
    107 # define	EMPTY		'.'
    108 # define	STAR		'*'
    109 # define	BASE		'#'
    110 # define	ENTERPRISE	'E'
    111 # define	QUEENE		'Q'
    112 # define	KLINGON		'K'
    113 # define	INHABIT		'@'
    114 # define	HOLE		' '
    115 
    116 /* current sector map */
    117 char	Sect[NSECTS][NSECTS];
    118 
    119 
    120 /************************ DEVICES ******************************/
    121 
    122 # define	NDEV		16	/* max number of devices */
    123 
    124 /* device tokens */
    125 # define	WARP		0	/* warp engines */
    126 # define	SRSCAN		1	/* short range scanners */
    127 # define	LRSCAN		2	/* long range scanners */
    128 # define	PHASER		3	/* phaser control */
    129 # define	TORPED		4	/* photon torpedo control */
    130 # define	IMPULSE		5	/* impulse engines */
    131 # define	SHIELD		6	/* shield control */
    132 # define	COMPUTER	7	/* on board computer */
    133 # define	SSRADIO		8	/* subspace radio */
    134 # define	LIFESUP		9	/* life support systems */
    135 # define	SINS		10	/* Space Inertial Navigation System */
    136 # define	CLOAK		11	/* cloaking device */
    137 # define	XPORTER		12	/* transporter */
    138 # define	SHUTTLE		13	/* shuttlecraft */
    139 
    140 /* device names */
    141 struct device
    142 {
    143 	char	*name;		/* device name */
    144 	char	*person;	/* the person who fixes it */
    145 };
    146 
    147 struct device	Device[NDEV];
    148 
    149 /***************************  EVENTS  ****************************/
    150 
    151 # define	NEVENTS		12	/* number of different event types */
    152 
    153 # define	E_LRTB		1	/* long range tractor beam */
    154 # define	E_KATSB		2	/* Klingon attacks starbase */
    155 # define	E_KDESB		3	/* Klingon destroys starbase */
    156 # define	E_ISSUE		4	/* distress call is issued */
    157 # define	E_ENSLV		5	/* Klingons enslave a quadrant */
    158 # define	E_REPRO		6	/* a Klingon is reproduced */
    159 # define	E_FIXDV		7	/* fix a device */
    160 # define	E_ATTACK	8	/* Klingon attack during rest period */
    161 # define	E_SNAP		9	/* take a snapshot for time warp */
    162 # define	E_SNOVA		10	/* supernova occurs */
    163 
    164 # define	E_GHOST		0100	/* ghost of a distress call if ssradio out */
    165 # define	E_HIDDEN	0200	/* event that is unreportable because ssradio out */
    166 # define	E_EVENT		077	/* mask to get event code */
    167 
    168 struct event
    169 {
    170 	char	x, y;			/* coordinates */
    171 	double	date;			/* trap stardate */
    172 	char	evcode;			/* event type */
    173 	char	systemname;		/* starsystem name */
    174 };
    175 /* systemname conventions:
    176  *	1 -> NINHAB	index into Systemname table for reported distress calls
    177  *
    178  * evcode conventions:
    179  *	1 -> NEVENTS-1	event type
    180  *	+ E_HIDDEN	unreported (SSradio out)
    181  *	+ E_GHOST	actually already expired
    182  *	0		unallocated
    183  */
    184 
    185 # define	MAXEVENTS	25	/* max number of concurrently pending events */
    186 
    187 struct event	Event[MAXEVENTS];	/* dynamic event list; one entry per pending event */
    188 
    189 /*****************************  KLINGONS  *******************************/
    190 
    191 struct kling
    192 {
    193 	char	x, y;		/* coordinates */
    194 	int	power;		/* power left */
    195 	double	dist;		/* distance to Enterprise */
    196 	double	avgdist;	/* average over this move */
    197 	char	srndreq;	/* set if surrender has been requested */
    198 };
    199 
    200 # define	MAXKLQUAD	9	/* maximum klingons per quadrant */
    201 
    202 /********************** MISCELLANEOUS ***************************/
    203 
    204 /* condition codes */
    205 # define	GREEN		0
    206 # define	DOCKED		1
    207 # define	YELLOW		2
    208 # define	RED		3
    209 
    210 /* starbase coordinates */
    211 # define	MAXBASES	9	/* maximum number of starbases in galaxy */
    212 
    213 /*  distress calls  */
    214 # define	MAXDISTR	5	/* maximum concurrent distress calls */
    215 
    216 /* phaser banks */
    217 # define	NBANKS		6	/* number of phaser banks */
    218 
    219 struct xy
    220 {
    221 	char	x, y;		/* coordinates */
    222 };
    223 
    224 
    225 /*
    226  *	note that much of the stuff in the following structs CAN NOT
    227  *	be moved around!!!!
    228  */
    229 
    230 
    231 /* information regarding the state of the starship */
    232 struct
    233 {
    234 	double	warp;		/* warp factor */
    235 	double	warp2;		/* warp factor squared */
    236 	double	warp3;		/* warp factor cubed */
    237 	char	shldup;		/* shield up flag */
    238 	char	cloaked;	/* set if cloaking device on */
    239 	int	energy;		/* starship's energy */
    240 	int	shield;		/* energy in shields */
    241 	double	reserves;	/* life support reserves */
    242 	int	crew;		/* ship's complement */
    243 	int	brigfree;	/* space left in brig */
    244 	char	torped;		/* torpedoes */
    245 	char	cloakgood;	/* set if we have moved */
    246 	int	quadx;		/* quadrant x coord */
    247 	int	quady;		/* quadrant y coord */
    248 	int	sectx;		/* sector x coord */
    249 	int	secty;		/* sector y coord */
    250 	char	cond;		/* condition code */
    251 	char	sinsbad;	/* Space Inertial Navigation System condition */
    252 	char	*shipname;	/* name of current starship */
    253 	char	ship;		/* current starship */
    254 	int	distressed;	/* number of distress calls */
    255 }	Ship;
    256 
    257 /* sinsbad is set if SINS is working but not calibrated */
    258 
    259 /* game related information, mostly scoring */
    260 struct
    261 {
    262 	int	killk;		/* number of klingons killed */
    263 	int	deaths;		/* number of deaths onboard Enterprise */
    264 	char	negenbar;	/* number of hits on negative energy barrier */
    265 	char	killb;		/* number of starbases killed */
    266 	int	kills;		/* number of stars killed */
    267 	char	skill;		/* skill rating of player */
    268 	char	length;		/* length of game */
    269 	char	killed;		/* set if you were killed */
    270 	char	killinhab;	/* number of inhabited starsystems killed */
    271 	char	tourn;		/* set if a tournament game */
    272 	char	passwd[15];	/* game password */
    273 	char	snap;		/* set if snapshot taken */
    274 	char	helps;		/* number of help calls */
    275 	int	captives;	/* total number of captives taken */
    276 }	Game;
    277 
    278 /* per move information */
    279 struct
    280 {
    281 	char	free;		/* set if a move is free */
    282 	char	endgame;	/* end of game flag */
    283 	char	shldchg;	/* set if shields changed this move */
    284 	char	newquad;	/* set if just entered this quadrant */
    285 	char	resting;	/* set if this move is a rest */
    286 	double	time;		/* time used this move */
    287 }	Move;
    288 
    289 /* parametric information */
    290 struct
    291 {
    292 	char	bases;		/* number of starbases */
    293 	char	klings;		/* number of klingons */
    294 	double	date;		/* stardate */
    295 	double	time;		/* time left */
    296 	double	resource;	/* Federation resources */
    297 	int	energy;		/* starship's energy */
    298 	int	shield;		/* energy in shields */
    299 	double	reserves;	/* life support reserves */
    300 	int	crew;		/* size of ship's complement */
    301 	int	brigfree;	/* max possible number of captives */
    302 	char	torped;		/* photon torpedos */
    303 	double	damfac[NDEV];	/* damage factor */
    304 	double	dockfac;	/* docked repair time factor */
    305 	double	regenfac;	/* regeneration factor */
    306 	int	stopengy;	/* energy to do emergency stop */
    307 	int	shupengy;	/* energy to put up shields */
    308 	int	klingpwr;	/* Klingon initial power */
    309 	int	warptime;	/* time chewer multiplier */
    310 	double	phasfac;	/* Klingon phaser power eater factor */
    311 	char	moveprob[6];	/* probability that a Klingon moves */
    312 	double	movefac[6];	/* Klingon move distance multiplier */
    313 	double	eventdly[NEVENTS];	/* event time multipliers */
    314 	double	navigcrud[2];	/* navigation crudup factor */
    315 	int	cloakenergy;	/* cloaking device energy per stardate */
    316 	double	damprob[NDEV];	/* damage probability */
    317 	double	hitfac;		/* Klingon attack factor */
    318 	int	klingcrew;	/* number of Klingons in a crew */
    319 	double	srndrprob;	/* surrender probability */
    320 	int	energylow;	/* low energy mark (cond YELLOW) */
    321 }	Param;
    322 
    323 /* Sum of damage probabilities must add to 1000 */
    324 
    325 /* other information kept in a snapshot */
    326 struct
    327 {
    328 	char	bases;		/* number of starbases */
    329 	char	klings;		/* number of klingons */
    330 	double	date;		/* stardate */
    331 	double	time;		/* time left */
    332 	double	resource;	/* Federation resources */
    333 	char	distressed;	/* number of currently distressed quadrants */
    334 	struct event	*eventptr[NEVENTS];	/* pointer to event structs */
    335 	struct xy	base[MAXBASES];		/* locations of starbases */
    336 }	Now;
    337 
    338 /* Other stuff, not dumped in a snapshot */
    339 struct
    340 {
    341 	struct kling	klingon[MAXKLQUAD];	/* sorted Klingon list */
    342 	char		nkling;			/* number of Klingons in this sector */
    343 						/* < 0 means automatic override mode */
    344 	char		fast;			/* set if speed > 300 baud */
    345 	struct xy	starbase;	/* starbase in current quadrant */
    346 	char		snapshot[sizeof Quad + sizeof Event + sizeof Now];	/* snapshot for time warp */
    347 	char		statreport;		/* set to get a status report on a srscan */
    348 }	Etc;
    349 
    350 /*
    351  *	eventptr is a pointer to the event[] entry of the last
    352  *	scheduled event of each type.  Zero if no such event scheduled.
    353  */
    354 
    355 /* Klingon move indicies */
    356 # define	KM_OB		0	/* Old quadrant, Before attack */
    357 # define	KM_OA		1	/* Old quadrant, After attack */
    358 # define	KM_EB		2	/* Enter quadrant, Before attack */
    359 # define	KM_EA		3	/* Enter quadrant, After attack */
    360 # define	KM_LB		4	/* Leave quadrant, Before attack */
    361 # define	KM_LA		5	/* Leave quadrant, After attack */
    362 
    363 /* you lose codes */
    364 # define	L_NOTIME	1	/* ran out of time */
    365 # define	L_NOENGY	2	/* ran out of energy */
    366 # define	L_DSTRYD	3	/* destroyed by a Klingon */
    367 # define	L_NEGENB	4	/* ran into the negative energy barrier */
    368 # define	L_SUICID	5	/* destroyed in a nova */
    369 # define	L_SNOVA		6	/* destroyed in a supernova */
    370 # define	L_NOLIFE	7	/* life support died (so did you) */
    371 # define	L_NOHELP	8	/* you could not be rematerialized */
    372 # define	L_TOOFAST	9	/* pretty stupid going at warp 10 */
    373 # define	L_STAR		10	/* ran into a star */
    374 # define	L_DSTRCT	11	/* self destructed */
    375 # define	L_CAPTURED	12	/* captured by Klingons */
    376 # define	L_NOCREW	13	/* you ran out of crew */
    377 
    378 /******************  COMPILE OPTIONS  ***********************/
    379 
    380 /* Trace info */
    381 # define	xTRACE		1
    382 int	Trace;
    383