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