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. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)trek.h 8.1 (Berkeley) 5/31/93
30 * $DragonFly: src/games/trek/trek.h,v 1.2 2006/09/07 21:19:44 pavalos Exp $
41 ** Global Declarations
43 ** Virtually all non-local variable declarations are made in this
44 ** file. Exceptions are those things which are initialized, which
45 ** are defined in "externs.c", and things which are local to one
48 ** So far as I know, nothing in here must be preinitialized to
51 ** You may have problems from the loader if you move this to a
52 ** different machine. These things actually get allocated in each
53 ** source file, which UNIX allows; however, you may (on other
54 ** systems) have to change everything in here to be "extern" and
55 ** actually allocate stuff in "externs.c"
59 /********************* GALAXY **************************/
61 /* galactic parameters */
62 #define NSECTS 10 /* dimensions of quadrant in sectors */
63 #define NQUADS 8 /* dimension of galazy in quadrants */
64 #define NINHAB 32 /* number of quadrants which are inhabited */
66 /* definition for each quadrant */
68 char bases
; /* number of bases in this quadrant */
69 char klings
; /* number of Klingons in this quadrant */
70 char holes
; /* number of black holes in this quadrant */
71 int scanned
; /* star chart entry (see below) */
72 char stars
; /* number of stars in this quadrant */
73 char qsystemname
; /* starsystem name (see below) */
76 #define Q_DISTRESSED 0200
80 * systemname conventions:
81 * 1 -> NINHAB index into Systemname table for live system.
82 * + Q_DISTRESSED distressed starsystem -- systemname & Q_SYSTEM
83 * is the index into the Event table which will
84 * have the system name
85 * 0 dead or nonexistent starsystem
87 * starchart ("scanned") conventions:
88 * 0 -> 999 taken as is
89 * -1 not yet scanned ("...")
90 * 1000 supernova ("///")
91 * 1001 starbase + ??? (".1.")
94 /* ascii names of systems */
95 extern const char *Systemname
[NINHAB
];
97 /* quadrant definition */
98 struct quad Quad
[NQUADS
][NQUADS
];
100 /* defines for sector map (below) */
104 #define ENTERPRISE 'E'
110 /* current sector map */
111 char Sect
[NSECTS
][NSECTS
];
114 /************************ DEVICES ******************************/
116 #define NDEV 16 /* max number of devices */
119 #define WARP 0 /* warp engines */
120 #define SRSCAN 1 /* short range scanners */
121 #define LRSCAN 2 /* long range scanners */
122 #define PHASER 3 /* phaser control */
123 #define TORPED 4 /* photon torpedo control */
124 #define IMPULSE 5 /* impulse engines */
125 #define SHIELD 6 /* shield control */
126 #define COMPUTER 7 /* on board computer */
127 #define SSRADIO 8 /* subspace radio */
128 #define LIFESUP 9 /* life support systems */
129 #define SINS 10 /* Space Inertial Navigation System */
130 #define CLOAK 11 /* cloaking device */
131 #define XPORTER 12 /* transporter */
132 #define SHUTTLE 13 /* shuttlecraft */
136 const char *name
; /* device name */
137 const char *person
; /* the person who fixes it */
140 extern struct device Device
[NDEV
];
142 /*************************** EVENTS ****************************/
144 #define NEVENTS 12 /* number of different event types */
146 #define E_LRTB 1 /* long range tractor beam */
147 #define E_KATSB 2 /* Klingon attacks starbase */
148 #define E_KDESB 3 /* Klingon destroys starbase */
149 #define E_ISSUE 4 /* distress call is issued */
150 #define E_ENSLV 5 /* Klingons enslave a quadrant */
151 #define E_REPRO 6 /* a Klingon is reproduced */
152 #define E_FIXDV 7 /* fix a device */
153 #define E_ATTACK 8 /* Klingon attack during rest period */
154 #define E_SNAP 9 /* take a snapshot for time warp */
155 #define E_SNOVA 10 /* supernova occurs */
157 #define E_GHOST 0100 /* ghost of a distress call if ssradio out */
158 #define E_HIDDEN 0200 /* event that is unreportable because ssradio out */
159 #define E_EVENT 077 /* mask to get event code */
162 short x
, y
; /* coordinates */
163 double date
; /* trap stardate */
164 char evcode
; /* event type */
165 short systemname
; /* starsystem name */
169 * systemname conventions:
170 * 1 -> NINHAB index into Systemname table for reported distress calls
172 * evcode conventions:
173 * 1 -> NEVENTS-1 event type
174 * + E_HIDDEN unreported (SSradio out)
175 * + E_GHOST actually already expired
179 /* max number of concurrently pending events */
182 /* dynamic event list; one entry per pending event */
183 struct event Event
[MAXEVENTS
];
185 /***************************** KLINGONS *******************************/
188 short x
, y
; /* coordinates */
189 int power
; /* power left */
190 double dist
; /* distance to Enterprise */
191 double avgdist
; /* average over this move */
192 char srndreq
; /* set if surrender has been requested */
195 #define MAXKLQUAD 9 /* maximum klingons per quadrant */
197 /********************** MISCELLANEOUS ***************************/
199 /* condition codes */
205 /* starbase coordinates */
206 #define MAXBASES 9 /* maximum number of starbases in galaxy */
209 #define MAXDISTR 5 /* maximum concurrent distress calls */
212 #define NBANKS 6 /* number of phaser banks */
215 short x
, y
; /* coordinates */
220 * note that much of the stuff in the following structs CAN NOT
221 * be moved around!!!!
225 /* information regarding the state of the starship */
227 double warp
; /* warp factor */
228 double warp2
; /* warp factor squared */
229 double warp3
; /* warp factor cubed */
230 char shldup
; /* shield up flag */
231 char cloaked
; /* set if cloaking device on */
232 int energy
; /* starship's energy */
233 int shield
; /* energy in shields */
234 double reserves
; /* life support reserves */
235 int crew
; /* ship's complement */
236 int brigfree
; /* space left in brig */
237 char torped
; /* torpedoes */
238 char cloakgood
; /* set if we have moved */
239 int quadx
; /* quadrant x coord */
240 int quady
; /* quadrant y coord */
241 int sectx
; /* sector x coord */
242 int secty
; /* sector y coord */
243 short cond
; /* condition code */
244 /* sinsbad is set if SINS is working but not calibrated */
245 char sinsbad
; /* Space Inertial Navigation System condition */
246 const char *shipname
; /* name of current starship */
247 char ship
; /* current starship */
248 int distressed
; /* number of distress calls */
250 struct Ship_struct Ship
;
253 /* game related information, mostly scoring */
255 int killk
; /* number of klingons killed */
256 int deaths
; /* number of deaths onboard Enterprise */
257 char negenbar
; /* number of hits on negative energy barrier */
258 char killb
; /* number of starbases killed */
259 int kills
; /* number of stars killed */
260 char skill
; /* skill rating of player */
261 char length
; /* length of game */
262 char killed
; /* set if you were killed */
263 char killinhab
; /* number of inhabited starsystems killed */
264 char tourn
; /* set if a tournament game */
265 char passwd
[15]; /* game password */
266 char snap
; /* set if snapshot taken */
267 char helps
; /* number of help calls */
268 int captives
; /* total number of captives taken */
270 struct Game_struct Game
;
272 /* per move information */
274 char free
; /* set if a move is free */
275 char endgame
; /* end of game flag */
276 char shldchg
; /* set if shields changed this move */
277 char newquad
; /* set if just entered this quadrant */
278 char resting
; /* set if this move is a rest */
279 double time
; /* time used this move */
281 struct Move_struct Move
;
283 /* parametric information */
284 struct Param_struct
{
285 char bases
; /* number of starbases */
286 char klings
; /* number of klingons */
287 double date
; /* stardate */
288 double time
; /* time left */
289 double resource
; /* Federation resources */
290 int energy
; /* starship's energy */
291 int shield
; /* energy in shields */
292 double reserves
; /* life support reserves */
293 int crew
; /* size of ship's complement */
294 int brigfree
; /* max possible number of captives */
295 char torped
; /* photon torpedos */
296 double damfac
[NDEV
]; /* damage factor */
297 double dockfac
; /* docked repair time factor */
298 double regenfac
; /* regeneration factor */
299 int stopengy
; /* energy to do emergency stop */
300 int shupengy
; /* energy to put up shields */
301 int klingpwr
; /* Klingon initial power */
302 int warptime
; /* time chewer multiplier */
303 double phasfac
; /* Klingon phaser power eater factor */
304 char moveprob
[6]; /* probability that a Klingon moves */
305 double movefac
[6]; /* Klingon move distance multiplier */
306 double eventdly
[NEVENTS
]; /* event time multipliers */
307 double navigcrud
[2]; /* navigation crudup factor */
308 int cloakenergy
; /* cloaking device energy per stardate */
309 double damprob
[NDEV
]; /* damage probability */
310 double hitfac
; /* Klingon attack factor */
311 int klingcrew
; /* number of Klingons in a crew */
312 double srndrprob
; /* surrender probability */
313 int energylow
; /* low energy mark (cond YELLOW) */
315 struct Param_struct Param
;
317 /* Sum of damage probabilities must add to 1000 */
319 /* other information kept in a snapshot */
321 short bases
; /* number of starbases */
322 char klings
; /* number of klingons */
323 double date
; /* stardate */
324 double time
; /* time left */
325 double resource
; /* Federation resources */
326 char distressed
; /* number of currently distressed quadrants */
327 struct event
*eventptr
[NEVENTS
]; /* pointer to event structs */
328 struct xy base
[MAXBASES
]; /* locations of starbases */
330 struct Now_struct Now
;
332 /* Other stuff, not dumped in a snapshot */
334 struct kling klingon
[MAXKLQUAD
];/* sorted Klingon list */
335 int nkling
; /* number of Klingons in this sector */
336 /* < 0 means automatic override mode */
337 struct xy starbase
; /* starbase in current quadrant */
338 char snapshot
[sizeof Quad
+ sizeof Event
+ sizeof Now
];
339 /* snapshot for time warp */
340 char statreport
; /* set to get a status report on a srscan */
342 struct Etc_struct Etc
;
345 * eventptr is a pointer to the event[] entry of the last
346 * scheduled event of each type. Zero if no such event scheduled.
349 /* Klingon move indicies */
350 #define KM_OB 0 /* Old quadrant, Before attack */
351 #define KM_OA 1 /* Old quadrant, After attack */
352 #define KM_EB 2 /* Enter quadrant, Before attack */
353 #define KM_EA 3 /* Enter quadrant, After attack */
354 #define KM_LB 4 /* Leave quadrant, Before attack */
355 #define KM_LA 5 /* Leave quadrant, After attack */
358 #define L_NOTIME 1 /* ran out of time */
359 #define L_NOENGY 2 /* ran out of energy */
360 #define L_DSTRYD 3 /* destroyed by a Klingon */
361 #define L_NEGENB 4 /* ran into the negative energy barrier */
362 #define L_SUICID 5 /* destroyed in a nova */
363 #define L_SNOVA 6 /* destroyed in a supernova */
364 #define L_NOLIFE 7 /* life support died (so did you) */
365 #define L_NOHELP 8 /* you could not be rematerialized */
366 #define L_TOOFAST 9 /* pretty stupid going at warp 10 */
367 #define L_STAR 10 /* ran into a star */
368 #define L_DSTRCT 11 /* self destructed */
369 #define L_CAPTURED 12 /* captured by Klingons */
370 #define L_NOCREW 13 /* you ran out of crew */
372 /****************** COMPILE OPTIONS ***********************/
378 #define TOOLARGE (1e50) /* FIXME, make this DBL_MAX/2 for portability */
380 /* external function definitions */
387 void checkcond(void);
388 void compkldist(bool);
390 void damage(int, double);
397 bool restartgame(void);
399 int dumpssradio(void);
401 bool getcodi(int *, double *);
405 void sector(int *, int *);
406 void killk(int, int);
407 void killb(int, int);
408 void kills(int, int, int);
409 void killd(int, int, int);
413 double move(int, int, double, double);
422 struct event
*schedule(int, double, char, char, char);
423 void reschedule(struct event
*, double);
424 void unschedule(struct event
*);
425 struct event
*xsched(int, int, int, int, int);
426 void xresched(struct event
*, int, int);
431 void snova(int, int);
433 const char *systemname(struct quad
*);
435 char *bmove(const void *, void *, size_t);
436 bool sequal(const char *, const char *);
437 void syserr(const char *, ...) __printflike(1, 2);
439 void warp(int, int, double);