+static void set_graphic_parameters(int graphic, int action, int *parameter)
+{
+ Bitmap *src_bitmap = getBitmapFromImageID(graphic);
+ int num_xtiles = (src_bitmap ? src_bitmap->width : TILEX) / TILEX;
+ int num_ytiles = (src_bitmap ? src_bitmap->height * 2 / 3 : TILEY) / TILEY;
+
+ graphic_info[graphic].bitmap = src_bitmap;
+
+ graphic_info[graphic].src_x = parameter[GFX_ARG_XPOS] * TILEX;
+ graphic_info[graphic].src_y = parameter[GFX_ARG_YPOS] * TILEY;
+ graphic_info[graphic].offset_x = parameter[GFX_ARG_OFFSET];
+ graphic_info[graphic].offset_y = 0;
+
+ /* animation frames are ordered vertically instead of horizontally */
+ if (parameter[GFX_ARG_VERTICAL])
+ {
+ graphic_info[graphic].offset_x = 0;
+ graphic_info[graphic].offset_y = parameter[GFX_ARG_OFFSET];
+ }
+
+ /* optionally, the x and y offset of frames can be specified directly */
+ if (parameter[GFX_ARG_XOFFSET] != ARG_UNDEFINED_VALUE)
+ graphic_info[graphic].offset_x = parameter[GFX_ARG_XOFFSET];
+ if (parameter[GFX_ARG_YOFFSET] != ARG_UNDEFINED_VALUE)
+ graphic_info[graphic].offset_y = parameter[GFX_ARG_YOFFSET];
+
+ /* automatically determine correct number of frames, if not defined */
+ if (parameter[GFX_ARG_FRAMES] != ARG_UNDEFINED_VALUE)
+ graphic_info[graphic].anim_frames = parameter[GFX_ARG_FRAMES];
+ else if (parameter[GFX_ARG_XPOS] == 0 && !parameter[GFX_ARG_VERTICAL])
+ graphic_info[graphic].anim_frames = num_xtiles;
+ else if (parameter[GFX_ARG_YPOS] == 0 && parameter[GFX_ARG_VERTICAL])
+ graphic_info[graphic].anim_frames = num_ytiles;
+ else
+ graphic_info[graphic].anim_frames = 1;
+
+ graphic_info[graphic].anim_delay = parameter[GFX_ARG_DELAY];
+ if (graphic_info[graphic].anim_delay == 0) /* delay must be at least 1 */
+ graphic_info[graphic].anim_delay = 1;
+
+ /* set mode for animation frame order */
+ if (parameter[GFX_ARG_MODE_LOOP])
+ graphic_info[graphic].anim_mode = ANIM_LOOP;
+ else if (parameter[GFX_ARG_MODE_LINEAR])
+ graphic_info[graphic].anim_mode = ANIM_LINEAR;
+ else if (parameter[GFX_ARG_MODE_PINGPONG])
+ graphic_info[graphic].anim_mode = ANIM_PINGPONG;
+ else if (parameter[GFX_ARG_MODE_PINGPONG2])
+ graphic_info[graphic].anim_mode = ANIM_PINGPONG2;
+ else if (parameter[GFX_ARG_MODE_RANDOM])
+ graphic_info[graphic].anim_mode = ANIM_RANDOM;
+ else if (graphic_info[graphic].anim_frames > 1)
+ graphic_info[graphic].anim_mode = ANIM_LOOP;
+ else
+ graphic_info[graphic].anim_mode = ANIM_NONE;
+
+ /* set additional flag to play animation frames in reverse order */
+ if (parameter[GFX_ARG_MODE_REVERSE])
+ graphic_info[graphic].anim_mode |= ANIM_REVERSE;
+
+ /* set first frame of animation after determining animation mode */
+ graphic_info[graphic].anim_start_frame = parameter[GFX_ARG_START_FRAME];
+
+ /* automatically determine correct start frame, if not defined */
+ if (parameter[GFX_ARG_START_FRAME] == ARG_UNDEFINED_VALUE)
+ graphic_info[graphic].anim_start_frame = 0;
+ else if (graphic_info[graphic].anim_mode & ANIM_REVERSE)
+ graphic_info[graphic].anim_start_frame =
+ graphic_info[graphic].anim_frames - parameter[GFX_ARG_START_FRAME] - 1;
+
+ /* animation synchronized with global frame counter, not move position */
+ graphic_info[graphic].anim_global_sync = parameter[GFX_ARG_GLOBAL_SYNC];
+
+ /* set global_sync for all animations with undefined "animation action" */
+ if (parameter[GFX_ARG_GLOBAL_SYNC] == ARG_UNDEFINED_VALUE)
+ graphic_info[graphic].anim_global_sync =
+ (action == ACTION_DEFAULT ? TRUE : FALSE);
+
+ /* "linear" animations are never globally synchronized */
+ if (parameter[GFX_ARG_MODE_LINEAR])
+ graphic_info[graphic].anim_global_sync = FALSE;
+}
+