125995Smckusick /* 2*60859Sbostic * Copyright (c) 1980, 1993 3*60859Sbostic * The Regents of the University of California. All rights reserved. 425995Smckusick * 542606Sbostic * %sccs.include.redist.c% 634205Sbostic * 7*60859Sbostic * @(#)trek.h 8.1 (Berkeley) 05/31/93 825995Smckusick */ 911708Smckusick 1011708Smckusick /* 1111708Smckusick ** Global Declarations 1211708Smckusick ** 1311708Smckusick ** Virtually all non-local variable declarations are made in this 1411708Smckusick ** file. Exceptions are those things which are initialized, which 1511708Smckusick ** are defined in "externs.c", and things which are local to one 1611708Smckusick ** program file. 1711708Smckusick ** 1811708Smckusick ** So far as I know, nothing in here must be preinitialized to 1911708Smckusick ** zero. 2011708Smckusick ** 2111708Smckusick ** You may have problems from the loader if you move this to a 2211708Smckusick ** different machine. These things actually get allocated in each 2311708Smckusick ** source file, which UNIX allows; however, you may (on other 2411708Smckusick ** systems) have to change everything in here to be "extern" and 2511708Smckusick ** actually allocate stuff in "externs.c" 2611708Smckusick */ 2711708Smckusick 2811708Smckusick /* external function definitions */ 2911708Smckusick extern double franf(); /* floating random number function */ 3011708Smckusick extern double sqrt(); /* square root */ 3111708Smckusick extern double sin(), cos(); /* trig functions */ 3211708Smckusick extern double atan2(); /* fancy arc tangent function */ 3311708Smckusick extern double log(); /* log base e */ 3411708Smckusick extern double pow(); /* power function */ 3511708Smckusick extern double fabs(); /* absolute value function */ 3611708Smckusick extern double exp(); /* exponential function */ 3711708Smckusick 3811708Smckusick /********************* GALAXY **************************/ 3911708Smckusick 4011708Smckusick /* galactic parameters */ 4111708Smckusick # define NSECTS 10 /* dimensions of quadrant in sectors */ 4211708Smckusick # define NQUADS 8 /* dimension of galazy in quadrants */ 4311708Smckusick # define NINHAB 32 /* number of quadrants which are inhabited */ 4411708Smckusick 4511708Smckusick struct quad /* definition for each quadrant */ 4611708Smckusick { 4711708Smckusick char bases; /* number of bases in this quadrant */ 4811708Smckusick char klings; /* number of Klingons in this quadrant */ 4911708Smckusick char holes; /* number of black holes in this quadrant */ 5011708Smckusick int scanned; /* star chart entry (see below) */ 5111708Smckusick char stars; /* number of stars in this quadrant */ 5212738Slayer char qsystemname; /* starsystem name (see below) */ 5311708Smckusick }; 5411708Smckusick 5511708Smckusick # define Q_DISTRESSED 0200 5611708Smckusick # define Q_SYSTEM 077 5711708Smckusick 5811708Smckusick /* systemname conventions: 5911708Smckusick * 1 -> NINHAB index into Systemname table for live system. 6011708Smckusick * + Q_DISTRESSED distressed starsystem -- systemname & Q_SYSTEM 6111708Smckusick * is the index into the Event table which will 6211708Smckusick * have the system name 6311708Smckusick * 0 dead or nonexistent starsystem 6411708Smckusick * 6511708Smckusick * starchart ("scanned") conventions: 6611708Smckusick * 0 -> 999 taken as is 6711708Smckusick * -1 not yet scanned ("...") 6811708Smckusick * 1000 supernova ("///") 6911708Smckusick * 1001 starbase + ??? (".1.") 7011708Smckusick */ 7111708Smckusick 7211708Smckusick /* ascii names of systems */ 7311708Smckusick extern char *Systemname[NINHAB]; 7411708Smckusick 7511708Smckusick /* quadrant definition */ 7611708Smckusick struct quad Quad[NQUADS][NQUADS]; 7711708Smckusick 7811708Smckusick /* defines for sector map (below) */ 7911708Smckusick # define EMPTY '.' 8011708Smckusick # define STAR '*' 8111708Smckusick # define BASE '#' 8211708Smckusick # define ENTERPRISE 'E' 8311708Smckusick # define QUEENE 'Q' 8411708Smckusick # define KLINGON 'K' 8511708Smckusick # define INHABIT '@' 8611708Smckusick # define HOLE ' ' 8711708Smckusick 8811708Smckusick /* current sector map */ 8911708Smckusick char Sect[NSECTS][NSECTS]; 9011708Smckusick 9111708Smckusick 9211708Smckusick /************************ DEVICES ******************************/ 9311708Smckusick 9411708Smckusick # define NDEV 16 /* max number of devices */ 9511708Smckusick 9611708Smckusick /* device tokens */ 9711708Smckusick # define WARP 0 /* warp engines */ 9811708Smckusick # define SRSCAN 1 /* short range scanners */ 9911708Smckusick # define LRSCAN 2 /* long range scanners */ 10011708Smckusick # define PHASER 3 /* phaser control */ 10111708Smckusick # define TORPED 4 /* photon torpedo control */ 10211708Smckusick # define IMPULSE 5 /* impulse engines */ 10311708Smckusick # define SHIELD 6 /* shield control */ 10411708Smckusick # define COMPUTER 7 /* on board computer */ 10511708Smckusick # define SSRADIO 8 /* subspace radio */ 10611708Smckusick # define LIFESUP 9 /* life support systems */ 10711708Smckusick # define SINS 10 /* Space Inertial Navigation System */ 10811708Smckusick # define CLOAK 11 /* cloaking device */ 10911708Smckusick # define XPORTER 12 /* transporter */ 11011708Smckusick # define SHUTTLE 13 /* shuttlecraft */ 11111708Smckusick 11211708Smckusick /* device names */ 11311708Smckusick struct device 11411708Smckusick { 11511708Smckusick char *name; /* device name */ 11611708Smckusick char *person; /* the person who fixes it */ 11711708Smckusick }; 11811708Smckusick 11911708Smckusick struct device Device[NDEV]; 12011708Smckusick 12111708Smckusick /*************************** EVENTS ****************************/ 12211708Smckusick 12311708Smckusick # define NEVENTS 12 /* number of different event types */ 12411708Smckusick 12511708Smckusick # define E_LRTB 1 /* long range tractor beam */ 12611708Smckusick # define E_KATSB 2 /* Klingon attacks starbase */ 12711708Smckusick # define E_KDESB 3 /* Klingon destroys starbase */ 12811708Smckusick # define E_ISSUE 4 /* distress call is issued */ 12911708Smckusick # define E_ENSLV 5 /* Klingons enslave a quadrant */ 13011708Smckusick # define E_REPRO 6 /* a Klingon is reproduced */ 13111708Smckusick # define E_FIXDV 7 /* fix a device */ 13211708Smckusick # define E_ATTACK 8 /* Klingon attack during rest period */ 13311708Smckusick # define E_SNAP 9 /* take a snapshot for time warp */ 13411708Smckusick # define E_SNOVA 10 /* supernova occurs */ 13511708Smckusick 13611708Smckusick # define E_GHOST 0100 /* ghost of a distress call if ssradio out */ 13711708Smckusick # define E_HIDDEN 0200 /* event that is unreportable because ssradio out */ 13811708Smckusick # define E_EVENT 077 /* mask to get event code */ 13911708Smckusick 14011708Smckusick struct event 14111708Smckusick { 14211708Smckusick char x, y; /* coordinates */ 14312738Slayer double date; /* trap stardate */ 14411708Smckusick char evcode; /* event type */ 14511708Smckusick char systemname; /* starsystem name */ 14611708Smckusick }; 14711708Smckusick /* systemname conventions: 14811708Smckusick * 1 -> NINHAB index into Systemname table for reported distress calls 14911708Smckusick * 15011708Smckusick * evcode conventions: 15111708Smckusick * 1 -> NEVENTS-1 event type 15211708Smckusick * + E_HIDDEN unreported (SSradio out) 15311708Smckusick * + E_GHOST actually already expired 15411708Smckusick * 0 unallocated 15511708Smckusick */ 15611708Smckusick 15711708Smckusick # define MAXEVENTS 25 /* max number of concurrently pending events */ 15811708Smckusick 15911708Smckusick struct event Event[MAXEVENTS]; /* dynamic event list; one entry per pending event */ 16011708Smckusick 16111708Smckusick /***************************** KLINGONS *******************************/ 16211708Smckusick 16311708Smckusick struct kling 16411708Smckusick { 16511708Smckusick char x, y; /* coordinates */ 16611708Smckusick int power; /* power left */ 16712738Slayer double dist; /* distance to Enterprise */ 16812738Slayer double avgdist; /* average over this move */ 16911708Smckusick char srndreq; /* set if surrender has been requested */ 17011708Smckusick }; 17111708Smckusick 17211708Smckusick # define MAXKLQUAD 9 /* maximum klingons per quadrant */ 17311708Smckusick 17411708Smckusick /********************** MISCELLANEOUS ***************************/ 17511708Smckusick 17611708Smckusick /* condition codes */ 17711708Smckusick # define GREEN 0 17811708Smckusick # define DOCKED 1 17911708Smckusick # define YELLOW 2 18011708Smckusick # define RED 3 18111708Smckusick 18211708Smckusick /* starbase coordinates */ 18311708Smckusick # define MAXBASES 9 /* maximum number of starbases in galaxy */ 18411708Smckusick 18511708Smckusick /* distress calls */ 18611708Smckusick # define MAXDISTR 5 /* maximum concurrent distress calls */ 18711708Smckusick 18811708Smckusick /* phaser banks */ 18911708Smckusick # define NBANKS 6 /* number of phaser banks */ 19011708Smckusick 19111708Smckusick struct xy 19211708Smckusick { 19311708Smckusick char x, y; /* coordinates */ 19411708Smckusick }; 19511708Smckusick 19611708Smckusick 19711708Smckusick /* 19811708Smckusick * note that much of the stuff in the following structs CAN NOT 19911708Smckusick * be moved around!!!! 20011708Smckusick */ 20111708Smckusick 20211708Smckusick 20311708Smckusick /* information regarding the state of the starship */ 20411708Smckusick struct 20511708Smckusick { 20612738Slayer double warp; /* warp factor */ 20712738Slayer double warp2; /* warp factor squared */ 20812738Slayer double warp3; /* warp factor cubed */ 20911708Smckusick char shldup; /* shield up flag */ 21011708Smckusick char cloaked; /* set if cloaking device on */ 21111708Smckusick int energy; /* starship's energy */ 21211708Smckusick int shield; /* energy in shields */ 21312738Slayer double reserves; /* life support reserves */ 21411708Smckusick int crew; /* ship's complement */ 21511708Smckusick int brigfree; /* space left in brig */ 21611708Smckusick char torped; /* torpedoes */ 21711708Smckusick char cloakgood; /* set if we have moved */ 21811708Smckusick int quadx; /* quadrant x coord */ 21911708Smckusick int quady; /* quadrant y coord */ 22011708Smckusick int sectx; /* sector x coord */ 22111708Smckusick int secty; /* sector y coord */ 22211708Smckusick char cond; /* condition code */ 22311708Smckusick char sinsbad; /* Space Inertial Navigation System condition */ 22411708Smckusick char *shipname; /* name of current starship */ 22511708Smckusick char ship; /* current starship */ 22634088Sbostic int distressed; /* number of distress calls */ 22711708Smckusick } Ship; 22811708Smckusick 22911708Smckusick /* sinsbad is set if SINS is working but not calibrated */ 23011708Smckusick 23111708Smckusick /* game related information, mostly scoring */ 23211708Smckusick struct 23311708Smckusick { 23411708Smckusick int killk; /* number of klingons killed */ 23511708Smckusick int deaths; /* number of deaths onboard Enterprise */ 23611708Smckusick char negenbar; /* number of hits on negative energy barrier */ 23711708Smckusick char killb; /* number of starbases killed */ 23811708Smckusick int kills; /* number of stars killed */ 23911708Smckusick char skill; /* skill rating of player */ 24011708Smckusick char length; /* length of game */ 24111708Smckusick char killed; /* set if you were killed */ 24211708Smckusick char killinhab; /* number of inhabited starsystems killed */ 24311708Smckusick char tourn; /* set if a tournament game */ 24411708Smckusick char passwd[15]; /* game password */ 24511708Smckusick char snap; /* set if snapshot taken */ 24611708Smckusick char helps; /* number of help calls */ 24711708Smckusick int captives; /* total number of captives taken */ 24811708Smckusick } Game; 24911708Smckusick 25011708Smckusick /* per move information */ 25111708Smckusick struct 25211708Smckusick { 25311708Smckusick char free; /* set if a move is free */ 25411708Smckusick char endgame; /* end of game flag */ 25511708Smckusick char shldchg; /* set if shields changed this move */ 25611708Smckusick char newquad; /* set if just entered this quadrant */ 25711708Smckusick char resting; /* set if this move is a rest */ 25812738Slayer double time; /* time used this move */ 25911708Smckusick } Move; 26011708Smckusick 26111708Smckusick /* parametric information */ 26211708Smckusick struct 26311708Smckusick { 26411708Smckusick char bases; /* number of starbases */ 26511708Smckusick char klings; /* number of klingons */ 26612738Slayer double date; /* stardate */ 26712738Slayer double time; /* time left */ 26812738Slayer double resource; /* Federation resources */ 26911708Smckusick int energy; /* starship's energy */ 27011708Smckusick int shield; /* energy in shields */ 27112738Slayer double reserves; /* life support reserves */ 27211708Smckusick int crew; /* size of ship's complement */ 27311708Smckusick int brigfree; /* max possible number of captives */ 27411708Smckusick char torped; /* photon torpedos */ 27512738Slayer double damfac[NDEV]; /* damage factor */ 27612738Slayer double dockfac; /* docked repair time factor */ 27712738Slayer double regenfac; /* regeneration factor */ 27811708Smckusick int stopengy; /* energy to do emergency stop */ 27911708Smckusick int shupengy; /* energy to put up shields */ 28011708Smckusick int klingpwr; /* Klingon initial power */ 28111708Smckusick int warptime; /* time chewer multiplier */ 28212738Slayer double phasfac; /* Klingon phaser power eater factor */ 28311708Smckusick char moveprob[6]; /* probability that a Klingon moves */ 28412738Slayer double movefac[6]; /* Klingon move distance multiplier */ 28512738Slayer double eventdly[NEVENTS]; /* event time multipliers */ 28612738Slayer double navigcrud[2]; /* navigation crudup factor */ 28711708Smckusick int cloakenergy; /* cloaking device energy per stardate */ 28812738Slayer double damprob[NDEV]; /* damage probability */ 28912738Slayer double hitfac; /* Klingon attack factor */ 29011708Smckusick int klingcrew; /* number of Klingons in a crew */ 29112738Slayer double srndrprob; /* surrender probability */ 29211708Smckusick int energylow; /* low energy mark (cond YELLOW) */ 29311708Smckusick } Param; 29411708Smckusick 29511708Smckusick /* Sum of damage probabilities must add to 1000 */ 29611708Smckusick 29711708Smckusick /* other information kept in a snapshot */ 29811708Smckusick struct 29911708Smckusick { 30011708Smckusick char bases; /* number of starbases */ 30111708Smckusick char klings; /* number of klingons */ 30212738Slayer double date; /* stardate */ 30312738Slayer double time; /* time left */ 30412738Slayer double resource; /* Federation resources */ 30511708Smckusick char distressed; /* number of currently distressed quadrants */ 30611708Smckusick struct event *eventptr[NEVENTS]; /* pointer to event structs */ 30711708Smckusick struct xy base[MAXBASES]; /* locations of starbases */ 30811708Smckusick } Now; 30911708Smckusick 31011708Smckusick /* Other stuff, not dumped in a snapshot */ 31111708Smckusick struct 31211708Smckusick { 31311708Smckusick struct kling klingon[MAXKLQUAD]; /* sorted Klingon list */ 31411708Smckusick char nkling; /* number of Klingons in this sector */ 31511708Smckusick /* < 0 means automatic override mode */ 31611708Smckusick char fast; /* set if speed > 300 baud */ 31711708Smckusick struct xy starbase; /* starbase in current quadrant */ 31811708Smckusick char snapshot[sizeof Quad + sizeof Event + sizeof Now]; /* snapshot for time warp */ 31911708Smckusick char statreport; /* set to get a status report on a srscan */ 32011708Smckusick } Etc; 32111708Smckusick 32211708Smckusick /* 32311708Smckusick * eventptr is a pointer to the event[] entry of the last 32411708Smckusick * scheduled event of each type. Zero if no such event scheduled. 32511708Smckusick */ 32611708Smckusick 32711708Smckusick /* Klingon move indicies */ 32811708Smckusick # define KM_OB 0 /* Old quadrant, Before attack */ 32911708Smckusick # define KM_OA 1 /* Old quadrant, After attack */ 33011708Smckusick # define KM_EB 2 /* Enter quadrant, Before attack */ 33111708Smckusick # define KM_EA 3 /* Enter quadrant, After attack */ 33211708Smckusick # define KM_LB 4 /* Leave quadrant, Before attack */ 33311708Smckusick # define KM_LA 5 /* Leave quadrant, After attack */ 33411708Smckusick 33511708Smckusick /* you lose codes */ 33611708Smckusick # define L_NOTIME 1 /* ran out of time */ 33711708Smckusick # define L_NOENGY 2 /* ran out of energy */ 33811708Smckusick # define L_DSTRYD 3 /* destroyed by a Klingon */ 33911708Smckusick # define L_NEGENB 4 /* ran into the negative energy barrier */ 34011708Smckusick # define L_SUICID 5 /* destroyed in a nova */ 34111708Smckusick # define L_SNOVA 6 /* destroyed in a supernova */ 34211708Smckusick # define L_NOLIFE 7 /* life support died (so did you) */ 34311708Smckusick # define L_NOHELP 8 /* you could not be rematerialized */ 34411708Smckusick # define L_TOOFAST 9 /* pretty stupid going at warp 10 */ 34511708Smckusick # define L_STAR 10 /* ran into a star */ 34611708Smckusick # define L_DSTRCT 11 /* self destructed */ 34711708Smckusick # define L_CAPTURED 12 /* captured by Klingons */ 34811708Smckusick # define L_NOCREW 13 /* you ran out of crew */ 34911708Smckusick 35011708Smckusick /****************** COMPILE OPTIONS ***********************/ 35111708Smckusick 35211708Smckusick /* Trace info */ 35311708Smckusick # define xTRACE 1 35411708Smckusick int Trace; 355