X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame.c;h=b85dbcae9861dfcae7df2d211ed5a51e2aeba768;hb=edfb8a9789e107ac11ad76e456bb0f7c2a943ffa;hp=2432ab343e0ac2fe0cdc36bc380a32f82ca78643;hpb=ef1162b39495bd80698e6e449060ba82a43ed21c;p=rocksndiamonds.git diff --git a/src/game.c b/src/game.c index 2432ab34..b85dbcae 100644 --- a/src/game.c +++ b/src/game.c @@ -1106,7 +1106,7 @@ void ContinueMoving(int, int); void Bang(int, int); void InitMovDir(int, int); void InitAmoebaNr(int, int); -int NewHiScore(int); +int NewHighScore(int); void TestIfGoodThingHitsBadThing(int, int, int); void TestIfBadThingHitsGoodThing(int, int, int); @@ -4960,7 +4960,7 @@ void GameEnd(void) { // used instead of "level_nr" (needed for network games) int last_level_nr = levelset.level_nr; - int hi_pos; + int highlight_position; game.LevelSolved_GameEnd = TRUE; @@ -4971,6 +4971,9 @@ void GameEnd(void) CloseDoor(DOOR_CLOSE_1); SaveTapeChecked_LevelSolved(tape.level_nr); // ask to save tape + + // set unique basename for score tape (also saved in high score table) + strcpy(tape.score_tape_basename, getScoreTapeBasename(setup.player_name)); } // if no tape is to be saved, close both doors simultaneously @@ -5001,6 +5004,9 @@ void GameEnd(void) SaveLevelSetup_SeriesInfo(); } + // save score and score tape before potentially erasing tape below + highlight_position = NewHighScore(last_level_nr); + if (setup.increment_levels && level_nr < leveldir_current->last_level && !network_playing) @@ -5016,13 +5022,11 @@ void GameEnd(void) } } - hi_pos = NewHiScore(last_level_nr); - - if (hi_pos >= 0 && setup.show_scores_after_game) + if (highlight_position >= 0 && setup.show_scores_after_game) { SetGameStatus(GAME_MODE_SCORES); - DrawHallOfFame(last_level_nr, hi_pos); + DrawHallOfFame(last_level_nr, highlight_position); } else if (setup.auto_play_next_level && setup.increment_levels && last_level_nr < leveldir_current->last_level && @@ -5038,78 +5042,93 @@ void GameEnd(void) } } -int NewHiScore(int level_nr) +static int addScoreEntry(struct ScoreInfo *list, struct ScoreEntry *new_entry) { - int k, l; - int position = -1; boolean one_score_entry_per_name = !program.many_scores_per_name; + int i; - LoadScore(level_nr); - - if (strEqual(setup.player_name, EMPTY_PLAYER_NAME) || - game.score_final < scores.entry[MAX_SCORE_ENTRIES - 1].score) + if (strEqual(setup.player_name, EMPTY_PLAYER_NAME)) return -1; - for (k = 0; k < MAX_SCORE_ENTRIES; k++) + for (i = 0; i < MAX_SCORE_ENTRIES; i++) { - 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); + struct ScoreEntry *entry = &list->entry[i]; + boolean score_is_better = (new_entry->score > entry->score); + boolean score_is_equal = (new_entry->score == entry->score); + boolean time_is_better = (new_entry->time < entry->time); + boolean time_is_equal = (new_entry->time == entry->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); + boolean entry_is_empty = (entry->score == 0 && + entry->time == 0); if (is_better || entry_is_empty) { // player has made it to the hall of fame - if (k < MAX_SCORE_ENTRIES - 1) + if (i < MAX_SCORE_ENTRIES - 1) { int m = MAX_SCORE_ENTRIES - 1; + int l; if (one_score_entry_per_name) { - for (l = k; l < MAX_SCORE_ENTRIES; l++) - if (strEqual(setup.player_name, scores.entry[l].name)) + for (l = i; l < MAX_SCORE_ENTRIES; l++) + if (strEqual(list->entry[l].name, setup.player_name)) m = l; - if (m == k) // player's new highscore overwrites his old one + if (m == i) // player's new highscore overwrites his old one goto put_into_list; } - for (l = m; l > k; l--) - { - 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; - } + for (l = m; l > i; l--) + list->entry[l] = list->entry[l - 1]; } put_into_list: - 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; + *entry = *new_entry; - break; + return i; } else if (one_score_entry_per_name && - !strncmp(setup.player_name, scores.entry[k].name, - MAX_PLAYER_NAME_LEN)) - break; // player already there with a higher score + strEqual(entry->name, setup.player_name)) + { + // player already in high score list with better score or time + + return -1; + } } - if (position >= 0) + return -1; +} + +int NewHighScore(int level_nr) +{ + struct ScoreEntry new_entry = {{ 0 }}; // (prevent warning from GCC bug 53119) + + strncpy(new_entry.tape_basename, tape.score_tape_basename, MAX_FILENAME_LEN); + strncpy(new_entry.name, setup.player_name, MAX_PLAYER_NAME_LEN); + + new_entry.score = game.score_final; + new_entry.time = game.score_time_final; + + LoadScore(level_nr); + + int position = addScoreEntry(&scores, &new_entry); + + if (position >= 0) + { SaveScore(level_nr); + if (game.LevelSolved_SaveTape) + SaveScoreTape(level_nr); + } + return position; } @@ -13140,7 +13159,7 @@ void ScrollPlayer(struct PlayerInfo *player, int mode) RemovePlayer(player); } - if (!game.LevelSolved && level.use_step_counter) + if (level.use_step_counter) { int i; @@ -13150,14 +13169,14 @@ void ScrollPlayer(struct PlayerInfo *player, int mode) { TimeLeft--; - if (TimeLeft <= 10 && setup.time_limit) + if (TimeLeft <= 10 && setup.time_limit && !game.LevelSolved) PlaySound(SND_GAME_RUNNING_OUT_OF_TIME); game_panel_controls[GAME_PANEL_TIME].value = TimeLeft; DisplayGameControlValues(); - if (!TimeLeft && setup.time_limit) + if (!TimeLeft && setup.time_limit && !game.LevelSolved) for (i = 0; i < MAX_PLAYERS; i++) KillPlayer(&stored_player[i]); }