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