changed calculating final game values when game is really over
authorHolger Schemel <info@artsoft.org>
Sat, 20 Mar 2021 10:16:59 +0000 (11:16 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 1 May 2021 13:38:01 +0000 (15:38 +0200)
Before this change, final game values (like final score and final
playing time or steps) were calculated before the game was really
over (but instead at the time the player started moving to the exit).

This especially caused calculating a wrong playing time that did not
include the time the player needed to finally reach the exit, which
was especially wrong when using steps instead of seconds/frames to
count the playing time, as the very last step was always missing in
this case.

This change fixes this bug by moving the code to calculate the final
game values to a later point where there is no player action anymore.

src/game.c

index 1b2db60f629cda8509a6fd42d5f0e5bf760fc43b..2432ab343e0ac2fe0cdc36bc380a32f82ca78643 100644 (file)
@@ -4708,24 +4708,6 @@ static void LevelSolved(void)
 
   game.LevelSolved = TRUE;
   game.GameOver = TRUE;
-
-  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;
 }
 
 void GameWon(void)
@@ -4748,6 +4730,24 @@ 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;
+
     game.LevelSolved_GameWon = TRUE;
     game.LevelSolved_SaveTape = tape.recording;
     game.LevelSolved_SaveScore = !tape.playing;