added storing played time in score files (not used yet)
authorHolger Schemel <info@artsoft.org>
Thu, 11 Mar 2021 19:35:24 +0000 (20:35 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 1 May 2021 13:38:00 +0000 (15:38 +0200)
src/files.c
src/main.h

index 612d09422e2733604c2815456f84ca30f269d033..4dc7fceb920713954d13f135147dec071bc433b8 100644 (file)
@@ -8390,6 +8390,7 @@ static void setScoreInfoToDefaults(void)
   {
     strcpy(scores.entry[i].name, EMPTY_PLAYER_NAME);
     scores.entry[i].score = 0;
+    scores.entry[i].time = 0;
   }
 }
 
@@ -8508,6 +8509,18 @@ static int LoadScore_SCOR(File *file, int chunk_size, struct ScoreInfo *scores)
   return chunk_size;
 }
 
+static int LoadScore_TIME(File *file, int chunk_size, struct ScoreInfo *scores)
+{
+  int i;
+
+  for (i = 0; i < scores->num_entries; i++)
+    scores->entry[i].time = getFile32BitBE(file);
+
+  chunk_size = scores->num_entries * 4;
+
+  return chunk_size;
+}
+
 void LoadScore(int nr)
 {
   char *filename = getScoreFilename(nr);
@@ -8577,6 +8590,7 @@ void LoadScore(int nr)
       { "INFO", -1,                    LoadScore_INFO },
       { "NAME", -1,                    LoadScore_NAME },
       { "SCOR", -1,                    LoadScore_SCOR },
+      { "TIME", -1,                    LoadScore_TIME },
 
       {  NULL,  0,                     NULL }
     };
@@ -8695,6 +8709,14 @@ static void SaveScore_SCOR(FILE *file, struct ScoreInfo *scores)
     putFile16BitBE(file, scores->entry[i].score);
 }
 
+static void SaveScore_TIME(FILE *file, struct ScoreInfo *scores)
+{
+  int i;
+
+  for (i = 0; i < scores->num_entries; i++)
+    putFile32BitBE(file, scores->entry[i].time);
+}
+
 static void SaveScoreToFilename(char *filename)
 {
   FILE *file;
@@ -8702,6 +8724,7 @@ static void SaveScoreToFilename(char *filename)
   int info_chunk_size;
   int name_chunk_size;
   int scor_chunk_size;
+  int time_chunk_size;
 
   if (!(file = fopen(filename, MODE_WRITE)))
   {
@@ -8713,6 +8736,7 @@ static void SaveScoreToFilename(char *filename)
   info_chunk_size = 2 + (strlen(scores.level_identifier) + 1) + 2 + 2;
   name_chunk_size = scores.num_entries * MAX_PLAYER_NAME_LEN;
   scor_chunk_size = scores.num_entries * 2;
+  time_chunk_size = scores.num_entries * 4;
 
   putFileChunkBE(file, "RND1", CHUNK_SIZE_UNDEFINED);
   putFileChunkBE(file, "SCOR", CHUNK_SIZE_NONE);
@@ -8729,6 +8753,9 @@ static void SaveScoreToFilename(char *filename)
   putFileChunkBE(file, "SCOR", scor_chunk_size);
   SaveScore_SCOR(file, &scores);
 
+  putFileChunkBE(file, "TIME", time_chunk_size);
+  SaveScore_TIME(file, &scores);
+
   fclose(file);
 
   SetFilePermissions(filename, permissions);
@@ -8751,6 +8778,7 @@ void SaveScore(int nr)
 
   for (i = 0; i < MAX_SCORE_ENTRIES; i++)
     if (scores.entry[i].score == 0 &&
+        scores.entry[i].time == 0 &&
         strEqual(scores.entry[i].name, EMPTY_PLAYER_NAME))
       break;
 
index 8c12cf95b93e7973c7d96645a72325368bac21ac..c0b74e80f8765ea1503941f8b7c61905dadbab8f 100644 (file)
@@ -3042,6 +3042,7 @@ struct ScoreEntry
 {
   char name[MAX_PLAYER_NAME_LEN + 1];
   int score;
+  int time;            // time (in frames) or steps played
 };
 
 struct ScoreInfo