+ return ((part->control_info.style & STYLE_PASSTHROUGH) ? FALSE : TRUE);
+}
+
+static void SetGlobalAnimPartTileXY(struct GlobalAnimPartControlInfo *part)
+{
+ // calculate playfield position (with scrolling) for related CE tile
+ // (do not use FX/FY, which are incorrect during envelope requests)
+ int FX0 = 2 * TILEX_VAR; // same as FX during DRAW_TO_FIELDBUFFER
+ int FY0 = 2 * TILEY_VAR; // same as FY during DRAW_TO_FIELDBUFFER
+ int fx = getFieldbufferOffsetX_RND(ScreenMovDir, ScreenGfxPos);
+ int fy = getFieldbufferOffsetY_RND(ScreenMovDir, ScreenGfxPos);
+ int sx = FX0 + SCREENX(part->tile_x) * TILEX_VAR;
+ int sy = FY0 + SCREENY(part->tile_y) * TILEY_VAR;
+ int cx = SX - REAL_SX;
+ int cy = SY - REAL_SY;
+ int x = sx - fx + cx;
+ int y = sy - fy + cy;
+
+ part->tile_xoffset += part->step_xoffset;
+ part->tile_yoffset += part->step_yoffset;
+
+ part->x = x + part->tile_xoffset;
+ part->y = y + part->tile_yoffset;
+}
+
+static void InitGlobalAnim_Triggered(struct GlobalAnimPartControlInfo *part,
+ boolean *click_consumed,
+ boolean *any_event_action,
+ int event_value, char *info_text)
+{
+ struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[part->mode_nr];
+
+ int gic_anim_nr = part->old_anim_nr + 1; // X as in "anim_X"
+ int gic_part_nr = part->old_nr + 1; // Y as in "part_Y"
+ int mask = event_value | (gic_anim_nr << ANIM_EVENT_ANIM_BIT);
+
+ if (!part->is_base)
+ mask |= gic_part_nr << ANIM_EVENT_PART_BIT;
+
+ int anim2_nr;
+
+ for (anim2_nr = 0; anim2_nr < ctrl->num_anims; anim2_nr++)
+ {
+ struct GlobalAnimMainControlInfo *anim2 = &ctrl->anim[anim2_nr];
+ int part2_nr;
+
+ for (part2_nr = 0; part2_nr < anim2->num_parts_all; part2_nr++)
+ {
+ struct GlobalAnimPartControlInfo *part2 = &anim2->part[part2_nr];
+
+ if (!(part2->state & (ANIM_STATE_RUNNING | ANIM_STATE_WAITING)))
+ continue;
+
+ if (isClickablePart(part2, mask))
+ {
+ part2->triggered = TRUE;
+ *click_consumed |= clickConsumed(part); // click was on "part"!
+
+#if DEBUG_ANIM_EVENTS
+ Debug("anim:InitGlobalAnim_Triggered",
+ "%d.%d TRIGGERED BY %s OF %d.%d",
+ part2->old_anim_nr + 1, part2->old_nr + 1, info_text,
+ part->old_anim_nr + 1, part->old_nr + 1);
+#endif
+#if 0
+ Debug("anim:InitGlobalAnim_Triggered",
+ "%d.%d TRIGGER CLICKED [%d]", anim2_nr, part2_nr,
+ part2->control_info.anim_event_action);
+#endif
+
+ // after executing event action, ignore any further actions
+ if (!*any_event_action && DoGlobalAnim_EventAction(part2))
+ *any_event_action = TRUE;
+ }
+
+#if 0
+ struct GraphicInfo *c = &part2->control_info;
+
+ if (isClickablePart(part2, mask))
+ Debug("anim:InitGlobalAnim_Triggered",
+ "%d.%d: 0x%08x, 0x%08x [0x%08x] <--- TRIGGERED BY %d.%d",
+ anim2_nr, part2_nr, c->init_event, c->anim_event, mask,
+ anim_nr, part_nr);
+ else
+ Debug("anim:InitGlobalAnim_Triggered",
+ "%d.%d: 0x%08x, 0x%08x [0x%08x]",
+ anim2_nr, part2_nr, c->init_event, c->anim_event, mask);
+#endif
+ }
+ }
+}
+
+static void InitGlobalAnim_Triggered_ByCustomElement(int nr, int page,
+ int x, int y,
+ int trigger_x,
+ int trigger_y)
+{
+ struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[GAME_MODE_PLAYING];
+
+ int event_value = ANIM_EVENT_CE_CHANGE;
+ int event_bits = (nr << ANIM_EVENT_CE_BIT) | (page << ANIM_EVENT_PAGE_BIT);
+ int mask = event_value | event_bits;
+ int anim2_nr;
+
+ for (anim2_nr = 0; anim2_nr < ctrl->num_anims; anim2_nr++)
+ {
+ struct GlobalAnimMainControlInfo *anim2 = &ctrl->anim[anim2_nr];
+ int part2_nr;
+
+ for (part2_nr = 0; part2_nr < anim2->num_parts_all; part2_nr++)
+ {
+ struct GlobalAnimPartControlInfo *part2 = &anim2->part[part2_nr];
+
+ if (!(part2->state & (ANIM_STATE_RUNNING | ANIM_STATE_WAITING)))
+ continue;
+
+ if (isClickablePart(part2, mask) && !part2->triggered)
+ {
+ struct GraphicInfo *c = &part2->control_info;
+
+ if (c->position == POS_CE ||
+ c->position == POS_CE_TRIGGER)
+ {
+ // store CE tile and offset position to handle scrolling
+ part2->tile_x = (c->position == POS_CE_TRIGGER ? trigger_x : x);
+ part2->tile_y = (c->position == POS_CE_TRIGGER ? trigger_y : y);
+ part2->tile_xoffset = c->x;
+ part2->tile_yoffset = c->y;
+
+ // set resulting animation position relative to CE tile position
+ // (but only for ".init_event", not ".anim_event" type events)
+ if (part2->init_event_state)
+ SetGlobalAnimPartTileXY(part2);
+
+ // restart animation (by using current sync frame)
+ part2->initial_anim_sync_frame = anim_sync_frame;
+ }
+
+ part2->triggered = TRUE;
+
+ // do not trigger any other animation if CE change event was consumed
+ if (c->style == STYLE_CONSUME_CE_EVENT)
+ return;
+
+#if 0
+ Debug("anim:InitGlobalAnim_Triggered_ByCustomElement",
+ "%d.%d TRIGGERED BY CE %d", anim2_nr, part2_nr, nr + 1);
+#endif
+ }
+ }
+ }
+}
+
+static void HandleGlobalAnimDelay(struct GlobalAnimPartControlInfo *part,
+ int delay_type, char *info_text)
+{
+#if DEBUG_ANIM_DELAY
+ Debug("anim:HandleGlobalAnimDelay", "%d.%d %s",
+ part->old_anim_nr + 1, part->old_nr + 1, info_text);
+#endif
+
+ DoGlobalAnim_DelayAction(part, delay_type);
+}
+
+static void HandleGlobalAnimEvent(struct GlobalAnimPartControlInfo *part,
+ int event_value, char *info_text)
+{
+#if DEBUG_ANIM_EVENTS
+ Debug("anim:HandleGlobalAnimEvent", "%d.%d %s",
+ part->old_anim_nr + 1, part->old_nr + 1, info_text);
+#endif
+
+ boolean click_consumed = FALSE;
+ boolean any_event_action = FALSE;
+
+ // check if this event is defined to trigger other animations
+ InitGlobalAnim_Triggered(part, &click_consumed, &any_event_action,
+ event_value, info_text);