home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / games / trek / trek.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-08  |  12.9 KB  |  381 lines

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