...in favor of DESTROY macro, change planet indices to be zero-based.
sortkl();\r
}\r
/* check for a helpful planet */\r
- for (i = 1; i <= inplan; i++) {\r
+ for (i = 0; i < inplan; i++) {\r
if (game.state.plnets[i].x==game.state.isx && game.state.plnets[i].y==game.state.isy &&\r
game.state.plnets[i].crystals == 1) {\r
/* destroy the planet */\r
- game.state.plnets[i] = nulplanet;\r
+ DESTROY(&game.state.plnets[i]);\r
game.state.newstuf[game.state.isx][game.state.isy] -= 1;\r
if (game.damage[DRADIO] == 0.0 || condit == IHDOCKED) {\r
if (*ipage==0) pause(1);\r
crami(icas, 1);\r
prout(" casualties.");\r
casual += icas;\r
- for (l=1; l <= ndevice; l++) {\r
+ for (l=1; l <= NDEVICES; l++) {\r
if (l == DDRAY) continue; // Don't damage deathray \r
if (game.damage[l] < 0) continue;\r
extradm = (10.0*type*Rand()+1.0)*damfac;\r
prout(" destroyed.");\r
game.state.nplankl++;\r
game.state.newstuf[quadx][quady] -= 1;\r
- game.state.plnets[iplnet] = nulplanet;\r
+ DESTROY(&game.state.plnets[iplnet]);\r
iplnet = 0;\r
plnetx = plnety = 0;\r
game.quad[ix][iy] = IHDOT;\r
/* Select devices and cause damage */\r
for (l = 1; l <= ncrit; l++) {\r
do {\r
- j = ndevice*Rand()+1.0;\r
+ j = NDEVICES*Rand()+1.0;\r
/* Cheat to prevent shuttle damage unless on ship */\r
} while (game.damage[j] < 0.0 || (j == DSHUTTL && iscraft != 1) ||\r
j == DDRAY);\r
for (i = 1; i <= nenhere; i++) {\r
hits[i] = 0.0;\r
if (powrem <= 0) continue;\r
- hits[i] = fabs(game.kpower[i])/(phasefac*pow(0.90,game.kdist[i]));\r
+ hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));\r
over = (0.01 + 0.05*Rand())*hits[i];\r
temp = powrem;\r
powrem -= hits[i] + over;\r
if (key == IHEOL) {\r
chew();\r
if (ipoop && k > kz) {\r
- int irec=(fabs(game.kpower[k])/(phasefac*pow(0.9,game.kdist[k])))*\r
+ int irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*\r
(1.01+0.05*Rand()) + 1.0;\r
kz = k;\r
proutn("(");\r
hit = wham*pow(dustfac,game.kdist[kk]);\r
kpini = game.kpower[kk];\r
kp = fabs(kpini);\r
- if (phasefac*hit < kp) kp = phasefac*hit;\r
+ if (PHASEFAC*hit < kp) kp = PHASEFAC*hit;\r
game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp);\r
kpow = game.kpower[kk];\r
ii = game.kx[kk];\r
repair = xtime;\r
if (condit == IHDOCKED) repair /= docfac;\r
/* Don't fix Deathray here */\r
- for (l=1; l<=ndevice; l++)\r
+ for (l=1; l<=NDEVICES; l++)\r
if (game.damage[l] > 0.0 && l != DDRAY)\r
game.damage[l] -= (game.damage[l]-repair > 0.0 ? repair : game.damage[l]);\r
/* If radio repaired, update star chart and attack reports */\r
game.state.nplankl++;\r
crmena(1, IHP, 2, ii, jj);\r
prout(" destroyed.");\r
- game.state.plnets[iplnet] = nulplanet;\r
+ DESTROY(&game.state.plnets[iplnet]);\r
iplnet = plnetx = plnety = 0;\r
if (landed == 1) {\r
finish(FPNOVA);\r
npdead = num - nrmdead*10;\r
if (npdead) {\r
int l;\r
- for (l = 1; l <= inplan; l++)\r
+ for (l = 0; l < inplan; l++)\r
if (game.state.plnets[l].x == nqx && game.state.plnets[l].y == nqy) {\r
- game.state.plnets[l] = nulplanet;\r
+ DESTROY(&game.state.plnets[l]);\r
}\r
}\r
/* Destroy any base in supernovaed quadrant */\r
/* Make sure Galileo is consistant -- Snapshot may have been taken\r
when on planet, which would give us two Galileos! */\r
gotit = 0;\r
- for (l = 1; l <= inplan; l++) {\r
+ for (l = 0; l < inplan; l++) {\r
if (game.state.plnets[l].known == shuttle_down) {\r
gotit = 1;\r
if (iscraft==1 && ship==IHE) {\r
#include "sst.h"\r
\r
-static char classes[4][2]={"","M","N","O"};\r
static int height;\r
\r
+static char *classes[] = {"M","N","O"};\r
+\r
static int consumeTime(void) {\r
/* I think most of this avoidance was caused by overlay scheme.\r
Let's see what happens if all events can occur here */\r
chew();\r
prout("Spock- \"Planet report follows, Captain.\"");\r
skip(1);\r
- for (i = 1; i <= inplan; i++) {\r
+ for (i = 0; i < inplan; i++) {\r
if (game.state.plnets[i].known != unknown\r
#ifdef DEBUG\r
|| ( idebug && game.state.plnets[i].x !=0)\r
int jdam = FALSE, i;\r
chew();\r
\r
- for (i = 1; i <= ndevice; i++) {\r
+ for (i = 1; i <= NDEVICES; i++) {\r
if (game.damage[i] > 0.0) {\r
if (!jdam) {\r
skip(1);\r
iscraft=0; /* Gallileo disappears */\r
/* Resupply ship */\r
condit=IHDOCKED;\r
- for (l = 1; l <= ndevice; l++) game.damage[l] = 0.0;\r
+ for (l = 1; l <= NDEVICES; l++) game.damage[l] = 0.0;\r
game.damage[DSHUTTL] = -1;\r
energy = inenrg = 3000.0;\r
shield = inshld = 1250.0;\r
nprobes = (int)(3.0*Rand() + 2.0); /* Give them 2-4 of these wonders */\r
warpfac = 5.0;\r
wfacsq = warpfac * warpfac;\r
- for (i=0; i <= ndevice; i++) game.damage[i] = 0.0;\r
+ for (i=0; i <= NDEVICES; i++) game.damage[i] = 0.0;\r
// Set up assorted game parameters\r
batx = baty = 0;\r
game.state.date = indate = 100.0*(int)(31.0*Rand()+20.0);\r
game.state.cy[i] = iy;\r
}\r
// Locate planets in galaxy\r
- for (i = 1; i <= inplan; i++) {\r
+ for (i = 0; i < inplan; i++) {\r
do iran8(&ix, &iy);\r
while (game.state.newstuf[ix][iy] > 0);\r
game.state.newstuf[ix][iy] = 1;\r
game.state.plnets[i].x = ix;\r
game.state.plnets[i].y = iy;\r
- game.state.plnets[i].pclass = Rand()*3.0 + 1.0; // Planet class M N or O\r
+ game.state.plnets[i].pclass = Rand()*3.0; // Planet class M N or O\r
game.state.plnets[i].crystals = 1.5*Rand(); // 1 in 3 chance of crystals\r
game.state.plnets[i].known = unknown;\r
}\r
\r
if (nplan) {\r
// If quadrant needs a planet, put it in\r
- for (i=1; i <= inplan; i++)\r
+ for (i=0; i < inplan; i++)\r
if (game.state.plnets[i].x == quadx && game.state.plnets[i].y == quady) break;\r
- if (i <= inplan) {\r
+ if (i < inplan) {\r
iplnet = i;\r
dropin(IHP, &plnetx, &plnety);\r
}\r
proutn("Reset damage? ");\r
if (ja() != 0) {\r
int i;\r
- for (i=0; i <= ndevice; i++) if (damage[i] > 0.0) damage[i] = 0.0;\r
+ for (i=0; i <= NDEVICES; i++) if (damage[i] > 0.0) damage[i] = 0.0;\r
stdamtim = 1e30;\r
}\r
proutn("Toggle idebug? ");\r
proutn("Cause selective damage? ");\r
if (ja() != 0) {\r
int i, key;\r
- for (i=1; i <= ndevice; i++) {\r
+ for (i=1; i <= NDEVICES; i++) {\r
proutn("Kill ");\r
proutn(device[i]);\r
proutn("? ");\r
\r
// #define DEBUG\r
\r
-#define ndevice (15) // Number of devices\r
-#define phasefac (2.0)\r
+#define NDEVICES (15) // Number of devices\r
+#define PHASEFAC (2.0)\r
#define PLNETMAX (10)\r
#define NEVENTS (8)\r
\r
typedef struct {\r
int x; /* Quadrant location of planet */\r
int y;\r
- int pclass; /* class M, N, or O (1, 2, or 3) */\r
+ enum {M=0, N=1, O=2} pclass;\r
int crystals; /* has crystals */\r
enum {unknown, known, shuttle_down} known;\r
} planet;\r
\r
+#define DESTROY(pl) memset(pl, '\0', sizeof(planet))\r
+\r
typedef struct {\r
int snap, // snapshot taken\r
remkl, // remaining klingons\r
nromrem, // Romulans remaining\r
nsckill, // super commanders killed\r
nplankl; // destroyed planets\r
- planet plnets[PLNETMAX+1]; // Planet information\r
+ planet plnets[PLNETMAX]; // Planet information\r
double date, // stardate\r
remres, // remaining resources\r
remtime; // remaining time\r
// original names. Gee, I could have done this with the d structure,\r
// but I just didn't think of it back when I started.\r
\r
+#define SSTMAGIC "SST2.0\n"\r
+\r
EXTERN struct {\r
+ char magic[sizeof(SSTMAGIC)];\r
snapshot state;\r
snapshot snapsht;\r
char quad[11][11]; // contents of our quadrant\r
double kpower[21]; // enemy energy levels\r
double kdist[21]; // enemy distances\r
double kavgd[21]; // average distances\r
- double damage[ndevice+1]; // damage encountered\r
+ double damage[NDEVICES+1]; // damage encountered\r
double future[NEVENTS+1]; // future events\r
char passwd[10]; // Self Destruct password\r
int kx[21]; // enemy sector locations\r
\r
/* the following global state doesn't need to be saved */\r
EXTERN int fromcommandline; // Game start from command line options\r
-EXTERN char *device[ndevice+1];\r
-EXTERN planet nulplanet; // zeroed planet structure\r
+EXTERN char *device[NDEVICES+1];\r
EXTERN int iscore, iskill; // Common PLAQ\r
EXTERN double perdate;\r
EXTERN double aaitem;\r
#define FDSPROB 8 // Move deep space probe\r
\r
#ifdef INCLUDED\r
-planet nulplanet = {0};\r
-char *device[ndevice+1] = {\r
+char *device[NDEVICES+1] = {\r
"",\r
"S. R. Sensors",\r
"L. R. Sensors",\r