added showing optional title screen for native BD cavesets
[rocksndiamonds.git] / src / game.c
index 137028077fea13ad46a5b646a0f6f068bc9bc286..9127a1b6a5be48bc22c593b6ff728b8a02269192 100644 (file)
@@ -89,7 +89,7 @@
 // game panel display and control definitions
 #define GAME_PANEL_LEVEL_NUMBER                        0
 #define GAME_PANEL_GEMS                                1
-#define GAME_PANEL_GEMS_TOTAL                  2
+#define GAME_PANEL_GEMS_NEEDED                 2
 #define GAME_PANEL_GEMS_COLLECTED              3
 #define GAME_PANEL_GEMS_SCORE                  4
 #define GAME_PANEL_INVENTORY_COUNT             5
@@ -246,8 +246,8 @@ static struct GamePanelControlInfo game_panel_controls[] =
     TYPE_INTEGER,
   },
   {
-    GAME_PANEL_GEMS_TOTAL,
-    &game.panel.gems_total,
+    GAME_PANEL_GEMS_NEEDED,
+    &game.panel.gems_needed,
     TYPE_INTEGER,
   },
   {
@@ -1835,6 +1835,29 @@ static void InitPlayerField(int x, int y, int element, boolean init_game)
   }
 }
 
+static void InitFieldForEngine_RND(int x, int y)
+{
+  int element = Tile[x][y];
+
+  // convert BD engine elements to corresponding R'n'D engine elements
+  element = (element == EL_BD_EMPTY            ? EL_EMPTY :
+            element == EL_BD_PLAYER            ? EL_PLAYER_1 :
+            element == EL_BD_INBOX             ? EL_PLAYER_1 :
+            element == EL_BD_SAND              ? EL_SAND :
+            element == EL_BD_STEELWALL         ? EL_STEELWALL :
+            element == EL_BD_EXIT_CLOSED       ? EL_EXIT_CLOSED :
+            element == EL_BD_EXIT_OPEN         ? EL_EXIT_OPEN :
+            element);
+
+  Tile[x][y] = element;
+}
+
+static void InitFieldForEngine(int x, int y)
+{
+  if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
+    InitFieldForEngine_RND(x, y);
+}
+
 static void InitField(int x, int y, boolean init_game)
 {
   int element = Tile[x][y];
@@ -2262,6 +2285,8 @@ static void UpdateGameControlValues(void)
   int i, k;
   int time = (game.LevelSolved ?
              game.LevelSolved_CountingTime :
+             level.game_engine_type == GAME_ENGINE_TYPE_BD ?
+             game_bd.time_played :
              level.game_engine_type == GAME_ENGINE_TYPE_EM ?
              game_em.lev->time :
              level.game_engine_type == GAME_ENGINE_TYPE_SP ?
@@ -2271,6 +2296,8 @@ static void UpdateGameControlValues(void)
              game.no_level_time_limit ? TimePlayed : TimeLeft);
   int score = (game.LevelSolved ?
               game.LevelSolved_CountingScore :
+              level.game_engine_type == GAME_ENGINE_TYPE_BD ?
+              game_bd.score :
               level.game_engine_type == GAME_ENGINE_TYPE_EM ?
               game_em.lev->score :
               level.game_engine_type == GAME_ENGINE_TYPE_SP ?
@@ -2278,17 +2305,25 @@ static void UpdateGameControlValues(void)
               level.game_engine_type == GAME_ENGINE_TYPE_MM ?
               game_mm.score :
               game.score);
-  int gems = (level.game_engine_type == GAME_ENGINE_TYPE_EM ?
+  int gems = (level.game_engine_type == GAME_ENGINE_TYPE_BD ?
+             game_bd.gems_still_needed :
+             level.game_engine_type == GAME_ENGINE_TYPE_EM ?
              game_em.lev->gems_needed :
              level.game_engine_type == GAME_ENGINE_TYPE_SP ?
              game_sp.infotrons_still_needed :
              level.game_engine_type == GAME_ENGINE_TYPE_MM ?
              game_mm.kettles_still_needed :
              game.gems_still_needed);
-  int gems_total = level.gems_needed;
-  int gems_collected = gems_total - gems;
-  int gems_score = level.score[SC_EMERALD];
-  int exit_closed = (level.game_engine_type == GAME_ENGINE_TYPE_EM ?
+  int gems_needed = level.gems_needed;
+  int gems_collected = (level.game_engine_type == GAME_ENGINE_TYPE_BD ?
+                       game_bd.game->cave->diamonds_collected :
+                       gems_needed - gems);
+  int gems_score = (level.game_engine_type == GAME_ENGINE_TYPE_BD ?
+                   game_bd.game->cave->diamond_value :
+                   level.score[SC_EMERALD]);
+  int exit_closed = (level.game_engine_type == GAME_ENGINE_TYPE_BD ?
+                    game_bd.gems_still_needed > 0 :
+                    level.game_engine_type == GAME_ENGINE_TYPE_EM ?
                     game_em.lev->gems_needed > 0 :
                     level.game_engine_type == GAME_ENGINE_TYPE_SP ?
                     game_sp.infotrons_still_needed > 0 :
@@ -2313,7 +2348,7 @@ static void UpdateGameControlValues(void)
   // used instead of "level_nr" (for network games)
   game_panel_controls[GAME_PANEL_LEVEL_NUMBER].value = levelset.level_nr;
   game_panel_controls[GAME_PANEL_GEMS].value = gems;
-  game_panel_controls[GAME_PANEL_GEMS_TOTAL].value = gems_total;
+  game_panel_controls[GAME_PANEL_GEMS_NEEDED].value = gems_needed;
   game_panel_controls[GAME_PANEL_GEMS_COLLECTED].value = gems_collected;
   game_panel_controls[GAME_PANEL_GEMS_SCORE].value = gems_score;
 
@@ -2710,7 +2745,7 @@ static void DisplayGameControlValues(void)
     if (PANEL_DEACTIVATED(pos))
       continue;
 
-    if (pos->class == get_hash_from_key("extra_panel_items") &&
+    if (pos->class == get_hash_from_string("extra_panel_items") &&
        !setup.prefer_extra_panel_items)
       continue;
 
@@ -2802,7 +2837,7 @@ static void DisplayGameControlValues(void)
       int width, height;
       int dst_x = PANEL_XPOS(pos);
       int dst_y = PANEL_YPOS(pos);
-      boolean skip = (pos->class == get_hash_from_key("mm_engine_only") &&
+      boolean skip = (pos->class == get_hash_from_string("mm_engine_only") &&
                      level.game_engine_type != GAME_ENGINE_TYPE_MM);
 
       if (graphic != IMG_UNDEFINED && !skip)
@@ -3995,6 +4030,8 @@ void InitGame(void)
 
   SCAN_PLAYFIELD(x, y)
   {
+    InitFieldForEngine(x, y);
+
     if (emulate_bd && !IS_BD_ELEMENT(Tile[x][y]))
       emulate_bd = FALSE;
     if (emulate_sp && !IS_SP_ELEMENT(Tile[x][y]))
@@ -4491,7 +4528,11 @@ void InitGame(void)
     scroll_y = game.forced_scroll_y;
 
   // !!! FIX THIS (START) !!!
-  if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
+  if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
+  {
+    InitGameEngine_BD();
+  }
+  else if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
   {
     InitGameEngine_EM();
   }
@@ -4865,6 +4906,31 @@ static void LevelSolved(void)
   LevelSolved_SetFinalGameValues();
 }
 
+static boolean AdvanceToNextLevel(void)
+{
+  if (setup.increment_levels &&
+      level_nr < leveldir_current->last_level &&
+      !network_playing)
+  {
+    level_nr++;                // advance to next level
+    TapeErase();       // start with empty tape
+
+    if (setup.auto_play_next_level)
+    {
+      scores.continue_playing = TRUE;
+      scores.next_level_nr = level_nr;
+
+      LoadLevel(level_nr);
+
+      SaveLevelSetup_SeriesInfo();
+    }
+
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
 void GameWon(void)
 {
   static int time_count_steps;
@@ -4956,7 +5022,8 @@ void GameWon(void)
     }
 
     // if not counting score after game, immediately update game panel values
-    if (level_editor_test_game || !setup.count_score_after_game)
+    if (level_editor_test_game || !setup.count_score_after_game ||
+       level.game_engine_type == GAME_ENGINE_TYPE_BD)
     {
       time = time_final;
       score = score_final;
@@ -5095,7 +5162,11 @@ void GameEnd(void)
   int last_level_nr = levelset.level_nr;
   boolean tape_saved = FALSE;
 
-  game.LevelSolved_GameEnd = TRUE;
+  // Important note: This function is not only called after "GameWon()", but also after
+  // "game over" (if automatically asking for restarting the game is disabled in setup)
+
+  if (game.LevelSolved)
+    game.LevelSolved_GameEnd = TRUE;
 
   if (game.LevelSolved_SaveTape && !score_info_tape_play)
   {
@@ -5122,7 +5193,7 @@ void GameEnd(void)
     return;
   }
 
-  if (!game.LevelSolved_SaveScore)
+  if (!game.GamePlayed || (!game.LevelSolved_SaveScore && !level.bd_intermission))
   {
     SetGameStatus(GAME_MODE_MAIN);
 
@@ -5139,27 +5210,13 @@ void GameEnd(void)
   }
 
   // save score and score tape before potentially erasing tape below
-  NewHighScore(last_level_nr, tape_saved);
-
-  if (setup.increment_levels &&
-      level_nr < leveldir_current->last_level &&
-      !network_playing)
-  {
-    level_nr++;                // advance to next level
-    TapeErase();       // start with empty tape
-
-    if (setup.auto_play_next_level)
-    {
-      scores.continue_playing = TRUE;
-      scores.next_level_nr = level_nr;
+  if (game.LevelSolved_SaveScore)
+    NewHighScore(last_level_nr, tape_saved);
 
-      LoadLevel(level_nr);
+  // increment and load next level (if possible and not configured otherwise)
+  AdvanceToNextLevel();
 
-      SaveLevelSetup_SeriesInfo();
-    }
-  }
-
-  if (scores.last_added >= 0 && setup.show_scores_after_game)
+  if (game.LevelSolved_SaveScore && scores.last_added >= 0 && setup.show_scores_after_game)
   {
     SetGameStatus(GAME_MODE_SCORES);
 
@@ -11692,6 +11749,10 @@ static void CheckLevelSolved(void)
 
 static void PlayTimeoutSound(int seconds_left)
 {
+  // will be played directly by BD engine (for classic bonus time sounds)
+  if (level.game_engine_type == GAME_ENGINE_TYPE_BD && checkBonusTime_BD())
+    return;
+
   // try to use individual "running out of time" sound for each second left
   int sound = SND_GAME_RUNNING_OUT_OF_TIME_0 - seconds_left;
 
@@ -11738,9 +11799,24 @@ static void CheckLevelTime_StepCounter(void)
 
 static void CheckLevelTime(void)
 {
+  int frames_per_second = FRAMES_PER_SECOND;
   int i;
 
-  if (TimeFrames >= FRAMES_PER_SECOND)
+  if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
+  {
+    // level time may be running slower in native BD engine
+    frames_per_second = getFramesPerSecond_BD();
+
+    // if native engine time changed, force main engine time change
+    if (getTimeLeft_BD() < TimeLeft)
+      TimeFrames = frames_per_second;
+
+    // if last second running, wait for native engine time to exactly reach zero
+    if (getTimeLeft_BD() == 1 && TimeLeft == 1)
+      TimeFrames = frames_per_second - 1;
+  }
+
+  if (TimeFrames >= frames_per_second)
   {
     TimeFrames = 0;
 
@@ -11775,11 +11851,20 @@ static void CheckLevelTime(void)
 
        if (!TimeLeft && game.time_limit)
        {
-         if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
+         if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
+         {
+           if (game_bd.game->cave->player_state == GD_PL_LIVING)
+             game_bd.game->cave->player_state = GD_PL_TIMEOUT;
+         }
+         else if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
+         {
            game_em.lev->killed_out_of_time = TRUE;
+         }
          else
+         {
            for (i = 0; i < MAX_PLAYERS; i++)
              KillPlayer(&stored_player[i]);
+         }
        }
       }
       else if (game.no_level_time_limit && !game.all_players_gone)
@@ -11810,10 +11895,20 @@ void AdvanceFrameAndPlayerCounters(int player_nr)
 {
   int i;
 
+  // handle game and tape time differently for native BD game engine
+
+  // tape time is running in native BD engine even if player is not hatched yet
+  if (!checkGameRunning())
+    return;
+
   // advance frame counters (global frame counter and tape time frame counter)
   FrameCounter++;
   TapeTimeFrames++;
 
+  // level time is running in native BD engine after player is being hatched
+  if (!checkGamePlaying())
+    return;
+
   // advance time frame counter (used to control available time to solve level)
   TimeFrames++;
 
@@ -12164,7 +12259,11 @@ static void GameActionsExt(void)
     game.snapshot.last_action[i] = stored_player[i].effective_action;
   }
 
-  if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
+  if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
+  {
+    GameActions_BD_Main();
+  }
+  else if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
   {
     GameActions_EM_Main();
   }
@@ -12231,6 +12330,17 @@ void GameActions(void)
   GameActions_CheckSaveEngineSnapshot();
 }
 
+void GameActions_BD_Main(void)
+{
+  byte effective_action[MAX_PLAYERS];
+  int i;
+
+  for (i = 0; i < MAX_PLAYERS; i++)
+    effective_action[i] = stored_player[i].effective_action;
+
+  GameActions_BD(effective_action);
+}
+
 void GameActions_EM_Main(void)
 {
   byte effective_action[MAX_PLAYERS];
@@ -15467,56 +15577,81 @@ static int getSoundAction_BD(int sample)
 {
   switch (sample)
   {
-    case GD_S_STONE:
-    case GD_S_NUT:
-    case GD_S_DIRT_BALL:
-    case GD_S_NITRO:
-    case GD_S_FALLING_WALL:
+    case GD_S_STONE_PUSHING:
+    case GD_S_MEGA_STONE_PUSHING:
+    case GD_S_FLYING_STONE_PUSHING:
+    case GD_S_WAITING_STONE_PUSHING:
+    case GD_S_CHASING_STONE_PUSHING:
+    case GD_S_NUT_PUSHING:
+    case GD_S_NITRO_PACK_PUSHING:
+    case GD_S_BLADDER_PUSHING:
+    case GD_S_BOX_PUSHING:
+      return ACTION_PUSHING;
+
+    case GD_S_STONE_FALLING:
+    case GD_S_MEGA_STONE_FALLING:
+    case GD_S_FLYING_STONE_FALLING:
+    case GD_S_NUT_FALLING:
+    case GD_S_DIRT_BALL_FALLING:
+    case GD_S_DIRT_LOOSE_FALLING:
+    case GD_S_NITRO_PACK_FALLING:
+    case GD_S_FALLING_WALL_FALLING:
+      return ACTION_FALLING;
+
+    case GD_S_STONE_IMPACT:
+    case GD_S_MEGA_STONE_IMPACT:
+    case GD_S_FLYING_STONE_IMPACT:
+    case GD_S_NUT_IMPACT:
+    case GD_S_DIRT_BALL_IMPACT:
+    case GD_S_DIRT_LOOSE_IMPACT:
+    case GD_S_NITRO_PACK_IMPACT:
+    case GD_S_FALLING_WALL_IMPACT:
       return ACTION_IMPACT;
 
-    case GD_S_NUT_CRACK:
+    case GD_S_NUT_CRACKING:
       return ACTION_BREAKING;
 
     case GD_S_EXPANDING_WALL:
-    case GD_S_WALL_REAPPEAR:
+    case GD_S_WALL_REAPPEARING:
     case GD_S_SLIME:
     case GD_S_LAVA:
-    case GD_S_ACID_SPREAD:
+    case GD_S_ACID_SPREADING:
       return ACTION_GROWING;
 
-    case GD_S_DIAMOND_COLLECT:
-    case GD_S_SKELETON_COLLECT:
-    case GD_S_PNEUMATIC_COLLECT:
-    case GD_S_BOMB_COLLECT:
-    case GD_S_CLOCK_COLLECT:
-    case GD_S_SWEET_COLLECT:
-    case GD_S_KEY_COLLECT:
-    case GD_S_DIAMOND_KEY_COLLECT:
+    case GD_S_DIAMOND_COLLECTING:
+    case GD_S_FLYING_DIAMOND_COLLECTING:
+    case GD_S_SKELETON_COLLECTING:
+    case GD_S_PNEUMATIC_COLLECTING:
+    case GD_S_BOMB_COLLECTING:
+    case GD_S_CLOCK_COLLECTING:
+    case GD_S_SWEET_COLLECTING:
+    case GD_S_KEY_COLLECTING:
+    case GD_S_DIAMOND_KEY_COLLECTING:
       return ACTION_COLLECTING;
 
-    case GD_S_BOMB_PLACE:
+    case GD_S_BOMB_PLACING:
     case GD_S_REPLICATOR:
       return ACTION_DROPPING;
 
-    case GD_S_BLADDER_MOVE:
+    case GD_S_BLADDER_MOVING:
       return ACTION_MOVING;
 
     case GD_S_BLADDER_SPENDER:
-    case GD_S_BLADDER_CONVERT:
-    case GD_S_GRAVITY_CHANGE:
+    case GD_S_BLADDER_CONVERTING:
+    case GD_S_GRAVITY_CHANGING:
       return ACTION_CHANGING;
 
-    case GD_S_BITER_EAT:
+    case GD_S_BITER_EATING:
       return ACTION_EATING;
 
-    case GD_S_DOOR_OPEN:
-    case GD_S_CRACK:
+    case GD_S_DOOR_OPENING:
+    case GD_S_CRACKING:
       return ACTION_OPENING;
 
-    case GD_S_WALK_EARTH:
+    case GD_S_DIRT_WALKING:
       return ACTION_DIGGING;
 
-    case GD_S_WALK_EMPTY:
+    case GD_S_EMPTY_WALKING:
       return ACTION_WALKING;
 
     case GD_S_SWITCH_BITER:
@@ -15528,36 +15663,59 @@ static int getSoundAction_BD(int sample)
     case GD_S_STIRRING:
       return ACTION_ACTIVATING;
 
-    case GD_S_BOX_PUSH:
-      return ACTION_PUSHING;
-
     case GD_S_TELEPORTER:
       return ACTION_PASSING;
 
-    case GD_S_EXPLOSION:
-    case GD_S_BOMB_EXPLOSION:
-    case GD_S_GHOST_EXPLOSION:
-    case GD_S_VOODOO_EXPLOSION:
-    case GD_S_NITRO_EXPLOSION:
+    case GD_S_EXPLODING:
+    case GD_S_BOMB_EXPLODING:
+    case GD_S_GHOST_EXPLODING:
+    case GD_S_VOODOO_EXPLODING:
+    case GD_S_NITRO_PACK_EXPLODING:
       return ACTION_EXPLODING;
 
-    case GD_S_COVER:
+    case GD_S_COVERING:
     case GD_S_AMOEBA:
-    case GD_S_AMOEBA_MAGIC:
     case GD_S_MAGIC_WALL:
     case GD_S_PNEUMATIC_HAMMER:
     case GD_S_WATER:
       return ACTION_ACTIVE;
 
-    case GD_S_DIAMOND_RANDOM:
-    case GD_S_DIAMOND_1:
-    case GD_S_DIAMOND_2:
-    case GD_S_DIAMOND_3:
-    case GD_S_DIAMOND_4:
-    case GD_S_DIAMOND_5:
-    case GD_S_DIAMOND_6:
-    case GD_S_DIAMOND_7:
-    case GD_S_DIAMOND_8:
+    case GD_S_DIAMOND_FALLING_RANDOM:
+    case GD_S_DIAMOND_FALLING_1:
+    case GD_S_DIAMOND_FALLING_2:
+    case GD_S_DIAMOND_FALLING_3:
+    case GD_S_DIAMOND_FALLING_4:
+    case GD_S_DIAMOND_FALLING_5:
+    case GD_S_DIAMOND_FALLING_6:
+    case GD_S_DIAMOND_FALLING_7:
+    case GD_S_DIAMOND_FALLING_8:
+    case GD_S_DIAMOND_IMPACT_RANDOM:
+    case GD_S_DIAMOND_IMPACT_1:
+    case GD_S_DIAMOND_IMPACT_2:
+    case GD_S_DIAMOND_IMPACT_3:
+    case GD_S_DIAMOND_IMPACT_4:
+    case GD_S_DIAMOND_IMPACT_5:
+    case GD_S_DIAMOND_IMPACT_6:
+    case GD_S_DIAMOND_IMPACT_7:
+    case GD_S_DIAMOND_IMPACT_8:
+    case GD_S_FLYING_DIAMOND_FALLING_RANDOM:
+    case GD_S_FLYING_DIAMOND_FALLING_1:
+    case GD_S_FLYING_DIAMOND_FALLING_2:
+    case GD_S_FLYING_DIAMOND_FALLING_3:
+    case GD_S_FLYING_DIAMOND_FALLING_4:
+    case GD_S_FLYING_DIAMOND_FALLING_5:
+    case GD_S_FLYING_DIAMOND_FALLING_6:
+    case GD_S_FLYING_DIAMOND_FALLING_7:
+    case GD_S_FLYING_DIAMOND_FALLING_8:
+    case GD_S_FLYING_DIAMOND_IMPACT_RANDOM:
+    case GD_S_FLYING_DIAMOND_IMPACT_1:
+    case GD_S_FLYING_DIAMOND_IMPACT_2:
+    case GD_S_FLYING_DIAMOND_IMPACT_3:
+    case GD_S_FLYING_DIAMOND_IMPACT_4:
+    case GD_S_FLYING_DIAMOND_IMPACT_5:
+    case GD_S_FLYING_DIAMOND_IMPACT_6:
+    case GD_S_FLYING_DIAMOND_IMPACT_7:
+    case GD_S_FLYING_DIAMOND_IMPACT_8:
     case GD_S_TIMEOUT_0:
     case GD_S_TIMEOUT_1:
     case GD_S_TIMEOUT_2:
@@ -15570,10 +15728,12 @@ static int getSoundAction_BD(int sample)
     case GD_S_TIMEOUT_9:
     case GD_S_TIMEOUT_10:
     case GD_S_BONUS_LIFE:
-      // kludge to prevent playing as loop sound
+      // trigger special post-processing (and force sound to be non-looping)
       return ACTION_OTHER;
 
+    case GD_S_AMOEBA_MAGIC:
     case GD_S_FINISHED:
+      // trigger special post-processing (and force sound to be looping)
       return ACTION_DEFAULT;
 
     default:
@@ -15592,24 +15752,75 @@ static int getSoundEffect_BD(int element_bd, int sample)
       sound_action != ACTION_DEFAULT)
     return sound_effect;
 
-  // special sounds
+  // special post-processing for some sounds
   switch (sample)
   {
-    case GD_S_DIAMOND_RANDOM:
-      nr = GetSimpleRandom(8);
-      sound_effect = SND_BD_DIAMOND_IMPACT_RANDOM_1 + nr;
+    case GD_S_DIAMOND_FALLING_RANDOM:
+    case GD_S_DIAMOND_FALLING_1:
+    case GD_S_DIAMOND_FALLING_2:
+    case GD_S_DIAMOND_FALLING_3:
+    case GD_S_DIAMOND_FALLING_4:
+    case GD_S_DIAMOND_FALLING_5:
+    case GD_S_DIAMOND_FALLING_6:
+    case GD_S_DIAMOND_FALLING_7:
+    case GD_S_DIAMOND_FALLING_8:
+      nr = (sample == GD_S_DIAMOND_FALLING_RANDOM ? GetSimpleRandom(8) :
+           sample - GD_S_DIAMOND_FALLING_1);
+      sound_effect = SND_BD_DIAMOND_FALLING_RANDOM_1 + nr;
+
+      if (getSoundInfoEntryFilename(sound_effect) == NULL)
+       sound_effect = SND_BD_DIAMOND_FALLING;
       break;
 
-    case GD_S_DIAMOND_1:
-    case GD_S_DIAMOND_2:
-    case GD_S_DIAMOND_3:
-    case GD_S_DIAMOND_4:
-    case GD_S_DIAMOND_5:
-    case GD_S_DIAMOND_6:
-    case GD_S_DIAMOND_7:
-    case GD_S_DIAMOND_8:
-      nr = sample - GD_S_DIAMOND_1;
+    case GD_S_DIAMOND_IMPACT_RANDOM:
+    case GD_S_DIAMOND_IMPACT_1:
+    case GD_S_DIAMOND_IMPACT_2:
+    case GD_S_DIAMOND_IMPACT_3:
+    case GD_S_DIAMOND_IMPACT_4:
+    case GD_S_DIAMOND_IMPACT_5:
+    case GD_S_DIAMOND_IMPACT_6:
+    case GD_S_DIAMOND_IMPACT_7:
+    case GD_S_DIAMOND_IMPACT_8:
+      nr = (sample == GD_S_DIAMOND_IMPACT_RANDOM ? GetSimpleRandom(8) :
+           sample - GD_S_DIAMOND_IMPACT_1);
       sound_effect = SND_BD_DIAMOND_IMPACT_RANDOM_1 + nr;
+
+      if (getSoundInfoEntryFilename(sound_effect) == NULL)
+       sound_effect = SND_BD_DIAMOND_IMPACT;
+      break;
+
+    case GD_S_FLYING_DIAMOND_FALLING_RANDOM:
+    case GD_S_FLYING_DIAMOND_FALLING_1:
+    case GD_S_FLYING_DIAMOND_FALLING_2:
+    case GD_S_FLYING_DIAMOND_FALLING_3:
+    case GD_S_FLYING_DIAMOND_FALLING_4:
+    case GD_S_FLYING_DIAMOND_FALLING_5:
+    case GD_S_FLYING_DIAMOND_FALLING_6:
+    case GD_S_FLYING_DIAMOND_FALLING_7:
+    case GD_S_FLYING_DIAMOND_FALLING_8:
+      nr = (sample == GD_S_FLYING_DIAMOND_FALLING_RANDOM ? GetSimpleRandom(8) :
+           sample - GD_S_FLYING_DIAMOND_FALLING_1);
+      sound_effect = SND_BD_FLYING_DIAMOND_FALLING_RANDOM_1 + nr;
+
+      if (getSoundInfoEntryFilename(sound_effect) == NULL)
+       sound_effect = SND_BD_FLYING_DIAMOND_FALLING;
+      break;
+
+    case GD_S_FLYING_DIAMOND_IMPACT_RANDOM:
+    case GD_S_FLYING_DIAMOND_IMPACT_1:
+    case GD_S_FLYING_DIAMOND_IMPACT_2:
+    case GD_S_FLYING_DIAMOND_IMPACT_3:
+    case GD_S_FLYING_DIAMOND_IMPACT_4:
+    case GD_S_FLYING_DIAMOND_IMPACT_5:
+    case GD_S_FLYING_DIAMOND_IMPACT_6:
+    case GD_S_FLYING_DIAMOND_IMPACT_7:
+    case GD_S_FLYING_DIAMOND_IMPACT_8:
+      nr = (sample == GD_S_FLYING_DIAMOND_IMPACT_RANDOM ? GetSimpleRandom(8) :
+           sample - GD_S_FLYING_DIAMOND_IMPACT_1);
+      sound_effect = SND_BD_FLYING_DIAMOND_IMPACT_RANDOM_1 + nr;
+
+      if (getSoundInfoEntryFilename(sound_effect) == NULL)
+       sound_effect = SND_BD_FLYING_DIAMOND_IMPACT;
       break;
 
     case GD_S_TIMEOUT_0:
@@ -15630,14 +15841,18 @@ static int getSoundEffect_BD(int element_bd, int sample)
        sound_effect = SND_GAME_RUNNING_OUT_OF_TIME;
       break;
 
-    case GD_S_FINISHED:
-      sound_effect = SND_GAME_LEVELTIME_BONUS;
-      break;
-
     case GD_S_BONUS_LIFE:
       sound_effect = SND_GAME_HEALTH_BONUS;
       break;
 
+    case GD_S_AMOEBA_MAGIC:
+      sound_effect = SND_BD_AMOEBA_OTHER;
+      break;
+
+    case GD_S_FINISHED:
+      sound_effect = SND_GAME_LEVELTIME_BONUS;
+      break;
+
     default:
       sound_effect = SND_UNDEFINED;
       break;
@@ -15656,7 +15871,14 @@ void PlayLevelSound_BD(int xx, int yy, int element_bd, int sample)
   int x = xx - offset;
   int y = yy - offset;
 
-  if (sound_action == ACTION_OTHER)
+  // some sound actions are always looping in native BD game engine
+  if (sound_action == ACTION_DEFAULT)
+    is_loop_sound = TRUE;
+
+  // some sound actions are always non-looping in native BD game engine
+  if (sound_action == ACTION_FALLING ||
+      sound_action == ACTION_MOVING ||
+      sound_action == ACTION_OTHER)
     is_loop_sound = FALSE;
 
   if (sound_effect != SND_UNDEFINED)
@@ -16007,6 +16229,10 @@ void RequestQuitGameExt(boolean skip_request, boolean quick_quit, char *message)
     }
     else
     {
+      // when using BD game engine, cover screen before fading out
+      if (!quick_quit && level.game_engine_type == GAME_ENGINE_TYPE_BD)
+       game_bd.cover_screen = TRUE;
+
       if (quick_quit)
        FadeSkipNextFadeIn();
 
@@ -16063,7 +16289,17 @@ static void RequestRestartGame(void)
   int request_mode = (has_started_game ? REQ_ASK : REQ_CONFIRM);
   int door_state = DOOR_CLOSE_1;
 
-  if (Request(message, request_mode | REQ_STAY_OPEN) && has_started_game)
+  boolean restart_wanted = (Request(message, request_mode | REQ_STAY_OPEN) && has_started_game);
+
+  // if no restart wanted, continue with next level for BD style intermission levels
+  if (!restart_wanted && !level_editor_test_game && level.bd_intermission)
+  {
+    boolean success = AdvanceToNextLevel();
+
+    restart_wanted = (success && setup.auto_play_next_level);
+  }
+
+  if (restart_wanted)
   {
     CloseDoor(door_state);
 
@@ -16129,6 +16365,28 @@ boolean CheckRestartGame(void)
   return TRUE;
 }
 
+boolean checkGameRunning(void)
+{
+  if (game_status != GAME_MODE_PLAYING)
+    return FALSE;
+
+  if (level.game_engine_type == GAME_ENGINE_TYPE_BD && !checkGameRunning_BD())
+    return FALSE;
+
+  return TRUE;
+}
+
+boolean checkGamePlaying(void)
+{
+  if (game_status != GAME_MODE_PLAYING)
+    return FALSE;
+
+  if (level.game_engine_type == GAME_ENGINE_TYPE_BD && !checkGamePlaying_BD())
+    return FALSE;
+
+  return TRUE;
+}
+
 boolean checkGameSolved(void)
 {
   // set for all game engines if level was solved