Merge some more SERGEEV stuff.
[super-star-trek.git] / sst.c
diff --git a/sst.c b/sst.c
index 8d82100865f63fd1a37f9581e18906a7cc703939..3567c2551b8aa14c25d622fdcc77a5de6d3097b4 100644 (file)
--- a/sst.c
+++ b/sst.c
@@ -1,6 +1,7 @@
 #define INCLUDED       // Define externs here\r
-#include "sst.h"\r
 #include <ctype.h>\r
+#include <getopt.h>\r
+#include "sst.h"\r
 \r
 #ifndef SSTDOC\r
 #define SSTDOC "sst.doc"\r
@@ -8,7 +9,11 @@
        \r
 static char line[128], *linep = line;\r
 \r
-/* Compared to original version, I've changed the "help" command to\r
+/*\r
+\r
+Here are Tom Almy's changes:\r
+\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
@@ -30,10 +35,10 @@ static char line[128], *linep = line;
 \r
    1. Better base positioning at startup\r
 \r
-   2. deathray improvement (but keeping original failure alternatives)\r
+   2. Deathray improvement (but keeping original failure alternatives)\r
+\r
+   3. Tholian Web.\r
 \r
-   3. Tholian Web\r
-s\r
    4. Enemies can ram the Enterprise. Regular Klingons and Romulans can\r
       move in Expert and Emeritus games. This code could use improvement.\r
 \r
@@ -41,9 +46,42 @@ 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 completely 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.  There is a\r
+        chance you might get timewarped instead.\r
+\r
+   */\r
 \r
 static char *commands[] = {\r
        "srscan",\r
@@ -95,6 +133,21 @@ static void listCommands(int x) {
        if (x) prout("   HELP");\r
 }\r
 \r
+#ifdef SERGEEV\r
+void setwnd(short wndnum){\r
+     int cury;\r
+     cury=wherey()+wnds[curwnd].wndtop-wnds[wndnum].wndtop;\r
+     if ((curwnd==0)&&(wndnum!=0)) clrscr();\r
+     window(wnds[wndnum].wndleft, wnds[wndnum].wndtop, wnds[wndnum].wndright, wnds[wndnum].wndbottom);\r
+     if ((curwnd==wndnum)&&(cury>wnds[wndnum].wndbottom-wnds[wndnum].wndtop+1)){\r
+        gotoxy(wnds[wndnum].wndright-wnds[wndnum].wndleft+1,wnds[wndnum].wndbottom-wnds[wndnum].wndtop+1);\r
+       skip(1);\r
+     }\r
+     curwnd=wndnum;\r
+     gotoxy(1,cury);\r
+}\r
+#endif /* SERGEEV */\r
+\r
 static void helpme(void) {\r
        int i, j;\r
        char cmdbuf[32], *cp;\r
@@ -105,9 +158,15 @@ static void helpme(void) {
        key = scan();\r
        while (TRUE) {\r
                if (key == IHEOL) {\r
-                       proutn("Help on what command?");\r
+#ifdef SERGEEV\r
+                        setwnd(5);\r
+#endif /* SERGEEV */\r
+                        proutn("Help on what command? ");\r
                        key = scan();\r
                }\r
+#ifdef SERGEEV\r
+                setwnd(4);\r
+#endif /* SERGEEV */\r
                if (key == IHEOL) return;\r
                for (i = 0; i < NUMCOMMANDS; i++) {\r
                        if (strcmp(commands[i], citem)==0) break;\r
@@ -162,9 +221,29 @@ static void helpme(void) {
        fclose(fp);\r
 }\r
 \r
+#ifdef SERGEEV\r
+void drawmaps(short l){\r
+     _setcursortype(_NOCURSOR);\r
+     if (l==1) sensor();\r
+     if (l!=2) setwnd(1);\r
+     gotoxy(1,1);\r
+     strcpy(line,"s");\r
+     srscan(1);\r
+     if (l!=2){\r
+        setwnd(2);\r
+        clrscr();\r
+        srscan(2);\r
+        setwnd(3);\r
+        clrscr();\r
+        strcpy(line,"l");\r
+        lrscan();\r
+        _setcursortype(_NORMALCURSOR);\r
+     }\r
+}\r
+#endif /* SERGEEV */\r
+\r
 static void makemoves(void) {\r
        int i, hitme;\r
-       char ch;\r
        while (TRUE) { /* command loop */\r
                hitme = FALSE;\r
                justin = 0;\r
@@ -189,6 +268,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
@@ -215,7 +295,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
@@ -313,6 +394,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
@@ -344,20 +426,25 @@ static void makemoves(void) {
 \r
 \r
 int main(int argc, char **argv) {\r
-       int i;\r
-       int hitme;\r
-       char ch;\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();\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
@@ -376,12 +463,19 @@ int main(int argc, char **argv) {
                                freeze(FALSE);\r
                        }\r
                }\r
-               proutn("Do you want to play again?");\r
+               proutn("Do you want to play again? ");\r
                if (!ja()) break;\r
+#ifdef SERGEEV\r
+               setwnd(0);\r
+               clrscr();\r
+#endif /* SERGEEV */\r
        }\r
        skip(1);\r
+#ifndef SERGEEV\r
        ioend();\r
+#endif /* SERGEEV */\r
        puts("May the Great Bird of the Galaxy roost upon your home planet.");\r
+       exit(0);\r
 }\r
 \r
 \r
@@ -400,6 +494,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
@@ -480,7 +575,6 @@ int scan(void) {
                        return IHEOL;\r
                }\r
                getline(line, sizeof(line));\r
-               line[strlen(line)-1] = '\0';\r
                linep = line;\r
        }\r
        // Skip leading white space\r
@@ -492,6 +586,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
@@ -520,12 +615,10 @@ int ja(void) {
                chew();\r
                if (*citem == 'y') return TRUE;\r
                if (*citem == 'n') return FALSE;\r
-               proutn("Please answer with \"Y\" or \"N\":");\r
+               proutn("Please answer with \"Y\" or \"N\": ");\r
        }\r
 }\r
 \r
-double square(double i) { return i*i; }\r
-                                                                       \r
 void huh(void) {\r
        chew();\r
        skip(1);\r