From: Holger Schemel Date: Mon, 18 Mar 2002 00:33:22 +0000 (+0100) Subject: rnd-20020318-2-src X-Git-Tag: 2.0.1^2~4 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=d3e8110e6f4f9fb2f92ecf7c7842fbf56c8f2e01;p=rocksndiamonds.git rnd-20020318-2-src --- diff --git a/src/files.c b/src/files.c index 7937c948..2080cd61 100644 --- a/src/files.c +++ b/src/files.c @@ -36,18 +36,12 @@ #define TAPE_HEADER_UNUSED 7 /* unused tape header bytes */ /* file identifier strings */ -#define LEVEL_COOKIE "ROCKSNDIAMONDS_LEVEL_FILE_VERSION_2.0" +#define LEVEL_COOKIE_TMPL "ROCKSNDIAMONDS_LEVEL_FILE_VERSION_x.x" +#define TAPE_COOKIE_TMPL "ROCKSNDIAMONDS_TAPE_FILE_VERSION_x.x" #define SCORE_COOKIE "ROCKSNDIAMONDS_SCORE_FILE_VERSION_1.2" -#define TAPE_COOKIE "ROCKSNDIAMONDS_TAPE_FILE_VERSION_2.0" #define SETUP_COOKIE "ROCKSNDIAMONDS_SETUP_FILE_VERSION_1.2" #define LEVELSETUP_COOKIE "ROCKSNDIAMONDS_LEVELSETUP_FILE_VERSION_1.2" #define LEVELINFO_COOKIE "ROCKSNDIAMONDS_LEVELINFO_FILE_VERSION_1.2" -/* old file identifiers for backward compatibility */ -#define LEVEL_COOKIE_10 "ROCKSNDIAMONDS_LEVEL_FILE_VERSION_1.0" -#define LEVEL_COOKIE_12 "ROCKSNDIAMONDS_LEVEL_FILE_VERSION_1.2" -#define LEVEL_COOKIE_14 "ROCKSNDIAMONDS_LEVEL_FILE_VERSION_1.4" -#define TAPE_COOKIE_10 "ROCKSNDIAMONDS_LEVELREC_FILE_VERSION_1.0" -#define TAPE_COOKIE_12 "ROCKSNDIAMONDS_TAPE_FILE_VERSION_1.2" /* file names and filename extensions */ #if !defined(PLATFORM_MSDOS) @@ -68,39 +62,6 @@ #define SCOREFILE_EXTENSION "sco" #endif -#if 0 -#if defined(PLATFORM_WIN32) -#ifndef S_IRGRP -#define S_IRGRP S_IRUSR -#endif -#ifndef S_IROTH -#define S_IROTH S_IRUSR -#endif -#ifndef S_IWGRP -#define S_IWGRP S_IWUSR -#endif -#ifndef S_IWOTH -#define S_IWOTH S_IWUSR -#endif -#ifndef S_IXGRP -#define S_IXGRP S_IXUSR -#endif -#ifndef S_IXOTH -#define S_IXOTH S_IXUSR -#endif -#endif /* PLATFORM_WIN32 */ - -/* file permissions for newly written files */ -#define MODE_R_ALL (S_IRUSR | S_IRGRP | S_IROTH) -#define MODE_W_ALL (S_IWUSR | S_IWGRP | S_IWOTH) -#define MODE_X_ALL (S_IXUSR | S_IXGRP | S_IXOTH) - -#define LEVEL_PERMS (MODE_R_ALL | MODE_W_ALL) -#define SCORE_PERMS LEVEL_PERMS -#define TAPE_PERMS LEVEL_PERMS -#define SETUP_PERMS LEVEL_PERMS -#endif - /* sort priorities of level series (also used as level series classes) */ #define LEVELCLASS_TUTORIAL_START 10 #define LEVELCLASS_TUTORIAL_END 99 @@ -560,203 +521,6 @@ static int checkLevelElement(int element) return element; } -void OLD_LoadLevel(int level_nr) -{ - int i, x, y; - char *filename = getLevelFilename(level_nr); - char cookie[MAX_LINE_LEN]; - char chunk_name[CHUNK_ID_LEN + 1]; - boolean encoding_16bit = FALSE; /* default: maximal 256 elements */ - int file_version = FILE_VERSION_ACTUAL; - int chunk_size; - FILE *file; - - /* always start with reliable default values */ - setLevelInfoToDefaults(); - - if (!(file = fopen(filename, MODE_READ))) - { - Error(ERR_WARN, "cannot read level '%s' - creating new level", filename); - return; - } - - /* check file identifier */ - fgets(cookie, MAX_LINE_LEN, file); - if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n') - cookie[strlen(cookie) - 1] = '\0'; - -#if 0 - if (strcmp(cookie, LEVEL_COOKIE_10) == 0) /* old 1.0 level format */ - file_version = FILE_VERSION_1_0; - else if (strcmp(cookie, LEVEL_COOKIE_12) == 0)/* 1.2 (8 bit) level format */ - file_version = FILE_VERSION_1_2; - else if (strcmp(cookie, LEVEL_COOKIE) != 0) /* unknown level format */ - { - Error(ERR_WARN, "wrong file identifier of level file '%s'", filename); - fclose(file); - return; - } -#else - if (!checkCookieString(cookie, LEVEL_COOKIE)) /* unknown file format */ - { - Error(ERR_WARN, "unknown format of level file '%s'", filename); - fclose(file); - return; - } - - file_version = getFileVersionFromCookieString(cookie); -#endif - - level.file_version = file_version; - - /* read chunk "HEAD" */ - if (file_version >= FILE_VERSION_1_2) - { - getFileChunk(file, chunk_name, &chunk_size, BYTE_ORDER_BIG_ENDIAN); - if (strcmp(chunk_name, "HEAD") || chunk_size != LEVEL_HEADER_SIZE) - { - Error(ERR_WARN, "wrong 'HEAD' chunk of level file '%s'", filename); - fclose(file); - return; - } - } - - lev_fieldx = level.fieldx = fgetc(file); - lev_fieldy = level.fieldy = 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_name, &chunk_size, BYTE_ORDER_BIG_ENDIAN); - - /* look for optional author chunk */ - if (strcmp(chunk_name, "AUTH") == 0 && chunk_size == MAX_LEVEL_AUTHOR_LEN) - { - for(i=0; i MAX_ELEMENT_CONTENTS) - { -#if DEBUG - printf("WARNING: num_yam_contents == %d (corrected)\n", - level.num_yam_contents); -#endif - level.num_yam_contents = STD_ELEMENT_CONTENTS; - } - - for(i=0; ifile_version), &(level->game_version)); @@ -942,26 +706,6 @@ void LoadLevel(int level_nr) return; } -#if 0 - /* check file identifier */ - fgets(cookie, MAX_LINE_LEN, file); - if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n') - cookie[strlen(cookie) - 1] = '\0'; - - if (!checkCookieString(cookie, LEVEL_COOKIE)) /* unknown file format */ - { - Error(ERR_WARN, "unknown format of level file '%s'", filename); - fclose(file); - return; - } - - if ((level.file_version = getFileVersionFromCookieString(cookie)) == -1) - { - Error(ERR_WARN, "unsupported version of level file '%s'", filename); - fclose(file); - return; - } -#else getFileChunk(file, chunk_name, NULL, BYTE_ORDER_BIG_ENDIAN); if (strcmp(chunk_name, "RND1") == 0) { @@ -982,7 +726,7 @@ void LoadLevel(int level_nr) if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n') cookie[strlen(cookie) - 1] = '\0'; - if (!checkCookieString(cookie, LEVEL_COOKIE)) /* unknown file format */ + if (!checkCookieString(cookie, LEVEL_COOKIE_TMPL)) { Error(ERR_WARN, "unknown format of level file '%s'", filename); fclose(file); @@ -996,7 +740,6 @@ void LoadLevel(int level_nr) return; } } -#endif if (level.file_version < FILE_VERSION_1_2) { @@ -1090,106 +833,6 @@ void LoadLevel(int level_nr) SetBorderElement(); } -void OLD_SaveLevel(int level_nr) -{ - int i, x, y; - char *filename = getLevelFilename(level_nr); -#if 0 - boolean encoding_16bit_amoeba = FALSE; - boolean encoding_16bit_yamyam = FALSE; -#endif - boolean encoding_16bit = FALSE; /* default: only 8-bit elements */ - char *oldest_possible_cookie; - FILE *file; - - if (!(file = fopen(filename, MODE_WRITE))) - { - Error(ERR_WARN, "cannot save level file '%s'", filename); - return; - } - - /* check yam content for 16-bit elements */ - for(i=0; i 255) - encoding_16bit = TRUE; - - /* check level field for 16-bit elements */ - for(y=0; y 255) - encoding_16bit = TRUE; - - oldest_possible_cookie = (encoding_16bit ? LEVEL_COOKIE : LEVEL_COOKIE_12); - - fputs(oldest_possible_cookie, file); /* file identifier */ - fputc('\n', file); - - putFileChunk(file, "HEAD", LEVEL_HEADER_SIZE, BYTE_ORDER_BIG_ENDIAN); - - fputc(level.fieldx, file); - fputc(level.fieldy, file); - - putFile16BitInteger(file, level.time, BYTE_ORDER_BIG_ENDIAN); - putFile16BitInteger(file, level.gems_needed, BYTE_ORDER_BIG_ENDIAN); - - for(i=0; i 0 && cookie[strlen(cookie) - 1] == '\n') - cookie[strlen(cookie) - 1] = '\0'; - -#if 0 - if (strcmp(cookie, TAPE_COOKIE_10) == 0) /* old 1.0 tape format */ - file_version = FILE_VERSION_1_0; - else if (strcmp(cookie, TAPE_COOKIE) != 0) /* unknown tape format */ - { - Error(ERR_WARN, "wrong file identifier of tape file '%s'", filename); - fclose(file); - return; - } -#else - if (!checkCookieString(cookie, TAPE_COOKIE)) /* unknown file format */ - { - Error(ERR_WARN, "unknown format of tape file '%s'", filename); - fclose(file); - return; - } - - file_version = getFileVersionFromCookieString(cookie); -#endif - - tape.file_version = file_version; - tape.game_version = file_version; - - /* read chunk "HEAD" */ - if (file_version >= FILE_VERSION_1_2) - { - getFileChunk(file, chunk_name, &chunk_size, BYTE_ORDER_BIG_ENDIAN); - if (strcmp(chunk_name, "HEAD") || chunk_size != TAPE_HEADER_SIZE) - { - Error(ERR_WARN, "wrong 'HEAD' chunk of tape file '%s'", filename); - fclose(file); - return; - } - } - - 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) - { - byte store_participating_players = fgetc(file); - - for(i=0; i= FILE_VERSION_1_2) - { - getFileChunk(file, chunk_name, &chunk_size, BYTE_ORDER_BIG_ENDIAN); - if (strcmp(chunk_name, "BODY") || - chunk_size != (num_participating_players + 1) * tape.length) - { - Error(ERR_WARN, "wrong 'BODY' chunk of tape file '%s'", filename); - fclose(file); - return; - } - } - -#if DEBUG - printf("\nTAPE OF LEVEL %d\n", level_nr); -#endif - - for(i=0; i= MAX_TAPELEN) - break; - - for(j=0; j' : ' '), - (x & JOY_UP ? '^' : ' '), - (x & JOY_DOWN ? 'v' : ' '), - (x & JOY_BUTTON_1 ? '1' : ' '), - (x & JOY_BUTTON_2 ? '2' : ' ')); - } -#endif - - } - - tape.pos[i].delay = fgetc(file); - -#if DEBUG - printf("[%03d]\n", tape.pos[i].delay); -#endif - - if (file_version == FILE_VERSION_1_0) - { - /* eliminate possible diagonal moves in old tapes */ - /* this is only for backward compatibility */ - - byte joy_dir[4] = { JOY_LEFT, JOY_RIGHT, JOY_UP, JOY_DOWN }; - byte action = tape.pos[i].action[0]; - int k, num_moves = 0; - - for (k=0; k<4; k++) - { - if (action & joy_dir[k]) - { - tape.pos[i + num_moves].action[0] = joy_dir[k]; - if (num_moves > 0) - tape.pos[i + num_moves].delay = 0; - num_moves++; - } - } - - if (num_moves > 1) - { - num_moves--; - i += num_moves; - tape.length += num_moves; - } - } - else if (file_version < FILE_VERSION_2_0) - { - if (tape.pos[i].delay > 1) - { - /* action part */ - tape.pos[i + 1] = tape.pos[i]; - tape.pos[i + 1].delay = 1; - - /* delay part */ - for(j=0; jfile_version), &(tape->game_version)); @@ -1770,26 +1188,6 @@ void LoadTape(int level_nr) if (!(file = fopen(filename, MODE_READ))) return; -#if 0 - /* check file identifier */ - fgets(cookie, MAX_LINE_LEN, file); - if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n') - cookie[strlen(cookie) - 1] = '\0'; - - if (!checkCookieString(cookie, TAPE_COOKIE)) /* unknown file format */ - { - Error(ERR_WARN, "unknown format of tape file '%s'", filename); - fclose(file); - return; - } - - if ((level.file_version = getFileVersionFromCookieString(cookie)) == -1) - { - Error(ERR_WARN, "unsupported version of level file '%s'", filename); - fclose(file); - return; - } -#else getFileChunk(file, chunk_name, NULL, BYTE_ORDER_BIG_ENDIAN); if (strcmp(chunk_name, "RND1") == 0) { @@ -1810,7 +1208,7 @@ void LoadTape(int level_nr) if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n') cookie[strlen(cookie) - 1] = '\0'; - if (!checkCookieString(cookie, TAPE_COOKIE)) /* unknown file format */ + if (!checkCookieString(cookie, TAPE_COOKIE_TMPL)) { Error(ERR_WARN, "unknown format of tape file '%s'", filename); fclose(file); @@ -1824,7 +1222,6 @@ void LoadTape(int level_nr) return; } } -#endif tape.game_version = tape.file_version; @@ -1894,81 +1291,6 @@ void LoadTape(int level_nr) tape.length_seconds = GetTapeLength(); } -void OLD_SaveTape(int level_nr) -{ - int i; - char *filename = getTapeFilename(level_nr); - FILE *file; - boolean new_tape = TRUE; - byte store_participating_players; - int num_participating_players; - - InitTapeDirectory(leveldir_current->filename); - - /* if a tape still exists, ask to overwrite it */ - if (access(filename, F_OK) == 0) - { - new_tape = FALSE; - if (!Request("Replace old tape ?", REQ_ASK)) - return; - } - - /* count number of players and set corresponding bits for compact storage */ - store_participating_players = 0; - num_participating_players = 0; - for(i=0; i 0 && cookie[strlen(cookie) - 1] == '\n') cookie[strlen(cookie) - 1] = '\0'; -#if 0 - if (strcmp(cookie, SCORE_COOKIE) != 0) - { - Error(ERR_WARN, "wrong file identifier of score file '%s'", filename); - fclose(file); - return; - } -#else - if (!checkCookieString(cookie, SCORE_COOKIE)) /* unknown file format */ + if (!checkCookieString(cookie, SCORE_COOKIE)) { Error(ERR_WARN, "unknown format of score file '%s'", filename); fclose(file); return; } -#endif for(i=0; i