Experimental X code
[super-star-trek.git] / reports.c
index e6c9f6e5a98df0d0f72d1e649e036af4d0e46d14..f0dc134eb88d29d975e7cb753952030d2882ef97 100644 (file)
--- a/reports.c
+++ b/reports.c
@@ -6,7 +6,7 @@
 void attakreport(int curt) 
 {
     if (!curt) {
-       if (game.future[FCDBAS] < 1e30) {
+       if (game.future[FCDBAS] < FOREVER) {
            prout("Starbase in %s is currently under Commander attack.",
                  cramlc(quadrant, batx, baty));
            prout("It can hold out until Stardate %d.", 
@@ -19,7 +19,7 @@ void attakreport(int curt)
                  (int)game.future[FSCDBAS]);
        }
     } else {
-        if (game.future[FCDBAS] < 1e30)
+        if (game.future[FCDBAS] < FOREVER)
            proutn("Base in %i - %i attacked by C. Alive until %.1f", batx, baty, game.future[FCDBAS]);
         if (isatb == 1)
            proutn("Base in %i - %i attacked by S. Alive until %.1f", game.state.isx, game.state.isy, game.future[FSCDBAS]);
@@ -54,10 +54,9 @@ void report(void)
     if (skill>SKILL_GOOD && thawed && !alldone) prout("No plaque is allowed.");
     if (tourn) prout("This is tournament game %d.", tourn);
     prout("Your secret password is \"%s\"",game.passwd);
-    proutn("%d of %d Klingons have been killed",
-          game.state.killk+game.state.killc+game.state.nsckill, inkling);
-    if (game.state.killc) prout(", including %d Commander%s.", game.state.killc, game.state.killc==1?"":"s");
-    else if (game.state.killk+game.state.nsckill > 0) prout(", but no Commanders.");
+    proutn("%d of %d Klingons have been killed", KLINGKILLED, INKLINGTOT);
+    if (NKILLC) prout(", including %d Commander%s.", NKILLC, NKILLC==1?"":"s");
+    else if (NKILLK + NKILLSC > 0) prout(", but no Commanders.");
     else prout(".");
     if (skill > SKILL_FAIR) prout("The Super Commander has %sbeen destroyed.",
                                  game.state.nscrem?"not ":"");
@@ -89,7 +88,7 @@ void report(void)
        prout(".");
     }
     if ((game.damage[DRADIO] == 0.0 || condit == IHDOCKED)&&
-       game.future[FDSPROB] != 1e30) {
+       game.future[FDSPROB] != FOREVER) {
        if (isarmed) 
            proutn("An armed deep space probe is in");
        else
@@ -124,7 +123,7 @@ void lrscan(void)
            prout("LONG-RANGE SENSORS DAMAGED.");
            return;
        }
-       proutn("Starbase's long-range scan");
+       prout("Starbase's long-range scan");
     }
     else {
        prout("Long-range scan");
@@ -132,12 +131,18 @@ void lrscan(void)
     for (x = quadx-1; x <= quadx+1; x++) {
        proutn(" ");
        for (y = quady-1; y <= quady+1; y++) {
-           if (x == 0 || x > GALSIZE || y == 0 || y > GALSIZE)
+           if (!VALID_QUADRANT(x, y))
                proutn("  -1");
            else {
-               if (game.state.galaxy[x][y]<SUPERNOVA_PLACE) proutn(" %3d", game.state.galaxy[x][y]);
-               else proutn("***");
-               game.starch[x][y] = game.damage[DRADIO] > 0 ? game.state.galaxy[x][y]+SUPERNOVA_PLACE : 1;
+               if (!game.damage[DRADIO])
+                   game.state.galaxy[x][y].charted = TRUE;
+               game.state.chart[x][y].klingons = game.state.galaxy[x][y].klingons;
+               game.state.chart[x][y].starbase = game.state.galaxy[x][y].starbase;
+               game.state.chart[x][y].stars = game.state.galaxy[x][y].stars;
+               if (game.state.galaxy[x][y].supernova) 
+                   proutn(" ***");
+               else
+                   proutn(" %3d", game.state.chart[x][y].klingons*100 + game.state.chart[x][y].starbase * 10 + game.state.chart[x][y].stars);
            }
        }
        prout(" ");
@@ -149,7 +154,7 @@ void dreprt(void)
     int jdam = FALSE, i;
     chew();
 
-    for (i = 1; i <= NDEVICES; i++) {
+    for (i = 0; i < NDEVICES; i++) {
        if (game.damage[i] > 0.0) {
            if (!jdam) {
                prout("DEVICE            -REPAIR TIMES-");
@@ -165,52 +170,63 @@ void dreprt(void)
     if (!jdam) prout("All devices functional.");
 }
 
+void rechart(void)
+/* update the chart in the Enterprise's computer from galaxy data */
+{
+    int i, j;
+    lastchart = game.state.date;
+    for_quadrants(i)
+       for_quadrants(j) 
+           if (game.state.galaxy[i][j].charted) {
+               game.state.chart[i][j].klingons = game.state.galaxy[i][j].klingons;
+               game.state.chart[i][j].starbase = game.state.galaxy[i][j].starbase;
+               game.state.chart[i][j].stars = game.state.galaxy[i][j].stars;
+           }
+}
+
 void chart(int nn) 
 {
     int i,j;
-    char *cp;
     chew();
-    if (stdamtim != 1e30 && stdamtim != game.state.date && condit == IHDOCKED) {
-       proutn("Spock-  \"I revised the Star Chart from the starbase's records.\"\n\r");
-    }
-    if (nn == 0) proutn("       STAR CHART FOR THE KNOWN GALAXY\n\r");
-    if (stdamtim != 1e30) {
-       if (condit == IHDOCKED) {
-           /* We are docked, so restore chart from base information */
-           stdamtim = game.state.date;
-           for (i=1; i <= GALSIZE ; i++)
-               for (j=1; j <= GALSIZE; j++)
-                   if (game.starch[i][j] == 1) game.starch[i][j] = game.state.galaxy[i][j]+SUPERNOVA_PLACE;
-       }
-       else {
-           proutn("(Last surveillance update %d stardates ago.",
-                  (int)(game.state.date-stdamtim));
-       }
+
+    if (game.damage[DRADIO] == 0.0)
+       rechart();
+
+    if (lastchart < game.state.date && condit == IHDOCKED) {
+       prout("Spock-  \"I revised the Star Chart from the starbase's records.\"");
+       rechart();
     }
 
+    if (nn == 0) prout("       STAR CHART FOR THE KNOWN GALAXY");
+    if (game.state.date > lastchart)
+       prout("(Last surveillance update %d stardates ago).",
+             (int)(game.state.date-lastchart));
     prout("      1    2    3    4    5    6    7    8");
-    for (i = 1; i <= GALSIZE; i++) {
+    for_quadrants(i) {
        proutn("%d |", i);
-       for (j = 1; j <= GALSIZE; j++) {
+       for_quadrants(j) {
            char buf[4];
-           proutn("  ");
-           if (game.starch[i][j] == CHART_UNKNOWN)
-               strcpy(buf, ".1.");
-           else if (game.starch[i][j] == 0)
-               strcpy(buf, "...");
-           else if (game.state.galaxy[i][j]>=SUPERNOVA_PLACE)
+           if ((game.options & OPTION_SHOWME) && i == quadx && j == quady)
+               proutn("<");
+           else
+               proutn(" ");
+           if (game.state.galaxy[i][j].supernova)
                strcpy(buf, "***");
+           else if (!game.state.galaxy[i][j].charted && game.state.galaxy[i][j].starbase)
+               strcpy(buf, ".1.");
+           else if (game.state.galaxy[i][j].charted)
+               sprintf(buf, "%3d", game.state.chart[i][j].klingons*100 + game.state.chart[i][j].starbase * 10 + game.state.chart[i][j].stars);
            else
-               sprintf(buf, "%03d", game.state.galaxy[i][j]);
-           for (cp = buf; cp < buf + sizeof(buf); cp++)
-               if (*cp == '0')
-                   *cp = '.';
+               strcpy(buf, "...");
            proutn(buf);
+           if ((game.options & OPTION_SHOWME) && i == quadx && j == quady)
+               proutn(">");
+           else
+               proutn(" ");
        }
        proutn("  |");
-       if (i<GALSIZE) proutn("\n\r");
+       if (i<GALSIZE) skip(1);
     }
-    prout(""); /* flush output */
 }
 
 static void sectscan(int goodScan, int i, int j) 
@@ -227,9 +243,7 @@ static void sectscan(int goodScan, int i, int j)
            if (game.quad[i][j] != ship) 
                highvideo();
        }
-       if (game.quad[i][j] & DAMAGED) 
-           highvideo();
-       proutn("%c ",game.quad[i][j] & ~DAMAGED);
+       proutn("%c ",game.quad[i][j]);
        textcolor(DEFAULT);
     }
     else
@@ -253,8 +267,9 @@ static void status(int req)
        case IHDOCKED: cp = "DOCKED"; break;
        case IHDEAD: cp="DEAD"; break;
        }
-       for (t=0;t<=NDEVICES;t++)
-           if (game.damage[t]>0) dam++;
+       for (t=0;t<NDEVICES;t++)
+           if (game.damage[t]>0) 
+               dam++;
        proutn("Condition     %s, %i DAMAGES", cp, dam);
        break;
     case 3:
@@ -277,7 +292,7 @@ static void status(int req)
        break;
     case 6:
        proutn("Energy        %.2f", energy);
-       if (icrystl)    /* ESR */
+       if (icrystl && (game.options & OPTION_SHOWME))  /* ESR */
            proutn(" (have crystals)");
        break;
     case 7:
@@ -295,28 +310,18 @@ static void status(int req)
               (int)((100.0*shield)/inshld + 0.5), shield);
        break;
     case 9:
-       proutn("Klingons Left %d", game.state.remkl);
+       proutn("Klingons Left %d", KLINGREM);
        break;
     case 10:
        attakreport(1);
        break;
-       /*
-        * Note: attakreport() can in some cases produce two lines of
-        * output.  If that happens, and QUADSIZE is the normal 10, items
-        * 11 and up will be printed past the bottom of the quadrant display.
-        * Under the curses display logic they will get lost because they're
-        * written outside the report window.
-        */
-    case 11:   /* ESR */
-       proutn("Bases Left    %d", game.state.rembase);
-       break;
     }
 }
                
 int srscan(int l) 
 {
     static char requests[][3] =
-       {"","da","co","po","ls","wa","en","to","sh","kl","ti", "ba"};
+       {"","da","co","po","ls","wa","en","to","sh","kl","ti"};
     int leftside=TRUE, rightside=TRUE, i, j, jj, req=0, nn=FALSE;
     int goodScan=TRUE;
     switch (l) {
@@ -330,13 +335,18 @@ int srscan(int l)
            else
                prout("  [Using Base's sensors]");
        }
-       else proutn("     Short-range scan\n\r");
-       if (goodScan) game.starch[quadx][quady] = game.damage[DRADIO]>0.0 ? game.state.galaxy[quadx][quady]+SUPERNOVA_PLACE:1;
+       else prout("     Short-range scan");
+       if (goodScan && !game.damage[DRADIO]) { 
+           game.state.chart[quadx][quady].klingons = game.state.galaxy[quadx][quady].klingons;
+           game.state.chart[quadx][quady].starbase = game.state.galaxy[quadx][quady].starbase;
+           game.state.chart[quadx][quady].stars = game.state.galaxy[quadx][quady].stars;
+           game.state.galaxy[quadx][quady].charted = TRUE;
+       }
        scan();
        if (isit("chart")) nn = TRUE;
        if (isit("no")) rightside = FALSE;
        chew();
-       proutn("    1 2 3 4 5 6 7 8 9 10\n\r");
+       prout("    1 2 3 4 5 6 7 8 9 10");
        break;
     case SCAN_REQUEST:
        while (scan() == IHEOL)
@@ -346,9 +356,9 @@ int srscan(int l)
            if (strncmp(citem,requests[req],min(2,strlen(citem)))==0)
                break;
        if (req > sizeof(requests)/sizeof(requests[0])) {
-           prout("UNRECOGNIZED REQUEST. Legal requests are:\n"
-                 "  date, condition, position, lsupport, warpfactor,\n"
-                 "  energy, torpedoes, shields, klingons, time, bases.");
+           prout("UNRECOGNIZED REQUEST. Legal requests are:");
+           prout("  date, condition, position, lsupport, warpfactor,");
+           prout("  energy, torpedoes, shields, klingons, time, bases.");
            return FALSE;
        }
        // no break
@@ -366,13 +376,13 @@ int srscan(int l)
        jj = (req!=0 ? req : i);
        if (leftside && i <= QUADSIZE) {
            proutn("%2d  ", i);
-           for (j = 1; j <= QUADSIZE; j++) {
+           for_sectors(j) {
                sectscan(goodScan, i, j);
            }
        }
        if (rightside)
            status(jj);
-       if (i<sizeof(requests)/sizeof(requests[0])) proutn("\n\r");
+       if (i<sizeof(requests)/sizeof(requests[0])) skip(1);
        if (req!=0) return(goodScan);
     }
     prout("");
@@ -421,8 +431,7 @@ void eta(void)
        else iy2=QUADSIZE;
     }
 
-    if (ix1 > GALSIZE || ix1 < 1 || iy1 > GALSIZE || iy1 < 1 ||
-       ix2 > QUADSIZE || ix2 < 1 || iy2 > QUADSIZE || iy2 < 1) {
+    if (!VALID_QUADRANT(ix1, iy1) || !VALID_SECTOR(ix2, iy2)) {
        huh();
        return;
     }