2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
33 * @(#)trek.h 8.1 (Berkeley) 5/31/93
34 * $DragonFly: src/games/trek/trek.h,v 1.2 2006/09/07 21:19:44 pavalos Exp $
45 ** Global Declarations
47 ** Virtually all non-local variable declarations are made in this
48 ** file. Exceptions are those things which are initialized, which
49 ** are defined in "externs.c", and things which are local to one
52 ** So far as I know, nothing in here must be preinitialized to
55 ** You may have problems from the loader if you move this to a
56 ** different machine. These things actually get allocated in each
57 ** source file, which UNIX allows; however, you may (on other
58 ** systems) have to change everything in here to be "extern" and
59 ** actually allocate stuff in "externs.c"
63 /********************* GALAXY **************************/
65 /* galactic parameters */
66 # define NSECTS 10 /* dimensions of quadrant in sectors */
67 # define NQUADS 8 /* dimension of galazy in quadrants */
68 # define NINHAB 32 /* number of quadrants which are inhabited */
70 struct quad
/* definition for each quadrant */
72 char bases
; /* number of bases in this quadrant */
73 char klings
; /* number of Klingons in this quadrant */
74 char holes
; /* number of black holes in this quadrant */
75 int scanned
; /* star chart entry (see below) */
76 char stars
; /* number of stars in this quadrant */
77 char qsystemname
; /* starsystem name (see below) */
80 # define Q_DISTRESSED 0200
83 /* systemname conventions:
84 * 1 -> NINHAB index into Systemname table for live system.
85 * + Q_DISTRESSED distressed starsystem -- systemname & Q_SYSTEM
86 * is the index into the Event table which will
87 * have the system name
88 * 0 dead or nonexistent starsystem
90 * starchart ("scanned") conventions:
91 * 0 -> 999 taken as is
92 * -1 not yet scanned ("...")
93 * 1000 supernova ("///")
94 * 1001 starbase + ??? (".1.")
97 /* ascii names of systems */
98 extern const char *Systemname
[NINHAB
];
100 /* quadrant definition */
101 struct quad Quad
[NQUADS
][NQUADS
];
103 /* defines for sector map (below) */
107 # define ENTERPRISE 'E'
113 /* current sector map */
114 char Sect
[NSECTS
][NSECTS
];
117 /************************ DEVICES ******************************/
119 # define NDEV 16 /* max number of devices */
122 # define WARP 0 /* warp engines */
123 # define SRSCAN 1 /* short range scanners */
124 # define LRSCAN 2 /* long range scanners */
125 # define PHASER 3 /* phaser control */
126 # define TORPED 4 /* photon torpedo control */
127 # define IMPULSE 5 /* impulse engines */
128 # define SHIELD 6 /* shield control */
129 # define COMPUTER 7 /* on board computer */
130 # define SSRADIO 8 /* subspace radio */
131 # define LIFESUP 9 /* life support systems */
132 # define SINS 10 /* Space Inertial Navigation System */
133 # define CLOAK 11 /* cloaking device */
134 # define XPORTER 12 /* transporter */
135 # define SHUTTLE 13 /* shuttlecraft */
140 const char *name
; /* device name */
141 const char *person
; /* the person who fixes it */
144 extern struct device Device
[NDEV
];
146 /*************************** EVENTS ****************************/
148 # define NEVENTS 12 /* number of different event types */
150 # define E_LRTB 1 /* long range tractor beam */
151 # define E_KATSB 2 /* Klingon attacks starbase */
152 # define E_KDESB 3 /* Klingon destroys starbase */
153 # define E_ISSUE 4 /* distress call is issued */
154 # define E_ENSLV 5 /* Klingons enslave a quadrant */
155 # define E_REPRO 6 /* a Klingon is reproduced */
156 # define E_FIXDV 7 /* fix a device */
157 # define E_ATTACK 8 /* Klingon attack during rest period */
158 # define E_SNAP 9 /* take a snapshot for time warp */
159 # define E_SNOVA 10 /* supernova occurs */
161 # define E_GHOST 0100 /* ghost of a distress call if ssradio out */
162 # define E_HIDDEN 0200 /* event that is unreportable because ssradio out */
163 # define E_EVENT 077 /* mask to get event code */
167 short x
, y
; /* coordinates */
168 double date
; /* trap stardate */
169 char evcode
; /* event type */
170 short systemname
; /* starsystem name */
172 /* systemname conventions:
173 * 1 -> NINHAB index into Systemname table for reported distress calls
175 * evcode conventions:
176 * 1 -> NEVENTS-1 event type
177 * + E_HIDDEN unreported (SSradio out)
178 * + E_GHOST actually already expired
182 # define MAXEVENTS 25 /* max number of concurrently pending events */
184 struct event Event
[MAXEVENTS
]; /* dynamic event list; one entry per pending event */
186 /***************************** KLINGONS *******************************/
190 short x
, y
; /* coordinates */
191 int power
; /* power left */
192 double dist
; /* distance to Enterprise */
193 double avgdist
; /* average over this move */
194 char srndreq
; /* set if surrender has been requested */
197 # define MAXKLQUAD 9 /* maximum klingons per quadrant */
199 /********************** MISCELLANEOUS ***************************/
201 /* condition codes */
207 /* starbase coordinates */
208 # define MAXBASES 9 /* maximum number of starbases in galaxy */
211 # define MAXDISTR 5 /* maximum concurrent distress calls */
214 # define NBANKS 6 /* number of phaser banks */
218 short x
, y
; /* coordinates */
223 * note that much of the stuff in the following structs CAN NOT
224 * be moved around!!!!
228 /* information regarding the state of the starship */
231 double warp
; /* warp factor */
232 double warp2
; /* warp factor squared */
233 double warp3
; /* warp factor cubed */
234 char shldup
; /* shield up flag */
235 char cloaked
; /* set if cloaking device on */
236 int energy
; /* starship's energy */
237 int shield
; /* energy in shields */
238 double reserves
; /* life support reserves */
239 int crew
; /* ship's complement */
240 int brigfree
; /* space left in brig */
241 char torped
; /* torpedoes */
242 char cloakgood
; /* set if we have moved */
243 int quadx
; /* quadrant x coord */
244 int quady
; /* quadrant y coord */
245 int sectx
; /* sector x coord */
246 int secty
; /* sector y coord */
247 short cond
; /* condition code */
248 char sinsbad
; /* Space Inertial Navigation System condition */
249 const char *shipname
; /* name of current starship */
250 char ship
; /* current starship */
251 int distressed
; /* number of distress calls */
254 /* sinsbad is set if SINS is working but not calibrated */
256 /* game related information, mostly scoring */
259 int killk
; /* number of klingons killed */
260 int deaths
; /* number of deaths onboard Enterprise */
261 char negenbar
; /* number of hits on negative energy barrier */
262 char killb
; /* number of starbases killed */
263 int kills
; /* number of stars killed */
264 char skill
; /* skill rating of player */
265 char length
; /* length of game */
266 char killed
; /* set if you were killed */
267 char killinhab
; /* number of inhabited starsystems killed */
268 char tourn
; /* set if a tournament game */
269 char passwd
[15]; /* game password */
270 char snap
; /* set if snapshot taken */
271 char helps
; /* number of help calls */
272 int captives
; /* total number of captives taken */
275 /* per move information */
278 char free
; /* set if a move is free */
279 char endgame
; /* end of game flag */
280 char shldchg
; /* set if shields changed this move */
281 char newquad
; /* set if just entered this quadrant */
282 char resting
; /* set if this move is a rest */
283 double time
; /* time used this move */
286 /* parametric information */
289 char bases
; /* number of starbases */
290 char klings
; /* number of klingons */
291 double date
; /* stardate */
292 double time
; /* time left */
293 double resource
; /* Federation resources */
294 int energy
; /* starship's energy */
295 int shield
; /* energy in shields */
296 double reserves
; /* life support reserves */
297 int crew
; /* size of ship's complement */
298 int brigfree
; /* max possible number of captives */
299 char torped
; /* photon torpedos */
300 double damfac
[NDEV
]; /* damage factor */
301 double dockfac
; /* docked repair time factor */
302 double regenfac
; /* regeneration factor */
303 int stopengy
; /* energy to do emergency stop */
304 int shupengy
; /* energy to put up shields */
305 int klingpwr
; /* Klingon initial power */
306 int warptime
; /* time chewer multiplier */
307 double phasfac
; /* Klingon phaser power eater factor */
308 char moveprob
[6]; /* probability that a Klingon moves */
309 double movefac
[6]; /* Klingon move distance multiplier */
310 double eventdly
[NEVENTS
]; /* event time multipliers */
311 double navigcrud
[2]; /* navigation crudup factor */
312 int cloakenergy
; /* cloaking device energy per stardate */
313 double damprob
[NDEV
]; /* damage probability */
314 double hitfac
; /* Klingon attack factor */
315 int klingcrew
; /* number of Klingons in a crew */
316 double srndrprob
; /* surrender probability */
317 int energylow
; /* low energy mark (cond YELLOW) */
320 /* Sum of damage probabilities must add to 1000 */
322 /* other information kept in a snapshot */
325 short bases
; /* number of starbases */
326 char klings
; /* number of klingons */
327 double date
; /* stardate */
328 double time
; /* time left */
329 double resource
; /* Federation resources */
330 char distressed
; /* number of currently distressed quadrants */
331 struct event
*eventptr
[NEVENTS
]; /* pointer to event structs */
332 struct xy base
[MAXBASES
]; /* locations of starbases */
335 /* Other stuff, not dumped in a snapshot */
338 struct kling klingon
[MAXKLQUAD
]; /* sorted Klingon list */
339 int nkling
; /* number of Klingons in this sector */
340 /* < 0 means automatic override mode */
341 char fast
; /* set if speed > 300 baud */
342 struct xy starbase
; /* starbase in current quadrant */
343 char snapshot
[sizeof Quad
+ sizeof Event
+ sizeof Now
]; /* snapshot for time warp */
344 char statreport
; /* set to get a status report on a srscan */
348 * eventptr is a pointer to the event[] entry of the last
349 * scheduled event of each type. Zero if no such event scheduled.
352 /* Klingon move indicies */
353 # define KM_OB 0 /* Old quadrant, Before attack */
354 # define KM_OA 1 /* Old quadrant, After attack */
355 # define KM_EB 2 /* Enter quadrant, Before attack */
356 # define KM_EA 3 /* Enter quadrant, After attack */
357 # define KM_LB 4 /* Leave quadrant, Before attack */
358 # define KM_LA 5 /* Leave quadrant, After attack */
361 # define L_NOTIME 1 /* ran out of time */
362 # define L_NOENGY 2 /* ran out of energy */
363 # define L_DSTRYD 3 /* destroyed by a Klingon */
364 # define L_NEGENB 4 /* ran into the negative energy barrier */
365 # define L_SUICID 5 /* destroyed in a nova */
366 # define L_SNOVA 6 /* destroyed in a supernova */
367 # define L_NOLIFE 7 /* life support died (so did you) */
368 # define L_NOHELP 8 /* you could not be rematerialized */
369 # define L_TOOFAST 9 /* pretty stupid going at warp 10 */
370 # define L_STAR 10 /* ran into a star */
371 # define L_DSTRCT 11 /* self destructed */
372 # define L_CAPTURED 12 /* captured by Klingons */
373 # define L_NOCREW 13 /* you ran out of crew */
375 /****************** COMPILE OPTIONS ***********************/
381 /* external function definitions */
388 void checkcond(void);
389 void compkldist(bool);
391 void damage(int, double);
398 bool restartgame(void);
400 int dumpssradio(void);
402 bool getcodi(int *, double *);
406 void sector(int *, int *);
407 void killk(int, int);
408 void killb(int, int);
409 void kills(int, int, int);
410 void killd(int, int, int);
414 double move(int, int, double, double);
423 struct event
*schedule(int, double, char, char, char);
424 void reschedule(struct event
*, double);
425 void unschedule(struct event
*);
426 struct event
*xsched(int, int, int, int, int);
427 void xresched(struct event
*, int, int);
432 void snova(int, int);
434 const char *systemname(struct quad
*);
436 char *bmove(const void *, void *, size_t);
437 bool sequal(const char *, const char *);
438 void syserr(const char *, ...);
440 void warp(int, int, double);