X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=moving.c;h=c48ded55789c8ccbd9c472482910857dc5f21d92;hp=0f53518da8b334475627d6881e59ddeb999ced82;hb=7d27c8befdb5de9a50ff4af88e764c8336bc1797;hpb=eaf59bc9a6f0a5c917df2f51be128ae29ba6a595 diff --git a/moving.c b/moving.c index 0f53518..c48ded5 100644 --- a/moving.c +++ b/moving.c @@ -24,14 +24,14 @@ void move(void) { deltax /= bigger; /* If tractor beam is to occur, don't move full distance */ - if (state.date+Time >= frozen.future[FTBEAM]) { + if (game.state.date+Time >= game.future[FTBEAM]) { trbeam = 1; condit = IHRED; - dist = dist*(frozen.future[FTBEAM]-state.date)/Time + 0.1; - Time = frozen.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 +46,11 @@ void move(void) { if (nenhere != 0 && iattak != 2) { newcnd(); for (l = 1; l <= nenhere; l++) { - finald = sqrt((ix-frozen.kx[l])*(double)(ix-frozen.kx[l]) + - (iy-frozen.ky[l])*(double)(iy-frozen.ky[l])); - frozen.kavgd[l] = 0.5 * (finald+frozen.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 +98,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; + prout(""); + prout("Entering %s.", + cramlc(quadrant, quadx, quady)); + game.quad[sectx][secty] = ship; newqad(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; @@ -129,9 +129,8 @@ void move(void) { skip(1); proutn("***"); crmshp(); - proutn(" pulled into black hole at"); - cramlc(2, ix, iy); - skip(1); + proutn(" pulled into black hole at "); + prout(cramlc(sector, ix, iy)); finish(FHOLE); return; default: @@ -139,14 +138,13 @@ void move(void) { 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,18 +168,18 @@ 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-frozen.kx[l])*(double)(ix-frozen.kx[l]) + - (iy-frozen.ky[l])*(double)(iy-frozen.ky[l])); - frozen.kavgd[l] = 0.5 * (finald+frozen.kdist[l]); - frozen.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++) frozen.kavgd[l] = frozen.kdist[l]; + for (l = 1 ; l <= nenhere; l++) game.kavgd[l] = game.kdist[l]; } newcnd(); iattak = 0; @@ -210,7 +208,7 @@ void dock(void) { torps = intorps; lsupres = inlsr; if (stdamtim != 1e30 && - (frozen.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(); @@ -247,7 +245,7 @@ static void getcd(int isprobe, int akey) { return; } while (automatic == -1) { - if (frozen.damage[DCOMPTR]) { + if (game.damage[DCOMPTR]) { if (isprobe) prout("Computer damaged; manual navigation only"); else @@ -357,9 +355,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 +407,7 @@ void impuls(void) { double power; ididit = 0; - if (frozen.damage[DIMPULS]) { + if (game.damage[DIMPULS]) { chew(); skip(1); prout("Engineer Scott- \"The impulse engines are damaged, Sir.\""); @@ -431,8 +428,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,7 +440,7 @@ 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?\""); @@ -467,13 +464,13 @@ void warp(int i) { if (i!=2) { /* Not WARPX entry */ ididit = 0; - if (frozen.damage[DWARPEN] > 10.0) { + if (game.damage[DWARPEN] > 10.0) { chew(); skip(1); prout("Engineer Scott- \"The impulse engines are damaged, Sir.\""); return; } - if (frozen.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 +497,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,11 +513,11 @@ 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;} @@ -567,7 +565,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; } @@ -584,7 +582,7 @@ void warp(int i) { Time = 10.0*dist/wfacsq; if (twarp) timwrp(); if (blooey) { - frozen.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."); @@ -609,11 +607,11 @@ void setwrp(void) { huh(); return; } - if (frozen.damage[DWARPEN] > 10.0) { + if (game.damage[DWARPEN] > 10.0) { prout("Warp engines inoperative."); return; } - if (frozen.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 +628,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 %do, Captain.\"", + (int)warpfac); return; } if (warpfac < 8.00) { @@ -653,7 +650,7 @@ void atover(int igrab) { chew(); /* is captain on planet? */ if (landed==1) { - if (frozen.damage[DTRANSP]) { + if (game.damage[DTRANSP]) { finish(FPNOVA); return; } @@ -703,10 +700,10 @@ void atover(int igrab) { crmshp(); skip(1); prout("safely out of quadrant."); - frozen.starch[quadx][quady] = frozen.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 (frozen.damage[DWARPEN]) { + if (game.damage[DWARPEN]) { skip(1); prout("Warp engines damaged."); finish(FSNOVAED); @@ -714,9 +711,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 +730,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) { - frozen.future[FTBEAM] = state.date + expran(intime/state.remcom); - frozen.future[FBATTAK] = state.date + expran(0.3*intime); - } - frozen.future[FSNOVA] = state.date + expran(0.5*intime); - frozen.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) frozen.future[FSCMOVE] = 0.2777; + if (game.state.nscrem) game.future[FSCMOVE] = 0.2777; isatb = 0; - frozen.future[FCDBAS] = frozen.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 +769,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 && frozen.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 (frozen.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 (frozen.starch[l][ll] > 1) - frozen.starch[l][ll]=frozen.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 (frozen.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 */ - frozen.future[FTBEAM] += Time; - frozen.damage[DRADIO] += Time; + game.future[FTBEAM] += Time; + game.damage[DRADIO] += Time; } newqad(0); } @@ -816,16 +808,16 @@ void probe(void) { prout("Ye Faerie Queene has no deep space probes."); return; } - if (frozen.damage[DDSP] != 0.0) { + if (game.damage[DDSP] != 0.0) { chew(); skip(1); prout("Engineer Scott- \"The probe launcher is damaged, Sir.\""); return; } - if (frozen.future[FDSPROB] != 1e30) { + if (game.future[FDSPROB] != 1e30) { chew(); skip(1); - if (frozen.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 +829,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; } @@ -870,7 +861,7 @@ void probe(void) { probey = quady*10 + secty - 1; probecx = quadx; probecy = quady; - frozen.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 +877,11 @@ void help(void) { prout("Lt. Uhura- \"But Captain, we're already docked.\""); return; } - if (frozen.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 +899,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,12 +939,12 @@ 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; + game.quad[ix][iy]=ship; dock(); skip(1); prout("Lt. Uhura- \"Captain, we made it!\"");