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 enum {mined=-1, present=0, absent=1} crystals; /* has crystals */
55 enum {unknown, known, shuttle_down} known;
58 #define DESTROY(pl) memset(pl, '\0', sizeof(planet))
82 bool snap; // snapshot taken
83 int crew, // crew complement
84 #define FULLCREW 428 /* BSD Trek was 387, that's wrong */
85 remkl, // remaining klingons
86 remcom, // remaining commanders
87 nscrem, // remaining super commanders
88 rembase, // remaining bases
89 starkl, // destroyed stars
90 basekl, // destroyed bases
91 nromrem, // Romulans remaining
92 nplankl, // destroyed uninhabited planets
93 nworldkl; // destroyed inhabited planets
94 planet plnets[PLNETMAX]; // Planet information
95 double date, // stardate
96 remres, // remaining resources
97 remtime; // remaining time
98 coord baseq[BASEMAX+1]; // Base quadrant coordinates
99 coord kcmdr[QUADSIZE+1]; // Commander quadrant coordinates
100 coord kscmdr; // Supercommander quadrant coordinates
110 enum {secure, distressed, enslaved} status;
111 } galaxy[GALSIZE+1][GALSIZE+1]; // The Galaxy (subscript 0 not used)
116 } chart[GALSIZE+1][GALSIZE+1]; // the starchart (subscript 0 not used)
117 } snapshot; // Data that is snapshot
119 #define MAXKLGAME 127
122 #define NKILLK (game.inkling - game.state.remkl)
123 #define NKILLC (game.incom - game.state.remcom)
124 #define NKILLSC (game.inscom - game.state.nscrem)
125 #define NKILLROM (game.inrom - game.state.nromrem)
126 #define KLINGREM (game.state.remkl + game.state.remcom + game.state.nscrem)
127 #define INKLINGTOT (game.inkling + game.incom + game.inscom)
128 #define KLINGKILLED (INKLINGTOT - KLINGREM)
131 #define OPTION_ALL 0xffffffff
132 #define OPTION_TTY 0x00000001 /* old interface */
133 #define OPTION_CURSES 0x00000002 /* new interface */
134 #define OPTION_IOMODES 0x00000003 /* cover both interfaces */
135 #define OPTION_PLANETS 0x00000004 /* planets and mining */
136 #define OPTION_THOLIAN 0x00000008 /* Tholians and their webs */
137 #define OPTION_THINGY 0x00000010 /* Space Thingy can shoot back */
138 #define OPTION_PROBE 0x00000020 /* deep-space probes */
139 #define OPTION_SHOWME 0x00000040 /* bracket Enterprise in chart */
140 #define OPTION_RAMMING 0x00000080 /* enemies may ram Enterprise */
141 #define OPTION_MVBADDY 0x00000100 /* more enemies can move */
142 #define OPTION_BLKHOLE 0x00000200 /* black hole may timewarp you */
143 #define OPTION_BASE 0x00000400 /* bases have good shields */
144 #define OPTION_WORLDS 0x00000800 /* logic for inhabited worlds */
145 #define OPTION_PLAIN 0x01000000 /* user chose plain game */
146 #define OPTION_ALMY 0x02000000 /* user chose Almy variant */
165 #define NDEVICES (16) // Number of devices
167 #define damaged(dev) (game.damage[dev] != 0.0)
171 /* Define future events */
172 #define FSPY 0 // Spy event happens always (no future[] entry)
173 // can cause SC to tractor beam Enterprise
174 #define FSNOVA 1 // Supernova
175 #define FTBEAM 2 // Commander tractor beams Enterprise
176 #define FSNAP 3 // Snapshot for time warp
177 #define FBATTAK 4 // Commander attacks base
178 #define FCDBAS 5 // Commander destroys base
179 #define FSCMOVE 6 // Supercommander moves (might attack base)
180 #define FSCDBAS 7 // Supercommander destroys base
181 #define FDSPROB 8 // Move deep space probe
182 #define FDISTR 9 // Emit distress call from an inhabited world
183 #define FENSLV 10 // Inhabited word is enslaved */
184 #define FREPRO 11 // Klingons build a ship in an enslaved system
193 * abstract out the event handling -- underlying data structures will change
194 * when we implement stateful events
196 extern event *unschedule(int);
197 extern int is_scheduled(int);
198 extern event *schedule(int, double);
199 extern void postpone(int, double);
200 extern double scheduled(int);
201 #define findevent(evtype) &game.future[evtype]
203 #define SSTMAGIC "SST2.0\n"
205 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
208 char magic[sizeof(SSTMAGIC)];
209 unsigned long options;
212 feature quad[QUADSIZE+1][QUADSIZE+1]; // contents of our quadrant
213 double kpower[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy energy levels
214 double kdist[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy distances
215 double kavgd[(QUADSIZE+1)*(QUADSIZE+1)]; // average distances
216 double damage[NDEVICES]; // damage encountered
217 event future[NEVENTS]; // future events
218 char passwd[10]; // Self Destruct password
219 coord ks[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy sector locations
220 coord quadrant, sector; // where we are
221 coord tholian; // coordinates of Tholian
222 coord base; // position of base in current quadrant
223 coord battle; // base coordinates being attacked
224 coord plnet; // location of planet in quadrant
225 coord probec; // current probe quadrant
226 bool gamewon, // Finished!
227 ididit, // action taken -- allows enemy to attack
228 alive, // we are alive (not killed)
229 justin, // just entered quadrant
230 shldup, // shields are up
231 shldchg, // shield is changing (affects efficiency)
232 comhere, // commander here
233 ishere, // super-commander in quadrant
234 iscate, // super commander is here
235 ientesc, // attempted escape from supercommander
236 ithere, // Tholian is here
237 resting, // rest time
238 icraft, // Kirk in Galileo
239 landed, // party on planet (true), on ship (false)
240 alldone, // game is now finished
241 neutz, // Romulan Neutral Zone
242 isarmed, // probe is armed
243 inorbit, // orbiting a planet
245 icrystl, // dilithium crystals aboard
246 iseenit, // seen base attack report
247 thawed; // thawed game
254 } condition; // condition (red/yellow/green/docked)
259 } iscraft; // 'onship' if craft on ship, 'removed' if out of game
267 } skill; // skill level
268 int inkling, // initial number of klingons
269 inbase, // initial number of bases
270 incom, // initial number of commanders
271 inscom, // initial number of commanders
272 inrom, // initial number of commanders
273 instar, // initial stars
274 intorps, // initial/max torpedoes
275 torps, // number of torpedoes
276 ship, // ship type -- 'E' is Enterprise
277 abandoned, // count of crew abandoned in space
278 length, // length of game
279 klhere, // klingons here
280 casual, // causalties
281 nhelp, // calls for help
282 nkinks, // count of energy-barrier crossings
283 iplnet, // planet # in quadrant
284 inplan, // initial planets
285 nenhere, // number of enemies in quadrant
286 irhere, // Romulans in quadrant
287 isatb, // =1 if super commander is attacking base
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