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