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