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