Curation round 14: console and Lua API, effects, lasers, enemies, eleven bosses, the Depths and Mom, status effects, the playable characters

This commit is contained in:
shweet committed 2026-11-20 19:04:41 -05:00
1 parent 8ae02a8422
commit 6e3da161fc
138 files changed
+16754 -6825

No files matched your search

+397
View File
@@ -0,0 +1,397 @@
#include "boss_ai.h"
#include "npc_caves.h"
#include "room_grid.h"
#include "sfx_manager.h"
#include <cmath>
// Polycephalus's subtypes (the red one, and the pair) and the Stain's grey one. Variant 1 is the Pile.
constexpr int POLYCEPHALUS_RED = 1;
constexpr int POLYCEPHALUS_PAIR = 2;
constexpr int STAIN_GREY = 1;
constexpr int POLYCEPHALUS_PILE = 1;
// Their states once surfaced: the shot burst, the stream (the Stain's spin), the summon (Polycephalus) and the
// Stain's summon.
constexpr int POLYCEPHALUS_SHOOT = NPC_STATE_ATTACK;
constexpr int POLYCEPHALUS_STREAM = NPC_STATE_ATTACK2;
constexpr int POLYCEPHALUS_SUMMON = NPC_STATE_ATTACK3;
constexpr int STAIN_SUMMON = NPC_STATE_SUMMON;
// The burrow's phases (i1): going under, waiting for that to end, and moving underground.
enum PolycephalusBurrow
{
BURROW_START,
BURROW_SINKING,
BURROW_MOVING
};
// The Stain's spin phases (i1) after it surfaces: two rounds of shooting and stopping, then going under.
enum StainSpin
{
STAIN_SPIN_SHOOT = 1,
STAIN_SPIN_STOP = 2,
STAIN_SPIN_START = 3,
STAIN_SPIN_SHOOT_FAST = 4,
STAIN_SPIN_STOP_FAST = 5,
STAIN_SPIN_UNDER = 6
};
constexpr float POLYCEPHALUS_TWIN_REACH = 40;
constexpr uint32_t POLYCEPHALUS_BURROW_ODDS = 30;
constexpr float POLYCEPHALUS_FRICTION = 0.8f;
constexpr int POLYCEPHALUS_SHRINK_FRAMES = 50;
constexpr float POLYCEPHALUS_WANDER = 100;
constexpr float POLYCEPHALUS_WALL_MARGIN = 20;
constexpr float POLYCEPHALUS_DIG_SPEED = 1;
constexpr int POLYCEPHALUS_PATH_MARKER = 100;
constexpr float POLYCEPHALUS_SURFACE_REACH_SQUARED = 22500;
constexpr uint32_t POLYCEPHALUS_SURFACE_ODDS = 15;
constexpr int POLYCEPHALUS_STATUS_ENDING = 5;
constexpr int POLYCEPHALUS_ENEMY_LIMIT = 3;
constexpr uint32_t POLYCEPHALUS_SUMMON_ODDS = 5;
constexpr int POLYCEPHALUS_SOUND_DELAY = 60;
constexpr float POLYCEPHALUS_SURFACE_VOLUME = 0.8f;
constexpr float POLYCEPHALUS_LEAD = 10;
constexpr float POLYCEPHALUS_SHOOT_VOLUME = 1.5f;
constexpr float POLYCEPHALUS_SHOT_SPEED = 10;
constexpr float POLYCEPHALUS_RED_SHOTS = 6;
constexpr float POLYCEPHALUS_STREAM_ARC = 1;
constexpr float POLYCEPHALUS_WORM_REACH = 60;
constexpr float STAIN_CREEP_STEP = 0.125f;
constexpr float STAIN_CREEP_REACH = 120;
constexpr float STAIN_CREEP_GROWTH = 0.56f;
constexpr float STAIN_CREEP_MIN = 0.3f;
constexpr float STAIN_CREEP_CENTER = 1.84f;
constexpr int STAIN_CREEP_TIMEOUT = 70;
constexpr int STAIN_SPIN_FRAMES = 90;
constexpr int STAIN_STOP_FRAMES = 31;
constexpr float STAIN_SPIN_ACCEL = -0.06f;
constexpr float STAIN_SPIN_FALL = -2;
constexpr float STAIN_SPIN_TURN = 0.118f;
constexpr float STAIN_SPIN_SLOWDOWN = 0.985f;
constexpr float STAIN_SPIN_SPEED = 6;
constexpr float STAIN_SPIN_SHOTS = 3;
constexpr float STAIN_SPIN_FAST_TURN = 0.12f;
constexpr float STAIN_SPIN_SPEEDUP = 1.025f;
constexpr float STAIN_SPIN_FAST_SPEED = 3.2f;
constexpr float STAIN_SPIN_FAST_SHOTS = 4;
constexpr int STAIN_SUMMON_PAIR = 2;
constexpr float STAIN_SUMMON_REACH = 60;
// Whether its minions are few enough to summon more: three enemies, or a Delirium form's own of a type.
static bool polycephalus_is_under_cap(Entity_NPC& npc, int type)
{
if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM))
return npc.CountRelatedEntities(type, 0, nullptr) < POLYCEPHALUS_ENEMY_LIMIT;
return g_game->room->GetAliveEnemiesCount() < POLYCEPHALUS_ENEMY_LIMIT;
}
// Its full size back as it surfaces, under its shrink.
static void polycephalus_size_reset(Entity_NPC& npc, float scale)
{
npc.scale = scale;
npc.sprite.scale = vector_scale(vector_make(1, 1), scale * npc.shrinkStatus1);
}
// Underground it shrinks into its dirt and digs toward a spot near its target, surfacing to attack when near it one
// time in fifteen, or as its confusion or fear wears off.
static void polycephalus_dig(Entity_NPC& npc, bool isGrey)
{
if (npc.stateFrame++ < POLYCEPHALUS_SHRINK_FRAMES)
polycephalus_size_reset(npc, 1 - (float)npc.stateFrame / POLYCEPHALUS_SHRINK_FRAMES);
npc.sprite.Play("Dirt");
Vector target = npc.CalcTargetPosition(0);
Vector direction = random_direction();
float reach = random_unit() * POLYCEPHALUS_WANDER;
Vector spot = vector_make(reach * direction.x + target.x, reach * direction.y + target.y);
float margin = POLYCEPHALUS_WALL_MARGIN;
spot = g_game->room->GetClampedPositionImpl(spot, margin, margin, margin, margin);
npc.pathfinder.FindGridPath(spot, POLYCEPHALUS_DIG_SPEED, POLYCEPHALUS_PATH_MARKER, DIRECT_PATH_FAR);
npc.entityCollisionClass = ENTCOLL_NONE;
Vector away = vector_sub(npc.pos, npc.GetPlayerTarget()->pos);
bool isSurfacing = (vector_length_squared(away) < POLYCEPHALUS_SURFACE_REACH_SQUARED &&
Random() % POLYCEPHALUS_SURFACE_ODDS == 0) ||
(npc.HasEntityFlags(FLAG_CONFUSION) && npc.confusionCountdown < POLYCEPHALUS_STATUS_ENDING) ||
(npc.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK) && npc.fearCountdown < POLYCEPHALUS_STATUS_ENDING);
if (!isSurfacing) return;
if (npc.type == ENTITY_POLYCEPHALUS)
{
int minion = npc.subtype == POLYCEPHALUS_RED ? ENTITY_PARA_BITE : ENTITY_ROUND_WORM;
bool isUnderCap = polycephalus_is_under_cap(npc, minion);
npc.state = (int)(Random() & 1) | POLYCEPHALUS_SHOOT;
if (npc.subtype == POLYCEPHALUS_RED) npc.state = POLYCEPHALUS_SHOOT;
if (Random() % POLYCEPHALUS_SUMMON_ODDS == 0 && isUnderCap && npc.subtype != POLYCEPHALUS_PAIR)
npc.state = POLYCEPHALUS_SUMMON;
}
else if (npc.type == ENTITY_STAIN)
{
npc.state = (Random() & 1) == 0 || isGrey ? POLYCEPHALUS_SHOOT : POLYCEPHALUS_STREAM;
bool isUnderCap = polycephalus_is_under_cap(npc, isGrey ? ENTITY_ROUND_WORM : ENTITY_CHARGER);
if ((Random() % POLYCEPHALUS_SUMMON_ODDS == 0 || isGrey) && isUnderCap) npc.state = STAIN_SUMMON;
npc.stateFrame = 0;
}
npc.i1 = 0;
npc.i2 = 0;
npc.entityCollisionClass = ENTCOLL_ALL;
polycephalus_size_reset(npc, 1);
npc.UpdateDirtColor(true);
}
// The burrow: it goes under, then digs about until it surfaces.
static void polycephalus_burrow(Entity_NPC& npc, bool isGrey)
{
npc.UpdateDirtColor(false);
if (npc.i1 == BURROW_START)
{
npc.sprite.Play("GoUnder");
npc.i1 = BURROW_SINKING;
npc.i2 = 0;
npc.stateFrame = 0;
npc_sound_play(SOUND_MAGGOT_ENTER_GROUND, 1, 2, 1);
}
else if (npc.i1 == BURROW_SINKING && npc_anim_is_done(npc))
{
npc.i1 = BURROW_MOVING;
npc.i2 = 0;
npc.stateFrame = 0;
}
else if (npc.i1 == BURROW_MOVING) polycephalus_dig(npc, isGrey);
}
// Polycephalus's attacks once surfaced: a burst of shots (a ring for the red one), a stream lobbed where its target
// is heading, or a worm (a Para-Bite for the red one) summoned beside it.
static void polycephalus_attack(Entity_NPC& npc)
{
if (npc.state == POLYCEPHALUS_SHOOT)
{
npc.sprite.Play("Attack1");
if (!npc.sprite.IsEventTriggered("Shoot")) return;
Entity* target = npc.GetPlayerTarget();
Vector lead = vector_scale(npc.GetPlayerTarget()->velocity, POLYCEPHALUS_LEAD);
Vector aim = vector_sub(vector_add(lead, target->pos), npc.pos);
npc.PlaySound(SOUND_CHILD_ANGRY_ROAR, POLYCEPHALUS_SHOOT_VOLUME, POLYCEPHALUS_SOUND_DELAY, false, 1);
if (npc.subtype == POLYCEPHALUS_RED)
return npc.FireProjectiles(npc.pos, vector_make(POLYCEPHALUS_SHOT_SPEED, POLYCEPHALUS_RED_SHOTS),
PROJECTILES_RING, ProjectileParams());
if ((Random() & 1) == 0)
{
ProjectileParams params;
Vector velocity = vector_scale(vector_normalized(aim), POLYCEPHALUS_SHOT_SPEED);
return npc.FireProjectiles(npc.pos, velocity, PROJECTILES_THREE_WIDE, params);
}
return npc.FireProjectiles(npc.pos, vector_make(POLYCEPHALUS_SHOT_SPEED, 0), PROJECTILES_EIGHT,
ProjectileParams());
}
if (npc.state == POLYCEPHALUS_STREAM)
{
npc.sprite.Play("Attack2");
npc.PlaySound(SOUND_WEIRD_WORM_SPIT, 1, POLYCEPHALUS_SOUND_DELAY, false, 1);
if (!npc.sprite.WasEventTriggered("Shoot") || npc.sprite.WasEventTriggered("StopShooting")) return;
ProjectileParams params;
Entity* target = npc.GetPlayerTarget();
Vector lead = vector_scale(npc.GetPlayerTarget()->velocity, POLYCEPHALUS_LEAD);
npc.FireBossProjectiles(1, vector_add(lead, target->pos), POLYCEPHALUS_STREAM_ARC, params);
return;
}
npc.sprite.Play("Attack3");
if (!npc.sprite.IsEventTriggered("Shoot")) return;
npc.PlaySound(SOUND_SHAKEY_KID_ROAR, 1, POLYCEPHALUS_SOUND_DELAY, false, 1);
uint32_t seed = Random();
Vector spot = vector_add(vector_scale(random_direction(), POLYCEPHALUS_WORM_REACH), npc.pos);
int type = npc.subtype == POLYCEPHALUS_RED ? ENTITY_PARA_BITE : ENTITY_ROUND_WORM;
g_game->Spawn({.position = spot, .spawner = &npc, .type = type, .seed = seed})->Update();
}
// The Stain's creep: a line of red puddles across it, biggest in the middle.
static void stain_creep_spread(Entity_NPC& npc)
{
npc_sound_play(SOUND_WEIRD_WORM_SPIT, 1, 2, 1);
for (float k = -1; k <= 1; k += STAIN_CREEP_STEP)
{
uint32_t seed = Random();
Vector spot = vector_make(k * STAIN_CREEP_REACH + npc.pos.x, k * 0 + npc.pos.y);
auto* creep = static_cast<Entity_Effect*>(g_game->Spawn(
{.position = spot, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_CREEP_RED, .seed = seed}));
float scale = k == 0 ? STAIN_CREEP_CENTER : std::abs(k) * STAIN_CREEP_GROWTH + STAIN_CREEP_MIN;
creep->timeout = STAIN_CREEP_TIMEOUT;
creep->lifespan = STAIN_CREEP_TIMEOUT;
creep->sprite.scale = vector_make(scale, scale);
creep->Update();
}
}
// One round of the Stain's spin: rings of accelerating shots turning with each, slower then faster.
static void stain_spin_shoot(Entity_NPC& npc)
{
if (!npc.sprite.IsPlaying("Attack2Shooting"))
{
npc.sprite.Play("Attack2Shooting");
npc_sound_play(SOUND_STAIN_ATTACK_VOX, 1, 2, 1);
}
npc.stateFrame++;
if (npc.sprite.IsEventTriggered("Shoot"))
{
bool isFast = npc.i1 == STAIN_SPIN_SHOOT_FAST;
ProjectileParams params;
params.bulletFlags |= PROJECTILE_ACCELERATE;
params.fallingAccelModifier = STAIN_SPIN_ACCEL;
params.circleAngle = (float)npc.stateFrame * (isFast ? STAIN_SPIN_FAST_TURN : STAIN_SPIN_TURN);
params.fallingSpeedModifier = STAIN_SPIN_FALL;
params.acceleration = isFast ? STAIN_SPIN_SPEEDUP : STAIN_SPIN_SLOWDOWN;
Vector ring = isFast ? vector_make(STAIN_SPIN_FAST_SPEED, STAIN_SPIN_FAST_SHOTS)
: vector_make(STAIN_SPIN_SPEED, STAIN_SPIN_SHOTS);
npc.FireProjectiles(npc.pos, ring, PROJECTILES_RING, params);
}
if (npc.stateFrame < STAIN_SPIN_FRAMES) return;
npc.i1++;
npc.i2 = 0;
npc.stateFrame = 0;
}
// The Stain's spin: shooting, stopping, starting again faster, stopping, then going back under.
static void stain_spin(Entity_NPC& npc)
{
switch (npc.i1)
{
case STAIN_SPIN_START:
npc.sprite.Play("Attack2Start");
if (!npc_anim_is_done(npc)) return;
npc.i1++;
npc.i2 = 0;
return npc_sound_play(SOUND_THE_STAIN_BURST, 1, 2, 1);
case STAIN_SPIN_SHOOT:
case STAIN_SPIN_SHOOT_FAST:
return stain_spin_shoot(npc);
case STAIN_SPIN_STOP:
case STAIN_SPIN_STOP_FAST:
npc.sprite.Play("Attack2End");
npc.stateFrame++;
if (!npc_anim_is_done(npc) || npc.stateFrame < STAIN_STOP_FRAMES) return;
npc.i1++;
npc.i2 = 0;
npc.stateFrame = 0;
return;
case STAIN_SPIN_UNDER:
npc.sprite.Play("GoUnder2");
if (npc.i2 == 1) npc_sound_play(SOUND_MAGGOT_ENTER_GROUND, 1, 2, 1);
if (!npc_anim_is_done(npc)) return;
npc.state = NPC_STATE_MOVE;
npc.i1 = BURROW_SINKING;
npc.i2 = 0;
npc.stateFrame = 0;
return;
}
}
// The Stain's summon: two Chargers (Round Worms for the grey one) at free spots near it, fewer for a Delirium form.
static void stain_summon(Entity_NPC& npc, bool isGrey)
{
npc.sprite.Play("Summon");
if (!npc.sprite.IsEventTriggered("Summon")) return;
npc_sound_play(SOUND_SUMMONSOUND, 1, 2, 1);
int count = STAIN_SUMMON_PAIR;
if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM))
{
int spare = POLYCEPHALUS_ENEMY_LIMIT - npc.CountRelatedEntities(ENTITY_ROUND_WORM, 0, nullptr) -
npc.CountRelatedEntities(ENTITY_CHARGER, 0, nullptr);
if (spare < POLYCEPHALUS_ENEMY_LIMIT) count = spare;
}
for (int i = 0; i < count; i++)
{
uint32_t seed = Random();
Vector spot = room_free_pickup_position_find({.position = npc.pos, .step = STAIN_SUMMON_REACH});
g_game->Spawn(
{.position = spot, .spawner = &npc, .type = isGrey ? ENTITY_ROUND_WORM : ENTITY_CHARGER, .seed = seed});
}
}
// Surfacing (ComeUp, the Stain's spin from ComeUp2), then its attack, back to idle once that ends.
static void polycephalus_surface(Entity_NPC& npc, bool isGrey)
{
bool isStain = npc.type == ENTITY_STAIN;
if (npc.i1 == 0)
{
if (isStain)
{
npc.sprite.Play(npc.state == POLYCEPHALUS_STREAM ? "ComeUp2" : "ComeUp");
if (npc.i2 == 1)
{
npc_sound_play(SOUND_MAGGOT_BURST_OUT, 1, 2, 1);
npc_sound_play(SOUND_THE_STAIN_BURST, 1, 2, 1);
}
}
else
{
npc.sprite.Play("ComeUp");
npc.PlaySound(SOUND_MULTI_SCREAM, POLYCEPHALUS_SURFACE_VOLUME, POLYCEPHALUS_SOUND_DELAY, false, 1);
}
if (!npc_anim_is_done(npc)) return;
npc.i1 = 1;
npc.i2 = 0;
return;
}
if (isStain && npc.state == POLYCEPHALUS_STREAM) return stain_spin(npc);
if (isStain && npc.state == POLYCEPHALUS_SHOOT)
{
npc.sprite.Play("Attack1");
if (npc.sprite.IsEventTriggered("Shoot")) stain_creep_spread(npc);
}
else if (isStain) stain_summon(npc, isGrey);
else polycephalus_attack(npc);
if (npc_anim_is_done(npc)) npc.state = NPC_STATE_IDLE;
}
// 00489ca0 NpcAI::ENTITY_POLYCEPHALUS: Polycephalus and the Stain burrow about and surface near their target to
// shoot, spray creep, spin rings of shots or summon. The Pile (variant 1) has its own AI.
void boss_polycephalus_update(Entity_NPC& npc)
{
if (npc.variant == POLYCEPHALUS_PILE) return (void)NpcAI::ENTITY_POLYCEPHALUS_the_pile(&npc);
bool isGrey = npc.type == ENTITY_STAIN && npc.subtype == STAIN_GREY;
npc.i2++;
if (npc.state == NPC_STATE_INIT)
{
npc.state = NPC_STATE_IDLE;
bool isTwin = npc.spawnerType == ENTITY_POLYCEPHALUS;
if (npc.subtype == POLYCEPHALUS_PAIR && npc.type == ENTITY_POLYCEPHALUS && !isTwin)
{
uint32_t seed = Random();
Vector spot = vector_add(vector_scale(random_direction(), POLYCEPHALUS_TWIN_REACH), npc.pos);
g_game->Spawn({.position = spot,
.velocity = npc.velocity,
.spawner = &npc,
.subType = npc.subtype,
.type = npc.type,
.variant = npc.variant,
.seed = seed});
}
return npc.UpdateDirtColor(true);
}
bool isSurfaced = npc.state == POLYCEPHALUS_SHOOT || npc.state == POLYCEPHALUS_STREAM ||
(npc.type == ENTITY_POLYCEPHALUS ? npc.state == POLYCEPHALUS_SUMMON : npc.state == STAIN_SUMMON);
if (npc.state == NPC_STATE_IDLE)
{
npc.sprite.Play("Idle");
if (!(npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) && Random() % POLYCEPHALUS_BURROW_ODDS == 0)
{
npc.state = NPC_STATE_MOVE;
npc.i1 = BURROW_START;
npc.i2 = 0;
}
}
else if (npc.state == NPC_STATE_MOVE) polycephalus_burrow(npc, isGrey);
else if (isSurfaced) polycephalus_surface(npc, isGrey);
npc.friction *= POLYCEPHALUS_FRICTION;
if (npc.isDead) polycephalus_size_reset(npc, 1);
}