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