+ return -1;
+}
+
+static int get_scaled_graphic_width(int graphic)
+{
+ int original_width = getOriginalImageWidthFromImageID(graphic);
+ int scale_up_factor = graphic_info[graphic].scale_up_factor;
+
+ return original_width * scale_up_factor;
+}
+
+static int get_scaled_graphic_height(int graphic)
+{
+ int original_height = getOriginalImageHeightFromImageID(graphic);
+ int scale_up_factor = graphic_info[graphic].scale_up_factor;
+
+ return original_height * scale_up_factor;
+}
+
+static void set_graphic_parameters_ext(int graphic, int *parameter,
+ Bitmap **src_bitmaps)
+{
+ struct GraphicInfo *g = &graphic_info[graphic];
+ Bitmap *src_bitmap = (src_bitmaps ? src_bitmaps[IMG_BITMAP_STANDARD] : NULL);
+ int anim_frames_per_row = 1, anim_frames_per_col = 1;
+ int anim_frames_per_line = 1;
+
+ /* always start with reliable default values */
+ g->src_image_width = 0;
+ g->src_image_height = 0;
+ g->src_x = 0;
+ g->src_y = 0;
+ g->width = TILEX; /* default for element graphics */
+ g->height = TILEY; /* default for element graphics */
+ g->offset_x = 0; /* one or both of these values ... */
+ g->offset_y = 0; /* ... will be corrected later */
+ g->offset2_x = 0; /* one or both of these values ... */
+ g->offset2_y = 0; /* ... will be corrected later */
+ g->swap_double_tiles = -1; /* auto-detect tile swapping */
+ g->crumbled_like = -1; /* do not use clone element */
+ g->diggable_like = -1; /* do not use clone element */
+ g->border_size = TILEX / 8; /* "CRUMBLED" border size */
+ g->scale_up_factor = 1; /* default: no scaling up */
+ g->tile_size = TILESIZE; /* default: standard tile size */
+ g->clone_from = -1; /* do not use clone graphic */
+ g->anim_delay_fixed = 0;
+ g->anim_delay_random = 0;
+ g->post_delay_fixed = 0;
+ g->post_delay_random = 0;
+ g->fade_mode = FADE_MODE_DEFAULT;
+ g->fade_delay = -1;
+ g->post_delay = -1;
+ g->auto_delay = -1;
+ g->align = ALIGN_CENTER; /* default for title screens */
+ g->valign = VALIGN_MIDDLE; /* default for title screens */
+ g->sort_priority = 0; /* default for title screens */
+ g->class = 0;
+ g->style = STYLE_DEFAULT;
+
+ g->bitmaps = src_bitmaps;
+ g->bitmap = src_bitmap;
+
+ /* optional zoom factor for scaling up the image to a larger size */
+ if (parameter[GFX_ARG_SCALE_UP_FACTOR] != ARG_UNDEFINED_VALUE)
+ g->scale_up_factor = parameter[GFX_ARG_SCALE_UP_FACTOR];
+ if (g->scale_up_factor < 1)
+ g->scale_up_factor = 1; /* no scaling */
+
+ /* optional tile size for using non-standard image size */
+ if (parameter[GFX_ARG_TILE_SIZE] != ARG_UNDEFINED_VALUE)
+ {
+ g->tile_size = parameter[GFX_ARG_TILE_SIZE];
+
+#if 0
+ // CHECK: should tile sizes less than standard tile size be allowed?
+ if (g->tile_size < TILESIZE)
+ g->tile_size = TILESIZE; /* standard tile size */
+#endif
+
+#if 0
+ // CHECK: when setting tile size, should this set width and height?
+ g->width = g->tile_size;
+ g->height = g->tile_size;
+#endif
+ }
+
+ if (g->use_image_size)
+ {
+ /* set new default bitmap size (with scaling, but without small images) */
+ g->width = get_scaled_graphic_width(graphic);
+ g->height = get_scaled_graphic_height(graphic);
+ }
+
+ /* optional width and height of each animation frame */
+ if (parameter[GFX_ARG_WIDTH] != ARG_UNDEFINED_VALUE)
+ g->width = parameter[GFX_ARG_WIDTH];
+ if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE)
+ g->height = parameter[GFX_ARG_HEIGHT];
+
+ /* optional x and y tile position of animation frame sequence */
+ if (parameter[GFX_ARG_XPOS] != ARG_UNDEFINED_VALUE)
+ g->src_x = parameter[GFX_ARG_XPOS] * g->width;
+ if (parameter[GFX_ARG_YPOS] != ARG_UNDEFINED_VALUE)
+ g->src_y = parameter[GFX_ARG_YPOS] * g->height;
+
+ /* optional x and y pixel position of animation frame sequence */
+ if (parameter[GFX_ARG_X] != ARG_UNDEFINED_VALUE)
+ g->src_x = parameter[GFX_ARG_X];
+ if (parameter[GFX_ARG_Y] != ARG_UNDEFINED_VALUE)
+ g->src_y = parameter[GFX_ARG_Y];
+
+ if (src_bitmap)
+ {
+ if (g->width <= 0)
+ {
+ Error(ERR_INFO_LINE, "-");
+ Error(ERR_WARN, "invalid value %d for '%s.width' (fallback done to %d)",
+ g->width, getTokenFromImageID(graphic), TILEX);
+ Error(ERR_INFO_LINE, "-");
+
+ g->width = TILEX; /* will be checked to be inside bitmap later */
+ }
+
+ if (g->height <= 0)
+ {
+ Error(ERR_INFO_LINE, "-");
+ Error(ERR_WARN, "invalid value %d for '%s.height' (fallback done to %d)",
+ g->height, getTokenFromImageID(graphic), TILEY);
+ Error(ERR_INFO_LINE, "-");
+
+ g->height = TILEY; /* will be checked to be inside bitmap later */
+ }
+ }
+
+ if (src_bitmap)
+ {
+ /* get final bitmap size (with scaling, but without small images) */
+ int src_image_width = get_scaled_graphic_width(graphic);
+ int src_image_height = get_scaled_graphic_height(graphic);
+
+ if (src_image_width == 0 || src_image_height == 0)
+ {
+ /* only happens when loaded outside artwork system (like "global.busy") */
+ src_image_width = src_bitmap->width;
+ src_image_height = src_bitmap->height;
+ }
+
+ if (parameter[GFX_ARG_TILE_SIZE] != ARG_UNDEFINED_VALUE)
+ {
+ anim_frames_per_row = src_image_width / g->tile_size;
+ anim_frames_per_col = src_image_height / g->tile_size;
+ }
+ else
+ {
+ anim_frames_per_row = src_image_width / g->width;
+ anim_frames_per_col = src_image_height / g->height;
+ }
+
+ g->src_image_width = src_image_width;
+ g->src_image_height = src_image_height;
+ }
+
+ /* correct x or y offset dependent of vertical or horizontal frame order */
+ if (parameter[GFX_ARG_VERTICAL]) /* frames are ordered vertically */
+ {
+ g->offset_y = (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE ?
+ parameter[GFX_ARG_OFFSET] : g->height);
+ anim_frames_per_line = anim_frames_per_col;
+ }
+ else /* frames are ordered horizontally */
+ {
+ g->offset_x = (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE ?
+ parameter[GFX_ARG_OFFSET] : g->width);