Abstract away the operations involving a sentinel value for coordinates.
[super-star-trek.git] / src / moving.c
index 80d6660dc5dae5cb4cb0350c5ea395c635f146e6..3373b37b0738d29c4f65c4800fa99afcf41a736f 100644 (file)
@@ -4,8 +4,8 @@
 
 static void getcd(bool, int);
 
-void imove(void)
-/* movement execution for warp, impule, supernova, and tractor-beam events */
+void imove(bool novapush)
+/* movement execution for warp, impulse, supernova, and tractor-beam events */
 {
     double angle, deltax, deltay, bigger, x, y,
         finald, stopegy, probf;
@@ -51,7 +51,7 @@ void imove(void)
            if (!VALID_SECTOR(w.x, w.y)) {
                /* Leaving quadrant -- allow final enemy attack */
                /* Don't do it if being pushed by Nova */
-               if (game.nenhere != 0 && game.iattak != 2) {
+               if (game.nenhere != 0 && !novapush) {
                    newcnd();
                    for_local_enemies(m) {
                        finald = distance(w, game.ks[m]);
@@ -63,7 +63,7 @@ void imove(void)
                     * are present and your skill is good.
                     */
                    if (game.skill > SKILL_GOOD && game.klhere > 0 && !game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova)
-                       attack(0);
+                       attack(false);
                    if (game.alldone) return;
                }
                /* compute final position -- new quadrant and sector */
@@ -116,7 +116,7 @@ void imove(void)
                prout(_("Entering %s."), cramlc(quadrant, game.quadrant));
                game.quad[game.sector.x][game.sector.y] = game.ship;
                newqad(false);
-               if (game.skill>SKILL_NOVICE) attack(0);
+               if (game.skill>SKILL_NOVICE) attack(false);
                return;
            }
            iquad = game.quad[w.x][w.y];
@@ -197,12 +197,11 @@ no_quad_change:
            game.kdist[m] = finald;
        }
        sortkl();
-       if (!game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova && game.iattak == 0)
-           attack(0);
+       if (!game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova)
+           attack(false);
        for_local_enemies(m) game.kavgd[m] = game.kdist[m];
     }
     newcnd();
-    game.iattak = 0;
     drawmaps(0);
     setwnd(message_window);
     return;
@@ -220,7 +219,7 @@ void dock(bool verbose)
        prout(_("You must first leave standard orbit."));
        return;
     }
-    if (game.base.x==0 || abs(game.sector.x-game.base.x) > 1 || abs(game.sector.y-game.base.y) > 1) {
+    if (!is_valid(game.base) || abs(game.sector.x-game.base.x) > 1 || abs(game.sector.y-game.base.y) > 1) {
        crmshp();
        prout(_(" not adjacent to base."));
        return;
@@ -477,7 +476,7 @@ void impuls(void)
        if (ja() == false) return;
     }
     /* Activate impulse engines and pay the cost */
-    imove();
+    imove(false);
     game.ididit = true;
     if (game.alldone) return;
     power = 20.0 + 100.0*game.dist;
@@ -605,7 +604,7 @@ void warp(bool timewarp)
                                
 
     /* Activate Warp Engines and pay the cost */
-    imove();
+    imove(false);
     if (game.alldone) return;
     game.energy -= game.dist*game.warpfac*game.warpfac*game.warpfac*(game.shldup+1);
     if (game.energy <= 0) finish(FNRG);
@@ -794,7 +793,7 @@ void timwrp()
        game.isatb = 0;
        unschedule(FCDBAS);
        unschedule(FSCDBAS);
-       game.battle.x = game.battle.y = 0;
+       invalidate(game.battle);
 
        /* Make sure Galileo is consistant -- Snapshot may have been taken
           when on planet, which would give us two Galileos! */
@@ -988,7 +987,7 @@ void mayday(void)
            break;
        }
     }
-    if (game.sector.x==0){
+    if (!is_valid(game.sector)){
        prout(_("You have been lost in space..."));
        finish(FMATERIALIZE);
        return;