+ int x, y;
+ int num_phase = 9;
+ int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
+ int last_phase = num_phase * delay;
+ int half_phase = (num_phase / 2) * delay;
+ int first_phase_after_start = EX_PHASE_START + 1;
+
+ if (game.explosions_delayed)
+ {
+ ExplodeField[ex][ey] = mode;
+ return;
+ }
+
+ if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
+ {
+ int center_element = Feld[ex][ey];
+
+ 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;
+ }
+
+ for (y=ey-1; y<=ey+1; y++) for(x=ex-1; x<=ex+1; x++)
+ {
+ int element;
+
+ if (!IN_LEV_FIELD(x, y) ||
+ ((mode != EX_NORMAL || center_element == EL_AMOEBA_TO_DIAMOND) &&
+ (x != ex || y != ey)))
+ continue;
+
+ element = Feld[x][y];
+
+ if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
+ {
+ element = MovingOrBlocked2Element(x, y);
+ RemoveMovingField(x, y);
+ }
+
+ if (IS_MASSIVE(element) || element == EL_FLAMES)
+ continue;
+
+ 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;
+ }
+
+ if (element == EL_EXPLOSION)
+ element = Store2[x][y];
+
+ if (IS_PLAYER(ex, ey) && !PLAYER_PROTECTED(ex, ey))
+ {
+ switch(StorePlayer[ex][ey])
+ {
+ case EL_PLAYER2:
+ Store[x][y] = EL_EMERALD_RED;
+ break;
+ case EL_PLAYER3:
+ Store[x][y] = EL_EMERALD;
+ break;
+ case EL_PLAYER4:
+ Store[x][y] = EL_EMERALD_PURPLE;
+ break;
+ case EL_PLAYER1:
+ default:
+ Store[x][y] = EL_EMERALD_YELLOW;
+ break;
+ }
+
+ if (game.emulation == EMU_SUPAPLEX)
+ Store[x][y] = EL_EMPTY;
+ }
+ 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_YAMYAM)
+ Store[x][y] = level.yam_content[game.yam_content_nr][x-ex+1][y-ey+1];
+ else if (center_element == EL_AMOEBA_TO_DIAMOND)
+ Store[x][y] = level.amoeba_content;
+ 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_PFORTE(Store[x][y]))
+ Store[x][y] = EL_EMPTY;
+
+ if (x != ex || y != ey ||
+ center_element == EL_AMOEBA_TO_DIAMOND || mode == EX_BORDER)
+ Store2[x][y] = element;
+
+ if (AmoebaNr[x][y] &&
+ (element == EL_AMOEBA_FULL ||
+ element == EL_BD_AMOEBA ||
+ element == EL_AMOEBA_CREATING))
+ {
+ AmoebaCnt[AmoebaNr[x][y]]--;
+ AmoebaCnt2[AmoebaNr[x][y]]--;
+ }
+
+ Feld[x][y] = EL_EXPLOSION;
+ MovDir[x][y] = MovPos[x][y] = 0;
+ AmoebaNr[x][y] = 0;
+ ExplodePhase[x][y] = 1;
+ Stop[x][y] = TRUE;
+ }
+
+ if (center_element == EL_YAMYAM)
+ game.yam_content_nr = (game.yam_content_nr + 1) % level.num_yam_contents;
+
+ return;
+ }
+
+ if (Stop[ex][ey])
+ return;
+
+ x = ex;
+ y = ey;
+
+ ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
+
+ 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))
+ KillHeroUnlessProtected(x, y);
+ else if (IS_EXPLOSIVE(element))
+ {
+ Feld[x][y] = Store2[x][y];
+ Store2[x][y] = 0;
+ Bang(x, y);
+ }
+ else if (element == EL_AMOEBA_TO_DIAMOND)
+ AmoebeUmwandeln(x, y);
+ }
+
+ if (phase == last_phase)
+ {
+ int element;
+
+ element = Feld[x][y] = Store[x][y];
+ Store[x][y] = Store2[x][y] = 0;
+ MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
+ InitField(x, y, FALSE);
+ if (CAN_MOVE(element) || COULD_MOVE(element))
+ InitMovDir(x, y);
+ DrawLevelField(x, y);
+
+ if (IS_PLAYER(x, y) && !PLAYERINFO(x,y)->present)
+ StorePlayer[x][y] = 0;
+ }
+ else if (phase >= delay && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ {
+ int stored = Store[x][y];
+ int graphic = (game.emulation != EMU_SUPAPLEX ? IMG_EXPLOSION :
+ stored == EL_SP_INFOTRON ? IMG_SP_EXPLOSION_INFOTRON :
+ IMG_SP_EXPLOSION);
+ int frame = getGraphicAnimationFrame(graphic, phase - delay);
+
+ if (phase == delay)
+ DrawCrumbledSand(SCREENX(x), SCREENY(y));
+
+ if (IS_PFORTE(Store[x][y]))
+ {
+ DrawLevelElement(x, y, Store[x][y]);
+ DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
+ }
+ else
+ DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
+ }
+}
+
+void DynaExplode(int ex, int ey)
+{
+ int i, j;
+ 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(Feld[ex][ey]))
+ {
+ player = &stored_player[Feld[ex][ey] - EL_DYNABOMB_PLAYER1_ACTIVE];
+ dynabomb_size = player->dynabomb_size;
+ dynabomb_xl = player->dynabomb_xl;
+ player->dynabombs_left++;
+ }
+
+ Explode(ex, ey, EX_PHASE_START, EX_CENTER);
+
+ for (i=0; i<4; i++)
+ {
+ for (j=1; j<=dynabomb_size; j++)
+ {
+ int x = ex + j * xy[i % 4][0];
+ int y = ey + j * xy[i % 4][1];
+ int element;
+
+ if (!IN_LEV_FIELD(x, y) || IS_MASSIVE(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_BORDER);
+
+ if (element != EL_EMPTY &&
+ element != EL_SAND &&
+ element != EL_EXPLOSION &&
+ !dynabomb_xl)
+ break;
+ }
+ }
+}
+
+void Bang(int x, int y)
+{
+ int element = Feld[x][y];
+
+ if (game.emulation == EMU_SUPAPLEX)
+ PlaySoundLevel(x, y, SND_SP_ELEMENT_EXPLODING);
+ else
+ PlaySoundLevel(x, y, SND_ELEMENT_EXPLODING);
+
+#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_NORMAL);
+ break;
+ case EL_DYNABOMB_PLAYER1_ACTIVE:
+ case EL_DYNABOMB_PLAYER2_ACTIVE:
+ case EL_DYNABOMB_PLAYER3_ACTIVE:
+ case EL_DYNABOMB_PLAYER4_ACTIVE:
+ case EL_DYNABOMB_NR:
+ case EL_DYNABOMB_SZ:
+ case EL_DYNABOMB_XL:
+ DynaExplode(x, y);
+ break;
+ case EL_PENGUIN:
+ case EL_LAMP:
+ case EL_LAMP_ACTIVE:
+ if (IS_PLAYER(x, y))
+ Explode(x, y, EX_PHASE_START, EX_NORMAL);
+ else
+ Explode(x, y, EX_PHASE_START, EX_CENTER);
+ break;
+ default:
+ Explode(x, y, EX_PHASE_START, EX_NORMAL);
+ break;
+ }
+}
+
+void Blurb(int x, int y)
+{
+ int element = Feld[x][y];
+
+ if (element != EL_ACID_SPLASH_LEFT &&
+ element != EL_ACID_SPLASH_RIGHT) /* start */
+ {
+ PlaySoundLevel(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;
+ }
+ }
+ else /* go on */
+ {
+ int graphic = (element == EL_ACID_SPLASH_LEFT ?
+ IMG_ACID_SPLASH_LEFT :
+ IMG_ACID_SPLASH_RIGHT);
+
+ if (!MovDelay[x][y]) /* initialize animation counter */
+ MovDelay[x][y] = 9;
+
+ if (MovDelay[x][y]) /* continue animation */
+ {
+ MovDelay[x][y]--;
+ if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ {
+ int frame = getGraphicAnimationFrame(graphic, 8 - MovDelay[x][y]);
+
+ DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
+ }
+
+ if (!MovDelay[x][y])
+ {
+ Feld[x][y] = EL_EMPTY;
+ DrawLevelField(x, y);
+ }
+ }
+ }
+}
+
+static void InitBeltMovement()
+{
+ static int belt_base_element[4] =
+ {
+ EL_CONVEYOR_BELT1_LEFT,
+ EL_CONVEYOR_BELT2_LEFT,
+ EL_CONVEYOR_BELT3_LEFT,
+ EL_CONVEYOR_BELT4_LEFT
+ };
+ static int belt_base_active_element[4] =
+ {
+ EL_CONVEYOR_BELT1_LEFT_ACTIVE,
+ EL_CONVEYOR_BELT2_LEFT_ACTIVE,
+ EL_CONVEYOR_BELT3_LEFT_ACTIVE,
+ EL_CONVEYOR_BELT4_LEFT_ACTIVE
+ };