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)
40 typedef struct {int x; int y;} coord;
42 #define square(i) ((i)*(i))
43 #define same(c1, c2) ((c1.x == c2.x) && (c1.y == c2.y))
44 #define distance(c1, c2) sqrt(square(c1.x - c2.x) + square(c1.y - c2.y))
45 #define invalidate(w) w.x = w.y = 0
46 #define is_valid(w) (w.x != 0 && w.y != 0)
50 enum {M=0, N=1, O=2} pclass;
51 int inhabited; /* if NZ, an index into a name array */
52 #define UNINHABITED -1
53 enum {mined=-1, present=0, absent=1} crystals; /* has crystals */
54 enum {unknown, known, shuttle_down} known;
57 #define DESTROY(pl) memset(pl, '\0', sizeof(planet))
81 bool snap; // snapshot taken
82 int crew, // crew complement
83 #define FULLCREW 428 /* BSD Trek was 387, that's wrong */
84 remkl, // remaining klingons
85 remcom, // remaining commanders
86 nscrem, // remaining super commanders
87 rembase, // remaining bases
88 starkl, // destroyed stars
89 basekl, // destroyed bases
90 nromrem, // Romulans remaining
91 nplankl, // destroyed uninhabited planets
92 nworldkl; // destroyed inhabited planets
93 planet planets[PLNETMAX]; // Planet information
94 double date, // stardate
95 remres, // remaining resources
96 remtime; // remaining time
97 coord baseq[BASEMAX+1]; // Base quadrant coordinates
98 coord kcmdr[QUADSIZE+1]; // Commander quadrant coordinates
99 coord kscmdr; // Supercommander quadrant coordinates
109 enum {secure, distressed, enslaved} status;
110 } galaxy[GALSIZE+1][GALSIZE+1]; // The Galaxy (subscript 0 not used)
115 } chart[GALSIZE+1][GALSIZE+1]; // the starchart (subscript 0 not used)
116 } snapshot; // Data that is snapshot
118 #define NKILLK (game.inkling - game.state.remkl)
119 #define NKILLC (game.incom - game.state.remcom)
120 #define NKILLSC (game.inscom - game.state.nscrem)
121 #define NKILLROM (game.inrom - game.state.nromrem)
122 #define KLINGREM (game.state.remkl + game.state.remcom + game.state.nscrem)
123 #define INKLINGTOT (game.inkling + game.incom + game.inscom)
124 #define KLINGKILLED (INKLINGTOT - KLINGREM)
127 #define OPTION_ALL 0xffffffff
128 #define OPTION_TTY 0x00000001 /* old interface */
129 #define OPTION_CURSES 0x00000002 /* new interface */
130 #define OPTION_IOMODES 0x00000003 /* cover both interfaces */
131 #define OPTION_PLANETS 0x00000004 /* planets and mining */
132 #define OPTION_THOLIAN 0x00000008 /* Tholians and their webs */
133 #define OPTION_THINGY 0x00000010 /* Space Thingy can shoot back */
134 #define OPTION_PROBE 0x00000020 /* deep-space probes */
135 #define OPTION_SHOWME 0x00000040 /* bracket Enterprise in chart */
136 #define OPTION_RAMMING 0x00000080 /* enemies may ram Enterprise */
137 #define OPTION_MVBADDY 0x00000100 /* more enemies can move */
138 #define OPTION_BLKHOLE 0x00000200 /* black hole may timewarp you */
139 #define OPTION_BASE 0x00000400 /* bases have good shields */
140 #define OPTION_WORLDS 0x00000800 /* logic for inhabited worlds */
141 #define OPTION_PLAIN 0x01000000 /* user chose plain game */
142 #define OPTION_ALMY 0x02000000 /* user chose Almy variant */
161 #define NDEVICES (16) // Number of devices
163 #define damaged(dev) (game.damage[dev] != 0.0)
167 /* Define future events */
168 #define FSPY 0 // Spy event happens always (no future[] entry)
169 // can cause SC to tractor beam Enterprise
170 #define FSNOVA 1 // Supernova
171 #define FTBEAM 2 // Commander tractor beams Enterprise
172 #define FSNAP 3 // Snapshot for time warp
173 #define FBATTAK 4 // Commander attacks base
174 #define FCDBAS 5 // Commander destroys base
175 #define FSCMOVE 6 // Supercommander moves (might attack base)
176 #define FSCDBAS 7 // Supercommander destroys base
177 #define FDSPROB 8 // Move deep space probe
178 #define FDISTR 9 // Emit distress call from an inhabited world
179 #define FENSLV 10 // Inhabited word is enslaved */
180 #define FREPRO 11 // Klingons build a ship in an enslaved system
189 * abstract out the event handling -- underlying data structures will change
190 * when we implement stateful events
192 extern event *unschedule(int);
193 extern int is_scheduled(int);
194 extern event *schedule(int, double);
195 extern void postpone(int, double);
196 extern double scheduled(int);
197 #define findevent(evtype) &game.future[evtype]
199 #define SSTMAGIC "SST2.0\n"
201 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
204 char magic[sizeof(SSTMAGIC)];
205 unsigned long options;
208 feature quad[QUADSIZE+1][QUADSIZE+1]; // contents of our quadrant
209 double kpower[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy energy levels
210 double kdist[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy distances
211 double kavgd[(QUADSIZE+1)*(QUADSIZE+1)]; // average distances
212 double damage[NDEVICES]; // damage encountered
213 event future[NEVENTS]; // future events
214 char passwd[10]; // Self Destruct password
215 coord ks[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy sector locations
216 coord quadrant, sector; // where we are
217 coord tholian; // coordinates of Tholian
218 coord base; // position of base in current quadrant
219 coord battle; // base coordinates being attacked
220 coord plnet; // location of planet in quadrant
221 coord probec; // current probe quadrant
222 bool gamewon, // Finished!
223 ididit, // action taken -- allows enemy to attack
224 alive, // we are alive (not killed)
225 justin, // just entered quadrant
226 shldup, // shields are up
227 shldchg, // shield is changing (affects efficiency)
228 comhere, // commander here
229 ishere, // super-commander in quadrant
230 iscate, // super commander is here
231 ientesc, // attempted escape from supercommander
232 ithere, // Tholian is here
233 resting, // rest time
234 icraft, // Kirk in Galileo
235 landed, // party on planet (true), on ship (false)
236 alldone, // game is now finished
237 neutz, // Romulan Neutral Zone
238 isarmed, // probe is armed
239 inorbit, // orbiting a planet
241 icrystl, // dilithium crystals aboard
242 iseenit, // seen base attack report
243 thawed; // thawed game
250 } condition; // condition (red/yellow/green/docked)
255 } iscraft; // 'onship' if craft on ship, 'removed' if out of game
263 } skill; // skill level
264 int inkling, // initial number of klingons
265 inbase, // initial number of bases
266 incom, // initial number of commanders
267 inscom, // initial number of commanders
268 inrom, // initial number of commanders
269 instar, // initial stars
270 intorps, // initial/max torpedoes
271 torps, // number of torpedoes
272 ship, // ship type -- 'E' is Enterprise
273 abandoned, // count of crew abandoned in space
274 length, // length of game
275 klhere, // klingons here
276 casual, // causalties
277 nhelp, // calls for help
278 nkinks, // count of energy-barrier crossings
279 iplnet, // planet # in quadrant
280 inplan, // initial planets
281 nenhere, // number of enemies in quadrant
282 irhere, // Romulans in quadrant
283 isatb, // =1 if super commander is attacking base
284 tourn, // tournament number
285 proben, // number of moves for probe
286 nprobes; // number of probes available
287 double inresor, // initial resources
288 intime, // initial time
289 inenrg, // initial/max energy
290 inshld, // initial/max shield
291 inlsr, // initial life support resources
292 indate, // initial date
293 energy, // energy level
294 shield, // shield level
295 warpfac, // warp speed
296 wfacsq, // squared warp factor
297 lsupres, // life support reserves
298 dist, // movement distance
299 direc, // movement direction
300 optime, // time taken by current operation
301 docfac, // repair factor when docking (constant?)
302 damfac, // damage factor
303 lastchart, // time star chart was last updated
304 cryprob, // probability that crystal will work
305 probex, // location of probe
307 probeinx, // probe x,y increment
309 height; // height of orbit around planet
311 extern struct game game;
313 /* the following global state doesn't need to be saved */
314 extern char *device[NDEVICES];
315 extern char *systnames[NINHAB + 1];
316 extern int iscore, iskill; // Common PLAQ
317 extern double perdate;
318 extern double aaitem;
319 extern char citem[10];
322 extern FILE *logfp, *replayfp;
324 /* the Space Thingy's global state should *not* be saved! */
326 extern bool iqhere, iqengry;
329 FWON, FDEPLETE, FLIFESUP, FNRG, FBATTLE,
330 FNEG3, FNOVA, FSNOVAED, FABANDN, FDILITHIUM,
331 FMATERIALIZE, FPHASER, FLOST, FMINING, FDPLANET,
332 FPNOVA, FSSC, FSTRACTOR, FDRAY, FTRIBBLE,
336 enum loctype {neither, quadrant, sector};
338 /* Function prototypes */
339 extern void prelim(void);
340 extern void attack(bool);
341 extern bool choose(bool);
342 extern void setup(bool);
343 extern void score(void);
344 extern void atover(bool);
345 extern void srscan(void);
346 extern void lrscan(void);
347 extern void phasers(void);
348 extern void photon(void);
349 extern void warp(bool);
350 extern void doshield(bool);
351 extern void dock(bool);
352 extern void damagereport(void);
353 extern void chart(void);
354 extern void rechart(void);
355 extern void impulse(void);
356 extern void wait(void);
357 extern void setwarp(void);
358 extern void events(void);
359 extern void report(void);
360 extern void eta(void);
361 extern void mayday(void);
362 extern void abandon(void);
363 extern void finish(FINTYPE);
364 extern void selfdestruct(void);
365 extern void kaboom(void);
366 extern void freeze(bool);
367 extern bool thaw(void);
368 extern void plaque(void);
369 extern int scan(void);
370 extern void status(int req);
371 extern void request(void);
375 extern void chew(void);
376 extern void chew2(void);
377 extern void skip(int);
378 extern void prout(const char *, ...) __attribute__((format(printf, 1, 2)));
379 extern void proutn(const char *, ...) __attribute__((format(printf, 1, 2)));
380 extern void prouts(const char *, ...) __attribute__((format(printf, 1, 2)));
381 extern void prstat(const char *txt, const char *fmt, ...)
382 __attribute__((format(printf, 2, 3)));
383 extern void stars(void);
384 extern void newqad(bool);
385 extern bool ja(void);
386 extern void cramen(feature);
387 extern void crmshp(void);
388 extern char *cramlc(enum loctype, coord w);
389 extern double expran(double);
390 extern double Rand(void);
391 extern coord randplace(int);
392 extern coord dropin(feature);
393 extern void newcnd(void);
394 extern void sortklings(void);
395 extern void imove(bool);
396 extern void ram(bool, feature, coord);
397 extern void crmena(bool, feature, enum loctype, coord w);
398 extern void deadkl(coord, feature, coord);
399 extern void timwrp(void);
400 extern void moveklings(void);
401 extern void torpedo(double, double, coord, double *, int, int);
402 extern void huh(void);
403 extern void pause_reset(void);
404 extern void pause_game(bool);
405 extern void nova(coord);
406 extern void supernova(bool, coord *);
407 extern void supercommander(void);
408 extern void hittem(double *);
409 extern bool isit(char *);
410 extern void survey(void);
411 extern void orbit(void);
412 extern void sensor(void);
413 extern void drawmaps(int);
414 extern void beam(void);
415 extern void mine(void);
416 extern void usecrystals(void);
417 extern void shuttle(void);
418 extern void deathray(void);
419 extern void debugme(void);
420 extern void attackreport(bool);
421 extern void movetholian(void);
422 extern void probe(void);
423 extern void iostart(void);
424 extern void setwnd(WINDOW *);
425 extern void warble(void);
426 extern void boom(coord);
427 extern void tracktorpedo(coord, int, int, int, int);
428 extern void cgetline(char *, int);
429 extern void waitfor(void);
430 extern void setpassword(void);
431 extern void commandhook(char *, bool);
432 extern void makechart(void);
433 extern coord newkling(int);
435 extern void visual(void);
438 extern WINDOW *curwnd;
439 extern WINDOW *fullscreen_window;
440 extern WINDOW *srscan_window;
441 extern WINDOW *report_window;
442 extern WINDOW *lrscan_window;
443 extern WINDOW *message_window;
444 extern WINDOW *prompt_window;
446 extern void clreol(void);
447 extern void clrscr(void);
448 extern void textcolor(int);
449 extern void highvideo(void);
453 BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY,
454 DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE