1167 lines
48 KiB
C++
1167 lines
48 KiB
C++
#include "boss_ai.h"
|
|
#include "camera.h"
|
|
#include "entity_config.h"
|
|
#include "entity_player.h"
|
|
#include "entity_projectile.h"
|
|
#include "manager.h"
|
|
#include "platform.h"
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <cmath>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
// Delirium's own phases (deliriumState): starting, in a form, about to change form, the hallucinations of his death and
|
|
// his last scream.
|
|
enum DeliriumState : uint8_t
|
|
{
|
|
DELIRIUM_START = 0,
|
|
DELIRIUM_FORM = 8,
|
|
DELIRIUM_MORPH = 16,
|
|
DELIRIUM_DYING = 17,
|
|
DELIRIUM_SCREAM = 18
|
|
};
|
|
|
|
// A form lasts a random whole number of seconds between a least and a most, by the fifth of his health he has left.
|
|
struct FormSeconds
|
|
{
|
|
float least;
|
|
float most;
|
|
};
|
|
constexpr std::array<FormSeconds, 6> FORM_SECONDS = {{{1, 3}, {2, 5}, {3, 6}, {4, 7}, {5, 8}, {6, 10}}};
|
|
constexpr float HEALTH_FIFTHS = 5;
|
|
constexpr float RANDOM_RANGE = 4294967295.0f;
|
|
constexpr int SECOND_FRAMES = 30;
|
|
|
|
// Each form makes 2 to 4 attacks. He starts behind a 120 frame shield, and his shield grows to 80 as he weakens.
|
|
constexpr uint32_t NPC_STATE_ATTACKS_MIN = 2;
|
|
constexpr uint32_t NPC_STATE_ATTACKS_ROLL = 3;
|
|
constexpr int START_SHIELD_FRAMES = 120;
|
|
constexpr float SHIELD_STRENGTH = 80;
|
|
|
|
// He changes into his own form 10 rolls in 100, else into a boss met this run, drawing up to 100 times for one that is
|
|
// not himself, Hornfel or Gideon, not tagged nodelirium and not the form he leaves. Mom takes her variant 10, Satan
|
|
// his variant 10 one roll in 2, and Mama Gurdy her variant 0.
|
|
constexpr uint32_t FORM_ROLL = 100;
|
|
constexpr uint32_t OWN_FORM_ODDS = 10;
|
|
constexpr int FORM_DRAWS = 100;
|
|
constexpr uint32_t ALTERNATE_FORM_VARIANT = 10;
|
|
|
|
// Each change adds 10 to the odds of a rage, which lasts 120 frames, tints him and runs his form at full speed.
|
|
constexpr uint32_t RAGE_ODDS_STEP = 10;
|
|
constexpr uint32_t DELIRIUM_RAGE_FRAMES = 120;
|
|
constexpr float RAGE_TINT = 0.7f;
|
|
constexpr uint32_t RAGE_STEPS = 3;
|
|
|
|
// He teleports every 300 to 899 frames, at most 30 frames after he leaves the camera's sight (checked 100 out from him
|
|
// at each corner), the damage he takes cutting it by half. He lands 160 to 320 out from his target along its way (any
|
|
// way while it stands still), at least 160 from every player: 20 more spots go round his target 90 degrees at a time,
|
|
// 40 further out each, from 320, the last one never checked. Bosses that stay in place never teleport.
|
|
constexpr uint32_t TELEPORT_FRAMES_MIN = 300;
|
|
constexpr uint32_t TELEPORT_FRAMES_ROLL = 600;
|
|
constexpr uint32_t TELEPORT_HIDDEN_FRAMES = 30;
|
|
constexpr float CAMERA_CORNER = 100;
|
|
constexpr float TELEPORT_DAMAGE_SHARE = 0.5f;
|
|
constexpr float DELIRIUM_TELEPORT_REACH = 160;
|
|
constexpr float TELEPORT_RING = 320;
|
|
constexpr float DELIRIUM_RING_STEP = DELIRIUM_TELEPORT_REACH * 0.25f;
|
|
constexpr int DELIRIUM_TELEPORT_TRIES = 20;
|
|
constexpr int TELEPORT_QUARTERS = 4;
|
|
constexpr float TELEPORT_QUARTER_DEGREES = 90;
|
|
constexpr std::array<int, 10> STILL_BOSSES = {ENTITY_GURDY, ENTITY_MOM, ENTITY_MOMS_HEART, ENTITY_ISAAC,
|
|
ENTITY_MEGA_MAW, ENTITY_GATE, ENTITY_MAMA_GURDY, ENTITY_MR_FRED,
|
|
ENTITY_THE_LAMB, ENTITY_MATRIARCH};
|
|
|
|
// A form's attacks count down on the frame after it starts one of these states.
|
|
constexpr std::array<int, 10> ATTACK_STATES = {NPC_STATE_JUMP, NPC_STATE_STOMP, NPC_STATE_SPECIAL, NPC_STATE_ATTACK,
|
|
NPC_STATE_ATTACK2, NPC_STATE_ATTACK3, NPC_STATE_ATTACK4, NPC_STATE_SUMMON,
|
|
NPC_STATE_SUMMON2, NPC_STATE_SUMMON3};
|
|
|
|
// His death: five hallucinations, 0.4 seconds per one left (the last one of backdrop 17, the others random), then ten
|
|
// double speed loops of "IdleNoLoop" over a deep gurgle and his scream.
|
|
constexpr int DEATH_HALLUCINATIONS = 5;
|
|
constexpr float HALLUCINATION_SECONDS = 0.4f;
|
|
constexpr int HALLUCINATION_RANDOM = 63;
|
|
constexpr int HALLUCINATION_LAST = 17;
|
|
constexpr int SCREAM_LOOPS = 10;
|
|
constexpr float GURGLE_VOLUME = 5;
|
|
constexpr float GURGLE_PITCH = 0.1f;
|
|
constexpr int DELIRIUM_SOUND_DELAY = 2;
|
|
constexpr int MOM_VOICE_DELAY = 45;
|
|
|
|
// The speed a form runs at: its extra steps (3 less 3 per health share, all 3 while raging), each moving it on by a
|
|
// share of its velocity and calling its AI again while the steps allow. A form calls nothing for its first 4 frames a
|
|
// step, and the attacks it may start are forced one roll in (3 less its extra steps), or 10 to that power for the
|
|
// horsemen (a quarter more for Death, five times for his variant 30).
|
|
constexpr float FULL_STEPS = 3;
|
|
constexpr uint32_t STEP_FRAMES = 4;
|
|
constexpr int YOUNG_FORM_FRAMES = 30;
|
|
constexpr int MOM_FORM_FRAMES = 60;
|
|
constexpr double FORCED_ODDS_BASE = 10;
|
|
constexpr double DEATH_ODDS_POWER = 0.5;
|
|
constexpr double DEATH_30_ODDS_POWER = 2.5;
|
|
constexpr int DEATH_RUSH_VARIANT = 30;
|
|
|
|
// Larry Jr.'s body: 4 to 9 segments, 20 apart (with up to 5 jitter) back from his target, turned up to 45 degrees.
|
|
constexpr uint32_t LARRY_SEGMENTS_MIN = 4;
|
|
constexpr uint32_t LARRY_SEGMENTS_ROLL = 6;
|
|
constexpr float LARRY_SEGMENT_GAP = 20;
|
|
constexpr uint32_t LARRY_TURN_ROLL = 90;
|
|
constexpr int LARRY_TURN_MAX = 45;
|
|
constexpr uint32_t LARRY_JITTER_ROLL = 5000;
|
|
constexpr float LARRY_JITTER_SCALE = 1000;
|
|
constexpr int GEMINI_UMBILICAL = 20;
|
|
constexpr int PLAYER_SPAWNER = 1;
|
|
|
|
// The bosses a form may bring a companion of the other, as pairs with the odds in 100 of either bringing the other.
|
|
struct FormPair
|
|
{
|
|
int type;
|
|
int variant;
|
|
int otherType;
|
|
int otherVariant;
|
|
uint32_t odds;
|
|
};
|
|
constexpr std::array<FormPair, 32> FORM_PAIRS = {{
|
|
{19, 0, 19, 1, 20}, {267, 0, 268, 0, 8}, {20, 0, 43, 0, 5}, {43, 0, 43, 1, 8}, {28, 0, 28, 1, 10},
|
|
{36, 0, 237, 1, 8}, {36, 0, 237, 2, 8}, {99, 0, 237, 1, 5}, {99, 0, 237, 2, 5}, {402, 0, 237, 2, 8},
|
|
{402, 0, 261, 1, 15}, {62, 0, 62, 1, 3}, {62, 0, 62, 2, 3}, {67, 0, 67, 1, 15}, {79, 0, 79, 1, 18},
|
|
{79, 0, 79, 2, 10}, {71, 0, 71, 1, 10}, {68, 0, 68, 1, 4}, {263, 0, 265, 0, 8}, {69, 0, 69, 1, 5},
|
|
{100, 0, 100, 1, 12}, {271, 0, 272, 0, 6}, {261, 0, 261, 1, 12}, {404, 0, 411, 0, 4}, {405, 0, 409, 0, 4},
|
|
{74, 0, 74, 0, 18}, {63, 0, 64, 0, 10}, {65, 0, 65, 1, 6}, {63, 0, 82, 0, 10}, {65, 0, 66, 0, 8},
|
|
{64, 0, 66, 0, 6}, {65, 1, 82, 0, 10},
|
|
}};
|
|
|
|
// His shots: 11 patterns, each a burst of shots every interval (a quarter as often in a boss form) for some volleys,
|
|
// then he keeps it at the keep odds (10 less each time) or draws another with odds 30 and a new turn.
|
|
constexpr int SHOT_PATTERNS = 11;
|
|
constexpr uint8_t RANDOM_PATTERN = 0xff;
|
|
constexpr uint32_t KEEP_ROLL = 100;
|
|
constexpr uint8_t KEEP_ODDS_STEP = 10;
|
|
constexpr uint8_t KEEP_ODDS_FRESH = 30;
|
|
constexpr uint32_t TURN_STEPS = 255;
|
|
constexpr int FORM_SHOT_SLOWDOWN = 4;
|
|
constexpr int BURST_DELAY = 5;
|
|
constexpr int BURST_SLOTS = 16;
|
|
constexpr float SHOT_HEIGHT = 5;
|
|
constexpr float DELIRIUM_SHOT_FALL_SPEED = -3.2f;
|
|
constexpr float DELIRIUM_SHOT_FALL_ACCEL = -0.06f;
|
|
constexpr float DELIRIUM_SHOT_SCALE = 1.5f;
|
|
constexpr float AIMED_SHOT_SPEED = 4;
|
|
|
|
// A shot pattern: its interval, ring size, burst, volleys, speed, colorize and flags, whether alternate volleys curve
|
|
// the other way in another color, how far each volley turns him, and whether it is an aimed fan instead of a ring.
|
|
struct ShotPattern
|
|
{
|
|
std::array<float, 3> colorize;
|
|
std::array<float, 3> alternateColorize;
|
|
uint64_t flags;
|
|
float speed;
|
|
int interval;
|
|
int ringSize;
|
|
int burst;
|
|
uint8_t volleys;
|
|
uint8_t turn;
|
|
bool isAlternating;
|
|
bool isAimed;
|
|
};
|
|
|
|
// The health share a form's speed reads, from 0 dead to 1 full.
|
|
static float health_share_get(Entity_NPC& npc)
|
|
{
|
|
return std::clamp(npc.health / npc.maxHitPoints, 0.0f, 1.0f);
|
|
}
|
|
|
|
// A whole random number of seconds between a range's ends, in frames.
|
|
static uint16_t form_frames_roll(FormSeconds seconds)
|
|
{
|
|
float roll = (float)(Random() % UINT32_MAX);
|
|
return (uint16_t)((int)(roll / (RANDOM_RANGE / (seconds.most - seconds.least)) + seconds.least) * SECOND_FRAMES);
|
|
}
|
|
|
|
// Whether an entity is a boss form's: the same type and variant.
|
|
static bool is_form(Entity& entity, int type, int variant)
|
|
{
|
|
return entity.type == type && entity.variant == variant;
|
|
}
|
|
|
|
// 004a6240 Removes what a form left behind: other bosses of its kind, its companion's kind, Gemini's cord, Hush's
|
|
// rising lasers, every laser not a player's and the Eternal Flies.
|
|
static void delirium_minions_remove(int type, int variant, Entity& self, Entity* companion)
|
|
{
|
|
std::vector<Entity*>& updated = g_game->room->entityList.updateEL;
|
|
|
|
for (size_t i = 0; i < updated.size(); i++)
|
|
{
|
|
Entity& entity = *updated[i];
|
|
bool isFormBoss = &entity != &self && entity.IsBoss() && is_form(entity, type, variant);
|
|
bool isCompanionKind = companion && is_form(entity, companion->type, companion->variant);
|
|
if (isFormBoss || isCompanionKind) entity.Remove();
|
|
}
|
|
|
|
if (type == ENTITY_GEMINI)
|
|
for (Entity* cord : entity_query(ENTITY_GEMINI, GEMINI_UMBILICAL)) cord->Remove();
|
|
else if (type == ENTITY_HUSH)
|
|
for (Entity* laser : entity_query(ENTITY_EFFECT, EFFECT_HUSH_LASER_UP)) laser->Remove();
|
|
for (Entity* laser : entity_query(ENTITY_LASER, -1))
|
|
if (laser->spawnerType != PLAYER_SPAWNER) laser->Remove();
|
|
for (Entity* fly : entity_query(ENTITY_ETERNALFLY, 0)) fly->Remove();
|
|
}
|
|
|
|
// 004a8680 Grows a form's body: Larry Jr.'s segments trailing back from his target (the first one with the form's
|
|
// health) or Mama Gurdy's two hands.
|
|
static void delirium_segments_spawn(Entity_NPC& head, float maxHealth)
|
|
{
|
|
if (head.type == ENTITY_MAMA_GURDY)
|
|
{
|
|
spawn_at(head.type, 1, 0, head.pos, &head);
|
|
spawn_at(head.type, 2, 0, head.pos, &head);
|
|
return;
|
|
}
|
|
if (head.type != ENTITY_LARRYJR) return;
|
|
|
|
int count = (int)(Random() % LARRY_SEGMENTS_ROLL + LARRY_SEGMENTS_MIN);
|
|
Vector away = vector_sub(head.pos, head.GetPlayerTarget()->pos);
|
|
float length = std::sqrt(away.x * away.x + away.y * away.y);
|
|
if (length > 0) away = vector_scale(away, 1 / length);
|
|
float turn = (float)((int)(Random() % LARRY_TURN_ROLL) - LARRY_TURN_MAX) * DEGREES_TO_RADIANS;
|
|
Vector direction = vector_make(away.x * std::cos(turn) - away.y * std::sin(turn),
|
|
away.x * std::sin(turn) + away.y * std::cos(turn));
|
|
Entity_NPC* previous = &head;
|
|
|
|
for (int i = 1; i <= count; i++)
|
|
{
|
|
Vector position = vector_add(head.pos, vector_scale(direction, (float)i * LARRY_SEGMENT_GAP));
|
|
position.y += (float)(Random() % LARRY_JITTER_ROLL) / LARRY_JITTER_SCALE;
|
|
position.x += (float)(Random() % LARRY_JITTER_ROLL) / LARRY_JITTER_SCALE;
|
|
auto* segment = static_cast<Entity_NPC*>(spawn_at(head.type, head.variant, 0, position, &head));
|
|
|
|
if (i == 1)
|
|
{
|
|
segment->health = maxHealth;
|
|
segment->maxHitPoints = maxHealth;
|
|
segment->isInvincible = true;
|
|
}
|
|
segment->parent = previous;
|
|
previous->child = segment;
|
|
segment->ClearEntityFlags(FLAG_APPEAR);
|
|
segment->AddEntityFlags(FLAG_NO_DEATH_TRIGGER | FLAG_DONT_COUNT_BOSS_HP);
|
|
segment->state = NPC_STATE_MOVE;
|
|
segment->vectorDeque1.push_front(segment->pos);
|
|
segment->vectorDeque2.push_front(segment->velocity);
|
|
segment->groupIdx = head.groupIdx;
|
|
ANM2::LoadDeliriumForm(segment->sprite, head.type, head.variant, true);
|
|
segment->sprite.Play("WalkBodyHori");
|
|
segment->Update();
|
|
previous = segment;
|
|
}
|
|
}
|
|
|
|
// 004a84f0 Brings a companion for a form one roll in its pair's odds, somewhere in the room with the form's health:
|
|
// the other boss of a pair it belongs to (looked up from either end of the list), taking the form's variant.
|
|
static void delirium_companion_spawn(Entity_NPC& npc)
|
|
{
|
|
bool isFromEnd = Random() & 1;
|
|
const FormPair* found = nullptr;
|
|
int otherType = 0;
|
|
|
|
for (int i = 0; i < (int)FORM_PAIRS.size() && !found; i++)
|
|
{
|
|
const FormPair& pair = FORM_PAIRS[isFromEnd ? FORM_PAIRS.size() - 1 - i : i];
|
|
if (is_form(npc, pair.type, pair.variant)) otherType = pair.otherType;
|
|
else if (is_form(npc, pair.otherType, pair.otherVariant)) otherType = pair.type;
|
|
else continue;
|
|
found = &pair;
|
|
}
|
|
if (!found || Random() % FORM_ROLL >= found->odds) return;
|
|
|
|
uint32_t seed = Random();
|
|
auto* companion = static_cast<Entity_NPC*>(g_game->Spawn({.position = g_game->room->GetRandomPosition(0),
|
|
.spawner = &npc,
|
|
.type = otherType,
|
|
.variant = npc.variant,
|
|
.seed = seed}));
|
|
companion->health = npc.maxHitPoints;
|
|
companion->AddEntityFlags(FLAG_NO_DEATH_TRIGGER | FLAG_DONT_COUNT_BOSS_HP);
|
|
companion->maxHitPoints = npc.maxHitPoints;
|
|
ANM2::LoadDeliriumForm(companion->sprite, otherType, npc.variant, true);
|
|
delirium_segments_spawn(*companion, npc.maxHitPoints);
|
|
npc.deliriumEntity = companion;
|
|
companion->Update();
|
|
log_printf(LOG_INFO, "Spawned Delirium companion %d:%u\n", otherType, (uint32_t)npc.variant);
|
|
}
|
|
|
|
// A shot pattern's settings, by its number.
|
|
static ShotPattern shot_pattern_get(int pattern)
|
|
{
|
|
switch (pattern)
|
|
{
|
|
case 0:
|
|
return {{2, 2, 2}, {3, 3, 3}, PROJECTILE_ACCELERATE, 2.5f, 18, 20, 1, 2, 0, true, false};
|
|
case 1:
|
|
return {{2, 2.8f, 2}, {1, 1, 1}, PROJECTILE_EXPLODE, 4, 25, 8, 1, 1, 0, false, false};
|
|
case 2:
|
|
return {{2.6f, 2.6f, 2.6f}, {1, 1, 1}, PROJECTILE_SAWTOOTH_WIGGLE, 4.5f, 5, 6, 1, 1, 0, false, false};
|
|
case 3:
|
|
return {{3.4f, 3.4f, 3.4f}, {1, 1, 1}, 0, 4, 25, 1, 12, 3, 0, false, false};
|
|
case 4:
|
|
return {{2.4f, 2.4f, 2.4f}, {1, 1, 1}, PROJECTILE_WIGGLE, 5, 20, 20, 1, 4, 3, false, false};
|
|
case 5:
|
|
return {{3.6f, 3.6f, 3.6f}, {2.2f, 2.2f, 2.2f}, PROJECTILE_MEGA_WIGGLE, 3, 20, 10, 1, 2, 2, true, false};
|
|
case 6:
|
|
return {{3.8f, 3.8f, 3.8f}, {1, 1, 1}, PROJECTILE_ORBIT_CW, 5, 25, 14, 1, 2, 0, false, false};
|
|
case 7:
|
|
return {{4, 4, 4}, {1, 1, 1}, PROJECTILE_ORBIT_CCW, 5, 25, 14, 1, 2, 0, false, false};
|
|
case 8:
|
|
return {{2.6f, 2.6f, 2.6f}, {1, 1, 1}, PROJECTILE_SINE_VELOCITY, 4, 10, 10, 1, 3, 4, false, false};
|
|
case 9:
|
|
return {{2.6f, 2.6f, 2.6f}, {1, 1, 1}, 0, 4, 30, 14, 4, 1, 2, false, false};
|
|
case 10:
|
|
return {{3.6f, 3.6f, 3.6f}, {1, 1, 1}, 0, AIMED_SHOT_SPEED, 18, 6, 1, 4, 0, false, true};
|
|
default:
|
|
return {{1, 0.4f, 0}, {1, 1, 1}, 0, 3, 10, 6, 4, 1, 0, false, false};
|
|
}
|
|
}
|
|
|
|
// The burst a pattern fires in, each shot with its frame delay and angle: half turns 5 frames apart, a single shot at
|
|
// an eighth of a half turn for pattern 2, or pattern 3's four triple bursts, a third of a half turn apart.
|
|
static void burst_fill(int pattern, std::array<int, BURST_SLOTS>& delays, std::array<float, BURST_SLOTS>& angles)
|
|
{
|
|
for (int i = 0; i < BURST_SLOTS; i++)
|
|
{
|
|
delays[i] = i * BURST_DELAY;
|
|
angles[i] = (float)i * PI_F;
|
|
}
|
|
if (pattern == 2)
|
|
{
|
|
delays[0] = 0;
|
|
angles[0] = PI_F / 8;
|
|
}
|
|
if (pattern != 3) return;
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
float angle = (float)i * (PI_F / 3);
|
|
for (int quarter = 0; quarter < 4; quarter++) delays[i + quarter * 3] = i * 10;
|
|
angles[i] = angle;
|
|
angles[i + 3] = angle + PI_F;
|
|
angles[i + 6] = angle + PI_F / 2;
|
|
angles[i + 9] = angle + PI_F + PI_F / 2;
|
|
}
|
|
}
|
|
|
|
// 004a8b70 Fires Delirium's shots (not Mom's or Satan's variant 10 forms): the burst of the pattern on the frames it
|
|
// fires, blinking in his own form. A pattern's volleys spent, he keeps it or draws a new one and a new turn.
|
|
static void delirium_shots_fire(Entity_NPC& npc)
|
|
{
|
|
if (npc.type == ENTITY_MOM) return;
|
|
if (npc.deliriumBossType == ENTITY_SATAN && npc.deliriumBossVariant == ALTERNATE_FORM_VARIANT) return;
|
|
|
|
int pattern = npc.deliriumAttackPattern;
|
|
uint8_t keepOdds = npc.deliriumAttackKeepChance;
|
|
uint32_t turn = npc.deliriumAttackAngle;
|
|
if (pattern == RANDOM_PATTERN) pattern = (int)(Random() % SHOT_PATTERNS);
|
|
|
|
ShotPattern shots = shot_pattern_get(pattern);
|
|
Vector velocity = vector_make(shots.speed, 0);
|
|
ProjectilesMode mode = PROJECTILES_RING;
|
|
int volleys = npc.deliriumAttackRepeats == RANDOM_PATTERN ? shots.volleys : npc.deliriumAttackRepeats;
|
|
std::array<int, BURST_SLOTS> delays;
|
|
std::array<float, BURST_SLOTS> angles;
|
|
|
|
burst_fill(pattern, delays, angles);
|
|
turn += shots.turn;
|
|
if (shots.isAimed)
|
|
{
|
|
velocity = vector_scale(vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos)), shots.speed);
|
|
mode = PROJECTILES_FIVE;
|
|
}
|
|
|
|
int period = (npc.type == ENTITY_DELIRIUM ? 1 : FORM_SHOT_SLOWDOWN) * shots.interval;
|
|
float turnAngle = ((float)(int)turn / (float)TURN_STEPS) * PI_F * 2;
|
|
bool isFired = false;
|
|
for (int i = 0; i < shots.burst; i++)
|
|
{
|
|
int frame = npc.deliriumAttackFrame - delays[i];
|
|
if (frame % period != 0) continue;
|
|
|
|
ProjectileParams params;
|
|
params.heightModifier = SHOT_HEIGHT;
|
|
params.scale = (float)(Random() % UINT32_MAX) * RANDOM_UNIT_SCALE + DELIRIUM_SHOT_SCALE;
|
|
params.fallingAccelModifier = DELIRIUM_SHOT_FALL_ACCEL;
|
|
params.fallingSpeedModifier = DELIRIUM_SHOT_FALL_SPEED;
|
|
params.bulletFlags |= shots.flags;
|
|
params.color = {{1, 1, 1, 1}, {shots.colorize[0], shots.colorize[1], shots.colorize[2], 1}, {0, 0, 0}};
|
|
params.targetPosition = npc.pos;
|
|
params.circleAngle = turnAngle + angles[i];
|
|
if (shots.isAlternating && ((frame / period) & 1) == 0)
|
|
{
|
|
params.bulletFlags |= PROJECTILE_CURVE_RIGHT;
|
|
const std::array<float, 3>& tint = shots.alternateColorize;
|
|
params.color = {{1, 1, 1, 1}, {tint[0], tint[1], tint[2], 1}, {0, 0, 0}};
|
|
}
|
|
else if (shots.isAlternating) params.bulletFlags |= PROJECTILE_CURVE_LEFT;
|
|
if (mode == PROJECTILES_RING) velocity.y = (float)shots.ringSize;
|
|
npc.FireProjectiles(npc.pos, velocity, mode, params);
|
|
isFired = true;
|
|
}
|
|
|
|
if (isFired)
|
|
{
|
|
if (npc.type == ENTITY_DELIRIUM) npc.sprite.Play("Blink");
|
|
if (--volleys < 1)
|
|
{
|
|
if (Random() % KEEP_ROLL < keepOdds) keepOdds -= KEEP_ODDS_STEP;
|
|
else
|
|
{
|
|
uint32_t roll;
|
|
do roll = Random();
|
|
while ((int)(roll % SHOT_PATTERNS) == pattern);
|
|
keepOdds = KEEP_ODDS_FRESH;
|
|
turn = Random() % TURN_STEPS;
|
|
pattern = (int)(roll % SHOT_PATTERNS);
|
|
}
|
|
volleys = RANDOM_PATTERN;
|
|
}
|
|
}
|
|
npc.deliriumAttackAngle = (uint8_t)turn;
|
|
npc.deliriumAttackFrame++;
|
|
npc.deliriumAttackKeepChance = keepOdds;
|
|
npc.deliriumAttackRepeats = (uint8_t)volleys;
|
|
npc.deliriumAttackPattern = (uint8_t)pattern;
|
|
}
|
|
|
|
// How fast a form runs this frame: the extra steps it takes, how many of them step its animations and call its AI,
|
|
// and the share of its velocity each extra step moves it by.
|
|
struct FormSpeed
|
|
{
|
|
Vector stepVelocity{};
|
|
uint32_t aiCalls = 0;
|
|
uint32_t animSteps = 0;
|
|
uint32_t steps = 0;
|
|
};
|
|
|
|
// Sets a form's steps (and with them its AI calls and animation steps) to a count of its own.
|
|
static void form_steps_set(FormSpeed& speed, float steps)
|
|
{
|
|
speed.steps = (uint32_t)steps;
|
|
speed.animSteps = speed.steps;
|
|
speed.aiCalls = speed.steps + 1;
|
|
}
|
|
|
|
// Scales the extra steps' velocity by a factor and the steps' share of a full speed.
|
|
static void form_velocity_scale(FormSpeed& speed, float factor)
|
|
{
|
|
float share = (float)speed.steps / FULL_STEPS;
|
|
speed.stepVelocity = vector_make(speed.stepVelocity.x * factor * share, speed.stepVelocity.y * factor * share);
|
|
}
|
|
|
|
// The speed each boss runs at as a form, some bosses holding or cutting short their attacks while the form is young.
|
|
static FormSpeed form_speed_get(Entity_NPC& npc, float health)
|
|
{
|
|
uint32_t aggression = (uint32_t)(FULL_STEPS - health * FULL_STEPS);
|
|
uint32_t age = npc.deliriumFormAge;
|
|
FormSpeed speed = {npc.velocity, aggression + 1, aggression, npc.deliriumRageTimer ? RAGE_STEPS : aggression};
|
|
uint32_t odds = (uint32_t)FULL_STEPS - aggression;
|
|
bool isAttacking = npc.state == NPC_STATE_ATTACK2 || npc.state == NPC_STATE_ATTACK3;
|
|
|
|
switch (npc.type)
|
|
{
|
|
case ENTITY_FORSAKEN:
|
|
case ENTITY_LOKI:
|
|
form_velocity_scale(speed, 1);
|
|
break;
|
|
case ENTITY_LARRYJR:
|
|
case ENTITY_CHUB:
|
|
case ENTITY_MASK_OF_INFAMY:
|
|
case ENTITY_GURDY_JR:
|
|
case ENTITY_WIDOW:
|
|
case ENTITY_GURGLING:
|
|
case ENTITY_DARK_ONE:
|
|
form_velocity_scale(speed, 0.20000005f);
|
|
break;
|
|
case ENTITY_MONSTRO:
|
|
case ENTITY_HEADLESS_HORSEMAN:
|
|
case ENTITY_RAG_MAN:
|
|
form_velocity_scale(speed, 0.39999998f);
|
|
break;
|
|
case ENTITY_GURDY:
|
|
case ENTITY_MONSTRO2:
|
|
case ENTITY_MOMS_HEART:
|
|
case ENTITY_MEGA_MAW:
|
|
if (age < YOUNG_FORM_FRAMES && npc.state == NPC_STATE_ATTACK) npc.state = NPC_STATE_IDLE;
|
|
if (age < YOUNG_FORM_FRAMES || npc.state == NPC_STATE_ATTACK) form_steps_set(speed, 1);
|
|
form_velocity_scale(speed, 0.39999998f);
|
|
break;
|
|
case ENTITY_MOM:
|
|
if (age > MOM_FORM_FRAMES && random_below((int)odds) == 0) npc.projectileCooldown = 0;
|
|
form_steps_set(speed, 0);
|
|
break;
|
|
case ENTITY_PIN:
|
|
form_velocity_scale(speed, (npc.variant == 0 ? 1.2f : 2.0f) - 1);
|
|
break;
|
|
case ENTITY_FAMINE:
|
|
form_velocity_scale(speed, 1.5f);
|
|
break;
|
|
case ENTITY_WAR:
|
|
if (npc.variant == ALTERNATE_FORM_VARIANT) form_velocity_scale(speed, 0);
|
|
else form_velocity_scale(speed, npc.variant == 1 ? 0.39999998f : 1.5f);
|
|
break;
|
|
case ENTITY_DUKE:
|
|
if (npc.variant == 1) form_velocity_scale(speed, 0.39999998f);
|
|
break;
|
|
case ENTITY_PEEP:
|
|
if (npc.variant != 1) break;
|
|
if (age < YOUNG_FORM_FRAMES && isAttacking) npc.state = NPC_STATE_IDLE;
|
|
if (age < YOUNG_FORM_FRAMES || isAttacking) form_steps_set(speed, 1);
|
|
break;
|
|
case ENTITY_FALLEN:
|
|
npc.maxHitPoints = npc.health;
|
|
form_velocity_scale(speed, 0.6f);
|
|
break;
|
|
case ENTITY_BLASTOCYST_BIG:
|
|
form_velocity_scale(speed, 0.6f);
|
|
break;
|
|
case ENTITY_GEMINI:
|
|
form_velocity_scale(speed, (npc.variant == 2 ? 1.1f : 1.2f) - 1);
|
|
break;
|
|
case ENTITY_SATAN:
|
|
if (npc.variant == ALTERNATE_FORM_VARIANT)
|
|
{
|
|
if (random_below((int)odds) == 0) npc.stateFrame = 0;
|
|
form_velocity_scale(speed, 0.20000005f);
|
|
form_steps_set(speed, 0);
|
|
break;
|
|
}
|
|
form_velocity_scale(speed, 0);
|
|
form_steps_set(speed, FULL_STEPS - health * FULL_STEPS);
|
|
break;
|
|
case ENTITY_DADDYLONGLEGS:
|
|
speed.animSteps = 0;
|
|
break;
|
|
case ENTITY_ISAAC:
|
|
form_steps_set(speed, 2 - (health + health));
|
|
form_velocity_scale(speed, 0.6f);
|
|
break;
|
|
case ENTITY_DINGLE:
|
|
speed.aiCalls = 2;
|
|
form_velocity_scale(speed, 0.20000005f);
|
|
break;
|
|
case ENTITY_GATE:
|
|
npc.pos = npc.targetPosition;
|
|
form_velocity_scale(speed, -1);
|
|
break;
|
|
case ENTITY_CAGE:
|
|
if (npc.state == NPC_STATE_JUMP) form_steps_set(speed, 1 - health);
|
|
break;
|
|
case ENTITY_HUSH:
|
|
form_steps_set(speed, 1 - health);
|
|
break;
|
|
case ENTITY_ADVERSARY:
|
|
form_velocity_scale(speed, 0.20000005f);
|
|
form_steps_set(speed, npc.state == NPC_STATE_ATTACK ? 1 - health : 2 - (health + health));
|
|
break;
|
|
case ENTITY_URIEL:
|
|
case ENTITY_GABRIEL:
|
|
case ENTITY_THE_LAMB:
|
|
speed.aiCalls = 1;
|
|
form_velocity_scale(speed, 0.20000005f);
|
|
break;
|
|
case ENTITY_LITTLE_HORN:
|
|
form_velocity_scale(speed, 1);
|
|
form_steps_set(speed, 2 - (health + health));
|
|
break;
|
|
case ENTITY_SISTERS_VIS:
|
|
form_velocity_scale(speed, 0.6f);
|
|
form_steps_set(speed, 2 - (health + health));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return speed;
|
|
}
|
|
|
|
// Whether a forced attack passes its odds: always at none, else one roll in them.
|
|
static bool is_forced(uint32_t odds)
|
|
{
|
|
return odds == 0 || Random() % odds == 0;
|
|
}
|
|
|
|
// The horsemen's forced attack odds: 10 to the power of the form's odds scaled.
|
|
static uint32_t horseman_odds_get(uint32_t odds, double power)
|
|
{
|
|
return (uint32_t)(int)std::pow(FORCED_ODDS_BASE, (double)odds * power);
|
|
}
|
|
|
|
// Forces an attack a form would wait for: Monstro and Monstro II taunt or jump, Chub charges, the horsemen strike.
|
|
static void form_attack_force(Entity_NPC& npc, uint32_t odds)
|
|
{
|
|
const char* anim = nullptr;
|
|
|
|
switch (npc.type)
|
|
{
|
|
case ENTITY_MONSTRO:
|
|
case ENTITY_MONSTRO2:
|
|
if (npc.state != NPC_STATE_IDLE || !is_forced(odds)) return;
|
|
if (Random() & 1)
|
|
{
|
|
npc.state = NPC_STATE_JUMP;
|
|
npc_sound_play(SOUND_BOSS_LITE_ROAR, 1, DELIRIUM_SOUND_DELAY, champion_pitch_get(npc));
|
|
anim = "JumpUp";
|
|
}
|
|
else
|
|
{
|
|
npc.state = NPC_STATE_ATTACK;
|
|
anim = "Taunt";
|
|
}
|
|
break;
|
|
case ENTITY_CHUB:
|
|
if (npc.variant == 0 && npc.state == NPC_STATE_MOVE && is_forced(odds) && npc.stateFrame == 0)
|
|
npc.state = NPC_STATE_SUMMON;
|
|
return;
|
|
case ENTITY_PESTILENCE:
|
|
if (npc.state != NPC_STATE_MOVE || !is_forced(horseman_odds_get(odds, 1))) return;
|
|
npc.stateFrame = 0;
|
|
if (Random() & 1)
|
|
{
|
|
npc.state = NPC_STATE_ATTACK;
|
|
anim = npc.i1 ? "HeadlessAttack1" : "Attack1";
|
|
}
|
|
else
|
|
{
|
|
npc.state = NPC_STATE_SUMMON;
|
|
anim = npc.i1 ? "HeadlessAttack2" : "Attack2";
|
|
}
|
|
break;
|
|
case ENTITY_WAR:
|
|
if (npc.state != NPC_STATE_MOVE || npc.variant == ALTERNATE_FORM_VARIANT) return;
|
|
if (!is_forced(horseman_odds_get(odds, 1))) return;
|
|
if (Random() & 1)
|
|
{
|
|
int roar = SOUND_MONSTER_ROAR_0 + (int)(Random() & 3);
|
|
npc_sound_play(roar, 1, DELIRIUM_SOUND_DELAY, champion_pitch_get(npc));
|
|
npc.state = NPC_STATE_JUMP;
|
|
anim = "Attack2";
|
|
}
|
|
else
|
|
{
|
|
npc.state = NPC_STATE_ATTACK;
|
|
anim = "Attack1";
|
|
}
|
|
npc.stateFrame = 0;
|
|
break;
|
|
case ENTITY_DEATH:
|
|
{
|
|
double power = npc.variant == DEATH_RUSH_VARIANT ? DEATH_30_ODDS_POWER : DEATH_ODDS_POWER;
|
|
if (npc.state != NPC_STATE_MOVE || npc.variant == ALTERNATE_FORM_VARIANT) return;
|
|
if (!is_forced(horseman_odds_get(odds, power))) return;
|
|
|
|
uint32_t pick = npc.variant == DEATH_RUSH_VARIANT ? 0 : Random() % 3;
|
|
if (pick == 0) npc.state = NPC_STATE_SUMMON;
|
|
else if (pick == 1) npc.state = NPC_STATE_ATTACK;
|
|
else npc.state = NPC_STATE_SUMMON2;
|
|
npc.stateFrame = 0;
|
|
return;
|
|
}
|
|
case ENTITY_BLASTOCYST_BIG:
|
|
if (npc.state == NPC_STATE_SPECIAL) npc.state = NPC_STATE_IDLE;
|
|
return;
|
|
default:
|
|
return;
|
|
}
|
|
if (anim) npc.sprite.Play(anim, PLAY_FORCED);
|
|
}
|
|
|
|
// 004a9860 Runs a form's AI at its speed: past its first frames, the steps force its attacks, move it on, step its
|
|
// animations and call its AI, counting the rage down. Before that only its animations play.
|
|
static void delirium_form_update(Entity_NPC& npc)
|
|
{
|
|
if (npc.health == 0) return;
|
|
|
|
float health = health_share_get(npc);
|
|
uint32_t rage = npc.deliriumRageTimer;
|
|
FormSpeed speed = form_speed_get(npc, health);
|
|
uint32_t odds = (uint32_t)FULL_STEPS - (uint32_t)(FULL_STEPS - health * FULL_STEPS);
|
|
|
|
if (speed.steps * STEP_FRAMES >= npc.deliriumFormAge) return npc.sprite.Update();
|
|
|
|
for (uint32_t step = 0; step <= speed.steps; step++)
|
|
{
|
|
form_attack_force(npc, odds);
|
|
if (step != 0)
|
|
{
|
|
if (step <= speed.animSteps) npc.sprite.Update();
|
|
npc.pos = vector_add(npc.pos, speed.stepVelocity);
|
|
}
|
|
if (step < speed.aiCalls) npc_ai_update(npc);
|
|
}
|
|
npc.deliriumRageTimer = rage ? rage - 1 : 0;
|
|
}
|
|
|
|
// Whether any corner 100 out from him shows on the camera.
|
|
static bool is_seen(Entity_NPC& npc)
|
|
{
|
|
Camera& camera = *g_game->room->camera;
|
|
|
|
for (float x : {-CAMERA_CORNER, CAMERA_CORNER})
|
|
for (float y : {-CAMERA_CORNER, CAMERA_CORNER})
|
|
if (camera.IsPosVisible(vector_make(npc.pos.x + x, npc.pos.y + y))) return true;
|
|
return false;
|
|
}
|
|
|
|
// Whether a spot lies 160 or more from every player.
|
|
static bool is_clear_of_players(Vector spot)
|
|
{
|
|
for (Entity_Player* player : g_game->playerManager.playerList)
|
|
if (vector_length_squared(vector_sub(player->pos, spot)) < DELIRIUM_TELEPORT_REACH * DELIRIUM_TELEPORT_REACH) return false;
|
|
return true;
|
|
}
|
|
|
|
// Teleports him ahead of his target, away from the players, his shots and form clock starting over. Without a clear
|
|
// spot he stays. Either way the next teleport is 300 to 899 frames off.
|
|
static void delirium_teleport(Entity_NPC& npc)
|
|
{
|
|
Room& room = *g_game->room;
|
|
float reach = random_unit() * DELIRIUM_TELEPORT_REACH + DELIRIUM_TELEPORT_REACH;
|
|
Entity* target = npc.GetPlayerTarget();
|
|
Vector way = vector_is_zero(target->velocity) ? random_direction() : vector_normalized(target->velocity);
|
|
Vector spot = room.GetClampedPositionImpl(vector_add(target->pos, vector_scale(way, reach)), DELIRIUM_TELEPORT_REACH,
|
|
DELIRIUM_TELEPORT_REACH, DELIRIUM_TELEPORT_REACH, DELIRIUM_TELEPORT_REACH);
|
|
float start = random_unit() * 360;
|
|
int tries = 0;
|
|
|
|
while (!is_clear_of_players(spot))
|
|
{
|
|
float ring = (float)tries * DELIRIUM_RING_STEP + TELEPORT_RING;
|
|
float angle = ((float)(tries % TELEPORT_QUARTERS) * TELEPORT_QUARTER_DEGREES + start) * DEGREES_TO_RADIANS;
|
|
Vector around = npc.GetPlayerTarget()->pos;
|
|
spot = room.GetClampedPositionImpl(
|
|
vector_make(std::cos(angle) * ring + around.x, std::sin(angle) * ring + around.y), DELIRIUM_TELEPORT_REACH,
|
|
DELIRIUM_TELEPORT_REACH, DELIRIUM_TELEPORT_REACH, DELIRIUM_TELEPORT_REACH);
|
|
if (++tries < DELIRIUM_TELEPORT_TRIES) continue;
|
|
|
|
log_printf(LOG_INFO, "??? teleport: %d tries\n", tries);
|
|
npc.deliriumFormAge = npc.deliriumFormAge + 1;
|
|
npc.deliriumTeleportTimer = Random() % TELEPORT_FRAMES_ROLL + TELEPORT_FRAMES_MIN;
|
|
return;
|
|
}
|
|
|
|
log_printf(LOG_INFO, "??? teleport: %d tries\n", tries);
|
|
npc.pos = spot;
|
|
npc_sound_play(SOUND_HELL_PORTAL1, 1, DELIRIUM_SOUND_DELAY, champion_pitch_get(npc));
|
|
npc.deliriumAttackFrame = 0;
|
|
npc.deliriumAttackAngle = 0;
|
|
npc.deliriumFormAge = 0;
|
|
npc.deliriumTeleportTimer = Random() % TELEPORT_FRAMES_ROLL + TELEPORT_FRAMES_MIN;
|
|
}
|
|
|
|
// Big Horn's hands stay in Delirium's colors when his form comes out of the ground.
|
|
static void big_horn_hands_dress()
|
|
{
|
|
std::vector<Entity*>& updated = g_game->room->entityList.updateEL;
|
|
|
|
for (size_t i = 0; i < updated.size(); i++)
|
|
if (is_form(*updated[i], ENTITY_BIG_HORN, 1)) ANM2::LoadDeliriumForm(updated[i]->sprite, ENTITY_BIG_HORN, 1, false);
|
|
}
|
|
|
|
// Dresses what a form brought out this frame: the parts of the next phase, War's riders and the other legs of
|
|
// Daddy Long Legs (made invincible), as they start.
|
|
static void form_spawns_dress(Entity_NPC& npc, int previousI1)
|
|
{
|
|
if (previousI1 < npc.i1)
|
|
for (Entity* part : entity_query(npc.type, npc.variant + (int)ALTERNATE_FORM_VARIANT))
|
|
{
|
|
ANM2::LoadDeliriumForm(npc.sprite, npc.type, npc.variant, false);
|
|
ANM2::LoadDeliriumForm(part->sprite, npc.type, npc.variant + (int)ALTERNATE_FORM_VARIANT, true);
|
|
}
|
|
|
|
if (npc.type == ENTITY_WAR)
|
|
{
|
|
if (npc.variant == 1 && npc.IsFrame(8, 0) && npc.state == NPC_STATE_ATTACK2 && npc.stateFrame == 2 &&
|
|
npc.spawnerType != ENTITY_WAR)
|
|
for (Entity* rider : entity_query(ENTITY_WAR, 1))
|
|
ANM2::LoadDeliriumForm(rider->sprite, npc.type, npc.variant, true);
|
|
return;
|
|
}
|
|
if (npc.type != ENTITY_DADDYLONGLEGS) return;
|
|
|
|
for (Entity* leg : entity_query(ENTITY_DADDYLONGLEGS, npc.variant))
|
|
{
|
|
if (leg == &npc) continue;
|
|
int frame = leg->sprite.animState.animData ? (int)std::floor(leg->sprite.animState.animFrame) : -1;
|
|
if (frame != 0) continue;
|
|
|
|
std::string anim = leg->sprite.animState.animData ? leg->sprite.animState.animData->name : "";
|
|
ANM2::LoadDeliriumForm(leg->sprite, npc.type, npc.variant, true);
|
|
leg->sprite.Play(anim);
|
|
leg->isInvincible = true;
|
|
}
|
|
}
|
|
|
|
// Runs a boss form for a frame as the boss it mimics, his own health and pending damage kept out of the boss's hands,
|
|
// and redresses him when the boss turns into another.
|
|
static void boss_form_update(Entity_NPC& npc)
|
|
{
|
|
bool isBigHornRising = npc.type == ENTITY_BIG_HORN && npc.state == NPC_STATE_MOVE && npc.stateFrame == 0 &&
|
|
(!npc.sprite.animState.animData || !npc.sprite.animState.isPlaying);
|
|
int previousI1 = npc.i1;
|
|
float health = npc.health;
|
|
float maxHealth = npc.maxHitPoints;
|
|
std::vector<DamageEvent> damageEvents = std::move(npc.damageEvents);
|
|
float pendingDamage = npc.pendingDamage;
|
|
uint64_t pendingDamageFlags = npc.pendingDamageFlags;
|
|
|
|
npc.damageEvents.clear();
|
|
npc.pendingDamage = 0;
|
|
npc.pendingDamageFlags = 0;
|
|
delirium_form_update(npc);
|
|
npc.health = health;
|
|
npc.maxHitPoints = maxHealth;
|
|
npc.damageEvents = std::move(damageEvents);
|
|
npc.pendingDamageFlags = pendingDamageFlags;
|
|
npc.pendingDamage = pendingDamage;
|
|
|
|
if (npc.type == ENTITY_BIG_HORN && isBigHornRising) big_horn_hands_dress();
|
|
uint32_t cut = (uint32_t)(npc.pendingDamage * TELEPORT_DAMAGE_SHARE);
|
|
npc.deliriumTeleportTimer = cut <= npc.deliriumTeleportTimer ? npc.deliriumTeleportTimer - cut : 0;
|
|
if (npc.deliriumBossType != (uint32_t)npc.type || npc.deliriumBossVariant != (uint32_t)npc.variant)
|
|
{
|
|
npc.deliriumBossType = npc.type;
|
|
npc.deliriumBossVariant = npc.variant;
|
|
ANM2::LoadDeliriumForm(npc.sprite, npc.type, npc.variant, false);
|
|
}
|
|
form_spawns_dress(npc, previousI1);
|
|
}
|
|
|
|
// His own form between attacks: back to idle after a blink, and quick to teleport once out of sight.
|
|
static void own_form_update(Entity_NPC& npc)
|
|
{
|
|
if (npc.sprite.IsFinished("Blink")) npc.sprite.Play("Idle");
|
|
npc.velocity = vector_make(0, 0);
|
|
if (!is_seen(npc)) npc.deliriumTeleportTimer = std::min(npc.deliriumTeleportTimer, TELEPORT_HIDDEN_FRAMES);
|
|
}
|
|
|
|
// A form's frame: the boss runs as itself, then his shots, his rage tint, his teleport (bosses that stay in place stay)
|
|
// and the attack count. A companion's damage passes to him and it runs and shoots as a form too.
|
|
static void form_update(Entity_NPC& npc)
|
|
{
|
|
int type = npc.type;
|
|
int variant = npc.variant;
|
|
|
|
npc.type = (int)npc.deliriumBossType;
|
|
npc.variant = (int)npc.deliriumBossVariant;
|
|
if (npc.deliriumBossType == ENTITY_DELIRIUM) own_form_update(npc);
|
|
else boss_form_update(npc);
|
|
delirium_shots_fire(npc);
|
|
npc.type = type;
|
|
npc.variant = variant;
|
|
|
|
float tint = npc.deliriumRageTimer ? RAGE_TINT : 1;
|
|
npc.SetColor({{1, tint, tint, 1}, {0, 0, 0, 0}, {0, 0, 0}}, -1, 0xff, false, false);
|
|
bool isStill = std::find(STILL_BOSSES.begin(), STILL_BOSSES.end(), (int)npc.deliriumBossType) != STILL_BOSSES.end();
|
|
if (!isStill && npc.deliriumTeleportTimer == 0) delirium_teleport(npc);
|
|
else
|
|
{
|
|
if (!isStill) npc.deliriumTeleportTimer = npc.deliriumTeleportTimer - 1;
|
|
npc.deliriumFormAge = npc.deliriumFormAge + 1;
|
|
}
|
|
|
|
bool isAttackState = std::find(ATTACK_STATES.begin(), ATTACK_STATES.end(), npc.state) != ATTACK_STATES.end();
|
|
if (npc.stateFrame == 1 && isAttackState) npc.deliriumRemainingAttacks--;
|
|
|
|
Entity* companion = npc.deliriumEntity;
|
|
if (!companion || companion->isDead) return;
|
|
|
|
npc.TakeDamage(companion->pendingDamage, companion->pendingDamageFlags, EntityRef(), SECOND_FRAMES);
|
|
delirium_form_update(*static_cast<Entity_NPC*>(companion));
|
|
delirium_shots_fire(*static_cast<Entity_NPC*>(companion));
|
|
}
|
|
|
|
// A boss met this run he may change into, or his own form one roll in 10.
|
|
// The original reads a missing entity's config through null. A missing one is not usable here.
|
|
static BossId form_pick(Entity_NPC& npc)
|
|
{
|
|
uint32_t roll = Random() % FORM_ROLL;
|
|
BossId form = {ENTITY_DELIRIUM, 0};
|
|
|
|
for (int draws = FORM_DRAWS; draws > 0; draws--)
|
|
{
|
|
EntityConfig_Entity* config = g_manager->entityConfig.GetEntity(form.type, form.variant, 0);
|
|
bool isLeft = form.type == (int)npc.deliriumBossType && form.variant == (int)npc.deliriumBossVariant;
|
|
bool isUsable = form.type != ENTITY_DELIRIUM && form.type != ENTITY_HORNFEL && form.type != ENTITY_GIDEON &&
|
|
config && !(config->tags & ENTITY_TAG_NODELIRIUM) && !isLeft;
|
|
if (roll < OWN_FORM_ODDS || isUsable) break;
|
|
|
|
std::vector<BossId>& met = g_game->encounteredBosses;
|
|
form = met.empty() ? BossId{} : met[Random() % met.size()];
|
|
}
|
|
return form;
|
|
}
|
|
|
|
// Rolls a rage for the new form (never Mom's or Satan's variant 10), its odds starting over after one.
|
|
static void rage_roll(Entity_NPC& npc)
|
|
{
|
|
bool isCalm = npc.deliriumBossType == ENTITY_MOM ||
|
|
(npc.deliriumBossType == ENTITY_SATAN && npc.deliriumBossVariant == ALTERNATE_FORM_VARIANT);
|
|
if (isCalm || npc.deliriumRageChance <= Random() % FORM_ROLL)
|
|
{
|
|
if (!isCalm) npc.deliriumRageChance = npc.deliriumRageChance + RAGE_ODDS_STEP;
|
|
npc.deliriumRageTimer = 0;
|
|
return;
|
|
}
|
|
npc.deliriumRageTimer = DELIRIUM_RAGE_FRAMES;
|
|
npc.deliriumRageChance = 0;
|
|
}
|
|
|
|
// Wakes the parts of a chained boss in his colors, Chub's, Pin's and Mom's Heart's sharing the form's health.
|
|
static void form_chain_dress(Entity_NPC& npc, bool isShared, float maxHealth)
|
|
{
|
|
auto dress = [&](Entity& link)
|
|
{
|
|
ANM2::LoadDeliriumForm(link.sprite, link.type, link.variant, true);
|
|
if (!isShared) return;
|
|
link.AddEntityFlags(FLAG_NO_DEATH_TRIGGER | FLAG_DONT_COUNT_BOSS_HP);
|
|
link.health = maxHealth;
|
|
link.maxHitPoints = maxHealth;
|
|
link.isInvincible = true;
|
|
};
|
|
|
|
for (Entity* link = npc.child; link; link = link->child) dress(*link);
|
|
for (Entity* link = npc.parent; link; link = link->parent) dress(*link);
|
|
}
|
|
|
|
// Starts the bosses that set up their parts on their first update, dressing the parts in his colors.
|
|
static void form_start(Entity_NPC& npc, float maxHealth)
|
|
{
|
|
Vector targetPos = npc.GetPlayerTarget()->pos;
|
|
if (npc.type == ENTITY_GURDY || npc.type == ENTITY_MOMS_HEART) npc_ai_update(npc);
|
|
npc.GetPlayerTarget()->pos = targetPos;
|
|
|
|
if (npc.type == ENTITY_MOM)
|
|
{
|
|
npc.PlaySound(SOUND_MOM_VOX_ISAAC, 1, MOM_VOICE_DELAY, false, 1);
|
|
npc.AddEntityFlags(FLAG_NO_DEATH_TRIGGER);
|
|
npc.targetPosition = npc.pos;
|
|
npc.state = NPC_STATE_IDLE;
|
|
npc.subtype = 2;
|
|
npc.projectileCooldown = SECOND_FRAMES;
|
|
npc.entityCollisionClass = ENTCOLL_NONE;
|
|
}
|
|
if (npc.type == ENTITY_GEMINI)
|
|
{
|
|
npc_ai_update(npc);
|
|
for (Entity* cord : entity_query(npc.type, GEMINI_UMBILICAL))
|
|
ANM2::LoadDeliriumForm(cord->sprite, cord->type, cord->variant, true);
|
|
if (npc.child) ANM2::LoadDeliriumForm(npc.child->sprite, npc.child->type, npc.child->variant, true);
|
|
}
|
|
if (npc.type == ENTITY_HUSH)
|
|
{
|
|
npc_ai_update(npc);
|
|
npc.state = NPC_STATE_IDLE;
|
|
npc.sprite.Play("Idle");
|
|
}
|
|
if ((npc.type == ENTITY_LOKI && npc.variant == 1) || npc.type == ENTITY_SISTERS_VIS)
|
|
{
|
|
npc_ai_update(npc);
|
|
for (Entity* other : entity_query(npc.type, npc.variant))
|
|
ANM2::LoadDeliriumForm(other->sprite, other->type, other->variant, true);
|
|
}
|
|
if (npc.type == ENTITY_SISTERS_VIS) npc.deliriumEntity = npc.child.get();
|
|
if (npc.type == ENTITY_GATE) npc_ai_update(npc);
|
|
if (npc.type == ENTITY_MASK_OF_INFAMY)
|
|
{
|
|
npc_ai_update(npc);
|
|
form_chain_dress(npc, false, maxHealth);
|
|
}
|
|
if (npc.type == ENTITY_THE_LAMB && npc.variant != (int)ALTERNATE_FORM_VARIANT) return;
|
|
if (npc.type == ENTITY_THE_LAMB) npc_ai_update(npc);
|
|
if (npc.type == ENTITY_CHUB || npc.type == ENTITY_PIN || npc.type == ENTITY_MOMS_HEART)
|
|
{
|
|
npc_ai_update(npc);
|
|
form_chain_dress(npc, true, maxHealth);
|
|
}
|
|
if (npc.type == ENTITY_CHUB) npc.state = NPC_STATE_APPEAR;
|
|
}
|
|
|
|
// Changes him into his next form: what the last one left goes, the new boss inits in his place (clamped into the
|
|
// room) keeping his health, with its body and maybe a companion, and he leaves a poof the size of the boss.
|
|
static void delirium_morph(Entity_NPC& npc, FormSeconds seconds)
|
|
{
|
|
delirium_minions_remove((int)npc.deliriumBossType, (int)npc.deliriumBossVariant, npc, npc.deliriumEntity);
|
|
if (npc.deliriumBossType == ENTITY_THE_LAMB && npc.deliriumBossVariant == ALTERNATE_FORM_VARIANT && npc.child)
|
|
npc.child->Remove();
|
|
|
|
BossId form = form_pick(npc);
|
|
npc.deliriumBossType = form.type;
|
|
npc.deliriumBossVariant = form.variant;
|
|
if (form.type == 0) log_printf(LOG_ASSERT, "No form for Delirium");
|
|
rage_roll(npc);
|
|
if (form.type == ENTITY_MAMA_GURDY) npc.deliriumBossVariant = 0;
|
|
else if (form.type == ENTITY_MOM || (form.type == ENTITY_SATAN && (Random() & 1) == 0))
|
|
npc.deliriumBossVariant = ALTERNATE_FORM_VARIANT;
|
|
|
|
int type = npc.type;
|
|
int variant = npc.variant;
|
|
float health = npc.health;
|
|
float maxHealth = npc.maxHitPoints;
|
|
Vector spot = g_game->room->GetClampedPositionImpl(npc.pos, npc.size, npc.size, npc.size, npc.size);
|
|
|
|
npc.type = (int)npc.deliriumBossType;
|
|
npc.variant = (int)npc.deliriumBossVariant;
|
|
npc.ClearReferences();
|
|
log_printf(LOG_INFO, "Changed Delirium form to %d:%u.\n", npc.type, (uint32_t)npc.variant);
|
|
npc.Init(npc.type, npc.variant, 0, Random());
|
|
npc.pos = spot;
|
|
npc.deliriumBossType = npc.type;
|
|
npc.state = NPC_STATE_INIT;
|
|
npc.deliriumBossVariant = npc.variant;
|
|
npc.deliriumTransformationTimer = form_frames_roll(seconds);
|
|
npc.deliriumRemainingAttacks = (uint8_t)(Random() % NPC_STATE_ATTACKS_ROLL + NPC_STATE_ATTACKS_MIN);
|
|
ANM2::LoadDeliriumForm(npc.sprite, npc.type, npc.variant, true);
|
|
delirium_segments_spawn(npc, maxHealth);
|
|
delirium_companion_spawn(npc);
|
|
npc.deliriumState = DELIRIUM_FORM;
|
|
npc.stateFrame = 0;
|
|
if (npc.type == ENTITY_SATAN && npc.deliriumBossVariant == ALTERNATE_FORM_VARIANT)
|
|
npc.entityCollisionClass = ENTCOLL_NONE;
|
|
else if (npc.type == ENTITY_SATAN)
|
|
{
|
|
npc.i1 = 2;
|
|
npc.state = NPC_STATE_MOVE;
|
|
}
|
|
form_start(npc, maxHealth);
|
|
|
|
npc.deliriumFormAge = 0;
|
|
npc.health = health;
|
|
npc.maxHitPoints = maxHealth;
|
|
npc.type = type;
|
|
npc.variant = variant;
|
|
Entity* cloud = spawn_at(ENTITY_EFFECT, EFFECT_POOF01, poof_size_get(npc, false), npc.pos, &npc);
|
|
cloud->posOffset = npc.posOffset;
|
|
cloud->renderDepthOffset = npc.posOffset.y + 1;
|
|
}
|
|
|
|
// His death: every enemy and shot in the room dies with him, and he comes back in his own form, invincible at one
|
|
// health, for the hallucinations and the scream.
|
|
static void delirium_death_start(Entity_NPC& npc)
|
|
{
|
|
Game& game = *g_game;
|
|
std::vector<Entity*>& updated = game.room->entityList.updateEL;
|
|
|
|
delirium_minions_remove((int)npc.deliriumBossType, (int)npc.deliriumBossVariant, npc, npc.deliriumEntity);
|
|
for (size_t i = 0; i < updated.size(); i++)
|
|
{
|
|
Entity& entity = *updated[i];
|
|
bool isFoe = (game.deathmatchManager.state >= DEATHMATCH_INTRO && entity.type == ENTITY_PLAYER) ||
|
|
(entity.type >= ENTITY_FIRST_ENEMY && entity.type < ENTITY_EFFECT);
|
|
if (isFoe && entity.CanShutDoors() && entity.type != ENTITY_DARK_ESAU && !entity.HasEntityFlags(FLAG_FRIENDLY))
|
|
entity.Kill(EntityRef());
|
|
if (entity.type == ENTITY_PROJECTILE) entity.isDead = true;
|
|
}
|
|
|
|
npc.isDead = false;
|
|
Vector spot = game.room->GetClampedPositionImpl(npc.pos, npc.size, npc.size, npc.size, npc.size);
|
|
npc.ClearReferences();
|
|
npc.Init(ENTITY_DELIRIUM, 0, 0, Random());
|
|
npc.pos = spot;
|
|
npc.sprite.Play("Idle", PLAY_FORCED);
|
|
npc.deliriumState = DELIRIUM_DYING;
|
|
npc.deliriumTransformationTimer = DEATH_HALLUCINATIONS;
|
|
npc.velocity = vector_make(0, 0);
|
|
npc.health = 1;
|
|
npc.isInvincible = true;
|
|
npc.entityCollisionClass = ENTCOLL_NONE;
|
|
}
|
|
|
|
// The hallucinations, one each time the last ends (0.4 seconds a one left), then the gurgle.
|
|
static void delirium_dying_update(Entity_NPC& npc)
|
|
{
|
|
npc.sprite.Update();
|
|
if (g_game->hallucinationTimer > 0) return;
|
|
|
|
int left = npc.deliriumTransformationTimer;
|
|
g_game->ShowHallucination((int)((float)left * HALLUCINATION_SECONDS * SECOND_FRAMES),
|
|
left == 1 ? HALLUCINATION_LAST : HALLUCINATION_RANDOM);
|
|
if (--npc.deliriumTransformationTimer != 0) return;
|
|
|
|
npc.deliriumState = DELIRIUM_SCREAM;
|
|
npc.deliriumTransformationTimer = SCREAM_LOOPS;
|
|
npc_sound_play(SOUND_ANGRY_GURGLE, GURGLE_VOLUME, DELIRIUM_SOUND_DELAY, GURGLE_PITCH);
|
|
npc.sprite.Play("IdleNoLoop", PLAY_FORCED);
|
|
}
|
|
|
|
// The double speed loops, then the scream, after which he dies for good.
|
|
static void delirium_scream_update(Entity_NPC& npc)
|
|
{
|
|
if (npc.sprite.IsPlaying("IdleNoLoop"))
|
|
{
|
|
npc.sprite.Update();
|
|
npc.sprite.Update();
|
|
}
|
|
if (npc.sprite.IsFinished("IdleNoLoop"))
|
|
{
|
|
if (--npc.deliriumTransformationTimer == 0) npc.sprite.Play("Scream");
|
|
else npc.sprite.Play("IdleNoLoop", PLAY_FORCED);
|
|
return;
|
|
}
|
|
if (npc.sprite.IsFinished("Scream")) npc.isDead = true;
|
|
}
|
|
|
|
// His first frame: invincible and idle, a shot pattern to draw, a form to change into and a teleport to come.
|
|
static void delirium_start(Entity_NPC& npc, FormSeconds seconds)
|
|
{
|
|
npc.isInvincible = true;
|
|
npc.sprite.Play("Idle");
|
|
npc.deliriumState = DELIRIUM_MORPH;
|
|
npc.deliriumBossType = 0;
|
|
npc.deliriumBossVariant = 0;
|
|
npc.deliriumTransformationTimer = form_frames_roll(seconds);
|
|
uint32_t attacks = Random();
|
|
npc.deliriumAttackFrame = 0;
|
|
npc.deliriumAttackKeepChance = 0;
|
|
npc.deliriumAttackPattern = RANDOM_PATTERN;
|
|
npc.deliriumAttackRepeats = 0;
|
|
npc.deliriumAttackAngle = 0;
|
|
npc.state = NPC_STATE_ATTACK;
|
|
npc.deliriumRemainingAttacks = (uint8_t)(attacks % NPC_STATE_ATTACKS_ROLL + NPC_STATE_ATTACKS_MIN);
|
|
npc.shieldFrames = START_SHIELD_FRAMES;
|
|
npc.deliriumTeleportTimer = Random() % TELEPORT_FRAMES_ROLL + TELEPORT_FRAMES_MIN;
|
|
}
|
|
|
|
// 004a6500 NpcAI::ENTITY_DELIRIUM: Delirium changes into the bosses met this run (or his own form), each for a few
|
|
// seconds and a few attacks, running them faster as he weakens, shooting his own patterns over them and teleporting
|
|
// ahead of his target. His death kills the room and plays out in hallucinations and a scream.
|
|
void boss_delirium_update(Entity_NPC& npc)
|
|
{
|
|
FormSeconds seconds = FORM_SECONDS[(int)(health_share_get(npc) * HEALTH_FIFTHS)];
|
|
|
|
if (npc.isDead) return delirium_death_start(npc);
|
|
switch (npc.deliriumState)
|
|
{
|
|
case DELIRIUM_DYING:
|
|
delirium_dying_update(npc);
|
|
npc.velocity = vector_make(0, 0);
|
|
return;
|
|
case DELIRIUM_SCREAM:
|
|
delirium_scream_update(npc);
|
|
npc.velocity = vector_make(0, 0);
|
|
return;
|
|
case DELIRIUM_START:
|
|
return delirium_start(npc, seconds);
|
|
case DELIRIUM_FORM:
|
|
if (--npc.deliriumTransformationTimer == 0 || npc.deliriumRemainingAttacks == 0)
|
|
{
|
|
npc.deliriumState = DELIRIUM_MORPH;
|
|
npc.stateFrame = 0;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
npc.shieldStrength = (1 - npc.health / npc.maxHitPoints) * SHIELD_STRENGTH;
|
|
if (npc.deliriumBossType == ENTITY_DELIRIUM) npc.shieldStrength = 0;
|
|
if (npc.deliriumState == DELIRIUM_MORPH) return delirium_morph(npc, seconds);
|
|
if (npc.deliriumState == DELIRIUM_FORM) form_update(npc);
|
|
}
|