From: Holger Schemel Date: Sun, 4 Apr 2021 11:56:42 +0000 (+0200) Subject: added saving tape for each high score entry X-Git-Tag: 4.3.0.0~197 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=9d46a87f054d241cbfd96c9bec4694c7d1c30f53;p=rocksndiamonds.git added saving tape for each high score entry --- diff --git a/src/files.c b/src/files.c index 42d74dbf..7bdc35ca 100644 --- a/src/files.c +++ b/src/files.c @@ -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) { diff --git a/src/files.h b/src/files.h index b82c89e5..ade7a8d5 100644 --- a/src/files.h +++ b/src/files.h @@ -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); diff --git a/src/game.c b/src/game.c index 1b32c1ec..567f4cf9 100644 --- a/src/game.c +++ b/src/game.c @@ -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; } diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 32ae1121..dbfec24d 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -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) diff --git a/src/libgame/setup.h b/src/libgame/setup.h index c8c5fecc..b84bb822 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -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 *); diff --git a/src/tape.c b/src/tape.c index c1e4bcea..15be1252 100644 --- a/src/tape.c +++ b/src/tape.c @@ -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, diff --git a/src/tape.h b/src/tape.h index a829448a..85e1e64c 100644 --- a/src/tape.h +++ b/src/tape.h @@ -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;