rnd-20030808-5-src
[rocksndiamonds.git] / src / game.c
index 2a63d3cea336b8d82d9a92d23525ad97cf5055a1..32311aa5f492bdf4c5e4d5a540faf6a6130c3345 100644 (file)
@@ -398,9 +398,9 @@ move_stepsize_list[] =
 struct
 {
   int element;
-  int gem_count;
+  int count;
 }
-gem_count_list[] =
+collect_count_list[] =
 {
   { EL_EMERALD,                        1 },
   { EL_BD_DIAMOND,             1 },
@@ -715,7 +715,7 @@ void DrawGameDoorValues()
   DrawText(DX + XX_EMERALDS, DY + YY_EMERALDS,
           int2str(local_player->gems_still_needed, 3), FONT_TEXT_2);
   DrawText(DX + XX_DYNAMITE, DY + YY_DYNAMITE,
-          int2str(local_player->dynamite, 3), FONT_TEXT_2);
+          int2str(local_player->inventory_size, 3), FONT_TEXT_2);
   DrawText(DX + XX_SCORE, DY + YY_SCORE,
           int2str(local_player->score, 5), FONT_TEXT_2);
   DrawText(DX + XX_TIME, DY + YY_TIME,
@@ -890,12 +890,12 @@ static void InitGameEngine()
   /* initialize gem count values for each element */
   for (i=0; i<MAX_NUM_ELEMENTS; i++)
     if (!IS_CUSTOM_ELEMENT(i))
-      element_info[i].gem_count = 0;
+      element_info[i].collect_count = 0;
 
   /* add gem count values for all elements from pre-defined list */
-  for (i=0; gem_count_list[i].element != EL_UNDEFINED; i++)
-    element_info[gem_count_list[i].element].gem_count =
-      gem_count_list[i].gem_count;
+  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;
 }
 
 
@@ -952,7 +952,6 @@ void InitGame()
     for (j=0; j<4; j++)
       player->key[j] = FALSE;
 
-    player->dynamite = 0;
     player->dynabomb_count = 0;
     player->dynabomb_size = 1;
     player->dynabombs_left = 0;
@@ -994,6 +993,8 @@ void InitGame()
     player->shield_normal_time_left = 0;
     player->shield_deadly_time_left = 0;
 
+    player->inventory_size = 0;
+
     DigField(player, 0, 0, 0, 0, DF_NO_PUSH);
     SnapField(player, 0, 0);
 
@@ -1893,7 +1894,7 @@ void Explode(int ex, int ey, int phase, int mode)
       PlaySoundLevelAction(ex, ey, ACTION_EXPLODING);
 
     /* remove things displayed in background while burning dynamite */
-    if (!IS_INDESTRUCTIBLE(Back[ex][ey]))
+    if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
       Back[ex][ey] = 0;
 
     if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
@@ -1906,6 +1907,8 @@ void Explode(int ex, int ey, int phase, int mode)
 
     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;
       int element;
 
       if (!IN_LEV_FIELD(x, y) ||
@@ -1924,8 +1927,17 @@ void Explode(int ex, int ey, int phase, int mode)
       }
 
 #if 1
+
+#if 0
       if (IS_EXPLOSION_PROOF(element))
        continue;
+#else
+      /* indestructible elements can only explode in center (but not flames) */
+      if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey)) ||
+         element == EL_FLAMES)
+       continue;
+#endif
+
 #else
       if ((IS_INDESTRUCTIBLE(element) &&
           (game.engine_version < VERSION_IDENT(2,2,0) ||
@@ -1947,8 +1959,13 @@ void Explode(int ex, int ey, int phase, int mode)
       }
 
       /* save walkable background elements while explosion on same tile */
+#if 0
       if (IS_INDESTRUCTIBLE(element))
        Back[x][y] = element;
+#else
+      if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element))
+       Back[x][y] = element;
+#endif
 
       /* ignite explodable elements reached by other explosion */
       if (element == EL_EXPLOSION)
