+
+void gd_prepare_tile_bitmap(GdCave *cave, Bitmap *bitmap, int scale_down_factor)
+{
+ static SDL_Surface *tile_surface_c64 = NULL;
+ static Bitmap *gd_tile_bitmap_original = NULL;
+ static int scale_down_factor_last = -1;
+
+ if (program.headless)
+ return;
+
+ // check if tile bitmap has changed (different artwork or tile size selected)
+ if (bitmap != gd_tile_bitmap_original || scale_down_factor != scale_down_factor_last)
+ {
+ // check if tile bitmap has limited C64 style colors
+ tile_surface_c64 = get_tile_surface_c64(bitmap->surface, scale_down_factor);
+
+ // store original tile bitmap from current artwork set and scaling factor
+ gd_tile_bitmap_original = bitmap;
+ scale_down_factor_last = scale_down_factor;
+
+ // store reference tile bitmap from current artwork set (may be changed later)
+ gd_tile_bitmap_reference = bitmap;
+ }
+
+ // check if tile bitmap should be colored for next game
+ if (tile_surface_c64 != NULL)
+ {
+ // set tile bitmap to bitmap with level-specific colors
+ gd_tile_bitmap = get_tile_bitmap_c64(cave, tile_surface_c64);
+ }
+ else
+ {
+ // no special tile bitmap available for this artwork set
+ gd_tile_bitmap = NULL;
+ }
+}
+
+void gd_set_tile_bitmap_reference(Bitmap *bitmap)
+{
+ gd_tile_bitmap_reference = bitmap;
+}
+
+Bitmap *gd_get_tile_bitmap(Bitmap *bitmap)
+{
+ // if no special tile bitmap available, keep using default tile bitmap
+ if (gd_tile_bitmap == NULL)
+ return bitmap;
+
+ // if default bitmap refers to tile bitmap, use special tile bitmap
+ if (bitmap == gd_tile_bitmap_reference)
+ return gd_tile_bitmap;
+
+ return bitmap;
+}
+
+// returns true if the element is a player
+static inline boolean el_player(const int element)
+{
+ return (gd_elements[element & O_MASK].properties & P_PLAYER) != 0;
+}
+
+// returns true if the element is diggable
+static inline boolean el_diggable(const int element)
+{
+ return (gd_elements[element & O_MASK].properties & P_DIGGABLE) != 0;
+}
+
+#if 0
+// returns true if the element is collectible
+static inline boolean el_collectible(const int element)
+{
+ return (gd_elements[element & O_MASK].properties & P_COLLECTIBLE) != 0;
+}
+#endif
+
+// returns true if the element is pushable
+static inline boolean el_pushable(const int element)
+{
+ return (gd_elements[element & O_MASK].properties & P_PUSHABLE) != 0;
+}
+
+// returns true if the element can move
+static inline boolean el_can_move(const int element)
+{
+ return (gd_elements[element & O_MASK].properties & P_CAN_MOVE) != 0;
+}
+
+// returns true if the element can fall
+static inline boolean el_falling(const int element)
+{
+ return (gd_elements[element & O_MASK].properties & P_FALLING) != 0;
+}
+
+// returns true if the element is growing
+static inline boolean el_growing(const int element)
+{
+ return (gd_elements[element & O_MASK].properties & P_GROWING) != 0;
+}
+
+// returns true if the element is exploding
+static inline boolean el_explosion(const int element)
+{
+ return (gd_elements[element & O_MASK].properties & P_EXPLOSION) != 0;
+}
+
+static void gd_drawcave_tile(Bitmap *dest, GdGame *game, int x, int y, boolean draw_masked)
+{
+ void (*blit_bitmap)(Bitmap *, Bitmap *, int, int, int, int, int, int) =
+ (draw_masked ? BlitBitmapMasked : BlitBitmap);
+ GdCave *cave = game->cave;
+ int sx = x * cell_size - scroll_x;
+ int sy = y * cell_size - scroll_y;
+ int dir = game->dir_buffer[y][x];
+ int tile = game->element_buffer[y][x];
+ int frame = game->animcycle;
+ struct GraphicInfo_BD *g = &graphic_info_bd_object[tile][frame];
+ Bitmap *tile_bitmap = gd_get_tile_bitmap(g->bitmap);
+ boolean is_movable = (el_can_move(tile) || el_falling(tile) || el_pushable(tile) ||
+ el_player(tile));
+ boolean is_movable_or_diggable = (is_movable || el_diggable(game->last_element_buffer[y][x]));
+ boolean is_moving = (is_movable_or_diggable && dir != GD_MV_STILL);
+ boolean use_smooth_movements = use_bd_smooth_movements();
+
+ // do not use smooth movement animation for growing or exploding game elements
+ if ((el_growing(tile) || el_explosion(tile)) && dir != GD_MV_STILL)
+ {
+ int dx = (dir == GD_MV_LEFT ? +1 : dir == GD_MV_RIGHT ? -1 : 0);
+ int dy = (dir == GD_MV_UP ? +1 : dir == GD_MV_DOWN ? -1 : 0);
+ int old_x = cave->getx(cave, x + dx, y + dy);
+ int old_y = cave->gety(cave, x + dx, y + dy);
+ int last_tile_from = game->last_element_buffer[old_y][old_x] & ~SKIPPED;
+ boolean old_is_player = el_player(last_tile_from);
+
+ // check special case of player running into enemy from top or left side
+ if (old_is_player)
+ {
+ game->element_buffer[y][x] = (dir == GD_MV_LEFT ? O_PLAYER_LEFT :
+ dir == GD_MV_RIGHT ? O_PLAYER_RIGHT :
+ dir == GD_MV_UP ? O_PLAYER_UP :
+ dir == GD_MV_DOWN ? O_PLAYER_DOWN : O_PLAYER);
+
+ // draw player running into explosion (else player would disappear immediately)
+ gd_drawcave_tile(dest, game, x, y, draw_masked);
+
+ game->element_buffer[y][x] = tile;
+ }
+
+ use_smooth_movements = FALSE;
+ }
+
+ // do not use smooth movement animation for player entering exit (engine stopped)
+ if (cave->player_state == GD_PL_EXITED)
+ use_smooth_movements = FALSE;
+
+ // do not use smooth movement animation for player stirring the pot
+ if (tile == O_PLAYER_STIRRING)
+ use_smooth_movements = FALSE;
+
+#if DO_GFX_SANITY_CHECK
+ if (use_native_bd_graphics_engine() && !setup.small_game_graphics && !program.headless)
+ {
+ int old_x = (game->gfx_buffer[y][x] % GD_NUM_OF_CELLS) % GD_NUM_OF_CELLS_X;
+ int old_y = (game->gfx_buffer[y][x] % GD_NUM_OF_CELLS) / GD_NUM_OF_CELLS_X;
+ int new_x = g->src_x / g->width;
+ int new_y = g->src_y / g->height;
+
+ if (new_x != old_x || new_y != old_y)
+ {
+ printf("::: BAD ANIMATION FOR TILE %d, FRAME %d [NEW(%d, %d) != OLD(%d, %d)] ['%s']\n",
+ tile, frame,
+ new_x, new_y,
+ old_x, old_y,
+ gd_elements[tile].name);
+ }
+ }