More magic-number chasing.
[super-star-trek.git] / battle.c
index 1e6123fb3835257be1249ba2b82e647bfcfc6793..36a6cfa7a126273f4de9cd872c3dc5a56a94418c 100644 (file)
--- a/battle.c
+++ b/battle.c
@@ -1,6 +1,4 @@
 #include <unistd.h>
-#include "conio.h"
-#include "sstlinux.h"
 #include "sst.h"
 
 void doshield(int i) {
@@ -174,12 +172,9 @@ void ram(int ibumpd, int ienm, int ix, int iy) {
        return;
 }
 
-void torpedo(double course, double r, int inx, int iny, double *hit, int wait) {
+void torpedo(double course, double r, int inx, int iny, double *hit, int wait, int i, int n) {
         int l, iquad=0, ix=0, iy=0, jx=0, jy=0, shoved=0, ll;
-#ifdef SERGEEV
-       int crx,cry;
        
-#endif /* SERGEEV */
        double ac=course + 0.25*r;
        double angle = (15.0-ac)*0.5235988;
        double bullseye = (15.0 - course)*0.5235988;
@@ -190,63 +185,25 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int wait) {
        if (fabs(deltay) > bigger) bigger = fabs(deltay);
        deltax /= bigger;
        deltay /= bigger;
-#ifdef SERGEEV
-        crx=wherex();
-        cry=wherey();
-        if (game.damage[DSRSENS]==0 || condit==IHDOCKED) setwnd(LEFTUPPER_WINDOW);
-       else setwnd(LOWER_WINDOW);
-#endif /* SERGEEV */
+        if (game.damage[DSRSENS]==0 || condit==IHDOCKED) 
+           setwnd(srscan_window);
+       else 
+           setwnd(message_window);
        /* Loop to move a single torpedo */
        for (l=1; l <= 15; 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;
-#ifndef SERGEEV
-               if (l==4 || l==9) skip(1);
-               proutn("%d - %d   ", (int)x, (int)y);
+               if (iy < 1 || iy > QUADSIZE) break;
                iquad=game.quad[ix][iy];
-#else
-                iquad=game.quad[ix][iy];
-                if (game.damage[DSRSENS]==0 || condit==IHDOCKED){
-                   drawmaps(2);
-                   delay((wait!=1)*400);
-                   wait=1;
-                   gotoxy(iy*2+3,ix+2);
-                   if ((game.quad[ix][iy]==IHDOT)||(game.quad[ix][iy]==IHBLANK)){
-                      game.quad[ix][iy]='+';
-                      drawmaps(2);
-                      game.quad[ix][iy]=iquad;
-                      sound(l*10);
-                      delay(100);
-                      nosound();
-                   }
-                   else {
-                        game.quad[ix][iy]|=128;
-                        drawmaps(2);
-                        game.quad[ix][iy]=iquad;
-                        _setcursortype(_NOCURSOR);
-                        sound(500);
-                        delay(1000);
-                        nosound();
-                        lowvideo();
-                        _setcursortype(_NORMALCURSOR);
-                   }
-                }
-                else {
-                 proutn("%d - %d   ", (int)x, (int)y);
-               }
-#endif /* SERGEEV */
+               tracktorpedo(x, y, ix, iy, wait, l, i, n, iquad);
+               wait = 1;
                if (iquad==IHDOT) continue;
                /* hit something */
-#ifndef SERGEEV
-               skip(1);
-#else
-               setwnd(LOWER_WINDOW);
-               gotoxy(crx,cry);
-#endif
+               setwnd(message_window);
+               skip(1);        /* start new line after text track */
                switch(iquad) {
                        case IHE: /* Hit our ship */
                        case IHF:
@@ -268,7 +225,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int wait) {
                                yy = cos(ang)/temp;
                                jx=ix+xx+0.5;
                                jy=iy+yy+0.5;
-                               if (jx<1 || jx>10 || jy<1 ||jy > 10) return;
+                               if (jx<1 || jx>QUADSIZE || jy<1 ||jy > QUADSIZE) return;
                                if (game.quad[jx][jy]==IHBLANK) {
                                        finish(FHOLE);
                                        return;
@@ -316,7 +273,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int wait) {
                                yy = cos(ang)/temp;
                                jx=ix+xx+0.5;
                                jy=iy+yy+0.5;
-                               if (jx<1 || jx>10 || jy<1 ||jy > 10) {
+                               if (jx<1 || jx>QUADSIZE || jy<1 ||jy > QUADSIZE) {
                                        prout(" damaged but not destroyed.");
                                        return;
                                }
@@ -349,7 +306,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int wait) {
                                game.quad[ix][iy]=IHDOT;
                                game.state.rembase--;
                                basex=basey=0;
-                               game.state.galaxy[quadx][quady] -= 10;
+                               game.state.galaxy[quadx][quady] -= BASE_PLACE;
                                game.state.basekl++;
                                newcnd();
                                return;
@@ -363,7 +320,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int wait) {
                                plnetx = plnety = 0;
                                game.quad[ix][iy] = IHDOT;
                                if (landed==1) {
-                                       /* captain parishes on planet */
+                                       /* captain perishes on planet */
                                        finish(FDPLANET);
                                }
                                return;
@@ -410,15 +367,10 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int wait) {
                                         fabs(sin(bullseye-angle));
                                h1 = fabs(h1);
                                if (h1 >= 600) {
-#ifndef SERGEEV
-                                       prout(" destroyed.");
-#endif /* SERGEEV */
                                        game.quad[ix][iy] = IHDOT;
                                        ithere = 0;
                                        ithx = ithy = 0;
-#ifdef SERGEEV
                                         deadkl(ix, iy, iquad, ix, iy);
-#endif /* SERGEEV */
                                        return;
                                }
                                skip(1);
@@ -446,12 +398,9 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int wait) {
                }
                break;
        }
-#ifdef SERGEEV
-        if(curwnd!=LOWER_WINDOW) {
-           setwnd(LOWER_WINDOW);
-           gotoxy(crx,cry);
+        if(curwnd!=message_window) {
+           setwnd(message_window);
        }
-#endif /* SERGEEV */
        if (shoved) {
                game.quad[jx][jy]=iquad;
                game.quad[ix][iy]=IHDOT;
@@ -461,9 +410,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int wait) {
                sortkl();
                return;
        }
-#ifndef SERGEEV
        skip(1);
-#endif /* SERGEEV */
        prout("Torpedo missed.");
        return;
 }
@@ -564,9 +511,9 @@ void attack(int k) {
                        prout("  ");
                        r = (Rand()+Rand())*0.5 -0.5;
                        r += 0.002*game.kpower[l]*r;
-                       torpedo(course, r, jx, jy, &hit, 0);
+                       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] == 1000 ||
+                       if (game.state.galaxy[quadx][quady] == SUPERNOVA_PLACE ||
                                alldone) return; /* Supernova or finished */
                        if (hit == 0) continue;
                }
@@ -655,7 +602,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] -= 10;
+               game.state.newstuf[quadx][quady] -= ROMULAN_PLACE;
                irhere--;
                game.state.nromkl++;
                game.state.nromrem--;
@@ -731,7 +678,7 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy) {
 static int targetcheck(double x, double y, double *course) {
        double deltx, delty;
        /* Return TRUE if target is invalid */
-       if (x < 1.0 || x > 10.0 || y < 1.0 || y > 10.0) {
+       if (x < 1.0 || x > QUADSIZE || y < 1.0 || y > QUADSIZE) {
                huh();
                return 1;
        }
@@ -867,17 +814,7 @@ void photon(void) {
                        }
                }
                if (shldup || condit == IHDOCKED) r *= 1.0 + 0.0001*shield;
-#ifndef SERGEEV
-               if (n != 1) {
-                       skip(1);
-                       proutn("Track for torpedo number %d-  ", i);
-               }
-               else {
-                       skip(1);
-                       proutn("Torpedo track- ");
-               }
-#endif /* SERGEEV */
-               torpedo(course[i], r, sectx, secty, &dummy, i);
+               torpedo(course[i], r, sectx, secty, &dummy, 0, i, n);
                if (alldone || game.state.galaxy[quadx][quady]==1000) return;
        }
        if (game.state.remkl==0) finish(FWON);
@@ -1228,9 +1165,6 @@ void phasers(void) {
 
 void hittem(double *hits) {
        double kp, kpow, wham, hit, dustfac, kpini;
-#ifdef SERGEEV
-       int crx, cry;
-#endif /* SERGEEV */
        int nenhr2=nenhere, k=1, kk=1, ii, jj, ienm;
 
        skip(1);
@@ -1247,27 +1181,8 @@ void hittem(double *hits) {
                ii = game.kx[kk];
                jj = game.ky[kk];
                if (hit > 0.005) {
-#ifdef SERGEEV
-                        if (game.damage[DSRSENS]==0){
-                           crx=wherex();
-                           cry=wherey();
-                           setwnd(LEFTUPPER_WINDOW);
-                           drawmaps(2);
-                           gotoxy(jj*2+3,ii+2);
-                           highvideo();
-                           proutn("%c", game.quad[ii][jj]);
-                           gotoxy(wherex()-1,wherey());
-                           sound(500);
-                           delay(1000);
-                           nosound();
-                           lowvideo();
-                           proutn("%c", game.quad[ii][jj]);
-                           setwnd(LOWER_WINDOW);
-                           gotoxy(crx,cry);
-                           _setcursortype(_NORMALCURSOR);
-                           delay(500);
-                        }
-#endif /* SERGEEV */
+                        if (game.damage[DSRSENS]==0)
+                           boom(ii, jj);
                        proutn("%d unit hit on ", (int)hit);
                }
                else