cleanup of high score data structures
authorHolger Schemel <info@artsoft.org>
Thu, 11 Mar 2021 19:33:01 +0000 (20:33 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 1 May 2021 13:38:00 +0000 (15:38 +0200)
src/files.c
src/game.c
src/main.c
src/main.h
src/screens.c

index 9bbe3bc678e19974767ddb80555dbe5e9c50217c..612d09422e2733604c2815456f84ca30f269d033 100644 (file)
@@ -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;
index 07df1fe52a4f6676eb3713d170144b032a45a448..d8f34be03724384d6fd7f5295e60134bc2d2cf65 100644 (file)
@@ -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
   }
index 4b2a440b9ceb5d987fed00c1620c730cf3356028..8d8a61a0f848a35ef9aa2dc011d1befc1bdb52ec 100644 (file)
@@ -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;
index 9979d8308225393b06b18358a0423d157d9698cc..8c12cf95b93e7973c7d96645a72325368bac21ac 100644 (file)
@@ -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;
index 464840b6e078a7575f84d36c1958fcb963b4a55d..d1629867c96a2668cb0f1f282e4c54ab04c64936 100644 (file)
@@ -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;