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];
164 static struct ToonInfo toons[MAX_NUM_TOONS];
166 static unsigned int anim_sync_frame = 0;
168 static int game_mode_anim_classes[NUM_GAME_MODES];
169 static int anim_class_game_modes[NUM_ANIM_CLASSES];
171 static int anim_status_last = GAME_MODE_DEFAULT;
172 static int anim_classes_last = ANIM_CLASS_NONE;
175 static int getGlobalAnimationPart(struct GlobalAnimMainControlInfo *anim)
177 struct GraphicInfo *c = &anim->control_info;
178 int last_anim_random_frame = gfx.anim_random_frame;
181 gfx.anim_random_frame = -1; // (use simple, ad-hoc random numbers)
183 part_nr = getAnimationFrame(anim->num_parts, 1,
184 c->anim_mode, c->anim_start_frame,
187 gfx.anim_random_frame = last_anim_random_frame;
192 static int compareGlobalAnimPartControlInfo(const void *obj1, const void *obj2)
194 const struct GlobalAnimPartControlInfo *o1 =
195 (struct GlobalAnimPartControlInfo *)obj1;
196 const struct GlobalAnimPartControlInfo *o2 =
197 (struct GlobalAnimPartControlInfo *)obj2;
200 if (o1->control_info.draw_order != o2->control_info.draw_order)
201 compare_result = o1->control_info.draw_order - o2->control_info.draw_order;
203 compare_result = o1->nr - o2->nr;
205 return compare_result;
208 static int compareGlobalAnimMainControlInfo(const void *obj1, const void *obj2)
210 const struct GlobalAnimMainControlInfo *o1 =
211 (struct GlobalAnimMainControlInfo *)obj1;
212 const struct GlobalAnimMainControlInfo *o2 =
213 (struct GlobalAnimMainControlInfo *)obj2;
216 if (o1->control_info.draw_order != o2->control_info.draw_order)
217 compare_result = o1->control_info.draw_order - o2->control_info.draw_order;
219 compare_result = o1->nr - o2->nr;
221 return compare_result;
224 static void PrepareBackbuffer()
226 if (game_status != GAME_MODE_PLAYING)
229 BlitScreenToBitmap(backbuffer);
232 boolean ToonNeedsRedraw()
239 int num_toons = MAX_NUM_TOONS;
242 if (global.num_toons >= 0 && global.num_toons < MAX_NUM_TOONS)
243 num_toons = global.num_toons;
245 for (i = 0; i < num_toons; i++)
247 int graphic = IMG_TOON_1 + i;
248 struct FileInfo *image = getImageListEntryFromImageID(graphic);
250 toons[i].bitmap = graphic_info[graphic].bitmap;
252 toons[i].src_x = graphic_info[graphic].src_x;
253 toons[i].src_y = graphic_info[graphic].src_y;
255 toons[i].width = graphic_info[graphic].width;
256 toons[i].height = graphic_info[graphic].height;
258 toons[i].anim_frames = graphic_info[graphic].anim_frames;
259 toons[i].anim_delay = graphic_info[graphic].anim_delay;
260 toons[i].anim_mode = graphic_info[graphic].anim_mode;
261 toons[i].anim_start_frame = graphic_info[graphic].anim_start_frame;
263 toons[i].step_offset = graphic_info[graphic].step_offset;
264 toons[i].step_delay = graphic_info[graphic].step_delay;
266 toons[i].direction = image->parameter[GFX_ARG_DIRECTION];
267 toons[i].position = image->parameter[GFX_ARG_POSITION];
270 InitToonScreen(bitmap_db_toons,
271 BackToFront, PrepareBackbuffer, ToonNeedsRedraw,
273 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE,
277 static void InitToonControls()
279 int mode_nr_toons = GAME_MODE_PSEUDO_TOONS;
280 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[mode_nr_toons];
281 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[ctrl->num_anims];
282 int mode_nr, anim_nr, part_nr;
283 int control = IMG_INTERNAL_GLOBAL_TOON_DEFAULT;
284 int num_toons = MAX_NUM_TOONS;
287 if (global.num_toons >= 0 && global.num_toons < MAX_NUM_TOONS)
288 num_toons = global.num_toons;
290 mode_nr = mode_nr_toons;
291 anim_nr = ctrl->num_anims;
294 anim->mode_nr = mode_nr;
295 anim->control_info = graphic_info[control];
298 anim->part_counter = 0;
299 anim->active_part_nr = 0;
301 anim->has_base = FALSE;
303 anim->init_delay_counter = 0;
305 anim->state = ANIM_STATE_INACTIVE;
309 for (i = 0; i < num_toons; i++)
311 struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
312 int sound = SND_UNDEFINED;
313 int graphic = IMG_TOON_1 + i;
314 int control = graphic;
317 part->anim_nr = anim_nr;
318 part->mode_nr = mode_nr;
320 part->graphic = graphic;
321 part->graphic_info = graphic_info[graphic];
322 part->control_info = graphic_info[control];
324 part->graphic_info.anim_delay *= part->graphic_info.step_delay;
326 part->control_info.init_delay_fixed = 0;
327 part->control_info.init_delay_random = 150;
329 part->control_info.x = ARG_UNDEFINED_VALUE;
330 part->control_info.y = ARG_UNDEFINED_VALUE;
332 part->initial_anim_sync_frame = 0;
334 part->step_delay = 0;
335 part->step_delay_value = graphic_info[control].step_delay;
337 part->state = ANIM_STATE_INACTIVE;
338 part->last_anim_status = -1;
347 void InitGlobalAnimControls()
350 int mode_nr, anim_nr, part_nr;
351 int sound, graphic, control;
355 for (m = 0; m < NUM_GAME_MODES; m++)
359 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[mode_nr];
366 for (a = 0; a < NUM_GLOBAL_ANIMS; a++)
368 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[anim_nr];
369 int ctrl_id = GLOBAL_ANIM_ID_CONTROL_FIRST + a;
371 control = global_anim_info[ctrl_id].graphic[GLOBAL_ANIM_ID_PART_BASE][m];
373 // if no base animation parameters defined, use default values
374 if (control == IMG_UNDEFINED)
375 control = IMG_INTERNAL_GLOBAL_ANIM_DEFAULT;
378 anim->mode_nr = mode_nr;
379 anim->control_info = graphic_info[control];
382 anim->part_counter = 0;
383 anim->active_part_nr = 0;
385 anim->has_base = FALSE;
387 anim->init_delay_counter = 0;
389 anim->state = ANIM_STATE_INACTIVE;
393 for (p = 0; p < NUM_GLOBAL_ANIM_PARTS_ALL; p++)
395 struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
397 sound = global_anim_info[a].sound[p][m];
398 graphic = global_anim_info[a].graphic[p][m];
399 control = global_anim_info[ctrl_id].graphic[p][m];
401 if (graphic == IMG_UNDEFINED || graphic_info[graphic].bitmap == NULL ||
402 control == IMG_UNDEFINED)
406 printf("::: mode == %d, anim = %d, part = %d [%d, %d, %d] [%d]\n",
407 m, a, p, mode_nr, anim_nr, part_nr, control);
411 printf("::: mode == %d, anim = %d, part = %d [%d, %d, %d] [%d]\n",
412 m, a, p, mode_nr, anim_nr, part_nr, sound);
416 part->anim_nr = anim_nr;
417 part->mode_nr = mode_nr;
419 part->graphic = graphic;
420 part->graphic_info = graphic_info[graphic];
421 part->control_info = graphic_info[control];
423 part->initial_anim_sync_frame = 0;
425 part->step_delay = 0;
426 part->step_delay_value = graphic_info[control].step_delay;
428 part->state = ANIM_STATE_INACTIVE;
429 part->last_anim_status = -1;
431 if (p < GLOBAL_ANIM_ID_PART_BASE)
439 anim->has_base = TRUE;
443 if (anim->num_parts > 0 || anim->has_base)
453 /* sort all animations according to draw_order and animation number */
454 for (m = 0; m < NUM_GAME_MODES; m++)
456 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[m];
458 /* sort all main animations for this game mode */
459 qsort(ctrl->anim, ctrl->num_anims,
460 sizeof(struct GlobalAnimMainControlInfo),
461 compareGlobalAnimMainControlInfo);
463 for (a = 0; a < ctrl->num_anims; a++)
465 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[a];
467 /* sort all animation parts for this main animation */
468 qsort(anim->part, anim->num_parts,
469 sizeof(struct GlobalAnimPartControlInfo),
470 compareGlobalAnimPartControlInfo);
474 for (i = 0; i < NUM_GAME_MODES; i++)
475 game_mode_anim_classes[i] = ANIM_CLASS_NONE;
476 for (i = 0; game_mode_anim_classes_list[i].game_mode != -1; i++)
477 game_mode_anim_classes[game_mode_anim_classes_list[i].game_mode] =
478 game_mode_anim_classes_list[i].class;
480 for (i = 0; i < NUM_ANIM_CLASSES; i++)
481 anim_class_game_modes[i] = GAME_MODE_DEFAULT;
482 for (i = 0; anim_class_game_modes_list[i].game_mode != -1; i++)
483 anim_class_game_modes[anim_class_game_modes_list[i].class_bit] =
484 anim_class_game_modes_list[i].game_mode;
486 anim_status_last = GAME_MODE_LOADING;
487 anim_classes_last = ANIM_CLASS_NONE;
490 void InitGlobalAnimations()
492 InitGlobalAnimControls();
495 void DrawGlobalAnimExt(int drawing_stage)
499 if (global.anim_status != anim_status_last)
501 boolean before_fading = (global.anim_status == GAME_MODE_PSEUDO_FADING);
502 boolean after_fading = (anim_status_last == GAME_MODE_PSEUDO_FADING);
503 int anim_classes_next = game_mode_anim_classes[global.anim_status_next];
506 // ---------- part 1 ------------------------------------------------------
507 // start or stop global animations by change of game mode
508 // (special handling of animations for "current screen" and "all screens")
510 // stop animations for last screen
511 HandleGlobalAnim(ANIM_STOP, anim_status_last);
513 // start animations for current screen
514 HandleGlobalAnim(ANIM_START, global.anim_status);
516 // start animations for all screens after loading new artwork set
517 if (anim_status_last == GAME_MODE_LOADING)
518 HandleGlobalAnim(ANIM_START, GAME_MODE_DEFAULT);
520 // ---------- part 2 ------------------------------------------------------
521 // start or stop global animations by change of animation class
522 // (generic handling of animations for "class of screens")
524 for (i = 0; i < NUM_ANIM_CLASSES; i++)
526 int anim_class_check = (1 << i);
527 int anim_class_game_mode = anim_class_game_modes[i];
528 int anim_class_last = anim_classes_last & anim_class_check;
529 int anim_class_next = anim_classes_next & anim_class_check;
531 // stop animations for changed screen class before fading to new screen
532 if (before_fading && anim_class_last && !anim_class_next)
533 HandleGlobalAnim(ANIM_STOP, anim_class_game_mode);
535 // start animations for changed screen class after fading to new screen
536 if (after_fading && !anim_class_last && anim_class_next)
537 HandleGlobalAnim(ANIM_START, anim_class_game_mode);
541 anim_classes_last = anim_classes_next;
543 anim_status_last = global.anim_status;
546 if (!setup.toons || global.anim_status == GAME_MODE_LOADING)
549 if (drawing_stage == DRAW_GLOBAL_ANIM_STAGE_1)
552 for (mode_nr = 0; mode_nr < NUM_GAME_MODES; mode_nr++)
554 struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[mode_nr];
558 if (mode_nr != GFX_SPECIAL_ARG_DEFAULT &&
559 mode_nr != game_status)
563 for (anim_nr = 0; anim_nr < ctrl->num_anims; anim_nr++)
565 struct GlobalAnimMainControlInfo *anim = &ctrl->anim[anim_nr];
566 struct GraphicInfo *c = &anim->control_info;
567 int part_first, part_last;
570 if (!(anim->state & ANIM_STATE_RUNNING))
573 part_first = part_last = anim->active_part_nr;
575 if (c->anim_mode & ANIM_ALL || anim->num_parts == 0)
577 int num_parts = anim->num_parts + (anim->has_base ? 1 : 0);
580 part_last = num_parts - 1;
583 for (part_nr = part_first; part_nr <= part_last; part_nr++)
585 struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
586 struct GraphicInfo *g = &part->graphic_info;
589 int width = g->width;
590 int height = g->height;
598 if (!(part->state & ANIM_STATE_RUNNING))
601 if (part->drawing_stage != drawing_stage)
610 else if (part->x > part->viewport_width - g->width)
611 width -= (part->x - (part->viewport_width - g->width));
619 else if (part->y > part->viewport_height - g->height)
620 height -= (part->y - (part->viewport_height - g->height));
622 if (width <= 0 || height <= 0)
625 dst_x += part->viewport_x;
626 dst_y += part->viewport_y;
628 sync_frame = anim_sync_frame - part->initial_anim_sync_frame;
629 frame = getAnimationFrame(g->anim_frames, g->anim_delay,
630 g->anim_mode, g->anim_start_frame,
633 getFixedGraphicSource(part->graphic, frame, &src_bitmap,
639 BlitToScreenMasked(src_bitmap, src_x, src_y, width, height,
646 void DrawGlobalAnim(int drawing_stage)
648 DrawGlobalAnimExt(drawing_stage);
651 boolean SetGlobalAnimPart_Viewport(struct GlobalAnimPartControlInfo *part)
657 boolean changed = FALSE;
659 if (part->last_anim_status == global.anim_status)
662 part->last_anim_status = global.anim_status;
664 part->drawing_stage = DRAW_GLOBAL_ANIM_STAGE_1;
666 if (part->control_info.class == get_hash_from_key("window") ||
667 part->control_info.class == get_hash_from_key("border"))
671 viewport_width = WIN_XSIZE;
672 viewport_height = WIN_YSIZE;
674 part->drawing_stage = DRAW_GLOBAL_ANIM_STAGE_2;
676 else if (part->control_info.class == get_hash_from_key("door_1"))
680 viewport_width = DXSIZE;
681 viewport_height = DYSIZE;
683 else if (part->control_info.class == get_hash_from_key("door_2"))
687 viewport_width = VXSIZE;
688 viewport_height = VYSIZE;
690 else // default: "playfield"
692 viewport_x = REAL_SX;
693 viewport_y = REAL_SY;
694 viewport_width = FULL_SXSIZE;
695 viewport_height = FULL_SYSIZE;
698 if (viewport_x != part->viewport_x ||
699 viewport_y != part->viewport_y ||
700 viewport_width != part->viewport_width ||
701 viewport_height != part->viewport_height)
703 part->viewport_x = viewport_x;
704 part->viewport_y = viewport_y;
705 part->viewport_width = viewport_width;
706 part->viewport_height = viewport_height;
714 void PlayGlobalAnimSound(struct GlobalAnimPartControlInfo *part)
716 int sound = part->sound;
718 if (sound == SND_UNDEFINED)
721 if ((!setup.sound_simple && !IS_LOOP_SOUND(sound)) ||
722 (!setup.sound_loops && IS_LOOP_SOUND(sound)))
725 // !!! TODO: ADD STEREO POSITION FOR MOVING ANIMATIONS !!!
726 if (IS_LOOP_SOUND(sound))
727 PlaySoundLoop(sound);
732 printf("::: PLAY %d.%d.%d: %d\n",
733 part->anim_nr, part->nr, part->mode_nr, sound);
737 void StopGlobalAnimSound(struct GlobalAnimPartControlInfo *part)
739 int sound = part->sound;
741 if (sound == SND_UNDEFINED)
747 printf("::: STOP %d.%d.%d: %d\n",
748 part->anim_nr, part->nr, part->mode_nr, sound);
752 int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, int state)
754 struct GraphicInfo *g = &part->graphic_info;
755 struct GraphicInfo *c = &part->control_info;
756 boolean viewport_changed = SetGlobalAnimPart_Viewport(part);
758 if (viewport_changed)
759 state |= ANIM_STATE_RESTART;
761 if (state & ANIM_STATE_RESTART)
763 ResetDelayCounterExt(&part->step_delay, anim_sync_frame);
765 part->init_delay_counter =
766 (c->init_delay_fixed + GetSimpleRandom(c->init_delay_random));
768 part->anim_delay_counter =
769 (c->anim_delay_fixed + GetSimpleRandom(c->anim_delay_random));
771 part->initial_anim_sync_frame =
772 (g->anim_global_sync ? 0 : anim_sync_frame + part->init_delay_counter);
774 if (c->direction & MV_HORIZONTAL)
776 int pos_bottom = part->viewport_height - g->height;
778 if (c->position == POS_TOP)
780 else if (c->position == POS_UPPER)
781 part->y = GetSimpleRandom(pos_bottom / 2);
782 else if (c->position == POS_MIDDLE)
783 part->y = pos_bottom / 2;
784 else if (c->position == POS_LOWER)
785 part->y = pos_bottom / 2 + GetSimpleRandom(pos_bottom / 2);
786 else if (c->position == POS_BOTTOM)
787 part->y = pos_bottom;
789 part->y = GetSimpleRandom(pos_bottom);
791 if (c->direction == MV_RIGHT)
793 part->step_xoffset = c->step_offset;
794 part->x = -g->width + part->step_xoffset;
798 part->step_xoffset = -c->step_offset;
799 part->x = part->viewport_width + part->step_xoffset;
802 part->step_yoffset = 0;
804 else if (c->direction & MV_VERTICAL)
806 int pos_right = part->viewport_width - g->width;
808 if (c->position == POS_LEFT)
810 else if (c->position == POS_RIGHT)
813 part->x = GetSimpleRandom(pos_right);
815 if (c->direction == MV_DOWN)
817 part->step_yoffset = c->step_offset;
818 part->y = -g->height + part->step_yoffset;
822 part->step_yoffset = -c->step_offset;
823 part->y = part->viewport_height + part->step_yoffset;
826 part->step_xoffset = 0;
833 part->step_xoffset = 0;
834 part->step_yoffset = 0;
837 if (c->x != ARG_UNDEFINED_VALUE)
839 if (c->y != ARG_UNDEFINED_VALUE)
842 if (c->step_xoffset != ARG_UNDEFINED_VALUE)
843 part->step_xoffset = c->step_xoffset;
844 if (c->step_yoffset != ARG_UNDEFINED_VALUE)
845 part->step_yoffset = c->step_yoffset;
847 if (part->init_delay_counter == 0)
848 PlayGlobalAnimSound(part);
851 if (part->init_delay_counter > 0)
853 part->init_delay_counter--;
855 if (part->init_delay_counter == 0)
856 PlayGlobalAnimSound(part);
858 return ANIM_STATE_WAITING;
861 // check if moving animation has left the visible screen area
862 if ((part->x <= -g->width && part->step_xoffset <= 0) ||
863 (part->x >= part->viewport_width && part->step_xoffset >= 0) ||
864 (part->y <= -g->height && part->step_yoffset <= 0) ||
865 (part->y >= part->viewport_height && part->step_yoffset >= 0))
867 // do not stop animation before "anim" or "post" counter are finished
868 if (part->anim_delay_counter == 0 &&
869 part->post_delay_counter == 0)
871 StopGlobalAnimSound(part);
873 part->post_delay_counter =
874 (c->post_delay_fixed + GetSimpleRandom(c->post_delay_random));
876 if (part->post_delay_counter > 0)
877 return ANIM_STATE_RUNNING;
879 // drawing last frame not needed here -- animation not visible anymore
880 return ANIM_STATE_RESTART;
884 if (part->anim_delay_counter > 0)
886 part->anim_delay_counter--;
888 if (part->anim_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 // additional state "RUNNING" required to not skip drawing last frame
899 return ANIM_STATE_RESTART | ANIM_STATE_RUNNING;
903 if (part->post_delay_counter > 0)
905 part->post_delay_counter--;
907 if (part->post_delay_counter == 0)
908 return ANIM_STATE_RESTART;
910 return ANIM_STATE_WAITING;
913 if (!DelayReachedExt(&part->step_delay, part->step_delay_value,
915 return ANIM_STATE_RUNNING;
919 static unsigned int last_counter = -1;
920 unsigned int counter = Counter();
922 printf("::: NEXT ANIM PART [%d, %d]\n",
923 anim_sync_frame, counter - last_counter);
925 last_counter = counter;
929 part->x += part->step_xoffset;
930 part->y += part->step_yoffset;
932 return ANIM_STATE_RUNNING;
935 void HandleGlobalAnim_Main(struct GlobalAnimMainControlInfo *anim, int action)
937 struct GlobalAnimPartControlInfo *part;
938 struct GraphicInfo *c = &anim->control_info;
939 int state, active_part_nr;
942 printf("::: HandleGlobalAnim_Main: %d, %d => %d\n",
943 anim->mode_nr, anim->nr, anim->num_parts);
944 printf("::: %d, %d, %d\n", global.num_toons, setup.toons, num_toons);
948 printf("::: %s(%d): %d, %d, %d [%d]\n",
949 (action == ANIM_START ? "ANIM_START" :
950 action == ANIM_CONTINUE ? "ANIM_CONTINUE" :
951 action == ANIM_STOP ? "ANIM_STOP" : "(should not happen)"),
953 anim->state & ANIM_STATE_RESTART,
954 anim->state & ANIM_STATE_WAITING,
955 anim->state & ANIM_STATE_RUNNING,
962 anim->state = anim->last_state = ANIM_STATE_RESTART;
963 anim->active_part_nr = anim->last_active_part_nr = 0;
964 anim->part_counter = 0;
969 if (anim->state == ANIM_STATE_INACTIVE)
972 anim->state = anim->last_state;
973 anim->active_part_nr = anim->last_active_part_nr;
978 anim->state = ANIM_STATE_INACTIVE;
981 int num_parts = anim->num_parts + (anim->has_base ? 1 : 0);
984 for (i = 0; i < num_parts; i++)
985 StopGlobalAnimSound(&anim->part[i]);
994 if (c->anim_mode & ANIM_ALL || anim->num_parts == 0)
996 int num_parts = anim->num_parts + (anim->has_base ? 1 : 0);
1000 printf("::: HandleGlobalAnim_Main: %d, %d => %d\n",
1001 anim->mode_nr, anim->nr, num_parts);
1004 for (i = 0; i < num_parts; i++)
1006 part = &anim->part[i];
1011 anim->state = ANIM_STATE_RUNNING;
1012 part->state = ANIM_STATE_RESTART;
1017 if (part->state == ANIM_STATE_INACTIVE)
1023 part->state = ANIM_STATE_INACTIVE;
1031 part->state = HandleGlobalAnim_Part(part, part->state);
1033 // when animation mode is "once", stop after animation was played once
1034 if (c->anim_mode & ANIM_ONCE &&
1035 part->state & ANIM_STATE_RESTART)
1036 part->state = ANIM_STATE_INACTIVE;
1039 anim->last_state = anim->state;
1040 anim->last_active_part_nr = anim->active_part_nr;
1045 if (anim->state & ANIM_STATE_RESTART) // directly after restart
1046 anim->active_part_nr = getGlobalAnimationPart(anim);
1048 part = &anim->part[anim->active_part_nr];
1050 part->state = ANIM_STATE_RUNNING;
1052 anim->state = HandleGlobalAnim_Part(part, anim->state);
1054 if (anim->state & ANIM_STATE_RESTART)
1055 anim->part_counter++;
1057 // when animation mode is "once", stop after all animations were played once
1058 if (c->anim_mode & ANIM_ONCE &&
1059 anim->part_counter == anim->num_parts)
1060 anim->state = ANIM_STATE_INACTIVE;
1062 state = anim->state;
1063 active_part_nr = anim->active_part_nr;
1065 // while the animation parts are pausing (waiting or inactive), play the base
1066 // (main) animation; this corresponds to the "boring player animation" logic
1067 // (!!! KLUDGE WARNING: I THINK THIS IS A MESS THAT SHOULD BE CLEANED UP !!!)
1070 if (anim->state == ANIM_STATE_WAITING ||
1071 anim->state == ANIM_STATE_INACTIVE)
1073 anim->active_part_nr = anim->num_parts; // part nr of base animation
1074 part = &anim->part[anim->active_part_nr];
1076 if (anim->state != anim->last_state)
1077 part->state = ANIM_STATE_RESTART;
1079 anim->state = ANIM_STATE_RUNNING;
1080 part->state = HandleGlobalAnim_Part(part, part->state);
1084 anim->last_state = state;
1085 anim->last_active_part_nr = active_part_nr;
1088 void HandleGlobalAnim_Mode(struct GlobalAnimControlInfo *ctrl, int action)
1093 printf("::: HandleGlobalAnim_Mode: %d => %d\n",
1094 ctrl->nr, ctrl->num_anims);
1097 for (i = 0; i < ctrl->num_anims; i++)
1098 HandleGlobalAnim_Main(&ctrl->anim[i], action);
1101 static void HandleGlobalAnim(int action, int game_mode)
1104 printf("::: HandleGlobalAnim [mode == %d]\n", game_status);
1107 HandleGlobalAnim_Mode(&global_anim_ctrl[game_mode], action);
1110 static void DoAnimationExt()
1115 printf("::: DoAnimation [%d, %d]\n", anim_sync_frame, Counter());
1118 // global animations now synchronized with frame delay of screen update
1121 for (i = 0; i < NUM_GAME_MODES; i++)
1122 HandleGlobalAnim(ANIM_CONTINUE, i);
1125 // force screen redraw in next frame to continue drawing global animations
1126 redraw_mask = REDRAW_ALL;