Another documentation update.
[super-star-trek.git] / moving.c
index f9b352bf9f0f723aaeea6c3aef121d09e41fcddb..7d3f6dfcbbb52eaca28e37ba13a596cc1fcdb447 100644 (file)
--- a/moving.c
+++ b/moving.c
@@ -43,12 +43,12 @@ void imove(void)
        for (l = 1; l <= n; l++) {
            ix = (x += deltax) + 0.5;
            iy = (y += deltay) + 0.5;
-           if (ix < 1 || ix > QUADSIZE || iy < 1 || iy > QUADSIZE) {
+           if (!VALID_SECTOR(ix, iy)) {
                /* Leaving quadrant -- allow final enemy attack */
                /* Don't do it if being pushed by Nova */
                if (nenhere != 0 && iattak != 2) {
                    newcnd();
-                   for (l = 1; l <= nenhere; l++) {
+                   for_local_enemies(l) {
                        finald = sqrt((ix-game.kx[l])*(double)(ix-game.kx[l]) +
                                      (iy-game.ky[l])*(double)(iy-game.ky[l]));
                        game.kavgd[l] = 0.5 * (finald+game.kdist[l]);
@@ -58,7 +58,7 @@ void imove(void)
                     * that attacks only happen if Klingons
                     * are present and your skill is good.
                     */
-                   if (skill > SKILL_GOOD && klhere > 0 && game.state.galaxy[quadx][quady] != SUPERNOVA_PLACE)
+                   if (skill > SKILL_GOOD && klhere > 0 && !game.state.galaxy[quadx][quady].supernova)
                        attack(0);
                    if (alldone) return;
                }
@@ -97,9 +97,10 @@ void imove(void)
                        finish(FNEG3);
                        return;
                    }
-                   prout("\n\rYOU HAVE ATTEMPTED TO CROSS THE NEGATIVE ENERGY BARRIER\n\r"
-                         "AT THE EDGE OF THE GALAXY.  THE THIRD TIME YOU TRY THIS,\n\r"
-                         "YOU WILL BE DESTROYED.\n\r");
+                   skip(1);
+                   prout("YOU HAVE ATTEMPTED TO CROSS THE NEGATIVE ENERGY BARRIER");
+                   prout("AT THE EDGE OF THE GALAXY.  THE THIRD TIME YOU TRY THIS,");
+                   prout("YOU WILL BE DESTROYED.");
                }
                /* Compute final position in new quadrant */
                if (trbeam) return; /* Don't bother if we are to be beamed */
@@ -107,7 +108,8 @@ void imove(void)
                quady = (iy+(QUADSIZE-1))/QUADSIZE;
                sectx = ix - QUADSIZE*(quadx-1);
                secty = iy - QUADSIZE*(quady-1);
-               prout("\n\rEntering %s.",
+               skip(1);
+               prout("Entering %s.",
                      cramlc(quadrant, quadx, quady));
                game.quad[sectx][secty] = ship;
                newqad(0);
@@ -193,20 +195,21 @@ no_quad_change:
     /* No quadrant change -- compute new avg enemy distances */
     game.quad[sectx][secty] = ship;
     if (nenhere) {
-       for (l = 1; l <= nenhere; l++) {
+       for_local_enemies(l) {
            finald = sqrt((ix-game.kx[l])*(double)(ix-game.kx[l]) +
                          (iy-game.ky[l])*(double)(iy-game.ky[l]));
            game.kavgd[l] = 0.5 * (finald+game.kdist[l]);
            game.kdist[l] = finald;
        }
        sortkl();
-       if (game.state.galaxy[quadx][quady] != SUPERNOVA_PLACE && iattak == 0)
+       if (!game.state.galaxy[quadx][quady].supernova && iattak == 0)
            attack(0);
-       for (l = 1 ; l <= nenhere; l++) game.kavgd[l] = game.kdist[l];
+       for_local_enemies(l) game.kavgd[l] = game.kdist[l];
     }
     newcnd();
     iattak = 0;
     drawmaps(0);
+    setwnd(message_window);
     return;
 }
 
@@ -233,8 +236,8 @@ void dock(int l)
     shield = inshld;
     torps = intorps;
     lsupres = inlsr;
-    if (stdamtim != 1e30 &&
-       (game.future[FCDBAS] < 1e30 || isatb == 1) && iseenit == 0) {
+    if (game.damage[DRADIO] == 0.0 &&
+       (game.future[FCDBAS] < FOREVER || isatb == 1) && iseenit == 0) {
        /* get attack report from base */
        prout("Lt. Uhura- \"Captain, an important message from the starbase:\"");
        attakreport(0);
@@ -264,7 +267,7 @@ static void getcd(int isprobe, int akey) {
        
        if (landed == 1 && !isprobe) {
                prout("Dummy! You can't leave standard orbit until you");
-               proutn("are back abourt the ");
+               proutn("are back aboard the ");
                crmshp();
                prout(".");
                chew();
@@ -372,11 +375,10 @@ static void getcd(int isprobe, int akey) {
                        }
                        itemp = 1;
                }
-               if (irowq<1 || irowq > GALSIZE || icolq<1 || icolq > GALSIZE ||
-                       irows<1 || irows > QUADSIZE || icols<1 || icols > QUADSIZE) {
-                               huh();
-                               return;
-                       }
+               if (!VALID_QUADRANT(icolq,irowq)||!VALID_SECTOR(icols,irows)) {
+                   huh();
+                   return;
+               }
                skip(1);
                if (!isprobe) {
                        if (itemp) {
@@ -589,10 +591,9 @@ void warp(int i)
            for (l = 1; l <= n; l++) {
                x += deltax;
                ix = x + 0.5;
-               if (ix < 1 || ix > QUADSIZE) break;
                y += deltay;
                iy = y +0.5;
-               if (iy < 1 || iy > QUADSIZE) break;
+               if (!VALID_SECTOR(ix, iy)) break;
                if (game.quad[ix][iy] != IHDOT) {
                    blooey = 0;
                    twarp = 0;
@@ -641,8 +642,8 @@ void setwrp(void)
        return;
     }
     if (game.damage[DWARPEN] > 0.0 && aaitem > 4.0) {
-       prout("Engineer Scott- \"I'm doing my best, Captain,\n"
-             "  but right now we can only go warp 4.\"");
+       prout("Engineer Scott- \"I'm doing my best, Captain,");
+       prout("  but right now we can only go warp 4.\"");
        return;
     }
     if (aaitem > 10.0) {
@@ -730,8 +731,8 @@ void atover(int igrab)
        crmshp();
        skip(1);
        prout("safely out of quadrant.");
-       game.starch[quadx][quady] = game.damage[DRADIO] > 0.0 ? game.state.galaxy[quadx][quady]+SUPERNOVA_PLACE:1;
-
+       if (game.damage[DRADIO] == 0.0)
+           game.state.galaxy[quadx][quady].charted = TRUE;
        /* Try to use warp engines */
        if (game.damage[DWARPEN]) {
            skip(1);
@@ -759,14 +760,16 @@ void atover(int igrab)
            finish(FSNOVAED);
            return;
        }
+    } while 
        /* Repeat if another snova */
-    } while (game.state.galaxy[quadx][quady] == SUPERNOVA_PLACE);
-    if (game.state.remkl==0) finish(FWON); /* Snova killed remaining enemy. */
+       (game.state.galaxy[quadx][quady].supernova);
+    if (KLINGREM==0) 
+       finish(FWON); /* Snova killed remaining enemy. */
 }
 
 void timwrp() 
 {
-    int l, ll, gotit;
+    int l, gotit;
     prout("***TIME WARP ENTERED.");
     if (game.state.snap && Rand() < 0.5) {
        /* Go back in time */
@@ -783,7 +786,7 @@ void timwrp()
                                                                                  be sooner */
        if (game.state.nscrem) game.future[FSCMOVE] = 0.2777;
        isatb = 0;
-       game.future[FCDBAS] = game.future[FSCDBAS] = 1e30;
+       game.future[FCDBAS] = game.future[FSCDBAS] = FOREVER;
        batx = baty = 0;
 
        /* Make sure Galileo is consistant -- Snapshot may have been taken
@@ -804,16 +807,11 @@ void timwrp()
            prout("Checkov-  \"Security reports the Galileo has reappeared in the dock!\"");
            iscraft = 1;
        }
-
-       /* Revert star chart to earlier era, if it was known then*/
-       if (game.damage[DRADIO]==0.0 || stdamtim > game.state.date) {
-           for (l = 1; l <= GALSIZE; l++)
-               for (ll = 1; ll <= GALSIZE; ll++)
-                   if (game.starch[l][ll] > 1)
-                       game.starch[l][ll]=game.damage[DRADIO]>0.0 ? game.state.galaxy[l][ll]+SUPERNOVA_PLACE :1;
-           prout("Spock has reconstructed a correct star chart from memory");
-           if (game.damage[DRADIO] > 0.0) stdamtim = game.state.date;
-       }
+       /* 
+        * There used to be code to do the actual reconstrction here,
+        * but the starchart is now part of the snapshotted galaxy state.
+        */
+       prout("Spock has reconstructed a correct star chart from memory");
     }
     else {
        /* Go forward in time */
@@ -847,7 +845,7 @@ void probe(void)
        prout("Engineer Scott- \"The probe launcher is damaged, Sir.\"");
        return;
     }
-    if (game.future[FDSPROB] != 1e30) {
+    if (game.future[FDSPROB] != FOREVER) {
        chew();
        skip(1);
        if (game.damage[DRADIO] != 0 && condit != IHDOCKED) {
@@ -933,8 +931,8 @@ void help(void)
        ddist = sqrt(square(basex-sectx)+square(basey-secty));
     }
     else {
-       ddist = 1e30;
-       for (l = 1; l <= game.state.rembase; l++) {
+       ddist = FOREVER;
+       for_starbases(l) {
            xdist=10.0*sqrt(square(game.state.baseqx[l]-quadx)+square(game.state.baseqy[l]-quady));
            if (xdist < ddist) {
                ddist = xdist;
@@ -956,11 +954,10 @@ 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<=QUADSIZE && iy>=1 && iy<=QUADSIZE && game.quad[ix][iy]==IHDOT) {
+       if (VALID_SECTOR(ix,iy) && game.quad[ix][iy]==IHDOT) {
            /* found one -- finish up */
            sectx=ix;
            secty=iy;
-           game.quad[ix][iy]=IHMATER0;
            break;
        }
     }
@@ -979,22 +976,26 @@ void help(void)
        }
        proutn(" attempt to re-materialize ");
        crmshp();
-       warble();
-       if (Rand() > probf) break;
        switch (l){
-       case 1: game.quad[ix][iy]=IHMATER1;
+       case 1: game.quad[ix][iy]=IHMATER0;
            break;
-       case 2: game.quad[ix][iy]=IHMATER2;
+       case 2: game.quad[ix][iy]=IHMATER1;
            break;
-       case 3: game.quad[ix][iy]=IHQUEST;
+       case 3: game.quad[ix][iy]=IHMATER2;
            break;
        }
        textcolor(RED);
+       warble();
+       if (Rand() > probf) break;
        prout("fails.");
        delay(500);
        textcolor(DEFAULT);
     }
     if (l > 3) {
+       game.quad[ix][iy]=IHQUEST;
+       alive = 0;
+       drawmaps(1);
+       setwnd(message_window);
        finish(FMATERIALIZE);
        return;
     }