+ Delay(wait_delay_value);
+ }
+
+ screen_x_old = screen_x;
+ screen_y_old = screen_y;
+ }
+
+ if (force_redraw)
+ {
+ for (y = 0; y < MAX_BUF_YSIZE; y++)
+ {
+ for (x = 0; x < MAX_BUF_XSIZE; x++)
+ {
+ screentiles[y][x] = -1;
+ crumbled_state[y][x] = 0;
+ }
+ }
+ }
+
+ /* calculate new screen scrolling position, with regard to scroll delay */
+ screen_x = VALID_SCREEN_X(sx + offset_x < screen_x ? sx + offset_x :
+ sx - offset_x > screen_x ? sx - offset_x :
+ screen_x);
+ screen_y = VALID_SCREEN_Y(sy + offset_y < screen_y ? sy + offset_y :
+ sy - offset_y > screen_y ? sy - offset_y :
+ screen_y);
+
+ /* prevent scrolling further than double player step size when scrolling */
+ if (ABS(screen_x - screen_x_old) > 2 * stepsize)
+ {
+ int dx = SIGN(screen_x - screen_x_old);
+
+ screen_x = screen_x_old + dx * 2 * stepsize;
+ }
+ if (ABS(screen_y - screen_y_old) > 2 * stepsize)
+ {
+ int dy = SIGN(screen_y - screen_y_old);
+
+ screen_y = screen_y_old + dy * 2 * stepsize;
+ }
+
+ /* prevent scrolling away from the other players when focus on all players */
+ if (game.centered_player_nr == -1)
+ {
+ /* check if all players are still visible with new scrolling position */
+ if (checkIfAllPlayersAreVisible(screen_x_old, screen_y_old) &&
+ !checkIfAllPlayersAreVisible(screen_x, screen_y))
+ {
+ /* reset horizontal scroll position to last value, if needed */
+ if (!checkIfAllPlayersAreVisible(screen_x, screen_y_old))
+ screen_x = screen_x_old;
+
+ /* reset vertical scroll position to last value, if needed */
+ if (!checkIfAllPlayersAreVisible(screen_x_old, screen_y))
+ screen_y = screen_y_old;
+ }
+ }
+
+ /* prevent scrolling (for screen correcting) if no player is moving */
+ if (!game_em.any_player_moving)
+ {
+ screen_x = screen_x_old;
+ screen_y = screen_y_old;
+ }
+ else
+ {
+ /* prevent scrolling against the players move direction */
+ int player_nr = (game.centered_player_nr == -1 ?
+ max_center_distance_player_nr : game.centered_player_nr);
+ int player_move_dir = game_em.last_player_direction[player_nr];
+ int dx = SIGN(screen_x - screen_x_old);
+ int dy = SIGN(screen_y - screen_y_old);
+
+ if ((dx < 0 && player_move_dir != MV_LEFT) ||
+ (dx > 0 && player_move_dir != MV_RIGHT))
+ screen_x = screen_x_old;
+
+ if ((dy < 0 && player_move_dir != MV_UP) ||
+ (dy > 0 && player_move_dir != MV_DOWN))
+ screen_y = screen_y_old;
+ }