5 static void getcd(int, int);
8 double angle, deltax, deltay, bigger, x, y,
9 finald, finalx, finaly, stopegy, probf;
10 int trbeam = 0, n, l, ix=0, iy=0, kink, kinks, iquad;
13 prout("Helmsman Sulu- \"Leaving standard orbit.\"");
17 angle = ((15.0 - direc) * 0.5235988);
20 if (fabs(deltax) > fabs(deltay))
21 bigger = fabs(deltax);
23 bigger = fabs(deltay);
28 /* If tractor beam is to occur, don't move full distance */
29 if (game.state.date+Time >= game.future[FTBEAM]) {
32 dist = dist*(game.future[FTBEAM]-game.state.date)/Time + 0.1;
33 Time = game.future[FTBEAM] - game.state.date + 1e-5;
35 /* Move within the quadrant */
36 game.quad[sectx][secty] = IHDOT;
39 n = 10.0*dist*bigger+0.5;
42 for (l = 1; l <= n; l++) {
43 ix = (x += deltax) + 0.5;
44 iy = (y += deltay) + 0.5;
45 if (ix < 1 || ix > 10 || iy < 1 || iy > 10) {
46 /* Leaving quadrant -- allow final enemy attack */
47 /* Don't do it if being pushed by Nova */
48 if (nenhere != 0 && iattak != 2) {
50 for (l = 1; l <= nenhere; l++) {
51 finald = sqrt((ix-game.kx[l])*(double)(ix-game.kx[l]) +
52 (iy-game.ky[l])*(double)(iy-game.ky[l]));
53 game.kavgd[l] = 0.5 * (finald+game.kdist[l]);
56 * Stas Sergeev added the condition
57 * that attacks only happen if Klingons
58 * are present and your skill is > 3.
60 if (skill > 3 && klhere > 0 && game.state.galaxy[quadx][quady] != 1000)
64 /* compute final position -- new quadrant and sector */
65 x = 10*(quadx-1)+sectx;
66 y = 10*(quady-1)+secty;
67 ix = x+10.0*dist*bigger*deltax+0.5;
68 iy = y+10.0*dist*bigger*deltay+0.5;
69 /* check for edge of galaxy */
95 /* Three strikes -- you're out! */
99 prout("\n\rYOU HAVE ATTEMPTED TO CROSS THE NEGATIVE ENERGY BARRIER\n\r"
100 "AT THE EDGE OF THE GALAXY. THE THIRD TIME YOU TRY THIS,\n\r"
101 "YOU WILL BE DESTROYED.\n\r");
103 /* Compute final position in new quadrant */
104 if (trbeam) return; /* Don't bother if we are to be beamed */
107 sectx = ix - 10*(quadx-1);
108 secty = iy - 10*(quady-1);
109 prout("\n\rEntering %s.",
110 cramlc(quadrant, quadx, quady));
111 game.quad[sectx][secty] = ship;
113 if (skill>1) attack(0);
116 iquad = game.quad[ix][iy];
117 if (iquad != IHDOT) {
118 /* object encountered in flight path */
119 stopegy = 50.0*dist/Time;
120 dist=0.1*sqrt((sectx-ix)*(double)(sectx-ix) +
121 (secty-iy)*(double)(secty-iy));
123 case IHT: /* Ram a Tholian */
124 case IHK: /* Ram enemy ship */
131 ram(0, iquad, sectx, secty);
137 prouts("***RED ALERT! RED ALERT!");
141 proutn(" pulled into black hole at ");
142 prout(cramlc(sector, ix, iy));
144 * Getting pulled into a black
145 * hole was certain death in
146 * Almy's original. Stas
147 * Sergeev added a possibility
148 * that you'll get timewarped
152 for (l=1;l<=NDEVICES+1;l++)
153 if (game.damage[l]>0) n++;
154 probf=pow(1.4,(energy+shield)/5000.0-1.0)*
155 pow(1.3,1.0/(n+1)-1.0);
166 proutn(" encounters Tholian web at ");
168 proutn(" blocked by object at ");
169 proutn(cramlc(sector, ix,iy));
171 proutn("Emergency stop required ");
172 prout("%2d units of energy.", (int)stopegy);
174 finalx = x-deltax+0.5;
176 finaly = y-deltay+0.5;
184 goto label100; /* sorry! */
187 dist = 0.1*sqrt((sectx-ix)*(double)(sectx-ix) +
188 (secty-iy)*(double)(secty-iy));
195 /* No quadrant change -- compute new avg enemy distances */
196 game.quad[sectx][secty] = ship;
198 for (l = 1; l <= nenhere; l++) {
199 finald = sqrt((ix-game.kx[l])*(double)(ix-game.kx[l]) +
200 (iy-game.ky[l])*(double)(iy-game.ky[l]));
201 game.kavgd[l] = 0.5 * (finald+game.kdist[l]);
202 game.kdist[l] = finald;
205 if (game.state.galaxy[quadx][quady] != 1000 && iattak == 0)
207 for (l = 1 ; l <= nenhere; l++) game.kavgd[l] = game.kdist[l];
217 if (condit == IHDOCKED && l) {
218 prout("Already docked.");
222 prout("You must first leave standard orbit.");
225 if (basex==0 || abs(sectx-basex) > 1 || abs(secty-basey) > 1) {
227 prout(" not adjacent to base.");
231 if (l) prout("Docked.");
233 if (energy < inenrg) energy = inenrg;
237 if (stdamtim != 1e30 &&
238 (game.future[FCDBAS] < 1e30 || isatb == 1) && iseenit == 0) {
239 /* get attack report from base */
240 prout("Lt. Uhura- \"Captain, an important message from the starbase:\"");
246 static void getcd(int isprobe, int akey) {
247 /* This program originally required input in terms of a (clock)
248 direction and distance. Somewhere in history, it was changed to
249 cartesian coordinates. So we need to convert. I think
250 "manual" input should still be done this way -- it's a real
251 pain if the computer isn't working! Manual mode is still confusing
252 because it involves giving x and y motions, yet the coordinates
253 are always displayed y - x, where +y is downward! */
256 int irowq=quadx, icolq=quady, irows, icols, itemp=0, iprompt=0, key=0;
257 double xi, xj, xk, xl;
258 double deltax, deltay;
261 /* Get course direction and distance. If user types bad values, return
262 with DIREC = -1.0. */
266 if (landed == 1 && !isprobe) {
267 prout("Dummy! You can't leave standard orbit until you");
268 proutn("are back abourt the ");
274 while (automatic == -1) {
275 if (game.damage[DCOMPTR]) {
277 prout("Computer damaged; manual navigation only");
279 prout("Computer damaged; manual movement only");
285 if (isprobe && akey != -1) {
286 /* For probe launch, use pre-scaned value first time */
294 proutn("Manual or automatic- ");
298 else if (key == IHALPHA) {
299 if (isit("manual")) {
304 else if (isit("automatic")) {
317 prout("(Manual navigation assumed.)");
319 prout("(Manual movement assumed.)");
326 while (key == IHEOL) {
328 proutn("Target quadrant or quadrant§or- ");
330 proutn("Destination sector or quadrant§or- ");
349 /* both quadrant and sector specified */
365 /* only quadrant specified -- go to center of dest quad */
376 if (irowq<1 || irowq > 8 || icolq<1 || icolq > 8 ||
377 irows<1 || irows > 10 || icols<1 || icols > 10) {
385 prout("Helmsman Sulu- \"Course locked in for %s.\"",
386 cramlc(sector, irows, icols));
389 else prout("Ensign Chekov- \"Course laid in, Captain.\"");
391 deltax = icolq - quady + 0.1*(icols-secty);
392 deltay = quadx - irowq + 0.1*(sectx-irows);
395 while (key == IHEOL) {
396 proutn("X and Y displacements- ");
414 /* Check for zero movement */
415 if (deltax == 0 && deltay == 0) {
419 if (itemp == 2 && !isprobe) {
421 prout("Helmsman Sulu- \"Aye, Sir.\"");
423 dist = sqrt(deltax*deltax + deltay*deltay);
424 direc = atan2(deltax, deltay)*1.90985932;
425 if (direc < 0.0) direc += 12.0;
437 if (game.damage[DIMPULS]) {
440 prout("Engineer Scott- \"The impulse engines are damaged, Sir.\"");
446 if (direc == -1.0) return;
447 power = 20.0 + 100.0*dist;
452 if (power >= energy) {
453 /* Insufficient power for trip */
455 prout("First Officer Spock- \"Captain, the impulse engines");
456 prout("require 20.0 units to engage, plus 100.0 units per");
458 proutn("quadrant. We can go, therefore, a maximum of %d",
459 (int)(0.01 * (energy-20.0)-0.05));
460 prout(" quadrants.\"");
463 prout("quadrant. They are, therefore, useless.\"");
468 /* Make sure enough time is left for the trip */
470 if (Time >= game.state.remtime) {
471 prout("First Officer Spock- \"Captain, our speed under impulse");
472 prout("power is only 0.95 sectors per stardate. Are you sure");
473 proutn("we dare spend the time?\" ");
474 if (ja() == 0) return;
476 /* Activate impulse engines and pay the cost */
480 power = 20.0 + 100.0*dist;
483 if (energy <= 0) finish(FNRG);
489 int blooey=0, twarp=0, iwarp;
492 if (i!=2) { /* Not WARPX entry */
494 if (game.damage[DWARPEN] > 10.0) {
497 prout("Engineer Scott- \"The impulse engines are damaged, Sir.\"");
500 if (game.damage[DWARPEN] > 0.0 && warpfac > 4.0) {
503 prout("Engineer Scott- \"Sorry, Captain. Until this damage");
504 prout(" is repaired, I can only give you warp 4.\"");
508 /* Read in course and distance */
510 if (direc == -1.0) return;
512 /* Make sure starship has enough energy for the trip */
513 power = (dist+0.05)*warpfac*warpfac*warpfac*(shldup+1);
516 if (power >= energy) {
517 /* Insufficient power for trip */
520 prout("Engineering to bridge--");
521 if (shldup==0 || 0.5*power > energy) {
522 iwarp = pow((energy/(dist+0.05)), 0.333333333);
524 prout("We can't do it, Captain. We haven't the energy.");
527 proutn("We haven't the energy, but we could do it at warp %d", iwarp);
530 prout("if you'll lower the shields.");
537 prout("We haven't the energy to go that far with the shields up.");
541 /* Make sure enough time is left for the trip */
542 Time = 10.0*dist/wfacsq;
543 if (Time >= 0.8*game.state.remtime) {
545 prout("First Officer Spock- \"Captain, I compute that such");
546 proutn(" a trip would require approximately %2.0f",
547 100.0*Time/game.state.remtime);
548 prout(" percent of our");
549 proutn(" remaining time. Are you sure this is wise?\" ");
550 if (ja() == 0) { ididit = 0; Time=0; return;}
555 /* Decide if engine damage will occur */
556 double prob = dist*(6.0-warpfac)*(6.0-warpfac)/66.666666666;
561 /* Decide if time warp will occur */
562 if (0.5*dist*pow(7.0,warpfac-10.0) > Rand()) twarp=1;
564 if (idebug &&warpfac==10 && twarp==0) {
566 proutn("Force time warp? ");
567 if (ja()==1) twarp=1;
570 if (blooey || twarp) {
571 /* If time warp or engine damage, check path */
572 /* If it is obstructed, don't do warp or damage */
573 double angle = ((15.0-direc)*0.5235998);
574 double deltax = -sin(angle);
575 double deltay = cos(angle);
578 if (fabs(deltax) > fabs(deltay))
579 bigger = fabs(deltax);
581 bigger = fabs(deltay);
585 n = 10.0 * dist * bigger +0.5;
588 for (l = 1; l <= n; l++) {
591 if (ix < 1 || ix > 10) break;
594 if (iy < 1 || iy > 10) break;
595 if (game.quad[ix][iy] != IHDOT) {
604 /* Activate Warp Engines and pay the cost */
607 energy -= dist*warpfac*warpfac*warpfac*(shldup+1);
608 if (energy <= 0) finish(FNRG);
609 Time = 10.0*dist/wfacsq;
612 game.damage[DWARPEN] = damfac*(3.0*Rand()+1.0);
614 prout("Engineering to bridge--");
615 prout(" Scott here. The warp engines are damaged.");
616 prout(" We'll have to reduce speed to warp 4.");
628 while ((key=scan()) == IHEOL) {
630 proutn("Warp factor- ");
637 if (game.damage[DWARPEN] > 10.0) {
638 prout("Warp engines inoperative.");
641 if (game.damage[DWARPEN] > 0.0 && aaitem > 4.0) {
642 prout("Engineer Scott- \"I'm doing my best, Captain,\n"
643 " but right now we can only go warp 4.\"");
647 prout("Helmsman Sulu- \"Our top speed is warp 10, Captain.\"");
651 prout("Helmsman Sulu- \"We can't go below warp 1, Captain.\"");
656 wfacsq=warpfac*warpfac;
657 if (warpfac <= oldfac || warpfac <= 6.0) {
658 proutn("Helmsman Sulu- \"Warp factor %d, Captain.\"",
662 if (warpfac < 8.00) {
663 prout("Engineer Scott- \"Aye, but our maximum safe speed is warp 6.\"");
666 if (warpfac == 10.0) {
667 prout("Engineer Scott- \"Aye, Captain, we'll try it.\"");
670 prout("Engineer Scott- \"Aye, Captain, but our engines may not take it.\"");
674 void atover(int igrab) {
675 double power, distreq;
678 /* is captain on planet? */
680 if (game.damage[DTRANSP]) {
684 prout("Scotty rushes to the transporter controls.");
686 prout("But with the shields up it's hopeless.");
689 prouts("His desperate attempt to rescue you . . .");
698 proutn("The crystals mined were ");
699 if (Rand() <= 0.25) {
710 /* Check to see if captain in shuttle craft */
711 if (icraft) finish(FSTRACTOR);
714 /* Inform captain of attempt to reach safety */
718 prouts("***RED ALERT! READ ALERT!");
722 prout(" has stopped in a quadrant containing");
723 prouts(" a supernova.");
726 proutn("***Emergency automatic override attempts to hurl ");
729 prout("safely out of quadrant.");
730 game.starch[quadx][quady] = game.damage[DRADIO] > 0.0 ? game.state.galaxy[quadx][quady]+1000:1;
732 /* Try to use warp engines */
733 if (game.damage[DWARPEN]) {
735 prout("Warp engines damaged.");
739 warpfac = 6.0+2.0*Rand();
740 wfacsq = warpfac * warpfac;
741 prout("Warp factor set to %d", (int)warpfac);
743 dist = power/(warpfac*warpfac*warpfac*(shldup+1));
744 distreq = 1.4142+Rand();
745 if (distreq < dist) dist = distreq;
746 Time = 10.0*dist/wfacsq;
747 direc = 12.0*Rand(); /* How dumb! */
752 /* This is bad news, we didn't leave quadrant. */
755 prout("Insufficient energy to leave quadrant.");
759 /* Repeat if another snova */
760 } while (game.state.galaxy[quadx][quady] == 1000);
761 if (game.state.remkl==0) finish(FWON); /* Snova killed remaining enemy. */
766 prout("***TIME WARP ENTERED.");
767 if (game.state.snap && Rand() < 0.5) {
768 /* Go back in time */
769 prout("You are traveling backwards in time %d stardates.",
770 (int)(game.state.date-game.snapsht.date));
771 game.state = game.snapsht;
773 if (game.state.remcom) {
774 game.future[FTBEAM] = game.state.date + expran(intime/game.state.remcom);
775 game.future[FBATTAK] = game.state.date + expran(0.3*intime);
777 game.future[FSNOVA] = game.state.date + expran(0.5*intime);
778 game.future[FSNAP] = game.state.date +expran(0.25*game.state.remtime); /* next snapshot will
780 if (game.state.nscrem) game.future[FSCMOVE] = 0.2777;
782 game.future[FCDBAS] = game.future[FSCDBAS] = 1e30;
785 /* Make sure Galileo is consistant -- Snapshot may have been taken
786 when on planet, which would give us two Galileos! */
788 for (l = 0; l < inplan; l++) {
789 if (game.state.plnets[l].known == shuttle_down) {
791 if (iscraft==1 && ship==IHE) {
792 prout("Checkov- \"Security reports the Galileo has disappeared, Sir!");
797 /* Likewise, if in the original time the Galileo was abandoned, but
798 was on ship earlier, it would have vanished -- lets restore it */
799 if (iscraft==0 && gotit==0 && game.damage[DSHUTTL] >= 0.0) {
800 prout("Checkov- \"Security reports the Galileo has reappeared in the dock!\"");
804 /* Revert star chart to earlier era, if it was known then*/
805 if (game.damage[DRADIO]==0.0 || stdamtim > game.state.date) {
806 for (l = 1; l <= 8; l++)
807 for (ll = 1; ll <= 8; ll++)
808 if (game.starch[l][ll] > 1)
809 game.starch[l][ll]=game.damage[DRADIO]>0.0 ? game.state.galaxy[l][ll]+1000 :1;
810 prout("Spock has reconstructed a correct star chart from memory");
811 if (game.damage[DRADIO] > 0.0) stdamtim = game.state.date;
815 /* Go forward in time */
816 Time = -0.5*intime*log(Rand());
817 prout("You are traveling forward in time %d stardates.", (int)Time);
818 /* cheat to make sure no tractor beams occur during time warp */
819 game.future[FTBEAM] += Time;
820 game.damage[DRADIO] += Time;
823 events(); /* Stas Sergeev added this -- do pending events */
827 double angle, bigger;
829 /* New code to launch a deep space probe */
834 prout("Engineer Scott- \"We have no more deep space probes, Sir.\"");
836 prout("Ye Faerie Queene has no deep space probes.");
839 if (game.damage[DDSP] != 0.0) {
842 prout("Engineer Scott- \"The probe launcher is damaged, Sir.\"");
845 if (game.future[FDSPROB] != 1e30) {
848 if (game.damage[DRADIO] != 0 && condit != IHDOCKED) {
849 prout("Spock- \"Records show the previous probe has not yet");
850 prout(" reached its destination.\"");
853 prout("Uhura- \"The previous probe is still reporting data, Sir.\"");
859 /* slow mode, so let Kirk know how many probes there are left */
860 prout(nprobes==1 ? "%d probe left." : "%d probes left.", nprobes);
861 proutn("Are you sure you want to fire a probe? ");
866 if (key == IHALPHA && strcmp(citem,"armed") == 0) {
870 else if (key == IHEOL) {
871 proutn("Arm NOVAMAX warhead? ");
875 if (direc == -1.0) return;
877 angle = ((15.0 - direc) * 0.5235988);
878 probeinx = -sin(angle);
879 probeiny = cos(angle);
880 if (fabs(probeinx) > fabs(probeiny))
881 bigger = fabs(probeinx);
883 bigger = fabs(probeiny);
887 proben = 10.0*dist*bigger +0.5;
888 probex = quadx*10 + sectx - 1; // We will use better packing than original
889 probey = quady*10 + secty - 1;
892 game.future[FDSPROB] = game.state.date + 0.01; // Time to move one sector
893 prout("Ensign Chekov- \"The deep space probe is launched, Captain.\"");
899 /* There's more than one way to move in this game! */
900 double ddist, xdist, probf;
901 int line = 0, l, ix, iy;
904 /* Test for conditions which prevent calling for help */
905 if (condit == IHDOCKED) {
906 prout("Lt. Uhura- \"But Captain, we're already docked.\"");
909 if (game.damage[DRADIO] != 0) {
910 prout("Subspace radio damaged.");
913 if (game.state.rembase==0) {
914 prout("Lt. Uhura- \"Captain, I'm not getting any response from Starbase.\"");
918 proutn("You must be aboard the ");
923 /* OK -- call for help from nearest starbase */
926 /* There's one in this quadrant */
927 ddist = sqrt(square(basex-sectx)+square(basey-secty));
931 for (l = 1; l <= game.state.rembase; l++) {
932 xdist=10.0*sqrt(square(game.state.baseqx[l]-quadx)+square(game.state.baseqy[l]-quady));
938 /* Since starbase not in quadrant, set up new quadrant */
939 quadx = game.state.baseqx[line];
940 quady = game.state.baseqy[line];
943 /* dematerialize starship */
944 game.quad[sectx][secty]=IHDOT;
945 proutn("Starbase in %s responds--", cramlc(quadrant, quadx, quady));
948 prout(" dematerializes.");
950 for (l = 1; l <= 5; l++) {
951 ix = basex+3.0*Rand()-1;
952 iy = basey+3.0*Rand()-1;
953 if (ix>=1 && ix<=10 && iy>=1 && iy<=10 && game.quad[ix][iy]==IHDOT) {
954 /* found one -- finish up */
957 game.quad[ix][iy]=IHMATER0;
962 prout("You have been lost in space...");
963 finish(FMATERIALIZE);
966 /* Give starbase three chances to rematerialize starship */
967 probf = pow((1.0 - pow(0.98,ddist)), 0.33333333);
968 for (l = 1; l <= 3; l++) {
970 case 1: proutn("1st"); break;
971 case 2: proutn("2nd"); break;
972 case 3: proutn("3rd"); break;
974 proutn(" attempt to re-materialize ");
977 if (Rand() > probf) break;
979 case 1: game.quad[ix][iy]=IHMATER1;
981 case 2: game.quad[ix][iy]=IHMATER2;
983 case 3: game.quad[ix][iy]=IHQUEST;
992 finish(FMATERIALIZE);
995 game.quad[ix][iy]=ship;
1001 prout("Lt. Uhura- \"Captain, we made it!\"");