Curation round 23 (code only): the Mods menu and HUD pieces, Dogma and the Beast, Visage, Hornfel and other bosses, enemies and Entity_NPC branches, player revivals and missing methods, the player's frame, familiars, lasers, weapons and bombs, shared constants folded (115 duplicates, 385 gaps)
This commit is contained in:
1 parent
b9405bfb31
commit
11c71fe041
208 files changed
+20487
-5741
No files matched your search
@@ -0,0 +1,345 @@
|
||||
#include "boss_repentance.h"
|
||||
#include "boss_ai.h"
|
||||
#include "manager.h"
|
||||
#include "loot_list.h"
|
||||
#include "npc_ai.h"
|
||||
#include <algorithm>
|
||||
|
||||
// Clog's states: idling, spitting a drip, its whirlpool spin, its bullet hell and its fart.
|
||||
constexpr int CLOG_IDLE = NPC_STATE_IDLE;
|
||||
constexpr int CLOG_SPIT = NPC_STATE_ATTACK;
|
||||
constexpr int CLOG_SPIN = NPC_STATE_ATTACK2;
|
||||
constexpr int CLOG_BULLET_HELL = NPC_STATE_ATTACK3;
|
||||
constexpr int CLOG_FART = NPC_STATE_ATTACK4;
|
||||
|
||||
// Clog keeps its cooldowns packed in i2's bytes, as the original does: the spin's, the bullet hell's and the fart's,
|
||||
// each 90 after its attack, counted down every other frame.
|
||||
enum ClogCooldown
|
||||
{
|
||||
COOLDOWN_UNUSED,
|
||||
COOLDOWN_SPIN,
|
||||
COOLDOWN_BULLET_HELL,
|
||||
COOLDOWN_FART
|
||||
};
|
||||
constexpr uint8_t CLOG_ATTACK_COOLDOWN = 90;
|
||||
|
||||
static uint8_t& clog_cooldown(Entity_NPC& npc, ClogCooldown which)
|
||||
{
|
||||
return reinterpret_cast<uint8_t*>(&npc.i2)[which];
|
||||
}
|
||||
|
||||
// Its pick, one frame in ten: a spit (40 for each enemy missing from 5), the spin (20 per enemy from 3 enemies,
|
||||
// else 1), the bullet hell and the fart (30 each, 1 while cooling down).
|
||||
constexpr uint32_t CLOG_ATTACK_ODDS = 10;
|
||||
constexpr int CLOG_SPIT_ENEMY_LIMIT = 5;
|
||||
constexpr int CLOG_SPIT_WEIGHT = 40;
|
||||
constexpr int SPIN_WEIGHT = 20;
|
||||
constexpr int SPIN_WEIGHT_MIN = 60;
|
||||
constexpr int CLOG_ATTACK_WEIGHT = 30;
|
||||
constexpr float SPIN_SLOW = 10;
|
||||
constexpr float SPIN_FAST = 25;
|
||||
constexpr float CLOG_FRICTION = 0.7f;
|
||||
|
||||
// The spit: a drip 10 out within 45 of down, flung at 5 to 10 with a splash 40 up.
|
||||
constexpr float CLOG_SPIT_SPREAD = 90;
|
||||
constexpr float CLOG_SPIT_SPREAD_HALF = 45;
|
||||
constexpr float CLOG_SPIT_REACH = 10;
|
||||
constexpr float CLOG_SPIT_SPEED = 5;
|
||||
constexpr float CLOG_SPIT_SPEED_RANGE = 5;
|
||||
constexpr float CLOG_SPIT_SPLASH_HEIGHT = -40;
|
||||
constexpr int CLOG_SPIT_SPLASH_DEPTH = 500;
|
||||
constexpr ColorMod CLOG_SPIT_SPLASH_COLOR = {{1, 1, 1, 1}, {3.5f, 2.5f, 2.4f, 1}, {0, 0, 0}};
|
||||
constexpr int DRIP_FLUNG = NPC_STATE_MOVE;
|
||||
|
||||
// The spin: a whirlpool every 8 frames from the 5th, drawing the walkers in (at up to 1.5 after 22 frames), turning
|
||||
// them 90 about it, splashing about players and enemies every 3rd frame; it ends with its animation past 90 frames.
|
||||
constexpr int SPIN_WATER_SOUND_FRAME = 5;
|
||||
constexpr int SPIN_WATER_DELAY = 30;
|
||||
constexpr float SPIN_CENTER_SLACK = 80;
|
||||
constexpr float SPIN_CENTER_PUSH = 2;
|
||||
constexpr float SPIN_RAMP = 15;
|
||||
constexpr float SPIN_PULL_MAX = 1.5f;
|
||||
constexpr int SPIN_WHIRL_FROM = 4;
|
||||
constexpr int SPIN_WHIRL_EVERY = 8;
|
||||
constexpr float SPIN_WHIRL_SCALE = 1;
|
||||
constexpr float SPIN_WHIRL_SCALE_RANGE = 0.5f;
|
||||
constexpr float SPIN_INWARD = 0.4f;
|
||||
constexpr float SPIN_AROUND = 0.8f;
|
||||
constexpr uint32_t SPLASH_RANGE = 3;
|
||||
constexpr int SPLASH_MIN = 2;
|
||||
constexpr float CLOG_SPLASH_SPEED = 4;
|
||||
constexpr float CLOG_SPLASH_SPEED_RANGE = 6;
|
||||
constexpr int CLOG_ATTACK_FRAMES = 90;
|
||||
|
||||
// The bullet hell: a ring of four puke shots every 6 frames, turning with its spin, at 4 (6 for the fast spin) falling
|
||||
// slower for the fast one, their flags changing after 30.
|
||||
constexpr int HELL_EVERY = 6;
|
||||
constexpr int HELL_SOUND_DELAY = 45;
|
||||
constexpr float HELL_SOUND_PITCH = 0.8f;
|
||||
constexpr float HELL_FAST_TURN = 20;
|
||||
constexpr float HELL_SPEED = 4;
|
||||
constexpr float HELL_SPEED_FAST = 6;
|
||||
constexpr float HELL_SHOTS = 4;
|
||||
constexpr float HELL_FALL = -0.1f;
|
||||
constexpr float HELL_FALL_FAST = -0.05f;
|
||||
constexpr int HELL_CHANGE_TIMEOUT = 30;
|
||||
|
||||
// The fart: three fart waves 30 out, 120 apart, two of them carrying an eternal fly while fewer than 3 are out.
|
||||
constexpr int FART_WAVES = 3;
|
||||
constexpr float FART_STEP = 120;
|
||||
constexpr float FART_REACH = 30;
|
||||
constexpr int ETERNAL_FLY_LIMIT = 3;
|
||||
constexpr int FART_LAUGH_DELAY = 20;
|
||||
constexpr float FART_LAUGH_PITCH = 0.9f;
|
||||
|
||||
// The spit's drip and its splash.
|
||||
static void clog_spit(Entity_NPC& npc)
|
||||
{
|
||||
Vector heading = vector_rotated(vector_make(0, 1), random_unit() * CLOG_SPIT_SPREAD - CLOG_SPIT_SPREAD_HALF);
|
||||
uint32_t seed = Random();
|
||||
auto* drip = static_cast<Entity_NPC*>(g_game->Spawn(
|
||||
{.position = vector_add(npc.pos, vector_scale(heading, CLOG_SPIT_REACH)), .spawner = &npc, .type = ENTITY_DRIP, .seed = seed}));
|
||||
npc_push(*drip, vector_scale(heading, random_unit() * CLOG_SPIT_SPEED_RANGE + CLOG_SPIT_SPEED));
|
||||
drip->ClearEntityFlags(FLAG_APPEAR);
|
||||
drip->state = DRIP_FLUNG;
|
||||
drip->Update();
|
||||
|
||||
seed = Random();
|
||||
Entity* splash = g_game->Spawn({.position = drip->pos, .velocity = drip->velocity, .subType = 1,
|
||||
.type = ENTITY_EFFECT, .variant = EFFECT_BLOOD_EXPLOSION, .seed = seed});
|
||||
splash->sprite.rotation = random_unit() * FULL_TURN_DEGREES;
|
||||
splash->sprite.Play("Poof");
|
||||
splash->posOffset = vector_make(0, CLOG_SPIT_SPLASH_HEIGHT);
|
||||
splash->renderZOffset = CLOG_SPIT_SPLASH_DEPTH;
|
||||
splash->sprite.color = CLOG_SPIT_SPLASH_COLOR;
|
||||
npc.PlaySound(SOUND_FAT_WIGGLE, 1, 2, false, 1);
|
||||
}
|
||||
|
||||
// The spin's draw on everything walking: in and around it, splashing about the players and enemies it moves.
|
||||
static void clog_whirl_pull(Entity_NPC& npc, float pull, float around)
|
||||
{
|
||||
std::vector<Entity*> entities(g_game->room->entityList.updateEL.begin(), g_game->room->entityList.updateEL.end());
|
||||
for (Entity* entity : entities)
|
||||
{
|
||||
bool isCreature = entity->type == ENTITY_PLAYER || Entity::is_enemy_type(entity->type);
|
||||
if (!isCreature && entity->type != ENTITY_PICKUP && entity->type != ENTITY_BOMB) continue;
|
||||
bool isWalking = entity->entityGridCollisionClass == GRIDCOLL_GROUND ||
|
||||
entity->entityGridCollisionClass == GRIDCOLL_NOPITS;
|
||||
if (entity->IsBoss() || !isWalking) continue;
|
||||
|
||||
Vector inward = vector_normalized(vector_sub(npc.pos, entity->pos));
|
||||
Vector drift = vector_scale(vector_add(vector_scale(vector_rotated(inward, around), SPIN_AROUND),
|
||||
vector_scale(inward, SPIN_INWARD)),
|
||||
pull);
|
||||
entity->velocity = vector_add(entity->velocity, drift);
|
||||
if (!entity->IsFrame(3, 0) || !isCreature) continue;
|
||||
|
||||
for (uint32_t count = Random() % SPLASH_RANGE + SPLASH_MIN; count != 0; count--)
|
||||
{
|
||||
Vector at = random_direction();
|
||||
Vector spot = vector_add(entity->pos, vector_scale(vector_scale(at, entity->size), random_unit()));
|
||||
uint32_t seed = Random();
|
||||
float speed = random_unit() * CLOG_SPLASH_SPEED_RANGE + CLOG_SPLASH_SPEED;
|
||||
Vector velocity = vector_add(vector_scale(drift, speed), random_direction());
|
||||
g_game->Spawn({.position = spot, .velocity = velocity, .spawner = entity, .subType = 1,
|
||||
.type = ENTITY_EFFECT, .variant = EFFECT_WATER_SPLASH, .seed = seed})->Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The spin: a whirlpool about it drawing everything in, ending once its loop finishes past 90 frames.
|
||||
static void clog_spin_update(Entity_NPC& npc)
|
||||
{
|
||||
npc.sprite.Play(npc.i1 == 0 ? "SpinLoop" : "SpinLoop2");
|
||||
npc.stateFrame++;
|
||||
if (npc.stateFrame == SPIN_WATER_SOUND_FRAME)
|
||||
g_manager->sfxManager.Play(SOUND_BOSS2_WATERTHRASHING, {.frameDelay = SPIN_WATER_DELAY});
|
||||
|
||||
Vector fromCenter = vector_sub(npc.pos, Room::GetCenterPos());
|
||||
if (vector_length(fromCenter) > SPIN_CENTER_SLACK)
|
||||
npc_push(npc, vector_scale(vector_normalized(fromCenter), SPIN_CENTER_PUSH));
|
||||
float pull = std::min((float)npc.stateFrame / SPIN_RAMP, SPIN_PULL_MAX);
|
||||
float around = npc.i1 == 0 ? RIGHT_ANGLE_DEGREES : -RIGHT_ANGLE_DEGREES;
|
||||
if (npc.stateFrame > SPIN_WHIRL_FROM && npc.IsFrame(SPIN_WHIRL_EVERY, 0))
|
||||
{
|
||||
uint32_t seed = Random();
|
||||
auto* whirl = static_cast<Entity_Effect*>(g_game->Spawn(
|
||||
{.position = npc.pos, .spawner = &npc, .subType = 1, .type = ENTITY_EFFECT, .variant = EFFECT_WHIRLPOOL, .seed = seed}));
|
||||
whirl->rotation = random_unit() * FULL_TURN_DEGREES;
|
||||
whirl->sprite.isFlipX = npc.i1 == 0;
|
||||
float scale = random_unit() * SPIN_WHIRL_SCALE_RANGE + SPIN_WHIRL_SCALE;
|
||||
whirl->sprite.scale = vector_make(scale, scale);
|
||||
whirl->Update();
|
||||
}
|
||||
clog_whirl_pull(npc, pull, around);
|
||||
|
||||
if (npc.stateFrame <= CLOG_ATTACK_FRAMES) return;
|
||||
const AnimationData* data = npc.sprite.animState.animData;
|
||||
if (npc.sprite.GetFrame() != (data ? data->length : 0) - 1) return;
|
||||
npc.sprite.Play(npc.i1 == 0 ? "SpinEnd" : "SpinEnd2");
|
||||
npc.stateFrame = -1;
|
||||
}
|
||||
|
||||
// The bullet hell: rings of puke shots every 6 frames as it turns.
|
||||
static void clog_bullet_hell_update(Entity_NPC& npc)
|
||||
{
|
||||
npc.sprite.Play("BulletHellLoop");
|
||||
npc.PlaySound(SOUND_FART_GURG, 1, HELL_SOUND_DELAY, false, HELL_SOUND_PITCH);
|
||||
bool isSlow = std::abs(npc.v1.y) < HELL_FAST_TURN;
|
||||
int frame = npc.stateFrame;
|
||||
if (frame % HELL_EVERY == 0)
|
||||
{
|
||||
ProjectileParams params;
|
||||
params.targetPosition = npc.pos;
|
||||
params.fallingAccelModifier = isSlow ? HELL_FALL : HELL_FALL_FAST;
|
||||
params.variant = PROJECTILE_PUKE;
|
||||
params.circleAngle = npc.v1.x * PI_F / HALF_TURN_DEGREES;
|
||||
params.bulletFlags = PROJECTILE_NO_WALL_COLLIDE | PROJECTILE_CHANGE_FLAGS_AFTER_TIMEOUT;
|
||||
params.changeTimeout = HELL_CHANGE_TIMEOUT;
|
||||
params.changeFlags = 0;
|
||||
npc.FireProjectiles(npc.pos, vector_make(isSlow ? HELL_SPEED : HELL_SPEED_FAST, HELL_SHOTS), PROJECTILES_RING, params);
|
||||
npc.v1.x = normalize_angle_degrees(npc.v1.x + npc.v1.y);
|
||||
frame = npc.stateFrame;
|
||||
}
|
||||
npc.stateFrame = frame + 1;
|
||||
if (npc.stateFrame < CLOG_ATTACK_FRAMES + 1) return;
|
||||
npc.sprite.Play("BulletHellEnd");
|
||||
npc.stateFrame = -1;
|
||||
}
|
||||
|
||||
// An attack of three steps: its begin (stateFrame 0), its loop (above 0) and its end (below 0), cooling down after.
|
||||
static void clog_phased_update(Entity_NPC& npc, std::string_view begin, ClogCooldown cooldown, void (*loop)(Entity_NPC&))
|
||||
{
|
||||
if (npc.stateFrame == 0)
|
||||
{
|
||||
npc.sprite.Play(begin);
|
||||
if (npc.sprite.IsFinished()) npc.stateFrame = 1;
|
||||
return;
|
||||
}
|
||||
if (npc.stateFrame > 0) return loop(npc);
|
||||
if (!npc.sprite.IsFinished()) return;
|
||||
npc.state = CLOG_IDLE;
|
||||
clog_cooldown(npc, cooldown) = CLOG_ATTACK_COOLDOWN;
|
||||
}
|
||||
|
||||
// The fart: three fart waves about it, two carrying an eternal fly while there are few.
|
||||
static void clog_fart(Entity_NPC& npc)
|
||||
{
|
||||
npc_sound_play(SOUND_CLOG_POOPSMOKE, 1, 2, 1);
|
||||
float base = random_unit() * FULL_TURN_DEGREES;
|
||||
int flies = (int)entity_query(ENTITY_ETERNALFLY, -1).size();
|
||||
for (uint32_t i = 0; i < FART_WAVES; i++)
|
||||
{
|
||||
float angle = (float)i * FART_STEP + base;
|
||||
int carriesFly = 0;
|
||||
if (i < 2 && flies < ETERNAL_FLY_LIMIT)
|
||||
{
|
||||
flies++;
|
||||
carriesFly = 1;
|
||||
}
|
||||
uint32_t seed = Random();
|
||||
auto* wave = static_cast<Entity_Effect*>(g_game->Spawn({.position = vector_add(npc.pos, vector_scale(vector_from_angle(angle), FART_REACH)),
|
||||
.spawner = &npc,
|
||||
.subType = carriesFly,
|
||||
.type = ENTITY_EFFECT,
|
||||
.variant = EFFECT_FARTWAVE,
|
||||
.seed = seed}));
|
||||
wave->rotation = angle;
|
||||
wave->Update();
|
||||
}
|
||||
}
|
||||
|
||||
// Its pick of an attack once in a while: spit when the room is empty, spin when crowded, else bullet hell or fart.
|
||||
static void clog_attack_pick(Entity_NPC& npc)
|
||||
{
|
||||
int enemies = std::max(g_game->room->GetAliveEnemiesCount(), 0);
|
||||
WeightedOutcomePicker picker;
|
||||
int spitWeight = (CLOG_SPIT_ENEMY_LIMIT - enemies) * CLOG_SPIT_WEIGHT;
|
||||
if (spitWeight > 0) picker.AddOutcomeWeight(CLOG_SPIT, spitWeight);
|
||||
int spinWeight = enemies * SPIN_WEIGHT;
|
||||
if (spinWeight < SPIN_WEIGHT_MIN || clog_cooldown(npc, COOLDOWN_SPIN)) spinWeight = 1;
|
||||
if (spinWeight > 0) picker.AddOutcomeWeight(CLOG_SPIN, spinWeight);
|
||||
picker.AddOutcomeWeight(CLOG_BULLET_HELL, clog_cooldown(npc, COOLDOWN_BULLET_HELL) ? 1 : CLOG_ATTACK_WEIGHT);
|
||||
picker.AddOutcomeWeight(CLOG_FART, clog_cooldown(npc, COOLDOWN_FART) ? 1 : CLOG_ATTACK_WEIGHT);
|
||||
|
||||
npc.state = picker.PickOutcome({Random() | 1, 5, 9, 7});
|
||||
if (npc.state == CLOG_SPIN) npc.i1 = (int)(Random() & 1);
|
||||
else if (npc.state == CLOG_BULLET_HELL)
|
||||
{
|
||||
npc.v1.x = random_unit() * FULL_TURN_DEGREES;
|
||||
float spin = (Random() & 1) == 0 ? SPIN_SLOW : SPIN_FAST;
|
||||
npc.v1.y = (Random() & 1) == 0 ? -spin : spin;
|
||||
}
|
||||
npc.stateFrame = 0;
|
||||
}
|
||||
|
||||
// 004a12f0 Clog: a toilet boss rooted in place that spits drips, spins a whirlpool, rings puke shots and farts out
|
||||
// eternal flies. Its death flushes, taking its drips with it.
|
||||
void boss_clog_update(Entity_NPC& npc)
|
||||
{
|
||||
switch (npc.state)
|
||||
{
|
||||
case NPC_STATE_INIT:
|
||||
npc.state = CLOG_IDLE;
|
||||
npc.splatColor = POOP_SPLAT_COLOR;
|
||||
npc.stateFrame = 0;
|
||||
npc.projectileDelay = 0;
|
||||
npc.targetPosition = npc.pos;
|
||||
npc.i2 = 0;
|
||||
npc.entityGridCollisionClass = GRIDCOLL_WALLS;
|
||||
break;
|
||||
case CLOG_IDLE:
|
||||
npc.sprite.Play("Idle");
|
||||
if (Random() % CLOG_ATTACK_ODDS == 0) clog_attack_pick(npc);
|
||||
break;
|
||||
case CLOG_SPIT:
|
||||
npc.sprite.Play("Spit");
|
||||
if (npc.sprite.animState.animData)
|
||||
{
|
||||
if (npc.sprite.animState.IsEventTriggered("Shoot")) clog_spit(npc);
|
||||
if (npc.sprite.animState.animData && npc.sprite.animState.isPlaying) break;
|
||||
}
|
||||
npc.state = CLOG_IDLE;
|
||||
break;
|
||||
case CLOG_SPIN:
|
||||
clog_phased_update(npc, npc.i1 == 0 ? "SpinBegin" : "SpinBegin2", COOLDOWN_SPIN, &clog_spin_update);
|
||||
break;
|
||||
case CLOG_BULLET_HELL:
|
||||
clog_phased_update(npc, "BulletHellBegin", COOLDOWN_BULLET_HELL, &clog_bullet_hell_update);
|
||||
break;
|
||||
case CLOG_FART:
|
||||
npc.sprite.Play("Fart");
|
||||
if (npc.sprite.animState.animData)
|
||||
{
|
||||
if (npc.sprite.animState.IsEventTriggered("Shoot")) clog_fart(npc);
|
||||
if (npc.sprite.animState.animData)
|
||||
{
|
||||
if (npc.sprite.animState.IsEventTriggered("Sound"))
|
||||
npc.PlaySound(SOUND_BROWNIE_LAUGH, 1, FART_LAUGH_DELAY, false, FART_LAUGH_PITCH);
|
||||
if (npc.sprite.animState.animData && npc.sprite.animState.isPlaying) break;
|
||||
}
|
||||
}
|
||||
npc.state = CLOG_IDLE;
|
||||
clog_cooldown(npc, COOLDOWN_FART) = CLOG_ATTACK_COOLDOWN;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (npc.IsFrame(2, 0))
|
||||
for (int which = COOLDOWN_UNUSED; which <= COOLDOWN_FART; which++)
|
||||
{
|
||||
uint8_t& cooldown = clog_cooldown(npc, (ClogCooldown)which);
|
||||
if (cooldown != 0) cooldown--;
|
||||
}
|
||||
npc.velocity = vector_sub(npc.targetPosition, npc.pos);
|
||||
npc.friction *= CLOG_FRICTION;
|
||||
if (!npc.isDead) return;
|
||||
|
||||
uint32_t seed = Random();
|
||||
g_game->Spawn({.position = npc.pos, .type = ENTITY_EFFECT, .variant = EFFECT_WHIRLPOOL, .seed = seed})->Update();
|
||||
npc_sound_play(SOUND_FLUSH, 1, 2, 1);
|
||||
g_manager->sfxManager.Stop(SOUND_BOSS2_WATERTHRASHING);
|
||||
for (Entity* drip : entity_query(ENTITY_DRIP, -1))
|
||||
if (drip->IsVulnerableEnemy(nullptr) && !drip->HasEntityFlags(FLAG_FRIENDLY)) static_cast<Entity_NPC*>(drip)->KillUnique();
|
||||
}
|
||||
Reference in new issue
Block a user