renamed variables
[rocksndiamonds.git] / src / game.c
index 2c16aa62c93d95c8a5344eb9f5d44aea92955c54..1966bb3c6c03ec01db36464d7fce410a6fbedd9a 100644 (file)
@@ -1840,13 +1840,13 @@ 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 = (element == EL_BDX_EMPTY           ? EL_EMPTY :
+            element == EL_BDX_PLAYER           ? EL_PLAYER_1 :
+            element == EL_BDX_INBOX            ? EL_PLAYER_1 :
+            element == EL_BDX_SAND_1           ? EL_SAND :
+            element == EL_BDX_STEELWALL        ? EL_STEELWALL :
+            element == EL_BDX_EXIT_CLOSED      ? EL_EXIT_CLOSED :
+            element == EL_BDX_EXIT_OPEN        ? EL_EXIT_OPEN :
             element);
 
   Tile[x][y] = element;
@@ -2286,7 +2286,7 @@ static void UpdateGameControlValues(void)
   int time = (game.LevelSolved ?
              game.LevelSolved_CountingTime :
              level.game_engine_type == GAME_ENGINE_TYPE_BD ?
-             game_bd.time_played :
+             game_bd.time_left :
              level.game_engine_type == GAME_ENGINE_TYPE_EM ?
              game_em.lev->time :
              level.game_engine_type == GAME_ENGINE_TYPE_SP ?
@@ -3676,6 +3676,9 @@ void InitGame(void)
   else
   {
     SetGameStatus(GAME_MODE_PLAYING);
+
+    // do not cover screen before fading out when starting from main menu
+    game_bd.cover_screen = FALSE;
   }
 
   if (level_editor_test_game)
@@ -4621,6 +4624,7 @@ void InitGame(void)
   game.restart_level = FALSE;
   game.request_active = FALSE;
   game.envelope_active = FALSE;
+  game.any_door_active = FALSE;
 
   if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
     InitGameActions_MM();
@@ -4858,7 +4862,7 @@ void InitAmoebaNr(int x, int y)
 
 static void LevelSolved_SetFinalGameValues(void)
 {
-  game.time_final = (level.game_engine_type == GAME_ENGINE_TYPE_BD ? game_bd.time_played :
+  game.time_final = (level.game_engine_type == GAME_ENGINE_TYPE_BD ? game_bd.time_left :
                     game.no_level_time_limit ? TimePlayed : TimeLeft);
   game.score_time_final = (level.use_step_counter ? TimePlayed :
                           TimePlayed * FRAMES_PER_SECOND + TimeFrames);
@@ -5160,10 +5164,28 @@ void GameEnd(void)
   // used instead of "level_nr" (needed for network games)
   int last_level_nr = levelset.level_nr;
   boolean tape_saved = FALSE;
+  boolean game_over = checkGameFailed();
 
   // 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)
 
+  // do not handle game end if game over and automatically asking for game restart
+  if (game_over && setup.ask_on_game_over)
+  {
+    // (this is a special case: player pressed "return" key or fire button shortly before
+    // automatically asking to restart the game, so skip asking and restart right away)
+
+    CloseDoor(DOOR_CLOSE_1);
+
+    StartGameActions(network.enabled, setup.autorecord, level.random_seed);
+
+    return;
+  }
+
+  // do not handle game end if request dialog is already active
+  if (checkRequestActive())
+    return;
+
   if (game.LevelSolved)
     game.LevelSolved_GameEnd = TRUE;
 
@@ -15765,10 +15787,10 @@ static int getSoundEffect_BD(int element_bd, int sample)
     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;
+      sound_effect = SND_BDX_DIAMOND_FALLING_RANDOM_1 + nr;
 
       if (getSoundInfoEntryFilename(sound_effect) == NULL)
-       sound_effect = SND_BD_DIAMOND_FALLING;
+       sound_effect = SND_BDX_DIAMOND_FALLING;
       break;
 
     case GD_S_DIAMOND_IMPACT_RANDOM:
@@ -15782,10 +15804,10 @@ static int getSoundEffect_BD(int element_bd, int sample)
     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;
+      sound_effect = SND_BDX_DIAMOND_IMPACT_RANDOM_1 + nr;
 
       if (getSoundInfoEntryFilename(sound_effect) == NULL)
-       sound_effect = SND_BD_DIAMOND_IMPACT;
+       sound_effect = SND_BDX_DIAMOND_IMPACT;
       break;
 
     case GD_S_FLYING_DIAMOND_FALLING_RANDOM:
@@ -15799,10 +15821,10 @@ static int getSoundEffect_BD(int element_bd, int sample)
     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;
+      sound_effect = SND_BDX_FLYING_DIAMOND_FALLING_RANDOM_1 + nr;
 
       if (getSoundInfoEntryFilename(sound_effect) == NULL)
-       sound_effect = SND_BD_FLYING_DIAMOND_FALLING;
+       sound_effect = SND_BDX_FLYING_DIAMOND_FALLING;
       break;
 
     case GD_S_FLYING_DIAMOND_IMPACT_RANDOM:
@@ -15816,10 +15838,10 @@ static int getSoundEffect_BD(int element_bd, int sample)
     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;
+      sound_effect = SND_BDX_FLYING_DIAMOND_IMPACT_RANDOM_1 + nr;
 
       if (getSoundInfoEntryFilename(sound_effect) == NULL)
-       sound_effect = SND_BD_FLYING_DIAMOND_IMPACT;
+       sound_effect = SND_BDX_FLYING_DIAMOND_IMPACT;
       break;
 
     case GD_S_TIMEOUT_0:
@@ -15845,7 +15867,7 @@ static int getSoundEffect_BD(int element_bd, int sample)
       break;
 
     case GD_S_AMOEBA_MAGIC:
-      sound_effect = SND_BD_AMOEBA_OTHER;
+      sound_effect = SND_BDX_AMOEBA_1_OTHER;
       break;
 
     case GD_S_FINISHED:
@@ -16342,7 +16364,7 @@ boolean CheckRestartGame(void)
   }
 
   // do not ask to play again if request dialog is already active
-  if (game.request_active)
+  if (checkRequestActive())
     return FALSE;
 
   // do not ask to play again if request dialog already handled
@@ -16411,6 +16433,11 @@ boolean checkGameEnded(void)
   return (checkGameSolved() || checkGameFailed());
 }
 
+boolean checkRequestActive(void)
+{
+  return (game.request_active || game.envelope_active || game.any_door_active);
+}
+
 
 // ----------------------------------------------------------------------------
 // random generator functions