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))
25 #define NINHAB (GALSIZE * GALSIZE / 2)
27 #define PLNETMAX (NINHAB + MAXUNINHAB)
29 #define BASEMAX (GALSIZE * GALSIZE / 12)
34 * These macros hide the difference between 0-origin and 1-origin addressing.
35 * They're a step towards de-FORTRANizing the code.
37 #define VALID_QUADRANT(x, y) ((x)>=1 && (x)<=GALSIZE && (y)>=1 && (y)<=GALSIZE)
38 #define VALID_SECTOR(x, y) ((x)>=1 && (x)<=QUADSIZE && (y)>=1 && (y)<=QUADSIZE)
39 #define for_quadrants(i) for (i = 1; i <= GALSIZE; i++)
40 #define for_sectors(i) for (i = 1; i <= QUADSIZE; i++)
41 #define for_commanders(i) for (i = 1; i <= game.state.remcom; i++)
42 #define for_local_enemies(i) for (i = 1; i <= game.nenhere; i++)
43 #define for_starbases(i) for (i = 1; i <= game.state.rembase; i++)
45 typedef struct {int x; int y;} coord;
47 #define square(i) ((i)*(i))
48 #define same(c1, c2) ((c1.x == c2.x) && (c1.y == c2.y))
49 #define distance(c1, c2) sqrt(square(c1.x - c2.x) + square(c1.y - c2.y))
50 #define invalidate(w) w.x = w.y = 0
51 #define is_valid(w) (w.x != 0 && w.y != 0)
55 enum {M=0, N=1, O=2} pclass;
56 int inhabited; /* if NZ, an index into a name array */
57 #define UNINHABITED -1
58 enum {mined=-1, present=0, absent=1} crystals; /* has crystals */
59 enum {unknown, known, shuttle_down} known;
62 #define DESTROY(pl) memset(pl, '\0', sizeof(planet))
86 bool snap; // snapshot taken
87 int crew, // crew complement
88 #define FULLCREW 428 /* BSD Trek was 387, that's wrong */
89 remkl, // remaining klingons
90 remcom, // remaining commanders
91 nscrem, // remaining super commanders
92 rembase, // remaining bases
93 starkl, // destroyed stars
94 basekl, // destroyed bases
95 nromrem, // Romulans remaining
96 nplankl, // destroyed uninhabited planets
97 nworldkl; // destroyed inhabited planets
98 planet planets[PLNETMAX]; // Planet information
99 double date, // stardate
100 remres, // remaining resources
101 remtime; // remaining time
102 coord baseq[BASEMAX+1]; // Base quadrant coordinates
103 coord kcmdr[QUADSIZE+1]; // Commander quadrant coordinates
104 coord kscmdr; // Supercommander quadrant coordinates
114 enum {secure, distressed, enslaved} status;
115 } galaxy[GALSIZE+1][GALSIZE+1]; // The Galaxy (subscript 0 not used)
120 } chart[GALSIZE+1][GALSIZE+1]; // the starchart (subscript 0 not used)
121 } snapshot; // Data that is snapshot
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"
206 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
209 char magic[sizeof(SSTMAGIC)];
210 unsigned long options;
213 feature quad[QUADSIZE+1][QUADSIZE+1]; // contents of our quadrant
214 double kpower[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy energy levels
215 double kdist[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy distances
216 double kavgd[(QUADSIZE+1)*(QUADSIZE+1)]; // average distances
217 double damage[NDEVICES]; // damage encountered
218 event future[NEVENTS]; // future events
219 char passwd[10]; // Self Destruct password
220 coord ks[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy sector locations
221 coord quadrant, sector; // where we are
222 coord tholian; // coordinates of Tholian
223 coord base; // position of base in current quadrant
224 coord battle; // base coordinates being attacked
225 coord plnet; // location of planet in quadrant
226 coord probec; // current probe quadrant
227 bool gamewon, // Finished!
228 ididit, // action taken -- allows enemy to attack
229 alive, // we are alive (not killed)
230 justin, // just entered quadrant
231 shldup, // shields are up
232 shldchg, // shield is changing (affects efficiency)
233 comhere, // commander here
234 ishere, // super-commander in quadrant
235 iscate, // super commander is here
236 ientesc, // attempted escape from supercommander
237 ithere, // Tholian is here
238 resting, // rest time
239 icraft, // Kirk in Galileo
240 landed, // party on planet (true), on ship (false)
241 alldone, // game is now finished
242 neutz, // Romulan Neutral Zone
243 isarmed, // probe is armed
244 inorbit, // orbiting a planet
246 icrystl, // dilithium crystals aboard
247 iseenit, // seen base attack report
248 thawed; // thawed game
255 } condition; // condition (red/yellow/green/docked)
260 } iscraft; // 'onship' if craft on ship, 'removed' if out of game
268 } skill; // skill level
269 int inkling, // initial number of klingons
270 inbase, // initial number of bases
271 incom, // initial number of commanders
272 inscom, // initial number of commanders
273 inrom, // initial number of commanders
274 instar, // initial stars
275 intorps, // initial/max torpedoes
276 torps, // number of torpedoes
277 ship, // ship type -- 'E' is Enterprise
278 abandoned, // count of crew abandoned in space
279 length, // length of game
280 klhere, // klingons here
281 casual, // causalties
282 nhelp, // calls for help
283 nkinks, // count of energy-barrier crossings
284 iplnet, // planet # in quadrant
285 inplan, // initial planets
286 nenhere, // number of enemies in quadrant
287 irhere, // Romulans in quadrant
288 isatb, // =1 if super commander is attacking base
289 tourn, // tournament number
290 proben, // number of moves for probe
291 nprobes; // number of probes available
292 double inresor, // initial resources
293 intime, // initial time
294 inenrg, // initial/max energy
295 inshld, // initial/max shield
296 inlsr, // initial life support resources
297 indate, // initial date
298 energy, // energy level
299 shield, // shield level
300 warpfac, // warp speed
301 wfacsq, // squared warp factor
302 lsupres, // life support reserves
303 dist, // movement distance
304 direc, // movement direction
305 optime, // time taken by current operation
306 docfac, // repair factor when docking (constant?)
307 damfac, // damage factor
308 lastchart, // time star chart was last updated
309 cryprob, // probability that crystal will work
310 probex, // location of probe
312 probeinx, // probe x,y increment
314 height; // height of orbit around planet
316 extern struct game game;
318 /* the following global state doesn't need to be saved */
319 extern char *device[NDEVICES];
320 extern char *systnames[NINHAB + 1];
321 extern int iscore, iskill; // Common PLAQ
322 extern double perdate;
323 extern double aaitem;
324 extern char citem[10];
327 extern FILE *logfp, *replayfp;
329 /* the Space Thingy's global state should *not* be saved! */
331 extern bool iqhere, iqengry;
334 FWON, FDEPLETE, FLIFESUP, FNRG, FBATTLE,
335 FNEG3, FNOVA, FSNOVAED, FABANDN, FDILITHIUM,
336 FMATERIALIZE, FPHASER, FLOST, FMINING, FDPLANET,
337 FPNOVA, FSSC, FSTRACTOR, FDRAY, FTRIBBLE,
341 enum loctype {neither, quadrant, sector};
343 /* Function prototypes */
344 extern void prelim(void);
345 extern void attack(bool);
346 extern bool choose(bool);
347 extern void setup(bool);
348 extern void score(void);
349 extern void atover(bool);
350 extern void srscan(void);
351 extern void lrscan(void);
352 extern void phasers(void);
353 extern void photon(void);
354 extern void warp(bool);
355 extern void doshield(bool);
356 extern void dock(bool);
357 extern void dreprt(void);
358 extern void chart(void);
359 extern void rechart(void);
360 extern void impuls(void);
361 extern void wait(void);
362 extern void setwrp(void);
363 extern void events(void);
364 extern void report(void);
365 extern void eta(void);
366 extern void mayday(void);
367 extern void abandn(void);
368 extern void finish(FINTYPE);
369 extern void selfdestruct(void);
370 extern void kaboom(void);
371 extern void freeze(bool);
372 extern bool thaw(void);
373 extern void plaque(void);
374 extern int scan(void);
375 extern void status(int req);
376 extern void request(void);
380 extern void chew(void);
381 extern void chew2(void);
382 extern void skip(int);
383 extern void prout(const char *, ...) __attribute__((format(printf, 1, 2)));
384 extern void proutn(const char *, ...) __attribute__((format(printf, 1, 2)));
385 extern void prouts(const char *, ...) __attribute__((format(printf, 1, 2)));
386 extern void prstat(const char *txt, const char *fmt, ...)
387 __attribute__((format(printf, 2, 3)));
388 extern void stars(void);
389 extern void newqad(bool);
390 extern bool ja(void);
391 extern void cramen(feature);
392 extern void crmshp(void);
393 extern char *cramlc(enum loctype, coord w);
394 extern double expran(double);
395 extern double Rand(void);
396 extern coord randplace(int);
397 extern coord dropin(feature);
398 extern void newcnd(void);
399 extern void sortkl(void);
400 extern void imove(bool);
401 extern void ram(bool, feature, coord);
402 extern void crmena(bool, feature, enum loctype, coord w);
403 extern void deadkl(coord, feature, coord);
404 extern void timwrp(void);
405 extern void moveklings(void);
406 extern void torpedo(double, double, coord, double *, int, int);
407 extern void huh(void);
408 extern void pause_reset(void);
409 extern void pause_game(bool);
410 extern void nova(coord);
411 extern void snova(bool, coord *);
412 extern void scom(void);
413 extern void hittem(double *);
414 extern bool isit(char *);
415 extern void preport(void);
416 extern void orbit(void);
417 extern void sensor(void);
418 extern void drawmaps(int);
419 extern void beam(void);
420 extern void mine(void);
421 extern void usecrystals(void);
422 extern void shuttle(void);
423 extern void deathray(void);
424 extern void debugme(void);
425 extern void attakreport(bool);
426 extern void movetho(void);
427 extern void probe(void);
428 extern void iostart(void);
429 extern void setwnd(WINDOW *);
430 extern void warble(void);
431 extern void boom(coord);
432 extern void tracktorpedo(coord, int, int, int, int);
433 extern void cgetline(char *, int);
434 extern void waitfor(void);
435 extern void setpassword(void);
436 extern void commandhook(char *, bool);
437 extern void makechart(void);
438 extern coord newkling(int);
440 extern void visual(void);
443 extern WINDOW *curwnd;
444 extern WINDOW *fullscreen_window;
445 extern WINDOW *srscan_window;
446 extern WINDOW *report_window;
447 extern WINDOW *lrscan_window;
448 extern WINDOW *message_window;
449 extern WINDOW *prompt_window;
451 extern void clreol(void);
452 extern void clrscr(void);
453 extern void textcolor(int);
454 extern void highvideo(void);
458 BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY,
459 DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE