7 #define DOC_NAME "sst.doc"
13 SRSCAN, MOVE, PHASERS, CALL, STATUS, IMPULSE, PHOTONS, ABANDON,
14 LRSCAN, WARP, SHIELDS, DESTRUCT, CHART, REST, DOCK, QUIT, and DAMAGE
15 were in the original non-"super" version of UT FORTRAN Star Trek.
17 Tholians weren't in the original. Dave is dubious about their merits.
18 (They are now controlled by OPTION_THOLIAN and turned off if the game
21 Planets and dilithium crystals weren't in the original. Dave is OK
22 with this idea. (It's now controlled by OPTION_PLANETS and turned
23 off if the game type is "plain".)
25 Dave says the bit about the Galileo getting turned into a
26 McDonald's is "consistant with our original vision". (This has been
27 left permanently enabled, as it can only happen if OPTION_PLANETS
30 Dave also says the Space Thingy should not be preserved across saved
31 games, so you can't prove to others that you've seen it. He says it
32 shouldn't fire back, either. It should do nothing except scream and
33 disappear when hit by photon torpedos. It's OK that it may move
34 when attacked, but it didn't in the original. (Whether the Thingy
35 can fire back is now controlled by OPTION_THINGY and turned off if the
36 game type is "plain" or "almy". The no-save behavior has been restored.)
38 The Faerie Queen, black holes, and time warping were in the original.
40 Here are Tom Almy's changes:
42 In early 1997, I got the bright idea to look for references to
43 "Super Star Trek" on the World Wide Web. There weren't many hits,
44 but there was one that came up with 1979 Fortran sources! This
45 version had a few additional features that mine didn't have,
46 however mine had some feature it didn't have. So I merged its
47 features that I liked. I also took a peek at the DECUS version (a
48 port, less sources, to the PDP-10), and some other variations.
50 1, Compared to the original UT version, I've changed the "help" command to
51 "call" and the "terminate" command to "quit" to better match
52 user expectations. The DECUS version apparently made those changes
53 as well as changing "freeze" to "save". However I like "freeze".
54 (Both "freeze" and "save" work in SST2K.)
56 2. The experimental deathray originally had only a 5% chance of
57 success, but could be used repeatedly. I guess after a couple
58 years of use, it was less "experimental" because the 1979
59 version had a 70% success rate. However it was prone to breaking
60 after use. I upgraded the deathray, but kept the original set of
61 failure modes (great humor!). (Now controlled by OPTION_DEATHRAY
62 and turned off if game type is "plain".)
64 3. The 1979 version also mentions srscan and lrscan working when
65 docked (using the starbase's scanners), so I made some changes here
66 to do this (and indicating that fact to the player), and then realized
67 the base would have a subspace radio as well -- doing a Chart when docked
68 updates the star chart, and all radio reports will be heard. The Dock
69 command will also give a report if a base is under attack.
71 4. Tholian Web from the 1979 version. (Now controlled by
72 OPTION_THOLIAN and turned off if game type is "plain".)
74 5. Enemies can ram the Enterprise. (Now controlled by OPTION_RAMMING
75 and turned off if game type is "plain".)
77 6. Regular Klingons and Romulans can move in Expert and Emeritus games.
78 This code could use improvement. (Now controlled by OPTION_MVBADDY
79 and turned off if game type is "plain".)
81 7. The deep-space probe feature from the DECUS version. (Now controlled
82 by OPTION_PROBE and turned off if game type is "plain").
84 8. 'emexit' command from the 1979 version.
86 9. Bugfix: Klingon commander movements are no longer reported if long-range
89 10. Bugfix: Better base positioning at startup (more spread out).
90 That made sense to add because most people abort games with
93 In June 2002, I fixed two known bugs and a documentation typo.
94 In June 2004 I fixed a number of bugs involving: 1) parsing invalid
95 numbers, 2) manual phasers when SR scan is damaged and commander is
96 present, 3) time warping into the future, 4) hang when moving
97 klingons in crowded quadrants. (These fixes are in SST2K.)
99 Here are Stas Sergeev's changes:
101 1. The Space Thingy can be shoved, if you ram it, and can fire back if
102 fired upon. (Now controlled by OPTION_THINGY and turned off if game
103 type is "plain" or "almy".)
105 2. When you are docked, base covers you with an almost invincible shield.
106 (A commander can still ram you, or a Romulan can destroy the base,
107 or a SCom can even succeed with direct attack IIRC, but this rarely
108 happens.) (Now controlled by OPTION_BASE and turned off if game
109 type is "plain" or "almy".)
111 3. Ramming a black hole is no longer instant death. There is a
112 chance you might get timewarped instead. (Now controlled by
113 OPTION_BLKHOLE and turned off if game type is "plain" or "almy".)
115 4. The Tholian can be hit with phasers.
117 5. SCom can't escape from you if no more enemies remain
118 (without this, chasing SCom can take an eternity).
120 6. Probe target you enter is now the destination quadrant. Before I don't
121 remember what it was, but it was something I had difficulty using.
123 7. Secret password is now autogenerated.
125 8. "Plaque" is adjusted for A4 paper :-)
127 9. Phasers now tells you how much energy needed, but only if the computer
130 10. Planets are auto-scanned when you enter the quadrant.
132 11. Mining or using crystals in presense of enemy now yields an attack.
133 There are other minor adjustments to what yields an attack
136 12. "freeze" command reverts to "save", most people will understand this
137 better anyway. (SST2K recognizes both.)
139 13. Screen-oriented interface, with sensor scans always up. (SST2K
140 supports both screen-oriented and TTY modes.)
142 Eric Raymond's changes:
144 Mainly, I translated this C code out of FORTRAN into C -- created #defines
145 for a lot of magic numbers and refactored the heck out of it.
147 1. "sos" and "call" becomes "mayday", "freeze" and "save" are both good.
149 2. Status report now indicates when dilithium crystals are on board.
151 3. Per Dave Matuszek's remarks, Thingy state is never saved across games.
153 4. Added game option selection so you can play a close (but not bug-for-
154 bug identical) approximation of older versions.
157 /* the input queue */
158 static char line[128], *linep = line;
161 int thingx, thingy, iqhere, iqengry;
162 int iscore, iskill; // Common PLAQ
167 char *device[NDEVICES] = {
188 unsigned long option;
193 {"SRSCAN", SRSCAN, OPTION_TTY},
195 {"STATUS", STATUS, OPTION_TTY},
197 {"REQUEST", REQUEST, OPTION_TTY},
199 {"LRSCAN", LRSCAN, OPTION_TTY},
201 {"PHASERS", PHASERS, 0},
203 {"TORPEDO", TORPEDO, 0},
204 {"PHOTONS", TORPEDO, 0},
208 {"SHIELDS", SHIELDS, 0},
212 {"DAMAGES", DAMAGES, 0},
216 {"IMPULSE", IMPULSE, 0},
224 {"SENSORS", SENSORS, OPTION_PLANETS},
226 {"ORBIT", ORBIT, OPTION_PLANETS},
228 {"TRANSPORT", TRANSPORT, OPTION_PLANETS},
230 {"MINE", MINE, OPTION_PLANETS},
232 {"CRYSTALS", CRYSTALS, OPTION_PLANETS},
234 {"SHUTTLE", SHUTTLE, OPTION_PLANETS},
236 {"PLANETS", PLANETS, OPTION_PLANETS},
238 {"REPORT", REPORT, 0},
240 {"COMPUTER", COMPUTER, 0},
242 {"COMMANDS", COMMANDS, 0},
244 {"EMEXIT", EMEXIT, 0},
246 {"PROBE", PROBE, OPTION_PROBE},
251 {"ABANDON", ABANDON, 0},
253 {"DESTRUCT", DESTRUCT, 0},
255 {"DEATHRAY", DEATHRAY, 0},
257 {"DEBUG", DEBUGCMD, 0},
259 {"MAYDAY", MAYDAY, 0},
260 //{"SOS", MAYDAY, 0},
261 //{"CALL", MAYDAY, 0},
268 #define NUMCOMMANDS sizeof(commands)/sizeof(commands[0])
269 #define ACCEPT(i) (!commands[i].option || (commands[i].option & game.options))
271 static void listCommands(void) {
273 proutn("LEGAL COMMANDS ARE:");
274 for (i = 0; i < NUMCOMMANDS; i++) {
279 proutn("%-12s ", commands[i].name);
285 static void helpme(void)
288 char cmdbuf[32], *cp;
291 /* Give help on commands */
296 setwnd(prompt_window);
297 proutn("Help on what command? ");
300 setwnd(message_window);
301 if (key == IHEOL) return;
302 for (i = 0; i < NUMCOMMANDS; i++) {
303 if (ACCEPT(i) && strcasecmp(commands[i].name, citem)==0) {
304 i = commands[i].value;
308 if (i != NUMCOMMANDS) break;
310 prout("Valid commands:");
317 strcpy(cmdbuf, " ABBREV");
320 for (j = 0; commands[i].name[j]; j++)
321 cmdbuf[j] = toupper(commands[i].name[j]);
324 fp = fopen(SSTDOC, "r");
326 fp = fopen(DOC_NAME, "r");
328 prout("Spock- \"Captain, that information is missing from the");
329 prout(" computer. You need to find "DOC_NAME" and put it in the");
330 prout(" current directory or to "SSTDOC".\"");
332 * This used to continue: "You need to find SST.DOC and put
333 * it in the current directory."
338 if (fgets(linebuf, sizeof(linebuf), fp) == NULL) {
339 prout("Spock- \"Captain, there is no information on that command.\"");
343 if (linebuf[0] == '%' && linebuf[1] == '%'&& linebuf[2] == ' ') {
344 for (cp = linebuf+3; isspace(*cp); cp++)
346 linebuf[strlen(linebuf)-1] = '\0';
347 if (strcasecmp(cp, cmdbuf) == 0)
353 prout("Spock- \"Captain, I've found the following information:\"");
356 while (fgets(linebuf, sizeof(linebuf),fp)) {
357 if (strstr(linebuf, "******"))
364 void enqueue(char *s)
369 static void makemoves(void)
373 setwnd(message_window);
374 while (TRUE) { /* command loop */
376 while (TRUE) { /* get a command */
382 setwnd(prompt_window);
385 if (scan() == IHEOL) {
391 setwnd(message_window);
393 for (i=0; i < ABANDON; i++)
394 if (ACCEPT(i) && isit(commands[i].name)) {
395 v = commands[i].value;
398 if (i < ABANDON && (!commands[i].option || (commands[i].option & game.options)))
400 for (; i < NUMCOMMANDS; i++)
401 if (ACCEPT(i) && strcasecmp(commands[i].name, citem) == 0) {
402 v = commands[i].value;
405 if (i < NUMCOMMANDS && (!commands[i].option || (commands[i].option & game.options)))
409 commandhook(commands[i].name, TRUE);
410 switch (v) { /* command switch */
411 case SRSCAN: // srscan
414 case STATUS: // status
417 case REQUEST: // status request
418 srscan(SCAN_REQUEST);
420 case LRSCAN: // lrscan
423 case PHASERS: // phasers
425 if (ididit) hitme = TRUE;
427 case TORPEDO: // photons
429 if (ididit) hitme = TRUE;
434 case SHIELDS: // shields
443 if (ididit) attack(0);
445 case DAMAGES: // damages
451 case IMPULSE: // impulse
456 if (ididit) hitme = TRUE;
464 case SENSORS: // sensors
469 if (ididit) hitme = TRUE;
471 case TRANSPORT: // transport "beam"
476 if (ididit) hitme = TRUE;
478 case CRYSTALS: // crystals
480 if (ididit) hitme = TRUE;
482 case SHUTTLE: // shuttle
484 if (ididit) hitme = TRUE;
486 case PLANETS: // Planet list
489 case REPORT: // Game Report
492 case COMPUTER: // use COMPUTER!
498 case EMEXIT: // Emergency exit
499 clrscr(); // Hide screen
500 freeze(TRUE); // forced save
501 exit(1); // And quick exit
504 probe(); // Launch probe
505 if (ididit) hitme = TRUE;
507 case ABANDON: // Abandon Ship
510 case DESTRUCT: // Self Destruct
513 case SAVE: // Save Game
516 if (skill > SKILL_GOOD)
517 prout("WARNING--Saved games produce no plaques!");
519 case DEATHRAY: // Try a desparation measure
521 if (ididit) hitme = TRUE;
523 case DEBUGCMD: // What do we want for debug???
528 case MAYDAY: // Call for help
530 if (ididit) hitme = TRUE;
533 alldone = 1; // quit the game
539 helpme(); // get help
542 commandhook(commands[i].name, FALSE);
544 if (alldone) break; // Game has ended
546 if (idebug) prout("2500");
550 if (alldone) break; // Events did us in
552 if (game.state.galaxy[quadx][quady].supernova) { // Galaxy went Nova!
556 if (hitme && justin==0) {
559 if (game.state.galaxy[quadx][quady].supernova) { // went NOVA!
572 int main(int argc, char **argv)
576 game.options = OPTION_ALL &~ (OPTION_IOMODES | OPTION_SHOWME | OPTION_PLAIN | OPTION_ALMY);
578 game.options |= OPTION_CURSES | OPTION_SHOWME;
580 game.options |= OPTION_TTY;
582 while ((option = getopt(argc, argv, "t")) != -1) {
585 game.options |= OPTION_TTY;
586 game.options &=~ OPTION_CURSES;
589 fprintf(stderr, "usage: sst [-t] [startcommand...].\n");
598 for (i = optind; i < argc; i++) {
599 strcat(line, argv[i]);
602 while (TRUE) { /* Play a game */
603 setwnd(fullscreen_window);
605 prout("INITIAL OPTIONS: %0lx", game.options);
609 setup(line[0] == '\0');
619 if (tourn && alldone) {
620 proutn("Do you want your score recorded?");
626 proutn("Do you want to play again? ");
630 prout("May the Great Bird of the Galaxy roost upon your home planet.");
637 /* return an enemy */
641 case IHR: s = "Romulan"; break;
642 case IHK: s = "Klingon"; break;
643 case IHC: s = "Commander"; break;
644 case IHS: s = "Super-commander"; break;
645 case IHSTAR: s = "Star"; break;
646 case IHP: s = "Planet"; break;
647 case IHB: s = "Starbase"; break;
648 case IHBLANK: s = "Black hole"; break;
649 case IHT: s = "Tholian"; break;
650 case IHWEB: s = "Tholian web"; break;
651 case IHQUEST: s = "Stranger"; break;
652 default: s = "Unknown??"; break;
657 char *cramlc(enum loctype key, int x, int y)
661 if (key == quadrant) strcpy(buf, "Quadrant ");
662 else if (key == sector) strcpy(buf, "Sector ");
663 sprintf(buf+strlen(buf), "%d - %d", x, y);
667 void crmena(int i, int enemy, int key, int x, int y)
669 if (i == 1) proutn("***");
672 proutn(cramlc(key, x, y));
679 case IHE: s = "Enterprise"; break;
680 case IHF: s = "Faerie Queene"; break;
681 default: s = "Ship???"; break;
688 prouts("******************************************************");
692 double expran(double avrage)
694 return -avrage*log(1e-7 + Rand());
698 return rand()/(1.0 + (double)RAND_MAX);
701 void iran(int size, int *i, int *j)
703 *i = Rand()*(size*1.0) + 1.0;
704 *j = Rand()*(size*1.0) + 1.0;
715 /* return IHEOL next time */
729 // Read a line if nothing here
735 cgetline(line, sizeof(line));
737 if (curwnd==prompt_window){
739 setwnd(message_window);
744 // Skip leading white space
745 while (*linep == ' ') linep++;
751 if (isdigit(*linep) || *linep=='+' || *linep=='-' || *linep=='.') {
754 if (sscanf(linep, "%lf%n", &aaitem, &i) < 1) {
755 linep = line; // Invalid numbers are ignored
767 while (*linep && *linep!=' ') {
768 if ((cp - citem) < 9) *cp++ = tolower(*linep);
781 if (*citem == 'y') return TRUE;
782 if (*citem == 'n') return FALSE;
783 proutn("Please answer with \"Y\" or \"N\": ");
791 prout("Beg your pardon, Captain?");
796 /* New function -- compares s to scanned citem and returns true if it
797 matches to the length of s */
799 return strncasecmp(s, citem, max(1, strlen(citem))) == 0;
806 proutn("Reset levels? ");
808 if (energy < inenrg) energy = inenrg;
813 proutn("Reset damage? ");
816 for (i=0; i < NDEVICES; i++)
817 if (game.damage[i] > 0.0)
818 game.damage[i] = 0.0;
820 proutn("Toggle idebug? ");
823 if (idebug) prout("Debug output ON");
824 else prout("Debug output OFF");
826 proutn("Cause selective damage? ");
829 for (i=0; i < NDEVICES; i++) {
835 if (key == IHALPHA && isit("y")) {
836 game.damage[i] = 10.0;
840 proutn("Examine/change events? ");
843 for (i = 1; i < NEVENTS; i++) {
845 if (game.future[i] == FOREVER) continue;
847 case FSNOVA: proutn("Supernova "); break;
848 case FTBEAM: proutn("T Beam "); break;
849 case FSNAP: proutn("Snapshot "); break;
850 case FBATTAK: proutn("Base Attack "); break;
851 case FCDBAS: proutn("Base Destroy "); break;
852 case FSCMOVE: proutn("SC Move "); break;
853 case FSCDBAS: proutn("SC Base Destroy "); break;
855 proutn("%.2f", game.future[i]-game.state.date);
860 game.future[i] = game.state.date + aaitem;
865 proutn("Induce supernova here? ");
867 game.state.galaxy[quadx][quady].supernova = TRUE;