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