@@ -2002,11 +2019,10 @@ void Explode(int ex, int ey, int phase, int mode)
       else if (center_element == EL_AMOEBA_TO_DIAMOND)
        Store[x][y] = level.amoeba_content;
       else if (center_element == EL_YAMYAM)
-       Store[x][y] =
-         level.yamyam_content[game.yamyam_content_nr][x - ex + 1][y - ey + 1];
-      else if (IS_CUSTOM_ELEMENT(center_element))
-       Store[x][y] =
-         element_info[center_element].content[x - ex + 1][y - ey + 1];
+       Store[x][y] = level.yamyam_content[game.yamyam_content_nr][xx][yy];
+      else if (IS_CUSTOM_ELEMENT(center_element) &&
+              element_info[center_element].content[xx][yy] != EL_EMPTY)
+       Store[x][y] = element_info[center_element].content[xx][yy];
       else if (element == EL_WALL_EMERALD)
        Store[x][y] = EL_EMERALD;
       else if (element == EL_WALL_DIAMOND)
@@ -2023,6 +2039,8 @@ void Explode(int ex, int ey, int phase, int mode)
        Store[x][y] = EL_PEARL;
       else if (element == EL_WALL_CRYSTAL)
        Store[x][y] = EL_CRYSTAL;
+      else if (IS_CUSTOM_ELEMENT(element) && !CAN_EXPLODE(element))
+       Store[x][y] = element_info[element].content[1][1];
       else
        Store[x][y] = EL_EMPTY;
 
@@ -2119,6 +2137,9 @@ void Explode(int ex, int ey, int phase, int mode)
       InitMovDir(x, y);
     DrawLevelField(x, y);
 
+    if (CAN_BE_CRUMBLED(element))
+      DrawLevelFieldCrumbledSandNeighbours(x, y);
+
     if (IS_PLAYER(x, y) && !PLAYERINFO(x,y)->present)
       StorePlayer[x][y] = 0;
   }
@@ -2195,6 +2216,7 @@ void DynaExplode(int ex, int ey)
 
       Explode(x, y, EX_PHASE_START, EX_BORDER);
 
+      /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
       if (element != EL_EMPTY &&
          element != EL_SAND &&
          element != EL_EXPLOSION &&
@@ -2505,14 +2527,16 @@ static int getInvisibleActiveFromInvisibleElement(int element)
 {
   return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
          element == EL_INVISIBLE_WALL      ? EL_INVISIBLE_WALL_ACTIVE :
-         EL_INVISIBLE_SAND_ACTIVE);
+         element == EL_INVISIBLE_SAND      ? EL_INVISIBLE_SAND_ACTIVE :
+         element);
 }
 
 static int getInvisibleFromInvisibleActiveElement(int element)
 {
   return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
          element == EL_INVISIBLE_WALL_ACTIVE      ? EL_INVISIBLE_WALL :
-         EL_INVISIBLE_SAND);
+         element == EL_INVISIBLE_SAND_ACTIVE      ? EL_INVISIBLE_SAND :
+         element);
 }
 
 static void RedrawAllLightSwitchesAndInvisibleElements()
@@ -2660,7 +2684,9 @@ void Impact(int x, int y)
     return;
   }
 
-  if (impact)
+  /* only reset graphic animation if graphic really changes after impact */
+  if (impact &&
+      el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
   {
     ResetGfxAnimation(x, y);
     DrawLevelField(x, y);
@@ -2678,7 +2704,7 @@ void Impact(int x, int y)
     return;
   }
 #if 1
-  else if (impact && CheckElementChange(x, y, element, ACTION_IMPACT))
+  else if (impact && CheckElementChange(x, y, element, CE_IMPACT))
   {
     PlaySoundLevelElementAction(x, y, element, ACTION_IMPACT);
 
@@ -3426,7 +3452,9 @@ void StartMoving(int x, int y)
   if (Stop[x][y])
     return;
 
-  GfxAction[x][y] = ACTION_DEFAULT;
+  /* !!! this should be handled more generic (not only for mole) !!! */
+  if (element != EL_MOLE && GfxAction[x][y] != ACTION_DIGGING)
+    GfxAction[x][y] = ACTION_DEFAULT;
 
   if (CAN_FALL(element) && y < lev_fieldy - 1)
   {
@@ -3821,7 +3849,10 @@ void StartMoving(int x, int y)
        return;
       }
 
-      GfxAction[x][y] = ACTION_MOVING;
+      /* special case of "moving" animation of waiting elements (FIX THIS !!!);
+        for all other elements GfxAction will be set by InitMovingField() */
+      if (element == EL_BD_BUTTERFLY || element == EL_BD_FIREFLY)
+       GfxAction[x][y] = ACTION_MOVING;
     }
 
     /* now make next step */
@@ -4005,6 +4036,11 @@ void StartMoving(int x, int y)
       {
        Feld[newx][newy] = EL_AMOEBA_SHRINKING;
        PlaySoundLevel(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 */
       }
@@ -4029,7 +4065,8 @@ void StartMoving(int x, int y)
       TurnRound(x, y);
 
 #if 1
-      DrawLevelElementAnimation(x, y, element);
+      if (GFX_ELEMENT(element) != EL_SAND)     /* !!! FIX THIS (crumble) !!! */
+       DrawLevelElementAnimation(x, y, element);
 #else
       if (element == EL_BUG ||
          element == EL_SPACESHIP ||
@@ -4523,6 +4560,7 @@ void AmoebeAbleger(int ax, int ay)
     if (!IN_LEV_FIELD(x, y))
       return;
 
+    /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
     if (IS_FREE(x, y) ||
        Feld[x][y] == EL_SAND || Feld[x][y] == EL_QUICKSAND_EMPTY)
     {
@@ -4547,6 +4585,7 @@ void AmoebeAbleger(int ax, int ay)
       if (!IN_LEV_FIELD(x, y))
        continue;
 
+      /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
       if (IS_FREE(x, y) ||
          Feld[x][y] == EL_SAND || Feld[x][y] == EL_QUICKSAND_EMPTY)
       {
@@ -4691,6 +4730,7 @@ void Life(int ax, int ay)
        changed = TRUE;
       }
     }
+    /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
     else if (IS_FREE(xx, yy) || Feld[xx][yy] == EL_SAND)
     {                                  /* free border field */
       if (nachbarn >= life[2] && nachbarn <= life[3])
@@ -5108,11 +5148,13 @@ static void ChangeActiveTrap(int x, int y)
 
 static void ChangeElementNowExt(int x, int y, int target_element)
 {
+#if 0  /* !!! let the player exacpe from a suddenly unaccessible element */
   if (IS_PLAYER(x, y) && !IS_ACCESSIBLE(target_element))
   {
     Bang(x, y);
     return;
   }
+#endif
 
   RemoveField(x, y);
   Feld[x][y] = target_element;
@@ -5202,8 +5244,10 @@ static void ChangeElementNow(int x, int y, int element)
 
     if (!change->only_complete || complete_change)
     {
+      boolean something_has_changed = FALSE;
+
       if (change->only_complete && change->use_random_change &&
-         RND(change->random) != 0)
+         RND(100) < change->random)
        return;
 
       for (yy = 0; yy < 3; yy++) for(xx = 0; xx < 3 ; xx++)
@@ -5212,24 +5256,31 @@ static void ChangeElementNow(int x, int y, int element)
        int ey = y + yy - 1;
 
        if (can_change[xx][yy] && (!change->use_random_change ||
-                                  RND(change->random) == 0))
+                                  RND(100) < change->random))
        {
          if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
            RemoveMovingField(ex, ey);
 
          ChangeElementNowExt(ex, ey, change->content[xx][yy]);
 
+         something_has_changed = TRUE;
+
          /* for symmetry reasons, stop newly created border elements */
          if (ex != x || ey != y)
            Stop[ex][ey] = TRUE;
        }
       }
 
-      return;
+      if (something_has_changed)
+       PlaySoundLevelElementAction(x, y, element, ACTION_CHANGING);
     }
   }
