+ if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ DrawGraphic(SCREENX(x), SCREENY(y), el2gfx(element)+phase);
+
+ if ((element == EL_MAMPFER || element == EL_MAMPFER2)
+ && MovDelay[x][y]%4 == 3)
+ PlaySoundLevel(x, y, SND_NJAM);
+ }
+ else if (element == EL_SP_ELECTRON)
+ DrawGraphicAnimation(x, y, GFX2_SP_ELECTRON, 8, 2, ANIM_NORMAL);
+ else if (element == EL_DRACHE)
+ {
+ int i;
+ int dir = MovDir[x][y];
+ int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
+ int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
+ int graphic = (dir == MV_LEFT ? GFX_FLAMMEN_LEFT :
+ dir == MV_RIGHT ? GFX_FLAMMEN_RIGHT :
+ dir == MV_UP ? GFX_FLAMMEN_UP :
+ dir == MV_DOWN ? GFX_FLAMMEN_DOWN : GFX_LEERRAUM);
+ int phase = FrameCounter % 2;
+
+ for (i=1; i<=3; i++)
+ {
+ int xx = x + i*dx, yy = y + i*dy;
+ int sx = SCREENX(xx), sy = SCREENY(yy);
+
+ if (!IN_LEV_FIELD(xx, yy) ||
+ IS_SOLID(Feld[xx][yy]) || Feld[xx][yy] == EL_EXPLODING)
+ break;
+
+ if (MovDelay[x][y])
+ {
+ int flamed = MovingOrBlocked2Element(xx, yy);
+
+ if (IS_ENEMY(flamed) || IS_EXPLOSIVE(flamed))
+ Bang(xx, yy);
+ else
+ RemoveMovingField(xx, yy);
+
+ Feld[xx][yy] = EL_BURNING;
+ if (IN_SCR_FIELD(sx, sy))
+ DrawGraphic(sx, sy, graphic + phase*3 + i-1);
+ }
+ else
+ {
+ if (Feld[xx][yy] == EL_BURNING)
+ Feld[xx][yy] = EL_LEERRAUM;
+ DrawLevelField(xx, yy);
+ }
+ }
+ }
+
+ if (MovDelay[x][y])
+ return;
+ }
+
+ if (element == EL_KAEFER || element == EL_BUTTERFLY)
+ {
+ PlaySoundLevel(x, y, SND_KLAPPER);
+ }
+ else if (element == EL_FLIEGER || element == EL_FIREFLY)
+ {
+ PlaySoundLevel(x, y, SND_ROEHR);
+ }
+
+ /* now make next step */
+
+ Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
+
+ if (IS_ENEMY(element) && IS_PLAYER(newx, newy) &&
+ !PLAYER_PROTECTED(newx, newy))
+ {
+
+#if 1
+ TestIfBadThingHitsHero(x, y);
+ return;
+#else
+ /* enemy got the player */
+ MovDir[x][y] = 0;
+ KillHero(PLAYERINFO(newx, newy));
+ return;
+#endif
+
+ }
+ else if ((element == EL_PINGUIN || element == EL_ROBOT ||
+ element == EL_SONDE || element == EL_BALLOON) &&
+ IN_LEV_FIELD(newx, newy) &&
+ MovDir[x][y] == MV_DOWN && Feld[newx][newy] == EL_SALZSAEURE)
+ {
+ Blurb(x, y);
+ Store[x][y] = EL_SALZSAEURE;
+ }
+ else if (element == EL_PINGUIN && IN_LEV_FIELD(newx, newy))
+ {
+ if (Feld[newx][newy] == EL_AUSGANG_AUF)
+ {
+ Feld[x][y] = EL_LEERRAUM;
+ DrawLevelField(x, y);
+
+ PlaySoundLevel(newx, newy, SND_BUING);
+ if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
+ DrawGraphicThruMask(SCREENX(newx), SCREENY(newy), el2gfx(element));
+
+ local_player->friends_still_needed--;
+ if (!local_player->friends_still_needed &&
+ !local_player->GameOver && AllPlayersGone)
+ local_player->LevelSolved = local_player->GameOver = TRUE;
+
+ return;
+ }
+ else if (IS_MAMPF3(Feld[newx][newy]))
+ {
+ if (DigField(local_player, newx, newy, 0, 0, DF_DIG) == MF_MOVING)
+ DrawLevelField(newx, newy);
+ else
+ MovDir[x][y] = MV_NO_MOVING;
+ }
+ else if (!IS_FREE(newx, newy))
+ {
+ if (IS_PLAYER(x, y))
+ DrawPlayerField(x, y);
+ else
+ DrawLevelField(x, y);
+ return;
+ }
+ }
+ else if (element == EL_SCHWEIN && IN_LEV_FIELD(newx, newy))
+ {
+ if (IS_GEM(Feld[newx][newy]))
+ {
+ if (IS_MOVING(newx, newy))
+ RemoveMovingField(newx, newy);
+ else
+ {
+ Feld[newx][newy] = EL_LEERRAUM;
+ DrawLevelField(newx, newy);
+ }
+ }
+ else if (!IS_FREE(newx, newy))
+ {
+ if (IS_PLAYER(x, y))
+ DrawPlayerField(x, y);
+ else
+ DrawLevelField(x, y);
+ return;
+ }
+ }
+ else if (element == EL_DRACHE && IN_LEV_FIELD(newx, newy))
+ {
+ if (!IS_FREE(newx, newy))
+ {
+ if (IS_PLAYER(x, y))
+ DrawPlayerField(x, y);
+ else
+ DrawLevelField(x, y);
+ return;
+ }
+ else
+ {
+ boolean wanna_flame = !RND(10);
+ int dx = newx - x, dy = newy - y;
+ int newx1 = newx+1*dx, newy1 = newy+1*dy;
+ int newx2 = newx+2*dx, newy2 = newy+2*dy;
+ int element1 = (IN_LEV_FIELD(newx1, newy1) ?
+ MovingOrBlocked2Element(newx1, newy1) : EL_BETON);
+ int element2 = (IN_LEV_FIELD(newx2, newy2) ?
+ MovingOrBlocked2Element(newx2, newy2) : EL_BETON);
+
+ if ((wanna_flame || IS_ENEMY(element1) || IS_ENEMY(element2)) &&
+ element1 != EL_DRACHE && element2 != EL_DRACHE &&
+ element1 != EL_BURNING && element2 != EL_BURNING)
+ {
+ if (IS_PLAYER(x, y))
+ DrawPlayerField(x, y);
+ else
+ DrawLevelField(x, y);
+
+ MovDelay[x][y] = 50;
+ Feld[newx][newy] = EL_BURNING;
+ if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_LEERRAUM)
+ Feld[newx1][newy1] = EL_BURNING;
+ if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_LEERRAUM)
+ Feld[newx2][newy2] = EL_BURNING;
+ return;
+ }
+ }
+ }
+ else if (element == EL_MAMPFER && IN_LEV_FIELD(newx, newy) &&
+ Feld[newx][newy] == EL_DIAMANT)
+ {
+ if (IS_MOVING(newx, newy))
+ RemoveMovingField(newx, newy);
+ else
+ {
+ Feld[newx][newy] = EL_LEERRAUM;
+ DrawLevelField(newx, newy);
+ }
+ }
+ else if (element == EL_MAMPFER2 && IN_LEV_FIELD(newx, newy) &&
+ IS_MAMPF2(Feld[newx][newy]))
+ {
+ if (AmoebaNr[newx][newy])
+ {
+ AmoebaCnt2[AmoebaNr[newx][newy]]--;
+ if (Feld[newx][newy] == EL_AMOEBE_VOLL ||
+ Feld[newx][newy] == EL_AMOEBE_BD)
+ AmoebaCnt[AmoebaNr[newx][newy]]--;
+ }
+
+ if (IS_MOVING(newx, newy))
+ RemoveMovingField(newx, newy);
+ else
+ {
+ Feld[newx][newy] = EL_LEERRAUM;
+ DrawLevelField(newx, newy);
+ }
+ }
+ else if ((element == EL_PACMAN || element == EL_MOLE)
+ && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
+ {
+ if (AmoebaNr[newx][newy])
+ {
+ AmoebaCnt2[AmoebaNr[newx][newy]]--;
+ if (Feld[newx][newy] == EL_AMOEBE_VOLL ||
+ Feld[newx][newy] == EL_AMOEBE_BD)
+ AmoebaCnt[AmoebaNr[newx][newy]]--;
+ }
+
+ if (element == EL_MOLE)
+ {
+ Feld[newx][newy] = EL_DEAMOEBING;
+ MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
+ return; /* wait for shrinking amoeba */
+ }
+ else /* element == EL_PACMAN */
+ {
+ Feld[newx][newy] = EL_LEERRAUM;
+ DrawLevelField(newx, newy);
+ }
+ }
+ else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
+ (Feld[newx][newy] == EL_DEAMOEBING ||
+ (Feld[newx][newy] == EL_LEERRAUM && Stop[newx][newy])))
+ {
+ /* wait for shrinking amoeba to completely disappear */
+ return;
+ }
+ else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
+ {
+ /* object was running against a wall */
+
+ TurnRound(x, y);
+
+ if (element == EL_KAEFER || element == EL_FLIEGER ||
+ element == EL_SP_SNIKSNAK || element == EL_MOLE)
+ DrawLevelField(x, y);
+ else if (element == EL_BUTTERFLY || element == EL_FIREFLY)
+ DrawGraphicAnimation(x, y, el2gfx(element), 2, 4, ANIM_NORMAL);
+ else if (element == EL_SONDE)
+ DrawGraphicAnimation(x, y, GFX_SONDE_START, 8, 2, ANIM_NORMAL);
+ else if (element == EL_SP_ELECTRON)
+ DrawGraphicAnimation(x, y, GFX2_SP_ELECTRON, 8, 2, ANIM_NORMAL);
+
+ if (DONT_TOUCH(element))
+ TestIfBadThingHitsHero(x, y);
+
+ return;
+ }
+
+ if (element == EL_ROBOT && IN_SCR_FIELD(x, y))
+ PlaySoundLevel(x, y, SND_SCHLURF);
+
+ InitMovingField(x, y, MovDir[x][y]);
+ }
+
+ if (MovDir[x][y])
+ ContinueMoving(x, y);
+}
+
+void ContinueMoving(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 newx = x + dx, newy = y + dy;
+ int step = (horiz_move ? dx : dy) * TILEX / 8;
+
+ if (element == EL_TROPFEN)
+ step /= 2;
+ else if (Store[x][y] == EL_MORAST_VOLL || Store[x][y] == EL_MORAST_LEER)
+ step /= 4;
+ else if (CAN_FALL(element) && horiz_move &&
+ y < lev_fieldy-1 && IS_BELT(Feld[x][y+1]))
+ step /= 2;
+
+#if OLD_GAME_BEHAVIOUR
+ else if (CAN_FALL(element) && horiz_move && !IS_SP_ELEMENT(element))
+ step*=2;
+#endif
+
+ MovPos[x][y] += step;
+
+ if (ABS(MovPos[x][y])>=TILEX) /* object reached its destination */
+ {
+ Feld[x][y] = EL_LEERRAUM;
+ Feld[newx][newy] = element;
+
+ if (element == EL_MOLE)
+ {
+ int i;
+ static int xy[4][2] =
+ {
+ { 0, -1 },
+ { -1, 0 },
+ { +1, 0 },
+ { 0, +1 }
+ };
+
+ Feld[x][y] = EL_ERDREICH;
+ DrawLevelField(x, y);
+
+ for(i=0; i<4; i++)
+ {
+ int xx, yy;
+
+ xx = x + xy[i][0];
+ yy = y + xy[i][1];
+
+ if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_ERDREICH)
+ DrawLevelField(xx, yy); /* for "ErdreichAnbroeckeln()" */
+ }
+ }
+
+ if (Store[x][y] == EL_MORAST_VOLL)
+ {
+ Store[x][y] = 0;
+ Feld[newx][newy] = EL_MORAST_VOLL;
+ element = EL_MORAST_VOLL;
+ }
+ else if (Store[x][y] == EL_MORAST_LEER)
+ {
+ Store[x][y] = 0;
+ Feld[x][y] = EL_MORAST_LEER;
+ }
+ else if (Store[x][y] == EL_SIEB_VOLL)
+ {
+ Store[x][y] = 0;
+ element = Feld[newx][newy] =
+ (game.magic_wall_active ? EL_SIEB_VOLL : EL_SIEB_TOT);
+ }
+ else if (Store[x][y] == EL_SIEB_LEER)
+ {
+ Store[x][y] = Store2[x][y] = 0;
+ Feld[x][y] = (game.magic_wall_active ? EL_SIEB_LEER : EL_SIEB_TOT);
+ }
+ else if (Store[x][y] == EL_SIEB2_VOLL)
+ {
+ Store[x][y] = 0;
+ element = Feld[newx][newy] =
+ (game.magic_wall_active ? EL_SIEB2_VOLL : EL_SIEB2_TOT);
+ }
+ else if (Store[x][y] == EL_SIEB2_LEER)
+ {
+ Store[x][y] = Store2[x][y] = 0;
+ Feld[x][y] = (game.magic_wall_active ? EL_SIEB2_LEER : EL_SIEB2_TOT);
+ }
+ else if (Store[x][y] == EL_SALZSAEURE)
+ {
+ Store[x][y] = 0;
+ Feld[newx][newy] = EL_SALZSAEURE;
+ element = EL_SALZSAEURE;
+ }
+ else if (Store[x][y] == EL_AMOEBE_NASS)
+ {
+ Store[x][y] = 0;
+ Feld[x][y] = EL_AMOEBE_NASS;
+ }
+
+ MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
+ MovDelay[newx][newy] = 0;
+
+ if (!CAN_MOVE(element))
+ MovDir[newx][newy] = 0;
+
+ DrawLevelField(x, y);
+ DrawLevelField(newx, newy);
+
+ Stop[newx][newy] = TRUE;
+ JustStopped[newx][newy] = 3;
+
+ if (DONT_TOUCH(element)) /* object may be nasty to player or others */
+ {
+ TestIfBadThingHitsHero(newx, newy);
+ TestIfBadThingHitsFriend(newx, newy);
+ TestIfBadThingHitsOtherBadThing(newx, newy);
+ }
+ else if (element == EL_PINGUIN)
+ TestIfFriendHitsBadThing(newx, newy);
+
+ if (CAN_SMASH(element) && direction == MV_DOWN &&
+ (newy == lev_fieldy-1 || !IS_FREE(x, newy+1)))
+ Impact(x, newy);
+ }
+ else /* still moving on */
+ DrawLevelField(x, y);
+}
+
+int AmoebeNachbarNr(int ax, int ay)
+{
+ int i;
+ int element = Feld[ax][ay];
+ int group_nr = 0;
+ static int xy[4][2] =
+ {
+ { 0, -1 },
+ { -1, 0 },
+ { +1, 0 },
+ { 0, +1 }
+ };
+
+ for (i=0; i<4; i++)
+ {
+ int x = ax + xy[i][0];
+ int y = ay + xy[i][1];
+
+ if (!IN_LEV_FIELD(x, y))
+ continue;
+
+ if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
+ group_nr = AmoebaNr[x][y];
+ }
+
+ return group_nr;
+}
+
+void AmoebenVereinigen(int ax, int ay)
+{
+ int i, x, y, xx, yy;
+ int new_group_nr = AmoebaNr[ax][ay];
+ static int xy[4][2] =
+ {
+ { 0, -1 },
+ { -1, 0 },
+ { +1, 0 },
+ { 0, +1 }
+ };
+
+ if (new_group_nr == 0)
+ return;
+
+ for (i=0; i<4; i++)
+ {
+ x = ax + xy[i][0];
+ y = ay + xy[i][1];
+
+ if (!IN_LEV_FIELD(x, y))
+ continue;
+
+ if ((Feld[x][y] == EL_AMOEBE_VOLL ||
+ Feld[x][y] == EL_AMOEBE_BD ||
+ Feld[x][y] == EL_AMOEBE_TOT) &&
+ AmoebaNr[x][y] != new_group_nr)
+ {
+ int old_group_nr = AmoebaNr[x][y];
+
+ if (old_group_nr == 0)
+ return;
+
+ AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
+ AmoebaCnt[old_group_nr] = 0;
+ AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
+ AmoebaCnt2[old_group_nr] = 0;
+
+ for (yy=0; yy<lev_fieldy; yy++)
+ {
+ for (xx=0; xx<lev_fieldx; xx++)
+ {
+ if (AmoebaNr[xx][yy] == old_group_nr)
+ AmoebaNr[xx][yy] = new_group_nr;
+ }
+ }
+ }
+ }
+}
+
+void AmoebeUmwandeln(int ax, int ay)
+{
+ int i, x, y;
+
+ if (Feld[ax][ay] == EL_AMOEBE_TOT)
+ {
+ int group_nr = AmoebaNr[ax][ay];
+
+#ifdef DEBUG
+ if (group_nr == 0)
+ {
+ printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
+ printf("AmoebeUmwandeln(): This should never happen!\n");
+ return;
+ }
+#endif
+
+ for (y=0; y<lev_fieldy; y++)
+ {
+ for (x=0; x<lev_fieldx; x++)
+ {
+ if (Feld[x][y] == EL_AMOEBE_TOT && AmoebaNr[x][y] == group_nr)
+ {
+ AmoebaNr[x][y] = 0;
+ Feld[x][y] = EL_AMOEBA2DIAM;
+ }
+ }
+ }
+ Bang(ax, ay);
+ }
+ else
+ {
+ static int xy[4][2] =
+ {
+ { 0, -1 },
+ { -1, 0 },
+ { +1, 0 },
+ { 0, +1 }
+ };
+
+ for (i=0; i<4; i++)
+ {
+ x = ax + xy[i][0];
+ y = ay + xy[i][1];
+
+ if (!IN_LEV_FIELD(x, y))
+ continue;
+
+ if (Feld[x][y] == EL_AMOEBA2DIAM)
+ Bang(x, y);
+ }
+ }
+}
+
+void AmoebeUmwandelnBD(int ax, int ay, int new_element)
+{
+ int x, y;
+ int group_nr = AmoebaNr[ax][ay];
+ boolean done = FALSE;
+
+#ifdef DEBUG
+ if (group_nr == 0)
+ {
+ printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
+ printf("AmoebeUmwandelnBD(): This should never happen!\n");
+ return;
+ }
+#endif
+
+ for (y=0; y<lev_fieldy; y++)
+ {
+ for (x=0; x<lev_fieldx; x++)
+ {
+ if (AmoebaNr[x][y] == group_nr &&
+ (Feld[x][y] == EL_AMOEBE_TOT ||
+ Feld[x][y] == EL_AMOEBE_BD ||
+ Feld[x][y] == EL_AMOEBING))
+ {
+ AmoebaNr[x][y] = 0;
+ Feld[x][y] = new_element;
+ InitField(x, y, FALSE);
+ DrawLevelField(x, y);
+ done = TRUE;
+ }
+ }
+ }
+
+ if (done)
+ PlaySoundLevel(ax, ay,
+ (new_element == EL_FELSBROCKEN ? SND_KLOPF : SND_PLING));
+}
+
+void AmoebeWaechst(int x, int y)
+{
+ static unsigned long sound_delay = 0;
+ static unsigned long sound_delay_value = 0;
+
+ if (!MovDelay[x][y]) /* start new growing cycle */
+ {
+ MovDelay[x][y] = 7;
+
+ if (DelayReached(&sound_delay, sound_delay_value))
+ {
+ PlaySoundLevel(x, y, SND_AMOEBE);
+ sound_delay_value = 30;
+ }
+ }
+
+ if (MovDelay[x][y]) /* wait some time before growing bigger */
+ {
+ MovDelay[x][y]--;
+ if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ DrawGraphic(SCREENX(x), SCREENY(y), GFX_AMOEBING + 3 - MovDelay[x][y]/2);
+
+ if (!MovDelay[x][y])
+ {
+ Feld[x][y] = Store[x][y];
+ Store[x][y] = 0;
+ DrawLevelField(x, y);
+ }
+ }
+}
+
+void AmoebeSchrumpft(int x, int y)
+{
+ static unsigned long sound_delay = 0;
+ static unsigned long sound_delay_value = 0;
+
+ if (!MovDelay[x][y]) /* start new shrinking cycle */
+ {
+ MovDelay[x][y] = 7;
+
+ if (DelayReached(&sound_delay, sound_delay_value))
+ {
+ PlaySoundLevel(x, y, SND_BLURB);
+ sound_delay_value = 30;
+ }
+ }
+
+ if (MovDelay[x][y]) /* wait some time before shrinking */
+ {
+ MovDelay[x][y]--;
+ if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ DrawGraphic(SCREENX(x), SCREENY(y), GFX_AMOEBING + MovDelay[x][y]/2);
+
+ if (!MovDelay[x][y])
+ {
+ Feld[x][y] = EL_LEERRAUM;
+ DrawLevelField(x, y);
+
+ /* don't let mole enter this field in this cycle;
+ (give priority to objects falling to this field from above) */
+ Stop[x][y] = TRUE;
+ }
+ }
+}
+
+void AmoebeAbleger(int ax, int ay)
+{
+ int i;
+ int element = Feld[ax][ay];
+ int newax = ax, neway = ay;
+ static int xy[4][2] =
+ {
+ { 0, -1 },
+ { -1, 0 },
+ { +1, 0 },
+ { 0, +1 }
+ };
+
+ if (!level.amoeba_speed)
+ {
+ Feld[ax][ay] = EL_AMOEBE_TOT;
+ DrawLevelField(ax, ay);
+ return;
+ }
+
+ if (!MovDelay[ax][ay]) /* start making new amoeba field */
+ MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
+
+ if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
+ {
+ MovDelay[ax][ay]--;
+ if (MovDelay[ax][ay])
+ return;
+ }
+
+ if (element == EL_AMOEBE_NASS) /* object is an acid / amoeba drop */
+ {
+ int start = RND(4);
+ int x = ax + xy[start][0];
+ int y = ay + xy[start][1];
+
+ if (!IN_LEV_FIELD(x, y))
+ return;
+
+ if (IS_FREE(x, y) ||
+ Feld[x][y] == EL_ERDREICH || Feld[x][y] == EL_MORAST_LEER)
+ {
+ newax = x;
+ neway = y;
+ }
+
+ if (newax == ax && neway == ay)
+ return;
+ }
+ else /* normal or "filled" (BD style) amoeba */
+ {
+ int start = RND(4);
+ boolean waiting_for_player = FALSE;
+
+ for (i=0; i<4; i++)
+ {
+ int j = (start + i) % 4;
+ int x = ax + xy[j][0];
+ int y = ay + xy[j][1];
+
+ if (!IN_LEV_FIELD(x, y))
+ continue;
+
+ if (IS_FREE(x, y) ||
+ Feld[x][y] == EL_ERDREICH || Feld[x][y] == EL_MORAST_LEER)
+ {
+ newax = x;
+ neway = y;
+ break;
+ }
+ else if (IS_PLAYER(x, y))
+ waiting_for_player = TRUE;
+ }
+
+ if (newax == ax && neway == ay) /* amoeba cannot grow */
+ {
+ if (i == 4 && (!waiting_for_player || game.emulation == EMU_BOULDERDASH))
+ {
+ Feld[ax][ay] = EL_AMOEBE_TOT;
+ DrawLevelField(ax, ay);
+ AmoebaCnt[AmoebaNr[ax][ay]]--;
+
+ if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
+ {
+ if (element == EL_AMOEBE_VOLL)
+ AmoebeUmwandeln(ax, ay);
+ else if (element == EL_AMOEBE_BD)
+ AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
+ }
+ }
+ return;
+ }
+ else if (element == EL_AMOEBE_VOLL || element == EL_AMOEBE_BD)
+ {
+ /* amoeba gets larger by growing in some direction */
+
+ int new_group_nr = AmoebaNr[ax][ay];
+
+#ifdef DEBUG
+ if (new_group_nr == 0)
+ {
+ printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
+ printf("AmoebeAbleger(): This should never happen!\n");
+ return;
+ }
+#endif
+
+ AmoebaNr[newax][neway] = new_group_nr;
+ AmoebaCnt[new_group_nr]++;
+ AmoebaCnt2[new_group_nr]++;
+
+ /* if amoeba touches other amoeba(s) after growing, unify them */
+ AmoebenVereinigen(newax, neway);
+
+ if (element == EL_AMOEBE_BD && AmoebaCnt2[new_group_nr] >= 200)
+ {
+ AmoebeUmwandelnBD(newax, neway, EL_FELSBROCKEN);
+ return;
+ }
+ }
+ }
+
+ if (element != EL_AMOEBE_NASS || neway < ay || !IS_FREE(newax, neway) ||
+ (neway == lev_fieldy - 1 && newax != ax))
+ {
+ Feld[newax][neway] = EL_AMOEBING;
+ Store[newax][neway] = element;
+ }
+ else if (neway == ay)
+ Feld[newax][neway] = EL_TROPFEN;
+ else
+ {
+ InitMovingField(ax, ay, MV_DOWN);
+ Feld[ax][ay] = EL_TROPFEN;
+ Store[ax][ay] = EL_AMOEBE_NASS;
+ ContinueMoving(ax, ay);
+ return;
+ }
+
+ DrawLevelField(newax, neway);
+}
+
+void Life(int ax, int ay)
+{
+ int x1, y1, x2, y2;
+ static int life[4] = { 2, 3, 3, 3 }; /* parameters for "game of life" */
+ int life_time = 40;
+ int element = Feld[ax][ay];
+
+ if (Stop[ax][ay])
+ return;
+
+ if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
+ MovDelay[ax][ay] = life_time;
+
+ if (MovDelay[ax][ay]) /* wait some time before next cycle */
+ {
+ MovDelay[ax][ay]--;
+ if (MovDelay[ax][ay])
+ return;
+ }
+
+ for (y1=-1; y1<2; y1++) for(x1=-1; x1<2; x1++)
+ {
+ int xx = ax+x1, yy = ay+y1;
+ int nachbarn = 0;
+
+ if (!IN_LEV_FIELD(xx, yy))
+ continue;
+
+ for (y2=-1; y2<2; y2++) for (x2=-1; x2<2; x2++)
+ {
+ int x = xx+x2, y = yy+y2;
+
+ if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
+ continue;
+
+ if (((Feld[x][y] == element ||
+ (element == EL_LIFE && IS_PLAYER(x, y))) &&
+ !Stop[x][y]) ||
+ (IS_FREE(x, y) && Stop[x][y]))
+ nachbarn++;
+ }
+
+ if (xx == ax && yy == ay) /* field in the middle */
+ {
+ if (nachbarn<life[0] || nachbarn>life[1])
+ {
+ Feld[xx][yy] = EL_LEERRAUM;
+ if (!Stop[xx][yy])
+ DrawLevelField(xx, yy);
+ Stop[xx][yy] = TRUE;
+ }
+ }
+ else if (IS_FREE(xx, yy) || Feld[xx][yy] == EL_ERDREICH)
+ { /* free border field */
+ if (nachbarn>=life[2] && nachbarn<=life[3])
+ {
+ Feld[xx][yy] = element;
+ MovDelay[xx][yy] = (element == EL_LIFE ? 0 : life_time-1);
+ if (!Stop[xx][yy])
+ DrawLevelField(xx, yy);
+ Stop[xx][yy] = TRUE;
+ }
+ }
+ }
+}
+
+void Ablenk(int x, int y)
+{
+ if (!MovDelay[x][y]) /* next animation frame */
+ MovDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
+
+ if (MovDelay[x][y]) /* wait some time before next frame */
+ {
+ MovDelay[x][y]--;
+ if (MovDelay[x][y])
+ {
+ if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ DrawGraphic(SCREENX(x), SCREENY(y), GFX_ABLENK+MovDelay[x][y]%4);
+ if (!(MovDelay[x][y]%4))
+ PlaySoundLevel(x, y, SND_MIEP);
+ return;
+ }
+ }
+
+ Feld[x][y] = EL_ABLENK_AUS;
+ DrawLevelField(x, y);
+ if (ZX == x && ZY == y)
+ ZX = ZY = -1;
+}
+
+void TimegateWheel(int x, int y)
+{
+ if (!MovDelay[x][y]) /* next animation frame */
+ MovDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
+
+ if (MovDelay[x][y]) /* wait some time before next frame */
+ {
+ MovDelay[x][y]--;
+ if (MovDelay[x][y])
+ {
+ if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ DrawGraphic(SCREENX(x), SCREENY(y),
+ GFX_TIMEGATE_SWITCH + MovDelay[x][y]%4);
+ if (!(MovDelay[x][y]%4))
+ PlaySoundLevel(x, y, SND_MIEP);
+ return;
+ }
+ }
+
+ Feld[x][y] = EL_TIMEGATE_SWITCH_OFF;
+ DrawLevelField(x, y);
+ if (ZX == x && ZY == y)
+ ZX = ZY = -1;
+}
+
+void Birne(int x, int y)
+{
+ if (!MovDelay[x][y]) /* next animation frame */
+ MovDelay[x][y] = 800;
+
+ if (MovDelay[x][y]) /* wait some time before next frame */
+ {
+ MovDelay[x][y]--;
+ if (MovDelay[x][y])
+ {
+ if (!(MovDelay[x][y]%5))
+ {
+ if (!(MovDelay[x][y]%10))
+ Feld[x][y]=EL_ABLENK_EIN;
+ else
+ Feld[x][y]=EL_ABLENK_AUS;
+ DrawLevelField(x, y);
+ Feld[x][y]=EL_ABLENK_EIN;
+ }
+ return;
+ }
+ }
+
+ Feld[x][y]=EL_ABLENK_AUS;
+ DrawLevelField(x, y);
+ if (ZX == x && ZY == y)
+ ZX=ZY=-1;
+}
+
+void Blubber(int x, int y)
+{
+ if (y > 0 && IS_MOVING(x, y-1) && MovDir[x][y-1] == MV_DOWN)
+ DrawLevelField(x, y-1);
+ else
+ DrawGraphicAnimation(x, y, GFX_GEBLUBBER, 4, 10, ANIM_NORMAL);
+}
+
+void NussKnacken(int x, int y)
+{
+ if (!MovDelay[x][y]) /* next animation frame */
+ MovDelay[x][y] = 7;
+
+ if (MovDelay[x][y]) /* wait some time before next frame */
+ {
+ MovDelay[x][y]--;
+ if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ DrawGraphic(SCREENX(x), SCREENY(y),
+ GFX_CRACKINGNUT + 3 - MovDelay[x][y]/2);
+
+ if (!MovDelay[x][y])
+ {
+ Feld[x][y] = EL_EDELSTEIN;
+ DrawLevelField(x, y);
+ }
+ }
+}
+
+void BreakingPearl(int x, int y)
+{
+ if (!MovDelay[x][y]) /* next animation frame */
+ MovDelay[x][y] = 9;
+
+ if (MovDelay[x][y]) /* wait some time before next frame */
+ {
+ MovDelay[x][y]--;
+ if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ DrawGraphic(SCREENX(x), SCREENY(y),
+ GFX_PEARL_BREAKING + 4 - MovDelay[x][y]/2);
+
+ if (!MovDelay[x][y])
+ {
+ Feld[x][y] = EL_LEERRAUM;
+ DrawLevelField(x, y);
+ }
+ }
+}
+
+void SiebAktivieren(int x, int y, int typ)
+{
+ int graphic = (typ == 1 ? GFX_SIEB_VOLL : GFX_SIEB2_VOLL) + 3;
+
+ DrawGraphicAnimation(x, y, graphic, 4, 4, ANIM_REVERSE);
+}
+
+void AusgangstuerPruefen(int x, int y)
+{
+ if (!local_player->gems_still_needed &&
+ !local_player->sokobanfields_still_needed &&
+ !local_player->lights_still_needed)
+ {
+ Feld[x][y] = EL_AUSGANG_ACT;
+
+ PlaySoundLevel(x < LEVELX(BX1) ? LEVELX(BX1) :
+ (x > LEVELX(BX2) ? LEVELX(BX2) : x),
+ y < LEVELY(BY1) ? LEVELY(BY1) :
+ (y > LEVELY(BY2) ? LEVELY(BY2) : y),
+ SND_OEFFNEN);
+ }
+}
+
+void AusgangstuerOeffnen(int x, int y)
+{
+ int delay = 6;
+
+ if (!MovDelay[x][y]) /* next animation frame */
+ MovDelay[x][y] = 5*delay;
+
+ if (MovDelay[x][y]) /* wait some time before next frame */
+ {
+ int tuer;
+
+ MovDelay[x][y]--;
+ tuer = MovDelay[x][y]/delay;
+ if (!(MovDelay[x][y]%delay) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ DrawGraphic(SCREENX(x), SCREENY(y), GFX_AUSGANG_AUF-tuer);
+
+ if (!MovDelay[x][y])
+ {
+ Feld[x][y] = EL_AUSGANG_AUF;
+ DrawLevelField(x, y);
+ }
+ }
+}
+
+void AusgangstuerBlinken(int x, int y)
+{
+ DrawGraphicAnimation(x, y, GFX_AUSGANG_AUF, 4, 4, ANIM_OSCILLATE);
+}
+
+void OpenSwitchgate(int x, int y)
+{
+ int delay = 6;
+
+ if (!MovDelay[x][y]) /* next animation frame */
+ MovDelay[x][y] = 5 * delay;
+
+ if (MovDelay[x][y]) /* wait some time before next frame */
+ {
+ int phase;
+
+ MovDelay[x][y]--;
+ phase = MovDelay[x][y] / delay;
+ if (!(MovDelay[x][y] % delay) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ DrawGraphic(SCREENX(x), SCREENY(y), GFX_SWITCHGATE_OPEN - phase);
+
+ if (!MovDelay[x][y])
+ {
+ Feld[x][y] = EL_SWITCHGATE_OPEN;
+ DrawLevelField(x, y);
+ }
+ }
+}
+
+void CloseSwitchgate(int x, int y)
+{
+ int delay = 6;
+
+ if (!MovDelay[x][y]) /* next animation frame */
+ MovDelay[x][y] = 5 * delay;
+
+ if (MovDelay[x][y]) /* wait some time before next frame */
+ {
+ int phase;
+
+ MovDelay[x][y]--;
+ phase = MovDelay[x][y] / delay;
+ if (!(MovDelay[x][y] % delay) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ DrawGraphic(SCREENX(x), SCREENY(y), GFX_SWITCHGATE_CLOSED + phase);
+
+ if (!MovDelay[x][y])
+ {
+ Feld[x][y] = EL_SWITCHGATE_CLOSED;
+ DrawLevelField(x, y);
+ }
+ }
+}
+
+void OpenTimegate(int x, int y)
+{
+ int delay = 6;
+
+ if (!MovDelay[x][y]) /* next animation frame */
+ MovDelay[x][y] = 5 * delay;
+
+ if (MovDelay[x][y]) /* wait some time before next frame */
+ {
+ int phase;
+
+ MovDelay[x][y]--;
+ phase = MovDelay[x][y] / delay;
+ if (!(MovDelay[x][y] % delay) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ DrawGraphic(SCREENX(x), SCREENY(y), GFX_TIMEGATE_OPEN - phase);
+
+ if (!MovDelay[x][y])
+ {
+ Feld[x][y] = EL_TIMEGATE_OPEN;
+ DrawLevelField(x, y);
+ }
+ }
+}
+
+void CloseTimegate(int x, int y)
+{
+ int delay = 6;
+
+ if (!MovDelay[x][y]) /* next animation frame */
+ MovDelay[x][y] = 5 * delay;
+
+ if (MovDelay[x][y]) /* wait some time before next frame */
+ {
+ int phase;
+
+ MovDelay[x][y]--;
+ phase = MovDelay[x][y] / delay;
+ if (!(MovDelay[x][y] % delay) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ DrawGraphic(SCREENX(x), SCREENY(y), GFX_TIMEGATE_CLOSED + phase);
+
+ if (!MovDelay[x][y])
+ {
+ Feld[x][y] = EL_TIMEGATE_CLOSED;
+ DrawLevelField(x, y);
+ }
+ }
+}
+
+static void CloseAllOpenTimegates()
+{
+ 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_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
+ {
+ Feld[x][y] = EL_TIMEGATE_CLOSING;
+ PlaySoundLevel(x, y, SND_OEFFNEN);
+ }
+ }
+ }
+}
+
+void EdelsteinFunkeln(int x, int y)
+{
+ if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
+ return;
+
+ if (Feld[x][y] == EL_EDELSTEIN_BD)
+ DrawGraphicAnimation(x, y, GFX_EDELSTEIN_BD, 4, 4, ANIM_REVERSE);
+ else
+ {
+ if (!MovDelay[x][y]) /* next animation frame */
+ MovDelay[x][y] = 11 * !SimpleRND(500);
+
+ if (MovDelay[x][y]) /* wait some time before next frame */
+ {
+ MovDelay[x][y]--;
+
+ if (setup.direct_draw && MovDelay[x][y])
+ SetDrawtoField(DRAW_BUFFERED);
+
+ DrawGraphic(SCREENX(x), SCREENY(y), el2gfx(Feld[x][y]));
+
+ if (MovDelay[x][y])
+ {
+ int phase = (MovDelay[x][y]-1)/2;
+
+ if (phase > 2)
+ phase = 4-phase;
+
+ DrawGraphicThruMask(SCREENX(x), SCREENY(y), GFX_FUNKELN_WEISS + phase);
+
+ if (setup.direct_draw)
+ {
+ int dest_x, dest_y;
+
+ dest_x = FX + SCREENX(x)*TILEX;
+ dest_y = FY + SCREENY(y)*TILEY;
+
+ XCopyArea(display, drawto_field, window, gc,
+ dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
+ SetDrawtoField(DRAW_DIRECT);
+ }
+ }
+ }
+ }
+}
+
+void MauerWaechst(int x, int y)
+{
+ int delay = 6;
+
+ if (!MovDelay[x][y]) /* next animation frame */
+ MovDelay[x][y] = 3*delay;
+
+ if (MovDelay[x][y]) /* wait some time before next frame */
+ {
+ int phase;
+
+ MovDelay[x][y]--;
+ phase = 2-MovDelay[x][y]/delay;
+ if (!(MovDelay[x][y]%delay) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ DrawGraphic(SCREENX(x), SCREENY(y),
+ (MovDir[x][y] == MV_LEFT ? GFX_MAUER_LEFT :
+ MovDir[x][y] == MV_RIGHT ? GFX_MAUER_RIGHT :
+ MovDir[x][y] == MV_UP ? GFX_MAUER_UP :
+ GFX_MAUER_DOWN ) + phase);
+
+ if (!MovDelay[x][y])
+ {
+ if (MovDir[x][y] == MV_LEFT)
+ {
+ if (IN_LEV_FIELD(x-1, y) && IS_MAUER(Feld[x-1][y]))
+ DrawLevelField(x-1, y);
+ }
+ else if (MovDir[x][y] == MV_RIGHT)
+ {
+ if (IN_LEV_FIELD(x+1, y) && IS_MAUER(Feld[x+1][y]))
+ DrawLevelField(x+1, y);
+ }
+ else if (MovDir[x][y] == MV_UP)
+ {
+ if (IN_LEV_FIELD(x, y-1) && IS_MAUER(Feld[x][y-1]))
+ DrawLevelField(x, y-1);
+ }
+ else
+ {
+ if (IN_LEV_FIELD(x, y+1) && IS_MAUER(Feld[x][y+1]))
+ DrawLevelField(x, y+1);
+ }
+
+ Feld[x][y] = Store[x][y];
+ Store[x][y] = 0;
+ MovDir[x][y] = MV_NO_MOVING;
+ DrawLevelField(x, y);
+ }
+ }
+}
+
+void MauerAbleger(int ax, int ay)
+{
+ int element = Feld[ax][ay];
+ boolean oben_frei = FALSE, unten_frei = FALSE;
+ boolean links_frei = FALSE, rechts_frei = FALSE;
+ boolean oben_massiv = FALSE, unten_massiv = FALSE;
+ boolean links_massiv = FALSE, rechts_massiv = FALSE;
+
+ if (!MovDelay[ax][ay]) /* start building new wall */
+ MovDelay[ax][ay] = 6;
+
+ if (MovDelay[ax][ay]) /* wait some time before building new wall */
+ {
+ MovDelay[ax][ay]--;
+ if (MovDelay[ax][ay])
+ return;
+ }
+
+ if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
+ oben_frei = TRUE;
+ if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
+ unten_frei = TRUE;
+ if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
+ links_frei = TRUE;
+ if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
+ rechts_frei = TRUE;
+
+ if (element == EL_MAUER_Y || element == EL_MAUER_XY)
+ {
+ if (oben_frei)
+ {
+ Feld[ax][ay-1] = EL_MAUERND;
+ Store[ax][ay-1] = element;
+ MovDir[ax][ay-1] = MV_UP;
+ if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
+ DrawGraphic(SCREENX(ax), SCREENY(ay-1), GFX_MAUER_UP);
+ }
+ if (unten_frei)
+ {
+ Feld[ax][ay+1] = EL_MAUERND;
+ Store[ax][ay+1] = element;
+ MovDir[ax][ay+1] = MV_DOWN;
+ if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
+ DrawGraphic(SCREENX(ax), SCREENY(ay+1), GFX_MAUER_DOWN);
+ }
+ }
+
+ if (element == EL_MAUER_X || element == EL_MAUER_XY ||
+ element == EL_MAUER_LEBT)
+ {
+ if (links_frei)
+ {
+ Feld[ax-1][ay] = EL_MAUERND;
+ Store[ax-1][ay] = element;
+ MovDir[ax-1][ay] = MV_LEFT;
+ if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
+ DrawGraphic(SCREENX(ax-1), SCREENY(ay), GFX_MAUER_LEFT);
+ }
+ if (rechts_frei)
+ {
+ Feld[ax+1][ay] = EL_MAUERND;
+ Store[ax+1][ay] = element;
+ MovDir[ax+1][ay] = MV_RIGHT;
+ if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
+ DrawGraphic(SCREENX(ax+1), SCREENY(ay), GFX_MAUER_RIGHT);
+ }
+ }
+
+ if (element == EL_MAUER_LEBT && (links_frei || rechts_frei))
+ DrawLevelField(ax, ay);
+
+ if (!IN_LEV_FIELD(ax, ay-1) || IS_MAUER(Feld[ax][ay-1]))
+ oben_massiv = TRUE;
+ if (!IN_LEV_FIELD(ax, ay+1) || IS_MAUER(Feld[ax][ay+1]))
+ unten_massiv = TRUE;
+ if (!IN_LEV_FIELD(ax-1, ay) || IS_MAUER(Feld[ax-1][ay]))
+ links_massiv = TRUE;
+ if (!IN_LEV_FIELD(ax+1, ay) || IS_MAUER(Feld[ax+1][ay]))
+ rechts_massiv = TRUE;
+
+ if (((oben_massiv && unten_massiv) ||
+ element == EL_MAUER_X || element == EL_MAUER_LEBT) &&
+ ((links_massiv && rechts_massiv) ||
+ element == EL_MAUER_Y))
+ Feld[ax][ay] = EL_MAUERWERK;
+}
+
+void CheckForDragon(int x, int y)
+{
+ int i, j;
+ boolean dragon_found = FALSE;
+ static int xy[4][2] =
+ {
+ { 0, -1 },
+ { -1, 0 },
+ { +1, 0 },
+ { 0, +1 }
+ };
+
+ for (i=0; i<4; i++)
+ {
+ for (j=0; j<4; j++)
+ {
+ int xx = x + j*xy[i][0], yy = y + j*xy[i][1];
+
+ if (IN_LEV_FIELD(xx, yy) &&
+ (Feld[xx][yy] == EL_BURNING || Feld[xx][yy] == EL_DRACHE))
+ {
+ if (Feld[xx][yy] == EL_DRACHE)
+ dragon_found = TRUE;
+ }
+ else
+ break;
+ }
+ }
+
+ if (!dragon_found)
+ {
+ for (i=0; i<4; i++)
+ {
+ for (j=0; j<3; j++)
+ {
+ int xx = x + j*xy[i][0], yy = y + j*xy[i][1];
+
+ if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_BURNING)
+ {
+ Feld[xx][yy] = EL_LEERRAUM;
+ DrawLevelField(xx, yy);
+ }
+ else
+ break;
+ }
+ }
+ }
+}
+
+static void CheckBuggyBase(int x, int y)
+{
+ int element = Feld[x][y];
+
+ if (element == EL_SP_BUG)
+ {
+ if (!MovDelay[x][y]) /* wait some time before activating base */
+ MovDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
+
+ if (MovDelay[x][y])
+ {
+ MovDelay[x][y]--;
+ if (MovDelay[x][y] < 5 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ DrawGraphic(SCREENX(x), SCREENY(y), GFX_SP_BUG_WARNING);
+ if (MovDelay[x][y])
+ return;
+
+ Feld[x][y] = EL_SP_BUG_ACTIVE;
+ }
+ }
+ else if (element == EL_SP_BUG_ACTIVE)
+ {
+ if (!MovDelay[x][y]) /* start activating buggy base */
+ MovDelay[x][y] = 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND);
+
+ if (MovDelay[x][y])
+ {
+ MovDelay[x][y]--;
+ if (MovDelay[x][y])
+ {
+ int i;
+ static int xy[4][2] =
+ {
+ { 0, -1 },
+ { -1, 0 },
+ { +1, 0 },
+ { 0, +1 }
+ };
+
+ if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ DrawGraphic(SCREENX(x),SCREENY(y), GFX_SP_BUG_ACTIVE + SimpleRND(4));
+
+ for (i=0; i<4; i++)
+ {
+ int xx = x + xy[i][0], yy = y + xy[i][1];
+
+ if (IS_PLAYER(xx, yy))
+ {
+ PlaySoundLevel(x, y, SND_SP_BUG);
+ break;
+ }
+ }
+
+ return;
+ }
+
+ Feld[x][y] = EL_SP_BUG;
+ DrawLevelField(x, y);
+ }
+ }
+}
+
+static void CheckTrap(int x, int y)
+{
+ int element = Feld[x][y];
+
+ if (element == EL_TRAP_INACTIVE)
+ {
+ if (!MovDelay[x][y]) /* wait some time before activating trap */
+ MovDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
+
+ if (MovDelay[x][y])
+ {
+ MovDelay[x][y]--;
+ if (MovDelay[x][y])
+ return;
+
+ Feld[x][y] = EL_TRAP_ACTIVE;
+ }
+ }
+ else if (element == EL_TRAP_ACTIVE)
+ {
+ int delay = 4;
+ int num_frames = 8;
+
+ if (!MovDelay[x][y]) /* start activating trap */
+ MovDelay[x][y] = num_frames * delay;
+
+ if (MovDelay[x][y])
+ {
+ MovDelay[x][y]--;
+
+ if (MovDelay[x][y])
+ {
+ if (!(MovDelay[x][y] % delay))
+ {
+ int phase = MovDelay[x][y]/delay;
+
+ if (phase >= num_frames/2)
+ phase = num_frames - phase;
+
+ if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ {
+ DrawGraphic(SCREENX(x),SCREENY(y), GFX_TRAP_INACTIVE + phase - 1);
+ ErdreichAnbroeckeln(SCREENX(x), SCREENY(y));
+ }
+ }
+
+ return;
+ }
+
+ Feld[x][y] = EL_TRAP_INACTIVE;
+ DrawLevelField(x, y);
+ }
+ }
+}
+
+static void DrawBeltAnimation(int x, int y, int element)
+{
+ int belt_nr = getBeltNrFromElement(element);
+ int belt_dir = game.belt_dir[belt_nr];
+
+ if (belt_dir != MV_NO_MOVING)
+ {
+ int delay = 2;
+ int mode = (belt_dir == MV_LEFT ? ANIM_NORMAL : ANIM_REVERSE);
+ int graphic = el2gfx(element) + (belt_dir == MV_LEFT ? 0 : 7);
+
+ DrawGraphicAnimation(x, y, graphic, 8, delay, mode);
+ }
+}
+
+static void PlayerActions(struct PlayerInfo *player, byte player_action)
+{
+ static byte stored_player_action[MAX_PLAYERS];
+ static int num_stored_actions = 0;
+ static boolean save_tape_entry = FALSE;
+ boolean moved = FALSE, snapped = FALSE, bombed = FALSE;
+ int jx = player->jx, jy = player->jy;
+ int left = player_action & JOY_LEFT;
+ int right = player_action & JOY_RIGHT;
+ int up = player_action & JOY_UP;
+ int down = player_action & JOY_DOWN;
+ int button1 = player_action & JOY_BUTTON_1;
+ int button2 = player_action & JOY_BUTTON_2;
+ int dx = (left ? -1 : right ? 1 : 0);
+ int dy = (up ? -1 : down ? 1 : 0);
+
+ stored_player_action[player->index_nr] = 0;
+ num_stored_actions++;
+
+ if (!player->active || tape.pausing)
+ return;
+
+ if (player_action)
+ {
+ save_tape_entry = TRUE;
+ player->frame_reset_delay = 0;
+
+ if (button1)
+ snapped = SnapField(player, dx, dy);
+ else
+ {
+ if (button2)
+ bombed = PlaceBomb(player);
+ moved = MoveFigure(player, dx, dy);
+ }
+
+ if (tape.recording && (moved || snapped || bombed))
+ {
+ if (bombed && !moved)
+ player_action &= JOY_BUTTON;
+
+ stored_player_action[player->index_nr] = player_action;
+ }
+ else if (tape.playing && snapped)
+ SnapField(player, 0, 0); /* stop snapping */
+ }
+ else
+ {
+ /* no actions for this player (no input at player's configured device) */
+
+ DigField(player, 0, 0, 0, 0, DF_NO_PUSH);
+ SnapField(player, 0, 0);
+ CheckGravityMovement(player);
+
+ if (++player->frame_reset_delay > player->move_delay_value)
+ player->Frame = 0;
+ }
+
+ if (tape.recording && num_stored_actions >= MAX_PLAYERS && save_tape_entry)
+ {
+ TapeRecordAction(stored_player_action);
+ num_stored_actions = 0;
+ save_tape_entry = FALSE;
+ }
+
+ if (tape.playing && !tape.pausing && !player_action &&
+ tape.counter < tape.length)
+ {
+ int next_joy =
+ tape.pos[tape.counter].action[player->index_nr] & (JOY_LEFT|JOY_RIGHT);
+
+ if ((next_joy == JOY_LEFT || next_joy == JOY_RIGHT) &&
+ (player->MovDir != JOY_UP && player->MovDir != JOY_DOWN))
+ {
+ int dx = (next_joy == JOY_LEFT ? -1 : +1);
+
+ if (IN_LEV_FIELD(jx+dx, jy) && IS_PUSHABLE(Feld[jx+dx][jy]))
+ {
+ int el = Feld[jx+dx][jy];
+ int push_delay = (IS_SB_ELEMENT(el) || el == EL_SONDE ? 2 :
+ el == EL_BALLOON ? 0 : 10);
+
+ if (tape.delay_played + push_delay >= tape.pos[tape.counter].delay)
+ {
+ player->MovDir = next_joy;
+ player->Frame = FrameCounter % 4;
+ player->Pushing = TRUE;
+ }
+ }
+ }
+ }
+}
+
+void GameActions()
+{
+ static unsigned long action_delay = 0;
+ unsigned long action_delay_value;
+ int sieb_x = 0, sieb_y = 0;
+ int i, x, y, element;
+ byte *recorded_player_action;
+ byte summarized_player_action = 0;
+
+ if (game_status != PLAYING)
+ return;