9a67c1d063ac1dd44cafcb6a6d15c34ff7edc51c
[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 } game;
217
218 #define inkling game.inkling            // Initial number of klingons
219 #define inbase game.inbase                      // Initial number of bases
220 #define incom game.incom                        // Initian number of commanders
221 #define instar game.instar                      // Initial stars
222 #define intorps game.intorps            // Initial/Max torpedoes
223 #define condit game.condit                      // Condition (red, yellow, green docked)
224 #define torps game.torps                        // number of torpedoes
225 #define ship game.ship                          // Ship type -- 'E' is Enterprise
226 #define quadx game.quadx                        // where we are
227 #define quady game.quady                        //
228 #define sectx game.sectx                        // where we are
229 #define secty game.secty                        //
230 #define length game.length                      // length of game
231 #define skill game.skill                        // skill level
232 #define basex game.basex                        // position of base in current quad
233 #define basey game.basey                        //
234 #define klhere game.klhere                      // klingons here
235 #define comhere game.comhere            // commanders here
236 #define casual game.casual                      // causalties
237 #define nhelp game.nhelp                        // calls for help
238 #define nkinks game.nkinks                      //
239 #define ididit game.ididit                      // Action taken -- allows enemy to attack
240 #define gamewon game.gamewon            // Finished!
241 #define alive game.alive                        // We are alive (not killed)
242 #define justin game.justin                      // just entered quadrant
243 #define alldone game.alldone            // game is now finished
244 #define shldchg game.shldchg            // shield is changing (affects efficiency)
245 #define plnetx game.plnetx                      // location of planet in quadrant
246 #define plnety game.plnety                      //
247 #define inorbit game.inorbit            // orbiting
248 #define landed game.landed                      // party on planet (1), on ship (-1)
249 #define iplnet game.iplnet                      // planet # in quadrant
250 #define imine game.imine                        // mining
251 #define inplan game.inplan                      // initial planets
252 #define nenhere game.nenhere            // Number of enemies in quadrant
253 #define ishere game.ishere                      // Super-commander in quandrant
254 #define neutz game.neutz                        // Romulan Neutral Zone
255 #define irhere game.irhere                      // Romulans in quadrant
256 #define icraft game.icraft                      // Kirk in Galileo
257 #define ientesc game.ientesc            // Attempted escape from supercommander
258 #define iscraft game.iscraft            // =1 if craft on ship, -1 if removed from game
259 #define isatb game.isatb                        // =1 if SuperCommander is attacking base
260 #define iscate game.iscate                      // Super Commander is here
261 #ifdef DEBUG
262 #define idebug game.idebug                      // Debug mode
263 #endif
264 #define iattak game.iattak                      // attack recursion elimination (was cracks[4])
265 #define icrystl game.icrystl            // dilithium crystals aboard
266 #define tourn game.tourn                        // Tournament number
267 #define thawed game.thawed                      // Thawed game
268 #define batx game.batx                          // Base coordinates being attacked
269 #define baty game.baty                          //
270 #define ithere game.ithere                      // Tholean is here 
271 #define ithx game.ithx                          // coordinates of tholean
272 #define ithy game.ithy
273 #define iseenit game.iseenit            // Seen base attack report
274 #define inresor game.inresor            // initial resources
275 #define intime game.intime                      // initial time
276 #define inenrg game.inenrg                      // Initial/Max Energy
277 #define inshld game.inshld                      // Initial/Max Shield
278 #define inlsr game.inlsr                        // initial life support resources
279 #define indate game.indate                      // Initial date
280 #define energy game.energy                      // Energy level
281 #define shield game.shield                      // Shield level
282 #define shldup game.shldup                      // Shields are up
283 #define warpfac game.warpfac            // Warp speed
284 #define wfacsq game.wfacsq                      // squared warp factor
285 #define lsupres game.lsupres            // life support reserves
286 #define dist game.dist                          // movement distance
287 #define direc game.direc                        // movement direction
288 #define Time game.Time                          // time taken by current operation
289 #define docfac game.docfac                      // repair factor when docking (constant?)
290 #define resting game.resting            // rest time
291 #define damfac game.damfac                      // damage factor
292 #define stdamtim game.stdamtim          // time that star chart was damaged
293 #define cryprob game.cryprob            // probability that crystal will work
294 #define probex game.probex                      // location of probe
295 #define probey game.probey
296 #define probecx game.probecx            // current probe quadrant
297 #define probecy game.probecy    
298 #define probeinx game.probeinx          // Probe x,y increment
299 #define probeiny game.probeiny          
300 #define proben game.proben                      // number of moves for probe
301 #define isarmed game.isarmed            // Probe is armed
302 #define nprobes game.nprobes            // number of probes available
303
304 /* the following global state doesn't need to be saved */
305 EXTERN char     *device[NDEVICES];
306 EXTERN int iscore, iskill; // Common PLAQ
307 EXTERN double perdate;
308 EXTERN double aaitem;
309 EXTERN char citem[10];
310
311 /* the Space Thingy's global state should *not* be saved! */
312 EXTERN int thingx, thingy, iqhere, iqengry;
313
314 typedef enum {FWON, FDEPLETE, FLIFESUP, FNRG, FBATTLE,
315               FNEG3, FNOVA, FSNOVAED, FABANDN, FDILITHIUM,
316                           FMATERIALIZE, FPHASER, FLOST, FMINING, FDPLANET,
317                           FPNOVA, FSSC, FSTRACTOR, FDRAY, FTRIBBLE,
318                           FHOLE} FINTYPE ;
319 enum loctype {neither, quadrant, sector};
320
321 /* Define future events */
322 #define FSPY    0       // Spy event happens always (no future[] entry)
323                                         // can cause SC to tractor beam Enterprise
324 #define FSNOVA  1   // Supernova
325 #define FTBEAM  2   // Commander tractor beams Enterprise
326 #define FSNAP   3   // Snapshot for time warp
327 #define FBATTAK 4   // Commander attacks base
328 #define FCDBAS  5   // Commander destroys base
329 #define FSCMOVE 6   // Supercommander moves (might attack base)
330 #define FSCDBAS 7   // Supercommander destroys base
331 #define FDSPROB 8   // Move deep space probe
332
333 #ifdef INCLUDED
334 char *device[NDEVICES] = {
335         "S. R. Sensors",
336         "L. R. Sensors",
337         "Phasers",
338         "Photon Tubes",
339         "Life Support",
340         "Warp Engines",
341         "Impulse Engines",
342         "Shields",
343         "Subspace Radio",
344         "Shuttle Craft",
345         "Computer",
346         "Transporter",
347         "Shield Control",
348         "Death Ray",
349         "D. S. Probe"};                                                                 
350 #endif
351
352 #ifndef TRUE
353 #define TRUE (1)
354 #define FALSE (0)
355 #endif
356
357 #define IHR 'R'
358 #define IHK 'K'
359 #define IHC 'C'
360 #define IHS 'S'
361 #define IHSTAR '*'
362 #define IHP 'P'
363 #define IHB 'B'
364 #define IHBLANK ' '
365 #define IHDOT '.'
366 #define IHQUEST '?'
367 #define IHE 'E'
368 #define IHF 'F'
369 #define IHT 'T'
370 #define IHWEB '#'
371 #define IHGREEN 'G'
372 #define IHYELLOW 'Y'
373 #define IHRED 'R'
374 #define IHDOCKED 'D'
375 #define IHDEAD 'Z'
376 #define IHMATER0 '-'
377 #define IHMATER1 'o'
378 #define IHMATER2 '0'
379
380
381 /* Function prototypes */
382 void prelim(void);
383 void attack(int);
384 int choose(int);
385 void setup(int);
386 void score(void);
387 void atover(int);
388 int srscan(int);
389 void lrscan(void);
390 void phasers(void);
391 void photon(void);
392 void warp(int);
393 void doshield(int);
394 void dock(int);
395 void dreprt(void);
396 void chart(int);
397 void rechart(void);
398 void impuls(void);
399 void wait(void);
400 void setwrp(void);
401 void events(void);
402 void report(void);
403 void eta(void);
404 void help(void);
405 void abandn(void);
406 void finish(FINTYPE);
407 void dstrct(void);
408 void kaboom(void);
409 void freeze(int);
410 int thaw(void);
411 void plaque(void);
412 int scan(void);
413 #define IHEOL (0)
414 #define IHALPHA (1)
415 #define IHREAL (2)
416 void chew(void);
417 void chew2(void);
418 void skip(int);
419 void prout(char *, ...);
420 void proutn(char *, ...);
421 void stars(void);
422 void newqad(int);
423 int ja(void);
424 void cramen(int);
425 void crmshp(void);
426 char *cramlc(enum loctype, int, int);
427 double expran(double);
428 double Rand(void);
429 void iran(int, int *, int *);
430 #define square(i) ((i)*(i))
431 void dropin(int, int*, int*);
432 void newcnd(void);
433 void sortkl(void);
434 void imove(void);
435 void ram(int, int, int, int);
436 void crmena(int, int, int, int, int);
437 void deadkl(int, int, int, int, int);
438 void timwrp(void);
439 void movcom(void);
440 void torpedo(double, double, int, int, double *, int, int, int);
441 void huh(void);
442 void pause_game(int);
443 void nova(int, int);
444 void snova(int, int);
445 void scom(int *);
446 void hittem(double *);
447 void prouts(char *, ...);
448 int isit(char *);
449 void preport(void);
450 void orbit(void);
451 void sensor(int);
452 void drawmaps(short);
453 void beam(void);
454 void mine(void);
455 void usecrystals(void);
456 void shuttle(void);
457 void deathray(void);
458 void debugme(void);
459 void attakreport(int);
460 void movetho(void);
461 void probe(void);
462 void iostart(void);
463 void setwnd(WINDOW *);
464 void warble(void);
465 void boom(int ii, int jj);
466 void tracktorpedo(int x, int y, int ix, int iy, int wait, int l, int i, int n, int iquad);
467 void cgetline(char *, int);
468 void waitfor(void);
469 void setpassword(void);
470 void commandhook(char *, int);
471 void makechart(void);
472 void enqueue(char *);
473
474 /* mode arguments for srscan() */
475 #define SCAN_FULL               1
476 #define SCAN_REQUEST            2
477 #define SCAN_STATUS             3
478 #define SCAN_NO_LEFTSIDE        4
479
480 WINDOW *fullscreen_window;
481 WINDOW *srscan_window;
482 WINDOW *report_window;
483 WINDOW *lrscan_window;
484 WINDOW *message_window;
485 WINDOW *prompt_window;
486
487 extern void clreol(void);
488 extern void clrscr(void);
489 extern void textcolor(int color);
490 extern void highvideo(void);
491
492 enum COLORS {
493    DEFAULT,
494    BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY,
495    DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE
496 };
497
498 #define DAMAGED 128     /* marker for damaged ship in starmap */