4 static void getcd(int, int);
7 double angle, deltax, deltay, bigger, x, y,
8 finald, finalx, finaly, stopegy, probf;
9 int trbeam = 0, n, l, ix=0, iy=0, kink, kinks, iquad;
12 prout("Helmsman Sulu- \"Leaving standard orbit.\"");
16 angle = ((15.0 - direc) * 0.5235988);
19 if (fabs(deltax) > fabs(deltay))
20 bigger = fabs(deltax);
22 bigger = fabs(deltay);
27 /* If tractor beam is to occur, don't move full distance */
28 if (game.state.date+Time >= game.future[FTBEAM]) {
31 dist = dist*(game.future[FTBEAM]-game.state.date)/Time + 0.1;
32 Time = game.future[FTBEAM] - game.state.date + 1e-5;
34 /* Move within the quadrant */
35 game.quad[sectx][secty] = IHDOT;
38 n = 10.0*dist*bigger+0.5;
41 for (l = 1; l <= n; l++) {
42 ix = (x += deltax) + 0.5;
43 iy = (y += deltay) + 0.5;
44 if (ix < 1 || ix > 10 || iy < 1 || iy > 10) {
45 /* Leaving quadrant -- allow final enemy attack */
46 /* Don't do it if being pushed by Nova */
47 if (nenhere != 0 && iattak != 2) {
49 for (l = 1; l <= nenhere; l++) {
50 finald = sqrt((ix-game.kx[l])*(double)(ix-game.kx[l]) +
51 (iy-game.ky[l])*(double)(iy-game.ky[l]));
52 game.kavgd[l] = 0.5 * (finald+game.kdist[l]);
54 if (game.state.galaxy[quadx][quady] != 1000) attack(0);
57 /* compute final position -- new quadrant and sector */
58 x = 10*(quadx-1)+sectx;
59 y = 10*(quady-1)+secty;
60 ix = x+10.0*dist*bigger*deltax+0.5;
61 iy = y+10.0*dist*bigger*deltay+0.5;
62 /* check for edge of galaxy */
88 /* Three strikes -- you're out! */
92 prout("\nYOU HAVE ATTEMPTED TO CROSS THE NEGATIVE ENERGY BARRIER\n"
93 "AT THE EDGE OF THE GALAXY. THE THIRD TIME YOU TRY THIS,\n"
94 "YOU WILL BE DESTROYED.\n");
96 /* Compute final position in new quadrant */
97 if (trbeam) return; /* Don't bother if we are to be beamed */
100 sectx = ix - 10*(quadx-1);
101 secty = iy - 10*(quady-1);
102 proutn("\n\rEntering %s.",
103 cramlc(quadrant, quadx, quady));
104 game.quad[sectx][secty] = ship;
106 if (skill>1) attack(0);
109 iquad = game.quad[ix][iy];
110 if (iquad != IHDOT) {
111 /* object encountered in flight path */
112 stopegy = 50.0*dist/Time;
113 dist=0.1*sqrt((sectx-ix)*(double)(sectx-ix) +
114 (secty-iy)*(double)(secty-iy));
116 case IHT: /* Ram a Tholian */
117 case IHK: /* Ram enemy ship */
124 ram(0, iquad, sectx, secty);
130 prouts("***RED ALERT! RED ALERT!");
134 proutn(" pulled into black hole at ");
135 prout(cramlc(sector, ix, iy));
137 * Getting pulled into a black
138 * hole was certain death in
139 * Almy's original. Stas
140 * Sergeev added a possibility
141 * that you'll get timewarped
145 for (l=1;l<=NDEVICES+1;l++)
146 if (game.damage[l]>0) n++;
147 probf=pow(1.4,(energy+shield)/5000.0-1.0)*
148 pow(1.3,1.0/(n+1)-1.0);
159 proutn(" encounters Tholian web at ");
161 proutn(" blocked by object at ");
162 proutn(cramlc(sector, ix,iy));
164 proutn("Emergency stop required ");
165 prout("%2d units of energy.", (int)stopegy);
167 finalx = x-deltax+0.5;
169 finaly = y-deltay+0.5;
177 goto label100; /* sorry! */
180 dist = 0.1*sqrt((sectx-ix)*(double)(sectx-ix) +
181 (secty-iy)*(double)(secty-iy));
188 /* No quadrant change -- compute new avg enemy distances */
189 game.quad[sectx][secty] = ship;
191 for (l = 1; l <= nenhere; l++) {
192 finald = sqrt((ix-game.kx[l])*(double)(ix-game.kx[l]) +
193 (iy-game.ky[l])*(double)(iy-game.ky[l]));
194 game.kavgd[l] = 0.5 * (finald+game.kdist[l]);
195 game.kdist[l] = finald;
198 if (game.state.galaxy[quadx][quady] != 1000 && iattak == 0)
200 for (l = 1 ; l <= nenhere; l++) game.kavgd[l] = game.kdist[l];
212 if (condit == IHDOCKED && l) {
213 prout("Already docked.");
217 prout("You must first leave standard orbit.");
220 if (basex==0 || abs(sectx-basex) > 1 || abs(secty-basey) > 1) {
222 prout(" not adjacent to base.");
226 if (l) prout("Docked.");
228 if (energy < inenrg) energy = inenrg;
232 if (stdamtim != 1e30 &&
233 (game.future[FCDBAS] < 1e30 || isatb == 1) && iseenit == 0) {
234 /* get attack report from base */
235 prout("Lt. Uhura- \"Captain, an important message from the starbase:\"");
241 static void getcd(int isprobe, int akey) {
242 /* This program originally required input in terms of a (clock)
243 direction and distance. Somewhere in history, it was changed to
244 cartesian coordinates. So we need to convert. I think
245 "manual" input should still be done this way -- it's a real
246 pain if the computer isn't working! Manual mode is still confusing
247 because it involves giving x and y motions, yet the coordinates
248 are always displayed y - x, where +y is downward! */
251 int irowq=quadx, icolq=quady, irows, icols, itemp=0, iprompt=0, key=0;
252 double xi, xj, xk, xl;
253 double deltax, deltay;
256 /* Get course direction and distance. If user types bad values, return
257 with DIREC = -1.0. */
261 if (landed == 1 && !isprobe) {
262 prout("Dummy! You can't leave standard orbit until you");
263 proutn("are back abourt the ");
269 while (automatic == -1) {
270 if (game.damage[DCOMPTR]) {
272 prout("Computer damaged; manual navigation only");
274 prout("Computer damaged; manual movement only");
280 if (isprobe && akey != -1) {
281 /* For probe launch, use pre-scaned value first time */
289 proutn("Manual or automatic- ");
293 else if (key == IHALPHA) {
294 if (isit("manual")) {
299 else if (isit("automatic")) {
312 prout("(Manual navigation assumed.)");
314 prout("(Manual movement assumed.)");
321 while (key == IHEOL) {
323 proutn("Target quadrant or quadrant§or- ");
325 proutn("Destination sector or quadrant§or- ");
344 /* both quadrant and sector specified */
360 /* only quadrant specified -- go to center of dest quad */
371 if (irowq<1 || irowq > 8 || icolq<1 || icolq > 8 ||
372 irows<1 || irows > 10 || icols<1 || icols > 10) {
380 proutn("Helmsman Sulu- \"Course locked in for %s.\"",
381 cramlc(sector, irows, icols));
384 else prout("Ensign Chekov- \"Course laid in, Captain.\"");
386 deltax = icolq - quady + 0.1*(icols-secty);
387 deltay = quadx - irowq + 0.1*(sectx-irows);
390 while (key == IHEOL) {
391 proutn("X and Y displacements- ");
409 /* Check for zero movement */
410 if (deltax == 0 && deltay == 0) {
414 if (itemp == 2 && !isprobe) {
416 prout("Helmsman Sulu- \"Aye, Sir.\"");
418 dist = sqrt(deltax*deltax + deltay*deltay);
419 direc = atan2(deltax, deltay)*1.90985932;
420 if (direc < 0.0) direc += 12.0;
432 if (game.damage[DIMPULS]) {
435 prout("Engineer Scott- \"The impulse engines are damaged, Sir.\"");
441 if (direc == -1.0) return;
442 power = 20.0 + 100.0*dist;
447 if (power >= energy) {
448 /* Insufficient power for trip */
450 prout("First Officer Spock- \"Captain, the impulse engines");
451 prout("require 20.0 units to engage, plus 100.0 units per");
453 proutn("quadrant. We can go, therefore, a maximum of %d",
454 (int)(0.01 * (energy-20.0)-0.05));
455 prout(" quadrants.\"");
458 prout("quadrant. They are, therefore, useless.\"");
463 /* Make sure enough time is left for the trip */
465 if (Time >= game.state.remtime) {
466 prout("First Officer Spock- \"Captain, our speed under impulse");
467 prout("power is only 0.95 sectors per stardate. Are you sure");
468 proutn("we dare spend the time?\" ");
469 if (ja() == 0) return;
471 /* Activate impulse engines and pay the cost */
475 power = 20.0 + 100.0*dist;
478 if (energy <= 0) finish(FNRG);
484 int blooey=0, twarp=0, iwarp;
487 if (i!=2) { /* Not WARPX entry */
489 if (game.damage[DWARPEN] > 10.0) {
492 prout("Engineer Scott- \"The impulse engines are damaged, Sir.\"");
495 if (game.damage[DWARPEN] > 0.0 && warpfac > 4.0) {
498 prout("Engineer Scott- \"Sorry, Captain. Until this damage");
499 prout(" is repaired, I can only give you warp 4.\"");
503 /* Read in course and distance */
505 if (direc == -1.0) return;
507 /* Make sure starship has enough energy for the trip */
508 power = (dist+0.05)*warpfac*warpfac*warpfac*(shldup+1);
511 if (power >= energy) {
512 /* Insufficient power for trip */
515 prout("Engineering to bridge--");
516 if (shldup==0 || 0.5*power > energy) {
517 iwarp = pow((energy/(dist+0.05)), 0.333333333);
519 prout("We can't do it, Captain. We haven't the energy.");
522 proutn("We haven't the energy, but we could do it at warp %d", iwarp);
525 prout("if you'll lower the shields.");
532 prout("We haven't the energy to go that far with the shields up.");
536 /* Make sure enough time is left for the trip */
537 Time = 10.0*dist/wfacsq;
538 if (Time >= 0.8*game.state.remtime) {
540 prout("First Officer Spock- \"Captain, I compute that such");
541 proutn(" a trip would require approximately %2.0f",
542 100.0*Time/game.state.remtime);
543 prout(" percent of our");
544 proutn(" remaining time. Are you sure this is wise?\" ");
545 if (ja() == 0) { ididit = 0; Time=0; return;}
550 /* Decide if engine damage will occur */
551 double prob = dist*(6.0-warpfac)*(6.0-warpfac)/66.666666666;
556 /* Decide if time warp will occur */
557 if (0.5*dist*pow(7.0,warpfac-10.0) > Rand()) twarp=1;
559 if (idebug &&warpfac==10 && twarp==0) {
561 proutn("Force time warp? ");
562 if (ja()==1) twarp=1;
565 if (blooey || twarp) {
566 /* If time warp or engine damage, check path */
567 /* If it is obstructed, don't do warp or damage */
568 double angle = ((15.0-direc)*0.5235998);
569 double deltax = -sin(angle);
570 double deltay = cos(angle);
573 if (fabs(deltax) > fabs(deltay))
574 bigger = fabs(deltax);
576 bigger = fabs(deltay);
580 n = 10.0 * dist * bigger +0.5;
583 for (l = 1; l <= n; l++) {
586 if (ix < 1 || ix > 10) break;
589 if (iy < 1 || iy > 10) break;
590 if (game.quad[ix][iy] != IHDOT) {
599 /* Activate Warp Engines and pay the cost */
602 energy -= dist*warpfac*warpfac*warpfac*(shldup+1);
603 if (energy <= 0) finish(FNRG);
604 Time = 10.0*dist/wfacsq;
607 game.damage[DWARPEN] = damfac*(3.0*Rand()+1.0);
609 prout("Engineering to bridge--");
610 prout(" Scott here. The warp engines are damaged.");
611 prout(" We'll have to reduce speed to warp 4.");
623 while ((key=scan()) == IHEOL) {
625 proutn("Warp factor- ");
632 if (game.damage[DWARPEN] > 10.0) {
633 prout("Warp engines inoperative.");
636 if (game.damage[DWARPEN] > 0.0 && aaitem > 4.0) {
637 prout("Engineer Scott- \"I'm doing my best, Captain,\n"
638 " but right now we can only go warp 4.\"");
642 prout("Helmsman Sulu- \"Our top speed is warp 10, Captain.\"");
646 prout("Helmsman Sulu- \"We can't go below warp 1, Captain.\"");
651 wfacsq=warpfac*warpfac;
652 if (warpfac <= oldfac || warpfac <= 6.0) {
653 proutn("Helmsman Sulu- \"Warp factor %d, Captain.\"",
657 if (warpfac < 8.00) {
658 prout("Engineer Scott- \"Aye, but our maximum safe speed is warp 6.\"");
661 if (warpfac == 10.0) {
662 prout("Engineer Scott- \"Aye, Captain, we'll try it.\"");
665 prout("Engineer Scott- \"Aye, Captain, but our engines may not take it.\"");
669 void atover(int igrab) {
670 double power, distreq;
673 /* is captain on planet? */
675 if (game.damage[DTRANSP]) {
679 prout("Scotty rushes to the transporter controls.");
681 prout("But with the shields up it's hopeless.");
684 prouts("His desperate attempt to rescue you . . .");
693 proutn("The crystals mined were ");
694 if (Rand() <= 0.25) {
705 /* Check to see if captain in shuttle craft */
706 if (icraft) finish(FSTRACTOR);
709 /* Inform captain of attempt to reach safety */
713 prouts("***RED ALERT! READ ALERT!");
717 prout(" has stopped in a quadrant containing");
718 prouts(" a supernova.");
721 proutn("***Emergency automatic override attempts to hurl ");
724 prout("safely out of quadrant.");
725 game.starch[quadx][quady] = game.damage[DRADIO] > 0.0 ? game.state.galaxy[quadx][quady]+1000:1;
727 /* Try to use warp engines */
728 if (game.damage[DWARPEN]) {
730 prout("Warp engines damaged.");
734 warpfac = 6.0+2.0*Rand();
735 wfacsq = warpfac * warpfac;
736 prout("Warp factor set to %d", (int)warpfac);
738 dist = power/(warpfac*warpfac*warpfac*(shldup+1));
739 distreq = 1.4142+Rand();
740 if (distreq < dist) dist = distreq;
741 Time = 10.0*dist/wfacsq;
742 direc = 12.0*Rand(); /* How dumb! */
747 /* This is bad news, we didn't leave quadrant. */
750 prout("Insufficient energy to leave quadrant.");
754 /* Repeat if another snova */
755 } while (game.state.galaxy[quadx][quady] == 1000);
756 if (game.state.remkl==0) finish(FWON); /* Snova killed remaining enemy. */
761 prout("***TIME WARP ENTERED.");
762 if (game.state.snap && Rand() < 0.5) {
763 /* Go back in time */
764 prout("You are traveling backwards in time %d stardates.",
765 (int)(game.state.date-game.snapsht.date));
766 game.state = game.snapsht;
768 if (game.state.remcom) {
769 game.future[FTBEAM] = game.state.date + expran(intime/game.state.remcom);
770 game.future[FBATTAK] = game.state.date + expran(0.3*intime);
772 game.future[FSNOVA] = game.state.date + expran(0.5*intime);
773 game.future[FSNAP] = game.state.date +expran(0.25*game.state.remtime); /* next snapshot will
775 if (game.state.nscrem) game.future[FSCMOVE] = 0.2777;
777 game.future[FCDBAS] = game.future[FSCDBAS] = 1e30;
780 /* Make sure Galileo is consistant -- Snapshot may have been taken
781 when on planet, which would give us two Galileos! */
783 for (l = 0; l < inplan; l++) {
784 if (game.state.plnets[l].known == shuttle_down) {
786 if (iscraft==1 && ship==IHE) {
787 prout("Checkov- \"Security reports the Galileo has disappeared, Sir!");
792 /* Likewise, if in the original time the Galileo was abandoned, but
793 was on ship earlier, it would have vanished -- lets restore it */
794 if (iscraft==0 && gotit==0 && game.damage[DSHUTTL] >= 0.0) {
795 prout("Checkov- \"Security reports the Galileo has reappeared in the dock!\"");
799 /* Revert star chart to earlier era, if it was known then*/
800 if (game.damage[DRADIO]==0.0 || stdamtim > game.state.date) {
801 for (l = 1; l <= 8; l++)
802 for (ll = 1; ll <= 8; ll++)
803 if (game.starch[l][ll] > 1)
804 game.starch[l][ll]=game.damage[DRADIO]>0.0 ? game.state.galaxy[l][ll]+1000 :1;
805 prout("Spock has reconstructed a correct star chart from memory");
806 if (game.damage[DRADIO] > 0.0) stdamtim = game.state.date;
810 /* Go forward in time */
811 Time = -0.5*intime*log(Rand());
812 prout("You are traveling forward in time %d stardates.", (int)Time);
813 /* cheat to make sure no tractor beams occur during time warp */
814 game.future[FTBEAM] += Time;
815 game.damage[DRADIO] += Time;
824 double angle, bigger;
826 /* New code to launch a deep space probe */
831 prout("Engineer Scott- \"We have no more deep space probes, Sir.\"");
833 prout("Ye Faerie Queene has no deep space probes.");
836 if (game.damage[DDSP] != 0.0) {
839 prout("Engineer Scott- \"The probe launcher is damaged, Sir.\"");
842 if (game.future[FDSPROB] != 1e30) {
845 if (game.damage[DRADIO] != 0 && condit != IHDOCKED) {
846 prout("Spock- \"Records show the previous probe has not yet");
847 prout(" reached its destination.\"");
850 prout("Uhura- \"The previous probe is still reporting data, Sir.\"");
856 /* slow mode, so let Kirk know how many probes there are left */
857 prout(nprobes==1 ? "%d probe left." : "%d probes left.", nprobes);
858 proutn("Are you sure you want to fire a probe? ");
863 if (key == IHALPHA && strcmp(citem,"armed") == 0) {
867 else if (key == IHEOL) {
868 proutn("Arm NOVAMAX warhead? ");
872 if (direc == -1.0) return;
874 angle = ((15.0 - direc) * 0.5235988);
875 probeinx = -sin(angle);
876 probeiny = cos(angle);
877 if (fabs(probeinx) > fabs(probeiny))
878 bigger = fabs(probeinx);
880 bigger = fabs(probeiny);
884 proben = 10.0*dist*bigger +0.5;
885 probex = quadx*10 + sectx - 1; // We will use better packing than original
886 probey = quady*10 + secty - 1;
889 game.future[FDSPROB] = game.state.date + 0.01; // Time to move one sector
890 prout("Ensign Chekov- \"The deep space probe is launched, Captain.\"");
896 /* There's more than one way to move in this game! */
897 double ddist, xdist, probf;
898 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.");
951 for (l = 1; l <= 5; l++) {
952 ix = basex+3.0*Rand()-1;
953 iy = basey+3.0*Rand()-1;
954 if (ix>=1 && ix<=10 && iy>=1 && iy<=10 && game.quad[ix][iy]==IHDOT) {
955 /* found one -- finish up */
958 game.quad[ix][iy]=IHMATER0;
963 prout("You have been lost in space...");
964 finish(FMATERIALIZE);
968 /* Give starbase three chances to rematerialize starship */
969 probf = pow((1.0 - pow(0.98,ddist)), 0.33333333);
970 for (l = 1; l <= 3; l++) {
972 case 1: proutn("1st"); break;
973 case 2: proutn("2nd"); break;
974 case 3: proutn("3rd"); break;
976 proutn(" attempt to re-materialize ");
978 prouts(" . . . . . ");
979 if (Rand() > probf) break;
983 finish(FMATERIALIZE);
986 /* Rematerialization attempt should succeed if can get adj to base */
987 for (l = 1; l <= 5; l++) {
988 ix = basex+3.0*Rand()-1;
989 iy = basey+3.0*Rand()-1;
990 if (ix>=1 && ix<=10 && iy>=1 && iy<=10 && game.quad[ix][iy]==IHDOT) {
991 /* found one -- finish up */
995 game.quad[ix][iy]=ship;
998 prout("Lt. Uhura- \"Captain, we made it!\"");
1002 finish(FMATERIALIZE);