X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ffiles.c;h=34c53f77c97c76deb60b5cf7c1cfc0b993dc8d17;hb=20e58eb6573a45a41c25958e17e8d9c20f738edc;hp=069e61a99030ea3e8c5867231844b322f52cda60;hpb=209871b6f17880f98d41cf7d7953f6bf2227a16c;p=rocksndiamonds.git diff --git a/src/files.c b/src/files.c index 069e61a9..34c53f77 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 16 /* 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()' */ @@ -253,33 +282,71 @@ 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, BYTE_ORDER_BIG_ENDIAN); if (strcmp(chunk, "HEAD") || chunk_length != LEVEL_HEADER_SIZE) { Error(ERR_WARN, "wrong 'HEAD' chunk of level file '%s'", filename); @@ -333,35 +397,37 @@ void LoadLevel(int level_nr) lev_fieldx = level.fieldx = fgetc(file); lev_fieldy = level.fieldy = fgetc(file); - level.time = (fgetc(file)<<8) | fgetc(file); - level.edelsteine = (fgetc(file)<<8) | fgetc(file); + level.time = getFile16BitInteger(file, BYTE_ORDER_BIG_ENDIAN); + level.gems_needed = getFile16BitInteger(file, BYTE_ORDER_BIG_ENDIAN); - 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, BYTE_ORDER_BIG_ENDIAN); + + /* 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; } + + /* determine border element for this level */ + SetBorderElement(); } void SaveLevel(int level_nr) @@ -426,7 +503,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,64 +513,51 @@ 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, BYTE_ORDER_BIG_ENDIAN); fputc(level.fieldx, file); fputc(level.fieldy, file); - fputc(level.time / 256, file); - fputc(level.time % 256, file); - 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 + MAX_ELEMENT_CONTENTS * 3 * 3, + BYTE_ORDER_BIG_ENDIAN); fputc(EL_MAMPFER, file); - fputc(MampferMax, file); + fputc(level.num_yam_contents, file); fputc(0, file); fputc(0, file); - for(i=0; i<8; i++) + 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, "BODY", lev_fieldx * lev_fieldy, BYTE_ORDER_BIG_ENDIAN); for(y=0; y= 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, BYTE_ORDER_BIG_ENDIAN); if (strcmp(chunk, "HEAD") || chunk_length != TAPE_HEADER_SIZE) { Error(ERR_WARN, "wrong 'HEAD' chunk of tape file '%s'", filename); @@ -560,12 +619,9 @@ void LoadTape(int level_nr) } } - tape.random_seed = - (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file); - tape.date = - (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file); - tape.length = - (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file); + tape.random_seed = getFile32BitInteger(file, BYTE_ORDER_BIG_ENDIAN); + tape.date = getFile32BitInteger(file, BYTE_ORDER_BIG_ENDIAN); + tape.length = getFile32BitInteger(file, BYTE_ORDER_BIG_ENDIAN); /* read header fields that are new since version 1.2 */ if (file_version >= FILE_VERSION_1_2) @@ -600,10 +656,7 @@ void LoadTape(int level_nr) /* read chunk "BODY" */ if (file_version >= FILE_VERSION_1_2) { - /* next check body 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, BYTE_ORDER_BIG_ENDIAN); if (strcmp(chunk, "BODY") || chunk_length != (num_participating_players + 1) * tape.length) { @@ -676,7 +729,6 @@ void SaveTape(int level_nr) boolean new_tape = TRUE; byte store_participating_players; int num_participating_players; - int chunk_length; InitTapeDirectory(leveldir[leveldir_nr].filename); @@ -709,42 +761,19 @@ void SaveTape(int level_nr) fputs(TAPE_COOKIE, file); /* file identifier */ fputc('\n', file); - fputs("HEAD", file); /* chunk identifier for file header */ - - chunk_length = TAPE_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); - - fputc((tape.random_seed >> 24) & 0xff, file); - fputc((tape.random_seed >> 16) & 0xff, file); - fputc((tape.random_seed >> 8) & 0xff, file); - fputc((tape.random_seed >> 0) & 0xff, file); + putFileChunk(file, "HEAD", TAPE_HEADER_SIZE, BYTE_ORDER_BIG_ENDIAN); - fputc((tape.date >> 24) & 0xff, file); - fputc((tape.date >> 16) & 0xff, file); - fputc((tape.date >> 8) & 0xff, file); - fputc((tape.date >> 0) & 0xff, file); - - fputc((tape.length >> 24) & 0xff, file); - fputc((tape.length >> 16) & 0xff, file); - fputc((tape.length >> 8) & 0xff, file); - fputc((tape.length >> 0) & 0xff, file); + putFile32BitInteger(file, tape.random_seed, BYTE_ORDER_BIG_ENDIAN); + putFile32BitInteger(file, tape.date, BYTE_ORDER_BIG_ENDIAN); + putFile32BitInteger(file, tape.length, BYTE_ORDER_BIG_ENDIAN); fputc(store_participating_players, 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, "BODY", (num_participating_players + 1) * tape.length, + BYTE_ORDER_BIG_ENDIAN); for(i=0; iname = 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 +1377,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 +1473,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 +1533,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;