textcolor() is now available in the text input manager.
[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         ididit=1;
82 }
83
84 void sensor(void) {
85 #ifdef SERGEEV
86     if (game.damage[DSRSENS] != 0.0) return;
87     if ((plnetx != 0)&&(game.state.plnets[iplnet].known == 0)) {
88 #else
89         skip(1);
90         chew();
91         if (game.damage[DSRSENS] != 0.0) {
92                 prout("Short range sensors damaged.");
93                 return;
94         }
95         if (plnetx == 0) {
96                 prout("No planet in this quadrant.");
97                 return;
98         }
99 #endif /* SERGEEV */
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 #ifdef SERGEEV
112     }
113 #endif /* SERGEEV */
114 }
115
116 void beam(void) {
117         chew();
118         skip(1);
119         if (game.damage[DTRANSP] != 0) {
120                 prout("Transporter damaged.");
121                 if (game.damage[DSHUTTL]==0 && (game.state.plnets[iplnet].known==shuttle_down || iscraft == 1)) {
122                         skip(1);
123                         proutn("Spock-  \"May I suggest the shuttle craft, Sir?\" ");
124                         if (ja() != 0) shuttle();
125                 }
126                 return;
127         }
128         if (inorbit==0) {
129                 crmshp();
130                 prout(" not in standard orbit.");
131                 return;
132         }
133         if (shldup!=0) {
134                 prout("Impossible to transport through shields.");
135                 return;
136         }
137         if (game.state.plnets[iplnet].known==unknown) {
138                 prout("Spock-  \"Captain, we have no information on this planet");
139                 prout("  and Starfleet Regulations clearly state that in this situation");
140                 prout("  you may not go down.\"");
141                 return;
142         }
143         if (landed==1) {
144                 /* Coming from planet */
145                 if (game.state.plnets[iplnet].known==shuttle_down) {
146                         proutn("Spock-  \"Wouldn't you rather take the Galileo?\" ");
147                         if (ja() != 0) {
148                                 chew();
149                                 return;
150                         }
151                         prout("Your crew hides the Galileo to prevent capture by aliens.");
152                 }
153                 prout("Landing party assembled, ready to beam up.");
154                 skip(1);
155                 prout("Kirk whips out communicator...");
156                 prouts("BEEP  BEEP  BEEP");
157                 skip(2);
158                 prout("\"Kirk to enterprise-  Lock on coordinates...energize.\"");
159         }
160         else {
161                 /* Going to planet */
162                 if (game.state.plnets[iplnet].crystals==0) {
163                         prout("Spock-  \"Captain, I fail to see the logic in");
164                         prout("  exploring a planet with no dilithium crystals.");
165                         proutn("  Are you sure this is wise?\" ");
166                         if (ja()==0) {
167                                 chew();
168                                 return;
169                         }
170                 }
171                 prout("Scotty-  \"Transporter room ready, Sir.\"");
172                 skip(1);
173                 prout("Kirk, and landing party prepare to beam down to planet surface.");
174                 skip(1);
175                 prout("Kirk-  \"Energize.\"");
176         }
177         ididit=1;
178         skip(1);
179         prouts("WWHOOOIIIIIRRRRREEEE.E.E.  .  .  .  .   .    .");
180         skip(2);
181         if (Rand() > 0.98) {
182                 prouts("BOOOIIIOOOIIOOOOIIIOIING . . .");
183                 skip(2);
184                 prout("Scotty-  \"Oh my God!  I've lost them.\"");
185                 finish(FLOST);
186                 return;
187         }
188         prouts(".    .   .  .  .  .  .E.E.EEEERRRRRIIIIIOOOHWW");
189         skip(2);
190         prout("Transport complete.");
191         landed = -landed;
192         if (landed==1 && game.state.plnets[iplnet].known==shuttle_down) {
193                 prout("The shuttle craft Galileo is here!");
194         }
195         if (landed!=1 && imine==1) {
196                 icrystl = 1;
197                 cryprob = 0.05;
198         }
199         imine = 0;
200         return;
201 }
202
203 void mine(void) {
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         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*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         double r = Rand();
398         
399         ididit = 0;
400         skip(1);
401         chew();
402         if (ship != IHE) {
403                 prout("Ye Faerie Queene has no death ray.");
404                 return;
405         }
406         if (nenhere==0) {
407                 prout("Sulu-  \"But Sir, there are no enemies in this quadrant.\"");
408                 return;
409         }
410         if (game.damage[DDRAY] > 0.0) {
411                 prout("Death Ray is damaged.");
412                 return;
413         }
414         prout("Spock-  \"Captain, the 'Experimental Death Ray'");
415         prout("  is highly unpredictible.  Considering the alternatives,");
416         proutn("  are you sure this is wise?\" ");
417         if (ja()==0) return;
418         prout("Spock-  \"Acknowledged.\"");
419         skip(1);
420         ididit=1;
421         prouts("WHOOEE ... WHOOEE ... WHOOEE ... WHOOEE");
422         skip(1);
423         prout("Crew scrambles in emergency preparation.");
424         prout("Spock and Scotty ready the death ray and");
425         prout("prepare to channel all ship's power to the device.");
426         skip(1);
427         prout("Spock-  \"Preparations complete, sir.\"");
428         prout("Kirk-  \"Engage!\"");
429         skip(1);
430         prouts("WHIRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR");
431         skip(1);
432         if (r > .30) {
433                 prouts("Sulu- \"Captain!  It's working!\"");
434                 skip(2);
435                 while (nenhere > 0)
436                         deadkl(game.kx[1],game.ky[1],game.quad[game.kx[1]][game.ky[1]],game.kx[1],game.ky[1]);
437                 prout("Ensign Chekov-  \"Congratulations, Captain!\"");
438                 if (game.state.remkl == 0) finish(FWON);
439                 prout("Spock-  \"Captain, I believe the `Experimental Death Ray'");
440                 if (Rand() <= 0.05) {
441                         prout("   is still operational.\"");
442                 }
443                 else {
444                         prout("   has been rendered nonfunctional.\"");
445                         game.damage[DDRAY] = 39.95;
446                 }
447                 return;
448         }
449         r = Rand();     // Pick failure method 
450         if (r <= .30) {
451                 prouts("Sulu- \"Captain!  It's working!\"");
452                 skip(1);
453                 prouts("***RED ALERT!  RED ALERT!");
454                 skip(1);
455                 prout("***MATTER-ANTIMATTER IMPLOSION IMMINENT!");
456                 skip(1);
457                 prouts("***RED ALERT!  RED A*L********************************");
458                 skip(1);
459                 stars();
460                 prouts("******************   KA-BOOM!!!!   *******************");
461                 skip(1);
462                 kaboom();
463                 return;
464         }
465         if (r <= .55) {
466                 prouts("Sulu- \"Captain!  Yagabandaghangrapl, brachriigringlanbla!\"");
467                 skip(1);
468                 prout("Lt. Uhura-  \"Graaeek!  Graaeek!\"");
469                 skip(1);
470                 prout("Spock-  \"Facinating!  . . . All humans aboard");
471                 prout("  have apparently been transformed into strange mutations.");
472                 prout("  Vulcans do not seem to be affected.");
473                 skip(1);
474                 prout("Kirk-  \"Raauch!  Raauch!\"");
475                 finish(FDRAY);
476                 return;
477         }
478         if (r <= 0.75) {
479                 int i,j;
480                 prouts("Sulu- \"Captain!  It's   --WHAT?!?!\"");
481                 skip(2);
482                 proutn("Spock-  \"I believe the word is");
483                 prouts(" *ASTONISHING*");
484                 prout(" Mr. Sulu.");
485                 for (i=1; i<=10; i++)
486                         for (j=1; j<=10; j++)
487                                 if (game.quad[i][j] == IHDOT) game.quad[i][j] = IHQUEST;
488                 prout("  Captain, our quadrant is now infested with");
489                 prouts(" - - - - - -  *THINGS*.");
490                 skip(1);
491                 prout("  I have no logical explanation.\"");
492                 return;
493         }
494         prouts("Sulu- \"Captain!  The Death Ray is creating tribbles!\"");
495         skip(1);
496         prout("Scotty-  \"There are so many tribbles down here");
497         prout("  in Engineering, we can't move for 'em, Captain.\"");
498         finish(FTRIBBLE);
499         return;
500 }