Files
isaac-port/src/entity_tear.cpp
T

1630 lines
71 KiB
C++

#include "entity_tear.h"
#include "entity_effect.h"
#include "entity_familiar.h"
#include "entity_player.h"
#include "game.h"
#include "grid_entity.h"
#include "log.h"
#include "lua_engine.h"
#include "manager.h"
#include "npc_ai.h"
#include "room.h"
#include "room_grid.h"
#include "sfx_manager.h"
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
constexpr float TEAR_HEIGHT_START = -23;
constexpr float TEAR_DAMAGE_DEFAULT = 3.5f;
constexpr float TEAR_FALL_SPREAD = 0.2f;
constexpr float TEAR_HOMING_FRICTION = 0.85f;
constexpr float TEAR_KNOCKBACK_MULTIPLIER = 1.7f;
constexpr float TEAR_RANGE_DEFAULT = 260;
constexpr float TEAR_SCALE_MIN = 0.01f;
constexpr float TEAR_FLOOR_HEIGHT = -5;
constexpr float TEAR_GRID_HIT_HEIGHT = -60;
constexpr float CRAWLSPACE_OFFSET_Y = -18;
constexpr float CRAWLSPACE_RANGE_SHARE = 0.6f;
constexpr float CRAWLSPACE_ROOM_MARGIN = -256;
constexpr float CRAWLSPACE_FIRE_RAISE = 4;
constexpr float CRAWLSPACE_LEVEL_SLOPE = 0.05f;
constexpr float GRAVITY_MIN_ACCEL = 0.001f;
constexpr float GRAVITY_PULL = 0.1f;
constexpr float GRAVITY_FALL_DRAG = 0.9f;
constexpr float HOVER_HEIGHT_BOB = 0.5f;
constexpr int HOVER_BOB_FRAMES = 15;
constexpr float ROOM_SLOWDOWN_SCALE = 0.75f;
constexpr float RIGHT_ANGLE = 90;
// The height offset a tear flying without gravity draws at: a fixed lift, and a curve near the floor.
constexpr float HOVER_OFFSET_SCALE = 0.4f;
constexpr float FIXED_HEIGHT_OFFSET = -8;
constexpr float GFUEL_NAIL_OFFSET = -12;
// The scale each RegularTear%d animation (1 to 13) draws at, the one a tear plays being the first at least its scale
// less the margin. A grown tear scales its layers by its scale over its animation's.
constexpr std::array<float, 13> TEAR_ANIMATION_SCALES = {0.25f, 0.5f, 0.625f, 0.75f, 0.875f, 1.0f, 1.125f,
1.375f, 1.625f, 1.875f, 2.125f, 2.5f, 2.75f};
constexpr float TEAR_ANIMATION_MARGIN = 0.05f;
constexpr int TEAR_ANIMATION_BASE = 100;
constexpr int TEAR_ANIMATION_NAME_SIZE = 32;
constexpr float TEAR_EFFECT_SCALE = 0.45f;
// The tear effect sprite's flag for drawing behind the tear.
constexpr unsigned int TEAR_EFFECT_BEHIND = 1 << 13;
constexpr float GFUEL_SIZE_DIVISOR = 3;
constexpr float GFUEL_NAIL_WIDTH = 3;
// The splash a dying tear leaves: the poof sizes by its scale, the sounds, and the stains blood tears leave.
constexpr float POOF_SCALE_SMALL = 0.4f;
constexpr float POOF_SCALE_LARGE = 0.8f;
constexpr float SWORD_BEAM_VOLUME = 0.3f;
constexpr float SWORD_BEAM_PITCH = 2;
constexpr float SWORD_BEAM_PITCH_SPREAD = 0.5f;
constexpr int SWORD_BEAM_POOF_SUBTYPE = 22;
constexpr int STAIN_COUNT_MAX = 5;
constexpr float STAIN_SPREAD = 24;
constexpr float STAIN_SCALE = 0.3f;
constexpr float STAIN_ALPHA = 0.08f;
constexpr float MASCARA_ALPHA = 0.2f;
constexpr float MASCARA_ALPHA_SPREAD = 0.3f;
constexpr ColorMod STAIN_COLOR = {{0, 0, 0, STAIN_ALPHA}, {0, 0, 0, 0}, {0, 0, 0}};
constexpr ColorMod NUMBER_ONE_STAIN_COLOR = {{0, 0, 0, 0.5f}, {0, 0, 0, 0}, {150 / 255.0f, 150 / 255.0f, 0}};
// The tint a room's slowdown (the Broken Watch's) lays over a tear for two frames.
constexpr ColorMod SLOWDOWN_COLOR = {{1, 1, 1.3f, 1}, {0, 0, 0, 0}, {40 / 255.0f, 40 / 255.0f, 40 / 255.0f}};
constexpr int SLOWDOWN_COLOR_FRAMES = 2;
constexpr int COLOR_PRIORITY_TOP = 255;
// What the tear's grid hit does to rocks: one hit, two for a strong tear.
constexpr float STRONG_TEAR_DAMAGE = 10;
// The grid path below which a wall the players pass stops tears.
constexpr int GRID_PATH_TEAR_WALL = 3000;
// A tear spawned with FLAG_NO_SPIKE_DAMAGE starts with more friction, easing off over its first updates.
constexpr float LAUNCH_DRAG_TIME = 5;
constexpr float LAUNCH_DRAG_FRICTION = 0.55f;
// How the flags move a tear: Anti-Gravity's wait, homing's search and pull, Hook Worm's turns, Lump of Coal's growth,
// Proptosis' shrinking, My Reflection's pull, Pulse Worm's beat and Flat Worm's stretch.
constexpr int WAIT_FRAMES = 90;
constexpr int HOMING_SEARCH_FRAMES = 4;
constexpr float HOMING_LOOK_AHEAD = 5;
constexpr float HOMING_RADIUS = 128;
constexpr float HOMING_SCORE_NONE = 1e9f;
constexpr float HOMING_PULL = 2;
constexpr int SQUARE_START_FRAME = 3;
constexpr int SQUARE_LOOP_START = 5;
constexpr int SQUARE_LOOP_FRAMES = 22;
constexpr int SQUARE_TURN_LEFT_SLOW = 0;
constexpr int SQUARE_TURN_LEFT = 7;
constexpr int SQUARE_TURN_RIGHT_SLOW = 10;
constexpr int SQUARE_TURN_RIGHT = 19;
constexpr float GROW_DAMAGE = 0.014f;
constexpr float GROW_SCALE = 0.01f;
constexpr float SHRINK_START = 4;
constexpr float SHRINK_FAST = 0.08f;
constexpr float SHRINK_SLOW = 0.03f;
constexpr float SHRINK_FAST_SHARE = 3;
constexpr float SHRINK_DAMAGE_MIN = 0.1f;
constexpr int SPECTRAL_GRID_CHANCE = 8;
constexpr float BOOMERANG_ANCHOR_LIFT = 2;
constexpr float BOOMERANG_RANGE_START = 60;
constexpr float BOOMERANG_REACH_MIN = 20;
constexpr float BOOMERANG_SPEED = 10;
constexpr float PULSE_STRENGTH = 0.3f;
constexpr float PULSE_RATE = 0.7f;
constexpr float PULSE_BASE = 0.6f;
constexpr float PULSE_OFFSET = 0.7f;
constexpr float SQUARE_SPEED_SHARE = 0.5f;
constexpr float BOOMERANG_REACH_SHARE = 0.5f;
constexpr float FLAT_STRETCH = 0.5f;
constexpr float PUPULA_SPIN = 45;
constexpr float TURN_AWAY = -0.1f;
constexpr int BOUNCE_SOUND = 905;
// The wiggles: Wiggle Worm's sideways sway, Ring Worm's spiral and Ouroboros Worm's wide one.
constexpr float WIGGLE_RATE = 0.7f;
constexpr float WIGGLE_SPEED_SHARE = 0.5f;
constexpr float WIGGLE_MAX = 5;
constexpr float SPIRAL_RATE = 0.7f;
constexpr float SPIRAL_SIDE = 10;
constexpr float SPIRAL_FORWARD = 20;
constexpr float BIG_SPIRAL_RATE = 0.2f;
constexpr float BIG_SPIRAL_RADIUS = 15;
constexpr float QUARTER_TURN = 1.5707964f;
constexpr float HALF_FRAME = 0.5f;
// The pieces a dying tear breaks into: Parasite's two halves, Compound Fracture's shards and Cricket's Body's four.
constexpr float SPLIT_DAMAGE_MIN = 1;
constexpr float SPLIT_HEIGHT_SHARE = 1.5f;
constexpr float SPLIT_DAMAGE = 0.5f;
constexpr float SPLIT_RISING_DAMAGE = 0.25f;
constexpr float SPLIT_RISING_ACCEL = 2;
constexpr float SPLIT_SCALE = 0.5f;
constexpr float BONE_DAMAGE = 0.5f;
constexpr int BONE_SHARDS = 2;
constexpr const char* BROKEN_BONE_SHEET = "gfx/tears_brokenbone.png";
constexpr int QUADSPLIT_PIECES = 4;
constexpr float QUADSPLIT_SLOW_SQUARED = 0.1f;
constexpr float QUADSPLIT_SLOW_SPEED = 10;
constexpr float QUADSPLIT_DAMAGE = 0.5f;
constexpr float QUADSPLIT_SCALE = 0.6f;
constexpr float QUADSPLIT_HEIGHT_SHARE = 0.5f;
constexpr float QUADSPLIT_FALL_SHARE = 0.3f;
constexpr float PLAYER_TEAR_HEIGHT = -23.75f;
// The creep Mysterious Liquid's and It Hurts' tears leave where they die.
constexpr float CREEP_MARGIN = 15;
constexpr float CREEP_SCALE = 0.4f;
// What a hit's flags do: the slowing and its tint (Ball of Tar's dark), and the durations of the status effects.
constexpr int SLOW_DURATION = 60;
constexpr float SLOW_AMOUNT = 0.9f;
constexpr ColorMod SLOW_COLOR = {{1, 1, 1.3f, 1}, {0, 0, 0, 0}, {40 / 255.0f, 40 / 255.0f, 40 / 255.0f}};
constexpr ColorMod GISH_COLOR = {{0.2f, 0.2f, 0.2f, 1}, {0, 0, 0, 0}, {0, 0, 0}};
constexpr int POISON_DURATION = 40;
constexpr int POISON_DURATION_VERSUS = 60;
constexpr int FREEZE_DURATION = -50;
constexpr int FREEZE_DURATION_VERSUS = -45;
constexpr int CHARM_DURATION = 150;
constexpr int CONFUSION_DURATION = 150;
constexpr int CONFUSION_SPREAD = 30;
constexpr int PERMANENT_CONFUSION = -99999999;
constexpr int PERMANENT_CONFUSION_BOSS = -300;
constexpr int PERMANENT_CONFUSION_VERSUS = -240;
constexpr int FEAR_DURATION = -150;
constexpr int BURN_DURATION = 40;
constexpr int BURN_DURATION_LONG = 80;
constexpr int MIDAS_DURATION = 90;
constexpr int MAGNETIZE_DURATION = 150;
constexpr int BAIT_DURATION = 180;
constexpr int ICE_DURATION = 10;
constexpr int SHRINK_DURATION = -150;
constexpr int GREED_COIN_CHANCE = 20;
constexpr int HP_DROP_CHANCE = 3;
constexpr float HIT_DIRECTION_MIN_SPEED = 0.02f;
constexpr int EFFECT_FIRE_JET = 147;
constexpr int SOUND_TEAR_FIRE = 153;
constexpr int SOUND_FETUS_FIRE = 237;
constexpr float FETUS_FIRE_PITCH = 1.2f;
constexpr int SOUND_LITTLE_HORN = 868;
constexpr int SOUND_SWORD_BEAM_IMPACT = 49;
constexpr int SOUND_TECH_SWORD_BEAM_IMPACT = 134;
constexpr int SOUND_DELAY = 2;
// How Tiny Planet's and My Reflection's tears are thrown when fired.
constexpr float ORBIT_FALL_SCALE = 3;
constexpr float HYDROBOUNCE_LIFT = 15;
constexpr float HYDROBOUNCE_ACCEL = 3;
constexpr float BOOMERANG_FALL_SCALE = 0.5f;
constexpr float BOOMERANG_ACCEL_OFFSET = 0.08f;
constexpr float BOOMERANG_ACCEL_SCALE = 0.25f;
constexpr int COLLECTIBLE_EVES_MASCARA = 310;
constexpr uint32_t CHALLENGE_ONANS_STREAK = 29;
constexpr int TRINKET_PULSE_WORM = 9;
constexpr int TRINKET_WIGGLE_WORM = 10;
constexpr int TRINKET_RING_WORM = 11;
constexpr int TRINKET_FLAT_WORM = 12;
constexpr int TRINKET_HOOK_WORM = 26;
// Onan's Streak punishes a tear that misses with a hit to its player.
constexpr float STREAK_DAMAGE = 1;
constexpr int STREAK_DAMAGE_COUNTDOWN = 30;
constexpr const char* GFUEL_NAIL_ANM2 = "gfx/promo/gfuel/bullet tear.anm2";
constexpr const char* GFUEL_NAIL_BLOOD_ANM2 = "gfx/promo/gfuel/missile.anm2";
// The variants whose splash and flight are reconstructed: plain tears and the ones that only change the sprite.
constexpr std::array<int, 23> TEAR_PLAIN_VARIANTS = {
TEAR_BLUE, TEAR_BLOOD, TEAR_METALLIC, TEAR_FIRE_MIND, TEAR_DARK_MATTER,
TEAR_MYSTERIOUS, TEAR_LOST_CONTACT, TEAR_CUPID_BLUE, TEAR_CUPID_BLOOD, TEAR_PUPULA,
TEAR_PUPULA_BLOOD, TEAR_GODS_FLESH, TEAR_GODS_FLESH_BLOOD, TEAR_MULTIDIMENSIONAL, TEAR_GLAUCOMA,
TEAR_GLAUCOMA_BLOOD, TEAR_NEEDLE, TEAR_BELIAL, TEAR_HUNGRY, TEAR_FIST,
TEAR_ICE, TEAR_SWORD_BEAM, TEAR_TECH_SWORD_BEAM};
// The variants whose splash is a bullet poof rather than a tear poof.
constexpr std::array<int, 7> TEAR_BULLET_POOF_VARIANTS = {TEAR_BLOOD, TEAR_CUPID_BLOOD, TEAR_PUPULA_BLOOD,
TEAR_GODS_FLESH_BLOOD, TEAR_GLAUCOMA_BLOOD, TEAR_BELIAL,
TEAR_FIST};
// The variants that point along their flight.
constexpr std::array<int, 17> TEAR_ROTATED_VARIANTS = {
TEAR_CUPID_BLUE, TEAR_CUPID_BLOOD, TEAR_NAIL, TEAR_PUPULA, TEAR_PUPULA_BLOOD, TEAR_NAIL_BLOOD, TEAR_NEEDLE,
TEAR_EYE, TEAR_EYE_BLOOD, TEAR_COIN, TEAR_FIST, TEAR_ICE, TEAR_KEY, TEAR_KEY_BLOOD,
TEAR_ERASER, TEAR_SWORD_BEAM, TEAR_TECH_SWORD_BEAM};
// The variants that stain the floor where they splash.
constexpr std::array<int, 4> TEAR_STAINING_VARIANTS = {TEAR_BLUE, TEAR_GLAUCOMA, TEAR_GODS_FLESH, TEAR_HUNGRY};
// The variants that play BloodTear%d, Tooth%dMove, Rotate%d or Stone%dMove rather than RegularTear%d.
constexpr std::array<int, 6> BLOOD_ANIMATION_VARIANTS = {TEAR_BLOOD, TEAR_CUPID_BLOOD, TEAR_PUPULA_BLOOD,
TEAR_GODS_FLESH_BLOOD, TEAR_EYE_BLOOD, TEAR_GLAUCOMA_BLOOD};
constexpr std::array<int, 6> STONE_ANIMATION_VARIANTS = {TEAR_STONE, TEAR_BOOGER, TEAR_EGG,
TEAR_RAZOR, TEAR_BONE, TEAR_SPORE};
// The halo of a glowing tear, and the tear effects in the order SetTearFlags picks them: the flag that shows each and
// its sprite. Rift's tears show Little Horn's effect tinted.
constexpr const char* TEAR_HALO_ANM2 = "gfx/TearHalo.anm2";
constexpr ColorMod RIFT_EFFECT_COLOR = {{1, 0.7f, 0.7f, 1}, {0, 0, 0, 0}, {0, 0, 0}};
// A render flag the creep, fire and dark matter effects and their first layer carry. The flight turns such layers.
constexpr unsigned int TEAR_EFFECT_LAYERED = 1 << 12;
// A tear effect: the flag that shows it and its sprite.
struct TearEffect
{
int flag = 0;
const char* anm2 = nullptr;
};
constexpr std::array<TearEffect, 7> TEAR_EFFECTS = {{
{TEAR_HORN, "gfx/LittleHornTearEffect.anm2"},
{TEAR_RIFT, "gfx/LittleHornTearEffect.anm2"},
{TEAR_LIGHT_FROM_HEAVEN, "gfx/HolyLightTearEffect.anm2"},
{TEAR_JACOBS, "gfx/JacobsLadderTearEffect.anm2"},
{TEAR_MYSTERIOUS_LIQUID_CREEP, "gfx/MysteriousTearEffect.anm2"},
{TEAR_BURN, "gfx/FireMindTearEffect.anm2"},
{TEAR_DARK_MATTER_FLAG, "gfx/DarkMatterTearEffect.anm2"},
}};
// A flag whose behaviour is not reconstructed yet, and where the game stops when a tear carries it.
struct UnhandledFlag
{
int flag = 0;
const char* name = nullptr;
};
constexpr std::array<UnhandledFlag, 28> UPDATE_UNHANDLED_FLAGS = {{
{TEAR_LUDOVICO, "Entity_Tear::Update 006670f0: a Ludovico tear"},
{TEAR_DETONATE, "Entity_Tear::Update 006670f0: a detonating tear"},
{TEAR_LASER, "Entity_Tear::Update 006670f0: Technology Zero's lasers"},
{TEAR_LASERSHOT, "Entity_Tear::Update 006670f0: a laser shot tear"},
{TEAR_HYDROBOUNCE, "Entity_Tear::Update 006670f0: a bouncing water tear"},
{TEAR_EXPLOSIVE, "Entity_Tear::Update 006670f0: an explosive tear"},
{TEAR_BURSTSPLIT, "Entity_Tear::Update 006670f0: Haemolacria's burst"},
{TEAR_ORBIT, "Entity_Tear::Update 006670f0: an orbiting tear"},
{TEAR_ORBIT_ADVANCED, "Entity_Tear::Update 006670f0: an orbiting tear"},
{TEAR_FETUS_FLAG, "Entity_Tear::Update 006670f0: a fetus tear"},
{TEAR_OCCULT, "Entity_Tear::Update 006670f0: Eye of the Occult's steering"},
{TEAR_ATTRACTOR, "Entity_Tear::Update 006670f0: Strange Attractor's pull"},
{TEAR_STICKY, "Entity_Tear::Update 006670f0: a sticking tear"},
{TEAR_SPORE_FLAG, "Entity_Tear::Update 006670f0: a sticking tear"},
{TEAR_BOOGER_FLAG, "Entity_Tear::Update 006670f0: a sticking tear"},
{TEAR_GLOW, "Entity_Tear::Update 006670f0: Godhead's aura"},
{TEAR_DECELERATE, "Entity_Tear::Update 006670f0: a slowing tear"},
{TEAR_ACCELERATE, "Entity_Tear::Update 006670f0: a speeding tear"},
{TEAR_ABSORB, "Entity_Tear::Update 006670f0: Lachryphagy's absorbing"},
{TEAR_CHAIN, "Entity_Tear::Update 006670f0: a chained tear"},
{TEAR_TRACTOR_BEAM, "Entity_Tear::Update 006670f0: Tractor Beam's guide"},
{TEAR_POP, "Entity_Tear::Update 006670f0: Pop!'s bouncing"},
{TEAR_REROLL_ROCK_WISP, "Entity_Tear::Update 006670f0: a rock rerolling tear"},
{TEAR_CONTINUUM, "Entity_Tear::Update 006670f0: Continuum's wrapping"},
{TEAR_BOUNCE_WALLSONLY, "Entity_Tear::Update 006670f0: a wall bouncing tear"},
{TEAR_INTERVAL_FLAGS, "Entity_Tear::Update 006670f0: flags swapped on an interval"},
{TEAR_INTERVAL_SPEED, "Entity_Tear::Update 006670f0: a speed reset on an interval"},
{TEAR_PARENT_STEER, "Entity_Tear::Update 006670f0: a tear steering to its parent"},
}};
constexpr std::array<UnhandledFlag, 7> HIT_UNHANDLED_FLAGS = {{
{TEAR_COIN_DROP_DEATH, "Entity_Tear::ApplyTearFlagEffects 0067af60: a drop on death"},
{TEAR_CARD_DROP_DEATH, "Entity_Tear::ApplyTearFlagEffects 0067af60: a drop on death"},
{TEAR_RUNE_DROP_DEATH, "Entity_Tear::ApplyTearFlagEffects 0067af60: a drop on death"},
{TEAR_ECOLI, "Entity_Tear::ApplyTearFlagEffects 0067af60: E. Coli's poop"},
{TEAR_ENEMY_TO_WISP, "Entity_Tear::ApplyTearFlagEffects 0067af60: an enemy turned to a wisp"},
{TEAR_REROLL_ENEMY, "Entity_Tear::ApplyTearFlagEffects 0067af60: an enemy rerolled"},
{TEAR_MOM_STOMP_WISP, "Entity_Tear::ApplyTearFlagEffects 0067af60: Mom's stomp"},
}};
// The splash a dying tear leaves: its poof and its sound.
struct TearSplash
{
float pitch = 1;
float volume = 1;
int effect = 0;
int sound = 0;
int subType = 0;
};
template <size_t N>
static bool is_listed(const std::array<int, N>& list, int value)
{
return std::find(list.begin(), list.end(), value) != list.end();
}
// Stops the game at the first flag in the list a tear carries.
template <size_t N>
static void unhandled_check(const TearFlags& flags, const std::array<UnhandledFlag, N>& list)
{
for (const UnhandledFlag& unhandled : list)
if (flags[unhandled.flag]) reconstruction_missing(unhandled.name);
}
// How much of a per-tick factor is left over a step of timeScale ticks (Math::timescale_factor).
static float timescale_factor(float factor, float timeScale)
{
return timeScale == 1 ? factor : factor / ((factor + timeScale) - factor * timeScale);
}
// Whether the current room is a crawlspace, where tears drop under gravity.
static bool is_crawlspace()
{
return g_game->room->roomType == ROOM_DUNGEON;
}
// Whether the player is another machine's in an online game, whose shots the game fades.
static bool is_remote_player(Entity_Player* player)
{
NetplayManager& netplay = g_manager->netplayManager;
return player && netplay.is_online() && !netplay.IsIdxLocalPlayer(player->controllerIndex);
}
// Whether a tear is one of the nails the G-Fuel seed turns into bullets.
static bool is_gfuel_nail(int variant)
{
return (variant == TEAR_NAIL || variant == TEAR_NAIL_BLOOD) && g_game->seedEffects.HasSeedEffect(SEED_G_FUEL);
}
// Makes a sprite layer add its light to what is under it.
static void layer_additive_set(ANM2& sprite, int layerId)
{
LayerState* layer = sprite.GetLayer(layerId);
bool isPremultiplied = KAGE::Graphics::manager.isPremultipliedAlpha;
layer->blendMode[BLEND_EQUATION] = BLEND_EQUATION_ADD;
layer->blendMode[BLEND_RGB_SOURCE] = isPremultiplied ? BLEND_FACTOR_ONE : BLEND_FACTOR_SRC_ALPHA;
layer->blendMode[BLEND_RGB_DEST] = BLEND_FACTOR_ONE;
layer->blendMode[BLEND_ALPHA_SOURCE] = BLEND_FACTOR_ONE;
layer->blendMode[BLEND_ALPHA_DEST] = BLEND_FACTOR_ONE;
}
// In Onan's Streak, a tear that misses hurts its player.
static void streak_end(Entity_Player& player)
{
if (g_game->challenge != CHALLENGE_ONANS_STREAK) return;
player.TakeDamage(STREAK_DAMAGE, DAMAGE_INVINCIBLE, EntityRef(), STREAK_DAMAGE_COUNTDOWN);
}
// A vector turned a quarter turn, as Vector::Rotated turns it by 90 degrees.
static Vector vector_quarter_turn(Vector v)
{
float angle = RIGHT_ANGLE * DEGREES_TO_RADIANS;
return vector_make(v.x * std::cos(angle) - v.y * std::sin(angle), v.x * std::sin(angle) + v.y * std::cos(angle));
}
// 007c2d50 How strong a worm trinket makes its flag's motion: its multiplier, at least one, and one for the other
// flags or without a player.
float worm_multiplier_get(Entity_Player* player, int flag)
{
int trinket = 0;
switch (flag)
{
case TEAR_WIGGLE: trinket = TRINKET_WIGGLE_WORM; break;
case TEAR_PULSE: trinket = TRINKET_PULSE_WORM; break;
case TEAR_SPIRAL: trinket = TRINKET_RING_WORM; break;
case TEAR_FLAT: trinket = TRINKET_FLAT_WORM; break;
case TEAR_SQUARE: trinket = TRINKET_HOOK_WORM; break;
case TEAR_BIG_SPIRAL: trinket = TRINKET_OUROBOROS_WORM; break;
default: return 1;
}
return player ? (float)std::max(player->GetTrinketMultiplier(trinket), 1) : 1;
}
// 006660a0 Starts a tear 23 high with a slight random fall, base damage and scale, no flags, links or targets, and
// the sprite of its config. The brimstone balloon's glow and the G-Fuel nails' sprites add light.
void Entity_Tear::Init(int entityType, int entityVariant, int entitySubType, uint32_t seed)
{
Entity::Init(entityType, entityVariant, entitySubType, seed);
if (config) sprite.Load(config->anm2Path, GRAPHICS_LOAD);
entityGridCollisionClass = GRIDCOLL_BULLET;
collisionDamage = TEAR_DAMAGE_DEFAULT;
baseDamage = TEAR_DAMAGE_DEFAULT;
float fallSpread = random_unit();
fallingAccel = 0;
height = TEAR_HEIGHT_START;
fallingSpeed = (fallSpread - 0.5f) * TEAR_FALL_SPREAD;
posOffset.y = get_height_offset_y(TEAR_HEIGHT_START);
if (is_crawlspace()) posOffset.y = CRAWLSPACE_OFFSET_Y;
homingFriction = TEAR_HOMING_FRICTION;
fScale = 1;
baseScale = 1;
rotation = 0;
scaleAnimNum = -1;
knockbackMultiplier = TEAR_KNOCKBACK_MULTIPLIER;
maxHitPoints = 0;
tearFlags.reset();
waitFrames = 0;
continueVelocity = {};
hitList.clear();
posDisplacement = {};
parentOffset = {};
stickTarget = nullptr;
stickDiff = {};
techZeroLaser = nullptr;
techZeroTarget = nullptr;
laserShotLaser = nullptr;
linkPrev = nullptr;
linkNext = nullptr;
deadEyeIntensity = 0;
isMultidimensionalTouched = false;
isPrismTouched = false;
isFireSoundPending = true;
isCanTriggerStreakEnd = true;
isHovering = false;
isFireSoundMuted = false;
holdOffset = {};
holdTimer = 0;
popBounceCount = 0;
hitCount = 0;
deathFlags = 0;
if (variant == TEAR_BALLOON_BRIMSTONE) layer_additive_set(sprite, 1);
orbitAngle = 0;
orbitRadius = 0;
orbitVelocity = {};
tearRange = TEAR_RANGE_DEFAULT;
tearIdx = -1;
if (is_gfuel_nail(variant))
{
sprite.Load(variant == TEAR_NAIL ? GFUEL_NAIL_ANM2 : GFUEL_NAIL_BLOOD_ANM2, GRAPHICS_LOAD);
layer_additive_set(sprite, variant == TEAR_NAIL ? 0 : 1);
}
lua_engine_get().PostTearInit(this);
}
// 006670f0 Flies the tear for a frame, or splashes and removes it once it has died. While held it bobs at its
// parent, while waiting it hovers until its player stops firing, and its flags steer, grow, shrink and split it.
void Entity_Tear::Update()
{
if (isFireSoundPending)
{
play_fire_sound();
isFireSoundPending = false;
}
if (!is_listed(TEAR_PLAIN_VARIANTS, variant))
reconstruction_missing("Entity_Tear::Update 006670f0: this tear variant's flight and splash");
Room& room = *g_game->room;
speedMultiplier = g_game->room->GetTimeScale(this);
if (room.HasSlowDown()) speedMultiplier *= ROOM_SLOWDOWN_SCALE;
if (hold_update()) return;
if (is_crawlspace() && height >= CRAWLSPACE_HEIGHT_MAX && updateTime > tearRange * CRAWLSPACE_RANGE_SHARE)
{
isDead = true;
deathFlags = TEAR_DEATH_FORCED;
}
if (is_gfuel_nail(variant)) tearFlags.reset(TEAR_LASERSHOT);
unhandled_check(tearFlags, UPDATE_UNHANDLED_FLAGS);
wait_update();
death_creep_spawn();
if (laserShotLaser)
{
isVisible = true;
entityCollisionClass = ENTCOLL_ALL;
laserShotLaser->Remove();
laserShotLaser = nullptr;
}
if (isDead) return death_update();
flight_update();
if (is_crawlspace() && !room.IsPositionInRoom(pos, CRAWLSPACE_ROOM_MARGIN)) Remove();
if (room.HasSlowDown()) SetColor(SLOWDOWN_COLOR, SLOWDOWN_COLOR_FRAMES, COLOR_PRIORITY_TOP, false, true);
lua_engine_get().PostTearUpdate(this);
}
// Counts down a held tear, pinning it bobbing at its parent and updating it there. Whether it is still held.
// Once the hold ends the tear takes the velocity it was held with.
bool Entity_Tear::hold_update()
{
if (holdTimer <= 0) return false;
if (--holdTimer == 0)
{
velocity = holdVelocity;
return false;
}
if (parent) pos = vector_add(parent->pos, holdOffset);
velocity = {};
SetHeight(height + ((holdTimer / HOVER_BOB_FRAMES & 1) == 0 ? HOVER_HEIGHT_BOB : -HOVER_HEIGHT_BOB));
Entity::Update();
return true;
}
// Starts Anti-Gravity's wait, keeping the velocity for later, or counts a waiting tear down. It ends at once when its
// player stops firing and then flies on with the velocity it waited with. It bobs while it waits.
void Entity_Tear::wait_update()
{
if (tearFlags[TEAR_WAIT])
{
waitFrames = WAIT_FRAMES;
tearFlags.reset(TEAR_WAIT);
continueVelocity = velocity;
velocity = {};
return;
}
if (waitFrames <= 0) return;
Entity* owner = parent;
if (owner && owner->type == ENTITY_FAMILIAR) owner = static_cast<Entity_Familiar*>(owner)->player;
else if (owner && owner->type != ENTITY_PLAYER) owner = nullptr;
Entity_Player* player = owner ? owner->ToPlayer() : nullptr;
if (player && player->fireDirection == DIRECTION_NONE) waitFrames = 1;
if (--waitFrames == 0)
{
velocity = vector_add(velocity, continueVelocity);
continueVelocity = {};
}
SetHeight(height + ((waitFrames / HOVER_BOB_FRAMES & 1) == 0 ? HOVER_HEIGHT_BOB : -HOVER_HEIGHT_BOB));
}
// Leaves the creep a dying tear's flags call for: Mysterious Liquid's green and It Hurts' red, sized by the tear.
// An explosive tear or Bob's head leaves none.
void Entity_Tear::death_creep_spawn()
{
if (!isDead || tearFlags[TEAR_EXPLOSIVE] || variant == TEAR_BOBS_HEAD) return;
for (int flag : {TEAR_MYSTERIOUS_LIQUID_CREEP, TEAR_BLOOD_CREEP})
{
if (!tearFlags[flag]) continue;
Vector position = g_game->room->GetClampedPosition(pos, CREEP_MARGIN);
int creepVariant = flag == TEAR_BLOOD_CREEP ? EFFECT_PLAYER_CREEP_RED : EFFECT_PLAYER_CREEP_GREEN;
Entity* creep = g_game->Spawn({.position = position, .spawner = spawnerEntity, .type = ENTITY_EFFECT,
.variant = creepVariant, .seed = Random()});
creep->sprite.scale = vector_make(CREEP_SCALE * fScale, CREEP_SCALE * fScale);
creep->Update();
}
}
// The splash of a dying tear by its variant: a bullet poof for the blood-like ones, a tear poof sized by its scale
// (the larger one above the floor) for the rest, and the sword beams' own.
static TearSplash splash_get(Entity_Tear& tear)
{
TearSplash splash;
if (tear.variant == TEAR_SWORD_BEAM || tear.variant == TEAR_TECH_SWORD_BEAM)
{
splash.sound = tear.variant == TEAR_SWORD_BEAM ? SOUND_SWORD_BEAM_IMPACT : SOUND_TECH_SWORD_BEAM_IMPACT;
splash.pitch = random_unit() * SWORD_BEAM_PITCH_SPREAD + SWORD_BEAM_PITCH;
splash.effect = EFFECT_TEAR_POOF_A;
splash.subType = SWORD_BEAM_POOF_SUBTYPE;
splash.volume = SWORD_BEAM_VOLUME;
}
else if (is_listed(TEAR_BULLET_POOF_VARIANTS, tear.variant))
{
splash.effect = EFFECT_BULLET_POOF;
splash.sound = SOUND_TEAR_IMPACTS;
}
else if (tear.fScale < POOF_SCALE_SMALL)
{
splash.volume = POOF_VOLUME_TINY;
splash.sound = SOUND_SPLATTER;
splash.effect = EFFECT_TEAR_POOF_VERYSMALL;
}
else if (tear.fScale < POOF_SCALE_LARGE)
{
splash.volume = POOF_VOLUME_SMALL;
splash.sound = SOUND_SPLATTER;
splash.effect = EFFECT_TEAR_POOF_SMALL;
}
else
{
bool isHigh = tear.height <= TEAR_FLOOR_HEIGHT;
splash.sound = isHigh ? SOUND_TEAR_IMPACTS : SOUND_SPLATTER;
splash.effect = isHigh ? EFFECT_TEAR_POOF_A : EFFECT_TEAR_POOF_B;
}
return splash;
}
// Splashes the dead tear: its sound, Cricket's Body's four pieces, its poof in its color at its height, the stains
// some leave, then removes it. Game::Spawn returning nothing crashes the original. This skips the poof.
void Entity_Tear::death_update()
{
TearSplash splash = splash_get(*this);
if (splash.sound) npc_sound_play(splash.sound, splash.volume, SOUND_DELAY, splash.pitch);
if (tearFlags[TEAR_QUADSPLIT]) quadsplit_fire();
uint32_t seed = Random();
Entity* poof = g_game->Spawn({.position = pos, .spawner = this, .subType = splash.subType, .type = ENTITY_EFFECT,
.variant = splash.effect, .seed = seed});
if (poof)
{
poof->posOffset = posOffset;
if (splash.effect != EFFECT_TEAR_POOF_SMALL && splash.effect != EFFECT_TEAR_POOF_VERYSMALL)
{
bool isPupula = variant == TEAR_PUPULA || variant == TEAR_PUPULA_BLOOD;
float scale = fScale * (isPupula ? POOF_SCALE_SMALL : POOF_SCALE_LARGE);
poof->sprite.scale = vector_make(scale, scale);
poof->sprite.rotation = (float)random_below(4) * RIGHT_ANGLE;
}
poof->SetColor(sprite.color, -1, COLOR_PRIORITY_TOP, false, true);
if (is_remote_player(spawnerEntity ? spawnerEntity->ToPlayer() : nullptr))
reconstruction_missing("Entity_Tear::Update 006670f0: a remote player's faded splash");
}
if (is_listed(TEAR_STAINING_VARIANTS, variant)) blood_stains_spawn();
Remove();
}
// Cricket's Body: four pieces at a random angle and its right angles, at the dying tear's speed (10 when it barely
// moved), from where it was a frame ago. They fly a little lower and slower, smaller and with half the damage.
void Entity_Tear::quadsplit_fire()
{
float speedSquared = vector_length_squared(velocity);
Vector direction = vector_scale(random_direction(), speedSquared < QUADSPLIT_SLOW_SQUARED ? QUADSPLIT_SLOW_SPEED
: vector_length(velocity));
TearFlags flags = tearFlags;
for (int dropped : {TEAR_QUADSPLIT, TEAR_SPLIT, TEAR_LUDOVICO, TEAR_BONE_FLAG, TEAR_ABSORB, TEAR_HYDROBOUNCE,
TEAR_FETUS_FLAG})
flags.reset(dropped);
for (int i = 0; i < QUADSPLIT_PIECES; i++)
{
Vector pieceVelocity = i < 2 ? direction : vector_make(direction.y, -direction.x);
if (i & 1) pieceVelocity = vector_scale(pieceVelocity, -1);
Entity_Player* player = GetRootPlayer();
int pieceVariant = variant == TEAR_FETUS ? TEAR_BLOOD : variant;
Entity* spawned = g_game->Spawn({.position = vector_sub(pos, velocity), .velocity = pieceVelocity,
.spawner = spawnerEntity, .type = type, .variant = pieceVariant,
.seed = Random()});
Entity_Tear& piece = *spawned->ToTear();
piece.SetHeight((player ? player->tearHeight : PLAYER_TEAR_HEIGHT) * QUADSPLIT_HEIGHT_SHARE);
piece.fallingAccel = fallingAccel;
float playerFall = g_game->GetPlayer(0)->tearFallingSpeed;
if (playerFall > 0) playerFall *= QUADSPLIT_FALL_SHARE;
piece.fallingSpeed = random_unit() * TEAR_FALL_SPREAD - playerFall;
piece.SetCollisionDamage(collisionDamage * QUADSPLIT_DAMAGE);
piece.SetTearFlags(flags);
piece.SetScale(fScale * QUADSPLIT_SCALE);
piece.SetColor(sprite.color, -1, COLOR_PRIORITY_TOP, false, true);
piece.parent = parent;
piece.Update();
}
}
// Leaves up to four faint stains around the splash, Eve's Mascara's darker and Number One's yellow.
void Entity_Tear::blood_stains_spawn()
{
int count = random_below(STAIN_COUNT_MAX);
Entity_Player* player = GetRootPlayer();
for (int i = 0; i < count; i++)
{
uint32_t seed = Random();
Vector direction = random_direction();
float distance = random_unit() * STAIN_SPREAD;
Vector position = vector_add(pos, vector_scale(direction, distance));
Entity* stain = g_game->Spawn(
{.position = position, .type = ENTITY_EFFECT, .variant = EFFECT_BLOOD_SPLAT, .seed = seed});
if (!stain) continue;
ColorMod color = STAIN_COLOR;
stain->sprite.scale = vector_make(STAIN_SCALE, STAIN_SCALE);
if (player && player->HasCollectible(COLLECTIBLE_EVES_MASCARA))
color._tint[3] = random_unit() * MASCARA_ALPHA_SPREAD + MASCARA_ALPHA;
else if (player && player->HasCollectible(COLLECTIBLE_NUMBER_ONE)) color = NUMBER_ONE_STAIN_COLOR;
stain->SetColor(color, -1, COLOR_PRIORITY_TOP, false, true);
stain->Update();
}
}
// Flies the living tear: its flags steer and resize it, it points along its flight, dies on the floor or a wall (or
// bounces), sizes its sprite, moves, turns toward its target, and falls by its speed and acceleration.
void Entity_Tear::flight_update()
{
Entity_Player* player = GetRootPlayer();
square_turn();
homing_update();
float scaleFactor = size_flags_update();
spectral_update();
boomerang_pull();
if (tearFlags[TEAR_WIGGLE]) wiggle_apply(worm_multiplier_get(player, TEAR_WIGGLE));
if (tearFlags[TEAR_SPIRAL]) spiral_apply(worm_multiplier_get(player, TEAR_SPIRAL));
if (tearFlags[TEAR_BIG_SPIRAL]) big_spiral_apply(worm_multiplier_get(player, TEAR_BIG_SPIRAL));
if (tearFlags[TEAR_PULSE])
{
float strength = worm_multiplier_get(player, TEAR_PULSE) * PULSE_STRENGTH;
scaleFactor *= (std::sin((float)FrameCount() * PULSE_RATE) + PULSE_OFFSET) * strength + PULSE_BASE;
}
rotation_update(player);
if (HasEntityFlags(FLAG_NO_SPIKE_DAMAGE))
{
if (updateTime >= LAUNCH_DRAG_TIME) ClearEntityFlags(FLAG_NO_SPIKE_DAMAGE);
else friction *= updateTime / LAUNCH_DRAG_TIME * (1 - LAUNCH_DRAG_FRICTION) + LAUNCH_DRAG_FRICTION;
}
if (height > TEAR_FLOOR_HEIGHT) floor_hit();
else if ((tearFlags[TEAR_BOUNCE] || variant == TEAR_FIRE) && !g_game->room->IsBeastDungeon()) bounce_hit();
else grid_hit();
if (g_game->deathmatchManager.is_active())
reconstruction_missing("Entity_Tear::Update 006670f0: the versus mode's tear reflections");
fScale = std::max(scaleFactor * baseScale, TEAR_SCALE_MIN);
ResetSpriteScale();
if (g_game->seedEffects.HasSeedEffect(SEED_BLACK_ISAAC))
reconstruction_missing("Entity_Tear::Update 006670f0: Black Isaac's tear color");
Vector previous = pos;
Entity::Update();
turn_horizontal_update(previous);
posDisplacement = vector_sub(pos, previous);
fall_update();
}
// Hook Worm: from its third frame the tear turns a right angle (its first one), then keeps turning left and right on
// a 22 frame loop, slowing or speeding by the worm's strength.
void Entity_Tear::square_turn()
{
int frame = FrameCount();
if (!tearFlags[TEAR_SQUARE] || frame < SQUARE_START_FRAME) return;
float speed = worm_multiplier_get(GetRootPlayer(), TEAR_SQUARE) * SQUARE_SPEED_SHARE + SQUARE_SPEED_SHARE;
Vector right = vector_make(velocity.y, -velocity.x);
Vector left = vector_make(-velocity.y, velocity.x);
if (frame < SQUARE_LOOP_START)
{
if (frame == SQUARE_START_FRAME) velocity = vector_scale(right, speed);
return;
}
switch ((frame - SQUARE_LOOP_START) % SQUARE_LOOP_FRAMES)
{
case SQUARE_TURN_LEFT_SLOW: velocity = vector_scale(left, 1 / speed); break;
case SQUARE_TURN_LEFT: velocity = vector_scale(left, speed); break;
case SQUARE_TURN_RIGHT_SLOW: velocity = vector_scale(right, 1 / speed); break;
case SQUARE_TURN_RIGHT: velocity = vector_scale(right, speed); break;
}
}
// The enemy a homing tear picks every fourth frame: a vulnerable one ahead of it that it has not hit, each skipped
// half the time, scored by its distance plus a random part. A tear that collides with the grid needs a clear line.
static Entity* homing_target_find(Entity_Tear& tear)
{
Entity* best = nullptr;
float bestScore = HOMING_SCORE_NONE;
Vector ahead = vector_add(tear.pos, vector_scale(tear.velocity, HOMING_LOOK_AHEAD));
for (Entity* enemy : entity_query_radius(ahead, HOMING_RADIUS, QUERY_ENEMIES))
{
if (!enemy->IsVulnerableEnemy(nullptr)) continue;
if (tear.spawnerEntity && tear.spawnerEntity->IsDescendantOf(enemy)) continue;
if (enemy->HasEntityFlags(FLAG_FRIENDLY | FLAG_NO_TARGET)) continue;
if (EntityList::HitListContains(tear.hitList, *enemy)) continue;
if (enemy->type == ENTITY_PLAYER && static_cast<Entity_Player*>(enemy)->IsInvisible()) continue;
if (random_below(2) == 0) continue;
if (tear.entityGridCollisionClass == GRIDCOLL_BULLET &&
!room_check_line(tear.pos, enemy->pos, LINE_MODE_PROJECTILE, 0))
continue;
float score = vector_length(vector_sub(ahead, enemy->pos)) + random_unit() * HOMING_RADIUS;
if (score < bestScore)
{
best = enemy;
bestScore = score;
}
}
if (g_game->deathmatchManager.is_active())
reconstruction_missing("Entity_Tear::Update 006670f0: homing on the versus mode's familiars");
return best;
}
// Spoon Bender and Brain Worm: drops a target already hit, searches a new one every fourth frame, and a homing tear
// pulls toward it, its speed eased by its homing friction.
void Entity_Tear::homing_update()
{
if (!tearFlags[TEAR_HOMING] && !tearFlags[TEAR_TURN_HORIZONTAL]) return;
if (target && EntityList::HitListContains(hitList, *target)) target = nullptr;
if (!target && IsFrame(HOMING_SEARCH_FRAMES, (int)index)) target = homing_target_find(*this);
if (!target || !tearFlags[TEAR_HOMING]) return;
Vector away = vector_normalized(vector_sub(pos, target->pos));
velocity = vector_sub(velocity, vector_scale(away, speedMultiplier * HOMING_PULL));
velocity = vector_scale(velocity, timescale_factor(homingFriction, speedMultiplier));
}
// Lump of Coal's growth with the distance flown and Proptosis' shrinking damage, which kills the tear once it has
// none left. The factor its scale draws at.
float Entity_Tear::size_flags_update()
{
float scaleFactor = 1;
if (tearFlags[TEAR_GROW] && waitFrames < 1)
{
collisionDamage += vector_length(posDisplacement) * GROW_DAMAGE;
baseScale += GROW_SCALE;
}
if (tearFlags[TEAR_SHRINK] && waitFrames < 1 && updateTime > SHRINK_START)
{
float rate = baseDamage / SHRINK_FAST_SHARE < collisionDamage ? SHRINK_FAST : SHRINK_SLOW;
collisionDamage = std::max(collisionDamage - rate * baseDamage, SHRINK_DAMAGE_MIN);
scaleFactor = std::sqrt(collisionDamage / baseDamage);
if (collisionDamage <= SHRINK_DAMAGE_MIN)
{
isDead = true;
deathFlags |= TEAR_DEATH_SHRUNK;
}
}
return scaleFactor;
}
// A spectral tear flies over the grid (Bob's head and the Chaos Card only stop at walls), hurting the poop and fires
// it passes: everything under it the first time it touches any, then now and then.
void Entity_Tear::spectral_update()
{
if (!tearFlags[TEAR_SPECTRAL]) return;
bool isGridBound = variant == TEAR_BOBS_HEAD || variant == TEAR_CHAOS_CARD;
entityGridCollisionClass = isGridBound ? GRIDCOLL_WALLS : GRIDCOLL_NONE;
if (!isGridTouched)
{
if (try_make_bridges(pos))
{
apply_death_flag_effects(nullptr);
isGridTouched = true;
}
}
else if (random_below(SPECTRAL_GRID_CHANCE) == 0) try_make_bridges(pos);
}
// My Reflection: pulls the tear back toward its parent (or the target position), harder at a higher shot speed and a
// shorter range.
void Entity_Tear::boomerang_pull()
{
if (!tearFlags[TEAR_BOOMERANG] || !parent) return;
Vector lift = vector_make(0, BOOMERANG_ANCHOR_LIFT);
Vector anchor = vector_is_zero(targetPosition) ? vector_add(parent->pos, lift) : vector_sub(targetPosition, lift);
Entity_Player* player = GetRootPlayer();
float reach = std::max((tearRange - BOOMERANG_RANGE_START) * BOOMERANG_REACH_SHARE, BOOMERANG_REACH_MIN);
float speed = (player ? player->shotSpeed : 1) * BOOMERANG_SPEED;
float pull = speed * speed / (reach + reach);
velocity = vector_sub(velocity, vector_scale(vector_normalized(vector_sub(pos, anchor)), pull));
}
// Points the tear along its flight: Flat Worm stretches it, the rotated variants and the turning layers of its tear
// effect follow the direction it moves and falls, and a boomerang Pupula Duplex tear spins.
void Entity_Tear::rotation_update(Entity_Player* player)
{
sprite.rotation = 0;
bool isRotated = false;
bool isEffectRotated = tearEffectANM2.isLoaded && (tearEffectANM2.bitflags & TEAR_EFFECT_LAYERED);
if (tearFlags[TEAR_FLAT] && variant != TEAR_BOBS_HEAD)
{
float stretch = worm_multiplier_get(player, TEAR_FLAT) * FLAT_STRETCH + 1;
isRotated = variant != TEAR_FETUS;
sizeMulti = isRotated ? vector_make(1, stretch) : vector_make(stretch, 1);
}
if (is_gfuel_nail(variant)) sizeMulti.x = GFUEL_NAIL_WIDTH;
bool isPupula = variant == TEAR_PUPULA || variant == TEAR_PUPULA_BLOOD;
if (isPupula && tearFlags[TEAR_BOOMERANG])
{
sprite.rotation = updateTime * PUPULA_SPIN;
isRotated = false;
}
else if (is_listed(TEAR_ROTATED_VARIANTS, variant)) isRotated = true;
if (!isRotated && !isEffectRotated) return;
Vector direction = velocity;
if (waitFrames >= 1) direction = continueVelocity;
else if (fallingAccel > GRAVITY_MIN_ACCEL) direction.y += fallingSpeed;
float angle = vector_angle(direction);
if (isRotated) sprite.rotation = angle;
if (!isEffectRotated) return;
for (LayerState& layer : tearEffectANM2.layerStates)
if (layer.bitflags & TEAR_EFFECT_LAYERED) layer.rotation = angle;
}
// The tear reached the floor: it dies there, ending its player's streak.
void Entity_Tear::floor_hit()
{
isDead = true;
deathFlags |= TEAR_DEATH_FLOOR;
apply_death_flag_effects(nullptr);
if (!parent || !isCanTriggerStreakEnd) return;
if (Entity_Player* player = parent->ToPlayer())
{
if (player->HasCollectible(COLLECTIBLE_DEAD_EYE)) player->ClearDeadEyeCharge();
streak_end(*player);
}
}
// The tear hit the grid, or stands on a wall: it dies, hurting the rocks and poop it touches, unless it is spectral.
// Missing anything but poop or TNT ends its player's streak.
void Entity_Tear::grid_hit()
{
Room& room = *g_game->room;
int gridIndex = room.GetGridIndex(pos);
uint32_t collision = room.GetGridCollision(gridIndex);
bool isWall = collision == COLLISION_WALL;
int gridPath = gridIndex >= 0 ? room.gridPaths[gridIndex] : 0;
bool isPlayerWall = collision == COLLISION_WALL_EXCEPT_PLAYER && gridPath < GRID_PATH_TEAR_WALL;
if (!isCollidesWithGrid) return;
if (height <= TEAR_GRID_HIT_HEIGHT && !isWall && !isPlayerWall) return;
if (tearFlags[TEAR_SPECTRAL] && variant != TEAR_BOBS_HEAD) return;
isDead = true;
deathFlags |= TEAR_DEATH_GRID;
if (isWall || collision == COLLISION_WALL_EXCEPT_PLAYER) deathFlags |= TEAR_DEATH_WALL;
apply_death_flag_effects(nullptr);
try_make_bridges(pos);
if (!parent || !isCanTriggerStreakEnd) return;
Entity_Player* player = parent->ToPlayer();
GridEntity* grid = room.GetGridEntity(gridIndex);
if (!player || (grid && (grid->type == GRID_POOP || grid->type == GRID_TNT))) return;
streak_end(*player);
if (player->HasCollectible(COLLECTIBLE_DEAD_EYE)) player->ClearDeadEyeCharge();
}
// Rubber Cement and the flames: the tear bounces off the grid at the speed the collision left it, hurting what it
// hit, forgetting the entities it hit and the Tractor Beam. A crawlspace takes the bounce away.
void Entity_Tear::bounce_hit()
{
entityGridCollisionClass = tearFlags[TEAR_SPECTRAL] ? GRIDCOLL_WALLS : GRIDCOLL_NOPITS;
if (!isCollidesWithGrid) return;
try_make_bridges(vector_sub(pos, velocity));
velocity = vector_scale(vector_normalized(velocity), vector_length(gridCollisionVelocity));
tearFlags.reset(TEAR_TRACTOR_BEAM);
hitList.clear();
Entity_Player* shooter = spawnerEntity ? spawnerEntity->ToPlayer() : nullptr;
npc_sound_play(BOUNCE_SOUND, shooter ? shooter->local_volume_get() : 1, SOUND_DELAY, 1);
if (is_crawlspace()) tearFlags.reset(TEAR_BOUNCE);
}
// Brain Worm: once the target passes beside the tear it turns a right angle toward it, once. A tear moving away from
// a target behind it loses the target unless it homes.
void Entity_Tear::turn_horizontal_update(Vector previous)
{
if (!target || !tearFlags[TEAR_TURN_HORIZONTAL]) return;
Vector direction = vector_normalized(velocity);
float before = vector_dot(vector_normalized(vector_sub(vector_sub(target->pos, previous), velocity)), direction);
Vector toTarget = vector_normalized(vector_sub(vector_sub(target->pos, pos), velocity));
float after = vector_dot(toTarget, direction);
if (after > 0 || (before <= 0 && after < TURN_AWAY))
{
if (after < TURN_AWAY && before < TURN_AWAY && !tearFlags[TEAR_HOMING]) target = nullptr;
return;
}
Vector turned = vector_quarter_turn(direction);
if (vector_dot(turned, toTarget) < 0) turned = vector_scale(turned, -1);
velocity = vector_scale(turned, vector_length(velocity));
tearFlags.reset(TEAR_TURN_HORIZONTAL);
}
// Lets the flying tear fall by its speed and acceleration, a crawlspace's tears dropping under gravity.
void Entity_Tear::fall_update()
{
if (waitFrames >= 1 || isDead || stickTarget) return;
fallingSpeed = speedMultiplier * GRAVITY_PULL + timescale_factor(GRAVITY_FALL_DRAG, speedMultiplier) * fallingSpeed +
speedMultiplier * fallingAccel;
SetHeight(speedMultiplier * fallingSpeed + height);
if (!is_crawlspace()) return;
if (fallingAccel >= GRAVITY_MIN_ACCEL) velocity.y += fallingAccel;
else if (height > CRAWLSPACE_SINK_HEIGHT) velocity.y += CRAWLSPACE_SINK_SPEED;
if (g_game->room->IsBeastDungeon()) reconstruction_missing("Entity_Tear::Update 006670f0: the Beast's lava");
}
// 00679400 Moves the tear half a step for the frame between updates, sways the worms' tears, and places its sprite at
// the height it will fall to. A held tear stays at its parent.
void Entity_Tear::Interpolate()
{
if (holdTimer > 0 && parent) pos = vector_add(parent->pos, holdOffset);
for (int flag : {TEAR_TRACTOR_BEAM, TEAR_LASER, TEAR_LUDOVICO, TEAR_HYDROBOUNCE})
if (tearFlags[flag]) reconstruction_missing("Entity_Tear::Interpolate 00679400: the tear flags' motion");
Entity_Player* player = GetRootPlayer();
if (tearFlags[TEAR_WIGGLE]) wiggle_apply(worm_multiplier_get(player, TEAR_WIGGLE));
if (tearFlags[TEAR_SPIRAL]) spiral_apply(worm_multiplier_get(player, TEAR_SPIRAL));
if (tearFlags[TEAR_BIG_SPIRAL]) big_spiral_apply(worm_multiplier_get(player, TEAR_BIG_SPIRAL));
Entity::Interpolate();
if (waitFrames >= 1 || isDead) return;
posOffset.y = is_crawlspace() ? CRAWLSPACE_OFFSET_Y
: get_height_offset_y(fallingSpeed * speedMultiplier * 0.5f + height);
}
// 006668c0 Wiggle Worm: sways the tear sideways on a wave, odd tears the other way, by half its speed (at most 5).
void Entity_Tear::wiggle_apply(float strength)
{
Vector side = vector_normalized(vector_make(velocity.y, -velocity.x));
float sway = std::min(vector_length(velocity) * WIGGLE_SPEED_SHARE, WIGGLE_MAX);
float phase = (tearIdx & 1) == 0 ? 0 : PI_F;
float wave = std::cos(((float)(g_game->frameCount - spawnFrame) + HALF_FRAME) * WIGGLE_RATE + phase);
pos = vector_add(pos, vector_scale(side, wave * sway * strength));
}
// The shared spiral: a circle of a radius across and along the flight, turning at a rate, half a frame ahead on odd
// global frames.
static void spiral_move(Entity_Tear& tear, float rate, float side, float forward)
{
float frame = (float)(g_game->frameCount - tear.spawnFrame) + (float)(g_manager->framecount % 2) * HALF_FRAME;
Vector direction = tear.velocity;
float phase = std::fabs(direction.x) <= std::fabs(direction.y) ? frame * rate : QUARTER_TURN - frame * rate;
float cosine = std::cos(phase);
float sine = std::sin(phase);
direction = vector_normalized(direction);
tear.pos.x += cosine * direction.y * side + cosine * direction.x * forward;
tear.pos.y += -direction.x * sine * side + sine * direction.y * forward;
}
// 00666a00 Ring Worm: spins the tear in tight circles along its flight.
void Entity_Tear::spiral_apply(float strength)
{
spiral_move(*this, SPIRAL_RATE, SPIRAL_SIDE * strength, SPIRAL_FORWARD);
}
// 00666ba0 Ouroboros Worm: spins the tear in wide, slow circles along its flight.
void Entity_Tear::big_spiral_apply(float strength)
{
spiral_move(*this, BIG_SPIRAL_RATE, BIG_SPIRAL_RADIUS * strength, BIG_SPIRAL_RADIUS);
}
// 006790c0 Draws the tear with its halo, its tear effect behind or in front, and Dead Eye's glow.
void Entity_Tear::Render(const Vector& offset)
{
if (!isExists || !isVisible) return;
renderPosition = vector_add(render_position_get(vector_add(pos, posOffset), RENDER_SNAPPED), offset);
SpriteDraw draw = {renderPosition, {}, {}};
bool isEffectBehind = tearEffectANM2.bitflags & TEAR_EFFECT_BEHIND;
if (tearFlags[TEAR_GLOW]) tearHaloANM2.Render(draw);
if (tearEffectANM2.isLoaded && isEffectBehind) tearEffectANM2.Render(draw);
if (is_remote_player(spawnerEntity ? spawnerEntity->ToPlayer() : nullptr))
reconstruction_missing("Entity_Tear::Render 006790c0: a remote player's faded tear");
Entity::Render(offset);
if (tearEffectANM2.isLoaded && !isEffectBehind) tearEffectANM2.Render(draw);
if (deadEyeIntensity != 0) deadEyeANM2.Render(draw);
lua_engine_get().PostTearRender(this, offset);
}
// 00675fa0 Sets the damage it deals, and the damage it started with.
void Entity_Tear::SetCollisionDamage(float damage)
{
collisionDamage = damage;
baseDamage = damage;
}
// 006666c0 Removes its lasers and attached effect, lets go of its sprites and links, joining the tears linked on
// either side of it, and removes the rest of a Ludovico chain.
void Entity_Tear::ClearReferences()
{
if (techZeroLaser) techZeroLaser->Remove();
if (laserShotLaser) laserShotLaser->Remove();
Entity::ClearReferences();
tearHaloANM2.Reset();
tearEffectANM2.Reset();
deadEyeANM2.Reset();
stickTarget = nullptr;
techZeroLaser = nullptr;
techZeroTarget = nullptr;
laserShotLaser = nullptr;
if (linkPrev && linkNext)
{
Entity* previous = linkPrev;
Entity* next = linkNext;
if (previous->type == ENTITY_TEAR) static_cast<Entity_Tear*>(previous)->linkNext = next;
if (next->type == ENTITY_TEAR) static_cast<Entity_Tear*>(next)->linkPrev = previous;
}
linkPrev = nullptr;
linkNext = nullptr;
if (attachedEffect) attachedEffect->Remove();
if (!tearFlags[TEAR_LUDOVICO]) return;
for (Entity* link = child; link && link->type == ENTITY_TEAR; link = link->child) link->Remove();
}
// 00665b00 The player at the end of its spawner chain, or none when that is not a player.
Entity_Player* Entity_Tear::GetRootPlayer()
{
Entity* root = this;
while (root->spawnerEntity) root = root->spawnerEntity;
return root->type == ENTITY_PLAYER ? static_cast<Entity_Player*>(root) : nullptr;
}
// 00666d40 Plays its fire sound unless muted (and Little Horn's), then sets up the flight its flags give it: Tiny
// Planet's tears hover and fall faster, water bounces leap up, and My Reflection's fall slower. In a crawlspace it
// starts a little higher, dropping when fired sideways.
void Entity_Tear::play_fire_sound()
{
isFireSoundPending = false;
bool isSilent = variant == TEAR_CHAOS_CARD || variant == TEAR_FIRE || variant == TEAR_GRIDENT || isFireSoundMuted;
bool isFetus = variant == TEAR_FETUS;
if (!isSilent && !is_gfuel_nail(variant))
npc_sound_play(isFetus ? SOUND_FETUS_FIRE : SOUND_TEAR_FIRE, 1, SOUND_DELAY, isFetus ? FETUS_FIRE_PITCH : 1);
if (tearFlags[TEAR_HORN]) npc_sound_play(SOUND_LITTLE_HORN, 1, SOUND_DELAY, 1);
if (tearFlags[TEAR_ORBIT])
{
if (fallingSpeed < 0) fallingSpeed *= ORBIT_FALL_SCALE;
isHovering = true;
}
if (tearFlags[TEAR_HYDROBOUNCE])
{
isHovering = false;
fallingSpeed -= HYDROBOUNCE_LIFT;
fallingAccel += HYDROBOUNCE_ACCEL;
}
else if (tearFlags[TEAR_BOOMERANG])
{
fallingSpeed *= BOOMERANG_FALL_SCALE;
fallingAccel = (fallingAccel + BOOMERANG_ACCEL_OFFSET) * BOOMERANG_ACCEL_SCALE - BOOMERANG_ACCEL_OFFSET;
}
if (!is_crawlspace()) return;
pos.y -= CRAWLSPACE_FIRE_RAISE;
if (fallingAccel > 0 && velocity.y < std::fabs(velocity.x)) velocity.y = fallingSpeed * 0.5f + velocity.y;
if (std::fabs(velocity.y) >= std::fabs(velocity.x)) return;
float length = vector_length(velocity);
float directionY = length > 0 ? velocity.y * (1 / length) : velocity.y;
if (directionY > 0 && directionY < CRAWLSPACE_LEVEL_SLOPE) velocity.y = 0;
}
// 00676020 Where the sprite draws for a height: at the height itself while it falls, lifted on a curve near the
// floor while it hovers, and fixed for the flames and sword beams that do not fall.
float Entity_Tear::get_height_offset_y(float tearHeight)
{
bool isHovering = fallingAccel <= GRAVITY_MIN_ACCEL || this->isHovering;
bool isFixed = variant == TEAR_FIRE || ((variant == TEAR_SWORD_BEAM || variant == TEAR_TECH_SWORD_BEAM) && isHovering);
if (isFixed) return FIXED_HEIGHT_OFFSET;
if (is_gfuel_nail(variant) && isHovering) return GFUEL_NAIL_OFFSET;
if (!isHovering) return tearHeight;
float aboveFloor = std::max(height + HOVER_FLOOR_DISTANCE, 0.0f);
return (height * HOVER_OFFSET_SCALE + HOVER_OFFSET_LIFT) + aboveFloor * aboveFloor;
}
// 00675fc0 Sets the height and the sprite offset it draws at. A crawlspace keeps the sprite level and the tear above
// the floor.
void Entity_Tear::SetHeight(float tearHeight)
{
height = tearHeight;
posOffset.y = get_height_offset_y(tearHeight);
if (!is_crawlspace()) return;
posOffset.y = CRAWLSPACE_OFFSET_Y;
if (tearHeight > CRAWLSPACE_HEIGHT_MAX) height = CRAWLSPACE_HEIGHT_MAX;
}
// 00676120 Sets its scale and the scale it returns to, at least a hundredth, and sizes its sprite to it.
void Entity_Tear::SetScale(float scale)
{
scale = std::max(scale, TEAR_SCALE_MIN);
baseScale = scale;
fScale = scale;
ResetSpriteScale();
}
// Loads the tear effect the first of its flags calls for and plays it: Little Horn's additive (tinted for Rift's
// tears), Holy Light's and Jacob's Ladder's first layer additive, and the creep, fire and dark matter drawn behind.
static void tear_effect_load(ANM2& effect, const TearFlags& flags)
{
auto shown = std::find_if(TEAR_EFFECTS.begin(), TEAR_EFFECTS.end(),
[&flags](const TearEffect& candidate) { return flags[candidate.flag]; });
if (shown == TEAR_EFFECTS.end()) return;
effect.Load(shown->anm2, GRAPHICS_LOAD);
switch (shown->flag)
{
case TEAR_HORN:
case TEAR_RIFT:
for (int i = 0; i < (int)effect.layerStates.size(); i++)
{
layer_additive_set(effect, i);
if (shown->flag == TEAR_RIFT) effect.GetLayer(i)->color = RIFT_EFFECT_COLOR;
}
break;
case TEAR_LIGHT_FROM_HEAVEN:
case TEAR_JACOBS: layer_additive_set(effect, 0); break;
default:
effect.bitflags |= TEAR_EFFECT_LAYERED | TEAR_EFFECT_BEHIND;
effect.GetLayer(0)->bitflags = TEAR_EFFECT_LAYERED;
if (shown->flag == TEAR_MYSTERIOUS_LIQUID_CREEP) layer_additive_set(effect, 1);
}
effect.Play("Idle");
}
// 00676150 Sets the tear flags, loading what they show the first time: a glowing tear's halo, and its one effect.
void Entity_Tear::SetTearFlags(TearFlags flags)
{
if (flags[TEAR_GLOW] && !tearHaloANM2.isLoaded)
{
tearHaloANM2.Load(TEAR_HALO_ANM2, GRAPHICS_LOAD);
tearHaloANM2.Play("Idle");
}
if (!tearEffectANM2.isLoaded) tear_effect_load(tearEffectANM2, flags);
tearFlags = flags;
}
// The opacity a remote player's shots fade to, or one for local shots and in versus.
static float shot_alpha_get(Entity_Tear& tear)
{
if (!is_remote_player(tear.spawnerEntity ? tear.spawnerEntity->ToPlayer() : nullptr)) return 1;
if (g_game->deathmatchManager.is_active()) return 1;
return (float)g_manager->optionsConfig.onlinePlayerOpacity * 0.09f + 0.1f;
}
// 00676be0 Applies what its flags do when it dies above the floor: Parasite splits it in two and Compound Fracture
// into two shards. A tear bouncing back up off water splits too, without explosions.
void Entity_Tear::apply_death_flag_effects(Entity*)
{
bool isRising = isDead && tearFlags[TEAR_HYDROBOUNCE] && fallingSpeed < 0;
bool isAbove = height < TEAR_FLOOR_HEIGHT;
if (tearFlags[TEAR_SPLIT] && collisionDamage > SPLIT_DAMAGE_MIN && (isAbove || isRising)) split_fire(isRising);
if (tearFlags[TEAR_BONE_FLAG] && isAbove) bone_shards_fire(isRising);
if (tearFlags[TEAR_JACOBS] && isAbove)
reconstruction_missing("Entity_Tear::apply_death_flag_effects 00676be0: Jacob's Ladder's lightning");
if (tearFlags[TEAR_RIFT])
reconstruction_missing("Entity_Tear::apply_death_flag_effects 00676be0: Ocular Rift's rift");
}
// What every piece a dying tear breaks into shares: its color (faded for a remote player), its flags, its parent,
// and a first update.
void Entity_Tear::child_setup(Entity_Tear& child, TearFlags flags, float alpha)
{
ColorMod color = sprite.color;
color._tint[3] *= alpha;
child.SetColor(color, -1, COLOR_PRIORITY_TOP, false, true);
child.SetTearFlags(flags);
child.parent = parent;
child.Update();
}
// Parasite: two plain tears out to the sides from where the tear was a frame ago, lower and with half its damage
// and size. Rising off water they start at the floor with a quarter.
void Entity_Tear::split_fire(bool isRising)
{
TearFlags flags = tearFlags;
for (int dropped : {TEAR_LUDOVICO, TEAR_ABSORB, TEAR_HYDROBOUNCE, TEAR_FETUS_FLAG}) flags.reset(dropped);
if (isRising) flags.reset(TEAR_EXPLOSIVE);
float alpha = shot_alpha_get(*this);
for (int i = 0; i < 2; i++)
{
Vector side = i == 0 ? vector_make(velocity.y, -velocity.x) : vector_make(-velocity.y, velocity.x);
Entity* spawned = g_game->Spawn({.position = vector_sub(pos, velocity), .velocity = side,
.spawner = spawnerEntity, .type = ENTITY_TEAR, .variant = TEAR_BLUE,
.seed = Random()});
Entity_Tear& piece = *spawned->ToTear();
piece.SetHeight(isRising ? CRAWLSPACE_HEIGHT_MAX : height / SPLIT_HEIGHT_SHARE);
piece.fallingSpeed = fallingSpeed;
if (isRising) piece.fallingAccel = SPLIT_RISING_ACCEL;
piece.SetCollisionDamage(collisionDamage * (isRising ? SPLIT_RISING_DAMAGE : SPLIT_DAMAGE));
piece.baseScale = std::max(fScale * SPLIT_SCALE, TEAR_SCALE_MIN);
piece.fScale = piece.baseScale;
piece.ResetSpriteScale();
child_setup(piece, flags, alpha);
}
}
// Compound Fracture: two shards (bone tears, broken looking ones from a bone tear) flying off at random at the
// tear's speed with half its damage.
void Entity_Tear::bone_shards_fire(bool isRising)
{
TearFlags flags = tearFlags;
for (int dropped : {TEAR_LUDOVICO, TEAR_BONE_FLAG, TEAR_FETUS_FLAG}) flags.reset(dropped);
if (isRising) flags.reset(TEAR_EXPLOSIVE);
float alpha = shot_alpha_get(*this);
int shardVariant = variant == TEAR_FETUS ? TEAR_BONE : variant;
for (int i = 0; i < BONE_SHARDS; i++)
{
float angle = random_unit() * RANDOM_HALF_TURN;
angle += angle;
float speed = vector_length(velocity);
Vector shardVelocity = vector_make(std::cos(angle) * speed, std::sin(angle) * speed);
Entity* spawned = g_game->Spawn({.position = vector_sub(pos, velocity), .velocity = shardVelocity,
.spawner = spawnerEntity, .type = ENTITY_TEAR, .variant = shardVariant,
.seed = Random()});
Entity_Tear& shard = *spawned->ToTear();
if (shardVariant == TEAR_BONE)
{
shard.sprite.ReplaceSpritesheet(0, BROKEN_BONE_SHEET);
shard.sprite.LoadGraphics();
}
shard.SetHeight(height);
shard.fallingSpeed = fallingSpeed;
shard.SetCollisionDamage(collisionDamage * BONE_DAMAGE);
child_setup(shard, flags, alpha);
}
}
// Whether a variant plays an animation sized to its scale.
static bool is_sized_variant(int variant)
{
return variant <= TEAR_METALLIC || (variant >= TEAR_LOST_CONTACT && variant <= TEAR_FIST) || variant == TEAR_ICE ||
variant == TEAR_SPORE;
}
// The sized animation's name for a variant and its number.
static std::string sized_animation_name(int variant, int number)
{
const char* format = "RegularTear%d";
if (is_listed(BLOOD_ANIMATION_VARIANTS, variant)) format = "BloodTear%d";
else if (variant == TEAR_TOOTH || variant == TEAR_BLACK_TOOTH) format = "Tooth%dMove";
else if (variant == TEAR_COIN) format = "Rotate%d";
else if (is_listed(STONE_ANIMATION_VARIANTS, variant)) format = "Stone%dMove";
char name[TEAR_ANIMATION_NAME_SIZE];
std::snprintf(name, sizeof(name), format, number);
return name;
}
// Plays the animation of its variant and size when that changed: the first sized one at least its scale, or a
// fixed one. The scale its layers draw at, its scale over the animation's where no animation matches it.
float Entity_Tear::animation_update()
{
int animationBase = variant * TEAR_ANIMATION_BASE;
if (is_sized_variant(variant))
{
auto found = std::find_if(TEAR_ANIMATION_SCALES.begin(), TEAR_ANIMATION_SCALES.end() - 1,
[this](float scale) { return fScale <= scale + TEAR_ANIMATION_MARGIN; });
bool isLargest = found == TEAR_ANIMATION_SCALES.end() - 1;
int number = (int)(found - TEAR_ANIMATION_SCALES.begin()) + 1;
if (scaleAnimNum != animationBase + number)
{
sprite.Play(sized_animation_name(variant, number));
scaleAnimNum = animationBase + number;
}
return isLargest || tearFlags[TEAR_GROW] || tearFlags[TEAR_LUDOVICO] ? fScale / *found : 1;
}
switch (variant)
{
case TEAR_FIRE_MIND:
case TEAR_DARK_MATTER:
case TEAR_MYSTERIOUS:
{
if (scaleAnimNum != animationBase)
{
sprite.Play("MoveHori");
scaleAnimNum = animationBase;
}
Vector direction = waitFrames > 0 ? continueVelocity : vector_make(velocity.x, fallingSpeed + velocity.y);
sprite.rotation = vector_angle(direction);
return fScale / TEAR_ANIMATION_SCALES.back();
}
case TEAR_SCHYTHE:
case TEAR_ROCK:
case TEAR_FETUS:
reconstruction_missing("Entity_Tear::ResetSpriteScale 00677780: this tear variant's animation");
case TEAR_CHAOS_CARD:
if (isDead) return 1;
if (scaleAnimNum != animationBase)
{
sprite.Play("Rotate");
scaleAnimNum = animationBase;
}
sprite.isFlipX = velocity.x < 0;
return 1;
case TEAR_GRIDENT:
return 1;
case TEAR_FIRE:
sprite.Play("Flickering");
layer_additive_set(sprite, 0);
return 1;
case TEAR_SWORD_BEAM:
case TEAR_TECH_SWORD_BEAM:
sprite.Play("Idle");
return fScale;
default:
if (scaleAnimNum != animationBase)
{
sprite.Play("Idle");
scaleAnimNum = animationBase;
}
return 1;
}
}
// 00677780 Plays the animation for its size and variant, sizes its layers and effect sprites with its size
// multiplier (a third as wide for the G-Fuel nails), and its collision and shadow with its scale.
void Entity_Tear::ResetSpriteScale()
{
float layerScale = animation_update();
float sizeX = sizeMulti.x;
float sizeY = sizeMulti.y;
if (variant > TEAR_FETUS) layerScale = fScale;
else if (is_gfuel_nail(variant)) sizeX /= GFUEL_SIZE_DIVISOR;
for (LayerState& layer : sprite.layerStates) layer.size = vector_make(layerScale * sizeX, layerScale * sizeY);
float effectScale = fScale * TEAR_EFFECT_SCALE;
Vector effectSize = vector_make(effectScale * sizeX, effectScale * sizeY);
if (tearFlags[TEAR_GLOW])
{
tearHaloANM2.scale = effectSize;
tearHaloANM2.Update();
}
tearEffectANM2.scale = effectSize;
tearEffectANM2.Update();
if (deadEyeIntensity != 0)
{
deadEyeANM2.scale = effectSize;
deadEyeANM2.Update();
}
SetSize(config->collisionRadius * fScale, sizeMulti, config->gridCollisionPoints);
shadowSize = config->shadowSize * fScale * (sizeX + sizeY) * 0.5f;
}
// 00678060 Whether it was not split off another tear.
bool Entity_Tear::is_not_familiar_spawned()
{
return !parent || parent->type != ENTITY_TEAR;
}
// 0067d560 Hurts the rocks, poop and other solid grid entities its collision points touch at a position, once each,
// unless the tear does no grid damage. Whether it touched any.
bool Entity_Tear::try_make_bridges(const Vector& position)
{
if (tearFlags[TEAR_NO_GRID_DAMAGE]) return false;
Room& room = *g_game->room;
std::vector<int> cells;
int damage = collisionDamage > STRONG_TEAR_DAMAGE ? 2 : 1;
bool isHitSolid = false;
for (Vector point : collisionPoints)
{
int cell = room.GetGridIndex(vector_add(position, point));
if (cell >= 0) cells.push_back(cell);
}
std::sort(cells.begin(), cells.end());
cells.erase(std::unique(cells.begin(), cells.end()), cells.end());
for (int cell : cells)
{
GridEntity* grid = room.GetGridEntity(cell);
if (!grid || grid->collisionClass == COLLISION_NONE || grid->collisionClass == COLLISION_PIT) continue;
isHitSolid = true;
if (tearFlags[TEAR_ACID] || tearFlags[TEAR_ROCK_FLAG])
reconstruction_missing("Entity_Tear::try_make_bridges 0067d560: the acid and rock tears breaking rocks");
grid->Hurt(damage, EntityRef(this));
}
return isHitSolid;
}
// The hit's direction draws a random one for a tear too slow to have its own. Only Backstabber, Knockout Drops and
// the coins use the direction, none of which is written yet, but the draw still advances the generator.
static void hit_direction_draw(Entity* source)
{
if (source && source->type == ENTITY_TEAR && vector_length(source->velocity) < HIT_DIRECTION_MIN_SPEED)
random_direction();
}
// The status effects of a hit on a vulnerable enemy: Spider Bite's slowing (Ball of Tar's darker), poison, freezing,
// charm, confusion (Glaucoma's lasting), fear, burning, Midas' gold, magnetism, bait, ice, black hearts and God's
// Flesh's shrinking.
static void status_effects_apply(Entity& entity, const TearFlags& flags, Entity* source)
{
EntityRef ref(source);
bool isVersus = g_game->deathmatchManager.is_active();
if (flags[TEAR_SLOW])
entity.AddSlowing(ref, SLOW_DURATION, SLOW_AMOUNT, flags[TEAR_GISH] ? GISH_COLOR : SLOW_COLOR, false);
if (flags[TEAR_POISON]) entity.AddPoison(ref, isVersus ? POISON_DURATION_VERSUS : POISON_DURATION, 0, false);
if (flags[TEAR_FREEZE]) entity.AddFreeze(ref, isVersus ? FREEZE_DURATION_VERSUS : FREEZE_DURATION, false);
if (flags[TEAR_CHARM]) entity.AddCharmed(ref, CHARM_DURATION, false, false);
if (flags[TEAR_CONFUSION]) entity.AddConfusion(ref, (int)(Random() % CONFUSION_SPREAD) + CONFUSION_DURATION, false);
if (flags[TEAR_PERMANENT_CONFUSION])
{
int duration = entity.IsBoss() ? PERMANENT_CONFUSION_BOSS : PERMANENT_CONFUSION;
if (isVersus && entity.type == ENTITY_PLAYER) duration = PERMANENT_CONFUSION_VERSUS;
entity.AddConfusion(ref, duration, false);
}
if (flags[TEAR_FEAR]) entity.AddFear(ref, FEAR_DURATION, false);
if (flags[TEAR_BURN])
{
bool isHotFire = source && source->type == ENTITY_EFFECT && source->variant == EFFECT_FIRE_JET;
entity.AddBurn(ref, isHotFire ? BURN_DURATION_LONG : BURN_DURATION, 0, false);
}
if (flags[TEAR_MIDAS]) entity.AddMidasFreeze(ref, MIDAS_DURATION, false);
if (flags[TEAR_BACKSTAB])
reconstruction_missing("Entity_Tear::ApplyTearFlagEffects 0067af60: Backstabber's bleeding");
if (flags[TEAR_MAGNETIZE]) entity.AddMagnetized(ref, MAGNETIZE_DURATION);
if (flags[TEAR_BAIT]) entity.AddBaited(ref, BAIT_DURATION);
if (flags[TEAR_ICE_FLAG]) entity.AddIce(ref, ICE_DURATION);
if (flags[TEAR_PUNCH]) reconstruction_missing("Entity_Tear::ApplyTearFlagEffects 0067af60: Knockout Drops' punch");
if (flags[TEAR_BLACK_HP_DROP]) entity.AddEntityFlags(FLAG_SPAWN_BLACK_HP);
if (flags[TEAR_GODS_FLESH_FLAG]) entity.AddShrink(ref, SHRINK_DURATION, false);
if (flags[TEAR_COIN_DROP] || (flags[TEAR_GREED_COIN] && Random() % GREED_COIN_CHANCE == 0))
reconstruction_missing("Entity_Tear::ApplyTearFlagEffects 0067af60: a coin knocked out");
}
// 0067af60 What a hit's tear flags do to what it hits: the status effects on vulnerable enemies, the knockback a
// tear's mass and push give, and the gore. An explosive tear leaves the effects to its explosion, and a friendly
// target is spared. The original reads a missing target's position. This does nothing for one.
void Entity_Tear::ApplyTearFlagEffects(Entity* entity, const Vector&, const TearFlags& flags, Entity* source, float)
{
if (!entity || (source && entity->IsDamageSourceFriendly(EntityRef(source)))) return;
hit_direction_draw(source);
bool isActiveEnemy = entity->IsActiveEnemy(DEAD_EXCLUDED);
if (!source || source->type != ENTITY_TEAR || !flags[TEAR_EXPLOSIVE])
{
if (entity->IsVulnerableEnemy(nullptr)) status_effects_apply(*entity, flags, source);
if (flags[TEAR_NEEDLE_FLAG] && isActiveEnemy && !entity->IsBoss() && entity->type != ENTITY_PLAYER)
reconstruction_missing("Entity_Tear::ApplyTearFlagEffects 0067af60: Euthanasia's needle");
if (flags[TEAR_HORN] && isActiveEnemy && !entity->HasEntityFlags(FLAG_NO_TARGET))
reconstruction_missing("Entity_Tear::ApplyTearFlagEffects 0067af60: Little Horn's hand");
if (flags[TEAR_HP_DROP] && Random() % HP_DROP_CHANCE == 0)
reconstruction_missing("Entity_Tear::ApplyTearFlagEffects 0067af60: a heart knocked out");
unhandled_check(flags, HIT_UNHANDLED_FLAGS);
if (flags[TEAR_KNOCKBACK] && !entity->HasEntityFlags(FLAG_NO_KNOCKBACK) && source)
{
if (source->type != ENTITY_TEAR)
reconstruction_missing("Entity_Tear::ApplyTearFlagEffects 0067af60: a knife's or effect's knockback");
Vector push = vector_scale(vector_normalized(source->velocity), source->mass);
if (entity->mass > 0) push = vector_scale(push, 1 / entity->mass);
float multiplier = static_cast<Entity_Tear*>(source)->knockbackMultiplier;
entity->AddVelocity_divided(vector_scale(push, multiplier), false);
}
}
if (flags[TEAR_LIGHT_FROM_HEAVEN] && isActiveEnemy)
reconstruction_missing("Entity_Tear::ApplyTearFlagEffects 0067af60: Holy Light's beam");
if (flags[TEAR_EGG_FLAG]) reconstruction_missing("Entity_Tear::ApplyTearFlagEffects 0067af60: Parasitoid's egg");
bool isGoreTarget = (g_game->deathmatchManager.is_active() && entity->type == ENTITY_PLAYER) ||
Entity::is_enemy_type(entity->type);
if (flags[TEAR_EXTRA_GORE] && isGoreTarget) entity->AddEntityFlags(FLAG_EXTRA_GORE);
}
// The rest of Entity_Tear is not reconstructed yet: the split projectiles, Dead Eye, the multidimensional copies,
// the variant change, the links and the rerolls.
// 00678080
void Entity_Tear::fire_split_projectiles(bool)
{
reconstruction_missing("Entity_Tear::fire_split_projectiles 00678080");
}
// 00679e80
void Entity_Tear::SetDeadEyeIntensity(float)
{
reconstruction_missing("Entity_Tear::SetDeadEyeIntensity 00679e80");
}
// 0067a190
Entity_Tear* Entity_Tear::MakeMultidimensionalCopy(Entity*)
{
reconstruction_missing("Entity_Tear::MakeMultidimensionalCopy 0067a190");
}
// 0067a400
void Entity_Tear::ChangeVariant(int)
{
reconstruction_missing("Entity_Tear::ChangeVariant 0067a400");
}
// 0067a770
int Entity_Tear::find_nearest_linkable_tear()
{
reconstruction_missing("Entity_Tear::find_nearest_linkable_tear 0067a770");
}
// 0067a8f0
Entity_Tear* Entity_Tear::find_link_partner()
{
reconstruction_missing("Entity_Tear::find_link_partner 0067a8f0");
}
// 0067aaf0
void Entity_Tear::apply_link_spring_forces()
{
reconstruction_missing("Entity_Tear::apply_link_spring_forces 0067aaf0");
}
// 006b5320
void Entity_Tear::reroll_hit_entity(int)
{
reconstruction_missing("Entity_Tear::reroll_hit_entity 006b5320");
}