hammer viconfig: remove 2nd 'rebalance'
[dragonfly.git] / games / trek / trek.h
bloba981fe50fc2d4591ea1404017c6c4bdfe1c1b830
1 /*
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
7 * are met:
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
31 * SUCH DAMAGE.
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 $
37 #include <math.h>
38 #include <setjmp.h>
39 #include <stdbool.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include <unistd.h>
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
50 ** program file.
52 ** So far as I know, nothing in here must be preinitialized to
53 ** zero.
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"
62 extern jmp_buf env;
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
81 # define Q_SYSTEM 077
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) */
104 # define EMPTY '.'
105 # define STAR '*'
106 # define BASE '#'
107 # define ENTERPRISE 'E'
108 # define QUEENE 'Q'
109 # define KLINGON 'K'
110 # define INHABIT '@'
111 # define HOLE ' '
113 /* current sector map */
114 char Sect[NSECTS][NSECTS];
117 /************************ DEVICES ******************************/
119 # define NDEV 16 /* max number of devices */
121 /* device tokens */
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 */
137 /* device names */
138 struct device
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 */
165 struct event
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
179 * 0 unallocated
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 *******************************/
188 struct kling
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 */
202 # define GREEN 0
203 # define DOCKED 1
204 # define YELLOW 2
205 # define RED 3
207 /* starbase coordinates */
208 # define MAXBASES 9 /* maximum number of starbases in galaxy */
210 /* distress calls */
211 # define MAXDISTR 5 /* maximum concurrent distress calls */
213 /* phaser banks */
214 # define NBANKS 6 /* number of phaser banks */
216 struct xy
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 */
229 struct
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 */
252 } Ship;
254 /* sinsbad is set if SINS is working but not calibrated */
256 /* game related information, mostly scoring */
257 struct
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 */
273 } Game;
275 /* per move information */
276 struct
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 */
284 } Move;
286 /* parametric information */
287 struct
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) */
318 } Param;
320 /* Sum of damage probabilities must add to 1000 */
322 /* other information kept in a snapshot */
323 struct
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 */
333 } Now;
335 /* Other stuff, not dumped in a snapshot */
336 struct
338 struct kling klingon[MAXKLQUAD]; /* sorted Klingon list */
339 int nkling; /* number of Klingons in this sector */
340 /* < 0 means automatic override mode */
341 struct xy starbase; /* starbase in current quadrant */
342 char snapshot[sizeof Quad + sizeof Event + sizeof Now]; /* snapshot for time warp */
343 char statreport; /* set to get a status report on a srscan */
344 } Etc;
347 * eventptr is a pointer to the event[] entry of the last
348 * scheduled event of each type. Zero if no such event scheduled.
351 /* Klingon move indicies */
352 # define KM_OB 0 /* Old quadrant, Before attack */
353 # define KM_OA 1 /* Old quadrant, After attack */
354 # define KM_EB 2 /* Enter quadrant, Before attack */
355 # define KM_EA 3 /* Enter quadrant, After attack */
356 # define KM_LB 4 /* Leave quadrant, Before attack */
357 # define KM_LA 5 /* Leave quadrant, After attack */
359 /* you lose codes */
360 # define L_NOTIME 1 /* ran out of time */
361 # define L_NOENGY 2 /* ran out of energy */
362 # define L_DSTRYD 3 /* destroyed by a Klingon */
363 # define L_NEGENB 4 /* ran into the negative energy barrier */
364 # define L_SUICID 5 /* destroyed in a nova */
365 # define L_SNOVA 6 /* destroyed in a supernova */
366 # define L_NOLIFE 7 /* life support died (so did you) */
367 # define L_NOHELP 8 /* you could not be rematerialized */
368 # define L_TOOFAST 9 /* pretty stupid going at warp 10 */
369 # define L_STAR 10 /* ran into a star */
370 # define L_DSTRCT 11 /* self destructed */
371 # define L_CAPTURED 12 /* captured by Klingons */
372 # define L_NOCREW 13 /* you ran out of crew */
374 /****************** COMPILE OPTIONS ***********************/
376 /* Trace info */
377 # define xTRACE 1
378 int Trace;
380 /* external function definitions */
381 void abandon(int);
382 void attack(int);
383 void autover(void);
384 void capture(int);
385 int cgetc(int);
386 bool check_out(int);
387 void checkcond(void);
388 void compkldist(bool);
389 void computer(int);
390 void damage(int, double);
391 bool damaged(int);
392 void dcrept(int);
393 void destruct(int);
394 void dock(int);
395 void undock(int);
396 void dumpgame(int);
397 bool restartgame(void);
398 void dumpme(int);
399 int dumpssradio(void);
400 void events(int);
401 bool getcodi(int *, double *);
402 void help(int);
403 void impulse(int);
404 void initquad(int);
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);
410 void klmove(int);
411 void lose(int);
412 void lrscan(int);
413 double move(int, int, double, double);
414 void nova(int, int);
415 void out(int);
416 void phaser(int);
417 void play(void);
418 void ram(int, int);
419 int ranf(int);
420 double franf(void);
421 void rest(int);
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);
427 long score(void);
428 void setup(void);
429 void setwarp(int);
430 void shield(int);
431 void snova(int, int);
432 void srscan(int);
433 const char *systemname(struct quad *);
434 void torped(int);
435 char *bmove(const void *, void *, size_t);
436 bool sequal(const char *, const char *);
437 void syserr(const char *, ...);
438 void visual(int);
439 void warp(int, int, double);
440 void dowarp(int);
441 void win(void);