Magic number elimination.
[super-star-trek.git] / sst.h
1 #include <stdio.h>
2 #include <math.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <curses.h>
6 #ifndef INCLUDED
7 #define EXTERN extern
8 #else
9 #define EXTERN
10 #endif
11
12 #define min(x, y)       ((x)<(y)?(x):(y))
13 #define max(x, y)       ((x)>(y)?(x):(y))
14
15 // #define DEBUG
16
17 #define NDEVICES (15)   // Number of devices
18 #define PHASEFAC (2.0)
19 #define PLNETMAX (10)
20 #define NEVENTS (8)
21 #define GALSIZE (8)
22 #define QUADSIZE (10)
23
24 typedef struct {
25     int x;      /* Quadrant location of planet */
26     int y;
27     enum {M=0, N=1, O=2} pclass;
28     int crystals; /* has crystals */
29     enum {unknown, known, shuttle_down} known;
30 } planet;
31
32 #define DESTROY(pl)     memset(pl, '\0', sizeof(planet))
33
34 typedef struct {
35     int snap,           // snapshot taken
36         remkl,                  // remaining klingons
37         remcom,                 // remaining commanders
38         rembase,                // remaining bases
39         starkl,                 // destroyed stars
40         basekl,                 // destroyed bases
41         killk,                  // Klingons killed
42         killc,                  // commanders killed
43         galaxy[GALSIZE+1][GALSIZE+1],   // The Galaxy (subscript 0 not used)
44         cx[QUADSIZE+1],cy[QUADSIZE+1],  // Commander quadrant coordinates
45         baseqx[6],              // Base quadrant X
46         baseqy[6],              // Base quadrant Y
47         newstuf[GALSIZE+1][GALSIZE+1],  // Extended galaxy goodies
48         isx, isy,               // Coordinate of Super Commander
49         nscrem,                 // remaining super commanders
50         nromkl,                 // Romulans killed
51         nromrem,                // Romulans remaining
52         nsckill,                // super commanders killed
53         nplankl;                // destroyed planets
54         planet plnets[PLNETMAX];  // Planet information
55         double date,            // stardate
56             remres,             // remaining resources
57             remtime;            // remaining time
58 } snapshot;                             // Data that is snapshot
59
60 // Scalar variables that are needed for freezing the game
61 // are placed in a structure. #defines are used to access by their
62 // original names. Gee, I could have done this with the d structure,
63 // but I just didn't think of it back when I started.
64
65 #define SSTMAGIC        "SST2.0\n"
66
67 EXTERN WINDOW *curwnd;
68
69 EXTERN struct {
70     char magic[sizeof(SSTMAGIC)];
71     snapshot state;
72     snapshot snapsht;
73     char quad[QUADSIZE+1][QUADSIZE+1];          // contents of our quadrant
74     double kpower[(QUADSIZE+1)*(QUADSIZE+1)];           // enemy energy levels
75     double kdist[(QUADSIZE+1)*(QUADSIZE+1)];            // enemy distances
76     double kavgd[(QUADSIZE+1)*(QUADSIZE+1)];            // average distances
77     double damage[NDEVICES+1];  // damage encountered
78     double future[NEVENTS+1];   // future events
79     char passwd[10];            // Self Destruct password
80     int kx[(QUADSIZE+1)*(QUADSIZE+1)];                  // enemy sector locations
81     int ky[(QUADSIZE+1)*(QUADSIZE+1)];
82     int starch[GALSIZE+1][GALSIZE+1];           // star chart
83     /* members with macro definitions start here */
84     int inkling,
85         inbase,
86         incom,
87         instar,
88         intorps,
89         condit,
90         torps,
91         ship,
92         quadx,
93         quady,
94         sectx,
95         secty,
96         length,
97         skill,
98         basex,
99         basey,
100         klhere,
101         comhere,
102         casual,
103         nhelp,
104         nkinks,
105         ididit,
106         gamewon,
107         alive,
108         justin,
109         alldone,
110         shldchg,
111         thingx,
112         thingy,
113         plnetx,
114         plnety,
115         inorbit,
116         landed,
117         iplnet,
118         imine,
119         inplan,
120         nenhere,
121         ishere,
122         neutz,
123         irhere,
124         icraft,
125         ientesc,
126         iscraft,
127         isatb,
128         iscate,
129 #ifdef DEBUG
130         idebug,
131 #endif
132         iattak,
133         icrystl,
134         tourn,
135         thawed,
136         batx,
137         baty,
138         ithere,
139         iqhere,
140         iqengry,
141         ithx,
142         ithy,
143         iseenit,
144         probecx,
145         probecy,
146         proben,
147         isarmed,
148         nprobes;
149     double inresor,
150         intime,
151         inenrg,
152         inshld,
153         inlsr,
154         indate,
155         energy,
156         shield,
157         shldup,
158         warpfac,
159         wfacsq,
160         lsupres,
161         dist,
162         direc,
163         Time,
164         docfac,
165         resting,
166         damfac,
167         stdamtim,
168         cryprob,
169         probex,
170         probey,
171         probeinx,
172         probeiny;
173 } game;
174
175 #define inkling game.inkling            // Initial number of klingons
176 #define inbase game.inbase                      // Initial number of bases
177 #define incom game.incom                        // Initian number of commanders
178 #define instar game.instar                      // Initial stars
179 #define intorps game.intorps            // Initial/Max torpedoes
180 #define condit game.condit                      // Condition (red, yellow, green docked)
181 #define torps game.torps                        // number of torpedoes
182 #define ship game.ship                          // Ship type -- 'E' is Enterprise
183 #define quadx game.quadx                        // where we are
184 #define quady game.quady                        //
185 #define sectx game.sectx                        // where we are
186 #define secty game.secty                        //
187 #define length game.length                      // length of game
188 #define skill game.skill                        // skill level
189 #define basex game.basex                        // position of base in current quad
190 #define basey game.basey                        //
191 #define klhere game.klhere                      // klingons here
192 #define comhere game.comhere            // commanders here
193 #define casual game.casual                      // causalties
194 #define nhelp game.nhelp                        // calls for help
195 #define nkinks game.nkinks                      //
196 #define ididit game.ididit                      // Action taken -- allows enemy to attack
197 #define gamewon game.gamewon            // Finished!
198 #define alive game.alive                        // We are alive (not killed)
199 #define justin game.justin                      // just entered quadrant
200 #define alldone game.alldone            // game is now finished
201 #define shldchg game.shldchg            // shield is changing (affects efficiency)
202 #define thingx game.thingx                      // location of strange object in galaxy
203 #define thingy game.thingy                      //
204 #define plnetx game.plnetx                      // location of planet in quadrant
205 #define plnety game.plnety                      //
206 #define inorbit game.inorbit            // orbiting
207 #define landed game.landed                      // party on planet (1), on ship (-1)
208 #define iplnet game.iplnet                      // planet # in quadrant
209 #define imine game.imine                        // mining
210 #define inplan game.inplan                      // initial planets
211 #define nenhere game.nenhere            // Number of enemies in quadrant
212 #define ishere game.ishere                      // Super-commander in quandrant
213 #define neutz game.neutz                        // Romulan Neutral Zone
214 #define irhere game.irhere                      // Romulans in quadrant
215 #define iqhere game.iqhere                      // Thing in quadrant
216 #define iqengry game.iqengry                    // Thing attacking
217 #define icraft game.icraft                      // Kirk in Galileo
218 #define ientesc game.ientesc            // Attempted escape from supercommander
219 #define iscraft game.iscraft            // =1 if craft on ship, -1 if removed from game
220 #define isatb game.isatb                        // =1 if SuperCommander is attacking base
221 #define iscate game.iscate                      // Super Commander is here
222 #ifdef DEBUG
223 #define idebug game.idebug                      // Debug mode
224 #endif
225 #define iattak game.iattak                      // attack recursion elimination (was cracks[4])
226 #define icrystl game.icrystl            // dilithium crystals aboard
227 #define tourn game.tourn                        // Tournament number
228 #define thawed game.thawed                      // Thawed game
229 #define batx game.batx                          // Base coordinates being attacked
230 #define baty game.baty                          //
231 #define ithere game.ithere                      // Tholean is here 
232 #define ithx game.ithx                          // coordinates of tholean
233 #define ithy game.ithy
234 #define iseenit game.iseenit            // Seen base attack report
235 #define inresor game.inresor            // initial resources
236 #define intime game.intime                      // initial time
237 #define inenrg game.inenrg                      // Initial/Max Energy
238 #define inshld game.inshld                      // Initial/Max Shield
239 #define inlsr game.inlsr                        // initial life support resources
240 #define indate game.indate                      // Initial date
241 #define energy game.energy                      // Energy level
242 #define shield game.shield                      // Shield level
243 #define shldup game.shldup                      // Shields are up
244 #define warpfac game.warpfac            // Warp speed
245 #define wfacsq game.wfacsq                      // squared warp factor
246 #define lsupres game.lsupres            // life support reserves
247 #define dist game.dist                          // movement distance
248 #define direc game.direc                        // movement direction
249 #define Time game.Time                          // time taken by current operation
250 #define docfac game.docfac                      // repair factor when docking (constant?)
251 #define resting game.resting            // rest time
252 #define damfac game.damfac                      // damage factor
253 #define stdamtim game.stdamtim          // time that star chart was damaged
254 #define cryprob game.cryprob            // probability that crystal will work
255 #define probex game.probex                      // location of probe
256 #define probey game.probey
257 #define probecx game.probecx            // current probe quadrant
258 #define probecy game.probecy    
259 #define probeinx game.probeinx          // Probe x,y increment
260 #define probeiny game.probeiny          
261 #define proben game.proben                      // number of moves for probe
262 #define isarmed game.isarmed            // Probe is armed
263 #define nprobes game.nprobes            // number of probes available
264
265 /* the following global state doesn't need to be saved */
266 EXTERN char     *device[NDEVICES+1];
267 EXTERN int iscore, iskill; // Common PLAQ
268 EXTERN double perdate;
269 EXTERN double aaitem;
270 EXTERN char citem[10];
271
272 typedef enum {FWON, FDEPLETE, FLIFESUP, FNRG, FBATTLE,
273               FNEG3, FNOVA, FSNOVAED, FABANDN, FDILITHIUM,
274                           FMATERIALIZE, FPHASER, FLOST, FMINING, FDPLANET,
275                           FPNOVA, FSSC, FSTRACTOR, FDRAY, FTRIBBLE,
276                           FHOLE} FINTYPE ;
277 enum loctype {neither, quadrant, sector};
278
279 /* Define devices */
280 #define DSRSENS 1
281 #define DLRSENS 2
282 #define DPHASER 3
283 #define DPHOTON 4
284 #define DLIFSUP 5
285 #define DWARPEN 6
286 #define DIMPULS 7
287 #define DSHIELD 8
288 #define DRADIO  9
289 #define DSHUTTL 10
290 #define DCOMPTR 11
291 #define DTRANSP 12
292 #define DSHCTRL 13
293 #define DDRAY   14  // Added deathray
294 #define DDSP    15  // Added deep space probe
295
296 /* Define future events */
297 #define FSPY    0       // Spy event happens always (no future[] entry)
298                                         // can cause SC to tractor beam Enterprise
299 #define FSNOVA  1   // Supernova
300 #define FTBEAM  2   // Commander tractor beams Enterprise
301 #define FSNAP   3   // Snapshot for time warp
302 #define FBATTAK 4   // Commander attacks base
303 #define FCDBAS  5   // Commander destroys base
304 #define FSCMOVE 6   // Supercommander moves (might attack base)
305 #define FSCDBAS 7   // Supercommander destroys base
306 #define FDSPROB 8   // Move deep space probe
307
308 #ifdef INCLUDED
309 char *device[NDEVICES+1] = {
310         "",
311         "S. R. Sensors",
312         "L. R. Sensors",
313         "Phasers",
314         "Photon Tubes",
315         "Life Support",
316         "Warp Engines",
317         "Impulse Engines",
318         "Shields",
319         "Subspace Radio",
320         "Shuttle Craft",
321         "Computer",
322         "Transporter",
323         "Shield Control",
324     "Death Ray",
325     "D. S. Probe"};                                                                     
326 #endif
327
328 #ifndef TRUE
329 #define TRUE (1)
330 #define FALSE (0)
331 #endif
332
333 #define IHR 'R'
334 #define IHK 'K'
335 #define IHC 'C'
336 #define IHS 'S'
337 #define IHSTAR '*'
338 #define IHP 'P'
339 #define IHB 'B'
340 #define IHBLANK ' '
341 #define IHDOT '.'
342 #define IHQUEST '?'
343 #define IHE 'E'
344 #define IHF 'F'
345 #define IHT 'T'
346 #define IHWEB '#'
347 #define IHGREEN 'G'
348 #define IHYELLOW 'Y'
349 #define IHRED 'R'
350 #define IHDOCKED 'D'
351 #define IHDEAD 'Z'
352 #define IHMATER0 '-'
353 #define IHMATER1 'o'
354 #define IHMATER2 '0'
355
356
357 /* Function prototypes */
358 void prelim(void);
359 void attack(int);
360 int choose(int);
361 void setup(int);
362 void score(void);
363 void atover(int);
364 int srscan(int);
365 void lrscan(void);
366 void phasers(void);
367 void photon(void);
368 void warp(int);
369 void doshield(int);
370 void dock(int);
371 void dreprt(void);
372 void chart(int);
373 void impuls(void);
374 void wait(void);
375 void setwrp(void);
376 void events(void);
377 void report(void);
378 void eta(void);
379 void help(void);
380 void abandn(void);
381 void finish(FINTYPE);
382 void dstrct(void);
383 void kaboom(void);
384 void freeze(int);
385 int thaw(void);
386 void plaque(void);
387 int scan(void);
388 #define IHEOL (0)
389 #define IHALPHA (1)
390 #define IHREAL (2)
391 void chew(void);
392 void chew2(void);
393 void skip(int);
394 void prout(char *, ...);
395 void proutn(char *, ...);
396 void stars(void);
397 void newqad(int);
398 int ja(void);
399 void cramen(int);
400 void crmshp(void);
401 char *cramlc(enum loctype, int, int);
402 double expran(double);
403 double Rand(void);
404 void iran8(int *, int *);
405 void iran10(int *, int *);
406 #define square(i) ((i)*(i))
407 void dropin(int, int*, int*);
408 void newcnd(void);
409 void sortkl(void);
410 void imove(void);
411 void ram(int, int, int, int);
412 void crmena(int, int, int, int, int);
413 void deadkl(int, int, int, int, int);
414 void timwrp(void);
415 void movcom(void);
416 void torpedo(double, double, int, int, double *, int, int, int);
417 void huh(void);
418 void pause_game(int);
419 void nova(int, int);
420 void snova(int, int);
421 void scom(int *);
422 void hittem(double *);
423 void prouts(char *, ...);
424 int isit(char *);
425 void preport(void);
426 void orbit(void);
427 void sensor(void);
428 void drawmaps(short);
429 void beam(void);
430 void mine(void);
431 void usecrystals(void);
432 void shuttle(void);
433 void deathray(void);
434 void debugme(void);
435 void attakreport(int);
436 void movetho(void);
437 void probe(void);
438 void iostart(int);
439 void setwnd(WINDOW *);
440 void warble(void);
441 void boom(int ii, int jj);
442 void tracktorpedo(int x, int y, int ix, int iy, int wait, int l, int i, int n, int iquad);
443 void cgetline(char *, int);
444 void waitfor(void);
445 void setpassword(void);
446 void commandhook(char *, int);
447 void makechart(void);
448 void enqueue(char *);
449
450 /* mode arguments for srscan() */
451 #define SCAN_FULL               1
452 #define SCAN_REQUEST            2
453 #define SCAN_STATUS             3
454 #define SCAN_NO_LEFTSIDE        4
455
456 WINDOW *fullscreen_window;
457 WINDOW *srscan_window;
458 WINDOW *report_window;
459 WINDOW *lrscan_window;
460 WINDOW *message_window;
461 WINDOW *prompt_window;
462
463 extern void clreol(void);
464 extern void clrscr(void);
465 extern void textcolor(int color);
466 extern void highvideo(void);
467
468 enum COLORS {
469    DEFAULT,
470    BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY,
471    DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE
472 };
473
474 #define DAMAGED 128     /* marker for damaged ship in starmap */