+ TYPE_INTEGER, CONF_VALUE_16_BIT(4),
+ &xx_ei.ce_value_fixed_initial, 0,
+ &yy_ei.ce_value_fixed_initial
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(5),
+ &xx_ei.ce_value_random_initial, 0,
+ &yy_ei.ce_value_random_initial
+ },
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(3),
+ &xx_ei.use_last_ce_value, FALSE,
+ &yy_ei.use_last_ce_value
+ },
+
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(6),
+ &xx_ei.push_delay_fixed, 8,
+ &yy_ei.push_delay_fixed
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(7),
+ &xx_ei.push_delay_random, 8,
+ &yy_ei.push_delay_random
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(8),
+ &xx_ei.drop_delay_fixed, 0,
+ &yy_ei.drop_delay_fixed
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(9),
+ &xx_ei.drop_delay_random, 0,
+ &yy_ei.drop_delay_random
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(10),
+ &xx_ei.move_delay_fixed, 0,
+ &yy_ei.move_delay_fixed
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(11),
+ &xx_ei.move_delay_random, 0,
+ &yy_ei.move_delay_random
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(16),
+ &xx_ei.step_delay_fixed, 0,
+ &yy_ei.step_delay_fixed
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(17),
+ &xx_ei.step_delay_random, 0,
+ &yy_ei.step_delay_random
+ },
+
+ {
+ -1, -1,
+ TYPE_BITFIELD, CONF_VALUE_32_BIT(3),
+ &xx_ei.move_pattern, MV_ALL_DIRECTIONS,
+ &yy_ei.move_pattern
+ },
+ {
+ -1, -1,
+ TYPE_BITFIELD, CONF_VALUE_8_BIT(4),
+ &xx_ei.move_direction_initial, MV_START_AUTOMATIC,
+ &yy_ei.move_direction_initial
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(5),
+ &xx_ei.move_stepsize, TILEX / 8,
+ &yy_ei.move_stepsize
+ },
+
+ {
+ -1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(12),
+ &xx_ei.move_enter_element, EL_EMPTY_SPACE,
+ &yy_ei.move_enter_element
+ },
+ {
+ -1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(13),
+ &xx_ei.move_leave_element, EL_EMPTY_SPACE,
+ &yy_ei.move_leave_element
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(6),
+ &xx_ei.move_leave_type, LEAVE_TYPE_UNLIMITED,
+ &yy_ei.move_leave_type
+ },
+
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(7),
+ &xx_ei.slippery_type, SLIPPERY_ANY_RANDOM,
+ &yy_ei.slippery_type
+ },
+
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(8),
+ &xx_ei.explosion_type, EXPLODES_3X3,
+ &yy_ei.explosion_type
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(14),
+ &xx_ei.explosion_delay, 16,
+ &yy_ei.explosion_delay
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(15),
+ &xx_ei.ignition_delay, 8,
+ &yy_ei.ignition_delay
+ },
+
+ {
+ -1, -1,
+ TYPE_CONTENT_LIST, CONF_VALUE_BYTES(2),
+ &xx_ei.content, EL_EMPTY_SPACE,
+ &yy_ei.content,
+ &xx_num_contents, 1, 1
+ },
+
+ // ---------- "num_change_pages" must be the last entry ---------------------
+
+ {
+ -1, SAVE_CONF_ALWAYS,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(9),
+ &xx_ei.num_change_pages, 1,
+ &yy_ei.num_change_pages
+ },
+
+ {
+ -1, -1,
+ -1, -1,
+ NULL, -1,
+ NULL
+ }
+};
+
+static struct LevelFileConfigInfo chunk_config_CUSX_change[] =
+{
+ // ---------- "current_change_page" must be the first entry -----------------
+
+ {
+ -1, SAVE_CONF_ALWAYS,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(1),
+ &xx_current_change_page, -1
+ },
+
+ // ---------- (the remaining entries can be in any order) -------------------
+
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
+ &xx_change.can_change, FALSE
+ },
+
+ {
+ -1, -1,
+ TYPE_BITFIELD, CONF_VALUE_32_BIT(1),
+ &xx_event_bits[0], 0
+ },
+ {
+ -1, -1,
+ TYPE_BITFIELD, CONF_VALUE_32_BIT(2),
+ &xx_event_bits[1], 0
+ },
+
+ {
+ -1, -1,
+ TYPE_BITFIELD, CONF_VALUE_8_BIT(3),
+ &xx_change.trigger_player, CH_PLAYER_ANY
+ },
+ {
+ -1, -1,
+ TYPE_BITFIELD, CONF_VALUE_8_BIT(4),
+ &xx_change.trigger_side, CH_SIDE_ANY
+ },
+ {
+ -1, -1,
+ TYPE_BITFIELD, CONF_VALUE_32_BIT(3),
+ &xx_change.trigger_page, CH_PAGE_ANY
+ },
+
+ {
+ -1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &xx_change.target_element, EL_EMPTY_SPACE
+ },
+
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(2),
+ &xx_change.delay_fixed, 0
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(3),
+ &xx_change.delay_random, 0
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(4),
+ &xx_change.delay_frames, FRAMES_PER_SECOND
+ },
+
+ {
+ -1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(5),
+ &xx_change.initial_trigger_element, EL_EMPTY_SPACE
+ },
+
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(6),
+ &xx_change.explode, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(7),
+ &xx_change.use_target_content, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(8),
+ &xx_change.only_if_complete, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(9),
+ &xx_change.use_random_replace, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(10),
+ &xx_change.random_percentage, 100
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(11),
+ &xx_change.replace_when, CP_WHEN_EMPTY
+ },
+
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(12),
+ &xx_change.has_action, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(13),
+ &xx_change.action_type, CA_NO_ACTION
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(14),
+ &xx_change.action_mode, CA_MODE_UNDEFINED
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(6),
+ &xx_change.action_arg, CA_ARG_UNDEFINED
+ },
+
+ {
+ -1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(7),
+ &xx_change.action_element, EL_EMPTY_SPACE
+ },
+
+ {
+ -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,
+ NULL, -1
+ }
+};
+
+static struct LevelFileConfigInfo chunk_config_GRPX[] =
+{
+ {
+ -1, -1,
+ TYPE_STRING, CONF_VALUE_BYTES(1),
+ &xx_ei.description[0], -1, NULL,
+ &xx_string_length_unused, -1, MAX_ELEMENT_NAME_LEN,
+ &xx_default_description[0]
+ },
+
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
+ &xx_ei.use_gfx_element, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &xx_ei.gfx_element_initial, EL_EMPTY_SPACE
+ },
+
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(2),
+ &xx_group.choice_mode, ANIM_RANDOM
+ },
+
+ {
+ -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,
+ NULL, -1
+ }
+};
+
+static struct LevelFileConfigInfo chunk_config_EMPX[] =
+{
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
+ &xx_ei.use_gfx_element, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &xx_ei.gfx_element_initial, EL_EMPTY_SPACE
+ },
+
+ {
+ -1, -1,
+ -1, -1,
+ NULL, -1
+ }
+};
+
+static struct LevelFileConfigInfo chunk_config_CONF[] = // (OBSOLETE)
+{
+ {
+ EL_PLAYER_1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(9),
+ &li.block_snap_field, TRUE
+ },
+ {
+ EL_PLAYER_1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(13),
+ &li.continuous_snapping, TRUE
+ },
+ {
+ EL_PLAYER_1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(1),
+ &li.initial_player_stepsize[0], STEPSIZE_NORMAL
+ },
+ {
+ EL_PLAYER_1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(10),
+ &li.use_start_element[0], FALSE
+ },
+ {
+ EL_PLAYER_1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.start_element[0], EL_PLAYER_1
+ },
+ {
+ EL_PLAYER_1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(11),
+ &li.use_artwork_element[0], FALSE
+ },
+ {
+ EL_PLAYER_1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(2),
+ &li.artwork_element[0], EL_PLAYER_1
+ },
+ {
+ EL_PLAYER_1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(12),
+ &li.use_explosion_element[0], FALSE
+ },
+ {
+ EL_PLAYER_1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(3),
+ &li.explosion_element[0], EL_PLAYER_1
+ },
+
+ {
+ -1, -1,
+ -1, -1,
+ NULL, -1
+ }
+};
+
+static struct
+{
+ int filetype;
+ char *id;
+}
+filetype_id_list[] =
+{
+ { LEVEL_FILE_TYPE_RND, "RND" },
+ { LEVEL_FILE_TYPE_BD, "BD" },
+ { LEVEL_FILE_TYPE_EM, "EM" },
+ { LEVEL_FILE_TYPE_SP, "SP" },
+ { LEVEL_FILE_TYPE_DX, "DX" },
+ { LEVEL_FILE_TYPE_SB, "SB" },
+ { LEVEL_FILE_TYPE_DC, "DC" },
+ { LEVEL_FILE_TYPE_MM, "MM" },
+ { LEVEL_FILE_TYPE_MM, "DF" },
+ { -1, NULL },
+};
+
+
+// ============================================================================
+// level file functions
+// ============================================================================
+
+static boolean check_special_flags(char *flag)
+{
+ if (strEqual(options.special_flags, flag) ||
+ strEqual(leveldir_current->special_flags, flag))
+ return TRUE;
+
+ return FALSE;
+}
+
+static struct DateInfo getCurrentDate(void)
+{
+ 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;
+
+ date.src = DATE_SRC_CLOCK;
+
+ return date;
+}
+
+static void resetEventFlags(struct ElementChangeInfo *change)
+{
+ int i;
+
+ for (i = 0; i < NUM_CHANGE_EVENTS; i++)
+ change->has_event[i] = FALSE;
+}
+
+static void resetEventBits(void)
+{
+ int i;
+
+ for (i = 0; i < NUM_CE_BITFIELDS; i++)
+ xx_event_bits[i] = 0;
+}
+
+static void setEventFlagsFromEventBits(struct ElementChangeInfo *change)
+{
+ int i;
+
+ /* important: only change event flag if corresponding event bit is set
+ (this is because all xx_event_bits[] values are loaded separately,
+ and all xx_event_bits[] values are set back to zero before loading
+ another value xx_event_bits[x] (each value representing 32 flags)) */
+
+ for (i = 0; i < NUM_CHANGE_EVENTS; i++)
+ if (xx_event_bits[CH_EVENT_BITFIELD_NR(i)] & CH_EVENT_BIT(i))
+ change->has_event[i] = TRUE;
+}
+
+static void setEventBitsFromEventFlags(struct ElementChangeInfo *change)
+{
+ int i;
+
+ /* in contrast to the above function setEventFlagsFromEventBits(), it
+ would also be possible to set all bits in xx_event_bits[] to 0 or 1
+ depending on the corresponding change->has_event[i] values here, as
+ all xx_event_bits[] values are reset in resetEventBits() before */
+
+ for (i = 0; i < NUM_CHANGE_EVENTS; i++)
+ if (change->has_event[i])
+ xx_event_bits[CH_EVENT_BITFIELD_NR(i)] |= CH_EVENT_BIT(i);
+}
+
+static char *getDefaultElementDescription(struct ElementInfo *ei)
+{
+ static char description[MAX_ELEMENT_NAME_LEN + 1];
+ char *default_description = (ei->custom_description != NULL ?
+ ei->custom_description :
+ ei->editor_description);
+ int i;
+
+ // always start with reliable default values
+ for (i = 0; i < MAX_ELEMENT_NAME_LEN + 1; i++)
+ description[i] = '\0';
+
+ // truncate element description to MAX_ELEMENT_NAME_LEN bytes
+ strncpy(description, default_description, MAX_ELEMENT_NAME_LEN);
+
+ return &description[0];
+}
+
+static void setElementDescriptionToDefault(struct ElementInfo *ei)
+{
+ char *default_description = getDefaultElementDescription(ei);
+ int i;
+
+ for (i = 0; i < MAX_ELEMENT_NAME_LEN + 1; i++)
+ ei->description[i] = default_description[i];
+}
+
+static void setConfigToDefaultsFromConfigList(struct LevelFileConfigInfo *conf)
+{
+ int i;
+
+ for (i = 0; conf[i].data_type != -1; i++)
+ {
+ 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 = conf[i].default_num_entities;
+ int max_num_entities = conf[i].max_num_entities;
+
+ *(int *)(conf[i].num_entities) = default_num_entities;
+
+ if (data_type == TYPE_STRING)
+ {
+ 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 *)(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 *)(conf[i].value);
+ int c, x, y;
+
+ 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 (data_type == TYPE_BOOLEAN)
+ *(boolean *)(conf[i].value) = default_value;
+ else
+ *(int *) (conf[i].value) = default_value;
+ }
+ }
+}
+
+static void copyConfigFromConfigList(struct LevelFileConfigInfo *conf)
+{
+ int i;
+
+ for (i = 0; conf[i].data_type != -1; i++)
+ {
+ 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 = conf[i].max_num_entities;
+
+ if (data_type == TYPE_STRING)
+ {
+ 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 *)(conf[i].value);
+ int *element_array_copy = (int *)(conf[i].value_copy);
+ int j;
+
+ for (j = 0; j < max_num_entities; j++)
+ element_array_copy[j] = element_array[j];
+ }
+ else if (data_type == TYPE_CONTENT_LIST)
+ {
+ 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++)
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ content_copy[c].e[x][y] = content[c].e[x][y];
+ }
+ }
+ else // constant size configuration data (1, 2 or 4 bytes)
+ {
+ if (data_type == TYPE_BOOLEAN)
+ *(boolean *)(conf[i].value_copy) = *(boolean *)(conf[i].value);
+ else
+ *(int *) (conf[i].value_copy) = *(int *) (conf[i].value);
+ }
+ }
+}
+
+void copyElementInfo(struct ElementInfo *ei_from, struct ElementInfo *ei_to)
+{
+ int i;
+
+ xx_ei = *ei_from; // copy element data into temporary buffer
+ yy_ei = *ei_to; // copy element data into temporary buffer
+
+ copyConfigFromConfigList(chunk_config_CUSX_base);
+
+ *ei_from = xx_ei;
+ *ei_to = yy_ei;
+
+ // ---------- reinitialize and copy change pages ----------
+
+ ei_to->num_change_pages = ei_from->num_change_pages;
+ ei_to->current_change_page = ei_from->current_change_page;
+
+ setElementChangePages(ei_to, ei_to->num_change_pages);
+
+ for (i = 0; i < ei_to->num_change_pages; i++)
+ ei_to->change_page[i] = ei_from->change_page[i];
+
+ // ---------- copy group element info ----------
+ if (ei_from->group != NULL && ei_to->group != NULL) // group or internal
+ *ei_to->group = *ei_from->group;
+
+ // mark this custom element as modified
+ ei_to->modified_settings = TRUE;
+}
+
+void setElementChangePages(struct ElementInfo *ei, int change_pages)
+{
+ int change_page_size = sizeof(struct ElementChangeInfo);
+
+ ei->num_change_pages = MAX(1, change_pages);
+
+ ei->change_page =
+ checked_realloc(ei->change_page, ei->num_change_pages * change_page_size);
+
+ if (ei->current_change_page >= ei->num_change_pages)
+ ei->current_change_page = ei->num_change_pages - 1;
+
+ ei->change = &ei->change_page[ei->current_change_page];
+}
+
+void setElementChangeInfoToDefaults(struct ElementChangeInfo *change)
+{
+ xx_change = *change; // copy change data into temporary buffer
+
+ setConfigToDefaultsFromConfigList(chunk_config_CUSX_change);
+
+ *change = xx_change;
+
+ resetEventFlags(change);
+
+ change->direct_action = 0;
+ change->other_action = 0;
+
+ change->pre_change_function = NULL;
+ change->change_function = NULL;
+ change->post_change_function = NULL;
+}
+
+static void setLevelInfoToDefaults_Level(struct LevelInfo *level)
+{
+ int i, x, y;
+
+ li = *level; // copy level data into temporary buffer
+ setConfigToDefaultsFromConfigList(chunk_config_INFO);
+ *level = li; // copy temporary buffer back to level data
+
+ setLevelInfoToDefaults_BD();
+ setLevelInfoToDefaults_EM();
+ setLevelInfoToDefaults_SP();
+ setLevelInfoToDefaults_MM();
+
+ level->native_bd_level = &native_bd_level;
+ level->native_em_level = &native_em_level;
+ level->native_sp_level = &native_sp_level;
+ level->native_mm_level = &native_mm_level;
+
+ level->file_version = FILE_VERSION_ACTUAL;
+ level->game_version = GAME_VERSION_ACTUAL;
+
+ level->creation_date = getCurrentDate();
+
+ level->encoding_16bit_field = TRUE;
+ level->encoding_16bit_yamyam = TRUE;
+ level->encoding_16bit_amoeba = TRUE;
+
+ // clear level name and level author string buffers
+ for (i = 0; i < MAX_LEVEL_NAME_LEN; i++)
+ level->name[i] = '\0';
+ for (i = 0; i < MAX_LEVEL_AUTHOR_LEN; i++)
+ level->author[i] = '\0';
+
+ // set level name and level author to default values
+ strcpy(level->name, NAMELESS_LEVEL_NAME);
+ strcpy(level->author, ANONYMOUS_NAME);
+
+ // set level playfield to playable default level with player and exit
+ for (x = 0; x < MAX_LEV_FIELDX; x++)
+ for (y = 0; y < MAX_LEV_FIELDY; y++)
+ level->field[x][y] = EL_SAND;
+
+ level->field[0][0] = EL_PLAYER_1;
+ level->field[STD_LEV_FIELDX - 1][STD_LEV_FIELDY - 1] = EL_EXIT_CLOSED;
+
+ BorderElement = EL_STEELWALL;
+
+ // detect custom elements when loading them
+ level->file_has_custom_elements = FALSE;
+
+ // set default color type and colors for BD style level colors
+ SetDefaultLevelColorType_BD();
+ SetDefaultLevelColors_BD();
+
+ // set all bug compatibility flags to "false" => do not emulate this bug
+ level->use_action_after_change_bug = FALSE;
+
+ if (leveldir_current)
+ {
+ // try to determine better author name than 'anonymous'
+ if (!strEqual(leveldir_current->author, ANONYMOUS_NAME))
+ {
+ strncpy(level->author, leveldir_current->author, MAX_LEVEL_AUTHOR_LEN);
+ level->author[MAX_LEVEL_AUTHOR_LEN] = '\0';
+ }
+ else
+ {
+ switch (LEVELCLASS(leveldir_current))
+ {
+ case LEVELCLASS_TUTORIAL:
+ strcpy(level->author, PROGRAM_AUTHOR_STRING);
+ break;
+
+ case LEVELCLASS_CONTRIB:
+ strncpy(level->author, leveldir_current->name, MAX_LEVEL_AUTHOR_LEN);
+ level->author[MAX_LEVEL_AUTHOR_LEN] = '\0';
+ break;
+
+ case LEVELCLASS_PRIVATE:
+ strncpy(level->author, getRealName(), MAX_LEVEL_AUTHOR_LEN);
+ level->author[MAX_LEVEL_AUTHOR_LEN] = '\0';
+ break;
+
+ default:
+ // keep default value
+ break;
+ }
+ }
+ }
+}
+
+static void setLevelInfoToDefaults_Elements(struct LevelInfo *level)
+{
+ static boolean clipboard_elements_initialized = FALSE;
+ int i;
+
+ InitElementPropertiesStatic();
+
+ li = *level; // copy level data into temporary buffer
+ setConfigToDefaultsFromConfigList(chunk_config_ELEM);
+ *level = li; // copy temporary buffer back to level data
+
+ for (i = 0; i < MAX_NUM_ELEMENTS; i++)
+ {
+ int element = i;
+ struct ElementInfo *ei = &element_info[element];
+
+ if (element == EL_MM_GRAY_BALL)
+ {
+ struct LevelInfo_MM *level_mm = level->native_mm_level;
+ int j;
+
+ for (j = 0; j < level->num_mm_ball_contents; j++)
+ level->mm_ball_content[j] =
+ map_element_MM_to_RND(level_mm->ball_content[j]);
+ }
+
+ // never initialize clipboard elements after the very first time
+ // (to be able to use clipboard elements between several levels)
+ if (IS_CLIPBOARD_ELEMENT(element) && clipboard_elements_initialized)
+ continue;
+
+ if (IS_ENVELOPE(element))
+ {
+ int envelope_nr = element - EL_ENVELOPE_1;
+
+ setConfigToDefaultsFromConfigList(chunk_config_NOTE);
+
+ level->envelope[envelope_nr] = xx_envelope;
+ }
+
+ if (IS_CUSTOM_ELEMENT(element) ||
+ IS_GROUP_ELEMENT(element) ||
+ IS_INTERNAL_ELEMENT(element))
+ {
+ xx_ei = *ei; // copy element data into temporary buffer
+
+ setConfigToDefaultsFromConfigList(chunk_config_CUSX_base);
+
+ *ei = xx_ei;
+ }
+
+ setElementChangePages(ei, 1);
+ setElementChangeInfoToDefaults(ei->change);
+
+ if (IS_CUSTOM_ELEMENT(element) ||
+ IS_GROUP_ELEMENT(element))
+ {
+ setElementDescriptionToDefault(ei);
+
+ ei->modified_settings = FALSE;
+ }
+
+ if (IS_CUSTOM_ELEMENT(element) ||
+ IS_INTERNAL_ELEMENT(element))
+ {
+ // internal values used in level editor
+
+ ei->access_type = 0;
+ ei->access_layer = 0;
+ ei->access_protected = 0;
+ ei->walk_to_action = 0;
+ ei->smash_targets = 0;
+ ei->deadliness = 0;
+
+ ei->can_explode_by_fire = FALSE;
+ ei->can_explode_smashed = FALSE;
+ ei->can_explode_impact = FALSE;
+
+ ei->current_change_page = 0;
+ }
+
+ if (IS_GROUP_ELEMENT(element) ||
+ IS_INTERNAL_ELEMENT(element))
+ {
+ struct ElementGroupInfo *group;
+
+ // initialize memory for list of elements in group
+ if (ei->group == NULL)
+ ei->group = checked_malloc(sizeof(struct ElementGroupInfo));
+
+ group = ei->group;
+
+ xx_group = *group; // copy group data into temporary buffer
+
+ setConfigToDefaultsFromConfigList(chunk_config_GRPX);
+
+ *group = xx_group;
+ }
+
+ if (IS_EMPTY_ELEMENT(element) ||
+ IS_INTERNAL_ELEMENT(element))
+ {
+ xx_ei = *ei; // copy element data into temporary buffer
+
+ setConfigToDefaultsFromConfigList(chunk_config_EMPX);
+
+ *ei = xx_ei;
+ }
+ }
+
+ clipboard_elements_initialized = TRUE;
+}
+
+static void setLevelInfoToDefaults(struct LevelInfo *level,
+ boolean level_info_only,
+ boolean reset_file_status)
+{
+ setLevelInfoToDefaults_Level(level);
+
+ if (!level_info_only)
+ setLevelInfoToDefaults_Elements(level);
+
+ if (reset_file_status)
+ {
+ level->no_valid_file = FALSE;
+ level->no_level_file = FALSE;