1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
14 #include "libgame/libgame.h"
26 #define DEBUG_FRAME_TIME FALSE
28 // tool button identifiers
29 #define TOOL_CTRL_ID_YES 0
30 #define TOOL_CTRL_ID_NO 1
31 #define TOOL_CTRL_ID_CONFIRM 2
32 #define TOOL_CTRL_ID_PLAYER_1 3
33 #define TOOL_CTRL_ID_PLAYER_2 4
34 #define TOOL_CTRL_ID_PLAYER_3 5
35 #define TOOL_CTRL_ID_PLAYER_4 6
36 #define TOOL_CTRL_ID_TOUCH_YES 7
37 #define TOOL_CTRL_ID_TOUCH_NO 8
38 #define TOOL_CTRL_ID_TOUCH_CONFIRM 9
40 #define NUM_TOOL_BUTTONS 10
42 // constants for number of doors and door parts
44 #define NUM_PANELS NUM_DOORS
45 // #define NUM_PANELS 0
46 #define MAX_PARTS_PER_DOOR 8
47 #define MAX_DOOR_PARTS (NUM_DOORS * MAX_PARTS_PER_DOOR + NUM_PANELS)
48 #define DOOR_PART_IS_PANEL(i) ((i) >= NUM_DOORS * MAX_PARTS_PER_DOOR)
51 struct DoorPartOrderInfo
57 static struct DoorPartOrderInfo door_part_order[MAX_DOOR_PARTS];
59 struct DoorPartControlInfo
63 struct DoorPartPosInfo *pos;
66 static struct DoorPartControlInfo door_part_controls[] =
70 IMG_GFX_DOOR_1_PART_1,
75 IMG_GFX_DOOR_1_PART_2,
80 IMG_GFX_DOOR_1_PART_3,
85 IMG_GFX_DOOR_1_PART_4,
90 IMG_GFX_DOOR_1_PART_5,
95 IMG_GFX_DOOR_1_PART_6,
100 IMG_GFX_DOOR_1_PART_7,
105 IMG_GFX_DOOR_1_PART_8,
111 IMG_GFX_DOOR_2_PART_1,
116 IMG_GFX_DOOR_2_PART_2,
121 IMG_GFX_DOOR_2_PART_3,
126 IMG_GFX_DOOR_2_PART_4,
131 IMG_GFX_DOOR_2_PART_5,
136 IMG_GFX_DOOR_2_PART_6,
141 IMG_GFX_DOOR_2_PART_7,
146 IMG_GFX_DOOR_2_PART_8,
152 IMG_BACKGROUND_PANEL,
169 // forward declaration for internal use
170 static void UnmapToolButtons(void);
171 static void HandleToolButtons(struct GadgetInfo *);
172 static int el_act_dir2crm(int, int, int);
173 static int el_act2crm(int, int);
175 static struct GadgetInfo *tool_gadget[NUM_TOOL_BUTTONS];
176 static int request_gadget_id = -1;
178 static char *print_if_not_empty(int element)
180 static char *s = NULL;
181 char *token_name = element_info[element].token_name;
186 s = checked_malloc(strlen(token_name) + 10 + 1);
188 if (element != EL_EMPTY)
189 sprintf(s, "%d\t['%s']", element, token_name);
191 sprintf(s, "%d", element);
196 int getFieldbufferOffsetX_RND(int dir, int pos)
198 int full_lev_fieldx = lev_fieldx + (BorderElement != EL_EMPTY ? 2 : 0);
199 int dx = (dir & MV_HORIZONTAL ? pos : 0);
200 int dx_var = dx * TILESIZE_VAR / TILESIZE;
203 if (EVEN(SCR_FIELDX))
205 int sbx_right = SBX_Right + (BorderElement != EL_EMPTY ? 1 : 0);
206 int ffx = (scroll_x - SBX_Left) * TILEX_VAR + dx_var;
208 if (ffx < sbx_right * TILEX_VAR + TILEX_VAR / 2)
209 fx += dx_var - MIN(ffx, TILEX_VAR / 2) + TILEX_VAR;
211 fx += (dx_var > 0 ? TILEX_VAR : 0);
218 if (full_lev_fieldx <= SCR_FIELDX)
220 if (EVEN(SCR_FIELDX))
221 fx = 2 * TILEX_VAR - (ODD(lev_fieldx) ? TILEX_VAR / 2 : 0);
223 fx = 2 * TILEX_VAR - (EVEN(lev_fieldx) ? TILEX_VAR / 2 : 0);
229 int getFieldbufferOffsetY_RND(int dir, int pos)
231 int full_lev_fieldy = lev_fieldy + (BorderElement != EL_EMPTY ? 2 : 0);
232 int dy = (dir & MV_VERTICAL ? pos : 0);
233 int dy_var = dy * TILESIZE_VAR / TILESIZE;
236 if (EVEN(SCR_FIELDY))
238 int sby_lower = SBY_Lower + (BorderElement != EL_EMPTY ? 1 : 0);
239 int ffy = (scroll_y - SBY_Upper) * TILEY_VAR + dy_var;
241 if (ffy < sby_lower * TILEY_VAR + TILEY_VAR / 2)
242 fy += dy_var - MIN(ffy, TILEY_VAR / 2) + TILEY_VAR;
244 fy += (dy_var > 0 ? TILEY_VAR : 0);
251 if (full_lev_fieldy <= SCR_FIELDY)
253 if (EVEN(SCR_FIELDY))
254 fy = 2 * TILEY_VAR - (ODD(lev_fieldy) ? TILEY_VAR / 2 : 0);
256 fy = 2 * TILEY_VAR - (EVEN(lev_fieldy) ? TILEY_VAR / 2 : 0);
262 static int getLevelFromScreenX_RND(int sx)
264 int fx = getFieldbufferOffsetX_RND(ScreenMovDir, ScreenGfxPos);
267 int lx = LEVELX((px + dx) / TILESIZE_VAR);
272 static int getLevelFromScreenY_RND(int sy)
274 int fy = getFieldbufferOffsetY_RND(ScreenMovDir, ScreenGfxPos);
277 int ly = LEVELY((py + dy) / TILESIZE_VAR);
282 static int getLevelFromScreenX_EM(int sx)
284 int level_xsize = level.native_em_level->cav->width;
285 int full_xsize = level_xsize * TILESIZE_VAR;
287 sx -= (full_xsize < SXSIZE ? (SXSIZE - full_xsize) / 2 : 0);
289 int fx = getFieldbufferOffsetX_EM();
292 int lx = LEVELX((px + dx) / TILESIZE_VAR);
297 static int getLevelFromScreenY_EM(int sy)
299 int level_ysize = level.native_em_level->cav->height;
300 int full_ysize = level_ysize * TILESIZE_VAR;
302 sy -= (full_ysize < SYSIZE ? (SYSIZE - full_ysize) / 2 : 0);
304 int fy = getFieldbufferOffsetY_EM();
307 int ly = LEVELY((py + dy) / TILESIZE_VAR);
312 static int getLevelFromScreenX_SP(int sx)
314 int menBorder = setup.sp_show_border_elements;
315 int level_xsize = level.native_sp_level->width;
316 int full_xsize = (level_xsize - (menBorder ? 0 : 1)) * TILESIZE_VAR;
318 sx += (full_xsize < SXSIZE ? (SXSIZE - full_xsize) / 2 : 0);
320 int fx = getFieldbufferOffsetX_SP();
323 int lx = LEVELX((px + dx) / TILESIZE_VAR);
328 static int getLevelFromScreenY_SP(int sy)
330 int menBorder = setup.sp_show_border_elements;
331 int level_ysize = level.native_sp_level->height;
332 int full_ysize = (level_ysize - (menBorder ? 0 : 1)) * TILESIZE_VAR;
334 sy += (full_ysize < SYSIZE ? (SYSIZE - full_ysize) / 2 : 0);
336 int fy = getFieldbufferOffsetY_SP();
339 int ly = LEVELY((py + dy) / TILESIZE_VAR);
344 static int getLevelFromScreenX_MM(int sx)
346 int level_xsize = level.native_mm_level->fieldx;
347 int full_xsize = level_xsize * TILESIZE_VAR;
349 sx -= (full_xsize < SXSIZE ? (SXSIZE - full_xsize) / 2 : 0);
352 int lx = (px + TILESIZE_VAR) / TILESIZE_VAR - 1;
357 static int getLevelFromScreenY_MM(int sy)
359 int level_ysize = level.native_mm_level->fieldy;
360 int full_ysize = level_ysize * TILESIZE_VAR;
362 sy -= (full_ysize < SYSIZE ? (SYSIZE - full_ysize) / 2 : 0);
365 int ly = (py + TILESIZE_VAR) / TILESIZE_VAR - 1;
370 int getLevelFromScreenX(int x)
372 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
373 return getLevelFromScreenX_EM(x);
374 if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
375 return getLevelFromScreenX_SP(x);
376 if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
377 return getLevelFromScreenX_MM(x);
379 return getLevelFromScreenX_RND(x);
382 int getLevelFromScreenY(int y)
384 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
385 return getLevelFromScreenY_EM(y);
386 if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
387 return getLevelFromScreenY_SP(y);
388 if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
389 return getLevelFromScreenY_MM(y);
391 return getLevelFromScreenY_RND(y);
394 void DumpTile(int x, int y)
401 Info("Field Info: SCREEN(%d, %d), LEVEL(%d, %d)", sx, sy, x, y);
404 if (!IN_LEV_FIELD(x, y))
406 Info("(not in level field)");
412 token_name = element_info[Tile[x][y]].token_name;
414 Info("Tile: %d\t['%s']", Tile[x][y], token_name);
415 Info("Back: %s", print_if_not_empty(Back[x][y]));
416 Info("Store: %s", print_if_not_empty(Store[x][y]));
417 Info("Store2: %s", print_if_not_empty(Store2[x][y]));
418 Info("StorePlayer: %s", print_if_not_empty(StorePlayer[x][y]));
419 Info("MovPos: %d", MovPos[x][y]);
420 Info("MovDir: %d", MovDir[x][y]);
421 Info("MovDelay: %d", MovDelay[x][y]);
422 Info("ChangeDelay: %d", ChangeDelay[x][y]);
423 Info("CustomValue: %d", CustomValue[x][y]);
424 Info("GfxElement: %d", GfxElement[x][y]);
425 Info("GfxAction: %d", GfxAction[x][y]);
426 Info("GfxFrame: %d [%d]", GfxFrame[x][y], FrameCounter);
427 Info("Player x/y: %d, %d", local_player->jx, local_player->jy);
431 void DumpTileFromScreen(int sx, int sy)
433 int lx = getLevelFromScreenX(sx);
434 int ly = getLevelFromScreenY(sy);
439 void SetDrawtoField(int mode)
441 if (mode == DRAW_TO_FIELDBUFFER)
447 BX2 = SCR_FIELDX + 1;
448 BY2 = SCR_FIELDY + 1;
450 drawto_field = fieldbuffer;
452 else // DRAW_TO_BACKBUFFER
458 BX2 = SCR_FIELDX - 1;
459 BY2 = SCR_FIELDY - 1;
461 drawto_field = backbuffer;
465 static void RedrawPlayfield_RND(void)
467 if (game.envelope_active)
470 DrawLevel(REDRAW_ALL);
474 void RedrawPlayfield(void)
476 if (game_status != GAME_MODE_PLAYING)
479 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
480 RedrawPlayfield_EM(TRUE);
481 else if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
482 RedrawPlayfield_SP(TRUE);
483 else if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
484 RedrawPlayfield_MM();
485 else if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
486 RedrawPlayfield_RND();
488 BlitScreenToBitmap(backbuffer);
490 BlitBitmap(drawto, window, gfx.sx, gfx.sy, gfx.sxsize, gfx.sysize,
494 static void DrawMaskedBorderExt_Rect(int x, int y, int width, int height,
497 Bitmap *src_bitmap = getGlobalBorderBitmapFromStatus(global.border_status);
498 Bitmap *dst_bitmap = gfx.masked_border_bitmap_ptr;
500 if (x == -1 && y == -1)
503 if (draw_target == DRAW_TO_SCREEN)
504 BlitToScreenMasked(src_bitmap, x, y, width, height, x, y);
506 BlitBitmapMasked(src_bitmap, dst_bitmap, x, y, width, height, x, y);
509 static void DrawMaskedBorderExt_FIELD(int draw_target)
511 if (global.border_status >= GAME_MODE_MAIN &&
512 global.border_status <= GAME_MODE_PLAYING &&
513 border.draw_masked[global.border_status])
514 DrawMaskedBorderExt_Rect(REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE,
518 static void DrawMaskedBorderExt_DOOR_1(int draw_target)
520 // when drawing to backbuffer, never draw border over open doors
521 if (draw_target == DRAW_TO_BACKBUFFER &&
522 (GetDoorState() & DOOR_OPEN_1))
525 if (border.draw_masked[GFX_SPECIAL_ARG_DOOR] &&
526 (global.border_status != GAME_MODE_EDITOR ||
527 border.draw_masked[GFX_SPECIAL_ARG_EDITOR]))
528 DrawMaskedBorderExt_Rect(DX, DY, DXSIZE, DYSIZE, draw_target);
531 static void DrawMaskedBorderExt_DOOR_2(int draw_target)
533 // when drawing to backbuffer, never draw border over open doors
534 if (draw_target == DRAW_TO_BACKBUFFER &&
535 (GetDoorState() & DOOR_OPEN_2))
538 if (border.draw_masked[GFX_SPECIAL_ARG_DOOR] &&
539 global.border_status != GAME_MODE_EDITOR)
540 DrawMaskedBorderExt_Rect(VX, VY, VXSIZE, VYSIZE, draw_target);
543 static void DrawMaskedBorderExt_DOOR_3(int draw_target)
545 // currently not available
548 static void DrawMaskedBorderExt_ALL(int draw_target)
550 DrawMaskedBorderExt_FIELD(draw_target);
551 DrawMaskedBorderExt_DOOR_1(draw_target);
552 DrawMaskedBorderExt_DOOR_2(draw_target);
553 DrawMaskedBorderExt_DOOR_3(draw_target);
556 static void DrawMaskedBorderExt(int redraw_mask, int draw_target)
558 // never draw masked screen borders on borderless screens
559 if (global.border_status == GAME_MODE_LOADING ||
560 global.border_status == GAME_MODE_TITLE)
563 if (redraw_mask & REDRAW_ALL)
564 DrawMaskedBorderExt_ALL(draw_target);
567 if (redraw_mask & REDRAW_FIELD)
568 DrawMaskedBorderExt_FIELD(draw_target);
569 if (redraw_mask & REDRAW_DOOR_1)
570 DrawMaskedBorderExt_DOOR_1(draw_target);
571 if (redraw_mask & REDRAW_DOOR_2)
572 DrawMaskedBorderExt_DOOR_2(draw_target);
573 if (redraw_mask & REDRAW_DOOR_3)
574 DrawMaskedBorderExt_DOOR_3(draw_target);
578 void DrawMaskedBorder_FIELD(void)
580 DrawMaskedBorderExt_FIELD(DRAW_TO_BACKBUFFER);
583 void DrawMaskedBorder(int redraw_mask)
585 DrawMaskedBorderExt(redraw_mask, DRAW_TO_BACKBUFFER);
588 void DrawMaskedBorderToTarget(int draw_target)
590 if (draw_target == DRAW_TO_BACKBUFFER ||
591 draw_target == DRAW_TO_SCREEN)
593 DrawMaskedBorderExt(REDRAW_ALL, draw_target);
597 int last_border_status = global.border_status;
599 if (draw_target == DRAW_TO_FADE_SOURCE)
601 global.border_status = gfx.fade_border_source_status;
602 gfx.masked_border_bitmap_ptr = gfx.fade_bitmap_source;
604 else if (draw_target == DRAW_TO_FADE_TARGET)
606 global.border_status = gfx.fade_border_target_status;
607 gfx.masked_border_bitmap_ptr = gfx.fade_bitmap_target;
610 DrawMaskedBorderExt(REDRAW_ALL, draw_target);
612 global.border_status = last_border_status;
613 gfx.masked_border_bitmap_ptr = backbuffer;
617 void DrawTileCursor(int draw_target)
623 int graphic = IMG_GLOBAL_TILE_CURSOR;
625 int tilesize = TILESIZE_VAR;
626 int width = tilesize;
627 int height = tilesize;
629 if (game_status != GAME_MODE_PLAYING)
632 if (!tile_cursor.enabled ||
636 if (tile_cursor.moving)
638 int step = TILESIZE_VAR / 4;
639 int dx = tile_cursor.target_x - tile_cursor.x;
640 int dy = tile_cursor.target_y - tile_cursor.y;
643 tile_cursor.x = tile_cursor.target_x;
645 tile_cursor.x += SIGN(dx) * step;
648 tile_cursor.y = tile_cursor.target_y;
650 tile_cursor.y += SIGN(dy) * step;
652 if (tile_cursor.x == tile_cursor.target_x &&
653 tile_cursor.y == tile_cursor.target_y)
654 tile_cursor.moving = FALSE;
657 dst_x = tile_cursor.x;
658 dst_y = tile_cursor.y;
660 frame = getGraphicAnimationFrame(graphic, -1);
662 getSizedGraphicSource(graphic, frame, tilesize, &src_bitmap, &src_x, &src_y);
665 (draw_target == DRAW_TO_FADE_SOURCE ? gfx.fade_bitmap_source :
666 draw_target == DRAW_TO_FADE_TARGET ? gfx.fade_bitmap_target : NULL);
668 if (draw_target == DRAW_TO_SCREEN)
669 BlitToScreenMasked(src_bitmap, src_x, src_y, width, height, dst_x, dst_y);
671 BlitBitmapMasked(src_bitmap, fade_bitmap, src_x, src_y, width, height,
675 void BlitScreenToBitmapExt_RND(Bitmap *target_bitmap, int fx, int fy)
677 BlitBitmap(drawto_field, target_bitmap, fx, fy, SXSIZE, SYSIZE, SX, SY);
680 void BlitScreenToBitmap_RND(Bitmap *target_bitmap)
682 int fx = getFieldbufferOffsetX_RND(ScreenMovDir, ScreenGfxPos);
683 int fy = getFieldbufferOffsetY_RND(ScreenMovDir, ScreenGfxPos);
685 BlitScreenToBitmapExt_RND(target_bitmap, fx, fy);
688 void BlitScreenToBitmap(Bitmap *target_bitmap)
690 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
691 BlitScreenToBitmap_EM(target_bitmap);
692 else if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
693 BlitScreenToBitmap_SP(target_bitmap);
694 else if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
695 BlitScreenToBitmap_MM(target_bitmap);
696 else if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
697 BlitScreenToBitmap_RND(target_bitmap);
699 redraw_mask |= REDRAW_FIELD;
702 static void DrawFramesPerSecond(void)
705 int font_nr = FONT_TEXT_2;
706 int font_width = getFontWidth(font_nr);
707 int draw_deactivation_mask = GetDrawDeactivationMask();
708 boolean draw_masked = (draw_deactivation_mask == REDRAW_NONE);
710 // draw FPS with leading space (needed if field buffer deactivated)
711 sprintf(text, " %04.1f fps", global.frames_per_second);
713 // override draw deactivation mask (required for invisible warp mode)
714 SetDrawDeactivationMask(REDRAW_NONE);
716 // draw opaque FPS if field buffer deactivated, else draw masked FPS
717 DrawTextExt(backbuffer, SX + SXSIZE - font_width * strlen(text), SY, text,
718 font_nr, (draw_masked ? BLIT_MASKED : BLIT_OPAQUE));
720 // set draw deactivation mask to previous value
721 SetDrawDeactivationMask(draw_deactivation_mask);
723 // force full-screen redraw in this frame
724 redraw_mask = REDRAW_ALL;
728 static void PrintFrameTimeDebugging(void)
730 static unsigned int last_counter = 0;
731 unsigned int counter = Counter();
732 int diff_1 = counter - last_counter;
733 int diff_2 = diff_1 - GAME_FRAME_DELAY;
735 int diff_2_cut = MIN(ABS(diff_2), diff_2_max);
736 char diff_bar[2 * diff_2_max + 5];
740 diff_bar[pos++] = (diff_2 < -diff_2_max ? '<' : ' ');
742 for (i = 0; i < diff_2_max; i++)
743 diff_bar[pos++] = (diff_2 >= 0 ? ' ' :
744 i >= diff_2_max - diff_2_cut ? '-' : ' ');
746 diff_bar[pos++] = '|';
748 for (i = 0; i < diff_2_max; i++)
749 diff_bar[pos++] = (diff_2 <= 0 ? ' ' : i < diff_2_cut ? '+' : ' ');
751 diff_bar[pos++] = (diff_2 > diff_2_max ? '>' : ' ');
753 diff_bar[pos++] = '\0';
755 Debug("time:frame", "%06d [%02d] [%c%02d] %s",
758 (diff_2 < 0 ? '-' : diff_2 > 0 ? '+' : ' '), ABS(diff_2),
761 last_counter = counter;
765 static int unifiedRedrawMask(int mask)
767 if (mask & REDRAW_ALL)
770 if (mask & REDRAW_FIELD && mask & REDRAW_DOORS)
776 static boolean equalRedrawMasks(int mask_1, int mask_2)
778 return unifiedRedrawMask(mask_1) == unifiedRedrawMask(mask_2);
781 void BackToFront(void)
783 static int last_redraw_mask = REDRAW_NONE;
785 // force screen redraw in every frame to continue drawing global animations
786 // (but always use the last redraw mask to prevent unwanted side effects)
787 if (redraw_mask == REDRAW_NONE)
788 redraw_mask = last_redraw_mask;
790 last_redraw_mask = redraw_mask;
793 // masked border now drawn immediately when blitting backbuffer to window
795 // draw masked border to all viewports, if defined
796 DrawMaskedBorder(redraw_mask);
799 // draw frames per second (only if debug mode is enabled)
800 if (redraw_mask & REDRAW_FPS)
801 DrawFramesPerSecond();
803 // remove playfield redraw before potentially merging with doors redraw
804 if (DrawingDeactivated(REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE))
805 redraw_mask &= ~REDRAW_FIELD;
807 // redraw complete window if both playfield and (some) doors need redraw
808 if (redraw_mask & REDRAW_FIELD && redraw_mask & REDRAW_DOORS)
809 redraw_mask = REDRAW_ALL;
811 /* although redrawing the whole window would be fine for normal gameplay,
812 being able to only redraw the playfield is required for deactivating
813 certain drawing areas (mainly playfield) to work, which is needed for
814 warp-forward to be fast enough (by skipping redraw of most frames) */
816 if (redraw_mask & REDRAW_ALL)
818 BlitBitmap(backbuffer, window, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
820 else if (redraw_mask & REDRAW_FIELD)
822 BlitBitmap(backbuffer, window,
823 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, REAL_SX, REAL_SY);
825 else if (redraw_mask & REDRAW_DOORS)
827 // merge door areas to prevent calling screen redraw more than once
833 if (redraw_mask & REDRAW_DOOR_1)
837 x2 = MAX(x2, DX + DXSIZE);
838 y2 = MAX(y2, DY + DYSIZE);
841 if (redraw_mask & REDRAW_DOOR_2)
845 x2 = MAX(x2, VX + VXSIZE);
846 y2 = MAX(y2, VY + VYSIZE);
849 if (redraw_mask & REDRAW_DOOR_3)
853 x2 = MAX(x2, EX + EXSIZE);
854 y2 = MAX(y2, EY + EYSIZE);
857 // make sure that at least one pixel is blitted, and inside the screen
858 // (else nothing is blitted, causing the animations not to be updated)
859 x1 = MIN(MAX(0, x1), WIN_XSIZE - 1);
860 y1 = MIN(MAX(0, y1), WIN_YSIZE - 1);
861 x2 = MIN(MAX(1, x2), WIN_XSIZE);
862 y2 = MIN(MAX(1, y2), WIN_YSIZE);
864 BlitBitmap(backbuffer, window, x1, y1, x2 - x1, y2 - y1, x1, y1);
867 redraw_mask = REDRAW_NONE;
870 PrintFrameTimeDebugging();
874 void BackToFront_WithFrameDelay(unsigned int frame_delay_value)
876 unsigned int frame_delay_value_old = GetVideoFrameDelay();
878 SetVideoFrameDelay(frame_delay_value);
882 SetVideoFrameDelay(frame_delay_value_old);
885 static int fade_type_skip = FADE_TYPE_NONE;
887 static void FadeExt(int fade_mask, int fade_mode, int fade_type)
889 void (*draw_border_function)(void) = NULL;
890 int x, y, width, height;
891 int fade_delay, post_delay;
893 if (fade_type == FADE_TYPE_FADE_OUT)
895 if (fade_type_skip != FADE_TYPE_NONE)
897 // skip all fade operations until specified fade operation
898 if (fade_type & fade_type_skip)
899 fade_type_skip = FADE_TYPE_NONE;
904 if (fading.fade_mode & FADE_TYPE_TRANSFORM)
908 redraw_mask |= fade_mask;
910 if (fade_type == FADE_TYPE_SKIP)
912 fade_type_skip = fade_mode;
917 fade_delay = fading.fade_delay;
918 post_delay = (fade_mode == FADE_MODE_FADE_OUT ? fading.post_delay : 0);
920 if (fade_type_skip != FADE_TYPE_NONE)
922 // skip all fade operations until specified fade operation
923 if (fade_type & fade_type_skip)
924 fade_type_skip = FADE_TYPE_NONE;
929 if (global.autoplay_leveldir)
934 if (fade_mask == REDRAW_FIELD)
939 height = FADE_SYSIZE;
941 if (border.draw_masked_when_fading)
942 draw_border_function = DrawMaskedBorder_FIELD; // update when fading
944 DrawMaskedBorder_FIELD(); // draw once
954 // when switching screens without fading, set fade delay to zero
955 if (!setup.fade_screens || fading.fade_mode == FADE_MODE_NONE)
958 // do not display black frame when fading out without fade delay
959 if (fade_mode == FADE_MODE_FADE_OUT && fade_delay == 0)
962 FadeRectangle(x, y, width, height, fade_mode, fade_delay, post_delay,
963 draw_border_function);
965 redraw_mask &= ~fade_mask;
967 ClearAutoRepeatKeyEvents();
970 static void SetScreenStates_BeforeFadingIn(void)
972 // temporarily set screen mode for animations to screen after fading in
973 global.anim_status = global.anim_status_next;
975 // store backbuffer with all animations that will be started after fading in
976 PrepareFadeBitmap(DRAW_TO_FADE_TARGET);
978 // set screen mode for animations back to fading
979 global.anim_status = GAME_MODE_PSEUDO_FADING;
982 static void SetScreenStates_AfterFadingIn(void)
984 // store new source screen (to use correct masked border for fading)
985 gfx.fade_border_source_status = global.border_status;
987 global.anim_status = global.anim_status_next;
990 static void SetScreenStates_BeforeFadingOut(void)
992 // store new target screen (to use correct masked border for fading)
993 gfx.fade_border_target_status = game_status;
995 // set screen mode for animations to fading
996 global.anim_status = GAME_MODE_PSEUDO_FADING;
998 // store backbuffer with all animations that will be stopped for fading out
999 PrepareFadeBitmap(DRAW_TO_FADE_SOURCE);
1002 static void SetScreenStates_AfterFadingOut(void)
1004 global.border_status = game_status;
1007 void FadeIn(int fade_mask)
1009 SetScreenStates_BeforeFadingIn();
1012 DrawMaskedBorder(REDRAW_ALL);
1015 if (fading.fade_mode & FADE_TYPE_TRANSFORM)
1016 FadeExt(fade_mask, fading.fade_mode, FADE_TYPE_FADE_IN);
1018 FadeExt(fade_mask, FADE_MODE_FADE_IN, FADE_TYPE_FADE_IN);
1022 FADE_SXSIZE = FULL_SXSIZE;
1023 FADE_SYSIZE = FULL_SYSIZE;
1025 // activate virtual buttons depending on upcoming game status
1026 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS) &&
1027 game_status == GAME_MODE_PLAYING && !tape.playing)
1028 SetOverlayActive(TRUE);
1030 SetScreenStates_AfterFadingIn();
1032 // force update of global animation status in case of rapid screen changes
1033 redraw_mask = REDRAW_ALL;
1037 void FadeOut(int fade_mask)
1039 // update screen if areas covered by "fade_mask" and "redraw_mask" differ
1040 if (!equalRedrawMasks(fade_mask, redraw_mask) &&
1041 fade_type_skip != FADE_MODE_SKIP_FADE_OUT)
1044 SetScreenStates_BeforeFadingOut();
1046 SetTileCursorActive(FALSE);
1047 SetOverlayActive(FALSE);
1050 DrawMaskedBorder(REDRAW_ALL);
1053 if (fading.fade_mode & FADE_TYPE_TRANSFORM)
1054 FadeExt(fade_mask, fading.fade_mode, FADE_TYPE_FADE_OUT);
1056 FadeExt(fade_mask, FADE_MODE_FADE_OUT, FADE_TYPE_FADE_OUT);
1058 SetScreenStates_AfterFadingOut();
1061 static void FadeSetLeaveNext(struct TitleFadingInfo fading_leave, boolean set)
1063 static struct TitleFadingInfo fading_leave_stored;
1066 fading_leave_stored = fading_leave;
1068 fading = fading_leave_stored;
1071 void FadeSetEnterMenu(void)
1073 fading = menu.enter_menu;
1075 FadeSetLeaveNext(fading, TRUE); // (keep same fade mode)
1078 void FadeSetLeaveMenu(void)
1080 fading = menu.leave_menu;
1082 FadeSetLeaveNext(fading, TRUE); // (keep same fade mode)
1085 void FadeSetEnterScreen(void)
1087 fading = menu.enter_screen[game_status];
1089 FadeSetLeaveNext(menu.leave_screen[game_status], TRUE); // store
1092 void FadeSetNextScreen(void)
1094 fading = menu.next_screen[game_status];
1096 // (do not overwrite fade mode set by FadeSetEnterScreen)
1097 // FadeSetLeaveNext(fading, TRUE); // (keep same fade mode)
1100 void FadeSetLeaveScreen(void)
1102 FadeSetLeaveNext(menu.leave_screen[game_status], FALSE); // recall
1105 void FadeSetFromType(int type)
1107 if (type & TYPE_ENTER_SCREEN)
1108 FadeSetEnterScreen();
1109 else if (type & TYPE_ENTER)
1111 else if (type & TYPE_LEAVE)
1115 void FadeSetDisabled(void)
1117 static struct TitleFadingInfo fading_none = { FADE_MODE_NONE, -1, -1, -1 };
1119 fading = fading_none;
1122 void FadeSkipNextFadeIn(void)
1124 FadeExt(0, FADE_MODE_SKIP_FADE_IN, FADE_TYPE_SKIP);
1127 void FadeSkipNextFadeOut(void)
1129 FadeExt(0, FADE_MODE_SKIP_FADE_OUT, FADE_TYPE_SKIP);
1132 static Bitmap *getBitmapFromGraphicOrDefault(int graphic, int default_graphic)
1134 if (graphic == IMG_UNDEFINED)
1137 boolean redefined = getImageListEntryFromImageID(graphic)->redefined;
1139 return (graphic_info[graphic].bitmap != NULL || redefined ?
1140 graphic_info[graphic].bitmap :
1141 graphic_info[default_graphic].bitmap);
1144 static Bitmap *getBackgroundBitmap(int graphic)
1146 return getBitmapFromGraphicOrDefault(graphic, IMG_BACKGROUND);
1149 static Bitmap *getGlobalBorderBitmap(int graphic)
1151 return getBitmapFromGraphicOrDefault(graphic, IMG_GLOBAL_BORDER);
1154 Bitmap *getGlobalBorderBitmapFromStatus(int status)
1157 (status == GAME_MODE_MAIN ||
1158 status == GAME_MODE_PSEUDO_TYPENAME ? IMG_GLOBAL_BORDER_MAIN :
1159 status == GAME_MODE_SCORES ? IMG_GLOBAL_BORDER_SCORES :
1160 status == GAME_MODE_EDITOR ? IMG_GLOBAL_BORDER_EDITOR :
1161 status == GAME_MODE_PLAYING ? IMG_GLOBAL_BORDER_PLAYING :
1164 return getGlobalBorderBitmap(graphic);
1167 void SetWindowBackgroundImageIfDefined(int graphic)
1169 if (graphic_info[graphic].bitmap)
1170 SetWindowBackgroundBitmap(graphic_info[graphic].bitmap);
1173 void SetMainBackgroundImageIfDefined(int graphic)
1175 if (graphic_info[graphic].bitmap)
1176 SetMainBackgroundBitmap(graphic_info[graphic].bitmap);
1179 void SetDoorBackgroundImageIfDefined(int graphic)
1181 if (graphic_info[graphic].bitmap)
1182 SetDoorBackgroundBitmap(graphic_info[graphic].bitmap);
1185 void SetWindowBackgroundImage(int graphic)
1187 SetWindowBackgroundBitmap(getBackgroundBitmap(graphic));
1190 void SetMainBackgroundImage(int graphic)
1192 SetMainBackgroundBitmap(getBackgroundBitmap(graphic));
1195 void SetDoorBackgroundImage(int graphic)
1197 SetDoorBackgroundBitmap(getBackgroundBitmap(graphic));
1200 void SetPanelBackground(void)
1202 struct GraphicInfo *gfx = &graphic_info[IMG_BACKGROUND_PANEL];
1204 BlitBitmapTiled(gfx->bitmap, bitmap_db_panel, gfx->src_x, gfx->src_y,
1205 gfx->width, gfx->height, 0, 0, DXSIZE, DYSIZE);
1207 SetDoorBackgroundBitmap(bitmap_db_panel);
1210 void DrawBackground(int x, int y, int width, int height)
1212 // "drawto" might still point to playfield buffer here (hall of fame)
1213 ClearRectangleOnBackground(backbuffer, x, y, width, height);
1215 if (IN_GFX_FIELD_FULL(x, y))
1216 redraw_mask |= REDRAW_FIELD;
1217 else if (IN_GFX_DOOR_1(x, y))
1218 redraw_mask |= REDRAW_DOOR_1;
1219 else if (IN_GFX_DOOR_2(x, y))
1220 redraw_mask |= REDRAW_DOOR_2;
1221 else if (IN_GFX_DOOR_3(x, y))
1222 redraw_mask |= REDRAW_DOOR_3;
1225 void DrawBackgroundForFont(int x, int y, int width, int height, int font_nr)
1227 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
1229 if (font->bitmap == NULL)
1232 DrawBackground(x, y, width, height);
1235 void DrawBackgroundForGraphic(int x, int y, int width, int height, int graphic)
1237 struct GraphicInfo *g = &graphic_info[graphic];
1239 if (g->bitmap == NULL)
1242 DrawBackground(x, y, width, height);
1245 static int game_status_last = -1;
1246 static Bitmap *global_border_bitmap_last = NULL;
1247 static Bitmap *global_border_bitmap = NULL;
1248 static int real_sx_last = -1, real_sy_last = -1;
1249 static int full_sxsize_last = -1, full_sysize_last = -1;
1250 static int dx_last = -1, dy_last = -1;
1251 static int dxsize_last = -1, dysize_last = -1;
1252 static int vx_last = -1, vy_last = -1;
1253 static int vxsize_last = -1, vysize_last = -1;
1254 static int ex_last = -1, ey_last = -1;
1255 static int exsize_last = -1, eysize_last = -1;
1257 boolean CheckIfGlobalBorderHasChanged(void)
1259 // if game status has not changed, global border has not changed either
1260 if (game_status == game_status_last)
1263 // determine and store new global border bitmap for current game status
1264 global_border_bitmap = getGlobalBorderBitmapFromStatus(game_status);
1266 return (global_border_bitmap_last != global_border_bitmap);
1269 #define ONLY_REDRAW_GLOBAL_BORDER_IF_NEEDED 0
1271 #if ONLY_REDRAW_GLOBAL_BORDER_IF_NEEDED
1272 static boolean CheckIfGlobalBorderRedrawIsNeeded(void)
1274 // if game status has not changed, nothing has to be redrawn
1275 if (game_status == game_status_last)
1278 // redraw if last screen was title screen
1279 if (game_status_last == GAME_MODE_TITLE)
1282 // redraw if global screen border has changed
1283 if (CheckIfGlobalBorderHasChanged())
1286 // redraw if position or size of playfield area has changed
1287 if (real_sx_last != REAL_SX || real_sy_last != REAL_SY ||
1288 full_sxsize_last != FULL_SXSIZE || full_sysize_last != FULL_SYSIZE)
1291 // redraw if position or size of door area has changed
1292 if (dx_last != DX || dy_last != DY ||
1293 dxsize_last != DXSIZE || dysize_last != DYSIZE)
1296 // redraw if position or size of tape area has changed
1297 if (vx_last != VX || vy_last != VY ||
1298 vxsize_last != VXSIZE || vysize_last != VYSIZE)
1301 // redraw if position or size of editor area has changed
1302 if (ex_last != EX || ey_last != EY ||
1303 exsize_last != EXSIZE || eysize_last != EYSIZE)
1310 static void RedrawGlobalBorderFromBitmap(Bitmap *bitmap)
1313 BlitBitmap(bitmap, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
1315 ClearRectangle(backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE);
1318 void RedrawGlobalBorder(void)
1320 Bitmap *bitmap = getGlobalBorderBitmapFromStatus(game_status);
1322 RedrawGlobalBorderFromBitmap(bitmap);
1324 redraw_mask = REDRAW_ALL;
1327 static void RedrawGlobalBorderIfNeeded(void)
1329 #if ONLY_REDRAW_GLOBAL_BORDER_IF_NEEDED
1330 if (game_status == game_status_last)
1334 // copy current draw buffer to later copy back areas that have not changed
1335 if (game_status_last != GAME_MODE_TITLE)
1336 BlitBitmap(backbuffer, bitmap_db_store_1, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
1338 #if ONLY_REDRAW_GLOBAL_BORDER_IF_NEEDED
1339 if (CheckIfGlobalBorderRedrawIsNeeded())
1341 // determine and store new global border bitmap for current game status
1342 global_border_bitmap = getGlobalBorderBitmapFromStatus(game_status);
1345 // redraw global screen border (or clear, if defined to be empty)
1346 RedrawGlobalBorderFromBitmap(global_border_bitmap);
1348 if (game_status == GAME_MODE_EDITOR)
1349 DrawSpecialEditorDoor();
1351 // copy previous playfield and door areas, if they are defined on both
1352 // previous and current screen and if they still have the same size
1354 if (real_sx_last != -1 && real_sy_last != -1 &&
1355 REAL_SX != -1 && REAL_SY != -1 &&
1356 full_sxsize_last == FULL_SXSIZE && full_sysize_last == FULL_SYSIZE)
1357 BlitBitmap(bitmap_db_store_1, backbuffer,
1358 real_sx_last, real_sy_last, FULL_SXSIZE, FULL_SYSIZE,
1361 if (dx_last != -1 && dy_last != -1 &&
1362 DX != -1 && DY != -1 &&
1363 dxsize_last == DXSIZE && dysize_last == DYSIZE)
1364 BlitBitmap(bitmap_db_store_1, backbuffer,
1365 dx_last, dy_last, DXSIZE, DYSIZE, DX, DY);
1367 if (game_status != GAME_MODE_EDITOR)
1369 if (vx_last != -1 && vy_last != -1 &&
1370 VX != -1 && VY != -1 &&
1371 vxsize_last == VXSIZE && vysize_last == VYSIZE)
1372 BlitBitmap(bitmap_db_store_1, backbuffer,
1373 vx_last, vy_last, VXSIZE, VYSIZE, VX, VY);
1377 if (ex_last != -1 && ey_last != -1 &&
1378 EX != -1 && EY != -1 &&
1379 exsize_last == EXSIZE && eysize_last == EYSIZE)
1380 BlitBitmap(bitmap_db_store_1, backbuffer,
1381 ex_last, ey_last, EXSIZE, EYSIZE, EX, EY);
1384 redraw_mask = REDRAW_ALL;
1387 game_status_last = game_status;
1389 global_border_bitmap_last = global_border_bitmap;
1391 real_sx_last = REAL_SX;
1392 real_sy_last = REAL_SY;
1393 full_sxsize_last = FULL_SXSIZE;
1394 full_sysize_last = FULL_SYSIZE;
1397 dxsize_last = DXSIZE;
1398 dysize_last = DYSIZE;
1401 vxsize_last = VXSIZE;
1402 vysize_last = VYSIZE;
1405 exsize_last = EXSIZE;
1406 eysize_last = EYSIZE;
1409 void ClearField(void)
1411 RedrawGlobalBorderIfNeeded();
1413 // !!! "drawto" might still point to playfield buffer here (see above) !!!
1414 // (when entering hall of fame after playing)
1415 DrawBackground(REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
1417 // !!! maybe this should be done before clearing the background !!!
1418 if (game_status == GAME_MODE_PLAYING)
1420 ClearRectangle(fieldbuffer, 0, 0, FXSIZE, FYSIZE);
1421 SetDrawtoField(DRAW_TO_FIELDBUFFER);
1425 SetDrawtoField(DRAW_TO_BACKBUFFER);
1429 void MarkTileDirty(int x, int y)
1431 redraw_mask |= REDRAW_FIELD;
1434 void SetBorderElement(void)
1438 BorderElement = EL_EMPTY;
1440 // only the R'n'D game engine may use an additional steelwall border
1441 if (level.game_engine_type != GAME_ENGINE_TYPE_RND)
1444 for (y = 0; y < lev_fieldy && BorderElement == EL_EMPTY; y++)
1446 for (x = 0; x < lev_fieldx; x++)
1448 if (!IS_INDESTRUCTIBLE(Tile[x][y]))
1449 BorderElement = EL_STEELWALL;
1451 if (y != 0 && y != lev_fieldy - 1 && x != lev_fieldx - 1)
1457 void FloodFillLevelExt(int from_x, int from_y, int fill_element,
1458 int max_array_fieldx, int max_array_fieldy,
1459 short field[max_array_fieldx][max_array_fieldy],
1460 int max_fieldx, int max_fieldy)
1464 static int check[4][2] = { { -1, 0 }, { 0, -1 }, { 1, 0 }, { 0, 1 } };
1465 static int safety = 0;
1467 // check if starting field still has the desired content
1468 if (field[from_x][from_y] == fill_element)
1473 if (safety > max_fieldx * max_fieldy)
1474 Fail("Something went wrong in 'FloodFill()'. Please debug.");
1476 old_element = field[from_x][from_y];
1477 field[from_x][from_y] = fill_element;
1479 for (i = 0; i < 4; i++)
1481 x = from_x + check[i][0];
1482 y = from_y + check[i][1];
1484 if (IN_FIELD(x, y, max_fieldx, max_fieldy) && field[x][y] == old_element)
1485 FloodFillLevelExt(x, y, fill_element, max_array_fieldx, max_array_fieldy,
1486 field, max_fieldx, max_fieldy);
1492 void FloodFillLevel(int from_x, int from_y, int fill_element,
1493 short field[MAX_LEV_FIELDX][MAX_LEV_FIELDY],
1494 int max_fieldx, int max_fieldy)
1496 FloodFillLevelExt(from_x, from_y, fill_element,
1497 MAX_LEV_FIELDX, MAX_LEV_FIELDY, field,
1498 max_fieldx, max_fieldy);
1501 void SetRandomAnimationValue(int x, int y)
1503 gfx.anim_random_frame = GfxRandom[x][y];
1506 int getGraphicAnimationFrame(int graphic, int sync_frame)
1508 // animation synchronized with global frame counter, not move position
1509 if (graphic_info[graphic].anim_global_sync || sync_frame < 0)
1510 sync_frame = FrameCounter;
1512 return getAnimationFrame(graphic_info[graphic].anim_frames,
1513 graphic_info[graphic].anim_delay,
1514 graphic_info[graphic].anim_mode,
1515 graphic_info[graphic].anim_start_frame,
1519 void getGraphicSourceBitmap(int graphic, int tilesize, Bitmap **bitmap)
1521 struct GraphicInfo *g = &graphic_info[graphic];
1522 int tilesize_capped = MIN(MAX(1, tilesize), TILESIZE);
1524 if (tilesize == gfx.standard_tile_size)
1525 *bitmap = g->bitmaps[IMG_BITMAP_STANDARD];
1526 else if (tilesize == game.tile_size)
1527 *bitmap = g->bitmaps[IMG_BITMAP_GAME];
1529 *bitmap = g->bitmaps[IMG_BITMAP_1x1 - log_2(tilesize_capped)];
1532 void getGraphicSourceXY(int graphic, int frame, int *x, int *y,
1533 boolean get_backside)
1535 struct GraphicInfo *g = &graphic_info[graphic];
1536 int src_x = g->src_x + (get_backside ? g->offset2_x : 0);
1537 int src_y = g->src_y + (get_backside ? g->offset2_y : 0);
1539 if (g->offset_y == 0) // frames are ordered horizontally
1541 int max_width = g->anim_frames_per_line * g->width;
1542 int pos = (src_y / g->height) * max_width + src_x + frame * g->offset_x;
1544 *x = pos % max_width;
1545 *y = src_y % g->height + pos / max_width * g->height;
1547 else if (g->offset_x == 0) // frames are ordered vertically
1549 int max_height = g->anim_frames_per_line * g->height;
1550 int pos = (src_x / g->width) * max_height + src_y + frame * g->offset_y;
1552 *x = src_x % g->width + pos / max_height * g->width;
1553 *y = pos % max_height;
1555 else // frames are ordered diagonally
1557 *x = src_x + frame * g->offset_x;
1558 *y = src_y + frame * g->offset_y;
1562 void getSizedGraphicSourceExt(int graphic, int frame, int tilesize,
1563 Bitmap **bitmap, int *x, int *y,
1564 boolean get_backside)
1566 struct GraphicInfo *g = &graphic_info[graphic];
1568 // if no graphics defined at all, use fallback graphics
1569 if (g->bitmaps == NULL)
1570 *g = graphic_info[IMG_CHAR_EXCLAM];
1572 // if no in-game graphics defined, always use standard graphic size
1573 if (g->bitmaps[IMG_BITMAP_GAME] == NULL)
1574 tilesize = TILESIZE;
1576 getGraphicSourceBitmap(graphic, tilesize, bitmap);
1577 getGraphicSourceXY(graphic, frame, x, y, get_backside);
1579 *x = *x * tilesize / g->tile_size;
1580 *y = *y * tilesize / g->tile_size;
1583 void getSizedGraphicSource(int graphic, int frame, int tilesize,
1584 Bitmap **bitmap, int *x, int *y)
1586 getSizedGraphicSourceExt(graphic, frame, tilesize, bitmap, x, y, FALSE);
1589 void getFixedGraphicSource(int graphic, int frame,
1590 Bitmap **bitmap, int *x, int *y)
1592 getSizedGraphicSourceExt(graphic, frame, TILESIZE, bitmap, x, y, FALSE);
1595 void getMiniGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y)
1597 getSizedGraphicSource(graphic, 0, MINI_TILESIZE, bitmap, x, y);
1600 static void getGraphicSourceExt(int graphic, int frame, Bitmap **bitmap,
1601 int *x, int *y, boolean get_backside)
1603 getSizedGraphicSourceExt(graphic, frame, TILESIZE_VAR, bitmap, x, y,
1607 void getGraphicSource(int graphic, int frame, Bitmap **bitmap, int *x, int *y)
1609 getGraphicSourceExt(graphic, frame, bitmap, x, y, FALSE);
1612 void DrawGraphic(int x, int y, int graphic, int frame)
1615 if (!IN_SCR_FIELD(x, y))
1617 Debug("draw:DrawGraphic", "x = %d, y = %d, graphic = %d", x, y, graphic);
1618 Debug("draw:DrawGraphic", "This should never happen!");
1624 DrawGraphicExt(drawto_field, FX + x * TILEX_VAR, FY + y * TILEY_VAR, graphic,
1627 MarkTileDirty(x, y);
1630 void DrawFixedGraphic(int x, int y, int graphic, int frame)
1633 if (!IN_SCR_FIELD(x, y))
1635 Debug("draw:DrawFixedGraphic", "x = %d, y = %d, graphic = %d",
1637 Debug("draw:DrawFixedGraphic", "This should never happen!");
1643 DrawFixedGraphicExt(drawto_field, FX + x * TILEX, FY + y * TILEY, graphic,
1645 MarkTileDirty(x, y);
1648 void DrawGraphicExt(DrawBuffer *dst_bitmap, int x, int y, int graphic,
1654 getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y);
1656 BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, TILEX_VAR, TILEY_VAR, x, y);
1659 void DrawFixedGraphicExt(DrawBuffer *dst_bitmap, int x, int y, int graphic,
1665 getFixedGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y);
1666 BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, TILEX, TILEY, x, y);
1669 void DrawGraphicThruMask(int x, int y, int graphic, int frame)
1672 if (!IN_SCR_FIELD(x, y))
1674 Debug("draw:DrawGraphicThruMask", "x = %d,y = %d, graphic = %d",
1676 Debug("draw:DrawGraphicThruMask", "This should never happen!");
1682 DrawGraphicThruMaskExt(drawto_field, FX + x * TILEX_VAR, FY + y * TILEY_VAR,
1685 MarkTileDirty(x, y);
1688 void DrawFixedGraphicThruMask(int x, int y, int graphic, int frame)
1691 if (!IN_SCR_FIELD(x, y))
1693 Debug("draw:DrawFixedGraphicThruMask", "x = %d,y = %d, graphic = %d",
1695 Debug("draw:DrawFixedGraphicThruMask", "This should never happen!");
1701 DrawFixedGraphicThruMaskExt(drawto_field, FX + x * TILEX, FY + y * TILEY,
1703 MarkTileDirty(x, y);
1706 void DrawGraphicThruMaskExt(DrawBuffer *d, int dst_x, int dst_y, int graphic,
1712 getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y);
1714 BlitBitmapMasked(src_bitmap, d, src_x, src_y, TILEX_VAR, TILEY_VAR,
1718 void DrawFixedGraphicThruMaskExt(DrawBuffer *d, int dst_x, int dst_y,
1719 int graphic, int frame)
1724 getFixedGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y);
1726 BlitBitmapMasked(src_bitmap, d, src_x, src_y, TILEX, TILEY,
1730 void DrawSizedGraphic(int x, int y, int graphic, int frame, int tilesize)
1732 DrawSizedGraphicExt(drawto, SX + x * tilesize, SY + y * tilesize, graphic,
1734 MarkTileDirty(x / tilesize, y / tilesize);
1737 void DrawSizedGraphicThruMask(int x, int y, int graphic, int frame,
1740 DrawSizedGraphicThruMaskExt(drawto, SX + x * tilesize, SY + y * tilesize,
1741 graphic, frame, tilesize);
1742 MarkTileDirty(x / tilesize, y / tilesize);
1745 void DrawSizedGraphicExt(DrawBuffer *d, int x, int y, int graphic, int frame,
1751 getSizedGraphicSource(graphic, frame, tilesize, &src_bitmap, &src_x, &src_y);
1752 BlitBitmap(src_bitmap, d, src_x, src_y, tilesize, tilesize, x, y);
1755 void DrawSizedGraphicThruMaskExt(DrawBuffer *d, int x, int y, int graphic,
1756 int frame, int tilesize)
1761 getSizedGraphicSource(graphic, frame, tilesize, &src_bitmap, &src_x, &src_y);
1762 BlitBitmapMasked(src_bitmap, d, src_x, src_y, tilesize, tilesize, x, y);
1765 void DrawMiniGraphic(int x, int y, int graphic)
1767 DrawMiniGraphicExt(drawto, SX + x * MINI_TILEX,SY + y * MINI_TILEY, graphic);
1768 MarkTileDirty(x / 2, y / 2);
1771 void DrawMiniGraphicExt(DrawBuffer *d, int x, int y, int graphic)
1776 getMiniGraphicSource(graphic, &src_bitmap, &src_x, &src_y);
1777 BlitBitmap(src_bitmap, d, src_x, src_y, MINI_TILEX, MINI_TILEY, x, y);
1780 static void DrawGraphicShiftedNormal(int x, int y, int dx, int dy,
1781 int graphic, int frame,
1782 int cut_mode, int mask_mode)
1787 int width = TILEX, height = TILEY;
1790 if (dx || dy) // shifted graphic
1792 if (x < BX1) // object enters playfield from the left
1799 else if (x > BX2) // object enters playfield from the right
1805 else if (x == BX1 && dx < 0) // object leaves playfield to the left
1811 else if (x == BX2 && dx > 0) // object leaves playfield to the right
1813 else if (dx) // general horizontal movement
1814 MarkTileDirty(x + SIGN(dx), y);
1816 if (y < BY1) // object enters playfield from the top
1818 if (cut_mode == CUT_BELOW) // object completely above top border
1826 else if (y > BY2) // object enters playfield from the bottom
1832 else if (y == BY1 && dy < 0) // object leaves playfield to the top
1838 else if (dy > 0 && cut_mode == CUT_ABOVE)
1840 if (y == BY2) // object completely above bottom border
1846 MarkTileDirty(x, y + 1);
1847 } // object leaves playfield to the bottom
1848 else if (dy > 0 && (y == BY2 || cut_mode == CUT_BELOW))
1850 else if (dy) // general vertical movement
1851 MarkTileDirty(x, y + SIGN(dy));
1855 if (!IN_SCR_FIELD(x, y))
1857 Debug("draw:DrawGraphicShiftedNormal", "x = %d, y = %d, graphic = %d",
1859 Debug("draw:DrawGraphicShiftedNormal", "This should never happen!");
1865 width = width * TILESIZE_VAR / TILESIZE;
1866 height = height * TILESIZE_VAR / TILESIZE;
1867 cx = cx * TILESIZE_VAR / TILESIZE;
1868 cy = cy * TILESIZE_VAR / TILESIZE;
1869 dx = dx * TILESIZE_VAR / TILESIZE;
1870 dy = dy * TILESIZE_VAR / TILESIZE;
1872 if (width > 0 && height > 0)
1874 getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y);
1879 dst_x = FX + x * TILEX_VAR + dx;
1880 dst_y = FY + y * TILEY_VAR + dy;
1882 if (mask_mode == USE_MASKING)
1883 BlitBitmapMasked(src_bitmap, drawto_field, src_x, src_y, width, height,
1886 BlitBitmap(src_bitmap, drawto_field, src_x, src_y, width, height,
1889 MarkTileDirty(x, y);
1893 static void DrawGraphicShiftedDouble(int x, int y, int dx, int dy,
1894 int graphic, int frame,
1895 int cut_mode, int mask_mode)
1900 int width = TILEX_VAR, height = TILEY_VAR;
1903 int x2 = x + SIGN(dx);
1904 int y2 = y + SIGN(dy);
1906 // movement with two-tile animations must be sync'ed with movement position,
1907 // not with current GfxFrame (which can be higher when using slow movement)
1908 int anim_pos = (dx ? ABS(dx) : ABS(dy));
1909 int anim_frames = graphic_info[graphic].anim_frames;
1911 // (we also need anim_delay here for movement animations with less frames)
1912 int anim_delay = graphic_info[graphic].anim_delay;
1913 int sync_frame = anim_pos * anim_frames * anim_delay / TILESIZE;
1915 boolean draw_start_tile = (cut_mode != CUT_ABOVE); // only for falling!
1916 boolean draw_end_tile = (cut_mode != CUT_BELOW); // only for falling!
1918 // re-calculate animation frame for two-tile movement animation
1919 frame = getGraphicAnimationFrame(graphic, sync_frame);
1921 // check if movement start graphic inside screen area and should be drawn
1922 if (draw_start_tile && IN_SCR_FIELD(x1, y1))
1924 getGraphicSourceExt(graphic, frame, &src_bitmap, &src_x, &src_y, TRUE);
1926 dst_x = FX + x1 * TILEX_VAR;
1927 dst_y = FY + y1 * TILEY_VAR;
1929 if (mask_mode == USE_MASKING)
1930 BlitBitmapMasked(src_bitmap, drawto_field, src_x, src_y, width, height,
1933 BlitBitmap(src_bitmap, drawto_field, src_x, src_y, width, height,
1936 MarkTileDirty(x1, y1);
1939 // check if movement end graphic inside screen area and should be drawn
1940 if (draw_end_tile && IN_SCR_FIELD(x2, y2))
1942 getGraphicSourceExt(graphic, frame, &src_bitmap, &src_x, &src_y, FALSE);
1944 dst_x = FX + x2 * TILEX_VAR;
1945 dst_y = FY + y2 * TILEY_VAR;
1947 if (mask_mode == USE_MASKING)
1948 BlitBitmapMasked(src_bitmap, drawto_field, src_x, src_y, width, height,
1951 BlitBitmap(src_bitmap, drawto_field, src_x, src_y, width, height,
1954 MarkTileDirty(x2, y2);
1958 static void DrawGraphicShifted(int x, int y, int dx, int dy,
1959 int graphic, int frame,
1960 int cut_mode, int mask_mode)
1964 DrawGraphic(x, y, graphic, frame);
1969 if (graphic_info[graphic].double_movement) // EM style movement images
1970 DrawGraphicShiftedDouble(x, y, dx, dy, graphic, frame, cut_mode,mask_mode);
1972 DrawGraphicShiftedNormal(x, y, dx, dy, graphic, frame, cut_mode,mask_mode);
1975 static void DrawGraphicShiftedThruMask(int x, int y, int dx, int dy,
1976 int graphic, int frame, int cut_mode)
1978 DrawGraphicShifted(x, y, dx, dy, graphic, frame, cut_mode, USE_MASKING);
1981 void DrawScreenElementExt(int x, int y, int dx, int dy, int element,
1982 int cut_mode, int mask_mode)
1984 int lx = LEVELX(x), ly = LEVELY(y);
1988 if (IN_LEV_FIELD(lx, ly))
1990 SetRandomAnimationValue(lx, ly);
1992 graphic = el_act_dir2img(element, GfxAction[lx][ly], GfxDir[lx][ly]);
1993 frame = getGraphicAnimationFrame(graphic, GfxFrame[lx][ly]);
1995 // do not use double (EM style) movement graphic when not moving
1996 if (graphic_info[graphic].double_movement && !dx && !dy)
1998 graphic = el_act_dir2img(element, ACTION_DEFAULT, GfxDir[lx][ly]);
1999 frame = getGraphicAnimationFrame(graphic, GfxFrame[lx][ly]);
2002 else // border element
2004 graphic = el2img(element);
2005 frame = getGraphicAnimationFrame(graphic, -1);
2008 if (element == EL_EXPANDABLE_WALL)
2010 boolean left_stopped = FALSE, right_stopped = FALSE;
2012 if (!IN_LEV_FIELD(lx - 1, ly) || IS_WALL(Tile[lx - 1][ly]))
2013 left_stopped = TRUE;
2014 if (!IN_LEV_FIELD(lx + 1, ly) || IS_WALL(Tile[lx + 1][ly]))
2015 right_stopped = TRUE;
2017 if (left_stopped && right_stopped)
2019 else if (left_stopped)
2021 graphic = IMG_EXPANDABLE_WALL_GROWING_RIGHT;
2022 frame = graphic_info[graphic].anim_frames - 1;
2024 else if (right_stopped)
2026 graphic = IMG_EXPANDABLE_WALL_GROWING_LEFT;
2027 frame = graphic_info[graphic].anim_frames - 1;
2032 DrawGraphicShifted(x, y, dx, dy, graphic, frame, cut_mode, mask_mode);
2033 else if (mask_mode == USE_MASKING)
2034 DrawGraphicThruMask(x, y, graphic, frame);
2036 DrawGraphic(x, y, graphic, frame);
2039 void DrawLevelElementExt(int x, int y, int dx, int dy, int element,
2040 int cut_mode, int mask_mode)
2042 if (IN_LEV_FIELD(x, y) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
2043 DrawScreenElementExt(SCREENX(x), SCREENY(y), dx, dy, element,
2044 cut_mode, mask_mode);
2047 void DrawScreenElementShifted(int x, int y, int dx, int dy, int element,
2050 DrawScreenElementExt(x, y, dx, dy, element, cut_mode, NO_MASKING);
2053 void DrawLevelElementShifted(int x, int y, int dx, int dy, int element,
2056 DrawLevelElementExt(x, y, dx, dy, element, cut_mode, NO_MASKING);
2059 void DrawLevelElementThruMask(int x, int y, int element)
2061 DrawLevelElementExt(x, y, 0, 0, element, NO_CUTTING, USE_MASKING);
2064 void DrawLevelFieldThruMask(int x, int y)
2066 DrawLevelElementExt(x, y, 0, 0, Tile[x][y], NO_CUTTING, USE_MASKING);
2069 // !!! implementation of quicksand is totally broken !!!
2070 #define IS_CRUMBLED_TILE(x, y, e) \
2071 (GFX_CRUMBLED(e) && (!IN_LEV_FIELD(x, y) || \
2072 !IS_MOVING(x, y) || \
2073 (e) == EL_QUICKSAND_EMPTYING || \
2074 (e) == EL_QUICKSAND_FAST_EMPTYING))
2076 static void DrawLevelFieldCrumbledInnerCorners(int x, int y, int dx, int dy,
2081 int width, height, cx, cy;
2082 int sx = SCREENX(x), sy = SCREENY(y);
2083 int crumbled_border_size = graphic_info[graphic].border_size;
2084 int crumbled_tile_size = graphic_info[graphic].tile_size;
2085 int crumbled_border_size_var =
2086 crumbled_border_size * TILESIZE_VAR / crumbled_tile_size;
2089 getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
2091 for (i = 1; i < 4; i++)
2093 int dxx = (i & 1 ? dx : 0);
2094 int dyy = (i & 2 ? dy : 0);
2097 int element = (IN_LEV_FIELD(xx, yy) ? TILE_GFX_ELEMENT(xx, yy) :
2100 // check if neighbour field is of same crumble type
2101 boolean same = (IS_CRUMBLED_TILE(xx, yy, element) &&
2102 graphic_info[graphic].class ==
2103 graphic_info[el_act2crm(element, ACTION_DEFAULT)].class);
2105 // return if check prevents inner corner
2106 if (same == (dxx == dx && dyy == dy))
2110 // if we reach this point, we have an inner corner
2112 getGraphicSource(graphic, 1, &src_bitmap, &src_x, &src_y);
2114 width = crumbled_border_size_var;
2115 height = crumbled_border_size_var;
2116 cx = (dx > 0 ? TILESIZE_VAR - width : 0);
2117 cy = (dy > 0 ? TILESIZE_VAR - height : 0);
2119 BlitBitmap(src_bitmap, drawto_field, src_x + cx, src_y + cy,
2120 width, height, FX + sx * TILEX_VAR + cx, FY + sy * TILEY_VAR + cy);
2123 static void DrawLevelFieldCrumbledBorders(int x, int y, int graphic, int frame,
2128 int width, height, bx, by, cx, cy;
2129 int sx = SCREENX(x), sy = SCREENY(y);
2130 int crumbled_border_size = graphic_info[graphic].border_size;
2131 int crumbled_tile_size = graphic_info[graphic].tile_size;
2132 int crumbled_border_size_var =
2133 crumbled_border_size * TILESIZE_VAR / crumbled_tile_size;
2134 int crumbled_border_pos_var = TILESIZE_VAR - crumbled_border_size_var;
2137 getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y);
2139 // draw simple, sloppy, non-corner-accurate crumbled border
2141 width = (dir == 1 || dir == 2 ? crumbled_border_size_var : TILESIZE_VAR);
2142 height = (dir == 0 || dir == 3 ? crumbled_border_size_var : TILESIZE_VAR);
2143 cx = (dir == 2 ? crumbled_border_pos_var : 0);
2144 cy = (dir == 3 ? crumbled_border_pos_var : 0);
2146 BlitBitmap(src_bitmap, drawto_field, src_x + cx, src_y + cy, width, height,
2147 FX + sx * TILEX_VAR + cx,
2148 FY + sy * TILEY_VAR + cy);
2150 // (remaining middle border part must be at least as big as corner part)
2151 if (!(graphic_info[graphic].style & STYLE_ACCURATE_BORDERS) ||
2152 crumbled_border_size_var >= TILESIZE_VAR / 3)
2155 // correct corners of crumbled border, if needed
2157 for (i = -1; i <= 1; i += 2)
2159 int xx = x + (dir == 0 || dir == 3 ? i : 0);
2160 int yy = y + (dir == 1 || dir == 2 ? i : 0);
2161 int element = (IN_LEV_FIELD(xx, yy) ? TILE_GFX_ELEMENT(xx, yy) :
2164 // check if neighbour field is of same crumble type
2165 if (IS_CRUMBLED_TILE(xx, yy, element) &&
2166 graphic_info[graphic].class ==
2167 graphic_info[el_act2crm(element, ACTION_DEFAULT)].class)
2169 // no crumbled corner, but continued crumbled border
2171 int c1 = (dir == 2 || dir == 3 ? crumbled_border_pos_var : 0);
2172 int c2 = (i == 1 ? crumbled_border_pos_var : 0);
2173 int b1 = (i == 1 ? crumbled_border_size_var :
2174 TILESIZE_VAR - 2 * crumbled_border_size_var);
2176 width = crumbled_border_size_var;
2177 height = crumbled_border_size_var;
2179 if (dir == 1 || dir == 2)
2194 BlitBitmap(src_bitmap, drawto_field, src_x + bx, src_y + by,
2196 FX + sx * TILEX_VAR + cx,
2197 FY + sy * TILEY_VAR + cy);
2202 static void DrawLevelFieldCrumbledExt(int x, int y, int graphic, int frame)
2204 int sx = SCREENX(x), sy = SCREENY(y);
2207 static int xy[4][2] =
2215 if (!IN_LEV_FIELD(x, y))
2218 element = TILE_GFX_ELEMENT(x, y);
2220 if (IS_CRUMBLED_TILE(x, y, element)) // crumble field itself
2222 if (!IN_SCR_FIELD(sx, sy))
2225 // crumble field borders towards direct neighbour fields
2226 for (i = 0; i < 4; i++)
2228 int xx = x + xy[i][0];
2229 int yy = y + xy[i][1];
2231 element = (IN_LEV_FIELD(xx, yy) ? TILE_GFX_ELEMENT(xx, yy) :
2234 // check if neighbour field is of same crumble type
2235 if (IS_CRUMBLED_TILE(xx, yy, element) &&
2236 graphic_info[graphic].class ==
2237 graphic_info[el_act2crm(element, ACTION_DEFAULT)].class)
2240 DrawLevelFieldCrumbledBorders(x, y, graphic, frame, i);
2243 // crumble inner field corners towards corner neighbour fields
2244 if ((graphic_info[graphic].style & STYLE_INNER_CORNERS) &&
2245 graphic_info[graphic].anim_frames == 2)
2247 for (i = 0; i < 4; i++)
2249 int dx = (i & 1 ? +1 : -1);
2250 int dy = (i & 2 ? +1 : -1);
2252 DrawLevelFieldCrumbledInnerCorners(x, y, dx, dy, graphic);
2256 MarkTileDirty(sx, sy);
2258 else // center field is not crumbled -- crumble neighbour fields
2260 // crumble field borders of direct neighbour fields
2261 for (i = 0; i < 4; i++)
2263 int xx = x + xy[i][0];
2264 int yy = y + xy[i][1];
2265 int sxx = sx + xy[i][0];
2266 int syy = sy + xy[i][1];
2268 if (!IN_LEV_FIELD(xx, yy) ||
2269 !IN_SCR_FIELD(sxx, syy))
2272 // do not crumble fields that are being digged or snapped
2273 if (Tile[xx][yy] == EL_EMPTY ||
2274 Tile[xx][yy] == EL_ELEMENT_SNAPPING)
2277 element = TILE_GFX_ELEMENT(xx, yy);
2279 if (!IS_CRUMBLED_TILE(xx, yy, element))
2282 graphic = el_act2crm(element, ACTION_DEFAULT);
2284 DrawLevelFieldCrumbledBorders(xx, yy, graphic, 0, 3 - i);
2286 MarkTileDirty(sxx, syy);
2289 // crumble inner field corners of corner neighbour fields
2290 for (i = 0; i < 4; i++)
2292 int dx = (i & 1 ? +1 : -1);
2293 int dy = (i & 2 ? +1 : -1);
2299 if (!IN_LEV_FIELD(xx, yy) ||
2300 !IN_SCR_FIELD(sxx, syy))
2303 if (Tile[xx][yy] == EL_ELEMENT_SNAPPING)
2306 element = TILE_GFX_ELEMENT(xx, yy);
2308 if (!IS_CRUMBLED_TILE(xx, yy, element))
2311 graphic = el_act2crm(element, ACTION_DEFAULT);
2313 if ((graphic_info[graphic].style & STYLE_INNER_CORNERS) &&
2314 graphic_info[graphic].anim_frames == 2)
2315 DrawLevelFieldCrumbledInnerCorners(xx, yy, -dx, -dy, graphic);
2317 MarkTileDirty(sxx, syy);
2322 void DrawLevelFieldCrumbled(int x, int y)
2326 if (!IN_LEV_FIELD(x, y))
2329 if (Tile[x][y] == EL_ELEMENT_SNAPPING &&
2330 GfxElement[x][y] != EL_UNDEFINED &&
2331 GFX_CRUMBLED(GfxElement[x][y]))
2333 DrawLevelFieldCrumbledDigging(x, y, GfxDir[x][y], GfxFrame[x][y]);
2338 graphic = el_act2crm(TILE_GFX_ELEMENT(x, y), ACTION_DEFAULT);
2340 DrawLevelFieldCrumbledExt(x, y, graphic, 0);
2343 void DrawLevelFieldCrumbledDigging(int x, int y, int direction,
2346 int graphic1 = el_act_dir2img(GfxElement[x][y], ACTION_DIGGING, direction);
2347 int graphic2 = el_act_dir2crm(GfxElement[x][y], ACTION_DIGGING, direction);
2348 int frame1 = getGraphicAnimationFrame(graphic1, step_frame);
2349 int frame2 = getGraphicAnimationFrame(graphic2, step_frame);
2350 int sx = SCREENX(x), sy = SCREENY(y);
2352 DrawGraphic(sx, sy, graphic1, frame1);
2353 DrawLevelFieldCrumbledExt(x, y, graphic2, frame2);
2356 void DrawLevelFieldCrumbledNeighbours(int x, int y)
2358 int sx = SCREENX(x), sy = SCREENY(y);
2359 static int xy[4][2] =
2368 // crumble direct neighbour fields (required for field borders)
2369 for (i = 0; i < 4; i++)
2371 int xx = x + xy[i][0];
2372 int yy = y + xy[i][1];
2373 int sxx = sx + xy[i][0];
2374 int syy = sy + xy[i][1];
2376 if (!IN_LEV_FIELD(xx, yy) ||
2377 !IN_SCR_FIELD(sxx, syy) ||
2378 !GFX_CRUMBLED(Tile[xx][yy]) ||
2382 DrawLevelField(xx, yy);
2385 // crumble corner neighbour fields (required for inner field corners)
2386 for (i = 0; i < 4; i++)
2388 int dx = (i & 1 ? +1 : -1);
2389 int dy = (i & 2 ? +1 : -1);
2395 if (!IN_LEV_FIELD(xx, yy) ||
2396 !IN_SCR_FIELD(sxx, syy) ||
2397 !GFX_CRUMBLED(Tile[xx][yy]) ||
2401 int element = TILE_GFX_ELEMENT(xx, yy);
2402 int graphic = el_act2crm(element, ACTION_DEFAULT);
2404 if ((graphic_info[graphic].style & STYLE_INNER_CORNERS) &&
2405 graphic_info[graphic].anim_frames == 2)
2406 DrawLevelField(xx, yy);
2410 static int getBorderElement(int x, int y)
2414 { EL_STEELWALL_TOPLEFT, EL_INVISIBLE_STEELWALL_TOPLEFT },
2415 { EL_STEELWALL_TOPRIGHT, EL_INVISIBLE_STEELWALL_TOPRIGHT },
2416 { EL_STEELWALL_BOTTOMLEFT, EL_INVISIBLE_STEELWALL_BOTTOMLEFT },
2417 { EL_STEELWALL_BOTTOMRIGHT, EL_INVISIBLE_STEELWALL_BOTTOMRIGHT },
2418 { EL_STEELWALL_VERTICAL, EL_INVISIBLE_STEELWALL_VERTICAL },
2419 { EL_STEELWALL_HORIZONTAL, EL_INVISIBLE_STEELWALL_HORIZONTAL },
2420 { EL_STEELWALL, EL_INVISIBLE_STEELWALL }
2422 int steel_type = (BorderElement == EL_STEELWALL ? 0 : 1);
2423 int steel_position = (x == -1 && y == -1 ? 0 :
2424 x == lev_fieldx && y == -1 ? 1 :
2425 x == -1 && y == lev_fieldy ? 2 :
2426 x == lev_fieldx && y == lev_fieldy ? 3 :
2427 x == -1 || x == lev_fieldx ? 4 :
2428 y == -1 || y == lev_fieldy ? 5 : 6);
2430 return border[steel_position][steel_type];
2433 void DrawScreenElement(int x, int y, int element)
2435 DrawScreenElementExt(x, y, 0, 0, element, NO_CUTTING, NO_MASKING);
2436 DrawLevelFieldCrumbled(LEVELX(x), LEVELY(y));
2439 void DrawLevelElement(int x, int y, int element)
2441 if (IN_LEV_FIELD(x, y) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
2442 DrawScreenElement(SCREENX(x), SCREENY(y), element);
2445 void DrawScreenField(int x, int y)
2447 int lx = LEVELX(x), ly = LEVELY(y);
2448 int element, content;
2450 if (!IN_LEV_FIELD(lx, ly))
2452 if (lx < -1 || lx > lev_fieldx || ly < -1 || ly > lev_fieldy)
2455 element = getBorderElement(lx, ly);
2457 DrawScreenElement(x, y, element);
2462 element = Tile[lx][ly];
2463 content = Store[lx][ly];
2465 if (IS_MOVING(lx, ly))
2467 int horiz_move = (MovDir[lx][ly] == MV_LEFT || MovDir[lx][ly] == MV_RIGHT);
2468 boolean cut_mode = NO_CUTTING;
2470 if (element == EL_QUICKSAND_EMPTYING ||
2471 element == EL_QUICKSAND_FAST_EMPTYING ||
2472 element == EL_MAGIC_WALL_EMPTYING ||
2473 element == EL_BD_MAGIC_WALL_EMPTYING ||
2474 element == EL_DC_MAGIC_WALL_EMPTYING ||
2475 element == EL_AMOEBA_DROPPING)
2476 cut_mode = CUT_ABOVE;
2477 else if (element == EL_QUICKSAND_FILLING ||
2478 element == EL_QUICKSAND_FAST_FILLING ||
2479 element == EL_MAGIC_WALL_FILLING ||
2480 element == EL_BD_MAGIC_WALL_FILLING ||
2481 element == EL_DC_MAGIC_WALL_FILLING)
2482 cut_mode = CUT_BELOW;
2484 if (cut_mode == CUT_ABOVE)
2485 DrawScreenElement(x, y, element);
2487 DrawScreenElement(x, y, EL_EMPTY);
2490 DrawScreenElementShifted(x, y, MovPos[lx][ly], 0, element, NO_CUTTING);
2491 else if (cut_mode == NO_CUTTING)
2492 DrawScreenElementShifted(x, y, 0, MovPos[lx][ly], element, cut_mode);
2495 DrawScreenElementShifted(x, y, 0, MovPos[lx][ly], content, cut_mode);
2497 if (cut_mode == CUT_BELOW &&
2498 IN_LEV_FIELD(lx, ly + 1) && IN_SCR_FIELD(x, y + 1))
2499 DrawLevelElement(lx, ly + 1, element);
2502 if (content == EL_ACID)
2504 int dir = MovDir[lx][ly];
2505 int newlx = lx + (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
2506 int newly = ly + (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
2508 DrawLevelElementThruMask(newlx, newly, EL_ACID);
2510 // prevent target field from being drawn again (but without masking)
2511 // (this would happen if target field is scanned after moving element)
2512 Stop[newlx][newly] = TRUE;
2515 else if (IS_BLOCKED(lx, ly))
2520 boolean cut_mode = NO_CUTTING;
2521 int element_old, content_old;
2523 Blocked2Moving(lx, ly, &oldx, &oldy);
2526 horiz_move = (MovDir[oldx][oldy] == MV_LEFT ||
2527 MovDir[oldx][oldy] == MV_RIGHT);
2529 element_old = Tile[oldx][oldy];
2530 content_old = Store[oldx][oldy];
2532 if (element_old == EL_QUICKSAND_EMPTYING ||
2533 element_old == EL_QUICKSAND_FAST_EMPTYING ||
2534 element_old == EL_MAGIC_WALL_EMPTYING ||
2535 element_old == EL_BD_MAGIC_WALL_EMPTYING ||
2536 element_old == EL_DC_MAGIC_WALL_EMPTYING ||
2537 element_old == EL_AMOEBA_DROPPING)
2538 cut_mode = CUT_ABOVE;
2540 DrawScreenElement(x, y, EL_EMPTY);
2543 DrawScreenElementShifted(sx, sy, MovPos[oldx][oldy], 0, element_old,
2545 else if (cut_mode == NO_CUTTING)
2546 DrawScreenElementShifted(sx, sy, 0, MovPos[oldx][oldy], element_old,
2549 DrawScreenElementShifted(sx, sy, 0, MovPos[oldx][oldy], content_old,
2552 else if (IS_DRAWABLE(element))
2553 DrawScreenElement(x, y, element);
2555 DrawScreenElement(x, y, EL_EMPTY);
2558 void DrawLevelField(int x, int y)
2560 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
2561 DrawScreenField(SCREENX(x), SCREENY(y));
2562 else if (IS_MOVING(x, y))
2566 Moving2Blocked(x, y, &newx, &newy);
2567 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
2568 DrawScreenField(SCREENX(newx), SCREENY(newy));
2570 else if (IS_BLOCKED(x, y))
2574 Blocked2Moving(x, y, &oldx, &oldy);
2575 if (IN_SCR_FIELD(SCREENX(oldx), SCREENY(oldy)))
2576 DrawScreenField(SCREENX(oldx), SCREENY(oldy));
2580 static void DrawSizedWallExt_MM(int dst_x, int dst_y, int element, int tilesize,
2581 int (*el2img_function)(int), boolean masked,
2582 int element_bits_draw)
2584 int element_base = map_mm_wall_element(element);
2585 int element_bits = (IS_DF_WALL(element) ?
2586 element - EL_DF_WALL_START :
2587 IS_MM_WALL(element) ?
2588 element - EL_MM_WALL_START : EL_EMPTY) & 0x000f;
2589 int graphic = el2img_function(element_base);
2590 int tilesize_draw = tilesize / 2;
2595 getSizedGraphicSource(graphic, 0, tilesize_draw, &src_bitmap, &src_x, &src_y);
2597 for (i = 0; i < 4; i++)
2599 int dst_draw_x = dst_x + (i % 2) * tilesize_draw;
2600 int dst_draw_y = dst_y + (i / 2) * tilesize_draw;
2602 if (!(element_bits_draw & (1 << i)))
2605 if (element_bits & (1 << i))
2608 BlitBitmapMasked(src_bitmap, drawto, src_x, src_y,
2609 tilesize_draw, tilesize_draw, dst_draw_x, dst_draw_y);
2611 BlitBitmap(src_bitmap, drawto, src_x, src_y,
2612 tilesize_draw, tilesize_draw, dst_draw_x, dst_draw_y);
2617 ClearRectangle(drawto, dst_draw_x, dst_draw_y,
2618 tilesize_draw, tilesize_draw);
2623 void DrawSizedWallParts_MM(int x, int y, int element, int tilesize,
2624 boolean masked, int element_bits_draw)
2626 DrawSizedWallExt_MM(SX + x * tilesize, SY + y * tilesize,
2627 element, tilesize, el2edimg, masked, element_bits_draw);
2630 static void DrawSizedWall_MM(int dst_x, int dst_y, int element, int tilesize,
2631 int (*el2img_function)(int))
2633 DrawSizedWallExt_MM(dst_x, dst_y, element, tilesize, el2img_function, FALSE,
2637 static void DrawSizedElementExt(int x, int y, int element, int tilesize,
2640 if (IS_MM_WALL(element))
2642 DrawSizedWallExt_MM(SX + x * tilesize, SY + y * tilesize,
2643 element, tilesize, el2edimg, masked, 0x000f);
2647 int graphic = el2edimg(element);
2650 DrawSizedGraphicThruMask(x, y, graphic, 0, tilesize);
2652 DrawSizedGraphic(x, y, graphic, 0, tilesize);
2656 void DrawSizedElement(int x, int y, int element, int tilesize)
2658 DrawSizedElementExt(x, y, element, tilesize, FALSE);
2661 void DrawSizedElementThruMask(int x, int y, int element, int tilesize)
2663 DrawSizedElementExt(x, y, element, tilesize, TRUE);
2666 void DrawMiniElement(int x, int y, int element)
2670 graphic = el2edimg(element);
2671 DrawMiniGraphic(x, y, graphic);
2674 void DrawSizedElementOrWall(int sx, int sy, int scroll_x, int scroll_y,
2677 int x = sx + scroll_x, y = sy + scroll_y;
2679 if (x < -1 || x > lev_fieldx || y < -1 || y > lev_fieldy)
2680 DrawSizedElement(sx, sy, EL_EMPTY, tilesize);
2681 else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy)
2682 DrawSizedElement(sx, sy, Tile[x][y], tilesize);
2684 DrawSizedGraphic(sx, sy, el2edimg(getBorderElement(x, y)), 0, tilesize);
2687 void DrawMiniElementOrWall(int sx, int sy, int scroll_x, int scroll_y)
2689 int x = sx + scroll_x, y = sy + scroll_y;
2691 if (x < -1 || x > lev_fieldx || y < -1 || y > lev_fieldy)
2692 DrawMiniElement(sx, sy, EL_EMPTY);
2693 else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy)
2694 DrawMiniElement(sx, sy, Tile[x][y]);
2696 DrawMiniGraphic(sx, sy, el2edimg(getBorderElement(x, y)));
2699 static void DrawEnvelopeBackgroundTiles(int graphic, int startx, int starty,
2700 int x, int y, int xsize, int ysize,
2701 int tile_width, int tile_height)
2705 int dst_x = startx + x * tile_width;
2706 int dst_y = starty + y * tile_height;
2707 int width = graphic_info[graphic].width;
2708 int height = graphic_info[graphic].height;
2709 int inner_width_raw = MAX(width - 2 * tile_width, tile_width);
2710 int inner_height_raw = MAX(height - 2 * tile_height, tile_height);
2711 int inner_width = inner_width_raw - (inner_width_raw % tile_width);
2712 int inner_height = inner_height_raw - (inner_height_raw % tile_height);
2713 int inner_sx = (width >= 3 * tile_width ? tile_width : 0);
2714 int inner_sy = (height >= 3 * tile_height ? tile_height : 0);
2715 boolean draw_masked = graphic_info[graphic].draw_masked;
2717 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
2719 if (src_bitmap == NULL || width < tile_width || height < tile_height)
2721 ClearRectangle(drawto, dst_x, dst_y, tile_width, tile_height);
2725 src_x += (x == 0 ? 0 : x == xsize - 1 ? width - tile_width :
2726 inner_sx + (x - 1) * tile_width % inner_width);
2727 src_y += (y == 0 ? 0 : y == ysize - 1 ? height - tile_height :
2728 inner_sy + (y - 1) * tile_height % inner_height);
2731 BlitBitmapMasked(src_bitmap, drawto, src_x, src_y, tile_width, tile_height,
2734 BlitBitmap(src_bitmap, drawto, src_x, src_y, tile_width, tile_height,
2738 static void DrawEnvelopeBackground(int graphic, int startx, int starty,
2739 int x, int y, int xsize, int ysize,
2742 int font_width = getFontWidth(font_nr);
2743 int font_height = getFontHeight(font_nr);
2745 DrawEnvelopeBackgroundTiles(graphic, startx, starty, x, y, xsize, ysize,
2746 font_width, font_height);
2749 static void AnimateEnvelope(int envelope_nr, int anim_mode, int action)
2751 int graphic = IMG_BACKGROUND_ENVELOPE_1 + envelope_nr;
2752 Bitmap *src_bitmap = graphic_info[graphic].bitmap;
2753 int mask_mode = (src_bitmap != NULL ? BLIT_MASKED : BLIT_ON_BACKGROUND);
2754 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2755 boolean no_delay = (tape.warp_forward);
2756 unsigned int anim_delay = 0;
2757 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2758 int anim_delay_value = MAX(1, (no_delay ? 0 : frame_delay_value) / 2);
2759 int font_nr = FONT_ENVELOPE_1 + envelope_nr;
2760 int font_width = getFontWidth(font_nr);
2761 int font_height = getFontHeight(font_nr);
2762 int max_xsize = level.envelope[envelope_nr].xsize;
2763 int max_ysize = level.envelope[envelope_nr].ysize;
2764 int xstart = (anim_mode & ANIM_VERTICAL ? max_xsize : 0);
2765 int ystart = (anim_mode & ANIM_HORIZONTAL ? max_ysize : 0);
2766 int xend = max_xsize;
2767 int yend = (anim_mode != ANIM_DEFAULT ? max_ysize : 0);
2768 int xstep = (xstart < xend ? 1 : 0);
2769 int ystep = (ystart < yend || xstep == 0 ? 1 : 0);
2771 int end = MAX(xend - xstart, yend - ystart);
2774 for (i = start; i <= end; i++)
2776 int last_frame = end; // last frame of this "for" loop
2777 int x = xstart + i * xstep;
2778 int y = ystart + i * ystep;
2779 int xsize = (action == ACTION_CLOSING ? xend - (x - xstart) : x) + 2;
2780 int ysize = (action == ACTION_CLOSING ? yend - (y - ystart) : y) + 2;
2781 int sx = SX + (SXSIZE - xsize * font_width) / 2;
2782 int sy = SY + (SYSIZE - ysize * font_height) / 2;
2785 SetDrawtoField(DRAW_TO_FIELDBUFFER);
2787 BlitScreenToBitmap(backbuffer);
2789 SetDrawtoField(DRAW_TO_BACKBUFFER);
2791 for (yy = 0; yy < ysize; yy++)
2792 for (xx = 0; xx < xsize; xx++)
2793 DrawEnvelopeBackground(graphic, sx, sy, xx, yy, xsize, ysize, font_nr);
2795 DrawTextBuffer(sx + font_width, sy + font_height,
2796 level.envelope[envelope_nr].text, font_nr, max_xsize,
2797 xsize - 2, ysize - 2, 0, mask_mode,
2798 level.envelope[envelope_nr].autowrap,
2799 level.envelope[envelope_nr].centered, FALSE);
2801 redraw_mask |= REDRAW_FIELD;
2804 SkipUntilDelayReached(&anim_delay, anim_delay_value, &i, last_frame);
2807 ClearAutoRepeatKeyEvents();
2810 void ShowEnvelope(int envelope_nr)
2812 int element = EL_ENVELOPE_1 + envelope_nr;
2813 int graphic = IMG_BACKGROUND_ENVELOPE_1 + envelope_nr;
2814 int sound_opening = element_info[element].sound[ACTION_OPENING];
2815 int sound_closing = element_info[element].sound[ACTION_CLOSING];
2816 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2817 boolean no_delay = (tape.warp_forward);
2818 int normal_delay_value = ONE_SECOND_DELAY / (ffwd_delay ? 2 : 1);
2819 int wait_delay_value = (no_delay ? 0 : normal_delay_value);
2820 int anim_mode = graphic_info[graphic].anim_mode;
2821 int main_anim_mode = (anim_mode == ANIM_NONE ? ANIM_VERTICAL|ANIM_HORIZONTAL:
2822 anim_mode == ANIM_DEFAULT ? ANIM_VERTICAL : anim_mode);
2824 game.envelope_active = TRUE; // needed for RedrawPlayfield() events
2826 PlayMenuSoundStereo(sound_opening, SOUND_MIDDLE);
2828 if (anim_mode == ANIM_DEFAULT)
2829 AnimateEnvelope(envelope_nr, ANIM_DEFAULT, ACTION_OPENING);
2831 AnimateEnvelope(envelope_nr, main_anim_mode, ACTION_OPENING);
2834 Delay_WithScreenUpdates(wait_delay_value);
2836 WaitForEventToContinue();
2838 PlayMenuSoundStereo(sound_closing, SOUND_MIDDLE);
2840 if (anim_mode != ANIM_NONE)
2841 AnimateEnvelope(envelope_nr, main_anim_mode, ACTION_CLOSING);
2843 if (anim_mode == ANIM_DEFAULT)
2844 AnimateEnvelope(envelope_nr, ANIM_DEFAULT, ACTION_CLOSING);
2846 game.envelope_active = FALSE;
2848 SetDrawtoField(DRAW_TO_FIELDBUFFER);
2850 redraw_mask |= REDRAW_FIELD;
2854 static void setRequestBasePosition(int *x, int *y)
2856 int sx_base, sy_base;
2858 if (request.x != -1)
2859 sx_base = request.x;
2860 else if (request.align == ALIGN_LEFT)
2862 else if (request.align == ALIGN_RIGHT)
2863 sx_base = SX + SXSIZE;
2865 sx_base = SX + SXSIZE / 2;
2867 if (request.y != -1)
2868 sy_base = request.y;
2869 else if (request.valign == VALIGN_TOP)
2871 else if (request.valign == VALIGN_BOTTOM)
2872 sy_base = SY + SYSIZE;
2874 sy_base = SY + SYSIZE / 2;
2880 static void setRequestPositionExt(int *x, int *y, int width, int height,
2881 boolean add_border_size)
2883 int border_size = request.border_size;
2884 int sx_base, sy_base;
2887 setRequestBasePosition(&sx_base, &sy_base);
2889 if (request.align == ALIGN_LEFT)
2891 else if (request.align == ALIGN_RIGHT)
2892 sx = sx_base - width;
2894 sx = sx_base - width / 2;
2896 if (request.valign == VALIGN_TOP)
2898 else if (request.valign == VALIGN_BOTTOM)
2899 sy = sy_base - height;
2901 sy = sy_base - height / 2;
2903 sx = MAX(0, MIN(sx, WIN_XSIZE - width));
2904 sy = MAX(0, MIN(sy, WIN_YSIZE - height));
2906 if (add_border_size)
2916 static void setRequestPosition(int *x, int *y, boolean add_border_size)
2918 setRequestPositionExt(x, y, request.width, request.height, add_border_size);
2921 static void DrawEnvelopeRequest(char *text)
2923 char *text_final = text;
2924 char *text_door_style = NULL;
2925 int graphic = IMG_BACKGROUND_REQUEST;
2926 Bitmap *src_bitmap = graphic_info[graphic].bitmap;
2927 int mask_mode = (src_bitmap != NULL ? BLIT_MASKED : BLIT_ON_BACKGROUND);
2928 int font_nr = FONT_REQUEST;
2929 int font_width = getFontWidth(font_nr);
2930 int font_height = getFontHeight(font_nr);
2931 int border_size = request.border_size;
2932 int line_spacing = request.line_spacing;
2933 int line_height = font_height + line_spacing;
2934 int max_text_width = request.width - 2 * border_size;
2935 int max_text_height = request.height - 2 * border_size;
2936 int line_length = max_text_width / font_width;
2937 int max_lines = max_text_height / line_height;
2938 int text_width = line_length * font_width;
2939 int width = request.width;
2940 int height = request.height;
2941 int tile_size = MAX(request.step_offset, 1);
2942 int x_steps = width / tile_size;
2943 int y_steps = height / tile_size;
2944 int sx_offset = border_size;
2945 int sy_offset = border_size;
2949 if (request.centered)
2950 sx_offset = (request.width - text_width) / 2;
2952 if (request.wrap_single_words && !request.autowrap)
2954 char *src_text_ptr, *dst_text_ptr;
2956 text_door_style = checked_malloc(2 * strlen(text) + 1);
2958 src_text_ptr = text;
2959 dst_text_ptr = text_door_style;
2961 while (*src_text_ptr)
2963 if (*src_text_ptr == ' ' ||
2964 *src_text_ptr == '?' ||
2965 *src_text_ptr == '!')
2966 *dst_text_ptr++ = '\n';
2968 if (*src_text_ptr != ' ')
2969 *dst_text_ptr++ = *src_text_ptr;
2974 *dst_text_ptr = '\0';
2976 text_final = text_door_style;
2979 setRequestPosition(&sx, &sy, FALSE);
2981 ClearRectangle(backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE);
2983 for (y = 0; y < y_steps; y++)
2984 for (x = 0; x < x_steps; x++)
2985 DrawEnvelopeBackgroundTiles(graphic, sx, sy,
2986 x, y, x_steps, y_steps,
2987 tile_size, tile_size);
2989 // force DOOR font inside door area
2990 SetFontStatus(GAME_MODE_PSEUDO_DOOR);
2992 DrawTextBuffer(sx + sx_offset, sy + sy_offset, text_final, font_nr,
2993 line_length, -1, max_lines, line_spacing, mask_mode,
2994 request.autowrap, request.centered, FALSE);
2998 for (i = 0; i < NUM_TOOL_BUTTONS; i++)
2999 RedrawGadget(tool_gadget[i]);
3001 // store readily prepared envelope request for later use when animating
3002 BlitBitmap(backbuffer, bitmap_db_store_2, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
3004 if (text_door_style)
3005 free(text_door_style);
3008 static void AnimateEnvelopeRequest(int anim_mode, int action)
3010 int graphic = IMG_BACKGROUND_REQUEST;
3011 boolean draw_masked = graphic_info[graphic].draw_masked;
3012 int delay_value_normal = request.step_delay;
3013 int delay_value_fast = delay_value_normal / 2;
3014 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3015 boolean no_delay = (tape.warp_forward);
3016 int delay_value = (ffwd_delay ? delay_value_fast : delay_value_normal);
3017 int anim_delay_value = MAX(1, (no_delay ? 0 : delay_value + 500 * 0) / 2);
3018 unsigned int anim_delay = 0;
3020 int tile_size = MAX(request.step_offset, 1);
3021 int max_xsize = request.width / tile_size;
3022 int max_ysize = request.height / tile_size;
3023 int max_xsize_inner = max_xsize - 2;
3024 int max_ysize_inner = max_ysize - 2;
3026 int xstart = (anim_mode & ANIM_VERTICAL ? max_xsize_inner : 0);
3027 int ystart = (anim_mode & ANIM_HORIZONTAL ? max_ysize_inner : 0);
3028 int xend = max_xsize_inner;
3029 int yend = (anim_mode != ANIM_DEFAULT ? max_ysize_inner : 0);
3030 int xstep = (xstart < xend ? 1 : 0);
3031 int ystep = (ystart < yend || xstep == 0 ? 1 : 0);
3033 int end = MAX(xend - xstart, yend - ystart);
3036 if (setup.quick_doors)
3043 for (i = start; i <= end; i++)
3045 int last_frame = end; // last frame of this "for" loop
3046 int x = xstart + i * xstep;
3047 int y = ystart + i * ystep;
3048 int xsize = (action == ACTION_CLOSING ? xend - (x - xstart) : x) + 2;
3049 int ysize = (action == ACTION_CLOSING ? yend - (y - ystart) : y) + 2;
3050 int xsize_size_left = (xsize - 1) * tile_size;
3051 int ysize_size_top = (ysize - 1) * tile_size;
3052 int max_xsize_pos = (max_xsize - 1) * tile_size;
3053 int max_ysize_pos = (max_ysize - 1) * tile_size;
3054 int width = xsize * tile_size;
3055 int height = ysize * tile_size;
3060 setRequestPosition(&src_x, &src_y, FALSE);
3061 setRequestPositionExt(&dst_x, &dst_y, width, height, FALSE);
3063 BlitBitmap(bitmap_db_store_1, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
3065 for (yy = 0; yy < 2; yy++)
3067 for (xx = 0; xx < 2; xx++)
3069 int src_xx = src_x + xx * max_xsize_pos;
3070 int src_yy = src_y + yy * max_ysize_pos;
3071 int dst_xx = dst_x + xx * xsize_size_left;
3072 int dst_yy = dst_y + yy * ysize_size_top;
3073 int xx_size = (xx ? tile_size : xsize_size_left);
3074 int yy_size = (yy ? tile_size : ysize_size_top);
3077 BlitBitmapMasked(bitmap_db_store_2, backbuffer,
3078 src_xx, src_yy, xx_size, yy_size, dst_xx, dst_yy);
3080 BlitBitmap(bitmap_db_store_2, backbuffer,
3081 src_xx, src_yy, xx_size, yy_size, dst_xx, dst_yy);
3085 redraw_mask |= REDRAW_FIELD;
3089 SkipUntilDelayReached(&anim_delay, anim_delay_value, &i, last_frame);
3092 ClearAutoRepeatKeyEvents();
3095 static void ShowEnvelopeRequest(char *text, unsigned int req_state, int action)
3097 int graphic = IMG_BACKGROUND_REQUEST;
3098 int sound_opening = SND_REQUEST_OPENING;
3099 int sound_closing = SND_REQUEST_CLOSING;
3100 int anim_mode_1 = request.anim_mode; // (higher priority)
3101 int anim_mode_2 = graphic_info[graphic].anim_mode; // (lower priority)
3102 int anim_mode = (anim_mode_1 != ANIM_DEFAULT ? anim_mode_1 : anim_mode_2);
3103 int main_anim_mode = (anim_mode == ANIM_NONE ? ANIM_VERTICAL|ANIM_HORIZONTAL:
3104 anim_mode == ANIM_DEFAULT ? ANIM_VERTICAL : anim_mode);
3106 if (game_status == GAME_MODE_PLAYING)
3107 BlitScreenToBitmap(backbuffer);
3109 SetDrawtoField(DRAW_TO_BACKBUFFER);
3111 // SetDrawBackgroundMask(REDRAW_NONE);
3113 if (action == ACTION_OPENING)
3115 BlitBitmap(backbuffer, bitmap_db_store_1, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
3117 if (req_state & REQ_ASK)
3119 MapGadget(tool_gadget[TOOL_CTRL_ID_YES]);
3120 MapGadget(tool_gadget[TOOL_CTRL_ID_NO]);
3121 MapGadget(tool_gadget[TOOL_CTRL_ID_TOUCH_YES]);
3122 MapGadget(tool_gadget[TOOL_CTRL_ID_TOUCH_NO]);
3124 else if (req_state & REQ_CONFIRM)
3126 MapGadget(tool_gadget[TOOL_CTRL_ID_CONFIRM]);
3127 MapGadget(tool_gadget[TOOL_CTRL_ID_TOUCH_CONFIRM]);
3129 else if (req_state & REQ_PLAYER)
3131 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_1]);
3132 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_2]);
3133 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_3]);
3134 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_4]);
3137 DrawEnvelopeRequest(text);
3140 game.envelope_active = TRUE; // needed for RedrawPlayfield() events
3142 if (action == ACTION_OPENING)
3144 PlayMenuSoundStereo(sound_opening, SOUND_MIDDLE);
3146 if (anim_mode == ANIM_DEFAULT)
3147 AnimateEnvelopeRequest(ANIM_DEFAULT, ACTION_OPENING);
3149 AnimateEnvelopeRequest(main_anim_mode, ACTION_OPENING);
3153 PlayMenuSoundStereo(sound_closing, SOUND_MIDDLE);
3155 if (anim_mode != ANIM_NONE)
3156 AnimateEnvelopeRequest(main_anim_mode, ACTION_CLOSING);
3158 if (anim_mode == ANIM_DEFAULT)
3159 AnimateEnvelopeRequest(ANIM_DEFAULT, ACTION_CLOSING);
3162 game.envelope_active = FALSE;
3164 if (action == ACTION_CLOSING)
3165 BlitBitmap(bitmap_db_store_1, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
3167 // SetDrawBackgroundMask(last_draw_background_mask);
3169 redraw_mask |= REDRAW_FIELD;
3173 if (action == ACTION_CLOSING &&
3174 game_status == GAME_MODE_PLAYING &&
3175 level.game_engine_type == GAME_ENGINE_TYPE_RND)
3176 SetDrawtoField(DRAW_TO_FIELDBUFFER);
3179 static void DrawPreviewElement(int dst_x, int dst_y, int element, int tilesize)
3181 if (IS_MM_WALL(element))
3183 DrawSizedWall_MM(dst_x, dst_y, element, tilesize, el2preimg);
3189 int graphic = el2preimg(element);
3191 getSizedGraphicSource(graphic, 0, tilesize, &src_bitmap, &src_x, &src_y);
3192 BlitBitmap(src_bitmap, drawto, src_x, src_y, tilesize, tilesize,
3197 void DrawLevel(int draw_background_mask)
3201 SetMainBackgroundImage(IMG_BACKGROUND_PLAYING);
3202 SetDrawBackgroundMask(draw_background_mask);
3206 for (x = BX1; x <= BX2; x++)
3207 for (y = BY1; y <= BY2; y++)
3208 DrawScreenField(x, y);
3210 redraw_mask |= REDRAW_FIELD;
3213 void DrawSizedLevel(int size_x, int size_y, int scroll_x, int scroll_y,
3218 for (x = 0; x < size_x; x++)
3219 for (y = 0; y < size_y; y++)
3220 DrawSizedElementOrWall(x, y, scroll_x, scroll_y, tilesize);
3222 redraw_mask |= REDRAW_FIELD;
3225 void DrawMiniLevel(int size_x, int size_y, int scroll_x, int scroll_y)
3229 for (x = 0; x < size_x; x++)
3230 for (y = 0; y < size_y; y++)
3231 DrawMiniElementOrWall(x, y, scroll_x, scroll_y);
3233 redraw_mask |= REDRAW_FIELD;
3236 static void DrawPreviewLevelPlayfield(int from_x, int from_y)
3238 boolean show_level_border = (BorderElement != EL_EMPTY);
3239 int level_xsize = lev_fieldx + (show_level_border ? 2 : 0);
3240 int level_ysize = lev_fieldy + (show_level_border ? 2 : 0);
3241 int tile_size = preview.tile_size;
3242 int preview_width = preview.xsize * tile_size;
3243 int preview_height = preview.ysize * tile_size;
3244 int real_preview_xsize = MIN(level_xsize, preview.xsize);
3245 int real_preview_ysize = MIN(level_ysize, preview.ysize);
3246 int real_preview_width = real_preview_xsize * tile_size;
3247 int real_preview_height = real_preview_ysize * tile_size;
3248 int dst_x = SX + ALIGNED_XPOS(preview.x, preview_width, preview.align);
3249 int dst_y = SY + ALIGNED_YPOS(preview.y, preview_height, preview.valign);
3252 if (!IN_GFX_FIELD_FULL(dst_x, dst_y + preview_height - 1))
3255 DrawBackground(dst_x, dst_y, preview_width, preview_height);
3257 dst_x += (preview_width - real_preview_width) / 2;
3258 dst_y += (preview_height - real_preview_height) / 2;
3260 for (x = 0; x < real_preview_xsize; x++)
3262 for (y = 0; y < real_preview_ysize; y++)
3264 int lx = from_x + x + (show_level_border ? -1 : 0);
3265 int ly = from_y + y + (show_level_border ? -1 : 0);
3266 int element = (IN_LEV_FIELD(lx, ly) ? level.field[lx][ly] :
3267 getBorderElement(lx, ly));
3269 DrawPreviewElement(dst_x + x * tile_size, dst_y + y * tile_size,
3270 element, tile_size);
3274 redraw_mask |= REDRAW_FIELD;
3277 #define MICROLABEL_EMPTY 0
3278 #define MICROLABEL_LEVEL_NAME 1
3279 #define MICROLABEL_LEVEL_AUTHOR_HEAD 2
3280 #define MICROLABEL_LEVEL_AUTHOR 3
3281 #define MICROLABEL_IMPORTED_FROM_HEAD 4
3282 #define MICROLABEL_IMPORTED_FROM 5
3283 #define MICROLABEL_IMPORTED_BY_HEAD 6
3284 #define MICROLABEL_IMPORTED_BY 7
3286 static int getMaxTextLength(struct TextPosInfo *pos, int font_nr)
3288 int max_text_width = SXSIZE;
3289 int font_width = getFontWidth(font_nr);
3291 if (pos->align == ALIGN_CENTER)
3292 max_text_width = (pos->x < SXSIZE / 2 ? pos->x * 2 : (SXSIZE - pos->x) * 2);
3293 else if (pos->align == ALIGN_RIGHT)
3294 max_text_width = pos->x;
3296 max_text_width = SXSIZE - pos->x;
3298 return max_text_width / font_width;
3301 static void DrawPreviewLevelLabelExt(int mode, struct TextPosInfo *pos)
3303 char label_text[MAX_OUTPUT_LINESIZE + 1];
3304 int max_len_label_text;
3305 int font_nr = pos->font;
3308 if (!IN_GFX_FIELD_FULL(pos->x, pos->y + getFontHeight(pos->font)))
3311 if (mode == MICROLABEL_LEVEL_AUTHOR_HEAD ||
3312 mode == MICROLABEL_IMPORTED_FROM_HEAD ||
3313 mode == MICROLABEL_IMPORTED_BY_HEAD)
3314 font_nr = pos->font_alt;
3316 max_len_label_text = getMaxTextLength(pos, font_nr);
3318 if (pos->size != -1)
3319 max_len_label_text = pos->size;
3321 for (i = 0; i < max_len_label_text; i++)
3322 label_text[i] = ' ';
3323 label_text[max_len_label_text] = '\0';
3325 if (strlen(label_text) > 0)
3326 DrawTextSAligned(pos->x, pos->y, label_text, font_nr, pos->align);
3329 (mode == MICROLABEL_LEVEL_NAME ? level.name :
3330 mode == MICROLABEL_LEVEL_AUTHOR_HEAD ? "created by" :
3331 mode == MICROLABEL_LEVEL_AUTHOR ? level.author :
3332 mode == MICROLABEL_IMPORTED_FROM_HEAD ? "imported from" :
3333 mode == MICROLABEL_IMPORTED_FROM ? leveldir_current->imported_from :
3334 mode == MICROLABEL_IMPORTED_BY_HEAD ? "imported by" :
3335 mode == MICROLABEL_IMPORTED_BY ? leveldir_current->imported_by :""),
3336 max_len_label_text);
3337 label_text[max_len_label_text] = '\0';
3339 if (strlen(label_text) > 0)
3340 DrawTextSAligned(pos->x, pos->y, label_text, font_nr, pos->align);
3342 redraw_mask |= REDRAW_FIELD;
3345 static void DrawPreviewLevelLabel(int mode)
3347 DrawPreviewLevelLabelExt(mode, &menu.main.text.level_info_2);
3350 static void DrawPreviewLevelInfo(int mode)
3352 if (mode == MICROLABEL_LEVEL_NAME)
3353 DrawPreviewLevelLabelExt(mode, &menu.main.text.level_name);
3354 else if (mode == MICROLABEL_LEVEL_AUTHOR)
3355 DrawPreviewLevelLabelExt(mode, &menu.main.text.level_author);
3358 static void DrawPreviewLevelExt(boolean restart)
3360 static unsigned int scroll_delay = 0;
3361 static unsigned int label_delay = 0;
3362 static int from_x, from_y, scroll_direction;
3363 static int label_state, label_counter;
3364 unsigned int scroll_delay_value = preview.step_delay;
3365 boolean show_level_border = (BorderElement != EL_EMPTY);
3366 int level_xsize = lev_fieldx + (show_level_border ? 2 : 0);
3367 int level_ysize = lev_fieldy + (show_level_border ? 2 : 0);
3374 if (preview.anim_mode == ANIM_CENTERED)
3376 if (level_xsize > preview.xsize)
3377 from_x = (level_xsize - preview.xsize) / 2;
3378 if (level_ysize > preview.ysize)
3379 from_y = (level_ysize - preview.ysize) / 2;
3382 from_x += preview.xoffset;
3383 from_y += preview.yoffset;
3385 scroll_direction = MV_RIGHT;
3389 DrawPreviewLevelPlayfield(from_x, from_y);
3390 DrawPreviewLevelLabel(label_state);
3392 DrawPreviewLevelInfo(MICROLABEL_LEVEL_NAME);
3393 DrawPreviewLevelInfo(MICROLABEL_LEVEL_AUTHOR);
3395 // initialize delay counters
3396 DelayReached(&scroll_delay, 0);
3397 DelayReached(&label_delay, 0);
3399 if (leveldir_current->name)
3401 struct TextPosInfo *pos = &menu.main.text.level_info_1;
3402 char label_text[MAX_OUTPUT_LINESIZE + 1];
3403 int font_nr = pos->font;
3404 int max_len_label_text = getMaxTextLength(pos, font_nr);
3406 if (pos->size != -1)
3407 max_len_label_text = pos->size;
3409 strncpy(label_text, leveldir_current->name, max_len_label_text);
3410 label_text[max_len_label_text] = '\0';
3412 if (IN_GFX_FIELD_FULL(pos->x, pos->y + getFontHeight(pos->font)))
3413 DrawTextSAligned(pos->x, pos->y, label_text, font_nr, pos->align);
3419 // scroll preview level, if needed
3420 if (preview.anim_mode != ANIM_NONE &&
3421 (level_xsize > preview.xsize || level_ysize > preview.ysize) &&
3422 DelayReached(&scroll_delay, scroll_delay_value))
3424 switch (scroll_direction)
3429 from_x -= preview.step_offset;
3430 from_x = (from_x < 0 ? 0 : from_x);
3433 scroll_direction = MV_UP;
3437 if (from_x < level_xsize - preview.xsize)
3439 from_x += preview.step_offset;
3440 from_x = (from_x > level_xsize - preview.xsize ?
3441 level_xsize - preview.xsize : from_x);
3444 scroll_direction = MV_DOWN;
3450 from_y -= preview.step_offset;
3451 from_y = (from_y < 0 ? 0 : from_y);
3454 scroll_direction = MV_RIGHT;
3458 if (from_y < level_ysize - preview.ysize)
3460 from_y += preview.step_offset;
3461 from_y = (from_y > level_ysize - preview.ysize ?
3462 level_ysize - preview.ysize : from_y);
3465 scroll_direction = MV_LEFT;
3472 DrawPreviewLevelPlayfield(from_x, from_y);
3475 // !!! THIS ALL SUCKS -- SHOULD BE CLEANLY REWRITTEN !!!
3476 // redraw micro level label, if needed
3477 if (!strEqual(level.name, NAMELESS_LEVEL_NAME) &&
3478 !strEqual(level.author, ANONYMOUS_NAME) &&
3479 !strEqual(level.author, leveldir_current->name) &&
3480 DelayReached(&label_delay, MICROLEVEL_LABEL_DELAY))
3482 int max_label_counter = 23;
3484 if (leveldir_current->imported_from != NULL &&
3485 strlen(leveldir_current->imported_from) > 0)
3486 max_label_counter += 14;
3487 if (leveldir_current->imported_by != NULL &&
3488 strlen(leveldir_current->imported_by) > 0)
3489 max_label_counter += 14;
3491 label_counter = (label_counter + 1) % max_label_counter;
3492 label_state = (label_counter >= 0 && label_counter <= 7 ?
3493 MICROLABEL_LEVEL_NAME :
3494 label_counter >= 9 && label_counter <= 12 ?
3495 MICROLABEL_LEVEL_AUTHOR_HEAD :
3496 label_counter >= 14 && label_counter <= 21 ?
3497 MICROLABEL_LEVEL_AUTHOR :
3498 label_counter >= 23 && label_counter <= 26 ?
3499 MICROLABEL_IMPORTED_FROM_HEAD :
3500 label_counter >= 28 && label_counter <= 35 ?
3501 MICROLABEL_IMPORTED_FROM :
3502 label_counter >= 37 && label_counter <= 40 ?
3503 MICROLABEL_IMPORTED_BY_HEAD :
3504 label_counter >= 42 && label_counter <= 49 ?
3505 MICROLABEL_IMPORTED_BY : MICROLABEL_EMPTY);
3507 if (leveldir_current->imported_from == NULL &&
3508 (label_state == MICROLABEL_IMPORTED_FROM_HEAD ||
3509 label_state == MICROLABEL_IMPORTED_FROM))
3510 label_state = (label_state == MICROLABEL_IMPORTED_FROM_HEAD ?
3511 MICROLABEL_IMPORTED_BY_HEAD : MICROLABEL_IMPORTED_BY);
3513 DrawPreviewLevelLabel(label_state);
3517 void DrawPreviewPlayers(void)
3519 if (game_status != GAME_MODE_MAIN)
3522 // do not draw preview players if level preview redefined, but players aren't
3523 if (preview.redefined && !menu.main.preview_players.redefined)
3526 boolean player_found[MAX_PLAYERS];
3527 int num_players = 0;
3530 for (i = 0; i < MAX_PLAYERS; i++)
3531 player_found[i] = FALSE;
3533 // check which players can be found in the level (simple approach)
3534 for (x = 0; x < lev_fieldx; x++)
3536 for (y = 0; y < lev_fieldy; y++)
3538 int element = level.field[x][y];
3540 if (ELEM_IS_PLAYER(element))
3542 int player_nr = GET_PLAYER_NR(element);
3544 player_nr = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
3546 if (!player_found[player_nr])
3549 player_found[player_nr] = TRUE;
3554 struct TextPosInfo *pos = &menu.main.preview_players;
3555 int tile_size = pos->tile_size;
3556 int border_size = pos->border_size;
3557 int player_xoffset_raw = (pos->vertical ? 0 : tile_size + border_size);
3558 int player_yoffset_raw = (pos->vertical ? tile_size + border_size : 0);
3559 int player_xoffset = (pos->xoffset != -1 ? pos->xoffset : player_xoffset_raw);
3560 int player_yoffset = (pos->yoffset != -1 ? pos->yoffset : player_yoffset_raw);
3561 int max_players_width = (MAX_PLAYERS - 1) * player_xoffset + tile_size;
3562 int max_players_height = (MAX_PLAYERS - 1) * player_yoffset + tile_size;
3563 int all_players_width = (num_players - 1) * player_xoffset + tile_size;
3564 int all_players_height = (num_players - 1) * player_yoffset + tile_size;
3565 int max_xpos = SX + ALIGNED_XPOS(pos->x, max_players_width, pos->align);
3566 int max_ypos = SY + ALIGNED_YPOS(pos->y, max_players_height, pos->valign);
3567 int xpos = SX + ALIGNED_XPOS(pos->x, all_players_width, pos->align);
3568 int ypos = SY + ALIGNED_YPOS(pos->y, all_players_height, pos->valign);
3570 // clear area in which the players will be drawn
3571 ClearRectangleOnBackground(drawto, max_xpos, max_ypos,
3572 max_players_width, max_players_height);
3574 if (!network.enabled && !setup.team_mode)
3577 // only draw players if level is suited for team mode
3578 if (num_players < 2)
3581 // draw all players that were found in the level
3582 for (i = 0; i < MAX_PLAYERS; i++)
3584 if (player_found[i])
3586 int graphic = el2img(EL_PLAYER_1 + i);
3588 DrawSizedGraphicThruMaskExt(drawto, xpos, ypos, graphic, 0, tile_size);
3590 xpos += player_xoffset;
3591 ypos += player_yoffset;
3596 void DrawPreviewLevelInitial(void)
3598 DrawPreviewLevelExt(TRUE);
3599 DrawPreviewPlayers();
3602 void DrawPreviewLevelAnimation(void)
3604 DrawPreviewLevelExt(FALSE);
3607 static void DrawNetworkPlayer(int x, int y, int player_nr, int tile_size,
3608 int border_size, int font_nr)
3610 int graphic = el2img(EL_PLAYER_1 + player_nr);
3611 int font_height = getFontHeight(font_nr);
3612 int player_height = MAX(tile_size, font_height);
3613 int xoffset_text = tile_size + border_size;
3614 int yoffset_text = (player_height - font_height) / 2;
3615 int yoffset_graphic = (player_height - tile_size) / 2;
3616 char *player_name = getNetworkPlayerName(player_nr + 1);
3618 DrawSizedGraphicThruMaskExt(drawto, x, y + yoffset_graphic, graphic, 0,
3620 DrawText(x + xoffset_text, y + yoffset_text, player_name, font_nr);
3623 static void DrawNetworkPlayersExt(boolean force)
3625 if (game_status != GAME_MODE_MAIN)
3628 if (!network.connected && !force)
3631 // do not draw network players if level preview redefined, but players aren't
3632 if (preview.redefined && !menu.main.network_players.redefined)
3635 int num_players = 0;
3638 for (i = 0; i < MAX_PLAYERS; i++)
3639 if (stored_player[i].connected_network)
3642 struct TextPosInfo *pos = &menu.main.network_players;
3643 int tile_size = pos->tile_size;
3644 int border_size = pos->border_size;
3645 int xoffset_text = tile_size + border_size;
3646 int font_nr = pos->font;
3647 int font_width = getFontWidth(font_nr);
3648 int font_height = getFontHeight(font_nr);
3649 int player_height = MAX(tile_size, font_height);
3650 int player_yoffset = player_height + border_size;
3651 int max_players_width = xoffset_text + MAX_PLAYER_NAME_LEN * font_width;
3652 int max_players_height = MAX_PLAYERS * player_yoffset - border_size;
3653 int all_players_height = num_players * player_yoffset - border_size;
3654 int max_xpos = SX + ALIGNED_XPOS(pos->x, max_players_width, pos->align);
3655 int max_ypos = SY + ALIGNED_YPOS(pos->y, max_players_height, pos->valign);
3656 int ypos = SY + ALIGNED_YPOS(pos->y, all_players_height, pos->valign);
3658 ClearRectangleOnBackground(drawto, max_xpos, max_ypos,
3659 max_players_width, max_players_height);
3661 // first draw local network player ...
3662 for (i = 0; i < MAX_PLAYERS; i++)
3664 if (stored_player[i].connected_network &&
3665 stored_player[i].connected_locally)
3667 char *player_name = getNetworkPlayerName(i + 1);
3668 int player_width = xoffset_text + getTextWidth(player_name, font_nr);
3669 int xpos = SX + ALIGNED_XPOS(pos->x, player_width, pos->align);
3671 DrawNetworkPlayer(xpos, ypos, i, tile_size, border_size, font_nr);
3673 ypos += player_yoffset;
3677 // ... then draw all other network players
3678 for (i = 0; i < MAX_PLAYERS; i++)
3680 if (stored_player[i].connected_network &&
3681 !stored_player[i].connected_locally)
3683 char *player_name = getNetworkPlayerName(i + 1);
3684 int player_width = xoffset_text + getTextWidth(player_name, font_nr);
3685 int xpos = SX + ALIGNED_XPOS(pos->x, player_width, pos->align);
3687 DrawNetworkPlayer(xpos, ypos, i, tile_size, border_size, font_nr);
3689 ypos += player_yoffset;
3694 void DrawNetworkPlayers(void)
3696 DrawNetworkPlayersExt(FALSE);
3699 void ClearNetworkPlayers(void)
3701 DrawNetworkPlayersExt(TRUE);
3704 static void DrawGraphicAnimationExt(DrawBuffer *dst_bitmap, int x, int y,
3705 int graphic, int sync_frame,
3708 int frame = getGraphicAnimationFrame(graphic, sync_frame);
3710 if (mask_mode == USE_MASKING)
3711 DrawGraphicThruMaskExt(dst_bitmap, x, y, graphic, frame);
3713 DrawGraphicExt(dst_bitmap, x, y, graphic, frame);
3716 void DrawFixedGraphicAnimationExt(DrawBuffer *dst_bitmap, int x, int y,
3717 int graphic, int sync_frame, int mask_mode)
3719 int frame = getGraphicAnimationFrame(graphic, sync_frame);
3721 if (mask_mode == USE_MASKING)
3722 DrawFixedGraphicThruMaskExt(dst_bitmap, x, y, graphic, frame);
3724 DrawFixedGraphicExt(dst_bitmap, x, y, graphic, frame);
3727 static void DrawGraphicAnimation(int x, int y, int graphic)
3729 int lx = LEVELX(x), ly = LEVELY(y);
3731 if (!IN_SCR_FIELD(x, y))
3734 DrawGraphicAnimationExt(drawto_field, FX + x * TILEX_VAR, FY + y * TILEY_VAR,
3735 graphic, GfxFrame[lx][ly], NO_MASKING);
3737 MarkTileDirty(x, y);
3740 void DrawFixedGraphicAnimation(int x, int y, int graphic)
3742 int lx = LEVELX(x), ly = LEVELY(y);
3744 if (!IN_SCR_FIELD(x, y))
3747 DrawGraphicAnimationExt(drawto_field, FX + x * TILEX, FY + y * TILEY,
3748 graphic, GfxFrame[lx][ly], NO_MASKING);
3749 MarkTileDirty(x, y);
3752 void DrawLevelGraphicAnimation(int x, int y, int graphic)
3754 DrawGraphicAnimation(SCREENX(x), SCREENY(y), graphic);
3757 void DrawLevelElementAnimation(int x, int y, int element)
3759 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
3761 DrawGraphicAnimation(SCREENX(x), SCREENY(y), graphic);
3764 void DrawLevelGraphicAnimationIfNeeded(int x, int y, int graphic)
3766 int sx = SCREENX(x), sy = SCREENY(y);
3768 if (!IN_LEV_FIELD(x, y) || !IN_SCR_FIELD(sx, sy))
3771 if (!IS_NEW_FRAME(GfxFrame[x][y], graphic))
3774 DrawGraphicAnimation(sx, sy, graphic);
3777 if (GFX_CRUMBLED(TILE_GFX_ELEMENT(x, y)))
3778 DrawLevelFieldCrumbled(x, y);
3780 if (GFX_CRUMBLED(Tile[x][y]))
3781 DrawLevelFieldCrumbled(x, y);
3785 void DrawLevelElementAnimationIfNeeded(int x, int y, int element)
3787 int sx = SCREENX(x), sy = SCREENY(y);
3790 if (!IN_LEV_FIELD(x, y) || !IN_SCR_FIELD(sx, sy))
3793 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
3795 if (!IS_NEW_FRAME(GfxFrame[x][y], graphic))
3798 DrawGraphicAnimation(sx, sy, graphic);
3800 if (GFX_CRUMBLED(element))
3801 DrawLevelFieldCrumbled(x, y);
3804 static int getPlayerGraphic(struct PlayerInfo *player, int move_dir)
3806 if (player->use_murphy)
3808 // this works only because currently only one player can be "murphy" ...
3809 static int last_horizontal_dir = MV_LEFT;
3810 int graphic = el_act_dir2img(EL_SP_MURPHY, player->GfxAction, move_dir);
3812 if (move_dir == MV_LEFT || move_dir == MV_RIGHT)
3813 last_horizontal_dir = move_dir;
3815 if (graphic == IMG_SP_MURPHY) // undefined => use special graphic
3817 int direction = (player->is_snapping ? move_dir : last_horizontal_dir);
3819 graphic = el_act_dir2img(EL_SP_MURPHY, player->GfxAction, direction);
3825 return el_act_dir2img(player->artwork_element, player->GfxAction,move_dir);
3828 static boolean equalGraphics(int graphic1, int graphic2)
3830 struct GraphicInfo *g1 = &graphic_info[graphic1];
3831 struct GraphicInfo *g2 = &graphic_info[graphic2];
3833 return (g1->bitmap == g2->bitmap &&
3834 g1->src_x == g2->src_x &&
3835 g1->src_y == g2->src_y &&
3836 g1->anim_frames == g2->anim_frames &&
3837 g1->anim_delay == g2->anim_delay &&
3838 g1->anim_mode == g2->anim_mode);
3841 #define DRAW_PLAYER_OVER_PUSHED_ELEMENT 1
3845 DRAW_PLAYER_STAGE_INIT = 0,
3846 DRAW_PLAYER_STAGE_LAST_FIELD,
3847 DRAW_PLAYER_STAGE_FIELD_UNDER_PLAYER,
3848 #if DRAW_PLAYER_OVER_PUSHED_ELEMENT
3849 DRAW_PLAYER_STAGE_ELEMENT_PUSHED,
3850 DRAW_PLAYER_STAGE_PLAYER,
3852 DRAW_PLAYER_STAGE_PLAYER,
3853 DRAW_PLAYER_STAGE_ELEMENT_PUSHED,
3855 DRAW_PLAYER_STAGE_ELEMENT_OVER_PLAYER,
3856 DRAW_PLAYER_STAGE_FIELD_OVER_PLAYER,
3858 NUM_DRAW_PLAYER_STAGES
3861 static void DrawPlayerExt(struct PlayerInfo *player, int drawing_stage)
3863 static int static_last_player_graphic[MAX_PLAYERS];
3864 static int static_last_player_frame[MAX_PLAYERS];
3865 static boolean static_player_is_opaque[MAX_PLAYERS];
3866 static boolean draw_player[MAX_PLAYERS];
3867 int pnr = player->index_nr;
3869 if (drawing_stage == DRAW_PLAYER_STAGE_INIT)
3871 static_last_player_graphic[pnr] = getPlayerGraphic(player, player->MovDir);
3872 static_last_player_frame[pnr] = player->Frame;
3873 static_player_is_opaque[pnr] = FALSE;
3875 draw_player[pnr] = TRUE;
3878 if (!draw_player[pnr])
3882 if (!IN_LEV_FIELD(player->jx, player->jy))
3884 Debug("draw:DrawPlayerExt", "x = %d, y = %d", player->jx, player->jy);
3885 Debug("draw:DrawPlayerExt", "This should never happen!");
3887 draw_player[pnr] = FALSE;
3893 int last_player_graphic = static_last_player_graphic[pnr];
3894 int last_player_frame = static_last_player_frame[pnr];
3895 boolean player_is_opaque = static_player_is_opaque[pnr];
3897 int jx = player->jx;
3898 int jy = player->jy;
3899 int move_dir = (player->is_waiting ? player->dir_waiting : player->MovDir);
3900 int dx = (move_dir == MV_LEFT ? -1 : move_dir == MV_RIGHT ? +1 : 0);
3901 int dy = (move_dir == MV_UP ? -1 : move_dir == MV_DOWN ? +1 : 0);
3902 int last_jx = (player->is_moving ? jx - dx : jx);
3903 int last_jy = (player->is_moving ? jy - dy : jy);
3904 int next_jx = jx + dx;
3905 int next_jy = jy + dy;
3906 boolean player_is_moving = (player->MovPos != 0 ? TRUE : FALSE);
3907 int sx = SCREENX(jx);
3908 int sy = SCREENY(jy);
3909 int sxx = (move_dir == MV_LEFT || move_dir == MV_RIGHT ? player->GfxPos : 0);
3910 int syy = (move_dir == MV_UP || move_dir == MV_DOWN ? player->GfxPos : 0);
3911 int element = Tile[jx][jy];
3912 int last_element = Tile[last_jx][last_jy];
3913 int action = (player->is_pushing ? ACTION_PUSHING :
3914 player->is_digging ? ACTION_DIGGING :
3915 player->is_collecting ? ACTION_COLLECTING :
3916 player->is_moving ? ACTION_MOVING :
3917 player->is_snapping ? ACTION_SNAPPING :
3918 player->is_dropping ? ACTION_DROPPING :
3919 player->is_waiting ? player->action_waiting :
3922 if (drawing_stage == DRAW_PLAYER_STAGE_INIT)
3924 // ------------------------------------------------------------------------
3925 // initialize drawing the player
3926 // ------------------------------------------------------------------------
3928 draw_player[pnr] = FALSE;
3930 // GfxElement[][] is set to the element the player is digging or collecting;
3931 // remove also for off-screen player if the player is not moving anymore
3932 if (IN_LEV_FIELD(jx, jy) && !player_is_moving)
3933 GfxElement[jx][jy] = EL_UNDEFINED;
3935 if (!player->active || !IN_SCR_FIELD(SCREENX(last_jx), SCREENY(last_jy)))
3938 if (element == EL_EXPLOSION)
3941 InitPlayerGfxAnimation(player, action, move_dir);
3943 draw_player[pnr] = TRUE;
3945 else if (drawing_stage == DRAW_PLAYER_STAGE_LAST_FIELD)
3947 // ------------------------------------------------------------------------
3948 // draw things in the field the player is leaving, if needed
3949 // ------------------------------------------------------------------------
3951 if (!IN_SCR_FIELD(sx, sy))
3952 draw_player[pnr] = FALSE;
3954 if (!player->is_moving)
3957 if (Back[last_jx][last_jy] && IS_DRAWABLE(last_element))
3959 DrawLevelElement(last_jx, last_jy, Back[last_jx][last_jy]);
3961 if (last_element == EL_DYNAMITE_ACTIVE ||
3962 last_element == EL_EM_DYNAMITE_ACTIVE ||
3963 last_element == EL_SP_DISK_RED_ACTIVE)
3964 DrawDynamite(last_jx, last_jy);
3966 DrawLevelFieldThruMask(last_jx, last_jy);
3968 else if (last_element == EL_DYNAMITE_ACTIVE ||
3969 last_element == EL_EM_DYNAMITE_ACTIVE ||
3970 last_element == EL_SP_DISK_RED_ACTIVE)
3971 DrawDynamite(last_jx, last_jy);
3973 DrawLevelField(last_jx, last_jy);
3975 if (player->is_pushing && IN_SCR_FIELD(SCREENX(next_jx), SCREENY(next_jy)))
3976 DrawLevelElement(next_jx, next_jy, EL_EMPTY);
3978 else if (drawing_stage == DRAW_PLAYER_STAGE_FIELD_UNDER_PLAYER)
3980 // ------------------------------------------------------------------------
3981 // draw things behind the player, if needed
3982 // ------------------------------------------------------------------------
3986 DrawLevelElement(jx, jy, Back[jx][jy]);
3991 if (IS_ACTIVE_BOMB(element))
3993 DrawLevelElement(jx, jy, EL_EMPTY);
3998 if (player_is_moving && GfxElement[jx][jy] != EL_UNDEFINED)
4000 int old_element = GfxElement[jx][jy];
4001 int old_graphic = el_act_dir2img(old_element, action, move_dir);
4002 int frame = getGraphicAnimationFrame(old_graphic, player->StepFrame);
4004 if (GFX_CRUMBLED(old_element))
4005 DrawLevelFieldCrumbledDigging(jx, jy, move_dir, player->StepFrame);
4007 DrawGraphic(sx, sy, old_graphic, frame);
4009 if (graphic_info[old_graphic].anim_mode & ANIM_OPAQUE_PLAYER)
4010 static_player_is_opaque[pnr] = TRUE;
4014 GfxElement[jx][jy] = EL_UNDEFINED;
4016 // make sure that pushed elements are drawn with correct frame rate
4017 int graphic = el_act_dir2img(element, ACTION_PUSHING, move_dir);
4019 if (player->is_pushing && player->is_moving && !IS_ANIM_MODE_CE(graphic))
4020 GfxFrame[jx][jy] = player->StepFrame;
4022 DrawLevelField(jx, jy);
4025 else if (drawing_stage == DRAW_PLAYER_STAGE_ELEMENT_PUSHED)
4027 // ------------------------------------------------------------------------
4028 // draw things the player is pushing, if needed
4029 // ------------------------------------------------------------------------
4031 if (!player->is_pushing || !player->is_moving)
4034 int gfx_frame = GfxFrame[jx][jy];
4036 if (!IS_MOVING(jx, jy)) // push movement already finished
4038 element = Tile[next_jx][next_jy];
4039 gfx_frame = GfxFrame[next_jx][next_jy];
4042 int graphic = el_act_dir2img(element, ACTION_PUSHING, move_dir);
4043 int sync_frame = (IS_ANIM_MODE_CE(graphic) ? gfx_frame : player->StepFrame);
4044 int frame = getGraphicAnimationFrame(graphic, sync_frame);
4046 // draw background element under pushed element (like the Sokoban field)
4047 if (game.use_masked_pushing && IS_MOVING(jx, jy))
4049 // this allows transparent pushing animation over non-black background
4052 DrawLevelElement(jx, jy, Back[jx][jy]);
4054 DrawLevelElement(jx, jy, EL_EMPTY);
4056 if (Back[next_jx][next_jy])
4057 DrawLevelElement(next_jx, next_jy, Back[next_jx][next_jy]);
4059 DrawLevelElement(next_jx, next_jy, EL_EMPTY);
4061 else if (Back[next_jx][next_jy])
4062 DrawLevelElement(next_jx, next_jy, Back[next_jx][next_jy]);
4064 int px = SCREENX(jx), py = SCREENY(jy);
4065 int pxx = (TILEX - ABS(sxx)) * dx;
4066 int pyy = (TILEY - ABS(syy)) * dy;
4069 // do not draw (EM style) pushing animation when pushing is finished
4070 // (two-tile animations usually do not contain start and end frame)
4071 if (graphic_info[graphic].double_movement && !IS_MOVING(jx, jy))
4072 DrawLevelElement(next_jx, next_jy, Tile[next_jx][next_jy]);
4074 DrawGraphicShiftedThruMask(px, py, pxx, pyy, graphic, frame, NO_CUTTING);
4076 // masked drawing is needed for EMC style (double) movement graphics
4077 // !!! (ONLY WHEN DRAWING PUSHED ELEMENT OVER THE PLAYER) !!!
4078 DrawGraphicShiftedThruMask(px, py, pxx, pyy, graphic, frame, NO_CUTTING);
4081 else if (drawing_stage == DRAW_PLAYER_STAGE_PLAYER)
4083 // ------------------------------------------------------------------------
4084 // draw player himself
4085 // ------------------------------------------------------------------------
4087 int graphic = getPlayerGraphic(player, move_dir);
4089 // in the case of changed player action or direction, prevent the current
4090 // animation frame from being restarted for identical animations
4091 if (player->Frame == 0 && equalGraphics(graphic, last_player_graphic))
4092 player->Frame = last_player_frame;
4094 int frame = getGraphicAnimationFrame(graphic, player->Frame);
4096 if (player_is_opaque)
4097 DrawGraphicShifted(sx,sy, sxx,syy, graphic, frame, NO_CUTTING,NO_MASKING);
4099 DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic, frame, NO_CUTTING);
4101 if (SHIELD_ON(player))
4103 graphic = (player->shield_deadly_time_left ? IMG_SHIELD_DEADLY_ACTIVE :
4104 IMG_SHIELD_NORMAL_ACTIVE);
4105 frame = getGraphicAnimationFrame(graphic, -1);
4107 DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic, frame, NO_CUTTING);
4110 else if (drawing_stage == DRAW_PLAYER_STAGE_ELEMENT_OVER_PLAYER)
4112 // ------------------------------------------------------------------------
4113 // draw things in front of player (active dynamite or dynabombs)
4114 // ------------------------------------------------------------------------
4116 if (IS_ACTIVE_BOMB(element))
4118 int graphic = el2img(element);
4119 int frame = getGraphicAnimationFrame(graphic, GfxFrame[jx][jy]);
4121 if (game.emulation == EMU_SUPAPLEX)
4122 DrawGraphic(sx, sy, IMG_SP_DISK_RED, frame);
4124 DrawGraphicThruMask(sx, sy, graphic, frame);
4127 if (player_is_moving && last_element == EL_EXPLOSION)
4129 int element = (GfxElement[last_jx][last_jy] != EL_UNDEFINED ?
4130 GfxElement[last_jx][last_jy] : EL_EMPTY);
4131 int graphic = el_act2img(element, ACTION_EXPLODING);
4132 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
4133 int phase = ExplodePhase[last_jx][last_jy] - 1;
4134 int frame = getGraphicAnimationFrame(graphic, phase - delay);
4137 DrawGraphicThruMask(SCREENX(last_jx), SCREENY(last_jy), graphic, frame);
4140 else if (drawing_stage == DRAW_PLAYER_STAGE_FIELD_OVER_PLAYER)
4142 // ------------------------------------------------------------------------
4143 // draw elements the player is just walking/passing through/under
4144 // ------------------------------------------------------------------------
4146 if (player_is_moving)
4148 // handle the field the player is leaving ...
4149 if (IS_ACCESSIBLE_INSIDE(last_element))
4150 DrawLevelField(last_jx, last_jy);
4151 else if (IS_ACCESSIBLE_UNDER(last_element))
4152 DrawLevelFieldThruMask(last_jx, last_jy);
4155 // do not redraw accessible elements if the player is just pushing them
4156 if (!player_is_moving || !player->is_pushing)
4158 // ... and the field the player is entering
4159 if (IS_ACCESSIBLE_INSIDE(element))
4160 DrawLevelField(jx, jy);
4161 else if (IS_ACCESSIBLE_UNDER(element))
4162 DrawLevelFieldThruMask(jx, jy);
4165 MarkTileDirty(sx, sy);
4169 void DrawPlayer(struct PlayerInfo *player)
4173 for (i = 0; i < NUM_DRAW_PLAYER_STAGES; i++)
4174 DrawPlayerExt(player, i);
4177 void DrawAllPlayers(void)
4181 for (i = 0; i < NUM_DRAW_PLAYER_STAGES; i++)
4182 for (j = 0; j < MAX_PLAYERS; j++)
4183 if (stored_player[j].active)
4184 DrawPlayerExt(&stored_player[j], i);
4187 void DrawPlayerField(int x, int y)
4189 if (!IS_PLAYER(x, y))
4192 DrawPlayer(PLAYERINFO(x, y));
4195 // ----------------------------------------------------------------------------
4197 void WaitForEventToContinue(void)
4199 boolean still_wait = TRUE;
4201 if (program.headless)
4204 // simulate releasing mouse button over last gadget, if still pressed
4206 HandleGadgets(-1, -1, 0);
4208 button_status = MB_RELEASED;
4216 if (NextValidEvent(&event))
4220 case EVENT_BUTTONRELEASE:
4221 case EVENT_KEYPRESS:
4222 case SDL_CONTROLLERBUTTONDOWN:
4223 case SDL_JOYBUTTONDOWN:
4227 case EVENT_KEYRELEASE:
4228 ClearPlayerAction();
4232 HandleOtherEvents(&event);
4236 else if (AnyJoystickButton() == JOY_BUTTON_NEW_PRESSED)
4245 #define MAX_REQUEST_LINES 13
4246 #define MAX_REQUEST_LINE_FONT1_LEN 7
4247 #define MAX_REQUEST_LINE_FONT2_LEN 10
4249 static int RequestHandleEvents(unsigned int req_state)
4251 boolean game_just_ended = (game_status == GAME_MODE_PLAYING &&
4253 int width = request.width;
4254 int height = request.height;
4258 // when showing request dialog after game ended, deactivate game panel
4259 if (game_just_ended)
4260 game.panel.active = FALSE;
4262 game.request_active = TRUE;
4264 setRequestPosition(&sx, &sy, FALSE);
4266 button_status = MB_RELEASED;
4268 request_gadget_id = -1;
4273 if (game_just_ended)
4275 // the MM game engine does not use a special (scrollable) field buffer
4276 if (level.game_engine_type != GAME_ENGINE_TYPE_MM)
4277 SetDrawtoField(DRAW_TO_FIELDBUFFER);
4279 HandleGameActions();
4281 SetDrawtoField(DRAW_TO_BACKBUFFER);
4283 if (global.use_envelope_request)
4285 // copy current state of request area to middle of playfield area
4286 BlitBitmap(bitmap_db_store_2, drawto, sx, sy, width, height, sx, sy);
4294 while (NextValidEvent(&event))
4298 case EVENT_BUTTONPRESS:
4299 case EVENT_BUTTONRELEASE:
4300 case EVENT_MOTIONNOTIFY:
4304 if (event.type == EVENT_MOTIONNOTIFY)
4309 motion_status = TRUE;
4310 mx = ((MotionEvent *) &event)->x;
4311 my = ((MotionEvent *) &event)->y;
4315 motion_status = FALSE;
4316 mx = ((ButtonEvent *) &event)->x;
4317 my = ((ButtonEvent *) &event)->y;
4318 if (event.type == EVENT_BUTTONPRESS)
4319 button_status = ((ButtonEvent *) &event)->button;
4321 button_status = MB_RELEASED;
4324 // this sets 'request_gadget_id'
4325 HandleGadgets(mx, my, button_status);
4327 switch (request_gadget_id)
4329 case TOOL_CTRL_ID_YES:
4330 case TOOL_CTRL_ID_TOUCH_YES:
4333 case TOOL_CTRL_ID_NO:
4334 case TOOL_CTRL_ID_TOUCH_NO:
4337 case TOOL_CTRL_ID_CONFIRM:
4338 case TOOL_CTRL_ID_TOUCH_CONFIRM:
4339 result = TRUE | FALSE;
4342 case TOOL_CTRL_ID_PLAYER_1:
4345 case TOOL_CTRL_ID_PLAYER_2:
4348 case TOOL_CTRL_ID_PLAYER_3:
4351 case TOOL_CTRL_ID_PLAYER_4:
4356 // only check clickable animations if no request gadget clicked
4357 HandleGlobalAnimClicks(mx, my, button_status, FALSE);
4364 case SDL_WINDOWEVENT:
4365 HandleWindowEvent((WindowEvent *) &event);
4368 case SDL_APP_WILLENTERBACKGROUND:
4369 case SDL_APP_DIDENTERBACKGROUND:
4370 case SDL_APP_WILLENTERFOREGROUND:
4371 case SDL_APP_DIDENTERFOREGROUND:
4372 HandlePauseResumeEvent((PauseResumeEvent *) &event);
4375 case EVENT_KEYPRESS:
4377 Key key = GetEventKey((KeyEvent *)&event, TRUE);
4382 if (req_state & REQ_CONFIRM)
4391 #if defined(KSYM_Rewind)
4392 case KSYM_Rewind: // for Amazon Fire TV remote
4401 #if defined(KSYM_FastForward)
4402 case KSYM_FastForward: // for Amazon Fire TV remote
4408 HandleKeysDebug(key, KEY_PRESSED);
4412 if (req_state & REQ_PLAYER)
4414 int old_player_nr = setup.network_player_nr;
4417 result = old_player_nr + 1;
4422 result = old_player_nr + 1;
4453 case EVENT_FINGERRELEASE:
4454 case EVENT_KEYRELEASE:
4455 ClearPlayerAction();
4458 case SDL_CONTROLLERBUTTONDOWN:
4459 switch (event.cbutton.button)
4461 case SDL_CONTROLLER_BUTTON_A:
4462 case SDL_CONTROLLER_BUTTON_X:
4463 case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
4464 case SDL_CONTROLLER_BUTTON_LEFTSTICK:
4468 case SDL_CONTROLLER_BUTTON_B:
4469 case SDL_CONTROLLER_BUTTON_Y:
4470 case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
4471 case SDL_CONTROLLER_BUTTON_RIGHTSTICK:
4472 case SDL_CONTROLLER_BUTTON_BACK:
4477 if (req_state & REQ_PLAYER)
4479 int old_player_nr = setup.network_player_nr;
4482 result = old_player_nr + 1;
4484 switch (event.cbutton.button)
4486 case SDL_CONTROLLER_BUTTON_DPAD_UP:
4487 case SDL_CONTROLLER_BUTTON_Y:
4491 case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
4492 case SDL_CONTROLLER_BUTTON_B:
4496 case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
4497 case SDL_CONTROLLER_BUTTON_A:
4501 case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
4502 case SDL_CONTROLLER_BUTTON_X:
4513 case SDL_CONTROLLERBUTTONUP:
4514 HandleJoystickEvent(&event);
4515 ClearPlayerAction();
4519 HandleOtherEvents(&event);
4524 else if (AnyJoystickButton() == JOY_BUTTON_NEW_PRESSED)
4526 int joy = AnyJoystick();
4528 if (joy & JOY_BUTTON_1)
4530 else if (joy & JOY_BUTTON_2)
4533 else if (AnyJoystick())
4535 int joy = AnyJoystick();
4537 if (req_state & REQ_PLAYER)
4541 else if (joy & JOY_RIGHT)
4543 else if (joy & JOY_DOWN)
4545 else if (joy & JOY_LEFT)
4550 if (game_just_ended)
4552 if (global.use_envelope_request)
4554 // copy back current state of pressed buttons inside request area
4555 BlitBitmap(drawto, bitmap_db_store_2, sx, sy, width, height, sx, sy);
4562 game.request_active = FALSE;
4567 static boolean RequestDoor(char *text, unsigned int req_state)
4569 unsigned int old_door_state;
4570 int max_request_line_len = MAX_REQUEST_LINE_FONT1_LEN;
4571 int font_nr = FONT_TEXT_2;
4576 if (maxWordLengthInRequestString(text) > MAX_REQUEST_LINE_FONT1_LEN)
4578 max_request_line_len = MAX_REQUEST_LINE_FONT2_LEN;
4579 font_nr = FONT_TEXT_1;
4582 if (game_status == GAME_MODE_PLAYING)
4583 BlitScreenToBitmap(backbuffer);
4585 // disable deactivated drawing when quick-loading level tape recording
4586 if (tape.playing && tape.deactivate_display)
4587 TapeDeactivateDisplayOff(TRUE);
4589 SetMouseCursor(CURSOR_DEFAULT);
4591 // pause network game while waiting for request to answer
4592 if (network.enabled &&
4593 game_status == GAME_MODE_PLAYING &&
4594 !game.all_players_gone &&
4595 req_state & REQUEST_WAIT_FOR_INPUT)
4596 SendToServer_PausePlaying();
4598 old_door_state = GetDoorState();
4600 // simulate releasing mouse button over last gadget, if still pressed
4602 HandleGadgets(-1, -1, 0);
4606 // draw released gadget before proceeding
4609 if (old_door_state & DOOR_OPEN_1)
4611 CloseDoor(DOOR_CLOSE_1);
4613 // save old door content
4614 BlitBitmap(bitmap_db_door_1, bitmap_db_door_1,
4615 0 * DXSIZE, 0, DXSIZE, DYSIZE, 1 * DXSIZE, 0);
4618 SetDoorBackgroundImage(IMG_BACKGROUND_DOOR);
4619 SetDrawBackgroundMask(REDRAW_FIELD | REDRAW_DOOR_1);
4621 // clear door drawing field
4622 DrawBackground(DX, DY, DXSIZE, DYSIZE);
4624 // force DOOR font inside door area
4625 SetFontStatus(GAME_MODE_PSEUDO_DOOR);
4627 // write text for request
4628 for (text_ptr = text, ty = 0; ty < MAX_REQUEST_LINES; ty++)
4630 char text_line[max_request_line_len + 1];
4636 for (tl = 0, tx = 0; tx < max_request_line_len; tl++, tx++)
4638 tc = *(text_ptr + tx);
4639 // if (!tc || tc == ' ')
4640 if (!tc || tc == ' ' || tc == '?' || tc == '!')
4644 if ((tc == '?' || tc == '!') && tl == 0)
4654 strncpy(text_line, text_ptr, tl);
4657 DrawText(DX + (DXSIZE - tl * getFontWidth(font_nr)) / 2,
4658 DY + 8 + ty * (getFontHeight(font_nr) + 2),
4659 text_line, font_nr);
4661 text_ptr += tl + (tc == ' ' ? 1 : 0);
4662 // text_ptr += tl + (tc == ' ' || tc == '?' || tc == '!' ? 1 : 0);
4667 if (req_state & REQ_ASK)
4669 MapGadget(tool_gadget[TOOL_CTRL_ID_YES]);
4670 MapGadget(tool_gadget[TOOL_CTRL_ID_NO]);
4671 MapGadget(tool_gadget[TOOL_CTRL_ID_TOUCH_YES]);
4672 MapGadget(tool_gadget[TOOL_CTRL_ID_TOUCH_NO]);
4674 else if (req_state & REQ_CONFIRM)
4676 MapGadget(tool_gadget[TOOL_CTRL_ID_CONFIRM]);
4677 MapGadget(tool_gadget[TOOL_CTRL_ID_TOUCH_CONFIRM]);
4679 else if (req_state & REQ_PLAYER)
4681 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_1]);
4682 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_2]);
4683 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_3]);
4684 MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_4]);
4687 // copy request gadgets to door backbuffer
4688 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
4690 OpenDoor(DOOR_OPEN_1);
4692 if (!(req_state & REQUEST_WAIT_FOR_INPUT))
4694 if (game_status == GAME_MODE_PLAYING)
4696 SetPanelBackground();
4697 SetDrawBackgroundMask(REDRAW_DOOR_1);
4701 SetDrawBackgroundMask(REDRAW_FIELD);
4707 SetDrawBackgroundMask(REDRAW_FIELD | REDRAW_DOOR_1);
4709 // ---------- handle request buttons ----------
4710 result = RequestHandleEvents(req_state);
4714 if (!(req_state & REQ_STAY_OPEN))
4716 CloseDoor(DOOR_CLOSE_1);
4718 if (((old_door_state & DOOR_OPEN_1) && !(req_state & REQ_STAY_CLOSED)) ||
4719 (req_state & REQ_REOPEN))
4720 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
4725 if (game_status == GAME_MODE_PLAYING)
4727 SetPanelBackground();
4728 SetDrawBackgroundMask(REDRAW_DOOR_1);
4732 SetDrawBackgroundMask(REDRAW_FIELD);
4735 // continue network game after request
4736 if (network.enabled &&
4737 game_status == GAME_MODE_PLAYING &&
4738 !game.all_players_gone &&
4739 req_state & REQUEST_WAIT_FOR_INPUT)
4740 SendToServer_ContinuePlaying();
4742 // restore deactivated drawing when quick-loading level tape recording
4743 if (tape.playing && tape.deactivate_display)
4744 TapeDeactivateDisplayOn();
4749 static boolean RequestEnvelope(char *text, unsigned int req_state)
4753 if (game_status == GAME_MODE_PLAYING)
4754 BlitScreenToBitmap(backbuffer);
4756 // disable deactivated drawing when quick-loading level tape recording
4757 if (tape.playing && tape.deactivate_display)
4758 TapeDeactivateDisplayOff(TRUE);
4760 SetMouseCursor(CURSOR_DEFAULT);
4762 // pause network game while waiting for request to answer
4763 if (network.enabled &&
4764 game_status == GAME_MODE_PLAYING &&
4765 !game.all_players_gone &&
4766 req_state & REQUEST_WAIT_FOR_INPUT)
4767 SendToServer_PausePlaying();
4769 // simulate releasing mouse button over last gadget, if still pressed
4771 HandleGadgets(-1, -1, 0);
4775 // (replace with setting corresponding request background)
4776 // SetDoorBackgroundImage(IMG_BACKGROUND_DOOR);
4777 // SetDrawBackgroundMask(REDRAW_FIELD | REDRAW_DOOR_1);
4779 // clear door drawing field
4780 // DrawBackground(DX, DY, DXSIZE, DYSIZE);
4782 ShowEnvelopeRequest(text, req_state, ACTION_OPENING);
4784 if (!(req_state & REQUEST_WAIT_FOR_INPUT))
4786 if (game_status == GAME_MODE_PLAYING)
4788 SetPanelBackground();
4789 SetDrawBackgroundMask(REDRAW_DOOR_1);
4793 SetDrawBackgroundMask(REDRAW_FIELD);
4799 SetDrawBackgroundMask(REDRAW_FIELD | REDRAW_DOOR_1);
4801 // ---------- handle request buttons ----------
4802 result = RequestHandleEvents(req_state);
4806 ShowEnvelopeRequest(text, req_state, ACTION_CLOSING);
4810 if (game_status == GAME_MODE_PLAYING)
4812 SetPanelBackground();
4813 SetDrawBackgroundMask(REDRAW_DOOR_1);
4817 SetDrawBackgroundMask(REDRAW_FIELD);
4820 // continue network game after request
4821 if (network.enabled &&
4822 game_status == GAME_MODE_PLAYING &&
4823 !game.all_players_gone &&
4824 req_state & REQUEST_WAIT_FOR_INPUT)
4825 SendToServer_ContinuePlaying();
4827 // restore deactivated drawing when quick-loading level tape recording
4828 if (tape.playing && tape.deactivate_display)
4829 TapeDeactivateDisplayOn();
4834 boolean Request(char *text, unsigned int req_state)
4836 boolean overlay_enabled = GetOverlayEnabled();
4839 SetOverlayEnabled(FALSE);
4841 if (global.use_envelope_request)
4842 result = RequestEnvelope(text, req_state);
4844 result = RequestDoor(text, req_state);
4846 SetOverlayEnabled(overlay_enabled);
4851 static int compareDoorPartOrderInfo(const void *object1, const void *object2)
4853 const struct DoorPartOrderInfo *dpo1 = (struct DoorPartOrderInfo *)object1;
4854 const struct DoorPartOrderInfo *dpo2 = (struct DoorPartOrderInfo *)object2;
4857 if (dpo1->sort_priority != dpo2->sort_priority)
4858 compare_result = dpo1->sort_priority - dpo2->sort_priority;
4860 compare_result = dpo1->nr - dpo2->nr;
4862 return compare_result;
4865 void InitGraphicCompatibilityInfo_Doors(void)
4871 struct DoorInfo *door;
4875 { DOOR_1, IMG_GFX_DOOR_1_PART_1, IMG_GFX_DOOR_1_PART_8, &door_1 },
4876 { DOOR_2, IMG_GFX_DOOR_2_PART_1, IMG_GFX_DOOR_2_PART_8, &door_2 },
4878 { -1, -1, -1, NULL }
4880 struct Rect door_rect_list[] =
4882 { DX, DY, DXSIZE, DYSIZE },
4883 { VX, VY, VXSIZE, VYSIZE }
4887 for (i = 0; doors[i].door_token != -1; i++)
4889 int door_token = doors[i].door_token;
4890 int door_index = DOOR_INDEX_FROM_TOKEN(door_token);
4891 int part_1 = doors[i].part_1;
4892 int part_8 = doors[i].part_8;
4893 int part_2 = part_1 + 1;
4894 int part_3 = part_1 + 2;
4895 struct DoorInfo *door = doors[i].door;
4896 struct Rect *door_rect = &door_rect_list[door_index];
4897 boolean door_gfx_redefined = FALSE;
4899 // check if any door part graphic definitions have been redefined
4901 for (j = 0; door_part_controls[j].door_token != -1; j++)
4903 struct DoorPartControlInfo *dpc = &door_part_controls[j];
4904 struct FileInfo *fi = getImageListEntryFromImageID(dpc->graphic);
4906 if (dpc->door_token == door_token && fi->redefined)
4907 door_gfx_redefined = TRUE;
4910 // check for old-style door graphic/animation modifications
4912 if (!door_gfx_redefined)
4914 if (door->anim_mode & ANIM_STATIC_PANEL)
4916 door->panel.step_xoffset = 0;
4917 door->panel.step_yoffset = 0;
4920 if (door->anim_mode & (ANIM_HORIZONTAL | ANIM_VERTICAL))
4922 struct GraphicInfo *g_part_1 = &graphic_info[part_1];
4923 struct GraphicInfo *g_part_2 = &graphic_info[part_2];
4924 int num_door_steps, num_panel_steps;
4926 // remove door part graphics other than the two default wings
4928 for (j = 0; door_part_controls[j].door_token != -1; j++)
4930 struct DoorPartControlInfo *dpc = &door_part_controls[j];
4931 struct GraphicInfo *g = &graphic_info[dpc->graphic];
4933 if (dpc->graphic >= part_3 &&
4934 dpc->graphic <= part_8)
4938 // set graphics and screen positions of the default wings
4940 g_part_1->width = door_rect->width;
4941 g_part_1->height = door_rect->height;
4942 g_part_2->width = door_rect->width;
4943 g_part_2->height = door_rect->height;
4944 g_part_2->src_x = door_rect->width;
4945 g_part_2->src_y = g_part_1->src_y;
4947 door->part_2.x = door->part_1.x;
4948 door->part_2.y = door->part_1.y;
4950 if (door->width != -1)
4952 g_part_1->width = door->width;
4953 g_part_2->width = door->width;
4955 // special treatment for graphics and screen position of right wing
4956 g_part_2->src_x += door_rect->width - door->width;
4957 door->part_2.x += door_rect->width - door->width;
4960 if (door->height != -1)
4962 g_part_1->height = door->height;
4963 g_part_2->height = door->height;
4965 // special treatment for graphics and screen position of bottom wing
4966 g_part_2->src_y += door_rect->height - door->height;
4967 door->part_2.y += door_rect->height - door->height;
4970 // set animation delays for the default wings and panels
4972 door->part_1.step_delay = door->step_delay;
4973 door->part_2.step_delay = door->step_delay;
4974 door->panel.step_delay = door->step_delay;
4976 // set animation draw order for the default wings
4978 door->part_1.sort_priority = 2; // draw left wing over ...
4979 door->part_2.sort_priority = 1; // ... right wing
4981 // set animation draw offset for the default wings
4983 if (door->anim_mode & ANIM_HORIZONTAL)
4985 door->part_1.step_xoffset = door->step_offset;
4986 door->part_1.step_yoffset = 0;
4987 door->part_2.step_xoffset = door->step_offset * -1;
4988 door->part_2.step_yoffset = 0;
4990 num_door_steps = g_part_1->width / door->step_offset;
4992 else // ANIM_VERTICAL
4994 door->part_1.step_xoffset = 0;
4995 door->part_1.step_yoffset = door->step_offset;
4996 door->part_2.step_xoffset = 0;
4997 door->part_2.step_yoffset = door->step_offset * -1;
4999 num_door_steps = g_part_1->height / door->step_offset;
5002 // set animation draw offset for the default panels
5004 if (door->step_offset > 1)
5006 num_panel_steps = 2 * door_rect->height / door->step_offset;
5007 door->panel.start_step = num_panel_steps - num_door_steps;
5008 door->panel.start_step_closing = door->panel.start_step;
5012 num_panel_steps = door_rect->height / door->step_offset;
5013 door->panel.start_step = num_panel_steps - num_door_steps / 2;
5014 door->panel.start_step_closing = door->panel.start_step;
5015 door->panel.step_delay *= 2;
5022 void InitDoors(void)
5026 for (i = 0; door_part_controls[i].door_token != -1; i++)
5028 struct DoorPartControlInfo *dpc = &door_part_controls[i];
5029 struct DoorPartOrderInfo *dpo = &door_part_order[i];
5031 // initialize "start_step_opening" and "start_step_closing", if needed
5032 if (dpc->pos->start_step_opening == 0 &&
5033 dpc->pos->start_step_closing == 0)
5035 // dpc->pos->start_step_opening = dpc->pos->start_step;
5036 dpc->pos->start_step_closing = dpc->pos->start_step;
5039 // fill structure for door part draw order (sorted below)
5041 dpo->sort_priority = dpc->pos->sort_priority;
5044 // sort door part controls according to sort_priority and graphic number
5045 qsort(door_part_order, MAX_DOOR_PARTS,
5046 sizeof(struct DoorPartOrderInfo), compareDoorPartOrderInfo);
5049 unsigned int OpenDoor(unsigned int door_state)
5051 if (door_state & DOOR_COPY_BACK)
5053 if (door_state & DOOR_OPEN_1)
5054 BlitBitmap(bitmap_db_door_1, bitmap_db_door_1,
5055 1 * DXSIZE, 0, DXSIZE, DYSIZE, 0 * DXSIZE, 0);
5057 if (door_state & DOOR_OPEN_2)
5058 BlitBitmap(bitmap_db_door_2, bitmap_db_door_2,
5059 1 * VXSIZE, 0, VXSIZE, VYSIZE, 0 * VXSIZE, 0);
5061 door_state &= ~DOOR_COPY_BACK;
5064 return MoveDoor(door_state);
5067 unsigned int CloseDoor(unsigned int door_state)
5069 unsigned int old_door_state = GetDoorState();
5071 if (!(door_state & DOOR_NO_COPY_BACK))
5073 if (old_door_state & DOOR_OPEN_1)
5074 BlitBitmap(backbuffer, bitmap_db_door_1,
5075 DX, DY, DXSIZE, DYSIZE, 0, 0);
5077 if (old_door_state & DOOR_OPEN_2)
5078 BlitBitmap(backbuffer, bitmap_db_door_2,
5079 VX, VY, VXSIZE, VYSIZE, 0, 0);
5081 door_state &= ~DOOR_NO_COPY_BACK;
5084 return MoveDoor(door_state);
5087 unsigned int GetDoorState(void)
5089 return MoveDoor(DOOR_GET_STATE);
5092 unsigned int SetDoorState(unsigned int door_state)
5094 return MoveDoor(door_state | DOOR_SET_STATE);
5097 static int euclid(int a, int b)
5099 return (b ? euclid(b, a % b) : a);
5102 unsigned int MoveDoor(unsigned int door_state)
5104 struct Rect door_rect_list[] =
5106 { DX, DY, DXSIZE, DYSIZE },
5107 { VX, VY, VXSIZE, VYSIZE }
5109 static int door1 = DOOR_CLOSE_1;
5110 static int door2 = DOOR_CLOSE_2;
5111 unsigned int door_delay = 0;
5112 unsigned int door_delay_value;
5115 if (door_state == DOOR_GET_STATE)
5116 return (door1 | door2);
5118 if (door_state & DOOR_SET_STATE)
5120 if (door_state & DOOR_ACTION_1)
5121 door1 = door_state & DOOR_ACTION_1;
5122 if (door_state & DOOR_ACTION_2)
5123 door2 = door_state & DOOR_ACTION_2;
5125 return (door1 | door2);
5128 if (!(door_state & DOOR_FORCE_REDRAW))
5130 if (door1 == DOOR_OPEN_1 && door_state & DOOR_OPEN_1)
5131 door_state &= ~DOOR_OPEN_1;
5132 else if (door1 == DOOR_CLOSE_1 && door_state & DOOR_CLOSE_1)
5133 door_state &= ~DOOR_CLOSE_1;
5134 if (door2 == DOOR_OPEN_2 && door_state & DOOR_OPEN_2)
5135 door_state &= ~DOOR_OPEN_2;
5136 else if (door2 == DOOR_CLOSE_2 && door_state & DOOR_CLOSE_2)
5137 door_state &= ~DOOR_CLOSE_2;
5140 if (global.autoplay_leveldir)
5142 door_state |= DOOR_NO_DELAY;
5143 door_state &= ~DOOR_CLOSE_ALL;
5146 if (game_status == GAME_MODE_EDITOR && !(door_state & DOOR_FORCE_ANIM))
5147 door_state |= DOOR_NO_DELAY;
5149 if (door_state & DOOR_ACTION)
5151 boolean door_panel_drawn[NUM_DOORS];
5152 boolean panel_has_doors[NUM_DOORS];
5153 boolean door_part_skip[MAX_DOOR_PARTS];
5154 boolean door_part_done[MAX_DOOR_PARTS];
5155 boolean door_part_done_all;
5156 int num_steps[MAX_DOOR_PARTS];
5157 int max_move_delay = 0; // delay for complete animations of all doors
5158 int max_step_delay = 0; // delay (ms) between two animation frames
5159 int num_move_steps = 0; // number of animation steps for all doors
5160 int max_move_delay_doors_only = 0; // delay for doors only (no panel)
5161 int num_move_steps_doors_only = 0; // steps for doors only (no panel)
5162 int current_move_delay = 0;
5166 for (i = 0; i < NUM_DOORS; i++)
5167 panel_has_doors[i] = FALSE;
5169 for (i = 0; i < MAX_DOOR_PARTS; i++)
5171 struct DoorPartControlInfo *dpc = &door_part_controls[i];
5172 struct GraphicInfo *g = &graphic_info[dpc->graphic];
5173 int door_token = dpc->door_token;
5175 door_part_done[i] = FALSE;
5176 door_part_skip[i] = (!(door_state & door_token) ||
5180 for (i = 0; i < MAX_DOOR_PARTS; i++)
5182 int nr = door_part_order[i].nr;
5183 struct DoorPartControlInfo *dpc = &door_part_controls[nr];
5184 struct DoorPartPosInfo *pos = dpc->pos;
5185 struct GraphicInfo *g = &graphic_info[dpc->graphic];
5186 int door_token = dpc->door_token;
5187 int door_index = DOOR_INDEX_FROM_TOKEN(door_token);
5188 boolean is_panel = DOOR_PART_IS_PANEL(nr);
5189 int step_xoffset = ABS(pos->step_xoffset);
5190 int step_yoffset = ABS(pos->step_yoffset);
5191 int step_delay = pos->step_delay;
5192 int current_door_state = door_state & door_token;
5193 boolean door_opening = ((current_door_state & DOOR_OPEN) != 0);
5194 boolean door_closing = ((current_door_state & DOOR_CLOSE) != 0);
5195 boolean part_opening = (is_panel ? door_closing : door_opening);
5196 int start_step = (part_opening ? pos->start_step_opening :
5197 pos->start_step_closing);
5198 float move_xsize = (step_xoffset ? g->width : 0);
5199 float move_ysize = (step_yoffset ? g->height : 0);
5200 int move_xsteps = (step_xoffset ? ceil(move_xsize / step_xoffset) : 0);
5201 int move_ysteps = (step_yoffset ? ceil(move_ysize / step_yoffset) : 0);
5202 int move_steps = (move_xsteps && move_ysteps ?
5203 MIN(move_xsteps, move_ysteps) :
5204 move_xsteps ? move_xsteps : move_ysteps) - start_step;
5205 int move_delay = move_steps * step_delay;
5207 if (door_part_skip[nr])
5210 max_move_delay = MAX(max_move_delay, move_delay);
5211 max_step_delay = (max_step_delay == 0 ? step_delay :
5212 euclid(max_step_delay, step_delay));
5213 num_steps[nr] = move_steps;
5217 max_move_delay_doors_only = MAX(max_move_delay_doors_only, move_delay);
5219 panel_has_doors[door_index] = TRUE;
5223 max_step_delay = MAX(1, max_step_delay); // prevent division by zero
5225 num_move_steps = max_move_delay / max_step_delay;
5226 num_move_steps_doors_only = max_move_delay_doors_only / max_step_delay;
5228 door_delay_value = max_step_delay;
5230 if ((door_state & DOOR_NO_DELAY) || setup.quick_doors)
5232 start = num_move_steps - 1;
5236 // opening door sound has priority over simultaneously closing door
5237 if (door_state & (DOOR_OPEN_1 | DOOR_OPEN_2))
5239 PlayMenuSoundStereo(SND_DOOR_OPENING, SOUND_MIDDLE);
5241 if (door_state & DOOR_OPEN_1)
5242 PlayMenuSoundStereo(SND_DOOR_1_OPENING, SOUND_MIDDLE);
5243 if (door_state & DOOR_OPEN_2)
5244 PlayMenuSoundStereo(SND_DOOR_2_OPENING, SOUND_MIDDLE);
5246 else if (door_state & (DOOR_CLOSE_1 | DOOR_CLOSE_2))
5248 PlayMenuSoundStereo(SND_DOOR_CLOSING, SOUND_MIDDLE);
5250 if (door_state & DOOR_CLOSE_1)
5251 PlayMenuSoundStereo(SND_DOOR_1_CLOSING, SOUND_MIDDLE);
5252 if (door_state & DOOR_CLOSE_2)
5253 PlayMenuSoundStereo(SND_DOOR_2_CLOSING, SOUND_MIDDLE);
5257 for (k = start; k < num_move_steps; k++)
5259 int last_frame = num_move_steps - 1; // last frame of this "for" loop
5261 door_part_done_all = TRUE;
5263 for (i = 0; i < NUM_DOORS; i++)
5264 door_panel_drawn[i] = FALSE;
5266 for (i = 0; i < MAX_DOOR_PARTS; i++)
5268 int nr = door_part_order[i].nr;
5269 struct DoorPartControlInfo *dpc = &door_part_controls[nr];
5270 struct DoorPartPosInfo *pos = dpc->pos;
5271 struct GraphicInfo *g = &graphic_info[dpc->graphic];
5272 int door_token = dpc->door_token;
5273 int door_index = DOOR_INDEX_FROM_TOKEN(door_token);
5274 boolean is_panel = DOOR_PART_IS_PANEL(nr);
5275 boolean is_panel_and_door_has_closed = FALSE;
5276 struct Rect *door_rect = &door_rect_list[door_index];
5277 Bitmap *bitmap_db_door = (door_token == DOOR_1 ? bitmap_db_door_1 :
5279 Bitmap *bitmap = (is_panel ? bitmap_db_door : g->bitmap);
5280 int current_door_state = door_state & door_token;
5281 boolean door_opening = ((current_door_state & DOOR_OPEN) != 0);
5282 boolean door_closing = !door_opening;
5283 boolean part_opening = (is_panel ? door_closing : door_opening);
5284 boolean part_closing = !part_opening;
5285 int start_step = (part_opening ? pos->start_step_opening :
5286 pos->start_step_closing);
5287 int step_delay = pos->step_delay;
5288 int step_factor = step_delay / max_step_delay;
5289 int k1 = (step_factor ? k / step_factor + 1 : k);
5290 int k2 = (part_opening ? k1 + start_step : num_steps[nr] - k1);
5291 int kk = MAX(0, k2);
5294 int src_x, src_y, src_xx, src_yy;
5295 int dst_x, dst_y, dst_xx, dst_yy;
5298 if (door_part_skip[nr])
5301 if (!(door_state & door_token))
5309 int k2_door = (door_opening ? k : num_move_steps_doors_only - k - 1);
5310 int kk_door = MAX(0, k2_door);
5311 int sync_frame = kk_door * door_delay_value;
5312 int frame = getGraphicAnimationFrame(dpc->graphic, sync_frame);
5314 getFixedGraphicSource(dpc->graphic, frame, &bitmap,
5315 &g_src_x, &g_src_y);
5320 if (!door_panel_drawn[door_index])
5322 ClearRectangle(drawto, door_rect->x, door_rect->y,
5323 door_rect->width, door_rect->height);
5325 door_panel_drawn[door_index] = TRUE;
5328 // draw opening or closing door parts
5330 if (pos->step_xoffset < 0) // door part on right side
5333 dst_xx = pos->x + ABS(kk * pos->step_xoffset);
5336 if (dst_xx + width > door_rect->width)
5337 width = door_rect->width - dst_xx;
5339 else // door part on left side
5342 dst_xx = pos->x - kk * pos->step_xoffset;
5346 src_xx = ABS(dst_xx);
5350 width = g->width - src_xx;
5352 if (width > door_rect->width)
5353 width = door_rect->width;
5355 // Debug("tools:MoveDoor", "k == %d [%d]", k, start_step);
5358 if (pos->step_yoffset < 0) // door part on bottom side
5361 dst_yy = pos->y + ABS(kk * pos->step_yoffset);
5364 if (dst_yy + height > door_rect->height)
5365 height = door_rect->height - dst_yy;
5367 else // door part on top side
5370 dst_yy = pos->y - kk * pos->step_yoffset;
5374 src_yy = ABS(dst_yy);
5378 height = g->height - src_yy;
5381 src_x = g_src_x + src_xx;
5382 src_y = g_src_y + src_yy;
5384 dst_x = door_rect->x + dst_xx;
5385 dst_y = door_rect->y + dst_yy;
5387 is_panel_and_door_has_closed =
5390 panel_has_doors[door_index] &&
5391 k >= num_move_steps_doors_only - 1);
5393 if (width >= 0 && width <= g->width &&
5394 height >= 0 && height <= g->height &&
5395 !is_panel_and_door_has_closed)
5397 if (is_panel || !pos->draw_masked)
5398 BlitBitmap(bitmap, drawto, src_x, src_y, width, height,
5401 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height,
5405 redraw_mask |= REDRAW_DOOR_FROM_TOKEN(door_token);
5407 if ((part_opening && (width < 0 || height < 0)) ||
5408 (part_closing && (width >= g->width && height >= g->height)))
5409 door_part_done[nr] = TRUE;
5411 // continue door part animations, but not panel after door has closed
5412 if (!door_part_done[nr] && !is_panel_and_door_has_closed)
5413 door_part_done_all = FALSE;
5416 if (!(door_state & DOOR_NO_DELAY))
5420 SkipUntilDelayReached(&door_delay, door_delay_value, &k, last_frame);
5422 current_move_delay += max_step_delay;
5424 // prevent OS (Windows) from complaining about program not responding
5428 if (door_part_done_all)
5432 if (!(door_state & DOOR_NO_DELAY))
5434 // wait for specified door action post delay
5435 if (door_state & DOOR_ACTION_1 && door_state & DOOR_ACTION_2)
5436 door_delay_value = MAX(door_1.post_delay, door_2.post_delay);
5437 else if (door_state & DOOR_ACTION_1)
5438 door_delay_value = door_1.post_delay;
5439 else if (door_state & DOOR_ACTION_2)
5440 door_delay_value = door_2.post_delay;
5442 while (!DelayReached(&door_delay, door_delay_value))
5447 if (door_state & DOOR_ACTION_1)
5448 door1 = door_state & DOOR_ACTION_1;
5449 if (door_state & DOOR_ACTION_2)
5450 door2 = door_state & DOOR_ACTION_2;
5452 // draw masked border over door area
5453 DrawMaskedBorder(REDRAW_DOOR_1);
5454 DrawMaskedBorder(REDRAW_DOOR_2);
5456 ClearAutoRepeatKeyEvents();
5458 return (door1 | door2);
5461 static boolean useSpecialEditorDoor(void)
5463 int graphic = IMG_GLOBAL_BORDER_EDITOR;
5464 boolean redefined = getImageListEntryFromImageID(graphic)->redefined;
5466 // do not draw special editor door if editor border defined or redefined
5467 if (graphic_info[graphic].bitmap != NULL || redefined)
5470 // do not draw special editor door if global border defined to be empty
5471 if (graphic_info[IMG_GLOBAL_BORDER].bitmap == NULL)
5474 // do not draw special editor door if viewport definitions do not match
5478 EY + EYSIZE != VY + VYSIZE)
5484 void DrawSpecialEditorDoor(void)
5486 struct GraphicInfo *gfx1 = &graphic_info[IMG_DOOR_2_TOP_BORDER_CORRECTION];
5487 int top_border_width = gfx1->width;
5488 int top_border_height = gfx1->height;
5489 int outer_border = viewport.door_2[GAME_MODE_EDITOR].border_size;
5490 int ex = EX - outer_border;
5491 int ey = EY - outer_border;
5492 int vy = VY - outer_border;
5493 int exsize = EXSIZE + 2 * outer_border;
5495 if (!useSpecialEditorDoor())
5498 // draw bigger level editor toolbox window
5499 BlitBitmap(gfx1->bitmap, drawto, gfx1->src_x, gfx1->src_y,
5500 top_border_width, top_border_height, ex, ey - top_border_height);
5501 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, drawto, ex, vy,
5502 exsize, EYSIZE - VYSIZE + outer_border, ex, ey);
5504 redraw_mask |= REDRAW_ALL;
5507 void UndrawSpecialEditorDoor(void)
5509 struct GraphicInfo *gfx1 = &graphic_info[IMG_DOOR_2_TOP_BORDER_CORRECTION];
5510 int top_border_width = gfx1->width;
5511 int top_border_height = gfx1->height;
5512 int outer_border = viewport.door_2[GAME_MODE_EDITOR].border_size;
5513 int ex = EX - outer_border;
5514 int ey = EY - outer_border;
5515 int ey_top = ey - top_border_height;
5516 int exsize = EXSIZE + 2 * outer_border;
5517 int eysize = EYSIZE + 2 * outer_border;
5519 if (!useSpecialEditorDoor())
5522 // draw normal tape recorder window
5523 if (graphic_info[IMG_GLOBAL_BORDER].bitmap)
5525 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, drawto,
5526 ex, ey_top, top_border_width, top_border_height,
5528 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, drawto,
5529 ex, ey, exsize, eysize, ex, ey);
5533 // if screen background is set to "[NONE]", clear editor toolbox window
5534 ClearRectangle(drawto, ex, ey_top, top_border_width, top_border_height);
5535 ClearRectangle(drawto, ex, ey, exsize, eysize);
5538 redraw_mask |= REDRAW_ALL;
5542 // ---------- new tool button stuff -------------------------------------------
5547 struct TextPosInfo *pos;
5549 boolean is_touch_button;
5551 } toolbutton_info[NUM_TOOL_BUTTONS] =
5554 IMG_GFX_REQUEST_BUTTON_YES, &request.button.yes,
5555 TOOL_CTRL_ID_YES, FALSE, "yes"
5558 IMG_GFX_REQUEST_BUTTON_NO, &request.button.no,
5559 TOOL_CTRL_ID_NO, FALSE, "no"
5562 IMG_GFX_REQUEST_BUTTON_CONFIRM, &request.button.confirm,
5563 TOOL_CTRL_ID_CONFIRM, FALSE, "confirm"
5566 IMG_GFX_REQUEST_BUTTON_PLAYER_1, &request.button.player_1,
5567 TOOL_CTRL_ID_PLAYER_1, FALSE, "player 1"
5570 IMG_GFX_REQUEST_BUTTON_PLAYER_2, &request.button.player_2,
5571 TOOL_CTRL_ID_PLAYER_2, FALSE, "player 2"
5574 IMG_GFX_REQUEST_BUTTON_PLAYER_3, &request.button.player_3,
5575 TOOL_CTRL_ID_PLAYER_3, FALSE, "player 3"
5578 IMG_GFX_REQUEST_BUTTON_PLAYER_4, &request.button.player_4,
5579 TOOL_CTRL_ID_PLAYER_4, FALSE, "player 4"
5582 IMG_GFX_REQUEST_BUTTON_TOUCH_YES, &request.button.touch_yes,
5583 TOOL_CTRL_ID_TOUCH_YES, TRUE, "yes"
5586 IMG_GFX_REQUEST_BUTTON_TOUCH_NO, &request.button.touch_no,
5587 TOOL_CTRL_ID_TOUCH_NO, TRUE, "no"
5590 IMG_GFX_REQUEST_BUTTON_TOUCH_CONFIRM, &request.button.touch_confirm,
5591 TOOL_CTRL_ID_TOUCH_CONFIRM, TRUE, "confirm"
5595 void CreateToolButtons(void)
5599 for (i = 0; i < NUM_TOOL_BUTTONS; i++)
5601 int graphic = toolbutton_info[i].graphic;
5602 struct GraphicInfo *gfx = &graphic_info[graphic];
5603 struct TextPosInfo *pos = toolbutton_info[i].pos;
5604 struct GadgetInfo *gi;
5605 Bitmap *deco_bitmap = None;
5606 int deco_x = 0, deco_y = 0, deco_xpos = 0, deco_ypos = 0;
5607 unsigned int event_mask = GD_EVENT_RELEASED;
5608 boolean is_touch_button = toolbutton_info[i].is_touch_button;
5609 int base_x = (is_touch_button ? 0 : DX);
5610 int base_y = (is_touch_button ? 0 : DY);
5611 int gd_x = gfx->src_x;
5612 int gd_y = gfx->src_y;
5613 int gd_xp = gfx->src_x + gfx->pressed_xoffset;
5614 int gd_yp = gfx->src_y + gfx->pressed_yoffset;
5619 if (global.use_envelope_request && !is_touch_button)
5621 setRequestPosition(&base_x, &base_y, TRUE);
5623 // check if request buttons are outside of envelope and fix, if needed
5624 if (x < 0 || x + gfx->width > request.width ||
5625 y < 0 || y + gfx->height > request.height)
5627 if (id == TOOL_CTRL_ID_YES)
5630 y = request.height - 2 * request.border_size - gfx->height;
5632 else if (id == TOOL_CTRL_ID_NO)
5634 x = request.width - 2 * request.border_size - gfx->width;
5635 y = request.height - 2 * request.border_size - gfx->height;
5637 else if (id == TOOL_CTRL_ID_CONFIRM)
5639 x = (request.width - 2 * request.border_size - gfx->width) / 2;
5640 y = request.height - 2 * request.border_size - gfx->height;
5642 else if (id >= TOOL_CTRL_ID_PLAYER_1 && id <= TOOL_CTRL_ID_PLAYER_4)
5644 int player_nr = id - TOOL_CTRL_ID_PLAYER_1;
5646 x = (request.width - 2 * request.border_size - gfx->width) / 2;
5647 y = request.height - 2 * request.border_size - gfx->height * 2;
5649 x += (player_nr == 3 ? -1 : player_nr == 1 ? +1 : 0) * gfx->width;
5650 y += (player_nr == 0 ? -1 : player_nr == 2 ? +1 : 0) * gfx->height;
5655 if (id >= TOOL_CTRL_ID_PLAYER_1 && id <= TOOL_CTRL_ID_PLAYER_4)
5657 int player_nr = id - TOOL_CTRL_ID_PLAYER_1;
5659 getSizedGraphicSource(PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0,
5660 pos->size, &deco_bitmap, &deco_x, &deco_y);
5661 deco_xpos = (gfx->width - pos->size) / 2;
5662 deco_ypos = (gfx->height - pos->size) / 2;
5665 gi = CreateGadget(GDI_CUSTOM_ID, id,
5666 GDI_IMAGE_ID, graphic,
5667 GDI_INFO_TEXT, toolbutton_info[i].infotext,
5670 GDI_WIDTH, gfx->width,
5671 GDI_HEIGHT, gfx->height,
5672 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5673 GDI_STATE, GD_BUTTON_UNPRESSED,
5674 GDI_DESIGN_UNPRESSED, gfx->bitmap, gd_x, gd_y,
5675 GDI_DESIGN_PRESSED, gfx->bitmap, gd_xp, gd_yp,
5676 GDI_DECORATION_DESIGN, deco_bitmap, deco_x, deco_y,
5677 GDI_DECORATION_POSITION, deco_xpos, deco_ypos,
5678 GDI_DECORATION_SIZE, pos->size, pos->size,
5679 GDI_DECORATION_SHIFTING, 1, 1,
5680 GDI_DIRECT_DRAW, FALSE,
5681 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
5682 GDI_EVENT_MASK, event_mask,
5683 GDI_CALLBACK_ACTION, HandleToolButtons,
5687 Fail("cannot create gadget");
5689 tool_gadget[id] = gi;
5693 void FreeToolButtons(void)
5697 for (i = 0; i < NUM_TOOL_BUTTONS; i++)
5698 FreeGadget(tool_gadget[i]);
5701 static void UnmapToolButtons(void)
5705 for (i = 0; i < NUM_TOOL_BUTTONS; i++)
5706 UnmapGadget(tool_gadget[i]);
5709 static void HandleToolButtons(struct GadgetInfo *gi)
5711 request_gadget_id = gi->custom_id;
5714 static struct Mapping_EM_to_RND_object
5717 boolean is_rnd_to_em_mapping; // unique mapping EM <-> RND
5718 boolean is_backside; // backside of moving element
5724 em_object_mapping_list[GAME_TILE_MAX + 1] =
5727 Zborder, FALSE, FALSE,
5731 Zplayer, FALSE, FALSE,
5740 Ztank, FALSE, FALSE,
5744 Zeater, FALSE, FALSE,
5748 Zdynamite, FALSE, FALSE,
5752 Zboom, FALSE, FALSE,
5757 Xchain, FALSE, FALSE,
5758 EL_DEFAULT, ACTION_EXPLODING, -1
5761 Xboom_bug, FALSE, FALSE,
5762 EL_BUG, ACTION_EXPLODING, -1
5765 Xboom_tank, FALSE, FALSE,
5766 EL_SPACESHIP, ACTION_EXPLODING, -1
5769 Xboom_android, FALSE, FALSE,
5770 EL_EMC_ANDROID, ACTION_OTHER, -1
5773 Xboom_1, FALSE, FALSE,
5774 EL_DEFAULT, ACTION_EXPLODING, -1
5777 Xboom_2, FALSE, FALSE,
5778 EL_DEFAULT, ACTION_EXPLODING, -1
5782 Xblank, TRUE, FALSE,
5787 Xsplash_e, FALSE, FALSE,
5788 EL_ACID_SPLASH_RIGHT, -1, -1
5791 Xsplash_w, FALSE, FALSE,
5792 EL_ACID_SPLASH_LEFT, -1, -1
5796 Xplant, TRUE, FALSE,
5797 EL_EMC_PLANT, -1, -1
5800 Yplant, FALSE, FALSE,
5801 EL_EMC_PLANT, -1, -1
5805 Xacid_1, TRUE, FALSE,
5809 Xacid_2, FALSE, FALSE,
5813 Xacid_3, FALSE, FALSE,
5817 Xacid_4, FALSE, FALSE,
5821 Xacid_5, FALSE, FALSE,
5825 Xacid_6, FALSE, FALSE,
5829 Xacid_7, FALSE, FALSE,
5833 Xacid_8, FALSE, FALSE,
5838 Xfake_acid_1, TRUE, FALSE,
5839 EL_EMC_FAKE_ACID, -1, -1
5842 Xfake_acid_2, FALSE, FALSE,
5843 EL_EMC_FAKE_ACID, -1, -1
5846 Xfake_acid_3, FALSE, FALSE,
5847 EL_EMC_FAKE_ACID, -1, -1
5850 Xfake_acid_4, FALSE, FALSE,
5851 EL_EMC_FAKE_ACID, -1, -1
5854 Xfake_acid_5, FALSE, FALSE,
5855 EL_EMC_FAKE_ACID, -1, -1
5858 Xfake_acid_6, FALSE, FALSE,
5859 EL_EMC_FAKE_ACID, -1, -1
5862 Xfake_acid_7, FALSE, FALSE,
5863 EL_EMC_FAKE_ACID, -1, -1
5866 Xfake_acid_8, FALSE, FALSE,
5867 EL_EMC_FAKE_ACID, -1, -1
5871 Xgrass, TRUE, FALSE,
5872 EL_EMC_GRASS, -1, -1
5875 Ygrass_nB, FALSE, FALSE,
5876 EL_EMC_GRASS, ACTION_DIGGING, MV_BIT_UP
5879 Ygrass_eB, FALSE, FALSE,
5880 EL_EMC_GRASS, ACTION_DIGGING, MV_BIT_RIGHT
5883 Ygrass_sB, FALSE, FALSE,
5884 EL_EMC_GRASS, ACTION_DIGGING, MV_BIT_DOWN
5887 Ygrass_wB, FALSE, FALSE,
5888 EL_EMC_GRASS, ACTION_DIGGING, MV_BIT_LEFT
5896 Ydirt_nB, FALSE, FALSE,
5897 EL_SAND, ACTION_DIGGING, MV_BIT_UP
5900 Ydirt_eB, FALSE, FALSE,
5901 EL_SAND, ACTION_DIGGING, MV_BIT_RIGHT
5904 Ydirt_sB, FALSE, FALSE,
5905 EL_SAND, ACTION_DIGGING, MV_BIT_DOWN
5908 Ydirt_wB, FALSE, FALSE,
5909 EL_SAND, ACTION_DIGGING, MV_BIT_LEFT
5913 Xandroid, TRUE, FALSE,
5914 EL_EMC_ANDROID, ACTION_ACTIVE, -1
5917 Xandroid_1_n, FALSE, FALSE,
5918 EL_EMC_ANDROID, ACTION_ACTIVE, MV_BIT_UP
5921 Xandroid_2_n, FALSE, FALSE,
5922 EL_EMC_ANDROID, ACTION_ACTIVE, MV_BIT_UP
5925 Xandroid_1_e, FALSE, FALSE,
5926 EL_EMC_ANDROID, ACTION_ACTIVE, MV_BIT_RIGHT
5929 Xandroid_2_e, FALSE, FALSE,
5930 EL_EMC_ANDROID, ACTION_ACTIVE, MV_BIT_RIGHT
5933 Xandroid_1_w, FALSE, FALSE,
5934 EL_EMC_ANDROID, ACTION_ACTIVE, MV_BIT_LEFT
5937 Xandroid_2_w, FALSE, FALSE,
5938 EL_EMC_ANDROID, ACTION_ACTIVE, MV_BIT_LEFT
5941 Xandroid_1_s, FALSE, FALSE,
5942 EL_EMC_ANDROID, ACTION_ACTIVE, MV_BIT_DOWN
5945 Xandroid_2_s, FALSE, FALSE,
5946 EL_EMC_ANDROID, ACTION_ACTIVE, MV_BIT_DOWN
5949 Yandroid_n, FALSE, FALSE,
5950 EL_EMC_ANDROID, ACTION_MOVING, MV_BIT_UP
5953 Yandroid_nB, FALSE, TRUE,
5954 EL_EMC_ANDROID, ACTION_MOVING, MV_BIT_UP
5957 Yandroid_ne, FALSE, FALSE,
5958 EL_EMC_ANDROID, ACTION_GROWING, MV_BIT_UPRIGHT
5961 Yandroid_neB, FALSE, TRUE,
5962 EL_EMC_ANDROID, ACTION_SHRINKING, MV_BIT_UPRIGHT
5965 Yandroid_e, FALSE, FALSE,
5966 EL_EMC_ANDROID, ACTION_MOVING, MV_BIT_RIGHT
5969 Yandroid_eB, FALSE, TRUE,
5970 EL_EMC_ANDROID, ACTION_MOVING, MV_BIT_RIGHT
5973 Yandroid_se, FALSE, FALSE,
5974 EL_EMC_ANDROID, ACTION_GROWING, MV_BIT_DOWNRIGHT
5977 Yandroid_seB, FALSE, TRUE,
5978 EL_EMC_ANDROID, ACTION_SHRINKING, MV_BIT_DOWNRIGHT
5981 Yandroid_s, FALSE, FALSE,
5982 EL_EMC_ANDROID, ACTION_MOVING, MV_BIT_DOWN
5985 Yandroid_sB, FALSE, TRUE,
5986 EL_EMC_ANDROID, ACTION_MOVING, MV_BIT_DOWN
5989 Yandroid_sw, FALSE, FALSE,
5990 EL_EMC_ANDROID, ACTION_GROWING, MV_BIT_DOWNLEFT
5993 Yandroid_swB, FALSE, TRUE,
5994 EL_EMC_ANDROID, ACTION_SHRINKING, MV_BIT_DOWNLEFT
5997 Yandroid_w, FALSE, FALSE,
5998 EL_EMC_ANDROID, ACTION_MOVING, MV_BIT_LEFT
6001 Yandroid_wB, FALSE, TRUE,
6002 EL_EMC_ANDROID, ACTION_MOVING, MV_BIT_LEFT
6005 Yandroid_nw, FALSE, FALSE,
6006 EL_EMC_ANDROID, ACTION_GROWING, MV_BIT_UPLEFT
6009 Yandroid_nwB, FALSE, TRUE,
6010 EL_EMC_ANDROID, ACTION_SHRINKING, MV_BIT_UPLEFT
6014 Xeater_n, TRUE, FALSE,
6015 EL_YAMYAM_UP, -1, -1
6018 Xeater_e, TRUE, FALSE,
6019 EL_YAMYAM_RIGHT, -1, -1
6022 Xeater_w, TRUE, FALSE,
6023 EL_YAMYAM_LEFT, -1, -1
6026 Xeater_s, TRUE, FALSE,
6027 EL_YAMYAM_DOWN, -1, -1
6030 Yeater_n, FALSE, FALSE,
6031 EL_YAMYAM, ACTION_MOVING, MV_BIT_UP
6034 Yeater_nB, FALSE, TRUE,
6035 EL_YAMYAM, ACTION_MOVING, MV_BIT_UP
6038 Yeater_e, FALSE, FALSE,
6039 EL_YAMYAM, ACTION_MOVING, MV_BIT_RIGHT
6042 Yeater_eB, FALSE, TRUE,
6043 EL_YAMYAM, ACTION_MOVING, MV_BIT_RIGHT
6046 Yeater_s, FALSE, FALSE,
6047 EL_YAMYAM, ACTION_MOVING, MV_BIT_DOWN
6050 Yeater_sB, FALSE, TRUE,
6051 EL_YAMYAM, ACTION_MOVING, MV_BIT_DOWN
6054 Yeater_w, FALSE, FALSE,
6055 EL_YAMYAM, ACTION_MOVING, MV_BIT_LEFT
6058 Yeater_wB, FALSE, TRUE,
6059 EL_YAMYAM, ACTION_MOVING, MV_BIT_LEFT
6062 Yeater_stone, FALSE, FALSE,
6063 EL_YAMYAM, ACTION_SMASHED_BY_ROCK, -1
6066 Yeater_spring, FALSE, FALSE,
6067 EL_YAMYAM, ACTION_SMASHED_BY_SPRING, -1
6071 Xalien, TRUE, FALSE,
6075 Xalien_pause, FALSE, FALSE,
6079 Yalien_n, FALSE, FALSE,
6080 EL_ROBOT, ACTION_MOVING, MV_BIT_UP
6083 Yalien_nB, FALSE, TRUE,
6084 EL_ROBOT, ACTION_MOVING, MV_BIT_UP
6087 Yalien_e, FALSE, FALSE,
6088 EL_ROBOT, ACTION_MOVING, MV_BIT_RIGHT
6091 Yalien_eB, FALSE, TRUE,
6092 EL_ROBOT, ACTION_MOVING, MV_BIT_RIGHT
6095 Yalien_s, FALSE, FALSE,
6096 EL_ROBOT, ACTION_MOVING, MV_BIT_DOWN
6099 Yalien_sB, FALSE, TRUE,
6100 EL_ROBOT, ACTION_MOVING, MV_BIT_DOWN
6103 Yalien_w, FALSE, FALSE,
6104 EL_ROBOT, ACTION_MOVING, MV_BIT_LEFT
6107 Yalien_wB, FALSE, TRUE,
6108 EL_ROBOT, ACTION_MOVING, MV_BIT_LEFT
6111 Yalien_stone, FALSE, FALSE,
6112 EL_ROBOT, ACTION_SMASHED_BY_ROCK, -1
6115 Yalien_spring, FALSE, FALSE,
6116 EL_ROBOT, ACTION_SMASHED_BY_SPRING, -1
6120 Xbug_1_n, TRUE, FALSE,
6124 Xbug_1_e, TRUE, FALSE,
6125 EL_BUG_RIGHT, -1, -1
6128 Xbug_1_s, TRUE, FALSE,
6132 Xbug_1_w, TRUE, FALSE,
6136 Xbug_2_n, FALSE, FALSE,
6140 Xbug_2_e, FALSE, FALSE,
6141 EL_BUG_RIGHT, -1, -1
6144 Xbug_2_s, FALSE, FALSE,
6148 Xbug_2_w, FALSE, FALSE,
6152 Ybug_n, FALSE, FALSE,
6153 EL_BUG, ACTION_MOVING, MV_BIT_UP
6156 Ybug_nB, FALSE, TRUE,
6157 EL_BUG, ACTION_MOVING, MV_BIT_UP
6160 Ybug_e, FALSE, FALSE,
6161 EL_BUG, ACTION_MOVING, MV_BIT_RIGHT
6164 Ybug_eB, FALSE, TRUE,
6165 EL_BUG, ACTION_MOVING, MV_BIT_RIGHT
6168 Ybug_s, FALSE, FALSE,
6169 EL_BUG, ACTION_MOVING, MV_BIT_DOWN
6172 Ybug_sB, FALSE, TRUE,
6173 EL_BUG, ACTION_MOVING, MV_BIT_DOWN
6176 Ybug_w, FALSE, FALSE,
6177 EL_BUG, ACTION_MOVING, MV_BIT_LEFT
6180 Ybug_wB, FALSE, TRUE,
6181 EL_BUG, ACTION_MOVING, MV_BIT_LEFT
6184 Ybug_w_n, FALSE, FALSE,
6185 EL_BUG, ACTION_TURNING_FROM_LEFT, MV_BIT_UP
6188 Ybug_n_e, FALSE, FALSE,
6189 EL_BUG, ACTION_TURNING_FROM_UP, MV_BIT_RIGHT
6192 Ybug_e_s, FALSE, FALSE,
6193 EL_BUG, ACTION_TURNING_FROM_RIGHT, MV_BIT_DOWN
6196 Ybug_s_w, FALSE, FALSE,
6197 EL_BUG, ACTION_TURNING_FROM_DOWN, MV_BIT_LEFT
6200 Ybug_e_n, FALSE, FALSE,
6201 EL_BUG, ACTION_TURNING_FROM_RIGHT, MV_BIT_UP
6204 Ybug_s_e, FALSE, FALSE,
6205 EL_BUG, ACTION_TURNING_FROM_DOWN, MV_BIT_RIGHT
6208 Ybug_w_s, FALSE, FALSE,
6209 EL_BUG, ACTION_TURNING_FROM_LEFT, MV_BIT_DOWN
6212 Ybug_n_w, FALSE, FALSE,
6213 EL_BUG, ACTION_TURNING_FROM_UP, MV_BIT_LEFT
6216 Ybug_stone, FALSE, FALSE,
6217 EL_BUG, ACTION_SMASHED_BY_ROCK, -1
6220 Ybug_spring, FALSE, FALSE,
6221 EL_BUG, ACTION_SMASHED_BY_SPRING, -1
6225 Xtank_1_n, TRUE, FALSE,
6226 EL_SPACESHIP_UP, -1, -1
6229 Xtank_1_e, TRUE, FALSE,
6230 EL_SPACESHIP_RIGHT, -1, -1
6233 Xtank_1_s, TRUE, FALSE,
6234 EL_SPACESHIP_DOWN, -1, -1
6237 Xtank_1_w, TRUE, FALSE,
6238 EL_SPACESHIP_LEFT, -1, -1
6241 Xtank_2_n, FALSE, FALSE,
6242 EL_SPACESHIP_UP, -1, -1
6245 Xtank_2_e, FALSE, FALSE,
6246 EL_SPACESHIP_RIGHT, -1, -1
6249 Xtank_2_s, FALSE, FALSE,
6250 EL_SPACESHIP_DOWN, -1, -1
6253 Xtank_2_w, FALSE, FALSE,
6254 EL_SPACESHIP_LEFT, -1, -1
6257 Ytank_n, FALSE, FALSE,
6258 EL_SPACESHIP, ACTION_MOVING, MV_BIT_UP
6261 Ytank_nB, FALSE, TRUE,
6262 EL_SPACESHIP, ACTION_MOVING, MV_BIT_UP
6265 Ytank_e, FALSE, FALSE,
6266 EL_SPACESHIP, ACTION_MOVING, MV_BIT_RIGHT
6269 Ytank_eB, FALSE, TRUE,
6270 EL_SPACESHIP, ACTION_MOVING, MV_BIT_RIGHT
6273 Ytank_s, FALSE, FALSE,
6274 EL_SPACESHIP, ACTION_MOVING, MV_BIT_DOWN
6277 Ytank_sB, FALSE, TRUE,
6278 EL_SPACESHIP, ACTION_MOVING, MV_BIT_DOWN
6281 Ytank_w, FALSE, FALSE,
6282 EL_SPACESHIP, ACTION_MOVING, MV_BIT_LEFT
6285 Ytank_wB, FALSE, TRUE,
6286 EL_SPACESHIP, ACTION_MOVING, MV_BIT_LEFT
6289 Ytank_w_n, FALSE, FALSE,
6290 EL_SPACESHIP, ACTION_TURNING_FROM_LEFT, MV_BIT_UP
6293 Ytank_n_e, FALSE, FALSE,
6294 EL_SPACESHIP, ACTION_TURNING_FROM_UP, MV_BIT_RIGHT
6297 Ytank_e_s, FALSE, FALSE,
6298 EL_SPACESHIP, ACTION_TURNING_FROM_RIGHT, MV_BIT_DOWN
6301 Ytank_s_w, FALSE, FALSE,
6302 EL_SPACESHIP, ACTION_TURNING_FROM_DOWN, MV_BIT_LEFT
6305 Ytank_e_n, FALSE, FALSE,
6306 EL_SPACESHIP, ACTION_TURNING_FROM_RIGHT, MV_BIT_UP
6309 Ytank_s_e, FALSE, FALSE,
6310 EL_SPACESHIP, ACTION_TURNING_FROM_DOWN, MV_BIT_RIGHT
6313 Ytank_w_s, FALSE, FALSE,
6314 EL_SPACESHIP, ACTION_TURNING_FROM_LEFT, MV_BIT_DOWN
6317 Ytank_n_w, FALSE, FALSE,
6318 EL_SPACESHIP, ACTION_TURNING_FROM_UP, MV_BIT_LEFT
6321 Ytank_stone, FALSE, FALSE,
6322 EL_SPACESHIP, ACTION_SMASHED_BY_ROCK, -1
6325 Ytank_spring, FALSE, FALSE,
6326 EL_SPACESHIP, ACTION_SMASHED_BY_SPRING, -1
6330 Xemerald, TRUE, FALSE,
6334 Xemerald_pause, FALSE, FALSE,
6338 Xemerald_fall, FALSE, FALSE,
6342 Xemerald_shine, FALSE, FALSE,
6343 EL_EMERALD, ACTION_TWINKLING, -1
6346 Yemerald_s, FALSE, FALSE,
6347 EL_EMERALD, ACTION_FALLING, -1
6350 Yemerald_sB, FALSE, TRUE,
6351 EL_EMERALD, ACTION_FALLING, -1
6354 Yemerald_e, FALSE, FALSE,
6355 EL_EMERALD, ACTION_MOVING, MV_BIT_RIGHT
6358 Yemerald_eB, FALSE, TRUE,
6359 EL_EMERALD, ACTION_MOVING, MV_BIT_RIGHT
6362 Yemerald_w, FALSE, FALSE,
6363 EL_EMERALD, ACTION_MOVING, MV_BIT_LEFT
6366 Yemerald_wB, FALSE, TRUE,
6367 EL_EMERALD, ACTION_MOVING, MV_BIT_LEFT
6370 Yemerald_blank, FALSE, FALSE,
6371 EL_EMERALD, ACTION_COLLECTING, -1
6375 Xdiamond, TRUE, FALSE,
6379 Xdiamond_pause, FALSE, FALSE,
6383 Xdiamond_fall, FALSE, FALSE,
6387 Xdiamond_shine, FALSE, FALSE,
6388 EL_DIAMOND, ACTION_TWINKLING, -1
6391 Ydiamond_s, FALSE, FALSE,
6392 EL_DIAMOND, ACTION_FALLING, -1
6395 Ydiamond_sB, FALSE, TRUE,
6396 EL_DIAMOND, ACTION_FALLING, -1
6399 Ydiamond_e, FALSE, FALSE,
6400 EL_DIAMOND, ACTION_MOVING, MV_BIT_RIGHT
6403 Ydiamond_eB, FALSE, TRUE,
6404 EL_DIAMOND, ACTION_MOVING, MV_BIT_RIGHT
6407 Ydiamond_w, FALSE, FALSE,
6408 EL_DIAMOND, ACTION_MOVING, MV_BIT_LEFT
6411 Ydiamond_wB, FALSE, TRUE,
6412 EL_DIAMOND, ACTION_MOVING, MV_BIT_LEFT
6415 Ydiamond_blank, FALSE, FALSE,
6416 EL_DIAMOND, ACTION_COLLECTING, -1
6419 Ydiamond_stone, FALSE, FALSE,
6420 EL_DIAMOND, ACTION_SMASHED_BY_ROCK, -1
6424 Xstone, TRUE, FALSE,
6428 Xstone_pause, FALSE, FALSE,
6432 Xstone_fall, FALSE, FALSE,
6436 Ystone_s, FALSE, FALSE,
6437 EL_ROCK, ACTION_FALLING, -1
6440 Ystone_sB, FALSE, TRUE,
6441 EL_ROCK, ACTION_FALLING, -1
6444 Ystone_e, FALSE, FALSE,
6445 EL_ROCK, ACTION_MOVING, MV_BIT_RIGHT
6448 Ystone_eB, FALSE, TRUE,
6449 EL_ROCK, ACTION_MOVING, MV_BIT_RIGHT
6452 Ystone_w, FALSE, FALSE,
6453 EL_ROCK, ACTION_MOVING, MV_BIT_LEFT
6456 Ystone_wB, FALSE, TRUE,
6457 EL_ROCK, ACTION_MOVING, MV_BIT_LEFT
6465 Xbomb_pause, FALSE, FALSE,
6469 Xbomb_fall, FALSE, FALSE,
6473 Ybomb_s, FALSE, FALSE,
6474 EL_BOMB, ACTION_FALLING, -1
6477 Ybomb_sB, FALSE, TRUE,
6478 EL_BOMB, ACTION_FALLING, -1
6481 Ybomb_e, FALSE, FALSE,
6482 EL_BOMB, ACTION_MOVING, MV_BIT_RIGHT
6485 Ybomb_eB, FALSE, TRUE,
6486 EL_BOMB, ACTION_MOVING, MV_BIT_RIGHT
6489 Ybomb_w, FALSE, FALSE,
6490 EL_BOMB, ACTION_MOVING, MV_BIT_LEFT
6493 Ybomb_wB, FALSE, TRUE,
6494 EL_BOMB, ACTION_MOVING, MV_BIT_LEFT
6497 Ybomb_blank, FALSE, FALSE,
6498 EL_BOMB, ACTION_ACTIVATING, -1
6506 Xnut_pause, FALSE, FALSE,
6510 Xnut_fall, FALSE, FALSE,
6514 Ynut_s, FALSE, FALSE,
6515 EL_NUT, ACTION_FALLING, -1
6518 Ynut_sB, FALSE, TRUE,
6519 EL_NUT, ACTION_FALLING, -1
6522 Ynut_e, FALSE, FALSE,
6523 EL_NUT, ACTION_MOVING, MV_BIT_RIGHT
6526 Ynut_eB, FALSE, TRUE,
6527 EL_NUT, ACTION_MOVING, MV_BIT_RIGHT
6530 Ynut_w, FALSE, FALSE,
6531 EL_NUT, ACTION_MOVING, MV_BIT_LEFT
6534 Ynut_wB, FALSE, TRUE,
6535 EL_NUT, ACTION_MOVING, MV_BIT_LEFT
6538 Ynut_stone, FALSE, FALSE,
6539 EL_NUT, ACTION_BREAKING, -1
6543 Xspring, TRUE, FALSE,
6547 Xspring_pause, FALSE, FALSE,
6551 Xspring_e, TRUE, FALSE,
6552 EL_SPRING_RIGHT, -1, -1
6555 Xspring_w, TRUE, FALSE,
6556 EL_SPRING_LEFT, -1, -1
6559 Xspring_fall, FALSE, FALSE,
6563 Yspring_s, FALSE, FALSE,
6564 EL_SPRING, ACTION_FALLING, -1
6567 Yspring_sB, FALSE, TRUE,
6568 EL_SPRING, ACTION_FALLING, -1
6571 Yspring_e, FALSE, FALSE,
6572 EL_SPRING, ACTION_MOVING, MV_BIT_RIGHT
6575 Yspring_eB, FALSE, TRUE,
6576 EL_SPRING, ACTION_MOVING, MV_BIT_RIGHT
6579 Yspring_w, FALSE, FALSE,
6580 EL_SPRING, ACTION_MOVING, MV_BIT_LEFT
6583 Yspring_wB, FALSE, TRUE,
6584 EL_SPRING, ACTION_MOVING, MV_BIT_LEFT
6587 Yspring_alien_e, FALSE, FALSE,
6588 EL_SPRING, ACTION_EATING, MV_BIT_RIGHT
6591 Yspring_alien_eB, FALSE, TRUE,
6592 EL_SPRING, ACTION_EATING, MV_BIT_RIGHT
6595 Yspring_alien_w, FALSE, FALSE,
6596 EL_SPRING, ACTION_EATING, MV_BIT_LEFT
6599 Yspring_alien_wB, FALSE, TRUE,
6600 EL_SPRING, ACTION_EATING, MV_BIT_LEFT
6604 Xpush_emerald_e, FALSE, FALSE,
6605 EL_EMERALD, -1, MV_BIT_RIGHT
6608 Xpush_emerald_w, FALSE, FALSE,
6609 EL_EMERALD, -1, MV_BIT_LEFT
6612 Xpush_diamond_e, FALSE, FALSE,
6613 EL_DIAMOND, -1, MV_BIT_RIGHT
6616 Xpush_diamond_w, FALSE, FALSE,
6617 EL_DIAMOND, -1, MV_BIT_LEFT
6620 Xpush_stone_e, FALSE, FALSE,
6621 EL_ROCK, -1, MV_BIT_RIGHT
6624 Xpush_stone_w, FALSE, FALSE,
6625 EL_ROCK, -1, MV_BIT_LEFT
6628 Xpush_bomb_e, FALSE, FALSE,
6629 EL_BOMB, -1, MV_BIT_RIGHT
6632 Xpush_bomb_w, FALSE, FALSE,
6633 EL_BOMB, -1, MV_BIT_LEFT
6636 Xpush_nut_e, FALSE, FALSE,
6637 EL_NUT, -1, MV_BIT_RIGHT
6640 Xpush_nut_w, FALSE, FALSE,
6641 EL_NUT, -1, MV_BIT_LEFT
6644 Xpush_spring_e, FALSE, FALSE,
6645 EL_SPRING_RIGHT, -1, MV_BIT_RIGHT
6648 Xpush_spring_w, FALSE, FALSE,
6649 EL_SPRING_LEFT, -1, MV_BIT_LEFT
6653 Xdynamite, TRUE, FALSE,
6654 EL_EM_DYNAMITE, -1, -1
6657 Ydynamite_blank, FALSE, FALSE,
6658 EL_EM_DYNAMITE, ACTION_COLLECTING, -1
6661 Xdynamite_1, TRUE, FALSE,
6662 EL_EM_DYNAMITE_ACTIVE, -1, -1
6665 Xdynamite_2, FALSE, FALSE,
6666 EL_EM_DYNAMITE_ACTIVE, -1, -1
6669 Xdynamite_3, FALSE, FALSE,
6670 EL_EM_DYNAMITE_ACTIVE, -1, -1
6673 Xdynamite_4, FALSE, FALSE,
6674 EL_EM_DYNAMITE_ACTIVE, -1, -1
6678 Xkey_1, TRUE, FALSE,
6682 Xkey_2, TRUE, FALSE,
6686 Xkey_3, TRUE, FALSE,
6690 Xkey_4, TRUE, FALSE,
6694 Xkey_5, TRUE, FALSE,
6695 EL_EMC_KEY_5, -1, -1
6698 Xkey_6, TRUE, FALSE,
6699 EL_EMC_KEY_6, -1, -1
6702 Xkey_7, TRUE, FALSE,
6703 EL_EMC_KEY_7, -1, -1
6706 Xkey_8, TRUE, FALSE,
6707 EL_EMC_KEY_8, -1, -1
6711 Xdoor_1, TRUE, FALSE,
6712 EL_EM_GATE_1, -1, -1
6715 Xdoor_2, TRUE, FALSE,
6716 EL_EM_GATE_2, -1, -1
6719 Xdoor_3, TRUE, FALSE,
6720 EL_EM_GATE_3, -1, -1
6723 Xdoor_4, TRUE, FALSE,
6724 EL_EM_GATE_4, -1, -1
6727 Xdoor_5, TRUE, FALSE,
6728 EL_EMC_GATE_5, -1, -1
6731 Xdoor_6, TRUE, FALSE,
6732 EL_EMC_GATE_6, -1, -1
6735 Xdoor_7, TRUE, FALSE,
6736 EL_EMC_GATE_7, -1, -1
6739 Xdoor_8, TRUE, FALSE,
6740 EL_EMC_GATE_8, -1, -1
6744 Xfake_door_1, TRUE, FALSE,
6745 EL_EM_GATE_1_GRAY, -1, -1
6748 Xfake_door_2, TRUE, FALSE,
6749 EL_EM_GATE_2_GRAY, -1, -1
6752 Xfake_door_3, TRUE, FALSE,
6753 EL_EM_GATE_3_GRAY, -1, -1
6756 Xfake_door_4, TRUE, FALSE,
6757 EL_EM_GATE_4_GRAY, -1, -1
6760 Xfake_door_5, TRUE, FALSE,
6761 EL_EMC_GATE_5_GRAY, -1, -1
6764 Xfake_door_6, TRUE, FALSE,
6765 EL_EMC_GATE_6_GRAY, -1, -1
6768 Xfake_door_7, TRUE, FALSE,
6769 EL_EMC_GATE_7_GRAY, -1, -1
6772 Xfake_door_8, TRUE, FALSE,
6773 EL_EMC_GATE_8_GRAY, -1, -1
6777 Xballoon, TRUE, FALSE,
6781 Yballoon_n, FALSE, FALSE,
6782 EL_BALLOON, ACTION_MOVING, MV_BIT_UP
6785 Yballoon_nB, FALSE, TRUE,
6786 EL_BALLOON, ACTION_MOVING, MV_BIT_UP
6789 Yballoon_e, FALSE, FALSE,
6790 EL_BALLOON, ACTION_MOVING, MV_BIT_RIGHT
6793 Yballoon_eB, FALSE, TRUE,
6794 EL_BALLOON, ACTION_MOVING, MV_BIT_RIGHT
6797 Yballoon_s, FALSE, FALSE,
6798 EL_BALLOON, ACTION_MOVING, MV_BIT_DOWN
6801 Yballoon_sB, FALSE, TRUE,
6802 EL_BALLOON, ACTION_MOVING, MV_BIT_DOWN
6805 Yballoon_w, FALSE, FALSE,
6806 EL_BALLOON, ACTION_MOVING, MV_BIT_LEFT
6809 Yballoon_wB, FALSE, TRUE,
6810 EL_BALLOON, ACTION_MOVING, MV_BIT_LEFT
6814 Xball_1, TRUE, FALSE,
6815 EL_EMC_MAGIC_BALL, -1, -1
6818 Yball_1, FALSE, FALSE,
6819 EL_EMC_MAGIC_BALL, ACTION_ACTIVE, -1
6822 Xball_2, FALSE, FALSE,
6823 EL_EMC_MAGIC_BALL, ACTION_ACTIVE, -1
6826 Yball_2, FALSE, FALSE,
6827 EL_EMC_MAGIC_BALL, ACTION_ACTIVE, -1
6830 Yball_blank, FALSE, FALSE,
6831 EL_EMC_MAGIC_BALL, ACTION_DROPPING, -1
6835 Xamoeba_1, TRUE, FALSE,
6836 EL_AMOEBA_DRY, ACTION_OTHER, -1
6839 Xamoeba_2, FALSE, FALSE,
6840 EL_AMOEBA_DRY, ACTION_OTHER, -1
6843 Xamoeba_3, FALSE, FALSE,
6844 EL_AMOEBA_DRY, ACTION_OTHER, -1
6847 Xamoeba_4, FALSE, FALSE,
6848 EL_AMOEBA_DRY, ACTION_OTHER, -1
6851 Xamoeba_5, TRUE, FALSE,
6852 EL_AMOEBA_WET, ACTION_OTHER, -1
6855 Xamoeba_6, FALSE, FALSE,
6856 EL_AMOEBA_WET, ACTION_OTHER, -1
6859 Xamoeba_7, FALSE, FALSE,
6860 EL_AMOEBA_WET, ACTION_OTHER, -1
6863 Xamoeba_8, FALSE, FALSE,
6864 EL_AMOEBA_WET, ACTION_OTHER, -1
6869 EL_AMOEBA_DROP, ACTION_GROWING, -1
6872 Xdrip_fall, FALSE, FALSE,
6873 EL_AMOEBA_DROP, -1, -1
6876 Xdrip_stretch, FALSE, FALSE,
6877 EL_AMOEBA_DROP, ACTION_FALLING, -1
6880 Xdrip_stretchB, FALSE, TRUE,
6881 EL_AMOEBA_DROP, ACTION_FALLING, -1
6884 Ydrip_1_s, FALSE, FALSE,
6885 EL_AMOEBA_DROP, ACTION_FALLING, -1
6888 Ydrip_1_sB, FALSE, TRUE,
6889 EL_AMOEBA_DROP, ACTION_FALLING, -1
6892 Ydrip_2_s, FALSE, FALSE,
6893 EL_AMOEBA_DROP, ACTION_FALLING, -1
6896 Ydrip_2_sB, FALSE, TRUE,
6897 EL_AMOEBA_DROP, ACTION_FALLING, -1
6901 Xwonderwall, TRUE, FALSE,
6902 EL_MAGIC_WALL, -1, -1
6905 Ywonderwall, FALSE, FALSE,
6906 EL_MAGIC_WALL, ACTION_ACTIVE, -1
6910 Xwheel, TRUE, FALSE,
6911 EL_ROBOT_WHEEL, -1, -1
6914 Ywheel, FALSE, FALSE,
6915 EL_ROBOT_WHEEL, ACTION_ACTIVE, -1
6919 Xswitch, TRUE, FALSE,
6920 EL_EMC_MAGIC_BALL_SWITCH, -1, -1
6923 Yswitch, FALSE, FALSE,
6924 EL_EMC_MAGIC_BALL_SWITCH, ACTION_ACTIVE, -1
6928 Xbumper, TRUE, FALSE,
6929 EL_EMC_SPRING_BUMPER, -1, -1
6932 Ybumper, FALSE, FALSE,
6933 EL_EMC_SPRING_BUMPER, ACTION_ACTIVE, -1
6937 Xacid_nw, TRUE, FALSE,
6938 EL_ACID_POOL_TOPLEFT, -1, -1
6941 Xacid_ne, TRUE, FALSE,
6942 EL_ACID_POOL_TOPRIGHT, -1, -1
6945 Xacid_sw, TRUE, FALSE,
6946 EL_ACID_POOL_BOTTOMLEFT, -1, -1
6949 Xacid_s, TRUE, FALSE,
6950 EL_ACID_POOL_BOTTOM, -1, -1
6953 Xacid_se, TRUE, FALSE,
6954 EL_ACID_POOL_BOTTOMRIGHT, -1, -1
6958 Xfake_blank, TRUE, FALSE,
6959 EL_INVISIBLE_WALL, -1, -1
6962 Yfake_blank, FALSE, FALSE,
6963 EL_INVISIBLE_WALL, ACTION_ACTIVE, -1
6967 Xfake_grass, TRUE, FALSE,
6968 EL_EMC_FAKE_GRASS, -1, -1
6971 Yfake_grass, FALSE, FALSE,
6972 EL_EMC_FAKE_GRASS, ACTION_ACTIVE, -1
6976 Xfake_amoeba, TRUE, FALSE,
6977 EL_EMC_DRIPPER, -1, -1
6980 Yfake_amoeba, FALSE, FALSE,
6981 EL_EMC_DRIPPER, ACTION_ACTIVE, -1
6985 Xlenses, TRUE, FALSE,
6986 EL_EMC_LENSES, -1, -1
6990 Xmagnify, TRUE, FALSE,
6991 EL_EMC_MAGNIFIER, -1, -1
6996 EL_QUICKSAND_EMPTY, -1, -1
6999 Xsand_stone, TRUE, FALSE,
7000 EL_QUICKSAND_FULL, -1, -1
7003 Xsand_stonein_1, FALSE, TRUE,
7004 EL_ROCK, ACTION_FILLING, -1
7007 Xsand_stonein_2, FALSE, TRUE,
7008 EL_ROCK, ACTION_FILLING, -1
7011 Xsand_stonein_3, FALSE, TRUE,
7012 EL_ROCK, ACTION_FILLING, -1
7015 Xsand_stonein_4, FALSE, TRUE,
7016 EL_ROCK, ACTION_FILLING, -1
7019 Xsand_sandstone_1, FALSE, FALSE,
7020 EL_QUICKSAND_FILLING, -1, -1
7023 Xsand_sandstone_2, FALSE, FALSE,
7024 EL_QUICKSAND_FILLING, -1, -1
7027 Xsand_sandstone_3, FALSE, FALSE,
7028 EL_QUICKSAND_FILLING, -1, -1
7031 Xsand_sandstone_4, FALSE, FALSE,
7032 EL_QUICKSAND_FILLING, -1, -1
7035 Xsand_stonesand_1, FALSE, FALSE,
7036 EL_QUICKSAND_EMPTYING, -1, -1
7039 Xsand_stonesand_2, FALSE, FALSE,
7040 EL_QUICKSAND_EMPTYING, -1, -1
7043 Xsand_stonesand_3, FALSE, FALSE,
7044 EL_QUICKSAND_EMPTYING, -1, -1
7047 Xsand_stonesand_4, FALSE, FALSE,
7048 EL_QUICKSAND_EMPTYING, -1, -1
7051 Xsand_stoneout_1, FALSE, FALSE,
7052 EL_ROCK, ACTION_EMPTYING, -1
7055 Xsand_stoneout_2, FALSE, FALSE,
7056 EL_ROCK, ACTION_EMPTYING, -1
7059 Xsand_stonesand_quickout_1, FALSE, FALSE,
7060 EL_QUICKSAND_EMPTYING, -1, -1
7063 Xsand_stonesand_quickout_2, FALSE, FALSE,
7064 EL_QUICKSAND_EMPTYING, -1, -1
7068 Xslide_ns, TRUE, FALSE,
7069 EL_EXPANDABLE_WALL_VERTICAL, -1, -1
7072 Yslide_ns_blank, FALSE, FALSE,
7073 EL_EXPANDABLE_WALL_VERTICAL, ACTION_GROWING, -1
7076 Xslide_ew, TRUE, FALSE,
7077 EL_EXPANDABLE_WALL_HORIZONTAL, -1, -1
7080 Yslide_ew_blank, FALSE, FALSE,
7081 EL_EXPANDABLE_WALL_HORIZONTAL, ACTION_GROWING, -1
7085 Xwind_n, TRUE, FALSE,
7086 EL_BALLOON_SWITCH_UP, -1, -1
7089 Xwind_e, TRUE, FALSE,
7090 EL_BALLOON_SWITCH_RIGHT, -1, -1
7093 Xwind_s, TRUE, FALSE,
7094 EL_BALLOON_SWITCH_DOWN, -1, -1
7097 Xwind_w, TRUE, FALSE,
7098 EL_BALLOON_SWITCH_LEFT, -1, -1
7101 Xwind_any, TRUE, FALSE,
7102 EL_BALLOON_SWITCH_ANY, -1, -1
7105 Xwind_stop, TRUE, FALSE,
7106 EL_BALLOON_SWITCH_NONE, -1, -1
7111 EL_EM_EXIT_CLOSED, -1, -1
7114 Xexit_1, TRUE, FALSE,
7115 EL_EM_EXIT_OPEN, -1, -1
7118 Xexit_2, FALSE, FALSE,
7119 EL_EM_EXIT_OPEN, -1, -1
7122 Xexit_3, FALSE, FALSE,
7123 EL_EM_EXIT_OPEN, -1, -1
7127 Xpause, FALSE, FALSE,
7132 Xwall_1, TRUE, FALSE,
7136 Xwall_2, TRUE, FALSE,
7137 EL_EMC_WALL_14, -1, -1
7140 Xwall_3, TRUE, FALSE,
7141 EL_EMC_WALL_15, -1, -1
7144 Xwall_4, TRUE, FALSE,
7145 EL_EMC_WALL_16, -1, -1
7149 Xroundwall_1, TRUE, FALSE,
7150 EL_WALL_SLIPPERY, -1, -1
7153 Xroundwall_2, TRUE, FALSE,
7154 EL_EMC_WALL_SLIPPERY_2, -1, -1
7157 Xroundwall_3, TRUE, FALSE,
7158 EL_EMC_WALL_SLIPPERY_3, -1, -1
7161 Xroundwall_4, TRUE, FALSE,
7162 EL_EMC_WALL_SLIPPERY_4, -1, -1
7166 Xsteel_1, TRUE, FALSE,
7167 EL_STEELWALL, -1, -1
7170 Xsteel_2, TRUE, FALSE,
7171 EL_EMC_STEELWALL_2, -1, -1
7174 Xsteel_3, TRUE, FALSE,
7175 EL_EMC_STEELWALL_3, -1, -1
7178 Xsteel_4, TRUE, FALSE,
7179 EL_EMC_STEELWALL_4, -1, -1
7183 Xdecor_1, TRUE, FALSE,
7184 EL_EMC_WALL_8, -1, -1
7187 Xdecor_2, TRUE, FALSE,
7188 EL_EMC_WALL_6, -1, -1
7191 Xdecor_3, TRUE, FALSE,
7192 EL_EMC_WALL_4, -1, -1
7195 Xdecor_4, TRUE, FALSE,
7196 EL_EMC_WALL_7, -1, -1
7199 Xdecor_5, TRUE, FALSE,
7200 EL_EMC_WALL_5, -1, -1
7203 Xdecor_6, TRUE, FALSE,
7204 EL_EMC_WALL_9, -1, -1
7207 Xdecor_7, TRUE, FALSE,
7208 EL_EMC_WALL_10, -1, -1
7211 Xdecor_8, TRUE, FALSE,
7212 EL_EMC_WALL_1, -1, -1
7215 Xdecor_9, TRUE, FALSE,
7216 EL_EMC_WALL_2, -1, -1
7219 Xdecor_10, TRUE, FALSE,
7220 EL_EMC_WALL_3, -1, -1
7223 Xdecor_11, TRUE, FALSE,
7224 EL_EMC_WALL_11, -1, -1
7227 Xdecor_12, TRUE, FALSE,
7228 EL_EMC_WALL_12, -1, -1
7232 Xalpha_0, TRUE, FALSE,
7233 EL_CHAR('0'), -1, -1
7236 Xalpha_1, TRUE, FALSE,
7237 EL_CHAR('1'), -1, -1
7240 Xalpha_2, TRUE, FALSE,
7241 EL_CHAR('2'), -1, -1
7244 Xalpha_3, TRUE, FALSE,
7245 EL_CHAR('3'), -1, -1
7248 Xalpha_4, TRUE, FALSE,
7249 EL_CHAR('4'), -1, -1
7252 Xalpha_5, TRUE, FALSE,
7253 EL_CHAR('5'), -1, -1
7256 Xalpha_6, TRUE, FALSE,
7257 EL_CHAR('6'), -1, -1
7260 Xalpha_7, TRUE, FALSE,
7261 EL_CHAR('7'), -1, -1
7264 Xalpha_8, TRUE, FALSE,
7265 EL_CHAR('8'), -1, -1
7268 Xalpha_9, TRUE, FALSE,
7269 EL_CHAR('9'), -1, -1
7272 Xalpha_excla, TRUE, FALSE,
7273 EL_CHAR('!'), -1, -1
7276 Xalpha_apost, TRUE, FALSE,
7277 EL_CHAR('\''), -1, -1
7280 Xalpha_comma, TRUE, FALSE,
7281 EL_CHAR(','), -1, -1
7284 Xalpha_minus, TRUE, FALSE,
7285 EL_CHAR('-'), -1, -1
7288 Xalpha_perio, TRUE, FALSE,
7289 EL_CHAR('.'), -1, -1
7292 Xalpha_colon, TRUE, FALSE,
7293 EL_CHAR(':'), -1, -1
7296 Xalpha_quest, TRUE, FALSE,
7297 EL_CHAR('?'), -1, -1
7300 Xalpha_a, TRUE, FALSE,
7301 EL_CHAR('A'), -1, -1
7304 Xalpha_b, TRUE, FALSE,
7305 EL_CHAR('B'), -1, -1
7308 Xalpha_c, TRUE, FALSE,
7309 EL_CHAR('C'), -1, -1
7312 Xalpha_d, TRUE, FALSE,
7313 EL_CHAR('D'), -1, -1
7316 Xalpha_e, TRUE, FALSE,
7317 EL_CHAR('E'), -1, -1
7320 Xalpha_f, TRUE, FALSE,
7321 EL_CHAR('F'), -1, -1
7324 Xalpha_g, TRUE, FALSE,
7325 EL_CHAR('G'), -1, -1
7328 Xalpha_h, TRUE, FALSE,
7329 EL_CHAR('H'), -1, -1
7332 Xalpha_i, TRUE, FALSE,
7333 EL_CHAR('I'), -1, -1
7336 Xalpha_j, TRUE, FALSE,
7337 EL_CHAR('J'), -1, -1
7340 Xalpha_k, TRUE, FALSE,
7341 EL_CHAR('K'), -1, -1
7344 Xalpha_l, TRUE, FALSE,
7345 EL_CHAR('L'), -1, -1
7348 Xalpha_m, TRUE, FALSE,
7349 EL_CHAR('M'), -1, -1
7352 Xalpha_n, TRUE, FALSE,
7353 EL_CHAR('N'), -1, -1
7356 Xalpha_o, TRUE, FALSE,
7357 EL_CHAR('O'), -1, -1
7360 Xalpha_p, TRUE, FALSE,
7361 EL_CHAR('P'), -1, -1
7364 Xalpha_q, TRUE, FALSE,
7365 EL_CHAR('Q'), -1, -1
7368 Xalpha_r, TRUE, FALSE,
7369 EL_CHAR('R'), -1, -1
7372 Xalpha_s, TRUE, FALSE,
7373 EL_CHAR('S'), -1, -1
7376 Xalpha_t, TRUE, FALSE,
7377 EL_CHAR('T'), -1, -1
7380 Xalpha_u, TRUE, FALSE,
7381 EL_CHAR('U'), -1, -1
7384 Xalpha_v, TRUE, FALSE,
7385 EL_CHAR('V'), -1, -1
7388 Xalpha_w, TRUE, FALSE,
7389 EL_CHAR('W'), -1, -1
7392 Xalpha_x, TRUE, FALSE,
7393 EL_CHAR('X'), -1, -1
7396 Xalpha_y, TRUE, FALSE,
7397 EL_CHAR('Y'), -1, -1
7400 Xalpha_z, TRUE, FALSE,
7401 EL_CHAR('Z'), -1, -1
7404 Xalpha_arrow_e, TRUE, FALSE,
7405 EL_CHAR('>'), -1, -1
7408 Xalpha_arrow_w, TRUE, FALSE,
7409 EL_CHAR('<'), -1, -1
7412 Xalpha_copyr, TRUE, FALSE,
7413 EL_CHAR(CHAR_BYTE_COPYRIGHT), -1, -1
7417 Ykey_1_blank, FALSE, FALSE,
7418 EL_EM_KEY_1, ACTION_COLLECTING, -1
7421 Ykey_2_blank, FALSE, FALSE,
7422 EL_EM_KEY_2, ACTION_COLLECTING, -1
7425 Ykey_3_blank, FALSE, FALSE,
7426 EL_EM_KEY_3, ACTION_COLLECTING, -1
7429 Ykey_4_blank, FALSE, FALSE,
7430 EL_EM_KEY_4, ACTION_COLLECTING, -1
7433 Ykey_5_blank, FALSE, FALSE,
7434 EL_EMC_KEY_5, ACTION_COLLECTING, -1
7437 Ykey_6_blank, FALSE, FALSE,
7438 EL_EMC_KEY_6, ACTION_COLLECTING, -1
7441 Ykey_7_blank, FALSE, FALSE,
7442 EL_EMC_KEY_7, ACTION_COLLECTING, -1
7445 Ykey_8_blank, FALSE, FALSE,
7446 EL_EMC_KEY_8, ACTION_COLLECTING, -1
7449 Ylenses_blank, FALSE, FALSE,
7450 EL_EMC_LENSES, ACTION_COLLECTING, -1
7453 Ymagnify_blank, FALSE, FALSE,
7454 EL_EMC_MAGNIFIER, ACTION_COLLECTING, -1
7457 Ygrass_blank, FALSE, FALSE,
7458 EL_EMC_GRASS, ACTION_SNAPPING, -1
7461 Ydirt_blank, FALSE, FALSE,
7462 EL_SAND, ACTION_SNAPPING, -1
7471 static struct Mapping_EM_to_RND_player
7480 em_player_mapping_list[MAX_PLAYERS * PLY_MAX + 1] =
7484 EL_PLAYER_1, ACTION_MOVING, MV_BIT_UP,
7488 EL_PLAYER_1, ACTION_MOVING, MV_BIT_RIGHT,
7492 EL_PLAYER_1, ACTION_MOVING, MV_BIT_DOWN,
7496 EL_PLAYER_1, ACTION_MOVING, MV_BIT_LEFT,
7500 EL_PLAYER_1, ACTION_PUSHING, MV_BIT_UP,
7504 EL_PLAYER_1, ACTION_PUSHING, MV_BIT_RIGHT,
7508 EL_PLAYER_1, ACTION_PUSHING, MV_BIT_DOWN,
7512 EL_PLAYER_1, ACTION_PUSHING, MV_BIT_LEFT,
7516 EL_PLAYER_1, ACTION_SNAPPING, MV_BIT_UP,
7520 EL_PLAYER_1, ACTION_SNAPPING, MV_BIT_RIGHT,
7524 EL_PLAYER_1, ACTION_SNAPPING, MV_BIT_DOWN,
7528 EL_PLAYER_1, ACTION_SNAPPING, MV_BIT_LEFT,
7532 EL_PLAYER_2, ACTION_MOVING, MV_BIT_UP,
7536 EL_PLAYER_2, ACTION_MOVING, MV_BIT_RIGHT,
7540 EL_PLAYER_2, ACTION_MOVING, MV_BIT_DOWN,
7544 EL_PLAYER_2, ACTION_MOVING, MV_BIT_LEFT,
7548 EL_PLAYER_2, ACTION_PUSHING, MV_BIT_UP,
7552 EL_PLAYER_2, ACTION_PUSHING, MV_BIT_RIGHT,
7556 EL_PLAYER_2, ACTION_PUSHING, MV_BIT_DOWN,
7560 EL_PLAYER_2, ACTION_PUSHING, MV_BIT_LEFT,
7564 EL_PLAYER_2, ACTION_SNAPPING, MV_BIT_UP,
7568 EL_PLAYER_2, ACTION_SNAPPING, MV_BIT_RIGHT,
7572 EL_PLAYER_2, ACTION_SNAPPING, MV_BIT_DOWN,
7576 EL_PLAYER_2, ACTION_SNAPPING, MV_BIT_LEFT,
7580 EL_PLAYER_1, ACTION_DEFAULT, -1,
7584 EL_PLAYER_2, ACTION_DEFAULT, -1,
7588 EL_PLAYER_3, ACTION_MOVING, MV_BIT_UP,
7592 EL_PLAYER_3, ACTION_MOVING, MV_BIT_RIGHT,
7596 EL_PLAYER_3, ACTION_MOVING, MV_BIT_DOWN,
7600 EL_PLAYER_3, ACTION_MOVING, MV_BIT_LEFT,
7604 EL_PLAYER_3, ACTION_PUSHING, MV_BIT_UP,
7608 EL_PLAYER_3, ACTION_PUSHING, MV_BIT_RIGHT,
7612 EL_PLAYER_3, ACTION_PUSHING, MV_BIT_DOWN,
7616 EL_PLAYER_3, ACTION_PUSHING, MV_BIT_LEFT,
7620 EL_PLAYER_3, ACTION_SNAPPING, MV_BIT_UP,
7624 EL_PLAYER_3, ACTION_SNAPPING, MV_BIT_RIGHT,
7628 EL_PLAYER_3, ACTION_SNAPPING, MV_BIT_DOWN,
7632 EL_PLAYER_3, ACTION_SNAPPING, MV_BIT_LEFT,
7636 EL_PLAYER_4, ACTION_MOVING, MV_BIT_UP,
7640 EL_PLAYER_4, ACTION_MOVING, MV_BIT_RIGHT,
7644 EL_PLAYER_4, ACTION_MOVING, MV_BIT_DOWN,
7648 EL_PLAYER_4, ACTION_MOVING, MV_BIT_LEFT,
7652 EL_PLAYER_4, ACTION_PUSHING, MV_BIT_UP,
7656 EL_PLAYER_4, ACTION_PUSHING, MV_BIT_RIGHT,
7660 EL_PLAYER_4, ACTION_PUSHING, MV_BIT_DOWN,
7664 EL_PLAYER_4, ACTION_PUSHING, MV_BIT_LEFT,
7668 EL_PLAYER_4, ACTION_SNAPPING, MV_BIT_UP,
7672 EL_PLAYER_4, ACTION_SNAPPING, MV_BIT_RIGHT,
7676 EL_PLAYER_4, ACTION_SNAPPING, MV_BIT_DOWN,
7680 EL_PLAYER_4, ACTION_SNAPPING, MV_BIT_LEFT,
7684 EL_PLAYER_3, ACTION_DEFAULT, -1,
7688 EL_PLAYER_4, ACTION_DEFAULT, -1,
7697 int map_element_RND_to_EM_cave(int element_rnd)
7699 static unsigned short mapping_RND_to_EM[NUM_FILE_ELEMENTS];
7700 static boolean mapping_initialized = FALSE;
7702 if (!mapping_initialized)
7706 // return "Xalpha_quest" for all undefined elements in mapping array
7707 for (i = 0; i < NUM_FILE_ELEMENTS; i++)
7708 mapping_RND_to_EM[i] = Xalpha_quest;
7710 for (i = 0; em_object_mapping_list[i].element_em != -1; i++)
7711 if (em_object_mapping_list[i].is_rnd_to_em_mapping)
7712 mapping_RND_to_EM[em_object_mapping_list[i].element_rnd] =
7713 em_object_mapping_list[i].element_em;
7715 mapping_initialized = TRUE;
7718 if (element_rnd < 0 || element_rnd >= NUM_FILE_ELEMENTS)
7720 Warn("invalid RND level element %d", element_rnd);
7725 return map_em_element_X_to_C(mapping_RND_to_EM[element_rnd]);
7728 int map_element_EM_to_RND_cave(int element_em_cave)
7730 static unsigned short mapping_EM_to_RND[GAME_TILE_MAX];
7731 static boolean mapping_initialized = FALSE;
7733 if (!mapping_initialized)
7737 // return "EL_UNKNOWN" for all undefined elements in mapping array
7738 for (i = 0; i < GAME_TILE_MAX; i++)
7739 mapping_EM_to_RND[i] = EL_UNKNOWN;
7741 for (i = 0; em_object_mapping_list[i].element_em != -1; i++)
7742 mapping_EM_to_RND[em_object_mapping_list[i].element_em] =
7743 em_object_mapping_list[i].element_rnd;
7745 mapping_initialized = TRUE;
7748 if (element_em_cave < 0 || element_em_cave >= CAVE_TILE_MAX)
7750 Warn("invalid EM cave element %d", element_em_cave);
7755 return mapping_EM_to_RND[map_em_element_C_to_X(element_em_cave)];
7758 int map_element_EM_to_RND_game(int element_em_game)
7760 static unsigned short mapping_EM_to_RND[GAME_TILE_MAX];
7761 static boolean mapping_initialized = FALSE;
7763 if (!mapping_initialized)
7767 // return "EL_UNKNOWN" for all undefined elements in mapping array
7768 for (i = 0; i < GAME_TILE_MAX; i++)
7769 mapping_EM_to_RND[i] = EL_UNKNOWN;
7771 for (i = 0; em_object_mapping_list[i].element_em != -1; i++)
7772 mapping_EM_to_RND[em_object_mapping_list[i].element_em] =
7773 em_object_mapping_list[i].element_rnd;
7775 mapping_initialized = TRUE;
7778 if (element_em_game < 0 || element_em_game >= GAME_TILE_MAX)
7780 Warn("invalid EM game element %d", element_em_game);
7785 return mapping_EM_to_RND[element_em_game];
7788 void map_android_clone_elements_RND_to_EM(struct LevelInfo *level)
7790 struct LevelInfo_EM *level_em = level->native_em_level;
7791 struct CAVE *cav = level_em->cav;
7794 for (i = 0; i < GAME_TILE_MAX; i++)
7795 cav->android_array[i] = Cblank;
7797 for (i = 0; i < level->num_android_clone_elements; i++)
7799 int element_rnd = level->android_clone_element[i];
7800 int element_em_cave = map_element_RND_to_EM_cave(element_rnd);
7802 for (j = 0; em_object_mapping_list[j].element_em != -1; j++)
7803 if (em_object_mapping_list[j].element_rnd == element_rnd)
7804 cav->android_array[em_object_mapping_list[j].element_em] =
7809 void map_android_clone_elements_EM_to_RND(struct LevelInfo *level)
7811 struct LevelInfo_EM *level_em = level->native_em_level;
7812 struct CAVE *cav = level_em->cav;
7815 level->num_android_clone_elements = 0;
7817 for (i = 0; i < GAME_TILE_MAX; i++)
7819 int element_em_cave = cav->android_array[i];
7821 boolean element_found = FALSE;
7823 if (element_em_cave == Cblank)
7826 element_rnd = map_element_EM_to_RND_cave(element_em_cave);
7828 for (j = 0; j < level->num_android_clone_elements; j++)
7829 if (level->android_clone_element[j] == element_rnd)
7830 element_found = TRUE;
7834 level->android_clone_element[level->num_android_clone_elements++] =
7837 if (level->num_android_clone_elements == MAX_ANDROID_ELEMENTS)
7842 if (level->num_android_clone_elements == 0)
7844 level->num_android_clone_elements = 1;
7845 level->android_clone_element[0] = EL_EMPTY;
7849 int map_direction_RND_to_EM(int direction)
7851 return (direction == MV_UP ? 0 :
7852 direction == MV_RIGHT ? 1 :
7853 direction == MV_DOWN ? 2 :
7854 direction == MV_LEFT ? 3 :
7858 int map_direction_EM_to_RND(int direction)
7860 return (direction == 0 ? MV_UP :
7861 direction == 1 ? MV_RIGHT :
7862 direction == 2 ? MV_DOWN :
7863 direction == 3 ? MV_LEFT :
7867 int map_element_RND_to_SP(int element_rnd)
7869 int element_sp = 0x20; // map unknown elements to yellow "hardware"
7871 if (element_rnd >= EL_SP_START &&
7872 element_rnd <= EL_SP_END)
7873 element_sp = element_rnd - EL_SP_START;
7874 else if (element_rnd == EL_EMPTY_SPACE)
7876 else if (element_rnd == EL_INVISIBLE_WALL)
7882 int map_element_SP_to_RND(int element_sp)
7884 int element_rnd = EL_UNKNOWN;
7886 if (element_sp >= 0x00 &&
7888 element_rnd = EL_SP_START + element_sp;
7889 else if (element_sp == 0x28)
7890 element_rnd = EL_INVISIBLE_WALL;
7895 int map_action_SP_to_RND(int action_sp)
7899 case actActive: return ACTION_ACTIVE;
7900 case actImpact: return ACTION_IMPACT;
7901 case actExploding: return ACTION_EXPLODING;
7902 case actDigging: return ACTION_DIGGING;
7903 case actSnapping: return ACTION_SNAPPING;
7904 case actCollecting: return ACTION_COLLECTING;
7905 case actPassing: return ACTION_PASSING;
7906 case actPushing: return ACTION_PUSHING;
7907 case actDropping: return ACTION_DROPPING;
7909 default: return ACTION_DEFAULT;
7913 int map_element_RND_to_MM(int element_rnd)
7915 return (element_rnd >= EL_MM_START_1 &&
7916 element_rnd <= EL_MM_END_1 ?
7917 EL_MM_START_1_NATIVE + element_rnd - EL_MM_START_1 :
7919 element_rnd >= EL_MM_START_2 &&
7920 element_rnd <= EL_MM_END_2 ?
7921 EL_MM_START_2_NATIVE + element_rnd - EL_MM_START_2 :
7923 element_rnd >= EL_CHAR_START &&
7924 element_rnd <= EL_CHAR_END ?
7925 EL_MM_CHAR_START_NATIVE + element_rnd - EL_CHAR_START :
7927 element_rnd >= EL_MM_RUNTIME_START &&
7928 element_rnd <= EL_MM_RUNTIME_END ?
7929 EL_MM_RUNTIME_START_NATIVE + element_rnd - EL_MM_RUNTIME_START :
7931 element_rnd >= EL_MM_DUMMY_START &&
7932 element_rnd <= EL_MM_DUMMY_END ?
7933 EL_MM_DUMMY_START_NATIVE + element_rnd - EL_MM_DUMMY_START :
7935 EL_MM_EMPTY_NATIVE);
7938 int map_element_MM_to_RND(int element_mm)
7940 return (element_mm == EL_MM_EMPTY_NATIVE ||
7941 element_mm == EL_DF_EMPTY_NATIVE ?
7944 element_mm >= EL_MM_START_1_NATIVE &&
7945 element_mm <= EL_MM_END_1_NATIVE ?
7946 EL_MM_START_1 + element_mm - EL_MM_START_1_NATIVE :
7948 element_mm >= EL_MM_START_2_NATIVE &&
7949 element_mm <= EL_MM_END_2_NATIVE ?
7950 EL_MM_START_2 + element_mm - EL_MM_START_2_NATIVE :
7952 element_mm >= EL_MM_CHAR_START_NATIVE &&
7953 element_mm <= EL_MM_CHAR_END_NATIVE ?
7954 EL_CHAR_START + element_mm - EL_MM_CHAR_START_NATIVE :
7956 element_mm >= EL_MM_RUNTIME_START_NATIVE &&
7957 element_mm <= EL_MM_RUNTIME_END_NATIVE ?
7958 EL_MM_RUNTIME_START + element_mm - EL_MM_RUNTIME_START_NATIVE :
7960 element_mm >= EL_MM_DUMMY_START_NATIVE &&
7961 element_mm <= EL_MM_DUMMY_END_NATIVE ?
7962 EL_MM_DUMMY_START + element_mm - EL_MM_DUMMY_START_NATIVE :
7967 int map_action_MM_to_RND(int action_mm)
7969 // all MM actions are defined to exactly match their RND counterparts
7973 int map_sound_MM_to_RND(int sound_mm)
7977 case SND_MM_GAME_LEVELTIME_CHARGING:
7978 return SND_GAME_LEVELTIME_CHARGING;
7980 case SND_MM_GAME_HEALTH_CHARGING:
7981 return SND_GAME_HEALTH_CHARGING;
7984 return SND_UNDEFINED;
7988 int map_mm_wall_element(int element)
7990 return (element >= EL_MM_STEEL_WALL_START &&
7991 element <= EL_MM_STEEL_WALL_END ?
7994 element >= EL_MM_WOODEN_WALL_START &&
7995 element <= EL_MM_WOODEN_WALL_END ?
7998 element >= EL_MM_ICE_WALL_START &&
7999 element <= EL_MM_ICE_WALL_END ?
8002 element >= EL_MM_AMOEBA_WALL_START &&
8003 element <= EL_MM_AMOEBA_WALL_END ?
8006 element >= EL_DF_STEEL_WALL_START &&
8007 element <= EL_DF_STEEL_WALL_END ?
8010 element >= EL_DF_WOODEN_WALL_START &&
8011 element <= EL_DF_WOODEN_WALL_END ?
8017 int map_mm_wall_element_editor(int element)
8021 case EL_MM_STEEL_WALL: return EL_MM_STEEL_WALL_START;
8022 case EL_MM_WOODEN_WALL: return EL_MM_WOODEN_WALL_START;
8023 case EL_MM_ICE_WALL: return EL_MM_ICE_WALL_START;
8024 case EL_MM_AMOEBA_WALL: return EL_MM_AMOEBA_WALL_START;
8025 case EL_DF_STEEL_WALL: return EL_DF_STEEL_WALL_START;
8026 case EL_DF_WOODEN_WALL: return EL_DF_WOODEN_WALL_START;
8028 default: return element;
8032 int get_next_element(int element)
8036 case EL_QUICKSAND_FILLING: return EL_QUICKSAND_FULL;
8037 case EL_QUICKSAND_EMPTYING: return EL_QUICKSAND_EMPTY;
8038 case EL_QUICKSAND_FAST_FILLING: return EL_QUICKSAND_FAST_FULL;
8039 case EL_QUICKSAND_FAST_EMPTYING: return EL_QUICKSAND_FAST_EMPTY;
8040 case EL_MAGIC_WALL_FILLING: return EL_MAGIC_WALL_FULL;
8041 case EL_MAGIC_WALL_EMPTYING: return EL_MAGIC_WALL_ACTIVE;
8042 case EL_BD_MAGIC_WALL_FILLING: return EL_BD_MAGIC_WALL_FULL;
8043 case EL_BD_MAGIC_WALL_EMPTYING: return EL_BD_MAGIC_WALL_ACTIVE;
8044 case EL_DC_MAGIC_WALL_FILLING: return EL_DC_MAGIC_WALL_FULL;
8045 case EL_DC_MAGIC_WALL_EMPTYING: return EL_DC_MAGIC_WALL_ACTIVE;
8046 case EL_AMOEBA_DROPPING: return EL_AMOEBA_WET;
8048 default: return element;
8052 int el2img_mm(int element_mm)
8054 return el2img(map_element_MM_to_RND(element_mm));
8057 int el_act_dir2img(int element, int action, int direction)
8059 element = GFX_ELEMENT(element);
8060 direction = MV_DIR_TO_BIT(direction); // default: MV_NONE => MV_DOWN
8062 // direction_graphic[][] == graphic[] for undefined direction graphics
8063 return element_info[element].direction_graphic[action][direction];
8066 static int el_act_dir2crm(int element, int action, int direction)
8068 element = GFX_ELEMENT(element);
8069 direction = MV_DIR_TO_BIT(direction); // default: MV_NONE => MV_DOWN
8071 // direction_graphic[][] == graphic[] for undefined direction graphics
8072 return element_info[element].direction_crumbled[action][direction];
8075 int el_act2img(int element, int action)
8077 element = GFX_ELEMENT(element);
8079 return element_info[element].graphic[action];
8082 int el_act2crm(int element, int action)
8084 element = GFX_ELEMENT(element);
8086 return element_info[element].crumbled[action];
8089 int el_dir2img(int element, int direction)
8091 element = GFX_ELEMENT(element);
8093 return el_act_dir2img(element, ACTION_DEFAULT, direction);
8096 int el2baseimg(int element)
8098 return element_info[element].graphic[ACTION_DEFAULT];
8101 int el2img(int element)
8103 element = GFX_ELEMENT(element);
8105 return element_info[element].graphic[ACTION_DEFAULT];
8108 int el2edimg(int element)
8110 element = GFX_ELEMENT(element);
8112 return element_info[element].special_graphic[GFX_SPECIAL_ARG_EDITOR];
8115 int el2preimg(int element)
8117 element = GFX_ELEMENT(element);
8119 return element_info[element].special_graphic[GFX_SPECIAL_ARG_PREVIEW];
8122 int el2panelimg(int element)
8124 element = GFX_ELEMENT(element);
8126 return element_info[element].special_graphic[GFX_SPECIAL_ARG_PANEL];
8129 int font2baseimg(int font_nr)
8131 return font_info[font_nr].special_graphic[GFX_SPECIAL_ARG_DEFAULT];
8134 int getBeltNrFromBeltElement(int element)
8136 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
8137 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
8138 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
8141 int getBeltNrFromBeltActiveElement(int element)
8143 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
8144 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
8145 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
8148 int getBeltNrFromBeltSwitchElement(int element)
8150 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
8151 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
8152 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
8155 int getBeltDirNrFromBeltElement(int element)
8157 static int belt_base_element[4] =
8159 EL_CONVEYOR_BELT_1_LEFT,
8160 EL_CONVEYOR_BELT_2_LEFT,
8161 EL_CONVEYOR_BELT_3_LEFT,
8162 EL_CONVEYOR_BELT_4_LEFT
8165 int belt_nr = getBeltNrFromBeltElement(element);
8166 int belt_dir_nr = element - belt_base_element[belt_nr];
8168 return (belt_dir_nr % 3);
8171 int getBeltDirNrFromBeltSwitchElement(int element)
8173 static int belt_base_element[4] =
8175 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
8176 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
8177 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
8178 EL_CONVEYOR_BELT_4_SWITCH_LEFT
8181 int belt_nr = getBeltNrFromBeltSwitchElement(element);
8182 int belt_dir_nr = element - belt_base_element[belt_nr];
8184 return (belt_dir_nr % 3);
8187 int getBeltDirFromBeltElement(int element)
8189 static int belt_move_dir[3] =
8196 int belt_dir_nr = getBeltDirNrFromBeltElement(element);
8198 return belt_move_dir[belt_dir_nr];
8201 int getBeltDirFromBeltSwitchElement(int element)
8203 static int belt_move_dir[3] =
8210 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
8212 return belt_move_dir[belt_dir_nr];
8215 int getBeltElementFromBeltNrAndBeltDirNr(int belt_nr, int belt_dir_nr)
8217 static int belt_base_element[4] =
8219 EL_CONVEYOR_BELT_1_LEFT,
8220 EL_CONVEYOR_BELT_2_LEFT,
8221 EL_CONVEYOR_BELT_3_LEFT,
8222 EL_CONVEYOR_BELT_4_LEFT
8225 return belt_base_element[belt_nr] + belt_dir_nr;
8228 int getBeltElementFromBeltNrAndBeltDir(int belt_nr, int belt_dir)
8230 int belt_dir_nr = (belt_dir == MV_LEFT ? 0 : belt_dir == MV_RIGHT ? 2 : 1);
8232 return getBeltElementFromBeltNrAndBeltDirNr(belt_nr, belt_dir_nr);
8235 int getBeltSwitchElementFromBeltNrAndBeltDirNr(int belt_nr, int belt_dir_nr)
8237 static int belt_base_element[4] =
8239 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
8240 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
8241 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
8242 EL_CONVEYOR_BELT_4_SWITCH_LEFT
8245 return belt_base_element[belt_nr] + belt_dir_nr;
8248 int getBeltSwitchElementFromBeltNrAndBeltDir(int belt_nr, int belt_dir)
8250 int belt_dir_nr = (belt_dir == MV_LEFT ? 0 : belt_dir == MV_RIGHT ? 2 : 1);
8252 return getBeltSwitchElementFromBeltNrAndBeltDirNr(belt_nr, belt_dir_nr);
8255 boolean swapTiles_EM(boolean is_pre_emc_cave)
8257 return is_pre_emc_cave && leveldir_current->use_emc_tiles;
8260 boolean getTeamMode_EM(void)
8262 return game.team_mode || network_playing;
8265 boolean isActivePlayer_EM(int player_nr)
8267 return stored_player[player_nr].active;
8270 unsigned int InitRND(int seed)
8272 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
8273 return InitEngineRandom_EM(seed);
8274 else if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
8275 return InitEngineRandom_SP(seed);
8276 else if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
8277 return InitEngineRandom_MM(seed);
8279 return InitEngineRandom_RND(seed);
8282 static struct Mapping_EM_to_RND_object object_mapping[GAME_TILE_MAX];
8283 static struct Mapping_EM_to_RND_player player_mapping[MAX_PLAYERS][PLY_MAX];
8285 static int get_effective_element_EM(int tile, int frame_em)
8287 int element = object_mapping[tile].element_rnd;
8288 int action = object_mapping[tile].action;
8289 boolean is_backside = object_mapping[tile].is_backside;
8290 boolean action_removing = (action == ACTION_DIGGING ||
8291 action == ACTION_SNAPPING ||
8292 action == ACTION_COLLECTING);
8300 return (frame_em > 5 ? EL_EMPTY : element);
8306 else // frame_em == 7
8317 case Ydiamond_stone:
8321 case Xdrip_stretchB:
8337 case Ymagnify_blank:
8340 case Xsand_stonein_1:
8341 case Xsand_stonein_2:
8342 case Xsand_stonein_3:
8343 case Xsand_stonein_4:
8347 return (is_backside || action_removing ? EL_EMPTY : element);
8352 static boolean check_linear_animation_EM(int tile)
8356 case Xsand_stonesand_1:
8357 case Xsand_stonesand_quickout_1:
8358 case Xsand_sandstone_1:
8359 case Xsand_stonein_1:
8360 case Xsand_stoneout_1:
8388 static void set_crumbled_graphics_EM(struct GraphicInfo_EM *g_em,
8389 boolean has_crumbled_graphics,
8390 int crumbled, int sync_frame)
8392 // if element can be crumbled, but certain action graphics are just empty
8393 // space (like instantly snapping sand to empty space in 1 frame), do not
8394 // treat these empty space graphics as crumbled graphics in EMC engine
8395 if (crumbled == IMG_EMPTY_SPACE)
8396 has_crumbled_graphics = FALSE;
8398 if (has_crumbled_graphics)
8400 struct GraphicInfo *g_crumbled = &graphic_info[crumbled];
8401 int frame_crumbled = getAnimationFrame(g_crumbled->anim_frames,
8402 g_crumbled->anim_delay,
8403 g_crumbled->anim_mode,
8404 g_crumbled->anim_start_frame,
8407 getGraphicSource(crumbled, frame_crumbled, &g_em->crumbled_bitmap,
8408 &g_em->crumbled_src_x, &g_em->crumbled_src_y);
8410 g_em->crumbled_border_size = graphic_info[crumbled].border_size;
8411 g_em->crumbled_tile_size = graphic_info[crumbled].tile_size;
8413 g_em->has_crumbled_graphics = TRUE;
8417 g_em->crumbled_bitmap = NULL;
8418 g_em->crumbled_src_x = 0;
8419 g_em->crumbled_src_y = 0;
8420 g_em->crumbled_border_size = 0;
8421 g_em->crumbled_tile_size = 0;
8423 g_em->has_crumbled_graphics = FALSE;
8428 void ResetGfxAnimation_EM(int x, int y, int tile)
8434 void SetGfxAnimation_EM(struct GraphicInfo_EM *g_em,
8435 int tile, int frame_em, int x, int y)
8437 int action = object_mapping[tile].action;
8438 int direction = object_mapping[tile].direction;
8439 int effective_element = get_effective_element_EM(tile, frame_em);
8440 int graphic = (direction == MV_NONE ?
8441 el_act2img(effective_element, action) :
8442 el_act_dir2img(effective_element, action, direction));
8443 struct GraphicInfo *g = &graphic_info[graphic];
8445 boolean action_removing = (action == ACTION_DIGGING ||
8446 action == ACTION_SNAPPING ||
8447 action == ACTION_COLLECTING);
8448 boolean action_moving = (action == ACTION_FALLING ||
8449 action == ACTION_MOVING ||
8450 action == ACTION_PUSHING ||
8451 action == ACTION_EATING ||
8452 action == ACTION_FILLING ||
8453 action == ACTION_EMPTYING);
8454 boolean action_falling = (action == ACTION_FALLING ||
8455 action == ACTION_FILLING ||
8456 action == ACTION_EMPTYING);
8458 // special case: graphic uses "2nd movement tile" and has defined
8459 // 7 frames for movement animation (or less) => use default graphic
8460 // for last (8th) frame which ends the movement animation
8461 if (g->double_movement && g->anim_frames < 8 && frame_em == 7)
8463 action = ACTION_DEFAULT; // (keep action_* unchanged for now)
8464 graphic = (direction == MV_NONE ?
8465 el_act2img(effective_element, action) :
8466 el_act_dir2img(effective_element, action, direction));
8468 g = &graphic_info[graphic];
8471 if ((action_removing || check_linear_animation_EM(tile)) && frame_em == 0)
8475 else if (action_moving)
8477 boolean is_backside = object_mapping[tile].is_backside;
8481 int direction = object_mapping[tile].direction;
8482 int move_dir = (action_falling ? MV_DOWN : direction);
8487 // !!! TEST !!! NEW !!! DOES NOT WORK RIGHT YET !!!
8488 if (g->double_movement && frame_em == 0)
8492 if (move_dir == MV_LEFT)
8493 GfxFrame[x - 1][y] = GfxFrame[x][y];
8494 else if (move_dir == MV_RIGHT)
8495 GfxFrame[x + 1][y] = GfxFrame[x][y];
8496 else if (move_dir == MV_UP)
8497 GfxFrame[x][y - 1] = GfxFrame[x][y];
8498 else if (move_dir == MV_DOWN)
8499 GfxFrame[x][y + 1] = GfxFrame[x][y];
8506 // special case: animation for Xsand_stonesand_quickout_1/2 twice as fast
8507 if (tile == Xsand_stonesand_quickout_1 ||
8508 tile == Xsand_stonesand_quickout_2)
8512 if (graphic_info[graphic].anim_global_sync)
8513 sync_frame = FrameCounter;
8514 else if (IN_FIELD(x, y, MAX_LEV_FIELDX, MAX_LEV_FIELDY))
8515 sync_frame = GfxFrame[x][y];
8517 sync_frame = 0; // playfield border (pseudo steel)
8519 SetRandomAnimationValue(x, y);
8521 int frame = getAnimationFrame(g->anim_frames,
8524 g->anim_start_frame,
8527 g_em->unique_identifier =
8528 (graphic << 16) | ((frame % 8) << 12) | (g_em->width << 6) | g_em->height;
8531 void getGraphicSourceObjectExt_EM(struct GraphicInfo_EM *g_em,
8532 int tile, int frame_em, int x, int y)
8534 int action = object_mapping[tile].action;
8535 int direction = object_mapping[tile].direction;
8536 boolean is_backside = object_mapping[tile].is_backside;
8537 int effective_element = get_effective_element_EM(tile, frame_em);
8538 int effective_action = action;
8539 int graphic = (direction == MV_NONE ?
8540 el_act2img(effective_element, effective_action) :
8541 el_act_dir2img(effective_element, effective_action,
8543 int crumbled = (direction == MV_NONE ?
8544 el_act2crm(effective_element, effective_action) :
8545 el_act_dir2crm(effective_element, effective_action,
8547 int base_graphic = el_act2img(effective_element, ACTION_DEFAULT);
8548 int base_crumbled = el_act2crm(effective_element, ACTION_DEFAULT);
8549 boolean has_crumbled_graphics = (base_crumbled != base_graphic);
8550 struct GraphicInfo *g = &graphic_info[graphic];
8553 // special case: graphic uses "2nd movement tile" and has defined
8554 // 7 frames for movement animation (or less) => use default graphic
8555 // for last (8th) frame which ends the movement animation
8556 if (g->double_movement && g->anim_frames < 8 && frame_em == 7)
8558 effective_action = ACTION_DEFAULT;
8559 graphic = (direction == MV_NONE ?
8560 el_act2img(effective_element, effective_action) :
8561 el_act_dir2img(effective_element, effective_action,
8563 crumbled = (direction == MV_NONE ?
8564 el_act2crm(effective_element, effective_action) :
8565 el_act_dir2crm(effective_element, effective_action,
8568 g = &graphic_info[graphic];
8571 if (graphic_info[graphic].anim_global_sync)
8572 sync_frame = FrameCounter;
8573 else if (IN_FIELD(x, y, MAX_LEV_FIELDX, MAX_LEV_FIELDY))
8574 sync_frame = GfxFrame[x][y];
8576 sync_frame = 0; // playfield border (pseudo steel)
8578 SetRandomAnimationValue(x, y);
8580 int frame = getAnimationFrame(g->anim_frames,
8583 g->anim_start_frame,
8586 getGraphicSourceExt(graphic, frame, &g_em->bitmap, &g_em->src_x, &g_em->src_y,
8587 g->double_movement && is_backside);
8589 // (updating the "crumbled" graphic definitions is probably not really needed,
8590 // as animations for crumbled graphics can't be longer than one EMC cycle)
8591 set_crumbled_graphics_EM(g_em, has_crumbled_graphics, crumbled,
8595 void getGraphicSourcePlayerExt_EM(struct GraphicInfo_EM *g_em,
8596 int player_nr, int anim, int frame_em)
8598 int element = player_mapping[player_nr][anim].element_rnd;
8599 int action = player_mapping[player_nr][anim].action;
8600 int direction = player_mapping[player_nr][anim].direction;
8601 int graphic = (direction == MV_NONE ?
8602 el_act2img(element, action) :
8603 el_act_dir2img(element, action, direction));
8604 struct GraphicInfo *g = &graphic_info[graphic];
8607 InitPlayerGfxAnimation(&stored_player[player_nr], action, direction);
8609 stored_player[player_nr].StepFrame = frame_em;
8611 sync_frame = stored_player[player_nr].Frame;
8613 int frame = getAnimationFrame(g->anim_frames,
8616 g->anim_start_frame,
8619 getGraphicSourceExt(graphic, frame, &g_em->bitmap,
8620 &g_em->src_x, &g_em->src_y, FALSE);
8623 void InitGraphicInfo_EM(void)
8627 // always start with reliable default values
8628 for (i = 0; i < GAME_TILE_MAX; i++)
8630 object_mapping[i].element_rnd = EL_UNKNOWN;
8631 object_mapping[i].is_backside = FALSE;
8632 object_mapping[i].action = ACTION_DEFAULT;
8633 object_mapping[i].direction = MV_NONE;
8636 // always start with reliable default values
8637 for (p = 0; p < MAX_PLAYERS; p++)
8639 for (i = 0; i < PLY_MAX; i++)
8641 player_mapping[p][i].element_rnd = EL_UNKNOWN;
8642 player_mapping[p][i].action = ACTION_DEFAULT;
8643 player_mapping[p][i].direction = MV_NONE;
8647 for (i = 0; em_object_mapping_list[i].element_em != -1; i++)
8649 int e = em_object_mapping_list[i].element_em;
8651 object_mapping[e].element_rnd = em_object_mapping_list[i].element_rnd;
8652 object_mapping[e].is_backside = em_object_mapping_list[i].is_backside;
8654 if (em_object_mapping_list[i].action != -1)
8655 object_mapping[e].action = em_object_mapping_list[i].action;
8657 if (em_object_mapping_list[i].direction != -1)
8658 object_mapping[e].direction =
8659 MV_DIR_FROM_BIT(em_object_mapping_list[i].direction);
8662 for (i = 0; em_player_mapping_list[i].action_em != -1; i++)
8664 int a = em_player_mapping_list[i].action_em;
8665 int p = em_player_mapping_list[i].player_nr;
8667 player_mapping[p][a].element_rnd = em_player_mapping_list[i].element_rnd;
8669 if (em_player_mapping_list[i].action != -1)
8670 player_mapping[p][a].action = em_player_mapping_list[i].action;
8672 if (em_player_mapping_list[i].direction != -1)
8673 player_mapping[p][a].direction =
8674 MV_DIR_FROM_BIT(em_player_mapping_list[i].direction);
8677 for (i = 0; i < GAME_TILE_MAX; i++)
8679 int element = object_mapping[i].element_rnd;
8680 int action = object_mapping[i].action;
8681 int direction = object_mapping[i].direction;
8682 boolean is_backside = object_mapping[i].is_backside;
8683 boolean action_exploding = ((action == ACTION_EXPLODING ||
8684 action == ACTION_SMASHED_BY_ROCK ||
8685 action == ACTION_SMASHED_BY_SPRING) &&
8686 element != EL_DIAMOND);
8687 boolean action_active = (action == ACTION_ACTIVE);
8688 boolean action_other = (action == ACTION_OTHER);
8690 for (j = 0; j < 8; j++)
8692 int effective_element = get_effective_element_EM(i, j);
8693 int effective_action = (j < 7 ? action :
8694 i == Xdrip_stretch ? action :
8695 i == Xdrip_stretchB ? action :
8696 i == Ydrip_1_s ? action :
8697 i == Ydrip_1_sB ? action :
8698 i == Yball_1 ? action :
8699 i == Xball_2 ? action :
8700 i == Yball_2 ? action :
8701 i == Yball_blank ? action :
8702 i == Ykey_1_blank ? action :
8703 i == Ykey_2_blank ? action :
8704 i == Ykey_3_blank ? action :
8705 i == Ykey_4_blank ? action :
8706 i == Ykey_5_blank ? action :
8707 i == Ykey_6_blank ? action :
8708 i == Ykey_7_blank ? action :
8709 i == Ykey_8_blank ? action :
8710 i == Ylenses_blank ? action :
8711 i == Ymagnify_blank ? action :
8712 i == Ygrass_blank ? action :
8713 i == Ydirt_blank ? action :
8714 i == Xsand_stonein_1 ? action :
8715 i == Xsand_stonein_2 ? action :
8716 i == Xsand_stonein_3 ? action :
8717 i == Xsand_stonein_4 ? action :
8718 i == Xsand_stoneout_1 ? action :
8719 i == Xsand_stoneout_2 ? action :
8720 i == Xboom_android ? ACTION_EXPLODING :
8721 action_exploding ? ACTION_EXPLODING :
8722 action_active ? action :
8723 action_other ? action :
8725 int graphic = (el_act_dir2img(effective_element, effective_action,
8727 int crumbled = (el_act_dir2crm(effective_element, effective_action,
8729 int base_graphic = el_act2img(effective_element, ACTION_DEFAULT);
8730 int base_crumbled = el_act2crm(effective_element, ACTION_DEFAULT);
8731 boolean has_action_graphics = (graphic != base_graphic);
8732 boolean has_crumbled_graphics = (base_crumbled != base_graphic);
8733 struct GraphicInfo *g = &graphic_info[graphic];
8734 struct GraphicInfo_EM *g_em = &graphic_info_em_object[i][j];
8737 // ensure to get symmetric 3-frame, 2-delay animations as used in EM
8738 boolean special_animation = (action != ACTION_DEFAULT &&
8739 g->anim_frames == 3 &&
8740 g->anim_delay == 2 &&
8741 g->anim_mode & ANIM_LINEAR);
8742 int sync_frame = (i == Xdrip_stretch ? 7 :
8743 i == Xdrip_stretchB ? 7 :
8744 i == Ydrip_2_s ? j + 8 :
8745 i == Ydrip_2_sB ? j + 8 :
8754 i == Xfake_acid_1 ? 0 :
8755 i == Xfake_acid_2 ? 10 :
8756 i == Xfake_acid_3 ? 20 :
8757 i == Xfake_acid_4 ? 30 :
8758 i == Xfake_acid_5 ? 40 :
8759 i == Xfake_acid_6 ? 50 :
8760 i == Xfake_acid_7 ? 60 :
8761 i == Xfake_acid_8 ? 70 :
8763 i == Yball_2 ? j + 8 :
8764 i == Yball_blank ? j + 1 :
8765 i == Ykey_1_blank ? j + 1 :
8766 i == Ykey_2_blank ? j + 1 :
8767 i == Ykey_3_blank ? j + 1 :
8768 i == Ykey_4_blank ? j + 1 :
8769 i == Ykey_5_blank ? j + 1 :
8770 i == Ykey_6_blank ? j + 1 :
8771 i == Ykey_7_blank ? j + 1 :
8772 i == Ykey_8_blank ? j + 1 :
8773 i == Ylenses_blank ? j + 1 :
8774 i == Ymagnify_blank ? j + 1 :
8775 i == Ygrass_blank ? j + 1 :
8776 i == Ydirt_blank ? j + 1 :
8777 i == Xamoeba_1 ? 0 :
8778 i == Xamoeba_2 ? 1 :
8779 i == Xamoeba_3 ? 2 :
8780 i == Xamoeba_4 ? 3 :
8781 i == Xamoeba_5 ? 0 :
8782 i == Xamoeba_6 ? 1 :
8783 i == Xamoeba_7 ? 2 :
8784 i == Xamoeba_8 ? 3 :
8785 i == Xexit_2 ? j + 8 :
8786 i == Xexit_3 ? j + 16 :
8787 i == Xdynamite_1 ? 0 :
8788 i == Xdynamite_2 ? 8 :
8789 i == Xdynamite_3 ? 16 :
8790 i == Xdynamite_4 ? 24 :
8791 i == Xsand_stonein_1 ? j + 1 :
8792 i == Xsand_stonein_2 ? j + 9 :
8793 i == Xsand_stonein_3 ? j + 17 :
8794 i == Xsand_stonein_4 ? j + 25 :
8795 i == Xsand_stoneout_1 && j == 0 ? 0 :
8796 i == Xsand_stoneout_1 && j == 1 ? 0 :
8797 i == Xsand_stoneout_1 && j == 2 ? 1 :
8798 i == Xsand_stoneout_1 && j == 3 ? 2 :
8799 i == Xsand_stoneout_1 && j == 4 ? 2 :
8800 i == Xsand_stoneout_1 && j == 5 ? 3 :
8801 i == Xsand_stoneout_1 && j == 6 ? 4 :
8802 i == Xsand_stoneout_1 && j == 7 ? 4 :
8803 i == Xsand_stoneout_2 && j == 0 ? 5 :
8804 i == Xsand_stoneout_2 && j == 1 ? 6 :
8805 i == Xsand_stoneout_2 && j == 2 ? 7 :
8806 i == Xsand_stoneout_2 && j == 3 ? 8 :
8807 i == Xsand_stoneout_2 && j == 4 ? 9 :
8808 i == Xsand_stoneout_2 && j == 5 ? 11 :
8809 i == Xsand_stoneout_2 && j == 6 ? 13 :
8810 i == Xsand_stoneout_2 && j == 7 ? 15 :
8811 i == Xboom_bug && j == 1 ? 2 :
8812 i == Xboom_bug && j == 2 ? 2 :
8813 i == Xboom_bug && j == 3 ? 4 :
8814 i == Xboom_bug && j == 4 ? 4 :
8815 i == Xboom_bug && j == 5 ? 2 :
8816 i == Xboom_bug && j == 6 ? 2 :
8817 i == Xboom_bug && j == 7 ? 0 :
8818 i == Xboom_tank && j == 1 ? 2 :
8819 i == Xboom_tank && j == 2 ? 2 :
8820 i == Xboom_tank && j == 3 ? 4 :
8821 i == Xboom_tank && j == 4 ? 4 :
8822 i == Xboom_tank && j == 5 ? 2 :
8823 i == Xboom_tank && j == 6 ? 2 :
8824 i == Xboom_tank && j == 7 ? 0 :
8825 i == Xboom_android && j == 7 ? 6 :
8826 i == Xboom_1 && j == 1 ? 2 :
8827 i == Xboom_1 && j == 2 ? 2 :
8828 i == Xboom_1 && j == 3 ? 4 :
8829 i == Xboom_1 && j == 4 ? 4 :
8830 i == Xboom_1 && j == 5 ? 6 :
8831 i == Xboom_1 && j == 6 ? 6 :
8832 i == Xboom_1 && j == 7 ? 8 :
8833 i == Xboom_2 && j == 0 ? 8 :
8834 i == Xboom_2 && j == 1 ? 8 :
8835 i == Xboom_2 && j == 2 ? 10 :
8836 i == Xboom_2 && j == 3 ? 10 :
8837 i == Xboom_2 && j == 4 ? 10 :
8838 i == Xboom_2 && j == 5 ? 12 :
8839 i == Xboom_2 && j == 6 ? 12 :
8840 i == Xboom_2 && j == 7 ? 12 :
8841 special_animation && j == 4 ? 3 :
8842 effective_action != action ? 0 :
8844 int frame = getAnimationFrame(g->anim_frames,
8847 g->anim_start_frame,
8850 getGraphicSourceExt(graphic, frame, &src_bitmap, &src_x, &src_y,
8851 g->double_movement && is_backside);
8853 g_em->bitmap = src_bitmap;
8854 g_em->src_x = src_x;
8855 g_em->src_y = src_y;
8856 g_em->src_offset_x = 0;
8857 g_em->src_offset_y = 0;
8858 g_em->dst_offset_x = 0;
8859 g_em->dst_offset_y = 0;
8860 g_em->width = TILEX;
8861 g_em->height = TILEY;
8863 g_em->preserve_background = FALSE;
8865 set_crumbled_graphics_EM(g_em, has_crumbled_graphics, crumbled,
8868 if ((!g->double_movement && (effective_action == ACTION_FALLING ||
8869 effective_action == ACTION_MOVING ||
8870 effective_action == ACTION_PUSHING ||
8871 effective_action == ACTION_EATING)) ||
8872 (!has_action_graphics && (effective_action == ACTION_FILLING ||
8873 effective_action == ACTION_EMPTYING)))
8876 (effective_action == ACTION_FALLING ||
8877 effective_action == ACTION_FILLING ||
8878 effective_action == ACTION_EMPTYING ? MV_DOWN : direction);
8879 int dx = (move_dir == MV_LEFT ? -1 : move_dir == MV_RIGHT ? 1 : 0);
8880 int dy = (move_dir == MV_UP ? -1 : move_dir == MV_DOWN ? 1 : 0);
8881 int num_steps = (i == Ydrip_1_s ? 16 :
8882 i == Ydrip_1_sB ? 16 :
8883 i == Ydrip_2_s ? 16 :
8884 i == Ydrip_2_sB ? 16 :
8885 i == Xsand_stonein_1 ? 32 :
8886 i == Xsand_stonein_2 ? 32 :
8887 i == Xsand_stonein_3 ? 32 :
8888 i == Xsand_stonein_4 ? 32 :
8889 i == Xsand_stoneout_1 ? 16 :
8890 i == Xsand_stoneout_2 ? 16 : 8);
8891 int cx = ABS(dx) * (TILEX / num_steps);
8892 int cy = ABS(dy) * (TILEY / num_steps);
8893 int step_frame = (i == Ydrip_2_s ? j + 8 :
8894 i == Ydrip_2_sB ? j + 8 :
8895 i == Xsand_stonein_2 ? j + 8 :
8896 i == Xsand_stonein_3 ? j + 16 :
8897 i == Xsand_stonein_4 ? j + 24 :
8898 i == Xsand_stoneout_2 ? j + 8 : j) + 1;
8899 int step = (is_backside ? step_frame : num_steps - step_frame);
8901 if (is_backside) // tile where movement starts
8903 if (dx < 0 || dy < 0)
8905 g_em->src_offset_x = cx * step;
8906 g_em->src_offset_y = cy * step;
8910 g_em->dst_offset_x = cx * step;
8911 g_em->dst_offset_y = cy * step;
8914 else // tile where movement ends
8916 if (dx < 0 || dy < 0)
8918 g_em->dst_offset_x = cx * step;
8919 g_em->dst_offset_y = cy * step;
8923 g_em->src_offset_x = cx * step;
8924 g_em->src_offset_y = cy * step;
8928 g_em->width = TILEX - cx * step;
8929 g_em->height = TILEY - cy * step;
8932 // create unique graphic identifier to decide if tile must be redrawn
8933 /* bit 31 - 16 (16 bit): EM style graphic
8934 bit 15 - 12 ( 4 bit): EM style frame
8935 bit 11 - 6 ( 6 bit): graphic width
8936 bit 5 - 0 ( 6 bit): graphic height */
8937 g_em->unique_identifier =
8938 (graphic << 16) | (frame << 12) | (g_em->width << 6) | g_em->height;
8942 for (i = 0; i < GAME_TILE_MAX; i++)
8944 for (j = 0; j < 8; j++)
8946 int element = object_mapping[i].element_rnd;
8947 int action = object_mapping[i].action;
8948 int direction = object_mapping[i].direction;
8949 boolean is_backside = object_mapping[i].is_backside;
8950 int graphic_action = el_act_dir2img(element, action, direction);
8951 int graphic_default = el_act_dir2img(element, ACTION_DEFAULT, direction);
8953 if ((action == ACTION_SMASHED_BY_ROCK ||
8954 action == ACTION_SMASHED_BY_SPRING ||
8955 action == ACTION_EATING) &&
8956 graphic_action == graphic_default)
8958 int e = (action == ACTION_SMASHED_BY_ROCK ? Ystone_s :
8959 action == ACTION_SMASHED_BY_SPRING ? Yspring_s :
8960 direction == MV_LEFT ? (is_backside? Yspring_wB: Yspring_w) :
8961 direction == MV_RIGHT ? (is_backside? Yspring_eB: Yspring_e) :
8964 // no separate animation for "smashed by rock" -- use rock instead
8965 struct GraphicInfo_EM *g_em = &graphic_info_em_object[i][j];
8966 struct GraphicInfo_EM *g_xx = &graphic_info_em_object[e][j];
8968 g_em->bitmap = g_xx->bitmap;
8969 g_em->src_x = g_xx->src_x;
8970 g_em->src_y = g_xx->src_y;
8971 g_em->src_offset_x = g_xx->src_offset_x;
8972 g_em->src_offset_y = g_xx->src_offset_y;
8973 g_em->dst_offset_x = g_xx->dst_offset_x;
8974 g_em->dst_offset_y = g_xx->dst_offset_y;
8975 g_em->width = g_xx->width;
8976 g_em->height = g_xx->height;
8977 g_em->unique_identifier = g_xx->unique_identifier;
8980 g_em->preserve_background = TRUE;
8985 for (p = 0; p < MAX_PLAYERS; p++)
8987 for (i = 0; i < PLY_MAX; i++)
8989 int element = player_mapping[p][i].element_rnd;
8990 int action = player_mapping[p][i].action;
8991 int direction = player_mapping[p][i].direction;
8993 for (j = 0; j < 8; j++)
8995 int effective_element = element;
8996 int effective_action = action;
8997 int graphic = (direction == MV_NONE ?
8998 el_act2img(effective_element, effective_action) :
8999 el_act_dir2img(effective_element, effective_action,
9001 struct GraphicInfo *g = &graphic_info[graphic];
9002 struct GraphicInfo_EM *g_em = &graphic_info_em_player[p][i][j];
9006 int frame = getAnimationFrame(g->anim_frames,
9009 g->anim_start_frame,
9012 getGraphicSourceExt(graphic, frame, &src_bitmap, &src_x, &src_y, FALSE);
9014 g_em->bitmap = src_bitmap;
9015 g_em->src_x = src_x;
9016 g_em->src_y = src_y;
9017 g_em->src_offset_x = 0;
9018 g_em->src_offset_y = 0;
9019 g_em->dst_offset_x = 0;
9020 g_em->dst_offset_y = 0;
9021 g_em->width = TILEX;
9022 g_em->height = TILEY;
9028 static void CheckSaveEngineSnapshot_EM(byte action[MAX_PLAYERS], int frame,
9029 boolean any_player_moving,
9030 boolean any_player_snapping,
9031 boolean any_player_dropping)
9033 if (frame == 7 && !any_player_dropping)
9035 if (!local_player->was_waiting)
9037 if (!CheckSaveEngineSnapshotToList())
9040 local_player->was_waiting = TRUE;
9043 else if (any_player_moving || any_player_snapping || any_player_dropping)
9045 local_player->was_waiting = FALSE;
9049 static void CheckSaveEngineSnapshot_SP(boolean murphy_is_waiting,
9050 boolean murphy_is_dropping)
9052 if (murphy_is_waiting)
9054 if (!local_player->was_waiting)
9056 if (!CheckSaveEngineSnapshotToList())
9059 local_player->was_waiting = TRUE;
9064 local_player->was_waiting = FALSE;
9068 static void CheckSaveEngineSnapshot_MM(boolean element_clicked,
9069 boolean button_released)
9071 if (button_released)
9073 if (game.snapshot.mode == SNAPSHOT_MODE_EVERY_MOVE)
9074 CheckSaveEngineSnapshotToList();
9076 else if (element_clicked)
9078 if (game.snapshot.mode != SNAPSHOT_MODE_EVERY_MOVE)
9079 CheckSaveEngineSnapshotToList();
9081 game.snapshot.changed_action = TRUE;
9085 boolean CheckSingleStepMode_EM(byte action[MAX_PLAYERS], int frame,
9086 boolean any_player_moving,
9087 boolean any_player_snapping,
9088 boolean any_player_dropping)
9090 if (tape.single_step && tape.recording && !tape.pausing)
9091 if (frame == 7 && !any_player_dropping)
9092 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
9094 CheckSaveEngineSnapshot_EM(action, frame, any_player_moving,
9095 any_player_snapping, any_player_dropping);
9097 return tape.pausing;
9100 void CheckSingleStepMode_SP(boolean murphy_is_waiting,
9101 boolean murphy_is_dropping)
9103 boolean murphy_starts_dropping = FALSE;
9106 for (i = 0; i < MAX_PLAYERS; i++)
9107 if (stored_player[i].force_dropping)
9108 murphy_starts_dropping = TRUE;
9110 if (tape.single_step && tape.recording && !tape.pausing)
9111 if (murphy_is_waiting && !murphy_starts_dropping)
9112 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
9114 CheckSaveEngineSnapshot_SP(murphy_is_waiting, murphy_is_dropping);
9117 void CheckSingleStepMode_MM(boolean element_clicked,
9118 boolean button_released)
9120 if (tape.single_step && tape.recording && !tape.pausing)
9121 if (button_released)
9122 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
9124 CheckSaveEngineSnapshot_MM(element_clicked, button_released);
9127 void getGraphicSource_SP(struct GraphicInfo_SP *g_sp,
9128 int graphic, int sync_frame, int x, int y)
9130 int frame = getGraphicAnimationFrame(graphic, sync_frame);
9132 getGraphicSource(graphic, frame, &g_sp->bitmap, &g_sp->src_x, &g_sp->src_y);
9135 boolean isNextAnimationFrame_SP(int graphic, int sync_frame)
9137 return (IS_NEXT_FRAME(sync_frame, graphic));
9140 int getGraphicInfo_Delay(int graphic)
9142 return graphic_info[graphic].anim_delay;
9145 void PlayMenuSoundExt(int sound)
9147 if (sound == SND_UNDEFINED)
9150 if ((!setup.sound_simple && !IS_LOOP_SOUND(sound)) ||
9151 (!setup.sound_loops && IS_LOOP_SOUND(sound)))
9154 if (IS_LOOP_SOUND(sound))
9155 PlaySoundLoop(sound);
9160 void PlayMenuSound(void)
9162 PlayMenuSoundExt(menu.sound[game_status]);
9165 void PlayMenuSoundStereo(int sound, int stereo_position)
9167 if (sound == SND_UNDEFINED)
9170 if ((!setup.sound_simple && !IS_LOOP_SOUND(sound)) ||
9171 (!setup.sound_loops && IS_LOOP_SOUND(sound)))
9174 if (IS_LOOP_SOUND(sound))
9175 PlaySoundExt(sound, SOUND_MAX_VOLUME, stereo_position, SND_CTRL_PLAY_LOOP);
9177 PlaySoundStereo(sound, stereo_position);
9180 void PlayMenuSoundIfLoopExt(int sound)
9182 if (sound == SND_UNDEFINED)
9185 if ((!setup.sound_simple && !IS_LOOP_SOUND(sound)) ||
9186 (!setup.sound_loops && IS_LOOP_SOUND(sound)))
9189 if (IS_LOOP_SOUND(sound))
9190 PlaySoundLoop(sound);
9193 void PlayMenuSoundIfLoop(void)
9195 PlayMenuSoundIfLoopExt(menu.sound[game_status]);
9198 void PlayMenuMusicExt(int music)
9200 if (music == MUS_UNDEFINED)
9203 if (!setup.sound_music)
9206 if (IS_LOOP_MUSIC(music))
9207 PlayMusicLoop(music);
9212 void PlayMenuMusic(void)
9214 char *curr_music = getCurrentlyPlayingMusicFilename();
9215 char *next_music = getMusicInfoEntryFilename(menu.music[game_status]);
9217 if (!strEqual(curr_music, next_music))
9218 PlayMenuMusicExt(menu.music[game_status]);
9221 void PlayMenuSoundsAndMusic(void)
9227 static void FadeMenuSounds(void)
9232 static void FadeMenuMusic(void)
9234 char *curr_music = getCurrentlyPlayingMusicFilename();
9235 char *next_music = getMusicInfoEntryFilename(menu.music[game_status]);
9237 if (!strEqual(curr_music, next_music))
9241 void FadeMenuSoundsAndMusic(void)
9247 void PlaySoundActivating(void)
9250 PlaySound(SND_MENU_ITEM_ACTIVATING);
9254 void PlaySoundSelecting(void)
9257 PlaySound(SND_MENU_ITEM_SELECTING);
9261 void ToggleFullscreenIfNeeded(void)
9263 // if setup and video fullscreen state are already matching, nothing do do
9264 if (setup.fullscreen == video.fullscreen_enabled ||
9265 !video.fullscreen_available)
9268 SDLSetWindowFullscreen(setup.fullscreen);
9270 // set setup value according to successfully changed fullscreen mode
9271 setup.fullscreen = video.fullscreen_enabled;
9274 void ChangeWindowScalingIfNeeded(void)
9276 // if setup and video window scaling are already matching, nothing do do
9277 if (setup.window_scaling_percent == video.window_scaling_percent ||
9278 video.fullscreen_enabled)
9281 SDLSetWindowScaling(setup.window_scaling_percent);
9283 // set setup value according to successfully changed window scaling
9284 setup.window_scaling_percent = video.window_scaling_percent;
9287 void ChangeVsyncModeIfNeeded(void)
9289 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
9290 int video_vsync_mode = video.vsync_mode;
9292 // if setup and video vsync mode are already matching, nothing do do
9293 if (setup_vsync_mode == video_vsync_mode)
9296 // if renderer is using OpenGL, vsync mode can directly be changed
9297 SDLSetScreenVsyncMode(setup.vsync_mode);
9299 // if vsync mode unchanged, try re-creating renderer to set vsync mode
9300 if (video.vsync_mode == video_vsync_mode)
9302 Bitmap *tmp_backbuffer = CreateBitmap(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH);
9304 // save backbuffer content which gets lost when re-creating screen
9305 BlitBitmap(backbuffer, tmp_backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
9307 // force re-creating screen and renderer to set new vsync mode
9308 video.fullscreen_enabled = !setup.fullscreen;
9310 // when creating new renderer, destroy textures linked to old renderer
9311 FreeAllImageTextures(); // needs old renderer to free the textures
9313 // re-create screen and renderer (including change of vsync mode)
9314 ChangeVideoModeIfNeeded(setup.fullscreen);
9316 // set setup value according to successfully changed fullscreen mode
9317 setup.fullscreen = video.fullscreen_enabled;
9319 // restore backbuffer content from temporary backbuffer backup bitmap
9320 BlitBitmap(tmp_backbuffer, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
9321 FreeBitmap(tmp_backbuffer);
9323 // update visible window/screen
9324 BlitBitmap(backbuffer, window, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
9326 // when changing vsync mode, re-create textures for new renderer
9327 InitImageTextures();
9330 // set setup value according to successfully changed vsync mode
9331 setup.vsync_mode = VSYNC_MODE_INT_TO_STR(video.vsync_mode);
9334 static void JoinRectangles(int *x, int *y, int *width, int *height,
9335 int x2, int y2, int width2, int height2)
9337 // do not join with "off-screen" rectangle
9338 if (x2 == -1 || y2 == -1)
9343 *width = MAX(*width, width2);
9344 *height = MAX(*height, height2);
9347 void SetAnimStatus(int anim_status_new)
9349 if (anim_status_new == GAME_MODE_MAIN)
9350 anim_status_new = GAME_MODE_PSEUDO_MAINONLY;
9351 else if (anim_status_new == GAME_MODE_SCORES)
9352 anim_status_new = GAME_MODE_PSEUDO_SCORESOLD;
9354 global.anim_status_next = anim_status_new;
9356 // directly set screen modes that are entered without fading
9357 if ((global.anim_status == GAME_MODE_PSEUDO_MAINONLY &&
9358 global.anim_status_next == GAME_MODE_PSEUDO_TYPENAME) ||
9359 (global.anim_status == GAME_MODE_PSEUDO_TYPENAME &&
9360 global.anim_status_next == GAME_MODE_PSEUDO_MAINONLY))
9361 global.anim_status = global.anim_status_next;
9364 void SetGameStatus(int game_status_new)
9366 if (game_status_new != game_status)
9367 game_status_last_screen = game_status;
9369 game_status = game_status_new;
9371 SetAnimStatus(game_status_new);
9374 void SetFontStatus(int game_status_new)
9376 static int last_game_status = -1;
9378 if (game_status_new != -1)
9380 // set game status for font use after storing last game status
9381 last_game_status = game_status;
9382 game_status = game_status_new;
9386 // reset game status after font use from last stored game status
9387 game_status = last_game_status;
9391 void ResetFontStatus(void)
9396 void SetLevelSetInfo(char *identifier, int level_nr)
9398 setString(&levelset.identifier, identifier);
9400 levelset.level_nr = level_nr;
9403 boolean CheckIfAllViewportsHaveChanged(void)
9405 // if game status has not changed, viewports have not changed either
9406 if (game_status == game_status_last)
9409 // check if all viewports have changed with current game status
9411 struct RectWithBorder *vp_playfield = &viewport.playfield[game_status];
9412 struct RectWithBorder *vp_door_1 = &viewport.door_1[game_status];
9413 struct RectWithBorder *vp_door_2 = &viewport.door_2[game_status];
9414 int new_real_sx = vp_playfield->x;
9415 int new_real_sy = vp_playfield->y;
9416 int new_full_sxsize = vp_playfield->width;
9417 int new_full_sysize = vp_playfield->height;
9418 int new_dx = vp_door_1->x;
9419 int new_dy = vp_door_1->y;
9420 int new_dxsize = vp_door_1->width;
9421 int new_dysize = vp_door_1->height;
9422 int new_vx = vp_door_2->x;
9423 int new_vy = vp_door_2->y;
9424 int new_vxsize = vp_door_2->width;
9425 int new_vysize = vp_door_2->height;
9427 boolean playfield_viewport_has_changed =
9428 (new_real_sx != REAL_SX ||
9429 new_real_sy != REAL_SY ||
9430 new_full_sxsize != FULL_SXSIZE ||
9431 new_full_sysize != FULL_SYSIZE);
9433 boolean door_1_viewport_has_changed =
9436 new_dxsize != DXSIZE ||
9437 new_dysize != DYSIZE);
9439 boolean door_2_viewport_has_changed =
9442 new_vxsize != VXSIZE ||
9443 new_vysize != VYSIZE ||
9444 game_status_last == GAME_MODE_EDITOR);
9446 return (playfield_viewport_has_changed &&
9447 door_1_viewport_has_changed &&
9448 door_2_viewport_has_changed);
9451 boolean CheckFadeAll(void)
9453 return (CheckIfGlobalBorderHasChanged() ||
9454 CheckIfAllViewportsHaveChanged());
9457 void ChangeViewportPropertiesIfNeeded(void)
9459 boolean use_mini_tilesize = (level.game_engine_type == GAME_ENGINE_TYPE_MM ?
9460 FALSE : setup.small_game_graphics);
9461 int gfx_game_mode = game_status;
9462 int gfx_game_mode2 = (game_status == GAME_MODE_EDITOR ? GAME_MODE_DEFAULT :
9464 struct RectWithBorder *vp_window = &viewport.window[gfx_game_mode];
9465 struct RectWithBorder *vp_playfield = &viewport.playfield[gfx_game_mode];
9466 struct RectWithBorder *vp_door_1 = &viewport.door_1[gfx_game_mode];
9467 struct RectWithBorder *vp_door_2 = &viewport.door_2[gfx_game_mode2];
9468 struct RectWithBorder *vp_door_3 = &viewport.door_2[GAME_MODE_EDITOR];
9469 int new_win_xsize = vp_window->width;
9470 int new_win_ysize = vp_window->height;
9471 int border_left = vp_playfield->border_left;
9472 int border_right = vp_playfield->border_right;
9473 int border_top = vp_playfield->border_top;
9474 int border_bottom = vp_playfield->border_bottom;
9475 int new_sx = vp_playfield->x + border_left;
9476 int new_sy = vp_playfield->y + border_top;
9477 int new_sxsize = vp_playfield->width - border_left - border_right;
9478 int new_sysize = vp_playfield->height - border_top - border_bottom;
9479 int new_real_sx = vp_playfield->x;
9480 int new_real_sy = vp_playfield->y;
9481 int new_full_sxsize = vp_playfield->width;
9482 int new_full_sysize = vp_playfield->height;
9483 int new_dx = vp_door_1->x;
9484 int new_dy = vp_door_1->y;
9485 int new_dxsize = vp_door_1->width;
9486 int new_dysize = vp_door_1->height;
9487 int new_vx = vp_door_2->x;
9488 int new_vy = vp_door_2->y;
9489 int new_vxsize = vp_door_2->width;
9490 int new_vysize = vp_door_2->height;
9491 int new_ex = vp_door_3->x;
9492 int new_ey = vp_door_3->y;
9493 int new_exsize = vp_door_3->width;
9494 int new_eysize = vp_door_3->height;
9495 int new_tilesize_var = (use_mini_tilesize ? MINI_TILESIZE : game.tile_size);
9496 int tilesize = (gfx_game_mode == GAME_MODE_PLAYING ? new_tilesize_var :
9497 gfx_game_mode == GAME_MODE_EDITOR ? MINI_TILESIZE : TILESIZE);
9498 int new_scr_fieldx = new_sxsize / tilesize;
9499 int new_scr_fieldy = new_sysize / tilesize;
9500 int new_scr_fieldx_buffers = new_sxsize / new_tilesize_var;
9501 int new_scr_fieldy_buffers = new_sysize / new_tilesize_var;
9502 boolean init_gfx_buffers = FALSE;
9503 boolean init_video_buffer = FALSE;
9504 boolean init_gadgets_and_anims = FALSE;
9505 boolean init_em_graphics = FALSE;
9507 if (new_win_xsize != WIN_XSIZE ||
9508 new_win_ysize != WIN_YSIZE)
9510 WIN_XSIZE = new_win_xsize;
9511 WIN_YSIZE = new_win_ysize;
9513 init_video_buffer = TRUE;
9514 init_gfx_buffers = TRUE;
9515 init_gadgets_and_anims = TRUE;
9517 // Debug("tools:viewport", "video: init_video_buffer, init_gfx_buffers");
9520 if (new_scr_fieldx != SCR_FIELDX ||
9521 new_scr_fieldy != SCR_FIELDY)
9523 // this always toggles between MAIN and GAME when using small tile size
9525 SCR_FIELDX = new_scr_fieldx;
9526 SCR_FIELDY = new_scr_fieldy;
9528 // Debug("tools:viewport", "new_scr_fieldx != SCR_FIELDX ...");
9539 new_sxsize != SXSIZE ||
9540 new_sysize != SYSIZE ||
9541 new_dxsize != DXSIZE ||
9542 new_dysize != DYSIZE ||
9543 new_vxsize != VXSIZE ||
9544 new_vysize != VYSIZE ||
9545 new_exsize != EXSIZE ||
9546 new_eysize != EYSIZE ||
9547 new_real_sx != REAL_SX ||
9548 new_real_sy != REAL_SY ||
9549 new_full_sxsize != FULL_SXSIZE ||
9550 new_full_sysize != FULL_SYSIZE ||
9551 new_tilesize_var != TILESIZE_VAR
9554 // ------------------------------------------------------------------------
9555 // determine next fading area for changed viewport definitions
9556 // ------------------------------------------------------------------------
9558 // start with current playfield area (default fading area)
9561 FADE_SXSIZE = FULL_SXSIZE;
9562 FADE_SYSIZE = FULL_SYSIZE;
9564 // add new playfield area if position or size has changed
9565 if (new_real_sx != REAL_SX || new_real_sy != REAL_SY ||
9566 new_full_sxsize != FULL_SXSIZE || new_full_sysize != FULL_SYSIZE)
9568 JoinRectangles(&FADE_SX, &FADE_SY, &FADE_SXSIZE, &FADE_SYSIZE,
9569 new_real_sx, new_real_sy, new_full_sxsize,new_full_sysize);
9572 // add current and new door 1 area if position or size has changed
9573 if (new_dx != DX || new_dy != DY ||
9574 new_dxsize != DXSIZE || new_dysize != DYSIZE)
9576 JoinRectangles(&FADE_SX, &FADE_SY, &FADE_SXSIZE, &FADE_SYSIZE,
9577 DX, DY, DXSIZE, DYSIZE);
9578 JoinRectangles(&FADE_SX, &FADE_SY, &FADE_SXSIZE, &FADE_SYSIZE,
9579 new_dx, new_dy, new_dxsize, new_dysize);
9582 // add current and new door 2 area if position or size has changed
9583 if (new_vx != VX || new_vy != VY ||
9584 new_vxsize != VXSIZE || new_vysize != VYSIZE)
9586 JoinRectangles(&FADE_SX, &FADE_SY, &FADE_SXSIZE, &FADE_SYSIZE,
9587 VX, VY, VXSIZE, VYSIZE);
9588 JoinRectangles(&FADE_SX, &FADE_SY, &FADE_SXSIZE, &FADE_SYSIZE,
9589 new_vx, new_vy, new_vxsize, new_vysize);
9592 // ------------------------------------------------------------------------
9593 // handle changed tile size
9594 // ------------------------------------------------------------------------
9596 if (new_tilesize_var != TILESIZE_VAR)
9598 // Debug("tools:viewport", "new_tilesize_var != TILESIZE_VAR");
9600 // changing tile size invalidates scroll values of engine snapshots
9601 FreeEngineSnapshotSingle();
9603 // changing tile size requires update of graphic mapping for EM engine
9604 init_em_graphics = TRUE;
9615 SXSIZE = new_sxsize;
9616 SYSIZE = new_sysize;
9617 DXSIZE = new_dxsize;
9618 DYSIZE = new_dysize;
9619 VXSIZE = new_vxsize;
9620 VYSIZE = new_vysize;
9621 EXSIZE = new_exsize;
9622 EYSIZE = new_eysize;
9623 REAL_SX = new_real_sx;
9624 REAL_SY = new_real_sy;
9625 FULL_SXSIZE = new_full_sxsize;
9626 FULL_SYSIZE = new_full_sysize;
9627 TILESIZE_VAR = new_tilesize_var;
9629 init_gfx_buffers = TRUE;
9630 init_gadgets_and_anims = TRUE;
9632 // Debug("tools:viewport", "viewports: init_gfx_buffers");
9633 // Debug("tools:viewport", "viewports: init_gadgets_and_anims");
9636 if (init_gfx_buffers)
9638 // Debug("tools:viewport", "init_gfx_buffers");
9640 SCR_FIELDX = new_scr_fieldx_buffers;
9641 SCR_FIELDY = new_scr_fieldy_buffers;
9645 SCR_FIELDX = new_scr_fieldx;
9646 SCR_FIELDY = new_scr_fieldy;
9648 SetDrawDeactivationMask(REDRAW_NONE);
9649 SetDrawBackgroundMask(REDRAW_FIELD);
9652 if (init_video_buffer)
9654 // Debug("tools:viewport", "init_video_buffer");
9656 FreeAllImageTextures(); // needs old renderer to free the textures
9658 InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen);
9659 InitImageTextures();
9662 if (init_gadgets_and_anims)
9664 // Debug("tools:viewport", "init_gadgets_and_anims");
9667 InitGlobalAnimations();
9670 if (init_em_graphics)
9672 InitGraphicInfo_EM();