From 359039abfddd65910747b48f5de6faedd496240e Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sun, 31 Oct 2004 20:26:15 +0000 Subject: [PATCH] The quad global gets pulled into the frozen structure. --- ai.c | 40 ++++++++++++++++++++-------------------- battle.c | 32 ++++++++++++++++---------------- events.c | 20 ++++++++++---------- finish.c | 2 +- moving.c | 16 ++++++++-------- planets.c | 4 ++-- reports.c | 2 +- setup.c | 40 +++++++++++++++++++--------------------- sst.h | 4 +--- 9 files changed, 78 insertions(+), 82 deletions(-) diff --git a/ai.c b/ai.c index e34eabc..6b173b5 100644 --- a/ai.c +++ b/ai.c @@ -187,7 +187,7 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) { if (my != 0) my = my*motion < 0 ? -1 : 1; nextx = comx; nexty = comy; - quad[comx][comy] = IHDOT; + frozen.quad[comx][comy] = IHDOT; /* main move loop */ for (ll = 1; ll <= nsteps; ll++) { #ifdef DEBUG @@ -218,9 +218,9 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) { looky = nexty + krawly; krawly = -krawly; } - else if (quad[lookx][looky] != IHDOT) { + else if (frozen.quad[lookx][looky] != IHDOT) { /* See if we should ram ship */ - if (quad[lookx][looky] == ship && + if (frozen.quad[lookx][looky] == ship && (ienm == IHC || ienm == IHS)) { ram(1, ienm, comx, comy); return; @@ -250,7 +250,7 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) { else break; /* done early */ } /* Put commander in place within same quadrant */ - quad[nextx][nexty] = ienm; + frozen.quad[nextx][nexty] = ienm; if (nextx != comx || nexty != comy) { /* it moved */ kx[loccom] = nextx; @@ -280,7 +280,7 @@ void movcom(void) { if (comhere) for (i = 1; i <= nenhere; i++) { ix = kx[i]; iy = ky[i]; - if (quad[ix][iy] == IHC) { + if (frozen.quad[ix][iy] == IHC) { movebaddy(ix, iy, i, IHC); break; } @@ -288,7 +288,7 @@ void movcom(void) { if (ishere) for (i = 1; i <= nenhere; i++) { ix = kx[i]; iy = ky[i]; - if (quad[ix][iy] == IHS) { + if (frozen.quad[ix][iy] == IHS) { movebaddy(ix, iy, i, IHS); break; } @@ -299,8 +299,8 @@ void movcom(void) { if (skill > 3) for (i = 1; i <= nenhere; i++) { ix = kx[i]; iy = ky[i]; - if (quad[ix][iy] == IHK || quad[ix][iy] == IHR) - movebaddy(ix, iy, i, quad[ix][iy]); + if (frozen.quad[ix][iy] == IHK || frozen.quad[ix][iy] == IHR) + movebaddy(ix, iy, i, frozen.quad[ix][iy]); } sortkl(); @@ -331,8 +331,8 @@ static int checkdest(int iqx, int iqy, int flag, int *ipage) { ientesc=0; future[FSCDBAS]=1e30; for (i = 1; i <= nenhere; i++) - if (quad[kx[i]][ky[i]] == IHS) break; - quad[kx[i]][ky[i]] = IHDOT; + if (frozen.quad[kx[i]][ky[i]] == IHS) break; + frozen.quad[kx[i]][ky[i]] = IHDOT; kx[i] = kx[nenhere]; ky[i] = ky[nenhere]; kdist[i] = kdist[nenhere]; @@ -572,15 +572,15 @@ void movetho(void) { } /* Do nothing if we are blocked */ - if (quad[idx][idy]!= IHDOT && quad[idx][idy]!= IHWEB) return; - quad[ithx][ithy] = IHWEB; + if (frozen.quad[idx][idy]!= IHDOT && frozen.quad[idx][idy]!= IHWEB) return; + frozen.quad[ithx][ithy] = IHWEB; if (ithx != idx) { /* move in x axis */ im = fabs((double)idx - ithx)/((double)idx - ithx); while (ithx != idx) { ithx += im; - if (quad[ithx][ithy]==IHDOT) quad[ithx][ithy] = IHWEB; + if (frozen.quad[ithx][ithy]==IHDOT) frozen.quad[ithx][ithy] = IHWEB; } } else if (ithy != idy) { @@ -588,20 +588,20 @@ void movetho(void) { im = fabs((double)idy - ithy)/((double)idy - ithy); while (ithy != idy) { ithy += im; - if (quad[ithx][ithy]==IHDOT) quad[ithx][ithy] = IHWEB; + if (frozen.quad[ithx][ithy]==IHDOT) frozen.quad[ithx][ithy] = IHWEB; } } - quad[ithx][ithy] = IHT; + frozen.quad[ithx][ithy] = IHT; /* check to see if all holes plugged */ for (i = 1; i < 11; i++) { - if (quad[1][i]!=IHWEB && quad[1][i]!=IHT) return; - if (quad[10][i]!=IHWEB && quad[10][i]!=IHT) return; - if (quad[i][1]!=IHWEB && quad[i][1]!=IHT) return; - if (quad[i][10]!=IHWEB && quad[i][10]!=IHT) return; + if (frozen.quad[1][i]!=IHWEB && frozen.quad[1][i]!=IHT) return; + if (frozen.quad[10][i]!=IHWEB && frozen.quad[10][i]!=IHT) return; + if (frozen.quad[i][1]!=IHWEB && frozen.quad[i][1]!=IHT) return; + if (frozen.quad[i][10]!=IHWEB && frozen.quad[i][10]!=IHT) return; } /* All plugged up -- Tholian splits */ - quad[ithx][ithy]=IHWEB; + frozen.quad[ithx][ithy]=IHWEB; dropin(IHBLANK, &dum, &my); crmena(1,IHT, 2, ithx, ithy); prout(" completes web."); diff --git a/battle.c b/battle.c index 184bc7c..2633a32 100644 --- a/battle.c +++ b/battle.c @@ -197,7 +197,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { proutn(" - "); cramf(y, 0, 1); proutn(" "); - iquad=quad[ix][iy]; + iquad=frozen.quad[ix][iy]; if (iquad==IHDOT) continue; /* hit something */ skip(1); @@ -223,11 +223,11 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { jx=ix+xx+0.5; jy=iy+yy+0.5; if (jx<1 || jx>10 || jy<1 ||jy > 10) return; - if (quad[jx][jy]==IHBLANK) { + if (frozen.quad[jx][jy]==IHBLANK) { finish(FHOLE); return; } - if (quad[jx][jy]!=IHDOT) { + if (frozen.quad[jx][jy]!=IHDOT) { /* can't move into object */ return; } @@ -274,12 +274,12 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { prout(" damaged but not destroyed."); return; } - if (quad[jx][jy]==IHBLANK) { + if (frozen.quad[jx][jy]==IHBLANK) { prout(" buffeted into black hole."); deadkl(ix, iy, iquad, jx, jy); return; } - if (quad[jx][jy]!=IHDOT) { + if (frozen.quad[jx][jy]!=IHDOT) { /* can't move into object */ prout(" damaged but not destroyed."); return; @@ -299,7 +299,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { break; } } - quad[ix][iy]=IHDOT; + frozen.quad[ix][iy]=IHDOT; state.rembase--; basex=basey=0; state.galaxy[quadx][quady] -= 10; @@ -314,7 +314,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { state.plnets[iplnet] = nulplanet; iplnet = 0; plnetx = plnety = 0; - quad[ix][iy] = IHDOT; + frozen.quad[ix][iy] = IHDOT; if (landed==1) { /* captain parishes on planet */ finish(FDPLANET); @@ -337,7 +337,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { proutn("Mr. Spock-"); prouts(" \"Facinating!\""); skip(1); - quad[ix][iy] = IHDOT; + frozen.quad[ix][iy] = IHDOT; return; case IHBLANK: /* Black hole */ skip(1); @@ -357,7 +357,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { h1 = fabs(h1); if (h1 >= 600) { prout(" destroyed."); - quad[ix][iy] = IHDOT; + frozen.quad[ix][iy] = IHDOT; ithere = 0; ithx = ithy = 0; return; @@ -367,7 +367,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { return; } prout(" disappears."); - quad[ix][iy] = IHWEB; + frozen.quad[ix][iy] = IHWEB; ithere = ithx = ithy = 0; { int dum, my; @@ -385,8 +385,8 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { break; } if (shoved) { - quad[jx][jy]=iquad; - quad[ix][iy]=IHDOT; + frozen.quad[jx][jy]=iquad; + frozen.quad[ix][iy]=IHDOT; proutn(" displaced by blast to"); cramlc(2, jx, jy); skip(1); @@ -469,7 +469,7 @@ void attack(int k) { if (kpower[l] < 500) r *= 0.25; jx = kx[l]; jy = ky[l]; - iquad = quad[jx][jy]; + iquad = frozen.quad[jx][jy]; itflag = (iquad == IHK && r > 0.0005) || k == 0 || (iquad==IHC && r > 0.015) || (iquad==IHR && r > 0.3) || @@ -632,7 +632,7 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy) { /* For each kind of enemy, finish message to player */ prout(" destroyestate."); - quad[ix][iy] = IHDOT; + frozen.quad[ix][iy] = IHDOT; if (state.remkl==0) return; state.remtime = state.remres/(state.remkl + 4*state.remcom); @@ -1059,7 +1059,7 @@ void phasers(void) { rpow = 0.0; for (k = 1; k <= nenhere;) { int ii = kx[k], jj = ky[k]; - int ienm = quad[ii][jj]; + int ienm = frozen.quad[ii][jj]; if (msgflag) { proutn("Energy available= "); cramf(energy-.006-(ifast?200:0), 0, 2); @@ -1190,7 +1190,7 @@ void hittem(double *hits) { } else proutn("Very small hit on "); - ienm = quad[ii][jj]; + ienm = frozen.quad[ii][jj]; crmena(0,ienm,2,ii,jj); skip(1); if (kpow == 0) { diff --git a/events.c b/events.c index 098c4a2..b94c05a 100644 --- a/events.c +++ b/events.c @@ -260,7 +260,7 @@ void events(void) { /* Handle case where base is in same quadrant as starship */ if (batx==quadx && baty==quady) { if (starch[batx][baty] > 999) starch[batx][baty] -= 10; - quad[basex][basey]= IHDOT; + frozen.quad[basex][basey]= IHDOT; basex=basey=0; newcnd(); skip(1); @@ -424,7 +424,7 @@ void nova(int ix, int iy) { } /* handle initial nova */ - quad[ix][iy] = IHDOT; + frozen.quad[ix][iy] = IHDOT; crmena(1, IHSTAR, 2, ix, iy); prout(" novas."); state.galaxy[quadx][quady] -= 1; @@ -444,7 +444,7 @@ void nova(int ix, int iy) { ii = hits[mm][1]+nn-2; jj = hits[mm][2]+j-2; if (ii < 1 || ii > 10 || jj < 1 || jj > 10) continue; - iquad = quad[ii][jj]; + iquad = frozen.quad[ii][jj]; switch (iquad) { // case IHDOT: /* Empty space ends reaction // case IHQUEST: @@ -466,7 +466,7 @@ void nova(int ix, int iy) { state.starkl++; crmena(1, IHSTAR, 2, ii, jj); prout(" novas."); - quad[ii][jj] = IHDOT; + frozen.quad[ii][jj] = IHDOT; break; case IHP: /* Destroy planet */ state.newstuf[quadx][quady] -= 1; @@ -479,7 +479,7 @@ void nova(int ix, int iy) { finish(FPNOVA); return; } - quad[ii][jj] = IHDOT; + frozen.quad[ii][jj] = IHDOT; break; case IHB: /* Destroy base */ state.galaxy[quadx][quady] -= 10; @@ -493,7 +493,7 @@ void nova(int ix, int iy) { newcnd(); crmena(1, IHB, 2, ii, jj); prout(" destroyed."); - quad[ii][jj] = IHDOT; + frozen.quad[ii][jj] = IHDOT; break; case IHE: /* Buffet ship */ case IHF: @@ -541,7 +541,7 @@ void nova(int ix, int iy) { skip(1); break; } - iquad1 = quad[newcx][newcy]; + iquad1 = frozen.quad[newcx][newcy]; if (iquad1 == IHBLANK) { proutn(", blasted into "); crmena(0, IHBLANK, 2, newcx, newcy); @@ -556,8 +556,8 @@ void nova(int ix, int iy) { } proutn(", buffeted to"); cramlc(2, newcx, newcy); - quad[ii][jj] = IHDOT; - quad[newcx][newcy] = iquad; + frozen.quad[ii][jj] = IHDOT; + frozen.quad[newcx][newcy] = iquad; kx[ll] = newcx; ky[ll] = newcy; kavgd[ll] = sqrt(square(sectx-newcx)+square(secty-newcy)); @@ -651,7 +651,7 @@ void snova(int insx, int insy) { num = Rand()* (state.galaxy[nqx][nqy]%10) + 1; for (nsx=1; nsx < 10; nsx++) { for (nsy=1; nsy < 10; nsy++) { - if (quad[nsx][nsy]==IHSTAR) { + if (frozen.quad[nsx][nsy]==IHSTAR) { num--; if (num==0) break; } diff --git a/finish.c b/finish.c index c9d6aa4..e396759 100644 --- a/finish.c +++ b/finish.c @@ -56,7 +56,7 @@ void kaboom(void) { int l=1; while (l <= nenhere) { if (kpower[l]*kdist[l] <= whammo) - deadkl(kx[l],ky[l], quad[kx[l]][ky[l]], kx[l], ky[l]); + deadkl(kx[l],ky[l], frozen.quad[kx[l]][ky[l]], kx[l], ky[l]); l++; } } diff --git a/moving.c b/moving.c index 9eb7096..24c9643 100644 --- a/moving.c +++ b/moving.c @@ -31,7 +31,7 @@ void move(void) { Time = future[FTBEAM] - state.date + 1e-5; } /* Move within the quadrant */ - quad[sectx][secty] = IHDOT; + frozen.quad[sectx][secty] = IHDOT; x = sectx; y = secty; n = 10.0*dist*bigger+0.5; @@ -101,11 +101,11 @@ void move(void) { proutn("\nEntering"); cramlc(1, quadx, quady); skip(1); - quad[sectx][secty] = ship; + frozen.quad[sectx][secty] = ship; newqad(0); return; } - iquad = quad[ix][iy]; + iquad = frozen.quad[ix][iy]; if (iquad != IHDOT) { /* object encountered in flight path */ stopegy = 50.0*dist/Time; @@ -170,7 +170,7 @@ void move(void) { finaly = secty; label100: /* No quadrant change -- compute new avg enemy distances */ - quad[sectx][secty] = ship; + frozen.quad[sectx][secty] = ship; if (nenhere) { for (l = 1; l <= nenhere; l++) { finald = sqrt((ix-kx[l])*(double)(ix-kx[l]) + @@ -567,7 +567,7 @@ void warp(int i) { y += deltay; iy = y +0.5; if (iy < 1 || iy > 10) break; - if (quad[ix][iy] != IHDOT) { + if (frozen.quad[ix][iy] != IHDOT) { blooey = 0; twarp = 0; } @@ -921,7 +921,7 @@ void help(void) { newqad(1); } /* dematerialize starship */ - quad[sectx][secty]=IHDOT; + frozen.quad[sectx][secty]=IHDOT; proutn("Starbase in"); cramlc(1, quadx, quady); proutn(" responds--"); @@ -949,12 +949,12 @@ void help(void) { for (l = 1; l <= 5; l++) { ix = basex+3.0*Rand()-1; iy = basey+3.0*Rand()-1; - if (ix>=1 && ix<=10 && iy>=1 && iy<=10 && quad[ix][iy]==IHDOT) { + if (ix>=1 && ix<=10 && iy>=1 && iy<=10 && frozen.quad[ix][iy]==IHDOT) { /* found one -- finish up */ prout("succeeds."); sectx=ix; secty=iy; - quad[ix][iy]=ship; + frozen.quad[ix][iy]=ship; dock(); skip(1); prout("Lt. Uhura- \"Captain, we made it!\""); diff --git a/planets.c b/planets.c index fefa8a4..133b0da 100644 --- a/planets.c +++ b/planets.c @@ -437,7 +437,7 @@ void deathray(void) { prouts("Sulu- \"Captain! It's working!\""); skip(2); while (nenhere > 0) - deadkl(kx[1],ky[1],quad[kx[1]][ky[1]],kx[1],ky[1]); + deadkl(kx[1],ky[1],frozen.quad[kx[1]][ky[1]],kx[1],ky[1]); prout("Ensign Chekov- \"Congratulations, Captain!\""); if (state.remkl == 0) finish(FWON); prout("Spock- \"Captain, I believe the `Experimental Death Ray'"); @@ -488,7 +488,7 @@ void deathray(void) { prout(" Mr. Sulu."); for (i=1; i<=10; i++) for (j=1; j<=10; j++) - if (quad[i][j] == IHDOT) quad[i][j] = IHQUEST; + if (frozen.quad[i][j] == IHDOT) frozen.quad[i][j] = IHQUEST; prout(" Captain, our quadrant is now infested with"); prouts(" - - - - - - *THINGS*."); skip(1); diff --git a/reports.c b/reports.c index afed60a..6ce31c4 100644 --- a/reports.c +++ b/reports.c @@ -270,7 +270,7 @@ void srscan(int l) { printf("%2d ", i); for (j = 1; j <= 10; j++) { if (goodScan || (abs(i-sectx)<= 1 && abs(j-secty) <= 1)) - printf("%c ",quad[i][j]); + printf("%c ",frozen.quad[i][j]); else printf("- "); } diff --git a/setup.c b/setup.c index 6484243..5c31748 100644 --- a/setup.c +++ b/setup.c @@ -38,7 +38,6 @@ void freeze(int boss) { } fwrite(&state, sizeof(state), 1, fp); fwrite(&snapsht, sizeof(snapsht), 1, fp); - fwrite(quad, sizeof(quad), 1, fp); fwrite(kx, sizeof(kx), 1, fp); fwrite(ky, sizeof(ky), 1, fp); fwrite(starch, sizeof(starch), 1, fp); @@ -82,7 +81,6 @@ void thaw(void) { } fread(&state, sizeof(state), 1, fp); fread(&snapsht, sizeof(snapsht), 1, fp); - fread(quad, sizeof(quad), 1, fp); fread(kx, sizeof(kx), 1, fp); fread(ky, sizeof(ky), 1, fp); fread(starch, sizeof(starch), 1, fp); @@ -161,13 +159,13 @@ void abandn(void) { } for (;;) { /* position next to base by trial and error */ - quad[sectx][secty] = IHDOT; + frozen.quad[sectx][secty] = IHDOT; for (l = 1; l <= 10; l++) { sectx = 3.0*Rand() - 1.0 + basex; secty = 3.0*Rand() - 1.0 + basey; if (sectx >= 1 && sectx <= 10 && secty >= 1 && secty <= 10 && - quad[sectx][secty] == IHDOT) break; + frozen.quad[sectx][secty] == IHDOT) break; } if (l < 11) break; /* found a spot */ sectx=5; @@ -176,7 +174,7 @@ void abandn(void) { } } /* Get new commission */ - quad[sectx][secty] = ship = IHF; + frozen.quad[sectx][secty] = ship = IHF; prout("Starfleet puts you in command of another ship,"); prout("the Faerie Queene, which is antiquated but,"); prout("still useable."); @@ -498,8 +496,8 @@ int choose(void) { void dropin(int iquad, int *ix, int *iy) { do iran10(ix, iy); - while (quad[*ix][*iy] != IHDOT); - quad[*ix][*iy] = iquad; + while (frozen.quad[*ix][*iy] != IHDOT); + frozen.quad[*ix][*iy] = iquad; } void newcnd(void) { @@ -538,7 +536,7 @@ void newqad(int shutup) { } // Clear quadrant for (i=1; i <= 10; i++) - for (j=1; j <= 10; j++) quad[i][j] = IHDOT; + for (j=1; j <= 10; j++) frozen.quad[i][j] = IHDOT; // cope with supernova if (quadnum > 999) { return; @@ -549,7 +547,7 @@ void newqad(int shutup) { nenhere = klhere + irhere; // Position Starship - quad[sectx][secty] = ship; + frozen.quad[sectx][secty] = ship; // Decide if quadrant needs a Tholian if ((skill < 3 && Rand() <= 0.02) || /* Lighten up if skill is low */ @@ -562,14 +560,14 @@ void newqad(int shutup) { do { ithx = Rand() > 0.5 ? 10 : 1; ithy = Rand() > 0.5 ? 10 : 1; - } while (quad[ithx][ithy] != IHDOT); - quad[ithx][ithy] = IHT; + } while (frozen.quad[ithx][ithy] != IHDOT); + frozen.quad[ithx][ithy] = IHT; ithere = 1; /* Reserve unocupied corners */ - if (quad[1][1]==IHDOT) quad[1][1] = 'X'; - if (quad[1][10]==IHDOT) quad[1][10] = 'X'; - if (quad[10][1]==IHDOT) quad[10][1] = 'X'; - if (quad[10][10]==IHDOT) quad[10][10] = 'X'; + if (frozen.quad[1][1]==IHDOT) frozen.quad[1][1] = 'X'; + if (frozen.quad[1][10]==IHDOT) frozen.quad[1][10] = 'X'; + if (frozen.quad[10][1]==IHDOT) frozen.quad[10][1] = 'X'; + if (frozen.quad[10][10]==IHDOT) frozen.quad[10][10] = 'X'; } if (quadnum >= 100) { @@ -587,14 +585,14 @@ void newqad(int shutup) { if (state.cx[i]==quadx && state.cy[i]==quady) break; if (i <= state.remcom) { - quad[ix][iy] = IHC; + frozen.quad[ix][iy] = IHC; kpower[klhere] = 950.0+400.0*Rand()+50.0*skill; comhere = 1; } // If we need a super-commander, promote a Klingon if (quadx == state.isx && quady == state.isy) { - quad[kx[1]][ky[1]] = IHS; + frozen.quad[kx[1]][ky[1]] = IHS; kpower[1] = 1175.0 + 400.0*Rand() + 125.0*skill; iscate = 1; ishere = 1; @@ -661,10 +659,10 @@ void newqad(int shutup) { // Take out X's in corners if Tholian present if (ithere) { - if (quad[1][1]=='X') quad[1][1] = IHDOT; - if (quad[1][10]=='X') quad[1][10] = IHDOT; - if (quad[10][1]=='X') quad[10][1] = IHDOT; - if (quad[10][10]=='X') quad[10][10] = IHDOT; + if (frozen.quad[1][1]=='X') frozen.quad[1][1] = IHDOT; + if (frozen.quad[1][10]=='X') frozen.quad[1][10] = IHDOT; + if (frozen.quad[10][1]=='X') frozen.quad[10][1] = IHDOT; + if (frozen.quad[10][10]=='X') frozen.quad[10][10] = IHDOT; } } diff --git a/sst.h b/sst.h index 78b8ca4..c6a1c87 100644 --- a/sst.h +++ b/sst.h @@ -49,15 +49,13 @@ EXTERN struct foo { remtime; // remaining time } state, snapsht; // Data that is snapshot -EXTERN char - quad[11][11]; // contents of our quadrant - // 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, // but I just didn't think of it back when I started. EXTERN struct foo2 { + char quad[11][11]; // contents of our quadrant int inkling, inbase, incom, -- 2.31.1