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))
62 int snap, // snapshot taken
63 crew, // crew complement
64 #define FULLCREW 428 /* BSD Trek was 387, that's wrong */
65 remkl, // remaining klingons
66 remcom, // remaining commanders
67 nscrem, // remaining super commanders
68 rembase, // remaining bases
69 starkl, // destroyed stars
70 basekl, // destroyed bases
71 nromrem, // Romulans remaining
72 nplankl, // destroyed uninhabited planets
73 nworldkl; // destroyed inhabited planets
74 planet plnets[PLNETMAX]; // Planet information
75 double date, // stardate
76 remres, // remaining resources
77 remtime; // remaining time
78 coord baseq[BASEMAX+1]; // Base quadrant coordinates
79 coord kcmdr[QUADSIZE+1]; // Commander quadrant coordinates
80 coord kscmdr; // Supercommander quadrant coordinates
90 enum {secure, distressed, enslaved} status;
91 } galaxy[GALSIZE+1][GALSIZE+1]; // The Galaxy (subscript 0 not used)
96 } chart[GALSIZE+1][GALSIZE+1]; // the starchart (subscript 0 not used)
97 } snapshot; // Data that is snapshot
102 #define NKILLK (game.inkling - game.state.remkl)
103 #define NKILLC (game.incom - game.state.remcom)
104 #define NKILLSC (game.inscom - game.state.nscrem)
105 #define NKILLROM (game.inrom - game.state.nromrem)
106 #define KLINGREM (game.state.remkl + game.state.remcom + game.state.nscrem)
107 #define INKLINGTOT (game.inkling + game.incom + game.inscom)
108 #define KLINGKILLED (INKLINGTOT - KLINGREM)
111 #define SKILL_NOVICE 1
114 #define SKILL_EXPERT 4
115 #define SKILL_EMERITUS 5
118 #define OPTION_ALL 0xffffffff
119 #define OPTION_TTY 0x00000001 /* old interface */
120 #define OPTION_CURSES 0x00000002 /* new interface */
121 #define OPTION_IOMODES 0x00000003 /* cover both interfaces */
122 #define OPTION_PLANETS 0x00000004 /* planets and mining */
123 #define OPTION_THOLIAN 0x00000008 /* Tholians and their webs */
124 #define OPTION_THINGY 0x00000010 /* Space Thingy can shoot back */
125 #define OPTION_PROBE 0x00000020 /* deep-space probes */
126 #define OPTION_SHOWME 0x00000040 /* bracket Enterprise in chart */
127 #define OPTION_RAMMING 0x00000080 /* enemies may ram Enterprise */
128 #define OPTION_MVBADDY 0x00000100 /* more enemies can move */
129 #define OPTION_BLKHOLE 0x00000200 /* black hole may timewarp you */
130 #define OPTION_BASE 0x00000400 /* bases have good shields */
131 #define OPTION_WORLDS 0x00000800 /* logic for inhabited worlds */
132 #define OPTION_PLAIN 0x01000000 /* user chose plain game */
133 #define OPTION_ALMY 0x02000000 /* user chose Almy variant */
149 #define DDRAY 13 // Added deathray
150 #define DDSP 14 // Added deep space probe
151 #define NDEVICES (15) // 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"
192 char magic[sizeof(SSTMAGIC)];
193 unsigned long options;
196 char quad[QUADSIZE+1][QUADSIZE+1]; // contents of our quadrant
197 double kpower[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy energy levels
198 double kdist[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy distances
199 double kavgd[(QUADSIZE+1)*(QUADSIZE+1)]; // average distances
200 double damage[NDEVICES]; // damage encountered
201 event future[NEVENTS]; // future events
202 char passwd[10]; // Self Destruct password
203 coord ks[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy sector locations
204 coord quadrant, sector; // where we are
205 coord tholian; // coordinates of Tholian
206 coord base; // position of base in current quadrant
207 coord battle; // base coordinates being attacked
208 coord plnet; // location of planet in quadrant
209 coord probec; // current probe quadrant
210 bool gamewon, // Finished!
211 ididit, // action taken -- allows enemy to attack
212 alive, // we are alive (not killed)
213 justin, // just entered quadrant
214 shldup, // shields are up
215 comhere, // commander here
216 ishere, // super-commander in quadrant
217 ientesc, // attempted escape from supercommander
218 ithere, // Tholian is here
219 resting, // rest time
220 icraft, // Kirk in Galileo
221 alldone, // game is now finished
222 neutz, // Romulan Neutral Zone
223 isarmed, // probe is armed
224 inorbit, // orbiting a planet
226 icrystl, // dilithium crystals aboard
227 iseenit, // seen base attack report
228 thawed; // thawed game
229 int inkling, // initial number of klingons
230 inbase, // initial number of bases
231 incom, // initial number of commanders
232 inscom, // initial number of commanders
233 inrom, // initial number of commanders
234 instar, // initial stars
235 intorps, // initial/Max torpedoes
236 condit, // condition (red/yellow/green/docked)
237 torps, // number of torpedoes
238 ship, // ship type -- 'E' is Enterprise
239 abandoned, // count of crew abandoned in space
240 length, // length of game
241 skill, // skill level
242 klhere, // klingons here
243 casual, // causalties
244 nhelp, // calls for help
245 nkinks, // count of energy-barrier crossings
246 shldchg, // shield is changing (affects efficiency)
247 landed, // party on planet (1), on ship (-1)
248 iplnet, // planet # in quadrant
249 inplan, // initial planets
250 nenhere, // number of enemies in quadrant
251 irhere, // Romulans in quadrant
252 iscraft, // =1 if craft on ship, -1 if removed from game
253 isatb, // =1 if super commander is attacking base
254 iscate, // super commander is here
255 iattak, // attack recursion elimination (was cracks[4])
256 tourn, // tournament number
257 proben, // number of moves for probe
258 nprobes; // number of probes available
259 double inresor, // initial resources
260 intime, // initial time
261 inenrg, // initial/max energy
262 inshld, // initial/max shield
263 inlsr, // initial life support resources
264 indate, // initial date
265 energy, // energy level
266 shield, // shield level
267 warpfac, // warp speed
268 wfacsq, // squared warp factor
269 lsupres, // life support reserves
270 dist, // movement distance
271 direc, // movement direction
272 optime, // time taken by current operation
273 docfac, // repair factor when docking (constant?)
274 damfac, // damage factor
275 lastchart, // time star chart was last updated
276 cryprob, // probability that crystal will work
277 probex, // location of probe
279 probeinx, // probe x,y increment
281 height; // height of orbit around planet
283 extern struct game game;
285 /* the following global state doesn't need to be saved */
286 extern char *device[NDEVICES];
287 extern int iscore, iskill; // Common PLAQ
288 extern double perdate;
289 extern double aaitem;
290 extern char citem[10];
293 extern FILE *logfp, *replayfp;
295 /* the Space Thingy's global state should *not* be saved! */
297 extern bool iqhere, iqengry;
299 typedef enum {FWON, FDEPLETE, FLIFESUP, FNRG, FBATTLE,
300 FNEG3, FNOVA, FSNOVAED, FABANDN, FDILITHIUM,
301 FMATERIALIZE, FPHASER, FLOST, FMINING, FDPLANET,
302 FPNOVA, FSSC, FSTRACTOR, FDRAY, FTRIBBLE,
303 FHOLE, FCREW} FINTYPE ;
304 enum loctype {neither, quadrant, sector};
331 /* Function prototypes */
356 void finish(FINTYPE);
357 void selfdestruct(void);
369 void prout(char *, ...);
370 void proutn(char *, ...);
376 char *cramlc(enum loctype, coord w);
377 double expran(double);
384 void ram(bool, int, coord);
385 void crmena(bool, int, enum loctype, coord w);
386 void deadkl(coord, int, coord);
389 void torpedo(double, double, coord, double *, int, int);
391 void pause_game(int);
393 void snova(bool, coord *);
395 void hittem(double *);
396 void prouts(char *, ...);
404 void usecrystals(void);
408 void attakreport(bool);
412 void setwnd(WINDOW *);
415 void tracktorpedo(coord, int, int, int, int);
416 void cgetline(char *, int);
418 void setpassword(void);
419 void commandhook(char *, bool);
420 void makechart(void);
421 void enqueue(char *);
422 char *systemname(int);
425 /* mode arguments for srscan() */
427 #define SCAN_REQUEST 2
428 #define SCAN_STATUS 3
429 #define SCAN_NO_LEFTSIDE 4
431 extern WINDOW *curwnd;
432 extern WINDOW *fullscreen_window;
433 extern WINDOW *srscan_window;
434 extern WINDOW *report_window;
435 extern WINDOW *lrscan_window;
436 extern WINDOW *message_window;
437 extern WINDOW *prompt_window;
439 extern void clreol(void);
440 extern void clrscr(void);
441 extern void textcolor(int color);
442 extern void highvideo(void);
446 BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY,
447 DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE