6 static void getcd(int, int);
9 double angle, deltax, deltay, bigger, x, y,
10 finald, finalx, finaly, stopegy, probf;
11 int trbeam = 0, n, l, ix=0, iy=0, kink, kinks, iquad;
14 prout("Helmsman Sulu- \"Leaving standard orbit.\"");
18 angle = ((15.0 - direc) * 0.5235988);
21 if (fabs(deltax) > fabs(deltay))
22 bigger = fabs(deltax);
24 bigger = fabs(deltay);
29 /* If tractor beam is to occur, don't move full distance */
30 if (game.state.date+Time >= game.future[FTBEAM]) {
33 dist = dist*(game.future[FTBEAM]-game.state.date)/Time + 0.1;
34 Time = game.future[FTBEAM] - game.state.date + 1e-5;
36 /* Move within the quadrant */
37 game.quad[sectx][secty] = IHDOT;
40 n = 10.0*dist*bigger+0.5;
43 for (l = 1; l <= n; l++) {
44 ix = (x += deltax) + 0.5;
45 iy = (y += deltay) + 0.5;
46 if (ix < 1 || ix > 10 || iy < 1 || iy > 10) {
47 /* Leaving quadrant -- allow final enemy attack */
48 /* Don't do it if being pushed by Nova */
49 if (nenhere != 0 && iattak != 2) {
51 for (l = 1; l <= nenhere; l++) {
52 finald = sqrt((ix-game.kx[l])*(double)(ix-game.kx[l]) +
53 (iy-game.ky[l])*(double)(iy-game.ky[l]));
54 game.kavgd[l] = 0.5 * (finald+game.kdist[l]);
57 * Stas Sergeev added the condition
58 * that attacks only happen if Klingons
59 * are present and your skill is > 3.
61 if (skill > 3 && klhere > 0 && game.state.galaxy[quadx][quady] != 1000)
65 /* compute final position -- new quadrant and sector */
66 x = 10*(quadx-1)+sectx;
67 y = 10*(quady-1)+secty;
68 ix = x+10.0*dist*bigger*deltax+0.5;
69 iy = y+10.0*dist*bigger*deltay+0.5;
70 /* check for edge of galaxy */
96 /* Three strikes -- you're out! */
100 prout("\n\rYOU HAVE ATTEMPTED TO CROSS THE NEGATIVE ENERGY BARRIER\n\r"
101 "AT THE EDGE OF THE GALAXY. THE THIRD TIME YOU TRY THIS,\n\r"
102 "YOU WILL BE DESTROYED.\n\r");
104 /* Compute final position in new quadrant */
105 if (trbeam) return; /* Don't bother if we are to be beamed */
108 sectx = ix - 10*(quadx-1);
109 secty = iy - 10*(quady-1);
110 proutn("\n\rEntering %s.",
111 cramlc(quadrant, quadx, quady));
112 game.quad[sectx][secty] = ship;
114 if (skill>1) attack(0);
117 iquad = game.quad[ix][iy];
118 if (iquad != IHDOT) {
119 /* object encountered in flight path */
120 stopegy = 50.0*dist/Time;
121 dist=0.1*sqrt((sectx-ix)*(double)(sectx-ix) +
122 (secty-iy)*(double)(secty-iy));
124 case IHT: /* Ram a Tholian */
125 case IHK: /* Ram enemy ship */
132 ram(0, iquad, sectx, secty);
138 prouts("***RED ALERT! RED ALERT!");
142 proutn(" pulled into black hole at ");
143 prout(cramlc(sector, ix, iy));
145 * Getting pulled into a black
146 * hole was certain death in
147 * Almy's original. Stas
148 * Sergeev added a possibility
149 * that you'll get timewarped
153 for (l=1;l<=NDEVICES+1;l++)
154 if (game.damage[l]>0) n++;
155 probf=pow(1.4,(energy+shield)/5000.0-1.0)*
156 pow(1.3,1.0/(n+1)-1.0);
167 proutn(" encounters Tholian web at ");
169 proutn(" blocked by object at ");
170 proutn(cramlc(sector, ix,iy));
172 proutn("Emergency stop required ");
173 prout("%2d units of energy.", (int)stopegy);
175 finalx = x-deltax+0.5;
177 finaly = y-deltay+0.5;
185 goto label100; /* sorry! */
188 dist = 0.1*sqrt((sectx-ix)*(double)(sectx-ix) +
189 (secty-iy)*(double)(secty-iy));
196 /* No quadrant change -- compute new avg enemy distances */
197 game.quad[sectx][secty] = ship;
199 for (l = 1; l <= nenhere; l++) {
200 finald = sqrt((ix-game.kx[l])*(double)(ix-game.kx[l]) +
201 (iy-game.ky[l])*(double)(iy-game.ky[l]));
202 game.kavgd[l] = 0.5 * (finald+game.kdist[l]);
203 game.kdist[l] = finald;
206 if (game.state.galaxy[quadx][quady] != 1000 && iattak == 0)
208 for (l = 1 ; l <= nenhere; l++) game.kavgd[l] = game.kdist[l];
220 if (condit == IHDOCKED && l) {
221 prout("Already docked.");
225 prout("You must first leave standard orbit.");
228 if (basex==0 || abs(sectx-basex) > 1 || abs(secty-basey) > 1) {
230 prout(" not adjacent to base.");
234 if (l) prout("Docked.");
236 if (energy < inenrg) energy = inenrg;
240 if (stdamtim != 1e30 &&
241 (game.future[FCDBAS] < 1e30 || isatb == 1) && iseenit == 0) {
242 /* get attack report from base */
243 prout("Lt. Uhura- \"Captain, an important message from the starbase:\"");
249 static void getcd(int isprobe, int akey) {
250 /* This program originally required input in terms of a (clock)
251 direction and distance. Somewhere in history, it was changed to
252 cartesian coordinates. So we need to convert. I think
253 "manual" input should still be done this way -- it's a real
254 pain if the computer isn't working! Manual mode is still confusing
255 because it involves giving x and y motions, yet the coordinates
256 are always displayed y - x, where +y is downward! */
259 int irowq=quadx, icolq=quady, irows, icols, itemp=0, iprompt=0, key=0;
260 double xi, xj, xk, xl;
261 double deltax, deltay;
264 /* Get course direction and distance. If user types bad values, return
265 with DIREC = -1.0. */
269 if (landed == 1 && !isprobe) {
270 prout("Dummy! You can't leave standard orbit until you");
271 proutn("are back abourt the ");
277 while (automatic == -1) {
278 if (game.damage[DCOMPTR]) {
280 prout("Computer damaged; manual navigation only");
282 prout("Computer damaged; manual movement only");
288 if (isprobe && akey != -1) {
289 /* For probe launch, use pre-scaned value first time */
297 proutn("Manual or automatic- ");
301 else if (key == IHALPHA) {
302 if (isit("manual")) {
307 else if (isit("automatic")) {
320 prout("(Manual navigation assumed.)");
322 prout("(Manual movement assumed.)");
329 while (key == IHEOL) {
331 proutn("Target quadrant or quadrant§or- ");
333 proutn("Destination sector or quadrant§or- ");
352 /* both quadrant and sector specified */
368 /* only quadrant specified -- go to center of dest quad */
379 if (irowq<1 || irowq > 8 || icolq<1 || icolq > 8 ||
380 irows<1 || irows > 10 || icols<1 || icols > 10) {
388 prout("Helmsman Sulu- \"Course locked in for %s.\"",
389 cramlc(sector, irows, icols));
392 else prout("Ensign Chekov- \"Course laid in, Captain.\"");
394 deltax = icolq - quady + 0.1*(icols-secty);
395 deltay = quadx - irowq + 0.1*(sectx-irows);
398 while (key == IHEOL) {
399 proutn("X and Y displacements- ");
417 /* Check for zero movement */
418 if (deltax == 0 && deltay == 0) {
422 if (itemp == 2 && !isprobe) {
424 prout("Helmsman Sulu- \"Aye, Sir.\"");
426 dist = sqrt(deltax*deltax + deltay*deltay);
427 direc = atan2(deltax, deltay)*1.90985932;
428 if (direc < 0.0) direc += 12.0;
440 if (game.damage[DIMPULS]) {
443 prout("Engineer Scott- \"The impulse engines are damaged, Sir.\"");
449 if (direc == -1.0) return;
450 power = 20.0 + 100.0*dist;
455 if (power >= energy) {
456 /* Insufficient power for trip */
458 prout("First Officer Spock- \"Captain, the impulse engines");
459 prout("require 20.0 units to engage, plus 100.0 units per");
461 proutn("quadrant. We can go, therefore, a maximum of %d",
462 (int)(0.01 * (energy-20.0)-0.05));
463 prout(" quadrants.\"");
466 prout("quadrant. They are, therefore, useless.\"");
471 /* Make sure enough time is left for the trip */
473 if (Time >= game.state.remtime) {
474 prout("First Officer Spock- \"Captain, our speed under impulse");
475 prout("power is only 0.95 sectors per stardate. Are you sure");
476 proutn("we dare spend the time?\" ");
477 if (ja() == 0) return;
479 /* Activate impulse engines and pay the cost */
483 power = 20.0 + 100.0*dist;
486 if (energy <= 0) finish(FNRG);
492 int blooey=0, twarp=0, iwarp;
495 if (i!=2) { /* Not WARPX entry */
497 if (game.damage[DWARPEN] > 10.0) {
500 prout("Engineer Scott- \"The impulse engines are damaged, Sir.\"");
503 if (game.damage[DWARPEN] > 0.0 && warpfac > 4.0) {
506 prout("Engineer Scott- \"Sorry, Captain. Until this damage");
507 prout(" is repaired, I can only give you warp 4.\"");
511 /* Read in course and distance */
513 if (direc == -1.0) return;
515 /* Make sure starship has enough energy for the trip */
516 power = (dist+0.05)*warpfac*warpfac*warpfac*(shldup+1);
519 if (power >= energy) {
520 /* Insufficient power for trip */
523 prout("Engineering to bridge--");
524 if (shldup==0 || 0.5*power > energy) {
525 iwarp = pow((energy/(dist+0.05)), 0.333333333);
527 prout("We can't do it, Captain. We haven't the energy.");
530 proutn("We haven't the energy, but we could do it at warp %d", iwarp);
533 prout("if you'll lower the shields.");
540 prout("We haven't the energy to go that far with the shields up.");
544 /* Make sure enough time is left for the trip */
545 Time = 10.0*dist/wfacsq;
546 if (Time >= 0.8*game.state.remtime) {
548 prout("First Officer Spock- \"Captain, I compute that such");
549 proutn(" a trip would require approximately %2.0f",
550 100.0*Time/game.state.remtime);
551 prout(" percent of our");
552 proutn(" remaining time. Are you sure this is wise?\" ");
553 if (ja() == 0) { ididit = 0; Time=0; return;}
558 /* Decide if engine damage will occur */
559 double prob = dist*(6.0-warpfac)*(6.0-warpfac)/66.666666666;
564 /* Decide if time warp will occur */
565 if (0.5*dist*pow(7.0,warpfac-10.0) > Rand()) twarp=1;
567 if (idebug &&warpfac==10 && twarp==0) {
569 proutn("Force time warp? ");
570 if (ja()==1) twarp=1;
573 if (blooey || twarp) {
574 /* If time warp or engine damage, check path */
575 /* If it is obstructed, don't do warp or damage */
576 double angle = ((15.0-direc)*0.5235998);
577 double deltax = -sin(angle);
578 double deltay = cos(angle);
581 if (fabs(deltax) > fabs(deltay))
582 bigger = fabs(deltax);
584 bigger = fabs(deltay);
588 n = 10.0 * dist * bigger +0.5;
591 for (l = 1; l <= n; l++) {
594 if (ix < 1 || ix > 10) break;
597 if (iy < 1 || iy > 10) break;
598 if (game.quad[ix][iy] != IHDOT) {
607 /* Activate Warp Engines and pay the cost */
610 energy -= dist*warpfac*warpfac*warpfac*(shldup+1);
611 if (energy <= 0) finish(FNRG);
612 Time = 10.0*dist/wfacsq;
615 game.damage[DWARPEN] = damfac*(3.0*Rand()+1.0);
617 prout("Engineering to bridge--");
618 prout(" Scott here. The warp engines are damaged.");
619 prout(" We'll have to reduce speed to warp 4.");
631 while ((key=scan()) == IHEOL) {
633 proutn("Warp factor- ");
640 if (game.damage[DWARPEN] > 10.0) {
641 prout("Warp engines inoperative.");
644 if (game.damage[DWARPEN] > 0.0 && aaitem > 4.0) {
645 prout("Engineer Scott- \"I'm doing my best, Captain,\n"
646 " but right now we can only go warp 4.\"");
650 prout("Helmsman Sulu- \"Our top speed is warp 10, Captain.\"");
654 prout("Helmsman Sulu- \"We can't go below warp 1, Captain.\"");
659 wfacsq=warpfac*warpfac;
660 if (warpfac <= oldfac || warpfac <= 6.0) {
661 proutn("Helmsman Sulu- \"Warp factor %d, Captain.\"",
665 if (warpfac < 8.00) {
666 prout("Engineer Scott- \"Aye, but our maximum safe speed is warp 6.\"");
669 if (warpfac == 10.0) {
670 prout("Engineer Scott- \"Aye, Captain, we'll try it.\"");
673 prout("Engineer Scott- \"Aye, Captain, but our engines may not take it.\"");
677 void atover(int igrab) {
678 double power, distreq;
681 /* is captain on planet? */
683 if (game.damage[DTRANSP]) {
687 prout("Scotty rushes to the transporter controls.");
689 prout("But with the shields up it's hopeless.");
692 prouts("His desperate attempt to rescue you . . .");
701 proutn("The crystals mined were ");
702 if (Rand() <= 0.25) {
713 /* Check to see if captain in shuttle craft */
714 if (icraft) finish(FSTRACTOR);
717 /* Inform captain of attempt to reach safety */
721 prouts("***RED ALERT! READ ALERT!");
725 prout(" has stopped in a quadrant containing");
726 prouts(" a supernova.");
729 proutn("***Emergency automatic override attempts to hurl ");
732 prout("safely out of quadrant.");
733 game.starch[quadx][quady] = game.damage[DRADIO] > 0.0 ? game.state.galaxy[quadx][quady]+1000:1;
735 /* Try to use warp engines */
736 if (game.damage[DWARPEN]) {
738 prout("Warp engines damaged.");
742 warpfac = 6.0+2.0*Rand();
743 wfacsq = warpfac * warpfac;
744 prout("Warp factor set to %d", (int)warpfac);
746 dist = power/(warpfac*warpfac*warpfac*(shldup+1));
747 distreq = 1.4142+Rand();
748 if (distreq < dist) dist = distreq;
749 Time = 10.0*dist/wfacsq;
750 direc = 12.0*Rand(); /* How dumb! */
755 /* This is bad news, we didn't leave quadrant. */
758 prout("Insufficient energy to leave quadrant.");
762 /* Repeat if another snova */
763 } while (game.state.galaxy[quadx][quady] == 1000);
764 if (game.state.remkl==0) finish(FWON); /* Snova killed remaining enemy. */
769 prout("***TIME WARP ENTERED.");
770 if (game.state.snap && Rand() < 0.5) {
771 /* Go back in time */
772 prout("You are traveling backwards in time %d stardates.",
773 (int)(game.state.date-game.snapsht.date));
774 game.state = game.snapsht;
776 if (game.state.remcom) {
777 game.future[FTBEAM] = game.state.date + expran(intime/game.state.remcom);
778 game.future[FBATTAK] = game.state.date + expran(0.3*intime);
780 game.future[FSNOVA] = game.state.date + expran(0.5*intime);
781 game.future[FSNAP] = game.state.date +expran(0.25*game.state.remtime); /* next snapshot will
783 if (game.state.nscrem) game.future[FSCMOVE] = 0.2777;
785 game.future[FCDBAS] = game.future[FSCDBAS] = 1e30;
788 /* Make sure Galileo is consistant -- Snapshot may have been taken
789 when on planet, which would give us two Galileos! */
791 for (l = 0; l < inplan; l++) {
792 if (game.state.plnets[l].known == shuttle_down) {
794 if (iscraft==1 && ship==IHE) {
795 prout("Checkov- \"Security reports the Galileo has disappeared, Sir!");
800 /* Likewise, if in the original time the Galileo was abandoned, but
801 was on ship earlier, it would have vanished -- lets restore it */
802 if (iscraft==0 && gotit==0 && game.damage[DSHUTTL] >= 0.0) {
803 prout("Checkov- \"Security reports the Galileo has reappeared in the dock!\"");
807 /* Revert star chart to earlier era, if it was known then*/
808 if (game.damage[DRADIO]==0.0 || stdamtim > game.state.date) {
809 for (l = 1; l <= 8; l++)
810 for (ll = 1; ll <= 8; ll++)
811 if (game.starch[l][ll] > 1)
812 game.starch[l][ll]=game.damage[DRADIO]>0.0 ? game.state.galaxy[l][ll]+1000 :1;
813 prout("Spock has reconstructed a correct star chart from memory");
814 if (game.damage[DRADIO] > 0.0) stdamtim = game.state.date;
818 /* Go forward in time */
819 Time = -0.5*intime*log(Rand());
820 prout("You are traveling forward in time %d stardates.", (int)Time);
821 /* cheat to make sure no tractor beams occur during time warp */
822 game.future[FTBEAM] += Time;
823 game.damage[DRADIO] += Time;
826 events(); /* Stas Sergeev added this -- do pending events */
830 double angle, bigger;
832 /* New code to launch a deep space probe */
837 prout("Engineer Scott- \"We have no more deep space probes, Sir.\"");
839 prout("Ye Faerie Queene has no deep space probes.");
842 if (game.damage[DDSP] != 0.0) {
845 prout("Engineer Scott- \"The probe launcher is damaged, Sir.\"");
848 if (game.future[FDSPROB] != 1e30) {
851 if (game.damage[DRADIO] != 0 && condit != IHDOCKED) {
852 prout("Spock- \"Records show the previous probe has not yet");
853 prout(" reached its destination.\"");
856 prout("Uhura- \"The previous probe is still reporting data, Sir.\"");
862 /* slow mode, so let Kirk know how many probes there are left */
863 prout(nprobes==1 ? "%d probe left." : "%d probes left.", nprobes);
864 proutn("Are you sure you want to fire a probe? ");
869 if (key == IHALPHA && strcmp(citem,"armed") == 0) {
873 else if (key == IHEOL) {
874 proutn("Arm NOVAMAX warhead? ");
878 if (direc == -1.0) return;
880 angle = ((15.0 - direc) * 0.5235988);
881 probeinx = -sin(angle);
882 probeiny = cos(angle);
883 if (fabs(probeinx) > fabs(probeiny))
884 bigger = fabs(probeinx);
886 bigger = fabs(probeiny);
890 proben = 10.0*dist*bigger +0.5;
891 probex = quadx*10 + sectx - 1; // We will use better packing than original
892 probey = quady*10 + secty - 1;
895 game.future[FDSPROB] = game.state.date + 0.01; // Time to move one sector
896 prout("Ensign Chekov- \"The deep space probe is launched, Captain.\"");
902 /* There's more than one way to move in this game! */
903 double ddist, xdist, probf;
904 int line = 0, l, ix, iy;
907 /* Test for conditions which prevent calling for help */
908 if (condit == IHDOCKED) {
909 prout("Lt. Uhura- \"But Captain, we're already docked.\"");
912 if (game.damage[DRADIO] != 0) {
913 prout("Subspace radio damaged.");
916 if (game.state.rembase==0) {
917 prout("Lt. Uhura- \"Captain, I'm not getting any response from Starbase.\"");
921 proutn("You must be aboard the ");
926 /* OK -- call for help from nearest starbase */
929 /* There's one in this quadrant */
930 ddist = sqrt(square(basex-sectx)+square(basey-secty));
934 for (l = 1; l <= game.state.rembase; l++) {
935 xdist=10.0*sqrt(square(game.state.baseqx[l]-quadx)+square(game.state.baseqy[l]-quady));
941 /* Since starbase not in quadrant, set up new quadrant */
942 quadx = game.state.baseqx[line];
943 quady = game.state.baseqy[line];
946 /* dematerialize starship */
947 game.quad[sectx][secty]=IHDOT;
948 proutn("Starbase in %s responds--", cramlc(quadrant, quadx, quady));
951 prout(" dematerializes.");
953 for (l = 1; l <= 5; l++) {
954 ix = basex+3.0*Rand()-1;
955 iy = basey+3.0*Rand()-1;
956 if (ix>=1 && ix<=10 && iy>=1 && iy<=10 && game.quad[ix][iy]==IHDOT) {
957 /* found one -- finish up */
960 game.quad[ix][iy]=IHMATER0;
965 prout("You have been lost in space...");
966 finish(FMATERIALIZE);
969 /* Give starbase three chances to rematerialize starship */
970 probf = pow((1.0 - pow(0.98,ddist)), 0.33333333);
971 for (l = 1; l <= 3; l++) {
973 case 1: proutn("1st"); break;
974 case 2: proutn("2nd"); break;
975 case 3: proutn("3rd"); break;
977 proutn(" attempt to re-materialize ");
980 if (Rand() > probf) break;
982 case 1: game.quad[ix][iy]=IHMATER1;
984 case 2: game.quad[ix][iy]=IHMATER2;
986 case 3: game.quad[ix][iy]=IHQUEST;
992 textcolor(LIGHTGRAY);
995 finish(FMATERIALIZE);
998 game.quad[ix][iy]=ship;
1001 textcolor(LIGHTGRAY);
1004 prout("Lt. Uhura- \"Captain, we made it!\"");