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