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