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