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