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