These are unused.
[super-star-trek.git] / sst.c
diff --git a/sst.c b/sst.c
index ee5bd3eeb3c64ca443c67fc1696a015ec752df79..b60b57e5621dab63dc1ff7a0fe888ec49f4e2d3c 100644 (file)
--- a/sst.c
+++ b/sst.c
@@ -1,23 +1,19 @@
 #define INCLUDED       // Define externs here\r
-#include "sst.h"\r
 #include <ctype.h>\r
-#include <stdarg.h>\r
-#ifdef MSDOS\r
-#include <dos.h>\r
-#endif\r
-#include <time.h>\r
+#include <getopt.h>\r
+#include "sst.h"\r
 \r
 #ifndef SSTDOC\r
 #define SSTDOC "sst.doc"\r
 #endif\r
        \r
 static char line[128], *linep = line;\r
-static int linecount;  /* for paging */\r
-static int screenheight = 24;\r
 \r
-static void clearscreen(void);\r
+/*\r
+\r
+Here are Tom Almy's changes:\r
 \r
-/* Compared to original version, I've changed the "help" command to\r
+ Compared to original version, I've changed the "help" command to\r
    "call" and the "terminate" command to "quit" to better match\r
    user expectations. The DECUS version apparently made those changes\r
    as well as changing "freeze" to "save". However I like "freeze".\r
@@ -50,9 +46,41 @@ s
 \r
    6. Perhaps cloaking to be added later? BSD version\r
 \r
+Here are Stas Sergeev's changes (controlled by the proprocessor symbol\r
+SERGEEV, not yet merged):\r
 \r
-   */\r
+   1. The Space Thingy can be shoved, if you it ram, and can fire back if \r
+      fired upon.\r
+\r
+   1 The Tholian can be hit with phasers\r
+\r
+   2. When you are docked, base covers you with an almost invincible shields \r
+      (a commander can still ram you, or a Romulan can destroy the base,\r
+      or a SCom can even succeed with direct attack IIRC, but this rarely \r
+      happens).\r
+\r
+    3. SCom can't escape from you if no more enemies remain (without this, \r
+       chasing SCom can take an eternity).\r
+\r
+    4. Probe target you enter is now the destination quadrant. Before I don't \r
+       remember what it was, but it was something I had difficulty using)\r
+\r
+    5. Secret password is now autogenerated.\r
+\r
+    6. "Plaque" is adjusted for A4 paper:)\r
+\r
+    7. Phasers now tells you how much energy needed, but only if the computer \r
+       is alive.\r
+\r
+    8. Planets are auto-scanned when you enter the quadrant.\r
 \r
