Clean up nasty FORTRAN-style if statements.
[super-star-trek.git] / src / reports.c
index 39fcf36cbed4df92796eb802f3db2b304390536d..93a525d8abc0bbb1d706b6bb7fc051955e2965eb 100644 (file)
@@ -13,19 +13,21 @@ void attakreport(bool curt)
            prout(_("It can hold out until Stardate %d."),
                  (int)scheduled(FCDBAS));
        }
-       if (game.isatb == 1) {
+       else if (game.isatb == 1) {
            prout(_("Starbase in %s is under Super-commander attack."),
                  cramlc(quadrant, game.state.kscmdr));
            prout(_("It can hold out until Stardate %d."),
                  (int)scheduled(FSCDBAS));
+       } else {
+           prout(_("No Starbase is currently under attack."));
        }
     } else {
         if (is_scheduled(FCDBAS))
            proutn(_("Base in %i - %i attacked by C. Alive until %.1f"), game.battle.x, game.battle.y, scheduled(FCDBAS));
         if (game.isatb)
            proutn(_("Base in %i - %i attacked by S. Alive until %.1f"), game.state.kscmdr.x, game.state.kscmdr.y, scheduled(FSCDBAS));
+       clreol();
     }
-    clreol();
 }
        
 
@@ -35,66 +37,79 @@ void report(void)
     char *s1,*s2,*s3;
 
     chew();
-    s1 = (game.thawed?"thawed ":"");
+    s1 = (game.thawed?_("thawed "):"");
     switch (game.length) {
-    case 1: s2="short"; break;
-    case 2: s2="medium"; break;
-    case 4: s2="long"; break;
-    default: s2="unknown length"; break;
+    case 1: s2=_("short"); break;
+    case 2: s2=_("medium"); break;
+    case 4: s2=_("long"); break;
+    default: s2=_("unknown length"); break;
     }
     switch (game.skill) {
-    case SKILL_NOVICE: s3="novice"; break;
-    case SKILL_FAIR: s3="fair"; break;
-    case SKILL_GOOD: s3="good"; break;
-    case SKILL_EXPERT: s3="expert"; break;
-    case SKILL_EMERITUS: s3="emeritus"; break;
-    default: s3="skilled"; break;
+    case SKILL_NOVICE: s3=_("novice"); break;
+    case SKILL_FAIR: s3=_("fair"); break;
+    case SKILL_GOOD: s3=_("good"); break;
+    case SKILL_EXPERT: s3=_("expert"); break;
+    case SKILL_EMERITUS: s3=_("emeritus"); break;
+    default: s3=_("skilled"); break;
     }
-    prout("");
-    prout(_("You %s playing a %s%s %s game."),
-         game.alldone? _("were") : _("are now"), s1, s2, s3);
-    if (game.skill>SKILL_GOOD && game.thawed && !game.alldone) prout(_("No plaque is allowed."));
-    if (game.tourn) prout(_("This is tournament game %d."), game.tourn);
+    skip(1);
+    prout(_("You %s a %s%s %s game."),
+         game.alldone? _("were playing") : _("are playing"), s1, s2, s3);
+    if (game.skill>SKILL_GOOD && game.thawed && !game.alldone)
+       prout(_("No plaque is allowed."));
+    if (game.tourn)
+       prout(_("This is tournament game %d."), game.tourn);
     prout(_("Your secret password is \"%s\""),game.passwd);
     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 (game.skill > SKILL_FAIR) prout(_("The Super Commander has %sbeen destroyed."),
-                                 game.state.nscrem?_("not "):"");
+    if (NKILLC)
+       prout(_(", including %d Commander%s."), NKILLC, NKILLC==1?"":_("s"));
+    else if (NKILLK + NKILLSC > 0)
+       prout(_(", but no Commanders."));
+    else
+       prout(".");
+    if (game.skill > SKILL_FAIR)
+       prout(_("The Super Commander has %sbeen destroyed."),
+             game.state.nscrem?_("not "):"");
     if (game.state.rembase != game.inbase) {
        proutn(_("There "));
-       if (game.inbase-game.state.rembase==1) proutn(_("has been 1 base"));
+       if (game.inbase-game.state.rembase==1)
+           proutn(_("has been 1 base"));
        else {
            proutn(_("have been %d bases"), game.inbase-game.state.rembase);
        }
        prout(_(" destroyed, %d remaining."), game.state.rembase);
     }
