moved redundant code to function
authorHolger Schemel <holger.schemel@virtion.de>
Thu, 12 Sep 2024 23:57:23 +0000 (01:57 +0200)
committerHolger Schemel <holger.schemel@virtion.de>
Fri, 13 Sep 2024 13:47:54 +0000 (15:47 +0200)
src/game_bd/bd_caveengine.c

index 5ebb0680341c719dcf153b8bf44e9c52f190f1a1..01145c4b668231c2848d44c9cb92ec3bdc3c950c 100644 (file)
@@ -1064,6 +1064,23 @@ static GdElement player_eat_element(GdCave *cave, const GdElement element, int x
       cave->conveyor_belts_direction_changed = !cave->conveyor_belts_direction_changed;
       return element;
 
+    case O_GRAVITY_SWITCH:
+      // only allow changing direction if the new dir is not diagonal
+      if (cave->gravity_switch_active &&
+          (dir == GD_MV_LEFT ||
+           dir == GD_MV_RIGHT ||
+           dir == GD_MV_UP ||
+           dir == GD_MV_DOWN))
+      {
+        gd_sound_play(cave, GD_S_SWITCH_GRAVITY, element, x, y);
+        // (use 1 instead of 0 for immediate gravitation change)
+        cave->gravity_will_change =
+          MAX(1, cave->gravity_change_time * cave->timing_factor);
+        cave->gravity_next_direction = dir;
+        cave->gravity_switch_active = FALSE;
+      }
+      return element;
+
     // USUAL STUFF
     case O_DIRT:
     case O_DIRT2:
@@ -2028,24 +2045,6 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire,
                  }
                  break;
 
-               case O_GRAVITY_SWITCH:
-                 // (we cannot use player_get for this as it does not have player_move parameter)
-                 // only allow changing direction if the new dir is not diagonal
-                 if (cave->gravity_switch_active &&
-                     (player_move == GD_MV_LEFT ||
-                      player_move == GD_MV_RIGHT ||
-                      player_move == GD_MV_UP ||
-                      player_move == GD_MV_DOWN))
-                 {
-                   gd_sound_play(cave, GD_S_SWITCH_GRAVITY, what, x, y);
-                    // (use 1 instead of 0 for immediate gravitation change)
-                   cave->gravity_will_change =
-                     MAX(1, cave->gravity_change_time * cave->timing_factor);
-                   cave->gravity_next_direction = player_move;
-                   cave->gravity_switch_active = FALSE;
-                 }
-                 break;
-
                default:
                  // get element - process others.
                  // if cannot get, player_eat_element will return the same
@@ -2134,25 +2133,6 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire,
            {
              switch (what)
              {
-               case O_GRAVITY_SWITCH:
-                 // (we cannot use player_get for this as it does not have
-                 // player_move parameter)
-                 // only allow changing direction if the new dir is not diagonal
-                 if (cave->gravity_switch_active &&
-                     (player_move == GD_MV_LEFT ||
-                      player_move == GD_MV_RIGHT ||
-                      player_move == GD_MV_UP ||
-                      player_move == GD_MV_DOWN))
-                 {
-                   gd_sound_play(cave, GD_S_SWITCH_GRAVITY, what, x, y);
-                    // (use 1 instead of 0 for immediate gravitation change)
-                   cave->gravity_will_change =
-                     MAX(1, cave->gravity_change_time * cave->timing_factor);
-                   cave->gravity_next_direction = player_move;
-                   cave->gravity_switch_active = FALSE;
-                 }
-                 break;
-
                default:
                  // get element. if cannot get, player_eat_element will return the same
                  remains = player_eat_element(cave, what, x, y, player_move);