1 /* 2000-08-13T14:36:17Z
3 * graphics manipulation crap
8 #define MIN_SCREEN_XPOS_RAW 0
9 #define MIN_SCREEN_YPOS_RAW 0
10 #define MAX_SCREEN_XPOS_RAW MAX(0, lev.width - SCR_FIELDX)
11 #define MAX_SCREEN_YPOS_RAW MAX(0, lev.height - SCR_FIELDY)
13 #define MIN_SCREEN_XPOS (MIN_SCREEN_XPOS_RAW + CAVE_BUFFER_XOFFSET)
14 #define MIN_SCREEN_YPOS (MIN_SCREEN_YPOS_RAW + CAVE_BUFFER_YOFFSET)
15 #define MAX_SCREEN_XPOS (MAX_SCREEN_XPOS_RAW + CAVE_BUFFER_XOFFSET)
16 #define MAX_SCREEN_YPOS (MAX_SCREEN_YPOS_RAW + CAVE_BUFFER_YOFFSET)
18 #define MIN_SCREEN_X (MIN_SCREEN_XPOS * TILEX)
19 #define MIN_SCREEN_Y (MIN_SCREEN_YPOS * TILEY)
20 #define MAX_SCREEN_X (MAX_SCREEN_XPOS * TILEX)
21 #define MAX_SCREEN_Y (MAX_SCREEN_YPOS * TILEY)
23 #define VALID_SCREEN_X(x) ((x) < MIN_SCREEN_X ? MIN_SCREEN_X : \
24 (x) > MAX_SCREEN_X ? MAX_SCREEN_X : (x))
25 #define VALID_SCREEN_Y(y) ((y) < MIN_SCREEN_Y ? MIN_SCREEN_Y : \
26 (y) > MAX_SCREEN_Y ? MAX_SCREEN_Y : (y))
28 #define PLAYER_POS_X(nr) (((7 - frame) * ply[nr].prev_x + \
29 (1 + frame) * ply[nr].x) * TILEX / 8)
30 #define PLAYER_POS_Y(nr) (((7 - frame) * ply[nr].prev_y + \
31 (1 + frame) * ply[nr].y) * TILEY / 8)
33 #define PLAYER_SCREEN_X(nr) (PLAYER_POS_X(nr) - \
34 (SCR_FIELDX - 1) * TILEX / 2)
35 #define PLAYER_SCREEN_Y(nr) (PLAYER_POS_Y(nr) - \
36 (SCR_FIELDY - 1) * TILEY / 2)
38 #define USE_EXTENDED_GRAPHICS_ENGINE 1
41 int frame; /* current screen frame */
42 int screen_x, screen_y; /* current scroll position */
44 /* tiles currently on screen */
45 static int screen_tiles[MAX_PLAYFIELD_WIDTH + 2][MAX_PLAYFIELD_HEIGHT + 2];
46 static int crumbled_state[MAX_PLAYFIELD_WIDTH + 2][MAX_PLAYFIELD_HEIGHT + 2];
48 /* graphic info for game objects/frames and players/actions/frames */
49 struct GraphicInfo_EM graphic_info_em_object[GAME_TILE_MAX][8];
50 struct GraphicInfo_EM graphic_info_em_player[MAX_PLAYERS][PLY_MAX][8];
52 static void setScreenCenteredToAllPlayers(int *, int *);
54 int getFieldbufferOffsetX_EM(void)
56 return screen_x % TILEX;
59 int getFieldbufferOffsetY_EM(void)
61 return screen_y % TILEY;
64 void BlitScreenToBitmap_EM(Bitmap *target_bitmap)
66 /* blit all (up to four) parts of the scroll buffer to the target bitmap */
68 int x = screen_x % (MAX_BUF_XSIZE * TILEX);
69 int y = screen_y % (MAX_BUF_YSIZE * TILEY);
72 int full_xsize = lev.width * TILEX;
73 int full_ysize = lev.height * TILEY;
74 int sx = SX + (full_xsize < xsize ? (xsize - full_xsize) / 2 : 0);
75 int sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0);
76 int sxsize = (full_xsize < xsize ? full_xsize : xsize);
77 int sysize = (full_ysize < ysize ? full_ysize : ysize);
78 int xxsize = MAX_BUF_XSIZE * TILEX - x;
79 int yysize = MAX_BUF_YSIZE * TILEY - y;
80 int xoffset = 2 * CAVE_BUFFER_XOFFSET * TILEX;
81 int yoffset = 2 * CAVE_BUFFER_YOFFSET * TILEY;
83 if (x < xoffset && y < yoffset)
85 BlitBitmap(screenBitmap, target_bitmap, x, y, sxsize, sysize,
88 else if (x < xoffset && y >= yoffset)
90 BlitBitmap(screenBitmap, target_bitmap, x, y, sxsize, yysize,
92 BlitBitmap(screenBitmap, target_bitmap, x, 0, sxsize, y - yoffset,
95 else if (x >= xoffset && y < yoffset)
97 BlitBitmap(screenBitmap, target_bitmap, x, y, xxsize, sysize,
99 BlitBitmap(screenBitmap, target_bitmap, 0, y, x - xoffset, sysize,
104 BlitBitmap(screenBitmap, target_bitmap, x, y, xxsize, yysize,
106 BlitBitmap(screenBitmap, target_bitmap, 0, y, x - xoffset, yysize,
108 BlitBitmap(screenBitmap, target_bitmap, x, 0, xxsize, y - yoffset,
110 BlitBitmap(screenBitmap, target_bitmap, 0, 0, x - xoffset, y - yoffset,
111 sx + xxsize, sy + yysize);
115 static void BackToFront_EM(void)
117 BlitBitmap(backbuffer, window, SX, SY, SXSIZE, SYSIZE, SX, SY);
120 static struct GraphicInfo_EM *getObjectGraphic(int x, int y)
122 int tile = lev.draw[x][y];
123 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
125 if (!game.use_native_emc_graphics_engine)
126 getGraphicSourceObjectExt_EM(g, tile, frame, x - lev.left, y - lev.top);
131 static struct GraphicInfo_EM *getPlayerGraphic(int player_nr, int anim)
133 struct GraphicInfo_EM *g = &graphic_info_em_player[player_nr][anim][frame];
135 if (!game.use_native_emc_graphics_engine)
136 getGraphicSourcePlayerExt_EM(g, player_nr, anim, frame);
141 static void DrawLevelField_EM(int x, int y, int sx, int sy,
144 struct GraphicInfo_EM *g = getObjectGraphic(x, y);
145 int src_x = g->src_x + g->src_offset_x * TILESIZE_VAR / TILESIZE;
146 int src_y = g->src_y + g->src_offset_y * TILESIZE_VAR / TILESIZE;
147 int dst_x = sx * TILEX + g->dst_offset_x * TILESIZE_VAR / TILESIZE;
148 int dst_y = sy * TILEY + g->dst_offset_y * TILESIZE_VAR / TILESIZE;
149 int width = g->width * TILESIZE_VAR / TILESIZE;
150 int height = g->height * TILESIZE_VAR / TILESIZE;
151 int left = screen_x / TILEX;
152 int top = screen_y / TILEY;
154 /* do not draw fields that are outside the visible screen area */
155 if (x < left || x >= left + MAX_BUF_XSIZE ||
156 y < top || y >= top + MAX_BUF_YSIZE)
161 if (width > 0 && height > 0)
162 BlitBitmapMasked(g->bitmap, screenBitmap,
163 src_x, src_y, width, height, dst_x, dst_y);
167 if ((width != TILEX || height != TILEY) && !g->preserve_background)
168 ClearRectangle(screenBitmap, sx * TILEX, sy * TILEY, TILEX, TILEY);
170 if (width > 0 && height > 0)
171 BlitBitmap(g->bitmap, screenBitmap,
172 src_x, src_y, width, height, dst_x, dst_y);
176 static void DrawLevelFieldCrumbled_EM(int x, int y, int sx, int sy,
177 int crm, boolean draw_masked)
179 struct GraphicInfo_EM *g;
180 int crumbled_border_size;
181 int left = screen_x / TILEX;
182 int top = screen_y / TILEY;
185 /* do not draw fields that are outside the visible screen area */
186 if (x < left || x >= left + MAX_BUF_XSIZE ||
187 y < top || y >= top + MAX_BUF_YSIZE)
190 if (crm == 0) /* no crumbled edges for this tile */
193 g = getObjectGraphic(x, y);
195 crumbled_border_size =
196 g->crumbled_border_size * TILESIZE_VAR / g->crumbled_tile_size;
198 for (i = 0; i < 4; i++)
202 int width, height, cx, cy;
204 if (i == 1 || i == 2)
206 width = crumbled_border_size;
208 cx = (i == 2 ? TILEX - crumbled_border_size : 0);
214 height = crumbled_border_size;
216 cy = (i == 3 ? TILEY - crumbled_border_size : 0);
219 if (width > 0 && height > 0)
221 int src_x = g->crumbled_src_x + cx;
222 int src_y = g->crumbled_src_y + cy;
223 int dst_x = sx * TILEX + cx;
224 int dst_y = sy * TILEY + cy;
227 BlitBitmapMasked(g->crumbled_bitmap, screenBitmap,
228 src_x, src_y, width, height, dst_x, dst_y);
230 BlitBitmap(g->crumbled_bitmap, screenBitmap,
231 src_x, src_y, width, height, dst_x, dst_y);
237 static void DrawLevelPlayer_EM(int x1, int y1, int player_nr, int anim,
240 struct GraphicInfo_EM *g = getPlayerGraphic(player_nr, anim);
241 int src_x = g->src_x, src_y = g->src_y;
244 /* do not draw fields that are outside the visible screen area */
245 if (x1 < screen_x - TILEX || x1 >= screen_x + MAX_BUF_XSIZE * TILEX ||
246 y1 < screen_y - TILEY || y1 >= screen_y + MAX_BUF_YSIZE * TILEY)
249 x1 %= MAX_BUF_XSIZE * TILEX;
250 y1 %= MAX_BUF_YSIZE * TILEY;
254 /* draw the player to current location */
257 BlitBitmapMasked(g->bitmap, screenBitmap,
258 src_x, src_y, TILEX, TILEY, dst_x, dst_y);
260 /* draw the player to opposite wrap-around column */
261 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
263 BlitBitmapMasked(g->bitmap, screenBitmap,
264 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
266 /* draw the player to opposite wrap-around row */
268 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
269 BlitBitmapMasked(g->bitmap, screenBitmap,
270 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
274 /* draw the player to current location */
277 BlitBitmap(g->bitmap, screenBitmap,
278 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
280 /* draw the player to opposite wrap-around column */
281 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
283 BlitBitmap(g->bitmap, screenBitmap,
284 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
286 /* draw the player to opposite wrap-around row */
288 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
289 BlitBitmap(g->bitmap, screenBitmap,
290 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
294 /* draw differences between game tiles and screen tiles
296 * implicitly handles scrolling and restoring background under the sprites
299 static void animscreen(void)
302 int left = screen_x / TILEX;
303 int top = screen_y / TILEY;
304 static int xy[4][2] =
312 if (!game.use_native_emc_graphics_engine)
313 for (y = lev.top; y < lev.bottom; y++)
314 for (x = lev.left; x < lev.right; x++)
315 SetGfxAnimation_EM(&graphic_info_em_object[lev.draw[x][y]][frame],
316 lev.draw[x][y], frame,
317 x - lev.left, y - lev.top);
319 for (y = top; y < top + MAX_BUF_YSIZE; y++)
321 for (x = left; x < left + MAX_BUF_XSIZE; x++)
323 int sx = x % MAX_BUF_XSIZE;
324 int sy = y % MAX_BUF_YSIZE;
325 int tile = lev.draw[x][y];
326 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
327 int obj = g->unique_identifier;
329 boolean redraw_screen_tile = FALSE;
331 /* re-calculate crumbled state of this tile */
332 if (g->has_crumbled_graphics)
334 for (i = 0; i < 4; i++)
336 int xx = x + xy[i][0];
337 int yy = y + xy[i][1];
340 if (xx < 0 || xx >= CAVE_BUFFER_WIDTH ||
341 yy < 0 || yy >= CAVE_BUFFER_HEIGHT)
344 tile_next = lev.draw[xx][yy];
346 if (!graphic_info_em_object[tile_next][frame].has_crumbled_graphics)
351 redraw_screen_tile = (screen_tiles[sx][sy] != obj ||
352 crumbled_state[sx][sy] != crm);
354 /* only redraw screen tiles if they (or their crumbled state) changed */
355 if (redraw_screen_tile)
357 DrawLevelField_EM(x, y, sx, sy, FALSE);
358 DrawLevelFieldCrumbled_EM(x, y, sx, sy, crm, FALSE);
360 screen_tiles[sx][sy] = obj;
361 crumbled_state[sx][sy] = crm;
368 /* blit players to the screen
370 * handles transparency and movement
373 static void blitplayer_ext(int nr)
380 /* x1/y1 are left/top and x2/y2 are right/down part of the player movement */
381 x1 = PLAYER_POS_X(nr);
382 y1 = PLAYER_POS_Y(nr);
386 if ((int)(x2 - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
387 (int)(y2 - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
389 /* some casts to "int" are needed because of negative calculation values */
390 int dx = (int)ply[nr].x - (int)ply[nr].prev_x;
391 int dy = (int)ply[nr].y - (int)ply[nr].prev_y;
392 int old_x = (int)ply[nr].prev_x + (int)frame * dx / 8;
393 int old_y = (int)ply[nr].prev_y + (int)frame * dy / 8;
394 int new_x = old_x + SIGN(dx);
395 int new_y = old_y + SIGN(dy);
396 int old_sx = old_x % MAX_BUF_XSIZE;
397 int old_sy = old_y % MAX_BUF_YSIZE;
398 int new_sx = new_x % MAX_BUF_XSIZE;
399 int new_sy = new_y % MAX_BUF_YSIZE;
400 int new_crm = crumbled_state[new_sx][new_sy];
402 /* only diggable elements can be crumbled in the classic EM engine */
403 boolean player_is_digging = (new_crm != 0);
405 if (player_is_digging)
407 /* draw the field the player is moving to (under the player) */
408 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, FALSE);
409 DrawLevelFieldCrumbled_EM(new_x, new_y, new_sx, new_sy, new_crm, FALSE);
411 /* draw the player (masked) over the element he is just digging away */
412 DrawLevelPlayer_EM(x1, y1, ply[nr].num, ply[nr].anim, TRUE);
414 /* draw the field the player is moving from (masked over the player) */
415 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
419 /* draw the player under the element which is on the same field */
420 DrawLevelPlayer_EM(x1, y1, ply[nr].num, ply[nr].anim, FALSE);
422 /* draw the field the player is moving from (masked over the player) */
423 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
425 /* draw the field the player is moving to (masked over the player) */
426 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, TRUE);
429 /* redraw screen tiles in the next frame (player may have left the tiles) */
430 screen_tiles[old_sx][old_sy] = -1;
431 screen_tiles[new_sx][new_sy] = -1;
435 static void blitplayer(int nr)
439 /* check for wrap-around movement ... */
440 if (ply[nr].x < lev.left ||
441 ply[nr].x > lev.right - 1)
443 struct PLAYER ply_last = ply[nr];
444 int dx = ply[nr].x - ply[nr].prev_x;
446 ply[nr].x = (ply[nr].x < lev.left ? lev.right - 1 : lev.left);
447 ply[nr].prev_x = ply[nr].x - dx;
449 /* draw player entering playfield from the opposite side */
452 /* ... but keep the old player position until game logic */
457 void game_initscreen(void)
463 if (game.centered_player_nr == -1)
465 setScreenCenteredToAllPlayers(&sx, &sy);
469 sx = PLAYER_SCREEN_X(game.centered_player_nr);
470 sy = PLAYER_SCREEN_Y(game.centered_player_nr);
473 screen_x = VALID_SCREEN_X(sx);
474 screen_y = VALID_SCREEN_Y(sy);
476 for (y = 0; y < MAX_BUF_YSIZE; y++)
478 for (x = 0; x < MAX_BUF_XSIZE; x++)
480 screen_tiles[x][y] = -1;
481 crumbled_state[x][y] = 0;
486 static int getMaxCenterDistancePlayerNr(int center_x, int center_y)
488 int max_dx = 0, max_dy = 0;
489 int player_nr = game_em.last_moving_player;
492 for (i = 0; i < MAX_PLAYERS; i++)
496 int sx = PLAYER_SCREEN_X(i);
497 int sy = PLAYER_SCREEN_Y(i);
499 if (game_em.last_player_direction[i] != MV_NONE &&
500 (ABS(sx - center_x) > max_dx ||
501 ABS(sy - center_y) > max_dy))
503 max_dx = MAX(max_dx, ABS(sx - center_x));
504 max_dy = MAX(max_dy, ABS(sy - center_y));
514 static void setMinimalPlayerBoundaries(int *sx1, int *sy1, int *sx2, int *sy2)
516 boolean num_checked_players = 0;
519 for (i = 0; i < MAX_PLAYERS; i++)
523 int sx = PLAYER_SCREEN_X(i);
524 int sy = PLAYER_SCREEN_Y(i);
526 if (num_checked_players == 0)
533 *sx1 = MIN(*sx1, sx);
534 *sy1 = MIN(*sy1, sy);
535 *sx2 = MAX(*sx2, sx);
536 *sy2 = MAX(*sy2, sy);
539 num_checked_players++;
544 boolean checkIfAllPlayersFitToScreen(void)
546 int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0;
548 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
550 return (sx2 - sx1 <= SCR_FIELDX * TILEX &&
551 sy2 - sy1 <= SCR_FIELDY * TILEY);
554 static void setScreenCenteredToAllPlayers(int *sx, int *sy)
556 int sx1 = screen_x, sy1 = screen_y, sx2 = screen_x, sy2 = screen_y;
558 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
560 *sx = (sx1 + sx2) / 2;
561 *sy = (sy1 + sy2) / 2;
564 static void setMaxCenterDistanceForAllPlayers(int *max_dx, int *max_dy,
565 int center_x, int center_y)
567 int sx1 = center_x, sy1 = center_y, sx2 = center_x, sy2 = center_y;
569 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
571 *max_dx = MAX(ABS(sx1 - center_x), ABS(sx2 - center_x));
572 *max_dy = MAX(ABS(sy1 - center_y), ABS(sy2 - center_y));
575 static boolean checkIfAllPlayersAreVisible(int center_x, int center_y)
579 setMaxCenterDistanceForAllPlayers(&max_dx, &max_dy, center_x, center_y);
581 return (max_dx <= SCR_FIELDX * TILEX / 2 &&
582 max_dy <= SCR_FIELDY * TILEY / 2);
585 void RedrawPlayfield_EM(boolean force_redraw)
587 boolean draw_new_player_location = FALSE;
588 boolean draw_new_player_location_wrap = FALSE;
589 boolean quick_relocation = setup.quick_switch;
590 int max_center_distance_player_nr =
591 getMaxCenterDistancePlayerNr(screen_x, screen_y);
592 int stepsize = TILEX / 8;
593 int offset_raw = game.scroll_delay_value;
594 int offset_x = MIN(offset_raw, (SCR_FIELDX - 2) / 2) * TILEX;
595 int offset_y = MIN(offset_raw, (SCR_FIELDY - 2) / 2) * TILEY;
596 int screen_x_old = screen_x;
597 int screen_y_old = screen_y;
601 if (game.set_centered_player)
603 boolean all_players_fit_to_screen = checkIfAllPlayersFitToScreen();
605 /* switching to "all players" only possible if all players fit to screen */
606 if (game.centered_player_nr_next == -1 && !all_players_fit_to_screen)
608 game.centered_player_nr_next = game.centered_player_nr;
609 game.set_centered_player = FALSE;
612 /* do not switch focus to non-existing (or non-active) player */
613 if (game.centered_player_nr_next >= 0 &&
614 !ply[game.centered_player_nr_next].alive)
616 game.centered_player_nr_next = game.centered_player_nr;
617 game.set_centered_player = FALSE;
621 /* also allow focus switching when screen is scrolled to half tile */
622 if (game.set_centered_player)
624 game.centered_player_nr = game.centered_player_nr_next;
626 draw_new_player_location = TRUE;
627 draw_new_player_location_wrap = game.set_centered_player_wrap;
630 game.set_centered_player = FALSE;
631 game.set_centered_player_wrap = FALSE;
634 if (game.centered_player_nr == -1)
636 if (draw_new_player_location || offset_raw == 0)
638 setScreenCenteredToAllPlayers(&sx, &sy);
642 sx = PLAYER_SCREEN_X(max_center_distance_player_nr);
643 sy = PLAYER_SCREEN_Y(max_center_distance_player_nr);
648 sx = PLAYER_SCREEN_X(game.centered_player_nr);
649 sy = PLAYER_SCREEN_Y(game.centered_player_nr);
652 if (draw_new_player_location && quick_relocation)
654 screen_x = VALID_SCREEN_X(sx);
655 screen_y = VALID_SCREEN_Y(sy);
656 screen_x_old = screen_x;
657 screen_y_old = screen_y;
660 if (draw_new_player_location && !quick_relocation)
662 unsigned int frame_delay_value_old = GetVideoFrameDelay();
663 int wait_delay_value = frame_delay_value_old;
664 int screen_xx = VALID_SCREEN_X(sx);
665 int screen_yy = VALID_SCREEN_Y(sy);
667 if (draw_new_player_location_wrap)
669 // when wrapping around (horizontally), keep vertical player position
670 screen_yy = screen_y;
672 // scrolling for wrapping should be faster than for switching players
673 wait_delay_value /= 4;
676 SetVideoFrameDelay(wait_delay_value);
678 while (screen_x != screen_xx || screen_y != screen_yy)
680 int dx = (screen_xx < screen_x ? +1 : screen_xx > screen_x ? -1 : 0);
681 int dy = (screen_yy < screen_y ? +1 : screen_yy > screen_y ? -1 : 0);
682 int dxx = 0, dyy = 0;
684 if (dx == 0 && dy == 0) /* no scrolling needed at all */
687 if (ABS(screen_xx - screen_x) >= TILEX)
689 screen_x -= dx * TILEX;
690 dxx = dx * TILEX / 2;
694 screen_x = screen_xx;
698 if (ABS(screen_yy - screen_y) >= TILEY)
700 screen_y -= dy * TILEY;
701 dyy = dy * TILEY / 2;
705 screen_y = screen_yy;
709 /* scroll in two steps of half tile size to make things smoother */
715 for (i = 0; i < MAX_PLAYERS; i++)
718 BlitScreenToBitmap_EM(backbuffer);
721 /* scroll second step to align at full tile size */
727 for (i = 0; i < MAX_PLAYERS; i++)
730 BlitScreenToBitmap_EM(backbuffer);
734 SetVideoFrameDelay(frame_delay_value_old);
736 screen_x_old = screen_x;
737 screen_y_old = screen_y;
742 for (y = 0; y < MAX_BUF_YSIZE; y++)
744 for (x = 0; x < MAX_BUF_XSIZE; x++)
746 screen_tiles[x][y] = -1;
747 crumbled_state[x][y] = 0;
752 /* calculate new screen scrolling position, with regard to scroll delay */
753 screen_x = VALID_SCREEN_X(sx + offset_x < screen_x ? sx + offset_x :
754 sx - offset_x > screen_x ? sx - offset_x :
756 screen_y = VALID_SCREEN_Y(sy + offset_y < screen_y ? sy + offset_y :
757 sy - offset_y > screen_y ? sy - offset_y :
760 /* prevent scrolling further than double player step size when scrolling */
761 if (ABS(screen_x - screen_x_old) > 2 * stepsize)
763 int dx = SIGN(screen_x - screen_x_old);
765 screen_x = screen_x_old + dx * 2 * stepsize;
767 if (ABS(screen_y - screen_y_old) > 2 * stepsize)
769 int dy = SIGN(screen_y - screen_y_old);
771 screen_y = screen_y_old + dy * 2 * stepsize;
774 /* prevent scrolling away from the other players when focus on all players */
775 if (game.centered_player_nr == -1)
777 /* check if all players are still visible with new scrolling position */
778 if (checkIfAllPlayersAreVisible(screen_x_old, screen_y_old) &&
779 !checkIfAllPlayersAreVisible(screen_x, screen_y))
781 /* reset horizontal scroll position to last value, if needed */
782 if (!checkIfAllPlayersAreVisible(screen_x, screen_y_old))
783 screen_x = screen_x_old;
785 /* reset vertical scroll position to last value, if needed */
786 if (!checkIfAllPlayersAreVisible(screen_x_old, screen_y))
787 screen_y = screen_y_old;
791 /* prevent scrolling (for screen correcting) if no player is moving */
792 if (!game_em.any_player_moving)
794 screen_x = screen_x_old;
795 screen_y = screen_y_old;
799 /* prevent scrolling against the players move direction */
800 int player_nr = (game.centered_player_nr == -1 ?
801 max_center_distance_player_nr : game.centered_player_nr);
802 int player_move_dir = game_em.last_player_direction[player_nr];
803 int dx = SIGN(screen_x - screen_x_old);
804 int dy = SIGN(screen_y - screen_y_old);
806 if ((dx < 0 && player_move_dir != MV_LEFT) ||
807 (dx > 0 && player_move_dir != MV_RIGHT))
808 screen_x = screen_x_old;
810 if ((dy < 0 && player_move_dir != MV_UP) ||
811 (dy > 0 && player_move_dir != MV_DOWN))
812 screen_y = screen_y_old;
815 // skip redrawing playfield in warp mode or when testing tapes with "autotest"
816 if (DrawingDeactivatedField())
821 for (i = 0; i < MAX_PLAYERS; i++)