3de87c34405b99a733bd54bc2ebb5e6a5e4c2288
[super-star-trek.git] / planets.c
1 #include "sst.h"
2
3 static int height;
4
5 static char *classes[] = {"M","N","O"};
6
7 static int consumeTime(void) {
8 /* I think most of this avoidance was caused by overlay scheme.
9    Let's see what happens if all events can occur here */
10
11 //      double asave;
12         ididit = 1;
13 #if 0
14         /* Don't wory about this */
15         if (future[FTBEAM] <= game.state.date+Time && game.state.remcom != 0 && condit != IHDOCKED) {
16                 /* We are about to be tractor beamed -- operation fails */
17                 return 1;
18         }
19 #endif
20 //      asave = future[FSNOVA];
21 //      future[FSNOVA] = 1e30; /* defer supernovas */
22         events();       /* Used to avoid if future[FSCMOVE] within time */
23 //      future[FSNOVA] = asave;
24         /*fails if game over, quadrant super-novas or we've moved to new quadrant*/
25         if (alldone || game.state.galaxy[quadx][quady] == 1000 || justin != 0) return 1;
26         return 0;
27 }
28
29 void preport(void) {
30         int iknow = 0, i;
31         skip(1);
32         chew();
33         prout("Spock-  \"Planet report follows, Captain.\"");
34         skip(1);
35         for (i = 0; i < inplan; i++) {
36                 if (game.state.plnets[i].known != unknown
37 #ifdef DEBUG
38                         || ( idebug && game.state.plnets[i].x !=0)
39 #endif
40                         ) {
41                         iknow = 1;
42 #ifdef DEBUG
43                         if (idebug && game.state.plnets[i].known==unknown) proutn("(Unknown) ");
44 #endif
45                         proutn(cramlc(quadrant, game.state.plnets[i].x, game.state.plnets[i].y));
46                         proutn("   class ");
47                         proutn(classes[game.state.plnets[i].pclass]);
48                         proutn("   ");
49                         if (game.state.plnets[i].crystals == 0) proutn("no ");
50                         prout("dilithium crystals present.");
51                         if (game.state.plnets[i].known==shuttle_down) 
52                                 prout("    Shuttle Craft Galileo on surface.");
53                 }
54         }
55         if (iknow==0) prout("No information available.");
56 }
57
58 void orbit(void) {
59         skip(1);
60         chew();
61         if (inorbit!=0) {
62                 prout("Already in standard orbit.");
63                 return;
64         }
65         if (game.damage[DWARPEN] != 0 && game.damage[DIMPULS] != 0) {
66                 prout("Both warp and impulse engines damaged.");
67                 return;
68         }
69         if (plnetx == 0 || abs(sectx-plnetx) > 1 || abs(secty-plnety) > 1) {
70                 crmshp();
71                 prout(" not adjacient to planet.\n");
72                 return;
73         }
74         Time = 0.02+0.03*Rand();
75         prout("Helmsman Sulu-  \"Entering standard orbit, Sir.\"");
76         newcnd();
77         if (consumeTime()) return;
78         height = (1400.+7200.*Rand());
79         prout("Sulu-  \"Entered orbit at altitude %.2f kilometers.\"", height);
80         inorbit = 1;
81         return;
82 }
83
84 void sensor(void) {
85         skip(1);
86         chew();
87         if (game.damage[DSRSENS] != 0.0) {
88                 prout("Short range sensors damaged.");
89                 return;
90         }
91         if (plnetx == 0) {
92                 prout("No planet in this quadrant.");
93                 return;
94         }
95         prout("Spock-  \"Sensor scan for %s-", cramlc(quadrant, quadx, quady));
96         skip(1);
97         prout("         Planet at %s is of class %s.", 
98                cramlc(sector, plnetx, plnety),
99                classes[game.state.plnets[iplnet].pclass]);
100         if (game.state.plnets[iplnet].known==shuttle_down) 
101                 prout("         Sensors show Galileo still on surface.");
102         proutn("         Readings indicate");
103         if (game.state.plnets[iplnet].crystals == 0) proutn(" no");
104         prout(" dilithium crystals present.\"");
105         if (game.state.plnets[iplnet].known == unknown) game.state.plnets[iplnet].known = known;
106         return;
107 }
108
109 void beam(void) {
110         chew();
111         skip(1);
112         if (game.damage[DTRANSP] != 0) {
113                 prout("Transporter damaged.");
114                 if (game.damage[DSHUTTL]==0 && (game.state.plnets[iplnet].known==shuttle_down || iscraft == 1)) {
115                         skip(1);
116                         proutn("Spock-  \"May I suggest the shuttle craft, Sir?\" ");
117                         if (ja() != 0) shuttle();
118                 }
119                 return;
120         }
121         if (inorbit==0) {
122                 crmshp();
123                 prout(" not in standard orbit.");
124                 return;
125         }
126         if (shldup!=0) {
127                 prout("Impossible to transport through shields.");
128                 return;
129         }
130         if (game.state.plnets[iplnet].known==unknown) {
131                 prout("Spock-  \"Captain, we have no information on this planet");
132                 prout("  and Starfleet Regulations clearly state that in this situation");
133                 prout("  you may not go down.\"");
134                 return;
135         }
136         if (landed==1) {
137                 /* Coming from planet */
138                 if (game.state.plnets[iplnet].known==shuttle_down) {
139                         proutn("Spock-  \"Wouldn't you rather take the Galileo?\" ");
140                         if (ja() != 0) {
141                                 chew();
142                                 return;
143                         }
144                         prout("Your crew hides the Galileo to prevent capture by aliens.");
145                 }
146                 prout("Landing party assembled, ready to beam up.");
147                 skip(1);
148                 prout("Kirk whips out communicator...");
149                 prouts("BEEP  BEEP  BEEP");
150                 skip(2);
151                 prout("\"Kirk to enterprise-  Lock on coordinates...energize.\"");
152         }
153         else {
154                 /* Going to planet */
155                 if (game.state.plnets[iplnet].crystals==0) {
156                         prout("Spock-  \"Captain, I fail to see the logic in");
157                         prout("  exploring a planet with no dilithium crystals.");
158                         proutn("  Are you sure this is wise?\" ");
159                         if (ja()==0) {
160                                 chew();
161                                 return;
162                         }
163                 }
164                 prout("Scotty-  \"Transporter room ready, Sir.\"");
165                 skip(1);
166                 prout("Kirk, and landing party prepare to beam down to planet surface.");
167                 skip(1);
168                 prout("Kirk-  \"Energize.\"");
169         }
170         skip(1);
171         prouts("WWHOOOIIIIIRRRRREEEE.E.E.  .  .  .  .   .    .");
172         skip(2);
173         if (Rand() > 0.98) {
174                 prouts("BOOOIIIOOOIIOOOOIIIOIING . . .");
175                 skip(2);
176                 prout("Scotty-  \"Oh my God!  I've lost them.\"");
177                 finish(FLOST);
178                 return;
179         }
180         prouts(".    .   .  .  .  .  .E.E.EEEERRRRRIIIIIOOOHWW");
181         skip(2);
182         prout("Transport complete.");
183         landed = -landed;
184         if (landed==1 && game.state.plnets[iplnet].known==shuttle_down) {
185                 prout("The shuttle craft Galileo is here!");
186         }
187         if (landed!=1 && imine==1) {
188                 icrystl = 1;
189                 cryprob = 0.05;
190         }
191         imine = 0;
192         return;
193 }
194
195 void mine(void) {
196
197         ididit = 0;
198         skip(1);
199         chew();
200         if (landed!= 1) {
201                 prout("Mining party not on planet.");
202                 return;
203         }
204         if (game.state.plnets[iplnet].crystals == 0) {
205                 prout("No dilithium crystals on this planet.");
206                 return;
207         }
208         if (imine == 1) {
209                 prout("You've already mined enough crystals for this trip.");
210                 return;
211         }
212         if (icrystl == 1 && cryprob == 0.05) {
213                 proutn("With all those fresh crystals aboard the ");
214                 crmshp();
215                 skip(1);
216                 prout("there's no reason to mine more at this time.");
217                 return;
218         }
219         Time = (0.1+0.2*Rand())*game.state.plnets[iplnet].pclass;
220         if (consumeTime()) return;
221         prout("Mining operation complete.");
222         imine = 1;
223         return;
224 }
225
226 void usecrystals(void) {
227
228         skip(1);
229         chew();
230         if (icrystl!=1) {
231                 prout("No dilithium crystals available.");
232                 return;
233         }
234         if (energy >= 1000) {
235                 prout("Spock-  \"Captain, Starfleet Regulations prohibit such an operation");
236                 prout("  except when condition Yellow exists.");
237                 return;
238         }
239         prout("Spock- \"Captain, I must warn you that loading");
240         prout("  raw dilithium crystals into the ship's power");
241         prout("  system may risk a severe explosion.");
242         proutn("  Are you sure this is wise?\" ");
243         if (ja()==0) {
244                 chew();
245                 return;
246         }
247         skip(1);
248         prout("Engineering Officer Scott-  \"(GULP) Aye Sir.");
249         prout("  Mr. Spock and I will try it.\"");
250         skip(1);
251         prout("Spock-  \"Crystals in place, Sir.");
252         prout("  Ready to activate circuit.\"");
253         skip(1);
254         prouts("Scotty-  \"Keep your fingers crossed, Sir!\"");
255         skip(1);
256         if (Rand() <= cryprob) {
257                 prouts("  \"Activating now! - - No good!  It's***");
258                 skip(2);
259                 prouts("***RED ALERT!  RED A*L********************************");
260                 skip(1);
261                 stars();
262                 prouts("******************   KA-BOOM!!!!   *******************");
263                 skip(1);
264                 kaboom();
265                 return;
266         }
267         energy += 5000.0*(1.0 + 0.9*Rand());
268         prouts("  \"Activating now! - - ");
269         prout("The instruments");
270         prout("   are going crazy, but I think it's");
271         prout("   going to work!!  Congratulations, Sir!\"");
272         cryprob *= 2.0;
273         return;
274 }
275
276 void shuttle(void) {
277
278         chew();
279         skip(1);
280         ididit = 0;
281         if(game.damage[DSHUTTL] != 0.0) {
282                 if (game.damage[DSHUTTL] == -1.0) {
283                         if (inorbit && game.state.plnets[iplnet].known == shuttle_down)
284                                 prout("Ye Faerie Queene has no shuttle craft bay to dock it at.");
285                         else
286                                 prout("Ye Faerie Queene had no shuttle craft.");
287                 }
288                 else if (game.damage[DSHUTTL] > 0)
289                         prout("The Galileo is damaged.");
290                 else prout("Shuttle craft is now serving Big Macs.");
291                 return;
292         }
293         if (inorbit==0) {
294                 crmshp();
295                 prout(" not in standard orbit.");
296                 return;
297         }
298         if ((game.state.plnets[iplnet].known != shuttle_down) && iscraft != 1) {
299                 prout("Shuttle craft not currently available.");
300                 return;
301         }
302         if (landed==-1 && game.state.plnets[iplnet].known==shuttle_down) {
303                 prout("You will have to beam down to retrieve the shuttle craft.");
304                 return;
305         }
306         if (shldup!=0 || condit == IHDOCKED) {
307                 prout("Shuttle craft cannot pass through shields.");
308                 return;
309         }
310         if (game.state.plnets[iplnet].known==unknown) {
311                 prout("Spock-  \"Captain, we have no information on this planet");
312                 prout("  and Starfleet Regulations clearly state that in this situation");
313                 prout("  you may not fly down.\"");
314                 return;
315         }
316         Time = 3.0e-5*height;
317         if (Time >= 0.8*game.state.remtime) {
318                 prout("First Officer Spock-  \"Captain, I compute that such");
319                 proutn("  a maneuver would require approximately 2d%% of our",
320                       (int)(100*Time/game.state.remtime));
321                 prout("remaining time.");
322                 proutn("Are you sure this is wise?\" ");
323                 if (ja()==0) {
324                         Time = 0.0;
325                         return;
326                 }
327         }
328         if (landed == 1) {
329                 /* Kirk on planet */
330                 if (iscraft==1) {
331                         /* Galileo on ship! */
332                         if (game.damage[DTRANSP]==0) {
333                                 proutn("Spock-  \"Would you rather use the transporter?\" ");
334                                 if (ja() != 0) {
335                                         beam();
336                                         return;
337                                 }
338                                 proutn("Shuttle crew");
339                         }
340                         else
341                                 proutn("Rescue party");
342                         prout(" boards Galileo and swoops toward planet surface.");
343                         iscraft = 0;
344                         skip(1);
345                         if (consumeTime()) return;
346                         game.state.plnets[iplnet].known=shuttle_down;
347                         prout("Trip complete.");
348                         return;
349                 }
350                 else {
351                         /* Ready to go back to ship */
352                         prout("You and your mining party board the");
353                         prout("shuttle craft for the trip back to the Enterprise.");
354                         skip(1);
355                         prout("The short hop begins . . .");
356                         game.state.plnets[iplnet].known=known;
357                         icraft = 1;
358                         skip(1);
359                         landed = -1;
360                         if (consumeTime()) return;
361                         iscraft = 1;
362                         icraft = 0;
363                         if (imine!=0) {
364                                 icrystl = 1;
365                                 cryprob = 0.05;
366                         }
367                         imine = 0;
368                         prout("Trip complete.");
369                         return;
370                 }
371         }
372         else {
373                 /* Kirk on ship */
374                 /* and so is Galileo */
375                 prout("Mining party assembles in the hangar deck,");
376                 prout("ready to board the shuttle craft \"Galileo\".");
377                 skip(1);
378                 prouts("The hangar doors open; the trip begins.");
379                 skip(1);
380                 icraft = 1;
381                 iscraft = 0;
382                 if (consumeTime()) return;
383                 game.state.plnets[iplnet].known = shuttle_down;
384                 landed = 1;
385                 icraft = 0;
386                 prout("Trip complete");
387                 return;
388         }
389 }
390                 
391
392 void deathray(void) {
393         double r = Rand();
394         
395         ididit = 0;
396         skip(1);
397         chew();
398         if (ship != IHE) {
399                 prout("Ye Faerie Queene has no death ray.");
400                 return;
401         }
402         if (nenhere==0) {
403                 prout("Sulu-  \"But Sir, there are no enemies in this quadrant.\"");
404                 return;
405         }
406         if (game.damage[DDRAY] > 0.0) {
407                 prout("Death Ray is damaged.");
408                 return;
409         }
410         prout("Spock-  \"Captain, the 'Experimental Death Ray'");
411         prout("  is highly unpredictible.  Considering the alternatives,");
412         proutn("  are you sure this is wise?\" ");
413         if (ja()==0) return;
414         prout("Spock-  \"Acknowledged.\"");
415         skip(1);
416         ididit=1;
417         prouts("WHOOEE ... WHOOEE ... WHOOEE ... WHOOEE");
418         skip(1);
419         prout("Crew scrambles in emergency preparation.");
420         prout("Spock and Scotty ready the death ray and");
421         prout("prepare to channel all ship's power to the device.");
422         skip(1);
423         prout("Spock-  \"Preparations complete, sir.\"");
424         prout("Kirk-  \"Engage!\"");
425         skip(1);
426         prouts("WHIRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR");
427         skip(1);
428         if (r > .30) {
429                 prouts("Sulu- \"Captain!  It's working!\"");
430                 skip(2);
431                 while (nenhere > 0)
432                         deadkl(game.kx[1],game.ky[1],game.quad[game.kx[1]][game.ky[1]],game.kx[1],game.ky[1]);
433                 prout("Ensign Chekov-  \"Congratulations, Captain!\"");
434                 if (game.state.remkl == 0) finish(FWON);
435                 prout("Spock-  \"Captain, I believe the `Experimental Death Ray'");
436                 if (Rand() <= 0.05) {
437                         prout("   is still operational.\"");
438                 }
439                 else {
440                         prout("   has been rendered nonfunctional.\"");
441                         game.damage[DDRAY] = 39.95;
442                 }
443                 return;
444         }
445         r = Rand();     // Pick failure method 
446         if (r <= .30) {
447                 prouts("Sulu- \"Captain!  It's working!\"");
448                 skip(1);
449                 prouts("***RED ALERT!  RED ALERT!");
450                 skip(1);
451                 prout("***MATTER-ANTIMATTER IMPLOSION IMMINENT!");
452                 skip(1);
453                 prouts("***RED ALERT!  RED A*L********************************");
454                 skip(1);
455                 stars();
456                 prouts("******************   KA-BOOM!!!!   *******************");
457                 skip(1);
458                 kaboom();
459                 return;
460         }
461         if (r <= .55) {
462                 prouts("Sulu- \"Captain!  Yagabandaghangrapl, brachriigringlanbla!\"");
463                 skip(1);
464                 prout("Lt. Uhura-  \"Graaeek!  Graaeek!\"");
465                 skip(1);
466                 prout("Spock-  \"Facinating!  . . . All humans aboard");
467                 prout("  have apparently been transformed into strange mutations.");
468                 prout("  Vulcans do not seem to be affected.");
469                 skip(1);
470                 prout("Kirk-  \"Raauch!  Raauch!\"");
471                 finish(FDRAY);
472                 return;
473         }
474         if (r <= 0.75) {
475                 int i,j;
476                 prouts("Sulu- \"Captain!  It's   --WHAT?!?!\"");
477                 skip(2);
478                 proutn("Spock-  \"I believe the word is");
479                 prouts(" *ASTONISHING*");
480                 prout(" Mr. Sulu.");
481                 for (i=1; i<=10; i++)
482                         for (j=1; j<=10; j++)
483                                 if (game.quad[i][j] == IHDOT) game.quad[i][j] = IHQUEST;
484                 prout("  Captain, our quadrant is now infested with");
485                 prouts(" - - - - - -  *THINGS*.");
486                 skip(1);
487                 prout("  I have no logical explanation.\"");
488                 return;
489         }
490         prouts("Sulu- \"Captain!  The Death Ray is creating tribbles!\"");
491         skip(1);
492         prout("Scotty-  \"There are so many tribbles down here");
493         prout("  in Engineering, we can't move for 'em, Captain.\"");
494         finish(FTRIBBLE);
495         return;
496 }