Seven agents took over tear and contact collision, NPC death with blood and gibs, champions, PathFinder, the Gaper's kin, the player's death with the game over screen, item pedestals with collectible pickup, AddCollectible and EvaluateItems, room state save and restore, GameState::read, pressure plates, fireplaces, entity lights, ambient sounds, and one Lua callback enum with gated runners. Integration reconstructed Room::Update's loot preview and Entity_NPC::UpdatePickupGhosts and replaced a leftover Sacred Orb stub that stopped every pedestal roll. Under gdb: Gapers die with blood and gibs, a cleared room opens its doors, the treasure room's item is taken (banner, costume, stats: a Magic Mushroom gives damage 3.5 -> 6.12 and a heart), death leads to the game over diary, and a saved run is read back on the next boot with Continue offered. 3028 functions taken over. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
996 lines
38 KiB
C++
996 lines
38 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 "room.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_HEIGHT_MAX = -5.1f;
|
|
constexpr float CRAWLSPACE_RANGE_SHARE = 0.6f;
|
|
constexpr float CRAWLSPACE_SINK_HEIGHT = -10;
|
|
constexpr float CRAWLSPACE_SINK_SPEED = 0.5f;
|
|
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 DEGREES_PER_RADIAN = 57.295776f;
|
|
constexpr float RANDOM_UNIT_SCALE = 2.3283064e-10f;
|
|
constexpr float RANDOM_DIRECTION_HALF_TURN = 3.14f;
|
|
|
|
// 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 HOVER_OFFSET_LIFT = -15;
|
|
constexpr float HOVER_FLOOR_DISTANCE = 8.5f;
|
|
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;
|
|
|
|
// 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 POOF_VOLUME_SMALL = 0.85f;
|
|
constexpr float POOF_VOLUME_TINY = 0.7f;
|
|
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 float RIGHT_ANGLE = 90;
|
|
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;
|
|
|
|
constexpr int EFFECT_BLOOD_SPLAT = 7;
|
|
constexpr int EFFECT_BULLET_POOF = 11;
|
|
constexpr int EFFECT_TEAR_POOF_A = 12;
|
|
constexpr int EFFECT_TEAR_POOF_B = 13;
|
|
constexpr int EFFECT_TEAR_POOF_SMALL = 79;
|
|
constexpr int EFFECT_TEAR_POOF_VERYSMALL = 80;
|
|
|
|
constexpr int SOUND_TEAR_FIRE = 153;
|
|
constexpr int SOUND_FETUS_FIRE = 237;
|
|
constexpr float FETUS_FIRE_PITCH = 1.2f;
|
|
constexpr int SOUND_TEAR_IMPACTS = 150;
|
|
constexpr int SOUND_SPLATTER = 258;
|
|
constexpr int SOUND_SWORD_BEAM_IMPACT = 49;
|
|
constexpr int SOUND_TECH_SWORD_BEAM_IMPACT = 134;
|
|
|
|
constexpr int COLLECTIBLE_NUMBER_ONE = 6;
|
|
constexpr int COLLECTIBLE_EVES_MASCARA = 310;
|
|
constexpr int COLLECTIBLE_DEAD_EYE = 373;
|
|
constexpr uint32_t CHALLENGE_ONANS_STREAK = 29;
|
|
|
|
// Onan's Streak punishes a tear that misses with a hit to its player.
|
|
constexpr float STREAK_DAMAGE = 1;
|
|
constexpr uint64_t DAMAGE_INVINCIBLE = 1ull << 13;
|
|
constexpr int STREAK_DAMAGE_COUNTDOWN = 30;
|
|
|
|
constexpr uint32_t GRAPHICS_PREMULTIPLIED_ALPHA = 4;
|
|
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, 19> TEAR_PLAIN_VARIANTS = {
|
|
TEAR_BLUE, TEAR_BLOOD, 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, read by nothing written yet.
|
|
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"},
|
|
}};
|
|
|
|
// 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();
|
|
}
|
|
|
|
static Vector vector_add(Vector a, Vector b)
|
|
{
|
|
return vector_make(a.x + b.x, a.y + b.y);
|
|
}
|
|
|
|
static Vector vector_sub(Vector a, Vector b)
|
|
{
|
|
return vector_make(a.x - b.x, a.y - b.y);
|
|
}
|
|
|
|
static float vector_length(Vector v)
|
|
{
|
|
return std::sqrt(v.x * v.x + v.y * v.y);
|
|
}
|
|
|
|
// A random fraction of one, as random_float makes it.
|
|
static float random_unit()
|
|
{
|
|
return (float)Random() * RANDOM_UNIT_SCALE;
|
|
}
|
|
|
|
// A random number below max, or 0 for none.
|
|
static int random_below(int max)
|
|
{
|
|
return max == 0 ? 0 : (int)(Random() % (uint32_t)max);
|
|
}
|
|
|
|
// A random unit direction, as MusicManager::RandomVector draws it.
|
|
static Vector random_direction()
|
|
{
|
|
float angle = random_unit() * RANDOM_DIRECTION_HALF_TURN;
|
|
angle += angle;
|
|
return vector_make(std::cos(angle), std::sin(angle));
|
|
}
|
|
|
|
// 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);
|
|
}
|
|
|
|
// 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 = g_graphicsManager_flags & GRAPHICS_PREMULTIPLIED_ALPHA;
|
|
|
|
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;
|
|
}
|
|
|
|
// Plays a sound at a volume and pitch, through the fart seeds.
|
|
static void sound_play(int sound, float volume, float pitch)
|
|
{
|
|
seed_fart_sound_override(&sound);
|
|
g_manager->sfxManager.Play(sound, {.volume = volume, .pitch = pitch});
|
|
}
|
|
|
|
// 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);
|
|
}
|
|
|
|
// 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;
|
|
|
|
bool isGFuelNail = (variant == TEAR_NAIL || variant == TEAR_NAIL_BLOOD) && g_game->seedEffects.HasSeedEffect(SEED_G_FUEL);
|
|
if (isGFuelNail)
|
|
{
|
|
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, and while waiting it hovers until its player stops firing.
|
|
void Entity_Tear::Update()
|
|
{
|
|
if (isFireSoundPending)
|
|
{
|
|
play_fire_sound();
|
|
isFireSoundPending = false;
|
|
}
|
|
if (tearFlags.any()) reconstruction_missing("Entity_Tear::Update 006670f0: the tear flags' effects");
|
|
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;
|
|
}
|
|
wait_update();
|
|
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;
|
|
}
|
|
|
|
// Counts down a waiting tear, which 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 (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));
|
|
}
|
|
|
|
// 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, 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) sound_play(splash.sound, splash.volume, splash.pitch);
|
|
|
|
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();
|
|
}
|
|
|
|
// 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_make(direction.x * distance, direction.y * 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: points it along its flight, lets it die on the floor or a wall, sizes its sprite, moves it,
|
|
// and lets it fall by its speed and acceleration.
|
|
void Entity_Tear::flight_update()
|
|
{
|
|
sprite.rotation = 0;
|
|
if (is_listed(TEAR_ROTATED_VARIANTS, variant))
|
|
{
|
|
Vector direction = velocity;
|
|
if (waitFrames >= 1) direction = continueVelocity;
|
|
else if (fallingAccel > GRAVITY_MIN_ACCEL) direction.y += fallingSpeed;
|
|
sprite.rotation = std::atan2(direction.y, direction.x) * DEGREES_PER_RADIAN;
|
|
}
|
|
|
|
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 grid_hit();
|
|
|
|
if (g_game->deathmatchManager.is_active())
|
|
reconstruction_missing("Entity_Tear::Update 006670f0: the versus mode's tear reflections");
|
|
fScale = std::max(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();
|
|
posDisplacement = vector_sub(pos, previous);
|
|
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");
|
|
}
|
|
|
|
// 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. 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;
|
|
|
|
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();
|
|
}
|
|
|
|
// 00679400 Moves the tear half a step for the frame between updates 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)
|
|
{
|
|
if (parent) pos = vector_add(parent->pos, holdOffset);
|
|
return;
|
|
}
|
|
if (tearFlags.any()) reconstruction_missing("Entity_Tear::Interpolate 00679400: the tear flags' motion");
|
|
|
|
Entity::Interpolate();
|
|
if (waitFrames >= 1 || isDead) return;
|
|
posOffset.y = is_crawlspace() ? CRAWLSPACE_OFFSET_Y
|
|
: get_height_offset_y(fallingSpeed * speedMultiplier * 0.5f + height);
|
|
}
|
|
|
|
// 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, then sets up the flight its flags give it. 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;
|
|
bool isGFuelNail =
|
|
(variant == TEAR_NAIL || variant == TEAR_NAIL_BLOOD) && g_game->seedEffects.HasSeedEffect(SEED_G_FUEL);
|
|
if (!isSilent && !isGFuelNail)
|
|
sound_play(isFetus ? SOUND_FETUS_FIRE : SOUND_TEAR_FIRE, 1, isFetus ? FETUS_FIRE_PITCH : 1);
|
|
if (tearFlags.any()) reconstruction_missing("Entity_Tear::play_fire_sound 00666d40: the tear flags' flight");
|
|
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;
|
|
|
|
bool isNail = variant == TEAR_NAIL || variant == TEAR_NAIL_BLOOD;
|
|
if (isNail && g_game->seedEffects.HasSeedEffect(SEED_G_FUEL) && 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;
|
|
}
|
|
|
|
// 00676be0 Applies what its flags do when it dies, splitting it or chaining lightning. A tear without flags does
|
|
// nothing.
|
|
void Entity_Tear::apply_death_flag_effects(Entity*)
|
|
{
|
|
if (tearFlags.any()) reconstruction_missing("Entity_Tear::apply_death_flag_effects 00676be0");
|
|
}
|
|
|
|
// 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 = std::atan2(direction.y, direction.x) * DEGREES_PER_RADIAN;
|
|
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;
|
|
bool isNail = variant == TEAR_NAIL || variant == TEAR_NAIL_BLOOD;
|
|
|
|
if (variant > TEAR_FETUS) layerScale = fScale;
|
|
else if (isNail && g_game->seedEffects.HasSeedEffect(SEED_G_FUEL)) 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.
|
|
// Whether it touched any.
|
|
bool Entity_Tear::try_make_bridges(const Vector& position)
|
|
{
|
|
if (tearFlags.any()) reconstruction_missing("Entity_Tear::try_make_bridges 0067d560: the tear flags' grid hits");
|
|
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;
|
|
grid->Hurt(damage, EntityRef(this));
|
|
}
|
|
return isHitSolid;
|
|
}
|
|
|
|
// The rest of Entity_Tear is not reconstructed yet: the tear flags' behaviours.
|
|
|
|
// 006668c0
|
|
void Entity_Tear::apply_wiggle(float)
|
|
{
|
|
reconstruction_missing("Entity_Tear::apply_wiggle 006668c0");
|
|
}
|
|
|
|
// 00666ba0
|
|
void Entity_Tear::update_wiggle()
|
|
{
|
|
reconstruction_missing("Entity_Tear::update_wiggle 00666ba0");
|
|
}
|
|
|
|
// 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");
|
|
}
|