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