X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ffiles.c;h=aa6ce2595cd11b718e80c263d58f0e806762f455;hb=1847b9f73a9189758958980912c005dc289e1b08;hp=44d0dbbfe08b4e71e4ab870d761022d512d5c24f;hpb=db89d31c2a430be3b7c3eb19b779c9347efa9ba5;p=rocksndiamonds.git diff --git a/src/files.c b/src/files.c index 44d0dbbf..aa6ce259 100644 --- a/src/files.c +++ b/src/files.c @@ -27,9 +27,14 @@ #define CHUNK_ID_LEN 4 /* IFF style chunk id length */ #define CHUNK_SIZE_UNDEFINED 0 /* undefined chunk size == 0 */ #define CHUNK_SIZE_NONE -1 /* do not write chunk size */ -#define FILE_VERS_CHUNK_SIZE 8 /* size of file version chunk */ -#define LEVEL_HEADER_SIZE 80 /* size of level file header */ -#define LEVEL_HEADER_UNUSED 0 /* unused level header bytes */ + +#define LEVEL_CHUNK_NAME_SIZE MAX_LEVEL_NAME_LEN +#define LEVEL_CHUNK_AUTH_SIZE MAX_LEVEL_AUTHOR_LEN + +#define LEVEL_CHUNK_VERS_SIZE 8 /* size of file version chunk */ +#define LEVEL_CHUNK_DATE_SIZE 4 /* size of file date chunk */ +#define LEVEL_CHUNK_HEAD_SIZE 80 /* size of level file header */ +#define LEVEL_CHUNK_HEAD_UNUSED 0 /* unused level header bytes */ #define LEVEL_CHUNK_CNT2_SIZE 160 /* size of level CNT2 chunk */ #define LEVEL_CHUNK_CNT2_UNUSED 11 /* unused CNT2 chunk bytes */ #define LEVEL_CHUNK_CNT3_HEADER 16 /* size of level CNT3 header */ @@ -37,8 +42,20 @@ #define LEVEL_CPART_CUS3_SIZE 134 /* size of CUS3 chunk part */ #define LEVEL_CPART_CUS3_UNUSED 15 /* unused CUS3 bytes / part */ #define LEVEL_CHUNK_GRP1_SIZE 74 /* size of level GRP1 chunk */ -#define TAPE_HEADER_SIZE 20 /* size of tape file header */ -#define TAPE_HEADER_UNUSED 3 /* unused tape header bytes */ + +/* (element number, number of change pages, change page number) */ +#define LEVEL_CHUNK_CUSX_UNCHANGED (2 + (1 + 1) + (1 + 1)) + +/* (element number only) */ +#define LEVEL_CHUNK_GRPX_UNCHANGED 2 +#define LEVEL_CHUNK_NOTE_UNCHANGED 2 + +/* (nothing at all if unchanged) */ +#define LEVEL_CHUNK_ELEM_UNCHANGED 0 + +#define TAPE_CHUNK_VERS_SIZE 8 /* size of file version chunk */ +#define TAPE_CHUNK_HEAD_SIZE 20 /* size of tape file header */ +#define TAPE_CHUNK_HEAD_UNUSED 3 /* unused tape header bytes */ #define LEVEL_CHUNK_CNT3_SIZE(x) (LEVEL_CHUNK_CNT3_HEADER + (x)) #define LEVEL_CHUNK_CUS3_SIZE(x) (2 + (x) * LEVEL_CPART_CUS3_SIZE) @@ -49,7 +66,12 @@ #define TAPE_COOKIE_TMPL "ROCKSNDIAMONDS_TAPE_FILE_VERSION_x.x" #define SCORE_COOKIE "ROCKSNDIAMONDS_SCORE_FILE_VERSION_1.2" -/* values for "CONF" chunk */ +/* values for deciding when (not) to save configuration data */ +#define SAVE_CONF_NEVER 0 +#define SAVE_CONF_ALWAYS 1 +#define SAVE_CONF_WHEN_CHANGED -1 + +/* values for chunks using micro chunks */ #define CONF_MASK_1_BYTE 0x00 #define CONF_MASK_2_BYTE 0x40 #define CONF_MASK_4_BYTE 0x80 @@ -63,69 +85,16 @@ #define CONF_VALUE_4_BYTE(x) (CONF_MASK_4_BYTE | (x)) #define CONF_VALUE_MULTI_BYTES(x) (CONF_MASK_MULTI_BYTES | (x)) -/* a sequence of configuration values can be terminated by this value */ -#define CONF_LAST_ENTRY CONF_VALUE_1_BYTE(0) - /* these definitions are just for convenience of use and readability */ #define CONF_VALUE_8_BIT(x) CONF_VALUE_1_BYTE(x) #define CONF_VALUE_16_BIT(x) CONF_VALUE_2_BYTE(x) #define CONF_VALUE_32_BIT(x) CONF_VALUE_4_BYTE(x) #define CONF_VALUE_BYTES(x) CONF_VALUE_MULTI_BYTES(x) -#define CONF_VALUE_INTEGER_1 CONF_VALUE_8_BIT(1) -#define CONF_VALUE_INTEGER_2 CONF_VALUE_8_BIT(2) -#define CONF_VALUE_INTEGER_3 CONF_VALUE_8_BIT(3) -#define CONF_VALUE_INTEGER_4 CONF_VALUE_8_BIT(4) -#define CONF_VALUE_INTEGER_5 CONF_VALUE_8_BIT(5) -#define CONF_VALUE_INTEGER_6 CONF_VALUE_8_BIT(6) -#define CONF_VALUE_INTEGER_7 CONF_VALUE_8_BIT(7) -#define CONF_VALUE_INTEGER_8 CONF_VALUE_8_BIT(8) -#define CONF_VALUE_BOOLEAN_1 CONF_VALUE_8_BIT(9) -#define CONF_VALUE_BOOLEAN_2 CONF_VALUE_8_BIT(10) -#define CONF_VALUE_BOOLEAN_3 CONF_VALUE_8_BIT(11) -#define CONF_VALUE_BOOLEAN_4 CONF_VALUE_8_BIT(12) -#define CONF_VALUE_BOOLEAN_5 CONF_VALUE_8_BIT(13) -#define CONF_VALUE_BOOLEAN_6 CONF_VALUE_8_BIT(14) -#define CONF_VALUE_BOOLEAN_7 CONF_VALUE_8_BIT(15) -#define CONF_VALUE_BOOLEAN_8 CONF_VALUE_8_BIT(16) - -#define CONF_VALUE_ELEMENT_1 CONF_VALUE_16_BIT(1) -#define CONF_VALUE_ELEMENT_2 CONF_VALUE_16_BIT(2) -#define CONF_VALUE_ELEMENT_3 CONF_VALUE_16_BIT(3) -#define CONF_VALUE_ELEMENT_4 CONF_VALUE_16_BIT(4) -#define CONF_VALUE_ELEMENT_5 CONF_VALUE_16_BIT(5) -#define CONF_VALUE_ELEMENT_6 CONF_VALUE_16_BIT(6) -#define CONF_VALUE_ELEMENT_7 CONF_VALUE_16_BIT(7) -#define CONF_VALUE_ELEMENT_8 CONF_VALUE_16_BIT(8) - -#if 0 -#define CONF_VALUE_ELEMENTS CONF_VALUE_BYTES(1) -#define CONF_VALUE_CONTENTS CONF_VALUE_BYTES(2) -#endif - -#if 0 -#define CONF_VALUE_INTEGER(x) ((x) >= CONF_VALUE_INTEGER_1 && \ - (x) <= CONF_VALUE_INTEGER_8) - -#define CONF_VALUE_BOOLEAN(x) ((x) >= CONF_VALUE_BOOLEAN_1 && \ - (x) <= CONF_VALUE_BOOLEAN_8) -#endif - #define CONF_VALUE_NUM_BYTES(x) ((x) == CONF_MASK_1_BYTE ? 1 : \ (x) == CONF_MASK_2_BYTE ? 2 : \ (x) == CONF_MASK_4_BYTE ? 4 : 0) -#if 0 -#define CONF_CONTENT_NUM_ELEMENTS (3 * 3) -#define CONF_CONTENT_NUM_BYTES (CONF_CONTENT_NUM_ELEMENTS * 2) -#define CONF_ELEMENT_NUM_BYTES (2) - -#define CONF_ENTITY_NUM_BYTES(t) ((t) == CONF_VALUE_ELEMENTS ? \ - CONF_ELEMENT_NUM_BYTES : \ - (t) == CONF_VALUE_CONTENTS ? \ - CONF_CONTENT_NUM_BYTES : 1) -#endif - #define CONF_CONTENT_NUM_ELEMENTS (3 * 3) #define CONF_CONTENT_NUM_BYTES (CONF_CONTENT_NUM_ELEMENTS * 2) #define CONF_ELEMENT_NUM_BYTES (2) @@ -148,26 +117,25 @@ #define CONF_CONTENTS_ELEMENT(b,c,x,y) ((b[CONF_CONTENT_BYTE_POS(c,x,y)]<< 8)|\ (b[CONF_CONTENT_BYTE_POS(c,x,y) + 1])) -#if 0 -static void LoadLevel_InitPlayfield(struct LevelInfo *, char *); -#endif - /* temporary variables used to store pointers to structure members */ static struct LevelInfo li; static struct ElementInfo xx_ei, yy_ei; static struct ElementChangeInfo xx_change; static struct ElementGroupInfo xx_group; +static struct EnvelopeInfo xx_envelope; static unsigned int xx_event_bits[NUM_CE_BITFIELDS]; static char xx_default_description[MAX_ELEMENT_NAME_LEN + 1]; -static int xx_default_description_length; static int xx_num_contents; static int xx_current_change_page; +static char xx_default_string_empty[1] = ""; +static int xx_string_length_unused; -struct ElementFileConfig +struct LevelFileConfigInfo { int element; /* element for which data is to be stored */ - int data_type; /* internal type of data */ - int conf_type; /* special type identifier stored in file */ + int save_type; /* save data always, never or when changed */ + int data_type; /* data type (used internally, not stored) */ + int conf_type; /* micro chunk identifier (stored in file) */ /* (mandatory) */ void *value; /* variable that holds the data to be stored */ @@ -181,319 +149,624 @@ struct ElementFileConfig char *default_string; /* optional default string for string data */ }; -static struct ElementFileConfig element_conf[] = +static struct LevelFileConfigInfo chunk_config_INFO[] = { - /* ---------- 1-byte values ---------------------------------------------- */ + /* ---------- values not related to single elements ----------------------- */ { - EL_EMC_ANDROID, - TYPE_INTEGER, CONF_VALUE_INTEGER_1, - &li.android_move_time, 10 + -1, SAVE_CONF_ALWAYS, + TYPE_INTEGER, CONF_VALUE_8_BIT(1), + &li.game_engine_type, GAME_ENGINE_TYPE_RND }, + { - EL_EMC_ANDROID, - TYPE_INTEGER, CONF_VALUE_INTEGER_2, - &li.android_clone_time, 10 + -1, SAVE_CONF_ALWAYS, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.fieldx, STD_LEV_FIELDX }, { - EL_EMC_LENSES, - TYPE_INTEGER, CONF_VALUE_INTEGER_1, - &li.lenses_score, 10 + -1, SAVE_CONF_ALWAYS, + TYPE_INTEGER, CONF_VALUE_16_BIT(2), + &li.fieldy, STD_LEV_FIELDY }, + { - EL_EMC_LENSES, - TYPE_INTEGER, CONF_VALUE_INTEGER_2, - &li.lenses_time, 10 + -1, SAVE_CONF_ALWAYS, + TYPE_INTEGER, CONF_VALUE_16_BIT(3), + &li.time, 100 }, + { - EL_EMC_MAGNIFIER, - TYPE_INTEGER, CONF_VALUE_INTEGER_1, - &li.magnify_score, 10 + -1, SAVE_CONF_ALWAYS, + TYPE_INTEGER, CONF_VALUE_16_BIT(4), + &li.gems_needed, 0 }, + { - EL_EMC_MAGNIFIER, - TYPE_INTEGER, CONF_VALUE_INTEGER_2, - &li.magnify_time, 10 + -1, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(2), + &li.use_step_counter, FALSE }, + { - EL_ROBOT, - TYPE_INTEGER, CONF_VALUE_INTEGER_1, - &li.slurp_score, 10 + -1, -1, + TYPE_BITFIELD, CONF_VALUE_8_BIT(4), + &li.wind_direction_initial, MV_NONE }, + { - EL_GAME_OF_LIFE, - TYPE_INTEGER, CONF_VALUE_INTEGER_1, - &li.game_of_life[0], 2 + -1, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(5), + &li.em_slippery_gems, FALSE }, + { - EL_GAME_OF_LIFE, - TYPE_INTEGER, CONF_VALUE_INTEGER_2, - &li.game_of_life[1], 3 + -1, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(6), + &li.use_custom_template, FALSE }, + { - EL_GAME_OF_LIFE, - TYPE_INTEGER, CONF_VALUE_INTEGER_3, - &li.game_of_life[2], 3 + -1, -1, + TYPE_BITFIELD, CONF_VALUE_32_BIT(1), + &li.can_move_into_acid_bits, ~0 /* default: everything can */ }, + { - EL_GAME_OF_LIFE, - TYPE_INTEGER, CONF_VALUE_INTEGER_4, - &li.game_of_life[3], 3 + -1, -1, + TYPE_BITFIELD, CONF_VALUE_8_BIT(7), + &li.dont_collide_with_bits, ~0 /* default: always deadly */ }, + { - EL_BIOMAZE, - TYPE_INTEGER, CONF_VALUE_INTEGER_1, - &li.biomaze[0], 2 + -1, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(5), + &li.score[SC_TIME_BONUS], 1 }, + { - EL_BIOMAZE, - TYPE_INTEGER, CONF_VALUE_INTEGER_2, - &li.biomaze[1], 3 + -1, -1, + -1, -1, + NULL, -1, }, +}; + +static struct LevelFileConfigInfo chunk_config_ELEM[] = +{ + /* (these values are the same for each player) */ { - EL_BIOMAZE, - TYPE_INTEGER, CONF_VALUE_INTEGER_3, - &li.biomaze[2], 3 + EL_PLAYER_1, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(1), + &li.block_last_field, FALSE /* default case for EM levels */ }, { - EL_BIOMAZE, - TYPE_INTEGER, CONF_VALUE_INTEGER_4, - &li.biomaze[3], 3 + EL_PLAYER_1, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(2), + &li.sp_block_last_field, TRUE /* default case for SP levels */ }, { - EL_BALLOON, - TYPE_BITFIELD, CONF_VALUE_INTEGER_1, - &li.wind_direction_initial, MV_NONE + EL_PLAYER_1, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(3), + &li.instant_relocation, FALSE }, { - EL_TIMEGATE_SWITCH, - TYPE_INTEGER, CONF_VALUE_INTEGER_1, - &li.time_timegate, 10 + EL_PLAYER_1, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(4), + &li.can_pass_to_walkable, FALSE }, { - EL_LIGHT_SWITCH_ACTIVE, - TYPE_INTEGER, CONF_VALUE_INTEGER_1, - &li.time_light, 10 + EL_PLAYER_1, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(5), + &li.block_snap_field, TRUE }, { - EL_SHIELD_NORMAL, - TYPE_INTEGER, CONF_VALUE_INTEGER_1, - &li.shield_normal_time, 10 + EL_PLAYER_1, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(6), + &li.continuous_snapping, TRUE }, + + /* (these values are different for each player) */ { - EL_SHIELD_DEADLY, - TYPE_INTEGER, CONF_VALUE_INTEGER_1, - &li.shield_deadly_time, 10 + EL_PLAYER_1, -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(7), + &li.initial_player_stepsize[0], STEPSIZE_NORMAL }, { - EL_EXTRA_TIME, - TYPE_INTEGER, CONF_VALUE_INTEGER_1, - &li.extra_time, 10 + EL_PLAYER_1, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(8), + &li.initial_player_gravity[0], FALSE }, { - EL_EXTRA_TIME, - TYPE_INTEGER, CONF_VALUE_INTEGER_2, - &li.extra_time_score, 10 + EL_PLAYER_1, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(9), + &li.use_start_element[0], FALSE }, { - EL_TIME_ORB_FULL, - TYPE_INTEGER, CONF_VALUE_INTEGER_1, - &li.time_orb_time, 10 + EL_PLAYER_1, -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(1), + &li.start_element[0], EL_PLAYER_1 }, { - EL_TIME_ORB_FULL, - TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_1, - &li.use_time_orb_bug, FALSE + EL_PLAYER_1, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(10), + &li.use_artwork_element[0], FALSE }, { - EL_PLAYER_1, - TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_1, - &li.block_snap_field, TRUE + EL_PLAYER_1, -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(2), + &li.artwork_element[0], EL_PLAYER_1 }, { - EL_PLAYER_1, - TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_2, - &li.use_start_element[0], FALSE + EL_PLAYER_1, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(11), + &li.use_explosion_element[0], FALSE }, { - EL_PLAYER_2, - TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_2, - &li.use_start_element[1], FALSE + EL_PLAYER_1, -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(3), + &li.explosion_element[0], EL_PLAYER_1 }, + { - EL_PLAYER_3, - TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_2, - &li.use_start_element[2], FALSE + EL_PLAYER_2, -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(7), + &li.initial_player_stepsize[1], STEPSIZE_NORMAL }, { - EL_PLAYER_4, - TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_2, - &li.use_start_element[3], FALSE + EL_PLAYER_2, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(8), + &li.initial_player_gravity[1], FALSE }, { - EL_PLAYER_1, - TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_3, - &li.use_artwork_element[0], FALSE + EL_PLAYER_2, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(9), + &li.use_start_element[1], FALSE + }, + { + EL_PLAYER_2, -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(1), + &li.start_element[1], EL_PLAYER_2 }, { - EL_PLAYER_2, - TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_3, + EL_PLAYER_2, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(10), &li.use_artwork_element[1], FALSE }, { - EL_PLAYER_3, - TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_3, - &li.use_artwork_element[2], FALSE + EL_PLAYER_2, -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(2), + &li.artwork_element[1], EL_PLAYER_2 }, { - EL_PLAYER_4, - TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_3, - &li.use_artwork_element[3], FALSE + EL_PLAYER_2, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(11), + &li.use_explosion_element[1], FALSE }, { - EL_PLAYER_1, - TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_4, - &li.use_explosion_element[0], FALSE + EL_PLAYER_2, -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(3), + &li.explosion_element[1], EL_PLAYER_2 + }, + + { + EL_PLAYER_3, -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(7), + &li.initial_player_stepsize[2], STEPSIZE_NORMAL }, { - EL_PLAYER_2, - TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_4, - &li.use_explosion_element[1], FALSE + EL_PLAYER_3, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(8), + &li.initial_player_gravity[2], FALSE + }, + { + EL_PLAYER_3, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(9), + &li.use_start_element[2], FALSE + }, + { + EL_PLAYER_3, -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(1), + &li.start_element[2], EL_PLAYER_3 }, { - EL_PLAYER_3, - TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_4, + EL_PLAYER_3, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(10), + &li.use_artwork_element[2], FALSE + }, + { + EL_PLAYER_3, -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(2), + &li.artwork_element[2], EL_PLAYER_3 + }, + { + EL_PLAYER_3, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(11), &li.use_explosion_element[2], FALSE }, { - EL_PLAYER_4, - TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_4, + EL_PLAYER_3, -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(3), + &li.explosion_element[2], EL_PLAYER_3 + }, + + { + EL_PLAYER_4, -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(7), + &li.initial_player_stepsize[3], STEPSIZE_NORMAL + }, + { + EL_PLAYER_4, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(8), + &li.initial_player_gravity[3], FALSE + }, + { + EL_PLAYER_4, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(9), + &li.use_start_element[3], FALSE + }, + { + EL_PLAYER_4, -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(1), + &li.start_element[3], EL_PLAYER_4 + }, + { + EL_PLAYER_4, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(10), + &li.use_artwork_element[3], FALSE + }, + { + EL_PLAYER_4, -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(2), + &li.artwork_element[3], EL_PLAYER_4 + }, + { + EL_PLAYER_4, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(11), &li.use_explosion_element[3], FALSE }, { - EL_PLAYER_1, - TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_5, - &li.continuous_snapping, TRUE + EL_PLAYER_4, -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(3), + &li.explosion_element[3], EL_PLAYER_4 }, + { - EL_PLAYER_1, - TYPE_INTEGER, CONF_VALUE_INTEGER_1, - &li.initial_player_stepsize, STEPSIZE_NORMAL + EL_EMERALD, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.score[SC_EMERALD], 10 }, + { - EL_EMC_MAGIC_BALL, - TYPE_INTEGER, CONF_VALUE_INTEGER_1, - &li.ball_time, 10 + EL_DIAMOND, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.score[SC_DIAMOND], 10 }, + { - EL_EMC_MAGIC_BALL, - TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_1, - &li.ball_random, FALSE + EL_BUG, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.score[SC_BUG], 10 }, + { - EL_EMC_MAGIC_BALL, - TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_2, - &li.ball_state_initial, FALSE + EL_SPACESHIP, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.score[SC_SPACESHIP], 10 }, - /* ---------- 2-byte values ---------------------------------------------- */ + { + EL_PACMAN, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.score[SC_PACMAN], 10 + }, { - EL_PLAYER_1, - TYPE_ELEMENT, CONF_VALUE_ELEMENT_1, - &li.start_element[0], EL_PLAYER_1 + EL_NUT, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.score[SC_NUT], 10 }, + { - EL_PLAYER_2, - TYPE_ELEMENT, CONF_VALUE_ELEMENT_1, - &li.start_element[1], EL_PLAYER_2 + EL_DYNAMITE, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.score[SC_DYNAMITE], 10 }, + { - EL_PLAYER_3, - TYPE_ELEMENT, CONF_VALUE_ELEMENT_1, - &li.start_element[2], EL_PLAYER_3 + EL_KEY_1, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.score[SC_KEY], 10 }, + { - EL_PLAYER_4, - TYPE_ELEMENT, CONF_VALUE_ELEMENT_1, - &li.start_element[3], EL_PLAYER_4 + EL_PEARL, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.score[SC_PEARL], 10 }, + { - EL_PLAYER_1, - TYPE_ELEMENT, CONF_VALUE_ELEMENT_2, - &li.artwork_element[0], EL_PLAYER_1 + EL_CRYSTAL, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.score[SC_CRYSTAL], 10 }, + { - EL_PLAYER_2, - TYPE_ELEMENT, CONF_VALUE_ELEMENT_2, - &li.artwork_element[1], EL_PLAYER_2 + EL_BD_AMOEBA, -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(1), + &li.amoeba_content, EL_DIAMOND }, { - EL_PLAYER_3, - TYPE_ELEMENT, CONF_VALUE_ELEMENT_2, - &li.artwork_element[2], EL_PLAYER_3 + EL_BD_AMOEBA, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(2), + &li.amoeba_speed, 10 }, { - EL_PLAYER_4, - TYPE_ELEMENT, CONF_VALUE_ELEMENT_2, - &li.artwork_element[3], EL_PLAYER_4 + EL_BD_AMOEBA, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(1), + &li.grow_into_diggable, TRUE }, + { - EL_PLAYER_1, - TYPE_ELEMENT, CONF_VALUE_ELEMENT_3, - &li.explosion_element[0], EL_PLAYER_1 + EL_YAMYAM, -1, + TYPE_CONTENT_LIST, CONF_VALUE_BYTES(1), + &li.yamyam_content, EL_ROCK, NULL, + &li.num_yamyam_contents, 4, MAX_ELEMENT_CONTENTS }, { - EL_PLAYER_2, - TYPE_ELEMENT, CONF_VALUE_ELEMENT_3, - &li.explosion_element[1], EL_PLAYER_2 + EL_YAMYAM, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.score[SC_YAMYAM], 10 }, + { - EL_PLAYER_3, - TYPE_ELEMENT, CONF_VALUE_ELEMENT_3, - &li.explosion_element[2], EL_PLAYER_3 + EL_ROBOT, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.score[SC_ROBOT], 10 }, { - EL_PLAYER_4, - TYPE_ELEMENT, CONF_VALUE_ELEMENT_3, - &li.explosion_element[3], EL_PLAYER_4 + EL_ROBOT, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(2), + &li.slurp_score, 10 + }, + + { + EL_ROBOT_WHEEL, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.time_wheel, 10 + }, + + { + EL_MAGIC_WALL, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.time_magic_wall, 10 + }, + + { + EL_GAME_OF_LIFE, -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(1), + &li.game_of_life[0], 2 + }, + { + EL_GAME_OF_LIFE, -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(2), + &li.game_of_life[1], 3 + }, + { + EL_GAME_OF_LIFE, -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(3), + &li.game_of_life[2], 3 + }, + { + EL_GAME_OF_LIFE, -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(4), + &li.game_of_life[3], 3 + }, + + { + EL_BIOMAZE, -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(1), + &li.biomaze[0], 2 + }, + { + EL_BIOMAZE, -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(2), + &li.biomaze[1], 3 + }, + { + EL_BIOMAZE, -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(3), + &li.biomaze[2], 3 + }, + { + EL_BIOMAZE, -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(4), + &li.biomaze[3], 3 + }, + + { + EL_TIMEGATE_SWITCH, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.time_timegate, 10 + }, + + { + EL_LIGHT_SWITCH_ACTIVE, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.time_light, 10 + }, + + { + EL_SHIELD_NORMAL, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.shield_normal_time, 10 + }, + { + EL_SHIELD_NORMAL, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(2), + &li.score[SC_SHIELD], 10 + }, + + { + EL_SHIELD_DEADLY, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.shield_deadly_time, 10 + }, + { + EL_SHIELD_DEADLY, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(2), + &li.score[SC_SHIELD], 10 + }, + + { + EL_EXTRA_TIME, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.extra_time, 10 + }, + { + EL_EXTRA_TIME, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(2), + &li.extra_time_score, 10 }, - /* ---------- multi-byte values ------------------------------------------ */ + { + EL_TIME_ORB_FULL, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.time_orb_time, 10 + }, + { + EL_TIME_ORB_FULL, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(1), + &li.use_time_orb_bug, FALSE + }, { - EL_EMC_ANDROID, + EL_SPRING, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(1), + &li.use_spring_bug, FALSE + }, + + { + EL_EMC_ANDROID, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.android_move_time, 10 + }, + { + EL_EMC_ANDROID, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(2), + &li.android_clone_time, 10 + }, + { + EL_EMC_ANDROID, -1, TYPE_ELEMENT_LIST, CONF_VALUE_BYTES(1), &li.android_clone_element[0], EL_EMPTY, NULL, &li.num_android_clone_elements, 1, MAX_ANDROID_ELEMENTS }, + + { + EL_EMC_LENSES, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.lenses_score, 10 + }, { - EL_EMC_MAGIC_BALL, - TYPE_CONTENT_LIST, CONF_VALUE_BYTES(2), + EL_EMC_LENSES, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(2), + &li.lenses_time, 10 + }, + + { + EL_EMC_MAGNIFIER, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.magnify_score, 10 + }, + { + EL_EMC_MAGNIFIER, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(2), + &li.magnify_time, 10 + }, + + { + EL_EMC_MAGIC_BALL, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.ball_time, 10 + }, + { + EL_EMC_MAGIC_BALL, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(1), + &li.ball_random, FALSE + }, + { + EL_EMC_MAGIC_BALL, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(2), + &li.ball_state_initial, FALSE + }, + { + EL_EMC_MAGIC_BALL, -1, + TYPE_CONTENT_LIST, CONF_VALUE_BYTES(1), &li.ball_content, EL_EMPTY, NULL, &li.num_ball_contents, 4, MAX_ELEMENT_CONTENTS }, + /* ---------- unused values ----------------------------------------------- */ + + { + EL_UNKNOWN, SAVE_CONF_NEVER, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.score[SC_UNKNOWN_14], 10 + }, + { + EL_UNKNOWN, SAVE_CONF_NEVER, + TYPE_INTEGER, CONF_VALUE_16_BIT(2), + &li.score[SC_UNKNOWN_15], 10 + }, + { - -1, + -1, -1, -1, -1, NULL, -1, }, }; -static struct ElementFileConfig custom_element_conf[] = +static struct LevelFileConfigInfo chunk_config_NOTE[] = { { - -1, + -1, -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(1), + &xx_envelope.xsize, MAX_ENVELOPE_XSIZE, + }, + { + -1, -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(2), + &xx_envelope.ysize, MAX_ENVELOPE_YSIZE, + }, + + { + -1, -1, + TYPE_STRING, CONF_VALUE_BYTES(1), + &xx_envelope.text, -1, NULL, + &xx_string_length_unused, -1, MAX_ENVELOPE_TEXT_LEN, + &xx_default_string_empty[0] + }, + + { + -1, -1, + -1, -1, + NULL, -1, + }, +}; + +static struct LevelFileConfigInfo chunk_config_CUSX_base[] = +{ + { + -1, -1, TYPE_STRING, CONF_VALUE_BYTES(1), &xx_ei.description[0], -1, &yy_ei.description[0], - &xx_default_description_length, -1, MAX_ELEMENT_NAME_LEN, + &xx_string_length_unused, -1, MAX_ELEMENT_NAME_LEN, &xx_default_description[0] }, { - -1, + -1, -1, TYPE_BITFIELD, CONF_VALUE_32_BIT(1), &xx_ei.properties[EP_BITFIELD_BASE_NR], EP_BITMASK_BASE_DEFAULT, &yy_ei.properties[EP_BITFIELD_BASE_NR] @@ -501,7 +774,7 @@ static struct ElementFileConfig custom_element_conf[] = #if 0 /* (reserved) */ { - -1, + -1, -1, TYPE_BITFIELD, CONF_VALUE_32_BIT(2), &xx_ei.properties[EP_BITFIELD_BASE_NR + 1], EP_BITMASK_DEFAULT, &yy_ei.properties[EP_BITFIELD_BASE_NR + 1] @@ -509,160 +782,160 @@ static struct ElementFileConfig custom_element_conf[] = #endif { - -1, + -1, -1, TYPE_BOOLEAN, CONF_VALUE_8_BIT(1), &xx_ei.use_gfx_element, FALSE, &yy_ei.use_gfx_element }, { - -1, + -1, -1, TYPE_ELEMENT, CONF_VALUE_16_BIT(1), &xx_ei.gfx_element, EL_EMPTY_SPACE, &yy_ei.gfx_element }, { - -1, + -1, -1, TYPE_BITFIELD, CONF_VALUE_8_BIT(2), &xx_ei.access_direction, MV_ALL_DIRECTIONS, &yy_ei.access_direction }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_16_BIT(2), &xx_ei.collect_score_initial, 10, &yy_ei.collect_score_initial }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_16_BIT(3), &xx_ei.collect_count_initial, 1, &yy_ei.collect_count_initial }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_16_BIT(4), &xx_ei.ce_value_fixed_initial, 0, &yy_ei.ce_value_fixed_initial }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_16_BIT(5), &xx_ei.ce_value_random_initial, 0, &yy_ei.ce_value_random_initial }, { - -1, + -1, -1, TYPE_BOOLEAN, CONF_VALUE_8_BIT(3), &xx_ei.use_last_ce_value, FALSE, &yy_ei.use_last_ce_value }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_16_BIT(6), &xx_ei.push_delay_fixed, 8, &yy_ei.push_delay_fixed }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_16_BIT(7), &xx_ei.push_delay_random, 8, &yy_ei.push_delay_random }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_16_BIT(8), &xx_ei.drop_delay_fixed, 0, &yy_ei.drop_delay_fixed }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_16_BIT(9), &xx_ei.drop_delay_random, 0, &yy_ei.drop_delay_random }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_16_BIT(10), &xx_ei.move_delay_fixed, 0, &yy_ei.move_delay_fixed }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_16_BIT(11), &xx_ei.move_delay_random, 0, &yy_ei.move_delay_random }, { - -1, + -1, -1, TYPE_BITFIELD, CONF_VALUE_32_BIT(3), &xx_ei.move_pattern, MV_ALL_DIRECTIONS, &yy_ei.move_pattern }, { - -1, + -1, -1, TYPE_BITFIELD, CONF_VALUE_8_BIT(4), &xx_ei.move_direction_initial, MV_START_AUTOMATIC, &yy_ei.move_direction_initial }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_8_BIT(5), &xx_ei.move_stepsize, TILEX / 8, &yy_ei.move_stepsize }, { - -1, + -1, -1, TYPE_ELEMENT, CONF_VALUE_16_BIT(12), &xx_ei.move_enter_element, EL_EMPTY_SPACE, &yy_ei.move_enter_element }, { - -1, + -1, -1, TYPE_ELEMENT, CONF_VALUE_16_BIT(13), &xx_ei.move_leave_element, EL_EMPTY_SPACE, &yy_ei.move_leave_element }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_8_BIT(6), &xx_ei.move_leave_type, LEAVE_TYPE_UNLIMITED, &yy_ei.move_leave_type }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_8_BIT(7), &xx_ei.slippery_type, SLIPPERY_ANY_RANDOM, &yy_ei.slippery_type }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_8_BIT(8), &xx_ei.explosion_type, EXPLODES_3X3, &yy_ei.explosion_type }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_16_BIT(14), &xx_ei.explosion_delay, 16, &yy_ei.explosion_delay }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_16_BIT(15), &xx_ei.ignition_delay, 8, &yy_ei.ignition_delay }, { - -1, + -1, -1, TYPE_CONTENT_LIST, CONF_VALUE_BYTES(2), &xx_ei.content, EL_EMPTY_SPACE, &yy_ei.content, @@ -672,195 +945,195 @@ static struct ElementFileConfig custom_element_conf[] = /* ---------- "num_change_pages" must be the last entry ------------------- */ { - -1, + -1, SAVE_CONF_ALWAYS, TYPE_INTEGER, CONF_VALUE_8_BIT(9), - &xx_ei.num_change_pages, -1, /* value must always be saved */ + &xx_ei.num_change_pages, 1, &yy_ei.num_change_pages }, { - -1, + -1, -1, -1, -1, NULL, -1, NULL }, }; -static struct ElementFileConfig custom_element_change_conf[] = +static struct LevelFileConfigInfo chunk_config_CUSX_change[] = { /* ---------- "current_change_page" must be the first entry --------------- */ { - -1, + -1, SAVE_CONF_ALWAYS, TYPE_INTEGER, CONF_VALUE_8_BIT(1), - &xx_current_change_page, -1 /* value must always be saved */ + &xx_current_change_page, -1 }, /* ---------- (the remaining entries can be in any order) ----------------- */ { - -1, + -1, -1, TYPE_BOOLEAN, CONF_VALUE_8_BIT(2), &xx_change.can_change, FALSE }, { - -1, + -1, -1, TYPE_BITFIELD, CONF_VALUE_32_BIT(1), &xx_event_bits[0], 0 }, { - -1, + -1, -1, TYPE_BITFIELD, CONF_VALUE_32_BIT(2), &xx_event_bits[1], 0 }, { - -1, - TYPE_INTEGER, CONF_VALUE_8_BIT(3), + -1, -1, + TYPE_BITFIELD, CONF_VALUE_8_BIT(3), &xx_change.trigger_player, CH_PLAYER_ANY }, { - -1, - TYPE_INTEGER, CONF_VALUE_8_BIT(4), + -1, -1, + TYPE_BITFIELD, CONF_VALUE_8_BIT(4), &xx_change.trigger_side, CH_SIDE_ANY }, { - -1, - TYPE_INTEGER, CONF_VALUE_8_BIT(5), + -1, -1, + TYPE_BITFIELD, CONF_VALUE_32_BIT(3), &xx_change.trigger_page, CH_PAGE_ANY }, { - -1, + -1, -1, TYPE_ELEMENT, CONF_VALUE_16_BIT(1), &xx_change.target_element, EL_EMPTY_SPACE }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_16_BIT(2), &xx_change.delay_fixed, 0 }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_16_BIT(3), &xx_change.delay_random, 0 }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_16_BIT(4), &xx_change.delay_frames, FRAMES_PER_SECOND }, { - -1, + -1, -1, TYPE_ELEMENT, CONF_VALUE_16_BIT(5), &xx_change.trigger_element, EL_EMPTY_SPACE }, { - -1, + -1, -1, TYPE_BOOLEAN, CONF_VALUE_8_BIT(6), &xx_change.explode, FALSE }, { - -1, + -1, -1, TYPE_BOOLEAN, CONF_VALUE_8_BIT(7), &xx_change.use_target_content, FALSE }, { - -1, + -1, -1, TYPE_BOOLEAN, CONF_VALUE_8_BIT(8), &xx_change.only_if_complete, FALSE }, { - -1, + -1, -1, TYPE_BOOLEAN, CONF_VALUE_8_BIT(9), &xx_change.use_random_replace, FALSE }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_8_BIT(10), &xx_change.random_percentage, 100 }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_8_BIT(11), &xx_change.replace_when, CP_WHEN_EMPTY }, { - -1, + -1, -1, TYPE_BOOLEAN, CONF_VALUE_8_BIT(12), &xx_change.has_action, FALSE }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_8_BIT(13), &xx_change.action_type, CA_NO_ACTION }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_8_BIT(14), &xx_change.action_mode, CA_MODE_UNDEFINED }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_16_BIT(6), &xx_change.action_arg, CA_ARG_UNDEFINED }, { - -1, + -1, -1, TYPE_CONTENT_LIST, CONF_VALUE_BYTES(1), &xx_change.target_content, EL_EMPTY_SPACE, NULL, &xx_num_contents, 1, 1 }, { - -1, + -1, -1, -1, -1, NULL, -1, }, }; -static struct ElementFileConfig group_element_conf[] = +static struct LevelFileConfigInfo chunk_config_GRPX[] = { { - -1, + -1, -1, TYPE_STRING, CONF_VALUE_BYTES(1), &xx_ei.description[0], -1, NULL, - &xx_default_description_length, -1, MAX_ELEMENT_NAME_LEN, + &xx_string_length_unused, -1, MAX_ELEMENT_NAME_LEN, &xx_default_description[0] }, { - -1, + -1, -1, TYPE_BOOLEAN, CONF_VALUE_8_BIT(1), &xx_ei.use_gfx_element, FALSE }, { - -1, + -1, -1, TYPE_ELEMENT, CONF_VALUE_16_BIT(1), &xx_ei.gfx_element, EL_EMPTY_SPACE }, { - -1, + -1, -1, TYPE_INTEGER, CONF_VALUE_8_BIT(2), &xx_group.choice_mode, ANIM_RANDOM }, { - -1, + -1, -1, TYPE_ELEMENT_LIST, CONF_VALUE_BYTES(2), &xx_group.element[0], EL_EMPTY_SPACE, NULL, &xx_group.num_elements, 1, MAX_ELEMENTS_IN_GROUP }, { - -1, + -1, -1, -1, -1, NULL, -1, }, @@ -888,6 +1161,19 @@ filetype_id_list[] = /* level file functions */ /* ========================================================================= */ +static struct DateInfo getCurrentDate() +{ + time_t epoch_seconds = time(NULL); + struct tm *now = localtime(&epoch_seconds); + struct DateInfo date; + + date.year = now->tm_year + 1900; + date.month = now->tm_mon + 1; + date.day = now->tm_mday; + + return date; +} + static void resetEventFlags(struct ElementChangeInfo *change) { int i; @@ -951,34 +1237,34 @@ static void setElementDescriptionToDefault(struct ElementInfo *ei) ei->description[i] = default_description[i]; } -static void setConfigToDefaultsFromConfigList(struct ElementFileConfig *config) +static void setConfigToDefaultsFromConfigList(struct LevelFileConfigInfo *conf) { int i; - for (i = 0; config[i].data_type != -1; i++) + for (i = 0; conf[i].data_type != -1; i++) { - int default_value = config[i].default_value; - int data_type = config[i].data_type; - int conf_type = config[i].conf_type; + int default_value = conf[i].default_value; + int data_type = conf[i].data_type; + int conf_type = conf[i].conf_type; int byte_mask = conf_type & CONF_MASK_BYTES; if (byte_mask == CONF_MASK_MULTI_BYTES) { - int default_num_entities = config[i].default_num_entities; - int max_num_entities = config[i].max_num_entities; + int default_num_entities = conf[i].default_num_entities; + int max_num_entities = conf[i].max_num_entities; - *(int *)(config[i].num_entities) = default_num_entities; + *(int *)(conf[i].num_entities) = default_num_entities; if (data_type == TYPE_STRING) { - char *default_string = config[i].default_string; - char *string = (char *)(config[i].value); + char *default_string = conf[i].default_string; + char *string = (char *)(conf[i].value); strncpy(string, default_string, max_num_entities); } else if (data_type == TYPE_ELEMENT_LIST) { - int *element_array = (int *)(config[i].value); + int *element_array = (int *)(conf[i].value); int j; for (j = 0; j < max_num_entities; j++) @@ -986,7 +1272,7 @@ static void setConfigToDefaultsFromConfigList(struct ElementFileConfig *config) } else if (data_type == TYPE_CONTENT_LIST) { - struct Content *content = (struct Content *)(config[i].value); + struct Content *content = (struct Content *)(conf[i].value); int c, x, y; for (c = 0; c < max_num_entities; c++) @@ -998,38 +1284,38 @@ static void setConfigToDefaultsFromConfigList(struct ElementFileConfig *config) else /* constant size configuration data (1, 2 or 4 bytes) */ { if (data_type == TYPE_BOOLEAN) - *(boolean *)(config[i].value) = default_value; + *(boolean *)(conf[i].value) = default_value; else - *(int *) (config[i].value) = default_value; + *(int *) (conf[i].value) = default_value; } } } -static void copyConfigFromConfigList(struct ElementFileConfig *config) +static void copyConfigFromConfigList(struct LevelFileConfigInfo *conf) { int i; - for (i = 0; config[i].data_type != -1; i++) + for (i = 0; conf[i].data_type != -1; i++) { - int data_type = config[i].data_type; - int conf_type = config[i].conf_type; + int data_type = conf[i].data_type; + int conf_type = conf[i].conf_type; int byte_mask = conf_type & CONF_MASK_BYTES; if (byte_mask == CONF_MASK_MULTI_BYTES) { - int max_num_entities = config[i].max_num_entities; + int max_num_entities = conf[i].max_num_entities; if (data_type == TYPE_STRING) { - char *string = (char *)(config[i].value); - char *string_copy = (char *)(config[i].value_copy); + char *string = (char *)(conf[i].value); + char *string_copy = (char *)(conf[i].value_copy); strncpy(string_copy, string, max_num_entities); } else if (data_type == TYPE_ELEMENT_LIST) { - int *element_array = (int *)(config[i].value); - int *element_array_copy = (int *)(config[i].value_copy); + int *element_array = (int *)(conf[i].value); + int *element_array_copy = (int *)(conf[i].value_copy); int j; for (j = 0; j < max_num_entities; j++) @@ -1037,8 +1323,8 @@ static void copyConfigFromConfigList(struct ElementFileConfig *config) } else if (data_type == TYPE_CONTENT_LIST) { - struct Content *content = (struct Content *)(config[i].value); - struct Content *content_copy = (struct Content *)(config[i].value_copy); + struct Content *content = (struct Content *)(conf[i].value); + struct Content *content_copy = (struct Content *)(conf[i].value_copy); int c, x, y; for (c = 0; c < max_num_entities; c++) @@ -1050,9 +1336,9 @@ static void copyConfigFromConfigList(struct ElementFileConfig *config) else /* constant size configuration data (1, 2 or 4 bytes) */ { if (data_type == TYPE_BOOLEAN) - *(boolean *)(config[i].value_copy) = *(boolean *)(config[i].value); + *(boolean *)(conf[i].value_copy) = *(boolean *)(conf[i].value); else - *(int *) (config[i].value_copy) = *(int *) (config[i].value); + *(int *) (conf[i].value_copy) = *(int *) (conf[i].value); } } } @@ -1070,7 +1356,7 @@ void copyElementInfo(struct ElementInfo *ei_from, struct ElementInfo *ei_to) xx_ei = *ei_from; /* copy element data into temporary buffer */ yy_ei = *ei_to; /* copy element data into temporary buffer */ - copyConfigFromConfigList(custom_element_conf); + copyConfigFromConfigList(chunk_config_CUSX_base); *ei_from = xx_ei; *ei_to = yy_ei; @@ -1169,7 +1455,7 @@ void setElementChangeInfoToDefaults(struct ElementChangeInfo *change) xx_change = *change; /* copy change data into temporary buffer */ xx_num_contents = 1; - setConfigToDefaultsFromConfigList(custom_element_change_conf); + setConfigToDefaultsFromConfigList(chunk_config_CUSX_change); *change = xx_change; @@ -1235,7 +1521,8 @@ static void setLevelInfoToDefaults(struct LevelInfo *level) #if 1 li = *level; /* copy level data into temporary buffer */ - setConfigToDefaultsFromConfigList(element_conf); + setConfigToDefaultsFromConfigList(chunk_config_INFO); + setConfigToDefaultsFromConfigList(chunk_config_ELEM); *level = li; /* copy temporary buffer back to level data */ #endif @@ -1244,22 +1531,35 @@ static void setLevelInfoToDefaults(struct LevelInfo *level) level->native_em_level = &native_em_level; +#if 0 level->game_engine_type = GAME_ENGINE_TYPE_RND; +#endif level->file_version = FILE_VERSION_ACTUAL; level->game_version = GAME_VERSION_ACTUAL; + level->creation_date = getCurrentDate(); + +#if 1 + level->encoding_16bit_field = TRUE; + level->encoding_16bit_yamyam = TRUE; + level->encoding_16bit_amoeba = TRUE; +#else level->encoding_16bit_field = FALSE; /* default: only 8-bit elements */ level->encoding_16bit_yamyam = FALSE; /* default: only 8-bit elements */ level->encoding_16bit_amoeba = FALSE; /* default: only 8-bit elements */ +#endif +#if 0 level->fieldx = STD_LEV_FIELDX; level->fieldy = STD_LEV_FIELDY; +#endif for (x = 0; x < MAX_LEV_FIELDX; x++) for (y = 0; y < MAX_LEV_FIELDY; y++) level->field[x][y] = EL_SAND; +#if 0 level->time = 100; level->gems_needed = 0; @@ -1267,12 +1567,15 @@ static void setLevelInfoToDefaults(struct LevelInfo *level) level->time_magic_wall = 10; level->time_wheel = 10; +#endif #if 0 level->time_light = 10; level->time_timegate = 10; #endif +#if 0 level->amoeba_content = EL_DIAMOND; +#endif #if 0 level->game_of_life[0] = 2; @@ -1289,16 +1592,19 @@ static void setLevelInfoToDefaults(struct LevelInfo *level) #if 0 level->double_speed = FALSE; #endif +#if 0 level->initial_gravity = FALSE; level->em_slippery_gems = FALSE; level->instant_relocation = FALSE; level->can_pass_to_walkable = FALSE; level->grow_into_diggable = TRUE; +#endif #if 0 level->block_snap_field = TRUE; #endif +#if 0 level->block_last_field = FALSE; /* EM does not block by default */ level->sp_block_last_field = TRUE; /* SP blocks the last field */ @@ -1309,6 +1615,7 @@ static void setLevelInfoToDefaults(struct LevelInfo *level) level->use_time_orb_bug = FALSE; level->use_step_counter = FALSE; +#endif /* values for the new EMC elements */ #if 0 @@ -1333,7 +1640,9 @@ static void setLevelInfoToDefaults(struct LevelInfo *level) level->android_array[i] = FALSE; #endif +#if 0 level->use_custom_template = FALSE; +#endif for (i = 0; i < MAX_LEVEL_NAME_LEN; i++) level->name[i] = '\0'; @@ -1343,22 +1652,28 @@ static void setLevelInfoToDefaults(struct LevelInfo *level) strcpy(level->name, NAMELESS_LEVEL_NAME); strcpy(level->author, ANONYMOUS_NAME); +#if 0 for (i = 0; i < 4; i++) { level->envelope_text[i][0] = '\0'; level->envelope_xsize[i] = MAX_ENVELOPE_XSIZE; level->envelope_ysize[i] = MAX_ENVELOPE_YSIZE; } +#endif +#if 0 for (i = 0; i < LEVEL_SCORE_ELEMENTS; i++) level->score[i] = (i == SC_TIME_BONUS ? 1 : 10); +#endif +#if 0 level->num_yamyam_contents = STD_ELEMENT_CONTENTS; for (i = 0; i < MAX_ELEMENT_CONTENTS; i++) for (x = 0; x < 3; x++) for (y = 0; y < 3; y++) level->yamyam_content[i].e[x][y] = (i < STD_ELEMENT_CONTENTS ? EL_ROCK : EL_EMPTY); +#endif level->field[0][0] = EL_PLAYER_1; level->field[STD_LEV_FIELDX - 1][STD_LEV_FIELDY - 1] = EL_EXIT_CLOSED; @@ -1368,6 +1683,15 @@ static void setLevelInfoToDefaults(struct LevelInfo *level) int element = i; struct ElementInfo *ei = &element_info[element]; + if (IS_ENVELOPE(element)) + { + int envelope_nr = element - EL_ENVELOPE_1; + + setConfigToDefaultsFromConfigList(chunk_config_NOTE); + + level->envelope[envelope_nr] = xx_envelope; + } + #if 1 if (IS_CUSTOM_ELEMENT(element) || IS_GROUP_ELEMENT(element) || @@ -1375,7 +1699,7 @@ static void setLevelInfoToDefaults(struct LevelInfo *level) { xx_ei = *ei; /* copy element data into temporary buffer */ - setConfigToDefaultsFromConfigList(custom_element_conf); + setConfigToDefaultsFromConfigList(chunk_config_CUSX_base); *ei = xx_ei; } @@ -1426,8 +1750,12 @@ static void setLevelInfoToDefaults(struct LevelInfo *level) ei->ce_value_random_initial = 0; ei->use_last_ce_value = FALSE; +#endif +#if 0 ei->push_delay_fixed = -1; /* initialize later */ ei->push_delay_random = -1; /* initialize later */ +#endif +#if 0 ei->drop_delay_fixed = 0; ei->drop_delay_random = 0; ei->move_delay_fixed = 0; @@ -1452,6 +1780,8 @@ static void setLevelInfoToDefaults(struct LevelInfo *level) ei->content.e[x][y] = EL_EMPTY_SPACE; #endif + /* internal values used in level editor */ + ei->access_type = 0; ei->access_layer = 0; ei->access_protected = 0; @@ -1498,7 +1828,7 @@ static void setLevelInfoToDefaults(struct LevelInfo *level) #if 1 xx_group = *group; /* copy group data into temporary buffer */ - setConfigToDefaultsFromConfigList(group_element_conf); + setConfigToDefaultsFromConfigList(chunk_config_GRPX); *group = xx_group; #endif @@ -1926,8 +2256,19 @@ static int LoadLevel_VERS(FILE *file, int chunk_size, struct LevelInfo *level) return chunk_size; } +static int LoadLevel_DATE(FILE *file, int chunk_size, struct LevelInfo *level) +{ + level->creation_date.year = getFile16BitBE(file); + level->creation_date.month = getFile8Bit(file); + level->creation_date.day = getFile8Bit(file); + + return chunk_size; +} + static int LoadLevel_HEAD(FILE *file, int chunk_size, struct LevelInfo *level) { + int initial_player_stepsize; + int initial_player_gravity; int i, x, y; level->fieldx = getFile8Bit(file); @@ -1954,10 +2295,17 @@ static int LoadLevel_HEAD(FILE *file, int chunk_size, struct LevelInfo *level) level->time_wheel = getFile8Bit(file); level->amoeba_content = getMappedElement(getFile8Bit(file)); - level->initial_player_stepsize = (getFile8Bit(file) == 1 ? STEPSIZE_FAST : - STEPSIZE_NORMAL); + initial_player_stepsize = (getFile8Bit(file) == 1 ? STEPSIZE_FAST : + STEPSIZE_NORMAL); + + for (i = 0; i < MAX_PLAYERS; i++) + level->initial_player_stepsize[0] = initial_player_stepsize; + + initial_player_gravity = (getFile8Bit(file) == 1 ? TRUE : FALSE); + + for (i = 0; i < MAX_PLAYERS; i++) + level->initial_player_gravity[0] = initial_player_gravity; - level->initial_gravity = (getFile8Bit(file) == 1 ? TRUE : FALSE); level->encoding_16bit_field = (getFile8Bit(file) == 1 ? TRUE : FALSE); level->em_slippery_gems = (getFile8Bit(file) == 1 ? TRUE : FALSE); @@ -1977,7 +2325,18 @@ static int LoadLevel_HEAD(FILE *file, int chunk_size, struct LevelInfo *level) level->game_engine_type = getFile8Bit(file); - ReadUnusedBytesFromFile(file, LEVEL_HEADER_UNUSED); + ReadUnusedBytesFromFile(file, LEVEL_CHUNK_HEAD_UNUSED); + + return chunk_size; +} + +static int LoadLevel_NAME(FILE *file, int chunk_size, struct LevelInfo *level) +{ + int i; + + for (i = 0; i < MAX_LEVEL_NAME_LEN; i++) + level->name[i] = getFile8Bit(file); + level->name[MAX_LEVEL_NAME_LEN] = 0; return chunk_size; } @@ -1988,7 +2347,7 @@ static int LoadLevel_AUTH(FILE *file, int chunk_size, struct LevelInfo *level) for (i = 0; i < MAX_LEVEL_AUTHOR_LEN; i++) level->author[i] = getFile8Bit(file); - level->author[MAX_LEVEL_NAME_LEN] = 0; + level->author[MAX_LEVEL_AUTHOR_LEN] = 0; return chunk_size; } @@ -2120,8 +2479,8 @@ static int LoadLevel_CNT3(FILE *file, int chunk_size, struct LevelInfo *level) envelope_len = getFile16BitBE(file); - level->envelope_xsize[envelope_nr] = getFile8Bit(file); - level->envelope_ysize[envelope_nr] = getFile8Bit(file); + level->envelope[envelope_nr].xsize = getFile8Bit(file); + level->envelope[envelope_nr].ysize = getFile8Bit(file); ReadUnusedBytesFromFile(file, LEVEL_CHUNK_CNT3_UNUSED); @@ -2133,7 +2492,7 @@ static int LoadLevel_CNT3(FILE *file, int chunk_size, struct LevelInfo *level) } for (i = 0; i < envelope_len; i++) - level->envelope_text[envelope_nr][i] = getFile8Bit(file); + level->envelope[envelope_nr].text[i] = getFile8Bit(file); return chunk_size; } @@ -2152,7 +2511,7 @@ static int LoadLevel_CUS1(FILE *file, int chunk_size, struct LevelInfo *level) for (i = 0; i < num_changed_custom_elements; i++) { - int element = getFile16BitBE(file); + int element = getMappedElement(getFile16BitBE(file)); int properties = getFile32BitBE(file); #if 1 @@ -2166,6 +2525,12 @@ static int LoadLevel_CUS1(FILE *file, int chunk_size, struct LevelInfo *level) else Error(ERR_WARN, "invalid custom element number %d", element); #endif + +#if 1 + /* needed for older levels (see src/init.c for details) */ + element_info[element].push_delay_fixed = -1; /* initialize later */ + element_info[element].push_delay_random = -1; /* initialize later */ +#endif } return chunk_size; @@ -2185,8 +2550,8 @@ static int LoadLevel_CUS2(FILE *file, int chunk_size, struct LevelInfo *level) for (i = 0; i < num_changed_custom_elements; i++) { - int element = getFile16BitBE(file); - int custom_target_element = getFile16BitBE(file); + int element = getMappedElement(getFile16BitBE(file)); + int custom_target_element = getMappedElement(getFile16BitBE(file)); if (IS_CUSTOM_ELEMENT(element)) element_info[element].change->target_element = custom_target_element; @@ -2211,7 +2576,7 @@ static int LoadLevel_CUS3(FILE *file, int chunk_size, struct LevelInfo *level) for (i = 0; i < num_changed_custom_elements; i++) { - int element = getFile16BitBE(file); + int element = getMappedElement(getFile16BitBE(file)); struct ElementInfo *ei = &element_info[element]; unsigned int event_bits; @@ -2301,7 +2666,7 @@ static int LoadLevel_CUS4(FILE *file, int chunk_size, struct LevelInfo *level) /* ---------- custom element base property values (96 bytes) ------------- */ - element = getFile16BitBE(file); + element = getMappedElement(getFile16BitBE(file)); if (!IS_CUSTOM_ELEMENT(element)) { @@ -2450,7 +2815,7 @@ static int LoadLevel_GRP1(FILE *file, int chunk_size, struct LevelInfo *level) int element; int i; - element = getFile16BitBE(file); + element = getMappedElement(getFile16BitBE(file)); if (!IS_GROUP_ELEMENT(element)) { @@ -2487,8 +2852,8 @@ static int LoadLevel_GRP1(FILE *file, int chunk_size, struct LevelInfo *level) return chunk_size; } -static int LoadLevel_MicroChunk(FILE *file, struct ElementFileConfig *config, - int element) +static int LoadLevel_MicroChunk(FILE *file, struct LevelFileConfigInfo *conf, + int element, int real_element) { int micro_chunk_size = 0; int conf_type = getFile8Bit(file); @@ -2509,14 +2874,14 @@ static int LoadLevel_MicroChunk(FILE *file, struct ElementFileConfig *config, ReadBytesFromFile(file, buffer, num_bytes); - for (i = 0; config[i].data_type != -1; i++) + for (i = 0; conf[i].data_type != -1; i++) { - if (config[i].element == element && - config[i].conf_type == conf_type) + if (conf[i].element == element && + conf[i].conf_type == conf_type) { - int data_type = config[i].data_type; + int data_type = conf[i].data_type; int num_entities = num_bytes / CONF_ENTITY_NUM_BYTES(data_type); - int max_num_entities = config[i].max_num_entities; + int max_num_entities = conf[i].max_num_entities; if (num_entities > max_num_entities) { @@ -2527,13 +2892,13 @@ static int LoadLevel_MicroChunk(FILE *file, struct ElementFileConfig *config, num_entities = max_num_entities; } - *(int *)(config[i].num_entities) = num_entities; + *(int *)(conf[i].num_entities) = num_entities; element_found = TRUE; if (data_type == TYPE_STRING) { - char *string = (char *)(config[i].value); + char *string = (char *)(conf[i].value); int j; for (j = 0; j < max_num_entities; j++) @@ -2541,7 +2906,7 @@ static int LoadLevel_MicroChunk(FILE *file, struct ElementFileConfig *config, } else if (data_type == TYPE_ELEMENT_LIST) { - int *element_array = (int *)(config[i].value); + int *element_array = (int *)(conf[i].value); int j; for (j = 0; j < num_entities; j++) @@ -2550,7 +2915,7 @@ static int LoadLevel_MicroChunk(FILE *file, struct ElementFileConfig *config, } else if (data_type == TYPE_CONTENT_LIST) { - struct Content *content= (struct Content *)(config[i].value); + struct Content *content= (struct Content *)(conf[i].value); int c, x, y; for (c = 0; c < num_entities; c++) @@ -2580,17 +2945,20 @@ static int LoadLevel_MicroChunk(FILE *file, struct ElementFileConfig *config, printf("::: - found single bytes\n"); #endif - for (i = 0; config[i].data_type != -1; i++) + for (i = 0; conf[i].data_type != -1; i++) { - if (config[i].element == element && - config[i].conf_type == conf_type) + if (conf[i].element == element && + conf[i].conf_type == conf_type) { - int data_type = config[i].data_type; + int data_type = conf[i].data_type; + + if (data_type == TYPE_ELEMENT) + value = getMappedElement(value); if (data_type == TYPE_BOOLEAN) - *(boolean *)(config[i].value) = value; + *(boolean *)(conf[i].value) = value; else - *(int *) (config[i].value) = value; + *(int *) (conf[i].value) = value; element_found = TRUE; @@ -2602,12 +2970,42 @@ static int LoadLevel_MicroChunk(FILE *file, struct ElementFileConfig *config, } if (!element_found) - Error(ERR_WARN, "cannot load micro chunk value for element %d", element); + { + char *error_conf_chunk_bytes = + (byte_mask == CONF_MASK_1_BYTE ? "CONF_VALUE_8_BIT" : + byte_mask == CONF_MASK_2_BYTE ? "CONF_VALUE_16_BIT" : + byte_mask == CONF_MASK_4_BYTE ? "CONF_VALUE_32_BIT" :"CONF_VALUE_BYTES"); + int error_conf_chunk_token = conf_type & CONF_MASK_TOKEN; + int error_element = real_element; + + Error(ERR_WARN, "cannot load micro chunk '%s(%d)' value for element %d ['%s']", + error_conf_chunk_bytes, error_conf_chunk_token, + error_element, EL_NAME(error_element)); + } return micro_chunk_size; } -static int LoadLevel_CONF(FILE *file, int chunk_size, struct LevelInfo *level) +static int LoadLevel_INFO(FILE *file, int chunk_size, struct LevelInfo *level) +{ + int real_chunk_size = 0; + + li = *level; /* copy level data into temporary buffer */ + + while (!feof(file)) + { + real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_INFO, -1, -1); + + if (real_chunk_size >= chunk_size) + break; + } + + *level = li; /* copy temporary buffer back to level data */ + + return real_chunk_size; +} + +static int LoadLevel_ELEM(FILE *file, int chunk_size, struct LevelInfo *level) { int real_chunk_size = 0; @@ -2617,10 +3015,11 @@ static int LoadLevel_CONF(FILE *file, int chunk_size, struct LevelInfo *level) while (!feof(file)) { - int element = getFile16BitBE(file); + int element = getMappedElement(getFile16BitBE(file)); #if 1 real_chunk_size += 2; - real_chunk_size += LoadLevel_MicroChunk(file, element_conf, element); + real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_ELEM, + element, element); #else int conf_type = getFile8Bit(file); int byte_mask = conf_type & CONF_MASK_BYTES; @@ -2640,14 +3039,14 @@ static int LoadLevel_CONF(FILE *file, int chunk_size, struct LevelInfo *level) ReadBytesFromFile(file, buffer, num_bytes); - for (i = 0; element_conf[i].data_type != -1; i++) + for (i = 0; chunk_config_ELEM[i].data_type != -1; i++) { - if (element_conf[i].element == element && - element_conf[i].conf_type == conf_type) + if (chunk_config_ELEM[i].element == element && + chunk_config_ELEM[i].conf_type == conf_type) { - int data_type = element_conf[i].data_type; + int data_type = chunk_config_ELEM[i].data_type; int num_entities = num_bytes / CONF_ENTITY_NUM_BYTES(data_type); - int max_num_entities = element_conf[i].max_num_entities; + int max_num_entities = chunk_config_ELEM[i].max_num_entities; if (num_entities > max_num_entities) { @@ -2658,13 +3057,13 @@ static int LoadLevel_CONF(FILE *file, int chunk_size, struct LevelInfo *level) num_entities = max_num_entities; } - *(int *)(element_conf[i].num_entities) = num_entities; + *(int *)(chunk_config_ELEM[i].num_entities) = num_entities; element_found = TRUE; if (data_type == TYPE_ELEMENT_LIST) { - int *element_array = (int *)(element_conf[i].value); + int *element_array = (int *)(chunk_config_ELEM[i].value); int j; for (j = 0; j < num_entities; j++) @@ -2673,7 +3072,7 @@ static int LoadLevel_CONF(FILE *file, int chunk_size, struct LevelInfo *level) } else if (data_type == TYPE_CONTENT_LIST) { - struct Content *content= (struct Content *)(element_conf[i].value); + struct Content *content= (struct Content *)(chunk_config_ELEM[i].value); int c, x, y; for (c = 0; c < num_entities; c++) @@ -2699,17 +3098,17 @@ static int LoadLevel_CONF(FILE *file, int chunk_size, struct LevelInfo *level) byte_mask == CONF_MASK_2_BYTE ? getFile16BitBE(file) : byte_mask == CONF_MASK_4_BYTE ? getFile32BitBE(file) : 0); - for (i = 0; element_conf[i].data_type != -1; i++) + for (i = 0; chunk_config_ELEM[i].data_type != -1; i++) { - if (element_conf[i].element == element && - element_conf[i].conf_type == conf_type) + if (chunk_config_ELEM[i].element == element && + chunk_config_ELEM[i].conf_type == conf_type) { - int data_type = element_conf[i].data_type; + int data_type = chunk_config_ELEM[i].data_type; if (data_type == TYPE_BOOLEAN) - *(boolean *)(element_conf[i].value) = value; + *(boolean *)(chunk_config_ELEM[i].value) = value; else - *(int *) (element_conf[i].value) = value; + *(int *) (chunk_config_ELEM[i].value) = value; element_found = TRUE; @@ -2728,13 +3127,8 @@ static int LoadLevel_CONF(FILE *file, int chunk_size, struct LevelInfo *level) *level = li; /* copy temporary buffer back to level data */ #endif -#if 1 if (real_chunk_size >= chunk_size) break; -#else - if (conf_type == CONF_LAST_ENTRY || real_chunk_size >= chunk_size) - break; -#endif } #if 1 @@ -2744,9 +3138,29 @@ static int LoadLevel_CONF(FILE *file, int chunk_size, struct LevelInfo *level) return real_chunk_size; } +static int LoadLevel_NOTE(FILE *file, int chunk_size, struct LevelInfo *level) +{ + int element = getMappedElement(getFile16BitBE(file)); + int envelope_nr = element - EL_ENVELOPE_1; + int real_chunk_size = 2; + + while (!feof(file)) + { + real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_NOTE, + -1, element); + + if (real_chunk_size >= chunk_size) + break; + } + + level->envelope[envelope_nr] = xx_envelope; + + return real_chunk_size; +} + static int LoadLevel_CUSX(FILE *file, int chunk_size, struct LevelInfo *level) { - int element = getFile16BitBE(file); + int element = getMappedElement(getFile16BitBE(file)); int real_chunk_size = 2; struct ElementInfo *ei = &element_info[element]; int i; @@ -2761,7 +3175,8 @@ static int LoadLevel_CUSX(FILE *file, int chunk_size, struct LevelInfo *level) while (!feof(file)) { - real_chunk_size += LoadLevel_MicroChunk(file, custom_element_conf, -1); + real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_CUSX_base, + -1, element); #if 0 printf("::: - real_chunk_size now %d\n", real_chunk_size); @@ -2805,7 +3220,8 @@ static int LoadLevel_CUSX(FILE *file, int chunk_size, struct LevelInfo *level) resetEventBits(); /* reset bits; change page might have changed */ - real_chunk_size += LoadLevel_MicroChunk(file,custom_element_change_conf,-1); + real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_CUSX_change, + -1, element); *change = xx_change; @@ -2820,7 +3236,7 @@ static int LoadLevel_CUSX(FILE *file, int chunk_size, struct LevelInfo *level) static int LoadLevel_GRPX(FILE *file, int chunk_size, struct LevelInfo *level) { - int element = getFile16BitBE(file); + int element = getMappedElement(getFile16BitBE(file)); int real_chunk_size = 2; struct ElementInfo *ei = &element_info[element]; struct ElementGroupInfo *group = ei->group; @@ -2830,7 +3246,8 @@ static int LoadLevel_GRPX(FILE *file, int chunk_size, struct LevelInfo *level) while (!feof(file)) { - real_chunk_size += LoadLevel_MicroChunk(file, group_element_conf, -1); + real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_GRPX, + -1, element); if (real_chunk_size >= chunk_size) break; @@ -2908,7 +3325,7 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level, if (level->file_version < FILE_VERSION_1_2) { /* level files from versions before 1.2.0 without chunk structure */ - LoadLevel_HEAD(file, LEVEL_HEADER_SIZE, level); + LoadLevel_HEAD(file, LEVEL_CHUNK_HEAD_SIZE, level); LoadLevel_BODY(file, level->fieldx * level->fieldy, level); } else @@ -2921,9 +3338,12 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level, } chunk_info[] = { - { "VERS", FILE_VERS_CHUNK_SIZE, LoadLevel_VERS }, - { "HEAD", LEVEL_HEADER_SIZE, LoadLevel_HEAD }, - { "AUTH", MAX_LEVEL_AUTHOR_LEN, LoadLevel_AUTH }, + { "VERS", LEVEL_CHUNK_VERS_SIZE, LoadLevel_VERS }, + { "DATE", LEVEL_CHUNK_DATE_SIZE, LoadLevel_DATE }, + { "HEAD", LEVEL_CHUNK_HEAD_SIZE, LoadLevel_HEAD }, + { "NAME", LEVEL_CHUNK_NAME_SIZE, LoadLevel_NAME }, + { "AUTH", LEVEL_CHUNK_AUTH_SIZE, LoadLevel_AUTH }, + { "INFO", -1, LoadLevel_INFO }, { "BODY", -1, LoadLevel_BODY }, { "CONT", -1, LoadLevel_CONT }, { "CNT2", LEVEL_CHUNK_CNT2_SIZE, LoadLevel_CNT2 }, @@ -2933,11 +3353,10 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level, { "CUS3", -1, LoadLevel_CUS3 }, { "CUS4", -1, LoadLevel_CUS4 }, { "GRP1", -1, LoadLevel_GRP1 }, - { "CONF", -1, LoadLevel_CONF }, -#if 1 + { "ELEM", -1, LoadLevel_ELEM }, + { "NOTE", -1, LoadLevel_NOTE }, { "CUSX", -1, LoadLevel_CUSX }, { "GRPX", -1, LoadLevel_GRPX }, -#endif { NULL, 0, NULL } }; @@ -3842,6 +4261,7 @@ void CopyNativeLevel_Native_to_RND(struct LevelInfo *level) static void LoadLevelFromFileStream_SP(FILE *file, struct LevelInfo *level, int nr) { + int initial_player_gravity; int num_special_ports; int i, x, y; @@ -3875,7 +4295,10 @@ static void LoadLevelFromFileStream_SP(FILE *file, struct LevelInfo *level, ReadUnusedBytesFromFile(file, 4); /* (not used by Supaplex engine) */ /* initial gravity: 1 == "on", anything else (0) == "off" */ - level->initial_gravity = (fgetc(file) == 1 ? TRUE : FALSE); + initial_player_gravity = (fgetc(file) == 1 ? TRUE : FALSE); + + for (i = 0; i < MAX_PLAYERS; i++) + level->initial_player_gravity[i] = initial_player_gravity; ReadUnusedBytesFromFile(file, 1); /* (not used by Supaplex engine) */ @@ -4237,6 +4660,8 @@ void LoadLevelFromFilename(struct LevelInfo *level, char *filename) static void LoadLevel_InitVersion(struct LevelInfo *level, char *filename) { + int i; + if (leveldir_current == NULL) /* only when dumping level */ return; @@ -4294,7 +4719,8 @@ static void LoadLevel_InitVersion(struct LevelInfo *level, char *filename) /* player was faster than enemies in 1.0.0 and before */ if (level->file_version == FILE_VERSION_1_0) - level->initial_player_stepsize = STEPSIZE_FAST; + for (i = 0; i < MAX_PLAYERS; i++) + level->initial_player_stepsize[i] = STEPSIZE_FAST; /* default behaviour for EM style gems was "slippery" only in 2.0.1 */ if (level->game_version == VERSION_IDENT(2,0,1,0)) @@ -4578,12 +5004,28 @@ void LoadLevel(int nr) LoadLevel_InitNativeEngines(&level, filename); } -static void SaveLevel_VERS(FILE *file, struct LevelInfo *level) +static int SaveLevel_VERS(FILE *file, struct LevelInfo *level) { - putFileVersion(file, level->file_version); - putFileVersion(file, level->game_version); + int chunk_size = 0; + + chunk_size += putFileVersion(file, level->file_version); + chunk_size += putFileVersion(file, level->game_version); + + return chunk_size; +} + +static int SaveLevel_DATE(FILE *file, struct LevelInfo *level) +{ + int chunk_size = 0; + + chunk_size += putFile16BitBE(file, level->creation_date.year); + chunk_size += putFile8Bit(file, level->creation_date.month); + chunk_size += putFile8Bit(file, level->creation_date.day); + + return chunk_size; } +#if 0 static void SaveLevel_HEAD(FILE *file, struct LevelInfo *level) { int i, x, y; @@ -4631,27 +5073,59 @@ static void SaveLevel_HEAD(FILE *file, struct LevelInfo *level) putFile8Bit(file, level->game_engine_type); - WriteUnusedBytesToFile(file, LEVEL_HEADER_UNUSED); + WriteUnusedBytesToFile(file, LEVEL_CHUNK_HEAD_UNUSED); +} +#endif + +static int SaveLevel_NAME(FILE *file, struct LevelInfo *level) +{ + int chunk_size = 0; + int i; + + for (i = 0; i < MAX_LEVEL_NAME_LEN; i++) + chunk_size += putFile8Bit(file, level->name[i]); + + return chunk_size; } -static void SaveLevel_AUTH(FILE *file, struct LevelInfo *level) +static int SaveLevel_AUTH(FILE *file, struct LevelInfo *level) { + int chunk_size = 0; int i; for (i = 0; i < MAX_LEVEL_AUTHOR_LEN; i++) - putFile8Bit(file, level->author[i]); + chunk_size += putFile8Bit(file, level->author[i]); + + return chunk_size; } -static void SaveLevel_BODY(FILE *file, struct LevelInfo *level) +#if 0 +static int SaveLevel_BODY(FILE *file, struct LevelInfo *level) { + int chunk_size = 0; int x, y; for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++) if (level->encoding_16bit_field) - putFile16BitBE(file, level->field[x][y]); + chunk_size += putFile16BitBE(file, level->field[x][y]); else - putFile8Bit(file, level->field[x][y]); + chunk_size += putFile8Bit(file, level->field[x][y]); + + return chunk_size; +} +#endif + +static int SaveLevel_BODY(FILE *file, struct LevelInfo *level) +{ + int chunk_size = 0; + int x, y; + + for (y = 0; y < level->fieldy; y++) + for (x = 0; x < level->fieldx; x++) + chunk_size += putFile16BitBE(file, level->field[x][y]); + + return chunk_size; } #if 0 @@ -4674,6 +5148,7 @@ static void SaveLevel_CONT(FILE *file, struct LevelInfo *level) } #endif +#if 0 static void SaveLevel_CNT2(FILE *file, struct LevelInfo *level, int element) { int i, x, y; @@ -4724,23 +5199,30 @@ static void SaveLevel_CNT2(FILE *file, struct LevelInfo *level, int element) for (x = 0; x < 3; x++) putFile16BitBE(file, content_array[i][x][y]); } +#endif -static void SaveLevel_CNT3(FILE *file, struct LevelInfo *level, int element) +#if 0 +static int SaveLevel_CNT3(FILE *file, struct LevelInfo *level, int element) { - int i; int envelope_nr = element - EL_ENVELOPE_1; int envelope_len = strlen(level->envelope_text[envelope_nr]) + 1; + int chunk_size = 0; + int i; - putFile16BitBE(file, element); - putFile16BitBE(file, envelope_len); - putFile8Bit(file, level->envelope_xsize[envelope_nr]); - putFile8Bit(file, level->envelope_ysize[envelope_nr]); + chunk_size += putFile16BitBE(file, element); + chunk_size += putFile16BitBE(file, envelope_len); + chunk_size += putFile8Bit(file, level->envelope_xsize[envelope_nr]); + chunk_size += putFile8Bit(file, level->envelope_ysize[envelope_nr]); WriteUnusedBytesToFile(file, LEVEL_CHUNK_CNT3_UNUSED); + chunk_size += LEVEL_CHUNK_CNT3_UNUSED; for (i = 0; i < envelope_len; i++) - putFile8Bit(file, level->envelope_text[envelope_nr][i]); + chunk_size += putFile8Bit(file, level->envelope_text[envelope_nr][i]); + + return chunk_size; } +#endif #if 0 static void SaveLevel_CUS1(FILE *file, struct LevelInfo *level, @@ -5052,8 +5534,10 @@ static void SaveLevel_GRP1(FILE *file, struct LevelInfo *level, int element) } #endif -static int SaveLevel_MicroChunk(FILE *file, struct ElementFileConfig *entry) +static int SaveLevel_MicroChunk(FILE *file, struct LevelFileConfigInfo *entry, + boolean write_element) { + int save_type = entry->save_type; int data_type = entry->data_type; int conf_type = entry->conf_type; int byte_mask = conf_type & CONF_MASK_BYTES; @@ -5072,10 +5556,12 @@ static int SaveLevel_MicroChunk(FILE *file, struct ElementFileConfig *entry) if (value != default_value) modified = TRUE; - if (!modified) /* do not save unmodified default settings */ + /* do not save if explicitly told or if unmodified default settings */ + if ((save_type == SAVE_CONF_NEVER) || + (save_type == SAVE_CONF_WHEN_CHANGED && !modified)) return 0; - if (element != -1) + if (write_element) num_bytes += putFile16BitBE(file, element); num_bytes += putFile8Bit(file, conf_type); @@ -5083,8 +5569,6 @@ static int SaveLevel_MicroChunk(FILE *file, struct ElementFileConfig *entry) byte_mask == CONF_MASK_2_BYTE ? putFile16BitBE(file, value) : byte_mask == CONF_MASK_4_BYTE ? putFile32BitBE(file, value) : 0); - - return num_bytes; } else if (data_type == TYPE_STRING) { @@ -5097,10 +5581,12 @@ static int SaveLevel_MicroChunk(FILE *file, struct ElementFileConfig *entry) if (!strEqual(string, default_string)) modified = TRUE; - if (!modified) /* do not save unmodified default settings */ + /* do not save if explicitly told or if unmodified default settings */ + if ((save_type == SAVE_CONF_NEVER) || + (save_type == SAVE_CONF_WHEN_CHANGED && !modified)) return 0; - if (element != -1) + if (write_element) num_bytes += putFile16BitBE(file, element); num_bytes += putFile8Bit(file, conf_type); @@ -5108,8 +5594,6 @@ static int SaveLevel_MicroChunk(FILE *file, struct ElementFileConfig *entry) for (i = 0; i < string_length; i++) num_bytes += putFile8Bit(file, string[i]); - - return num_bytes; } else if (data_type == TYPE_ELEMENT_LIST) { @@ -5122,10 +5606,12 @@ static int SaveLevel_MicroChunk(FILE *file, struct ElementFileConfig *entry) if (element_array[i] != default_value) modified = TRUE; - if (!modified) /* do not save unmodified default settings */ + /* do not save if explicitly told or if unmodified default settings */ + if ((save_type == SAVE_CONF_NEVER) || + (save_type == SAVE_CONF_WHEN_CHANGED && !modified)) return 0; - if (element != -1) + if (write_element) num_bytes += putFile16BitBE(file, element); num_bytes += putFile8Bit(file, conf_type); @@ -5133,8 +5619,6 @@ static int SaveLevel_MicroChunk(FILE *file, struct ElementFileConfig *entry) for (i = 0; i < num_elements; i++) num_bytes += putFile16BitBE(file, element_array[i]); - - return num_bytes; } else if (data_type == TYPE_CONTENT_LIST) { @@ -5149,10 +5633,12 @@ static int SaveLevel_MicroChunk(FILE *file, struct ElementFileConfig *entry) if (content[i].e[x][y] != default_value) modified = TRUE; - if (!modified) /* do not save unmodified default settings */ + /* do not save if explicitly told or if unmodified default settings */ + if ((save_type == SAVE_CONF_NEVER) || + (save_type == SAVE_CONF_WHEN_CHANGED && !modified)) return 0; - if (element != -1) + if (write_element) num_bytes += putFile16BitBE(file, element); num_bytes += putFile8Bit(file, conf_type); @@ -5162,17 +5648,15 @@ static int SaveLevel_MicroChunk(FILE *file, struct ElementFileConfig *entry) for (y = 0; y < 3; y++) for (x = 0; x < 3; x++) num_bytes += putFile16BitBE(file, content[i].e[x][y]); - - return num_bytes; } - return 0; + return num_bytes; } #if 0 static int SaveLevel_MicroChunk_SingleValue(FILE *file, - struct ElementFileConfig *entry) + struct LevelFileConfigInfo *entry) { int default_value = entry->default_value; int element = entry->element; @@ -5210,7 +5694,7 @@ static int SaveLevel_MicroChunk_SingleValue(FILE *file, } static int SaveLevel_MicroChunk_ElementList(FILE *file, - struct ElementFileConfig *entry) + struct LevelFileConfigInfo *entry) { int *element_array = (int *)(entry->value); int num_elements = *(int *)(entry->num_entities); @@ -5242,7 +5726,7 @@ static int SaveLevel_MicroChunk_ElementList(FILE *file, } static int SaveLevel_MicroChunk_ContentList(FILE *file, - struct ElementFileConfig *entry) + struct LevelFileConfigInfo *entry) { struct Content *content = (struct Content *)(entry->value); int num_contents = *(int *)(entry->num_entities); @@ -5279,35 +5763,65 @@ static int SaveLevel_MicroChunk_ContentList(FILE *file, #endif -static int SaveLevel_CONF(FILE *file, struct LevelInfo *level) +static int SaveLevel_INFO(FILE *file, struct LevelInfo *level) +{ + int chunk_size = 0; + int i; + + li = *level; /* copy level data into temporary buffer */ + + for (i = 0; chunk_config_INFO[i].data_type != -1; i++) + chunk_size += SaveLevel_MicroChunk(file, &chunk_config_INFO[i], FALSE); + + return chunk_size; +} + +static int SaveLevel_ELEM(FILE *file, struct LevelInfo *level) { int chunk_size = 0; int i; li = *level; /* copy level data into temporary buffer */ - for (i = 0; element_conf[i].data_type != -1; i++) + for (i = 0; chunk_config_ELEM[i].data_type != -1; i++) { #if 1 - chunk_size += SaveLevel_MicroChunk(file, &element_conf[i]); + chunk_size += SaveLevel_MicroChunk(file, &chunk_config_ELEM[i], TRUE); #else - struct ElementFileConfig *config = &element_conf[i]; - int data_type = config->data_type; - int conf_type = config->conf_type; + struct LevelFileConfigInfo *conf = &chunk_config_ELEM[i]; + int data_type = conf->data_type; + int conf_type = conf->conf_type; int byte_mask = conf_type & CONF_MASK_BYTES; if (byte_mask != CONF_MASK_MULTI_BYTES) - chunk_size += SaveLevel_MicroChunk_SingleValue(file, config); + chunk_size += SaveLevel_MicroChunk_SingleValue(file, conf); else if (data_type == TYPE_ELEMENT_LIST) - chunk_size += SaveLevel_MicroChunk_ElementList(file, config); + chunk_size += SaveLevel_MicroChunk_ElementList(file, conf); else if (data_type == TYPE_CONTENT_LIST) - chunk_size += SaveLevel_MicroChunk_ContentList(file, config); + chunk_size += SaveLevel_MicroChunk_ContentList(file, conf); #endif } return chunk_size; } +static int SaveLevel_NOTE(FILE *file, struct LevelInfo *level, int element) +{ + int envelope_nr = element - EL_ENVELOPE_1; + int chunk_size = 0; + int i; + + chunk_size += putFile16BitBE(file, element); + + /* copy envelope data into temporary buffer */ + xx_envelope = level->envelope[envelope_nr]; + + for (i = 0; chunk_config_NOTE[i].data_type != -1; i++) + chunk_size += SaveLevel_MicroChunk(file, &chunk_config_NOTE[i], FALSE); + + return chunk_size; +} + static int SaveLevel_CUSX(FILE *file, struct LevelInfo *level, int element) { struct ElementInfo *ei = &element_info[element]; @@ -5328,8 +5842,8 @@ static int SaveLevel_CUSX(FILE *file, struct LevelInfo *level, int element) printf("::: - element config\n"); #endif - for (i = 0; custom_element_conf[i].data_type != -1; i++) - chunk_size += SaveLevel_MicroChunk(file, &custom_element_conf[i]); + for (i = 0; chunk_config_CUSX_base[i].data_type != -1; i++) + chunk_size += SaveLevel_MicroChunk(file, &chunk_config_CUSX_base[i], FALSE); #if 0 printf("::: - change pages\n"); @@ -5353,8 +5867,9 @@ static int SaveLevel_CUSX(FILE *file, struct LevelInfo *level, int element) resetEventBits(); setEventBitsFromEventFlags(change); - for (j = 0; custom_element_change_conf[j].data_type != -1; j++) - chunk_size += SaveLevel_MicroChunk(file, &custom_element_change_conf[j]); + for (j = 0; chunk_config_CUSX_change[j].data_type != -1; j++) + chunk_size += SaveLevel_MicroChunk(file, &chunk_config_CUSX_change[j], + FALSE); #if 0 if (element == EL_CUSTOM_START) @@ -5381,16 +5896,20 @@ static int SaveLevel_GRPX(FILE *file, struct LevelInfo *level, int element) /* set default description string for this specific element */ strcpy(xx_default_description, getDefaultElementDescription(ei)); - for (i = 0; group_element_conf[i].data_type != -1; i++) - chunk_size += SaveLevel_MicroChunk(file, &group_element_conf[i]); + for (i = 0; chunk_config_GRPX[i].data_type != -1; i++) + chunk_size += SaveLevel_MicroChunk(file, &chunk_config_GRPX[i], FALSE); return chunk_size; } static void SaveLevelFromFilename(struct LevelInfo *level, char *filename) { - int body_chunk_size, conf_chunk_size; + int chunk_size; +#if 1 + int i; +#else int i, x, y; +#endif FILE *file; if (!(file = fopen(filename, MODE_WRITE))) @@ -5402,13 +5921,18 @@ static void SaveLevelFromFilename(struct LevelInfo *level, char *filename) level->file_version = FILE_VERSION_ACTUAL; level->game_version = GAME_VERSION_ACTUAL; + level->creation_date = getCurrentDate(); + +#if 0 /* check level field for 16-bit elements */ level->encoding_16bit_field = FALSE; for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++) if (level->field[x][y] > 255) level->encoding_16bit_field = TRUE; +#endif +#if 0 /* check yamyam content for 16-bit elements */ level->encoding_16bit_yamyam = FALSE; for (i = 0; i < level->num_yamyam_contents; i++) @@ -5416,31 +5940,54 @@ static void SaveLevelFromFilename(struct LevelInfo *level, char *filename) for (x = 0; x < 3; x++) if (level->yamyam_content[i].e[x][y] > 255) level->encoding_16bit_yamyam = TRUE; +#endif +#if 0 /* check amoeba content for 16-bit elements */ level->encoding_16bit_amoeba = FALSE; if (level->amoeba_content > 255) level->encoding_16bit_amoeba = TRUE; +#endif +#if 0 /* calculate size of "BODY" chunk */ body_chunk_size = level->fieldx * level->fieldy * (level->encoding_16bit_field ? 2 : 1); +#endif putFileChunkBE(file, "RND1", CHUNK_SIZE_UNDEFINED); putFileChunkBE(file, "CAVE", CHUNK_SIZE_NONE); - putFileChunkBE(file, "VERS", FILE_VERS_CHUNK_SIZE); + chunk_size = SaveLevel_VERS(NULL, level); + putFileChunkBE(file, "VERS", chunk_size); SaveLevel_VERS(file, level); - putFileChunkBE(file, "HEAD", LEVEL_HEADER_SIZE); + chunk_size = SaveLevel_DATE(NULL, level); + putFileChunkBE(file, "DATE", chunk_size); + SaveLevel_DATE(file, level); + +#if 0 + putFileChunkBE(file, "HEAD", LEVEL_CHUNK_HEAD_SIZE); SaveLevel_HEAD(file, level); +#endif + + chunk_size = SaveLevel_NAME(NULL, level); + putFileChunkBE(file, "NAME", chunk_size); + SaveLevel_NAME(file, level); - putFileChunkBE(file, "AUTH", MAX_LEVEL_AUTHOR_LEN); + chunk_size = SaveLevel_AUTH(NULL, level); + putFileChunkBE(file, "AUTH", chunk_size); SaveLevel_AUTH(file, level); - putFileChunkBE(file, "BODY", body_chunk_size); + chunk_size = SaveLevel_INFO(NULL, level); + putFileChunkBE(file, "INFO", chunk_size); + SaveLevel_INFO(file, level); + + chunk_size = SaveLevel_BODY(NULL, level); + putFileChunkBE(file, "BODY", chunk_size); SaveLevel_BODY(file, level); +#if 0 if (level->encoding_16bit_yamyam || level->num_yamyam_contents != STD_ELEMENT_CONTENTS) { @@ -5453,7 +6000,9 @@ static void SaveLevelFromFilename(struct LevelInfo *level, char *filename) putFileChunkBE(file, "CNT2", LEVEL_CHUNK_CNT2_SIZE); SaveLevel_CNT2(file, level, EL_BD_AMOEBA); } +#endif +#if 0 /* check for envelope content */ for (i = 0; i < 4; i++) { @@ -5465,11 +6014,12 @@ static void SaveLevelFromFilename(struct LevelInfo *level, char *filename) SaveLevel_CNT3(file, level, EL_ENVELOPE_1 + i); } } +#endif +#if 0 /* if not using template level, check for non-default custom/group elements */ if (!level->use_custom_template) { -#if 0 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++) { int element = EL_CUSTOM_START + i; @@ -5493,40 +6043,42 @@ static void SaveLevelFromFilename(struct LevelInfo *level, char *filename) SaveLevel_GRP1(file, level, element); } } -#endif } +#endif - conf_chunk_size = SaveLevel_CONF(NULL, level); + chunk_size = SaveLevel_ELEM(NULL, level); + if (chunk_size > LEVEL_CHUNK_ELEM_UNCHANGED) /* save if changed */ + { + putFileChunkBE(file, "ELEM", chunk_size); + SaveLevel_ELEM(file, level); + } - /* check if non-default element settings need to be saved */ - if (conf_chunk_size > 0) +#if 1 + for (i = 0; i < NUM_ENVELOPES; i++) { - putFileChunkBE(file, "CONF", conf_chunk_size); - SaveLevel_CONF(file, level); + int element = EL_ENVELOPE_1 + i; + + chunk_size = SaveLevel_NOTE(NULL, level, element); + if (chunk_size > LEVEL_CHUNK_NOTE_UNCHANGED) /* save if changed */ + { + putFileChunkBE(file, "NOTE", chunk_size); + SaveLevel_NOTE(file, level, element); + } } +#endif +#if 1 /* if not using template level, check for non-default custom/group elements */ if (!level->use_custom_template) { - /* (element number, number of change pages, change page number) */ - int cusx_chunk_size_no_changes = (2) + (1 + 1) + (1 + 1); - /* (element number only) */ - int grpx_chunk_size_no_changes = (2); - -#if 1 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++) { int element = EL_CUSTOM_START + i; - int cusx_chunk_size = SaveLevel_CUSX(NULL, level, element); - /* check if non-default element settings need to be saved */ - if (cusx_chunk_size > cusx_chunk_size_no_changes) + chunk_size = SaveLevel_CUSX(NULL, level, element); + if (chunk_size > LEVEL_CHUNK_CUSX_UNCHANGED) /* save if changed */ { -#if 1 - printf("::: SAVING CE %d\n", i + 1); -#endif - - putFileChunkBE(file, "CUSX", cusx_chunk_size); + putFileChunkBE(file, "CUSX", chunk_size); SaveLevel_CUSX(file, level, element); } } @@ -5534,21 +6086,16 @@ static void SaveLevelFromFilename(struct LevelInfo *level, char *filename) for (i = 0; i < NUM_GROUP_ELEMENTS; i++) { int element = EL_GROUP_START + i; - int grpx_chunk_size = SaveLevel_GRPX(NULL, level, element); - /* check if non-default element settings need to be saved */ - if (grpx_chunk_size > grpx_chunk_size_no_changes) + chunk_size = SaveLevel_GRPX(NULL, level, element); + if (chunk_size > LEVEL_CHUNK_GRPX_UNCHANGED) /* save if changed */ { -#if 1 - printf("::: SAVING GE %d\n", i + 1); -#endif - - putFileChunkBE(file, "GRPX", grpx_chunk_size); + putFileChunkBE(file, "GRPX", chunk_size); SaveLevel_GRPX(file, level, element); } } -#endif } +#endif fclose(file); @@ -5598,8 +6145,12 @@ void DumpLevel(struct LevelInfo *level) printf("\n"); printf("Amoeba speed: %d\n", level->amoeba_speed); printf("\n"); + +#if 0 printf("Initial gravity: %s\n", (level->initial_gravity ? "yes" : "no")); printf("Initial player stepsize: %d\n", level->initial_player_stepsize); +#endif + printf("EM style slippery gems: %s\n", (level->em_slippery_gems ? "yes" : "no")); printf("Player blocks last field: %s\n", (level->block_last_field ? "yes" : "no")); printf("SP player blocks last field: %s\n", (level->sp_block_last_field ? "yes" : "no")); @@ -5675,7 +6226,7 @@ static int LoadTape_HEAD(FILE *file, int chunk_size, struct TapeInfo *tape) } } - ReadUnusedBytesFromFile(file, TAPE_HEADER_UNUSED); + ReadUnusedBytesFromFile(file, TAPE_CHUNK_HEAD_UNUSED); engine_version = getFileVersion(file); if (engine_version > 0) @@ -5855,8 +6406,8 @@ void LoadTapeFromFilename(char *filename) if (tape.file_version < FILE_VERSION_1_2) { /* tape files from versions before 1.2.0 without chunk structure */ - LoadTape_HEAD(file, TAPE_HEADER_SIZE, &tape); - LoadTape_BODY(file, 2 * tape.length, &tape); + LoadTape_HEAD(file, TAPE_CHUNK_HEAD_SIZE, &tape); + LoadTape_BODY(file, 2 * tape.length, &tape); } else { @@ -5868,8 +6419,8 @@ void LoadTapeFromFilename(char *filename) } chunk_info[] = { - { "VERS", FILE_VERS_CHUNK_SIZE, LoadTape_VERS }, - { "HEAD", TAPE_HEADER_SIZE, LoadTape_HEAD }, + { "VERS", TAPE_CHUNK_VERS_SIZE, LoadTape_VERS }, + { "HEAD", TAPE_CHUNK_HEAD_SIZE, LoadTape_HEAD }, { "INFO", -1, LoadTape_INFO }, { "BODY", -1, LoadTape_BODY }, { NULL, 0, NULL } @@ -5961,7 +6512,7 @@ static void SaveTape_HEAD(FILE *file, struct TapeInfo *tape) putFile8Bit(file, store_participating_players); /* unused bytes not at the end here for 4-byte alignment of engine_version */ - WriteUnusedBytesToFile(file, TAPE_HEADER_UNUSED); + WriteUnusedBytesToFile(file, TAPE_CHUNK_HEAD_UNUSED); putFileVersion(file, tape->engine_version); } @@ -6033,10 +6584,10 @@ void SaveTape(int nr) putFileChunkBE(file, "RND1", CHUNK_SIZE_UNDEFINED); putFileChunkBE(file, "TAPE", CHUNK_SIZE_NONE); - putFileChunkBE(file, "VERS", FILE_VERS_CHUNK_SIZE); + putFileChunkBE(file, "VERS", TAPE_CHUNK_VERS_SIZE); SaveTape_VERS(file, &tape); - putFileChunkBE(file, "HEAD", TAPE_HEADER_SIZE); + putFileChunkBE(file, "HEAD", TAPE_CHUNK_HEAD_SIZE); SaveTape_HEAD(file, &tape); putFileChunkBE(file, "INFO", info_chunk_size);