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