X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=battle.c;h=4b3cf904e9ec10738c9a76b6422e9be758c639cf;hb=e1f6b356f97edb611f07a9601f2d78d03e96c1c0;hp=5356e3d14f9f11a1bdcb6a7ed057dc8d20274610;hpb=e536fe754b3a9be00dcaee8f6ec50ea2d8c7a184;p=super-star-trek.git diff --git a/battle.c b/battle.c index 5356e3d..4b3cf90 100644 --- 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; @@ -256,7 +255,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int wait, i case IHR: /* Hit a regular enemy */ case IHK: /* find the enemy */ - for (ll=1; ll <= nenhere; ll++) + for_local_enemies(ll) if (ix==game.kx[ll] && iy==game.ky[ll]) break; kp = fabs(game.kpower[ll]); h1 = 700.0 + 100.0*Rand() - @@ -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,7 @@ 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.."); - for (ll=1; ll<=game.state.rembase; ll++) { + for_starbases(ll) { if (game.state.baseqx[ll]==quadx && game.state.baseqy[ll]==quady) { game.state.baseqx[ll]=game.state.baseqx[game.state.rembase]; game.state.baseqy[ll]=game.state.baseqy[game.state.rembase]; @@ -411,7 +410,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int wait, i game.quad[jx][jy]=iquad; game.quad[ix][iy]=IHDOT; prout(" displaced by blast to %s ", cramlc(sector, jx, jy)); - for (ll=1; ll<=nenhere; ll++) + for_local_enemies(ll) game.kdist[ll] = game.kavgd[ll] = sqrt(square(sectx-game.kx[ll])+square(secty-game.ky[ll])); sortkl(); return; @@ -483,7 +482,7 @@ void attack(int torps_ok) if (shldchg == 1) chgfac = 0.25+0.5*Rand(); skip(1); if (skill <= SKILL_FAIR) i = 2; - for (l=1; l <= nenhere; l++) { + for_local_enemies(l) { if (game.kpower[l] < 0) continue; /* too weak to attack */ /* compute hit strength and diminsh shield power */ r = Rand(); @@ -596,7 +595,7 @@ void attack(int torps_ok) } } /* After attack, reset average distance to enemies */ - for (l = 1; l <= nenhere; l++) + for_local_enemies(l) game.kavgd[l] = game.kdist[l]; sortkl(); return; @@ -634,7 +633,7 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy) 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]; @@ -667,7 +666,7 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy) /* Remove enemy ship from arrays describing local conditions */ if (game.future[FCDBAS] < 1e30 && batx==quadx && baty==quady && type==IHC) game.future[FCDBAS] = 1e30; - for (i=1; i<=nenhere; i++) + for_local_enemies(i) if (game.kx[i]==ix && game.ky[i]==iy) break; nenhere--; if (i <= nenhere) { @@ -690,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; } @@ -998,7 +997,7 @@ void phasers(void) irec=0; do { chew(); - if (!kz) for (i = 1; i <= nenhere; i++) + if (!kz) for_local_enemies(i) irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))* (1.01+0.05*Rand()) + 1.0; kz=1; @@ -1033,7 +1032,7 @@ void phasers(void) if (nenhere) { extra = 0.0; powrem = rpow; - for (i = 1; i <= nenhere; i++) { + for_local_enemies(i) { hits[i] = 0.0; if (powrem <= 0) continue; hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));