+  else
+  {
+    ChangeElementNowExt(x, y, change->target_element);
 
-  ChangeElementNowExt(x, y, change->target_element);
+    PlaySoundLevelElementAction(x, y, element, ACTION_CHANGING);
+  }
 }
 
 static void ChangeElement(int x, int y)
@@ -5368,7 +5419,7 @@ static void PlayerActions(struct PlayerInfo *player, byte player_action)
 {
   static byte stored_player_action[MAX_PLAYERS];
   static int num_stored_actions = 0;
-  boolean moved = FALSE, snapped = FALSE, bombed = FALSE;
+  boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
   int left     = player_action & JOY_LEFT;
   int right    = player_action & JOY_RIGHT;
   int up       = player_action & JOY_UP;
@@ -5391,13 +5442,14 @@ static void PlayerActions(struct PlayerInfo *player, byte player_action)
     else
     {
       if (button2)
-       bombed = PlaceBomb(player);
+       dropped = DropElement(player);
+
       moved = MoveFigure(player, dx, dy);
     }
 
     if (tape.single_step && tape.recording && !tape.pausing)
     {
-      if (button1 || (bombed && !moved))
+      if (button1 || (dropped && !moved))
       {
        TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
        SnapField(player, 0, 0);                /* stop snapping */
@@ -5562,6 +5614,16 @@ void GameActions()
 
     GfxFrame[x][y]++;
 
+#if 1
+    /* reset finished pushing action (not done in ContinueMoving() to allow
+       continous pushing animation for elements without push delay) */
+    if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
+    {
+      ResetGfxAnimation(x, y);
+      DrawLevelField(x, y);
+    }
+#endif
+
 #if DEBUG
     if (IS_BLOCKED(x, y))
     {
@@ -5635,9 +5697,10 @@ void GameActions()
 #if 1
       graphic = el_act_dir2img(element, GfxAction[x][y], MovDir[x][y]);
 #if 0
-      if (element == EL_PACMAN)
-       printf("::: %d, %d, %d\n",
-              IS_ANIMATED(graphic), IS_MOVING(x, y), Stop[x][y]);
+      if (element == EL_MOLE)
+       printf("::: %d, %d, %d [%d]\n",
+              IS_ANIMATED(graphic), IS_MOVING(x, y), Stop[x][y],
+              GfxAction[x][y]);
 #endif
 #if 0
       if (element == EL_YAMYAM)
@@ -5653,7 +5716,7 @@ void GameActions()
        DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
 
 #if 0
-       if (element == EL_YAMYAM)
+       if (element == EL_MOLE)
          printf("::: %d, %d\n", graphic, GfxFrame[x][y]);
 #endif
       }
@@ -5760,6 +5823,7 @@ void GameActions()
 #endif
       element = Feld[x][y];
 
+      /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
       if (!IS_PLAYER(x,y) &&
          (element == EL_EMPTY ||
           element == EL_SAND ||
@@ -6047,6 +6111,7 @@ static void CheckGravityMovement(struct PlayerInfo *player)
       (IN_LEV_FIELD(new_jx, new_jy) &&
        (Feld[new_jx][new_jy] == EL_SP_BASE ||
        Feld[new_jx][new_jy] == EL_SAND));
+    /* !!! extend EL_SAND to anything diggable !!! */
 
     if (field_under_player_is_free &&
        !player_is_moving_to_valid_field &&
@@ -6317,7 +6382,9 @@ void ScrollFigure(struct PlayerInfo *player, int mode)
     if (Feld[last_jx][last_jy] == EL_EMPTY)
       Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
 
+#if 0
     DrawPlayer(player);
+#endif
     return;
   }
   else if (!FrameReached(&player->actual_frame_counter, 1))
@@ -6333,7 +6400,9 @@ void ScrollFigure(struct PlayerInfo *player, int mode)
   if (player->MovPos == 0)
     CheckGravityMovement(player);
 
-  DrawPlayer(player);
+#if 0
+  DrawPlayer(player);  /* needed here only to cleanup last field */
+#endif
 
   if (player->MovPos == 0)
   {
@@ -6395,6 +6464,7 @@ void ScrollScreen(struct PlayerInfo *player, int mode)
 
 void TestIfPlayerTouchesCustomElement(int x, int y)
 {
+  static boolean check_changing = FALSE;
   static int xy[4][2] =
   {
     { 0, -1 },
@@ -6402,9 +6472,13 @@ void TestIfPlayerTouchesCustomElement(int x, int y)
     { +1, 0 },
     { 0, +1 }
   };
-  boolean center_is_player = (IS_PLAYER(x, y));
   int i;
 
+  if (check_changing)  /* prevent this function from running into a loop */
+    return;
+
+  check_changing = TRUE;
+
   for (i=0; i<4; i++)
   {
     int xx = x + xy[i][0];
@@ -6413,7 +6487,7 @@ void TestIfPlayerTouchesCustomElement(int x, int y)
     if (!IN_LEV_FIELD(xx, yy))
       continue;
 
-    if (center_is_player)
+    if (IS_PLAYER(x, y))
     {
       CheckTriggeredElementChange(xx, yy, Feld[xx][yy], CE_OTHER_GETS_TOUCHED);
       CheckElementChange(xx, yy, Feld[xx][yy], CE_TOUCHED_BY_PLAYER);
@@ -6426,10 +6500,13 @@ void TestIfPlayerTouchesCustomElement(int x, int y)
       break;
     }
   }
+
+  check_changing = FALSE;
 }
 
 void TestIfElementTouchesCustomElement(int x, int y)
 {
+  static boolean check_changing = FALSE;
   static int xy[4][2] =
   {
     { 0, -1 },
@@ -6437,29 +6514,41 @@ void TestIfElementTouchesCustomElement(int x, int y)
     { +1, 0 },
     { 0, +1 }
   };
-  boolean center_is_custom = (IS_CUSTOM_ELEMENT(Feld[x][y]));
+  boolean change_center_element = FALSE;
+  int center_element = Feld[x][y];
   int i;
 
+  if (check_changing)  /* prevent this function from running into a loop */
+    return;
+
+  check_changing = TRUE;
+
   for (i=0; i<4; i++)
   {
     int xx = x + xy[i][0];
     int yy = y + xy[i][1];
+    int border_element;
 
     if (!IN_LEV_FIELD(xx, yy))
       continue;
 
-    if (center_is_custom &&
-       Feld[xx][yy] == element_info[Feld[x][y]].change.trigger_element)
-    {
-      CheckElementChange(x, y, Feld[x][y], CE_OTHER_IS_TOUCHING);
-    }
+    border_element = Feld[xx][yy];
 
-    if (IS_CUSTOM_ELEMENT(Feld[xx][yy]) &&
-       Feld[x][y] == element_info[Feld[xx][yy]].change.trigger_element)
-    {
-      CheckElementChange(xx, yy, Feld[xx][yy], CE_OTHER_IS_TOUCHING);
-    }
+    /* check for change of center element (but change it only once) */
+    if (IS_CUSTOM_ELEMENT(center_element) &&
+       border_element == element_info[center_element].change.trigger_element)
+      change_center_element = TRUE;
+
+    /* check for change of border element */
+    if (IS_CUSTOM_ELEMENT(border_element) &&
+       center_element == element_info[border_element].change.trigger_element)
+      CheckElementChange(xx, yy, border_element, CE_OTHER_IS_TOUCHING);
   }
+
+  if (change_center_element)
+    CheckElementChange(x, y, center_element, CE_OTHER_IS_TOUCHING);
+
+  check_changing = FALSE;
 }
 
 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
@@ -7000,6 +7089,12 @@ int DigField(struct PlayerInfo *player,
          !IS_FREE(nextx, nexty))
        return MF_NO_ACTION;
 
+      if (element == EL_SP_GRAVITY_PORT_LEFT ||
+         element == EL_SP_GRAVITY_PORT_RIGHT ||
+         element == EL_SP_GRAVITY_PORT_UP ||
+         element == EL_SP_GRAVITY_PORT_DOWN)
+       level.gravity = !level.gravity;
+
       /* automatically move to the next field with double speed */
       player->programmed_action = move_direction;
       DOUBLE_PLAYER_SPEED(player);
@@ -7130,8 +7225,12 @@ int DigField(struct PlayerInfo *player,
 
        if (mode != DF_SNAP)
        {
+#if 1
+         GfxElement[x][y] = GFX_ELEMENT(element);
+#else
          GfxElement[x][y] =
            (CAN_BE_CRUMBLED(element) ? EL_SAND : GFX_ELEMENT(element));
+#endif
          player->is_digging = TRUE;
        }
 
@@ -7164,11 +7263,13 @@ int DigField(struct PlayerInfo *player,
        }
        else if (element == EL_DYNAMITE || element == EL_SP_DISK_RED)
        {
-         player->dynamite++;
+         if (player->inventory_size < MAX_INVENTORY_SIZE)
+           player->inventory_element[player->inventory_size++] = element;
+
          player->use_disk_red_graphic = (element == EL_SP_DISK_RED);
 
          DrawText(DX_DYNAMITE, DY_DYNAMITE,
-                  int2str(local_player->dynamite, 3), FONT_TEXT_2);
+                  int2str(local_player->inventory_size, 3), FONT_TEXT_2);
        }
        else if (element == EL_DYNABOMB_INCREASE_NUMBER)
        {
@@ -7195,10 +7296,21 @@ int DigField(struct PlayerInfo *player,
                             el2edimg(EL_KEY_1 + key_nr));
          redraw_mask |= REDRAW_DOOR_1;
        }
-       else if (element_info[element].gem_count > 0)
+       else if (IS_DROPPABLE(element)) /* can be collected and dropped */
+       {
+         int 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;
+
+         DrawText(DX_DYNAMITE, DY_DYNAMITE,
+                  int2str(local_player->inventory_size, 3), FONT_TEXT_2);
+       }
+       else if (element_info[element].collect_count > 0)
        {
          local_player->gems_still_needed -=
-           element_info[element].gem_count;
+           element_info[element].collect_count;
          if (local_player->gems_still_needed < 0)
            local_player->gems_still_needed = 0;
 
@@ -7287,6 +7399,7 @@ int DigField(struct PlayerInfo *player,
          PlaySoundLevelElementAction(x, y, element, ACTION_PUSHING);
 
        InitMovingField(x, y, move_direction);
+       GfxAction[x][y] = ACTION_PUSHING;
 
        if (mode == DF_SNAP)
          ContinueMoving(x, y);
@@ -7373,66 +7486,68 @@ boolean SnapField(struct PlayerInfo *player, int dx, int dy)
   return TRUE;
 }
 
-boolean PlaceBomb(struct PlayerInfo *player)
+boolean DropElement(struct PlayerInfo *player)
 {
   int jx = player->jx, jy = player->jy;
-  int element;
+  int old_element;
 
   if (!player->active || player->MovPos)
     return FALSE;
 
-  element = Feld[jx][jy];
+  old_element = Feld[jx][jy];
 
-  if ((player->dynamite == 0 && player->dynabombs_left == 0) ||
-      IS_ACTIVE_BOMB(element) || element == EL_EXPLOSION)
+  /* check if player has anything that can be dropped */
+  if (player->inventory_size == 0 && player->dynabombs_left == 0)
     return FALSE;
 
-#if 0
-  if (element != EL_EMPTY)
+  /* check if anything can be dropped at the current position */
+  if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
     return FALSE;
-#endif
 
-  if (element != EL_EMPTY)
-  {
-#if 0
-    Store[jx][jy] = element;
-#else
-    Back[jx][jy] = element;
-#endif
-  }
+  /* collected custom elements can only be dropped on empty fields */
+  if (player->inventory_size > 0 &&
+      IS_CUSTOM_ELEMENT(player->inventory_element[player->inventory_size - 1])
+      && old_element != EL_EMPTY)
+    return FALSE;
+
+  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->dynamite)
+  if (player->inventory_size > 0)
   {
+    int new_element = player->inventory_element[--player->inventory_size];
+
+#if 1
+    Feld[jx][jy] = (new_element == EL_DYNAMITE ? EL_DYNAMITE_ACTIVE :
+                   new_element == EL_SP_DISK_RED ? EL_SP_DISK_RED_ACTIVE :
+                   new_element);
+#else
     Feld[jx][jy] = (player->use_disk_red_graphic ? EL_SP_DISK_RED_ACTIVE :
                    EL_DYNAMITE_ACTIVE);
-    player->dynamite--;
+#endif
+
+    DrawText(DX_DYNAMITE, DY_DYNAMITE,
+            int2str(local_player->inventory_size, 3), FONT_TEXT_2);
 
-    DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(local_player->dynamite, 3),
-            FONT_TEXT_2);
     if (IN_SCR_FIELD(SCREENX(jx), SCREENY(jy)))
-    {
-#if 1
       DrawGraphicThruMask(SCREENX(jx), SCREENY(jy), el2img(Feld[jx][jy]), 0);
-#else
-      if (game.emulation == EMU_SUPAPLEX)
-       DrawGraphic(SCREENX(jx), SCREENY(jy), IMG_SP_DISK_RED, 0);
-      else
-       DrawGraphicThruMask(SCREENX(jx), SCREENY(jy), IMG_DYNAMITE_ACTIVE, 0);
-#endif
-    }
 
     PlaySoundLevelAction(jx, jy, ACTION_DROPPING);
+
+    CheckTriggeredElementChange(jx, jy, new_element, CE_OTHER_GETS_DROPPED);
+    CheckElementChange(jx, jy, new_element, CE_DROPPED_BY_PLAYER);
   }
-  else
+  else         /* player is dropping a dyna bomb */
   {
+    player->dynabombs_left--;
+
     Feld[jx][jy] =
       EL_DYNABOMB_PLAYER_1_ACTIVE + (player->element_nr - EL_PLAYER_1);
-    player->dynabombs_left--;
 
     if (IN_SCR_FIELD(SCREENX(jx), SCREENY(jy)))
       DrawGraphicThruMask(SCREENX(jx), SCREENY(jy), el2img(Feld[jx][jy]), 0);
@@ -7618,7 +7733,7 @@ void RaiseScoreElement(int element)
       RaiseScore(level.score[SC_KEY]);
       break;
     default:
-      RaiseScore(element_info[element].score);
+      RaiseScore(element_info[element].collect_score);
       break;
   }
 }
@@ -7845,6 +7960,8 @@ static void HandleGameButtons(struct GadgetInfo *gi)
       else if (audio.music_available)
       { 
        setup.sound = setup.sound_music = TRUE;
+
+       SetAudioMode(setup.sound);
        PlayMusic(level_nr);
       }
       break;
@@ -7853,14 +7970,20 @@ static void HandleGameButtons(struct GadgetInfo *gi)
       if (setup.sound_loops)
        setup.sound_loops = FALSE;
       else if (audio.loops_available)
+      {
        setup.sound = setup.sound_loops = TRUE;
+       SetAudioMode(setup.sound);
+      }
       break;
 
     case SOUND_CTRL_ID_SIMPLE:
       if (setup.sound_simple)
        setup.sound_simple = FALSE;
       else if (audio.sound_available)
+      {
        setup.sound = setup.sound_simple = TRUE;
+       SetAudioMode(setup.sound);
+      }
       break;
 
     default: