This completely merges the line-oriented and screen I/O managers,
[super-star-trek.git] / sst.c
diff --git a/sst.c b/sst.c
index f6b86b1cedb6f876bb9d92e3747696183214e206..dc26b35442556fcf1b04a2747ec573f8d1f8c2f7 100644 (file)
--- a/sst.c
+++ b/sst.c
@@ -2,7 +2,6 @@
 #include <ctype.h>
 #include <getopt.h>
 #include <time.h>
 #include <ctype.h>
 #include <getopt.h>
 #include <time.h>
-#include "conio.h"
 #include "sstlinux.h"
 #include "sst.h"
 
 #include "sstlinux.h"
 #include "sst.h"
 
@@ -10,8 +9,6 @@
 #define SSTDOC "sst.doc"
 #endif
        
 #define SSTDOC "sst.doc"
 #endif
        
-static char line[128], *linep = line;
-
 /*
 
 Here are Tom Almy's changes:
 /*
 
 Here are Tom Almy's changes:
@@ -49,130 +46,133 @@ Here are Tom Almy's changes:
 
    6. Perhaps cloaking to be added later? BSD version
 
 
    6. Perhaps cloaking to be added later? BSD version
 
-Here are Stas Sergeev's changes (controlled by the proprocessor symbol
-SERGEEV, not yet completely merged):
+Here are Stas Sergeev's changes:
 
    1. The Space Thingy can be shoved, if you it ram, and can fire back if 
       fired upon.
 
 
    1. The Space Thingy can be shoved, if you it ram, and can fire back if 
       fired upon.
 
-   1 The Tholian can be hit with phasers
+   2. The Tholian can be hit with phasers
 
 
-   2. When you are docked, base covers you with an almost invincible shields 
+   3. When you are docked, base covers you with an almost invincible shields 
       (a commander can still ram you, or a Romulan can destroy the base,
       or a SCom can even succeed with direct attack IIRC, but this rarely 
       happens).
 
       (a commander can still ram you, or a Romulan can destroy the base,
       or a SCom can even succeed with direct attack IIRC, but this rarely 
       happens).
 
-    3. SCom can't escape from you if no more enemies remain (without this, 
-       chasing SCom can take an eternity).
+   4. SCom can't escape from you if no more enemies remain (without this, 
+      chasing SCom can take an eternity).
 
 
-    4. Probe target you enter is now the destination quadrant. Before I don't 
-       remember what it was, but it was something I had difficulty using)
+   5. Probe target you enter is now the destination quadrant. Before I don't 
+      remember what it was, but it was something I had difficulty using)
 
 
-    5. Secret password is now autogenerated.
+   6. Secret password is now autogenerated.
 
 
-    6. "Plaque" is adjusted for A4 paper:)
+   7. "Plaque" is adjusted for A4 paper :-)
 
 
-    7. Phasers now tells you how much energy needed, but only if the computer 
+   8. Phasers now tells you how much energy needed, but only if the computer 
        is alive.
 
        is alive.
 
-    8. Planets are auto-scanned when you enter the quadrant.
+   9. Planets are auto-scanned when you enter the quadrant.
 
 
-    9. Mining or using crystals in presense of enemy now yields an attack.
+   10. Mining or using crystals in presense of enemy now yields an attack.
        There are other minor adjustments to what yields an attack
        and what does not.
 
        There are other minor adjustments to what yields an attack
        and what does not.
 
-    10. Ramming a black hole is no longer instant death.  There is a
-        chance you might get timewarped instead.
+   11. Ramming a black hole is no longer instant death.  There is a
+       chance you might get timewarped instead.
 
 
-    11. "freeze" command reverts to "save", most people will understand this
+   12. "freeze" command reverts to "save", most people will understand this
         better anyway.
 
         better anyway.
 
+   13. Screen-oriented interface, with sensor scans always up.
+
 Eric Raymond's changes:
 
 Eric Raymond's changes:
 
-     1. "sos" and "call" becomes "mayday", "freeze" and "save" are both good.
+   1. "sos" and "call" becomes "mayday", "freeze" and "save" are both good.
 
    */
 
 
    */
 
