+ int element = Feld[xx][yy];
+
+ if (element == EL_SWITCHGATE_SWITCH_1 ||
+ element == EL_SWITCHGATE_SWITCH_2)
+ {
+ Feld[xx][yy] = EL_SWITCHGATE_SWITCH_1 + game.switchgate_pos;
+ DrawLevelField(xx, yy);
+ }
+ else if (element == EL_SWITCHGATE_OPEN ||
+ element == EL_SWITCHGATE_OPENING)
+ {
+ Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
+ PlaySoundLevel(xx, yy, SND_OEFFNEN);
+ }
+ else if (element == EL_SWITCHGATE_CLOSED ||
+ element == EL_SWITCHGATE_CLOSING)
+ {
+ Feld[xx][yy] = EL_SWITCHGATE_OPENING;
+ PlaySoundLevel(xx, yy, SND_OEFFNEN);
+ }
+ }
+ }
+}
+
+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_OFF &&
+ game.light_time_left > 0)
+ {
+ Feld[x][y] = EL_LIGHT_SWITCH_ON;
+ DrawLevelField(x, y);
+ }
+ else if (element == EL_LIGHT_SWITCH_ON &&
+ game.light_time_left == 0)
+ {
+ Feld[x][y] = EL_LIGHT_SWITCH_OFF;
+ DrawLevelField(x, y);
+ }
+
+ if (element == EL_INVISIBLE_STEEL ||
+ element == EL_UNSICHTBAR ||
+ element == EL_SAND_INVISIBLE)
+ DrawLevelField(x, y);
+ }
+ }
+}
+
+static void ToggleLightSwitch(int x, int y)
+{
+ int element = Feld[x][y];
+
+ game.light_time_left =
+ (element == EL_LIGHT_SWITCH_OFF ?
+ 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;
+ PlaySoundLevel(xx, yy, SND_OEFFNEN);
+ }
+
+ /*
+ else if (element == EL_TIMEGATE_SWITCH_ON)
+ {
+ Feld[xx][yy] = EL_TIMEGATE_SWITCH_OFF;
+ DrawLevelField(xx, yy);
+ }
+ */
+
+ }
+ }
+
+ Feld[x][y] = EL_TIMEGATE_SWITCH_ON;
+}
+
+void Impact(int x, int y)
+{
+ boolean lastline = (y == lev_fieldy-1);
+ boolean object_hit = FALSE;
+ int element = Feld[x][y];
+ int smashed = 0;
+
+ 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 (object_hit)
+ smashed = MovingOrBlocked2Element(x, y+1);
+ }
+
+ if (!lastline && smashed == EL_SALZSAEURE) /* element falls into acid */
+ {
+ Blurb(x, y);
+ return;
+ }
+
+ if ((element == EL_BOMBE ||
+ element == EL_SP_DISK_ORANGE ||
+ element == EL_DX_SUPABOMB) &&
+ (lastline || object_hit)) /* element is bomb */
+ {
+ Bang(x, y);
+ return;
+ }
+ else if (element == EL_PEARL)
+ {
+ Feld[x][y] = EL_PEARL_BREAKING;
+ PlaySoundLevel(x, y, SND_KNACK);
+ return;
+ }
+
+ if (element == EL_TROPFEN && (lastline || object_hit)) /* acid drop */
+ {
+ if (object_hit && IS_PLAYER(x, y+1))
+ KillHeroUnlessProtected(x, y+1);
+ else if (object_hit && smashed == EL_PINGUIN)
+ Bang(x, y+1);
+ else
+ {
+ Feld[x][y] = EL_AMOEBING;
+ Store[x][y] = EL_AMOEBE_NASS;
+ }
+ return;
+ }
+
+ if (!lastline && object_hit) /* check which object was hit */
+ {
+ if (CAN_CHANGE(element) &&
+ (smashed == EL_MAGIC_WALL_OFF || smashed == EL_MAGIC_WALL_BD_OFF))
+ {
+ int x, y;
+ int activated_magic_wall =
+ (smashed == EL_MAGIC_WALL_OFF ? EL_MAGIC_WALL_EMPTY :
+ EL_MAGIC_WALL_BD_EMPTY);
+
+ /* activate magic wall / mill */
+
+ for (y=0; y<lev_fieldy; y++)
+ for (x=0; x<lev_fieldx; x++)
+ if (Feld[x][y] == smashed)
+ Feld[x][y] = activated_magic_wall;
+
+ game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
+ game.magic_wall_active = TRUE;
+ }
+
+ if (IS_PLAYER(x, y+1))
+ {
+ KillHeroUnlessProtected(x, y+1);
+ return;
+ }
+ else if (smashed == EL_PINGUIN)
+ {
+ Bang(x, y+1);
+ return;
+ }
+ else if (element == EL_EDELSTEIN_BD)
+ {
+ if (IS_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
+ {
+ Bang(x, y+1);
+ return;
+ }
+ }
+ else if (element == EL_FELSBROCKEN ||
+ element == EL_SP_ZONK ||
+ element == EL_BD_ROCK)
+ {
+ if (IS_ENEMY(smashed) ||
+ smashed == EL_BOMBE || smashed == EL_SP_DISK_ORANGE ||
+ smashed == EL_DX_SUPABOMB ||
+ smashed == EL_SONDE || smashed == EL_SCHWEIN ||
+ smashed == EL_DRACHE || smashed == EL_MOLE)
+ {
+ Bang(x, y+1);
+ return;
+ }
+ else if (!IS_MOVING(x, y+1))
+ {
+ if (smashed == EL_BIRNE_AUS || smashed == EL_BIRNE_EIN)
+ {
+ Bang(x, y+1);
+ return;
+ }
+ else if (smashed == EL_KOKOSNUSS)
+ {
+ Feld[x][y+1] = EL_CRACKINGNUT;
+ PlaySoundLevel(x, y, SND_KNACK);
+ RaiseScoreElement(EL_KOKOSNUSS);
+ return;
+ }
+ else if (smashed == EL_PEARL)
+ {
+ Feld[x][y+1] = EL_PEARL_BREAKING;
+ PlaySoundLevel(x, y, SND_KNACK);
+ return;
+ }
+ else if (smashed == EL_DIAMANT)
+ {
+ Feld[x][y+1] = EL_LEERRAUM;
+ PlaySoundLevel(x, y, SND_QUIRK);
+ return;
+ }
+ else if (IS_BELT_SWITCH(smashed))
+ {
+ ToggleBeltSwitch(x, y+1);
+ }
+ else if (smashed == EL_SWITCHGATE_SWITCH_1 ||
+ smashed == EL_SWITCHGATE_SWITCH_2)
+ {
+ ToggleSwitchgateSwitch(x, y+1);
+ }
+ else if (smashed == EL_LIGHT_SWITCH_OFF ||
+ smashed == EL_LIGHT_SWITCH_ON)
+ {
+ ToggleLightSwitch(x, y+1);
+ }
+ }
+ }
+ }
+
+ /* play sound of magic wall / mill */
+ if (!lastline &&
+ (Feld[x][y+1] == EL_MAGIC_WALL_EMPTY ||
+ Feld[x][y+1] == EL_MAGIC_WALL_BD_EMPTY))
+ {
+ PlaySoundLevel(x, y, SND_QUIRK);
+ return;
+ }
+
+ /* play sound of object that hits the ground */
+ if (lastline || object_hit)
+ {
+ int sound;
+
+ switch(element)
+ {
+ case EL_EDELSTEIN:
+ case EL_EDELSTEIN_BD:
+ case EL_EDELSTEIN_GELB:
+ case EL_EDELSTEIN_ROT:
+ case EL_EDELSTEIN_LILA:
+ case EL_DIAMANT:
+ case EL_SP_INFOTRON:
+ sound = SND_PLING;
+ break;
+ case EL_KOKOSNUSS:
+ sound = SND_KLUMPF;
+ break;
+ case EL_FELSBROCKEN:
+ case EL_BD_ROCK:
+ sound = SND_KLOPF;
+ break;
+ case EL_SP_ZONK:
+ sound = SND_SP_ZONKDOWN;
+ break;
+ case EL_SCHLUESSEL:
+ case EL_SCHLUESSEL1:
+ case EL_SCHLUESSEL2:
+ case EL_SCHLUESSEL3:
+ case EL_SCHLUESSEL4:
+ case EL_EM_KEY_1:
+ case EL_EM_KEY_2:
+ case EL_EM_KEY_3:
+ case EL_EM_KEY_4:
+ sound = SND_KINK;
+ break;
+ case EL_ZEIT_VOLL:
+ case EL_ZEIT_LEER:
+ sound = SND_DENG;
+ break;
+ default:
+ sound = -1;
+ break;
+ }
+
+ if (sound >= 0)
+ PlaySoundLevel(x, y, sound);
+ }
+}
+
+void TurnRound(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 }
+ };
+ static struct
+ {
+ int left, right, back;
+ } turn[] =
+ {
+ { 0, 0, 0 },
+ { MV_DOWN, MV_UP, MV_RIGHT },
+ { MV_UP, MV_DOWN, MV_LEFT },
+ { 0, 0, 0 },
+ { MV_LEFT, MV_RIGHT, MV_DOWN },
+ { 0,0,0 }, { 0,0,0 }, { 0,0,0 },
+ { MV_RIGHT, MV_LEFT, MV_UP }
+ };
+
+ int element = Feld[x][y];
+ int old_move_dir = MovDir[x][y];
+ int left_dir = turn[old_move_dir].left;
+ int right_dir = turn[old_move_dir].right;
+ int back_dir = turn[old_move_dir].back;
+
+ int left_dx = move_xy[left_dir].x, left_dy = move_xy[left_dir].y;
+ int right_dx = move_xy[right_dir].x, right_dy = move_xy[right_dir].y;
+ int move_dx = move_xy[old_move_dir].x, move_dy = move_xy[old_move_dir].y;
+ int back_dx = move_xy[back_dir].x, back_dy = move_xy[back_dir].y;
+
+ int left_x = x+left_dx, left_y = y+left_dy;
+ int right_x = x+right_dx, right_y = y+right_dy;
+ int move_x = x+move_dx, move_y = y+move_dy;
+
+ if (element == EL_KAEFER || element == EL_BUTTERFLY)
+ {
+ TestIfBadThingHitsOtherBadThing(x, y);
+
+ if (IN_LEV_FIELD(right_x, right_y) &&
+ IS_FREE(right_x, right_y))
+ MovDir[x][y] = right_dir;
+ else if (!IN_LEV_FIELD(move_x, move_y) ||
+ !IS_FREE(move_x, move_y))
+ MovDir[x][y] = left_dir;
+
+ if (element == EL_KAEFER && MovDir[x][y] != old_move_dir)
+ MovDelay[x][y] = 9;
+ else if (element == EL_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
+ MovDelay[x][y] = 1;
+ }
+ else if (element == EL_FLIEGER || element == EL_FIREFLY ||
+ element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
+ {
+ TestIfBadThingHitsOtherBadThing(x, y);
+
+ if (IN_LEV_FIELD(left_x, left_y) &&
+ IS_FREE(left_x, left_y))
+ MovDir[x][y] = left_dir;
+ else if (!IN_LEV_FIELD(move_x, move_y) ||
+ !IS_FREE(move_x, move_y))
+ MovDir[x][y] = right_dir;
+
+ if ((element == EL_FLIEGER ||
+ element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
+ && MovDir[x][y] != old_move_dir)
+ MovDelay[x][y] = 9;
+ else if (element == EL_FIREFLY) /* && MovDir[x][y] == right_dir) */
+ MovDelay[x][y] = 1;
+ }
+ else if (element == EL_MAMPFER)
+ {
+ boolean can_turn_left = FALSE, can_turn_right = FALSE;
+
+ if (IN_LEV_FIELD(left_x, left_y) &&
+ (IS_FREE_OR_PLAYER(left_x, left_y) ||
+ Feld[left_x][left_y] == EL_DIAMANT))
+ can_turn_left = TRUE;
+ if (IN_LEV_FIELD(right_x, right_y) &&
+ (IS_FREE_OR_PLAYER(right_x, right_y) ||
+ Feld[right_x][right_y] == EL_DIAMANT))
+ can_turn_right = TRUE;
+
+ if (can_turn_left && can_turn_right)
+ MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
+ else if (can_turn_left)
+ MovDir[x][y] = (RND(2) ? left_dir : back_dir);
+ else if (can_turn_right)
+ MovDir[x][y] = (RND(2) ? right_dir : back_dir);
+ else
+ MovDir[x][y] = back_dir;
+
+ MovDelay[x][y] = 16+16*RND(3);
+ }
+ else if (element == EL_MAMPFER2)
+ {
+ boolean can_turn_left = FALSE, can_turn_right = FALSE;
+
+ if (IN_LEV_FIELD(left_x, left_y) &&
+ (IS_FREE_OR_PLAYER(left_x, left_y) ||
+ IS_MAMPF2(Feld[left_x][left_y])))
+ can_turn_left = TRUE;
+ if (IN_LEV_FIELD(right_x, right_y) &&
+ (IS_FREE_OR_PLAYER(right_x, right_y) ||
+ IS_MAMPF2(Feld[right_x][right_y])))
+ can_turn_right = TRUE;
+
+ if (can_turn_left && can_turn_right)
+ MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
+ else if (can_turn_left)
+ MovDir[x][y] = (RND(2) ? left_dir : back_dir);
+ else if (can_turn_right)
+ MovDir[x][y] = (RND(2) ? right_dir : back_dir);
+ else
+ MovDir[x][y] = back_dir;
+
+ MovDelay[x][y] = 16+16*RND(3);
+ }
+ else if (element == EL_PACMAN)
+ {
+ boolean can_turn_left = FALSE, can_turn_right = FALSE;
+
+ if (IN_LEV_FIELD(left_x, left_y) &&
+ (IS_FREE_OR_PLAYER(left_x, left_y) ||
+ IS_AMOEBOID(Feld[left_x][left_y])))
+ can_turn_left = TRUE;
+ if (IN_LEV_FIELD(right_x, right_y) &&
+ (IS_FREE_OR_PLAYER(right_x, right_y) ||
+ IS_AMOEBOID(Feld[right_x][right_y])))
+ can_turn_right = TRUE;
+
+ if (can_turn_left && can_turn_right)
+ MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
+ else if (can_turn_left)
+ MovDir[x][y] = (RND(2) ? left_dir : back_dir);
+ else if (can_turn_right)
+ MovDir[x][y] = (RND(2) ? right_dir : back_dir);
+ else
+ MovDir[x][y] = back_dir;
+
+ MovDelay[x][y] = 6+RND(40);
+ }
+ else if (element == EL_SCHWEIN)
+ {
+ boolean can_turn_left = FALSE, can_turn_right = FALSE, can_move_on = FALSE;
+ boolean should_turn_left = FALSE, should_turn_right = FALSE;
+ boolean should_move_on = FALSE;
+ int rnd_value = 24;
+ int rnd = RND(rnd_value);
+
+ if (IN_LEV_FIELD(left_x, left_y) &&
+ (IS_FREE(left_x, left_y) || IS_GEM(Feld[left_x][left_y])))
+ can_turn_left = TRUE;
+ if (IN_LEV_FIELD(right_x, right_y) &&
+ (IS_FREE(right_x, right_y) || IS_GEM(Feld[right_x][right_y])))
+ can_turn_right = TRUE;
+ if (IN_LEV_FIELD(move_x, move_y) &&
+ (IS_FREE(move_x, move_y) || IS_GEM(Feld[move_x][move_y])))
+ can_move_on = TRUE;
+
+ if (can_turn_left &&
+ (!can_move_on ||
+ (IN_LEV_FIELD(x+back_dx+left_dx, y+back_dy+left_dy) &&
+ !IS_FREE(x+back_dx+left_dx, y+back_dy+left_dy))))
+ should_turn_left = TRUE;
+ if (can_turn_right &&
+ (!can_move_on ||
+ (IN_LEV_FIELD(x+back_dx+right_dx, y+back_dy+right_dy) &&
+ !IS_FREE(x+back_dx+right_dx, y+back_dy+right_dy))))
+ should_turn_right = TRUE;
+ if (can_move_on &&
+ (!can_turn_left || !can_turn_right ||
+ (IN_LEV_FIELD(x+move_dx+left_dx, y+move_dy+left_dy) &&
+ !IS_FREE(x+move_dx+left_dx, y+move_dy+left_dy)) ||
+ (IN_LEV_FIELD(x+move_dx+right_dx, y+move_dy+right_dy) &&
+ !IS_FREE(x+move_dx+right_dx, y+move_dy+right_dy))))
+ should_move_on = TRUE;
+
+ if (should_turn_left || should_turn_right || should_move_on)
+ {
+ if (should_turn_left && should_turn_right && should_move_on)
+ MovDir[x][y] = (rnd < rnd_value/3 ? left_dir :
+ rnd < 2*rnd_value/3 ? right_dir :
+ old_move_dir);
+ else if (should_turn_left && should_turn_right)
+ MovDir[x][y] = (rnd < rnd_value/2 ? left_dir : right_dir);
+ else if (should_turn_left && should_move_on)
+ MovDir[x][y] = (rnd < rnd_value/2 ? left_dir : old_move_dir);
+ else if (should_turn_right && should_move_on)
+ MovDir[x][y] = (rnd < rnd_value/2 ? right_dir : old_move_dir);
+ else if (should_turn_left)
+ MovDir[x][y] = left_dir;
+ else if (should_turn_right)
+ MovDir[x][y] = right_dir;
+ else if (should_move_on)
+ MovDir[x][y] = old_move_dir;
+ }
+ else if (can_move_on && rnd > rnd_value/8)
+ MovDir[x][y] = old_move_dir;
+ else if (can_turn_left && can_turn_right)
+ MovDir[x][y] = (rnd < rnd_value/2 ? left_dir : right_dir);
+ else if (can_turn_left && rnd > rnd_value/8)
+ MovDir[x][y] = left_dir;
+ else if (can_turn_right && rnd > rnd_value/8)
+ MovDir[x][y] = right_dir;
+ else
+ MovDir[x][y] = back_dir;
+
+ if (!IS_FREE(x+move_xy[MovDir[x][y]].x, y+move_xy[MovDir[x][y]].y) &&
+ !IS_GEM(Feld[x+move_xy[MovDir[x][y]].x][y+move_xy[MovDir[x][y]].y]))
+ MovDir[x][y] = old_move_dir;
+
+ MovDelay[x][y] = 0;
+ }
+ else if (element == EL_DRACHE)
+ {
+ boolean can_turn_left = FALSE, can_turn_right = FALSE, can_move_on = FALSE;
+ int rnd_value = 24;
+ int rnd = RND(rnd_value);
+
+ if (IN_LEV_FIELD(left_x, left_y) && IS_FREE(left_x, left_y))
+ can_turn_left = TRUE;
+ if (IN_LEV_FIELD(right_x, right_y) && IS_FREE(right_x, right_y))
+ can_turn_right = TRUE;
+ if (IN_LEV_FIELD(move_x, move_y) && IS_FREE(move_x, move_y))
+ can_move_on = TRUE;
+
+ if (can_move_on && rnd > rnd_value/8)
+ MovDir[x][y] = old_move_dir;
+ else if (can_turn_left && can_turn_right)
+ MovDir[x][y] = (rnd < rnd_value/2 ? left_dir : right_dir);
+ else if (can_turn_left && rnd > rnd_value/8)
+ MovDir[x][y] = left_dir;
+ else if (can_turn_right && rnd > rnd_value/8)
+ MovDir[x][y] = right_dir;
+ else
+ MovDir[x][y] = back_dir;
+
+ if (!IS_FREE(x+move_xy[MovDir[x][y]].x, y+move_xy[MovDir[x][y]].y))
+ MovDir[x][y] = old_move_dir;
+
+ MovDelay[x][y] = 0;
+ }
+ else if (element == EL_MOLE)
+ {
+ boolean can_turn_left = FALSE, can_turn_right = FALSE, can_move_on = FALSE;
+
+ if (IN_LEV_FIELD(move_x, move_y) &&
+ (IS_FREE(move_x, move_y) || IS_AMOEBOID(Feld[move_x][move_y]) ||
+ Feld[move_x][move_y] == EL_DEAMOEBING))
+ can_move_on = TRUE;
+
+ if (!can_move_on)
+ {
+ if (IN_LEV_FIELD(left_x, left_y) &&
+ (IS_FREE(left_x, left_y) || IS_AMOEBOID(Feld[left_x][left_y])))
+ can_turn_left = TRUE;
+ if (IN_LEV_FIELD(right_x, right_y) &&
+ (IS_FREE(right_x, right_y) || IS_AMOEBOID(Feld[right_x][right_y])))
+ can_turn_right = TRUE;
+
+ if (can_turn_left && can_turn_right)
+ MovDir[x][y] = (RND(2) ? left_dir : right_dir);
+ else if (can_turn_left)
+ MovDir[x][y] = left_dir;
+ else
+ MovDir[x][y] = right_dir;
+ }
+
+ if (MovDir[x][y] != old_move_dir)
+ MovDelay[x][y] = 9;
+ }
+ else if (element == EL_BALLOON)
+ {
+ MovDir[x][y] = game.balloon_dir;
+ MovDelay[x][y] = 0;
+ }
+ else if (element == EL_SPRING_MOVING)
+ {
+ if (!IN_LEV_FIELD(move_x, move_y) || !IS_FREE(move_x, move_y) ||
+ (IN_LEV_FIELD(x, y+1) && IS_FREE(x, y+1)))
+ {
+ Feld[x][y] = EL_SPRING;
+ MovDir[x][y] = MV_NO_MOVING;
+ }
+ MovDelay[x][y] = 0;
+ }
+ else if (element == EL_ROBOT || element == EL_SONDE || element == EL_PINGUIN)
+ {
+ int attr_x = -1, attr_y = -1;
+
+ if (AllPlayersGone)
+ {
+ attr_x = ExitX;
+ attr_y = ExitY;
+ }
+ else
+ {
+ int i;
+
+ for (i=0; i<MAX_PLAYERS; i++)
+ {
+ struct PlayerInfo *player = &stored_player[i];
+ int jx = player->jx, jy = player->jy;
+
+ if (!player->active)
+ continue;
+
+ if (attr_x == -1 || ABS(jx-x)+ABS(jy-y) < ABS(attr_x-x)+ABS(attr_y-y))
+ {
+ attr_x = jx;
+ attr_y = jy;
+ }
+ }
+ }
+
+ if (element == EL_ROBOT && ZX>=0 && ZY>=0)
+ {
+ attr_x = ZX;
+ attr_y = ZY;
+ }
+
+ if (element == EL_PINGUIN)
+ {
+ int i;
+ static int xy[4][2] =
+ {
+ { 0, -1 },
+ { -1, 0 },
+ { +1, 0 },
+ { 0, +1 }
+ };
+
+ for (i=0; i<4; i++)
+ {
+ int ex = x + xy[i%4][0];
+ int ey = y + xy[i%4][1];
+
+ if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_AUSGANG_AUF)
+ {
+ attr_x = ex;
+ attr_y = ey;
+ break;
+ }
+ }
+ }
+
+ MovDir[x][y] = MV_NO_MOVING;
+ if (attr_x<x)
+ MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
+ else if (attr_x>x)
+ MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
+ if (attr_y<y)
+ MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
+ else if (attr_y>y)
+ MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
+
+ if (element == EL_ROBOT)
+ {
+ int newx, newy;
+
+ if ((MovDir[x][y]&(MV_LEFT|MV_RIGHT)) && (MovDir[x][y]&(MV_UP|MV_DOWN)))
+ MovDir[x][y] &= (RND(2) ? (MV_LEFT|MV_RIGHT) : (MV_UP|MV_DOWN));
+ Moving2Blocked(x, y, &newx, &newy);
+
+ if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
+ MovDelay[x][y] = 8+8*!RND(3);
+ else
+ MovDelay[x][y] = 16;
+ }
+ else
+ {
+ int newx, newy;
+
+ MovDelay[x][y] = 1;
+
+ if ((MovDir[x][y]&(MV_LEFT|MV_RIGHT)) && (MovDir[x][y]&(MV_UP|MV_DOWN)))
+ {
+ boolean first_horiz = RND(2);
+ int new_move_dir = MovDir[x][y];
+
+ MovDir[x][y] =
+ new_move_dir & (first_horiz ? (MV_LEFT|MV_RIGHT) : (MV_UP|MV_DOWN));
+ Moving2Blocked(x, y, &newx, &newy);
+
+ if (IN_LEV_FIELD(newx, newy) &&
+ (IS_FREE(newx, newy) ||
+ Feld[newx][newy] == EL_SALZSAEURE ||
+ (element == EL_PINGUIN &&
+ (Feld[newx][newy] == EL_AUSGANG_AUF ||
+ IS_MAMPF3(Feld[newx][newy])))))
+ return;
+
+ MovDir[x][y] =
+ new_move_dir & (!first_horiz ? (MV_LEFT|MV_RIGHT) : (MV_UP|MV_DOWN));
+ Moving2Blocked(x, y, &newx, &newy);
+
+ if (IN_LEV_FIELD(newx, newy) &&
+ (IS_FREE(newx, newy) ||
+ Feld[newx][newy] == EL_SALZSAEURE ||
+ (element == EL_PINGUIN &&
+ (Feld[newx][newy] == EL_AUSGANG_AUF ||
+ IS_MAMPF3(Feld[newx][newy])))))
+ return;
+
+ MovDir[x][y] = old_move_dir;
+ return;
+ }
+ }
+ }
+}
+
+static boolean JustBeingPushed(int x, int y)
+{
+ int i;
+
+ for (i=0; i<MAX_PLAYERS; i++)
+ {
+ struct PlayerInfo *player = &stored_player[i];
+
+ if (player->active && player->Pushing && player->MovPos)
+ {
+ int next_jx = player->jx + (player->jx - player->last_jx);
+ int next_jy = player->jy + (player->jy - player->last_jy);
+
+ if (x == next_jx && y == next_jy)
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+void StartMoving(int x, int y)
+{
+ int element = Feld[x][y];
+
+ if (Stop[x][y])
+ return;
+
+ if (CAN_FALL(element) && y<lev_fieldy-1)
+ {
+ if ((x>0 && IS_PLAYER(x-1, y)) || (x<lev_fieldx-1 && IS_PLAYER(x+1, y)))
+ if (JustBeingPushed(x, y))
+ return;
+
+ if (element == EL_MORAST_VOLL)
+ {
+ if (IS_FREE(x, y+1))
+ {
+ InitMovingField(x, y, MV_DOWN);
+ Feld[x][y] = EL_FELSBROCKEN;
+ Store[x][y] = EL_MORAST_LEER;
+ }
+ else if (Feld[x][y+1] == EL_MORAST_LEER)
+ {
+ if (!MovDelay[x][y])
+ MovDelay[x][y] = TILEY + 1;
+
+ if (MovDelay[x][y])
+ {
+ MovDelay[x][y]--;
+ if (MovDelay[x][y])
+ return;
+ }
+
+ Feld[x][y] = EL_MORAST_LEER;
+ Feld[x][y+1] = EL_MORAST_VOLL;
+ }
+ }
+ else if ((element == EL_FELSBROCKEN || element == EL_BD_ROCK) &&
+ Feld[x][y+1] == EL_MORAST_LEER)
+ {
+ InitMovingField(x, y, MV_DOWN);
+ Store[x][y] = EL_MORAST_VOLL;
+ }
+ else if (element == EL_MAGIC_WALL_FULL)
+ {
+ if (IS_FREE(x, y+1))
+ {
+ InitMovingField(x, y, MV_DOWN);
+ Feld[x][y] = EL_CHANGED(Store2[x][y]);
+ Store[x][y] = EL_MAGIC_WALL_EMPTY;
+ }
+ else if (Feld[x][y+1] == EL_MAGIC_WALL_EMPTY)
+ {
+ if (!MovDelay[x][y])
+ MovDelay[x][y] = TILEY/4 + 1;
+
+ if (MovDelay[x][y])
+ {
+ MovDelay[x][y]--;
+ if (MovDelay[x][y])
+ return;
+ }
+
+ Feld[x][y] = EL_MAGIC_WALL_EMPTY;
+ Feld[x][y+1] = EL_MAGIC_WALL_FULL;
+ Store2[x][y+1] = EL_CHANGED(Store2[x][y]);
+ Store2[x][y] = 0;
+ }
+ }
+ else if (element == EL_MAGIC_WALL_BD_FULL)
+ {
+ if (IS_FREE(x, y+1))
+ {
+ InitMovingField(x, y, MV_DOWN);
+ Feld[x][y] = EL_CHANGED2(Store2[x][y]);
+ Store[x][y] = EL_MAGIC_WALL_BD_EMPTY;
+ }
+ else if (Feld[x][y+1] == EL_MAGIC_WALL_BD_EMPTY)
+ {
+ if (!MovDelay[x][y])
+ MovDelay[x][y] = TILEY/4 + 1;
+
+ if (MovDelay[x][y])
+ {
+ MovDelay[x][y]--;
+ if (MovDelay[x][y])
+ return;
+ }
+
+ Feld[x][y] = EL_MAGIC_WALL_BD_EMPTY;
+ Feld[x][y+1] = EL_MAGIC_WALL_BD_FULL;
+ Store2[x][y+1] = EL_CHANGED2(Store2[x][y]);
+ Store2[x][y] = 0;
+ }
+ }
+ else if (CAN_CHANGE(element) &&
+ (Feld[x][y+1] == EL_MAGIC_WALL_EMPTY ||
+ Feld[x][y+1] == EL_MAGIC_WALL_BD_EMPTY))
+ {
+ InitMovingField(x, y, MV_DOWN);
+ Store[x][y] =
+ (Feld[x][y+1] == EL_MAGIC_WALL_EMPTY ? EL_MAGIC_WALL_FULL :
+ EL_MAGIC_WALL_BD_FULL);
+ Store2[x][y+1] = element;
+ }
+ else if (CAN_SMASH(element) && Feld[x][y+1] == EL_SALZSAEURE)
+ {
+ Blurb(x, y);
+ InitMovingField(x, y, MV_DOWN);
+ Store[x][y] = EL_SALZSAEURE;
+ }
+ else if (CAN_SMASH(element) && Feld[x][y+1] == EL_BLOCKED &&
+ JustStopped[x][y])
+ {
+ Impact(x, y);
+ }
+ else if (IS_FREE(x, y+1))
+ {
+ InitMovingField(x, y, MV_DOWN);
+ }
+ else if (element == EL_TROPFEN)
+ {
+ Feld[x][y] = EL_AMOEBING;
+ Store[x][y] = EL_AMOEBE_NASS;
+ }
+#if OLD_GAME_BEHAVIOUR
+ else if (IS_SLIPPERY(Feld[x][y+1]) && !Store[x][y+1])
+#else
+ else if (IS_SLIPPERY(Feld[x][y+1]) && !Store[x][y+1] &&
+ !IS_FALLING(x, y+1) && !JustStopped[x][y+1] &&
+ element != EL_DX_SUPABOMB)
+#endif
+ {
+ boolean left = (x>0 && IS_FREE(x-1, y) &&
+ (IS_FREE(x-1, y+1) || Feld[x-1][y+1] == EL_SALZSAEURE));
+ boolean right = (x<lev_fieldx-1 && IS_FREE(x+1, y) &&
+ (IS_FREE(x+1, y+1) || Feld[x+1][y+1] == EL_SALZSAEURE));
+
+ if (left || right)
+ {
+ if (left && right &&
+ (game.emulation != EMU_BOULDERDASH &&
+ element != EL_BD_ROCK && element != EL_EDELSTEIN_BD))
+ left = !(right = RND(2));
+
+ InitMovingField(x, y, left ? MV_LEFT : MV_RIGHT);
+ }
+ }
+ else if (IS_BELT(Feld[x][y+1]))
+ {
+ boolean left_is_free = (x>0 && IS_FREE(x-1, y));
+ boolean right_is_free = (x<lev_fieldx-1 && IS_FREE(x+1, y));
+ int belt_nr = getBeltNrFromElement(Feld[x][y+1]);
+ int belt_dir = game.belt_dir[belt_nr];
+
+ if ((belt_dir == MV_LEFT && left_is_free) ||
+ (belt_dir == MV_RIGHT && right_is_free))
+ InitMovingField(x, y, belt_dir);
+ }
+ }
+ else if (CAN_MOVE(element))
+ {
+ int newx, newy;
+
+ if ((element == EL_SONDE || element == EL_BALLOON ||
+ element == EL_SPRING_MOVING)
+ && JustBeingPushed(x, y))
+ return;
+
+ if (!MovDelay[x][y]) /* start new movement phase */
+ {
+ /* all objects that can change their move direction after each step */
+ /* (MAMPFER, MAMPFER2 and PACMAN go straight until they hit a wall */
+
+ if (element!=EL_MAMPFER && element!=EL_MAMPFER2 && element!=EL_PACMAN)
+ {
+ TurnRound(x, y);
+ if (MovDelay[x][y] && (element == EL_KAEFER ||
+ element == EL_FLIEGER ||
+ element == EL_SP_SNIKSNAK ||
+ element == EL_SP_ELECTRON ||
+ element == EL_MOLE))
+ DrawLevelField(x, y);
+ }
+ }
+
+ if (MovDelay[x][y]) /* wait some time before next movement */
+ {
+ MovDelay[x][y]--;
+
+ if (element == EL_ROBOT ||
+ element == EL_MAMPFER || element == EL_MAMPFER2)
+ {
+ int phase = MovDelay[x][y] % 8;
+
+ if (phase>3)
+ phase = 7-phase;
+
+ 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;
+ else if (element == EL_SPRING_MOVING)
+ 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_MAGIC_WALL_FULL)
+ {
+ Store[x][y] = 0;
+ element = Feld[newx][newy] =
+ (game.magic_wall_active ? EL_MAGIC_WALL_FULL : EL_MAGIC_WALL_DEAD);
+ }
+ else if (Store[x][y] == EL_MAGIC_WALL_EMPTY)
+ {
+ Store[x][y] = Store2[x][y] = 0;
+ Feld[x][y] = (game.magic_wall_active ? EL_MAGIC_WALL_EMPTY :
+ EL_MAGIC_WALL_DEAD);
+ }
+ else if (Store[x][y] == EL_MAGIC_WALL_BD_FULL)
+ {
+ Store[x][y] = 0;
+ element = Feld[newx][newy] =
+ (game.magic_wall_active ? EL_MAGIC_WALL_BD_FULL :
+ EL_MAGIC_WALL_BD_DEAD);
+ }
+ else if (Store[x][y] == EL_MAGIC_WALL_BD_EMPTY)
+ {
+ Store[x][y] = Store2[x][y] = 0;
+ Feld[x][y] = (game.magic_wall_active ? EL_MAGIC_WALL_BD_EMPTY :
+ EL_MAGIC_WALL_BD_DEAD);
+ }
+ 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_BD_ROCK ? 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_BD_ROCK);
+ 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;