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 int crystals; /* has crystals */
55 #define MINED -1 /* used to have crystals, but they were mined out */
56 enum {unknown, known, shuttle_down} known;
59 #define DESTROY(pl) memset(pl, '\0', sizeof(planet))
83 int snap, // snapshot taken
84 crew, // crew complement
85 #define FULLCREW 428 /* BSD Trek was 387, that's wrong */
86 remkl, // remaining klingons
87 remcom, // remaining commanders
88 nscrem, // remaining super commanders
89 rembase, // remaining bases
90 starkl, // destroyed stars
91 basekl, // destroyed bases
92 nromrem, // Romulans remaining
93 nplankl, // destroyed uninhabited planets
94 nworldkl; // destroyed inhabited planets
95 planet plnets[PLNETMAX]; // Planet information
96 double date, // stardate
97 remres, // remaining resources
98 remtime; // remaining time
99 coord baseq[BASEMAX+1]; // Base quadrant coordinates
100 coord kcmdr[QUADSIZE+1]; // Commander quadrant coordinates
101 coord kscmdr; // Supercommander quadrant coordinates
111 enum {secure, distressed, enslaved} status;
112 } galaxy[GALSIZE+1][GALSIZE+1]; // The Galaxy (subscript 0 not used)
117 } chart[GALSIZE+1][GALSIZE+1]; // the starchart (subscript 0 not used)
118 } snapshot; // Data that is snapshot
120 #define MAXKLGAME 127
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 SKILL_NOVICE 1
135 #define SKILL_EXPERT 4
136 #define SKILL_EMERITUS 5
139 #define OPTION_ALL 0xffffffff
140 #define OPTION_TTY 0x00000001 /* old interface */
141 #define OPTION_CURSES 0x00000002 /* new interface */
142 #define OPTION_IOMODES 0x00000003 /* cover both interfaces */
143 #define OPTION_PLANETS 0x00000004 /* planets and mining */
144 #define OPTION_THOLIAN 0x00000008 /* Tholians and their webs */
145 #define OPTION_THINGY 0x00000010 /* Space Thingy can shoot back */
146 #define OPTION_PROBE 0x00000020 /* deep-space probes */
147 #define OPTION_SHOWME 0x00000040 /* bracket Enterprise in chart */
148 #define OPTION_RAMMING 0x00000080 /* enemies may ram Enterprise */
149 #define OPTION_MVBADDY 0x00000100 /* more enemies can move */
150 #define OPTION_BLKHOLE 0x00000200 /* black hole may timewarp you */
151 #define OPTION_BASE 0x00000400 /* bases have good shields */
152 #define OPTION_WORLDS 0x00000800 /* logic for inhabited worlds */
153 #define OPTION_PLAIN 0x01000000 /* user chose plain game */
154 #define OPTION_ALMY 0x02000000 /* user chose Almy variant */
173 #define NDEVICES (16) // Number of devices
175 #define damaged(dev) (game.damage[dev] != 0.0)
179 /* Define future events */
180 #define FSPY 0 // Spy event happens always (no future[] entry)
181 // can cause SC to tractor beam Enterprise
182 #define FSNOVA 1 // Supernova
183 #define FTBEAM 2 // Commander tractor beams Enterprise
184 #define FSNAP 3 // Snapshot for time warp
185 #define FBATTAK 4 // Commander attacks base
186 #define FCDBAS 5 // Commander destroys base
187 #define FSCMOVE 6 // Supercommander moves (might attack base)
188 #define FSCDBAS 7 // Supercommander destroys base
189 #define FDSPROB 8 // Move deep space probe
190 #define FDISTR 9 // Emit distress call from an inhabited world
191 #define FENSLV 10 // Inhabited word is enslaved */
192 #define FREPRO 11 // Klingons build a ship in an enslaved system
201 * abstract out the event handling -- underlying data structures will change
202 * when we implement stateful events
204 extern event *unschedule(int);
205 extern int is_scheduled(int);
206 extern event *schedule(int, double);
207 extern void postpone(int, double);
208 extern double scheduled(int);
209 #define findevent(evtype) &game.future[evtype]
211 #define SSTMAGIC "SST2.0\n"
214 char magic[sizeof(SSTMAGIC)];
215 unsigned long options;
218 feature quad[QUADSIZE+1][QUADSIZE+1]; // contents of our quadrant
219 double kpower[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy energy levels
220 double kdist[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy distances
221 double kavgd[(QUADSIZE+1)*(QUADSIZE+1)]; // average distances
222 double damage[NDEVICES]; // damage encountered
223 event future[NEVENTS]; // future events
224 char passwd[10]; // Self Destruct password
225 coord ks[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy sector locations
226 coord quadrant, sector; // where we are
227 coord tholian; // coordinates of Tholian
228 coord base; // position of base in current quadrant
229 coord battle; // base coordinates being attacked
230 coord plnet; // location of planet in quadrant
231 coord probec; // current probe quadrant
232 bool gamewon, // Finished!
233 ididit, // action taken -- allows enemy to attack
234 alive, // we are alive (not killed)
235 justin, // just entered quadrant
236 shldup, // shields are up
237 comhere, // commander here
238 ishere, // super-commander in quadrant
239 ientesc, // attempted escape from supercommander
240 ithere, // Tholian is here
241 resting, // rest time
242 icraft, // Kirk in Galileo
243 alldone, // game is now finished
244 neutz, // Romulan Neutral Zone
245 isarmed, // probe is armed
246 inorbit, // orbiting a planet
248 icrystl, // dilithium crystals aboard
249 iseenit, // seen base attack report
250 thawed; // thawed game
257 } condition; // condition (red/yellow/green/docked)
258 int inkling, // initial number of klingons
259 inbase, // initial number of bases
260 incom, // initial number of commanders
261 inscom, // initial number of commanders
262 inrom, // initial number of commanders
263 instar, // initial stars
264 intorps, // initial/Max torpedoes
265 torps, // number of torpedoes
266 ship, // ship type -- 'E' is Enterprise
267 abandoned, // count of crew abandoned in space
268 length, // length of game
269 skill, // skill level
270 klhere, // klingons here
271 casual, // causalties
272 nhelp, // calls for help
273 nkinks, // count of energy-barrier crossings
274 shldchg, // shield is changing (affects efficiency)
275 landed, // party on planet (1), on ship (-1)
276 iplnet, // planet # in quadrant
277 inplan, // initial planets
278 nenhere, // number of enemies in quadrant
279 irhere, // Romulans in quadrant
280 iscraft, // =1 if craft on ship, -1 if removed from game
281 isatb, // =1 if super commander is attacking base
282 iscate, // super commander is here
283 iattak, // attack recursion elimination (was cracks[4])
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 int iscore, iskill; // Common PLAQ
316 extern double perdate;
317 extern double aaitem;
318 extern char citem[10];
321 extern FILE *logfp, *replayfp;
323 /* the Space Thingy's global state should *not* be saved! */
325 extern bool iqhere, iqengry;
328 FWON, FDEPLETE, FLIFESUP, FNRG, FBATTLE,
329 FNEG3, FNOVA, FSNOVAED, FABANDN, FDILITHIUM,
330 FMATERIALIZE, FPHASER, FLOST, FMINING, FDPLANET,
331 FPNOVA, FSSC, FSTRACTOR, FDRAY, FTRIBBLE,
335 enum loctype {neither, quadrant, sector};
344 /* Function prototypes */
351 void srscan(scantype);
369 void finish(FINTYPE);
370 void selfdestruct(void);
382 void prout(char *, ...);
383 void proutn(char *, ...);
387 void cramen(feature);
389 char *cramlc(enum loctype, coord w);
390 double expran(double);
392 coord randplace(int);
393 coord dropin(feature);
397 void ram(bool, feature, coord);
398 void crmena(bool, feature, enum loctype, coord w);
399 void deadkl(coord, feature, coord);
402 void torpedo(double, double, coord, double *, int, int);
404 void pause_game(bool);
406 void snova(bool, coord *);
408 void hittem(double *);
409 void prouts(char *, ...);
417 void usecrystals(void);
421 void attakreport(bool);
425 void setwnd(WINDOW *);
428 void tracktorpedo(coord, int, int, int, int);
429 void cgetline(char *, int);
431 void setpassword(void);
432 void commandhook(char *, bool);
433 void makechart(void);
434 void enqueue(char *);
435 char *systemname(int);
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