c7fb44008db7a586d625498d87fc16ca4cba2f93
[super-star-trek.git] / src / planets.c
1 #include "sst.h"
2
3 static char *classes[] = {"M","N","O"};
4
5 static int consumeTime(void) 
6 {
7 /* I think most of this avoidance was caused by overlay scheme.
8    Let's see what happens if all events can occur here */
9
10 //  double asave;
11     game.ididit = 1;
12 #if 0
13     /* Don't worry about this */
14     if (scheduled(FTBEAM) <= game.state.date+game.optime && game.state.remcom != 0 && game.condit != IHDOCKED) {
15         /* We are about to be tractor beamed -- operation fails */
16         return 1;
17     }
18 #endif
19 //      asave = scheduled(FSNOVA);
20 //      unschedule(FSNOVA); /* defer supernovas */
21     events();   /* Used to avoid if FSCMOVE is scheduled within time */
22 //      schedule(FSNOVA, asave-game.state.time);
23     /*fails if game over, quadrant super-novas or we've moved to new quadrant*/
24     if (game.alldone || game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova || game.justin != 0) return 1;
25     return 0;
26 }
27
28 void preport(void) 
29 {
30     bool iknow = false;
31     int i;
32     skip(1);
33     chew();
34     prout(_("Spock-  \"Planet report follows, Captain.\""));
35     skip(1);
36     for (i = 0; i < game.inplan; i++) {
37         if ((game.state.plnets[i].known != unknown
38             && game.state.plnets[i].crystals != 0)
39             || (idebug && game.state.plnets[i].w.x !=0)
40             ) {
41             iknow = true;
42             if (idebug && game.state.plnets[i].known==unknown)
43                 proutn("(Unknown) ");
44             proutn(cramlc(quadrant, game.state.plnets[i].w));
45             proutn(_("   class "));
46             proutn(classes[game.state.plnets[i].pclass]);
47             proutn("   ");
48             if (game.state.plnets[i].crystals <= 0) proutn(_("no "));
49             prout(_("dilithium crystals present."));
50             if (game.state.plnets[i].known==shuttle_down) 
51                 prout(_("    Shuttle Craft Galileo on surface."));
52         }
53     }
54     if (iknow==0) prout(_("No information available."));
55 }
56
57 void orbit(void) 
58 {
59     skip(1);
60     chew();
61     if (game.inorbit) {
62         prout(_("Already in standard orbit."));
63         return;
64     }
65     if (damaged(DWARPEN) && damaged(DIMPULS)) {
66         prout(_("Both warp and impulse engines damaged."));
67         return;
68     }
69     if (game.plnet.x == 0 || abs(game.sector.x-game.plnet.x) > 1 || abs(game.sector.y-game.plnet.y) > 1) {
70         crmshp();
71         prout(_(" not adjacent to planet."));
72         skip(1);
73         return;
74     }
75     game.optime = 0.02+0.03*Rand();
76     prout(_("Helmsman Sulu-  \"Entering standard orbit, Sir.\""));
77     newcnd();
78     if (consumeTime()) return;
79     game.height = (1400.0+7200.0*Rand());
80     prout(_("Sulu-  \"Entered orbit at altitude %.2f kilometers.\""), game.height);
81     game.inorbit = true;
82     game.ididit = true;
83 }
84
85 void sensor(void) 
86 {
87     skip(1);
88     chew();
89     if (damaged(DSRSENS)) {
90         prout(_("Short range sensors damaged."));
91         return;
92     }
93     if (!game.plnet.x && (game.options & OPTION_TTY)) {
94         prout(_("Spock- \"No planet in this quadrant, Captain.\""));
95         return;
96     }
97     if ((game.plnet.x != 0)&& (game.state.plnets[game.iplnet].known == unknown)) {
98         prout(_("Spock-  \"Sensor scan for %s-"), cramlc(quadrant, game.quadrant));
99         skip(1);
100         prout(_("         Planet at %s is of class %s."),
101               cramlc(sector,game.plnet),
102               classes[game.state.plnets[game.iplnet].pclass]);
103         if (game.state.plnets[game.iplnet].known==shuttle_down) 
104             prout(_("         Sensors show Galileo still on surface."));
105         proutn(_("         Readings indicate"));
106         if (game.state.plnets[game.iplnet].crystals == 0) proutn(_(" no"));
107         prout(_(" dilithium crystals present.\""));
108         if (game.state.plnets[game.iplnet].known == unknown) game.state.plnets[game.iplnet].known = known;
109     }
110 }
111
112 void beam(void) 
113 {
114     chew();
115     skip(1);
116     if (damaged(DTRANSP)) {
117         prout(_("Transporter damaged."));
118         if (!damaged(DSHUTTL) && (game.state.plnets[game.iplnet].known==shuttle_down || game.iscraft == 1)) {
119             skip(1);
120             proutn(_("Spock-  \"May I suggest the shuttle craft, Sir?\" "));
121             if (ja() == true) shuttle();
122         }
123         return;
124     }
125     if (!game.inorbit) {
126         crmshp();
127         prout(_(" not in standard orbit."));
128         return;
129     }
130     if (game.shldup) {
131         prout(_("Impossible to transport through shields."));
132         return;
133     }
134     if (game.state.plnets[game.iplnet].known==unknown) {
135         prout(_("Spock-  \"Captain, we have no information on this planet"));
136         prout(_("  and Starfleet Regulations clearly state that in this situation"));
137         prout(_("  you may not go down.\""));
138         return;
139     }
140     if (game.landed==1) {
141         /* Coming from planet */
142         if (game.state.plnets[game.iplnet].known==shuttle_down) {
143             proutn(_("Spock-  \"Wouldn't you rather take the Galileo?\" "));
144             if (ja() == true) {
145                 chew();
146                 return;
147             }
148             prout(_("Your crew hides the Galileo to prevent capture by aliens."));
149         }
150         prout(_("Landing party assembled, ready to beam up."));
151         skip(1);
152         prout(_("Kirk whips out communicator..."));
153         prouts(_("BEEP  BEEP  BEEP"));
154         skip(2);
155         prout(_("\"Kirk to enterprise-  Lock on coordinates...energize.\""));
156     }
157     else {
158         /* Going to planet */
159         if (game.state.plnets[game.iplnet].crystals==0) {
160             prout(_("Spock-  \"Captain, I fail to see the logic in"));
161             prout(_("  exploring a planet with no dilithium crystals."));
162             proutn(_("  Are you sure this is wise?\" "));
163             if (ja() == false) {
164                 chew();
165                 return;
166             }
167         }
168         prout(_("Scotty-  \"Transporter room ready, Sir.\""));
169         skip(1);
170         prout(_("Kirk and landing party prepare to beam down to planet surface."));
171         skip(1);
172         prout(_("Kirk-  \"Energize.\""));
173     }
174     game.ididit=1;
175     skip(1);
176     prouts("WWHOOOIIIIIRRRRREEEE.E.E.  .  .  .  .   .    .");
177     skip(2);
178     if (Rand() > 0.98) {
179         prouts("BOOOIIIOOOIIOOOOIIIOIING . . .");
180         skip(2);
181         prout(_("Scotty-  \"Oh my God!  I've lost them.\""));
182         finish(FLOST);
183         return;
184     }
185     prouts(".    .   .  .  .  .  .E.E.EEEERRRRRIIIIIOOOHWW");
186     skip(2);
187     prout(_("Transport complete."));
188     game.landed = -game.landed;
189     if (game.landed==1 && game.state.plnets[game.iplnet].known==shuttle_down) {
190         prout(_("The shuttle craft Galileo is here!"));
191     }
192     if (game.landed!=1 && game.imine==1) {
193         game.icrystl = 1;
194         game.cryprob = 0.05;
195     }
196     game.imine = 0;
197     return;
198 }
199
200 void mine(void) 
201 {
202     skip(1);
203     chew();
204     if (game.landed!= 1) {
205         prout(_("Mining party not on planet."));
206         return;
207     }
208     if (game.state.plnets[game.iplnet].crystals == MINED) {
209         prout(_("This planet has already been strip-mined for dilithium."));
210         return;
211     }
212     else if (game.state.plnets[game.iplnet].crystals == 0) {
213         prout(_("No dilithium crystals on this planet."));
214         return;
215     }
216     if (game.imine == 1) {
217         prout(_("You've already mined enough crystals for this trip."));
218         return;
219     }
220     if (game.icrystl == 1 && game.cryprob == 0.05) {
221         proutn(_("With all those fresh crystals aboard the "));
222         crmshp();
223         skip(1);
224         prout(_("there's no reason to mine more at this time."));
225         return;
226     }
227     game.optime = (0.1+0.2*Rand())*game.state.plnets[game.iplnet].pclass;
228     if (consumeTime()) return;
229     prout(_("Mining operation complete."));
230     game.state.plnets[game.iplnet].crystals = MINED;
231     game.imine = 1;
232     game.ididit=1;
233 }
234
235 void usecrystals(void) 
236 {
237     game.ididit=0;
238     skip(1);
239     chew();
240     if (game.icrystl!=1) {
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=1;
284 }
285
286 void shuttle(void) 
287 {
288     chew();
289     skip(1);
290     if(damaged(DSHUTTL)) {
291         if (game.damage[DSHUTTL] == -1.0) {
292             if (game.inorbit && game.state.plnets[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.plnets[game.iplnet].known != shuttle_down) && game.iscraft != 1) {
309         prout(_("Shuttle craft not currently available."));
310         return;
311     }
312     if (game.landed==-1 && game.state.plnets[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.condit == IHDOCKED) {
317         prout(_("Shuttle craft cannot pass through shields."));
318         return;
319     }
320     if (game.state.plnets[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 == 1) {
339         /* Kirk on planet */
340         if (game.iscraft==1) {
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 = 0;
354             skip(1);
355             if (consumeTime()) return;
356             game.state.plnets[game.iplnet].known=shuttle_down;
357             prout(_("Trip complete."));
358             return;
359         }
360         else {
361             /* Ready to go back to ship */
362             prout(_("You and your mining party board the"));
363             prout(_("shuttle craft for the trip back to the Enterprise."));
364             skip(1);
365             prout(_("The short hop begins . . ."));
366             game.state.plnets[game.iplnet].known=known;
367             game.icraft = 1;
368             skip(1);
369             game.landed = -1;
370             if (consumeTime()) return;
371             game.iscraft = 1;
372             game.icraft = 0;
373             if (game.imine!=0) {
374                 game.icrystl = 1;
375                 game.cryprob = 0.05;
376             }
377             game.imine = 0;
378             prout(_("Trip complete."));
379             return;
380         }
381     }
382     else {
383         /* Kirk on ship */
384         /* and so is Galileo */
385         prout(_("Mining party assembles in the hangar deck,"));
386         prout(_("ready to board the shuttle craft \"Galileo\"."));
387         skip(1);
388         prouts(_("The hangar doors open; the trip begins."));
389         skip(1);
390         game.icraft = 1;
391         game.iscraft = 0;
392         if (consumeTime()) return;
393         game.state.plnets[game.iplnet].known = shuttle_down;
394         game.landed = 1;
395         game.icraft = 0;
396         prout(_("Trip complete"));
397         return;
398     }
399 }
400
401 void deathray(void) 
402 {
403     double dprob, r = Rand();
404         
405     game.ididit = 0;
406     skip(1);
407     chew();
408     if (game.ship != IHE) {
409         prout(_("Ye Faerie Queene has no death ray."));
410         return;
411     }
412     if (game.nenhere==0) {
413         prout(_("Sulu-  \"But Sir, there are no enemies in this quadrant.\""));
414         return;
415     }
416     if (damaged(DDRAY)) {
417         prout(_("Death Ray is damaged."));
418         return;
419     }
420     prout(_("Spock-  \"Captain, the 'Experimental Death Ray'"));
421     prout(_("  is highly unpredictible.  Considering the alternatives,"));
422     proutn(_("  are you sure this is wise?\" "));
423     if (ja() == false) return;
424     prout(_("Spock-  \"Acknowledged.\""));
425     skip(1);
426     game.ididit=1;
427     prouts(_("WHOOEE ... WHOOEE ... WHOOEE ... WHOOEE"));
428     skip(1);
429     prout(_("Crew scrambles in emergency preparation."));
430     prout(_("Spock and Scotty ready the death ray and"));
431     prout(_("prepare to channel all ship's power to the device."));
432     skip(1);
433     prout(_("Spock-  \"Preparations complete, sir.\""));
434     prout(_("Kirk-  \"Engage!\""));
435     skip(1);
436     prouts(_("WHIRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR"));
437     skip(1);
438     dprob = .30;
439     if (game.options & OPTION_PLAIN)
440         dprob = .5;
441     if (r > dprob) {
442         prouts(_("Sulu- \"Captain!  It's working!\""));
443         skip(2);
444         while (game.nenhere > 0)
445             deadkl(game.ks[1], game.quad[game.ks[1].x][game.ks[1].y],game.ks[1].x,game.ks[1].y);
446         prout(_("Ensign Chekov-  \"Congratulations, Captain!\""));
447         if (KLINGREM == 0) finish(FWON);
448         if ((game.options & OPTION_PLAIN) == 0) {
449             prout(_("Spock-  \"Captain, I believe the `Experimental Death Ray'"));
450             if (Rand() <= 0.05) {
451                 prout(_("   is still operational.\""));
452             }
453             else {
454                 prout(_("   has been rendered nonfunctional.\""));
455                 game.damage[DDRAY] = 39.95;
456             }
457         }
458         return;
459     }
460     r = Rand(); // Pick failure method 
461     if (r <= .30) {
462         prouts(_("Sulu- \"Captain!  It's working!\""));
463         skip(1);
464         prouts(_("***RED ALERT!  RED ALERT!"));
465         skip(1);
466         prout(_("***MATTER-ANTIMATTER IMPLOSION IMMINENT!"));
467         skip(1);
468         prouts(_("***RED ALERT!  RED A*L********************************"));
469         skip(1);
470         stars();
471         prouts(_("******************   KA-BOOM!!!!   *******************"));
472         skip(1);
473         kaboom();
474         return;
475     }
476     if (r <= .55) {
477         prouts(_("Sulu- \"Captain!  Yagabandaghangrapl, brachriigringlanbla!\""));
478         skip(1);
479         prout(_("Lt. Uhura-  \"Graaeek!  Graaeek!\""));
480         skip(1);
481         prout(_("Spock-  \"Fascinating!  . . . All humans aboard"));
482         prout(_("  have apparently been transformed into strange mutations."));
483         prout(_("  Vulcans do not seem to be affected."));
484         skip(1);
485         prout(_("Kirk-  \"Raauch!  Raauch!\""));
486         finish(FDRAY);
487         return;
488     }
489     if (r <= 0.75) {
490         int i,j;
491         prouts(_("Sulu- \"Captain!  It's   --WHAT?!?!\""));
492         skip(2);
493         proutn(_("Spock-  \"I believe the word is"));
494         prouts(_(" *ASTONISHING*"));
495         prout(_(" Mr. Sulu."));
496         for_sectors(i)
497             for_sectors(j)
498                 if (game.quad[i][j] == IHDOT) game.quad[i][j] = IHQUEST;
499         prout(_("  Captain, our quadrant is now infested with"));
500         prouts(_(" - - - - - -  *THINGS*."));
501         skip(1);
502         prout(_("  I have no logical explanation.\""));
503         return;
504     }
505     prouts(_("Sulu- \"Captain!  The Death Ray is creating tribbles!\""));
506     skip(1);
507     prout(_("Scotty-  \"There are so many tribbles down here"));
508     prout(_("  in Engineering, we can't move for 'em, Captain.\""));
509     finish(FTRIBBLE);
510     return;
511 }
512
513 char *systemname(int pindx)
514 {
515     static char copy[BUFSIZ];
516     /* the below array should not be static, or it won't gettextize
517      * because of the early initialization. */
518     char *names[NINHAB+1] =
519     {
520         /*
521          * I used <http://www.memory-alpha.org> to find planets
522          * with references in ST:TOS.  Eath and the Alpha Centauri
523          * Colony have been omitted.
524          *
525          * Some planets marked Class G and P here will be displayed as class M
526          * because of the way planets are generated. This is a known bug.
527          */
528         "ERROR",
529         // Federation Worlds
530         _("Andoria (Fesoan)"),  /* several episodes */
531         _("Tellar Prime (Miracht)"),    /* TOS: "Journey to Babel" */
532         _("Vulcan (T'Khasi)"),  /* many episodes */
533         _("Medusa"),            /* TOS: "Is There in Truth No Beauty?" */
534         _("Argelius II (Nelphia)"),/* TOS: "Wolf in the Fold" ("IV" in BSD) */
535         _("Ardana"),            /* TOS: "The Cloud Minders" */
536         _("Catulla (Cendo-Prae)"),      /* TOS: "The Way to Eden" */
537         _("Gideon"),            /* TOS: "The Mark of Gideon" */
538         _("Aldebaran III"),     /* TOS: "The Deadly Years" */
539         _("Alpha Majoris I"),   /* TOS: "Wolf in the Fold" */
540         _("Altair IV"),         /* TOS: "Amok Time */
541         _("Ariannus"),          /* TOS: "Let That Be Your Last Battlefield" */
542         _("Benecia"),           /* TOS: "The Conscience of the King" */
543         _("Beta Niobe I (Sarpeidon)"),  /* TOS: "All Our Yesterdays" */
544         _("Alpha Carinae II"),  /* TOS: "The Ultimate Computer" */
545         _("Capella IV (Kohath)"),       /* TOS: "Friday's Child" (Class G) */
546         _("Daran V"),           /* TOS: "For the World is Hollow and I Have Touched the Sky" */
547         _("Deneb II"),          /* TOS: "Wolf in the Fold" ("IV" in BSD) */
548         _("Eminiar VII"),               /* TOS: "A Taste of Armageddon" */
549         _("Gamma Canaris IV"),  /* TOS: "Metamorphosis" */
550         _("Gamma Tranguli VI (Vaalel)"),        /* TOS: "The Apple" */
551         _("Ingraham B"),                /* TOS: "Operation: Annihilate" */
552         _("Janus IV"),          /* TOS: "The Devil in the Dark" */
553         _("Makus III"),         /* TOS: "The Galileo Seven" */
554         _("Marcos XII"),                /* TOS: "And the Children Shall Lead", */
555         _("Omega IV"),          /* TOS: "The Omega Glory" */
556         _("Regulus V"),         /* TOS: "Amok Time */
557         _("Deneva"),            /* TOS: "Operation -- Annihilate!" */
558         /* Worlds from BSD Trek */
559         _("Rigel II"),          /* TOS: "Shore Leave" ("III" in BSD) */
560         _("Beta III"),          /* TOS: "The Return of the Archons" */
561         _("Triacus"),           /* TOS: "And the Children Shall Lead", */
562         _("Exo III"),           /* TOS: "What Are Little Girls Made Of?" (Class P) */
563 #if 0
564         // Others
565         _("Hansen's Planet"),   /* TOS: "The Galileo Seven" */
566         _("Taurus IV"),         /* TOS: "The Galileo Seven" (class G) */
567         _("Antos IV (Doraphane)"),      /* TOS: "Whom Gods Destroy", "Who Mourns for Adonais?" */
568         _("Izar"),                      /* TOS: "Whom Gods Destroy" */
569         _("Tiburon"),           /* TOS: "The Way to Eden" */
570         _("Merak II"),          /* TOS: "The Cloud Minders" */ 
571         _("Coridan (Desotriana)"),      /* TOS: "Journey to Babel" */
572         _("Iotia"),             /* TOS: "A Piece of the Action" */
573 #endif
574     };
575
576     strcpy(copy, names[pindx]);
577     return copy;
578 }