392 lines
16 KiB
C++
392 lines
16 KiB
C++
#include "boss_ai.h"
|
|
#include "entity_projectile.h"
|
|
#include "room_grid.h"
|
|
#include "sfx_manager.h"
|
|
#include <algorithm>
|
|
|
|
// Dingle and Dangle (variant 1), and the subtypes that change what they summon and shoot.
|
|
constexpr int DANGLE = 1;
|
|
constexpr int DINGLE_POOPER = 1;
|
|
constexpr int DINGLE_SPIDERS = 2;
|
|
constexpr int CORNY_DIP = 2;
|
|
constexpr int RED_POOP = 1;
|
|
|
|
// Dingle's states beyond the shared ones.
|
|
constexpr int DINGLE_WHISTLE = NPC_STATE_ATTACK2;
|
|
constexpr int DINGLE_DANCE = NPC_STATE_ATTACK3;
|
|
constexpr int DINGLE_BEFORE_SLIDE = NPC_STATE_ATTACK4;
|
|
constexpr int DINGLE_TIRED = NPC_STATE_SPECIAL;
|
|
|
|
constexpr ColorMod DINGLE_SPLAT_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0.25490198f, 0.16078432f, 0.13725491f}};
|
|
constexpr ColorMod DANGLE_SPLAT_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0.6f, 0.4f, 0}};
|
|
|
|
constexpr int DINGLE_IDLE_WAIT = 15;
|
|
constexpr int DANGLE_IDLE_WAIT = 30;
|
|
constexpr uint32_t ACT_ODDS = 10;
|
|
constexpr uint32_t DANGLE_ACT_ODDS = 20;
|
|
constexpr uint32_t HURT_ACT_ODDS = 5;
|
|
constexpr uint32_t DANGLE_HURT_ACT_ODDS = 10;
|
|
constexpr uint32_t WHISTLE_ODDS = 3;
|
|
constexpr uint64_t STUNNED = FLAG_CONFUSION | FLAG_FEAR | FLAG_SHRINK;
|
|
|
|
constexpr float SLIDE_KICK = 10;
|
|
constexpr float SPIDERS_SLIDE_KICK = 15;
|
|
constexpr float SLIDE_PUSH = 1;
|
|
constexpr float SPIDERS_SLIDE_PUSH = 1.5f;
|
|
constexpr float DINGLE_SLIDE_FRICTION = 0.98f;
|
|
constexpr float SLIDE_REST_FRICTION = 0.9f;
|
|
constexpr float STILL_FRICTION = 0.7f;
|
|
constexpr int SLIDE_SOUND_DELAY = 30;
|
|
constexpr uint32_t SLIDE_DROP_ODDS = 5;
|
|
constexpr int SLIDE_REST = 12;
|
|
constexpr int SLIDES = 2;
|
|
constexpr int DANGLE_SLIDES = 1;
|
|
constexpr int POOPER_SLIDES = 3;
|
|
constexpr float SLIDE_FART_REACH = 20;
|
|
constexpr float SLIDE_FART_SCALE = 0.5f;
|
|
constexpr float SLIDE_FART_INTERVAL = 2;
|
|
constexpr float SLIDE_CREEP_SCALE = 0.75f;
|
|
constexpr float SLIDE_CREEP_SCALE_SPREAD = 0.25f;
|
|
|
|
constexpr float WALL_SPLAT_REACH = 200;
|
|
constexpr float WALL_SPLAT_MARGIN = -24;
|
|
constexpr float WALL_SPLAT_SIZE = 1;
|
|
constexpr float WALL_SPLAT_SIZE_SPREAD = 2;
|
|
constexpr float WALL_SPLAT_TURN = 90;
|
|
constexpr int DINGLE_SPLAT_FRAMES = 2;
|
|
constexpr int TRAIL_SPLAT_FRAMES = 5;
|
|
constexpr float DINGLE_SPLAT_SIZE = 0.2f;
|
|
constexpr float DINGLE_SPLAT_SIZE_SPREAD = 0.5f;
|
|
|
|
constexpr float DINGLE_SHOT_SPEED = 10;
|
|
constexpr float SPRAY_FALLING_ACCEL = 0.001f;
|
|
constexpr float SPRAY_FALLING_SPEED = -1;
|
|
constexpr int SUMMON_ENEMY_LIMIT = 5;
|
|
constexpr int POOP_LIMIT = 6;
|
|
constexpr int DIP_LIMIT = 3;
|
|
constexpr float SUMMON_REACH = 60;
|
|
constexpr float SUMMON_SCATTER = 10;
|
|
constexpr float DANGLE_DIP_AHEAD = 30;
|
|
constexpr float DANGLE_DIP_KICK = 15;
|
|
constexpr float MUSIC_VOLUME = 0.6f;
|
|
constexpr int MUSIC_DELAY = 60;
|
|
constexpr int WHISTLE_DELAY = 60;
|
|
constexpr uint32_t TIRED_WAIT = 60;
|
|
constexpr uint32_t TIRED_WAIT_SPREAD = 30;
|
|
|
|
// Whether a cell may take a new poop: off the grid, empty, or under a decoration or web, and not in a crawlspace.
|
|
static bool poop_cell_is_free(int cell)
|
|
{
|
|
Room& room = *g_game->room;
|
|
GridEntity* standing = (uint32_t)cell < ROOM_GRID_CELLS ? room.gridEntities[cell] : nullptr;
|
|
bool isClear = !standing || standing->type == GRID_DECORATION || standing->type == GRID_SPIDERWEB;
|
|
return isClear && room.roomType != ROOM_DUNGEON;
|
|
}
|
|
|
|
// A blood splat under it, tinted brown, scaled 0.2 to 0.7.
|
|
static Entity_Effect* dingle_splat(Entity_NPC& npc, const ColorMod& color)
|
|
{
|
|
Entity_Effect* splat = npc.MakeSplat(random_unit() * DINGLE_SPLAT_SIZE_SPREAD + DINGLE_SPLAT_SIZE);
|
|
splat->SetColor(color, -1, COLOR_PRIORITY_DEFAULT, false, true);
|
|
return splat;
|
|
}
|
|
|
|
// Idling, until it whistles for help, dances, or slides at its target, sooner when hurt. A calm Delirium form idles.
|
|
static void dingle_idle(Entity_NPC& npc)
|
|
{
|
|
npc.sprite.Play("Idle");
|
|
if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) return;
|
|
|
|
bool isDangle = npc.variant == DANGLE;
|
|
npc.stateFrame += npc_ticks_get(npc);
|
|
if (npc.stateFrame <= (isDangle ? DANGLE_IDLE_WAIT : DINGLE_IDLE_WAIT)) return;
|
|
if (Random() % (isDangle ? DANGLE_ACT_ODDS : ACT_ODDS) != 0)
|
|
{
|
|
if (npc.pendingDamage <= 0) return;
|
|
if (Random() % (isDangle ? DANGLE_HURT_ACT_ODDS : HURT_ACT_ODDS) != 0) return;
|
|
}
|
|
|
|
if (Random() % WHISTLE_ODDS == 0) npc.state = DINGLE_WHISTLE;
|
|
else if ((Random() & 1) == 0 && !npc.HasEntityFlags(STUNNED)) npc.state = DINGLE_BEFORE_SLIDE;
|
|
else npc.state = DINGLE_DANCE;
|
|
}
|
|
|
|
// The slide's kick toward its target: Dingle may leave a poop and Dangle a corn mine where it starts.
|
|
static void slide_kick(Entity_NPC& npc)
|
|
{
|
|
Vector aim = vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos));
|
|
float kick = npc.subtype == DINGLE_SPIDERS ? SPIDERS_SLIDE_KICK : SLIDE_KICK;
|
|
npc.velocity = vector_add(npc.velocity, vector_scale(aim, kick));
|
|
npc.PlaySound(SOUND_FART_GURG, 1, SLIDE_SOUND_DELAY, false, 1);
|
|
if (npc.i1 != 0 || Random() % SLIDE_DROP_ODDS != 0) return;
|
|
|
|
if (npc.variant == 0)
|
|
{
|
|
Room& room = *g_game->room;
|
|
int cell = room.GetGridIndex(npc.pos);
|
|
if (poop_cell_is_free(cell)) room.SpawnGridEntity(cell, GRID_POOP, 0, npc.dropRNG.Next(), 0);
|
|
}
|
|
else if (npc.variant == DANGLE)
|
|
g_game->Spawn({.position = npc.pos, .spawner = &npc, .type = ENTITY_CORN_MINE, .seed = Random()});
|
|
npc.PlaySound(SOUND_FART, 1, 2, false, 1);
|
|
}
|
|
|
|
// Dangle's slide trail: a fart every other tick and a creep puddle, green when poisoned, white when slowed.
|
|
static void dangle_trail(Entity_NPC& npc)
|
|
{
|
|
if (npc.GetIntervalTicks(SLIDE_FART_INTERVAL, 0) != 0)
|
|
game_fart({.position = npc.pos, .source = &npc, .radius = npc.size + SLIDE_FART_REACH, .scale = SLIDE_FART_SCALE});
|
|
|
|
int creep = npc.HasEntityFlags(FLAG_POISON) ? EFFECT_CREEP_GREEN : EFFECT_CREEP_SLIPPERY_BROWN;
|
|
if (npc.HasEntityFlags(FLAG_SLOW)) creep = EFFECT_CREEP_WHITE;
|
|
Entity* puddle = g_game->Spawn(
|
|
{.position = npc.pos, .spawner = &npc, .type = ENTITY_EFFECT, .variant = creep, .seed = Random()});
|
|
float size = random_unit() * SLIDE_CREEP_SCALE_SPREAD + SLIDE_CREEP_SCALE;
|
|
puddle->sprite.scale = vector_make(size, size);
|
|
puddle->Update();
|
|
}
|
|
|
|
// Hitting a wall: it picks a new random spot and splashes a splat on the wall behind the hit, turned to face out.
|
|
static void slide_wall_hit(Entity_NPC& npc)
|
|
{
|
|
Room& room = *g_game->room;
|
|
npc.targetPosition = room.GetRandomPosition(0);
|
|
npc.PlaySound(SOUND_MEAT_JUMPS, 1, 2, false, 1);
|
|
|
|
float margin = random_unit() * WALL_SPLAT_MARGIN;
|
|
Vector behind = vector_add(npc.pos, vector_scale(npc.gridCollisionNormal, WALL_SPLAT_REACH));
|
|
Vector spot = room.GetClampedPositionImpl(behind, margin, margin, margin, margin);
|
|
GridEntity* wall = room_grid_entity_at(spot);
|
|
if (!wall || (wall->type != GRID_WALL && wall->type != GRID_DOOR)) return;
|
|
|
|
Entity_Effect* splat = npc.MakeSplat(random_unit() * WALL_SPLAT_SIZE_SPREAD + WALL_SPLAT_SIZE);
|
|
splat->pos = spot;
|
|
splat->SetColor(npc.splatColor, -1, COLOR_PRIORITY_DEFAULT, false, true);
|
|
splat->AddEntityFlags(FLAG_RENDER_WALL);
|
|
splat->sprite.rotation = vector_angle(vector_cardinal(npc.gridCollisionNormal)) + WALL_SPLAT_TURN;
|
|
splat->Update();
|
|
}
|
|
|
|
// The slide: a short rest between slides, then a kick at its target on Slide and a push along while it lasts. Each
|
|
// slide ends at its animation's end or when stunned, up to its slides in a row before it tires.
|
|
static void dingle_slide(Entity_NPC& npc)
|
|
{
|
|
if (npc.stateFrame != 0)
|
|
{
|
|
npc.friction *= SLIDE_REST_FRICTION;
|
|
npc.stateFrame = std::max(npc.stateFrame - npc_ticks_get(npc), 0);
|
|
if (npc.stateFrame == 0) npc.sprite.Play("Slide", PLAY_FORCED);
|
|
return;
|
|
}
|
|
|
|
npc.sprite.Play("Slide");
|
|
if (npc.sprite.IsEventTriggered("Slide")) slide_kick(npc);
|
|
npc.friction *= DINGLE_SLIDE_FRICTION;
|
|
if (npc.sprite.WasEventTriggered("Slide"))
|
|
{
|
|
Vector push = vector_resized(npc.velocity, npc.subtype == DINGLE_SPIDERS ? SPIDERS_SLIDE_PUSH : SLIDE_PUSH);
|
|
if (npc.friction != 0)
|
|
npc.velocity = vector_add(npc.velocity, vector_scale(push, npc.speedMultiplier / npc.friction));
|
|
if (npc.variant == DANGLE) dangle_trail(npc);
|
|
}
|
|
npc.sprite.isFlipX = npc.velocity.x > 0;
|
|
if (npc.IsFrame(DINGLE_SPLAT_FRAMES, (int)npc.index)) dingle_splat(npc, DINGLE_SPLAT_COLOR);
|
|
|
|
if (!npc.sprite.IsPlaying() || npc.HasEntityFlags(STUNNED))
|
|
{
|
|
int slides = npc.variant == DANGLE ? DANGLE_SLIDES : SLIDES;
|
|
if (npc.subtype == DINGLE_POOPER) slides = POOPER_SLIDES;
|
|
else if (npc.subtype == DINGLE_SPIDERS) slides = 0;
|
|
if (npc.i1 < slides)
|
|
{
|
|
npc.stateFrame = (int)(Random() & 3) + SLIDE_REST;
|
|
npc.i1++;
|
|
}
|
|
else
|
|
{
|
|
npc.state = DINGLE_TIRED;
|
|
npc.stateFrame = 0;
|
|
npc.i1 = 0;
|
|
}
|
|
}
|
|
if (npc.isCollidesWithGrid) slide_wall_hit(npc);
|
|
}
|
|
|
|
// The spit on Shoot: three shots at its target (puke, or blood for the pooper, corn for Dangle) or, for the spider
|
|
// Dingle, a ring of eight. It faces its target once it spat, and idles when done.
|
|
static void dingle_shoot(Entity_NPC& npc)
|
|
{
|
|
npc.sprite.Play("Spit");
|
|
Vector toTarget = vector_sub(npc.GetPlayerTarget()->pos, npc.pos);
|
|
if (npc.sprite.IsEventTriggered("Shoot"))
|
|
{
|
|
ProjectileParams params;
|
|
params.variant = npc.variant == DANGLE ? PROJECTILE_CORN : npc.subtype == DINGLE_POOPER ? PROJECTILE_NORMAL
|
|
: PROJECTILE_PUKE;
|
|
if (npc.subtype == DINGLE_SPIDERS)
|
|
{
|
|
params.fallingAccelModifier = SPRAY_FALLING_ACCEL;
|
|
params.fallingSpeedModifier = SPRAY_FALLING_SPEED;
|
|
npc.FireProjectiles(npc.pos, vector_make(DINGLE_SHOT_SPEED, 0), PROJECTILES_EIGHT, params);
|
|
}
|
|
else
|
|
npc.FireProjectiles(npc.pos, vector_scale(vector_normalized(toTarget), DINGLE_SHOT_SPEED), PROJECTILES_THREE,
|
|
params);
|
|
npc.PlaySound(SOUND_FAT_WIGGLE, 1, 2, false, 1);
|
|
}
|
|
if (npc.sprite.WasEventTriggered("Shoot")) npc.sprite.isFlipX = toTarget.x > 0;
|
|
if (npc.sprite.IsPlaying()) return;
|
|
npc.state = NPC_STATE_IDLE;
|
|
npc.stateFrame = 0;
|
|
}
|
|
|
|
// A spot near it a summon takes: a free pickup spot within reach, scattered a little.
|
|
static Vector summon_spot(Entity_NPC& npc)
|
|
{
|
|
Vector free = room_free_pickup_position_find({.position = npc.pos, .step = SUMMON_REACH});
|
|
Vector scatter = random_direction();
|
|
float spread = random_unit();
|
|
return vector_add(vector_scale(vector_scale(scatter, spread), SUMMON_SCATTER), free);
|
|
}
|
|
|
|
// Dangle's corny dip, flung out ahead toward its target and already moving.
|
|
static void dangle_dip_spawn(Entity_NPC& npc)
|
|
{
|
|
Vector aim = vector_normalized(vector_sub(npc.CalcTargetPosition(0), npc.pos));
|
|
uint32_t seed = Random();
|
|
Vector scatter = random_direction();
|
|
float spread = random_unit() * SUMMON_SCATTER;
|
|
Vector spot = vector_add(vector_add(vector_scale(scatter, spread), vector_scale(aim, DANGLE_DIP_AHEAD)), npc.pos);
|
|
auto* dip = static_cast<Entity_NPC*>(g_game->Spawn(
|
|
{.position = spot, .spawner = &npc, .type = ENTITY_DIP, .variant = CORNY_DIP, .seed = seed}));
|
|
if (dip->friction != 0)
|
|
dip->velocity = vector_add(dip->velocity, vector_scale(aim, DANGLE_DIP_KICK * dip->speedMultiplier / dip->friction));
|
|
dip->ClearEntityFlags(FLAG_APPEAR);
|
|
dip->Update();
|
|
dip->state = NPC_STATE_MOVE;
|
|
}
|
|
|
|
// A spider near it, for the spider Dingle's whistle.
|
|
static void spider_spawn(Entity_NPC& npc)
|
|
{
|
|
uint32_t seed = Random();
|
|
Vector spot = summon_spot(npc);
|
|
g_game->Spawn({.position = spot, .spawner = &npc, .type = ENTITY_SPIDER, .seed = seed});
|
|
}
|
|
|
|
// The whistle's summons on Spawn: one or two dips (three at most in all for a Delirium form), a red poop for the
|
|
// pooper (six at most), or one or two spiders for the spider Dingle. Only while the room has few enemies, except that
|
|
// the check lets everything but the pooper through. False when nothing was summoned for that.
|
|
static bool whistle_summon(Entity_NPC& npc)
|
|
{
|
|
Room& room = *g_game->room;
|
|
bool isFewEnemies = room.GetAliveEnemiesCount() < SUMMON_ENEMY_LIMIT;
|
|
if (!((isFewEnemies && npc.subtype != DINGLE_POOPER) || npc.i2 < POOP_LIMIT)) return false;
|
|
|
|
if (npc.subtype == 0)
|
|
{
|
|
int count = (int)(Random() & 1) + 1;
|
|
if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM))
|
|
count = std::min(count, DIP_LIMIT - npc.CountRelatedEntities(ENTITY_DIP, 0, nullptr));
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
if (npc.variant == DANGLE)
|
|
{
|
|
dangle_dip_spawn(npc);
|
|
continue;
|
|
}
|
|
uint32_t seed = Random();
|
|
Vector spot = summon_spot(npc);
|
|
g_game->Spawn({.position = spot, .spawner = &npc, .type = ENTITY_DIP, .seed = seed})->Update();
|
|
}
|
|
}
|
|
else if (npc.subtype == DINGLE_POOPER)
|
|
{
|
|
int cell = room.GetGridIndex(room_free_pickup_position_find({.position = npc.pos, .step = SUMMON_REACH}));
|
|
if (poop_cell_is_free(cell))
|
|
{
|
|
room.SpawnGridEntity(cell, GRID_POOP, RED_POOP, npc.dropRNG.Next(), 0);
|
|
npc.i2++;
|
|
}
|
|
}
|
|
else if (npc.subtype == DINGLE_SPIDERS)
|
|
{
|
|
spider_spawn(npc);
|
|
if ((Random() & 1) == 0) spider_spawn(npc);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// Dingle (and Dangle, variant 1) idles, whistles up dips (or poop or spiders by subtype), dances, and slides at its
|
|
// target in bursts before it tires. Each whistle or dance ends in a spit.
|
|
static void dingle_act(Entity_NPC& npc)
|
|
{
|
|
switch (npc.state)
|
|
{
|
|
case NPC_STATE_IDLE:
|
|
return dingle_idle(npc);
|
|
case NPC_STATE_MOVE:
|
|
return dingle_slide(npc);
|
|
case NPC_STATE_ATTACK:
|
|
return dingle_shoot(npc);
|
|
case DINGLE_WHISTLE:
|
|
npc.sprite.Play("Whistle");
|
|
npc.PlaySound(npc.variant == DANGLE ? SOUND_DANGLE_WHISTLE : SOUND_WHISTLE, 1, WHISTLE_DELAY, false, 1);
|
|
if (npc.sprite.IsEventTriggered("Spawn") && whistle_summon(npc))
|
|
npc.PlaySound(SOUND_MEAT_JUMPS, MUSIC_VOLUME, 2, false, 1);
|
|
break;
|
|
case DINGLE_DANCE:
|
|
npc.sprite.Play("Dance");
|
|
npc.PlaySound(SOUND_MEAT_JUMPS, MUSIC_VOLUME, MUSIC_DELAY, false, 1);
|
|
break;
|
|
case DINGLE_BEFORE_SLIDE:
|
|
npc.sprite.Play("BeforeSlide");
|
|
npc.PlaySound(SOUND_MEAT_JUMPS, MUSIC_VOLUME, MUSIC_DELAY, false, 1);
|
|
if (npc.sprite.IsPlaying()) return;
|
|
npc.state = NPC_STATE_MOVE;
|
|
npc.stateFrame = 0;
|
|
return;
|
|
case DINGLE_TIRED:
|
|
{
|
|
npc.sprite.Play("Tired");
|
|
uint32_t wait = Random() % TIRED_WAIT_SPREAD + TIRED_WAIT;
|
|
if (npc.variant == DANGLE) wait /= 2;
|
|
if (npc.stateFrame++ <= (int)wait) return;
|
|
npc.state = NPC_STATE_IDLE;
|
|
npc.stateFrame = 0;
|
|
return;
|
|
}
|
|
default:
|
|
return;
|
|
}
|
|
if (npc.sprite.IsPlaying()) return;
|
|
npc.state = NPC_STATE_ATTACK;
|
|
npc.stateFrame = 0;
|
|
}
|
|
|
|
// 004855b0 NpcAI::ENTITY_DINGLE: Dingle and Dangle. The pooper (subtype 1) shrugs off poop damage. Every fifth frame
|
|
// it leaves a splat, and it slows down hard unless sliding.
|
|
void boss_dingle_update(Entity_NPC& npc)
|
|
{
|
|
if (npc.state == NPC_STATE_INIT)
|
|
{
|
|
npc.state = NPC_STATE_IDLE;
|
|
npc.stateFrame = 0;
|
|
npc.splatColor = npc.variant == DANGLE ? DANGLE_SPLAT_COLOR : DINGLE_SPLAT_COLOR;
|
|
npc.i1 = 0;
|
|
npc.i2 = 0;
|
|
return;
|
|
}
|
|
|
|
npc.sprite.isFlipX = false;
|
|
if (npc.subtype == DINGLE_POOPER)
|
|
for (DamageEvent& hit : npc.damageEvents)
|
|
if (hit.damageFlags & DAMAGE_POOP) hit.damage = 0;
|
|
dingle_act(npc);
|
|
|
|
bool isTrailFrame = (g_game->frameCount + (int)npc.index) % TRAIL_SPLAT_FRAMES == 0;
|
|
if (!npc.HasEntityFlags(FLAG_INTERPOLATION_UPDATE) && !g_game->IsPaused() && isTrailFrame)
|
|
dingle_splat(npc, npc.splatColor);
|
|
if (npc.state != NPC_STATE_MOVE) npc.friction *= STILL_FRICTION;
|
|
}
|