-#if 0
- printf("::: %d: %d, %d [%d]\n",
- player_nr,
- stored_player[player_nr].Frame,
- stored_player[player_nr].StepFrame,
- FrameCounter);
-#endif
-}
-
-void InitGraphicInfo_EM(void)
-{
-#if 0
- struct Mapping_EM_to_RND_object object_mapping[TILE_MAX];
- struct Mapping_EM_to_RND_player player_mapping[MAX_PLAYERS][SPR_MAX];
-#endif
- int i, j, p;
-
-#if DEBUG_EM_GFX
- int num_em_gfx_errors = 0;
-
- if (graphic_info_em_object[0][0].bitmap == NULL)
- {
- /* EM graphics not yet initialized in em_open_all() */
-
- return;
- }
-
- printf("::: [4 errors can be ignored (1 x 'bomb', 3 x 'em_dynamite']\n");
-#endif
-
- /* always start with reliable default values */
- for (i = 0; i < TILE_MAX; i++)
- {
- object_mapping[i].element_rnd = EL_UNKNOWN;
- object_mapping[i].is_backside = FALSE;
- object_mapping[i].action = ACTION_DEFAULT;
- object_mapping[i].direction = MV_NONE;
- }
-
- /* always start with reliable default values */
- for (p = 0; p < MAX_PLAYERS; p++)
- {
- for (i = 0; i < SPR_MAX; i++)
- {
- player_mapping[p][i].element_rnd = EL_UNKNOWN;
- player_mapping[p][i].action = ACTION_DEFAULT;
- player_mapping[p][i].direction = MV_NONE;
- }
- }
-
- for (i = 0; em_object_mapping_list[i].element_em != -1; i++)
- {
- int e = em_object_mapping_list[i].element_em;
-
- object_mapping[e].element_rnd = em_object_mapping_list[i].element_rnd;
- object_mapping[e].is_backside = em_object_mapping_list[i].is_backside;
-
- if (em_object_mapping_list[i].action != -1)
- object_mapping[e].action = em_object_mapping_list[i].action;
-
- if (em_object_mapping_list[i].direction != -1)
- object_mapping[e].direction =
- MV_DIR_FROM_BIT(em_object_mapping_list[i].direction);
- }
-
- for (i = 0; em_player_mapping_list[i].action_em != -1; i++)
- {
- int a = em_player_mapping_list[i].action_em;
- int p = em_player_mapping_list[i].player_nr;
-
- player_mapping[p][a].element_rnd = em_player_mapping_list[i].element_rnd;
-
- if (em_player_mapping_list[i].action != -1)
- player_mapping[p][a].action = em_player_mapping_list[i].action;
-
- if (em_player_mapping_list[i].direction != -1)
- player_mapping[p][a].direction =
- MV_DIR_FROM_BIT(em_player_mapping_list[i].direction);
- }
-
- for (i = 0; i < TILE_MAX; i++)
- {
- int element = object_mapping[i].element_rnd;
- int action = object_mapping[i].action;
- int direction = object_mapping[i].direction;
- boolean is_backside = object_mapping[i].is_backside;
-#if 0
- boolean action_removing = (action == ACTION_DIGGING ||
- action == ACTION_SNAPPING ||
- action == ACTION_COLLECTING);
-#endif
- boolean action_exploding = ((action == ACTION_EXPLODING ||
- action == ACTION_SMASHED_BY_ROCK ||
- action == ACTION_SMASHED_BY_SPRING) &&
- element != EL_DIAMOND);
- boolean action_active = (action == ACTION_ACTIVE);
- boolean action_other = (action == ACTION_OTHER);
-
- for (j = 0; j < 8; j++)
- {
-#if 1
- int effective_element = get_effective_element_EM(i, j);
-#else
- int effective_element = (j > 5 && i == Yacid_splash_eB ? EL_EMPTY :
- j > 5 && i == Yacid_splash_wB ? EL_EMPTY :
- j < 7 ? element :
- i == Xdrip_stretch ? element :
- i == Xdrip_stretchB ? element :
- i == Ydrip_s1 ? element :
- i == Ydrip_s1B ? element :
- i == Xball_1B ? element :
- i == Xball_2 ? element :
- i == Xball_2B ? element :
- i == Yball_eat ? element :
- i == Ykey_1_eat ? element :
- i == Ykey_2_eat ? element :
- i == Ykey_3_eat ? element :
- i == Ykey_4_eat ? element :
- i == Ykey_5_eat ? element :
- i == Ykey_6_eat ? element :
- i == Ykey_7_eat ? element :
- i == Ykey_8_eat ? element :
- i == Ylenses_eat ? element :
- i == Ymagnify_eat ? element :
- i == Ygrass_eat ? element :
- i == Ydirt_eat ? element :
- i == Yemerald_stone ? EL_EMERALD :
- i == Ydiamond_stone ? EL_ROCK :
- i == Xsand_stonein_1 ? element :
- i == Xsand_stonein_2 ? element :
- i == Xsand_stonein_3 ? element :
- i == Xsand_stonein_4 ? element :
- is_backside ? EL_EMPTY :
- action_removing ? EL_EMPTY :
- element);
-#endif
- int effective_action = (j < 7 ? action :
- i == Xdrip_stretch ? action :
- i == Xdrip_stretchB ? action :
- i == Ydrip_s1 ? action :
- i == Ydrip_s1B ? action :
- i == Xball_1B ? action :
- i == Xball_2 ? action :
- i == Xball_2B ? action :
- i == Yball_eat ? action :
- i == Ykey_1_eat ? action :
- i == Ykey_2_eat ? action :
- i == Ykey_3_eat ? action :
- i == Ykey_4_eat ? action :
- i == Ykey_5_eat ? action :
- i == Ykey_6_eat ? action :
- i == Ykey_7_eat ? action :
- i == Ykey_8_eat ? action :
- i == Ylenses_eat ? action :
- i == Ymagnify_eat ? action :
- i == Ygrass_eat ? action :
- i == Ydirt_eat ? action :
- i == Xsand_stonein_1 ? action :
- i == Xsand_stonein_2 ? action :
- i == Xsand_stonein_3 ? action :
- i == Xsand_stonein_4 ? action :
- i == Xsand_stoneout_1 ? action :
- i == Xsand_stoneout_2 ? action :
- i == Xboom_android ? ACTION_EXPLODING :
- action_exploding ? ACTION_EXPLODING :
- action_active ? action :
- action_other ? action :
- ACTION_DEFAULT);
- int graphic = (el_act_dir2img(effective_element, effective_action,
- direction));
- int crumbled = (el_act_dir2crm(effective_element, effective_action,
- direction));
- int base_graphic = el_act2img(effective_element, ACTION_DEFAULT);
- int base_crumbled = el_act2crm(effective_element, ACTION_DEFAULT);
- boolean has_action_graphics = (graphic != base_graphic);
- boolean has_crumbled_graphics = (base_crumbled != base_graphic);
- struct GraphicInfo *g = &graphic_info[graphic];
-#if 0
- struct GraphicInfo *g_crumbled = &graphic_info[crumbled];
-#endif
- struct GraphicInfo_EM *g_em = &graphic_info_em_object[i][7 - j];
- Bitmap *src_bitmap;
- int src_x, src_y;
- /* ensure to get symmetric 3-frame, 2-delay animations as used in EM */
- boolean special_animation = (action != ACTION_DEFAULT &&
- g->anim_frames == 3 &&
- g->anim_delay == 2 &&
- g->anim_mode & ANIM_LINEAR);
- int sync_frame = (i == Xdrip_stretch ? 7 :
- i == Xdrip_stretchB ? 7 :
- i == Ydrip_s2 ? j + 8 :
- i == Ydrip_s2B ? j + 8 :
- i == Xacid_1 ? 0 :
- i == Xacid_2 ? 10 :
- i == Xacid_3 ? 20 :
- i == Xacid_4 ? 30 :
- i == Xacid_5 ? 40 :
- i == Xacid_6 ? 50 :
- i == Xacid_7 ? 60 :
- i == Xacid_8 ? 70 :
- i == Xfake_acid_1 ? 0 :
- i == Xfake_acid_2 ? 10 :
- i == Xfake_acid_3 ? 20 :
- i == Xfake_acid_4 ? 30 :
- i == Xfake_acid_5 ? 40 :
- i == Xfake_acid_6 ? 50 :
- i == Xfake_acid_7 ? 60 :
- i == Xfake_acid_8 ? 70 :
- i == Xball_2 ? 7 :
- i == Xball_2B ? j + 8 :
- i == Yball_eat ? j + 1 :
- i == Ykey_1_eat ? j + 1 :
- i == Ykey_2_eat ? j + 1 :
- i == Ykey_3_eat ? j + 1 :
- i == Ykey_4_eat ? j + 1 :
- i == Ykey_5_eat ? j + 1 :
- i == Ykey_6_eat ? j + 1 :
- i == Ykey_7_eat ? j + 1 :
- i == Ykey_8_eat ? j + 1 :
- i == Ylenses_eat ? j + 1 :
- i == Ymagnify_eat ? j + 1 :
- i == Ygrass_eat ? j + 1 :
- i == Ydirt_eat ? j + 1 :
- i == Xamoeba_1 ? 0 :
- i == Xamoeba_2 ? 1 :
- i == Xamoeba_3 ? 2 :
- i == Xamoeba_4 ? 3 :
- i == Xamoeba_5 ? 0 :
- i == Xamoeba_6 ? 1 :
- i == Xamoeba_7 ? 2 :
- i == Xamoeba_8 ? 3 :
- i == Xexit_2 ? j + 8 :
- i == Xexit_3 ? j + 16 :
- i == Xdynamite_1 ? 0 :
- i == Xdynamite_2 ? 8 :
- i == Xdynamite_3 ? 16 :
- i == Xdynamite_4 ? 24 :
- i == Xsand_stonein_1 ? j + 1 :
- i == Xsand_stonein_2 ? j + 9 :
- i == Xsand_stonein_3 ? j + 17 :
- i == Xsand_stonein_4 ? j + 25 :
- i == Xsand_stoneout_1 && j == 0 ? 0 :
- i == Xsand_stoneout_1 && j == 1 ? 0 :
- i == Xsand_stoneout_1 && j == 2 ? 1 :
- i == Xsand_stoneout_1 && j == 3 ? 2 :
- i == Xsand_stoneout_1 && j == 4 ? 2 :
- i == Xsand_stoneout_1 && j == 5 ? 3 :
- i == Xsand_stoneout_1 && j == 6 ? 4 :
- i == Xsand_stoneout_1 && j == 7 ? 4 :
- i == Xsand_stoneout_2 && j == 0 ? 5 :
- i == Xsand_stoneout_2 && j == 1 ? 6 :
- i == Xsand_stoneout_2 && j == 2 ? 7 :
- i == Xsand_stoneout_2 && j == 3 ? 8 :
- i == Xsand_stoneout_2 && j == 4 ? 9 :
- i == Xsand_stoneout_2 && j == 5 ? 11 :
- i == Xsand_stoneout_2 && j == 6 ? 13 :
- i == Xsand_stoneout_2 && j == 7 ? 15 :
- i == Xboom_bug && j == 1 ? 2 :
- i == Xboom_bug && j == 2 ? 2 :
- i == Xboom_bug && j == 3 ? 4 :
- i == Xboom_bug && j == 4 ? 4 :
- i == Xboom_bug && j == 5 ? 2 :
- i == Xboom_bug && j == 6 ? 2 :
- i == Xboom_bug && j == 7 ? 0 :
- i == Xboom_bomb && j == 1 ? 2 :
- i == Xboom_bomb && j == 2 ? 2 :
- i == Xboom_bomb && j == 3 ? 4 :
- i == Xboom_bomb && j == 4 ? 4 :
- i == Xboom_bomb && j == 5 ? 2 :
- i == Xboom_bomb && j == 6 ? 2 :
- i == Xboom_bomb && j == 7 ? 0 :
- i == Xboom_android && j == 7 ? 6 :
- i == Xboom_1 && j == 1 ? 2 :
- i == Xboom_1 && j == 2 ? 2 :
- i == Xboom_1 && j == 3 ? 4 :
- i == Xboom_1 && j == 4 ? 4 :
- i == Xboom_1 && j == 5 ? 6 :
- i == Xboom_1 && j == 6 ? 6 :
- i == Xboom_1 && j == 7 ? 8 :
- i == Xboom_2 && j == 0 ? 8 :
- i == Xboom_2 && j == 1 ? 8 :
- i == Xboom_2 && j == 2 ? 10 :
- i == Xboom_2 && j == 3 ? 10 :
- i == Xboom_2 && j == 4 ? 10 :
- i == Xboom_2 && j == 5 ? 12 :
- i == Xboom_2 && j == 6 ? 12 :
- i == Xboom_2 && j == 7 ? 12 :
- special_animation && j == 4 ? 3 :
- effective_action != action ? 0 :
- j);
-
-#if DEBUG_EM_GFX
- Bitmap *debug_bitmap = g_em->bitmap;
- int debug_src_x = g_em->src_x;
- int debug_src_y = g_em->src_y;
-#endif
-
- int frame = getAnimationFrame(g->anim_frames,
- g->anim_delay,
- g->anim_mode,
- g->anim_start_frame,
- sync_frame);
-
- getGraphicSourceExt(graphic, frame, &src_bitmap, &src_x, &src_y,
- g->double_movement && is_backside);
-
- g_em->bitmap = src_bitmap;
- g_em->src_x = src_x;
- g_em->src_y = src_y;
- g_em->src_offset_x = 0;
- g_em->src_offset_y = 0;
- g_em->dst_offset_x = 0;
- g_em->dst_offset_y = 0;
- g_em->width = TILEX;
- g_em->height = TILEY;
-
- g_em->preserve_background = FALSE;
-
-#if 1
- set_crumbled_graphics_EM(g_em, has_crumbled_graphics, crumbled,
- sync_frame);
-
-#else
-
- g_em->crumbled_bitmap = NULL;
- g_em->crumbled_src_x = 0;
- g_em->crumbled_src_y = 0;
- g_em->crumbled_border_size = 0;
-
- g_em->has_crumbled_graphics = FALSE;
-
-#if 0
- if (has_crumbled_graphics && crumbled == IMG_EMPTY_SPACE)
- printf("::: empty crumbled: %d [%s], %d, %d\n",
- effective_element, element_info[effective_element].token_name,
- effective_action, direction);
-#endif
-
- /* if element can be crumbled, but certain action graphics are just empty
- space (like instantly snapping sand to empty space in 1 frame), do not
- treat these empty space graphics as crumbled graphics in EMC engine */
- if (has_crumbled_graphics && crumbled != IMG_EMPTY_SPACE)
- {
- int frame_crumbled = getAnimationFrame(g_crumbled->anim_frames,
- g_crumbled->anim_delay,
- g_crumbled->anim_mode,
- g_crumbled->anim_start_frame,
- sync_frame);
-
- getGraphicSource(crumbled, frame_crumbled, &src_bitmap, &src_x, &src_y);
-
- g_em->has_crumbled_graphics = TRUE;
- g_em->crumbled_bitmap = src_bitmap;
- g_em->crumbled_src_x = src_x;
- g_em->crumbled_src_y = src_y;
- g_em->crumbled_border_size = graphic_info[crumbled].border_size;
-
-
-#if 0
- if (g_em == &graphic_info_em_object[207][0])
- printf("... %d, %d [%d, %d, %d, %d] [%d, %d, %d, %d, %d, %d => %d]\n",
- graphic_info_em_object[207][0].crumbled_src_x,
- graphic_info_em_object[207][0].crumbled_src_y,
-
- crumbled, frame, src_x, src_y,
-
- g->anim_frames,
- g->anim_delay,
- g->anim_mode,
- g->anim_start_frame,
- sync_frame,
- gfx.anim_random_frame,
- frame);
-#endif
-
-#if 0
- printf("::: EMC tile %d is crumbled\n", i);
-#endif
- }
-#endif
-
-#if 0
- if (element == EL_ROCK &&
- effective_action == ACTION_FILLING)
- printf("::: has_action_graphics == %d\n", has_action_graphics);
-#endif
-
- if ((!g->double_movement && (effective_action == ACTION_FALLING ||
- effective_action == ACTION_MOVING ||
- effective_action == ACTION_PUSHING ||
- effective_action == ACTION_EATING)) ||
- (!has_action_graphics && (effective_action == ACTION_FILLING ||
- effective_action == ACTION_EMPTYING)))
- {
- int move_dir =
- (effective_action == ACTION_FALLING ||
- effective_action == ACTION_FILLING ||
- effective_action == ACTION_EMPTYING ? MV_DOWN : direction);
- int dx = (move_dir == MV_LEFT ? -1 : move_dir == MV_RIGHT ? 1 : 0);
- int dy = (move_dir == MV_UP ? -1 : move_dir == MV_DOWN ? 1 : 0);
- int num_steps = (i == Ydrip_s1 ? 16 :
- i == Ydrip_s1B ? 16 :
- i == Ydrip_s2 ? 16 :
- i == Ydrip_s2B ? 16 :
- i == Xsand_stonein_1 ? 32 :
- i == Xsand_stonein_2 ? 32 :
- i == Xsand_stonein_3 ? 32 :
- i == Xsand_stonein_4 ? 32 :
- i == Xsand_stoneout_1 ? 16 :
- i == Xsand_stoneout_2 ? 16 : 8);
- int cx = ABS(dx) * (TILEX / num_steps);
- int cy = ABS(dy) * (TILEY / num_steps);
- int step_frame = (i == Ydrip_s2 ? j + 8 :
- i == Ydrip_s2B ? j + 8 :
- i == Xsand_stonein_2 ? j + 8 :
- i == Xsand_stonein_3 ? j + 16 :
- i == Xsand_stonein_4 ? j + 24 :
- i == Xsand_stoneout_2 ? j + 8 : j) + 1;
- int step = (is_backside ? step_frame : num_steps - step_frame);
-
- if (is_backside) /* tile where movement starts */
- {
- if (dx < 0 || dy < 0)
- {
- g_em->src_offset_x = cx * step;
- g_em->src_offset_y = cy * step;
- }
- else
- {
- g_em->dst_offset_x = cx * step;
- g_em->dst_offset_y = cy * step;
- }
- }
- else /* tile where movement ends */
- {
- if (dx < 0 || dy < 0)
- {
- g_em->dst_offset_x = cx * step;
- g_em->dst_offset_y = cy * step;
- }
- else
- {
- g_em->src_offset_x = cx * step;
- g_em->src_offset_y = cy * step;
- }
- }
-
- g_em->width = TILEX - cx * step;
- g_em->height = TILEY - cy * step;
- }
-
- /* create unique graphic identifier to decide if tile must be redrawn */
- /* bit 31 - 16 (16 bit): EM style graphic
- bit 15 - 12 ( 4 bit): EM style frame
- bit 11 - 6 ( 6 bit): graphic width
- bit 5 - 0 ( 6 bit): graphic height */
- g_em->unique_identifier =
- (graphic << 16) | (frame << 12) | (g_em->width << 6) | g_em->height;
-
-#if DEBUG_EM_GFX
-
- /* skip check for EMC elements not contained in original EMC artwork */
- if (element == EL_EMC_FAKE_ACID)
- continue;
-
- if (g_em->bitmap != debug_bitmap ||
- g_em->src_x != debug_src_x ||
- g_em->src_y != debug_src_y ||
- g_em->src_offset_x != 0 ||
- g_em->src_offset_y != 0 ||
- g_em->dst_offset_x != 0 ||
- g_em->dst_offset_y != 0 ||
- g_em->width != TILEX ||
- g_em->height != TILEY)