|
|
1.1 root 1: #
2:
3: #define ever (;;)
4:
5: /* external function definitions */
6: extern double franf(); /* floating random number function */
7: extern double sqrt(); /* square root */
8: extern double sin(), cos(); /* trig functions */
9: extern double atan2(); /* fancy arc tangent function */
10: extern double log(); /* log base e */
11: extern double pow(); /* power function */
12: extern double fabs(); /* absolute value function */
13: extern double exp(); /* exponential function */
14:
15: /********************* GALAXY **************************/
16:
17: /* galactic parameters */
18: # define NSECTS 10 /* dimensions of quadrant in sectors */
19: # define NQUADS 8 /* dimension of galazy in quadrants */
20: # define NINHAB 32 /* number of quadrants which are inhabited */
21:
22: #define QUAD struct quad
23: QUAD /* definition for each quadrant */
24: {
25: char bases; /* number of bases in this quadrant */
26: char qkling:4; /* number of Klingons in this quadrant */
27: char holes:4; /* number of black holes in this quadrant */
28: char stars; /* number of stars in this quadrant */
29: char systemname; /* starsystem name (see below) */
30: int scanned; /* star chart entry (see below) */
31: };
32: /* systemname conventions:
33: * 1 -> NINHAB index into Systemname table for live system.
34: * + Q_GHOST ghost starsystem.
35: * + Q_DISTRESS distressed starsystem.
36: * the index into the Distress table, which will
37: * have the starsystem name.
38: * 0 dead or nonexistent starsystem
39: *
40: * starchart ("scanned") conventions:
41: * 0 -> 999 taken as is
42: * -1 not yet scanned ("...")
43: * 1000 supernova ("///")
44: * 1001 starbase + ??? (".1.")
45: */
46:
47: /* ascii names of systems */
48: extern char *Systemname[NINHAB];
49:
50: /* quadrant definition */
51: QUAD Quad[NQUADS][NQUADS];
52:
53: /* defines for sector map (below) */
54: # define EMPTY '.'
55: # define STAR '*'
56: # define BASE '#'
57: # define ENTERPRISE 'E'
58: # define QUEENE 'Q'
59: # define KLINGON 'K'
60: # define INHABIT '@'
61: # define BLACKHOLE ' '
62:
63: /* current sector map */
64: char Sect[NSECTS][NSECTS];
65:
66: /* current position of Enterprise */
67: char Quadx, Quady; /* current quadrant */
68: char Sectx, Secty; /* current sector */
69:
70: /************************ DEVICES ******************************/
71:
72: # define NDEV 16 /* max number of devices */
73: char Damage[NDEV]; /* set if device damaged */
74:
75: /* device tokens */
76: # define WARP 0 /* warp engines */
77: # define SRSCAN 1 /* short range scanners */
78: # define LRSCAN 2 /* long range scanners */
79: # define PHASER 3 /* phaser control */
80: # define TORPED 4 /* photon torpedo control */
81: # define IMPULSE 5 /* impulse engines */
82: # define SHIELD 6 /* shield control */
83: # define COMPUTER 7 /* on board computer */
84: # define SSRADIO 8 /* subspace radio */
85: # define LIFESUP 9 /* life support systems */
86: # define SINS 10 /* Space Inertial Navigation System */
87: # define CLOAK 11 /* cloaking device */
88: # define XPORTER 12 /* transporter */
89: # define SHUTTLE 13 /* shuttlecraft */
90:
91: /* device names */
92: #define DEVICE struct device
93: DEVICE
94: {
95: char *name; /* device name */
96: char *person; /* the person who fixes it */
97: };
98:
99: DEVICE Device[NDEV];
100:
101: /*************************** EVENTS ****************************/
102:
103: # define NEVENTS 12 /* number of different event types */
104:
105: # define E_SNOVA 0 /* supernova occurs */
106: # define E_LRTB 1 /* long range tractor beam */
107: # define E_KATSB 2 /* Klingon attacks starbase */
108: # define E_KDESB 3 /* Klingon destroys starbase */
109: # define E_ISSUE 4 /* distress call is issued */
110: # define E_ENSLV 5 /* Klingons enslave a quadrant */
111: # define E_REPRO 6 /* a Klingon is reproduced */
112: # define E_FIXDV 7 /* fix a device */
113: # define E_ATTACK 8 /* Klingon attack during rest period */
114: # define E_SNAP 9 /* take a snapshot for time warp */
115: # define E_NREPORT 32 /* distress call not yet reported */
116: # define Q_DISTRESS 64
117: # define Q_GHOST 32
118: # define Q_STARNAME 31
119:
120: #define EVENT struct event
121: EVENT
122: {
123: char x, y; /* coordinates */
124: char evcode; /* event type */
125: char evdata; /* starsystem name */
126: float date; /* trap stardate */
127: };
128: /* systemname conventions:
129: * 1 -> NINHAB index into Systemname table for reported distress calls
130: * + E_NREPORT flag marking distress call not reported (SS radio out)
131: */
132:
133: # define MAXEVENTS 25 /* max number of concurrently pending events */
134:
135: EVENT Event[MAXEVENTS]; /* dynamic event list; one entry per pending event */
136:
137: /***************************** KLINGONS *******************************/
138:
139: #define KLINGONS struct klingon
140: KLINGONS
141: {
142: char x, y; /* coordinates */
143: int power; /* power left */
144: float dist; /* distance to Enterprise */
145: float avgdist; /* average over this move */
146: };
147: # define MAXKLQUAD 9 /* maximum klingons per quadrant */
148: KLINGONS Kling[MAXKLQUAD];
149: int Nkling; /* number of Klingons in this sector */
150:
151: /********************** MISCELLANEOUS ***************************/
152:
153: /* condition codes */
154: # define GREEN 0
155: # define DOCKED 1
156: # define YELLOW 2
157: # define RED 3
158:
159: /*
160: * note that much of the stuff in the following structs CAN NOT
161: * be moved around!!!!
162: */
163:
164: /* initial information */
165: struct
166: {
167: char bases; /* number of starbases */
168: char kling; /* number of klingons */
169: char torped; /* photon torpedos */
170: float date; /* stardate */
171: float time; /* time left */
172: float resource; /* Federation resources */
173: int energy; /* starship's energy */
174: int shield; /* energy in shields */
175: float reserves; /* life support reserves */
176: int crew; /* size of ship's complement */
177: int brigfree; /* max possible number of captives */
178: } Initial;
179:
180: /* status information */
181: struct
182: {
183: char bases; /* number of starbases */
184: char kling; /* number of klingons */
185: char torped; /* torpedoes */
186: float date; /* stardate */
187: float time; /* time left */
188: float resource; /* Federation resources */
189: int energy; /* starship's energy */
190: int shield; /* energy in shields */
191: float reserves; /* life support reserves */
192: int crew; /* ship's complement */
193: int brigfree; /* space left in brig */
194: char shldup; /* shield up flag */
195: char cond; /* condition code */
196: char sinsbad; /* Space Inertial Navigation System condition */
197: char cloaked; /* set if cloaking device on */
198: float warp; /* warp factor */
199: float warp2; /* warp factor squared */
200: float warp3; /* warp factor cubed */
201: float cloakdate; /* stardate we became cloaked */
202: char *shipname; /* name of current starship */
203: char ship; /* current starship */
204: char distressed; /* number of currently distressed quadrants */
205: } Status;
206:
207: /* sinsbad is set if SINS is working but not calibrated */
208:
209: /* game related information, mostly scoring */
210: #define PWDLEN 15
211: long inittime;
212: struct
213: {
214: int gkillk; /* number of klingons killed */
215: int helps; /* number of help calls */
216: int deaths; /* number of deaths onboard Enterprise */
217: char negenbar; /* number of hits on negative energy barrier */
218: char killb; /* number of starbases killed */
219: int kills; /* number of stars killed */
220: char skill; /* skill rating of player */
221: char length; /* length of game */
222: char killed; /* set if you were killed */
223: char killinhab; /* number of inhabited starsystems killed */
224: char tourn; /* set if a tournament game */
225: char passwd[PWDLEN]; /* game password */
226: char snap; /* set if snapshot taken */
227: int captives; /* total number of captives taken */
228: } Game;
229:
230: /* per move information */
231: struct
232: {
233: char free; /* set if a move is free */
234: char endgame; /* end of game flag */
235: char shldchg; /* set if shields changed this move */
236: char newquad; /* set if just entered this quadrant */
237: char resting; /* set if this move is a rest */
238: float delta; /* time used this move */
239: } Move;
240:
241: /* parametric information */
242: struct
243: {
244: float damfac[NDEV]; /* damage factor */
245: float dockfac; /* docked repair time factor */
246: float regenfac; /* regeneration factor */
247: int stopengy; /* energy to do emergency stop */
248: int shupengy; /* energy to put up shields */
249: int klingpwr; /* Klingon initial power */
250: int warptime; /* time chewer multiplier */
251: float phasfac; /* Klingon phaser power eater factor */
252: char moveprob[6]; /* probability that a Klingon moves */
253: float movefac[6]; /* Klingon move distance multiplier */
254: float eventdly[NEVENTS]; /* event time multipliers */
255: float navigcrud[2]; /* navigation crudup factor */
256: int cloakenergy; /* cloaking device energy per stardate */
257: float damprob[NDEV]; /* damage probability */
258: float hitfac; /* Klingon attack factor */
259: } Param;
260:
261: /* Sum of damage probabilities must add to 1000 */
262:
263: /* Other crap, mostly redundant stuff kept for efficiency reasons */
264: struct
265: {
266: EVENT *eventptr[NEVENTS]; /* pointer to event structs */
267: } Etc;
268:
269: /*
270: * eventptr is a pointer to the event[] entry of the last
271: * scheduled event of each type. Zero if no such event scheduled.
272: */
273:
274: /* Klingon move indicies */
275: # define KM_OB 0 /* Old quadrant, Before attack */
276: # define KM_OA 1 /* Old quadrant, After attack */
277: # define KM_EB 2 /* Enter quadrant, Before attack */
278: # define KM_EA 3 /* Enter quadrant, After attack */
279: # define KM_LB 4 /* Leave quadrant, Before attack */
280: # define KM_LA 5 /* Leave quadrant, After attack */
281:
282: /* you lose codes */
283: # define L_NOTIME 1 /* ran out of time */
284: # define L_NOENGY 2 /* ran out of energy */
285: # define L_DSTRYD 3 /* destroyed by a Klingon */
286: # define L_NEGENB 4 /* ran into the negative energy barrier */
287: # define L_SUICID 5 /* destroyed in a nova */
288: # define L_SNOVA 6 /* destroyed in a supernova */
289: # define L_NOLIFE 7 /* life support died (so did you) */
290: # define L_NOHELP 8 /* you could not be rematerialized */
291: # define L_TOOFAST 9 /* pretty stupid going at warp 10 */
292: # define L_STAR 10 /* ran into a star */
293: # define L_DSTRCT 11 /* self destructed */
294: # define L_CAPTURED 12 /* captured by Klingons */
295: # define L_NOCREW 13 /* you ran out of crew */
296: #define L_CHEAT 14 /* probably cheating */
297:
298: # define CVNTAB struct cvntab
299: CVNTAB /* used for getcodpar() paramater list */
300: {
301: char *abrev;
302: char *full;
303: };
304:
305: #define XY struct xy
306: XY
307: {
308: char x, y; /* coordinates */
309: };
310:
311: /* starbase coordinates */
312: # define MAXBASES 9 /* maximum number of starbases in galaxy */
313:
314: #define SIGINT 2
315: int mkfault; /* marks outstanding signal */
316:
317: XY Base[MAXBASES]; /* quad coords of starbases */
318: XY Starbase; /* starbase in current quadrant */
319:
320: /* distress calls */
321: # define MAXDISTR 4 /* maximum concurrent distress calls */
322:
323: #include <setjmp.h>
324: jmp_buf errjmp;
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.