X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ffiles.c;h=7e1ad30bc6dafa99c5a9478dc6929c6a34b41678;hb=48542a06103232c408ce6250f5bc2d9add00f233;hp=71d01e945fd9f35c3d38ee7736d2e38e2f1d44a0;hpb=41364660abbcb81a83f5018be3655352ecdf1ac9;p=rocksndiamonds.git diff --git a/src/files.c b/src/files.c index 71d01e94..7e1ad30b 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 17 /* 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 */ @@ -116,11 +116,6 @@ static void SaveUserLevelInfo(); /* for 'InitUserLevelDir()' */ static char *getSetupLine(char *, int); /* for 'SaveUserLevelInfo()' */ -static char *getGlobalDataDir() -{ - return GAME_DIR; -} - char *getUserDataDir() { static char *userdata_dir = NULL; @@ -178,7 +173,7 @@ static char *getTapeDir(char *level_subdir) static char *getScoreDir(char *level_subdir) { static char *score_dir = NULL; - char *data_dir = getGlobalDataDir(); + char *data_dir = options.rw_base_directory; char *score_subdir = SCORES_DIRECTORY; if (score_dir) @@ -275,27 +270,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,12 +282,13 @@ 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; 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); @@ -417,36 +392,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) { - 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) @@ -463,23 +439,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); @@ -637,12 +614,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) @@ -677,10 +651,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) { @@ -753,7 +724,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); @@ -786,42 +756,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; iname = getStringCopy(ANONYMOUS_NAME); + ldi->name_short = NULL; ldi->author = getStringCopy(ANONYMOUS_NAME); ldi->levels = 0; ldi->first_level = 0; @@ -1515,6 +1464,10 @@ static int LoadLevelInfoFromLevelDir(char *level_directory, int start_entry) setSetupInfo(i, getTokenValue(setup_file_list, token_info[i].text)); leveldir[current_entry] = ldi; + if (leveldir[current_entry].name_short == NULL) + leveldir[current_entry].name_short = + getStringCopy(leveldir[current_entry].name); + leveldir[current_entry].filename = getStringCopy(dir_entry->d_name); leveldir[current_entry].last_level = leveldir[current_entry].first_level + @@ -1585,6 +1538,7 @@ static void SaveUserLevelInfo() setLevelDirInfoToDefaults(&ldi); ldi.name = getLoginName(); + ldi.name_short = getLoginName(); ldi.author = getRealName(); ldi.levels = 100; ldi.first_level = 1; @@ -1625,11 +1579,11 @@ void LoadSetup() freeSetupFileList(setup_file_list); /* needed to work around problems with fixed length strings */ - if (strlen(setup.player_name) >= MAX_NAMELEN) - setup.player_name[MAX_NAMELEN - 1] = '\0'; - else if (strlen(setup.player_name) < MAX_NAMELEN - 1) + if (strlen(setup.player_name) > MAX_PLAYER_NAME_LEN) + setup.player_name[MAX_PLAYER_NAME_LEN] = '\0'; + else if (strlen(setup.player_name) < MAX_PLAYER_NAME_LEN) { - char *new_name = checked_malloc(MAX_NAMELEN); + char *new_name = checked_malloc(MAX_PLAYER_NAME_LEN + 1); strcpy(new_name, setup.player_name); free(setup.player_name);