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