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