From 321425c10831f63599c41c31e9d42bc4ec8001d0 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 29 Sep 2006 07:41:43 +0000 Subject: [PATCH] Get rid of the iterator macros I wrote. They interfere with mechanical translation. --- src/ai.c | 84 ++++++++++++++++++++++++++------------------------- src/battle.c | 23 +++++++------- src/events.c | 26 ++++++++-------- src/moving.c | 11 ++++--- src/planets.c | 4 +-- src/reports.c | 10 +++--- src/setup.c | 16 +++++----- src/sst.h | 5 --- 8 files changed, 88 insertions(+), 91 deletions(-) diff --git a/src/ai.c b/src/ai.c index 2849b61..7f0112d 100644 --- a/src/ai.c +++ b/src/ai.c @@ -17,7 +17,7 @@ static bool tryexit(coord look, int ienm, int loccom, bool irun) if (!irun) { /* avoid intruding on another commander's territory */ if (ienm == IHC) { - for_commanders(n) + for (n = 1; n <= game.state.remcom; n++) if (same(game.state.kcmdr[n],iq)) return false; /* refuse to leave if currently attacking starbase */ @@ -59,7 +59,7 @@ static bool tryexit(coord look, int ienm, int loccom, bool irun) game.state.kscmdr=iq; } else { - for_commanders(n) { + for (n = 1; n <= game.state.remcom; n++) { if (same(game.state.kcmdr[n], game.quadrant)) { game.state.kcmdr[n]=iq; break; @@ -285,7 +285,7 @@ void moveklings(void) // Figure out which Klingon is the commander (or Supercommander) // and do move if (game.comhere) - for_local_enemies(i) { + for (i = 1; i <= game.nenhere; i++) { w = game.ks[i]; if (game.quad[w.x][w.y] == IHC) { movebaddy(w, i, IHC); @@ -293,7 +293,7 @@ void moveklings(void) } } if (game.ishere) - for_local_enemies(i) { + for (i = 1; i <= game.nenhere; i++) { w = game.ks[i]; if (game.quad[w.x][w.y] == IHS) { movebaddy(w, i, IHS); @@ -304,7 +304,7 @@ void moveklings(void) // Move these last so they can base their actions on what the // commander(s) do. if (game.skill >= SKILL_EXPERT && (game.options & OPTION_MVBADDY)) - for_local_enemies(i) { + for (i = 1; i <= game.nenhere; i++) { w = game.ks[i]; if (game.quad[w.x][w.y] == IHK || game.quad[w.x][w.y] == IHR) movebaddy(w, i, game.quad[w.x][w.y]); @@ -324,7 +324,7 @@ static bool movescom(coord iq, bool avoid) return 1; if (avoid) { /* Avoid quadrants with bases if we want to avoid Enterprise */ - for_starbases(i) + for (i = 1; i <= game.state.rembase; i++) if (same(game.state.baseq[i], iq)) return true; } @@ -341,7 +341,7 @@ static bool movescom(coord iq, bool avoid) game.ishere = false; game.ientesc = false; unschedule(FSCDBAS); - for_local_enemies(i) + for (i = 1; i <= game.nenhere; i++) if (game.quad[game.ks[i].x][game.ks[i].y] == IHS) break; game.quad[game.ks[i].x][game.ks[i].y] = IHDOT; @@ -409,7 +409,7 @@ void supercommander(void) return; } sc = game.state.kscmdr; - for_starbases(i) { + for (i = 1; i <= game.state.rembase; i++) { basetbl[i] = i; bdist[i] = distance(game.state.baseq[i], sc); } @@ -435,16 +435,16 @@ void supercommander(void) without too many Klingons, and not already under attack. */ ifindit = iwhichb = 0; - for_starbases(i2) { + for (i2 = 1; i2 <= game.state.rembase; i2++) { i = basetbl[i2]; /* bug in original had it not finding nearest*/ ibq = game.state.baseq[i]; if (same(ibq, game.quadrant) || same(ibq, game.battle) || game.state.galaxy[ibq.x][ibq.y].supernova || game.state.galaxy[ibq.x][ibq.y].klingons > MAXKLQUAD-1) continue; - /* if there is a commander, and no other base is appropriate, - we will take the one with the commander */ - for_commanders (j) { + // if there is a commander, and no other base is appropriate, + // we will take the one with the commander + for (j = 1; j <= game.state.remcom; j++) { if (same(ibq, game.state.kcmdr[j]) && ifindit!= 2) { ifindit = 2; iwhichb = i; @@ -510,35 +510,37 @@ void supercommander(void) if (game.state.rembase == 0) { unschedule(FSCMOVE); } - else for_starbases(i) { - ibq = game.state.baseq[i]; - if (same(ibq, game.state.kscmdr) && same(game.state.kscmdr, game.battle)) { - /* attack the base */ - if (avoid) - return; /* no, don't attack base! */ - game.iseenit = false; - game.isatb = 1; - schedule(FSCDBAS, 1.0 +2.0*Rand()); - if (is_scheduled(FCDBAS)) - postpone(FSCDBAS, scheduled(FCDBAS)-game.state.date); - if (damaged(DRADIO) && game.condition != docked) - return; /* no warning */ - game.iseenit = true; - pause_game(true); - proutn(_("Lt. Uhura- \"Captain, the starbase in ")); - proutn(cramlc(quadrant, game.state.kscmdr)); - skip(1); - prout(_(" reports that it is under attack from the Klingon Super-commander.")); - proutn(_(" It can survive until stardate %d.\""), - (int)scheduled(FSCDBAS)); - if (!game.resting) - return; - prout(_("Mr. Spock- \"Captain, shall we cancel the rest period?\"")); - if (ja() == false) + else { + for (i = 1; i <= game.state.rembase; i++) { + ibq = game.state.baseq[i]; + if (same(ibq, game.state.kscmdr) && same(game.state.kscmdr, game.battle)) { + /* attack the base */ + if (avoid) + return; /* no, don't attack base! */ + game.iseenit = false; + game.isatb = 1; + schedule(FSCDBAS, 1.0 +2.0*Rand()); + if (is_scheduled(FCDBAS)) + postpone(FSCDBAS, scheduled(FCDBAS)-game.state.date); + if (damaged(DRADIO) && game.condition != docked) + return; /* no warning */ + game.iseenit = true; + pause_game(true); + proutn(_("Lt. Uhura- \"Captain, the starbase in ")); + proutn(cramlc(quadrant, game.state.kscmdr)); + skip(1); + prout(_(" reports that it is under attack from the Klingon Super-commander.")); + proutn(_(" It can survive until stardate %d.\""), + (int)scheduled(FSCDBAS)); + if (!game.resting) + return; + prout(_("Mr. Spock- \"Captain, shall we cancel the rest period?\"")); + if (ja() == false) + return; + game.resting = false; + game.optime = 0.0; /* actually finished */ return; - game.resting = false; - game.optime = 0.0; /* actually finished */ - return; + } } } /* Check for intelligence report */ @@ -608,7 +610,7 @@ void movetholian(void) game.ks[game.nenhere] = game.tholian; /* check to see if all holes plugged */ - for_sectors(i) { + for (i = 1; i <= QUADSIZE; i++) { if (game.quad[1][i]!=IHWEB && game.quad[1][i]!=IHT) return; if (game.quad[QUADSIZE][i]!=IHWEB && game.quad[QUADSIZE][i]!=IHT) diff --git a/src/battle.c b/src/battle.c index a1e1377..8f45cfb 100644 --- a/src/battle.c +++ b/src/battle.c @@ -335,7 +335,7 @@ void torpedo(double course, double r, coord in, double *hit, int i, int n) case IHR: /* Hit a regular enemy */ case IHK: /* find the enemy */ - for_local_enemies(ll) + for (ll = 1; ll <= game.nenhere; ll++) if (same(w, game.ks[ll])) break; kp = fabs(game.kpower[ll]); @@ -380,7 +380,7 @@ void torpedo(double course, double r, coord in, double *hit, int i, int n) case IHB: /* Hit a base */ skip(1); prout(_("***STARBASE DESTROYED..")); - for_starbases(ll) { + for (ll = 1; ll <= game.state.rembase; ll++) { if (same(game.state.baseq[ll], game.quadrant)) { game.state.baseq[ll]=game.state.baseq[game.state.rembase]; break; @@ -501,7 +501,7 @@ void torpedo(double course, double r, coord in, double *hit, int i, int n) game.quad[w.x][w.y]=IHDOT; game.quad[jw.x][jw.y]=iquad; prout(_(" displaced by blast to %s "), cramlc(sector, jw)); - for_local_enemies(ll) + for (ll = 1; ll <= game.nenhere; ll++) game.kdist[ll] = game.kavgd[ll] = distance(game.sector,game.ks[ll]); sortklings(); return; @@ -597,7 +597,7 @@ void attack(bool torps_ok) if (game.skill <= SKILL_FAIR) where = sector; - for_local_enemies(loop) { + for (loop = 1; loop <= game.nenhere; loop++) { if (game.kpower[loop] < 0) continue; /* too weak to attack */ /* compute hit strength and diminish shield power */ @@ -722,7 +722,7 @@ void attack(bool torps_ok) } } /* After attack, reset average distance to enemies */ - for_local_enemies(loop) + for (loop = 1; loop <= game.nenhere; loop++) game.kavgd[loop] = game.kdist[loop]; sortklings(); return; @@ -758,7 +758,7 @@ void deadkl(coord w, feature type, coord mv) switch (type) { case IHC: game.comhere = false; - for_commanders (i) + for (i = 1; i <= game.state.remcom; i++) if (same(game.state.kcmdr[i], game.quadrant)) break; game.state.kcmdr[i] = game.state.kcmdr[game.state.remcom]; @@ -797,7 +797,7 @@ void deadkl(coord w, feature type, coord mv) /* Remove enemy ship from arrays describing local conditions */ if (is_scheduled(FCDBAS) && same(game.battle, game.quadrant) && type==IHC) unschedule(FCDBAS); - for_local_enemies(i) + for (i = 1; i <= game.nenhere; i++) if (same(game.ks[i], w)) break; game.nenhere--; @@ -1138,9 +1138,10 @@ void phasers(void) irec=0; do { chew(); - if (!kz) for_local_enemies(i) - irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))* - (1.01+0.05*Rand()) + 1.0; + if (!kz) + for (i = 1; i <= game.nenhere; i++) + irec += fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))* + (1.01+0.05*Rand()) + 1.0; kz=1; proutn(_("%d units required. "), irec); chew(); @@ -1175,7 +1176,7 @@ void phasers(void) if (game.nenhere) { extra = 0.0; powrem = rpow; - for_local_enemies(i) { + for (i = 1; i <= game.nenhere; i++) { hits[i] = 0.0; if (powrem <= 0) continue; diff --git a/src/events.c b/src/events.c index 7e5c411..aeefdb4 100644 --- a/src/events.c +++ b/src/events.c @@ -270,8 +270,8 @@ void events(void) break; } i = 0; - for_starbases(j) { - for_commanders(k) + for (j = 1; j <= game.state.rembase; j++) { + for (k = 1; k <= game.state.remcom; k++) if (same(game.state.baseq[j], game.state.kcmdr[k]) && !same(game.state.baseq[j], game.quadrant) && !same(game.state.baseq[j], game.state.kscmdr)) { @@ -320,7 +320,7 @@ void events(void) if (evcode==FCDBAS) { unschedule(FCDBAS); /* find the lucky pair */ - for_commanders(i) + for (i = 1; i <= game.state.remcom; i++) if (same(game.state.kcmdr[i], game.battle)) break; if (i > game.state.remcom || game.state.rembase == 0 || @@ -358,7 +358,7 @@ void events(void) } /* Remove Starbase from galaxy */ game.state.galaxy[game.battle.x][game.battle.y].starbase = false; - for_starbases(i) + for (i = 1; i <= game.state.rembase; i++) if (same(game.state.baseq[i], game.battle)) game.state.baseq[i] = game.state.baseq[game.state.rembase]; game.state.rembase--; @@ -700,7 +700,7 @@ void nova(coord nov) break; case IHB: /* Destroy base */ game.state.galaxy[game.quadrant.x][game.quadrant.y].starbase = false; - for_starbases(i) + for (i = 1; i <= game.state.rembase; i++) if (same(game.state.baseq[i], game.quadrant)) break; game.state.baseq[i] = game.state.baseq[game.state.rembase]; @@ -744,7 +744,7 @@ void nova(coord nov) case IHC: /* Damage/destroy big enemies */ case IHS: case IHR: - for_local_enemies(ll) + for (ll = 1; ll <= game.nenhere; ll++) if (same(game.ks[ll], scratch)) break; game.kpower[ll] -= 800.0; /* If firepower is lost, die */ @@ -825,16 +825,14 @@ void supernova(bool induced, coord *w) /* Scheduled supernova -- select star */ /* logic changed here so that we won't favor quadrants in top left of universe */ - for_quadrants(nq.x) { - for_quadrants(nq.y) { + for (nq.x = 1; nq.x <= GALSIZE; nq.x++) + for (nq.y = 1; nq.y <= GALSIZE; nq.y++) stars += game.state.galaxy[nq.x][nq.y].stars; - } - } if (stars == 0) return; /* nothing to supernova exists */ num = Rand()*stars + 1; - for_quadrants(nq.x) { - for_quadrants(nq.y) { + for (nq.x = 1; nq.x <= GALSIZE; nq.x++) { + for (nq.y = 1; nq.y <= GALSIZE; nq.y++) { num -= game.state.galaxy[nq.x][nq.y].stars; if (num <= 0) break; @@ -862,8 +860,8 @@ void supernova(bool induced, coord *w) coord ns; /* we are in the quadrant! */ num = Rand()* game.state.galaxy[nq.x][nq.y].stars + 1; - for_sectors(ns.x) { - for_sectors(ns.y) { + for (ns.x = 1; ns.x <= QUADSIZE; ns.x++) { + for (ns.y = 1; ns.y <= QUADSIZE; ns.y++) { if (game.quad[ns.x][ns.y]==IHSTAR) { num--; if (num==0) diff --git a/src/moving.c b/src/moving.c index a8eb87b..63a51c7 100644 --- a/src/moving.c +++ b/src/moving.c @@ -53,7 +53,7 @@ void imove(bool novapush) /* Don't do it if being pushed by Nova */ if (game.nenhere != 0 && !novapush) { newcnd(); - for_local_enemies(m) { + for (m = 1; m <= game.nenhere; m++) { finald = distance(w, game.ks[m]); game.kavgd[m] = 0.5 * (finald + game.kdist[m]); } @@ -195,7 +195,7 @@ no_quad_change: /* No quadrant change -- compute new avg enemy distances */ game.quad[game.sector.x][game.sector.y] = game.ship; if (game.nenhere) { - for_local_enemies(m) { + for (m = 1; m <= game.nenhere; m++) { finald = distance(w, game.ks[m]); game.kavgd[m] = 0.5 * (finald+game.kdist[m]); game.kdist[m] = finald; @@ -203,7 +203,8 @@ no_quad_change: sortklings(); if (!game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova) attack(false); - for_local_enemies(m) game.kavgd[m] = game.kdist[m]; + for (m = 1; m <= game.nenhere; m++) + game.kavgd[m] = game.kdist[m]; } newcnd(); drawmaps(0); @@ -989,7 +990,7 @@ void mayday(void) } else { ddist = FOREVER; - for_starbases(m) { + for (m = 1; m <= game.state.rembase; m++) { xdist = QUADSIZE * distance(game.state.baseq[m], game.quadrant); if (xdist < ddist) { ddist = xdist; @@ -1163,7 +1164,7 @@ void abandon(void) for (;;) { /* position next to base by trial and error */ game.quad[game.sector.x][game.sector.y] = IHDOT; - for_sectors(l) { + for (l = 1; l <= QUADSIZE; l++) { game.sector.x = 3.0*Rand() - 1.0 + game.base.x; game.sector.y = 3.0*Rand() - 1.0 + game.base.y; if (VALID_SECTOR(game.sector.x, game.sector.y) && diff --git a/src/planets.c b/src/planets.c index e9cfcc2..5f31e5d 100644 --- a/src/planets.c +++ b/src/planets.c @@ -499,8 +499,8 @@ void deathray(void) proutn(_("Spock- \"I believe the word is")); prouts(_(" *ASTONISHING*")); prout(_(" Mr. Sulu.")); - for_sectors(i) - for_sectors(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")); diff --git a/src/reports.c b/src/reports.c index fa9d2e4..3c67218 100644 --- a/src/reports.c +++ b/src/reports.c @@ -195,8 +195,8 @@ void rechart(void) { int i, j; game.lastchart = game.state.date; - for_quadrants(i) - for_quadrants(j) + for (i = 1; i <= GALSIZE; i++) + for (j = 1; j <= GALSIZE; j++) if (game.state.galaxy[i][j].charted) { game.state.chart[i][j].klingons = game.state.galaxy[i][j].klingons; game.state.chart[i][j].starbase = game.state.galaxy[i][j].starbase; @@ -223,9 +223,9 @@ void chart(void) prout(_("(Last surveillance update %d stardates ago)."), (int)(game.state.date-game.lastchart)); prout(" 1 2 3 4 5 6 7 8"); - for_quadrants(i) { + for (i = 1; i <= GALSIZE; i++) { proutn("%d |", i); - for_quadrants(j) { + for (j = 1; j <= GALSIZE; j++) { char buf[4]; if ((game.options & OPTION_SHOWME) && i == game.quadrant.x && j == game.quadrant.y) proutn("<"); @@ -412,7 +412,7 @@ void srscan(void) newcnd(); for (i = 1; i <= QUADSIZE; i++) { proutn("%2d ", i); - for_sectors(j) { + for (j = 1; j <= QUADSIZE; j++) { sectscan(goodScan, i, j); } skip(1); diff --git a/src/setup.c b/src/setup.c index 8365576..c8112e0 100644 --- a/src/setup.c +++ b/src/setup.c @@ -223,9 +223,9 @@ void setup(bool needprompt) game.landed = false; game.alive = true; game.docfac = 0.25; - for_quadrants(i) - for_quadrants(j) { - struct quadrant *quad = &game.state.galaxy[i][j]; + for (i = 1; i <= GALSIZE; i++) + for (j = 1; j <= GALSIZE; j++) { + struct quadrant *quad = &game.state.galaxy[i][j]; quad->charted = 0; quad->planet = NOPLANET; quad->romulans = 0; @@ -256,8 +256,8 @@ void setup(bool needprompt) game.lastchart = FOREVER; // Put stars in the galaxy game.instar = 0; - for_quadrants(i) - for_quadrants(j) { + for (i = 1; i <= GALSIZE; i++) + for (j = 1; j <= GALSIZE; j++) { int k = Rand()*9.0 + 1.0; game.instar += k; game.state.galaxy[i][j].stars = k; @@ -607,8 +607,8 @@ void newqad(bool shutup) game.ientesc = true; } // Clear quadrant - for_sectors(i) - for_sectors(j) + for (i = 1; i <= QUADSIZE; i++) + for (j = 1; j <= QUADSIZE; j++) game.quad[i][j] = IHDOT; q = &game.state.galaxy[game.quadrant.x][game.quadrant.y]; // cope with supernova @@ -627,7 +627,7 @@ void newqad(bool shutup) for (i = 1; i <= game.klhere; i++) w = newkling(i); // If we need a commander, promote a Klingon - for_commanders(i) + for (i = 1; i <= game.state.remcom; i++) if (same(game.state.kcmdr[i], game.quadrant)) break; diff --git a/src/sst.h b/src/sst.h index 5ea29e9..63a9679 100644 --- a/src/sst.h +++ b/src/sst.h @@ -36,11 +36,6 @@ */ #define VALID_QUADRANT(x, y) ((x)>=1 && (x)<=GALSIZE && (y)>=1 && (y)<=GALSIZE) #define VALID_SECTOR(x, y) ((x)>=1 && (x)<=QUADSIZE && (y)>=1 && (y)<=QUADSIZE) -#define for_quadrants(i) for (i = 1; i <= GALSIZE; i++) -#define for_sectors(i) for (i = 1; i <= QUADSIZE; i++) -#define for_commanders(i) for (i = 1; i <= game.state.remcom; i++) -#define for_local_enemies(i) for (i = 1; i <= game.nenhere; i++) -#define for_starbases(i) for (i = 1; i <= game.state.rembase; i++) typedef struct {int x; int y;} coord; -- 2.31.1