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