X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ffiles.c;h=1321fe9cc7be00bc3511c13887a56af1a331aef4;hb=f857fec3082c785b0dd271b6ad1b7642a2ed4e65;hp=15264d2d4e3a6eeea4f12a875469f3496d01dc16;hpb=ea933dd51bfca7ddcc6b75465476cce57afd1682;p=rocksndiamonds.git diff --git a/src/files.c b/src/files.c index 15264d2d..1321fe9c 100644 --- a/src/files.c +++ b/src/files.c @@ -17,6 +17,7 @@ #include "libgame/libgame.h" #include "files.h" +#include "init.h" #include "tools.h" #include "tape.h" @@ -44,7 +45,7 @@ static void setLevelInfoToDefaults() { - int i, x, y; + int i, j, x, y; level.file_version = FILE_VERSION_ACTUAL; level.game_version = GAME_VERSION_ACTUAL; @@ -95,7 +96,17 @@ static void setLevelInfoToDefaults() Ur[STD_LEV_FIELDX-1][STD_LEV_FIELDY-1] = EL_EXIT_CLOSED; for (i=0; i < NUM_CUSTOM_ELEMENTS; i++) - Properties1[EL_CUSTOM_START + i] = EP_BITMASK_DEFAULT; + { + level.custom_element_successor[i] = EL_EMPTY_SPACE; + + /* start with no properties at all */ +#if 1 + for (j=0; j < NUM_EP_BITFIELDS; j++) + Properties[EL_CUSTOM_START + i][j] = EP_BITMASK_DEFAULT; +#else + Properties[EL_CUSTOM_START + i][EP_BITFIELD_BASE] = EP_BITMASK_DEFAULT; +#endif + } BorderElement = EL_STEELWALL; @@ -334,7 +345,34 @@ static int LoadLevel_CUS1(FILE *file, int chunk_size, struct LevelInfo *level) int properties = getFile32BitBE(file); if (IS_CUSTOM_ELEMENT(element)) - Properties1[element] = properties; + Properties[element][EP_BITFIELD_BASE] = properties; + else + Error(ERR_WARN, "invalid custom element number %d", element); + } + + return chunk_size; +} + +static int LoadLevel_CUS2(FILE *file, int chunk_size, struct LevelInfo *level) +{ + int num_changed_custom_elements = getFile16BitBE(file); + int chunk_size_expected = 2 + num_changed_custom_elements * 4; + int i; + + if (chunk_size_expected != chunk_size) + { + ReadUnusedBytesFromFile(file, chunk_size - 2); + return chunk_size_expected; + } + + for (i=0; i < num_changed_custom_elements; i++) + { + int element = getFile16BitBE(file); + int custom_element_successor = getFile16BitBE(file); + int i = element - EL_CUSTOM_START; + + if (IS_CUSTOM_ELEMENT(element)) + level->custom_element_successor[i] = custom_element_successor; else Error(ERR_WARN, "invalid custom element number %d", element); } @@ -421,6 +459,7 @@ void LoadLevelFromFilename(char *filename) { "CONT", -1, LoadLevel_CONT }, { "CNT2", LEVEL_CHUNK_CNT2_SIZE, LoadLevel_CNT2 }, { "CUS1", -1, LoadLevel_CUS1 }, + { "CUS2", -1, LoadLevel_CUS2 }, { NULL, 0, NULL } }; @@ -515,6 +554,32 @@ void LoadLevelFromFilename(char *filename) level.em_slippery_gems = TRUE; } + /* map some elements which have changed in newer versions */ + if (level.game_version <= VERSION_IDENT(2,2,0)) + { + int x, y; + + /* map game font elements */ + for(y=0; ycustom_element_successor[i] != EL_EMPTY_SPACE) + { + if (check < num_changed_custom_elements) + { + putFile16BitBE(file, element); + putFile16BitBE(file, level->custom_element_successor[i]); + } + + check++; + } + } + + if (check != num_changed_custom_elements) /* should not happen */ + Error(ERR_WARN, "inconsistent number of custom element successors"); +} + void SaveLevel(int level_nr) { char *filename = getLevelFilename(level_nr); int body_chunk_size; - int num_changed_custom_elements = 0; + int num_changed_custom_elements1 = 0; + int num_changed_custom_elements2 = 0; int i, x, y; FILE *file; @@ -727,8 +822,13 @@ void SaveLevel(int level_nr) /* check for non-standard custom elements and calculate "CUS1" chunk size */ for (i=0; i < NUM_CUSTOM_ELEMENTS; i++) - if (Properties1[EL_CUSTOM_START + i] != EP_BITMASK_DEFAULT) - num_changed_custom_elements++; + if (Properties[EL_CUSTOM_START +i][EP_BITFIELD_BASE] != EP_BITMASK_DEFAULT) + num_changed_custom_elements1++; + + /* check for non-standard custom elements and calculate "CUS2" chunk size */ + for (i=0; i < NUM_CUSTOM_ELEMENTS; i++) + if (level.custom_element_successor[i] != EL_EMPTY_SPACE) + num_changed_custom_elements2++; putFileChunkBE(file, "RND1", CHUNK_SIZE_UNDEFINED); putFileChunkBE(file, "CAVE", CHUNK_SIZE_NONE); @@ -758,10 +858,16 @@ void SaveLevel(int level_nr) SaveLevel_CNT2(file, &level, EL_BD_AMOEBA); } - if (num_changed_custom_elements > 0) + if (num_changed_custom_elements1 > 0) { - putFileChunkBE(file, "CUS1", 2 + num_changed_custom_elements * 6); - SaveLevel_CUS1(file, num_changed_custom_elements); + putFileChunkBE(file, "CUS1", 2 + num_changed_custom_elements1 * 6); + SaveLevel_CUS1(file, &level, num_changed_custom_elements1); + } + + if (num_changed_custom_elements2 > 0) + { + putFileChunkBE(file, "CUS2", 2 + num_changed_custom_elements2 * 4); + SaveLevel_CUS2(file, &level, num_changed_custom_elements2); } fclose(file); @@ -1601,32 +1707,32 @@ static void setSetupInfoToDefaults(struct SetupInfo *si) si->options.verbose = FALSE; } -static void decodeSetupFileList(struct SetupFileList *setup_file_list) +static void decodeSetupFileHash(SetupFileHash *setup_file_hash) { int i, pnr; - if (!setup_file_list) + if (!setup_file_hash) return; /* global setup */ si = setup; for (i=0; i