X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ffiles.c;h=b23388e9435e212d8e54b9990eaaac52226bc952;hb=4fd248da29cc447e267876a0461b9c1a867d30e9;hp=1d29930366fd64f8d6375501991b2c30112e0678;hpb=652f2eebd3bac1458da0010bef1b1208c19649c7;p=rocksndiamonds.git diff --git a/src/files.c b/src/files.c index 1d299303..b23388e9 100644 --- a/src/files.c +++ b/src/files.c @@ -58,215 +58,779 @@ #define CONF_MASK_BYTES 0xc0 #define CONF_MASK_TOKEN 0x3f -#define CONF_LAST_ENTRY (CONF_MASK_1_BYTE | 0) +#define CONF_VALUE_1_BYTE(x) (CONF_MASK_1_BYTE | (x)) +#define CONF_VALUE_2_BYTE(x) (CONF_MASK_2_BYTE | (x)) +#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) -#define CONF_VALUE_INTEGER_1 (CONF_MASK_1_BYTE | 1) -#define CONF_VALUE_INTEGER_2 (CONF_MASK_1_BYTE | 2) -#define CONF_VALUE_INTEGER_3 (CONF_MASK_1_BYTE | 3) -#define CONF_VALUE_INTEGER_4 (CONF_MASK_1_BYTE | 4) -#define CONF_VALUE_BOOLEAN_1 (CONF_MASK_1_BYTE | 5) -#define CONF_VALUE_BOOLEAN_2 (CONF_MASK_1_BYTE | 6) -#define CONF_VALUE_BOOLEAN_3 (CONF_MASK_1_BYTE | 7) -#define CONF_VALUE_BOOLEAN_4 (CONF_MASK_1_BYTE | 8) - -#define CONF_VALUE_ELEMENT_1 (CONF_MASK_2_BYTE | 1) -#define CONF_VALUE_ELEMENT_2 (CONF_MASK_2_BYTE | 2) -#define CONF_VALUE_ELEMENT_3 (CONF_MASK_2_BYTE | 3) -#define CONF_VALUE_ELEMENT_4 (CONF_MASK_2_BYTE | 4) - -#define CONF_VALUE_CONTENT_1 (CONF_MASK_MULTI_BYTES | 1) -#define CONF_VALUE_CONTENT_8 (CONF_MASK_MULTI_BYTES | 2) +#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_4) + (x) <= CONF_VALUE_INTEGER_8) #define CONF_VALUE_BOOLEAN(x) ((x) >= CONF_VALUE_BOOLEAN_1 && \ - (x) <= CONF_VALUE_BOOLEAN_4) + (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) + +#define CONF_ENTITY_NUM_BYTES(t) ((t) == TYPE_ELEMENT || \ + (t) == TYPE_ELEMENT_LIST ? \ + CONF_ELEMENT_NUM_BYTES : \ + (t) == TYPE_CONTENT || \ + (t) == TYPE_CONTENT_LIST ? \ + CONF_CONTENT_NUM_BYTES : 1) + +#define CONF_ELEMENT_BYTE_POS(i) ((i) * CONF_ELEMENT_NUM_BYTES) +#define CONF_ELEMENTS_ELEMENT(b,i) ((b[CONF_ELEMENT_BYTE_POS(i)] << 8) | \ + (b[CONF_ELEMENT_BYTE_POS(i) + 1])) #define CONF_CONTENT_ELEMENT_POS(c,x,y) ((c) * CONF_CONTENT_NUM_ELEMENTS + \ (y) * 3 + (x)) -#define CONF_CONTENT_BYTE_POS(c,x,y) (CONF_CONTENT_ELEMENT_POS(c,x,y) * 2) -#define CONF_CONTENT_ELEMENT(b,c,x,y) ((b[CONF_CONTENT_BYTE_POS(c,x,y)] << 8)|\ - (b[CONF_CONTENT_BYTE_POS(c,x,y) + 1])) +#define CONF_CONTENT_BYTE_POS(c,x,y) (CONF_CONTENT_ELEMENT_POS(c,x,y) * \ + CONF_ELEMENT_NUM_BYTES) +#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])) -static struct LevelInfo li; +#if 0 +static void LoadLevel_InitPlayfield(struct LevelInfo *, char *); +#endif -static struct +/* temporary variables used to store pointers to structure members */ +static struct LevelInfo li; +static struct ElementInfo xx_ei; +static struct ElementChangeInfo xx_change; +static struct ElementGroupInfo xx_group; +static unsigned int xx_event_bits_0_31, xx_event_bits_32_63; +static int xx_num_description_bytes; +static int xx_num_contents; +static int xx_current_change_page; + +struct ElementFileConfig { - int element; - int type; - void *value; - int default_value; -} element_conf[] = + 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 */ + + /* (mandatory) */ + void *value; /* variable that holds the data to be stored */ + int default_value; /* initial default value for this variable */ + + /* (optional) */ + void *num_entities; /* number of entities for multi-byte data */ + int default_num_entities; /* default number of entities for this data */ + int max_num_entities; /* maximal number of entities for this data */ +}; + +static struct ElementFileConfig element_conf[] = { /* ---------- 1-byte values ---------------------------------------------- */ + { - EL_EMC_ANDROID, CONF_VALUE_INTEGER_1, + EL_EMC_ANDROID, + TYPE_INTEGER, CONF_VALUE_INTEGER_1, &li.android_move_time, 10 }, { - EL_EMC_ANDROID, CONF_VALUE_INTEGER_2, + EL_EMC_ANDROID, + TYPE_INTEGER, CONF_VALUE_INTEGER_2, &li.android_clone_time, 10 }, { - EL_EMC_LENSES, CONF_VALUE_INTEGER_1, + EL_EMC_LENSES, + TYPE_INTEGER, CONF_VALUE_INTEGER_1, &li.lenses_score, 10 }, { - EL_EMC_LENSES, CONF_VALUE_INTEGER_2, + EL_EMC_LENSES, + TYPE_INTEGER, CONF_VALUE_INTEGER_2, &li.lenses_time, 10 }, { - EL_EMC_MAGNIFIER, CONF_VALUE_INTEGER_1, + EL_EMC_MAGNIFIER, + TYPE_INTEGER, CONF_VALUE_INTEGER_1, &li.magnify_score, 10 }, { - EL_EMC_MAGNIFIER, CONF_VALUE_INTEGER_2, + EL_EMC_MAGNIFIER, + TYPE_INTEGER, CONF_VALUE_INTEGER_2, &li.magnify_time, 10 }, { - EL_ROBOT, CONF_VALUE_INTEGER_1, + EL_ROBOT, + TYPE_INTEGER, CONF_VALUE_INTEGER_1, &li.slurp_score, 10 }, { - EL_GAME_OF_LIFE, CONF_VALUE_INTEGER_1, + EL_GAME_OF_LIFE, + TYPE_INTEGER, CONF_VALUE_INTEGER_1, &li.game_of_life[0], 2 }, { - EL_GAME_OF_LIFE, CONF_VALUE_INTEGER_2, + EL_GAME_OF_LIFE, + TYPE_INTEGER, CONF_VALUE_INTEGER_2, &li.game_of_life[1], 3 }, { - EL_GAME_OF_LIFE, CONF_VALUE_INTEGER_3, + EL_GAME_OF_LIFE, + TYPE_INTEGER, CONF_VALUE_INTEGER_3, &li.game_of_life[2], 3 }, { - EL_GAME_OF_LIFE, CONF_VALUE_INTEGER_4, + EL_GAME_OF_LIFE, + TYPE_INTEGER, CONF_VALUE_INTEGER_4, &li.game_of_life[3], 3 }, { - EL_BIOMAZE, CONF_VALUE_INTEGER_1, + EL_BIOMAZE, + TYPE_INTEGER, CONF_VALUE_INTEGER_1, &li.biomaze[0], 2 }, { - EL_BIOMAZE, CONF_VALUE_INTEGER_2, + EL_BIOMAZE, + TYPE_INTEGER, CONF_VALUE_INTEGER_2, &li.biomaze[1], 3 }, { - EL_BIOMAZE, CONF_VALUE_INTEGER_3, + EL_BIOMAZE, + TYPE_INTEGER, CONF_VALUE_INTEGER_3, &li.biomaze[2], 3 }, { - EL_BIOMAZE, CONF_VALUE_INTEGER_4, + EL_BIOMAZE, + TYPE_INTEGER, CONF_VALUE_INTEGER_4, &li.biomaze[3], 3 }, { - EL_BALLOON, CONF_VALUE_INTEGER_1, + EL_BALLOON, + TYPE_BITFIELD, CONF_VALUE_INTEGER_1, &li.wind_direction_initial, MV_NONE }, { - EL_TIMEGATE_SWITCH, CONF_VALUE_INTEGER_1, + EL_TIMEGATE_SWITCH, + TYPE_INTEGER, CONF_VALUE_INTEGER_1, &li.time_timegate, 10 }, { - EL_LIGHT_SWITCH_ACTIVE, CONF_VALUE_INTEGER_1, + EL_LIGHT_SWITCH_ACTIVE, + TYPE_INTEGER, CONF_VALUE_INTEGER_1, &li.time_light, 10 }, { - EL_SHIELD_NORMAL, CONF_VALUE_INTEGER_1, + EL_SHIELD_NORMAL, + TYPE_INTEGER, CONF_VALUE_INTEGER_1, &li.shield_normal_time, 10 }, { - EL_SHIELD_DEADLY, CONF_VALUE_INTEGER_1, + EL_SHIELD_DEADLY, + TYPE_INTEGER, CONF_VALUE_INTEGER_1, &li.shield_deadly_time, 10 }, { - EL_EXTRA_TIME, CONF_VALUE_INTEGER_1, + EL_EXTRA_TIME, + TYPE_INTEGER, CONF_VALUE_INTEGER_1, &li.extra_time, 10 }, { - EL_EXTRA_TIME, CONF_VALUE_INTEGER_2, + EL_EXTRA_TIME, + TYPE_INTEGER, CONF_VALUE_INTEGER_2, &li.extra_time_score, 10 }, { - EL_TIME_ORB_FULL, CONF_VALUE_INTEGER_1, + EL_TIME_ORB_FULL, + TYPE_INTEGER, CONF_VALUE_INTEGER_1, &li.time_orb_time, 10 }, { - EL_TIME_ORB_FULL, CONF_VALUE_BOOLEAN_1, + EL_TIME_ORB_FULL, + TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_1, &li.use_time_orb_bug, FALSE }, { - EL_PLAYER_1, CONF_VALUE_BOOLEAN_1, + EL_PLAYER_1, + TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_1, &li.block_snap_field, TRUE }, { - EL_PLAYER_1, CONF_VALUE_BOOLEAN_2, + EL_PLAYER_1, + TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_2, &li.use_start_element[0], FALSE }, { - EL_PLAYER_2, CONF_VALUE_BOOLEAN_2, + EL_PLAYER_2, + TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_2, &li.use_start_element[1], FALSE }, { - EL_PLAYER_3, CONF_VALUE_BOOLEAN_2, + EL_PLAYER_3, + TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_2, &li.use_start_element[2], FALSE }, { - EL_PLAYER_4, CONF_VALUE_BOOLEAN_2, + EL_PLAYER_4, + TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_2, &li.use_start_element[3], FALSE }, { - EL_EMC_MAGIC_BALL, CONF_VALUE_INTEGER_1, - &li.ball_time, 10 + EL_PLAYER_1, + TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_3, + &li.use_artwork_element[0], FALSE + }, + { + EL_PLAYER_2, + TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_3, + &li.use_artwork_element[1], FALSE + }, + { + EL_PLAYER_3, + TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_3, + &li.use_artwork_element[2], FALSE + }, + { + EL_PLAYER_4, + TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_3, + &li.use_artwork_element[3], FALSE + }, + { + EL_PLAYER_1, + TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_4, + &li.use_explosion_element[0], FALSE + }, + { + EL_PLAYER_2, + TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_4, + &li.use_explosion_element[1], FALSE + }, + { + EL_PLAYER_3, + TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_4, + &li.use_explosion_element[2], FALSE + }, + { + EL_PLAYER_4, + TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_4, + &li.use_explosion_element[3], FALSE + }, + { + EL_PLAYER_1, + TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_5, + &li.continuous_snapping, TRUE + }, + { + EL_PLAYER_1, + TYPE_INTEGER, CONF_VALUE_INTEGER_1, + &li.initial_player_stepsize, STEPSIZE_NORMAL }, { - EL_EMC_MAGIC_BALL, CONF_VALUE_INTEGER_2, - &li.num_ball_contents, 8 + EL_EMC_MAGIC_BALL, + TYPE_INTEGER, CONF_VALUE_INTEGER_1, + &li.ball_time, 10 }, { - EL_EMC_MAGIC_BALL, CONF_VALUE_BOOLEAN_1, + EL_EMC_MAGIC_BALL, + TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_1, &li.ball_random, FALSE }, { - EL_EMC_MAGIC_BALL, CONF_VALUE_BOOLEAN_2, + EL_EMC_MAGIC_BALL, + TYPE_BOOLEAN, CONF_VALUE_BOOLEAN_2, &li.ball_state_initial, FALSE }, /* ---------- 2-byte values ---------------------------------------------- */ + { - EL_PLAYER_1, CONF_VALUE_ELEMENT_1, + EL_PLAYER_1, + TYPE_ELEMENT, CONF_VALUE_ELEMENT_1, &li.start_element[0], EL_PLAYER_1 }, { - EL_PLAYER_2, CONF_VALUE_ELEMENT_1, + EL_PLAYER_2, + TYPE_ELEMENT, CONF_VALUE_ELEMENT_1, &li.start_element[1], EL_PLAYER_2 }, { - EL_PLAYER_3, CONF_VALUE_ELEMENT_1, + EL_PLAYER_3, + TYPE_ELEMENT, CONF_VALUE_ELEMENT_1, &li.start_element[2], EL_PLAYER_3 }, { - EL_PLAYER_4, CONF_VALUE_ELEMENT_1, + EL_PLAYER_4, + TYPE_ELEMENT, CONF_VALUE_ELEMENT_1, &li.start_element[3], EL_PLAYER_4 }, + { + EL_PLAYER_1, + TYPE_ELEMENT, CONF_VALUE_ELEMENT_2, + &li.artwork_element[0], EL_PLAYER_1 + }, + { + EL_PLAYER_2, + TYPE_ELEMENT, CONF_VALUE_ELEMENT_2, + &li.artwork_element[1], EL_PLAYER_2 + }, + { + EL_PLAYER_3, + TYPE_ELEMENT, CONF_VALUE_ELEMENT_2, + &li.artwork_element[2], EL_PLAYER_3 + }, + { + EL_PLAYER_4, + TYPE_ELEMENT, CONF_VALUE_ELEMENT_2, + &li.artwork_element[3], EL_PLAYER_4 + }, + { + EL_PLAYER_1, + TYPE_ELEMENT, CONF_VALUE_ELEMENT_3, + &li.explosion_element[0], EL_PLAYER_1 + }, + { + EL_PLAYER_2, + TYPE_ELEMENT, CONF_VALUE_ELEMENT_3, + &li.explosion_element[1], EL_PLAYER_2 + }, + { + EL_PLAYER_3, + TYPE_ELEMENT, CONF_VALUE_ELEMENT_3, + &li.explosion_element[2], EL_PLAYER_3 + }, + { + EL_PLAYER_4, + TYPE_ELEMENT, CONF_VALUE_ELEMENT_3, + &li.explosion_element[3], EL_PLAYER_4 + }, /* ---------- multi-byte values ------------------------------------------ */ + + { + EL_EMC_ANDROID, + TYPE_ELEMENT_LIST, CONF_VALUE_BYTES(1), + &li.android_clone_element[0], EL_EMPTY, + &li.num_android_clone_elements, 1, MAX_ANDROID_ELEMENTS + }, + { + EL_EMC_MAGIC_BALL, + TYPE_CONTENT_LIST, CONF_VALUE_BYTES(2), + &li.ball_content, EL_EMPTY, + &li.num_ball_contents, 4, MAX_ELEMENT_CONTENTS + }, + + { + -1, + -1, -1, + NULL, -1, + }, +}; + +static struct ElementFileConfig custom_element_conf[] = +{ + { + -1, + TYPE_STRING, CONF_VALUE_BYTES(1), + &xx_ei.description[0], 0, + &xx_num_description_bytes, MAX_ELEMENT_NAME_LEN, MAX_ELEMENT_NAME_LEN, + }, + + { + -1, + TYPE_BITFIELD, CONF_VALUE_32_BIT(1), + &xx_ei.properties[EP_BITFIELD_BASE], +#if 0 + EP_BITMASK_DEFAULT +#else + (1 << EP_CAN_MOVE_INTO_ACID) +#endif + }, +#if 0 + /* (reserved) */ + { + -1, + TYPE_BITFIELD, CONF_VALUE_32_BIT(2), + &xx_ei.properties[EP_BITFIELD_BASE + 1], EP_BITMASK_DEFAULT + }, +#endif + + { + -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(1), + &xx_ei.use_gfx_element, FALSE + }, + { + -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(1), + &xx_ei.gfx_element, EL_EMPTY_SPACE + }, + + { + -1, + TYPE_BITFIELD, CONF_VALUE_8_BIT(2), + &xx_ei.access_direction, MV_ALL_DIRECTIONS + }, + + { + -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(2), + &xx_ei.collect_score_initial, 10 + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(3), + &xx_ei.collect_count_initial, 1 + }, + + { + -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(4), + &xx_ei.ce_value_fixed_initial, 0 + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(5), + &xx_ei.ce_value_random_initial, 0 + }, + { + -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(3), + &xx_ei.use_last_ce_value, FALSE + }, + + { + -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(6), + &xx_ei.push_delay_fixed, 8, + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(7), + &xx_ei.push_delay_random, 8, + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(8), + &xx_ei.drop_delay_fixed, 0 + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(9), + &xx_ei.drop_delay_random, 0 + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(10), + &xx_ei.move_delay_fixed, 0 + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(11), + &xx_ei.move_delay_random, 0 + }, + + { + -1, + TYPE_BITFIELD, CONF_VALUE_32_BIT(3), + &xx_ei.move_pattern, MV_ALL_DIRECTIONS + }, + { + -1, + TYPE_BITFIELD, CONF_VALUE_8_BIT(4), + &xx_ei.move_direction_initial, MV_START_AUTOMATIC + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(5), + &xx_ei.move_stepsize, TILEX / 8 + }, + + { + -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(12), + &xx_ei.move_enter_element, EL_EMPTY_SPACE + }, + { + -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(13), + &xx_ei.move_leave_element, EL_EMPTY_SPACE + }, { - EL_EMC_MAGIC_BALL, CONF_VALUE_CONTENT_8, - &li.ball_content, EL_EMPTY + -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(6), + &xx_ei.move_leave_type, LEAVE_TYPE_UNLIMITED }, { + -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(7), + &xx_ei.slippery_type, SLIPPERY_ANY_RANDOM + }, + + { + -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(8), + &xx_ei.explosion_type, EXPLODES_3X3 + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(14), + &xx_ei.explosion_delay, 16 + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(15), + &xx_ei.ignition_delay, 8 + }, + + { + -1, + TYPE_CONTENT_LIST, CONF_VALUE_BYTES(2), + &xx_ei.content, EL_EMPTY_SPACE, + &xx_num_contents, 1, 1 + }, + + /* ---------- "num_change_pages" must be the last entry ------------------- */ + + { + -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(9), + &xx_ei.num_change_pages, -1 /* always save this value */ + }, + + { + -1, -1, -1, - NULL, -1 + NULL, -1, + }, +}; + +static struct ElementFileConfig custom_element_change_conf[] = +{ + /* ---------- "current_change_page" must be the first entry --------------- */ + + { + -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(1), + &xx_current_change_page, -1 + }, + + { + -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(2), + &xx_change.can_change, FALSE + }, + + { + -1, + TYPE_BITFIELD, CONF_VALUE_32_BIT(1), + &xx_event_bits_0_31, 0 + }, + { + -1, + TYPE_BITFIELD, CONF_VALUE_32_BIT(2), + &xx_event_bits_32_63, 0 + }, + + { + -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(3), + &xx_change.trigger_player, CH_PLAYER_ANY + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(4), + &xx_change.trigger_side, CH_SIDE_ANY + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(5), + &xx_change.trigger_page, CH_PAGE_ANY + }, + + { + -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(1), + &xx_change.target_element, EL_EMPTY_SPACE + }, + + { + -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(2), + &xx_change.delay_fixed, 0 + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(3), + &xx_change.delay_random, 0 + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(4), + &xx_change.delay_frames, FRAMES_PER_SECOND + }, + + { + -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(5), + &xx_change.trigger_element, EL_EMPTY_SPACE + }, + + { + -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(6), + &xx_change.explode, FALSE + }, + { + -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(7), + &xx_change.use_target_content, FALSE + }, + { + -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(8), + &xx_change.only_if_complete, FALSE + }, + { + -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(9), + &xx_change.use_random_replace, FALSE + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(10), + &xx_change.random_percentage, 100 + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(11), + &xx_change.replace_when, CP_WHEN_EMPTY + }, + + { + -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(12), + &xx_change.has_action, FALSE + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(13), + &xx_change.action_type, CA_NO_ACTION + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(14), + &xx_change.action_mode, CA_MODE_UNDEFINED + }, + { + -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(6), + &xx_change.action_arg, CA_ARG_UNDEFINED + }, + + { + -1, + TYPE_CONTENT_LIST, CONF_VALUE_BYTES(1), + &xx_change.target_content, EL_EMPTY_SPACE, + &xx_num_contents, 1, 1 + }, + + { + -1, + -1, -1, + NULL, -1, + }, +}; + +static struct ElementFileConfig group_element_conf[] = +{ + { + -1, + TYPE_STRING, CONF_VALUE_BYTES(1), + &xx_ei.description[0], 0, + &xx_num_description_bytes, MAX_ELEMENT_NAME_LEN, MAX_ELEMENT_NAME_LEN, + }, + + { + -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(1), + &xx_ei.use_gfx_element, FALSE + }, + { + -1, + TYPE_ELEMENT, CONF_VALUE_16_BIT(1), + &xx_ei.gfx_element, EL_EMPTY_SPACE + }, + + { + -1, + TYPE_INTEGER, CONF_VALUE_8_BIT(2), + &xx_group.choice_mode, ANIM_RANDOM + }, + + { + -1, + TYPE_ELEMENT_LIST, CONF_VALUE_BYTES(2), + &xx_group.element[0], EL_EMPTY_SPACE, + &xx_group.num_elements, 1, MAX_ELEMENTS_IN_GROUP + }, + + { + -1, + -1, -1, + NULL, -1, }, }; @@ -296,34 +860,51 @@ static void setLevelInfoToDefaultsFromConfigList(struct LevelInfo *level) { int i; - li = *level; /* copy level information into temporary buffer */ + li = *level; /* copy level data into temporary buffer */ - for (i = 0; element_conf[i].element != -1; i++) + for (i = 0; element_conf[i].data_type != -1; i++) { int default_value = element_conf[i].default_value; - int type = element_conf[i].type; - int bytes = type & CONF_MASK_BYTES; + int data_type = element_conf[i].data_type; + int conf_type = element_conf[i].conf_type; + int byte_mask = conf_type & CONF_MASK_BYTES; + + if (byte_mask == CONF_MASK_MULTI_BYTES) + { + int default_num_entities = element_conf[i].default_num_entities; + int max_num_entities = element_conf[i].max_num_entities; + + *(int *)(element_conf[i].num_entities) = default_num_entities; + + if (data_type == TYPE_ELEMENT_LIST) + { + int *element_array = (int *)(element_conf[i].value); + int j; + + for (j = 0; j < max_num_entities; j++) + element_array[j] = default_value; + } + else if (data_type == TYPE_CONTENT_LIST) + { + struct Content *content = (struct Content *)(element_conf[i].value); + int c, x, y; - if (bytes != CONF_MASK_MULTI_BYTES) + for (c = 0; c < max_num_entities; c++) + for (y = 0; y < 3; y++) + for (x = 0; x < 3; x++) + content[c].e[x][y] = default_value; + } + } + else /* constant size configuration data (1, 2 or 4 bytes) */ { - if (CONF_VALUE_BOOLEAN(type)) + if (data_type == TYPE_BOOLEAN) *(boolean *)(element_conf[i].value) = default_value; else *(int *) (element_conf[i].value) = default_value; } - else if (type == CONF_VALUE_CONTENT_8) - { - struct Content *content = (struct Content *)(element_conf[i].value); - int c, x, y; - - for (c = 0; c < MAX_ELEMENT_CONTENTS; c++) - for (y = 0; y < 3; y++) - for (x = 0; x < 3; x++) - content[c].e[x][y] = default_value; - } } - *level = li; /* copy temporary buffer back to level information */ + *level = li; /* copy temporary buffer back to level data */ } void setElementChangePages(struct ElementInfo *ei, int change_pages) @@ -440,14 +1021,18 @@ static void setLevelInfoToDefaults(struct LevelInfo *level) level->biomaze[2] = 3; level->biomaze[3] = 3; +#if 0 level->double_speed = FALSE; +#endif level->initial_gravity = FALSE; level->em_slippery_gems = FALSE; level->instant_relocation = FALSE; level->can_pass_to_walkable = FALSE; level->grow_into_diggable = TRUE; +#if 0 level->block_snap_field = TRUE; +#endif level->block_last_field = FALSE; /* EM does not block by default */ level->sp_block_last_field = TRUE; /* SP blocks the last field */ @@ -478,8 +1063,10 @@ static void setLevelInfoToDefaults(struct LevelInfo *level) for (y = 0; y < 3; y++) level->ball_content[i].e[x][y] = EL_EMPTY; #endif +#if 0 for (i = 0; i < 16; i++) level->android_array[i] = FALSE; +#endif level->use_custom_template = FALSE; @@ -595,8 +1182,13 @@ static void setLevelInfoToDefaults(struct LevelInfo *level) /* !!! now done in InitElementPropertiesStatic() (see above) !!! */ /* !!! (else properties set there will be overwritten here) !!! */ /* start with no properties at all */ +#if 1 + for (j = 0; j < NUM_EP_BITFIELDS; j++) + ei->properties[j] = EP_BITMASK_DEFAULT; +#else for (j = 0; j < NUM_EP_BITFIELDS; j++) Properties[element][j] = EP_BITMASK_DEFAULT; +#endif #endif /* now set default properties */ @@ -636,7 +1228,7 @@ static void setLevelInfoToDefaults(struct LevelInfo *level) return; /* try to determine better author name than 'anonymous' */ - if (strcmp(leveldir_current->author, ANONYMOUS_NAME) != 0) + if (!strEqual(leveldir_current->author, ANONYMOUS_NAME)) { strncpy(level->author, leveldir_current->author, MAX_LEVEL_AUTHOR_LEN); level->author[MAX_LEVEL_AUTHOR_LEN] = '\0'; @@ -677,9 +1269,15 @@ static void setFileInfoToDefaults(struct LevelFileInfo *level_file_info) static void ActivateLevelTemplate() { +#if 1 + /* Currently there is no special action needed to activate the template + data, because 'element_info' property settings overwrite the original + level data, while all other variables do not change. */ +#else /* Currently there is no special action needed to activate the template data, because 'element_info' and 'Properties' overwrite the original level data, while all other variables do not change. */ +#endif } static char *getLevelFilenameFromBasename(char *basename) @@ -838,7 +1436,7 @@ static int getFiletypeFromID(char *filetype_id) { char *id_lower = getStringToLower(filetype_id_list[i].id); - if (strcmp(filetype_id_lower, id_lower) == 0) + if (strEqual(filetype_id_lower, id_lower)) filetype = filetype_id_list[i].filetype; free(id_lower); @@ -1056,7 +1654,10 @@ static int LoadLevel_HEAD(FILE *file, int chunk_size, struct LevelInfo *level) level->time_magic_wall = getFile8Bit(file); level->time_wheel = getFile8Bit(file); level->amoeba_content = getMappedElement(getFile8Bit(file)); - level->double_speed = (getFile8Bit(file) == 1 ? TRUE : FALSE); + + level->initial_player_stepsize = (getFile8Bit(file) == 1 ? STEPSIZE_FAST : + STEPSIZE_NORMAL); + 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); @@ -1255,10 +1856,17 @@ static int LoadLevel_CUS1(FILE *file, int chunk_size, struct LevelInfo *level) int element = getFile16BitBE(file); int properties = getFile32BitBE(file); +#if 1 + if (IS_CUSTOM_ELEMENT(element)) + element_info[element].properties[EP_BITFIELD_BASE] = properties; + else + Error(ERR_WARN, "invalid custom element number %d", element); +#else if (IS_CUSTOM_ELEMENT(element)) Properties[element][EP_BITFIELD_BASE] = properties; else Error(ERR_WARN, "invalid custom element number %d", element); +#endif } return chunk_size; @@ -1306,7 +1914,7 @@ static int LoadLevel_CUS3(FILE *file, int chunk_size, struct LevelInfo *level) { int element = getFile16BitBE(file); struct ElementInfo *ei = &element_info[element]; - unsigned long event_bits; + unsigned int event_bits; if (!IS_CUSTOM_ELEMENT(element)) { @@ -1319,7 +1927,11 @@ static int LoadLevel_CUS3(FILE *file, int chunk_size, struct LevelInfo *level) ei->description[j] = getFile8Bit(file); ei->description[MAX_ELEMENT_NAME_LEN] = 0; +#if 1 + ei->properties[EP_BITFIELD_BASE] = getFile32BitBE(file); +#else Properties[element][EP_BITFIELD_BASE] = getFile32BitBE(file); +#endif /* some free bytes for future properties and padding */ ReadUnusedBytesFromFile(file, 7); @@ -1406,7 +2018,11 @@ static int LoadLevel_CUS4(FILE *file, int chunk_size, struct LevelInfo *level) ei->description[i] = getFile8Bit(file); ei->description[MAX_ELEMENT_NAME_LEN] = 0; +#if 1 + ei->properties[EP_BITFIELD_BASE] = getFile32BitBE(file); +#else Properties[element][EP_BITFIELD_BASE] = getFile32BitBE(file); +#endif ReadUnusedBytesFromFile(file, 4); /* reserved for more base properties */ ei->num_change_pages = getFile8Bit(file); @@ -1469,7 +2085,7 @@ static int LoadLevel_CUS4(FILE *file, int chunk_size, struct LevelInfo *level) for (i = 0; i < ei->num_change_pages; i++) { struct ElementChangeInfo *change = &ei->change_page[i]; - unsigned long event_bits; + unsigned int event_bits; /* always start with reliable default values */ setElementChangeInfoToDefaults(change); @@ -1545,74 +2161,219 @@ static int LoadLevel_GRP1(FILE *file, int chunk_size, struct LevelInfo *level) return chunk_size; } - ei = &element_info[element]; + ei = &element_info[element]; + + for (i = 0; i < MAX_ELEMENT_NAME_LEN; i++) + ei->description[i] = getFile8Bit(file); + ei->description[MAX_ELEMENT_NAME_LEN] = 0; + + group = element_info[element].group; + + group->num_elements = getFile8Bit(file); + + ei->use_gfx_element = getFile8Bit(file); + ei->gfx_element = getMappedElement(getFile16BitBE(file)); + + group->choice_mode = getFile8Bit(file); + + /* some free bytes for future values and padding */ + ReadUnusedBytesFromFile(file, 3); + + for (i = 0; i < MAX_ELEMENTS_IN_GROUP; i++) + group->element[i] = getMappedElement(getFile16BitBE(file)); + + /* mark this group element as modified */ + element_info[element].modified_settings = TRUE; + + return chunk_size; +} + +static int LoadLevel_MicroChunk(FILE *file, struct ElementFileConfig *config, + int element) +{ + int micro_chunk_size = 0; + int conf_type = getFile8Bit(file); + int byte_mask = conf_type & CONF_MASK_BYTES; + boolean element_found = FALSE; + int i; + + micro_chunk_size += 1; + + if (byte_mask == CONF_MASK_MULTI_BYTES) + { + int num_bytes = getFile16BitBE(file); + byte *buffer = checked_malloc(num_bytes); + +#if 1 + printf("::: - found multi bytes\n"); +#endif + + ReadBytesFromFile(file, buffer, num_bytes); + + for (i = 0; config[i].data_type != -1; i++) + { + if (config[i].element == element && + config[i].conf_type == conf_type) + { + int data_type = config[i].data_type; + int num_entities = num_bytes / CONF_ENTITY_NUM_BYTES(data_type); + int max_num_entities = config[i].max_num_entities; + + if (num_entities > max_num_entities) + { + Error(ERR_WARN, + "truncating number of entities for element %d from %d to %d", + element, num_entities, max_num_entities); + + num_entities = max_num_entities; + } + + *(int *)(config[i].num_entities) = num_entities; + + element_found = TRUE; + + if (data_type == TYPE_ELEMENT_LIST) + { + int *element_array = (int *)(config[i].value); + int j; + + for (j = 0; j < num_entities; j++) + element_array[j] = + getMappedElement(CONF_ELEMENTS_ELEMENT(buffer, j)); + } + else if (data_type == TYPE_CONTENT_LIST) + { + struct Content *content= (struct Content *)(config[i].value); + int c, x, y; + + for (c = 0; c < num_entities; c++) + for (y = 0; y < 3; y++) + for (x = 0; x < 3; x++) + content[c].e[x][y] = + getMappedElement(CONF_CONTENTS_ELEMENT(buffer, c, x, y)); + } + else + element_found = FALSE; + + break; + } + } + + checked_free(buffer); - for (i = 0; i < MAX_ELEMENT_NAME_LEN; i++) - ei->description[i] = getFile8Bit(file); - ei->description[MAX_ELEMENT_NAME_LEN] = 0; + micro_chunk_size += 2 + num_bytes; + } + else /* constant size configuration data (1, 2 or 4 bytes) */ + { + int value = (byte_mask == CONF_MASK_1_BYTE ? getFile8Bit (file) : + byte_mask == CONF_MASK_2_BYTE ? getFile16BitBE(file) : + byte_mask == CONF_MASK_4_BYTE ? getFile32BitBE(file) : 0); - group = element_info[element].group; +#if 1 + printf("::: - found single bytes\n"); +#endif - group->num_elements = getFile8Bit(file); + for (i = 0; config[i].data_type != -1; i++) + { + if (config[i].element == element && + config[i].conf_type == conf_type) + { + int data_type = config[i].data_type; - ei->use_gfx_element = getFile8Bit(file); - ei->gfx_element = getMappedElement(getFile16BitBE(file)); + if (data_type == TYPE_BOOLEAN) + *(boolean *)(config[i].value) = value; + else + *(int *) (config[i].value) = value; - group->choice_mode = getFile8Bit(file); + element_found = TRUE; - /* some free bytes for future values and padding */ - ReadUnusedBytesFromFile(file, 3); + break; + } + } - for (i = 0; i < MAX_ELEMENTS_IN_GROUP; i++) - group->element[i] = getMappedElement(getFile16BitBE(file)); + micro_chunk_size += CONF_VALUE_NUM_BYTES(byte_mask); + } - /* mark this group element as modified */ - element_info[element].modified_settings = TRUE; + if (!element_found) + Error(ERR_WARN, "cannot load micro chunk value for element %d", element); - return chunk_size; + return micro_chunk_size; } static int LoadLevel_CONF(FILE *file, int chunk_size, struct LevelInfo *level) { int real_chunk_size = 0; - int i; + +#if 1 + li = *level; /* copy level data into temporary buffer */ +#endif while (!feof(file)) { int element = getFile16BitBE(file); - int type = getFile8Bit(file); - int bytes = type & CONF_MASK_BYTES; +#if 1 + real_chunk_size += 2; + real_chunk_size += LoadLevel_MicroChunk(file, element_conf, element); +#else + int conf_type = getFile8Bit(file); + int byte_mask = conf_type & CONF_MASK_BYTES; boolean element_found = FALSE; + int i; real_chunk_size += 3; - li = *level; /* copy level information into temporary buffer */ +#if 0 + li = *level; /* copy level data into temporary buffer */ +#endif - if (bytes == CONF_MASK_MULTI_BYTES) + if (byte_mask == CONF_MASK_MULTI_BYTES) { int num_bytes = getFile16BitBE(file); byte *buffer = checked_malloc(num_bytes); ReadBytesFromFile(file, buffer, num_bytes); - for (i = 0; element_conf[i].element != -1; i++) + for (i = 0; element_conf[i].data_type != -1; i++) { if (element_conf[i].element == element && - element_conf[i].type == type) + element_conf[i].conf_type == conf_type) { + int data_type = element_conf[i].data_type; + int num_entities = num_bytes / CONF_ENTITY_NUM_BYTES(data_type); + int max_num_entities = element_conf[i].max_num_entities; + + if (num_entities > max_num_entities) + { + Error(ERR_WARN, + "truncating number of entities for element %d from %d to %d", + element, num_entities, max_num_entities); + + num_entities = max_num_entities; + } + + *(int *)(element_conf[i].num_entities) = num_entities; + element_found = TRUE; - if (type == CONF_VALUE_CONTENT_8) + if (data_type == TYPE_ELEMENT_LIST) + { + int *element_array = (int *)(element_conf[i].value); + int j; + + for (j = 0; j < num_entities; j++) + element_array[j] = + getMappedElement(CONF_ELEMENTS_ELEMENT(buffer, j)); + } + else if (data_type == TYPE_CONTENT_LIST) { struct Content *content= (struct Content *)(element_conf[i].value); - int num_contents = num_bytes / CONF_CONTENT_NUM_BYTES; int c, x, y; - for (c = 0; c < num_contents; c++) + for (c = 0; c < num_entities; c++) for (y = 0; y < 3; y++) for (x = 0; x < 3; x++) content[c].e[x][y] = - getMappedElement(CONF_CONTENT_ELEMENT(buffer, c, x, y)); + getMappedElement(CONF_CONTENTS_ELEMENT(buffer, c, x, y)); } else element_found = FALSE; @@ -1625,18 +2386,20 @@ static int LoadLevel_CONF(FILE *file, int chunk_size, struct LevelInfo *level) real_chunk_size += 2 + num_bytes; } - else + else /* constant size configuration data (1, 2 or 4 bytes) */ { - int value = (bytes == CONF_MASK_1_BYTE ? getFile8Bit (file) : - bytes == CONF_MASK_2_BYTE ? getFile16BitBE(file) : - bytes == CONF_MASK_4_BYTE ? getFile32BitBE(file) : 0); + int value = (byte_mask == CONF_MASK_1_BYTE ? getFile8Bit (file) : + byte_mask == CONF_MASK_2_BYTE ? getFile16BitBE(file) : + byte_mask == CONF_MASK_4_BYTE ? getFile32BitBE(file) : 0); - for (i = 0; element_conf[i].element != -1; i++) + for (i = 0; element_conf[i].data_type != -1; i++) { if (element_conf[i].element == element && - element_conf[i].type == type) + element_conf[i].conf_type == conf_type) { - if (CONF_VALUE_BOOLEAN(type)) + int data_type = element_conf[i].data_type; + + if (data_type == TYPE_BOOLEAN) *(boolean *)(element_conf[i].value) = value; else *(int *) (element_conf[i].value) = value; @@ -1647,18 +2410,129 @@ static int LoadLevel_CONF(FILE *file, int chunk_size, struct LevelInfo *level) } } - real_chunk_size += CONF_VALUE_NUM_BYTES(bytes); + real_chunk_size += CONF_VALUE_NUM_BYTES(byte_mask); } - *level = li; /* copy temporary buffer back to level information */ - if (!element_found) Error(ERR_WARN, "cannot load CONF value for element %d", element); +#endif + +#if 0 + *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 + *level = li; /* copy temporary buffer back to level data */ +#endif + + return real_chunk_size; +} + +static int LoadLevel_CUSX(FILE *file, int chunk_size, struct LevelInfo *level) +{ + int element = getFile16BitBE(file); + int real_chunk_size = 2; + struct ElementInfo *ei = &element_info[element]; + +#if 1 + printf("::: CUSX: loading element '%s' ...\n", EL_NAME(element)); +#endif + + xx_ei = *ei; /* copy element data into temporary buffer */ + + xx_ei.num_change_pages = -1; + + while (!feof(file)) + { + real_chunk_size += LoadLevel_MicroChunk(file, custom_element_conf, -1); + +#if 1 + printf("::: - real_chunk_size now %d\n", real_chunk_size); +#endif + + if (xx_ei.num_change_pages != -1) + break; + + if (real_chunk_size >= chunk_size) + break; + } + + *ei = xx_ei; + + if (ei->num_change_pages == -1) + { + Error(ERR_WARN, "LoadLevel_CUSX(): missing 'num_change_pages' for '%s'", + EL_NAME(element)); + + ei->num_change_pages = 1; + setElementChangePages(ei, 1); + + return real_chunk_size; + } + + setElementChangePages(ei, ei->num_change_pages); - if (type == CONF_LAST_ENTRY || real_chunk_size >= chunk_size) + xx_current_change_page = 0; + + xx_event_bits_0_31 = 0; + xx_event_bits_32_63 = 0; + + while (!feof(file)) + { + struct ElementChangeInfo *change = &ei->change_page[xx_current_change_page]; + int i; + + xx_change = *change; /* copy change data into temporary buffer */ + + real_chunk_size += LoadLevel_MicroChunk(file,custom_element_change_conf,-1); + + *change = xx_change; + + for (i = 0; i < NUM_CHANGE_EVENTS; i++) + if ((i < 32 && xx_event_bits_0_31 & (1 << i)) || + (i >= 32 && xx_event_bits_32_63 & (1 << (i - 32)))) + change->has_event[i] = TRUE; + + xx_event_bits_0_31 = 0; + xx_event_bits_32_63 = 0; + + if (real_chunk_size >= chunk_size) + break; + } + + return real_chunk_size; +} + +static int LoadLevel_GRPX(FILE *file, int chunk_size, struct LevelInfo *level) +{ + int element = getFile16BitBE(file); + int real_chunk_size = 2; + struct ElementInfo *ei = &element_info[element]; + struct ElementGroupInfo *group = ei->group; + + xx_ei = *ei; /* copy element data into temporary buffer */ + xx_group = *group; /* copy group data into temporary buffer */ + + while (!feof(file)) + { + real_chunk_size += LoadLevel_MicroChunk(file, group_element_conf, -1); + + if (real_chunk_size >= chunk_size) break; } + *ei = xx_ei; + *group = xx_group; + return real_chunk_size; } @@ -1682,12 +2556,12 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level, } getFileChunkBE(file, chunk_name, NULL); - if (strcmp(chunk_name, "RND1") == 0) + if (strEqual(chunk_name, "RND1")) { getFile32BitBE(file); /* not used */ getFileChunkBE(file, chunk_name, NULL); - if (strcmp(chunk_name, "CAVE") != 0) + if (!strEqual(chunk_name, "CAVE")) { level->no_valid_file = TRUE; @@ -1754,6 +2628,10 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level, { "CUS4", -1, LoadLevel_CUS4 }, { "GRP1", -1, LoadLevel_GRP1 }, { "CONF", -1, LoadLevel_CONF }, +#if 1 + { "CUSX", -1, LoadLevel_CUSX }, + { "GRPX", -1, LoadLevel_GRPX }, +#endif { NULL, 0, NULL } }; @@ -1763,7 +2641,7 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level, int i = 0; while (chunk_info[i].name != NULL && - strcmp(chunk_name, chunk_info[i].name) != 0) + !strEqual(chunk_name, chunk_info[i].name)) i++; if (chunk_info[i].name == NULL) @@ -2241,10 +3119,17 @@ void CopyNativeLevel_RND_to_EM(struct LevelInfo *level) }; struct LevelInfo_EM *level_em = level->native_em_level; struct LEVEL *lev = level_em->lev; - struct PLAYER *ply1 = level_em->ply1; - struct PLAYER *ply2 = level_em->ply2; + struct PLAYER **ply = level_em->ply; int i, j, x, y; +#if 0 + printf("::: A\n"); + for (i = 0; i < MAX_ELEMENT_CONTENTS; i++) + for (j = 0; j < 8; j++) + printf("::: ball %d, %d: %d\n", i, j, + level->ball_content[i].e[ball_xy[j][0]][ball_xy[j][1]]); +#endif + lev->width = MIN(level->fieldx, EM_MAX_CAVE_WIDTH); lev->height = MIN(level->fieldy, EM_MAX_CAVE_HEIGHT); @@ -2297,14 +3182,64 @@ void CopyNativeLevel_RND_to_EM(struct LevelInfo *level) map_element_RND_to_EM(level-> ball_content[i].e[ball_xy[j][0]][ball_xy[j][1]]); +#if 0 + for (i = 0; i < MAX_ELEMENT_CONTENTS; i++) + for (j = 0; j < 8; j++) + printf("::: ball %d, %d: %d\n", i, j, + level->ball_content[i].e[ball_xy[j][0]][ball_xy[j][1]]); +#endif + + map_android_clone_elements_RND_to_EM(level); + +#if 0 for (i = 0; i < 16; i++) lev->android_array[i] = FALSE; /* !!! YET TO COME !!! */ +#endif /* first fill the complete playfield with the default border element */ for (y = 0; y < EM_MAX_CAVE_HEIGHT; y++) for (x = 0; x < EM_MAX_CAVE_WIDTH; x++) level_em->cave[x][y] = ZBORDER; +#if 1 + +#if 0 +#if 1 + LoadLevel_InitPlayfield(); +#else + lev_fieldx = lev->width; /* !!! also in LoadLevel_InitPlayfield() !!! */ + lev_fieldy = lev->height; /* !!! also in LoadLevel_InitPlayfield() !!! */ + SetBorderElement(); /* !!! also in LoadLevel_InitPlayfield() !!! */ +#endif +#endif + +#if 0 + printf("::: BorderElement == %d\n", BorderElement); +#endif + + if (BorderElement == EL_STEELWALL) + { + for (y = 0; y < lev->height + 2; y++) + for (x = 0; x < lev->width + 2; x++) + level_em->cave[x + 1][y + 1] = map_element_RND_to_EM(EL_STEELWALL); + } + + /* then copy the real level contents from level file into the playfield */ + for (y = 0; y < lev->height; y++) for (x = 0; x < lev->width; x++) + { + int new_element = map_element_RND_to_EM(level->field[x][y]); + int offset = (BorderElement == EL_STEELWALL ? 1 : 0); + int xx = x + 1 + offset; + int yy = y + 1 + offset; + + if (level->field[x][y] == EL_AMOEBA_DEAD) + new_element = map_element_RND_to_EM(EL_AMOEBA_WET); + + level_em->cave[xx][yy] = new_element; + } + +#else + /* then copy the real level contents from level file into the playfield */ for (y = 0; y < lev->height; y++) for (x = 0; x < lev->width; x++) { @@ -2316,15 +3251,46 @@ void CopyNativeLevel_RND_to_EM(struct LevelInfo *level) level_em->cave[x + 1][y + 1] = new_element; } +#endif + +#if 1 + + for (i = 0; i < MAX_PLAYERS; i++) + { + ply[i]->x_initial = 0; + ply[i]->y_initial = 0; + } + +#else + ply1->x_initial = 0; ply1->y_initial = 0; ply2->x_initial = 0; ply2->y_initial = 0; +#endif + /* initialize player positions and delete players from the playfield */ for (y = 0; y < lev->height; y++) for (x = 0; x < lev->width; x++) { + +#if 1 + if (ELEM_IS_PLAYER(level->field[x][y])) + { + int player_nr = GET_PLAYER_NR(level->field[x][y]); + int offset = (BorderElement == EL_STEELWALL ? 1 : 0); + int xx = x + 1 + offset; + int yy = y + 1 + offset; + + ply[player_nr]->x_initial = xx; + ply[player_nr]->y_initial = yy; + + level_em->cave[xx][yy] = map_element_RND_to_EM(EL_EMPTY); + } + +#else + #if 1 /* !!! CURRENTLY ONLY SUPPORT FOR ONE PLAYER !!! */ if (ELEM_IS_PLAYER(level->field[x][y])) @@ -2348,6 +3314,17 @@ void CopyNativeLevel_RND_to_EM(struct LevelInfo *level) level_em->cave[x + 1][y + 1] = map_element_RND_to_EM(EL_EMPTY); } #endif + +#endif + + } + + if (BorderElement == EL_STEELWALL) + { +#if 1 + lev->width += 2; + lev->height += 2; +#endif } } @@ -2366,8 +3343,7 @@ void CopyNativeLevel_EM_to_RND(struct LevelInfo *level) }; struct LevelInfo_EM *level_em = level->native_em_level; struct LEVEL *lev = level_em->lev; - struct PLAYER *ply1 = level_em->ply1; - struct PLAYER *ply2 = level_em->ply2; + struct PLAYER **ply = level_em->ply; int i, j, x, y; level->fieldx = MIN(lev->width, MAX_LEV_FIELDX); @@ -2418,13 +3394,33 @@ void CopyNativeLevel_EM_to_RND(struct LevelInfo *level) level->wind_direction_initial = map_direction_EM_to_RND(lev->wind_direction_initial); +#if 0 + printf("::: foo\n"); + for (i = 0; i < MAX_ELEMENT_CONTENTS; i++) + for (j = 0; j < 8; j++) + printf("::: ball %d, %d: %d\n", i, j, + level->ball_content[i].e[ball_xy[j][0]][ball_xy[j][1]]); +#endif + for (i = 0; i < MAX_ELEMENT_CONTENTS; i++) for (j = 0; j < 8; j++) level->ball_content[i].e[ball_xy[j][0]][ball_xy[j][1]] = map_element_EM_to_RND(lev->ball_array[i][j]); +#if 0 + printf("::: bar\n"); + for (i = 0; i < MAX_ELEMENT_CONTENTS; i++) + for (j = 0; j < 8; j++) + printf("::: ball %d, %d: %d\n", i, j, + level->ball_content[i].e[ball_xy[j][0]][ball_xy[j][1]]); +#endif + + map_android_clone_elements_EM_to_RND(level); + +#if 0 for (i = 0; i < 16; i++) level->android_array[i] = FALSE; /* !!! YET TO COME !!! */ +#endif /* convert the playfield (some elements need special treatment) */ for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++) @@ -2437,13 +3433,50 @@ void CopyNativeLevel_EM_to_RND(struct LevelInfo *level) level->field[x][y] = new_element; } +#if 0 + printf("::: bar 0\n"); + for (i = 0; i < MAX_ELEMENT_CONTENTS; i++) + for (j = 0; j < 8; j++) + printf("::: ball %d, %d: %d\n", i, j, + level->ball_content[i].e[ball_xy[j][0]][ball_xy[j][1]]); +#endif + +#if 1 + + for (i = 0; i < MAX_PLAYERS; i++) + { + /* in case of all players set to the same field, use the first player */ + int nr = MAX_PLAYERS - i - 1; + int jx = ply[nr]->x_initial - 1; + int jy = ply[nr]->y_initial - 1; + +#if 0 + printf("::: player %d: %d, %d\n", nr, jx, jy); +#endif + + if (jx != -1 && jy != -1) + level->field[jx][jy] = EL_PLAYER_1 + nr; + } + +#else + /* in case of both players set to the same field, use the first player */ level->field[ply2->x_initial - 1][ply2->y_initial - 1] = EL_PLAYER_2; level->field[ply1->x_initial - 1][ply1->y_initial - 1] = EL_PLAYER_1; +#endif + #if 0 printf("::: native Emerald Mine file version: %d\n", level_em->file_version); #endif + +#if 0 + printf("::: bar 2\n"); + for (i = 0; i < MAX_ELEMENT_CONTENTS; i++) + for (j = 0; j < 8; j++) + printf("::: ball %d, %d: %d\n", i, j, + level->ball_content[i].e[ball_xy[j][0]][ball_xy[j][1]]); +#endif } static void LoadLevelFromFileInfo_EM(struct LevelInfo *level, @@ -2461,6 +3494,30 @@ void CopyNativeLevel_RND_to_Native(struct LevelInfo *level) void CopyNativeLevel_Native_to_RND(struct LevelInfo *level) { + +#if 0 + { + static int ball_xy[8][2] = + { + { 0, 0 }, + { 1, 0 }, + { 2, 0 }, + { 0, 1 }, + { 2, 1 }, + { 0, 2 }, + { 1, 2 }, + { 2, 2 }, + }; + int i, j; + + printf("::: A6\n"); + for (i = 0; i < MAX_ELEMENT_CONTENTS; i++) + for (j = 0; j < 8; j++) + printf("::: ball %d, %d: %d\n", i, j, + level->ball_content[i].e[ball_xy[j][0]][ball_xy[j][1]]); + } +#endif + if (level->game_engine_type == GAME_ENGINE_TYPE_EM) CopyNativeLevel_EM_to_RND(level); } @@ -2617,8 +3674,12 @@ static void LoadLevelFromFileStream_SP(FILE *file, struct LevelInfo *level, level->time_wheel = 0; level->amoeba_content = EL_EMPTY; +#if 1 + /* original Supaplex does not use score values -- use default values */ +#else for (i = 0; i < LEVEL_SCORE_ELEMENTS; i++) level->score[i] = 0; /* !!! CORRECT THIS !!! */ +#endif /* there are no yamyams in supaplex levels */ for (i = 0; i < level->num_yamyam_contents; i++) @@ -2721,7 +3782,7 @@ static void LoadLevelFromFileInfo_SP(struct LevelInfo *level, if (reading_multipart_level && (!is_multipart_level || - strcmp(level->name, multipart_level.name) != 0)) + !strEqual(level->name, multipart_level.name))) { /* we are already reading parts of a multi-part level, but this level is either not a multi-part level, or a part of a different multi-part @@ -2843,10 +3904,15 @@ void LoadLevelFromFileInfo(struct LevelInfo *level, if (level->game_engine_type == GAME_ENGINE_TYPE_UNKNOWN) level->game_engine_type = GAME_ENGINE_TYPE_RND; +#if 1 + if (level_file_info->type != LEVEL_FILE_TYPE_RND) + CopyNativeLevel_Native_to_RND(level); +#else if (level_file_info->type == LEVEL_FILE_TYPE_RND) CopyNativeLevel_RND_to_Native(level); else CopyNativeLevel_Native_to_RND(level); +#endif } void LoadLevelFromFilename(struct LevelInfo *level, char *filename) @@ -2868,6 +3934,19 @@ static void LoadLevel_InitVersion(struct LevelInfo *level, char *filename) if (leveldir_current == NULL) /* only when dumping level */ return; + /* all engine modifications also valid for levels which use latest engine */ +#if 1 + if (level->game_version < VERSION_IDENT(3,2,0,5)) + { + /* time bonus score was given for 10 s instead of 1 s before 3.2.0-5 */ + level->score[SC_TIME_BONUS] /= 10; + } +#endif + +#if 0 + leveldir_current->latest_engine = TRUE; /* !!! TEST ONLY !!! */ +#endif + if (leveldir_current->latest_engine) { /* ---------- use latest game engine ----------------------------------- */ @@ -2909,7 +3988,7 @@ 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->double_speed = TRUE; + level->initial_player_stepsize = 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)) @@ -2930,8 +4009,16 @@ static void LoadLevel_InitVersion(struct LevelInfo *level, char *filename) /* extra time score was same value as time left score before 3.2.0-5 */ level->extra_time_score = level->score[SC_TIME_BONUS]; +#if 0 /* time bonus score was given for 10 s instead of 1 s before 3.2.0-5 */ level->score[SC_TIME_BONUS] /= 10; +#endif + } + + if (level->game_version < VERSION_IDENT(3,2,0,7)) + { + /* default behaviour for snapping was "not continuous" before 3.2.0-7 */ + level->continuous_snapping = FALSE; } /* only few elements were able to actively move into acid before 3.1.0 */ @@ -2985,6 +4072,7 @@ static void LoadLevel_InitElements(struct LevelInfo *level, char *filename) int element = EL_CUSTOM_START + i; /* order of checking and copying events to be mapped is important */ + /* (do not change the start and end value -- they are constant) */ for (j = CE_BY_OTHER_ACTION; j >= CE_VALUE_GETS_ZERO; j--) { if (HAS_CHANGE_EVENT(element, j - 2)) @@ -2995,6 +4083,7 @@ static void LoadLevel_InitElements(struct LevelInfo *level, char *filename) } /* order of checking and copying events to be mapped is important */ + /* (do not change the start and end value -- they are constant) */ for (j = CE_PLAYER_COLLECTS_X; j >= CE_HITTING_SOMETHING; j--) { if (HAS_CHANGE_EVENT(element, j - 1)) @@ -3134,6 +4223,21 @@ static void LoadLevel_InitPlayfield(struct LevelInfo *level, char *filename) SetBorderElement(); } +static void LoadLevel_InitNativeEngines(struct LevelInfo *level,char *filename) +{ + struct LevelFileInfo *level_file_info = &level->file_info; + +#if 1 + if (level_file_info->type == LEVEL_FILE_TYPE_RND) + CopyNativeLevel_RND_to_Native(level); +#else + if (level_file_info->type == LEVEL_FILE_TYPE_RND) + CopyNativeLevel_RND_to_Native(level); + else + CopyNativeLevel_Native_to_RND(level); +#endif +} + void LoadLevelTemplate(int nr) { char *filename; @@ -3164,6 +4268,8 @@ void LoadLevel(int nr) LoadLevel_InitVersion(&level, filename); LoadLevel_InitElements(&level, filename); LoadLevel_InitPlayfield(&level, filename); + + LoadLevel_InitNativeEngines(&level, filename); } static void SaveLevel_VERS(FILE *file, struct LevelInfo *level) @@ -3198,7 +4304,7 @@ static void SaveLevel_HEAD(FILE *file, struct LevelInfo *level) putFile8Bit(file, level->time_wheel); putFile8Bit(file, (level->encoding_16bit_amoeba ? EL_EMPTY : level->amoeba_content)); - putFile8Bit(file, (level->double_speed ? 1 : 0)); + putFile8Bit(file, (level->initial_player_stepsize == STEPSIZE_FAST ? 1 : 0)); putFile8Bit(file, (level->initial_gravity ? 1 : 0)); putFile8Bit(file, (level->encoding_16bit_field ? 1 : 0)); putFile8Bit(file, (level->em_slippery_gems ? 1 : 0)); @@ -3342,6 +4448,20 @@ static void SaveLevel_CUS1(FILE *file, struct LevelInfo *level, { int element = EL_CUSTOM_START + i; +#if 1 + struct ElementInfo *ei = &element_info[element]; + + if (ei->properties[EP_BITFIELD_BASE] != EP_BITMASK_DEFAULT) + { + if (check < num_changed_custom_elements) + { + putFile16BitBE(file, element); + putFile32BitBE(file, ei->properties[EP_BITFIELD_BASE]); + } + + check++; + } +#else if (Properties[element][EP_BITFIELD_BASE] != EP_BITMASK_DEFAULT) { if (check < num_changed_custom_elements) @@ -3352,6 +4472,7 @@ static void SaveLevel_CUS1(FILE *file, struct LevelInfo *level, check++; } +#endif } if (check != num_changed_custom_elements) /* should not happen */ @@ -3410,7 +4531,11 @@ static void SaveLevel_CUS3(FILE *file, struct LevelInfo *level, for (j = 0; j < MAX_ELEMENT_NAME_LEN; j++) putFile8Bit(file, ei->description[j]); +#if 1 + putFile32BitBE(file, ei->properties[EP_BITFIELD_BASE]); +#else putFile32BitBE(file, Properties[element][EP_BITFIELD_BASE]); +#endif /* some free bytes for future properties and padding */ WriteUnusedBytesToFile(file, 7); @@ -3483,7 +4608,11 @@ static void SaveLevel_CUS4(FILE *file, struct LevelInfo *level, int element) for (i = 0; i < MAX_ELEMENT_NAME_LEN; i++) putFile8Bit(file, ei->description[i]); +#if 1 + putFile32BitBE(file, ei->properties[EP_BITFIELD_BASE]); +#else putFile32BitBE(file, Properties[element][EP_BITFIELD_BASE]); +#endif WriteUnusedBytesToFile(file, 4); /* reserved for more base properties */ putFile8Bit(file, ei->num_change_pages); @@ -3537,7 +4666,7 @@ static void SaveLevel_CUS4(FILE *file, struct LevelInfo *level, int element) for (i = 0; i < ei->num_change_pages; i++) { struct ElementChangeInfo *change = &ei->change_page[i]; - unsigned long event_bits; + unsigned int event_bits; /* bits 0 - 31 of "has_event[]" ... */ event_bits = 0; @@ -3613,14 +4742,16 @@ static void SaveLevel_GRP1(FILE *file, struct LevelInfo *level, int element) putFile16BitBE(file, group->element[i]); } -static int SaveLevel_CONF_Value(FILE *file, int pos) +static int SaveLevel_MicroChunk_SingleValue(FILE *file, + struct ElementFileConfig *entry) { - int default_value = element_conf[pos].default_value; - int element = element_conf[pos].element; - int type = element_conf[pos].type; - int bytes = type & CONF_MASK_BYTES; - void *value_ptr = element_conf[pos].value; - int value = (CONF_VALUE_BOOLEAN(type) ? *(boolean *)value_ptr : + int default_value = entry->default_value; + int element = entry->element; + int data_type = entry->data_type; + int conf_type = entry->conf_type; + int byte_mask = conf_type & CONF_MASK_BYTES; + void *value_ptr = entry->value; + int value = (data_type == TYPE_BOOLEAN ? *(boolean *)value_ptr : *(int *)value_ptr); int num_bytes = 0; boolean modified = FALSE; @@ -3632,24 +4763,63 @@ static int SaveLevel_CONF_Value(FILE *file, int pos) if (!modified) /* do not save unmodified default settings */ return 0; - if (bytes == CONF_MASK_MULTI_BYTES) - Error(ERR_EXIT, "SaveLevel_CONF_Value: cannot save multi-byte values"); +#if 0 + printf("::: %02x, %d: %d != %d\n", + byte_mask, conf_type & CONF_MASK_TOKEN, + value, default_value); +#endif + + if (element != -1) + num_bytes += putFile16BitBE(file, element); + + num_bytes += putFile8Bit(file, conf_type); + num_bytes += (byte_mask == CONF_MASK_1_BYTE ? putFile8Bit (file, value) : + byte_mask == CONF_MASK_2_BYTE ? putFile16BitBE(file, value) : + byte_mask == CONF_MASK_4_BYTE ? putFile32BitBE(file, value) :0); + + return num_bytes; +} + +static int SaveLevel_MicroChunk_ElementList(FILE *file, + struct ElementFileConfig *entry) +{ + int *element_array = (int *)(entry->value); + int num_elements = *(int *)(entry->num_entities); + int default_value = entry->default_value; + int element = entry->element; + int conf_type = entry->conf_type; + int num_bytes = 0; + boolean modified = FALSE; + int i; + + /* check if any settings have been modified before saving them */ + for (i = 0; i < num_elements; i++) + if (element_array[i] != default_value) + modified = TRUE; + + if (!modified) /* do not save unmodified default settings */ + return 0; + + if (element != -1) + num_bytes += putFile16BitBE(file, element); - num_bytes += putFile16BitBE(file, element); - num_bytes += putFile8Bit(file, type); - num_bytes += (bytes == CONF_MASK_1_BYTE ? putFile8Bit (file, value) : - bytes == CONF_MASK_2_BYTE ? putFile16BitBE(file, value) : - bytes == CONF_MASK_4_BYTE ? putFile32BitBE(file, value) : 0); + num_bytes += putFile8Bit(file, conf_type); + num_bytes += putFile16BitBE(file, num_elements * CONF_ELEMENT_NUM_BYTES); + + for (i = 0; i < num_elements; i++) + num_bytes += putFile16BitBE(file, element_array[i]); return num_bytes; } -static int SaveLevel_CONF_Content(FILE *file, int pos, int num_contents) +static int SaveLevel_MicroChunk_ContentList(FILE *file, + struct ElementFileConfig *entry) { - struct Content *content = (struct Content *)(element_conf[pos].value); - int default_value = element_conf[pos].default_value; - int element = element_conf[pos].element; - int type = element_conf[pos].type; + struct Content *content = (struct Content *)(entry->value); + int num_contents = *(int *)(entry->num_entities); + int default_value = entry->default_value; + int element = entry->element; + int conf_type = entry->conf_type; int num_bytes = 0; boolean modified = FALSE; int i, x, y; @@ -3664,8 +4834,10 @@ static int SaveLevel_CONF_Content(FILE *file, int pos, int num_contents) if (!modified) /* do not save unmodified default settings */ return 0; - num_bytes += putFile16BitBE(file, element); - num_bytes += putFile8Bit(file, type); + if (element != -1) + num_bytes += putFile16BitBE(file, element); + + num_bytes += putFile8Bit(file, conf_type); num_bytes += putFile16BitBE(file, num_contents * CONF_CONTENT_NUM_BYTES); for (i = 0; i < num_contents; i++) @@ -3681,17 +4853,138 @@ static int SaveLevel_CONF(FILE *file, struct LevelInfo *level) int chunk_size = 0; int i; - li = *level; /* copy level information into temporary buffer */ + li = *level; /* copy level data into temporary buffer */ + + for (i = 0; element_conf[i].data_type != -1; i++) + { + struct ElementFileConfig *config = &element_conf[i]; + int data_type = config->data_type; + int conf_type = config->conf_type; + int byte_mask = conf_type & CONF_MASK_BYTES; + + if (byte_mask != CONF_MASK_MULTI_BYTES) + chunk_size += SaveLevel_MicroChunk_SingleValue(file, config); + else if (data_type == TYPE_ELEMENT_LIST) + chunk_size += SaveLevel_MicroChunk_ElementList(file, config); + else if (data_type == TYPE_CONTENT_LIST) + chunk_size += SaveLevel_MicroChunk_ContentList(file, config); + } + + return chunk_size; +} + +static int SaveLevel_CUSX(FILE *file, struct LevelInfo *level, int element) +{ + struct ElementInfo *ei = &element_info[element]; + int chunk_size = 0; + int i; + + chunk_size += putFile16BitBE(file, element); + + xx_ei = *ei; /* copy element data into temporary buffer */ + + xx_num_description_bytes = MAX_ELEMENT_NAME_LEN; + xx_num_contents = 1; + +#if 0 + printf("::: - element config\n"); +#endif + + for (i = 0; custom_element_conf[i].data_type != -1; i++) + { + struct ElementFileConfig *config = &custom_element_conf[i]; + int data_type = config->data_type; + int conf_type = config->conf_type; + int byte_mask = conf_type & CONF_MASK_BYTES; + + if (byte_mask != CONF_MASK_MULTI_BYTES) + chunk_size += SaveLevel_MicroChunk_SingleValue(file, config); + else if (data_type == TYPE_ELEMENT_LIST) + chunk_size += SaveLevel_MicroChunk_ElementList(file, config); + else if (data_type == TYPE_CONTENT_LIST) + chunk_size += SaveLevel_MicroChunk_ContentList(file, config); + } + +#if 0 + printf("::: - change pages\n"); +#endif + + for (i = 0; i < ei->num_change_pages; i++) + { + struct ElementChangeInfo *change = &ei->change_page[i]; + + xx_current_change_page = i; + + xx_change = *change; /* copy change data into temporary buffer */ + +#if 0 + printf("::: %d: xx_change.action_mode == %d\n", + i, xx_change.action_mode); + printf("::: %d: xx_change.action_arg == %d\n", + i, xx_change.action_arg); +#endif + + xx_event_bits_0_31 = 0; + xx_event_bits_32_63 = 0; + + for (i = 0; i < NUM_CHANGE_EVENTS; i++) + { + if (change->has_event[i]) + { + if (i < 32) + xx_event_bits_0_31 |= (1 << i); + else + xx_event_bits_32_63 |= (1 << (i - 32)); + } + } + + for (i = 0; custom_element_change_conf[i].data_type != -1; i++) + { + struct ElementFileConfig *config = &custom_element_change_conf[i]; + int data_type = config->data_type; + int conf_type = config->conf_type; + int byte_mask = conf_type & CONF_MASK_BYTES; + + if (byte_mask != CONF_MASK_MULTI_BYTES) + chunk_size += SaveLevel_MicroChunk_SingleValue(file, config); + else if (data_type == TYPE_ELEMENT_LIST) + chunk_size += SaveLevel_MicroChunk_ElementList(file, config); + else if (data_type == TYPE_CONTENT_LIST) + chunk_size += SaveLevel_MicroChunk_ContentList(file, config); + } + } + + return chunk_size; +} + +static int SaveLevel_GRPX(FILE *file, struct LevelInfo *level, int element) +{ + struct ElementInfo *ei = &element_info[element]; + struct ElementGroupInfo *group = ei->group; + int chunk_size = 0; + int i; + + chunk_size += putFile16BitBE(file, element); + + xx_ei = *ei; /* copy element data into temporary buffer */ + xx_group = *group; /* copy group data into temporary buffer */ - for (i = 0; element_conf[i].element != -1; i++) + xx_num_description_bytes = MAX_ELEMENT_NAME_LEN; + xx_num_contents = 1; + + for (i = 0; group_element_conf[i].data_type != -1; i++) { - int type = element_conf[i].type; - int bytes = type & CONF_MASK_BYTES; + struct ElementFileConfig *config = &group_element_conf[i]; + int data_type = config->data_type; + int conf_type = config->conf_type; + int byte_mask = conf_type & CONF_MASK_BYTES; - if (bytes != CONF_MASK_MULTI_BYTES) - chunk_size += SaveLevel_CONF_Value(file, i); - else if (type == CONF_VALUE_CONTENT_8) - chunk_size += SaveLevel_CONF_Content(file, i, MAX_ELEMENT_CONTENTS); + if (byte_mask != CONF_MASK_MULTI_BYTES) + chunk_size += SaveLevel_MicroChunk_SingleValue(file, config); + else if (data_type == TYPE_ELEMENT_LIST) + chunk_size += SaveLevel_MicroChunk_ElementList(file, config); + else if (data_type == TYPE_CONTENT_LIST) + chunk_size += SaveLevel_MicroChunk_ContentList(file, config); } return chunk_size; @@ -3776,9 +5069,10 @@ static void SaveLevelFromFilename(struct LevelInfo *level, char *filename) } } - /* check for non-default custom elements (unless using template level) */ + /* if not using template level, check for non-default custom/group elements */ if (!level->use_custom_template) { +#if 1 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++) { int element = EL_CUSTOM_START + i; @@ -3791,11 +5085,9 @@ static void SaveLevelFromFilename(struct LevelInfo *level, char *filename) SaveLevel_CUS4(file, level, element); } } - } +#endif - /* check for non-default group elements (unless using template level) */ - if (!level->use_custom_template) - { +#if 1 for (i = 0; i < NUM_GROUP_ELEMENTS; i++) { int element = EL_GROUP_START + i; @@ -3806,17 +5098,75 @@ static void SaveLevelFromFilename(struct LevelInfo *level, char *filename) SaveLevel_GRP1(file, level, element); } } +#endif } - conf_chunk_size = SaveLevel_CONF(NULL, level); /* get chunk size */ + conf_chunk_size = SaveLevel_CONF(NULL, level); - /* check for non-default configuration settings to be saved in CONF chunk */ + /* check if non-default element settings need to be saved */ if (conf_chunk_size > 0) { putFileChunkBE(file, "CONF", conf_chunk_size); SaveLevel_CONF(file, level); } + /* 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) + { +#if 1 + printf("::: SAVING CE %d\n", i + 1); +#endif + + putFileChunkBE(file, "CUSX", cusx_chunk_size); + SaveLevel_CUSX(file, level, element); + } + +#if 0 + if (i == 1) + break; +#endif + } +#endif + +#if 1 + 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) + { +#if 1 + printf("::: SAVING GE %d\n", i + 1); +#endif + + putFileChunkBE(file, "GRPX", grpx_chunk_size); + SaveLevel_GRPX(file, level, element); + } + +#if 0 + if (i == 1) + break; +#endif + } +#endif + } + fclose(file); SetFilePermissions(filename, PERMS_PRIVATE); @@ -3866,7 +5216,7 @@ void DumpLevel(struct LevelInfo *level) printf("Amoeba speed: %d\n", level->amoeba_speed); printf("\n"); printf("Initial gravity: %s\n", (level->initial_gravity ? "yes" : "no")); - printf("Double speed movement: %s\n", (level->double_speed ? "yes" : "no")); + printf("Initial player stepsize: %d\n", level->initial_player_stepsize); 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")); @@ -4076,12 +5426,12 @@ void LoadTapeFromFilename(char *filename) } getFileChunkBE(file, chunk_name, NULL); - if (strcmp(chunk_name, "RND1") == 0) + if (strEqual(chunk_name, "RND1")) { getFile32BitBE(file); /* not used */ getFileChunkBE(file, chunk_name, NULL); - if (strcmp(chunk_name, "TAPE") != 0) + if (!strEqual(chunk_name, "TAPE")) { tape.no_valid_file = TRUE; @@ -4147,7 +5497,7 @@ void LoadTapeFromFilename(char *filename) int i = 0; while (chunk_info[i].name != NULL && - strcmp(chunk_name, chunk_info[i].name) != 0) + !strEqual(chunk_name, chunk_info[i].name)) i++; if (chunk_info[i].name == NULL) @@ -4324,6 +5674,7 @@ void SaveTape(int nr) void DumpTape(struct TapeInfo *tape) { + int tape_frame_counter; int i, j; if (tape->no_valid_file) @@ -4341,12 +5692,14 @@ void DumpTape(struct TapeInfo *tape) printf("Level series identifier: '%s'\n", tape->level_identifier); printf_line("-", 79); + tape_frame_counter = 0; + for (i = 0; i < tape->length; i++) { if (i >= MAX_TAPE_LEN) break; - printf("%03d: ", i); + printf("%04d: ", i); for (j = 0; j < MAX_PLAYERS; j++) { @@ -4365,7 +5718,10 @@ void DumpTape(struct TapeInfo *tape) } } - printf("(%03d)\n", tape->pos[i].delay); + printf("(%03d) ", tape->pos[i].delay); + printf("[%05d]\n", tape_frame_counter); + + tape_frame_counter += tape->pos[i].delay; } printf_line("-", 79); @@ -4471,21 +5827,26 @@ void SaveScore(int nr) #define SETUP_TOKEN_SOFT_SCROLLING 7 #define SETUP_TOKEN_FADING 8 #define SETUP_TOKEN_AUTORECORD 9 -#define SETUP_TOKEN_QUICK_DOORS 10 -#define SETUP_TOKEN_TEAM_MODE 11 -#define SETUP_TOKEN_HANDICAP 12 -#define SETUP_TOKEN_SKIP_LEVELS 13 -#define SETUP_TOKEN_TIME_LIMIT 14 -#define SETUP_TOKEN_FULLSCREEN 15 -#define SETUP_TOKEN_ASK_ON_ESCAPE 16 -#define SETUP_TOKEN_GRAPHICS_SET 17 -#define SETUP_TOKEN_SOUNDS_SET 18 -#define SETUP_TOKEN_MUSIC_SET 19 -#define SETUP_TOKEN_OVERRIDE_LEVEL_GRAPHICS 20 -#define SETUP_TOKEN_OVERRIDE_LEVEL_SOUNDS 21 -#define SETUP_TOKEN_OVERRIDE_LEVEL_MUSIC 22 - -#define NUM_GLOBAL_SETUP_TOKENS 23 +#define SETUP_TOKEN_SHOW_TITLESCREEN 10 +#define SETUP_TOKEN_QUICK_DOORS 11 +#define SETUP_TOKEN_TEAM_MODE 12 +#define SETUP_TOKEN_HANDICAP 13 +#define SETUP_TOKEN_SKIP_LEVELS 14 +#define SETUP_TOKEN_TIME_LIMIT 15 +#define SETUP_TOKEN_FULLSCREEN 16 +#define SETUP_TOKEN_ASK_ON_ESCAPE 17 +#define SETUP_TOKEN_ASK_ON_ESCAPE_EDITOR 18 +#define SETUP_TOKEN_QUICK_SWITCH 19 +#define SETUP_TOKEN_INPUT_ON_FOCUS 20 +#define SETUP_TOKEN_PREFER_AGA_GRAPHICS 21 +#define SETUP_TOKEN_GRAPHICS_SET 22 +#define SETUP_TOKEN_SOUNDS_SET 23 +#define SETUP_TOKEN_MUSIC_SET 24 +#define SETUP_TOKEN_OVERRIDE_LEVEL_GRAPHICS 25 +#define SETUP_TOKEN_OVERRIDE_LEVEL_SOUNDS 26 +#define SETUP_TOKEN_OVERRIDE_LEVEL_MUSIC 27 + +#define NUM_GLOBAL_SETUP_TOKENS 28 /* editor setup */ #define SETUP_TOKEN_EDITOR_EL_BOULDERDASH 0 @@ -4501,15 +5862,39 @@ void SaveScore(int nr) #define SETUP_TOKEN_EDITOR_EL_HEADLINES 10 #define SETUP_TOKEN_EDITOR_EL_USER_DEFINED 11 #define SETUP_TOKEN_EDITOR_EL_DYNAMIC 12 - -#define NUM_EDITOR_SETUP_TOKENS 13 +#define SETUP_TOKEN_EDITOR_SHOW_ELEMENT_TOKEN 13 + +#define NUM_EDITOR_SETUP_TOKENS 14 + +/* editor cascade setup */ +#define SETUP_TOKEN_EDITOR_CASCADE_BD 0 +#define SETUP_TOKEN_EDITOR_CASCADE_EM 1 +#define SETUP_TOKEN_EDITOR_CASCADE_EMC 2 +#define SETUP_TOKEN_EDITOR_CASCADE_RND 3 +#define SETUP_TOKEN_EDITOR_CASCADE_SB 4 +#define SETUP_TOKEN_EDITOR_CASCADE_SP 5 +#define SETUP_TOKEN_EDITOR_CASCADE_DC 6 +#define SETUP_TOKEN_EDITOR_CASCADE_DX 7 +#define SETUP_TOKEN_EDITOR_CASCADE_TEXT 8 +#define SETUP_TOKEN_EDITOR_CASCADE_CE 9 +#define SETUP_TOKEN_EDITOR_CASCADE_GE 10 +#define SETUP_TOKEN_EDITOR_CASCADE_USER 11 +#define SETUP_TOKEN_EDITOR_CASCADE_GENERIC 12 +#define SETUP_TOKEN_EDITOR_CASCADE_DYNAMIC 13 + +#define NUM_EDITOR_CASCADE_SETUP_TOKENS 14 /* shortcut setup */ #define SETUP_TOKEN_SHORTCUT_SAVE_GAME 0 #define SETUP_TOKEN_SHORTCUT_LOAD_GAME 1 #define SETUP_TOKEN_SHORTCUT_TOGGLE_PAUSE 2 +#define SETUP_TOKEN_SHORTCUT_FOCUS_PLAYER_1 3 +#define SETUP_TOKEN_SHORTCUT_FOCUS_PLAYER_2 4 +#define SETUP_TOKEN_SHORTCUT_FOCUS_PLAYER_3 5 +#define SETUP_TOKEN_SHORTCUT_FOCUS_PLAYER_4 6 +#define SETUP_TOKEN_SHORTCUT_FOCUS_PLAYER_ALL 7 -#define NUM_SHORTCUT_SETUP_TOKENS 3 +#define NUM_SHORTCUT_SETUP_TOKENS 8 /* player setup */ #define SETUP_TOKEN_PLAYER_USE_JOYSTICK 0 @@ -4545,6 +5930,7 @@ void SaveScore(int nr) static struct SetupInfo si; static struct SetupEditorInfo sei; +static struct SetupEditorCascadeInfo seci; static struct SetupShortcutInfo ssi; static struct SetupInputInfo sii; static struct SetupSystemInfo syi; @@ -4562,6 +5948,7 @@ static struct TokenInfo global_setup_tokens[] = { TYPE_SWITCH, &si.soft_scrolling, "soft_scrolling" }, { TYPE_SWITCH, &si.fading, "screen_fading" }, { TYPE_SWITCH, &si.autorecord, "automatic_tape_recording" }, + { TYPE_SWITCH, &si.show_titlescreen, "show_titlescreen" }, { TYPE_SWITCH, &si.quick_doors, "quick_doors" }, { TYPE_SWITCH, &si.team_mode, "team_mode" }, { TYPE_SWITCH, &si.handicap, "handicap" }, @@ -4569,6 +5956,10 @@ static struct TokenInfo global_setup_tokens[] = { TYPE_SWITCH, &si.time_limit, "time_limit" }, { TYPE_SWITCH, &si.fullscreen, "fullscreen" }, { TYPE_SWITCH, &si.ask_on_escape, "ask_on_escape" }, + { TYPE_SWITCH, &si.ask_on_escape_editor, "ask_on_escape_editor" }, + { TYPE_SWITCH, &si.quick_switch, "quick_player_switch" }, + { TYPE_SWITCH, &si.input_on_focus, "input_on_focus" }, + { TYPE_SWITCH, &si.prefer_aga_graphics, "prefer_aga_graphics" }, { TYPE_STRING, &si.graphics_set, "graphics_set" }, { TYPE_STRING, &si.sounds_set, "sounds_set" }, { TYPE_STRING, &si.music_set, "music_set" }, @@ -4592,13 +5983,36 @@ static struct TokenInfo editor_setup_tokens[] = { TYPE_SWITCH, &sei.el_headlines, "editor.el_headlines" }, { TYPE_SWITCH, &sei.el_user_defined, "editor.el_user_defined" }, { TYPE_SWITCH, &sei.el_dynamic, "editor.el_dynamic" }, + { TYPE_SWITCH, &sei.show_element_token,"editor.show_element_token" }, +}; + +static struct TokenInfo editor_cascade_setup_tokens[] = +{ + { TYPE_SWITCH, &seci.el_bd, "editor.cascade.el_bd" }, + { TYPE_SWITCH, &seci.el_em, "editor.cascade.el_em" }, + { TYPE_SWITCH, &seci.el_emc, "editor.cascade.el_emc" }, + { TYPE_SWITCH, &seci.el_rnd, "editor.cascade.el_rnd" }, + { TYPE_SWITCH, &seci.el_sb, "editor.cascade.el_sb" }, + { TYPE_SWITCH, &seci.el_sp, "editor.cascade.el_sp" }, + { TYPE_SWITCH, &seci.el_dc, "editor.cascade.el_dc" }, + { TYPE_SWITCH, &seci.el_dx, "editor.cascade.el_dx" }, + { TYPE_SWITCH, &seci.el_chars, "editor.cascade.el_chars" }, + { TYPE_SWITCH, &seci.el_ce, "editor.cascade.el_ce" }, + { TYPE_SWITCH, &seci.el_ge, "editor.cascade.el_ge" }, + { TYPE_SWITCH, &seci.el_user, "editor.cascade.el_user" }, + { TYPE_SWITCH, &seci.el_dynamic, "editor.cascade.el_dynamic" }, }; static struct TokenInfo shortcut_setup_tokens[] = { { TYPE_KEY_X11, &ssi.save_game, "shortcut.save_game" }, { TYPE_KEY_X11, &ssi.load_game, "shortcut.load_game" }, - { TYPE_KEY_X11, &ssi.toggle_pause, "shortcut.toggle_pause" } + { TYPE_KEY_X11, &ssi.toggle_pause, "shortcut.toggle_pause" }, + { TYPE_KEY_X11, &ssi.focus_player[0], "shortcut.focus_player_1" }, + { TYPE_KEY_X11, &ssi.focus_player[1], "shortcut.focus_player_2" }, + { TYPE_KEY_X11, &ssi.focus_player[2], "shortcut.focus_player_3" }, + { TYPE_KEY_X11, &ssi.focus_player[3], "shortcut.focus_player_4" }, + { TYPE_KEY_X11, &ssi.focus_player_all,"shortcut.focus_player_all" }, }; static struct TokenInfo player_setup_tokens[] = @@ -4618,18 +6032,18 @@ static struct TokenInfo player_setup_tokens[] = { TYPE_KEY_X11, &sii.key.up, ".key.move_up" }, { TYPE_KEY_X11, &sii.key.down, ".key.move_down" }, { TYPE_KEY_X11, &sii.key.snap, ".key.snap_field" }, - { TYPE_KEY_X11, &sii.key.drop, ".key.place_bomb" } + { TYPE_KEY_X11, &sii.key.drop, ".key.place_bomb" }, }; static struct TokenInfo system_setup_tokens[] = { { TYPE_STRING, &syi.sdl_audiodriver, "system.sdl_audiodriver" }, - { TYPE_INTEGER, &syi.audio_fragment_size,"system.audio_fragment_size" } + { TYPE_INTEGER, &syi.audio_fragment_size,"system.audio_fragment_size" }, }; static struct TokenInfo options_setup_tokens[] = { - { TYPE_BOOLEAN, &soi.verbose, "options.verbose" } + { TYPE_BOOLEAN, &soi.verbose, "options.verbose" }, }; static char *get_corrected_login_name(char *login_name) @@ -4664,6 +6078,7 @@ static void setSetupInfoToDefaults(struct SetupInfo *si) si->soft_scrolling = TRUE; si->fading = FALSE; si->autorecord = TRUE; + si->show_titlescreen = TRUE; si->quick_doors = FALSE; si->team_mode = FALSE; si->handicap = TRUE; @@ -4671,6 +6086,10 @@ static void setSetupInfoToDefaults(struct SetupInfo *si) si->time_limit = TRUE; si->fullscreen = FALSE; si->ask_on_escape = TRUE; + si->ask_on_escape_editor = TRUE; + si->quick_switch = FALSE; + si->input_on_focus = FALSE; + si->prefer_aga_graphics = TRUE; si->graphics_set = getStringCopy(GFX_CLASSIC_SUBDIR); si->sounds_set = getStringCopy(SND_CLASSIC_SUBDIR); @@ -4694,10 +6113,18 @@ static void setSetupInfoToDefaults(struct SetupInfo *si) si->editor.el_user_defined = FALSE; si->editor.el_dynamic = TRUE; + si->editor.show_element_token = FALSE; + si->shortcut.save_game = DEFAULT_KEY_SAVE_GAME; si->shortcut.load_game = DEFAULT_KEY_LOAD_GAME; si->shortcut.toggle_pause = DEFAULT_KEY_TOGGLE_PAUSE; + si->shortcut.focus_player[0] = DEFAULT_KEY_FOCUS_PLAYER_1; + si->shortcut.focus_player[1] = DEFAULT_KEY_FOCUS_PLAYER_2; + si->shortcut.focus_player[2] = DEFAULT_KEY_FOCUS_PLAYER_3; + si->shortcut.focus_player[3] = DEFAULT_KEY_FOCUS_PLAYER_4; + si->shortcut.focus_player_all = DEFAULT_KEY_FOCUS_PLAYER_ALL; + for (i = 0; i < MAX_PLAYERS; i++) { si->input[i].use_joystick = FALSE; @@ -4724,6 +6151,24 @@ static void setSetupInfoToDefaults(struct SetupInfo *si) si->options.verbose = FALSE; } +static void setSetupInfoToDefaults_EditorCascade(struct SetupInfo *si) +{ + si->editor_cascade.el_bd = TRUE; + si->editor_cascade.el_em = TRUE; + si->editor_cascade.el_emc = TRUE; + si->editor_cascade.el_rnd = TRUE; + si->editor_cascade.el_sb = TRUE; + si->editor_cascade.el_sp = TRUE; + si->editor_cascade.el_dc = TRUE; + si->editor_cascade.el_dx = TRUE; + + si->editor_cascade.el_chars = FALSE; + si->editor_cascade.el_ce = FALSE; + si->editor_cascade.el_ge = FALSE; + si->editor_cascade.el_user = FALSE; + si->editor_cascade.el_dynamic = FALSE; +} + static void decodeSetupFileHash(SetupFileHash *setup_file_hash) { int i, pnr; @@ -4786,6 +6231,22 @@ static void decodeSetupFileHash(SetupFileHash *setup_file_hash) setup.options = soi; } +static void decodeSetupFileHash_EditorCascade(SetupFileHash *setup_file_hash) +{ + int i; + + if (!setup_file_hash) + return; + + /* editor cascade setup */ + seci = setup.editor_cascade; + for (i = 0; i < NUM_EDITOR_CASCADE_SETUP_TOKENS; i++) + setSetupInfo(editor_cascade_setup_tokens, i, + getHashEntry(setup_file_hash, + editor_cascade_setup_tokens[i].text)); + setup.editor_cascade = seci; +} + void LoadSetup() { char *filename = getSetupFilename(); @@ -4800,7 +6261,7 @@ void LoadSetup() { char *player_name_new; - checkSetupFileHashIdentifier(setup_file_hash, getCookie("SETUP")); + checkSetupFileHashIdentifier(setup_file_hash, filename,getCookie("SETUP")); decodeSetupFileHash(setup_file_hash); setup.direct_draw = !setup.double_buffering; @@ -4816,6 +6277,27 @@ void LoadSetup() Error(ERR_WARN, "using default setup values"); } +void LoadSetup_EditorCascade() +{ + char *filename = getPath2(getSetupDir(), EDITORCASCADE_FILENAME); + SetupFileHash *setup_file_hash = NULL; + + /* always start with reliable default values */ + setSetupInfoToDefaults_EditorCascade(&setup); + + setup_file_hash = loadSetupFileHash(filename); + + if (setup_file_hash) + { + checkSetupFileHashIdentifier(setup_file_hash, filename,getCookie("SETUP")); + decodeSetupFileHash_EditorCascade(setup_file_hash); + + freeSetupFileHash(setup_file_hash); + } + + free(filename); +} + void SaveSetup() { char *filename = getSetupFilename(); @@ -4888,6 +6370,37 @@ void SaveSetup() SetFilePermissions(filename, PERMS_PRIVATE); } +void SaveSetup_EditorCascade() +{ + char *filename = getPath2(getSetupDir(), EDITORCASCADE_FILENAME); + FILE *file; + int i; + + InitUserDataDirectory(); + + if (!(file = fopen(filename, MODE_WRITE))) + { + Error(ERR_WARN, "cannot write editor cascade state file '%s'", filename); + free(filename); + return; + } + + fprintf(file, "%s\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER, + getCookie("SETUP"))); + fprintf(file, "\n"); + + seci = setup.editor_cascade; + fprintf(file, "\n"); + for (i = 0; i < NUM_EDITOR_SETUP_TOKENS; i++) + fprintf(file, "%s\n", getSetupLine(editor_cascade_setup_tokens, "", i)); + + fclose(file); + + SetFilePermissions(filename, PERMS_PRIVATE); + + free(filename); +} + void LoadCustomElementDescriptions() { char *filename = getCustomArtworkConfigFilename(ARTWORK_TYPE_GRAPHICS); @@ -4920,19 +6433,14 @@ void LoadCustomElementDescriptions() freeSetupFileHash(setup_file_hash); } -void LoadSpecialMenuDesignSettings() +static void LoadSpecialMenuDesignSettingsFromFilename(char *filename) { - char *filename = getCustomArtworkConfigFilename(ARTWORK_TYPE_GRAPHICS); SetupFileHash *setup_file_hash; - int i, j; + int i; - /* always start with reliable default values from default config */ - for (i = 0; image_config_vars[i].token != NULL; i++) - for (j = 0; image_config[j].token != NULL; j++) - if (strcmp(image_config_vars[i].token, image_config[j].token) == 0) - *image_config_vars[i].value = - get_auto_parameter_value(image_config_vars[i].token, - image_config[j].value); +#if 0 + printf("LoadSpecialMenuDesignSettings from file '%s' ...\n", filename); +#endif if ((setup_file_hash = loadSetupFileHash(filename)) == NULL) return; @@ -4965,6 +6473,42 @@ void LoadSpecialMenuDesignSettings() freeSetupFileHash(setup_file_hash); } +void LoadSpecialMenuDesignSettings() +{ + char *filename_base = UNDEFINED_FILENAME, *filename_local; + int i, j; + + /* always start with reliable default values from default config */ + for (i = 0; image_config_vars[i].token != NULL; i++) + for (j = 0; image_config[j].token != NULL; j++) + if (strEqual(image_config_vars[i].token, image_config[j].token)) + *image_config_vars[i].value = + get_auto_parameter_value(image_config_vars[i].token, + image_config[j].value); + +#if 1 + if (!SETUP_OVERRIDE_ARTWORK(setup, ARTWORK_TYPE_GRAPHICS)) + { + /* first look for special settings configured in level series config */ + filename_base = getCustomArtworkLevelConfigFilename(ARTWORK_TYPE_GRAPHICS); + + if (fileExists(filename_base)) + LoadSpecialMenuDesignSettingsFromFilename(filename_base); + } + + filename_local = getCustomArtworkConfigFilename(ARTWORK_TYPE_GRAPHICS); + + if (filename_local != NULL && !strEqual(filename_base, filename_local)) + LoadSpecialMenuDesignSettingsFromFilename(filename_local); + +#else + + filename_local = getCustomArtworkConfigFilename(ARTWORK_TYPE_GRAPHICS); + + LoadSpecialMenuDesignSettingsFromFilename(filename_local); +#endif +} + void LoadUserDefinedEditorElementList(int **elements, int *num_elements) { char *filename = getEditorSetupFilename(); @@ -5154,7 +6698,7 @@ static boolean music_info_listed_ext(struct MusicFileInfo *list, char *basename, boolean is_sound) { for (; list != NULL; list = list->next) - if (list->is_sound == is_sound && strcmp(list->basename, basename) == 0) + if (list->is_sound == is_sound && strEqual(list->basename, basename)) return TRUE; return FALSE; @@ -5212,7 +6756,7 @@ void LoadMusicInfo() if (music->filename == NULL) continue; - if (strcmp(music->filename, UNDEFINED_FILENAME) == 0) + if (strEqual(music->filename, UNDEFINED_FILENAME)) continue; /* a configured file may be not recognized as music */ @@ -5251,7 +6795,7 @@ void LoadMusicInfo() if (music->filename == NULL) continue; - if (strcmp(basename, music->filename) == 0) + if (strEqual(basename, music->filename)) { music_already_used = TRUE; break; @@ -5287,7 +6831,7 @@ void LoadMusicInfo() if (sound->filename == NULL) continue; - if (strcmp(sound->filename, UNDEFINED_FILENAME) == 0) + if (strEqual(sound->filename, UNDEFINED_FILENAME)) continue; /* a configured file may be not recognized as sound */ @@ -5386,7 +6930,7 @@ void LoadHelpAnimInfo() i_to_a(element_action_info[i].value)); /* do not store direction index (bit) here, but direction value! */ - for (i = 0; i < NUM_DIRECTIONS; i++) + for (i = 0; i < NUM_DIRECTIONS_FULL; i++) setHashEntry(direction_hash, element_direction_info[i].suffix, i_to_a(1 << element_direction_info[i].value)); @@ -5396,7 +6940,7 @@ void LoadHelpAnimInfo() char *element_value, *action_value, *direction_value; int delay = atoi(list->value); - if (strcmp(list->token, "end") == 0) + if (strEqual(list->token, "end")) { add_helpanim_entry(HELPANIM_LIST_NEXT, -1, -1, -1, &num_list_entries); @@ -5548,7 +7092,8 @@ void LoadHelpAnimInfo() #if 0 for (i = 0; i < num_list_entries; i++) - printf("::: %d, %d, %d => %d\n", + printf("::: '%s': %d, %d, %d => %d\n", + EL_NAME(helpanim_info[i].element), helpanim_info[i].element, helpanim_info[i].action, helpanim_info[i].direction,