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