More boolean-chasing and coord applications.
[super-star-trek.git] / src / sst.c
index 7fbbfc2ef558af029e37e827537410314a35ef4f..ba9bef7418d3175854d8146f0bd22d59942a251e 100644 (file)
--- a/src/sst.c
+++ b/src/sst.c
@@ -162,6 +162,12 @@ for a lot of magic numbers and refactored the heck out of it.
       type is "plain" or "almy".)
 
    6. User input is now logged so we can do regression testing.
       type is "plain" or "almy".)
 
    6. User input is now logged so we can do regression testing.
+
+   7. More BSD-Trek features: You can now lose if your entire crew
+      dies in battle.  When abandoning ship in a game with inhabited
+      worlds enabled, they must have one in the quadrant to beam down
+      to; otherwise they die in space and this counts heavily against
+      your score.  Docking at a starbase replenishes your crew.
 */
 
 /* the input queue */
 */
 
 /* the input queue */
@@ -169,7 +175,7 @@ static char line[128], *linep = line;
 
 struct game game;
 coord thing;
 
 struct game game;
 coord thing;
-int iqhere, iqengry;
+bool iqhere, iqengry;
 int iscore, iskill;    // Common PLAQ
 double aaitem;
 double perdate;
 int iscore, iskill;    // Common PLAQ
 double aaitem;
 double perdate;
