+ boolean draw_new_player_location = FALSE;
+ boolean draw_new_player_location_wrap = FALSE;
+ boolean quick_relocation = setup.quick_switch;
+ int max_center_distance_player_nr =
+ getMaxCenterDistancePlayerNr(screen_x, screen_y);
+ int stepsize = TILEX / 8;
+ int offset_raw = game.scroll_delay_value;
+ int offset_x = MIN(offset_raw, (SCR_FIELDX - 2) / 2) * TILEX;
+ int offset_y = MIN(offset_raw, (SCR_FIELDY - 2) / 2) * TILEY;
+ int screen_x_old = screen_x;
+ int screen_y_old = screen_y;
+ int x, y, sx, sy;
+ int i;
+
+ if (game.set_centered_player)
+ {
+ boolean all_players_fit_to_screen = checkIfAllPlayersFitToScreen();
+
+ /* switching to "all players" only possible if all players fit to screen */
+ if (game.centered_player_nr_next == -1 && !all_players_fit_to_screen)
+ {
+ game.centered_player_nr_next = game.centered_player_nr;
+ game.set_centered_player = FALSE;
+ }
+
+ /* do not switch focus to non-existing (or non-active) player */
+ if (game.centered_player_nr_next >= 0 &&
+ !ply[game.centered_player_nr_next].alive)
+ {
+ game.centered_player_nr_next = game.centered_player_nr;
+ game.set_centered_player = FALSE;
+ }
+ }
+
+ /* also allow focus switching when screen is scrolled to half tile */
+ if (game.set_centered_player)
+ {
+ game.centered_player_nr = game.centered_player_nr_next;
+
+ draw_new_player_location = TRUE;
+ draw_new_player_location_wrap = game.set_centered_player_wrap;
+ force_redraw = TRUE;
+
+ game.set_centered_player = FALSE;
+ game.set_centered_player_wrap = FALSE;
+ }
+
+ if (game.centered_player_nr == -1)
+ {
+ if (draw_new_player_location || offset_raw == 0)
+ {
+ setScreenCenteredToAllPlayers(&sx, &sy);
+ }
+ else
+ {
+ sx = PLAYER_SCREEN_X(max_center_distance_player_nr);
+ sy = PLAYER_SCREEN_Y(max_center_distance_player_nr);
+ }
+ }
+ else
+ {
+ sx = PLAYER_SCREEN_X(game.centered_player_nr);
+ sy = PLAYER_SCREEN_Y(game.centered_player_nr);
+ }
+
+ if (draw_new_player_location && quick_relocation)
+ {
+ screen_x = VALID_SCREEN_X(sx);
+ screen_y = VALID_SCREEN_Y(sy);
+ screen_x_old = screen_x;
+ screen_y_old = screen_y;
+ }
+
+ if (draw_new_player_location && !quick_relocation)
+ {
+ unsigned int frame_delay_value_old = GetVideoFrameDelay();
+ int wait_delay_value = frame_delay_value_old;
+ int screen_xx = VALID_SCREEN_X(sx);
+ int screen_yy = VALID_SCREEN_Y(sy);
+
+ if (draw_new_player_location_wrap)
+ {
+ if (lev.infinite_true)
+ {
+ // when wrapping around (horizontally), keep vertical player position
+ screen_yy = screen_y;
+ }
+
+ // scrolling for wrapping should be faster than for switching players
+ wait_delay_value /= 4;
+ }
+
+ SetVideoFrameDelay(wait_delay_value);
+
+ while (screen_x != screen_xx || screen_y != screen_yy)
+ {
+ int dx = (screen_xx < screen_x ? +1 : screen_xx > screen_x ? -1 : 0);
+ int dy = (screen_yy < screen_y ? +1 : screen_yy > screen_y ? -1 : 0);
+ int dxx = 0, dyy = 0;
+
+ if (dx == 0 && dy == 0) /* no scrolling needed at all */
+ break;
+
+ if (ABS(screen_xx - screen_x) >= TILEX)
+ {
+ screen_x -= dx * TILEX;
+ dxx = dx * TILEX / 2;
+ }
+ else
+ {
+ screen_x = screen_xx;
+ dxx = 0;
+ }
+
+ if (ABS(screen_yy - screen_y) >= TILEY)
+ {
+ screen_y -= dy * TILEY;
+ dyy = dy * TILEY / 2;
+ }
+ else
+ {
+ screen_y = screen_yy;
+ dyy = 0;
+ }
+
+ /* scroll in two steps of half tile size to make things smoother */
+ screen_x += dxx;
+ screen_y += dyy;
+
+ animscreen();
+
+ for (i = 0; i < MAX_PLAYERS; i++)
+ blitplayer(i);
+
+ BlitScreenToBitmap_EM(backbuffer);
+ BackToFront_EM();
+
+ /* scroll second step to align at full tile size */
+ screen_x -= dxx;
+ screen_y -= dyy;