+ else if (element == EL_DYNABOMB_INCREASE_NUMBER)
+ {
+ player->dynabomb_count++;
+ player->dynabombs_left++;
+ }
+ else if (element == EL_DYNABOMB_INCREASE_SIZE)
+ {
+ player->dynabomb_size++;
+ }
+ else if (element == EL_DYNABOMB_INCREASE_POWER)
+ {
+ player->dynabomb_xl = TRUE;
+ }
+ else if (IS_KEY(element))
+ {
+ player->key[KEY_NR(element)] = TRUE;
+
+ DrawGameDoorValues();
+ }
+ else if (element == EL_DC_KEY_WHITE)
+ {
+ player->num_white_keys++;
+
+ /* display white keys? */
+ /* DrawGameDoorValues(); */
+ }
+ else if (IS_ENVELOPE(element))
+ {
+ player->show_envelope = element;
+ }
+ else if (element == EL_EMC_LENSES)
+ {
+ game.lenses_time_left = level.lenses_time * FRAMES_PER_SECOND;
+
+ RedrawAllInvisibleElementsForLenses();
+ }
+ else if (element == EL_EMC_MAGNIFIER)
+ {
+ game.magnify_time_left = level.magnify_time * FRAMES_PER_SECOND;
+
+ RedrawAllInvisibleElementsForMagnifier();
+ }
+ else if (IS_DROPPABLE(element) ||
+ IS_THROWABLE(element)) /* can be collected and dropped */
+ {
+ int i;
+
+ if (collect_count == 0)
+ player->inventory_infinite_element = element;
+ else
+ for (i = 0; i < collect_count; i++)
+ if (player->inventory_size < MAX_INVENTORY_SIZE)
+ player->inventory_element[player->inventory_size++] = element;
+
+ DrawGameDoorValues();
+ }
+ else if (collect_count > 0)
+ {
+ local_player->gems_still_needed -= collect_count;
+ if (local_player->gems_still_needed < 0)
+ local_player->gems_still_needed = 0;
+
+ game.snapshot.collected_item = TRUE;
+
+ game_panel_controls[GAME_PANEL_GEMS].value = local_player->gems_still_needed;
+
+ DisplayGameControlValues();
+ }
+
+ RaiseScoreElement(element);
+ PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
+
+ if (is_player)
+ CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_COLLECTS_X,
+ player->index_bit, dig_side);
+
+ if (mode == DF_SNAP)
+ {
+ if (level.block_snap_field)
+ setFieldForSnapping(x, y, element, move_direction);
+ else
+ TestIfElementTouchesCustomElement(x, y); /* for empty space */
+
+ CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
+ player->index_bit, dig_side);
+ }
+ }
+ else if (player_can_move_or_snap && IS_PUSHABLE(element))
+ {
+ if (mode == DF_SNAP && element != EL_BD_ROCK)
+ return MP_NO_ACTION;
+
+ if (CAN_FALL(element) && dy)
+ return MP_NO_ACTION;
+
+ if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
+ !(element == EL_SPRING && level.use_spring_bug))
+ return MP_NO_ACTION;
+
+ if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
+ ((move_direction & MV_VERTICAL &&
+ ((element_info[element].move_pattern & MV_LEFT &&
+ IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
+ (element_info[element].move_pattern & MV_RIGHT &&
+ IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
+ (move_direction & MV_HORIZONTAL &&
+ ((element_info[element].move_pattern & MV_UP &&
+ IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
+ (element_info[element].move_pattern & MV_DOWN &&
+ IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
+ return MP_NO_ACTION;
+
+ /* do not push elements already moving away faster than player */
+ if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
+ ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
+ return MP_NO_ACTION;
+
+ if (game.engine_version >= VERSION_IDENT(3,1,0,0))
+ {
+ if (player->push_delay_value == -1 || !player_was_pushing)
+ player->push_delay_value = GET_NEW_PUSH_DELAY(element);
+ }
+ else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
+ {
+ if (player->push_delay_value == -1)
+ player->push_delay_value = GET_NEW_PUSH_DELAY(element);
+ }
+ else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
+ {
+ if (!player->is_pushing)
+ player->push_delay_value = GET_NEW_PUSH_DELAY(element);
+ }
+
+ player->is_pushing = TRUE;
+ player->is_active = TRUE;
+
+ if (!(IN_LEV_FIELD(nextx, nexty) &&
+ (IS_FREE(nextx, nexty) ||
+ (IS_SB_ELEMENT(element) &&
+ Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY) ||
+ (IS_CUSTOM_ELEMENT(element) &&
+ CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, nextx, nexty)))))
+ return MP_NO_ACTION;
+
+ if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
+ return MP_NO_ACTION;
+
+ if (player->push_delay == -1) /* new pushing; restart delay */
+ player->push_delay = 0;
+
+ if (player->push_delay < player->push_delay_value &&
+ !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
+ element != EL_SPRING && element != EL_BALLOON)
+ {
+ /* make sure that there is no move delay before next try to push */
+ if (game.engine_version >= VERSION_IDENT(3,0,7,1))
+ player->move_delay = 0;
+
+ return MP_NO_ACTION;
+ }
+
+ if (IS_CUSTOM_ELEMENT(element) &&
+ CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, nextx, nexty))
+ {
+ if (!DigFieldByCE(nextx, nexty, element))
+ return MP_NO_ACTION;
+ }
+
+ if (IS_SB_ELEMENT(element))
+ {
+ if (element == EL_SOKOBAN_FIELD_FULL)
+ {
+ Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
+ local_player->sokobanfields_still_needed++;
+ }
+
+ if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
+ {
+ Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
+ local_player->sokobanfields_still_needed--;
+ }
+
+ Feld[x][y] = EL_SOKOBAN_OBJECT;
+
+ if (Back[x][y] == Back[nextx][nexty])
+ PlayLevelSoundAction(x, y, ACTION_PUSHING);
+ else if (Back[x][y] != 0)
+ PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
+ ACTION_EMPTYING);
+ else
+ PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
+ ACTION_FILLING);
+
+ if (local_player->sokobanfields_still_needed == 0 &&
+ (game.emulation == EMU_SOKOBAN || level.auto_exit_sokoban))
+ {
+ PlayerWins(player);
+
+ PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
+ }
+ }
+ else
+ PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
+
+ InitMovingField(x, y, move_direction);
+ GfxAction[x][y] = ACTION_PUSHING;
+
+ if (mode == DF_SNAP)
+ ContinueMoving(x, y);
+ else
+ MovPos[x][y] = (dx != 0 ? dx : dy);
+
+ Pushed[x][y] = TRUE;
+ Pushed[nextx][nexty] = TRUE;
+
+ if (game.engine_version < VERSION_IDENT(2,2,0,7))
+ player->push_delay_value = GET_NEW_PUSH_DELAY(element);
+ else
+ player->push_delay_value = -1; /* get new value later */
+
+ /* check for element change _after_ element has been pushed */
+ if (game.use_change_when_pushing_bug)
+ {
+ CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
+ player->index_bit, dig_side);
+ CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PUSHES_X,
+ player->index_bit, dig_side);
+ }
+ }
+ else if (IS_SWITCHABLE(element))
+ {
+ if (PLAYER_SWITCHING(player, x, y))
+ {
+ CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
+ player->index_bit, dig_side);
+
+ return MP_ACTION;
+ }
+
+ player->is_switching = TRUE;
+ player->switch_x = x;
+ player->switch_y = y;
+
+ PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
+
+ if (element == EL_ROBOT_WHEEL)
+ {
+ Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
+ ZX = x;
+ ZY = y;
+
+ game.robot_wheel_active = TRUE;
+
+ TEST_DrawLevelField(x, y);
+ }
+ else if (element == EL_SP_TERMINAL)
+ {
+ int xx, yy;
+
+ SCAN_PLAYFIELD(xx, yy)
+ {
+ if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
+ {
+ Bang(xx, yy);
+ }
+ else if (Feld[xx][yy] == EL_SP_TERMINAL)
+ {
+ Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
+
+ ResetGfxAnimation(xx, yy);
+ TEST_DrawLevelField(xx, yy);
+ }
+ }
+ }
+ else if (IS_BELT_SWITCH(element))
+ {
+ ToggleBeltSwitch(x, y);
+ }
+ else if (element == EL_SWITCHGATE_SWITCH_UP ||
+ element == EL_SWITCHGATE_SWITCH_DOWN ||
+ element == EL_DC_SWITCHGATE_SWITCH_UP ||
+ element == EL_DC_SWITCHGATE_SWITCH_DOWN)
+ {
+ ToggleSwitchgateSwitch(x, y);
+ }
+ else if (element == EL_LIGHT_SWITCH ||
+ element == EL_LIGHT_SWITCH_ACTIVE)
+ {
+ ToggleLightSwitch(x, y);
+ }
+ else if (element == EL_TIMEGATE_SWITCH ||
+ element == EL_DC_TIMEGATE_SWITCH)
+ {
+ ActivateTimegateSwitch(x, y);
+ }
+ else if (element == EL_BALLOON_SWITCH_LEFT ||
+ element == EL_BALLOON_SWITCH_RIGHT ||
+ element == EL_BALLOON_SWITCH_UP ||
+ element == EL_BALLOON_SWITCH_DOWN ||
+ element == EL_BALLOON_SWITCH_NONE ||
+ element == EL_BALLOON_SWITCH_ANY)
+ {
+ game.wind_direction = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
+ element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
+ element == EL_BALLOON_SWITCH_UP ? MV_UP :
+ element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
+ element == EL_BALLOON_SWITCH_NONE ? MV_NONE :
+ move_direction);
+ }
+ else if (element == EL_LAMP)
+ {
+ Feld[x][y] = EL_LAMP_ACTIVE;
+ local_player->lights_still_needed--;
+
+ ResetGfxAnimation(x, y);
+ TEST_DrawLevelField(x, y);
+ }
+ else if (element == EL_TIME_ORB_FULL)
+ {
+ Feld[x][y] = EL_TIME_ORB_EMPTY;
+
+ if (level.time > 0 || level.use_time_orb_bug)
+ {
+ TimeLeft += level.time_orb_time;
+ game.no_time_limit = FALSE;
+
+ game_panel_controls[GAME_PANEL_TIME].value = TimeLeft;
+
+ DisplayGameControlValues();
+ }
+
+ ResetGfxAnimation(x, y);
+ TEST_DrawLevelField(x, y);
+ }
+ else if (element == EL_EMC_MAGIC_BALL_SWITCH ||
+ element == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
+ {
+ int xx, yy;
+
+ game.ball_state = !game.ball_state;
+
+ SCAN_PLAYFIELD(xx, yy)
+ {
+ int e = Feld[xx][yy];
+
+ if (game.ball_state)
+ {
+ if (e == EL_EMC_MAGIC_BALL)
+ CreateField(xx, yy, EL_EMC_MAGIC_BALL_ACTIVE);
+ else if (e == EL_EMC_MAGIC_BALL_SWITCH)
+ CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH_ACTIVE);
+ }
+ else
+ {
+ if (e == EL_EMC_MAGIC_BALL_ACTIVE)
+ CreateField(xx, yy, EL_EMC_MAGIC_BALL);
+ else if (e == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
+ CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH);
+ }
+ }
+ }
+
+ CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
+ player->index_bit, dig_side);
+
+ CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
+ player->index_bit, dig_side);
+
+ CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
+ player->index_bit, dig_side);
+
+ return MP_ACTION;
+ }
+ else
+ {
+ if (!PLAYER_SWITCHING(player, x, y))
+ {
+ player->is_switching = TRUE;
+ player->switch_x = x;
+ player->switch_y = y;
+
+ CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
+ player->index_bit, dig_side);
+ CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
+ player->index_bit, dig_side);
+
+ CheckElementChangeByPlayer(x, y, element, CE_SWITCHED_BY_PLAYER,
+ player->index_bit, dig_side);
+ CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
+ player->index_bit, dig_side);
+ }
+
+ CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
+ player->index_bit, dig_side);
+ CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
+ player->index_bit, dig_side);
+
+ return MP_NO_ACTION;
+ }
+
+ player->push_delay = -1;
+
+ if (is_player) /* function can also be called by EL_PENGUIN */
+ {
+ if (Feld[x][y] != element) /* really digged/collected something */
+ {
+ player->is_collecting = !player->is_digging;
+ player->is_active = TRUE;
+ }
+ }
+
+ return MP_MOVING;
+}
+
+static boolean DigFieldByCE(int x, int y, int digging_element)
+{
+ int element = Feld[x][y];
+
+ if (!IS_FREE(x, y))
+ {
+ int action = (IS_DIGGABLE(element) ? ACTION_DIGGING :
+ IS_COLLECTIBLE(element) ? ACTION_COLLECTING :
+ ACTION_BREAKING);
+
+ /* no element can dig solid indestructible elements */
+ if (IS_INDESTRUCTIBLE(element) &&
+ !IS_DIGGABLE(element) &&
+ !IS_COLLECTIBLE(element))
+ return FALSE;
+
+ if (AmoebaNr[x][y] &&
+ (element == EL_AMOEBA_FULL ||
+ element == EL_BD_AMOEBA ||
+ element == EL_AMOEBA_GROWING))
+ {
+ AmoebaCnt[AmoebaNr[x][y]]--;
+ AmoebaCnt2[AmoebaNr[x][y]]--;
+ }
+
+ if (IS_MOVING(x, y))
+ RemoveMovingField(x, y);
+ else
+ {
+ RemoveField(x, y);
+ TEST_DrawLevelField(x, y);
+ }
+
+ /* if digged element was about to explode, prevent the explosion */
+ ExplodeField[x][y] = EX_TYPE_NONE;
+
+ PlayLevelSoundAction(x, y, action);
+ }
+
+ Store[x][y] = EL_EMPTY;
+
+ /* this makes it possible to leave the removed element again */
+ if (IS_EQUAL_OR_IN_GROUP(element, MOVE_ENTER_EL(digging_element)))
+ Store[x][y] = element;
+
+ return TRUE;
+}
+
+static boolean SnapField(struct PlayerInfo *player, int dx, int dy)
+{
+ int jx = player->jx, jy = player->jy;
+ int x = jx + dx, y = jy + dy;
+ int snap_direction = (dx == -1 ? MV_LEFT :
+ dx == +1 ? MV_RIGHT :
+ dy == -1 ? MV_UP :
+ dy == +1 ? MV_DOWN : MV_NONE);
+ boolean can_continue_snapping = (level.continuous_snapping &&
+ WasJustFalling[x][y] < CHECK_DELAY_FALLING);
+
+ if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
+ return FALSE;
+
+ if (!player->active || !IN_LEV_FIELD(x, y))
+ return FALSE;
+
+ if (dx && dy)
+ return FALSE;
+
+ if (!dx && !dy)
+ {
+ if (player->MovPos == 0)
+ player->is_pushing = FALSE;
+
+ player->is_snapping = FALSE;
+
+ if (player->MovPos == 0)
+ {
+ player->is_moving = FALSE;
+ player->is_digging = FALSE;
+ player->is_collecting = FALSE;
+ }
+
+ return FALSE;
+ }
+
+ /* prevent snapping with already pressed snap key when not allowed */
+ if (player->is_snapping && !can_continue_snapping)
+ return FALSE;
+
+ player->MovDir = snap_direction;
+
+ if (player->MovPos == 0)
+ {
+ player->is_moving = FALSE;
+ player->is_digging = FALSE;
+ player->is_collecting = FALSE;
+ }
+
+ player->is_dropping = FALSE;
+ player->is_dropping_pressed = FALSE;
+ player->drop_pressed_delay = 0;
+
+ if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MP_NO_ACTION)
+ return FALSE;
+
+ player->is_snapping = TRUE;
+ player->is_active = TRUE;
+
+ if (player->MovPos == 0)
+ {
+ player->is_moving = FALSE;
+ player->is_digging = FALSE;
+ player->is_collecting = FALSE;
+ }
+
+ if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
+ TEST_DrawLevelField(player->last_jx, player->last_jy);
+
+ TEST_DrawLevelField(x, y);
+
+ return TRUE;
+}
+
+static boolean DropElement(struct PlayerInfo *player)
+{
+ int old_element, new_element;
+ int dropx = player->jx, dropy = player->jy;
+ int drop_direction = player->MovDir;
+ int drop_side = drop_direction;
+ int drop_element = get_next_dropped_element(player);
+
+ player->is_dropping_pressed = TRUE;
+
+ /* do not drop an element on top of another element; when holding drop key
+ pressed without moving, dropped element must move away before the next
+ element can be dropped (this is especially important if the next element
+ is dynamite, which can be placed on background for historical reasons) */
+ if (PLAYER_DROPPING(player, dropx, dropy) && Feld[dropx][dropy] != EL_EMPTY)
+ return MP_ACTION;
+
+ if (IS_THROWABLE(drop_element))
+ {
+ dropx += GET_DX_FROM_DIR(drop_direction);
+ dropy += GET_DY_FROM_DIR(drop_direction);
+
+ if (!IN_LEV_FIELD(dropx, dropy))
+ return FALSE;
+ }
+
+ old_element = Feld[dropx][dropy]; /* old element at dropping position */
+ new_element = drop_element; /* default: no change when dropping */
+
+ /* check if player is active, not moving and ready to drop */
+ if (!player->active || player->MovPos || player->drop_delay > 0)
+ return FALSE;
+
+ /* check if player has anything that can be dropped */
+ if (new_element == EL_UNDEFINED)
+ return FALSE;
+
+ /* check if drop key was pressed long enough for EM style dynamite */
+ if (new_element == EL_EM_DYNAMITE && player->drop_pressed_delay < 40)
+ return FALSE;
+
+ /* check if anything can be dropped at the current position */
+ if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
+ return FALSE;
+
+ /* collected custom elements can only be dropped on empty fields */
+ if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
+ return FALSE;
+
+ if (old_element != EL_EMPTY)
+ Back[dropx][dropy] = old_element; /* store old element on this field */
+
+ ResetGfxAnimation(dropx, dropy);
+ ResetRandomAnimationValue(dropx, dropy);
+
+ if (player->inventory_size > 0 ||
+ player->inventory_infinite_element != EL_UNDEFINED)
+ {
+ if (player->inventory_size > 0)
+ {
+ player->inventory_size--;
+
+ DrawGameDoorValues();
+
+ if (new_element == EL_DYNAMITE)
+ new_element = EL_DYNAMITE_ACTIVE;
+ else if (new_element == EL_EM_DYNAMITE)
+ new_element = EL_EM_DYNAMITE_ACTIVE;
+ else if (new_element == EL_SP_DISK_RED)
+ new_element = EL_SP_DISK_RED_ACTIVE;
+ }
+
+ Feld[dropx][dropy] = new_element;
+
+ if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
+ DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
+ el2img(Feld[dropx][dropy]), 0);
+
+ PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
+
+ /* needed if previous element just changed to "empty" in the last frame */
+ ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
+
+ CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
+ player->index_bit, drop_side);
+ CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
+ CE_PLAYER_DROPS_X,
+ player->index_bit, drop_side);
+
+ TestIfElementTouchesCustomElement(dropx, dropy);
+ }
+ else /* player is dropping a dyna bomb */
+ {
+ player->dynabombs_left--;
+
+ Feld[dropx][dropy] = new_element;
+
+ if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
+ DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
+ el2img(Feld[dropx][dropy]), 0);
+
+ PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
+ }
+
+ if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
+ InitField_WithBug1(dropx, dropy, FALSE);
+
+ new_element = Feld[dropx][dropy]; /* element might have changed */
+
+ if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
+ element_info[new_element].move_pattern == MV_WHEN_DROPPED)
+ {
+ if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
+ MovDir[dropx][dropy] = drop_direction;
+
+ ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
+
+ /* do not cause impact style collision by dropping elements that can fall */
+ CheckCollision[dropx][dropy] = CHECK_DELAY_COLLISION;
+ }
+
+ player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
+ player->is_dropping = TRUE;
+
+ player->drop_pressed_delay = 0;
+ player->is_dropping_pressed = FALSE;
+
+ player->drop_x = dropx;
+ player->drop_y = dropy;
+
+ return TRUE;
+}
+
+/* ------------------------------------------------------------------------- */
+/* game sound playing functions */
+/* ------------------------------------------------------------------------- */
+
+static int *loop_sound_frame = NULL;
+static int *loop_sound_volume = NULL;
+
+void InitPlayLevelSound()
+{
+ int num_sounds = getSoundListSize();
+
+ checked_free(loop_sound_frame);
+ checked_free(loop_sound_volume);
+
+ loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
+ loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
+}
+
+static void PlayLevelSound(int x, int y, int nr)
+{
+ int sx = SCREENX(x), sy = SCREENY(y);
+ int volume, stereo_position;
+ int max_distance = 8;
+ int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
+
+ if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
+ (!setup.sound_loops && IS_LOOP_SOUND(nr)))
+ return;
+
+ if (!IN_LEV_FIELD(x, y) ||
+ sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
+ sy < -max_distance || sy >= SCR_FIELDY + max_distance)
+ return;
+
+ volume = SOUND_MAX_VOLUME;
+
+ if (!IN_SCR_FIELD(sx, sy))
+ {
+ int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
+ int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
+
+ volume -= volume * (dx > dy ? dx : dy) / max_distance;
+ }
+
+ stereo_position = (SOUND_MAX_LEFT +
+ (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
+ (SCR_FIELDX + 2 * max_distance));
+
+ if (IS_LOOP_SOUND(nr))
+ {
+ /* This assures that quieter loop sounds do not overwrite louder ones,
+ while restarting sound volume comparison with each new game frame. */
+
+ if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
+ return;
+
+ loop_sound_volume[nr] = volume;
+ loop_sound_frame[nr] = FrameCounter;
+ }
+
+ PlaySoundExt(nr, volume, stereo_position, type);
+}
+
+static void PlayLevelSoundNearest(int x, int y, int sound_action)
+{
+ 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 PlayLevelSoundAction(int x, int y, int action)
+{
+ PlayLevelSoundElementAction(x, y, Feld[x][y], action);
+}
+
+static void PlayLevelSoundElementAction(int x, int y, int element, int action)
+{
+ int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
+
+ if (sound_effect != SND_UNDEFINED)
+ PlayLevelSound(x, y, sound_effect);
+}
+
+static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
+ int action)
+{
+ int sound_effect = element_info[SND_ELEMENT(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[SND_ELEMENT(Feld[x][y])].sound[action];
+
+ if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
+ PlayLevelSound(x, y, sound_effect);
+}
+
+static void StopLevelSoundActionIfLoop(int x, int y, int action)
+{
+ int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
+
+ if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
+ 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 PlayLevelSound_EM(int xx, int yy, int element_em, int sample)
+{
+ int element = (element_em > -1 ? map_element_EM_to_RND(element_em) : 0);
+ int offset = (BorderElement == EL_STEELWALL ? 1 : 0);
+ int x = xx - 1 - offset;
+ int y = yy - 1 - offset;
+
+ switch (sample)
+ {
+ case SAMPLE_blank:
+ PlayLevelSoundElementAction(x, y, element, ACTION_WALKING);
+ break;
+
+ case SAMPLE_roll:
+ PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
+ break;
+
+ case SAMPLE_stone:
+ PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
+ break;
+
+ case SAMPLE_nut:
+ PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
+ break;
+
+ case SAMPLE_crack:
+ PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
+ break;
+
+ case SAMPLE_bug:
+ PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
+ break;
+
+ case SAMPLE_tank:
+ PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
+ break;
+
+ case SAMPLE_android_clone:
+ PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
+ break;
+
+ case SAMPLE_android_move:
+ PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
+ break;
+
+ case SAMPLE_spring:
+ PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
+ break;
+
+ case SAMPLE_slurp:
+ PlayLevelSoundElementAction(x, y, element, ACTION_EATING);
+ break;
+
+ case SAMPLE_eater:
+ PlayLevelSoundElementAction(x, y, element, ACTION_WAITING);
+ break;
+
+ case SAMPLE_eater_eat:
+ PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
+ break;
+
+ case SAMPLE_alien:
+ PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
+ break;
+
+ case SAMPLE_collect:
+ PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
+ break;
+
+ case SAMPLE_diamond:
+ PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
+ break;
+
+ case SAMPLE_squash:
+ /* !!! CHECK THIS !!! */
+#if 1
+ PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
+#else
+ PlayLevelSoundElementAction(x, y, element, ACTION_SMASHED_BY_ROCK);
+#endif
+ break;
+
+ case SAMPLE_wonderfall:
+ PlayLevelSoundElementAction(x, y, element, ACTION_FILLING);
+ break;
+
+ case SAMPLE_drip:
+ PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
+ break;
+
+ case SAMPLE_push:
+ PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
+ break;
+
+ case SAMPLE_dirt:
+ PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
+ break;
+
+ case SAMPLE_acid:
+ PlayLevelSoundElementAction(x, y, element, ACTION_SPLASHING);
+ break;
+
+ case SAMPLE_ball:
+ PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
+ break;
+
+ case SAMPLE_grow:
+ PlayLevelSoundElementAction(x, y, element, ACTION_GROWING);
+ break;
+
+ case SAMPLE_wonder:
+ PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
+ break;
+
+ case SAMPLE_door:
+ PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
+ break;
+
+ case SAMPLE_exit_open:
+ PlayLevelSoundElementAction(x, y, element, ACTION_OPENING);
+ break;
+
+ case SAMPLE_exit_leave:
+ PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
+ break;
+
+ case SAMPLE_dynamite:
+ PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
+ break;
+
+ case SAMPLE_tick:
+ PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
+ break;
+
+ case SAMPLE_press:
+ PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
+ break;
+
+ case SAMPLE_wheel:
+ PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
+ break;
+
+ case SAMPLE_boom:
+ PlayLevelSoundElementAction(x, y, element, ACTION_EXPLODING);
+ break;
+
+ case SAMPLE_die:
+ PlayLevelSoundElementAction(x, y, element, ACTION_DYING);
+ break;
+
+ case SAMPLE_time:
+ PlaySound(SND_GAME_RUNNING_OUT_OF_TIME);
+ break;
+
+ default:
+ PlayLevelSoundElementAction(x, y, element, ACTION_DEFAULT);
+ break;
+ }
+}
+
+void PlayLevelSound_SP(int xx, int yy, int element_sp, int action_sp)
+{
+ int element = map_element_SP_to_RND(element_sp);
+ int action = map_action_SP_to_RND(action_sp);
+ int offset = (setup.sp_show_border_elements ? 0 : 1);
+ int x = xx - offset;
+ int y = yy - offset;
+
+ PlayLevelSoundElementAction(x, y, element, action);
+}
+
+void RaiseScore(int value)
+{
+ local_player->score += value;
+
+ game_panel_controls[GAME_PANEL_SCORE].value = local_player->score;
+
+ DisplayGameControlValues();
+}
+
+void RaiseScoreElement(int element)
+{
+ switch (element)
+ {
+ case EL_EMERALD:
+ case EL_BD_DIAMOND:
+ case EL_EMERALD_YELLOW:
+ case EL_EMERALD_RED:
+ case EL_EMERALD_PURPLE:
+ case EL_SP_INFOTRON:
+ RaiseScore(level.score[SC_EMERALD]);
+ break;
+ case EL_DIAMOND:
+ RaiseScore(level.score[SC_DIAMOND]);
+ break;
+ case EL_CRYSTAL:
+ RaiseScore(level.score[SC_CRYSTAL]);
+ break;
+ case EL_PEARL:
+ RaiseScore(level.score[SC_PEARL]);
+ break;
+ case EL_BUG:
+ case EL_BD_BUTTERFLY:
+ case EL_SP_ELECTRON:
+ RaiseScore(level.score[SC_BUG]);
+ break;
+ case EL_SPACESHIP:
+ case EL_BD_FIREFLY:
+ case EL_SP_SNIKSNAK:
+ RaiseScore(level.score[SC_SPACESHIP]);
+ break;
+ case EL_YAMYAM:
+ case EL_DARK_YAMYAM:
+ RaiseScore(level.score[SC_YAMYAM]);
+ break;
+ case EL_ROBOT:
+ RaiseScore(level.score[SC_ROBOT]);
+ break;
+ case EL_PACMAN:
+ RaiseScore(level.score[SC_PACMAN]);
+ break;
+ case EL_NUT:
+ RaiseScore(level.score[SC_NUT]);
+ break;
+ case EL_DYNAMITE:
+ case EL_EM_DYNAMITE:
+ case EL_SP_DISK_RED:
+ case EL_DYNABOMB_INCREASE_NUMBER:
+ case EL_DYNABOMB_INCREASE_SIZE:
+ case EL_DYNABOMB_INCREASE_POWER:
+ RaiseScore(level.score[SC_DYNAMITE]);
+ break;
+ case EL_SHIELD_NORMAL:
+ case EL_SHIELD_DEADLY:
+ RaiseScore(level.score[SC_SHIELD]);
+ break;
+ case EL_EXTRA_TIME:
+ RaiseScore(level.extra_time_score);
+ break;
+ case EL_KEY_1:
+ case EL_KEY_2:
+ case EL_KEY_3:
+ case EL_KEY_4:
+ case EL_EM_KEY_1:
+ case EL_EM_KEY_2:
+ case EL_EM_KEY_3:
+ case EL_EM_KEY_4:
+ case EL_EMC_KEY_5:
+ case EL_EMC_KEY_6:
+ case EL_EMC_KEY_7:
+ case EL_EMC_KEY_8:
+ case EL_DC_KEY_WHITE:
+ RaiseScore(level.score[SC_KEY]);
+ break;
+ default:
+ RaiseScore(element_info[element].collect_score);
+ break;
+ }
+}