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