Get rid of FORTRANisms.
[super-star-trek.git] / sst.c
diff --git a/sst.c b/sst.c
index c353d04b0621bfe41e97a429c538f25b4aaac314..23e10016f42312fd7c8994f33b0ecffe3b5f9f58 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,151 +46,156 @@ 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.
+ Mainly, I translated this C code out of FORTRAN into C -- created #defines
+   for a lot of magic numbers.
+
+   1. "sos" and "call" becomes "mayday", "freeze" and "save" are both good.
+
+   2. Status report now indicates when dilithium crystals are on board.
+
+   3. Can now report starbases left in scrscan.
 
    */
 
 
    */
 
+/* the input queue */
+static char line[128], *linep = line;
+static int usecurses = TRUE;
+
 static struct 
 {
     char *name;
     int value;
 }
 commands[] = {
 static struct 
 {
     char *name;
     int value;
 }
 commands[] = {
-#ifndef SERGEEV
-#define SRSCAN 1
+#define SRSCAN 0
        {"SRSCAN",      SRSCAN},
        {"SRSCAN",      SRSCAN},
-       {"STATUS",      SRSCAN},
-#define LRSCAN 2
+#define STATUS 1
+       {"STATUS",      STATUS},
+#define REQUEST        2
+       {"REQUEST",     REQUEST},
+#define LRSCAN 3
        {"LRSCAN",      LRSCAN},
        {"LRSCAN",      LRSCAN},
-#endif /* SERGEEV */
-#define PHASERS        3
+#define PHASERS        4
        {"PHASERS",     PHASERS},
        {"PHASERS",     PHASERS},
-#define TORPEDO        4
+#define TORPEDO        5
         {"TORPEDO",    TORPEDO},
        {"PHOTONS",     TORPEDO},
         {"TORPEDO",    TORPEDO},
        {"PHOTONS",     TORPEDO},
-#define MOVE   5
+#define MOVE   6
        {"MOVE",        MOVE},
        {"MOVE",        MOVE},
-#define SHIELDS        6
+#define SHIELDS        7
        {"SHIELDS",     SHIELDS},
        {"SHIELDS",     SHIELDS},
-#define DOCK   7
+#define DOCK   8
        {"DOCK",        DOCK},
        {"DOCK",        DOCK},
-#define DAMAGES        8
+#define DAMAGES        9
        {"DAMAGES",     DAMAGES},
        {"DAMAGES",     DAMAGES},
-#define CHART  9
+#define CHART  10
        {"CHART",       CHART},
        {"CHART",       CHART},
-#define IMPULSE        10
+#define IMPULSE        11
        {"IMPULSE",     IMPULSE},
        {"IMPULSE",     IMPULSE},
-#define REST   11
+#define REST   12
        {"REST",        REST},
        {"REST",        REST},
-#define WARP   12
+#define WARP   13
        {"WARP",        WARP},
        {"WARP",        WARP},
-#define SCORE  13
+#define SCORE  14
        {"SCORE",       SCORE},
        {"SCORE",       SCORE},
-#ifndef SERGEEV
-#define SENSORS        14
+#define SENSORS        15
        {"SENSORS",     SENSORS},
        {"SENSORS",     SENSORS},
-#endif /* SERGEEV */
-#define ORBIT  15
+#define ORBIT  16
        {"ORBIT",       ORBIT},
 #define TRANSPORT      17
        {"TRANSPORT",   TRANSPORT},
 #define MINE   18
        {"MINE",        MINE},
        {"ORBIT",       ORBIT},
 #define TRANSPORT      17
        {"TRANSPORT",   TRANSPORT},
 #define MINE   18
        {"MINE",        MINE},
-#define CRYSTALS 19
+#define CRYSTALS       19
        {"CRYSTALS",    CRYSTALS},
 #define SHUTTLE        20
        {"SHUTTLE",     SHUTTLE},
 #define PLANETS        21
        {"PLANETS",     PLANETS},
        {"CRYSTALS",    CRYSTALS},
 #define SHUTTLE        20
        {"SHUTTLE",     SHUTTLE},
 #define PLANETS        21
        {"PLANETS",     PLANETS},
-#ifdef SERGEEV
-#define REQUEST        22
-       {"REQUEST",     REQUEST},
-#endif /* SERGEEV */
-#define REPORT 23
+#define REPORT 22
        {"REPORT",      REPORT},
        {"REPORT",      REPORT},
-#define COMPUTER       24
+#define COMPUTER       23
        {"COMPUTER",    COMPUTER},
        {"COMPUTER",    COMPUTER},
-#define COMMANDS       25
+#define COMMANDS       24
        {"COMMANDS",    COMMANDS},
        {"COMMANDS",    COMMANDS},
-#define EMEXIT 26
+#define EMEXIT 25
        {"EMEXIT",      EMEXIT},
        {"EMEXIT",      EMEXIT},
-#define PROBE  27
+#define PROBE  26
        {"PROBE",       PROBE},
        {"PROBE",       PROBE},
-#define SAVE   28
+#define SAVE   27
        {"SAVE",        SAVE},
        {"FREEZE",      SAVE},
        {"SAVE",        SAVE},
        {"FREEZE",      SAVE},
-#define ABANDON        29
+#define ABANDON        28
        {"ABANDON",     ABANDON},
        {"ABANDON",     ABANDON},
-#define DESTRUCT 30
+#define DESTRUCT       29
        {"DESTRUCT",    DESTRUCT},
        {"DESTRUCT",    DESTRUCT},
-#define DEATHRAY 31
+#define DEATHRAY       30
        {"DEATHRAY",    DEATHRAY},
        {"DEATHRAY",    DEATHRAY},
-#define DEBUGCMD       32
+#define DEBUGCMD       31
        {"DEBUG",       DEBUGCMD},
        {"DEBUG",       DEBUGCMD},
-#define MAYDAY 33
+#define MAYDAY 32
        {"MAYDAY",      MAYDAY},
        {"SOS",         MAYDAY},
        {"CALL",        MAYDAY},
        {"MAYDAY",      MAYDAY},
        {"SOS",         MAYDAY},
        {"CALL",        MAYDAY},
-#define QUIT   34
+#define QUIT   33
        {"QUIT",        QUIT},
        {"QUIT",        QUIT},
-#define HELP   35
+#define HELP   34
        {"HELP",        HELP},
 };
 
        {"HELP",        HELP},
 };
 
