static int tryexit(int lookx, int looky, int ienm, int loccom, int irun) {
int iqx, iqy, l;
- iqx = quadx+(lookx+9)/10 - 1;
- iqy = quady+(looky+9)/10 - 1;
- if (iqx < 1 || iqx > 8 || iqy < 1 || iqy > 8 ||
+ iqx = quadx+(lookx+(QUADSIZE-1))/QUADSIZE - 1;
+ iqy = quady+(looky+(QUADSIZE-1))/QUADSIZE - 1;
+ if (iqx < 1 || iqx > GALSIZE || iqy < 1 || iqy > GALSIZE ||
game.state.galaxy[iqx][iqy] > 899)
return 0; /* no can do -- neg energy, supernovae, or >8 Klingons */
if (ienm == IHR) return 0; /* Romulans cannot escape! */
int i;
if ((iqx==quadx && iqy==quady) ||
- iqx < 1 || iqx > 8 || iqy < 1 || iqy > 8 ||
+ iqx < 1 || iqx > GALSIZE || iqy < 1 || iqy > GALSIZE ||
game.state.galaxy[iqx][iqy] > 899) return 1;
if (flag) {
/* Avoid quadrants with bases if we want to avoid Enterprise */
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;
+ if (iy < 1 || iy > QUADSIZE) break;
iquad=game.quad[ix][iy];
tracktorpedo(x, y, ix, iy, wait, l, i, n, iquad);
wait = 1;
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;
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;
}
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;
}
if (stdamtim == 1e30 && game.damage[DRADIO] != 0.0) {
/* chart will no longer be updated because radio is dead */
stdamtim = game.state.date;
- for (i=1; i <= 8 ; i++)
- for (j=1; j <= 8; j++)
+ for (i=1; i <= GALSIZE ; i++)
+ for (j=1; j <= GALSIZE; j++)
if (game.starch[i][j] == 1) game.starch[i][j] = game.state.galaxy[i][j]+1000;
}
prout("Lt. Uhura- \"Captain, the sub-space radio is working and");
prout(" surveillance reports are coming in.");
skip(1);
- for (i=1; i <= 8 ; i++)
- for (j=1; j <= 8; j++)
+ for (i=1; i <= GALSIZE ; i++)
+ for (j=1; j <= GALSIZE; j++)
if (game.starch[i][j] > 999) game.starch[i][j] = 1;
if (iseenit==0) {
attakreport(0);
if (probecx != i || probecy != j) {
probecx = i;
probecy = j;
- if (i < 1 || i > 8 || j < 1 || j > 8 ||
+ if (i < 1 || i > GALSIZE || j < 1 || j > GALSIZE ||
game.state.galaxy[probecx][probecy] == 1000) {
// Left galaxy or ran into supernova
if (game.damage[DRADIO]==0.0 || condit == IHDOCKED) {
ipage = 1;
skip(1);
proutn("Lt. Uhura- \"The deep space probe ");
- if (i < 1 ||i > 8 || j < 1 || j > 8)
+ if (i < 1 ||i > GALSIZE || j < 1 || j > GALSIZE)
proutn("has left the galaxy");
else
proutn("is no longer transmitting");
if (j==2 && nn== 2) continue;
ii = hits[mm][1]+nn-2;
jj = hits[mm][2]+j-2;
- if (ii < 1 || ii > 10 || jj < 1 || jj > 10) continue;
+ if (ii < 1 || ii > QUADSIZE || jj < 1 || jj > QUADSIZE) continue;
iquad = game.quad[ii][jj];
switch (iquad) {
// case IHDOT: /* Empty space ends reaction
newcy = jj + jj - hits[mm][2];
crmena(1, iquad, 2, ii, jj);
proutn(" damaged");
- if (newcx<1 || newcx>10 || newcy<1 || newcy>10) {
+ if (newcx<1 || newcx>QUADSIZE || newcy<1 || newcy>QUADSIZE) {
/* can't leave quadrant */
skip(1);
break;
/* Scheduled supernova -- select star */
/* logic changed here so that we won't favor quadrants in top
left of universe */
- for (nqx = 1; nqx<=8; nqx++) {
- for (nqy = 1; nqy<=8; nqy++) {
+ for (nqx = 1; nqx<=GALSIZE; nqx++) {
+ for (nqy = 1; nqy<=GALSIZE; nqy++) {
stars += game.state.galaxy[nqx][nqy] % 10;
}
}
if (stars == 0) return; /* nothing to supernova exists */
num = Rand()*stars + 1;
- for (nqx = 1; nqx<=8; nqx++) {
- for (nqy = 1; nqy<=8; nqy++) {
+ for (nqx = 1; nqx<=GALSIZE; nqx++) {
+ for (nqy = 1; nqy<=GALSIZE; nqy++) {
num -= game.state.galaxy[nqx][nqy] % 10;
if (num <= 0) break;
}
/* we are in the quadrant! */
insipient = 1;
num = Rand()* (game.state.galaxy[nqx][nqy]%10) + 1;
- for (nsx=1; nsx < 10; nsx++) {
- for (nsy=1; nsy < 10; nsy++) {
+ for (nsx=1; nsx < QUADSIZE; nsx++) {
+ for (nsy=1; nsy < QUADSIZE; nsy++) {
if (game.quad[nsx][nsy]==IHSTAR) {
num--;
if (num==0) break;
for (l = 1; l <= n; l++) {
ix = (x += deltax) + 0.5;
iy = (y += deltay) + 0.5;
- if (ix < 1 || ix > 10 || iy < 1 || iy > 10) {
+ if (ix < 1 || ix > QUADSIZE || iy < 1 || iy > QUADSIZE) {
/* Leaving quadrant -- allow final enemy attack */
/* Don't do it if being pushed by Nova */
if (nenhere != 0 && iattak != 2) {
if (alldone) return;
}
/* compute final position -- new quadrant and sector */
- x = 10*(quadx-1)+sectx;
- y = 10*(quady-1)+secty;
+ x = QUADSIZE*(quadx-1)+sectx;
+ y = QUADSIZE*(quady-1)+secty;
ix = x+10.0*dist*bigger*deltax+0.5;
iy = y+10.0*dist*bigger*deltay+0.5;
/* check for edge of galaxy */
iy = -iy + 1;
kink = 1;
}
- if (ix > 80) {
+ if (ix > GALSIZE*QUADSIZE) {
ix = 161 - ix;
kink = 1;
}
- if (iy > 80) {
+ if (iy > GALSIZE*QUADSIZE) {
iy = 161 - iy;
kink = 1;
}
}
/* Compute final position in new quadrant */
if (trbeam) return; /* Don't bother if we are to be beamed */
- quadx = (ix+9)/10;
- quady = (iy+9)/10;
- sectx = ix - 10*(quadx-1);
- secty = iy - 10*(quady-1);
+ quadx = (ix+9)/QUADSIZE;
+ quady = (iy+9)/QUADSIZE;
+ sectx = ix - QUADSIZE*(quadx-1);
+ secty = iy - QUADSIZE*(quady-1);
prout("\n\rEntering %s.",
cramlc(quadrant, quadx, quady));
game.quad[sectx][secty] = ship;
}
itemp = 1;
}
- if (irowq<1 || irowq > 8 || icolq<1 || icolq > 8 ||
- irows<1 || irows > 10 || icols<1 || icols > 10) {
+ if (irowq<1 || irowq > GALSIZE || icolq<1 || icolq > GALSIZE ||
+ irows<1 || irows > QUADSIZE || icols<1 || icols > QUADSIZE) {
huh();
return;
}
for (l = 1; l <= n; 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;
+ if (iy < 1 || iy > QUADSIZE) break;
if (game.quad[ix][iy] != IHDOT) {
blooey = 0;
twarp = 0;
/* Revert star chart to earlier era, if it was known then*/
if (game.damage[DRADIO]==0.0 || stdamtim > game.state.date) {
- for (l = 1; l <= 8; l++)
- for (ll = 1; ll <= 8; ll++)
+ for (l = 1; l <= GALSIZE; l++)
+ for (ll = 1; ll <= GALSIZE; ll++)
if (game.starch[l][ll] > 1)
game.starch[l][ll]=game.damage[DRADIO]>0.0 ? game.state.galaxy[l][ll]+1000 :1;
prout("Spock has reconstructed a correct star chart from memory");
probeiny /= bigger;
probeinx /= bigger;
proben = 10.0*dist*bigger +0.5;
- probex = quadx*10 + sectx - 1; // We will use better packing than original
- probey = quady*10 + secty - 1;
+ probex = quadx*QUADSIZE + sectx - 1; // We will use better packing than original
+ probey = quady*QUADSIZE + secty - 1;
probecx = quadx;
probecy = quady;
game.future[FDSPROB] = game.state.date + 0.01; // Time to move one sector
for (l = 1; l <= 5; l++) {
ix = basex+3.0*Rand()-1;
iy = basey+3.0*Rand()-1;
- if (ix>=1 && ix<=10 && iy>=1 && iy<=10 && game.quad[ix][iy]==IHDOT) {
+ if (ix>=1 && ix<=QUADSIZE && iy>=1 && iy<=QUADSIZE && game.quad[ix][iy]==IHDOT) {
/* found one -- finish up */
sectx=ix;
secty=iy;
proutn("Spock- \"I believe the word is");
prouts(" *ASTONISHING*");
prout(" Mr. Sulu.");
- for (i=1; i<=10; i++)
- for (j=1; j<=10; j++)
+ for (i=1; i<=QUADSIZE; i++)
+ for (j=1; j<=QUADSIZE; j++)
if (game.quad[i][j] == IHDOT) game.quad[i][j] = IHQUEST;
prout(" Captain, our quadrant is now infested with");
prouts(" - - - - - - *THINGS*.");
for (x = quadx-1; x <= quadx+1; x++) {
proutn(" ");
for (y = quady-1; y <= quady+1; y++) {
- if (x == 0 || x > 8 || y == 0 || y > 8)
+ if (x == 0 || x > GALSIZE || y == 0 || y > GALSIZE)
proutn(" -1");
else {
if (game.state.galaxy[x][y]<1000) proutn(" %3d", game.state.galaxy[x][y]);
if (condit == IHDOCKED) {
/* We are docked, so restore chart from base information */
stdamtim = game.state.date;
- for (i=1; i <= 8 ; i++)
- for (j=1; j <= 8; j++)
+ for (i=1; i <= GALSIZE ; i++)
+ for (j=1; j <= GALSIZE; j++)
if (game.starch[i][j] == 1) game.starch[i][j] = game.state.galaxy[i][j]+1000;
}
else {
}
prout(" 1 2 3 4 5 6 7 8");
- for (i = 1; i <= 8; i++) {
+ for (i = 1; i <= GALSIZE; i++) {
proutn("%d |", i);
- for (j = 1; j <= 8; j++) {
+ for (j = 1; j <= GALSIZE; j++) {
char buf[4];
proutn(" ");
if (game.starch[i][j] < 0)
proutn(buf);
}
proutn(" |");
- if (i<8) proutn("\n\r");
+ if (i<GALSIZE) proutn("\n\r");
}
prout(""); /* flush output */
}
while (scan() == IHEOL)
proutn("Information desired? ");
chew();
- for (k = 1; k <= 10; k++)
+ for (k = 1; k <= sizeof(requests)/sizeof(requests[0]); k++)
if (strncmp(citem,requests[k],min(2,strlen(citem)))==0)
break;
- if (k > 10) {
+ if (k > sizeof(requests)/sizeof(requests[0])) {
prout("UNRECOGNIZED REQUEST. Legal requests are:\n"
" date, condition, position, lsupport, warpfactor,\n"
" energy, torpedoes, shields, klingons, time.");
break;
}
}
- if (i<10) proutn("\n\r");
+ if (i<sizeof(requests)/sizeof(requests[0])) proutn("\n\r");
if (k!=0) return(goodScan);
}
prout("");
}
else {
if (quady>ix1) ix2 = 1;
- else ix2=10;
+ else ix2=QUADSIZE;
if (quadx>iy1) iy2 = 1;
- else iy2=10;
+ else iy2=QUADSIZE;
}
- if (ix1 > 8 || ix1 < 1 || iy1 > 8 || iy1 < 1 ||
- ix2 > 10 || ix2 < 1 || iy2 > 10 || iy2 < 1) {
+ if (ix1 > GALSIZE || ix1 < 1 || iy1 > GALSIZE || iy1 < 1 ||
+ ix2 > QUADSIZE || ix2 < 1 || iy2 > QUADSIZE || iy2 < 1) {
huh();
return;
}
for (;;) {
/* position next to base by trial and error */
game.quad[sectx][secty] = IHDOT;
- for (l = 1; l <= 10; l++) {
+ for (l = 1; l <= QUADSIZE; l++) {
sectx = 3.0*Rand() - 1.0 + basex;
secty = 3.0*Rand() - 1.0 + basey;
- if (sectx >= 1 && sectx <= 10 &&
- secty >= 1 && secty <= 10 &&
+ if (sectx >= 1 && sectx <= QUADSIZE &&
+ secty >= 1 && secty <= QUADSIZE &&
game.quad[sectx][secty] == IHDOT) break;
}
if (l < 11) break; /* found a spot */
landed = -1;
alive = 1;
docfac = 0.25;
- for (i = 1; i <= 8; i++)
- for (j = 1; j <= 8; j++) game.state.newstuf[i][j] = game.starch[i][j] = 0;
+ for (i = 1; i <= GALSIZE; i++)
+ for (j = 1; j <= GALSIZE; j++) game.state.newstuf[i][j] = game.starch[i][j] = 0;
// Initialize times for extraneous events
game.future[FSNOVA] = game.state.date + expran(0.5 * intime);
game.future[FTBEAM] = game.state.date + expran(1.5 * (intime / game.state.remcom));
stdamtim = 1e30;
// Put stars in the galaxy
instar = 0;
- for (i=1; i<=8; i++)
- for (j=1; j<=8; j++) {
+ for (i=1; i<=GALSIZE; i++)
+ for (j=1; j<=GALSIZE; j++) {
int k = Rand()*9.0 + 1.0;
instar += k;
game.state.galaxy[i][j] = k;
ientesc = 1;
}
// Clear quadrant
- for (i=1; i <= 10; i++)
- for (j=1; j <= 10; j++) game.quad[i][j] = IHDOT;
+ for (i=1; i <= QUADSIZE; i++)
+ for (j=1; j <= QUADSIZE; j++) game.quad[i][j] = IHDOT;
// cope with supernova
if (quadnum > 999) {
return;
game.kpower[nenhere] = Rand()*400.0 +100.0 +25.0*skill;
/* Reserve unocupied corners */
if (game.quad[1][1]==IHDOT) game.quad[1][1] = 'X';
- if (game.quad[1][10]==IHDOT) game.quad[1][10] = 'X';
- if (game.quad[10][1]==IHDOT) game.quad[10][1] = 'X';
- if (game.quad[10][10]==IHDOT) game.quad[10][10] = 'X';
+ if (game.quad[1][QUADSIZE]==IHDOT) game.quad[1][QUADSIZE] = 'X';
+ if (game.quad[QUADSIZE][1]==IHDOT) game.quad[QUADSIZE][1] = 'X';
+ if (game.quad[QUADSIZE][QUADSIZE]==IHDOT) game.quad[QUADSIZE][QUADSIZE] = 'X';
}
sortkl();
// Take out X's in corners if Tholian present
if (ithere) {
if (game.quad[1][1]=='X') game.quad[1][1] = IHDOT;
- if (game.quad[1][10]=='X') game.quad[1][10] = IHDOT;
- if (game.quad[10][1]=='X') game.quad[10][1] = IHDOT;
- if (game.quad[10][10]=='X') game.quad[10][10] = IHDOT;
+ if (game.quad[1][QUADSIZE]=='X') game.quad[1][QUADSIZE] = IHDOT;
+ if (game.quad[QUADSIZE][1]=='X') game.quad[QUADSIZE][1] = IHDOT;
+ if (game.quad[QUADSIZE][QUADSIZE]=='X') game.quad[QUADSIZE][QUADSIZE] = IHDOT;
}
}
#define PHASEFAC (2.0)
#define PLNETMAX (10)
#define NEVENTS (8)
+#define GALSIZE (8)
+#define QUADSIZE (10)
typedef struct {
int x; /* Quadrant location of planet */
basekl, // destroyed bases
killk, // Klingons killed
killc, // commanders killed
- galaxy[9][9], // The Galaxy (subscript 0 not used)
- cx[11],cy[11], // Commander quadrant coordinates
+ galaxy[GALSIZE+1][GALSIZE+1], // The Galaxy (subscript 0 not used)
+ cx[QUADSIZE+1],cy[QUADSIZE+1], // Commander quadrant coordinates
baseqx[6], // Base quadrant X
baseqy[6], // Base quadrant Y
- newstuf[9][9], // Extended galaxy goodies
+ newstuf[GALSIZE+1][GALSIZE+1], // Extended galaxy goodies
isx, isy, // Coordinate of Super Commander
nscrem, // remaining super commanders
nromkl, // Romulans killed
char magic[sizeof(SSTMAGIC)];
snapshot state;
snapshot snapsht;
- char quad[11][11]; // contents of our quadrant
- double kpower[21]; // enemy energy levels
- double kdist[21]; // enemy distances
- double kavgd[21]; // average distances
+ char quad[QUADSIZE+1][QUADSIZE+1]; // contents of our quadrant
+ double kpower[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy energy levels
+ double kdist[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy distances
+ double kavgd[(QUADSIZE+1)*(QUADSIZE+1)]; // average distances
double damage[NDEVICES+1]; // damage encountered
double future[NEVENTS+1]; // future events
char passwd[10]; // Self Destruct password
- int kx[21]; // enemy sector locations
- int ky[21];
- int starch[9][9]; // star chart
+ int kx[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy sector locations
+ int ky[(QUADSIZE+1)*(QUADSIZE+1)];
+ int starch[GALSIZE+1][GALSIZE+1]; // star chart
/* members with macro definitions start here */
int inkling,
inbase,