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