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