#include "boss_ai.h" #include "entity_combat.h" #include "entity_effect.h" #include "entity_familiar.h" #include "entity_laser.h" #include "entity_pickup.h" #include "entity_player.h" #include "entity_projectile.h" #include "entity_tear.h" #include "game.h" #include "grid_entity.h" #include "log.h" #include "manager.h" #include "npc_ai.h" #include "room.h" #include "room_grid.h" #include "sfx_manager.h" #include #include #include constexpr float LASER_KNOCKBACK = 1.8f; constexpr float OWNER_KNOCKBACK_SCALE = 0.2f; constexpr float GROW_RANGE = 1000; constexpr float GROW_GAIN = 5; constexpr float SHRINK_RANGE = 300; constexpr float MINIMUM_DAMAGE = 0.1f; constexpr float THICK_BACK_REACH = 16; constexpr float PATH_END_REACH = 40; constexpr float RING_REACH_SCALE = 0.1f; constexpr float GRID_SWEEP_STEP = 20; constexpr float ROOM_SIDE_MARGIN = -8; constexpr float GRID_REACH_EXTRA = 15; constexpr float SPLASH_EDGE = 2; constexpr float SPLASH_SPEED_MIN = 4; constexpr float SPLASH_SPEED_RANGE = 6; constexpr float SPLASH_SPREAD = 3; constexpr float SPLASH_SCALE = 2; constexpr float SPLASH_HALF_TURN = 3.14f; constexpr float MARKED_SPLASH_SPEED_MIN = 2; constexpr float MARKED_SPLASH_SPEED_RANGE = 2; constexpr float MARKED_TINT_RED = 2; constexpr float MARKED_ROTATION_RANGE = 360; constexpr float MARKED_SOUND_VOLUME = 0.7f; constexpr int MARKED_SOUND_DELAY = 8; constexpr float MARKED_DAMAGE_EXTRA = 3; constexpr float PLAYER_HIT_DAMAGE = 1; constexpr int LASER_HIT_COUNTDOWN = 30; constexpr int GRID_HURT_CHANCE_MASK = 3; constexpr int SHIELD_RING_CHANCE = 50; constexpr int SHIELD_CHANCE = 5; constexpr float RING_FAMILIAR_SCALE = 0.75f; constexpr float RING_PULSE_RATE = 0.1f; constexpr float RING_PULSE_SIZE = 20; constexpr float RING_GROW_RANGE = 500; constexpr float RING_GROW_SIZE = 50; constexpr float RING_OPEN_MIN = 5; constexpr float RING_WALL_FACING = 0.75f; constexpr float RING_FADE_GROWTH = 0.2f; constexpr float RING_HIT_INTERVAL = 2; constexpr float RING_LUDOVICO_FRICTION = 0.8f; constexpr float RING_SAMPLE_BLEND = 0.3f; constexpr float RING_COLLINEAR_TOLERANCE = 0.001f; constexpr float RING_WIGGLE_RATE = 1.6f; constexpr float RING_GRID_OFFSET_SCALE = 0.8f; constexpr float LIGHT_RING_INTERVAL = 30; constexpr int RING_OPEN_FRAMES = 10; constexpr int RING_FADE_FRAMES = 5; constexpr int RING_BRIMSTONE_FADE = 20; constexpr int MARKED_SPRAY_SUBTYPE = 2; constexpr RNG BLACK_HEART_RNG = {0, 1, 5, 19}; constexpr int PULLED_EFFECTS[] = {EFFECT_TINY_BUG, EFFECT_TINY_FLY, EFFECT_WORM, EFFECT_BEETLE, EFFECT_LIL_GHOST}; // Whether a laser's knockback moves an entity: a bomb with knockback off only from a player's laser, a player not // from a friendly spawner's. static bool is_knocked_back(Entity_Laser& laser, Entity& entity) { Entity* spawner = laser.spawnerEntity; if (entity.HasEntityFlags(FLAG_NO_KNOCKBACK)) return entity.type == ENTITY_BOMB && spawner && spawner->type == ENTITY_PLAYER; return entity.type != ENTITY_PLAYER || !spawner || !spawner->HasEntityFlags(FLAG_FRIENDLY); } // Pushes an entity along a direction by the laser's mass, divided by the entity's weight, weaker on players and // familiars, twice as strong under Knockback. static void laser_push(Entity_Laser& laser, Entity& entity, Vector direction, float weight) { if (weight > 0) direction = vector_scale(direction, 1 / weight); float strength = laser.mass * LASER_KNOCKBACK; if (entity.type == ENTITY_PLAYER || entity.type == ENTITY_FAMILIAR) strength *= OWNER_KNOCKBACK_SCALE; if (laser.tearFlags[TEAR_KNOCKBACK]) strength += strength; if (entity.friction == 0) return; entity.velocity = vector_add(entity.velocity, vector_scale(direction, strength * entity.speedMultiplier / entity.friction)); } // 0097e3c0 Hits an entity: it joins the hit list, then takes the laser's damage and tear effects from its spawner. A // player outside a versus match (and the familiars that take a player's hits) takes one heart's hit. Bombs are // spared. A Brimstone-marked entity takes a thick beam's hit harder, and Black Hp drops are rolled from its seed. void Entity_Laser::DoDamage(Entity* entity, float damage) { std::vector& hits = hit_list_get(); uint32_t hitIndex = entity->GetHitListIndex(); auto slot = std::lower_bound(hits.begin(), hits.end(), hitIndex); if (slot == hits.end() || *slot != hitIndex) hits.insert(slot, hitIndex); if (entity->type == ENTITY_BOMB) return; Entity* source = spawnerEntity ? spawnerEntity.get() : this; bool isVersus = g_game->deathmatchManager.is_active(); if (entity->type == ENTITY_PLAYER) { if (!isVersus) { entity->TakeDamage(PLAYER_HIT_DAMAGE, DAMAGE_LASER, EntityRef(source), LASER_HIT_COUNTDOWN); return; } if (IsDescendantOf(entity)) return; } else if (entity->type == ENTITY_FAMILIAR && !isVersus && (entity->variant == Entity_Familiar::ISAACS_HEART || (g_game->challenge == CHALLENGE_GUARDIAN && entity->variant == Entity_Familiar::PUNCHING_BAG))) { Entity_Player* player = static_cast(entity)->player; player->TakeDamage(PLAYER_HIT_DAMAGE, DAMAGE_LASER | DAMAGE_ISAAC_HURT, EntityRef(source), LASER_HIT_COUNTDOWN); return; } uint64_t damageFlags = DAMAGE_LASER | tear_damage_flags_get(tearFlags, this); Entity_Tear::ApplyTearFlagEffects(entity, pos, tearFlags, this, damage); if (entity->HasEntityFlags(FLAG_BRIMSTONE_MARKED) && is_thick_variant()) { int sound = SOUND_MEATY_DEATHS; seed_fart_sound_override(&sound); g_manager->sfxManager.Play(sound, {.volume = MARKED_SOUND_VOLUME, .frameDelay = MARKED_SOUND_DELAY}); entity->AddEntityFlags(FLAG_EXTRA_GORE); damage = damage + damage + MARKED_DAMAGE_EXTRA; } if (blackHpDropChance > 0 && entity->IsActiveEnemy(DEAD_EXCLUDED)) { RNG roll = BLACK_HEART_RNG; roll._seed = entity->initSeed; if (roll.RandomFloat() < blackHpDropChance) damageFlags |= DAMAGE_SPAWN_BLACK_HEART; } if (isVersus && tearFlags[TEAR_LASERSHOT]) damageFlags |= DAMAGE_LASER; entity->TakeDamage(damage, damageFlags, EntityRef(source), LASER_HIT_COUNTDOWN); } // 00971590 Hurts the grid entity in a cell the beam crosses. One time in four a standing one is broken by an Acid or // Rocks laser (bridging the pit beyond it). Whether the hurt took. bool Entity_Laser::damage_grid_entity(int gridIndex, const Vector& direction) { if (gridIndex < 0 || gridIndex >= ROOM_GRID_CELLS) return false; Room& room = *g_game->room; GridEntity* grid = room.GetGridEntity((uint32_t)gridIndex); if (!grid) return false; bool isStanding = grid->collisionClass != COLLISION_NONE && grid->collisionClass != COLLISION_PIT; if (isStanding && (Random() & GRID_HURT_CHANCE_MASK) == 0) { TearFlags flags = tearFlags; Entity* spawner = spawnerEntity; Entity_Player* player = spawner && spawner->type == ENTITY_PLAYER ? spawner->ToPlayer() : nullptr; if (spawner && spawner->type == ENTITY_FAMILIAR && spawner->variant == Entity_Familiar::INCUBUS) player = static_cast(spawner)->player; if (player) flags |= player->GetTearHitParams(WEAPON_LASER, 1, 0, spawner).tearFlags; bool isBreaking = flags[TEAR_ACID] || flags[TEAR_ROCK_FLAG]; if (isBreaking && grid->CanTakeDamageFromTearEffects() && grid->Destroy(false, EntityRef(this))) { Vector step = vector_cardinal(direction); if (!vector_is_zero(step)) { int beyond = room.GetGridIndex(vector_add(grid->Position(), vector_scale(step, GRID_CELL_SIZE))); if (beyond >= 0) room_bridge_make(room.GetGridEntity((uint32_t)beyond), grid); } } } return grid->Hurt(1, EntityRef(this)); } // 00970cb0 What the beam's path meets on the grid: the cells across its width (20 apart) it covers, hurt once each, // and the room's edge, nearest along the path (beyond it the last point inside, for a beam that leaves the room). // Every beam of the players' also hurts each grid entity within its width along its angle. void Entity_Laser::find_nearest_grid_hit(const Vector& offset) { Room& room = *g_game->room; if (isSampleLaser && homingLaser.nonOptimizedSamples.size() > 1) { const std::vector& samples = homingLaser.nonOptimizedSamples; size_t count = samples.size(); std::map crossed; Vector previous = vector_add(samples[0], offset); Vector lastInRoom = previous; Vector lastInRoomDirection{}; float lastInRoomDistance = 0; float travelled = 0; Vector last{}; // Records a point across the beam: past the room's side it stops a Continuum beam, inside it marks its cell. auto probe = [&](const Vector& point, const Vector& direction) { if (!room.IsPositionInRoom(point, ROOM_SIDE_MARGIN)) { if (tearFlags[TEAR_CONTINUUM] && travelled < impactDistance) { impactDistance = travelled; impactPosition = previous; impactDirection = direction; } return; } int column = (int)((point.x - GRID_ORIGIN_X) / GRID_CELL_SIZE + 0.5f); int row = (int)((point.y - GRID_ORIGIN_Y) / GRID_CELL_SIZE + 0.5f); int index = room.GetGridIndexByTile(column, row); uint32_t collision = index >= 0 ? room.GetGridCollision(index) : COLLISION_NONE; if (index >= 0 && collision != COLLISION_NONE && collision != COLLISION_PIT) crossed.try_emplace(index, direction); }; for (size_t i = 0; i <= count; i++) { Vector point{}; Vector segment{}; if (i < count) { point = vector_add(samples[i], offset); segment = i < count - 1 ? vector_sub(samples[i + 1], samples[i]) : vector_sub(samples[i], samples[i - 1]); } else { segment = vector_sub(samples[count - 1], samples[count - 2]); point = vector_add(vector_add(samples[count - 1], segment), offset); } float length = vector_length(segment); Vector direction = vector_scale(segment, 1 / length); Vector side = vector_make(direction.y, -direction.x); if (room.IsPositionInRoom(point, 0)) { lastInRoomDistance = travelled; lastInRoom = point; lastInRoomDirection = direction; } for (float width = 0; width < size; width += GRID_SWEEP_STEP) { probe(vector_add(point, vector_scale(side, width)), direction); if (width != 0) probe(vector_sub(point, vector_scale(side, width)), direction); } travelled += length; previous = point; last = point; } for (auto& [index, direction] : crossed) damage_grid_entity(index, direction); if (!room.IsPositionInRoom(last, 0) && lastInRoomDistance < impactDistance && !IsCircleLaser()) { impactDistance = lastInRoomDistance; impactPosition = lastInRoom; impactDirection = lastInRoomDirection; } } Vector direction = vector_from_angle(angleDegrees); Entity* owner = parent; bool isPlayersParent = owner && (owner->type == ENTITY_PLAYER || owner->type == ENTITY_FAMILIAR || owner->spawnerType == ENTITY_PLAYER); if (!isPlayersParent && spawnerType != ENTITY_PLAYER && spawnerType != ENTITY_FAMILIAR) return; float reach = maxDistance > 0 ? size + maxDistance : INFINITY; int cells = room.gridHeight * room.gridWidth; for (int index = 0; index < cells && index < ROOM_GRID_CELLS; index++) { if (!room.gridEntities[(size_t)index]) continue; Vector cell = vector_make((float)(index % room.gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_X, (float)(index / room.gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_Y); Vector relative = vector_add(vector_sub(cell, pos), offset); float along = vector_dot(relative, direction); float across = relative.y * direction.x - relative.x * direction.y; if (std::abs(across) < size + GRID_REACH_EXTRA && along > 0 && along <= reach) damage_grid_entity(index, direction); } } // Splashes a thick beam throws off what it hits: up to three drops across the part of the beam's width the entity // covers, in the beam's sprite color, and a red spray off a Brimstone-marked one. void Entity_Laser::splash_spawn(const Vector& center, const Vector& along, float from, float to, Entity& target) { const AnimationFrame* frame = sprite.animState.GetLayerFrame(0); LayerState* layer = sprite.GetLayer(0); ColorMod splash = sprite.color; if (layer) color_multiply(splash, layer->color); if (frame) color_multiply(splash, frame->color); Vector side = vector_make(along.y, -along.x); float height = posOffset.y; int drops = (int)(Random() & 3); for (int i = 0; i < drops; i++) { uint32_t seed = Random(); float speed = random_unit() * SPLASH_SPEED_RANGE + SPLASH_SPEED_MIN; float angle = random_unit() * SPLASH_HALF_TURN * 2; Vector velocity = vector_add(vector_make(std::cos(angle), std::sin(angle)), vector_scale(along, speed)); float across = (to - from) * random_unit() + from; Vector position = vector_add(vector_add(center, vector_scale(side, across)), vector_scale(along, SPLASH_SPREAD * random_unit())); Entity* drop = g_game->Spawn({.position = position, .velocity = velocity, .subType = 1, .type = ENTITY_EFFECT, .variant = EFFECT_WATER_SPLASH, .seed = seed}); drop->sprite.scale = vector_scale(drop->sprite.scale, SPLASH_SCALE); drop->SetColor(splash, -1, COLOR_PRIORITY_DEFAULT, false, true); drop->posOffset = vector_make(0, height); drop->Update(); } if (!target.HasEntityFlags(FLAG_BRIMSTONE_MARKED)) return; ColorMod marked = {{MARKED_TINT_RED, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 0}}; color_multiply(marked, sprite.color); uint32_t seed = Random(); float speed = random_unit() * MARKED_SPLASH_SPEED_RANGE + MARKED_SPLASH_SPEED_MIN; float angle = random_unit() * SPLASH_HALF_TURN * 2; Vector velocity = vector_add(vector_make(std::cos(angle), std::sin(angle)), vector_scale(along, speed)); float across = (to - from) * random_unit() + from; Entity* spray = g_game->Spawn({.position = vector_add(center, vector_scale(side, across)), .velocity = velocity, .subType = MARKED_SPRAY_SUBTYPE, .type = ENTITY_EFFECT, .variant = EFFECT_BLOOD_EXPLOSION, .seed = seed}); spray->SetColor(marked, -1, COLOR_PRIORITY_DEFAULT, false, true); spray->posOffset = vector_make(0, height); spray->sprite.rotation = random_unit() * MARKED_ROTATION_RANGE; spray->Update(); } // 00971810 Hits what the beam crosses, for a damage. A straight beam hits what lies within its width along its // angle and length. A path beam takes the entities it may hurt (with the small critters it kills, the players' // bombs it pushes, and a projectile Lost Contact catches now and then), finds where each crosses its segments, and // marks the nearest as where it stops. Its hits grow with distance under Lump of Coal and fade under Proptosis. void Entity_Laser::update_line_hits(float damage) { Room& room = *g_game->room; if (!isSampleLaser) { Vector direction = vector_from_angle(angleDegrees); for (size_t i = 0; i < room.entityList.updateEL.size(); i++) { Entity* entity = room.entityList.updateEL[i]; if (!CanDamageEntity(entity)) continue; Vector relative = vector_sub(entity->pos, pos); float along = vector_dot(relative, direction); float across = std::abs(direction.y * relative.x - direction.x * relative.y); float reach = variant == LASER_PRIDE ? vector_length(relative) * RING_REACH_SCALE : entity->size + size; if (across >= reach || along <= 0 || along >= std::abs(posOffset.y) + laserLength) continue; DoDamage(entity, damage); if (is_knocked_back(*this, *entity)) laser_push(*this, *entity, direction, entity->mass); if (!is_thick_variant()) continue; Vector center = vector_add(pos, vector_scale(direction, along)); float offset = vector_dot(vector_sub(entity->pos, center), vector_make(direction.y, -direction.x)); float from = std::max(offset - entity->size, -size); float to = std::min(offset + entity->size, size); if (from + SPLASH_EDGE < to) splash_spawn(center, direction, from, to, *entity); } return; } std::vector candidates; candidates.reserve(10); bool isShielded = tearFlags[TEAR_SHIELDED]; for (size_t i = 0; i < room.entityList.updateEL.size(); i++) { Entity* entity = room.entityList.updateEL[i]; bool isCritter = entity->type == ENTITY_EFFECT && std::find(std::begin(PULLED_EFFECTS), std::end(PULLED_EFFECTS), entity->variant) != std::end(PULLED_EFFECTS); bool isCandidate = isCritter || CanDamageEntity(entity); if (!isCandidate && entity->type == ENTITY_BOMB) isCandidate = is_players_laser(); else if (!isCandidate && isShielded && entity->type == ENTITY_PROJECTILE && !(static_cast(entity)->projectileFlags & PROJECTILE_CANT_HIT_PLAYER)) isCandidate = (IsCircleLaser() && Random() % SHIELD_RING_CHANCE == 0) || Random() % SHIELD_CHANCE == 0; if (isCandidate) candidates.push_back(entity); bool isPulled = entity->IsVulnerableEnemy(nullptr) || entity->type == ENTITY_PICKUP; if (tearFlags[TEAR_ATTRACTOR] && isPulled) reconstruction_missing("Entity_Laser::update_line_hits 00971810: Strange Attractor's pull"); } const std::vector& samples = homingLaser.samples; for (Entity* entity : candidates) { float travelled = 0; for (size_t i = 0; i + 1 < samples.size(); i++) { Vector end = samples[i + 1]; bool isLastSegment = i == samples.size() - 2; if (!IsCircleLaser() && isLastSegment && !isGridHit && maxDistance <= 0) end = vector_add(end, vector_resized(vector_sub(end, samples[i]), PATH_END_REACH)); SegmentProjection projection = segment_project_point(entity->pos, samples[i], end); float length = vector_length(vector_sub(end, samples[i])); if (i == 0 && is_thick_variant()) { Vector behind = vector_sub(samples[0], vector_scale(vector_from_angle(angleDegrees), THICK_BACK_REACH)); float behindSquared = vector_length_squared(vector_sub(entity->pos, behind)); if (behindSquared < projection.distanceSquared) projection = {behindSquared, 0}; } float reach = entity->size + size; if (reach * reach <= projection.distanceSquared) { travelled += length; continue; } if (entity->type == ENTITY_PROJECTILE) { static_cast(entity)->projectileFlags = 0; entity->isDead = true; break; } if (entity->type == ENTITY_EFFECT) { entity->isDead = true; break; } float gap = std::sqrt(projection.distanceSquared) - size; float sizeSquared = entity->size * entity->size; float depth = sizeSquared > gap * gap ? std::sqrt(sizeSquared - gap * gap) : 0; Vector direction = vector_scale(vector_sub(end, samples[i]), 1 / length); float distance = length * projection.t + travelled; if (distance - depth < impactDistance) { impactDistance = distance - depth; impactPosition = vector_add(samples[i], vector_scale(direction, length * projection.t - depth)); impactDirection = direction; } bool isSticky = tear_flags_any(tearFlags, {TEAR_STICKY, TEAR_BOOGER_FLAG, TEAR_SPORE_FLAG}); if (tearFlags[TEAR_MYSTERIOUS_LIQUID_CREEP] || (isSticky && !entity->isDead && entity->IsEnemy())) reconstruction_missing( "Entity_Laser::update_line_hits 00971810: the creep and sticking tears of a hit"); float hitDamage = damage; if (!IsCircleLaser()) { if (tearFlags[TEAR_GROW]) hitDamage *= std::min(distance, GROW_RANGE) * GROW_GAIN / GROW_RANGE + 1; if (tearFlags[TEAR_SHRINK]) hitDamage *= (1 - std::min(distance, SHRINK_RANGE) / SHRINK_RANGE) * 2; hitDamage = std::max(hitDamage, MINIMUM_DAMAGE); } DoDamage(entity, hitDamage); if ((!IsCircleLaser() || subtype == LASER_SUBTYPE_RING_PROJECTILE) && is_knocked_back(*this, *entity)) { Vector push = subtype == LASER_SUBTYPE_RING_PROJECTILE ? vector_normalized(velocity) : direction; laser_push(*this, *entity, push, entity->collision_mass_get(this)); } if (is_thick_variant()) { Vector center = vector_add(samples[i], vector_scale(vector_sub(samples[i + 1], samples[i]), projection.t)); float offset = vector_dot(vector_sub(entity->pos, center), vector_make(-direction.y, direction.x)); float from = std::max(offset - entity->size, -size); float to = std::min(offset + entity->size, size); if (from + SPLASH_EDGE < to) splash_spawn(center, direction, from, to, *entity); } break; } } } // 0096d3f0 What the beam's tear flags do where it ends: explosions, split and quad split tears, Rift, Jacob's // Ladder's arcs. None of them is reconstructed yet. void Entity_Laser::impact_tear_flag_effects(const Vector&, const Vector&) { if (tear_flags_any(tearFlags, {TEAR_EXPLOSIVE, TEAR_SPLIT, TEAR_QUADSPLIT, TEAR_RIFT, TEAR_JACOBS})) reconstruction_missing("Entity_Laser::impact_tear_flag_effects 0096d3f0"); } // How a ring's radius changes with its tear flags and age, before it is drawn: pulsing, growing or shrinking with the // distance from its player, and a flying ring springing open over its first frames (wider than its radius at first). static float ring_radius_get(Entity_Laser& laser, Entity_Player* player, float& widthScale) { float radius = laser.radius; if (laser.parent && laser.parent->type == ENTITY_FAMILIAR) radius *= RING_FAMILIAR_SCALE; if (laser.tearFlags[TEAR_PULSE]) radius += std::sin(laser.updateTime * RING_PULSE_RATE) * RING_PULSE_SIZE; if (laser.subtype == LASER_SUBTYPE_RING_FOLLOW_PARENT && laser.parent == player) return radius; float distance = player ? std::min(vector_length(vector_sub(laser.pos, player->pos)), RING_GROW_RANGE) : 0; if (laser.tearFlags[TEAR_GROW]) radius += distance * RING_GROW_SIZE / RING_GROW_RANGE; if (laser.tearFlags[TEAR_SHRINK]) radius += (1 - distance / RING_GROW_RANGE) * RING_GROW_SIZE; if (laser.subtype != LASER_SUBTYPE_RING_PROJECTILE) return radius; int age = g_game->frameCount - laser.spawnFrame; if (age >= RING_OPEN_FRAMES) return radius; float t = 1 - (float)age / RING_OPEN_FRAMES; float opened = std::max((1 - (t * t * t - std::sin(t * PI_F) * t)) * radius, RING_OPEN_MIN); if (opened > radius) widthScale = opened / radius; return std::min(opened, radius); } // A flying ring at the walls: it bounces off them once with Rubber Cement, and otherwise starts fading when it flies // into one. static void ring_walls_update(Entity_Laser& laser, float radius) { Vector clamped = g_game->room->GetClampedPosition(laser.pos, radius); if (!laser.tearFlags[TEAR_BOUNCE]) { if (laser.tearFlags[TEAR_CONTINUUM]) return; float facing = vector_dot(vector_normalized(vector_sub(clamped, laser.pos)), vector_normalized(laser.velocity)); if (facing < -RING_WALL_FACING && laser.timeout == 0) laser.timeout = RING_FADE_FRAMES; return; } for (int axis = 0; axis < 2; axis++) { float& position = axis == 0 ? laser.pos.x : laser.pos.y; float& speed = axis == 0 ? laser.velocity.x : laser.velocity.y; float wall = axis == 0 ? clamped.x : clamped.y; if (!((wall < position && speed > 0) || (position < wall && speed < 0))) continue; position = wall; speed = -speed; laser.tearFlags.reset(TEAR_BOUNCE); laser.heldTearFlags.set(TEAR_BOUNCE); } } // A ring that ended: Tech X's thin ring plays its fade and grows while it does, every other ring goes. static void ring_fade_update(Entity_Laser& laser, float& widthScale) { if (laser.variant == LASER_THIN_RED) { const AnimationData* animation = laser.sprite.animState.animData; if (!animation || !animation->isLooping) widthScale = (animation ? laser.sprite.animState.animFrame : -1) * RING_FADE_GROWTH + 1; else laser.sprite.Play(laser.sprite.GetAnimation() + "Fade"); if (laser.sprite.IsPlaying()) return; } laser.Remove(); } // 0097baa0 A ring's frame (Tech X's, Ludovico's, the ring bosses'): it follows its parent, flies and fades or bounces // off the walls, finds its radius, lays its circle of samples (cut by the grid) and hits what it covers every other // frame. The light ring hurts enemies inside it every second instead. void Entity_Laser::UpdateHits() { refresh_tear_params(); if (isFirstUpdate || !isOneHit) activeTearFlags = tearFlags; bool isHitFrame = !isDead && !isInterpolating && variant != LASER_LIGHT_RING && (isFirstUpdate || GetIntervalTicks(RING_HIT_INTERVAL, 0)); if (isHitFrame && !parentLaser) hitList.clear(); if (!isInterpolating && subtype == LASER_SUBTYPE_RING_LUDOVICO) friction *= RING_LUDOVICO_FRICTION; homingLaser.bezier.clear(); homingLaser.origin = pos; homingLaser.endPoint = {}; Entity_Player* player = spawnerEntity && spawnerEntity->type == ENTITY_PLAYER ? spawnerEntity->ToPlayer() : nullptr; float widthScale = 1; float radiusNow = ring_radius_get(*this, player, widthScale); bool isTimed = subtype == LASER_SUBTYPE_RING_PROJECTILE || subtype == LASER_SUBTYPE_RING_FOLLOW_PARENT; if (subtype == LASER_SUBTYPE_RING_PROJECTILE) ring_walls_update(*this, radiusNow); else if (subtype == LASER_SUBTYPE_RING_FOLLOW_PARENT && (!parent || parent->isDead) && !isDead) { isDead = true; timeout = 0; } if (isTimed && isDead) ring_fade_update(*this, widthScale); if (isTimed && timeout > 0 && !isInterpolating) { if (variant != LASER_THIN_RED && subtype == LASER_SUBTYPE_RING_PROJECTILE) { widthScale = (float)(RING_FADE_FRAMES - timeout) * RING_FADE_GROWTH + 1; sprite.color = color; sprite.color._tint[3] = (float)std::min(timeout, RING_FADE_FRAMES) * sprite.color._tint[3] / RING_FADE_FRAMES; } if (--timeout < 1) isDead = true; } float blend = RING_SAMPLE_BLEND; if (subtype == LASER_SUBTYPE_RING_FOLLOW_PARENT) { if (parent && !isDisableFollowParent) { pos = vector_add(parent->pos, parentOffset); velocity = parent->velocity; } if (variant == LASER_THICK_RED || variant == LASER_BRIM_TECH || variant == LASER_THICKER_RED || variant == LASER_THICKER_BRIM_TECH) { sprite.color = COLOR_DEFAULT; sprite.color._tint[3] = (float)std::min(timeout, RING_BRIMSTONE_FADE) / RING_BRIMSTONE_FADE; } } else if (!tearFlags[TEAR_CONTINUUM]) pos = g_game->room->GetClampedPosition(pos, radiusNow); else if (!isInterpolating) reconstruction_missing("Entity_Laser::UpdateHits 0097baa0: Continuum's ring wrapping"); if ((variant == LASER_THIN_RED || variant == LASER_ELECTRIC) && child) { Vector childPosition = pos; if (!isInterpolating && !tearFlags[TEAR_CONTINUUM] && subtype != LASER_SUBTYPE_RING_FOLLOW_PARENT) childPosition = g_game->room->GetClampedPosition(vector_add(pos, vector_scale(velocity, friction)), radiusNow); if (subtype == LASER_SUBTYPE_RING_PROJECTILE) childPosition = vector_sub(childPosition, velocity); child->pos = childPosition; child->SetColor(sprite.color, -1, COLOR_PRIORITY_DEFAULT, false, true); child->posOffset = posOffset; } homingLaser.build_ring_bezier(pos, tearFlags[TEAR_HOMING], parent, radiusNow * widthScale); homingLaser.CalculateSamples(blend); homingLaser.remove_collinear_samples(RING_COLLINEAR_TOLERANCE); if (tearFlags[TEAR_WIGGLE]) { bool isKnife = parent && parent->type == ENTITY_KNIFE; float amplitude = player ? worm_multiplier_get(player, TEAR_WIGGLE) : 1; homingLaser.apply_sine_offset(amplitude, isKnife ? (float)g_game->frameCount * RING_WIGGLE_RATE : 0); } isGridHit = false; if (entityGridCollisionClass != GRIDCOLL_NONE) isGridHit = homingLaser.clip_samples_to_grid(vector_scale(posOffset, RING_GRID_OFFSET_SCALE), entityGridCollisionClass); if (isHitFrame) update_endpoint_and_hits(); else if (!isDead && !isInterpolating && variant == LASER_LIGHT_RING && GetIntervalTicks(LIGHT_RING_INTERVAL, 0)) for (Entity* entity : entity_query_radius(pos, radius, QUERY_ENEMIES)) if (entity->IsVulnerableEnemy(nullptr) && !IsDescendantOf(entity)) entity->TakeDamage(collisionDamage, 0, EntityRef(this), LASER_HIT_COUNTDOWN); if (isHitFrame && (std::isfinite(impactDistance) || isGridHit)) impact_tear_flag_effects(impactPosition, impactDirection); }