fixed undefined signed integer overflow for expression "1 << 31"
[rocksndiamonds.git] / src / editor.c
index 2aba3638632873b3f022036f8d2e6827b5df00c5..833dce2ec7996d81f106a9d3522178bb274753bc 100644 (file)
@@ -489,6 +489,12 @@ enum
   GADGET_ID_MOVE_DELAY_RND_DOWN,
   GADGET_ID_MOVE_DELAY_RND_TEXT,
   GADGET_ID_MOVE_DELAY_RND_UP,
+  GADGET_ID_STEP_DELAY_FIX_DOWN,
+  GADGET_ID_STEP_DELAY_FIX_TEXT,
+  GADGET_ID_STEP_DELAY_FIX_UP,
+  GADGET_ID_STEP_DELAY_RND_DOWN,
+  GADGET_ID_STEP_DELAY_RND_TEXT,
+  GADGET_ID_STEP_DELAY_RND_UP,
   GADGET_ID_EXPLOSION_DELAY_DOWN,
   GADGET_ID_EXPLOSION_DELAY_TEXT,
   GADGET_ID_EXPLOSION_DELAY_UP,
@@ -559,6 +565,7 @@ enum
   // selectbox identifiers
 
   GADGET_ID_TIME_OR_STEPS,
+  GADGET_ID_TIME_SCORE_BASE,
   GADGET_ID_GAME_ENGINE_TYPE,
   GADGET_ID_LEVELSET_SAVE_MODE,
   GADGET_ID_WIND_DIRECTION,
@@ -630,6 +637,7 @@ enum
   // checkbuttons/radiobuttons for level/element properties
 
   GADGET_ID_AUTO_COUNT_GEMS,
+  GADGET_ID_RATE_TIME_OVER_SCORE,
   GADGET_ID_USE_LEVELSET_ARTWORK,
   GADGET_ID_COPY_LEVEL_TEMPLATE,
   GADGET_ID_RANDOM_PERCENTAGE,
@@ -648,6 +656,8 @@ enum
   GADGET_ID_SB_OBJECTS_NEEDED,
   GADGET_ID_AUTO_EXIT_SOKOBAN,
   GADGET_ID_SOLVED_BY_ONE_PLAYER,
+  GADGET_ID_FINISH_DIG_COLLECT,
+  GADGET_ID_KEEP_WALKABLE_CE,
   GADGET_ID_CONTINUOUS_SNAPPING,
   GADGET_ID_BLOCK_SNAP_FIELD,
   GADGET_ID_BLOCK_LAST_FIELD,
@@ -750,6 +760,8 @@ enum
   ED_COUNTER_ID_DROP_DELAY_RND,
   ED_COUNTER_ID_MOVE_DELAY_FIX,
   ED_COUNTER_ID_MOVE_DELAY_RND,
+  ED_COUNTER_ID_STEP_DELAY_FIX,
+  ED_COUNTER_ID_STEP_DELAY_RND,
   ED_COUNTER_ID_EXPLOSION_DELAY,
   ED_COUNTER_ID_IGNITION_DELAY,
   ED_COUNTER_ID_GROUP_CONTENT,
@@ -839,6 +851,7 @@ enum
 enum
 {
   ED_SELECTBOX_ID_TIME_OR_STEPS,
+  ED_SELECTBOX_ID_TIME_SCORE_BASE,
   ED_SELECTBOX_ID_GAME_ENGINE_TYPE,
   ED_SELECTBOX_ID_LEVELSET_SAVE_MODE,
   ED_SELECTBOX_ID_WIND_DIRECTION,
@@ -935,6 +948,7 @@ enum
 enum
 {
   ED_CHECKBUTTON_ID_AUTO_COUNT_GEMS,
+  ED_CHECKBUTTON_ID_RATE_TIME_OVER_SCORE,
   ED_CHECKBUTTON_ID_USE_LEVELSET_ARTWORK,
   ED_CHECKBUTTON_ID_COPY_LEVEL_TEMPLATE,
   ED_CHECKBUTTON_ID_RANDOM_RESTRICTED,
@@ -953,6 +967,8 @@ enum
   ED_CHECKBUTTON_ID_SB_OBJECTS_NEEDED,
   ED_CHECKBUTTON_ID_AUTO_EXIT_SOKOBAN,
   ED_CHECKBUTTON_ID_SOLVED_BY_ONE_PLAYER,
+  ED_CHECKBUTTON_ID_FINISH_DIG_COLLECT,
+  ED_CHECKBUTTON_ID_KEEP_WALKABLE_CE,
   ED_CHECKBUTTON_ID_CONTINUOUS_SNAPPING,
   ED_CHECKBUTTON_ID_BLOCK_SNAP_FIELD,
   ED_CHECKBUTTON_ID_BLOCK_LAST_FIELD,
@@ -1007,7 +1023,7 @@ enum
 };
 
 #define ED_CHECKBUTTON_ID_LEVEL_FIRST  ED_CHECKBUTTON_ID_AUTO_COUNT_GEMS
-#define ED_CHECKBUTTON_ID_LEVEL_LAST   ED_CHECKBUTTON_ID_AUTO_COUNT_GEMS
+#define ED_CHECKBUTTON_ID_LEVEL_LAST   ED_CHECKBUTTON_ID_RATE_TIME_OVER_SCORE
 
 #define ED_CHECKBUTTON_ID_LEVELSET_FIRST ED_CHECKBUTTON_ID_USE_LEVELSET_ARTWORK
 #define ED_CHECKBUTTON_ID_LEVELSET_LAST         ED_CHECKBUTTON_ID_COPY_LEVEL_TEMPLATE
@@ -1408,10 +1424,10 @@ static struct
     GADGET_ID_LEVEL_TIMESCORE_DOWN,    GADGET_ID_LEVEL_TIMESCORE_UP,
     GADGET_ID_LEVEL_TIMESCORE_TEXT,    GADGET_ID_NONE,
     &level.score[SC_TIME_BONUS],
-    "score for each second/step left:",        NULL, NULL
+    "score for time or steps left:",   NULL, NULL
   },
   {
-    ED_LEVEL_SETTINGS_XPOS(0),         ED_LEVEL_SETTINGS_YPOS(12),
+    ED_LEVEL_SETTINGS_XPOS(0),         ED_LEVEL_SETTINGS_YPOS(13),
     0,                                 9999,
     GADGET_ID_LEVEL_RANDOM_SEED_DOWN,  GADGET_ID_LEVEL_RANDOM_SEED_UP,
     GADGET_ID_LEVEL_RANDOM_SEED_TEXT,  GADGET_ID_NONE,
@@ -1604,7 +1620,23 @@ static struct
     NULL,                              "+random", NULL
   },
   {
-    ED_ELEMENT_SETTINGS_XPOS(1),       ED_ELEMENT_SETTINGS_YPOS(12),
+    ED_ELEMENT_SETTINGS_XPOS(1),       ED_ELEMENT_SETTINGS_YPOS(6),
+    0,                                 999,
+    GADGET_ID_STEP_DELAY_FIX_DOWN,     GADGET_ID_STEP_DELAY_FIX_UP,
+    GADGET_ID_STEP_DELAY_FIX_TEXT,     GADGET_ID_NONE,
+    &custom_element.step_delay_fixed,
+    NULL,                              "step delay", NULL
+  },
+  {
+    -1,                                        ED_ELEMENT_SETTINGS_YPOS(6),
+    0,                                 999,
+    GADGET_ID_STEP_DELAY_RND_DOWN,     GADGET_ID_STEP_DELAY_RND_UP,
+    GADGET_ID_STEP_DELAY_RND_TEXT,     GADGET_ID_STEP_DELAY_FIX_UP,
+    &custom_element.step_delay_random,
+    NULL,                              "+random", NULL
+  },
+  {
+    ED_ELEMENT_SETTINGS_XPOS(1),       ED_ELEMENT_SETTINGS_YPOS(13),
     0,                                 999,
     GADGET_ID_EXPLOSION_DELAY_DOWN,    GADGET_ID_EXPLOSION_DELAY_UP,
     GADGET_ID_EXPLOSION_DELAY_TEXT,    GADGET_ID_NONE,
@@ -1612,7 +1644,7 @@ static struct
     NULL,                              "explosion delay", NULL
   },
   {
-    ED_ELEMENT_SETTINGS_XPOS(1),       ED_ELEMENT_SETTINGS_YPOS(13),
+    ED_ELEMENT_SETTINGS_XPOS(1),       ED_ELEMENT_SETTINGS_YPOS(14),
     0,                                 999,
     GADGET_ID_IGNITION_DELAY_DOWN,     GADGET_ID_IGNITION_DELAY_UP,
     GADGET_ID_IGNITION_DELAY_TEXT,     GADGET_ID_NONE,
@@ -1731,6 +1763,14 @@ static struct ValueTextInfo options_time_or_steps[] =
   { -1,                                NULL                            }
 };
 
