X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=moving.c;h=ec7bc91b4ca0676f45d481991a654879b84679cd;hp=24c9643e6187cc3e054a4b94ece8d303443b1ff3;hb=cf91699c89b88f76dcf63c60624635184e8cb7eb;hpb=359039abfddd65910747b48f5de6faedd496240e diff --git a/moving.c b/moving.c index 24c9643..ec7bc91 100644 --- a/moving.c +++ b/moving.c @@ -1,11 +1,12 @@ +#include #include "sst.h" static void getcd(int, int); -void move(void) { +void imove(void) { double angle, deltax, deltay, bigger, x, y, - finald, finalx, finaly, stopegy; - int trbeam = 0, n, l, ix, iy, kink, kinks, iquad; + finald, finalx, finaly, stopegy, probf; + int trbeam = 0, n, l, ix=0, iy=0, kink, kinks, iquad; if (inorbit) { prout("Helmsman Sulu- \"Leaving standard orbit.\""); @@ -24,14 +25,14 @@ void move(void) { deltax /= bigger; /* If tractor beam is to occur, don't move full distance */ - if (state.date+Time >= future[FTBEAM]) { + if (game.state.date+Time >= game.future[FTBEAM]) { trbeam = 1; condit = IHRED; - dist = dist*(future[FTBEAM]-state.date)/Time + 0.1; - Time = future[FTBEAM] - state.date + 1e-5; + dist = dist*(game.future[FTBEAM]-game.state.date)/Time + 0.1; + Time = game.future[FTBEAM] - game.state.date + 1e-5; } /* Move within the quadrant */ - frozen.quad[sectx][secty] = IHDOT; + game.quad[sectx][secty] = IHDOT; x = sectx; y = secty; n = 10.0*dist*bigger+0.5; @@ -46,11 +47,11 @@ void move(void) { if (nenhere != 0 && iattak != 2) { newcnd(); for (l = 1; l <= nenhere; l++) { - finald = sqrt((ix-kx[l])*(double)(ix-kx[l]) + - (iy-ky[l])*(double)(iy-ky[l])); - kavgd[l] = 0.5 * (finald+kdist[l]); + finald = sqrt((ix-game.kx[l])*(double)(ix-game.kx[l]) + + (iy-game.ky[l])*(double)(iy-game.ky[l])); + game.kavgd[l] = 0.5 * (finald+game.kdist[l]); } - if (state.galaxy[quadx][quady] != 1000) attack(0); + if (game.state.galaxy[quadx][quady] != 1000) attack(0); if (alldone) return; } /* compute final position -- new quadrant and sector */ @@ -98,14 +99,14 @@ void move(void) { quady = (iy+9)/10; sectx = ix - 10*(quadx-1); secty = iy - 10*(quady-1); - proutn("\nEntering"); - cramlc(1, quadx, quady); - skip(1); - frozen.quad[sectx][secty] = ship; + proutn("\n\rEntering %s.", + cramlc(quadrant, quadx, quady)); + game.quad[sectx][secty] = ship; newqad(0); + if (skill>1) attack(0); return; } - iquad = frozen.quad[ix][iy]; + iquad = game.quad[ix][iy]; if (iquad != IHDOT) { /* object encountered in flight path */ stopegy = 50.0*dist/Time; @@ -117,6 +118,7 @@ void move(void) { case IHC: case IHS: case IHR: + case IHQUEST: sectx = ix; secty = iy; ram(0, iquad, sectx, secty); @@ -129,24 +131,38 @@ void move(void) { skip(1); proutn("***"); crmshp(); - proutn(" pulled into black hole at"); - cramlc(2, ix, iy); - skip(1); - finish(FHOLE); + proutn(" pulled into black hole at "); + prout(cramlc(sector, ix, iy)); + /* + * Getting pulled into a black + * hole was certain death in + * Almy's original. Stas + * Sergeev added a possibility + * that you'll get timewarped + * instead. + */ + n=0; + for (l=1;l<=NDEVICES+1;l++) + if (game.damage[l]>0) n++; + probf=pow(1.4,(energy+shield)/5000.0-1.0)* + pow(1.3,1.0/(n+1)-1.0); + if (Rand()>probf) + timwrp(); + else + finish(FHOLE); return; default: /* something else */ skip(1); crmshp(); if (iquad == IHWEB) - proutn(" encounters Tholian web at"); + proutn(" encounters Tholian web at "); else - proutn(" blocked by object at"); - cramlc(2, ix,iy); + proutn(" blocked by object at "); + proutn(cramlc(sector, ix,iy)); prout(";"); proutn("Emergency stop required "); - cramf(stopegy, 0, 2); - prout(" units of energy."); + prout("%2d units of energy.", (int)stopegy); energy -= stopegy; finalx = x-deltax+0.5; sectx = finalx; @@ -170,27 +186,27 @@ void move(void) { finaly = secty; label100: /* No quadrant change -- compute new avg enemy distances */ - frozen.quad[sectx][secty] = ship; + game.quad[sectx][secty] = ship; if (nenhere) { for (l = 1; l <= nenhere; l++) { - finald = sqrt((ix-kx[l])*(double)(ix-kx[l]) + - (iy-ky[l])*(double)(iy-ky[l])); - kavgd[l] = 0.5 * (finald+kdist[l]); - kdist[l] = finald; + finald = sqrt((ix-game.kx[l])*(double)(ix-game.kx[l]) + + (iy-game.ky[l])*(double)(iy-game.ky[l])); + game.kavgd[l] = 0.5 * (finald+game.kdist[l]); + game.kdist[l] = finald; } sortkl(); - if (state.galaxy[quadx][quady] != 1000 && iattak == 0) + if (game.state.galaxy[quadx][quady] != 1000 && iattak == 0) attack(0); - for (l = 1 ; l <= nenhere; l++) kavgd[l] = kdist[l]; + for (l = 1 ; l <= nenhere; l++) game.kavgd[l] = game.kdist[l]; } newcnd(); iattak = 0; return; } -void dock(void) { +void dock(int l) { chew(); - if (condit == IHDOCKED) { + if (condit == IHDOCKED && l) { prout("Already docked."); return; } @@ -210,10 +226,10 @@ void dock(void) { torps = intorps; lsupres = inlsr; if (stdamtim != 1e30 && - (future[FCDBAS] < 1e30 || isatb == 1) && iseenit == 0) { + (game.future[FCDBAS] < 1e30 || isatb == 1) && iseenit == 0) { /* get attack report from base */ prout("Lt. Uhura- \"Captain, an important message from the starbase:\""); - attakreport(); + attakreport(0); iseenit = 1; } } @@ -228,7 +244,7 @@ static void getcd(int isprobe, int akey) { are always displayed y - x, where +y is downward! */ - int irowq=quadx, icolq=quady, irows, icols, itemp=0, iprompt=0, key; + int irowq=quadx, icolq=quady, irows, icols, itemp=0, iprompt=0, key=0; double xi, xj, xk, xl; double deltax, deltay; int automatic = -1; @@ -247,7 +263,7 @@ static void getcd(int isprobe, int akey) { return; } while (automatic == -1) { - if (damage[DCOMPTR]) { + if (game.damage[DCOMPTR]) { if (isprobe) prout("Computer damaged; manual navigation only"); else @@ -357,9 +373,8 @@ static void getcd(int isprobe, int akey) { if (!isprobe) { if (itemp) { if (iprompt) { - proutn("Helmsman Sulu- \"Course locked in for"); - cramlc(2, irows, icols); - prout(".\""); + proutn("Helmsman Sulu- \"Course locked in for %s.\"", + cramlc(sector, irows, icols)); } } else prout("Ensign Chekov- \"Course laid in, Captain.\""); @@ -410,7 +425,7 @@ void impuls(void) { double power; ididit = 0; - if (damage[DIMPULS]) { + if (game.damage[DIMPULS]) { chew(); skip(1); prout("Engineer Scott- \"The impulse engines are damaged, Sir.\""); @@ -431,8 +446,8 @@ void impuls(void) { prout("First Officer Spock- \"Captain, the impulse engines"); prout("require 20.0 units to engage, plus 100.0 units per"); if (energy > 30) { - proutn("quadrant. We can go, therefore, a maximum of "); - cramf(0.01 * (energy-20.0)-0.05, 0, 1); + proutn("quadrant. We can go, therefore, a maximum of %d", + (int)(0.01 * (energy-20.0)-0.05)); prout(" quadrants.\""); } else { @@ -443,14 +458,14 @@ void impuls(void) { } /* Make sure enough time is left for the trip */ Time = dist/0.095; - if (Time >= state.remtime) { + if (Time >= game.state.remtime) { prout("First Officer Spock- \"Captain, our speed under impulse"); prout("power is only 0.95 sectors per stardate. Are you sure"); - prout("we dare spend the time?\""); + proutn("we dare spend the time?\" "); if (ja() == 0) return; } /* Activate impulse engines and pay the cost */ - move(); + imove(); ididit = 1; if (alldone) return; power = 20.0 + 100.0*dist; @@ -467,13 +482,13 @@ void warp(int i) { if (i!=2) { /* Not WARPX entry */ ididit = 0; - if (damage[DWARPEN] > 10.0) { + if (game.damage[DWARPEN] > 10.0) { chew(); skip(1); prout("Engineer Scott- \"The impulse engines are damaged, Sir.\""); return; } - if (damage[DWARPEN] > 0.0 && warpfac > 4.0) { + if (game.damage[DWARPEN] > 0.0 && warpfac > 4.0) { chew(); skip(1); prout("Engineer Scott- \"Sorry, Captain. Until this damage"); @@ -500,10 +515,11 @@ void warp(int i) { prout("We can't do it, Captain. We haven't the energy."); } else { - proutn("We haven't the energy, but we could do it at warp "); - crami(iwarp, 1); - if (shldup) - prout(",\nif you'll lower the shields."); + proutn("We haven't the energy, but we could do it at warp %d", iwarp); + if (shldup) { + prout(","); + prout("if you'll lower the shields."); + } else prout("."); } @@ -515,14 +531,14 @@ void warp(int i) { /* Make sure enough time is left for the trip */ Time = 10.0*dist/wfacsq; - if (Time >= 0.8*state.remtime) { + if (Time >= 0.8*game.state.remtime) { skip(1); prout("First Officer Spock- \"Captain, I compute that such"); - proutn(" a trip would require approximately "); - cramf(100.0*Time/state.remtime, 0, 2); + proutn(" a trip would require approximately %2.0f", + 100.0*Time/game.state.remtime); prout(" percent of our"); - prout(" remaining time. Are you sure this is wise?\""); - if (ja() == 0) { ididit = 0; return;} + proutn(" remaining time. Are you sure this is wise?\" "); + if (ja() == 0) { ididit = 0; Time=0; return;} } } /* Entry WARPX */ @@ -567,7 +583,7 @@ void warp(int i) { y += deltay; iy = y +0.5; if (iy < 1 || iy > 10) break; - if (frozen.quad[ix][iy] != IHDOT) { + if (game.quad[ix][iy] != IHDOT) { blooey = 0; twarp = 0; } @@ -577,14 +593,14 @@ void warp(int i) { /* Activate Warp Engines and pay the cost */ - move(); + imove(); if (alldone) return; energy -= dist*warpfac*warpfac*warpfac*(shldup+1); if (energy <= 0) finish(FNRG); Time = 10.0*dist/wfacsq; if (twarp) timwrp(); if (blooey) { - damage[DWARPEN] = damfac*(3.0*Rand()+1.0); + game.damage[DWARPEN] = damfac*(3.0*Rand()+1.0); skip(1); prout("Engineering to bridge--"); prout(" Scott here. The warp engines are damaged."); @@ -602,18 +618,18 @@ void setwrp(void) { while ((key=scan()) == IHEOL) { chew(); - proutn("Warp factor-"); + proutn("Warp factor- "); } chew(); if (key != IHREAL) { huh(); return; } - if (damage[DWARPEN] > 10.0) { + if (game.damage[DWARPEN] > 10.0) { prout("Warp engines inoperative."); return; } - if (damage[DWARPEN] > 0.0 && aaitem > 4.0) { + if (game.damage[DWARPEN] > 0.0 && aaitem > 4.0) { prout("Engineer Scott- \"I'm doing my best, Captain,\n" " but right now we can only go warp 4.\""); return; @@ -630,9 +646,8 @@ void setwrp(void) { warpfac = aaitem; wfacsq=warpfac*warpfac; if (warpfac <= oldfac || warpfac <= 6.0) { - proutn("Helmsman Sulu- \"Warp factor "); - cramf(warpfac, 0, 1); - prout(", Captain.\""); + proutn("Helmsman Sulu- \"Warp factor %d, Captain.\"", + (int)warpfac); return; } if (warpfac < 8.00) { @@ -653,7 +668,7 @@ void atover(int igrab) { chew(); /* is captain on planet? */ if (landed==1) { - if (damage[DTRANSP]) { + if (game.damage[DTRANSP]) { finish(FPNOVA); return; } @@ -703,10 +718,10 @@ void atover(int igrab) { crmshp(); skip(1); prout("safely out of quadrant."); - starch[quadx][quady] = damage[DRADIO] > 0.0 ? state.galaxy[quadx][quady]+1000:1; + game.starch[quadx][quady] = game.damage[DRADIO] > 0.0 ? game.state.galaxy[quadx][quady]+1000:1; /* Try to use warp engines */ - if (damage[DWARPEN]) { + if (game.damage[DWARPEN]) { skip(1); prout("Warp engines damaged."); finish(FSNOVAED); @@ -714,9 +729,7 @@ void atover(int igrab) { } warpfac = 6.0+2.0*Rand(); wfacsq = warpfac * warpfac; - proutn("Warp factor set to "); - cramf(warpfac, 1, 1); - skip(1); + prout("Warp factor set to %d", (int)warpfac); power = 0.75*energy; dist = power/(warpfac*warpfac*warpfac*(shldup+1)); distreq = 1.4142+Rand(); @@ -735,37 +748,36 @@ void atover(int igrab) { return; } /* Repeat if another snova */ - } while (state.galaxy[quadx][quady] == 1000); - if (state.remkl==0) finish(FWON); /* Snova killed remaining enemy. */ + } while (game.state.galaxy[quadx][quady] == 1000); + if (game.state.remkl==0) finish(FWON); /* Snova killed remaining enemy. */ } void timwrp() { int l, ll, gotit; prout("***TIME WARP ENTERED."); - if (state.snap && Rand() < 0.5) { + if (game.state.snap && Rand() < 0.5) { /* Go back in time */ - proutn("You are traveling backwards in time "); - cramf(state.date-snapsht.date, 0, 2); - prout(" stardates."); - state = snapsht; - state.snap = 0; - if (state.remcom) { - future[FTBEAM] = state.date + expran(intime/state.remcom); - future[FBATTAK] = state.date + expran(0.3*intime); - } - future[FSNOVA] = state.date + expran(0.5*intime); - future[FSNAP] = state.date +expran(0.25*state.remtime); /* next snapshot will + prout("You are traveling backwards in time %d stardates.", + (int)(game.state.date-game.snapsht.date)); + game.state = game.snapsht; + game.state.snap = 0; + if (game.state.remcom) { + game.future[FTBEAM] = game.state.date + expran(intime/game.state.remcom); + game.future[FBATTAK] = game.state.date + expran(0.3*intime); + } + game.future[FSNOVA] = game.state.date + expran(0.5*intime); + game.future[FSNAP] = game.state.date +expran(0.25*game.state.remtime); /* next snapshot will be sooner */ - if (state.nscrem) future[FSCMOVE] = 0.2777; + if (game.state.nscrem) game.future[FSCMOVE] = 0.2777; isatb = 0; - future[FCDBAS] = future[FSCDBAS] = 1e30; + game.future[FCDBAS] = game.future[FSCDBAS] = 1e30; batx = baty = 0; /* Make sure Galileo is consistant -- Snapshot may have been taken when on planet, which would give us two Galileos! */ gotit = 0; - for (l = 1; l <= inplan; l++) { - if (state.plnets[l].known == 2) { + for (l = 0; l < inplan; l++) { + if (game.state.plnets[l].known == shuttle_down) { gotit = 1; if (iscraft==1 && ship==IHE) { prout("Checkov- \"Security reports the Galileo has disappeared, Sir!"); @@ -775,30 +787,28 @@ void timwrp() { } /* Likewise, if in the original time the Galileo was abandoned, but was on ship earlier, it would have vanished -- lets restore it */ - if (iscraft==0 && gotit==0 && damage[DSHUTTL] >= 0.0) { + if (iscraft==0 && gotit==0 && game.damage[DSHUTTL] >= 0.0) { prout("Checkov- \"Security reports the Galileo has reappeared in the dock!\""); iscraft = 1; } /* Revert star chart to earlier era, if it was known then*/ - if (damage[DRADIO]==0.0 || stdamtim > state.date) { + if (game.damage[DRADIO]==0.0 || stdamtim > game.state.date) { for (l = 1; l <= 8; l++) for (ll = 1; ll <= 8; ll++) - if (starch[l][ll] > 1) - starch[l][ll]=damage[DRADIO]>0.0 ? state.galaxy[l][ll]+1000 :1; + if (game.starch[l][ll] > 1) + game.starch[l][ll]=game.damage[DRADIO]>0.0 ? game.state.galaxy[l][ll]+1000 :1; prout("Spock has reconstructed a correct star chart from memory"); - if (damage[DRADIO] > 0.0) stdamtim = state.date; + if (game.damage[DRADIO] > 0.0) stdamtim = game.state.date; } } else { /* Go forward in time */ Time = -0.5*intime*log(Rand()); - proutn("You are traveling forward in time "); - cramf(Time, 1, 2); - prout(" stardates."); + prout("You are traveling forward in time %d stardates.", (int)Time); /* cheat to make sure no tractor beams occur during time warp */ - future[FTBEAM] += Time; - damage[DRADIO] += Time; + game.future[FTBEAM] += Time; + game.damage[DRADIO] += Time; } newqad(0); } @@ -816,16 +826,16 @@ void probe(void) { prout("Ye Faerie Queene has no deep space probes."); return; } - if (damage[DDSP] != 0.0) { + if (game.damage[DDSP] != 0.0) { chew(); skip(1); prout("Engineer Scott- \"The probe launcher is damaged, Sir.\""); return; } - if (future[FDSPROB] != 1e30) { + if (game.future[FDSPROB] != 1e30) { chew(); skip(1); - if (damage[DRADIO] != 0 && condit != IHDOCKED) { + if (game.damage[DRADIO] != 0 && condit != IHDOCKED) { prout("Spock- \"Records show the previous probe has not yet"); prout(" reached its destination.\""); } @@ -837,8 +847,7 @@ void probe(void) { if (key == IHEOL) { /* slow mode, so let Kirk know how many probes there are left */ - crami(nprobes,1); - prout(nprobes==1 ? " probe left." : " probes left."); + prout(nprobes==1 ? "%d probe left." : "%d probes left.", nprobes); proutn("Are you sure you want to fire a probe? "); if (ja()==0) return; } @@ -849,7 +858,7 @@ void probe(void) { key = scan(); } else if (key == IHEOL) { - proutn("Arm NOVAMAX warhead?"); + proutn("Arm NOVAMAX warhead? "); isarmed = ja(); } getcd(TRUE, key); @@ -870,7 +879,7 @@ void probe(void) { probey = quady*10 + secty - 1; probecx = quadx; probecy = quady; - future[FDSPROB] = state.date + 0.01; // Time to move one sector + game.future[FDSPROB] = game.state.date + 0.01; // Time to move one sector prout("Ensign Chekov- \"The deep space probe is launched, Captain.\""); return; } @@ -886,11 +895,11 @@ void help(void) { prout("Lt. Uhura- \"But Captain, we're already docked.\""); return; } - if (damage[DRADIO] != 0) { + if (game.damage[DRADIO] != 0) { prout("Subspace radio damaged."); return; } - if (state.rembase==0) { + if (game.state.rembase==0) { prout("Lt. Uhura- \"Captain, I'm not getting any response from Starbase.\""); return; } @@ -908,23 +917,22 @@ void help(void) { } else { ddist = 1e30; - for (l = 1; l <= state.rembase; l++) { - xdist=10.0*sqrt(square(state.baseqx[l]-quadx)+square(state.baseqy[l]-quady)); + for (l = 1; l <= game.state.rembase; l++) { + xdist=10.0*sqrt(square(game.state.baseqx[l]-quadx)+square(game.state.baseqy[l]-quady)); if (xdist < ddist) { ddist = xdist; line = l; } } /* Since starbase not in quadrant, set up new quadrant */ - quadx = state.baseqx[line]; - quady = state.baseqy[line]; + quadx = game.state.baseqx[line]; + quady = game.state.baseqy[line]; newqad(1); } /* dematerialize starship */ - frozen.quad[sectx][secty]=IHDOT; - proutn("Starbase in"); - cramlc(1, quadx, quady); - proutn(" responds--"); + game.quad[sectx][secty]=IHDOT; + proutn("Starbase in %s responds--", cramlc(quadrant, quadx, quady)); + proutn(""); crmshp(); prout(" dematerializes."); /* Give starbase three chances to rematerialize starship */ @@ -949,13 +957,13 @@ void help(void) { for (l = 1; l <= 5; l++) { ix = basex+3.0*Rand()-1; iy = basey+3.0*Rand()-1; - if (ix>=1 && ix<=10 && iy>=1 && iy<=10 && frozen.quad[ix][iy]==IHDOT) { + if (ix>=1 && ix<=10 && iy>=1 && iy<=10 && game.quad[ix][iy]==IHDOT) { /* found one -- finish up */ prout("succeeds."); sectx=ix; secty=iy; - frozen.quad[ix][iy]=ship; - dock(); + game.quad[ix][iy]=ship; + dock(0); skip(1); prout("Lt. Uhura- \"Captain, we made it!\""); return;