From 77e371705e1e059173ec9c88f63be7a460e44e50 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 1 Nov 2004 01:23:39 +0000 Subject: [PATCH] Magic number changes, get rid of nulplanet structure. ...in favor of DESTROY macro, change planet indices to be zero-based. --- ai.c | 4 ++-- battle.c | 12 ++++++------ events.c | 8 ++++---- moving.c | 2 +- planets.c | 5 +++-- reports.c | 2 +- setup.c | 12 ++++++------ sst.c | 4 ++-- sst.h | 21 ++++++++++++--------- 9 files changed, 37 insertions(+), 33 deletions(-) diff --git a/ai.c b/ai.c index 9dcb1a0..d2223ca 100644 --- a/ai.c +++ b/ai.c @@ -344,11 +344,11 @@ static int checkdest(int iqx, int iqy, int flag, int *ipage) { sortkl(); } /* check for a helpful planet */ - for (i = 1; i <= inplan; i++) { + for (i = 0; i < inplan; i++) { if (game.state.plnets[i].x==game.state.isx && game.state.plnets[i].y==game.state.isy && game.state.plnets[i].crystals == 1) { /* destroy the planet */ - game.state.plnets[i] = nulplanet; + DESTROY(&game.state.plnets[i]); game.state.newstuf[game.state.isx][game.state.isy] -= 1; if (game.damage[DRADIO] == 0.0 || condit == IHDOCKED) { if (*ipage==0) pause(1); diff --git a/battle.c b/battle.c index 1f043c6..590d08c 100644 --- a/battle.c +++ b/battle.c @@ -156,7 +156,7 @@ void ram(int ibumpd, int ienm, int ix, int iy) { crami(icas, 1); prout(" casualties."); casual += icas; - for (l=1; l <= ndevice; l++) { + for (l=1; l <= NDEVICES; l++) { if (l == DDRAY) continue; // Don't damage deathray if (game.damage[l] < 0) continue; extradm = (10.0*type*Rand()+1.0)*damfac; @@ -311,7 +311,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { prout(" destroyed."); game.state.nplankl++; game.state.newstuf[quadx][quady] -= 1; - game.state.plnets[iplnet] = nulplanet; + DESTROY(&game.state.plnets[iplnet]); iplnet = 0; plnetx = plnety = 0; game.quad[ix][iy] = IHDOT; @@ -412,7 +412,7 @@ static void fry(double hit) { /* Select devices and cause damage */ for (l = 1; l <= ncrit; l++) { do { - j = ndevice*Rand()+1.0; + j = NDEVICES*Rand()+1.0; /* Cheat to prevent shuttle damage unless on ship */ } while (game.damage[j] < 0.0 || (j == DSHUTTL && iscraft != 1) || j == DDRAY); @@ -1017,7 +1017,7 @@ void phasers(void) { for (i = 1; i <= nenhere; i++) { hits[i] = 0.0; if (powrem <= 0) continue; - hits[i] = fabs(game.kpower[i])/(phasefac*pow(0.90,game.kdist[i])); + hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i])); over = (0.01 + 0.05*Rand())*hits[i]; temp = powrem; powrem -= hits[i] + over; @@ -1080,7 +1080,7 @@ void phasers(void) { if (key == IHEOL) { chew(); if (ipoop && k > kz) { - int irec=(fabs(game.kpower[k])/(phasefac*pow(0.9,game.kdist[k])))* + int irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))* (1.01+0.05*Rand()) + 1.0; kz = k; proutn("("); @@ -1179,7 +1179,7 @@ void hittem(double *hits) { hit = wham*pow(dustfac,game.kdist[kk]); kpini = game.kpower[kk]; kp = fabs(kpini); - if (phasefac*hit < kp) kp = phasefac*hit; + if (PHASEFAC*hit < kp) kp = PHASEFAC*hit; game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp); kpow = game.kpower[kk]; ii = game.kx[kk]; diff --git a/events.c b/events.c index 1fad713..0cbc880 100644 --- a/events.c +++ b/events.c @@ -51,7 +51,7 @@ void events(void) { repair = xtime; if (condit == IHDOCKED) repair /= docfac; /* Don't fix Deathray here */ - for (l=1; l<=ndevice; l++) + for (l=1; l<=NDEVICES; l++) if (game.damage[l] > 0.0 && l != DDRAY) game.damage[l] -= (game.damage[l]-repair > 0.0 ? repair : game.damage[l]); /* If radio repaired, update star chart and attack reports */ @@ -473,7 +473,7 @@ void nova(int ix, int iy) { game.state.nplankl++; crmena(1, IHP, 2, ii, jj); prout(" destroyed."); - game.state.plnets[iplnet] = nulplanet; + DESTROY(&game.state.plnets[iplnet]); iplnet = plnetx = plnety = 0; if (landed == 1) { finish(FPNOVA); @@ -715,9 +715,9 @@ void snova(int insx, int insy) { npdead = num - nrmdead*10; if (npdead) { int l; - for (l = 1; l <= inplan; l++) + for (l = 0; l < inplan; l++) if (game.state.plnets[l].x == nqx && game.state.plnets[l].y == nqy) { - game.state.plnets[l] = nulplanet; + DESTROY(&game.state.plnets[l]); } } /* Destroy any base in supernovaed quadrant */ diff --git a/moving.c b/moving.c index 26011bf..0b9ecbe 100644 --- a/moving.c +++ b/moving.c @@ -764,7 +764,7 @@ void timwrp() { /* Make sure Galileo is consistant -- Snapshot may have been taken when on planet, which would give us two Galileos! */ gotit = 0; - for (l = 1; l <= inplan; l++) { + for (l = 0; l < inplan; l++) { if (game.state.plnets[l].known == shuttle_down) { gotit = 1; if (iscraft==1 && ship==IHE) { diff --git a/planets.c b/planets.c index a98235f..3f9bfc3 100644 --- a/planets.c +++ b/planets.c @@ -1,8 +1,9 @@ #include "sst.h" -static char classes[4][2]={"","M","N","O"}; static int height; +static char *classes[] = {"M","N","O"}; + static int consumeTime(void) { /* I think most of this avoidance was caused by overlay scheme. Let's see what happens if all events can occur here */ @@ -31,7 +32,7 @@ void preport(void) { chew(); prout("Spock- \"Planet report follows, Captain.\""); skip(1); - for (i = 1; i <= inplan; i++) { + for (i = 0; i < inplan; i++) { if (game.state.plnets[i].known != unknown #ifdef DEBUG || ( idebug && game.state.plnets[i].x !=0) diff --git a/reports.c b/reports.c index 9475ab3..436900e 100644 --- a/reports.c +++ b/reports.c @@ -147,7 +147,7 @@ void dreprt(void) { int jdam = FALSE, i; chew(); - for (i = 1; i <= ndevice; i++) { + for (i = 1; i <= NDEVICES; i++) { if (game.damage[i] > 0.0) { if (!jdam) { skip(1); diff --git a/setup.c b/setup.c index 6b24e06..24c5f6f 100644 --- a/setup.c +++ b/setup.c @@ -161,7 +161,7 @@ void abandn(void) { iscraft=0; /* Gallileo disappears */ /* Resupply ship */ condit=IHDOCKED; - for (l = 1; l <= ndevice; l++) game.damage[l] = 0.0; + for (l = 1; l <= NDEVICES; l++) game.damage[l] = 0.0; game.damage[DSHUTTL] = -1; energy = inenrg = 3000.0; shield = inshld = 1250.0; @@ -195,7 +195,7 @@ void setup(void) { nprobes = (int)(3.0*Rand() + 2.0); /* Give them 2-4 of these wonders */ warpfac = 5.0; wfacsq = warpfac * warpfac; - for (i=0; i <= ndevice; i++) game.damage[i] = 0.0; + for (i=0; i <= NDEVICES; i++) game.damage[i] = 0.0; // Set up assorted game parameters batx = baty = 0; game.state.date = indate = 100.0*(int)(31.0*Rand()+20.0); @@ -298,13 +298,13 @@ void setup(void) { game.state.cy[i] = iy; } // Locate planets in galaxy - for (i = 1; i <= inplan; i++) { + for (i = 0; i < inplan; i++) { do iran8(&ix, &iy); while (game.state.newstuf[ix][iy] > 0); game.state.newstuf[ix][iy] = 1; game.state.plnets[i].x = ix; game.state.plnets[i].y = iy; - game.state.plnets[i].pclass = Rand()*3.0 + 1.0; // Planet class M N or O + game.state.plnets[i].pclass = Rand()*3.0; // Planet class M N or O game.state.plnets[i].crystals = 1.5*Rand(); // 1 in 3 chance of crystals game.state.plnets[i].known = unknown; } @@ -593,9 +593,9 @@ void newqad(int shutup) { if (nplan) { // If quadrant needs a planet, put it in - for (i=1; i <= inplan; i++) + for (i=0; i < inplan; i++) if (game.state.plnets[i].x == quadx && game.state.plnets[i].y == quady) break; - if (i <= inplan) { + if (i < inplan) { iplnet = i; dropin(IHP, &plnetx, &plnety); } diff --git a/sst.c b/sst.c index 3120225..f6db887 100644 --- a/sst.c +++ b/sst.c @@ -637,7 +637,7 @@ void debugme(void) { proutn("Reset damage? "); if (ja() != 0) { int i; - for (i=0; i <= ndevice; i++) if (damage[i] > 0.0) damage[i] = 0.0; + for (i=0; i <= NDEVICES; i++) if (damage[i] > 0.0) damage[i] = 0.0; stdamtim = 1e30; } proutn("Toggle idebug? "); @@ -649,7 +649,7 @@ void debugme(void) { proutn("Cause selective damage? "); if (ja() != 0) { int i, key; - for (i=1; i <= ndevice; i++) { + for (i=1; i <= NDEVICES; i++) { proutn("Kill "); proutn(device[i]); proutn("? "); diff --git a/sst.h b/sst.h index 5617ae3..a2c4c92 100644 --- a/sst.h +++ b/sst.h @@ -10,19 +10,21 @@ // #define DEBUG -#define ndevice (15) // Number of devices -#define phasefac (2.0) +#define NDEVICES (15) // Number of devices +#define PHASEFAC (2.0) #define PLNETMAX (10) #define NEVENTS (8) typedef struct { int x; /* Quadrant location of planet */ int y; - int pclass; /* class M, N, or O (1, 2, or 3) */ + enum {M=0, N=1, O=2} pclass; int crystals; /* has crystals */ enum {unknown, known, shuttle_down} known; } planet; +#define DESTROY(pl) memset(pl, '\0', sizeof(planet)) + typedef struct { int snap, // snapshot taken remkl, // remaining klingons @@ -43,7 +45,7 @@ typedef struct { nromrem, // Romulans remaining nsckill, // super commanders killed nplankl; // destroyed planets - planet plnets[PLNETMAX+1]; // Planet information + planet plnets[PLNETMAX]; // Planet information double date, // stardate remres, // remaining resources remtime; // remaining time @@ -54,14 +56,17 @@ typedef struct { // original names. Gee, I could have done this with the d structure, // but I just didn't think of it back when I started. +#define SSTMAGIC "SST2.0\n" + EXTERN struct { + 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 - double damage[ndevice+1]; // damage encountered + double damage[NDEVICES+1]; // damage encountered double future[NEVENTS+1]; // future events char passwd[10]; // Self Destruct password int kx[21]; // enemy sector locations @@ -247,8 +252,7 @@ EXTERN struct { /* the following global state doesn't need to be saved */ EXTERN int fromcommandline; // Game start from command line options -EXTERN char *device[ndevice+1]; -EXTERN planet nulplanet; // zeroed planet structure +EXTERN char *device[NDEVICES+1]; EXTERN int iscore, iskill; // Common PLAQ EXTERN double perdate; EXTERN double aaitem; @@ -290,8 +294,7 @@ typedef enum {FWON, FDEPLETE, FLIFESUP, FNRG, FBATTLE, #define FDSPROB 8 // Move deep space probe #ifdef INCLUDED -planet nulplanet = {0}; -char *device[ndevice+1] = { +char *device[NDEVICES+1] = { "", "S. R. Sensors", "L. R. Sensors", -- 2.31.1