Fixed the Python help command.
[super-star-trek.git] / src / finish.c
index 9c518b6c4bfed28dfe2496ef8ea0fa63e85510e4..90b23fc2dcbd39551428d7dc6c260d8f12026afe 100644 (file)
@@ -2,7 +2,8 @@
 #include <string.h>
 #include <time.h>
 
-void dstrct() 
+void selfdestruct(void)
+/* self-destruct maneuver */
 {
     /* Finish with a BANG! */
     chew();
@@ -49,7 +50,8 @@ void dstrct()
 void kaboom(void) 
 {
     stars();
-    if (game.ship==IHE) prouts("***");
+    if (game.ship==IHE)
+       prouts("***");
     prouts(_("********* Entropy of "));
     crmshp();
     prouts(_(" maximized *********"));
@@ -61,7 +63,7 @@ void kaboom(void)
        int l=1;
        while (l <= game.nenhere) {
            if (game.kpower[l]*game.kdist[l] <= whammo) 
-               deadkl(game.ks[l], game.quad[game.ks[l].x][game.ks[l].y], game.ks[l].x, game.ks[l].y);
+               deadkl(game.ks[l], game.quad[game.ks[l].x][game.ks[l].y], game.ks[l]);
            l++;
        }
     }
@@ -69,7 +71,8 @@ void kaboom(void)
 }
                                
 
