Curation round 12: basement enemies, projectiles, tear flags, lighting and blend modes, actives, boss deaths, familiars, shops and secret rooms
This commit is contained in:
1 parent
698eeb74e9
commit
f8ce24fc6c
146 files changed
+16389
-3104
No files matched your search
+431
-85
@@ -1,21 +1,42 @@
|
||||
#include "npc_ai.h"
|
||||
#include "npc_basement.h"
|
||||
#include "entity_bomb.h"
|
||||
#include "entity_config.h"
|
||||
#include "entity_player.h"
|
||||
#include "game.h"
|
||||
#include "grid_entity.h"
|
||||
#include "room.h"
|
||||
#include "score_sheet.h"
|
||||
#include <algorithm>
|
||||
|
||||
constexpr int ENTITY_ISAAC_BOSS = 102;
|
||||
constexpr int ENTITY_ORBIT_SPAWNER = 873;
|
||||
// The fly kin this AI runs: the fly, Pooter, attack fly, the Sucker's family, Moter, the level 2 fly, the full fly and
|
||||
// the fly bomb.
|
||||
constexpr int ENTITY_MOTER = 80;
|
||||
constexpr int ENTITY_FLY_L2 = 214;
|
||||
constexpr int ENTITY_FULL_FLY = 249;
|
||||
constexpr int SPAWNER_UNBOUNDED = 67;
|
||||
constexpr int COLLECTIBLE_SKATOLE_ID = 9;
|
||||
constexpr int POOTER_TRIPLE_VARIANT = 2;
|
||||
constexpr int POOTER_TWO_SHOT_VARIANT = 1;
|
||||
|
||||
// The fly types this file covers: the fly, the Pooter and the attack fly.
|
||||
constexpr int ENTITY_FLY = 13;
|
||||
constexpr int ENTITY_POOTER = 14;
|
||||
constexpr int ENTITY_ATTACKFLY = 18;
|
||||
// The Sucker's variants: the Sucker, Spit, Soul Sucker, Ink, Mama Fly, the Bulbs and the Bloodfly.
|
||||
constexpr int SUCKER_SPIT = 1;
|
||||
constexpr int SUCKER_SOUL = 2;
|
||||
constexpr int SUCKER_INK = 3;
|
||||
constexpr int SUCKER_MAMA_FLY = 4;
|
||||
constexpr int SUCKER_BULB_BLACK = 6;
|
||||
constexpr int POOTER_TWO_SHOT_VARIANT = 1;
|
||||
constexpr int POOTER_TRIPLE_VARIANT = 2;
|
||||
constexpr int FLY_BOMB_ORBITING = 1;
|
||||
constexpr int FLY_BOMB_BOMB_VARIANT = 14;
|
||||
|
||||
constexpr ColorMod SPIT_SPLAT_COLOR = {{0.5f, 0.5f, 0.5f, 1}, {0, 0, 0, 0}, {-0.19607845f, 0.50980395f, 0.19607845f}};
|
||||
constexpr ColorMod INK_SPLAT_COLOR = {{0.02f, 0.05f, 0.05f, 1}, {0, 0, 0, 0}, {0, 0, 0}};
|
||||
constexpr ColorMod FLY_BOMB_SPLAT_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0.11764707f, 0.11764707f, 0.11764707f}};
|
||||
|
||||
// The Suckers' death shots: a plus, or the Bloodfly's ring of six.
|
||||
constexpr float SUCKER_SHOT_SPEED = 8;
|
||||
constexpr float SUCKER_HARD_SHOT_SPEED = 10;
|
||||
constexpr float BLOODFLY_RING_SHOTS = 6;
|
||||
constexpr float BLOODFLY_SHOT_SCALE = 1.8f;
|
||||
constexpr float MOTER_SPLIT_SPEED = 10;
|
||||
constexpr float MOTER_OVERKILL = -20;
|
||||
|
||||
// How a Pooter shoots: when its target is in range (checked every 7 frames), its cooldowns, and its shot.
|
||||
constexpr float POOTER_RANGE = 200;
|
||||
@@ -27,14 +48,26 @@ constexpr float POOTER_HARD_SHOT_SPEED = 10;
|
||||
constexpr float POOTER_FRICTION = 0.8f;
|
||||
constexpr float POOTER_DRIFT_DECAY = 0.7f;
|
||||
constexpr int SOUND_POOTER_SHOOT = 178;
|
||||
constexpr uint64_t PROJECTILE_FLAG_54 = 1ull << 54;
|
||||
|
||||
// The super Pooter's shot.
|
||||
constexpr float SUPER_POOTER_SCALE = 1.4f;
|
||||
constexpr float SUPER_POOTER_FALL_ACCEL = -0.15f;
|
||||
constexpr float SUPER_POOTER_FALL_SPEED = 1;
|
||||
constexpr float SUPER_POOTER_SPREAD = 1.2f;
|
||||
|
||||
// The fly bomb's cannonball: shot at 10, it deploys after 45 frames or below 5, bouncing off walls. Its orbiting kind
|
||||
// circles its parent at 40, and drops a bomb that blows 46 to 60 frames later.
|
||||
constexpr float CANNONBALL_SPEED = 10;
|
||||
constexpr float CANNONBALL_MASS = 50;
|
||||
constexpr int CANNONBALL_FRAMES = 45;
|
||||
constexpr float CANNONBALL_MIN_SPEED = 5;
|
||||
constexpr float CANNONBALL_FRICTION = 0.85f;
|
||||
constexpr int SOUND_CANNONBALL_BOUNCE = 40;
|
||||
constexpr float ORBIT_TURN = 5;
|
||||
constexpr float ORBIT_RADIUS = 40;
|
||||
constexpr float ORBIT_DROP_SPEED = 15;
|
||||
constexpr int BOMB_FUSE = 60;
|
||||
constexpr int BOMB_FUSE_RANGE = 15;
|
||||
constexpr int BOMB_APPEAR_FRAME = 8;
|
||||
|
||||
// How a fly wanders: the spot it eyes (and a poop or fireplace there), its drift and the bounds it stays within.
|
||||
constexpr int FLY_RETARGET_FRAMES = 3;
|
||||
constexpr float FLY_WANDER = 240;
|
||||
@@ -42,6 +75,7 @@ constexpr int FLY_FIREPLACE_ODDS = 100;
|
||||
constexpr int FLY_POOP_ODDS = 1000;
|
||||
constexpr int FLY_CHASE_ODDS = 5;
|
||||
constexpr float FLY_CHASE_SPEED = 0.7f;
|
||||
constexpr float FLY_STEER_SPEED = 1.1f;
|
||||
constexpr float FLY_DRIFT_KEEP = 0.4f;
|
||||
constexpr float FLY_DRIFT_NEW = 0.6f;
|
||||
constexpr float FLY_DRIFT_STEP = 0.06f;
|
||||
@@ -53,6 +87,15 @@ constexpr float FLY_FRICTION = 0.6f;
|
||||
constexpr int FLY_DRIFT_PERIOD = 4;
|
||||
constexpr int FLY_STEER_PERIOD = 3;
|
||||
|
||||
// How a kin fly circles its parent: within 260, at 65 give or take a slow sway of 5.
|
||||
constexpr float PARENT_RANGE = 260;
|
||||
constexpr float PARENT_ORBIT = 65;
|
||||
constexpr float PARENT_SWAY = 5;
|
||||
constexpr float PARENT_SWAY_RATE = 0.02f;
|
||||
constexpr float PARENT_PULL = 0.5f;
|
||||
constexpr float PARENT_SPIN = 0.2f;
|
||||
constexpr float PARENT_SPIN_DAMP = 2;
|
||||
|
||||
// How a fly flees what it fears: within 400 (at full distance under 200), aimed in a random arc around away.
|
||||
constexpr float FLEE_RANGE = 400;
|
||||
constexpr float FLEE_NEAR = 200;
|
||||
@@ -61,49 +104,172 @@ constexpr float FLEE_ARC = 220;
|
||||
constexpr float FLEE_ARC_BLOCKED = 360;
|
||||
constexpr uint64_t FLEE_BLOCKERS = FLAG_FREEZE | FLAG_CHARM | FLAG_CONFUSION | FLAG_MIDAS_FREEZE;
|
||||
|
||||
// How it flies to its target: how near it stops (an attack fly nearer), and how hard it pulls.
|
||||
// How it flies to its target: how near it stops (the kin nearer, Suckers and big flies nearer still), and how hard
|
||||
// it pulls. The zigzagging kin pull twice as hard, and bounce off walls now and then.
|
||||
constexpr float TARGET_REACH = 30;
|
||||
constexpr float TARGET_REACH_ATTACK = 25;
|
||||
constexpr float TARGET_REACH_KIN = 25;
|
||||
constexpr float TARGET_REACH_BIG = 15;
|
||||
constexpr float TARGET_PULL = 0.08f;
|
||||
constexpr float TARGET_PULL_MAX = 1.2f;
|
||||
constexpr float TARGET_Y_SHARE = 0.5f;
|
||||
constexpr float TARGET_PARENT_SHARE = 0.2f;
|
||||
constexpr float CONTROLLER_REACH = 100;
|
||||
constexpr float BIG_FLY_SCALE = 1.1f;
|
||||
constexpr float KILL_ON_TOUCH_FRICTION = 0.9f;
|
||||
constexpr float CHARGE_INTERVAL = 2;
|
||||
constexpr float REGENERATION_FRAMES = 60;
|
||||
constexpr uint32_t GRID_COLLISION_WALL = 4;
|
||||
constexpr int BOUNCE_ODDS = 3;
|
||||
constexpr float BOUNCE_MIN = 2;
|
||||
constexpr float BOUNCE_RANGE = 1.5f;
|
||||
constexpr float BOUNCE_DECAY = 0.9f;
|
||||
|
||||
// The fly's sprite: Fly while it flies (restarted when it stopped), the Pooter's back to Fly after its attack.
|
||||
static bool is_kin(int type)
|
||||
{
|
||||
return type == ENTITY_ATTACKFLY || type == ENTITY_MOTER || type == ENTITY_FLY_L2 || type == ENTITY_FULL_FLY ||
|
||||
type == ENTITY_FLY_BOMB;
|
||||
}
|
||||
|
||||
static bool is_zigzag(int type)
|
||||
{
|
||||
return type == ENTITY_FLY_L2 || type == ENTITY_FULL_FLY || type == ENTITY_FLY_BOMB;
|
||||
}
|
||||
|
||||
// The first frame: idle, with a Spit's green, an Ink's black and a fly bomb's dark blood. The orbiting fly bomb is
|
||||
// out of reach.
|
||||
static void fly_init(Entity_NPC& npc)
|
||||
{
|
||||
npc.entityGridCollisionClass = GRIDCOLL_WALLS;
|
||||
npc.v2 = {};
|
||||
npc.state = NPC_STATE_IDLE;
|
||||
if (npc.type == ENTITY_SUCKER && npc.variant == SUCKER_SPIT) npc.splatColor = SPIT_SPLAT_COLOR;
|
||||
else if (npc.type == ENTITY_SUCKER && npc.variant == SUCKER_INK) npc.splatColor = INK_SPLAT_COLOR;
|
||||
else if (npc.type == ENTITY_FLY_BOMB)
|
||||
{
|
||||
npc.splatColor = FLY_BOMB_SPLAT_COLOR;
|
||||
if (npc.variant == FLY_BOMB_ORBITING)
|
||||
{
|
||||
npc.AddEntityFlags(FLAG_NO_STATUS_EFFECTS | FLAG_NO_TARGET);
|
||||
npc.isInvincible = true;
|
||||
npc.entityGridCollisionClass = GRIDCOLL_NONE;
|
||||
}
|
||||
}
|
||||
npc.i1 = 0;
|
||||
}
|
||||
|
||||
// A dying Sucker bursts by its variant: a plus of shots, the Spit's arcing puddle shot, or the Bloodfly's ring.
|
||||
static void sucker_death(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.HasEntityFlags(FLAG_SHRINK)) return;
|
||||
|
||||
switch (npc.variant)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
ProjectileParams params;
|
||||
float speed = game_is_hard_mode() ? SUCKER_HARD_SHOT_SPEED : SUCKER_SHOT_SPEED;
|
||||
npc.FireProjectiles(npc.pos, vector_make(speed, 0), PROJECTILES_PLUS, params);
|
||||
break;
|
||||
}
|
||||
case SUCKER_SPIT:
|
||||
reconstruction_missing("npc_fly_update 00506bd0: a Spit's death shot (FireBossProjectiles' projectile)");
|
||||
case SUCKER_SOUL:
|
||||
reconstruction_missing("npc_fly_update 00506bd0: a Soul Sucker's death (spawn_tracer_effect198)");
|
||||
case SUCKER_INK:
|
||||
reconstruction_missing("npc_fly_update 00506bd0: an Ink's death splash");
|
||||
case SUCKER_BLOODFLY:
|
||||
{
|
||||
ProjectileParams params;
|
||||
params.scale = BLOODFLY_SHOT_SCALE;
|
||||
params.bulletFlags = PROJECTILE_BURST8;
|
||||
params.circleAngle = 0;
|
||||
npc.FireProjectiles(npc.pos, vector_make(SUCKER_SHOT_SPEED, BLOODFLY_RING_SHOTS), PROJECTILES_RING, params);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A Moter killed outright splits into two attack flies, flung apart across its target's line.
|
||||
static void moter_split(Entity_NPC& npc)
|
||||
{
|
||||
Vector toward = vector_sub(npc.GetPlayerTarget()->pos, npc.pos);
|
||||
float distance = vector_length(toward);
|
||||
Vector fling = distance > 0
|
||||
? vector_make(-(toward.y / distance) * MOTER_SPLIT_SPEED, toward.x / distance * MOTER_SPLIT_SPEED)
|
||||
: vector_scale(random_direction(), MOTER_SPLIT_SPEED);
|
||||
|
||||
uint32_t seed = Random();
|
||||
Entity* first = g_game->Spawn({.position = vector_add(npc.pos, fling),
|
||||
.velocity = fling,
|
||||
.spawner = &npc,
|
||||
.type = ENTITY_ATTACKFLY,
|
||||
.seed = seed});
|
||||
seed = Random();
|
||||
Entity* second = g_game->Spawn({.position = vector_sub(npc.pos, fling),
|
||||
.velocity = vector_sub({}, fling),
|
||||
.spawner = &npc,
|
||||
.type = ENTITY_ATTACKFLY,
|
||||
.seed = seed});
|
||||
first->ClearEntityFlags(FLAG_APPEAR);
|
||||
second->ClearEntityFlags(FLAG_APPEAR);
|
||||
first->Update();
|
||||
second->Update();
|
||||
}
|
||||
|
||||
// The fly bomb's bomb, lit to blow 46 to 60 frames later.
|
||||
static void fly_bomb_drop(Entity_NPC& npc, Entity* parent)
|
||||
{
|
||||
Entity_Bomb* bomb = static_cast<Entity_Bomb*>(g_game->Spawn({.position = npc.pos,
|
||||
.velocity = npc.velocity,
|
||||
.spawner = &npc,
|
||||
.type = ENTITY_BOMB,
|
||||
.variant = FLY_BOMB_BOMB_VARIANT,
|
||||
.seed = Random()}));
|
||||
bomb->sprite.Play("Appear");
|
||||
if (bomb->sprite.animState.animData) bomb->sprite.animState.SetFrameFloat(BOMB_APPEAR_FRAME);
|
||||
bomb->parent = parent;
|
||||
bomb->SetExplosionCountdown(BOMB_FUSE - (int)(Random() % BOMB_FUSE_RANGE));
|
||||
}
|
||||
|
||||
// The fly's sprite: Fly while it flies (restarted when it stopped, a Sucker facing its way), the Pooter's back to
|
||||
// Fly after its attack, the kin idling.
|
||||
static void fly_animation_update(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.type == ENTITY_POOTER)
|
||||
int type = npc.type;
|
||||
if (type == ENTITY_FLY || type == ENTITY_MOTER || type == ENTITY_SUCKER || type == ENTITY_ATTACKFLY)
|
||||
{
|
||||
const AnimationData* current = npc.sprite.animState.animData;
|
||||
bool isFlying = current && current->name == "Fly" && (!current->isLooping || npc.sprite.animState.isPlaying);
|
||||
if (!isFlying && npc.sprite.SetAnimation("Fly", SWITCH_KEEP_FRAME))
|
||||
{
|
||||
npc.sprite.animState.Rewind();
|
||||
npc.sprite.animState.isPlaying = true;
|
||||
}
|
||||
if (type == ENTITY_SUCKER) npc.sprite.isFlipX = npc.velocity.x < 0;
|
||||
}
|
||||
else if (type == ENTITY_POOTER)
|
||||
{
|
||||
bool isAttackDone = !npc.sprite.animState.animData || !npc.sprite.animState.isPlaying;
|
||||
if (npc.state < NPC_STATE_SUICIDE) npc.sprite.Play("Fly");
|
||||
else if (npc.state == NPC_STATE_ATTACK && isAttackDone) npc.state = NPC_STATE_MOVE;
|
||||
return;
|
||||
}
|
||||
|
||||
const AnimationData* current = npc.sprite.animState.animData;
|
||||
bool isFlying = current && current->name == "Fly" && (!current->isLooping || npc.sprite.animState.isPlaying);
|
||||
if (!isFlying && npc.sprite.SetAnimation("Fly", SWITCH_KEEP_FRAME))
|
||||
{
|
||||
npc.sprite.animState.Rewind();
|
||||
npc.sprite.animState.isPlaying = true;
|
||||
}
|
||||
else if (type == ENTITY_FLY_L2 || type == ENTITY_FULL_FLY || (type == ENTITY_FLY_BOMB && npc.state == NPC_STATE_IDLE))
|
||||
npc.sprite.Play("Idle");
|
||||
}
|
||||
|
||||
// A fly that crosses a poop (one chance in a thousand a frame) eats it and becomes a Pooter.
|
||||
// A fly that crosses a poop (one chance in a thousand a frame) eats some of it and becomes a Pooter.
|
||||
static void fly_poop_eat(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.type != ENTITY_FLY || Random() % FLY_POOP_ODDS != 0) return;
|
||||
|
||||
Room& room = *g_game->room;
|
||||
int gridIndex = room.GetGridIndex(npc.pos);
|
||||
GridEntity* grid = gridIndex >= 0 ? room.GetGridEntity(gridIndex) : nullptr;
|
||||
if (grid && grid->type == GRID_POOP) reconstruction_missing("npc_fly_update 00506bd0: a fly eating poop");
|
||||
GridEntity* grid = gridIndex >= 0 && gridIndex < ROOM_GRID_CELLS ? room.gridEntities[gridIndex] : nullptr;
|
||||
if (!grid || grid->type != GRID_POOP) return;
|
||||
|
||||
grid->Hurt(1, EntityRef(&npc));
|
||||
npc.Morph(ENTITY_POOTER, 0, 0, -1);
|
||||
npc.health = npc.maxHitPoints;
|
||||
}
|
||||
|
||||
// A Pooter in range of its target turns to it and shoots on its Shoot event: a single shot, two for the twin
|
||||
@@ -137,7 +303,7 @@ static void pooter_attack_update(Entity_NPC& npc)
|
||||
params.fallingAccelModifier = SUPER_POOTER_FALL_ACCEL;
|
||||
params.fallingSpeedModifier = SUPER_POOTER_FALL_SPEED;
|
||||
params.spread = SUPER_POOTER_SPREAD;
|
||||
params.bulletFlags = PROJECTILE_FLAG_54;
|
||||
params.bulletFlags = PROJECTILE_BACK_SPLIT;
|
||||
params.isFallingKept = true;
|
||||
mode = PROJECTILES_FOUR;
|
||||
speed = POOTER_SHOT_SPEED;
|
||||
@@ -155,32 +321,104 @@ static void pooter_attack_update(Entity_NPC& npc)
|
||||
}
|
||||
}
|
||||
|
||||
// Every third frame a fly picks where it heads: an attack fly (or any under Skatole) its target, a plain fly or
|
||||
// Pooter eyes a random spot and its poop, or now and then a fireplace, though it heads nowhere in the end.
|
||||
// The fly bomb shot as a cannonball flies at 10 until it slows or 45 frames pass, bouncing off walls, then deploys.
|
||||
// The orbiting one circles its parent, dropping its bomb once the parent is gone. Whether the update ends here.
|
||||
static bool fly_bomb_update(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.state == NPC_STATE_SPECIAL)
|
||||
{
|
||||
if (npc.stateFrame == -1)
|
||||
{
|
||||
npc.friction *= CANNONBALL_FRICTION;
|
||||
if (!npc.sprite.animState.animData || !npc.sprite.animState.isPlaying) npc.state = NPC_STATE_IDLE;
|
||||
return true;
|
||||
}
|
||||
if (npc.mass < CANNONBALL_MASS)
|
||||
{
|
||||
npc.velocity = vector_resized(npc.velocity, CANNONBALL_SPEED);
|
||||
npc.mass = CANNONBALL_MASS;
|
||||
}
|
||||
npc.sprite.Play("Cannonball");
|
||||
npc.stateFrame++;
|
||||
if (npc.stateFrame > CANNONBALL_FRAMES || vector_length(npc.velocity) < CANNONBALL_MIN_SPEED)
|
||||
{
|
||||
npc.sprite.Play("Deploy");
|
||||
npc.stateFrame = -1;
|
||||
npc.mass = npc.config->mass;
|
||||
}
|
||||
if (!npc.isCollidesWithGrid) return true;
|
||||
|
||||
Vector normal = npc.gridCollisionNormal;
|
||||
Vector hit = npc.gridCollisionVelocity;
|
||||
npc.velocity = vector_sub(hit, vector_scale(normal, 2 * vector_dot(hit, normal)));
|
||||
npc_sound_play(SOUND_CANNONBALL_BOUNCE, 1, 2, 1);
|
||||
return true;
|
||||
}
|
||||
if (npc.variant != FLY_BOMB_ORBITING) return false;
|
||||
|
||||
Entity* parent = npc.parent.get();
|
||||
npc.isInvincible = true;
|
||||
if (!parent)
|
||||
{
|
||||
npc.Kill(EntityRef());
|
||||
npc.velocity = vector_scale(vector_from_angle(npc.v1.x), ORBIT_DROP_SPEED);
|
||||
fly_bomb_drop(npc, npc.parent.get());
|
||||
return true;
|
||||
}
|
||||
npc.v1.x = normalize_angle_degrees(npc.speedMultiplier * ORBIT_TURN + npc.v1.x);
|
||||
npc.targetPosition = vector_add(parent->pos, vector_scale(vector_from_angle(npc.v1.x), ORBIT_RADIUS));
|
||||
npc.velocity = vector_sub(npc.targetPosition, npc.pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
// A kin fly near its parent keeps a swaying distance around it and circles it.
|
||||
static void fly_parent_circle(Entity_NPC& npc)
|
||||
{
|
||||
Entity* parent = npc.parent.get();
|
||||
if (!parent || npc.controllerID != -1) return;
|
||||
|
||||
Vector toward = vector_sub(parent->pos, npc.pos);
|
||||
float distance = vector_length(toward);
|
||||
if (distance >= PARENT_RANGE) return;
|
||||
|
||||
float sway = std::sin((float)g_game->frameCount * PARENT_SWAY_RATE) * PARENT_SWAY + PARENT_ORBIT;
|
||||
float offset = std::clamp(distance - sway, -PARENT_SWAY, PARENT_SWAY);
|
||||
npc.AddVelocity_divided(vector_make(offset * toward.x * PARENT_PULL / distance,
|
||||
offset * toward.y * PARENT_PULL / distance),
|
||||
false);
|
||||
float spin = std::abs(offset) + PARENT_SPIN_DAMP;
|
||||
npc.AddVelocity_divided(vector_make(-(toward.y * PARENT_SPIN / spin) / npc.friction,
|
||||
toward.x * PARENT_SPIN / spin / npc.friction),
|
||||
false);
|
||||
}
|
||||
|
||||
// A plain fly or Pooter eyes a random spot within 240 and its poop, or now and then a fireplace.
|
||||
static void fly_wander_pick(Entity_NPC& npc)
|
||||
{
|
||||
Room& room = *g_game->room;
|
||||
Vector direction = random_direction();
|
||||
float scaleFirst = random_unit();
|
||||
float distance = random_unit() * scaleFirst * FLY_WANDER;
|
||||
int gridIndex = room.GetGridIndex(vector_add(npc.pos, vector_scale(direction, distance)));
|
||||
GridEntity* grid = gridIndex >= 0 && gridIndex < ROOM_GRID_CELLS ? room.gridEntities[gridIndex] : nullptr;
|
||||
if (grid && grid->type == GRID_POOP) npc.targetPosition = room.GetGridPosition(gridIndex);
|
||||
if (Random() % FLY_FIREPLACE_ODDS != 0) return;
|
||||
|
||||
std::vector<Entity*> fireplaces;
|
||||
for (Entity* entity : room.entityList.mainEL)
|
||||
if (entity->type == ENTITY_FIREPLACE) fireplaces.push_back(entity);
|
||||
if (!fireplaces.empty()) npc.targetPosition = fireplaces[random_below((int)fireplaces.size())]->pos;
|
||||
}
|
||||
|
||||
// Every third frame a fly picks where it heads: the kin circle their parent, plain flies and Pooters eye a spot,
|
||||
// and in the end each heads for its target (a plain fly or Pooter forgets it right after).
|
||||
static void fly_target_pick(Entity_NPC& npc, bool isSkatoleActive)
|
||||
{
|
||||
if (!npc.IsFrame(FLY_RETARGET_FRAMES, 0)) return;
|
||||
if (npc.type == ENTITY_ATTACKFLY && npc.parent && npc.controllerID == -1)
|
||||
reconstruction_missing("npc_fly_update 00506bd0: an attack fly circling its parent");
|
||||
|
||||
if (npc.type != ENTITY_ATTACKFLY && !isSkatoleActive)
|
||||
{
|
||||
Room& room = *g_game->room;
|
||||
Vector direction = random_direction();
|
||||
float scaleFirst = random_unit();
|
||||
float distance = random_unit() * scaleFirst * FLY_WANDER;
|
||||
int gridIndex = room.GetGridIndex(vector_add(npc.pos, vector_scale(direction, distance)));
|
||||
GridEntity* grid = gridIndex >= 0 ? room.GetGridEntity(gridIndex) : nullptr;
|
||||
if (grid && grid->type == GRID_POOP) npc.targetPosition = room.GetGridPosition(gridIndex);
|
||||
if (Random() % FLY_FIREPLACE_ODDS == 0)
|
||||
{
|
||||
std::vector<Entity*> fireplaces;
|
||||
for (Entity* entity : room.entityList.mainEL)
|
||||
if (entity->type == ENTITY_FIREPLACE) fireplaces.push_back(entity);
|
||||
if (!fireplaces.empty()) npc.targetPosition = fireplaces[random_below((int)fireplaces.size())]->pos;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (is_kin(npc.type)) fly_parent_circle(npc);
|
||||
bool isWanderer = npc.type != ENTITY_ATTACKFLY && npc.type != ENTITY_SUCKER && !is_kin(npc.type);
|
||||
if (isWanderer && !isSkatoleActive) fly_wander_pick(npc);
|
||||
npc.targetPosition = npc.CalcTargetPosition(0);
|
||||
}
|
||||
|
||||
@@ -205,42 +443,72 @@ static void fly_flee_update(Entity_NPC& npc)
|
||||
npc.v1 = vector_scale(npc.v1, 0.5f);
|
||||
}
|
||||
|
||||
// Every other tick a fly with a target pulls toward it once farther than its reach, harder the farther.
|
||||
static void fly_target_follow(Entity_NPC& npc)
|
||||
// Every other tick a fly with a target pulls toward it once farther than its reach, harder the farther. The level 2
|
||||
// fly and fly bomb veer one way, the full fly the other, twice as hard.
|
||||
static void fly_target_follow(Entity_NPC& npc, bool isSkatoleActive)
|
||||
{
|
||||
if (vector_is_zero(npc.targetPosition) || npc.GetIntervalTicks(CHARGE_INTERVAL, 0) == 0) return;
|
||||
|
||||
float reach = npc.type == ENTITY_ATTACKFLY ? TARGET_REACH_ATTACK : TARGET_REACH;
|
||||
if (npc.sprite.scale.x > BIG_FLY_SCALE) reach = TARGET_REACH_BIG;
|
||||
int type = npc.type;
|
||||
float reach = is_kin(type) ? TARGET_REACH_KIN : TARGET_REACH;
|
||||
if (type == ENTITY_SUCKER || npc.sprite.scale.x > BIG_FLY_SCALE) reach = TARGET_REACH_BIG;
|
||||
|
||||
Vector toward = vector_sub(npc.targetPosition, npc.pos);
|
||||
if (npc.controllerID == -1)
|
||||
{
|
||||
bool isVeering = !isSkatoleActive;
|
||||
if ((type == ENTITY_FLY_L2 || type == ENTITY_FLY_BOMB) && isVeering)
|
||||
toward = vector_make(toward.x - toward.y, toward.y + toward.x);
|
||||
else if (type == ENTITY_FULL_FLY && isVeering) toward = vector_make(toward.x + toward.y, toward.y - toward.x);
|
||||
toward.y *= TARGET_Y_SHARE;
|
||||
if (npc.parent) toward = vector_scale(toward, TARGET_PARENT_SHARE);
|
||||
}
|
||||
else toward = vector_scale(npc.GetControllerInput(0), FLEE_DISTANCE);
|
||||
else toward = vector_scale(npc.GetControllerInput(0), CONTROLLER_REACH);
|
||||
|
||||
float distance = vector_length(toward);
|
||||
Vector direction = distance > 0 ? vector_scale(toward, 1 / distance) : toward;
|
||||
if (npc.isKillOnTouch) npc.friction *= KILL_ON_TOUCH_FRICTION;
|
||||
if (npc.type != ENTITY_ATTACKFLY) npc.v1 = vector_scale(npc.v1, POOTER_DRIFT_DECAY);
|
||||
if (distance > reach)
|
||||
npc.AddVelocity_divided(vector_scale(direction, std::min((distance - reach) * TARGET_PULL, TARGET_PULL_MAX)),
|
||||
false);
|
||||
if (type != ENTITY_SUCKER && !is_kin(type)) npc.v1 = vector_scale(npc.v1, POOTER_DRIFT_DECAY);
|
||||
if (distance <= reach) return;
|
||||
|
||||
float pull = std::min((distance - reach) * TARGET_PULL, TARGET_PULL_MAX);
|
||||
if (is_zigzag(type) && !isSkatoleActive) pull += pull;
|
||||
npc.AddVelocity_divided(vector_scale(direction, pull), false);
|
||||
}
|
||||
|
||||
// A fly's buzzing: without a target it now and then darts toward its player, every fourth frame its drift turns,
|
||||
// every third it drifts back inside the room's middle and its drift moves it.
|
||||
// The zigzagging kin now and then bounce off a wall they touch, the bounce fading.
|
||||
static void fly_bounce_update(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.isCollidesWithGrid && Random() % BOUNCE_ODDS == 0 && !npc.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK))
|
||||
npc.v2 = vector_resized(npc.gridCollisionNormal, -BOUNCE_MIN - random_unit() * BOUNCE_RANGE);
|
||||
|
||||
if (vector_length_squared(npc.v2) <= 1)
|
||||
{
|
||||
npc.v2 = {};
|
||||
return;
|
||||
}
|
||||
npc.AddVelocity_divided(npc.v2, false);
|
||||
npc.v2 = vector_scale(npc.v2, BOUNCE_DECAY);
|
||||
}
|
||||
|
||||
// A fly's buzzing: without a target it now and then darts toward its player (or its player steers it), every fourth
|
||||
// frame its drift turns, every third it drifts back inside the room's middle and its drift moves it.
|
||||
static void fly_drift_update(Entity_NPC& npc)
|
||||
{
|
||||
if (vector_is_zero(npc.targetPosition))
|
||||
{
|
||||
if (npc.controllerID != -1) reconstruction_missing("npc_fly_update 00506bd0: a controlled fly's steering");
|
||||
if (Random() % FLY_CHASE_ODDS == 0)
|
||||
if (npc.controllerID == -1)
|
||||
{
|
||||
Vector toward = vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos));
|
||||
npc.velocity = vector_add(npc.velocity, vector_scale(toward, FLY_CHASE_SPEED * npc.speedMultiplier));
|
||||
if (Random() % FLY_CHASE_ODDS == 0)
|
||||
{
|
||||
Vector toward = vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos));
|
||||
npc.velocity = vector_add(npc.velocity, vector_scale(toward, FLY_CHASE_SPEED * npc.speedMultiplier));
|
||||
}
|
||||
}
|
||||
else if (npc.GetIntervalTicks(CHARGE_INTERVAL, 0) != 0)
|
||||
{
|
||||
Vector input = npc.GetControllerInput(0);
|
||||
npc.velocity = vector_add(npc.velocity, vector_scale(input, FLY_STEER_SPEED * npc.speedMultiplier));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,31 +528,26 @@ static void fly_drift_update(Entity_NPC& npc)
|
||||
npc.friction *= FLY_FRICTION;
|
||||
}
|
||||
|
||||
// 00506bd0 The flies' AI (the fly, Pooter and attack fly, with Moter, Sucker and their kin left to come): Skatole
|
||||
// befriends them, Lord of the Flies turns them blue, they buzz about drifting, the attack fly chases its target and
|
||||
// the Pooter shoots at it.
|
||||
// 00506bd0 The flies' AI: the fly, Pooter, attack fly, Moter, the Suckers, the level 2 and full flies and the fly
|
||||
// bomb. Skatole befriends them, Lord of the Flies turns them blue, they buzz about drifting, the kin circle their
|
||||
// parent and chase their target, the Pooter shoots at it, and the Suckers and Moter burst as they die.
|
||||
void npc_fly_update(Entity_NPC& npc)
|
||||
{
|
||||
bool isCovered = npc.type == ENTITY_FLY || npc.type == ENTITY_POOTER || npc.type == ENTITY_ATTACKFLY;
|
||||
if (!isCovered) reconstruction_missing("npc_fly_update 00506bd0: the Sucker, Moter and the other fly kin");
|
||||
|
||||
if (npc.state == NPC_STATE_INIT)
|
||||
{
|
||||
npc.entityGridCollisionClass = GRIDCOLL_WALLS;
|
||||
npc.v2 = {};
|
||||
npc.state = NPC_STATE_IDLE;
|
||||
npc.i1 = 0;
|
||||
}
|
||||
if (npc.type == ENTITY_SUCKER && (npc.variant == SUCKER_BULB || npc.variant == SUCKER_BULB_BLACK))
|
||||
return NpcAI::ENTITY_BULB(&npc);
|
||||
if (npc.type == ENTITY_SUCKER && npc.variant == SUCKER_MAMA_FLY) return (void)NpcAI::ENTITY_MAMA_FLY(&npc);
|
||||
if (npc.state == NPC_STATE_INIT) fly_init(npc);
|
||||
|
||||
PlayerManager& players = g_game->playerManager;
|
||||
bool isSkatoleActive =
|
||||
players.FirstCollectibleOwner(COLLECTIBLE_SKATOLE_ID, LAZARUS_SHARE_CHECK) && !npc.IsFriendly();
|
||||
bool isSkatoleActive = players.FirstCollectibleOwner(COLLECTIBLE_SKATOLE, LAZARUS_SHARE_CHECK) && !npc.IsFriendly();
|
||||
if (isSkatoleActive && npc.type == ENTITY_ATTACKFLY) npc.Morph(ENTITY_FLY, 0, 0, -1);
|
||||
|
||||
Entity_Player* beelzebub = players.GetRandomPlayer(npc.initSeed);
|
||||
if (beelzebub && !npc.isDead)
|
||||
{
|
||||
if (npc.type == ENTITY_ATTACKFLY || npc.type == ENTITY_FLY)
|
||||
bool isBlued = npc.type == ENTITY_ATTACKFLY || npc.type == ENTITY_FLY || npc.type == ENTITY_FLY_L2 ||
|
||||
npc.type == ENTITY_FULL_FLY;
|
||||
if (isBlued)
|
||||
{
|
||||
g_game->scoreSheet.AddKilledEnemy(npc);
|
||||
npc.Remove();
|
||||
@@ -292,12 +555,17 @@ void npc_fly_update(Entity_NPC& npc)
|
||||
}
|
||||
else if (!npc.IsBoss() && !npc.IsFriendly()) npc.AddCharmed(EntityRef(beelzebub), -1, true, false);
|
||||
}
|
||||
if (npc.type == ENTITY_SUCKER && npc.controllerID != -1 && npc.IsControllerActionPressed(CONTROLLER_ACTION_SHOOT))
|
||||
npc.Kill(EntityRef());
|
||||
|
||||
if (npc.isDead && npc.type == ENTITY_SUCKER) sucker_death(npc);
|
||||
else if (npc.isDead && npc.type == ENTITY_MOTER && npc.health > MOTER_OVERKILL && !isSkatoleActive) moter_split(npc);
|
||||
if (npc.i1 > 0)
|
||||
{
|
||||
npc.health = std::min(npc.health + npc.maxHitPoints / REGENERATION_FRAMES, npc.maxHitPoints);
|
||||
npc.i1--;
|
||||
}
|
||||
if (npc.isDead && npc.type == ENTITY_FLY_BOMB) fly_bomb_drop(npc, npc.parent.get());
|
||||
|
||||
fly_animation_update(npc);
|
||||
fly_poop_eat(npc);
|
||||
@@ -306,14 +574,92 @@ void npc_fly_update(Entity_NPC& npc)
|
||||
bool isIsaacsFly = npc.spawnerType == ENTITY_ISAAC_BOSS && npc.subtype != 0;
|
||||
if (isIsaacsFly) NpcAI::ENTITY_FLY_isaac_spawned(&npc);
|
||||
else if (npc.spawnerType == ENTITY_ORBIT_SPAWNER) return NpcAI::ENTITY_FLY_orbit_parent(&npc);
|
||||
else fly_target_pick(npc, isSkatoleActive);
|
||||
else
|
||||
{
|
||||
if (npc.type == ENTITY_FLY_BOMB && fly_bomb_update(npc)) return;
|
||||
fly_target_pick(npc, isSkatoleActive);
|
||||
}
|
||||
|
||||
if ((npc.type == ENTITY_FLY || npc.type == ENTITY_POOTER) && !isIsaacsFly) npc.targetPosition = {};
|
||||
fly_flee_update(npc);
|
||||
if (!isIsaacsFly) fly_target_follow(npc);
|
||||
if (!isIsaacsFly)
|
||||
{
|
||||
fly_target_follow(npc, isSkatoleActive);
|
||||
if (is_zigzag(npc.type)) fly_bounce_update(npc);
|
||||
}
|
||||
|
||||
if (npc.entityGridCollisionClass == GRIDCOLL_NONE && g_game->room->IsPositionInRoom(npc.pos, npc.size) &&
|
||||
room_grid_collision_at(npc.pos) < GRID_COLLISION_WALL)
|
||||
npc.entityGridCollisionClass = GRIDCOLL_WALLS;
|
||||
fly_drift_update(npc);
|
||||
|
||||
if (npc.type == ENTITY_FULL_FLY && npc.isDead && !npc.HasEntityFlags(FLAG_SHRINK))
|
||||
{
|
||||
ProjectileParams params;
|
||||
npc.FireProjectiles(npc.pos, vector_make(SUCKER_SHOT_SPEED, BLOODFLY_RING_SHOTS), PROJECTILES_RING, params);
|
||||
}
|
||||
}
|
||||
|
||||
// The dart fly circles while it homes in on where its target is heading, at up to 8.
|
||||
constexpr float DART_TURN = 0.18849558f;
|
||||
constexpr float DART_FULL_TURN = 6.2831855f;
|
||||
constexpr float DART_LEAD = 0.25f;
|
||||
constexpr float DART_CIRCLE = 10;
|
||||
constexpr float DART_HOMING = 15;
|
||||
constexpr float DART_HOMING_SHARE = 0.9f;
|
||||
constexpr float DART_ACCEL = 0.75f;
|
||||
constexpr float DART_ACCEL_DAMP = 0.9f;
|
||||
constexpr float DART_ACCEL_SHARE = 0.033333335f;
|
||||
constexpr float DART_MAX_SPEED = 8;
|
||||
constexpr float DART_FRICTION = 0.95f;
|
||||
|
||||
// 005400d0 The dart fly's AI: Lord of the Flies turns it blue and Skatole tames it into a fly. It weaves along a
|
||||
// circle while homing in on where its target is heading, at up to 8.
|
||||
void npc_dart_fly_update(Entity_NPC& npc)
|
||||
{
|
||||
PlayerManager& players = g_game->playerManager;
|
||||
Entity_Player* beelzebub = players.GetRandomPlayer(npc.initSeed);
|
||||
if (beelzebub && !npc.isDead)
|
||||
{
|
||||
g_game->scoreSheet.AddKilledEnemy(npc);
|
||||
npc.Remove();
|
||||
beelzebub->AddBlueFlies(1, npc.pos, nullptr);
|
||||
}
|
||||
if (players.FirstCollectibleOwner(COLLECTIBLE_SKATOLE, LAZARUS_SHARE_CHECK) && !npc.IsFriendly())
|
||||
{
|
||||
npc.Morph(ENTITY_FLY, 0, 0, -1);
|
||||
npc.v2 = {};
|
||||
npc.v1 = {};
|
||||
}
|
||||
if (npc.state == NPC_STATE_INIT)
|
||||
{
|
||||
npc.stateFrame = 0;
|
||||
npc.state = NPC_STATE_MOVE;
|
||||
float turn = random_unit();
|
||||
npc.v1.x = (turn + turn) * PI_F;
|
||||
}
|
||||
|
||||
if (npc.state == NPC_STATE_MOVE)
|
||||
{
|
||||
if (npc.controllerID != -1)
|
||||
reconstruction_missing("NpcAI::ENTITY_DART_FLY 005400d0: a dart fly under a player's control");
|
||||
npc.v1.x += DART_TURN;
|
||||
if (npc.v1.x >= DART_FULL_TURN) npc.v1.x -= DART_FULL_TURN;
|
||||
|
||||
Vector toward = vector_sub(npc.CalcTargetPosition(0), npc.pos);
|
||||
float distance = vector_length(toward);
|
||||
Vector lead = npc.GetPlayerTarget()->velocity;
|
||||
Vector aim = vector_normalized(vector_make((lead.x + lead.x) * distance * DART_LEAD + toward.x,
|
||||
(lead.y + lead.y) * distance * DART_LEAD + toward.y));
|
||||
float circleX = (float)std::cos((double)(npc.v1.x * 0.5f));
|
||||
float circleY = (float)std::sin((double)npc.v1.x);
|
||||
float steerX = circleX * DART_CIRCLE + aim.x * DART_HOMING * DART_HOMING_SHARE;
|
||||
float steerY = circleY * DART_CIRCLE + aim.y * DART_HOMING * DART_HOMING_SHARE;
|
||||
npc.velocity.x += steerX * DART_ACCEL * DART_ACCEL_DAMP * DART_ACCEL_SHARE * npc.speedMultiplier;
|
||||
npc.velocity.y += steerY * DART_ACCEL * DART_ACCEL_DAMP * DART_ACCEL_SHARE * npc.speedMultiplier;
|
||||
if (vector_length(npc.velocity) > DART_MAX_SPEED) npc.velocity = vector_resized(npc.velocity, DART_MAX_SPEED);
|
||||
npc.friction *= DART_FRICTION;
|
||||
}
|
||||
npc.sprite.Play("Fly");
|
||||
npc.sprite.isFlipX = npc.velocity.x > 0;
|
||||
}
|
||||
Reference in new issue
Block a user