X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=events.c;h=fc03bb0f48bbb3d0ff493d9c1f8794d19507a99e;hb=797f0f77ccdfd001fff39396ceae760478c2b920;hp=55cc81671184eb2911c2714099a9ec80b3f7f2a7;hpb=e536fe754b3a9be00dcaee8f6ec50ea2d8c7a184;p=super-star-trek.git diff --git a/events.c b/events.c index 55cc816..fc03bb0 100644 --- a/events.c +++ b/events.c @@ -177,8 +177,8 @@ void events(void) break; } i = 0; - for (j=1; j<=game.state.rembase; j++) { - for (k=1; k<=game.state.remcom; k++) + for_commanders (j) { + for_commanders(k) if (game.state.baseqx[j]==game.state.cx[k] && game.state.baseqy[j]==game.state.cy[k] && (game.state.baseqx[j]!=quadx || game.state.baseqy[j]!=quady) && (game.state.baseqx[j]!=game.state.isx || game.state.baseqy[j]!=game.state.isy)) { @@ -236,7 +236,7 @@ void events(void) if (line==FCDBAS) { game.future[FCDBAS] = 1e30; /* find the lucky pair */ - for (i = 1; i <= game.state.remcom; i++) + for_commanders(i) if (game.state.cx[i]==batx && game.state.cy[i]==baty) break; if (i > game.state.remcom || game.state.rembase == 0 || @@ -273,7 +273,7 @@ void events(void) } /* Remove Starbase from galaxy */ game.state.galaxy[batx][baty].starbase = FALSE; - for (i=1; i <= game.state.rembase; i++) + for_starbases(i) if (game.state.baseqx[i]==batx && game.state.baseqy[i]==baty) { game.state.baseqx[i]=game.state.baseqx[game.state.rembase]; game.state.baseqy[i]=game.state.baseqy[game.state.rembase]; @@ -304,7 +304,7 @@ void events(void) if (probecx != i || probecy != j) { probecx = i; probecy = j; - if (i < 1 || i > GALSIZE || j < 1 || j > GALSIZE || + if (!VALID_QUADRANT(i, j) || game.state.galaxy[probecx][probecy].supernova) { // Left galaxy or ran into supernova if (game.damage[DRADIO]==0.0 || condit == IHDOCKED) { @@ -312,7 +312,7 @@ void events(void) ipage = 1; skip(1); proutn("Lt. Uhura- \"The deep space probe "); - if (i < 1 ||i > GALSIZE || j < 1 || j > GALSIZE) + if (!VALID_QUADRANT(j, i)) proutn("has left the galaxy"); else proutn("is no longer transmitting"); @@ -441,7 +441,7 @@ void nova(int ix, int iy) if (j==2 && nn== 2) continue; ii = hits[mm][1]+nn-2; jj = hits[mm][2]+j-2; - if (ii < 1 || ii > QUADSIZE || jj < 1 || jj > QUADSIZE) continue; + if (!VALID_SECTOR(jj, ii)) continue; iquad = game.quad[ii][jj]; switch (iquad) { // case IHDOT: /* Empty space ends reaction @@ -481,7 +481,7 @@ void nova(int ix, int iy) break; case IHB: /* Destroy base */ game.state.galaxy[quadx][quady].starbase = FALSE; - for (i = 1; i <= game.state.rembase; i++) + for_starbases(i) if (game.state.baseqx[i]==quadx && game.state.baseqy[i]==quady) break; game.state.baseqx[i] = game.state.baseqx[game.state.rembase]; @@ -524,7 +524,7 @@ void nova(int ix, int iy) case IHC: /* Damage/destroy big enemies */ case IHS: case IHR: - for (ll = 1; ll <= nenhere; ll++) + for_local_enemies(ll) if (game.kx[ll]==ii && game.ky[ll]==jj) break; game.kpower[ll] -= 800.0; /* If firepower is lost, die */ if (game.kpower[ll] <= 0.0) { @@ -535,7 +535,7 @@ void nova(int ix, int iy) newcy = jj + jj - hits[mm][2]; crmena(1, iquad, 2, ii, jj); proutn(" damaged"); - if (newcx<1 || newcx>QUADSIZE || newcy<1 || newcy>QUADSIZE) { + if (!VALID_SECTOR(newcx, newcy)) { /* can't leave quadrant */ skip(1); break; @@ -610,15 +610,15 @@ void snova(int insx, int insy) /* Scheduled supernova -- select star */ /* logic changed here so that we won't favor quadrants in top left of universe */ - for (nqx = 1; nqx<=GALSIZE; nqx++) { - for (nqy = 1; nqy<=GALSIZE; nqy++) { + for_quadrants(nqx) { + for_quadrants(nqy) { stars += game.state.galaxy[nqx][nqy].stars; } } if (stars == 0) return; /* nothing to supernova exists */ num = Rand()*stars + 1; - for (nqx = 1; nqx<=GALSIZE; nqx++) { - for (nqy = 1; nqy<=GALSIZE; nqy++) { + for_quadrants(nqx) { + for_quadrants(nqy) { num -= game.state.galaxy[nqx][nqy].stars; if (num <= 0) break; } @@ -648,8 +648,8 @@ void snova(int insx, int insy) /* we are in the quadrant! */ incipient = 1; num = Rand()* game.state.galaxy[nqx][nqy].stars + 1; - for (nsx=1; nsx < QUADSIZE; nsx++) { - for (nsy=1; nsy < QUADSIZE; nsy++) { + for_sectors(nsx) { + for_sectors(nsy) { if (game.quad[nsx][nsy]==IHSTAR) { num--; if (num==0) break;