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 fb508be4ce8e6dacc46618327b1c5b29424e36ab..dc26b35442556fcf1b04a2747ec573f8d1f8c2f7 100644 (file)
--- a/sst.c
+++ b/sst.c
@@ -2,7 +2,6 @@
 #include <ctype.h>
 #include <getopt.h>
 #include <time.h>
-#include "conio.h"
 #include "sstlinux.h"
 #include "sst.h"
 
@@ -10,8 +9,6 @@
 #define SSTDOC "sst.doc"
 #endif
        
-static char line[128], *linep = line;
-
 /*
 
 Here are Tom Almy's changes:
@@ -49,106 +46,105 @@ Here are Tom Almy's changes:
 
    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 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).
 
-    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.
 
-    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.
 
-    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.
 
+   13. Screen-oriented interface, with sensor scans always up.
+
 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[] = {
-#ifndef SERGEEV
 #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},
-#endif /* SERGEEV */
-#define PHASERS        3
+#define PHASERS        5
        {"PHASERS",     PHASERS},
-#define TORPEDO        4
+#define TORPEDO        6
         {"TORPEDO",    TORPEDO},
        {"PHOTONS",     TORPEDO},
-#define MOVE   5
+#define MOVE   7
        {"MOVE",        MOVE},
-#define SHIELDS        6
+#define SHIELDS        8
        {"SHIELDS",     SHIELDS},
-#define DOCK   7
+#define DOCK   9
        {"DOCK",        DOCK},
-#define DAMAGES        8
+#define DAMAGES        10
        {"DAMAGES",     DAMAGES},
-#define CHART  9
+#define CHART  11
        {"CHART",       CHART},
-#define IMPULSE        10
+#define IMPULSE        12
        {"IMPULSE",     IMPULSE},
-#define REST   11
+#define REST   13
        {"REST",        REST},
-#define WARP   12
+#define WARP   14
        {"WARP",        WARP},
-#define SCORE  13
+#define SCORE  15
        {"SCORE",       SCORE},
-#ifndef SERGEEV
-#define SENSORS        14
+#define SENSORS        16
        {"SENSORS",     SENSORS},
-#endif /* SERGEEV */
-#define ORBIT  15
+#define ORBIT  17
        {"ORBIT",       ORBIT},
-#define TRANSPORT      17
+#define TRANSPORT      18
        {"TRANSPORT",   TRANSPORT},
-#define MINE   18
+#define MINE   19
        {"MINE",        MINE},
-#define CRYSTALS 19
+#define CRYSTALS       20
        {"CRYSTALS",    CRYSTALS},
-#define SHUTTLE        20
+#define SHUTTLE        21
        {"SHUTTLE",     SHUTTLE},
-#define PLANETS        21
+#define PLANETS        22
        {"PLANETS",     PLANETS},
-#ifdef SERGEEV
-#define REQUEST        22
-       {"REQUEST",     REQUEST},
-#endif /* SERGEEV */
 #define REPORT 23
        {"REPORT",      REPORT},
 #define COMPUTER       24
