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