xref: /netbsd/games/trek/trek.h (revision bf9ec67e)
1 /*	$NetBSD: trek.h,v 1.8 1999/09/17 17:06:08 jsm 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. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  *	@(#)trek.h	8.1 (Berkeley) 5/31/93
36  */
37 
38 /*
39 **  Global Declarations
40 **
41 **	Virtually all non-local variable declarations are made in this
42 **	file.  Exceptions are those things which are initialized, which
43 **	are defined in "externs.c", and things which are local to one
44 **	program file.
45 **
46 **	So far as I know, nothing in here must be preinitialized to
47 **	zero.
48 */
49 
50 /* external function definitions */
51 
52 /*********************  GALAXY  **************************/
53 
54 /* galactic parameters */
55 # define	NSECTS		10	/* dimensions of quadrant in sectors */
56 # define	NQUADS		8	/* dimension of galazy in quadrants */
57 # define	NINHAB		32	/* number of quadrants which are inhabited */
58 
59 struct quad		/* definition for each quadrant */
60 {
61 	unsigned char	bases;	/* number of bases in this quadrant */
62 	char	klings;		/* number of Klingons in this quadrant */
63 	char	holes;		/* number of black holes in this quadrant */
64 	int	scanned;	/* star chart entry (see below) */
65 	short	stars;		/* number of stars in this quadrant */
66 	char	qsystemname;	/* starsystem name (see below) */
67 };
68 
69 # define	Q_DISTRESSED	0200
70 # define	Q_SYSTEM	077
71 
72 /*  systemname conventions:
73  *	1 -> NINHAB	index into Systemname table for live system.
74  *	+ Q_DISTRESSED	distressed starsystem -- systemname & Q_SYSTEM
75  *			is the index into the Event table which will
76  *			have the system name
77  *	0		dead or nonexistent starsystem
78  *
79  *  starchart ("scanned") conventions:
80  *	0 -> 999	taken as is
81  *	-1		not yet scanned ("...")
82  *	1000		supernova ("///")
83  *	1001		starbase + ??? (".1.")
84 */
85 
86 /* ascii names of systems */
87 extern const char	*const Systemname[NINHAB];
88 
89 /* quadrant definition */
90 extern struct quad	Quad[NQUADS][NQUADS];
91 
92 /* defines for sector map  (below) */
93 # define	EMPTY		'.'
94 # define	STAR		'*'
95 # define	BASE		'#'
96 # define	ENTERPRISE	'E'
97 # define	QUEENE		'Q'
98 # define	KLINGON		'K'
99 # define	INHABIT		'@'
100 # define	HOLE		' '
101 
102 /* current sector map */
103 extern char	Sect[NSECTS][NSECTS];
104 
105 
106 
107 /************************ DEVICES ******************************/
108 
109 # define	NDEV		16	/* max number of devices */
110 
111 /* device tokens */
112 # define	WARP		0	/* warp engines */
113 # define	SRSCAN		1	/* short range scanners */
114 # define	LRSCAN		2	/* long range scanners */
115 # define	PHASER		3	/* phaser control */
116 # define	TORPED		4	/* photon torpedo control */
117 # define	IMPULSE		5	/* impulse engines */
118 # define	SHIELD		6	/* shield control */
119 # define	COMPUTER	7	/* on board computer */
120 # define	SSRADIO		8	/* subspace radio */
121 # define	LIFESUP		9	/* life support systems */
122 # define	SINS		10	/* Space Inertial Navigation System */
123 # define	CLOAK		11	/* cloaking device */
124 # define	XPORTER		12	/* transporter */
125 # define	SHUTTLE		13	/* shuttlecraft */
126 
127 /* device names */
128 struct device
129 {
130 	const char	*name;		/* device name */
131 	const char	*person;	/* the person who fixes it */
132 };
133 
134 extern const struct device	Device[NDEV];
135 
136 /***************************  EVENTS  ****************************/
137 
138 # define	NEVENTS		12	/* number of different event types */
139 
140 # define	E_LRTB		1	/* long range tractor beam */
141 # define	E_KATSB		2	/* Klingon attacks starbase */
142 # define	E_KDESB		3	/* Klingon destroys starbase */
143 # define	E_ISSUE		4	/* distress call is issued */
144 # define	E_ENSLV		5	/* Klingons enslave a quadrant */
145 # define	E_REPRO		6	/* a Klingon is reproduced */
146 # define	E_FIXDV		7	/* fix a device */
147 # define	E_ATTACK	8	/* Klingon attack during rest period */
148 # define	E_SNAP		9	/* take a snapshot for time warp */
149 # define	E_SNOVA		10	/* supernova occurs */
150 
151 # define	E_GHOST		0100	/* ghost of a distress call if ssradio out */
152 # define	E_HIDDEN	0200	/* event that is unreportable because ssradio out */
153 # define	E_EVENT		077	/* mask to get event code */
154 
155 struct event
156 {
157 	unsigned char 	x, y;		/* coordinates */
158 	double		date;		/* trap stardate */
159 	char		evcode;		/* event type */
160 	unsigned char	systemname;	/* starsystem name */
161 };
162 /* systemname conventions:
163  *	1 -> NINHAB	index into Systemname table for reported distress calls
164  *
165  * evcode conventions:
166  *	1 -> NEVENTS-1	event type
167  *	+ E_HIDDEN	unreported (SSradio out)
168  *	+ E_GHOST	actually already expired
169  *	0		unallocated
170  */
171 
172 # define	MAXEVENTS	25	/* max number of concurrently pending events */
173 
174 extern struct event	Event[MAXEVENTS];	/* dynamic event list; one entry per pending event */
175 
176 /*****************************  KLINGONS  *******************************/
177 
178 struct kling
179 {
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 {
208 	unsigned char	x, y;		/* coordinates */
209 };
210 
211 
212 extern const struct cvntab	Skitab[];
213 extern const struct cvntab	Lentab[];
214 
215 /*
216  *	note that much of the stuff in the following structs CAN NOT
217  *	be moved around!!!!
218  */
219 
220 
221 /* information regarding the state of the starship */
222 struct Ship_struct
223 {
224 	double	warp;		/* warp factor */
225 	double	warp2;		/* warp factor squared */
226 	double	warp3;		/* warp factor cubed */
227 	char	shldup;		/* shield up flag */
228 	char	cloaked;	/* set if cloaking device on */
229 	int	energy;		/* starship's energy */
230 	int	shield;		/* energy in shields */
231 	double	reserves;	/* life support reserves */
232 	int	crew;		/* ship's complement */
233 	int	brigfree;	/* space left in brig */
234 	char	torped;		/* torpedoes */
235 	char	cloakgood;	/* set if we have moved */
236 	int	quadx;		/* quadrant x coord */
237 	int	quady;		/* quadrant y coord */
238 	int	sectx;		/* sector x coord */
239 	int	secty;		/* sector y coord */
240 	unsigned char	cond;	/* condition code */
241 	char	sinsbad;	/* Space Inertial Navigation System condition */
242 	const char *shipname;	/* name of current starship */
243 	char	ship;		/* current starship */
244 	int	distressed;	/* number of distress calls */
245 };
246 extern struct Ship_struct Ship;
247 
248 /* sinsbad is set if SINS is working but not calibrated */
249 
250 /* game related information, mostly scoring */
251 struct Game_struct
252 {
253 	int	killk;		/* number of klingons killed */
254 	int	deaths;		/* number of deaths onboard Enterprise */
255 	char	negenbar;	/* number of hits on negative energy barrier */
256 	char	killb;		/* number of starbases killed */
257 	int	kills;		/* number of stars killed */
258 	char	skill;		/* skill rating of player */
259 	char	length;		/* length of game */
260 	char	killed;		/* set if you were killed */
261 	char	killinhab;	/* number of inhabited starsystems killed */
262 	char	tourn;		/* set if a tournament game */
263 	char	passwd[15];	/* game password */
264 	char	snap;		/* set if snapshot taken */
265 	char	helps;		/* number of help calls */
266 	int	captives;	/* total number of captives taken */
267 };
268 extern struct Game_struct Game;
269 
270 /* per move information */
271 struct Move_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 };
280 extern struct Move_struct Move;
281 
282 /* parametric information */
283 struct Param_struct
284 {
285 	unsigned 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) */
314 };
315 extern struct Param_struct Param;
316 
317 /* Sum of damage probabilities must add to 1000 */
318 
319 /* other information kept in a snapshot */
320 struct Now_struct
321 {
322 	unsigned char	bases;	/* number of starbases */
323 	char	klings;		/* number of klingons */
324 	double	date;		/* stardate */
325 	double	time;		/* time left */
326 	double	resource;	/* Federation resources */
327 	char	distressed;	/* number of currently distressed quadrants */
328 	struct event	*eventptr[NEVENTS];	/* pointer to event structs */
329 	struct xy	base[MAXBASES];		/* locations of starbases */
330 };
331 extern struct Now_struct Now;
332 
333 /* Other stuff, not dumped in a snapshot */
334 struct Etc_struct
335 {
336 	struct kling	klingon[MAXKLQUAD];	/* sorted Klingon list */
337 	short		nkling;			/* number of Klingons in this sector */
338 						/* < 0 means automatic override mode */
339 	char		fast;			/* set if speed > 300 baud */
340 	struct xy	starbase;	/* starbase in current quadrant */
341 	char		snapshot[sizeof Quad + sizeof Event + sizeof Now];	/* snapshot for time warp */
342 	char		statreport;		/* set to get a status report on a srscan */
343 };
344 extern struct Etc_struct Etc;
345 
346 /*
347  *	eventptr is a pointer to the event[] entry of the last
348  *	scheduled event of each type.  Zero if no such event scheduled.
349  */
350 
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 */
358 
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 */
373 
374 /******************  COMPILE OPTIONS  ***********************/
375 
376 /* Trace info */
377 # define	xTRACE		1
378 extern int	Trace;
379 
380 /* abandon.c */
381 void abandon __P((int));
382 
383 /* attack.c */
384 void attack __P((int));
385 
386 /* autover.c */
387 void autover __P((void));
388 
389 /* capture.c */
390 void capture __P((int));
391 struct kling *selectklingon __P((void));
392 
393 /* cgetc.c */
394 char cgetc __P((int));
395 
396 /* check_out.c */
397 int check_out __P((int));
398 
399 /* checkcond.c */
400 void checkcond __P((void));
401 
402 /* compkl.c */
403 void compkldist __P((int));
404 
405 /* computer.c */
406 void computer __P((int));
407 
408 /* damage.c */
409 void damage __P((int, double));
410 
411 /* damaged.c */
412 int damaged __P((int));
413 
414 /* dcrept.c */
415 void dcrept __P((int));
416 
417 /* destruct.c */
418 void destruct __P((int));
419 
420 /* dock.c */
421 void dock __P((int));
422 void undock __P((int));
423 
424 /* dumpgame.c */
425 void dumpgame __P((int));
426 int restartgame __P((void));
427 
428 /* dumpme.c */
429 void dumpme __P((int));
430 
431 /* dumpssradio.c */
432 int dumpssradio __P((void));
433 
434 /* events.c */
435 int events __P((int));
436 
437 /* externs.c */
438 
439 /* getcodi.c */
440 int getcodi __P((int *, double *));
441 
442 /* help.c */
443 void help __P((int));
444 
445 /* impulse.c */
446 void impulse __P((int));
447 
448 /* initquad.c */
449 void initquad __P((int));
450 void sector __P((int *, int *));
451 
452 /* kill.c */
453 void killk __P((int, int ));
454 void killb __P((int, int ));
455 void kills __P((int, int , int));
456 void killd __P((int, int , int));
457 
458 /* klmove.c */
459 void klmove __P((int));
460 
461 /* lose.c */
462 void lose __P((int)) __attribute__((__noreturn__));
463 
464 /* lrscan.c */
465 void lrscan __P((int));
466 
467 /* move.c */
468 double move __P((int, int, double, double));
469 
470 /* nova.c */
471 void nova __P((int, int ));
472 
473 /* out.c */
474 void out __P((int));
475 
476 /* phaser.c */
477 void phaser __P((int));
478 
479 /* play.c */
480 void myreset __P((int)) __attribute__((__noreturn__));
481 void play __P((void)) __attribute__((__noreturn__));
482 
483 /* ram.c */
484 void ram __P((int, int ));
485 
486 /* ranf.c */
487 int ranf __P((int));
488 double franf __P((void));
489 
490 /* rest.c */
491 void rest __P((int));
492 
493 /* schedule.c */
494 struct event *schedule __P((int, double, int, int , int));
495 void reschedule __P((struct event *, double));
496 void unschedule __P((struct event *));
497 struct event *xsched __P((int, int, int, int , int ));
498 void xresched __P((struct event *, int, int));
499 
500 /* score.c */
501 long score __P((void));
502 
503 /* setup.c */
504 void setup __P((void));
505 
506 /* setwarp.c */
507 void setwarp __P((int));
508 
509 /* shield.c */
510 void shield __P((int));
511 
512 /* snova.c */
513 void snova __P((int, int ));
514 
515 /* srscan.c */
516 void srscan __P((int));
517 
518 /* systemname.c */
519 const char *systemname __P((const struct quad *));
520 
521 /* torped.c */
522 void torped __P((int));
523 
524 /* visual.c */
525 void visual __P((int));
526 
527 /* warp.c */
528 void dowarp __P((int));
529 void warp __P((int, int, double));
530 
531 /* win.c */
532 void win __P((void)) __attribute__((__noreturn__));
533