From: Holger Schemel Date: Thu, 11 Mar 2021 19:33:01 +0000 (+0100) Subject: cleanup of high score data structures X-Git-Tag: 4.3.0.0~212 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=77eea34405c119f20f461acae08cd77ec5c21dd6;p=rocksndiamonds.git cleanup of high score data structures --- diff --git a/src/files.c b/src/files.c index 9bbe3bc6..612d0942 100644 --- a/src/files.c +++ b/src/files.c @@ -8388,8 +8388,8 @@ static void setScoreInfoToDefaults(void) for (i = 0; i < MAX_SCORE_ENTRIES; i++) { - strcpy(highscore[i].Name, EMPTY_PLAYER_NAME); - highscore[i].Score = 0; + strcpy(scores.entry[i].name, EMPTY_PLAYER_NAME); + scores.entry[i].score = 0; } } @@ -8422,7 +8422,7 @@ static void LoadScore_OLD(int nr) for (i = 0; i < MAX_SCORE_ENTRIES; i++) { - if (fscanf(file, "%d", &highscore[i].Score) == EOF) + if (fscanf(file, "%d", &scores.entry[i].score) == EOF) Warn("fscanf() failed; %s", strerror(errno)); if (fgets(line, MAX_LINE_LEN, file) == NULL) @@ -8435,8 +8435,8 @@ static void LoadScore_OLD(int nr) { if (*line_ptr != ' ' && *line_ptr != '\t' && *line_ptr != '\0') { - strncpy(highscore[i].Name, line_ptr, MAX_PLAYER_NAME_LEN); - highscore[i].Name[MAX_PLAYER_NAME_LEN] = '\0'; + strncpy(scores.entry[i].name, line_ptr, MAX_PLAYER_NAME_LEN); + scores.entry[i].name[MAX_PLAYER_NAME_LEN] = '\0'; break; } } @@ -8486,9 +8486,9 @@ static int LoadScore_NAME(File *file, int chunk_size, struct ScoreInfo *scores) for (i = 0; i < scores->num_entries; i++) { for (j = 0; j < MAX_PLAYER_NAME_LEN; j++) - highscore[i].Name[j] = getFile8Bit(file); + scores->entry[i].name[j] = getFile8Bit(file); - highscore[i].Name[MAX_PLAYER_NAME_LEN] = '\0'; + scores->entry[i].name[MAX_PLAYER_NAME_LEN] = '\0'; } chunk_size = scores->num_entries * MAX_PLAYER_NAME_LEN; @@ -8501,7 +8501,7 @@ static int LoadScore_SCOR(File *file, int chunk_size, struct ScoreInfo *scores) int i; for (i = 0; i < scores->num_entries; i++) - highscore[i].Score = getFile16BitBE(file); + scores->entry[i].score = getFile16BitBE(file); chunk_size = scores->num_entries * 2; @@ -8646,7 +8646,7 @@ void SaveScore_OLD(int nr) fprintf(file, "%s\n\n", SCORE_COOKIE); for (i = 0; i < MAX_SCORE_ENTRIES; i++) - fprintf(file, "%d %s\n", highscore[i].Score, highscore[i].Name); + fprintf(file, "%d %s\n", scores.entry[i].score, scores.entry[i].name); fclose(file); @@ -8680,10 +8680,10 @@ static void SaveScore_NAME(FILE *file, struct ScoreInfo *scores) for (i = 0; i < scores->num_entries; i++) { - int name_size = strlen(highscore[i].Name); + int name_size = strlen(scores->entry[i].name); for (j = 0; j < MAX_PLAYER_NAME_LEN; j++) - putFile8Bit(file, (j < name_size ? highscore[i].Name[j] : 0)); + putFile8Bit(file, (j < name_size ? scores->entry[i].name[j] : 0)); } } @@ -8692,7 +8692,7 @@ static void SaveScore_SCOR(FILE *file, struct ScoreInfo *scores) int i; for (i = 0; i < scores->num_entries; i++) - putFile16BitBE(file, highscore[i].Score); + putFile16BitBE(file, scores->entry[i].score); } static void SaveScoreToFilename(char *filename) @@ -8750,8 +8750,8 @@ void SaveScore(int nr) scores.level_nr = level_nr; for (i = 0; i < MAX_SCORE_ENTRIES; i++) - if (highscore[i].Score == 0 && - strEqual(highscore[i].Name, EMPTY_PLAYER_NAME)) + if (scores.entry[i].score == 0 && + strEqual(scores.entry[i].name, EMPTY_PLAYER_NAME)) break; scores.num_entries = i; diff --git a/src/game.c b/src/game.c index 07df1fe5..d8f34be0 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; @@ -5035,12 +5035,12 @@ 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) + if (game.score_final > scores.entry[k].score) { // player has made it to the hall of fame @@ -5051,7 +5051,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 +5060,22 @@ 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; } } 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; 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 } diff --git a/src/main.c b/src/main.c index 4b2a440b..8d8a61a0 100644 --- a/src/main.c +++ b/src/main.c @@ -128,7 +128,6 @@ boolean network_player_action_received = FALSE; struct LevelInfo level, level_template; struct PlayerInfo stored_player[MAX_PLAYERS], *local_player = NULL; -struct HiScore highscore[MAX_SCORE_ENTRIES]; struct ScoreInfo scores; struct TapeInfo tape; struct GameInfo game; diff --git a/src/main.h b/src/main.h index 9979d830..8c12cf95 100644 --- a/src/main.h +++ b/src/main.h @@ -3038,10 +3038,10 @@ struct ViewportInfo struct RectWithBorder door_2[NUM_SPECIAL_GFX_ARGS]; }; -struct HiScore +struct ScoreEntry { - char Name[MAX_PLAYER_NAME_LEN + 1]; - int Score; + char name[MAX_PLAYER_NAME_LEN + 1]; + int score; }; struct ScoreInfo @@ -3053,6 +3053,8 @@ struct ScoreInfo int level_nr; int num_entries; + + struct ScoreEntry entry[MAX_SCORE_ENTRIES]; }; struct Content @@ -3760,7 +3762,6 @@ extern boolean network_player_action_received; extern int graphics_action_mapping[]; extern struct LevelInfo level, level_template; -extern struct HiScore highscore[]; extern struct ScoreInfo scores; extern struct TapeInfo tape; extern struct GlobalInfo global; diff --git a/src/screens.c b/src/screens.c index 464840b6..d1629867 100644 --- a/src/screens.c +++ b/src/screens.c @@ -5110,10 +5110,10 @@ static void drawHallOfFameList(int level_nr, int first_entry, for (j = 0; j < num_dots; j++) DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3); - if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME)) - DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2); + if (!strEqual(scores.entry[entry].name, EMPTY_PLAYER_NAME)) + DrawText(mSX + dx2, sy, scores.entry[entry].name, font_nr2); - DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4); + DrawText(mSX + dx3, sy, int2str(scores.entry[entry].score, 5), font_nr4); } redraw_mask |= REDRAW_FIELD;