1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // http://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
12 #include "libgame/libgame.h"
22 #define DEBUG_ANIM_EVENTS 0
25 // values for global toon animation definition
26 #define NUM_GLOBAL_TOON_ANIMS 1
27 #define NUM_GLOBAL_TOON_PARTS MAX_NUM_TOONS
29 // values for global animation definition (including toons)
30 #define NUM_GLOBAL_ANIMS_AND_TOONS (NUM_GLOBAL_ANIMS + \
31 NUM_GLOBAL_TOON_ANIMS)
32 #define NUM_GLOBAL_ANIM_PARTS_AND_TOONS MAX(NUM_GLOBAL_ANIM_PARTS_ALL, \
33 NUM_GLOBAL_TOON_PARTS)
35 #define ANIM_CLASS_BIT_TITLE_INITIAL 0
36 #define ANIM_CLASS_BIT_TITLE 1
37 #define ANIM_CLASS_BIT_MAIN 2
38 #define ANIM_CLASS_BIT_SCORES 3
39 #define ANIM_CLASS_BIT_SUBMENU 4
40 #define ANIM_CLASS_BIT_MENU 5
41 #define ANIM_CLASS_BIT_TOONS 6
42 #define ANIM_CLASS_BIT_NO_TITLE 7
44 #define NUM_ANIM_CLASSES 8
46 #define ANIM_CLASS_NONE 0
47 #define ANIM_CLASS_TITLE_INITIAL (1 << ANIM_CLASS_BIT_TITLE_INITIAL)
48 #define ANIM_CLASS_TITLE (1 << ANIM_CLASS_BIT_TITLE)
49 #define ANIM_CLASS_MAIN (1 << ANIM_CLASS_BIT_MAIN)
50 #define ANIM_CLASS_SCORES (1 << ANIM_CLASS_BIT_SCORES)
51 #define ANIM_CLASS_SUBMENU (1 << ANIM_CLASS_BIT_SUBMENU)
52 #define ANIM_CLASS_MENU (1 << ANIM_CLASS_BIT_MENU)
53 #define ANIM_CLASS_TOONS (1 << ANIM_CLASS_BIT_TOONS)
54 #define ANIM_CLASS_NO_TITLE (1 << ANIM_CLASS_BIT_NO_TITLE)
56 #define ANIM_CLASS_TOONS_SCORES (ANIM_CLASS_TOONS | \
60 #define ANIM_CLASS_TOONS_MENU_MAIN (ANIM_CLASS_TOONS | \
65 #define ANIM_CLASS_TOONS_MENU_SUBMENU (ANIM_CLASS_TOONS | \
67 ANIM_CLASS_SUBMENU | \
70 // values for global animation states
71 #define ANIM_STATE_INACTIVE 0
72 #define ANIM_STATE_RESTART (1 << 0)
73 #define ANIM_STATE_WAITING (1 << 1)
74 #define ANIM_STATE_RUNNING (1 << 2)
76 // values for global animation control
77 #define ANIM_NO_ACTION 0
79 #define ANIM_CONTINUE 2
83 struct GlobalAnimPartControlInfo
85 int old_nr; // position before mapping animation parts linearly
86 int old_anim_nr; // position before mapping animations linearly
92 boolean is_base; // animation part is base/main/default animation part
98 struct GraphicInfo graphic_info;
99 struct GraphicInfo control_info;
107 int step_xoffset, step_yoffset;
109 unsigned int initial_anim_sync_frame;
110 unsigned int step_delay, step_delay_value;
112 int init_delay_counter;
113 int anim_delay_counter;
114 int post_delay_counter;
116 boolean init_event_state;
117 boolean anim_event_state;
126 int last_anim_status;
129 struct GlobalAnimMainControlInfo
131 struct GlobalAnimPartControlInfo base;
132 struct GlobalAnimPartControlInfo part[NUM_GLOBAL_ANIM_PARTS_AND_TOONS];
137 struct GraphicInfo control_info;
139 int num_parts; // number of animation parts, but without base part
140 int num_parts_all; // number of animation parts, including base part
144 boolean has_base; // animation has base/main/default animation part
148 int init_delay_counter;
152 int last_state, last_active_part_nr;
155 struct GlobalAnimControlInfo
157 struct GlobalAnimMainControlInfo anim[NUM_GLOBAL_ANIMS_AND_TOONS];
163 struct GameModeAnimClass
167 } game_mode_anim_classes_list[] =
169 { GAME_MODE_TITLE_INITIAL_1, ANIM_CLASS_TITLE_INITIAL },
170 { GAME_MODE_TITLE_INITIAL_2, ANIM_CLASS_TITLE_INITIAL },
171 { GAME_MODE_TITLE_INITIAL_3, ANIM_CLASS_TITLE_INITIAL },
172 { GAME_MODE_TITLE_INITIAL_4, ANIM_CLASS_TITLE_INITIAL },
173 { GAME_MODE_TITLE_INITIAL_5, ANIM_CLASS_TITLE_INITIAL },
174 { GAME_MODE_TITLE_1, ANIM_CLASS_TITLE },
175 { GAME_MODE_TITLE_2, ANIM_CLASS_TITLE },
176 { GAME_MODE_TITLE_3, ANIM_CLASS_TITLE },
177 { GAME_MODE_TITLE_4, ANIM_CLASS_TITLE },
178 { GAME_MODE_TITLE_5, ANIM_CLASS_TITLE },
179 { GAME_MODE_LEVELS, ANIM_CLASS_TOONS_MENU_SUBMENU },
180 { GAME_MODE_LEVELNR, ANIM_CLASS_TOONS_MENU_SUBMENU },
181 { GAME_MODE_INFO, ANIM_CLASS_TOONS_MENU_SUBMENU },
182 { GAME_MODE_SETUP, ANIM_CLASS_TOONS_MENU_SUBMENU },
183 { GAME_MODE_PSEUDO_MAINONLY, ANIM_CLASS_TOONS_MENU_MAIN },
184 { GAME_MODE_PSEUDO_TYPENAME, ANIM_CLASS_TOONS_MENU_MAIN },
185 { GAME_MODE_PSEUDO_SCORESOLD, ANIM_CLASS_TOONS_SCORES },
186 { GAME_MODE_PSEUDO_SCORESNEW, ANIM_CLASS_TOONS_SCORES },
187 { GAME_MODE_EDITOR, ANIM_CLASS_NO_TITLE },
188 { GAME_MODE_PLAYING, ANIM_CLASS_NO_TITLE },
193 struct AnimClassGameMode
197 } anim_class_game_modes_list[] =
199 { ANIM_CLASS_BIT_TITLE_INITIAL, GAME_MODE_TITLE_INITIAL },
200 { ANIM_CLASS_BIT_TITLE, GAME_MODE_TITLE },
201 { ANIM_CLASS_BIT_MAIN, GAME_MODE_MAIN },
202 { ANIM_CLASS_BIT_SCORES, GAME_MODE_SCORES },
203 { ANIM_CLASS_BIT_SUBMENU, GAME_MODE_PSEUDO_SUBMENU },
204 { ANIM_CLASS_BIT_MENU, GAME_MODE_PSEUDO_MENU },
205 { ANIM_CLASS_BIT_TOONS, GAME_MODE_PSEUDO_TOONS },
206 { ANIM_CLASS_BIT_NO_TITLE, GAME_MODE_PSEUDO_NO_TITLE },
211 // forward declaration for internal use
212 static boolean DoGlobalAnim_EventAction(struct GlobalAnimPartControlInfo *);
213 static void HandleGlobalAnim(int, int);
214 static void DoAnimationExt(void);
215 static void ResetGlobalAnim_Clickable(void);
216 static void ResetGlobalAnim_Clicked(void);
218 static struct GlobalAnimControlInfo global_anim_ctrl[NUM_GAME_MODES];
220 static unsigned int anim_sync_frame = 0;
222 static int game_mode_anim_classes[NUM_GAME_MODES];
223 static int anim_class_game_modes[NUM_ANIM_CLASSES];
225 static int anim_status_last_before_fading = GAME_MODE_DEFAULT;
226 static int anim_status_last = GAME_MODE_DEFAULT;
227 static int anim_classes_last = ANIM_CLASS_NONE;
229 static boolean drawing_to_fading_buffer = FALSE;
232 // ============================================================================
233 // generic animation frame calculation
234 // ============================================================================
236 int getAnimationFrame(int num_frames, int delay, int mode, int start_frame,
241 sync_frame += start_frame * delay;
243 if (mode & ANIM_LOOP) // looping animation
245 frame = (sync_frame % (delay * num_frames)) / delay;
247 else if (mode & ANIM_LINEAR) // linear (non-looping) animation
249 frame = sync_frame / delay;
251 if (frame > num_frames - 1)
252 frame = num_frames - 1;
254 else if (mode & ANIM_PINGPONG) // oscillate (border frames once)
256 int max_anim_frames = (num_frames > 1 ? 2 * num_frames - 2 : 1);
258 frame = (sync_frame % (delay * max_anim_frames)) / delay;
259 frame = (frame < num_frames ? frame : max_anim_frames - frame);
261 else if (mode & ANIM_PINGPONG2) // oscillate (border frames twice)
263 int max_anim_frames = 2 * num_frames;
265 frame = (sync_frame % (delay * max_anim_frames)) / delay;
266 frame = (frame < num_frames ? frame : max_anim_frames - frame - 1);
268 else if (mode & ANIM_RANDOM) // play frames in random order
270 // note: expect different frames for the same delay cycle!
272 if (gfx.anim_random_frame < 0)
273 frame = GetSimpleRandom(num_frames);
275 frame = gfx.anim_random_frame % num_frames;
277 else if (mode & (ANIM_CE_VALUE | ANIM_CE_SCORE | ANIM_CE_DELAY))
279 frame = sync_frame % num_frames;
282 if (mode & ANIM_REVERSE) // use reverse animation direction
283 frame = num_frames - frame - 1;
289 // ============================================================================
290 // global animation functions
291 // ============================================================================
293 static int getGlobalAnimationPart(struct GlobalAnimMainControlInfo *anim)
295 struct GraphicInfo *c = &anim->control_info;
296 int last_anim_random_frame = gfx.anim_random_frame;
299 gfx.anim_random_frame = -1; // (use simple, ad-hoc random numbers)
301 part_nr = getAnimationFrame(anim->num_parts, 1,
302 c->anim_mode, c->anim_start_frame,
305 gfx.anim_random_frame = last_anim_random_frame;
310 static int compareGlobalAnimPartControlInfo(const void *obj1, const void *obj2)
312 const struct GlobalAnimPartControlInfo *o1 =
313 (struct GlobalAnimPartControlInfo *)obj1;
314 const struct GlobalAnimPartControlInfo *o2 =
315 (struct GlobalAnimPartControlInfo *)obj2;
318 if (o1->control_info.draw_order != o2->control_info.draw_order)
319 compare_result = o1->control_info.draw_order - o2->control_info.draw_order;
321 compare_result = o1->nr - o2->nr;
323 return compare_result;
326 static int compareGlobalAnimMainControlInfo(const void *obj1, const void *obj2)
328 const struct GlobalAnimMainControlInfo *o1 =
329 (struct GlobalAnimMainControlInfo *)obj1;
330 const struct GlobalAnimMainControlInfo *o2 =
331 (struct GlobalAnimMainControlInfo *)obj2;
334 if (o1->control_info.draw_order != o2->control_info.draw_order)
335 compare_result = o1->control_info.draw_order - o2->control_info.draw_order;
337 compare_result = o1->nr - o2->nr;
339 return compare_result;
342 static void InitToonControls(void)
344 int mode_nr_toons = GAME_MODE_PSEUDO_TOONS;
345 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[mode_nr_toons];
346 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[ctrl->num_anims];
347 int mode_nr, anim_nr, part_nr;
348 int control = IMG_INTERNAL_GLOBAL_TOON_DEFAULT;
349 int num_toons = MAX_NUM_TOONS;
352 if (global.num_toons >= 0 && global.num_toons < MAX_NUM_TOONS)
353 num_toons = global.num_toons;
355 mode_nr = mode_nr_toons;
356 anim_nr = ctrl->num_anims;
359 anim->mode_nr = mode_nr;
360 anim->control_info = graphic_info[control];
363 anim->num_parts_all = 0;
364 anim->part_counter = 0;
365 anim->active_part_nr = 0;
367 anim->has_base = FALSE;
369 anim->last_x = POS_OFFSCREEN;
370 anim->last_y = POS_OFFSCREEN;
372 anim->init_delay_counter = 0;
374 anim->state = ANIM_STATE_INACTIVE;
378 for (i = 0; i < num_toons; i++)
380 struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
381 int sound = SND_UNDEFINED;
382 int music = MUS_UNDEFINED;
383 int graphic = IMG_TOON_1 + i;
384 int control = graphic;
387 part->anim_nr = anim_nr;
388 part->mode_nr = mode_nr;
390 part->is_base = FALSE;
394 part->graphic = graphic;
396 part->graphic_info = graphic_info[graphic];
397 part->control_info = graphic_info[control];
399 part->graphic_info.anim_delay *= part->graphic_info.step_delay;
401 part->control_info.init_delay_fixed = 0;
402 part->control_info.init_delay_random = 150;
404 part->control_info.x = ARG_UNDEFINED_VALUE;
405 part->control_info.y = ARG_UNDEFINED_VALUE;
407 part->initial_anim_sync_frame = 0;
409 part->step_delay = 0;
410 part->step_delay_value = graphic_info[control].step_delay;
412 part->state = ANIM_STATE_INACTIVE;
413 part->last_anim_status = -1;
416 anim->num_parts_all++;
424 static void InitGlobalAnimControls(void)
427 int mode_nr, anim_nr, part_nr;
428 int sound, music, graphic, control;
432 for (m = 0; m < NUM_GAME_MODES; m++)
436 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[mode_nr];
443 for (a = 0; a < NUM_GLOBAL_ANIMS; a++)
445 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[anim_nr];
446 int ctrl_id = GLOBAL_ANIM_ID_CONTROL_FIRST + a;
448 control = global_anim_info[ctrl_id].graphic[GLOBAL_ANIM_ID_PART_BASE][m];
450 // if no base animation parameters defined, use default values
451 if (control == IMG_UNDEFINED)
452 control = IMG_INTERNAL_GLOBAL_ANIM_DEFAULT;
455 anim->mode_nr = mode_nr;
456 anim->control_info = graphic_info[control];
459 anim->num_parts_all = 0;
460 anim->part_counter = 0;
461 anim->active_part_nr = 0;
463 anim->has_base = FALSE;
465 anim->last_x = POS_OFFSCREEN;
466 anim->last_y = POS_OFFSCREEN;
468 anim->init_delay_counter = 0;
470 anim->state = ANIM_STATE_INACTIVE;
474 for (p = 0; p < NUM_GLOBAL_ANIM_PARTS_ALL; p++)
476 struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
478 sound = global_anim_info[a].sound[p][m];
479 music = global_anim_info[a].music[p][m];
480 graphic = global_anim_info[a].graphic[p][m];
481 control = global_anim_info[ctrl_id].graphic[p][m];
483 if (graphic == IMG_UNDEFINED || graphic_info[graphic].bitmap == NULL ||
484 control == IMG_UNDEFINED)
488 printf("::: mode == %d, anim = %d, part = %d [%d, %d, %d] [%d]\n",
489 m, a, p, mode_nr, anim_nr, part_nr, control);
493 printf("::: mode == %d, anim = %d, part = %d [%d, %d, %d] [%d]\n",
494 m, a, p, mode_nr, anim_nr, part_nr, sound);
498 part->old_anim_nr = a;
501 part->anim_nr = anim_nr;
502 part->mode_nr = mode_nr;
506 part->graphic = graphic;
508 part->graphic_info = graphic_info[graphic];
509 part->control_info = graphic_info[control];
511 part->initial_anim_sync_frame = 0;
513 part->step_delay = 0;
514 part->step_delay_value = graphic_info[control].step_delay;
516 part->state = ANIM_STATE_INACTIVE;
517 part->last_anim_status = -1;
519 anim->num_parts_all++;
521 if (p < GLOBAL_ANIM_ID_PART_BASE)
523 part->is_base = FALSE;
530 part->is_base = TRUE;
533 anim->has_base = TRUE;
537 if (anim->num_parts > 0 || anim->has_base)
547 // sort all animations according to draw_order and animation number
548 for (m = 0; m < NUM_GAME_MODES; m++)
550 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[m];
552 // sort all main animations for this game mode
553 qsort(ctrl->anim, ctrl->num_anims,
554 sizeof(struct GlobalAnimMainControlInfo),
555 compareGlobalAnimMainControlInfo);
557 for (a = 0; a < ctrl->num_anims; a++)
559 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[a];
561 // sort all animation parts for this main animation
562 qsort(anim->part, anim->num_parts,
563 sizeof(struct GlobalAnimPartControlInfo),
564 compareGlobalAnimPartControlInfo);
568 for (i = 0; i < NUM_GAME_MODES; i++)
569 game_mode_anim_classes[i] = ANIM_CLASS_NONE;
570 for (i = 0; game_mode_anim_classes_list[i].game_mode != -1; i++)
571 game_mode_anim_classes[game_mode_anim_classes_list[i].game_mode] =
572 game_mode_anim_classes_list[i].class;
574 for (i = 0; i < NUM_ANIM_CLASSES; i++)
575 anim_class_game_modes[i] = GAME_MODE_DEFAULT;
576 for (i = 0; anim_class_game_modes_list[i].game_mode != -1; i++)
577 anim_class_game_modes[anim_class_game_modes_list[i].class_bit] =
578 anim_class_game_modes_list[i].game_mode;
580 anim_status_last_before_fading = GAME_MODE_LOADING;
581 anim_status_last = GAME_MODE_LOADING;
582 anim_classes_last = ANIM_CLASS_NONE;
585 void InitGlobalAnimations(void)
587 InitGlobalAnimControls();
590 static void DrawGlobalAnimationsExt(int drawing_target, int drawing_stage)
592 Bitmap *fade_bitmap =
593 (drawing_target == DRAW_TO_FADE_SOURCE ? gfx.fade_bitmap_source :
594 drawing_target == DRAW_TO_FADE_TARGET ? gfx.fade_bitmap_target : NULL);
595 int game_mode_anim_action[NUM_GAME_MODES];
601 if (drawing_stage == DRAW_GLOBAL_ANIM_STAGE_1 &&
602 drawing_target == DRAW_TO_SCREEN)
605 // always start with reliable default values (no animation actions)
606 for (mode_nr = 0; mode_nr < NUM_GAME_MODES; mode_nr++)
607 game_mode_anim_action[mode_nr] = ANIM_NO_ACTION;
609 if (global.anim_status != anim_status_last)
611 boolean before_fading = (global.anim_status == GAME_MODE_PSEUDO_FADING);
612 boolean after_fading = (anim_status_last == GAME_MODE_PSEUDO_FADING);
613 int anim_classes_next = game_mode_anim_classes[global.anim_status_next];
616 if (drawing_target == DRAW_TO_FADE_TARGET)
619 // special case: changing from/to this screen is done without fading
620 if (global.anim_status == GAME_MODE_PSEUDO_TYPENAME ||
621 anim_status_last == GAME_MODE_PSEUDO_TYPENAME)
624 // ---------- part 1 ------------------------------------------------------
625 // start or stop global animations by change of game mode
626 // (special handling of animations for "current screen" and "all screens")
628 if (global.anim_status_next != anim_status_last_before_fading)
630 // stop animations for last screen before fading to new screen
631 game_mode_anim_action[anim_status_last] = ANIM_STOP;
633 // start animations for current screen after fading to new screen
634 game_mode_anim_action[global.anim_status] = ANIM_START;
637 // start animations for all screens after loading new artwork set
638 if (anim_status_last == GAME_MODE_LOADING)
639 game_mode_anim_action[GAME_MODE_DEFAULT] = ANIM_START;
641 // ---------- part 2 ------------------------------------------------------
642 // start or stop global animations by change of animation class
643 // (generic handling of animations for "class of screens")
645 for (i = 0; i < NUM_ANIM_CLASSES; i++)
647 int anim_class_check = (1 << i);
648 int anim_class_game_mode = anim_class_game_modes[i];
649 int anim_class_last = anim_classes_last & anim_class_check;
650 int anim_class_next = anim_classes_next & anim_class_check;
652 // stop animations for changed screen class before fading to new screen
653 if (before_fading && anim_class_last && !anim_class_next)
654 game_mode_anim_action[anim_class_game_mode] = ANIM_STOP;
656 // start animations for changed screen class after fading to new screen
657 if (after_fading && !anim_class_last && anim_class_next)
658 game_mode_anim_action[anim_class_game_mode] = ANIM_START;
661 if (drawing_target == DRAW_TO_SCREEN)
665 anim_classes_last = anim_classes_next;
666 anim_status_last_before_fading = global.anim_status;
669 anim_status_last = global.anim_status;
671 // start or stop animations determined to be started or stopped above
672 for (mode_nr = 0; mode_nr < NUM_GAME_MODES; mode_nr++)
673 if (game_mode_anim_action[mode_nr] != ANIM_NO_ACTION)
674 HandleGlobalAnim(game_mode_anim_action[mode_nr], mode_nr);
676 else if (drawing_target == DRAW_TO_FADE_TARGET)
678 drawing_to_fading_buffer = TRUE;
680 // start animations determined to be (temporary) started above
681 for (mode_nr = 0; mode_nr < NUM_GAME_MODES; mode_nr++)
682 if (game_mode_anim_action[mode_nr] == ANIM_START)
683 HandleGlobalAnim(ANIM_START, mode_nr);
687 if (global.anim_status == GAME_MODE_LOADING)
690 for (mode_nr = 0; mode_nr < NUM_GAME_MODES; mode_nr++)
692 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[mode_nr];
695 // when preparing source fading buffer, only draw animations to be stopped
696 if (drawing_target == DRAW_TO_FADE_SOURCE &&
697 game_mode_anim_action[mode_nr] != ANIM_STOP)
700 // when preparing target fading buffer, only draw animations to be started
701 if (drawing_target == DRAW_TO_FADE_TARGET &&
702 game_mode_anim_action[mode_nr] != ANIM_START)
706 if (mode_nr != GFX_SPECIAL_ARG_DEFAULT &&
707 mode_nr != game_status)
711 for (anim_nr = 0; anim_nr < ctrl->num_anims; anim_nr++)
713 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[anim_nr];
714 struct GraphicInfo *c = &anim->control_info;
715 int part_first, part_last;
718 if (!(anim->state & ANIM_STATE_RUNNING))
721 part_first = part_last = anim->active_part_nr;
723 if (c->anim_mode & ANIM_ALL || anim->num_parts == 0)
725 int num_parts = anim->num_parts + (anim->has_base ? 1 : 0);
728 part_last = num_parts - 1;
731 for (part_nr = part_first; part_nr <= part_last; part_nr++)
733 struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
734 struct GraphicInfo *g = &part->graphic_info;
737 int width = g->width;
738 int height = g->height;
745 void (*blit_bitmap)(Bitmap *, Bitmap *, int, int, int, int, int, int) =
746 (g->draw_masked ? BlitBitmapMasked : BlitBitmap);
747 void (*blit_screen)(Bitmap *, int, int, int, int, int, int) =
748 (g->draw_masked ? BlitToScreenMasked : BlitToScreen);
750 if (!(part->state & ANIM_STATE_RUNNING))
753 if (part->drawing_stage != drawing_stage)
762 else if (part->x > part->viewport_width - g->width)
763 width -= (part->x - (part->viewport_width - g->width));
771 else if (part->y > part->viewport_height - g->height)
772 height -= (part->y - (part->viewport_height - g->height));
774 if (width <= 0 || height <= 0)
777 dst_x += part->viewport_x;
778 dst_y += part->viewport_y;
780 sync_frame = anim_sync_frame - part->initial_anim_sync_frame;
781 frame = getAnimationFrame(g->anim_frames, g->anim_delay,
782 g->anim_mode, g->anim_start_frame,
785 getFixedGraphicSource(part->graphic, frame, &src_bitmap,
791 if (drawing_target == DRAW_TO_SCREEN)
792 blit_screen(src_bitmap, src_x, src_y, width, height,
795 blit_bitmap(src_bitmap, fade_bitmap, src_x, src_y, width, height,
801 if (drawing_target == DRAW_TO_FADE_TARGET)
803 // stop animations determined to be (temporary) started above
804 for (mode_nr = 0; mode_nr < NUM_GAME_MODES; mode_nr++)
805 if (game_mode_anim_action[mode_nr] == ANIM_START)
806 HandleGlobalAnim(ANIM_STOP, mode_nr);
808 drawing_to_fading_buffer = FALSE;
812 void DrawGlobalAnimations(int drawing_target, int drawing_stage)
814 if (drawing_stage == DRAW_GLOBAL_ANIM_STAGE_1)
815 ResetGlobalAnim_Clickable();
817 DrawGlobalAnimationsExt(drawing_target, drawing_stage);
819 if (drawing_stage == DRAW_GLOBAL_ANIM_STAGE_2)
820 ResetGlobalAnim_Clicked();
823 static boolean SetGlobalAnimPart_Viewport(struct GlobalAnimPartControlInfo *part)
829 boolean changed = FALSE;
831 if (part->last_anim_status == global.anim_status)
834 part->last_anim_status = global.anim_status;
836 part->drawing_stage = DRAW_GLOBAL_ANIM_STAGE_1;
838 if (part->control_info.class == get_hash_from_key("window") ||
839 part->control_info.class == get_hash_from_key("border"))
843 viewport_width = WIN_XSIZE;
844 viewport_height = WIN_YSIZE;
846 part->drawing_stage = DRAW_GLOBAL_ANIM_STAGE_2;
848 else if (part->control_info.class == get_hash_from_key("door_1"))
852 viewport_width = DXSIZE;
853 viewport_height = DYSIZE;
855 else if (part->control_info.class == get_hash_from_key("door_2"))
859 viewport_width = VXSIZE;
860 viewport_height = VYSIZE;
862 else // default: "playfield"
864 viewport_x = REAL_SX;
865 viewport_y = REAL_SY;
866 viewport_width = FULL_SXSIZE;
867 viewport_height = FULL_SYSIZE;
870 if (viewport_x != part->viewport_x ||
871 viewport_y != part->viewport_y ||
872 viewport_width != part->viewport_width ||
873 viewport_height != part->viewport_height)
875 part->viewport_x = viewport_x;
876 part->viewport_y = viewport_y;
877 part->viewport_width = viewport_width;
878 part->viewport_height = viewport_height;
886 static void PlayGlobalAnimSound(struct GlobalAnimPartControlInfo *part)
888 int sound = part->sound;
890 if (sound == SND_UNDEFINED)
893 if ((!setup.sound_simple && !IS_LOOP_SOUND(sound)) ||
894 (!setup.sound_loops && IS_LOOP_SOUND(sound)))
897 // !!! TODO: ADD STEREO POSITION FOR MOVING ANIMATIONS !!!
898 if (IS_LOOP_SOUND(sound))
899 PlaySoundLoop(sound);
904 printf("::: PLAY SOUND %d.%d.%d: %d\n",
905 part->anim_nr, part->nr, part->mode_nr, sound);
909 static void StopGlobalAnimSound(struct GlobalAnimPartControlInfo *part)
911 int sound = part->sound;
913 if (sound == SND_UNDEFINED)
919 printf("::: STOP SOUND %d.%d.%d: %d\n",
920 part->anim_nr, part->nr, part->mode_nr, sound);
924 static void PlayGlobalAnimMusic(struct GlobalAnimPartControlInfo *part)
926 int music = part->music;
928 if (music == MUS_UNDEFINED)
931 if (!setup.sound_music)
934 if (IS_LOOP_MUSIC(music))
935 PlayMusicLoop(music);
940 printf("::: PLAY MUSIC %d.%d.%d: %d\n",
941 part->anim_nr, part->nr, part->mode_nr, music);
945 static void StopGlobalAnimMusic(struct GlobalAnimPartControlInfo *part)
947 int music = part->music;
949 if (music == MUS_UNDEFINED)
955 printf("::: STOP MUSIC %d.%d.%d: %d\n",
956 part->anim_nr, part->nr, part->mode_nr, music);
960 static void PlayGlobalAnimSoundAndMusic(struct GlobalAnimPartControlInfo *part)
962 // when drawing animations to fading buffer, do not play sounds or music
963 if (drawing_to_fading_buffer)
966 PlayGlobalAnimSound(part);
967 PlayGlobalAnimMusic(part);
970 static void StopGlobalAnimSoundAndMusic(struct GlobalAnimPartControlInfo *part)
972 StopGlobalAnimSound(part);
973 StopGlobalAnimMusic(part);
976 static void PlayGlobalAnimSoundIfLoop(struct GlobalAnimPartControlInfo *part)
978 // when drawing animations to fading buffer, do not play sounds
979 if (drawing_to_fading_buffer)
982 // loop sounds only expire when playing
983 if (game_status != GAME_MODE_PLAYING)
986 // check if any sound is defined for this animation part
987 if (part->sound == SND_UNDEFINED)
990 // normal (non-loop) sounds do not expire when playing
991 if (!IS_LOOP_SOUND(part->sound))
994 // prevent expiring loop sounds when playing
995 PlayGlobalAnimSound(part);
998 static boolean checkGlobalAnimEvent(int anim_event, int mask)
1000 int mask_anim_only = mask & ~ANIM_EVENT_PART_MASK;
1002 if (mask & ANIM_EVENT_ANY)
1003 return (anim_event & ANIM_EVENT_ANY);
1004 else if (mask & ANIM_EVENT_SELF)
1005 return (anim_event & ANIM_EVENT_SELF);
1007 return (anim_event == mask ||
1008 anim_event == mask_anim_only);
1011 static boolean isClickablePart(struct GlobalAnimPartControlInfo *part, int mask)
1013 struct GraphicInfo *c = &part->control_info;
1014 int num_init_events = GetGlobalAnimEventValueCount(c->init_event);
1015 int num_anim_events = GetGlobalAnimEventValueCount(c->anim_event);
1018 for (i = 0; i < num_init_events; i++)
1020 int init_event = GetGlobalAnimEventValue(c->init_event, i);
1022 if (checkGlobalAnimEvent(init_event, mask))
1026 for (i = 0; i < num_anim_events; i++)
1028 int anim_event = GetGlobalAnimEventValue(c->anim_event, i);
1030 if (checkGlobalAnimEvent(anim_event, mask))
1037 static boolean isClickedPart(struct GlobalAnimPartControlInfo *part,
1038 int mx, int my, boolean clicked)
1040 struct GraphicInfo *g = &part->graphic_info;
1041 int part_x = part->viewport_x + part->x;
1042 int part_y = part->viewport_y + part->y;
1043 int part_width = g->width;
1044 int part_height = g->height;
1046 // check if mouse click was detected at all
1050 // check if mouse click is inside the animation part's viewport
1051 if (mx < part->viewport_x ||
1052 mx >= part->viewport_x + part->viewport_width ||
1053 my < part->viewport_y ||
1054 my >= part->viewport_y + part->viewport_height)
1057 // check if mouse click is inside the animation part's graphic
1059 mx >= part_x + part_width ||
1061 my >= part_y + part_height)
1067 static boolean clickConsumed(struct GlobalAnimPartControlInfo *part)
1069 return (part->control_info.style & STYLE_PASSTHROUGH ? FALSE : TRUE);
1072 static void InitGlobalAnim_Triggered(struct GlobalAnimPartControlInfo *part,
1073 boolean *anything_clicked,
1074 boolean *any_event_action,
1075 int event_value, char *info_text)
1077 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[part->mode_nr];
1079 int gic_anim_nr = part->old_anim_nr + 1; // X as in "anim_X"
1080 int gic_part_nr = part->old_nr + 1; // Y as in "part_Y"
1081 int mask = event_value | (gic_anim_nr << ANIM_EVENT_ANIM_BIT);
1084 mask |= gic_part_nr << ANIM_EVENT_PART_BIT;
1088 for (anim2_nr = 0; anim2_nr < ctrl->num_anims; anim2_nr++)
1090 struct GlobalAnimMainControlInfo *anim2 = &ctrl->anim[anim2_nr];
1093 for (part2_nr = 0; part2_nr < anim2->num_parts_all; part2_nr++)
1095 struct GlobalAnimPartControlInfo *part2 = &anim2->part[part2_nr];
1097 if (part2->state != ANIM_STATE_RUNNING)
1100 if (isClickablePart(part2, mask))
1102 part2->triggered = TRUE;
1103 *anything_clicked = clickConsumed(part); // click was on "part"!
1105 #if DEBUG_ANIM_EVENTS
1106 printf("::: => %d.%d TRIGGERED BY %s OF %d.%d\n",
1107 part2->old_anim_nr + 1, part2->old_nr + 1, info_text,
1108 part->old_anim_nr + 1, part->old_nr + 1);
1111 printf("::: %d.%d TRIGGER CLICKED [%d]\n", anim2_nr, part2_nr,
1112 part2->control_info.anim_event_action);
1115 // after executing event action, ignore any further actions
1116 if (!*any_event_action && DoGlobalAnim_EventAction(part2))
1117 *any_event_action = TRUE;
1121 struct GraphicInfo *c = &part2->control_info;
1123 printf("::: - %d.%d: 0x%08x, 0x%08x [0x%08x]",
1124 anim2_nr, part2_nr, c->init_event, c->anim_event, mask);
1126 if (isClickablePart(part2, mask))
1127 printf(" <--- TRIGGERED BY %d.%d",
1136 static void HandleGlobalAnimEvent(struct GlobalAnimPartControlInfo *part,
1137 int event_value, char *info_text)
1139 #if DEBUG_ANIM_EVENTS
1140 printf("::: %d.%d %s\n", part->old_anim_nr + 1, part->old_nr + 1, info_text);
1143 boolean anything_clicked = FALSE;
1144 boolean any_event_action = FALSE;
1146 // check if this event is defined to trigger other animations
1147 InitGlobalAnim_Triggered(part, &anything_clicked, &any_event_action,
1148 event_value, info_text);
1151 static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part,
1154 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[part->mode_nr];
1155 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[part->anim_nr];
1156 struct GraphicInfo *g = &part->graphic_info;
1157 struct GraphicInfo *c = &part->control_info;
1158 boolean viewport_changed = SetGlobalAnimPart_Viewport(part);
1160 if (viewport_changed)
1161 state |= ANIM_STATE_RESTART;
1163 if (state & ANIM_STATE_RESTART)
1165 // when drawing animations to fading buffer, only start fixed animations
1166 if (drawing_to_fading_buffer && (c->x == ARG_UNDEFINED_VALUE ||
1167 c->y == ARG_UNDEFINED_VALUE))
1168 return ANIM_STATE_INACTIVE;
1170 ResetDelayCounterExt(&part->step_delay, anim_sync_frame);
1172 part->init_delay_counter =
1173 (c->init_delay_fixed + GetSimpleRandom(c->init_delay_random));
1175 part->anim_delay_counter =
1176 (c->anim_delay_fixed + GetSimpleRandom(c->anim_delay_random));
1178 part->init_event_state = (c->init_event != ANIM_EVENT_UNDEFINED);
1179 part->anim_event_state = (c->anim_event != ANIM_EVENT_UNDEFINED);
1181 part->initial_anim_sync_frame =
1182 (g->anim_global_sync ? 0 : anim_sync_frame + part->init_delay_counter);
1184 if (c->direction & MV_HORIZONTAL)
1186 int pos_bottom = part->viewport_height - g->height;
1188 if (c->position == POS_TOP)
1190 else if (c->position == POS_UPPER)
1191 part->y = GetSimpleRandom(pos_bottom / 2);
1192 else if (c->position == POS_MIDDLE)
1193 part->y = pos_bottom / 2;
1194 else if (c->position == POS_LOWER)
1195 part->y = pos_bottom / 2 + GetSimpleRandom(pos_bottom / 2);
1196 else if (c->position == POS_BOTTOM)
1197 part->y = pos_bottom;
1199 part->y = GetSimpleRandom(pos_bottom);
1201 if (c->direction == MV_RIGHT)
1203 part->step_xoffset = c->step_offset;
1204 part->x = -g->width + part->step_xoffset;
1208 part->step_xoffset = -c->step_offset;
1209 part->x = part->viewport_width + part->step_xoffset;
1212 part->step_yoffset = 0;
1214 else if (c->direction & MV_VERTICAL)
1216 int pos_right = part->viewport_width - g->width;
1218 if (c->position == POS_LEFT)
1220 else if (c->position == POS_RIGHT)
1221 part->x = pos_right;
1223 part->x = GetSimpleRandom(pos_right);
1225 if (c->direction == MV_DOWN)
1227 part->step_yoffset = c->step_offset;
1228 part->y = -g->height + part->step_yoffset;
1232 part->step_yoffset = -c->step_offset;
1233 part->y = part->viewport_height + part->step_yoffset;
1236 part->step_xoffset = 0;
1243 part->step_xoffset = 0;
1244 part->step_yoffset = 0;
1247 if (c->x != ARG_UNDEFINED_VALUE)
1249 if (c->y != ARG_UNDEFINED_VALUE)
1252 if (c->position == POS_LAST &&
1253 anim->last_x > -g->width && anim->last_x < part->viewport_width &&
1254 anim->last_y > -g->height && anim->last_y < part->viewport_height)
1256 part->x = anim->last_x;
1257 part->y = anim->last_y;
1260 if (c->step_xoffset != ARG_UNDEFINED_VALUE)
1261 part->step_xoffset = c->step_xoffset;
1262 if (c->step_yoffset != ARG_UNDEFINED_VALUE)
1263 part->step_yoffset = c->step_yoffset;
1265 if (part->init_delay_counter == 0 &&
1266 !part->init_event_state)
1268 PlayGlobalAnimSoundAndMusic(part);
1270 HandleGlobalAnimEvent(part, ANIM_EVENT_START, "START [ANIM]");
1274 HandleGlobalAnimEvent(part, ANIM_EVENT_INIT, "START [INIT_DELAY/EVENT]");
1278 if (part->clicked &&
1279 part->init_event_state)
1281 if (part->initial_anim_sync_frame > 0)
1282 part->initial_anim_sync_frame -= part->init_delay_counter - 1;
1284 part->init_delay_counter = 1;
1285 part->init_event_state = FALSE;
1287 part->clicked = FALSE;
1290 if (part->clicked &&
1291 part->anim_event_state)
1293 part->anim_delay_counter = 1;
1294 part->anim_event_state = FALSE;
1296 part->clicked = FALSE;
1299 if (part->init_delay_counter > 0)
1301 part->init_delay_counter--;
1303 if (part->init_delay_counter == 0)
1305 part->init_event_state = FALSE;
1307 PlayGlobalAnimSoundAndMusic(part);
1309 HandleGlobalAnimEvent(part, ANIM_EVENT_START, "START [ANIM]");
1312 return ANIM_STATE_WAITING;
1315 if (part->init_event_state)
1316 return ANIM_STATE_WAITING;
1318 // animation part is now running/visible and therefore clickable
1319 part->clickable = TRUE;
1321 // check if moving animation has left the visible screen area
1322 if ((part->x <= -g->width && part->step_xoffset <= 0) ||
1323 (part->x >= part->viewport_width && part->step_xoffset >= 0) ||
1324 (part->y <= -g->height && part->step_yoffset <= 0) ||
1325 (part->y >= part->viewport_height && part->step_yoffset >= 0))
1327 // do not wait for "anim" events for off-screen animations
1328 part->anim_event_state = FALSE;
1330 // do not stop animation before "anim" or "post" counter are finished
1331 if (part->anim_delay_counter == 0 &&
1332 part->post_delay_counter == 0)
1334 StopGlobalAnimSoundAndMusic(part);
1336 HandleGlobalAnimEvent(part, ANIM_EVENT_END, "END [ANIM/OFF-SCREEN]");
1338 part->post_delay_counter =
1339 (c->post_delay_fixed + GetSimpleRandom(c->post_delay_random));
1341 if (part->post_delay_counter > 0)
1342 return ANIM_STATE_RUNNING;
1344 // drawing last frame not needed here -- animation not visible anymore
1345 return ANIM_STATE_RESTART;
1349 if (part->anim_delay_counter > 0)
1351 part->anim_delay_counter--;
1353 if (part->anim_delay_counter == 0)
1355 part->anim_event_state = FALSE;
1357 StopGlobalAnimSoundAndMusic(part);
1359 HandleGlobalAnimEvent(part, ANIM_EVENT_END, "END [ANIM_DELAY/EVENT]");
1361 part->post_delay_counter =
1362 (c->post_delay_fixed + GetSimpleRandom(c->post_delay_random));
1364 if (part->post_delay_counter > 0)
1365 return ANIM_STATE_RUNNING;
1367 // additional state "RUNNING" required to not skip drawing last frame
1368 return ANIM_STATE_RESTART | ANIM_STATE_RUNNING;
1372 if (part->post_delay_counter > 0)
1374 part->post_delay_counter--;
1376 if (part->post_delay_counter == 0)
1378 HandleGlobalAnimEvent(part, ANIM_EVENT_POST, "END [POST_DELAY]");
1380 return ANIM_STATE_RESTART;
1383 return ANIM_STATE_WAITING;
1386 // special case to prevent expiring loop sounds when playing
1387 PlayGlobalAnimSoundIfLoop(part);
1389 if (!DelayReachedExt(&part->step_delay, part->step_delay_value,
1391 return ANIM_STATE_RUNNING;
1395 static unsigned int last_counter = -1;
1396 unsigned int counter = Counter();
1398 printf("::: NEXT ANIM PART [%d, %d]\n",
1399 anim_sync_frame, counter - last_counter);
1401 last_counter = counter;
1405 part->x += part->step_xoffset;
1406 part->y += part->step_yoffset;
1408 anim->last_x = part->x;
1409 anim->last_y = part->y;
1411 return ANIM_STATE_RUNNING;
1414 static void HandleGlobalAnim_Main(struct GlobalAnimMainControlInfo *anim,
1417 struct GlobalAnimPartControlInfo *part;
1418 struct GraphicInfo *c = &anim->control_info;
1419 int num_parts = anim->num_parts + (anim->has_base ? 1 : 0);
1420 int state, active_part_nr;
1424 printf("::: HandleGlobalAnim_Main: %d, %d => %d\n",
1425 anim->mode_nr, anim->nr, anim->num_parts);
1426 printf("::: %d, %d, %d\n", global.num_toons, setup.toons, num_toons);
1430 printf("::: %s(%d): %d, %d, %d [%d]\n",
1431 (action == ANIM_START ? "ANIM_START" :
1432 action == ANIM_CONTINUE ? "ANIM_CONTINUE" :
1433 action == ANIM_STOP ? "ANIM_STOP" : "(should not happen)"),
1435 anim->state & ANIM_STATE_RESTART,
1436 anim->state & ANIM_STATE_WAITING,
1437 anim->state & ANIM_STATE_RUNNING,
1444 anim->state = anim->last_state = ANIM_STATE_RESTART;
1445 anim->active_part_nr = anim->last_active_part_nr = 0;
1446 anim->part_counter = 0;
1451 if (anim->state == ANIM_STATE_INACTIVE)
1454 anim->state = anim->last_state;
1455 anim->active_part_nr = anim->last_active_part_nr;
1460 anim->state = ANIM_STATE_INACTIVE;
1462 for (i = 0; i < num_parts; i++)
1463 StopGlobalAnimSoundAndMusic(&anim->part[i]);
1471 if (c->anim_mode & ANIM_ALL || anim->num_parts == 0)
1474 printf("::: HandleGlobalAnim_Main: %d, %d => %d\n",
1475 anim->mode_nr, anim->nr, num_parts);
1478 for (i = 0; i < num_parts; i++)
1480 part = &anim->part[i];
1485 anim->state = ANIM_STATE_RUNNING;
1486 part->state = ANIM_STATE_RESTART;
1491 if (part->state == ANIM_STATE_INACTIVE)
1497 part->state = ANIM_STATE_INACTIVE;
1505 part->state = HandleGlobalAnim_Part(part, part->state);
1507 // when animation mode is "once", stop after animation was played once
1508 if (c->anim_mode & ANIM_ONCE &&
1509 part->state & ANIM_STATE_RESTART)
1510 part->state = ANIM_STATE_INACTIVE;
1513 anim->last_state = anim->state;
1514 anim->last_active_part_nr = anim->active_part_nr;
1519 if (anim->state & ANIM_STATE_RESTART) // directly after restart
1520 anim->active_part_nr = getGlobalAnimationPart(anim);
1522 part = &anim->part[anim->active_part_nr];
1524 // first set all animation parts to "inactive", ...
1525 for (i = 0; i < num_parts; i++)
1526 anim->part[i].state = ANIM_STATE_INACTIVE;
1528 // ... then set current animation parts to "running"
1529 part->state = ANIM_STATE_RUNNING;
1531 anim->state = HandleGlobalAnim_Part(part, anim->state);
1533 if (anim->state & ANIM_STATE_RESTART)
1534 anim->part_counter++;
1536 // when animation mode is "once", stop after all animations were played once
1537 if (c->anim_mode & ANIM_ONCE &&
1538 anim->part_counter == anim->num_parts)
1539 anim->state = ANIM_STATE_INACTIVE;
1541 state = anim->state;
1542 active_part_nr = anim->active_part_nr;
1544 // while the animation parts are pausing (waiting or inactive), play the base
1545 // (main) animation; this corresponds to the "boring player animation" logic
1546 // (!!! KLUDGE WARNING: I THINK THIS IS A MESS THAT SHOULD BE CLEANED UP !!!)
1549 if (anim->state == ANIM_STATE_WAITING ||
1550 anim->state == ANIM_STATE_INACTIVE)
1552 anim->active_part_nr = anim->num_parts; // part nr of base animation
1553 part = &anim->part[anim->active_part_nr];
1555 if (anim->state != anim->last_state)
1556 part->state = ANIM_STATE_RESTART;
1558 anim->state = ANIM_STATE_RUNNING;
1559 part->state = HandleGlobalAnim_Part(part, part->state);
1563 anim->last_state = state;
1564 anim->last_active_part_nr = active_part_nr;
1567 static void HandleGlobalAnim_Mode(struct GlobalAnimControlInfo *ctrl, int action)
1572 printf("::: HandleGlobalAnim_Mode: %d => %d\n",
1573 ctrl->nr, ctrl->num_anims);
1576 for (i = 0; i < ctrl->num_anims; i++)
1577 HandleGlobalAnim_Main(&ctrl->anim[i], action);
1580 static void HandleGlobalAnim(int action, int game_mode)
1583 printf("::: HandleGlobalAnim [mode == %d]\n", game_status);
1586 HandleGlobalAnim_Mode(&global_anim_ctrl[game_mode], action);
1589 static void DoAnimationExt(void)
1594 printf("::: DoAnimation [%d, %d]\n", anim_sync_frame, Counter());
1597 // global animations now synchronized with frame delay of screen update
1600 for (i = 0; i < NUM_GAME_MODES; i++)
1601 HandleGlobalAnim(ANIM_CONTINUE, i);
1604 // force screen redraw in next frame to continue drawing global animations
1605 redraw_mask = REDRAW_ALL;
1609 static boolean DoGlobalAnim_EventAction(struct GlobalAnimPartControlInfo *part)
1611 int anim_event_action = part->control_info.anim_event_action;
1613 if (anim_event_action == -1)
1616 boolean action_executed = (DoGadgetAction(anim_event_action) ||
1617 DoScreenAction(anim_event_action) ||
1618 DoKeysymAction(anim_event_action));
1620 // check if further actions are allowed to be executed
1621 if (part->control_info.style & STYLE_MULTIPLE_ACTIONS)
1624 return action_executed;
1627 static void InitGlobalAnim_Clickable(void)
1631 for (mode_nr = 0; mode_nr < NUM_GAME_MODES; mode_nr++)
1633 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[mode_nr];
1636 for (anim_nr = 0; anim_nr < ctrl->num_anims; anim_nr++)
1638 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[anim_nr];
1641 for (part_nr = 0; part_nr < anim->num_parts_all; part_nr++)
1643 struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
1645 if (part->triggered)
1646 part->clicked = TRUE;
1648 part->triggered = FALSE;
1649 part->clickable = FALSE;
1655 static boolean InitGlobalAnim_Clicked(int mx, int my, boolean clicked)
1657 boolean anything_clicked = FALSE;
1658 boolean any_part_clicked = FALSE;
1659 boolean any_event_action = FALSE;
1662 // check game modes in reverse draw order (to stop when clicked)
1663 for (mode_nr = NUM_GAME_MODES - 1; mode_nr >= 0; mode_nr--)
1665 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[mode_nr];
1668 // check animations in reverse draw order (to stop when clicked)
1669 for (anim_nr = ctrl->num_anims - 1; anim_nr >= 0; anim_nr--)
1671 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[anim_nr];
1674 // check animation parts in reverse draw order (to stop when clicked)
1675 for (part_nr = anim->num_parts_all - 1; part_nr >= 0; part_nr--)
1677 struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
1681 part->clicked = FALSE;
1686 if (!part->clickable)
1689 if (part->state != ANIM_STATE_RUNNING)
1692 // always handle "any" click events (clicking anywhere on screen) ...
1693 if (isClickablePart(part, ANIM_EVENT_ANY))
1695 #if DEBUG_ANIM_EVENTS
1696 printf("::: => %d.%d TRIGGERED BY ANY\n",
1697 part->old_anim_nr + 1, part->old_nr + 1);
1700 part->clicked = TRUE;
1701 anything_clicked = clickConsumed(part);
1704 // ... but only handle the first (topmost) clickable animation
1705 if (any_part_clicked)
1708 if (isClickedPart(part, mx, my, clicked))
1711 printf("::: %d.%d CLICKED [%d]\n", anim_nr, part_nr,
1712 part->control_info.anim_event_action);
1715 // after executing event action, ignore any further actions
1716 if (!any_event_action && DoGlobalAnim_EventAction(part))
1717 any_event_action = TRUE;
1719 // determine if mouse clicks should be blocked from other animations
1720 any_part_clicked = clickConsumed(part);
1722 if (isClickablePart(part, ANIM_EVENT_SELF))
1724 #if DEBUG_ANIM_EVENTS
1725 printf("::: => %d.%d TRIGGERED BY SELF\n",
1726 part->old_anim_nr + 1, part->old_nr + 1);
1729 part->clicked = TRUE;
1730 anything_clicked = clickConsumed(part);
1733 // check if this click is defined to trigger other animations
1734 InitGlobalAnim_Triggered(part, &anything_clicked, &any_event_action,
1735 ANIM_EVENT_CLICK, "CLICK");
1741 return (anything_clicked || any_event_action);
1744 static void ResetGlobalAnim_Clickable(void)
1746 InitGlobalAnim_Clickable();
1749 static void ResetGlobalAnim_Clicked(void)
1751 InitGlobalAnim_Clicked(-1, -1, FALSE);
1754 boolean HandleGlobalAnimClicks(int mx, int my, int button)
1756 static boolean click_consumed = FALSE;
1757 static int last_button = 0;
1758 boolean press_event;
1759 boolean release_event;
1760 boolean click_consumed_current = click_consumed;
1762 // check if button state has changed since last invocation
1763 press_event = (button != 0 && last_button == 0);
1764 release_event = (button == 0 && last_button != 0);
1765 last_button = button;
1769 click_consumed = InitGlobalAnim_Clicked(mx, my, TRUE);
1770 click_consumed_current = click_consumed;
1774 click_consumed = FALSE;
1776 return click_consumed_current;