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