5 static void getcd(bool, int);
9 double angle, deltax, deltay, bigger, x, y,
10 finald, finalx, finaly, stopegy, probf;
11 int trbeam = 0, n, l, kink, kinks, iquad;
16 prout(_("Helmsman Sulu- \"Leaving standard orbit.\""));
20 angle = ((15.0 - game.direc) * 0.5235988);
23 if (fabs(deltax) > fabs(deltay))
24 bigger = fabs(deltax);
26 bigger = fabs(deltay);
31 /* If tractor beam is to occur, don't move full distance */
32 if (game.state.date+game.optime >= scheduled(FTBEAM)) {
35 game.dist = game.dist*(scheduled(FTBEAM)-game.state.date)/game.optime + 0.1;
36 game.optime = scheduled(FTBEAM) - game.state.date + 1e-5;
38 /* Move within the quadrant */
39 game.quad[game.sector.x][game.sector.y] = IHDOT;
42 n = 10.0*game.dist*bigger+0.5;
45 for (l = 1; l <= n; l++) {
46 w.x = (x += deltax) + 0.5;
47 w.y = (y += deltay) + 0.5;
48 if (!VALID_SECTOR(w.x, w.y)) {
49 /* Leaving quadrant -- allow final enemy attack */
50 /* Don't do it if being pushed by Nova */
51 if (game.nenhere != 0 && game.iattak != 2) {
53 for_local_enemies(l) {
54 finald = sqrt((w.x-game.ks[l].x)*(double)(w.x-game.ks[l].x) +
55 (w.y-game.ks[l].y)*(double)(w.y-game.ks[l].y));
56 game.kavgd[l] = 0.5 * (finald+game.kdist[l]);
59 * Stas Sergeev added the game.condition
60 * that attacks only happen if Klingons
61 * are present and your skill is good.
63 if (game.skill > SKILL_GOOD && game.klhere > 0 && !game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova)
65 if (game.alldone) return;
67 /* compute final position -- new quadrant and sector */
68 x = QUADSIZE*(game.quadrant.x-1)+game.sector.x;
69 y = QUADSIZE*(game.quadrant.y-1)+game.sector.y;
70 w.x = x+10.0*game.dist*bigger*deltax+0.5;
71 w.y = y+10.0*game.dist*bigger*deltay+0.5;
72 /* check for edge of galaxy */
84 if (w.x > GALSIZE*QUADSIZE) {
85 w.x = (GALSIZE*QUADSIZE*2)+1 - w.x;
88 if (w.y > GALSIZE*QUADSIZE) {
89 w.y = (GALSIZE*QUADSIZE*2)+1 - w.y;
97 if (game.nkinks == 3) {
98 /* Three strikes -- you're out! */
103 prout(_("YOU HAVE ATTEMPTED TO CROSS THE NEGATIVE ENERGY BARRIER"));
104 prout(_("AT THE EDGE OF THE GALAXY. THE THIRD TIME YOU TRY THIS,"));
105 prout(_("YOU WILL BE DESTROYED."));
107 /* Compute final position in new quadrant */
108 if (trbeam) return; /* Don't bother if we are to be beamed */
109 game.quadrant.x = (w.x+(QUADSIZE-1))/QUADSIZE;
110 game.quadrant.y = (w.y+(QUADSIZE-1))/QUADSIZE;
111 game.sector.x = w.x - QUADSIZE*(game.quadrant.x-1);
112 game.sector.y = w.y - QUADSIZE*(game.quadrant.y-1);
114 prout(_("Entering %s."), cramlc(quadrant, game.quadrant));
115 game.quad[game.sector.x][game.sector.y] = game.ship;
117 if (game.skill>SKILL_NOVICE) attack(0);
120 iquad = game.quad[w.x][w.y];
121 if (iquad != IHDOT) {
122 /* object encountered in flight path */
123 stopegy = 50.0*game.dist/game.optime;
124 game.dist=0.1*sqrt((game.sector.x-w.x)*(double)(game.sector.x-w.x) +
125 (game.sector.y-w.y)*(double)(game.sector.y-w.y));
127 case IHT: /* Ram a Tholian */
128 case IHK: /* Ram enemy ship */
135 ram(0, iquad, game.sector);
136 finalx = game.sector.x;
137 finaly = game.sector.y;
141 prouts(_("***RED ALERT! RED ALERT!"));
145 proutn(_(" pulled into black hole at "));
146 prout(cramlc(sector, w));
148 * Getting pulled into a black hole was certain
149 * death in Almy's original. Stas Sergeev added a
150 * possibility that you'll get timewarped instead.
153 for (l=0;l<NDEVICES;l++)
154 if (game.damage[l]>0)
156 probf=pow(1.4,(game.energy+game.shield)/5000.0-1.0)*pow(1.3,1.0/(n+1)-1.0);
157 if ((game.options & OPTION_BLKHOLE) && Rand()>probf)
167 proutn(_(" encounters Tholian web at "));
169 proutn(_(" blocked by object at "));
170 proutn(cramlc(sector, w));
172 proutn(_("Emergency stop required "));
173 prout(_("%2d units of energy."), (int)stopegy);
174 game.energy -= stopegy;
175 finalx = x-deltax+0.5;
176 game.sector.x = finalx;
177 finaly = y-deltay+0.5;
178 game.sector.y = finaly;
179 if (game.energy <= 0) {
185 goto no_quad_change; /* sorry! */
188 game.dist = 0.1*sqrt((game.sector.x-w.x)*(double)(game.sector.x-w.x) +
189 (game.sector.y-w.y)*(double)(game.sector.y-w.y));
193 finalx = game.sector.x;
194 finaly = game.sector.y;
196 /* No quadrant change -- compute new avg enemy distances */
197 game.quad[game.sector.x][game.sector.y] = game.ship;
199 for_local_enemies(l) {
200 finald = sqrt((w.x-game.ks[l].x)*(double)(w.x-game.ks[l].x) +
201 (w.y-game.ks[l].y)*(double)(w.y-game.ks[l].y));
202 game.kavgd[l] = 0.5 * (finald+game.kdist[l]);
203 game.kdist[l] = finald;
206 if (!game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova && game.iattak == 0)
208 for_local_enemies(l) game.kavgd[l] = game.kdist[l];
213 setwnd(message_window);
220 if (game.condit == IHDOCKED && l) {
221 prout(_("Already docked."));
225 prout(_("You must first leave standard orbit."));
228 if (game.base.x==0 || abs(game.sector.x-game.base.x) > 1 || abs(game.sector.y-game.base.y) > 1) {
230 prout(_(" not adjacent to base."));
233 game.condit = IHDOCKED;
234 if (l) prout(_("Docked."));
236 if (game.energy < game.inenrg) game.energy = game.inenrg;
237 game.shield = game.inshld;
238 game.torps = game.intorps;
239 game.lsupres = game.inlsr;
240 if (!damaged(DRADIO) &&
241 (is_scheduled(FCDBAS) || game.isatb == 1) && game.iseenit == 0) {
242 /* get attack report from base */
243 prout(_("Lt. Uhura- \"Captain, an important message from the starbase:\""));
249 static void getcd(bool 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=game.quadrant.x, icolq=game.quadrant.y, itemp=0, iprompt=0, key=0;
260 double xi, xj, xk, xl;
261 double deltax, deltay;
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 (automatic == -1) {
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-scaned 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.)"));
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 == 2 && !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;
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() == 0) 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)
494 int blooey=0, twarp=0, iwarp;
497 if (!timewarp) { /* Not WARPX entry */
499 if (game.damage[DWARPEN] > 10.0) {
502 prout(_("Engineer Scott- \"The impulse engines are damaged, Sir.\""));
505 if (damaged(DWARPEN) && game.warpfac > 4.0) {
508 prout(_("Engineer Scott- \"Sorry, Captain. Until this damage"));
509 prout(_(" is repaired, I can only give you warp 4.\""));
513 /* Read in course and distance */
515 if (game.direc == -1.0) return;
517 /* Make sure starship has enough energy for the trip */
518 power = (game.dist+0.05)*game.warpfac*game.warpfac*game.warpfac*(game.shldup+1);
521 if (power >= game.energy) {
522 /* Insufficient power for trip */
525 prout(_("Engineering to bridge--"));
526 if (!game.shldup || 0.5*power > game.energy) {
527 iwarp = pow((game.energy/(game.dist+0.05)), 0.333333333);
529 prout(_("We can't do it, Captain. We don't have enough energy."));
532 proutn(_("We don't have enough energy, but we could do it at warp %d"), iwarp);
535 prout(_("if you'll lower the shields."));
542 prout(_("We haven't the energy to go that far with the shields up."));
546 /* Make sure enough time is left for the trip */
547 game.optime = 10.0*game.dist/game.wfacsq;
548 if (game.optime >= 0.8*game.state.remtime) {
550 prout(_("First Officer Spock- \"Captain, I compute that such"));
551 proutn(_(" a trip would require approximately %2.0f"),
552 100.0*game.optime/game.state.remtime);
553 prout(_(" percent of our"));
554 proutn(_(" remaining time. Are you sure this is wise?\" "));
555 if (ja() == 0) { game.ididit = 0; game.optime=0; return;}
559 if (game.warpfac > 6.0) {
560 /* Decide if engine damage will occur */
561 double prob = game.dist*(6.0-game.warpfac)*(6.0-game.warpfac)/66.666666666;
564 game.dist = Rand()*game.dist;
566 /* Decide if time warp will occur */
567 if (0.5*game.dist*pow(7.0,game.warpfac-10.0) > Rand()) twarp=1;
568 if (idebug && game.warpfac==10 && twarp==0) {
570 proutn("=== Force time warp? ");
571 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-game.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 * game.dist * bigger +0.5;
591 for (l = 1; l <= n; l++) {
596 if (!VALID_SECTOR(ix, iy)) break;
597 if (game.quad[ix][iy] != IHDOT) {
606 /* Activate Warp Engines and pay the cost */
608 if (game.alldone) return;
609 game.energy -= game.dist*game.warpfac*game.warpfac*game.warpfac*(game.shldup+1);
610 if (game.energy <= 0) finish(FNRG);
611 game.optime = 10.0*game.dist/game.wfacsq;
614 game.damage[DWARPEN] = game.damfac*(3.0*Rand()+1.0);
616 prout(_("Engineering to bridge--"));
617 prout(_(" Scott here. The warp engines are damaged."));
618 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 (damaged(DWARPEN) && aaitem > 4.0) {
645 prout(_("Engineer Scott- \"I'm doing my best, Captain,"));
646 prout(_(" 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.\""));
657 oldfac = game.warpfac;
658 game.warpfac = aaitem;
659 game.wfacsq=game.warpfac*game.warpfac;
660 if (game.warpfac <= oldfac || game.warpfac <= 6.0) {
661 proutn(_("Helmsman Sulu- \"Warp factor %d, Captain.\""),
665 if (game.warpfac < 8.00) {
666 prout(_("Engineer Scott- \"Aye, but our maximum safe speed is warp 6.\""));
669 if (game.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)
679 double power, distreq;
682 /* is captain on planet? */
683 if (game.landed==1) {
684 if (damaged(DTRANSP)) {
688 prout(_("Scotty rushes to the transporter controls."));
690 prout(_("But with the shields up it's hopeless."));
693 prouts(_("His desperate attempt to rescue you . . ."));
699 prout(_("SUCCEEDS!"));
702 proutn(_("The crystals mined were "));
703 if (Rand() <= 0.25) {
714 /* Check to see if captain in shuttle craft */
715 if (game.icraft) finish(FSTRACTOR);
716 if (game.alldone) return;
718 /* Inform captain of attempt to reach safety */
722 prouts(_("***RED ALERT! RED ALERT!"));
726 prout(_(" has stopped in a quadrant containing"));
727 prouts(_(" a supernova."));
730 proutn(_("***Emergency automatic override attempts to hurl "));
733 prout(_("safely out of quadrant."));
734 if (!damaged(DRADIO))
735 game.state.galaxy[game.quadrant.x][game.quadrant.y].charted = true;
736 /* Try to use warp engines */
737 if (damaged(DWARPEN)) {
739 prout(_("Warp engines damaged."));
743 game.warpfac = 6.0+2.0*Rand();
744 game.wfacsq = game.warpfac * game.warpfac;
745 prout(_("Warp factor set to %d"), (int)game.warpfac);
746 power = 0.75*game.energy;
747 game.dist = power/(game.warpfac*game.warpfac*game.warpfac*(game.shldup+1));
748 distreq = 1.4142+Rand();
749 if (distreq < game.dist) game.dist = distreq;
750 game.optime = 10.0*game.dist/game.wfacsq;
751 game.direc = 12.0*Rand(); /* How dumb! */
753 game.inorbit = false;
756 /* This is bad news, we didn't leave quadrant. */
757 if (game.alldone) return;
759 prout(_("Insufficient energy to leave quadrant."));
764 /* Repeat if another snova */
765 (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova);
767 finish(FWON); /* Snova killed remaining enemy. */
773 prout(_("***TIME WARP ENTERED."));
774 if (game.state.snap && Rand() < 0.5) {
775 /* Go back in time */
776 prout(_("You are traveling backwards in time %d stardates."),
777 (int)(game.state.date-game.snapsht.date));
778 game.state = game.snapsht;
780 if (game.state.remcom) {
781 schedule(FTBEAM, expran(game.intime/game.state.remcom));
782 schedule(FBATTAK, expran(0.3*game.intime));
784 schedule(FSNOVA, expran(0.5*game.intime));
785 /* next snapshot will be sooner */
786 schedule(FSNAP, expran(0.25*game.state.remtime));
788 if (game.state.nscrem) schedule(FSCMOVE, 0.2777);
792 game.battle.x = game.battle.y = 0;
794 /* Make sure Galileo is consistant -- Snapshot may have been taken
795 when on planet, which would give us two Galileos! */
797 for (l = 0; l < game.inplan; l++) {
798 if (game.state.plnets[l].known == shuttle_down) {
800 if (game.iscraft==1 && game.ship==IHE) {
801 prout(_("Checkov- \"Security reports the Galileo has disappeared, Sir!"));
806 /* Likewise, if in the original time the Galileo was abandoned, but
807 was on ship earlier, it would have vanished -- lets restore it */
808 if (game.iscraft==0 && gotit==0 && game.damage[DSHUTTL] >= 0.0) {
809 prout(_("Checkov- \"Security reports the Galileo has reappeared in the dock!\""));
813 * There used to be code to do the actual reconstrction here,
814 * but the starchart is now part of the snapshotted galaxy state.
816 prout(_("Spock has reconstructed a correct star chart from memory"));
819 /* Go forward in time */
820 game.optime = -0.5*game.intime*log(Rand());
821 prout(_("You are traveling forward in time %d stardates."), (int)game.optime);
822 /* cheat to make sure no tractor beams occur during time warp */
823 postpone(FTBEAM, game.optime);
824 game.damage[DRADIO] += game.optime;
827 events(); /* Stas Sergeev added this -- do pending events */
832 double angle, bigger;
834 /* New code to launch a deep space probe */
835 if (game.nprobes == 0) {
838 if (game.ship == IHE)
839 prout(_("Engineer Scott- \"We have no more deep space probes, Sir.\""));
841 prout(_("Ye Faerie Queene has no deep space probes."));
847 prout(_("Engineer Scott- \"The probe launcher is damaged, Sir.\""));
850 if (is_scheduled(FDSPROB)) {
853 if (damaged(DRADIO) && game.condit != IHDOCKED) {
854 prout(_("Spock- \"Records show the previous probe has not yet"));
855 prout(_(" reached its destination.\""));
858 prout(_("Uhura- \"The previous probe is still reporting data, Sir.\""));
864 /* slow mode, so let Kirk know how many probes there are left */
865 prout(game.nprobes==1 ? _("%d probe left.") : _("%d probes left."), game.nprobes);
866 proutn(_("Are you sure you want to fire a probe? "));
870 game.isarmed = false;
871 if (key == IHALPHA && strcmp(citem,"armed") == 0) {
875 else if (key == IHEOL) {
876 proutn(_("Arm NOVAMAX warhead? "));
880 if (game.direc == -1.0) return;
882 angle = ((15.0 - game.direc) * 0.5235988);
883 game.probeinx = -sin(angle);
884 game.probeiny = cos(angle);
885 if (fabs(game.probeinx) > fabs(game.probeiny))
886 bigger = fabs(game.probeinx);
888 bigger = fabs(game.probeiny);
890 game.probeiny /= bigger;
891 game.probeinx /= bigger;
892 game.proben = 10.0*game.dist*bigger +0.5;
893 game.probex = game.quadrant.x*QUADSIZE + game.sector.x - 1; // We will use better packing than original
894 game.probey = game.quadrant.y*QUADSIZE + game.sector.y - 1;
895 game.probec = game.quadrant;
896 schedule(FDSPROB, 0.01); // Time to move one sector
897 prout(_("Ensign Chekov- \"The deep space probe is launched, Captain.\""));
904 /* There's more than one way to move in this game! */
905 double ddist, xdist, probf;
906 int line = 0, l, ix, iy;
909 /* Test for game.conditions which prevent calling for help */
910 if (game.condit == IHDOCKED) {
911 prout(_("Lt. Uhura- \"But Captain, we're already docked.\""));
914 if (damaged(DRADIO)) {
915 prout(_("Subspace radio damaged."));
918 if (game.state.rembase==0) {
919 prout(_("Lt. Uhura- \"Captain, I'm not getting any response from Starbase.\""));
922 if (game.landed == 1) {
923 proutn(_("You must be aboard the "));
928 /* OK -- call for help from nearest starbase */
930 if (game.base.x!=0) {
931 /* There's one in this quadrant */
932 ddist = sqrt(square(game.base.x-game.sector.x)+square(game.base.y-game.sector.y));
937 xdist=10.0*sqrt(square(game.state.baseq[l].x-game.quadrant.x)+square(game.state.baseq[l].y-game.quadrant.y));
943 /* Since starbase not in quadrant, set up new quadrant */
944 game.quadrant = game.state.baseq[line];
947 /* dematerialize starship */
948 game.quad[game.sector.x][game.sector.y]=IHDOT;
949 proutn(_("Starbase in %s responds--"), cramlc(quadrant, game.quadrant));
952 prout(_(" dematerializes."));
954 for (l = 1; l <= 5; l++) {
955 ix = game.base.x+3.0*Rand()-1;
956 iy = game.base.y+3.0*Rand()-1;
957 if (VALID_SECTOR(ix,iy) && game.quad[ix][iy]==IHDOT) {
958 /* found one -- finish up */
964 if (game.sector.x==0){
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 case 1: game.quad[ix][iy]=IHMATER0;
982 case 2: game.quad[ix][iy]=IHMATER1;
984 case 3: game.quad[ix][iy]=IHMATER2;
989 if (Rand() > probf) break;
995 game.quad[ix][iy]=IHQUEST;
998 setwnd(message_window);
999 finish(FMATERIALIZE);
1002 game.quad[ix][iy]=game.ship;
1004 prout(_("succeeds."));
1008 prout(_("Lt. Uhura- \"Captain, we made it!\""));