Web page now published. Add material to the history section of the docs.
[super-star-trek.git] / events.c
index 55cc81671184eb2911c2714099a9ec80b3f7f2a7..589a83821ad22a3489a01dc0fb10334be4a3dbca 100644 (file)
--- a/events.c
+++ b/events.c
@@ -18,7 +18,7 @@ void events(void)
        line = FSPY;
        if (alldone) return;
        datemin = fintim;
-       for (l=1; l<=NEVENTS; l++)
+       for (l = 1; l < NEVENTS; l++)
            if (game.future[l] < datemin) {
                line = l;
                datemin = game.future[l];
@@ -50,7 +50,6 @@ void events(void)
                game.damage[l] -= (game.damage[l]-repair > 0.0 ? repair : game.damage[l]);
        /* If radio repaired, update star chart and attack reports */
        if (radio_was_broken && game.damage[DRADIO] == 0.0) {
-           stdamtim = 1e30;
            prout("Lt. Uhura- \"Captain, the sub-space radio is working and");
            prout("   surveillance reports are coming in.");
            skip(1);
@@ -91,7 +90,7 @@ void events(void)
        case FTBEAM: /* Tractor beam */
            if (line==FTBEAM) {
                if (game.state.remcom == 0) {
-                   game.future[FTBEAM] = 1e30;
+                   game.future[FTBEAM] = FOREVER;
                    break;
                }
                i = Rand()*game.state.remcom+1.0;
@@ -162,7 +161,7 @@ void events(void)
            /* Adjust finish time to time of tractor beaming */
            fintim = game.state.date+Time;
            attack(0);
-           if (game.state.remcom <= 0) game.future[FTBEAM] = 1e30;
+           if (game.state.remcom <= 0) game.future[FTBEAM] = FOREVER;
            else game.future[FTBEAM] = game.state.date+Time+expran(1.5*intime/game.state.remcom);
            break;
        case FSNAP: /* Snapshot of the universe (for time warp) */
@@ -173,12 +172,12 @@ void events(void)
        case FBATTAK: /* Commander attacks starbase */
            if (game.state.remcom==0 || game.state.rembase==0) {
                /* no can do */
-               game.future[FBATTAK] = game.future[FCDBAS] = 1e30;
+               game.future[FBATTAK] = game.future[FCDBAS] = FOREVER;
                break;
            }
            i = 0;
-           for (j=1; j<=game.state.rembase; j++) {
-               for (k=1; k<=game.state.remcom; k++)
+           for_starbases(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)) {
@@ -190,7 +189,7 @@ void events(void)
            if (j>game.state.rembase) {
                /* no match found -- try later */
                game.future[FBATTAK] = game.state.date + expran(0.3*intime);
-               game.future[FCDBAS] = 1e30;
+               game.future[FCDBAS] = FOREVER;
                break;
            }
            /* commander + starbase combination found -- launch attack */
@@ -224,7 +223,7 @@ void events(void)
            }
            break;
        case FSCDBAS: /* Supercommander destroys base */
-           game.future[FSCDBAS] = 1e30;
+           game.future[FSCDBAS] = FOREVER;
            isatb = 2;
            if (!game.state.galaxy[game.state.isx][game.state.isy].starbase) 
                break; /* WAS RETURN! */
@@ -234,9 +233,9 @@ void events(void)
            baty = game.state.isy;
        case FCDBAS: /* Commander succeeds in destroying base */
            if (line==FCDBAS) {
-               game.future[FCDBAS] = 1e30;
+               game.future[FCDBAS] = FOREVER;
                /* 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 +272,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 +303,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,13 +311,13 @@ 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");
                        prout(".\"");
                    }
-                   game.future[FDSPROB] = 1e30;
+                   game.future[FDSPROB] = FOREVER;
                    break;
                }
                if (game.damage[DRADIO]==0.0   || condit == IHDOCKED) {
@@ -343,7 +342,7 @@ void events(void)
                game.state.galaxy[probecx][probecy].stars) {
                /* lets blow the sucker! */
                snova(1,0);
-               game.future[FDSPROB] = 1e30;
+               game.future[FDSPROB] = FOREVER;
                if (game.state.galaxy[quadx][quady].supernova) 
                    return;
            }
@@ -441,7 +440,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 +480,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 +523,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 +534,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 +609,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 +647,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;
@@ -686,9 +685,8 @@ void snova(int insx, int insy)
        /* did in the Supercommander! */
        game.state.nscrem = game.state.isx = game.state.isy = isatb = iscate = 0;
        iscdead = 1;
-       game.future[FSCMOVE] = game.future[FSCDBAS] = 1e30;
+       game.future[FSCMOVE] = game.future[FSCDBAS] = FOREVER;
     }
-    game.state.remkl -= kldead;
     if (game.state.remcom) {
        int maxloop = game.state.remcom, l;
        for (l = 1; l <= maxloop; l++) {
@@ -699,11 +697,12 @@ void snova(int insx, int insy)
                game.state.remcom--;
                kldead--;
                comdead++;
-               if (game.state.remcom==0) game.future[FTBEAM] = 1e30;
+               if (game.state.remcom==0) game.future[FTBEAM] = FOREVER;
                break;
            }
        }
     }
+    game.state.remkl -= kldead;
     /* destroy Romulans and planets in supernovaed quadrant */
     nrmdead = game.state.galaxy[nqx][nqy].romulans;
     game.state.galaxy[nqx][nqy].romulans = 0;
@@ -732,11 +731,7 @@ void snova(int insx, int insy)
     if (insx) {
        game.state.starkl += game.state.galaxy[nqx][nqy].stars;
        game.state.basekl += game.state.galaxy[nqx][nqy].starbase;
-       game.state.killk += kldead;
-       game.state.killc += comdead;
-       game.state.nromkl += nrmdead;
        game.state.nplankl += npdead;
-       game.state.nsckill += iscdead;
     }
     /* mark supernova in galaxy and in star chart */
     if ((quadx == nqx && quady == nqy) ||
@@ -744,7 +739,7 @@ void snova(int insx, int insy)
        condit == IHDOCKED)
        game.state.galaxy[nqx][nqy].supernova = TRUE;
     /* If supernova destroys last klingons give special message */
-    if (game.state.remkl==0 && (nqx != quadx || nqy != quady)) {
+    if (KLINGREM==0 && (nqx != quadx || nqy != quady)) {
        skip(2);
        if (insx == 0) prout("Lucky you!");
        proutn("A supernova in %s has just destroyed the last Klingons.",