game.damage[l] += Time + extradm; /* Damage for at least time of travel! */
}
shldup = 0;
- if (game.state.remkl) {
+ if (KLINGREM) {
pause_game(2);
dreprt();
}
return;
}
-void torpedo(double course, double r, int inx, int iny, double *hit, int wait, int i, int n)
+void torpedo(double course, double r, int inx, int iny, double *hit, int i, int n)
{
int l, iquad=0, ix=0, iy=0, jx=0, jy=0, shoved=0, ll;
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;
+ tracktorpedo(ix, iy, l, i, n, iquad);
if (iquad==IHDOT) continue;
/* hit something */
setwnd(message_window);
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;
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() -
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;
}
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++) {
+ 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];
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;
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;
} else {
/*
* Stas Sergeev added the possibility that
- * you can shove the Thingy abd piss it off.
+ * you can shove the Thingy and piss it off.
* It then becomes an enemy and may fire at you.
*/
iqengry=1;
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();
prout(" ");
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 */
+ torpedo(course, r, jx, jy, &hit, 1, 1);
+ if (KLINGREM==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) {
}
}
/* 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;
/* 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--;
}
else if (type == IHT) {
}
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];
game.state.cx[game.state.remcom] = 0;
game.state.cy[game.state.remcom] = 0;
game.state.remcom--;
- game.future[FTBEAM] = 1e30;
+ game.future[FTBEAM] = FOREVER;
if (game.state.remcom != 0)
game.future[FTBEAM] = game.state.date + expran(1.0*incom/game.state.remcom);
- game.state.killc++;
break;
case IHK:
- game.state.killk++;
+ game.state.remkl--;
break;
case IHS:
- game.state.nscrem = ishere = game.state.isx = game.state.isy = isatb = iscate = 0;
- game.state.nsckill = 1;
- game.future[FSCMOVE] = game.future[FSCDBAS] = 1e30;
+ game.state.nscrem--;
+ ishere = game.state.isx = game.state.isy = isatb = iscate = 0;
+ game.future[FSCMOVE] = game.future[FSCDBAS] = FOREVER;
break;
}
}
/* For each kind of enemy, finish message to player */
prout(" destroyed.");
game.quad[ix][iy] = IHDOT;
- if (game.state.remkl==0) return;
+ if (KLINGREM==0) return;
game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom);
/* 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++)
+ if (game.future[FCDBAS] < FOREVER && batx==quadx && baty==quady && type==IHC)
+ game.future[FCDBAS] = FOREVER;
+ for_local_enemies(i)
if (game.kx[i]==ix && game.ky[i]==iy) break;
nenhere--;
if (i <= nenhere) {
{
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;
}
}
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)
+ torpedo(course[i], r, sectx, secty, &dummy, i, n);
+ if (alldone || game.state.galaxy[quadx][quady].supernova)
return;
}
- if (game.state.remkl==0) finish(FWON);
+ if (KLINGREM==0) finish(FWON);
}
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]));
skip(1);
if (kpow == 0) {
deadkl(ii, jj, ienm, ii, jj);
- if (game.state.remkl==0) finish(FWON);
+ if (KLINGREM==0) finish(FWON);
if (alldone) return;
kk--; /* don't do the increment */
}