#include "npc_depths.h" #include "boss_ai.h" #include "sfx_manager.h" #include // One Deep Gaper in 3 without a subtype rolls one of 6 heads, the sixth carrying a leech it throws as it dies. constexpr int DEEP_GAPER_HEAD_ODDS = 3; constexpr int DEEP_GAPER_HEADS = 6; constexpr int DEEP_GAPER_LEECH_HEAD = 6; // Those in the room as it is entered lie under the water, unseen and untouchable, until the fight is on (its last // enemy gone, its plates pressed, or itself friendly). Then, every 4 frames, one time in 8 (or after 90 frames), with // no player within 60, it rises out. constexpr int DEEP_GAPER_PLATE_DELAY = 9; constexpr int DEEP_GAPER_RISE_CHECK_FRAMES = 4; constexpr uint32_t DEEP_GAPER_RISE_MASK = 7; constexpr int DEEP_GAPER_RISE_AFTER = 90; constexpr float DEEP_GAPER_RISE_CLEARANCE = 60; constexpr float DEEP_GAPER_STEER_SPEED = 1; constexpr std::array DEEP_GAPER_AMBUSHES = {"Ambush1", "Ambush2"}; constexpr int DEEP_GAPER_SPLASH_SOUND_DELAY = 10; // Out, it walks its grid path at 0.6 (fleeing when scared), groaning one time in 3 while it sees its prey. constexpr float DEEP_GAPER_PATH_SPEED = 0.6f; constexpr int DEEP_GAPER_PATH_MARKER = 900; constexpr float DEEP_GAPER_WALK_THRESHOLD = 0.1f; constexpr float DEEP_GAPER_FEAR_FRICTION = 0.8f; constexpr uint32_t DEEP_GAPER_GROAN_ODDS = 3; constexpr int DEEP_GAPER_GROAN_DELAY = 40; // Out of the water: walking, its head on. static void deep_gaper_surface(Entity_NPC& npc) { npc.state = NPC_STATE_MOVE; npc.sprite.SetFrame("WalkVert", 0); npc.sprite.PlayOverlay("Head"); } // Its head, then whether it waits under the water (when spawned as the room is entered). static void deep_gaper_init(Entity_NPC& npc) { if (npc.subtype == 0) { RNG rng = {npc.initSeed, 1, 5, 16}; if (rng.RandomInt(DEEP_GAPER_HEAD_ODDS) == 0) npc.Morph(npc.type, npc.variant, (int)rng.RandomInt(DEEP_GAPER_HEADS) + 1, -1); } Room& room = *g_game->room; if (!room.isInitialized || g_game->frameCount != room.enterFrame) { deep_gaper_surface(npc); npc.entityCollisionClass = ENTCOLL_ALL; return; } npc.entityCollisionClass = ENTCOLL_NONE; npc.isVisible = false; npc.isCanShutDoors = false; npc.state = NPC_STATE_IDLE; npc.isInvincible = true; npc.ClearEntityFlags(FLAG_APPEAR); npc.AddEntityFlags(FLAG_NO_STATUS_EFFECTS | FLAG_NO_TARGET); npc.i1 = npc.championColorIdx; npc.championColorIdx = CHAMPION_NONE; } // Under the water: waiting for the fight, then rising out when the moment comes (or its controller says). static void deep_gaper_wait(Entity_NPC& npc) { bool isControlled = npc.controllerID != -1; if (isControlled) { npc.pathfinder.FindGridPath({}, DEEP_GAPER_STEER_SPEED, 0, DIRECT_PATH_FAR); npc.SpawnControlTarget(2, -1); } if (!npc.isCanShutDoors) { Room& room = *g_game->room; bool isFightOn = npc.HasEntityFlags(FLAG_FRIENDLY) || (npc.GetAliveEnemyCount() < 1 && room.roomClearDelay < DEEP_GAPER_PLATE_DELAY) || g_game->GetCurrentRoomDesc()->flags & ROOM_DESCRIPTOR_FLAG_PRESSURE_PLATES_TRIGGERED; if (!isFightOn) return; npc.isCanShutDoors = true; npc.stateFrame = 0; return; } if (isControlled) npc.UpdateChargeBar(DEEP_GAPER_RISE_AFTER, 0, (float)npc.stateFrame, true); bool isRising = false; if (npc.IsFrame(DEEP_GAPER_RISE_CHECK_FRAMES, 0)) isRising = (Random() & DEEP_GAPER_RISE_MASK) == 0 || npc.stateFrame > DEEP_GAPER_RISE_AFTER; if (!isRising && isControlled) isRising = npc.IsControllerActionPressed(CONTROLLER_ACTION_SHOOT) || npc.stateFrame > DEEP_GAPER_RISE_AFTER; if (isRising && !npc.IsPlayerInRadius(npc.pos, DEEP_GAPER_RISE_CLEARANCE)) { if (npc.chargeBarSprite.isLoaded) npc.chargeBarSprite.color._tint[3] = 0; npc.state = NPC_STATE_ATTACK; npc.sprite.Play(DEEP_GAPER_AMBUSHES[npc.initSeed & 1]); npc.ClearEntityFlags(FLAG_NO_STATUS_EFFECTS | FLAG_NO_TARGET); npc.isVisible = true; npc.isInvincible = false; npc.championColorIdx = npc.i1; g_game->UpdateBackwardsPathStages(); } npc.stateFrame += npc_ticks_get(npc); } // Walking after its prey, groaning now and then. static void deep_gaper_walk(Entity_NPC& npc) { npc.AnimWalkFrame("WalkHori", "WalkVert", DEEP_GAPER_WALK_THRESHOLD); if (!npc.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK) || npc.controllerID != -1) npc.pathfinder.FindGridPath(npc.CalcTargetPosition(0), DEEP_GAPER_PATH_SPEED, DEEP_GAPER_PATH_MARKER, DIRECT_PATH_FAR); else { npc.pathfinder.EvadeTarget(npc.GetPlayerTarget()->pos, STATUS_OBEYED); npc.friction *= DEEP_GAPER_FEAR_FRICTION; } bool isGroaning = npc.controllerID == -1 ? npc.IsHostileTo(npc.GetPlayerTarget()) && npc.pathfinder.hasDirectPath && Random() % DEEP_GAPER_GROAN_ODDS == 0 : npc.IsControllerActionPressed(CONTROLLER_ACTION_GROAN); if (isGroaning) npc_sound_play(SOUND_ZOMBIE_WALKER_KID, 1, DEEP_GAPER_GROAN_DELAY, champion_pitch_get(npc)); } // Rising out of the water with a splash on the "Splash" event, then walking. static void deep_gaper_rise(Entity_NPC& npc) { AnimationState& anim = npc.sprite.animState; if (anim.animData && anim.IsEventTriggered("Splash")) { g_game->Spawn({.position = npc.pos, .type = ENTITY_EFFECT, .variant = EFFECT_BIG_SPLASH, .seed = Random()}) ->Update(); npc_sound_play(SOUND_BOSS2_DIVE, 1, DEEP_GAPER_SPLASH_SOUND_DELAY, 1); npc_sound_play(SOUND_ZOMBIE_WALKER_KID, 1, DEEP_GAPER_GROAN_DELAY, champion_pitch_get(npc)); npc.entityCollisionClass = ENTCOLL_ALL; } if (!anim.animData || !anim.isPlaying) deep_gaper_surface(npc); } // 00560570 The Deep Gaper's AI: a gaper that may lie in wait under the water until the fight is on, then rises and // walks after its prey. The leech headed one throws its leech as it dies. void npc_deep_gaper_update(Entity_NPC& npc) { if (npc.state == NPC_STATE_INIT) deep_gaper_init(npc); else if (npc.state == NPC_STATE_IDLE) deep_gaper_wait(npc); else if (npc.state == NPC_STATE_MOVE) deep_gaper_walk(npc); else if (npc.state == NPC_STATE_ATTACK) deep_gaper_rise(npc); if (npc.isDead && npc.subtype == DEEP_GAPER_LEECH_HEAD) reconstruction_missing("NpcAI::ENTITY_DEEP_GAPER 00560570: its leech (Entity_NPC::ThrowLeech 0055c4c0, from 30 " "up onto a free spot within 80)"); }