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