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