added saving tape for each high score entry
authorHolger Schemel <info@artsoft.org>
Sun, 4 Apr 2021 11:56:42 +0000 (13:56 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 1 May 2021 13:38:01 +0000 (15:38 +0200)
src/files.c
src/files.h
src/game.c
src/libgame/setup.c
src/libgame/setup.h
src/tape.c
src/tape.h

index 42d74dbf80c45bb7bb3ff4d3fb393905c3aaa053..7bdc35ca474b97862a46c46600288c6c5b8846cb 100644 (file)
@@ -8295,13 +8295,10 @@ void SaveTapeToFilename(char *filename)
   SetFilePermissions(filename, PERMS_PRIVATE);
 }
 
-void SaveTape(int nr)
+static void SaveTapeExt(char *filename)
 {
-  char *filename = getTapeFilename(nr);
   int i;
 
-  InitTapeDirectory(leveldir_current->subdir);
-
   tape.file_version = FILE_VERSION_ACTUAL;
   tape.game_version = GAME_VERSION_ACTUAL;
 
@@ -8317,6 +8314,25 @@ void SaveTape(int nr)
   tape.changed = FALSE;
 }
 
+void SaveTape(int nr)
+{
+  char *filename = getTapeFilename(nr);
+
+  InitTapeDirectory(leveldir_current->subdir);
+
+  SaveTapeExt(filename);
+}
+
+void SaveScoreTape(int nr)
+{
+  char *filename = getScoreTapeFilename(tape.score_tape_basename, nr);
+
+  // used instead of "leveldir_current->subdir" (for network games)
+  InitScoreTapeDirectory(levelset.identifier, nr);
+
+  SaveTapeExt(filename);
+}
+
 static boolean SaveTapeCheckedExt(int nr, char *msg_replace, char *msg_saved,
                                  unsigned int req_state_added)
 {
index b82c89e5c7c4c42d0ccb9c989cc75d51638fdb97..ade7a8d51f24641fc7b23a47e0129afe071fe339 100644 (file)
@@ -54,6 +54,7 @@ void LoadTape(int);
 void LoadSolutionTape(int);
 void SaveTapeToFilename(char *);
 void SaveTape(int);
+void SaveScoreTape(int);
 void DumpTape(struct TapeInfo *);
 boolean SaveTapeChecked(int);
 boolean SaveTapeChecked_LevelSolved(int);
index 1b32c1ecfe4c3caf25dbb1fe808717ea859f936c..567f4cf9c21de638164fb35ec9a03bf895d7f149 100644 (file)
@@ -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
@@ -5108,7 +5111,10 @@ int NewHiScore(int level_nr)
   }
 
   if (position >= 0) 
+  {
+    SaveScoreTape(level_nr);
     SaveScore(level_nr);
+  }
 
   return position;
 }
index 32ae11215a1a87626d9acdac70e99d6ea62cafaf..dbfec24dd8202d1a924230408950d822064c0dd6 100644 (file)
@@ -114,6 +114,19 @@ static char *getScoreDir(char *level_subdir)
   return score_dir;
 }
 
+static char *getScoreTapeDir(char *level_subdir, int nr)
+{
+  static char *score_tape_dir = NULL;
+  char tape_subdir[MAX_FILENAME_LEN];
+
+  checked_free(score_tape_dir);
+
+  sprintf(tape_subdir, "%03d", nr);
+  score_tape_dir = getPath2(getScoreDir(level_subdir), tape_subdir);
+
+  return score_tape_dir;
+}
+
 static char *getUserSubdir(int nr)
 {
   static char user_subdir[16] = { 0 };
@@ -594,6 +607,34 @@ char *getScoreFilename(int nr)
   return filename;
 }
 
+char *getScoreTapeBasename(char *name)
+{
+  static char basename[MAX_FILENAME_LEN];
+  char basename_raw[MAX_FILENAME_LEN];
+  char timestamp[20];
+
+  sprintf(timestamp, "%s", getCurrentTimestamp());
+  sprintf(basename_raw, "%s-%s", timestamp, name);
+  sprintf(basename, "%s-%08x", timestamp, get_hash_from_key(basename_raw));
+
+  return basename;
+}
+
+char *getScoreTapeFilename(char *basename_no_ext, int nr)
+{
+  static char *filename = NULL;
+  char basename[MAX_FILENAME_LEN];
+
+  checked_free(filename);
+
+  sprintf(basename, "%s.%s", basename_no_ext, TAPEFILE_EXTENSION);
+
+  // used instead of "leveldir_current->subdir" (for network games)
+  filename = getPath2(getScoreTapeDir(levelset.identifier, nr), basename);
+
+  return filename;
+}
+
 char *getSetupFilename(void)
 {
   static char *filename = NULL;
@@ -1075,6 +1116,15 @@ void InitScoreDirectory(char *level_subdir)
   createDirectory(getScoreDir(level_subdir), "level score", permissions);
 }
 
+void InitScoreTapeDirectory(char *level_subdir, int nr)
+{
+  int permissions = (program.global_scores ? PERMS_PUBLIC : PERMS_PRIVATE);
+
+  InitScoreDirectory(level_subdir);
+
+  createDirectory(getScoreTapeDir(level_subdir, nr), "score tape", permissions);
+}
+
 static void SaveUserLevelInfo(void);
 
 void InitUserLevelDirectory(char *level_subdir)
index c8c5feccd309922b6bcdc066de190fc7a528e8e6..b84bb822dd7abe6d98670b9c1f065b9fe1748fc6 100644 (file)
@@ -266,6 +266,8 @@ char *getProgramConfigFilename(char *);
 char *getTapeFilename(int);
 char *getSolutionTapeFilename(int);
 char *getScoreFilename(int);
+char *getScoreTapeBasename(char *);
+char *getScoreTapeFilename(char *, int);
 char *getSetupFilename(void);
 char *getDefaultSetupFilename(void);
 char *getEditorSetupFilename(void);
@@ -284,6 +286,7 @@ char *getCustomMusicDirectory(void);
 
 void InitTapeDirectory(char *);
 void InitScoreDirectory(char *);
+void InitScoreTapeDirectory(char *, int);
 void InitUserLevelDirectory(char *);
 void InitNetworkLevelDirectory(char *);
 void InitLevelSetupDirectory(char *);
index c1e4bcea9f05cb67f8035a0af5cd0336c014cd6b..15be125214d49ff1bf163a85e7901056af9ce198 100644 (file)
@@ -540,6 +540,8 @@ void TapeErase(void)
   tape.length_frames = 0;
   tape.length_seconds = 0;
 
+  tape.score_tape_basename[0] = '\0';
+
   if (leveldir_current)
   {
     strncpy(tape.level_identifier, leveldir_current->identifier,
index a829448a5e007c5c959d66dfc32baa1b9e46457c..85e1e64cae65420881d923454148f0f34e5415d5 100644 (file)
@@ -178,6 +178,7 @@ struct TapeInfo
   int game_version;    // game release version the tape was created with
   int engine_version;  // game engine version the tape was recorded with
 
+  char score_tape_basename[MAX_FILENAME_LEN + 1];
   char level_identifier[MAX_FILENAME_LEN + 1];
   int level_nr;
   unsigned int random_seed;