Home | History | Annotate | Line # | Download | only in trek
trek.h revision 1.12
      1 /*	$NetBSD: trek.h,v 1.12 2009/03/31 18:48:16 christos 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. 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  *	@(#)trek.h	8.1 (Berkeley) 5/31/93
     32  */
     33 
     34 /*
     35 **  Global Declarations
     36 **
     37 **	Virtually all non-local variable declarations are made in this
     38 **	file.  Exceptions are those things which are initialized, which
     39 **	are defined in "externs.c", and things which are local to one
     40 **	program file.
     41 **
     42 **	So far as I know, nothing in here must be preinitialized to
     43 **	zero.
     44 */
     45 
     46 /* external function definitions */
     47 
     48 /*********************  GALAXY  **************************/
     49 
     50 /* galactic parameters */
     51 # define	NSECTS		10	/* dimensions of quadrant in sectors */
     52 # define	NQUADS		8	/* dimension of galazy in quadrants */
     53 # define	NINHAB		32	/* number of quadrants which are inhabited */
     54 
     55 struct quad		/* definition for each quadrant */
     56 {
     57 	unsigned char	bases;	/* number of bases in this quadrant */
     58 	char	klings;		/* number of Klingons in this quadrant */
     59 	char	holes;		/* number of black holes in this quadrant */
     60 	int	scanned;	/* star chart entry (see below) */
     61 	short	stars;		/* number of stars in this quadrant */
     62 	char	qsystemname;	/* starsystem name (see below) */
     63 };
     64 
     65 # define	Q_DISTRESSED	0200
     66 # define	Q_SYSTEM	077
     67 
     68 /*  systemname conventions:
     69  *	1 -> NINHAB	index into Systemname table for live system.
     70  *	+ Q_DISTRESSED	distressed starsystem -- systemname & Q_SYSTEM
     71  *			is the index into the Event table which will
     72  *			have the system name
     73  *	0		dead or nonexistent starsystem
     74  *
     75  *  starchart ("scanned") conventions:
     76  *	0 -> 999	taken as is
     77  *	-1		not yet scanned ("...")
     78  *	1000		supernova ("///")
     79  *	1001		starbase + ??? (".1.")
     80 */
     81 
     82 /* ascii names of systems */
     83 extern const char	*const Systemname[NINHAB];
     84 
     85 /* quadrant definition */
     86 extern struct quad	Quad[NQUADS][NQUADS];
     87 
     88 /* defines for sector map  (below) */
     89 # define	EMPTY		'.'
     90 # define	STAR		'*'
     91 # define	BASE		'#'
     92 # define	ENTERPRISE	'E'
     93 # define	QUEENE		'Q'
     94 # define	KLINGON		'K'
     95 # define	INHABIT		'@'
     96 # define	HOLE		' '
     97 
     98 /* current sector map */
     99 extern char	Sect[NSECTS][NSECTS];
    100 
    101 
    102 
    103 /************************ DEVICES ******************************/
    104 
    105 # define	NDEV		16	/* max number of devices */
    106 
    107 /* device tokens */
    108 # define	WARP		0	/* warp engines */
    109 # define	SRSCAN		1	/* short range scanners */
    110 # define	LRSCAN		2	/* long range scanners */
    111 # define	PHASER		3	/* phaser control */
    112 # define	TORPED		4	/* photon torpedo control */
    113 # define	IMPULSE		5	/* impulse engines */
    114 # define	SHIELD		6	/* shield control */
    115 # define	COMPUTER	7	/* on board computer */
    116 # define	SSRADIO		8	/* subspace radio */
    117 # define	LIFESUP		9	/* life support systems */
    118 # define	SINS		10	/* Space Inertial Navigation System */
    119 # define	CLOAK		11	/* cloaking device */
    120 # define	XPORTER		12	/* transporter */
    121 # define	SHUTTLE		13	/* shuttlecraft */
    122 
    123 /* device names */
    124 struct device
    125 {
    126 	const char	*name;		/* device name */
    127 	const char	*person;	/* the person who fixes it */
    128 };
    129 
    130 extern const struct device	Device[NDEV];
    131 
    132 /***************************  EVENTS  ****************************/
    133 
    134 # define	NEVENTS		12	/* number of different event types */
    135 
    136 # define	E_LRTB		1	/* long range tractor beam */
    137 # define	E_KATSB		2	/* Klingon attacks starbase */
    138 # define	E_KDESB		3	/* Klingon destroys starbase */
    139 # define	E_ISSUE		4	/* distress call is issued */
    140 # define	E_ENSLV		5	/* Klingons enslave a quadrant */
    141 # define	E_REPRO		6	/* a Klingon is reproduced */
    142 # define	E_FIXDV		7	/* fix a device */
    143 # define	E_ATTACK	8	/* Klingon attack during rest period */
    144 # define	E_SNAP		9	/* take a snapshot for time warp */
    145 # define	E_SNOVA		10	/* supernova occurs */
    146 
    147 # define	E_GHOST		0100	/* ghost of a distress call if ssradio out */
    148 # define	E_HIDDEN	0200	/* event that is unreportable because ssradio out */
    149 # define	E_EVENT		077	/* mask to get event code */
    150 
    151 struct event
    152 {
    153 	unsigned char 	x, y;		/* coordinates */
    154 	double		date;		/* trap stardate */
    155 	char		evcode;		/* event type */
    156 	unsigned char	systemname;	/* starsystem name */
    157 };
    158 /* systemname conventions:
    159  *	1 -> NINHAB	index into Systemname table for reported distress calls
    160  *
    161  * evcode conventions:
    162  *	1 -> NEVENTS-1	event type
    163  *	+ E_HIDDEN	unreported (SSradio out)
    164  *	+ E_GHOST	actually already expired
    165  *	0		unallocated
    166  */
    167 
    168 # define	MAXEVENTS	25	/* max number of concurrently pending events */
    169 
    170 extern struct event	Event[MAXEVENTS];	/* dynamic event list; one entry per pending event */
    171 
    172 /*****************************  KLINGONS  *******************************/
    173 
    174 struct kling
    175 {
    176 	unsigned char	x, y;	/* coordinates */
    177 	int	power;		/* power left */
    178 	double	dist;		/* distance to Enterprise */
    179 	double	avgdist;	/* average over this move */
    180 	char	srndreq;	/* set if surrender has been requested */
    181 };
    182 
    183 # define	MAXKLQUAD	9	/* maximum klingons per quadrant */
    184 
    185 /********************** MISCELLANEOUS ***************************/
    186 
    187 /* condition codes */
    188 # define	GREEN		0
    189 # define	DOCKED		1
    190 # define	YELLOW		2
    191 # define	RED		3
    192 
    193 /* starbase coordinates */
    194 # define	MAXBASES	9	/* maximum number of starbases in galaxy */
    195 
    196 /*  distress calls  */
    197 # define	MAXDISTR	5	/* maximum concurrent distress calls */
    198 
    199 /* phaser banks */
    200 # define	NBANKS		6	/* number of phaser banks */
    201 
    202 struct xy
    203 {
    204 	unsigned char	x, y;		/* coordinates */
    205 };
    206 
    207 
    208 /*
    209  *	note that much of the stuff in the following structs CAN NOT
    210  *	be moved around!!!!
    211  */
    212 
    213 
    214 /* information regarding the state of the starship */
    215 struct Ship_struct
    216 {
    217 	double	warp;		/* warp factor */
    218 	double	warp2;		/* warp factor squared */
    219 	double	warp3;		/* warp factor cubed */
    220 	char	shldup;		/* shield up flag */
    221 	char	cloaked;	/* set if cloaking device on */
    222 	int	energy;		/* starship's energy */
    223 	int	shield;		/* energy in shields */
    224 	double	reserves;	/* life support reserves */
    225 	int	crew;		/* ship's complement */
    226 	int	brigfree;	/* space left in brig */
    227 	char	torped;		/* torpedoes */
    228 	char	cloakgood;	/* set if we have moved */
    229 	int	quadx;		/* quadrant x coord */
    230 	int	quady;		/* quadrant y coord */
    231 	int	sectx;		/* sector x coord */
    232 	int	secty;		/* sector y coord */
    233 	unsigned char	cond;	/* condition code */
    234 	char	sinsbad;	/* Space Inertial Navigation System condition */
    235 	const char *shipname;	/* name of current starship */
    236 	char	ship;		/* current starship */
    237 	int	distressed;	/* number of distress calls */
    238 };
    239 extern struct Ship_struct Ship;
    240 
    241 /* sinsbad is set if SINS is working but not calibrated */
    242 
    243 /* game related information, mostly scoring */
    244 struct Game_struct
    245 {
    246 	int	killk;		/* number of klingons killed */
    247 	int	deaths;		/* number of deaths onboard Enterprise */
    248 	char	negenbar;	/* number of hits on negative energy barrier */
    249 	char	killb;		/* number of starbases killed */
    250 	int	kills;		/* number of stars killed */
    251 	char	skill;		/* skill rating of player */
    252 	char	length;		/* length of game */
    253 	char	killed;		/* set if you were killed */
    254 	char	killinhab;	/* number of inhabited starsystems killed */
    255 	char	tourn;		/* set if a tournament game */
    256 	char	passwd[15];	/* game password */
    257 	char	snap;		/* set if snapshot taken */
    258 	char	helps;		/* number of help calls */
    259 	int	captives;	/* total number of captives taken */
    260 };
    261 extern struct Game_struct Game;
    262 
    263 /* per move information */
    264 struct Move_struct
    265 {
    266 	char	free;		/* set if a move is free */
    267 	char	endgame;	/* end of game flag */
    268 	char	shldchg;	/* set if shields changed this move */
    269 	char	newquad;	/* set if just entered this quadrant */
    270 	char	resting;	/* set if this move is a rest */
    271 	double	time;		/* time used this move */
    272 };
    273 extern struct Move_struct Move;
    274 
    275 /* parametric information */
    276 struct Param_struct
    277 {
    278 	unsigned char	bases;	/* number of starbases */
    279 	char	klings;		/* number of klingons */
    280 	double	date;		/* stardate */
    281 	double	time;		/* time left */
    282 	double	resource;	/* Federation resources */
    283 	int	energy;		/* starship's energy */
    284 	int	shield;		/* energy in shields */
    285 	double	reserves;	/* life support reserves */
    286 	int	crew;		/* size of ship's complement */
    287 	int	brigfree;	/* max possible number of captives */
    288 	char	torped;		/* photon torpedos */
    289 	double	damfac[NDEV];	/* damage factor */
    290 	double	dockfac;	/* docked repair time factor */
    291 	double	regenfac;	/* regeneration factor */
    292 	int	stopengy;	/* energy to do emergency stop */
    293 	int	shupengy;	/* energy to put up shields */
    294 	int	klingpwr;	/* Klingon initial power */
    295 	int	warptime;	/* time chewer multiplier */
    296 	double	phasfac;	/* Klingon phaser power eater factor */
    297 	char	moveprob[6];	/* probability that a Klingon moves */
    298 	double	movefac[6];	/* Klingon move distance multiplier */
    299 	double	eventdly[NEVENTS];	/* event time multipliers */
    300 	double	navigcrud[2];	/* navigation crudup factor */
    301 	int	cloakenergy;	/* cloaking device energy per stardate */
    302 	double	damprob[NDEV];	/* damage probability */
    303 	double	hitfac;		/* Klingon attack factor */
    304 	int	klingcrew;	/* number of Klingons in a crew */
    305 	double	srndrprob;	/* surrender probability */
    306 	int	energylow;	/* low energy mark (cond YELLOW) */
    307 };
    308 extern struct Param_struct Param;
    309 
    310 /* Sum of damage probabilities must add to 1000 */
    311 
    312 /* other information kept in a snapshot */
    313 struct Now_struct
    314 {
    315 	unsigned char	bases;	/* number of starbases */
    316 	char	klings;		/* number of klingons */
    317 	double	date;		/* stardate */
    318 	double	time;		/* time left */
    319 	double	resource;	/* Federation resources */
    320 	char	distressed;	/* number of currently distressed quadrants */
    321 	struct event	*eventptr[NEVENTS];	/* pointer to event structs */
    322 	struct xy	base[MAXBASES];		/* locations of starbases */
    323 };
    324 extern struct Now_struct Now;
    325 
    326 /* Other stuff, not dumped in a snapshot */
    327 struct Etc_struct
    328 {
    329 	struct kling	klingon[MAXKLQUAD];	/* sorted Klingon list */
    330 	short		nkling;			/* number of Klingons in this sector */
    331 						/* < 0 means automatic override mode */
    332 	char		fast;			/* set if speed > 300 baud */
    333 	struct xy	starbase;	/* starbase in current quadrant */
    334 	char		snapshot[sizeof Quad + sizeof Event + sizeof Now];	/* snapshot for time warp */
    335 	char		statreport;		/* set to get a status report on a srscan */
    336 };
    337 extern struct Etc_struct Etc;
    338 
    339 /*
    340  *	eventptr is a pointer to the event[] entry of the last
    341  *	scheduled event of each type.  Zero if no such event scheduled.
    342  */
    343 
    344 /* Klingon move indicies */
    345 # define	KM_OB		0	/* Old quadrant, Before attack */
    346 # define	KM_OA		1	/* Old quadrant, After attack */
    347 # define	KM_EB		2	/* Enter quadrant, Before attack */
    348 # define	KM_EA		3	/* Enter quadrant, After attack */
    349 # define	KM_LB		4	/* Leave quadrant, Before attack */
    350 # define	KM_LA		5	/* Leave quadrant, After attack */
    351 
    352 /* you lose codes */
    353 # define	L_NOTIME	1	/* ran out of time */
    354 # define	L_NOENGY	2	/* ran out of energy */
    355 # define	L_DSTRYD	3	/* destroyed by a Klingon */
    356 # define	L_NEGENB	4	/* ran into the negative energy barrier */
    357 # define	L_SUICID	5	/* destroyed in a nova */
    358 # define	L_SNOVA		6	/* destroyed in a supernova */
    359 # define	L_NOLIFE	7	/* life support died (so did you) */
    360 # define	L_NOHELP	8	/* you could not be rematerialized */
    361 # define	L_TOOFAST	9	/* pretty stupid going at warp 10 */
    362 # define	L_STAR		10	/* ran into a star */
    363 # define	L_DSTRCT	11	/* self destructed */
    364 # define	L_CAPTURED	12	/* captured by Klingons */
    365 # define	L_NOCREW	13	/* you ran out of crew */
    366 
    367 /******************  COMPILE OPTIONS  ***********************/
    368 
    369 /* Trace info */
    370 # define	xTRACE		1
    371 extern int	Trace;
    372 
    373 # define 	TOOLARGE	(DBL_MAX / 2)	/* < DOUBLE_MAX for everyone */
    374 
    375 /* abandon.c */
    376 void abandon(int);
    377 
    378 /* attack.c */
    379 void attack(int);
    380 
    381 /* autover.c */
    382 void autover(void);
    383 
    384 /* capture.c */
    385 void capture(int);
    386 struct kling *selectklingon(void);
    387 
    388 /* cgetc.c */
    389 char cgetc(int);
    390 
    391 /* check_out.c */
    392 int check_out(int);
    393 
    394 /* checkcond.c */
    395 void checkcond(void);
    396 
    397 /* compkl.c */
    398 void compkldist(int);
    399 
    400 /* computer.c */
    401 void computer(int);
    402 
    403 /* damage.c */
    404 void damage(int, double);
    405 
    406 /* damaged.c */
    407 int damaged(int);
    408 
    409 /* dcrept.c */
    410 void dcrept(int);
    411 
    412 /* destruct.c */
    413 void destruct(int);
    414 
    415 /* dock.c */
    416 void dock(int);
    417 void undock(int);
    418 
    419 /* dumpgame.c */
    420 void dumpgame(int);
    421 int restartgame(void);
    422 
    423 /* dumpme.c */
    424 void dumpme(int);
    425 
    426 /* dumpssradio.c */
    427 int dumpssradio(void);
    428 
    429 /* events.c */
    430 int events(int);
    431 
    432 /* externs.c */
    433 
    434 /* getcodi.c */
    435 int getcodi(int *, double *);
    436 
    437 /* help.c */
    438 void help(int);
    439 
    440 /* impulse.c */
    441 void impulse(int);
    442 
    443 /* initquad.c */
    444 void initquad(int);
    445 void sector(int *, int *);
    446 
    447 /* kill.c */
    448 void killk(int, int );
    449 void killb(int, int );
    450 void kills(int, int , int);
    451 void killd(int, int , int);
    452 
    453 /* klmove.c */
    454 void klmove(int);
    455 
    456 /* lose.c */
    457 void lose(int) __attribute__((__noreturn__));
    458 
    459 /* lrscan.c */
    460 void lrscan(int);
    461 
    462 /* move.c */
    463 double move(int, int, double, double);
    464 
    465 /* nova.c */
    466 void nova(int, int );
    467 
    468 /* out.c */
    469 void out(int);
    470 
    471 /* phaser.c */
    472 void phaser(int);
    473 
    474 /* play.c */
    475 void myreset(int) __attribute__((__noreturn__));
    476 void play(void) __attribute__((__noreturn__));
    477 
    478 /* ram.c */
    479 void ram(int, int );
    480 
    481 /* ranf.c */
    482 int ranf(int);
    483 double franf(void);
    484 
    485 /* rest.c */
    486 void rest(int);
    487 
    488 /* schedule.c */
    489 struct event *schedule(int, double, int, int , int);
    490 void reschedule(struct event *, double);
    491 void unschedule(struct event *);
    492 struct event *xsched(int, int, int, int , int );
    493 void xresched(struct event *, int, int);
    494 
    495 /* score.c */
    496 long score(void);
    497 
    498 /* setup.c */
    499 void setup(void);
    500 
    501 /* setwarp.c */
    502 void setwarp(int);
    503 
    504 /* shield.c */
    505 void shield(int);
    506 
    507 /* snova.c */
    508 void snova(int, int );
    509 
    510 /* srscan.c */
    511 void srscan(int);
    512 
    513 /* systemname.c */
    514 const char *systemname(const struct quad *);
    515 
    516 /* torped.c */
    517 void torped(int);
    518 
    519 /* visual.c */
    520 void visual(int);
    521 
    522 /* warp.c */
    523 void dowarp(int);
    524 void warp(int, int, double);
    525 
    526 /* win.c */
    527 void win(void) __attribute__((__noreturn__));
    528