From: Holger Schemel Date: Sun, 4 Apr 2021 12:29:27 +0000 (+0200) Subject: added saving tape basename for each high score entry X-Git-Tag: 4.3.0.0~195 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=881bd7909d3a28c07c0bed2185e60a437b407e7c;p=rocksndiamonds.git added saving tape basename for each high score entry --- diff --git a/src/files.c b/src/files.c index 7bdc35ca..a4f7f10a 100644 --- a/src/files.c +++ b/src/files.c @@ -8430,6 +8430,7 @@ static void setScoreInfoToDefaults(void) for (i = 0; i < MAX_SCORE_ENTRIES; i++) { + strcpy(scores.entry[i].tape_basename, UNDEFINED_FILENAME); strcpy(scores.entry[i].name, EMPTY_PLAYER_NAME); scores.entry[i].score = 0; scores.entry[i].time = 0; @@ -8582,6 +8583,23 @@ static int LoadScore_TIME(File *file, int chunk_size, struct ScoreInfo *scores) return chunk_size; } +static int LoadScore_TAPE(File *file, int chunk_size, struct ScoreInfo *scores) +{ + int i, j; + + for (i = 0; i < scores->num_entries; i++) + { + for (j = 0; j < MAX_SCORE_TAPE_BASENAME_LEN; j++) + scores->entry[i].tape_basename[j] = getFile8Bit(file); + + scores->entry[i].tape_basename[MAX_SCORE_TAPE_BASENAME_LEN] = '\0'; + } + + chunk_size = scores->num_entries * MAX_SCORE_TAPE_BASENAME_LEN; + + return chunk_size; +} + void LoadScore(int nr) { char *filename = getScoreFilename(nr); @@ -8655,6 +8673,7 @@ void LoadScore(int nr) { "NAME", -1, LoadScore_NAME }, { "SCOR", -1, LoadScore_SCOR }, { "TIME", -1, LoadScore_TIME }, + { "TAPE", -1, LoadScore_TAPE }, { NULL, 0, NULL } }; @@ -8781,6 +8800,19 @@ static void SaveScore_TIME(FILE *file, struct ScoreInfo *scores) putFile32BitBE(file, scores->entry[i].time); } +static void SaveScore_TAPE(FILE *file, struct ScoreInfo *scores) +{ + int i, j; + + for (i = 0; i < scores->num_entries; i++) + { + int size = strlen(scores->entry[i].tape_basename); + + for (j = 0; j < MAX_SCORE_TAPE_BASENAME_LEN; j++) + putFile8Bit(file, (j < size ? scores->entry[i].tape_basename[j] : 0)); + } +} + static void SaveScoreToFilename(char *filename) { FILE *file; @@ -8789,6 +8821,7 @@ static void SaveScoreToFilename(char *filename) int name_chunk_size; int scor_chunk_size; int time_chunk_size; + int tape_chunk_size; if (!(file = fopen(filename, MODE_WRITE))) { @@ -8801,6 +8834,7 @@ static void SaveScoreToFilename(char *filename) name_chunk_size = scores.num_entries * MAX_PLAYER_NAME_LEN; scor_chunk_size = scores.num_entries * 2; time_chunk_size = scores.num_entries * 4; + tape_chunk_size = scores.num_entries * MAX_SCORE_TAPE_BASENAME_LEN; putFileChunkBE(file, "RND1", CHUNK_SIZE_UNDEFINED); putFileChunkBE(file, "SCOR", CHUNK_SIZE_NONE); @@ -8820,6 +8854,9 @@ static void SaveScoreToFilename(char *filename) putFileChunkBE(file, "TIME", time_chunk_size); SaveScore_TIME(file, &scores); + putFileChunkBE(file, "TAPE", tape_chunk_size); + SaveScore_TAPE(file, &scores); + fclose(file); SetFilePermissions(filename, permissions); diff --git a/src/game.c b/src/game.c index 5c554516..20021266 100644 --- a/src/game.c +++ b/src/game.c @@ -5097,6 +5097,7 @@ int NewHiScore(int level_nr) put_into_list: + strcpy(entry->tape_basename, tape.score_tape_basename); strncpy(entry->name, setup.player_name, MAX_PLAYER_NAME_LEN); entry->name[MAX_PLAYER_NAME_LEN] = '\0'; entry->score = game.score_final; diff --git a/src/main.h b/src/main.h index 482f7317..b429c15b 100644 --- a/src/main.h +++ b/src/main.h @@ -3040,6 +3040,7 @@ struct ViewportInfo struct ScoreEntry { + char tape_basename[MAX_FILENAME_LEN + 1]; char name[MAX_PLAYER_NAME_LEN + 1]; int score; int time; // time (in frames) or steps played diff --git a/src/tape.h b/src/tape.h index 85e1e64c..e4732817 100644 --- a/src/tape.h +++ b/src/tape.h @@ -39,6 +39,9 @@ #define TAPE_PROPERTY_NONE 0 #define TAPE_PROPERTY_EM_RANDOM_BUG (1 << 0) +// values for score tape basename length (date, time, name hash, no extension) +#define MAX_SCORE_TAPE_BASENAME_LEN 24 + // some positions in the video tape control window #define VIDEO_DISPLAY1_XPOS 5 #define VIDEO_DISPLAY1_YPOS 5