838bc8ae829f4a527aa25f4f983ce23318b38b4d
[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 <= game.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 (game.inkling - game.state.remkl)
83 #define NKILLC (game.incom - game.state.remcom)
84 #define NKILLSC (game.inscom - game.state.nscrem)
85 #define NKILLROM (game.inrom - game.state.nromrem)
86 #define KLINGREM (game.state.remkl + game.state.remcom + game.state.nscrem)
87 #define INKLINGTOT (game.inkling + game.incom + game.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     int inkling,        // Initial number of klingons
171         inbase,         // Initial number of bases
172         incom,          // Initial number of commanders
173         inscom,         // Initial number of commanders
174         inrom,          // Initial number of commanders
175         instar,         // Initial stars
176         intorps,        // Initial/Max torpedoes
177         condit,         // Condition (red/yellow/green/docked)
178         torps,          // number of torpedoes
179         ship,           // Ship type -- 'E' is Enterprise
180         quadx,          // where we are
181         quady,          //
182         sectx,          // where we are
183         secty,          //
184         length,         // length of game
185         skill,          // skill level
186         basex,          // position of base in current quadrant
187         basey,          //
188         klhere,         // klingons here
189         comhere,        // commanders here
190         casual,         // causalties
191         nhelp,          // calls for help
192         nkinks,         // count of energy-barrier crossings
193         ididit,         // Action taken -- allows enemy to attack
194         gamewon,        // Finished!
195         alive,          // We are alive (not killed)
196         justin,         // just entered quadrant
197         alldone,        // game is now finished
198         shldchg,        // shield is changing (affects efficiency)
199         plnetx,         // location of planet in quadrant
200         plnety,         //
201         inorbit,        // orbiting
202         landed,         // party on planet (1), on ship (-1)
203         iplnet,         // planet # in quadrant
204         imine,          // mining
205         inplan,         // initial planets
206         nenhere,        // number of enemies in quadrant
207         ishere,         // super-commander in quandrant
208         neutz,          // Romulan Neutral Zone
209         irhere,         // Romulans in quadrant
210         icraft,         // Kirk in Galileo
211         ientesc,        // attempted escape from supercommander
212         iscraft,        // =1 if craft on ship, -1 if removed from game
213         isatb,          // =1 if super commander is attacking base
214         iscate,         // super commander is here
215 #ifdef DEBUG
216         idebug,         // debug mode
217 #endif
218         iattak,         // attack recursion elimination (was cracks[4])
219         icrystl,        // dilithium crystals aboard
220         tourn,          // tournament number
221         thawed,         // thawed game
222         batx,           // base coordinates being attacked
223         baty,           //
224         ithere,         // Tholian is here 
225         ithx,           // coordinates of Tholian
226         ithy,           //
227         iseenit,        // seen base attack report
228         probecx,        // current probe quadrant
229         probecy,        //
230         proben,         // number of moves for probe
231         isarmed,        // probe is armed
232         nprobes;        // number of probes available
233     double inresor,     // initial resources
234         intime,         // initial time
235         inenrg,         // initial/max energy
236         inshld,         // initial/max shield
237         inlsr,          // initial life support resources
238         indate,         // initial date
239         energy,         // energy level
240         shield,         // shield level
241         shldup,         // shields are up
242         warpfac,        // warp speed
243         wfacsq,         // squared warp factor
244         lsupres,        // life support reserves
245         dist,           // movement distance
246         direc,          // movement direction
247         optime,         // time taken by current operation
248         docfac,         // repair factor when docking (constant?)
249         resting,        // rest time
250         damfac,         // damage factor
251         lastchart,      // time star chart was last updated
252         cryprob,        // probability that crystal will work
253         probex,         // location of probe
254         probey,         //
255         probeinx,       // probe x,y increment
256         probeiny,       //
257         height;         // height of orbit around planet
258 };
259 extern struct game game;
260
261 /* the following global state doesn't need to be saved */
262 extern char *device[NDEVICES];
263 extern int iscore, iskill; // Common PLAQ
264 extern double perdate;
265 extern double aaitem;
266 extern char citem[10];
267
268 /* the Space Thingy's global state should *not* be saved! */
269 extern int thingx, thingy, iqhere, iqengry;
270
271 typedef enum {FWON, FDEPLETE, FLIFESUP, FNRG, FBATTLE,
272               FNEG3, FNOVA, FSNOVAED, FABANDN, FDILITHIUM,
273                           FMATERIALIZE, FPHASER, FLOST, FMINING, FDPLANET,
274                           FPNOVA, FSSC, FSTRACTOR, FDRAY, FTRIBBLE,
275                           FHOLE} FINTYPE ;
276 enum loctype {neither, quadrant, sector};
277
278 #ifndef TRUE
279 #define TRUE (1)
280 #define FALSE (0)
281 #endif
282
283 #define IHR 'R'
284 #define IHK 'K'
285 #define IHC 'C'
286 #define IHS 'S'
287 #define IHSTAR '*'
288 #define IHP 'P'
289 #define IHB 'B'
290 #define IHBLANK ' '
291 #define IHDOT '.'
292 #define IHQUEST '?'
293 #define IHE 'E'
294 #define IHF 'F'
295 #define IHT 'T'
296 #define IHWEB '#'
297 #define IHGREEN 'G'
298 #define IHYELLOW 'Y'
299 #define IHRED 'R'
300 #define IHDOCKED 'D'
301 #define IHDEAD 'Z'
302 #define IHMATER0 '-'
303 #define IHMATER1 'o'
304 #define IHMATER2 '0'
305
306
307 /* Function prototypes */
308 void prelim(void);
309 void attack(int);
310 int choose(int);
311 void setup(int);
312 void score(void);
313 void atover(int);
314 int srscan(int);
315 void lrscan(void);
316 void phasers(void);
317 void photon(void);
318 void warp(int);
319 void doshield(int);
320 void dock(int);
321 void dreprt(void);
322 void chart(int);
323 void rechart(void);
324 void impuls(void);
325 void wait(void);
326 void setwrp(void);
327 void events(void);
328 void report(void);
329 void eta(void);
330 void help(void);
331 void abandn(void);
332 void finish(FINTYPE);
333 void dstrct(void);
334 void kaboom(void);
335 void freeze(int);
336 int thaw(void);
337 void plaque(void);
338 int scan(void);
339 #define IHEOL (0)
340 #define IHALPHA (1)
341 #define IHREAL (2)
342 void chew(void);
343 void chew2(void);
344 void skip(int);
345 void prout(char *, ...);
346 void proutn(char *, ...);
347 void stars(void);
348 void newqad(int);
349 int ja(void);
350 void cramen(int);
351 void crmshp(void);
352 char *cramlc(enum loctype, int, int);
353 double expran(double);
354 double Rand(void);
355 void iran(int, int *, int *);
356 #define square(i) ((i)*(i))
357 void dropin(int, int*, int*);
358 void newcnd(void);
359 void sortkl(void);
360 void imove(void);
361 void ram(int, int, int, int);
362 void crmena(int, int, int, int, int);
363 void deadkl(int, int, int, int, int);
364 void timwrp(void);
365 void movcom(void);
366 void torpedo(double, double, int, int, double *, int, int);
367 void huh(void);
368 void pause_game(int);
369 void nova(int, int);
370 void snova(int, int);
371 void scom(int *);
372 void hittem(double *);
373 void prouts(char *, ...);
374 int isit(char *);
375 void preport(void);
376 void orbit(void);
377 void sensor(void);
378 void drawmaps(short);
379 void beam(void);
380 void mine(void);
381 void usecrystals(void);
382 void shuttle(void);
383 void deathray(void);
384 void debugme(void);
385 void attakreport(int);
386 void movetho(void);
387 void probe(void);
388 void iostart(void);
389 void setwnd(WINDOW *);
390 void warble(void);
391 void boom(int ii, int jj);
392 void tracktorpedo(int ix, int iy, int l, int i, int n, int iquad);
393 void cgetline(char *, int);
394 void waitfor(void);
395 void setpassword(void);
396 void commandhook(char *, int);
397 void makechart(void);
398 void enqueue(char *);
399
400 /* mode arguments for srscan() */
401 #define SCAN_FULL               1
402 #define SCAN_REQUEST            2
403 #define SCAN_STATUS             3
404 #define SCAN_NO_LEFTSIDE        4
405
406 WINDOW *fullscreen_window;
407 WINDOW *srscan_window;
408 WINDOW *report_window;
409 WINDOW *lrscan_window;
410 WINDOW *message_window;
411 WINDOW *prompt_window;
412
413 extern void clreol(void);
414 extern void clrscr(void);
415 extern void textcolor(int color);
416 extern void highvideo(void);
417
418 enum COLORS {
419    DEFAULT,
420    BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY,
421    DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE
422 };
423
424 #define DAMAGED 128     /* marker for damaged ship in starmap */
425
426 #endif