Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include "sst.h"
  2. #include <string.h>
  3. #ifndef KOS32
  4. #include <time.h>
  5. #else
  6. #include <kolibrisys.h>
  7. #endif
  8.  
  9. void dstrct() {
  10.         /* Finish with a BANG! */
  11.         chew();
  12.         if (damage[DCOMPTR] != 0.0) {
  13.                 prout("Computer damaged; cannot execute destruct sequence.");
  14.                 return;
  15.         }
  16.         skip(1);
  17.         prouts("---WORKING---"); skip(1);
  18.         prout("SELF-DESTRUCT-SEQUENCE-ACTIVATED");
  19.         prouts("   10"); skip(1);
  20.         prouts("       9"); skip(1);
  21.         prouts("          8"); skip(1);
  22.         prouts("             7"); skip(1);
  23.         prouts("                6"); skip(1);
  24.         prout("ENTER-CORRECT-PASSWORD-TO-CONTINUE-");
  25.         prout("SELF-DESTRUCT-SEQUENCE-OTHERWISE-");
  26.         prout("SELF-DESTRUCT-SEQUENCE-WILL-BE-ABORTED");
  27.         scan();
  28.         chew();
  29.         if (strcmp(passwd, citem) != 0) {
  30.                 prouts("PASSWORD-REJECTED;"); skip(1);
  31.                 prout("CONTINUITY-EFFECTED");
  32.                 skip(1);
  33.                 return;
  34.         }
  35.         prouts("PASSWORD-ACCEPTED"); skip(1);
  36.         prouts("                   5"); skip(1);
  37.         prouts("                      4"); skip(1);
  38.         prouts("                         3"); skip(1);
  39.         prouts("                            2"); skip(1);
  40.         prouts("                              1"); skip(1);
  41.         if (Rand() < 0.15) {
  42.                 prouts("GOODBYE-CRUEL-WORLD");
  43.                 skip(1);
  44.         }
  45.         skip(2);
  46.         kaboom();
  47. }
  48.  
  49. void kaboom(void) {
  50.         stars();
  51.         if (ship==IHE) prouts("***");
  52.         prouts("********* Entropy of ");
  53.         crmshp();
  54.         prouts(" maximized *********");
  55.         skip(1);
  56.         stars();
  57.         skip(1);
  58.         if (nenhere != 0) {
  59.                 double whammo = 25.0 * energy;
  60.                 int l=1;
  61.                 while (l <= nenhere) {
  62.                         if (kpower[l]*kdist[l] <= whammo)
  63.                                 deadkl(kx[l],ky[l], quad[kx[l]][ky[l]], kx[l], ky[l]);
  64.                         l++;
  65.                 }
  66.         }
  67.         finish(FDILITHIUM);
  68. }
  69.                                
  70.  
  71. void finish(FINTYPE ifin) {
  72.         int igotit = 0;
  73.         alldone = 1;
  74.         skip(3);
  75.         printf("It is stardate %.1f .\n\n", d.date);
  76.         switch (ifin) {
  77.                 case FWON: // Game has been won
  78.                         if (d.nromrem != 0)
  79.                                 printf("The remaining %d Romulans surrender to Starfleet Command.\n",
  80.                                            d.nromrem);
  81.  
  82.  
  83.             prout("You have smashed the Klingon invasion fleet and saved");
  84.             prout("the Federation.");
  85.  
  86. #ifdef CAPTURE
  87.             if (alive && brigcapacity-brigfree > 0) { // captured Klingon crew will get transfered to starbase
  88.                 kcaptured += brigcapacity-brigfree;
  89.                 printf("The %d captured Klingons are transferred to Star Fleet Command.\n",
  90.                        brigcapacity-brigfree);
  91.             }
  92. #endif
  93.                         gamewon=1;
  94.                         if (alive) {
  95.                 double badpt;
  96.  
  97.                                 badpt = 5.*d.starkl + casual + 10.*d.nplankl +
  98.                                                 45.*nhelp+100.*d.basekl;
  99.                                 if (ship == IHF) badpt += 100.0;
  100.                                 else if (ship == 0) badpt += 200.0;
  101.                                 if (badpt < 100.0) badpt = 0.0; // Close enough!
  102.                                 if (d.date-indate < 5.0 ||
  103.                                         // killsPerDate >= RateMax
  104.                                         (d.killk+d.killc+d.nsckill)/(d.date-indate) >=
  105.                                         0.1*skill*(skill+1.0) + 0.1 + 0.008*badpt) {
  106.                                         skip(1);
  107.                                         prout("In fact, you have done so well that Starfleet Command");
  108.                                         switch (skill) {
  109.                                                 case SNOVICE:
  110.                                                         prout("promotes you one step in rank from \"Novice\" to \"Fair\".");
  111.                                                         break;
  112.                                                 case SFAIR:
  113.                                                         prout("promotes you one step in rank from \"Fair\" to \"Good\".");
  114.                                                         break;
  115.                                                 case SGOOD:
  116.                                                         prout("promotes you one step in rank from \"Good\" to \"Expert\".");
  117.                                                         break;
  118.                                                 case SEXPERT:
  119.                                                         prout("promotes you to Commodore Emeritus.");
  120.                                                         skip(1);
  121.                                                         prout("Now that you think you're really good, try playing");
  122.                                                         prout("the \"Emeritus\" game. It will splatter your ego.");
  123.                                                         break;
  124.                                                 case SEMERITUS:
  125.                                                         skip(1);
  126.                                                         prout("Computer-  ERROR-ERROR-ERROR-ERROR");
  127.                                                         skip(1);
  128.                                                         prout("  YOUR-SKILL-HAS-EXCEEDED-THE-CAPACITY-OF-THIS-PROGRAM");
  129.                                                         prout("  THIS-PROGRAM-MUST-SURVIVE");
  130.                                                         prout("  THIS-PROGRAM-MUST-SURVIVE");
  131.                                                         prout("  THIS-PROGRAM-MUST-SURVIVE");
  132.                                                         prout("  THIS-PROGRAM-MUST?- MUST ? - SUR? ? -?  VI");
  133.                                                         skip(1);
  134.                                                         prout("Now you can retire and write your own Star Trek game!");
  135.                                                         skip(1);
  136.                                                         break;
  137.                                         }
  138.                                         if (skill > SGOOD) {
  139.                                                 if (thawed
  140. #ifdef DEBUG
  141.                                                         && !idebug
  142. #endif
  143.                                                         )
  144.                                                         prout("You cannot get a citation, so...");
  145.                                                 else {
  146.                                                         prout("Do you want your Commodore Emeritus Citation printed?");
  147.                                                         proutn("(You need a 132 column printer.)");
  148.                                                         chew();
  149.                                                         if (ja()) {
  150.                                                                 igotit = 1;
  151.                                                         }
  152.                                                 }
  153.                                         }
  154.                                 }
  155.                                 // Only grant long life if alive (original didn't!)
  156.                                 skip(1);
  157.                                 prout("LIVE LONG AND PROSPER.");
  158.                         }
  159.                         score(0);
  160.                         if (igotit != 0) plaque();
  161.                         return;
  162.                 case FDEPLETE: // Federation Resources Depleted
  163.                         prout("Your time has run out and the Federation has been");
  164.                         prout("conquered.  Your starship is now Klingon property,");
  165.                         prout("and you are put on trial as a war criminal.  On the");
  166.                         proutn("basis of your record, you are ");
  167.                         if (d.remkl*3.0 > inkling) {
  168.                                 prout("aquitted.");
  169.                                 skip(1);
  170.                                 prout("LIVE LONG AND PROSPER.");
  171.                         }
  172.                         else {
  173.                                 prout("found guilty and");
  174.                                 prout("sentenced to death by slow torture.");
  175.                                 alive = 0;
  176.                         }
  177.                         score(0);
  178.                         return;
  179.                 case FLIFESUP:
  180.                         prout("Your life support reserves have run out, and");
  181.                         prout("you die of thirst, starvation, and asphyxiation.");
  182.                         prout("Your starship is a derelict in space.");
  183.                         break;
  184.                 case FNRG:
  185.                         prout("Your energy supply is exhausted.");
  186.                         skip(1);
  187.                         prout("Your starship is a derelict in space.");
  188.                         break;
  189.                 case FBATTLE:
  190.                         proutn("The ");
  191.                         crmshp();
  192.                         prout("has been destroyed in battle.");
  193.                         skip(1);
  194.                         prout("Dulce et decorum est pro patria mori.");
  195.                         break;
  196.                 case FNEG3:
  197.                         prout("You have made three attempts to cross the negative energy");
  198.                         prout("barrier which surrounds the galaxy.");
  199.                         skip(1);
  200.                         prout("Your navigation is abominable.");
  201.                         score(0);
  202.                         return;
  203.                 case FNOVA:
  204.                         prout("Your starship has been destroyed by a nova.");
  205.                         prout("That was a great shot.");
  206.                         skip(1);
  207.                         break;
  208.                 case FSNOVAED:
  209.                         proutn("The ");
  210.                         crmshp();
  211.                         prout(" has been fried by a supernova.");
  212.                         prout("...Not even cinders remain...");
  213.                         break;
  214.                 case FABANDN:
  215.                         prout("You have been captured by the Klingons. If you still");
  216.                         prout("had a starbase to be returned to, you would have been");
  217.                         prout("repatriated and given another chance. Since you have");
  218.                         prout("no starbases, you will be mercilessly tortured to death.");
  219.                         break;
  220.                 case FDILITHIUM:
  221.                         prout("Your starship is now an expanding cloud of subatomic particles");
  222.                         break;
  223.                 case FMATERIALIZE:
  224.                         prout("Starbase was unable to re-materialize your starship.");
  225.                         prout("Sic transit gloria muntdi");
  226.                         break;
  227.                 case FPHASER:
  228.                         proutn("The ");
  229.                         crmshp();
  230.                         prout(" has been cremated by its own phasers.");
  231.                         break;
  232.                 case FLOST:
  233.                         prout("You and your landing party have been");
  234.                         prout("converted to energy, dissipating through space.");
  235.                         break;
  236.                 case FMINING:
  237.                         prout("You are left with your landing party on");
  238.                         prout("a wild jungle planet inhabited by primitive cannibals.");
  239.                         skip(1);
  240.                         prout("They are very fond of \"Captain Kirk\" soup.");
  241.                         skip(1);
  242.                         proutn("Without your leadership, the ");
  243.                         crmshp();
  244.                         prout(" is destroyed.");
  245.                         break;
  246.                 case FDPLANET:
  247.                         prout("You and your mining party perish.");
  248.                         skip(1);
  249.                         prout("That was a great shot.");
  250.                         skip(1);
  251.                         break;
  252.                 case FSSC:
  253.                         prout("The Galileo is instantly annihilated by the supernova.");
  254.                         // no break;
  255.                 case FPNOVA:
  256.                         prout("You and your mining party are atomized.");
  257.                         skip(1);
  258.                         proutn("Mr. Spock takes command of the ");
  259.                         crmshp();
  260.                         prout(" and");
  261.                         prout("joins the Romulans, reigning terror on the Federation.");
  262.                         break;
  263.                 case FSTRACTOR:
  264.                         prout("The shuttle craft Galileo is also caught,");
  265.                         prout("and breaks up under the strain.");
  266.                         skip(1);
  267.                         prout("Your debris is scattered for millions of miles.");
  268.                         proutn("Without your leadership, the ");
  269.                         crmshp();
  270.                         prout(" is destroyed.");
  271.                         break;
  272.                 case FDRAY:
  273.                         prout("The mutants attack and kill Spock.");
  274.                         prout("Your ship is captured by Klingons, and");
  275.                         prout("your crew is put on display in a Klingon zoo.");
  276.                         break;
  277.                 case FTRIBBLE:
  278.                         prout("Tribbles consume all remaining water,");
  279.                         prout("food, and oxygen on your ship.");
  280.                         skip(1);
  281.                         prout("You die of thirst, starvation, and asphyxiation.");
  282.                         prout("Your starship is a derelict in space.");
  283.                         break;
  284.                 case FHOLE:
  285.                         prout("Your ship is drawn to the center of the black hole.");
  286.                         prout("You are crushed into extremely dense matter.");
  287.                         break;
  288. #ifdef CLOAKING
  289.                 case FCLOAK:
  290.                         ncviol++;
  291.                         prout("You have violated the Treaty of Algeron.");
  292.                         prout("The Romulan Empire can never trust you again.");
  293.                         break;
  294. #endif
  295.         }
  296. #ifdef CLOAKING
  297.         if (ifin!=FWON && ifin!=FCLOAK && iscloaked!=0) {
  298.                 prout("Your ship was cloaked so your subspace radio did not receive anything.");
  299.                 prout("You may have missed some warning messages.");
  300.                 skip(1);
  301.         }
  302. #endif
  303.  
  304.         if (ship==IHF) ship= 0;
  305.         else if (ship == IHE) ship = IHF;
  306.         alive = 0;
  307.         if (d.remkl != 0) {
  308.                 double goodies = d.remres/inresor;
  309.                 double baddies = (d.remkl + 2.0*d.remcom)/(inkling+2.0*incom);
  310.                 if (goodies/baddies >= 1.0+0.5*Rand()) {
  311.                         prout("As a result of your actions, a treaty with the Klingon");
  312.                         prout("Empire has been signed. The terms of the treaty are");
  313.                         if (goodies/baddies >= 3.0+Rand()) {
  314.                                 prout("favorable to the Federation.");
  315.                                 skip(1);
  316.                                 prout("Congratulations!");
  317.                         }
  318.                         else
  319.                                 prout("highly unfavorable to the Federation.");
  320.                 }
  321.                 else
  322.                         prout("The Federation will be destroyed.");
  323.         }
  324.         else {
  325.                 prout("Since you took the last Klingon with you, you are a");
  326.                 prout("martyr and a hero. Someday maybe they'll erect a");
  327.                 prout("statue in your memory. Rest in peace, and try not");
  328.                 prout("to think about pigeons.");
  329.                 gamewon = 1;
  330.         }
  331.         score(0);
  332. }
  333.  
  334. void score(int inGame) {
  335.         double timused = d.date - indate;
  336.     int ithperd, iwon, klship;
  337.     int dnromrem = d.nromrem; // Leave global value alone
  338.  
  339.     if (!inGame) pause(0);
  340.  
  341.         iskill = skill;
  342.         if ((timused == 0 || d.remkl != 0) && timused < 5.0) timused = 5.0;
  343.         perdate = (d.killc + d.killk + d.nsckill)/timused;
  344.         ithperd = 500*perdate + 0.5;
  345.         iwon = 0;
  346.         if (gamewon) iwon = 100*skill;
  347.         if (ship == IHE) klship = 0;
  348.         else if (ship == IHF) klship = 1;
  349.         else klship = 2;
  350.         if (gamewon == 0 || inGame) dnromrem = 0; // None captured if no win or if still in the game
  351.         iscore = 10*d.killk + 50*d.killc + ithperd + iwon
  352.                          - 100*d.basekl - 100*klship - 45*nhelp -5*d.starkl - casual
  353.                  + 20*d.nromkl + 200*d.nsckill - 10*d.nplankl + dnromrem;
  354. #ifdef CLOAKING
  355.         iscore -= 100*ncviol;
  356. #endif
  357. #ifdef CAPTURE
  358.         iscore += 3*kcaptured;
  359. #endif
  360.         if (alive == 0) iscore -= 200;
  361.         skip(2);
  362.     if (inGame) prout("Your score so far --");
  363.     else prout("Your score --");
  364.         if (d.nromkl)
  365.                 printf(d.nromkl> 1 ? "%6d Romulan ships destroyed            %5d\n" : "%6d Romulan ship destroyed             %5d\n",
  366.                            d.nromkl, 20*d.nromkl);
  367.         if (dnromrem)
  368.                 printf(dnromrem > 1 ? "%6d Romulan ships captured             %5d\n" : "%6d Romulan ship captured              %5d\n",
  369.                            dnromrem, dnromrem);
  370.         if (d.killk)
  371.                 printf(d.killk > 1 ? "%6d ordinary Klingon ships destroyed   %5d\n" : "%6d ordinary Klingon ship destroyed    %5d\n",
  372.                            d.killk,  10*d.killk);
  373.         if (d.killc)
  374.                 printf(d.killc > 1 ? "%6d Klingon Commander ships destroyed  %5d\n" : "%6d Klingon Commander ship destroyed   %5d\n",
  375.                            d.killc, 50*d.killc);
  376.         if (d.nsckill)
  377.                 printf("%6d Super-Commander ship destroyed     %5d\n",
  378.                            d.nsckill, 200*d.nsckill);
  379.         if (ithperd)
  380.                 printf("%6.2f Klingons per stardate              %5d\n",
  381.                            perdate, ithperd);
  382. #ifdef CAPTURE
  383.         if (kcaptured)
  384.                 printf(kcaptured > 1 ? "%6d Klingons captured                  %5d\n" : "%6d Klingon captured                   %5d\n",
  385.                         kcaptured, 3*kcaptured);
  386. #endif
  387.         if (d.starkl)
  388.                 printf(d.starkl > 1 ? "%6d stars destroyed by your action     %5d\n" : "%6d star destroyed by your action      %5d\n",
  389.                            d.starkl, -5*d.starkl);
  390.         if (d.nplankl)
  391.                 printf(d.nplankl > 1 ? "%6d planets destroyed by your action   %5d\n" : "%6d planet destroyed by your action    %5d\n",
  392.                            d.nplankl, -10*d.nplankl);
  393.         if (d.basekl)
  394.                 printf(d.basekl > 1 ? "%6d bases destroyed by your action     %5d\n" : "%6d base destroyed by your action      %5d\n",
  395.                            d.basekl, -100*d.basekl);
  396.         if (nhelp)
  397.                 printf(nhelp > 1 ? "%6d calls for help from starbase       %5d\n" : "%6d call for help from starbase        %5d\n",
  398.                            nhelp, -45*nhelp);
  399.         if (casual)
  400.                 printf(casual > 1 ? "%6d casualties incurred                %5d\n" : "%6d casualty incurred                  %5d\n",
  401.                            casual, -casual);
  402.         if (klship)
  403.                 printf(klship > 1 ? "%6d ships lost or destroyed            %5d\n" : "%6d ship lost or destroyed             %5d\n",
  404.                            klship, -100*klship);
  405. #ifdef CLOAKING
  406.         if (ncviol>0)
  407.                 printf(ncviol > 1 ? "%6d Treaty of Algeron violations       %5d\n" : "%6d Treaty of Algeron violation        %5d\n",
  408.                        ncviol, -100*ncviol);
  409. #endif
  410.         if (alive==0)
  411.                 prout("Penalty for getting yourself killed        -200");
  412.         if (gamewon) {
  413.                 skip(1);
  414.                 proutn("Bonus for winning ");
  415.                 switch (skill) {
  416.                         case SNOVICE: proutn("Novice game  "); break;
  417.                         case SFAIR: proutn("Fair game    "); break;
  418.                         case SGOOD: proutn("Good game    "); break;
  419.                         case SEXPERT: proutn("Expert game  "); break;
  420.                         case SEMERITUS: proutn("Emeritus game"); break;
  421.                 }
  422.                 printf("           %5d\n", iwon);
  423.         }
  424.         skip(2);
  425.     printf("TOTAL SCORE                               %5d\n", iscore);
  426.     if (inGame && skill < SGOOD) printf("REMEMBER--The score doesn't really matter until the mission is accomplished!\n");
  427. }
  428.  
  429. void plaque(void) {
  430.         FILE *fp=NULL;
  431. #ifndef KOS32  
  432.         time_t t;
  433. #else
  434.         int kos_date, kos_time;
  435. #endif
  436.         char *timestring;
  437.         int nskip;
  438.         char winner[128];
  439.         skip(2);
  440.        
  441.         while (fp == NULL) {
  442.                 printf("File or device name for your plaque:");
  443. #ifndef KOS32          
  444.                 fgets(winner, 128, stdin);
  445. #else
  446.                 gets(winner);
  447. #endif         
  448.                 winner[strlen(winner)-1] = '\0';
  449.                 fp = fopen(winner, "w");
  450.                 if (fp==NULL) {
  451.                         printf("Invalid name.\n");
  452.                 }
  453.         }
  454.  
  455.         printf("Enter name to go on plaque (up to 30 characters):");
  456. #ifndef KOS32          
  457.                 fgets(winner, 128, stdin);
  458. #else
  459.                 gets(winner);
  460. #endif          winner[strlen(winner)-1] = '\0';
  461.         winner[30] = '\0';
  462.         nskip = 64 - strlen(winner)/2;
  463.  
  464.         fprintf(fp,"\n\n\n\n");
  465.         /* --------DRAW ENTERPRISE PICTURE. */
  466.         fprintf(fp, "                                                                EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n" );
  467.         fprintf(fp, "                                      EEE                      E  : :                                         :  E\n" );
  468.         fprintf(fp, "                                    EE   EEE                   E  : :                   NCC-1701              :  E\n");
  469.         fprintf(fp, "                    EEEEEEEEEEEEEEEE        EEEEEEEEEEEEEEE    E  : :                                         : E\n");
  470.         fprintf(fp, "                     E                                     E    EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n");
  471.         fprintf(fp, "                      EEEEEEEEE               EEEEEEEEEEEEE                 E  E\n");
  472.         fprintf(fp, "                               EEEEEEE   EEEEE    E          E              E  E\n");
  473.         fprintf(fp, "                                      EEE           E          E            E  E\n");
  474.         fprintf(fp, "                                                       E         E          E  E\n");
  475.         fprintf(fp, "                                                         EEEEEEEEEEEEE      E  E\n");
  476.         fprintf(fp, "                                                      EEE :           EEEEEEE  EEEEEEEE\n");
  477.         fprintf(fp, "                                                    :E    :                 EEEE       E\n");
  478.         fprintf(fp, "                                                   .-E   -:-----                       E\n");
  479.         fprintf(fp, "                                                    :E    :                            E\n");
  480.         fprintf(fp, "                                                      EE  :                    EEEEEEEE\n");
  481.         fprintf(fp, "                                                       EEEEEEEEEEEEEEEEEEEEEEE\n");
  482.         fprintf(fp, "\n\n\n");
  483.         fprintf(fp, "                                                       U. S. S. ENTERPRISE\n");
  484.         fprintf(fp, "\n\n\n\n");
  485.         fprintf(fp, "                                  For demonstrating outstanding ability as a starship captain\n");
  486.         fprintf(fp, "\n");
  487.         fprintf(fp, "                                                Starfleet Command bestows to you\n");
  488.         fprintf(fp, "\n");
  489.         fprintf(fp,"%*s%s\n\n", nskip, "", winner);
  490.         fprintf(fp, "                                                           the rank of\n\n");
  491.         fprintf(fp, "                                                       \"Commodore Emeritus\"\n\n");
  492.         fprintf(fp, "                                                          ");
  493.         switch (iskill) {
  494.                 case SEXPERT: fprintf(fp," Expert level\n\n"); break;
  495.                 case SEMERITUS: fprintf(fp,"Emeritus level\n\n"); break;
  496.                 default: fprintf(fp," Cheat level\n\n"); break;
  497.         }
  498. #ifndef KOS32  
  499.         t = time(NULL);
  500.         timestring = ctime(&t);
  501.         fprintf(fp, "                                                 This day of %.6s %.4s, %.8s\n\n",
  502.                         timestring+4, timestring+20, timestring+11);
  503. #else
  504.         kos_date = _ksys_get_date();
  505.         kos_time = _ksys_get_system_clock();
  506.         fprintf(fp, "                                                 This day of %02i/%02i/%02i %02i:%02i:%02i\n\n",
  507.                         kos_date >> 16, (kos_date & 0xFF00) >> 8, (kos_date & 0xFF) + 2000,
  508.                         kos_time & 0xFF, (kos_time & 0xFF00) >> 8, kos_time >> 16 );
  509. #endif
  510.         fprintf(fp,"                                                        Your score:  %d\n\n", iscore);
  511.         fprintf(fp,"                                                    Klingons per stardate:  %.2f\n", perdate);
  512.         fclose(fp);
  513. }
  514.