-    else prout(_("There are %d bases."), game.inbase);
+    else
+       prout(_("There are %d bases."), game.inbase);
     if (!damaged(DRADIO) || game.condition == docked || game.iseenit) {
        /* Don't report this if not seen and
           either the radio is dead or not at base! */
        attakreport(false);
        game.iseenit = true;
     }
-    if (game.casual) prout(_("%d casualt%s suffered so far."),
-                     game.casual, game.casual==1? "y" : "ies");
-    if (game.nhelp) prout(_("There were %d call%s for help."),
-                    game.nhelp, game.nhelp==1 ? "" : _("s"));
+    if (game.casual) 
+       prout(_("%d casualt%s suffered so far."),
+             game.casual, game.casual==1? "y" : "ies");
+    if (game.nhelp)
+       prout(_("There were %d call%s for help."),
+             game.nhelp, game.nhelp==1 ? "" : _("s"));
     if (game.ship == IHE) {
        proutn(_("You have "));
-       if (game.nprobes) proutn("%d", game.nprobes);
-       else proutn(_("no"));
+       if (game.nprobes)
+           proutn("%d", game.nprobes);
+       else
+           proutn(_("no"));
        proutn(_(" deep space probe"));
-       if (game.nprobes!=1) proutn(_("s"));
+       if (game.nprobes!=1)
+           proutn(_("s"));
        prout(".");
     }
     if ((!damaged(DRADIO) || game.condition == docked)
                && is_scheduled(FDSPROB)) {
        if (game.isarmed) 
-           proutn(_("An armed deep space probe is in"));
+           proutn(_("An armed deep space probe is in "));
        else
-           proutn(_("A deep space probe is in"));
+           proutn(_("A deep space probe is in "));
        proutn(cramlc(quadrant, game.probec));
        prout(".");
     }
@@ -119,7 +134,6 @@ void lrscan(void)
 /* long-range sensor scan */
 {
     int x, y;
-    chew();
     if (damaged(DLRSENS)) {
        /* Now allow base's sensors if docked */
        if (game.condition != docked) {
@@ -162,17 +176,18 @@ void dreprt(void)
     for (i = 0; i < NDEVICES; i++) {
        if (damaged(i)) {
            if (!jdam) {
-               prout(_("DEVICE            -REPAIR TIMES-"));
-               prout(_("                IN FLIGHT   DOCKED"));
+               prout(_("\tDEVICE\t\t\t-REPAIR TIMES-"));
+               prout(_("\t\t\tIN FLIGHT\t\tDOCKED"));
                jdam = true;
            }
-           prout("  %16s %8.2f  %8.2f", 
+           prout("  %-26s\t%8.2f\t\t%8.2f", 
                  device[i],
                  game.damage[i]+0.05,
                  game.docfac*game.damage[i]+0.005);
        }
     }
-    if (!jdam) prout(_("All devices functional."));
+    if (!jdam)
+       prout(_("All devices functional."));
 }
 
 void rechart(void)
@@ -189,7 +204,7 @@ void rechart(void)
            }
 }
 
-void chart(bool title)
+void chart(void)
 /* display the star chart */ 
 {
     int i,j;
@@ -203,7 +218,7 @@ void chart(bool title)
        rechart();
     }
 
-    if (!title) prout(_("       STAR CHART FOR THE KNOWN GALAXY"));
+    prout(_("       STAR CHART FOR THE KNOWN GALAXY"));
     if (game.state.date > game.lastchart)
        prout(_("(Last surveillance update %d stardates ago)."),
              (int)(game.state.date-game.lastchart));
@@ -231,9 +246,9 @@ void chart(bool title)
                proutn(" ");
        }
        proutn("  |");
-       if (i<GALSIZE) skip(1);
+       if (i<GALSIZE)
+           skip(1);
     }