-#ifdef SERGEEV
-wnd wnds[6]={{1,1,80,25},{1,1,25,12},{26,2,80,12},{65,1,80,10},{1,13,80,23},{1,24,80,25}};
-short curwnd;
-#endif /* SERGEEV */
-
 #define NUMCOMMANDS    sizeof(commands)/sizeof(commands[0])
 
 #define NUMCOMMANDS    sizeof(commands)/sizeof(commands[0])
 
-static void listCommands(int x) {
-    int i;
-    prout("LEGAL COMMANDS ARE:");
-    for (i = 0; i < NUMCOMMANDS; i++) {
-       proutn("%-12s ", commands[i].name);
-       if (i % 5 == 4)
+#define MIN_CURSES_COMMAND     PHASERS         /* might change someday */
+
+static void listCommands(int usecurses) {
+    int i, k = 0;
+    proutn("LEGAL COMMANDS ARE:");
+    for (i = usecurses ? MIN_CURSES_COMMAND : 0; i < NUMCOMMANDS; i++) {
+       if (k % 5 == 0)
            skip(1);
            skip(1);
+       proutn("%-12s ", commands[i].name); 
+       k++;
     }
     skip(1);
 }
     }
     skip(1);
 }
@@ -208,15 +210,11 @@ static void helpme(void) {
        key = scan();
        while (TRUE) {
                if (key == IHEOL) {
        key = scan();
        while (TRUE) {
                if (key == IHEOL) {
-#ifdef SERGEEV
-                        setwnd(5);
-#endif /* SERGEEV */
+                        setwnd(prompt_window);
                         proutn("Help on what command? ");
                        key = scan();
                }
                         proutn("Help on what command? ");
                        key = scan();
                }
-#ifdef SERGEEV
-                setwnd(4);
-#endif /* SERGEEV */
+                setwnd(message_window);
                if (key == IHEOL) return;
                for (i = 0; i < NUMCOMMANDS; i++) {
                    if (strcasecmp(commands[i].name, citem)==0) {
                if (key == IHEOL) return;
                for (i = 0; i < NUMCOMMANDS; i++) {
                    if (strcasecmp(commands[i].name, citem)==0) {
@@ -227,7 +225,7 @@ static void helpme(void) {
                if (i != NUMCOMMANDS) break;
                skip(1);
                prout("Valid commands:");
                if (i != NUMCOMMANDS) break;
                skip(1);
                prout("Valid commands:");
-               listCommands(FALSE);
+               listCommands(usecurses);
                key = IHEOL;
                chew();
                skip(1);
                key = IHEOL;
                chew();
                skip(1);
@@ -272,39 +270,19 @@ 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(1);
-     gotoxy(1,1);
-     strcpy(line,"s");
-     srscan(1);
-     if (l!=2){
-        setwnd(2);
-        clrscr();
-        srscan(2);
-        setwnd(3);
-        clrscr();
-        strcpy(line,"l");
-        lrscan();
-        _setcursortype(_NORMALCURSOR);
-     }
-#endif /* SERGEEV */
+void enqueue(char *s) {
+    strcpy(line, s);
 }
 
 static void makemoves(void) {
        int i, hitme;
 }
 
 static void makemoves(void) {
        int i, hitme;
-#ifdef SERGEEV
         clrscr();
         clrscr();
-        setwnd(4);
-#endif /* SERGEEV */
+        setwnd(message_window);
        while (TRUE) { /* command loop */
                 drawmaps(1);
                 while (TRUE)  { /* get a command */
        while (TRUE) { /* command loop */
                 drawmaps(1);
                 while (TRUE)  { /* get a command */
@@ -313,27 +291,17 @@ static void makemoves(void) {
                        Time = 0.0;
                        i = -1;
                        chew();
                        Time = 0.0;
                        i = -1;
                        chew();
-#ifdef SERGEEV
-                        setwnd(5);
+                        setwnd(prompt_window);
                         clrscr();
                         clrscr();
-#endif /* SERGEEV */
                        proutn("COMMAND> ");
                         if (scan() == IHEOL) {
                        proutn("COMMAND> ");
                         if (scan() == IHEOL) {
-#ifdef SERGEEV
-                            _setcursortype(_NOCURSOR);
-                            setwnd(4);
-                            clrscr();
-                            chart(0);
-                            _setcursortype(_NORMALCURSOR);
-#endif /* SERGEEV */
+                           makechart();
                             continue;
                         }
                             continue;
                         }
-#ifdef SERGEEV
                         ididit=0;
                         clrscr();
                         ididit=0;
                         clrscr();
-                        setwnd(4);
+                        setwnd(message_window);
                         clrscr();
                         clrscr();
-#endif /* SERGEEV */
                        for (i=0; i < ABANDON; i++)
                            if (isit(commands[i].name)) {
                                i = commands[i].value;
                        for (i=0; i < ABANDON; i++)
                            if (isit(commands[i].name)) {
                                i = commands[i].value;
@@ -346,19 +314,22 @@ static void makemoves(void) {
                                    break;
                            }
                        if (i < NUMCOMMANDS) break;
                                    break;
                            }
                        if (i < NUMCOMMANDS) break;
-
-                       listCommands(TRUE);
+                       listCommands(usecurses);
                }
                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;
+                        case STATUS:                 // status
+                               srscan(SCAN_STATUS);
                                break;
                                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;
@@ -400,11 +371,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;
@@ -434,7 +403,7 @@ static void makemoves(void) {
                                eta();
                                break;
                        case COMMANDS:
                                eta();
                                break;
                        case COMMANDS:
-                               listCommands(TRUE);
+                               listCommands(usecurses);
                                break;
                        case EMEXIT:            // Emergency exit
                                clrscr();       // Hide screen
                                break;
                        case EMEXIT:            // Emergency exit
                                clrscr();       // Hide screen
@@ -453,10 +422,8 @@ static void makemoves(void) {
                                break;
                        case SAVE:                      // Save Game
                                freeze(FALSE);
                                break;
                        case SAVE:                      // Save Game
                                freeze(FALSE);
-#ifdef SERGEEV
                                 clrscr();
                                 clrscr();
-#endif /* SERGEEV */
-                               if (skill > 3)
+                               if (skill > SKILL_GOOD)
                                         prout("WARNING--Saved games produce no plaques!");
                                break;
                        case DEATHRAY:          // Try a desparation measure
                                         prout("WARNING--Saved games produce no plaques!");
                                break;
                        case DEATHRAY:          // Try a desparation measure
@@ -492,14 +459,14 @@ static void makemoves(void) {
                                events();
                                if (alldone) break;             // Events did us in
                        }
                                events();
                                if (alldone) break;             // Events did us in
                        }
-                       if (game.state.galaxy[quadx][quady] == 1000) { // Galaxy went Nova!
+                       if (game.state.galaxy[quadx][quady] == SUPERNOVA_PLACE) { // Galaxy went Nova!
                                atover(0);
                                continue;
                        }
                        if (hitme && justin==0) {
                                attack(2);
                                if (alldone) break;
                                atover(0);
                                continue;
                        }
                        if (hitme && justin==0) {
                                attack(2);
                                if (alldone) break;
-                               if (game.state.galaxy[quadx][quady] == 1000) {  // went NOVA! 
+                               if (game.state.galaxy[quadx][quady] == SUPERNOVA_PLACE) {       // went NOVA! 
                                        atover(0);
                                        hitme = TRUE;
                                        continue;
                                        atover(0);
                                        hitme = TRUE;
                                        continue;
@@ -513,7 +480,7 @@ static void makemoves(void) {
 
 
 int main(int argc, char **argv) {
 
 
 int main(int argc, char **argv) {
-       int i, option, usecurses = TRUE;
+    int i, option;
 
        while ((option = getopt(argc, argv, "t")) != -1) {
            switch (option) {
 
        while ((option = getopt(argc, argv, "t")) != -1) {
            switch (option) {
@@ -526,20 +493,17 @@ int main(int argc, char **argv) {
            }
        }
 
            }
        }
 
-#ifndef SERGEEV
-       iostart(usecurses);
-#else
        randomize();
        randomize();
-        textattr(7);
-        clrscr();
-        setwnd(0);
-#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) {
@@ -560,15 +524,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;
-#ifdef SERGEEV
-               setwnd(0);
-               clrscr();
-#endif /* SERGEEV */
        }
        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;
 }
@@ -634,14 +591,9 @@ double Rand(void) {
        return rand()/(1.0 + (double)RAND_MAX);
 }
 
        return rand()/(1.0 + (double)RAND_MAX);
 }
 
-void iran8(int *i, int *j) {
-       *i = Rand()*8.0 + 1.0;
-       *j = Rand()*8.0 + 1.0;
-}
-
-void iran10(int *i, int *j) {
-       *i = Rand()*10.0 + 1.0;
-       *j = Rand()*10.0 + 1.0;
+void iran(int size, int *i, int *j) {
+    *i = Rand()*(size*1.0) + 1.0;
+    *j = Rand()*(size*1.0) + 1.0;
 }
 
 void chew(void) {
 }
 
 void chew(void) {
@@ -669,15 +621,13 @@ int scan(void) {
                        chew();
                        return IHEOL;
                }
                        chew();
                        return IHEOL;
                }
-               getline(line, sizeof(line));
-#ifdef SERGEEV
+               cgetline(line, sizeof(line));
                 fflush(stdin);
                 fflush(stdin);
-                if (curwnd==5){
+                if (curwnd==prompt_window){
                    clrscr();
                    clrscr();
-                   setwnd(4);
+                   setwnd(message_window);
                    clrscr();
                 }
                    clrscr();
                 }
-#endif /* SERGEEV */
                linep = line;
        }
        // Skip leading white space
                linep = line;
        }
        // Skip leading white space