+static struct ValueTextInfo options_time_score_base[] =
+{
+  { 1,                         "per second/step"               },
+  { 10,                                "per 10 seconds/steps"          },
+
+  { -1,                                NULL                            }
+};
+
 static struct ValueTextInfo options_game_engine_type[] =
 {
   { GAME_ENGINE_TYPE_RND,      "Rocks'n'Diamonds"              },
@@ -1969,6 +2009,9 @@ static struct ValueTextInfo options_change_direct_action[] =
   { CE_HEADLINE_SPECIAL_EVENTS,        "[mouse events]"                },
   { CE_CLICKED_BY_MOUSE,       "clicked by mouse"              },
   { CE_PRESSED_BY_MOUSE,       "pressed by mouse"              },
+  { CE_UNDEFINED,              " "                             },
+  { CE_HEADLINE_SPECIAL_EVENTS,        "[static states]"               },
+  { CE_NEXT_TO_PLAYER,         "next to player"                },
 
   { -1,                                NULL                            }
 };
@@ -2002,6 +2045,10 @@ static struct ValueTextInfo options_change_other_action[] =
   { CE_HEADLINE_SPECIAL_EVENTS,        "[mouse events]"                },
   { CE_MOUSE_CLICKED_ON_X,     "mouse clicked on"              },
   { CE_MOUSE_PRESSED_ON_X,     "mouse pressed on"              },
+  { CE_UNDEFINED,              " "                             },
+  { CE_HEADLINE_SPECIAL_EVENTS,        "[static states]"               },
+  { CE_PLAYER_NEXT_TO_X,       "player next to"                },
+  { CE_NEXT_TO_X,              "next to"                       },
 
   { -1,                                NULL                            }
 };
@@ -2032,38 +2079,38 @@ static struct ValueTextInfo options_change_trigger_player[] =
 
 static struct ValueTextInfo options_change_trigger_page[] =
 {
-  { (1 << 0),                  "1"                             },
-  { (1 << 1),                  "2"                             },
-  { (1 << 2),                  "3"                             },
-  { (1 << 3),                  "4"                             },
-  { (1 << 4),                  "5"                             },
-  { (1 << 5),                  "6"                             },
-  { (1 << 6),                  "7"                             },
-  { (1 << 7),                  "8"                             },
-  { (1 << 8),                  "9"                             },
-  { (1 << 9),                  "10"                            },
-  { (1 << 10),                 "11"                            },
-  { (1 << 11),                 "12"                            },
-  { (1 << 12),                 "13"                            },
-  { (1 << 13),                 "14"                            },
-  { (1 << 14),                 "15"                            },
-  { (1 << 15),                 "16"                            },
-  { (1 << 16),                 "17"                            },
-  { (1 << 17),                 "18"                            },
-  { (1 << 18),                 "19"                            },
-  { (1 << 19),                 "20"                            },
-  { (1 << 20),                 "21"                            },
-  { (1 << 21),                 "22"                            },
-  { (1 << 22),                 "23"                            },
-  { (1 << 23),                 "24"                            },
-  { (1 << 24),                 "25"                            },
-  { (1 << 25),                 "26"                            },
-  { (1 << 26),                 "27"                            },
-  { (1 << 27),                 "28"                            },
-  { (1 << 28),                 "29"                            },
-  { (1 << 29),                 "30"                            },
-  { (1 << 30),                 "31"                            },
-  { (1 << 31),                 "32"                            },
+  { (1u << 0),                 "1"                             },
+  { (1u << 1),                 "2"                             },
+  { (1u << 2),                 "3"                             },
+  { (1u << 3),                 "4"                             },
+  { (1u << 4),                 "5"                             },
+  { (1u << 5),                 "6"                             },
+  { (1u << 6),                 "7"                             },
+  { (1u << 7),                 "8"                             },
+  { (1u << 8),                 "9"                             },
+  { (1u << 9),                 "10"                            },
+  { (1u << 10),                        "11"                            },
+  { (1u << 11),                        "12"                            },
+  { (1u << 12),                        "13"                            },
+  { (1u << 13),                        "14"                            },
+  { (1u << 14),                        "15"                            },
+  { (1u << 15),                        "16"                            },
+  { (1u << 16),                        "17"                            },
+  { (1u << 17),                        "18"                            },
+  { (1u << 18),                        "19"                            },
+  { (1u << 19),                        "20"                            },
+  { (1u << 20),                        "21"                            },
+  { (1u << 21),                        "22"                            },
+  { (1u << 22),                        "23"                            },
+  { (1u << 23),                        "24"                            },
+  { (1u << 24),                        "25"                            },
+  { (1u << 25),                        "26"                            },
+  { (1u << 26),                        "27"                            },
+  { (1u << 27),                        "28"                            },
+  { (1u << 28),                        "29"                            },
+  { (1u << 29),                        "30"                            },
+  { (1u << 30),                        "31"                            },
+  { (1u << 31),                        "32"                            },
   { CH_PAGE_ANY,               "any"                           },
 
   { -1,                                NULL                            }
@@ -2466,7 +2513,15 @@ static struct
     NULL, NULL, "(0 => no limit)",     "time or step limit"
   },
   {
-    ED_LEVEL_SETTINGS_XPOS(0),         ED_LEVEL_SETTINGS_YPOS(11),
+    -1,                                        ED_LEVEL_SETTINGS_YPOS(10),
+    GADGET_ID_TIME_SCORE_BASE,         GADGET_ID_LEVEL_TIMESCORE_UP,
+    -1,
+    options_time_score_base,
+    &level.time_score_base,
+    NULL, NULL, NULL,                  "time score for 1 or 10 seconds/steps"
+  },
+  {
+    ED_LEVEL_SETTINGS_XPOS(0),         ED_LEVEL_SETTINGS_YPOS(12),
     GADGET_ID_GAME_ENGINE_TYPE,                GADGET_ID_NONE,
     -1,
     options_game_engine_type,
@@ -2582,7 +2637,7 @@ static struct
     NULL, "            can", ":",      "leave behind or change element"
   },
   {
-    -1,                                        ED_ELEMENT_SETTINGS_YPOS(7),
+    -1,                                        ED_ELEMENT_SETTINGS_YPOS(8),
     GADGET_ID_CUSTOM_SMASH_TARGETS,    GADGET_ID_CUSTOM_CAN_SMASH,
     -1,
     options_smash_targets,
@@ -2590,7 +2645,7 @@ static struct
     NULL, "can smash", NULL,           "elements that can be smashed"
   },
   {
-    ED_ELEMENT_SETTINGS_XPOS(1),       ED_ELEMENT_SETTINGS_YPOS(8),
+    ED_ELEMENT_SETTINGS_XPOS(1),       ED_ELEMENT_SETTINGS_YPOS(9),
     GADGET_ID_CUSTOM_SLIPPERY_TYPE,    GADGET_ID_NONE,
     -1,
     options_slippery_type,
@@ -2598,7 +2653,7 @@ static struct
     NULL, "slippery", NULL,            "where other elements fall down"
   },
   {
-    ED_ELEMENT_SETTINGS_XPOS(1),       ED_ELEMENT_SETTINGS_YPOS(9),
+    ED_ELEMENT_SETTINGS_XPOS(1),       ED_ELEMENT_SETTINGS_YPOS(10),
     GADGET_ID_CUSTOM_DEADLINESS,       GADGET_ID_NONE,
     -1,
     options_deadliness,
@@ -2606,7 +2661,7 @@ static struct
     NULL, "deadly when", NULL,         "deadliness of element"
   },
   {
-    ED_ELEMENT_SETTINGS_XPOS(1),       ED_ELEMENT_SETTINGS_YPOS(10),
+    ED_ELEMENT_SETTINGS_XPOS(1),       ED_ELEMENT_SETTINGS_YPOS(11),
     GADGET_ID_CUSTOM_EXPLOSION_TYPE,   GADGET_ID_NONE,
     -1,
     options_explosion_type,
@@ -2981,6 +3036,13 @@ static struct
     NULL, NULL,
     "automatically count gems needed", "set counter to number of gems"
   },
