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