#include "npc_gehenna.h" #include "boss_ai.h" #include "entity_player.h" // The Mockulus is an invulnerable eye that keeps shut while no player shoots. Once one does it opens and slides // diagonally, bouncing off the walls, until the shooting stops and it shuts again. Its pupil (layer 2) watches the // nearest player. It dies once the room's plates are pressed or the rest are dead. constexpr int MOCKULUS_SHUT = NPC_STATE_IDLE; constexpr int MOCKULUS_OPEN = NPC_STATE_MOVE; constexpr int MOCKULUS_PUPIL_LAYER = 2; constexpr float MOCKULUS_PUPIL_REACH = 4; constexpr float MOCKULUS_PUPIL_SPEED = 3; constexpr int MOCKULUS_TOGGLE_HOLD = 10; constexpr float MOCKULUS_SHUT_FRICTION = 0.8f; constexpr float MOCKULUS_OPEN_FRICTION = 0.9f; constexpr int MOCKULUS_SPLAT_ODDS = 4; constexpr float MOCKULUS_SPLAT_MIN = 0.3f; constexpr float MOCKULUS_SPLAT_RANGE = 0.3f; constexpr int MOCKULUS_CLEAR_DELAY = 8; constexpr float MOCKULUS_NO_PLAYER = 100000; // Eases its pupil toward the nearest player (to the middle with none), 3 a frame at most. static void pupil_update(Entity_NPC& npc, Entity_Player* nearest) { Vector goal{}; if (nearest) goal = vector_scale(vector_normalized(vector_sub(nearest->pos, npc.pos)), MOCKULUS_PUPIL_REACH); LayerState& pupil = *npc.sprite.GetLayer(MOCKULUS_PUPIL_LAYER); if (pupil.pos.x == goal.x && pupil.pos.y == goal.y) return; float maxStep = npc.speedMultiplier * MOCKULUS_PUPIL_SPEED; Vector step = vector_sub(goal, pupil.pos); float length = vector_length(step); if (maxStep < length) step = vector_scale(step, maxStep / length); pupil.pos = vector_add(step, pupil.pos); } // Open: it bleeds a little and pushes on diagonally, shutting once no one shoots and its hold ran out. static void open_update(Entity_NPC& npc, bool isAnyShooting) { npc.friction *= MOCKULUS_OPEN_FRICTION; if (npc_anim_is_done(npc)) npc_anim_loop(npc.sprite, "Idle"); if ((Random() & (MOCKULUS_SPLAT_ODDS - 1)) == 0) npc.MakeSplat(random_unit() * MOCKULUS_SPLAT_RANGE + MOCKULUS_SPLAT_MIN); Vector sign = vector_make(npc.velocity.x < 0 ? -1 : 1, npc.velocity.y < 0 ? -1 : 1); if (npc.friction != 0) { npc.velocity.y += npc.speedMultiplier * sign.y / npc.friction; npc.velocity.x += npc.speedMultiplier * sign.x / npc.friction; } npc.v2 = sign; if (npc.i1 > 0 || isAnyShooting) return; npc_anim_loop(npc.sprite, "Close"); npc.state = MOCKULUS_SHUT; npc.i1 = MOCKULUS_TOGGLE_HOLD; } // Shut: it waits, opening when a player shoots and setting off the way it last went. static void shut_update(Entity_NPC& npc, bool isAnyShooting) { npc.friction *= MOCKULUS_SHUT_FRICTION; if (npc_anim_is_done(npc)) npc_anim_loop(npc.sprite, "CloseIdle"); if (!isAnyShooting) return; npc_anim_loop(npc.sprite, "Open"); npc.state = MOCKULUS_OPEN; npc.i1 = MOCKULUS_TOGGLE_HOLD; npc.velocity = vector_add(npc.velocity, npc.v2); } // 004f76f0 The Mockulus' AI: a shut eye that opens and slides about while a player shoots, watching the nearest one, // and dies once the room is cleared. void npc_mockulus_update(Entity_NPC& npc) { bool isCleared = room_plates_is_triggered() || (npc.GetAliveEnemyCount() <= 0 && g_game->room->roomClearDelay <= MOCKULUS_CLEAR_DELAY); bool isAnyShooting = false; float nearestDistance = MOCKULUS_NO_PLAYER; Entity_Player* nearest = nullptr; for (Entity_Player* player : g_game->playerManager.playerList) { float distance = vector_length_squared(vector_sub(npc.pos, player->pos)); if (player->fireDirection != DIRECTION_NONE) isAnyShooting = true; if (distance < nearestDistance) { nearestDistance = distance; nearest = player; } } switch (npc.state) { case NPC_STATE_INIT: npc.flags |= FLAG_NO_STATUS_EFFECTS | FLAG_HIDE_HP_BAR; npc.isInvincible = true; npc.entityGridCollisionClass = GRIDCOLL_WALLS; npc.state = MOCKULUS_SHUT; npc_anim_loop(npc.sprite, "CloseIdle"); break; case MOCKULUS_SHUT: shut_update(npc, isAnyShooting); break; case MOCKULUS_OPEN: open_update(npc, isAnyShooting); break; default: break; } pupil_update(npc, nearest); if (npc.i1 > 0) npc.i1 -= npc_ticks_get(npc); if (isCleared) npc.Kill(EntityRef{}); }