More magic-number chasing, and the "Bases left" report.
[super-star-trek.git] / sst.h
1 #include <stdio.h>
2 #include <math.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <curses.h>
6 #ifndef INCLUDED
7 #define EXTERN extern
8 #else
9 #define EXTERN
10 #endif
11
12 #define min(x, y)       ((x)<(y)?(x):(y))
13 #define max(x, y)       ((x)>(y)?(x):(y))
14
15 // #define DEBUG
16
17 #define NDEVICES (15)   // Number of devices
18 #define PHASEFAC (2.0)
19 #define PLNETMAX (10)
20 #define NEVENTS (8)
21 #define GALSIZE (8)
22 #define QUADSIZE (10)
23 #define BASEMAX (6)
24
25 typedef struct {
26     int x;      /* Quadrant location of planet */
27     int y;
28     enum {M=0, N=1, O=2} pclass;
29     int crystals; /* has crystals */
30     enum {unknown, known, shuttle_down} known;
31 } planet;
32
33 #define DESTROY(pl)     memset(pl, '\0', sizeof(planet))
34
35 typedef struct {
36     int snap,           // snapshot taken
37         remkl,                  // remaining klingons
38         remcom,                 // remaining commanders
39         rembase,                // remaining bases
40         starkl,                 // destroyed stars
41         basekl,                 // destroyed bases
42         killk,                  // Klingons killed
43         killc,                  // commanders killed
44         galaxy[GALSIZE+1][GALSIZE+1],   // The Galaxy (subscript 0 not used)
45         cx[QUADSIZE+1],cy[QUADSIZE+1],  // Commander quadrant coordinates
46         baseqx[BASEMAX],                // Base quadrant X
47         baseqy[BASEMAX],                // Base quadrant Y
48         newstuf[GALSIZE+1][GALSIZE+1],  // Extended galaxy goodies
49         isx, isy,               // Coordinate of Super Commander
50         nscrem,                 // remaining super commanders
51         nromkl,                 // Romulans killed
52         nromrem,                // Romulans remaining
53         nsckill,                // super commanders killed
54         nplankl;                // destroyed planets
55         planet plnets[PLNETMAX];  // Planet information
56         double date,            // stardate
57             remres,             // remaining resources
58             remtime;            // remaining time
59 } snapshot;                             // Data that is snapshot
60
61 /*
62  * This is how the integers in galaxy are encoded.
63  * Someday these should turn into structure fields.
64  */
65 #define SUPERNOVA_PLACE 1000
66 #define ENEMY_PLACE     100
67 #define BASE_PLACE      10
68 #define STAR_PLACE      1
69
70 /* for newstuff */
71 #define ROMULAN_PLACE   10
72
73 /* for starch */
74 #define CHART_UNKNOWN   -1
75
76 // Scalar variables that are needed for freezing the game
77 // are placed in a structure. #defines are used to access by their
78 // original names. Gee, I could have done this with the d structure,
79 // but I just didn't think of it back when I started.
80
81 #define SSTMAGIC        "SST2.0\n"
82
83 EXTERN WINDOW *curwnd;
84
85 EXTERN struct {
86     char magic[sizeof(SSTMAGIC)];
87     snapshot state;
88     snapshot snapsht;
89     char quad[QUADSIZE+1][QUADSIZE+1];          // contents of our quadrant
90     double kpower[(QUADSIZE+1)*(QUADSIZE+1)];           // enemy energy levels
91     double kdist[(QUADSIZE+1)*(QUADSIZE+1)];            // enemy distances
92     double kavgd[(QUADSIZE+1)*(QUADSIZE+1)];            // average distances
93     double damage[NDEVICES+1];  // damage encountered
94     double future[NEVENTS+1];   // future events
95     char passwd[10];            // Self Destruct password
96     int kx[(QUADSIZE+1)*(QUADSIZE+1)];                  // enemy sector locations
97     int ky[(QUADSIZE+1)*(QUADSIZE+1)];
98     int starch[GALSIZE+1][GALSIZE+1];           // star chart
99     /* members with macro definitions start here */
100     int inkling,
101         inbase,
102         incom,
103         instar,
104         intorps,
105         condit,
106         torps,
107         ship,
108         quadx,
109         quady,
110         sectx,
111         secty,
112         length,
113         skill,
114         basex,
115         basey,
116         klhere,
117         comhere,
118         casual,
119         nhelp,
120         nkinks,
121         ididit,
122         gamewon,
123         alive,
124         justin,
125         alldone,
126         shldchg,
127         thingx,
128         thingy,
129         plnetx,
130         plnety,
131         inorbit,
132         landed,
133         iplnet,
134         imine,
135         inplan,
136         nenhere,
137         ishere,
138         neutz,
139         irhere,
140         icraft,
141         ientesc,
142         iscraft,
143         isatb,
144         iscate,
145 #ifdef DEBUG
146         idebug,
147 #endif
148         iattak,
149         icrystl,
150         tourn,
151         thawed,
152         batx,
153         baty,
154         ithere,
155         iqhere,
156         iqengry,
157         ithx,
158         ithy,
159         iseenit,
160         probecx,
161         probecy,
162         proben,
163         isarmed,
164         nprobes;
165     double inresor,
166         intime,
167         inenrg,
168         inshld,
169         inlsr,
170         indate,
171         energy,
172         shield,
173         shldup,
174         warpfac,
175         wfacsq,
176         lsupres,
177         dist,
178         direc,
179         Time,
180         docfac,
181         resting,
182         damfac,
183         stdamtim,
184         cryprob,
185         probex,
186         probey,
187         probeinx,
188         probeiny;
189 } game;
190
191 #define inkling game.inkling            // Initial number of klingons
192 #define inbase game.inbase                      // Initial number of bases
193 #define incom game.incom                        // Initian number of commanders
194 #define instar game.instar                      // Initial stars
195 #define intorps game.intorps            // Initial/Max torpedoes
196 #define condit game.condit                      // Condition (red, yellow, green docked)
197 #define torps game.torps                        // number of torpedoes
198 #define ship game.ship                          // Ship type -- 'E' is Enterprise
199 #define quadx game.quadx                        // where we are
200 #define quady game.quady                        //
201 #define sectx game.sectx                        // where we are
202 #define secty game.secty                        //
203 #define length game.length                      // length of game
204 #define skill game.skill                        // skill level
205 #define basex game.basex                        // position of base in current quad
206 #define basey game.basey                        //
207 #define klhere game.klhere                      // klingons here
208 #define comhere game.comhere            // commanders here
209 #define casual game.casual                      // causalties
210 #define nhelp game.nhelp                        // calls for help
211 #define nkinks game.nkinks                      //
212 #define ididit game.ididit                      // Action taken -- allows enemy to attack
213 #define gamewon game.gamewon            // Finished!
214 #define alive game.alive                        // We are alive (not killed)
215 #define justin game.justin                      // just entered quadrant
216 #define alldone game.alldone            // game is now finished
217 #define shldchg game.shldchg            // shield is changing (affects efficiency)
218 #define thingx game.thingx                      // location of strange object in galaxy
219 #define thingy game.thingy                      //
220 #define plnetx game.plnetx                      // location of planet in quadrant
221 #define plnety game.plnety                      //
222 #define inorbit game.inorbit            // orbiting
223 #define landed game.landed                      // party on planet (1), on ship (-1)
224 #define iplnet game.iplnet                      // planet # in quadrant
225 #define imine game.imine                        // mining
226 #define inplan game.inplan                      // initial planets
227 #define nenhere game.nenhere            // Number of enemies in quadrant
228 #define ishere game.ishere                      // Super-commander in quandrant
229 #define neutz game.neutz                        // Romulan Neutral Zone
230 #define irhere game.irhere                      // Romulans in quadrant
231 #define iqhere game.iqhere                      // Thing in quadrant
232 #define iqengry game.iqengry                    // Thing attacking
233 #define icraft game.icraft                      // Kirk in Galileo
234 #define ientesc game.ientesc            // Attempted escape from supercommander
235 #define iscraft game.iscraft            // =1 if craft on ship, -1 if removed from game
236 #define isatb game.isatb                        // =1 if SuperCommander is attacking base
237 #define iscate game.iscate                      // Super Commander is here
238 #ifdef DEBUG
239 #define idebug game.idebug                      // Debug mode
240 #endif
241 #define iattak game.iattak                      // attack recursion elimination (was cracks[4])
242 #define icrystl game.icrystl            // dilithium crystals aboard
243 #define tourn game.tourn                        // Tournament number
244 #define thawed game.thawed                      // Thawed game
245 #define batx game.batx                          // Base coordinates being attacked
246 #define baty game.baty                          //
247 #define ithere game.ithere                      // Tholean is here 
248 #define ithx game.ithx                          // coordinates of tholean
249 #define ithy game.ithy
250 #define iseenit game.iseenit            // Seen base attack report
251 #define inresor game.inresor            // initial resources
252 #define intime game.intime                      // initial time
253 #define inenrg game.inenrg                      // Initial/Max Energy
254 #define inshld game.inshld                      // Initial/Max Shield
255 #define inlsr game.inlsr                        // initial life support resources
256 #define indate game.indate                      // Initial date
257 #define energy game.energy                      // Energy level
258 #define shield game.shield                      // Shield level
259 #define shldup game.shldup                      // Shields are up
260 #define warpfac game.warpfac            // Warp speed
261 #define wfacsq game.wfacsq                      // squared warp factor
262 #define lsupres game.lsupres            // life support reserves
263 #define dist game.dist                          // movement distance
264 #define direc game.direc                        // movement direction
265 #define Time game.Time                          // time taken by current operation
266 #define docfac game.docfac                      // repair factor when docking (constant?)
267 #define resting game.resting            // rest time
268 #define damfac game.damfac                      // damage factor
269 #define stdamtim game.stdamtim          // time that star chart was damaged
270 #define cryprob game.cryprob            // probability that crystal will work
271 #define probex game.probex                      // location of probe
272 #define probey game.probey
273 #define probecx game.probecx            // current probe quadrant
274 #define probecy game.probecy    
275 #define probeinx game.probeinx          // Probe x,y increment
276 #define probeiny game.probeiny          
277 #define proben game.proben                      // number of moves for probe
278 #define isarmed game.isarmed            // Probe is armed
279 #define nprobes game.nprobes            // number of probes available
280
281 /* the following global state doesn't need to be saved */
282 EXTERN char     *device[NDEVICES+1];
283 EXTERN int iscore, iskill; // Common PLAQ
284 EXTERN double perdate;
285 EXTERN double aaitem;
286 EXTERN char citem[10];
287
288 typedef enum {FWON, FDEPLETE, FLIFESUP, FNRG, FBATTLE,
289               FNEG3, FNOVA, FSNOVAED, FABANDN, FDILITHIUM,
290                           FMATERIALIZE, FPHASER, FLOST, FMINING, FDPLANET,
291                           FPNOVA, FSSC, FSTRACTOR, FDRAY, FTRIBBLE,
292                           FHOLE} FINTYPE ;
293 enum loctype {neither, quadrant, sector};
294
295 /* Define devices */
296 #define DSRSENS 1
297 #define DLRSENS 2
298 #define DPHASER 3
299 #define DPHOTON 4
300 #define DLIFSUP 5
301 #define DWARPEN 6
302 #define DIMPULS 7
303 #define DSHIELD 8
304 #define DRADIO  9
305 #define DSHUTTL 10
306 #define DCOMPTR 11
307 #define DTRANSP 12
308 #define DSHCTRL 13
309 #define DDRAY   14  // Added deathray
310 #define DDSP    15  // Added deep space probe
311
312 /* Define future events */
313 #define FSPY    0       // Spy event happens always (no future[] entry)
314                                         // can cause SC to tractor beam Enterprise
315 #define FSNOVA  1   // Supernova
316 #define FTBEAM  2   // Commander tractor beams Enterprise
317 #define FSNAP   3   // Snapshot for time warp
318 #define FBATTAK 4   // Commander attacks base
319 #define FCDBAS  5   // Commander destroys base
320 #define FSCMOVE 6   // Supercommander moves (might attack base)
321 #define FSCDBAS 7   // Supercommander destroys base
322 #define FDSPROB 8   // Move deep space probe
323
324 #ifdef INCLUDED
325 char *device[NDEVICES+1] = {
326         "",
327         "S. R. Sensors",
328         "L. R. Sensors",
329         "Phasers",
330         "Photon Tubes",
331         "Life Support",
332         "Warp Engines",
333         "Impulse Engines",
334         "Shields",
335         "Subspace Radio",
336         "Shuttle Craft",
337         "Computer",
338         "Transporter",
339         "Shield Control",
340     "Death Ray",
341     "D. S. Probe"};                                                                     
342 #endif
343
344 #ifndef TRUE
345 #define TRUE (1)
346 #define FALSE (0)
347 #endif
348
349 #define IHR 'R'
350 #define IHK 'K'
351 #define IHC 'C'
352 #define IHS 'S'
353 #define IHSTAR '*'
354 #define IHP 'P'
355 #define IHB 'B'
356 #define IHBLANK ' '
357 #define IHDOT '.'
358 #define IHQUEST '?'
359 #define IHE 'E'
360 #define IHF 'F'
361 #define IHT 'T'
362 #define IHWEB '#'
363 #define IHGREEN 'G'
364 #define IHYELLOW 'Y'
365 #define IHRED 'R'
366 #define IHDOCKED 'D'
367 #define IHDEAD 'Z'
368 #define IHMATER0 '-'
369 #define IHMATER1 'o'
370 #define IHMATER2 '0'
371
372
373 /* Function prototypes */
374 void prelim(void);
375 void attack(int);
376 int choose(int);
377 void setup(int);
378 void score(void);
379 void atover(int);
380 int srscan(int);
381 void lrscan(void);
382 void phasers(void);
383 void photon(void);
384 void warp(int);
385 void doshield(int);
386 void dock(int);
387 void dreprt(void);
388 void chart(int);
389 void impuls(void);
390 void wait(void);
391 void setwrp(void);
392 void events(void);
393 void report(void);
394 void eta(void);
395 void help(void);
396 void abandn(void);
397 void finish(FINTYPE);
398 void dstrct(void);
399 void kaboom(void);
400 void freeze(int);
401 int thaw(void);
402 void plaque(void);
403 int scan(void);
404 #define IHEOL (0)
405 #define IHALPHA (1)
406 #define IHREAL (2)
407 void chew(void);
408 void chew2(void);
409 void skip(int);
410 void prout(char *, ...);
411 void proutn(char *, ...);
412 void stars(void);
413 void newqad(int);
414 int ja(void);
415 void cramen(int);
416 void crmshp(void);
417 char *cramlc(enum loctype, int, int);
418 double expran(double);
419 double Rand(void);
420 void iran8(int *, int *);
421 void iran10(int *, int *);
422 #define square(i) ((i)*(i))
423 void dropin(int, int*, int*);
424 void newcnd(void);
425 void sortkl(void);
426 void imove(void);
427 void ram(int, int, int, int);
428 void crmena(int, int, int, int, int);
429 void deadkl(int, int, int, int, int);
430 void timwrp(void);
431 void movcom(void);
432 void torpedo(double, double, int, int, double *, int, int, int);
433 void huh(void);
434 void pause_game(int);
435 void nova(int, int);
436 void snova(int, int);
437 void scom(int *);
438 void hittem(double *);
439 void prouts(char *, ...);
440 int isit(char *);
441 void preport(void);
442 void orbit(void);
443 void sensor(void);
444 void drawmaps(short);
445 void beam(void);
446 void mine(void);
447 void usecrystals(void);
448 void shuttle(void);
449 void deathray(void);
450 void debugme(void);
451 void attakreport(int);
452 void movetho(void);
453 void probe(void);
454 void iostart(int);
455 void setwnd(WINDOW *);
456 void warble(void);
457 void boom(int ii, int jj);
458 void tracktorpedo(int x, int y, int ix, int iy, int wait, int l, int i, int n, int iquad);
459 void cgetline(char *, int);
460 void waitfor(void);
461 void setpassword(void);
462 void commandhook(char *, int);
463 void makechart(void);
464 void enqueue(char *);
465
466 /* mode arguments for srscan() */
467 #define SCAN_FULL               1
468 #define SCAN_REQUEST            2
469 #define SCAN_STATUS             3
470 #define SCAN_NO_LEFTSIDE        4
471
472 WINDOW *fullscreen_window;
473 WINDOW *srscan_window;
474 WINDOW *report_window;
475 WINDOW *lrscan_window;
476 WINDOW *message_window;
477 WINDOW *prompt_window;
478
479 extern void clreol(void);
480 extern void clrscr(void);
481 extern void textcolor(int color);
482 extern void highvideo(void);
483
484 enum COLORS {
485    DEFAULT,
486    BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY,
487    DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE
488 };
489
490 #define DAMAGED 128     /* marker for damaged ship in starmap */