+  {
+    ED_LEVEL_SETTINGS_XPOS(0),         ED_LEVEL_SETTINGS_YPOS(11),
+    GADGET_ID_RATE_TIME_OVER_SCORE,    GADGET_ID_NONE,
+    &level.rate_time_over_score,
+    NULL, NULL,
+    "rate time/steps used over score", "sort high scores by playing time/steps"
+  },
   {
     ED_LEVEL_SETTINGS_XPOS(0),         ED_LEVEL_SETTINGS_YPOS(7),
     GADGET_ID_USE_LEVELSET_ARTWORK,    GADGET_ID_NONE,
@@ -3110,6 +3172,20 @@ static struct
     NULL, NULL,
     "only one player must enter exit", "level solved by first player in exit"
   },
+  {
+    ED_ELEMENT_SETTINGS_XPOS(0),       ED_ELEMENT_SETTINGS_YPOS(3),
+    GADGET_ID_FINISH_DIG_COLLECT,      GADGET_ID_NONE,
+    &level.finish_dig_collect,
+    NULL, NULL,
+    "CE action on finished dig/collect", "only finished dig/collect triggers CE"
+  },
+  {
+    ED_ELEMENT_SETTINGS_XPOS(0),       ED_ELEMENT_SETTINGS_YPOS(4),
+    GADGET_ID_KEEP_WALKABLE_CE,                GADGET_ID_NONE,
+    &level.keep_walkable_ce,
+    NULL, NULL,
+    "keep walkable CE changed to player", "keep CE changing to player if walkable"
+  },
   {
     ED_ELEMENT_SETTINGS_XPOS(0),       ED_ELEMENT_SETTINGS_YPOS(9),
     GADGET_ID_CONTINUOUS_SNAPPING,     GADGET_ID_NONE,
@@ -3341,56 +3417,56 @@ static struct
     NULL,                              "element can move with some pattern"
   },
   {
-    ED_ELEMENT_SETTINGS_XPOS(0),       ED_ELEMENT_SETTINGS_YPOS(7),
+    ED_ELEMENT_SETTINGS_XPOS(0),       ED_ELEMENT_SETTINGS_YPOS(8),
     GADGET_ID_CUSTOM_CAN_FALL,         GADGET_ID_NONE,
     &custom_element_properties[EP_CAN_FALL],
     NULL, NULL,
     "can fall",                                "element can fall down"
   },
   {
-    -1,                                        ED_ELEMENT_SETTINGS_YPOS(7),
+    -1,                                        ED_ELEMENT_SETTINGS_YPOS(8),
     GADGET_ID_CUSTOM_CAN_SMASH,                GADGET_ID_CUSTOM_CAN_FALL,
     &custom_element_properties[EP_CAN_SMASH],
     NULL, " ",
     NULL,                              "element can smash other elements"
   },
   {
-    ED_ELEMENT_SETTINGS_XPOS(0),       ED_ELEMENT_SETTINGS_YPOS(8),
+    ED_ELEMENT_SETTINGS_XPOS(0),       ED_ELEMENT_SETTINGS_YPOS(9),
     GADGET_ID_CUSTOM_SLIPPERY,         GADGET_ID_NONE,
     &custom_element_properties[EP_SLIPPERY],
     NULL, NULL,
     NULL,                              "other elements can fall down from it"
   },
   {
-    ED_ELEMENT_SETTINGS_XPOS(0),       ED_ELEMENT_SETTINGS_YPOS(9),
+    ED_ELEMENT_SETTINGS_XPOS(0),       ED_ELEMENT_SETTINGS_YPOS(10),
     GADGET_ID_CUSTOM_DEADLY,           GADGET_ID_NONE,
     &custom_element_properties[EP_DEADLY],
     NULL, NULL,
     NULL,                              "element can kill the player"
   },
   {
-    ED_ELEMENT_SETTINGS_XPOS(0),       ED_ELEMENT_SETTINGS_YPOS(10),
+    ED_ELEMENT_SETTINGS_XPOS(0),       ED_ELEMENT_SETTINGS_YPOS(11),
     GADGET_ID_CUSTOM_CAN_EXPLODE,      GADGET_ID_NONE,
     &custom_element_properties[EP_CAN_EXPLODE],
     NULL, NULL,
     NULL,                              "element can explode"
   },
   {
-    ED_ELEMENT_SETTINGS_XPOS(1),       ED_ELEMENT_SETTINGS_YPOS(11),
+    ED_ELEMENT_SETTINGS_XPOS(1),       ED_ELEMENT_SETTINGS_YPOS(12),
     GADGET_ID_CUSTOM_EXPLODE_FIRE,     GADGET_ID_NONE,
     &custom_element_properties[EP_EXPLODES_BY_FIRE],
     NULL, NULL,
     "by fire",                         "element can explode by fire/explosion"
   },
   {
-    -1,                                        ED_ELEMENT_SETTINGS_YPOS(11),
+    -1,                                        ED_ELEMENT_SETTINGS_YPOS(12),
     GADGET_ID_CUSTOM_EXPLODE_SMASH,    GADGET_ID_CUSTOM_EXPLODE_FIRE,
     &custom_element_properties[EP_EXPLODES_SMASHED],
     NULL, " ",
     "smashed",                         "element can explode when smashed"
   },
   {
-    -1,                                        ED_ELEMENT_SETTINGS_YPOS(11),
+    -1,                                        ED_ELEMENT_SETTINGS_YPOS(12),
     GADGET_ID_CUSTOM_EXPLODE_IMPACT,   GADGET_ID_CUSTOM_EXPLODE_SMASH,
     &custom_element_properties[EP_EXPLODES_IMPACT],
     NULL, " ",
@@ -3681,7 +3757,7 @@ static struct
   // ---------- custom content (when exploding) -------------------------------
 
   {
-    -1,                                        ED_AREA_3X3_SETTINGS_YPOS(10),
+    -1,                                        ED_AREA_3X3_SETTINGS_YPOS(11),
     0,                                 ED_AREA_3X3_SETTINGS_YOFF,
     GADGET_ID_CUSTOM_CONTENT,          GADGET_ID_NONE, // align three rows
     &custom_element.content.e[0][0],   3, 3,
@@ -5196,6 +5272,41 @@ static int *editor_el_group_ptr = editor_el_group;
 static int num_editor_hl_group = ARRAY_SIZE(editor_hl_group);
 static int num_editor_el_group = ARRAY_SIZE(editor_el_group);
 
+static int editor_hl_empty_space[] =
+{
+  EL_INTERNAL_CASCADE_ES_ACTIVE,
+  EL_CHAR('E'),
+  EL_CHAR('S'),
+  EL_EMPTY,
+};
+
+static int editor_el_empty_space[] =
+{
+  EL_EMPTY_SPACE_1,
+  EL_EMPTY_SPACE_2,
+  EL_EMPTY_SPACE_3,
+  EL_EMPTY_SPACE_4,
+
+  EL_EMPTY_SPACE_5,
+  EL_EMPTY_SPACE_6,
+  EL_EMPTY_SPACE_7,
+  EL_EMPTY_SPACE_8,
+
+  EL_EMPTY_SPACE_9,
+  EL_EMPTY_SPACE_10,
+  EL_EMPTY_SPACE_11,
+  EL_EMPTY_SPACE_12,
+
+  EL_EMPTY_SPACE_13,
+  EL_EMPTY_SPACE_14,
+  EL_EMPTY_SPACE_15,
+  EL_EMPTY_SPACE_16
+};
+static int *editor_hl_empty_space_ptr = editor_hl_empty_space;
+static int *editor_el_empty_space_ptr = editor_el_empty_space;
+static int num_editor_hl_empty_space = ARRAY_SIZE(editor_hl_empty_space);
+static int num_editor_el_empty_space = ARRAY_SIZE(editor_el_empty_space);
+
 static int editor_hl_reference[] =
 {
   EL_INTERNAL_CASCADE_REF_ACTIVE,
@@ -5408,6 +5519,12 @@ editor_elements_info[] =
     &editor_hl_group_ptr,              &num_editor_hl_group,
     &editor_el_group_ptr,              &num_editor_el_group
   },
+  {
+    &setup_editor_el_custom,
+    &setup.editor_cascade.el_es,
+    &editor_hl_empty_space_ptr,                &num_editor_hl_empty_space,
+    &editor_el_empty_space_ptr,                &num_editor_el_empty_space
+  },
   {
     &setup_editor_el_custom,
     &setup.editor_cascade.el_ref,
@@ -5440,6 +5557,14 @@ editor_elements_info[] =
   }
 };
 
+static struct XY xy_directions[] =
+{
+  { -1,  0 },
+  { +1,  0 },
+  {  0, -1 },
+  {  0, +1 }
+};
+
 
 // ----------------------------------------------------------------------------
 // functions
@@ -5493,7 +5618,7 @@ static char *getElementInfoText(int element)
 
 static char *getElementDescriptionFilenameExt(char *basename)
 {
-  char *elements_subdir = "elements";
+  char *elements_subdir = ELEMENTS_DIRECTORY;
   static char *elements_subdir2 = NULL;
   static char *filename = NULL;
 
@@ -5534,6 +5659,11 @@ static char *getElementDescriptionFilename(int element)
   if (filename != NULL)
     return filename;
 
+  // 3rd try: look for generic fallback text file for any element
+  filename = getElementDescriptionFilenameExt(FALLBACK_TEXT_FILENAME);
+  if (filename != NULL)
+    return filename;
+
   return NULL;
 }
 
@@ -5749,10 +5879,10 @@ static void ReinitializeElementList(void)
       int element = (*editor_elements_info[i].element_list)[j];
 
       if (element >= NUM_FILE_ELEMENTS)
-       Error(ERR_WARN, "editor element %d is runtime element", element);
+       Warn("editor element %d is runtime element", element);
 
       if (strEqual(getElementInfoText(element), INFOTEXT_UNKNOWN_ELEMENT))
-       Error(ERR_WARN, "no element description text for element %d", element);
+       Warn("no element description text for element %d", element);
     }
   }
 
