fixed sound for charging level time (energy) for MM engine
[rocksndiamonds.git] / src / game_mm / mm_game.c
index 4de58b82685bec2e28bdef152f38f30c16f217e7..ed84121dd2d75d463aeb4f6535e4ffa47d7d5e41 100644 (file)
 /* values for 'click_delay_value' in ClickElement() */
 #define CLICK_DELAY_SHORT      125
 #define CLICK_DELAY_LONG       250
+
 #define AUTO_ROTATE_DELAY      CLICK_DELAY_SHORT
+#define INIT_GAME_ACTIONS_DELAY        ONE_SECOND_DELAY
+#define NUM_INIT_CYCLE_STEPS   16
 
 /* forward declaration for internal use */
 static int MovingOrBlocked2Element_MM(int, int);
@@ -215,41 +218,28 @@ static void InitField(int x, int y, boolean init_game)
   }
 }
 
-static void InitCycleElements()
+static void InitCycleElements_RotateSingleStep()
 {
-  int i, j;
+  int i;
 
   if (game_mm.num_cycle == 0)  /* no elements to cycle */
     return;
 
-  for (i = 0; i < 16; i++)
+  for (i = 0; i < game_mm.num_cycle; i++)
   {
-    for (j = 0; j < game_mm.num_cycle; j++)
-    {
-      int x = game_mm.cycle[j].x;
-      int y = game_mm.cycle[j].y;
-      int step = SIGN(game_mm.cycle[j].steps);
-      int last_element = Feld[x][y];
-      int next_element = get_rotated_element(last_element, step);
-
-      if (!game_mm.cycle[j].steps)
-       continue;
+    int x = game_mm.cycle[i].x;
+    int y = game_mm.cycle[i].y;
+    int step = SIGN(game_mm.cycle[i].steps);
+    int last_element = Feld[x][y];
+    int next_element = get_rotated_element(last_element, step);
 
-      Feld[x][y] = next_element;
-
-      DrawField_MM(x, y);
-      game_mm.cycle[j].steps -= step;
-    }
-
-    BackToFront();
-    ColorCycling();
-
-#ifdef DEBUG
-    if (setup.quick_doors)
+    if (!game_mm.cycle[i].steps)
       continue;
-#endif
 
-    Delay(AUTO_ROTATE_DELAY);
+    Feld[x][y] = next_element;
+
+    DrawField_MM(x, y);
+    game_mm.cycle[i].steps -= step;
   }
 }
 
@@ -292,15 +282,12 @@ void InitGameEngine_MM()
 {
   int i, x, y;
 
-  /* set global editor control values */
-  editor.draw_walls_masked = FALSE;
-
   /* set global game control values */
   game_mm.num_cycle = 0;
   game_mm.num_pacman = 0;
 
   game_mm.score = 0;
-  game_mm.energy_left = native_mm_level.time;
+  game_mm.energy_left = 0;     // later set to "native_mm_level.time"
   game_mm.kettles_still_needed =
     (native_mm_level.auto_count_kettles ? 0 : native_mm_level.kettles_needed);
   game_mm.lights_still_needed = 0;
@@ -310,6 +297,8 @@ void InitGameEngine_MM()
   game_mm.game_over = FALSE;
   game_mm.game_over_cause = 0;
 
+  game_mm.laser_overload_value = 0;
+
   /* set global laser control values (must be set before "InitLaser()") */
   laser.start_edge.x = 0;
   laser.start_edge.y = 0;
@@ -351,9 +340,12 @@ void InitGameEngine_MM()
   DrawLevel_MM();
 }
 