@@ -164,9 +160,9 @@ commands[] = {
        {"FREEZE",      SAVE},
 #define ABANDON        29
        {"ABANDON",     ABANDON},
-#define DESTRUCT 30
+#define DESTRUCT       30
        {"DESTRUCT",    DESTRUCT},
-#define DEATHRAY 31
+#define DEATHRAY       31
        {"DEATHRAY",    DEATHRAY},
 #define DEBUGCMD       32
        {"DEBUG",       DEBUGCMD},
@@ -203,15 +199,11 @@ static void helpme(void) {
        key = scan();
        while (TRUE) {
                if (key == IHEOL) {
-#ifdef SERGEEV
                         setwnd(BOTTOM_WINDOW);
-#endif /* SERGEEV */
                         proutn("Help on what command? ");
                        key = scan();
                }
-#ifdef SERGEEV
                 setwnd(LOWER_WINDOW);
-#endif /* SERGEEV */
                if (key == IHEOL) return;
                for (i = 0; i < NUMCOMMANDS; i++) {
                    if (strcasecmp(commands[i].name, citem)==0) {
@@ -267,39 +259,19 @@ static void helpme(void) {
        while (fgets(linebuf, sizeof(linebuf),fp)) {
                if (strstr(linebuf, "******"))
                        break;
-               proutc(linebuf);
+               proutn(linebuf);
        }
        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) {
        int i, hitme;
-#ifdef SERGEEV
         clrscr();
         setwnd(LOWER_WINDOW);
-#endif /* SERGEEV */
        while (TRUE) { /* command loop */
                 drawmaps(1);
                 while (TRUE)  { /* get a command */
@@ -308,27 +280,17 @@ static void makemoves(void) {
                        Time = 0.0;
                        i = -1;
                        chew();
-#ifdef SERGEEV
                         setwnd(BOTTOM_WINDOW);
                         clrscr();
-#endif /* SERGEEV */
                        proutn("COMMAND> ");
                         if (scan() == IHEOL) {
-#ifdef SERGEEV
-                            _setcursortype(_NOCURSOR);
-                            setwnd(LOWER_WINDOW);
-                            clrscr();
-                            chart(0);
-                            _setcursortype(_NORMALCURSOR);
-#endif /* SERGEEV */
+                           makechart();
                             continue;
                         }
-#ifdef SERGEEV
                         ididit=0;
                         clrscr();
                         setwnd(LOWER_WINDOW);
                         clrscr();
-#endif /* SERGEEV */
                        for (i=0; i < ABANDON; i++)
                            if (isit(commands[i].name)) {
                                i = commands[i].value;
@@ -346,14 +308,18 @@ static void makemoves(void) {
                }
                commandhook(commands[i].name, TRUE);
                switch (i) { /* command switch */
-#ifndef SERGEEV
                         case SRSCAN:                 // srscan
-                               srscan(1);
+                               srscan(SCAN_FULL);
+                               break;
+                        case STATUS:                 // status
+                               srscan(SCAN_STATUS);
                                break;
+                       case REQUEST:                   // status request 
+                               srscan(SCAN_REQUEST);
+                               break;
                        case LRSCAN:                    // lrscan
                                lrscan();
                                 break;
-#endif /* SERGEEV */
                        case PHASERS:                   // phasers
                                phasers();
                                if (ididit) hitme = TRUE;
@@ -395,11 +361,9 @@ static void makemoves(void) {
                         case SCORE:                // score
                                 score();
                                break;
-#ifndef SERGEEV
                        case SENSORS:                   // sensors
                                sensor();
                                break;
-#endif /* SERGEEV */
                        case ORBIT:                     // orbit
                                orbit();
                                if (ididit) hitme = TRUE;
@@ -448,9 +412,7 @@ static void makemoves(void) {
                                break;
                        case SAVE:                      // Save Game
                                freeze(FALSE);
-#ifdef SERGEEV
                                 clrscr();
-#endif /* SERGEEV */
                                if (skill > 3)
                                         prout("WARNING--Saved games produce no plaques!");
                                break;
@@ -521,20 +483,17 @@ int main(int argc, char **argv) {
            }
        }
 
-#ifndef SERGEEV
-       iostart(usecurses);
-#else
        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 */
+               setwnd(FULLSCREEN_WINDOW);
+               clrscr();
                prelim();
                setup(line[0] == '\0');
                if (alldone) {
@@ -555,15 +514,8 @@ int main(int argc, char **argv) {
                }
                proutn("Do you want to play again? ");
                if (!ja()) break;
-#ifdef SERGEEV
-               setwnd(FULLSCREEN_WINDOW);
-               clrscr();
-#endif /* SERGEEV */
        }
        skip(1);
-#ifndef SERGEEV
-       ioend();
-#endif /* SERGEEV */
        prout("May the Great Bird of the Galaxy roost upon your home planet.");
        return 0;
 }
@@ -664,15 +616,13 @@ int scan(void) {
                        chew();
                        return IHEOL;
                }
-               getline(line, sizeof(line));
-#ifdef SERGEEV
+               cgetline(line, sizeof(line));
                 fflush(stdin);
                 if (curwnd==BOTTOM_WINDOW){
                    clrscr();
                    setwnd(LOWER_WINDOW);
                    clrscr();
                 }
-#endif /* SERGEEV */
                linep = line;
        }
        // Skip leading white space