X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ffiles.c;h=34c53f77c97c76deb60b5cf7c1cfc0b993dc8d17;hb=20e58eb6573a45a41c25958e17e8d9c20f738edc;hp=77585d6cda98510c79a1506c677c6b3b686c107b;hpb=efd80a08bd5de21956872a615f1d03f2dd90cee2;p=rocksndiamonds.git diff --git a/src/files.c b/src/files.c index 77585d6c..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 */ @@ -108,6 +108,11 @@ 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()' */ @@ -282,13 +287,18 @@ static void setLevelInfoToDefaults() Feld[x][y] = Ur[x][y] = EL_ERDREICH; level.time = 100; - level.edelsteine = 0; - level.tempo_amoebe = 10; - level.dauer_sieb = 10; - level.dauer_ablenk = 10; - level.amoebe_inhalt = EL_DIAMANT; + level.gems_needed = 0; + level.amoeba_speed = 10; + level.time_magic_wall = 10; + level.time_wheel = 10; + level.amoeba_content = EL_DIAMANT; + level.double_speed = FALSE; + level.gravity = FALSE; - level.high_speed = FALSE; + for(i=0; i= 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); @@ -392,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> 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); + + putFile16BitInteger(file, level.time, BYTE_ORDER_BIG_ENDIAN); + putFile16BitInteger(file, level.gems_needed, BYTE_ORDER_BIG_ENDIAN); 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); @@ -619,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) @@ -659,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) { @@ -735,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); @@ -768,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); + putFileChunk(file, "HEAD", TAPE_HEADER_SIZE, BYTE_ORDER_BIG_ENDIAN); - 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); - - 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; i