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