Files
isaac-port/src/entity_effect.h
T

447 lines
15 KiB
C++

#pragma once
#include "entity.h"
#include "sfx_manager.h"
#include <array>
#include <memory>
#include <span>
#include <vector>
// The effect variant that spawns a boss, which counts as the boss until it does.
constexpr int EFFECT_SPAWN_PENTAGRAM = 203;
// Whether Update goes on to its shared end (the timeout, the pause position and the Lua callback) after a variant's
// frame, or returns at once as the original does when a shrinking rock particle vanishes.
enum EffectUpdateEnd
{
EFFECT_UPDATE_FINISH,
EFFECT_UPDATE_RETURN
};
struct Entity_Effect;
// What a variant runs beside Entity_Effect's shared Init, Update and Render: its part of Init (after the shared start,
// before LoadGraphics), its frame (between Update's shared start and end) and its draw. A missing one keeps the default.
struct EffectBehaviour
{
int variant = -1;
void (*init)(Entity_Effect&) = nullptr;
EffectUpdateEnd (*update)(Entity_Effect&) = nullptr;
void (*render)(Entity_Effect&, const Vector&) = nullptr;
};
// An update that always goes on to Update's shared end.
template <void (*UPDATE)(Entity_Effect&)> EffectUpdateEnd effect_finishing(Entity_Effect& effect)
{
UPDATE(effect);
return EFFECT_UPDATE_FINISH;
}
// Redemption's states: waiting while its player holds an item up, succeeded, failed.
enum RedemptionState
{
REDEMPTION_WAITING = 1,
REDEMPTION_SUCCESS,
REDEMPTION_FAIL
};
// The pulling effect's subtypes: the purple, the grey pulsing and the red pulsing champion's.
constexpr int PULLING_PURPLE = 0;
constexpr int PULLING_GREY = 1;
constexpr int PULLING_RED = 2;
// A blood explosion's subtypes the shots and bosses splash with: a burst, a splash, a big splash and a flame.
constexpr int BLOOD_EXPLOSION_BURST = 2;
constexpr int BLOOD_EXPLOSION_SPLASH = 3;
constexpr int BLOOD_EXPLOSION_SPLASH_BIG = 4;
constexpr int BLOOD_EXPLOSION_FLAME = 5;
// The dust clouds thrown up by doors, debris and falls: their speed, spread and least spin.
constexpr float DUST_SPEED = 5;
constexpr float DUST_RADIUS = 20;
constexpr float DUST_SPIN_MIN = 2;
// Dogma's blackhole (171): its sparks (subtype 1) and swirls (2), and its states while open and closing.
constexpr int BLACKHOLE_SPARK = 1;
constexpr int BLACKHOLE_SWIRL = 2;
constexpr int BLACKHOLE_OPEN = 1;
constexpr int BLACKHOLE_CLOSING = 2;
// The enemy ghost's bursts (144): the Beast's crackwave's, and the larger one of Dogma's babies and the Beast's souls.
constexpr int ENEMY_GHOST_BURST = 1;
constexpr int ENEMY_GHOST_BLAST = 2;
// Poof02's lava splashes, small and large.
constexpr int POOF02_LAVA_SPLASH = 66;
constexpr int POOF02_LAVA_SPLASH_LARGE = 67;
// The halos' subtypes several files spawn (EFFECT_HALO).
enum HaloSubtype
{
HALO_CURSE = 3,
HALO_STATIC = 4,
HALO_TELEKINESIS = 1,
HALO_SALVATION = 6,
HALO_STATIC_PRERENDERED = 7,
HALO_DARK_ARTS = 8,
HALO_BREATH_OF_LIFE = 9
};
// The effect variants several files name (Lua's EffectVariant).
enum EffectVariant : int
{
EFFECT_BOMB_EXPLOSION = 1,
EFFECT_BLOOD_EXPLOSION = 2,
EFFECT_FLY_EXPLOSION = 3,
EFFECT_ROCK_PARTICLE = 4,
EFFECT_BLOOD_PARTICLE = 5,
EFFECT_DEVIL = 6,
EFFECT_BLOOD_SPLAT = 7,
EFFECT_MONSTROS_TOOTH = 28,
EFFECT_WOMB_TELEPORT = 82,
EFFECT_MEGA_BEAN_EXPLOSION = 202,
EFFECT_ANGEL = 9,
EFFECT_BLUE_FLAME = 10,
EFFECT_BULLET_POOF = 11,
EFFECT_TEAR_POOF_A = 12,
EFFECT_TEAR_POOF_B = 13,
EFFECT_RIPPLE_POOF = 14,
EFFECT_POOF01 = 15,
EFFECT_POOF02 = 16,
EFFECT_BOMB_CRATER = 18,
EFFECT_CRACK_THE_SKY = 19,
EFFECT_SCYTHE_BREAK = 20,
EFFECT_DIAMOND_PARTICLE = 85,
EFFECT_NAIL_PARTICLE = 86,
EFFECT_IMPACT = 97,
EFFECT_COIN_PARTICLE = 98,
EFFECT_URN_OF_SOULS = 178,
EFFECT_TINY_BUG = 21,
EFFECT_CREEP_RED = 22,
EFFECT_CREEP_GREEN = 23,
EFFECT_CREEP_YELLOW = 24,
EFFECT_CREEP_WHITE = 25,
EFFECT_CREEP_BLACK = 26,
EFFECT_WOOD_PARTICLE = 27,
EFFECT_MOM_FOOT_STOMP = 29,
EFFECT_TARGET = 30,
EFFECT_ROCKET = 31,
EFFECT_PLAYER_CREEP_LEMON_MISHAP = 32,
EFFECT_TINY_FLY = 33,
EFFECT_FART = 34,
EFFECT_TOOTH_PARTICLE = 35,
EFFECT_PLAYER_CREEP_HOLYWATER = 37,
EFFECT_SPIDER_EXPLOSION = 38,
EFFECT_HEAVEN_LIGHT_DOOR = 39,
EFFECT_WATER_DROPLET = 41,
EFFECT_POOP_EXPLOSION = 43,
EFFECT_PLAYER_CREEP_WHITE = 44,
EFFECT_PLAYER_CREEP_BLACK = 45,
EFFECT_PLAYER_CREEP_RED = 46,
EFFECT_TRINITY_SHIELD = 47,
EFFECT_HEART = 49,
EFFECT_LASER_IMPACT = 50,
EFFECT_HOT_BOMB_FIRE = 51,
EFFECT_RED_CANDLE_FLAME = 52,
EFFECT_PLAYER_CREEP_GREEN = 53,
EFFECT_PLAYER_CREEP_HOLYWATER_TRAIL = 54,
EFFECT_SPIKE = 55,
EFFECT_CREEP_BROWN = 56,
EFFECT_PULLING_EFFECT = 57,
EFFECT_POOP_PARTICLE = 58,
EFFECT_DUST_CLOUD = 59,
EFFECT_SHOCKWAVE = 61,
EFFECT_ROCK_EXPLOSION = 62,
EFFECT_WORM = 63,
EFFECT_BEETLE = 64,
EFFECT_WISP = 65,
EFFECT_EMBER_PARTICLE = 66,
EFFECT_SHOCKWAVE_DIRECTIONAL = 67,
EFFECT_WALL_BUG = 68,
EFFECT_BLOOD_DROP = 70,
EFFECT_BRIMSTONE_SWIRL = 71,
EFFECT_CRACKWAVE = 72,
EFFECT_SHOCKWAVE_RANDOM = 73,
EFFECT_ISAACS_CARPET = 74,
EFFECT_DICE_FLOOR = 76,
EFFECT_LARGE_BLOOD_EXPLOSION = 77,
EFFECT_PLAYER_CREEP_LEMON_PARTY = 78,
EFFECT_TEAR_POOF_SMALL = 79,
EFFECT_TEAR_POOF_VERYSMALL = 80,
EFFECT_EVIL_EYE = 84,
EFFECT_FALLING_EMBER = 87,
EFFECT_DARK_BALL_SMOKE_PARTICLE = 88,
EFFECT_PLAYER_CREEP_PUDDLE_MILK = 90,
EFFECT_MOMS_HAND_CONTACT = 91,
EFFECT_PLAYER_CREEP_BLACKPOWDER = 92,
EFFECT_PENTAGRAM_BLACKPOWDER = 93,
EFFECT_CREEP_SLIPPERY_BROWN = 94,
EFFECT_GOLD_PARTICLE = 95,
EFFECT_HUSH_LASER = 96,
EFFECT_WATER_SPLASH = 99,
EFFECT_HUSH_ASHES = 100,
EFFECT_HUSH_LASER_UP = 101,
EFFECT_BULLET_POOF_HUSH = 102,
EFFECT_FIREWORKS = 104,
EFFECT_ENEMY_BRIMSTONE_SWIRL = 110,
EFFECT_HAEMO_TRAIL = 111,
EFFECT_HALLOWED_GROUND = 112,
EFFECT_BRIMSTONE_BALL = 113,
EFFECT_FORGOTTEN_CHAIN = 114,
EFFECT_BROKEN_SHOVEL_SHADOW = 115,
EFFECT_DIRT_PATCH = 116,
EFFECT_FORGOTTEN_SOUL = 117,
EFFECT_SMALL_ROCKET = 118,
EFFECT_SPAWNER = 120,
EFFECT_LIGHT = 121,
EFFECT_BIG_HORN_HOLE_HELPER = 122,
EFFECT_HALO = 123,
EFFECT_TAR_BUBBLE = 124,
EFFECT_BIG_HORN_HAND = 125,
EFFECT_TECH_DOT = 126,
EFFECT_BIG_SPLASH = 132,
EFFECT_WATER_RIPPLE = 133,
EFFECT_PEDESTAL_RIPPLE = 134,
EFFECT_RAIN_DROP = 135,
EFFECT_GRID_ENTITY_PROJECTILE_HELPER = 136,
EFFECT_MIST = 138,
EFFECT_WILLO_SPAWNER = 157,
EFFECT_MINES_TRAPDOOR_COVER = 139,
EFFECT_BACKDROP_DECORATION = 140,
EFFECT_SMOKE_CLOUD = 141,
EFFECT_WHIRLPOOL = 142,
EFFECT_ENEMY_GHOST = 144,
EFFECT_ROCK_POOF = 145,
EFFECT_DIRT_PILE = 146,
EFFECT_FIRE_JET = 147,
EFFECT_OCCULT_TARGET = 153,
EFFECT_DOOR_OUTLINE = 154,
EFFECT_CREEP_SLIPPERY_BROWN_GROWING = 155,
EFFECT_TALL_LADDER = 156,
EFFECT_TADPOLE = 158,
EFFECT_LIL_GHOST = 159,
EFFECT_PORTAL_TELEPORT = 161,
EFFECT_SPRITE_TRAIL = 166,
EFFECT_COLOSTOMIA_PUDDLE = 168,
EFFECT_CREEP_STATIC = 169,
EFFECT_KINETI_BEAM = 175,
EFFECT_REVERSE_EXPLOSION = 177,
EFFECT_RIFT = 180,
EFFECT_PURGATORY = 189,
EFFECT_ANIMA_CHAIN = 193,
EFFECT_CREEP_LIQUID_POOP = 195,
EFFECT_DARK_SNARE = 194,
EFFECT_CLEAVER_SLASH = 176,
EFFECT_MR_ME = 108,
EFFECT_DEAD_BIRD = 197,
EFFECT_GENERIC_TRACER = 198,
EFFECT_UMBILICAL_CORD_HELPER = 201,
EFFECT_PLAYER_CREEP_YELLOW = 204,
EFFECT_MAMA_MEGA_EXPLOSION = 127,
EFFECT_CHAIN_GIB = 163,
EFFECT_BIG_ROCK_EXPLOSION = 149,
EFFECT_BIG_CRACKWAVE = 150,
EFFECT_BIG_ATTRACT = 151,
EFFECT_FIRE_WAVE = 148,
EFFECT_BOOMERANG = 60,
EFFECT_FRIEND_BALL = 81,
EFFECT_BLACK_HOLE = 107,
EFFECT_LADDER = 8,
EFFECT_XRAY_WALL = 36,
EFFECT_STARFLASH = 40,
EFFECT_BUTTERFLY = 69,
EFFECT_BAR_PARTICLE = 75,
EFFECT_SPEAR_OF_DESTINY = 83,
EFFECT_ULTRA_GREED_FOOTPRINT = 89,
EFFECT_ULTRA_GREED_BLING = 103,
EFFECT_BROWN_CLOUD = 105,
EFFECT_FART_RING = 106,
EFFECT_DEATH_SKULL = 109,
EFFECT_OPTION_LINE = 128,
EFFECT_UNUSED_129 = 129,
EFFECT_LEECH_EXPLOSION = 130,
EFFECT_MAGGOT_EXPLOSION = 131,
EFFECT_WORMWOOD_HOLE = 137,
EFFECT_FARTWAVE = 143,
EFFECT_HORNFEL_ROOM_CONTROLLER = 152,
EFFECT_BISHOP_SHIELD = 160,
EFFECT_HERETIC_PENTAGRAM = 162,
EFFECT_SIREN_RING = 164,
EFFECT_CHARM_EFFECT = 165,
EFFECT_CHAIN_LIGHTNING = 167,
EFFECT_DOGMA_DEBRIS = 170,
EFFECT_DOGMA_BLACKHOLE = 171,
EFFECT_DOGMA_ORB = 172,
EFFECT_CRACKED_ORB_POOF = 173,
EFFECT_SHOP_SPIKES = 174,
EFFECT_ENEMY_SOUL = 179,
EFFECT_LAVA_SPAWNER = 181,
EFFECT_BIG_KNIFE = 182,
EFFECT_MOTHER_SHOCKWAVE = 183,
EFFECT_WORM_FRIEND_SNARE = 184,
EFFECT_REDEMPTION = 185,
EFFECT_HUNGRY_SOUL = 186,
EFFECT_EXPLOSION_WAVE = 187,
EFFECT_DIVINE_INTERVENTION = 188,
EFFECT_MOTHER_TRACER = 190,
EFFECT_PICKUP_GHOST = 191,
EFFECT_FISSURE_SPAWNER = 192,
EFFECT_GROUND_GLOW = 196,
EFFECT_ULTRA_DEATH_SCYTHE = 199,
EFFECT_BULLET_POOF_STATIC = 200,
EFFECT_GUN = 205
};
// Construction and destruction (005cd9f0, 005cd960) are the defaults, the extra data shared with its other holders.
// Field accessors (00435e60, 00435eb0, 004d7770, 005784c0, 0060ce20) are the public fields.
// An effect (Lua's EntityEffect): a visual or a hazard such as creep, a poof or a light beam, with its timeout, its
// fall, the per-variant data it keeps and the extra data some variants share.
// Init, Update and Render run the shared parts here and hand each variant to its group's behaviour table (the ambient,
// hazard, floor, beam, item, portal, blast, soul, Mother, shot, vortex, helper and Dogma files, and a few the player's
// and weapons' files hold) or to entity_effect_combat.h (blood, gibs, poofs, explosions). Any other variant stops.
struct Entity_Effect : Entity
{
// The base of the extra data some variants keep (MrMeData, PickupGhostData, SpriteTrailData).
struct ExtraData
{
virtual ~ExtraData() = default;
};
std::shared_ptr<ExtraData> extraData;
std::array<uint32_t, 4> varData{};
std::vector<uint32_t> hitList;
GridEntityDesc gridDesc{};
Vector parentOffset{};
float baseDamage = 0;
float baseScale = 0;
float fallingAcceleration = 0;
float fallingSpeed = 0;
float height = 0;
float maxRadius = 0;
float minRadius = 0;
float rotation = 0;
float scale = 0;
int damageSource = 0;
int lifespan = 0;
int spawnSubtype = 0;
int spawnType = 0;
int spawnVariant = 0;
int state = 0;
int timeout = 0;
bool isFollowing = false;
void Init(int type, int variant, int subType, uint32_t initSeed) override;
void Update() override;
void Interpolate() override;
void Render(const Vector& offset) override;
void Remove() override;
void TriggerGlowingHourglass() override;
void ClearReferences() override;
bool CanShutDoors() override;
bool HandleCollision(Entity* collider, bool isLow) override;
void SetTimeout(int frames);
void SetRadii(float newMinRadius, float newMaxRadius);
void FollowParent(Entity* parent);
static bool rift_attract_filter(int first, int second);
void update_mr_me();
static void moonlight_timer_callback(Entity_Effect* timer);
static bool IsPlayerCreep(int effectVariant);
static Entity_Effect* CreateTimer(void* fn, uint32_t delay, uint32_t times, bool isPersistent);
void update_variant178_shooter(bool isPositionOnly);
static Entity_Effect* CreateLootPreview(LootList* lootList, const Vector& pos, Entity* owner, Entity_Effect* effect);
void setup_loot_preview(LootList* lootList);
};
// The most pickups a pickup ghost shows.
constexpr int PICKUP_GHOST_SLOTS = 4;
// Construction and destruction (005d2300, 005d23a0) are the defaults.
// The pickups a pickup ghost (Guppy's Eye's look into a chest) shows, which setup_loot_preview fills.
struct PickupGhostData : Entity_Effect::ExtraData
{
std::array<ANM2, PICKUP_GHOST_SLOTS> sprites;
int count = 0;
};
// Construction (005cd850) and destruction are the defaults.
// What Mr. ME! is doing: its job, the cell it works on, the pickup it carries (drawn on it) with the collision it
// took from it, its frames of work, and whether a Glitched Crown pedestal is about.
struct MrMeData : Entity_Effect::ExtraData
{
ANM2 carried;
int frames = 0;
int gridIndex = -1;
int job = 0;
int savedCollisionClass = 0;
bool isGlitchedCrown = false;
};
// The groups of variants Entity_Effect hands out by table (entity_effect_<group>.cpp).
std::span<const EffectBehaviour> ambient_effect_behaviours();
std::span<const EffectBehaviour> hazard_effect_behaviours();
std::span<const EffectBehaviour> floor_effect_behaviours();
std::span<const EffectBehaviour> beam_effect_behaviours();
std::span<const EffectBehaviour> spike_effect_behaviours();
std::span<const EffectBehaviour> boss_effect_behaviours();
std::span<const EffectBehaviour> alt_effect_behaviours();
std::span<const EffectBehaviour> item_effect_behaviours();
std::span<const EffectBehaviour> portal_effect_behaviours();
std::span<const EffectBehaviour> blast_effect_behaviours();
std::span<const EffectBehaviour> soul_effect_behaviours();
std::span<const EffectBehaviour> mother_effect_behaviours();
std::span<const EffectBehaviour> shot_effect_behaviours();
std::span<const EffectBehaviour> vortex_effect_behaviours();
std::span<const EffectBehaviour> helper_effect_behaviours();
std::span<const EffectBehaviour> dogma_effect_behaviours();
// The frame the plain poofs share: the sprite turned by the effect's rotation (mirrored unless flipped), the effect
// gone once its animation ends.
EffectUpdateEnd effect_poof_update(Entity_Effect& effect);
// Plays a sound through the seeds' fart override (SoundEffects::PlayWithFartOverride).
void effect_sound_play(int sound, SoundPlay play = {});
// FUN_007ab0e0: whether a player is free to step into a light or a portal: no extra or item animation playing, unless
// carrying their twin.
bool is_player_free(Entity_Player& player);
// The tear flags an effect carries in its variant data, and laying them there.
TearFlags effect_tear_flags(const Entity_Effect& effect);
void effect_tear_flags_set(Entity_Effect& effect, const TearFlags& flags);
// A chain lightning to start (spawn_chain_lightning's arguments): where, its damage and tear flags, from whom.
struct ChainLightning
{
TearFlags tearFlags{};
Vector position{};
Entity* spawner = nullptr;
float damage = 0;
};
Entity_Effect* chain_lightning_spawn(const ChainLightning& chain);
// FUN_0060dae0: whether the Siren may charm a familiar.
struct Entity_Familiar;
bool is_familiar_charmable(Entity_Familiar& familiar);
int timer_times_get(Entity_Effect& timer);
// Sets a layer to draw additively (BlendMode::SetMode 2), or normally (1).
void layer_additive_set(LayerState& layer);
void layer_normal_set(LayerState& layer);
// The degrees of a full turn.
constexpr float DEGREES_PER_TURN = 360;
float angle_wrapped(float angle);
float angle_approach(float current, float target, float maxStep);
void vector_lerp(Vector& v, Vector target, float t);
// A color tinted, with no colorize or offset (Color::Reset and SetTint).
constexpr ColorMod tint_color_make(float red, float green, float blue, float alpha)
{
return {{red, green, blue, alpha}, {0, 0, 0, 0}, {0, 0, 0}};
}