From 5db6160de8bad4de189d3b54dd54011260c7a34f Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 7 Feb 2005 09:47:49 +0000 Subject: [PATCH] Change devices arrays from 1-origin to 0-origin. --- battle.c | 20 +++++++++++--------- events.c | 2 +- moving.c | 8 ++++---- reports.c | 7 ++++--- setup.c | 6 ++++-- sst.c | 4 ++-- sst.h | 47 +++++++++++++++++++++++------------------------ 7 files changed, 49 insertions(+), 45 deletions(-) diff --git a/battle.c b/battle.c index f8c81eb..75ac190 100644 --- a/battle.c +++ b/battle.c @@ -159,9 +159,11 @@ void ram(int ibumpd, int ienm, int ix, int iy) icas = 10.0+20.0*Rand(); prout("***Sickbay reports %d casualties", icas); casual += icas; - for (l=1; l <= NDEVICES; l++) { - if (l == DDRAY) continue; // Don't damage deathray - if (game.damage[l] < 0) continue; + for (l=0; 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; game.damage[l] += Time + extradm; /* Damage for at least time of travel! */ } @@ -422,7 +424,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int wait, i static void fry(double hit) { double ncrit, extradm; - int ktr=1, l, ll, j, cdam[NDEVICES+1]; + int ktr=1, l, ll, j, cdam[NDEVICES]; /* a critical hit occured */ if (hit < (275.0-25.0*skill)*(1.0+0.5*Rand())) return; @@ -430,16 +432,16 @@ static void fry(double hit) ncrit = 1.0 + hit/(500.0+100.0*Rand()); proutn("***CRITICAL HIT--"); /* Select devices and cause damage */ - for (l = 1; l <= ncrit && l <= NDEVICES; l++) { + for (l = 0; l < ncrit && 0 < NDEVICES; l++) { do { - j = NDEVICES*Rand()+1.0; + j = NDEVICES*Rand(); /* Cheat to prevent shuttle damage unless on ship */ - } while (game.damage[j] < 0.0 || (j == DSHUTTL && iscraft != 1) || - j == DDRAY); + } while + (game.damage[j]<0.0 || (j==DSHUTTL && iscraft!=1) || j==DDRAY); cdam[l] = j; extradm = (hit*damfac)/(ncrit*(75.0+25.0*Rand())); game.damage[j] += extradm; - if (l > 1) { + if (l > 0) { for (ll=2; ll<=l && j != cdam[ll-1]; ll++) ; if (ll<=l) continue; ktr += 1; diff --git a/events.c b/events.c index c9d0f7b..5b75fae 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<=NDEVICES; l++) + for (l=0; 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 */ diff --git a/moving.c b/moving.c index 0c91f71..f9b352b 100644 --- a/moving.c +++ b/moving.c @@ -147,10 +147,10 @@ void imove(void) * possibility that you'll get timewarped instead. */ n=0; - for (l=1;l<=NDEVICES+1;l++) - if (game.damage[l]>0) n++; - probf=pow(1.4,(energy+shield)/5000.0-1.0)* - pow(1.3,1.0/(n+1)-1.0); + for (l=0;l0) + n++; + probf=pow(1.4,(energy+shield)/5000.0-1.0)*pow(1.3,1.0/(n+1)-1.0); if (Rand()>probf) timwrp(); else diff --git a/reports.c b/reports.c index e6c9f6e..de2ba1b 100644 --- a/reports.c +++ b/reports.c @@ -149,7 +149,7 @@ void dreprt(void) int jdam = FALSE, i; chew(); - for (i = 1; i <= NDEVICES; i++) { + for (i = 0; i < NDEVICES; i++) { if (game.damage[i] > 0.0) { if (!jdam) { prout("DEVICE -REPAIR TIMES-"); @@ -253,8 +253,9 @@ static void status(int req) case IHDOCKED: cp = "DOCKED"; break; case IHDEAD: cp="DEAD"; break; } - for (t=0;t<=NDEVICES;t++) - if (game.damage[t]>0) dam++; + for (t=0;t0) + dam++; proutn("Condition %s, %i DAMAGES", cp, dam); break; case 3: diff --git a/setup.c b/setup.c index 3066651..b9c4842 100644 --- a/setup.c +++ b/setup.c @@ -179,7 +179,8 @@ void abandn(void) iscraft=0; /* Gallileo disappears */ /* Resupply ship */ condit=IHDOCKED; - for (l = 1; l <= NDEVICES; l++) game.damage[l] = 0.0; + for (l = 0; l < NDEVICES; l++) + game.damage[l] = 0.0; game.damage[DSHUTTL] = -1; energy = inenrg = 3000.0; shield = inshld = 1250.0; @@ -214,7 +215,8 @@ void setup(int needprompt) nprobes = (int)(3.0*Rand() + 2.0); /* Give them 2-4 of these wonders */ warpfac = 5.0; wfacsq = warpfac * warpfac; - for (i=0; i <= NDEVICES; 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); diff --git a/sst.c b/sst.c index 5dfdabd..65c79ac 100644 --- a/sst.c +++ b/sst.c @@ -749,7 +749,7 @@ void debugme(void) proutn("Reset damage? "); if (ja() != 0) { int i; - for (i=0; i <= NDEVICES; i++) + for (i=0; i < NDEVICES; i++) if (game.damage[i] > 0.0) game.damage[i] = 0.0; stdamtim = 1e30; @@ -763,7 +763,7 @@ void debugme(void) proutn("Cause selective damage? "); if (ja() != 0) { int i, key; - for (i=1; i <= NDEVICES; i++) { + for (i=0; i < NDEVICES; i++) { proutn("Kill "); proutn(device[i]); proutn("? "); diff --git a/sst.h b/sst.h index 64dd1bc..5b6fb04 100644 --- a/sst.h +++ b/sst.h @@ -14,7 +14,6 @@ // #define DEBUG -#define NDEVICES (15) // Number of devices #define PHASEFAC (2.0) #define PLNETMAX (10) #define NEVENTS (8) @@ -95,6 +94,24 @@ typedef struct { #define OPTION_THINGY 0x00000010 /* Space Thingy can shoot back */ #define OPTION_PROBE 0x00000020 /* deep-space probes */ +/* Define devices */ +#define DSRSENS 0 +#define DLRSENS 1 +#define DPHASER 2 +#define DPHOTON 3 +#define DLIFSUP 4 +#define DWARPEN 5 +#define DIMPULS 6 +#define DSHIELD 7 +#define DRADIO 8 +#define DSHUTTL 9 +#define DCOMPTR 10 +#define DTRANSP 11 +#define DSHCTRL 12 +#define DDRAY 13 // Added deathray +#define DDSP 14 // Added deep space probe +#define NDEVICES (15) // Number of devices + // Scalar variables that are needed for freezing the game // are placed in a structure. #defines are used to access by their // original names. Gee, I could have done this with the d structure, @@ -113,7 +130,7 @@ EXTERN struct { 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 damage[NDEVICES]; // damage encountered double future[NEVENTS+1]; // future events char passwd[10]; // Self Destruct password int kx[(QUADSIZE+1)*(QUADSIZE+1)]; // enemy sector locations @@ -294,7 +311,7 @@ EXTERN struct { #define nprobes game.nprobes // number of probes available /* the following global state doesn't need to be saved */ -EXTERN char *device[NDEVICES+1]; +EXTERN char *device[NDEVICES]; EXTERN int iscore, iskill; // Common PLAQ EXTERN double perdate; EXTERN double aaitem; @@ -310,23 +327,6 @@ typedef enum {FWON, FDEPLETE, FLIFESUP, FNRG, FBATTLE, FHOLE} FINTYPE ; enum loctype {neither, quadrant, sector}; -/* Define devices */ -#define DSRSENS 1 -#define DLRSENS 2 -#define DPHASER 3 -#define DPHOTON 4 -#define DLIFSUP 5 -#define DWARPEN 6 -#define DIMPULS 7 -#define DSHIELD 8 -#define DRADIO 9 -#define DSHUTTL 10 -#define DCOMPTR 11 -#define DTRANSP 12 -#define DSHCTRL 13 -#define DDRAY 14 // Added deathray -#define DDSP 15 // Added deep space probe - /* Define future events */ #define FSPY 0 // Spy event happens always (no future[] entry) // can cause SC to tractor beam Enterprise @@ -340,8 +340,7 @@ enum loctype {neither, quadrant, sector}; #define FDSPROB 8 // Move deep space probe #ifdef INCLUDED -char *device[NDEVICES+1] = { - "", +char *device[NDEVICES] = { "S. R. Sensors", "L. R. Sensors", "Phasers", @@ -355,8 +354,8 @@ char *device[NDEVICES+1] = { "Computer", "Transporter", "Shield Control", - "Death Ray", - "D. S. Probe"}; + "Death Ray", + "D. S. Probe"}; #endif #ifndef TRUE -- 2.31.1