#include "boss_repentance.h" #include "boss_ai.h" #include "grid_entity_trap_door.h" #include "entity_config.h" #include "npc_fireplace.h" #include #include // Clutch's forms, by variant: Clutch himself and the fireballs circling him. constexpr int CLUTCH_FIREBALL = 1; // Clutch's states: resting before he picks a Clickety Clack, wandering in his last phase, inside a Clickety Clack, // stunned once none is left, flying to the one he picked, flying at his target, his ring of flames, leaving a // Clickety Clack, and his last phase's start. enum ClutchState { CLUTCH_IDLE = NPC_STATE_IDLE, CLUTCH_WANDER = NPC_STATE_MOVE, CLUTCH_POSSESS = NPC_STATE_JUMP, CLUTCH_STUNNED = NPC_STATE_STOMP, CLUTCH_FLY = NPC_STATE_ATTACK, CLUTCH_CHARGE = NPC_STATE_ATTACK2, CLUTCH_RING = NPC_STATE_ATTACK3, CLUTCH_UNPOSSESS = NPC_STATE_ATTACK4, CLUTCH_TRANSITION = NPC_STATE_SPECIAL }; // The Clickety Clacks' states Clutch drives: its stomp, its stun, getting up and its pile of bones. // His last phase starts at a quarter of his health. His Clickety Clacks take 1.75 times their health. constexpr float CLUTCH_LAST_PHASE = 0.25f; constexpr float CLACK_HEALTH_SHARE = 1.75f; constexpr ColorMod CLUTCH_SPLAT_COLOR = {{0.8f, 0.75f, 1, 0.5f}, {2.1f, 1.7f, 2.5f, 1}, {0, 0, 0}}; constexpr uint32_t CLUTCH_AI_CALLS = AI_CALL_INTERPOLATE | AI_CALL_POST_UPDATE; // Resting 15 frames, then flying at his pick: starting 29 frames in after a quick revert, waiting 30 more. constexpr int CLUTCH_REST = 15; constexpr float CLUTCH_FRICTION = 0.9f; constexpr float CLUTCH_SLOW_FRICTION = 0.8f; constexpr float CLUTCH_MOVE_START_FRAME = 29; constexpr int CLUTCH_REVERT_REST = 30; // The flight: up to 0.8 a frame faster a frame (30 at most) to his pick, entering it within 20. In his last phase he // wanders 8 frames, then flies at half the gap to his target (1.2 a frame faster, 30 at most) and rings it with flames // within 20: six rings of nine fire shots at 9, every other one turned 30 degrees. constexpr float CLUTCH_FLY_GAIN = 0.8f; constexpr float CLUTCH_FLY_MAX = 30; constexpr float CLUTCH_REACH = 20; constexpr int CLUTCH_WANDER_FRAMES = 8; constexpr float CLUTCH_CHARGE_GAIN = 1.2f; constexpr float CLUTCH_RING_SPEED = 9; constexpr float CLUTCH_RING_SHOTS = 6; constexpr float CLUTCH_RING_TURN = 0.5235988f; constexpr int CLUTCH_RINGS = 5; constexpr float CLUTCH_RING_VOLUME = 0.8f; // Stunned with no Clickety Clack left he takes 80 hurt (a tenth a frame at least) before rising, waking the burnt piles // every 8 frames. Thrown out of a dead Clickety Clack at 20. In his last phase he takes a tenth of each hit. constexpr float CLUTCH_STUN_HEALTH = 80; constexpr float CLUTCH_STUN_DRAIN = 0.1f; constexpr float CLUTCH_THROW_SPEED = 20; constexpr float CLUTCH_PILE_EVERY = 8; constexpr float CLUTCH_LAST_DAMAGE_SHARE = 0.1f; constexpr float CLUTCH_ROAR_VOLUME = 2; constexpr float CLUTCH_LAST_ROAR_VOLUME = 1.5f; constexpr int CLUTCH_SHAKE = 16; constexpr float CLUTCH_RIPPLE_AMPLITUDE = 0.035f; constexpr float CLUTCH_RIPPLE_SPEED = 0.025f; constexpr int CLUTCH_RIPPLE_FRAMES = 10; constexpr float CLUTCH_COUNT_EVERY = 15; // The beam between Clutch and his pick fades over 10 frames, raised 12, once he enters it. constexpr ColorMod CLUTCH_BEAM_COLOR = {{0.35f, 0.1f, 1, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}}; constexpr int CLUTCH_BEAM_FADE = 10; constexpr float CLUTCH_BEAM_RAISE = -12; // A Clickety Clack burnt for good becomes a purple fire with two fireballs 10 out at a random angle. constexpr std::string_view CLUTCH_FIRE_ANM2 = "gfx/009.002_Fire Projectile.anm2"; constexpr std::string_view CLUTCH_POOF_ANM2 = "gfx/033.010_Movable Fireplace.anm2"; constexpr int CLUTCH_FIREBALLS = 2; constexpr float CLUTCH_FIREBALL_OUT = 10; constexpr float CLUTCH_POOF_VOLUME = 0.85f; // The trail of purple flames behind him: one more every time the Trail null moved 8 (squared) from the last, 0.6 to 0.8 // of the null's size, drifting 1.5 down (or swinging across his flight), slowing by 0.9 plus 0.08 of its size, shaking // by 0.3 of it and shrinking 0.08 a frame, kept within 40 of the null. Half a step between frames. constexpr float TRAIL_SPACING_SQUARED = 8; constexpr float CLUTCH_TRAIL_SIZE = 0.6f; constexpr float TRAIL_SIZE_RANGE = 0.2f; constexpr float TRAIL_DRIFT = 1.5f; constexpr float TRAIL_SWAY = 6; constexpr float TRAIL_SWAY_PERIOD = 15; constexpr float TRAIL_SWING_RATE = 0.25f; constexpr float TRAIL_SWING_SHARE = 0.33f; constexpr float TRAIL_DRAG = 0.9f; constexpr float TRAIL_SIZE_DRAG = 0.08f; constexpr float TRAIL_SHAKE = 0.3f; constexpr float CLUTCH_TRAIL_SHRINK = 0.08f; constexpr float TRAIL_REACH = 40; constexpr float TRAIL_PULL = 0.6f; constexpr float TRAIL_INTERPOLATED_STEP = 0.5f; constexpr ColorMod TRAIL_HIDDEN_COLOR = {{1, 1, 1, 0}, {0, 0, 0, 0}, {0, 0, 0}}; constexpr size_t TRAIL_POINT = 3; constexpr int TRAIL_FIRST_LAYER = 1; constexpr int TRAIL_LAST_LAYER = 2; // A trail segment shows one of 8 frames by its flames' size, stretched to half its length per missing frame (1 to 3). constexpr int TRAIL_FRAMES = 8; constexpr float TRAIL_STRETCH_MAX = 3; // Whether a Clickety Clack (or other NPC) is one of Clutch's side. static bool clutch_is_ally(Entity_NPC& npc, Entity& other) { return Entity::is_enemy_type(other.type) && other.IsFriendly() == npc.IsFriendly(); } // The Clickety Clacks of his side he leads. static std::vector clutch_clacks_get(Entity_NPC& npc) { std::vector clacks; for (Entity* other : Entity_NPC::QueryNPCsType(ENTITY_CLICKETY_CLACK, -1)) if (clutch_is_ally(npc, *other) && other->parent.get() == &npc) clacks.push_back(static_cast(other)); return clacks; } // 00572a70 The Clickety Clack of his farthest from him he may enter: not his pick, not burning, not untargetable. static Entity_NPC* clutch_clack_farthest(Entity_NPC& npc) { Entity_NPC* farthest = nullptr; float farthestDistance = 0; for (Entity* other : entity_query(ENTITY_CLICKETY_CLACK, -1)) { auto* clack = static_cast(other); bool isPick = clutch_is_ally(npc, *clack) && clack->parent.get() == &npc && clack != npc.child.get() && clack->i2 != CLACK_FLAME && !clack->HasEntityFlags(FLAG_NO_TARGET); float distance = vector_distance(npc.pos, clack->pos); if (!isPick || distance <= farthestDistance) continue; farthestDistance = distance; farthest = clack; } return farthest; } // How his beam goes: left fading where his pick stands, or removed. enum BeamRelease { BEAM_RELEASE_FADE, BEAM_RELEASE_REMOVE }; // 005729a0 Lets the beam to his pick go. static void clutch_beam_release(Entity_NPC& npc, BeamRelease release) { Entity* beam = npc.entityRef.get(); if (!beam || beam->type != ENTITY_EFFECT) return; if (release == BEAM_RELEASE_REMOVE) beam->Remove(); else { static_cast(beam)->SetTimeout(CLUTCH_BEAM_FADE); beam->pos = npc.child->pos; beam->posOffset = vector_make(0, CLUTCH_BEAM_RAISE); beam->target = nullptr; } npc.entityRef = nullptr; } // His purple beam from a spawner to a Clickety Clack, under a parent. Entity* clutch_beam_spawn(Entity& spawner, Entity& target, Entity* parent) { Entity* beam = g_game->Spawn({.position = target.pos, .spawner = &spawner, .type = ENTITY_EFFECT, .variant = EFFECT_KINETI_BEAM, .seed = Random()}); beam->SetColor(CLUTCH_BEAM_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); beam->target = ⌖ beam->parent = parent; beam->Update(); return beam; } // Clutch flies off to a Clickety Clack, his beam on it, stunning it. static void clutch_beam_to(Entity_NPC& npc, Entity_NPC& clack) { npc_sound_play(SOUND_DEVILROOM_DEAL, 1, 2, CLUTCH_SOUND_PITCH); clutch_beam_release(npc, BEAM_RELEASE_FADE); npc.entityRef = clutch_beam_spawn(npc, clack, &npc); } // Where a Clickety Clack burnt for good goes: a purple poof of the movable fireplace. static void clutch_fire_poof(Entity& at) { npc_sound_play(SOUND_STEAM_HALFSEC, CLUTCH_POOF_VOLUME, 2, 1); Entity* poof = g_game->Spawn({.position = at.pos, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); poof->sprite.Load(CLUTCH_POOF_ANM2, GRAPHICS_LOAD); for (LayerState& layer : poof->sprite.layerStates) layer.color = CLUTCH_FLAME_COLOR; poof->sprite.Play("Disappear"); poof->Update(); } // 00572c10 A pile of bones gets up again at full health, from its Regen's 15th frame. static void clutch_pile_regen(Entity_NPC& clack) { clack.health = clack.maxHitPoints; clack.sprite.Play("Regen"); if (clack.sprite.animState.animData) clack.sprite.animState.SetFrameFloat(CLACK_REGEN_FRAME); clack.state = CLACK_REGEN; } // 00572cc0 A Clickety Clack burns for good: killed as a purple fire, two fireballs circling Clutch. static void clutch_fire_spawn(Entity_NPC& npc, Entity& clack) { clack.AddEntityFlags(FLAG_NO_TARGET); clack.Kill(EntityRef(&npc)); Entity* fire = g_game->Spawn({.position = clack.pos, .spawner = &npc, .type = ENTITY_FIREPLACE, .variant = FIRE_MOVEABLE_PURPLE, .seed = Random()}); fire->sprite.Load(CLUTCH_FIRE_ANM2, GRAPHICS_LOAD); fire->sprite.Play("Flickering"); for (LayerState& layer : fire->sprite.layerStates) layer.color = CLUTCH_FLAME_COLOR; fire->Update(); for (int i = 0; i < CLUTCH_FIREBALLS; i++) { uint32_t seed = Random(); Vector position = vector_add(clack.pos, vector_scale(random_direction(), CLUTCH_FIREBALL_OUT)); auto* fireball = static_cast(g_game->Spawn( {.position = position, .spawner = &npc, .type = ENTITY_CLUTCH, .variant = CLUTCH_FIREBALL, .seed = seed})); fireball->parent = &npc; fireball->v1.x = random_unit() * FULL_TURN_DEGREES; } } // Clutch's roar on a stun's end or his last phase: shaking the room with a ripple. static void clutch_roar(Entity_NPC& npc, float volume) { npc.PlaySound(SOUND_THUMBS_DOWN, 1, 2, false, 1); npc.PlaySound(SOUND_MULTI_SCREAM, 1, 2, false, 1); npc.PlaySound(SOUND_FORSAKEN_SCREAM, volume, 2, false, 1); game_shake_screen(CLUTCH_SHAKE); shockwave_make(npc.pos, CLUTCH_RIPPLE_AMPLITUDE, CLUTCH_RIPPLE_SPEED, CLUTCH_RIPPLE_FRAMES); } // Which Clickety Clacks the roar picks from: the piles, or any. enum ClackPick { PICK_PILES, PICK_ANY }; // Every 8 frames after the roar one of his Clickety Clacks: a pile gets up, or one burns in his last phase. static void clutch_roar_pick(Entity_NPC& npc, ClackPick pick, void (*picked)(Entity_NPC&, Entity_NPC&)) { if (!npc.sprite.WasEventTriggered("Shoot") || !npc.GetIntervalTicks(CLUTCH_PILE_EVERY, 0)) return; std::vector clacks; for (Entity_NPC* clack : clutch_clacks_get(npc)) if (pick == PICK_ANY || clack->state == CLACK_PILE) clacks.push_back(clack); if (!clacks.empty()) picked(npc, *clacks[random_below((int)clacks.size())]); } // The rest after the roar: every pile of his gets up (or burns), and he goes back to resting (or wandering). static void clutch_roar_finish(Entity_NPC& npc, void (*finished)(Entity_NPC&, Entity_NPC&)) { for (Entity_NPC* clack : clutch_clacks_get(npc)) if (clack->state == CLACK_PILE) finished(npc, *clack); } static void clack_regen_picked(Entity_NPC&, Entity_NPC& clack) { clutch_pile_regen(clack); } static void clack_burn_picked(Entity_NPC& npc, Entity_NPC& clack) { clutch_fire_spawn(npc, clack); } // Enters his last phase: a roar, out of any Clickety Clack, his beam gone. static void clutch_transition_start(Entity_NPC& npc) { npc.sprite.Play("Transition"); npc.state = CLUTCH_TRANSITION; clutch_beam_release(npc, BEAM_RELEASE_REMOVE); } // Resting: once rested (or after a quick revert) he flies to the Clickety Clack he left or the farthest, stunning it. static void clutch_idle_update(Entity_NPC& npc, int ticks) { npc.sprite.Play("Idle"); npc.pathfinder.MoveRandomlyBoss(STATUS_OBEYED); if (npc.stateFrame >= 0) npc.stateFrame += ticks; npc.friction *= CLUTCH_FRICTION; if (npc.stateFrame <= CLUTCH_REST && npc.stateFrame >= 0) return; auto* clack = static_cast(npc.parent.get()); if (!clack || clack->type != ENTITY_CLICKETY_CLACK) clack = clutch_clack_farthest(npc); if (!clack) clutch_transition_start(npc); else { npc.state = CLUTCH_FLY; Vector gap = vector_sub(clack->pos, npc.pos); if (std::abs(gap.x) > std::abs(gap.y)) npc.sprite.Play("MoveStart"); else npc.sprite.Play(npc.pos.y <= clack->pos.y ? "MoveStartDown" : "MoveStartUp"); npc.child = clack; if (npc.stateFrame < 0) { if (npc.sprite.animState.animData) npc.sprite.animState.SetFrameFloat(CLUTCH_MOVE_START_FRAME); npc.entityCollisionClass = ENTCOLL_PLAYEROBJECTS; npc.shadowSize = npc.config->shadowSize; } else clutch_beam_to(npc, *clack); if (clack->state != CLACK_PILE) { clack->state = CLACK_STUNNED; clack->sprite.Play("Stunned"); clack->targetPosition = {}; } npc.sprite.isFlipX = npc.pos.x < clack->pos.x; } npc.stateFrame = npc.stateFrame < 0 ? CLUTCH_REVERT_REST : 0; } // Inside a Clickety Clack, riding it until it dies: then he takes the farthest other (or falls stunned with none), // thrown away from his target. static void clutch_possess_update(Entity_NPC& npc) { Entity* clack = npc.child.get(); npc.friction *= CLUTCH_FRICTION; if (clack && !clack->isDead && !clack->HasEntityFlags(FLAG_NO_TARGET)) { npc.velocity = vector_sub(clack->pos, npc.pos); if (npc.sprite.IsEventTriggered("Sound")) npc_sound_play(SOUND_PORTAL_SPAWN, 1, 2, CLUTCH_SOUND_PITCH); if (!npc.sprite.IsEventTriggered("Shoot")) return; npc_sound_play(SOUND_BONE_HEART, 1, 2, CLUTCH_SOUND_PITCH); npc.entityCollisionClass = ENTCOLL_NONE; npc.shadowSize = 0; Entity_NPC* host = npc.ChildNPC(); host->state = CLACK_STOMP; host->sprite.Play("Transition"); if (host == npc.ParentNPC() && host->sprite.animState.animData) host->sprite.animState.SetFrameFloat(CLUTCH_MOVE_START_FRAME); return; } if (npc.entityCollisionClass != ENTCOLL_NONE) { npc.sprite.Play("Idle"); npc.state = CLUTCH_IDLE; npc.stateFrame = CLUTCH_REST; npc.entityCollisionClass = ENTCOLL_PLAYEROBJECTS; npc.shadowSize = npc.config->shadowSize; return; } Entity_NPC* next = clutch_clack_farthest(npc); if (!next) { npc.sprite.Play("Stun"); npc.state = CLUTCH_STUNNED; npc.stateFrame = 0; npc.v1.x = CLUTCH_STUN_HEALTH; } else { npc.parent = next; npc.state = CLUTCH_UNPOSSESS; npc_sound_play(SOUND_DEVILROOM_DEAL, 1, 2, CLUTCH_SOUND_PITCH); clutch_beam_release(npc, BEAM_RELEASE_REMOVE); npc.entityRef = clutch_beam_spawn(npc, *next, &npc); npc.sprite.Play("Unpossess"); } npc.entityCollisionClass = ENTCOLL_PLAYEROBJECTS; npc.shadowSize = npc.config->shadowSize; Vector away = vector_normalized(vector_sub(npc.pos, npc.GetPlayerTarget()->pos)); npc.velocity = vector_add(npc.velocity, vector_scale(away, CLUTCH_THROW_SPEED)); } // Stunned with none left: the burning piles go out first, then he takes hurt until he rises with a roar, waking them. static void clutch_stunned_update(Entity_NPC& npc) { npc.friction *= CLUTCH_SLOW_FRICTION; if (npc.stateFrame == 0) { npc.stateFrame = 1; for (Entity_NPC* clack : clutch_clacks_get(npc)) { if (clack->state != CLACK_PILE || clack->i2 != CLACK_FLAME) continue; clack->i2 = 0; clack->sprite.Play("Collapse"); if (clack->sprite.animState.animData) clack->sprite.animState.AdvancePosition(clack->sprite.animState.animData->length - 1); clutch_fire_poof(*clack); } } if (npc.v1.x > 0) { if (!npc.sprite.IsPlaying()) npc.sprite.Play("StunLoop"); npc.v1.x -= std::max(npc.speedMultiplier * CLUTCH_STUN_DRAIN, npc.pendingDamage); return; } npc.sprite.Play("StunEnd"); npc.parent = nullptr; npc.child = nullptr; if (npc.sprite.IsEventTriggered("Shoot")) clutch_roar(npc, CLUTCH_ROAR_VOLUME); clutch_roar_pick(npc, PICK_PILES, clack_regen_picked); if (npc.sprite.IsPlaying()) return; clutch_roar_finish(npc, clack_regen_picked); npc.sprite.Play("Idle"); npc.state = CLUTCH_IDLE; npc.stateFrame = 0; } // Flying to his pick, faster each frame. Whether he entered it. static bool clutch_fly_update(Entity_NPC& npc, int ticks) { npc.friction *= CLUTCH_FRICTION; Entity* clack = npc.child.get(); if (!clack) { npc.sprite.Play("Idle"); npc.state = CLUTCH_IDLE; npc.stateFrame = CLUTCH_REST; return false; } if (!npc.sprite.IsPlaying()) npc.sprite.Play("MoveLoop"); npc.stateFrame += ticks; if (npc.sprite.IsEventTriggered("Shoot")) { npc_sound_play(SOUND_BEAST_GHOST_DASH, 1, 2, 1); clutch_beam_release(npc, BEAM_RELEASE_FADE); } if (!npc.sprite.WasEventTriggered("Shoot") && !npc.sprite.animState.IsLoopingAnimation()) return false; float maxSpeed = std::min((float)npc.stateFrame * CLUTCH_FLY_GAIN, CLUTCH_FLY_MAX); npc.velocity = vector_sub(clack->pos, npc.pos); float distance = vector_length(npc.velocity); if (distance >= CLUTCH_REACH) { if (maxSpeed < distance && distance > 0) npc.velocity = vector_scale(npc.velocity, maxSpeed / distance); return false; } npc.sprite.Play("Possess"); npc.state = CLUTCH_POSSESS; npc.stateFrame = 0; return true; } // His last phase: he wanders, flies at his target and rings it with fire. Hits do a tenth while he roars. static void clutch_last_phase_update(Entity_NPC& npc, int ticks) { switch (npc.state) { case CLUTCH_WANDER: npc.pathfinder.MoveRandomlyBoss(STATUS_OBEYED); npc.stateFrame += ticks; npc.friction *= CLUTCH_FRICTION; if (npc.stateFrame > CLUTCH_WANDER_FRAMES) { Vector target = npc.GetPlayerTarget()->pos; if (vector_is_zero(target)) break; npc.state = CLUTCH_CHARGE; npc.sprite.Play("MoveStart2"); npc.targetPosition = target; npc.sprite.isFlipX = npc.pos.x < target.x; npc.stateFrame = 0; } break; case CLUTCH_CHARGE: { if (npc.sprite.IsFinished()) npc.sprite.Play("MoveLoop2"); npc.stateFrame += ticks; if (!npc.sprite.WasEventTriggered("Shoot") && !npc.sprite.animState.IsLoopingAnimation()) break; float maxSpeed = std::min((float)npc.stateFrame * CLUTCH_CHARGE_GAIN, CLUTCH_FLY_MAX); npc.velocity = vector_scale(vector_sub(npc.targetPosition, npc.pos), HALF); float distance = vector_length(npc.velocity); if (distance < CLUTCH_REACH) { npc.sprite.Play("AttackStart"); npc.state = CLUTCH_RING; npc.stateFrame = 0; } else if (maxSpeed < distance) npc.velocity = vector_resized(npc.velocity, maxSpeed); break; } case CLUTCH_RING: npc.friction *= CLUTCH_FRICTION; if (npc.sprite.IsEventTriggered("Shoot")) { npc.PlaySound(SOUND_BEAST_FIRE_RING, CLUTCH_RING_VOLUME, 2, false, CLUTCH_SOUND_PITCH); ProjectileParams params; params.circleAngle = npc.stateFrame & 1 ? 0 : CLUTCH_RING_TURN; params.variant = PROJECTILE_FIRE; params.color = CLUTCH_FLAME_COLOR; npc.FireProjectiles(npc.pos, vector_make(CLUTCH_RING_SPEED, CLUTCH_RING_SHOTS), PROJECTILES_RING, params); npc.stateFrame++; } if (!npc.sprite.IsFinished()) break; if (npc.stateFrame > CLUTCH_RINGS) { npc.sprite.Play("Idle2"); npc.state = CLUTCH_WANDER; npc.stateFrame = 0; } else npc.sprite.Play("Attack", PLAY_FORCED); break; case CLUTCH_TRANSITION: npc.friction *= CLUTCH_SLOW_FRICTION; if (npc.sprite.IsEventTriggered("Shoot")) clutch_roar(npc, CLUTCH_LAST_ROAR_VOLUME); clutch_roar_pick(npc, PICK_ANY, clack_burn_picked); if (npc.sprite.IsPlaying()) { npc.pendingDamage = 0; for (DamageEvent& hit : npc.damageEvents) { hit.damage *= CLUTCH_LAST_DAMAGE_SHARE; npc.pendingDamage += hit.damage; } break; } clutch_roar_finish(npc, clack_burn_picked); npc.sprite.Play("Idle2"); npc.state = CLUTCH_WANDER; npc.stateFrame = 0; break; } } // Numbers the Clickety Clacks he leads standing (his pick 0) for their places, keeping one more than their count. static void clutch_clacks_count(Entity_NPC& npc) { int count = 1; for (Entity* other : entity_query(ENTITY_CLICKETY_CLACK, -1)) { auto* clack = static_cast(other); if (!Entity::is_enemy_type(clack->type) || clack->parent.get() != &npc || clack->state == CLACK_PILE) continue; clack->i2 = clack == npc.child.get() ? 0 : count++; } npc.i1 = count; } // Dying, he takes his Clickety Clacks, purple fires and fireballs with him. His shots fall. static void clutch_death_update(Entity_NPC& npc) { for (Entity* other : entities_live(g_game->room->entityList.updateEL)) { if (!clutch_is_ally(npc, *other)) { if (other->type == ENTITY_PROJECTILE && other->parent.get() == &npc) { static_cast(other)->projectileFlags = 0; other->isDead = true; } continue; } if (other->type == ENTITY_CLICKETY_CLACK) { if (other->parent.get() != &npc) continue; other->AddEntityFlags(FLAG_NO_TARGET); other->Kill(EntityRef(&npc)); } else if (other->type == ENTITY_FIREPLACE && other->variant == FIRE_MOVEABLE_PURPLE) { other->Kill(EntityRef(&npc)); clutch_fire_poof(*other); } else if (other->type == ENTITY_CLUTCH && other->variant == CLUTCH_FIREBALL && other->parent.get() == &npc) other->Kill(EntityRef(&npc)); } } // Part of 00573030 Between frames the trail steps half and keeps its last whole step. After the update it steps whole, // grows a flame and takes the Trail null's colour onto its two layers. static void clutch_trail_update(Entity_NPC& npc) { bool isInterpolated = npc.aiCallPhase == AI_PHASE_INTERPOLATE; if (isInterpolated) npc.vectorDeque2 = npc.vectorDeque1; else npc.vectorDeque1 = npc.vectorDeque2; bool isFlying = (npc.state == CLUTCH_FLY || npc.state == CLUTCH_CHARGE) && (npc.sprite.WasEventTriggered("Shoot") || npc.sprite.animState.IsLoopingAnimation()); Vector anchor = vector_add(npc.pos, npc.GetNullOffset("Trail")); Vector drift = vector_make(0, TRAIL_DRIFT); if (!isFlying) anchor.x += std::sin(npc.updateTime * PI_F / TRAIL_SWAY_PERIOD) * TRAIL_SWAY; else { Vector side = vector_rotated(npc.velocity, RIGHT_ANGLE_DEGREES); float swing = std::sin(npc.updateTime * PI_F * TRAIL_SWING_RATE); anchor = vector_add(anchor, vector_scale(side, swing)); drift = vector_scale(side, TRAIL_SWING_SHARE * swing); } const NullFrame* null = npc.sprite.animState.animData ? npc.sprite.animState.GetNullFrame("Trail") : nullptr; std::deque& trail = npc.vectorDeque1; float step = (isInterpolated ? TRAIL_INTERPOLATED_STEP : 1) * npc.speedMultiplier; for (size_t i = 0; i < trail.size();) { Vector& position = trail[i]; Vector& velocity = trail[i + 1]; Vector& size = trail[i + 2]; position = vector_add(position, vector_scale(velocity, step)); velocity = vector_scale(velocity, timescale_factor(size.x * TRAIL_SIZE_DRAG + TRAIL_DRAG, step)); Vector shake = random_direction(); float strength = size.x * random_unit() * TRAIL_SHAKE * step; velocity = vector_add(velocity, vector_scale(shake, strength)); size.x = std::max(size.x - step * CLUTCH_TRAIL_SHRINK, 0.0f); float distance = vector_distance(anchor, position); if (distance > TRAIL_REACH) { float kept = timescale_factor(TRAIL_PULL, step) * (distance - TRAIL_REACH) + TRAIL_REACH; position = vector_add(anchor, vector_scale(vector_sub(position, anchor), kept / distance)); } if (size.x > 0 || isInterpolated) i += TRAIL_POINT; else trail.erase(trail.begin() + (long)i, trail.begin() + (long)(i + TRAIL_POINT)); } bool isSpaced = trail.empty() || vector_length_squared(vector_sub(anchor, trail.front())) > TRAIL_SPACING_SQUARED; if (!isInterpolated && isSpaced) { float scale = null ? null->scale.x : 1; trail.push_front(vector_make((random_unit() * TRAIL_SIZE_RANGE + CLUTCH_TRAIL_SIZE) * scale, 0)); trail.push_front(drift); trail.push_front(anchor); } ColorMod color = null && null->isVisible ? null->color : TRAIL_HIDDEN_COLOR; npc.sprite.GetLayer(TRAIL_LAST_LAYER)->color = color; npc.sprite.GetLayer(TRAIL_FIRST_LAYER)->color = color; } // 00573030 Clutch rides his Clickety Clacks one by one, leaving each dead one to stomp its bones and wake again, and // falls stunned once none is left. Below a quarter of his health he burns them all and flies at his target, ringing // it with fire. void boss_clutch_update(Entity_NPC& npc) { if (npc.aiCallPhase == AI_PHASE_POST_UPDATE || npc.aiCallPhase == AI_PHASE_INTERPOLATE) return clutch_trail_update(npc); int ticks = npc_ticks_get(npc); bool isCounted = npc.GetIntervalTicks(CLUTCH_COUNT_EVERY, 0); bool isLastPhaseDue = npc.state == CLUTCH_IDLE || npc.state == CLUTCH_FLY || (npc.state == CLUTCH_STUNNED && !npc.sprite.WasEventTriggered("Shoot")); if (isLastPhaseDue && npc.health <= npc.maxHitPoints * CLUTCH_LAST_PHASE) { clutch_transition_start(npc); npc.entityCollisionClass = ENTCOLL_PLAYEROBJECTS; npc.shadowSize = npc.config->shadowSize; } switch (npc.state) { case NPC_STATE_INIT: { npc.splatColor = CLUTCH_SPLAT_COLOR; npc.state = CLUTCH_IDLE; npc.aiCallFlags = CLUTCH_AI_CALLS; npc.sprite.PlayOverlay("Trail"); npc.sprite.GetLayer(TRAIL_FIRST_LAYER)->isVisible = false; npc.sprite.GetLayer(TRAIL_LAST_LAYER)->isVisible = false; npc.entityCollisionClass = ENTCOLL_PLAYEROBJECTS; npc.entityGridCollisionClass = GRIDCOLL_WALLS; int count = 1; for (Entity* other : Entity_NPC::QueryNPCsType(ENTITY_CLICKETY_CLACK, -1)) { if (!clutch_is_ally(npc, *other) || other->parent) continue; auto* clack = static_cast(other); clack->parent = &npc; clack->maxHitPoints *= CLACK_HEALTH_SHARE; clack->i2 = count++; clack->health = clack->maxHitPoints; } npc.i1 = count; break; } case CLUTCH_IDLE: clutch_idle_update(npc, ticks); break; case CLUTCH_POSSESS: clutch_possess_update(npc); break; case CLUTCH_STUNNED: clutch_stunned_update(npc); break; case CLUTCH_FLY: if (clutch_fly_update(npc, ticks)) isCounted = true; break; case CLUTCH_UNPOSSESS: npc.friction *= CLUTCH_SLOW_FRICTION; if (npc.sprite.IsPlaying()) break; npc.state = CLUTCH_IDLE; npc.stateFrame = CLUTCH_REVERT_WAIT; break; default: clutch_last_phase_update(npc, ticks); break; } if (isCounted) clutch_clacks_count(npc); if (npc.isDead) clutch_death_update(npc); } // 00575a10 Clutch draws his trail of flames segment by segment on his two trail layers, each between two flames, // turned along them and showing their size, then himself. The fireballs draw plainly. void clutch_render(Entity_NPC& npc, const Vector& offset) { std::deque& trail = npc.vectorDeque1; if (npc.variant != 0 || npc.sprite.GetLayer(TRAIL_FIRST_LAYER)->color._tint[3] <= 0 || trail.empty()) return npc.Entity::Render(offset); npc.sprite.GetLayer(TRAIL_FIRST_LAYER)->isVisible = true; npc.sprite.GetLayer(TRAIL_LAST_LAYER)->isVisible = true; for (int layerId = TRAIL_FIRST_LAYER; layerId <= TRAIL_LAST_LAYER; layerId++) for (size_t i = 0; i + TRAIL_POINT < trail.size(); i += TRAIL_POINT) { Vector from = trail[i]; Vector to = trail[i + TRAIL_POINT]; Vector middle = render_position_get(vector_scale(vector_add(from, to), HALF), RENDER_SNAPPED); float size = (trail[i + TRAIL_POINT + 2].x + trail[i + 2].x) * HALF; int frame = (int)((float)TRAIL_FRAMES - size * TRAIL_FRAMES); if (frame >= TRAIL_FRAMES) continue; float stretch = 1; if (frame != TRAIL_FRAMES - 1) stretch = std::clamp(vector_distance(from, to) * HALF / (float)(TRAIL_FRAMES - frame), 1.0f, TRAIL_STRETCH_MAX); LayerState& layer = *npc.sprite.GetLayer(layerId); layer.size = vector_make(stretch, 1); Vector gap = vector_sub(to, from); layer.rotation = std::atan2(gap.y, gap.x) * RADIANS_TO_DEGREES * (npc.sprite.isFlipX ? -1.0f : 1.0f); if (npc.sprite.overlayAnimState.animData) npc.sprite.overlayAnimState.SetFrameFloat((float)frame); npc.sprite.RenderLayer(layerId, SpriteDraw{vector_add(middle, offset), {}, {}}); } npc.sprite.GetLayer(TRAIL_FIRST_LAYER)->isVisible = false; npc.sprite.GetLayer(TRAIL_LAST_LAYER)->isVisible = false; npc.Entity::Render(offset); }