1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // http://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
17 /* values for global toon animation definition */
18 #define NUM_GLOBAL_TOON_ANIMS 1
19 #define NUM_GLOBAL_TOON_PARTS MAX_NUM_TOONS
21 /* values for global animation definition (including toons) */
22 #define NUM_GLOBAL_ANIMS_AND_TOONS (NUM_GLOBAL_ANIMS + \
23 NUM_GLOBAL_TOON_ANIMS)
24 #define NUM_GLOBAL_ANIM_PARTS_AND_TOONS MAX(NUM_GLOBAL_ANIM_PARTS_ALL, \
25 NUM_GLOBAL_TOON_PARTS)
27 #define ANIM_CLASS_BIT_TITLE_INITIAL 0
28 #define ANIM_CLASS_BIT_TITLE 1
29 #define ANIM_CLASS_BIT_MAIN 2
30 #define ANIM_CLASS_BIT_SUBMENU 3
31 #define ANIM_CLASS_BIT_MENU 4
32 #define ANIM_CLASS_BIT_TOONS 5
34 #define NUM_ANIM_CLASSES 6
36 #define ANIM_CLASS_NONE 0
37 #define ANIM_CLASS_TITLE_INITIAL (1 << ANIM_CLASS_BIT_TITLE_INITIAL)
38 #define ANIM_CLASS_TITLE (1 << ANIM_CLASS_BIT_TITLE)
39 #define ANIM_CLASS_MAIN (1 << ANIM_CLASS_BIT_MAIN)
40 #define ANIM_CLASS_SUBMENU (1 << ANIM_CLASS_BIT_SUBMENU)
41 #define ANIM_CLASS_MENU (1 << ANIM_CLASS_BIT_MENU)
42 #define ANIM_CLASS_TOONS (1 << ANIM_CLASS_BIT_TOONS)
44 #define ANIM_CLASS_TOONS_MENU_MAIN (ANIM_CLASS_TOONS | \
48 #define ANIM_CLASS_TOONS_MENU_SUBMENU (ANIM_CLASS_TOONS | \
52 struct GlobalAnimPartControlInfo
61 struct GraphicInfo graphic_info;
62 struct GraphicInfo control_info;
70 int step_xoffset, step_yoffset;
72 unsigned int initial_anim_sync_frame;
73 unsigned int step_delay, step_delay_value;
75 int init_delay_counter;
76 int anim_delay_counter;
77 int post_delay_counter;
85 struct GlobalAnimMainControlInfo
87 struct GlobalAnimPartControlInfo base;
88 struct GlobalAnimPartControlInfo part[NUM_GLOBAL_ANIM_PARTS_AND_TOONS];
93 struct GraphicInfo control_info;
101 int init_delay_counter;
105 int last_state, last_active_part_nr;
108 struct GlobalAnimControlInfo
110 struct GlobalAnimMainControlInfo anim[NUM_GLOBAL_ANIMS_AND_TOONS];
116 struct GameModeAnimClass
120 } game_mode_anim_classes_list[] =
122 { GAME_MODE_TITLE_INITIAL_1, ANIM_CLASS_TITLE_INITIAL },
123 { GAME_MODE_TITLE_INITIAL_2, ANIM_CLASS_TITLE_INITIAL },
124 { GAME_MODE_TITLE_INITIAL_3, ANIM_CLASS_TITLE_INITIAL },
125 { GAME_MODE_TITLE_INITIAL_4, ANIM_CLASS_TITLE_INITIAL },
126 { GAME_MODE_TITLE_INITIAL_5, ANIM_CLASS_TITLE_INITIAL },
127 { GAME_MODE_TITLE_1, ANIM_CLASS_TITLE },
128 { GAME_MODE_TITLE_2, ANIM_CLASS_TITLE },
129 { GAME_MODE_TITLE_3, ANIM_CLASS_TITLE },
130 { GAME_MODE_TITLE_4, ANIM_CLASS_TITLE },
131 { GAME_MODE_TITLE_5, ANIM_CLASS_TITLE },
132 { GAME_MODE_LEVELS, ANIM_CLASS_TOONS_MENU_SUBMENU },
133 { GAME_MODE_LEVELNR, ANIM_CLASS_TOONS_MENU_SUBMENU },
134 { GAME_MODE_INFO, ANIM_CLASS_TOONS_MENU_SUBMENU },
135 { GAME_MODE_SETUP, ANIM_CLASS_TOONS_MENU_SUBMENU },
136 { GAME_MODE_PSEUDO_MAINONLY, ANIM_CLASS_TOONS_MENU_MAIN },
137 { GAME_MODE_PSEUDO_TYPENAME, ANIM_CLASS_TOONS_MENU_MAIN },
138 { GAME_MODE_SCORES, ANIM_CLASS_TOONS },
143 struct AnimClassGameMode
147 } anim_class_game_modes_list[] =
149 { ANIM_CLASS_BIT_TITLE_INITIAL, GAME_MODE_TITLE_INITIAL },
150 { ANIM_CLASS_BIT_TITLE, GAME_MODE_TITLE },
151 { ANIM_CLASS_BIT_MAIN, GAME_MODE_MAIN },
152 { ANIM_CLASS_BIT_SUBMENU, GAME_MODE_PSEUDO_SUBMENU },
153 { ANIM_CLASS_BIT_MENU, GAME_MODE_PSEUDO_MENU },
154 { ANIM_CLASS_BIT_TOONS, GAME_MODE_PSEUDO_TOONS },
159 /* forward declaration for internal use */
160 static void HandleGlobalAnim(int, int);
161 static void DoAnimationExt(void);
163 static struct GlobalAnimControlInfo global_anim_ctrl[NUM_GAME_MODES];
165 static unsigned int anim_sync_frame = 0;
167 static int game_mode_anim_classes[NUM_GAME_MODES];
168 static int anim_class_game_modes[NUM_ANIM_CLASSES];
170 static int anim_status_last = GAME_MODE_DEFAULT;
171 static int anim_classes_last = ANIM_CLASS_NONE;
174 static int getGlobalAnimationPart(struct GlobalAnimMainControlInfo *anim)
176 struct GraphicInfo *c = &anim->control_info;
177 int last_anim_random_frame = gfx.anim_random_frame;
180 gfx.anim_random_frame = -1; // (use simple, ad-hoc random numbers)
182 part_nr = getAnimationFrame(anim->num_parts, 1,
183 c->anim_mode, c->anim_start_frame,
186 gfx.anim_random_frame = last_anim_random_frame;
191 static int compareGlobalAnimPartControlInfo(const void *obj1, const void *obj2)
193 const struct GlobalAnimPartControlInfo *o1 =
194 (struct GlobalAnimPartControlInfo *)obj1;
195 const struct GlobalAnimPartControlInfo *o2 =
196 (struct GlobalAnimPartControlInfo *)obj2;
199 if (o1->control_info.draw_order != o2->control_info.draw_order)
200 compare_result = o1->control_info.draw_order - o2->control_info.draw_order;
202 compare_result = o1->nr - o2->nr;
204 return compare_result;
207 static int compareGlobalAnimMainControlInfo(const void *obj1, const void *obj2)
209 const struct GlobalAnimMainControlInfo *o1 =
210 (struct GlobalAnimMainControlInfo *)obj1;
211 const struct GlobalAnimMainControlInfo *o2 =
212 (struct GlobalAnimMainControlInfo *)obj2;
215 if (o1->control_info.draw_order != o2->control_info.draw_order)
216 compare_result = o1->control_info.draw_order - o2->control_info.draw_order;
218 compare_result = o1->nr - o2->nr;
220 return compare_result;
223 static void InitToonControls()
225 int mode_nr_toons = GAME_MODE_PSEUDO_TOONS;
226 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[mode_nr_toons];
227 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[ctrl->num_anims];
228 int mode_nr, anim_nr, part_nr;
229 int control = IMG_INTERNAL_GLOBAL_TOON_DEFAULT;
230 int num_toons = MAX_NUM_TOONS;
233 if (global.num_toons >= 0 && global.num_toons < MAX_NUM_TOONS)
234 num_toons = global.num_toons;
236 mode_nr = mode_nr_toons;
237 anim_nr = ctrl->num_anims;
240 anim->mode_nr = mode_nr;
241 anim->control_info = graphic_info[control];
244 anim->part_counter = 0;
245 anim->active_part_nr = 0;
247 anim->has_base = FALSE;
249 anim->init_delay_counter = 0;
251 anim->state = ANIM_STATE_INACTIVE;
255 for (i = 0; i < num_toons; i++)
257 struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
258 int sound = SND_UNDEFINED;
259 int graphic = IMG_TOON_1 + i;
260 int control = graphic;
263 part->anim_nr = anim_nr;
264 part->mode_nr = mode_nr;
266 part->graphic = graphic;
267 part->graphic_info = graphic_info[graphic];
268 part->control_info = graphic_info[control];
270 part->graphic_info.anim_delay *= part->graphic_info.step_delay;
272 part->control_info.init_delay_fixed = 0;
273 part->control_info.init_delay_random = 150;
275 part->control_info.x = ARG_UNDEFINED_VALUE;
276 part->control_info.y = ARG_UNDEFINED_VALUE;
278 part->initial_anim_sync_frame = 0;
280 part->step_delay = 0;
281 part->step_delay_value = graphic_info[control].step_delay;
283 part->state = ANIM_STATE_INACTIVE;
284 part->last_anim_status = -1;
293 void InitGlobalAnimControls()
296 int mode_nr, anim_nr, part_nr;
297 int sound, graphic, control;
301 for (m = 0; m < NUM_GAME_MODES; m++)
305 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[mode_nr];
312 for (a = 0; a < NUM_GLOBAL_ANIMS; a++)
314 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[anim_nr];
315 int ctrl_id = GLOBAL_ANIM_ID_CONTROL_FIRST + a;
317 control = global_anim_info[ctrl_id].graphic[GLOBAL_ANIM_ID_PART_BASE][m];
319 // if no base animation parameters defined, use default values
320 if (control == IMG_UNDEFINED)
321 control = IMG_INTERNAL_GLOBAL_ANIM_DEFAULT;
324 anim->mode_nr = mode_nr;
325 anim->control_info = graphic_info[control];
328 anim->part_counter = 0;
329 anim->active_part_nr = 0;
331 anim->has_base = FALSE;
333 anim->init_delay_counter = 0;
335 anim->state = ANIM_STATE_INACTIVE;
339 for (p = 0; p < NUM_GLOBAL_ANIM_PARTS_ALL; p++)
341 struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
343 sound = global_anim_info[a].sound[p][m];
344 graphic = global_anim_info[a].graphic[p][m];
345 control = global_anim_info[ctrl_id].graphic[p][m];
347 if (graphic == IMG_UNDEFINED || graphic_info[graphic].bitmap == NULL ||
348 control == IMG_UNDEFINED)
352 printf("::: mode == %d, anim = %d, part = %d [%d, %d, %d] [%d]\n",
353 m, a, p, mode_nr, anim_nr, part_nr, control);
357 printf("::: mode == %d, anim = %d, part = %d [%d, %d, %d] [%d]\n",
358 m, a, p, mode_nr, anim_nr, part_nr, sound);
362 part->anim_nr = anim_nr;
363 part->mode_nr = mode_nr;
365 part->graphic = graphic;
366 part->graphic_info = graphic_info[graphic];
367 part->control_info = graphic_info[control];
369 part->initial_anim_sync_frame = 0;
371 part->step_delay = 0;
372 part->step_delay_value = graphic_info[control].step_delay;
374 part->state = ANIM_STATE_INACTIVE;
375 part->last_anim_status = -1;
377 if (p < GLOBAL_ANIM_ID_PART_BASE)
385 anim->has_base = TRUE;
389 if (anim->num_parts > 0 || anim->has_base)
399 /* sort all animations according to draw_order and animation number */
400 for (m = 0; m < NUM_GAME_MODES; m++)
402 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[m];
404 /* sort all main animations for this game mode */
405 qsort(ctrl->anim, ctrl->num_anims,
406 sizeof(struct GlobalAnimMainControlInfo),
407 compareGlobalAnimMainControlInfo);
409 for (a = 0; a < ctrl->num_anims; a++)
411 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[a];
413 /* sort all animation parts for this main animation */
414 qsort(anim->part, anim->num_parts,
415 sizeof(struct GlobalAnimPartControlInfo),
416 compareGlobalAnimPartControlInfo);
420 for (i = 0; i < NUM_GAME_MODES; i++)
421 game_mode_anim_classes[i] = ANIM_CLASS_NONE;
422 for (i = 0; game_mode_anim_classes_list[i].game_mode != -1; i++)
423 game_mode_anim_classes[game_mode_anim_classes_list[i].game_mode] =
424 game_mode_anim_classes_list[i].class;
426 for (i = 0; i < NUM_ANIM_CLASSES; i++)
427 anim_class_game_modes[i] = GAME_MODE_DEFAULT;
428 for (i = 0; anim_class_game_modes_list[i].game_mode != -1; i++)
429 anim_class_game_modes[anim_class_game_modes_list[i].class_bit] =
430 anim_class_game_modes_list[i].game_mode;
432 anim_status_last = GAME_MODE_LOADING;
433 anim_classes_last = ANIM_CLASS_NONE;
436 void InitGlobalAnimations()
438 InitGlobalAnimControls();
441 void DrawGlobalAnimationsExt(int drawing_stage)
445 if (global.anim_status != anim_status_last)
447 boolean before_fading = (global.anim_status == GAME_MODE_PSEUDO_FADING);
448 boolean after_fading = (anim_status_last == GAME_MODE_PSEUDO_FADING);
449 int anim_classes_next = game_mode_anim_classes[global.anim_status_next];
452 // ---------- part 1 ------------------------------------------------------
453 // start or stop global animations by change of game mode
454 // (special handling of animations for "current screen" and "all screens")
456 // stop animations for last screen
457 HandleGlobalAnim(ANIM_STOP, anim_status_last);
459 // start animations for current screen
460 HandleGlobalAnim(ANIM_START, global.anim_status);
462 // start animations for all screens after loading new artwork set
463 if (anim_status_last == GAME_MODE_LOADING)
464 HandleGlobalAnim(ANIM_START, GAME_MODE_DEFAULT);
466 // ---------- part 2 ------------------------------------------------------
467 // start or stop global animations by change of animation class
468 // (generic handling of animations for "class of screens")
470 for (i = 0; i < NUM_ANIM_CLASSES; i++)
472 int anim_class_check = (1 << i);
473 int anim_class_game_mode = anim_class_game_modes[i];
474 int anim_class_last = anim_classes_last & anim_class_check;
475 int anim_class_next = anim_classes_next & anim_class_check;
477 // stop animations for changed screen class before fading to new screen
478 if (before_fading && anim_class_last && !anim_class_next)
479 HandleGlobalAnim(ANIM_STOP, anim_class_game_mode);
481 // start animations for changed screen class after fading to new screen
482 if (after_fading && !anim_class_last && anim_class_next)
483 HandleGlobalAnim(ANIM_START, anim_class_game_mode);
487 anim_classes_last = anim_classes_next;
489 anim_status_last = global.anim_status;
492 if (!setup.toons || global.anim_status == GAME_MODE_LOADING)
495 if (drawing_stage == DRAW_GLOBAL_ANIM_STAGE_1)
498 for (mode_nr = 0; mode_nr < NUM_GAME_MODES; mode_nr++)
500 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[mode_nr];
504 if (mode_nr != GFX_SPECIAL_ARG_DEFAULT &&
505 mode_nr != game_status)
509 for (anim_nr = 0; anim_nr < ctrl->num_anims; anim_nr++)
511 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[anim_nr];
512 struct GraphicInfo *c = &anim->control_info;
513 int part_first, part_last;
516 if (!(anim->state & ANIM_STATE_RUNNING))
519 part_first = part_last = anim->active_part_nr;
521 if (c->anim_mode & ANIM_ALL || anim->num_parts == 0)
523 int num_parts = anim->num_parts + (anim->has_base ? 1 : 0);
526 part_last = num_parts - 1;
529 for (part_nr = part_first; part_nr <= part_last; part_nr++)
531 struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
532 struct GraphicInfo *g = &part->graphic_info;
535 int width = g->width;
536 int height = g->height;
544 if (!(part->state & ANIM_STATE_RUNNING))
547 if (part->drawing_stage != drawing_stage)
556 else if (part->x > part->viewport_width - g->width)
557 width -= (part->x - (part->viewport_width - g->width));
565 else if (part->y > part->viewport_height - g->height)
566 height -= (part->y - (part->viewport_height - g->height));
568 if (width <= 0 || height <= 0)
571 dst_x += part->viewport_x;
572 dst_y += part->viewport_y;
574 sync_frame = anim_sync_frame - part->initial_anim_sync_frame;
575 frame = getAnimationFrame(g->anim_frames, g->anim_delay,
576 g->anim_mode, g->anim_start_frame,
579 getFixedGraphicSource(part->graphic, frame, &src_bitmap,
585 BlitToScreenMasked(src_bitmap, src_x, src_y, width, height,
592 void DrawGlobalAnimations(int drawing_stage)
594 DrawGlobalAnimationsExt(drawing_stage);
597 boolean SetGlobalAnimPart_Viewport(struct GlobalAnimPartControlInfo *part)
603 boolean changed = FALSE;
605 if (part->last_anim_status == global.anim_status)
608 part->last_anim_status = global.anim_status;
610 part->drawing_stage = DRAW_GLOBAL_ANIM_STAGE_1;
612 if (part->control_info.class == get_hash_from_key("window") ||
613 part->control_info.class == get_hash_from_key("border"))
617 viewport_width = WIN_XSIZE;
618 viewport_height = WIN_YSIZE;
620 part->drawing_stage = DRAW_GLOBAL_ANIM_STAGE_2;
622 else if (part->control_info.class == get_hash_from_key("door_1"))
626 viewport_width = DXSIZE;
627 viewport_height = DYSIZE;
629 else if (part->control_info.class == get_hash_from_key("door_2"))
633 viewport_width = VXSIZE;
634 viewport_height = VYSIZE;
636 else // default: "playfield"
638 viewport_x = REAL_SX;
639 viewport_y = REAL_SY;
640 viewport_width = FULL_SXSIZE;
641 viewport_height = FULL_SYSIZE;
644 if (viewport_x != part->viewport_x ||
645 viewport_y != part->viewport_y ||
646 viewport_width != part->viewport_width ||
647 viewport_height != part->viewport_height)
649 part->viewport_x = viewport_x;
650 part->viewport_y = viewport_y;
651 part->viewport_width = viewport_width;
652 part->viewport_height = viewport_height;
660 void PlayGlobalAnimSound(struct GlobalAnimPartControlInfo *part)
662 int sound = part->sound;
664 if (sound == SND_UNDEFINED)
667 if ((!setup.sound_simple && !IS_LOOP_SOUND(sound)) ||
668 (!setup.sound_loops && IS_LOOP_SOUND(sound)))
671 // !!! TODO: ADD STEREO POSITION FOR MOVING ANIMATIONS !!!
672 if (IS_LOOP_SOUND(sound))
673 PlaySoundLoop(sound);
678 printf("::: PLAY %d.%d.%d: %d\n",
679 part->anim_nr, part->nr, part->mode_nr, sound);
683 void StopGlobalAnimSound(struct GlobalAnimPartControlInfo *part)
685 int sound = part->sound;
687 if (sound == SND_UNDEFINED)
693 printf("::: STOP %d.%d.%d: %d\n",
694 part->anim_nr, part->nr, part->mode_nr, sound);
698 int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, int state)
700 struct GraphicInfo *g = &part->graphic_info;
701 struct GraphicInfo *c = &part->control_info;
702 boolean viewport_changed = SetGlobalAnimPart_Viewport(part);
704 if (viewport_changed)
705 state |= ANIM_STATE_RESTART;
707 if (state & ANIM_STATE_RESTART)
709 ResetDelayCounterExt(&part->step_delay, anim_sync_frame);
711 part->init_delay_counter =
712 (c->init_delay_fixed + GetSimpleRandom(c->init_delay_random));
714 part->anim_delay_counter =
715 (c->anim_delay_fixed + GetSimpleRandom(c->anim_delay_random));
717 part->initial_anim_sync_frame =
718 (g->anim_global_sync ? 0 : anim_sync_frame + part->init_delay_counter);
720 if (c->direction & MV_HORIZONTAL)
722 int pos_bottom = part->viewport_height - g->height;
724 if (c->position == POS_TOP)
726 else if (c->position == POS_UPPER)
727 part->y = GetSimpleRandom(pos_bottom / 2);
728 else if (c->position == POS_MIDDLE)
729 part->y = pos_bottom / 2;
730 else if (c->position == POS_LOWER)
731 part->y = pos_bottom / 2 + GetSimpleRandom(pos_bottom / 2);
732 else if (c->position == POS_BOTTOM)
733 part->y = pos_bottom;
735 part->y = GetSimpleRandom(pos_bottom);
737 if (c->direction == MV_RIGHT)
739 part->step_xoffset = c->step_offset;
740 part->x = -g->width + part->step_xoffset;
744 part->step_xoffset = -c->step_offset;
745 part->x = part->viewport_width + part->step_xoffset;
748 part->step_yoffset = 0;
750 else if (c->direction & MV_VERTICAL)
752 int pos_right = part->viewport_width - g->width;
754 if (c->position == POS_LEFT)
756 else if (c->position == POS_RIGHT)
759 part->x = GetSimpleRandom(pos_right);
761 if (c->direction == MV_DOWN)
763 part->step_yoffset = c->step_offset;
764 part->y = -g->height + part->step_yoffset;
768 part->step_yoffset = -c->step_offset;
769 part->y = part->viewport_height + part->step_yoffset;
772 part->step_xoffset = 0;
779 part->step_xoffset = 0;
780 part->step_yoffset = 0;
783 if (c->x != ARG_UNDEFINED_VALUE)
785 if (c->y != ARG_UNDEFINED_VALUE)
788 if (c->step_xoffset != ARG_UNDEFINED_VALUE)
789 part->step_xoffset = c->step_xoffset;
790 if (c->step_yoffset != ARG_UNDEFINED_VALUE)
791 part->step_yoffset = c->step_yoffset;
793 if (part->init_delay_counter == 0)
794 PlayGlobalAnimSound(part);
797 if (part->init_delay_counter > 0)
799 part->init_delay_counter--;
801 if (part->init_delay_counter == 0)
802 PlayGlobalAnimSound(part);
804 return ANIM_STATE_WAITING;
807 // check if moving animation has left the visible screen area
808 if ((part->x <= -g->width && part->step_xoffset <= 0) ||
809 (part->x >= part->viewport_width && part->step_xoffset >= 0) ||
810 (part->y <= -g->height && part->step_yoffset <= 0) ||
811 (part->y >= part->viewport_height && part->step_yoffset >= 0))
813 // do not stop animation before "anim" or "post" counter are finished
814 if (part->anim_delay_counter == 0 &&
815 part->post_delay_counter == 0)
817 StopGlobalAnimSound(part);
819 part->post_delay_counter =
820 (c->post_delay_fixed + GetSimpleRandom(c->post_delay_random));
822 if (part->post_delay_counter > 0)
823 return ANIM_STATE_RUNNING;
825 // drawing last frame not needed here -- animation not visible anymore
826 return ANIM_STATE_RESTART;
830 if (part->anim_delay_counter > 0)
832 part->anim_delay_counter--;
834 if (part->anim_delay_counter == 0)
836 StopGlobalAnimSound(part);
838 part->post_delay_counter =
839 (c->post_delay_fixed + GetSimpleRandom(c->post_delay_random));
841 if (part->post_delay_counter > 0)
842 return ANIM_STATE_RUNNING;
844 // additional state "RUNNING" required to not skip drawing last frame
845 return ANIM_STATE_RESTART | ANIM_STATE_RUNNING;
849 if (part->post_delay_counter > 0)
851 part->post_delay_counter--;
853 if (part->post_delay_counter == 0)
854 return ANIM_STATE_RESTART;
856 return ANIM_STATE_WAITING;
859 if (!DelayReachedExt(&part->step_delay, part->step_delay_value,
861 return ANIM_STATE_RUNNING;
865 static unsigned int last_counter = -1;
866 unsigned int counter = Counter();
868 printf("::: NEXT ANIM PART [%d, %d]\n",
869 anim_sync_frame, counter - last_counter);
871 last_counter = counter;
875 part->x += part->step_xoffset;
876 part->y += part->step_yoffset;
878 return ANIM_STATE_RUNNING;
881 void HandleGlobalAnim_Main(struct GlobalAnimMainControlInfo *anim, int action)
883 struct GlobalAnimPartControlInfo *part;
884 struct GraphicInfo *c = &anim->control_info;
885 int state, active_part_nr;
888 printf("::: HandleGlobalAnim_Main: %d, %d => %d\n",
889 anim->mode_nr, anim->nr, anim->num_parts);
890 printf("::: %d, %d, %d\n", global.num_toons, setup.toons, num_toons);
894 printf("::: %s(%d): %d, %d, %d [%d]\n",
895 (action == ANIM_START ? "ANIM_START" :
896 action == ANIM_CONTINUE ? "ANIM_CONTINUE" :
897 action == ANIM_STOP ? "ANIM_STOP" : "(should not happen)"),
899 anim->state & ANIM_STATE_RESTART,
900 anim->state & ANIM_STATE_WAITING,
901 anim->state & ANIM_STATE_RUNNING,
908 anim->state = anim->last_state = ANIM_STATE_RESTART;
909 anim->active_part_nr = anim->last_active_part_nr = 0;
910 anim->part_counter = 0;
915 if (anim->state == ANIM_STATE_INACTIVE)
918 anim->state = anim->last_state;
919 anim->active_part_nr = anim->last_active_part_nr;
924 anim->state = ANIM_STATE_INACTIVE;
927 int num_parts = anim->num_parts + (anim->has_base ? 1 : 0);
930 for (i = 0; i < num_parts; i++)
931 StopGlobalAnimSound(&anim->part[i]);
940 if (c->anim_mode & ANIM_ALL || anim->num_parts == 0)
942 int num_parts = anim->num_parts + (anim->has_base ? 1 : 0);
946 printf("::: HandleGlobalAnim_Main: %d, %d => %d\n",
947 anim->mode_nr, anim->nr, num_parts);
950 for (i = 0; i < num_parts; i++)
952 part = &anim->part[i];
957 anim->state = ANIM_STATE_RUNNING;
958 part->state = ANIM_STATE_RESTART;
963 if (part->state == ANIM_STATE_INACTIVE)
969 part->state = ANIM_STATE_INACTIVE;
977 part->state = HandleGlobalAnim_Part(part, part->state);
979 // when animation mode is "once", stop after animation was played once
980 if (c->anim_mode & ANIM_ONCE &&
981 part->state & ANIM_STATE_RESTART)
982 part->state = ANIM_STATE_INACTIVE;
985 anim->last_state = anim->state;
986 anim->last_active_part_nr = anim->active_part_nr;
991 if (anim->state & ANIM_STATE_RESTART) // directly after restart
992 anim->active_part_nr = getGlobalAnimationPart(anim);
994 part = &anim->part[anim->active_part_nr];
996 part->state = ANIM_STATE_RUNNING;
998 anim->state = HandleGlobalAnim_Part(part, anim->state);
1000 if (anim->state & ANIM_STATE_RESTART)
1001 anim->part_counter++;
1003 // when animation mode is "once", stop after all animations were played once
1004 if (c->anim_mode & ANIM_ONCE &&
1005 anim->part_counter == anim->num_parts)
1006 anim->state = ANIM_STATE_INACTIVE;
1008 state = anim->state;
1009 active_part_nr = anim->active_part_nr;
1011 // while the animation parts are pausing (waiting or inactive), play the base
1012 // (main) animation; this corresponds to the "boring player animation" logic
1013 // (!!! KLUDGE WARNING: I THINK THIS IS A MESS THAT SHOULD BE CLEANED UP !!!)
1016 if (anim->state == ANIM_STATE_WAITING ||
1017 anim->state == ANIM_STATE_INACTIVE)
1019 anim->active_part_nr = anim->num_parts; // part nr of base animation
1020 part = &anim->part[anim->active_part_nr];
1022 if (anim->state != anim->last_state)
1023 part->state = ANIM_STATE_RESTART;
1025 anim->state = ANIM_STATE_RUNNING;
1026 part->state = HandleGlobalAnim_Part(part, part->state);
1030 anim->last_state = state;
1031 anim->last_active_part_nr = active_part_nr;
1034 void HandleGlobalAnim_Mode(struct GlobalAnimControlInfo *ctrl, int action)
1039 printf("::: HandleGlobalAnim_Mode: %d => %d\n",
1040 ctrl->nr, ctrl->num_anims);
1043 for (i = 0; i < ctrl->num_anims; i++)
1044 HandleGlobalAnim_Main(&ctrl->anim[i], action);
1047 static void HandleGlobalAnim(int action, int game_mode)
1050 printf("::: HandleGlobalAnim [mode == %d]\n", game_status);
1053 HandleGlobalAnim_Mode(&global_anim_ctrl[game_mode], action);
1056 static void DoAnimationExt()
1061 printf("::: DoAnimation [%d, %d]\n", anim_sync_frame, Counter());
1064 // global animations now synchronized with frame delay of screen update
1067 for (i = 0; i < NUM_GAME_MODES; i++)
1068 HandleGlobalAnim(ANIM_CONTINUE, i);
1071 // force screen redraw in next frame to continue drawing global animations
1072 redraw_mask = REDRAW_ALL;