5 static void getcd(bool, int);
8 /* movement execution for warp, impule, supernova, and tractor-beam events */
10 double angle, deltax, deltay, bigger, x, y,
11 finald, stopegy, probf;
12 int n, m, kink, kinks, iquad;
18 prout(_("Helmsman Sulu- \"Leaving standard orbit.\""));
22 angle = ((15.0 - game.direc) * 0.5235988);
25 if (fabs(deltax) > fabs(deltay))
26 bigger = fabs(deltax);
28 bigger = fabs(deltay);
33 /* If tractor beam is to occur, don't move full distance */
34 if (game.state.date+game.optime >= scheduled(FTBEAM)) {
37 game.dist = game.dist*(scheduled(FTBEAM)-game.state.date)/game.optime + 0.1;
38 game.optime = scheduled(FTBEAM) - game.state.date + 1e-5;
40 /* Move within the quadrant */
41 game.quad[game.sector.x][game.sector.y] = IHDOT;
44 n = 10.0*game.dist*bigger+0.5;
47 for (m = 1; m <= n; m++) {
48 w.x = (x += deltax) + 0.5;
49 w.y = (y += deltay) + 0.5;
50 if (!VALID_SECTOR(w.x, w.y)) {
51 /* Leaving quadrant -- allow final enemy attack */
52 /* Don't do it if being pushed by Nova */
53 if (game.nenhere != 0 && game.iattak != 2) {
55 for_local_enemies(m) {
56 finald = distance(w, game.ks[m]);
57 game.kavgd[m] = 0.5 * (finald + game.kdist[m]);
60 * Stas Sergeev added the condition
61 * that attacks only happen if Klingons
62 * are present and your skill is good.
64 if (game.skill > SKILL_GOOD && game.klhere > 0 && !game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova)
66 if (game.alldone) return;
68 /* compute final position -- new quadrant and sector */
69 x = QUADSIZE*(game.quadrant.x-1)+game.sector.x;
70 y = QUADSIZE*(game.quadrant.y-1)+game.sector.y;
71 w.x = x+10.0*game.dist*bigger*deltax+0.5;
72 w.y = y+10.0*game.dist*bigger*deltay+0.5;
73 /* check for edge of galaxy */
85 if (w.x > GALSIZE*QUADSIZE) {
86 w.x = (GALSIZE*QUADSIZE*2)+1 - w.x;
89 if (w.y > GALSIZE*QUADSIZE) {
90 w.y = (GALSIZE*QUADSIZE*2)+1 - w.y;
98 if (game.nkinks == 3) {
99 /* Three strikes -- you're out! */
104 prout(_("YOU HAVE ATTEMPTED TO CROSS THE NEGATIVE ENERGY BARRIER"));
105 prout(_("AT THE EDGE OF THE GALAXY. THE THIRD TIME YOU TRY THIS,"));
106 prout(_("YOU WILL BE DESTROYED."));
108 /* Compute final position in new quadrant */
109 if (trbeam) return; /* Don't bother if we are to be beamed */
110 game.quadrant.x = (w.x+(QUADSIZE-1))/QUADSIZE;
111 game.quadrant.y = (w.y+(QUADSIZE-1))/QUADSIZE;
112 game.sector.x = w.x - QUADSIZE*(game.quadrant.x-1);
113 game.sector.y = w.y - QUADSIZE*(game.quadrant.y-1);
115 prout(_("Entering %s."), cramlc(quadrant, game.quadrant));
116 game.quad[game.sector.x][game.sector.y] = game.ship;
118 if (game.skill>SKILL_NOVICE) attack(0);
121 iquad = game.quad[w.x][w.y];
122 if (iquad != IHDOT) {
123 /* object encountered in flight path */
124 stopegy = 50.0*game.dist/game.optime;
125 game.dist = distance(game.sector, w) / (QUADSIZE * 1.0);
127 case IHT: /* Ram a Tholian */
128 case IHK: /* Ram enemy ship */
134 ram(false, iquad, game.sector);
139 prouts(_("***RED ALERT! RED ALERT!"));
143 proutn(_(" pulled into black hole at "));
144 prout(cramlc(sector, w));
146 * Getting pulled into a black hole was certain
147 * death in Almy's original. Stas Sergeev added a
148 * possibility that you'll get timewarped instead.
151 for (m=0;m<NDEVICES;m++)
152 if (game.damage[m]>0)
154 probf=pow(1.4,(game.energy+game.shield)/5000.0-1.0)*pow(1.3,1.0/(n+1)-1.0);
155 if ((game.options & OPTION_BLKHOLE) && Rand()>probf)
165 proutn(_(" encounters Tholian web at "));
167 proutn(_(" blocked by object at "));
168 proutn(cramlc(sector, w));
170 proutn(_("Emergency stop required "));
171 prout(_("%2d units of energy."), (int)stopegy);
172 game.energy -= stopegy;
173 final.x = x-deltax+0.5;
174 final.y = y-deltay+0.5;
176 if (game.energy <= 0) {
182 goto no_quad_change; /* sorry! */
185 game.dist = distance(game.sector, w) / (QUADSIZE * 1.0);
190 /* No quadrant change -- compute new avg enemy distances */
191 game.quad[game.sector.x][game.sector.y] = game.ship;
193 for_local_enemies(m) {
194 finald = distance(w, game.ks[m]);
195 game.kavgd[m] = 0.5 * (finald+game.kdist[m]);
196 game.kdist[m] = finald;
199 if (!game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova && game.iattak == 0)
201 for_local_enemies(m) game.kavgd[m] = game.kdist[m];
206 setwnd(message_window);
210 void dock(bool verbose)
211 /* dock our ship at a starbase */
214 if (game.condition == docked && verbose) {
215 prout(_("Already docked."));
219 prout(_("You must first leave standard orbit."));
222 if (game.base.x==0 || abs(game.sector.x-game.base.x) > 1 || abs(game.sector.y-game.base.y) > 1) {
224 prout(_(" not adjacent to base."));
227 game.condition = docked;
228 if (verbose) prout(_("Docked."));
230 if (game.energy < game.inenrg) game.energy = game.inenrg;
231 game.shield = game.inshld;
232 game.torps = game.intorps;
233 game.lsupres = game.inlsr;
234 game.state.crew = FULLCREW;
235 if (!damaged(DRADIO) &&
236 (is_scheduled(FCDBAS) || game.isatb == 1) && !game.iseenit) {
237 /* get attack report from base */
238 prout(_("Lt. Uhura- \"Captain, an important message from the starbase:\""));
245 * This program originally required input in terms of a (clock)
246 * direction and distance. Somewhere in history, it was changed to
247 * cartesian coordinates. So we need to convert. I think
248 * "manual" input should still be done this way -- it's a real
249 * pain if the computer isn't working! Manual mode is still confusing
250 * because it involves giving x and y motions, yet the coordinates
251 * are always displayed y - x, where +y is downward!
254 static void getcd(bool isprobe, int akey)
255 /* get course and distance */
257 int irowq=game.quadrant.x, icolq=game.quadrant.y, key=0;
258 double xi, xj, xk, xl;
259 double deltax, deltay;
260 enum {unspecified, manual, automatic} navmode = unspecified;
261 enum {curt, normal, verbose} itemp = curt;
263 bool iprompt = false;
265 /* Get course direction and distance. If user types bad values, return
266 with DIREC = -1.0. */
270 if (game.landed == 1 && !isprobe) {
271 prout(_("Dummy! You can't leave standard orbit until you"));
272 proutn(_("are back aboard the "));
278 while (navmode == unspecified) {
279 if (damaged(DCOMPTR)) {
281 prout(_("Computer damaged; manual navigation only"));
283 prout(_("Computer damaged; manual movement only"));
289 if (isprobe && akey != -1) {
290 /* For probe launch, use pre-scanned value first time */
298 proutn(_("Manual or automatic- "));
302 else if (key == IHALPHA) {
303 if (isit("manual")) {
308 else if (isit("automatic")) {
321 prout(_("(Manual navigation assumed.)"));
323 prout(_("(Manual movement assumed.)"));
329 if (navmode == automatic) {
330 while (key == IHEOL) {
332 proutn(_("Target quadrant or quadrant§or- "));
334 proutn(_("Destination sector or quadrant§or- "));
353 /* both quadrant and sector specified */
369 /* only quadrant specified -- go to center of dest quad */
380 if (!VALID_QUADRANT(icolq,irowq)||!VALID_SECTOR(incr.x,incr.y)) {
388 prout(_("Helmsman Sulu- \"Course locked in for %s.\""),
389 cramlc(sector, incr));
392 else prout(_("Ensign Chekov- \"Course laid in, Captain.\""));
394 deltax = icolq - game.quadrant.y + 0.1*(incr.x-game.sector.y);
395 deltay = game.quadrant.x - irowq + 0.1*(game.sector.x-incr.y);
398 while (key == IHEOL) {
399 proutn(_("X and Y displacements- "));
417 /* Check for zero movement */
418 if (deltax == 0 && deltay == 0) {
422 if (itemp == verbose && !isprobe) {
424 prout(_("Helmsman Sulu- \"Aye, Sir.\""));
426 game.dist = sqrt(deltax*deltax + deltay*deltay);
427 game.direc = atan2(deltax, deltay)*1.90985932;
428 if (game.direc < 0.0) game.direc += 12.0;
436 /* move under impulse power */
441 if (damaged(DIMPULS)) {
444 prout(_("Engineer Scott- \"The impulse engines are damaged, Sir.\""));
448 if (game.energy > 30.0) {
450 if (game.direc == -1.0) return;
451 power = 20.0 + 100.0*game.dist;
456 if (power >= game.energy) {
457 /* Insufficient power for trip */
459 prout(_("First Officer Spock- \"Captain, the impulse engines"));
460 prout(_("require 20.0 units to engage, plus 100.0 units per"));
461 if (game.energy > 30) {
462 proutn(_("quadrant. We can go, therefore, a maximum of %d"),
463 (int)(0.01 * (game.energy-20.0)-0.05));
464 prout(_(" quadrants.\""));
467 prout(_("quadrant. They are, therefore, useless.\""));
472 /* Make sure enough time is left for the trip */
473 game.optime = game.dist/0.095;
474 if (game.optime >= game.state.remtime) {
475 prout(_("First Officer Spock- \"Captain, our speed under impulse"));
476 prout(_("power is only 0.95 sectors per stardate. Are you sure"));
477 proutn(_("we dare spend the time?\" "));
478 if (ja() == false) return;
480 /* Activate impulse engines and pay the cost */
483 if (game.alldone) return;
484 power = 20.0 + 100.0*game.dist;
485 game.energy -= power;
486 game.optime = game.dist/0.095;
487 if (game.energy <= 0) finish(FNRG);
492 void warp(bool timewarp)
493 /* move under warp drive */
496 bool blooey = false, twarp = false;
499 if (!timewarp) { /* Not WARPX entry */
501 if (game.damage[DWARPEN] > 10.0) {
504 prout(_("Engineer Scott- \"The impulse engines are damaged, Sir.\""));
507 if (damaged(DWARPEN) && game.warpfac > 4.0) {
510 prout(_("Engineer Scott- \"Sorry, Captain. Until this damage"));
511 prout(_(" is repaired, I can only give you warp 4.\""));
515 /* Read in course and distance */
517 if (game.direc == -1.0) return;
519 /* Make sure starship has enough energy for the trip */
520 power = (game.dist+0.05)*game.warpfac*game.warpfac*game.warpfac*(game.shldup+1);
523 if (power >= game.energy) {
524 /* Insufficient power for trip */
527 prout(_("Engineering to bridge--"));
528 if (!game.shldup || 0.5*power > game.energy) {
529 iwarp = pow((game.energy/(game.dist+0.05)), 0.333333333);
531 prout(_("We can't do it, Captain. We don't have enough energy."));
534 proutn(_("We don't have enough energy, but we could do it at warp %d"), iwarp);
537 prout(_("if you'll lower the shields."));
544 prout(_("We haven't the energy to go that far with the shields up."));
548 /* Make sure enough time is left for the trip */
549 game.optime = 10.0*game.dist/game.wfacsq;
550 if (game.optime >= 0.8*game.state.remtime) {
552 prout(_("First Officer Spock- \"Captain, I compute that such"));
553 proutn(_(" a trip would require approximately %2.0f"),
554 100.0*game.optime/game.state.remtime);
555 prout(_(" percent of our"));
556 proutn(_(" remaining time. Are you sure this is wise?\" "));
557 if (ja() == false) { game.ididit = false; game.optime=0; return;}
561 if (game.warpfac > 6.0) {
562 /* Decide if engine damage will occur */
563 double prob = game.dist*(6.0-game.warpfac)*(6.0-game.warpfac)/66.666666666;
566 game.dist = Rand()*game.dist;
568 /* Decide if time warp will occur */
569 if (0.5*game.dist*pow(7.0,game.warpfac-10.0) > Rand()) twarp = true;
570 if (idebug && game.warpfac==10 && !twarp) {
572 proutn("=== Force time warp? ");
573 if (ja() == true) twarp = true;
575 if (blooey || twarp) {
576 /* If time warp or engine damage, check path */
577 /* If it is obstructed, don't do warp or damage */
578 double angle = ((15.0-game.direc)*0.5235998);
579 double deltax = -sin(angle);
580 double deltay = cos(angle);
583 if (fabs(deltax) > fabs(deltay))
584 bigger = fabs(deltax);
586 bigger = fabs(deltay);
590 n = 10.0 * game.dist * bigger +0.5;
593 for (l = 1; l <= n; l++) {
598 if (!VALID_SECTOR(ix, iy)) break;
599 if (game.quad[ix][iy] != IHDOT) {
608 /* Activate Warp Engines and pay the cost */
610 if (game.alldone) return;
611 game.energy -= game.dist*game.warpfac*game.warpfac*game.warpfac*(game.shldup+1);
612 if (game.energy <= 0) finish(FNRG);
613 game.optime = 10.0*game.dist/game.wfacsq;
616 game.damage[DWARPEN] = game.damfac*(3.0*Rand()+1.0);
618 prout(_("Engineering to bridge--"));
619 prout(_(" Scott here. The warp engines are damaged."));
620 prout(_(" We'll have to reduce speed to warp 4."));
629 /* change the warp factor */
634 while ((key=scan()) == IHEOL) {
636 proutn(_("Warp factor- "));
643 if (game.damage[DWARPEN] > 10.0) {
644 prout(_("Warp engines inoperative."));
647 if (damaged(DWARPEN) && aaitem > 4.0) {
648 prout(_("Engineer Scott- \"I'm doing my best, Captain,"));
649 prout(_(" but right now we can only go warp 4.\""));
653 prout(_("Helmsman Sulu- \"Our top speed is warp 10, Captain.\""));
657 prout(_("Helmsman Sulu- \"We can't go below warp 1, Captain.\""));
660 oldfac = game.warpfac;
661 game.warpfac = aaitem;
662 game.wfacsq=game.warpfac*game.warpfac;
663 if (game.warpfac <= oldfac || game.warpfac <= 6.0) {
664 prout(_("Helmsman Sulu- \"Warp factor %d, Captain.\""),
668 if (game.warpfac < 8.00) {
669 prout(_("Engineer Scott- \"Aye, but our maximum safe speed is warp 6.\""));
672 if (game.warpfac == 10.0) {
673 prout(_("Engineer Scott- \"Aye, Captain, we'll try it.\""));
676 prout(_("Engineer Scott- \"Aye, Captain, but our engines may not take it.\""));
680 void atover(bool igrab)
681 /* cope with being tossed out of quadrant by supernova or yanked by beam */
683 double power, distreq;
686 /* is captain on planet? */
687 if (game.landed==1) {
688 if (damaged(DTRANSP)) {
692 prout(_("Scotty rushes to the transporter controls."));
694 prout(_("But with the shields up it's hopeless."));
697 prouts(_("His desperate attempt to rescue you . . ."));
703 prout(_("SUCCEEDS!"));
706 proutn(_("The crystals mined were "));
707 if (Rand() <= 0.25) {
718 /* Check to see if captain in shuttle craft */
719 if (game.icraft) finish(FSTRACTOR);
720 if (game.alldone) return;
722 /* Inform captain of attempt to reach safety */
726 prouts(_("***RED ALERT! RED ALERT!"));
730 prout(_(" has stopped in a quadrant containing"));
731 prouts(_(" a supernova."));
734 proutn(_("***Emergency automatic override attempts to hurl "));
737 prout(_("safely out of quadrant."));
738 if (!damaged(DRADIO))
739 game.state.galaxy[game.quadrant.x][game.quadrant.y].charted = true;
740 /* Try to use warp engines */
741 if (damaged(DWARPEN)) {
743 prout(_("Warp engines damaged."));
747 game.warpfac = 6.0+2.0*Rand();
748 game.wfacsq = game.warpfac * game.warpfac;
749 prout(_("Warp factor set to %d"), (int)game.warpfac);
750 power = 0.75*game.energy;
751 game.dist = power/(game.warpfac*game.warpfac*game.warpfac*(game.shldup+1));
752 distreq = 1.4142+Rand();
753 if (distreq < game.dist) game.dist = distreq;
754 game.optime = 10.0*game.dist/game.wfacsq;
755 game.direc = 12.0*Rand(); /* How dumb! */
757 game.inorbit = false;
760 /* This is bad news, we didn't leave quadrant. */
761 if (game.alldone) return;
763 prout(_("Insufficient energy to leave quadrant."));
768 /* Repeat if another snova */
769 (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova);
771 finish(FWON); /* Snova killed remaining enemy. */
775 /* let's do the time warp again */
779 prout(_("***TIME WARP ENTERED."));
780 if (game.state.snap && Rand() < 0.5) {
781 /* Go back in time */
782 prout(_("You are traveling backwards in time %d stardates."),
783 (int)(game.state.date-game.snapsht.date));
784 game.state = game.snapsht;
786 if (game.state.remcom) {
787 schedule(FTBEAM, expran(game.intime/game.state.remcom));
788 schedule(FBATTAK, expran(0.3*game.intime));
790 schedule(FSNOVA, expran(0.5*game.intime));
791 /* next snapshot will be sooner */
792 schedule(FSNAP, expran(0.25*game.state.remtime));
794 if (game.state.nscrem) schedule(FSCMOVE, 0.2777);
798 game.battle.x = game.battle.y = 0;
800 /* Make sure Galileo is consistant -- Snapshot may have been taken
801 when on planet, which would give us two Galileos! */
803 for (l = 0; l < game.inplan; l++) {
804 if (game.state.plnets[l].known == shuttle_down) {
806 if (game.iscraft==1 && game.ship==IHE) {
807 prout(_("Checkov- \"Security reports the Galileo has disappeared, Sir!"));
812 /* Likewise, if in the original time the Galileo was abandoned, but
813 was on ship earlier, it would have vanished -- lets restore it */
814 if (game.iscraft==0 && !gotit && game.damage[DSHUTTL] >= 0.0) {
815 prout(_("Checkov- \"Security reports the Galileo has reappeared in the dock!\""));
819 * There used to be code to do the actual reconstrction here,
820 * but the starchart is now part of the snapshotted galaxy state.
822 prout(_("Spock has reconstructed a correct star chart from memory"));
825 /* Go forward in time */
826 game.optime = -0.5*game.intime*log(Rand());
827 prout(_("You are traveling forward in time %d stardates."), (int)game.optime);
828 /* cheat to make sure no tractor beams occur during time warp */
829 postpone(FTBEAM, game.optime);
830 game.damage[DRADIO] += game.optime;
833 events(); /* Stas Sergeev added this -- do pending events */
837 /* launch deep-space probe */
839 double angle, bigger;
841 /* New code to launch a deep space probe */
842 if (game.nprobes == 0) {
845 if (game.ship == IHE)
846 prout(_("Engineer Scott- \"We have no more deep space probes, Sir.\""));
848 prout(_("Ye Faerie Queene has no deep space probes."));
854 prout(_("Engineer Scott- \"The probe launcher is damaged, Sir.\""));
857 if (is_scheduled(FDSPROB)) {
860 if (damaged(DRADIO) && game.condition != docked) {
861 prout(_("Spock- \"Records show the previous probe has not yet"));
862 prout(_(" reached its destination.\""));
865 prout(_("Uhura- \"The previous probe is still reporting data, Sir.\""));
871 /* slow mode, so let Kirk know how many probes there are left */
872 prout(game.nprobes==1 ? _("%d probe left.") : _("%d probes left."), game.nprobes);
873 proutn(_("Are you sure you want to fire a probe? "));
874 if (ja() == false) return;
877 game.isarmed = false;
878 if (key == IHALPHA && strcmp(citem,"armed") == 0) {
882 else if (key == IHEOL) {
883 proutn(_("Arm NOVAMAX warhead? "));
887 if (game.direc == -1.0) return;
889 angle = ((15.0 - game.direc) * 0.5235988);
890 game.probeinx = -sin(angle);
891 game.probeiny = cos(angle);
892 if (fabs(game.probeinx) > fabs(game.probeiny))
893 bigger = fabs(game.probeinx);
895 bigger = fabs(game.probeiny);
897 game.probeiny /= bigger;
898 game.probeinx /= bigger;
899 game.proben = 10.0*game.dist*bigger +0.5;
900 game.probex = game.quadrant.x*QUADSIZE + game.sector.x - 1; // We will use better packing than original
901 game.probey = game.quadrant.y*QUADSIZE + game.sector.y - 1;
902 game.probec = game.quadrant;
903 schedule(FDSPROB, 0.01); // Time to move one sector
904 prout(_("Ensign Chekov- \"The deep space probe is launched, Captain.\""));
910 /* yell for help from nearest starbase */
912 /* There's more than one way to move in this game! */
913 double ddist, xdist, probf;
914 int line = 0, m, ix, iy;
917 /* Test for conditions which prevent calling for help */
918 if (game.condition == docked) {
919 prout(_("Lt. Uhura- \"But Captain, we're already docked.\""));
922 if (damaged(DRADIO)) {
923 prout(_("Subspace radio damaged."));
926 if (game.state.rembase==0) {
927 prout(_("Lt. Uhura- \"Captain, I'm not getting any response from Starbase.\""));
930 if (game.landed == 1) {
931 proutn(_("You must be aboard the "));
936 /* OK -- call for help from nearest starbase */
938 if (game.base.x!=0) {
939 /* There's one in this quadrant */
940 ddist = distance(game.base, game.sector);
945 xdist = QUADSIZE * distance(game.state.baseq[m], game.quadrant);
951 /* Since starbase not in quadrant, set up new quadrant */
952 game.quadrant = game.state.baseq[line];
955 /* dematerialize starship */
956 game.quad[game.sector.x][game.sector.y]=IHDOT;
957 proutn(_("Starbase in %s responds--"), cramlc(quadrant, game.quadrant));
960 prout(_(" dematerializes."));
962 for (m = 1; m <= 5; m++) {
963 ix = game.base.x+3.0*Rand()-1;
964 iy = game.base.y+3.0*Rand()-1;
965 if (VALID_SECTOR(ix,iy) && game.quad[ix][iy]==IHDOT) {
966 /* found one -- finish up */
972 if (game.sector.x==0){
973 prout(_("You have been lost in space..."));
974 finish(FMATERIALIZE);
977 /* Give starbase three chances to rematerialize starship */
978 probf = pow((1.0 - pow(0.98,ddist)), 0.33333333);
979 for (m = 1; m <= 3; m++) {
981 case 1: proutn(_("1st")); break;
982 case 2: proutn(_("2nd")); break;
983 case 3: proutn(_("3rd")); break;
985 proutn(_(" attempt to re-materialize "));
988 case 1: game.quad[ix][iy]=IHMATER0;
990 case 2: game.quad[ix][iy]=IHMATER1;
992 case 3: game.quad[ix][iy]=IHMATER2;
997 if (Rand() > probf) break;
1003 game.quad[ix][iy]=IHQUEST;
1006 setwnd(message_window);
1007 finish(FMATERIALIZE);
1010 game.quad[ix][iy]=game.ship;
1012 prout(_("succeeds."));
1016 prout(_("Lt. Uhura- \"Captain, we made it!\""));