Hide more origin differences.
[super-star-trek.git] / battle.c
index 75ac19035437662a1a48dfdab3db81b450ded6f8..549039999cdbf594490e157a670a81c466325d2b 100644 (file)
--- a/battle.c
+++ b/battle.c
@@ -198,10 +198,9 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int wait, i
     for (l=1; l <= 15; 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;
        iquad=game.quad[ix][iy];
        tracktorpedo(x, y, ix, iy, wait, l, i, n, iquad);
        wait = 1;
@@ -230,7 +229,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int wait, i
            yy = cos(ang)/temp;
            jx=ix+xx+0.5;
            jy=iy+yy+0.5;
-           if (jx<1 || jx>QUADSIZE || jy<1 ||jy > QUADSIZE) return;
+           if (!VALID_SECTOR(jx, jy)) return;
            if (game.quad[jx][jy]==IHBLANK) {
                finish(FHOLE);
                return;
@@ -278,7 +277,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int wait, i
            yy = cos(ang)/temp;
            jx=ix+xx+0.5;
            jy=iy+yy+0.5;
-           if (jx<1 || jx>QUADSIZE || jy<1 ||jy > QUADSIZE) {
+           if (!VALID_SECTOR(jx, jy)) {
                prout(" damaged but not destroyed.");
                return;
            }
@@ -300,7 +299,6 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int wait, i
        case IHB: /* Hit a base */
            skip(1);
            prout("***STARBASE DESTROYED..");
-           if (game.starch[quadx][quady] < 0) game.starch[quadx][quady] = 0;
            for (ll=1; ll<=game.state.rembase; ll++) {
                if (game.state.baseqx[ll]==quadx && game.state.baseqy[ll]==quady) {
                    game.state.baseqx[ll]=game.state.baseqx[game.state.rembase];
@@ -311,7 +309,8 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int wait, i
            game.quad[ix][iy]=IHDOT;
            game.state.rembase--;
            basex=basey=0;
-           game.state.galaxy[quadx][quady] -= BASE_PLACE;
+           game.state.galaxy[quadx][quady].starbase--;
+           game.state.chart[quadx][quady].starbase--;
            game.state.basekl++;
            newcnd();
            return;
@@ -319,7 +318,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int wait, i
            crmena(1, iquad, 2, ix, iy);
            prout(" destroyed.");
            game.state.nplankl++;
-           game.state.newstuf[quadx][quady] -= 1;
+           game.state.galaxy[quadx][quady].planets--;
            DESTROY(&game.state.plnets[iplnet]);
            iplnet = 0;
            plnetx = plnety = 0;
@@ -520,9 +519,10 @@ void attack(int torps_ok)
            r = (Rand()+Rand())*0.5 -0.5;
            r += 0.002*game.kpower[l]*r;
            torpedo(course, r, jx, jy, &hit, 0, 1, 1);
-           if (game.state.remkl==0) finish(FWON); /* Klingons did themselves in! */
-           if (game.state.galaxy[quadx][quady] == SUPERNOVA_PLACE ||
-               alldone) return; /* Supernova or finished */
+           if (game.state.remkl==0) 
+               finish(FWON); /* Klingons did themselves in! */
+           if (game.state.galaxy[quadx][quady].supernova || alldone) 
+               return; /* Supernova or finished */
            if (hit == 0) continue;
        }
        if (shldup != 0 || shldchg != 0 || condit==IHDOCKED) {
@@ -612,7 +612,7 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy)
     /* Decide what kind of enemy it is and update approriately */
     if (type == IHR) {
        /* chalk up a Romulan */
-       game.state.newstuf[quadx][quady] -= ROMULAN_PLACE;
+       game.state.galaxy[quadx][quady].romulans--;
        irhere--;
        game.state.nromkl++;
        game.state.nromrem--;
@@ -627,13 +627,13 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy)
     }
     else {
        /* Some type of a Klingon */
-       game.state.galaxy[quadx][quady] -= KLINGON_PLACE;
+       game.state.galaxy[quadx][quady].klingons--;
        klhere--;
        game.state.remkl--;
        switch (type) {
        case IHC:
            comhere = 0;
-           for (i=1; i<=game.state.remcom; i++)
+           for_commanders (i)
                if (game.state.cx[i]==quadx && game.state.cy[i]==quady) break;
            game.state.cx[i] = game.state.cx[game.state.remcom];
            game.state.cy[i] = game.state.cy[game.state.remcom];
@@ -689,7 +689,7 @@ static int targetcheck(double x, double y, double *course)
 {
     double deltx, delty;
     /* Return TRUE if target is invalid */
-    if (x < 1.0 || x > QUADSIZE || y < 1.0 || y > QUADSIZE) {
+    if (!VALID_SECTOR(x, y)) {
        huh();
        return 1;
     }
@@ -828,7 +828,7 @@ void photon(void)
        if (shldup || condit == IHDOCKED) 
            r *= 1.0 + 0.0001*shield;
        torpedo(course[i], r, sectx, secty, &dummy, 0, i, n);
-       if (alldone||game.state.galaxy[quadx][quady]==SUPERNOVA_PLACE)
+       if (alldone || game.state.galaxy[quadx][quady].supernova)
            return;
     }
     if (game.state.remkl==0) finish(FWON);