+    9. Mining or using crystals in presense of enemy now yields an attack.\r
+       There are other minor adjustments to what yields an attack\r
+       and what does not.\r
+\r
+    10. Ramming a black hole is no longer instant death.  \r
+\r
+   */\r
 \r
 static char *commands[] = {\r
        "srscan",\r
@@ -173,7 +201,6 @@ static void helpme(void) {
 \r
 static void makemoves(void) {\r
        int i, hitme;\r
-       char ch;\r
        while (TRUE) { /* command loop */\r
                hitme = FALSE;\r
                justin = 0;\r
@@ -198,6 +225,7 @@ static void makemoves(void) {
                        }\r
                        else prout("UNRECOGNIZED COMMAND.");\r
                }\r
+               commandhook(commands[i], TRUE);\r
                switch (i) { /* command switch */\r
                        case 0:                 // srscan\r
                                srscan(1);\r
@@ -224,7 +252,8 @@ static void makemoves(void) {
                                }\r
                                break;\r
                        case 6:                 // dock\r
-                               dock();\r
+                               dock(1);\r
+                                if (ididit) attack(0);\r
                                break;\r
                        case 7:                 // damages\r
                                dreprt();\r
@@ -322,6 +351,7 @@ static void makemoves(void) {
                                helpme();       // get help\r
                                break;\r
                }\r
+               commandhook(commands[i], FALSE);\r
                for (;;) {\r
                        if (alldone) break;             // Game has ended\r
 #ifdef DEBUG\r
@@ -353,23 +383,25 @@ static void makemoves(void) {
 \r
 \r
 int main(int argc, char **argv) {\r
-       int i;\r
-       int hitme;\r
-       char ch;\r
-       prelim();\r
-       char *LINES = getenv("LINES");\r
\r
-       if (LINES)\r
-           screenheight = atoi(LINES);\r
+    int i, option, usecurses = TRUE;\r
+       while ((option = getopt(argc, argv, "t")) != -1) {\r
+           switch (option) {\r
+           case 't':\r
+               usecurses = FALSE;\r
+               break;\r
+           default:\r
+               fprintf(stderr, "usage: sst [-t] [startcommand...].\n");\r
+               exit(0);\r
+           }\r
+       }\r
 \r
+       iostart(usecurses);\r
+       prelim(); \r
        line[0] = '\0';\r
-       if (argc > 1) {\r
-               while (--argc > 0) {\r
-                       strcat(line, *(++argv));\r
-                       strcat(line, " ");\r
-               }\r
+       for (i = optind; i < argc;  i++) {\r
+               strcat(line, argv[i]);\r
+               strcat(line, " ");\r
        }\r
-\r
        while (TRUE) { /* Play a game */\r
                setup(line[0] == '\0');\r
                if (alldone) {\r
@@ -392,7 +424,9 @@ int main(int argc, char **argv) {
                if (!ja()) break;\r
        }\r
        skip(1);\r
-       prout("May the Great Bird of the Galaxy roost upon your home planet.");\r
+       ioend();\r
+       puts("May the Great Bird of the Galaxy roost upon your home planet.");\r
+       exit(0);\r
 }\r
 \r
 \r
@@ -411,6 +445,7 @@ void cramen(int i) {
                case IHBLANK: s = "Black hole"; break;\r
                case IHT: s = "Tholian"; break;\r
                case IHWEB: s = "Tholian web"; break;\r
+                case IHQUEST: s = "Stranger"; break;\r
                default: s = "Unknown??"; break;\r
        }\r
        proutn(s);\r
@@ -466,14 +501,12 @@ void iran10(int *i, int *j) {
 }\r
 \r
 void chew(void) {\r
-       linecount = 0;\r
        linep = line;\r
        *linep = 0;\r
 }\r
 \r
 void chew2(void) {\r
        /* return IHEOL next time */\r
-       linecount = 0;\r
        linep = line+1;\r
        *linep = 0;\r
 }\r
@@ -482,8 +515,6 @@ int scan(void) {
        int i;\r
        char *cp;\r
 \r
-       linecount = 0;\r
-\r
        // Init result\r
        aaitem = 0.0;\r
        *citem = 0;\r
@@ -494,8 +525,7 @@ int scan(void) {
                        chew();\r
                        return IHEOL;\r
                }\r
-               fgets(line, sizeof(line), stdin);\r
-               line[strlen(line)-1] = '\0';\r
+               getline(line, sizeof(line));\r
                linep = line;\r
        }\r
        // Skip leading white space\r
@@ -507,6 +537,7 @@ int scan(void) {
        }\r
        if (isdigit(*linep) || *linep=='+' || *linep=='-' || *linep=='.') {\r
                // treat as a number\r
+           i = 0;\r
            if (sscanf(linep, "%lf%n", &aaitem, &i) < 1) {\r
                linep = line; // Invalid numbers are ignored\r
                *linep = 0;\r
@@ -539,97 +570,6 @@ int ja(void) {
        }\r
 }\r
 \r
-double square(double i) { return i*i; }\r
-                                                                       \r
-static void clearscreen(void) {\r
-       /* Somehow we need to clear the screen */\r
-#ifdef __BORLANDC__\r
-       extern void clrscr(void);\r
-       clrscr();\r
-#else\r
-       // proutn("\033[2J");   /* Hope for an ANSI display */\r
-       /* much more in that old-time TTY spirit to just throw linefeeds */\r
-       int i;\r
-       for (i = 0; i < screenheight; i++)\r
-           putchar('\n');\r
-#endif\r
-}\r
-\r
-/* We will pull these out in case we want to do something special later */\r
-\r
-void pause(int i) {\r
-       char buf[BUFSIZ];\r
-       putchar('\n');\r
-       if (i==1) {\r
-               if (skill > 2)\r
-                       prout("[ANOUNCEMENT ARRIVING...]");\r
-               else\r
-                       prout("[IMPORTANT ANNOUNCEMENT ARRIVING -- PRESS ENTER TO CONTINUE]");\r
-       }\r
-       else {\r
-               if (skill > 2)\r
-                       proutn("[CONTINUE?]");\r
-               else\r
-                       proutn("[PRESS ENTER TO CONTINUE]");\r
-\r
-       }\r
-       fgets(buf, sizeof(buf), stdin);\r
-       if (i != 0) {\r
-               clearscreen();\r
-       }\r
-       linecount = 0;\r
-}\r
-\r
-\r
-void skip(int i) {\r
-       while (i-- > 0) {\r
-               linecount++;\r
-               if (linecount >= screenheight)\r
-                       pause(0);\r
-               else\r
-                       putchar('\n');\r
-       }\r
-}\r
-\r
-\r
-void proutn(char *fmt, ...) {\r
-    va_list ap;\r
-    va_start(ap, fmt);\r
-    vprintf(fmt, ap);\r
-    va_end(ap);\r
-}\r
-\r
-void prout(char *fmt, ...) {\r
-    va_list ap;\r
-    va_start(ap, fmt);\r
-    vprintf(fmt, ap);\r
-    va_end(ap);\r
-    skip(1);\r
-}\r
-\r
-void proutc(char *line) {\r
-    line[strlen(line)-1] = '\0';\r
-    fputs(line, stdout);\r
-    skip(1);\r
-}\r
-\r
-void prouts(char *fmt, ...) {\r
-       clock_t endTime;\r
-       char *s, buf[BUFSIZ];\r
-       /* print slowly! */\r
-       va_list ap;\r
-       va_start(ap, fmt);\r
-       vsprintf(buf, fmt, ap);\r
-       va_end(ap);\r
-       skip(1);\r
-       for (s = buf; *s; s++) {\r
-               endTime = clock() + CLOCKS_PER_SEC*0.05;\r
-               while (clock() < endTime) ;\r
-               putchar(*s);\r
-               fflush(stdout);\r
-       }\r
-}\r
-\r
 void huh(void) {\r
        chew();\r
        skip(1);\r