X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame.c;h=1b2db60f629cda8509a6fd42d5f0e5bf760fc43b;hb=088c9c2caa2434a1667dc8ea25b152b41cf7dc1b;hp=07df1fe52a4f6676eb3713d170144b032a45a448;hpb=94a1798d87daf68e97fa0968f7b08109868020ab;p=rocksndiamonds.git diff --git a/src/game.c b/src/game.c index 07df1fe5..1b2db60f 100644 --- a/src/game.c +++ b/src/game.c @@ -2402,7 +2402,7 @@ static void UpdateGameControlValues(void) } game_panel_controls[GAME_PANEL_SCORE].value = score; - game_panel_controls[GAME_PANEL_HIGHSCORE].value = highscore[0].Score; + game_panel_controls[GAME_PANEL_HIGHSCORE].value = scores.entry[0].score; game_panel_controls[GAME_PANEL_TIME].value = time; @@ -3809,6 +3809,9 @@ void InitGame(void) game.switchgate_pos = 0; game.wind_direction = level.wind_direction_initial; + game.time_final = 0; + game.score_time_final = 0; + game.score = 0; game.score_final = 0; @@ -4706,16 +4709,21 @@ 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.no_time_limit ? TimePlayed : TimeLeft); + game.LevelSolved_CountingTime = game.time_final; game.LevelSolved_CountingScore = game.score_final; game.LevelSolved_CountingHealth = game.health_final; } @@ -4760,23 +4768,27 @@ void GameWon(void) game_over_delay_2 = FRAMES_PER_SECOND / 2; // delay before counting health game_over_delay_3 = FRAMES_PER_SECOND; // delay before ending the game - time = time_final = (game.no_time_limit ? TimePlayed : TimeLeft); + time = time_final = game.time_final; score = score_final = game.score_final; health = health_final = game.health_final; if (time_score > 0) { + int time_final_max = 999; + int time_frames_final_max = time_final_max * FRAMES_PER_SECOND; int time_frames = 0; + int time_frames_left = TimeLeft * FRAMES_PER_SECOND - TimeFrames; + int time_frames_played = TimePlayed * FRAMES_PER_SECOND + TimeFrames; if (TimeLeft > 0) { time_final = 0; - time_frames = TimeLeft * FRAMES_PER_SECOND - TimeFrames; + time_frames = time_frames_left; } - else if (game.no_time_limit && TimePlayed < 999) + else if (game.no_time_limit && TimePlayed < time_final_max) { - time_final = 999; - time_frames = (999 - TimePlayed) * FRAMES_PER_SECOND - TimeFrames; + time_final = time_final_max; + time_frames = time_frames_final_max - time_frames_played; } score_final += time_score * time_frames / FRAMES_PER_SECOND + 0.5; @@ -5035,12 +5047,25 @@ int NewHiScore(int level_nr) LoadScore(level_nr); if (strEqual(setup.player_name, EMPTY_PLAYER_NAME) || - game.score_final < highscore[MAX_SCORE_ENTRIES - 1].Score) + game.score_final < scores.entry[MAX_SCORE_ENTRIES - 1].score) return -1; for (k = 0; k < MAX_SCORE_ENTRIES; k++) { - if (game.score_final > highscore[k].Score) + boolean score_is_better = (game.score_final > scores.entry[k].score); + boolean score_is_equal = (game.score_final == scores.entry[k].score); + boolean time_is_better = (game.score_time_final < scores.entry[k].time); + boolean time_is_equal = (game.score_time_final == scores.entry[k].time); + boolean better_by_score = (score_is_better || + (score_is_equal && time_is_better)); + boolean better_by_time = (time_is_better || + (time_is_equal && score_is_better)); + boolean is_better = (level.rate_time_over_score ? better_by_time : + better_by_score); + boolean entry_is_empty = (scores.entry[k].score == 0 && + scores.entry[k].time == 0); + + if (is_better || entry_is_empty) { // player has made it to the hall of fame @@ -5051,7 +5076,7 @@ int NewHiScore(int level_nr) if (one_score_entry_per_name) { for (l = k; l < MAX_SCORE_ENTRIES; l++) - if (strEqual(setup.player_name, highscore[l].Name)) + if (strEqual(setup.player_name, scores.entry[l].name)) m = l; if (m == k) // player's new highscore overwrites his old one @@ -5060,22 +5085,24 @@ int NewHiScore(int level_nr) for (l = m; l > k; l--) { - strcpy(highscore[l].Name, highscore[l - 1].Name); - highscore[l].Score = highscore[l - 1].Score; + strcpy(scores.entry[l].name, scores.entry[l - 1].name); + scores.entry[l].score = scores.entry[l - 1].score; + scores.entry[l].time = scores.entry[l - 1].time; } } put_into_list: - strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN); - highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0'; - highscore[k].Score = game.score_final; + strncpy(scores.entry[k].name, setup.player_name, MAX_PLAYER_NAME_LEN); + scores.entry[k].name[MAX_PLAYER_NAME_LEN] = '\0'; + scores.entry[k].score = game.score_final; + scores.entry[k].time = game.score_time_final; position = k; break; } else if (one_score_entry_per_name && - !strncmp(setup.player_name, highscore[k].Name, + !strncmp(setup.player_name, scores.entry[k].name, MAX_PLAYER_NAME_LEN)) break; // player already there with a higher score }