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))
48 #define invalidate(w) w.x = w.y = 0
49 #define is_valid(w) (w.x != 0 && w.y != 0)
53 enum {M=0, N=1, O=2} pclass;
54 int inhabited; /* if NZ, an index into a name array */
55 #define UNINHABITED -1
56 enum {mined=-1, present=0, absent=1} crystals; /* has crystals */
57 enum {unknown, known, shuttle_down} known;
60 #define DESTROY(pl) memset(pl, '\0', sizeof(planet))
84 bool snap; // snapshot taken
85 int crew, // crew complement
86 #define FULLCREW 428 /* BSD Trek was 387, that's wrong */
87 remkl, // remaining klingons
88 remcom, // remaining commanders
89 nscrem, // remaining super commanders
90 rembase, // remaining bases
91 starkl, // destroyed stars
92 basekl, // destroyed bases
93 nromrem, // Romulans remaining
94 nplankl, // destroyed uninhabited planets
95 nworldkl; // destroyed inhabited planets
96 planet plnets[PLNETMAX]; // Planet information
97 double date, // stardate
98 remres, // remaining resources
99 remtime; // remaining time
100 coord baseq[BASEMAX+1]; // Base quadrant coordinates
101 coord kcmdr[QUADSIZE+1]; // Commander quadrant coordinates
102 coord kscmdr; // Supercommander quadrant coordinates
112 enum {secure, distressed, enslaved} status;
113 } galaxy[GALSIZE+1][GALSIZE+1]; // The Galaxy (subscript 0 not used)
118 } chart[GALSIZE+1][GALSIZE+1]; // the starchart (subscript 0 not used)
119 } snapshot; // Data that is snapshot
121 #define MAXKLGAME 127
124 #define NKILLK (game.inkling - game.state.remkl)
125 #define NKILLC (game.incom - game.state.remcom)
126 #define NKILLSC (game.inscom - game.state.nscrem)
127 #define NKILLROM (game.inrom - game.state.nromrem)
128 #define KLINGREM (game.state.remkl + game.state.remcom + game.state.nscrem)
129 #define INKLINGTOT (game.inkling + game.incom + game.inscom)
130 #define KLINGKILLED (INKLINGTOT - KLINGREM)
133 #define OPTION_ALL 0xffffffff
134 #define OPTION_TTY 0x00000001 /* old interface */
135 #define OPTION_CURSES 0x00000002 /* new interface */
136 #define OPTION_IOMODES 0x00000003 /* cover both interfaces */
137 #define OPTION_PLANETS 0x00000004 /* planets and mining */
138 #define OPTION_THOLIAN 0x00000008 /* Tholians and their webs */
139 #define OPTION_THINGY 0x00000010 /* Space Thingy can shoot back */
140 #define OPTION_PROBE 0x00000020 /* deep-space probes */
141 #define OPTION_SHOWME 0x00000040 /* bracket Enterprise in chart */
142 #define OPTION_RAMMING 0x00000080 /* enemies may ram Enterprise */
143 #define OPTION_MVBADDY 0x00000100 /* more enemies can move */
144 #define OPTION_BLKHOLE 0x00000200 /* black hole may timewarp you */
145 #define OPTION_BASE 0x00000400 /* bases have good shields */
146 #define OPTION_WORLDS 0x00000800 /* logic for inhabited worlds */
147 #define OPTION_PLAIN 0x01000000 /* user chose plain game */
148 #define OPTION_ALMY 0x02000000 /* user chose Almy variant */
167 #define NDEVICES (16) // Number of devices
169 #define damaged(dev) (game.damage[dev] != 0.0)
173 /* Define future events */
174 #define FSPY 0 // Spy event happens always (no future[] entry)
175 // can cause SC to tractor beam Enterprise
176 #define FSNOVA 1 // Supernova
177 #define FTBEAM 2 // Commander tractor beams Enterprise
178 #define FSNAP 3 // Snapshot for time warp
179 #define FBATTAK 4 // Commander attacks base
180 #define FCDBAS 5 // Commander destroys base
181 #define FSCMOVE 6 // Supercommander moves (might attack base)
182 #define FSCDBAS 7 // Supercommander destroys base
183 #define FDSPROB 8 // Move deep space probe
184 #define FDISTR 9 // Emit distress call from an inhabited world
185 #define FENSLV 10 // Inhabited word is enslaved */
186 #define FREPRO 11 // Klingons build a ship in an enslaved system
195 * abstract out the event handling -- underlying data structures will change
196 * when we implement stateful events
198 extern event *unschedule(int);
199 extern int is_scheduled(int);
200 extern event *schedule(int, double);
201 extern void postpone(int, double);
202 extern double scheduled(int);
203 #define findevent(evtype) &game.future[evtype]
205 #define SSTMAGIC "SST2.0\n"
207 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
210 char magic[sizeof(SSTMAGIC)];
211 unsigned long options;
214 feature quad[QUADSIZE+1][QUADSIZE+1]; // contents of our quadrant
215 double kpower[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy energy levels
216 double kdist[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy distances
217 double kavgd[(QUADSIZE+1)*(QUADSIZE+1)]; // average distances
218 double damage[NDEVICES]; // damage encountered
219 event future[NEVENTS]; // future events
220 char passwd[10]; // Self Destruct password
221 coord ks[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy sector locations
222 coord quadrant, sector; // where we are
223 coord tholian; // coordinates of Tholian
224 coord base; // position of base in current quadrant
225 coord battle; // base coordinates being attacked
226 coord plnet; // location of planet in quadrant
227 coord probec; // current probe quadrant
228 bool gamewon, // Finished!
229 ididit, // action taken -- allows enemy to attack
230 alive, // we are alive (not killed)
231 justin, // just entered quadrant
232 shldup, // shields are up
233 shldchg, // shield is changing (affects efficiency)
234 comhere, // commander here
235 ishere, // super-commander in quadrant
236 iscate, // super commander is here
237 ientesc, // attempted escape from supercommander
238 ithere, // Tholian is here
239 resting, // rest time
240 icraft, // Kirk in Galileo
241 landed, // party on planet (true), on ship (false)
242 alldone, // game is now finished
243 neutz, // Romulan Neutral Zone
244 isarmed, // probe is armed
245 inorbit, // orbiting a planet
247 icrystl, // dilithium crystals aboard
248 iseenit, // seen base attack report
249 thawed; // thawed game
256 } condition; // condition (red/yellow/green/docked)
261 } iscraft; // 'onship' if craft on ship, 'removed' if out of game
269 } skill; // skill level
270 int inkling, // initial number of klingons
271 inbase, // initial number of bases
272 incom, // initial number of commanders
273 inscom, // initial number of commanders
274 inrom, // initial number of commanders
275 instar, // initial stars
276 intorps, // initial/max torpedoes
277 torps, // number of torpedoes
278 ship, // ship type -- 'E' is Enterprise
279 abandoned, // count of crew abandoned in space
280 length, // length of game
281 klhere, // klingons here
282 casual, // causalties
283 nhelp, // calls for help
284 nkinks, // count of energy-barrier crossings
285 iplnet, // planet # in quadrant
286 inplan, // initial planets
287 nenhere, // number of enemies in quadrant
288 irhere, // Romulans in quadrant
289 isatb, // =1 if super commander is attacking base
290 tourn, // tournament number
291 proben, // number of moves for probe
292 nprobes; // number of probes available
293 double inresor, // initial resources
294 intime, // initial time
295 inenrg, // initial/max energy
296 inshld, // initial/max shield
297 inlsr, // initial life support resources
298 indate, // initial date
299 energy, // energy level
300 shield, // shield level
301 warpfac, // warp speed
302 wfacsq, // squared warp factor
303 lsupres, // life support reserves
304 dist, // movement distance
305 direc, // movement direction
306 optime, // time taken by current operation
307 docfac, // repair factor when docking (constant?)
308 damfac, // damage factor
309 lastchart, // time star chart was last updated
310 cryprob, // probability that crystal will work
311 probex, // location of probe
313 probeinx, // probe x,y increment
315 height; // height of orbit around planet
317 extern struct game game;
319 /* the following global state doesn't need to be saved */
320 extern char *device[NDEVICES];
321 extern char *systnames[NINHAB + 1];
322 extern int iscore, iskill; // Common PLAQ
323 extern double perdate;
324 extern double aaitem;
325 extern char citem[10];
328 extern FILE *logfp, *replayfp;
330 /* the Space Thingy's global state should *not* be saved! */
332 extern bool iqhere, iqengry;
335 FWON, FDEPLETE, FLIFESUP, FNRG, FBATTLE,
336 FNEG3, FNOVA, FSNOVAED, FABANDN, FDILITHIUM,
337 FMATERIALIZE, FPHASER, FLOST, FMINING, FDPLANET,
338 FPNOVA, FSSC, FSTRACTOR, FDRAY, FTRIBBLE,
342 enum loctype {neither, quadrant, sector};
344 /* Function prototypes */
369 void finish(FINTYPE);
370 void selfdestruct(void);
376 void status(int req);
384 void prout(const char *, ...) __attribute__((format(printf, 1, 2)));
385 void proutn(const char *, ...) __attribute__((format(printf, 1, 2)));
386 void prouts(const char *, ...) __attribute__((format(printf, 1, 2)));
387 void prstat(const char *txt, const char *fmt, ...)
388 __attribute__((format(printf, 2, 3)));
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 *);
421 void usecrystals(void);
425 void attakreport(bool);
429 void setwnd(WINDOW *);
432 void tracktorpedo(coord, int, int, int, int);
433 void cgetline(char *, int);
435 void setpassword(void);
436 void commandhook(char *, bool);
437 void makechart(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