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