+
+void InitGraphicsInfoEM(void)
+{
+ int mapping_EM_to_RND_element[TILE_MAX];
+ int mapping_EM_to_RND_action[TILE_MAX];
+ int mapping_EM_to_RND_direction[TILE_MAX];
+ boolean mapping_EM_to_RND_backside[TILE_MAX];
+ int i, j;
+
+ /* return "EL_UNKNOWN" for all undefined elements in mapping array */
+ for (i = 0; i < TILE_MAX; i++)
+ {
+ mapping_EM_to_RND_element[i] = EL_UNKNOWN;
+ mapping_EM_to_RND_backside[i] = FALSE;
+ mapping_EM_to_RND_action[i] = ACTION_DEFAULT;
+ mapping_EM_to_RND_direction[i] = MV_NO_MOVING;
+ }
+
+ for (i = 0; mapping_EM_to_RND_list[i].element_em != -1; i++)
+ {
+ int e = mapping_EM_to_RND_list[i].element_em;
+
+ mapping_EM_to_RND_element[e] = mapping_EM_to_RND_list[i].element_rnd;
+ mapping_EM_to_RND_backside[e] = mapping_EM_to_RND_list[i].is_backside;
+
+ if (mapping_EM_to_RND_list[i].action != -1)
+ mapping_EM_to_RND_action[e] = mapping_EM_to_RND_list[i].action;
+
+ if (mapping_EM_to_RND_list[i].direction != -1)
+ mapping_EM_to_RND_direction[e] = 1<< mapping_EM_to_RND_list[i].direction;
+ }
+
+ for (i = 0; i < TILE_MAX; i++)
+ {
+ int element = mapping_EM_to_RND_element[i];
+ int action = mapping_EM_to_RND_action[i];
+ int direction = mapping_EM_to_RND_direction[i];
+ int backside = mapping_EM_to_RND_backside[i];
+ boolean action_removing = (action == ACTION_DIGGING ||
+ action == ACTION_SNAPPING ||
+ action == ACTION_COLLECTING);
+ 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++)
+ {
+ int effective_element = (j < 7 ? element :
+ i == Ynut_sB ? 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 == Yspring_kill_e ? EL_SPRING :
+ i == Yspring_kill_w ? EL_SPRING :
+ i == Yemerald_stone ? EL_EMERALD :
+ i == Ydiamond_stone ? EL_ROCK :
+ backside ? EL_EMPTY :
+ action_removing ? EL_EMPTY :
+ element);
+ int effective_action = (j < 7 ? action :
+ i == Ynut_sB ? 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 == 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 = (direction == MV_NO_MOVING ?
+ el_act2img(effective_element, effective_action) :
+ el_act_dir2img(effective_element, effective_action,
+ direction));
+ struct GraphicInfo *g = &graphic_info[graphic];
+ struct GraphicInfo_EM *g_em = &graphic_info_em[i][7 - j];
+ Bitmap *src_bitmap;
+ int src_x, src_y;
+ 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 ? 1 :
+ i == Xacid_3 ? 2 :
+ i == Xacid_4 ? 3 :
+ i == Xacid_5 ? 4 :
+ i == Xacid_6 ? 5 :
+ i == Xacid_7 ? 6 :
+ i == Xacid_8 ? 7 :
+ i == Xball_2 ? 7 :
+ i == Xball_2B ? j + 8 :
+ i == Yball_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 ? 2 :
+ i == Xdynamite_3 ? 4 :
+ i == Xdynamite_4 ? 6 :
+ 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 ? 1 :
+ i == Xsand_stoneout_1 && j == 1 ? 1 :
+ i == Xsand_stoneout_1 && j == 2 ? 2 :
+ i == Xsand_stoneout_1 && j == 3 ? 4 :
+ i == Xsand_stoneout_1 && j == 4 ? 4 :
+ i == Xsand_stoneout_1 && j == 5 ? 6 :
+ i == Xsand_stoneout_1 && j == 6 ? 8 :
+ i == Xsand_stoneout_1 && j == 7 ? 8 :
+ i == Xsand_stoneout_2 && j == 0 ? 10 :
+ i == Xsand_stoneout_2 && j == 1 ? 12 :
+ i == Xsand_stoneout_2 && j == 2 ? 14 :
+ i == Xsand_stoneout_2 && j == 3 ? 16 :
+ i == Xsand_stoneout_2 && j == 4 ? 18 :
+ i == Xsand_stoneout_2 && j == 5 ? 22 :
+ i == Xsand_stoneout_2 && j == 6 ? 26 :
+ i == Xsand_stoneout_2 && j == 7 ? 30 :
+ i == Xboom_bug && j == 2 ? 1 :
+ i == Xboom_bug && j == 3 ? 2 :
+ i == Xboom_bug && j == 4 ? 2 :
+ i == Xboom_bug && j == 5 ? 1 :
+ i == Xboom_bug && j == 6 ? 1 :
+ i == Xboom_bug && j == 7 ? 0 :
+ i == Xboom_bomb && j == 2 ? 1 :
+ i == Xboom_bomb && j == 3 ? 2 :
+ i == Xboom_bomb && j == 4 ? 2 :
+ i == Xboom_bomb && j == 5 ? 1 :
+ i == Xboom_bomb && j == 6 ? 1 :
+ i == Xboom_bomb && j == 7 ? 0 :
+ i == Xboom_android && j == 7 ? 3 :
+ i == Xboom_1 && j == 2 ? 1 :
+ i == Xboom_1 && j == 3 ? 2 :
+ i == Xboom_1 && j == 4 ? 2 :
+ i == Xboom_1 && j == 5 ? 3 :
+ i == Xboom_1 && j == 6 ? 3 :
+ i == Xboom_1 && j == 7 ? 4 :
+ i == Xboom_2 && j == 0 ? 4 :
+ i == Xboom_2 && j == 1 ? 4 :
+ i == Xboom_2 && j == 2 ? 5 :
+ i == Xboom_2 && j == 3 ? 5 :
+ i == Xboom_2 && j == 4 ? 5 :
+ i == Xboom_2 && j == 5 ? 6 :
+ effective_action != action ? 0 :
+ j);
+#if 1
+ 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 && backside);
+
+#if 1
+ 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;
+#endif
+
+#if 1
+ if (!g->double_movement && (effective_action == ACTION_FALLING ||
+ effective_action == ACTION_MOVING ||
+ effective_action == ACTION_PUSHING))
+ {
+ int move_dir =
+ (effective_action == ACTION_FALLING ? 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 cx = ABS(dx) * TILEX / 8;
+ int cy = ABS(dy) * TILEY / 8;
+
+#if 0
+ if (i == Yemerald_sB)
+ printf("::: %d: ...\n", j);
+#endif
+
+ if (backside) /* tile where movement starts */
+ {
+ if (dx < 0 || dy < 0)
+ {
+ g_em->src_offset_x = cx * (j + 1);
+ g_em->src_offset_y = cy * (j + 1);
+ }
+ else
+ {
+ g_em->dst_offset_x = cx * (j + 1);
+ g_em->dst_offset_y = cy * (j + 1);
+ }
+
+ g_em->width = TILEX - cx * (j + 1);
+ g_em->height = TILEY - cy * (j + 1);
+ }
+ else /* tile where movement ends */
+ {
+ if (dx < 0 || dy < 0)
+ {
+ g_em->dst_offset_x = cx * (7 - j);
+ g_em->dst_offset_y = cy * (7 - j);
+ }
+ else
+ {
+ g_em->src_offset_x = cx * (7 - j);
+ g_em->src_offset_y = cy * (7 - j);
+ }
+
+ g_em->width = TILEX - cx * (7 - j);
+ g_em->height = TILEY - cy * (7 - j);
+ }
+ }
+#endif
+
+#if 0
+ 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)
+ {
+ static int last_i = -1;
+
+ if (i != last_i)
+ {
+ printf("\n");
+
+ last_i = i;
+ }
+
+ printf("::: EMC GFX ERROR for element %d -> %d ('%s')",
+ i, element, element_info[element].token_name);
+
+ if (element != effective_element)
+ printf(" [%d ('%s')]",
+ effective_element,element_info[effective_element].token_name);
+
+ printf("\n");
+
+ if (g_em->bitmap != debug_bitmap)
+ printf(" %d(%d): different bitmap!\n",
+ j, backside);
+
+ if (g_em->src_x != debug_src_x ||
+ g_em->src_y != debug_src_y)
+ printf(" frame %d (%c): %d,%d (%d,%d) should be %d,%d (%d,%d)\n",
+ j, (backside ? 'B' : 'F'),
+ g_em->src_x, g_em->src_y,
+ g_em->src_x / 32, g_em->src_y / 32,
+ debug_src_x, debug_src_y,
+ debug_src_x / 32, debug_src_y / 32);
+
+ if (g_em->src_offset_x != 0 ||
+ g_em->src_offset_y != 0 ||
+ g_em->dst_offset_x != 0 ||
+ g_em->dst_offset_y != 0)
+ printf(" %d(%d): offsets %d,%d and %d,%d should be all 0\n",
+ j, backside,
+ g_em->src_offset_x, g_em->src_offset_y,
+ g_em->dst_offset_x, g_em->dst_offset_y);
+
+ if (g_em->width != TILEX ||
+ g_em->height != TILEY)
+ printf(" %d(%d): size %d,%d should be %d,%d\n",
+ j, backside,
+ g_em->width, g_em->height, TILEX, TILEY);
+ }
+#endif
+
+ }
+ }
+
+#if 0
+ exit(0);
+#endif
+}