More int-to-boolean cleanup. Make the FDISTR event work.
[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 (game.damage[DWARPEN] != 0 && game.damage[DIMPULS] != 0) {
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 (game.damage[DSRSENS] != 0.0) {
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 (game.damage[DTRANSP] != 0) {
117         prout("Transporter damaged.");
118         if (game.damage[DSHUTTL]==0 && (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() != 0) 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() != 0) {
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()==0) {
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 game.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()==0) {
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(game.damage[DSHUTTL] != 0.0) {
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 prout("Shuttle craft is now serving Big Macs.");
300         return;
301     }
302     if (!game.inorbit) {
303         crmshp();
304         prout(" not in standard orbit.");
305         return;
306     }
307     if ((game.state.plnets[game.iplnet].known != shuttle_down) && game.iscraft != 1) {
308         prout("Shuttle craft not currently available.");
309         return;
310     }
311     if (game.landed==-1 && game.state.plnets[game.iplnet].known==shuttle_down) {
312         prout("You will have to beam down to retrieve the shuttle craft.");
313         return;
314     }
315     if (game.shldup || game.condit == IHDOCKED) {
316         prout("Shuttle craft cannot pass through shields.");
317         return;
318     }
319     if (game.state.plnets[game.iplnet].known==unknown) {
320         prout("Spock-  \"Captain, we have no information on this planet");
321         prout("  and Starfleet Regulations clearly state that in this situation");
322         prout("  you may not fly down.\"");
323         return;
324     }
325     game.optime = 3.0e-5*game.height;
326     if (game.optime >= 0.8*game.state.remtime) {
327         prout("First Officer Spock-  \"Captain, I compute that such");
328         proutn("  a maneuver would require approximately 2d%% of our",
329                (int)(100*game.optime/game.state.remtime));
330         prout("remaining time.");
331         proutn("Are you sure this is wise?\" ");
332         if (ja()==0) {
333             game.optime = 0.0;
334             return;
335         }
336     }
337     if (game.landed == 1) {
338         /* Kirk on planet */
339         if (game.iscraft==1) {
340             /* Galileo on ship! */
341             if (game.damage[DTRANSP]==0) {
342                 proutn("Spock-  \"Would you rather use the transporter?\" ");
343                 if (ja() != 0) {
344                     beam();
345                     return;
346                 }
347                 proutn("Shuttle crew");
348             }
349             else
350                 proutn("Rescue party");
351             prout(" boards Galileo and swoops toward planet surface.");
352             game.iscraft = 0;
353             skip(1);
354             if (consumeTime()) return;
355             game.state.plnets[game.iplnet].known=shuttle_down;
356             prout("Trip complete.");
357             return;
358         }
359         else {
360             /* Ready to go back to ship */
361             prout("You and your mining party board the");
362             prout("shuttle craft for the trip back to the Enterprise.");
363             skip(1);
364             prout("The short hop begins . . .");
365             game.state.plnets[game.iplnet].known=known;
366             game.icraft = 1;
367             skip(1);
368             game.landed = -1;
369             if (consumeTime()) return;
370             game.iscraft = 1;
371             game.icraft = 0;
372             if (game.imine!=0) {
373                 game.icrystl = 1;
374                 game.cryprob = 0.05;
375             }
376             game.imine = 0;
377             prout("Trip complete.");
378             return;
379         }
380     }
381     else {
382         /* Kirk on ship */
383         /* and so is Galileo */
384         prout("Mining party assembles in the hangar deck,");
385         prout("ready to board the shuttle craft \"Galileo\".");
386         skip(1);
387         prouts("The hangar doors open; the trip begins.");
388         skip(1);
389         game.icraft = 1;
390         game.iscraft = 0;
391         if (consumeTime()) return;
392         game.state.plnets[game.iplnet].known = shuttle_down;
393         game.landed = 1;
394         game.icraft = 0;
395         prout("Trip complete");
396         return;
397     }
398 }
399
400 void deathray(void) 
401 {
402     double dprob, r = Rand();
403         
404     game.ididit = 0;
405     skip(1);
406     chew();
407     if (game.ship != IHE) {
408         prout("Ye Faerie Queene has no death ray.");
409         return;
410     }
411     if (game.nenhere==0) {
412         prout("Sulu-  \"But Sir, there are no enemies in this quadrant.\"");
413         return;
414     }
415     if (game.damage[DDRAY] > 0.0) {
416         prout("Death Ray is damaged.");
417         return;
418     }
419     prout("Spock-  \"Captain, the 'Experimental Death Ray'");
420     prout("  is highly unpredictible.  Considering the alternatives,");
421     proutn("  are you sure this is wise?\" ");
422     if (ja()==0) return;
423     prout("Spock-  \"Acknowledged.\"");
424     skip(1);
425     game.ididit=1;
426     prouts("WHOOEE ... WHOOEE ... WHOOEE ... WHOOEE");
427     skip(1);
428     prout("Crew scrambles in emergency preparation.");
429     prout("Spock and Scotty ready the death ray and");
430     prout("prepare to channel all ship's power to the device.");
431     skip(1);
432     prout("Spock-  \"Preparations complete, sir.\"");
433     prout("Kirk-  \"Engage!\"");
434     skip(1);
435     prouts("WHIRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR");
436     skip(1);
437     dprob = .30;
438     if (game.options & OPTION_PLAIN)
439         dprob = .5;
440     if (r > dprob) {
441         prouts("Sulu- \"Captain!  It's working!\"");
442         skip(2);
443         while (game.nenhere > 0)
444             deadkl(game.ks[1], game.quad[game.ks[1].x][game.ks[1].y],game.ks[1].x,game.ks[1].y);
445         prout("Ensign Chekov-  \"Congratulations, Captain!\"");
446         if (KLINGREM == 0) finish(FWON);
447         if ((game.options & OPTION_PLAIN) == 0) {
448             prout("Spock-  \"Captain, I believe the `Experimental Death Ray'");
449             if (Rand() <= 0.05) {
450                 prout("   is still operational.\"");
451             }
452             else {
453                 prout("   has been rendered nonfunctional.\"");
454                 game.damage[DDRAY] = 39.95;
455             }
456         }
457         return;
458     }
459     r = Rand(); // Pick failure method 
460     if (r <= .30) {
461         prouts("Sulu- \"Captain!  It's working!\"");
462         skip(1);
463         prouts("***RED ALERT!  RED ALERT!");
464         skip(1);
465         prout("***MATTER-ANTIMATTER IMPLOSION IMMINENT!");
466         skip(1);
467         prouts("***RED ALERT!  RED A*L********************************");
468         skip(1);
469         stars();
470         prouts("******************   KA-BOOM!!!!   *******************");
471         skip(1);
472         kaboom();
473         return;
474     }
475     if (r <= .55) {
476         prouts("Sulu- \"Captain!  Yagabandaghangrapl, brachriigringlanbla!\"");
477         skip(1);
478         prout("Lt. Uhura-  \"Graaeek!  Graaeek!\"");
479         skip(1);
480         prout("Spock-  \"Fascinating!  . . . All humans aboard");
481         prout("  have apparently been transformed into strange mutations.");
482         prout("  Vulcans do not seem to be affected.");
483         skip(1);
484         prout("Kirk-  \"Raauch!  Raauch!\"");
485         finish(FDRAY);
486         return;
487     }
488     if (r <= 0.75) {
489         int i,j;
490         prouts("Sulu- \"Captain!  It's   --WHAT?!?!\"");
491         skip(2);
492         proutn("Spock-  \"I believe the word is");
493         prouts(" *ASTONISHING*");
494         prout(" Mr. Sulu.");
495         for_sectors(i)
496             for_sectors(j)
497                 if (game.quad[i][j] == IHDOT) game.quad[i][j] = IHQUEST;
498         prout("  Captain, our quadrant is now infested with");
499         prouts(" - - - - - -  *THINGS*.");
500         skip(1);
501         prout("  I have no logical explanation.\"");
502         return;
503     }
504     prouts("Sulu- \"Captain!  The Death Ray is creating tribbles!\"");
505     skip(1);
506     prout("Scotty-  \"There are so many tribbles down here");
507     prout("  in Engineering, we can't move for 'em, Captain.\"");
508     finish(FTRIBBLE);
509     return;
510 }
511
512 char *systemname(int pindx)
513 {
514     static char *names[NINHAB] =
515     {
516         /*
517          * This started out life as the BSD Trek inhabited-planets list,
518          * but I used <http://www.memory-alpha.org> to weed out planets
519          * with no references in ST:TOS and to fill it out again to the
520          * required length from "The Worlds of The Federation" list,
521          * <http://memory-alpha.org/en/wiki/The_Worlds_of_the_Federation>.
522          * Some misspellings have been silently corrected.  (To be
523          * fair, there was no Web when Eric Allman did his list.)
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         // Added Federation Worlds
530         "Deneva",               /* TOS: "Operation -- Annihilate!" */
531         "Eminiar VII",          /* TOS: "A Taste of Armageddon" */
532         "Hansen's Planet",      /* TOS: "The Galileo Seven" */
533         "Taurus IV",            /* TOS: "The Galileo Seven" (class G) */
534         "Aldebaran III",        /* TOS: "The Deadly Years" */
535         "Vulcan (T'Khasi)",     /* many episodes */
536         "Tellar Prime (Miracht)",       /* TOS: "Journey to Babel" */
537         "Andoria (Fesoan)",     /* several episodes */
538         "Antos IV (Doraphane)", /* TOS: "Whom Gods Destroy", "Who Mourns for Adonais?" */
539         "Catulla (Cendo-Prae)", /* TOS: "The Way to Eden" */
540         "Izar",                 /* TOS: "Whom Gods Destroy" */
541         "Tiburon",              /* TOS: "The Way to Eden" */
542         "Merak II",             /* TOS: "The Cloud Minders" */
543         "Argelius II (Nelphia)",        /* TOS: "Wolf in the Fold" ("IV" in BSD) */
544         "Daran V",              /* TOS: "For the World is Hollow and I Have Touched the Sky" */
545         "Medusa",               /* TOS: "Is There in Truth No Beauty?" */
546         "Coridan (Desotriana)", /* TOS: "Journey to Babel" */
547         "Berengaria IV",        /* TOS: "This Side of Paradise" */
548         "Capella IV (Kohath)",  /* TOS: "Friday's Child" (Class G) */
549         "Gideon",               /* TOS: "The Mark of Gideon" */
550         "Iotia",                /* TOS: "A Piece of the Action" */
551         /* Worlds from BSD Trek */
552         //"Talos IV",           /* TOS: "The Cage" (interdicted world) */
553         "Rigel II",             /* TOS: "Shore Leave" ("III" in BSD) */
554         "Deneb II",             /* TOS: "Wolf in the Fold" ("IV" in BSD) */
555         //"Canopus V",          /* noncanonical */
556         //"Icarus I",           /* noncanonical */
557         //"Prometheus II",      /* noncanonical */
558         //"Omega VII",          /* noncanonical */
559         //"Elysium I",          /* noncanonical */
560         "Scalos IV",            /* TOS: "Wink of an Eye" */
561         //"Procyon IV",         /* noncanonical */
562         //"Arachnid I",         /* noncanonical */
563         //"Argo VIII",          /* noncanonical */
564         //"Triad III",          /* noncanonical */
565         //"Echo IV",            /* noncanonical */
566         //"Nimrod III",         /* noncanonical */
567         //"Nemisis IV",         /* noncanonical */
568         //"Centarurus I",       /* noncanonical */
569         //"Kronos III",         /* noncanonical */
570         //"Spectros V",         /* noncanonical */
571         "Beta III",             /* TOS: "The Return of the Archons" */
572         "Gamma Tranguli VI (Vaalel)",   /* TOS: "The Apple" */
573         "Pyris VII",            /* TOS: "Catspaw" ("III" in BSD) */
574         "Triacus",              /* TOS: "And the Children Shall Lead", */
575         "Marcos XII",           /* TOS: "And the Children Shall Lead", */
576         //"Kaland",             /* noncanonical */
577         "Ardana",               /* TOS: "The Cloud Minders" */
578         //"Stratos",            /* noncanonical */
579         //"Eden",               /* TOS: "The Way to Eden" (in Romulan space) */
580         //"Arrikis",            /* noncanonical */
581         //"Epsilon Eridani IV", /* noncanonical */
582         "Exo III",              /* TOS: "What Are Little Girls Made Of?" (Class P) */
583     };
584
585     return names[pindx];
586 }