+ 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_AMOEBA_SHRINKING))
+ 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)
+ {
+ if ((MovDir[x][y] == MV_LEFT || MovDir[x][y] == MV_RIGHT) &&
+ (!IN_LEV_FIELD(move_x, move_y) || !IS_FREE(move_x, move_y) ||
+ (IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))
+ MovDir[x][y] = MV_NO_MOVING;
+
+ MovDelay[x][y] = 0;
+ }
+ else if (element == EL_ROBOT ||
+ element == EL_SATELLITE ||
+ element == EL_PENGUIN)
+ {
+ 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_PENGUIN)
+ {
+ 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_EXIT_OPEN)
+ {
+ 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_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
+ MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
+ 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_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
+ {
+ boolean first_horiz = RND(2);
+ int new_move_dir = MovDir[x][y];
+
+ MovDir[x][y] =
+ new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
+ Moving2Blocked(x, y, &newx, &newy);
+
+ if (IN_LEV_FIELD(newx, newy) &&
+ (IS_FREE(newx, newy) ||
+ Feld[newx][newy] == EL_ACID ||
+ (element == EL_PENGUIN &&
+ (Feld[newx][newy] == EL_EXIT_OPEN ||
+ IS_FOOD_PENGUIN(Feld[newx][newy])))))
+ return;
+
+ MovDir[x][y] =
+ new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
+ Moving2Blocked(x, y, &newx, &newy);
+
+ if (IN_LEV_FIELD(newx, newy) &&
+ (IS_FREE(newx, newy) ||
+ Feld[newx][newy] == EL_ACID ||
+ (element == EL_PENGUIN &&
+ (Feld[newx][newy] == EL_EXIT_OPEN ||
+ IS_FOOD_PENGUIN(Feld[newx][newy])))))
+ return;
+
+ MovDir[x][y] = old_move_dir;
+ return;
+ }
+ }
+ }
+ else if (element_info[element].move_pattern == MV_ALL_DIRECTIONS)
+ {
+ boolean can_turn_left = FALSE, can_turn_right = FALSE;
+
+ if (IN_LEV_FIELD(left_x, left_y) &&
+ (IS_FREE(left_x, left_y) ||
+ (DONT_COLLIDE_WITH(element) && IS_FREE_OR_PLAYER(left_x, left_y))))
+ can_turn_left = TRUE;
+ if (IN_LEV_FIELD(right_x, right_y) &&
+ (IS_FREE(right_x, right_y) ||
+ (DONT_COLLIDE_WITH(element) && IS_FREE_OR_PLAYER(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] = GET_NEW_MOVE_DELAY(element);
+ }
+ else if (element_info[element].move_pattern == MV_HORIZONTAL ||
+ element_info[element].move_pattern == MV_VERTICAL)
+ {
+ if (element_info[element].move_pattern & old_move_dir)
+ MovDir[x][y] = back_dir;
+ else if (element_info[element].move_pattern == MV_HORIZONTAL)
+ MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
+ else if (element_info[element].move_pattern == MV_VERTICAL)
+ MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
+
+ MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
+ }
+ else if (element_info[element].move_pattern & MV_ANY_DIRECTION)
+ {
+ MovDir[x][y] = element_info[element].move_pattern;
+ MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
+ }
+ else if (element_info[element].move_pattern == MV_ALONG_LEFT_SIDE)
+ {
+ if (IN_LEV_FIELD(left_x, left_y) &&
+ (IS_FREE(left_x, left_y) ||
+ (DONT_COLLIDE_WITH(element) && IS_FREE_OR_PLAYER(left_x, left_y))))
+ MovDir[x][y] = left_dir;
+ else if (!IN_LEV_FIELD(move_x, move_y) ||
+ (!IS_FREE(move_x, move_y) &&
+ (!DONT_COLLIDE_WITH(element) || !IS_FREE_OR_PLAYER(move_x, move_y))))