13 #define SSTDOC DATA_DIR"/"DOC_NAME
15 #define SSTDOC DOC_NAME
18 #define _(str) gettext(str)
20 #define min(x, y) ((x)<(y)?(x):(y))
21 #define max(x, y) ((x)>(y)?(x):(y))
23 #define PHASEFAC (2.0)
25 #define NINHAB (GALSIZE * GALSIZE / 2)
26 #define MAXUNINHAB (10)
27 #define PLNETMAX (NINHAB + MAXUNINHAB)
32 * These macros hide the difference between 0-origin and 1-origin addressing.
33 * They're a step towards de-FORTRANizing the code.
35 #define VALID_QUADRANT(x, y) ((x)>=1 && (x)<=GALSIZE && (y)>=1 && (y)<=GALSIZE)
36 #define VALID_SECTOR(x, y) ((x)>=1 && (x)<=QUADSIZE && (y)>=1 && (y)<=QUADSIZE)
37 #define for_quadrants(i) for (i = 1; i <= GALSIZE; i++)
38 #define for_sectors(i) for (i = 1; i <= QUADSIZE; i++)
39 #define for_commanders(i) for (i = 1; i <= game.state.remcom; i++)
40 #define for_local_enemies(i) for (i = 1; i <= game.nenhere; i++)
41 #define for_starbases(i) for (i = 1; i <= game.state.rembase; i++)
43 typedef struct {int x; int y;} coord;
45 #define square(i) ((i)*(i))
46 #define same(c1, c2) ((c1.x == c2.x) && (c1.y == c2.y))
47 #define distance(c1, c2) sqrt(square(c1.x - c2.x) + square(c1.y - c2.y))
51 enum {M=0, N=1, O=2} pclass;
52 int inhabited; /* if NZ, an index into a name array */
53 #define UNINHABITED -1
54 int crystals; /* has crystals */
55 #define MINED -1 /* used to have crystals, but they were mined out */
56 enum {unknown, known, shuttle_down} known;
59 #define DESTROY(pl) memset(pl, '\0', sizeof(planet))
83 bool snap; // snapshot taken
84 int crew, // crew complement
85 #define FULLCREW 428 /* BSD Trek was 387, that's wrong */
86 remkl, // remaining klingons
87 remcom, // remaining commanders
88 nscrem, // remaining super commanders
89 rembase, // remaining bases
90 starkl, // destroyed stars
91 basekl, // destroyed bases
92 nromrem, // Romulans remaining
93 nplankl, // destroyed uninhabited planets
94 nworldkl; // destroyed inhabited planets
95 planet plnets[PLNETMAX]; // Planet information
96 double date, // stardate
97 remres, // remaining resources
98 remtime; // remaining time
99 coord baseq[BASEMAX+1]; // Base quadrant coordinates
100 coord kcmdr[QUADSIZE+1]; // Commander quadrant coordinates
101 coord kscmdr; // Supercommander quadrant coordinates
111 enum {secure, distressed, enslaved} status;
112 } galaxy[GALSIZE+1][GALSIZE+1]; // The Galaxy (subscript 0 not used)
117 } chart[GALSIZE+1][GALSIZE+1]; // the starchart (subscript 0 not used)
118 } snapshot; // Data that is snapshot
120 #define MAXKLGAME 127
123 #define NKILLK (game.inkling - game.state.remkl)
124 #define NKILLC (game.incom - game.state.remcom)
125 #define NKILLSC (game.inscom - game.state.nscrem)
126 #define NKILLROM (game.inrom - game.state.nromrem)
127 #define KLINGREM (game.state.remkl + game.state.remcom + game.state.nscrem)
128 #define INKLINGTOT (game.inkling + game.incom + game.inscom)
129 #define KLINGKILLED (INKLINGTOT - KLINGREM)
132 #define OPTION_ALL 0xffffffff
133 #define OPTION_TTY 0x00000001 /* old interface */
134 #define OPTION_CURSES 0x00000002 /* new interface */
135 #define OPTION_IOMODES 0x00000003 /* cover both interfaces */
136 #define OPTION_PLANETS 0x00000004 /* planets and mining */
137 #define OPTION_THOLIAN 0x00000008 /* Tholians and their webs */
138 #define OPTION_THINGY 0x00000010 /* Space Thingy can shoot back */
139 #define OPTION_PROBE 0x00000020 /* deep-space probes */
140 #define OPTION_SHOWME 0x00000040 /* bracket Enterprise in chart */
141 #define OPTION_RAMMING 0x00000080 /* enemies may ram Enterprise */
142 #define OPTION_MVBADDY 0x00000100 /* more enemies can move */
143 #define OPTION_BLKHOLE 0x00000200 /* black hole may timewarp you */
144 #define OPTION_BASE 0x00000400 /* bases have good shields */
145 #define OPTION_WORLDS 0x00000800 /* logic for inhabited worlds */
146 #define OPTION_PLAIN 0x01000000 /* user chose plain game */
147 #define OPTION_ALMY 0x02000000 /* user chose Almy variant */
166 #define NDEVICES (16) // Number of devices
168 #define damaged(dev) (game.damage[dev] != 0.0)
172 /* Define future events */
173 #define FSPY 0 // Spy event happens always (no future[] entry)
174 // can cause SC to tractor beam Enterprise
175 #define FSNOVA 1 // Supernova
176 #define FTBEAM 2 // Commander tractor beams Enterprise
177 #define FSNAP 3 // Snapshot for time warp
178 #define FBATTAK 4 // Commander attacks base
179 #define FCDBAS 5 // Commander destroys base
180 #define FSCMOVE 6 // Supercommander moves (might attack base)
181 #define FSCDBAS 7 // Supercommander destroys base
182 #define FDSPROB 8 // Move deep space probe
183 #define FDISTR 9 // Emit distress call from an inhabited world
184 #define FENSLV 10 // Inhabited word is enslaved */
185 #define FREPRO 11 // Klingons build a ship in an enslaved system
194 * abstract out the event handling -- underlying data structures will change
195 * when we implement stateful events
197 extern event *unschedule(int);
198 extern int is_scheduled(int);
199 extern event *schedule(int, double);
200 extern void postpone(int, double);
201 extern double scheduled(int);
202 #define findevent(evtype) &game.future[evtype]
204 #define SSTMAGIC "SST2.0\n"
207 char magic[sizeof(SSTMAGIC)];
208 unsigned long options;
211 feature quad[QUADSIZE+1][QUADSIZE+1]; // contents of our quadrant
212 double kpower[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy energy levels
213 double kdist[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy distances
214 double kavgd[(QUADSIZE+1)*(QUADSIZE+1)]; // average distances
215 double damage[NDEVICES]; // damage encountered
216 event future[NEVENTS]; // future events
217 char passwd[10]; // Self Destruct password
218 coord ks[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy sector locations
219 coord quadrant, sector; // where we are
220 coord tholian; // coordinates of Tholian
221 coord base; // position of base in current quadrant
222 coord battle; // base coordinates being attacked
223 coord plnet; // location of planet in quadrant
224 coord probec; // current probe quadrant
225 bool gamewon, // Finished!
226 ididit, // action taken -- allows enemy to attack
227 alive, // we are alive (not killed)
228 justin, // just entered quadrant
229 shldup, // shields are up
230 shldchg, // shield is changing (affects efficiency)
231 comhere, // commander here
232 ishere, // super-commander in quadrant
233 iscate, // super commander is here
234 ientesc, // attempted escape from supercommander
235 ithere, // Tholian is here
236 resting, // rest time
237 icraft, // Kirk in Galileo
238 landed, // party on planet (true), on ship (false)
239 alldone, // game is now finished
240 neutz, // Romulan Neutral Zone
241 isarmed, // probe is armed
242 inorbit, // orbiting a planet
244 icrystl, // dilithium crystals aboard
245 iseenit, // seen base attack report
246 thawed; // thawed game
253 } condition; // condition (red/yellow/green/docked)
258 } iscraft; // 'onship' if craft on ship, 'removed' if out of game
266 } skill; // skill level
267 int inkling, // initial number of klingons
268 inbase, // initial number of bases
269 incom, // initial number of commanders
270 inscom, // initial number of commanders
271 inrom, // initial number of commanders
272 instar, // initial stars
273 intorps, // initial/max torpedoes
274 torps, // number of torpedoes
275 ship, // ship type -- 'E' is Enterprise
276 abandoned, // count of crew abandoned in space
277 length, // length of game
278 klhere, // klingons here
279 casual, // causalties
280 nhelp, // calls for help
281 nkinks, // count of energy-barrier crossings
282 iplnet, // planet # in quadrant
283 inplan, // initial planets
284 nenhere, // number of enemies in quadrant
285 irhere, // Romulans in quadrant
286 isatb, // =1 if super commander is attacking base
287 iattak, // attack recursion elimination (was cracks[4])
288 tourn, // tournament number
289 proben, // number of moves for probe
290 nprobes; // number of probes available
291 double inresor, // initial resources
292 intime, // initial time
293 inenrg, // initial/max energy
294 inshld, // initial/max shield
295 inlsr, // initial life support resources
296 indate, // initial date
297 energy, // energy level
298 shield, // shield level
299 warpfac, // warp speed
300 wfacsq, // squared warp factor
301 lsupres, // life support reserves
302 dist, // movement distance
303 direc, // movement direction
304 optime, // time taken by current operation
305 docfac, // repair factor when docking (constant?)
306 damfac, // damage factor
307 lastchart, // time star chart was last updated
308 cryprob, // probability that crystal will work
309 probex, // location of probe
311 probeinx, // probe x,y increment
313 height; // height of orbit around planet
315 extern struct game game;
317 /* the following global state doesn't need to be saved */
318 extern char *device[NDEVICES];
319 extern char *systnames[NINHAB + 1];
320 extern int iscore, iskill; // Common PLAQ
321 extern double perdate;
322 extern double aaitem;
323 extern char citem[10];
326 extern FILE *logfp, *replayfp;
328 /* the Space Thingy's global state should *not* be saved! */
330 extern bool iqhere, iqengry;
333 FWON, FDEPLETE, FLIFESUP, FNRG, FBATTLE,
334 FNEG3, FNOVA, FSNOVAED, FABANDN, FDILITHIUM,
335 FMATERIALIZE, FPHASER, FLOST, FMINING, FDPLANET,
336 FPNOVA, FSSC, FSTRACTOR, FDRAY, FTRIBBLE,
340 enum loctype {neither, quadrant, sector};
349 /* Function prototypes */
356 void srscan(scantype);
374 void finish(FINTYPE);
375 void selfdestruct(void);
387 void prout(char *, ...);
388 void proutn(char *, ...);
392 void cramen(feature);
394 char *cramlc(enum loctype, coord w);
395 double expran(double);
397 coord randplace(int);
398 coord dropin(feature);
402 void ram(bool, feature, coord);
403 void crmena(bool, feature, enum loctype, coord w);
404 void deadkl(coord, feature, coord);
407 void torpedo(double, double, coord, double *, int, int);
409 void pause_game(bool);
411 void snova(bool, coord *);
413 void hittem(double *);
414 void prouts(char *, ...);
422 void usecrystals(void);
426 void attakreport(bool);
430 void setwnd(WINDOW *);
433 void tracktorpedo(coord, int, int, int, int);
434 void cgetline(char *, int);
436 void setpassword(void);
437 void commandhook(char *, bool);
438 void makechart(void);
439 void enqueue(char *);
445 extern WINDOW *curwnd;
446 extern WINDOW *fullscreen_window;
447 extern WINDOW *srscan_window;
448 extern WINDOW *report_window;
449 extern WINDOW *lrscan_window;
450 extern WINDOW *message_window;
451 extern WINDOW *prompt_window;
453 extern void clreol(void);
454 extern void clrscr(void);
455 extern void textcolor(int);
456 extern void highvideo(void);
460 BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY,
461 DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE