rnd-20040205-1-src
[rocksndiamonds.git] / src / game.c
index cfb239c97717b8c1f120ee7153eaf2240b04bc8a..f5dc4186379d4a9063acd9b4441139d286ba1797 100644 (file)
 #define GET_MAX_MOVE_DELAY(e)  (   (element_info[e].move_delay_fixed) + \
                                    (element_info[e].move_delay_random))
 
+#if 1
+#define ELEMENT_CAN_ENTER_FIELD_GENERIC(e, x, y, condition)            \
+               (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) ||                \
+                                       (condition) ||                  \
+                                       (DONT_COLLIDE_WITH(e) &&        \
+                                        IS_PLAYER(x, y) &&             \
+                                        !PLAYER_PROTECTED(x, y))))
+#else
 #define ELEMENT_CAN_ENTER_FIELD_GENERIC(e, x, y, condition)            \
                (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) ||                \
                                        (condition) ||                  \
                                        (DONT_COLLIDE_WITH(e) &&        \
                                         IS_FREE_OR_PLAYER(x, y))))
+#endif
 
 #define ELEMENT_CAN_ENTER_FIELD_GENERIC_2(x, y, condition)             \
                (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) ||                \
                                        Feld[x][y] == EL_EXIT_OPEN ||   \
                                        Feld[x][y] == EL_ACID))
 
+#if 0
+#if 1
+#define MAZE_RUNNER_CAN_ENTER_FIELD(x, y)                              \
+               (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
+#else
+#define MAZE_RUNNER_CAN_ENTER_FIELD(x, y)                              \
+               (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) ||                \
+                                       IS_FOOD_DARK_YAMYAM(Feld[x][y])))
+#endif
+#endif
+
+#define GROUP_NR(e)            ((e) - EL_GROUP_START)
+#define MOVE_ENTER_EL(e)       (element_info[e].move_enter_element)
+#define IS_IN_GROUP(e, nr)     (element_info[e].in_group[nr] == TRUE)
+#define IS_IN_GROUP_EL(e, ge)  (IS_IN_GROUP(e, (ge) - EL_GROUP_START))
+
+#define IS_EQUAL_OR_IN_GROUP(e, ge)                                    \
+       (IS_GROUP_ELEMENT(ge) ? IS_IN_GROUP(e, GROUP_NR(ge)) : (e) == (ge))
+
+#if 1
+#define CE_ENTER_FIELD_COND(e, x, y)                                   \
+               (!IS_PLAYER(x, y) &&                                    \
+                (Feld[x][y] == EL_ACID ||                              \
+                 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e))))
+#else
+#define CE_ENTER_FIELD_COND(e, x, y)                                   \
+               (!IS_PLAYER(x, y) &&                                    \
+                (Feld[x][y] == EL_ACID ||                              \
+                 Feld[x][y] == MOVE_ENTER_EL(e) ||                     \
+                 (IS_GROUP_ELEMENT(MOVE_ENTER_EL(e)) &&                \
+                  IS_IN_GROUP_EL(Feld[x][y], MOVE_ENTER_EL(e)))))
+#endif
+
+#define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y)                                \
+       ELEMENT_CAN_ENTER_FIELD_GENERIC(e, x, y, CE_ENTER_FIELD_COND(e, x, y))
+
 #define MOLE_CAN_ENTER_FIELD(x, y, condition)                          \
                (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || (condition)))
 
@@ -175,6 +220,7 @@ static void KillHeroUnlessProtected(int, int);
 
 static void TestIfPlayerTouchesCustomElement(int, int);
 static void TestIfElementTouchesCustomElement(int, int);
+static void TestIfElementHitsCustomElement(int, int, int);
 
 static void ChangeElement(int, int, int);
 static boolean CheckTriggeredElementSideChange(int, int, int, int, int);
@@ -182,12 +228,14 @@ static boolean CheckTriggeredElementChange(int, int, int, int);
 static boolean CheckElementSideChange(int, int, int, int, int, int);
 static boolean CheckElementChange(int, int, int, int);
 
-static void PlaySoundLevel(int, int, int);
-static void PlaySoundLevelNearest(int, int, int);
-static void PlaySoundLevelAction(int, int, int);
-static void PlaySoundLevelElementAction(int, int, int, int);
-static void PlaySoundLevelActionIfLoop(int, int, int);
-static void StopSoundLevelActionIfLoop(int, int, int);
+static void PlayLevelSound(int, int, int);
+static void PlayLevelSoundNearest(int, int, int);
+static void PlayLevelSoundAction(int, int, int);
+static void PlayLevelSoundElementAction(int, int, int, int);
+static void PlayLevelSoundElementActionIfLoop(int, int, int, int);
+static void PlayLevelSoundActionIfLoop(int, int, int);
+static void StopLevelSoundActionIfLoop(int, int, int);
+static void PlayLevelMusic();
 
 static void MapGameButtons();
 static void HandleGameButtons(struct GadgetInfo *);
@@ -558,6 +606,10 @@ static void InitPlayerField(int x, int y, int element, boolean init_game)
 
     player->present = TRUE;
 
+    player->block_last_field = (element == EL_SP_MURPHY ?
+                               level.sp_block_last_field :
+                               level.block_last_field);
+
     if (!options.network || player->connected)
     {
       player->active = TRUE;
@@ -597,6 +649,18 @@ static void InitField(int x, int y, boolean init_game)
       InitPlayerField(x, y, element, init_game);
       break;
 
+    case EL_SOKOBAN_FIELD_PLAYER:
+      element = Feld[x][y] = EL_PLAYER_1;
+      InitField(x, y, init_game);
+
+      element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
+      InitField(x, y, init_game);
+      break;
+
+    case EL_SOKOBAN_FIELD_EMPTY:
+      local_player->sokobanfields_still_needed++;
+      break;
+
     case EL_STONEBLOCK:
       if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
        Feld[x][y] = EL_ACID_POOL_TOPLEFT;
@@ -662,6 +726,11 @@ static void InitField(int x, int y, boolean init_game)
       break;
 
     case EL_DYNAMITE_ACTIVE:
+    case EL_SP_DISK_RED_ACTIVE:
+    case EL_DYNABOMB_PLAYER_1_ACTIVE:
+    case EL_DYNABOMB_PLAYER_2_ACTIVE:
+    case EL_DYNABOMB_PLAYER_3_ACTIVE:
+    case EL_DYNABOMB_PLAYER_4_ACTIVE:
       MovDelay[x][y] = 96;
       break;
 
@@ -669,10 +738,6 @@ static void InitField(int x, int y, boolean init_game)
       local_player->lights_still_needed++;
       break;
 
-    case EL_SOKOBAN_FIELD_EMPTY:
-      local_player->sokobanfields_still_needed++;
-      break;
-
     case EL_PENGUIN:
       local_player->friends_still_needed++;
       break;
@@ -746,6 +811,28 @@ static void InitField(int x, int y, boolean init_game)
     default:
       if (IS_CUSTOM_ELEMENT(element) && CAN_MOVE(element))
        InitMovDir(x, y);
+      else if (IS_GROUP_ELEMENT(element))
+      {
+       struct ElementGroupInfo *group = element_info[element].group;
+       int last_anim_random_frame = gfx.anim_random_frame;
+       int element_pos;
+
+       if (group->choice_mode == ANIM_RANDOM)
+         gfx.anim_random_frame = RND(group->num_elements_resolved);
+
+       element_pos = getAnimationFrame(group->num_elements_resolved, 1,
+                                       group->choice_mode, 0,
+                                       group->choice_pos);
+
+       if (group->choice_mode == ANIM_RANDOM)
+         gfx.anim_random_frame = last_anim_random_frame;
+
+       group->choice_pos++;
+
+       Feld[x][y] = group->element_resolved[element_pos];
+
+       InitField(x, y, init_game);
+      }
       break;
   }
 }
@@ -754,8 +841,8 @@ void DrawGameDoorValues()
 {
   int i, j;
 
-  for (i=0; i<MAX_PLAYERS; i++)
-    for (j=0; j<4; j++)
+  for (i = 0; i < MAX_PLAYERS; i++)
+    for (j = 0; j < 4; j++)
       if (stored_player[i].key[j])
        DrawMiniGraphicExt(drawto, DX_KEYS + j * MINI_TILEX, DY_KEYS,
                           el2edimg(EL_KEY_1 + j));
@@ -770,6 +857,61 @@ void DrawGameDoorValues()
           int2str(TimeLeft, 3), FONT_TEXT_2);
 }
 
+static void resolve_group_element(int group_element, int recursion_depth)
+{
+  static int group_nr;
+  static struct ElementGroupInfo *group;
+  struct ElementGroupInfo *actual_group = element_info[group_element].group;
+  int i;
+
+  if (recursion_depth > NUM_GROUP_ELEMENTS)    /* recursion too deep */
+  {
+    Error(ERR_WARN, "recursion too deep when resolving group element %d",
+         group_element - EL_GROUP_START + 1);
+
+    /* replace element which caused too deep recursion by question mark */
+    group->element_resolved[group->num_elements_resolved++] = EL_UNKNOWN;
+
+    return;
+  }
+
+  if (recursion_depth == 0)                    /* initialization */
+  {
+    group = element_info[group_element].group;
+    group_nr = group_element - EL_GROUP_START;
+
+    group->num_elements_resolved = 0;
+    group->choice_pos = 0;
+  }
+
+  for (i = 0; i < actual_group->num_elements; i++)
+  {
+    int element = actual_group->element[i];
+
+    if (group->num_elements_resolved == NUM_FILE_ELEMENTS)
+      break;
+
+    if (IS_GROUP_ELEMENT(element))
+      resolve_group_element(element, recursion_depth + 1);
+    else
+    {
+      group->element_resolved[group->num_elements_resolved++] = element;
+      element_info[element].in_group[group_nr] = TRUE;
+    }
+  }
+
+#if 0
+  if (recursion_depth == 0 && group_element <= EL_GROUP_4)
+  {
+    printf("::: group %d: %d resolved elements\n",
+          group_element - EL_GROUP_START, group->num_elements_resolved);
+    for (i = 0; i < group->num_elements_resolved; i++)
+      printf("::: - %d ['%s']\n", group->element_resolved[i],
+            element_info[group->element_resolved[i]].token_name);
+  }
+#endif
+}
+
 
 /*
   =============================================================================
@@ -798,6 +940,15 @@ static void InitGameEngine()
   printf("       => game.engine_version == %06d\n", game.engine_version);
 #endif
 
+  /* ---------- recursively resolve group elements ------------------------- */
+
+  for (i = 0; i < MAX_NUM_ELEMENTS; i++)
+    for (j = 0; j < NUM_GROUP_ELEMENTS; j++)
+      element_info[i].in_group[j] = FALSE;
+
+  for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
+    resolve_group_element(EL_GROUP_START + i, 0);
+
   /* ---------- initialize player's initial move delay --------------------- */
 
   /* dynamically adjust player properties according to game engine version */
@@ -818,7 +969,7 @@ static void InitGameEngine()
   /* ---------- initialize changing elements ------------------------------- */
 
   /* initialize changing elements information */
-  for (i=0; i < MAX_NUM_ELEMENTS; i++)
+  for (i = 0; i < MAX_NUM_ELEMENTS; i++)
   {
     struct ElementInfo *ei = &element_info[i];
 
@@ -834,7 +985,7 @@ static void InitGameEngine()
     }
 
     ei->change_events = CE_BITMASK_DEFAULT;
-    for (j=0; j < NUM_CHANGE_EVENTS; j++)
+    for (j = 0; j < NUM_CHANGE_EVENTS; j++)
     {
       ei->event_page_nr[j] = 0;
       ei->event_page[j] = &ei->change_page[0];
@@ -842,7 +993,7 @@ static void InitGameEngine()
   }
 
   /* add changing elements from pre-defined list */
-  for (i=0; change_delay_list[i].element != EL_UNDEFINED; i++)
+  for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
   {
     struct ChangingElementInfo *ch_delay = &change_delay_list[i];
     struct ElementInfo *ei = &element_info[ch_delay->element];
@@ -859,16 +1010,16 @@ static void InitGameEngine()
 
 #if 1
   /* add change events from custom element configuration */
-  for (i=0; i < NUM_CUSTOM_ELEMENTS; i++)
+  for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
   {
     struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
 
-    for (j=0; j < ei->num_change_pages; j++)
+    for (j = 0; j < ei->num_change_pages; j++)
     {
       if (!ei->change_page[j].can_change)
        continue;
 
-      for (k=0; k < NUM_CHANGE_EVENTS; k++)
+      for (k = 0; k < NUM_CHANGE_EVENTS; k++)
       {
        /* only add event page for the first page found with this event */
        if (ei->change_page[j].events & CH_EVENT_BIT(k) &&
@@ -885,7 +1036,7 @@ static void InitGameEngine()
 #else
 
   /* add change events from custom element configuration */
-  for (i=0; i < NUM_CUSTOM_ELEMENTS; i++)
+  for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
   {
     int element = EL_CUSTOM_START + i;
 
@@ -898,16 +1049,16 @@ static void InitGameEngine()
   /* ---------- initialize trigger events ---------------------------------- */
 
   /* initialize trigger events information */
-  for (i=0; i<MAX_NUM_ELEMENTS; i++)
+  for (i = 0; i < MAX_NUM_ELEMENTS; i++)
     trigger_events[i] = EP_BITMASK_DEFAULT;
 
 #if 1
   /* add trigger events from element change event properties */
-  for (i=0; i<MAX_NUM_ELEMENTS; i++)
+  for (i = 0; i < MAX_NUM_ELEMENTS; i++)
   {
     struct ElementInfo *ei = &element_info[i];
 
-    for (j=0; j < ei->num_change_pages; j++)
+    for (j = 0; j < ei->num_change_pages; j++)
     {
       if (!ei->change_page[j].can_change)
        continue;
@@ -916,13 +1067,22 @@ static void InitGameEngine()
       {
        int trigger_element = ei->change_page[j].trigger_element;
 
-       trigger_events[trigger_element] |= ei->change_page[j].events;
+       if (IS_GROUP_ELEMENT(trigger_element))
+       {
+         struct ElementGroupInfo *group = element_info[trigger_element].group;
+
+         for (k = 0; k < group->num_elements_resolved; k++)
+           trigger_events[group->element_resolved[k]]
+             |= ei->change_page[j].events;
+       }
+       else
+         trigger_events[trigger_element] |= ei->change_page[j].events;
       }
     }
   }
 #else
   /* add trigger events from element change event properties */
-  for (i=0; i<MAX_NUM_ELEMENTS; i++)
+  for (i = 0; i < MAX_NUM_ELEMENTS; i++)
     if (HAS_CHANGE_EVENT(i, CE_BY_OTHER_ACTION))
       trigger_events[element_info[i].change->trigger_element] |=
        element_info[i].change->events;
@@ -931,7 +1091,7 @@ static void InitGameEngine()
   /* ---------- initialize push delay -------------------------------------- */
 
   /* initialize push delay values to default */
-  for (i=0; i<MAX_NUM_ELEMENTS; i++)
+  for (i = 0; i < MAX_NUM_ELEMENTS; i++)
   {
     if (!IS_CUSTOM_ELEMENT(i))
     {
@@ -941,7 +1101,7 @@ static void InitGameEngine()
   }
 
   /* set push delay value for certain elements from pre-defined list */
-  for (i=0; push_delay_list[i].element != EL_UNDEFINED; i++)
+  for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
   {
     int e = push_delay_list[i].element;
 
@@ -949,30 +1109,51 @@ static void InitGameEngine()
     element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
   }
 
+  /* set push delay value for Supaplex elements for newer engine versions */
+  if (game.engine_version >= VERSION_IDENT(3,0,9,0))
+  {
+    for (i = 0; i < MAX_NUM_ELEMENTS; i++)
+    {
+      if (IS_SP_ELEMENT(i))
+      {
+       element_info[i].push_delay_fixed  = 6;
+       element_info[i].push_delay_random = 0;
+      }
+    }
+  }
+
   /* ---------- initialize move stepsize ----------------------------------- */
 
   /* initialize move stepsize values to default */
-  for (i=0; i<MAX_NUM_ELEMENTS; i++)
+  for (i = 0; i < MAX_NUM_ELEMENTS; i++)
     if (!IS_CUSTOM_ELEMENT(i))
       element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
 
   /* set move stepsize value for certain elements from pre-defined list */
-  for (i=0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
+  for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
   {
     int e = move_stepsize_list[i].element;
 
     element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
   }
 
+  /* ---------- initialize move dig/leave ---------------------------------- */
+
+  for (i = 0; i < MAX_NUM_ELEMENTS; i++)
+  {
+    element_info[i].can_leave_element = FALSE;
+    element_info[i].can_leave_element_last = FALSE;
+  }
+
   /* ---------- initialize gem count --------------------------------------- */
 
   /* initialize gem count values for each element */
-  for (i=0; i<MAX_NUM_ELEMENTS; i++)
+  for (i = 0; i < MAX_NUM_ELEMENTS; i++)
     if (!IS_CUSTOM_ELEMENT(i))
       element_info[i].collect_count = 0;
 
   /* add gem count values for all elements from pre-defined list */
-  for (i=0; collect_count_list[i].element != EL_UNDEFINED; i++)
+  for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
     element_info[collect_count_list[i].element].collect_count =
       collect_count_list[i].count;
 }
@@ -991,7 +1172,7 @@ void InitGame()
   boolean emulate_bd = TRUE;   /* unless non-BOULDERDASH elements found */
   boolean emulate_sb = TRUE;   /* unless non-SOKOBAN     elements found */
   boolean emulate_sp = TRUE;   /* unless non-SUPAPLEX    elements found */
-  int i, j, x, y;
+  int i, j, k, x, y;
 
   InitGameEngine();
 
@@ -1008,7 +1189,7 @@ void InitGame()
   /* don't play tapes over network */
   network_playing = (options.network && !tape.playing);
 
-  for (i=0; i<MAX_PLAYERS; i++)
+  for (i = 0; i < MAX_PLAYERS; i++)
   {
     struct PlayerInfo *player = &stored_player[i];
 
@@ -1028,7 +1209,7 @@ void InitGame()
     player->lights_still_needed = 0;
     player->friends_still_needed = 0;
 
-    for (j=0; j<4; j++)
+    for (j = 0; j < 4; j++)
       player->key[j] = FALSE;
 
     player->dynabomb_count = 0;
@@ -1046,8 +1227,12 @@ void InitGame()
 
     player->use_murphy_graphic = FALSE;
 
+    player->block_last_field = FALSE;
+
     player->actual_frame_counter = 0;
 
+    player->step_counter = 0;
+
     player->last_move_dir = MV_NO_MOVING;
 
     player->is_waiting = FALSE;
@@ -1057,6 +1242,54 @@ void InitGame()
     player->is_collecting = FALSE;
     player->is_pushing = FALSE;
     player->is_switching = FALSE;
+    player->is_dropping = FALSE;
+
+    player->is_bored = FALSE;
+    player->is_sleeping = FALSE;
+
+    player->frame_counter_bored = -1;
+    player->frame_counter_sleeping = -1;
+
+    player->anim_delay_counter = 0;
+    player->post_delay_counter = 0;
+
+    player->action_waiting = ACTION_DEFAULT;
+    player->last_action_waiting = ACTION_DEFAULT;
+    player->special_action_bored = ACTION_DEFAULT;
+    player->special_action_sleeping = ACTION_DEFAULT;
+
+    player->num_special_action_bored = 0;
+    player->num_special_action_sleeping = 0;
+
+    /* determine number of special actions for bored and sleeping animation */
+    for (j = ACTION_BORING_1; j <= ACTION_BORING_LAST; j++)
+    {
+      boolean found = FALSE;
+
+      for (k = 0; k < NUM_DIRECTIONS; k++)
+       if (el_act_dir2img(player->element_nr, j, k) !=
+           el_act_dir2img(player->element_nr, ACTION_DEFAULT, k))
+         found = TRUE;
+
+      if (found)
+       player->num_special_action_bored++;
+      else
+       break;
+    }
+    for (j = ACTION_SLEEPING_1; j <= ACTION_SLEEPING_LAST; j++)
+    {
+      boolean found = FALSE;
+
+      for (k = 0; k < NUM_DIRECTIONS; k++)
+       if (el_act_dir2img(player->element_nr, j, k) !=
+           el_act_dir2img(player->element_nr, ACTION_DEFAULT, k))
+         found = TRUE;
+
+      if (found)
+       player->num_special_action_sleeping++;
+      else
+       break;
+    }
 
     player->switch_x = -1;
     player->switch_y = -1;
@@ -1066,9 +1299,13 @@ void InitGame()
     player->move_delay       = game.initial_move_delay;
     player->move_delay_value = game.initial_move_delay_value;
 
+    player->move_delay_reset_counter = 0;
+
     player->push_delay = 0;
     player->push_delay_value = game.initial_push_delay_value;
 
+    player->drop_delay = 0;
+
     player->last_jx = player->last_jy = 0;
     player->jx = player->jy = 0;
 
@@ -1119,18 +1356,18 @@ void InitGame()
 
   game.envelope_active = FALSE;
 
-  for (i=0; i<4; i++)
+  for (i = 0; i < 4; i++)
   {
     game.belt_dir[i] = MV_NO_MOVING;
     game.belt_dir_nr[i] = 3;           /* not moving, next moving left */
   }
 
-  for (i=0; i<MAX_NUM_AMOEBA; i++)
+  for (i = 0; i < MAX_NUM_AMOEBA; i++)
     AmoebaCnt[i] = AmoebaCnt2[i] = 0;
 
-  for (x=0; x<lev_fieldx; x++)
+  for (x = 0; x < lev_fieldx; x++)
   {
-    for (y=0; y<lev_fieldy; y++)
+    for (y = 0; y < lev_fieldy; y++)
     {
       Feld[x][y] = level.field[x][y];
       MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
@@ -1149,6 +1386,9 @@ void InitGame()
       ExplodePhase[x][y] = 0;
       ExplodeField[x][y] = EX_NO_EXPLOSION;
 
+      RunnerVisit[x][y] = 0;
+      PlayerVisit[x][y] = 0;
+
       GfxFrame[x][y] = 0;
       GfxRandom[x][y] = INIT_GFX_RANDOM();
       GfxElement[x][y] = EL_UNDEFINED;
@@ -1157,9 +1397,9 @@ void InitGame()
     }
   }
 
-  for(y=0; y<lev_fieldy; y++)
+  for (y = 0; y < lev_fieldy; y++)
   {
-    for(x=0; x<lev_fieldx; x++)
+    for (x = 0; x < lev_fieldx; x++)
     {
       if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
        emulate_bd = FALSE;
@@ -1179,18 +1419,18 @@ void InitGame()
                    emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
 
   /* correct non-moving belts to start moving left */
-  for (i=0; i<4; i++)
+  for (i = 0; i < 4; i++)
     if (game.belt_dir[i] == MV_NO_MOVING)
       game.belt_dir_nr[i] = 3;         /* not moving, next moving left */
 
   /* check if any connected player was not found in playfield */
-  for (i=0; i<MAX_PLAYERS; i++)
+  for (i = 0; i < MAX_PLAYERS; i++)
   {
     struct PlayerInfo *player = &stored_player[i];
 
     if (player->connected && !player->present)
     {
-      for (j=0; j<MAX_PLAYERS; j++)
+      for (j = 0; j < MAX_PLAYERS; j++)
       {
        struct PlayerInfo *some_player = &stored_player[j];
        int jx = some_player->jx, jy = some_player->jy;
@@ -1200,7 +1440,9 @@ void InitGame()
        {
          player->present = TRUE;
          player->active = TRUE;
+
          some_player->present = FALSE;
+         some_player->active = FALSE;
 
          StorePlayer[jx][jy] = player->element_nr;
          player->jx = player->last_jx = jx;
@@ -1214,9 +1456,9 @@ void InitGame()
 
   if (tape.playing)
   {
-    /* when playing a tape, eliminate all players who do not participate */
+    /* when playing a tape, eliminate all players which do not participate */
 
-    for (i=0; i<MAX_PLAYERS; i++)
+    for (i = 0; i < MAX_PLAYERS; i++)
     {
       if (stored_player[i].active && !tape.player_participates[i])
       {
@@ -1233,11 +1475,11 @@ void InitGame()
   {
     /* when in single player mode, eliminate all but the first active player */
 
-    for (i=0; i<MAX_PLAYERS; i++)
+    for (i = 0; i < MAX_PLAYERS; i++)
     {
       if (stored_player[i].active)
       {
-       for (j=i+1; j<MAX_PLAYERS; j++)
+       for (j = i + 1; j < MAX_PLAYERS; j++)
        {
          if (stored_player[j].active)
          {
@@ -1245,6 +1487,8 @@ void InitGame()
            int jx = player->jx, jy = player->jy;
 
            player->active = FALSE;
+           player->present = FALSE;
+
            StorePlayer[jx][jy] = 0;
            Feld[jx][jy] = EL_EMPTY;
          }
@@ -1256,14 +1500,14 @@ void InitGame()
   /* when recording the game, store which players take part in the game */
   if (tape.recording)
   {
-    for (i=0; i<MAX_PLAYERS; i++)
+    for (i = 0; i < MAX_PLAYERS; i++)
       if (stored_player[i].active)
        tape.player_participates[i] = TRUE;
   }
 
   if (options.debug)
   {
-    for (i=0; i<MAX_PLAYERS; i++)
+    for (i = 0; i < MAX_PLAYERS; i++)
     {
       struct PlayerInfo *player = &stored_player[i];
 
@@ -1306,7 +1550,7 @@ void InitGame()
     int found_rating = 0;
     int found_element = EL_UNDEFINED;
 
-    for(y=0; y < lev_fieldy; y++) for(x=0; x < lev_fieldx; x++)
+    for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
     {
       int element = Feld[x][y];
       int content;
@@ -1318,7 +1562,7 @@ void InitGame()
 
       if (CAN_CHANGE(element))
       {
-       for (i=0; i < element_info[element].num_change_pages; i++)
+       for (i = 0; i < element_info[element].num_change_pages; i++)
        {
          content = element_info[element].change_page[i].target_element;
          is_player = ELEM_IS_PLAYER(content);
@@ -1334,7 +1578,7 @@ void InitGame()
        }
       }
 
-      for(yy=0; yy < 3; yy++) for(xx=0; xx < 3; xx++)
+      for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
       {
        content = element_info[element].content[xx][yy];
        is_player = ELEM_IS_PLAYER(content);
@@ -1351,7 +1595,7 @@ void InitGame()
        if (!CAN_CHANGE(element))
          continue;
 
-       for (i=0; i < element_info[element].num_change_pages; i++)
+       for (i = 0; i < element_info[element].num_change_pages; i++)
        {
          content = element_info[element].change_page[i].content[xx][yy];
          is_player = ELEM_IS_PLAYER(content);
@@ -1449,17 +1693,22 @@ void InitGame()
   OpenDoor(DOOR_OPEN_ALL);
 
   PlaySoundStereo(SND_GAME_STARTING, SOUND_MIDDLE);
+
   if (setup.sound_music)
-    PlayMusic(level_nr);
+    PlayLevelMusic();
 
   KeyboardAutoRepeatOffUnlessAutoplay();
 
   if (options.debug)
   {
-    for (i=0; i<4; i++)
+    for (i = 0; i < 4; i++)
       printf("Player %d %sactive.\n",
             i + 1, (stored_player[i].active ? "" : "not "));
   }
+
+#if 0
+  printf("::: starting game [%d]\n", FrameCounter);
+#endif
 }
 
 void InitMovDir(int x, int y)
@@ -1540,29 +1789,46 @@ void InitMovDir(int x, int y)
     default:
       if (IS_CUSTOM_ELEMENT(element))
       {
-       if (element_info[element].move_direction_initial != MV_NO_MOVING)
-         MovDir[x][y] = element_info[element].move_direction_initial;
-       else if (element_info[element].move_pattern == MV_ALL_DIRECTIONS ||
-                element_info[element].move_pattern == MV_TURNING_LEFT ||
-                element_info[element].move_pattern == MV_TURNING_RIGHT)
+       struct ElementInfo *ei = &element_info[element];
+       int move_direction_initial = ei->move_direction_initial;
+       int move_pattern = ei->move_pattern;
+
+       if (move_direction_initial == MV_START_PREVIOUS)
+       {
+         if (MovDir[x][y] != MV_NO_MOVING)
+           return;
+
+         move_direction_initial = MV_START_AUTOMATIC;
+       }
+
+       if (move_direction_initial == MV_START_RANDOM)
          MovDir[x][y] = 1 << RND(4);
-       else if (element_info[element].move_pattern == MV_HORIZONTAL)
+       else if (move_direction_initial & MV_ANY_DIRECTION)
+         MovDir[x][y] = move_direction_initial;
+       else if (move_pattern == MV_ALL_DIRECTIONS ||
+                move_pattern == MV_TURNING_LEFT ||
+                move_pattern == MV_TURNING_RIGHT ||
+                move_pattern == MV_TURNING_LEFT_RIGHT ||
+                move_pattern == MV_TURNING_RIGHT_LEFT ||
+                move_pattern == MV_TURNING_RANDOM)
+         MovDir[x][y] = 1 << RND(4);
+       else if (move_pattern == MV_HORIZONTAL)
          MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
-       else if (element_info[element].move_pattern == MV_VERTICAL)
+       else if (move_pattern == MV_VERTICAL)
          MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
-       else if (element_info[element].move_pattern & MV_ANY_DIRECTION)
+       else if (move_pattern & MV_ANY_DIRECTION)
          MovDir[x][y] = element_info[element].move_pattern;
-       else if (element_info[element].move_pattern == MV_ALONG_LEFT_SIDE ||
-                element_info[element].move_pattern == MV_ALONG_RIGHT_SIDE)
+       else if (move_pattern == MV_ALONG_LEFT_SIDE ||
+                move_pattern == MV_ALONG_RIGHT_SIDE)
        {
-         for (i=0; i<4; i++)
+         for (i = 0; i < 4; i++)
          {
            int x1 = x + xy[i][0];
            int y1 = y + xy[i][1];
 
            if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
            {
-             if (element_info[element].move_pattern == MV_ALONG_RIGHT_SIDE)
+             if (move_pattern == MV_ALONG_RIGHT_SIDE)
                MovDir[x][y] = direction[0][i];
              else
                MovDir[x][y] = direction[1][i];
@@ -1582,7 +1848,7 @@ void InitMovDir(int x, int y)
            element != EL_BD_FIREFLY)
          break;
 
-       for (i=0; i<4; i++)
+       for (i = 0; i < 4; i++)
        {
          int x1 = x + xy[i][0];
          int y1 = y + xy[i][1];
@@ -1616,7 +1882,7 @@ void InitAmoebaNr(int x, int y)
 
   if (group_nr == 0)
   {
-    for (i=1; i<MAX_NUM_AMOEBA; i++)
+    for (i = 1; i < MAX_NUM_AMOEBA; i++)
     {
       if (AmoebaCnt[i] == 0)
       {
@@ -1713,7 +1979,7 @@ void GameWon()
     Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
                          EL_SP_EXIT_CLOSING);
 
-    PlaySoundLevelElementAction(ExitX, ExitY, element, ACTION_CLOSING);
+    PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
   }
 
   /* Hero disappears */
@@ -1777,7 +2043,7 @@ int NewHiScore()
       local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score) 
     return -1;
 
-  for (k=0; k<MAX_SCORE_ENTRIES; k++) 
+  for (k = 0; k < MAX_SCORE_ENTRIES; k++) 
   {
     if (local_player->score > highscore[k].Score)
     {
@@ -1788,14 +2054,14 @@ int NewHiScore()
        int m = MAX_SCORE_ENTRIES - 1;
 
 #ifdef ONE_PER_NAME
-       for (l=k; l<MAX_SCORE_ENTRIES; l++)
+       for (l = k; l < MAX_SCORE_ENTRIES; l++)
          if (!strcmp(setup.player_name, highscore[l].Name))
            m = l;
        if (m == k)     /* player's new highscore overwrites his old one */
          goto put_into_list;
 #endif
 
-       for (l=m; l>k; l--)
+       for (l = m; l > k; l--)
        {
          strcpy(highscore[l].Name, highscore[l - 1].Name);
          highscore[l].Score = highscore[l - 1].Score;
@@ -2050,14 +2316,14 @@ void CheckDynamite(int x, int y)
     if (MovDelay[x][y] != 0)
     {
       DrawDynamite(x, y);
-      PlaySoundLevelActionIfLoop(x, y, ACTION_ACTIVE);
+      PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
 
       return;
     }
   }
 
 #if 1
-  StopSoundLevelActionIfLoop(x, y, ACTION_ACTIVE);
+  StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
 #else
   if (Feld[x][y] == EL_DYNAMITE_ACTIVE ||
       Feld[x][y] == EL_SP_DISK_RED_ACTIVE)
@@ -2072,6 +2338,13 @@ void CheckDynamite(int x, int y)
 void RelocatePlayer(int x, int y, int element)
 {
   struct PlayerInfo *player = &stored_player[element - EL_PLAYER_1];
+  boolean ffwd_delay = (tape.playing && tape.fast_forward);
+  boolean no_delay = (tape.index_search);
+  int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
+  int wait_delay_value = (no_delay ? 0 : frame_delay_value);
+
+  if (player->GameOver)                /* do not reanimate dead player */
+    return;
 
 #if 1
   RemoveField(x, y);           /* temporarily remove newly placed player */
@@ -2089,7 +2362,7 @@ void RelocatePlayer(int x, int y, int element)
       DrawPlayer(player);
 
       BackToFront();
-      Delay(GAME_FRAME_DELAY);
+      Delay(wait_delay_value);
     }
 
     DrawPlayer(player);                /* needed here only to cleanup last field */
@@ -2133,11 +2406,11 @@ void RelocatePlayer(int x, int y, int element)
       /* scroll in two steps of half tile size to make things smoother */
       BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
       FlushDisplay();
-      Delay(GAME_FRAME_DELAY);
+      Delay(wait_delay_value);
 
       /* scroll second step to align at full tile size */
       BackToFront();
-      Delay(GAME_FRAME_DELAY);
+      Delay(wait_delay_value);
     }
   }
 }
@@ -2170,7 +2443,7 @@ void Explode(int ex, int ey, int phase, int mode)
 #endif
 
     if (mode == EX_NORMAL || mode == EX_CENTER)
-      PlaySoundLevelAction(ex, ey, ACTION_EXPLODING);
+      PlayLevelSoundAction(ex, ey, ACTION_EXPLODING);
 
     /* remove things displayed in background while burning dynamite */
     if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
@@ -2184,7 +2457,7 @@ void Explode(int ex, int ey, int phase, int mode)
       Feld[ex][ey] = center_element;
     }
 
-    for (y = ey - 1; y <= ey + 1; y++) for(x = ex - 1; x <= ex + 1; x++)
+    for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
     {
       int xx = x - ex + 1;
       int yy = y - ey + 1;
@@ -2268,17 +2541,17 @@ void Explode(int ex, int ey, int phase, int mode)
        switch(StorePlayer[ex][ey])
        {
          case EL_PLAYER_2:
-           Store[x][y] = EL_EMERALD_RED;
+           Store[x][y] = EL_PLAYER_IS_EXPLODING_2;
            break;
          case EL_PLAYER_3:
-           Store[x][y] = EL_EMERALD;
+           Store[x][y] = EL_PLAYER_IS_EXPLODING_3;
            break;
          case EL_PLAYER_4:
-           Store[x][y] = EL_EMERALD_PURPLE;
+           Store[x][y] = EL_PLAYER_IS_EXPLODING_4;
            break;
          case EL_PLAYER_1:
          default:
-           Store[x][y] = EL_EMERALD_YELLOW;
+           Store[x][y] = EL_PLAYER_IS_EXPLODING_1;
            break;
        }
 
@@ -2425,6 +2698,17 @@ void Explode(int ex, int ey, int phase, int mode)
     Store[x][y] = Store2[x][y] = 0;
     GfxElement[x][y] = EL_UNDEFINED;
 
+    /* player can escape from explosions and might therefore be still alive */
+    if (element >= EL_PLAYER_IS_EXPLODING_1 &&
+       element <= EL_PLAYER_IS_EXPLODING_4)
+      Feld[x][y] = (stored_player[element - EL_PLAYER_IS_EXPLODING_1].active ?
+                   EL_EMPTY :
+                   element == EL_PLAYER_IS_EXPLODING_1 ? EL_EMERALD_YELLOW :
+                   element == EL_PLAYER_IS_EXPLODING_2 ? EL_EMERALD_RED :
+                   element == EL_PLAYER_IS_EXPLODING_3 ? EL_EMERALD :
+                   EL_EMERALD_PURPLE);
+
+    /* restore probably existing indestructible background element */
     if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
       element = Feld[x][y] = Back[x][y];
     Back[x][y] = 0;
@@ -2435,8 +2719,11 @@ void Explode(int ex, int ey, int phase, int mode)
     ChangePage[x][y] = -1;
 
     InitField(x, y, FALSE);
+#if 1
+    /* !!! not needed !!! */
     if (CAN_MOVE(element))
       InitMovDir(x, y);
+#endif
     DrawLevelField(x, y);
 
     TestIfElementTouchesCustomElement(x, y);
@@ -2462,6 +2749,12 @@ void Explode(int ex, int ey, int phase, int mode)
 #endif
     int frame = getGraphicAnimationFrame(graphic, phase - delay);
 
+#if 0
+    printf("::: %d ['%s'] -> %d\n", GfxElement[x][y],
+          element_info[GfxElement[x][y]].token_name,
+          graphic);
+#endif
+
     if (phase == delay)
       DrawLevelFieldCrumbledSand(x, y);
 
@@ -2483,6 +2776,7 @@ void Explode(int ex, int ey, int phase, int mode)
 void DynaExplode(int ex, int ey)
 {
   int i, j;
+  int dynabomb_element = Feld[ex][ey];
   int dynabomb_size = 1;
   boolean dynabomb_xl = FALSE;
   struct PlayerInfo *player;
@@ -2494,9 +2788,9 @@ void DynaExplode(int ex, int ey)
     { 0, +1 }
   };
 
-  if (IS_ACTIVE_BOMB(Feld[ex][ey]))
+  if (IS_ACTIVE_BOMB(dynabomb_element))
   {
-    player = &stored_player[Feld[ex][ey] - EL_DYNABOMB_PLAYER_1_ACTIVE];
+    player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
     dynabomb_size = player->dynabomb_size;
     dynabomb_xl = player->dynabomb_xl;
     player->dynabombs_left++;
@@ -2504,9 +2798,9 @@ void DynaExplode(int ex, int ey)
 
   Explode(ex, ey, EX_PHASE_START, EX_CENTER);
 
-  for (i=0; i<4; i++)
+  for (i = 0; i < 4; i++)
   {
-    for (j=1; j<=dynabomb_size; j++)
+    for (j = 1; j <= dynabomb_size; j++)
     {
       int x = ex + j * xy[i % 4][0];
       int y = ey + j * xy[i % 4][1];
@@ -2555,12 +2849,12 @@ void Bang(int x, int y)
 
 #if 0
 #if 1
-  PlaySoundLevelAction(x, y, ACTION_EXPLODING);
+  PlayLevelSoundAction(x, y, ACTION_EXPLODING);
 #else
   if (game.emulation == EMU_SUPAPLEX)
-    PlaySoundLevel(x, y, SND_SP_ELEMENT_EXPLODING);
+    PlayLevelSound(x, y, SND_SP_ELEMENT_EXPLODING);
   else
-    PlaySoundLevel(x, y, SND_ELEMENT_EXPLODING);
+    PlayLevelSound(x, y, SND_ELEMENT_EXPLODING);
 #endif
 #endif
 
@@ -2601,7 +2895,9 @@ void Bang(int x, int y)
        Explode(x, y, EX_PHASE_START, EX_CENTER);
       break;
     default:
-      if (CAN_EXPLODE_1X1(element))
+      if (CAN_EXPLODE_DYNA(element))
+       DynaExplode(x, y);
+      else if (CAN_EXPLODE_1X1(element))
        Explode(x, y, EX_PHASE_START, EX_CENTER);
       else
        Explode(x, y, EX_PHASE_START, EX_NORMAL);
@@ -2618,7 +2914,7 @@ void SplashAcid(int x, int y)
   if (element != EL_ACID_SPLASH_LEFT &&
       element != EL_ACID_SPLASH_RIGHT)
   {
-    PlaySoundLevel(x, y, SND_ACID_SPLASHING);
+    PlayLevelSound(x, y, SND_ACID_SPLASHING);
 
     if (IN_LEV_FIELD(x-1, y) && IS_FREE(x-1, y) &&
        (!IN_LEV_FIELD(x-1, y-1) ||
@@ -2652,11 +2948,11 @@ static void InitBeltMovement()
   int x, y, i, j;
 
   /* set frame order for belt animation graphic according to belt direction */
-  for (i=0; i<4; i++)
+  for (i = 0; i < 4; i++)
   {
     int belt_nr = i;
 
-    for (j=0; j<3; j++)
+    for (j = 0; j < 3; j++)
     {
       int element = belt_base_active_element[belt_nr] + j;
       int graphic = el2img(element);
@@ -2668,13 +2964,13 @@ static void InitBeltMovement()
     }
   }
 
-  for(y=0; y<lev_fieldy; y++)
+  for (y = 0; y < lev_fieldy; y++)
   {
-    for(x=0; x<lev_fieldx; x++)
+    for (x = 0; x < lev_fieldx; x++)
     {
       int element = Feld[x][y];
 
-      for (i=0; i<4; i++)
+      for (i = 0; i < 4; i++)
       {
        if (IS_BELT(element) && game.belt_dir[i] != MV_NO_MOVING)
        {
@@ -2740,7 +3036,7 @@ static void ToggleBeltSwitch(int x, int y)
     belt_dir_nr = 1;
 
   /* set frame order for belt animation graphic according to belt direction */
-  for (i=0; i<3; i++)
+  for (i = 0; i < 3; i++)
   {
     int element = belt_base_active_element[belt_nr] + i;
     int graphic = el2img(element);
@@ -2751,9 +3047,9 @@ static void ToggleBeltSwitch(int x, int y)
       graphic_info[graphic].anim_mode |=  ANIM_REVERSE;
   }
 
-  for (yy=0; yy<lev_fieldy; yy++)
+  for (yy = 0; yy < lev_fieldy; yy++)
   {
-    for (xx=0; xx<lev_fieldx; xx++)
+    for (xx = 0; xx < lev_fieldx; xx++)
     {
       int element = Feld[xx][yy];
 
@@ -2801,9 +3097,9 @@ static void ToggleSwitchgateSwitch(int x, int y)
 
   game.switchgate_pos = !game.switchgate_pos;
 
-  for (yy=0; yy<lev_fieldy; yy++)
+  for (yy = 0; yy < lev_fieldy; yy++)
   {
-    for (xx=0; xx<lev_fieldx; xx++)
+    for (xx = 0; xx < lev_fieldx; xx++)
     {
       int element = Feld[xx][yy];
 
@@ -2818,9 +3114,9 @@ static void ToggleSwitchgateSwitch(int x, int y)
       {
        Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
 #if 1
-       PlaySoundLevelAction(xx, yy, ACTION_CLOSING);
+       PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
 #else
-       PlaySoundLevel(xx, yy, SND_SWITCHGATE_CLOSING);
+       PlayLevelSound(xx, yy, SND_SWITCHGATE_CLOSING);
 #endif
       }
       else if (element == EL_SWITCHGATE_CLOSED ||
@@ -2828,9 +3124,9 @@ static void ToggleSwitchgateSwitch(int x, int y)
       {
        Feld[xx][yy] = EL_SWITCHGATE_OPENING;
 #if 1
-       PlaySoundLevelAction(xx, yy, ACTION_OPENING);
+       PlayLevelSoundAction(xx, yy, ACTION_OPENING);
 #else
-       PlaySoundLevel(xx, yy, SND_SWITCHGATE_OPENING);
+       PlayLevelSound(xx, yy, SND_SWITCHGATE_OPENING);
 #endif
       }
     }
@@ -2857,9 +3153,9 @@ static void RedrawAllLightSwitchesAndInvisibleElements()
 {
   int x, y;
 
-  for (y=0; y<lev_fieldy; y++)
+  for (y = 0; y < lev_fieldy; y++)
   {
-    for (x=0; x<lev_fieldx; x++)
+    for (x = 0; x < lev_fieldx; x++)
     {
       int element = Feld[x][y];
 
@@ -2914,9 +3210,9 @@ static void ActivateTimegateSwitch(int x, int y)
 
   game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
 
-  for (yy=0; yy<lev_fieldy; yy++)
+  for (yy = 0; yy < lev_fieldy; yy++)
   {
-    for (xx=0; xx<lev_fieldx; xx++)
+    for (xx = 0; xx < lev_fieldx; xx++)
     {
       int element = Feld[xx][yy];
 
@@ -2924,7 +3220,7 @@ static void ActivateTimegateSwitch(int x, int y)
          element == EL_TIMEGATE_CLOSING)
       {
        Feld[xx][yy] = EL_TIMEGATE_OPENING;
-       PlaySoundLevel(xx, yy, SND_TIMEGATE_OPENING);
+       PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
       }
 
       /*
@@ -2981,6 +3277,10 @@ void Impact(int x, int y)
                                         MovDir[x][y + 1] != MV_DOWN ||
                                         MovPos[x][y + 1] <= TILEY / 2));
 
+#if 0
+    object_hit = !IS_FREE(x, y + 1);
+#endif
+
     /* do not smash moving elements that left the smashed field in time */
     if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
        ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
@@ -3014,12 +3314,12 @@ void Impact(int x, int y)
   else if (impact && element == EL_PEARL)
   {
     Feld[x][y] = EL_PEARL_BREAKING;
-    PlaySoundLevel(x, y, SND_PEARL_BREAKING);
+    PlayLevelSound(x, y, SND_PEARL_BREAKING);
     return;
   }
   else if (impact && CheckElementChange(x, y, element, CE_IMPACT))
   {
-    PlaySoundLevelElementAction(x, y, element, ACTION_IMPACT);
+    PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
 
     return;
   }
@@ -3052,15 +3352,15 @@ void Impact(int x, int y)
         EL_BD_MAGIC_WALL_ACTIVE);
 
       /* activate magic wall / mill */
-      for (yy=0; yy<lev_fieldy; yy++)
-       for (xx=0; xx<lev_fieldx; xx++)
+      for (yy = 0; yy < lev_fieldy; yy++)
+       for (xx = 0; xx < lev_fieldx; xx++)
          if (Feld[xx][yy] == smashed)
            Feld[xx][yy] = activated_magic_wall;
 
       game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
       game.magic_wall_active = TRUE;
 
-      PlaySoundLevel(x, y, (smashed == EL_MAGIC_WALL ?
+      PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
                            SND_MAGIC_WALL_ACTIVATING :
                            SND_BD_MAGIC_WALL_ACTIVATING));
     }
@@ -3089,11 +3389,13 @@ void Impact(int x, int y)
        return;
       }
     }
-    else if ((element == EL_SP_INFOTRON ||
-             element == EL_SP_ZONK) &&
-            (smashed == EL_SP_SNIKSNAK ||
-             smashed == EL_SP_ELECTRON ||
-             smashed == EL_SP_DISK_ORANGE))
+    else if (((element == EL_SP_INFOTRON ||
+              element == EL_SP_ZONK) &&
+             (smashed == EL_SP_SNIKSNAK ||
+              smashed == EL_SP_ELECTRON ||
+              smashed == EL_SP_DISK_ORANGE)) ||
+            (element == EL_SP_INFOTRON &&
+             smashed == EL_SP_DISK_YELLOW))
     {
       Bang(x, y + 1);
       return;
@@ -3124,20 +3426,20 @@ void Impact(int x, int y)
        else if (smashed == EL_NUT)
        {
          Feld[x][y + 1] = EL_NUT_BREAKING;
-         PlaySoundLevel(x, y, SND_NUT_BREAKING);
+         PlayLevelSound(x, y, SND_NUT_BREAKING);
          RaiseScoreElement(EL_NUT);
          return;
        }
        else if (smashed == EL_PEARL)
        {
          Feld[x][y + 1] = EL_PEARL_BREAKING;
-         PlaySoundLevel(x, y, SND_PEARL_BREAKING);
+         PlayLevelSound(x, y, SND_PEARL_BREAKING);
          return;
        }
        else if (smashed == EL_DIAMOND)
        {
          Feld[x][y + 1] = EL_DIAMOND_BREAKING;
-         PlaySoundLevel(x, y, SND_DIAMOND_BREAKING);
+         PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
          return;
        }
        else if (IS_BELT_SWITCH(smashed))
@@ -3177,16 +3479,16 @@ void Impact(int x, int y)
        Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
   {
     if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
-      PlaySoundLevel(x, y, SND_MAGIC_WALL_FILLING);
+      PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
     else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
-      PlaySoundLevel(x, y, SND_BD_MAGIC_WALL_FILLING);
+      PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
 
     return;
   }
 
   /* play sound of object that hits the ground */
   if (lastline || object_hit)
-    PlaySoundLevelElementAction(x, y, element, ACTION_IMPACT);
+    PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
 }
 
 inline static void TurnRoundExt(int x, int y)
@@ -3221,6 +3523,8 @@ inline static void TurnRoundExt(int x, int y)
   };
 
   int element = Feld[x][y];
+  int move_pattern = element_info[element].move_pattern;
+
   int old_move_dir = MovDir[x][y];
   int left_dir  = turn[old_move_dir].left;
   int right_dir = turn[old_move_dir].right;
@@ -3388,6 +3692,11 @@ inline static void TurnRoundExt(int x, int y)
     int rnd_value = 24;
     int rnd = RND(rnd_value);
 
+#if 0
+    if (FrameCounter < 1 && x == 0 && y == 29)
+      printf(":2: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
+#endif
+
     if (can_move_on && rnd > rnd_value / 8)
       MovDir[x][y] = old_move_dir;
     else if (can_turn_left && can_turn_right)
@@ -3402,8 +3711,25 @@ inline static void TurnRoundExt(int x, int y)
     xx = x + move_xy[MovDir[x][y]].x;
     yy = y + move_xy[MovDir[x][y]].y;
 
+#if 0
+    if (FrameCounter < 1 && x == 0 && y == 29)
+      printf(":3: %d/%d: %d (%d/%d: %d) [%d]\n", x, y, MovDir[x][y],
+            xx, yy, Feld[xx][yy],
+            FrameCounter);
+#endif
+
+#if 1
+    if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
+      MovDir[x][y] = old_move_dir;
+#else
     if (!IS_FREE(xx, yy))
       MovDir[x][y] = old_move_dir;
+#endif
+
+#if 0
+    if (FrameCounter < 1 && x == 0 && y == 29)
+      printf(":4: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
+#endif
 
     MovDelay[x][y] = 0;
   }
@@ -3463,7 +3789,7 @@ inline static void TurnRoundExt(int x, int y)
     {
       int i;
 
-      for (i=0; i<MAX_PLAYERS; i++)
+      for (i = 0; i < MAX_PLAYERS; i++)
       {
        struct PlayerInfo *player = &stored_player[i];
        int jx = player->jx, jy = player->jy;
@@ -3497,7 +3823,7 @@ inline static void TurnRoundExt(int x, int y)
        { 0, +1 }
       };
 
-      for (i=0; i<4; i++)
+      for (i = 0; i < 4; i++)
       {
        int ex = x + xy[i % 4][0];
        int ey = y + xy[i % 4][1];
@@ -3593,17 +3919,30 @@ inline static void TurnRoundExt(int x, int y)
       }
     }
   }
-  else if (element_info[element].move_pattern == MV_ALL_DIRECTIONS ||
-          element_info[element].move_pattern == MV_TURNING_LEFT ||
-          element_info[element].move_pattern == MV_TURNING_RIGHT)
+  else if (move_pattern == MV_TURNING_LEFT ||
+          move_pattern == MV_TURNING_RIGHT ||
+          move_pattern == MV_TURNING_LEFT_RIGHT ||
+          move_pattern == MV_TURNING_RIGHT_LEFT ||
+          move_pattern == MV_TURNING_RANDOM ||
+          move_pattern == MV_ALL_DIRECTIONS)
   {
-    boolean can_turn_left  = ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
-    boolean can_turn_right = ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
+    boolean can_turn_left =
+      CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
+    boolean can_turn_right =
+      CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
 
-    if (element_info[element].move_pattern == MV_TURNING_LEFT)
+    if (move_pattern == MV_TURNING_LEFT)
       MovDir[x][y] = left_dir;
-    else if (element_info[element].move_pattern == MV_TURNING_RIGHT)
+    else if (move_pattern == MV_TURNING_RIGHT)
       MovDir[x][y] = right_dir;
+    else if (move_pattern == MV_TURNING_LEFT_RIGHT)
+      MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
+    else if (move_pattern == MV_TURNING_RIGHT_LEFT)
+      MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
+    else if (move_pattern == MV_TURNING_RANDOM)
+      MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
+                     can_turn_right && !can_turn_left ? right_dir :
+                     RND(2) ? left_dir : right_dir);
     else if (can_turn_left && can_turn_right)
       MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
     else if (can_turn_left)
@@ -3615,50 +3954,49 @@ inline static void TurnRoundExt(int x, int y)
 
     MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
   }
-  else if (element_info[element].move_pattern == MV_HORIZONTAL ||
-          element_info[element].move_pattern == MV_VERTICAL)
+  else if (move_pattern == MV_HORIZONTAL ||
+          move_pattern == MV_VERTICAL)
   {
-    if (element_info[element].move_pattern & old_move_dir)
+    if (move_pattern & old_move_dir)
       MovDir[x][y] = back_dir;
-    else if (element_info[element].move_pattern == MV_HORIZONTAL)
+    else if (move_pattern == MV_HORIZONTAL)
       MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
-    else if (element_info[element].move_pattern == MV_VERTICAL)
+    else if (move_pattern == MV_VERTICAL)
       MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
 
     MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
   }
-  else if (element_info[element].move_pattern & MV_ANY_DIRECTION)
+  else if (move_pattern & MV_ANY_DIRECTION)
   {
-    MovDir[x][y] = element_info[element].move_pattern;
+    MovDir[x][y] = move_pattern;
     MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
   }
-  else if (element_info[element].move_pattern == MV_ALONG_LEFT_SIDE)
+  else if (move_pattern == MV_ALONG_LEFT_SIDE)
   {
-    if (ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
+    if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
       MovDir[x][y] = left_dir;
-    else if (!ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
+    else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
       MovDir[x][y] = right_dir;
 
     if (MovDir[x][y] != old_move_dir)
       MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
   }
-  else if (element_info[element].move_pattern == MV_ALONG_RIGHT_SIDE)
+  else if (move_pattern == MV_ALONG_RIGHT_SIDE)
   {
-    if (ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
+    if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
       MovDir[x][y] = right_dir;
-    else if (!ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
+    else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
       MovDir[x][y] = left_dir;
 
     if (MovDir[x][y] != old_move_dir)
       MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
   }
-  else if (element_info[element].move_pattern == MV_TOWARDS_PLAYER ||
-          element_info[element].move_pattern == MV_AWAY_FROM_PLAYER)
+  else if (move_pattern == MV_TOWARDS_PLAYER ||
+          move_pattern == MV_AWAY_FROM_PLAYER)
   {
     int attr_x = -1, attr_y = -1;
     int newx, newy;
-    boolean move_away =
-      (element_info[element].move_pattern == MV_AWAY_FROM_PLAYER);
+    boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
 
     if (AllPlayersGone)
     {
@@ -3669,7 +4007,7 @@ inline static void TurnRoundExt(int x, int y)
     {
       int i;
 
-      for (i=0; i<MAX_PLAYERS; i++)
+      for (i = 0; i < MAX_PLAYERS; i++)
       {
        struct PlayerInfo *player = &stored_player[i];
        int jx = player->jx, jy = player->jy;
@@ -3707,26 +4045,97 @@ inline static void TurnRoundExt(int x, int y)
        new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
       Moving2Blocked(x, y, &newx, &newy);
 
-      if (ELEMENT_CAN_ENTER_FIELD_OR_ACID(element, newx, newy))
+      if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
        return;
 
       MovDir[x][y] =
        new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
       Moving2Blocked(x, y, &newx, &newy);
 
-      if (ELEMENT_CAN_ENTER_FIELD_OR_ACID(element, newx, newy))
+      if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
        return;
 
       MovDir[x][y] = old_move_dir;
     }
   }
-  else if (element_info[element].move_pattern == MV_WHEN_PUSHED)
+  else if (move_pattern == MV_WHEN_PUSHED ||
+          move_pattern == MV_WHEN_DROPPED)
   {
     if (!IN_LEV_FIELD_AND_IS_FREE(move_x, move_y))
       MovDir[x][y] = MV_NO_MOVING;
 
     MovDelay[x][y] = 0;
   }
+  else if (move_pattern & MV_MAZE_RUNNER_STYLE)
+  {
+    static int test_xy[7][2] =
+    {
+      { 0, -1 },
+      { -1, 0 },
+      { +1, 0 },
+      { 0, +1 },
+      { 0, -1 },
+      { -1, 0 },
+      { +1, 0 },
+    };
+    static int test_dir[7] =
+    {
+      MV_UP,
+      MV_LEFT,
+      MV_RIGHT,
+      MV_DOWN,
+      MV_UP,
+      MV_LEFT,
+      MV_RIGHT,
+    };
+    boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
+    int move_preference = -1000000;    /* start with very low preference */
+    int new_move_dir = MV_NO_MOVING;
+    int start_test = RND(4);
+    int i;
+
+    for (i = 0; i < 4; i++)
+    {
+      int move_dir = test_dir[start_test + i];
+      int move_dir_preference;
+
+      xx = x + test_xy[start_test + i][0];
+      yy = y + test_xy[start_test + i][1];
+
+      if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
+         (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
+      {
+       new_move_dir = move_dir;
+
+       break;
+      }
+
+      if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
+       continue;
+
+      move_dir_preference = -1 * RunnerVisit[xx][yy];
+      if (hunter_mode && PlayerVisit[xx][yy] > 0)
+       move_dir_preference = PlayerVisit[xx][yy];
+
+      if (move_dir_preference > move_preference)
+      {
+       /* prefer field that has not been visited for the longest time */
+       move_preference = move_dir_preference;
+       new_move_dir = move_dir;
+      }
+      else if (move_dir_preference == move_preference &&
+              move_dir == old_move_dir)
+      {
+       /* prefer last direction when all directions are preferred equally */
+       move_preference = move_dir_preference;
+       new_move_dir = move_dir;
+      }
+    }
+
+    MovDir[x][y] = new_move_dir;
+    if (old_move_dir != new_move_dir)
+      MovDelay[x][y] = 9;
+  }
 }
 
 static void TurnRound(int x, int y)
@@ -3759,7 +4168,7 @@ static boolean JustBeingPushed(int x, int y)
 {
   int i;
 
-  for (i=0; i<MAX_PLAYERS; i++)
+  for (i = 0; i < MAX_PLAYERS; i++)
   {
     struct PlayerInfo *player = &stored_player[i];
 
@@ -3811,9 +4220,9 @@ void StartMoving(int x, int y)
        Feld[x][y] = EL_QUICKSAND_EMPTYING;
        Store[x][y] = EL_ROCK;
 #if 1
-       PlaySoundLevelAction(x, y, ACTION_EMPTYING);
+       PlayLevelSoundAction(x, y, ACTION_EMPTYING);
 #else
-       PlaySoundLevel(x, y, SND_QUICKSAND_EMPTYING);
+       PlayLevelSound(x, y, SND_QUICKSAND_EMPTYING);
 #endif
       }
       else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
@@ -3833,9 +4242,9 @@ void StartMoving(int x, int y)
        Store[x][y + 1] = Store[x][y];
        Store[x][y] = 0;
 #if 1
-       PlaySoundLevelAction(x, y, ACTION_FILLING);
+       PlayLevelSoundAction(x, y, ACTION_FILLING);
 #else
-       PlaySoundLevel(x, y, SND_QUICKSAND_FILLING);
+       PlayLevelSound(x, y, SND_QUICKSAND_FILLING);
 #endif
       }
     }
@@ -3848,9 +4257,9 @@ void StartMoving(int x, int y)
       Feld[x][y] = EL_QUICKSAND_FILLING;
       Store[x][y] = element;
 #if 1
-      PlaySoundLevelAction(x, y, ACTION_FILLING);
+      PlayLevelSoundAction(x, y, ACTION_FILLING);
 #else
-      PlaySoundLevel(x, y, SND_QUICKSAND_FILLING);
+      PlayLevelSound(x, y, SND_QUICKSAND_FILLING);
 #endif
     }
     else if (element == EL_MAGIC_WALL_FULL)
@@ -3968,6 +4377,11 @@ void StartMoving(int x, int y)
         element; also, the case of the player being the element to smash was
         simply not covered here... :-/ ) */
 
+#if 0
+      WasJustMoving[x][y] = 0;
+      WasJustFalling[x][y] = 0;
+#endif
+
       Impact(x, y);
     }
     else if (IS_FREE(x, y + 1) && element == EL_SPRING && use_spring_bug)
@@ -4067,8 +4481,11 @@ void StartMoving(int x, int y)
   /* not "else if" because of elements that can fall and move (EL_SPRING) */
   if (CAN_MOVE(element) && !started_moving)
   {
+    int move_pattern = element_info[element].move_pattern;
     int newx, newy;
 
+    Moving2Blocked(x, y, &newx, &newy);
+
 #if 1
     if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
       return;
@@ -4080,6 +4497,43 @@ void StartMoving(int x, int y)
       return;
 #endif
 
+#if 1
+    if (game.engine_version >= VERSION_IDENT(3,0,9,0) &&
+       WasJustMoving[x][y] && IN_LEV_FIELD(newx, newy) &&
+       (Feld[newx][newy] == EL_BLOCKED || IS_PLAYER(newx, newy)))
+    {
+#if 0
+      printf("::: element %d '%s' WasJustMoving %d [%d, %d, %d, %d]\n",
+            element, element_info[element].token_name,
+            WasJustMoving[x][y],
+            HAS_ANY_CHANGE_EVENT(element, CE_HITTING_SOMETHING),
+            HAS_ANY_CHANGE_EVENT(element, CE_HIT_BY_SOMETHING),
+            HAS_ANY_CHANGE_EVENT(element, CE_OTHER_IS_HITTING),
+            HAS_ANY_CHANGE_EVENT(element, CE_OTHER_GETS_HIT));
+#endif
+
+#if 1
+      WasJustMoving[x][y] = 0;
+#endif
+
+      TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
+
+#if 0
+      if (Feld[x][y] != element)       /* element has changed */
+      {
+       element = Feld[x][y];
+       move_pattern = element_info[element].move_pattern;
+
+       if (!CAN_MOVE(element))
+         return;
+      }
+#else
+      if (Feld[x][y] != element)       /* element has changed */
+       return;
+#endif
+    }
+#endif
+
 #if 0
 #if 0
     if (element == EL_SPRING && MovDir[x][y] == MV_DOWN)
@@ -4094,6 +4548,11 @@ void StartMoving(int x, int y)
 #endif
 #endif
 
+#if 0
+    if (FrameCounter < 1 && x == 0 && y == 29)
+      printf(":1: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
+#endif
+
     if (!MovDelay[x][y])       /* start new movement phase */
     {
       /* all objects that can change their move direction after each step
@@ -4102,12 +4561,20 @@ void StartMoving(int x, int y)
       if (element != EL_YAMYAM &&
          element != EL_DARK_YAMYAM &&
          element != EL_PACMAN &&
-         !(element_info[element].move_pattern & MV_ANY_DIRECTION) &&
-         element_info[element].move_pattern != MV_TURNING_LEFT &&
-         element_info[element].move_pattern != MV_TURNING_RIGHT)
+         !(move_pattern & MV_ANY_DIRECTION) &&
+         move_pattern != MV_TURNING_LEFT &&
+         move_pattern != MV_TURNING_RIGHT &&
+         move_pattern != MV_TURNING_LEFT_RIGHT &&
+         move_pattern != MV_TURNING_RIGHT_LEFT &&
+         move_pattern != MV_TURNING_RANDOM)
       {
        TurnRound(x, y);
 
+#if 0
+       if (FrameCounter < 1 && x == 0 && y == 29)
+         printf(":9: %d: %d [%d]\n", y, MovDir[x][y], FrameCounter);
+#endif
+
        if (MovDelay[x][y] && (element == EL_BUG ||
                               element == EL_SPACESHIP ||
                               element == EL_SP_SNIKSNAK ||
@@ -4157,7 +4624,7 @@ void StartMoving(int x, int y)
 #else
        DrawLevelElementAnimationIfNeeded(x, y, element);
 #endif
-       PlaySoundLevelAction(x, y, ACTION_WAITING);
+       PlayLevelSoundAction(x, y, ACTION_WAITING);
       }
       else if (element == EL_SP_ELECTRON)
        DrawLevelElementAnimationIfNeeded(x, y, element);
@@ -4184,9 +4651,9 @@ void StartMoving(int x, int y)
        else
          DrawLevelField(x, y);
 
-       PlaySoundLevelActionIfLoop(x, y, ACTION_ATTACKING);
+       PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
 
-       for (i=1; i <= 3; i++)
+       for (i = 1; i <= 3; i++)
        {
          int xx = x + i * dx;
          int yy = y + i * dy;
@@ -4224,7 +4691,7 @@ void StartMoving(int x, int y)
 
       if (MovDelay[x][y])      /* element still has to wait some time */
       {
-       PlaySoundLevelAction(x, y, ACTION_WAITING);
+       PlayLevelSoundAction(x, y, ACTION_WAITING);
 
        return;
       }
@@ -4247,6 +4714,7 @@ void StartMoving(int x, int y)
     {
 #if 1
       TestIfBadThingRunsIntoHero(x, y, MovDir[x][y]);
+
       return;
 #else
       /* player killed by element which is deadly when colliding with */
@@ -4271,10 +4739,15 @@ void StartMoving(int x, int y)
     {
       if (Feld[newx][newy] == EL_EXIT_OPEN)
       {
+#if 1
+       RemoveField(x, y);
+       DrawLevelField(x, y);
+#else
        Feld[x][y] = EL_EMPTY;
        DrawLevelField(x, y);
+#endif
 
-       PlaySoundLevel(newx, newy, SND_PENGUIN_PASSING);
+       PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
        if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
          DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
 
@@ -4300,6 +4773,7 @@ void StartMoving(int x, int y)
          DrawPlayerField(x, y);
        else
          DrawLevelField(x, y);
+
        return;
       }
     }
@@ -4315,7 +4789,7 @@ void StartMoving(int x, int y)
          DrawLevelField(newx, newy);
        }
 
-       PlaySoundLevel(x, y, SND_PIG_DIGGING);
+       PlayLevelSound(x, y, SND_PIG_DIGGING);
       }
       else if (!IS_FREE(newx, newy))
       {
@@ -4323,19 +4797,90 @@ void StartMoving(int x, int y)
          DrawPlayerField(x, y);
        else
          DrawLevelField(x, y);
+
        return;
       }
     }
-    else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
+
+#if 1
+
+    /*
+    else if (move_pattern & MV_MAZE_RUNNER_STYLE && IN_LEV_FIELD(newx, newy))
+    */
+
+    else if (IS_CUSTOM_ELEMENT(element) &&
+            CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy)
+
+#if 0
+ &&
+            !IS_FREE(newx, newy)
+#endif
+
+)
     {
+      int new_element = Feld[newx][newy];
+
+#if 0
+      printf("::: '%s' digs '%s' [%d]\n",
+            element_info[element].token_name,
+            element_info[Feld[newx][newy]].token_name,
+            StorePlayer[newx][newy]);
+#endif
+
       if (!IS_FREE(newx, newy))
       {
-       if (IS_PLAYER(x, y))
-         DrawPlayerField(x, y);
+       int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
+                     IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
+                     ACTION_BREAKING);
+
+       /* no element can dig solid indestructible elements */
+       if (IS_INDESTRUCTIBLE(new_element) &&
+           !IS_DIGGABLE(new_element) &&
+           !IS_COLLECTIBLE(new_element))
+         return;
+
+       if (AmoebaNr[newx][newy] &&
+           (new_element == EL_AMOEBA_FULL ||
+            new_element == EL_BD_AMOEBA ||
+            new_element == EL_AMOEBA_GROWING))
+       {
+         AmoebaCnt[AmoebaNr[newx][newy]]--;
+         AmoebaCnt2[AmoebaNr[newx][newy]]--;
+       }
+
+       if (IS_MOVING(newx, newy))
+         RemoveMovingField(newx, newy);
        else
-         DrawLevelField(x, y);
+       {
+         RemoveField(newx, newy);
+         DrawLevelField(newx, newy);
+       }
 
-       return;
+       PlayLevelSoundAction(x, y, action);
+      }
+
+      if (new_element == element_info[element].move_enter_element)
+       element_info[element].can_leave_element = TRUE;
+
+      if (move_pattern & MV_MAZE_RUNNER_STYLE)
+      {
+       RunnerVisit[x][y] = FrameCounter;
+       PlayerVisit[x][y] /= 8;         /* expire player visit path */
+      }
+    }
+
+#endif
+
+    else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
+    {
+      if (!IS_FREE(newx, newy))
+      {
+       if (IS_PLAYER(x, y))
+         DrawPlayerField(x, y);
+       else
+         DrawLevelField(x, y);
+
+       return;
       }
       else
       {
@@ -4364,7 +4909,7 @@ void StartMoving(int x, int y)
          else
            DrawLevelField(x, y);
 
-         PlaySoundLevel(x, y, SND_DRAGON_ATTACKING);
+         PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
 
          MovDelay[x][y] = 50;
 
@@ -4389,7 +4934,7 @@ void StartMoving(int x, int y)
        DrawLevelField(newx, newy);
       }
 
-      PlaySoundLevel(x, y, SND_YAMYAM_DIGGING);
+      PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
     }
     else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
             IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
@@ -4410,7 +4955,7 @@ void StartMoving(int x, int y)
        DrawLevelField(newx, newy);
       }
 
-      PlaySoundLevel(x, y, SND_DARK_YAMYAM_DIGGING);
+      PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
     }
     else if ((element == EL_PACMAN || element == EL_MOLE)
             && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
@@ -4426,20 +4971,21 @@ void StartMoving(int x, int y)
       if (element == EL_MOLE)
       {
        Feld[newx][newy] = EL_AMOEBA_SHRINKING;
-       PlaySoundLevel(x, y, SND_MOLE_DIGGING);
+       PlayLevelSound(x, y, SND_MOLE_DIGGING);
 
        ResetGfxAnimation(x, y);
        GfxAction[x][y] = ACTION_DIGGING;
        DrawLevelField(x, y);
 
        MovDelay[newx][newy] = 0;       /* start amoeba shrinking delay */
+
        return;                         /* wait for shrinking amoeba */
       }
       else     /* element == EL_PACMAN */
       {
        Feld[newx][newy] = EL_EMPTY;
        DrawLevelField(newx, newy);
-       PlaySoundLevel(x, y, SND_PACMAN_DIGGING);
+       PlayLevelSound(x, y, SND_PACMAN_DIGGING);
       }
     }
     else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
@@ -4478,7 +5024,7 @@ void StartMoving(int x, int y)
        TestIfBadThingTouchesHero(x, y);
 
 #if 0
-      PlaySoundLevelAction(x, y, ACTION_WAITING);
+      PlayLevelSoundAction(x, y, ACTION_WAITING);
 #endif
 
       return;
@@ -4486,7 +5032,7 @@ void StartMoving(int x, int y)
 
     InitMovingField(x, y, MovDir[x][y]);
 
-    PlaySoundLevelAction(x, y, ACTION_MOVING);
+    PlayLevelSoundAction(x, y, ACTION_MOVING);
   }
 
   if (MovDir[x][y])
@@ -4496,11 +5042,14 @@ void StartMoving(int x, int y)
 void ContinueMoving(int x, int y)
 {
   int element = Feld[x][y];
+  struct ElementInfo *ei = &element_info[element];
   int direction = MovDir[x][y];
   int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
   int dy = (direction == MV_UP   ? -1 : direction == MV_DOWN  ? +1 : 0);
   int newx = x + dx, newy = y + dy;
+#if 0
   int nextx = newx + dx, nexty = newy + dy;
+#endif
   boolean pushed = Pushed[x][y];
 
   MovPos[x][y] += getElementMoveStepsize(x, y);
@@ -4610,6 +5159,24 @@ void ContinueMoving(int x, int y)
 
   ResetGfxAnimation(x, y);     /* reset animation values for old field */
 
+#if 1
+  /* some elements can leave other elements behind after moving */
+  if (IS_CUSTOM_ELEMENT(element) && !IS_PLAYER(x, y) &&
+      ei->move_leave_element != EL_EMPTY &&
+      (ei->move_leave_type == LEAVE_TYPE_UNLIMITED ||
+       ei->can_leave_element_last))
+  {
+    Feld[x][y] = ei->move_leave_element;
+    InitField(x, y, FALSE);
+
+    if (GFX_CRUMBLED(Feld[x][y]))
+      DrawLevelFieldCrumbledSandNeighbours(x, y);
+  }
+
+  ei->can_leave_element_last = ei->can_leave_element;
+  ei->can_leave_element = FALSE;
+#endif
+
 #if 0
   /* 2.1.1 (does not work correctly for spring) */
   if (!CAN_MOVE(element))
@@ -4657,7 +5224,9 @@ void ContinueMoving(int x, int y)
   {
     TestIfBadThingTouchesHero(newx, newy);
     TestIfBadThingTouchesFriend(newx, newy);
-    TestIfBadThingTouchesOtherBadThing(newx, newy);
+
+    if (!IS_CUSTOM_ELEMENT(element))
+      TestIfBadThingTouchesOtherBadThing(newx, newy);
   }
   else if (element == EL_PENGUIN)
     TestIfFriendTouchesBadThing(newx, newy);
@@ -4667,7 +5236,7 @@ void ContinueMoving(int x, int y)
     Impact(x, newy);
 
 #if 1
-  TestIfElementTouchesCustomElement(x, y);             /* for empty space */
+  TestIfElementTouchesCustomElement(x, y);     /* empty or new element */
 #endif
 
 #if 0
@@ -4675,9 +5244,90 @@ void ContinueMoving(int x, int y)
     ChangeElement(newx, newy, ChangePage[newx][newy]);
 #endif
 
+#if 1
+
+  TestIfElementHitsCustomElement(newx, newy, direction);
+
+#else
+
   if (!IN_LEV_FIELD(nextx, nexty) || !IS_FREE(nextx, nexty))
-    CheckElementSideChange(newx, newy, Feld[newx][newy], direction,
-                          CE_COLLISION, -1);
+  {
+    int hitting_element = Feld[newx][newy];
+
+    /* !!! fix side (direction) orientation here and elsewhere !!! */
+    CheckElementSideChange(newx, newy, hitting_element,
+                          direction, CE_HITTING_SOMETHING, -1);
+
+#if 0
+    if (IN_LEV_FIELD(nextx, nexty))
+    {
+      static int opposite_directions[] =
+      {
+       MV_RIGHT,
+       MV_LEFT,
+       MV_DOWN,
+       MV_UP
+      };
+      int move_dir_bit = MV_DIR_BIT(direction);
+      int opposite_direction = opposite_directions[move_dir_bit];
+      int hitting_side = direction;
+      int touched_side = opposite_direction;
+      int touched_element = MovingOrBlocked2Element(nextx, nexty);
+      boolean object_hit = (!IS_MOVING(nextx, nexty) ||
+                           MovDir[nextx][nexty] != direction ||
+                           ABS(MovPos[nextx][nexty]) <= TILEY / 2);
+
+      if (object_hit)
+      {
+       int i;
+
+       CheckElementSideChange(nextx, nexty, touched_element,
+                              opposite_direction, CE_HIT_BY_SOMETHING, -1);
+
+       if (IS_CUSTOM_ELEMENT(hitting_element) &&
+           HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING))
+       {
+         for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
+         {
+           struct ElementChangeInfo *change =
+             &element_info[hitting_element].change_page[i];
+
+           if (change->can_change &&
+               change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) &&
+               change->sides & touched_side &&
+               change->trigger_element == touched_element)
+           {
+             CheckElementSideChange(newx, newy, hitting_element,
+                                    CH_SIDE_ANY, CE_OTHER_IS_HITTING, i);
+             break;
+           }
+         }
+       }
+
+       if (IS_CUSTOM_ELEMENT(touched_element) &&
+           HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_HIT))
+       {
+         for (i = 0; i < element_info[touched_element].num_change_pages; i++)
+         {
+           struct ElementChangeInfo *change =
+             &element_info[touched_element].change_page[i];
+
+           if (change->can_change &&
+               change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) &&
+               change->sides & hitting_side &&
+               change->trigger_element == hitting_element)
+           {
+             CheckElementSideChange(nextx, nexty, touched_element,
+                                    CH_SIDE_ANY, CE_OTHER_GETS_HIT, i);
+             break;
+           }
+         }
+       }
+      }
+    }
+#endif
+  }
+#endif
 
   TestIfPlayerTouchesCustomElement(newx, newy);
   TestIfElementTouchesCustomElement(newx, newy);
@@ -4696,7 +5346,7 @@ int AmoebeNachbarNr(int ax, int ay)
     { 0, +1 }
   };
 
-  for (i=0; i<4; i++)
+  for (i = 0; i < 4; i++)
   {
     int x = ax + xy[i][0];
     int y = ay + xy[i][1];
@@ -4726,7 +5376,7 @@ void AmoebenVereinigen(int ax, int ay)
   if (new_group_nr == 0)
     return;
 
-  for (i=0; i<4; i++)
+  for (i = 0; i < 4; i++)
   {
     x = ax + xy[i][0];
     y = ay + xy[i][1];
@@ -4749,9 +5399,9 @@ void AmoebenVereinigen(int ax, int ay)
       AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
       AmoebaCnt2[old_group_nr] = 0;
 
-      for (yy=0; yy<lev_fieldy; yy++)
+      for (yy = 0; yy < lev_fieldy; yy++)
       {
-       for (xx=0; xx<lev_fieldx; xx++)
+       for (xx = 0; xx < lev_fieldx; xx++)
        {
          if (AmoebaNr[xx][yy] == old_group_nr)
            AmoebaNr[xx][yy] = new_group_nr;
@@ -4778,9 +5428,9 @@ void AmoebeUmwandeln(int ax, int ay)
     }
 #endif
 
-    for (y=0; y<lev_fieldy; y++)
+    for (y = 0; y < lev_fieldy; y++)
     {
-      for (x=0; x<lev_fieldx; x++)
+      for (x = 0; x < lev_fieldx; x++)
       {
        if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
        {
@@ -4789,7 +5439,7 @@ void AmoebeUmwandeln(int ax, int ay)
        }
       }
     }
-    PlaySoundLevel(ax, ay, (IS_GEM(level.amoeba_content) ?
+    PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
                            SND_AMOEBA_TURNING_TO_GEM :
                            SND_AMOEBA_TURNING_TO_ROCK));
     Bang(ax, ay);
@@ -4804,7 +5454,7 @@ void AmoebeUmwandeln(int ax, int ay)
       { 0, +1 }
     };
 
-    for (i=0; i<4; i++)
+    for (i = 0; i < 4; i++)
     {
       x = ax + xy[i][0];
       y = ay + xy[i][1];
@@ -4814,7 +5464,7 @@ void AmoebeUmwandeln(int ax, int ay)
 
       if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
       {
-       PlaySoundLevel(x, y, (IS_GEM(level.amoeba_content) ?
+       PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
                              SND_AMOEBA_TURNING_TO_GEM :
                              SND_AMOEBA_TURNING_TO_ROCK));
        Bang(x, y);
@@ -4838,9 +5488,9 @@ void AmoebeUmwandelnBD(int ax, int ay, int new_element)
   }
 #endif
 
-  for (y=0; y<lev_fieldy; y++)
+  for (y = 0; y < lev_fieldy; y++)
   {
-    for (x=0; x<lev_fieldx; x++)
+    for (x = 0; x < lev_fieldx; x++)
     {
       if (AmoebaNr[x][y] == group_nr &&
          (Feld[x][y] == EL_AMOEBA_DEAD ||
@@ -4857,7 +5507,7 @@ void AmoebeUmwandelnBD(int ax, int ay, int new_element)
   }
 
   if (done)
-    PlaySoundLevel(ax, ay, (new_element == EL_BD_ROCK ?
+    PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
                            SND_BD_AMOEBA_TURNING_TO_ROCK :
                            SND_BD_AMOEBA_TURNING_TO_GEM));
 }
@@ -4874,12 +5524,12 @@ void AmoebeWaechst(int x, int y)
     if (DelayReached(&sound_delay, sound_delay_value))
     {
 #if 1
-      PlaySoundLevelElementAction(x, y, Store[x][y], ACTION_GROWING);
+      PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
 #else
       if (Store[x][y] == EL_BD_AMOEBA)
-       PlaySoundLevel(x, y, SND_BD_AMOEBA_GROWING);
+       PlayLevelSound(x, y, SND_BD_AMOEBA_GROWING);
       else
-       PlaySoundLevel(x, y, SND_AMOEBA_GROWING);
+       PlayLevelSound(x, y, SND_AMOEBA_GROWING);
 #endif
       sound_delay_value = 30;
     }
@@ -5000,7 +5650,7 @@ void AmoebeAbleger(int ax, int ay)
     int start = RND(4);
     boolean waiting_for_player = FALSE;
 
-    for (i=0; i<4; i++)
+    for (i = 0; i < 4; i++)
     {
       int j = (start + i) % 4;
       int x = ax + xy[j][0];
@@ -5079,9 +5729,9 @@ void AmoebeAbleger(int ax, int ay)
   {
     Feld[newax][neway] = EL_AMOEBA_DROP;       /* drop left/right of amoeba */
 #if 1
-    PlaySoundLevelAction(newax, neway, ACTION_GROWING);
+    PlayLevelSoundAction(newax, neway, ACTION_GROWING);
 #else
-    PlaySoundLevel(newax, neway, SND_AMOEBA_GROWING);
+    PlayLevelSound(newax, neway, SND_AMOEBA_GROWING);
 #endif
   }
   else
@@ -5121,7 +5771,7 @@ void Life(int ax, int ay)
       return;
   }
 
-  for (y1=-1; y1<2; y1++) for(x1=-1; x1<2; x1++)
+  for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
   {
     int xx = ax+x1, yy = ay+y1;
     int nachbarn = 0;
@@ -5129,7 +5779,7 @@ void Life(int ax, int ay)
     if (!IN_LEV_FIELD(xx, yy))
       continue;
 
-    for (y2=-1; y2<2; y2++) for (x2=-1; x2<2; x2++)
+    for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
     {
       int x = xx+x2, y = yy+y2;
 
@@ -5170,7 +5820,7 @@ void Life(int ax, int ay)
   }
 
   if (changed)
-    PlaySoundLevel(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
+    PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
                   SND_GAME_OF_LIFE_GROWING);
 }
 
@@ -5181,7 +5831,7 @@ static void InitRobotWheel(int x, int y)
 
 static void RunRobotWheel(int x, int y)
 {
-  PlaySoundLevel(x, y, SND_ROBOT_WHEEL_ACTIVE);
+  PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
 }
 
 static void StopRobotWheel(int x, int y)
@@ -5197,7 +5847,7 @@ static void InitTimegateWheel(int x, int y)
 
 static void RunTimegateWheel(int x, int y)
 {
-  PlaySoundLevel(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
+  PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
 }
 
 void CheckExit(int x, int y)
@@ -5220,7 +5870,7 @@ void CheckExit(int x, int y)
 
   Feld[x][y] = EL_EXIT_OPENING;
 
-  PlaySoundLevelNearest(x, y, SND_CLASS_EXIT_OPENING);
+  PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
 }
 
 void CheckExitSP(int x, int y)
@@ -5241,16 +5891,16 @@ void CheckExitSP(int x, int y)
 
   Feld[x][y] = EL_SP_EXIT_OPENING;
 
-  PlaySoundLevelNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
+  PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
 }
 
 static void CloseAllOpenTimegates()
 {
   int x, y;
 
-  for (y=0; y<lev_fieldy; y++)
+  for (y = 0; y < lev_fieldy; y++)
   {
-    for (x=0; x<lev_fieldx; x++)
+    for (x = 0; x < lev_fieldx; x++)
     {
       int element = Feld[x][y];
 
@@ -5258,9 +5908,9 @@ static void CloseAllOpenTimegates()
       {
        Feld[x][y] = EL_TIMEGATE_CLOSING;
 #if 1
-       PlaySoundLevelAction(x, y, ACTION_CLOSING);
+       PlayLevelSoundAction(x, y, ACTION_CLOSING);
 #else
-       PlaySoundLevel(x, y, SND_TIMEGATE_CLOSING);
+       PlayLevelSound(x, y, SND_TIMEGATE_CLOSING);
 #endif
       }
     }
@@ -5464,9 +6114,9 @@ void MauerAbleger(int ax, int ay)
 
   if (new_wall)
 #if 1
-    PlaySoundLevelAction(ax, ay, ACTION_GROWING);
+    PlayLevelSoundAction(ax, ay, ACTION_GROWING);
 #else
-    PlaySoundLevel(ax, ay, SND_EXPANDABLE_WALL_GROWING);
+    PlayLevelSound(ax, ay, SND_EXPANDABLE_WALL_GROWING);
 #endif
 }
 
@@ -5482,9 +6132,9 @@ void CheckForDragon(int x, int y)
     { 0, +1 }
   };
 
-  for (i=0; i<4; i++)
+  for (i = 0; i < 4; i++)
   {
-    for (j=0; j<4; j++)
+    for (j = 0; j < 4; j++)
     {
       int xx = x + j*xy[i][0], yy = y + j*xy[i][1];
 
@@ -5501,9 +6151,9 @@ void CheckForDragon(int x, int y)
 
   if (!dragon_found)
   {
-    for (i=0; i<4; i++)
+    for (i = 0; i < 4; i++)
     {
-      for (j=0; j<3; j++)
+      for (j = 0; j < 3; j++)
       {
        int xx = x + j*xy[i][0], yy = y + j*xy[i][1];
   
@@ -5544,13 +6194,13 @@ static void WarnBuggyBase(int x, int y)
     { 0, +1 }
   };
 
-  for (i=0; i<4; i++)
+  for (i = 0; i < 4; i++)
   {
     int xx = x + xy[i][0], yy = y + xy[i][1];
 
     if (IS_PLAYER(xx, yy))
     {
-      PlaySoundLevel(x, y, SND_SP_BUGGY_BASE_ACTIVE);
+      PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
 
       break;
     }
@@ -5564,7 +6214,7 @@ static void InitTrap(int x, int y)
 
 static void ActivateTrap(int x, int y)
 {
-  PlaySoundLevel(x, y, SND_TRAP_ACTIVATING);
+  PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
 }
 
 static void ChangeActiveTrap(int x, int y)
@@ -5578,6 +6228,8 @@ static void ChangeActiveTrap(int x, int y)
 
 static void ChangeElementNowExt(int x, int y, int target_element)
 {
+  int previous_move_direction = MovDir[x][y];
+
   /* check if element under player changes from accessible to unaccessible
      (needed for special case of dropping element which then changes) */
   if (IS_PLAYER(x, y) && !PLAYER_PROTECTED(x, y) &&
@@ -5595,6 +6247,9 @@ static void ChangeElementNowExt(int x, int y, int target_element)
   ResetGfxAnimation(x, y);
   ResetRandomAnimationValue(x, y);
 
+  if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
+    MovDir[x][y] = previous_move_direction;
+
   InitField(x, y, FALSE);
   if (CAN_MOVE(Feld[x][y]))
     InitMovDir(x, y);
@@ -5646,7 +6301,7 @@ static boolean ChangeElementNow(int x, int y, int element, int page)
     boolean can_change[3][3];
     int xx, yy;
 
-    for (yy = 0; yy < 3; yy++) for(xx = 0; xx < 3 ; xx++)
+    for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
     {
       boolean half_destructible;
       int ex = x + xx - 1;
@@ -5697,7 +6352,7 @@ static boolean ChangeElementNow(int x, int y, int element, int page)
          RND(100) < change->random)
        return FALSE;
 
-      for (yy = 0; yy < 3; yy++) for(xx = 0; xx < 3 ; xx++)
+      for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
       {
        int ex = x + xx - 1;
        int ey = y + yy - 1;
@@ -5721,14 +6376,14 @@ static boolean ChangeElementNow(int x, int y, int element, int page)
       }
 
       if (something_has_changed)
-       PlaySoundLevelElementAction(x, y, element, ACTION_CHANGING);
+       PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
     }
   }
   else
   {
     ChangeElementNowExt(x, y, change->target_element);
 
-    PlaySoundLevelElementAction(x, y, element, ACTION_CHANGING);
+    PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
   }
 
   return TRUE;
@@ -5785,7 +6440,11 @@ static void ChangeElement(int x, int y, int page)
       ChangePage[x][y] = -1;
     }
 
+#if 0
+    if (IS_MOVING(x, y) && !change->explode)
+#else
     if (IS_MOVING(x, y))               /* never change a running system ;-) */
+#endif
     {
       ChangeDelay[x][y] = 1;           /* try change after next move step */
       ChangePage[x][y] = page;         /* remember page to use for change */
@@ -5811,7 +6470,7 @@ static boolean CheckTriggeredElementSideChange(int lx, int ly,
   if (!(trigger_events[trigger_element] & CH_EVENT_BIT(trigger_event)))
     return FALSE;
 
-  for (i=0; i < NUM_CUSTOM_ELEMENTS; i++)
+  for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
   {
     int element = EL_CUSTOM_START + i;
 
@@ -5821,7 +6480,7 @@ static boolean CheckTriggeredElementSideChange(int lx, int ly,
     if (!CAN_CHANGE(element) || !HAS_ANY_CHANGE_EVENT(element, trigger_event))
       continue;
 
-    for (j=0; j < element_info[element].num_change_pages; j++)
+    for (j = 0; j < element_info[element].num_change_pages; j++)
     {
       struct ElementChangeInfo *change = &element_info[element].change_page[j];
 
@@ -5830,7 +6489,12 @@ static boolean CheckTriggeredElementSideChange(int lx, int ly,
          change->events & CH_EVENT_BIT(trigger_event) &&
 #endif
          change->sides & trigger_side &&
-         change->trigger_element == trigger_element)
+#if 1
+         IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element)
+#else
+         change->trigger_element == trigger_element
+#endif
+         )
       {
 #if 0
        if (!(change->events & CH_EVENT_BIT(trigger_event)))
@@ -5848,7 +6512,7 @@ static boolean CheckTriggeredElementSideChange(int lx, int ly,
     if (!change_element)
       continue;
 
-    for (y=0; y<lev_fieldy; y++) for (x=0; x<lev_fieldx; x++)
+    for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
     {
 #if 0
       if (x == lx && y == ly)  /* do not change trigger element itself */
@@ -5904,6 +6568,168 @@ static boolean CheckElementChange(int x, int y, int element, int trigger_event)
   return CheckElementSideChange(x, y, element, CH_SIDE_ANY, trigger_event, -1);
 }
 
+static void PlayPlayerSound(struct PlayerInfo *player)
+{
+  int jx = player->jx, jy = player->jy;
+  int element = player->element_nr;
+  int last_action = player->last_action_waiting;
+  int action = player->action_waiting;
+
+  if (player->is_waiting)
+  {
+    if (action != last_action)
+      PlayLevelSoundElementAction(jx, jy, element, action);
+    else
+      PlayLevelSoundElementActionIfLoop(jx, jy, element, action);
+  }
+  else
+  {
+    if (action != last_action)
+      StopSound(element_info[element].sound[last_action]);
+
+    if (last_action == ACTION_SLEEPING)
+      PlayLevelSoundElementAction(jx, jy, element, ACTION_AWAKENING);
+  }
+}
+
+static void PlayAllPlayersSound()
+{
+  int i;
+
+  for (i = 0; i < MAX_PLAYERS; i++)
+    if (stored_player[i].active)
+      PlayPlayerSound(&stored_player[i]);
+}
+
+static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
+{
+  boolean last_waiting = player->is_waiting;
+  int move_dir = player->MovDir;
+
+  player->last_action_waiting = player->action_waiting;
+
+  if (is_waiting)
+  {
+    if (!last_waiting)         /* not waiting -> waiting */
+    {
+      player->is_waiting = TRUE;
+
+      player->frame_counter_bored =
+       FrameCounter +
+       game.player_boring_delay_fixed +
+       SimpleRND(game.player_boring_delay_random);
+      player->frame_counter_sleeping =
+       FrameCounter +
+       game.player_sleeping_delay_fixed +
+       SimpleRND(game.player_sleeping_delay_random);
+
+      InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
+    }
+
+    if (game.player_sleeping_delay_fixed +
+       game.player_sleeping_delay_random > 0 &&
+       player->anim_delay_counter == 0 &&
+       player->post_delay_counter == 0 &&
+       FrameCounter >= player->frame_counter_sleeping)
+      player->is_sleeping = TRUE;
+    else if (game.player_boring_delay_fixed +
+            game.player_boring_delay_random > 0 &&
+            FrameCounter >= player->frame_counter_bored)
+      player->is_bored = TRUE;
+
+    player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
+                             player->is_bored ? ACTION_BORING :
+                             ACTION_WAITING);
+
+    if (player->is_sleeping)
+    {
+      if (player->num_special_action_sleeping > 0)
+      {
+       if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
+       {
+         int last_special_action = player->special_action_sleeping;
+         int num_special_action = player->num_special_action_sleeping;
+         int special_action =
+           (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
+            last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
+            last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
+            last_special_action + 1 : ACTION_SLEEPING);
+         int special_graphic =
+           el_act_dir2img(player->element_nr, special_action, move_dir);
+
+         player->anim_delay_counter =
+           graphic_info[special_graphic].anim_delay_fixed +
+           SimpleRND(graphic_info[special_graphic].anim_delay_random);
+         player->post_delay_counter =
+           graphic_info[special_graphic].post_delay_fixed +
+           SimpleRND(graphic_info[special_graphic].post_delay_random);
+
+         player->special_action_sleeping = special_action;
+       }
+
+       if (player->anim_delay_counter > 0)
+       {
+         player->action_waiting = player->special_action_sleeping;
+         player->anim_delay_counter--;
+       }
+       else if (player->post_delay_counter > 0)
+       {
+         player->post_delay_counter--;
+       }
+      }
+    }
+    else if (player->is_bored)
+    {
+      if (player->num_special_action_bored > 0)
+      {
+       if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
+       {
+         int special_action =
+           ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
+         int special_graphic =
+           el_act_dir2img(player->element_nr, special_action, move_dir);
+
+         player->anim_delay_counter =
+           graphic_info[special_graphic].anim_delay_fixed +
+           SimpleRND(graphic_info[special_graphic].anim_delay_random);
+         player->post_delay_counter =
+           graphic_info[special_graphic].post_delay_fixed +
+           SimpleRND(graphic_info[special_graphic].post_delay_random);
+
+         player->special_action_bored = special_action;
+       }
+
+       if (player->anim_delay_counter > 0)
+       {
+         player->action_waiting = player->special_action_bored;
+         player->anim_delay_counter--;
+       }
+       else if (player->post_delay_counter > 0)
+       {
+         player->post_delay_counter--;
+       }
+      }
+    }
+  }
+  else if (last_waiting)       /* waiting -> not waiting */
+  {
+    player->is_waiting = FALSE;
+    player->is_bored = FALSE;
+    player->is_sleeping = FALSE;
+
+    player->frame_counter_bored = -1;
+    player->frame_counter_sleeping = -1;
+
+    player->anim_delay_counter = 0;
+    player->post_delay_counter = 0;
+
+    player->action_waiting = ACTION_DEFAULT;
+
+    player->special_action_bored = ACTION_DEFAULT;
+    player->special_action_sleeping = ACTION_DEFAULT;
+  }
+}
+
 #if 1
 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
 {
@@ -5933,6 +6759,11 @@ static byte PlayerActions(struct PlayerInfo *player, byte player_action)
   if (!player->active || tape.pausing)
     return 0;
 
+#if 0
+  printf("::: [%d %d %d %d] [%d %d]\n",
+        left, right, up, down, button1, button2);
+#endif
+
   if (player_action)
   {
 #if 0
@@ -5958,6 +6789,8 @@ static byte PlayerActions(struct PlayerInfo *player, byte player_action)
       }
     }
 
+    SetPlayerWaiting(player, FALSE);
+
 #if 1
     return player_action;
 #else
@@ -5977,11 +6810,13 @@ static byte PlayerActions(struct PlayerInfo *player, byte player_action)
     CheckGravityMovement(player);
 
     if (player->MovPos == 0)
-      InitPlayerGfxAnimation(player, ACTION_DEFAULT, player->MovDir);
+      SetPlayerWaiting(player, TRUE);
 
     if (player->MovPos == 0)   /* needed for tape.playing */
       player->is_moving = FALSE;
 
+    player->is_dropping = FALSE;
+
     return 0;
   }
 
@@ -6127,9 +6962,13 @@ void GameActions()
   if (tape.pausing)
     return;
 
+#if 0
+  printf("::: getting new tape action [%d]\n", FrameCounter);
+#endif
+
   recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
 
-  for (i=0; i<MAX_PLAYERS; i++)
+  for (i = 0; i < MAX_PLAYERS; i++)
   {
     summarized_player_action |= stored_player[i].action;
 
@@ -6145,7 +6984,7 @@ void GameActions()
   if (!options.network && !setup.team_mode)
     local_player->effective_action = summarized_player_action;
 
-  for (i=0; i < MAX_PLAYERS; i++)
+  for (i = 0; i < MAX_PLAYERS; i++)
   {
     int actual_player_action = stored_player[i].effective_action;
 
@@ -6157,6 +6996,9 @@ void GameActions()
 
     tape_action[i] = PlayerActions(&stored_player[i], actual_player_action);
 
+    if (tape.recording && tape_action[i] && !tape.player_participates[i])
+      tape.player_participates[i] = TRUE;    /* player just appeared from CE */
+
     ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
   }
 
@@ -6173,14 +7015,14 @@ void GameActions()
   FrameCounter++;
   TimeFrames++;
 
-  for (i=0; i<MAX_PLAYERS; i++)
+  for (i = 0; i < MAX_PLAYERS; i++)
     stored_player[i].Frame++;
 #endif
 
 #if 1
   if (game.engine_version < VERSION_IDENT(2,2,0,7))
   {
-    for (i=0; i<MAX_PLAYERS; i++)
+    for (i = 0; i < MAX_PLAYERS; i++)
     {
       struct PlayerInfo *player = &stored_player[i];
       int x = player->jx;
@@ -6201,7 +7043,7 @@ void GameActions()
   }
 #endif
 
-  for (y=0; y<lev_fieldy; y++) for (x=0; x<lev_fieldx; x++)
+  for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
   {
     Changed[x][y] = CE_BITMASK_DEFAULT;
     ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
@@ -6251,7 +7093,7 @@ void GameActions()
 #endif
   }
 
-  for (y=0; y<lev_fieldy; y++) for (x=0; x<lev_fieldx; x++)
+  for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
   {
     element = Feld[x][y];
 #if 1
@@ -6279,7 +7121,7 @@ void GameActions()
     SetRandomAnimationValue(x, y);
 
 #if 1
-    PlaySoundLevelActionIfLoop(x, y, GfxAction[x][y]);
+    PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
 #endif
 
     if (IS_INACTIVE(element))
@@ -6316,6 +7158,7 @@ void GameActions()
       StartMoving(x, y);
 
 #if 1
+      element = Feld[x][y];
       graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
 #if 0
       if (element == EL_MOLE)
@@ -6409,7 +7252,7 @@ void GameActions()
 #endif
 
     if (IS_BELT_ACTIVE(element))
-      PlaySoundLevelAction(x, y, ACTION_ACTIVE);
+      PlayLevelSoundAction(x, y, ACTION_ACTIVE);
 
     if (game.magic_wall_active)
     {
@@ -6475,7 +7318,7 @@ void GameActions()
   {
     game.explosions_delayed = FALSE;
 
-    for (y=0; y<lev_fieldy; y++) for (x=0; x<lev_fieldx; x++)
+    for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
     {
       element = Feld[x][y];
 
@@ -6499,9 +7342,9 @@ void GameActions()
       if (element == EL_BD_MAGIC_WALL_FULL ||
          element == EL_BD_MAGIC_WALL_ACTIVE ||
          element == EL_BD_MAGIC_WALL_EMPTYING)
-       PlaySoundLevel(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
+       PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
       else
-       PlaySoundLevel(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
+       PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
     }
 
     if (game.magic_wall_time_left > 0)
@@ -6509,7 +7352,7 @@ void GameActions()
       game.magic_wall_time_left--;
       if (!game.magic_wall_time_left)
       {
-       for (y=0; y<lev_fieldy; y++) for (x=0; x<lev_fieldx; x++)
+       for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
        {
          element = Feld[x][y];
 
@@ -6548,16 +7391,16 @@ void GameActions()
       CloseAllOpenTimegates();
   }
 
-  for (i=0; i<MAX_PLAYERS; i++)
+  for (i = 0; i < MAX_PLAYERS; i++)
   {
     struct PlayerInfo *player = &stored_player[i];
 
     if (SHIELD_ON(player))
     {
       if (player->shield_deadly_time_left)
-       PlaySoundLevel(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
+       PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
       else if (player->shield_normal_time_left)
-       PlaySoundLevel(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
+       PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
     }
   }
 
@@ -6566,7 +7409,7 @@ void GameActions()
     TimeFrames = 0;
     TimePlayed++;
 
-    for (i=0; i<MAX_PLAYERS; i++)
+    for (i = 0; i < MAX_PLAYERS; i++)
     {
       struct PlayerInfo *player = &stored_player[i];
 
@@ -6592,7 +7435,7 @@ void GameActions()
       DrawText(DX_TIME, DY_TIME, int2str(TimeLeft, 3), FONT_TEXT_2);
 
       if (!TimeLeft && setup.time_limit)
-       for (i=0; i<MAX_PLAYERS; i++)
+       for (i = 0; i < MAX_PLAYERS; i++)
          KillHero(&stored_player[i]);
     }
     else if (level.time == 0 && !AllPlayersGone) /* level without time limit */
@@ -6600,6 +7443,7 @@ void GameActions()
   }
 
   DrawAllPlayers();
+  PlayAllPlayersSound();
 
   if (options.debug)                   /* calculate frames per second */
   {
@@ -6635,7 +7479,7 @@ void GameActions()
   FrameCounter++;
   TimeFrames++;
 
-  for (i=0; i<MAX_PLAYERS; i++)
+  for (i = 0; i < MAX_PLAYERS; i++)
   {
     int move_frames =
       MOVE_DELAY_NORMAL_SPEED /  stored_player[i].move_delay_value;
@@ -6644,6 +7488,9 @@ void GameActions()
 
     if (stored_player[i].MovPos != 0)
       stored_player[i].StepFrame += move_frames;
+
+    if (stored_player[i].drop_delay > 0)
+      stored_player[i].drop_delay--;
   }
 #endif
 
@@ -6662,7 +7509,7 @@ static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
   int min_x = x, min_y = y, max_x = x, max_y = y;
   int i;
 
-  for (i=0; i<MAX_PLAYERS; i++)
+  for (i = 0; i < MAX_PLAYERS; i++)
   {
     int jx = stored_player[i].jx, jy = stored_player[i].jy;
 
@@ -6682,7 +7529,7 @@ static boolean AllPlayersInVisibleScreen()
 {
   int i;
 
-  for (i=0; i<MAX_PLAYERS; i++)
+  for (i = 0; i < MAX_PLAYERS; i++)
   {
     int jx = stored_player[i].jx, jy = stored_player[i].jy;
 
@@ -6712,20 +7559,52 @@ void ScrollLevel(int dx, int dy)
   if (dx)
   {
     x = (dx == 1 ? BX1 : BX2);
-    for (y=BY1; y <= BY2; y++)
+    for (y = BY1; y <= BY2; y++)
       DrawScreenField(x, y);
   }
 
   if (dy)
   {
     y = (dy == 1 ? BY1 : BY2);
-    for (x=BX1; x <= BX2; x++)
+    for (x = BX1; x <= BX2; x++)
       DrawScreenField(x, y);
   }
 
   redraw_mask |= REDRAW_FIELD;
 }
 
+static boolean canEnterSupaplexPort(int x, int y, int dx, int dy)
+{
+  int nextx = x + dx, nexty = y + dy;
+  int element = Feld[x][y];
+
+  if ((dx == -1 &&
+       element != EL_SP_PORT_LEFT &&
+       element != EL_SP_GRAVITY_PORT_LEFT &&
+       element != EL_SP_PORT_HORIZONTAL &&
+       element != EL_SP_PORT_ANY) ||
+      (dx == +1 &&
+       element != EL_SP_PORT_RIGHT &&
+       element != EL_SP_GRAVITY_PORT_RIGHT &&
+       element != EL_SP_PORT_HORIZONTAL &&
+       element != EL_SP_PORT_ANY) ||
+      (dy == -1 &&
+       element != EL_SP_PORT_UP &&
+       element != EL_SP_GRAVITY_PORT_UP &&
+       element != EL_SP_PORT_VERTICAL &&
+       element != EL_SP_PORT_ANY) ||
+      (dy == +1 &&
+       element != EL_SP_PORT_DOWN &&
+       element != EL_SP_GRAVITY_PORT_DOWN &&
+       element != EL_SP_PORT_VERTICAL &&
+       element != EL_SP_PORT_ANY) ||
+      !IN_LEV_FIELD(nextx, nexty) ||
+      !IS_FREE(nextx, nexty))
+    return FALSE;
+
+  return TRUE;
+}
+
 static void CheckGravityMovement(struct PlayerInfo *player)
 {
   if (game.gravity && !player->programmed_action)
@@ -6745,7 +7624,9 @@ static void CheckGravityMovement(struct PlayerInfo *player)
     boolean player_is_moving_to_valid_field =
       (IN_LEV_FIELD(new_jx, new_jy) &&
        (Feld[new_jx][new_jy] == EL_SP_BASE ||
-       Feld[new_jx][new_jy] == EL_SAND));
+       Feld[new_jx][new_jy] == EL_SAND ||
+       (IS_SP_PORT(Feld[new_jx][new_jy]) &&
+        canEnterSupaplexPort(new_jx, new_jy, dx, dy))));
     /* !!! extend EL_SAND to anything diggable !!! */
 
     if (field_under_player_is_free &&
@@ -6841,6 +7722,12 @@ boolean MovePlayerOneStep(struct PlayerInfo *player,
   player->MovPos =
     (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
 
+  player->step_counter++;
+
+  player->drop_delay = 0;
+
+  PlayerVisit[jx][jy] = FrameCounter;
+
   ScrollPlayer(player, SCROLL_INIT);
 
 #if 0
@@ -6870,8 +7757,27 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
   int old_jx = jx, old_jy = jy;
   int moved = MF_NO_ACTION;
 
+#if 1
+  if (!player->active)
+    return FALSE;
+
+  if (!dx && !dy)
+  {
+    if (player->MovPos == 0)
+    {
+      player->is_moving = FALSE;
+      player->is_digging = FALSE;
+      player->is_collecting = FALSE;
+      player->is_snapping = FALSE;
+      player->is_pushing = FALSE;
+    }
+
+    return FALSE;
+  }
+#else
   if (!player->active || (!dx && !dy))
     return FALSE;
+#endif
 
 #if 0
   if (!FrameReached(&player->move_delay, player->move_delay_value) &&
@@ -7026,6 +7932,8 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
     player->is_switching = FALSE;
 #endif
 
+    player->is_dropping = FALSE;
+
 
 #if 1
     {
@@ -7106,6 +8014,7 @@ void ScrollPlayer(struct PlayerInfo *player, int mode)
 #if 0
     DrawPlayer(player);
 #endif
+
     return;
   }
   else if (!FrameReached(&player->actual_frame_counter, 1))
@@ -7114,7 +8023,8 @@ void ScrollPlayer(struct PlayerInfo *player, int mode)
   player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
   player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
 
-  if (Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
+  if (!player->block_last_field &&
+      Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
     Feld[last_jx][last_jy] = EL_EMPTY;
 
   /* before DrawPlayer() to draw correct player graphic for this case */
@@ -7127,6 +8037,21 @@ void ScrollPlayer(struct PlayerInfo *player, int mode)
 
   if (player->MovPos == 0)     /* player reached destination field */
   {
+#if 1
+    if (player->move_delay_reset_counter > 0)
+    {
+      player->move_delay_reset_counter--;
+
+      if (player->move_delay_reset_counter == 0)
+      {
+       /* continue with normal speed after quickly moving through gate */
+       HALVE_PLAYER_SPEED(player);
+
+       /* be able to make the next move without delay */
+       player->move_delay = 0;
+      }
+    }
+#else
     if (IS_PASSABLE(Feld[last_jx][last_jy]))
     {
       /* continue with normal speed after quickly moving through gate */
@@ -7135,6 +8060,11 @@ void ScrollPlayer(struct PlayerInfo *player, int mode)
       /* be able to make the next move without delay */
       player->move_delay = 0;
     }
+#endif
+
+    if (player->block_last_field &&
+       Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
+      Feld[last_jx][last_jy] = EL_EMPTY;
 
     player->last_jx = jx;
     player->last_jy = jy;
@@ -7224,7 +8154,7 @@ void TestIfPlayerTouchesCustomElement(int x, int y)
   int center_element = Feld[x][y];     /* should always be non-moving! */
   int i;
 
-  for (i=0; i<4; i++)
+  for (i = 0; i < 4; i++)
   {
     int xx = x + xy[i][0];
     int yy = y + xy[i][1];
@@ -7282,7 +8212,7 @@ void TestIfElementTouchesCustomElement(int x, int y)
   };
   static int change_sides[4][2] =
   {
-    /* center side       border side */
+    /* center side     border side */
     { CH_SIDE_TOP,     CH_SIDE_BOTTOM  },      /* check top    */
     { CH_SIDE_LEFT,    CH_SIDE_RIGHT   },      /* check left   */
     { CH_SIDE_RIGHT,   CH_SIDE_LEFT    },      /* check right  */
@@ -7300,7 +8230,7 @@ void TestIfElementTouchesCustomElement(int x, int y)
   int center_element = Feld[x][y];     /* should always be non-moving! */
   int i, j;
 
-  for (i=0; i<4; i++)
+  for (i = 0; i < 4; i++)
   {
     int xx = x + xy[i][0];
     int yy = y + xy[i][1];
@@ -7325,7 +8255,7 @@ void TestIfElementTouchesCustomElement(int x, int y)
        HAS_ANY_CHANGE_EVENT(center_element, CE_OTHER_IS_TOUCHING) &&
        !change_center_element)
     {
-      for (j=0; j < element_info[center_element].num_change_pages; j++)
+      for (j = 0; j < element_info[center_element].num_change_pages; j++)
       {
        struct ElementChangeInfo *change =
          &element_info[center_element].change_page[j];
@@ -7333,7 +8263,12 @@ void TestIfElementTouchesCustomElement(int x, int y)
        if (change->can_change &&
            change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) &&
            change->sides & border_side &&
-           change->trigger_element == border_element)
+#if 1
+           IS_EQUAL_OR_IN_GROUP(border_element, change->trigger_element)
+#else
+           change->trigger_element == border_element
+#endif
+           )
        {
          change_center_element = TRUE;
          center_element_change_page = j;
@@ -7347,7 +8282,7 @@ void TestIfElementTouchesCustomElement(int x, int y)
     if (IS_CUSTOM_ELEMENT(border_element) &&
        HAS_ANY_CHANGE_EVENT(border_element, CE_OTHER_IS_TOUCHING))
     {
-      for (j=0; j < element_info[border_element].num_change_pages; j++)
+      for (j = 0; j < element_info[border_element].num_change_pages; j++)
       {
        struct ElementChangeInfo *change =
          &element_info[border_element].change_page[j];
@@ -7355,7 +8290,12 @@ void TestIfElementTouchesCustomElement(int x, int y)
        if (change->can_change &&
            change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) &&
            change->sides & center_side &&
-           change->trigger_element == center_element)
+#if 1
+           IS_EQUAL_OR_IN_GROUP(center_element, change->trigger_element)
+#else
+           change->trigger_element == center_element
+#endif
+           )
        {
          CheckElementSideChange(xx, yy, border_element, CH_SIDE_ANY,
                                 CE_OTHER_IS_TOUCHING, j);
@@ -7370,6 +8310,114 @@ void TestIfElementTouchesCustomElement(int x, int y)
                           CE_OTHER_IS_TOUCHING, center_element_change_page);
 }
 
+void TestIfElementHitsCustomElement(int x, int y, int direction)
+{
+  int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
+  int dy = (direction == MV_UP   ? -1 : direction == MV_DOWN  ? +1 : 0);
+  int hitx = x + dx, hity = y + dy;
+  int hitting_element = Feld[x][y];
+#if 0
+  boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
+                       !IS_FREE(hitx, hity) &&
+                       (!IS_MOVING(hitx, hity) ||
+                        MovDir[hitx][hity] != direction ||
+                        ABS(MovPos[hitx][hity]) <= TILEY / 2));
+#endif
+
+  if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
+    return;
+
+#if 0
+  if (IN_LEV_FIELD(hitx, hity) && !object_hit)
+    return;
+#endif
+
+  CheckElementSideChange(x, y, hitting_element,
+                        direction, CE_HITTING_SOMETHING, -1);
+
+  if (IN_LEV_FIELD(hitx, hity))
+  {
+    static int opposite_directions[] =
+    {
+      MV_RIGHT,
+      MV_LEFT,
+      MV_DOWN,
+      MV_UP
+    };
+    int move_dir_bit = MV_DIR_BIT(direction);
+    int opposite_direction = opposite_directions[move_dir_bit];
+    int hitting_side = direction;
+    int touched_side = opposite_direction;
+    int touched_element = MovingOrBlocked2Element(hitx, hity);
+#if 1
+    boolean object_hit = (!IS_MOVING(hitx, hity) ||
+                         MovDir[hitx][hity] != direction ||
+                         ABS(MovPos[hitx][hity]) <= TILEY / 2);
+
+    object_hit = TRUE;
+#endif
+
+    if (object_hit)
+    {
+      int i;
+
+      CheckElementSideChange(hitx, hity, touched_element,
+                            opposite_direction, CE_HIT_BY_SOMETHING, -1);
+
+      if (IS_CUSTOM_ELEMENT(hitting_element) &&
+         HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING))
+      {
+       for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
+       {
+         struct ElementChangeInfo *change =
+           &element_info[hitting_element].change_page[i];
+
+         if (change->can_change &&
+             change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) &&
+             change->sides & touched_side &&
+         
+#if 1
+             IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element)
+#else
+             change->trigger_element == touched_element
+#endif
+             )
+         {
+           CheckElementSideChange(x, y, hitting_element,
+                                  CH_SIDE_ANY, CE_OTHER_IS_HITTING, i);
+           break;
+         }
+       }
+      }
+
+      if (IS_CUSTOM_ELEMENT(touched_element) &&
+         HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_HIT))
+      {
+       for (i = 0; i < element_info[touched_element].num_change_pages; i++)
+       {
+         struct ElementChangeInfo *change =
+           &element_info[touched_element].change_page[i];
+
+         if (change->can_change &&
+             change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) &&
+             change->sides & hitting_side &&
+#if 1
+             IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element)
+#else
+             change->trigger_element == hitting_element
+#endif
+             )
+         {
+           CheckElementSideChange(hitx, hity, touched_element,
+                                  CH_SIDE_ANY, CE_OTHER_GETS_HIT, i);
+           break;
+         }
+       }
+      }
+    }
+  }
+}
+
 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
 {
   int i, kill_x = -1, kill_y = -1;
@@ -7388,7 +8436,7 @@ void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
     MV_DOWN
   };
 
-  for (i=0; i<4; i++)
+  for (i = 0; i < 4; i++)
   {
     int test_x, test_y, test_move_dir, test_element;
 
@@ -7463,7 +8511,7 @@ void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
   if (bad_element == EL_EXPLOSION)     /* skip just exploding bad things */
     return;
 
-  for (i=0; i<4; i++)
+  for (i = 0; i < 4; i++)
   {
     int test_x, test_y, test_move_dir, test_element;
 
@@ -7567,7 +8615,7 @@ void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
     { 0, +1 }
   };
 
-  for (i=0; i<4; i++)
+  for (i = 0; i < 4; i++)
   {
     int x, y, element;
 
@@ -7622,11 +8670,11 @@ void BuryHero(struct PlayerInfo *player)
     return;
 
 #if 1
-  PlaySoundLevelElementAction(jx, jy, player->element_nr, ACTION_DYING);
+  PlayLevelSoundElementAction(jx, jy, player->element_nr, ACTION_DYING);
 #else
-  PlaySoundLevel(jx, jy, SND_CLASS_PLAYER_DYING);
+  PlayLevelSound(jx, jy, SND_CLASS_PLAYER_DYING);
 #endif
-  PlaySoundLevel(jx, jy, SND_GAME_LOSING);
+  PlayLevelSound(jx, jy, SND_GAME_LOSING);
 
   player->GameOver = TRUE;
   RemoveHero(player);
@@ -7643,7 +8691,7 @@ void RemoveHero(struct PlayerInfo *player)
   if (!ExplodeField[jx][jy])
     StorePlayer[jx][jy] = 0;
 
-  for (i=0; i<MAX_PLAYERS; i++)
+  for (i = 0; i < MAX_PLAYERS; i++)
     if (stored_player[i].active)
       found = TRUE;
 
@@ -7787,6 +8835,10 @@ int DigField(struct PlayerInfo *player,
     case EL_SP_GRAVITY_PORT_RIGHT:
     case EL_SP_GRAVITY_PORT_UP:
     case EL_SP_GRAVITY_PORT_DOWN:
+#if 1
+      if (!canEnterSupaplexPort(x, y, dx, dy))
+       return MF_NO_ACTION;
+#else
       if ((dx == -1 &&
           element != EL_SP_PORT_LEFT &&
           element != EL_SP_GRAVITY_PORT_LEFT &&
@@ -7810,6 +8862,7 @@ int DigField(struct PlayerInfo *player,
          !IN_LEV_FIELD(nextx, nexty) ||
          !IS_FREE(nextx, nexty))
        return MF_NO_ACTION;
+#endif
 
       if (element == EL_SP_GRAVITY_PORT_LEFT ||
          element == EL_SP_GRAVITY_PORT_RIGHT ||
@@ -7819,9 +8872,20 @@ int DigField(struct PlayerInfo *player,
 
       /* automatically move to the next field with double speed */
       player->programmed_action = move_direction;
+#if 1
+      if (player->move_delay_reset_counter == 0)
+      {
+       player->move_delay_reset_counter = 2;   /* two double speed steps */
+
+       DOUBLE_PLAYER_SPEED(player);
+      }
+#else
+      player->move_delay_reset_counter = 2;
+
       DOUBLE_PLAYER_SPEED(player);
+#endif
 
-      PlaySoundLevel(x, y, SND_CLASS_SP_PORT_PASSING);
+      PlayLevelSound(x, y, SND_CLASS_SP_PORT_PASSING);
       break;
 
     case EL_TUBE_ANY:
@@ -7863,7 +8927,7 @@ int DigField(struct PlayerInfo *player,
        if (!(tube_enter_directions[i][1] & move_direction))
          return MF_NO_ACTION;  /* tube has no opening in this direction */
 
-       PlaySoundLevel(x, y, SND_CLASS_TUBE_WALKING);
+       PlayLevelSound(x, y, SND_CLASS_TUBE_WALKING);
       }
       break;
 
@@ -7896,9 +8960,9 @@ int DigField(struct PlayerInfo *player,
 
        /* play sound from background or player, whatever is available */
        if (element_info[element].sound[sound_action] != SND_UNDEFINED)
-         PlaySoundLevelElementAction(x, y, element, sound_action);
+         PlayLevelSoundElementAction(x, y, element, sound_action);
        else
-         PlaySoundLevelElementAction(x, y, player->element_nr, sound_action);
+         PlayLevelSoundElementAction(x, y, player->element_nr, sound_action);
 
        break;
       }
@@ -7925,9 +8989,20 @@ int DigField(struct PlayerInfo *player,
 
        /* automatically move to the next field with double speed */
        player->programmed_action = move_direction;
+#if 1
+       if (player->move_delay_reset_counter == 0)
+       {
+         player->move_delay_reset_counter = 2; /* two double speed steps */
+
+         DOUBLE_PLAYER_SPEED(player);
+       }
+#else
+       player->move_delay_reset_counter = 2;
+
        DOUBLE_PLAYER_SPEED(player);
+#endif
 
-       PlaySoundLevelAction(x, y, ACTION_PASSING);
+       PlayLevelSoundAction(x, y, ACTION_PASSING);
 
        break;
       }
@@ -7946,7 +9021,7 @@ int DigField(struct PlayerInfo *player,
          player->is_digging = TRUE;
        }
 
-       PlaySoundLevelElementAction(x, y, element, ACTION_DIGGING);
+       PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
 
        CheckTriggeredElementChange(x, y, element, CE_OTHER_GETS_DIGGED);
 
@@ -8025,7 +9100,7 @@ int DigField(struct PlayerInfo *player,
        {
          int i;
 
-         for (i=0; i < element_info[element].collect_count; i++)
+         for (i = 0; i < element_info[element].collect_count; i++)
            if (player->inventory_size < MAX_INVENTORY_SIZE)
              player->inventory_element[player->inventory_size++] = element;
 
@@ -8044,7 +9119,7 @@ int DigField(struct PlayerInfo *player,
        }
 
        RaiseScoreElement(element);
-       PlaySoundLevelElementAction(x, y, element, ACTION_COLLECTING);
+       PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
 
        CheckTriggeredElementChange(x, y, element, CE_OTHER_GETS_COLLECTED);
 
@@ -8168,23 +9243,23 @@ int DigField(struct PlayerInfo *player,
          Feld[x][y] = EL_SOKOBAN_OBJECT;
 
          if (Back[x][y] == Back[nextx][nexty])
-           PlaySoundLevelAction(x, y, ACTION_PUSHING);
+           PlayLevelSoundAction(x, y, ACTION_PUSHING);
          else if (Back[x][y] != 0)
-           PlaySoundLevelElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
+           PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
                                        ACTION_EMPTYING);
          else
-           PlaySoundLevelElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
+           PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
                                        ACTION_FILLING);
 
          if (local_player->sokobanfields_still_needed == 0 &&
              game.emulation == EMU_SOKOBAN)
          {
            player->LevelSolved = player->GameOver = TRUE;
-           PlaySoundLevel(x, y, SND_GAME_SOKOBAN_SOLVING);
+           PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
          }
        }
        else
-         PlaySoundLevelElementAction(x, y, element, ACTION_PUSHING);
+         PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
 
        InitMovingField(x, y, move_direction);
        GfxAction[x][y] = ACTION_PUSHING;
@@ -8218,7 +9293,7 @@ int DigField(struct PlayerInfo *player,
        player->switch_x = x;
        player->switch_y = y;
 
-       PlaySoundLevelElementAction(x, y, element, ACTION_ACTIVATING);
+       PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
 
        if (element == EL_ROBOT_WHEEL)
        {
@@ -8232,7 +9307,7 @@ int DigField(struct PlayerInfo *player,
        {
          int xx, yy;
 
-         for (yy=0; yy < lev_fieldy; yy++) for (xx=0; xx < lev_fieldx; xx++)
+         for (yy = 0; yy < lev_fieldy; yy++) for (xx=0; xx < lev_fieldx; xx++)
          {
            if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
              Bang(xx, yy);
@@ -8255,7 +9330,7 @@ int DigField(struct PlayerInfo *player,
          ToggleLightSwitch(x, y);
 
 #if 0
-         PlaySoundLevel(x, y, element == EL_LIGHT_SWITCH ?
+         PlayLevelSound(x, y, element == EL_LIGHT_SWITCH ?
                         SND_LIGHT_SWITCH_ACTIVATING :
                         SND_LIGHT_SWITCH_DEACTIVATING);
 #endif
@@ -8371,18 +9446,30 @@ boolean SnapField(struct PlayerInfo *player, int dx, int dy)
 
   player->MovDir = snap_direction;
 
-  player->is_moving = FALSE;
-  player->is_digging = FALSE;
-  player->is_collecting = FALSE;
+#if 1
+  if (player->MovPos == 0)
+#endif
+  {
+    player->is_moving = FALSE;
+    player->is_digging = FALSE;
+    player->is_collecting = FALSE;
+  }
+
+  player->is_dropping = FALSE;
 
   if (DigField(player, x, y, 0, 0, DF_SNAP) == MF_NO_ACTION)
     return FALSE;
 
   player->is_snapping = TRUE;
 
-  player->is_moving = FALSE;
-  player->is_digging = FALSE;
-  player->is_collecting = FALSE;
+#if 1
+  if (player->MovPos == 0)
+#endif
+  {
+    player->is_moving = FALSE;
+    player->is_digging = FALSE;
+    player->is_collecting = FALSE;
+  }
 
   DrawLevelField(x, y);
   BackToFront();
@@ -8393,13 +9480,13 @@ boolean SnapField(struct PlayerInfo *player, int dx, int dy)
 boolean DropElement(struct PlayerInfo *player)
 {
   int jx = player->jx, jy = player->jy;
-  int old_element;
+  int old_element = Feld[jx][jy];
+  int new_element;
 
-  if (!player->active || player->MovPos)
+  /* check if player is active, not moving and ready to drop */
+  if (!player->active || player->MovPos || player->drop_delay > 0)
     return FALSE;
 
-  old_element = Feld[jx][jy];
-
   /* check if player has anything that can be dropped */
   if (player->inventory_size == 0 && player->dynabombs_left == 0)
     return FALSE;
@@ -8417,18 +9504,20 @@ boolean DropElement(struct PlayerInfo *player)
   if (old_element != EL_EMPTY)
     Back[jx][jy] = old_element;                /* store old element on this field */
 
-  MovDelay[jx][jy] = 96;
-
   ResetGfxAnimation(jx, jy);
   ResetRandomAnimationValue(jx, jy);
 
   if (player->inventory_size > 0)
   {
-    int new_element = player->inventory_element[--player->inventory_size];
+    player->inventory_size--;
+    new_element = player->inventory_element[player->inventory_size];
+
+    if (new_element == EL_DYNAMITE)
+      new_element = EL_DYNAMITE_ACTIVE;
+    else if (new_element == EL_SP_DISK_RED)
+      new_element = EL_SP_DISK_RED_ACTIVE;
 
-    Feld[jx][jy] = (new_element == EL_DYNAMITE ? EL_DYNAMITE_ACTIVE :
-                   new_element == EL_SP_DISK_RED ? EL_SP_DISK_RED_ACTIVE :
-                   new_element);
+    Feld[jx][jy] = new_element;
 
     DrawText(DX_DYNAMITE, DY_DYNAMITE,
             int2str(local_player->inventory_size, 3), FONT_TEXT_2);
@@ -8436,7 +9525,12 @@ boolean DropElement(struct PlayerInfo *player)
     if (IN_SCR_FIELD(SCREENX(jx), SCREENY(jy)))
       DrawGraphicThruMask(SCREENX(jx), SCREENY(jy), el2img(Feld[jx][jy]), 0);
 
-    PlaySoundLevelAction(jx, jy, ACTION_DROPPING);
+    PlayLevelSoundAction(jx, jy, ACTION_DROPPING);
+
+#if 1
+    /* needed if previous element just changed to "empty" in the last frame */
+    Changed[jx][jy] = 0;               /* allow another change */
+#endif
 
     CheckTriggeredElementChange(jx, jy, new_element, CE_OTHER_GETS_DROPPED);
     CheckElementChange(jx, jy, new_element, CE_DROPPED_BY_PLAYER);
@@ -8446,16 +9540,77 @@ boolean DropElement(struct PlayerInfo *player)
   else         /* player is dropping a dyna bomb */
   {
     player->dynabombs_left--;
+    new_element = EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr;
 
-    Feld[jx][jy] =
-      EL_DYNABOMB_PLAYER_1_ACTIVE + (player->element_nr - EL_PLAYER_1);
+    Feld[jx][jy] = new_element;
 
     if (IN_SCR_FIELD(SCREENX(jx), SCREENY(jy)))
       DrawGraphicThruMask(SCREENX(jx), SCREENY(jy), el2img(Feld[jx][jy]), 0);
 
-    PlaySoundLevelAction(jx, jy, ACTION_DROPPING);
+    PlayLevelSoundAction(jx, jy, ACTION_DROPPING);
   }
 
+
+
+#if 1
+
+  if (Feld[jx][jy] == new_element)     /* uninitialized unless CE change */
+  {
+    InitField(jx, jy, FALSE);
+    if (CAN_MOVE(Feld[jx][jy]))
+      InitMovDir(jx, jy);
+  }
+
+  new_element = Feld[jx][jy];
+
+  if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
+      element_info[new_element].move_pattern == MV_WHEN_DROPPED)
+  {
+    int move_stepsize = element_info[new_element].move_stepsize;
+    int direction, dx, dy, nextx, nexty;
+
+    if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
+      MovDir[jx][jy] = player->MovDir;
+
+    direction = MovDir[jx][jy];
+    dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
+    dy = (direction == MV_UP   ? -1 : direction == MV_DOWN  ? +1 : 0);
+    nextx = jx + dx;
+    nexty = jy + dy;
+
+    if (IN_LEV_FIELD(nextx, nexty) && IS_FREE(nextx, nexty))
+    {
+#if 0
+      WasJustMoving[jx][jy] = 3;
+#else
+      InitMovingField(jx, jy, direction);
+      ContinueMoving(jx, jy);
+#endif
+    }
+    else
+    {
+      Changed[jx][jy] = 0;             /* allow another change */
+
+#if 1
+      TestIfElementHitsCustomElement(jx, jy, direction);
+#else
+      CheckElementSideChange(jx, jy, new_element,
+                            direction, CE_HITTING_SOMETHING, -1);
+#endif
+    }
+
+    player->drop_delay = 2 * TILEX / move_stepsize + 1;
+  }
+
+#if 0
+  player->drop_delay = 8 + 8 + 8;
+#endif
+
+#endif
+
+  player->is_dropping = TRUE;
+
+
   return TRUE;
 }
 
@@ -8466,21 +9621,18 @@ boolean DropElement(struct PlayerInfo *player)
 static int *loop_sound_frame = NULL;
 static int *loop_sound_volume = NULL;
 
-void InitPlaySoundLevel()
+void InitPlayLevelSound()
 {
   int num_sounds = getSoundListSize();
 
-  if (loop_sound_frame != NULL)
-    free(loop_sound_frame);
+  checked_free(loop_sound_frame);
+  checked_free(loop_sound_volume);
 
-  if (loop_sound_volume != NULL)
-    free(loop_sound_volume);
-
-  loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
+  loop_sound_frame  = checked_calloc(num_sounds * sizeof(int));
   loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
 }
 
-static void PlaySoundLevel(int x, int y, int nr)
+static void PlayLevelSound(int x, int y, int nr)
 {
   int sx = SCREENX(x), sy = SCREENY(y);
   int volume, stereo_position;
@@ -8525,42 +9677,59 @@ static void PlaySoundLevel(int x, int y, int nr)
   PlaySoundExt(nr, volume, stereo_position, type);
 }
 
-static void PlaySoundLevelNearest(int x, int y, int sound_action)
+static void PlayLevelSoundNearest(int x, int y, int sound_action)
 {
-  PlaySoundLevel(x < LEVELX(BX1) ? LEVELX(BX1) :
+  PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
                 x > LEVELX(BX2) ? LEVELX(BX2) : x,
                 y < LEVELY(BY1) ? LEVELY(BY1) :
                 y > LEVELY(BY2) ? LEVELY(BY2) : y,
                 sound_action);
 }
 
-static void PlaySoundLevelAction(int x, int y, int action)
+static void PlayLevelSoundAction(int x, int y, int action)
 {
-  PlaySoundLevelElementAction(x, y, Feld[x][y], action);
+  PlayLevelSoundElementAction(x, y, Feld[x][y], action);
 }
 
-static void PlaySoundLevelElementAction(int x, int y, int element, int action)
+static void PlayLevelSoundElementAction(int x, int y, int element, int action)
 {
   int sound_effect = element_info[element].sound[action];
 
   if (sound_effect != SND_UNDEFINED)
-    PlaySoundLevel(x, y, sound_effect);
+    PlayLevelSound(x, y, sound_effect);
 }
 
-static void PlaySoundLevelActionIfLoop(int x, int y, int action)
+static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
+                                             int action)
+{
+  int sound_effect = element_info[element].sound[action];
+
+  if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
+    PlayLevelSound(x, y, sound_effect);
+}
+
+static void PlayLevelSoundActionIfLoop(int x, int y, int action)
 {
   int sound_effect = element_info[Feld[x][y]].sound[action];
 
   if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
-    PlaySoundLevel(x, y, sound_effect);
+    PlayLevelSound(x, y, sound_effect);
 }
 
-static void StopSoundLevelActionIfLoop(int x, int y, int action)
+static void StopLevelSoundActionIfLoop(int x, int y, int action)
 {
   int sound_effect = element_info[Feld[x][y]].sound[action];
 
   if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
-    StopSoundExt(sound_effect, SND_CTRL_STOP_SOUND);
+    StopSound(sound_effect);
+}
+
+static void PlayLevelMusic()
+{
+  if (levelset.music[level_nr] != MUS_UNDEFINED)
+    PlayMusic(levelset.music[level_nr]);       /* from config file */
+  else
+    PlayMusic(MAP_NOCONF_MUSIC(level_nr));     /* from music dir */
 }
 
 void RaiseScore(int value)
@@ -8724,7 +9893,7 @@ void CreateGameButtons()
 {
   int i;
 
-  for (i=0; i<NUM_GAME_BUTTONS; i++)
+  for (i = 0; i < NUM_GAME_BUTTONS; i++)
   {
     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
     struct GadgetInfo *gi;
@@ -8790,7 +9959,7 @@ void FreeGameButtons()
 {
   int i;
 
-  for (i=0; i<NUM_GAME_BUTTONS; i++)
+  for (i = 0; i < NUM_GAME_BUTTONS; i++)
     FreeGadget(game_gadget[i]);
 }
 
@@ -8798,7 +9967,7 @@ static void MapGameButtons()
 {
   int i;
 
-  for (i=0; i<NUM_GAME_BUTTONS; i++)
+  for (i = 0; i < NUM_GAME_BUTTONS; i++)
     MapGadget(game_gadget[i]);
 }
 
@@ -8806,7 +9975,7 @@ void UnmapGameButtons()
 {
   int i;
 
-  for (i=0; i<NUM_GAME_BUTTONS; i++)
+  for (i = 0; i < NUM_GAME_BUTTONS; i++)
     UnmapGadget(game_gadget[i]);
 }
 
@@ -8863,7 +10032,8 @@ static void HandleGameButtons(struct GadgetInfo *gi)
        setup.sound = setup.sound_music = TRUE;
 
        SetAudioMode(setup.sound);
-       PlayMusic(level_nr);
+
+       PlayLevelMusic();
       }
       break;