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