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)
2491 int element_base = map_mm_wall_element(element);
2492 int element_bits = (IS_DF_WALL(element) ?
2493 element - EL_DF_WALL_START :
2494 element - EL_MM_WALL_START) & 0x000f;
2495 int graphic = el2img_function(element_base);
2496 int tilesize_draw = tilesize / 2;
2501 getSizedGraphicSource(graphic, 0, tilesize_draw, &src_bitmap, &src_x, &src_y);
2503 for (i = 0; i < 4; i++)
2505 int dst_draw_x = dst_x + (i % 2) * tilesize_draw;
2506 int dst_draw_y = dst_y + (i / 2) * tilesize_draw;
2508 if (element_bits & (1 << i))
2511 BlitBitmapMasked(src_bitmap, drawto, src_x, src_y,
2512 tilesize_draw, tilesize_draw, dst_draw_x, dst_draw_y);
2514 BlitBitmap(src_bitmap, drawto, src_x, src_y,
2515 tilesize_draw, tilesize_draw, dst_draw_x, dst_draw_y);
2520 ClearRectangle(drawto, dst_draw_x, dst_draw_y,
2521 tilesize_draw, tilesize_draw);
2526 void DrawSizedWall_MM(int dst_x, int dst_y, int element, int tilesize,
2527 int (*el2img_function)(int))
2529 DrawSizedWallExt_MM(dst_x, dst_y, element, tilesize, el2img_function, FALSE);
2532 void DrawSizedElementExt(int x, int y, int element, int tilesize,
2535 if (IS_MM_WALL(element))
2537 DrawSizedWallExt_MM(SX + x * tilesize, SY + y * tilesize,
2538 element, tilesize, el2edimg, masked);
2542 int graphic = el2edimg(element);
2545 DrawSizedGraphicThruMask(x, y, graphic, 0, tilesize);
2547 DrawSizedGraphic(x, y, graphic, 0, tilesize);
2551 void DrawSizedElement(int x, int y, int element, int tilesize)
2553 DrawSizedElementExt(x, y, element, tilesize, FALSE);
2556 void DrawSizedElementThruMask(int x, int y, int element, int tilesize)
2558 DrawSizedElementExt(x, y, element, tilesize, TRUE);
2561 void DrawMiniElement(int x, int y, int element)
2565 graphic = el2edimg(element);
2566 DrawMiniGraphic(x, y, graphic);
2569 void DrawSizedElementOrWall(int sx, int sy, int scroll_x, int scroll_y,
2572 int x = sx + scroll_x, y = sy + scroll_y;
2574 if (x < -1 || x > lev_fieldx || y < -1 || y > lev_fieldy)
2575 DrawSizedElement(sx, sy, EL_EMPTY, tilesize);
2576 else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy)
2577 DrawSizedElement(sx, sy, Feld[x][y], tilesize);
2579 DrawSizedGraphic(sx, sy, el2edimg(getBorderElement(x, y)), 0, tilesize);
2582 void DrawMiniElementOrWall(int sx, int sy, int scroll_x, int scroll_y)
2584 int x = sx + scroll_x, y = sy + scroll_y;
2586 if (x < -1 || x > lev_fieldx || y < -1 || y > lev_fieldy)
2587 DrawMiniElement(sx, sy, EL_EMPTY);
2588 else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy)
2589 DrawMiniElement(sx, sy, Feld[x][y]);
2591 DrawMiniGraphic(sx, sy, el2edimg(getBorderElement(x, y)));
2594 void DrawEnvelopeBackgroundTiles(int graphic, int startx, int starty,
2595 int x, int y, int xsize, int ysize,
2596 int tile_width, int tile_height)
2600 int dst_x = startx + x * tile_width;
2601 int dst_y = starty + y * tile_height;
2602 int width = graphic_info[graphic].width;
2603 int height = graphic_info[graphic].height;
2604 int inner_width_raw = MAX(width - 2 * tile_width, tile_width);
2605 int inner_height_raw = MAX(height - 2 * tile_height, tile_height);
2606 int inner_width = inner_width_raw - (inner_width_raw % tile_width);
2607 int inner_height = inner_height_raw - (inner_height_raw % tile_height);
2608 int inner_sx = (width >= 3 * tile_width ? tile_width : 0);
2609 int inner_sy = (height >= 3 * tile_height ? tile_height : 0);
2610 boolean draw_masked = graphic_info[graphic].draw_masked;
2612 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
2614 if (src_bitmap == NULL || width < tile_width || height < tile_height)
2616 ClearRectangle(drawto, dst_x, dst_y, tile_width, tile_height);
2620 src_x += (x == 0 ? 0 : x == xsize - 1 ? width - tile_width :
2621 inner_sx + (x - 1) * tile_width % inner_width);
2622 src_y += (y == 0 ? 0 : y == ysize - 1 ? height - tile_height :
2623 inner_sy + (y - 1) * tile_height % inner_height);
2626 BlitBitmapMasked(src_bitmap, drawto, src_x, src_y, tile_width, tile_height,
2629 BlitBitmap(src_bitmap, drawto, src_x, src_y, tile_width, tile_height,
2633 void DrawEnvelopeBackground(int graphic, int startx, int starty,
2634 int x, int y, int xsize, int ysize, int font_nr)
2636 int font_width = getFontWidth(font_nr);
2637 int font_height = getFontHeight(font_nr);
2639 DrawEnvelopeBackgroundTiles(graphic, startx, starty, x, y, xsize, ysize,
2640 font_width, font_height);
2643 void AnimateEnvelope(int envelope_nr, int anim_mode, int action)
2645 int graphic = IMG_BACKGROUND_ENVELOPE_1 + envelope_nr;
2646 Bitmap *src_bitmap = graphic_info[graphic].bitmap;
2647 int mask_mode = (src_bitmap != NULL ? BLIT_MASKED : BLIT_ON_BACKGROUND);
2648 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2649 boolean no_delay = (tape.warp_forward);
2650 unsigned int anim_delay = 0;
2651 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2652 int anim_delay_value = MAX(1, (no_delay ? 0 : frame_delay_value) / 2);
2653 int font_nr = FONT_ENVELOPE_1 + envelope_nr;
2654 int font_width = getFontWidth(font_nr);
2655 int font_height = getFontHeight(font_nr);
2656 int max_xsize = level.envelope[envelope_nr].xsize;
2657 int max_ysize = level.envelope[envelope_nr].ysize;
2658 int xstart = (anim_mode & ANIM_VERTICAL ? max_xsize : 0);
2659 int ystart = (anim_mode & ANIM_HORIZONTAL ? max_ysize : 0);
2660 int xend = max_xsize;
2661 int yend = (anim_mode != ANIM_DEFAULT ? max_ysize : 0);
2662 int xstep = (xstart < xend ? 1 : 0);
2663 int ystep = (ystart < yend || xstep == 0 ? 1 : 0);
2665 int end = MAX(xend - xstart, yend - ystart);
2668 for (i = start; i <= end; i++)
2670 int last_frame = end; // last frame of this "for" loop
2671 int x = xstart + i * xstep;
2672 int y = ystart + i * ystep;
2673 int xsize = (action == ACTION_CLOSING ? xend - (x - xstart) : x) + 2;
2674 int ysize = (action == ACTION_CLOSING ? yend - (y - ystart) : y) + 2;
2675 int sx = SX + (SXSIZE - xsize * font_width) / 2;
2676 int sy = SY + (SYSIZE - ysize * font_height) / 2;
2679 SetDrawtoField(DRAW_TO_FIELDBUFFER);
2681 BlitScreenToBitmap(backbuffer);
2683 SetDrawtoField(DRAW_TO_BACKBUFFER);
2685 for (yy = 0; yy < ysize; yy++)
2686 for (xx = 0; xx < xsize; xx++)
2687 DrawEnvelopeBackground(graphic, sx, sy, xx, yy, xsize, ysize, font_nr);
2689 DrawTextBuffer(sx + font_width, sy + font_height,
2690 level.envelope[envelope_nr].text, font_nr, max_xsize,
2691 xsize - 2, ysize - 2, 0, mask_mode,
2692 level.envelope[envelope_nr].autowrap,
2693 level.envelope[envelope_nr].centered, FALSE);
2695 redraw_mask |= REDRAW_FIELD;
2698 SkipUntilDelayReached(&anim_delay, anim_delay_value, &i, last_frame);
2702 void ShowEnvelope(int envelope_nr)
2704 int element = EL_ENVELOPE_1 + envelope_nr;
2705 int graphic = IMG_BACKGROUND_ENVELOPE_1 + envelope_nr;
2706 int sound_opening = element_info[element].sound[ACTION_OPENING];
2707 int sound_closing = element_info[element].sound[ACTION_CLOSING];
2708 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2709 boolean no_delay = (tape.warp_forward);
2710 int normal_delay_value = ONE_SECOND_DELAY / (ffwd_delay ? 2 : 1);
2711 int wait_delay_value = (no_delay ? 0 : normal_delay_value);
2712 int anim_mode = graphic_info[graphic].anim_mode;
2713 int main_anim_mode = (anim_mode == ANIM_NONE ? ANIM_VERTICAL|ANIM_HORIZONTAL:
2714 anim_mode == ANIM_DEFAULT ? ANIM_VERTICAL : anim_mode);
2716 game.envelope_active = TRUE; /* needed for RedrawPlayfield() events */
2718 PlayMenuSoundStereo(sound_opening, SOUND_MIDDLE);
2720 if (anim_mode == ANIM_DEFAULT)
2721 AnimateEnvelope(envelope_nr, ANIM_DEFAULT, ACTION_OPENING);
2723 AnimateEnvelope(envelope_nr, main_anim_mode, ACTION_OPENING);
2726 Delay(wait_delay_value);
2728 WaitForEventToContinue();
2730 PlayMenuSoundStereo(sound_closing, SOUND_MIDDLE);
2732 if (anim_mode != ANIM_NONE)
2733 AnimateEnvelope(envelope_nr, main_anim_mode, ACTION_CLOSING);
2735 if (anim_mode == ANIM_DEFAULT)
2736 AnimateEnvelope(envelope_nr, ANIM_DEFAULT, ACTION_CLOSING);
2738 game.envelope_active = FALSE;
2740 SetDrawtoField(DRAW_TO_FIELDBUFFER);
2742 redraw_mask |= REDRAW_FIELD;
2746 static void setRequestBasePosition(int *x, int *y)
2748 int sx_base, sy_base;
2750 if (request.x != -1)
2751 sx_base = request.x;
2752 else if (request.align == ALIGN_LEFT)
2754 else if (request.align == ALIGN_RIGHT)
2755 sx_base = SX + SXSIZE;
2757 sx_base = SX + SXSIZE / 2;
2759 if (request.y != -1)
2760 sy_base = request.y;
2761 else if (request.valign == VALIGN_TOP)
2763 else if (request.valign == VALIGN_BOTTOM)
2764 sy_base = SY + SYSIZE;
2766 sy_base = SY + SYSIZE / 2;
2772 static void setRequestPositionExt(int *x, int *y, int width, int height,
2773 boolean add_border_size)
2775 int border_size = request.border_size;
2776 int sx_base, sy_base;
2779 setRequestBasePosition(&sx_base, &sy_base);
2781 if (request.align == ALIGN_LEFT)
2783 else if (request.align == ALIGN_RIGHT)
2784 sx = sx_base - width;
2786 sx = sx_base - width / 2;
2788 if (request.valign == VALIGN_TOP)
2790 else if (request.valign == VALIGN_BOTTOM)
2791 sy = sy_base - height;
2793 sy = sy_base - height / 2;
2795 sx = MAX(0, MIN(sx, WIN_XSIZE - width));
2796 sy = MAX(0, MIN(sy, WIN_YSIZE - height));
2798 if (add_border_size)
2808 static void setRequestPosition(int *x, int *y, boolean add_border_size)
2810 setRequestPositionExt(x, y, request.width, request.height, add_border_size);
2813 void DrawEnvelopeRequest(char *text)
2815 char *text_final = text;
2816 char *text_door_style = NULL;
2817 int graphic = IMG_BACKGROUND_REQUEST;
2818 Bitmap *src_bitmap = graphic_info[graphic].bitmap;
2819 int mask_mode = (src_bitmap != NULL ? BLIT_MASKED : BLIT_ON_BACKGROUND);
2820 int font_nr = FONT_REQUEST;
2821 int font_width = getFontWidth(font_nr);
2822 int font_height = getFontHeight(font_nr);
2823 int border_size = request.border_size;
2824 int line_spacing = request.line_spacing;
2825 int line_height = font_height + line_spacing;
2826 int max_text_width = request.width - 2 * border_size;
2827 int max_text_height = request.height - 2 * border_size;
2828 int line_length = max_text_width / font_width;
2829 int max_lines = max_text_height / line_height;
2830 int text_width = line_length * font_width;
2831 int width = request.width;
2832 int height = request.height;
2833 int tile_size = MAX(request.step_offset, 1);
2834 int x_steps = width / tile_size;
2835 int y_steps = height / tile_size;
2836 int sx_offset = border_size;
2837 int sy_offset = border_size;
2841 if (request.centered)
2842 sx_offset = (request.width - text_width) / 2;
2844 if (request.wrap_single_words && !request.autowrap)
2846 char *src_text_ptr, *dst_text_ptr;
2848 text_door_style = checked_malloc(2 * strlen(text) + 1);
2850 src_text_ptr = text;
2851 dst_text_ptr = text_door_style;
2853 while (*src_text_ptr)
2855 if (*src_text_ptr == ' ' ||
2856 *src_text_ptr == '?' ||
2857 *src_text_ptr == '!')
2858 *dst_text_ptr++ = '\n';
2860 if (*src_text_ptr != ' ')
2861 *dst_text_ptr++ = *src_text_ptr;
2866 *dst_text_ptr = '\0';
2868 text_final = text_door_style;
2871 setRequestPosition(&sx, &sy, FALSE);
2873 ClearRectangle(backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE);
2875 for (y = 0; y < y_steps; y++)
2876 for (x = 0; x < x_steps; x++)
2877 DrawEnvelopeBackgroundTiles(graphic, sx, sy,
2878 x, y, x_steps, y_steps,
2879 tile_size, tile_size);
2881 /* force DOOR font inside door area */
2882 SetFontStatus(GAME_MODE_PSEUDO_DOOR);
2884 DrawTextBuffer(sx + sx_offset, sy + sy_offset, text_final, font_nr,
2885 line_length, -1, max_lines, line_spacing, mask_mode,
2886 request.autowrap, request.centered, FALSE);
2890 for (i = 0; i < NUM_TOOL_BUTTONS; i++)
2891 RedrawGadget(tool_gadget[i]);
2893 // store readily prepared envelope request for later use when animating
2894 BlitBitmap(backbuffer, bitmap_db_store_2, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
2896 if (text_door_style)
2897 free(text_door_style);
2900 void AnimateEnvelopeRequest(int anim_mode, int action)
2902 int graphic = IMG_BACKGROUND_REQUEST;
2903 boolean draw_masked = graphic_info[graphic].draw_masked;
2904 int delay_value_normal = request.step_delay;
2905 int delay_value_fast = delay_value_normal / 2;
2906 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2907 boolean no_delay = (tape.warp_forward);
2908 int delay_value = (ffwd_delay ? delay_value_fast : delay_value_normal);
2909 int anim_delay_value = MAX(1, (no_delay ? 0 : delay_value + 500 * 0) / 2);
2910 unsigned int anim_delay = 0;
2912 int tile_size = MAX(request.step_offset, 1);
2913 int max_xsize = request.width / tile_size;
2914 int max_ysize = request.height / tile_size;
2915 int max_xsize_inner = max_xsize - 2;
2916 int max_ysize_inner = max_ysize - 2;
2918 int xstart = (anim_mode & ANIM_VERTICAL ? max_xsize_inner : 0);
2919 int ystart = (anim_mode & ANIM_HORIZONTAL ? max_ysize_inner : 0);
2920 int xend = max_xsize_inner;
2921 int yend = (anim_mode != ANIM_DEFAULT ? max_ysize_inner : 0);
2922 int xstep = (xstart < xend ? 1 : 0);
2923 int ystep = (ystart < yend || xstep == 0 ? 1 : 0);
2925 int end = MAX(xend - xstart, yend - ystart);
2928 if (setup.quick_doors)
2935 for (i = start; i <= end; i++)
2937 int last_frame = end; // last frame of this "for" loop
2938 int x = xstart + i * xstep;
2939 int y = ystart + i * ystep;
2940 int xsize = (action == ACTION_CLOSING ? xend - (x - xstart) : x) + 2;
2941 int ysize = (action == ACTION_CLOSING ? yend - (y - ystart) : y) + 2;
2942 int xsize_size_left = (xsize - 1) * tile_size;
2943 int ysize_size_top = (ysize - 1) * tile_size;
2944 int max_xsize_pos = (max_xsize - 1) * tile_size;
2945 int max_ysize_pos = (max_ysize - 1) * tile_size;
2946 int width = xsize * tile_size;
2947 int height = ysize * tile_size;
2952 setRequestPosition(&src_x, &src_y, FALSE);
2953 setRequestPositionExt(&dst_x, &dst_y, width, height, FALSE);
2955 BlitBitmap(bitmap_db_store_1, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
2957 for (yy = 0; yy < 2; yy++)
2959 for (xx = 0; xx < 2; xx++)
2961 int src_xx = src_x + xx * max_xsize_pos;
2962 int src_yy = src_y + yy * max_ysize_pos;
2963 int dst_xx = dst_x + xx * xsize_size_left;
2964 int dst_yy = dst_y + yy * ysize_size_top;
2965 int xx_size = (xx ? tile_size : xsize_size_left);
2966 int yy_size = (yy ? tile_size : ysize_size_top);
2969 BlitBitmapMasked(bitmap_db_store_2, backbuffer,
2970 src_xx, src_yy, xx_size, yy_size, dst_xx, dst_yy);
2972 BlitBitmap(bitmap_db_store_2, backbuffer,
2973 src_xx, src_yy, xx_size, yy_size, dst_xx, dst_yy);
2977 redraw_mask |= REDRAW_FIELD;
2981 SkipUntilDelayReached(&anim_delay, anim_delay_value, &i, last_frame);
2985 void ShowEnvelopeRequest(char *text, unsigned int req_state, int action)
2987 int graphic = IMG_BACKGROUND_REQUEST;
2988 int sound_opening = SND_REQUEST_OPENING;
2989 int sound_closing = SND_REQUEST_CLOSING;
2990 int anim_mode_1 = request.anim_mode; /* (higher priority) */
2991 int anim_mode_2 = graphic_info[graphic].anim_mode; /* (lower priority) */
2992 int anim_mode = (anim_mode_1 != ANIM_DEFAULT ? anim_mode_1 : anim_mode_2);
2993 int main_anim_mode = (anim_mode == ANIM_NONE ? ANIM_VERTICAL|ANIM_HORIZONTAL:
2994 anim_mode == ANIM_DEFAULT ? ANIM_VERTICAL : anim_mode);
2996 if (game_status == GAME_MODE_PLAYING)
2997 BlitScreenToBitmap(backbuffer);
2999 SetDrawtoField(DRAW_TO_BACKBUFFER);
3001 // SetDrawBackgroundMask(REDRAW_NONE);
3003 if (action == ACTION_OPENING)
3005 BlitBitmap(backbuffer, bitmap_db_store_1, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
3007 if (req_state & REQ_ASK)
3009 MapGadget(tool_gadget[TOOL_CTRL_ID_YES]);
3010 MapGadget(tool_gadget[TOOL_CTRL_ID_NO]);
3012 else if (req_state & REQ_CONFIRM)
3014 MapGadget(tool_gadget[TOOL_CTRL_ID_CONFIRM]);
3016 else if (req_state & REQ_PLAYER)
3018 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_1]);
3019 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_2]);
3020 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_3]);
3021 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_4]);
3024 DrawEnvelopeRequest(text);
3027 game.envelope_active = TRUE; /* needed for RedrawPlayfield() events */
3029 if (action == ACTION_OPENING)
3031 PlayMenuSoundStereo(sound_opening, SOUND_MIDDLE);
3033 if (anim_mode == ANIM_DEFAULT)
3034 AnimateEnvelopeRequest(ANIM_DEFAULT, ACTION_OPENING);
3036 AnimateEnvelopeRequest(main_anim_mode, ACTION_OPENING);
3040 PlayMenuSoundStereo(sound_closing, SOUND_MIDDLE);
3042 if (anim_mode != ANIM_NONE)
3043 AnimateEnvelopeRequest(main_anim_mode, ACTION_CLOSING);
3045 if (anim_mode == ANIM_DEFAULT)
3046 AnimateEnvelopeRequest(ANIM_DEFAULT, ACTION_CLOSING);
3049 game.envelope_active = FALSE;
3051 if (action == ACTION_CLOSING)
3052 BlitBitmap(bitmap_db_store_1, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
3054 // SetDrawBackgroundMask(last_draw_background_mask);
3056 redraw_mask |= REDRAW_FIELD;
3060 if (action == ACTION_CLOSING &&
3061 game_status == GAME_MODE_PLAYING &&
3062 level.game_engine_type == GAME_ENGINE_TYPE_RND)
3063 SetDrawtoField(DRAW_TO_FIELDBUFFER);
3066 void DrawPreviewElement(int dst_x, int dst_y, int element, int tilesize)
3068 if (IS_MM_WALL(element))
3070 DrawSizedWall_MM(dst_x, dst_y, element, tilesize, el2preimg);
3076 int graphic = el2preimg(element);
3078 getSizedGraphicSource(graphic, 0, tilesize, &src_bitmap, &src_x, &src_y);
3079 BlitBitmap(src_bitmap, drawto, src_x, src_y, tilesize, tilesize,
3084 void DrawLevel(int draw_background_mask)
3088 SetMainBackgroundImage(IMG_BACKGROUND_PLAYING);
3089 SetDrawBackgroundMask(draw_background_mask);
3093 for (x = BX1; x <= BX2; x++)
3094 for (y = BY1; y <= BY2; y++)
3095 DrawScreenField(x, y);
3097 redraw_mask |= REDRAW_FIELD;
3100 void DrawSizedLevel(int size_x, int size_y, int scroll_x, int scroll_y,
3105 for (x = 0; x < size_x; x++)
3106 for (y = 0; y < size_y; y++)
3107 DrawSizedElementOrWall(x, y, scroll_x, scroll_y, tilesize);
3109 redraw_mask |= REDRAW_FIELD;
3112 void DrawMiniLevel(int size_x, int size_y, int scroll_x, int scroll_y)
3116 for (x = 0; x < size_x; x++)
3117 for (y = 0; y < size_y; y++)
3118 DrawMiniElementOrWall(x, y, scroll_x, scroll_y);
3120 redraw_mask |= REDRAW_FIELD;
3123 static void DrawPreviewLevelPlayfield(int from_x, int from_y)
3125 boolean show_level_border = (BorderElement != EL_EMPTY);
3126 int level_xsize = lev_fieldx + (show_level_border ? 2 : 0);
3127 int level_ysize = lev_fieldy + (show_level_border ? 2 : 0);
3128 int tile_size = preview.tile_size;
3129 int preview_width = preview.xsize * tile_size;
3130 int preview_height = preview.ysize * tile_size;
3131 int real_preview_xsize = MIN(level_xsize, preview.xsize);
3132 int real_preview_ysize = MIN(level_ysize, preview.ysize);
3133 int real_preview_width = real_preview_xsize * tile_size;
3134 int real_preview_height = real_preview_ysize * tile_size;
3135 int dst_x = SX + ALIGNED_XPOS(preview.x, preview_width, preview.align);
3136 int dst_y = SY + ALIGNED_YPOS(preview.y, preview_height, preview.valign);
3139 if (!IN_GFX_FIELD_FULL(dst_x, dst_y + preview_height - 1))
3142 DrawBackground(dst_x, dst_y, preview_width, preview_height);
3144 dst_x += (preview_width - real_preview_width) / 2;
3145 dst_y += (preview_height - real_preview_height) / 2;
3147 for (x = 0; x < real_preview_xsize; x++)
3149 for (y = 0; y < real_preview_ysize; y++)
3151 int lx = from_x + x + (show_level_border ? -1 : 0);
3152 int ly = from_y + y + (show_level_border ? -1 : 0);
3153 int element = (IN_LEV_FIELD(lx, ly) ? level.field[lx][ly] :
3154 getBorderElement(lx, ly));
3156 DrawPreviewElement(dst_x + x * tile_size, dst_y + y * tile_size,
3157 element, tile_size);
3161 redraw_mask |= REDRAW_FIELD;
3164 #define MICROLABEL_EMPTY 0
3165 #define MICROLABEL_LEVEL_NAME 1
3166 #define MICROLABEL_LEVEL_AUTHOR_HEAD 2
3167 #define MICROLABEL_LEVEL_AUTHOR 3
3168 #define MICROLABEL_IMPORTED_FROM_HEAD 4
3169 #define MICROLABEL_IMPORTED_FROM 5
3170 #define MICROLABEL_IMPORTED_BY_HEAD 6
3171 #define MICROLABEL_IMPORTED_BY 7
3173 static int getMaxTextLength(struct TextPosInfo *pos, int font_nr)
3175 int max_text_width = SXSIZE;
3176 int font_width = getFontWidth(font_nr);
3178 if (pos->align == ALIGN_CENTER)
3179 max_text_width = (pos->x < SXSIZE / 2 ? pos->x * 2 : (SXSIZE - pos->x) * 2);
3180 else if (pos->align == ALIGN_RIGHT)
3181 max_text_width = pos->x;
3183 max_text_width = SXSIZE - pos->x;
3185 return max_text_width / font_width;
3188 static void DrawPreviewLevelLabelExt(int mode, struct TextPosInfo *pos)
3190 char label_text[MAX_OUTPUT_LINESIZE + 1];
3191 int max_len_label_text;
3192 int font_nr = pos->font;
3195 if (!IN_GFX_FIELD_FULL(pos->x, pos->y + getFontHeight(pos->font)))
3198 if (mode == MICROLABEL_LEVEL_AUTHOR_HEAD ||
3199 mode == MICROLABEL_IMPORTED_FROM_HEAD ||
3200 mode == MICROLABEL_IMPORTED_BY_HEAD)
3201 font_nr = pos->font_alt;
3203 max_len_label_text = getMaxTextLength(pos, font_nr);
3205 if (pos->size != -1)
3206 max_len_label_text = pos->size;
3208 for (i = 0; i < max_len_label_text; i++)
3209 label_text[i] = ' ';
3210 label_text[max_len_label_text] = '\0';
3212 if (strlen(label_text) > 0)
3213 DrawTextSAligned(pos->x, pos->y, label_text, font_nr, pos->align);
3216 (mode == MICROLABEL_LEVEL_NAME ? level.name :
3217 mode == MICROLABEL_LEVEL_AUTHOR_HEAD ? "created by" :
3218 mode == MICROLABEL_LEVEL_AUTHOR ? level.author :
3219 mode == MICROLABEL_IMPORTED_FROM_HEAD ? "imported from" :
3220 mode == MICROLABEL_IMPORTED_FROM ? leveldir_current->imported_from :
3221 mode == MICROLABEL_IMPORTED_BY_HEAD ? "imported by" :
3222 mode == MICROLABEL_IMPORTED_BY ? leveldir_current->imported_by :""),
3223 max_len_label_text);
3224 label_text[max_len_label_text] = '\0';
3226 if (strlen(label_text) > 0)
3227 DrawTextSAligned(pos->x, pos->y, label_text, font_nr, pos->align);
3229 redraw_mask |= REDRAW_FIELD;
3232 static void DrawPreviewLevelLabel(int mode)
3234 DrawPreviewLevelLabelExt(mode, &menu.main.text.level_info_2);
3237 static void DrawPreviewLevelInfo(int mode)
3239 if (mode == MICROLABEL_LEVEL_NAME)
3240 DrawPreviewLevelLabelExt(mode, &menu.main.text.level_name);
3241 else if (mode == MICROLABEL_LEVEL_AUTHOR)
3242 DrawPreviewLevelLabelExt(mode, &menu.main.text.level_author);
3245 static void DrawPreviewLevelExt(boolean restart)
3247 static unsigned int scroll_delay = 0;
3248 static unsigned int label_delay = 0;
3249 static int from_x, from_y, scroll_direction;
3250 static int label_state, label_counter;
3251 unsigned int scroll_delay_value = preview.step_delay;
3252 boolean show_level_border = (BorderElement != EL_EMPTY);
3253 int level_xsize = lev_fieldx + (show_level_border ? 2 : 0);
3254 int level_ysize = lev_fieldy + (show_level_border ? 2 : 0);
3261 if (preview.anim_mode == ANIM_CENTERED)
3263 if (level_xsize > preview.xsize)
3264 from_x = (level_xsize - preview.xsize) / 2;
3265 if (level_ysize > preview.ysize)
3266 from_y = (level_ysize - preview.ysize) / 2;
3269 from_x += preview.xoffset;
3270 from_y += preview.yoffset;
3272 scroll_direction = MV_RIGHT;
3276 DrawPreviewLevelPlayfield(from_x, from_y);
3277 DrawPreviewLevelLabel(label_state);
3279 DrawPreviewLevelInfo(MICROLABEL_LEVEL_NAME);
3280 DrawPreviewLevelInfo(MICROLABEL_LEVEL_AUTHOR);
3282 /* initialize delay counters */
3283 DelayReached(&scroll_delay, 0);
3284 DelayReached(&label_delay, 0);
3286 if (leveldir_current->name)
3288 struct TextPosInfo *pos = &menu.main.text.level_info_1;
3289 char label_text[MAX_OUTPUT_LINESIZE + 1];
3290 int font_nr = pos->font;
3291 int max_len_label_text = getMaxTextLength(pos, font_nr);
3293 if (pos->size != -1)
3294 max_len_label_text = pos->size;
3296 strncpy(label_text, leveldir_current->name, max_len_label_text);
3297 label_text[max_len_label_text] = '\0';
3299 if (IN_GFX_FIELD_FULL(pos->x, pos->y + getFontHeight(pos->font)))
3300 DrawTextSAligned(pos->x, pos->y, label_text, font_nr, pos->align);
3306 /* scroll preview level, if needed */
3307 if (preview.anim_mode != ANIM_NONE &&
3308 (level_xsize > preview.xsize || level_ysize > preview.ysize) &&
3309 DelayReached(&scroll_delay, scroll_delay_value))
3311 switch (scroll_direction)
3316 from_x -= preview.step_offset;
3317 from_x = (from_x < 0 ? 0 : from_x);
3320 scroll_direction = MV_UP;
3324 if (from_x < level_xsize - preview.xsize)
3326 from_x += preview.step_offset;
3327 from_x = (from_x > level_xsize - preview.xsize ?
3328 level_xsize - preview.xsize : from_x);
3331 scroll_direction = MV_DOWN;
3337 from_y -= preview.step_offset;
3338 from_y = (from_y < 0 ? 0 : from_y);
3341 scroll_direction = MV_RIGHT;
3345 if (from_y < level_ysize - preview.ysize)
3347 from_y += preview.step_offset;
3348 from_y = (from_y > level_ysize - preview.ysize ?
3349 level_ysize - preview.ysize : from_y);
3352 scroll_direction = MV_LEFT;
3359 DrawPreviewLevelPlayfield(from_x, from_y);
3362 /* !!! THIS ALL SUCKS -- SHOULD BE CLEANLY REWRITTEN !!! */
3363 /* redraw micro level label, if needed */
3364 if (!strEqual(level.name, NAMELESS_LEVEL_NAME) &&
3365 !strEqual(level.author, ANONYMOUS_NAME) &&
3366 !strEqual(level.author, leveldir_current->name) &&
3367 DelayReached(&label_delay, MICROLEVEL_LABEL_DELAY))
3369 int max_label_counter = 23;
3371 if (leveldir_current->imported_from != NULL &&
3372 strlen(leveldir_current->imported_from) > 0)
3373 max_label_counter += 14;
3374 if (leveldir_current->imported_by != NULL &&
3375 strlen(leveldir_current->imported_by) > 0)
3376 max_label_counter += 14;
3378 label_counter = (label_counter + 1) % max_label_counter;
3379 label_state = (label_counter >= 0 && label_counter <= 7 ?
3380 MICROLABEL_LEVEL_NAME :
3381 label_counter >= 9 && label_counter <= 12 ?
3382 MICROLABEL_LEVEL_AUTHOR_HEAD :
3383 label_counter >= 14 && label_counter <= 21 ?
3384 MICROLABEL_LEVEL_AUTHOR :
3385 label_counter >= 23 && label_counter <= 26 ?
3386 MICROLABEL_IMPORTED_FROM_HEAD :
3387 label_counter >= 28 && label_counter <= 35 ?
3388 MICROLABEL_IMPORTED_FROM :
3389 label_counter >= 37 && label_counter <= 40 ?
3390 MICROLABEL_IMPORTED_BY_HEAD :
3391 label_counter >= 42 && label_counter <= 49 ?
3392 MICROLABEL_IMPORTED_BY : MICROLABEL_EMPTY);
3394 if (leveldir_current->imported_from == NULL &&
3395 (label_state == MICROLABEL_IMPORTED_FROM_HEAD ||
3396 label_state == MICROLABEL_IMPORTED_FROM))
3397 label_state = (label_state == MICROLABEL_IMPORTED_FROM_HEAD ?
3398 MICROLABEL_IMPORTED_BY_HEAD : MICROLABEL_IMPORTED_BY);
3400 DrawPreviewLevelLabel(label_state);
3404 void DrawPreviewLevelInitial()
3406 DrawPreviewLevelExt(TRUE);
3409 void DrawPreviewLevelAnimation()
3411 DrawPreviewLevelExt(FALSE);
3414 inline static void DrawGraphicAnimationExt(DrawBuffer *dst_bitmap, int x, int y,
3415 int graphic, int sync_frame,
3418 int frame = getGraphicAnimationFrame(graphic, sync_frame);
3420 if (mask_mode == USE_MASKING)
3421 DrawGraphicThruMaskExt(dst_bitmap, x, y, graphic, frame);
3423 DrawGraphicExt(dst_bitmap, x, y, graphic, frame);
3426 void DrawFixedGraphicAnimationExt(DrawBuffer *dst_bitmap, int x, int y,
3427 int graphic, int sync_frame, int mask_mode)
3429 int frame = getGraphicAnimationFrame(graphic, sync_frame);
3431 if (mask_mode == USE_MASKING)
3432 DrawFixedGraphicThruMaskExt(dst_bitmap, x, y, graphic, frame);
3434 DrawFixedGraphicExt(dst_bitmap, x, y, graphic, frame);
3437 inline static void DrawGraphicAnimation(int x, int y, int graphic)
3439 int lx = LEVELX(x), ly = LEVELY(y);
3441 if (!IN_SCR_FIELD(x, y))
3444 DrawGraphicAnimationExt(drawto_field, FX + x * TILEX_VAR, FY + y * TILEY_VAR,
3445 graphic, GfxFrame[lx][ly], NO_MASKING);
3447 MarkTileDirty(x, y);
3450 void DrawFixedGraphicAnimation(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, FY + y * TILEY,
3458 graphic, GfxFrame[lx][ly], NO_MASKING);
3459 MarkTileDirty(x, y);
3462 void DrawLevelGraphicAnimation(int x, int y, int graphic)
3464 DrawGraphicAnimation(SCREENX(x), SCREENY(y), graphic);
3467 void DrawLevelElementAnimation(int x, int y, int element)
3469 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
3471 DrawGraphicAnimation(SCREENX(x), SCREENY(y), graphic);
3474 void DrawLevelGraphicAnimationIfNeeded(int x, int y, int graphic)
3476 int sx = SCREENX(x), sy = SCREENY(y);
3478 if (!IN_LEV_FIELD(x, y) || !IN_SCR_FIELD(sx, sy))
3481 if (!IS_NEW_FRAME(GfxFrame[x][y], graphic))
3484 DrawGraphicAnimation(sx, sy, graphic);
3487 if (GFX_CRUMBLED(TILE_GFX_ELEMENT(x, y)))
3488 DrawLevelFieldCrumbled(x, y);
3490 if (GFX_CRUMBLED(Feld[x][y]))
3491 DrawLevelFieldCrumbled(x, y);
3495 void DrawLevelElementAnimationIfNeeded(int x, int y, int element)
3497 int sx = SCREENX(x), sy = SCREENY(y);
3500 if (!IN_LEV_FIELD(x, y) || !IN_SCR_FIELD(sx, sy))
3503 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
3505 if (!IS_NEW_FRAME(GfxFrame[x][y], graphic))
3508 DrawGraphicAnimation(sx, sy, graphic);
3510 if (GFX_CRUMBLED(element))
3511 DrawLevelFieldCrumbled(x, y);
3514 static int getPlayerGraphic(struct PlayerInfo *player, int move_dir)
3516 if (player->use_murphy)
3518 /* this works only because currently only one player can be "murphy" ... */
3519 static int last_horizontal_dir = MV_LEFT;
3520 int graphic = el_act_dir2img(EL_SP_MURPHY, player->GfxAction, move_dir);
3522 if (move_dir == MV_LEFT || move_dir == MV_RIGHT)
3523 last_horizontal_dir = move_dir;
3525 if (graphic == IMG_SP_MURPHY) /* undefined => use special graphic */
3527 int direction = (player->is_snapping ? move_dir : last_horizontal_dir);
3529 graphic = el_act_dir2img(EL_SP_MURPHY, player->GfxAction, direction);
3535 return el_act_dir2img(player->artwork_element, player->GfxAction,move_dir);
3538 static boolean equalGraphics(int graphic1, int graphic2)
3540 struct GraphicInfo *g1 = &graphic_info[graphic1];
3541 struct GraphicInfo *g2 = &graphic_info[graphic2];
3543 return (g1->bitmap == g2->bitmap &&
3544 g1->src_x == g2->src_x &&
3545 g1->src_y == g2->src_y &&
3546 g1->anim_frames == g2->anim_frames &&
3547 g1->anim_delay == g2->anim_delay &&
3548 g1->anim_mode == g2->anim_mode);
3551 void DrawAllPlayers()
3555 for (i = 0; i < MAX_PLAYERS; i++)
3556 if (stored_player[i].active)
3557 DrawPlayer(&stored_player[i]);
3560 void DrawPlayerField(int x, int y)
3562 if (!IS_PLAYER(x, y))
3565 DrawPlayer(PLAYERINFO(x, y));
3568 #define DRAW_PLAYER_OVER_PUSHED_ELEMENT 1
3570 void DrawPlayer(struct PlayerInfo *player)
3572 int jx = player->jx;
3573 int jy = player->jy;
3574 int move_dir = player->MovDir;
3575 int dx = (move_dir == MV_LEFT ? -1 : move_dir == MV_RIGHT ? +1 : 0);
3576 int dy = (move_dir == MV_UP ? -1 : move_dir == MV_DOWN ? +1 : 0);
3577 int last_jx = (player->is_moving ? jx - dx : jx);
3578 int last_jy = (player->is_moving ? jy - dy : jy);
3579 int next_jx = jx + dx;
3580 int next_jy = jy + dy;
3581 boolean player_is_moving = (player->MovPos ? TRUE : FALSE);
3582 boolean player_is_opaque = FALSE;
3583 int sx = SCREENX(jx), sy = SCREENY(jy);
3584 int sxx = 0, syy = 0;
3585 int element = Feld[jx][jy], last_element = Feld[last_jx][last_jy];
3587 int action = ACTION_DEFAULT;
3588 int last_player_graphic = getPlayerGraphic(player, move_dir);
3589 int last_player_frame = player->Frame;
3592 /* GfxElement[][] is set to the element the player is digging or collecting;
3593 remove also for off-screen player if the player is not moving anymore */
3594 if (IN_LEV_FIELD(jx, jy) && !player_is_moving)
3595 GfxElement[jx][jy] = EL_UNDEFINED;
3597 if (!player->active || !IN_SCR_FIELD(SCREENX(last_jx), SCREENY(last_jy)))
3601 if (!IN_LEV_FIELD(jx, jy))
3603 printf("DrawPlayerField(): x = %d, y = %d\n",jx,jy);
3604 printf("DrawPlayerField(): sx = %d, sy = %d\n",sx,sy);
3605 printf("DrawPlayerField(): This should never happen!\n");
3610 if (element == EL_EXPLOSION)
3613 action = (player->is_pushing ? ACTION_PUSHING :
3614 player->is_digging ? ACTION_DIGGING :
3615 player->is_collecting ? ACTION_COLLECTING :
3616 player->is_moving ? ACTION_MOVING :
3617 player->is_snapping ? ACTION_SNAPPING :
3618 player->is_dropping ? ACTION_DROPPING :
3619 player->is_waiting ? player->action_waiting : ACTION_DEFAULT);
3621 if (player->is_waiting)
3622 move_dir = player->dir_waiting;
3624 InitPlayerGfxAnimation(player, action, move_dir);
3626 /* ----------------------------------------------------------------------- */
3627 /* draw things in the field the player is leaving, if needed */
3628 /* ----------------------------------------------------------------------- */
3630 if (player->is_moving)
3632 if (Back[last_jx][last_jy] && IS_DRAWABLE(last_element))
3634 DrawLevelElement(last_jx, last_jy, Back[last_jx][last_jy]);
3636 if (last_element == EL_DYNAMITE_ACTIVE ||
3637 last_element == EL_EM_DYNAMITE_ACTIVE ||
3638 last_element == EL_SP_DISK_RED_ACTIVE)
3639 DrawDynamite(last_jx, last_jy);
3641 DrawLevelFieldThruMask(last_jx, last_jy);
3643 else if (last_element == EL_DYNAMITE_ACTIVE ||
3644 last_element == EL_EM_DYNAMITE_ACTIVE ||
3645 last_element == EL_SP_DISK_RED_ACTIVE)
3646 DrawDynamite(last_jx, last_jy);
3648 /* !!! this is not enough to prevent flickering of players which are
3649 moving next to each others without a free tile between them -- this
3650 can only be solved by drawing all players layer by layer (first the
3651 background, then the foreground etc.) !!! => TODO */
3652 else if (!IS_PLAYER(last_jx, last_jy))
3653 DrawLevelField(last_jx, last_jy);
3656 DrawLevelField(last_jx, last_jy);
3659 if (player->is_pushing && IN_SCR_FIELD(SCREENX(next_jx), SCREENY(next_jy)))
3660 DrawLevelElement(next_jx, next_jy, EL_EMPTY);
3663 if (!IN_SCR_FIELD(sx, sy))
3666 /* ----------------------------------------------------------------------- */
3667 /* draw things behind the player, if needed */
3668 /* ----------------------------------------------------------------------- */
3671 DrawLevelElement(jx, jy, Back[jx][jy]);
3672 else if (IS_ACTIVE_BOMB(element))
3673 DrawLevelElement(jx, jy, EL_EMPTY);
3676 if (player_is_moving && GfxElement[jx][jy] != EL_UNDEFINED)
3678 int old_element = GfxElement[jx][jy];
3679 int old_graphic = el_act_dir2img(old_element, action, move_dir);
3680 int frame = getGraphicAnimationFrame(old_graphic, player->StepFrame);
3682 if (GFX_CRUMBLED(old_element))
3683 DrawLevelFieldCrumbledDigging(jx, jy, move_dir, player->StepFrame);
3685 DrawGraphic(sx, sy, old_graphic, frame);
3687 if (graphic_info[old_graphic].anim_mode & ANIM_OPAQUE_PLAYER)
3688 player_is_opaque = TRUE;
3692 GfxElement[jx][jy] = EL_UNDEFINED;
3694 /* make sure that pushed elements are drawn with correct frame rate */
3695 graphic = el_act_dir2img(element, ACTION_PUSHING, move_dir);
3697 if (player->is_pushing && player->is_moving && !IS_ANIM_MODE_CE(graphic))
3698 GfxFrame[jx][jy] = player->StepFrame;
3700 DrawLevelField(jx, jy);
3704 #if !DRAW_PLAYER_OVER_PUSHED_ELEMENT
3705 /* ----------------------------------------------------------------------- */
3706 /* draw player himself */
3707 /* ----------------------------------------------------------------------- */
3709 graphic = getPlayerGraphic(player, move_dir);
3711 /* in the case of changed player action or direction, prevent the current
3712 animation frame from being restarted for identical animations */
3713 if (player->Frame == 0 && equalGraphics(graphic, last_player_graphic))
3714 player->Frame = last_player_frame;
3716 frame = getGraphicAnimationFrame(graphic, player->Frame);
3720 if (move_dir == MV_LEFT || move_dir == MV_RIGHT)
3721 sxx = player->GfxPos;
3723 syy = player->GfxPos;
3726 if (player_is_opaque)
3727 DrawGraphicShifted(sx, sy, sxx, syy, graphic, frame,NO_CUTTING,NO_MASKING);
3729 DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic, frame, NO_CUTTING);
3731 if (SHIELD_ON(player))
3733 int graphic = (player->shield_deadly_time_left ? IMG_SHIELD_DEADLY_ACTIVE :
3734 IMG_SHIELD_NORMAL_ACTIVE);
3735 int frame = getGraphicAnimationFrame(graphic, -1);
3737 DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic, frame, NO_CUTTING);
3741 #if DRAW_PLAYER_OVER_PUSHED_ELEMENT
3744 if (move_dir == MV_LEFT || move_dir == MV_RIGHT)
3745 sxx = player->GfxPos;
3747 syy = player->GfxPos;
3751 /* ----------------------------------------------------------------------- */
3752 /* draw things the player is pushing, if needed */
3753 /* ----------------------------------------------------------------------- */
3755 if (player->is_pushing && player->is_moving)
3757 int px = SCREENX(jx), py = SCREENY(jy);
3758 int pxx = (TILEX - ABS(sxx)) * dx;
3759 int pyy = (TILEY - ABS(syy)) * dy;
3760 int gfx_frame = GfxFrame[jx][jy];
3766 if (!IS_MOVING(jx, jy)) /* push movement already finished */
3768 element = Feld[next_jx][next_jy];
3769 gfx_frame = GfxFrame[next_jx][next_jy];
3772 graphic = el_act_dir2img(element, ACTION_PUSHING, move_dir);
3774 sync_frame = (IS_ANIM_MODE_CE(graphic) ? gfx_frame : player->StepFrame);
3775 frame = getGraphicAnimationFrame(graphic, sync_frame);
3777 /* draw background element under pushed element (like the Sokoban field) */
3778 if (game.use_masked_pushing && IS_MOVING(jx, jy))
3780 /* this allows transparent pushing animation over non-black background */
3783 DrawLevelElement(jx, jy, Back[jx][jy]);
3785 DrawLevelElement(jx, jy, EL_EMPTY);
3787 if (Back[next_jx][next_jy])
3788 DrawLevelElement(next_jx, next_jy, Back[next_jx][next_jy]);
3790 DrawLevelElement(next_jx, next_jy, EL_EMPTY);
3792 else if (Back[next_jx][next_jy])
3793 DrawLevelElement(next_jx, next_jy, Back[next_jx][next_jy]);
3796 /* do not draw (EM style) pushing animation when pushing is finished */
3797 /* (two-tile animations usually do not contain start and end frame) */
3798 if (graphic_info[graphic].double_movement && !IS_MOVING(jx, jy))
3799 DrawLevelElement(next_jx, next_jy, Feld[next_jx][next_jy]);
3801 DrawGraphicShiftedThruMask(px, py, pxx, pyy, graphic, frame, NO_CUTTING);
3803 /* masked drawing is needed for EMC style (double) movement graphics */
3804 /* !!! (ONLY WHEN DRAWING PUSHED ELEMENT OVER THE PLAYER) !!! */
3805 DrawGraphicShiftedThruMask(px, py, pxx, pyy, graphic, frame, NO_CUTTING);
3809 #if DRAW_PLAYER_OVER_PUSHED_ELEMENT
3810 /* ----------------------------------------------------------------------- */
3811 /* draw player himself */
3812 /* ----------------------------------------------------------------------- */
3814 graphic = getPlayerGraphic(player, move_dir);
3816 /* in the case of changed player action or direction, prevent the current
3817 animation frame from being restarted for identical animations */
3818 if (player->Frame == 0 && equalGraphics(graphic, last_player_graphic))
3819 player->Frame = last_player_frame;
3821 frame = getGraphicAnimationFrame(graphic, player->Frame);
3825 if (move_dir == MV_LEFT || move_dir == MV_RIGHT)
3826 sxx = player->GfxPos;
3828 syy = player->GfxPos;
3831 if (player_is_opaque)
3832 DrawGraphicShifted(sx, sy, sxx, syy, graphic, frame,NO_CUTTING,NO_MASKING);
3834 DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic, frame, NO_CUTTING);
3836 if (SHIELD_ON(player))
3838 int graphic = (player->shield_deadly_time_left ? IMG_SHIELD_DEADLY_ACTIVE :
3839 IMG_SHIELD_NORMAL_ACTIVE);
3840 int frame = getGraphicAnimationFrame(graphic, -1);
3842 DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic, frame, NO_CUTTING);
3846 /* ----------------------------------------------------------------------- */
3847 /* draw things in front of player (active dynamite or dynabombs) */
3848 /* ----------------------------------------------------------------------- */
3850 if (IS_ACTIVE_BOMB(element))
3852 graphic = el2img(element);
3853 frame = getGraphicAnimationFrame(graphic, GfxFrame[jx][jy]);
3855 if (game.emulation == EMU_SUPAPLEX)
3856 DrawGraphic(sx, sy, IMG_SP_DISK_RED, frame);
3858 DrawGraphicThruMask(sx, sy, graphic, frame);
3861 if (player_is_moving && last_element == EL_EXPLOSION)
3863 int element = (GfxElement[last_jx][last_jy] != EL_UNDEFINED ?
3864 GfxElement[last_jx][last_jy] : EL_EMPTY);
3865 int graphic = el_act2img(element, ACTION_EXPLODING);
3866 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
3867 int phase = ExplodePhase[last_jx][last_jy] - 1;
3868 int frame = getGraphicAnimationFrame(graphic, phase - delay);
3871 DrawGraphicThruMask(SCREENX(last_jx), SCREENY(last_jy), graphic, frame);
3874 /* ----------------------------------------------------------------------- */
3875 /* draw elements the player is just walking/passing through/under */
3876 /* ----------------------------------------------------------------------- */
3878 if (player_is_moving)
3880 /* handle the field the player is leaving ... */
3881 if (IS_ACCESSIBLE_INSIDE(last_element))
3882 DrawLevelField(last_jx, last_jy);
3883 else if (IS_ACCESSIBLE_UNDER(last_element))
3884 DrawLevelFieldThruMask(last_jx, last_jy);
3887 /* do not redraw accessible elements if the player is just pushing them */
3888 if (!player_is_moving || !player->is_pushing)
3890 /* ... and the field the player is entering */
3891 if (IS_ACCESSIBLE_INSIDE(element))
3892 DrawLevelField(jx, jy);
3893 else if (IS_ACCESSIBLE_UNDER(element))
3894 DrawLevelFieldThruMask(jx, jy);
3897 MarkTileDirty(sx, sy);
3900 /* ------------------------------------------------------------------------- */
3902 void WaitForEventToContinue()
3904 boolean still_wait = TRUE;
3906 if (program.headless)
3909 /* simulate releasing mouse button over last gadget, if still pressed */
3911 HandleGadgets(-1, -1, 0);
3913 button_status = MB_RELEASED;
3921 if (NextValidEvent(&event))
3925 case EVENT_BUTTONPRESS:
3926 case EVENT_KEYPRESS:
3927 #if defined(TARGET_SDL2)
3928 case SDL_CONTROLLERBUTTONDOWN:
3930 case SDL_JOYBUTTONDOWN:
3934 case EVENT_KEYRELEASE:
3935 ClearPlayerAction();
3939 HandleOtherEvents(&event);
3943 else if (AnyJoystickButton() == JOY_BUTTON_NEW_PRESSED)
3952 #define MAX_REQUEST_LINES 13
3953 #define MAX_REQUEST_LINE_FONT1_LEN 7
3954 #define MAX_REQUEST_LINE_FONT2_LEN 10
3956 static int RequestHandleEvents(unsigned int req_state)
3958 boolean level_solved = (game_status == GAME_MODE_PLAYING &&
3959 local_player->LevelSolved_GameEnd);
3960 int width = request.width;
3961 int height = request.height;
3965 setRequestPosition(&sx, &sy, FALSE);
3967 button_status = MB_RELEASED;
3969 request_gadget_id = -1;
3976 SetDrawtoField(DRAW_TO_FIELDBUFFER);
3978 HandleGameActions();
3980 SetDrawtoField(DRAW_TO_BACKBUFFER);
3982 if (global.use_envelope_request)
3984 /* copy current state of request area to middle of playfield area */
3985 BlitBitmap(bitmap_db_store_2, drawto, sx, sy, width, height, sx, sy);
3993 while (NextValidEvent(&event))
3997 case EVENT_BUTTONPRESS:
3998 case EVENT_BUTTONRELEASE:
3999 case EVENT_MOTIONNOTIFY:
4003 if (event.type == EVENT_MOTIONNOTIFY)
4008 motion_status = TRUE;
4009 mx = ((MotionEvent *) &event)->x;
4010 my = ((MotionEvent *) &event)->y;
4014 motion_status = FALSE;
4015 mx = ((ButtonEvent *) &event)->x;
4016 my = ((ButtonEvent *) &event)->y;
4017 if (event.type == EVENT_BUTTONPRESS)
4018 button_status = ((ButtonEvent *) &event)->button;
4020 button_status = MB_RELEASED;
4023 /* this sets 'request_gadget_id' */
4024 HandleGadgets(mx, my, button_status);
4026 switch (request_gadget_id)
4028 case TOOL_CTRL_ID_YES:
4031 case TOOL_CTRL_ID_NO:
4034 case TOOL_CTRL_ID_CONFIRM:
4035 result = TRUE | FALSE;
4038 case TOOL_CTRL_ID_PLAYER_1:
4041 case TOOL_CTRL_ID_PLAYER_2:
4044 case TOOL_CTRL_ID_PLAYER_3:
4047 case TOOL_CTRL_ID_PLAYER_4:
4058 #if defined(TARGET_SDL2)
4059 case SDL_WINDOWEVENT:
4060 HandleWindowEvent((WindowEvent *) &event);
4063 case SDL_APP_WILLENTERBACKGROUND:
4064 case SDL_APP_DIDENTERBACKGROUND:
4065 case SDL_APP_WILLENTERFOREGROUND:
4066 case SDL_APP_DIDENTERFOREGROUND:
4067 HandlePauseResumeEvent((PauseResumeEvent *) &event);
4071 case EVENT_KEYPRESS:
4073 Key key = GetEventKey((KeyEvent *)&event, TRUE);
4078 if (req_state & REQ_CONFIRM)
4083 #if defined(TARGET_SDL2)
4086 #if defined(KSYM_Rewind)
4087 case KSYM_Rewind: /* for Amazon Fire TV remote */
4094 #if defined(TARGET_SDL2)
4096 #if defined(KSYM_FastForward)
4097 case KSYM_FastForward: /* for Amazon Fire TV remote */
4104 HandleKeysDebug(key);
4108 if (req_state & REQ_PLAYER)
4114 case EVENT_KEYRELEASE:
4115 ClearPlayerAction();
4118 #if defined(TARGET_SDL2)
4119 case SDL_CONTROLLERBUTTONDOWN:
4120 switch (event.cbutton.button)
4122 case SDL_CONTROLLER_BUTTON_A:
4123 case SDL_CONTROLLER_BUTTON_X:
4124 case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
4128 case SDL_CONTROLLER_BUTTON_B:
4129 case SDL_CONTROLLER_BUTTON_Y:
4130 case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
4131 case SDL_CONTROLLER_BUTTON_BACK:
4136 if (req_state & REQ_PLAYER)
4141 case SDL_CONTROLLERBUTTONUP:
4142 HandleJoystickEvent(&event);
4143 ClearPlayerAction();
4148 HandleOtherEvents(&event);
4153 else if (AnyJoystickButton() == JOY_BUTTON_NEW_PRESSED)
4155 int joy = AnyJoystick();
4157 if (joy & JOY_BUTTON_1)
4159 else if (joy & JOY_BUTTON_2)
4165 if (global.use_envelope_request)
4167 /* copy back current state of pressed buttons inside request area */
4168 BlitBitmap(drawto, bitmap_db_store_2, sx, sy, width, height, sx, sy);
4178 static boolean RequestDoor(char *text, unsigned int req_state)
4180 unsigned int old_door_state;
4181 int max_request_line_len = MAX_REQUEST_LINE_FONT1_LEN;
4182 int font_nr = FONT_TEXT_2;
4187 if (maxWordLengthInString(text) > MAX_REQUEST_LINE_FONT1_LEN)
4189 max_request_line_len = MAX_REQUEST_LINE_FONT2_LEN;
4190 font_nr = FONT_TEXT_1;
4193 if (game_status == GAME_MODE_PLAYING)
4194 BlitScreenToBitmap(backbuffer);
4196 /* disable deactivated drawing when quick-loading level tape recording */
4197 if (tape.playing && tape.deactivate_display)
4198 TapeDeactivateDisplayOff(TRUE);
4200 SetMouseCursor(CURSOR_DEFAULT);
4202 #if defined(NETWORK_AVALIABLE)
4203 /* pause network game while waiting for request to answer */
4204 if (options.network &&
4205 game_status == GAME_MODE_PLAYING &&
4206 req_state & REQUEST_WAIT_FOR_INPUT)
4207 SendToServer_PausePlaying();
4210 old_door_state = GetDoorState();
4212 /* simulate releasing mouse button over last gadget, if still pressed */
4214 HandleGadgets(-1, -1, 0);
4218 /* draw released gadget before proceeding */
4221 if (old_door_state & DOOR_OPEN_1)
4223 CloseDoor(DOOR_CLOSE_1);
4225 /* save old door content */
4226 BlitBitmap(bitmap_db_door_1, bitmap_db_door_1,
4227 0 * DXSIZE, 0, DXSIZE, DYSIZE, 1 * DXSIZE, 0);
4230 SetDoorBackgroundImage(IMG_BACKGROUND_DOOR);
4231 SetDrawBackgroundMask(REDRAW_FIELD | REDRAW_DOOR_1);
4233 /* clear door drawing field */
4234 DrawBackground(DX, DY, DXSIZE, DYSIZE);
4236 /* force DOOR font inside door area */
4237 SetFontStatus(GAME_MODE_PSEUDO_DOOR);
4239 /* write text for request */
4240 for (text_ptr = text, ty = 0; ty < MAX_REQUEST_LINES; ty++)
4242 char text_line[max_request_line_len + 1];
4248 for (tl = 0, tx = 0; tx < max_request_line_len; tl++, tx++)
4250 tc = *(text_ptr + tx);
4251 // if (!tc || tc == ' ')
4252 if (!tc || tc == ' ' || tc == '?' || tc == '!')
4256 if ((tc == '?' || tc == '!') && tl == 0)
4266 strncpy(text_line, text_ptr, tl);
4269 DrawText(DX + (DXSIZE - tl * getFontWidth(font_nr)) / 2,
4270 DY + 8 + ty * (getFontHeight(font_nr) + 2),
4271 text_line, font_nr);
4273 text_ptr += tl + (tc == ' ' ? 1 : 0);
4274 // text_ptr += tl + (tc == ' ' || tc == '?' || tc == '!' ? 1 : 0);
4279 if (req_state & REQ_ASK)
4281 MapGadget(tool_gadget[TOOL_CTRL_ID_YES]);
4282 MapGadget(tool_gadget[TOOL_CTRL_ID_NO]);
4284 else if (req_state & REQ_CONFIRM)
4286 MapGadget(tool_gadget[TOOL_CTRL_ID_CONFIRM]);
4288 else if (req_state & REQ_PLAYER)
4290 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_1]);
4291 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_2]);
4292 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_3]);
4293 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_4]);
4296 /* copy request gadgets to door backbuffer */
4297 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
4299 OpenDoor(DOOR_OPEN_1);
4301 if (!(req_state & REQUEST_WAIT_FOR_INPUT))
4303 if (game_status == GAME_MODE_PLAYING)
4305 SetPanelBackground();
4306 SetDrawBackgroundMask(REDRAW_DOOR_1);
4310 SetDrawBackgroundMask(REDRAW_FIELD);
4316 SetDrawBackgroundMask(REDRAW_FIELD | REDRAW_DOOR_1);
4318 // ---------- handle request buttons ----------
4319 result = RequestHandleEvents(req_state);
4323 if (!(req_state & REQ_STAY_OPEN))
4325 CloseDoor(DOOR_CLOSE_1);
4327 if (((old_door_state & DOOR_OPEN_1) && !(req_state & REQ_STAY_CLOSED)) ||
4328 (req_state & REQ_REOPEN))
4329 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
4334 if (game_status == GAME_MODE_PLAYING)
4336 SetPanelBackground();
4337 SetDrawBackgroundMask(REDRAW_DOOR_1);
4341 SetDrawBackgroundMask(REDRAW_FIELD);
4344 #if defined(NETWORK_AVALIABLE)
4345 /* continue network game after request */
4346 if (options.network &&
4347 game_status == GAME_MODE_PLAYING &&
4348 req_state & REQUEST_WAIT_FOR_INPUT)
4349 SendToServer_ContinuePlaying();
4352 /* restore deactivated drawing when quick-loading level tape recording */
4353 if (tape.playing && tape.deactivate_display)
4354 TapeDeactivateDisplayOn();
4359 static boolean RequestEnvelope(char *text, unsigned int req_state)
4363 if (game_status == GAME_MODE_PLAYING)
4364 BlitScreenToBitmap(backbuffer);
4366 /* disable deactivated drawing when quick-loading level tape recording */
4367 if (tape.playing && tape.deactivate_display)
4368 TapeDeactivateDisplayOff(TRUE);
4370 SetMouseCursor(CURSOR_DEFAULT);
4372 #if defined(NETWORK_AVALIABLE)
4373 /* pause network game while waiting for request to answer */
4374 if (options.network &&
4375 game_status == GAME_MODE_PLAYING &&
4376 req_state & REQUEST_WAIT_FOR_INPUT)
4377 SendToServer_PausePlaying();
4380 /* simulate releasing mouse button over last gadget, if still pressed */
4382 HandleGadgets(-1, -1, 0);
4386 // (replace with setting corresponding request background)
4387 // SetDoorBackgroundImage(IMG_BACKGROUND_DOOR);
4388 // SetDrawBackgroundMask(REDRAW_FIELD | REDRAW_DOOR_1);
4390 /* clear door drawing field */
4391 // DrawBackground(DX, DY, DXSIZE, DYSIZE);
4393 ShowEnvelopeRequest(text, req_state, ACTION_OPENING);
4395 if (!(req_state & REQUEST_WAIT_FOR_INPUT))
4397 if (game_status == GAME_MODE_PLAYING)
4399 SetPanelBackground();
4400 SetDrawBackgroundMask(REDRAW_DOOR_1);
4404 SetDrawBackgroundMask(REDRAW_FIELD);
4410 SetDrawBackgroundMask(REDRAW_FIELD | REDRAW_DOOR_1);
4412 // ---------- handle request buttons ----------
4413 result = RequestHandleEvents(req_state);
4417 ShowEnvelopeRequest(text, req_state, ACTION_CLOSING);
4421 if (game_status == GAME_MODE_PLAYING)
4423 SetPanelBackground();
4424 SetDrawBackgroundMask(REDRAW_DOOR_1);
4428 SetDrawBackgroundMask(REDRAW_FIELD);
4431 #if defined(NETWORK_AVALIABLE)
4432 /* continue network game after request */
4433 if (options.network &&
4434 game_status == GAME_MODE_PLAYING &&
4435 req_state & REQUEST_WAIT_FOR_INPUT)
4436 SendToServer_ContinuePlaying();
4439 /* restore deactivated drawing when quick-loading level tape recording */
4440 if (tape.playing && tape.deactivate_display)
4441 TapeDeactivateDisplayOn();
4446 boolean Request(char *text, unsigned int req_state)
4448 boolean overlay_active = GetOverlayActive();
4451 SetOverlayActive(FALSE);
4453 if (global.use_envelope_request)
4454 result = RequestEnvelope(text, req_state);
4456 result = RequestDoor(text, req_state);
4458 SetOverlayActive(overlay_active);
4463 static int compareDoorPartOrderInfo(const void *object1, const void *object2)
4465 const struct DoorPartOrderInfo *dpo1 = (struct DoorPartOrderInfo *)object1;
4466 const struct DoorPartOrderInfo *dpo2 = (struct DoorPartOrderInfo *)object2;
4469 if (dpo1->sort_priority != dpo2->sort_priority)
4470 compare_result = dpo1->sort_priority - dpo2->sort_priority;
4472 compare_result = dpo1->nr - dpo2->nr;
4474 return compare_result;
4477 void InitGraphicCompatibilityInfo_Doors()
4483 struct DoorInfo *door;
4487 { DOOR_1, IMG_GFX_DOOR_1_PART_1, IMG_GFX_DOOR_1_PART_8, &door_1 },
4488 { DOOR_2, IMG_GFX_DOOR_2_PART_1, IMG_GFX_DOOR_2_PART_8, &door_2 },
4490 { -1, -1, -1, NULL }
4492 struct Rect door_rect_list[] =
4494 { DX, DY, DXSIZE, DYSIZE },
4495 { VX, VY, VXSIZE, VYSIZE }
4499 for (i = 0; doors[i].door_token != -1; i++)
4501 int door_token = doors[i].door_token;
4502 int door_index = DOOR_INDEX_FROM_TOKEN(door_token);
4503 int part_1 = doors[i].part_1;
4504 int part_8 = doors[i].part_8;
4505 int part_2 = part_1 + 1;
4506 int part_3 = part_1 + 2;
4507 struct DoorInfo *door = doors[i].door;
4508 struct Rect *door_rect = &door_rect_list[door_index];
4509 boolean door_gfx_redefined = FALSE;
4511 /* check if any door part graphic definitions have been redefined */
4513 for (j = 0; door_part_controls[j].door_token != -1; j++)
4515 struct DoorPartControlInfo *dpc = &door_part_controls[j];
4516 struct FileInfo *fi = getImageListEntryFromImageID(dpc->graphic);
4518 if (dpc->door_token == door_token && fi->redefined)
4519 door_gfx_redefined = TRUE;
4522 /* check for old-style door graphic/animation modifications */
4524 if (!door_gfx_redefined)
4526 if (door->anim_mode & ANIM_STATIC_PANEL)
4528 door->panel.step_xoffset = 0;
4529 door->panel.step_yoffset = 0;
4532 if (door->anim_mode & (ANIM_HORIZONTAL | ANIM_VERTICAL))
4534 struct GraphicInfo *g_part_1 = &graphic_info[part_1];
4535 struct GraphicInfo *g_part_2 = &graphic_info[part_2];
4536 int num_door_steps, num_panel_steps;
4538 /* remove door part graphics other than the two default wings */
4540 for (j = 0; door_part_controls[j].door_token != -1; j++)
4542 struct DoorPartControlInfo *dpc = &door_part_controls[j];
4543 struct GraphicInfo *g = &graphic_info[dpc->graphic];
4545 if (dpc->graphic >= part_3 &&
4546 dpc->graphic <= part_8)
4550 /* set graphics and screen positions of the default wings */
4552 g_part_1->width = door_rect->width;
4553 g_part_1->height = door_rect->height;
4554 g_part_2->width = door_rect->width;
4555 g_part_2->height = door_rect->height;
4556 g_part_2->src_x = door_rect->width;
4557 g_part_2->src_y = g_part_1->src_y;
4559 door->part_2.x = door->part_1.x;
4560 door->part_2.y = door->part_1.y;
4562 if (door->width != -1)
4564 g_part_1->width = door->width;
4565 g_part_2->width = door->width;
4567 // special treatment for graphics and screen position of right wing
4568 g_part_2->src_x += door_rect->width - door->width;
4569 door->part_2.x += door_rect->width - door->width;
4572 if (door->height != -1)
4574 g_part_1->height = door->height;
4575 g_part_2->height = door->height;
4577 // special treatment for graphics and screen position of bottom wing
4578 g_part_2->src_y += door_rect->height - door->height;
4579 door->part_2.y += door_rect->height - door->height;
4582 /* set animation delays for the default wings and panels */
4584 door->part_1.step_delay = door->step_delay;
4585 door->part_2.step_delay = door->step_delay;
4586 door->panel.step_delay = door->step_delay;
4588 /* set animation draw order for the default wings */
4590 door->part_1.sort_priority = 2; /* draw left wing over ... */
4591 door->part_2.sort_priority = 1; /* ... right wing */
4593 /* set animation draw offset for the default wings */
4595 if (door->anim_mode & ANIM_HORIZONTAL)
4597 door->part_1.step_xoffset = door->step_offset;
4598 door->part_1.step_yoffset = 0;
4599 door->part_2.step_xoffset = door->step_offset * -1;
4600 door->part_2.step_yoffset = 0;
4602 num_door_steps = g_part_1->width / door->step_offset;
4604 else // ANIM_VERTICAL
4606 door->part_1.step_xoffset = 0;
4607 door->part_1.step_yoffset = door->step_offset;
4608 door->part_2.step_xoffset = 0;
4609 door->part_2.step_yoffset = door->step_offset * -1;
4611 num_door_steps = g_part_1->height / door->step_offset;
4614 /* set animation draw offset for the default panels */
4616 if (door->step_offset > 1)
4618 num_panel_steps = 2 * door_rect->height / door->step_offset;
4619 door->panel.start_step = num_panel_steps - num_door_steps;
4620 door->panel.start_step_closing = door->panel.start_step;
4624 num_panel_steps = door_rect->height / door->step_offset;
4625 door->panel.start_step = num_panel_steps - num_door_steps / 2;
4626 door->panel.start_step_closing = door->panel.start_step;
4627 door->panel.step_delay *= 2;
4638 for (i = 0; door_part_controls[i].door_token != -1; i++)
4640 struct DoorPartControlInfo *dpc = &door_part_controls[i];
4641 struct DoorPartOrderInfo *dpo = &door_part_order[i];
4643 /* initialize "start_step_opening" and "start_step_closing", if needed */
4644 if (dpc->pos->start_step_opening == 0 &&
4645 dpc->pos->start_step_closing == 0)
4647 // dpc->pos->start_step_opening = dpc->pos->start_step;
4648 dpc->pos->start_step_closing = dpc->pos->start_step;
4651 /* fill structure for door part draw order (sorted below) */
4653 dpo->sort_priority = dpc->pos->sort_priority;
4656 /* sort door part controls according to sort_priority and graphic number */
4657 qsort(door_part_order, MAX_DOOR_PARTS,
4658 sizeof(struct DoorPartOrderInfo), compareDoorPartOrderInfo);
4661 unsigned int OpenDoor(unsigned int door_state)
4663 if (door_state & DOOR_COPY_BACK)
4665 if (door_state & DOOR_OPEN_1)
4666 BlitBitmap(bitmap_db_door_1, bitmap_db_door_1,
4667 1 * DXSIZE, 0, DXSIZE, DYSIZE, 0 * DXSIZE, 0);
4669 if (door_state & DOOR_OPEN_2)
4670 BlitBitmap(bitmap_db_door_2, bitmap_db_door_2,
4671 1 * VXSIZE, 0, VXSIZE, VYSIZE, 0 * VXSIZE, 0);
4673 door_state &= ~DOOR_COPY_BACK;
4676 return MoveDoor(door_state);
4679 unsigned int CloseDoor(unsigned int door_state)
4681 unsigned int old_door_state = GetDoorState();
4683 if (!(door_state & DOOR_NO_COPY_BACK))
4685 if (old_door_state & DOOR_OPEN_1)
4686 BlitBitmap(backbuffer, bitmap_db_door_1,
4687 DX, DY, DXSIZE, DYSIZE, 0, 0);
4689 if (old_door_state & DOOR_OPEN_2)
4690 BlitBitmap(backbuffer, bitmap_db_door_2,
4691 VX, VY, VXSIZE, VYSIZE, 0, 0);
4693 door_state &= ~DOOR_NO_COPY_BACK;
4696 return MoveDoor(door_state);
4699 unsigned int GetDoorState()
4701 return MoveDoor(DOOR_GET_STATE);
4704 unsigned int SetDoorState(unsigned int door_state)
4706 return MoveDoor(door_state | DOOR_SET_STATE);
4709 int euclid(int a, int b)
4711 return (b ? euclid(b, a % b) : a);
4714 unsigned int MoveDoor(unsigned int door_state)
4716 struct Rect door_rect_list[] =
4718 { DX, DY, DXSIZE, DYSIZE },
4719 { VX, VY, VXSIZE, VYSIZE }
4721 static int door1 = DOOR_CLOSE_1;
4722 static int door2 = DOOR_CLOSE_2;
4723 unsigned int door_delay = 0;
4724 unsigned int door_delay_value;
4727 if (door_state == DOOR_GET_STATE)
4728 return (door1 | door2);
4730 if (door_state & DOOR_SET_STATE)
4732 if (door_state & DOOR_ACTION_1)
4733 door1 = door_state & DOOR_ACTION_1;
4734 if (door_state & DOOR_ACTION_2)
4735 door2 = door_state & DOOR_ACTION_2;
4737 return (door1 | door2);
4740 if (!(door_state & DOOR_FORCE_REDRAW))
4742 if (door1 == DOOR_OPEN_1 && door_state & DOOR_OPEN_1)
4743 door_state &= ~DOOR_OPEN_1;
4744 else if (door1 == DOOR_CLOSE_1 && door_state & DOOR_CLOSE_1)
4745 door_state &= ~DOOR_CLOSE_1;
4746 if (door2 == DOOR_OPEN_2 && door_state & DOOR_OPEN_2)
4747 door_state &= ~DOOR_OPEN_2;
4748 else if (door2 == DOOR_CLOSE_2 && door_state & DOOR_CLOSE_2)
4749 door_state &= ~DOOR_CLOSE_2;
4752 if (global.autoplay_leveldir)
4754 door_state |= DOOR_NO_DELAY;
4755 door_state &= ~DOOR_CLOSE_ALL;
4758 if (game_status == GAME_MODE_EDITOR)
4759 door_state |= DOOR_NO_DELAY;
4761 if (door_state & DOOR_ACTION)
4763 boolean door_panel_drawn[NUM_DOORS];
4764 boolean panel_has_doors[NUM_DOORS];
4765 boolean door_part_skip[MAX_DOOR_PARTS];
4766 boolean door_part_done[MAX_DOOR_PARTS];
4767 boolean door_part_done_all;
4768 int num_steps[MAX_DOOR_PARTS];
4769 int max_move_delay = 0; // delay for complete animations of all doors
4770 int max_step_delay = 0; // delay (ms) between two animation frames
4771 int num_move_steps = 0; // number of animation steps for all doors
4772 int max_move_delay_doors_only = 0; // delay for doors only (no panel)
4773 int num_move_steps_doors_only = 0; // steps for doors only (no panel)
4774 int current_move_delay = 0;
4778 for (i = 0; i < NUM_DOORS; i++)
4779 panel_has_doors[i] = FALSE;
4781 for (i = 0; i < MAX_DOOR_PARTS; i++)
4783 struct DoorPartControlInfo *dpc = &door_part_controls[i];
4784 struct GraphicInfo *g = &graphic_info[dpc->graphic];
4785 int door_token = dpc->door_token;
4787 door_part_done[i] = FALSE;
4788 door_part_skip[i] = (!(door_state & door_token) ||
4792 for (i = 0; i < MAX_DOOR_PARTS; i++)
4794 int nr = door_part_order[i].nr;
4795 struct DoorPartControlInfo *dpc = &door_part_controls[nr];
4796 struct DoorPartPosInfo *pos = dpc->pos;
4797 struct GraphicInfo *g = &graphic_info[dpc->graphic];
4798 int door_token = dpc->door_token;
4799 int door_index = DOOR_INDEX_FROM_TOKEN(door_token);
4800 boolean is_panel = DOOR_PART_IS_PANEL(nr);
4801 int step_xoffset = ABS(pos->step_xoffset);
4802 int step_yoffset = ABS(pos->step_yoffset);
4803 int step_delay = pos->step_delay;
4804 int current_door_state = door_state & door_token;
4805 boolean door_opening = ((current_door_state & DOOR_OPEN) != 0);
4806 boolean door_closing = ((current_door_state & DOOR_CLOSE) != 0);
4807 boolean part_opening = (is_panel ? door_closing : door_opening);
4808 int start_step = (part_opening ? pos->start_step_opening :
4809 pos->start_step_closing);
4810 float move_xsize = (step_xoffset ? g->width : 0);
4811 float move_ysize = (step_yoffset ? g->height : 0);
4812 int move_xsteps = (step_xoffset ? ceil(move_xsize / step_xoffset) : 0);
4813 int move_ysteps = (step_yoffset ? ceil(move_ysize / step_yoffset) : 0);
4814 int move_steps = (move_xsteps && move_ysteps ?
4815 MIN(move_xsteps, move_ysteps) :
4816 move_xsteps ? move_xsteps : move_ysteps) - start_step;
4817 int move_delay = move_steps * step_delay;
4819 if (door_part_skip[nr])
4822 max_move_delay = MAX(max_move_delay, move_delay);
4823 max_step_delay = (max_step_delay == 0 ? step_delay :
4824 euclid(max_step_delay, step_delay));
4825 num_steps[nr] = move_steps;
4829 max_move_delay_doors_only = MAX(max_move_delay_doors_only, move_delay);
4831 panel_has_doors[door_index] = TRUE;
4835 max_step_delay = MAX(1, max_step_delay); // prevent division by zero
4837 num_move_steps = max_move_delay / max_step_delay;
4838 num_move_steps_doors_only = max_move_delay_doors_only / max_step_delay;
4840 door_delay_value = max_step_delay;
4842 if ((door_state & DOOR_NO_DELAY) || setup.quick_doors)
4844 start = num_move_steps - 1;
4848 /* opening door sound has priority over simultaneously closing door */
4849 if (door_state & (DOOR_OPEN_1 | DOOR_OPEN_2))
4850 PlayMenuSoundStereo(SND_DOOR_OPENING, SOUND_MIDDLE);
4851 else if (door_state & (DOOR_CLOSE_1 | DOOR_CLOSE_2))
4852 PlayMenuSoundStereo(SND_DOOR_CLOSING, SOUND_MIDDLE);
4855 for (k = start; k < num_move_steps; k++)
4857 int last_frame = num_move_steps - 1; // last frame of this "for" loop
4859 door_part_done_all = TRUE;
4861 for (i = 0; i < NUM_DOORS; i++)
4862 door_panel_drawn[i] = FALSE;
4864 for (i = 0; i < MAX_DOOR_PARTS; i++)
4866 int nr = door_part_order[i].nr;
4867 struct DoorPartControlInfo *dpc = &door_part_controls[nr];
4868 struct DoorPartPosInfo *pos = dpc->pos;
4869 struct GraphicInfo *g = &graphic_info[dpc->graphic];
4870 int door_token = dpc->door_token;
4871 int door_index = DOOR_INDEX_FROM_TOKEN(door_token);
4872 boolean is_panel = DOOR_PART_IS_PANEL(nr);
4873 boolean is_panel_and_door_has_closed = FALSE;
4874 struct Rect *door_rect = &door_rect_list[door_index];
4875 Bitmap *bitmap_db_door = (door_token == DOOR_1 ? bitmap_db_door_1 :
4877 Bitmap *bitmap = (is_panel ? bitmap_db_door : g->bitmap);
4878 int current_door_state = door_state & door_token;
4879 boolean door_opening = ((current_door_state & DOOR_OPEN) != 0);
4880 boolean door_closing = !door_opening;
4881 boolean part_opening = (is_panel ? door_closing : door_opening);
4882 boolean part_closing = !part_opening;
4883 int start_step = (part_opening ? pos->start_step_opening :
4884 pos->start_step_closing);
4885 int step_delay = pos->step_delay;
4886 int step_factor = step_delay / max_step_delay;
4887 int k1 = (step_factor ? k / step_factor + 1 : k);
4888 int k2 = (part_opening ? k1 + start_step : num_steps[nr] - k1);
4889 int kk = MAX(0, k2);
4892 int src_x, src_y, src_xx, src_yy;
4893 int dst_x, dst_y, dst_xx, dst_yy;
4896 if (door_part_skip[nr])
4899 if (!(door_state & door_token))
4907 int k2_door = (door_opening ? k : num_move_steps_doors_only - k - 1);
4908 int kk_door = MAX(0, k2_door);
4909 int sync_frame = kk_door * door_delay_value;
4910 int frame = getGraphicAnimationFrame(dpc->graphic, sync_frame);
4912 getFixedGraphicSource(dpc->graphic, frame, &bitmap,
4913 &g_src_x, &g_src_y);
4918 if (!door_panel_drawn[door_index])
4920 ClearRectangle(drawto, door_rect->x, door_rect->y,
4921 door_rect->width, door_rect->height);
4923 door_panel_drawn[door_index] = TRUE;
4926 // draw opening or closing door parts
4928 if (pos->step_xoffset < 0) // door part on right side
4931 dst_xx = pos->x + ABS(kk * pos->step_xoffset);
4934 if (dst_xx + width > door_rect->width)
4935 width = door_rect->width - dst_xx;
4937 else // door part on left side
4940 dst_xx = pos->x - kk * pos->step_xoffset;
4944 src_xx = ABS(dst_xx);
4948 width = g->width - src_xx;
4950 if (width > door_rect->width)
4951 width = door_rect->width;
4953 // printf("::: k == %d [%d] \n", k, start_step);
4956 if (pos->step_yoffset < 0) // door part on bottom side
4959 dst_yy = pos->y + ABS(kk * pos->step_yoffset);
4962 if (dst_yy + height > door_rect->height)
4963 height = door_rect->height - dst_yy;
4965 else // door part on top side
4968 dst_yy = pos->y - kk * pos->step_yoffset;
4972 src_yy = ABS(dst_yy);
4976 height = g->height - src_yy;
4979 src_x = g_src_x + src_xx;
4980 src_y = g_src_y + src_yy;
4982 dst_x = door_rect->x + dst_xx;
4983 dst_y = door_rect->y + dst_yy;
4985 is_panel_and_door_has_closed =
4988 panel_has_doors[door_index] &&
4989 k >= num_move_steps_doors_only - 1);
4991 if (width >= 0 && width <= g->width &&
4992 height >= 0 && height <= g->height &&
4993 !is_panel_and_door_has_closed)
4995 if (is_panel || !pos->draw_masked)
4996 BlitBitmap(bitmap, drawto, src_x, src_y, width, height,
4999 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height,
5003 redraw_mask |= REDRAW_DOOR_FROM_TOKEN(door_token);
5005 if ((part_opening && (width < 0 || height < 0)) ||
5006 (part_closing && (width >= g->width && height >= g->height)))
5007 door_part_done[nr] = TRUE;
5009 // continue door part animations, but not panel after door has closed
5010 if (!door_part_done[nr] && !is_panel_and_door_has_closed)
5011 door_part_done_all = FALSE;
5014 if (!(door_state & DOOR_NO_DELAY))
5018 SkipUntilDelayReached(&door_delay, door_delay_value, &k, last_frame);
5020 current_move_delay += max_step_delay;
5022 /* prevent OS (Windows) from complaining about program not responding */
5026 if (door_part_done_all)
5031 if (door_state & DOOR_ACTION_1)
5032 door1 = door_state & DOOR_ACTION_1;
5033 if (door_state & DOOR_ACTION_2)
5034 door2 = door_state & DOOR_ACTION_2;
5036 // draw masked border over door area
5037 DrawMaskedBorder(REDRAW_DOOR_1);
5038 DrawMaskedBorder(REDRAW_DOOR_2);
5040 return (door1 | door2);
5043 static boolean useSpecialEditorDoor()
5045 int graphic = IMG_GLOBAL_BORDER_EDITOR;
5046 boolean redefined = getImageListEntryFromImageID(graphic)->redefined;
5048 // do not draw special editor door if editor border defined or redefined
5049 if (graphic_info[graphic].bitmap != NULL || redefined)
5052 // do not draw special editor door if global border defined to be empty
5053 if (graphic_info[IMG_GLOBAL_BORDER].bitmap == NULL)
5056 // do not draw special editor door if viewport definitions do not match
5060 EY + EYSIZE != VY + VYSIZE)
5066 void DrawSpecialEditorDoor()
5068 struct GraphicInfo *gfx1 = &graphic_info[IMG_DOOR_2_TOP_BORDER_CORRECTION];
5069 int top_border_width = gfx1->width;
5070 int top_border_height = gfx1->height;
5071 int outer_border = viewport.door_2[GAME_MODE_EDITOR].border_size;
5072 int ex = EX - outer_border;
5073 int ey = EY - outer_border;
5074 int vy = VY - outer_border;
5075 int exsize = EXSIZE + 2 * outer_border;
5077 if (!useSpecialEditorDoor())
5080 /* draw bigger level editor toolbox window */
5081 BlitBitmap(gfx1->bitmap, drawto, gfx1->src_x, gfx1->src_y,
5082 top_border_width, top_border_height, ex, ey - top_border_height);
5083 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, drawto, ex, vy,
5084 exsize, EYSIZE - VYSIZE + outer_border, ex, ey);
5086 redraw_mask |= REDRAW_ALL;
5089 void UndrawSpecialEditorDoor()
5091 struct GraphicInfo *gfx1 = &graphic_info[IMG_DOOR_2_TOP_BORDER_CORRECTION];
5092 int top_border_width = gfx1->width;
5093 int top_border_height = gfx1->height;
5094 int outer_border = viewport.door_2[GAME_MODE_EDITOR].border_size;
5095 int ex = EX - outer_border;
5096 int ey = EY - outer_border;
5097 int ey_top = ey - top_border_height;
5098 int exsize = EXSIZE + 2 * outer_border;
5099 int eysize = EYSIZE + 2 * outer_border;
5101 if (!useSpecialEditorDoor())
5104 /* draw normal tape recorder window */
5105 if (graphic_info[IMG_GLOBAL_BORDER].bitmap)
5107 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, drawto,
5108 ex, ey_top, top_border_width, top_border_height,
5110 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, drawto,
5111 ex, ey, exsize, eysize, ex, ey);
5115 // if screen background is set to "[NONE]", clear editor toolbox window
5116 ClearRectangle(drawto, ex, ey_top, top_border_width, top_border_height);
5117 ClearRectangle(drawto, ex, ey, exsize, eysize);
5120 redraw_mask |= REDRAW_ALL;
5124 /* ---------- new tool button stuff ---------------------------------------- */
5129 struct TextPosInfo *pos;
5132 } toolbutton_info[NUM_TOOL_BUTTONS] =
5135 IMG_GFX_REQUEST_BUTTON_YES, &request.button.yes,
5136 TOOL_CTRL_ID_YES, "yes"
5139 IMG_GFX_REQUEST_BUTTON_NO, &request.button.no,
5140 TOOL_CTRL_ID_NO, "no"
5143 IMG_GFX_REQUEST_BUTTON_CONFIRM, &request.button.confirm,
5144 TOOL_CTRL_ID_CONFIRM, "confirm"
5147 IMG_GFX_REQUEST_BUTTON_PLAYER_1, &request.button.player_1,
5148 TOOL_CTRL_ID_PLAYER_1, "player 1"
5151 IMG_GFX_REQUEST_BUTTON_PLAYER_2, &request.button.player_2,
5152 TOOL_CTRL_ID_PLAYER_2, "player 2"
5155 IMG_GFX_REQUEST_BUTTON_PLAYER_3, &request.button.player_3,
5156 TOOL_CTRL_ID_PLAYER_3, "player 3"
5159 IMG_GFX_REQUEST_BUTTON_PLAYER_4, &request.button.player_4,
5160 TOOL_CTRL_ID_PLAYER_4, "player 4"
5164 void CreateToolButtons()
5168 for (i = 0; i < NUM_TOOL_BUTTONS; i++)
5170 struct GraphicInfo *gfx = &graphic_info[toolbutton_info[i].graphic];
5171 struct TextPosInfo *pos = toolbutton_info[i].pos;
5172 struct GadgetInfo *gi;
5173 Bitmap *deco_bitmap = None;
5174 int deco_x = 0, deco_y = 0, deco_xpos = 0, deco_ypos = 0;
5175 unsigned int event_mask = GD_EVENT_RELEASED;
5178 int gd_x = gfx->src_x;
5179 int gd_y = gfx->src_y;
5180 int gd_xp = gfx->src_x + gfx->pressed_xoffset;
5181 int gd_yp = gfx->src_y + gfx->pressed_yoffset;
5184 if (global.use_envelope_request)
5185 setRequestPosition(&dx, &dy, TRUE);
5187 if (id >= TOOL_CTRL_ID_PLAYER_1 && id <= TOOL_CTRL_ID_PLAYER_4)
5189 int player_nr = id - TOOL_CTRL_ID_PLAYER_1;
5191 getSizedGraphicSource(PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0,
5192 pos->size, &deco_bitmap, &deco_x, &deco_y);
5193 deco_xpos = (gfx->width - pos->size) / 2;
5194 deco_ypos = (gfx->height - pos->size) / 2;
5197 gi = CreateGadget(GDI_CUSTOM_ID, id,
5198 GDI_INFO_TEXT, toolbutton_info[i].infotext,
5199 GDI_X, dx + GDI_ACTIVE_POS(pos->x),
5200 GDI_Y, dy + GDI_ACTIVE_POS(pos->y),
5201 GDI_WIDTH, gfx->width,
5202 GDI_HEIGHT, gfx->height,
5203 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5204 GDI_STATE, GD_BUTTON_UNPRESSED,
5205 GDI_DESIGN_UNPRESSED, gfx->bitmap, gd_x, gd_y,
5206 GDI_DESIGN_PRESSED, gfx->bitmap, gd_xp, gd_yp,
5207 GDI_DECORATION_DESIGN, deco_bitmap, deco_x, deco_y,
5208 GDI_DECORATION_POSITION, deco_xpos, deco_ypos,
5209 GDI_DECORATION_SIZE, pos->size, pos->size,
5210 GDI_DECORATION_SHIFTING, 1, 1,
5211 GDI_DIRECT_DRAW, FALSE,
5212 GDI_EVENT_MASK, event_mask,
5213 GDI_CALLBACK_ACTION, HandleToolButtons,
5217 Error(ERR_EXIT, "cannot create gadget");
5219 tool_gadget[id] = gi;
5223 void FreeToolButtons()
5227 for (i = 0; i < NUM_TOOL_BUTTONS; i++)
5228 FreeGadget(tool_gadget[i]);
5231 static void UnmapToolButtons()
5235 for (i = 0; i < NUM_TOOL_BUTTONS; i++)
5236 UnmapGadget(tool_gadget[i]);
5239 static void HandleToolButtons(struct GadgetInfo *gi)
5241 request_gadget_id = gi->custom_id;
5244 static struct Mapping_EM_to_RND_object
5247 boolean is_rnd_to_em_mapping; /* unique mapping EM <-> RND */
5248 boolean is_backside; /* backside of moving element */
5254 em_object_mapping_list[] =
5257 Xblank, TRUE, FALSE,
5261 Yacid_splash_eB, FALSE, FALSE,
5262 EL_ACID_SPLASH_RIGHT, -1, -1
5265 Yacid_splash_wB, FALSE, FALSE,
5266 EL_ACID_SPLASH_LEFT, -1, -1
5269 #ifdef EM_ENGINE_BAD_ROLL
5271 Xstone_force_e, FALSE, FALSE,
5272 EL_ROCK, -1, MV_BIT_RIGHT
5275 Xstone_force_w, FALSE, FALSE,
5276 EL_ROCK, -1, MV_BIT_LEFT
5279 Xnut_force_e, FALSE, FALSE,
5280 EL_NUT, -1, MV_BIT_RIGHT
5283 Xnut_force_w, FALSE, FALSE,
5284 EL_NUT, -1, MV_BIT_LEFT
5287 Xspring_force_e, FALSE, FALSE,
5288 EL_SPRING, -1, MV_BIT_RIGHT
5291 Xspring_force_w, FALSE, FALSE,
5292 EL_SPRING, -1, MV_BIT_LEFT
5295 Xemerald_force_e, FALSE, FALSE,
5296 EL_EMERALD, -1, MV_BIT_RIGHT
5299 Xemerald_force_w, FALSE, FALSE,
5300 EL_EMERALD, -1, MV_BIT_LEFT
5303 Xdiamond_force_e, FALSE, FALSE,
5304 EL_DIAMOND, -1, MV_BIT_RIGHT
5307 Xdiamond_force_w, FALSE, FALSE,
5308 EL_DIAMOND, -1, MV_BIT_LEFT
5311 Xbomb_force_e, FALSE, FALSE,
5312 EL_BOMB, -1, MV_BIT_RIGHT
5315 Xbomb_force_w, FALSE, FALSE,
5316 EL_BOMB, -1, MV_BIT_LEFT
5318 #endif /* EM_ENGINE_BAD_ROLL */
5321 Xstone, TRUE, FALSE,
5325 Xstone_pause, FALSE, FALSE,
5329 Xstone_fall, FALSE, FALSE,
5333 Ystone_s, FALSE, FALSE,
5334 EL_ROCK, ACTION_FALLING, -1
5337 Ystone_sB, FALSE, TRUE,
5338 EL_ROCK, ACTION_FALLING, -1
5341 Ystone_e, FALSE, FALSE,
5342 EL_ROCK, ACTION_MOVING, MV_BIT_RIGHT
5345 Ystone_eB, FALSE, TRUE,
5346 EL_ROCK, ACTION_MOVING, MV_BIT_RIGHT
5349 Ystone_w, FALSE, FALSE,
5350 EL_ROCK, ACTION_MOVING, MV_BIT_LEFT
5353 Ystone_wB, FALSE, TRUE,
5354 EL_ROCK, ACTION_MOVING, MV_BIT_LEFT
5361 Xnut_pause, FALSE, FALSE,
5365 Xnut_fall, FALSE, FALSE,
5369 Ynut_s, FALSE, FALSE,
5370 EL_NUT, ACTION_FALLING, -1
5373 Ynut_sB, FALSE, TRUE,
5374 EL_NUT, ACTION_FALLING, -1
5377 Ynut_e, FALSE, FALSE,
5378 EL_NUT, ACTION_MOVING, MV_BIT_RIGHT
5381 Ynut_eB, FALSE, TRUE,
5382 EL_NUT, ACTION_MOVING, MV_BIT_RIGHT
5385 Ynut_w, FALSE, FALSE,
5386 EL_NUT, ACTION_MOVING, MV_BIT_LEFT
5389 Ynut_wB, FALSE, TRUE,
5390 EL_NUT, ACTION_MOVING, MV_BIT_LEFT
5393 Xbug_n, TRUE, FALSE,
5397 Xbug_e, TRUE, FALSE,
5398 EL_BUG_RIGHT, -1, -1
5401 Xbug_s, TRUE, FALSE,
5405 Xbug_w, TRUE, FALSE,
5409 Xbug_gon, FALSE, FALSE,
5413 Xbug_goe, FALSE, FALSE,
5414 EL_BUG_RIGHT, -1, -1
5417 Xbug_gos, FALSE, FALSE,
5421 Xbug_gow, FALSE, FALSE,
5425 Ybug_n, FALSE, FALSE,
5426 EL_BUG, ACTION_MOVING, MV_BIT_UP
5429 Ybug_nB, FALSE, TRUE,
5430 EL_BUG, ACTION_MOVING, MV_BIT_UP
5433 Ybug_e, FALSE, FALSE,
5434 EL_BUG, ACTION_MOVING, MV_BIT_RIGHT
5437 Ybug_eB, FALSE, TRUE,
5438 EL_BUG, ACTION_MOVING, MV_BIT_RIGHT
5441 Ybug_s, FALSE, FALSE,
5442 EL_BUG, ACTION_MOVING, MV_BIT_DOWN
5445 Ybug_sB, FALSE, TRUE,
5446 EL_BUG, ACTION_MOVING, MV_BIT_DOWN
5449 Ybug_w, FALSE, FALSE,
5450 EL_BUG, ACTION_MOVING, MV_BIT_LEFT
5453 Ybug_wB, FALSE, TRUE,
5454 EL_BUG, ACTION_MOVING, MV_BIT_LEFT
5457 Ybug_w_n, FALSE, FALSE,
5458 EL_BUG, ACTION_TURNING_FROM_LEFT, MV_BIT_UP
5461 Ybug_n_e, FALSE, FALSE,
5462 EL_BUG, ACTION_TURNING_FROM_UP, MV_BIT_RIGHT
5465 Ybug_e_s, FALSE, FALSE,
5466 EL_BUG, ACTION_TURNING_FROM_RIGHT, MV_BIT_DOWN
5469 Ybug_s_w, FALSE, FALSE,
5470 EL_BUG, ACTION_TURNING_FROM_DOWN, MV_BIT_LEFT
5473 Ybug_e_n, FALSE, FALSE,
5474 EL_BUG, ACTION_TURNING_FROM_RIGHT, MV_BIT_UP
5477 Ybug_s_e, FALSE, FALSE,
5478 EL_BUG, ACTION_TURNING_FROM_DOWN, MV_BIT_RIGHT
5481 Ybug_w_s, FALSE, FALSE,
5482 EL_BUG, ACTION_TURNING_FROM_LEFT, MV_BIT_DOWN
5485 Ybug_n_w, FALSE, FALSE,
5486 EL_BUG, ACTION_TURNING_FROM_UP, MV_BIT_LEFT
5489 Ybug_stone, FALSE, FALSE,
5490 EL_BUG, ACTION_SMASHED_BY_ROCK, -1
5493 Ybug_spring, FALSE, FALSE,
5494 EL_BUG, ACTION_SMASHED_BY_SPRING, -1
5497 Xtank_n, TRUE, FALSE,
5498 EL_SPACESHIP_UP, -1, -1
5501 Xtank_e, TRUE, FALSE,
5502 EL_SPACESHIP_RIGHT, -1, -1
5505 Xtank_s, TRUE, FALSE,
5506 EL_SPACESHIP_DOWN, -1, -1
5509 Xtank_w, TRUE, FALSE,
5510 EL_SPACESHIP_LEFT, -1, -1
5513 Xtank_gon, FALSE, FALSE,
5514 EL_SPACESHIP_UP, -1, -1
5517 Xtank_goe, FALSE, FALSE,
5518 EL_SPACESHIP_RIGHT, -1, -1
5521 Xtank_gos, FALSE, FALSE,
5522 EL_SPACESHIP_DOWN, -1, -1
5525 Xtank_gow, FALSE, FALSE,
5526 EL_SPACESHIP_LEFT, -1, -1
5529 Ytank_n, FALSE, FALSE,
5530 EL_SPACESHIP, ACTION_MOVING, MV_BIT_UP
5533 Ytank_nB, FALSE, TRUE,
5534 EL_SPACESHIP, ACTION_MOVING, MV_BIT_UP
5537 Ytank_e, FALSE, FALSE,
5538 EL_SPACESHIP, ACTION_MOVING, MV_BIT_RIGHT
5541 Ytank_eB, FALSE, TRUE,
5542 EL_SPACESHIP, ACTION_MOVING, MV_BIT_RIGHT
5545 Ytank_s, FALSE, FALSE,
5546 EL_SPACESHIP, ACTION_MOVING, MV_BIT_DOWN
5549 Ytank_sB, FALSE, TRUE,
5550 EL_SPACESHIP, ACTION_MOVING, MV_BIT_DOWN
5553 Ytank_w, FALSE, FALSE,
5554 EL_SPACESHIP, ACTION_MOVING, MV_BIT_LEFT
5557 Ytank_wB, FALSE, TRUE,
5558 EL_SPACESHIP, ACTION_MOVING, MV_BIT_LEFT
5561 Ytank_w_n, FALSE, FALSE,
5562 EL_SPACESHIP, ACTION_TURNING_FROM_LEFT, MV_BIT_UP
5565 Ytank_n_e, FALSE, FALSE,
5566 EL_SPACESHIP, ACTION_TURNING_FROM_UP, MV_BIT_RIGHT
5569 Ytank_e_s, FALSE, FALSE,
5570 EL_SPACESHIP, ACTION_TURNING_FROM_RIGHT, MV_BIT_DOWN
5573 Ytank_s_w, FALSE, FALSE,
5574 EL_SPACESHIP, ACTION_TURNING_FROM_DOWN, MV_BIT_LEFT
5577 Ytank_e_n, FALSE, FALSE,
5578 EL_SPACESHIP, ACTION_TURNING_FROM_RIGHT, MV_BIT_UP
5581 Ytank_s_e, FALSE, FALSE,
5582 EL_SPACESHIP, ACTION_TURNING_FROM_DOWN, MV_BIT_RIGHT
5585 Ytank_w_s, FALSE, FALSE,
5586 EL_SPACESHIP, ACTION_TURNING_FROM_LEFT, MV_BIT_DOWN
5589 Ytank_n_w, FALSE, FALSE,
5590 EL_SPACESHIP, ACTION_TURNING_FROM_UP, MV_BIT_LEFT
5593 Ytank_stone, FALSE, FALSE,
5594 EL_SPACESHIP, ACTION_SMASHED_BY_ROCK, -1
5597 Ytank_spring, FALSE, FALSE,
5598 EL_SPACESHIP, ACTION_SMASHED_BY_SPRING, -1
5601 Xandroid, TRUE, FALSE,
5602 EL_EMC_ANDROID, ACTION_ACTIVE, -1
5605 Xandroid_1_n, FALSE, FALSE,
5606 EL_EMC_ANDROID, ACTION_ACTIVE, MV_BIT_UP
5609 Xandroid_2_n, FALSE, FALSE,
5610 EL_EMC_ANDROID, ACTION_ACTIVE, MV_BIT_UP
5613 Xandroid_1_e, FALSE, FALSE,
5614 EL_EMC_ANDROID, ACTION_ACTIVE, MV_BIT_RIGHT
5617 Xandroid_2_e, FALSE, FALSE,
5618 EL_EMC_ANDROID, ACTION_ACTIVE, MV_BIT_RIGHT
5621 Xandroid_1_w, FALSE, FALSE,
5622 EL_EMC_ANDROID, ACTION_ACTIVE, MV_BIT_LEFT
5625 Xandroid_2_w, FALSE, FALSE,
5626 EL_EMC_ANDROID, ACTION_ACTIVE, MV_BIT_LEFT
5629 Xandroid_1_s, FALSE, FALSE,
5630 EL_EMC_ANDROID, ACTION_ACTIVE, MV_BIT_DOWN
5633 Xandroid_2_s, FALSE, FALSE,
5634 EL_EMC_ANDROID, ACTION_ACTIVE, MV_BIT_DOWN
5637 Yandroid_n, FALSE, FALSE,
5638 EL_EMC_ANDROID, ACTION_MOVING, MV_BIT_UP
5641 Yandroid_nB, FALSE, TRUE,
5642 EL_EMC_ANDROID, ACTION_MOVING, MV_BIT_UP
5645 Yandroid_ne, FALSE, FALSE,
5646 EL_EMC_ANDROID, ACTION_GROWING, MV_BIT_UPRIGHT
5649 Yandroid_neB, FALSE, TRUE,
5650 EL_EMC_ANDROID, ACTION_SHRINKING, MV_BIT_UPRIGHT
5653 Yandroid_e, FALSE, FALSE,
5654 EL_EMC_ANDROID, ACTION_MOVING, MV_BIT_RIGHT
5657 Yandroid_eB, FALSE, TRUE,
5658 EL_EMC_ANDROID, ACTION_MOVING, MV_BIT_RIGHT
5661 Yandroid_se, FALSE, FALSE,
5662 EL_EMC_ANDROID, ACTION_GROWING, MV_BIT_DOWNRIGHT
5665 Yandroid_seB, FALSE, TRUE,
5666 EL_EMC_ANDROID, ACTION_SHRINKING, MV_BIT_DOWNRIGHT
5669 Yandroid_s, FALSE, FALSE,
5670 EL_EMC_ANDROID, ACTION_MOVING, MV_BIT_DOWN
5673 Yandroid_sB, FALSE, TRUE,
5674 EL_EMC_ANDROID, ACTION_MOVING, MV_BIT_DOWN
5677 Yandroid_sw, FALSE, FALSE,
5678 EL_EMC_ANDROID, ACTION_GROWING, MV_BIT_DOWNLEFT
5681 Yandroid_swB, FALSE, TRUE,
5682 EL_EMC_ANDROID, ACTION_SHRINKING, MV_BIT_DOWNLEFT
5685 Yandroid_w, FALSE, FALSE,
5686 EL_EMC_ANDROID, ACTION_MOVING, MV_BIT_LEFT
5689 Yandroid_wB, FALSE, TRUE,
5690 EL_EMC_ANDROID, ACTION_MOVING, MV_BIT_LEFT
5693 Yandroid_nw, FALSE, FALSE,
5694 EL_EMC_ANDROID, ACTION_GROWING, MV_BIT_UPLEFT
5697 Yandroid_nwB, FALSE, TRUE,
5698 EL_EMC_ANDROID, ACTION_SHRINKING, MV_BIT_UPLEFT
5701 Xspring, TRUE, FALSE,
5705 Xspring_pause, FALSE, FALSE,
5709 Xspring_e, FALSE, FALSE,
5713 Xspring_w, FALSE, FALSE,
5717 Xspring_fall, FALSE, FALSE,
5721 Yspring_s, FALSE, FALSE,
5722 EL_SPRING, ACTION_FALLING, -1
5725 Yspring_sB, FALSE, TRUE,
5726 EL_SPRING, ACTION_FALLING, -1
5729 Yspring_e, FALSE, FALSE,
5730 EL_SPRING, ACTION_MOVING, MV_BIT_RIGHT
5733 Yspring_eB, FALSE, TRUE,
5734 EL_SPRING, ACTION_MOVING, MV_BIT_RIGHT
5737 Yspring_w, FALSE, FALSE,
5738 EL_SPRING, ACTION_MOVING, MV_BIT_LEFT
5741 Yspring_wB, FALSE, TRUE,
5742 EL_SPRING, ACTION_MOVING, MV_BIT_LEFT
5745 Yspring_kill_e, FALSE, FALSE,
5746 EL_SPRING, ACTION_EATING, MV_BIT_RIGHT
5749 Yspring_kill_eB, FALSE, TRUE,
5750 EL_SPRING, ACTION_EATING, MV_BIT_RIGHT
5753 Yspring_kill_w, FALSE, FALSE,
5754 EL_SPRING, ACTION_EATING, MV_BIT_LEFT
5757 Yspring_kill_wB, FALSE, TRUE,
5758 EL_SPRING, ACTION_EATING, MV_BIT_LEFT
5761 Xeater_n, TRUE, FALSE,
5762 EL_YAMYAM_UP, -1, -1
5765 Xeater_e, TRUE, FALSE,
5766 EL_YAMYAM_RIGHT, -1, -1
5769 Xeater_w, TRUE, FALSE,
5770 EL_YAMYAM_LEFT, -1, -1
5773 Xeater_s, TRUE, FALSE,
5774 EL_YAMYAM_DOWN, -1, -1
5777 Yeater_n, FALSE, FALSE,
5778 EL_YAMYAM, ACTION_MOVING, MV_BIT_UP
5781 Yeater_nB, FALSE, TRUE,
5782 EL_YAMYAM, ACTION_MOVING, MV_BIT_UP
5785 Yeater_e, FALSE, FALSE,
5786 EL_YAMYAM, ACTION_MOVING, MV_BIT_RIGHT
5789 Yeater_eB, FALSE, TRUE,
5790 EL_YAMYAM, ACTION_MOVING, MV_BIT_RIGHT
5793 Yeater_s, FALSE, FALSE,
5794 EL_YAMYAM, ACTION_MOVING, MV_BIT_DOWN
5797 Yeater_sB, FALSE, TRUE,
5798 EL_YAMYAM, ACTION_MOVING, MV_BIT_DOWN
5801 Yeater_w, FALSE, FALSE,
5802 EL_YAMYAM, ACTION_MOVING, MV_BIT_LEFT
5805 Yeater_wB, FALSE, TRUE,
5806 EL_YAMYAM, ACTION_MOVING, MV_BIT_LEFT
5809 Yeater_stone, FALSE, FALSE,
5810 EL_YAMYAM, ACTION_SMASHED_BY_ROCK, -1
5813 Yeater_spring, FALSE, FALSE,
5814 EL_YAMYAM, ACTION_SMASHED_BY_SPRING, -1
5817 Xalien, TRUE, FALSE,
5821 Xalien_pause, FALSE, FALSE,
5825 Yalien_n, FALSE, FALSE,
5826 EL_ROBOT, ACTION_MOVING, MV_BIT_UP
5829 Yalien_nB, FALSE, TRUE,
5830 EL_ROBOT, ACTION_MOVING, MV_BIT_UP
5833 Yalien_e, FALSE, FALSE,
5834 EL_ROBOT, ACTION_MOVING, MV_BIT_RIGHT
5837 Yalien_eB, FALSE, TRUE,
5838 EL_ROBOT, ACTION_MOVING, MV_BIT_RIGHT
5841 Yalien_s, FALSE, FALSE,
5842 EL_ROBOT, ACTION_MOVING, MV_BIT_DOWN
5845 Yalien_sB, FALSE, TRUE,
5846 EL_ROBOT, ACTION_MOVING, MV_BIT_DOWN
5849 Yalien_w, FALSE, FALSE,
5850 EL_ROBOT, ACTION_MOVING, MV_BIT_LEFT
5853 Yalien_wB, FALSE, TRUE,
5854 EL_ROBOT, ACTION_MOVING, MV_BIT_LEFT
5857 Yalien_stone, FALSE, FALSE,
5858 EL_ROBOT, ACTION_SMASHED_BY_ROCK, -1
5861 Yalien_spring, FALSE, FALSE,
5862 EL_ROBOT, ACTION_SMASHED_BY_SPRING, -1
5865 Xemerald, TRUE, FALSE,
5869 Xemerald_pause, FALSE, FALSE,
5873 Xemerald_fall, FALSE, FALSE,
5877 Xemerald_shine, FALSE, FALSE,
5878 EL_EMERALD, ACTION_TWINKLING, -1
5881 Yemerald_s, FALSE, FALSE,
5882 EL_EMERALD, ACTION_FALLING, -1
5885 Yemerald_sB, FALSE, TRUE,
5886 EL_EMERALD, ACTION_FALLING, -1
5889 Yemerald_e, FALSE, FALSE,
5890 EL_EMERALD, ACTION_MOVING, MV_BIT_RIGHT
5893 Yemerald_eB, FALSE, TRUE,
5894 EL_EMERALD, ACTION_MOVING, MV_BIT_RIGHT
5897 Yemerald_w, FALSE, FALSE,
5898 EL_EMERALD, ACTION_MOVING, MV_BIT_LEFT
5901 Yemerald_wB, FALSE, TRUE,
5902 EL_EMERALD, ACTION_MOVING, MV_BIT_LEFT
5905 Yemerald_eat, FALSE, FALSE,
5906 EL_EMERALD, ACTION_COLLECTING, -1
5909 Yemerald_stone, FALSE, FALSE,
5910 EL_NUT, ACTION_BREAKING, -1
5913 Xdiamond, TRUE, FALSE,
5917 Xdiamond_pause, FALSE, FALSE,
5921 Xdiamond_fall, FALSE, FALSE,
5925 Xdiamond_shine, FALSE, FALSE,
5926 EL_DIAMOND, ACTION_TWINKLING, -1
5929 Ydiamond_s, FALSE, FALSE,
5930 EL_DIAMOND, ACTION_FALLING, -1
5933 Ydiamond_sB, FALSE, TRUE,
5934 EL_DIAMOND, ACTION_FALLING, -1
5937 Ydiamond_e, FALSE, FALSE,
5938 EL_DIAMOND, ACTION_MOVING, MV_BIT_RIGHT
5941 Ydiamond_eB, FALSE, TRUE,
5942 EL_DIAMOND, ACTION_MOVING, MV_BIT_RIGHT
5945 Ydiamond_w, FALSE, FALSE,
5946 EL_DIAMOND, ACTION_MOVING, MV_BIT_LEFT
5949 Ydiamond_wB, FALSE, TRUE,
5950 EL_DIAMOND, ACTION_MOVING, MV_BIT_LEFT
5953 Ydiamond_eat, FALSE, FALSE,
5954 EL_DIAMOND, ACTION_COLLECTING, -1
5957 Ydiamond_stone, FALSE, FALSE,
5958 EL_DIAMOND, ACTION_SMASHED_BY_ROCK, -1
5961 Xdrip_fall, TRUE, FALSE,
5962 EL_AMOEBA_DROP, -1, -1
5965 Xdrip_stretch, FALSE, FALSE,
5966 EL_AMOEBA_DROP, ACTION_FALLING, -1
5969 Xdrip_stretchB, FALSE, TRUE,
5970 EL_AMOEBA_DROP, ACTION_FALLING, -1
5973 Xdrip_eat, FALSE, FALSE,
5974 EL_AMOEBA_DROP, ACTION_GROWING, -1
5977 Ydrip_s1, FALSE, FALSE,
5978 EL_AMOEBA_DROP, ACTION_FALLING, -1
5981 Ydrip_s1B, FALSE, TRUE,
5982 EL_AMOEBA_DROP, ACTION_FALLING, -1
5985 Ydrip_s2, FALSE, FALSE,
5986 EL_AMOEBA_DROP, ACTION_FALLING, -1
5989 Ydrip_s2B, FALSE, TRUE,
5990 EL_AMOEBA_DROP, ACTION_FALLING, -1
5997 Xbomb_pause, FALSE, FALSE,
6001 Xbomb_fall, FALSE, FALSE,
6005 Ybomb_s, FALSE, FALSE,
6006 EL_BOMB, ACTION_FALLING, -1
6009 Ybomb_sB, FALSE, TRUE,
6010 EL_BOMB, ACTION_FALLING, -1
6013 Ybomb_e, FALSE, FALSE,
6014 EL_BOMB, ACTION_MOVING, MV_BIT_RIGHT
6017 Ybomb_eB, FALSE, TRUE,
6018 EL_BOMB, ACTION_MOVING, MV_BIT_RIGHT
6021 Ybomb_w, FALSE, FALSE,
6022 EL_BOMB, ACTION_MOVING, MV_BIT_LEFT
6025 Ybomb_wB, FALSE, TRUE,
6026 EL_BOMB, ACTION_MOVING, MV_BIT_LEFT
6029 Ybomb_eat, FALSE, FALSE,
6030 EL_BOMB, ACTION_ACTIVATING, -1
6033 Xballoon, TRUE, FALSE,
6037 Yballoon_n, FALSE, FALSE,
6038 EL_BALLOON, ACTION_MOVING, MV_BIT_UP
6041 Yballoon_nB, FALSE, TRUE,
6042 EL_BALLOON, ACTION_MOVING, MV_BIT_UP
6045 Yballoon_e, FALSE, FALSE,
6046 EL_BALLOON, ACTION_MOVING, MV_BIT_RIGHT
6049 Yballoon_eB, FALSE, TRUE,
6050 EL_BALLOON, ACTION_MOVING, MV_BIT_RIGHT
6053 Yballoon_s, FALSE, FALSE,
6054 EL_BALLOON, ACTION_MOVING, MV_BIT_DOWN
6057 Yballoon_sB, FALSE, TRUE,
6058 EL_BALLOON, ACTION_MOVING, MV_BIT_DOWN
6061 Yballoon_w, FALSE, FALSE,
6062 EL_BALLOON, ACTION_MOVING, MV_BIT_LEFT
6065 Yballoon_wB, FALSE, TRUE,
6066 EL_BALLOON, ACTION_MOVING, MV_BIT_LEFT
6069 Xgrass, TRUE, FALSE,
6070 EL_EMC_GRASS, -1, -1
6073 Ygrass_nB, FALSE, FALSE,
6074 EL_EMC_GRASS, ACTION_DIGGING, MV_BIT_UP
6077 Ygrass_eB, FALSE, FALSE,
6078 EL_EMC_GRASS, ACTION_DIGGING, MV_BIT_RIGHT
6081 Ygrass_sB, FALSE, FALSE,
6082 EL_EMC_GRASS, ACTION_DIGGING, MV_BIT_DOWN
6085 Ygrass_wB, FALSE, FALSE,
6086 EL_EMC_GRASS, ACTION_DIGGING, MV_BIT_LEFT
6093 Ydirt_nB, FALSE, FALSE,
6094 EL_SAND, ACTION_DIGGING, MV_BIT_UP
6097 Ydirt_eB, FALSE, FALSE,
6098 EL_SAND, ACTION_DIGGING, MV_BIT_RIGHT
6101 Ydirt_sB, FALSE, FALSE,
6102 EL_SAND, ACTION_DIGGING, MV_BIT_DOWN
6105 Ydirt_wB, FALSE, FALSE,
6106 EL_SAND, ACTION_DIGGING, MV_BIT_LEFT
6109 Xacid_ne, TRUE, FALSE,
6110 EL_ACID_POOL_TOPRIGHT, -1, -1
6113 Xacid_se, TRUE, FALSE,
6114 EL_ACID_POOL_BOTTOMRIGHT, -1, -1
6117 Xacid_s, TRUE, FALSE,
6118 EL_ACID_POOL_BOTTOM, -1, -1
6121 Xacid_sw, TRUE, FALSE,
6122 EL_ACID_POOL_BOTTOMLEFT, -1, -1
6125 Xacid_nw, TRUE, FALSE,
6126 EL_ACID_POOL_TOPLEFT, -1, -1
6129 Xacid_1, TRUE, FALSE,
6133 Xacid_2, FALSE, FALSE,
6137 Xacid_3, FALSE, FALSE,
6141 Xacid_4, FALSE, FALSE,
6145 Xacid_5, FALSE, FALSE,
6149 Xacid_6, FALSE, FALSE,
6153 Xacid_7, FALSE, FALSE,
6157 Xacid_8, FALSE, FALSE,
6161 Xball_1, TRUE, FALSE,
6162 EL_EMC_MAGIC_BALL, -1, -1
6165 Xball_1B, FALSE, FALSE,
6166 EL_EMC_MAGIC_BALL, ACTION_ACTIVE, -1
6169 Xball_2, FALSE, FALSE,
6170 EL_EMC_MAGIC_BALL, ACTION_ACTIVE, -1
6173 Xball_2B, FALSE, FALSE,
6174 EL_EMC_MAGIC_BALL, ACTION_ACTIVE, -1
6177 Yball_eat, FALSE, FALSE,
6178 EL_EMC_MAGIC_BALL, ACTION_DROPPING, -1
6181 Ykey_1_eat, FALSE, FALSE,
6182 EL_EM_KEY_1, ACTION_COLLECTING, -1
6185 Ykey_2_eat, FALSE, FALSE,
6186 EL_EM_KEY_2, ACTION_COLLECTING, -1
6189 Ykey_3_eat, FALSE, FALSE,
6190 EL_EM_KEY_3, ACTION_COLLECTING, -1
6193 Ykey_4_eat, FALSE, FALSE,
6194 EL_EM_KEY_4, ACTION_COLLECTING, -1
6197 Ykey_5_eat, FALSE, FALSE,
6198 EL_EMC_KEY_5, ACTION_COLLECTING, -1
6201 Ykey_6_eat, FALSE, FALSE,
6202 EL_EMC_KEY_6, ACTION_COLLECTING, -1
6205 Ykey_7_eat, FALSE, FALSE,
6206 EL_EMC_KEY_7, ACTION_COLLECTING, -1
6209 Ykey_8_eat, FALSE, FALSE,
6210 EL_EMC_KEY_8, ACTION_COLLECTING, -1
6213 Ylenses_eat, FALSE, FALSE,
6214 EL_EMC_LENSES, ACTION_COLLECTING, -1
6217 Ymagnify_eat, FALSE, FALSE,
6218 EL_EMC_MAGNIFIER, ACTION_COLLECTING, -1
6221 Ygrass_eat, FALSE, FALSE,
6222 EL_EMC_GRASS, ACTION_SNAPPING, -1
6225 Ydirt_eat, FALSE, FALSE,
6226 EL_SAND, ACTION_SNAPPING, -1
6229 Xgrow_ns, TRUE, FALSE,
6230 EL_EXPANDABLE_WALL_VERTICAL, -1, -1
6233 Ygrow_ns_eat, FALSE, FALSE,
6234 EL_EXPANDABLE_WALL_VERTICAL, ACTION_GROWING, -1
6237 Xgrow_ew, TRUE, FALSE,
6238 EL_EXPANDABLE_WALL_HORIZONTAL, -1, -1
6241 Ygrow_ew_eat, FALSE, FALSE,
6242 EL_EXPANDABLE_WALL_HORIZONTAL, ACTION_GROWING, -1
6245 Xwonderwall, TRUE, FALSE,
6246 EL_MAGIC_WALL, -1, -1
6249 XwonderwallB, FALSE, FALSE,
6250 EL_MAGIC_WALL, ACTION_ACTIVE, -1
6253 Xamoeba_1, TRUE, FALSE,
6254 EL_AMOEBA_DRY, ACTION_OTHER, -1
6257 Xamoeba_2, FALSE, FALSE,
6258 EL_AMOEBA_DRY, ACTION_OTHER, -1
6261 Xamoeba_3, FALSE, FALSE,
6262 EL_AMOEBA_DRY, ACTION_OTHER, -1
6265 Xamoeba_4, FALSE, FALSE,
6266 EL_AMOEBA_DRY, ACTION_OTHER, -1
6269 Xamoeba_5, TRUE, FALSE,
6270 EL_AMOEBA_WET, ACTION_OTHER, -1
6273 Xamoeba_6, FALSE, FALSE,
6274 EL_AMOEBA_WET, ACTION_OTHER, -1
6277 Xamoeba_7, FALSE, FALSE,
6278 EL_AMOEBA_WET, ACTION_OTHER, -1
6281 Xamoeba_8, FALSE, FALSE,
6282 EL_AMOEBA_WET, ACTION_OTHER, -1
6285 Xdoor_1, TRUE, FALSE,
6286 EL_EM_GATE_1, -1, -1
6289 Xdoor_2, TRUE, FALSE,
6290 EL_EM_GATE_2, -1, -1
6293 Xdoor_3, TRUE, FALSE,
6294 EL_EM_GATE_3, -1, -1
6297 Xdoor_4, TRUE, FALSE,
6298 EL_EM_GATE_4, -1, -1
6301 Xdoor_5, TRUE, FALSE,
6302 EL_EMC_GATE_5, -1, -1
6305 Xdoor_6, TRUE, FALSE,
6306 EL_EMC_GATE_6, -1, -1
6309 Xdoor_7, TRUE, FALSE,
6310 EL_EMC_GATE_7, -1, -1
6313 Xdoor_8, TRUE, FALSE,
6314 EL_EMC_GATE_8, -1, -1
6317 Xkey_1, TRUE, FALSE,
6321 Xkey_2, TRUE, FALSE,
6325 Xkey_3, TRUE, FALSE,
6329 Xkey_4, TRUE, FALSE,
6333 Xkey_5, TRUE, FALSE,
6334 EL_EMC_KEY_5, -1, -1
6337 Xkey_6, TRUE, FALSE,
6338 EL_EMC_KEY_6, -1, -1
6341 Xkey_7, TRUE, FALSE,
6342 EL_EMC_KEY_7, -1, -1
6345 Xkey_8, TRUE, FALSE,
6346 EL_EMC_KEY_8, -1, -1
6349 Xwind_n, TRUE, FALSE,
6350 EL_BALLOON_SWITCH_UP, -1, -1
6353 Xwind_e, TRUE, FALSE,
6354 EL_BALLOON_SWITCH_RIGHT, -1, -1
6357 Xwind_s, TRUE, FALSE,
6358 EL_BALLOON_SWITCH_DOWN, -1, -1
6361 Xwind_w, TRUE, FALSE,
6362 EL_BALLOON_SWITCH_LEFT, -1, -1
6365 Xwind_nesw, TRUE, FALSE,
6366 EL_BALLOON_SWITCH_ANY, -1, -1
6369 Xwind_stop, TRUE, FALSE,
6370 EL_BALLOON_SWITCH_NONE, -1, -1
6374 EL_EM_EXIT_CLOSED, -1, -1
6377 Xexit_1, TRUE, FALSE,
6378 EL_EM_EXIT_OPEN, -1, -1
6381 Xexit_2, FALSE, FALSE,
6382 EL_EM_EXIT_OPEN, -1, -1
6385 Xexit_3, FALSE, FALSE,
6386 EL_EM_EXIT_OPEN, -1, -1
6389 Xdynamite, TRUE, FALSE,
6390 EL_EM_DYNAMITE, -1, -1
6393 Ydynamite_eat, FALSE, FALSE,
6394 EL_EM_DYNAMITE, ACTION_COLLECTING, -1
6397 Xdynamite_1, TRUE, FALSE,
6398 EL_EM_DYNAMITE_ACTIVE, -1, -1
6401 Xdynamite_2, FALSE, FALSE,
6402 EL_EM_DYNAMITE_ACTIVE, -1, -1
6405 Xdynamite_3, FALSE, FALSE,
6406 EL_EM_DYNAMITE_ACTIVE, -1, -1
6409 Xdynamite_4, FALSE, FALSE,
6410 EL_EM_DYNAMITE_ACTIVE, -1, -1
6413 Xbumper, TRUE, FALSE,
6414 EL_EMC_SPRING_BUMPER, -1, -1
6417 XbumperB, FALSE, FALSE,
6418 EL_EMC_SPRING_BUMPER, ACTION_ACTIVE, -1
6421 Xwheel, TRUE, FALSE,
6422 EL_ROBOT_WHEEL, -1, -1
6425 XwheelB, FALSE, FALSE,
6426 EL_ROBOT_WHEEL, ACTION_ACTIVE, -1
6429 Xswitch, TRUE, FALSE,
6430 EL_EMC_MAGIC_BALL_SWITCH, -1, -1
6433 XswitchB, FALSE, FALSE,
6434 EL_EMC_MAGIC_BALL_SWITCH, ACTION_ACTIVE, -1
6438 EL_QUICKSAND_EMPTY, -1, -1
6441 Xsand_stone, TRUE, FALSE,
6442 EL_QUICKSAND_FULL, -1, -1
6445 Xsand_stonein_1, FALSE, TRUE,
6446 EL_ROCK, ACTION_FILLING, -1
6449 Xsand_stonein_2, FALSE, TRUE,
6450 EL_ROCK, ACTION_FILLING, -1
6453 Xsand_stonein_3, FALSE, TRUE,
6454 EL_ROCK, ACTION_FILLING, -1
6457 Xsand_stonein_4, FALSE, TRUE,
6458 EL_ROCK, ACTION_FILLING, -1
6461 Xsand_stonesand_1, FALSE, FALSE,
6462 EL_QUICKSAND_EMPTYING, -1, -1
6465 Xsand_stonesand_2, FALSE, FALSE,
6466 EL_QUICKSAND_EMPTYING, -1, -1
6469 Xsand_stonesand_3, FALSE, FALSE,
6470 EL_QUICKSAND_EMPTYING, -1, -1
6473 Xsand_stonesand_4, FALSE, FALSE,
6474 EL_QUICKSAND_EMPTYING, -1, -1
6477 Xsand_stonesand_quickout_1, FALSE, FALSE,
6478 EL_QUICKSAND_EMPTYING, -1, -1
6481 Xsand_stonesand_quickout_2, FALSE, FALSE,
6482 EL_QUICKSAND_EMPTYING, -1, -1
6485 Xsand_stoneout_1, FALSE, FALSE,
6486 EL_ROCK, ACTION_EMPTYING, -1
6489 Xsand_stoneout_2, FALSE, FALSE,
6490 EL_ROCK, ACTION_EMPTYING, -1
6493 Xsand_sandstone_1, FALSE, FALSE,
6494 EL_QUICKSAND_FILLING, -1, -1
6497 Xsand_sandstone_2, FALSE, FALSE,
6498 EL_QUICKSAND_FILLING, -1, -1
6501 Xsand_sandstone_3, FALSE, FALSE,
6502 EL_QUICKSAND_FILLING, -1, -1
6505 Xsand_sandstone_4, FALSE, FALSE,
6506 EL_QUICKSAND_FILLING, -1, -1
6509 Xplant, TRUE, FALSE,
6510 EL_EMC_PLANT, -1, -1
6513 Yplant, FALSE, FALSE,
6514 EL_EMC_PLANT, -1, -1
6517 Xlenses, TRUE, FALSE,
6518 EL_EMC_LENSES, -1, -1
6521 Xmagnify, TRUE, FALSE,
6522 EL_EMC_MAGNIFIER, -1, -1
6525 Xdripper, TRUE, FALSE,
6526 EL_EMC_DRIPPER, -1, -1
6529 XdripperB, FALSE, FALSE,
6530 EL_EMC_DRIPPER, ACTION_ACTIVE, -1
6533 Xfake_blank, TRUE, FALSE,
6534 EL_INVISIBLE_WALL, -1, -1
6537 Xfake_blankB, FALSE, FALSE,
6538 EL_INVISIBLE_WALL, ACTION_ACTIVE, -1
6541 Xfake_grass, TRUE, FALSE,
6542 EL_EMC_FAKE_GRASS, -1, -1
6545 Xfake_grassB, FALSE, FALSE,
6546 EL_EMC_FAKE_GRASS, ACTION_ACTIVE, -1
6549 Xfake_door_1, TRUE, FALSE,
6550 EL_EM_GATE_1_GRAY, -1, -1
6553 Xfake_door_2, TRUE, FALSE,
6554 EL_EM_GATE_2_GRAY, -1, -1
6557 Xfake_door_3, TRUE, FALSE,
6558 EL_EM_GATE_3_GRAY, -1, -1
6561 Xfake_door_4, TRUE, FALSE,
6562 EL_EM_GATE_4_GRAY, -1, -1
6565 Xfake_door_5, TRUE, FALSE,
6566 EL_EMC_GATE_5_GRAY, -1, -1
6569 Xfake_door_6, TRUE, FALSE,
6570 EL_EMC_GATE_6_GRAY, -1, -1
6573 Xfake_door_7, TRUE, FALSE,
6574 EL_EMC_GATE_7_GRAY, -1, -1
6577 Xfake_door_8, TRUE, FALSE,
6578 EL_EMC_GATE_8_GRAY, -1, -1
6581 Xfake_acid_1, TRUE, FALSE,
6582 EL_EMC_FAKE_ACID, -1, -1
6585 Xfake_acid_2, FALSE, FALSE,
6586 EL_EMC_FAKE_ACID, -1, -1
6589 Xfake_acid_3, FALSE, FALSE,
6590 EL_EMC_FAKE_ACID, -1, -1
6593 Xfake_acid_4, FALSE, FALSE,
6594 EL_EMC_FAKE_ACID, -1, -1
6597 Xfake_acid_5, FALSE, FALSE,
6598 EL_EMC_FAKE_ACID, -1, -1
6601 Xfake_acid_6, FALSE, FALSE,
6602 EL_EMC_FAKE_ACID, -1, -1
6605 Xfake_acid_7, FALSE, FALSE,
6606 EL_EMC_FAKE_ACID, -1, -1
6609 Xfake_acid_8, FALSE, FALSE,
6610 EL_EMC_FAKE_ACID, -1, -1
6613 Xsteel_1, TRUE, FALSE,
6614 EL_STEELWALL, -1, -1
6617 Xsteel_2, TRUE, FALSE,
6618 EL_EMC_STEELWALL_2, -1, -1
6621 Xsteel_3, TRUE, FALSE,
6622 EL_EMC_STEELWALL_3, -1, -1
6625 Xsteel_4, TRUE, FALSE,
6626 EL_EMC_STEELWALL_4, -1, -1
6629 Xwall_1, TRUE, FALSE,
6633 Xwall_2, TRUE, FALSE,
6634 EL_EMC_WALL_14, -1, -1
6637 Xwall_3, TRUE, FALSE,
6638 EL_EMC_WALL_15, -1, -1
6641 Xwall_4, TRUE, FALSE,
6642 EL_EMC_WALL_16, -1, -1
6645 Xround_wall_1, TRUE, FALSE,
6646 EL_WALL_SLIPPERY, -1, -1
6649 Xround_wall_2, TRUE, FALSE,
6650 EL_EMC_WALL_SLIPPERY_2, -1, -1
6653 Xround_wall_3, TRUE, FALSE,
6654 EL_EMC_WALL_SLIPPERY_3, -1, -1
6657 Xround_wall_4, TRUE, FALSE,
6658 EL_EMC_WALL_SLIPPERY_4, -1, -1
6661 Xdecor_1, TRUE, FALSE,
6662 EL_EMC_WALL_8, -1, -1
6665 Xdecor_2, TRUE, FALSE,
6666 EL_EMC_WALL_6, -1, -1
6669 Xdecor_3, TRUE, FALSE,
6670 EL_EMC_WALL_4, -1, -1
6673 Xdecor_4, TRUE, FALSE,
6674 EL_EMC_WALL_7, -1, -1
6677 Xdecor_5, TRUE, FALSE,
6678 EL_EMC_WALL_5, -1, -1
6681 Xdecor_6, TRUE, FALSE,
6682 EL_EMC_WALL_9, -1, -1
6685 Xdecor_7, TRUE, FALSE,
6686 EL_EMC_WALL_10, -1, -1
6689 Xdecor_8, TRUE, FALSE,
6690 EL_EMC_WALL_1, -1, -1
6693 Xdecor_9, TRUE, FALSE,
6694 EL_EMC_WALL_2, -1, -1
6697 Xdecor_10, TRUE, FALSE,
6698 EL_EMC_WALL_3, -1, -1
6701 Xdecor_11, TRUE, FALSE,
6702 EL_EMC_WALL_11, -1, -1
6705 Xdecor_12, TRUE, FALSE,
6706 EL_EMC_WALL_12, -1, -1
6709 Xalpha_0, TRUE, FALSE,
6710 EL_CHAR('0'), -1, -1
6713 Xalpha_1, TRUE, FALSE,
6714 EL_CHAR('1'), -1, -1
6717 Xalpha_2, TRUE, FALSE,
6718 EL_CHAR('2'), -1, -1
6721 Xalpha_3, TRUE, FALSE,
6722 EL_CHAR('3'), -1, -1
6725 Xalpha_4, TRUE, FALSE,
6726 EL_CHAR('4'), -1, -1
6729 Xalpha_5, TRUE, FALSE,
6730 EL_CHAR('5'), -1, -1
6733 Xalpha_6, TRUE, FALSE,
6734 EL_CHAR('6'), -1, -1
6737 Xalpha_7, TRUE, FALSE,
6738 EL_CHAR('7'), -1, -1
6741 Xalpha_8, TRUE, FALSE,
6742 EL_CHAR('8'), -1, -1
6745 Xalpha_9, TRUE, FALSE,
6746 EL_CHAR('9'), -1, -1
6749 Xalpha_excla, TRUE, FALSE,
6750 EL_CHAR('!'), -1, -1
6753 Xalpha_quote, TRUE, FALSE,
6754 EL_CHAR('"'), -1, -1
6757 Xalpha_comma, TRUE, FALSE,
6758 EL_CHAR(','), -1, -1
6761 Xalpha_minus, TRUE, FALSE,
6762 EL_CHAR('-'), -1, -1
6765 Xalpha_perio, TRUE, FALSE,
6766 EL_CHAR('.'), -1, -1
6769 Xalpha_colon, TRUE, FALSE,
6770 EL_CHAR(':'), -1, -1
6773 Xalpha_quest, TRUE, FALSE,
6774 EL_CHAR('?'), -1, -1
6777 Xalpha_a, TRUE, FALSE,
6778 EL_CHAR('A'), -1, -1
6781 Xalpha_b, TRUE, FALSE,
6782 EL_CHAR('B'), -1, -1
6785 Xalpha_c, TRUE, FALSE,
6786 EL_CHAR('C'), -1, -1
6789 Xalpha_d, TRUE, FALSE,
6790 EL_CHAR('D'), -1, -1
6793 Xalpha_e, TRUE, FALSE,
6794 EL_CHAR('E'), -1, -1
6797 Xalpha_f, TRUE, FALSE,
6798 EL_CHAR('F'), -1, -1
6801 Xalpha_g, TRUE, FALSE,
6802 EL_CHAR('G'), -1, -1
6805 Xalpha_h, TRUE, FALSE,
6806 EL_CHAR('H'), -1, -1
6809 Xalpha_i, TRUE, FALSE,
6810 EL_CHAR('I'), -1, -1
6813 Xalpha_j, TRUE, FALSE,
6814 EL_CHAR('J'), -1, -1
6817 Xalpha_k, TRUE, FALSE,
6818 EL_CHAR('K'), -1, -1
6821 Xalpha_l, TRUE, FALSE,
6822 EL_CHAR('L'), -1, -1
6825 Xalpha_m, TRUE, FALSE,
6826 EL_CHAR('M'), -1, -1
6829 Xalpha_n, TRUE, FALSE,
6830 EL_CHAR('N'), -1, -1
6833 Xalpha_o, TRUE, FALSE,
6834 EL_CHAR('O'), -1, -1
6837 Xalpha_p, TRUE, FALSE,
6838 EL_CHAR('P'), -1, -1
6841 Xalpha_q, TRUE, FALSE,
6842 EL_CHAR('Q'), -1, -1
6845 Xalpha_r, TRUE, FALSE,
6846 EL_CHAR('R'), -1, -1
6849 Xalpha_s, TRUE, FALSE,
6850 EL_CHAR('S'), -1, -1
6853 Xalpha_t, TRUE, FALSE,
6854 EL_CHAR('T'), -1, -1
6857 Xalpha_u, TRUE, FALSE,
6858 EL_CHAR('U'), -1, -1
6861 Xalpha_v, TRUE, FALSE,
6862 EL_CHAR('V'), -1, -1
6865 Xalpha_w, TRUE, FALSE,
6866 EL_CHAR('W'), -1, -1
6869 Xalpha_x, TRUE, FALSE,
6870 EL_CHAR('X'), -1, -1
6873 Xalpha_y, TRUE, FALSE,
6874 EL_CHAR('Y'), -1, -1
6877 Xalpha_z, TRUE, FALSE,
6878 EL_CHAR('Z'), -1, -1
6881 Xalpha_arrow_e, TRUE, FALSE,
6882 EL_CHAR('>'), -1, -1
6885 Xalpha_arrow_w, TRUE, FALSE,
6886 EL_CHAR('<'), -1, -1
6889 Xalpha_copyr, TRUE, FALSE,
6890 EL_CHAR(CHAR_BYTE_COPYRIGHT), -1, -1
6894 Xboom_bug, FALSE, FALSE,
6895 EL_BUG, ACTION_EXPLODING, -1
6898 Xboom_bomb, FALSE, FALSE,
6899 EL_BOMB, ACTION_EXPLODING, -1
6902 Xboom_android, FALSE, FALSE,
6903 EL_EMC_ANDROID, ACTION_OTHER, -1
6906 Xboom_1, FALSE, FALSE,
6907 EL_DEFAULT, ACTION_EXPLODING, -1
6910 Xboom_2, FALSE, FALSE,
6911 EL_DEFAULT, ACTION_EXPLODING, -1
6914 Znormal, FALSE, FALSE,
6918 Zdynamite, FALSE, FALSE,
6922 Zplayer, FALSE, FALSE,
6926 ZBORDER, FALSE, FALSE,
6936 static struct Mapping_EM_to_RND_player
6945 em_player_mapping_list[] =
6949 EL_PLAYER_1, ACTION_MOVING, MV_BIT_UP,
6953 EL_PLAYER_1, ACTION_MOVING, MV_BIT_RIGHT,
6957 EL_PLAYER_1, ACTION_MOVING, MV_BIT_DOWN,
6961 EL_PLAYER_1, ACTION_MOVING, MV_BIT_LEFT,
6965 EL_PLAYER_1, ACTION_PUSHING, MV_BIT_UP,
6969 EL_PLAYER_1, ACTION_PUSHING, MV_BIT_RIGHT,
6973 EL_PLAYER_1, ACTION_PUSHING, MV_BIT_DOWN,
6977 EL_PLAYER_1, ACTION_PUSHING, MV_BIT_LEFT,
6981 EL_PLAYER_1, ACTION_SNAPPING, MV_BIT_UP,
6985 EL_PLAYER_1, ACTION_SNAPPING, MV_BIT_RIGHT,
6989 EL_PLAYER_1, ACTION_SNAPPING, MV_BIT_DOWN,
6993 EL_PLAYER_1, ACTION_SNAPPING, MV_BIT_LEFT,
6997 EL_PLAYER_2, ACTION_MOVING, MV_BIT_UP,
7001 EL_PLAYER_2, ACTION_MOVING, MV_BIT_RIGHT,
7005 EL_PLAYER_2, ACTION_MOVING, MV_BIT_DOWN,
7009 EL_PLAYER_2, ACTION_MOVING, MV_BIT_LEFT,
7013 EL_PLAYER_2, ACTION_PUSHING, MV_BIT_UP,
7017 EL_PLAYER_2, ACTION_PUSHING, MV_BIT_RIGHT,
7021 EL_PLAYER_2, ACTION_PUSHING, MV_BIT_DOWN,
7025 EL_PLAYER_2, ACTION_PUSHING, MV_BIT_LEFT,
7029 EL_PLAYER_2, ACTION_SNAPPING, MV_BIT_UP,
7033 EL_PLAYER_2, ACTION_SNAPPING, MV_BIT_RIGHT,
7037 EL_PLAYER_2, ACTION_SNAPPING, MV_BIT_DOWN,
7041 EL_PLAYER_2, ACTION_SNAPPING, MV_BIT_LEFT,
7045 EL_PLAYER_1, ACTION_DEFAULT, -1,
7049 EL_PLAYER_2, ACTION_DEFAULT, -1,
7053 EL_PLAYER_3, ACTION_MOVING, MV_BIT_UP,
7057 EL_PLAYER_3, ACTION_MOVING, MV_BIT_RIGHT,
7061 EL_PLAYER_3, ACTION_MOVING, MV_BIT_DOWN,
7065 EL_PLAYER_3, ACTION_MOVING, MV_BIT_LEFT,
7069 EL_PLAYER_3, ACTION_PUSHING, MV_BIT_UP,
7073 EL_PLAYER_3, ACTION_PUSHING, MV_BIT_RIGHT,
7077 EL_PLAYER_3, ACTION_PUSHING, MV_BIT_DOWN,
7081 EL_PLAYER_3, ACTION_PUSHING, MV_BIT_LEFT,
7085 EL_PLAYER_3, ACTION_SNAPPING, MV_BIT_UP,
7089 EL_PLAYER_3, ACTION_SNAPPING, MV_BIT_RIGHT,
7093 EL_PLAYER_3, ACTION_SNAPPING, MV_BIT_DOWN,
7097 EL_PLAYER_3, ACTION_SNAPPING, MV_BIT_LEFT,
7101 EL_PLAYER_4, ACTION_MOVING, MV_BIT_UP,
7105 EL_PLAYER_4, ACTION_MOVING, MV_BIT_RIGHT,
7109 EL_PLAYER_4, ACTION_MOVING, MV_BIT_DOWN,
7113 EL_PLAYER_4, ACTION_MOVING, MV_BIT_LEFT,
7117 EL_PLAYER_4, ACTION_PUSHING, MV_BIT_UP,
7121 EL_PLAYER_4, ACTION_PUSHING, MV_BIT_RIGHT,
7125 EL_PLAYER_4, ACTION_PUSHING, MV_BIT_DOWN,
7129 EL_PLAYER_4, ACTION_PUSHING, MV_BIT_LEFT,
7133 EL_PLAYER_4, ACTION_SNAPPING, MV_BIT_UP,
7137 EL_PLAYER_4, ACTION_SNAPPING, MV_BIT_RIGHT,
7141 EL_PLAYER_4, ACTION_SNAPPING, MV_BIT_DOWN,
7145 EL_PLAYER_4, ACTION_SNAPPING, MV_BIT_LEFT,
7149 EL_PLAYER_3, ACTION_DEFAULT, -1,
7153 EL_PLAYER_4, ACTION_DEFAULT, -1,
7162 int map_element_RND_to_EM(int element_rnd)
7164 static unsigned short mapping_RND_to_EM[NUM_FILE_ELEMENTS];
7165 static boolean mapping_initialized = FALSE;
7167 if (!mapping_initialized)
7171 /* return "Xalpha_quest" for all undefined elements in mapping array */
7172 for (i = 0; i < NUM_FILE_ELEMENTS; i++)
7173 mapping_RND_to_EM[i] = Xalpha_quest;
7175 for (i = 0; em_object_mapping_list[i].element_em != -1; i++)
7176 if (em_object_mapping_list[i].is_rnd_to_em_mapping)
7177 mapping_RND_to_EM[em_object_mapping_list[i].element_rnd] =
7178 em_object_mapping_list[i].element_em;
7180 mapping_initialized = TRUE;
7183 if (element_rnd >= 0 && element_rnd < NUM_FILE_ELEMENTS)
7184 return mapping_RND_to_EM[element_rnd];
7186 Error(ERR_WARN, "invalid RND level element %d", element_rnd);
7191 int map_element_EM_to_RND(int element_em)
7193 static unsigned short mapping_EM_to_RND[TILE_MAX];
7194 static boolean mapping_initialized = FALSE;
7196 if (!mapping_initialized)
7200 /* return "EL_UNKNOWN" for all undefined elements in mapping array */
7201 for (i = 0; i < TILE_MAX; i++)
7202 mapping_EM_to_RND[i] = EL_UNKNOWN;
7204 for (i = 0; em_object_mapping_list[i].element_em != -1; i++)
7205 mapping_EM_to_RND[em_object_mapping_list[i].element_em] =
7206 em_object_mapping_list[i].element_rnd;
7208 mapping_initialized = TRUE;
7211 if (element_em >= 0 && element_em < TILE_MAX)
7212 return mapping_EM_to_RND[element_em];
7214 Error(ERR_WARN, "invalid EM level element %d", element_em);
7219 void map_android_clone_elements_RND_to_EM(struct LevelInfo *level)
7221 struct LevelInfo_EM *level_em = level->native_em_level;
7222 struct LEVEL *lev = level_em->lev;
7225 for (i = 0; i < TILE_MAX; i++)
7226 lev->android_array[i] = Xblank;
7228 for (i = 0; i < level->num_android_clone_elements; i++)
7230 int element_rnd = level->android_clone_element[i];
7231 int element_em = map_element_RND_to_EM(element_rnd);
7233 for (j = 0; em_object_mapping_list[j].element_em != -1; j++)
7234 if (em_object_mapping_list[j].element_rnd == element_rnd)
7235 lev->android_array[em_object_mapping_list[j].element_em] = element_em;
7239 void map_android_clone_elements_EM_to_RND(struct LevelInfo *level)
7241 struct LevelInfo_EM *level_em = level->native_em_level;
7242 struct LEVEL *lev = level_em->lev;
7245 level->num_android_clone_elements = 0;
7247 for (i = 0; i < TILE_MAX; i++)
7249 int element_em = lev->android_array[i];
7251 boolean element_found = FALSE;
7253 if (element_em == Xblank)
7256 element_rnd = map_element_EM_to_RND(element_em);
7258 for (j = 0; j < level->num_android_clone_elements; j++)
7259 if (level->android_clone_element[j] == element_rnd)
7260 element_found = TRUE;
7264 level->android_clone_element[level->num_android_clone_elements++] =
7267 if (level->num_android_clone_elements == MAX_ANDROID_ELEMENTS)
7272 if (level->num_android_clone_elements == 0)
7274 level->num_android_clone_elements = 1;
7275 level->android_clone_element[0] = EL_EMPTY;
7279 int map_direction_RND_to_EM(int direction)
7281 return (direction == MV_UP ? 0 :
7282 direction == MV_RIGHT ? 1 :
7283 direction == MV_DOWN ? 2 :
7284 direction == MV_LEFT ? 3 :
7288 int map_direction_EM_to_RND(int direction)
7290 return (direction == 0 ? MV_UP :
7291 direction == 1 ? MV_RIGHT :
7292 direction == 2 ? MV_DOWN :
7293 direction == 3 ? MV_LEFT :
7297 int map_element_RND_to_SP(int element_rnd)
7299 int element_sp = 0x20; /* map unknown elements to yellow "hardware" */
7301 if (element_rnd >= EL_SP_START &&
7302 element_rnd <= EL_SP_END)
7303 element_sp = element_rnd - EL_SP_START;
7304 else if (element_rnd == EL_EMPTY_SPACE)
7306 else if (element_rnd == EL_INVISIBLE_WALL)
7312 int map_element_SP_to_RND(int element_sp)
7314 int element_rnd = EL_UNKNOWN;
7316 if (element_sp >= 0x00 &&
7318 element_rnd = EL_SP_START + element_sp;
7319 else if (element_sp == 0x28)
7320 element_rnd = EL_INVISIBLE_WALL;
7325 int map_action_SP_to_RND(int action_sp)
7329 case actActive: return ACTION_ACTIVE;
7330 case actImpact: return ACTION_IMPACT;
7331 case actExploding: return ACTION_EXPLODING;
7332 case actDigging: return ACTION_DIGGING;
7333 case actSnapping: return ACTION_SNAPPING;
7334 case actCollecting: return ACTION_COLLECTING;
7335 case actPassing: return ACTION_PASSING;
7336 case actPushing: return ACTION_PUSHING;
7337 case actDropping: return ACTION_DROPPING;
7339 default: return ACTION_DEFAULT;
7343 int map_element_RND_to_MM(int element_rnd)
7345 return (element_rnd >= EL_MM_START_1 &&
7346 element_rnd <= EL_MM_END_1 ?
7347 EL_MM_START_1_NATIVE + element_rnd - EL_MM_START_1 :
7349 element_rnd >= EL_MM_START_2 &&
7350 element_rnd <= EL_MM_END_2 ?
7351 EL_MM_START_2_NATIVE + element_rnd - EL_MM_START_2 :
7353 element_rnd >= EL_CHAR_START &&
7354 element_rnd <= EL_CHAR_END ?
7355 EL_MM_CHAR_START_NATIVE + element_rnd - EL_CHAR_START :
7357 element_rnd >= EL_MM_RUNTIME_START &&
7358 element_rnd <= EL_MM_RUNTIME_END ?
7359 EL_MM_RUNTIME_START_NATIVE + element_rnd - EL_MM_RUNTIME_START :
7361 element_rnd >= EL_MM_DUMMY_START &&
7362 element_rnd <= EL_MM_DUMMY_END ?
7363 EL_MM_DUMMY_START_NATIVE + element_rnd - EL_MM_DUMMY_START :
7365 EL_MM_EMPTY_NATIVE);
7368 int map_element_MM_to_RND(int element_mm)
7370 return (element_mm == EL_MM_EMPTY_NATIVE ||
7371 element_mm == EL_DF_EMPTY_NATIVE ?
7374 element_mm >= EL_MM_START_1_NATIVE &&
7375 element_mm <= EL_MM_END_1_NATIVE ?
7376 EL_MM_START_1 + element_mm - EL_MM_START_1_NATIVE :
7378 element_mm >= EL_MM_START_2_NATIVE &&
7379 element_mm <= EL_MM_END_2_NATIVE ?
7380 EL_MM_START_2 + element_mm - EL_MM_START_2_NATIVE :
7382 element_mm >= EL_MM_CHAR_START_NATIVE &&
7383 element_mm <= EL_MM_CHAR_END_NATIVE ?
7384 EL_CHAR_START + element_mm - EL_MM_CHAR_START_NATIVE :
7386 element_mm >= EL_MM_RUNTIME_START_NATIVE &&
7387 element_mm <= EL_MM_RUNTIME_END_NATIVE ?
7388 EL_MM_RUNTIME_START + element_mm - EL_MM_RUNTIME_START_NATIVE :
7390 element_mm >= EL_MM_DUMMY_START_NATIVE &&
7391 element_mm <= EL_MM_DUMMY_END_NATIVE ?
7392 EL_MM_DUMMY_START + element_mm - EL_MM_DUMMY_START_NATIVE :
7397 int map_mm_wall_element(int element)
7399 return (element >= EL_MM_STEEL_WALL_START &&
7400 element <= EL_MM_STEEL_WALL_END ?
7403 element >= EL_MM_WOODEN_WALL_START &&
7404 element <= EL_MM_WOODEN_WALL_END ?
7407 element >= EL_MM_ICE_WALL_START &&
7408 element <= EL_MM_ICE_WALL_END ?
7411 element >= EL_MM_AMOEBA_WALL_START &&
7412 element <= EL_MM_AMOEBA_WALL_END ?
7415 element >= EL_DF_STEEL_WALL_START &&
7416 element <= EL_DF_STEEL_WALL_END ?
7419 element >= EL_DF_WOODEN_WALL_START &&
7420 element <= EL_DF_WOODEN_WALL_END ?
7426 int map_mm_wall_element_editor(int element)
7430 case EL_MM_STEEL_WALL: return EL_MM_STEEL_WALL_START;
7431 case EL_MM_WOODEN_WALL: return EL_MM_WOODEN_WALL_START;
7432 case EL_MM_ICE_WALL: return EL_MM_ICE_WALL_START;
7433 case EL_MM_AMOEBA_WALL: return EL_MM_AMOEBA_WALL_START;
7434 case EL_DF_STEEL_WALL: return EL_DF_STEEL_WALL_START;
7435 case EL_DF_WOODEN_WALL: return EL_DF_WOODEN_WALL_START;
7437 default: return element;
7441 int get_next_element(int element)
7445 case EL_QUICKSAND_FILLING: return EL_QUICKSAND_FULL;
7446 case EL_QUICKSAND_EMPTYING: return EL_QUICKSAND_EMPTY;
7447 case EL_QUICKSAND_FAST_FILLING: return EL_QUICKSAND_FAST_FULL;
7448 case EL_QUICKSAND_FAST_EMPTYING: return EL_QUICKSAND_FAST_EMPTY;
7449 case EL_MAGIC_WALL_FILLING: return EL_MAGIC_WALL_FULL;
7450 case EL_MAGIC_WALL_EMPTYING: return EL_MAGIC_WALL_ACTIVE;
7451 case EL_BD_MAGIC_WALL_FILLING: return EL_BD_MAGIC_WALL_FULL;
7452 case EL_BD_MAGIC_WALL_EMPTYING: return EL_BD_MAGIC_WALL_ACTIVE;
7453 case EL_DC_MAGIC_WALL_FILLING: return EL_DC_MAGIC_WALL_FULL;
7454 case EL_DC_MAGIC_WALL_EMPTYING: return EL_DC_MAGIC_WALL_ACTIVE;
7455 case EL_AMOEBA_DROPPING: return EL_AMOEBA_WET;
7457 default: return element;
7461 int el2img_mm(int element_mm)
7463 return el2img(map_element_MM_to_RND(element_mm));
7466 int el_act_dir2img(int element, int action, int direction)
7468 element = GFX_ELEMENT(element);
7469 direction = MV_DIR_TO_BIT(direction); /* default: MV_NONE => MV_DOWN */
7471 /* direction_graphic[][] == graphic[] for undefined direction graphics */
7472 return element_info[element].direction_graphic[action][direction];
7475 static int el_act_dir2crm(int element, int action, int direction)
7477 element = GFX_ELEMENT(element);
7478 direction = MV_DIR_TO_BIT(direction); /* default: MV_NONE => MV_DOWN */
7480 /* direction_graphic[][] == graphic[] for undefined direction graphics */
7481 return element_info[element].direction_crumbled[action][direction];
7484 int el_act2img(int element, int action)
7486 element = GFX_ELEMENT(element);
7488 return element_info[element].graphic[action];
7491 int el_act2crm(int element, int action)
7493 element = GFX_ELEMENT(element);
7495 return element_info[element].crumbled[action];
7498 int el_dir2img(int element, int direction)
7500 element = GFX_ELEMENT(element);
7502 return el_act_dir2img(element, ACTION_DEFAULT, direction);
7505 int el2baseimg(int element)
7507 return element_info[element].graphic[ACTION_DEFAULT];
7510 int el2img(int element)
7512 element = GFX_ELEMENT(element);
7514 return element_info[element].graphic[ACTION_DEFAULT];
7517 int el2edimg(int element)
7519 element = GFX_ELEMENT(element);
7521 return element_info[element].special_graphic[GFX_SPECIAL_ARG_EDITOR];
7524 int el2preimg(int element)
7526 element = GFX_ELEMENT(element);
7528 return element_info[element].special_graphic[GFX_SPECIAL_ARG_PREVIEW];
7531 int el2panelimg(int element)
7533 element = GFX_ELEMENT(element);
7535 return element_info[element].special_graphic[GFX_SPECIAL_ARG_PANEL];
7538 int font2baseimg(int font_nr)
7540 return font_info[font_nr].special_graphic[GFX_SPECIAL_ARG_DEFAULT];
7543 int getBeltNrFromBeltElement(int element)
7545 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
7546 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
7547 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
7550 int getBeltNrFromBeltActiveElement(int element)
7552 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
7553 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
7554 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
7557 int getBeltNrFromBeltSwitchElement(int element)
7559 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
7560 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
7561 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
7564 int getBeltDirNrFromBeltElement(int element)
7566 static int belt_base_element[4] =
7568 EL_CONVEYOR_BELT_1_LEFT,
7569 EL_CONVEYOR_BELT_2_LEFT,
7570 EL_CONVEYOR_BELT_3_LEFT,
7571 EL_CONVEYOR_BELT_4_LEFT
7574 int belt_nr = getBeltNrFromBeltElement(element);
7575 int belt_dir_nr = element - belt_base_element[belt_nr];
7577 return (belt_dir_nr % 3);
7580 int getBeltDirNrFromBeltSwitchElement(int element)
7582 static int belt_base_element[4] =
7584 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
7585 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
7586 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
7587 EL_CONVEYOR_BELT_4_SWITCH_LEFT
7590 int belt_nr = getBeltNrFromBeltSwitchElement(element);
7591 int belt_dir_nr = element - belt_base_element[belt_nr];
7593 return (belt_dir_nr % 3);
7596 int getBeltDirFromBeltElement(int element)
7598 static int belt_move_dir[3] =
7605 int belt_dir_nr = getBeltDirNrFromBeltElement(element);
7607 return belt_move_dir[belt_dir_nr];
7610 int getBeltDirFromBeltSwitchElement(int element)
7612 static int belt_move_dir[3] =
7619 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
7621 return belt_move_dir[belt_dir_nr];
7624 int getBeltElementFromBeltNrAndBeltDirNr(int belt_nr, int belt_dir_nr)
7626 static int belt_base_element[4] =
7628 EL_CONVEYOR_BELT_1_LEFT,
7629 EL_CONVEYOR_BELT_2_LEFT,
7630 EL_CONVEYOR_BELT_3_LEFT,
7631 EL_CONVEYOR_BELT_4_LEFT
7634 return belt_base_element[belt_nr] + belt_dir_nr;
7637 int getBeltElementFromBeltNrAndBeltDir(int belt_nr, int belt_dir)
7639 int belt_dir_nr = (belt_dir == MV_LEFT ? 0 : belt_dir == MV_RIGHT ? 2 : 1);
7641 return getBeltElementFromBeltNrAndBeltDirNr(belt_nr, belt_dir_nr);
7644 int getBeltSwitchElementFromBeltNrAndBeltDirNr(int belt_nr, int belt_dir_nr)
7646 static int belt_base_element[4] =
7648 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
7649 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
7650 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
7651 EL_CONVEYOR_BELT_4_SWITCH_LEFT
7654 return belt_base_element[belt_nr] + belt_dir_nr;
7657 int getBeltSwitchElementFromBeltNrAndBeltDir(int belt_nr, int belt_dir)
7659 int belt_dir_nr = (belt_dir == MV_LEFT ? 0 : belt_dir == MV_RIGHT ? 2 : 1);
7661 return getBeltSwitchElementFromBeltNrAndBeltDirNr(belt_nr, belt_dir_nr);
7664 boolean getTeamMode_EM()
7666 return game.team_mode;
7669 int getGameFrameDelay_EM(int native_em_game_frame_delay)
7671 int game_frame_delay_value;
7673 game_frame_delay_value =
7674 (tape.playing && tape.fast_forward ? FfwdFrameDelay :
7675 GameFrameDelay == GAME_FRAME_DELAY ? native_em_game_frame_delay :
7678 if (tape.playing && tape.warp_forward && !tape.pausing)
7679 game_frame_delay_value = 0;
7681 return game_frame_delay_value;
7684 unsigned int InitRND(int seed)
7686 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
7687 return InitEngineRandom_EM(seed);
7688 else if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
7689 return InitEngineRandom_SP(seed);
7690 else if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
7691 return InitEngineRandom_MM(seed);
7693 return InitEngineRandom_RND(seed);
7696 static struct Mapping_EM_to_RND_object object_mapping[TILE_MAX];
7697 static struct Mapping_EM_to_RND_player player_mapping[MAX_PLAYERS][SPR_MAX];
7699 inline static int get_effective_element_EM(int tile, int frame_em)
7701 int element = object_mapping[tile].element_rnd;
7702 int action = object_mapping[tile].action;
7703 boolean is_backside = object_mapping[tile].is_backside;
7704 boolean action_removing = (action == ACTION_DIGGING ||
7705 action == ACTION_SNAPPING ||
7706 action == ACTION_COLLECTING);
7712 case Yacid_splash_eB:
7713 case Yacid_splash_wB:
7714 return (frame_em > 5 ? EL_EMPTY : element);
7720 else /* frame_em == 7 */
7724 case Yacid_splash_eB:
7725 case Yacid_splash_wB:
7728 case Yemerald_stone:
7731 case Ydiamond_stone:
7735 case Xdrip_stretchB:
7754 case Xsand_stonein_1:
7755 case Xsand_stonein_2:
7756 case Xsand_stonein_3:
7757 case Xsand_stonein_4:
7761 return (is_backside || action_removing ? EL_EMPTY : element);
7766 inline static boolean check_linear_animation_EM(int tile)
7770 case Xsand_stonesand_1:
7771 case Xsand_stonesand_quickout_1:
7772 case Xsand_sandstone_1:
7773 case Xsand_stonein_1:
7774 case Xsand_stoneout_1:
7793 case Yacid_splash_eB:
7794 case Yacid_splash_wB:
7795 case Yemerald_stone:
7802 inline static void set_crumbled_graphics_EM(struct GraphicInfo_EM *g_em,
7803 boolean has_crumbled_graphics,
7804 int crumbled, int sync_frame)
7806 /* if element can be crumbled, but certain action graphics are just empty
7807 space (like instantly snapping sand to empty space in 1 frame), do not
7808 treat these empty space graphics as crumbled graphics in EMC engine */
7809 if (crumbled == IMG_EMPTY_SPACE)
7810 has_crumbled_graphics = FALSE;
7812 if (has_crumbled_graphics)
7814 struct GraphicInfo *g_crumbled = &graphic_info[crumbled];
7815 int frame_crumbled = getAnimationFrame(g_crumbled->anim_frames,
7816 g_crumbled->anim_delay,
7817 g_crumbled->anim_mode,
7818 g_crumbled->anim_start_frame,
7821 getGraphicSource(crumbled, frame_crumbled, &g_em->crumbled_bitmap,
7822 &g_em->crumbled_src_x, &g_em->crumbled_src_y);
7824 g_em->crumbled_border_size = graphic_info[crumbled].border_size;
7825 g_em->crumbled_tile_size = graphic_info[crumbled].tile_size;
7827 g_em->has_crumbled_graphics = TRUE;
7831 g_em->crumbled_bitmap = NULL;
7832 g_em->crumbled_src_x = 0;
7833 g_em->crumbled_src_y = 0;
7834 g_em->crumbled_border_size = 0;
7835 g_em->crumbled_tile_size = 0;
7837 g_em->has_crumbled_graphics = FALSE;
7841 void ResetGfxAnimation_EM(int x, int y, int tile)
7846 void SetGfxAnimation_EM(struct GraphicInfo_EM *g_em,
7847 int tile, int frame_em, int x, int y)
7849 int action = object_mapping[tile].action;
7850 int direction = object_mapping[tile].direction;
7851 int effective_element = get_effective_element_EM(tile, frame_em);
7852 int graphic = (direction == MV_NONE ?
7853 el_act2img(effective_element, action) :
7854 el_act_dir2img(effective_element, action, direction));
7855 struct GraphicInfo *g = &graphic_info[graphic];
7857 boolean action_removing = (action == ACTION_DIGGING ||
7858 action == ACTION_SNAPPING ||
7859 action == ACTION_COLLECTING);
7860 boolean action_moving = (action == ACTION_FALLING ||
7861 action == ACTION_MOVING ||
7862 action == ACTION_PUSHING ||
7863 action == ACTION_EATING ||
7864 action == ACTION_FILLING ||
7865 action == ACTION_EMPTYING);
7866 boolean action_falling = (action == ACTION_FALLING ||
7867 action == ACTION_FILLING ||
7868 action == ACTION_EMPTYING);
7870 /* special case: graphic uses "2nd movement tile" and has defined
7871 7 frames for movement animation (or less) => use default graphic
7872 for last (8th) frame which ends the movement animation */
7873 if (g->double_movement && g->anim_frames < 8 && frame_em == 7)
7875 action = ACTION_DEFAULT; /* (keep action_* unchanged for now) */
7876 graphic = (direction == MV_NONE ?
7877 el_act2img(effective_element, action) :
7878 el_act_dir2img(effective_element, action, direction));
7880 g = &graphic_info[graphic];
7883 if ((action_removing || check_linear_animation_EM(tile)) && frame_em == 0)
7887 else if (action_moving)
7889 boolean is_backside = object_mapping[tile].is_backside;
7893 int direction = object_mapping[tile].direction;
7894 int move_dir = (action_falling ? MV_DOWN : direction);
7899 /* !!! TEST !!! NEW !!! DOES NOT WORK RIGHT YET !!! */
7900 if (g->double_movement && frame_em == 0)
7904 if (move_dir == MV_LEFT)
7905 GfxFrame[x - 1][y] = GfxFrame[x][y];
7906 else if (move_dir == MV_RIGHT)
7907 GfxFrame[x + 1][y] = GfxFrame[x][y];
7908 else if (move_dir == MV_UP)
7909 GfxFrame[x][y - 1] = GfxFrame[x][y];
7910 else if (move_dir == MV_DOWN)
7911 GfxFrame[x][y + 1] = GfxFrame[x][y];
7918 /* special case: animation for Xsand_stonesand_quickout_1/2 twice as fast */
7919 if (tile == Xsand_stonesand_quickout_1 ||
7920 tile == Xsand_stonesand_quickout_2)
7924 if (graphic_info[graphic].anim_global_sync)
7925 sync_frame = FrameCounter;
7926 else if (IN_FIELD(x, y, MAX_LEV_FIELDX, MAX_LEV_FIELDY))
7927 sync_frame = GfxFrame[x][y];
7929 sync_frame = 0; /* playfield border (pseudo steel) */
7931 SetRandomAnimationValue(x, y);
7933 int frame = getAnimationFrame(g->anim_frames,
7936 g->anim_start_frame,
7939 g_em->unique_identifier =
7940 (graphic << 16) | ((frame % 8) << 12) | (g_em->width << 6) | g_em->height;
7943 void getGraphicSourceObjectExt_EM(struct GraphicInfo_EM *g_em,
7944 int tile, int frame_em, int x, int y)
7946 int action = object_mapping[tile].action;
7947 int direction = object_mapping[tile].direction;
7948 boolean is_backside = object_mapping[tile].is_backside;
7949 int effective_element = get_effective_element_EM(tile, frame_em);
7950 int effective_action = action;
7951 int graphic = (direction == MV_NONE ?
7952 el_act2img(effective_element, effective_action) :
7953 el_act_dir2img(effective_element, effective_action,
7955 int crumbled = (direction == MV_NONE ?
7956 el_act2crm(effective_element, effective_action) :
7957 el_act_dir2crm(effective_element, effective_action,
7959 int base_graphic = el_act2img(effective_element, ACTION_DEFAULT);
7960 int base_crumbled = el_act2crm(effective_element, ACTION_DEFAULT);
7961 boolean has_crumbled_graphics = (base_crumbled != base_graphic);
7962 struct GraphicInfo *g = &graphic_info[graphic];
7965 /* special case: graphic uses "2nd movement tile" and has defined
7966 7 frames for movement animation (or less) => use default graphic
7967 for last (8th) frame which ends the movement animation */
7968 if (g->double_movement && g->anim_frames < 8 && frame_em == 7)
7970 effective_action = ACTION_DEFAULT;
7971 graphic = (direction == MV_NONE ?
7972 el_act2img(effective_element, effective_action) :
7973 el_act_dir2img(effective_element, effective_action,
7975 crumbled = (direction == MV_NONE ?
7976 el_act2crm(effective_element, effective_action) :
7977 el_act_dir2crm(effective_element, effective_action,
7980 g = &graphic_info[graphic];
7983 if (graphic_info[graphic].anim_global_sync)
7984 sync_frame = FrameCounter;
7985 else if (IN_FIELD(x, y, MAX_LEV_FIELDX, MAX_LEV_FIELDY))
7986 sync_frame = GfxFrame[x][y];
7988 sync_frame = 0; /* playfield border (pseudo steel) */
7990 SetRandomAnimationValue(x, y);
7992 int frame = getAnimationFrame(g->anim_frames,
7995 g->anim_start_frame,
7998 getGraphicSourceExt(graphic, frame, &g_em->bitmap, &g_em->src_x, &g_em->src_y,
7999 g->double_movement && is_backside);
8001 /* (updating the "crumbled" graphic definitions is probably not really needed,
8002 as animations for crumbled graphics can't be longer than one EMC cycle) */
8003 set_crumbled_graphics_EM(g_em, has_crumbled_graphics, crumbled,
8007 void getGraphicSourcePlayerExt_EM(struct GraphicInfo_EM *g_em,
8008 int player_nr, int anim, int frame_em)
8010 int element = player_mapping[player_nr][anim].element_rnd;
8011 int action = player_mapping[player_nr][anim].action;
8012 int direction = player_mapping[player_nr][anim].direction;
8013 int graphic = (direction == MV_NONE ?
8014 el_act2img(element, action) :
8015 el_act_dir2img(element, action, direction));
8016 struct GraphicInfo *g = &graphic_info[graphic];
8019 InitPlayerGfxAnimation(&stored_player[player_nr], action, direction);
8021 stored_player[player_nr].StepFrame = frame_em;
8023 sync_frame = stored_player[player_nr].Frame;
8025 int frame = getAnimationFrame(g->anim_frames,
8028 g->anim_start_frame,
8031 getGraphicSourceExt(graphic, frame, &g_em->bitmap,
8032 &g_em->src_x, &g_em->src_y, FALSE);
8035 void InitGraphicInfo_EM(void)
8040 int num_em_gfx_errors = 0;
8042 if (graphic_info_em_object[0][0].bitmap == NULL)
8044 /* EM graphics not yet initialized in em_open_all() */
8049 printf("::: [4 errors can be ignored (1 x 'bomb', 3 x 'em_dynamite']\n");
8052 /* always start with reliable default values */
8053 for (i = 0; i < TILE_MAX; i++)
8055 object_mapping[i].element_rnd = EL_UNKNOWN;
8056 object_mapping[i].is_backside = FALSE;
8057 object_mapping[i].action = ACTION_DEFAULT;
8058 object_mapping[i].direction = MV_NONE;
8061 /* always start with reliable default values */
8062 for (p = 0; p < MAX_PLAYERS; p++)
8064 for (i = 0; i < SPR_MAX; i++)
8066 player_mapping[p][i].element_rnd = EL_UNKNOWN;
8067 player_mapping[p][i].action = ACTION_DEFAULT;
8068 player_mapping[p][i].direction = MV_NONE;
8072 for (i = 0; em_object_mapping_list[i].element_em != -1; i++)
8074 int e = em_object_mapping_list[i].element_em;
8076 object_mapping[e].element_rnd = em_object_mapping_list[i].element_rnd;
8077 object_mapping[e].is_backside = em_object_mapping_list[i].is_backside;
8079 if (em_object_mapping_list[i].action != -1)
8080 object_mapping[e].action = em_object_mapping_list[i].action;
8082 if (em_object_mapping_list[i].direction != -1)
8083 object_mapping[e].direction =
8084 MV_DIR_FROM_BIT(em_object_mapping_list[i].direction);
8087 for (i = 0; em_player_mapping_list[i].action_em != -1; i++)
8089 int a = em_player_mapping_list[i].action_em;
8090 int p = em_player_mapping_list[i].player_nr;
8092 player_mapping[p][a].element_rnd = em_player_mapping_list[i].element_rnd;
8094 if (em_player_mapping_list[i].action != -1)
8095 player_mapping[p][a].action = em_player_mapping_list[i].action;
8097 if (em_player_mapping_list[i].direction != -1)
8098 player_mapping[p][a].direction =
8099 MV_DIR_FROM_BIT(em_player_mapping_list[i].direction);
8102 for (i = 0; i < TILE_MAX; i++)
8104 int element = object_mapping[i].element_rnd;
8105 int action = object_mapping[i].action;
8106 int direction = object_mapping[i].direction;
8107 boolean is_backside = object_mapping[i].is_backside;
8108 boolean action_exploding = ((action == ACTION_EXPLODING ||
8109 action == ACTION_SMASHED_BY_ROCK ||
8110 action == ACTION_SMASHED_BY_SPRING) &&
8111 element != EL_DIAMOND);
8112 boolean action_active = (action == ACTION_ACTIVE);
8113 boolean action_other = (action == ACTION_OTHER);
8115 for (j = 0; j < 8; j++)
8117 int effective_element = get_effective_element_EM(i, j);
8118 int effective_action = (j < 7 ? action :
8119 i == Xdrip_stretch ? action :
8120 i == Xdrip_stretchB ? action :
8121 i == Ydrip_s1 ? action :
8122 i == Ydrip_s1B ? action :
8123 i == Xball_1B ? action :
8124 i == Xball_2 ? action :
8125 i == Xball_2B ? action :
8126 i == Yball_eat ? action :
8127 i == Ykey_1_eat ? action :
8128 i == Ykey_2_eat ? action :
8129 i == Ykey_3_eat ? action :
8130 i == Ykey_4_eat ? action :
8131 i == Ykey_5_eat ? action :
8132 i == Ykey_6_eat ? action :
8133 i == Ykey_7_eat ? action :
8134 i == Ykey_8_eat ? action :
8135 i == Ylenses_eat ? action :
8136 i == Ymagnify_eat ? action :
8137 i == Ygrass_eat ? action :
8138 i == Ydirt_eat ? action :
8139 i == Xsand_stonein_1 ? action :
8140 i == Xsand_stonein_2 ? action :
8141 i == Xsand_stonein_3 ? action :
8142 i == Xsand_stonein_4 ? action :
8143 i == Xsand_stoneout_1 ? action :
8144 i == Xsand_stoneout_2 ? action :
8145 i == Xboom_android ? ACTION_EXPLODING :
8146 action_exploding ? ACTION_EXPLODING :
8147 action_active ? action :
8148 action_other ? action :
8150 int graphic = (el_act_dir2img(effective_element, effective_action,
8152 int crumbled = (el_act_dir2crm(effective_element, effective_action,
8154 int base_graphic = el_act2img(effective_element, ACTION_DEFAULT);
8155 int base_crumbled = el_act2crm(effective_element, ACTION_DEFAULT);
8156 boolean has_action_graphics = (graphic != base_graphic);
8157 boolean has_crumbled_graphics = (base_crumbled != base_graphic);
8158 struct GraphicInfo *g = &graphic_info[graphic];
8159 struct GraphicInfo_EM *g_em = &graphic_info_em_object[i][7 - j];
8162 /* ensure to get symmetric 3-frame, 2-delay animations as used in EM */
8163 boolean special_animation = (action != ACTION_DEFAULT &&
8164 g->anim_frames == 3 &&
8165 g->anim_delay == 2 &&
8166 g->anim_mode & ANIM_LINEAR);
8167 int sync_frame = (i == Xdrip_stretch ? 7 :
8168 i == Xdrip_stretchB ? 7 :
8169 i == Ydrip_s2 ? j + 8 :
8170 i == Ydrip_s2B ? j + 8 :
8179 i == Xfake_acid_1 ? 0 :
8180 i == Xfake_acid_2 ? 10 :
8181 i == Xfake_acid_3 ? 20 :
8182 i == Xfake_acid_4 ? 30 :
8183 i == Xfake_acid_5 ? 40 :
8184 i == Xfake_acid_6 ? 50 :
8185 i == Xfake_acid_7 ? 60 :
8186 i == Xfake_acid_8 ? 70 :
8188 i == Xball_2B ? j + 8 :
8189 i == Yball_eat ? j + 1 :
8190 i == Ykey_1_eat ? j + 1 :
8191 i == Ykey_2_eat ? j + 1 :
8192 i == Ykey_3_eat ? j + 1 :
8193 i == Ykey_4_eat ? j + 1 :
8194 i == Ykey_5_eat ? j + 1 :
8195 i == Ykey_6_eat ? j + 1 :
8196 i == Ykey_7_eat ? j + 1 :
8197 i == Ykey_8_eat ? j + 1 :
8198 i == Ylenses_eat ? j + 1 :
8199 i == Ymagnify_eat ? j + 1 :
8200 i == Ygrass_eat ? j + 1 :
8201 i == Ydirt_eat ? j + 1 :
8202 i == Xamoeba_1 ? 0 :
8203 i == Xamoeba_2 ? 1 :
8204 i == Xamoeba_3 ? 2 :
8205 i == Xamoeba_4 ? 3 :
8206 i == Xamoeba_5 ? 0 :
8207 i == Xamoeba_6 ? 1 :
8208 i == Xamoeba_7 ? 2 :
8209 i == Xamoeba_8 ? 3 :
8210 i == Xexit_2 ? j + 8 :
8211 i == Xexit_3 ? j + 16 :
8212 i == Xdynamite_1 ? 0 :
8213 i == Xdynamite_2 ? 8 :
8214 i == Xdynamite_3 ? 16 :
8215 i == Xdynamite_4 ? 24 :
8216 i == Xsand_stonein_1 ? j + 1 :
8217 i == Xsand_stonein_2 ? j + 9 :
8218 i == Xsand_stonein_3 ? j + 17 :
8219 i == Xsand_stonein_4 ? j + 25 :
8220 i == Xsand_stoneout_1 && j == 0 ? 0 :
8221 i == Xsand_stoneout_1 && j == 1 ? 0 :
8222 i == Xsand_stoneout_1 && j == 2 ? 1 :
8223 i == Xsand_stoneout_1 && j == 3 ? 2 :
8224 i == Xsand_stoneout_1 && j == 4 ? 2 :
8225 i == Xsand_stoneout_1 && j == 5 ? 3 :
8226 i == Xsand_stoneout_1 && j == 6 ? 4 :
8227 i == Xsand_stoneout_1 && j == 7 ? 4 :
8228 i == Xsand_stoneout_2 && j == 0 ? 5 :
8229 i == Xsand_stoneout_2 && j == 1 ? 6 :
8230 i == Xsand_stoneout_2 && j == 2 ? 7 :
8231 i == Xsand_stoneout_2 && j == 3 ? 8 :
8232 i == Xsand_stoneout_2 && j == 4 ? 9 :
8233 i == Xsand_stoneout_2 && j == 5 ? 11 :
8234 i == Xsand_stoneout_2 && j == 6 ? 13 :
8235 i == Xsand_stoneout_2 && j == 7 ? 15 :
8236 i == Xboom_bug && j == 1 ? 2 :
8237 i == Xboom_bug && j == 2 ? 2 :
8238 i == Xboom_bug && j == 3 ? 4 :
8239 i == Xboom_bug && j == 4 ? 4 :
8240 i == Xboom_bug && j == 5 ? 2 :
8241 i == Xboom_bug && j == 6 ? 2 :
8242 i == Xboom_bug && j == 7 ? 0 :
8243 i == Xboom_bomb && j == 1 ? 2 :
8244 i == Xboom_bomb && j == 2 ? 2 :
8245 i == Xboom_bomb && j == 3 ? 4 :
8246 i == Xboom_bomb && j == 4 ? 4 :
8247 i == Xboom_bomb && j == 5 ? 2 :
8248 i == Xboom_bomb && j == 6 ? 2 :
8249 i == Xboom_bomb && j == 7 ? 0 :
8250 i == Xboom_android && j == 7 ? 6 :
8251 i == Xboom_1 && j == 1 ? 2 :
8252 i == Xboom_1 && j == 2 ? 2 :
8253 i == Xboom_1 && j == 3 ? 4 :
8254 i == Xboom_1 && j == 4 ? 4 :
8255 i == Xboom_1 && j == 5 ? 6 :
8256 i == Xboom_1 && j == 6 ? 6 :
8257 i == Xboom_1 && j == 7 ? 8 :
8258 i == Xboom_2 && j == 0 ? 8 :
8259 i == Xboom_2 && j == 1 ? 8 :
8260 i == Xboom_2 && j == 2 ? 10 :
8261 i == Xboom_2 && j == 3 ? 10 :
8262 i == Xboom_2 && j == 4 ? 10 :
8263 i == Xboom_2 && j == 5 ? 12 :
8264 i == Xboom_2 && j == 6 ? 12 :
8265 i == Xboom_2 && j == 7 ? 12 :
8266 special_animation && j == 4 ? 3 :
8267 effective_action != action ? 0 :
8271 Bitmap *debug_bitmap = g_em->bitmap;
8272 int debug_src_x = g_em->src_x;
8273 int debug_src_y = g_em->src_y;
8276 int frame = getAnimationFrame(g->anim_frames,
8279 g->anim_start_frame,
8282 getGraphicSourceExt(graphic, frame, &src_bitmap, &src_x, &src_y,
8283 g->double_movement && is_backside);
8285 g_em->bitmap = src_bitmap;
8286 g_em->src_x = src_x;
8287 g_em->src_y = src_y;
8288 g_em->src_offset_x = 0;
8289 g_em->src_offset_y = 0;
8290 g_em->dst_offset_x = 0;
8291 g_em->dst_offset_y = 0;
8292 g_em->width = TILEX;
8293 g_em->height = TILEY;
8295 g_em->preserve_background = FALSE;
8297 set_crumbled_graphics_EM(g_em, has_crumbled_graphics, crumbled,
8300 if ((!g->double_movement && (effective_action == ACTION_FALLING ||
8301 effective_action == ACTION_MOVING ||
8302 effective_action == ACTION_PUSHING ||
8303 effective_action == ACTION_EATING)) ||
8304 (!has_action_graphics && (effective_action == ACTION_FILLING ||
8305 effective_action == ACTION_EMPTYING)))
8308 (effective_action == ACTION_FALLING ||
8309 effective_action == ACTION_FILLING ||
8310 effective_action == ACTION_EMPTYING ? MV_DOWN : direction);
8311 int dx = (move_dir == MV_LEFT ? -1 : move_dir == MV_RIGHT ? 1 : 0);
8312 int dy = (move_dir == MV_UP ? -1 : move_dir == MV_DOWN ? 1 : 0);
8313 int num_steps = (i == Ydrip_s1 ? 16 :
8314 i == Ydrip_s1B ? 16 :
8315 i == Ydrip_s2 ? 16 :
8316 i == Ydrip_s2B ? 16 :
8317 i == Xsand_stonein_1 ? 32 :
8318 i == Xsand_stonein_2 ? 32 :
8319 i == Xsand_stonein_3 ? 32 :
8320 i == Xsand_stonein_4 ? 32 :
8321 i == Xsand_stoneout_1 ? 16 :
8322 i == Xsand_stoneout_2 ? 16 : 8);
8323 int cx = ABS(dx) * (TILEX / num_steps);
8324 int cy = ABS(dy) * (TILEY / num_steps);
8325 int step_frame = (i == Ydrip_s2 ? j + 8 :
8326 i == Ydrip_s2B ? j + 8 :
8327 i == Xsand_stonein_2 ? j + 8 :
8328 i == Xsand_stonein_3 ? j + 16 :
8329 i == Xsand_stonein_4 ? j + 24 :
8330 i == Xsand_stoneout_2 ? j + 8 : j) + 1;
8331 int step = (is_backside ? step_frame : num_steps - step_frame);
8333 if (is_backside) /* tile where movement starts */
8335 if (dx < 0 || dy < 0)
8337 g_em->src_offset_x = cx * step;
8338 g_em->src_offset_y = cy * step;
8342 g_em->dst_offset_x = cx * step;
8343 g_em->dst_offset_y = cy * step;
8346 else /* tile where movement ends */
8348 if (dx < 0 || dy < 0)
8350 g_em->dst_offset_x = cx * step;
8351 g_em->dst_offset_y = cy * step;
8355 g_em->src_offset_x = cx * step;
8356 g_em->src_offset_y = cy * step;
8360 g_em->width = TILEX - cx * step;
8361 g_em->height = TILEY - cy * step;
8364 /* create unique graphic identifier to decide if tile must be redrawn */
8365 /* bit 31 - 16 (16 bit): EM style graphic
8366 bit 15 - 12 ( 4 bit): EM style frame
8367 bit 11 - 6 ( 6 bit): graphic width
8368 bit 5 - 0 ( 6 bit): graphic height */
8369 g_em->unique_identifier =
8370 (graphic << 16) | (frame << 12) | (g_em->width << 6) | g_em->height;
8374 /* skip check for EMC elements not contained in original EMC artwork */
8375 if (element == EL_EMC_FAKE_ACID)
8378 if (g_em->bitmap != debug_bitmap ||
8379 g_em->src_x != debug_src_x ||
8380 g_em->src_y != debug_src_y ||
8381 g_em->src_offset_x != 0 ||
8382 g_em->src_offset_y != 0 ||
8383 g_em->dst_offset_x != 0 ||
8384 g_em->dst_offset_y != 0 ||
8385 g_em->width != TILEX ||
8386 g_em->height != TILEY)
8388 static int last_i = -1;
8396 printf("::: EMC GFX ERROR for element %d -> %d ('%s', '%s', %d)",
8397 i, element, element_info[element].token_name,
8398 element_action_info[effective_action].suffix, direction);
8400 if (element != effective_element)
8401 printf(" [%d ('%s')]",
8403 element_info[effective_element].token_name);
8407 if (g_em->bitmap != debug_bitmap)
8408 printf(" %d (%d): different bitmap! (0x%08x != 0x%08x)\n",
8409 j, is_backside, (int)(g_em->bitmap), (int)(debug_bitmap));
8411 if (g_em->src_x != debug_src_x ||
8412 g_em->src_y != debug_src_y)
8413 printf(" frame %d (%c): %d,%d (%d,%d) should be %d,%d (%d,%d)\n",
8414 j, (is_backside ? 'B' : 'F'),
8415 g_em->src_x, g_em->src_y,
8416 g_em->src_x / 32, g_em->src_y / 32,
8417 debug_src_x, debug_src_y,
8418 debug_src_x / 32, debug_src_y / 32);
8420 if (g_em->src_offset_x != 0 ||
8421 g_em->src_offset_y != 0 ||
8422 g_em->dst_offset_x != 0 ||
8423 g_em->dst_offset_y != 0)
8424 printf(" %d (%d): offsets %d,%d and %d,%d should be all 0\n",
8426 g_em->src_offset_x, g_em->src_offset_y,
8427 g_em->dst_offset_x, g_em->dst_offset_y);
8429 if (g_em->width != TILEX ||
8430 g_em->height != TILEY)
8431 printf(" %d (%d): size %d,%d should be %d,%d\n",
8433 g_em->width, g_em->height, TILEX, TILEY);
8435 num_em_gfx_errors++;
8442 for (i = 0; i < TILE_MAX; i++)
8444 for (j = 0; j < 8; j++)
8446 int element = object_mapping[i].element_rnd;
8447 int action = object_mapping[i].action;
8448 int direction = object_mapping[i].direction;
8449 boolean is_backside = object_mapping[i].is_backside;
8450 int graphic_action = el_act_dir2img(element, action, direction);
8451 int graphic_default = el_act_dir2img(element, ACTION_DEFAULT, direction);
8453 if ((action == ACTION_SMASHED_BY_ROCK ||
8454 action == ACTION_SMASHED_BY_SPRING ||
8455 action == ACTION_EATING) &&
8456 graphic_action == graphic_default)
8458 int e = (action == ACTION_SMASHED_BY_ROCK ? Ystone_s :
8459 action == ACTION_SMASHED_BY_SPRING ? Yspring_s :
8460 direction == MV_LEFT ? (is_backside? Yspring_wB: Yspring_w) :
8461 direction == MV_RIGHT ? (is_backside? Yspring_eB: Yspring_e) :
8464 /* no separate animation for "smashed by rock" -- use rock instead */
8465 struct GraphicInfo_EM *g_em = &graphic_info_em_object[i][7 - j];
8466 struct GraphicInfo_EM *g_xx = &graphic_info_em_object[e][7 - j];
8468 g_em->bitmap = g_xx->bitmap;
8469 g_em->src_x = g_xx->src_x;
8470 g_em->src_y = g_xx->src_y;
8471 g_em->src_offset_x = g_xx->src_offset_x;
8472 g_em->src_offset_y = g_xx->src_offset_y;
8473 g_em->dst_offset_x = g_xx->dst_offset_x;
8474 g_em->dst_offset_y = g_xx->dst_offset_y;
8475 g_em->width = g_xx->width;
8476 g_em->height = g_xx->height;
8477 g_em->unique_identifier = g_xx->unique_identifier;
8480 g_em->preserve_background = TRUE;
8485 for (p = 0; p < MAX_PLAYERS; p++)
8487 for (i = 0; i < SPR_MAX; i++)
8489 int element = player_mapping[p][i].element_rnd;
8490 int action = player_mapping[p][i].action;
8491 int direction = player_mapping[p][i].direction;
8493 for (j = 0; j < 8; j++)
8495 int effective_element = element;
8496 int effective_action = action;
8497 int graphic = (direction == MV_NONE ?
8498 el_act2img(effective_element, effective_action) :
8499 el_act_dir2img(effective_element, effective_action,
8501 struct GraphicInfo *g = &graphic_info[graphic];
8502 struct GraphicInfo_EM *g_em = &graphic_info_em_player[p][i][7 - j];
8508 Bitmap *debug_bitmap = g_em->bitmap;
8509 int debug_src_x = g_em->src_x;
8510 int debug_src_y = g_em->src_y;
8513 int frame = getAnimationFrame(g->anim_frames,
8516 g->anim_start_frame,
8519 getGraphicSourceExt(graphic, frame, &src_bitmap, &src_x, &src_y, FALSE);
8521 g_em->bitmap = src_bitmap;
8522 g_em->src_x = src_x;
8523 g_em->src_y = src_y;
8524 g_em->src_offset_x = 0;
8525 g_em->src_offset_y = 0;
8526 g_em->dst_offset_x = 0;
8527 g_em->dst_offset_y = 0;
8528 g_em->width = TILEX;
8529 g_em->height = TILEY;
8533 /* skip check for EMC elements not contained in original EMC artwork */
8534 if (element == EL_PLAYER_3 ||
8535 element == EL_PLAYER_4)
8538 if (g_em->bitmap != debug_bitmap ||
8539 g_em->src_x != debug_src_x ||
8540 g_em->src_y != debug_src_y)
8542 static int last_i = -1;
8550 printf("::: EMC GFX ERROR for p/a %d/%d -> %d ('%s', '%s', %d)",
8551 p, i, element, element_info[element].token_name,
8552 element_action_info[effective_action].suffix, direction);
8554 if (element != effective_element)
8555 printf(" [%d ('%s')]",
8557 element_info[effective_element].token_name);
8561 if (g_em->bitmap != debug_bitmap)
8562 printf(" %d: different bitmap! (0x%08x != 0x%08x)\n",
8563 j, (int)(g_em->bitmap), (int)(debug_bitmap));
8565 if (g_em->src_x != debug_src_x ||
8566 g_em->src_y != debug_src_y)
8567 printf(" frame %d: %d,%d (%d,%d) should be %d,%d (%d,%d)\n",
8569 g_em->src_x, g_em->src_y,
8570 g_em->src_x / 32, g_em->src_y / 32,
8571 debug_src_x, debug_src_y,
8572 debug_src_x / 32, debug_src_y / 32);
8574 num_em_gfx_errors++;
8584 printf("::: [%d errors found]\n", num_em_gfx_errors);
8590 void CheckSaveEngineSnapshot_EM(byte action[MAX_PLAYERS], int frame,
8591 boolean any_player_moving,
8592 boolean any_player_snapping,
8593 boolean any_player_dropping)
8595 if (frame == 0 && !any_player_dropping)
8597 if (!local_player->was_waiting)
8599 if (!CheckSaveEngineSnapshotToList())
8602 local_player->was_waiting = TRUE;
8605 else if (any_player_moving || any_player_snapping || any_player_dropping)
8607 local_player->was_waiting = FALSE;
8611 void CheckSaveEngineSnapshot_SP(boolean murphy_is_waiting,
8612 boolean murphy_is_dropping)
8614 if (murphy_is_waiting)
8616 if (!local_player->was_waiting)
8618 if (!CheckSaveEngineSnapshotToList())
8621 local_player->was_waiting = TRUE;
8626 local_player->was_waiting = FALSE;
8630 void CheckSingleStepMode_EM(byte action[MAX_PLAYERS], int frame,
8631 boolean any_player_moving,
8632 boolean any_player_snapping,
8633 boolean any_player_dropping)
8635 if (tape.single_step && tape.recording && !tape.pausing)
8636 if (frame == 0 && !any_player_dropping)
8637 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8639 CheckSaveEngineSnapshot_EM(action, frame, any_player_moving,
8640 any_player_snapping, any_player_dropping);
8643 void CheckSingleStepMode_SP(boolean murphy_is_waiting,
8644 boolean murphy_is_dropping)
8646 boolean murphy_starts_dropping = FALSE;
8649 for (i = 0; i < MAX_PLAYERS; i++)
8650 if (stored_player[i].force_dropping)
8651 murphy_starts_dropping = TRUE;
8653 if (tape.single_step && tape.recording && !tape.pausing)
8654 if (murphy_is_waiting && !murphy_starts_dropping)
8655 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8657 CheckSaveEngineSnapshot_SP(murphy_is_waiting, murphy_is_dropping);
8660 void getGraphicSource_SP(struct GraphicInfo_SP *g_sp,
8661 int graphic, int sync_frame, int x, int y)
8663 int frame = getGraphicAnimationFrame(graphic, sync_frame);
8665 getGraphicSource(graphic, frame, &g_sp->bitmap, &g_sp->src_x, &g_sp->src_y);
8668 boolean isNextAnimationFrame_SP(int graphic, int sync_frame)
8670 return (IS_NEXT_FRAME(sync_frame, graphic));
8673 int getGraphicInfo_Delay(int graphic)
8675 return graphic_info[graphic].anim_delay;
8678 void PlayMenuSoundExt(int sound)
8680 if (sound == SND_UNDEFINED)
8683 if ((!setup.sound_simple && !IS_LOOP_SOUND(sound)) ||
8684 (!setup.sound_loops && IS_LOOP_SOUND(sound)))
8687 if (IS_LOOP_SOUND(sound))
8688 PlaySoundLoop(sound);
8693 void PlayMenuSound()
8695 PlayMenuSoundExt(menu.sound[game_status]);
8698 void PlayMenuSoundStereo(int sound, int stereo_position)
8700 if (sound == SND_UNDEFINED)
8703 if ((!setup.sound_simple && !IS_LOOP_SOUND(sound)) ||
8704 (!setup.sound_loops && IS_LOOP_SOUND(sound)))
8707 if (IS_LOOP_SOUND(sound))
8708 PlaySoundExt(sound, SOUND_MAX_VOLUME, stereo_position, SND_CTRL_PLAY_LOOP);
8710 PlaySoundStereo(sound, stereo_position);
8713 void PlayMenuSoundIfLoopExt(int sound)
8715 if (sound == SND_UNDEFINED)
8718 if ((!setup.sound_simple && !IS_LOOP_SOUND(sound)) ||
8719 (!setup.sound_loops && IS_LOOP_SOUND(sound)))
8722 if (IS_LOOP_SOUND(sound))
8723 PlaySoundLoop(sound);
8726 void PlayMenuSoundIfLoop()
8728 PlayMenuSoundIfLoopExt(menu.sound[game_status]);
8731 void PlayMenuMusicExt(int music)
8733 if (music == MUS_UNDEFINED)
8736 if (!setup.sound_music)
8742 void PlayMenuMusic()
8744 char *curr_music = getCurrentlyPlayingMusicFilename();
8745 char *next_music = getMusicInfoEntryFilename(menu.music[game_status]);
8747 if (!strEqual(curr_music, next_music))
8748 PlayMenuMusicExt(menu.music[game_status]);
8751 void PlayMenuSoundsAndMusic()
8757 static void FadeMenuSounds()
8762 static void FadeMenuMusic()
8764 char *curr_music = getCurrentlyPlayingMusicFilename();
8765 char *next_music = getMusicInfoEntryFilename(menu.music[game_status]);
8767 if (!strEqual(curr_music, next_music))
8771 void FadeMenuSoundsAndMusic()
8777 void PlaySoundActivating()
8780 PlaySound(SND_MENU_ITEM_ACTIVATING);
8784 void PlaySoundSelecting()
8787 PlaySound(SND_MENU_ITEM_SELECTING);
8791 void ToggleFullscreenOrChangeWindowScalingIfNeeded()
8793 boolean change_fullscreen = (setup.fullscreen !=
8794 video.fullscreen_enabled);
8795 boolean change_window_scaling_percent = (!video.fullscreen_enabled &&
8796 setup.window_scaling_percent !=
8797 video.window_scaling_percent);
8799 if (change_window_scaling_percent && video.fullscreen_enabled)
8802 if (!change_window_scaling_percent && !video.fullscreen_available)
8805 #if defined(TARGET_SDL2)
8806 if (change_window_scaling_percent)
8808 SDLSetWindowScaling(setup.window_scaling_percent);
8812 else if (change_fullscreen)
8814 SDLSetWindowFullscreen(setup.fullscreen);
8816 /* set setup value according to successfully changed fullscreen mode */
8817 setup.fullscreen = video.fullscreen_enabled;
8823 if (change_fullscreen ||
8824 change_window_scaling_percent)
8826 Bitmap *tmp_backbuffer = CreateBitmap(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH);
8828 /* save backbuffer content which gets lost when toggling fullscreen mode */
8829 BlitBitmap(backbuffer, tmp_backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
8831 if (change_window_scaling_percent)
8833 /* keep window mode, but change window scaling */
8834 video.fullscreen_enabled = TRUE; /* force new window scaling */
8837 /* toggle fullscreen */
8838 ChangeVideoModeIfNeeded(setup.fullscreen);
8840 /* set setup value according to successfully changed fullscreen mode */
8841 setup.fullscreen = video.fullscreen_enabled;
8843 /* restore backbuffer content from temporary backbuffer backup bitmap */
8844 BlitBitmap(tmp_backbuffer, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
8846 FreeBitmap(tmp_backbuffer);
8848 /* update visible window/screen */
8849 BlitBitmap(backbuffer, window, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
8853 void JoinRectangles(int *x, int *y, int *width, int *height,
8854 int x2, int y2, int width2, int height2)
8856 // do not join with "off-screen" rectangle
8857 if (x2 == -1 || y2 == -1)
8862 *width = MAX(*width, width2);
8863 *height = MAX(*height, height2);
8866 void SetAnimStatus(int anim_status_new)
8868 if (anim_status_new == GAME_MODE_MAIN)
8869 anim_status_new = GAME_MODE_PSEUDO_MAINONLY;
8870 else if (anim_status_new == GAME_MODE_SCORES)
8871 anim_status_new = GAME_MODE_PSEUDO_SCORESOLD;
8873 global.anim_status_next = anim_status_new;
8875 // directly set screen modes that are entered without fading
8876 if ((global.anim_status == GAME_MODE_PSEUDO_MAINONLY &&
8877 global.anim_status_next == GAME_MODE_PSEUDO_TYPENAME) ||
8878 (global.anim_status == GAME_MODE_PSEUDO_TYPENAME &&
8879 global.anim_status_next == GAME_MODE_PSEUDO_MAINONLY))
8880 global.anim_status = global.anim_status_next;
8883 void SetGameStatus(int game_status_new)
8885 if (game_status_new != game_status)
8886 game_status_last_screen = game_status;
8888 game_status = game_status_new;
8890 SetAnimStatus(game_status_new);
8893 void SetFontStatus(int game_status_new)
8895 static int last_game_status = -1;
8897 if (game_status_new != -1)
8899 // set game status for font use after storing last game status
8900 last_game_status = game_status;
8901 game_status = game_status_new;
8905 // reset game status after font use from last stored game status
8906 game_status = last_game_status;
8910 void ResetFontStatus()
8915 void ChangeViewportPropertiesIfNeeded()
8917 boolean use_mini_tilesize = (level.game_engine_type == GAME_ENGINE_TYPE_MM ?
8918 FALSE : setup.small_game_graphics);
8919 int gfx_game_mode = game_status;
8920 int gfx_game_mode2 = (game_status == GAME_MODE_EDITOR ? GAME_MODE_DEFAULT :
8922 struct RectWithBorder *vp_window = &viewport.window[gfx_game_mode];
8923 struct RectWithBorder *vp_playfield = &viewport.playfield[gfx_game_mode];
8924 struct RectWithBorder *vp_door_1 = &viewport.door_1[gfx_game_mode];
8925 struct RectWithBorder *vp_door_2 = &viewport.door_2[gfx_game_mode2];
8926 struct RectWithBorder *vp_door_3 = &viewport.door_2[GAME_MODE_EDITOR];
8927 int new_win_xsize = vp_window->width;
8928 int new_win_ysize = vp_window->height;
8929 int border_size = vp_playfield->border_size;
8930 int new_sx = vp_playfield->x + border_size;
8931 int new_sy = vp_playfield->y + border_size;
8932 int new_sxsize = vp_playfield->width - 2 * border_size;
8933 int new_sysize = vp_playfield->height - 2 * border_size;
8934 int new_real_sx = vp_playfield->x;
8935 int new_real_sy = vp_playfield->y;
8936 int new_full_sxsize = vp_playfield->width;
8937 int new_full_sysize = vp_playfield->height;
8938 int new_dx = vp_door_1->x;
8939 int new_dy = vp_door_1->y;
8940 int new_dxsize = vp_door_1->width;
8941 int new_dysize = vp_door_1->height;
8942 int new_vx = vp_door_2->x;
8943 int new_vy = vp_door_2->y;
8944 int new_vxsize = vp_door_2->width;
8945 int new_vysize = vp_door_2->height;
8946 int new_ex = vp_door_3->x;
8947 int new_ey = vp_door_3->y;
8948 int new_exsize = vp_door_3->width;
8949 int new_eysize = vp_door_3->height;
8950 int new_tilesize_var = (use_mini_tilesize ? MINI_TILESIZE : game.tile_size);
8951 int tilesize = (gfx_game_mode == GAME_MODE_PLAYING ? new_tilesize_var :
8952 gfx_game_mode == GAME_MODE_EDITOR ? MINI_TILESIZE : TILESIZE);
8953 int new_scr_fieldx = new_sxsize / tilesize;
8954 int new_scr_fieldy = new_sysize / tilesize;
8955 int new_scr_fieldx_buffers = new_sxsize / new_tilesize_var;
8956 int new_scr_fieldy_buffers = new_sysize / new_tilesize_var;
8957 boolean init_gfx_buffers = FALSE;
8958 boolean init_video_buffer = FALSE;
8959 boolean init_gadgets_and_anims = FALSE;
8960 boolean init_em_graphics = FALSE;
8962 if (new_win_xsize != WIN_XSIZE ||
8963 new_win_ysize != WIN_YSIZE)
8965 WIN_XSIZE = new_win_xsize;
8966 WIN_YSIZE = new_win_ysize;
8968 init_video_buffer = TRUE;
8969 init_gfx_buffers = TRUE;
8970 init_gadgets_and_anims = TRUE;
8972 // printf("::: video: init_video_buffer, init_gfx_buffers\n");
8975 if (new_scr_fieldx != SCR_FIELDX ||
8976 new_scr_fieldy != SCR_FIELDY)
8978 /* this always toggles between MAIN and GAME when using small tile size */
8980 SCR_FIELDX = new_scr_fieldx;
8981 SCR_FIELDY = new_scr_fieldy;
8983 // printf("::: new_scr_fieldx != SCR_FIELDX ...\n");
8994 new_sxsize != SXSIZE ||
8995 new_sysize != SYSIZE ||
8996 new_dxsize != DXSIZE ||
8997 new_dysize != DYSIZE ||
8998 new_vxsize != VXSIZE ||
8999 new_vysize != VYSIZE ||
9000 new_exsize != EXSIZE ||
9001 new_eysize != EYSIZE ||
9002 new_real_sx != REAL_SX ||
9003 new_real_sy != REAL_SY ||
9004 new_full_sxsize != FULL_SXSIZE ||
9005 new_full_sysize != FULL_SYSIZE ||
9006 new_tilesize_var != TILESIZE_VAR
9009 // ------------------------------------------------------------------------
9010 // determine next fading area for changed viewport definitions
9011 // ------------------------------------------------------------------------
9013 // start with current playfield area (default fading area)
9016 FADE_SXSIZE = FULL_SXSIZE;
9017 FADE_SYSIZE = FULL_SYSIZE;
9019 // add new playfield area if position or size has changed
9020 if (new_real_sx != REAL_SX || new_real_sy != REAL_SY ||
9021 new_full_sxsize != FULL_SXSIZE || new_full_sysize != FULL_SYSIZE)
9023 JoinRectangles(&FADE_SX, &FADE_SY, &FADE_SXSIZE, &FADE_SYSIZE,
9024 new_real_sx, new_real_sy, new_full_sxsize,new_full_sysize);
9027 // add current and new door 1 area if position or size has changed
9028 if (new_dx != DX || new_dy != DY ||
9029 new_dxsize != DXSIZE || new_dysize != DYSIZE)
9031 JoinRectangles(&FADE_SX, &FADE_SY, &FADE_SXSIZE, &FADE_SYSIZE,
9032 DX, DY, DXSIZE, DYSIZE);
9033 JoinRectangles(&FADE_SX, &FADE_SY, &FADE_SXSIZE, &FADE_SYSIZE,
9034 new_dx, new_dy, new_dxsize, new_dysize);
9037 // add current and new door 2 area if position or size has changed
9038 if (new_dx != VX || new_dy != VY ||
9039 new_dxsize != VXSIZE || new_dysize != VYSIZE)
9041 JoinRectangles(&FADE_SX, &FADE_SY, &FADE_SXSIZE, &FADE_SYSIZE,
9042 VX, VY, VXSIZE, VYSIZE);
9043 JoinRectangles(&FADE_SX, &FADE_SY, &FADE_SXSIZE, &FADE_SYSIZE,
9044 new_vx, new_vy, new_vxsize, new_vysize);
9047 // ------------------------------------------------------------------------
9048 // handle changed tile size
9049 // ------------------------------------------------------------------------
9051 if (new_tilesize_var != TILESIZE_VAR)
9053 // printf("::: new_tilesize_var != TILESIZE_VAR\n");
9055 // changing tile size invalidates scroll values of engine snapshots
9056 FreeEngineSnapshotSingle();
9058 // changing tile size requires update of graphic mapping for EM engine
9059 init_em_graphics = TRUE;
9070 SXSIZE = new_sxsize;
9071 SYSIZE = new_sysize;
9072 DXSIZE = new_dxsize;
9073 DYSIZE = new_dysize;
9074 VXSIZE = new_vxsize;
9075 VYSIZE = new_vysize;
9076 EXSIZE = new_exsize;
9077 EYSIZE = new_eysize;
9078 REAL_SX = new_real_sx;
9079 REAL_SY = new_real_sy;
9080 FULL_SXSIZE = new_full_sxsize;
9081 FULL_SYSIZE = new_full_sysize;
9082 TILESIZE_VAR = new_tilesize_var;
9084 init_gfx_buffers = TRUE;
9085 init_gadgets_and_anims = TRUE;
9087 // printf("::: viewports: init_gfx_buffers\n");
9088 // printf("::: viewports: init_gadgets_and_anims\n");
9091 if (init_gfx_buffers)
9093 // printf("::: init_gfx_buffers\n");
9095 SCR_FIELDX = new_scr_fieldx_buffers;
9096 SCR_FIELDY = new_scr_fieldy_buffers;
9100 SCR_FIELDX = new_scr_fieldx;
9101 SCR_FIELDY = new_scr_fieldy;
9103 SetDrawDeactivationMask(REDRAW_NONE);
9104 SetDrawBackgroundMask(REDRAW_FIELD);
9107 if (init_video_buffer)
9109 // printf("::: init_video_buffer\n");
9111 InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen);
9112 InitImageTextures();
9115 if (init_gadgets_and_anims)
9117 // printf("::: init_gadgets_and_anims\n");
9120 InitGlobalAnimations();
9123 if (init_em_graphics)
9125 InitGraphicInfo_EM();