From f972ad4a9a237ecae732391e0c37345fdfb9acea Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sun, 6 Feb 2005 16:37:01 +0000 Subject: [PATCH] More magic-number fixes. --- ai.c | 24 ++++++++++++------------ events.c | 6 +++--- reports.c | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/ai.c b/ai.c index 5865c29..db9de87 100644 --- a/ai.c +++ b/ai.c @@ -84,7 +84,7 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) { if (ienm==IHS && (game.kpower[loccom] <= 500.0 || (condit==IHDOCKED && game.damage[DPHOTON]==0))) { irun = 1; - motion = -10; + motion = -QUADSIZE; } else { /* decide whether to advance, retreat, or hold position */ @@ -165,7 +165,7 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) { /* calcuate preferred number of steps */ nsteps = motion < 0 ? -motion : motion; if (motion > 0 && nsteps > mdist) nsteps = mdist; /* don't overshoot */ - if (nsteps > 10) nsteps = 10; /* This shouldn't be necessary */ + if (nsteps > QUADSIZE) nsteps = QUADSIZE; /* This shouldn't be necessary */ if (nsteps < 1) nsteps = 1; /* This shouldn't be necessary */ #ifdef DEBUG if (idebug) { @@ -196,14 +196,14 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) { success = 0; attempts = 0; /* Settle mysterious hang problem */ while (attempts++ < 20 && !success) { - if (lookx < 1 || lookx > 10) { + if (lookx < 1 || lookx > QUADSIZE) { if (motion < 0 && tryexit(lookx, looky, ienm, loccom, irun)) return; if (krawlx == mx || my == 0) break; lookx = nextx + krawlx; krawlx = -krawlx; } - else if (looky < 1 || looky > 10) { + else if (looky < 1 || looky > QUADSIZE) { if (motion < 0 && tryexit(lookx, looky, ienm, loccom, irun)) return; if (krawly == my || mx == 0) break; @@ -546,15 +546,15 @@ void movetho(void) { if (ithere==0 || justin == 1) return; if (ithx == 1 && ithy == 1) { - idx = 1; idy = 10; + idx = 1; idy = QUADSIZE; } - else if (ithx == 1 && ithy == 10) { - idx = 10; idy = 10; + else if (ithx == 1 && ithy == QUADSIZE) { + idx = QUADSIZE; idy = QUADSIZE; } - else if (ithx == 10 && ithy == 10) { - idx = 10; idy = 1; + else if (ithx == QUADSIZE && ithy == QUADSIZE) { + idx = QUADSIZE; idy = 1; } - else if (ithx == 10 && ithy == 1) { + else if (ithx == QUADSIZE && ithy == 1) { idx = 1; idy = 1; } else { @@ -590,9 +590,9 @@ void movetho(void) { /* check to see if all holes plugged */ for (i = 1; i < 11; i++) { if (game.quad[1][i]!=IHWEB && game.quad[1][i]!=IHT) return; - if (game.quad[10][i]!=IHWEB && game.quad[10][i]!=IHT) return; + if (game.quad[QUADSIZE][i]!=IHWEB && game.quad[QUADSIZE][i]!=IHT) return; if (game.quad[i][1]!=IHWEB && game.quad[i][1]!=IHT) return; - if (game.quad[i][10]!=IHWEB && game.quad[i][10]!=IHT) return; + if (game.quad[i][QUADSIZE]!=IHWEB && game.quad[i][QUADSIZE]!=IHT) return; } /* All plugged up -- Tholian splits */ game.quad[ithx][ithy]=IHWEB; diff --git a/events.c b/events.c index 4923660..51470c1 100644 --- a/events.c +++ b/events.c @@ -304,8 +304,8 @@ void events(void) { game.future[FDSPROB] = game.state.date + 0.01; probex += probeinx; probey += probeiny; - i = (int)(probex/10 +0.05); - j = (int)(probey/10 + 0.05); + i = (int)(probex/QUADSIZE +0.05); + j = (int)(probey/QUADSIZE + 0.05); if (probecx != i || probecy != j) { probecx = i; probecy = j; @@ -410,7 +410,7 @@ void wait(void) { void nova(int ix, int iy) { static double course[] = {0.0, 10.5, 12.0, 1.5, 9.0, 0.0, 3.0, 7.5, 6.0, 4.5}; - int bot, top, top2, hits[11][3], kount, icx, icy, mm, nn, j; + int bot, top, top2, hits[QUADSIZE+1][3], kount, icx, icy, mm, nn, j; int iquad, iquad1, i, ll, newcx, newcy, ii, jj; if (Rand() < 0.05) { /* Wow! We've supernova'ed */ diff --git a/reports.c b/reports.c index 4c3fd33..f71b8c5 100644 --- a/reports.c +++ b/reports.c @@ -257,11 +257,11 @@ int srscan(int l) { break; } if (condit != IHDOCKED) newcnd(); - for (i = 1; i <= 10; i++) { + for (i = 1; i <= QUADSIZE; i++) { jj = (k!=0 ? k : i); if (leftside) { proutn("%2d ", i); - for (j = 1; j <= 10; j++) { + for (j = 1; j <= QUADSIZE; j++) { if (goodScan || (abs(i-sectx)<= 1 && abs(j-secty) <= 1)){ if ((game.quad[i][j]==IHMATER0)||(game.quad[i][j]==IHMATER1)||(game.quad[i][j]==IHMATER2)||(game.quad[i][j]==IHE)||(game.quad[i][j]==IHF)){ switch (condit) { -- 2.31.1