@@ -6218,7 +6348,7 @@ static void CreateControlButtons(void)
                      GDI_END);
 
     if (gi == NULL)
-      Error(ERR_EXIT, "cannot create gadget");
+      Fail("cannot create gadget");
 
     level_editor_gadget[id] = gi;
   }
@@ -6284,7 +6414,7 @@ static void CreateControlButtons(void)
                      GDI_END);
 
     if (gi == NULL)
-      Error(ERR_EXIT, "cannot create gadget");
+      Fail("cannot create gadget");
 
     level_editor_gadget[id] = gi;
   }
@@ -6337,7 +6467,7 @@ static void CreateControlButtons(void)
                      GDI_END);
 
     if (gi == NULL)
-      Error(ERR_EXIT, "cannot create gadget");
+      Fail("cannot create gadget");
 
     level_editor_gadget[id] = gi;
   }
@@ -6431,7 +6561,7 @@ static void CreateCounterButtons(void)
                        GDI_END);
 
       if (gi == NULL)
-       Error(ERR_EXIT, "cannot create gadget");
+       Fail("cannot create gadget");
 
       level_editor_gadget[id] = gi;
       right_gadget_border[id] =
@@ -6493,7 +6623,7 @@ static void CreateCounterButtons(void)
                          GDI_END);
 
        if (gi == NULL)
-         Error(ERR_EXIT, "cannot create gadget");
+         Fail("cannot create gadget");
 
        level_editor_gadget[id] = gi;
        right_gadget_border[id] =
@@ -6551,7 +6681,7 @@ static void CreateDrawingAreas(void)
                      GDI_END);
 
     if (gi == NULL)
-      Error(ERR_EXIT, "cannot create gadget");
+      Fail("cannot create gadget");
 
     level_editor_gadget[id] = gi;
     right_gadget_border[id] =
@@ -6624,7 +6754,7 @@ static void CreateTextInputGadgets(void)
                      GDI_END);
 
     if (gi == NULL)
-      Error(ERR_EXIT, "cannot create gadget");
+      Fail("cannot create gadget");
 
     level_editor_gadget[id] = gi;
   }
@@ -6673,7 +6803,7 @@ static void CreateTextAreaGadgets(void)
                      GDI_END);
 
     if (gi == NULL)
-      Error(ERR_EXIT, "cannot create gadget");
+      Fail("cannot create gadget");
 
     level_editor_gadget[id] = gi;
   }
@@ -6752,7 +6882,7 @@ static void CreateSelectboxGadgets(void)
                      GDI_END);
 
     if (gi == NULL)
-      Error(ERR_EXIT, "cannot create gadget");
+      Fail("cannot create gadget");
 
     level_editor_gadget[id] = gi;
     right_gadget_border[id] =
@@ -6836,7 +6966,7 @@ static void CreateTextbuttonGadgets(void)
                      GDI_END);
 
     if (gi == NULL)
-      Error(ERR_EXIT, "cannot create gadget");
+      Fail("cannot create gadget");
 
     level_editor_gadget[id] = gi;
     right_gadget_border[id] =
@@ -6892,7 +7022,7 @@ static void CreateGraphicbuttonGadgets(void)
                      GDI_END);
 
     if (gi == NULL)
-      Error(ERR_EXIT, "cannot create gadget");
+      Fail("cannot create gadget");
 
     level_editor_gadget[id] = gi;
     right_gadget_border[id] =
@@ -7007,7 +7137,7 @@ static void CreateScrollbarGadgets(void)
                      GDI_END);
 
     if (gi == NULL)
-      Error(ERR_EXIT, "cannot create gadget");
+      Fail("cannot create gadget");
 
     level_editor_gadget[id] = gi;
   }
@@ -7067,7 +7197,7 @@ static void CreateCheckbuttonGadgets(void)
                      GDI_END);
 
     if (gi == NULL)
-      Error(ERR_EXIT, "cannot create gadget");
+      Fail("cannot create gadget");
 
     level_editor_gadget[id] = gi;
     right_gadget_border[id] =
@@ -7132,7 +7262,7 @@ static void CreateRadiobuttonGadgets(void)
                      GDI_END);
 
     if (gi == NULL)
-      Error(ERR_EXIT, "cannot create gadget");
+      Fail("cannot create gadget");
 
     level_editor_gadget[id] = gi;
     right_gadget_border[id] =
@@ -7151,7 +7281,7 @@ void CreateLevelEditorGadgets(void)
 
   num_editor_gadgets = NUM_EDITOR_GADGETS;
 
-  // printf("::: allocating %d gadgets ...\n", num_editor_gadgets);
+  // Debug("editor", "allocating %d gadgets ...\n", num_editor_gadgets);
 
   level_editor_gadget =
     checked_calloc(num_editor_gadgets * sizeof(struct GadgetInfo *));
