X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Ffiles.c;h=71d01e945fd9f35c3d38ee7736d2e38e2f1d44a0;hp=77585d6cda98510c79a1506c677c6b3b686c107b;hb=3ae3dff29ac1a6022b1e5af414ba2c99391148c8;hpb=efd80a08bd5de21956872a615f1d03f2dd90cee2 diff --git a/src/files.c b/src/files.c index 77585d6c..71d01e94 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 */ @@ -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()' */ @@ -270,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; @@ -287,8 +313,12 @@ static void setLevelInfoToDefaults() level.dauer_sieb = 10; level.dauer_ablenk = 10; level.amoebe_inhalt = EL_DIAMANT; + level.double_speed = 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); if (strcmp(chunk, "HEAD") || chunk_length != LEVEL_HEADER_SIZE) { Error(ERR_WARN, "wrong 'HEAD' chunk of level file '%s'", filename); @@ -397,7 +422,7 @@ void LoadLevel(int level_nr) 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> 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); @@ -524,18 +549,17 @@ void SaveLevel(int level_nr) fputc(level.dauer_sieb, file); fputc(level.dauer_ablenk, file); fputc(level.amoebe_inhalt, file); + fputc((level.double_speed ? 1 : 0), 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); @@ -547,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; y