@@ -284,7 +290,9 @@ commands[] = {
 #define NUMCOMMANDS    sizeof(commands)/sizeof(commands[0])
 #define ACCEPT(i)      (!commands[i].option || (commands[i].option & game.options))
 
 #define NUMCOMMANDS    sizeof(commands)/sizeof(commands[0])
 #define ACCEPT(i)      (!commands[i].option || (commands[i].option & game.options))
 
-static void listCommands(void) {
+static void listCommands(void) 
+/* generate a list of legal commands */
+{
     int i, k = 0;
     proutn("LEGAL COMMANDS ARE:");
     for (i = 0; i < NUMCOMMANDS; i++) {
     int i, k = 0;
     proutn("LEGAL COMMANDS ARE:");
     for (i = 0; i < NUMCOMMANDS; i++) {
@@ -298,7 +306,8 @@ static void listCommands(void) {
     skip(1);
 }
 
     skip(1);
 }
 
-static void helpme(void) 
+static void helpme(void)
+/* browse on-line help */
 {
     int i, j;
     char cmdbuf[32], *cp;
 {
     int i, j;
     char cmdbuf[32], *cp;
@@ -377,12 +386,14 @@ static void helpme(void)
     fclose(fp);
 }
 
     fclose(fp);
 }
 
-void enqueue(char *s) 
+void enqueue(char *s)
+/* enqueue input for the command parser */
 {
     strcpy(line, s);
 }
 
 {
     strcpy(line, s);
 }
 
-static void makemoves(void) 
+static void makemoves(void)
+/* command-interpretation loop */
 {
     int key, i, v = 0;
     bool hitme;
 {
     int key, i, v = 0;
     bool hitme;
@@ -392,7 +403,7 @@ static void makemoves(void)
        drawmaps(1);
        for(;;)  { /* get a command */
            hitme = false;
        drawmaps(1);
        for(;;)  { /* get a command */
            hitme = false;
-           game.justin = 0;
+           game.justin = false;
            game.optime = 0.0;
            i = -1;
            chew();
            game.optime = 0.0;
            i = -1;
            chew();
@@ -403,7 +414,7 @@ static void makemoves(void)
                makechart();
                continue;
            }
                makechart();
                continue;
            }
-           game.ididit=0;
+           game.ididit = false;
            clrscr();
            setwnd(message_window);
            clrscr();
            clrscr();
            setwnd(message_window);
            clrscr();
@@ -463,7 +474,7 @@ static void makemoves(void)
            dreprt();
            break;
        case CHART:                     // chart
            dreprt();
            break;
        case CHART:                     // chart
-           chart(0);
+           chart(false);
            break;
        case IMPULSE:                   // impulse
            impuls();
            break;
        case IMPULSE:                   // impulse
            impuls();
@@ -525,7 +536,7 @@ static void makemoves(void)
            abandn();
            break;
        case DESTRUCT:                  // Self Destruct
            abandn();
            break;
        case DESTRUCT:                  // Self Destruct
-           dstrct();
+           selfdestruct();
            break;
        case SAVE:                      // Save Game
            freeze(false);
            break;
        case SAVE:                      // Save Game
            freeze(false);
@@ -545,7 +556,7 @@ static void makemoves(void)
            if (game.ididit) hitme = true;
            break;
        case QUIT:
            if (game.ididit) hitme = true;
            break;
        case QUIT:
-           game.alldone = 1;           // quit the game
+           game.alldone = true;                // quit the game
            break;
        case HELP:
            helpme();                   // get help
            break;
        case HELP:
            helpme();                   // get help
@@ -564,14 +575,14 @@ static void makemoves(void)
                if (game.alldone) break;        // Events did us in
            }
            if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova) { // Galaxy went Nova!
                if (game.alldone) break;        // Events did us in
            }
            if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova) { // Galaxy went Nova!
-               atover(0);
+               atover(false);
                continue;
            }
                continue;
            }
-           if (hitme && game.justin==0) {
+           if (hitme && !game.justin) {
                attack(2);
                if (game.alldone) break;
                if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova) {    // went NOVA! 
                attack(2);
                if (game.alldone) break;
                if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova) {    // went NOVA! 
-                   atover(0);
+                   atover(false);
                    hitme = true;
                    continue;
                }
                    hitme = true;
                    continue;
                }
@@ -641,7 +652,7 @@ int main(int argc, char **argv)
        setup(line[0] == '\0');
        if (game.alldone) {
            score();
        setup(line[0] == '\0');
        if (game.alldone) {
            score();
-           game.alldone = 0;
+           game.alldone = false;
        }
        else makemoves();
        skip(1);
        }
        else makemoves();
        skip(1);
@@ -650,7 +661,7 @@ int main(int argc, char **argv)
 
        if (game.tourn && game.alldone) {
            proutn("Do you want your score recorded?");
 
        if (game.tourn && game.alldone) {
            proutn("Do you want your score recorded?");
-           if (ja()) {
+           if (ja() == true) {
                chew2();
                freeze(false);
            }
                chew2();
                freeze(false);
            }
@@ -665,6 +676,7 @@ int main(int argc, char **argv)
 
 
 void cramen(int i) 
 
 
 void cramen(int i) 
+/* print the name of an enemy */
 {
     /* return an enemy */
     char *s;
 {
     /* return an enemy */
     char *s;
@@ -687,6 +699,7 @@ void cramen(int i)
 }
 
 char *cramlc(enum loctype key, coord w)
 }
 
 char *cramlc(enum loctype key, coord w)
+/* name a location */
 {
     static char buf[32];
     buf[0] = '\0';
 {
     static char buf[32];
     buf[0] = '\0';
@@ -696,15 +709,17 @@ char *cramlc(enum loctype key, coord w)
     return buf;
 }
 
     return buf;
 }
 
-void crmena(int i, int enemy, int key, coord w) 
+void crmena(bool stars, int enemy, enum loctype key, coord w) 
+/* print an enemy and his location */
 {
 {
-    if (i == 1) proutn("***");
+    if (stars) proutn("***");
     cramen(enemy);
     proutn(" at ");
     proutn(cramlc(key, w));
 }
 
     cramen(enemy);
     proutn(" at ");
     proutn(cramlc(key, w));
 }
 
-void crmshp(void) 
+void crmshp(void)
+/* print our ship name */
 {
     char *s;
     switch (game.ship) {
 {
     char *s;
     switch (game.ship) {
@@ -715,7 +730,8 @@ void crmshp(void)
     proutn(s);
 }
 
     proutn(s);
 }
 
-void stars(void) 
+void stars(void)
+/* print a line of stars */
 {
     prouts("******************************************************");
     skip(1);
 {
     prouts("******************************************************");
     skip(1);
@@ -731,10 +747,13 @@ double Rand(void)
     return rand()/(1.0 + (double)RAND_MAX);
 }
 
     return rand()/(1.0 + (double)RAND_MAX);
 }
 
-void iran(int size, int *i, int *j) 
+coord iran(int size)
+/* choose a random location */ 
 {
 {
-    *i = Rand()*(size*1.0) + 1.0;
-    *j = Rand()*(size*1.0) + 1.0;
+    coord w;
+    w.x = Rand()*(size*1.0) + 1.0;
+    w.y = Rand()*(size*1.0) + 1.0;
+    return w;
 }
 
 void chew(void)
 }
 
 void chew(void)
@@ -805,7 +824,8 @@ int scan(void)
     return IHALPHA;
 }
 
     return IHALPHA;
 }
 
-bool ja(void) 
+bool ja(void)
+/* yes-or-no confirmation */
 {
     chew();
     for(;;) {
 {
     chew();
     for(;;) {
@@ -817,7 +837,8 @@ bool ja(void)
     }
 }
 
     }
 }
 
-void huh(void) 
+void huh(void)
+/* complain about unparseable input */
 {
     chew();
     skip(1);
 {
     chew();
     skip(1);
@@ -825,38 +846,36 @@ void huh(void)
 }
 
 int isit(char *s) 
 }
 
 int isit(char *s) 
+/* compares s to citem and returns true if it matches to the length of s */
 {
 {
-    /* New function -- compares s to scanned citem and returns true if it
-       matches to the length of s */
-
     return strncasecmp(s, citem, max(1, strlen(citem))) == 0;
     return strncasecmp(s, citem, max(1, strlen(citem))) == 0;
-
 }
 
 }
 
-void debugme(void) 
+void debugme(void)
+/* access to the internals for debugging */
 {
     proutn("Reset levels? ");
 {
     proutn("Reset levels? ");
-    if (ja() != 0) {
+    if (ja() == true) {
        if (game.energy < game.inenrg) game.energy = game.inenrg;
        game.shield = game.inshld;
        game.torps = game.intorps;
        game.lsupres = game.inlsr;
     }
     proutn("Reset damage? ");
        if (game.energy < game.inenrg) game.energy = game.inenrg;
        game.shield = game.inshld;
        game.torps = game.intorps;
        game.lsupres = game.inlsr;
     }
     proutn("Reset damage? ");
-    if (ja() != 0) {
+    if (ja() == true) {
        int i;
        for (i=0; i < NDEVICES; i++) 
            if (game.damage[i] > 0.0) 
                game.damage[i] = 0.0;
     }
     proutn("Toggle debug flag? ");
        int i;
        for (i=0; i < NDEVICES; i++) 
            if (game.damage[i] > 0.0) 
                game.damage[i] = 0.0;
     }
     proutn("Toggle debug flag? ");
-    if (ja() != 0) {
+    if (ja() == true) {
        idebug = !idebug;
        if (idebug) prout("Debug output ON");
        else prout("Debug output OFF");
     }
     proutn("Cause selective damage? ");
        idebug = !idebug;
        if (idebug) prout("Debug output ON");
        else prout("Debug output OFF");
     }
     proutn("Cause selective damage? ");
-    if (ja() != 0) {
+    if (ja() == true) {
        int i, key;
        for (i=0; i < NDEVICES; i++) {
            proutn("Kill ");
        int i, key;
        for (i=0; i < NDEVICES; i++) {
            proutn("Kill ");
@@ -870,7 +889,7 @@ void debugme(void)
        }
     }
     proutn("Examine/change events? ");
        }
     }
     proutn("Examine/change events? ");
-    if (ja() != 0) {
+    if (ja() == true) {
        event *ev;
        coord w;
        int i;
        event *ev;
        coord w;
        int i;
@@ -909,28 +928,31 @@ void debugme(void)
                    chew();
                    proutn("In quadrant- ");
                    key = scan();
                    chew();
                    proutn("In quadrant- ");
                    key = scan();
-                   if (key != IHREAL) {
-                       prout("Event %d canceled, no y coordinate.", i);
-                       unschedule(i);
-                       continue;
-                   }
-                   w.y = (int)aaitem;
-                   key = scan();
-                   if (key != IHREAL) {
-                       prout("Event %d canceled, no x coordinate.", i);
-                       unschedule(i);
-                       continue;
+                   /* IHEOL says to leave coordinates as they are */
+                   if (key != IHEOL) {
+                       if (key != IHREAL) {
+                           prout("Event %d canceled, no x coordinate.", i);
+                           unschedule(i);
+                           continue;
+                       }
+                       w.x = (int)aaitem;
+                       key = scan();
+                       if (key != IHREAL) {
+                           prout("Event %d canceled, no y coordinate.", i);
+                           unschedule(i);
+                           continue;
+                       }
+                       w.y = (int)aaitem;
+                       ev->quadrant = w;
                    }
                    }
-                   w.x = (int)aaitem;
-                   ev->quadrant = w;
                }
            }
        }
        chew();
     }
     proutn("Induce supernova here? ");
                }
            }
        }
        chew();
     }
     proutn("Induce supernova here? ");
-    if (ja()) {
+    if (ja() == true) {
        game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova = true;
        game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova = true;
-       atover(1);
+       atover(true);
     }
 }
     }
 }