More magic-number hunting -- BASEMAX this time.
[super-star-trek.git] / moving.c
index 05c3d3ab95761cf83e570d13d7220b3d4aeed39c..ac368e159226fd310b7183612c5a3cfa8c8b48f6 100644 (file)
--- a/moving.c
+++ b/moving.c
@@ -1,4 +1,5 @@
 #include <unistd.h>
+#include "sstlinux.h"
 #include "sst.h"
 
 static void getcd(int, int);
@@ -41,7 +42,7 @@ void imove(void) {
                for (l = 1; l <= n; l++) {
                        ix = (x += deltax) + 0.5;
                        iy = (y += deltay) + 0.5;
-                       if (ix < 1 || ix > 10 || iy < 1 || iy > 10) {
+                       if (ix < 1 || ix > QUADSIZE || iy < 1 || iy > QUADSIZE) {
                                /* Leaving quadrant -- allow final enemy attack */
                                /* Don't do it if being pushed by Nova */
                                if (nenhere != 0 && iattak != 2) {
@@ -51,12 +52,18 @@ void imove(void) {
                                                                          (iy-game.ky[l])*(double)(iy-game.ky[l]));
                                                game.kavgd[l] = 0.5 * (finald+game.kdist[l]);
                                        }
-                                       if (game.state.galaxy[quadx][quady] != 1000) attack(0);
+                                       /*
+                                        * Stas Sergeev added the condition
+                                        * that attacks only happen if Klingons
+                                        * are present and your skill is > 3.
+                                        */
+                                        if (skill > 3 && klhere > 0 && game.state.galaxy[quadx][quady] != 1000)
+                                           attack(0);
                                        if (alldone) return;
                                }
                                /* compute final position -- new quadrant and sector */
-                               x = 10*(quadx-1)+sectx;
-                               y = 10*(quady-1)+secty;
+                               x = QUADSIZE*(quadx-1)+sectx;
+                               y = QUADSIZE*(quady-1)+secty;
                                ix = x+10.0*dist*bigger*deltax+0.5;
                                iy = y+10.0*dist*bigger*deltay+0.5;
                                /* check for edge of galaxy */
@@ -71,11 +78,11 @@ void imove(void) {
                                                iy = -iy + 1;
                                                kink = 1;
                                        }
-                                       if (ix > 80) {
+                                       if (ix > GALSIZE*QUADSIZE) {
                                                ix = 161 - ix;
                                                kink = 1;
                                        }
-                                       if (iy > 80) {
+                                       if (iy > GALSIZE*QUADSIZE) {
                                                iy = 161 - iy;
                                                kink = 1;
                                        }
@@ -89,17 +96,17 @@ void imove(void) {
                                                finish(FNEG3);
                                                return;
                                        }
-                                       prout("\nYOU HAVE ATTEMPTED TO CROSS THE NEGATIVE ENERGY BARRIER\n"
-                                                "AT THE EDGE OF THE GALAXY.  THE THIRD TIME YOU TRY THIS,\n"
-                                                "YOU WILL BE DESTROYED.\n");
+                                        prout("\n\rYOU HAVE ATTEMPTED TO CROSS THE NEGATIVE ENERGY BARRIER\n\r"
+                                                 "AT THE EDGE OF THE GALAXY.  THE THIRD TIME YOU TRY THIS,\n\r"
+                                                 "YOU WILL BE DESTROYED.\n\r");
                                }
                                /* Compute final position in new quadrant */
                                if (trbeam) return; /* Don't bother if we are to be beamed */
-                               quadx = (ix+9)/10;
-                               quady = (iy+9)/10;
-                               sectx = ix - 10*(quadx-1);
-                               secty = iy - 10*(quady-1);
-                               proutn("\n\rEntering %s.",
+                               quadx = (ix+9)/QUADSIZE;
+                               quady = (iy+9)/QUADSIZE;
+                               sectx = ix - QUADSIZE*(quadx-1);
+                               secty = iy - QUADSIZE*(quady-1);
+                               prout("\n\rEntering %s.",
                                      cramlc(quadrant, quadx, quady));
                                game.quad[sectx][secty] = ship;
                                newqad(0);
@@ -201,9 +208,7 @@ label100:
        }
        newcnd();
        iattak = 0;
-#ifdef SERGEEV
        drawmaps(0);
-#endif /* SERGEEV */
        return;
 }
 
@@ -368,8 +373,8 @@ static void getcd(int isprobe, int akey) {
                        }
                        itemp = 1;
                }
-               if (irowq<1 || irowq > 8 || icolq<1 || icolq > 8 ||
-                       irows<1 || irows > 10 || icols<1 || icols > 10) {
+               if (irowq<1 || irowq > GALSIZE || icolq<1 || icolq > GALSIZE ||
+                       irows<1 || irows > QUADSIZE || icols<1 || icols > QUADSIZE) {
                                huh();
                                return;
                        }
@@ -377,7 +382,7 @@ static void getcd(int isprobe, int akey) {
                if (!isprobe) {
                        if (itemp) {
                                if (iprompt) {
-                                       proutn("Helmsman Sulu- \"Course locked in for %s.\"",
+                                       prout("Helmsman Sulu- \"Course locked in for %s.\"",
                                                cramlc(sector, irows, icols));
                                }
                        }
@@ -583,10 +588,10 @@ void warp(int i) {
                        for (l = 1; l <= n; l++) {
                                x += deltax;
                                ix = x + 0.5;
-                               if (ix < 1 || ix > 10) break;
+                               if (ix < 1 || ix > QUADSIZE) break;
                                y += deltay;
                                iy = y +0.5;
-                               if (iy < 1 || iy > 10) break;
+                               if (iy < 1 || iy > QUADSIZE) break;
                                if (game.quad[ix][iy] != IHDOT) {
                                        blooey = 0;
                                        twarp = 0;
@@ -798,8 +803,8 @@ void timwrp() {
 
                /* Revert star chart to earlier era, if it was known then*/
                if (game.damage[DRADIO]==0.0 || stdamtim > game.state.date) {
-                       for (l = 1; l <= 8; l++)
-                               for (ll = 1; ll <= 8; ll++)
+                       for (l = 1; l <= GALSIZE; l++)
+                               for (ll = 1; ll <= GALSIZE; ll++)
                                        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");
@@ -815,9 +820,7 @@ void timwrp() {
                game.damage[DRADIO] += Time;
        }
        newqad(0);
-#ifdef SERGEEV
-        events();
-#endif /* SERGEEV */
+        events();      /* Stas Sergeev added this -- do pending events */
 }
 
 void probe(void) {
@@ -882,8 +885,8 @@ void probe(void) {
        probeiny /= bigger;
        probeinx /= bigger;
        proben = 10.0*dist*bigger +0.5;
-       probex = quadx*10 + sectx - 1;  // We will use better packing than original
-       probey = quady*10 + secty - 1;
+       probex = quadx*QUADSIZE + sectx - 1;    // We will use better packing than original
+       probey = quady*QUADSIZE + secty - 1;
        probecx = quadx;
        probecy = quady;
        game.future[FDSPROB] = game.state.date + 0.01; // Time to move one sector
@@ -896,9 +899,6 @@ void help(void) {
        /* There's more than one way to move in this game! */
        double ddist, xdist, probf;
        int line = 0, l, ix, iy;
-#ifdef SERGEEV
-       int pox, posy;
-#endif /* SERGEEV */
 
        chew();
        /* Test for conditions which prevent calling for help */
@@ -946,12 +946,11 @@ void help(void) {
        proutn("");
        crmshp();
        prout(" dematerializes.");
-#ifdef SERGEEV
         sectx=0;
         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 && game.quad[ix][iy]==IHDOT) {
+                if (ix>=1 && ix<=QUADSIZE && iy>=1 && iy<=QUADSIZE && game.quad[ix][iy]==IHDOT) {
                         /* found one -- finish up */
                         sectx=ix;
                         secty=iy;
@@ -964,7 +963,6 @@ void help(void) {
            finish(FMATERIALIZE);
            return;
         }
-#endif /* SERGEEV */
        /* Give starbase three chances to rematerialize starship */
        probf = pow((1.0 - pow(0.98,ddist)), 0.33333333);
        for (l = 1; l <= 3; l++) {
@@ -975,30 +973,30 @@ void help(void) {
                }
                proutn(" attempt to re-materialize ");
                crmshp();
-               prouts(" . . . . . ");
+               warble();
                if (Rand() > probf) break;
+                switch (l){
+                       case 1: game.quad[ix][iy]=IHMATER1;
+                               break;
+                       case 2: game.quad[ix][iy]=IHMATER2;
+                               break;
+                       case 3: game.quad[ix][iy]=IHQUEST;
+                               break;
+                }
+                textcolor(RED);
                prout("fails.");
+                delay(500);
+                textcolor(DEFAULT);
        }
        if (l > 3) {
                finish(FMATERIALIZE);
                return;
        }
-       /* Rematerialization attempt should succeed if can get adj to base */
-       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 && game.quad[ix][iy]==IHDOT) {
-                       /* found one -- finish up */
-                       prout("succeeds.");
-                       sectx=ix;
-                       secty=iy;
-                       game.quad[ix][iy]=ship;
-                       dock(0);
-                       skip(1);
-                       prout("Lt. Uhura-  \"Captain, we made it!\"");
-                       return;
-               }
-       }
-       finish(FMATERIALIZE);
-       return;
+       game.quad[ix][iy]=ship;
+       textcolor(GREEN);
+       prout("succeeds.");
+       textcolor(DEFAULT);
+       dock(0);
+       skip(1);
+       prout("Lt. Uhura-  \"Captain, we made it!\"");
 }