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