First checkin of experimental event code for the BSDTrek-style Klingons.
[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
11 #ifdef DATA_DIR
12 #define SSTDOC DATA_DIR"/"DOC_NAME
13 #else
14 #define SSTDOC DOC_NAME
15 #endif
16
17 #define _(str) gettext(str)
18
19 #define min(x, y)       ((x)<(y)?(x):(y))
20 #define max(x, y)       ((x)>(y)?(x):(y))
21
22 // #define DEBUG
23
24 #define PHASEFAC (2.0)
25 #define GALSIZE (8)
26 #define NINHAB (GALSIZE * GALSIZE / 2)
27 #define MAXUNINHAB (10)
28 #define PLNETMAX (NINHAB + MAXUNINHAB)
29 #define QUADSIZE (10)
30 #define BASEMAX (5)
31
32 /*
33  * These macros hide the difference between 0-origin and 1-origin addressing.
34  * They're a step towards de-FORTRANizing the code.
35  */
36 #define VALID_QUADRANT(x, y)    ((x)>=1 && (x)<=GALSIZE && (y)>=1 && (y)<=GALSIZE)
37 #define VALID_SECTOR(x, y)      ((x)>=1 && (x)<=QUADSIZE && (y)>=1 && (y)<=QUADSIZE)
38 #define for_quadrants(i)        for (i = 1; i <= GALSIZE; i++)
39 #define for_sectors(i)          for (i = 1; i <= QUADSIZE; i++)
40 #define for_commanders(i)       for (i = 1; i <= game.state.remcom; i++)
41 #define for_local_enemies(i)    for (i = 1; i <= game.nenhere; i++)
42 #define for_starbases(i)        for (i = 1; i <= game.state.rembase; i++)
43
44 typedef struct {
45     int x;      /* Quadrant location of planet */
46     int y;
47     enum {M=0, N=1, O=2} pclass;
48     int inhabited;      /* if NZ, an index into a name array */
49 #define UNINHABITED     -1
50     int crystals; /* has crystals */
51 #define MINED   -1      /* used to have crystals, but they were mined out */
52     enum {unknown, known, shuttle_down} known;
53 } planet;
54
55 #define DESTROY(pl)     memset(pl, '\0', sizeof(planet))
56
57 typedef struct {
58     int snap,           // snapshot taken
59         remkl,                  // remaining klingons
60         remcom,                 // remaining commanders
61         nscrem,                 // remaining super commanders
62         rembase,                // remaining bases
63         starkl,                 // destroyed stars
64         basekl,                 // destroyed bases
65         cx[QUADSIZE+1],cy[QUADSIZE+1],  // Commander quadrant coordinates
66         baseqx[BASEMAX+1],              // Base quadrant X
67         baseqy[BASEMAX+1],              // Base quadrant Y
68         isx, isy,               // Coordinate of Super Commander
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     struct quadrant {
76         int stars;
77         planet *planet;
78         int starbase;
79         int klingons;
80         int romulans;
81         int supernova;
82         int charted;
83 #ifdef EXPERIMENTAL
84         enum {secure, distressed, enslaved} status;
85 #endif /* EXPERIMENTAL */
86     } galaxy[GALSIZE+1][GALSIZE+1];     // The Galaxy (subscript 0 not used)
87     struct {
88         int stars;
89         int starbase;
90         int klingons;
91     } chart[GALSIZE+1][GALSIZE+1];      // the starchart (subscript 0 not used)
92 } snapshot;                             // Data that is snapshot
93
94 #define NKILLK (game.inkling - game.state.remkl)
95 #define NKILLC (game.incom - game.state.remcom)
96 #define NKILLSC (game.inscom - game.state.nscrem)
97 #define NKILLROM (game.inrom - game.state.nromrem)
98 #define KLINGREM (game.state.remkl + game.state.remcom + game.state.nscrem)
99 #define INKLINGTOT (game.inkling + game.incom + game.inscom)
100 #define KLINGKILLED (INKLINGTOT - KLINGREM)
101
102 #define SKILL_NONE      0
103 #define SKILL_NOVICE    1
104 #define SKILL_FAIR      2
105 #define SKILL_GOOD      3
106 #define SKILL_EXPERT    4
107 #define SKILL_EMERITUS  5
108
109 /* game options */
110 #define OPTION_ALL      0xffffffff
111 #define OPTION_TTY      0x00000001      /* old interface */
112 #define OPTION_CURSES   0x00000002      /* new interface */
113 #define OPTION_IOMODES  0x00000003      /* cover both interfaces */
114 #define OPTION_PLANETS  0x00000004      /* planets and mining */
115 #define OPTION_THOLIAN  0x00000008      /* Tholians and their webs */
116 #define OPTION_THINGY   0x00000010      /* Space Thingy can shoot back */
117 #define OPTION_PROBE    0x00000020      /* deep-space probes */
118 #define OPTION_SHOWME   0x00000040      /* bracket Enterprise in chart */
119 #define OPTION_RAMMING  0x00000080      /* enemies may ram Enterprise */
120 #define OPTION_MVBADDY  0x00000100      /* more enemies can move */
121 #define OPTION_BLKHOLE  0x00000200      /* black hole may timewarp you */
122 #define OPTION_BASE     0x00000400      /* bases have good shields */
123 #define OPTION_WORLDS   0x00000800      /* logic for inhabited worlds */
124 #define OPTION_PLAIN    0x01000000      /* user chose plain game */
125 #define OPTION_ALMY     0x02000000      /* user chose Almy variant */
126
127 /* Define devices */
128 #define DSRSENS 0
129 #define DLRSENS 1
130 #define DPHASER 2
131 #define DPHOTON 3
132 #define DLIFSUP 4
133 #define DWARPEN 5
134 #define DIMPULS 6
135 #define DSHIELD 7
136 #define DRADIO  8
137 #define DSHUTTL 9
138 #define DCOMPTR 10
139 #define DTRANSP 11
140 #define DSHCTRL 12
141 #define DDRAY   13  // Added deathray
142 #define DDSP    14  // Added deep space probe
143 #define NDEVICES (15)   // Number of devices
144
145 #define FOREVER 1e30
146
147 /* Define future events */
148 #define FSPY    0       // Spy event happens always (no future[] entry)
149                                         // can cause SC to tractor beam Enterprise
150 #define FSNOVA  1   // Supernova
151 #define FTBEAM  2   // Commander tractor beams Enterprise
152 #define FSNAP   3   // Snapshot for time warp
153 #define FBATTAK 4   // Commander attacks base
154 #define FCDBAS  5   // Commander destroys base
155 #define FSCMOVE 6   // Supercommander moves (might attack base)
156 #define FSCDBAS 7   // Supercommander destroys base
157 #define FDSPROB 8   // Move deep space probe
158 #ifndef EXPERIMENTAL
159 #define NEVENTS (9)
160 #else /* EXPERIMENTAL */
161 #define FDISTR  9   // Emit distress call from an inhabited world 
162 #define FENSLV  10  // Inhabited word is enslaved */
163 #define FREPRO  11  // Klingons build a ship in an enslaved system
164 #define NEVENTS (12)
165 #endif /* EXPERIMENTAL */
166
167 #ifdef EXPERIMENTAL
168 #define MAXDISTR        5       /* maximum concurrent distress calls */
169 #endif /* EXPERIMENTAL */
170
171 #define SSTMAGIC        "SST2.0\n"
172
173 struct game {
174     char magic[sizeof(SSTMAGIC)];
175     unsigned long options;
176     snapshot state;
177     snapshot snapsht;
178     char quad[QUADSIZE+1][QUADSIZE+1];          // contents of our quadrant
179     double kpower[(QUADSIZE+1)*(QUADSIZE+1)];           // enemy energy levels
180     double kdist[(QUADSIZE+1)*(QUADSIZE+1)];            // enemy distances
181     double kavgd[(QUADSIZE+1)*(QUADSIZE+1)];            // average distances
182     double damage[NDEVICES];    // damage encountered
183     double future[NEVENTS];     // future events
184     char passwd[10];            // Self Destruct password
185     int kx[(QUADSIZE+1)*(QUADSIZE+1)];                  // enemy sector locations
186     int ky[(QUADSIZE+1)*(QUADSIZE+1)];
187     int inkling,        // Initial number of klingons
188         inbase,         // Initial number of bases
189         incom,          // Initial number of commanders
190         inscom,         // Initial number of commanders
191         inrom,          // Initial number of commanders
192         instar,         // Initial stars
193         intorps,        // Initial/Max torpedoes
194         condit,         // Condition (red/yellow/green/docked)
195         torps,          // number of torpedoes
196         ship,           // Ship type -- 'E' is Enterprise
197         quadx,          // where we are
198         quady,          //
199         sectx,          // where we are
200         secty,          //
201         length,         // length of game
202         skill,          // skill level
203         basex,          // position of base in current quadrant
204         basey,          //
205         klhere,         // klingons here
206         comhere,        // commanders here
207         casual,         // causalties
208         nhelp,          // calls for help
209         nkinks,         // count of energy-barrier crossings
210         ididit,         // Action taken -- allows enemy to attack
211         gamewon,        // Finished!
212         alive,          // We are alive (not killed)
213         justin,         // just entered quadrant
214         alldone,        // game is now finished
215         shldchg,        // shield is changing (affects efficiency)
216         plnetx,         // location of planet in quadrant
217         plnety,         //
218         inorbit,        // orbiting
219         landed,         // party on planet (1), on ship (-1)
220         iplnet,         // planet # in quadrant
221         imine,          // mining
222         inplan,         // initial planets
223         nenhere,        // number of enemies in quadrant
224         ishere,         // super-commander in quandrant
225         neutz,          // Romulan Neutral Zone
226         irhere,         // Romulans in quadrant
227         icraft,         // Kirk in Galileo
228         ientesc,        // attempted escape from supercommander
229         iscraft,        // =1 if craft on ship, -1 if removed from game
230         isatb,          // =1 if super commander is attacking base
231         iscate,         // super commander is here
232 #ifdef DEBUG
233         idebug,         // debug mode
234 #endif
235         iattak,         // attack recursion elimination (was cracks[4])
236         icrystl,        // dilithium crystals aboard
237         tourn,          // tournament number
238         thawed,         // thawed game
239         batx,           // base coordinates being attacked
240         baty,           //
241         ithere,         // Tholian is here 
242         ithx,           // coordinates of Tholian
243         ithy,           //
244         iseenit,        // seen base attack report
245 #ifdef EXPERIMENTAL
246         ndistr,         //* count of distress calls */ 
247 #endif /* EXPERIMENTAL */
248         probecx,        // current probe quadrant
249         probecy,        //
250         proben,         // number of moves for probe
251         isarmed,        // probe is armed
252         nprobes;        // number of probes available
253     double inresor,     // initial resources
254         intime,         // initial time
255         inenrg,         // initial/max energy
256         inshld,         // initial/max shield
257         inlsr,          // initial life support resources
258         indate,         // initial date
259         energy,         // energy level
260         shield,         // shield level
261         shldup,         // shields are up
262         warpfac,        // warp speed
263         wfacsq,         // squared warp factor
264         lsupres,        // life support reserves
265         dist,           // movement distance
266         direc,          // movement direction
267         optime,         // time taken by current operation
268         docfac,         // repair factor when docking (constant?)
269         resting,        // rest time
270         damfac,         // damage factor
271         lastchart,      // time star chart was last updated
272         cryprob,        // probability that crystal will work
273         probex,         // location of probe
274         probey,         //
275         probeinx,       // probe x,y increment
276         probeiny,       //
277         height;         // height of orbit around planet
278 };
279 extern struct game game;
280
281 /* the following global state doesn't need to be saved */
282 extern char *device[NDEVICES];
283 extern int iscore, iskill; // Common PLAQ
284 extern double perdate;
285 extern double aaitem;
286 extern char citem[10];
287
288 /* the Space Thingy's global state should *not* be saved! */
289 extern int thingx, thingy, iqhere, iqengry;
290
291 typedef enum {FWON, FDEPLETE, FLIFESUP, FNRG, FBATTLE,
292               FNEG3, FNOVA, FSNOVAED, FABANDN, FDILITHIUM,
293                           FMATERIALIZE, FPHASER, FLOST, FMINING, FDPLANET,
294                           FPNOVA, FSSC, FSTRACTOR, FDRAY, FTRIBBLE,
295                           FHOLE} FINTYPE ;
296 enum loctype {neither, quadrant, sector};
297
298 #ifndef TRUE
299 #define TRUE (1)
300 #define FALSE (0)
301 #endif
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 int choose(int);
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(int);
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 int ja(void);
371 void cramen(int);
372 void crmshp(void);
373 char *cramlc(enum loctype, int, int);
374 double expran(double);
375 double Rand(void);
376 void iran(int, int *, int *);
377 #define square(i) ((i)*(i))
378 void dropin(int, int*, int*);
379 void newcnd(void);
380 void sortkl(void);
381 void imove(void);
382 void ram(int, int, int, int);
383 void crmena(int, int, int, int, int);
384 void deadkl(int, int, 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 *, int);
418 void makechart(void);
419 void enqueue(char *);
420 char *systemname(planet *);
421 void newkling(int, int *, int *);
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