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