X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ffiles.c;h=0c4a7f435ee6f230cd8a9a323303940d5142b1c9;hb=6b83db8bee17d70c4e89dc3e3b703b7032aa5f27;hp=069e61a99030ea3e8c5867231844b322f52cda60;hpb=209871b6f17880f98d41cf7d7953f6bf2227a16c;p=rocksndiamonds.git diff --git a/src/files.c b/src/files.c index 069e61a9..0c4a7f43 100644 --- a/src/files.c +++ b/src/files.c @@ -26,7 +26,7 @@ #define MAX_LINE_LEN 1000 /* maximal input line length */ #define CHUNK_ID_LEN 4 /* IFF style chunk id length */ #define LEVEL_HEADER_SIZE 80 /* size of level file header */ -#define LEVEL_HEADER_UNUSED 18 /* unused level header bytes */ +#define LEVEL_HEADER_UNUSED 17 /* unused level header bytes */ #define TAPE_HEADER_SIZE 20 /* size of tape file header */ #define TAPE_HEADER_UNUSED 7 /* unused tape header bytes */ #define FILE_VERSION_1_0 10 /* old 1.0 file version */ @@ -82,8 +82,37 @@ #define LEVELCLASS_CONTRIBUTION_END 299 #define LEVELCLASS_USER_START 300 #define LEVELCLASS_USER_END 399 + +#define LEVELCLASS_TUTORIAL LEVELCLASS_TUTORIAL_START +#define LEVELCLASS_CLASSICS LEVELCLASS_CLASSICS_START +#define LEVELCLASS_CONTRIBUTION LEVELCLASS_CONTRIBUTION_START +#define LEVELCLASS_USER LEVELCLASS_USER_START #define LEVELCLASS_UNDEFINED 999 +#define IS_LEVELCLASS_TUTORIAL(n) \ + (leveldir[n].sort_priority >= LEVELCLASS_TUTORIAL_START && \ + leveldir[n].sort_priority <= LEVELCLASS_TUTORIAL_END) +#define IS_LEVELCLASS_CLASSICS(n) \ + (leveldir[n].sort_priority >= LEVELCLASS_CLASSICS_START && \ + leveldir[n].sort_priority <= LEVELCLASS_CLASSICS_END) +#define IS_LEVELCLASS_CONTRIBUTION(n) \ + (leveldir[n].sort_priority >= LEVELCLASS_CONTRIBUTION_START && \ + leveldir[n].sort_priority <= LEVELCLASS_CONTRIBUTION_END) +#define IS_LEVELCLASS_USER(n) \ + (leveldir[n].sort_priority >= LEVELCLASS_USER_START && \ + leveldir[n].sort_priority <= LEVELCLASS_USER_END) + +#define LEVELCLASS(n) (IS_LEVELCLASS_TUTORIAL(n) ? LEVELCLASS_TUTORIAL : \ + IS_LEVELCLASS_CLASSICS(n) ? LEVELCLASS_CLASSICS : \ + IS_LEVELCLASS_CONTRIBUTION(n) ? LEVELCLASS_CONTRIBUTION : \ + IS_LEVELCLASS_USER(n) ? LEVELCLASS_USER : \ + LEVELCLASS_UNDEFINED) + +#define LEVELCOLOR(n) (IS_LEVELCLASS_TUTORIAL(n) ? FC_BLUE : \ + IS_LEVELCLASS_CLASSICS(n) ? FC_YELLOW : \ + IS_LEVELCLASS_CONTRIBUTION(n) ? FC_GREEN : \ + IS_LEVELCLASS_USER(n) ? FC_RED : FC_BLUE) + static void SaveUserLevelInfo(); /* for 'InitUserLevelDir()' */ static char *getSetupLine(char *, int); /* for 'SaveUserLevelInfo()' */ @@ -246,6 +275,27 @@ static void InitUserLevelDirectory(char *level_subdir) } } +static void getFileChunk(FILE *file, char *chunk_buffer, int *chunk_length) +{ + fgets(chunk_buffer, CHUNK_ID_LEN + 1, file); + + *chunk_length = + (fgetc(file) << 24) | + (fgetc(file) << 16) | + (fgetc(file) << 8) | + (fgetc(file) << 0); +} + +static void putFileChunk(FILE *file, char *chunk_name, int chunk_length) +{ + fputs(chunk_name, file); + + fputc((chunk_length >> 24) & 0xff, file); + fputc((chunk_length >> 16) & 0xff, file); + fputc((chunk_length >> 8) & 0xff, file); + fputc((chunk_length >> 0) & 0xff, file); +} + static void setLevelInfoToDefaults() { int i, x, y; @@ -253,8 +303,8 @@ static void setLevelInfoToDefaults() lev_fieldx = level.fieldx = STD_LEV_FIELDX; lev_fieldy = level.fieldy = STD_LEV_FIELDY; - for(x=0; x= FILE_VERSION_1_2) { - /* first check header chunk identifier and chunk length */ - fgets(chunk, CHUNK_ID_LEN + 1, file); - chunk_length = - (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file); + getFileChunk(file, chunk, &chunk_length); if (strcmp(chunk, "HEAD") || chunk_length != LEVEL_HEADER_SIZE) { Error(ERR_WARN, "wrong 'HEAD' chunk of level file '%s'", filename); @@ -336,9 +420,9 @@ void LoadLevel(int level_nr) level.time = (fgetc(file)<<8) | fgetc(file); level.edelsteine = (fgetc(file)<<8) | fgetc(file); - for(i=0; i= FILE_VERSION_1_2) { - fgets(chunk, CHUNK_ID_LEN + 1, file); - chunk_length = - (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file); + getFileChunk(file, chunk, &chunk_length); + + /* look for optional author chunk */ + if (strcmp(chunk, "AUTH") == 0 && chunk_length == MAX_LEVEL_AUTHOR_LEN) + { + for(i=0; i= LEVELCLASS_CONTRIBUTION_START && - leveldir[leveldir_nr].sort_priority <= LEVELCLASS_CONTRIBUTION_END) + IS_LEVELCLASS_CONTRIBUTION(leveldir_nr)) { Error(ERR_WARN, "level file '%s' has version number 1.0", filename); Error(ERR_WARN, "using high speed movement for player"); - level.high_speed = TRUE; + level.double_speed = TRUE; } } @@ -426,7 +518,6 @@ void SaveLevel(int level_nr) int i, x, y; char *filename = getLevelFilename(level_nr); FILE *file; - int chunk_length; if (!(file = fopen(filename, "w"))) { @@ -437,14 +528,7 @@ void SaveLevel(int level_nr) fputs(LEVEL_COOKIE, file); /* file identifier */ fputc('\n', file); - fputs("HEAD", file); /* chunk identifier for file header */ - - chunk_length = LEVEL_HEADER_SIZE; - - fputc((chunk_length >> 24) & 0xff, file); - fputc((chunk_length >> 16) & 0xff, file); - fputc((chunk_length >> 8) & 0xff, file); - fputc((chunk_length >> 0) & 0xff, file); + putFileChunk(file, "HEAD", LEVEL_HEADER_SIZE); fputc(level.fieldx, file); fputc(level.fieldy, file); @@ -453,7 +537,7 @@ void SaveLevel(int level_nr) fputc(level.edelsteine / 256, file); fputc(level.edelsteine % 256, file); - for(i=0; i> 24) & 0xff, file); - fputc((chunk_length >> 16) & 0xff, file); - fputc((chunk_length >> 8) & 0xff, file); - fputc((chunk_length >> 0) & 0xff, file); + putFileChunk(file, "CONT", 4 + 8 * 3 * 3); fputc(EL_MAMPFER, file); fputc(MampferMax, file); @@ -488,13 +571,7 @@ void SaveLevel(int level_nr) for(x=0; x<3; x++) fputc(level.mampfer_inhalt[i][x][y], file); - fputs("BODY", file); /* chunk identifier for file body */ - chunk_length = lev_fieldx * lev_fieldy; - - fputc((chunk_length >> 24) & 0xff, file); - fputc((chunk_length >> 16) & 0xff, file); - fputc((chunk_length >> 8) & 0xff, file); - fputc((chunk_length >> 0) & 0xff, file); + putFileChunk(file, "BODY", lev_fieldx * lev_fieldy); for(y=0; yname = getStringCopy("non-existing"); + ldi->name = getStringCopy(ANONYMOUS_NAME); + ldi->author = getStringCopy(ANONYMOUS_NAME); ldi->levels = 0; ldi->first_level = 0; ldi->sort_priority = LEVELCLASS_UNDEFINED; /* default: least priority */ @@ -1345,7 +1425,7 @@ int getLastPlayedLevelOfLevelSeries(char *level_series_name) { char *token_value; int level_series_nr = getLevelSeriesNrFromLevelSeriesName(level_series_name); - int last_level_nr = 0; + int last_level_nr = leveldir[level_series_nr].first_level; if (!level_series_name) return 0; @@ -1441,6 +1521,7 @@ static int LoadLevelInfoFromLevelDir(char *level_directory, int start_entry) leveldir[current_entry].levels - 1; leveldir[current_entry].user_defined = (level_directory == options.level_directory ? FALSE : TRUE); + leveldir[current_entry].color = LEVELCOLOR(current_entry); freeSetupFileList(setup_file_list); current_entry++; @@ -1500,9 +1581,13 @@ static void SaveUserLevelInfo() return; } + /* always start with reliable default values */ + setLevelDirInfoToDefaults(&ldi); + ldi.name = getLoginName(); + ldi.author = getRealName(); ldi.levels = 100; - ldi.first_level = 0; + ldi.first_level = 1; ldi.sort_priority = LEVELCLASS_USER_START; ldi.readonly = FALSE;