-    prout("");
 }
 
 static void sectscan(int goodScan, int i, int j) 
@@ -258,157 +273,150 @@ static void sectscan(int goodScan, int i, int j)
        proutn("- ");
 }
 
-static void status(int req)
+void status(int req)
 /* print status report lines */
 {
-    char *cp = NULL;
+#define RQ(n, a) if (!req || req == n) do { a } while(0)
+    char *cp = NULL, s[256];
     int t, dam = 0;
-    switch (req) {
-    case 1:
-       proutn(_("Stardate      %.1f, Time Left %.2f"), game.state.date, game.state.remtime);
-       break;
-    case 2:
-       if (game.condition != docked) newcnd();
+
+    RQ(1,
+       prstat(_("Stardate"), _("%.1f, Time Left %.2f"), game.state.date, game.state.remtime);
+    );
+
+    RQ(2,
+       if (game.condition != docked)
+           newcnd();
        switch (game.condition) {
-       case red: cp = "RED"; break;
-       case green: cp = "GREEN"; break;
-       case yellow: cp = "YELLOW"; break;
-       case docked: cp = "DOCKED"; break;
-       case dead: cp="DEAD"; break;
+           case red: cp = _("RED"); break;
+           case green: cp = _("GREEN"); break;
+           case yellow: cp = _("YELLOW"); break;
+           case docked: cp = _("DOCKED"); break;
+           case dead: cp = _("DEAD"); break;
        }
        for (t=0;t<NDEVICES;t++)
            if (game.damage[t]>0) 
                dam++;
-       proutn(_("Condition     %s, %i DAMAGES"), cp, dam);
-       break;
-    case 3:
-       proutn(_("Position      %d - %d , %d - %d"),
-              game.quadrant.x, game.quadrant.y, game.sector.x, game.sector.y);
-       break;
-    case 4:
-       proutn(_("Life Support  "));
+       prstat(_("Condition"), _("%s, %i DAMAGES"), cp, dam);
+    );
+
+    RQ(3,
+       prstat(_("Position"), "%d - %d , %d - %d",
+             game.quadrant.x, game.quadrant.y, game.sector.x, game.sector.y);
+    );
+
+    RQ(4,
        if (damaged(DLIFSUP)) {
            if (game.condition == docked)
-               proutn(_("DAMAGED, Base provides"));
+               sprintf(s, _("DAMAGED, Base provides"));
            else
-               proutn(_("DAMAGED, reserves=%4.2f"), game.lsupres);
+               sprintf(s, _("DAMAGED, reserves=%4.2f"), game.lsupres);
        }
        else
-           proutn(_("ACTIVE"));
-       break;
-    case 5:
-       proutn(_("Warp Factor   %.1f"), game.warpfac);
-       break;
-    case 6:
-       proutn(_("Energy        %.2f"), game.energy);
-       if (game.icrystl && (game.options & OPTION_SHOWME))     /* ESR */
-           proutn(_(" (have crystals)"));
-       break;
-    case 7:
-       proutn(_("Torpedoes     %d"), game.torps);
-       break;
-    case 8:
-       proutn(_("Shields       "));
+           sprintf(s, _("ACTIVE"));
+       prstat(_("Life Support"), s);
+    );
+
+    RQ(5,
+       prstat(_("Warp Factor"), "%.1f", game.warpfac);
+    );
+
+    RQ(6,
+       prstat(_("Energy"), "%.2f%s", game.energy,
+               (game.icrystl && (game.options & OPTION_SHOWME)) ? /* ESR */
+               _(" (have crystals)") : "");
+    );
+
+    RQ(7,
+       prstat(_("Torpedoes"), "%d", game.torps);
+    );
+
+    RQ(8,
        if (damaged(DSHIELD))
-           proutn(_("DAMAGED,"));
+           strcpy(s, _("DAMAGED,"));
        else if (game.shldup)
-           proutn(_("UP,"));
+           strcpy(s, _("UP,"));
        else
-           proutn(_("DOWN,"));
-       proutn(_(" %d%% %.1f units"),
+           strcpy(s, _("DOWN,"));
+       sprintf(s + strlen(s), _(" %d%% %.1f units"),
               (int)((100.0*game.shield)/game.inshld + 0.5), game.shield);
-       break;
-    case 9:
-       proutn(_("Klingons Left %d"), KLINGREM);
-       break;
-    case 10:
+       prstat(_("Shields"), s);
+    );
+
+    RQ(9,
+        prstat(_("Klingons Left"), "%d", KLINGREM);
+    );
+
+    RQ(10,
        if (game.options & OPTION_WORLDS) {
            int plnet = game.state.galaxy[game.quadrant.x][game.quadrant.y].planet;
            if (plnet != NOPLANET && game.state.plnets[plnet].inhabited != UNINHABITED)
-               proutn(_("Major system  %s"), systemname(plnet));
+               prstat(_("Major system"), "%s", systnames[plnet]);
            else
-               proutn(_("Sector is uninhabited"));
+               prout(_("Sector is uninhabited"));
        }
+    );
+
+    RQ(11,
+       attakreport(!req);
+    );
+
+#undef RQ
+}
+
+void request(void)
+{
+    int req;
+    static char requests[][3] =
+       {"da","co","po","ls","wa","en","to","sh","kl","sy", "ti"};
 
-       break;
-    case 11:
-       attakreport(true);
-       break;
+    while (scan() == IHEOL)
+       proutn(_("Information desired? "));
+    chew();
+    for (req = 0; req < ARRAY_SIZE(requests); req++)
+       if (strncmp(citem, requests[req], min(2,strlen(citem)))==0)
+           break;
+    if (req >= ARRAY_SIZE(requests)) {
+       prout(_("UNRECOGNIZED REQUEST. Legal requests are:"));
+       prout(("  date, condition, position, lsupport, warpfactor,"));
+       prout(("  energy, torpedoes, shields, klingons, system, time."));
+       return;
     }
+    status(req + 1);
 }
                
-void srscan(scantype type)
+void srscan(void)
 /* short-range scan */
 {
-    /* the "sy" request is undocumented */
-    static char requests[][3] =
-       {"","da","co","po","ls","wa","en","to","sh","kl","sy", "ti"};
-    
-    int i, j, jj, req=0;
-    int goodScan=true, leftside=true, rightside=true, title=false; 
-    switch (type) {
-    case SCAN_FULL: // SRSCAN
-       if (damaged(DSRSENS)) {
-           /* Allow base's sensors if docked */
-           if (game.condition != docked) {
-               prout(_("   S.R. SENSORS DAMAGED!"));
-               goodScan=false;
-           }
-           else
-               prout(_("  [Using Base's sensors]"));
-       }
-       else prout(_("     Short-range scan"));
-       if (goodScan && !damaged(DRADIO)) { 
-           game.state.chart[game.quadrant.x][game.quadrant.y].klingons = game.state.galaxy[game.quadrant.x][game.quadrant.y].klingons;
-           game.state.chart[game.quadrant.x][game.quadrant.y].starbase = game.state.galaxy[game.quadrant.x][game.quadrant.y].starbase;
-           game.state.chart[game.quadrant.x][game.quadrant.y].stars = game.state.galaxy[game.quadrant.x][game.quadrant.y].stars;
-           game.state.galaxy[game.quadrant.x][game.quadrant.y].charted = true;
-       }
-       scan();
-       if (isit("chart")) title = true;
-       if (isit("no")) rightside = false;
-       chew();
-       prout("    1 2 3 4 5 6 7 8 9 10");
-       break;
-    case SCAN_REQUEST:
-       while (scan() == IHEOL)
-           proutn(_("Information desired? "));
-       chew();
-       for (req = 1; req <= sizeof(requests)/sizeof(requests[0]); req++)
-           if (strncmp(citem,requests[req],min(2,strlen(citem)))==0)
-               break;
-       if (req > sizeof(requests)/sizeof(requests[0])) {
-           prout(_("UNRECOGNIZED REQUEST. Legal requests are:"));
-           prout(_("  date, condition, position, lsupport, warpfactor,"));
-           prout(_("  energy, torpedoes, shields, klingons, time, system, bases."));
-           return;
+    int i, j;
+    int goodScan=true;
+    if (damaged(DSRSENS)) {
+       /* Allow base's sensors if docked */
+       if (game.condition != docked) {
+           prout(_("   S.R. SENSORS DAMAGED!"));
+           goodScan=false;
        }
-       // no break
-    case SCAN_STATUS: // STATUS
-       chew();
-       leftside = false;
-       skip(1);
-       // no break
-    case SCAN_NO_LEFTSIDE: // REQUEST
-       leftside=false;
-       break;
+       else
+           prout(_("  [Using Base's sensors]"));
     }
-    if (game.condition != docked) newcnd();
-    for (i = 1; i <= max(QUADSIZE, sizeof(requests)/sizeof(requests[0])); i++) {
-       jj = (req!=0 ? req : i);
-       if (leftside && i <= QUADSIZE) {
-           proutn("%2d  ", i);
-           for_sectors(j) {
-               sectscan(goodScan, i, j);
-           }
+    else
+       prout(_("     Short-range scan"));
+    if (goodScan && !damaged(DRADIO)) { 
+       game.state.chart[game.quadrant.x][game.quadrant.y].klingons = game.state.galaxy[game.quadrant.x][game.quadrant.y].klingons;
+       game.state.chart[game.quadrant.x][game.quadrant.y].starbase = game.state.galaxy[game.quadrant.x][game.quadrant.y].starbase;
+       game.state.chart[game.quadrant.x][game.quadrant.y].stars = game.state.galaxy[game.quadrant.x][game.quadrant.y].stars;
+       game.state.galaxy[game.quadrant.x][game.quadrant.y].charted = true;
+    }
+    prout("    1 2 3 4 5 6 7 8 9 10");
+    if (game.condition != docked)
+       newcnd();
+    for (i = 1; i <= QUADSIZE; i++) {
+       proutn("%2d  ", i);
+       for_sectors(j) {
+           sectscan(goodScan, i, j);
        }
-       if (rightside)
-           status(jj);
-       if (i<sizeof(requests)/sizeof(requests[0])) skip(1);
-       if (req!=0) return;
+       skip(1);
     }
-    prout("");
-    if (title) chart(true);
 }
                        
                        
@@ -447,10 +455,14 @@ void eta(void)
        w2.x = aaitem + 0.5;
     }
     else {
-       if (game.quadrant.y>w1.x) w2.x = 1;
-       else w2.x=QUADSIZE;
-       if (game.quadrant.x>w1.y) w2.y = 1;
-       else w2.y=QUADSIZE;
+       if (game.quadrant.y>w1.x)
+           w2.x = 1;
+       else
+           w2.x=QUADSIZE;
+       if (game.quadrant.x>w1.y)
+           w2.y = 1;
+       else
+           w2.y=QUADSIZE;
     }
 
     if (!VALID_QUADRANT(w1.x, w1.y) || !VALID_SECTOR(w2.x, w2.y)) {
@@ -461,7 +473,8 @@ void eta(void)
                square(w1.x-game.quadrant.x+0.1*(w2.x-game.sector.x)));
     wfl = false;
 
-    if (prompt) prout(_("Answer \"no\" if you don't know the value:"));
+    if (prompt)
+       prout(_("Answer \"no\" if you don't know the value:"));
     for (;;) {
        chew();
        proutn(_("Time or arrival date? "));
@@ -474,7 +487,8 @@ void eta(void)
                chew();
                return;
            }
-           if (twarp < 1.0) twarp = 1.0;
+           if (twarp < 1.0)
+               twarp = 1.0;
            break;
        }
        chew();
@@ -497,7 +511,8 @@ void eta(void)
        if (tpower >= game.energy) {
            prout(_("Insufficient energy, sir."));
            if (!game.shldup || tpower > game.energy*2.0) {
-               if (!wfl) return;
+               if (!wfl)
+                   return;
                proutn(_("New warp factor to try? "));
                if (scan() == IHREAL) {
                    wfl = true;