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