+ int k, l;
+ int position = -1;
+
+ LoadScore(level_nr);
+
+ if (strcmp(setup.player_name, EMPTY_PLAYER_NAME) == 0 ||
+ local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score)
+ return -1;
+
+ for (k = 0; k < MAX_SCORE_ENTRIES; k++)
+ {
+ if (local_player->score > highscore[k].Score)
+ {
+ /* player has made it to the hall of fame */
+
+ if (k < MAX_SCORE_ENTRIES - 1)
+ {
+ int m = MAX_SCORE_ENTRIES - 1;
+
+#ifdef ONE_PER_NAME
+ 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--)
+ {
+ strcpy(highscore[l].Name, highscore[l - 1].Name);
+ highscore[l].Score = highscore[l - 1].Score;
+ }
+ }
+
+#ifdef ONE_PER_NAME
+ put_into_list:
+#endif
+ strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
+ highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
+ highscore[k].Score = local_player->score;
+ position = k;
+ break;
+ }
+
+#ifdef ONE_PER_NAME
+ else if (!strncmp(setup.player_name, highscore[k].Name,
+ MAX_PLAYER_NAME_LEN))
+ break; /* player already there with a higher score */
+#endif
+
+ }
+
+ if (position >= 0)
+ SaveScore(level_nr);
+
+ return position;
+}
+
+void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
+{
+ if (player->GfxAction != action || player->GfxDir != dir)
+ {
+#if 0
+ printf("Player frame reset! (%d => %d, %d => %d)\n",
+ player->GfxAction, action, player->GfxDir, dir);
+#endif
+
+ player->GfxAction = action;
+ player->GfxDir = dir;
+ player->Frame = 0;
+ player->StepFrame = 0;
+ }
+}
+
+static void ResetRandomAnimationValue(int x, int y)
+{
+ GfxRandom[x][y] = INIT_GFX_RANDOM();
+}
+
+static void ResetGfxAnimation(int x, int y)
+{
+ GfxFrame[x][y] = 0;
+ GfxAction[x][y] = ACTION_DEFAULT;
+ GfxDir[x][y] = MovDir[x][y];
+}
+
+void InitMovingField(int x, int y, int direction)
+{
+ int element = Feld[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;
+ int newy = y + dy;
+
+ if (!WasJustMoving[x][y] || direction != MovDir[x][y])
+ ResetGfxAnimation(x, y);
+
+ MovDir[newx][newy] = MovDir[x][y] = direction;
+ GfxDir[x][y] = direction;
+
+ if (Feld[newx][newy] == EL_EMPTY)
+ Feld[newx][newy] = EL_BLOCKED;
+
+ if (direction == MV_DOWN && CAN_FALL(element))
+ GfxAction[x][y] = ACTION_FALLING;
+ else
+ GfxAction[x][y] = ACTION_MOVING;
+
+ GfxFrame[newx][newy] = GfxFrame[x][y];
+ GfxRandom[newx][newy] = GfxRandom[x][y];
+ GfxAction[newx][newy] = GfxAction[x][y];
+ GfxDir[newx][newy] = GfxDir[x][y];
+}
+
+void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
+{
+ int direction = MovDir[x][y];
+ int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
+ int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
+
+ *goes_to_x = newx;
+ *goes_to_y = newy;
+}
+
+void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
+{
+ int oldx = x, oldy = y;
+ int direction = MovDir[x][y];
+
+ if (direction == MV_LEFT)
+ oldx++;
+ else if (direction == MV_RIGHT)
+ oldx--;
+ else if (direction == MV_UP)
+ oldy++;
+ else if (direction == MV_DOWN)
+ oldy--;
+
+ *comes_from_x = oldx;
+ *comes_from_y = oldy;
+}
+
+int MovingOrBlocked2Element(int x, int y)
+{
+ int element = Feld[x][y];
+
+ if (element == EL_BLOCKED)
+ {
+ int oldx, oldy;
+
+ Blocked2Moving(x, y, &oldx, &oldy);
+ return Feld[oldx][oldy];
+ }
+ else
+ return element;
+}
+
+static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
+{
+ /* like MovingOrBlocked2Element(), but if element is moving
+ and (x,y) is the field the moving element is just leaving,
+ return EL_BLOCKED instead of the element value */
+ int element = Feld[x][y];
+
+ if (IS_MOVING(x, y))
+ {
+ if (element == EL_BLOCKED)
+ {
+ int oldx, oldy;
+
+ Blocked2Moving(x, y, &oldx, &oldy);
+ return Feld[oldx][oldy];
+ }
+ else
+ return EL_BLOCKED;
+ }
+ else
+ return element;
+}
+
+static void RemoveField(int x, int y)
+{
+ Feld[x][y] = EL_EMPTY;
+
+ MovPos[x][y] = 0;
+ MovDir[x][y] = 0;
+ MovDelay[x][y] = 0;
+
+ AmoebaNr[x][y] = 0;
+ ChangeDelay[x][y] = 0;
+ ChangePage[x][y] = -1;
+ Pushed[x][y] = FALSE;
+
+#if 0
+ ExplodeField[x][y] = EX_TYPE_NONE;
+#endif
+
+ GfxElement[x][y] = EL_UNDEFINED;
+ GfxAction[x][y] = ACTION_DEFAULT;
+ GfxDir[x][y] = MV_NO_MOVING;
+}
+
+void RemoveMovingField(int x, int y)
+{
+ int oldx = x, oldy = y, newx = x, newy = y;
+ int element = Feld[x][y];
+ int next_element = EL_UNDEFINED;
+
+ if (element != EL_BLOCKED && !IS_MOVING(x, y))
+ return;
+
+ if (IS_MOVING(x, y))
+ {
+ Moving2Blocked(x, y, &newx, &newy);
+#if 0
+ if (Feld[newx][newy] != EL_BLOCKED)
+ return;
+#else
+ if (Feld[newx][newy] != EL_BLOCKED)
+ {
+ /* element is moving, but target field is not free (blocked), but
+ already occupied by something different (example: acid pool);
+ in this case, only remove the moving field, but not the target */
+
+ RemoveField(oldx, oldy);
+
+ Store[oldx][oldy] = Store2[oldx][oldy] = 0;
+
+ DrawLevelField(oldx, oldy);
+
+ return;
+ }
+#endif
+ }
+ else if (element == EL_BLOCKED)
+ {
+ Blocked2Moving(x, y, &oldx, &oldy);
+ if (!IS_MOVING(oldx, oldy))
+ return;
+ }
+
+ if (element == EL_BLOCKED &&
+ (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
+ Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
+ Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
+ Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
+ next_element = get_next_element(Feld[oldx][oldy]);
+
+ RemoveField(oldx, oldy);
+ RemoveField(newx, newy);
+
+ Store[oldx][oldy] = Store2[oldx][oldy] = 0;
+
+ if (next_element != EL_UNDEFINED)
+ Feld[oldx][oldy] = next_element;
+
+ DrawLevelField(oldx, oldy);
+ DrawLevelField(newx, newy);
+}
+
+void DrawDynamite(int x, int y)
+{
+ int sx = SCREENX(x), sy = SCREENY(y);
+ int graphic = el2img(Feld[x][y]);
+ int frame;
+
+ if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
+ return;
+
+ if (IS_WALKABLE_INSIDE(Back[x][y]))
+ return;
+
+ if (Back[x][y])
+ DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
+ else if (Store[x][y])
+ DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
+
+ frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
+
+#if 1
+ if (Back[x][y] || Store[x][y])
+ DrawGraphicThruMask(sx, sy, graphic, frame);
+ else
+ DrawGraphic(sx, sy, graphic, frame);
+#else
+ if (game.emulation == EMU_SUPAPLEX)
+ DrawGraphic(sx, sy, IMG_SP_DISK_RED, frame);
+ else if (Store[x][y])
+ DrawGraphicThruMask(sx, sy, graphic, frame);
+ else
+ DrawGraphic(sx, sy, graphic, frame);
+#endif
+}
+
+void CheckDynamite(int x, int y)
+{
+ if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
+ {
+ MovDelay[x][y]--;
+
+ if (MovDelay[x][y] != 0)
+ {
+ DrawDynamite(x, y);
+ PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
+
+ return;
+ }
+ }
+
+#if 1
+ StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
+#else
+ if (Feld[x][y] == EL_DYNAMITE_ACTIVE ||
+ Feld[x][y] == EL_SP_DISK_RED_ACTIVE)
+ StopSound(SND_DYNAMITE_ACTIVE);
+ else
+ StopSound(SND_DYNABOMB_ACTIVE);
+#endif
+
+ Bang(x, y);
+}
+
+void DrawRelocatePlayer(struct PlayerInfo *player)
+{
+ boolean ffwd_delay = (tape.playing && tape.fast_forward);
+ boolean no_delay = (tape.warp_forward);
+ int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
+ int wait_delay_value = (no_delay ? 0 : frame_delay_value);
+ int jx = player->jx;
+ int jy = player->jy;
+
+ if (level.instant_relocation)
+ {
+#if 1
+ int offset = (setup.scroll_delay ? 3 : 0);
+
+ if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
+ {
+ scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
+ local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
+ local_player->jx - MIDPOSX);
+
+ scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
+ local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
+ local_player->jy - MIDPOSY);
+ }
+ else
+ {
+ if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
+ (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
+ scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
+
+ if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
+ (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
+ scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
+
+ /* don't scroll over playfield boundaries */
+ if (scroll_x < SBX_Left || scroll_x > SBX_Right)
+ scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
+
+ /* don't scroll over playfield boundaries */
+ if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
+ scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
+ }
+#else
+ scroll_x += (local_player->jx - old_jx);
+ scroll_y += (local_player->jy - old_jy);
+
+ /* don't scroll over playfield boundaries */
+ if (scroll_x < SBX_Left || scroll_x > SBX_Right)
+ scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
+
+ /* don't scroll over playfield boundaries */
+ if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
+ scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
+#endif
+
+ RedrawPlayfield(TRUE, 0,0,0,0);
+ }
+ else
+ {
+#if 1
+#if 0
+ int offset = (setup.scroll_delay ? 3 : 0);
+#endif
+ int scroll_xx = -999, scroll_yy = -999;
+
+ ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
+
+ while (scroll_xx != scroll_x || scroll_yy != scroll_y)
+ {
+ int dx = 0, dy = 0;
+ int fx = FX, fy = FY;
+
+ scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
+ local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
+ local_player->jx - MIDPOSX);
+
+ scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
+ local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
+ local_player->jy - MIDPOSY);
+
+ dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
+ dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
+
+#if 1
+ if (dx == 0 && dy == 0) /* no scrolling needed at all */
+ break;
+#else
+ if (scroll_xx == scroll_x && scroll_yy == scroll_y)
+ break;
+#endif
+
+ scroll_x -= dx;
+ scroll_y -= dy;
+
+ fx += dx * TILEX / 2;
+ fy += dy * TILEY / 2;
+
+ ScrollLevel(dx, dy);
+ DrawAllPlayers();
+
+ /* scroll in two steps of half tile size to make things smoother */
+ BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
+ FlushDisplay();
+ Delay(wait_delay_value);
+
+ /* scroll second step to align at full tile size */
+ BackToFront();
+ Delay(wait_delay_value);
+ }
+#else
+ int scroll_xx = -999, scroll_yy = -999;
+
+ ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
+
+ while (scroll_xx != scroll_x || scroll_yy != scroll_y)
+ {
+ int dx = 0, dy = 0;
+ int fx = FX, fy = FY;
+
+ scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
+ local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
+ local_player->jx - MIDPOSX);
+
+ scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
+ local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
+ local_player->jy - MIDPOSY);
+
+ dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
+ dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
+
+#if 1
+ if (dx == 0 && dy == 0) /* no scrolling needed at all */
+ break;
+#else
+ if (scroll_xx == scroll_x && scroll_yy == scroll_y)
+ break;
+#endif
+
+ scroll_x -= dx;
+ scroll_y -= dy;
+
+ fx += dx * TILEX / 2;
+ fy += dy * TILEY / 2;
+
+ ScrollLevel(dx, dy);
+ DrawAllPlayers();
+
+ /* scroll in two steps of half tile size to make things smoother */
+ BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
+ FlushDisplay();
+ Delay(wait_delay_value);
+
+ /* scroll second step to align at full tile size */
+ BackToFront();
+ Delay(wait_delay_value);
+ }
+#endif
+
+ DrawPlayer(player);
+ BackToFront();
+ Delay(wait_delay_value);
+ }
+}
+
+void RelocatePlayer(int jx, int jy, int el_player_raw)
+{
+ int el_player = (el_player_raw == EL_SP_MURPHY ? EL_PLAYER_1 :el_player_raw);
+ struct PlayerInfo *player = &stored_player[el_player - EL_PLAYER_1];
+ boolean ffwd_delay = (tape.playing && tape.fast_forward);
+ boolean no_delay = (tape.warp_forward);
+ int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
+ int wait_delay_value = (no_delay ? 0 : frame_delay_value);
+ int old_jx = player->jx;
+ int old_jy = player->jy;
+ int old_element = Feld[old_jx][old_jy];
+ int element = Feld[jx][jy];
+ boolean player_relocated = (old_jx != jx || old_jy != jy);
+
+ static int trigger_sides[4][2] =
+ {
+ /* enter side leave side */
+ { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
+ { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
+ { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
+ { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
+ };
+ int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
+ int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
+ int enter_side_horiz = trigger_sides[MV_DIR_BIT(move_dir_horiz)][0];
+ int enter_side_vert = trigger_sides[MV_DIR_BIT(move_dir_vert)][0];
+ int enter_side = enter_side_horiz | enter_side_vert;
+ int leave_side_horiz = trigger_sides[MV_DIR_BIT(move_dir_horiz)][1];
+ int leave_side_vert = trigger_sides[MV_DIR_BIT(move_dir_vert)][1];
+ int leave_side = leave_side_horiz | leave_side_vert;
+
+ if (player->GameOver) /* do not reanimate dead player */
+ return;
+
+ if (!player_relocated) /* no need to relocate the player */
+ return;
+
+ if (IS_PLAYER(jx, jy)) /* player already placed at new position */
+ {
+ RemoveField(jx, jy); /* temporarily remove newly placed player */
+ DrawLevelField(jx, jy);
+ }
+
+ if (player->present)
+ {
+ while (player->MovPos)
+ {
+ ScrollPlayer(player, SCROLL_GO_ON);
+ ScrollScreen(NULL, SCROLL_GO_ON);
+ FrameCounter++;
+
+ DrawPlayer(player);
+
+ BackToFront();
+ Delay(wait_delay_value);
+ }
+
+ DrawPlayer(player); /* needed here only to cleanup last field */
+ DrawLevelField(player->jx, player->jy); /* remove player graphic */
+
+ player->is_moving = FALSE;
+ }
+
+#if 1
+ if (IS_CUSTOM_ELEMENT(old_element))
+ CheckElementChangeByPlayer(old_jx, old_jy, old_element,
+ CE_LEFT_BY_PLAYER,
+ player->index_bit, leave_side);
+
+ CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
+ CE_OTHER_GETS_LEFT,
+ player->index_bit, leave_side);
+#endif
+
+ Feld[jx][jy] = el_player;
+ InitPlayerField(jx, jy, el_player, TRUE);
+
+ Feld[jx][jy] = element; /* player may be set on walkable element */
+ InitField(jx, jy, FALSE);
+
+#if 1
+ if (player == local_player) /* only visually relocate local player */
+ DrawRelocatePlayer(player);
+#endif
+
+#if 1
+ TestIfHeroTouchesBadThing(jx, jy);
+ TestIfPlayerTouchesCustomElement(jx, jy);
+#endif
+
+#if 1
+ /* needed to allow change of walkable custom element by entering player */
+ Changed[jx][jy] = 0; /* allow another change */
+#endif
+
+#if 1
+ if (IS_CUSTOM_ELEMENT(element))
+ CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
+ player->index_bit, enter_side);
+
+ CheckTriggeredElementChangeByPlayer(jx, jy, element,
+ CE_OTHER_GETS_ENTERED,
+ player->index_bit, enter_side);
+#endif
+}
+
+void Explode(int ex, int ey, int phase, int mode)
+{
+ int x, y;
+#if 0
+ int num_phase = 9;
+#endif
+
+ /* !!! eliminate this variable !!! */
+ int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
+
+#if 1
+ int last_phase;
+#else
+ int last_phase = num_phase * delay;
+ int half_phase = (num_phase / 2) * delay;
+ int first_phase_after_start = EX_PHASE_START + 1;
+#endif
+ int border_element;
+
+ if (game.explosions_delayed)
+ {
+ ExplodeField[ex][ey] = mode;
+ return;
+ }
+
+ if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
+ {
+ int center_element = Feld[ex][ey];
+
+#if 0
+ printf("::: start explosion %d,%d [%d]\n", ex, ey, FrameCounter);
+#endif
+
+#if 0
+ /* --- This is only really needed (and now handled) in "Impact()". --- */
+ /* do not explode moving elements that left the explode field in time */
+ if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
+ center_element == EL_EMPTY &&
+ (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
+ return;
+#endif
+
+ if (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER)
+ PlayLevelSoundAction(ex, ey, ACTION_EXPLODING);
+
+ /* remove things displayed in background while burning dynamite */
+ if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
+ Back[ex][ey] = 0;
+
+ if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
+ {
+ /* put moving element to center field (and let it explode there) */
+ center_element = MovingOrBlocked2Element(ex, ey);
+ RemoveMovingField(ex, ey);
+ Feld[ex][ey] = center_element;
+ }
+
+#if 1
+
+#if 1
+ last_phase = element_info[center_element].explosion_delay + 1;
+#else
+ last_phase = element_info[center_element].explosion_delay;
+#endif
+
+#if 0
+ printf("::: %d -> %d\n", center_element, last_phase);
+#endif
+#endif
+
+ 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 1
+#if 1
+ if (!IN_LEV_FIELD(x, y) ||
+ (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
+ (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
+ continue;
+#else
+ if (!IN_LEV_FIELD(x, y) ||
+ (mode != EX_TYPE_NORMAL && (x != ex || y != ey)))
+ continue;
+#endif
+#else
+ if (!IN_LEV_FIELD(x, y) ||
+ ((mode != EX_TYPE_NORMAL ||
+ center_element == EL_AMOEBA_TO_DIAMOND) &&
+ (x != ex || y != ey)))
+ continue;
+#endif
+
+ element = Feld[x][y];
+
+ if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
+ {
+ element = MovingOrBlocked2Element(x, y);
+
+ if (!IS_EXPLOSION_PROOF(element))
+ RemoveMovingField(x, y);
+ }
+
+#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,0) ||
+ (!IS_WALKABLE_OVER(element) && !IS_WALKABLE_UNDER(element)))) ||
+ element == EL_FLAMES)
+ continue;
+#endif
+
+ if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
+ {
+ if (IS_ACTIVE_BOMB(element))
+ {
+ /* re-activate things under the bomb like gate or penguin */
+ Feld[x][y] = (Store[x][y] ? Store[x][y] : EL_EMPTY);
+ Store[x][y] = 0;
+ }
+
+ continue;
+ }
+
+ /* 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)
+ element = Store2[x][y];
+
+#if 1
+ if (AmoebaNr[x][y] &&
+ (element == EL_AMOEBA_FULL ||
+ element == EL_BD_AMOEBA ||
+ element == EL_AMOEBA_GROWING))
+ {
+ AmoebaCnt[AmoebaNr[x][y]]--;
+ AmoebaCnt2[AmoebaNr[x][y]]--;
+ }
+
+ RemoveField(x, y);
+#endif
+
+ if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
+ {
+ switch(StorePlayer[ex][ey])
+ {
+ case EL_PLAYER_2:
+ Store[x][y] = EL_PLAYER_IS_EXPLODING_2;
+ break;
+ case EL_PLAYER_3:
+ Store[x][y] = EL_PLAYER_IS_EXPLODING_3;
+ break;
+ case EL_PLAYER_4:
+ Store[x][y] = EL_PLAYER_IS_EXPLODING_4;
+ break;
+ case EL_PLAYER_1:
+ default:
+ Store[x][y] = EL_PLAYER_IS_EXPLODING_1;
+ break;
+ }
+
+#if 1
+ if (PLAYERINFO(ex, ey)->use_murphy_graphic)
+ Store[x][y] = EL_EMPTY;
+#else
+ if (game.emulation == EMU_SUPAPLEX)
+ Store[x][y] = EL_EMPTY;
+#endif
+ }
+ else if (center_element == EL_MOLE)
+ Store[x][y] = EL_EMERALD_RED;
+ else if (center_element == EL_PENGUIN)
+ Store[x][y] = EL_EMERALD_PURPLE;
+ else if (center_element == EL_BUG)
+ Store[x][y] = ((x == ex && y == ey) ? EL_DIAMOND : EL_EMERALD);
+ else if (center_element == EL_BD_BUTTERFLY)
+ Store[x][y] = EL_BD_DIAMOND;
+ else if (center_element == EL_SP_ELECTRON)
+ Store[x][y] = EL_SP_INFOTRON;
+ 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][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)
+ Store[x][y] = EL_DIAMOND;
+ else if (element == EL_WALL_BD_DIAMOND)
+ Store[x][y] = EL_BD_DIAMOND;
+ else if (element == EL_WALL_EMERALD_YELLOW)
+ Store[x][y] = EL_EMERALD_YELLOW;
+ else if (element == EL_WALL_EMERALD_RED)
+ Store[x][y] = EL_EMERALD_RED;
+ else if (element == EL_WALL_EMERALD_PURPLE)
+ Store[x][y] = EL_EMERALD_PURPLE;
+ else if (element == EL_WALL_PEARL)
+ 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;
+
+ if (x != ex || y != ey ||
+ center_element == EL_AMOEBA_TO_DIAMOND || mode == EX_TYPE_BORDER)
+ Store2[x][y] = element;
+
+#if 0
+ 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 1
+ RemoveField(x, y);
+#else
+ MovDir[x][y] = MovPos[x][y] = 0;
+ GfxDir[x][y] = MovDir[x][y];
+ AmoebaNr[x][y] = 0;
+#endif
+#endif
+
+ Feld[x][y] = EL_EXPLOSION;
+#if 1
+ GfxElement[x][y] = center_element;
+#else
+ GfxElement[x][y] = EL_UNDEFINED;
+#endif
+
+ ExplodePhase[x][y] = 1;
+#if 1
+ ExplodeDelay[x][y] = last_phase;
+#endif
+
+#if 0
+#if 1
+ GfxFrame[x][y] = 0; /* animation does not start until next frame */
+#else
+ GfxFrame[x][y] = -1; /* animation does not start until next frame */
+#endif
+#endif
+
+ Stop[x][y] = TRUE;
+ }
+
+ if (center_element == EL_YAMYAM)
+ game.yamyam_content_nr =
+ (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
+
+ return;
+ }
+
+ if (Stop[ex][ey])
+ return;
+
+ x = ex;
+ y = ey;
+
+#if 1
+ if (phase == 1)
+ GfxFrame[x][y] = 0; /* restart explosion animation */
+#endif
+
+#if 0
+ printf(":X: phase == %d [%d]\n", phase, GfxFrame[x][y]);
+#endif
+
+#if 1
+ last_phase = ExplodeDelay[x][y];
+#endif
+
+ ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
+
+#ifdef DEBUG
+
+ /* activate this even in non-DEBUG version until cause for crash in
+ getGraphicAnimationFrame() (see below) is found and eliminated */
+#endif
+#if 1
+
+ if (GfxElement[x][y] == EL_UNDEFINED)
+ {
+ printf("\n\n");
+ printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
+ printf("Explode(): This should never happen!\n");
+ printf("\n\n");
+
+ GfxElement[x][y] = EL_EMPTY;
+ }
+#endif
+
+#if 1
+
+ border_element = Store2[x][y];
+ if (IS_PLAYER(x, y))
+ border_element = StorePlayer[x][y];
+
+#if 0
+ printf("::: phase == %d\n", phase);
+#endif
+
+ if (phase == element_info[border_element].ignition_delay ||
+ phase == last_phase)
+ {
+ boolean border_explosion = FALSE;
+
+#if 1
+ if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present)
+#else
+ if (IS_PLAYER(x, y))
+#endif
+ {
+ KillHeroUnlessExplosionProtected(x, y);
+ border_explosion = TRUE;
+
+#if 0
+ if (phase == last_phase)
+ printf("::: IS_PLAYER\n");
+#endif
+ }
+ else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
+ {
+ Feld[x][y] = Store2[x][y];
+ Store2[x][y] = 0;
+ Bang(x, y);
+ border_explosion = TRUE;
+
+#if 0
+ if (phase == last_phase)
+ printf("::: CAN_EXPLODE_BY_EXPLOSION\n");
+#endif
+ }
+ else if (border_element == EL_AMOEBA_TO_DIAMOND)
+ {
+ AmoebeUmwandeln(x, y);
+ Store2[x][y] = 0;
+ border_explosion = TRUE;
+
+#if 0
+ if (phase == last_phase)
+ printf("::: EL_AMOEBA_TO_DIAMOND [%d, %d] [%d]\n",
+ element_info[border_element].explosion_delay,
+ element_info[border_element].ignition_delay,
+ phase);
+#endif
+ }
+
+#if 1
+ /* if an element just explodes due to another explosion (chain-reaction),
+ do not immediately end the new explosion when it was the last frame of
+ the explosion (as it would be done in the following "if"-statement!) */
+ if (border_explosion && phase == last_phase)
+ return;
+#endif
+ }
+
+#else
+
+ if (phase == first_phase_after_start)
+ {
+ int element = Store2[x][y];
+
+ if (element == EL_BLACK_ORB)
+ {
+ Feld[x][y] = Store2[x][y];
+ Store2[x][y] = 0;
+ Bang(x, y);
+ }
+ }
+ else if (phase == half_phase)
+ {
+ int element = Store2[x][y];
+
+ if (IS_PLAYER(x, y))
+ KillHeroUnlessExplosionProtected(x, y);
+ else if (CAN_EXPLODE_BY_EXPLOSION(element))
+ {
+ Feld[x][y] = Store2[x][y];
+ Store2[x][y] = 0;
+ Bang(x, y);
+ }
+ else if (element == EL_AMOEBA_TO_DIAMOND)
+ AmoebeUmwandeln(x, y);
+ }
+#endif
+
+ if (phase == last_phase)
+ {
+ int element;
+
+#if 0
+ printf("::: done: phase == %d\n", phase);
+#endif
+
+#if 0
+ printf("::: explosion %d,%d done [%d]\n", x, y, FrameCounter);
+#endif
+
+ element = Feld[x][y] = Store[x][y];
+ 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;
+
+ MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
+ GfxDir[x][y] = MV_NO_MOVING;
+ ChangeDelay[x][y] = 0;
+ ChangePage[x][y] = -1;
+
+#if 1
+ InitField_WithBug2(x, y, FALSE);
+#else
+ InitField(x, y, FALSE);
+#if 1
+ /* !!! not needed !!! */
+#if 1
+ if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
+ CAN_MOVE(Feld[x][y]) && Feld[x][y] != EL_MOLE)
+ InitMovDir(x, y);
+#else
+ if (CAN_MOVE(element))
+ InitMovDir(x, y);
+#endif
+#endif
+#endif
+ DrawLevelField(x, y);
+
+ TestIfElementTouchesCustomElement(x, y);
+
+ if (GFX_CRUMBLED(element))
+ DrawLevelFieldCrumbledSandNeighbours(x, y);
+
+ if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
+ StorePlayer[x][y] = 0;
+
+ if (ELEM_IS_PLAYER(element))
+ RelocatePlayer(x, y, element);
+ }
+#if 1
+ else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+#else
+ else if (phase >= delay && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+#endif
+ {
+#if 1
+ int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
+#else
+ int stored = Store[x][y];
+ int graphic = (game.emulation != EMU_SUPAPLEX ? IMG_EXPLOSION :
+ stored == EL_SP_INFOTRON ? IMG_SP_EXPLOSION_INFOTRON :
+ IMG_SP_EXPLOSION);
+#endif
+#if 1
+ int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
+#else
+ int frame = getGraphicAnimationFrame(graphic, phase - delay);
+#endif
+
+#if 0
+ printf("::: phase == %d [%d]\n", phase, GfxFrame[x][y]);
+#endif
+
+#if 0
+ printf("::: %d / %d [%d - %d]\n",
+ GfxFrame[x][y], phase - delay, phase, delay);
+#endif
+
+#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);
+
+ if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
+ {
+ DrawLevelElement(x, y, Back[x][y]);
+ DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
+ }
+ else if (IS_WALKABLE_UNDER(Back[x][y]))
+ {
+ DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
+ DrawLevelElementThruMask(x, y, Back[x][y]);
+ }
+ else if (!IS_WALKABLE_INSIDE(Back[x][y]))
+ DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
+ }
+}
+
+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;
+ static int xy[4][2] =
+ {
+ { 0, -1 },
+ { -1, 0 },
+ { +1, 0 },
+ { 0, +1 }
+ };
+
+ if (IS_ACTIVE_BOMB(dynabomb_element))
+ {
+ player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
+ dynabomb_size = player->dynabomb_size;
+ dynabomb_xl = player->dynabomb_xl;
+ player->dynabombs_left++;
+ }
+
+ Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
+
+ for (i = 0; i < NUM_DIRECTIONS; i++)
+ {
+ for (j = 1; j <= dynabomb_size; j++)
+ {
+ int x = ex + j * xy[i][0];
+ int y = ey + j * xy[i][1];
+ int element;
+
+ if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
+ break;
+
+ element = Feld[x][y];
+
+ /* do not restart explosions of fields with active bombs */
+ if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
+ continue;
+
+ Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
+
+#if 1
+ if (element != EL_EMPTY && element != EL_EXPLOSION &&
+ !CAN_GROW_INTO(element) && !dynabomb_xl)
+ break;
+#else
+ /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
+ if (element != EL_EMPTY && element != EL_EXPLOSION &&
+ element != EL_SAND && !dynabomb_xl)
+ break;
+#endif
+ }
+ }
+}
+
+void Bang(int x, int y)
+{
+#if 1
+ int element = MovingOrBlocked2Element(x, y);
+#else
+ int element = Feld[x][y];
+#endif
+
+#if 1
+ if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
+#else
+ if (IS_PLAYER(x, y))
+#endif
+ {
+ struct PlayerInfo *player = PLAYERINFO(x, y);
+
+ element = Feld[x][y] = (player->use_murphy_graphic ? EL_SP_MURPHY :
+ player->element_nr);
+ }
+
+#if 0
+#if 1
+ PlayLevelSoundAction(x, y, ACTION_EXPLODING);
+#else
+ if (game.emulation == EMU_SUPAPLEX)
+ PlayLevelSound(x, y, SND_SP_ELEMENT_EXPLODING);
+ else
+ PlayLevelSound(x, y, SND_ELEMENT_EXPLODING);
+#endif
+#endif
+
+#if 0
+ if (IS_PLAYER(x, y)) /* remove objects that might cause smaller explosion */
+ element = EL_EMPTY;
+#endif
+
+ switch(element)
+ {
+ case EL_BUG:
+ case EL_SPACESHIP:
+ case EL_BD_BUTTERFLY:
+ case EL_BD_FIREFLY:
+ case EL_YAMYAM:
+ case EL_DARK_YAMYAM:
+ case EL_ROBOT:
+ case EL_PACMAN:
+ case EL_MOLE:
+ RaiseScoreElement(element);
+ Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
+ break;
+ case EL_DYNABOMB_PLAYER_1_ACTIVE:
+ case EL_DYNABOMB_PLAYER_2_ACTIVE:
+ case EL_DYNABOMB_PLAYER_3_ACTIVE:
+ case EL_DYNABOMB_PLAYER_4_ACTIVE:
+ case EL_DYNABOMB_INCREASE_NUMBER:
+ case EL_DYNABOMB_INCREASE_SIZE:
+ case EL_DYNABOMB_INCREASE_POWER:
+ DynaExplode(x, y);
+ break;
+ case EL_PENGUIN:
+ case EL_LAMP:
+ case EL_LAMP_ACTIVE:
+#if 1
+ case EL_AMOEBA_TO_DIAMOND:
+#endif
+ if (IS_PLAYER(x, y))
+ Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
+ else
+ Explode(x, y, EX_PHASE_START, EX_TYPE_CENTER);
+ break;
+ default:
+ if (CAN_EXPLODE_CROSS(element))
+#if 1
+ Explode(x, y, EX_PHASE_START, EX_TYPE_CROSS);
+#else
+ DynaExplode(x, y);
+#endif
+ else if (CAN_EXPLODE_1X1(element))
+ Explode(x, y, EX_PHASE_START, EX_TYPE_CENTER);
+ else
+ Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
+ break;
+ }
+
+ CheckTriggeredElementChange(x, y, element, CE_OTHER_IS_EXPLODING);
+}
+
+void SplashAcid(int x, int y)
+{
+#if 1
+ if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
+ (!IN_LEV_FIELD(x - 1, y - 2) ||
+ !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
+ Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
+
+ if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
+ (!IN_LEV_FIELD(x + 1, y - 2) ||
+ !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
+ Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
+
+ PlayLevelSound(x, y, SND_ACID_SPLASHING);
+#else
+ /* input: position of element entering acid (obsolete) */
+
+ int element = Feld[x][y];
+
+ if (!IN_LEV_FIELD(x, y + 1) || Feld[x][y + 1] != EL_ACID)
+ return;
+
+ if (element != EL_ACID_SPLASH_LEFT &&
+ element != EL_ACID_SPLASH_RIGHT)
+ {
+ 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) ||
+ !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 1))))
+ Feld[x - 1][y] = EL_ACID_SPLASH_LEFT;
+
+ if (IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y) &&
+ (!IN_LEV_FIELD(x + 1, y - 1) ||
+ !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 1))))
+ Feld[x + 1][y] = EL_ACID_SPLASH_RIGHT;
+ }
+#endif
+}
+
+static void InitBeltMovement()
+{
+ static int belt_base_element[4] =
+ {
+ EL_CONVEYOR_BELT_1_LEFT,
+ EL_CONVEYOR_BELT_2_LEFT,
+ EL_CONVEYOR_BELT_3_LEFT,
+ EL_CONVEYOR_BELT_4_LEFT
+ };
+ static int belt_base_active_element[4] =
+ {
+ EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
+ EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
+ EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
+ EL_CONVEYOR_BELT_4_LEFT_ACTIVE
+ };
+
+ int x, y, i, j;
+
+ /* set frame order for belt animation graphic according to belt direction */
+ for (i = 0; i < NUM_BELTS; i++)
+ {
+ int belt_nr = i;
+
+ for (j = 0; j < NUM_BELT_PARTS; j++)
+ {
+ int element = belt_base_active_element[belt_nr] + j;
+ int graphic = el2img(element);
+
+ if (game.belt_dir[i] == MV_LEFT)
+ graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
+ else
+ graphic_info[graphic].anim_mode |= ANIM_REVERSE;
+ }
+ }
+
+ for (y = 0; y < lev_fieldy; y++)
+ {
+ for (x = 0; x < lev_fieldx; x++)
+ {
+ int element = Feld[x][y];
+
+ for (i = 0; i < NUM_BELTS; i++)
+ {
+ if (IS_BELT(element) && game.belt_dir[i] != MV_NO_MOVING)
+ {
+ int e_belt_nr = getBeltNrFromBeltElement(element);
+ int belt_nr = i;
+
+ if (e_belt_nr == belt_nr)
+ {
+ int belt_part = Feld[x][y] - belt_base_element[belt_nr];
+
+ Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
+ }
+ }
+ }
+ }
+ }
+}
+
+static void ToggleBeltSwitch(int x, int y)
+{
+ static int belt_base_element[4] =
+ {
+ EL_CONVEYOR_BELT_1_LEFT,
+ EL_CONVEYOR_BELT_2_LEFT,
+ EL_CONVEYOR_BELT_3_LEFT,
+ EL_CONVEYOR_BELT_4_LEFT
+ };
+ static int belt_base_active_element[4] =
+ {
+ EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
+ EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
+ EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
+ EL_CONVEYOR_BELT_4_LEFT_ACTIVE
+ };
+ static int belt_base_switch_element[4] =
+ {
+ EL_CONVEYOR_BELT_1_SWITCH_LEFT,
+ EL_CONVEYOR_BELT_2_SWITCH_LEFT,
+ EL_CONVEYOR_BELT_3_SWITCH_LEFT,
+ EL_CONVEYOR_BELT_4_SWITCH_LEFT
+ };
+ static int belt_move_dir[4] =
+ {
+ MV_LEFT,
+ MV_NO_MOVING,
+ MV_RIGHT,
+ MV_NO_MOVING,
+ };
+
+ int element = Feld[x][y];
+ int belt_nr = getBeltNrFromBeltSwitchElement(element);
+ int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
+ int belt_dir = belt_move_dir[belt_dir_nr];
+ int xx, yy, i;
+
+ if (!IS_BELT_SWITCH(element))
+ return;
+
+ game.belt_dir_nr[belt_nr] = belt_dir_nr;
+ game.belt_dir[belt_nr] = belt_dir;
+
+ if (belt_dir_nr == 3)
+ belt_dir_nr = 1;
+
+ /* set frame order for belt animation graphic according to belt direction */
+ for (i = 0; i < NUM_BELT_PARTS; i++)
+ {
+ int element = belt_base_active_element[belt_nr] + i;
+ int graphic = el2img(element);
+
+ if (belt_dir == MV_LEFT)
+ graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
+ else
+ graphic_info[graphic].anim_mode |= ANIM_REVERSE;
+ }
+
+ for (yy = 0; yy < lev_fieldy; yy++)
+ {
+ for (xx = 0; xx < lev_fieldx; xx++)
+ {
+ int element = Feld[xx][yy];
+
+ if (IS_BELT_SWITCH(element))
+ {
+ int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
+
+ if (e_belt_nr == belt_nr)
+ {
+ Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
+ DrawLevelField(xx, yy);
+ }
+ }
+ else if (IS_BELT(element) && belt_dir != MV_NO_MOVING)
+ {
+ int e_belt_nr = getBeltNrFromBeltElement(element);
+
+ if (e_belt_nr == belt_nr)
+ {
+ int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
+
+ Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
+ DrawLevelField(xx, yy);
+ }
+ }
+ else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NO_MOVING)
+ {
+ int e_belt_nr = getBeltNrFromBeltActiveElement(element);
+
+ if (e_belt_nr == belt_nr)
+ {
+ int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
+
+ Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
+ DrawLevelField(xx, yy);
+ }
+ }
+ }
+ }
+}
+
+static void ToggleSwitchgateSwitch(int x, int y)
+{
+ int xx, yy;
+
+ game.switchgate_pos = !game.switchgate_pos;
+
+ for (yy = 0; yy < lev_fieldy; yy++)
+ {
+ for (xx = 0; xx < lev_fieldx; xx++)
+ {
+ int element = Feld[xx][yy];
+
+ if (element == EL_SWITCHGATE_SWITCH_UP ||
+ element == EL_SWITCHGATE_SWITCH_DOWN)
+ {
+ Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
+ DrawLevelField(xx, yy);
+ }
+ else if (element == EL_SWITCHGATE_OPEN ||
+ element == EL_SWITCHGATE_OPENING)
+ {
+ Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
+#if 1
+ PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
+#else
+ PlayLevelSound(xx, yy, SND_SWITCHGATE_CLOSING);
+#endif
+ }
+ else if (element == EL_SWITCHGATE_CLOSED ||
+ element == EL_SWITCHGATE_CLOSING)
+ {
+ Feld[xx][yy] = EL_SWITCHGATE_OPENING;
+#if 1
+ PlayLevelSoundAction(xx, yy, ACTION_OPENING);
+#else
+ PlayLevelSound(xx, yy, SND_SWITCHGATE_OPENING);
+#endif
+ }
+ }
+ }
+}
+
+static int getInvisibleActiveFromInvisibleElement(int element)
+{
+ return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
+ element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_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 :
+ element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
+ element);
+}
+
+static void RedrawAllLightSwitchesAndInvisibleElements()
+{
+ int x, y;
+
+ for (y = 0; y < lev_fieldy; y++)
+ {
+ for (x = 0; x < lev_fieldx; x++)
+ {
+ int element = Feld[x][y];
+
+ if (element == EL_LIGHT_SWITCH &&
+ game.light_time_left > 0)
+ {
+ Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
+ DrawLevelField(x, y);
+ }
+ else if (element == EL_LIGHT_SWITCH_ACTIVE &&
+ game.light_time_left == 0)
+ {
+ Feld[x][y] = EL_LIGHT_SWITCH;
+ DrawLevelField(x, y);
+ }
+ else if (element == EL_INVISIBLE_STEELWALL ||
+ element == EL_INVISIBLE_WALL ||
+ element == EL_INVISIBLE_SAND)
+ {
+ if (game.light_time_left > 0)
+ Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
+
+ DrawLevelField(x, y);
+ }
+ else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
+ element == EL_INVISIBLE_WALL_ACTIVE ||
+ element == EL_INVISIBLE_SAND_ACTIVE)
+ {
+ if (game.light_time_left == 0)
+ Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
+
+ DrawLevelField(x, y);
+ }
+ }
+ }
+}
+
+static void ToggleLightSwitch(int x, int y)
+{
+ int element = Feld[x][y];
+
+ game.light_time_left =
+ (element == EL_LIGHT_SWITCH ?
+ level.time_light * FRAMES_PER_SECOND : 0);
+
+ RedrawAllLightSwitchesAndInvisibleElements();
+}
+
+static void ActivateTimegateSwitch(int x, int y)
+{
+ int xx, yy;
+
+ game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
+
+ for (yy = 0; yy < lev_fieldy; yy++)
+ {
+ for (xx = 0; xx < lev_fieldx; xx++)
+ {
+ int element = Feld[xx][yy];
+
+ if (element == EL_TIMEGATE_CLOSED ||
+ element == EL_TIMEGATE_CLOSING)
+ {
+ Feld[xx][yy] = EL_TIMEGATE_OPENING;
+ PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
+ }
+
+ /*
+ else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
+ {
+ Feld[xx][yy] = EL_TIMEGATE_SWITCH;
+ DrawLevelField(xx, yy);
+ }
+ */
+
+ }
+ }
+
+ Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
+}
+
+inline static int getElementMoveStepsize(int x, int y)
+{
+ int element = Feld[x][y];
+ 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 horiz_move = (dx != 0);
+ int sign = (horiz_move ? dx : dy);
+ int step = sign * element_info[element].move_stepsize;
+
+ /* special values for move stepsize for spring and things on conveyor belt */
+ if (horiz_move)
+ {
+#if 0
+ if (element == EL_SPRING)
+ step = sign * MOVE_STEPSIZE_NORMAL * 2;
+ else if (CAN_FALL(element) && !CAN_MOVE(element) &&
+ y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
+ step = sign * MOVE_STEPSIZE_NORMAL / 2;
+#else
+ if (CAN_FALL(element) &&
+ y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
+ step = sign * MOVE_STEPSIZE_NORMAL / 2;
+ else if (element == EL_SPRING)
+ step = sign * MOVE_STEPSIZE_NORMAL * 2;
+#endif
+ }
+
+ return step;
+}
+
+void Impact(int x, int y)
+{
+ boolean lastline = (y == lev_fieldy-1);
+ boolean object_hit = FALSE;
+ boolean impact = (lastline || object_hit);
+ int element = Feld[x][y];
+ int smashed = EL_STEELWALL;
+
+ if (!lastline) /* check if element below was hit */
+ {
+ if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
+ return;
+
+ object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
+ 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)
+ object_hit = FALSE;
+
+ if (object_hit)
+ smashed = MovingOrBlocked2Element(x, y + 1);
+
+ impact = (lastline || object_hit);
+ }
+
+ if (!lastline && smashed == EL_ACID) /* element falls into acid */
+ {
+ SplashAcid(x, y + 1);
+ return;
+ }
+
+ /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
+ /* 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);
+ }
+
+ if (impact && CAN_EXPLODE_IMPACT(element))
+ {
+ Bang(x, y);
+ return;
+ }
+ else if (impact && element == EL_PEARL)
+ {
+ ResetGfxAnimation(x, y);
+
+ Feld[x][y] = EL_PEARL_BREAKING;
+ PlayLevelSound(x, y, SND_PEARL_BREAKING);
+ return;
+ }
+ else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
+ {
+ PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
+
+ return;
+ }
+
+ if (impact && element == EL_AMOEBA_DROP)
+ {
+ if (object_hit && IS_PLAYER(x, y + 1))
+ KillHeroUnlessEnemyProtected(x, y + 1);
+ else if (object_hit && smashed == EL_PENGUIN)
+ Bang(x, y + 1);
+ else
+ {
+ Feld[x][y] = EL_AMOEBA_GROWING;
+ Store[x][y] = EL_AMOEBA_WET;
+
+ ResetRandomAnimationValue(x, y);
+ }
+ return;
+ }
+
+ if (object_hit) /* check which object was hit */
+ {
+ if (CAN_PASS_MAGIC_WALL(element) &&
+ (smashed == EL_MAGIC_WALL ||
+ smashed == EL_BD_MAGIC_WALL))
+ {
+ int xx, yy;
+ int activated_magic_wall =
+ (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
+ EL_BD_MAGIC_WALL_ACTIVE);
+
+ /* activate magic wall / mill */
+ 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;
+
+ PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
+ SND_MAGIC_WALL_ACTIVATING :
+ SND_BD_MAGIC_WALL_ACTIVATING));
+ }
+
+ if (IS_PLAYER(x, y + 1))
+ {
+ if (CAN_SMASH_PLAYER(element))
+ {
+ KillHeroUnlessEnemyProtected(x, y + 1);
+ return;
+ }
+ }
+ else if (smashed == EL_PENGUIN)
+ {
+ if (CAN_SMASH_PLAYER(element))
+ {
+ Bang(x, y + 1);
+ return;
+ }
+ }
+ else if (element == EL_BD_DIAMOND)
+ {
+ if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
+ {
+ Bang(x, y + 1);
+ return;
+ }
+ }
+ 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;
+ }
+#if 0
+ else if (CAN_SMASH_ENEMIES(element) && IS_CLASSIC_ENEMY(smashed))
+ {
+ Bang(x, y + 1);
+ return;
+ }
+#endif
+ else if (CAN_SMASH_EVERYTHING(element))
+ {
+ if (IS_CLASSIC_ENEMY(smashed) ||
+ CAN_EXPLODE_SMASHED(smashed))
+ {
+ Bang(x, y + 1);
+ return;
+ }
+ else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
+ {
+ if (smashed == EL_LAMP ||
+ smashed == EL_LAMP_ACTIVE)
+ {
+ Bang(x, y + 1);
+ return;
+ }
+ else if (smashed == EL_NUT)
+ {
+ Feld[x][y + 1] = EL_NUT_BREAKING;
+ PlayLevelSound(x, y, SND_NUT_BREAKING);
+ RaiseScoreElement(EL_NUT);
+ return;
+ }
+ else if (smashed == EL_PEARL)
+ {
+ ResetGfxAnimation(x, y);
+
+ Feld[x][y + 1] = EL_PEARL_BREAKING;
+ PlayLevelSound(x, y, SND_PEARL_BREAKING);
+ return;
+ }
+ else if (smashed == EL_DIAMOND)
+ {
+ Feld[x][y + 1] = EL_DIAMOND_BREAKING;
+ PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
+ return;
+ }
+ else if (IS_BELT_SWITCH(smashed))
+ {
+ ToggleBeltSwitch(x, y + 1);
+ }
+ else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
+ smashed == EL_SWITCHGATE_SWITCH_DOWN)
+ {
+ ToggleSwitchgateSwitch(x, y + 1);
+ }
+ else if (smashed == EL_LIGHT_SWITCH ||
+ smashed == EL_LIGHT_SWITCH_ACTIVE)
+ {
+ ToggleLightSwitch(x, y + 1);
+ }
+ else
+ {
+#if 0
+ TestIfElementSmashesCustomElement(x, y, MV_DOWN);
+#endif
+
+ CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
+
+#if 1
+ /* !!! TEST ONLY !!! */
+ CheckElementChangeBySide(x, y + 1, smashed, element,
+ CE_SWITCHED, CH_SIDE_TOP);
+ CheckTriggeredElementChangeBySide(x, y + 1, smashed,
+ CE_OTHER_IS_SWITCHING,CH_SIDE_TOP);
+#else
+ CheckTriggeredElementChangeBySide(x, y + 1, smashed,
+ CE_OTHER_IS_SWITCHING,CH_SIDE_TOP);
+ CheckElementChangeBySide(x, y + 1, smashed, element,
+ CE_SWITCHED, CH_SIDE_TOP);
+#endif
+ }
+ }
+ else
+ {
+ CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
+ }
+ }
+ }
+
+ /* play sound of magic wall / mill */
+ if (!lastline &&
+ (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
+ Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
+ {
+ if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
+ PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
+ else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
+ PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
+
+ return;
+ }
+
+ /* play sound of object that hits the ground */
+ if (lastline || object_hit)
+ PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
+}
+
+inline static void TurnRoundExt(int x, int y)
+{
+ static struct
+ {
+ int x, y;
+ } move_xy[] =
+ {
+ { 0, 0 },
+ { -1, 0 },
+ { +1, 0 },
+ { 0, 0 },
+ { 0, -1 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, +1 }
+ };