1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // http://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
14 #include "libgame/libgame.h"
26 /* select level set with EMC X11 graphics before activating EM GFX debugging */
27 #define DEBUG_EM_GFX FALSE
28 #define DEBUG_FRAME_TIME FALSE
30 /* tool button identifiers */
31 #define TOOL_CTRL_ID_YES 0
32 #define TOOL_CTRL_ID_NO 1
33 #define TOOL_CTRL_ID_CONFIRM 2
34 #define TOOL_CTRL_ID_PLAYER_1 3
35 #define TOOL_CTRL_ID_PLAYER_2 4
36 #define TOOL_CTRL_ID_PLAYER_3 5
37 #define TOOL_CTRL_ID_PLAYER_4 6
39 #define NUM_TOOL_BUTTONS 7
41 /* constants for number of doors and door parts */
43 #define NUM_PANELS NUM_DOORS
44 // #define NUM_PANELS 0
45 #define MAX_PARTS_PER_DOOR 8
46 #define MAX_DOOR_PARTS (NUM_DOORS * MAX_PARTS_PER_DOOR + NUM_PANELS)
47 #define DOOR_PART_IS_PANEL(i) ((i) >= NUM_DOORS * MAX_PARTS_PER_DOOR)
50 struct DoorPartOrderInfo
56 static struct DoorPartOrderInfo door_part_order[MAX_DOOR_PARTS];
58 struct DoorPartControlInfo
62 struct DoorPartPosInfo *pos;
65 static struct DoorPartControlInfo door_part_controls[] =
69 IMG_GFX_DOOR_1_PART_1,
74 IMG_GFX_DOOR_1_PART_2,
79 IMG_GFX_DOOR_1_PART_3,
84 IMG_GFX_DOOR_1_PART_4,
89 IMG_GFX_DOOR_1_PART_5,
94 IMG_GFX_DOOR_1_PART_6,
99 IMG_GFX_DOOR_1_PART_7,
104 IMG_GFX_DOOR_1_PART_8,
110 IMG_GFX_DOOR_2_PART_1,
115 IMG_GFX_DOOR_2_PART_2,
120 IMG_GFX_DOOR_2_PART_3,
125 IMG_GFX_DOOR_2_PART_4,
130 IMG_GFX_DOOR_2_PART_5,
135 IMG_GFX_DOOR_2_PART_6,
140 IMG_GFX_DOOR_2_PART_7,
145 IMG_GFX_DOOR_2_PART_8,
151 IMG_BACKGROUND_PANEL,
168 /* forward declaration for internal use */
169 static void UnmapToolButtons();
170 static void HandleToolButtons(struct GadgetInfo *);
171 static int el_act_dir2crm(int, int, int);
172 static int el_act2crm(int, int);
174 static struct GadgetInfo *tool_gadget[NUM_TOOL_BUTTONS];
175 static int request_gadget_id = -1;
177 static char *print_if_not_empty(int element)
179 static char *s = NULL;
180 char *token_name = element_info[element].token_name;
185 s = checked_malloc(strlen(token_name) + 10 + 1);
187 if (element != EL_EMPTY)
188 sprintf(s, "%d\t['%s']", element, token_name);
190 sprintf(s, "%d", element);
195 int correctLevelPosX_EM(int lx)
198 lx -= (BorderElement != EL_EMPTY ? 1 : 0);
203 int correctLevelPosY_EM(int ly)
206 ly -= (BorderElement != EL_EMPTY ? 1 : 0);
211 static int getFieldbufferOffsetX_RND()
213 int full_lev_fieldx = lev_fieldx + (BorderElement != EL_EMPTY ? 2 : 0);
214 int dx = (ScreenMovDir & (MV_LEFT | MV_RIGHT) ? ScreenGfxPos : 0);
215 int dx_var = dx * TILESIZE_VAR / TILESIZE;
218 if (EVEN(SCR_FIELDX))
220 int ffx = (scroll_x - SBX_Left) * TILEX_VAR + dx_var;
222 if (ffx < SBX_Right * TILEX_VAR + TILEX_VAR / 2 + TILEX_VAR)
223 fx += dx_var - MIN(ffx, TILEX_VAR / 2) + TILEX_VAR;
225 fx += (dx_var > 0 ? TILEX_VAR : 0);
232 if (full_lev_fieldx <= SCR_FIELDX)
234 if (EVEN(SCR_FIELDX))
235 fx = 2 * TILEX_VAR - (ODD(lev_fieldx) ? TILEX_VAR / 2 : 0);
237 fx = 2 * TILEX_VAR - (EVEN(lev_fieldx) ? TILEX_VAR / 2 : 0);
243 static int getFieldbufferOffsetY_RND()
245 int full_lev_fieldy = lev_fieldy + (BorderElement != EL_EMPTY ? 2 : 0);
246 int dy = (ScreenMovDir & (MV_UP | MV_DOWN) ? ScreenGfxPos : 0);
247 int dy_var = dy * TILESIZE_VAR / TILESIZE;
250 if (EVEN(SCR_FIELDY))
252 int ffy = (scroll_y - SBY_Upper) * TILEY_VAR + dy_var;
254 if (ffy < SBY_Lower * TILEY_VAR + TILEY_VAR / 2 + TILEY_VAR)
255 fy += dy_var - MIN(ffy, TILEY_VAR / 2) + TILEY_VAR;
257 fy += (dy_var > 0 ? TILEY_VAR : 0);
264 if (full_lev_fieldy <= SCR_FIELDY)
266 if (EVEN(SCR_FIELDY))
267 fy = 2 * TILEY_VAR - (ODD(lev_fieldy) ? TILEY_VAR / 2 : 0);
269 fy = 2 * TILEY_VAR - (EVEN(lev_fieldy) ? TILEY_VAR / 2 : 0);
275 static int getLevelFromScreenX_RND(int sx)
277 int fx = getFieldbufferOffsetX_RND();
280 int lx = LEVELX((px + dx) / TILESIZE_VAR);
285 static int getLevelFromScreenY_RND(int sy)
287 int fy = getFieldbufferOffsetY_RND();
290 int ly = LEVELY((py + dy) / TILESIZE_VAR);
295 static int getLevelFromScreenX_EM(int sx)
297 int level_xsize = level.native_em_level->lev->width;
298 int full_xsize = level_xsize * TILESIZE_VAR;
300 sx -= (full_xsize < SXSIZE ? (SXSIZE - full_xsize) / 2 : 0);
302 int fx = getFieldbufferOffsetX_EM();
305 int lx = LEVELX((px + dx) / TILESIZE_VAR);
307 lx = correctLevelPosX_EM(lx);
312 static int getLevelFromScreenY_EM(int sy)
314 int level_ysize = level.native_em_level->lev->height;
315 int full_ysize = level_ysize * TILESIZE_VAR;
317 sy -= (full_ysize < SYSIZE ? (SYSIZE - full_ysize) / 2 : 0);
319 int fy = getFieldbufferOffsetY_EM();
322 int ly = LEVELY((py + dy) / TILESIZE_VAR);
324 ly = correctLevelPosY_EM(ly);
329 static int getLevelFromScreenX_SP(int sx)
331 int menBorder = setup.sp_show_border_elements;
332 int level_xsize = level.native_sp_level->width;
333 int full_xsize = (level_xsize - (menBorder ? 0 : 1)) * TILESIZE_VAR;
335 sx += (full_xsize < SXSIZE ? (SXSIZE - full_xsize) / 2 : 0);
337 int fx = getFieldbufferOffsetX_SP();
340 int lx = LEVELX((px + dx) / TILESIZE_VAR);
345 static int getLevelFromScreenY_SP(int sy)
347 int menBorder = setup.sp_show_border_elements;
348 int level_ysize = level.native_sp_level->height;
349 int full_ysize = (level_ysize - (menBorder ? 0 : 1)) * TILESIZE_VAR;
351 sy += (full_ysize < SYSIZE ? (SYSIZE - full_ysize) / 2 : 0);
353 int fy = getFieldbufferOffsetY_SP();
356 int ly = LEVELY((py + dy) / TILESIZE_VAR);
361 static int getLevelFromScreenX_MM(int sx)
364 int level_xsize = level.native_mm_level->fieldx;
365 int full_xsize = level_xsize * TILESIZE_VAR;
367 sx -= (full_xsize < SXSIZE ? (SXSIZE - full_xsize) / 2 : 0);
371 int lx = px / TILESIZE_VAR;
376 static int getLevelFromScreenY_MM(int sy)
379 int level_ysize = level.native_mm_level->fieldy;
380 int full_ysize = level_ysize * TILESIZE_VAR;
382 sy -= (full_ysize < SYSIZE ? (SYSIZE - full_ysize) / 2 : 0);
386 int ly = py / TILESIZE_VAR;
391 int getLevelFromScreenX(int x)
393 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
394 return getLevelFromScreenX_EM(x);
395 if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
396 return getLevelFromScreenX_SP(x);
397 if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
398 return getLevelFromScreenX_MM(x);
400 return getLevelFromScreenX_RND(x);
403 int getLevelFromScreenY(int y)
405 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
406 return getLevelFromScreenY_EM(y);
407 if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
408 return getLevelFromScreenY_SP(y);
409 if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
410 return getLevelFromScreenY_MM(y);
412 return getLevelFromScreenY_RND(y);
415 void DumpTile(int x, int y)
421 printf_line("-", 79);
422 printf("Field Info: SCREEN(%d, %d), LEVEL(%d, %d)\n", sx, sy, x, y);
423 printf_line("-", 79);
425 if (!IN_LEV_FIELD(x, y))
427 printf("(not in level field)\n");
433 token_name = element_info[Feld[x][y]].token_name;
435 printf(" Feld: %d\t['%s']\n", Feld[x][y], token_name);
436 printf(" Back: %s\n", print_if_not_empty(Back[x][y]));
437 printf(" Store: %s\n", print_if_not_empty(Store[x][y]));
438 printf(" Store2: %s\n", print_if_not_empty(Store2[x][y]));
439 printf(" StorePlayer: %s\n", print_if_not_empty(StorePlayer[x][y]));
440 printf(" MovPos: %d\n", MovPos[x][y]);
441 printf(" MovDir: %d\n", MovDir[x][y]);
442 printf(" MovDelay: %d\n", MovDelay[x][y]);
443 printf(" ChangeDelay: %d\n", ChangeDelay[x][y]);
444 printf(" CustomValue: %d\n", CustomValue[x][y]);
445 printf(" GfxElement: %d\n", GfxElement[x][y]);
446 printf(" GfxAction: %d\n", GfxAction[x][y]);
447 printf(" GfxFrame: %d [%d]\n", GfxFrame[x][y], FrameCounter);
448 printf(" Player x/y: %d, %d\n", local_player->jx, local_player->jy);
452 void DumpTileFromScreen(int sx, int sy)
454 int lx = getLevelFromScreenX(sx);
455 int ly = getLevelFromScreenY(sy);
460 void SetDrawtoField(int mode)
462 if (mode == DRAW_TO_FIELDBUFFER)
468 BX2 = SCR_FIELDX + 1;
469 BY2 = SCR_FIELDY + 1;
471 drawto_field = fieldbuffer;
473 else /* DRAW_TO_BACKBUFFER */
479 BX2 = SCR_FIELDX - 1;
480 BY2 = SCR_FIELDY - 1;
482 drawto_field = backbuffer;
486 static void RedrawPlayfield_RND()
488 if (game.envelope_active)
491 DrawLevel(REDRAW_ALL);
495 void RedrawPlayfield()
497 if (game_status != GAME_MODE_PLAYING)
500 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
501 RedrawPlayfield_EM(TRUE);
502 else if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
503 RedrawPlayfield_SP(TRUE);
504 else if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
505 RedrawPlayfield_MM();
506 else if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
507 RedrawPlayfield_RND();
509 BlitScreenToBitmap(backbuffer);
511 BlitBitmap(drawto, window, gfx.sx, gfx.sy, gfx.sxsize, gfx.sysize,
515 static void DrawMaskedBorderExt_Rect(int x, int y, int width, int height,
518 Bitmap *src_bitmap = getGlobalBorderBitmapFromStatus(global.border_status);
519 Bitmap *dst_bitmap = gfx.masked_border_bitmap_ptr;
521 if (x == -1 && y == -1)
524 if (draw_target == DRAW_TO_SCREEN)
525 BlitToScreenMasked(src_bitmap, x, y, width, height, x, y);
527 BlitBitmapMasked(src_bitmap, dst_bitmap, x, y, width, height, x, y);
530 static void DrawMaskedBorderExt_FIELD(int draw_target)
532 if (global.border_status >= GAME_MODE_MAIN &&
533 global.border_status <= GAME_MODE_PLAYING &&
534 border.draw_masked[global.border_status])
535 DrawMaskedBorderExt_Rect(REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE,
539 static void DrawMaskedBorderExt_DOOR_1(int draw_target)
541 // when drawing to backbuffer, never draw border over open doors
542 if (draw_target == DRAW_TO_BACKBUFFER &&
543 (GetDoorState() & DOOR_OPEN_1))
546 if (border.draw_masked[GFX_SPECIAL_ARG_DOOR] &&
547 (global.border_status != GAME_MODE_EDITOR ||
548 border.draw_masked[GFX_SPECIAL_ARG_EDITOR]))
549 DrawMaskedBorderExt_Rect(DX, DY, DXSIZE, DYSIZE, draw_target);
552 static void DrawMaskedBorderExt_DOOR_2(int draw_target)
554 // when drawing to backbuffer, never draw border over open doors
555 if (draw_target == DRAW_TO_BACKBUFFER &&
556 (GetDoorState() & DOOR_OPEN_2))
559 if (border.draw_masked[GFX_SPECIAL_ARG_DOOR] &&
560 global.border_status != GAME_MODE_EDITOR)
561 DrawMaskedBorderExt_Rect(VX, VY, VXSIZE, VYSIZE, draw_target);
564 static void DrawMaskedBorderExt_DOOR_3(int draw_target)
566 /* currently not available */
569 static void DrawMaskedBorderExt_ALL(int draw_target)
571 DrawMaskedBorderExt_FIELD(draw_target);
572 DrawMaskedBorderExt_DOOR_1(draw_target);
573 DrawMaskedBorderExt_DOOR_2(draw_target);
574 DrawMaskedBorderExt_DOOR_3(draw_target);
577 static void DrawMaskedBorderExt(int redraw_mask, int draw_target)
579 /* never draw masked screen borders on borderless screens */
580 if (global.border_status == GAME_MODE_LOADING ||
581 global.border_status == GAME_MODE_TITLE)
584 if (redraw_mask & REDRAW_ALL)
585 DrawMaskedBorderExt_ALL(draw_target);
588 if (redraw_mask & REDRAW_FIELD)
589 DrawMaskedBorderExt_FIELD(draw_target);
590 if (redraw_mask & REDRAW_DOOR_1)
591 DrawMaskedBorderExt_DOOR_1(draw_target);
592 if (redraw_mask & REDRAW_DOOR_2)
593 DrawMaskedBorderExt_DOOR_2(draw_target);
594 if (redraw_mask & REDRAW_DOOR_3)
595 DrawMaskedBorderExt_DOOR_3(draw_target);
599 void DrawMaskedBorder_FIELD()
601 DrawMaskedBorderExt_FIELD(DRAW_TO_BACKBUFFER);
604 void DrawMaskedBorder(int redraw_mask)
606 DrawMaskedBorderExt(redraw_mask, DRAW_TO_BACKBUFFER);
609 void DrawMaskedBorderToTarget(int draw_target)
611 if (draw_target == DRAW_TO_BACKBUFFER ||
612 draw_target == DRAW_TO_SCREEN)
614 DrawMaskedBorderExt(REDRAW_ALL, draw_target);
618 int last_border_status = global.border_status;
620 if (draw_target == DRAW_TO_FADE_SOURCE)
622 global.border_status = gfx.fade_border_source_status;
623 gfx.masked_border_bitmap_ptr = gfx.fade_bitmap_source;
625 else if (draw_target == DRAW_TO_FADE_TARGET)
627 global.border_status = gfx.fade_border_target_status;
628 gfx.masked_border_bitmap_ptr = gfx.fade_bitmap_target;
631 DrawMaskedBorderExt(REDRAW_ALL, draw_target);
633 global.border_status = last_border_status;
634 gfx.masked_border_bitmap_ptr = backbuffer;
638 void BlitScreenToBitmap_RND(Bitmap *target_bitmap)
640 int fx = getFieldbufferOffsetX_RND();
641 int fy = getFieldbufferOffsetY_RND();
643 BlitBitmap(drawto_field, target_bitmap, fx, fy, SXSIZE, SYSIZE, SX, SY);
646 void BlitScreenToBitmap(Bitmap *target_bitmap)
648 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
649 BlitScreenToBitmap_EM(target_bitmap);
650 else if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
651 BlitScreenToBitmap_SP(target_bitmap);
652 else if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
653 BlitScreenToBitmap_MM(target_bitmap);
654 else if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
655 BlitScreenToBitmap_RND(target_bitmap);
657 redraw_mask |= REDRAW_FIELD;
660 void DrawFramesPerSecond()
663 int font_nr = FONT_TEXT_2;
664 int font_width = getFontWidth(font_nr);
665 int draw_deactivation_mask = GetDrawDeactivationMask();
666 boolean draw_masked = (draw_deactivation_mask == REDRAW_NONE);
668 /* draw FPS with leading space (needed if field buffer deactivated) */
669 sprintf(text, " %04.1f fps", global.frames_per_second);
671 /* override draw deactivation mask (required for invisible warp mode) */
672 SetDrawDeactivationMask(REDRAW_NONE);
674 /* draw opaque FPS if field buffer deactivated, else draw masked FPS */
675 DrawTextExt(backbuffer, SX + SXSIZE - font_width * strlen(text), SY, text,
676 font_nr, (draw_masked ? BLIT_MASKED : BLIT_OPAQUE));
678 /* set draw deactivation mask to previous value */
679 SetDrawDeactivationMask(draw_deactivation_mask);
681 /* force full-screen redraw in this frame */
682 redraw_mask = REDRAW_ALL;
686 static void PrintFrameTimeDebugging()
688 static unsigned int last_counter = 0;
689 unsigned int counter = Counter();
690 int diff_1 = counter - last_counter;
691 int diff_2 = diff_1 - GAME_FRAME_DELAY;
693 int diff_2_cut = MIN(ABS(diff_2), diff_2_max);
694 char diff_bar[2 * diff_2_max + 5];
698 diff_bar[pos++] = (diff_2 < -diff_2_max ? '<' : ' ');
700 for (i = 0; i < diff_2_max; i++)
701 diff_bar[pos++] = (diff_2 >= 0 ? ' ' :
702 i >= diff_2_max - diff_2_cut ? '-' : ' ');
704 diff_bar[pos++] = '|';
706 for (i = 0; i < diff_2_max; i++)
707 diff_bar[pos++] = (diff_2 <= 0 ? ' ' : i < diff_2_cut ? '+' : ' ');
709 diff_bar[pos++] = (diff_2 > diff_2_max ? '>' : ' ');
711 diff_bar[pos++] = '\0';
713 Error(ERR_INFO, "%06d [%02d] [%c%02d] %s",
716 (diff_2 < 0 ? '-' : diff_2 > 0 ? '+' : ' '), ABS(diff_2),
719 last_counter = counter;
723 static int unifiedRedrawMask(int mask)
725 if (mask & REDRAW_ALL)
728 if (mask & REDRAW_FIELD && mask & REDRAW_DOORS)
734 static boolean equalRedrawMasks(int mask_1, int mask_2)
736 return unifiedRedrawMask(mask_1) == unifiedRedrawMask(mask_2);
741 static int last_redraw_mask = REDRAW_NONE;
743 // force screen redraw in every frame to continue drawing global animations
744 // (but always use the last redraw mask to prevent unwanted side effects)
745 if (redraw_mask == REDRAW_NONE)
746 redraw_mask = last_redraw_mask;
748 last_redraw_mask = redraw_mask;
751 // masked border now drawn immediately when blitting backbuffer to window
753 // draw masked border to all viewports, if defined
754 DrawMaskedBorder(redraw_mask);
757 // draw frames per second (only if debug mode is enabled)
758 if (redraw_mask & REDRAW_FPS)
759 DrawFramesPerSecond();
761 // remove playfield redraw before potentially merging with doors redraw
762 if (DrawingDeactivated(REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE))
763 redraw_mask &= ~REDRAW_FIELD;
765 // redraw complete window if both playfield and (some) doors need redraw
766 if (redraw_mask & REDRAW_FIELD && redraw_mask & REDRAW_DOORS)
767 redraw_mask = REDRAW_ALL;
769 /* although redrawing the whole window would be fine for normal gameplay,
770 being able to only redraw the playfield is required for deactivating
771 certain drawing areas (mainly playfield) to work, which is needed for
772 warp-forward to be fast enough (by skipping redraw of most frames) */
774 if (redraw_mask & REDRAW_ALL)
776 BlitBitmap(backbuffer, window, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
778 else if (redraw_mask & REDRAW_FIELD)
780 BlitBitmap(backbuffer, window,
781 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, REAL_SX, REAL_SY);
783 else if (redraw_mask & REDRAW_DOORS)
785 // merge door areas to prevent calling screen redraw more than once
791 if (redraw_mask & REDRAW_DOOR_1)
795 x2 = MAX(x2, DX + DXSIZE);
796 y2 = MAX(y2, DY + DYSIZE);
799 if (redraw_mask & REDRAW_DOOR_2)
803 x2 = MAX(x2, VX + VXSIZE);
804 y2 = MAX(y2, VY + VYSIZE);
807 if (redraw_mask & REDRAW_DOOR_3)
811 x2 = MAX(x2, EX + EXSIZE);
812 y2 = MAX(y2, EY + EYSIZE);
815 // make sure that at least one pixel is blitted, and inside the screen
816 // (else nothing is blitted, causing the animations not to be updated)
817 x1 = MIN(MAX(0, x1), WIN_XSIZE - 1);
818 y1 = MIN(MAX(0, y1), WIN_YSIZE - 1);
819 x2 = MIN(MAX(1, x2), WIN_XSIZE);
820 y2 = MIN(MAX(1, y2), WIN_YSIZE);
822 BlitBitmap(backbuffer, window, x1, y1, x2 - x1, y2 - y1, x1, y1);
825 redraw_mask = REDRAW_NONE;
828 PrintFrameTimeDebugging();
832 void BackToFront_WithFrameDelay(unsigned int frame_delay_value)
834 unsigned int frame_delay_value_old = GetVideoFrameDelay();
836 SetVideoFrameDelay(frame_delay_value);
840 SetVideoFrameDelay(frame_delay_value_old);
843 static int fade_type_skip = FADE_TYPE_NONE;
845 static void FadeExt(int fade_mask, int fade_mode, int fade_type)
847 void (*draw_border_function)(void) = NULL;
848 int x, y, width, height;
849 int fade_delay, post_delay;
851 if (fade_type == FADE_TYPE_FADE_OUT)
853 if (fade_type_skip != FADE_TYPE_NONE)
855 /* skip all fade operations until specified fade operation */
856 if (fade_type & fade_type_skip)
857 fade_type_skip = FADE_TYPE_NONE;
862 if (fading.fade_mode & FADE_TYPE_TRANSFORM)
866 redraw_mask |= fade_mask;
868 if (fade_type == FADE_TYPE_SKIP)
870 fade_type_skip = fade_mode;
875 fade_delay = fading.fade_delay;
876 post_delay = (fade_mode == FADE_MODE_FADE_OUT ? fading.post_delay : 0);
878 if (fade_type_skip != FADE_TYPE_NONE)
880 /* skip all fade operations until specified fade operation */
881 if (fade_type & fade_type_skip)
882 fade_type_skip = FADE_TYPE_NONE;
887 if (global.autoplay_leveldir)
892 if (fade_mask == REDRAW_FIELD)
897 height = FADE_SYSIZE;
899 if (border.draw_masked_when_fading)
900 draw_border_function = DrawMaskedBorder_FIELD; /* update when fading */
902 DrawMaskedBorder_FIELD(); /* draw once */
904 else /* REDRAW_ALL */
912 if (!setup.fade_screens ||
914 fading.fade_mode == FADE_MODE_NONE)
916 if (fade_mode == FADE_MODE_FADE_OUT)
919 BlitBitmap(backbuffer, window, x, y, width, height, x, y);
921 redraw_mask &= ~fade_mask;
926 FadeRectangle(x, y, width, height, fade_mode, fade_delay, post_delay,
927 draw_border_function);
929 redraw_mask &= ~fade_mask;
932 static void SetScreenStates_BeforeFadingIn()
934 // temporarily set screen mode for animations to screen after fading in
935 global.anim_status = global.anim_status_next;
937 // store backbuffer with all animations that will be started after fading in
938 if (fade_type_skip != FADE_MODE_SKIP_FADE_IN)
939 PrepareFadeBitmap(DRAW_TO_FADE_TARGET);
941 // set screen mode for animations back to fading
942 global.anim_status = GAME_MODE_PSEUDO_FADING;
945 static void SetScreenStates_AfterFadingIn()
947 // store new source screen (to use correct masked border for fading)
948 gfx.fade_border_source_status = global.border_status;
950 global.anim_status = global.anim_status_next;
953 static void SetScreenStates_BeforeFadingOut()
955 // store new target screen (to use correct masked border for fading)
956 gfx.fade_border_target_status = game_status;
958 // set screen mode for animations to fading
959 global.anim_status = GAME_MODE_PSEUDO_FADING;
961 // store backbuffer with all animations that will be stopped for fading out
962 if (fade_type_skip != FADE_MODE_SKIP_FADE_OUT)
963 PrepareFadeBitmap(DRAW_TO_FADE_SOURCE);
966 static void SetScreenStates_AfterFadingOut()
968 global.border_status = game_status;
971 void FadeIn(int fade_mask)
973 SetScreenStates_BeforeFadingIn();
976 DrawMaskedBorder(REDRAW_ALL);
979 if (fading.fade_mode & FADE_TYPE_TRANSFORM)
980 FadeExt(fade_mask, fading.fade_mode, FADE_TYPE_FADE_IN);
982 FadeExt(fade_mask, FADE_MODE_FADE_IN, FADE_TYPE_FADE_IN);
986 FADE_SXSIZE = FULL_SXSIZE;
987 FADE_SYSIZE = FULL_SYSIZE;
989 if (game_status == GAME_MODE_PLAYING &&
990 strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
991 SetOverlayActive(TRUE);
993 SetScreenStates_AfterFadingIn();
995 // force update of global animation status in case of rapid screen changes
996 redraw_mask = REDRAW_ALL;
1000 void FadeOut(int fade_mask)
1002 // update screen if areas covered by "fade_mask" and "redraw_mask" differ
1003 if (!equalRedrawMasks(fade_mask, redraw_mask))
1006 SetScreenStates_BeforeFadingOut();
1008 SetOverlayActive(FALSE);
1011 DrawMaskedBorder(REDRAW_ALL);
1014 if (fading.fade_mode & FADE_TYPE_TRANSFORM)
1015 FadeExt(fade_mask, fading.fade_mode, FADE_TYPE_FADE_OUT);
1017 FadeExt(fade_mask, FADE_MODE_FADE_OUT, FADE_TYPE_FADE_OUT);
1019 SetScreenStates_AfterFadingOut();
1022 static void FadeSetLeaveNext(struct TitleFadingInfo fading_leave, boolean set)
1024 static struct TitleFadingInfo fading_leave_stored;
1027 fading_leave_stored = fading_leave;
1029 fading = fading_leave_stored;
1032 void FadeSetEnterMenu()
1034 fading = menu.enter_menu;
1036 FadeSetLeaveNext(fading, TRUE); /* (keep same fade mode) */
1039 void FadeSetLeaveMenu()
1041 fading = menu.leave_menu;
1043 FadeSetLeaveNext(fading, TRUE); /* (keep same fade mode) */
1046 void FadeSetEnterScreen()
1048 fading = menu.enter_screen[game_status];
1050 FadeSetLeaveNext(menu.leave_screen[game_status], TRUE); /* store */
1053 void FadeSetNextScreen()
1055 fading = menu.next_screen[game_status];
1057 // (do not overwrite fade mode set by FadeSetEnterScreen)
1058 // FadeSetLeaveNext(fading, TRUE); /* (keep same fade mode) */
1061 void FadeSetLeaveScreen()
1063 FadeSetLeaveNext(menu.leave_screen[game_status], FALSE); /* recall */
1066 void FadeSetFromType(int type)
1068 if (type & TYPE_ENTER_SCREEN)
1069 FadeSetEnterScreen();
1070 else if (type & TYPE_ENTER)
1072 else if (type & TYPE_LEAVE)
1076 void FadeSetDisabled()
1078 static struct TitleFadingInfo fading_none = { FADE_MODE_NONE, -1, -1, -1 };
1080 fading = fading_none;
1083 void FadeSkipNextFadeIn()
1085 FadeExt(0, FADE_MODE_SKIP_FADE_IN, FADE_TYPE_SKIP);
1088 void FadeSkipNextFadeOut()
1090 FadeExt(0, FADE_MODE_SKIP_FADE_OUT, FADE_TYPE_SKIP);
1093 Bitmap *getBitmapFromGraphicOrDefault(int graphic, int default_graphic)
1095 boolean redefined = getImageListEntryFromImageID(graphic)->redefined;
1097 return (graphic == IMG_UNDEFINED ? NULL :
1098 graphic_info[graphic].bitmap != NULL || redefined ?
1099 graphic_info[graphic].bitmap :
1100 graphic_info[default_graphic].bitmap);
1103 Bitmap *getBackgroundBitmap(int graphic)
1105 return getBitmapFromGraphicOrDefault(graphic, IMG_BACKGROUND);
1108 Bitmap *getGlobalBorderBitmap(int graphic)
1110 return getBitmapFromGraphicOrDefault(graphic, IMG_GLOBAL_BORDER);
1113 Bitmap *getGlobalBorderBitmapFromStatus(int status)
1116 (status == GAME_MODE_MAIN ||
1117 status == GAME_MODE_PSEUDO_TYPENAME ? IMG_GLOBAL_BORDER_MAIN :
1118 status == GAME_MODE_SCORES ? IMG_GLOBAL_BORDER_SCORES :
1119 status == GAME_MODE_EDITOR ? IMG_GLOBAL_BORDER_EDITOR :
1120 status == GAME_MODE_PLAYING ? IMG_GLOBAL_BORDER_PLAYING :
1123 return getGlobalBorderBitmap(graphic);
1126 void SetWindowBackgroundImageIfDefined(int graphic)
1128 if (graphic_info[graphic].bitmap)
1129 SetWindowBackgroundBitmap(graphic_info[graphic].bitmap);
1132 void SetMainBackgroundImageIfDefined(int graphic)
1134 if (graphic_info[graphic].bitmap)
1135 SetMainBackgroundBitmap(graphic_info[graphic].bitmap);
1138 void SetDoorBackgroundImageIfDefined(int graphic)
1140 if (graphic_info[graphic].bitmap)
1141 SetDoorBackgroundBitmap(graphic_info[graphic].bitmap);
1144 void SetWindowBackgroundImage(int graphic)
1146 SetWindowBackgroundBitmap(getBackgroundBitmap(graphic));
1149 void SetMainBackgroundImage(int graphic)
1151 SetMainBackgroundBitmap(getBackgroundBitmap(graphic));
1154 void SetDoorBackgroundImage(int graphic)
1156 SetDoorBackgroundBitmap(getBackgroundBitmap(graphic));
1159 void SetPanelBackground()
1161 struct GraphicInfo *gfx = &graphic_info[IMG_BACKGROUND_PANEL];
1163 BlitBitmapTiled(gfx->bitmap, bitmap_db_panel, gfx->src_x, gfx->src_y,
1164 gfx->width, gfx->height, 0, 0, DXSIZE, DYSIZE);
1166 SetDoorBackgroundBitmap(bitmap_db_panel);
1169 void DrawBackground(int x, int y, int width, int height)
1171 /* "drawto" might still point to playfield buffer here (hall of fame) */
1172 ClearRectangleOnBackground(backbuffer, x, y, width, height);
1174 if (IN_GFX_FIELD_FULL(x, y))
1175 redraw_mask |= REDRAW_FIELD;
1176 else if (IN_GFX_DOOR_1(x, y))
1177 redraw_mask |= REDRAW_DOOR_1;
1178 else if (IN_GFX_DOOR_2(x, y))
1179 redraw_mask |= REDRAW_DOOR_2;
1180 else if (IN_GFX_DOOR_3(x, y))
1181 redraw_mask |= REDRAW_DOOR_3;
1184 void DrawBackgroundForFont(int x, int y, int width, int height, int font_nr)
1186 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
1188 if (font->bitmap == NULL)
1191 DrawBackground(x, y, width, height);
1194 void DrawBackgroundForGraphic(int x, int y, int width, int height, int graphic)
1196 struct GraphicInfo *g = &graphic_info[graphic];
1198 if (g->bitmap == NULL)
1201 DrawBackground(x, y, width, height);
1204 static int game_status_last = -1;
1205 static Bitmap *global_border_bitmap_last = NULL;
1206 static Bitmap *global_border_bitmap = NULL;
1207 static int real_sx_last = -1, real_sy_last = -1;
1208 static int full_sxsize_last = -1, full_sysize_last = -1;
1209 static int dx_last = -1, dy_last = -1;
1210 static int dxsize_last = -1, dysize_last = -1;
1211 static int vx_last = -1, vy_last = -1;
1212 static int vxsize_last = -1, vysize_last = -1;
1214 boolean CheckIfGlobalBorderHasChanged()
1216 // if game status has not changed, global border has not changed either
1217 if (game_status == game_status_last)
1220 // determine and store new global border bitmap for current game status
1221 global_border_bitmap = getGlobalBorderBitmapFromStatus(game_status);
1223 return (global_border_bitmap_last != global_border_bitmap);
1226 boolean CheckIfGlobalBorderRedrawIsNeeded()
1228 // if game status has not changed, nothing has to be redrawn
1229 if (game_status == game_status_last)
1232 // redraw if last screen was title screen
1233 if (game_status_last == GAME_MODE_TITLE)
1236 // redraw if global screen border has changed
1237 if (CheckIfGlobalBorderHasChanged())
1240 // redraw if position or size of playfield area has changed
1241 if (real_sx_last != REAL_SX || real_sy_last != REAL_SY ||
1242 full_sxsize_last != FULL_SXSIZE || full_sysize_last != FULL_SYSIZE)
1245 // redraw if position or size of door area has changed
1246 if (dx_last != DX || dy_last != DY ||
1247 dxsize_last != DXSIZE || dysize_last != DYSIZE)
1250 // redraw if position or size of tape area has changed
1251 if (vx_last != VX || vy_last != VY ||
1252 vxsize_last != VXSIZE || vysize_last != VYSIZE)
1258 void RedrawGlobalBorderFromBitmap(Bitmap *bitmap)
1261 BlitBitmap(bitmap, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
1263 ClearRectangle(backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE);
1266 void RedrawGlobalBorder()
1268 Bitmap *bitmap = getGlobalBorderBitmapFromStatus(game_status);
1270 RedrawGlobalBorderFromBitmap(bitmap);
1272 redraw_mask = REDRAW_ALL;
1275 static void RedrawGlobalBorderIfNeeded()
1277 if (game_status == game_status_last)
1280 // copy current draw buffer to later copy back areas that have not changed
1281 if (game_status_last != GAME_MODE_TITLE)
1282 BlitBitmap(backbuffer, bitmap_db_store_1, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
1284 if (CheckIfGlobalBorderRedrawIsNeeded())
1286 // redraw global screen border (or clear, if defined to be empty)
1287 RedrawGlobalBorderFromBitmap(global_border_bitmap);
1289 // copy previous playfield and door areas, if they are defined on both
1290 // previous and current screen and if they still have the same size
1292 if (real_sx_last != -1 && real_sy_last != -1 &&
1293 REAL_SX != -1 && REAL_SY != -1 &&
1294 full_sxsize_last == FULL_SXSIZE && full_sysize_last == FULL_SYSIZE)
1295 BlitBitmap(bitmap_db_store_1, backbuffer,
1296 real_sx_last, real_sy_last, FULL_SXSIZE, FULL_SYSIZE,
1299 if (dx_last != -1 && dy_last != -1 &&
1300 DX != -1 && DY != -1 &&
1301 dxsize_last == DXSIZE && dysize_last == DYSIZE)
1302 BlitBitmap(bitmap_db_store_1, backbuffer,
1303 dx_last, dy_last, DXSIZE, DYSIZE, DX, DY);
1305 if (vx_last != -1 && vy_last != -1 &&
1306 VX != -1 && VY != -1 &&
1307 vxsize_last == VXSIZE && vysize_last == VYSIZE)
1308 BlitBitmap(bitmap_db_store_1, backbuffer,
1309 vx_last, vy_last, VXSIZE, VYSIZE, VX, VY);
1311 redraw_mask = REDRAW_ALL;
1314 game_status_last = game_status;
1316 global_border_bitmap_last = global_border_bitmap;
1318 real_sx_last = REAL_SX;
1319 real_sy_last = REAL_SY;
1320 full_sxsize_last = FULL_SXSIZE;
1321 full_sysize_last = FULL_SYSIZE;
1324 dxsize_last = DXSIZE;
1325 dysize_last = DYSIZE;
1328 vxsize_last = VXSIZE;
1329 vysize_last = VYSIZE;
1334 RedrawGlobalBorderIfNeeded();
1336 /* !!! "drawto" might still point to playfield buffer here (see above) !!! */
1337 /* (when entering hall of fame after playing) */
1338 DrawBackground(REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
1340 /* !!! maybe this should be done before clearing the background !!! */
1341 if (game_status == GAME_MODE_PLAYING)
1343 ClearRectangle(fieldbuffer, 0, 0, FXSIZE, FYSIZE);
1344 SetDrawtoField(DRAW_TO_FIELDBUFFER);
1348 SetDrawtoField(DRAW_TO_BACKBUFFER);
1352 void MarkTileDirty(int x, int y)
1354 redraw_mask |= REDRAW_FIELD;
1357 void SetBorderElement()
1361 BorderElement = EL_EMPTY;
1363 /* the MM game engine does not use a visible border element */
1364 if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
1367 for (y = 0; y < lev_fieldy && BorderElement == EL_EMPTY; y++)
1369 for (x = 0; x < lev_fieldx; x++)
1371 if (!IS_INDESTRUCTIBLE(Feld[x][y]))
1372 BorderElement = EL_STEELWALL;
1374 if (y != 0 && y != lev_fieldy - 1 && x != lev_fieldx - 1)
1380 void FloodFillLevelExt(int from_x, int from_y, int fill_element,
1381 int max_array_fieldx, int max_array_fieldy,
1382 short field[max_array_fieldx][max_array_fieldy],
1383 int max_fieldx, int max_fieldy)
1387 static int check[4][2] = { { -1, 0 }, { 0, -1 }, { 1, 0 }, { 0, 1 } };
1388 static int safety = 0;
1390 /* check if starting field still has the desired content */
1391 if (field[from_x][from_y] == fill_element)
1396 if (safety > max_fieldx * max_fieldy)
1397 Error(ERR_EXIT, "Something went wrong in 'FloodFill()'. Please debug.");
1399 old_element = field[from_x][from_y];
1400 field[from_x][from_y] = fill_element;
1402 for (i = 0; i < 4; i++)
1404 x = from_x + check[i][0];
1405 y = from_y + check[i][1];
1407 if (IN_FIELD(x, y, max_fieldx, max_fieldy) && field[x][y] == old_element)
1408 FloodFillLevelExt(x, y, fill_element, max_array_fieldx, max_array_fieldy,
1409 field, max_fieldx, max_fieldy);
1415 void FloodFillLevel(int from_x, int from_y, int fill_element,
1416 short field[MAX_LEV_FIELDX][MAX_LEV_FIELDY],
1417 int max_fieldx, int max_fieldy)
1419 FloodFillLevelExt(from_x, from_y, fill_element,
1420 MAX_LEV_FIELDX, MAX_LEV_FIELDY, field,
1421 max_fieldx, max_fieldy);
1424 void SetRandomAnimationValue(int x, int y)
1426 gfx.anim_random_frame = GfxRandom[x][y];
1429 int getGraphicAnimationFrame(int graphic, int sync_frame)
1431 /* animation synchronized with global frame counter, not move position */
1432 if (graphic_info[graphic].anim_global_sync || sync_frame < 0)
1433 sync_frame = FrameCounter;
1435 return getAnimationFrame(graphic_info[graphic].anim_frames,
1436 graphic_info[graphic].anim_delay,
1437 graphic_info[graphic].anim_mode,
1438 graphic_info[graphic].anim_start_frame,
1442 void getGraphicSourceBitmap(int graphic, int tilesize, Bitmap **bitmap)
1444 struct GraphicInfo *g = &graphic_info[graphic];
1445 int tilesize_capped = MIN(MAX(1, tilesize), TILESIZE);
1447 if (tilesize == gfx.standard_tile_size)
1448 *bitmap = g->bitmaps[IMG_BITMAP_STANDARD];
1449 else if (tilesize == game.tile_size)
1450 *bitmap = g->bitmaps[IMG_BITMAP_GAME];
1452 *bitmap = g->bitmaps[IMG_BITMAP_1x1 - log_2(tilesize_capped)];
1455 void getGraphicSourceXY(int graphic, int frame, int *x, int *y,
1456 boolean get_backside)
1458 struct GraphicInfo *g = &graphic_info[graphic];
1459 int src_x = g->src_x + (get_backside ? g->offset2_x : 0);
1460 int src_y = g->src_y + (get_backside ? g->offset2_y : 0);
1462 if (g->offset_y == 0) /* frames are ordered horizontally */
1464 int max_width = g->anim_frames_per_line * g->width;
1465 int pos = (src_y / g->height) * max_width + src_x + frame * g->offset_x;
1467 *x = pos % max_width;
1468 *y = src_y % g->height + pos / max_width * g->height;
1470 else if (g->offset_x == 0) /* frames are ordered vertically */
1472 int max_height = g->anim_frames_per_line * g->height;
1473 int pos = (src_x / g->width) * max_height + src_y + frame * g->offset_y;
1475 *x = src_x % g->width + pos / max_height * g->width;
1476 *y = pos % max_height;
1478 else /* frames are ordered diagonally */
1480 *x = src_x + frame * g->offset_x;
1481 *y = src_y + frame * g->offset_y;
1485 void getSizedGraphicSourceExt(int graphic, int frame, int tilesize,
1486 Bitmap **bitmap, int *x, int *y,
1487 boolean get_backside)
1489 struct GraphicInfo *g = &graphic_info[graphic];
1491 // if no in-game graphics defined, always use standard graphic size
1492 if (g->bitmaps[IMG_BITMAP_GAME] == NULL)
1493 tilesize = TILESIZE;
1495 getGraphicSourceBitmap(graphic, tilesize, bitmap);
1496 getGraphicSourceXY(graphic, frame, x, y, get_backside);
1498 *x = *x * tilesize / g->tile_size;
1499 *y = *y * tilesize / g->tile_size;
1502 void getSizedGraphicSource(int graphic, int frame, int tilesize,
1503 Bitmap **bitmap, int *x, int *y)
1505 getSizedGraphicSourceExt(graphic, frame, tilesize, bitmap, x, y, FALSE);
1508 void getFixedGraphicSource(int graphic, int frame,
1509 Bitmap **bitmap, int *x, int *y)
1511 getSizedGraphicSourceExt(graphic, frame, TILESIZE, bitmap, x, y, FALSE);
1514 void getMiniGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y)
1516 getSizedGraphicSource(graphic, 0, MINI_TILESIZE, bitmap, x, y);
1519 inline static void getGraphicSourceExt(int graphic, int frame, Bitmap **bitmap,
1520 int *x, int *y, boolean get_backside)
1522 getSizedGraphicSourceExt(graphic, frame, TILESIZE_VAR, bitmap, x, y,
1526 void getGraphicSource(int graphic, int frame, Bitmap **bitmap, int *x, int *y)
1528 getGraphicSourceExt(graphic, frame, bitmap, x, y, FALSE);
1531 void DrawGraphic(int x, int y, int graphic, int frame)
1534 if (!IN_SCR_FIELD(x, y))
1536 printf("DrawGraphic(): x = %d, y = %d, graphic = %d\n", x, y, graphic);
1537 printf("DrawGraphic(): This should never happen!\n");
1542 DrawGraphicExt(drawto_field, FX + x * TILEX_VAR, FY + y * TILEY_VAR, graphic,
1545 MarkTileDirty(x, y);
1548 void DrawFixedGraphic(int x, int y, int graphic, int frame)
1551 if (!IN_SCR_FIELD(x, y))
1553 printf("DrawGraphic(): x = %d, y = %d, graphic = %d\n", x, y, graphic);
1554 printf("DrawGraphic(): This should never happen!\n");
1559 DrawFixedGraphicExt(drawto_field, FX + x * TILEX, FY + y * TILEY, graphic,
1561 MarkTileDirty(x, y);
1564 void DrawGraphicExt(DrawBuffer *dst_bitmap, int x, int y, int graphic,
1570 getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y);
1572 BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, TILEX_VAR, TILEY_VAR, x, y);
1575 void DrawFixedGraphicExt(DrawBuffer *dst_bitmap, int x, int y, int graphic,
1581 getFixedGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y);
1582 BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, TILEX, TILEY, x, y);
1585 void DrawGraphicThruMask(int x, int y, int graphic, int frame)
1588 if (!IN_SCR_FIELD(x, y))
1590 printf("DrawGraphicThruMask(): x = %d,y = %d, graphic = %d\n",x,y,graphic);
1591 printf("DrawGraphicThruMask(): This should never happen!\n");
1596 DrawGraphicThruMaskExt(drawto_field, FX + x * TILEX_VAR, FY + y * TILEY_VAR,
1599 MarkTileDirty(x, y);
1602 void DrawFixedGraphicThruMask(int x, int y, int graphic, int frame)
1605 if (!IN_SCR_FIELD(x, y))
1607 printf("DrawGraphicThruMask(): x = %d,y = %d, graphic = %d\n",x,y,graphic);
1608 printf("DrawGraphicThruMask(): This should never happen!\n");
1613 DrawFixedGraphicThruMaskExt(drawto_field, FX + x * TILEX, FY + y * TILEY,
1615 MarkTileDirty(x, y);
1618 void DrawGraphicThruMaskExt(DrawBuffer *d, int dst_x, int dst_y, int graphic,
1624 getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y);
1626 BlitBitmapMasked(src_bitmap, d, src_x, src_y, TILEX_VAR, TILEY_VAR,
1630 void DrawFixedGraphicThruMaskExt(DrawBuffer *d, int dst_x, int dst_y,
1631 int graphic, int frame)
1636 getFixedGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y);
1638 BlitBitmapMasked(src_bitmap, d, src_x, src_y, TILEX, TILEY,
1642 void DrawSizedGraphic(int x, int y, int graphic, int frame, int tilesize)
1644 DrawSizedGraphicExt(drawto, SX + x * tilesize, SY + y * tilesize, graphic,
1646 MarkTileDirty(x / tilesize, y / tilesize);
1649 void DrawSizedGraphicThruMask(int x, int y, int graphic, int frame,
1652 DrawSizedGraphicThruMaskExt(drawto, SX + x * tilesize, SY + y * tilesize,
1653 graphic, frame, tilesize);
1654 MarkTileDirty(x / tilesize, y / tilesize);
1657 void DrawSizedGraphicExt(DrawBuffer *d, int x, int y, int graphic, int frame,
1663 getSizedGraphicSource(graphic, frame, tilesize, &src_bitmap, &src_x, &src_y);
1664 BlitBitmap(src_bitmap, d, src_x, src_y, tilesize, tilesize, x, y);
1667 void DrawSizedGraphicThruMaskExt(DrawBuffer *d, int x, int y, int graphic,
1668 int frame, int tilesize)
1673 getSizedGraphicSource(graphic, frame, tilesize, &src_bitmap, &src_x, &src_y);
1674 BlitBitmapMasked(src_bitmap, d, src_x, src_y, tilesize, tilesize, x, y);
1677 void DrawMiniGraphic(int x, int y, int graphic)
1679 DrawMiniGraphicExt(drawto, SX + x * MINI_TILEX,SY + y * MINI_TILEY, graphic);
1680 MarkTileDirty(x / 2, y / 2);
1683 void DrawMiniGraphicExt(DrawBuffer *d, int x, int y, int graphic)
1688 getMiniGraphicSource(graphic, &src_bitmap, &src_x, &src_y);
1689 BlitBitmap(src_bitmap, d, src_x, src_y, MINI_TILEX, MINI_TILEY, x, y);
1692 inline static void DrawGraphicShiftedNormal(int x, int y, int dx, int dy,
1693 int graphic, int frame,
1694 int cut_mode, int mask_mode)
1699 int width = TILEX, height = TILEY;
1702 if (dx || dy) /* shifted graphic */
1704 if (x < BX1) /* object enters playfield from the left */
1711 else if (x > BX2) /* object enters playfield from the right */
1717 else if (x == BX1 && dx < 0) /* object leaves playfield to the left */
1723 else if (x == BX2 && dx > 0) /* object leaves playfield to the right */
1725 else if (dx) /* general horizontal movement */
1726 MarkTileDirty(x + SIGN(dx), y);
1728 if (y < BY1) /* object enters playfield from the top */
1730 if (cut_mode == CUT_BELOW) /* object completely above top border */
1738 else if (y > BY2) /* object enters playfield from the bottom */
1744 else if (y == BY1 && dy < 0) /* object leaves playfield to the top */
1750 else if (dy > 0 && cut_mode == CUT_ABOVE)
1752 if (y == BY2) /* object completely above bottom border */
1758 MarkTileDirty(x, y + 1);
1759 } /* object leaves playfield to the bottom */
1760 else if (dy > 0 && (y == BY2 || cut_mode == CUT_BELOW))
1762 else if (dy) /* general vertical movement */
1763 MarkTileDirty(x, y + SIGN(dy));
1767 if (!IN_SCR_FIELD(x, y))
1769 printf("DrawGraphicShifted(): x = %d, y = %d, graphic = %d\n",x,y,graphic);
1770 printf("DrawGraphicShifted(): This should never happen!\n");
1775 width = width * TILESIZE_VAR / TILESIZE;
1776 height = height * TILESIZE_VAR / TILESIZE;
1777 cx = cx * TILESIZE_VAR / TILESIZE;
1778 cy = cy * TILESIZE_VAR / TILESIZE;
1779 dx = dx * TILESIZE_VAR / TILESIZE;
1780 dy = dy * TILESIZE_VAR / TILESIZE;
1782 if (width > 0 && height > 0)
1784 getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y);
1789 dst_x = FX + x * TILEX_VAR + dx;
1790 dst_y = FY + y * TILEY_VAR + dy;
1792 if (mask_mode == USE_MASKING)
1793 BlitBitmapMasked(src_bitmap, drawto_field, src_x, src_y, width, height,
1796 BlitBitmap(src_bitmap, drawto_field, src_x, src_y, width, height,
1799 MarkTileDirty(x, y);
1803 inline static void DrawGraphicShiftedDouble(int x, int y, int dx, int dy,
1804 int graphic, int frame,
1805 int cut_mode, int mask_mode)
1810 int width = TILEX_VAR, height = TILEY_VAR;
1813 int x2 = x + SIGN(dx);
1814 int y2 = y + SIGN(dy);
1816 /* movement with two-tile animations must be sync'ed with movement position,
1817 not with current GfxFrame (which can be higher when using slow movement) */
1818 int anim_pos = (dx ? ABS(dx) : ABS(dy));
1819 int anim_frames = graphic_info[graphic].anim_frames;
1821 /* (we also need anim_delay here for movement animations with less frames) */
1822 int anim_delay = graphic_info[graphic].anim_delay;
1823 int sync_frame = anim_pos * anim_frames * anim_delay / TILESIZE;
1825 boolean draw_start_tile = (cut_mode != CUT_ABOVE); /* only for falling! */
1826 boolean draw_end_tile = (cut_mode != CUT_BELOW); /* only for falling! */
1828 /* re-calculate animation frame for two-tile movement animation */
1829 frame = getGraphicAnimationFrame(graphic, sync_frame);
1831 /* check if movement start graphic inside screen area and should be drawn */
1832 if (draw_start_tile && IN_SCR_FIELD(x1, y1))
1834 getGraphicSourceExt(graphic, frame, &src_bitmap, &src_x, &src_y, TRUE);
1836 dst_x = FX + x1 * TILEX_VAR;
1837 dst_y = FY + y1 * TILEY_VAR;
1839 if (mask_mode == USE_MASKING)
1840 BlitBitmapMasked(src_bitmap, drawto_field, src_x, src_y, width, height,
1843 BlitBitmap(src_bitmap, drawto_field, src_x, src_y, width, height,
1846 MarkTileDirty(x1, y1);
1849 /* check if movement end graphic inside screen area and should be drawn */
1850 if (draw_end_tile && IN_SCR_FIELD(x2, y2))
1852 getGraphicSourceExt(graphic, frame, &src_bitmap, &src_x, &src_y, FALSE);
1854 dst_x = FX + x2 * TILEX_VAR;
1855 dst_y = FY + y2 * TILEY_VAR;
1857 if (mask_mode == USE_MASKING)
1858 BlitBitmapMasked(src_bitmap, drawto_field, src_x, src_y, width, height,
1861 BlitBitmap(src_bitmap, drawto_field, src_x, src_y, width, height,
1864 MarkTileDirty(x2, y2);
1868 static void DrawGraphicShifted(int x, int y, int dx, int dy,
1869 int graphic, int frame,
1870 int cut_mode, int mask_mode)
1874 DrawGraphic(x, y, graphic, frame);
1879 if (graphic_info[graphic].double_movement) /* EM style movement images */
1880 DrawGraphicShiftedDouble(x, y, dx, dy, graphic, frame, cut_mode,mask_mode);
1882 DrawGraphicShiftedNormal(x, y, dx, dy, graphic, frame, cut_mode,mask_mode);
1885 void DrawGraphicShiftedThruMask(int x, int y, int dx, int dy, int graphic,
1886 int frame, int cut_mode)
1888 DrawGraphicShifted(x, y, dx, dy, graphic, frame, cut_mode, USE_MASKING);
1891 void DrawScreenElementExt(int x, int y, int dx, int dy, int element,
1892 int cut_mode, int mask_mode)
1894 int lx = LEVELX(x), ly = LEVELY(y);
1898 if (IN_LEV_FIELD(lx, ly))
1900 SetRandomAnimationValue(lx, ly);
1902 graphic = el_act_dir2img(element, GfxAction[lx][ly], GfxDir[lx][ly]);
1903 frame = getGraphicAnimationFrame(graphic, GfxFrame[lx][ly]);
1905 /* do not use double (EM style) movement graphic when not moving */
1906 if (graphic_info[graphic].double_movement && !dx && !dy)
1908 graphic = el_act_dir2img(element, ACTION_DEFAULT, GfxDir[lx][ly]);
1909 frame = getGraphicAnimationFrame(graphic, GfxFrame[lx][ly]);
1912 else /* border element */
1914 graphic = el2img(element);
1915 frame = getGraphicAnimationFrame(graphic, -1);
1918 if (element == EL_EXPANDABLE_WALL)
1920 boolean left_stopped = FALSE, right_stopped = FALSE;
1922 if (!IN_LEV_FIELD(lx - 1, ly) || IS_WALL(Feld[lx - 1][ly]))
1923 left_stopped = TRUE;
1924 if (!IN_LEV_FIELD(lx + 1, ly) || IS_WALL(Feld[lx + 1][ly]))
1925 right_stopped = TRUE;
1927 if (left_stopped && right_stopped)
1929 else if (left_stopped)
1931 graphic = IMG_EXPANDABLE_WALL_GROWING_RIGHT;
1932 frame = graphic_info[graphic].anim_frames - 1;
1934 else if (right_stopped)
1936 graphic = IMG_EXPANDABLE_WALL_GROWING_LEFT;
1937 frame = graphic_info[graphic].anim_frames - 1;
1942 DrawGraphicShifted(x, y, dx, dy, graphic, frame, cut_mode, mask_mode);
1943 else if (mask_mode == USE_MASKING)
1944 DrawGraphicThruMask(x, y, graphic, frame);
1946 DrawGraphic(x, y, graphic, frame);
1949 void DrawLevelElementExt(int x, int y, int dx, int dy, int element,
1950 int cut_mode, int mask_mode)
1952 if (IN_LEV_FIELD(x, y) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
1953 DrawScreenElementExt(SCREENX(x), SCREENY(y), dx, dy, element,
1954 cut_mode, mask_mode);
1957 void DrawScreenElementShifted(int x, int y, int dx, int dy, int element,
1960 DrawScreenElementExt(x, y, dx, dy, element, cut_mode, NO_MASKING);
1963 void DrawLevelElementShifted(int x, int y, int dx, int dy, int element,
1966 DrawLevelElementExt(x, y, dx, dy, element, cut_mode, NO_MASKING);
1969 void DrawLevelElementThruMask(int x, int y, int element)
1971 DrawLevelElementExt(x, y, 0, 0, element, NO_CUTTING, USE_MASKING);
1974 void DrawLevelFieldThruMask(int x, int y)
1976 DrawLevelElementExt(x, y, 0, 0, Feld[x][y], NO_CUTTING, USE_MASKING);
1979 /* !!! implementation of quicksand is totally broken !!! */
1980 #define IS_CRUMBLED_TILE(x, y, e) \
1981 (GFX_CRUMBLED(e) && (!IN_LEV_FIELD(x, y) || \
1982 !IS_MOVING(x, y) || \
1983 (e) == EL_QUICKSAND_EMPTYING || \
1984 (e) == EL_QUICKSAND_FAST_EMPTYING))
1986 static void DrawLevelFieldCrumbledInnerCorners(int x, int y, int dx, int dy,
1991 int width, height, cx, cy;
1992 int sx = SCREENX(x), sy = SCREENY(y);
1993 int crumbled_border_size = graphic_info[graphic].border_size;
1994 int crumbled_tile_size = graphic_info[graphic].tile_size;
1995 int crumbled_border_size_var =
1996 crumbled_border_size * TILESIZE_VAR / crumbled_tile_size;
1999 getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
2001 for (i = 1; i < 4; i++)
2003 int dxx = (i & 1 ? dx : 0);
2004 int dyy = (i & 2 ? dy : 0);
2007 int element = (IN_LEV_FIELD(xx, yy) ? TILE_GFX_ELEMENT(xx, yy) :
2010 /* check if neighbour field is of same crumble type */
2011 boolean same = (IS_CRUMBLED_TILE(xx, yy, element) &&
2012 graphic_info[graphic].class ==
2013 graphic_info[el_act2crm(element, ACTION_DEFAULT)].class);
2015 /* return if check prevents inner corner */
2016 if (same == (dxx == dx && dyy == dy))
2020 /* if we reach this point, we have an inner corner */
2022 getGraphicSource(graphic, 1, &src_bitmap, &src_x, &src_y);
2024 width = crumbled_border_size_var;
2025 height = crumbled_border_size_var;
2026 cx = (dx > 0 ? TILESIZE_VAR - width : 0);
2027 cy = (dy > 0 ? TILESIZE_VAR - height : 0);
2029 BlitBitmap(src_bitmap, drawto_field, src_x + cx, src_y + cy,
2030 width, height, FX + sx * TILEX_VAR + cx, FY + sy * TILEY_VAR + cy);
2033 static void DrawLevelFieldCrumbledBorders(int x, int y, int graphic, int frame,
2038 int width, height, bx, by, cx, cy;
2039 int sx = SCREENX(x), sy = SCREENY(y);
2040 int crumbled_border_size = graphic_info[graphic].border_size;
2041 int crumbled_tile_size = graphic_info[graphic].tile_size;
2042 int crumbled_border_size_var =
2043 crumbled_border_size * TILESIZE_VAR / crumbled_tile_size;
2044 int crumbled_border_pos_var = TILESIZE_VAR - crumbled_border_size_var;
2047 getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y);
2049 /* draw simple, sloppy, non-corner-accurate crumbled border */
2051 width = (dir == 1 || dir == 2 ? crumbled_border_size_var : TILESIZE_VAR);
2052 height = (dir == 0 || dir == 3 ? crumbled_border_size_var : TILESIZE_VAR);
2053 cx = (dir == 2 ? crumbled_border_pos_var : 0);
2054 cy = (dir == 3 ? crumbled_border_pos_var : 0);
2056 BlitBitmap(src_bitmap, drawto_field, src_x + cx, src_y + cy, width, height,
2057 FX + sx * TILEX_VAR + cx,
2058 FY + sy * TILEY_VAR + cy);
2060 /* (remaining middle border part must be at least as big as corner part) */
2061 if (!(graphic_info[graphic].style & STYLE_ACCURATE_BORDERS) ||
2062 crumbled_border_size_var >= TILESIZE_VAR / 3)
2065 /* correct corners of crumbled border, if needed */
2067 for (i = -1; i <= 1; i += 2)
2069 int xx = x + (dir == 0 || dir == 3 ? i : 0);
2070 int yy = y + (dir == 1 || dir == 2 ? i : 0);
2071 int element = (IN_LEV_FIELD(xx, yy) ? TILE_GFX_ELEMENT(xx, yy) :
2074 /* check if neighbour field is of same crumble type */
2075 if (IS_CRUMBLED_TILE(xx, yy, element) &&
2076 graphic_info[graphic].class ==
2077 graphic_info[el_act2crm(element, ACTION_DEFAULT)].class)
2079 /* no crumbled corner, but continued crumbled border */
2081 int c1 = (dir == 2 || dir == 3 ? crumbled_border_pos_var : 0);
2082 int c2 = (i == 1 ? crumbled_border_pos_var : 0);
2083 int b1 = (i == 1 ? crumbled_border_size_var :
2084 TILESIZE_VAR - 2 * crumbled_border_size_var);
2086 width = crumbled_border_size_var;
2087 height = crumbled_border_size_var;
2089 if (dir == 1 || dir == 2)
2104 BlitBitmap(src_bitmap, drawto_field, src_x + bx, src_y + by,
2106 FX + sx * TILEX_VAR + cx,
2107 FY + sy * TILEY_VAR + cy);
2112 static void DrawLevelFieldCrumbledExt(int x, int y, int graphic, int frame)
2114 int sx = SCREENX(x), sy = SCREENY(y);
2117 static int xy[4][2] =
2125 if (!IN_LEV_FIELD(x, y))
2128 element = TILE_GFX_ELEMENT(x, y);
2130 if (IS_CRUMBLED_TILE(x, y, element)) /* crumble field itself */
2132 if (!IN_SCR_FIELD(sx, sy))
2135 /* crumble field borders towards direct neighbour fields */
2136 for (i = 0; i < 4; i++)
2138 int xx = x + xy[i][0];
2139 int yy = y + xy[i][1];
2141 element = (IN_LEV_FIELD(xx, yy) ? TILE_GFX_ELEMENT(xx, yy) :
2144 /* check if neighbour field is of same crumble type */
2145 if (IS_CRUMBLED_TILE(xx, yy, element) &&
2146 graphic_info[graphic].class ==
2147 graphic_info[el_act2crm(element, ACTION_DEFAULT)].class)
2150 DrawLevelFieldCrumbledBorders(x, y, graphic, frame, i);
2153 /* crumble inner field corners towards corner neighbour fields */
2154 if ((graphic_info[graphic].style & STYLE_INNER_CORNERS) &&
2155 graphic_info[graphic].anim_frames == 2)
2157 for (i = 0; i < 4; i++)
2159 int dx = (i & 1 ? +1 : -1);
2160 int dy = (i & 2 ? +1 : -1);
2162 DrawLevelFieldCrumbledInnerCorners(x, y, dx, dy, graphic);
2166 MarkTileDirty(sx, sy);
2168 else /* center field is not crumbled -- crumble neighbour fields */
2170 /* crumble field borders of direct neighbour fields */
2171 for (i = 0; i < 4; i++)
2173 int xx = x + xy[i][0];
2174 int yy = y + xy[i][1];
2175 int sxx = sx + xy[i][0];
2176 int syy = sy + xy[i][1];
2178 if (!IN_LEV_FIELD(xx, yy) ||
2179 !IN_SCR_FIELD(sxx, syy))
2182 if (Feld[xx][yy] == EL_ELEMENT_SNAPPING)
2185 element = TILE_GFX_ELEMENT(xx, yy);
2187 if (!IS_CRUMBLED_TILE(xx, yy, element))
2190 graphic = el_act2crm(element, ACTION_DEFAULT);
2192 DrawLevelFieldCrumbledBorders(xx, yy, graphic, 0, 3 - i);
2194 MarkTileDirty(sxx, syy);
2197 /* crumble inner field corners of corner neighbour fields */
2198 for (i = 0; i < 4; i++)
2200 int dx = (i & 1 ? +1 : -1);
2201 int dy = (i & 2 ? +1 : -1);
2207 if (!IN_LEV_FIELD(xx, yy) ||
2208 !IN_SCR_FIELD(sxx, syy))
2211 if (Feld[xx][yy] == EL_ELEMENT_SNAPPING)
2214 element = TILE_GFX_ELEMENT(xx, yy);
2216 if (!IS_CRUMBLED_TILE(xx, yy, element))
2219 graphic = el_act2crm(element, ACTION_DEFAULT);
2221 if ((graphic_info[graphic].style & STYLE_INNER_CORNERS) &&
2222 graphic_info[graphic].anim_frames == 2)
2223 DrawLevelFieldCrumbledInnerCorners(xx, yy, -dx, -dy, graphic);
2225 MarkTileDirty(sxx, syy);
2230 void DrawLevelFieldCrumbled(int x, int y)
2234 if (!IN_LEV_FIELD(x, y))
2237 if (Feld[x][y] == EL_ELEMENT_SNAPPING &&
2238 GfxElement[x][y] != EL_UNDEFINED &&
2239 GFX_CRUMBLED(GfxElement[x][y]))
2241 DrawLevelFieldCrumbledDigging(x, y, GfxDir[x][y], GfxFrame[x][y]);
2246 graphic = el_act2crm(TILE_GFX_ELEMENT(x, y), ACTION_DEFAULT);
2248 DrawLevelFieldCrumbledExt(x, y, graphic, 0);
2251 void DrawLevelFieldCrumbledDigging(int x, int y, int direction,
2254 int graphic1 = el_act_dir2img(GfxElement[x][y], ACTION_DIGGING, direction);
2255 int graphic2 = el_act_dir2crm(GfxElement[x][y], ACTION_DIGGING, direction);
2256 int frame1 = getGraphicAnimationFrame(graphic1, step_frame);
2257 int frame2 = getGraphicAnimationFrame(graphic2, step_frame);
2258 int sx = SCREENX(x), sy = SCREENY(y);
2260 DrawGraphic(sx, sy, graphic1, frame1);
2261 DrawLevelFieldCrumbledExt(x, y, graphic2, frame2);
2264 void DrawLevelFieldCrumbledNeighbours(int x, int y)
2266 int sx = SCREENX(x), sy = SCREENY(y);
2267 static int xy[4][2] =
2276 /* crumble direct neighbour fields (required for field borders) */
2277 for (i = 0; i < 4; i++)
2279 int xx = x + xy[i][0];
2280 int yy = y + xy[i][1];
2281 int sxx = sx + xy[i][0];
2282 int syy = sy + xy[i][1];
2284 if (!IN_LEV_FIELD(xx, yy) ||
2285 !IN_SCR_FIELD(sxx, syy) ||
2286 !GFX_CRUMBLED(Feld[xx][yy]) ||
2290 DrawLevelField(xx, yy);
2293 /* crumble corner neighbour fields (required for inner field corners) */
2294 for (i = 0; i < 4; i++)
2296 int dx = (i & 1 ? +1 : -1);
2297 int dy = (i & 2 ? +1 : -1);
2303 if (!IN_LEV_FIELD(xx, yy) ||
2304 !IN_SCR_FIELD(sxx, syy) ||
2305 !GFX_CRUMBLED(Feld[xx][yy]) ||
2309 int element = TILE_GFX_ELEMENT(xx, yy);
2310 int graphic = el_act2crm(element, ACTION_DEFAULT);
2312 if ((graphic_info[graphic].style & STYLE_INNER_CORNERS) &&
2313 graphic_info[graphic].anim_frames == 2)
2314 DrawLevelField(xx, yy);
2318 static int getBorderElement(int x, int y)
2322 { EL_STEELWALL_TOPLEFT, EL_INVISIBLE_STEELWALL_TOPLEFT },
2323 { EL_STEELWALL_TOPRIGHT, EL_INVISIBLE_STEELWALL_TOPRIGHT },
2324 { EL_STEELWALL_BOTTOMLEFT, EL_INVISIBLE_STEELWALL_BOTTOMLEFT },
2325 { EL_STEELWALL_BOTTOMRIGHT, EL_INVISIBLE_STEELWALL_BOTTOMRIGHT },
2326 { EL_STEELWALL_VERTICAL, EL_INVISIBLE_STEELWALL_VERTICAL },
2327 { EL_STEELWALL_HORIZONTAL, EL_INVISIBLE_STEELWALL_HORIZONTAL },
2328 { EL_STEELWALL, EL_INVISIBLE_STEELWALL }
2330 int steel_type = (BorderElement == EL_STEELWALL ? 0 : 1);
2331 int steel_position = (x == -1 && y == -1 ? 0 :
2332 x == lev_fieldx && y == -1 ? 1 :
2333 x == -1 && y == lev_fieldy ? 2 :
2334 x == lev_fieldx && y == lev_fieldy ? 3 :
2335 x == -1 || x == lev_fieldx ? 4 :
2336 y == -1 || y == lev_fieldy ? 5 : 6);
2338 return border[steel_position][steel_type];
2341 void DrawScreenElement(int x, int y, int element)
2343 DrawScreenElementExt(x, y, 0, 0, element, NO_CUTTING, NO_MASKING);
2344 DrawLevelFieldCrumbled(LEVELX(x), LEVELY(y));
2347 void DrawLevelElement(int x, int y, int element)
2349 if (IN_LEV_FIELD(x, y) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
2350 DrawScreenElement(SCREENX(x), SCREENY(y), element);
2353 void DrawScreenField(int x, int y)
2355 int lx = LEVELX(x), ly = LEVELY(y);
2356 int element, content;
2358 if (!IN_LEV_FIELD(lx, ly))
2360 if (lx < -1 || lx > lev_fieldx || ly < -1 || ly > lev_fieldy)
2363 element = getBorderElement(lx, ly);
2365 DrawScreenElement(x, y, element);
2370 element = Feld[lx][ly];
2371 content = Store[lx][ly];
2373 if (IS_MOVING(lx, ly))
2375 int horiz_move = (MovDir[lx][ly] == MV_LEFT || MovDir[lx][ly] == MV_RIGHT);
2376 boolean cut_mode = NO_CUTTING;
2378 if (element == EL_QUICKSAND_EMPTYING ||
2379 element == EL_QUICKSAND_FAST_EMPTYING ||
2380 element == EL_MAGIC_WALL_EMPTYING ||
2381 element == EL_BD_MAGIC_WALL_EMPTYING ||
2382 element == EL_DC_MAGIC_WALL_EMPTYING ||
2383 element == EL_AMOEBA_DROPPING)
2384 cut_mode = CUT_ABOVE;
2385 else if (element == EL_QUICKSAND_FILLING ||
2386 element == EL_QUICKSAND_FAST_FILLING ||
2387 element == EL_MAGIC_WALL_FILLING ||
2388 element == EL_BD_MAGIC_WALL_FILLING ||
2389 element == EL_DC_MAGIC_WALL_FILLING)
2390 cut_mode = CUT_BELOW;
2392 if (cut_mode == CUT_ABOVE)
2393 DrawScreenElement(x, y, element);
2395 DrawScreenElement(x, y, EL_EMPTY);
2398 DrawScreenElementShifted(x, y, MovPos[lx][ly], 0, element, NO_CUTTING);
2399 else if (cut_mode == NO_CUTTING)
2400 DrawScreenElementShifted(x, y, 0, MovPos[lx][ly], element, cut_mode);
2403 DrawScreenElementShifted(x, y, 0, MovPos[lx][ly], content, cut_mode);
2405 if (cut_mode == CUT_BELOW &&
2406 IN_LEV_FIELD(lx, ly + 1) && IN_SCR_FIELD(x, y + 1))
2407 DrawLevelElement(lx, ly + 1, element);
2410 if (content == EL_ACID)
2412 int dir = MovDir[lx][ly];
2413 int newlx = lx + (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
2414 int newly = ly + (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
2416 DrawLevelElementThruMask(newlx, newly, EL_ACID);
2418 // prevent target field from being drawn again (but without masking)
2419 // (this would happen if target field is scanned after moving element)
2420 Stop[newlx][newly] = TRUE;
2423 else if (IS_BLOCKED(lx, ly))
2428 boolean cut_mode = NO_CUTTING;
2429 int element_old, content_old;
2431 Blocked2Moving(lx, ly, &oldx, &oldy);
2434 horiz_move = (MovDir[oldx][oldy] == MV_LEFT ||
2435 MovDir[oldx][oldy] == MV_RIGHT);
2437 element_old = Feld[oldx][oldy];
2438 content_old = Store[oldx][oldy];
2440 if (element_old == EL_QUICKSAND_EMPTYING ||
2441 element_old == EL_QUICKSAND_FAST_EMPTYING ||
2442 element_old == EL_MAGIC_WALL_EMPTYING ||
2443 element_old == EL_BD_MAGIC_WALL_EMPTYING ||
2444 element_old == EL_DC_MAGIC_WALL_EMPTYING ||
2445 element_old == EL_AMOEBA_DROPPING)
2446 cut_mode = CUT_ABOVE;
2448 DrawScreenElement(x, y, EL_EMPTY);
2451 DrawScreenElementShifted(sx, sy, MovPos[oldx][oldy], 0, element_old,
2453 else if (cut_mode == NO_CUTTING)
2454 DrawScreenElementShifted(sx, sy, 0, MovPos[oldx][oldy], element_old,
2457 DrawScreenElementShifted(sx, sy, 0, MovPos[oldx][oldy], content_old,
2460 else if (IS_DRAWABLE(element))
2461 DrawScreenElement(x, y, element);
2463 DrawScreenElement(x, y, EL_EMPTY);
2466 void DrawLevelField(int x, int y)
2468 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
2469 DrawScreenField(SCREENX(x), SCREENY(y));
2470 else if (IS_MOVING(x, y))
2474 Moving2Blocked(x, y, &newx, &newy);
2475 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
2476 DrawScreenField(SCREENX(newx), SCREENY(newy));
2478 else if (IS_BLOCKED(x, y))
2482 Blocked2Moving(x, y, &oldx, &oldy);
2483 if (IN_SCR_FIELD(SCREENX(oldx), SCREENY(oldy)))
2484 DrawScreenField(SCREENX(oldx), SCREENY(oldy));
2488 static void DrawSizedWallExt_MM(int dst_x, int dst_y, int element, int tilesize,
2489 int (*el2img_function)(int), boolean masked,
2490 int element_bits_draw)
2492 int element_base = map_mm_wall_element(element);
2493 int element_bits = (IS_DF_WALL(element) ?
2494 element - EL_DF_WALL_START :
2495 IS_MM_WALL(element) ?
2496 element - EL_MM_WALL_START : EL_EMPTY) & 0x000f;
2497 int graphic = el2img_function(element_base);
2498 int tilesize_draw = tilesize / 2;
2503 getSizedGraphicSource(graphic, 0, tilesize_draw, &src_bitmap, &src_x, &src_y);
2505 for (i = 0; i < 4; i++)
2507 int dst_draw_x = dst_x + (i % 2) * tilesize_draw;
2508 int dst_draw_y = dst_y + (i / 2) * tilesize_draw;
2510 if (!(element_bits_draw & (1 << i)))
2513 if (element_bits & (1 << i))
2516 BlitBitmapMasked(src_bitmap, drawto, src_x, src_y,
2517 tilesize_draw, tilesize_draw, dst_draw_x, dst_draw_y);
2519 BlitBitmap(src_bitmap, drawto, src_x, src_y,
2520 tilesize_draw, tilesize_draw, dst_draw_x, dst_draw_y);
2525 ClearRectangle(drawto, dst_draw_x, dst_draw_y,
2526 tilesize_draw, tilesize_draw);
2531 void DrawSizedWallParts_MM(int x, int y, int element, int tilesize,
2532 boolean masked, int element_bits_draw)
2534 DrawSizedWallExt_MM(SX + x * tilesize, SY + y * tilesize,
2535 element, tilesize, el2edimg, masked, element_bits_draw);
2538 void DrawSizedWall_MM(int dst_x, int dst_y, int element, int tilesize,
2539 int (*el2img_function)(int))
2541 DrawSizedWallExt_MM(dst_x, dst_y, element, tilesize, el2img_function, FALSE,
2545 void DrawSizedElementExt(int x, int y, int element, int tilesize,
2548 if (IS_MM_WALL(element))
2550 DrawSizedWallExt_MM(SX + x * tilesize, SY + y * tilesize,
2551 element, tilesize, el2edimg, masked, 0x000f);
2555 int graphic = el2edimg(element);
2558 DrawSizedGraphicThruMask(x, y, graphic, 0, tilesize);
2560 DrawSizedGraphic(x, y, graphic, 0, tilesize);
2564 void DrawSizedElement(int x, int y, int element, int tilesize)
2566 DrawSizedElementExt(x, y, element, tilesize, FALSE);
2569 void DrawSizedElementThruMask(int x, int y, int element, int tilesize)
2571 DrawSizedElementExt(x, y, element, tilesize, TRUE);
2574 void DrawMiniElement(int x, int y, int element)
2578 graphic = el2edimg(element);
2579 DrawMiniGraphic(x, y, graphic);
2582 void DrawSizedElementOrWall(int sx, int sy, int scroll_x, int scroll_y,
2585 int x = sx + scroll_x, y = sy + scroll_y;
2587 if (x < -1 || x > lev_fieldx || y < -1 || y > lev_fieldy)
2588 DrawSizedElement(sx, sy, EL_EMPTY, tilesize);
2589 else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy)
2590 DrawSizedElement(sx, sy, Feld[x][y], tilesize);
2592 DrawSizedGraphic(sx, sy, el2edimg(getBorderElement(x, y)), 0, tilesize);
2595 void DrawMiniElementOrWall(int sx, int sy, int scroll_x, int scroll_y)
2597 int x = sx + scroll_x, y = sy + scroll_y;
2599 if (x < -1 || x > lev_fieldx || y < -1 || y > lev_fieldy)
2600 DrawMiniElement(sx, sy, EL_EMPTY);
2601 else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy)
2602 DrawMiniElement(sx, sy, Feld[x][y]);
2604 DrawMiniGraphic(sx, sy, el2edimg(getBorderElement(x, y)));
2607 void DrawEnvelopeBackgroundTiles(int graphic, int startx, int starty,
2608 int x, int y, int xsize, int ysize,
2609 int tile_width, int tile_height)
2613 int dst_x = startx + x * tile_width;
2614 int dst_y = starty + y * tile_height;
2615 int width = graphic_info[graphic].width;
2616 int height = graphic_info[graphic].height;
2617 int inner_width_raw = MAX(width - 2 * tile_width, tile_width);
2618 int inner_height_raw = MAX(height - 2 * tile_height, tile_height);
2619 int inner_width = inner_width_raw - (inner_width_raw % tile_width);
2620 int inner_height = inner_height_raw - (inner_height_raw % tile_height);
2621 int inner_sx = (width >= 3 * tile_width ? tile_width : 0);
2622 int inner_sy = (height >= 3 * tile_height ? tile_height : 0);
2623 boolean draw_masked = graphic_info[graphic].draw_masked;
2625 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
2627 if (src_bitmap == NULL || width < tile_width || height < tile_height)
2629 ClearRectangle(drawto, dst_x, dst_y, tile_width, tile_height);
2633 src_x += (x == 0 ? 0 : x == xsize - 1 ? width - tile_width :
2634 inner_sx + (x - 1) * tile_width % inner_width);
2635 src_y += (y == 0 ? 0 : y == ysize - 1 ? height - tile_height :
2636 inner_sy + (y - 1) * tile_height % inner_height);
2639 BlitBitmapMasked(src_bitmap, drawto, src_x, src_y, tile_width, tile_height,
2642 BlitBitmap(src_bitmap, drawto, src_x, src_y, tile_width, tile_height,
2646 void DrawEnvelopeBackground(int graphic, int startx, int starty,
2647 int x, int y, int xsize, int ysize, int font_nr)
2649 int font_width = getFontWidth(font_nr);
2650 int font_height = getFontHeight(font_nr);
2652 DrawEnvelopeBackgroundTiles(graphic, startx, starty, x, y, xsize, ysize,
2653 font_width, font_height);
2656 void AnimateEnvelope(int envelope_nr, int anim_mode, int action)
2658 int graphic = IMG_BACKGROUND_ENVELOPE_1 + envelope_nr;
2659 Bitmap *src_bitmap = graphic_info[graphic].bitmap;
2660 int mask_mode = (src_bitmap != NULL ? BLIT_MASKED : BLIT_ON_BACKGROUND);
2661 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2662 boolean no_delay = (tape.warp_forward);
2663 unsigned int anim_delay = 0;
2664 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2665 int anim_delay_value = MAX(1, (no_delay ? 0 : frame_delay_value) / 2);
2666 int font_nr = FONT_ENVELOPE_1 + envelope_nr;
2667 int font_width = getFontWidth(font_nr);
2668 int font_height = getFontHeight(font_nr);
2669 int max_xsize = level.envelope[envelope_nr].xsize;
2670 int max_ysize = level.envelope[envelope_nr].ysize;
2671 int xstart = (anim_mode & ANIM_VERTICAL ? max_xsize : 0);
2672 int ystart = (anim_mode & ANIM_HORIZONTAL ? max_ysize : 0);
2673 int xend = max_xsize;
2674 int yend = (anim_mode != ANIM_DEFAULT ? max_ysize : 0);
2675 int xstep = (xstart < xend ? 1 : 0);
2676 int ystep = (ystart < yend || xstep == 0 ? 1 : 0);
2678 int end = MAX(xend - xstart, yend - ystart);
2681 for (i = start; i <= end; i++)
2683 int last_frame = end; // last frame of this "for" loop
2684 int x = xstart + i * xstep;
2685 int y = ystart + i * ystep;
2686 int xsize = (action == ACTION_CLOSING ? xend - (x - xstart) : x) + 2;
2687 int ysize = (action == ACTION_CLOSING ? yend - (y - ystart) : y) + 2;
2688 int sx = SX + (SXSIZE - xsize * font_width) / 2;
2689 int sy = SY + (SYSIZE - ysize * font_height) / 2;
2692 SetDrawtoField(DRAW_TO_FIELDBUFFER);
2694 BlitScreenToBitmap(backbuffer);
2696 SetDrawtoField(DRAW_TO_BACKBUFFER);
2698 for (yy = 0; yy < ysize; yy++)
2699 for (xx = 0; xx < xsize; xx++)
2700 DrawEnvelopeBackground(graphic, sx, sy, xx, yy, xsize, ysize, font_nr);
2702 DrawTextBuffer(sx + font_width, sy + font_height,
2703 level.envelope[envelope_nr].text, font_nr, max_xsize,
2704 xsize - 2, ysize - 2, 0, mask_mode,
2705 level.envelope[envelope_nr].autowrap,
2706 level.envelope[envelope_nr].centered, FALSE);
2708 redraw_mask |= REDRAW_FIELD;
2711 SkipUntilDelayReached(&anim_delay, anim_delay_value, &i, last_frame);
2715 void ShowEnvelope(int envelope_nr)
2717 int element = EL_ENVELOPE_1 + envelope_nr;
2718 int graphic = IMG_BACKGROUND_ENVELOPE_1 + envelope_nr;
2719 int sound_opening = element_info[element].sound[ACTION_OPENING];
2720 int sound_closing = element_info[element].sound[ACTION_CLOSING];
2721 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2722 boolean no_delay = (tape.warp_forward);
2723 int normal_delay_value = ONE_SECOND_DELAY / (ffwd_delay ? 2 : 1);
2724 int wait_delay_value = (no_delay ? 0 : normal_delay_value);
2725 int anim_mode = graphic_info[graphic].anim_mode;
2726 int main_anim_mode = (anim_mode == ANIM_NONE ? ANIM_VERTICAL|ANIM_HORIZONTAL:
2727 anim_mode == ANIM_DEFAULT ? ANIM_VERTICAL : anim_mode);
2729 game.envelope_active = TRUE; /* needed for RedrawPlayfield() events */
2731 PlayMenuSoundStereo(sound_opening, SOUND_MIDDLE);
2733 if (anim_mode == ANIM_DEFAULT)
2734 AnimateEnvelope(envelope_nr, ANIM_DEFAULT, ACTION_OPENING);
2736 AnimateEnvelope(envelope_nr, main_anim_mode, ACTION_OPENING);
2739 Delay(wait_delay_value);
2741 WaitForEventToContinue();
2743 PlayMenuSoundStereo(sound_closing, SOUND_MIDDLE);
2745 if (anim_mode != ANIM_NONE)
2746 AnimateEnvelope(envelope_nr, main_anim_mode, ACTION_CLOSING);
2748 if (anim_mode == ANIM_DEFAULT)
2749 AnimateEnvelope(envelope_nr, ANIM_DEFAULT, ACTION_CLOSING);
2751 game.envelope_active = FALSE;
2753 SetDrawtoField(DRAW_TO_FIELDBUFFER);
2755 redraw_mask |= REDRAW_FIELD;
2759 static void setRequestBasePosition(int *x, int *y)
2761 int sx_base, sy_base;
2763 if (request.x != -1)
2764 sx_base = request.x;
2765 else if (request.align == ALIGN_LEFT)
2767 else if (request.align == ALIGN_RIGHT)
2768 sx_base = SX + SXSIZE;
2770 sx_base = SX + SXSIZE / 2;
2772 if (request.y != -1)
2773 sy_base = request.y;
2774 else if (request.valign == VALIGN_TOP)
2776 else if (request.valign == VALIGN_BOTTOM)
2777 sy_base = SY + SYSIZE;
2779 sy_base = SY + SYSIZE / 2;
2785 static void setRequestPositionExt(int *x, int *y, int width, int height,
2786 boolean add_border_size)
2788 int border_size = request.border_size;
2789 int sx_base, sy_base;
2792 setRequestBasePosition(&sx_base, &sy_base);
2794 if (request.align == ALIGN_LEFT)
2796 else if (request.align == ALIGN_RIGHT)
2797 sx = sx_base - width;
2799 sx = sx_base - width / 2;
2801 if (request.valign == VALIGN_TOP)
2803 else if (request.valign == VALIGN_BOTTOM)
2804 sy = sy_base - height;
2806 sy = sy_base - height / 2;
2808 sx = MAX(0, MIN(sx, WIN_XSIZE - width));
2809 sy = MAX(0, MIN(sy, WIN_YSIZE - height));
2811 if (add_border_size)
2821 static void setRequestPosition(int *x, int *y, boolean add_border_size)
2823 setRequestPositionExt(x, y, request.width, request.height, add_border_size);
2826 void DrawEnvelopeRequest(char *text)
2828 char *text_final = text;
2829 char *text_door_style = NULL;
2830 int graphic = IMG_BACKGROUND_REQUEST;
2831 Bitmap *src_bitmap = graphic_info[graphic].bitmap;
2832 int mask_mode = (src_bitmap != NULL ? BLIT_MASKED : BLIT_ON_BACKGROUND);
2833 int font_nr = FONT_REQUEST;
2834 int font_width = getFontWidth(font_nr);
2835 int font_height = getFontHeight(font_nr);
2836 int border_size = request.border_size;
2837 int line_spacing = request.line_spacing;
2838 int line_height = font_height + line_spacing;
2839 int max_text_width = request.width - 2 * border_size;
2840 int max_text_height = request.height - 2 * border_size;
2841 int line_length = max_text_width / font_width;
2842 int max_lines = max_text_height / line_height;
2843 int text_width = line_length * font_width;
2844 int width = request.width;
2845 int height = request.height;
2846 int tile_size = MAX(request.step_offset, 1);
2847 int x_steps = width / tile_size;
2848 int y_steps = height / tile_size;
2849 int sx_offset = border_size;
2850 int sy_offset = border_size;
2854 if (request.centered)
2855 sx_offset = (request.width - text_width) / 2;
2857 if (request.wrap_single_words && !request.autowrap)
2859 char *src_text_ptr, *dst_text_ptr;
2861 text_door_style = checked_malloc(2 * strlen(text) + 1);
2863 src_text_ptr = text;
2864 dst_text_ptr = text_door_style;
2866 while (*src_text_ptr)
2868 if (*src_text_ptr == ' ' ||
2869 *src_text_ptr == '?' ||
2870 *src_text_ptr == '!')
2871 *dst_text_ptr++ = '\n';
2873 if (*src_text_ptr != ' ')
2874 *dst_text_ptr++ = *src_text_ptr;
2879 *dst_text_ptr = '\0';
2881 text_final = text_door_style;
2884 setRequestPosition(&sx, &sy, FALSE);
2886 ClearRectangle(backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE);
2888 for (y = 0; y < y_steps; y++)
2889 for (x = 0; x < x_steps; x++)
2890 DrawEnvelopeBackgroundTiles(graphic, sx, sy,
2891 x, y, x_steps, y_steps,
2892 tile_size, tile_size);
2894 /* force DOOR font inside door area */
2895 SetFontStatus(GAME_MODE_PSEUDO_DOOR);
2897 DrawTextBuffer(sx + sx_offset, sy + sy_offset, text_final, font_nr,
2898 line_length, -1, max_lines, line_spacing, mask_mode,
2899 request.autowrap, request.centered, FALSE);
2903 for (i = 0; i < NUM_TOOL_BUTTONS; i++)
2904 RedrawGadget(tool_gadget[i]);
2906 // store readily prepared envelope request for later use when animating
2907 BlitBitmap(backbuffer, bitmap_db_store_2, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
2909 if (text_door_style)
2910 free(text_door_style);
2913 void AnimateEnvelopeRequest(int anim_mode, int action)
2915 int graphic = IMG_BACKGROUND_REQUEST;
2916 boolean draw_masked = graphic_info[graphic].draw_masked;
2917 int delay_value_normal = request.step_delay;
2918 int delay_value_fast = delay_value_normal / 2;
2919 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2920 boolean no_delay = (tape.warp_forward);
2921 int delay_value = (ffwd_delay ? delay_value_fast : delay_value_normal);
2922 int anim_delay_value = MAX(1, (no_delay ? 0 : delay_value + 500 * 0) / 2);
2923 unsigned int anim_delay = 0;
2925 int tile_size = MAX(request.step_offset, 1);
2926 int max_xsize = request.width / tile_size;
2927 int max_ysize = request.height / tile_size;
2928 int max_xsize_inner = max_xsize - 2;
2929 int max_ysize_inner = max_ysize - 2;
2931 int xstart = (anim_mode & ANIM_VERTICAL ? max_xsize_inner : 0);
2932 int ystart = (anim_mode & ANIM_HORIZONTAL ? max_ysize_inner : 0);
2933 int xend = max_xsize_inner;
2934 int yend = (anim_mode != ANIM_DEFAULT ? max_ysize_inner : 0);
2935 int xstep = (xstart < xend ? 1 : 0);
2936 int ystep = (ystart < yend || xstep == 0 ? 1 : 0);
2938 int end = MAX(xend - xstart, yend - ystart);
2941 if (setup.quick_doors)
2948 for (i = start; i <= end; i++)
2950 int last_frame = end; // last frame of this "for" loop
2951 int x = xstart + i * xstep;
2952 int y = ystart + i * ystep;
2953 int xsize = (action == ACTION_CLOSING ? xend - (x - xstart) : x) + 2;
2954 int ysize = (action == ACTION_CLOSING ? yend - (y - ystart) : y) + 2;
2955 int xsize_size_left = (xsize - 1) * tile_size;
2956 int ysize_size_top = (ysize - 1) * tile_size;
2957 int max_xsize_pos = (max_xsize - 1) * tile_size;
2958 int max_ysize_pos = (max_ysize - 1) * tile_size;
2959 int width = xsize * tile_size;
2960 int height = ysize * tile_size;
2965 setRequestPosition(&src_x, &src_y, FALSE);
2966 setRequestPositionExt(&dst_x, &dst_y, width, height, FALSE);
2968 BlitBitmap(bitmap_db_store_1, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
2970 for (yy = 0; yy < 2; yy++)
2972 for (xx = 0; xx < 2; xx++)
2974 int src_xx = src_x + xx * max_xsize_pos;
2975 int src_yy = src_y + yy * max_ysize_pos;
2976 int dst_xx = dst_x + xx * xsize_size_left;
2977 int dst_yy = dst_y + yy * ysize_size_top;
2978 int xx_size = (xx ? tile_size : xsize_size_left);
2979 int yy_size = (yy ? tile_size : ysize_size_top);
2982 BlitBitmapMasked(bitmap_db_store_2, backbuffer,
2983 src_xx, src_yy, xx_size, yy_size, dst_xx, dst_yy);
2985 BlitBitmap(bitmap_db_store_2, backbuffer,
2986 src_xx, src_yy, xx_size, yy_size, dst_xx, dst_yy);
2990 redraw_mask |= REDRAW_FIELD;
2994 SkipUntilDelayReached(&anim_delay, anim_delay_value, &i, last_frame);
2998 void ShowEnvelopeRequest(char *text, unsigned int req_state, int action)
3000 int graphic = IMG_BACKGROUND_REQUEST;
3001 int sound_opening = SND_REQUEST_OPENING;
3002 int sound_closing = SND_REQUEST_CLOSING;
3003 int anim_mode_1 = request.anim_mode; /* (higher priority) */
3004 int anim_mode_2 = graphic_info[graphic].anim_mode; /* (lower priority) */
3005 int anim_mode = (anim_mode_1 != ANIM_DEFAULT ? anim_mode_1 : anim_mode_2);
3006 int main_anim_mode = (anim_mode == ANIM_NONE ? ANIM_VERTICAL|ANIM_HORIZONTAL:
3007 anim_mode == ANIM_DEFAULT ? ANIM_VERTICAL : anim_mode);
3009 if (game_status == GAME_MODE_PLAYING)
3010 BlitScreenToBitmap(backbuffer);
3012 SetDrawtoField(DRAW_TO_BACKBUFFER);
3014 // SetDrawBackgroundMask(REDRAW_NONE);
3016 if (action == ACTION_OPENING)
3018 BlitBitmap(backbuffer, bitmap_db_store_1, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
3020 if (req_state & REQ_ASK)
3022 MapGadget(tool_gadget[TOOL_CTRL_ID_YES]);
3023 MapGadget(tool_gadget[TOOL_CTRL_ID_NO]);
3025 else if (req_state & REQ_CONFIRM)
3027 MapGadget(tool_gadget[TOOL_CTRL_ID_CONFIRM]);
3029 else if (req_state & REQ_PLAYER)
3031 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_1]);
3032 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_2]);
3033 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_3]);
3034 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_4]);
3037 DrawEnvelopeRequest(text);
3040 game.envelope_active = TRUE; /* needed for RedrawPlayfield() events */
3042 if (action == ACTION_OPENING)
3044 PlayMenuSoundStereo(sound_opening, SOUND_MIDDLE);
3046 if (anim_mode == ANIM_DEFAULT)
3047 AnimateEnvelopeRequest(ANIM_DEFAULT, ACTION_OPENING);
3049 AnimateEnvelopeRequest(main_anim_mode, ACTION_OPENING);
3053 PlayMenuSoundStereo(sound_closing, SOUND_MIDDLE);
3055 if (anim_mode != ANIM_NONE)
3056 AnimateEnvelopeRequest(main_anim_mode, ACTION_CLOSING);
3058 if (anim_mode == ANIM_DEFAULT)
3059 AnimateEnvelopeRequest(ANIM_DEFAULT, ACTION_CLOSING);
3062 game.envelope_active = FALSE;
3064 if (action == ACTION_CLOSING)
3065 BlitBitmap(bitmap_db_store_1, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
3067 // SetDrawBackgroundMask(last_draw_background_mask);
3069 redraw_mask |= REDRAW_FIELD;
3073 if (action == ACTION_CLOSING &&
3074 game_status == GAME_MODE_PLAYING &&
3075 level.game_engine_type == GAME_ENGINE_TYPE_RND)
3076 SetDrawtoField(DRAW_TO_FIELDBUFFER);
3079 void DrawPreviewElement(int dst_x, int dst_y, int element, int tilesize)
3081 if (IS_MM_WALL(element))
3083 DrawSizedWall_MM(dst_x, dst_y, element, tilesize, el2preimg);
3089 int graphic = el2preimg(element);
3091 getSizedGraphicSource(graphic, 0, tilesize, &src_bitmap, &src_x, &src_y);
3092 BlitBitmap(src_bitmap, drawto, src_x, src_y, tilesize, tilesize,
3097 void DrawLevel(int draw_background_mask)
3101 SetMainBackgroundImage(IMG_BACKGROUND_PLAYING);
3102 SetDrawBackgroundMask(draw_background_mask);
3106 for (x = BX1; x <= BX2; x++)
3107 for (y = BY1; y <= BY2; y++)
3108 DrawScreenField(x, y);
3110 redraw_mask |= REDRAW_FIELD;
3113 void DrawSizedLevel(int size_x, int size_y, int scroll_x, int scroll_y,
3118 for (x = 0; x < size_x; x++)
3119 for (y = 0; y < size_y; y++)
3120 DrawSizedElementOrWall(x, y, scroll_x, scroll_y, tilesize);
3122 redraw_mask |= REDRAW_FIELD;
3125 void DrawMiniLevel(int size_x, int size_y, int scroll_x, int scroll_y)
3129 for (x = 0; x < size_x; x++)
3130 for (y = 0; y < size_y; y++)
3131 DrawMiniElementOrWall(x, y, scroll_x, scroll_y);
3133 redraw_mask |= REDRAW_FIELD;
3136 static void DrawPreviewLevelPlayfield(int from_x, int from_y)
3138 boolean show_level_border = (BorderElement != EL_EMPTY);
3139 int level_xsize = lev_fieldx + (show_level_border ? 2 : 0);
3140 int level_ysize = lev_fieldy + (show_level_border ? 2 : 0);
3141 int tile_size = preview.tile_size;
3142 int preview_width = preview.xsize * tile_size;
3143 int preview_height = preview.ysize * tile_size;
3144 int real_preview_xsize = MIN(level_xsize, preview.xsize);
3145 int real_preview_ysize = MIN(level_ysize, preview.ysize);
3146 int real_preview_width = real_preview_xsize * tile_size;
3147 int real_preview_height = real_preview_ysize * tile_size;
3148 int dst_x = SX + ALIGNED_XPOS(preview.x, preview_width, preview.align);
3149 int dst_y = SY + ALIGNED_YPOS(preview.y, preview_height, preview.valign);
3152 if (!IN_GFX_FIELD_FULL(dst_x, dst_y + preview_height - 1))
3155 DrawBackground(dst_x, dst_y, preview_width, preview_height);
3157 dst_x += (preview_width - real_preview_width) / 2;
3158 dst_y += (preview_height - real_preview_height) / 2;
3160 for (x = 0; x < real_preview_xsize; x++)
3162 for (y = 0; y < real_preview_ysize; y++)
3164 int lx = from_x + x + (show_level_border ? -1 : 0);
3165 int ly = from_y + y + (show_level_border ? -1 : 0);
3166 int element = (IN_LEV_FIELD(lx, ly) ? level.field[lx][ly] :
3167 getBorderElement(lx, ly));
3169 DrawPreviewElement(dst_x + x * tile_size, dst_y + y * tile_size,
3170 element, tile_size);
3174 redraw_mask |= REDRAW_FIELD;
3177 #define MICROLABEL_EMPTY 0
3178 #define MICROLABEL_LEVEL_NAME 1
3179 #define MICROLABEL_LEVEL_AUTHOR_HEAD 2
3180 #define MICROLABEL_LEVEL_AUTHOR 3
3181 #define MICROLABEL_IMPORTED_FROM_HEAD 4
3182 #define MICROLABEL_IMPORTED_FROM 5
3183 #define MICROLABEL_IMPORTED_BY_HEAD 6
3184 #define MICROLABEL_IMPORTED_BY 7
3186 static int getMaxTextLength(struct TextPosInfo *pos, int font_nr)
3188 int max_text_width = SXSIZE;
3189 int font_width = getFontWidth(font_nr);
3191 if (pos->align == ALIGN_CENTER)
3192 max_text_width = (pos->x < SXSIZE / 2 ? pos->x * 2 : (SXSIZE - pos->x) * 2);
3193 else if (pos->align == ALIGN_RIGHT)
3194 max_text_width = pos->x;
3196 max_text_width = SXSIZE - pos->x;
3198 return max_text_width / font_width;
3201 static void DrawPreviewLevelLabelExt(int mode, struct TextPosInfo *pos)
3203 char label_text[MAX_OUTPUT_LINESIZE + 1];
3204 int max_len_label_text;
3205 int font_nr = pos->font;
3208 if (!IN_GFX_FIELD_FULL(pos->x, pos->y + getFontHeight(pos->font)))
3211 if (mode == MICROLABEL_LEVEL_AUTHOR_HEAD ||
3212 mode == MICROLABEL_IMPORTED_FROM_HEAD ||
3213 mode == MICROLABEL_IMPORTED_BY_HEAD)
3214 font_nr = pos->font_alt;
3216 max_len_label_text = getMaxTextLength(pos, font_nr);
3218 if (pos->size != -1)
3219 max_len_label_text = pos->size;
3221 for (i = 0; i < max_len_label_text; i++)
3222 label_text[i] = ' ';
3223 label_text[max_len_label_text] = '\0';
3225 if (strlen(label_text) > 0)
3226 DrawTextSAligned(pos->x, pos->y, label_text, font_nr, pos->align);
3229 (mode == MICROLABEL_LEVEL_NAME ? level.name :
3230 mode == MICROLABEL_LEVEL_AUTHOR_HEAD ? "created by" :
3231 mode == MICROLABEL_LEVEL_AUTHOR ? level.author :
3232 mode == MICROLABEL_IMPORTED_FROM_HEAD ? "imported from" :
3233 mode == MICROLABEL_IMPORTED_FROM ? leveldir_current->imported_from :
3234 mode == MICROLABEL_IMPORTED_BY_HEAD ? "imported by" :
3235 mode == MICROLABEL_IMPORTED_BY ? leveldir_current->imported_by :""),
3236 max_len_label_text);
3237 label_text[max_len_label_text] = '\0';
3239 if (strlen(label_text) > 0)
3240 DrawTextSAligned(pos->x, pos->y, label_text, font_nr, pos->align);
3242 redraw_mask |= REDRAW_FIELD;
3245 static void DrawPreviewLevelLabel(int mode)
3247 DrawPreviewLevelLabelExt(mode, &menu.main.text.level_info_2);
3250 static void DrawPreviewLevelInfo(int mode)
3252 if (mode == MICROLABEL_LEVEL_NAME)
3253 DrawPreviewLevelLabelExt(mode, &menu.main.text.level_name);
3254 else if (mode == MICROLABEL_LEVEL_AUTHOR)
3255 DrawPreviewLevelLabelExt(mode, &menu.main.text.level_author);
3258 static void DrawPreviewLevelExt(boolean restart)
3260 static unsigned int scroll_delay = 0;
3261 static unsigned int label_delay = 0;
3262 static int from_x, from_y, scroll_direction;
3263 static int label_state, label_counter;
3264 unsigned int scroll_delay_value = preview.step_delay;
3265 boolean show_level_border = (BorderElement != EL_EMPTY);
3266 int level_xsize = lev_fieldx + (show_level_border ? 2 : 0);
3267 int level_ysize = lev_fieldy + (show_level_border ? 2 : 0);
3274 if (preview.anim_mode == ANIM_CENTERED)
3276 if (level_xsize > preview.xsize)
3277 from_x = (level_xsize - preview.xsize) / 2;
3278 if (level_ysize > preview.ysize)
3279 from_y = (level_ysize - preview.ysize) / 2;
3282 from_x += preview.xoffset;
3283 from_y += preview.yoffset;
3285 scroll_direction = MV_RIGHT;
3289 DrawPreviewLevelPlayfield(from_x, from_y);
3290 DrawPreviewLevelLabel(label_state);
3292 DrawPreviewLevelInfo(MICROLABEL_LEVEL_NAME);
3293 DrawPreviewLevelInfo(MICROLABEL_LEVEL_AUTHOR);
3295 /* initialize delay counters */
3296 DelayReached(&scroll_delay, 0);
3297 DelayReached(&label_delay, 0);
3299 if (leveldir_current->name)
3301 struct TextPosInfo *pos = &menu.main.text.level_info_1;
3302 char label_text[MAX_OUTPUT_LINESIZE + 1];
3303 int font_nr = pos->font;
3304 int max_len_label_text = getMaxTextLength(pos, font_nr);
3306 if (pos->size != -1)
3307 max_len_label_text = pos->size;
3309 strncpy(label_text, leveldir_current->name, max_len_label_text);
3310 label_text[max_len_label_text] = '\0';
3312 if (IN_GFX_FIELD_FULL(pos->x, pos->y + getFontHeight(pos->font)))
3313 DrawTextSAligned(pos->x, pos->y, label_text, font_nr, pos->align);
3319 /* scroll preview level, if needed */
3320 if (preview.anim_mode != ANIM_NONE &&
3321 (level_xsize > preview.xsize || level_ysize > preview.ysize) &&
3322 DelayReached(&scroll_delay, scroll_delay_value))
3324 switch (scroll_direction)
3329 from_x -= preview.step_offset;
3330 from_x = (from_x < 0 ? 0 : from_x);
3333 scroll_direction = MV_UP;
3337 if (from_x < level_xsize - preview.xsize)
3339 from_x += preview.step_offset;
3340 from_x = (from_x > level_xsize - preview.xsize ?
3341 level_xsize - preview.xsize : from_x);
3344 scroll_direction = MV_DOWN;
3350 from_y -= preview.step_offset;
3351 from_y = (from_y < 0 ? 0 : from_y);
3354 scroll_direction = MV_RIGHT;
3358 if (from_y < level_ysize - preview.ysize)
3360 from_y += preview.step_offset;
3361 from_y = (from_y > level_ysize - preview.ysize ?
3362 level_ysize - preview.ysize : from_y);
3365 scroll_direction = MV_LEFT;
3372 DrawPreviewLevelPlayfield(from_x, from_y);
3375 /* !!! THIS ALL SUCKS -- SHOULD BE CLEANLY REWRITTEN !!! */
3376 /* redraw micro level label, if needed */
3377 if (!strEqual(level.name, NAMELESS_LEVEL_NAME) &&
3378 !strEqual(level.author, ANONYMOUS_NAME) &&
3379 !strEqual(level.author, leveldir_current->name) &&
3380 DelayReached(&label_delay, MICROLEVEL_LABEL_DELAY))
3382 int max_label_counter = 23;
3384 if (leveldir_current->imported_from != NULL &&
3385 strlen(leveldir_current->imported_from) > 0)
3386 max_label_counter += 14;
3387 if (leveldir_current->imported_by != NULL &&
3388 strlen(leveldir_current->imported_by) > 0)
3389 max_label_counter += 14;
3391 label_counter = (label_counter + 1) % max_label_counter;
3392 label_state = (label_counter >= 0 && label_counter <= 7 ?
3393 MICROLABEL_LEVEL_NAME :
3394 label_counter >= 9 && label_counter <= 12 ?
3395 MICROLABEL_LEVEL_AUTHOR_HEAD :
3396 label_counter >= 14 && label_counter <= 21 ?
3397 MICROLABEL_LEVEL_AUTHOR :
3398 label_counter >= 23 && label_counter <= 26 ?
3399 MICROLABEL_IMPORTED_FROM_HEAD :
3400 label_counter >= 28 && label_counter <= 35 ?
3401 MICROLABEL_IMPORTED_FROM :
3402 label_counter >= 37 && label_counter <= 40 ?
3403 MICROLABEL_IMPORTED_BY_HEAD :
3404 label_counter >= 42 && label_counter <= 49 ?
3405 MICROLABEL_IMPORTED_BY : MICROLABEL_EMPTY);
3407 if (leveldir_current->imported_from == NULL &&
3408 (label_state == MICROLABEL_IMPORTED_FROM_HEAD ||
3409 label_state == MICROLABEL_IMPORTED_FROM))
3410 label_state = (label_state == MICROLABEL_IMPORTED_FROM_HEAD ?
3411 MICROLABEL_IMPORTED_BY_HEAD : MICROLABEL_IMPORTED_BY);
3413 DrawPreviewLevelLabel(label_state);
3417 void DrawPreviewLevelInitial()
3419 DrawPreviewLevelExt(TRUE);
3422 void DrawPreviewLevelAnimation()
3424 DrawPreviewLevelExt(FALSE);
3427 inline static void DrawGraphicAnimationExt(DrawBuffer *dst_bitmap, int x, int y,
3428 int graphic, int sync_frame,
3431 int frame = getGraphicAnimationFrame(graphic, sync_frame);
3433 if (mask_mode == USE_MASKING)
3434 DrawGraphicThruMaskExt(dst_bitmap, x, y, graphic, frame);
3436 DrawGraphicExt(dst_bitmap, x, y, graphic, frame);
3439 void DrawFixedGraphicAnimationExt(DrawBuffer *dst_bitmap, int x, int y,
3440 int graphic, int sync_frame, int mask_mode)
3442 int frame = getGraphicAnimationFrame(graphic, sync_frame);
3444 if (mask_mode == USE_MASKING)
3445 DrawFixedGraphicThruMaskExt(dst_bitmap, x, y, graphic, frame);
3447 DrawFixedGraphicExt(dst_bitmap, x, y, graphic, frame);
3450 inline static void DrawGraphicAnimation(int x, int y, int graphic)
3452 int lx = LEVELX(x), ly = LEVELY(y);
3454 if (!IN_SCR_FIELD(x, y))
3457 DrawGraphicAnimationExt(drawto_field, FX + x * TILEX_VAR, FY + y * TILEY_VAR,
3458 graphic, GfxFrame[lx][ly], NO_MASKING);
3460 MarkTileDirty(x, y);
3463 void DrawFixedGraphicAnimation(int x, int y, int graphic)
3465 int lx = LEVELX(x), ly = LEVELY(y);
3467 if (!IN_SCR_FIELD(x, y))
3470 DrawGraphicAnimationExt(drawto_field, FX + x * TILEX, FY + y * TILEY,
3471 graphic, GfxFrame[lx][ly], NO_MASKING);
3472 MarkTileDirty(x, y);
3475 void DrawLevelGraphicAnimation(int x, int y, int graphic)
3477 DrawGraphicAnimation(SCREENX(x), SCREENY(y), graphic);
3480 void DrawLevelElementAnimation(int x, int y, int element)
3482 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
3484 DrawGraphicAnimation(SCREENX(x), SCREENY(y), graphic);
3487 void DrawLevelGraphicAnimationIfNeeded(int x, int y, int graphic)
3489 int sx = SCREENX(x), sy = SCREENY(y);
3491 if (!IN_LEV_FIELD(x, y) || !IN_SCR_FIELD(sx, sy))
3494 if (!IS_NEW_FRAME(GfxFrame[x][y], graphic))
3497 DrawGraphicAnimation(sx, sy, graphic);
3500 if (GFX_CRUMBLED(TILE_GFX_ELEMENT(x, y)))
3501 DrawLevelFieldCrumbled(x, y);
3503 if (GFX_CRUMBLED(Feld[x][y]))
3504 DrawLevelFieldCrumbled(x, y);
3508 void DrawLevelElementAnimationIfNeeded(int x, int y, int element)
3510 int sx = SCREENX(x), sy = SCREENY(y);
3513 if (!IN_LEV_FIELD(x, y) || !IN_SCR_FIELD(sx, sy))
3516 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
3518 if (!IS_NEW_FRAME(GfxFrame[x][y], graphic))
3521 DrawGraphicAnimation(sx, sy, graphic);
3523 if (GFX_CRUMBLED(element))
3524 DrawLevelFieldCrumbled(x, y);
3527 static int getPlayerGraphic(struct PlayerInfo *player, int move_dir)
3529 if (player->use_murphy)
3531 /* this works only because currently only one player can be "murphy" ... */
3532 static int last_horizontal_dir = MV_LEFT;
3533 int graphic = el_act_dir2img(EL_SP_MURPHY, player->GfxAction, move_dir);
3535 if (move_dir == MV_LEFT || move_dir == MV_RIGHT)
3536 last_horizontal_dir = move_dir;
3538 if (graphic == IMG_SP_MURPHY) /* undefined => use special graphic */
3540 int direction = (player->is_snapping ? move_dir : last_horizontal_dir);
3542 graphic = el_act_dir2img(EL_SP_MURPHY, player->GfxAction, direction);
3548 return el_act_dir2img(player->artwork_element, player->GfxAction,move_dir);
3551 static boolean equalGraphics(int graphic1, int graphic2)
3553 struct GraphicInfo *g1 = &graphic_info[graphic1];
3554 struct GraphicInfo *g2 = &graphic_info[graphic2];
3556 return (g1->bitmap == g2->bitmap &&
3557 g1->src_x == g2->src_x &&
3558 g1->src_y == g2->src_y &&
3559 g1->anim_frames == g2->anim_frames &&
3560 g1->anim_delay == g2->anim_delay &&
3561 g1->anim_mode == g2->anim_mode);
3564 void DrawAllPlayers()
3568 for (i = 0; i < MAX_PLAYERS; i++)
3569 if (stored_player[i].active)
3570 DrawPlayer(&stored_player[i]);
3573 void DrawPlayerField(int x, int y)
3575 if (!IS_PLAYER(x, y))
3578 DrawPlayer(PLAYERINFO(x, y));
3581 #define DRAW_PLAYER_OVER_PUSHED_ELEMENT 1
3583 void DrawPlayer(struct PlayerInfo *player)
3585 int jx = player->jx;
3586 int jy = player->jy;
3587 int move_dir = player->MovDir;
3588 int dx = (move_dir == MV_LEFT ? -1 : move_dir == MV_RIGHT ? +1 : 0);
3589 int dy = (move_dir == MV_UP ? -1 : move_dir == MV_DOWN ? +1 : 0);
3590 int last_jx = (player->is_moving ? jx - dx : jx);
3591 int last_jy = (player->is_moving ? jy - dy : jy);
3592 int next_jx = jx + dx;
3593 int next_jy = jy + dy;
3594 boolean player_is_moving = (player->MovPos ? TRUE : FALSE);
3595 boolean player_is_opaque = FALSE;
3596 int sx = SCREENX(jx), sy = SCREENY(jy);
3597 int sxx = 0, syy = 0;
3598 int element = Feld[jx][jy], last_element = Feld[last_jx][last_jy];
3600 int action = ACTION_DEFAULT;
3601 int last_player_graphic = getPlayerGraphic(player, move_dir);
3602 int last_player_frame = player->Frame;
3605 /* GfxElement[][] is set to the element the player is digging or collecting;
3606 remove also for off-screen player if the player is not moving anymore */
3607 if (IN_LEV_FIELD(jx, jy) && !player_is_moving)
3608 GfxElement[jx][jy] = EL_UNDEFINED;
3610 if (!player->active || !IN_SCR_FIELD(SCREENX(last_jx), SCREENY(last_jy)))
3614 if (!IN_LEV_FIELD(jx, jy))
3616 printf("DrawPlayerField(): x = %d, y = %d\n",jx,jy);
3617 printf("DrawPlayerField(): sx = %d, sy = %d\n",sx,sy);
3618 printf("DrawPlayerField(): This should never happen!\n");
3623 if (element == EL_EXPLOSION)
3626 action = (player->is_pushing ? ACTION_PUSHING :
3627 player->is_digging ? ACTION_DIGGING :
3628 player->is_collecting ? ACTION_COLLECTING :
3629 player->is_moving ? ACTION_MOVING :
3630 player->is_snapping ? ACTION_SNAPPING :
3631 player->is_dropping ? ACTION_DROPPING :
3632 player->is_waiting ? player->action_waiting : ACTION_DEFAULT);
3634 if (player->is_waiting)
3635 move_dir = player->dir_waiting;
3637 InitPlayerGfxAnimation(player, action, move_dir);
3639 /* ----------------------------------------------------------------------- */
3640 /* draw things in the field the player is leaving, if needed */
3641 /* ----------------------------------------------------------------------- */
3643 if (player->is_moving)
3645 if (Back[last_jx][last_jy] && IS_DRAWABLE(last_element))
3647 DrawLevelElement(last_jx, last_jy, Back[last_jx][last_jy]);
3649 if (last_element == EL_DYNAMITE_ACTIVE ||
3650 last_element == EL_EM_DYNAMITE_ACTIVE ||
3651 last_element == EL_SP_DISK_RED_ACTIVE)
3652 DrawDynamite(last_jx, last_jy);
3654 DrawLevelFieldThruMask(last_jx, last_jy);
3656 else if (last_element == EL_DYNAMITE_ACTIVE ||
3657 last_element == EL_EM_DYNAMITE_ACTIVE ||
3658 last_element == EL_SP_DISK_RED_ACTIVE)
3659 DrawDynamite(last_jx, last_jy);
3661 /* !!! this is not enough to prevent flickering of players which are
3662 moving next to each others without a free tile between them -- this
3663 can only be solved by drawing all players layer by layer (first the
3664 background, then the foreground etc.) !!! => TODO */
3665 else if (!IS_PLAYER(last_jx, last_jy))
3666 DrawLevelField(last_jx, last_jy);
3669 DrawLevelField(last_jx, last_jy);
3672 if (player->is_pushing && IN_SCR_FIELD(SCREENX(next_jx), SCREENY(next_jy)))
3673 DrawLevelElement(next_jx, next_jy, EL_EMPTY);
3676 if (!IN_SCR_FIELD(sx, sy))
3679 /* ----------------------------------------------------------------------- */
3680 /* draw things behind the player, if needed */
3681 /* ----------------------------------------------------------------------- */
3684 DrawLevelElement(jx, jy, Back[jx][jy]);
3685 else if (IS_ACTIVE_BOMB(element))
3686 DrawLevelElement(jx, jy, EL_EMPTY);
3689 if (player_is_moving && GfxElement[jx][jy] != EL_UNDEFINED)
3691 int old_element = GfxElement[jx][jy];
3692 int old_graphic = el_act_dir2img(old_element, action, move_dir);
3693 int frame = getGraphicAnimationFrame(old_graphic, player->StepFrame);
3695 if (GFX_CRUMBLED(old_element))
3696 DrawLevelFieldCrumbledDigging(jx, jy, move_dir, player->StepFrame);
3698 DrawGraphic(sx, sy, old_graphic, frame);
3700 if (graphic_info[old_graphic].anim_mode & ANIM_OPAQUE_PLAYER)
3701 player_is_opaque = TRUE;
3705 GfxElement[jx][jy] = EL_UNDEFINED;
3707 /* make sure that pushed elements are drawn with correct frame rate */
3708 graphic = el_act_dir2img(element, ACTION_PUSHING, move_dir);
3710 if (player->is_pushing && player->is_moving && !IS_ANIM_MODE_CE(graphic))
3711 GfxFrame[jx][jy] = player->StepFrame;
3713 DrawLevelField(jx, jy);
3717 #if !DRAW_PLAYER_OVER_PUSHED_ELEMENT
3718 /* ----------------------------------------------------------------------- */
3719 /* draw player himself */
3720 /* ----------------------------------------------------------------------- */
3722 graphic = getPlayerGraphic(player, move_dir);
3724 /* in the case of changed player action or direction, prevent the current
3725 animation frame from being restarted for identical animations */
3726 if (player->Frame == 0 && equalGraphics(graphic, last_player_graphic))
3727 player->Frame = last_player_frame;
3729 frame = getGraphicAnimationFrame(graphic, player->Frame);
3733 if (move_dir == MV_LEFT || move_dir == MV_RIGHT)
3734 sxx = player->GfxPos;
3736 syy = player->GfxPos;
3739 if (player_is_opaque)
3740 DrawGraphicShifted(sx, sy, sxx, syy, graphic, frame,NO_CUTTING,NO_MASKING);
3742 DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic, frame, NO_CUTTING);
3744 if (SHIELD_ON(player))
3746 int graphic = (player->shield_deadly_time_left ? IMG_SHIELD_DEADLY_ACTIVE :
3747 IMG_SHIELD_NORMAL_ACTIVE);
3748 int frame = getGraphicAnimationFrame(graphic, -1);
3750 DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic, frame, NO_CUTTING);
3754 #if DRAW_PLAYER_OVER_PUSHED_ELEMENT
3757 if (move_dir == MV_LEFT || move_dir == MV_RIGHT)
3758 sxx = player->GfxPos;
3760 syy = player->GfxPos;
3764 /* ----------------------------------------------------------------------- */
3765 /* draw things the player is pushing, if needed */
3766 /* ----------------------------------------------------------------------- */
3768 if (player->is_pushing && player->is_moving)
3770 int px = SCREENX(jx), py = SCREENY(jy);
3771 int pxx = (TILEX - ABS(sxx)) * dx;
3772 int pyy = (TILEY - ABS(syy)) * dy;
3773 int gfx_frame = GfxFrame[jx][jy];
3779 if (!IS_MOVING(jx, jy)) /* push movement already finished */
3781 element = Feld[next_jx][next_jy];
3782 gfx_frame = GfxFrame[next_jx][next_jy];
3785 graphic = el_act_dir2img(element, ACTION_PUSHING, move_dir);
3787 sync_frame = (IS_ANIM_MODE_CE(graphic) ? gfx_frame : player->StepFrame);
3788 frame = getGraphicAnimationFrame(graphic, sync_frame);
3790 /* draw background element under pushed element (like the Sokoban field) */
3791 if (game.use_masked_pushing && IS_MOVING(jx, jy))
3793 /* this allows transparent pushing animation over non-black background */
3796 DrawLevelElement(jx, jy, Back[jx][jy]);
3798 DrawLevelElement(jx, jy, EL_EMPTY);
3800 if (Back[next_jx][next_jy])
3801 DrawLevelElement(next_jx, next_jy, Back[next_jx][next_jy]);
3803 DrawLevelElement(next_jx, next_jy, EL_EMPTY);
3805 else if (Back[next_jx][next_jy])
3806 DrawLevelElement(next_jx, next_jy, Back[next_jx][next_jy]);
3809 /* do not draw (EM style) pushing animation when pushing is finished */
3810 /* (two-tile animations usually do not contain start and end frame) */
3811 if (graphic_info[graphic].double_movement && !IS_MOVING(jx, jy))
3812 DrawLevelElement(next_jx, next_jy, Feld[next_jx][next_jy]);
3814 DrawGraphicShiftedThruMask(px, py, pxx, pyy, graphic, frame, NO_CUTTING);
3816 /* masked drawing is needed for EMC style (double) movement graphics */
3817 /* !!! (ONLY WHEN DRAWING PUSHED ELEMENT OVER THE PLAYER) !!! */
3818 DrawGraphicShiftedThruMask(px, py, pxx, pyy, graphic, frame, NO_CUTTING);
3822 #if DRAW_PLAYER_OVER_PUSHED_ELEMENT
3823 /* ----------------------------------------------------------------------- */
3824 /* draw player himself */
3825 /* ----------------------------------------------------------------------- */
3827 graphic = getPlayerGraphic(player, move_dir);
3829 /* in the case of changed player action or direction, prevent the current
3830 animation frame from being restarted for identical animations */
3831 if (player->Frame == 0 && equalGraphics(graphic, last_player_graphic))
3832 player->Frame = last_player_frame;
3834 frame = getGraphicAnimationFrame(graphic, player->Frame);
3838 if (move_dir == MV_LEFT || move_dir == MV_RIGHT)
3839 sxx = player->GfxPos;
3841 syy = player->GfxPos;
3844 if (player_is_opaque)
3845 DrawGraphicShifted(sx, sy, sxx, syy, graphic, frame,NO_CUTTING,NO_MASKING);
3847 DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic, frame, NO_CUTTING);
3849 if (SHIELD_ON(player))
3851 int graphic = (player->shield_deadly_time_left ? IMG_SHIELD_DEADLY_ACTIVE :
3852 IMG_SHIELD_NORMAL_ACTIVE);
3853 int frame = getGraphicAnimationFrame(graphic, -1);
3855 DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic, frame, NO_CUTTING);
3859 /* ----------------------------------------------------------------------- */
3860 /* draw things in front of player (active dynamite or dynabombs) */
3861 /* ----------------------------------------------------------------------- */
3863 if (IS_ACTIVE_BOMB(element))
3865 graphic = el2img(element);
3866 frame = getGraphicAnimationFrame(graphic, GfxFrame[jx][jy]);
3868 if (game.emulation == EMU_SUPAPLEX)
3869 DrawGraphic(sx, sy, IMG_SP_DISK_RED, frame);
3871 DrawGraphicThruMask(sx, sy, graphic, frame);
3874 if (player_is_moving && last_element == EL_EXPLOSION)
3876 int element = (GfxElement[last_jx][last_jy] != EL_UNDEFINED ?
3877 GfxElement[last_jx][last_jy] : EL_EMPTY);
3878 int graphic = el_act2img(element, ACTION_EXPLODING);
3879 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
3880 int phase = ExplodePhase[last_jx][last_jy] - 1;
3881 int frame = getGraphicAnimationFrame(graphic, phase - delay);
3884 DrawGraphicThruMask(SCREENX(last_jx), SCREENY(last_jy), graphic, frame);
3887 /* ----------------------------------------------------------------------- */
3888 /* draw elements the player is just walking/passing through/under */
3889 /* ----------------------------------------------------------------------- */
3891 if (player_is_moving)
3893 /* handle the field the player is leaving ... */
3894 if (IS_ACCESSIBLE_INSIDE(last_element))
3895 DrawLevelField(last_jx, last_jy);
3896 else if (IS_ACCESSIBLE_UNDER(last_element))
3897 DrawLevelFieldThruMask(last_jx, last_jy);
3900 /* do not redraw accessible elements if the player is just pushing them */
3901 if (!player_is_moving || !player->is_pushing)
3903 /* ... and the field the player is entering */
3904 if (IS_ACCESSIBLE_INSIDE(element))
3905 DrawLevelField(jx, jy);
3906 else if (IS_ACCESSIBLE_UNDER(element))
3907 DrawLevelFieldThruMask(jx, jy);
3910 MarkTileDirty(sx, sy);
3913 /* ------------------------------------------------------------------------- */
3915 void WaitForEventToContinue()
3917 boolean still_wait = TRUE;
3919 if (program.headless)
3922 /* simulate releasing mouse button over last gadget, if still pressed */
3924 HandleGadgets(-1, -1, 0);
3926 button_status = MB_RELEASED;
3934 if (NextValidEvent(&event))
3938 case EVENT_BUTTONPRESS:
3939 case EVENT_KEYPRESS:
3940 #if defined(TARGET_SDL2)
3941 case SDL_CONTROLLERBUTTONDOWN:
3943 case SDL_JOYBUTTONDOWN:
3947 case EVENT_KEYRELEASE:
3948 ClearPlayerAction();
3952 HandleOtherEvents(&event);
3956 else if (AnyJoystickButton() == JOY_BUTTON_NEW_PRESSED)
3965 #define MAX_REQUEST_LINES 13
3966 #define MAX_REQUEST_LINE_FONT1_LEN 7
3967 #define MAX_REQUEST_LINE_FONT2_LEN 10
3969 static int RequestHandleEvents(unsigned int req_state)