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