Abstract away the operations involving a sentinel value for coordinates.
[super-star-trek.git] / src / moving.c
index 534c13f1e9277c63d2f3d3fd840b0db399ce573a..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]);
@@ -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)
+       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;