fixed overloading laser due to duplicated tiles in damage list in MM engine
[rocksndiamonds.git] / src / game_mm / mm_game.c
index 8583a9a7d7d056e43e13b3e2bcc80ffefe35af3a..641aa4fde5c8fdf0759e408bb686fdf80fddc4d6 100644 (file)
@@ -644,8 +644,6 @@ void InitGameEngine_MM(void)
   game_mm.laser_green = FALSE;
   game_mm.laser_blue = TRUE;
 
-  game_mm.lightball_rnd = TRUE;
-
   game_mm.level_solved = FALSE;
   game_mm.game_over = FALSE;
   game_mm.game_over_cause = 0;
@@ -716,8 +714,6 @@ void InitGameActions_MM(void)
 
   InitLaser();
 
-  game_mm.lightball_rnd = FALSE;
-
   for (i = 0; i <= num_init_game_frames; i++)
   {
     if (i == num_init_game_frames)
@@ -753,8 +749,6 @@ void InitGameActions_MM(void)
 #endif
   }
 
-  game_mm.lightball_rnd = TRUE;
-
   ScanLaser();
 
   if (game_mm.kettles_still_needed == 0)
@@ -763,7 +757,11 @@ void InitGameActions_MM(void)
   SetTileCursorXY(laser.start_edge.x, laser.start_edge.y);
   SetTileCursorActive(TRUE);
 
+  // restart all delay counters after initially cycling game elements
+  ResetFrameCounter(&rotate_delay);
+  ResetFrameCounter(&pacman_delay);
   ResetFrameCounter(&energy_delay);
+  ResetFrameCounter(&overload_delay);
 }
 
 static void FadeOutLaser(void)
@@ -827,6 +825,13 @@ void AddLaserEdge(int lx, int ly)
 
 void AddDamagedField(int ex, int ey)
 {
+  // prevent adding the same field position again
+  if (laser.num_damages > 0 &&
+      laser.damage[laser.num_damages - 1].x == ex &&
+      laser.damage[laser.num_damages - 1].y == ey &&
+      laser.damage[laser.num_damages - 1].edge == laser.num_edges)
+    return;
+
   laser.damage[laser.num_damages].is_mirror = FALSE;
   laser.damage[laser.num_damages].angle = laser.current_angle;
   laser.damage[laser.num_damages].edge = laser.num_edges;
@@ -3060,8 +3065,6 @@ void RotateMirror(int x, int y, int button)
         IS_POLAR(Tile[x][y]) ||
         IS_POLAR_CROSS(Tile[x][y])) && x == ELX && y == ELY)
     {
-      check = 0;
-
       if (IS_BEAMER(Tile[x][y]))
       {
 #if 0
@@ -3069,12 +3072,13 @@ void RotateMirror(int x, int y, int button)
              LX, LY, laser.beamer_edge, laser.beamer[1].num);
 #endif
 
-#if 0
-       laser.num_edges--;
-#endif
+       if (check == 1)
+         laser.num_edges--;
       }
 
       ScanLaser();
+
+      check = 0;
     }
 
     if (check == 2)