More de-FORTRANizing of the output code.
[super-star-trek.git] / moving.c
index 9eb70960c277f72971d3d356e0fec83af5253cf4..c48ded55789c8ccbd9c472482910857dc5f21d92 100644 (file)
--- a/moving.c
+++ b/moving.c
@@ -24,14 +24,14 @@ void move(void) {
        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
-       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
@@ -46,11 +46,11 @@ void move(void) {
                                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
@@ -98,14 +98,14 @@ void move(void) {
                                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
-                               quad[sectx][secty] = ship;\r
+                               prout("");\r
+                               prout("Entering %s.",\r
+                                     cramlc(quadrant, quadx, quady));\r
+                               game.quad[sectx][secty] = ship;\r
                                newqad(0);\r
                                return;\r
                        }\r
-                       iquad = 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
@@ -129,9 +129,8 @@ void move(void) {
                                                skip(1);\r
                                                proutn("***");\r
                                                crmshp();\r
-                                               proutn(" pulled into black hole at");\r
-                                               cramlc(2, ix, iy);\r
-                                               skip(1);\r
+                                               proutn(" pulled into black hole at ");\r
+                                               prout(cramlc(sector, ix, iy));\r
                                                finish(FHOLE);\r
                                                return;\r
                                        default:\r
@@ -139,14 +138,13 @@ void move(void) {
                                                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
@@ -170,18 +168,18 @@ void move(void) {
        finaly = secty;\r
 label100:\r
        /* No quadrant change -- compute new avg enemy distances */\r
-       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
@@ -210,7 +208,7 @@ void dock(void) {
        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
@@ -247,7 +245,7 @@ static void getcd(int isprobe, int akey) {
                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
@@ -357,9 +355,8 @@ static void getcd(int isprobe, int akey) {
                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
@@ -410,7 +407,7 @@ void impuls(void) {
        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
@@ -431,8 +428,8 @@ void impuls(void) {
                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
@@ -443,7 +440,7 @@ void impuls(void) {
        }\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
@@ -467,13 +464,13 @@ void warp(int i) {
 \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
@@ -500,10 +497,11 @@ void warp(int i) {
                                        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
@@ -515,11 +513,11 @@ void warp(int i) {
                                                \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
@@ -567,7 +565,7 @@ void warp(int i) {
                                y += deltay;\r
                                iy = y +0.5;\r
                                if (iy < 1 || iy > 10) break;\r
-                               if (quad[ix][iy] != IHDOT) {\r
+                               if (game.quad[ix][iy] != IHDOT) {\r
                                        blooey = 0;\r
                                        twarp = 0;\r
                                }\r
@@ -584,7 +582,7 @@ void warp(int i) {
        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
@@ -609,11 +607,11 @@ void setwrp(void) {
                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
@@ -630,9 +628,8 @@ void setwrp(void) {
        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 %do, Captain.\"", \r
+                       (int)warpfac);\r
                return;\r
        }\r
        if (warpfac < 8.00) {\r
@@ -653,7 +650,7 @@ void atover(int igrab) {
        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
@@ -703,10 +700,10 @@ void atover(int igrab) {
                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
@@ -714,9 +711,7 @@ void atover(int igrab) {
                }\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
@@ -735,37 +730,36 @@ void atover(int igrab) {
                        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
@@ -775,30 +769,28 @@ void timwrp() {
                }\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
@@ -816,16 +808,16 @@ void probe(void) {
                        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
@@ -837,8 +829,7 @@ void probe(void) {
 \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
@@ -870,7 +861,7 @@ void probe(void) {
        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
@@ -886,11 +877,11 @@ void help(void) {
                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
@@ -908,23 +899,22 @@ void help(void) {
        }\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
-       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
@@ -949,12 +939,12 @@ void help(void) {
        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 && 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
-                       quad[ix][iy]=ship;\r
+                       game.quad[ix][iy]=ship;\r
                        dock();\r
                        skip(1);\r
                        prout("Lt. Uhura-  \"Captain, we made it!\"");\r