fixed displaying invalid panel values when finishing a game
[rocksndiamonds.git] / src / game.c
index 574d394f12dbce661af48c7ac3dad1762bac55b8..0093ee4566fe45623d0efc09c56cad5224d14757 100644 (file)
@@ -3542,7 +3542,6 @@ void InitGame(void)
   int fade_mask = REDRAW_FIELD;
 
   boolean emulate_bd = TRUE;   // unless non-BOULDERDASH elements found
-  boolean emulate_sb = TRUE;   // unless non-SOKOBAN     elements found
   boolean emulate_sp = TRUE;   // unless non-SUPAPLEX    elements found
   int initial_move_dir = MV_DOWN;
   int i, j, x, y;
@@ -3886,8 +3885,6 @@ void InitGame(void)
   {
     if (emulate_bd && !IS_BD_ELEMENT(Tile[x][y]))
       emulate_bd = FALSE;
-    if (emulate_sb && !IS_SB_ELEMENT(Tile[x][y]))
-      emulate_sb = FALSE;
     if (emulate_sp && !IS_SP_ELEMENT(Tile[x][y]))
       emulate_sp = FALSE;
 
@@ -3912,7 +3909,6 @@ void InitGame(void)
   }
 
   game.emulation = (emulate_bd ? EMU_BOULDERDASH :
-                   emulate_sb ? EMU_SOKOBAN :
                    emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
 
   // initialize type of slippery elements
@@ -4700,6 +4696,27 @@ void InitAmoebaNr(int x, int y)
   AmoebaCnt2[group_nr]++;
 }
 
+static void LevelSolved_SetFinalGameValues(void)
+{
+  game.time_final = (game.no_time_limit ? TimePlayed : TimeLeft);
+  game.score_time_final = (level.use_step_counter ? TimePlayed :
+                          TimePlayed * FRAMES_PER_SECOND + TimeFrames);
+
+  game.score_final = (level.game_engine_type == GAME_ENGINE_TYPE_EM ?
+                     game_em.lev->score :
+                     level.game_engine_type == GAME_ENGINE_TYPE_MM ?
+                     game_mm.score :
+                     game.score);
+
+  game.health_final = (level.game_engine_type == GAME_ENGINE_TYPE_MM ?
+                      MM_HEALTH(game_mm.laser_overload_value) :
+                      game.health);
+
+  game.LevelSolved_CountingTime = game.time_final;
+  game.LevelSolved_CountingScore = game.score_final;
+  game.LevelSolved_CountingHealth = game.health_final;
+}
+
 static void LevelSolved(void)
 {
   if (level.game_engine_type == GAME_ENGINE_TYPE_RND &&
@@ -4708,6 +4725,9 @@ static void LevelSolved(void)
 
   game.LevelSolved = TRUE;
   game.GameOver = TRUE;
+
+  // needed here to display correct panel values while player walks into exit
+  LevelSolved_SetFinalGameValues();
 }
 
 void GameWon(void)
@@ -4730,23 +4750,8 @@ void GameWon(void)
     if (local_player->active && local_player->MovPos)
       return;
 
-    game.time_final = (game.no_time_limit ? TimePlayed : TimeLeft);
-    game.score_time_final = (level.use_step_counter ? TimePlayed :
-                            TimePlayed * FRAMES_PER_SECOND + TimeFrames);
-
-    game.score_final = (level.game_engine_type == GAME_ENGINE_TYPE_EM ?
-                       game_em.lev->score :
-                       level.game_engine_type == GAME_ENGINE_TYPE_MM ?
-                       game_mm.score :
-                       game.score);
-
-    game.health_final = (level.game_engine_type == GAME_ENGINE_TYPE_MM ?
-                        MM_HEALTH(game_mm.laser_overload_value) :
-                        game.health);
-
-    game.LevelSolved_CountingTime = game.time_final;
-    game.LevelSolved_CountingScore = game.score_final;
-    game.LevelSolved_CountingHealth = game.health_final;
+    // calculate final game values after player finished walking into exit
+    LevelSolved_SetFinalGameValues();
 
     game.LevelSolved_GameWon = TRUE;
     game.LevelSolved_SaveTape = tape.recording;
@@ -14527,7 +14532,7 @@ static int DigField(struct PlayerInfo *player,
       if (sokoban_task_solved &&
          game.sokoban_fields_still_needed == 0 &&
          game.sokoban_objects_still_needed == 0 &&
-         (game.emulation == EMU_SOKOBAN || level.auto_exit_sokoban))
+         level.auto_exit_sokoban)
       {
        game.players_still_needed = 0;