@@ -7189,7 +7319,7 @@ void FreeLevelEditorGadgets(void)
 {
   int i;
 
-  // printf("::: freeing %d gadgets ...\n", num_editor_gadgets);
+  // Debug("editor", "freeing %d gadgets ...\n", num_editor_gadgets);
 
   for (i = 0; i < num_editor_gadgets; i++)
   {
@@ -7722,7 +7852,7 @@ static boolean PrepareSavingIntoPersonalLevelSet(void)
     return TRUE;
   }
 
-  if (!Request("This level is read only! "
+  if (!Request("This level is read-only! "
               "Save into personal level set?", REQ_ASK))
     return FALSE;
 
@@ -8136,7 +8266,8 @@ static void CopyCustomElementPropertiesToEditor(int element)
 
   // set "change by direct action" selectbox help value
   custom_element_change.direct_action =
-    (HAS_CHANGE_EVENT(element, CE_TOUCHED_BY_PLAYER) ? CE_TOUCHED_BY_PLAYER :
+    (HAS_CHANGE_EVENT(element, CE_NEXT_TO_PLAYER) ? CE_NEXT_TO_PLAYER :
+     HAS_CHANGE_EVENT(element, CE_TOUCHED_BY_PLAYER) ? CE_TOUCHED_BY_PLAYER :
      HAS_CHANGE_EVENT(element, CE_PRESSED_BY_PLAYER) ? CE_PRESSED_BY_PLAYER :
      HAS_CHANGE_EVENT(element, CE_SWITCHED_BY_PLAYER) ? CE_SWITCHED_BY_PLAYER :
      HAS_CHANGE_EVENT(element, CE_SNAPPED_BY_PLAYER) ? CE_SNAPPED_BY_PLAYER :
@@ -8160,7 +8291,8 @@ static void CopyCustomElementPropertiesToEditor(int element)
 
   // set "change by other element action" selectbox help value
   custom_element_change.other_action =
-    (HAS_CHANGE_EVENT(element, CE_PLAYER_TOUCHES_X) ? CE_PLAYER_TOUCHES_X :
+    (HAS_CHANGE_EVENT(element, CE_PLAYER_NEXT_TO_X) ? CE_PLAYER_NEXT_TO_X :
+     HAS_CHANGE_EVENT(element, CE_PLAYER_TOUCHES_X) ? CE_PLAYER_TOUCHES_X :
      HAS_CHANGE_EVENT(element, CE_PLAYER_PRESSES_X) ? CE_PLAYER_PRESSES_X :
      HAS_CHANGE_EVENT(element, CE_PLAYER_SWITCHES_X) ? CE_PLAYER_SWITCHES_X :
      HAS_CHANGE_EVENT(element, CE_PLAYER_SNAPS_X) ? CE_PLAYER_SNAPS_X :
@@ -8170,6 +8302,7 @@ static void CopyCustomElementPropertiesToEditor(int element)
      HAS_CHANGE_EVENT(element, CE_PLAYER_DIGS_X) ? CE_PLAYER_DIGS_X :
      HAS_CHANGE_EVENT(element, CE_PLAYER_COLLECTS_X) ? CE_PLAYER_COLLECTS_X :
      HAS_CHANGE_EVENT(element, CE_PLAYER_DROPS_X) ? CE_PLAYER_DROPS_X :
+     HAS_CHANGE_EVENT(element, CE_NEXT_TO_X) ? CE_NEXT_TO_X :
      HAS_CHANGE_EVENT(element, CE_TOUCHING_X) ? CE_TOUCHING_X :
      HAS_CHANGE_EVENT(element, CE_HITTING_X) ? CE_HITTING_X :
      HAS_CHANGE_EVENT(element, CE_DIGGING_X) ? CE_DIGGING_X :
@@ -8194,9 +8327,14 @@ static void CopyGroupElementPropertiesToEditor(int element)
   custom_element = element_info[element];      // needed for description
 }
 
+static void CopyEmptyElementPropertiesToEditor(int element)
+{
+  custom_element = element_info[element];
+}
+
 static void CopyClassicElementPropertiesToEditor(int element)
 {
-  if (ELEM_IS_PLAYER(element) || COULD_MOVE_INTO_ACID(element))
+  if (IS_PLAYER_ELEMENT(element) || COULD_MOVE_INTO_ACID(element))
     custom_element_properties[EP_CAN_MOVE_INTO_ACID] =
       getMoveIntoAcidProperty(&level, element);
 
@@ -8211,6 +8349,8 @@ static void CopyElementPropertiesToEditor(int element)
     CopyCustomElementPropertiesToEditor(element);
   else if (IS_GROUP_ELEMENT(element))
     CopyGroupElementPropertiesToEditor(element);
+  else if (IS_EMPTY_ELEMENT(element))
+    CopyEmptyElementPropertiesToEditor(element);
   else
     CopyClassicElementPropertiesToEditor(element);
 }
@@ -8298,6 +8438,7 @@ static void CopyCustomElementPropertiesToGame(int element)
   // ---------- element settings: advanced (custom elements) ------------------
 
   // set player change event from checkbox and selectbox
+  custom_element_change_events[CE_NEXT_TO_PLAYER] = FALSE;
   custom_element_change_events[CE_TOUCHED_BY_PLAYER] = FALSE;
   custom_element_change_events[CE_PRESSED_BY_PLAYER] = FALSE;
   custom_element_change_events[CE_SWITCHED_BY_PLAYER] = FALSE;
@@ -8322,6 +8463,7 @@ static void CopyCustomElementPropertiesToGame(int element)
     custom_element_change_events[CE_BY_DIRECT_ACTION];
 
   // set other element action change event from checkbox and selectbox
+  custom_element_change_events[CE_PLAYER_NEXT_TO_X] = FALSE;
   custom_element_change_events[CE_PLAYER_TOUCHES_X] = FALSE;
   custom_element_change_events[CE_PLAYER_PRESSES_X] = FALSE;
   custom_element_change_events[CE_PLAYER_SWITCHES_X] = FALSE;
@@ -8332,6 +8474,7 @@ static void CopyCustomElementPropertiesToGame(int element)
   custom_element_change_events[CE_PLAYER_DIGS_X] = FALSE;
   custom_element_change_events[CE_PLAYER_COLLECTS_X] = FALSE;
   custom_element_change_events[CE_PLAYER_DROPS_X] = FALSE;
+  custom_element_change_events[CE_NEXT_TO_X] = FALSE;
   custom_element_change_events[CE_TOUCHING_X] = FALSE;
   custom_element_change_events[CE_HITTING_X] = FALSE;
   custom_element_change_events[CE_DIGGING_X] = FALSE;
@@ -8380,9 +8523,24 @@ static void CopyGroupElementPropertiesToGame(int element)
   InitElementPropertiesGfxElement();
 }
 
+static void CopyEmptyElementPropertiesToGame(int element)
+{
+  // mark that this empty element has been modified
+  custom_element.modified_settings = TRUE;
+  level.changed = TRUE;
+
+  if (level.use_custom_template)
+    AskToCopyAndModifyLevelTemplate();
+
+  element_info[element] = custom_element;
+
+  // needed here to restore runtime value "element_info[element].gfx_element"
+  InitElementPropertiesGfxElement();
+}
+
 static void CopyClassicElementPropertiesToGame(int element)
 {
-  if (ELEM_IS_PLAYER(element) || COULD_MOVE_INTO_ACID(element))
+  if (IS_PLAYER_ELEMENT(element) || COULD_MOVE_INTO_ACID(element))
     setMoveIntoAcidProperty(&level, element,
                            custom_element_properties[EP_CAN_MOVE_INTO_ACID]);
 
@@ -8397,6 +8555,8 @@ static void CopyElementPropertiesToGame(int element)
     CopyCustomElementPropertiesToGame(element);
   else if (IS_GROUP_ELEMENT(element))
     CopyGroupElementPropertiesToGame(element);
+  else if (IS_EMPTY_ELEMENT(element))
+    CopyEmptyElementPropertiesToGame(element);
   else
     CopyClassicElementPropertiesToGame(element);
 }
@@ -8408,8 +8568,7 @@ static void CheckElementDescriptions(void)
 
   for (i = 0; i < NUM_FILE_ELEMENTS; i++)
     if (getElementDescriptionFilename(i) == NULL && !IS_OBSOLETE(i))
-      Error(ERR_WARN, "no element description file for element '%s'",
-           EL_NAME(i));
+      Warn("no element description file for element '%s'", EL_NAME(i));
 }
 #endif
 
@@ -9053,7 +9212,7 @@ static void DrawPropertiesTabulatorGadgets(void)
   int i;
 
   // draw two config tabulators for player elements
-  if (ELEM_IS_PLAYER(properties_element))
+  if (IS_PLAYER_ELEMENT(properties_element))
     id_last = ED_TEXTBUTTON_ID_PROPERTIES_CONFIG_2;
 
   // draw two config and one "change" tabulator for custom elements
@@ -9068,7 +9227,7 @@ static void DrawPropertiesTabulatorGadgets(void)
 
     // use "config 1" and "config 2" instead of "config" for players and CEs
     if (i == ED_TEXTBUTTON_ID_PROPERTIES_CONFIG &&
-       (ELEM_IS_PLAYER(properties_element) ||
+       (IS_PLAYER_ELEMENT(properties_element) ||
         IS_CUSTOM_ELEMENT(properties_element)))
       continue;
 
@@ -9761,11 +9920,12 @@ static boolean checkPropertiesConfig(int element)
   if (IS_GEM(element) ||
       IS_CUSTOM_ELEMENT(element) ||
       IS_GROUP_ELEMENT(element) ||
+      IS_EMPTY_ELEMENT(element) ||
       IS_BALLOON_ELEMENT(element) ||
       IS_ENVELOPE(element) ||
       IS_MM_MCDUFFIN(element) ||
       IS_DF_LASER(element) ||
-      ELEM_IS_PLAYER(element) ||
+      IS_PLAYER_ELEMENT(element) ||
       HAS_EDITOR_CONTENT(element) ||
       CAN_GROW(element) ||
       COULD_MOVE_INTO_ACID(element) ||
@@ -9922,7 +10082,7 @@ static void DrawPropertiesConfig(void)
       DrawAndroidElementArea(properties_element);
   }
 
-  if (ELEM_IS_PLAYER(properties_element))
+  if (IS_PLAYER_ELEMENT(properties_element))
   {
     int player_nr = GET_PLAYER_NR(properties_element);
 
@@ -9984,6 +10144,8 @@ static void DrawPropertiesConfig(void)
 
       // draw checkbutton gadgets
       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_INITIAL_INVENTORY);
+      MapCheckbuttonGadget(ED_CHECKBUTTON_ID_FINISH_DIG_COLLECT);
+      MapCheckbuttonGadget(ED_CHECKBUTTON_ID_KEEP_WALKABLE_CE);
 
       // draw counter gadgets
       MapCounterButtons(ED_COUNTER_ID_INVENTORY_SIZE);
@@ -10000,7 +10162,7 @@ static void DrawPropertiesConfig(void)
     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_EM_EXPLODES_BY_FIRE);
 
   if (COULD_MOVE_INTO_ACID(properties_element) &&
-      !ELEM_IS_PLAYER(properties_element) &&
+      !IS_PLAYER_ELEMENT(properties_element) &&
       (!IS_CUSTOM_ELEMENT(properties_element) ||
        edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_2))
   {
@@ -10008,7 +10170,7 @@ static void DrawPropertiesConfig(void)
     checkbutton_info[ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID].x =
       ED_ELEMENT_SETTINGS_XPOS(IS_CUSTOM_ELEMENT(properties_element) ? 1 : 0);
     checkbutton_info[ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID].y =
-      ED_ELEMENT_SETTINGS_YPOS(IS_CUSTOM_ELEMENT(properties_element) ? 6 :
+      ED_ELEMENT_SETTINGS_YPOS(IS_CUSTOM_ELEMENT(properties_element) ? 7 :
                               IS_BALLOON_ELEMENT(properties_element) ||
                               HAS_EDITOR_CONTENT(properties_element) ? 1 : 0);
 
@@ -10182,6 +10344,23 @@ static void DrawPropertiesConfig(void)
 
     draw_footer_line = TRUE;
   }
+  else if (IS_EMPTY_ELEMENT(properties_element))
+  {
+    // draw stickybutton gadget
+    MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
+
+    // draw checkbutton gadgets
+    MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC);
+    MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_1);
+
+    // draw textbutton gadgets
+    MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_1);
+
+    // draw drawing area gadgets
+    MapDrawingArea(ED_DRAWING_ID_CUSTOM_GRAPHIC);
+
+    draw_footer_line = TRUE;
+  }
 
   // draw little footer border line above CE/GE use/save template gadgets
   if (draw_footer_line)
@@ -10338,12 +10517,12 @@ static void DrawPropertiesWindow(void)
     edit_mode_properties = ED_MODE_PROPERTIES_CONFIG_2;
 
   if (edit_mode_properties > ED_MODE_PROPERTIES_CONFIG &&
-      !ELEM_IS_PLAYER(properties_element) &&
+      !IS_PLAYER_ELEMENT(properties_element) &&
       !IS_CUSTOM_ELEMENT(properties_element))
     edit_mode_properties = ED_MODE_PROPERTIES_CONFIG;
 
   if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG &&
-      (ELEM_IS_PLAYER(properties_element) ||
+      (IS_PLAYER_ELEMENT(properties_element) ||
        IS_CUSTOM_ELEMENT(properties_element)))
     edit_mode_properties = ED_MODE_PROPERTIES_CONFIG_1;
 
@@ -10664,13 +10843,7 @@ static int getChipFromOpenDirectionNotEmpty(int direction, int element_old)
 
 static int getClosedTube(int x, int y)
 {
-  static int xy[4][2] =
-  {
-    { -1, 0 },
-    { +1, 0 },
-    { 0, -1 },
-    { 0, +1 }
-  };
+  struct XY *xy = xy_directions;
   int element_old = IntelliDrawBuffer[x][y];
   int direction_old = getOpenDirectionFromTube(element_old);
   int direction_new = MV_NONE;
@@ -10678,8 +10851,8 @@ static int getClosedTube(int x, int y)
 
   for (i = 0; i < NUM_DIRECTIONS; i++)
   {
-    int xx = x + xy[i][0];
-    int yy = y + xy[i][1];
+    int xx = x + xy[i].x;
+    int yy = y + xy[i].y;
     int dir = MV_DIR_FROM_BIT(i);
     int dir_opposite = MV_DIR_OPPOSITE(dir);
 
@@ -10694,13 +10867,7 @@ static int getClosedTube(int x, int y)
 
 static int getClosedBelt(int x, int y)
 {
-  static int xy[4][2] =
-  {
-    { -1, 0 },
-    { +1, 0 },
-    { 0, -1 },
-    { 0, +1 }
-  };
+  struct XY *xy = xy_directions;
   int element_old = IntelliDrawBuffer[x][y];
   int nr = getBeltNrFromBeltElement(element_old);
   int direction_old = getOpenDirectionFromBelt(element_old);
@@ -10709,8 +10876,8 @@ static int getClosedBelt(int x, int y)
 
   for (i = MV_BIT_LEFT; i <= MV_BIT_RIGHT; i++)
   {
-    int xx = x + xy[i][0];
-    int yy = y + xy[i][1];
+    int xx = x + xy[i].x;
+    int yy = y + xy[i].y;
     int dir = MV_DIR_FROM_BIT(i);
     int dir_opposite = MV_DIR_OPPOSITE(dir);
 
@@ -10725,13 +10892,7 @@ static int getClosedBelt(int x, int y)
 
 static int getClosedPool(int x, int y)
 {
-  static int xy[4][2] =
-  {
-    { -1, 0 },
-    { +1, 0 },
-    { 0, -1 },
-    { 0, +1 }
-  };
+  struct XY *xy = xy_directions;
   int element_old = IntelliDrawBuffer[x][y];
   int direction_old = getOpenDirectionFromPool(element_old);
   int direction_new = MV_NONE;
@@ -10739,8 +10900,8 @@ static int getClosedPool(int x, int y)
 
   for (i = 0; i < NUM_DIRECTIONS; i++)
   {
-    int xx = x + xy[i][0];
-    int yy = y + xy[i][1];
+    int xx = x + xy[i].x;
+    int yy = y + xy[i].y;
     int dir = MV_DIR_FROM_BIT(i);
     int dir_opposite = MV_DIR_OPPOSITE(dir);
 
@@ -10756,13 +10917,7 @@ static int getClosedPool(int x, int y)
 
 static int getClosedPillar(int x, int y)
 {
-  static int xy[4][2] =
-  {
-    { -1, 0 },
-    { +1, 0 },
-    { 0, -1 },
-    { 0, +1 }
-  };
+  struct XY *xy = xy_directions;
   int element_old = IntelliDrawBuffer[x][y];
   int direction_old = getOpenDirectionFromPillar(element_old);
   int direction_new = MV_NONE;
@@ -10770,8 +10925,8 @@ static int getClosedPillar(int x, int y)
 
   for (i = MV_BIT_UP; i <= MV_BIT_DOWN; i++)
   {
-    int xx = x + xy[i][0];
-    int yy = y + xy[i][1];
+    int xx = x + xy[i].x;
+    int yy = y + xy[i].y;
     int dir = MV_DIR_FROM_BIT(i);
     int dir_opposite = MV_DIR_OPPOSITE(dir);
 
@@ -10786,13 +10941,7 @@ static int getClosedPillar(int x, int y)
 
 static int getClosedSteel2(int x, int y)
 {
-  static int xy[4][2] =
-  {
-    { -1, 0 },
-    { +1, 0 },
-    { 0, -1 },
-    { 0, +1 }
-  };
+  struct XY *xy = xy_directions;
   int element_old = IntelliDrawBuffer[x][y];
   int direction_old = getOpenDirectionFromSteel2(element_old);
   int direction_new = MV_NONE;
@@ -10800,8 +10949,8 @@ static int getClosedSteel2(int x, int y)
 
   for (i = 0; i < NUM_DIRECTIONS; i++)
   {
-    int xx = x + xy[i][0];
-    int yy = y + xy[i][1];
+    int xx = x + xy[i].x;
+    int yy = y + xy[i].y;
     int dir = MV_DIR_FROM_BIT(i);
     int dir_opposite = MV_DIR_OPPOSITE(dir);
 
@@ -10816,13 +10965,7 @@ static int getClosedSteel2(int x, int y)
 
 static int getClosedChip(int x, int y)
 {
-  static int xy[4][2] =
-  {
-    { -1, 0 },
-    { +1, 0 },
-    { 0, -1 },
-    { 0, +1 }
-  };
+  struct XY *xy = xy_directions;
   int element_old = IntelliDrawBuffer[x][y];
   int direction_old = getOpenDirectionFromChip(element_old);
   int direction_new = MV_NONE;
@@ -10830,8 +10973,8 @@ static int getClosedChip(int x, int y)
 
   for (i = 0; i < NUM_DIRECTIONS; i++)
   {
-    int xx = x + xy[i][0];
-    int yy = y + xy[i][1];
+    int xx = x + xy[i].x;
+    int yy = y + xy[i].y;
     int dir = MV_DIR_FROM_BIT(i);
     int dir_opposite = MV_DIR_OPPOSITE(dir);
 
@@ -10914,13 +11057,7 @@ static void MergeAndCloseNeighbourElements(int x1, int y1, int *element1,
 static void SetElementIntelliDraw(int x, int y, int new_element,
                                  boolean change_level, int button)
 {
-  static int xy[4][2] =
-  {
-    { -1, 0 },
-    { +1, 0 },
-    { 0, -1 },
-    { 0, +1 }
-  };
+  struct XY *xy = xy_directions;
   static int last_x = -1;
   static int last_y = -1;
 
@@ -10946,8 +11083,8 @@ static void SetElementIntelliDraw(int x, int y, int new_element,
 
     for (i = 0; i < NUM_DIRECTIONS; i++)
     {
-      int xx = x + xy[i][0];
-      int yy = y + xy[i][1];
+      int xx = x + xy[i].x;
+      int yy = y + xy[i].y;
 
       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
          IS_TUBE(IntelliDrawBuffer[last_x][last_y]))
@@ -10984,8 +11121,8 @@ static void SetElementIntelliDraw(int x, int y, int new_element,
 
     for (i = MV_BIT_LEFT; i <= MV_BIT_RIGHT; i++)
     {
-      int xx = x + xy[i][0];
-      int yy = y + xy[i][1];
+      int xx = x + xy[i].x;
+      int yy = y + xy[i].y;
 
       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
          IS_BELT(IntelliDrawBuffer[last_x][last_y]))
@@ -11022,8 +11159,8 @@ static void SetElementIntelliDraw(int x, int y, int new_element,
 
     for (i = 0; i < NUM_DIRECTIONS; i++)
     {
-      int xx = x + xy[i][0];
-      int yy = y + xy[i][1];
+      int xx = x + xy[i].x;
+      int yy = y + xy[i].y;
 
       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
          IS_ACID_POOL_OR_ACID(IntelliDrawBuffer[last_x][last_y]))
@@ -11065,8 +11202,8 @@ static void SetElementIntelliDraw(int x, int y, int new_element,
 
     for (i = MV_BIT_UP; i <= MV_BIT_DOWN; i++)
     {
-      int xx = x + xy[i][0];
-      int yy = y + xy[i][1];
+      int xx = x + xy[i].x;
+      int yy = y + xy[i].y;
 
       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
          IS_EMC_PILLAR(IntelliDrawBuffer[last_x][last_y]))
@@ -11102,8 +11239,8 @@ static void SetElementIntelliDraw(int x, int y, int new_element,
 
     for (i = 0; i < NUM_DIRECTIONS; i++)
     {
-      int xx = x + xy[i][0];
-      int yy = y + xy[i][1];
+      int xx = x + xy[i].x;
+      int yy = y + xy[i].y;
 
       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
          IS_DC_STEELWALL_2(IntelliDrawBuffer[last_x][last_y]))
@@ -11137,8 +11274,8 @@ static void SetElementIntelliDraw(int x, int y, int new_element,
 
     for (i = 0; i < NUM_DIRECTIONS; i++)
     {
-      int xx = x + xy[i][0];
-      int yy = y + xy[i][1];
+      int xx = x + xy[i].x;
+      int yy = y + xy[i].y;
 
       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
          IS_SP_CHIP(IntelliDrawBuffer[last_x][last_y]))
@@ -11198,8 +11335,8 @@ static void SetElementIntelliDraw(int x, int y, int new_element,
 
     for (i = 0; i < NUM_DIRECTIONS; i++)
     {
-      int xx = x + xy[i][0];
-      int yy = y + xy[i][1];
+      int xx = x + xy[i].x;
+      int yy = y + xy[i].y;
 
       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
          IS_IN_GROUP_EL(IntelliDrawBuffer[last_x][last_y], new_element))
@@ -12072,7 +12209,7 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
        mode == CB_BRUSH_TO_CLIPBOARD_SMALL)
       SDL_SetClipboardText(text);
     else
-      printf("%s", text);
+      Print("%s", text);       // print brush data to console and log file
 
     return;
   }
@@ -12163,6 +12300,9 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
          ptr++;
        }
 
+       // remap some (historic, now obsolete) elements
+       element = getMappedElement(element);
+
        if (element >= NUM_FILE_ELEMENTS)
          element = EL_UNKNOWN;
 
@@ -12238,6 +12378,36 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
       lev_fieldx = level.fieldx = brush_width;
       lev_fieldy = level.fieldy = brush_height;
 
+      boolean use_em_engine = TRUE;
+      boolean use_sp_engine = TRUE;
+      boolean use_mm_engine = TRUE;
+
+      for (x = 0; x < MAX_LEV_FIELDX; x++)
+      {
+       for (y = 0; y < MAX_LEV_FIELDY; y++)
+       {
+         int element = Tile[x][y];
+
+         if (!IS_EM_ELEMENT(element) && !IS_PLAYER_ELEMENT(element))
+           use_em_engine = FALSE;
+
+         if (!IS_SP_ELEMENT(element))
+           use_sp_engine = FALSE;
+
+         if (!IS_MM_ELEMENT(element) && element != EL_EMPTY)
+           use_mm_engine = FALSE;
+       }
+      }
+
+      level.game_engine_type = (use_em_engine ? GAME_ENGINE_TYPE_EM :
+                               use_sp_engine ? GAME_ENGINE_TYPE_SP :
+                               use_mm_engine ? GAME_ENGINE_TYPE_MM :
+                               GAME_ENGINE_TYPE_RND);
+
+      // update element selection list
+      ReinitializeElementList();
+      ModifyEditorElementList();
+
       SetBorderElement();
 
       DrawEditModeWindow();
@@ -12702,6 +12872,43 @@ static void WrapLevel(int dx, int dy)
   CopyLevelToUndoBuffer(UNDO_ACCUMULATE);
 }
 
+static void DrawAreaElementHighlight(boolean highlighted)
+{
+  DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
+
+  if (!highlighted)
+    return;
+
+  int x, y;
+
+  for (x = 0; x < ed_fieldx; x++)
+  {
+    for (y = 0; y < ed_fieldy; y++)
+    {
+      int lx = x + level_xpos;
+      int ly = y + level_ypos;
+
+      if (!IN_LEV_FIELD(lx, ly))
+       continue;
+
+      if (Tile[lx][ly] != new_element1)
+       continue;
+
+      int sx = SX + x * ed_tilesize;
+      int sy = SY + y * ed_tilesize;
+      int from_sx = sx;
+      int from_sy = sy;
+      int to_sx = sx + ed_tilesize - 1;
+      int to_sy = sy + ed_tilesize - 1;
+
+      DrawSimpleWhiteLine(drawto, from_sx, from_sy, to_sx,   from_sy);
+      DrawSimpleWhiteLine(drawto, to_sx,   from_sy, to_sx,   to_sy);
+      DrawSimpleWhiteLine(drawto, to_sx,   to_sy,   from_sx, to_sy);
+      DrawSimpleWhiteLine(drawto, from_sx, to_sy,   from_sx, from_sy);
+    }
+  }
+}
+
 static void CopyLevelTemplateToUserLevelSet(char *levelset_subdir)
 {
   char *template_filename_old = getLocalLevelTemplateFilename();
@@ -12864,7 +13071,7 @@ static void HandleDrawingAreas(struct GadgetInfo *gi)
        {
          SetDrawModeHiRes(new_element);
 
-         if (ELEM_IS_PLAYER(new_element))
+         if (IS_PLAYER_ELEMENT(new_element))
          {
            // remove player at old position
            for (y = 0; y < lev_fieldy; y++)
@@ -12873,7 +13080,7 @@ static void HandleDrawingAreas(struct GadgetInfo *gi)
              {
                int old_element = Tile[x][y];
 
-               if (ELEM_IS_PLAYER(old_element))
+               if (IS_PLAYER_ELEMENT(old_element))
                {
                  int replaced_with_element =
                    (old_element == EL_SOKOBAN_FIELD_PLAYER &&
@@ -13313,7 +13520,7 @@ static void HandleTextbuttonGadgets(struct GadgetInfo *gi)
     if (levelset_save_mode == LEVELSET_SAVE_MODE_UPDATE &&
        leveldir_current->readonly)
     {
-      Request("This level set is read only!", REQ_CONFIRM);
+      Request("This level set is read-only!", REQ_CONFIRM);
 
       return;
     }
@@ -13504,9 +13711,11 @@ static void HandleCheckbuttons(struct GadgetInfo *gi)
     boolean template_related_changes_found = FALSE;
     int i;
 
-    // check if any custom or group elements have been changed
+    // check if any custom, group or empty elements have been changed
     for (i = 0; i < NUM_FILE_ELEMENTS; i++)
-      if ((IS_CUSTOM_ELEMENT(i) || IS_GROUP_ELEMENT(i)) &&
+      if ((IS_CUSTOM_ELEMENT(i) ||
+          IS_GROUP_ELEMENT(i) ||
+          IS_EMPTY_ELEMENT(i)) &&
          element_info[i].modified_settings)
        template_related_changes_found = TRUE;
 
@@ -13774,7 +13983,7 @@ static void HandleControlButtons(struct GadgetInfo *gi)
       }
       else
       {
-       ChangeEditModeWindow(last_edit_mode);
+       ChangeEditModeWindow(ED_MODE_DRAWING);
 
        ClickOnGadget(level_editor_gadget[last_level_drawing_function],
                      MB_LEFTBUTTON);
@@ -13939,7 +14148,7 @@ static void HandleControlButtons(struct GadgetInfo *gi)
       }
       else
       {
-       ChangeEditModeWindow(last_edit_mode);
+       ChangeEditModeWindow(ED_MODE_DRAWING);
       }
       break;
 
@@ -14112,13 +14321,13 @@ static void HandleControlButtons(struct GadgetInfo *gi)
       }
 #ifdef DEBUG
       else if (gi->event.type == GD_EVENT_PRESSED)
-       printf("default: HandleControlButtons: GD_EVENT_PRESSED(%d)\n", id);
+       Debug("editor", "default: HandleControlButtons: GD_EVENT_PRESSED(%d)", id);
       else if (gi->event.type == GD_EVENT_RELEASED)
-       printf("default: HandleControlButtons: GD_EVENT_RELEASED(%d)\n", id);
+       Debug("editor", "default: HandleControlButtons: GD_EVENT_RELEASED(%d)", id);
       else if (gi->event.type == GD_EVENT_MOVING)
-       printf("default: HandleControlButtons: GD_EVENT_MOVING(%d)\n", id);
+       Debug("editor", "default: HandleControlButtons: GD_EVENT_MOVING(%d)", id);
       else
-       printf("default: HandleControlButtons: ? (id == %d)\n", id);
+       Debug("editor", "default: HandleControlButtons: ? (id == %d)", id);
 #endif
       break;
   }
@@ -14276,19 +14485,17 @@ void HandleLevelEditorKeyInput(Key key)
          ClickOnGadget(level_editor_gadget[i], button);
 }
 
-void HandleLevelEditorIdle(void)
+static void HandleLevelEditorIdle_Properties(void)
 {
   int element_border = graphic_info[IMG_EDITOR_ELEMENT_BORDER].border_size;
   int x = editor.settings.element_graphic.x + element_border;
   int y = editor.settings.element_graphic.y + element_border;
-  static unsigned int action_delay = 0;
-  unsigned int action_delay_value = GameFrameDelay;
+  static DelayCounter action_delay = { 0 };
   int i;
 
-  if (edit_mode != ED_MODE_PROPERTIES)
-    return;
+  action_delay.value = GameFrameDelay;
 
-  if (!DelayReached(&action_delay, action_delay_value))
+  if (!DelayReached(&action_delay))
     return;
 
   for (i = 0; i < ED_NUM_SELECTBOX; i++)
@@ -14306,6 +14513,29 @@ void HandleLevelEditorIdle(void)
   FrameCounter++;      // increase animation frame counter
 }
 
+static void HandleLevelEditorIdle_Drawing(void)
+{
+  static boolean last_highlighted = FALSE;
+  boolean highlighted = (GetKeyModState() & KMOD_Alt);
+
+  if (highlighted != last_highlighted)
+  {
+    DrawAreaElementHighlight(highlighted);
+
+    last_highlighted = highlighted;
+
+    redraw_mask |= REDRAW_FIELD;
+  }
+}
+
+void HandleLevelEditorIdle(void)
+{
+  if (edit_mode == ED_MODE_PROPERTIES)
+    HandleLevelEditorIdle_Properties();
+  else if (edit_mode == ED_MODE_DRAWING)
+    HandleLevelEditorIdle_Drawing();
+}
+
 static void ClearEditorGadgetInfoText(void)
 {
   DrawBackground(INFOTEXT_XPOS, INFOTEXT_YPOS, INFOTEXT_XSIZE, INFOTEXT_YSIZE);