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