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