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