Another step in consolidating the saved-state globals.
[super-star-trek.git] / moving.c
index 0f53518da8b334475627d6881e59ddeb999ced82..2fdefb66d5cbab249519967b2e31c4cb5144e069 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 >= frozen.future[FTBEAM]) {\r
+       if (game.state.date+Time >= game.future[FTBEAM]) {\r
                trbeam = 1;\r
                condit = IHRED;\r
-               dist = dist*(frozen.future[FTBEAM]-state.date)/Time + 0.1;\r
-               Time = frozen.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
@@ -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-frozen.kx[l])*(double)(ix-frozen.kx[l]) +\r
-                                                                         (iy-frozen.ky[l])*(double)(iy-frozen.ky[l]));\r
-                                               frozen.kavgd[l] = 0.5 * (finald+frozen.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
@@ -101,11 +101,11 @@ void move(void) {
                                proutn("\nEntering");\r
                                cramlc(1, quadx, quady);\r
                                skip(1);\r
-                               frozen.quad[sectx][secty] = ship;\r
+                               game.quad[sectx][secty] = ship;\r
                                newqad(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
@@ -170,18 +170,18 @@ void move(void) {
        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-frozen.kx[l])*(double)(ix-frozen.kx[l]) +\r
-                                                 (iy-frozen.ky[l])*(double)(iy-frozen.ky[l]));\r
-                       frozen.kavgd[l] = 0.5 * (finald+frozen.kdist[l]);\r
-                       frozen.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++) frozen.kavgd[l] = frozen.kdist[l];\r
+               for (l = 1 ; l <= nenhere; l++) game.kavgd[l] = game.kdist[l];\r
        }\r
        newcnd();\r
        iattak = 0;\r
@@ -210,7 +210,7 @@ void dock(void) {
        torps = intorps;\r
        lsupres = inlsr;\r
        if (stdamtim != 1e30 &&\r
-               (frozen.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 +247,7 @@ static void getcd(int isprobe, int akey) {
                return;\r
        }\r
        while (automatic == -1) {\r
-               if (frozen.damage[DCOMPTR]) {\r
+               if (game.damage[DCOMPTR]) {\r
                        if (isprobe)\r
                                prout("Computer damaged; manual navigation only");\r
                        else\r
@@ -410,7 +410,7 @@ void impuls(void) {
        double power;\r
 \r
        ididit = 0;\r
-       if (frozen.damage[DIMPULS]) {\r
+       if (game.damage[DIMPULS]) {\r
                chew();\r
                skip(1);\r
                prout("Engineer Scott- \"The impulse engines are damaged, Sir.\"");\r
@@ -443,7 +443,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 +467,13 @@ void warp(int i) {
 \r
        if (i!=2) { /* Not WARPX entry */\r
                ididit = 0;\r
-               if (frozen.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 (frozen.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
@@ -515,11 +515,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
+                       cramf(100.0*Time/game.state.remtime, 0, 2);\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 +567,7 @@ void warp(int i) {
                                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
@@ -584,7 +584,7 @@ void warp(int i) {
        Time = 10.0*dist/wfacsq;\r
        if (twarp) timwrp();\r
        if (blooey) {\r
-               frozen.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 +609,11 @@ void setwrp(void) {
                huh();\r
                return;\r
        }\r
-       if (frozen.damage[DWARPEN] > 10.0) {\r
+       if (game.damage[DWARPEN] > 10.0) {\r
                prout("Warp engines inoperative.");\r
                return;\r
        }\r
-       if (frozen.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
@@ -653,7 +653,7 @@ void atover(int igrab) {
        chew();\r
        /* is captain on planet? */\r
        if (landed==1) {\r
-               if (frozen.damage[DTRANSP]) {\r
+               if (game.damage[DTRANSP]) {\r
                        finish(FPNOVA);\r
                        return;\r
                }\r
@@ -703,10 +703,10 @@ void atover(int igrab) {
                crmshp();\r
                skip(1);\r
                prout("safely out of quadrant.");\r
-               frozen.starch[quadx][quady] = frozen.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 (frozen.damage[DWARPEN]) {\r
+               if (game.damage[DWARPEN]) {\r
                        skip(1);\r
                        prout("Warp engines damaged.");\r
                        finish(FSNOVAED);\r
@@ -735,37 +735,37 @@ 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
+               cramf(game.state.date-game.snapsht.date, 0, 2);\r
                prout(" stardates.");\r
-               state = snapsht;\r
-               state.snap = 0;\r
-               if (state.remcom) {\r
-                       frozen.future[FTBEAM] = state.date + expran(intime/state.remcom);\r
-                       frozen.future[FBATTAK] = state.date + expran(0.3*intime);\r
-               }\r
-               frozen.future[FSNOVA] = state.date + expran(0.5*intime);\r
-               frozen.future[FSNAP] = state.date +expran(0.25*state.remtime); /* next snapshot will\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) frozen.future[FSCMOVE] = 0.2777;\r
+               if (game.state.nscrem) game.future[FSCMOVE] = 0.2777;\r
                isatb = 0;\r
-               frozen.future[FCDBAS] = frozen.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
+                       if (game.state.plnets[l].known == 2) {\r
                                gotit = 1;\r
                                if (iscraft==1 && ship==IHE) {\r
                                        prout("Checkov-  \"Security reports the Galileo has disappeared, Sir!");\r
@@ -775,19 +775,19 @@ 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 && frozen.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 (frozen.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 (frozen.starch[l][ll] > 1)\r
-                                               frozen.starch[l][ll]=frozen.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 (frozen.damage[DRADIO] > 0.0) stdamtim = state.date;\r
+                       if (game.damage[DRADIO] > 0.0) stdamtim = game.state.date;\r
                }\r
        }\r
        else {\r
@@ -797,8 +797,8 @@ void timwrp() {
                cramf(Time, 1, 2);\r
                prout(" stardates.");\r
                /* cheat to make sure no tractor beams occur during time warp */\r
-               frozen.future[FTBEAM] += Time;\r
-               frozen.damage[DRADIO] += Time;\r
+               game.future[FTBEAM] += Time;\r
+               game.damage[DRADIO] += Time;\r
        }\r
        newqad(0);\r
 }\r
@@ -816,16 +816,16 @@ void probe(void) {
                        prout("Ye Faerie Queene has no deep space probes.");\r
                return;\r
        }\r
-       if (frozen.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 (frozen.future[FDSPROB] != 1e30) {\r
+       if (game.future[FDSPROB] != 1e30) {\r
                chew();\r
                skip(1);\r
-               if (frozen.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
@@ -870,7 +870,7 @@ void probe(void) {
        probey = quady*10 + secty - 1;\r
        probecx = quadx;\r
        probecy = quady;\r
-       frozen.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 +886,11 @@ void help(void) {
                prout("Lt. Uhura-  \"But Captain, we're already docked.\"");\r
                return;\r
        }\r
-       if (frozen.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,20 +908,20 @@ 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
-       frozen.quad[sectx][secty]=IHDOT;\r
+       game.quad[sectx][secty]=IHDOT;\r
        proutn("Starbase in");\r
        cramlc(1, quadx, quady);\r
        proutn(" responds--");\r
@@ -949,12 +949,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 && 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
+                       game.quad[ix][iy]=ship;\r
                        dock();\r
                        skip(1);\r
                        prout("Lt. Uhura-  \"Captain, we made it!\"");\r