Compute the maximum number of bases from BASEMAX.
[super-star-trek.git] / moving.c
index 2ba016a960af967b52f70f4f3e5d1978ddd3a66a..f44aff4c2bd98f98ac10409bfd9b1a9f8e2d9464 100644 (file)
--- a/moving.c
+++ b/moving.c
@@ -43,12 +43,12 @@ void imove(void)
        for (l = 1; l <= n; l++) {
            ix = (x += deltax) + 0.5;
            iy = (y += deltay) + 0.5;
-           if (ix < 1 || ix > QUADSIZE || iy < 1 || iy > QUADSIZE) {
+           if (!VALID_SECTOR(ix, iy)) {
                /* Leaving quadrant -- allow final enemy attack */
                /* Don't do it if being pushed by Nova */
                if (nenhere != 0 && iattak != 2) {
                    newcnd();
-                   for (l = 1; l <= nenhere; l++) {
+                   for_local_enemies(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]);
@@ -193,7 +193,7 @@ no_quad_change:
     /* No quadrant change -- compute new avg enemy distances */
     game.quad[sectx][secty] = ship;
     if (nenhere) {
-       for (l = 1; l <= nenhere; l++) {
+       for_local_enemies(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]);
@@ -202,7 +202,7 @@ no_quad_change:
        sortkl();
        if (!game.state.galaxy[quadx][quady].supernova && iattak == 0)
            attack(0);
-       for (l = 1 ; l <= nenhere; l++) game.kavgd[l] = game.kdist[l];
+       for_local_enemies(l) game.kavgd[l] = game.kdist[l];
     }
     newcnd();
     iattak = 0;
@@ -372,11 +372,10 @@ static void getcd(int isprobe, int akey) {
                        }
                        itemp = 1;
                }
-               if (irowq<1 || irowq > GALSIZE || icolq<1 || icolq > GALSIZE ||
-                       irows<1 || irows > QUADSIZE || icols<1 || icols > QUADSIZE) {
-                               huh();
-                               return;
-                       }
+               if (!VALID_QUADRANT(icolq,irowq)||!VALID_SECTOR(icols,irows)) {
+                   huh();
+                   return;
+               }
                skip(1);
                if (!isprobe) {
                        if (itemp) {
@@ -589,10 +588,9 @@ void warp(int i)
            for (l = 1; l <= n; l++) {
                x += deltax;
                ix = x + 0.5;
-               if (ix < 1 || ix > QUADSIZE) break;
                y += deltay;
                iy = y +0.5;
-               if (iy < 1 || iy > QUADSIZE) break;
+               if (!VALID_SECTOR(ix, iy)) break;
                if (game.quad[ix][iy] != IHDOT) {
                    blooey = 0;
                    twarp = 0;
@@ -931,7 +929,7 @@ void help(void)
     }
     else {
        ddist = 1e30;
-       for (l = 1; l <= game.state.rembase; l++) {
+       for_starbases(l) {
            xdist=10.0*sqrt(square(game.state.baseqx[l]-quadx)+square(game.state.baseqy[l]-quady));
            if (xdist < ddist) {
                ddist = xdist;
@@ -953,7 +951,7 @@ 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<=QUADSIZE && iy>=1 && iy<=QUADSIZE && game.quad[ix][iy]==IHDOT) {
+       if (VALID_SECTOR(ix,iy) && game.quad[ix][iy]==IHDOT) {
            /* found one -- finish up */
            sectx=ix;
            secty=iy;