+/* the input queue */
+static char line[128], *linep = line;
+
 static struct 
 {
     char *name;
     int value;
 }
 commands[] = {
 static struct 
 {
     char *name;
     int value;
 }
 commands[] = {
-#ifndef SERGEEV
 #define SRSCAN 1
        {"SRSCAN",      SRSCAN},
 #define SRSCAN 1
        {"SRSCAN",      SRSCAN},
-       {"STATUS",      SRSCAN},
-#define LRSCAN 2
+#define STATUS 2
+       {"STATUS",      STATUS},
+#define REQUEST        3
+       {"REQUEST",     REQUEST},
+#define LRSCAN 4
        {"LRSCAN",      LRSCAN},
        {"LRSCAN",      LRSCAN},
-#endif /* SERGEEV */
-#define PHASERS        3
+#define PHASERS        5
        {"PHASERS",     PHASERS},
        {"PHASERS",     PHASERS},
-#define TORPEDO        4
+#define TORPEDO        6
         {"TORPEDO",    TORPEDO},
        {"PHOTONS",     TORPEDO},
         {"TORPEDO",    TORPEDO},
        {"PHOTONS",     TORPEDO},
-#define MOVE   5
+#define MOVE   7
        {"MOVE",        MOVE},
        {"MOVE",        MOVE},
-#define SHIELDS        6
+#define SHIELDS        8
        {"SHIELDS",     SHIELDS},
        {"SHIELDS",     SHIELDS},
-#define DOCK   7
+#define DOCK   9
        {"DOCK",        DOCK},
        {"DOCK",        DOCK},
-#define DAMAGES        8
+#define DAMAGES        10
        {"DAMAGES",     DAMAGES},
        {"DAMAGES",     DAMAGES},
-#define CHART  9
+#define CHART  11
        {"CHART",       CHART},
        {"CHART",       CHART},
-#define IMPULSE        10
+#define IMPULSE        12
        {"IMPULSE",     IMPULSE},
        {"IMPULSE",     IMPULSE},
-#define REST   11
+#define REST   13
        {"REST",        REST},
        {"REST",        REST},
-#define WARP   12
+#define WARP   14
        {"WARP",        WARP},
        {"WARP",        WARP},
-#define SCORE  13
+#define SCORE  15
        {"SCORE",       SCORE},
        {"SCORE",       SCORE},
-#ifndef SERGEEV
-#define SENSORS        14
+#define SENSORS        16
        {"SENSORS",     SENSORS},
        {"SENSORS",     SENSORS},
-#endif /* SERGEEV */
-#define ORBIT  15
+#define ORBIT  17
        {"ORBIT",       ORBIT},
        {"ORBIT",       ORBIT},
-#define TRANSPORT      16
+#define TRANSPORT      18
        {"TRANSPORT",   TRANSPORT},
        {"TRANSPORT",   TRANSPORT},
-#define MINE   17
+#define MINE   19
        {"MINE",        MINE},
        {"MINE",        MINE},
-#define CRYSTALS 18
+#define CRYSTALS       20
        {"CRYSTALS",    CRYSTALS},
        {"CRYSTALS",    CRYSTALS},
-#define SHUTTLE        19
+#define SHUTTLE        21
        {"SHUTTLE",     SHUTTLE},
        {"SHUTTLE",     SHUTTLE},
-#define PLANETS        20
+#define PLANETS        22
        {"PLANETS",     PLANETS},
        {"PLANETS",     PLANETS},
-#define REPORT 21
+#define REPORT 23
        {"REPORT",      REPORT},
        {"REPORT",      REPORT},
-#define COMPUTER       23
+#define COMPUTER       24
        {"COMPUTER",    COMPUTER},
        {"COMPUTER",    COMPUTER},
-#define COMMANDS       24
+#define COMMANDS       25
        {"COMMANDS",    COMMANDS},
        {"COMMANDS",    COMMANDS},
-#define EMEXIT 25
+#define EMEXIT 26
        {"EMEXIT",      EMEXIT},
        {"EMEXIT",      EMEXIT},
-#define PROBE  26
+#define PROBE  27
        {"PROBE",       PROBE},
        {"PROBE",       PROBE},
-#define SAVE   27
+#define SAVE   28
        {"SAVE",        SAVE},
        {"FREEZE",      SAVE},
        {"SAVE",        SAVE},
        {"FREEZE",      SAVE},
-#define ABANDON        28
+#define ABANDON        29
        {"ABANDON",     ABANDON},
        {"ABANDON",     ABANDON},
-#define DESTRUCT 29
+#define DESTRUCT       30
        {"DESTRUCT",    DESTRUCT},
        {"DESTRUCT",    DESTRUCT},
-#define DEATHRAY 30
+#define DEATHRAY       31
        {"DEATHRAY",    DEATHRAY},
        {"DEATHRAY",    DEATHRAY},
-#define DEBUGCMD       31
+#define DEBUGCMD       32
        {"DEBUG",       DEBUGCMD},
        {"DEBUG",       DEBUGCMD},
-#define MAYDAY 32
+#define MAYDAY 33
        {"MAYDAY",      MAYDAY},
        {"SOS",         MAYDAY},
        {"CALL",        MAYDAY},
        {"MAYDAY",      MAYDAY},
        {"SOS",         MAYDAY},
        {"CALL",        MAYDAY},
-#define QUIT   33
+#define QUIT   34
        {"QUIT",        QUIT},
        {"QUIT",        QUIT},
-#define HELP   34
+#define HELP   35
        {"HELP",        HELP},
 };
 
        {"HELP",        HELP},
 };
 
