X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ffiles.c;h=34c53f77c97c76deb60b5cf7c1cfc0b993dc8d17;hb=20e58eb6573a45a41c25958e17e8d9c20f738edc;hp=2ef526ddc5a4c943ebe62e668f83c08ce43c3ec6;hpb=f6482a3218cec02ca8e251993972e681e47d4244;p=rocksndiamonds.git diff --git a/src/files.c b/src/files.c index 2ef526dd..34c53f77 100644 --- a/src/files.c +++ b/src/files.c @@ -275,27 +275,6 @@ 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; @@ -308,11 +287,11 @@ 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; @@ -327,11 +306,11 @@ static void setLevelInfoToDefaults() for(i=0; i= FILE_VERSION_1_2) { - getFileChunk(file, chunk, &chunk_length); + 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); @@ -418,35 +397,35 @@ 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) { - getFileChunk(file, chunk, &chunk_length); + 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) @@ -465,23 +444,24 @@ void LoadLevel(int level_nr) level.author[i] = fgetc(file); level.author[MAX_LEVEL_NAME_LEN] = 0; - getFileChunk(file, chunk, &chunk_length); + getFileChunk(file, chunk, &chunk_length, BYTE_ORDER_BIG_ENDIAN); } /* look for optional content chunk */ - if (strcmp(chunk, "CONT") == 0 && chunk_length == 4 + 8 * 3 * 3) + if (strcmp(chunk, "CONT") == 0 && + chunk_length == 4 + MAX_ELEMENT_CONTENTS * 3 * 3) { fgetc(file); - MampferMax = fgetc(file); + level.num_yam_contents = fgetc(file); fgetc(file); fgetc(file); - for(i=0; i<8; i++) + 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 != TAPE_HEADER_SIZE) { Error(ERR_WARN, "wrong 'HEAD' chunk of tape file '%s'", filename); @@ -640,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) @@ -680,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) { @@ -756,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); @@ -789,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; + putFileChunk(file, "HEAD", TAPE_HEADER_SIZE, BYTE_ORDER_BIG_ENDIAN); - 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); - - 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