1 /* $NetBSD: trek.h,v 1.17 2009/05/25 00:07:14 dholland Exp $ */
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
31 * @(#)trek.h 8.1 (Berkeley) 5/31/93
35 ** Global Declarations
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
42 ** So far as I know, nothing in here must be preinitialized to
46 /* external function definitions */
48 /********************* GALAXY **************************/
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 */
55 /* definition for each quadrant */
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) */
65 #define Q_DISTRESSED 0200
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
76 * starchart ("scanned") conventions:
77 * 0 -> 999 taken as is
78 * -1 not yet scanned ("...")
79 * 1000 supernova ("///")
80 * 1001 starbase + ??? (".1.")
83 /* ascii names of systems */
84 extern const char *const Systemname
[NINHAB
];
86 /* quadrant definition */
87 extern struct quad Quad
[NQUADS
][NQUADS
];
89 /* defines for sector map (below) */
93 #define ENTERPRISE 'E'
99 /* current sector map */
100 extern char Sect
[NSECTS
][NSECTS
];
104 /************************ DEVICES ******************************/
106 #define NDEV 16 /* max number of devices */
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 */
126 const char *name
; /* device name */
127 const char *person
; /* the person who fixes it */
130 extern const struct device Device
[NDEV
];
132 /*************************** EVENTS ****************************/
134 #define NEVENTS 12 /* number of different event types */
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 */
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 */
152 unsigned char x
, y
; /* coordinates */
153 double date
; /* trap stardate */
154 char evcode
; /* event type */
155 unsigned char systemname
; /* starsystem name */
159 * systemname conventions:
160 * 1 -> NINHAB index into Systemname table for reported distress calls
162 * evcode conventions:
163 * 1 -> NEVENTS-1 event type
164 * + E_HIDDEN unreported (SSradio out)
165 * + E_GHOST actually already expired
169 /* max number of concurrently pending events */
172 /* dynamic event list; one entry per pending event */
173 extern struct event Event
[MAXEVENTS
];
175 /***************************** KLINGONS *******************************/
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 */
185 #define MAXKLQUAD 9 /* maximum klingons per quadrant */
187 /********************** MISCELLANEOUS ***************************/
189 /* condition codes */
195 /* starbase coordinates */
196 #define MAXBASES 9 /* maximum number of starbases in galaxy */
199 #define MAXDISTR 5 /* maximum concurrent distress calls */
202 #define NBANKS 6 /* number of phaser banks */
205 unsigned char x
, y
; /* coordinates */
210 * note that much of the stuff in the following structs CAN NOT
211 * be moved around!!!!
215 /* information regarding the state of the starship */
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 */
240 extern struct Ship_struct Ship
;
243 /* game related information, mostly scoring */
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 */
260 extern struct Game_struct Game
;
262 /* per move information */
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 */
271 extern struct Move_struct Move
;
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) */
305 extern struct Param_struct Param
;
307 /* Sum of damage probabilities must add to 1000 */
309 /* other information kept in a snapshot */
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 */
320 extern struct Now_struct Now
;
322 /* Other stuff, not dumped in a snapshot */
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 */
333 extern struct Etc_struct Etc
;
336 * eventptr is a pointer to the event[] entry of the last
337 * scheduled event of each type. Zero if no such event scheduled.
340 /* Klingon move indicies */
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 */
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 */
363 /****************** COMPILE OPTIONS ***********************/
369 #define TOOLARGE (DBL_MAX / 2) /* < DOUBLE_MAX for everyone */
387 void checkcond(void);
390 void compkldist(int);
396 void damage(int, double);
413 int restartgame(void);
419 int dumpssradio(void);
427 int getcodi(int *, double *);
437 void sector(int *, int *);
440 void killk(int, int );
441 void killb(int, int );
442 void kills(int, int , int);
443 void killd(int, int , int);
449 void lose(int) __dead
;
455 double move(int, int, double, double);
458 void nova(int, int );
467 void play(void) __dead
;
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);
499 void snova(int, int );
505 const char *systemname(const struct quad
*);
515 void warp(int, int, double);
518 void win(void) __dead
;