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 */
170 #define DDRAY 13 // Added deathray
171 #define DDSP 14 // Added deep space probe
172 #define NDEVICES (15) // Number of devices
174 #define damaged(dev) game.damage[dev] != 0.0
178 /* Define future events */
179 #define FSPY 0 // Spy event happens always (no future[] entry)
180 // can cause SC to tractor beam Enterprise
181 #define FSNOVA 1 // Supernova
182 #define FTBEAM 2 // Commander tractor beams Enterprise
183 #define FSNAP 3 // Snapshot for time warp
184 #define FBATTAK 4 // Commander attacks base
185 #define FCDBAS 5 // Commander destroys base
186 #define FSCMOVE 6 // Supercommander moves (might attack base)
187 #define FSCDBAS 7 // Supercommander destroys base
188 #define FDSPROB 8 // Move deep space probe
189 #define FDISTR 9 // Emit distress call from an inhabited world
190 #define FENSLV 10 // Inhabited word is enslaved */
191 #define FREPRO 11 // Klingons build a ship in an enslaved system
200 * abstract out the event handling -- underlying data structures will change
201 * when we implement stateful events
203 extern event *unschedule(int);
204 extern int is_scheduled(int);
205 extern event *schedule(int, double);
206 extern void postpone(int, double);
207 extern double scheduled(int);
208 #define findevent(evtype) &game.future[evtype]
210 #define SSTMAGIC "SST2.0\n"
213 char magic[sizeof(SSTMAGIC)];
214 unsigned long options;
217 feature quad[QUADSIZE+1][QUADSIZE+1]; // contents of our quadrant
218 double kpower[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy energy levels
219 double kdist[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy distances
220 double kavgd[(QUADSIZE+1)*(QUADSIZE+1)]; // average distances
221 double damage[NDEVICES]; // damage encountered
222 event future[NEVENTS]; // future events
223 char passwd[10]; // Self Destruct password
224 coord ks[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy sector locations
225 coord quadrant, sector; // where we are
226 coord tholian; // coordinates of Tholian
227 coord base; // position of base in current quadrant
228 coord battle; // base coordinates being attacked
229 coord plnet; // location of planet in quadrant
230 coord probec; // current probe quadrant
231 bool gamewon, // Finished!
232 ididit, // action taken -- allows enemy to attack
233 alive, // we are alive (not killed)
234 justin, // just entered quadrant
235 shldup, // shields are up
236 comhere, // commander here
237 ishere, // super-commander in quadrant
238 ientesc, // attempted escape from supercommander
239 ithere, // Tholian is here
240 resting, // rest time
241 icraft, // Kirk in Galileo
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)
257 int inkling, // initial number of klingons
258 inbase, // initial number of bases
259 incom, // initial number of commanders
260 inscom, // initial number of commanders
261 inrom, // initial number of commanders
262 instar, // initial stars
263 intorps, // initial/Max torpedoes
264 torps, // number of torpedoes
265 ship, // ship type -- 'E' is Enterprise
266 abandoned, // count of crew abandoned in space
267 length, // length of game
268 skill, // skill level
269 klhere, // klingons here
270 casual, // causalties
271 nhelp, // calls for help
272 nkinks, // count of energy-barrier crossings
273 shldchg, // shield is changing (affects efficiency)
274 landed, // party on planet (1), on ship (-1)
275 iplnet, // planet # in quadrant
276 inplan, // initial planets
277 nenhere, // number of enemies in quadrant
278 irhere, // Romulans in quadrant
279 iscraft, // =1 if craft on ship, -1 if removed from game
280 isatb, // =1 if super commander is attacking base
281 iscate, // super commander is here
282 iattak, // attack recursion elimination (was cracks[4])
283 tourn, // tournament number
284 proben, // number of moves for probe
285 nprobes; // number of probes available
286 double inresor, // initial resources
287 intime, // initial time
288 inenrg, // initial/max energy
289 inshld, // initial/max shield
290 inlsr, // initial life support resources
291 indate, // initial date
292 energy, // energy level
293 shield, // shield level
294 warpfac, // warp speed
295 wfacsq, // squared warp factor
296 lsupres, // life support reserves
297 dist, // movement distance
298 direc, // movement direction
299 optime, // time taken by current operation
300 docfac, // repair factor when docking (constant?)
301 damfac, // damage factor
302 lastchart, // time star chart was last updated
303 cryprob, // probability that crystal will work
304 probex, // location of probe
306 probeinx, // probe x,y increment
308 height; // height of orbit around planet
310 extern struct game game;
312 /* the following global state doesn't need to be saved */
313 extern char *device[NDEVICES];
314 extern int iscore, iskill; // Common PLAQ
315 extern double perdate;
316 extern double aaitem;
317 extern char citem[10];
320 extern FILE *logfp, *replayfp;
322 /* the Space Thingy's global state should *not* be saved! */
324 extern bool iqhere, iqengry;
327 FWON, FDEPLETE, FLIFESUP, FNRG, FBATTLE,
328 FNEG3, FNOVA, FSNOVAED, FABANDN, FDILITHIUM,
329 FMATERIALIZE, FPHASER, FLOST, FMINING, FDPLANET,
330 FPNOVA, FSSC, FSTRACTOR, FDRAY, FTRIBBLE,
334 enum loctype {neither, quadrant, sector};
343 /* Function prototypes */
350 void srscan(scantype);
368 void finish(FINTYPE);
369 void selfdestruct(void);
381 void prout(char *, ...);
382 void proutn(char *, ...);
386 void cramen(feature);
388 char *cramlc(enum loctype, coord w);
389 double expran(double);
391 coord randplace(int);
392 coord dropin(feature);
396 void ram(bool, feature, coord);
397 void crmena(bool, feature, enum loctype, coord w);
398 void deadkl(coord, feature, coord);
401 void torpedo(double, double, coord, double *, int, int);
403 void pause_game(bool);
405 void snova(bool, coord *);
407 void hittem(double *);
408 void prouts(char *, ...);
416 void usecrystals(void);
420 void attakreport(bool);
424 void setwnd(WINDOW *);
427 void tracktorpedo(coord, int, int, int, int);
428 void cgetline(char *, int);
430 void setpassword(void);
431 void commandhook(char *, bool);
432 void makechart(void);
433 void enqueue(char *);
434 char *systemname(int);
437 extern WINDOW *curwnd;
438 extern WINDOW *fullscreen_window;
439 extern WINDOW *srscan_window;
440 extern WINDOW *report_window;
441 extern WINDOW *lrscan_window;
442 extern WINDOW *message_window;
443 extern WINDOW *prompt_window;
445 extern void clreol(void);
446 extern void clrscr(void);
447 extern void textcolor(int);
448 extern void highvideo(void);
452 BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY,
453 DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE