Curation round 24 (code only): pickups and slots, level generation with the Ascent and the Death Certificate return, rooms and grid entities, Game and Entity core with Polty, Clutch, Matriarch, Chimera, Bumbino and other bosses, the player's remaining branches, familiars and weapons, HUD and engine stubs, 004b6a90 renamed push_back, shared constants folded (66 duplicates, 38 main gaps)

This commit is contained in:
shweet committed 2026-11-23 03:27:24 -05:00
1 parent 11c71fe041
commit 534339a496
232 files changed
+14610 -3185

No files matched your search

+574
View File
@@ -0,0 +1,574 @@
#include "boss_ai.h"
#include "boss_repentance.h"
#include "entity_config.h"
#include "manager.h"
#include "npc_basement.h"
#include "npc_depths.h"
#include <algorithm>
#include <array>
#include <tuple>
#include <vector>
// The Matriarch's states: resting, flinching from a lost chunk, hopping, flinching in the air, spitting a Fistuloid,
// spraying worms, spitting a big shot, her rage of Fistuloids and her death into Chub.
enum MatriarchState
{
MATRIARCH_IDLE = NPC_STATE_IDLE,
MATRIARCH_FLINCH = NPC_STATE_SUICIDE,
MATRIARCH_HOP = NPC_STATE_JUMP,
MATRIARCH_AIR_FLINCH = NPC_STATE_STOMP,
MATRIARCH_SUMMON = NPC_STATE_ATTACK,
MATRIARCH_WORMS = NPC_STATE_ATTACK2,
MATRIARCH_SHOT = NPC_STATE_ATTACK3,
MATRIARCH_RAGE = NPC_STATE_SUMMON,
MATRIARCH_DEATH = NPC_STATE_SPECIAL
};
// She loses a chunk at 80, 65, 50 and 35 percent of her health: a Fistula or two (from the third) thrown back 40 out
// within 45 degrees of away from her target at 2 to 4, flinching back at 20 (6 in the air). Each chunk adds 90 to
// her anger (i1), which hits raise by 1 plus 0.6 per chunk lost, falling 1 a frame.
constexpr std::array<float, 4> MATRIARCH_CHUNKS = {0.8f, 0.65f, 0.5f, 0.35f};
constexpr float CHUNK_VOLUME = 0.8f;
constexpr int CHUNK_TWO_FROM = 1;
constexpr float CHUNK_SPREAD = 90;
constexpr float CHUNK_SPREAD_HALF = 45;
constexpr float CHUNK_OUT = 40;
constexpr float CHUNK_SPEED = 2;
constexpr float CHUNK_SPEED_RANGE = 2;
constexpr int CHUNK_FISTULA_SUBTYPE = 1000;
constexpr float CHUNK_BLOOD_SHARE = 0.5f;
constexpr float CHUNK_FLINCH_SPEED = 20;
constexpr float CHUNK_AIR_FLINCH_SPEED = 6;
constexpr int CHUNK_ANGER = 90;
constexpr float ANGER_PER_CHUNK = 0.6f;
constexpr float BLOOD_RAISE = -16;
constexpr int BLOOD_SUBTYPE_FISTULA = 4;
constexpr int BLOOD_SUBTYPE_SPLASH = 3;
constexpr int BLOOD_SUBTYPE_MEDIUM = 2;
constexpr int BLOOD_SUBTYPE_SMALL = 1;
// Resting: angered past 300 with three chunks lost she rages one time in five. Else one time in 12 she attacks: a
// Fistuloid (weight 100, 300 when angered past 150 or none is out, none with four out or when it would cost a chunk),
// worms (100) or a shot (100, 200 when cooled down). Else one time in ten she hops.
constexpr int RAGE_ANGER = 300;
constexpr int RAGE_CHUNKS = 3;
constexpr uint32_t MATRIARCH_RAGE_ODDS = 5;
constexpr int RAGE_START_ANGER = 400;
constexpr uint32_t MATRIARCH_ATTACK_ODDS = 12;
constexpr uint32_t SUMMON_WEIGHT = 100;
constexpr uint32_t SUMMON_ANGRY_WEIGHT = 300;
constexpr int SUMMON_ANGER = 150;
constexpr size_t SUMMON_LIMIT = 3;
constexpr int MATRIARCH_ATTACK_WEIGHT = 100;
constexpr int ATTACK_COOLED_WEIGHT = 200;
constexpr uint32_t MATRIARCH_HOP_ODDS = 10;
constexpr float IDLE_FRICTION = 0.5f;
constexpr float FLINCH_FRICTION = 0.8f;
// A hop at 6 at her target or the Fistuloid she leads, swerving 45 degrees when the swerve lands 128 out in the room
// and the target is more than 100 away.
constexpr float HOP_SPEED = 6;
constexpr float HOP_SWERVE_REACH = 100;
constexpr float HOP_SWERVE = 45;
constexpr float HOP_SWERVE_OUT = 128;
constexpr float MATRIARCH_LAND_VOLUME = 0.7f;
// A Fistuloid spat 20 ahead and 4 up at 10 (4 up), costing her its health down to a point above her next chunk.
constexpr float SUMMON_OUT = 20;
constexpr float SUMMON_RAISE = 4;
constexpr float MATRIARCH_SUMMON_SPEED = 10;
constexpr float SUMMON_BLOOD_SHARE = 0.3f;
constexpr int SUMMON_HIT_COUNTDOWN = 30;
// Worms: eight Chubber worms on an ellipse of 16 (22.4 across), their blood thrown at 0.3, 0.5 and 0.6 of their speed.
constexpr int WORMS = 8;
constexpr float WORM_STEP = 45;
constexpr float WORM_REACH = 16;
constexpr float WORM_WIDTH = 1.4f;
constexpr int WORM_SUBTYPE = 2;
constexpr float WORM_BLOOD_SPLASH = 0.3f;
constexpr float WORM_BLOOD_MEDIUM = 0.5f;
constexpr float WORM_BLOOD_SMALL = 0.6f;
constexpr float WORM_SOUND_VOLUME = 0.8f;
// A shot: a big red shot leaving creep at 10 from 40 ahead and 3 down, at where her target will be (a tenth of its
// speed per unit of distance, in the room), turned 45 degrees at most from straight ahead, cooling 90 to 149 frames.
constexpr float MATRIARCH_SHOT_LEAD = 0.1f;
constexpr float SHOT_MARGIN = 4;
constexpr float SHOT_OUT = 40;
constexpr float SHOT_DROP = 3;
constexpr float SHOT_TURN_MAX = 45;
constexpr float MATRIARCH_SHOT_SPEED = 10;
constexpr float MATRIARCH_SHOT_SCALE = 2;
constexpr float SHOT_SPIT_PITCH = 0.8f;
constexpr float SHOT_HEART_VOLUME = 0.8f;
constexpr float SHOT_BLOOD_RAISE = -10;
constexpr uint32_t SHOT_COOLDOWN_RANGE = 60;
constexpr int SHOT_COOLDOWN = 90;
// Her rage: she lets her Fistuloid go and spits one every 8 frames one time in two, within 90 degrees of her target,
// 20 out at 5 to 10, with half health, that dies on touch and the player cannot steer, until her anger falls to
// nothing at 2 a frame.
constexpr int RAGE_SPIT_EVERY = 8;
constexpr float RAGE_SPREAD = 180;
constexpr float RAGE_SPREAD_HALF = 90;
constexpr float RAGE_OUT = 20;
constexpr float RAGE_SPEED = 5;
constexpr float RAGE_SPEED_RANGE = 5;
constexpr float RAGE_HEALTH_SHARE = 0.5f;
constexpr int RAGE_ANGER_DRAIN = 2;
constexpr ColorMod RAGE_LOOSE_COLOR = {{1.5f, 0.6f, 0.6f, 1}, {0, 0, 0, 0}, {0.4f, 0.08f, 0.05f}};
constexpr ColorMod RAGE_LOOSE_FLASH = {{1, 1, 1, 1}, {0, 0, 0, 0}, {0.8f, 0.3f, 0.2f}};
constexpr int RAGE_LOOSE_FLASH_FRAMES = 15;
// Every 15 frames one time in two, leading none, she takes one of her Fistuloids to lead when at most one other
// door-shutting enemy is out (or one time in 100).
constexpr int LEAD_EVERY = 15;
constexpr uint32_t LEAD_CROWD_ODDS = 100;
// At a fifth of her health she bursts (a Fistula 40 out at 2 to 4, see below) and turns into a three-part Chub at a
// fifth of her health, her parts at her full health, in front of her.
constexpr float DEATH_HEALTH = 0.2f;
constexpr int DEATH_BURST_FISTULAS = 3;
constexpr int CHUB_SUBTYPE = 1000;
constexpr int CHUB_HEAD_DEPTH = 1500;
constexpr int CHUB_MIDDLE_DEPTH = 500;
constexpr int CHUB_TAIL_DEPTH = -500;
constexpr float CHUB_MIDDLE_SHADOW = 0.34f;
constexpr float CHUB_TAIL_SHADOW = 0.26f;
constexpr int MATRIARCH_CHUB_CHARGE = NPC_STATE_ATTACK;
// The chunk threshold she is at, none past her last.
static float matriarch_chunk_health(Entity_NPC& npc)
{
// The original reads past the table at her fifth chunk, a value so large no summon or cost fits under it.
return npc.i2 < (int)MATRIARCH_CHUNKS.size() ? MATRIARCH_CHUNKS[(size_t)npc.i2] * npc.maxHitPoints : INFINITY;
}
// A blood explosion raised to her mouth (FUN_004c5980).
static void matriarch_blood_spawn(int subType, const Vector& position, const Vector& velocity, float raise)
{
Entity* blood = g_game->Spawn({.position = position,
.velocity = velocity,
.subType = subType,
.type = ENTITY_EFFECT,
.variant = EFFECT_BLOOD_EXPLOSION,
.seed = Random()});
blood->posOffset = vector_make(0, raise);
}
// A Fistula thrown out of her along a direction, free of the boss bar.
static void matriarch_fistula_throw(Entity_NPC& npc, int type, Vector direction)
{
Vector position = vector_add(npc.pos, vector_scale(direction, CHUNK_OUT));
uint32_t seed = Random();
float speed = random_unit() * CHUNK_SPEED_RANGE + CHUNK_SPEED;
Entity* fistula = g_game->Spawn({.position = position,
.velocity = vector_scale(direction, speed),
.spawner = &npc,
.subType = CHUNK_FISTULA_SUBTYPE,
.type = type,
.seed = seed});
fistula->ClearEntityFlags(FLAG_APPEAR);
fistula->AddEntityFlags(FLAG_DONT_COUNT_BOSS_HP);
matriarch_blood_spawn(BLOOD_SUBTYPE_FISTULA, position, vector_scale(direction, CHUNK_BLOOD_SHARE), BLOOD_RAISE);
}
// The hits that would take her past her next chunks throw Fistulas off her and make her flinch.
static void matriarch_chunks_update(Entity_NPC& npc)
{
float health = npc.health - npc.pendingDamage;
while (npc.i2 < (int)MATRIARCH_CHUNKS.size() && health < matriarch_chunk_health(npc))
{
npc_sound_play(SOUND_DEATH_BURST_LARGE, CHUNK_VOLUME, 2, 1);
Vector away = vector_normalized(vector_sub(npc.pos, npc.GetPlayerTarget()->pos));
for (int i = 0; i < (npc.i2 > CHUNK_TWO_FROM) + 1; i++)
{
float angle = random_unit() * CHUNK_SPREAD - CHUNK_SPREAD_HALF;
matriarch_fistula_throw(npc, ENTITY_FISTULA_SMALL, vector_rotated(away, angle));
}
bool isAirborne = npc.state == MATRIARCH_HOP && npc.sprite.WasEventTriggered("Jump") &&
!npc.sprite.WasEventTriggered("Land");
if (isAirborne)
{
npc.sprite.Play("AirFlinch");
npc.state = MATRIARCH_AIR_FLINCH;
npc.velocity = vector_scale(away, CHUNK_AIR_FLINCH_SPEED);
}
else if (npc.state != MATRIARCH_FLINCH && npc.state != MATRIARCH_AIR_FLINCH)
{
npc.sprite.Play("Flinch");
npc.state = MATRIARCH_FLINCH;
npc.velocity = vector_scale(away, CHUNK_FLINCH_SPEED);
}
npc.i2++;
npc.i1 += CHUNK_ANGER;
}
}
// A Fistuloid's health, what spitting one costs her.
static float fistuloid_health_get()
{
// The original reads a missing config through a null pointer. Here it costs nothing.
EntityConfig_Entity* config = g_manager->entityConfig.GetEntity(ENTITY_FISTULOID, 0, 0);
return config ? config->baseHP : 0;
}
// Resting: her rage, an attack or a hop.
static void matriarch_idle_update(Entity_NPC& npc)
{
npc.sprite.Play("Idle");
npc.friction *= IDLE_FRICTION;
if (npc.i1 > RAGE_ANGER && npc.i2 >= RAGE_CHUNKS && Random() % MATRIARCH_RAGE_ODDS == 0)
{
npc.sprite.Play("RageBegin");
npc.state = MATRIARCH_RAGE;
npc.stateFrame = 0;
npc.i1 = RAGE_START_ANGER;
return;
}
if (Random() % MATRIARCH_ATTACK_ODDS != 0)
{
if (Random() % MATRIARCH_HOP_ODDS != 0) return;
npc.state = MATRIARCH_HOP;
npc.sprite.Play(Random() & 1 ? "Jump" : "Jump2");
return;
}
size_t led = 0;
for (Entity* fistuloid : Entity_NPC::QueryNPCsType(ENTITY_FISTULOID, -1))
if (fistuloid->parent.get() == &npc) led++;
uint32_t summonWeight = SUMMON_WEIGHT;
if (led > SUMMON_LIMIT || npc.health - fistuloid_health_get() < matriarch_chunk_health(npc)) summonWeight = 0;
else if (npc.i1 > SUMMON_ANGER || led == 0) summonWeight = SUMMON_ANGRY_WEIGHT;
uint32_t shotWeight = npc.projectileCooldown < 1 ? ATTACK_COOLED_WEIGHT : MATRIARCH_ATTACK_WEIGHT;
uint32_t roll = Random() % (shotWeight + summonWeight);
if (roll < summonWeight)
{
npc.PlaySound(SOUND_MONSTER_ROAR_1, 1, 2, false, 1);
npc.state = MATRIARCH_SUMMON;
}
else npc.state = roll < summonWeight + MATRIARCH_ATTACK_WEIGHT ? MATRIARCH_WORMS : MATRIARCH_SHOT;
}
// A hop at her target, or the Fistuloid she leads.
static void matriarch_hop_start(Entity_NPC& npc)
{
Vector direction{};
if (Entity* led = npc.child.get()) direction = vector_normalized(vector_sub(led->pos, npc.pos));
else
{
Vector gap = vector_sub(npc.CalcTargetPosition(0), npc.pos);
direction = vector_normalized(gap);
if (vector_length(gap) > HOP_SWERVE_REACH)
{
Vector swerve = vector_rotated(direction, Random() & 1 ? -HOP_SWERVE : HOP_SWERVE);
if (g_game->room->IsPositionInRoom(vector_add(npc.pos, vector_scale(swerve, HOP_SWERVE_OUT)), 0)) direction = swerve;
}
}
npc.targetPosition = vector_scale(direction, HOP_SPEED);
npc.velocity = npc.targetPosition;
}
// Where her shot aims: her target ahead by a tenth of its speed per unit of distance, kept in the room.
static Vector matriarch_shot_aim(Entity_NPC& npc)
{
Entity* target = npc.GetPlayerTarget();
float distance = vector_distance(npc.pos, target->pos);
Vector aim = vector_add(target->pos, vector_scale(target->velocity, MATRIARCH_SHOT_LEAD * distance));
return g_game->room->GetClampedPositionImpl(aim, SHOT_MARGIN, SHOT_MARGIN, SHOT_MARGIN, SHOT_MARGIN);
}
// Spits a Fistuloid ahead, costing her its health down to just above her next chunk.
static void matriarch_summon_spit(Entity_NPC& npc)
{
npc_sound_play(SOUND_SUMMONSOUND, 1, 2, 1);
float side = npc.sprite.isFlipX ? -1.0f : 1.0f;
Vector position = vector_make(npc.pos.x + side * SUMMON_OUT, npc.pos.y - SUMMON_RAISE);
Vector velocity = vector_make(-side * MATRIARCH_SUMMON_SPEED, -SUMMON_RAISE);
auto* fistuloid = static_cast<Entity_NPC*>(g_game->Spawn(
{.position = position, .velocity = velocity, .spawner = &npc, .type = ENTITY_FISTULOID, .seed = Random()}));
fistuloid->parent = &npc;
fistuloid->ClearEntityFlags(FLAG_APPEAR);
fistuloid_orbit_spread(*fistuloid);
g_game->Spawn({.position = position, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()});
matriarch_blood_spawn(BLOOD_SUBTYPE_SPLASH, position, vector_scale(fistuloid->velocity, SUMMON_BLOOD_SHARE), BLOOD_RAISE);
float left = std::max(npc.health - fistuloid_health_get(), matriarch_chunk_health(npc) + 1);
if (left < npc.health) npc.TakeDamage(npc.health - left, 0, EntityRef(), SUMMON_HIT_COUNTDOWN);
}
// Sprays a ring of eight Chubber worms, each in its blood.
static void matriarch_worms_spray(Entity_NPC& npc)
{
npc_sound_play(SOUND_HEARTOUT, WORM_SOUND_VOLUME, 2, 1);
for (int i = 0; i < WORMS; i++)
{
Vector unit = vector_from_angle((float)i * WORM_STEP);
Vector velocity = vector_make(unit.x * WORM_REACH * WORM_WIDTH, unit.y * WORM_REACH);
auto* worm = static_cast<Entity_NPC*>(g_game->Spawn({.position = vector_add(npc.pos, velocity),
.velocity = velocity,
.spawner = &npc,
.subType = WORM_SUBTYPE,
.type = ENTITY_VIS,
.variant = CHUBBER_WORM,
.seed = Random()}));
worm->state = NPC_STATE_INIT;
worm->parent = &npc;
worm->Update();
matriarch_blood_spawn(BLOOD_SUBTYPE_SPLASH, worm->pos, vector_scale(worm->velocity, WORM_BLOOD_SPLASH), BLOOD_RAISE);
matriarch_blood_spawn(BLOOD_SUBTYPE_MEDIUM, worm->pos, vector_scale(worm->velocity, WORM_BLOOD_MEDIUM), BLOOD_RAISE);
matriarch_blood_spawn(BLOOD_SUBTYPE_SMALL, worm->pos, vector_scale(worm->velocity, WORM_BLOOD_SMALL), BLOOD_RAISE);
}
}
// Spits her big shot ahead, turned 45 degrees at most toward where her target will be.
static void matriarch_shot_fire(Entity_NPC& npc)
{
npc_sound_play(SOUND_WORM_SPIT, 1, 2, SHOT_SPIT_PITCH);
npc_sound_play(SOUND_HEARTIN, SHOT_HEART_VOLUME, 2, 1);
Vector mouth = vector_make(npc.pos.x + (npc.sprite.isFlipX ? SHOT_OUT : -SHOT_OUT), npc.pos.y + SHOT_DROP);
Vector aim = matriarch_shot_aim(npc);
float ahead = npc.sprite.isFlipX ? 0 : HALF_TURN_DEGREES;
float turn = normalize_angle_degrees(vector_angle(vector_sub(aim, mouth)) - ahead);
Vector velocity = vector_scale(vector_from_angle(ahead + std::clamp(turn, -SHOT_TURN_MAX, SHOT_TURN_MAX)), MATRIARCH_SHOT_SPEED);
ProjectileParams params;
params.bulletFlags |= PROJECTILE_ACID_RED | PROJECTILE_RED_CREEP;
params.scale = MATRIARCH_SHOT_SCALE;
npc.FireProjectiles(mouth, velocity, PROJECTILES_SINGLE, params);
matriarch_blood_spawn(BLOOD_SUBTYPE_MEDIUM, mouth, velocity, SHOT_BLOOD_RAISE);
npc.projectileCooldown = (int)(Random() % SHOT_COOLDOWN_RANGE) + SHOT_COOLDOWN;
}
// A Fistuloid gone wild in her rage: reddened, flashing, deadly on touch and beyond a player's control.
static void matriarch_fistuloid_loose(Entity& fistuloid)
{
fistuloid.AddEntityFlags(FLAG_NO_PLAYER_CONTROL);
fistuloid.sprite.GetLayer(0)->color = RAGE_LOOSE_COLOR;
fistuloid.SetColor(RAGE_LOOSE_FLASH, RAGE_LOOSE_FLASH_FRAMES, COLOR_PRIORITY_DEFAULT, true, true);
}
// Her rage: she lets her Fistuloid loose on the roar, then spits wild ones until her anger is spent.
static void matriarch_rage_update(Entity_NPC& npc)
{
npc.friction *= IDLE_FRICTION;
if (npc.stateFrame == 0)
{
if (!npc.sprite.IsEventTriggered("Shoot")) return;
npc.PlaySound(SOUND_MONSTER_ROAR_1, 1, 2, false, 1);
npc.stateFrame = 1;
npc.sprite.isFlipX = npc.pos.x < npc.CalcTargetPosition(0).x;
if (Entity* led = npc.child.get())
{
led->parent = nullptr;
led->isKillOnTouch = true;
matriarch_fistuloid_loose(*led);
npc.child = nullptr;
}
return;
}
if (npc.stateFrame < 0)
{
if (!npc.sprite.IsPlaying()) npc.state = MATRIARCH_IDLE;
return;
}
if (!npc.sprite.IsPlaying()) npc.sprite.Play("RageLoop");
if (npc.stateFrame % RAGE_SPIT_EVERY == 0 && (Random() & 1) == 0)
{
npc_sound_play(SOUND_SUMMONSOUND, 1, 2, 1);
Vector toward = vector_normalized(vector_sub(npc.CalcTargetPosition(0), npc.pos));
Vector direction = vector_rotated(toward, random_unit() * RAGE_SPREAD - RAGE_SPREAD_HALF);
Vector position = vector_add(npc.pos, vector_scale(direction, RAGE_OUT));
uint32_t seed = Random();
float speed = random_unit() * RAGE_SPEED_RANGE + RAGE_SPEED;
Entity* fistuloid = g_game->Spawn({.position = position,
.velocity = vector_scale(direction, speed),
.spawner = &npc,
.type = ENTITY_FISTULOID,
.seed = seed});
float health = fistuloid->maxHitPoints * RAGE_HEALTH_SHARE;
fistuloid->ClearEntityFlags(FLAG_APPEAR);
fistuloid->isKillOnTouch = true;
fistuloid->maxHitPoints = health;
fistuloid->health = health;
matriarch_fistuloid_loose(*fistuloid);
g_game->Spawn({.position = position, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()});
matriarch_blood_spawn(BLOOD_SUBTYPE_SPLASH, position, vector_scale(fistuloid->velocity, SUMMON_BLOOD_SHARE), BLOOD_RAISE);
}
npc.stateFrame++;
npc.i1 -= RAGE_ANGER_DRAIN;
if (npc.i1 >= 1) return;
npc.i1 = 0;
npc.stateFrame = -1;
npc.sprite.Play("RageEnd");
}
// Her death: she bursts and turns into Chub, two more parts trailing her, charging at her target.
static void matriarch_burst(Entity_NPC& npc)
{
npc_sound_play(SOUND_ROCKET_BLAST_DEATH, 1, 2, 1);
uint32_t burst = Random();
g_game->Spawn({.position = npc.pos, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_LARGE_BLOOD_EXPLOSION, .seed = burst});
// The original counts its Fistulas on from the burst's seed, so all but one seed in a billion throw one small Fistula.
uint32_t thrown = burst;
do matriarch_fistula_throw(npc, thrown != 0 ? ENTITY_FISTULA_SMALL : ENTITY_FISTULA_MEDIUM, random_direction());
while (++thrown < DEATH_BURST_FISTULAS);
if (Entity* led = npc.child.get())
{
led->parent = nullptr;
npc.child = nullptr;
}
auto* fistuloid = static_cast<Entity_NPC*>(
g_game->Spawn({.position = npc.pos, .spawner = &npc, .type = ENTITY_FISTULOID, .seed = Random()}));
fistuloid->parent = &npc;
fistuloid->ClearEntityFlags(FLAG_APPEAR);
fistuloid_orbit_spread(*fistuloid);
float maxHealth = npc.maxHitPoints;
npc.RemoveStatusEffects();
npc.Morph(ENTITY_CHUB, 0, CHUB_SUBTYPE, -1);
npc.maxHitPoints = maxHealth;
npc.spawnerType = ENTITY_MATRIARCH;
npc.entityCollisionClass = ENTCOLL_ALL;
npc.health = maxHealth * DEATH_HEALTH;
auto* middle = static_cast<Entity_NPC*>(g_game->Spawn(
{.position = npc.pos, .spawner = &npc, .subType = npc.subtype, .type = npc.type, .variant = npc.variant, .seed = Random()}));
auto* tail = static_cast<Entity_NPC*>(g_game->Spawn(
{.position = npc.pos, .spawner = &npc, .subType = npc.subtype, .type = npc.type, .variant = npc.variant, .seed = Random()}));
middle->ClearEntityFlags(FLAG_APPEAR);
tail->ClearEntityFlags(FLAG_APPEAR);
npc.child = middle;
middle->parent = &npc;
middle->child = tail;
tail->parent = middle;
npc.ClearEntityFlags(FLAG_NO_DEATH_TRIGGER);
npc.i1 = 0;
npc.renderZOffset = CHUB_HEAD_DEPTH;
// Chub's parts carry their place along it in i1.
for (auto [part, depth, shadow, place] : {std::tuple{middle, CHUB_MIDDLE_DEPTH, CHUB_MIDDLE_SHADOW, 1},
std::tuple{tail, CHUB_TAIL_DEPTH, CHUB_TAIL_SHADOW, 2}})
{
part->renderZOffset = depth;
part->shadowSize = shadow;
part->i1 = place;
part->AddEntityFlags(FLAG_DONT_COUNT_BOSS_HP);
part->maxHitPoints = npc.maxHitPoints;
part->health = npc.maxHitPoints;
}
Vector toward = vector_sub(npc.GetPlayerTarget()->pos, npc.pos);
npc.PlaySound(SOUND_MONSTER_ROAR_0, 1, 2, false, 1);
npc.v1 = vector_cardinal(toward);
npc.state = MATRIARCH_CHUB_CHARGE;
npc.stateFrame = 0;
npc.pathfinder.movementTarget = {};
npc.pathfinder.moveDirection = {};
}
// Every 15 frames one time in two she takes a Fistuloid to lead, unless the room is crowded.
static void matriarch_lead_update(Entity_NPC& npc)
{
if (!npc.IsFrame(LEAD_EVERY, 0) || npc.child || (Random() & 1) != 0) return;
int crowd = 0;
for (Entity* entity : g_game->room->entityList.updateEL)
if (Entity::is_enemy_type(entity->type) && entity->CanShutDoors() && entity->type != ENTITY_MATRIARCH &&
entity->type != ENTITY_FISTULOID)
crowd++;
if (crowd > 1 && Random() % LEAD_CROWD_ODDS != 0) return;
std::vector<Entity*> led;
for (Entity* fistuloid : entity_query(ENTITY_FISTULOID, -1))
if (fistuloid->parent.get() == &npc) led.push_back(fistuloid);
if (led.empty()) return;
Entity* picked = led[random_below((int)led.size())];
npc.child = picked;
fistuloid_orbit_spread(static_cast<Entity_NPC&>(*picked));
}
// 004c59d0 The Matriarch hops about trailed by her Fistuloids, spitting them, worms and big shots. Losing chunks of
// her health throws Fistulas off her and angers her into a rage of wild Fistuloids. At a fifth of her health she
// bursts into Chub.
void boss_matriarch_update(Entity_NPC& npc)
{
bool isDeliriumForm = npc.deliriumBossType != 0;
if (!isDeliriumForm && npc.pendingDamage > 0 && npc.state != MATRIARCH_RAGE) matriarch_chunks_update(npc);
bool isEnded = true;
switch (npc.state)
{
case NPC_STATE_INIT:
npc.state = MATRIARCH_IDLE;
npc.i1 = 0;
npc.i2 = 0;
isEnded = false;
break;
case MATRIARCH_IDLE:
matriarch_idle_update(npc);
isEnded = false;
break;
case MATRIARCH_FLINCH:
npc.friction *= FLINCH_FRICTION;
break;
case MATRIARCH_HOP:
case MATRIARCH_AIR_FLINCH:
{
if (npc.state == MATRIARCH_HOP && npc.sprite.IsEventTriggered("Jump")) matriarch_hop_start(npc);
if (npc.sprite.IsEventTriggered("Land")) npc_sound_play(SOUND_FORESTBOSS_STOMPS, MATRIARCH_LAND_VOLUME, 2, 1);
bool isAirborne = npc.sprite.WasEventTriggered("Jump") && !npc.sprite.WasEventTriggered("Land");
if (isAirborne && npc.state == MATRIARCH_HOP) npc.sprite.isFlipX = npc.targetPosition.x > 0;
if (!isAirborne) npc.friction *= IDLE_FRICTION;
break;
}
case MATRIARCH_SUMMON:
npc.friction *= IDLE_FRICTION;
npc.sprite.Play("Attack1");
if (npc.sprite.IsEventTriggered("Shoot")) matriarch_summon_spit(npc);
break;
case MATRIARCH_WORMS:
npc.friction *= IDLE_FRICTION;
npc.sprite.Play("Attack2");
if (npc.sprite.IsEventTriggered("Shoot")) matriarch_worms_spray(npc);
break;
case MATRIARCH_SHOT:
npc.friction *= IDLE_FRICTION;
npc.sprite.Play("Attack3");
if (npc.sprite.GetFrame() == 0) npc.sprite.isFlipX = npc.pos.x < matriarch_shot_aim(npc).x;
if (npc.sprite.IsEventTriggered("Shoot")) matriarch_shot_fire(npc);
break;
case MATRIARCH_RAGE:
matriarch_rage_update(npc);
npc.friction *= FLINCH_FRICTION;
break;
case MATRIARCH_DEATH:
npc.friction *= IDLE_FRICTION;
npc.sprite.Play("Death");
if (!npc.sprite.IsPlaying()) return matriarch_burst(npc);
isEnded = false;
break;
default:
isEnded = false;
break;
}
if (isEnded && !npc.sprite.IsPlaying()) npc.state = MATRIARCH_IDLE;
if (npc.projectileCooldown > 0) npc.projectileCooldown--;
if (npc.state != MATRIARCH_RAGE)
{
if (npc.pendingDamage > 0) npc.i1 += (int)(((float)npc.i2 * ANGER_PER_CHUNK + 1) * npc.pendingDamage);
if (npc.i1 > 0) npc.i1--;
matriarch_lead_update(npc);
}
if (!isDeliriumForm && (npc.isDead || npc.health <= npc.maxHitPoints * DEATH_HEALTH))
{
npc.isDead = false;
npc.entityCollisionClass = ENTCOLL_NONE;
npc.state = MATRIARCH_DEATH;
npc.health = npc.maxHitPoints * DEATH_HEALTH;
}
}