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