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