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 /* values for global animation states */
53 #define ANIM_STATE_INACTIVE 0
54 #define ANIM_STATE_RESTART (1 << 0)
55 #define ANIM_STATE_WAITING (1 << 1)
56 #define ANIM_STATE_RUNNING (1 << 2)
58 /* values for global animation control */
60 #define ANIM_CONTINUE 1
64 struct GlobalAnimPartControlInfo
73 struct GraphicInfo graphic_info;
74 struct GraphicInfo control_info;
82 int step_xoffset, step_yoffset;
84 unsigned int initial_anim_sync_frame;
85 unsigned int step_delay, step_delay_value;
87 int init_delay_counter;
88 int anim_delay_counter;
89 int post_delay_counter;
97 struct GlobalAnimMainControlInfo
99 struct GlobalAnimPartControlInfo base;
100 struct GlobalAnimPartControlInfo part[NUM_GLOBAL_ANIM_PARTS_AND_TOONS];
105 struct GraphicInfo control_info;
113 int init_delay_counter;
117 int last_state, last_active_part_nr;
120 struct GlobalAnimControlInfo
122 struct GlobalAnimMainControlInfo anim[NUM_GLOBAL_ANIMS_AND_TOONS];
128 struct GameModeAnimClass
132 } game_mode_anim_classes_list[] =
134 { GAME_MODE_TITLE_INITIAL_1, ANIM_CLASS_TITLE_INITIAL },
135 { GAME_MODE_TITLE_INITIAL_2, ANIM_CLASS_TITLE_INITIAL },
136 { GAME_MODE_TITLE_INITIAL_3, ANIM_CLASS_TITLE_INITIAL },
137 { GAME_MODE_TITLE_INITIAL_4, ANIM_CLASS_TITLE_INITIAL },
138 { GAME_MODE_TITLE_INITIAL_5, ANIM_CLASS_TITLE_INITIAL },
139 { GAME_MODE_TITLE_1, ANIM_CLASS_TITLE },
140 { GAME_MODE_TITLE_2, ANIM_CLASS_TITLE },
141 { GAME_MODE_TITLE_3, ANIM_CLASS_TITLE },
142 { GAME_MODE_TITLE_4, ANIM_CLASS_TITLE },
143 { GAME_MODE_TITLE_5, ANIM_CLASS_TITLE },
144 { GAME_MODE_LEVELS, ANIM_CLASS_TOONS_MENU_SUBMENU },
145 { GAME_MODE_LEVELNR, ANIM_CLASS_TOONS_MENU_SUBMENU },
146 { GAME_MODE_INFO, ANIM_CLASS_TOONS_MENU_SUBMENU },
147 { GAME_MODE_SETUP, ANIM_CLASS_TOONS_MENU_SUBMENU },
148 { GAME_MODE_PSEUDO_MAINONLY, ANIM_CLASS_TOONS_MENU_MAIN },
149 { GAME_MODE_PSEUDO_TYPENAME, ANIM_CLASS_TOONS_MENU_MAIN },
150 { GAME_MODE_SCORES, ANIM_CLASS_TOONS },
155 struct AnimClassGameMode
159 } anim_class_game_modes_list[] =
161 { ANIM_CLASS_BIT_TITLE_INITIAL, GAME_MODE_TITLE_INITIAL },
162 { ANIM_CLASS_BIT_TITLE, GAME_MODE_TITLE },
163 { ANIM_CLASS_BIT_MAIN, GAME_MODE_MAIN },
164 { ANIM_CLASS_BIT_SUBMENU, GAME_MODE_PSEUDO_SUBMENU },
165 { ANIM_CLASS_BIT_MENU, GAME_MODE_PSEUDO_MENU },
166 { ANIM_CLASS_BIT_TOONS, GAME_MODE_PSEUDO_TOONS },
171 /* forward declaration for internal use */
172 static void HandleGlobalAnim(int, int);
173 static void DoAnimationExt(void);
175 static struct GlobalAnimControlInfo global_anim_ctrl[NUM_GAME_MODES];
177 static unsigned int anim_sync_frame = 0;
179 static int game_mode_anim_classes[NUM_GAME_MODES];
180 static int anim_class_game_modes[NUM_ANIM_CLASSES];
182 static int anim_status_last = GAME_MODE_DEFAULT;
183 static int anim_classes_last = ANIM_CLASS_NONE;
186 /* ========================================================================= */
187 /* generic animation frame calculation */
188 /* ========================================================================= */
190 int getAnimationFrame(int num_frames, int delay, int mode, int start_frame,
195 sync_frame += start_frame * delay;
197 if (mode & ANIM_LOOP) /* looping animation */
199 frame = (sync_frame % (delay * num_frames)) / delay;
201 else if (mode & ANIM_LINEAR) /* linear (non-looping) animation */
203 frame = sync_frame / delay;
205 if (frame > num_frames - 1)
206 frame = num_frames - 1;
208 else if (mode & ANIM_PINGPONG) /* oscillate (border frames once) */
210 int max_anim_frames = (num_frames > 1 ? 2 * num_frames - 2 : 1);
212 frame = (sync_frame % (delay * max_anim_frames)) / delay;
213 frame = (frame < num_frames ? frame : max_anim_frames - frame);
215 else if (mode & ANIM_PINGPONG2) /* oscillate (border frames twice) */
217 int max_anim_frames = 2 * num_frames;
219 frame = (sync_frame % (delay * max_anim_frames)) / delay;
220 frame = (frame < num_frames ? frame : max_anim_frames - frame - 1);
222 else if (mode & ANIM_RANDOM) /* play frames in random order */
224 /* note: expect different frames for the same delay cycle! */
226 if (gfx.anim_random_frame < 0)
227 frame = GetSimpleRandom(num_frames);
229 frame = gfx.anim_random_frame % num_frames;
231 else if (mode & (ANIM_CE_VALUE | ANIM_CE_SCORE | ANIM_CE_DELAY))
233 frame = sync_frame % num_frames;
236 if (mode & ANIM_REVERSE) /* use reverse animation direction */
237 frame = num_frames - frame - 1;
243 /* ========================================================================= */
244 /* global animation functions */
245 /* ========================================================================= */
247 static int getGlobalAnimationPart(struct GlobalAnimMainControlInfo *anim)
249 struct GraphicInfo *c = &anim->control_info;
250 int last_anim_random_frame = gfx.anim_random_frame;
253 gfx.anim_random_frame = -1; // (use simple, ad-hoc random numbers)
255 part_nr = getAnimationFrame(anim->num_parts, 1,
256 c->anim_mode, c->anim_start_frame,
259 gfx.anim_random_frame = last_anim_random_frame;
264 static int compareGlobalAnimPartControlInfo(const void *obj1, const void *obj2)
266 const struct GlobalAnimPartControlInfo *o1 =
267 (struct GlobalAnimPartControlInfo *)obj1;
268 const struct GlobalAnimPartControlInfo *o2 =
269 (struct GlobalAnimPartControlInfo *)obj2;
272 if (o1->control_info.draw_order != o2->control_info.draw_order)
273 compare_result = o1->control_info.draw_order - o2->control_info.draw_order;
275 compare_result = o1->nr - o2->nr;
277 return compare_result;
280 static int compareGlobalAnimMainControlInfo(const void *obj1, const void *obj2)
282 const struct GlobalAnimMainControlInfo *o1 =
283 (struct GlobalAnimMainControlInfo *)obj1;
284 const struct GlobalAnimMainControlInfo *o2 =
285 (struct GlobalAnimMainControlInfo *)obj2;
288 if (o1->control_info.draw_order != o2->control_info.draw_order)
289 compare_result = o1->control_info.draw_order - o2->control_info.draw_order;
291 compare_result = o1->nr - o2->nr;
293 return compare_result;
296 static void InitToonControls()
298 int mode_nr_toons = GAME_MODE_PSEUDO_TOONS;
299 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[mode_nr_toons];
300 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[ctrl->num_anims];
301 int mode_nr, anim_nr, part_nr;
302 int control = IMG_INTERNAL_GLOBAL_TOON_DEFAULT;
303 int num_toons = MAX_NUM_TOONS;
306 if (global.num_toons >= 0 && global.num_toons < MAX_NUM_TOONS)
307 num_toons = global.num_toons;
309 mode_nr = mode_nr_toons;
310 anim_nr = ctrl->num_anims;
313 anim->mode_nr = mode_nr;
314 anim->control_info = graphic_info[control];
317 anim->part_counter = 0;
318 anim->active_part_nr = 0;
320 anim->has_base = FALSE;
322 anim->init_delay_counter = 0;
324 anim->state = ANIM_STATE_INACTIVE;
328 for (i = 0; i < num_toons; i++)
330 struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
331 int sound = SND_UNDEFINED;
332 int graphic = IMG_TOON_1 + i;
333 int control = graphic;
336 part->anim_nr = anim_nr;
337 part->mode_nr = mode_nr;
339 part->graphic = graphic;
340 part->graphic_info = graphic_info[graphic];
341 part->control_info = graphic_info[control];
343 part->graphic_info.anim_delay *= part->graphic_info.step_delay;
345 part->control_info.init_delay_fixed = 0;
346 part->control_info.init_delay_random = 150;
348 part->control_info.x = ARG_UNDEFINED_VALUE;
349 part->control_info.y = ARG_UNDEFINED_VALUE;
351 part->initial_anim_sync_frame = 0;
353 part->step_delay = 0;
354 part->step_delay_value = graphic_info[control].step_delay;
356 part->state = ANIM_STATE_INACTIVE;
357 part->last_anim_status = -1;
366 void InitGlobalAnimControls()
369 int mode_nr, anim_nr, part_nr;
370 int sound, graphic, control;
374 for (m = 0; m < NUM_GAME_MODES; m++)
378 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[mode_nr];
385 for (a = 0; a < NUM_GLOBAL_ANIMS; a++)
387 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[anim_nr];
388 int ctrl_id = GLOBAL_ANIM_ID_CONTROL_FIRST + a;
390 control = global_anim_info[ctrl_id].graphic[GLOBAL_ANIM_ID_PART_BASE][m];
392 // if no base animation parameters defined, use default values
393 if (control == IMG_UNDEFINED)
394 control = IMG_INTERNAL_GLOBAL_ANIM_DEFAULT;
397 anim->mode_nr = mode_nr;
398 anim->control_info = graphic_info[control];
401 anim->part_counter = 0;
402 anim->active_part_nr = 0;
404 anim->has_base = FALSE;
406 anim->init_delay_counter = 0;
408 anim->state = ANIM_STATE_INACTIVE;
412 for (p = 0; p < NUM_GLOBAL_ANIM_PARTS_ALL; p++)
414 struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
416 sound = global_anim_info[a].sound[p][m];
417 graphic = global_anim_info[a].graphic[p][m];
418 control = global_anim_info[ctrl_id].graphic[p][m];
420 if (graphic == IMG_UNDEFINED || graphic_info[graphic].bitmap == NULL ||
421 control == IMG_UNDEFINED)
425 printf("::: mode == %d, anim = %d, part = %d [%d, %d, %d] [%d]\n",
426 m, a, p, mode_nr, anim_nr, part_nr, control);
430 printf("::: mode == %d, anim = %d, part = %d [%d, %d, %d] [%d]\n",
431 m, a, p, mode_nr, anim_nr, part_nr, sound);
435 part->anim_nr = anim_nr;
436 part->mode_nr = mode_nr;
438 part->graphic = graphic;
439 part->graphic_info = graphic_info[graphic];
440 part->control_info = graphic_info[control];
442 part->initial_anim_sync_frame = 0;
444 part->step_delay = 0;
445 part->step_delay_value = graphic_info[control].step_delay;
447 part->state = ANIM_STATE_INACTIVE;
448 part->last_anim_status = -1;
450 if (p < GLOBAL_ANIM_ID_PART_BASE)
458 anim->has_base = TRUE;
462 if (anim->num_parts > 0 || anim->has_base)
472 /* sort all animations according to draw_order and animation number */
473 for (m = 0; m < NUM_GAME_MODES; m++)
475 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[m];
477 /* sort all main animations for this game mode */
478 qsort(ctrl->anim, ctrl->num_anims,
479 sizeof(struct GlobalAnimMainControlInfo),
480 compareGlobalAnimMainControlInfo);
482 for (a = 0; a < ctrl->num_anims; a++)
484 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[a];
486 /* sort all animation parts for this main animation */
487 qsort(anim->part, anim->num_parts,
488 sizeof(struct GlobalAnimPartControlInfo),
489 compareGlobalAnimPartControlInfo);
493 for (i = 0; i < NUM_GAME_MODES; i++)
494 game_mode_anim_classes[i] = ANIM_CLASS_NONE;
495 for (i = 0; game_mode_anim_classes_list[i].game_mode != -1; i++)
496 game_mode_anim_classes[game_mode_anim_classes_list[i].game_mode] =
497 game_mode_anim_classes_list[i].class;
499 for (i = 0; i < NUM_ANIM_CLASSES; i++)
500 anim_class_game_modes[i] = GAME_MODE_DEFAULT;
501 for (i = 0; anim_class_game_modes_list[i].game_mode != -1; i++)
502 anim_class_game_modes[anim_class_game_modes_list[i].class_bit] =
503 anim_class_game_modes_list[i].game_mode;
505 anim_status_last = GAME_MODE_LOADING;
506 anim_classes_last = ANIM_CLASS_NONE;
509 void InitGlobalAnimations()
511 InitGlobalAnimControls();
514 void DrawGlobalAnimationsExt(int drawing_stage)
518 if (global.anim_status != anim_status_last)
520 boolean before_fading = (global.anim_status == GAME_MODE_PSEUDO_FADING);
521 boolean after_fading = (anim_status_last == GAME_MODE_PSEUDO_FADING);
522 int anim_classes_next = game_mode_anim_classes[global.anim_status_next];
525 // ---------- part 1 ------------------------------------------------------
526 // start or stop global animations by change of game mode
527 // (special handling of animations for "current screen" and "all screens")
529 // stop animations for last screen
530 HandleGlobalAnim(ANIM_STOP, anim_status_last);
532 // start animations for current screen
533 HandleGlobalAnim(ANIM_START, global.anim_status);
535 // start animations for all screens after loading new artwork set
536 if (anim_status_last == GAME_MODE_LOADING)
537 HandleGlobalAnim(ANIM_START, GAME_MODE_DEFAULT);
539 // ---------- part 2 ------------------------------------------------------
540 // start or stop global animations by change of animation class
541 // (generic handling of animations for "class of screens")
543 for (i = 0; i < NUM_ANIM_CLASSES; i++)
545 int anim_class_check = (1 << i);
546 int anim_class_game_mode = anim_class_game_modes[i];
547 int anim_class_last = anim_classes_last & anim_class_check;
548 int anim_class_next = anim_classes_next & anim_class_check;
550 // stop animations for changed screen class before fading to new screen
551 if (before_fading && anim_class_last && !anim_class_next)
552 HandleGlobalAnim(ANIM_STOP, anim_class_game_mode);
554 // start animations for changed screen class after fading to new screen
555 if (after_fading && !anim_class_last && anim_class_next)
556 HandleGlobalAnim(ANIM_START, anim_class_game_mode);
560 anim_classes_last = anim_classes_next;
562 anim_status_last = global.anim_status;
565 if (!setup.toons || global.anim_status == GAME_MODE_LOADING)
568 if (drawing_stage == DRAW_GLOBAL_ANIM_STAGE_1)
571 for (mode_nr = 0; mode_nr < NUM_GAME_MODES; mode_nr++)
573 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[mode_nr];
577 if (mode_nr != GFX_SPECIAL_ARG_DEFAULT &&
578 mode_nr != game_status)
582 for (anim_nr = 0; anim_nr < ctrl->num_anims; anim_nr++)
584 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[anim_nr];
585 struct GraphicInfo *c = &anim->control_info;
586 int part_first, part_last;
589 if (!(anim->state & ANIM_STATE_RUNNING))
592 part_first = part_last = anim->active_part_nr;
594 if (c->anim_mode & ANIM_ALL || anim->num_parts == 0)
596 int num_parts = anim->num_parts + (anim->has_base ? 1 : 0);
599 part_last = num_parts - 1;
602 for (part_nr = part_first; part_nr <= part_last; part_nr++)
604 struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
605 struct GraphicInfo *g = &part->graphic_info;
608 int width = g->width;
609 int height = g->height;
617 if (!(part->state & ANIM_STATE_RUNNING))
620 if (part->drawing_stage != drawing_stage)
629 else if (part->x > part->viewport_width - g->width)
630 width -= (part->x - (part->viewport_width - g->width));
638 else if (part->y > part->viewport_height - g->height)
639 height -= (part->y - (part->viewport_height - g->height));
641 if (width <= 0 || height <= 0)
644 dst_x += part->viewport_x;
645 dst_y += part->viewport_y;
647 sync_frame = anim_sync_frame - part->initial_anim_sync_frame;
648 frame = getAnimationFrame(g->anim_frames, g->anim_delay,
649 g->anim_mode, g->anim_start_frame,
652 getFixedGraphicSource(part->graphic, frame, &src_bitmap,
658 BlitToScreenMasked(src_bitmap, src_x, src_y, width, height,
665 void DrawGlobalAnimations(int drawing_stage)
667 DrawGlobalAnimationsExt(drawing_stage);
670 boolean SetGlobalAnimPart_Viewport(struct GlobalAnimPartControlInfo *part)
676 boolean changed = FALSE;
678 if (part->last_anim_status == global.anim_status)
681 part->last_anim_status = global.anim_status;
683 part->drawing_stage = DRAW_GLOBAL_ANIM_STAGE_1;
685 if (part->control_info.class == get_hash_from_key("window") ||
686 part->control_info.class == get_hash_from_key("border"))
690 viewport_width = WIN_XSIZE;
691 viewport_height = WIN_YSIZE;
693 part->drawing_stage = DRAW_GLOBAL_ANIM_STAGE_2;
695 else if (part->control_info.class == get_hash_from_key("door_1"))
699 viewport_width = DXSIZE;
700 viewport_height = DYSIZE;
702 else if (part->control_info.class == get_hash_from_key("door_2"))
706 viewport_width = VXSIZE;
707 viewport_height = VYSIZE;
709 else // default: "playfield"
711 viewport_x = REAL_SX;
712 viewport_y = REAL_SY;
713 viewport_width = FULL_SXSIZE;
714 viewport_height = FULL_SYSIZE;
717 if (viewport_x != part->viewport_x ||
718 viewport_y != part->viewport_y ||
719 viewport_width != part->viewport_width ||
720 viewport_height != part->viewport_height)
722 part->viewport_x = viewport_x;
723 part->viewport_y = viewport_y;
724 part->viewport_width = viewport_width;
725 part->viewport_height = viewport_height;
733 void PlayGlobalAnimSound(struct GlobalAnimPartControlInfo *part)
735 int sound = part->sound;
737 if (sound == SND_UNDEFINED)
740 if ((!setup.sound_simple && !IS_LOOP_SOUND(sound)) ||
741 (!setup.sound_loops && IS_LOOP_SOUND(sound)))
744 // !!! TODO: ADD STEREO POSITION FOR MOVING ANIMATIONS !!!
745 if (IS_LOOP_SOUND(sound))
746 PlaySoundLoop(sound);
751 printf("::: PLAY %d.%d.%d: %d\n",
752 part->anim_nr, part->nr, part->mode_nr, sound);
756 void StopGlobalAnimSound(struct GlobalAnimPartControlInfo *part)
758 int sound = part->sound;
760 if (sound == SND_UNDEFINED)
766 printf("::: STOP %d.%d.%d: %d\n",
767 part->anim_nr, part->nr, part->mode_nr, sound);
771 int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, int state)
773 struct GraphicInfo *g = &part->graphic_info;
774 struct GraphicInfo *c = &part->control_info;
775 boolean viewport_changed = SetGlobalAnimPart_Viewport(part);
777 if (viewport_changed)
778 state |= ANIM_STATE_RESTART;
780 if (state & ANIM_STATE_RESTART)
782 ResetDelayCounterExt(&part->step_delay, anim_sync_frame);
784 part->init_delay_counter =
785 (c->init_delay_fixed + GetSimpleRandom(c->init_delay_random));
787 part->anim_delay_counter =
788 (c->anim_delay_fixed + GetSimpleRandom(c->anim_delay_random));
790 part->initial_anim_sync_frame =
791 (g->anim_global_sync ? 0 : anim_sync_frame + part->init_delay_counter);
793 if (c->direction & MV_HORIZONTAL)
795 int pos_bottom = part->viewport_height - g->height;
797 if (c->position == POS_TOP)
799 else if (c->position == POS_UPPER)
800 part->y = GetSimpleRandom(pos_bottom / 2);
801 else if (c->position == POS_MIDDLE)
802 part->y = pos_bottom / 2;
803 else if (c->position == POS_LOWER)
804 part->y = pos_bottom / 2 + GetSimpleRandom(pos_bottom / 2);
805 else if (c->position == POS_BOTTOM)
806 part->y = pos_bottom;
808 part->y = GetSimpleRandom(pos_bottom);
810 if (c->direction == MV_RIGHT)
812 part->step_xoffset = c->step_offset;
813 part->x = -g->width + part->step_xoffset;
817 part->step_xoffset = -c->step_offset;
818 part->x = part->viewport_width + part->step_xoffset;
821 part->step_yoffset = 0;
823 else if (c->direction & MV_VERTICAL)
825 int pos_right = part->viewport_width - g->width;
827 if (c->position == POS_LEFT)
829 else if (c->position == POS_RIGHT)
832 part->x = GetSimpleRandom(pos_right);
834 if (c->direction == MV_DOWN)
836 part->step_yoffset = c->step_offset;
837 part->y = -g->height + part->step_yoffset;
841 part->step_yoffset = -c->step_offset;
842 part->y = part->viewport_height + part->step_yoffset;
845 part->step_xoffset = 0;
852 part->step_xoffset = 0;
853 part->step_yoffset = 0;
856 if (c->x != ARG_UNDEFINED_VALUE)
858 if (c->y != ARG_UNDEFINED_VALUE)
861 if (c->step_xoffset != ARG_UNDEFINED_VALUE)
862 part->step_xoffset = c->step_xoffset;
863 if (c->step_yoffset != ARG_UNDEFINED_VALUE)
864 part->step_yoffset = c->step_yoffset;
866 if (part->init_delay_counter == 0)
867 PlayGlobalAnimSound(part);
870 if (part->init_delay_counter > 0)
872 part->init_delay_counter--;
874 if (part->init_delay_counter == 0)
875 PlayGlobalAnimSound(part);
877 return ANIM_STATE_WAITING;
880 // check if moving animation has left the visible screen area
881 if ((part->x <= -g->width && part->step_xoffset <= 0) ||
882 (part->x >= part->viewport_width && part->step_xoffset >= 0) ||
883 (part->y <= -g->height && part->step_yoffset <= 0) ||
884 (part->y >= part->viewport_height && part->step_yoffset >= 0))
886 // do not stop animation before "anim" or "post" counter are finished
887 if (part->anim_delay_counter == 0 &&
888 part->post_delay_counter == 0)
890 StopGlobalAnimSound(part);
892 part->post_delay_counter =
893 (c->post_delay_fixed + GetSimpleRandom(c->post_delay_random));
895 if (part->post_delay_counter > 0)
896 return ANIM_STATE_RUNNING;
898 // drawing last frame not needed here -- animation not visible anymore
899 return ANIM_STATE_RESTART;
903 if (part->anim_delay_counter > 0)
905 part->anim_delay_counter--;
907 if (part->anim_delay_counter == 0)
909 StopGlobalAnimSound(part);
911 part->post_delay_counter =
912 (c->post_delay_fixed + GetSimpleRandom(c->post_delay_random));
914 if (part->post_delay_counter > 0)
915 return ANIM_STATE_RUNNING;
917 // additional state "RUNNING" required to not skip drawing last frame
918 return ANIM_STATE_RESTART | ANIM_STATE_RUNNING;
922 if (part->post_delay_counter > 0)
924 part->post_delay_counter--;
926 if (part->post_delay_counter == 0)
927 return ANIM_STATE_RESTART;
929 return ANIM_STATE_WAITING;
932 if (!DelayReachedExt(&part->step_delay, part->step_delay_value,
934 return ANIM_STATE_RUNNING;
938 static unsigned int last_counter = -1;
939 unsigned int counter = Counter();
941 printf("::: NEXT ANIM PART [%d, %d]\n",
942 anim_sync_frame, counter - last_counter);
944 last_counter = counter;
948 part->x += part->step_xoffset;
949 part->y += part->step_yoffset;
951 return ANIM_STATE_RUNNING;
954 void HandleGlobalAnim_Main(struct GlobalAnimMainControlInfo *anim, int action)
956 struct GlobalAnimPartControlInfo *part;
957 struct GraphicInfo *c = &anim->control_info;
958 int state, active_part_nr;
961 printf("::: HandleGlobalAnim_Main: %d, %d => %d\n",
962 anim->mode_nr, anim->nr, anim->num_parts);
963 printf("::: %d, %d, %d\n", global.num_toons, setup.toons, num_toons);
967 printf("::: %s(%d): %d, %d, %d [%d]\n",
968 (action == ANIM_START ? "ANIM_START" :
969 action == ANIM_CONTINUE ? "ANIM_CONTINUE" :
970 action == ANIM_STOP ? "ANIM_STOP" : "(should not happen)"),
972 anim->state & ANIM_STATE_RESTART,
973 anim->state & ANIM_STATE_WAITING,
974 anim->state & ANIM_STATE_RUNNING,
981 anim->state = anim->last_state = ANIM_STATE_RESTART;
982 anim->active_part_nr = anim->last_active_part_nr = 0;
983 anim->part_counter = 0;
988 if (anim->state == ANIM_STATE_INACTIVE)
991 anim->state = anim->last_state;
992 anim->active_part_nr = anim->last_active_part_nr;
997 anim->state = ANIM_STATE_INACTIVE;
1000 int num_parts = anim->num_parts + (anim->has_base ? 1 : 0);
1003 for (i = 0; i < num_parts; i++)
1004 StopGlobalAnimSound(&anim->part[i]);
1013 if (c->anim_mode & ANIM_ALL || anim->num_parts == 0)
1015 int num_parts = anim->num_parts + (anim->has_base ? 1 : 0);
1019 printf("::: HandleGlobalAnim_Main: %d, %d => %d\n",
1020 anim->mode_nr, anim->nr, num_parts);
1023 for (i = 0; i < num_parts; i++)
1025 part = &anim->part[i];
1030 anim->state = ANIM_STATE_RUNNING;
1031 part->state = ANIM_STATE_RESTART;
1036 if (part->state == ANIM_STATE_INACTIVE)
1042 part->state = ANIM_STATE_INACTIVE;
1050 part->state = HandleGlobalAnim_Part(part, part->state);
1052 // when animation mode is "once", stop after animation was played once
1053 if (c->anim_mode & ANIM_ONCE &&
1054 part->state & ANIM_STATE_RESTART)
1055 part->state = ANIM_STATE_INACTIVE;
1058 anim->last_state = anim->state;
1059 anim->last_active_part_nr = anim->active_part_nr;
1064 if (anim->state & ANIM_STATE_RESTART) // directly after restart
1065 anim->active_part_nr = getGlobalAnimationPart(anim);
1067 part = &anim->part[anim->active_part_nr];
1069 part->state = ANIM_STATE_RUNNING;
1071 anim->state = HandleGlobalAnim_Part(part, anim->state);
1073 if (anim->state & ANIM_STATE_RESTART)
1074 anim->part_counter++;
1076 // when animation mode is "once", stop after all animations were played once
1077 if (c->anim_mode & ANIM_ONCE &&
1078 anim->part_counter == anim->num_parts)
1079 anim->state = ANIM_STATE_INACTIVE;
1081 state = anim->state;
1082 active_part_nr = anim->active_part_nr;
1084 // while the animation parts are pausing (waiting or inactive), play the base
1085 // (main) animation; this corresponds to the "boring player animation" logic
1086 // (!!! KLUDGE WARNING: I THINK THIS IS A MESS THAT SHOULD BE CLEANED UP !!!)
1089 if (anim->state == ANIM_STATE_WAITING ||
1090 anim->state == ANIM_STATE_INACTIVE)
1092 anim->active_part_nr = anim->num_parts; // part nr of base animation
1093 part = &anim->part[anim->active_part_nr];
1095 if (anim->state != anim->last_state)
1096 part->state = ANIM_STATE_RESTART;
1098 anim->state = ANIM_STATE_RUNNING;
1099 part->state = HandleGlobalAnim_Part(part, part->state);
1103 anim->last_state = state;
1104 anim->last_active_part_nr = active_part_nr;
1107 void HandleGlobalAnim_Mode(struct GlobalAnimControlInfo *ctrl, int action)
1112 printf("::: HandleGlobalAnim_Mode: %d => %d\n",
1113 ctrl->nr, ctrl->num_anims);
1116 for (i = 0; i < ctrl->num_anims; i++)
1117 HandleGlobalAnim_Main(&ctrl->anim[i], action);
1120 static void HandleGlobalAnim(int action, int game_mode)
1123 printf("::: HandleGlobalAnim [mode == %d]\n", game_status);
1126 HandleGlobalAnim_Mode(&global_anim_ctrl[game_mode], action);
1129 static void DoAnimationExt()
1134 printf("::: DoAnimation [%d, %d]\n", anim_sync_frame, Counter());
1137 // global animations now synchronized with frame delay of screen update
1140 for (i = 0; i < NUM_GAME_MODES; i++)
1141 HandleGlobalAnim(ANIM_CONTINUE, i);
1144 // force screen redraw in next frame to continue drawing global animations
1145 redraw_mask = REDRAW_ALL;