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