@@ -259,31 +259,13 @@ static void helpme(void) {
        while (fgets(linebuf, sizeof(linebuf),fp)) {
                if (strstr(linebuf, "******"))
                        break;
        while (fgets(linebuf, sizeof(linebuf),fp)) {
                if (strstr(linebuf, "******"))
                        break;
-               proutc(linebuf);
+               proutn(linebuf);
        }
        fclose(fp);
 }
 
        }
        fclose(fp);
 }
 
-void drawmaps(short l) {
-/* hook to be called after moving to redraw maps */
-#ifdef SERGEEV
-     _setcursortype(_NOCURSOR);
-     if (l==1) sensor();
-     if (l!=2) setwnd(LEFTUPPER_WINDOW);
-     gotoxy(1,1);
-     strcpy(line,"s");
-     srscan(1);
-     if (l!=2){
-        setwnd(SRSCAN_WINDOW);
-        clrscr();
-        srscan(2);
-        setwnd(LRSCAN_WINDOW);
-        clrscr();
-        strcpy(line,"l");
-        lrscan();
-        _setcursortype(_NORMALCURSOR);
-     }
-#endif /* SERGEEV */
+void enqueue(char *s) {
+    strcpy(line, s);
 }
 
 static void makemoves(void) {
 }
 
 static void makemoves(void) {
@@ -302,13 +284,7 @@ static void makemoves(void) {
                         clrscr();
                        proutn("COMMAND> ");
                         if (scan() == IHEOL) {
                         clrscr();
                        proutn("COMMAND> ");
                         if (scan() == IHEOL) {
-#ifdef SERGEEV
-                            _setcursortype(_NOCURSOR);
-                            setwnd(LOWER_WINDOW);
-                            clrscr();
-                            chart(0);
-                            _setcursortype(_NORMALCURSOR);
-#endif /* SERGEEV */
+                           makechart();
                             continue;
                         }
                         ididit=0;
                             continue;
                         }
                         ididit=0;
@@ -332,14 +308,18 @@ static void makemoves(void) {
                }
                commandhook(commands[i].name, TRUE);
                switch (i) { /* command switch */
                }
                commandhook(commands[i].name, TRUE);
                switch (i) { /* command switch */
-#ifndef SERGEEV
                         case SRSCAN:                 // srscan
                         case SRSCAN:                 // srscan
-                               srscan(1);
+                               srscan(SCAN_FULL);
                                break;
                                break;
+                        case STATUS:                 // status
+                               srscan(SCAN_STATUS);
+                               break;
+                       case REQUEST:                   // status request 
+                               srscan(SCAN_REQUEST);
+                               break;
                        case LRSCAN:                    // lrscan
                                lrscan();
                                 break;
                        case LRSCAN:                    // lrscan
                                lrscan();
                                 break;
-#endif /* SERGEEV */
                        case PHASERS:                   // phasers
                                phasers();
                                if (ididit) hitme = TRUE;
                        case PHASERS:                   // phasers
                                phasers();
                                if (ididit) hitme = TRUE;
@@ -381,11 +361,9 @@ static void makemoves(void) {
                         case SCORE:                // score
                                 score();
                                break;
                         case SCORE:                // score
                                 score();
                                break;
-#ifndef SERGEEV
                        case SENSORS:                   // sensors
                                sensor();
                                break;
                        case SENSORS:                   // sensors
                                sensor();
                                break;
-#endif /* SERGEEV */
                        case ORBIT:                     // orbit
                                orbit();
                                if (ididit) hitme = TRUE;
                        case ORBIT:                     // orbit
                                orbit();
                                if (ididit) hitme = TRUE;
@@ -505,20 +483,17 @@ int main(int argc, char **argv) {
            }
        }
 
            }
        }
 
-#ifndef SERGEEV
-       iostart(usecurses);
-#else
        randomize();
        randomize();
-        textattr(7);
-        clrscr();
-        setwnd(FULLSCREEN_WINDOW);
-#endif /* SERGEEV */
+       iostart(usecurses);
+
        line[0] = '\0';
        for (i = optind; i < argc;  i++) {
                strcat(line, argv[i]);
                strcat(line, " ");
        }
        while (TRUE) { /* Play a game */
        line[0] = '\0';
        for (i = optind; i < argc;  i++) {
                strcat(line, argv[i]);
                strcat(line, " ");
        }
        while (TRUE) { /* Play a game */
+               setwnd(FULLSCREEN_WINDOW);
+               clrscr();
                prelim();
                setup(line[0] == '\0');
                if (alldone) {
                prelim();
                setup(line[0] == '\0');
                if (alldone) {
@@ -539,13 +514,8 @@ int main(int argc, char **argv) {
                }
                proutn("Do you want to play again? ");
                if (!ja()) break;
                }
                proutn("Do you want to play again? ");
                if (!ja()) break;
-               setwnd(FULLSCREEN_WINDOW);
-               clrscr();
        }
        skip(1);
        }
        skip(1);
-#ifndef SERGEEV
-       ioend();
-#endif /* SERGEEV */
        prout("May the Great Bird of the Galaxy roost upon your home planet.");
        return 0;
 }
        prout("May the Great Bird of the Galaxy roost upon your home planet.");
        return 0;
 }
@@ -647,14 +617,12 @@ int scan(void) {
                        return IHEOL;
                }
                cgetline(line, sizeof(line));
                        return IHEOL;
                }
                cgetline(line, sizeof(line));
-#ifdef SERGEEV
                 fflush(stdin);
                 if (curwnd==BOTTOM_WINDOW){
                    clrscr();
                    setwnd(LOWER_WINDOW);
                    clrscr();
                 }
                 fflush(stdin);
                 if (curwnd==BOTTOM_WINDOW){
                    clrscr();
                    setwnd(LOWER_WINDOW);
                    clrscr();
                 }
-#endif /* SERGEEV */
                linep = line;
        }
        // Skip leading white space
                linep = line;
        }
        // Skip leading white space