#include "entity_npc.h" #include "entity_config.h" #include "entity_effect.h" #include "entity_player.h" #include "game.h" #include "grid_entity_poop.h" #include "npc_ai.h" #include "npc_basement.h" #include "room.h" #include "room_grid.h" #include "sfx_manager.h" #include #include constexpr int ENTITY_FLICKER_TYPE = 252; constexpr int SHRINK_PULSE_FRAMES = 60; // The pulses: a slow and a fast sine over the room's frames, each shifted up by a half and clamped to 0 to 1. constexpr float PULSE_SLOW_RATE = 0.1f; constexpr float PULSE_FAST_RATE = 0.3f; constexpr float PULSE_SHIFT = 0.5f; constexpr ColorMod SHRINK_PULSE_COLOR = {{1, 1, 1, 1}, {0, 0, 0, 0}, {60 / 255.0f, 60 / 255.0f, 60 / 255.0f}}; // The rainbow champion's hue turns once every 90 frames. constexpr int RAINBOW_HUE_FRAMES = 90; constexpr float HUE_FULL_TURN = 360; constexpr float HUE_SEXTANT = 60; constexpr int HUE_SEXTANTS = 6; // The fly protected champion's fly starts shrunk. constexpr int ETERNAL_FLY_SHRINK_FRAMES = 150; // The brown champion's splats every 3 frames and its poop, one in four cells it leaves. constexpr int BROWN_SPLAT_FRAMES = 3; constexpr float BROWN_SPLAT_SIZE_MIN = 0.2f; constexpr float BROWN_SPLAT_SIZE_RANGE = 0.5f; constexpr ColorMod BROWN_CHAMPION_SPLAT_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0.255f, 0.161f, 0.137f}}; constexpr int BROWN_POOP_ODDS = 4; // The purple champion pulls players and tears from 300 away, the tears harder. constexpr float PURPLE_PULL_REACH = 300; constexpr float PURPLE_PULL_TEAR = 0.9f; constexpr float PURPLE_PULL_PLAYER = 0.8f; // The dark red champion lies as a Globin's ball for 90 ticks at 10 health, shrinking to it and growing back. constexpr float REGEN_HEALTH = 10; constexpr float CHAMPION_REGEN_FRICTION = 0.8f; constexpr int REGEN_SHRINK_END = 5; constexpr int REGEN_GROW_END = 9; constexpr int REGEN_RISE_START = 80; constexpr int REGEN_RISE_SHRINK_END = 85; constexpr int REGEN_END = 90; constexpr float REGEN_SHRINK = 0.5f; constexpr float REGEN_GROW = 2; constexpr int AI_CALL_FLAGS_SHIFT = 16; constexpr std::string_view REGEN_ANM2 = "gfx/024.000_Globin.anm2"; constexpr std::array REGEN_TARGET_RESET_TYPES = {ENTITY_LEAPER, ENTITY_KEEPER, ENTITY_FLAMING_HOPPER, ENTITY_RAGLING, ENTITY_HOPPER}; constexpr uint64_t CLICKETY_CLACK_REGEN_CLEARED = FLAG_NO_STATUS_EFFECTS | FLAG_NO_TARGET | FLAG_HIDE_HP_BAR; // The camouflaged champion is black, its color offset drifting toward the floor under it. constexpr float CAMO_FLOOR_SHARE = 0.9f; constexpr float CAMO_DRIFT = 0.3f; // The grey pulsing champion pushes the tears within 100 at the bottom of its slow pulse. constexpr float PULSE_PUSH_REACH = 100; constexpr float PULSE_PUSH_START = 0.2f; constexpr float PULSE_PUSH_END = 0.4f; // The red pulsing champion heals the enemies of its side by 20 every 30 frames, a red trail running to each. constexpr int PULSE_HEAL_FRAMES = 30; constexpr float PULSE_HEAL = 20; constexpr float HEAL_TRAIL_STEP = 20; constexpr int HEAL_TRAIL_MIN = 4; constexpr int HEAL_TRAIL_MAX = 12; constexpr float HEAL_TRAIL_SPEED_SHARE = 0.1f; constexpr float HEAL_TRAIL_SPEED_MAX = 4; constexpr float HEAL_TRAIL_SPREAD = 15; constexpr float HEAL_TRAIL_SCALE = 0.3f; constexpr float HEAL_TRAIL_RISE = -16; constexpr int HEAL_FLASH_FRAMES = 8; constexpr ColorMod HEAL_TRAIL_COLOR = {{1, 1, 1, 1}, {0, 0, 0, 0}, {0.3f, 0, 0}}; constexpr ColorMod HEAL_FLASH_COLOR = {{0.7f, 0.7f, 0.7f, 1}, {0, 0, 0, 0}, {0.7f, 0, 0}}; constexpr uint64_t HEAL_SIDE_FLAGS = FLAG_FRIENDLY | FLAG_CHARM; // The king champion crowns the plain enemies around it every 30 frames, and the size pulsing one keeps 5 flies. constexpr int KING_FRAMES = 30; constexpr int SIZE_PULSE_FLY_MAX = 4; constexpr int SIZE_PULSE_FLY_COOLDOWN = 60; // A look from its sheet color's channels and its sprite's tint and offset. constexpr ChampionLook champion_look(float red, float green, float blue, float alpha, ColorMod spriteColor = COLOR_DEFAULT) { return {{{red, green, blue, alpha}, {0, 0, 0, 0}, {0, 0, 0}}, spriteColor}; } constexpr float CHAMPION_GLOW = 30 / 255.0f; constexpr std::array CHAMPION_LOOKS = {{ champion_look(1, 0.1f, 0.1f, 1), champion_look(0.6f, 0.6f, 0, 1), champion_look(0.1f, 0.8f, 0.2f, 1), champion_look(1, 0.6f, 0.2f, 1), champion_look(0.2f, 0.2f, 1, 1), champion_look(0.03f, 0.24f, 0.24f, 1), champion_look(1, 1, 1, 1, {{1, 1, 1, 1}, {0, 0, 0, 0}, {90 / 255.0f, 90 / 255.0f, 90 / 255.0f}}), champion_look(0.5f, 0.5f, 0.5f, 1), champion_look(1, 1, 1, 1, {{1, 1, 1, 0.6f}, {0, 0, 0, 0}, {120 / 255.0f, 120 / 255.0f, 120 / 255.0f}}), champion_look(0, 0, 0, 0, {{0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0}}), champion_look(1, 0, 1, 1), champion_look(0.75f, 0, 1, 1), champion_look(0.5f, 0, 0, 1), champion_look(0.5f, 0.5f, 1, 1), champion_look(0, 0, 0, 0), champion_look(0.1f, 0.8f, 0.2f, 1, {{0.9f, 1, 0.9f, 1}, {0, 0, 0, 0}, {0, CHAMPION_GLOW, 0}}), champion_look(0.5f, 0.5f, 0.5f, 1, {{0.9f, 0.9f, 0.9f, 1}, {0, 0, 0, 0}, {CHAMPION_GLOW, CHAMPION_GLOW, CHAMPION_GLOW}}), champion_look(0.8f, 0.8f, 0.8f, 1, {{1, 1, 1, 1}, {0, 0, 0, 0}, {50 / 255.0f, 50 / 255.0f, 50 / 255.0f}}), champion_look(0, 0, 0, 0), champion_look(0, 0, 0, 0), champion_look(1, 0.2f, 0.2f, 1, {{1, 0.9f, 0.9f, 1}, {0, 0, 0, 0}, {CHAMPION_GLOW, 0, 0}}), champion_look(0, 0, 0, 0), champion_look(0, 0, 0, 0), champion_look(0.3f, 0.3f, 0.3f, 1, {{0.8f, 0.8f, 0.8f, 1}, {0, 0, 0, 0}, {0, 0, 0}}), champion_look(0.28f, 0.14f, 0.134f, 1), champion_look(1, 1, 1, 1), }}; // The colors a seed's champion roll picks among: the common ones (the late stages' with yellow), the rare, the // pulsing and sized, the late stages' special ones, and the late stages' uncommon ones. constexpr std::array CHAMPIONS_EARLY = {CHAMPION_RED, CHAMPION_GREEN, CHAMPION_DARK_GREEN, CHAMPION_GREY, CHAMPION_PINK, CHAMPION_LIGHT_BLUE}; constexpr std::array CHAMPIONS_LATE = {CHAMPION_RED, CHAMPION_YELLOW, CHAMPION_GREEN, CHAMPION_DARK_GREEN, CHAMPION_GREY, CHAMPION_PINK, CHAMPION_LIGHT_BLUE}; constexpr std::array CHAMPIONS_RARE = {CHAMPION_ORANGE, CHAMPION_DARK_BLUE, CHAMPION_DARK_RED}; constexpr std::array CHAMPIONS_PULSING = {CHAMPION_CAMO, CHAMPION_PULSE_GREEN, CHAMPION_PULSE_GREY, CHAMPION_FLY_PROTECTED, CHAMPION_TINY, CHAMPION_GIANT}; constexpr std::array CHAMPIONS_SPECIAL = {CHAMPION_PULSE_RED, CHAMPION_SIZE_PULSE, CHAMPION_KING, CHAMPION_DEATH}; constexpr std::array CHAMPIONS_UNCOMMON = {CHAMPION_TRANSPARENT, CHAMPION_FLICKER, CHAMPION_PURPLE, CHAMPION_BROWN}; constexpr uint32_t CHAMPION_RNG_SHIFT_INDEX = 33; constexpr uint32_t CHAMPION_LATE_STAGE = 5; constexpr uint32_t CHAMPION_YELLOW_STAGE = 3; constexpr uint32_t CHAMPION_PULSING_EARLY_COUNT = 4; constexpr float CHAMPION_ROLL_WHITE = 0.005f; constexpr float CHAMPION_ROLL_RAINBOW = 0.01f; constexpr float CHAMPION_ROLL_UNCOMMON = 0.05f; constexpr float CHAMPION_ROLL_RARE = 0.15f; constexpr float CHAMPION_ROLL_PULSING = 0.3f; constexpr float CHAMPION_ROLL_SPECIAL = 0.35f; constexpr std::array CHAMPION_NO_DARK_RED_TYPES = {240, 241, 242, 304}; // The champions' health, speed, size and contact damage, and the effect variant some keep around them. constexpr float CHAMPION_SCALE = 1.15f; constexpr float CHAMPION_TINY_SCALE = 0.5f; constexpr float CHAMPION_GIANT_SCALE = 1.5f; constexpr float CHAMPION_CONTACT_DAMAGE = 2; constexpr float CHAMPION_DEATH_CONTACT_DAMAGE = 4; constexpr float CHAMPION_HP_RED = 1.333f; constexpr float CHAMPION_HP_YELLOW = 0.75f; constexpr float CHAMPION_HP_GREY = 0.333f; constexpr float CHAMPION_HP_BIG = 1.5f; constexpr float CHAMPION_HP_KING = 3; constexpr float CHAMPION_SPEED_FAST = 1.333f; constexpr float CHAMPION_SPEED_SLOW = 0.8f; constexpr float CHAMPION_SPEED_GIANT = 0.9f; constexpr int CHAMPION_FLICKER_MIN = 60; constexpr int CHAMPION_FLICKER_RANGE = 30; constexpr int CHAMPION_SHOT_MIN = 40; constexpr int CHAMPION_SHOT_RANGE = 20; constexpr int CHAMPION_CREEP_FRAMES = 7; constexpr int CHAMPION_CREEP_TIMEOUT = 30; constexpr float CHAMPION_SHOT_SPEED = 5; constexpr float CHAMPION_SHOT_FALL_ACCEL = 0.3f; constexpr float CHAMPION_SHOT_FALL_SPEED = -5; constexpr float FLICKER_FADE = 0.05f; // Where a flickering champion is in its fade. enum FlickerState : int { FLICKER_SHOWN, FLICKER_FADING_OUT, FLICKER_FADING_IN, FLICKER_HIDDEN }; constexpr ColorMod PULLING_RED_COLOR = {{1, 0.2f, 0.2f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; // A champion color's look. const ChampionLook& champion_look_get(int championColor) { return CHAMPION_LOOKS[championColor]; } // 00505b80 The color a champion shows over a sprite without its sheets: its sheet color laid over its sprite color // (Color::__mul), or the sprite color for a look drawn on no sheet. ColorMod champion_sprite_color_get(int championColor) { const ChampionLook& look = CHAMPION_LOOKS[championColor]; if (look.sheetColor._tint[3] <= 0) return look.spriteColor; ColorMod color = look.sheetColor; const ColorMod& other = look.spriteColor; for (int i = 0; i < 4; i++) color._tint[i] *= other._tint[i]; if (other._colorize[0] + other._colorize[1] + other._colorize[2] != 0) for (int i = 0; i < 4; i++) color._colorize[i] = other._colorize[i]; for (int i = 0; i < 3; i++) color._offset[i] += other._offset[i]; return color; } // The sheet color of a champion color's look, or none for a look drawn on no _champion sheet. const ColorMod* champion_color_get(int championColor) { if (championColor < 0 || championColor >= CHAMPION_COUNT) return nullptr; const ColorMod& sheetColor = CHAMPION_LOOKS[championColor].sheetColor; return sheetColor._tint[3] > 0 ? &sheetColor : nullptr; } // 00684b90 A color from a hue in degrees, a saturation and a value. KColor hsv_to_rgb(float hue, float saturation, float value, float alpha) { float chroma = saturation * value; float second = (1 - std::abs(std::fmod(hue / HUE_SEXTANT, 2.0f) - 1)) * chroma; float red = 0; float green = 0; float blue = 0; switch ((int)(hue / HUE_SEXTANT) % HUE_SEXTANTS) { case 0: red = chroma; green = second; break; case 1: red = second; green = chroma; break; case 2: green = chroma; blue = second; break; case 3: green = second; blue = chroma; break; case 4: red = second; blue = chroma; break; case 5: red = chroma; blue = second; break; default: break; } float base = value - chroma; return kcolor_rgba(red + base, green + base, blue + base, alpha); } // A pulse over the room's frames at a rate: a sine shifted up by a half, clamped to 0 to 1. static float pulse_get(float rate) { return std::clamp(std::sin((float)g_game->room->GetFrameCount() * rate) + PULSE_SHIFT, 0.0f, 1.0f); } // The rainbow champion's champion color: its hue a turn along every 90 frames of the room. static void rainbow_hue_update(Entity_NPC& npc) { float hue = (float)(g_game->room->GetFrameCount() % RAINBOW_HUE_FRAMES) * HUE_FULL_TURN / RAINBOW_HUE_FRAMES; KColor color = hsv_to_rgb(hue, 1, 1, 1); npc.sprite.championColor = tint_color_make(color._red, color._green, color._blue, 1); } // The fly protected champion's eternal fly when it becomes one late, shrunk at once (FUN_006b5de0). static void shrunk_eternal_fly_spawn(Entity_NPC& npc) { Entity* fly = spawn_at(ENTITY_ETERNALFLY, 0, 0, npc.pos, &npc); fly->parent = &npc; fly->AddShrink(EntityRef(&npc), ETERNAL_FLY_SHRINK_FRAMES, true, true); if (fly->shrinkCountdown <= 0) return; fly->AddEntityFlags(FLAG_SHRINK); fly->shrinkStatus1 = fly->shrinkStatus2; } // Part of 006d03e0: a seed's champion color by the stage: rarely white or rainbow and uncommonly a strange one late, // else a rare, pulsing or sized, special late, or common one. static int champion_color_roll(uint32_t seed) { RNG rng; rng.SetSeed(seed, CHAMPION_RNG_SHIFT_INDEX); float roll = rng.RandomFloat(); uint32_t stage = g_game->stage; bool isLate = stage >= CHAMPION_LATE_STAGE; if (roll < CHAMPION_ROLL_RAINBOW && isLate) return roll < CHAMPION_ROLL_WHITE ? CHAMPION_WHITE : CHAMPION_RAINBOW; if (roll < CHAMPION_ROLL_UNCOMMON && isLate) return CHAMPIONS_UNCOMMON[rng.RandomInt(CHAMPIONS_UNCOMMON.size())]; if (roll < CHAMPION_ROLL_RARE) return CHAMPIONS_RARE[rng.RandomInt(CHAMPIONS_RARE.size())]; if (roll < CHAMPION_ROLL_PULSING) { uint32_t count = stage >= CHAMPION_YELLOW_STAGE ? CHAMPIONS_PULSING.size() : CHAMPION_PULSING_EARLY_COUNT; return CHAMPIONS_PULSING[rng.RandomInt(count)]; } if (roll < CHAMPION_ROLL_SPECIAL && isLate) return CHAMPIONS_SPECIAL[rng.RandomInt(CHAMPIONS_SPECIAL.size())]; if (stage < CHAMPION_YELLOW_STAGE) return CHAMPIONS_EARLY[rng.RandomInt(CHAMPIONS_EARLY.size())]; return CHAMPIONS_LATE[rng.RandomInt(CHAMPIONS_LATE.size())]; } // Part of 006d03e0: what a champion color changes beside the look: health, speed, grid collision, timers, and the // pulling effect or eternal fly some keep with them. void Entity_NPC::champion_traits_apply(bool isInit) { switch (championColorIdx) { case CHAMPION_RED: maxHitPoints *= CHAMPION_HP_RED; break; case CHAMPION_YELLOW: championSpeed = CHAMPION_SPEED_FAST; maxHitPoints *= CHAMPION_HP_YELLOW; break; case CHAMPION_GREY: maxHitPoints *= CHAMPION_HP_GREY; [[fallthrough]]; case CHAMPION_DARK_BLUE: championSpeed = CHAMPION_SPEED_SLOW; break; case CHAMPION_TRANSPARENT: entityGridCollisionClass = GRIDCOLL_WALLS; break; case CHAMPION_FLICKER: flickerTimer = random_below(CHAMPION_FLICKER_RANGE) + CHAMPION_FLICKER_MIN; break; case CHAMPION_PINK: championTimer = random_below(CHAMPION_SHOT_RANGE) + CHAMPION_SHOT_MIN; break; case CHAMPION_PURPLE: spawn_at(ENTITY_EFFECT, EFFECT_PULLING_EFFECT, PULLING_PURPLE, pos, this)->parent = this; break; case CHAMPION_PULSE_GREY: spawn_at(ENTITY_EFFECT, EFFECT_PULLING_EFFECT, PULLING_GREY, pos, this)->parent = this; break; case CHAMPION_FLY_PROTECTED: if (!isInit) shrunk_eternal_fly_spawn(*this); break; case CHAMPION_TINY: maxHitPoints *= CHAMPION_HP_GREY; championSpeed *= CHAMPION_SPEED_FAST; break; case CHAMPION_GIANT: maxHitPoints *= CHAMPION_HP_BIG; championSpeed *= CHAMPION_SPEED_GIANT; [[fallthrough]]; case CHAMPION_DEATH: if (collisionDamage > 0) collisionDamage = CHAMPION_DEATH_CONTACT_DAMAGE; break; case CHAMPION_PULSE_RED: { Entity* pulling = spawn_at(ENTITY_EFFECT, EFFECT_PULLING_EFFECT, PULLING_RED, pos, this); pulling->parent = this; pulling->SetColor(PULLING_RED_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); break; } case CHAMPION_KING: maxHitPoints *= CHAMPION_HP_KING; break; case CHAMPION_RAINBOW: championSpeed = CHAMPION_SPEED_FAST; maxHitPoints *= CHAMPION_HP_BIG; championTimer = random_below(CHAMPION_SHOT_RANGE) + CHAMPION_SHOT_MIN; spawn_at(ENTITY_EFFECT, EFFECT_PULLING_EFFECT, PULLING_PURPLE, pos, this)->parent = this; if (!isInit) spawn_at(ENTITY_ETERNALFLY, 0, 0, pos, this)->parent = this; rainbow_hue_update(*this); break; default: break; } } // 006d03e0 Makes it a champion of a color, or of one its seed draws for the stage at -1: twice the health and 2 // contact damage, its size (half for the tiny, 1.5 for the giant, 1.15 else), its champion sprite and its color's // traits. Dark red never befalls the slides and white not the fly protected kind. Only Init makes a champion twice. void Entity_NPC::MakeChampion(uint32_t seed, int championColor, bool isInit) { if (isChampion && !isInit) return; float baseMaxHitPoints = maxHitPoints; maxHitPoints = baseMaxHitPoints + baseMaxHitPoints; ResetColor(); if (collisionDamage > 0) collisionDamage = CHAMPION_CONTACT_DAMAGE; isChampion = true; championColorIdx = championColor; if (championColor < 0) championColor = champion_color_roll(seed); bool isNoDarkRed = std::ranges::find(CHAMPION_NO_DARK_RED_TYPES, type) != CHAMPION_NO_DARK_RED_TYPES.end(); if (championColor == CHAMPION_DARK_RED && isNoDarkRed) championColor = CHAMPION_RED; else if (championColor == CHAMPION_WHITE && type == ENTITY_CLICKETY_CLACK) championColor = CHAMPION_FLY_PROTECTED; championColorIdx = std::clamp(championColor, (int)CHAMPION_RED, (int)CHAMPION_RAINBOW); float championScale = CHAMPION_SCALE; if (championColorIdx == CHAMPION_TINY) { SetSize(size * CHAMPION_TINY_SCALE, sizeMulti, config->gridCollisionPoints); championScale = CHAMPION_TINY_SCALE; } else if (championColorIdx == CHAMPION_GIANT) championScale = CHAMPION_GIANT_SCALE; scale = championScale; sprite.scale = vector_make(championScale * shrinkStatus1, championScale * shrinkStatus1); load_graphics(false); champion_traits_apply(isInit); if (type == ENTITY_MULLIGAN && variant == MULLIGAN_VARIANT_FLEEING) maxHitPoints = std::min(maxHitPoints, baseMaxHitPoints); if (!isInit) health = maxHitPoints; ResetColor(); } // Part of 006c4b30: the brown champion smears brown splats every 3 frames outside a crawlspace, and one in four // cells it leaves sprouts a poop it stands inside, which rarely drops anything. static void brown_champion_update(Entity_NPC& npc) { if (npc.IsFrame(BROWN_SPLAT_FRAMES, 0)) { Entity_Effect* splat = npc.MakeSplat(random_unit() * BROWN_SPLAT_SIZE_RANGE + BROWN_SPLAT_SIZE_MIN); splat->SetColor(BROWN_CHAMPION_SPLAT_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); } Room& room = *g_game->room; int gridIndex = room.GetGridIndex(npc.pos); if (gridIndex == npc.lastGridIndex) return; if (random_below(BROWN_POOP_ODDS) == 0 && npc.lastGridIndex >= 0) { GridEntity* left = room.GetGridEntity(npc.lastGridIndex); bool isFree = room.GetGridCollision(npc.lastGridIndex) == COLLISION_NONE && (!left || !is_grid_floor_special(left->type)); if (isFree) { room.SpawnGridEntity(npc.lastGridIndex, GRID_POOP, 0, Random(), 0); GridEntity* spawned = room.GetGridEntity(npc.lastGridIndex); if (spawned && spawned->type == GRID_POOP) { auto* poop = static_cast(spawned); poop->varData = 1; poop->isEnemyInside = true; poop->collisionClass = COLLISION_NONE; } } } npc.lastGridIndex = gridIndex; } // Part of 006c4b30: the purple (and rainbow) champion pulls the players and tears toward it, harder the nearer. static void purple_champion_pull(Entity_NPC& npc) { EntityList_EL& entities = g_game->room->GetEntities()->updateEL; for (size_t i = 0; i < entities.size(); i++) { Entity* entity = entities[i]; if (entity->type != ENTITY_PLAYER && entity->type != ENTITY_TEAR) continue; Vector direction = vector_normalized(vector_sub(npc.pos, entity->pos)); float strength = entity->type == ENTITY_PLAYER ? PURPLE_PULL_PLAYER : PURPLE_PULL_TEAR; float distance = vector_length(vector_sub(npc.pos, entity->pos)); float pull = std::min(std::max((PURPLE_PULL_REACH - distance) * strength / PURPLE_PULL_REACH, 0.0f), strength); entity->AddVelocity_divided(vector_scale(direction, pull), false); } } // Part of 006c4b30: the dark red champion falls as a Globin's ball at 10 health instead of dying, its AI held, then // shrinks into the ball over 5 ticks, grows back to half, and from tick 80 shrinks and grows again to rise whole // at tick 90, its AI and graphics back. static void dark_red_champion_update(Entity_NPC& npc) { if (npc.championRegenTimer == 0) { if (!npc.isDead) return; npc.championRegenCount++; npc.championRegenTimer = 1; npc.isDead = false; npc.health = REGEN_HEALTH; npc.isInvincible = false; npc.entityCollisionClass = ENTCOLL_ALL; if (npc.entityGridCollisionClass == GRIDCOLL_NONE) npc.entityGridCollisionClass = GRIDCOLL_WALLS; npc.aiCallFlags <<= AI_CALL_FLAGS_SHIFT; return; } npc.friction *= CHAMPION_REGEN_FRICTION; int ticks = npc_ticks_get(npc); for (int i = ticks; i > 0; i--) { int timer = ++npc.championRegenTimer; bool isShrinking = timer <= REGEN_SHRINK_END || (timer > REGEN_RISE_START && timer <= REGEN_RISE_SHRINK_END); if (isShrinking) { npc.SetScale(npc.scale * REGEN_SHRINK); if (timer < REGEN_SHRINK_END || timer - ticks >= REGEN_SHRINK_END) continue; npc.sprite.Load(REGEN_ANM2, GRAPHICS_LOAD); npc.sprite.Play("ReGenChamp", PLAY_FORCED); npc.ResetColor(); continue; } if (timer > REGEN_GROW_END && timer <= REGEN_RISE_SHRINK_END) continue; npc.SetScale(npc.scale * REGEN_GROW); if (timer < REGEN_END) continue; npc.load_graphics(true); npc.state = NPC_STATE_APPEAR; npc.championRegenTimer = 0; npc.friction = npc.baseFriction; npc.aiCallFlags >>= AI_CALL_FLAGS_SHIFT; bool isTargetReset = std::ranges::find(REGEN_TARGET_RESET_TYPES, npc.type) != REGEN_TARGET_RESET_TYPES.end(); if (isTargetReset || npc.type == ENTITY_CLICKETY_CLACK) npc.targetPosition = {}; if (npc.type == ENTITY_CLICKETY_CLACK) { npc.ClearEntityFlags(CLICKETY_CLACK_REGEN_CLEARED); npc.isInvincible = false; } npc.pathfinder.Reset(); npc.ResetColor(); } } // Part of 006c4b30: the camouflaged champion is black, its color offset drifting toward the floor under it. static void camo_champion_update(Entity_NPC& npc) { KColor floor = room_floor_texel_get(*g_game->room, npc.pos); std::array target = {floor._red, floor._green, floor._blue}; ColorMod camo = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0}}; for (int i = 0; i < 3; i++) { float from = npc.sprite.color._offset[i]; camo._offset[i] = from + (target[i] * CAMO_FLOOR_SHARE - from) * CAMO_DRIFT; } npc.sprite.color = camo; } // Part of 006c4b30: the grey pulsing champion pushes the tears near it away, the nearer the harder. static void pulse_tears_push(Entity_NPC& npc, float strength) { for (Entity* tear : entity_query_radius(npc.pos, PULSE_PUSH_REACH, QUERY_TEARS)) { if (tear->type != ENTITY_TEAR) continue; Vector away = vector_sub(tear->pos, npc.pos); float closeness = 1 - vector_length_squared(away) / (PULSE_PUSH_REACH * PULSE_PUSH_REACH); tear->AddVelocity_divided(vector_resized(away, (closeness + closeness) * strength), false); } } // Part of 006c4b30: the red trail from a pulsing champion to an enemy it heals. static void heal_trail_spawn(Entity_NPC& npc, Entity& healed) { Vector offset = vector_sub(healed.pos, npc.pos); Vector speed = vector_scale(offset, HEAL_TRAIL_SPEED_SHARE); if (vector_length(speed) > HEAL_TRAIL_SPEED_MAX) speed = vector_resized(speed, HEAL_TRAIL_SPEED_MAX); int count = std::min(std::max((int)std::floor(vector_length(offset) / HEAL_TRAIL_STEP), HEAL_TRAIL_MIN), HEAL_TRAIL_MAX); for (int i = 1; i <= count; i++) { float along = (float)i / (float)(count + 1); Vector spot = vector_add(npc.pos, vector_scale(offset, along)); Vector direction = random_direction(); spot = vector_add(spot, vector_scale(direction, random_unit() * HEAL_TRAIL_SPREAD)); uint32_t seed = Random(); Vector velocity = vector_scale(speed, random_unit() * PULSE_SHIFT + PULSE_SHIFT); Entity* particle = g_game->Spawn({.position = spot, .velocity = velocity, .type = ENTITY_EFFECT, .variant = EFFECT_HAEMO_TRAIL, .seed = seed}); particle->SetColor(HEAL_TRAIL_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); float particleScale = along * (random_unit() * HEAL_TRAIL_SCALE + HEAL_TRAIL_SCALE); particle->sprite.scale = vector_make(particleScale, particleScale); particle->posOffset = vector_add(npc.posOffset, vector_make(0, npc.sprite.scale.y * HEAL_TRAIL_RISE)); } } // Part of 006c4b30: the red pulsing champion heals the hurt enemies of its side by 20, but other red pulsing ones // and Bishops, each with a heart, a trail and a flash, flashing itself with a slurp if it healed any. static void pulse_enemies_heal(Entity_NPC& npc) { bool isAnyHealed = false; EntityList_EL& entities = g_game->room->GetEntities()->updateEL; for (size_t i = 0; i < entities.size(); i++) { Entity* entity = entities[i]; if (!entity->IsActiveEnemy(DEAD_EXCLUDED) || entity == &npc) continue; if (entity->HasEntityFlags(FLAG_FRIENDLY) != npc.HasEntityFlags(HEAL_SIDE_FLAGS)) continue; // The original reads every enemy as an NPC here. A non-NPC enemy is left out. auto* other = dynamic_cast(entity); if (!other || other->championColorIdx == CHAMPION_PULSE_RED) continue; if (other->health >= other->maxHitPoints || other->IsType(ENTITY_BISHOP, -1, -1)) continue; other->health = std::min(other->health + PULSE_HEAL, other->maxHitPoints); g_game->Spawn({.position = other->pos, .type = ENTITY_EFFECT, .variant = EFFECT_HEART, .seed = Random()}); heal_trail_spawn(npc, *other); isAnyHealed = true; other->SetColor(HEAL_FLASH_COLOR, HEAL_FLASH_FRAMES, COLOR_PRIORITY_DEFAULT, true, true); } if (!isAnyHealed) return; npc.SetColor(HEAL_FLASH_COLOR, HEAL_FLASH_FRAMES, COLOR_PRIORITY_DEFAULT, true, true); npc_sound_play(SOUND_VAMP_GULP, 1, 2, 1); } // Part of 006c4b30: a pulsing champion (green, grey or red) fades between its look and its plain colors, the grey // one pushing tears away low in its pulse and the red one healing its side every 30 frames. static void pulse_champion_update(Entity_NPC& npc) { float slowPulse = pulse_get(PULSE_SLOW_RATE); float fastPulse = pulse_get(PULSE_FAST_RATE); const ChampionLook& look = champion_look_get(npc.championColorIdx); npc.sprite.color = color_lerp(look.spriteColor, COLOR_DEFAULT, fastPulse); const float* sheet = look.sheetColor._tint; npc.sprite.championColor = tint_color_make(sheet[0], sheet[1], sheet[2], 1 - slowPulse); if (npc.championColorIdx == CHAMPION_PULSE_GREY && slowPulse < PULSE_PUSH_END) pulse_tears_push(npc, lerp_range(slowPulse, {PULSE_PUSH_START, PULSE_PUSH_END, 1, 0})); else if (npc.championColorIdx == CHAMPION_PULSE_RED && npc.IsFrame(PULSE_HEAL_FRAMES, (int)npc.index)) pulse_enemies_heal(npc); } // Part of 006c4b30: every 30 frames the king champion makes the plain enemies around it yellow champions in look. static void king_champion_update(Entity_NPC& npc) { if (!npc.IsFrame(KING_FRAMES, (int)npc.index)) return; EntityList_EL& entities = g_game->room->GetEntities()->updateEL; for (size_t i = 0; i < entities.size(); i++) { Entity* entity = entities[i]; if (!entity->IsActiveEnemy(DEAD_EXCLUDED) || entity->IsBoss() || entity == &npc) continue; auto* other = dynamic_cast(entity); if (!other || other->isChampion) continue; other->isChampion = true; other->championColorIdx = CHAMPION_YELLOW; other->ResetColor(); } } // Part of 006c4b30: what a champion's color does each frame: green creep, brown poop, the white one's shield, // the flicker (and Wrath's twin's), pink shots, the purple pull, dark red regeneration, camouflage, the pulses, the // king's court, the rainbow's hues, and a shrunk enemy's pulse. void Entity_NPC::champion_update() { const NullFrame* overlay = sprite.animState.animData ? sprite.animState.GetNullFrame("OverlayEffect") : nullptr; bool isEffectShown = !overlay || overlay->isVisible; bool isShrunk = HasEntityFlags(FLAG_SHRINK); int champion = championColorIdx; bool isGreen = champion == CHAMPION_GREEN || champion == CHAMPION_RAINBOW; if (isGreen && isEffectShown && IsFrame(CHAMPION_CREEP_FRAMES, 0) && !isShrunk) { Entity_Effect* creep = static_cast(spawn_at(ENTITY_EFFECT, EFFECT_CREEP_GREEN, 0, pos, this)); creep->SetTimeout(CHAMPION_CREEP_TIMEOUT); creep->Update(); } if (champion == CHAMPION_BROWN && g_game->room->roomType != ROOM_DUNGEON && isEffectShown) brown_champion_update(*this); if (champion == CHAMPION_WHITE) white_champion_update(); if (champion == CHAMPION_FLICKER || type == ENTITY_FLICKER_TYPE) flicker_update(); if (champion == CHAMPION_TRANSPARENT) entityGridCollisionClass = GRIDCOLL_WALLS; else if ((champion == CHAMPION_PINK || champion == CHAMPION_RAINBOW) && --championTimer < 1 && isEffectShown && !isShrunk) champion_shot_fire(); if ((champion == CHAMPION_PURPLE || champion == CHAMPION_RAINBOW) && isEffectShown) purple_champion_pull(*this); switch (champion) { case CHAMPION_DARK_RED: dark_red_champion_update(*this); break; case CHAMPION_CAMO: camo_champion_update(*this); break; case CHAMPION_PULSE_GREEN: case CHAMPION_PULSE_GREY: case CHAMPION_PULSE_RED: pulse_champion_update(*this); break; case CHAMPION_KING: king_champion_update(*this); break; case CHAMPION_SIZE_PULSE: if (championTimer > 0) championTimer--; break; case CHAMPION_RAINBOW: rainbow_hue_update(*this); break; default: break; } if (!isShrunk || shrinkCountdown < 1 || shrinkCountdown >= SHRINK_PULSE_FRAMES) return; sprite.color = color_lerp(SHRINK_PULSE_COLOR, COLOR_DEFAULT, pulse_get(PULSE_FAST_RATE)); } // Part of 006d60a0: a size pulsing champion a player hurt (not by acid nor a blue fly) throws out an attack fly // from its edge, keeping no more than 5 and waiting 60 frames between them. void Entity_NPC::champion_fly_spawn() { int flies = 0; for (Entity* entity : g_game->room->GetEntities()->updateEL) if (entity->spawnerEntity.get() == this) flies++; if (flies > SIZE_PULSE_FLY_MAX) return; uint32_t seed = Random(); Vector edge = vector_add(pos, vector_scale(random_direction(), size)); Entity* fly = g_game->Spawn({.position = edge, .spawner = this, .type = ENTITY_ATTACKFLY, .seed = seed}); fly->isKillOnTouch = true; fly->spawnerEntity = this; fly->Update(); championTimer = SIZE_PULSE_FLY_COOLDOWN; } // Part of 006c4b30: a white champion cannot be hurt while another enemy holding the doors lives, unless that one is // white too. void Entity_NPC::white_champion_update() { isInvincible = false; ClearEntityFlags(FLAG_NO_STATUS_EFFECTS); for (Entity* entity : g_game->room->GetEntities()->updateEL) { Entity_NPC* npc = entity->IsEnemy() ? dynamic_cast(entity) : nullptr; if (!npc || !npc->CanShutDoors() || (npc->isChampion && npc->championColorIdx == CHAMPION_WHITE)) continue; isInvincible = true; AddEntityFlags(FLAG_NO_STATUS_EFFECTS); } } // Part of 006c4b30: the flickering champion (and the Flicker kind) waits visible, fades out, hides, then fades back // in, its sprite's alpha following. void Entity_NPC::flicker_update() { switch (flickerState) { case FLICKER_SHOWN: if (flickerTimer-- < 0) flickerState = FLICKER_FADING_OUT; break; case FLICKER_FADING_OUT: if (flickerAlpha > 0) flickerAlpha -= FLICKER_FADE; else { flickerState = FLICKER_HIDDEN; flickerTimer = random_below(CHAMPION_FLICKER_RANGE) + CHAMPION_FLICKER_MIN; } break; case FLICKER_FADING_IN: if (flickerAlpha < 1) flickerAlpha += FLICKER_FADE; else { flickerState = FLICKER_SHOWN; flickerTimer = random_below(CHAMPION_FLICKER_RANGE) + CHAMPION_FLICKER_MIN; } break; case FLICKER_HIDDEN: isVisible = false; if (flickerTimer-- < 0) { isVisible = true; flickerState = FLICKER_FADING_IN; } break; default: break; } sprite.color._tint[3] = flickerAlpha; } // Part of 006c4b30: the pink champion shoots along its walk every 40 to 59 frames while it moves. void Entity_NPC::champion_shot_fire() { float speed = vector_length(velocity); if (speed <= 0) return; Vector direction = vector_scale(velocity, 1 / speed); championTimer = random_below(CHAMPION_SHOT_RANGE) + CHAMPION_SHOT_MIN; ProjectileParams params; params.fallingAccelModifier = CHAMPION_SHOT_FALL_ACCEL; params.fallingSpeedModifier = CHAMPION_SHOT_FALL_SPEED; FireProjectiles(pos, vector_scale(direction, CHAMPION_SHOT_SPEED), PROJECTILES_SINGLE, params); PlaySound(SOUND_BLOODSHOOT, 1, 2, false, 1); }