#include "boss_ai.h" #include "npc_caves.h" #include // The Gush spews black creep: a puddle under it, then now and then another near one of its own puddles. constexpr ColorMod GUSH_SPLAT_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0}}; constexpr int GUSH_GRID_MARK = 900; constexpr int GUSH_GRID_MARK_LIMIT = 951; constexpr float GUSH_FRICTION = 0.8f; constexpr int GUSH_REST_MIN = 1; constexpr uint32_t GUSH_REST_RANGE = 10; constexpr float GUSH_CREEP_SCALE = 2; constexpr int GUSH_CREEP_TIMEOUT = 30; constexpr int GUSH_SPEW_TIMEOUT = 45; constexpr size_t GUSH_CREEP_LIMIT = 256; constexpr int GUSH_SPEW_TRIES = 10; constexpr float GUSH_SPEW_REACH = 200; constexpr float GUSH_SPEW_REACH_STEP = 100; constexpr float GUSH_OWN_CREEP_REACH_SQUARED = 5625; constexpr float GUSH_CROWDED_SQUARED = 1600; constexpr int GUSH_CREEP_HELD = 30; constexpr float GUSH_CREEP_GROW_START = 45; constexpr float GUSH_CREEP_GROW_SPAN = -15; constexpr float GUSH_CREEP_GROWN = 1.5f; constexpr float GUSH_SPLAT_MIN = 0.8f; constexpr float GUSH_SPLAT_RANGE = 0.4f; // A puddle of its creep, scaled, lasting a while. static Entity_Effect* gush_creep_spawn(Entity_NPC& npc, Vector position, int timeout) { auto* creep = static_cast(g_game->Spawn( {.position = position, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_CREEP_BLACK, .seed = Random()})); creep->timeout = timeout; creep->lifespan = timeout; creep->parent = &npc; creep->sprite.scale = vector_make(GUSH_CREEP_SCALE, GUSH_CREEP_SCALE); creep->Update(); return creep; } // Its puddles grow in as they spread and stay until it dies, each leaving a black splat as it settles. static void gush_creep_update(Entity_NPC& npc, std::vector& creeps) { for (Entity* entity : creeps) { auto* creep = static_cast(entity); if (creep->parent.get() != &npc) continue; if (creep->timeout <= GUSH_CREEP_HELD) { creep->timeout = GUSH_CREEP_HELD; creep->lifespan = GUSH_CREEP_HELD; continue; } float grown = std::clamp(((float)creep->timeout - GUSH_CREEP_GROW_START) / GUSH_CREEP_GROW_SPAN, 0.0f, 1.0f); creep->sprite.scale = vector_make(grown * GUSH_CREEP_GROWN, grown * GUSH_CREEP_GROWN); if (creep->timeout != GUSH_CREEP_HELD + 1) continue; Entity* splat = g_game->Spawn( {.position = creep->pos, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_BLOOD_SPLAT, .seed = Random()}); float size = random_unit() * GUSH_SPLAT_RANGE + GUSH_SPLAT_MIN; splat->sprite.scale = vector_make(size, size); splat->SetColor(GUSH_SPLAT_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); splat->Update(); } } // A new puddle, in ten tries further out each time: on a free spot in the room, clear of every puddle within 40 and // near one of its own within 75. It grows in from nothing. static void gush_spew(Entity_NPC& npc) { Room& room = *g_game->room; float reach = GUSH_SPEW_REACH; for (int i = 0; i < GUSH_SPEW_TRIES; i++, reach += GUSH_SPEW_REACH_STEP) { float spread = random_unit(); Vector direction = random_direction(); Vector spot = vector_add(npc.pos, vector_scale(direction, spread * spread * reach)); if (!room.IsPositionInRoom(spot, 0) || room.GetGridCollision(room.GetGridIndex(spot)) != 0) continue; std::vector creeps = entity_query(ENTITY_EFFECT, EFFECT_CREEP_BLACK); bool isOwnNear = false; bool isCrowded = false; for (Entity* creep : creeps) { float distance = vector_length_squared(vector_sub(spot, creep->pos)); if (distance < GUSH_OWN_CREEP_REACH_SQUARED && creep->parent.get() == &npc) isOwnNear = true; if (distance < GUSH_CROWDED_SQUARED) isCrowded = true; if (isCrowded) break; } if (isCrowded || !isOwnNear) continue; gush_creep_spawn(npc, spot, GUSH_SPEW_TIMEOUT)->sprite.scale = {}; return; } } // 00547330 The Gush (309): it sits in its creep, marking its cell for the pathfinder, and spews more every few frames. void npc_gush_update(Entity_NPC& npc) { Room& room = *g_game->room; int column = (int)((npc.pos.x - GRID_ORIGIN_X) / GRID_CELL_SIZE + 0.5f); int row = (int)((npc.pos.y - GRID_ORIGIN_Y) / GRID_CELL_SIZE + 0.5f); int cell = row * room.gridWidth + column; bool isInside = column >= 0 && column < room.gridWidth && row >= 0 && row < room.gridHeight && cell < ROOM_GRID_CELLS; if (isInside && room.gridPaths[cell] < GUSH_GRID_MARK_LIMIT) room.gridPaths[cell] = GUSH_GRID_MARK; if (npc.state == NPC_STATE_INIT) { npc.splatColor = GUSH_SPLAT_COLOR; npc.state = NPC_STATE_IDLE; npc.targetPosition = npc.pos; npc.AddEntityFlags(FLAG_NO_PLAYER_CONTROL); npc.i1 = (int)(Random() % GUSH_REST_RANGE) + GUSH_REST_MIN; gush_creep_spawn(npc, npc.pos, GUSH_CREEP_TIMEOUT); return; } if (npc.state == NPC_STATE_IDLE) { npc.sprite.Play("Spew"); npc.velocity = vector_sub(npc.targetPosition, npc.pos); std::vector creeps = entity_query(ENTITY_EFFECT, EFFECT_CREEP_BLACK); gush_creep_update(npc, creeps); if (npc.i1 >= 1) npc.i1 -= npc_ticks_get(npc); else if (creeps.size() < GUSH_CREEP_LIMIT) { npc.i1 = (int)(Random() % GUSH_REST_RANGE) + GUSH_REST_MIN; gush_spew(npc); } } npc.friction = GUSH_FRICTION; }