-void InitGameEngine_MM_AfterFadingIn()
+void InitGameActions_MM()
 {
-  InitCycleElements();
+  int num_init_game_frames = INIT_GAME_ACTIONS_DELAY / GAME_FRAME_DELAY;
+  int cycle_steps_done = 0;
+  int i;
+
   InitLaser();
 
 #if 0
@@ -386,24 +378,26 @@ void InitGameEngine_MM_AfterFadingIn()
   OpenDoor(DOOR_OPEN_ALL);
 #endif
 
-  if (setup.sound_loops)
-    PlaySoundExt(SND_FUEL, SOUND_MAX_VOLUME, SOUND_MAX_RIGHT, SND_CTRL_PLAY_LOOP);
-
-#if 0 // !!! TEMPORARILY DISABLED !!!
-  for (i = 0; i <= game_mm.energy_left; i += 2)
+  for (i = 0; i <= num_init_game_frames; i++)
   {
-    if (!setup.sound_loops)
-      PlaySoundStereo(SND_FUEL, SOUND_MAX_RIGHT);
+    if (i == num_init_game_frames)
+      StopSound_MM(SND_MM_GAME_LEVELTIME_CHARGING);
+    else if (setup.sound_loops)
+      PlaySoundLoop_MM(SND_MM_GAME_LEVELTIME_CHARGING);
+    else
+      PlaySound_MM(SND_MM_GAME_LEVELTIME_CHARGING);
 
-#if 0
-    BlitBitmap(pix[PIX_DOOR], drawto,
-              DOOR_GFX_PAGEX4 + XX_ENERGY,
-              DOOR_GFX_PAGEY1 + YY_ENERGY + ENERGY_YSIZE - i,
-              ENERGY_XSIZE, i,
-              DX_ENERGY, DY_ENERGY + ENERGY_YSIZE - i);
-#endif
+    game_mm.energy_left = native_mm_level.time * i / num_init_game_frames;
+
+    UpdateAndDisplayGameControlValues();
+
+    while (cycle_steps_done < NUM_INIT_CYCLE_STEPS * i / num_init_game_frames)
+    {
+      InitCycleElements_RotateSingleStep();
+
+      cycle_steps_done++;
+    }
 
-    redraw_mask |= REDRAW_DOOR_1;
     BackToFront();
 
     ColorCycling();
@@ -412,14 +406,8 @@ void InitGameEngine_MM_AfterFadingIn()
     if (setup.quick_doors)
       continue;
 #endif
-
-    Delay(20);
   }
 
-  if (setup.sound_loops)
-    StopSound(SND_FUEL);
-#endif
-
 #if 0
   if (setup.sound_music && num_bg_loops)
     PlayMusic(level_nr % num_bg_loops);
@@ -571,6 +559,10 @@ void ScanLaser()
   int element;
   int end = 0, rf = laser.num_edges;
 
+  /* do not scan laser again after the game was lost for whatever reason */
+  if (game_mm.game_over)
+    return;
+
   laser.overloaded = FALSE;
   laser.stops_inside_element = FALSE;
 
@@ -2436,13 +2428,16 @@ static void ContinueMoving_MM(int x, int y)
   laser.redraw = TRUE;
 }
 
-void ClickElement(int mx, int my, int button)
+void ClickElement(int x, int y, int button)
 {
   static unsigned int click_delay = 0;
   static int click_delay_value = CLICK_DELAY_SHORT;
   static boolean new_button = TRUE;
   int element;
-  int x = (mx - SX) / TILEX, y = (my - SY) / TILEY;
+
+  /* do not rotate objects hit by the laser after the game was solved */
+  if (game_mm.level_solved && Hit[x][y])
+    return;
 
   if (button == MB_RELEASED)
   {
@@ -2461,7 +2456,7 @@ void ClickElement(int mx, int my, int button)
   if (button == MB_MIDDLEBUTTON)       /* middle button has no function */
     return;
 
-  if (!IN_PIX_FIELD(mx - SX, my - SY))
+  if (!IN_LEV_FIELD(x, y))
     return;
 
   if (Feld[x][y] == EL_EMPTY)
@@ -2647,6 +2642,10 @@ void AutoRotateMirrors()
     {
       int element = Feld[x][y];
 
+      /* do not rotate objects hit by the laser after the game was solved */
+      if (game_mm.level_solved && Hit[x][y])
+       continue;
+
       if (IS_DF_MIRROR_AUTO(element) ||
          IS_GRID_WOOD_AUTO(element) ||
          IS_GRID_STEEL_AUTO(element) ||
@@ -2760,7 +2759,7 @@ void ColorCycling(void)
   }
 }
 
-static void GameActions_MM_Ext(byte action[MAX_PLAYERS], boolean warp_mode)
+static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode)
 {
   static unsigned int action_delay = 0;
   static unsigned int pacman_delay = 0;
@@ -2913,6 +2912,8 @@ static void GameActions_MM_Ext(byte action[MAX_PLAYERS], boolean warp_mode)
       laser.overload_value = 0;
     }
 
+    game_mm.laser_overload_value = laser.overload_value;
+
     if (laser.overload_value < MAX_LASER_OVERLOAD - 8)
     {
       int color_up = 0xFF * laser.overload_value / MAX_LASER_OVERLOAD;
@@ -3436,10 +3437,9 @@ static void GameActions_MM_Ext(byte action[MAX_PLAYERS], boolean warp_mode)
   return;
 }
 
-void GameActions_MM(byte action[MAX_PLAYERS], boolean warp_mode)
+void GameActions_MM(struct MouseActionInfo action, boolean warp_mode)
 {
-  if (!button_status)
-    ClickElement(0, 0, MB_NOT_PRESSED);
+  ClickElement(action.lx, action.ly, action.button);
 
   GameActions_MM_Ext(action, warp_mode);
 }