Files
isaac-port/src/entity_npc.h
T

389 lines
13 KiB
C++

#pragma once
#include "entity.h"
#include "anm2.h"
#include "entity_projectile.h"
#include "path_finder.h"
#include <deque>
#include <vector>
// Lua's NpcState: where an NPC's AI is in its routine. State 1 holds the AI while the NPC appears.
enum NpcState : int
{
NPC_STATE_INIT = 0,
NPC_STATE_APPEAR = 1,
NPC_STATE_APPEAR_CUSTOM = 2,
NPC_STATE_IDLE = 3,
NPC_STATE_MOVE = 4,
NPC_STATE_SUICIDE = 5,
NPC_STATE_JUMP = 6,
NPC_STATE_STOMP = 7,
NPC_STATE_ATTACK = 8,
NPC_STATE_ATTACK2 = 9,
NPC_STATE_ATTACK3 = 10,
NPC_STATE_ATTACK4 = 11,
NPC_STATE_ATTACK5 = 12,
NPC_STATE_SUMMON = 13,
NPC_STATE_SUMMON2 = 14,
NPC_STATE_SUMMON3 = 15,
NPC_STATE_SPECIAL = 16,
NPC_STATE_UNIQUE_DEATH = 17,
NPC_STATE_DEATH = 18
};
// Which extra AI calls an NPC asks for (_aiCallFlags), and the phase (_aiCallPhase) the AI sees in each.
enum AiCall : uint32_t
{
AI_CALL_PRE_UPDATE = 1 << 0,
AI_CALL_INTERPOLATE = 1 << 1,
AI_CALL_COLLISION = 1 << 2,
AI_CALL_POST_UPDATE = 1 << 3
};
enum AiPhase : int
{
AI_PHASE_UPDATE = 0,
AI_PHASE_PRE_UPDATE = 1,
AI_PHASE_INTERPOLATE = 2,
AI_PHASE_COLLISION = 3,
AI_PHASE_POST_UPDATE = 4
};
// The spreads FireProjectiles shoots (Lua's ProjectilesMode): fans of one to five shots along the velocity, plus and
// cross shapes and their union at the velocity's x, and a ring of round(velocity.y) shots at the velocity's x.
enum ProjectilesMode : int
{
PROJECTILES_SINGLE,
PROJECTILES_TWO,
PROJECTILES_THREE,
PROJECTILES_THREE_WIDE,
PROJECTILES_FOUR,
PROJECTILES_FIVE,
PROJECTILES_PLUS,
PROJECTILES_CROSS,
PROJECTILES_EIGHT,
PROJECTILES_RING
};
// Lua's ChampionColor values the NPC code tests.
enum ChampionColor : int
{
CHAMPION_NONE = -1,
CHAMPION_RED = 0,
CHAMPION_YELLOW = 1,
CHAMPION_GREEN = 2,
CHAMPION_ORANGE = 3,
CHAMPION_DARK_BLUE = 4,
CHAMPION_DARK_GREEN = 5,
CHAMPION_WHITE = 6,
CHAMPION_GREY = 7,
CHAMPION_TRANSPARENT = 8,
CHAMPION_FLICKER = 9,
CHAMPION_PINK = 10,
CHAMPION_PURPLE = 11,
CHAMPION_DARK_RED = 12,
CHAMPION_LIGHT_BLUE = 13,
CHAMPION_CAMO = 14,
CHAMPION_PULSE_GREEN = 15,
CHAMPION_PULSE_GREY = 16,
CHAMPION_FLY_PROTECTED = 17,
CHAMPION_TINY = 18,
CHAMPION_GIANT = 19,
CHAMPION_PULSE_RED = 20,
CHAMPION_SIZE_PULSE = 21,
CHAMPION_KING = 22,
CHAMPION_DEATH = 23,
CHAMPION_BROWN = 24,
CHAMPION_RAINBOW = 25,
CHAMPION_COUNT = 26
};
// Mask of Infamy's hit color, and Singe's ball variant.
constexpr ColorMod INFAMY_COLOR = {{1, 1, 1, 1}, {0, 0, 0, 0}, {64 / 255.0f, 64 / 255.0f, 128 / 255.0f}};
constexpr int SINGE_BALL = 1;
// How far apart a line check samples.
constexpr float LINE_STEP = 10;
// The Sucker's Bulb and Bloodfly variants.
constexpr int SUCKER_BULB = 5;
constexpr int SUCKER_BLOODFLY = 7;
// Construction (0043ef30) is the default, but for the circle angle it draws at random.
// How FireProjectiles shoots (Lua's ProjectileParams): the shots' variant, look, fall, homing and change, and the
// spread they leave in.
struct ProjectileParams
{
ProjectileHook motionHook = nullptr;
ColorMod color = COLOR_DEFAULT;
Vector fireDirectionLimit{};
Vector positionOffset{};
Vector targetPosition{};
uint64_t bulletFlags = 0;
uint64_t changeFlags = 0;
float acceleration = 1.01f;
float changeVelocity = 0;
float circleAngle;
float curvingStrength = 0.005f;
float damage = -1;
float depthOffset = 0;
float dotProductLimit = -1000;
float fallingAccelModifier = 0;
float fallingSpeedModifier = 0;
float heightModifier = 0;
float homingStrength = 1;
float scale = 1;
float spread = 1;
float velocityMulti = 1;
int changeTimeout = 30;
int variant = 0;
int wiggleFrameOffset = 0;
bool isGridCollision = true;
bool isFallingKept = false;
bool isRenderedAtGround = false;
ProjectileParams();
};
// Construction and destruction (006b88e0, 006b8590, 006b8910) are the defaults.
// Field accessors (004567a0, 006a8230, 006b8480, 007e92b0, 004e4850) are the public fields.
// An enemy or other non-player character (Lua's EntityNPC): its AI state and counters, pathfinder, champion and boss
// colors, shields, Delirium's forms, and the player controlling it with Siren or a friendly ball.
struct Entity_NPC : Entity
{
ANM2 chargeBarSprite;
ANM2 statusEffectSprite;
PathFinder pathfinder{this};
std::deque<EntityPtr> entityDeque;
std::deque<Vector> vectorDeque1;
std::deque<Vector> vectorDeque2;
std::deque<float> damageHistory;
std::vector<DamageEvent> killDamageEvents;
std::vector<uint32_t> hitList;
std::vector<uint32_t> secondaryHitList;
ColorMod dirtColor = COLOR_DEFAULT;
ColorMod floorColor = COLOR_DEFAULT;
EntityPtr aimTargetEffect;
EntityPtr entityRef;
EntityPtr forcedTarget;
EntityPtr pickupGhostsEntity;
EntityPtr salvationTarget;
EntityPtr unknownF54;
Entity* collisionEntity = nullptr;
Entity* deliriumEntity = nullptr;
Entity_Player* sirenPlayerEntity = nullptr;
uint64_t killDamageFlags = 0;
Vector confusionTargetPos{};
Vector controllerMovement{};
Vector forwardVector{};
Vector v1{};
Vector v2{};
float aiFloat = 1;
float championSpeed = 1;
float flickerAlpha = 1;
float hitPointsMulti = 1;
float killDamage = 0;
float scale = 1;
float scaleMulti = 1;
float shieldStrength = 0;
float totalDamageTaken = 0;
int aiCallPhase = AI_PHASE_UPDATE;
int aiCounter = 0;
int appearFrames = 0;
int bosscoloridx = -1;
int championColorIdx = CHAMPION_NONE;
int championTimer = 0;
int collisionResult = 0;
int controllerID = -1;
int decoyTargetTimer = 0;
int flickerState = 0;
int flickerTimer = 0;
int forcedTargetTimer = 0;
int groupIdx = -1;
int i1 = 0;
int i2 = 0;
int lastGridIndex = -1;
int projectileCooldown = 0;
int projectileDelay = -1;
int savedState = 0;
int shieldFrames = 0;
int state = NPC_STATE_INIT;
int stateFrame = 0;
int unknownF2c = 0;
uint32_t aiCallFlags = 0;
uint32_t deliriumAttackID = 0;
uint32_t deliriumBossType = 0;
uint32_t deliriumBossVariant = 0;
uint32_t deliriumCycleID = 0;
uint32_t deliriumCycleIDHigh = 0;
short championRegenCount = 0;
uint16_t championRegenTimer = 0;
uint16_t deliriumTransformationTimer = 0;
uint8_t deliriumAttackAngle = 0;
uint8_t deliriumRemainingAttacks = 0;
uint8_t deliriumState = 0;
bool isBestiaryEncountered = false;
bool isBoss = false;
bool isCanShutDoors = false;
bool isChampion = false;
bool isCollisionIsLow = false;
bool isDeathSoundAlt = false;
bool isUnknownC61 = false;
bool isUnknownC62 = false;
bool isUnreachableOnce = false;
void Init(int type, int variant, int subType, uint32_t initSeed) override;
void PreUpdate() override;
void Update() override;
void Interpolate() override;
void Render(const Vector& offset) override;
bool RenderShadowLayer(const Vector& offset) override;
bool TakeDamage(float damage, uint64_t damageFlags, const EntityRef& source, int damageCountdown) override;
void Kill(const EntityRef& source) override;
void Remove() override;
void ClearReferences() override;
bool CanShutDoors() override;
bool IsBoss() override;
bool TryThrow(const EntityRef& source, const Vector& direction, float force) override;
Vector GetForwardVector() override;
bool HandleCollision(Entity* collider, bool isLow) override;
void ResetColor() override;
void LoadEntityConfig() override;
void load_graphics(bool isReloadAnm2);
void boss_color_roll();
static bool Redirect(int* entityType, int* variant);
void Morph(int entityType, int variant, int subType, int championId);
void MakeChampion(uint32_t seed, int championColor, bool isInit);
void SetBossColorIdx(int bossColorIdx, int unused);
void SetScale(float newScale);
void UpdateDirtColor(bool isImmediate);
void room_enter();
float compute_speed_multiplier();
void ai_call(AiPhase phase);
void status_overlay_update();
bool paused_update();
void appear_update();
void appear_init();
void death_animation_update();
void death_animation_start();
void decoy_update();
void champion_update();
void champion_traits_apply(bool isInit);
void white_champion_update();
void flicker_update();
void champion_shot_fire();
void unreachable_update();
void dead_update();
void midas_coins_spawn();
void toxic_shock_creep_spawn();
void player_aura_update();
void item_effects_update();
void poof02_spawn();
void ripple_spawn();
void seed_effects_update();
void type_update();
void forced_target_update();
void update_frozen();
void update_physics();
void apply_velocity(char isInterpolated);
void update_move_direction_anim();
void update_blood_guide_gibs(const NullFrame& guide);
void spawn_damage_numbers();
void update_damage_history();
void status_overlay_render(const Vector& offset);
void Hornfel_UpdateAI();
void Hornfel_UpdateFrame();
Entity* GetPlayerTarget();
Vector CalcTargetPosition(float distanceLimit);
bool TryForceTarget(Entity* target, int duration);
void ResetPathFinderTarget();
bool IsTargetInAttackRange(float range, int frameInterval, bool isPredictVelocity);
int GetAliveEnemyCount();
void AnimWalkFrame(std::string_view horizontalAnim, std::string_view verticalAnim, float speedThreshold);
void PlaySound(int id, float volume, int frameDelay, bool isLoop, float pitch);
void FireProjectiles(const Vector& position, const Vector& velocity, ProjectilesMode mode,
const ProjectileParams& params);
void FireBossProjectiles(int count, const Vector& targetPos, float trajectoryModifier,
const ProjectileParams& params);
void projectile_params_apply(Entity_Projectile& projectile, const ProjectileParams& params);
void fire_projectile_from_params(Entity_Projectile* projectile);
Entity_Effect* MakeSplat(float size);
Entity_Effect* MakeBloodCloud(const Vector& pos, const ColorMod& color);
static Entity_NPC* ThrowSpider(const Vector& position, Entity* spawner, Vector targetPos, bool isBig,
float yOffset);
void PlayDeathEffects();
int death_burst_get();
void trigger_kill_item_effects();
void trigger_death_rewards();
void KillUnique();
bool CanBeDamagedFromVelocity(Vector velocity);
bool CanReroll();
uint8_t split(float damage, const EntityRef& source, bool isPlaySound);
Entity_NPC* ParentNPC();
Entity_NPC* ChildNPC();
void ClearChild();
void ClearDequeRefs();
void set_entity_ptr_f54(Entity* entity);
void SetRef_bec(Entity* entity);
void hold_set(int countdown, const Vector& position);
bool IsControllerActionPressed(int action);
bool IsControllerActionTriggered(int buttonAction);
Vector GetControllerInput(float deadzone);
Vector GetControllerMovementInput(float deadzone);
bool is_controller_input_idle();
void UpdateControllerMovement(bool isForceUpdate);
void UpdateChildEffectPosition(bool isPredictMovement);
void TransferControl(Entity_NPC* target);
void SpawnControlTarget(int inputMode, float rotation);
Vector GetAimTargetPosition();
void SetAimAngle(float angle);
void UpdateChargeBar(float start, float end, float value, bool isHideWhenFull);
void UpdatePickupGhosts();
void SetMinecartPosVel(const Vector& pos, const Vector& vel);
void MinecartUpdateChild(Entity* child);
void UpdateCordChain(bool isHalfScale);
void render_overlay(const Vector& offset, bool isShadow);
void render_v1_layer_frames();
void RenderSegmentLink(const Vector& offset, bool isShadow);
void CreateBling();
void CreateGoldParticles(uint32_t count);
void* fireplace_get_loot(void* outLoot, bool isShouldAdvance);
void on_player_damaged();
static int FindTargetPit(const Vector& pos1, const Vector& pos2, uint32_t pitIndex);
static Entity_NPC* ThrowStrider(const Vector& pos, Entity* spawner, const Vector& targetPos);
static void* QueryNPCsType(void* outList, int type, int variant);
static EntityList* QueryNPCsGroup(EntityList* outList, int groupIdx);
static void render_debug(float* position, int unused);
};
extern bool g_isChampionRollSkipped;
// Room::CheckLine's modes: a 10 wide band for walkers, the line's own cells, and the band for shots (over pits).
// A threshold of 999 lets any grid path pass.
enum LineCheckMode : int
{
LINE_MODE_GROUND = 0,
LINE_MODE_CELL = 1,
LINE_MODE_PROJECTILE = 3
};
constexpr int LINE_CHECK_THRESHOLD = 999;
// Game's, Room's and PlayerManager's queries the enemies need, until those classes carry them.
Entity_Player* game_nearest_player(const Vector& position);
bool game_is_enemy_erased(Entity& entity);
bool any_player_flying();
Entity* game_nearest_target_player(const Vector& position, Entity* source, bool isPlayersOnly, bool isTargetDecoys,
float maxDistance);
void game_shake_screen(int timeout);
bool game_is_hard_mode();
uint32_t room_grid_collision_at(const Vector& position);
ColorMod champion_sprite_color_get(int championColor);
bool room_check_line(const Vector& start, const Vector& end, int mode, int gridPathThreshold);