Files
isaac-port/src/entity_combat.cpp
T

1372 lines
67 KiB
C++

#include "entity_combat.h"
#include "boss_ai.h"
#include "entity_bomb.h"
#include "entity_config.h"
#include "entity_effect.h"
#include "entity_effect_combat.h"
#include "entity_familiar.h"
#include "entity_laser.h"
#include "entity_list.h"
#include "entity_player.h"
#include "entity_projectile.h"
#include "entity_tear.h"
#include "fx_layers.h"
#include "game.h"
#include "lua_engine.h"
#include "manager.h"
#include "entity_player_characters.h"
#include "npc_ai.h"
#include "platform.h"
#include "room.h"
#include "room_render.h"
#include "seeds.h"
#include "entity_npc.h"
#include "sfx_manager.h"
#include <algorithm>
#include <array>
#include <bit>
#include <cmath>
constexpr float HALF_F = 0.5f;
// The entities the combat code tells apart (Lua's EntityType).
constexpr int ENTITY_SINS_FIRST = 46;
constexpr int ENTITY_SINS_LAST = 52;
constexpr int ENTITY_IGNORED_BY_TEARS = 291;
constexpr int ENTITY_REFLECTING_ENEMY = 822;
constexpr uint32_t REFLECT_ODDS = 5;
constexpr uint32_t DELIRIUM_RAGE_MAX = 255;
constexpr float TOOTH_CHIP_SPEED = 2;
constexpr float TOOTH_CHIP_SPEED_RANGE = 3;
// A black tooth's chips are its colour darkened to three tenths.
constexpr ColorMod BLACK_TOOTH_SHADE = {{0.3f, 0.3f, 0.3f, 1}, {0, 0, 0, 0}, {0, 0, 0}};
constexpr int ENTITY_SHIELDED_SPAWN = 832;
constexpr int ENTITY_SHIELDED_PART = 889;
constexpr int ENTITY_FACING_SHIELD = 903;
constexpr int ENTITY_SHIELD_SPAWNER = 905;
constexpr int ENTITY_CHAOS_REMOVED = 907;
constexpr int ENTITY_SHIELD_PARENT = 921;
constexpr int ENTITY_SCOURGE_TYPE = 830;
constexpr int SCOURGE_BONE_VARIANT = 10;
constexpr int CHARGER_MY_SHADOW = 3;
constexpr int FACING_SHIELD_VARIANT = 1;
constexpr int FIREPLACE_NORMAL = 0;
constexpr int FIREPLACE_RED = 1;
constexpr int FIREPLACE_MOVEABLE = 10;
constexpr int FIREPLACE_VARIANT_LAST = 10;
constexpr int FAMILIAR_INCUBUS = 80;
constexpr int FAMILIAR_TEAR_DEFLECTOR = 239;
constexpr int BEAST_BACKGROUND_FIRST = 102;
constexpr int BEAST_BACKGROUND_COUNT = 3;
constexpr int BEAST_CHEER_MIN = 2;
constexpr uint32_t BEAST_CHEER_RANGE = 15;
// The obstacles a spectral or piercing tear treats as solid (Entity 006ac660): a lit fireplace, movable TNT, poop and
// the stone enemies.
constexpr std::array<int, 7> STATIC_OBSTACLE_TYPES = {292, 245, 302, 42, 201, 203, 235};
constexpr int STATIC_OBSTACLE_EXTRA = 202;
// The items, trinkets and player kinds the combat code reads (Lua's ids).
constexpr int COLLECTIBLE_ARIES = 300;
constexpr int NULLITEM_TOOTH_AND_NAIL = 59;
constexpr int PLAYER_FORM_COUNT_NEEDED = 3;
constexpr int BABY_CROW = 12;
constexpr int BLUE_FLY_MAX = 30;
// The effects the combat code spawns (Lua's EffectVariant).
constexpr int ROCK_PARTICLE_SUBTYPE = 0x10001;
// An iced enemy shatters into 3 to 6 shards at 3 to 5, a frozen one into its gibs and up to 2 more as rocks at 5, both
// in a cold white and with a pitch of 0.9 to 1.1.
constexpr ColorMod SHATTER_COLOR = {{0.8f, 0.8f, 0.8f, 1}, {1, 1, 1, 0.5f}, {0.3f, 0.5f, 0.8f}};
constexpr float SHATTER_PITCH_MIN = 0.9f;
constexpr float SHATTER_PITCH_RANGE = 0.2f;
constexpr float ICE_SHARD_SPEED_MIN = 3;
constexpr uint32_t ICE_SHARD_EXTRA_MASK = 3;
constexpr int ICE_SHARD_COUNT_MIN = 3;
constexpr uint32_t FROZEN_SHARD_EXTRA = 3;
constexpr float FROZEN_SHARD_SPEED = 5;
// The sounds the combat code plays (Lua's SoundEffect).
constexpr int BISHOP_HIT_DELAY = 10;
constexpr float SOUND_LARGE_VOLUME = 1.25f;
constexpr float SOUND_BABY_VOLUME = 1.8f;
constexpr float SOUND_SMALL_VOLUME = 0.8f;
// Entity::TakeDamage: a fire hit's cooldown, the share of a boss's hits co-op lets through, and the Bishop's shield.
constexpr int FIRE_DAMAGE_COOLDOWN = 10;
constexpr float COOP_BOSS_DAMAGE = 0.8f;
constexpr float BISHOP_SHIELD_HEIGHT = -24;
constexpr float BISHOP_SHIELD_NULL_Y = 4;
constexpr float NULL_OFFSET_SCALE = 0.5f / 0.65f;
// Entity_Tear::HandleCollision: the bounce of a just fired tear off a bomb, and
// the burning tear's explosion chance from luck.
constexpr float TEAR_DEFLECTOR_MASS_SCALE = 0.1f;
constexpr int BOMB_GRACE_FRAMES = 3;
constexpr float FLY_PUSH = 0.5f;
constexpr int BURN_EXPLODE_CHANCE = 10;
constexpr float BURN_EXPLODE_LUCK = 0.7f;
constexpr float TEAR_HIT_MOVE = 0.8f;
constexpr uint32_t TEAR_BOUNCE_PIERCE_MASK = 3;
constexpr int INFAMY_CHANCE = 2;
constexpr int INFAMY_CHANCE_VERSUS = 4;
constexpr int INFAMY_FLASH_FRAMES = 15;
constexpr float MULLIGAN_FLY_CHANCE = 0.166f;
constexpr float GUPPY_FLY_CHANCE = 0.66f;
constexpr float LASTING_BEAM_FLY_SCALE = 0.1f;
// Entity_Player::HandleCollision: the contact damage the items deal.
constexpr int CONTACT_COUNTDOWN = 15;
constexpr int SUPLEX_STATE_PASSING = 3;
// Mega Mush's stomp (weaker in versus) and the suplex grab: the fireplace it snuffs, its aim's time and its scamper's
// pitch. Breath of Life's burst: its damage, more per floor deep, and its size.
constexpr float MEGA_MUSH_STOMP = 80;
constexpr float MEGA_MUSH_STOMP_VERSUS = 10;
constexpr float SUPLEX_FIREPLACE_DAMAGE = 1000;
constexpr int SUPLEX_GRAB_AIM_FRAMES = 60;
constexpr float SUPLEX_GRAB_PITCH_MIN = 0.9f;
constexpr float SUPLEX_GRAB_PITCH_RANGE = 0.2f;
constexpr float BREATH_BURST_DAMAGE = 15;
constexpr float BREATH_BURST_DAMAGE_PER_STAGE = 2.1f;
constexpr float BREATH_BURST_SIZE = 80;
constexpr float HEELS_DAMAGE = 12;
constexpr float HEELS_DAMAGE_VERSUS = 2;
constexpr float VIRUS_DAMAGE = 12;
constexpr float VIRUS_DAMAGE_VERSUS = 1;
constexpr float BABY_CONTACT_DAMAGE = 10;
constexpr float HORN_DAMAGE = 3.5f;
constexpr float RAM_DAMAGE = 20;
constexpr float RAM_FINISH_HEALTH = 40;
// A versus ram deals 15 and waits a second, and Gamekid's touch scares a player (for the original's -60 frames).
constexpr float RAM_VERSUS_DAMAGE = 15;
constexpr int RAM_VERSUS_COOLDOWN = 30;
constexpr int GAMEKID_VERSUS_FEAR = -60;
// The kill trinkets a versus tear hit rolls.
constexpr uint32_t LOCUST_ODDS_MASK = 0xf;
constexpr uint32_t FISH_TAIL_EXTRA_ODDS = 5;
constexpr uint32_t VERSUS_BAT_WING_ODDS = 50;
constexpr uint32_t VERSUS_CRICKET_LEG_ODDS = 33;
constexpr uint32_t VERSUS_SIGIL_ODDS = 10;
constexpr int VERSUS_SIGIL_FRAMES = 30;
constexpr int VERSUS_SIGIL_MAX_FRAMES = 150;
constexpr int MIDAS_CONTACT_FREEZE = 90;
constexpr int MIDAS_CONTACT_FREEZE_VERSUS = 45;
constexpr float MIDAS_CONTACT_DAMAGE = 3.5f;
constexpr float MIDAS_COIN_DAMAGE = 0.2f;
constexpr float ARIES_DAMAGE = 25;
constexpr float ARIES_DAMAGE_VERSUS = 10;
constexpr float ARIES_SPEED = 4;
constexpr float ARIES_MASS = 1000;
constexpr int ARIES_COOLDOWN = 2;
constexpr float NULL_CONTACT_DAMAGE = 40;
constexpr float NULL_CONTACT_DAMAGE_VERSUS = 15;
constexpr float THROWN_DAMAGE_SCALE = 3;
constexpr float THROWN_DAMAGE_BONUS = 5;
constexpr float SLOW_ON_CONTACT = 0.5f;
constexpr float ICE_KNOCKBACK_SPEED_SQUARED = 0.001f;
constexpr float ICE_SHOVE_SPEED = 18;
constexpr int ICE_SHOVE_FRAMES = 200;
// Entity::BloodExplode and gibs_spawn: the bursts' gibs and blood drops.
constexpr int EXTRA_BLOOD_GIBS = 8;
constexpr int GIB_KINDS = 14;
constexpr int GIB_KIND_BONE = 1;
constexpr int GIB_KIND_EYE = 3;
constexpr int GIB_KIND_POOP = 5;
constexpr int GIB_KIND_WORM = 6;
constexpr int GIB_KIND_ROCK = 7;
constexpr int GIB_KIND_ROCK_SMALL = 8;
constexpr int GIB_KIND_CHAIN = 11;
constexpr int GIB_EYES_MAX = 3;
constexpr int GIB_TIMEOUT_MIN = 15;
constexpr int GIB_TIMEOUT_RANGE = 15;
constexpr int GIB_HUGE_TIMEOUT_MIN = 20;
constexpr int GIB_HUGE_TIMEOUT_RANGE = 30;
constexpr int GIB_ROCK_DISCARDED_DRAWS = 4;
constexpr uint32_t GIB_COUNTED_KINDS = GIB_FLAG_BLOOD | GIB_FLAG_BONE | GIB_FLAG_GUT | GIB_FLAG_POOP | GIB_FLAG_ROCK |
GIB_FLAG_ROCK_SMALL | GIB_FLAG_CHAIN;
constexpr float GIB_SPEED_MIN = 2;
constexpr float GIB_SPEED_RANGE = 4;
constexpr float GIB_LIFT = 0.5f;
constexpr float GIB_WORM_HEIGHT = -40;
constexpr float DUST_ALPHA_MIN = 0.2f;
constexpr float DUST_ALPHA_RANGE = 0.5f;
constexpr float DROP_SPEED = 10;
constexpr float DROP_SPIN_MIN = 2;
constexpr float DROP_SPIN_RANGE = 10;
constexpr float DROP_ALPHA_MIN = 0.1f;
constexpr float DROP_ALPHA_RANGE = 0.25f;
constexpr float HUGE_GIB_SCALE_MIN = 2;
constexpr float HUGE_GIB_THROW = 10;
constexpr float HUGE_DROP_SCALE_RANGE = 2;
constexpr float HUGE_DROP_SPEED = 4;
constexpr int BURST_DROPS_MIN_GIBS = 6;
constexpr int BURST_SHAKE_MIN_GIBS = 8;
constexpr int BURST_SHAKE = 6;
constexpr int HUGE_BURST_SHAKE = 24;
constexpr float BURST_SPEED = 2;
constexpr float HUGE_BURST_SPEED = 4;
constexpr float BURST_PUSH = 16;
constexpr int REDUCED_GIBS_DIVISOR = 4;
constexpr float EXTRA_BLOOD_SPLAT_SCALE = 2;
constexpr KColor BLOOD_BASE_COLOR = kcolor_rgba(0.61960787f, 0.043137256f, 0.05882353f, 1);
constexpr ColorMod POISON_GIB_TINT = {{1, 1, 1, 1}, {0.3f, 1.6f, 0, 1}, {0, 0, 0}};
constexpr ColorMod TOOTH_COLOR = {{0.54902f, 0.482353f, 0.482353f, 1}, {0, 0, 0, 0}, {0, 0, 0}};
// Spawns an effect with a seed drawn by the caller.
static Entity_Effect* effect_spawn(int variant, int subType, Vector position, Vector velocity, Entity* spawner,
uint32_t seed)
{
Entity* effect = g_game->Spawn({.position = position,
.velocity = velocity,
.spawner = spawner,
.subType = subType,
.type = ENTITY_EFFECT,
.variant = variant,
.seed = seed});
return static_cast<Entity_Effect*>(effect);
}
// A random angle of a full turn, as the bursts draw it.
static float random_angle()
{
float angle = random_unit() * PI_ROUGH;
return angle + angle;
}
// Which way a spawned gib spins: against the side of its flight it landed on.
static float spin_side(Entity& gib, Vector origin, Vector velocity)
{
return (gib.pos.y - origin.y) * -velocity.x + (gib.pos.x - origin.x) * velocity.y < 0 ? -1.0f : 1.0f;
}
// 006ac660 Whether it stands like a block: a collidable fireplace, movable TNT, poop or stone enemy.
static bool is_static_obstacle(Entity& entity)
{
if (entity.entityCollisionClass == ENTCOLL_NONE) return false;
if (entity.type == ENTITY_FIREPLACE) return entity.variant < FIREPLACE_VARIANT_LAST;
return entity.type == STATIC_OBSTACLE_EXTRA || std::ranges::find(STATIC_OBSTACLE_TYPES, entity.type) !=
STATIC_OBSTACLE_TYPES.end();
}
// 004e7d10 (find_nearest_enemy) The Bishop nearest a position whose charm matches, among the queryable ones in the
// room's update order. A frozen one does not count, a confused, feared or shrunk one half the time.
Entity* bishop_nearest_find(const Vector& position, bool isCharmed)
{
Entity* nearest = nullptr;
float nearestDistance = 1e6f;
for (Entity* entity : entity_query(ENTITY_BISHOP, -1))
{
if (entity->HasEntityFlags(FLAG_FREEZE)) continue;
bool isDistracted = entity->HasEntityFlags(FLAG_CONFUSION | FLAG_FEAR | FLAG_SHRINK);
if ((isDistracted && (Random() & 1)) || entity->HasEntityFlags(FLAG_CHARM) != isCharmed) continue;
float distance = vector_length(vector_sub(position, entity->pos));
if (distance >= nearestDistance) continue;
nearest = entity;
nearestDistance = distance;
}
return nearest;
}
// Part of 006ace60: a Bishop takes the hit for it, its shield effect flashing over it.
static bool bishop_shield(Entity& entity, Entity& bishop)
{
npc_sound_play(SOUND_BISHOP_HIT, 1, BISHOP_HIT_DELAY, 1);
if (entity.hitEffect) entity.hitEffect->Remove();
Entity_Effect* shield = effect_spawn(EFFECT_BISHOP_SHIELD, 0, entity.pos, {}, &bishop, Random());
shield->parent = &bishop;
shield->target = &entity;
shield->parentOffset = vector_make(0, BISHOP_SHIELD_HEIGHT);
const NullFrame* overlay =
entity.sprite.animState.animData ? entity.sprite.animState.GetNullFrame("OverlayEffect") : nullptr;
if (overlay)
shield->posOffset = vector_make(overlay->pos.x * NULL_OFFSET_SCALE + entity.posOffset.x,
(overlay->pos.y - BISHOP_SHIELD_NULL_Y) * NULL_OFFSET_SCALE + entity.posOffset.y);
shield->Update();
entity.hitEffect = shield;
return false;
}
// Part of 006ace60: the boss part whose own shield takes the hit, none for others. Dogma's body is shielded by its
// parent, the Heretic's Exorcists while they wake or summon, and Clutch's orbitals by Clutch (the one it holds only
// while Clutch is solid).
static Entity* part_shield_get(Entity& entity)
{
constexpr int SHIELD_EXORCIST_WAKING = NPC_STATE_SUICIDE;
constexpr int SHIELD_EXORCIST_SUMMONING = NPC_STATE_SPECIAL;
Entity* spawner = entity.spawnerEntity;
Entity* parent = entity.parent;
if (entity.type == ENTITY_DOGMA) return entity.variant == 0 ? parent : nullptr;
if (entity.type == ENTITY_SHIELDED_SPAWN)
{
int state = static_cast<Entity_NPC&>(entity).state;
bool isGuarded = entity.variant == 1 && spawner && spawner->type == ENTITY_SHIELD_SPAWNER;
return isGuarded && (state == SHIELD_EXORCIST_SUMMONING || state == SHIELD_EXORCIST_WAKING) ? spawner : nullptr;
}
if (entity.type != ENTITY_SHIELDED_PART || !parent || parent->type != ENTITY_SHIELD_PARENT) return nullptr;
return parent->child.get() != &entity || parent->entityCollisionClass != ENTCOLL_NONE ? parent : nullptr;
}
// The players a co-op boss fight counts: one for each pair of twins and none for a player's attachments.
static int coop_player_count()
{
int count = 0;
for (Entity_Player* player : g_game->playerManager.playerList)
{
Entity_Player* twin = player->twin_get();
bool isMainTwin = !twin || twin->playerIndex == -1 || player->playerIndex <= twin->playerIndex || player == twin;
if (isMainTwin && !player->parent) count++;
}
return count;
}
// 006ace60 Queues a hit for the next update: nothing from a friendly source, nothing from a fire or countdown hit
// while its cooldown runs, and nothing a Bishop shields. A boss takes less in co-op, a weakened entity double, and a
// mod's MC_ENTITY_TAKE_DMG may cancel it. A hit on an enemy (or a versus player) counts toward the damage its
// attacking player dealt this frame. Whether the hit was queued.
bool Entity::TakeDamage(float damage, uint64_t damageFlags, const EntityRef& source, int countdown)
{
if (type == ENTITY_PLAYER) log_printf(LOG_ASSERT, "Entity TakeDamage should not be called for Entity Player!");
if (!(damageFlags & DAMAGE_INVINCIBLE) && IsDamageSourceFriendly(source)) return false;
if (damage > 0)
{
bool isVulnerable = IsVulnerableEnemy(nullptr);
Entity* shield = isVulnerable || type == ENTITY_DOGMA ? part_shield_get(*this) : nullptr;
if (shield) return bishop_shield(*this, *shield);
if ((isVulnerable && type != ENTITY_BISHOP) || (!isVulnerable && type == ENTITY_DOGMA))
{
Entity* bishop = bishop_nearest_find(pos, IsFriendly());
if (bishop) return bishop_shield(*this, *bishop);
}
}
if ((damageFlags & DAMAGE_FIRE) && damage > 0)
{
if (fireDamageCountdown > 0) return false;
fireDamageCountdown = FIRE_DAMAGE_COOLDOWN;
}
if (damageFlags & DAMAGE_COUNTDOWN)
{
if (damageCountdown > 0) return false;
damageCountdown = countdown;
}
if (!(damageFlags & DAMAGE_INVINCIBLE) && IsBoss() && g_game->playerManager.playerList.size() > 1 &&
coop_player_count() > 1)
damage *= COOP_BOSS_DAMAGE;
if (HasEntityFlags(FLAG_WEAKNESS)) damage += damage;
if (maxHitPoints <= 0) return false;
if (!lua_engine_get().EntityTakeDamage(this, damage, damageFlags, source, countdown)) return false;
damageEvents.push_back({.source = source, .damage = damage, .damageFlags = damageFlags});
pendingDamageFlags |= damageFlags;
pendingDamage += damage;
// The online stats screen also tallies the damage, which netplay being offline leaves out.
Entity* attacker = source.entity ? source.entity->GetPlayerAncestor() : nullptr;
if (attacker && is_enemy_type(type)) static_cast<Entity_Player*>(attacker)->versus.damageDealt += (uint32_t)damage;
return true;
}
// 006ac920 Kills it once: Black Powder blasts a fireplace its player put out, anything not a boss or familiar bursts
// into gibs, and MC_POST_ENTITY_KILL runs. The online kill tally of the stats screen is not written yet.
void Entity::Kill(const EntityRef& source)
{
if (isDead) return;
isDead = true;
Entity* killer = source.entity ? source.entity->GetPlayerAncestor() : nullptr;
if (killer && type == ENTITY_FIREPLACE)
{
bool isPowderable = variant == FIREPLACE_NORMAL || variant == FIREPLACE_RED || variant == FIREPLACE_MOVEABLE;
if (static_cast<Entity_Player*>(killer)->HasCollectible(COLLECTIBLE_BLACK_POWDER) && isPowderable)
explosion_effects({.position = pos, .source = killer, .damage = BLACK_POWDER_DAMAGE});
}
if (!IsBoss() && type != ENTITY_FAMILIAR) BloodExplode();
lua_engine_get().PostEntityKill(this);
}
// Part of 006b45c0: the burst's sound, by what its config says it is made of.
static void burst_sound_play(Entity& entity)
{
uint32_t gibFlags = entity.config->gibFlags;
int gibsAmount = entity.config->gibsAmount;
bool isSin = entity.type >= ENTITY_SINS_FIRST && entity.type <= ENTITY_SINS_LAST;
bool isLargeBurst = !entity.isDead || !entity.config->isBoss || isSin;
Entity_NPC* npc = entity.IsEnemy() ? dynamic_cast<Entity_NPC*>(&entity) : nullptr;
bool isDarkRed = npc && npc->championColorIdx == CHAMPION_DARK_RED;
if (entity.type == ENTITY_SCOURGE_TYPE && entity.variant == SCOURGE_BONE_VARIANT) npc_sound_play(SOUND_BONE_BREAK, 1, 2, 1);
else if (gibFlags & GIB_FLAG_CHAIN) npc_sound_play(SOUND_CHAIN_BREAK, 1, 2, 1);
else if (entity.freezeCountdown > 0 || (gibFlags & (GIB_FLAG_ROCK | GIB_FLAG_ROCK_SMALL)))
npc_sound_play(SOUND_ROCK_CRUMBLE, 1, 2, 1);
else if (isDarkRed) npc_sound_play(SOUND_DEATH_BURST_SMALL, 1, 2, 1);
else if (gibFlags & GIB_FLAG_SOUND_BABY) npc_sound_play(SOUND_GOODEATH, SOUND_BABY_VOLUME, 2, 1);
else if (gibFlags & GIB_FLAG_SOUND_BONE) npc_sound_play(SOUND_DEATH_BURST_BONE, 1, 2, 1);
else if (gibFlags & GIB_FLAG_HUGE) npc_sound_play(SOUND_ROCKET_BLAST_DEATH, 1, 2, 1);
else if (gibFlags & GIB_FLAG_LARGE)
{
if (isLargeBurst) npc_sound_play(SOUND_DEATH_BURST_LARGE, SOUND_LARGE_VOLUME, 2, 1);
else npc_sound_play(SOUND_ROCKET_BLAST_DEATH, 1, 2, 1);
}
else if (entity.HasEntityFlags(FLAG_EXTRA_GORE) && gibsAmount > 0 && (gibFlags & GIB_FLAG_BLOOD))
npc_sound_play(SOUND_DEATH_BURST_LARGE, SOUND_LARGE_VOLUME, 2, 1);
else npc_sound_play(SOUND_DEATH_BURST_SMALL, gibsAmount > 0 ? 1 : SOUND_SMALL_VOLUME, 2, 1);
}
// Part of 006b45c0: a big burst's blood drops, dust clouds in the blood's color flung around it.
static void burst_drops_spawn(Entity& entity, int gibsAmount)
{
int half = gibsAmount / 2;
int count = half + random_below(half);
KColor blood = kcolor_apply(entity.splatColor, BLOOD_BASE_COLOR);
bool isHuge = entity.config->gibFlags & GIB_FLAG_HUGE;
for (int i = 0; i < count; i++)
{
float angle = random_angle();
float speed = random_unit() * DROP_SPEED;
Vector velocity = vector_make(std::cos(angle) * speed, std::sin(angle) * speed);
uint32_t seed = Random();
float placeAngle = random_angle();
float radius = random_unit() * DUST_RADIUS;
Vector position = vector_add(entity.pos, vector_make(std::cos(placeAngle) * radius, std::sin(placeAngle) * radius));
Entity_Effect* drop = effect_spawn(EFFECT_DUST_CLOUD, 0, position, velocity, &entity, seed);
float side = spin_side(*drop, entity.pos, velocity);
drop->rotation = (random_unit() * DROP_SPIN_RANGE + DROP_SPIN_MIN) * side;
float alpha = (random_unit() * DROP_ALPHA_RANGE + DROP_ALPHA_MIN) * blood._alpha;
drop->SetColor({{blood._red, blood._green, blood._blue, alpha}, {0, 0, 0, 0}, {0, 0, 0}}, -1,
COLOR_PRIORITY_DEFAULT, false, true);
if (!isHuge) drop->SetTimeout((int)(Random() % GIB_TIMEOUT_RANGE) + GIB_TIMEOUT_MIN);
else
{
float scale = random_unit() * HUGE_DROP_SCALE_RANGE + HUGE_GIB_SCALE_MIN;
drop->sprite.scale = vector_make(scale, scale);
drop->SetTimeout((int)(Random() % GIB_HUGE_TIMEOUT_RANGE) + GIB_HUGE_TIMEOUT_MIN);
drop->velocity = vector_scale(drop->velocity, HUGE_DROP_SPEED);
}
drop->Update();
}
}
constexpr ColorMod BULB_FLASH_COLOR = {{1, 1, 0, 1}, {0, 0, 0, 0}, {0, 0, 0}};
constexpr int BULB_FLASH_FRAMES = 3;
constexpr float BULB_FLASH_SCALE = 0.75f;
constexpr float BULB_FLASH_RAISE = -10;
// Part of 006b45c0: the Bulb's death flash, a yellow additive light 10 up for 3 frames.
static void bulb_flash_spawn(const Vector& position)
{
npc_sound_play(SOUND_BULB_FLASH, 1, 2, 1);
uint32_t seed = Random();
auto* flash = static_cast<Entity_Effect*>(
g_game->Spawn({.position = position, .type = ENTITY_EFFECT, .variant = EFFECT_LIGHT, .seed = seed}));
flash->SetColor(BULB_FLASH_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true);
flash->timeout = BULB_FLASH_FRAMES;
flash->lifespan = BULB_FLASH_FRAMES;
flash->sprite.scale = vector_make(BULB_FLASH_SCALE, BULB_FLASH_SCALE);
flash->state = BULB_FLASH_FRAMES;
flash->posOffset = vector_make(0, BULB_FLASH_RAISE);
if (flash->sprite.animState.animData) flash->sprite.animState.SetFrameFloat(1);
layer_additive_set(*flash->sprite.GetLayer(0));
}
// 006b45c0 Bursts it: an iced or frozen enemy only shatters into shards, anything else plays its burst sound and
// throws its config's gibs, a big burst (extra gore, or a huge config) shaking the screen, pushed away from the first
// hit and with blood drops. It leaves a blood splat unless it is a bomb, a pickup or splashes no blood.
void Entity::BloodExplode()
{
if (HasEntityFlags(FLAG_ICE) && !IsBoss() && !config->isBoss)
{
npc_sound_play(SOUND_FREEZE, 1, 2, random_unit() * SHATTER_PITCH_RANGE + SHATTER_PITCH_MIN);
float speed = random_unit();
speed = speed + speed + ICE_SHARD_SPEED_MIN;
int count = (int)(Random() & ICE_SHARD_EXTRA_MASK) + ICE_SHARD_COUNT_MIN;
game_particles_spawn({.color = SHATTER_COLOR, .position = pos, .speed = speed, .count = count,
.variant = EFFECT_TOOTH_PARTICLE});
return;
}
if (HasEntityFlags(FLAG_ICE_FROZEN))
{
npc_sound_play(SOUND_FREEZE_SHATTER, 1, 2, random_unit() * SHATTER_PITCH_RANGE + SHATTER_PITCH_MIN);
npc_sound_play(SOUND_ROCK_CRUMBLE, 1, 2, 1);
int count = config->gibsAmount + (int)(Random() % FROZEN_SHARD_EXTRA);
game_particles_spawn({.color = SHATTER_COLOR, .position = pos, .speed = FROZEN_SHARD_SPEED, .count = count,
.variant = EFFECT_ROCK_PARTICLE});
return;
}
burst_sound_play(*this);
if (type == ENTITY_SUCKER && variant == SUCKER_BULB) bulb_flash_spawn(pos);
int gibsAmount = config->gibsAmount;
if (gibsAmount >= 1 && HasEntityFlags(FLAG_REDUCE_GIBS)) gibsAmount = std::max(gibsAmount / REDUCED_GIBS_DIVISOR, 1);
else if (HasEntityFlags(FLAG_EXTRA_GORE)) gibsAmount *= 2;
bool isHuge = config->gibFlags & GIB_FLAG_HUGE;
GibSpawn gibs = {.color = splatColor, .position = pos, .spawner = this, .spread = size, .amount = gibsAmount,
.gibFlags = config->gibFlags};
if (HasEntityFlags(FLAG_EXTRA_GORE) || isHuge)
{
gibs.speed = isHuge ? HUGE_BURST_SPEED : BURST_SPEED;
if (isHuge) game_shake_screen(HUGE_BURST_SHAKE);
else if (gibsAmount > BURST_SHAKE_MIN_GIBS) game_shake_screen(BURST_SHAKE);
if (!damageEvents.empty())
gibs.velocity = vector_scale(vector_normalized(vector_sub(pos, damageEvents.front().source.position)),
BURST_PUSH);
if (gibsAmount > BURST_DROPS_MIN_GIBS && (config->gibFlags & GIB_FLAG_BLOOD)) burst_drops_spawn(*this, gibsAmount);
}
gibs_spawn(gibs);
if (type == ENTITY_BOMB || type == ENTITY_PICKUP || HasEntityFlags(FLAG_NO_BLOOD_SPLASH)) return;
Entity_Effect* splat = effect_spawn(EFFECT_BLOOD_SPLAT, 0, pos, {}, nullptr, Random());
splat->SetColor(splatColor, -1, COLOR_PRIORITY_DEFAULT, false, true);
if (g_game->seedEffects.HasSeedEffect(SEED_EXTRA_BLOOD))
splat->sprite.scale = vector_make(EXTRA_BLOOD_SPLAT_SCALE, EXTRA_BLOOD_SPLAT_SCALE);
splat->Update();
}
// Part of 006b31b0: how many gibs of each kind a burst throws.
static std::array<int, GIB_KINDS> gib_counts_get(uint32_t gibFlags, int each)
{
std::array<int, GIB_KINDS> counts{};
int half = each / 2;
if (gibFlags & GIB_FLAG_BLOOD)
{
int first = random_below(each);
counts[0] = first + random_below(each);
}
if (gibFlags & GIB_FLAG_BONE) counts[GIB_KIND_BONE] = half + random_below(half);
if (gibFlags & GIB_FLAG_GUT) counts[2] = random_below(each);
if (gibFlags & GIB_FLAG_EYE) counts[GIB_KIND_EYE] = random_below(std::min(each, GIB_EYES_MAX));
if (gibFlags & GIB_FLAG_POOP) counts[GIB_KIND_POOP] = random_below(each);
if (gibFlags & GIB_FLAG_WORM) counts[GIB_KIND_WORM] = random_below(each);
if (gibFlags & GIB_FLAG_ROCK) counts[GIB_KIND_ROCK] = half + random_below(half);
if (gibFlags & GIB_FLAG_ROCK_SMALL) counts[GIB_KIND_ROCK_SMALL] = half + random_below(half);
if (gibFlags & GIB_FLAG_CHAIN) counts[GIB_KIND_CHAIN] = half + random_below(half);
return counts;
}
// Part of 006b31b0: a dusty burst's clouds, from half to all of a share.
static void gib_dust_spawn(const GibSpawn& gibs, int half)
{
int count = (int)(Random() % (uint32_t)half) + half;
for (int i = 0; i < count; i++)
{
float angle = random_angle();
float speed = random_unit() * DUST_SPEED;
Vector velocity = vector_make(std::cos(angle) * speed, std::sin(angle) * speed);
uint32_t seed = Random();
float placeAngle = random_angle();
float radius = random_unit() * DUST_RADIUS;
Vector position = vector_add(gibs.position, vector_make(std::cos(placeAngle) * radius, std::sin(placeAngle) * radius));
Entity_Effect* dust = effect_spawn(EFFECT_DUST_CLOUD, 0, position, velocity, gibs.spawner, seed);
dust->rotation = (random_unit() * DROP_SPIN_RANGE + DROP_SPIN_MIN) * spin_side(*dust, gibs.position, velocity);
dust->SetTimeout((int)(Random() % GIB_TIMEOUT_RANGE) + GIB_TIMEOUT_MIN);
float alpha = random_unit() * DUST_ALPHA_RANGE + DUST_ALPHA_MIN;
dust->SetColor({{1, 1, 1, alpha}, {0, 0, 0, 0}, {0, 0, 0}}, -1, COLOR_PRIORITY_DEFAULT, false, true);
dust->Update();
}
}
// Part of 006b31b0: a gib flung up from within half the spread, at its speed plus a random share of the push.
static Entity_Effect* gib_fling(const GibSpawn& gibs, int variant, int subType, uint32_t seed, float speed)
{
float angle = random_angle();
float push = random_unit();
Vector velocity = vector_make(std::cos(angle) * speed + push * gibs.velocity.x,
std::sin(angle) * GIB_LIFT * speed + push * gibs.velocity.y);
float placeAngle = random_angle();
Vector position = vector_add(gibs.position, vector_make(std::cos(placeAngle) * HALF_F * gibs.spread,
std::sin(placeAngle) * HALF_F * gibs.spread));
return effect_spawn(variant, subType, position, velocity, gibs.spawner, seed);
}
// Part of 006b31b0: a tooth or chain gib, scattered within half the spread and flung at its own speed.
static Entity_Effect* gib_scatter(const GibSpawn& gibs, int variant, uint32_t angleDraw)
{
float angle = (float)angleDraw * RANDOM_UNIT_SCALE * PI_ROUGH;
angle += angle;
float reach = random_unit();
Vector position = vector_add(gibs.position, vector_make(std::cos(angle) * reach * HALF_F * gibs.spread,
std::sin(angle) * reach * HALF_F * gibs.spread));
float flingAngle = random_angle();
float speed = random_unit() * GIB_SPEED_RANGE + GIB_SPEED_MIN;
float push = random_unit();
Vector velocity = vector_make(push * gibs.velocity.x + std::cos(flingAngle) * speed,
push * gibs.velocity.y + std::sin(flingAngle) * speed);
return effect_spawn(variant, 0, position, velocity, gibs.spawner, Random());
}
// Part of 006b31b0: a blood, bone, gut or eye gib in the burst's color, tinted green for a poisoned spawner.
static Entity_Effect* gib_blood_spawn(const GibSpawn& gibs, int kind, uint32_t seed, float speed)
{
Entity_Effect* gib = gib_fling(gibs, EFFECT_BLOOD_PARTICLE, kind, seed, speed);
if (!gibs.spawner || !gibs.spawner->HasEntityFlags(FLAG_POISON))
{
gib->SetColor(gibs.color, -1, COLOR_PRIORITY_DEFAULT, false, true);
gib->splatColor = gibs.color;
}
else
{
ColorMod tinted = gibs.color;
color_multiply(tinted, POISON_GIB_TINT);
gib->SetColor(kind == 0 ? tinted : gibs.color, -1, COLOR_PRIORITY_DEFAULT, false, true);
gib->splatColor = tinted;
}
if (kind == GIB_KIND_BONE) gib->AddEntityFlags(FLAG_NO_BLOOD_SPLASH);
return gib;
}
// Part of 006b31b0: one gib of a kind.
static Entity_Effect* gib_spawn(const GibSpawn& gibs, int kind)
{
float speed = (random_unit() * GIB_SPEED_RANGE + GIB_SPEED_MIN) * gibs.speed;
switch (kind)
{
case GIB_KIND_POOP:
{
uint32_t seed = Random();
return gib_fling(gibs, EFFECT_POOP_PARTICLE, 0, seed, speed);
}
case GIB_KIND_WORM:
{
uint32_t seed = Random();
int subType = (int)(Random() & 1);
Entity_Effect* worm = gib_fling(gibs, EFFECT_WORM, subType, seed, speed);
worm->posOffset = vector_make(0, random_unit() * GIB_WORM_HEIGHT);
return worm;
}
case GIB_KIND_ROCK:
{
for (int i = 0; i < GIB_ROCK_DISCARDED_DRAWS; i++) Random();
uint32_t seed = Random();
Entity_Effect* rock = gib_fling(gibs, EFFECT_ROCK_PARTICLE, ROCK_PARTICLE_SUBTYPE, seed, speed);
rock->Update();
return rock;
}
default: break;
}
uint32_t draw = Random();
if (kind == GIB_KIND_ROCK_SMALL)
{
Entity_Effect* tooth = gib_scatter(gibs, EFFECT_TOOTH_PARTICLE, draw);
tooth->SetColor(TOOTH_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true);
return tooth;
}
if (kind == GIB_KIND_CHAIN) return gib_scatter(gibs, EFFECT_CHAIN_GIB, draw);
return gib_blood_spawn(gibs, kind, draw, speed);
}
// 006b31b0 Throws a burst's gibs: the amount (eight times it with the extra blood seed) shared among the kinds its
// flags name, each kind flung its own way, and the dust of a dusty burst. A huge burst's gibs come out bigger.
void gibs_spawn(const GibSpawn& gibs)
{
if (gibs.amount == 0) return;
int multiplier = g_game->seedEffects.HasSeedEffect(SEED_EXTRA_BLOOD) ? EXTRA_BLOOD_GIBS : 1;
int total = multiplier * gibs.amount + (int)(Random() & 1);
int kinds = std::popcount(gibs.gibFlags & GIB_COUNTED_KINDS);
int each = (kinds == 0 ? total : total / kinds) + 1;
std::array<int, GIB_KINDS> counts = gib_counts_get(gibs.gibFlags, each);
if ((gibs.gibFlags & GIB_FLAG_DUST) && each / 2 != 0) gib_dust_spawn(gibs, each / 2);
if (kinds == 0) return;
for (int kind = 0; kind < GIB_KINDS; kind++)
{
for (int i = 0; i < counts[kind]; i++)
{
Entity_Effect* gib = gib_spawn(gibs, kind);
if (gibs.gibFlags & GIB_FLAG_HUGE)
{
if (g_game->room->IsBeastDungeon())
gib->velocity.y += (-HUGE_GIB_THROW - random_unit() * HUGE_GIB_THROW) * gib->speedMultiplier;
float scale = random_unit() + HUGE_GIB_SCALE_MIN;
gib->AddEntityFlags(FLAG_EXTRA_GORE);
gib->sprite.scale = vector_make(scale, scale);
}
gib->Update();
}
}
}
// 0067d1f0 The damage flags a hit adds: a blue fly for Mulligan and Guppy (less likely from a lasting laser or
// brimstone ball), a booger tear's, a rock tear's crush, and the hit through cooldowns of a glowing versus tear or of
// bit 100.
uint64_t tear_damage_flags_get(const TearFlags& tearFlags, Entity* source)
{
uint64_t damageFlags = 0;
Entity* spawner = source ? source->spawnerEntity.get() : nullptr;
if (spawner && spawner->type == ENTITY_FAMILIAR && spawner->variant == FAMILIAR_INCUBUS)
spawner = static_cast<Entity_Familiar*>(spawner)->player;
if (spawner && spawner->type == ENTITY_PLAYER)
{
Entity_Player& player = *static_cast<Entity_Player*>(spawner);
float flyChance = player.HasCollectible(COLLECTIBLE_MULLIGAN) ? MULLIGAN_FLY_CHANCE : 0;
if (!player.hasCurseMistEffect && !player.isCoopGhost && player.playerForms[PLAYER_FORM_GUPPY] >= PLAYER_FORM_COUNT_NEEDED)
flyChance = GUPPY_FLY_CHANCE;
bool isLastingBall = source->type == ENTITY_EFFECT && source->variant == EFFECT_BRIMSTONE_BALL &&
static_cast<Entity_Effect*>(source)->timeout == -1;
bool isLastingLaser = source->type == ENTITY_LASER && static_cast<Entity_Laser*>(source)->timeout == -1;
if (isLastingBall || isLastingLaser) flyChance *= LASTING_BEAM_FLY_SCALE;
if (flyChance > 0 && player.numBlueFlies < BLUE_FLY_MAX && random_unit() < flyChance) damageFlags |= DAMAGE_SPAWN_FLY;
}
if (g_game->deathmatchManager.is_active() && tearFlags[TEAR_GLOW]) damageFlags |= DAMAGE_THROUGH_COOLDOWN;
if (source && source->type == ENTITY_TEAR && tearFlags[TEAR_BOOGER_FLAG]) damageFlags |= DAMAGE_BOOGER;
if (tearFlags[TEAR_ROCK_FLAG]) damageFlags |= DAMAGE_CRUSH;
if (tearFlags[TEAR_THROUGH_COOLDOWN]) damageFlags |= DAMAGE_THROUGH_COOLDOWN;
return damageFlags;
}
// What a tear does on touching an entity before it hits it: pass it, stop on it, or go on to hit it.
enum TearContact
{
TEAR_CONTACT_PASS,
TEAR_CONTACT_STOP,
TEAR_CONTACT_HIT
};
// Part of 00673660: pushes the collider along the line from the tear, by their relative speed and masses. A tear
// passing it fast and inward bounces the line off its flight. massScale weighs the tear's mass.
static void tear_push(Entity_Tear& tear, Entity& collider, float massScale)
{
Vector offset = vector_sub(collider.pos, tear.pos);
float distance = vector_length(offset);
if (distance < PUSH_MIN_DISTANCE) return;
Vector relative = vector_sub(tear.velocity, collider.velocity);
float speed = vector_length(relative);
if ((collider.size + tear.size) * HALF_F < speed && vector_dot(relative, offset) < 0)
{
float bounce = vector_dot(vector_normalized(relative), vector_normalized(offset));
offset = vector_make(offset.x + bounce * offset.x + bounce * offset.x,
offset.y + bounce * offset.y + bounce * offset.y);
distance = vector_length(offset);
}
float tearMass = tear.collision_mass_get(&collider) * massScale;
float share = tearMass / (collider.collision_mass_get(&tear) + tearMass);
collider.velocity.x += offset.x / distance * speed * share;
collider.velocity.y += offset.y / distance * speed * share;
}
// Part of 00673660: how a tear meets a player: it passes its own player's line, a charmed enemy's shot glances off
// the player who charmed it, and Infamy stops it half the time (a quarter in versus) with a flash.
static TearContact tear_player_contact(Entity_Tear& tear, Entity_Player& player)
{
if (tear.IsDescendantOf(&player)) return TEAR_CONTACT_PASS;
Entity* shooter = tear.spawnerEntity;
Entity* charmer = shooter && shooter->HasEntityFlags(FLAG_CHARM) ? shooter->charmSource.entity : nullptr;
if (charmer && charmer->IsDescendantOf(&player))
{
tear.velocity = vector_scale(random_direction(), vector_length(tear.velocity));
return TEAR_CONTACT_PASS;
}
int infamyChance = g_game->deathmatchManager.is_active() ? INFAMY_CHANCE_VERSUS : INFAMY_CHANCE;
if (!player.HasCollectible(COLLECTIBLE_INFAMY) || random_below(infamyChance) != 0) return TEAR_CONTACT_HIT;
player.SetColor(INFAMY_COLOR, INFAMY_FLASH_FRAMES, COLOR_PRIORITY_DEFAULT, true, true);
tear.Kill(EntityRef(&player));
return TEAR_CONTACT_PASS;
}
// Part of 00673660: two tears of different shooters meet only when one is shielded, which destroys the other.
static TearContact tear_tear_contact(Entity_Tear& tear, Entity_Tear& other)
{
if (tear.spawnerEntity.get() == other.spawnerEntity.get()) return TEAR_CONTACT_PASS;
if (!tear.tearFlags[TEAR_SHIELDED] && !other.tearFlags[TEAR_SHIELDED]) return TEAR_CONTACT_PASS;
if (tear.tearFlags[TEAR_SHIELDED]) other.Kill(EntityRef(&tear));
else tear.Kill(EntityRef(&other));
return TEAR_CONTACT_HIT;
}
// Part of 00673660: a Chaos Card kills any enemy it touches outright, passing the props and Dogma's and the Beast's
// bodies. Delirium only flies into a long rage, the card gone. The original also clears the top bits of his form's
// age, which this reconstruction does not keep.
static TearContact chaos_card_contact(Entity_Tear& tear, Entity& collider)
{
if (collider.type == ENTITY_GENERIC_PROP) return TEAR_CONTACT_PASS;
if ((collider.type == ENTITY_DOGMA || collider.type == ENTITY_BEAST) && collider.variant == 0) return TEAR_CONTACT_PASS;
if (collider.type == ENTITY_DELIRIUM)
{
tear.Remove();
static_cast<Entity_NPC&>(collider).deliriumRageTimer = DELIRIUM_RAGE_MAX;
return TEAR_CONTACT_PASS;
}
if (!collider.IsEnemy()) return TEAR_CONTACT_HIT;
collider.Kill(EntityRef(&tear));
if (collider.type == ENTITY_CHAOS_REMOVED) tear.Remove();
return TEAR_CONTACT_PASS;
}
// Part of 00673660: a tear meeting a bomb passes it while chained or orbiting, while just fired away from it, and
// past a fetus bomb unless a player's fetus tear hits it.
static TearContact tear_bomb_contact(Entity_Tear& tear, Entity_Bomb& bomb)
{
if (tear.tearFlags[TEAR_CHAIN] || tear.tearFlags[TEAR_ORBIT_ADVANCED]) return TEAR_CONTACT_PASS;
bool isFiredAway = vector_dot(vector_sub(bomb.pos, tear.pos), tear.velocity) < 0 &&
g_game->frameCount - tear.spawnFrame < BOMB_GRACE_FRAMES;
if (isFiredAway) return TEAR_CONTACT_PASS;
if (!bomb.isFetus) return TEAR_CONTACT_HIT;
return tear.spawnerType != ENTITY_PLAYER || tear.tearFlags[TEAR_FETUS_FLAG] ? TEAR_CONTACT_PASS : TEAR_CONTACT_HIT;
}
// Part of 00673660: how a tear meets what it touches before hitting it: its own familiars, Dark Esau, friendly enemies,
// rockets and invincible bosses it passes, a shielded tear stops shots, and a few entities deflect it.
static TearContact tear_contact_get(Entity_Tear& tear, Entity& collider, Entity* owner, bool isExplosive)
{
if (collider.type == ENTITY_PLAYER)
{
TearContact contact = tear_player_contact(tear, *static_cast<Entity_Player*>(&collider));
if (contact != TEAR_CONTACT_HIT) return contact;
}
if (collider.type == ENTITY_TEAR && tear_tear_contact(tear, *static_cast<Entity_Tear*>(&collider)) == TEAR_CONTACT_PASS)
return TEAR_CONTACT_PASS;
if (collider.type == ENTITY_FAMILIAR && collider.IsDescendantOf(owner)) return TEAR_CONTACT_PASS;
if (collider.type == ENTITY_DARK_ESAU) return TEAR_CONTACT_PASS;
if (collider.IsEnemy() && collider.IsFriendly() && collider.IsDamageSourceFriendly(EntityRef(&tear)))
return TEAR_CONTACT_PASS;
if (collider.type == ENTITY_FROZEN_ENEMY && &collider == tear.spawnerEntity.get()) return TEAR_CONTACT_STOP;
if (collider.type == ENTITY_BOMB && static_cast<Entity_Bomb&>(collider).IsRocket()) return TEAR_CONTACT_PASS;
if (collider.type == ENTITY_FAMILIAR && collider.IsDescendantOf(tear.spawnerEntity)) return TEAR_CONTACT_PASS;
if (tear.variant == TEAR_CHAOS_CARD)
{
TearContact contact = chaos_card_contact(tear, collider);
if (contact != TEAR_CONTACT_HIT) return contact;
}
if (collider.type == ENTITY_HUSH && collider.isInvincible) return TEAR_CONTACT_PASS;
if (collider.type == ENTITY_BOMB && tear_bomb_contact(tear, static_cast<Entity_Bomb&>(collider)) == TEAR_CONTACT_PASS)
return TEAR_CONTACT_PASS;
if (collider.type == ENTITY_IGNORED_BY_TEARS) return TEAR_CONTACT_PASS;
if (collider.type == ENTITY_BIG_HORN && collider.isInvincible) return TEAR_CONTACT_PASS;
if (collider.type == ENTITY_FAMILIAR && collider.variant == FAMILIAR_TEAR_DEFLECTOR)
{
if (!EntityList::HitListContains(tear.hitList, collider))
{
hit_list_insert(tear.hitList, collider);
tear_push(tear, collider, TEAR_DEFLECTOR_MASS_SCALE);
}
return TEAR_CONTACT_PASS;
}
if (!isExplosive && collider.type == ENTITY_REFLECTING_ENEMY &&
static_cast<Entity_NPC&>(collider).state == NPC_STATE_SPECIAL)
{
RNG rng = rng_make(collider.initSeed + tear.initSeed, DEFAULT_SHIFT_INDEX);
if (rng.RandomInt(REFLECT_ODDS) == 0)
{
Vector normal = vector_normalized(vector_sub(tear.pos, collider.pos));
float along = vector_dot(normal, tear.velocity);
if (along < 0) tear.velocity = vector_sub(tear.velocity, vector_scale(normal, along + along));
return TEAR_CONTACT_PASS;
}
}
if (collider.type == ENTITY_PROJECTILE)
{
Entity_Projectile& shot = static_cast<Entity_Projectile&>(collider);
bool isUnstoppable = !tear.tearFlags[TEAR_SHIELDED] || (shot.projectileFlags & PROJECTILE_CANT_HIT_PLAYER);
if (isUnstoppable && !(shot.projectileFlags & PROJECTILE_SHIELDED)) return TEAR_CONTACT_PASS;
shot.projectileFlags = 0;
shot.isDead = true;
}
return TEAR_CONTACT_HIT;
}
// How many locusts a locust trinket sends: one, or with Fish Tail two (sometimes three doubled, four tripled).
static int locust_count_get(Entity_Player& player)
{
if (!player.HasTrinket(TRINKET_FISH_TAIL)) return 1;
int multiplier = player.GetTrinketMultiplier(TRINKET_FISH_TAIL);
if (multiplier == 2) return Random() % FISH_TAIL_EXTRA_ODDS == 0 ? 3 : 2;
if (multiplier == 3 && Random() % FISH_TAIL_EXTRA_ODDS == 0) return 4;
return 2;
}
// Part of 00673660: a versus player's tear landing on another player rolls its kill trinkets: each locust one in 16
// (Conquest's twice as many), Bat Wing's flight one in 50, Cricket Leg's pickup one in 33 and Sigil of Baphomet's
// shield one in 10 for a second, up to five.
static void versus_hit_trinkets(Entity_Player& player)
{
TemporaryEffects& effects = player.temporaryEffects;
for (int trinket = TRINKET_LOCUST_OF_WRATH; trinket <= TRINKET_LOCUST_OF_CONQUEST; trinket++)
{
if (!player.HasTrinket(trinket) || (Random() & LOCUST_ODDS_MASK) != 0) continue;
int locusts = locust_count_get(player) * (trinket == TRINKET_LOCUST_OF_CONQUEST ? 2 : 1);
for (int i = 0; i < locusts; i++)
{
uint32_t seed = Random();
Entity* locust = g_game->Spawn({.position = player.pos, .spawner = &player,
.subType = trinket - TRINKET_LOCUST_OF_WRATH + 1, .type = ENTITY_FAMILIAR,
.variant = Entity_Familiar::BLUE_FLY, .seed = seed});
locust->ClearEntityFlags(FLAG_APPEAR);
}
}
if (player.HasTrinket(TRINKET_BAT_WING) && !effects.HasTrinketEffect(TRINKET_BAT_WING) &&
player.GetTrinketRNG(TRINKET_BAT_WING).RandomInt(VERSUS_BAT_WING_ODDS) == 0)
{
effects.AddTrinketEffect(TRINKET_BAT_WING, true, 1);
player.AddCostume(g_manager->itemConfig.GetNullItem(NULLITEM_BATWING_WINGS), false);
}
if (player.HasTrinket(TRINKET_CRICKET_LEG) && Random() % VERSUS_CRICKET_LEG_ODDS == 0) player.SpawnTrinketRandomPickup();
if (!player.HasTrinket(TRINKET_SIGIL_OF_BAPHOMET) || Random() % VERSUS_SIGIL_ODDS != 0) return;
TemporaryEffect* shadows = effects.GetCollectibleEffect(COLLECTIBLE_BOOK_OF_SHADOWS);
if (shadows && shadows->cooldown >= VERSUS_SIGIL_MAX_FRAMES) return;
TemporaryEffect added;
added.item = g_manager->itemConfig.GetCollectible(COLLECTIBLE_BOOK_OF_SHADOWS);
added.cooldown = VERSUS_SIGIL_FRAMES;
added.unknown = shadows ? 0 : 1;
if (!shadows) sound_play(SOUND_BOOK_SHADOWS_SIGIL);
effects.AddEffect(added, true, 1);
}
// Part of 00673660: a tear hitting what it may hurt: whether its owner's side may hurt it, and whether it faces the
// tear's way (a shielded front blocks). Piercing passes the fronts, and a spectral tear an obstacle with no grid
// damage. Whether the tear flies through.
static bool tear_damage_deal(Entity_Tear& tear, Entity& collider, bool& isHit)
{
float damage = tear.collisionDamage;
uint64_t damageFlags = tear_damage_flags_get(tear.tearFlags, &tear);
Entity_NPC* npc = dynamic_cast<Entity_NPC*>(&collider);
bool isFacing = !npc || npc->CanBeDamagedFromVelocity(tear.velocity);
Entity* shooter = tear.spawnerEntity;
bool isOwnSide = shooter && (shooter->IsDescendantOf(&collider) || collider.IsDescendantOf(tear.GetRootPlayer()));
bool isHostile = !isOwnSide || (Entity::is_enemy_type(collider.type) && !collider.IsFriendly());
bool isAlwaysHit = collider.type == ENTITY_FIREPLACE || collider.type == ENTITY_POOP || collider.type == ENTITY_BLOOD_PUPPY;
isHit = false;
if (!isAlwaysHit && !isHostile) return false;
bool isObstacle = is_static_obstacle(collider);
bool isPiercing = tear.tearFlags[TEAR_PIERCING];
bool isSpectral = tear.tearFlags[TEAR_SPECTRAL];
if (collider.IsEnemy() && (!isPiercing || isObstacle) && (!isSpectral || !isObstacle) && !isFacing) return false;
if (isSpectral && isObstacle && tear.tearFlags[TEAR_NO_GRID_DAMAGE]) return true;
Entity_Player* shooterPlayer = shooter ? shooter->ToPlayer() : nullptr;
if (g_game->deathmatchManager.is_active() && shooterPlayer)
{
shooterPlayer->trigger_vampire_charm_kill();
if (collider.type == ENTITY_PLAYER) versus_hit_trinkets(*shooterPlayer);
}
isHit = true;
collider.TakeDamage(damage, damageFlags, EntityRef(&tear), HIT_COUNTDOWN);
if (tear.tearFlags[TEAR_FETUS_FLAG] && !isObstacle) tear.fetus_hit(collider);
if (collider.IsEnemy()) tear.isCanTriggerStreakEnd = false;
return collider.IsEnemy() && (tear.tearFlags[TEAR_BOOGER_FLAG] || tear.tearFlags[TEAR_STICKY] || tear.tearFlags[TEAR_SPORE_FLAG]);
}
// Part of 00673660: Dead Eye charges when its player's tear hits an active enemy.
static void dead_eye_charge(Entity_Tear& tear, Entity& collider)
{
Entity* parent = tear.parent;
if (!parent || !collider.IsActiveEnemy(DEAD_EXCLUDED) || parent->type != ENTITY_PLAYER) return;
Entity_Player& player = *static_cast<Entity_Player*>(parent);
if (player.HasCollectible(COLLECTIBLE_DEAD_EYE)) player.AddDeadEyeCharge();
}
// Part of 00673660: what a hit does beside its damage: a burning tear may turn explosive by luck, a piercing or
// lasting tear pushes what it passes, a tooth Ludovico chips teeth off a vulnerable enemy, and flies are knocked along.
static void tear_hit_push(Entity_Tear& tear, Entity& collider, Entity* owner)
{
if (tear.tearFlags[TEAR_BURN] && collider.type != ENTITY_FIREPLACE)
{
float luck = owner && owner->type == ENTITY_PLAYER ? static_cast<Entity_Player*>(owner)->luck : 0;
int chance = BURN_EXPLODE_CHANCE - (int)(luck * BURN_EXPLODE_LUCK);
if (random_below(chance < 1 ? 1 : chance) == 0 && (!tear.tearFlags[TEAR_LUDOVICO] || tear.is_not_familiar_spawned()))
tear.tearFlags[TEAR_EXPLOSIVE] = true;
}
if ((tear.variant == TEAR_TOOTH || tear.variant == TEAR_BLACK_TOOTH) && tear.tearFlags[TEAR_LUDOVICO] &&
collider.IsVulnerableEnemy(nullptr))
{
ColorMod color = tear.sprite.color;
if (tear.variant == TEAR_BLACK_TOOTH) color_multiply(color, BLACK_TOOTH_SHADE);
game_particles_spawn({.color = color,
.position = tear.pos,
.height = tear.height,
.speed = random_between(TOOTH_CHIP_SPEED, TOOTH_CHIP_SPEED_RANGE),
.count = 1,
.variant = EFFECT_TOOTH_PARTICLE});
}
bool isPassing = tear.tearFlags[TEAR_PIERCING] || tear.tearFlags[TEAR_PERSISTENT];
if ((isPassing || tear.tearFlags[TEAR_FETUS_FLAG]) && !collider.HasEntityFlags(FLAG_NO_PHYSICS_KNOCKBACK))
tear_push(tear, collider, 1);
if ((collider.type == ENTITY_POOTER || collider.type == ENTITY_ATTACKFLY) && !isPassing)
collider.velocity = vector_add(collider.velocity, vector_scale(tear.velocity, FLY_PUSH));
}
// Part of 00673660: a lasting tear loses the damage it dealt and shrinks with it, dying once it has none left over or
// the enemy faced it.
static void tear_persist(Entity_Tear& tear, Entity& collider)
{
Entity_NPC* npc = dynamic_cast<Entity_NPC*>(&collider);
if (tear.collisionDamage <= collider.health || (npc && !npc->CanBeDamagedFromVelocity(tear.velocity)))
{
tear.deathFlags |= TEAR_DEATH_ENTITY;
tear.isDead = true;
return;
}
float damage = tear.collisionDamage;
tear.collisionDamage = damage - collider.health;
tear.SetScale(tear.collisionDamage * tear.baseScale / damage);
tear.isCanTriggerStreakEnd = false;
}
// Part of 00673660: whether a tear flies on after its hit: a bouncing one turns at random (a piercing one a quarter
// of the time off enemies), a lasting one keeps going, and piercing, Ludovico, spectral and Chaos Card tears pass.
static bool tear_flies_on(Entity_Tear& tear, Entity& collider)
{
bool isObstacle = is_static_obstacle(collider);
bool isPiercing = tear.tearFlags[TEAR_PIERCING];
if (tear.tearFlags[TEAR_FETUS_FLAG])
{
tear.isCanTriggerStreakEnd = false;
return true;
}
if (tear.tearFlags[TEAR_BOUNCE] && (!isPiercing || isObstacle || (Random() & TEAR_BOUNCE_PIERCE_MASK) == 0))
{
tear.velocity = vector_scale(random_direction(), vector_length(tear.velocity));
tear.tearFlags[TEAR_TRACTOR_BEAM] = false;
tear.isCanTriggerStreakEnd = false;
return true;
}
bool isSpectralBlocked = tear.tearFlags[TEAR_SPECTRAL] && isObstacle;
if (tear.tearFlags[TEAR_PERSISTENT] && (!isPiercing || isObstacle) && !tear.tearFlags[TEAR_LUDOVICO] &&
!isSpectralBlocked)
{
tear_persist(tear, collider);
dead_eye_charge(tear, collider);
return true;
}
return (isPiercing && !isObstacle) || tear.tearFlags[TEAR_LUDOVICO] || isSpectralBlocked ||
tear.variant == TEAR_CHAOS_CARD;
}
// 00673660 Hits what it collides with, after a mod's MC_PRE_TEAR_COLLISION: past what it passes (its own player and
// familiars, friends, rockets, other tears) and once per entity unless it pierces, it deals its damage with its hit
// flags, knocks flies along and applies its flags' effects, then dies there unless it flies on. An explosive tear
// bursts on any hit. Whether the collision is ignored.
bool Entity_Tear::HandleCollision(Entity* collider, bool isLow)
{
LuaResult lua = lua_engine_get().PreTearCollision(this, collider, isLow);
if (lua != LUA_RESULT_NIL) return lua == LUA_RESULT_TRUE;
bool isExplosive = tearFlags[TEAR_EXPLOSIVE] && !tearFlags[TEAR_LUDOVICO];
if (!isLow || isDead) return false;
Entity* owner = GetPlayerAncestor();
if (owner == collider) return true;
TearContact contact = tear_contact_get(*this, *collider, owner, isExplosive);
if (contact != TEAR_CONTACT_HIT) return contact == TEAR_CONTACT_PASS;
bool isPassing = tearFlags[TEAR_PIERCING] || tearFlags[TEAR_PERSISTENT] || tearFlags[TEAR_SPECTRAL] ||
tearFlags[TEAR_BOUNCE] || tearFlags[TEAR_LUDOVICO] || tearFlags[TEAR_BOOGER_FLAG] ||
tearFlags[TEAR_STICKY] || tearFlags[TEAR_SPORE_FLAG] || tearFlags[TEAR_FETUS_FLAG];
if (EntityList::HitListContains(hitList, *collider) && isPassing) return true;
hit_list_insert(hitList, *collider);
bool isSticking = tearFlags[TEAR_STICKY] || tearFlags[TEAR_BOOGER_FLAG] || tearFlags[TEAR_SPORE_FLAG];
if (collider->IsActiveEnemy(DEAD_EXCLUDED) && isSticking && stick(*collider)) return true;
if (!isExplosive)
{
bool isHit = false;
if (tear_damage_deal(*this, *collider, isHit)) return true;
if (isHit) dead_eye_charge(*this, *collider);
tear_hit_push(*this, *collider, owner);
}
ApplyTearFlagEffects(collider, pos, tearFlags, this, collisionDamage);
bool isErasable = collider->IsVulnerableEnemy(nullptr) && (!collider->IsBoss() || collider->HasMortalDamage());
if (variant == TEAR_ERASER && isErasable && enemy_erase(*collider)) npc_sound_play(SOUND_ERASER_HIT, 1, 2, 1);
if (tearFlags[TEAR_TELEPORT] && collider->IsVulnerableEnemy(nullptr) && !collider->IsBoss())
tear_hit_teleport(*collider);
if (isExplosive)
{
deathFlags |= TEAR_DEATH_ENTITY | TEAR_DEATH_EXPLOSION;
isDead = true;
if (tearFlags[TEAR_LUDOVICO] && is_not_familiar_spawned())
for (Entity* link = child; link; link = link->child) link->Kill(EntityRef());
}
else
{
apply_death_flag_effects(collider);
if (tearFlags[TEAR_BELIAL_FLAG]) belial_turn();
bool isPassed = collider->type == ENTITY_FAMILIAR && !static_cast<Entity_Familiar*>(collider)->CanBlockProjectiles();
if (g_game->deathmatchManager.is_active() && isPassed) return true;
if (tear_flies_on(*this, *collider)) return true;
deathFlags |= TEAR_DEATH_ENTITY;
isDead = true;
pos = vector_add(pos, vector_scale(collider->velocity, TEAR_HIT_MOVE));
}
dead_eye_charge(*this, *collider);
return false;
}
// Part of 006d4a00: whether a hit comes at My Shadow's charger from behind its face, which turns diagonal while it
// attacks.
static bool is_charger_hit_from_behind(Entity_NPC& npc, Vector hitVelocity)
{
std::string_view animation = npc.sprite.animState.GetAnimation();
int facing = npc.sprite.isFlipX ? DIRECTION_LEFT : DIRECTION_RIGHT;
if (animation.ends_with("Up")) facing = DIRECTION_UP;
else if (animation.ends_with("Down")) facing = DIRECTION_DOWN;
Vector face = vector_make(facing == DIRECTION_LEFT ? -1 : facing == DIRECTION_RIGHT ? 1 : 0,
facing == DIRECTION_UP ? -1 : facing == DIRECTION_DOWN ? 1 : 0);
if (animation.starts_with("Attack"))
face = vector_make(npc.sprite.isFlipX ? -DIAGONAL : DIAGONAL, facing == DIRECTION_UP ? -DIAGONAL : DIAGONAL);
return vector_dot(face, hitVelocity) >= 0;
}
// 006d4a00 Whether a hit moving this way may hurt it: the knights and the Mask of Infamy guard the side they face, a
// shield-carrying enemy its own, and My Shadow's charger anything coming at its face.
bool Entity_NPC::CanBeDamagedFromVelocity(Vector hitVelocity)
{
int facing = DIRECTION_DOWN;
if (type == ENTITY_KNIGHT || type == ENTITY_FLOATING_KNIGHT || type == ENTITY_BONE_KNIGHT)
{
const std::string& animation = sprite.animState.GetAnimation();
if (animation == "Up") facing = DIRECTION_UP;
else if (animation == "Hori") facing = sprite.isFlipX ? DIRECTION_LEFT : DIRECTION_RIGHT;
}
else if (type == ENTITY_MASK_OF_INFAMY) facing = get_velocity_direction();
else if (type == ENTITY_FACING_SHIELD && variant == FACING_SHIELD_VARIANT)
{
if (vector_is_zero(hitVelocity)) return true;
int hitDirection = std::fabs(hitVelocity.y) < std::fabs(hitVelocity.x)
? (hitVelocity.x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT)
: (hitVelocity.y >= 0 ? DIRECTION_DOWN : DIRECTION_UP);
return hitDirection == i1;
}
else if (type == ENTITY_CHARGER && variant == CHARGER_MY_SHADOW) return is_charger_hit_from_behind(*this, hitVelocity);
else return true;
return !((hitVelocity.x < 0 && facing == DIRECTION_RIGHT) || (hitVelocity.x > 0 && facing == DIRECTION_LEFT) ||
(hitVelocity.y > 0 && facing == DIRECTION_UP) || (hitVelocity.y < 0 && facing == DIRECTION_DOWN));
}
// 006d6d20 What a player's hurt does to the enemies that taunt: Gurdy and Satan take note, and the Beast's background
// horsemen cheer.
void Entity_NPC::on_player_damaged()
{
if (type == ENTITY_GURDY || type == ENTITY_SATAN) v1.x = 1;
else if (type == ENTITY_BEAST && variant >= BEAST_BACKGROUND_FIRST && variant < BEAST_BACKGROUND_FIRST + BEAST_BACKGROUND_COUNT &&
state == NPC_STATE_IDLE)
{
state = NPC_STATE_ATTACK;
stateFrame = (int)(Random() % BEAST_CHEER_RANGE) + BEAST_CHEER_MIN;
}
}
// Part of 0078e1f0: the damage a player's touch deals: in a versus fight 1 to a Sumo player (and Gamekid's fear), the
// ramming items (more against the weak, 15 against a versus player once a second), Mom's Heels, The
// Virus and Serpent's Kiss, Isaac's Heart's melee, Midas' Touch's gold freeze, the crow baby, Little Horn, Breath of Life, Aries at speed (which makes the player heavy and briefly unhurt),
// Tooth and Nail, all tripled when thrown. Whether Breath of Life adds to it goes back through isBreath.
static float player_contact_damage(Entity_Player& player, Entity& collider, bool& isBreath)
{
bool isVersus = g_game->deathmatchManager.is_active();
TemporaryEffects& effects = player.temporaryEffects;
float damage = 0;
if (collider.type == ENTITY_PLAYER && g_game->deathmatchManager.is_fighting())
{
damage = g_game->deathmatchManager.type->is_bouncy(static_cast<Entity_Player&>(collider)) ? 1 : 0;
if (effects.HasCollectibleEffect(COLLECTIBLE_GAMEKID)) collider.AddFear(EntityRef(&player), GAMEKID_VERSUS_FEAR, false);
}
TemporaryEffect* taurus = effects.GetCollectibleEffect(COLLECTIBLE_TAURUS);
bool isRamming = effects.HasCollectibleEffect(COLLECTIBLE_MY_LITTLE_UNICORN) ||
effects.HasCollectibleEffect(COLLECTIBLE_GAMEKID) || effects.HasCollectibleEffect(COLLECTIBLE_THE_NAIL) ||
(taurus && taurus->cooldown != 0);
if (isRamming && player.versus.ramCooldown == 0)
{
damage += collider.health <= RAM_FINISH_HEALTH ? RAM_DAMAGE + RAM_DAMAGE : RAM_DAMAGE;
if (isVersus && collider.type == ENTITY_PLAYER)
{
damage = RAM_VERSUS_DAMAGE;
player.versus.ramCooldown = RAM_VERSUS_COOLDOWN;
}
}
if (player.HasCollectible(COLLECTIBLE_MOMS_HEELS)) damage += isVersus ? HEELS_DAMAGE_VERSUS : HEELS_DAMAGE;
if (player.HasCollectible(COLLECTIBLE_VIRUS)) damage += isVersus ? VIRUS_DAMAGE_VERSUS : VIRUS_DAMAGE;
if (player.HasCollectible(COLLECTIBLE_SERPENTS_KISS)) damage += isVersus ? VIRUS_DAMAGE_VERSUS : VIRUS_DAMAGE;
Entity_Player* twin = player.twin_get();
Entity_Player& heartOwner = player.playerType == PLAYER_THESOUL_B && twin ? *twin : player;
if (heartOwner.HasCollectible(COLLECTIBLE_ISAACS_HEART)) damage = player.meleeDamage + player.meleeDamage + damage;
if (player.HasCollectible(COLLECTIBLE_MIDAS_TOUCH))
{
collider.AddMidasFreeze(EntityRef(&player), isVersus ? MIDAS_CONTACT_FREEZE_VERSUS : MIDAS_CONTACT_FREEZE, false);
damage = (float)player.numCoins * MIDAS_COIN_DAMAGE + MIDAS_CONTACT_DAMAGE + damage;
}
if (player.variant == PLAYER_VARIANT_COOP_BABY && player.babySkin == BABY_CROW) damage += BABY_CONTACT_DAMAGE;
if (player.HasCollectible(COLLECTIBLE_LITTLE_HORN)) damage += HORN_DAMAGE;
isBreath = effects.HasCollectibleEffect(COLLECTIBLE_BREATH_OF_LIFE);
if (isBreath) damage += HORN_DAMAGE;
bool isAries = player.HasCollectible(COLLECTIBLE_ARIES) || player.GetZodiacEffect() == COLLECTIBLE_ARIES;
if (isAries && vector_length(player.velocity) > ARIES_SPEED)
{
if (player.damageCooldown < 1) player.AddEntityFlags(FLAG_NO_DAMAGE_BLINK);
player.damageCooldown = std::max(player.damageCooldown, ARIES_COOLDOWN);
damage += isVersus ? ARIES_DAMAGE_VERSUS : ARIES_DAMAGE;
player.mass = ARIES_MASS;
}
if (effects.HasNullEffect(NULLITEM_TOOTH_AND_NAIL)) damage += isVersus ? NULL_CONTACT_DAMAGE_VERSUS : NULL_CONTACT_DAMAGE;
if (player.HasEntityFlags(FLAG_THROWN)) damage = damage * THROWN_DAMAGE_SCALE + THROWN_DAMAGE_BONUS;
return damage;
}
// Part of 0078e1f0: Mega Mush's stomp crushes what the giant touches once each: an enemy (unless friendly), a slot or a
// pickup, the last two blown up as well.
static void mega_mush_stomp(Entity_Player& player, Entity& collider)
{
bool isEnemy = collider.IsEnemy() && !collider.HasEntityFlags(FLAG_FRIENDLY);
if (!isEnemy && !collider.is_slot() && !collider.is_pickup()) return;
if (EntityList::HitListContains(player.contactHitList, collider)) return;
hit_list_insert(player.contactHitList, collider);
float damage = isEnemy && g_game->deathmatchManager.is_active() ? MEGA_MUSH_STOMP_VERSUS : MEGA_MUSH_STOMP;
uint64_t flags = isEnemy ? DAMAGE_CRUSH : DAMAGE_CRUSH | DAMAGE_EXPLOSION;
collider.TakeDamage(damage, flags, EntityRef(&player), HIT_COUNTDOWN);
}
// Part of 0078e1f0: Suplex!'s dash grabs what it runs into: shots pass, a fireplace is snuffed out, and an enemy or a
// bomb is lifted for the aim. Whether the collision is ignored for good.
static bool suplex_grab(Entity_Player& player, Entity& collider)
{
if (collider.type == ENTITY_PROJECTILE) return true;
if (!collider.IsEnemy() && !collider.is_bomb()) return false;
if (collider.type == ENTITY_FIREPLACE)
{
collider.TakeDamage(SUPLEX_FIREPLACE_DAMAGE, 0, EntityRef(&player), HIT_COUNTDOWN);
return false;
}
if (!player.TryHoldEntity(&collider)) return false;
player.itemState = COLLECTIBLE_SUPLEX;
player.suplexAimCountdown = SUPLEX_GRAB_AIM_FRAMES;
player.suplexState = SUPLEX_AIMING;
npc_sound_play(SOUND_SUPLEX_GRAB, 1, 2, 1);
npc_sound_play(SOUND_SCAMPER, 1, 2, random_unit() * SUPLEX_GRAB_PITCH_RANGE + SUPLEX_GRAB_PITCH_MIN);
return true;
}
// Part of 0078e1f0: the player's ways of touching before it hurts anything: shoving an iced enemy, Tainted Magdalene's
// hug and Mega Mush's stomp.
static void player_contact_touch(Entity_Player& player, Entity& collider)
{
bool isEnemyLike = Entity::is_enemy_type(collider.type) ||
(g_game->deathmatchManager.is_active() && collider.type == ENTITY_PLAYER);
bool isShoved = isEnemyLike && collider.HasEntityFlags(FLAG_ICE_FROZEN) && !collider.HasEntityFlags(FLAG_KNOCKED_BACK) &&
vector_length_squared(player.velocity) > ICE_KNOCKBACK_SPEED_SQUARED;
if (isShoved)
{
Vector toward = vector_normalized(vector_sub(collider.pos, player.pos));
Vector push = vector_normalized(vector_add(vector_normalized(player.velocity), toward));
collider.AddKnockback(EntityRef(&player), vector_scale(push, ICE_SHOVE_SPEED), ICE_SHOVE_FRAMES, true);
}
tainted_magdalene_hug(player, collider);
if (player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_MEGA_MUSH)) mega_mush_stomp(player, collider);
}
// Part of 0078e1f0: The Virus and Serpent's Kiss poison an enemy touched for 60 frames at 2 plus a twentieth of the
// square of the player's red hearts (a tenth of an eighth of them, at least 1, in a deathmatch). Serpent's Kiss marks
// it to drop a black heart. The poison is handed down the enemy's chain before it is added.
constexpr int VIRUS_POISON_FRAMES = 60;
constexpr float VIRUS_POISON_BASE = 2;
constexpr float VIRUS_POISON_SCALE = 0.05f;
constexpr float VIRUS_DEATHMATCH_SCALE = 0.125f * 0.1f;
static void virus_poison_apply(Entity_Player& player, Entity& collider)
{
if (player.HasCollectible(COLLECTIBLE_SERPENTS_KISS)) collider.AddEntityFlags(FLAG_SPAWN_BLACK_HP);
float hearts = (float)player.redHearts;
if (g_game->deathmatchManager.state >= DEATHMATCH_INTRO) hearts = std::max(1.0f, hearts * VIRUS_DEATHMATCH_SCALE);
collider.bossStatusEffectCooldown = 0;
collider.CopyStatusEffects();
collider.AddPoison(EntityRef(&player), VIRUS_POISON_FRAMES, hearts * VIRUS_POISON_SCALE * hearts + VIRUS_POISON_BASE,
false);
}
// Part of 0078e1f0: Breath of Life's holy burst where the player's edge meets the enemy it hurt, stronger deeper down
// (none while the player keeps Judas' Book of Belial), and a short spell unhurt.
static void breath_of_life_burst(Entity_Player& player, Entity& collider)
{
float damage = (float)g_game->stage_depth_get() * BREATH_BURST_DAMAGE_PER_STAGE + BREATH_BURST_DAMAGE;
Vector edge = vector_add(player.pos, vector_resized(vector_sub(collider.pos, player.pos), player.size));
if (!player.HasCollectible(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE))
{
Entity* burst = g_game->Spawn({.position = edge, .spawner = &player, .type = ENTITY_EFFECT,
.variant = EFFECT_CRACK_THE_SKY, .seed = Random()});
burst->parent = &player;
burst->SetCollisionDamage(damage);
burst->SetSize(BREATH_BURST_SIZE, vector_make(-1, -1), -1);
burst->subtype = 1;
}
if (player.damageCooldown < 1) player.AddEntityFlags(FLAG_NO_DAMAGE_BLINK);
player.damageCooldown = std::max(player.damageCooldown, CONTACT_COUNTDOWN);
}
// 0078e1f0 Touches another entity, after a mod's MC_PRE_PLAYER_COLLISION: mid-suplex it passes enemies and shots,
// it hurts a vulnerable enemy by its items' contact damage, poisons with The Virus or Serpent's Kiss, and a thrown
// Tainted Forgotten slows on enemies. Tainted Forgotten's soul picks the body up. Whether the collision is ignored, which a pony's dash makes it.
bool Entity_Player::HandleCollision(Entity* collider, bool isLow)
{
LuaResult lua = lua_engine_get().PrePlayerCollide(this, collider, isLow);
if (lua == LUA_RESULT_TRUE) return true;
if (lua == LUA_RESULT_FALSE) return false;
player_contact_touch(*this, *collider);
if (playerType == PLAYER_THESOUL_B && collider->type == ENTITY_PLAYER &&
static_cast<Entity_Player*>(collider)->playerType == PLAYER_THEFORGOTTEN_B)
{
Room& room = *g_game->room;
if (collider->HasEntityFlags(FLAG_HELD | FLAG_THROWN) || !room.isInitialized ||
g_game->frameCount - room.enterFrame < 2)
return true;
TryHoldEntity(collider);
}
if (suplexState == SUPLEX_DASHING && suplex_grab(*this, *collider)) return true;
if (suplexState >= SUPLEX_STATE_PASSING && (collider->IsEnemy() || collider->type == ENTITY_PROJECTILE)) return true;
bool isIgnored = false;
if (collider->IsVulnerableEnemy(nullptr))
{
isIgnored = ponyCharge > 0 || temporaryEffects.HasCollectibleEffect(COLLECTIBLE_RECALL);
bool isBreath = false;
float damage = player_contact_damage(*this, *collider, isBreath);
if (damage > 0 && collider->TakeDamage(damage, DAMAGE_COUNTDOWN, EntityRef(this), CONTACT_COUNTDOWN) && isBreath)
breath_of_life_burst(*this, *collider);
}
bool isPoisoning = HasCollectible(COLLECTIBLE_VIRUS) || temporaryEffects.HasCollectibleEffect(COLLECTIBLE_VIRUS) ||
HasCollectible(COLLECTIBLE_SERPENTS_KISS);
if (collider->IsActiveEnemy(DEAD_EXCLUDED) && isPoisoning && !collider->HasEntityFlags(FLAG_NO_STATUS_EFFECTS) &&
!collider->IsFriendly())
virus_poison_apply(*this, *collider);
if (playerType == PLAYER_THEFORGOTTEN_B && !isIgnored && collider->IsEnemy() && HasEntityFlags(FLAG_THROWN) &&
!collider->IsFriendly())
velocity = vector_scale(velocity, SLOW_ON_CONTACT);
if (collider->IsEnemy() && !collider->HasEntityFlags(FLAG_CHARM) && temporaryEffects.HasCollectibleEffect(COLLECTIBLE_MARS))
{
temporaryEffects.RemoveCollectibleEffect(COLLECTIBLE_MARS, -1);
velocity = vector_scale(vector_normalized(vector_sub(pos, collider->pos)), vector_length(velocity));
marsDashDirection = -1;
dash_impact();
}
return isIgnored;
}