void torpedo(double course, double r, int inx, int iny, double *hit, int i, int n)
/* let a photon torpedo fly */
{
- int l, iquad=0, jx=0, jy=0, ll;
+ int l, iquad=0, ll;
bool shoved = false;
double ac=course + 0.25*r;
double angle = (15.0-ac)*0.5235988;
double deltax=-sin(angle), deltay=cos(angle), x=inx, y=iny, bigger;
double ang, temp, xx, yy, kp, h1;
struct quadrant *q = &game.state.galaxy[game.quadrant.x][game.quadrant.y];
- coord w;
+ coord w, jw;
- w.x = w.y = 0;
+ w.x = w.y = jw.x = jw.y = 0;
bigger = fabs(deltax);
if (fabs(deltay) > bigger) bigger = fabs(deltay);
deltax /= bigger;
w.y = y + 0.5;
if (!VALID_SECTOR(w.x, w.y)) break;
iquad=game.quad[w.x][w.y];
- tracktorpedo(w.x, w.y, l, i, n, iquad);
+ tracktorpedo(w, l, i, n, iquad);
if (iquad==IHDOT) continue;
/* hit something */
setwnd(message_window);
if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
xx = -sin(ang)/temp;
yy = cos(ang)/temp;
- jx=w.x+xx+0.5;
- jy=w.y+yy+0.5;
- if (!VALID_SECTOR(jx, jy)) return;
- if (game.quad[jx][jy]==IHBLANK) {
+ jw.x=w.x+xx+0.5;
+ jw.y=w.y+yy+0.5;
+ if (!VALID_SECTOR(jw.x, jw.y)) return;
+ if (game.quad[jw.x][jw.y]==IHBLANK) {
finish(FHOLE);
return;
}
- if (game.quad[jx][jy]!=IHDOT) {
+ if (game.quad[jw.x][jw.y]!=IHDOT) {
/* can't move into object */
return;
}
- game.sector.x = jx;
- game.sector.y = jy;
+ game.sector.x = jw.x;
+ game.sector.y = jw.y;
crmshp();
shoved = true;
break;
if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
xx = -sin(ang)/temp;
yy = cos(ang)/temp;
- jx=w.x+xx+0.5;
- jy=w.y+yy+0.5;
- if (!VALID_SECTOR(jx, jy)) {
+ jw.x=w.x+xx+0.5;
+ jw.y=w.y+yy+0.5;
+ if (!VALID_SECTOR(jw.x, jw.y)) {
prout(_(" damaged but not destroyed."));
return;
}
- if (game.quad[jx][jy]==IHBLANK) {
+ if (game.quad[jw.x][jw.y]==IHBLANK) {
prout(_(" buffeted into black hole."));
- deadkl(w, iquad, jx, jy);
+ deadkl(w, iquad, jw.x, jw.y);
return;
}
- if (game.quad[jx][jy]!=IHDOT) {
+ if (game.quad[jw.x][jw.y]!=IHDOT) {
/* can't move into object */
prout(_(" damaged but not destroyed."));
return;
}
proutn(_(" damaged--"));
- game.ks[ll].x = jx;
- game.ks[ll].y = jy;
+ game.ks[ll].x = jw.x;
+ game.ks[ll].y = jw.y;
shoved = true;
break;
case IHB: /* Hit a base */
}
if (shoved) {
game.quad[w.x][w.y]=IHDOT;
- game.quad[jx][jy]=iquad;
- w.x = jx; w.y = jy;
- prout(_(" displaced by blast to %s "), cramlc(sector, w));
+ game.quad[jw.x][jw.y]=iquad;
+ prout(_(" displaced by blast to %s "), cramlc(sector, jw));
for_local_enemies(ll)
game.kdist[ll] = game.kavgd[ll] = distance(game.sector,game.ks[ll]);
sortkl();
w = game.ks[kk];
if (hit > 0.005) {
if (!damaged(DSRSENS))
- boom(w.x, w.y);
+ boom(w);
proutn(_("%d unit hit on "), (int)hit);
}
else
}
}
-static void put_srscan_sym(int x, int y, char sym)
+static void put_srscan_sym(coord w, char sym)
{
- wmove(srscan_window, x+1, y*2+2);
+ wmove(srscan_window, w.x+1, w.y*2+2);
waddch(srscan_window, sym);
wrefresh(srscan_window);
}
-void boom(int ii, int jj)
+void boom(coord w)
/* enemy fall down, go boom */
{
if (game.options & OPTION_CURSES) {
drawmaps(2);
setwnd(srscan_window);
wattron(srscan_window, A_REVERSE);
- put_srscan_sym(ii, jj, game.quad[ii][jj]);
+ put_srscan_sym(w, game.quad[w.x][w.y]);
sound(500);
delay(1000);
nosound();
wattroff(srscan_window, A_REVERSE);
- put_srscan_sym(ii, jj, game.quad[ii][jj]);
+ put_srscan_sym(w, game.quad[w.x][w.y]);
delay(500);
setwnd(message_window);
}
}
}
-void tracktorpedo(int ix, int iy, int l, int i, int n, int iquad)
+void tracktorpedo(coord w, int l, int i, int n, int iquad)
/* torpedo-track animation */
{
if (!game.options & OPTION_CURSES) {
}
} else if (l==4 || l==9)
skip(1);
- proutn("%d - %d ", ix, iy);
+ proutn("%d - %d ", w.x, w.y);
} else {
if (!damaged(DSRSENS) || game.condit==IHDOCKED) {
if (i != 1 && l == 1) {
delay(400);
}
if ((iquad==IHDOT)||(iquad==IHBLANK)){
- put_srscan_sym(ix, iy, '+');
+ put_srscan_sym(w, '+');
sound(l*10);
delay(100);
nosound();
- put_srscan_sym(ix, iy, iquad);
+ put_srscan_sym(w, iquad);
}
else {
wattron(curwnd, A_REVERSE);
- put_srscan_sym(ix, iy, iquad);
+ put_srscan_sym(w, iquad);
sound(500);
delay(1000);
nosound();
wattroff(curwnd, A_REVERSE);
- put_srscan_sym(ix, iy, iquad);
+ put_srscan_sym(w, iquad);
}
} else {
- proutn("%d - %d ", ix, iy);
+ proutn("%d - %d ", w.x, w.y);
}
}
}
/* movement execution for warp, impule, supernova, and tractor-beam events */
{
double angle, deltax, deltay, bigger, x, y,
- finald, finalx, finaly, stopegy, probf;
+ finald, stopegy, probf;
int n, m, kink, kinks, iquad;
- coord w;
- bool trbeam = 0;
+ coord w, final;
+ bool trbeam = false;
w.x = w.y = 0;
if (game.inorbit) {
if (game.nenhere != 0 && game.iattak != 2) {
newcnd();
for_local_enemies(m) {
- finald = sqrt((w.x-game.ks[m].x)*(double)(w.x-game.ks[m].x) +
- (w.y-game.ks[m].y)*(double)(w.y-game.ks[m].y));
- game.kavgd[m] = 0.5 * (finald+game.kdist[m]);
+ finald = distance(w, game.ks[m]);
+ game.kavgd[m] = 0.5 * (finald + game.kdist[m]);
}
/*
* Stas Sergeev added the game.condition
if (iquad != IHDOT) {
/* object encountered in flight path */
stopegy = 50.0*game.dist/game.optime;
- game.dist=0.1*sqrt((game.sector.x-w.x)*(double)(game.sector.x-w.x) +
- (game.sector.y-w.y)*(double)(game.sector.y-w.y));
+ game.dist = distance(game.sector, w) / (QUADSIZE * 1.0);
switch (iquad) {
case IHT: /* Ram a Tholian */
case IHK: /* Ram enemy ship */
case IHS:
case IHR:
case IHQUEST:
- game.sector.x = w.x;
- game.sector.y = w.y;
+ game.sector = w;
ram(0, iquad, game.sector);
- finalx = game.sector.x;
- finaly = game.sector.y;
+ final = game.sector;
break;
case IHBLANK:
skip(1);
proutn(_("Emergency stop required "));
prout(_("%2d units of energy."), (int)stopegy);
game.energy -= stopegy;
- finalx = x-deltax+0.5;
- game.sector.x = finalx;
- finaly = y-deltay+0.5;
- game.sector.y = finaly;
+ final.x = x-deltax+0.5;
+ final.y = y-deltay+0.5;
+ game.sector = final;
if (game.energy <= 0) {
finish(FNRG);
return;
goto no_quad_change; /* sorry! */
}
}
- game.dist = 0.1*sqrt((game.sector.x-w.x)*(double)(game.sector.x-w.x) +
- (game.sector.y-w.y)*(double)(game.sector.y-w.y));
- game.sector.x = w.x;
- game.sector.y = w.y;
+ game.dist = distance(game.sector, w) / (QUADSIZE * 1.0);
+ game.sector = w;
}
- finalx = game.sector.x;
- finaly = game.sector.y;
+ final = game.sector;
no_quad_change:
/* No quadrant change -- compute new avg enemy distances */
game.quad[game.sector.x][game.sector.y] = game.ship;
if (game.nenhere) {
for_local_enemies(m) {
- finald = sqrt((w.x-game.ks[m].x)*(double)(w.x-game.ks[m].x) +
- (w.y-game.ks[m].y)*(double)(w.y-game.ks[m].y));
+ finald = distance(w, game.ks[m]);
game.kavgd[m] = 0.5 * (finald+game.kdist[m]);
game.kdist[m] = finald;
}
}
else {
prout(_("saved."));
- game.icrystl = 1;
+ game.icrystl = true;
}
}
}
prout(_("The shuttle craft Galileo is here!"));
}
if (game.landed!=1 && game.imine) {
- game.icrystl = 1;
+ game.icrystl = true;
game.cryprob = 0.05;
}
game.imine = false;
prout(_("You've already mined enough crystals for this trip."));
return;
}
- if (game.icrystl == 1 && game.cryprob == 0.05) {
+ if (game.icrystl && game.cryprob == 0.05) {
proutn(_("With all those fresh crystals aboard the "));
crmshp();
skip(1);
game.ididit = false;
skip(1);
chew();
- if (game.icrystl!=1) {
+ if (!game.icrystl) {
prout(_("No dilithium crystals available."));
return;
}
game.iscraft = 1;
game.icraft = false;
if (game.imine) {
- game.icrystl = 1;
+ game.icrystl = true;
game.cryprob = 0.05;
}
game.imine = false;
/* If at least one base left, give 'em the Faerie Queene */
skip(1);
- game.icrystl = 0; /* crystals are lost */
+ game.icrystl = false; /* crystals are lost */
game.nprobes = 0; /* No probes */
prout("You are captured by Klingons and released to");
prout("the Federation in a prisoner-of-war exchange.");
prout("Starfleet puts you in command of another ship,");
prout("the Faerie Queene, which is antiquated but,");
prout("still useable.");
- if (game.icrystl!=0) prout("The dilithium crystals have been moved.");
+ if (game.icrystl) prout("The dilithium crystals have been moved.");
game.imine = false;
game.iscraft=0; /* Galileo disappears */
/* Resupply ship */
game.battle.x = game.battle.y = 0;
game.state.date = game.indate = 100.0*(int)(31.0*Rand()+20.0);
game.nkinks = game.nhelp = game.casual = game.abandoned = 0;
- game.resting = game.imine = game.icraft = false;
- game.isatb = game.iscate = game.icrystl = game.state.nplankl = 0;
+ game.resting = game.imine = game.icrystl = game.icraft = false;
+ game.isatb = game.iscate = game.state.nplankl = 0;
game.state.starkl = game.state.basekl = 0;
game.iscraft = 1;
game.landed = -1;
isarmed, // probe is armed
inorbit, // orbiting a planet
imine, // mining
+ icrystl, // dilithium crystals aboard
thawed; // thawed game
int inkling, // initial number of klingons
inbase, // initial number of bases
isatb, // =1 if super commander is attacking base
iscate, // super commander is here
iattak, // attack recursion elimination (was cracks[4])
- icrystl, // dilithium crystals aboard
tourn, // tournament number
iseenit, // seen base attack report
proben, // number of moves for probe
void iostart(void);
void setwnd(WINDOW *);
void warble(void);
-void boom(int, int);
-void tracktorpedo(int, int, int, int, int, int);
+void boom(coord);
+void tracktorpedo(coord, int, int, int, int);
void cgetline(char *, int);
void waitfor(void);
void setpassword(void);