/* Figure out which Klingon is the commander (or Supercommander)
and do move */
- if (comhere) for (i = 1; i <= nenhere; i++) {
- ix = game.kx[i];
- iy = game.ky[i];
- if (game.quad[ix][iy] == IHC) {
- movebaddy(ix, iy, i, IHC);
- break;
+ if (comhere)
+ for_local_enemies(i) {
+ ix = game.kx[i];
+ iy = game.ky[i];
+ if (game.quad[ix][iy] == IHC) {
+ movebaddy(ix, iy, i, IHC);
+ break;
+ }
}
- }
- if (ishere) for (i = 1; i <= nenhere; i++) {
- ix = game.kx[i];
- iy = game.ky[i];
- if (game.quad[ix][iy] == IHS) {
- movebaddy(ix, iy, i, IHS);
- break;
+ if (ishere)
+ for_local_enemies(i) {
+ ix = game.kx[i];
+ iy = game.ky[i];
+ if (game.quad[ix][iy] == IHS) {
+ movebaddy(ix, iy, i, IHS);
+ break;
+ }
}
- }
/* if skill level is high, move other Klingons and Romulans too!
Move these last so they can base their actions on what the
commander(s) do. */
- if (skill >= SKILL_EXPERT) for (i = 1; i <= nenhere; i++) {
+ if (skill >= SKILL_EXPERT) for_local_enemies(i) {
ix = game.kx[i];
iy = game.ky[i];
if (game.quad[ix][iy] == IHK || game.quad[ix][iy] == IHR)
return 1;
if (flag) {
/* Avoid quadrants with bases if we want to avoid Enterprise */
- for (i = 1; i <= game.state.rembase; i++)
+ for_starbases(i)
if (game.state.baseqx[i]==iqx && game.state.baseqy[i]==iqy) return 1;
}
if (justin && !iscate) return 1;
ishere=0;
ientesc=0;
game.future[FSCDBAS]=1e30;
- for (i = 1; i <= nenhere; i++)
+ for_local_enemies(i)
if (game.quad[game.kx[i]][game.ky[i]] == IHS) break;
game.quad[game.kx[i]][game.ky[i]] = IHDOT;
game.kx[i] = game.kx[nenhere];
}
sx = game.state.isx;
sy = game.state.isy;
- for (i = 1; i <= game.state.rembase; i++) {
+ for_starbases(i) {
basetbl[i] = i;
ibqx = game.state.baseqx[i];
ibqy = game.state.baseqy[i];
without too many Klingons, and not already under attack. */
ifindit = iwhichb = 0;
- for (i2 = 1; i2 <= game.state.rembase; i2++) {
+ for_starbases(i2) {
i = basetbl[i2]; /* bug in original had it not finding nearest*/
ibqx = game.state.baseqx[i];
ibqy = game.state.baseqy[i];
if (game.state.rembase == 0) {
game.future[FSCMOVE] = 1e30;
}
- else for (i=1; i<=game.state.rembase; i++) {
+ else for_starbases(i) {
ibqx = game.state.baseqx[i];
ibqy = game.state.baseqy[i];
if (ibqx==game.state.isx && ibqy == game.state.isy && game.state.isx != batx && game.state.isy != baty) {
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() -
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;
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();
}
}
/* 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;
/* 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) {
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;
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]));
break;
}
i = 0;
- for (j=1; j<=game.state.rembase; j++) {
- for (k=1; k<=game.state.remcom; k++)
+ for_commanders (j) {
+ for_commanders(k)
if (game.state.baseqx[j]==game.state.cx[k] && game.state.baseqy[j]==game.state.cy[k] &&
(game.state.baseqx[j]!=quadx || game.state.baseqy[j]!=quady) &&
(game.state.baseqx[j]!=game.state.isx || game.state.baseqy[j]!=game.state.isy)) {
if (line==FCDBAS) {
game.future[FCDBAS] = 1e30;
/* find the lucky pair */
- for (i = 1; i <= game.state.remcom; i++)
+ for_commanders(i)
if (game.state.cx[i]==batx && game.state.cy[i]==baty)
break;
if (i > game.state.remcom || game.state.rembase == 0 ||
}
/* Remove Starbase from galaxy */
game.state.galaxy[batx][baty].starbase = FALSE;
- for (i=1; i <= game.state.rembase; i++)
+ for_starbases(i)
if (game.state.baseqx[i]==batx && game.state.baseqy[i]==baty) {
game.state.baseqx[i]=game.state.baseqx[game.state.rembase];
game.state.baseqy[i]=game.state.baseqy[game.state.rembase];
break;
case IHB: /* Destroy base */
game.state.galaxy[quadx][quady].starbase = FALSE;
- for (i = 1; i <= game.state.rembase; i++)
+ for_starbases(i)
if (game.state.baseqx[i]==quadx && game.state.baseqy[i]==quady)
break;
game.state.baseqx[i] = game.state.baseqx[game.state.rembase];
case IHC: /* Damage/destroy big enemies */
case IHS:
case IHR:
- for (ll = 1; ll <= nenhere; ll++)
+ for_local_enemies(ll)
if (game.kx[ll]==ii && game.ky[ll]==jj) break;
game.kpower[ll] -= 800.0; /* If firepower is lost, die */
if (game.kpower[ll] <= 0.0) {
/* 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]);
/* 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]);
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;
}
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;
game.kpower[i] = Rand()*150.0 +300.0 +25.0*skill;
}
// If we need a commander, promote a Klingon
- for (i = 1; i <= game.state.remcom ; i++)
+ for_commanders(i)
if (game.state.cx[i]==quadx && game.state.cy[i]==quady) break;
if (i <= game.state.remcom) {
*/
#define VALID_QUADRANT(x, y) ((x)>=1 && (x)<=GALSIZE && (y)>=1 && (y)<=GALSIZE)
#define VALID_SECTOR(x, y) ((x)>=1 && (x)<=QUADSIZE && (y)>=1 && (y)<=QUADSIZE)
-#define for_quadrants(i) for (i = 1; i < GALSIZE+1; i++)
-#define for_sectors(i) for (i = 1; i < QUADSIZE+1; i++)
+#define for_quadrants(i) for (i = 1; i <= GALSIZE; i++)
+#define for_sectors(i) for (i = 1; i <= QUADSIZE; i++)
+#define for_commanders(i) for (i = 1; i <= game.state.remcom; i++)
+#define for_local_enemies(i) for (i = 1; i <= nenhere; i++)
+#define for_starbases(i) for (i = 1; i <= game.state.rembase; i++)
typedef struct {
int x; /* Quadrant location of planet */