trek.h 15 KB

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