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