-void finish(FINTYPE ifin) 
+void finish(FINTYPE ifin)
+/* end the game, with appropriate notfications */
 {
     bool igotit = false;
     game.alldone = true;
@@ -87,18 +90,28 @@ void finish(FINTYPE ifin)
        game.gamewon = true;
        if (game.alive) {
            double badpt;
-           badpt = 5.0*game.state.starkl + game.casual + 10.0*game.state.nplankl +
-               45.*game.nhelp+100.*game.state.basekl+3.*game.abandoned;
-           if (game.ship == IHF) badpt += 100.0;
-           else if (game.ship == 0) badpt += 200.0;
-           if (badpt < 100.0) badpt = 0.0;     // Close enough!
+           badpt = 5.0*game.state.starkl \
+               + game.casual \
+               + 10.0*game.state.nplankl \
+               + 300.0*game.state.nworldkl \
+               + 45.0*game.nhelp \
+               + 100.0*game.state.basekl \
+               + 3.0*game.abandoned;
+           if (game.ship == IHF)
+               badpt += 100.0;
+           else if (game.ship == 0)
+               badpt += 200.0;
+           if (badpt < 100.0)
+               badpt = 0.0;    // Close enough!
            if (game.state.date-game.indate < 5.0 ||
                // killsPerDate >= RateMax
-               KLINGKILLED/(game.state.date-game.indate) >=
+               ((game.inkling + game.incom + game.inscom) - (game.state.remkl + game.state.remcom + game.state.nscrem))/(game.state.date-game.indate) >=
                0.1*game.skill*(game.skill+1.0) + 0.1 + 0.008*badpt) {
                skip(1);
                prout(_("In fact, you have done so well that Starfleet Command"));
                switch (game.skill) {
+               case SKILL_NONE:
+                   break;      /* quiet gcc warning */
                case SKILL_NOVICE:
                    prout(_("promotes you one step in rank from \"Novice\" to \"Fair\"."));
                    break;
@@ -139,8 +152,8 @@ void finish(FINTYPE ifin)
                    else {
                        proutn(_("Do you want your Commodore Emeritus Citation printed? "));
                        chew();
-                       if (ja()) {
-                           igotit = 1;
+                       if (ja() == true) {
+                           igotit = true;
                        }
                    }
                }
@@ -150,14 +163,15 @@ void finish(FINTYPE ifin)
            prout(_("LIVE LONG AND PROSPER."));
        }
        score();
-       if (igotit != 0) plaque();
+       if (igotit)
+           plaque();       
        return;
     case FDEPLETE: // Federation Resources Depleted
        prout(_("Your time has run out and the Federation has been"));
        prout(_("conquered.  Your starship is now Klingon property,"));
        prout(_("and you are put on trial as a war criminal.  On the"));
        proutn(_("basis of your record, you are "));
-       if (KLINGREM*3.0 > INKLINGTOT) {
+       if ((game.state.remkl + game.state.remcom + game.state.nscrem)*3.0 > (game.inkling + game.incom + game.inscom)) {
            prout(_("acquitted."));
            skip(1);
            prout(_("LIVE LONG AND PROSPER."));
@@ -165,7 +179,7 @@ void finish(FINTYPE ifin)
        else {
            prout(_("found guilty and"));
            prout(_("sentenced to death by slow torture."));
-           game.alive = 0;
+           game.alive = false;
        }
        score();
        return;
@@ -215,7 +229,7 @@ void finish(FINTYPE ifin)
        break;
     case FMATERIALIZE:
        prout(_("Starbase was unable to re-materialize your starship."));
-       prout(_("Sic transit gloria muntdi"));
+       prout(_("Sic transit gloria mundi"));
        break;
     case FPHASER:
        proutn(_("The "));
@@ -282,10 +296,12 @@ void finish(FINTYPE ifin)
        prout(_("Your last crew member has died."));
        break;
     }
-    if (game.ship==IHF) game.ship= 0;
-    else if (game.ship == IHE) game.ship = IHF;
-    game.alive = 0;
-    if (KLINGREM != 0) {
+    if (game.ship==IHF)
+       game.ship= 0;
+    else if (game.ship == IHE)
+       game.ship = IHF;
+    game.alive = false;
+    if ((game.state.remkl + game.state.remcom + game.state.nscrem) != 0) {
        double goodies = game.state.remres/game.inresor;
        double baddies = (game.state.remkl + 2.0*game.state.remcom)/(game.inkling+2.0*game.incom);
        if (goodies/baddies >= 1.0+0.5*Rand()) {
@@ -307,79 +323,92 @@ void finish(FINTYPE ifin)
        prout(_("martyr and a hero. Someday maybe they'll erect a"));
        prout(_("statue in your memory. Rest in peace, and try not"));
        prout(_("to think about pigeons."));
-       game.gamewon = 1;
+       game.gamewon = true;
     }
     score();
 }
 
+static void score_item(const char *str, int num, int score)
+{
+    if (num) {
+       prout(str, num, score);
+       iscore += score;
+    }
+}
+
+static void score_item1(const char *str, int score)
+{
+    prout(str, score);
+    iscore += score;
+}
+
+static void score_itemf(const char *str, float num, int score)
+{
+    if (num > 0) {
+       prout(str, num, score);
+       iscore += score;
+    }
+}
+
 void score(void) 
+/* compute player's score */
 {
     double timused = game.state.date - game.indate;
-    int ithperd, iwon, klship;
+    int iwon, klship, num;
 
     iskill = game.skill;
-    if ((timused == 0 || KLINGREM != 0) && timused < 5.0) timused = 5.0;
-    perdate = KLINGKILLED/timused;
-    ithperd = 500*perdate + 0.5;
+    if ((timused == 0 || (game.state.remkl + game.state.remcom + game.state.nscrem) != 0) && timused < 5.0)
+       timused = 5.0;
     iwon = 0;
-    if (game.gamewon) iwon = 100*game.skill;
-    if (game.ship == IHE) klship = 0;
-    else if (game.ship == IHF) klship = 1;
-    else klship = 2;
-    if (game.gamewon == 0) game.state.nromrem = 0; // None captured if no win
-    iscore = 10*NKILLK + 50*NKILLC + ithperd + iwon
-       - 100*game.state.basekl - 100*klship - 45*game.nhelp -5*game.state.starkl - game.casual
-       + 20*NKILLROM + 200*NKILLSC - 10*game.state.nplankl - 300*game.state.nworldkl + game.state.nromrem;
-    if (game.alive == 0) iscore -= 200;
+    if (game.gamewon)
+       iwon = 100*game.skill;
+    if (game.ship == IHE) 
+       klship = 0;
+    else if (game.ship == IHF) 
+       klship = 1;
+    else
+       klship = 2;
+    iscore = 0;
     skip(2);
     prout(_("Your score --"));
-    if (NKILLROM)
-       prout(_("%6d Romulans destroyed                 %5d"),
-             NKILLROM,20*NKILLROM);
-    if (game.state.nromrem)
-       prout(_("%6d Romulans captured                  %5d"),
+    num = game.inrom - game.state.nromrem;
+    score_item(_("%6d Romulans destroyed                 %5d"), num, 20 * num);
+    if (game.gamewon)
+       score_item(_("%6d Romulans captured                  %5d"),
              game.state.nromrem, game.state.nromrem);
-    if (NKILLK)
-       prout(_("%6d ordinary Klingons destroyed        %5d"),
-             NKILLK, 10*NKILLK);
-    if (NKILLC)
-       prout(_("%6d Klingon commanders destroyed       %5d"),
-             NKILLC, 50*NKILLC);
-    if (NKILLSC)
-       prout(_("%6d Super-Commander destroyed          %5d"),
-             NKILLSC, 200*NKILLSC);
-    if (ithperd)
-       prout(_("%6.2f Klingons per stardate              %5d"),
-             perdate, ithperd);
-    if (game.state.starkl)
-       prout(_("%6d stars destroyed by your action     %5d"),
-             game.state.starkl, -5*game.state.starkl);
-    if (game.state.nplankl)
-       prout(_("%6d planets destroyed by your action   %5d"),
-             game.state.nplankl, -10*game.state.nplankl);
-    if ((game.options & OPTION_WORLDS) && game.state.nworldkl)
-       prout(_("%6d inhabited planets destroyed by your action   %5d"),
-             game.state.nplankl, -300*game.state.nworldkl);
-    if (game.state.basekl)
-       prout(_("%6d bases destroyed by your action     %5d"),
-             game.state.basekl, -100*game.state.basekl);
-    if (game.nhelp)
-       prout(_("%6d calls for help from starbase       %5d"),
-             game.nhelp, -45*game.nhelp);
-    if (game.casual)
-       prout(_("%6d casualties incurred                %5d"),
-             game.casual, -game.casual);
-    if (game.abandoned)
-       prout(_("%6d crew abandoned in space            %5d"),
-             game.abandoned, -3*game.abandoned);
-    if (klship)
-       prout(_("%6d ship(s) lost or destroyed          %5d"),
-             klship, -100*klship);
-    if (game.alive==0)
-       prout(_("Penalty for getting yourself killed        -200"));
+    num = game.inkling - game.state.remkl;
+    score_item(_("%6d ordinary Klingons destroyed        %5d"), num, 10 * num);
+    num = game.incom - game.state.remcom;
+    score_item(_("%6d Klingon commanders destroyed       %5d"), num, 50 * num);
+    num = game.inscom - game.state.nscrem;
+    score_item(_("%6d Super-Commander destroyed          %5d"), num, 200 * num);
+    perdate = ((game.inkling + game.incom + game.inscom) -
+           (game.state.remkl + game.state.remcom + game.state.nscrem))/timused;
+    score_itemf(_("%6.2f Klingons per stardate              %5d"), perdate,
+           500 * perdate + 0.5);
+    score_item(_("%6d stars destroyed by your action     %5d"),
+           game.state.starkl, -5*game.state.starkl);
+    score_item(_("%6d planets destroyed by your action   %5d"),
+           game.state.nplankl, -10*game.state.nplankl);
+    if (game.options & OPTION_WORLDS)
+       score_item(_("%6d inhabited planets destroyed by your action   %5d"),
+               game.state.nworldkl, -300*game.state.nworldkl);
+    score_item(_("%6d bases destroyed by your action     %5d"),
+           game.state.basekl, -100*game.state.basekl);
+    score_item(_("%6d calls for help from starbase       %5d"),
+           game.nhelp, -45*game.nhelp);
+    score_item(_("%6d casualties incurred                %5d"),
+           game.casual, -game.casual);
+    score_item(_("%6d crew abandoned in space            %5d"),
+           game.abandoned, -3*game.abandoned);
+    score_item(_("%6d ship(s) lost or destroyed          %5d"),
+           klship, -100*klship);
+    if (!game.alive)
+       score_item1(_("Penalty for getting yourself killed        %5d"), -200);
     if (game.gamewon) {
        proutn(_("Bonus for winning "));
        switch (game.skill) {
+       case SKILL_NONE:     break;     /* quiet gcc warning */
        case SKILL_NOVICE:   proutn(_("Novice game  ")); break;
        case SKILL_FAIR:     proutn(_("Fair game    ")); break;
        case SKILL_GOOD:     proutn(_("Good game    ")); break;
@@ -392,7 +421,9 @@ void score(void)
     prout(_("TOTAL SCORE                               %5d"), iscore);
 }
 
-void plaque(void) {
+void plaque(void)
+/* emit winner's commemmorative plaque */
+{
        FILE *fp=NULL;
        time_t t;
        char *timestring;
@@ -400,7 +431,6 @@ void plaque(void) {
        char winner[128];
 
        skip(2);
-       
        while (fp == NULL) {
                 proutn(_("File or device name for your plaque: "));
                 cgetline(winner, sizeof(winner));