From 024cb120162e3462d0a20262e1f68a6606528fb4 Mon Sep 17 00:00:00 2001 From: shweet Date: Sat, 21 Nov 2026 01:27:03 -0500 Subject: [PATCH] Curation round 17: Theora and Vorbis cutscene videos, Ludovico, Epic and Dr. Fetus, Tractor Beam and Eye of the Occult, familiars and blue spiders, fortune teller and restock, the Bag of Crafting and four tainted characters, ten enemies, water and the ultra secret door, Isaac, ???, the Lamb and Hush --- generated-src/classes.h | 127 +-- generated-src/npc_helper.cpp | 189 ---- generated-src/stubs.cpp | 108 --- generated-src/weapon_fetus.cpp | 413 --------- generated-src/weapon_ludovico.cpp | 635 ------------- generated-src/weapon_rockets.cpp | 525 ----------- src/active_items.h | 14 + src/bomb_explosion.cpp | 8 +- src/boss_ai.h | 13 + src/boss_hush.cpp | 1327 ++++++++++++++++++++++++++++ src/boss_isaac.cpp | 1276 ++++++++++++++++++++++++++ src/boss_lamb.cpp | 621 +++++++++++++ src/boss_polycephalus.cpp | 365 +++++++- src/console_commands.cpp | 3 +- src/cutscene.cpp | 13 +- src/cutscene.h | 1 + src/entity.cpp | 8 +- src/entity.h | 35 +- src/entity_bomb.cpp | 206 ++++- src/entity_bomb.h | 7 +- src/entity_combat.cpp | 12 +- src/entity_effect.cpp | 5 +- src/entity_effect.h | 17 +- src/entity_effect_boss.cpp | 133 +++ src/entity_factory.cpp | 11 +- src/entity_familiar.cpp | 148 +++- src/entity_familiar.h | 22 +- src/entity_list.cpp | 39 +- src/entity_npc.cpp | 132 ++- src/entity_npc.h | 4 +- src/entity_npc_render.cpp | 3 - src/entity_npc_rewards.cpp | 7 +- src/entity_pickup.cpp | 53 +- src/entity_pickup.h | 1 + src/entity_pickup_chest.cpp | 4 +- src/entity_pickup_morph.cpp | 8 +- src/entity_player.cpp | 62 ++ src/entity_player.h | 22 +- src/entity_player_actives.cpp | 78 +- src/entity_player_bombs.cpp | 105 +++ src/entity_player_characters.cpp | 166 +++- src/entity_player_characters.h | 11 + src/entity_player_collectibles.cpp | 6 +- src/entity_player_costumes.cpp | 19 +- src/entity_player_crafting.cpp | 641 ++++++++++++++ src/entity_player_crafting.h | 10 + src/entity_player_damage.cpp | 36 +- src/entity_player_death.cpp | 1 - src/entity_player_evaluate.cpp | 2 +- src/entity_player_forgotten.cpp | 2 + src/entity_player_frame.cpp | 152 +++- src/entity_player_missing.cpp | 40 - src/entity_player_pockets.cpp | 1 - src/entity_player_weapons.cpp | 1 - src/entity_projectile.cpp | 209 ++++- src/entity_projectile.h | 5 + src/entity_slot.cpp | 73 +- src/entity_slot.h | 1 + src/entity_tear.cpp | 419 ++++++++- src/entity_tear.h | 10 + src/entity_water.cpp | 137 +++ src/familiar_ai.cpp | 31 +- src/familiar_bums.cpp | 3 +- src/familiar_collision.cpp | 360 +++++++- src/familiar_evaluate.cpp | 36 +- src/familiar_follow.cpp | 68 ++ src/familiar_missing.cpp | 30 - src/familiar_shoot.cpp | 240 ++++- src/familiar_walker.cpp | 244 +++++ src/game.h | 1 + src/game_restore.cpp | 2 + src/game_save.cpp | 2 + src/grid_entity.cpp | 7 + src/grid_entity.h | 8 +- src/grid_entity_rock.cpp | 10 +- src/homing_laser.cpp | 185 +++- src/hud.cpp | 138 ++- src/hud.h | 12 +- src/item_config.h | 3 +- src/item_pickup.cpp | 171 +++- src/level.cpp | 14 +- src/lua_api_entity_player.cpp | 6 +- src/lua_api_game.cpp | 4 +- src/lua_api_room.cpp | 3 +- src/manager.cpp | 19 +- src/music_manager.h | 1 + src/npc_ai.cpp | 35 +- src/npc_alt.h | 14 +- src/npc_blaster.cpp | 3 +- src/npc_clotty.cpp | 1 - src/npc_cod_worm.cpp | 159 ++++ src/npc_collision.cpp | 44 +- src/npc_dark_esau.cpp | 587 ++++++++++++ src/npc_depths.h | 9 + src/npc_fire_worm.cpp | 184 ++++ src/npc_fireplace.cpp | 4 +- src/npc_fly.cpp | 3 +- src/npc_hanger.cpp | 111 +++ src/npc_hardy.cpp | 11 +- src/npc_hush_gaper.cpp | 105 +++ src/npc_mobile_host.cpp | 202 +++++ src/npc_moms_hand.cpp | 182 ++++ src/npc_mr_maw.cpp | 274 ++++++ src/npc_mulligan.cpp | 2 - src/npc_poky.cpp | 167 ++++ src/npc_rock_spider.cpp | 346 ++++++++ src/npc_strider.cpp | 187 ++++ src/npc_wizoob.cpp | 199 +++++ src/platform.cpp | 5 +- src/player_hud.cpp | 6 +- src/player_manager.cpp | 138 ++- src/room.cpp | 42 +- src/room.h | 1 + src/room_clear.cpp | 9 +- src/room_lighting.cpp | 13 - src/room_path.cpp | 76 ++ src/room_render.cpp | 216 ++++- src/room_update.cpp | 160 +++- src/sfx_manager.h | 35 +- src/tainted_characters.cpp | 607 +++++++++++++ src/tainted_characters.h | 21 + src/video_player.cpp | 403 ++++++++- src/video_player.h | 18 +- src/weapon.cpp | 75 +- src/weapon.h | 1 + src/weapon_fetus.cpp | 130 +++ src/weapon_fetus.h | 29 + src/weapon_lasers.cpp | 38 + src/weapon_lasers.h | 1 + src/weapon_ludovico.cpp | 250 ++++++ src/weapon_ludovico.h | 27 + src/weapon_rockets.cpp | 388 ++++++++ src/weapon_rockets.h | 27 + 133 files changed, 13325 insertions(+), 2520 deletions(-) delete mode 100644 generated-src/weapon_fetus.cpp delete mode 100644 generated-src/weapon_ludovico.cpp delete mode 100644 generated-src/weapon_rockets.cpp create mode 100644 src/boss_hush.cpp create mode 100644 src/boss_isaac.cpp create mode 100644 src/boss_lamb.cpp create mode 100644 src/entity_effect_boss.cpp create mode 100644 src/entity_player_crafting.cpp create mode 100644 src/entity_player_crafting.h create mode 100644 src/entity_water.cpp create mode 100644 src/npc_cod_worm.cpp create mode 100644 src/npc_dark_esau.cpp create mode 100644 src/npc_fire_worm.cpp create mode 100644 src/npc_hanger.cpp create mode 100644 src/npc_hush_gaper.cpp create mode 100644 src/npc_mobile_host.cpp create mode 100644 src/npc_moms_hand.cpp create mode 100644 src/npc_mr_maw.cpp create mode 100644 src/npc_poky.cpp create mode 100644 src/npc_rock_spider.cpp create mode 100644 src/npc_strider.cpp create mode 100644 src/npc_wizoob.cpp create mode 100644 src/tainted_characters.cpp create mode 100644 src/tainted_characters.h create mode 100644 src/weapon_fetus.cpp create mode 100644 src/weapon_fetus.h create mode 100644 src/weapon_ludovico.cpp create mode 100644 src/weapon_ludovico.h create mode 100644 src/weapon_rockets.cpp create mode 100644 src/weapon_rockets.h diff --git a/generated-src/classes.h b/generated-src/classes.h index 3f13505..8aac6c0 100644 --- a/generated-src/classes.h +++ b/generated-src/classes.h @@ -261,6 +261,7 @@ struct FXVein; struct FamiliarCount; struct FamiliarData; struct Fart; +struct FetusShot; struct File; struct FileSymbolInfo; struct FileSystem; @@ -364,6 +365,7 @@ struct ItemInfoHUD; struct ItemOverlay; struct ItemPool; struct ItemPool_Item; +struct ItemUse; struct KAGE_Filesys_File; struct KAGE_Filesys_FileManager; struct KAGE_Filesys_FileStream; @@ -4022,52 +4024,6 @@ struct Weapon_Deathmatch { }; LAYOUT32(sizeof(Weapon_Deathmatch) == 0x44); -struct Weapon_Fetus { - virtual ~Weapon_Fetus(); // 009f3260 slot 0 - virtual void Init(uint32_t param_2, uint32_t param_3); // 009f34d0 slot 1 Weapon::Init - virtual void Update(char param_2); // 009f34f0 slot 2 Weapon::Update - virtual void Fire(Vector *direction, uint8_t isShooting, uint8_t isInterpolated); // 00a036e0 slot 3 - virtual void Reset(); // 009f3480 slot 4 Weapon::Reset - virtual void ClearReferences(); // 009f3320 slot 5 Weapon::ClearReferences - virtual float GetMaxCharge(); // 00a03f60 slot 6 - virtual long double GetChargeBarAmount(); // 009f4150 slot 7 Weapon::GetChargeBarAmount - virtual void vfunc_8(); // 009f3130 slot 8 Weapon::GetMaxCharge - virtual uint32_t GetFocusEntity(); // 009f3140 slot 9 Weapon::GetFocusEntity - virtual void vfunc_10(); // 009f3140 slot 10 Weapon::GetFocusEntity - virtual void guard_check_icall(); // 0040c200 slot 11 ::guard_check_icall - virtual int GetMarkedTargetVariant(); // 009fa1b0 slot 12 Weapon_Bombs::GetMarkedTargetVariant - virtual uint8_t CanShutDoors(); // 005ccc00 slot 13 Entity::CanShutDoors - virtual void vfunc_14(); // 005ccc00 slot 14 Entity::CanShutDoors - virtual uint8_t CanTakeDamageFromTearEffects(); // 00709c30 slot 15 GridEntity::CanTakeDamageFromTearEffects - virtual void vfunc_16(); // 005ccc00 slot 16 Entity::CanShutDoors - - uint8_t _pad_0x4[0x40]; -}; -LAYOUT32(sizeof(Weapon_Fetus) == 0x44); - -struct Weapon_Ludovico { - virtual ~Weapon_Ludovico(); // 009f9880 slot 0 Weapon_Bombs::Free - virtual void Init(uint32_t param_2, uint32_t param_3); // 009f34d0 slot 1 Weapon::Init - virtual void Update(char param_2); // 009f34f0 slot 2 Weapon::Update - virtual void Fire(Vector *direction, uint8_t isShooting, uint8_t isInterpolated); // 00a06a30 slot 3 - virtual void Reset(); // 009f3480 slot 4 Weapon::Reset - virtual void ClearReferences(); // 00a063b0 slot 5 Weapon_Laser::ClearReferences - virtual long double GetMaxCharge(); // 009f3130 slot 6 Weapon::GetMaxCharge - virtual long double GetChargeBarAmount(); // 009f4150 slot 7 Weapon::GetChargeBarAmount - virtual void vfunc_8(); // 009f3130 slot 8 Weapon::GetMaxCharge - virtual Entity * GetMainEntity(); // 009f3150 slot 9 Weapon::GetMainEntity - virtual void vfunc_10(); // 009f3150 slot 10 Weapon::GetMainEntity - virtual void guard_check_icall(); // 0040c200 slot 11 ::guard_check_icall - virtual uint32_t GetFocusEntity(); // 009f3140 slot 12 Weapon::GetFocusEntity - virtual uint8_t CanShutDoors(); // 005ccc00 slot 13 Entity::CanShutDoors - virtual void vfunc_14(); // 005ccc00 slot 14 Entity::CanShutDoors - virtual void vfunc_15(); // 005ccc00 slot 15 Entity::CanShutDoors - virtual void vfunc_16(); // 005ccc00 slot 16 Entity::CanShutDoors - - uint8_t _pad_0x4[0x44]; -}; -LAYOUT32(sizeof(Weapon_Ludovico) == 0x48); - struct Weapon_MonstrosLung { virtual ~Weapon_MonstrosLung(); // 009f3260 slot 0 virtual void Init(uint32_t param_2, uint32_t param_3); // 009f34d0 slot 1 Weapon::Init @@ -4092,29 +4048,6 @@ struct Weapon_MonstrosLung { }; LAYOUT32(sizeof(Weapon_MonstrosLung) == 0x44); -struct Weapon_Rockets { - virtual ~Weapon_Rockets(); // 009f9880 slot 0 Weapon_Bombs::Free - virtual void Init(uint32_t param_2, uint32_t param_3); // 009f34d0 slot 1 Weapon::Init - virtual void Update(char param_2); // 009f34f0 slot 2 Weapon::Update - virtual void Fire(Vector *aimDirection, uint8_t isShooting, uint8_t isInterpolated); // 00a08d40 slot 3 - virtual void Reset(); // 009f3480 slot 4 Weapon::Reset - virtual void ClearReferences(); // 00a063b0 slot 5 Weapon_Laser::ClearReferences - virtual long double GetMaxCharge(); // 009f3130 slot 6 Weapon::GetMaxCharge - virtual long double GetChargeBarAmount(); // 009f4150 slot 7 Weapon::GetChargeBarAmount - virtual void vfunc_8(); // 009f3130 slot 8 Weapon::GetMaxCharge - virtual Entity * GetMainEntity(); // 009f3150 slot 9 Weapon::GetMainEntity - virtual void vfunc_10(); // 009f3150 slot 10 Weapon::GetMainEntity - virtual void guard_check_icall(); // 0040c200 slot 11 ::guard_check_icall - virtual int GetMarkedTargetVariant(); // 00a099a0 slot 12 - virtual uint8_t CanShutDoors(); // 005ccc00 slot 13 Entity::CanShutDoors - virtual void vfunc_14(); // 005ccc00 slot 14 Entity::CanShutDoors - virtual void vfunc_15(); // 005ccc00 slot 15 Entity::CanShutDoors - virtual void vfunc_16(); // 005ccc00 slot 16 Entity::CanShutDoors - - uint8_t _pad_0x4[0x44]; -}; -LAYOUT32(sizeof(Weapon_Rockets) == 0x48); - struct Weapon_SpiritSword { virtual ~Weapon_SpiritSword(); // 009f9930 slot 0 Weapon_Laser::Free virtual void Init(uint32_t param_2, uint32_t param_3); // 009f34d0 slot 1 Weapon::Init @@ -6076,7 +6009,6 @@ void FUN_00557b50(uint32_t param_1); // 00557b50 void FUN_00557b70(uint8_t *param_1); // 00557b70 bool FUN_00557bb0(int *param_1); // 00557bb0 void collect_npcs_with_same_parent(Entity_NPC *npc); // 00557ce0 -uint32_t FUN_0055c6a0(float *param_1); // 0055c6a0 void FUN_00565dd0(uint32_t param_1); // 00565dd0 void FUN_00565de0(uint32_t param_1); // 00565de0 void FUN_00568980(char param_1); // 00568980 @@ -6161,7 +6093,6 @@ void FUN_005b19f0(uint32_t param_1); // 005b19f0 uint8_t FUN_005b1a00(); // 005b1a00 bool FUN_005b1a10(); // 005b1a10 void alabaster_box_timer_callback(Entity *timer); // 005b30b0 -uint32_t FUN_005b3990(uint32_t *param_1); // 005b3990 void FUN_005c7ad0(int param_1); // 005c7ad0 void FUN_005c7bf0(int *param_1, int *param_2); // 005c7bf0 void FUN_005c7d30(int param_1); // 005c7d30 @@ -6310,7 +6241,6 @@ void FUN_0062e0e0(int param_1); // 0062e0e0 void FUN_00631a00(float *param_1, uint32_t param_2, float *param_3); // 00631a00 void familiar_wisp_pick_tear_color(RNG *rng, int *outVariant, BitSet128 *outFlags); // 00633990 void FUN_00638e20(); // 00638e20 -void spawn_blue_spider(Vector *position, Entity *spawner, Vector *target); // 00638e30 void FUN_006395e0(Vector *param_1, int *param_2, int param_3, int param_4, int param_5, float param_6, int param_7, int param_8, Entity *param_9, int param_10); // 006395e0 void FUN_0063b240(); // 0063b240 void FUN_0063c060(int param_1); // 0063c060 @@ -6650,7 +6580,6 @@ void FUN_007098c0(); // 007098c0 void FUN_00709930(); // 00709930 int FUN_00709bc0(); // 00709bc0 uint8_t FUN_0070bf60(); // 0070bf60 -uint8_t is_grid_type_floor_special(int gridType); // 0070bf80 void FUN_0070bfa0(int param_1, int param_2, uint32_t param_3, float param_4); // 0070bfa0 void FUN_0070c570(uint32_t *param_1); // 0070c570 uint32_t FUN_00710370(); // 00710370 @@ -6762,7 +6691,6 @@ void FUN_00753620(); // 00753620 bool FUN_00753630(); // 00753630 bool FUN_00753640(); // 00753640 void FUN_00753650(); // 00753650 -void FUN_00753660(uint32_t *param_1, uint32_t param_2); // 00753660 uint32_t FUN_00753700(); // 00753700 uint32_t FUN_00753710(); // 00753710 void FUN_00753720(); // 00753720 @@ -6822,9 +6750,7 @@ void FUN_007cf940(); // 007cf940 long double FUN_007cf9a0(float *param_1, KColor *param_2, uint32_t param_3); // 007cf9a0 uint8_t * FUN_007cfa90(); // 007cfa90 void FUN_007d3330(int param_1); // 007d3330 -Game * damage_charge_scale(); // 007d3560 void FUN_007d3e00(); // 007d3e00 -char FUN_007d4320(); // 007d4320 void FUN_007d9360(); // 007d9360 uint32_t FUN_007d9ca0(); // 007d9ca0 uint32_t FUN_007da770(); // 007da770 @@ -6999,7 +6925,6 @@ void render_beast_arena_background(void *self, int pass); // 0083a3d0 void FUN_0083aae0(uint8_t param_1, int *param_2, uint32_t *param_3); // 0083aae0 void FUN_0083b830(); // 0083b830 int FUN_0083bbc0(int param_1); // 0083bbc0 -void FUN_0083bed0(int param_1, int param_2); // 0083bed0 void FUN_0083bf50(); // 0083bf50 void FUN_0083bf90(uint32_t *param_1); // 0083bf90 void Catch_All_0083c241(); // 0083c241 @@ -9390,15 +9315,11 @@ void FUN_009f3c40(); // 009f3c40 void FUN_009f4130(); // 009f4130 Entity_Player * FUN_009f4fc0(); // 009f4fc0 void FUN_009f5810(uint8_t param_1); // 009f5810 -Entity_Tear * fire_fetus_tear(void *self, Vector *position, Vector *velocity, int fireFlags, Entity *source, float damageMultiplier, int unused); // 009f6e60 uint32_t * FUN_009f9080(); // 009f9080 uint32_t * FUN_009f90f0(); // 009f90f0 uint32_t * FUN_009f9170(); // 009f9170 uint32_t * FUN_009f92d0(); // 009f92d0 -uint32_t * FUN_009f9350(); // 009f9350 uint32_t * FUN_009f93d0(); // 009f93d0 -uint32_t * FUN_009f9440(); // 009f9440 -uint32_t * FUN_009f95d0(); // 009f95d0 uint32_t * FUN_00a06940(void *param_1, uint32_t *param_2); // 00a06940 void * operator_new(uint32_t size); // 00a0f4c0 void * operator_new_tracked(uint32_t size); // 00a0f4e0 @@ -13042,7 +12963,6 @@ void FUN_00a627d0(); // 00a627d0 void FUN_00a62800(uint8_t param_1); // 00a62800 void FUN_00a62830(uint32_t param_1, uint32_t param_2, uint32_t param_3, uint32_t param_4); // 00a62830 uint8_t FUN_00a62870(); // 00a62870 -uint32_t FUN_00a62910(uint8_t *param_1); // 00a62910 uint32_t FUN_00a62a10(); // 00a62a10 char * FUN_00a62dc0(); // 00a62dc0 char * string_duplicate_lower(); // 00a62e10 @@ -13458,7 +13378,6 @@ uint32_t * FUN_00a8a010(uint32_t *param_1); // 00a8a010 char * FUN_00a8a070(char *param_1); // 00a8a070 void FUN_00a8a810(uint8_t param_1); // 00a8a810 void FUN_00a8a970(); // 00a8a970 -int * theora_create_video_clip(uint32_t param_1, int *param_2); // 00a8ab60 void Catch_00a8b0f1(); // 00a8b0f1 void FUN_00a8b130(int param_1); // 00a8b130 void FUN_00a8b160(uint8_t param_1); // 00a8b160 @@ -13803,13 +13722,9 @@ void FUN_00aa9a20(int param_1); // 00aa9a20 void FUN_00aa9a70(int param_1); // 00aa9a70 void FUN_00aa9ab0(int param_1); // 00aa9ab0 void FUN_00aa9bb0(); // 00aa9bb0 -void vorbis_info_clear(void *info); // 00aa9c20 uint32_t _vorbis_unpack_books(); // 00aa9e80 -uint32_t vorbis_synthesis_headerin(int param_1); // 00aaa150 -int FUN_00aaa450(); // 00aaa450 int FUN_00aaa4a0(); // 00aaa4a0 void FUN_00aaaa90(); // 00aaaa90 -void FUN_00aaaae0(int param_1); // 00aaaae0 uint32_t FUN_00aaabb0(); // 00aaabb0 void FUN_00aaac20(); // 00aaac20 void FUN_00aaace0(uint8_t param_1); // 00aaace0 @@ -13838,23 +13753,13 @@ void FUN_00aabd90(int *param_1, char param_2); // 00aabd90 void FUN_00aabe70(int *param_1, char param_2); // 00aabe70 uint32_t FUN_00aabeb0(); // 00aabeb0 uint32_t FUN_00aabec0(); // 00aabec0 -int64_t ogg_page_granulepos(void *page); // 00aabed0 uint32_t FUN_00aabf60(); // 00aabf60 uint32_t FUN_00aabfb0(); // 00aabfb0 uint32_t FUN_00aac040(); // 00aac040 -void ogg_page_checksum_set(); // 00aac110 int FUN_00aac1a0(); // 00aac1a0 -int ogg_sync_pageseek(); // 00aac240 -int ogg_sync_pageout(void *syncState, void *page); // 00aac3e0 -uint32_t ogg_stream_pagein(); // 00aac5c0 -uint32_t ogg_stream_reset(); // 00aac8f0 -int ogg_stream_packetout(void *streamState, void *packet); // 00aac980 int FUN_00aaca80(); // 00aaca80 void FUN_00aacae0(); // 00aacae0 uint32_t _vds_shared_init(); // 00aacb50 -void vorbis_dsp_clear(void *dspState); // 00aacf20 -uint32_t vorbis_synthesis_restart(); // 00aad330 -uint32_t vorbis_synthesis_blockin(); // 00aad3b0 uint32_t FUN_00aada30(); // 00aada30 void FUN_00aadbf0(uint32_t param_1, uint32_t param_2); // 00aadbf0 uint32_t epoxy_has_wgl_extension(uint32_t param_1); // 00aadd10 @@ -13949,7 +13854,6 @@ int I420ToRGBAMatrix(uint8_t *srcY, int srcStrideY, uint8_t *srcU, int srcStride uint32_t FUN_00ab6bc0(int param_1, int param_2, int param_3, int param_4, int param_5, int param_6, uint32_t param_7, uint32_t param_8, int param_9); // 00ab6bc0 uint32_t FUN_00ab6d00(int param_1, int param_2, int param_3, int param_4, int param_5, int param_6, uint32_t param_7, uint32_t param_8, int param_9); // 00ab6d00 void FUN_00ab6e40(); // 00ab6e40 -void oggpack_write(void *buffer, uint32_t value, int bits); // 00ab6ee0 uint32_t FUN_00ab7010(); // 00ab7010 void FUN_00ab70d0(); // 00ab70d0 uint32_t FUN_00ab7120(); // 00ab7120 @@ -14266,10 +14170,7 @@ uint32_t oc_dec_postprocess_init(int param_1); // 00add7a0 void oc_dering_block(uint8_t *param_1, uint32_t param_2, uint32_t param_3, int *param_4, int param_5, uint8_t *param_6); // 00addab0 void oc_filter_hedge(uint8_t *param_1, int param_2, int param_3, int param_4, int param_5, int param_6, int *param_7, int *param_8); // 00ade460 void oc_filter_vedge(int param_1, int param_2, int param_3, int param_4, int *param_5); // 00ade750 -void * th_decode_alloc(void *info, void *setup); // 00ade980 -uint32_t th_decode_ctl(int param_1, uint32_t param_2, uint32_t *param_3, int param_4); // 00ade9f0 void FUN_00adeb70(int param_1); // 00adeb70 -uint32_t th_decode_packetin(int *param_1, uint32_t *param_2, int64_t *param_3); // 00adebd0 uint32_t FUN_00adf8c0(int param_1, void *param_2); // 00adf8c0 void FUN_00adf8f0(int *param_1); // 00adf8f0 void FUN_00adf940(uint32_t *param_1); // 00adf940 @@ -14304,7 +14205,6 @@ uint32_t oc_state_frarray_init(int param_1); // 00ae1330 uint32_t FUN_00ae1900(int param_1, int *param_2, int param_3, short param_4); // 00ae1900 int FUN_00ae19b0(uint32_t *param_1, uint8_t *param_2, uint32_t param_3); // 00ae19b0 uint32_t oc_state_ref_bufs_init(int param_1, int *param_2); // 00ae1cf0 -int64_t th_granule_frame(void *decoder, int64_t granulePosition); // 00ae2060 long double FUN_00ae2110(int param_1, int64_t param_2); // 00ae2110 void oc_dequant_tables_init(int param_1, int param_2, int param_3); // 00ae2200 int FUN_00ae2580(int *param_1); // 00ae2580 @@ -21067,7 +20967,6 @@ namespace AudioPacketQueue { void destroyAllAudioPackets(); // 00aadc80 } namespace FamiliarAI { -void * blue_spider(Entity_Familiar *familiar); // 00616050 void bobs_brain(Entity_Familiar *familiar); // 00616770 void gb_bug(Entity_Familiar *familiar); // 00618b00 void variant_53(Entity_Familiar *familiar); // 006196e0 @@ -21101,7 +21000,6 @@ void fly_head_pathfind_move(Entity_Familiar *familiar); // 0063d570 namespace Isaac { void SwapANM2(ANM2 *left, ANM2 *right); // 00407ae0 ItemConfig * GetItemConfig(); // 0042ca00 -void SpawnLocust(Entity_Player *player, int collectibleType, Vector *pos); // 005b35c0 int Random(int Max); // 0067f010 Vector * GetRandomPickupVelocity(Vector *outVelocity, Vector *position, uint32_t pickupVelType, RNG *rng); // 006ee440 void Shutdown(); // 009ab700 @@ -21150,14 +21048,11 @@ void ENTITY_BEAST_ultra_war_bomb(Entity_NPC *npc); // 0044f2b0 void ENTITY_LIL_BLUB(Entity_NPC *npc); // 00450da0 void ENTITY_BIG_HORN_grab_bomb(Entity_NPC *npc); // 00452eb0 void ENTITY_BIG_HORN(Entity_NPC *npc); // 00453140 -void ENTITY_FLY_isaac_spawned(Entity_NPC *npc); // 004568d0 void ENTITY_WAR(Entity_NPC *npc); // 00458870 void ENTITY_DEATH(Entity_NPC *npc); // 00459d20 void ENTITY_HEADLESS_HORSEMAN(Entity_NPC *npc); // 0045cd60 void ENTITY_DARK_ONE(Entity_NPC *npc); // 0045d7d0 -float ENTITY_ISAAC(Entity_NPC *npc); // 00463100 void ENTITY_PIN(Entity_NPC *npc); // 00476860 -void ENTITY_THE_LAMB(Entity_NPC *npc); // 00483710 void ENTITY_BROWNIE(Entity_NPC *npc); // 0048c3b0 void ENTITY_CORN_MINE(Entity_NPC *npc); // 0048ee30 void ENTITY_FORSAKEN(Entity_NPC *npc); // 0048f110 @@ -21181,9 +21076,7 @@ void ENTITY_HERETIC(Entity_NPC *npc); // 004b43c0 void ENTITY_HORNFEL_DOOR(Entity_NPC *npc); // 004bb9b0 void ENTITY_HORNY_BOYS(Entity_NPC *npc); // 004bd2a0 void ENTITY_HUSH_BOIL(Entity_NPC *npc); // 004be6f0 -void ENTITY_HUSH_GAPER(Entity_NPC *npc); // 004bee40 void ENTITY_HUSH_FLY(Entity_NPC *npc); // 004bf310 -void ENTITY_HUSH(Entity_NPC *npc); // 004bfd30 void ENTITY_MATRIARCH(Entity_NPC *npc); // 004c59d0 void ENTITY_MEGA_SATAN(Entity_NPC *npc); // 004c8090 void ENTITY_MEGA_SATAN_hand(Entity_NPC *npc); // 004cca10 @@ -21216,12 +21109,10 @@ void ENTITY_BALL_AND_CHAIN(Entity_NPC *npc); // 004f4730 void ENTITY_POOFER(Entity_NPC *npc); // 004f64e0 void ENTITY_MOCKULUS(Entity_NPC *npc); // 004f76f0 void ENTITY_MORNINGSTAR(Entity_NPC *npc); // 004f7e60 -void ENTITY_ROCK_SPIDER(Entity_NPC *npc); // 004f9ad0 void ENTITY_FACELESS(Entity_NPC *npc); // 004faad0 void ENTITY_DANNY(Entity_NPC *npc); // 004fbd10 void ENTITY_MOLE(Entity_NPC *npc); // 004fdf80 void ENTITY_GYRO(Entity_NPC *npc); // 004ff620 -void ENTITY_FIRE_WORM(Entity_NPC *npc); // 00500990 void ENTITY_BOUNCER(Entity_NPC *npc); // 00501f30 void ENTITY_FLESH_MAIDEN(Entity_NPC *npc); // 00502980 void ENTITY_BOMBGAGGER(Entity_NPC *npc); // 00503300 @@ -21231,18 +21122,10 @@ void ENTITY_DUSTY_DEATHS_HEAD(Entity_NPC *npc); // 00504a40 void ENTITY_NECRO(Entity_NPC *npc); // 005052a0 void ENTITY_STONE_EYE(Entity_NPC *npc); // 00505d00 void ENTITY_KNIGHT(Entity_NPC *npc); // 005135d0 -void ENTITY_MRMAW(Entity_NPC *npc); // 00517de0 void ENTITY_SWARMER(Entity_NPC *npc); // 00518e20 -void ENTITY_HANGER(Entity_NPC *npc); // 0051cb30 void ENTITY_URIEL(Entity_NPC *npc); // 0051e0f0 void ENTITY_HEART(Entity_NPC *npc); // 0051f2f0 -void ENTITY_POKY(Entity_NPC *npc); // 00521ab0 void ENTITY_DOPLE(Entity_NPC *npc); // 00525650 -void ENTITY_BABY(Entity_NPC *npc); // 0052ae30 -void ENTITY_COD_WORM(Entity_NPC *npc); // 00531350 -void ENTITY_MOBILE_HOST(Entity_NPC *npc); // 005321d0 -void ENTITY_MOMS_HAND(Entity_NPC *npc); // 00533b80 -void ENTITY_WIZOOB(Entity_NPC *npc); // 005374a0 void ENTITY_HOMUNCULUS(Entity_NPC *npc); // 00539b90 void ENTITY_OOB(Entity_NPC *npc); // 0053ab40 void ENTITY_BLACK_MAW(Entity_NPC *npc); // 0053b2f0 @@ -21258,14 +21141,12 @@ void ENTITY_COHORT(Entity_NPC *npc); // 005513a0 void ENTITY_GENERIC_PROP(Entity_NPC *npc); // 00551d30 void ENTITY_SHADY(Entity_NPC *npc); // 005522d0 void ENTITY_BLOOD_PUPPY(Entity_NPC *npc); // 00552d30 -void ENTITY_DARK_ESAU(Entity_NPC *npc); // 005542e0 void ENTITY_PEEPER_FATTY(Entity_NPC *npc); // 005562b0 void ENTITY_WILLO(Entity_NPC *npc); // 005586b0 int ENTITY_WILLO_L2_find_target(Entity_NPC *npc); // 005591c0 void ENTITY_WILLO_L2(Entity_NPC *npc); // 005593c0 Entity_Projectile * ENTITY_BUBBLES(Entity_NPC *npc); // 0055ad20 void ENTITY_SMALL_LEECH(Entity_NPC *npc); // 0055b740 -void ENTITY_STRIDER(Entity_NPC *npc); // 0055c810 uint32_t ENTITY_POLTY(Entity_NPC *npc); // 0055d230 void ENTITY_FLY_TRAP(Entity_NPC *npc); // 00560ca0 void ENTITY_FLY_orbit_parent(Entity_NPC *npc); // 00561580 @@ -21306,7 +21187,6 @@ void ENTITY_BEAST(Entity_NPC *npc); // 00592460 void ENTITY_BEAST_stalactite(Entity_NPC *npc); // 00596120 void ENTITY_BEAST_rock_projectile(Entity_NPC *npc); // 00596c60 void ENTITY_BEAST_soul(Entity_NPC *npc); // 005971e0 -void ENTITY_POLYCEPHALUS_the_pile(Entity_NPC *npc); // 005983f0 void ENTITY_TUFF_TWINS_head_anim(Entity_NPC *npc); // 00599b80 void ENTITY_TUFF_TWINS_body_anim(Entity_NPC *npc); // 00599d70 void ENTITY_TUFF_TWINS(Entity_NPC *npc); // 0059a2d0 @@ -21315,7 +21195,6 @@ void ENTITY_TURDLET(Entity_NPC *npc); // 0059c830 void ENTITY_ULTRA_GREED(Entity_NPC *npc); // 0059edb0 void ENTITY_ULTRA_COIN(Entity_NPC *npc); // 005a4820 void ENTITY_ULTRA_DOOR(Entity_NPC *npc); // 005a5b60 -void ENTITY_GREED_GAPER(Entity_NPC *npc); // 005a6b80 void ENTITY_VISAGE(Entity_NPC *npc); // 005a7b20 void ENTITY_VISAGE_mask(Entity_NPC *npc); // 005ab4d0 void ENTITY_VISAGE_chain(Entity_NPC *npc); // 005ad250 @@ -21336,7 +21215,6 @@ void read(int param_1, int *param_2); // 009163b0 } namespace TheoraVideoManager { void TheoraVideoManager(); // 00a8a090 -void destroyVideoClip(void *clip); // 00a8b190 void createWorkerThreads(int param_1); // 00a8b570 int requestWork(uint32_t param_1); // 00a8b7d0 } @@ -21346,7 +21224,6 @@ uint32_t _readData(); // 00a8d0a0 long double _decodeAudio(); // 00a8d580 void _executeSeek(); // 00a8da40 uint32_t _seekPage(int param_1, char param_2); // 00a8e1b0 -void readTheoraVorbisHeaders(); // 00a8e530 } namespace _Entity { int GetAncestorField(uint32_t param_1); // 006b7d20 diff --git a/generated-src/npc_helper.cpp b/generated-src/npc_helper.cpp index 63a1f07..1ab861e 100644 --- a/generated-src/npc_helper.cpp +++ b/generated-src/npc_helper.cpp @@ -1,194 +1,5 @@ #include "classes.h" -// 004830e0 -void NpcHelper::the_lamb_pattern(Entity_NPC *npc, int pattern, int frame) -{ - Entity *target; - uint32_t uVar1; - int projectileCount; - bool isEighthFrame; - float fVar2; - float pitch; - Vector local_c8; - float dirY; - float dirX; - float projectileSpeed; - ProjectileParams params; - float local_8; - Manager *manager; - - local_8 = (float)(__security_cookie ^ GHIDRA_UINT(&(¶ms)[1].CircleAngle)); - ProjectileParams::ProjectileParams(¶ms); - (*GHIDRA_CAST((GHIDRA_CAST(&(params)) + 0x4))) = 0x40a00000; - params.Scale = 1.8; - params.FallingAccelModifier = -0.06; - params.FallingSpeedModifier = -2.0; - target = Entity_NPC::GetPlayerTarget(npc); - dirX = (target->_pos).x - (npc->_pos).x; - dirY = (target->_pos).y - (npc->_pos).y; - fVar2 = sqrtf(dirX * dirX + dirY * dirY); - pitch = 1.0; - if (0.0 < fVar2) { - dirY = (1.0 / fVar2) * dirY; - dirX = (1.0 / fVar2) * dirX; - } - local_c8.y = atan2f(dirY,dirX); - if (pattern < 4) { - params.Color._colorize[0] = (float)0x3f333333; - params.Color._colorize[1] = (float)0x3f333333; - params.Color._colorize[2] = 1.0; - params.Color._colorize[3] = 1.0; - if (pattern == 0) { - if (frame != (frame / 3) * 3) { - return; - } - fVar2 = (float)frame * 0.125; - } - else { - if (pattern != 1) { - if (pattern == 2) { - if (frame % 0x16 != 0) { - return; - } - projectileCount = 3; - projectileSpeed = 8.0; - (*GHIDRA_CAST((GHIDRA_CAST(&(params.BulletFlags)) + 0x0))) = GHIDRA_UINT(params.BulletFlags) | 0x10000; - params.FallingSpeedModifier = 0.0; - params.FallingAccelModifier = 0.0; - } - else { - if (pattern != 3) { - return; - } - if (frame % 0x16 != 0) { - return; - } - projectileSpeed = 9.0; - projectileCount = 10; - } - goto LAB_00483620; - } - if (frame != (frame / 3) * 3) { - return; - } - fVar2 = (float)frame * -0.125; - } - projectileSpeed = 12.0; - projectileCount = 5; - params.CircleAngle = (fVar2 / 30.0) * 6.2831855; - } - else { - (*GHIDRA_CAST((GHIDRA_CAST(&(params.BulletFlags)) + 0x0))) = GHIDRA_UINT(params.BulletFlags) | 1; - params.HomingStrength = 0.3; - if (pattern == 4) { - uVar1 = frame & 0x80000007; - isEighthFrame = uVar1 == 0; - if (GHIDRA_INT(uVar1) < 0) { - isEighthFrame = (uVar1 - 1 | 0xfffffff8) == 0xffffffff; - } - if (!isEighthFrame) { - return; - } - projectileSpeed = 9.0; - projectileCount = 7; - params.FireDirectionLimit.x = dirX; - params.FireDirectionLimit.y = dirY; - params.DotProductLimit = 0.4; - params.CircleAngle = 0.0; - } - else if (pattern == 5) { - uVar1 = frame & 0x80000007; - isEighthFrame = uVar1 == 0; - if (GHIDRA_INT(uVar1) < 0) { - isEighthFrame = (uVar1 - 1 | 0xfffffff8) == 0xffffffff; - } - if (!isEighthFrame) { - return; - } - projectileSpeed = 9.0; - projectileCount = 7; - params.FireDirectionLimit.x = dirX; - params.FireDirectionLimit.y = dirY; - params.DotProductLimit = 0.4; - params.CircleAngle = local_c8.y; - } - else if (pattern == 6) { - uVar1 = frame & 0x80000007; - isEighthFrame = uVar1 == 0; - if (GHIDRA_INT(uVar1) < 0) { - isEighthFrame = (uVar1 - 1 | 0xfffffff8) == 0xffffffff; - } - if (!isEighthFrame) { - return; - } - projectileSpeed = 9.0; - projectileCount = 7; - params.FireDirectionLimit.x = dirX; - params.FireDirectionLimit.y = dirY; - params.DotProductLimit = 0.4; - uVar1 = Random(); - params.CircleAngle = - ((float)((double)GHIDRA_INT(uVar1) + __uint_to_double_fixup[-(GHIDRA_INT(uVar1) >> 0x1f)]) * - 2.3283064e-10 - 0.5) * 3.1415927 * 0.1 + local_c8.y + 0.44879895; - } - else if (pattern == 7) { - uVar1 = frame & 0x80000007; - isEighthFrame = uVar1 == 0; - if (GHIDRA_INT(uVar1) < 0) { - isEighthFrame = (uVar1 - 1 | 0xfffffff8) == 0xffffffff; - } - if (!isEighthFrame) { - return; - } - projectileSpeed = 9.0; - projectileCount = 7; - params.FireDirectionLimit.y = dirY; - params.DotProductLimit = 0.4; - params.FireDirectionLimit.x = dirX; - fVar2 = sin(((float)frame + (float)frame) / 30.0); - params.CircleAngle = fVar2 * 0.44879895 + local_c8.y + 0.44879895; - } - else if (pattern == 8) { - if (frame % 0xd != 0) { - return; - } - projectileSpeed = 9.0; - projectileCount = 8; - params.FireDirectionLimit.x = dirX; - params.FireDirectionLimit.y = dirY; - params.DotProductLimit = 0.0; - } - else { - if (pattern != 9) { - return; - } - if (frame % 10 != 0) { - return; - } - projectileCount = 3; - projectileSpeed = 9.0; - params.HomingStrength = 0.65; - params.CircleAngle = (((float)frame * -0.125) / 30.0) * 6.2831855; - } - } -LAB_00483620: - uVar1 = Random(); - manager = g_manager; - if (npc->_championColorIdx == 0x12) { - pitch = 1.5; - } - else if (npc->_championColorIdx == 0x13) { - pitch = 0.5; - } - local_c8.y = 1.62551e-43; - seed_fart_sound_override(GHIDRA_CAST(&local_c8.y)); - (GHIDRA_CAST((&manager->_sfxManager)))->SoundEffects::Play(GHIDRA_INT(local_c8.y),0.6,uVar1 % 0x1e + 0x14,0,pitch,0.0); - local_c8.x = projectileSpeed; - local_c8.y = (float)projectileCount; - Entity_NPC::FireProjectiles(npc,&npc->_pos,&local_c8,9,¶ms); - return; -} - // 00499a50 int * NpcHelper::chub_nearest_segment(int *param_1, int param_2) { diff --git a/generated-src/stubs.cpp b/generated-src/stubs.cpp index e5ec014..cb13f2b 100644 --- a/generated-src/stubs.cpp +++ b/generated-src/stubs.cpp @@ -9221,7 +9221,6 @@ void NetplayTextPopup::clear() { generated_stub("NetplayTextPopup::clear 0092388 void * NetworkManager::receive_message(void *outMessage, uint8_t channel, uint8_t isRemove) { generated_stub("NetworkManager::receive_message 00a78770"); } void NetworkManager::receive_packet(uint64_t *sender, void *buffer, int size) { generated_stub("NetworkManager::receive_packet 00a78a10"); } void * NetworkManager::get_peer(void *outPeer, uint64_t *userId) { generated_stub("NetworkManager::get_peer 00a790b0"); } -void NpcHelper::the_lamb_pattern(Entity_NPC *npc, int pattern, int frame) { generated_stub("NpcHelper::the_lamb_pattern 004830e0"); } int * NpcHelper::chub_nearest_segment(int *param_1, int param_2) { generated_stub("NpcHelper::chub_nearest_segment 00499a50"); } void NpcHelper::chimera_charge_begin(Entity_NPC *npc, Vector *target, float speed) { generated_stub("NpcHelper::chimera_charge_begin 0049f870"); } void NpcHelper::chimera_render_child(Entity_NPC *npc, Vector *offset) { generated_stub("NpcHelper::chimera_render_child 004a1000"); } @@ -9423,40 +9422,6 @@ uint8_t Weapon_Deathmatch::CanShutDoors() { generated_stub("Weapon_Deathmatch::C void Weapon_Deathmatch::vfunc_14() { generated_stub("Weapon_Deathmatch::vfunc_14 005ccc00"); } void Weapon_Deathmatch::vfunc_15() { generated_stub("Weapon_Deathmatch::vfunc_15 005ccc00"); } void Weapon_Deathmatch::vfunc_16() { generated_stub("Weapon_Deathmatch::vfunc_16 005ccc00"); } -Weapon_Fetus::~Weapon_Fetus() { generated_stub("Weapon_Fetus::~Weapon_Fetus 009f3260"); } -void Weapon_Fetus::Init(uint32_t param_2, uint32_t param_3) { generated_stub("Weapon_Fetus::Init 009f34d0"); } -void Weapon_Fetus::Update(char param_2) { generated_stub("Weapon_Fetus::Update 009f34f0"); } -void Weapon_Fetus::Fire(Vector *direction, uint8_t isShooting, uint8_t isInterpolated) { generated_stub("Weapon_Fetus::Fire 00a036e0"); } -void Weapon_Fetus::Reset() { generated_stub("Weapon_Fetus::Reset 009f3480"); } -void Weapon_Fetus::ClearReferences() { generated_stub("Weapon_Fetus::ClearReferences 009f3320"); } -float Weapon_Fetus::GetMaxCharge() { generated_stub("Weapon_Fetus::GetMaxCharge 00a03f60"); } -long double Weapon_Fetus::GetChargeBarAmount() { generated_stub("Weapon_Fetus::GetChargeBarAmount 009f4150"); } -void Weapon_Fetus::vfunc_8() { generated_stub("Weapon_Fetus::vfunc_8 009f3130"); } -uint32_t Weapon_Fetus::GetFocusEntity() { generated_stub("Weapon_Fetus::GetFocusEntity 009f3140"); } -void Weapon_Fetus::vfunc_10() { generated_stub("Weapon_Fetus::vfunc_10 009f3140"); } -void Weapon_Fetus::guard_check_icall() { generated_stub("Weapon_Fetus::guard_check_icall 0040c200"); } -int Weapon_Fetus::GetMarkedTargetVariant() { generated_stub("Weapon_Fetus::GetMarkedTargetVariant 009fa1b0"); } -uint8_t Weapon_Fetus::CanShutDoors() { generated_stub("Weapon_Fetus::CanShutDoors 005ccc00"); } -void Weapon_Fetus::vfunc_14() { generated_stub("Weapon_Fetus::vfunc_14 005ccc00"); } -uint8_t Weapon_Fetus::CanTakeDamageFromTearEffects() { generated_stub("Weapon_Fetus::CanTakeDamageFromTearEffects 00709c30"); } -void Weapon_Fetus::vfunc_16() { generated_stub("Weapon_Fetus::vfunc_16 005ccc00"); } -Weapon_Ludovico::~Weapon_Ludovico() { generated_stub("Weapon_Ludovico::~Weapon_Ludovico 009f9880"); } -void Weapon_Ludovico::Init(uint32_t param_2, uint32_t param_3) { generated_stub("Weapon_Ludovico::Init 009f34d0"); } -void Weapon_Ludovico::Update(char param_2) { generated_stub("Weapon_Ludovico::Update 009f34f0"); } -void Weapon_Ludovico::Fire(Vector *direction, uint8_t isShooting, uint8_t isInterpolated) { generated_stub("Weapon_Ludovico::Fire 00a06a30"); } -void Weapon_Ludovico::Reset() { generated_stub("Weapon_Ludovico::Reset 009f3480"); } -void Weapon_Ludovico::ClearReferences() { generated_stub("Weapon_Ludovico::ClearReferences 00a063b0"); } -long double Weapon_Ludovico::GetMaxCharge() { generated_stub("Weapon_Ludovico::GetMaxCharge 009f3130"); } -long double Weapon_Ludovico::GetChargeBarAmount() { generated_stub("Weapon_Ludovico::GetChargeBarAmount 009f4150"); } -void Weapon_Ludovico::vfunc_8() { generated_stub("Weapon_Ludovico::vfunc_8 009f3130"); } -Entity * Weapon_Ludovico::GetMainEntity() { generated_stub("Weapon_Ludovico::GetMainEntity 009f3150"); } -void Weapon_Ludovico::vfunc_10() { generated_stub("Weapon_Ludovico::vfunc_10 009f3150"); } -void Weapon_Ludovico::guard_check_icall() { generated_stub("Weapon_Ludovico::guard_check_icall 0040c200"); } -uint32_t Weapon_Ludovico::GetFocusEntity() { generated_stub("Weapon_Ludovico::GetFocusEntity 009f3140"); } -uint8_t Weapon_Ludovico::CanShutDoors() { generated_stub("Weapon_Ludovico::CanShutDoors 005ccc00"); } -void Weapon_Ludovico::vfunc_14() { generated_stub("Weapon_Ludovico::vfunc_14 005ccc00"); } -void Weapon_Ludovico::vfunc_15() { generated_stub("Weapon_Ludovico::vfunc_15 005ccc00"); } -void Weapon_Ludovico::vfunc_16() { generated_stub("Weapon_Ludovico::vfunc_16 005ccc00"); } Weapon_MonstrosLung::~Weapon_MonstrosLung() { generated_stub("Weapon_MonstrosLung::~Weapon_MonstrosLung 009f3260"); } void Weapon_MonstrosLung::Init(uint32_t param_2, uint32_t param_3) { generated_stub("Weapon_MonstrosLung::Init 009f34d0"); } void Weapon_MonstrosLung::Update(char param_2) { generated_stub("Weapon_MonstrosLung::Update 009f34f0"); } @@ -9475,23 +9440,6 @@ uint8_t Weapon_MonstrosLung::CanShutDoors() { generated_stub("Weapon_MonstrosLun uint8_t Weapon_MonstrosLung::CanTriggerKidneyStone() { generated_stub("Weapon_MonstrosLung::CanTriggerKidneyStone 005ccc00"); } uint8_t Weapon_MonstrosLung::CanOverrideForgottenThrow() { generated_stub("Weapon_MonstrosLung::CanOverrideForgottenThrow 005ccc00"); } void Weapon_MonstrosLung::FireBurst(uint32_t param_1, int param_2) { generated_stub("Weapon_MonstrosLung::FireBurst 00a08700"); } -Weapon_Rockets::~Weapon_Rockets() { generated_stub("Weapon_Rockets::~Weapon_Rockets 009f9880"); } -void Weapon_Rockets::Init(uint32_t param_2, uint32_t param_3) { generated_stub("Weapon_Rockets::Init 009f34d0"); } -void Weapon_Rockets::Update(char param_2) { generated_stub("Weapon_Rockets::Update 009f34f0"); } -void Weapon_Rockets::Fire(Vector *aimDirection, uint8_t isShooting, uint8_t isInterpolated) { generated_stub("Weapon_Rockets::Fire 00a08d40"); } -void Weapon_Rockets::Reset() { generated_stub("Weapon_Rockets::Reset 009f3480"); } -void Weapon_Rockets::ClearReferences() { generated_stub("Weapon_Rockets::ClearReferences 00a063b0"); } -long double Weapon_Rockets::GetMaxCharge() { generated_stub("Weapon_Rockets::GetMaxCharge 009f3130"); } -long double Weapon_Rockets::GetChargeBarAmount() { generated_stub("Weapon_Rockets::GetChargeBarAmount 009f4150"); } -void Weapon_Rockets::vfunc_8() { generated_stub("Weapon_Rockets::vfunc_8 009f3130"); } -Entity * Weapon_Rockets::GetMainEntity() { generated_stub("Weapon_Rockets::GetMainEntity 009f3150"); } -void Weapon_Rockets::vfunc_10() { generated_stub("Weapon_Rockets::vfunc_10 009f3150"); } -void Weapon_Rockets::guard_check_icall() { generated_stub("Weapon_Rockets::guard_check_icall 0040c200"); } -int Weapon_Rockets::GetMarkedTargetVariant() { generated_stub("Weapon_Rockets::GetMarkedTargetVariant 00a099a0"); } -uint8_t Weapon_Rockets::CanShutDoors() { generated_stub("Weapon_Rockets::CanShutDoors 005ccc00"); } -void Weapon_Rockets::vfunc_14() { generated_stub("Weapon_Rockets::vfunc_14 005ccc00"); } -void Weapon_Rockets::vfunc_15() { generated_stub("Weapon_Rockets::vfunc_15 005ccc00"); } -void Weapon_Rockets::vfunc_16() { generated_stub("Weapon_Rockets::vfunc_16 005ccc00"); } Weapon_SpiritSword::~Weapon_SpiritSword() { generated_stub("Weapon_SpiritSword::~Weapon_SpiritSword 009f9930"); } void Weapon_SpiritSword::Init(uint32_t param_2, uint32_t param_3) { generated_stub("Weapon_SpiritSword::Init 009f34d0"); } void Weapon_SpiritSword::Update(char param_2) { generated_stub("Weapon_SpiritSword::Update 009f34f0"); } @@ -10064,15 +10012,12 @@ bool FUN_004567d0() { generated_stub("FUN_004567d0 004567d0"); } void FUN_00456820() { generated_stub("FUN_00456820 00456820"); } void FUN_00456830(uint32_t param_1, uint32_t param_2, uint32_t param_3, uint32_t param_4) { generated_stub("FUN_00456830 00456830"); } int FUN_00456880() { generated_stub("FUN_00456880 00456880"); } -void NpcAI::ENTITY_FLY_isaac_spawned(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_FLY_isaac_spawned 004568d0"); } void NpcAI::ENTITY_WAR(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_WAR 00458870"); } void NpcAI::ENTITY_DEATH(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_DEATH 00459d20"); } void NpcAI::ENTITY_HEADLESS_HORSEMAN(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_HEADLESS_HORSEMAN 0045cd60"); } void NpcAI::ENTITY_DARK_ONE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_DARK_ONE 0045d7d0"); } -float NpcAI::ENTITY_ISAAC(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_ISAAC 00463100"); } void NpcAI::ENTITY_PIN(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_PIN 00476860"); } void FUN_00479d50(uint32_t *param_1) { generated_stub("FUN_00479d50 00479d50"); } -void NpcAI::ENTITY_THE_LAMB(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_THE_LAMB 00483710"); } void NpcAI::ENTITY_BROWNIE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BROWNIE 0048c3b0"); } void NpcAI::ENTITY_CORN_MINE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_CORN_MINE 0048ee30"); } void NpcAI::ENTITY_FORSAKEN(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_FORSAKEN 0048f110"); } @@ -10142,10 +10087,8 @@ uint32_t FUN_004bc660() { generated_stub("FUN_004bc660 004bc660"); } Entity * FUN_004bcb30(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_004bcb30 004bcb30"); } void NpcAI::ENTITY_HORNY_BOYS(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_HORNY_BOYS 004bd2a0"); } void NpcAI::ENTITY_HUSH_BOIL(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_HUSH_BOIL 004be6f0"); } -void NpcAI::ENTITY_HUSH_GAPER(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_HUSH_GAPER 004bee40"); } void NpcAI::ENTITY_HUSH_FLY(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_HUSH_FLY 004bf310"); } void FUN_004bfd20() { generated_stub("FUN_004bfd20 004bfd20"); } -void NpcAI::ENTITY_HUSH(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_HUSH 004bfd30"); } void FUN_004c5850(uint8_t *param_1) { generated_stub("FUN_004c5850 004c5850"); } void FUN_004c5980(float *param_1, Vector *param_2) { generated_stub("FUN_004c5980 004c5980"); } void NpcAI::ENTITY_MATRIARCH(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_MATRIARCH 004c59d0"); } @@ -10212,12 +10155,10 @@ uint8_t str_ne(std_string *a, uint8_t *b) { generated_stub("str_ne 004f84a0"); } void rng_pair_init(void *self) { generated_stub("rng_pair_init 004f88a0"); } uint32_t FUN_004f88e0() { generated_stub("FUN_004f88e0 004f88e0"); } uint32_t FUN_004f8930() { generated_stub("FUN_004f8930 004f8930"); } -void NpcAI::ENTITY_ROCK_SPIDER(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_ROCK_SPIDER 004f9ad0"); } void NpcAI::ENTITY_FACELESS(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_FACELESS 004faad0"); } void NpcAI::ENTITY_DANNY(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_DANNY 004fbd10"); } void NpcAI::ENTITY_MOLE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_MOLE 004fdf80"); } void NpcAI::ENTITY_GYRO(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_GYRO 004ff620"); } -void NpcAI::ENTITY_FIRE_WORM(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_FIRE_WORM 00500990"); } void NpcAI::ENTITY_BOUNCER(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BOUNCER 00501f30"); } void NpcAI::ENTITY_FLESH_MAIDEN(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_FLESH_MAIDEN 00502980"); } void NpcAI::ENTITY_BOMBGAGGER(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BOMBGAGGER 00503300"); } @@ -10232,18 +10173,10 @@ uint32_t * FUN_00505ce0() { generated_stub("FUN_00505ce0 00505ce0"); } void NpcAI::ENTITY_STONE_EYE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_STONE_EYE 00505d00"); } void NpcAI::ENTITY_KNIGHT(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_KNIGHT 005135d0"); } long double FUN_00515290(Vector *param_1, uint32_t param_2, int param_3) { generated_stub("FUN_00515290 00515290"); } -void NpcAI::ENTITY_MRMAW(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_MRMAW 00517de0"); } void NpcAI::ENTITY_SWARMER(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_SWARMER 00518e20"); } -void NpcAI::ENTITY_HANGER(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_HANGER 0051cb30"); } void NpcAI::ENTITY_URIEL(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_URIEL 0051e0f0"); } void NpcAI::ENTITY_HEART(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_HEART 0051f2f0"); } -void NpcAI::ENTITY_POKY(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_POKY 00521ab0"); } void NpcAI::ENTITY_DOPLE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_DOPLE 00525650"); } -void NpcAI::ENTITY_BABY(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BABY 0052ae30"); } -void NpcAI::ENTITY_COD_WORM(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_COD_WORM 00531350"); } -void NpcAI::ENTITY_MOBILE_HOST(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_MOBILE_HOST 005321d0"); } -void NpcAI::ENTITY_MOMS_HAND(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_MOMS_HAND 00533b80"); } -void NpcAI::ENTITY_WIZOOB(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_WIZOOB 005374a0"); } void NpcAI::ENTITY_HOMUNCULUS(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_HOMUNCULUS 00539b90"); } void NpcAI::ENTITY_OOB(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_OOB 0053ab40"); } void NpcAI::ENTITY_BLACK_MAW(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BLACK_MAW 0053b2f0"); } @@ -10261,7 +10194,6 @@ void NpcAI::ENTITY_COHORT(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_COHOR void NpcAI::ENTITY_GENERIC_PROP(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_GENERIC_PROP 00551d30"); } void NpcAI::ENTITY_SHADY(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_SHADY 005522d0"); } void NpcAI::ENTITY_BLOOD_PUPPY(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BLOOD_PUPPY 00552d30"); } -void NpcAI::ENTITY_DARK_ESAU(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_DARK_ESAU 005542e0"); } void NpcAI::ENTITY_PEEPER_FATTY(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_PEEPER_FATTY 005562b0"); } void FUN_005579b0(Vector *param_1) { generated_stub("FUN_005579b0 005579b0"); } void FUN_00557b50(uint32_t param_1) { generated_stub("FUN_00557b50 00557b50"); } @@ -10273,8 +10205,6 @@ int NpcAI::ENTITY_WILLO_L2_find_target(Entity_NPC *npc) { generated_stub("NpcAI: void NpcAI::ENTITY_WILLO_L2(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_WILLO_L2 005593c0"); } Entity_Projectile * NpcAI::ENTITY_BUBBLES(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BUBBLES 0055ad20"); } void NpcAI::ENTITY_SMALL_LEECH(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_SMALL_LEECH 0055b740"); } -uint32_t FUN_0055c6a0(float *param_1) { generated_stub("FUN_0055c6a0 0055c6a0"); } -void NpcAI::ENTITY_STRIDER(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_STRIDER 0055c810"); } uint32_t NpcAI::ENTITY_POLTY(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_POLTY 0055d230"); } void NpcAI::ENTITY_FLY_TRAP(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_FLY_TRAP 00560ca0"); } void NpcAI::ENTITY_FLY_orbit_parent(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_FLY_orbit_parent 00561580"); } @@ -10351,7 +10281,6 @@ void NpcAI::ENTITY_BEAST_rock_projectile(Entity_NPC *npc) { generated_stub("NpcA void NpcAI::ENTITY_BEAST_soul(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BEAST_soul 005971e0"); } void FUN_00598260(Vector *param_1) { generated_stub("FUN_00598260 00598260"); } uint32_t * FUN_00598290(uint32_t *param_1, uint32_t *param_2) { generated_stub("FUN_00598290 00598290"); } -void NpcAI::ENTITY_POLYCEPHALUS_the_pile(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_POLYCEPHALUS_the_pile 005983f0"); } void NpcAI::ENTITY_TUFF_TWINS_head_anim(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_TUFF_TWINS_head_anim 00599b80"); } void NpcAI::ENTITY_TUFF_TWINS_body_anim(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_TUFF_TWINS_body_anim 00599d70"); } void FUN_0059a200() { generated_stub("FUN_0059a200 0059a200"); } @@ -10361,7 +10290,6 @@ void NpcAI::ENTITY_TURDLET(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_TURD void NpcAI::ENTITY_ULTRA_GREED(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_ULTRA_GREED 0059edb0"); } void NpcAI::ENTITY_ULTRA_COIN(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_ULTRA_COIN 005a4820"); } void NpcAI::ENTITY_ULTRA_DOOR(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_ULTRA_DOOR 005a5b60"); } -void NpcAI::ENTITY_GREED_GAPER(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_GREED_GAPER 005a6b80"); } void FUN_005a6fb0() { generated_stub("FUN_005a6fb0 005a6fb0"); } uint8_t FUN_005a7570() { generated_stub("FUN_005a7570 005a7570"); } void NpcAI::ENTITY_VISAGE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_VISAGE 005a7b20"); } @@ -10417,8 +10345,6 @@ void FUN_005b19f0(uint32_t param_1) { generated_stub("FUN_005b19f0 005b19f0"); } uint8_t FUN_005b1a00() { generated_stub("FUN_005b1a00 005b1a00"); } bool FUN_005b1a10() { generated_stub("FUN_005b1a10 005b1a10"); } void alabaster_box_timer_callback(Entity *timer) { generated_stub("alabaster_box_timer_callback 005b30b0"); } -void Isaac::SpawnLocust(Entity_Player *player, int collectibleType, Vector *pos) { generated_stub("Isaac::SpawnLocust 005b35c0"); } -uint32_t FUN_005b3990(uint32_t *param_1) { generated_stub("FUN_005b3990 005b3990"); } void FUN_005c7ad0(int param_1) { generated_stub("FUN_005c7ad0 005c7ad0"); } void FUN_005c7bf0(int *param_1, int *param_2) { generated_stub("FUN_005c7bf0 005c7bf0"); } void FUN_005c7d30(int param_1) { generated_stub("FUN_005c7d30 005c7d30"); } @@ -10562,7 +10488,6 @@ void FUN_0060d400() { generated_stub("FUN_0060d400 0060d400"); } void FUN_0060d530(uint8_t param_1) { generated_stub("FUN_0060d530 0060d530"); } void FUN_0060d5e0(uint8_t param_1) { generated_stub("FUN_0060d5e0 0060d5e0"); } uint32_t FUN_0060dae0() { generated_stub("FUN_0060dae0 0060dae0"); } -void * FamiliarAI::blue_spider(Entity_Familiar *familiar) { generated_stub("FamiliarAI::blue_spider 00616050"); } void FamiliarAI::bobs_brain(Entity_Familiar *familiar) { generated_stub("FamiliarAI::bobs_brain 00616770"); } void FamiliarAI::gb_bug(Entity_Familiar *familiar) { generated_stub("FamiliarAI::gb_bug 00618b00"); } void FamiliarAI::variant_53(Entity_Familiar *familiar) { generated_stub("FamiliarAI::variant_53 006196e0"); } @@ -10580,7 +10505,6 @@ void FamiliarAI::sprinkler(Entity_Familiar *familiar) { generated_stub("Familiar void FamiliarAI::mystery_egg(Entity_Familiar *familiar) { generated_stub("FamiliarAI::mystery_egg 00638170"); } void FamiliarAI::lil_spewer(Entity_Familiar *familiar) { generated_stub("FamiliarAI::lil_spewer 006384a0"); } void FUN_00638e20() { generated_stub("FUN_00638e20 00638e20"); } -void spawn_blue_spider(Vector *position, Entity *spawner, Vector *target) { generated_stub("spawn_blue_spider 00638e30"); } void FUN_006395e0(Vector *param_1, int *param_2, int param_3, int param_4, int param_5, float param_6, int param_7, int param_8, Entity *param_9, int param_10) { generated_stub("FUN_006395e0 006395e0"); } Entity_Laser * FamiliarHelper::sprinkler_fire_laser(Entity_Familiar *familiar, float angle, float distance) { generated_stub("FamiliarHelper::sprinkler_fire_laser 0063acf0"); } Entity_Knife * FamiliarAI::sprinkler_spawn_knife(Entity_Familiar *familiar) { generated_stub("FamiliarAI::sprinkler_spawn_knife 0063b070"); } @@ -10938,7 +10862,6 @@ void FUN_007098c0() { generated_stub("FUN_007098c0 007098c0"); } void FUN_00709930() { generated_stub("FUN_00709930 00709930"); } int FUN_00709bc0() { generated_stub("FUN_00709bc0 00709bc0"); } uint8_t FUN_0070bf60() { generated_stub("FUN_0070bf60 0070bf60"); } -uint8_t is_grid_type_floor_special(int gridType) { generated_stub("is_grid_type_floor_special 0070bf80"); } void FUN_0070bfa0(int param_1, int param_2, uint32_t param_3, float param_4) { generated_stub("FUN_0070bfa0 0070bfa0"); } void FUN_0070c570(uint32_t *param_1) { generated_stub("FUN_0070c570 0070c570"); } uint32_t FUN_00710370() { generated_stub("FUN_00710370 00710370"); } @@ -11050,7 +10973,6 @@ void FUN_00753620() { generated_stub("FUN_00753620 00753620"); } bool FUN_00753630() { generated_stub("FUN_00753630 00753630"); } bool FUN_00753640() { generated_stub("FUN_00753640 00753640"); } void FUN_00753650() { generated_stub("FUN_00753650 00753650"); } -void FUN_00753660(uint32_t *param_1, uint32_t param_2) { generated_stub("FUN_00753660 00753660"); } uint32_t FUN_00753700() { generated_stub("FUN_00753700 00753700"); } uint32_t FUN_00753710() { generated_stub("FUN_00753710 00753710"); } void FUN_00753720() { generated_stub("FUN_00753720 00753720"); } @@ -11110,9 +11032,7 @@ void FUN_007cf940() { generated_stub("FUN_007cf940 007cf940"); } long double FUN_007cf9a0(float *param_1, KColor *param_2, uint32_t param_3) { generated_stub("FUN_007cf9a0 007cf9a0"); } uint8_t * FUN_007cfa90() { generated_stub("FUN_007cfa90 007cfa90"); } void FUN_007d3330(int param_1) { generated_stub("FUN_007d3330 007d3330"); } -Game * damage_charge_scale() { generated_stub("damage_charge_scale 007d3560"); } void FUN_007d3e00() { generated_stub("FUN_007d3e00 007d3e00"); } -char FUN_007d4320() { generated_stub("FUN_007d4320 007d4320"); } void FUN_007d9360() { generated_stub("FUN_007d9360 007d9360"); } uint32_t FUN_007d9ca0() { generated_stub("FUN_007d9ca0 007d9ca0"); } uint32_t FUN_007da770() { generated_stub("FUN_007da770 007da770"); } @@ -11289,7 +11209,6 @@ void render_beast_arena_background(void *self, int pass) { generated_stub("rende void FUN_0083aae0(uint8_t param_1, int *param_2, uint32_t *param_3) { generated_stub("FUN_0083aae0 0083aae0"); } void FUN_0083b830() { generated_stub("FUN_0083b830 0083b830"); } int FUN_0083bbc0(int param_1) { generated_stub("FUN_0083bbc0 0083bbc0"); } -void FUN_0083bed0(int param_1, int param_2) { generated_stub("FUN_0083bed0 0083bed0"); } void FUN_0083bf50() { generated_stub("FUN_0083bf50 0083bf50"); } void FUN_0083bf90(uint32_t *param_1) { generated_stub("FUN_0083bf90 0083bf90"); } void Catch_All_0083c241() { generated_stub("Catch_All_0083c241 0083c241"); } @@ -13693,15 +13612,11 @@ void FUN_009f3c40() { generated_stub("FUN_009f3c40 009f3c40"); } void FUN_009f4130() { generated_stub("FUN_009f4130 009f4130"); } Entity_Player * FUN_009f4fc0() { generated_stub("FUN_009f4fc0 009f4fc0"); } void FUN_009f5810(uint8_t param_1) { generated_stub("FUN_009f5810 009f5810"); } -Entity_Tear * fire_fetus_tear(void *self, Vector *position, Vector *velocity, int fireFlags, Entity *source, float damageMultiplier, int unused) { generated_stub("fire_fetus_tear 009f6e60"); } uint32_t * FUN_009f9080() { generated_stub("FUN_009f9080 009f9080"); } uint32_t * FUN_009f90f0() { generated_stub("FUN_009f90f0 009f90f0"); } uint32_t * FUN_009f9170() { generated_stub("FUN_009f9170 009f9170"); } uint32_t * FUN_009f92d0() { generated_stub("FUN_009f92d0 009f92d0"); } -uint32_t * FUN_009f9350() { generated_stub("FUN_009f9350 009f9350"); } uint32_t * FUN_009f93d0() { generated_stub("FUN_009f93d0 009f93d0"); } -uint32_t * FUN_009f9440() { generated_stub("FUN_009f9440 009f9440"); } -uint32_t * FUN_009f95d0() { generated_stub("FUN_009f95d0 009f95d0"); } uint32_t * FUN_00a06940(void *param_1, uint32_t *param_2) { generated_stub("FUN_00a06940 00a06940"); } void * operator_new(uint32_t size) { generated_stub("operator_new 00a0f4c0"); } void * operator_new_tracked(uint32_t size) { generated_stub("operator_new_tracked 00a0f4e0"); } @@ -17350,7 +17265,6 @@ void FUN_00a627d0() { generated_stub("FUN_00a627d0 00a627d0"); } void FUN_00a62800(uint8_t param_1) { generated_stub("FUN_00a62800 00a62800"); } void FUN_00a62830(uint32_t param_1, uint32_t param_2, uint32_t param_3, uint32_t param_4) { generated_stub("FUN_00a62830 00a62830"); } uint8_t FUN_00a62870() { generated_stub("FUN_00a62870 00a62870"); } -uint32_t FUN_00a62910(uint8_t *param_1) { generated_stub("FUN_00a62910 00a62910"); } uint32_t FUN_00a62a10() { generated_stub("FUN_00a62a10 00a62a10"); } char * FUN_00a62dc0() { generated_stub("FUN_00a62dc0 00a62dc0"); } char * string_duplicate_lower() { generated_stub("string_duplicate_lower 00a62e10"); } @@ -17768,11 +17682,9 @@ char * FUN_00a8a070(char *param_1) { generated_stub("FUN_00a8a070 00a8a070"); } void TheoraVideoManager::TheoraVideoManager() { generated_stub("TheoraVideoManager::TheoraVideoManager 00a8a090"); } void FUN_00a8a810(uint8_t param_1) { generated_stub("FUN_00a8a810 00a8a810"); } void FUN_00a8a970() { generated_stub("FUN_00a8a970 00a8a970"); } -int * theora_create_video_clip(uint32_t param_1, int *param_2) { generated_stub("theora_create_video_clip 00a8ab60"); } void Catch_00a8b0f1() { generated_stub("Catch_00a8b0f1 00a8b0f1"); } void FUN_00a8b130(int param_1) { generated_stub("FUN_00a8b130 00a8b130"); } void FUN_00a8b160(uint8_t param_1) { generated_stub("FUN_00a8b160 00a8b160"); } -void TheoraVideoManager::destroyVideoClip(void *clip) { generated_stub("TheoraVideoManager::destroyVideoClip 00a8b190"); } void TheoraVideoManager::createWorkerThreads(int param_1) { generated_stub("TheoraVideoManager::createWorkerThreads 00a8b570"); } int TheoraVideoManager::requestWork(uint32_t param_1) { generated_stub("TheoraVideoManager::requestWork 00a8b7d0"); } void FUN_00a8bbd0(uint8_t param_1) { generated_stub("FUN_00a8bbd0 00a8bbd0"); } @@ -17803,7 +17715,6 @@ void FUN_00a8d950() { generated_stub("FUN_00a8d950 00a8d950"); } void VideoClip_Theora::_executeSeek() { generated_stub("VideoClip_Theora::_executeSeek 00a8da40"); } void FUN_00a8e050() { generated_stub("FUN_00a8e050 00a8e050"); } uint32_t VideoClip_Theora::_seekPage(int param_1, char param_2) { generated_stub("VideoClip_Theora::_seekPage 00a8e1b0"); } -void VideoClip_Theora::readTheoraVorbisHeaders() { generated_stub("VideoClip_Theora::readTheoraVorbisHeaders 00a8e530"); } void wgl_provider_resolver(int param_1) { generated_stub("wgl_provider_resolver 00a8ecc0"); } void FUN_00a8f390() { generated_stub("FUN_00a8f390 00a8f390"); } void FUN_00a8f3c0(uint32_t param_1, uint32_t param_2, uint32_t param_3, uint32_t param_4) { generated_stub("FUN_00a8f3c0 00a8f3c0"); } @@ -18122,13 +18033,9 @@ void FUN_00aa9a20(int param_1) { generated_stub("FUN_00aa9a20 00aa9a20"); } void FUN_00aa9a70(int param_1) { generated_stub("FUN_00aa9a70 00aa9a70"); } void FUN_00aa9ab0(int param_1) { generated_stub("FUN_00aa9ab0 00aa9ab0"); } void FUN_00aa9bb0() { generated_stub("FUN_00aa9bb0 00aa9bb0"); } -void vorbis_info_clear(void *info) { generated_stub("vorbis_info_clear 00aa9c20"); } uint32_t _vorbis_unpack_books() { generated_stub("_vorbis_unpack_books 00aa9e80"); } -uint32_t vorbis_synthesis_headerin(int param_1) { generated_stub("vorbis_synthesis_headerin 00aaa150"); } -int FUN_00aaa450() { generated_stub("FUN_00aaa450 00aaa450"); } int FUN_00aaa4a0() { generated_stub("FUN_00aaa4a0 00aaa4a0"); } void FUN_00aaaa90() { generated_stub("FUN_00aaaa90 00aaaa90"); } -void FUN_00aaaae0(int param_1) { generated_stub("FUN_00aaaae0 00aaaae0"); } uint32_t FUN_00aaabb0() { generated_stub("FUN_00aaabb0 00aaabb0"); } void FUN_00aaac20() { generated_stub("FUN_00aaac20 00aaac20"); } void FUN_00aaace0(uint8_t param_1) { generated_stub("FUN_00aaace0 00aaace0"); } @@ -18157,23 +18064,13 @@ void FUN_00aabd90(int *param_1, char param_2) { generated_stub("FUN_00aabd90 00a void FUN_00aabe70(int *param_1, char param_2) { generated_stub("FUN_00aabe70 00aabe70"); } uint32_t FUN_00aabeb0() { generated_stub("FUN_00aabeb0 00aabeb0"); } uint32_t FUN_00aabec0() { generated_stub("FUN_00aabec0 00aabec0"); } -int64_t ogg_page_granulepos(void *page) { generated_stub("ogg_page_granulepos 00aabed0"); } uint32_t FUN_00aabf60() { generated_stub("FUN_00aabf60 00aabf60"); } uint32_t FUN_00aabfb0() { generated_stub("FUN_00aabfb0 00aabfb0"); } uint32_t FUN_00aac040() { generated_stub("FUN_00aac040 00aac040"); } -void ogg_page_checksum_set() { generated_stub("ogg_page_checksum_set 00aac110"); } int FUN_00aac1a0() { generated_stub("FUN_00aac1a0 00aac1a0"); } -int ogg_sync_pageseek() { generated_stub("ogg_sync_pageseek 00aac240"); } -int ogg_sync_pageout(void *syncState, void *page) { generated_stub("ogg_sync_pageout 00aac3e0"); } -uint32_t ogg_stream_pagein() { generated_stub("ogg_stream_pagein 00aac5c0"); } -uint32_t ogg_stream_reset() { generated_stub("ogg_stream_reset 00aac8f0"); } -int ogg_stream_packetout(void *streamState, void *packet) { generated_stub("ogg_stream_packetout 00aac980"); } int FUN_00aaca80() { generated_stub("FUN_00aaca80 00aaca80"); } void FUN_00aacae0() { generated_stub("FUN_00aacae0 00aacae0"); } uint32_t _vds_shared_init() { generated_stub("_vds_shared_init 00aacb50"); } -void vorbis_dsp_clear(void *dspState) { generated_stub("vorbis_dsp_clear 00aacf20"); } -uint32_t vorbis_synthesis_restart() { generated_stub("vorbis_synthesis_restart 00aad330"); } -uint32_t vorbis_synthesis_blockin() { generated_stub("vorbis_synthesis_blockin 00aad3b0"); } uint32_t FUN_00aada30() { generated_stub("FUN_00aada30 00aada30"); } void FUN_00aadbf0(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_00aadbf0 00aadbf0"); } void AudioPacketQueue::destroyAllAudioPackets() { generated_stub("AudioPacketQueue::destroyAllAudioPackets 00aadc80"); } @@ -18269,7 +18166,6 @@ int I420ToRGBAMatrix(uint8_t *srcY, int srcStrideY, uint8_t *srcU, int srcStride uint32_t FUN_00ab6bc0(int param_1, int param_2, int param_3, int param_4, int param_5, int param_6, uint32_t param_7, uint32_t param_8, int param_9) { generated_stub("FUN_00ab6bc0 00ab6bc0"); } uint32_t FUN_00ab6d00(int param_1, int param_2, int param_3, int param_4, int param_5, int param_6, uint32_t param_7, uint32_t param_8, int param_9) { generated_stub("FUN_00ab6d00 00ab6d00"); } void FUN_00ab6e40() { generated_stub("FUN_00ab6e40 00ab6e40"); } -void oggpack_write(void *buffer, uint32_t value, int bits) { generated_stub("oggpack_write 00ab6ee0"); } uint32_t FUN_00ab7010() { generated_stub("FUN_00ab7010 00ab7010"); } void FUN_00ab70d0() { generated_stub("FUN_00ab70d0 00ab70d0"); } uint32_t FUN_00ab7120() { generated_stub("FUN_00ab7120 00ab7120"); } @@ -18586,10 +18482,7 @@ uint32_t oc_dec_postprocess_init(int param_1) { generated_stub("oc_dec_postproce void oc_dering_block(uint8_t *param_1, uint32_t param_2, uint32_t param_3, int *param_4, int param_5, uint8_t *param_6) { generated_stub("oc_dering_block 00addab0"); } void oc_filter_hedge(uint8_t *param_1, int param_2, int param_3, int param_4, int param_5, int param_6, int *param_7, int *param_8) { generated_stub("oc_filter_hedge 00ade460"); } void oc_filter_vedge(int param_1, int param_2, int param_3, int param_4, int *param_5) { generated_stub("oc_filter_vedge 00ade750"); } -void * th_decode_alloc(void *info, void *setup) { generated_stub("th_decode_alloc 00ade980"); } -uint32_t th_decode_ctl(int param_1, uint32_t param_2, uint32_t *param_3, int param_4) { generated_stub("th_decode_ctl 00ade9f0"); } void FUN_00adeb70(int param_1) { generated_stub("FUN_00adeb70 00adeb70"); } -uint32_t th_decode_packetin(int *param_1, uint32_t *param_2, int64_t *param_3) { generated_stub("th_decode_packetin 00adebd0"); } uint32_t FUN_00adf8c0(int param_1, void *param_2) { generated_stub("FUN_00adf8c0 00adf8c0"); } void FUN_00adf8f0(int *param_1) { generated_stub("FUN_00adf8f0 00adf8f0"); } void FUN_00adf940(uint32_t *param_1) { generated_stub("FUN_00adf940 00adf940"); } @@ -18624,7 +18517,6 @@ uint32_t oc_state_frarray_init(int param_1) { generated_stub("oc_state_frarray_i uint32_t FUN_00ae1900(int param_1, int *param_2, int param_3, short param_4) { generated_stub("FUN_00ae1900 00ae1900"); } int FUN_00ae19b0(uint32_t *param_1, uint8_t *param_2, uint32_t param_3) { generated_stub("FUN_00ae19b0 00ae19b0"); } uint32_t oc_state_ref_bufs_init(int param_1, int *param_2) { generated_stub("oc_state_ref_bufs_init 00ae1cf0"); } -int64_t th_granule_frame(void *decoder, int64_t granulePosition) { generated_stub("th_granule_frame 00ae2060"); } long double FUN_00ae2110(int param_1, int64_t param_2) { generated_stub("FUN_00ae2110 00ae2110"); } void oc_dequant_tables_init(int param_1, int param_2, int param_3) { generated_stub("oc_dequant_tables_init 00ae2200"); } int FUN_00ae2580(int *param_1) { generated_stub("FUN_00ae2580 00ae2580"); } diff --git a/generated-src/weapon_fetus.cpp b/generated-src/weapon_fetus.cpp deleted file mode 100644 index 6912092..0000000 --- a/generated-src/weapon_fetus.cpp +++ /dev/null @@ -1,413 +0,0 @@ -#include "classes.h" - -// 00a036e0 -void Weapon_Fetus::Fire(Vector *direction, uint8_t isShooting, uint8_t isInterpolated) -{ - void *player = this; - Entity *source; - Vector shotDirection; - uint8_t bVar1; - uint32_t uVar2; - Entity_Player *owner; - int ownerPlayer; - float *pfVar3; - ANM2 *pAVar4; - Vector *pVVar5; - Entity_Tear *tear; - uint8_t *animName; - Vector *newAimDirection; - Entity_Player *player; - int extraout_ECX; - int unusedArg; - int extraout_ECX_00; - ANM2 *this_00; - ANM2 *extraout_ECX_01; - void *pvVar6; - ANM2 *extraout_ECX_02; - int unusedCollectibleId; - int extraout_ECX_03; - ANM2 *extraout_ECX_04; - int extraout_ECX_05; - int extraout_ECX_06; - Entity_Player *ownerAsPlayer; - long double fVar7; - float fVar8; - uint8_t *puVar9; - int iVar10; - short multiShotParams [2]; - float fStack_a0; - float fStack_9c; - float fStack_98; - float fStack_94; - int iStack_90; - float fStack_8c; - char isShootingBackwards; - char isShootingSideways; - uint32_t uStack_88; - uint32_t numRandomDirTears; - Weapon *weapon; - float spreadAngle; - Vector scratchVec; - Vector local_70; - Vector firePos; - Vector aimDirection; - Vector local_58; - Vector *directionLocal; - float local_4c; - char isMarked; - float local_44; - float local_40; - uint64_t subAnimName; - float local_34; - float local_30; - Vector local_2c; - uint32_t local_24; - uint8_t *puStack_20; - void *local_1c; - uint8_t *puStack_18; - uint32_t local_14; - - puStack_20 = GHIDRA_CAST((GHIDRA_INT(register0x00000010) + -4)); - local_14 = (void *)0xffffffff; - puStack_18 = &LAB_00b107dd; - local_1c = ExceptionList; - uVar2 = __security_cookie ^ GHIDRA_INT(register0x00000010) - 0x10U; - ExceptionList = &local_1c; - directionLocal = direction; - weapon = player; - local_24 = uVar2; - Weapon::Fire(player,direction,isShooting,isInterpolated); - owner = *GHIDRA_CAST((GHIDRA_CAST(player) + 4)); - ownerAsPlayer = owner; - if (owner == GHIDRA_CAST(0x0)) { -LAB_00a03762: - player = GHIDRA_CAST(0x0); - if ((owner == GHIDRA_CAST(0x0)) || (owner->_type != 1)) { -LAB_00a03770: - if ((owner == GHIDRA_CAST(0x0)) || - ((ownerAsPlayer = GHIDRA_CAST(0x0), owner->_type != 1 && - ((owner->_type != 3 || - (owner = *GHIDRA_CAST(&owner->_isControlsEnabled), owner == GHIDRA_CAST(0x0))))) - )) { - local_70.y = 1.0; - ownerAsPlayer = GHIDRA_CAST(0x0); - goto LAB_00a037a2; - } - } - local_70.y = owner->_shotspeed; - } - else { - if (owner->_type != 1) { - if (owner->_type != 3) goto LAB_00a03762; - player = *GHIDRA_CAST(&owner->_isControlsEnabled); - goto LAB_00a03770; - } - local_70.y = owner->_shotspeed; - player = owner; - } -LAB_00a037a2: - local_70.y = local_70.y * 1.25; - if (player == GHIDRA_CAST(0x0)) { -LAB_00a037c7: - isMarked = '\0'; - } - else { - bVar1 = Entity_Player::HasCollectible(player,0x18a,0); - isMarked = '\x01'; - if (bVar1 == 0) goto LAB_00a037c7; - } - local_40 = (float)(*GHIDRA_CAST((GHIDRA_CAST(player) + 0x34)) >> 7 & 0xffffff01); - fVar7 = (long double)(**(code **)(*GHIDRA_CAST(player) + 0x18))(uVar2); - iVar10 = *GHIDRA_CAST((GHIDRA_CAST(player) + 4)); - fVar8 = (float)fVar7; - local_44 = fVar8; - if (iVar10 == 0) { -LAB_00a0382d: - firePos.x = *GHIDRA_CAST((GHIDRA_CAST(player) + 0x28)); - firePos.y = *GHIDRA_CAST((GHIDRA_CAST(player) + 0x2c)); - } - else { - if (*GHIDRA_CAST((iVar10 + 0x28)) == 1) { - ownerPlayer = iVar10; - } - else if ((*GHIDRA_CAST((iVar10 + 0x28)) != 3) || - (ownerPlayer = *GHIDRA_CAST((iVar10 + 0x410)), ownerPlayer == 0)) goto LAB_00a0382d; - ownerPlayer = *GHIDRA_CAST((ownerPlayer + 0x140c)); - if ((ownerPlayer == 0) || (isMarked == '\0')) goto LAB_00a0382d; - firePos.x = *GHIDRA_CAST((ownerPlayer + 0x33c)); - firePos.y = *GHIDRA_CAST((ownerPlayer + 0x340)); - } - bVar1 = (firePos.x == g_vectorZero.x) << 6 | (NAN(firePos.x) || NAN(g_vectorZero.x)) << 2 | 2U | - firePos.x < g_vectorZero.x; - if (firePos.x == g_vectorZero.x) { - bVar1 = (firePos.y == g_vectorZero.y) << 6 | (NAN(firePos.y) || NAN(g_vectorZero.y)) << 2 | 2U | - firePos.y < g_vectorZero.y; - } - local_4c = (float)CONCAT31(CONCAT21((short)(GHIDRA_UINT(&firePos) >> 0x10),bVar1),isShooting); - if (((iVar10 != 0) && (*GHIDRA_CAST((iVar10 + 0x28)) == 1)) && (0 < *GHIDRA_CAST((iVar10 + 0x18f8)))) { - local_40 = 1.0; - pfVar3 = &local_40; - if (1.0 <= fVar8) { - pfVar3 = &local_44; - } - fVar8 = *pfVar3; - } - if ((-1000.0 < fVar8) && - (local_4c = (float)GHIDRA_UINT(isShooting), fVar8 <= *GHIDRA_CAST((GHIDRA_CAST(player) + 0x14)))) { - local_4c = 0.0; - } - aimDirection.x = *GHIDRA_CAST((GHIDRA_CAST(player) + 0x20)); - aimDirection.y = *GHIDRA_CAST((GHIDRA_CAST(player) + 0x24)); - bVar1 = Weapon::IsAxisAligned(player); - if (bVar1 == 0) { - fVar8 = sqrtf(aimDirection.y * aimDirection.y + aimDirection.x * aimDirection.x); - iVar10 = extraout_ECX_00; - if (0.0 < fVar8) { - aimDirection.x = (1.0 / fVar8) * aimDirection.x; - aimDirection.y = (float)(aimDirection.y * (1.0 / fVar8)); - } - } - else { - puVar9 = GHIDRA_CAST(0x0); - if (ABS(aimDirection.x) <= ABS(aimDirection.y)) { - aimDirection.x = 0.0; - if (0.0 <= aimDirection.y) { - puVar9 = GHIDRA_CAST(0x3f800000); - } - else { - puVar9 = &DAT_bf800000; - } - } - else if (0.0 <= aimDirection.x) { - aimDirection.x = 1.0; - } - else { - aimDirection.x = (float)&DAT_bf800000; - } - iVar10 = extraout_ECX; - aimDirection.y = (float)puVar9; - } - fVar8 = 1.0; - if ((*GHIDRA_CAST((GHIDRA_CAST(&(local_4c)) + 0x0))) == '\0') { - if (isInterpolated == 0) { - this_00 = GHIDRA_CAST(&local_44); - local_40 = 1.0; - pAVar4 = GHIDRA_CAST(&local_40); - if (1.0 <= local_44) { - pAVar4 = this_00; - } - if (*GHIDRA_CAST((GHIDRA_CAST(player) + 0x14)) < *GHIDRA_CAST((pAVar4->_filename)._buf)) { -LAB_00a03e32: - pVVar5 = directionLocal; - } - else { - *GHIDRA_CAST((GHIDRA_CAST(player) + 0xc)) = local_44 / 3.0; - if (ownerAsPlayer == GHIDRA_CAST(0x0)) { - ownerPlayer = 7 - GHIDRA_INT((local_44 * -0.15)); - iVar10 = 0xb; - if (0xb < ownerPlayer) { - iVar10 = ownerPlayer; - } - Weapon::SetBlinkTime(player,iVar10,ownerPlayer); - } - Weapon::TriggerTearEffects(player,&aimDirection,1); - Weapon::get_owner_position(player,&firePos); - local_4c = aimDirection.x * 10.0; - local_44 = aimDirection.y * 10.0; - pVVar5 = Weapon::get_tear_movement_inheritance(player,&scratchVec,&aimDirection); - local_4c = local_4c + pVVar5->x; - local_44 = local_44 + pVVar5->y; - iVar10 = unusedArg; - Weapon::GetMultiShotParams(player,multiShotParams,unusedArg); - local_40 = -local_44; - if (isShootingBackwards != '\0') { - local_58.x = -local_4c * local_70.y; - local_58.y = local_40 * local_70.y; - tear = fire_fetus_tear(player,&firePos,&local_58,0,*GHIDRA_CAST((GHIDRA_CAST(player) + 4)),1.0,iVar10); - iVar10 = 0xa03a92; - (**(code **)(*GHIDRA_CAST(tear) + 0xc))(); - } - if (isShootingSideways != '\0') { - local_58.x = local_4c * local_70.y; - local_58.y = local_40 * local_70.y; - tear = fire_fetus_tear(player,&firePos,&local_58,0,*GHIDRA_CAST((GHIDRA_CAST(player) + 4)),1.0,iVar10); - iVar10 = 0xa03adf; - (**(code **)(*GHIDRA_CAST(tear) + 0xc))(); - local_58.x = -local_4c * local_70.y; - local_58.y = local_44 * local_70.y; - tear = fire_fetus_tear(player,&firePos,&local_58,0,*GHIDRA_CAST((GHIDRA_CAST(player) + 4)),1.0,iVar10); - (**(code **)(*GHIDRA_CAST(tear) + 0xc))(); - } - local_40 = (float)(numRandomDirTears & 0xffff); - if (local_40 != 0.0) { - do { - source = *GHIDRA_CAST((GHIDRA_CAST(player) + 4)); - uVar2 = Random(); - spreadAngle = ((float)((double)GHIDRA_INT(uVar2) + - __uint_to_double_fixup[-(GHIDRA_INT(uVar2) >> 0x1f)]) * 2.3283064e-10 * - 50.0 - 25.0) * 0.017453292; - local_58.y = cos(spreadAngle); - iVar10 = 0xa03b99; - fVar8 = sin(spreadAngle); - scratchVec.x = (local_4c * local_58.y - local_44 * fVar8) * local_70.y; - scratchVec.y = (local_4c * fVar8 + local_44 * local_58.y) * local_70.y; - tear = fire_fetus_tear(player,&firePos,&scratchVec,0,source,1.0,iVar10); - (**(code **)(*GHIDRA_CAST(tear) + 0xc))(); - local_40 = (float)(GHIDRA_INT(local_40) - 1); - } while (local_40 != 0.0); - local_40 = 0.0; - } - iVar10 = 0; - if (0 < multiShotParams[0]) { - local_58.x = local_4c; - local_58.y = local_44; - do { - shotDirection.y = local_58.y; - shotDirection.x = local_58.x; - uVar2 = numRandomDirTears; - Entity_Player::GetMultiShotPositionVelocity - (&local_34,iVar10,9,shotDirection,local_70.y,multiShotParams[0],fStack_a0, - fStack_9c,fStack_98,fStack_94,iStack_90,fStack_8c,(uint8_t)uStack_88, - (short)numRandomDirTears); - scratchVec.x = firePos.x + local_34; - scratchVec.y = local_30 + firePos.y; - tear = fire_fetus_tear(player,&scratchVec,&local_2c,0,*GHIDRA_CAST((GHIDRA_CAST(player) + 4)),1.0, - uVar2); - (**(code **)(*GHIDRA_CAST(tear) + 0xc))(); - iVar10 = iVar10 + 1; - } while (iVar10 < multiShotParams[0]); - } - pVVar5 = directionLocal; - this_00 = *GHIDRA_CAST((GHIDRA_CAST(player) + 4)); - local_58.y = (float)this_00; - if ((this_00 != GHIDRA_CAST(0x0)) && ((this_00->_animDefaultName)._size == 1)) { - fVar8 = 2.10195e-44; - local_2c.y = 2.10195e-44; - local_14 = (void *)0x0; - local_34 = (float)0x6f6f6853; - local_2c.x = 1.82169e-44; - (*GHIDRA_CAST((GHIDRA_CAST(&(subAnimName)) + 0x0))) = 'S'; - (*GHIDRA_CAST((GHIDRA_CAST(&(subAnimName)) + 0x1))) = 'u'; - (*GHIDRA_CAST((GHIDRA_CAST(&(subAnimName)) + 0x2))) = 'b'; - (*GHIDRA_CAST((GHIDRA_CAST(&(subAnimName)) + 0x3))) = 'A'; - (*GHIDRA_CAST((GHIDRA_CAST(&(subAnimName)) + 0x4))) = 'n'; - (*GHIDRA_CAST((GHIDRA_CAST(&(subAnimName)) + 0x5))) = 'i'; - (*GHIDRA_CAST((GHIDRA_CAST(&(subAnimName)) + 0x6))) = 'm'; - (*GHIDRA_CAST((GHIDRA_CAST(&(subAnimName)) + 0x7))) = '_'; - local_30 = (float)CONCAT22((*GHIDRA_CAST((GHIDRA_CAST(&(local_30)) + 0x2))),0x74); - pvVar6 = (g_manager->_itemConfig)._collectibles._begin; - if (GHIDRA_INT((g_manager->_itemConfig)._collectibles._end) - GHIDRA_INT(pvVar6) >> 2 < 0x2a7) { - local_40 = 0.0; - } - else { - local_40 = *GHIDRA_CAST((GHIDRA_CAST(pvVar6) + 0xa98)); - } - pfVar3 = this_00[0x10]._championColor._colorize + 2; - iVar10 = 0xf; - do { - if ((-1 < GHIDRA_INT(*pfVar3)) && (*GHIDRA_CAST((pfVar3 + 3)) != '\0')) { - this_00 = GHIDRA_CAST((GHIDRA_INT(*pfVar3) * 0x130 + - GHIDRA_INT(((GHIDRA_CAST((GHIDRA_INT(local_58.y) + 0x1140)))->_championColor)._tint[3]) - )); - if (*GHIDRA_CAST(this_00[1]._filename._buf) == local_40) { - animName = GHIDRA_CAST(&subAnimName); - if (0xf < GHIDRA_UINT(fVar8)) { - animName = GHIDRA_CAST(subAnimName); - } - ANM2::PlayOverlay(this_00,animName,1); - this_00 = extraout_ECX_01; - fVar8 = local_2c.y; - } - } - player = weapon; - pfVar3 = pfVar3 + 4; - iVar10 = iVar10 + -1; - } while (iVar10 != 0); - local_14 = (void *)0xffffffff; - if (0xf < GHIDRA_UINT(fVar8)) { - uVar2 = GHIDRA_INT(fVar8) + 1; - pvVar6 = GHIDRA_CAST(subAnimName); - if (0xfff < uVar2) { - pvVar6 = *(void **)(GHIDRA_INT(GHIDRA_CAST(subAnimName)) + -4); - uVar2 = GHIDRA_INT(fVar8) + 0x24; - if (0x1f < GHIDRA_UINT((GHIDRA_INT(GHIDRA_CAST(subAnimName)) + (-4 - GHIDRA_INT(pvVar6))))) { - /* WARNING: Subroutine does not return */ - _invalid_parameter_noinfo_noreturn(); - } - } - operator_delete(pvVar6,uVar2); - this_00 = extraout_ECX_02; - } - goto LAB_00a03e32; - } - Weapon::UpdateHeadChargeAnimation(player,0x2a6,2,directionLocal,-1.0); - this_00 = extraout_ECX_04; - } - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(((GHIDRA_CAST(player)))) + 0x14)))) = 0; - bVar1 = Weapon::is_c_section_anim_finished(player,GHIDRA_INT(this_00)); - iVar10 = unusedCollectibleId; - if (bVar1 != 0) { - Weapon::update_c_section_charge_anim(player,unusedCollectibleId,0,pVVar5,0.0); - iVar10 = extraout_ECX_03; - } - } - else { - pVVar5 = directionLocal; - } - bVar1 = Weapon::is_c_section_anim_finished(player,iVar10); - if (bVar1 == 0) { - ExceptionList = local_1c; - return; - } - goto LAB_00a03f31; - } - local_40 = *GHIDRA_CAST((GHIDRA_CAST(player) + 0x14)); - if (local_44 <= local_40) { - puVar9 = &DAT_bf800000; - ownerPlayer = 1; -LAB_00a03f02: - pVVar5 = directionLocal; - Weapon::update_c_section_charge_anim(player,iVar10,ownerPlayer,directionLocal,(float)puVar9); - iVar10 = extraout_ECX_06; - } - else { - if (isInterpolated == 0) { - if (*GHIDRA_CAST((GHIDRA_CAST(player) + 4)) != 0) { - fVar8 = *GHIDRA_CAST((*GHIDRA_CAST((GHIDRA_CAST(player) + 4)) + 0x39c)); - } - local_40 = local_40 + fVar8; - *GHIDRA_CAST((GHIDRA_CAST(player) + 0x14)) = local_40; - } - bVar1 = Weapon::is_c_section_anim_finished(player,iVar10); - iVar10 = extraout_ECX_05; - pVVar5 = directionLocal; - if (bVar1 != 0) { - puVar9 = GHIDRA_CAST(((local_40 / local_44) * 18.0)); - ownerPlayer = 0; - goto LAB_00a03f02; - } - } - if (isInterpolated == 0) { - Weapon::SetBlinkTime(player,1,iVar10); - newAimDirection = Weapon::get_aim_direction(player,&local_70,pVVar5); - *GHIDRA_CAST((GHIDRA_CAST(player) + 0x20)) = newAimDirection->x; - *GHIDRA_CAST((GHIDRA_CAST(player) + 0x24)) = newAimDirection->y; - } -LAB_00a03f31: - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(((GHIDRA_CAST(player)))) + 0x3c)))) = pVVar5->x; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(((GHIDRA_CAST(player)))) + 0x40)))) = pVVar5->y; - ExceptionList = local_1c; - return; -} - -// 00a03f60 -float Weapon_Fetus::GetMaxCharge() -{ - float maxCharge; - - maxCharge = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x10)) * 3.0; - if (maxCharge <= 0.001) { - maxCharge = 0.001; - } - return maxCharge; -} diff --git a/generated-src/weapon_ludovico.cpp b/generated-src/weapon_ludovico.cpp deleted file mode 100644 index 198beac..0000000 --- a/generated-src/weapon_ludovico.cpp +++ /dev/null @@ -1,635 +0,0 @@ -#include "classes.h" - -// 00a06a30 -void Weapon_Ludovico::Fire(Vector *direction, uint8_t isShooting, uint8_t isInterpolated) -{ - void *orbitTear = this; - uint32_t *puVar1; - Entity *pEVar2; - uint8_t bVar3; - uint32_t uVar4; - int iVar5; - Vector *pVVar6; - TearParams *hitParams; - BitSet128 *pBVar7; - Entity_Tear **ppEVar8; - Entity_Tear *orbitTear; - uint32_t rngResult; - Entity_Player *extraout_ECX; - Entity_Player *extraout_ECX_00; - Entity_Player *extraout_ECX_01; - Entity_Player *extraout_ECX_02; - Entity_Player *pEVar9; - Entity_Player *extraout_ECX_03; - Entity_Player *extraout_ECX_04; - int extraout_ECX_05; - int *piVar10; - Entity_Player *player; - int *piVar11; - Entity_Tear *extraout_EDX; - uint64_t *allocatedBytesPtr; - Entity_Tear *pEVar12; - uint8_t *puVar13; - Weapon *weapon; - int *piVar14; - float fVar15; - float fVar16; - short multiShotParams [18]; - BitSet128 notExplosiveFlags; - BitSet128 tearFlagsTmp; - uint8_t local_16c [8]; - int iStack_164; - Entity_Tear *pEStack_160; - uint8_t notExplosiveFlags2 [4]; - Entity_Tear *orbitTearsBegin; - int *orbitTearsEnd; - int *orbitTearsCap; - void *childTearsBegin; - int *childTearsEnd; - int *local_144; - int *childTearsCap; - uint8_t local_13c [8]; - Vector VStack_134; - Vector local_12c; - uint8_t local_124 [8]; - Vector local_11c; - Entity_Tear *luck; - float shotSpeed; - int *local_10c; - Entity_Player *ownerPlayer; - Weapon *self; - Entity_Tear *local_100; - Vector local_fc; - Entity_Tear *local_f4; - Entity_Tear *local_f0; - int *local_ec; - Entity_Tear *local_e8; - TearParams tearParams; - TearParams hitParamsBuf; - uint32_t local_14; - void *local_10; - uint8_t *puStack_c; - float local_8; - uint64_t allocatedBytes; - Game *game; - - local_8 = -NAN; - puStack_c = &LAB_00b10866; - local_10 = ExceptionList; - uVar4 = __security_cookie ^ GHIDRA_UINT(((&hitParamsBuf)[1]._tearColor._colorize + 3)); - ExceptionList = &local_10; - local_f4 = GHIDRA_CAST(direction); - self = orbitTear; - local_14 = uVar4; - Weapon::Fire(orbitTear,direction,isShooting,isInterpolated); - pEVar9 = *GHIDRA_CAST((GHIDRA_CAST(orbitTear) + 4)); - if (pEVar9 == GHIDRA_CAST(0x0)) { -LAB_00a06a9a: - ownerPlayer = GHIDRA_CAST(0x0); - if (pEVar9 != GHIDRA_CAST(0x0)) goto LAB_00a06aa0; - local_f0 = GHIDRA_CAST(g_vectorZero.x); - local_ec = GHIDRA_CAST(g_vectorZero.y); - ownerPlayer = GHIDRA_CAST(0x0); -LAB_00a06b2b: - luck = GHIDRA_CAST(0x0); - if (pEVar9 != GHIDRA_CAST(0x0)) goto LAB_00a06b3a; -LAB_00a06b6d: - shotSpeed = 1.0; - } - else { - if (pEVar9->_type == 1) { - ownerPlayer = pEVar9; - } - else { - if (pEVar9->_type != 3) goto LAB_00a06a9a; - ownerPlayer = *GHIDRA_CAST(&pEVar9->_isControlsEnabled); - } -LAB_00a06aa0: - local_f0 = GHIDRA_CAST((pEVar9->_pos).x); - local_ec = GHIDRA_CAST((pEVar9->_pos).y); - if (pEVar9->_type == 1) { - player = pEVar9; - } - else if ((pEVar9->_type != 3) || - (player = *GHIDRA_CAST(&pEVar9->_isControlsEnabled), player == GHIDRA_CAST(0x0) - )) goto LAB_00a06b2b; - luck = GHIDRA_CAST(player->_luck); -LAB_00a06b3a: - if ((pEVar9->_type != 1) && - ((pEVar9->_type != 3 || - (pEVar9 = *GHIDRA_CAST(&pEVar9->_isControlsEnabled), pEVar9 == GHIDRA_CAST(0x0))))) - goto LAB_00a06b6d; - shotSpeed = pEVar9->_shotspeed; - } - player = ownerPlayer; - local_12c.y = (float)(GHIDRA_INT(orbitTear) + 0x44); - piVar14 = *GHIDRA_CAST((GHIDRA_CAST(orbitTear) + 0x44)); - local_10c = piVar14; - if ((piVar14 == GHIDRA_CAST(0x0)) || (piVar14[10] != 2)) { - if (isInterpolated != 0) { - ExceptionList = local_10; - return; - } - if (piVar14 != GHIDRA_CAST(0x0)) { - (**(code **)(*piVar14 + 0x28))(uVar4); - } - TearParams::constructor(&tearParams); - weapon = self; - if (player != GHIDRA_CAST(0x0)) { - pEVar2 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x4)))); - if ((pEVar2 == GHIDRA_CAST(0x0)) || (pEVar2->_type != 1)) { - iVar5 = 0; - } - else { - iVar5 = GHIDRA_INT(*GHIDRA_CAST((pEVar2[5]._sprite._championColor._tint + 3))); - } - hitParams = Entity_Player::GetTearHitParams(player,&hitParamsBuf,8,1.0,iVar5,pEVar2); - TearParams::operator_(&tearParams,hitParams); - } - uVar4 = Random(); - local_11c.x = (float)local_f0 + 0.0; - local_11c.y = (float)local_ec + 5.0; - orbitTear = (Entity_Tear *) - Game::Spawn(g_game,2,tearParams._tearVariant,&local_11c,&g_vectorZero, - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((weapon)) + 0x4)))),0,uVar4); - if ((orbitTear == GHIDRA_CAST(0x0)) || (orbitTear->_type != 2)) { - orbitTear = GHIDRA_CAST(0x0); - } - VStack_134.y = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((weapon)) + 0x4)))); - puVar1 = &orbitTear->_parent; - if (*puVar1 != 0) { - local_fc.y = (float)puVar1; - msvc::multiset::erase(&local_fc.y); - } - *puVar1 = VStack_134.y; - if (VStack_134.y != 0.0) { - msvc::multiset::insert(puVar1); - } - orbitTear->_height = -40.0; - fVar15 = Entity_Tear::get_height_offset_y(orbitTear,-40.0); - game = g_game; - (orbitTear->_posOffset).y = fVar15; - if (*GHIDRA_CAST((GHIDRA_CAST(game->_room) + 8)) == 0x10) { - (orbitTear->_posOffset).y = -18.0; - } - (**(code **)(*GHIDRA_CAST(orbitTear) + 0x40))(tearParams._tearDamage); - pBVar7 = BitSet128::operator_or(&tearFlagsTmp,&tearParams._flags,&g_tearFlagLudovico); - Entity_Tear::SetTearFlags(orbitTear,*pBVar7); - (**(code **)(*GHIDRA_CAST(orbitTear) + 0x3c))(&tearParams._tearColor,0xffffffff,0xff,0,1); - fVar15 = sqrtf(tearParams._tearDamage); - fVar15 = fVar15 * 0.15 + tearParams._tearDamage * 0.04 + 1.5; - if (fVar15 <= 0.01) { - fVar15 = 0.01; - } - orbitTear->_baseScale = fVar15; - orbitTear->_fScale = fVar15; - Entity_Tear::ResetSpriteScale(orbitTear); - (**(code **)(*GHIDRA_CAST(orbitTear) + 0xc))(); - fVar15 = local_12c.y; - if (*GHIDRA_CAST(local_12c.y) == orbitTear) { - ExceptionList = local_10; - return; - } - if (*GHIDRA_CAST(local_12c.y) != GHIDRA_CAST(0x0)) { - local_fc.y = local_12c.y; - msvc::multiset::erase(&local_fc.y); - } - *GHIDRA_CAST(fVar15) = orbitTear; - msvc::multiset::insert(fVar15); - ExceptionList = local_10; - return; - } - if (isInterpolated != 0) { - ExceptionList = local_10; - return; - } - if (isShooting != 0) { - local_fc.x = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((local_f4)) + 0x0)))); - local_100 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((local_f4)) + 0x4)))); - local_fc.y = (float)local_100; - local_e8 = GHIDRA_CAST(local_fc.x); - if (1.0 < local_fc.x * local_fc.x + (float)local_100 * (float)local_100) { - (GHIDRA_CAST((&local_fc)))->Vector::Normalize(); - local_e8 = GHIDRA_CAST(local_fc.x); - pEVar9 = extraout_ECX; - } - local_100 = GHIDRA_CAST(local_fc.y); - local_fc.x = (float)local_e8; - if (player != GHIDRA_CAST(0x0)) { - bVar3 = Entity_Player::HasCollectible(player,0x166,0); - pEVar9 = extraout_ECX_00; - if (bVar3 != 0) { - bVar3 = Entity_Player::HasCollectible(player,0xf5,0); - pEVar9 = extraout_ECX_01; - if (bVar3 == 0) { - local_f0 = GHIDRA_CAST(cos(0.7853982)); - fVar15 = sin(0.7853982); - fVar16 = (float)local_e8 * fVar15; - local_e8 = GHIDRA_CAST(((float)local_e8 * (float)local_f0 - fVar15 * (float)local_100)); - local_100 = GHIDRA_CAST(((float)local_f0 * (float)local_100 + fVar16)); - pEVar9 = extraout_ECX_02; - } - } - } - fVar15 = (float)piVar14[0xdb]; - if (fVar15 != 0.0) { - piVar14[0xd9] = - GHIDRA_INT((((float)piVar14[0xe7] * (float)local_100 * shotSpeed * 3.0) / fVar15 + - (float)piVar14[0xd9])); - piVar14[0xd8] = - GHIDRA_INT((((float)piVar14[0xe7] * (float)local_e8 * shotSpeed * 3.0) / fVar15 + - (float)piVar14[0xd8])); - } - } - weapon = self; - if (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x4)))) != GHIDRA_CAST(0x0)) { - iVar5 = Entity::GetIntervalTicks(*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x4)))),*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x10)))),0.0); - pEVar9 = extraout_ECX_03; - if (iVar5 != 0) { - iVar5 = *GHIDRA_CAST((weapon + 1)); - if (iVar5 == 0) { -LAB_00a06df7: - pVVar6 = MusicManager::RandomVector(&local_fc); - } - else { - VStack_134.x = *GHIDRA_CAST((iVar5 + 0x33c)); - VStack_134.y = *GHIDRA_CAST((iVar5 + 0x340)); - local_fc.x = *GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((weapon)) + 0x4)))) + 0x33c)); - local_fc.y = *GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((weapon)) + 0x4)))) + 0x340)); - bVar3 = (GHIDRA_CAST((&VStack_134)))->Vector::operator_ne(&local_fc); - if (bVar3 == 0) goto LAB_00a06df7; - local_fc.x = *GHIDRA_CAST((*GHIDRA_CAST((weapon + 1)) + 0x33c)) - - *GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((weapon)) + 0x4)))) + 0x33c)); - local_fc.y = *GHIDRA_CAST((*GHIDRA_CAST((weapon + 1)) + 0x340)) - - *GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((weapon)) + 0x4)))) + 0x340)); - pVVar6 = (GHIDRA_CAST((&local_fc)))->Vector::Normalized(&local_11c); - } - Weapon::TriggerTearEffects(weapon,pVVar6,1); - pEVar9 = extraout_ECX_04; - } - } - Weapon::GetMultiShotParams(weapon,multiShotParams,GHIDRA_INT(pEVar9)); - local_e8 = GHIDRA_CAST((multiShotParams[0] + -1)); - local_100 = (void *)0x0; - childTearsBegin = (void *)0x0; - if (GHIDRA_INT(local_e8) < 0) { - local_e8 = GHIDRA_CAST(0x0); - } - piVar11 = GHIDRA_CAST(0x0); - local_ec = GHIDRA_CAST(0x0); - childTearsEnd = GHIDRA_CAST(0x0); - childTearsCap = GHIDRA_CAST(0x0); - local_144 = GHIDRA_CAST(0x0); - local_8 = 0.0; - local_f4 = GHIDRA_CAST(piVar14[0xf0]); - if (local_f4 != GHIDRA_CAST(0x0)) { - do { - if (childTearsEnd == piVar11) { - msvc::vector::_Emplace_reallocate(childTearsEnd,&local_f4); - piVar11 = local_144; - } - else { - *childTearsEnd = GHIDRA_INT(local_f4); - childTearsEnd = childTearsEnd + 1; - } - local_f4 = GHIDRA_CAST(local_f4->_child); - } while (local_f4 != GHIDRA_CAST(0x0)); - local_100 = childTearsBegin; - childTearsCap = piVar11; - local_ec = childTearsEnd; - } - piVar11 = local_ec; - orbitTear = local_100; - local_f4 = GHIDRA_CAST((GHIDRA_INT(local_ec) - GHIDRA_INT(local_100) >> 2)); - childTearsBegin = local_100; - childTearsEnd = local_ec; - if (local_f4 < local_e8) { - TearParams::constructor(&tearParams); - orbitTear = extraout_EDX; - if (ownerPlayer != GHIDRA_CAST(0x0)) { - iVar5 = FUN_009f57f0(); - hitParams = Entity_Player::GetTearHitParams - (ownerPlayer,&hitParamsBuf,8,1.0,iVar5,*GHIDRA_CAST((extraout_ECX_05 + 4)) - ); - TearParams::operator_(&tearParams,hitParams); - orbitTear = local_e8; - } - local_e8 = GHIDRA_CAST((GHIDRA_INT(orbitTear) - GHIDRA_INT(local_f4))); - if (0 < GHIDRA_INT(local_e8)) { - local_ec = piVar14 + 0x3c; - local_f4 = GHIDRA_CAST(0x3c23d70a); - do { - uVar4 = Random(); - local_fc.x = (float)piVar14[0xcf] + 0.0; - local_fc.y = (float)piVar14[0xd0] + 5.0; - orbitTear = (Entity_Tear *) - Game::Spawn(g_game,2,tearParams._tearVariant,&local_fc,&g_vectorZero, - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x4)))),4,uVar4); - if ((orbitTear == GHIDRA_CAST(0x0)) || (orbitTear->_type != 2)) { - orbitTear = GHIDRA_CAST(0x0); - } - if (orbitTear->_parent != 0) { - local_f0 = GHIDRA_CAST(&orbitTear->_parent); - msvc::multiset::erase(&local_f0); - } - orbitTear->_parent = local_10c; - msvc::multiset::insert(&orbitTear->_parent); - orbitTear->_height = -40.0; - fVar15 = Entity_Tear::get_height_offset_y(orbitTear,-40.0); - game = g_game; - (orbitTear->_posOffset).y = fVar15; - if (*GHIDRA_CAST((GHIDRA_CAST(game->_room) + 8)) == 0x10) { - (orbitTear->_posOffset).y = -18.0; - } - (**(code **)(*GHIDRA_CAST(orbitTear) + 0x40))(local_10c[0xe2]); - pBVar7 = (GHIDRA_CAST((&g_tearFlagExplosive)))->BitSet128::__bnot(GHIDRA_CAST(notExplosiveFlags2)); - (*GHIDRA_CAST((GHIDRA_CAST(&(local_16c)) + 0x0))) = local_10c[0x10a]; - (*GHIDRA_CAST((GHIDRA_CAST(&(local_16c)) + 0x4))) = local_10c[0x10b]; - iStack_164 = local_10c[0x10c]; - pEStack_160 = GHIDRA_CAST(local_10c[0x10d]); - pBVar7 = BitSet128::operator_and(GHIDRA_CAST(local_124),GHIDRA_CAST(local_16c),pBVar7); - Entity_Tear::SetTearFlags(orbitTear,*pBVar7); - (**(code **)(*GHIDRA_CAST(orbitTear) + 0x3c))(local_ec,0xffffffff,0xff,0,1); - local_f0 = GHIDRA_CAST(((float)local_10c[0x108] * 0.5)); - ppEVar8 = &local_f0; - if ((float)local_10c[0x108] * 0.5 <= 0.01) { - ppEVar8 = &local_f4; - } - pEVar12 = *ppEVar8; - orbitTear->_baseScale = (float)pEVar12; - orbitTear->_fScale = (float)pEVar12; - Entity_Tear::ResetSpriteScale(orbitTear); - orbitTear->_entityGridCollisionClass = 0; - local_f0 = orbitTear; - if (piVar11 == childTearsCap) { - msvc::vector::_Emplace_reallocate(piVar11,&local_f0); - childTearsCap = local_144; - } - else { - *piVar11 = GHIDRA_INT(orbitTear); - childTearsEnd = piVar11 + 1; - } - local_e8 = GHIDRA_CAST((GHIDRA_INT(local_e8) + -1)); - piVar11 = childTearsEnd; - piVar14 = local_10c; - } while (local_e8 != GHIDRA_CAST(0x0)); - local_100 = childTearsBegin; - } -LAB_00a07202: - puVar13 = GHIDRA_CAST((GHIDRA_INT(piVar11) - GHIDRA_INT(local_100) >> 2)); - local_e8 = GHIDRA_CAST(0x0); - orbitTear = local_100; - piVar11 = piVar14; - if (puVar13 != GHIDRA_CAST(0x0)) { - do { - local_ec = *GHIDRA_CAST((GHIDRA_CAST(orbitTear) + GHIDRA_INT(local_e8) * 4)); - local_f0 = GHIDRA_CAST((piVar11 + 0xf0)); - if (*GHIDRA_CAST(local_f0) != 0) { - local_12c.y = (float)local_f0; - msvc::multiset::erase(&local_12c.y); - orbitTear = local_100; - } - *GHIDRA_CAST(local_f0) = local_ec; - if (local_ec != GHIDRA_CAST(0x0)) { - msvc::multiset::insert(local_f0); - orbitTear = local_100; - } - piVar11 = *GHIDRA_CAST((GHIDRA_CAST(orbitTear) + GHIDRA_INT(local_e8) * 4)); - if (g_game->_frameCount == piVar11[0xca]) { - (**(code **)(*piVar11 + 0xc))(); - piVar11 = *GHIDRA_CAST((GHIDRA_CAST(local_100) + GHIDRA_INT(local_e8) * 4)); - orbitTear = local_100; - } - local_e8 = GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((local_e8)) + 0x1)))); - } while (local_e8 < puVar13); - } - } - else if (local_e8 < local_f4) { - pEVar12 = local_e8; - do { - local_f0 = luck; - (**(code **)(**GHIDRA_CAST((GHIDRA_CAST(orbitTear) + GHIDRA_INT(pEVar12) * 4)) + 0x28))(); - pEVar12 = GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((pEVar12)) + 0x1)))); - } while (pEVar12 < local_f4); - luck = local_f0; - piVar10 = GHIDRA_CAST((GHIDRA_INT(orbitTear) + GHIDRA_INT(local_e8) * 4)); - piVar11 = local_ec; - piVar14 = local_10c; - if (piVar10 != local_ec) { - piVar11 = piVar10; - childTearsEnd = piVar10; - } - goto LAB_00a07202; - } - pEVar9 = ownerPlayer; - if (ownerPlayer != GHIDRA_CAST(0x0)) { - bVar3 = Entity_Player::HasCollectible(ownerPlayer,0xe5,0); - if (bVar3 != 0) { - piVar11 = GHIDRA_CAST(0x0); - local_f0 = GHIDRA_CAST(0x0); - orbitTearsBegin = GHIDRA_CAST(0x0); - orbitTearsEnd = GHIDRA_CAST(0x0); - local_ec = GHIDRA_CAST(0x0); - orbitTearsCap = GHIDRA_CAST(0x0); - (*GHIDRA_CAST((GHIDRA_CAST(&(local_8)) + 0x0))) = 1; - EntityList::QuerySublist - (GHIDRA_CAST((GHIDRA_INT(g_game->_room) + 0x1218)),GHIDRA_CAST(local_16c),2,-1,5,0,0); - local_8 = (float)CONCAT31((*GHIDRA_CAST((GHIDRA_CAST(&(local_8)) + 0x1))),2); - local_e8 = pEStack_160; - if (pEStack_160 == GHIDRA_CAST(0x0)) { - orbitTear = GHIDRA_CAST(0x0); - } - else { - piVar10 = GHIDRA_CAST(0x0); - local_f4 = (*GHIDRA_CAST((GHIDRA_CAST(&(GHIDRA_CAST(local_16c))) + 0x4))); - do { - if (*GHIDRA_CAST((*GHIDRA_CAST(local_f4) + 0x3bc)) == piVar14) { - if (piVar11 == piVar10) { - msvc::vector::_Emplace_reallocate(piVar11,local_f4); - local_ec = orbitTearsCap; - piVar10 = orbitTearsCap; - piVar11 = orbitTearsEnd; - } - else { - *piVar11 = *GHIDRA_CAST(local_f4); - orbitTearsEnd = piVar11 + 1; - piVar11 = orbitTearsEnd; - } - } - local_f4 = GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((local_f4)) + 0x4)))); - local_e8 = GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(local_e8[-1])) + 0x847)))); - } while (local_e8 != GHIDRA_CAST(0x0)); - local_f0 = orbitTearsBegin; - local_e8 = GHIDRA_CAST(0x0); - orbitTear = orbitTearsBegin; - } - weapon = self; - if (GHIDRA_INT(piVar11) - GHIDRA_INT(orbitTear) < 4) { - pEVar2 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x4)))); - if ((pEVar2 == GHIDRA_CAST(0x0)) || (pEVar2->_type != 1)) { - iVar5 = 0; - } - else { - iVar5 = GHIDRA_INT(*GHIDRA_CAST((pEVar2[5]._sprite._championColor._tint + 3))); - } - Entity_Player::GetTearHitParams(ownerPlayer,&tearParams,8,1.0,iVar5,pEVar2); - local_fc.y = 0.01; - local_10c = GHIDRA_CAST(&DAT_00000005); - do { - uVar4 = Random(); - fVar15 = (float)((double)GHIDRA_INT(uVar4) + __uint_to_double_fixup[-(GHIDRA_INT(uVar4) >> 0x1f)]) * - 2.3283064e-10 * 3.14; - local_12c.y = fVar15 + fVar15; - VStack_134.y = sin(local_12c.y); - uVar4 = Random(); - local_e8 = (Entity_Tear *) - ((float)((double)GHIDRA_INT(uVar4) + __uint_to_double_fixup[-(GHIDRA_INT(uVar4) >> 0x1f)]) * - 2.3283064e-10 * 20.0 + 5.0); - fVar15 = cos(local_12c.y); - local_f4 = GHIDRA_CAST((fVar15 * (float)local_e8)); - local_e8 = GHIDRA_CAST(((float)local_e8 * VStack_134.y)); - uVar4 = Random(); - local_11c.x = (float)local_f4 + (float)piVar14[0xcf]; - local_11c.y = (float)local_e8 + (float)piVar14[0xd0]; - orbitTear = (Entity_Tear *) - Game::Spawn(g_game,2,tearParams._tearVariant,&local_11c,&g_vectorZero, - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((weapon)) + 0x4)))),5,uVar4); - if ((orbitTear == GHIDRA_CAST(0x0)) || (orbitTear->_type != 2)) { - orbitTear = GHIDRA_CAST(0x0); - } - (orbitTear->_parentOffset).x = (float)local_f4; - (orbitTear->_parentOffset).y = (float)local_e8; - if (orbitTear->_parent != 0) { - VStack_134.y = (float)&orbitTear->_parent; - msvc::multiset::erase(&VStack_134.y); - } - orbitTear->_parent = piVar14; - msvc::multiset::insert(&orbitTear->_parent); - orbitTear->_height = -40.0; - fVar15 = Entity_Tear::get_height_offset_y(orbitTear,-40.0); - game = g_game; - (orbitTear->_posOffset).y = fVar15; - if (*GHIDRA_CAST((GHIDRA_CAST(game->_room) + 8)) == 0x10) { - (orbitTear->_posOffset).y = -18.0; - } - (**(code **)(*GHIDRA_CAST(orbitTear) + 0x40))(piVar14[0xe2]); - pBVar7 = (GHIDRA_CAST((&g_tearFlagExplosive)))->BitSet128::__bnot(¬ExplosiveFlags); - (*GHIDRA_CAST((GHIDRA_CAST(&(local_13c)) + 0x0))) = piVar14[0x10a]; - (*GHIDRA_CAST((GHIDRA_CAST(&(local_13c)) + 0x4))) = piVar14[0x10b]; - VStack_134.x = (float)piVar14[0x10c]; - VStack_134.y = (float)piVar14[0x10d]; - pBVar7 = BitSet128::operator_and(&tearFlagsTmp,GHIDRA_CAST(local_13c),pBVar7); - Entity_Tear::SetTearFlags(orbitTear,*pBVar7); - (**(code **)(*GHIDRA_CAST(orbitTear) + 0x3c))(piVar14 + 0x3c,0xffffffff,0xff,0,1); - uVar4 = Random(); - VStack_134.y = ((float)((double)GHIDRA_INT(uVar4) + __uint_to_double_fixup[-(GHIDRA_INT(uVar4) >> 0x1f)] - ) * 2.3283064e-10 * 0.75 + 0.5) * (float)piVar14[0x108]; - pVVar6 = &VStack_134; - if (VStack_134.y <= 0.01) { - pVVar6 = &local_fc; - } - fVar15 = pVVar6->y; - orbitTear->_baseScale = fVar15; - orbitTear->_fScale = fVar15; - Entity_Tear::ResetSpriteScale(orbitTear); - local_10c = GHIDRA_CAST((GHIDRA_INT(local_10c) + -1)); - orbitTear->_entityGridCollisionClass = 0; - weapon = self; - } while (local_10c != GHIDRA_CAST(0x0)); - } - if (local_16c[0] == '\0') { - if (g_mainHeap == (void *)0x0) { - allocatedBytesPtr = &g_allocatedBytesNoHeap; - } - else { - allocatedBytesPtr = GHIDRA_CAST((GHIDRA_INT(g_mainHeap) + 0x30)); - } - if ((*GHIDRA_CAST((GHIDRA_CAST(&(GHIDRA_CAST(local_16c))) + 0x4))) != GHIDRA_CAST(0x0)) { - uVar4 = *GHIDRA_CAST(&(GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(local_16c)) + 0x4)))(*GHIDRA_CAST((GHIDRA_CAST(( + -0x848))))) + 0x844)))); - allocatedBytes = *allocatedBytesPtr; - *GHIDRA_CAST(allocatedBytesPtr) = GHIDRA_UINT(*allocatedBytesPtr) - uVar4; - *GHIDRA_CAST((GHIDRA_CAST(allocatedBytesPtr) + 4)) = - *GHIDRA_CAST((GHIDRA_CAST(allocatedBytesPtr) + 4)) - GHIDRA_UINT((GHIDRA_UINT(allocatedBytes) < uVar4)); - free(&(GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(local_16c)) + 0x4)))(*GHIDRA_CAST((GHIDRA_CAST(( + -0x848))))) + 0x844)))); - } - } - local_8 = (float)(GHIDRA_UINT(local_8) & 0xffffff00); - if (local_f0 != GHIDRA_CAST(0x0)) { - uVar4 = GHIDRA_INT(local_ec) - GHIDRA_INT(local_f0) & 0xfffffffc; - orbitTear = local_f0; - if (0xfff < uVar4) { - orbitTear = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(local_f0[-1])) + 0x844)))); - uVar4 = uVar4 + 0x23; - if (0x1f < GHIDRA_UINT((GHIDRA_INT(local_f0) + (-4 - GHIDRA_INT(orbitTear))))) goto LAB_00a07ae8; - } - operator_delete(orbitTear,uVar4); - } - pEVar9 = ownerPlayer; - } - iVar5 = Entity::GetIntervalTicks(GHIDRA_CAST(pEVar9),*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x10)))),0.0); - if (iVar5 != 0) { - iVar5 = 0xa07781; - bVar3 = Entity_Player::HasCollectible(pEVar9,0x57,0); - if ((bVar3 != 0) && - ((local_fc.y = (float)__ftoui3(), GHIDRA_CAST(local_fc.y) == GHIDRA_CAST(0x0) || - (uVar4 = Random(), uVar4 % GHIDRA_UINT(local_fc.y) == 0)))) { - local_11c.x = shotSpeed * 10.0; - VStack_134.x = (float)piVar14[0xcf]; - VStack_134.y = (float)piVar14[0xd0]; - local_11c.y = shotSpeed * 0.0; - local_fc.y = local_11c.x; - local_ec = GHIDRA_CAST(local_11c.y); - Weapon::fire_tear(self,&VStack_134,&local_11c,6,iVar5,1.0,0.0); - VStack_134.y = shotSpeed * -10.0; - local_12c.x = (float)piVar14[0xcf]; - local_12c.y = (float)piVar14[0xd0]; - local_11c.y = (float)local_ec; - local_11c.x = VStack_134.y; - Weapon::fire_tear(self,&local_12c,&local_11c,6,iVar5,1.0,0.0); - local_fc.x = (float)piVar14[0xcf]; - local_11c.x = (float)local_ec; - local_11c.y = local_fc.y; - local_fc.y = (float)piVar14[0xd0]; - Weapon::fire_tear(self,&local_fc,&local_11c,6,iVar5,1.0,0.0); - local_fc.x = (float)piVar14[0xcf]; - local_fc.y = (float)piVar14[0xd0]; - local_11c.x = (float)local_ec; - local_11c.y = VStack_134.y; - Weapon::fire_tear(self,&local_fc,&local_11c,6,iVar5,1.0,0.0); - } - iVar5 = 0xa079a4; - bVar3 = Entity_Player::HasCollectible(pEVar9,0x37,0); - if ((bVar3 != 0) && - ((uVar4 = __ftoui3(), uVar4 == 0 || (rngResult = Random(), rngResult % uVar4 == 0)))) { - uVar4 = Random(); - shotSpeed = shotSpeed * 10.0; - fVar15 = (float)((double)GHIDRA_INT(uVar4) + __uint_to_double_fixup[-(GHIDRA_INT(uVar4) >> 0x1f)]) * - 2.3283064e-10 * 3.14; - local_fc.y = fVar15 + fVar15; - fVar15 = cos(local_fc.y); - local_11c.x = fVar15 * shotSpeed; - fVar15 = sin(local_fc.y); - VStack_134.x = (float)piVar14[0xcf]; - local_11c.y = fVar15 * shotSpeed; - VStack_134.y = (float)piVar14[0xd0]; - Weapon::fire_tear(self,&VStack_134,&local_11c,6,iVar5,1.0,0.0); - } - } - } - if (local_100 != (void *)0x0) { - uVar4 = GHIDRA_INT(childTearsCap) - GHIDRA_INT(local_100) & 0xfffffffc; - orbitTear = local_100; - if (0xfff < uVar4) { - orbitTear = *GHIDRA_CAST((GHIDRA_CAST(local_100) + -4)); - uVar4 = uVar4 + 0x23; - if (0x1f < GHIDRA_UINT((GHIDRA_INT(local_100) + (-4 - GHIDRA_INT(orbitTear))))) { -LAB_00a07ae8: - /* WARNING: Subroutine does not return */ - _invalid_parameter_noinfo_noreturn(); - } - } - operator_delete(orbitTear,uVar4); - } - ExceptionList = local_10; - return; -} diff --git a/generated-src/weapon_rockets.cpp b/generated-src/weapon_rockets.cpp deleted file mode 100644 index 18f4ab2..0000000 --- a/generated-src/weapon_rockets.cpp +++ /dev/null @@ -1,525 +0,0 @@ -#include "classes.h" - -// 00a08d40 -void Weapon_Rockets::Fire(Vector *aimDirection, uint8_t isShooting, uint8_t isInterpolated) -{ - void *player = this; - int iVar1; - uint64_t qVar2; - uint8_t bVar3; - char extraout_AL; - short rocketCount; - uint32_t uVar4; - Entity *mainTarget; - Entity *extraTarget; - int iVar5; - BitSet128 *maskedFlags; - Vector *pVVar6; - Entity_Player *extraout_ECX; - float *unusedArg; - Entity_Player *pEVar7; - float *extraout_ECX_00; - float *extraout_ECX_01; - float *extraout_ECX_02; - float *extraout_ECX_03; - int extraout_ECX_04; - int extraout_ECX_05; - uint64_t *allocCounter; - Entity_Player *player; - Weapon *pWVar8; - Entity_Player *familiar; - bool bVar9; - float fVar10; - float fVar11; - float fVar12; - undefined3 in_stack_00000009; - undefined3 in_stack_0000000d; - uint32_t uVar13; - TypeDescriptor *pTVar14; - TypeDescriptor *pTVar15; - uint32_t uVar16; - short multiShotParams [14]; - char local_6b; - char local_6a; - uint16_t local_68; - BitSet128 tearFlags; - BitSet128 local_54; - Vector tmpPos; - Vector local_3c; - float angleSin; - uint32_t *local_30; - Weapon *weapon; - Vector local_28; - float local_20; - float local_1c; - float local_18; - uint32_t local_14; - void *local_10; - uint8_t *puStack_c; - uint32_t local_8; - uint32_t *parentRef; - int *targetRef; - - local_8 = 0xffffffff; - puStack_c = &LAB_00b1089d; - local_10 = ExceptionList; - ExceptionList = &local_10; - local_1c = (float)_isInterpolated; - local_30 = GHIDRA_CAST(_isShooting); - weapon = player; - Weapon::Fire(player,aimDirection,isShooting,isInterpolated); - pEVar7 = *GHIDRA_CAST((GHIDRA_CAST(player) + 4)); - _isShooting = pEVar7; - if (pEVar7 == GHIDRA_CAST(0x0)) { -LAB_00a08dcb: - player = GHIDRA_CAST(0x0); - if ((pEVar7 != GHIDRA_CAST(0x0)) && (pEVar7->_type == 1)) goto LAB_00a08dde; -LAB_00a08da6: - _isShooting = GHIDRA_CAST(0x0); - if ((pEVar7 == GHIDRA_CAST(0x0)) || (pEVar7->_type != 3)) goto LAB_00a08dde; - local_14 = *GHIDRA_CAST((GHIDRA_CAST(player) + 0x34)) >> 0x1f; - _isShooting = GHIDRA_CAST(0x0); - familiar = pEVar7; -LAB_00a08e26: - pEVar7 = *GHIDRA_CAST(&pEVar7->_isControlsEnabled); - if (pEVar7 == GHIDRA_CAST(0x0)) goto LAB_00a08e3a; - local_28.y = (float)pEVar7->_markedTarget; - } - else { - if (pEVar7->_type != 1) { - if (pEVar7->_type != 3) goto LAB_00a08dcb; - player = *GHIDRA_CAST(&pEVar7->_isControlsEnabled); - goto LAB_00a08da6; - } - player = pEVar7; -LAB_00a08dde: - local_14 = *GHIDRA_CAST((GHIDRA_CAST(player) + 0x34)) >> 0x1f; - familiar = GHIDRA_CAST(0x0); - bVar3 = (uint8_t)(*GHIDRA_CAST((GHIDRA_CAST(player) + 0x34)) >> 0x1f); - _isInterpolated = GHIDRA_CAST(CONCAT13(bVar3,_isInterpolated)); - if (pEVar7 != GHIDRA_CAST(0x0)) { - local_14 = CONCAT31((int3)(GHIDRA_UINT(player) >> 8),bVar3); - if (pEVar7->_type == 1) { - local_14 = GHIDRA_UINT(bVar3); - local_28.y = (float)pEVar7->_markedTarget; - goto LAB_00a08e3c; - } - if (pEVar7->_type == 3) goto LAB_00a08e26; - } -LAB_00a08e3a: - local_28.y = 0.0; - } -LAB_00a08e3c: - if ((((char)local_14 == '\0') && (GHIDRA_CAST(local_28.y) != GHIDRA_CAST(0x0))) && - (player != GHIDRA_CAST(0x0))) { - bVar3 = Entity_Player::HasCollectible(player,0x18a,0); - pEVar7 = extraout_ECX; - if (bVar3 == 0) goto LAB_00a08e63; - unusedArg = GHIDRA_CAST(CONCAT31((int3)(GHIDRA_UINT(extraout_ECX) >> 8),1)); - } - else { -LAB_00a08e63: - unusedArg = GHIDRA_CAST((GHIDRA_UINT(pEVar7) & 0xffffff00)); - } - iVar5 = *GHIDRA_CAST((GHIDRA_CAST(player) + 0x44)); - local_3c.y = (float)(GHIDRA_INT(player) + 0x44); - _isInterpolated = GHIDRA_CAST(CONCAT13((char)unusedArg,_isInterpolated)); - if (iVar5 != 0) { - if ((char)unusedArg == '\0') { - pVVar6 = GHIDRA_CAST(aimDirection->x); - local_18 = aimDirection->y; - fVar11 = (float)pVVar6 * (float)pVVar6 + local_18 * local_18; - aimDirection = pVVar6; - if (1.0 < fVar11) { - fVar11 = sqrtf(fVar11); - unusedArg = extraout_ECX_00; - if (0.0 < fVar11) { - aimDirection = GHIDRA_CAST(((float)pVVar6 * (1.0 / fVar11))); - local_18 = local_18 * (1.0 / fVar11); - } - } - if (player == GHIDRA_CAST(0x0)) { -LAB_00a08fb1: - fVar11 = local_18; - } - else { - bVar3 = Entity_Player::HasCollectible(player,0x166,0); - unusedArg = extraout_ECX_01; - if (bVar3 == 0) goto LAB_00a08fb1; - bVar3 = Entity_Player::HasCollectible(player,0xf5,0); - unusedArg = extraout_ECX_02; - if (bVar3 != 0) goto LAB_00a08fb1; - local_20 = cos(0.7853982); - fVar11 = sin(0.7853982); - fVar10 = (float)aimDirection * fVar11; - aimDirection = GHIDRA_CAST(((float)aimDirection * local_20 - local_18 * fVar11)); - unusedArg = extraout_ECX_03; - fVar11 = local_18 * local_20 + fVar10; - } - iVar5 = *GHIDRA_CAST((GHIDRA_CAST(player) + 0x44)); - *GHIDRA_CAST((iVar5 + 0x360)) = - (float)aimDirection * 8.0 * *GHIDRA_CAST((iVar5 + 0x39c)) + *GHIDRA_CAST((iVar5 + 0x360)); - *GHIDRA_CAST((iVar5 + 0x364)) = - fVar11 * 8.0 * *GHIDRA_CAST((iVar5 + 0x39c)) + *GHIDRA_CAST((iVar5 + 0x364)); - } - else { - unusedArg = GHIDRA_CAST((iVar5 + 0x33c)); - fVar11 = (GHIDRA_CAST((GHIDRA_INT(local_28.y) + 0x33c)))->x; - fVar10 = (GHIDRA_CAST((GHIDRA_INT(local_28.y) + 0x33c)))->y; - if (familiar != GHIDRA_CAST(0x0)) { - fVar10 = (fVar10 + (familiar->_pos).y) - - *GHIDRA_CAST((*GHIDRA_CAST(&familiar->_isControlsEnabled) + 0x340)); - fVar11 = (fVar11 + (familiar->_pos).x) - - *GHIDRA_CAST((*GHIDRA_CAST(&familiar->_isControlsEnabled) + 0x33c)); - } - *unusedArg = fVar11; - *GHIDRA_CAST((iVar5 + 0x340)) = fVar10; - } - } - if ((*GHIDRA_CAST((GHIDRA_CAST(&(local_1c)) + 0x0))) != '\0') { - ExceptionList = local_10; - return; - } - Weapon::GetMultiShotParams(player,multiShotParams,GHIDRA_INT(unusedArg)); - iVar5 = extraout_ECX_04; - if ((char)local_14 == '\0') { -LAB_00a09039: - rocketCount = multiShotParams[0]; - } - else { - bVar3 = Entity_Player::HasCollectible(player,0x164,0); - iVar5 = extraout_ECX_05; - if (bVar3 == 0) goto LAB_00a09039; - rocketCount = multiShotParams[0] * 2; - } - if (((char)local_30 != '\0') || ((*GHIDRA_CAST((GHIDRA_CAST(&(in_stack_0000000d)) + 0x2))) != '\0')) { - Weapon::SetBlinkTime(player,10,iVar5); - if (((*GHIDRA_CAST((GHIDRA_CAST(player) + 0x44)) == 0) || - ((extraout_AL != '\0' && (*GHIDRA_CAST((*GHIDRA_CAST((GHIDRA_CAST(player) + 0x44)) + 0x173)) != '\0')))) && - ((*GHIDRA_CAST((GHIDRA_CAST(player) + 0xc)) <= 0.0 && *GHIDRA_CAST((GHIDRA_CAST(player) + 0xc)) != 0.0 || - ((char)local_14 != '\0')))) { - local_20 = (float)((rocketCount * 5 + 0x14) * 2); - iVar5 = *GHIDRA_CAST((GHIDRA_CAST(player) + 4)); - if (iVar5 == 0) { - tmpPos.x = g_vectorZero.x; - tmpPos.y = g_vectorZero.y; - } - else { - tmpPos.x = *GHIDRA_CAST((iVar5 + 0x33c)); - tmpPos.y = *GHIDRA_CAST((iVar5 + 0x340)); - } - local_18 = g_vectorOne.x; - local_1c = g_vectorOne.y; - if (familiar != GHIDRA_CAST(0x0)) { - local_18 = g_vectorOne.x * 0.8; - local_1c = g_vectorOne.y * 0.8; - } - if ((*GHIDRA_CAST((GHIDRA_CAST(&(in_stack_0000000d)) + 0x2))) != '\0') { - tmpPos.x = (GHIDRA_CAST((GHIDRA_INT(local_28.y) + 0x33c)))->x; - tmpPos.y = (GHIDRA_CAST((GHIDRA_INT(local_28.y) + 0x33c)))->y; - } - uVar4 = Random(); - mainTarget = Game::Spawn(g_game,1000,0x1e,&tmpPos,&g_vectorZero,*GHIDRA_CAST((GHIDRA_CAST(player) + 4)),0, - uVar4); - (mainTarget->_sprite)._scale.x = local_18; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(mainTarget[1])) + 0x40)))) = GHIDRA_INT(rocketCount); - *GHIDRA_CAST((mainTarget[1]._sprite._filename._buf + 4)) = local_20; - *GHIDRA_CAST((mainTarget[1]._sprite._filename._buf + 8)) = local_20; - (mainTarget->_sprite)._scale.y = local_1c; - if (((*GHIDRA_CAST((GHIDRA_CAST(&(in_stack_0000000d)) + 0x2))) != '\0') && (familiar == GHIDRA_CAST(0x0))) { - mainTarget->_visible = 0; - } - targetRef = GHIDRA_CAST((GHIDRA_INT(player) + 0x44)); - local_28.y = (float)mainTarget; - if (*GHIDRA_CAST((GHIDRA_CAST(player) + 0x44)) != mainTarget) { - if (*GHIDRA_CAST((GHIDRA_CAST(player) + 0x44)) != GHIDRA_CAST(0x0)) { - _isInterpolated = targetRef; - msvc::multiset::erase(&isInterpolated); - } - *targetRef = GHIDRA_INT(mainTarget); - msvc::multiset::insert(targetRef); - } - if (local_6b != '\0') { - uVar4 = Random(); - uVar16 = 0; - pTVar15 = &IsaacRepentancePlus::Entity_Effect::RTTI_Type_Descriptor; - pTVar14 = &IsaacRepentancePlus::Entity::RTTI_Type_Descriptor; - uVar13 = 0; - extraTarget = Game::Spawn(g_game,1000,0x1e,&tmpPos,&g_vectorZero,*GHIDRA_CAST((GHIDRA_CAST(player) + 4)) - ,0,uVar4); - iVar5 = __RTDynamicCast(extraTarget,uVar13,pTVar14,pTVar15,uVar16); - if (*GHIDRA_CAST((iVar5 + 0x3bc)) != 0) { - _isInterpolated = GHIDRA_CAST((iVar5 + 0x3bc)); - msvc::multiset::erase(&isInterpolated); - } - *GHIDRA_CAST((iVar5 + 0x3bc)) = mainTarget; - msvc::multiset::insert(GHIDRA_CAST((iVar5 + 0x3bc))); - *GHIDRA_CAST((iVar5 + 0x45c)) = local_20; - *GHIDRA_CAST((iVar5 + 0x460)) = local_20; - *GHIDRA_CAST((iVar5 + 0xe4)) = local_18; - *GHIDRA_CAST((iVar5 + 0xe8)) = local_1c; - *GHIDRA_CAST((iVar5 + 0x450)) = GHIDRA_INT(rocketCount); - *GHIDRA_CAST((iVar5 + 0x30)) = 1; - } - if (local_6a != '\0') { - _isInterpolated = GHIDRA_CAST(0x2); - do { - uVar4 = Random(); - uVar16 = 0; - pTVar15 = &IsaacRepentancePlus::Entity_Effect::RTTI_Type_Descriptor; - pTVar14 = &IsaacRepentancePlus::Entity::RTTI_Type_Descriptor; - uVar13 = 0; - mainTarget = Game::Spawn(g_game,1000,0x1e,&tmpPos,&g_vectorZero, - *GHIDRA_CAST((GHIDRA_CAST(player) + 4)),0,uVar4); - iVar5 = __RTDynamicCast(mainTarget,uVar13,pTVar14,pTVar15,uVar16); - parentRef = GHIDRA_CAST((iVar5 + 0x3bc)); - if (*GHIDRA_CAST((iVar5 + 0x3bc)) != 0) { - local_30 = parentRef; - msvc::multiset::erase(&local_30); - } - mainTarget = GHIDRA_CAST(local_28.y); - *parentRef = local_28.y; - msvc::multiset::insert(parentRef); - *GHIDRA_CAST((iVar5 + 0x45c)) = local_20; - *GHIDRA_CAST((iVar5 + 0x460)) = local_20; - *GHIDRA_CAST((iVar5 + 0x450)) = GHIDRA_INT(rocketCount); - *GHIDRA_CAST((iVar5 + 0x30)) = _isInterpolated; - _isInterpolated = GHIDRA_CAST((GHIDRA_INT(_isInterpolated) + 1)); - *GHIDRA_CAST((iVar5 + 0xe4)) = local_18; - *GHIDRA_CAST((iVar5 + 0xe8)) = local_1c; - } while (GHIDRA_INT(_isInterpolated) < 4); - } - _isInterpolated = GHIDRA_CAST(GHIDRA_UINT(local_68)); - while (_isInterpolated != GHIDRA_CAST(0x0)) { - uVar4 = Random(); - uVar16 = 0; - pTVar15 = &IsaacRepentancePlus::Entity_Effect::RTTI_Type_Descriptor; - pTVar14 = &IsaacRepentancePlus::Entity::RTTI_Type_Descriptor; - uVar13 = 0; - extraTarget = Game::Spawn(g_game,1000,0x1e,&tmpPos,&g_vectorZero,*GHIDRA_CAST((GHIDRA_CAST(player) + 4)) - ,0,uVar4); - local_28.y = (float)__RTDynamicCast(extraTarget,uVar13,pTVar14,pTVar15,uVar16); - parentRef = GHIDRA_CAST((GHIDRA_INT(local_28.y) + 0x3bc)); - if (*GHIDRA_CAST((GHIDRA_CAST(local_28.y) + 0x3bc)) != 0) { - local_30 = parentRef; - msvc::multiset::erase(&local_30); - } - *parentRef = mainTarget; - msvc::multiset::insert(parentRef); - fVar11 = local_28.y; - *GHIDRA_CAST((GHIDRA_CAST(local_28.y) + 0x45c)) = local_20; - *GHIDRA_CAST((GHIDRA_CAST(local_28.y) + 0x460)) = local_20; - *GHIDRA_CAST((GHIDRA_CAST(local_28.y) + 0xe4)) = local_18; - *GHIDRA_CAST((GHIDRA_CAST(local_28.y) + 0xe8)) = local_1c; - *GHIDRA_CAST((GHIDRA_CAST(local_28.y) + 0x450)) = GHIDRA_INT(rocketCount); - *GHIDRA_CAST((GHIDRA_CAST(local_28.y) + 0x30)) = 4; - uVar4 = Random(); - fVar10 = (float)((double)GHIDRA_INT(uVar4) + __uint_to_double_fixup[-(GHIDRA_INT(uVar4) >> 0x1f)]) * - 2.3283064e-10 * 3.14; - local_30 = GHIDRA_CAST((fVar10 + fVar10)); - angleSin = sin((float)local_30); - uVar4 = Random(); - local_28.y = (float)((double)GHIDRA_INT(uVar4) + __uint_to_double_fixup[-(GHIDRA_INT(uVar4) >> 0x1f)]) * - 2.3283064e-10 * 80.0 + 10.0; - fVar10 = cos((float)local_30); - _isInterpolated = GHIDRA_CAST((GHIDRA_INT(_isInterpolated) - 1)); - *GHIDRA_CAST((GHIDRA_CAST(fVar11) + 0x34c)) = fVar10 * local_28.y; - *GHIDRA_CAST((GHIDRA_CAST(fVar11) + 0x350)) = local_28.y * angleSin; - } - *GHIDRA_CAST((GHIDRA_CAST(player) + 0xc)) = *GHIDRA_CAST((GHIDRA_CAST(player) + 0x10)); - _isInterpolated = GHIDRA_CAST(0x0); - } - } - pWVar8 = GHIDRA_CAST((GHIDRA_INT(player) + 0x44)); - if (*GHIDRA_CAST(pWVar8) == 0) goto LAB_00a09959; - Weapon::get_owner_tear_flags(player,&tearFlags); - maskedFlags = BitSet128::operator_and(&local_54,&tearFlags,&g_tearFlagAttractor); - if ((GHIDRA_INT(maskedFlags->_l) != 0 || *GHIDRA_CAST((GHIDRA_INT(&maskedFlags->_l) + 4)) != 0) || - (GHIDRA_INT(maskedFlags->_h) != 0 || *GHIDRA_CAST((GHIDRA_INT(&maskedFlags->_h) + 4)) != 0)) { - tmpPos.x = *GHIDRA_CAST((*GHIDRA_CAST(pWVar8) + 0x33c)); - tmpPos.y = *GHIDRA_CAST((*GHIDRA_CAST(pWVar8) + 0x340)); - Game::AttractEntities(g_game,&tmpPos,(void *)0x0,(void *)0x0,10.0,250.0); - EntityList::QuerySublist - (GHIDRA_CAST((GHIDRA_INT(g_game->_room) + 0x1218)),GHIDRA_CAST(&local_54),1000,0x1e,-1,0 - ,0); - iVar5 = (*GHIDRA_CAST((GHIDRA_CAST(&(local_54._l)) + 0x4))); - uVar4 = 0; - local_8 = 0; - if ((*GHIDRA_CAST((GHIDRA_CAST(&(local_54._h)) + 0x4))) != 0) { - do { - iVar1 = *GHIDRA_CAST((iVar5 + uVar4 * 4)); - if (*GHIDRA_CAST((iVar1 + 0x3bc)) == *GHIDRA_CAST(pWVar8)) { - tmpPos.x = *GHIDRA_CAST((iVar1 + 0x33c)); - tmpPos.y = *GHIDRA_CAST((iVar1 + 0x340)); - Game::AttractEntities(g_game,&tmpPos,(void *)0x0,(void *)0x0,10.0,250.0); - } - uVar4 = uVar4 + 1; - } while (uVar4 < (*GHIDRA_CAST((GHIDRA_CAST(&(local_54._h)) + 0x4)))); - player = weapon; - } - local_8 = 0xffffffff; - if ((char)local_54._l == '\0') { - if (g_mainHeap == (void *)0x0) { - allocCounter = &g_allocatedBytesNoHeap; - } - else { - allocCounter = GHIDRA_CAST((GHIDRA_INT(g_mainHeap) + 0x30)); - } - if ((*GHIDRA_CAST((GHIDRA_CAST(&(local_54._l)) + 0x4))) != 0) { - uVar4 = *GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(local_54._l)) + 0x4))) + -4)); - qVar2 = *allocCounter; - *GHIDRA_CAST(allocCounter) = GHIDRA_UINT(*allocCounter) - uVar4; - *GHIDRA_CAST((GHIDRA_CAST(allocCounter) + 4)) = - *GHIDRA_CAST((GHIDRA_CAST(allocCounter) + 4)) - GHIDRA_UINT((GHIDRA_UINT(qVar2) < uVar4)); - free(GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(local_54._l)) + 0x4))) + -4))); - } - local_8 = 0xffffffff; - } - } - maskedFlags = BitSet128::operator_and(&local_54,&tearFlags,&g_tearFlagHoming); - if ((GHIDRA_INT(maskedFlags->_l) != 0 || *GHIDRA_CAST((GHIDRA_INT(&maskedFlags->_l) + 4)) != 0) || - (GHIDRA_INT(maskedFlags->_h) != 0 || *GHIDRA_CAST((GHIDRA_INT(&maskedFlags->_h) + 4)) != 0)) { - tmpPos.x = *GHIDRA_CAST((*GHIDRA_CAST(pWVar8) + 0x33c)); - tmpPos.y = *GHIDRA_CAST((*GHIDRA_CAST(pWVar8) + 0x340)); - EntityList::QueryRadius - (GHIDRA_CAST((GHIDRA_INT(g_game->_room) + 0x1218)),GHIDRA_CAST(&local_54),&tmpPos,200.0, - 8); - fVar11 = 999999.0; - uVar4 = 0; - aimDirection = GHIDRA_CAST(0x0); - if ((*GHIDRA_CAST((GHIDRA_CAST(&(local_54._h)) + 0x4))) != 0) { - _isInterpolated = *GHIDRA_CAST(&g_game->_deathmatchManager); - do { - pVVar6 = *GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(local_54._l)) + 0x4))) + uVar4 * 4)); - if ((GHIDRA_INT(_isInterpolated) < 2) || (pVVar6[5].x != 1.4013e-45)) { - fVar10 = pVVar6[5].x; - if ((GHIDRA_INT(fVar10) - 10U < 0x3de) && - (((fVar10 != 4.62428e-44 && (fVar10 != 2.38221e-44)) && (fVar10 != 4.09179e-43)))) { - if (fVar10 == 1.24015e-42) { - bVar9 = pVVar6[5].y == 1.4013e-44; - } - else { - if ((fVar10 == 1.34525e-42) || (fVar10 == 1.35225e-42)) goto LAB_00a0972d; - bVar9 = fVar10 == 3.43318e-43; - } - if (!bVar9) goto LAB_00a096e7; - } -LAB_00a0972d: - iVar5 = *GHIDRA_CAST(local_3c.y); - } - else { -LAB_00a096e7: - if (*GHIDRA_CAST((GHIDRA_INT(&pVVar6[0x2e].x) + 3)) != '\0') goto LAB_00a0972d; - iVar5 = *GHIDRA_CAST(local_3c.y); - fVar12 = *GHIDRA_CAST((iVar5 + 0x340)) - pVVar6[0x68].x; - fVar10 = *GHIDRA_CAST((iVar5 + 0x33c)) - pVVar6[0x67].y; - fVar10 = fVar12 * fVar12 + fVar10 * fVar10; - if (fVar10 < fVar11) { - fVar11 = fVar10; - aimDirection = pVVar6; - } - } - uVar4 = uVar4 + 1; - } while (uVar4 < (*GHIDRA_CAST((GHIDRA_CAST(&(local_54._h)) + 0x4)))); - player = weapon; - if (aimDirection != GHIDRA_CAST(0x0)) { - _isInterpolated = GHIDRA_CAST((aimDirection[0x68].x - *GHIDRA_CAST((iVar5 + 0x340)))); - fVar10 = aimDirection[0x67].y - *GHIDRA_CAST((iVar5 + 0x33c)); - fVar11 = sqrtf((float)_isInterpolated * (float)_isInterpolated + fVar10 * fVar10); - targetRef = _isInterpolated; - if (0.0 < fVar11) { - fVar10 = fVar10 * (1.0 / fVar11); - targetRef = GHIDRA_CAST(((float)_isInterpolated * (1.0 / fVar11))); - } - fVar11 = *GHIDRA_CAST((iVar5 + 0x36c)); - if (fVar11 != 0.0) { - *GHIDRA_CAST((iVar5 + 0x364)) = - (*GHIDRA_CAST((iVar5 + 0x39c)) * (float)targetRef) / fVar11 + *GHIDRA_CAST((iVar5 + 0x364)); - *GHIDRA_CAST((iVar5 + 0x360)) = - (*GHIDRA_CAST((iVar5 + 0x39c)) * fVar10) / fVar11 + *GHIDRA_CAST((iVar5 + 0x360)); - } - } - } - if ((char)local_54._l == '\0') { - if (g_mainHeap == (void *)0x0) { - allocCounter = &g_allocatedBytesNoHeap; - } - else { - allocCounter = GHIDRA_CAST((GHIDRA_INT(g_mainHeap) + 0x30)); - } - if ((*GHIDRA_CAST((GHIDRA_CAST(&(local_54._l)) + 0x4))) != 0) { - uVar4 = *GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(local_54._l)) + 0x4))) + -4)); - qVar2 = *allocCounter; - *GHIDRA_CAST(allocCounter) = GHIDRA_UINT(*allocCounter) - uVar4; - *GHIDRA_CAST((GHIDRA_CAST(allocCounter) + 4)) = - *GHIDRA_CAST((GHIDRA_CAST(allocCounter) + 4)) - GHIDRA_UINT((GHIDRA_UINT(qVar2) < uVar4)); - free(GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(local_54._l)) + 0x4))) + -4))); - } - local_8 = 0xffffffff; - } - pWVar8 = GHIDRA_CAST((GHIDRA_INT(player) + 0x44)); - } - if ((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(((GHIDRA_CAST(player)))) + 0x4)))) == GHIDRA_CAST(0x0)) || - (iVar5 = Entity::GetIntervalTicks - (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(((GHIDRA_CAST(player)))) + 0x4)))), - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(((GHIDRA_CAST(player)))) + 0x10)))),0.0), iVar5 == 0)) - goto LAB_00a09959; - iVar5 = *GHIDRA_CAST(pWVar8); - if (iVar5 == 0) { -LAB_00a098fd: - uVar4 = Random(); - fVar11 = (float)((double)GHIDRA_INT(uVar4) + __uint_to_double_fixup[-(GHIDRA_INT(uVar4) >> 0x1f)]) * - 2.3283064e-10 * 3.14; - fVar11 = fVar11 + fVar11; - local_28.x = cos(fVar11); - local_28.y = sin(fVar11); - pVVar6 = &local_28; - } - else { - fVar11 = *GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(((GHIDRA_CAST(player)))) + 0x4)))) + 0x33c)); - fVar10 = *GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(((GHIDRA_CAST(player)))) + 0x4)))) + 0x340)); - if ((*GHIDRA_CAST((iVar5 + 0x33c)) == fVar11) && (*GHIDRA_CAST((iVar5 + 0x340)) == fVar10)) - goto LAB_00a098fd; - _isInterpolated = GHIDRA_CAST((*GHIDRA_CAST((iVar5 + 0x340)) - fVar10)); - fVar11 = *GHIDRA_CAST((iVar5 + 0x33c)) - fVar11; - local_3c.x = fVar11; - local_3c.y = (float)_isInterpolated; - fVar10 = sqrtf((float)_isInterpolated * (float)_isInterpolated + fVar11 * fVar11); - if (0.0 < fVar10) { - local_3c.y = (1.0 / fVar10) * (float)_isInterpolated; - local_3c.x = (1.0 / fVar10) * fVar11; - } - pVVar6 = &local_3c; - } - Weapon::TriggerTearEffects(player,pVVar6,1); -LAB_00a09959: - if ((*GHIDRA_CAST(pWVar8) != 0) && (*GHIDRA_CAST((*GHIDRA_CAST(pWVar8) + 0x173)) != '\0')) { - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(((GHIDRA_CAST(player)))) + 0xc)))) = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(((GHIDRA_CAST(player)))) + 0x10)))); - if (((char)local_14 != '\0') && (_isShooting != GHIDRA_CAST(0x0))) { - Entity_Player::ResetItemState(_isShooting); - } - } - ExceptionList = local_10; - return; -} - -// 00a099a0 -int Weapon_Rockets::GetMarkedTargetVariant() -{ - void *player = this; - uint8_t isHasMarked; - Entity_Player *player; - - player = *GHIDRA_CAST((GHIDRA_CAST(player) + 4)); - if (player != GHIDRA_CAST(0x0)) { - if (player->_type == 1) goto LAB_00a099be; - if (player->_type == 3) { - player = *GHIDRA_CAST(&player->_isControlsEnabled); - goto LAB_00a099be; - } - } - player = GHIDRA_CAST(0x0); -LAB_00a099be: - isHasMarked = Entity_Player::HasCollectible(player,0x18a,0); - return -GHIDRA_UINT((isHasMarked != 0)) & 0x1e; -} diff --git a/src/active_items.h b/src/active_items.h index 497ed0d..cb3ff0a 100644 --- a/src/active_items.h +++ b/src/active_items.h @@ -61,6 +61,20 @@ struct UseResult bool isRemove = false; }; +// One active item use as its effect runs: the request, the item, and what the effect leaves for the end of the use. +struct ItemUse +{ + Entity_Player& player; + const ActiveUse& request; + ItemConfig_Item* item = nullptr; + UseResult result{}; + int id = 0; + bool isAddEffect = true; + bool isLuaAnimationAllowed = false; + bool isShowAnimation = false; + bool isWispAllowed = false; +}; + // An active item AddCollectible puts in a slot: the item, its charge (negative for its initial or full charge), the // slot and the data the slot keeps. struct ActiveGain diff --git a/src/bomb_explosion.cpp b/src/bomb_explosion.cpp index 8c11508..4b33956 100644 --- a/src/bomb_explosion.cpp +++ b/src/bomb_explosion.cpp @@ -57,8 +57,6 @@ constexpr int CHALLENGE_BLUE_BOMBER = 23; constexpr int CARPET_BLOWN = 1000; constexpr std::array EFFECTS_BLOWN_AWAY = {21, 33, 63, 64, 158, 159}; constexpr int BOMB_EXPLOSION_EFFECT = 1; -constexpr int BOMB_CRATER_EFFECT = 18; -constexpr int FIREWORKS_EFFECT = 104; constexpr int SPECIAL_DAILY_FIREWORKS = 12; constexpr size_t SAVED_EFFECTS_MAX = 128; @@ -327,7 +325,7 @@ void explosion_effects(const Explosion& explosion) if (g_game->dailyChallenge._specialDailyId == SPECIAL_DAILY_FIREWORKS && isFetusBomb) { Entity* fireworks = g_game->Spawn({.position = explosion.position, .subType = 1, .type = ENTITY_EFFECT, - .variant = FIREWORKS_EFFECT, .seed = Random()}); + .variant = EFFECT_FIREWORKS, .seed = Random()}); fireworks->isDead = true; fireworks->Update(); } @@ -340,7 +338,7 @@ Entity* bomb_crater_spawn(const Vector& position, Entity* spawner, float scale) { uint32_t seed = Random(); Entity* crater = g_game->Spawn({.position = position, .spawner = spawner, .type = ENTITY_EFFECT, - .variant = BOMB_CRATER_EFFECT, .seed = seed}); + .variant = EFFECT_BOMB_CRATER, .seed = seed}); crater->sprite.scale = vector_make(scale, scale); crater->Update(); @@ -348,7 +346,7 @@ Entity* bomb_crater_spawn(const Vector& position, Entity* spawner, float scale) while (saved.size() + 1 > SAVED_EFFECTS_MAX) saved.erase(saved.begin()); EntitySaveState& state = saved.emplace_back(); state.type = ENTITY_EFFECT; - state.variant = BOMB_CRATER_EFFECT; + state.variant = EFFECT_BOMB_CRATER; state.targetPosition = position; state.initSeed = crater->initSeed; state.intStorage1 = std::bit_cast(scale); diff --git a/src/boss_ai.h b/src/boss_ai.h index c26d7fd..c9a7055 100644 --- a/src/boss_ai.h +++ b/src/boss_ai.h @@ -136,6 +136,14 @@ enum SpawnerQueryMode std::vector npc_query_spawner_type(int spawnerType, int entityType, SpawnerQueryMode mode); +// Isaac's forms, by variant: Isaac in the Cathedral, ??? in the Chest, and the ??? whose death calls Hush. +enum IsaacVariant +{ + ISAAC_FORM_CATHEDRAL, + ISAAC_FORM_CHEST, + ISAAC_FORM_HUSH +}; + void boss_adversary_update(Entity_NPC& npc); void boss_baby_plum_update(Entity_NPC& npc); void boss_blastocyst_update(Entity_NPC& npc); @@ -170,6 +178,11 @@ void boss_widow_update(Entity_NPC& npc); void boss_satan_update(Entity_NPC& npc); void boss_fallen_update(Entity_NPC& npc); void boss_music_crossfade(); +void boss_isaac_update(Entity_NPC& npc); +void npc_baby_update(Entity_NPC& npc); +void boss_lamb_update(Entity_NPC& npc); +void npc_isaac_fly_update(Entity_NPC& npc); +void boss_hush_update(Entity_NPC& npc); // Gemini's baby, the variant its twin is tied to. constexpr int GEMINI_BABY = 10; diff --git a/src/boss_hush.cpp b/src/boss_hush.cpp new file mode 100644 index 0000000..0748857 --- /dev/null +++ b/src/boss_hush.cpp @@ -0,0 +1,1327 @@ +#include "boss_ai.h" +#include "entity_player.h" +#include "loot_list.h" +#include "npc_caves.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include +#include +#include + +// Hush's attacks (his states besides idle and turning concave): gapers from his mouth, flies, a spit of three bursting +// shots, curving shots from his faces, lasers, red creep (no roll picks it), face volleys, and three ways of sliding +// about concave: to a spot, to spots with his faces firing, or after his target with them firing. +enum HushAttack +{ + HUSH_GAPERS = 13, + HUSH_FLIES = 100, + HUSH_SPIT = 200, + HUSH_CURVES = 300, + HUSH_LASERS = 400, + HUSH_CREEP = 500, + HUSH_VOLLEYS = 600, + HUSH_SLIDE = 700, + HUSH_SLIDE_VOLLEYS = 710, + HUSH_CHASE_VOLLEYS = 720 +}; + +// His minions and the effects he leaves, by type and variant. +constexpr int HUSH_GAPER_VARIANT = 3; +constexpr int HUSH_LASER_VARIANT = 96; +constexpr int HUSH_BEAM_VARIANT = 101; + +// Which way his face looks (i1), indexing his face animations. +constexpr std::array FACE_VANISH = {"FaceVanishFromLeft", "FaceVanishFromUp", "FaceVanishFromRight", + "FaceVanishFromDown"}; +constexpr std::array FACE_APPEAR = {"FaceAppearLeft", "FaceAppearUp", "FaceAppearRight", + "FaceAppearDown"}; +constexpr std::array FACE_ATTACK = {"AttackLoopLeft", "AttackLoopUp", "AttackLoopRight", + "AttackLoopDown"}; +constexpr int FACE_DOWN = 3; + +// He rises 260 down or lower, drawn behind everything and untouchable while concave, and slides at 2 toward his spot. +constexpr float HUSH_TOP = 260; +constexpr float HUSH_BURIED_Z = 8000; +constexpr float HUSH_SLIDE_SPEED = 2; +constexpr float HUSH_SPOT_MARGIN = 1.3f; + +// His sprite is drawn at 0.65, his faces' nulls 23 below his center. +constexpr float HUSH_SPRITE_SCALE = 0.65f; +constexpr float HUSH_FACE_DROP = 23; + +// He grows restless (v1.x) a thirtieth a frame while every player is 400 away, calming by 0.99 a frame within. He +// turns concave at each fifth of his health lost, up to four times. Dying he shakes 20 and roars, taking every boss +// enemy and shot with him. +constexpr float RESTLESS_REACH = 400; +constexpr float RESTLESS_CALM = 0.99f; +constexpr float RESTLESS_RATE = 30; +constexpr float PHASE_FIRST = 0.8f; +constexpr float PHASE_STEP = 0.2f; +constexpr float PHASE_LAST = 4; +constexpr int HUSH_DEATH_SHAKE = 20; +constexpr int HUSH_ROAR_DELAY = 60; +constexpr float ROAR_PITCH_MIN = 0.8f; +constexpr float ROAR_PITCH_RANGE = 0.4f; + +// Shots passing his top half draw over him: those within 120 left to 138 right and 146 up to 69 down of his center, +// lifted by how far above him they are plus 20. +constexpr float SHOT_LAYER_LEFT = 120; +constexpr float SHOT_LAYER_RIGHT = 138.46155f; +constexpr float SHOT_LAYER_TOP = 146.15385f; +constexpr float SHOT_LAYER_BOTTOM = 69.230774f; +constexpr float SHOT_LAYER_LIFT = 20; + +// Popping out he shakes 15, eats the boils he touches (healing twice their health) and throws players 20 and gapers 3. +constexpr int POP_SHAKE = 15; +constexpr float POP_PLAYER_PUSH = 20; +constexpr float POP_GAPER_PUSH = 3; +constexpr float BOIL_HEAL_SCALE = 2; + +// Idle he waits 30 frames (60 after a spit), wiggling or drifting down to the room's middle on his first phase, then +// one roll in 2 at each wiggle's start picks an attack, at once below half a percent of his health. +constexpr int IDLE_WAIT = 30; +constexpr int SPIT_WAIT = 60; +constexpr float DRIFT_DOWN = 2; +constexpr float DESPERATE_HEALTH = 0.005f; + +// The attack weights: volleys 200 (25 after volleys or a volley slide), flies 200 (50 after flies), curves 200, gapers +// 100, the volley slide 100 (25 after one), the chase 666666 once restless past 12, the spit 100 (25 after one), +// lasers 250 (50 after lasers, 2250 after a phase change). +constexpr int WEIGHT_VOLLEYS = 200; +constexpr int WEIGHT_VOLLEYS_AGAIN = 25; +constexpr int WEIGHT_FLIES = 200; +constexpr int WEIGHT_FLIES_AGAIN = 50; +constexpr int WEIGHT_CURVES = 200; +constexpr int WEIGHT_GAPERS = 100; +constexpr int WEIGHT_SLIDE = 100; +constexpr int WEIGHT_SLIDE_AGAIN = 25; +constexpr int WEIGHT_CHASE = 666666; +constexpr float CHASE_RESTLESS = 12; +constexpr int WEIGHT_SPIT = 100; +constexpr int WEIGHT_SPIT_AGAIN = 25; +constexpr int WEIGHT_LASERS = 250; +constexpr int WEIGHT_LASERS_AGAIN = 50; +constexpr int WEIGHT_LASERS_AFTER_TURN = 2000; +constexpr int GAPER_CROWD = 2; +constexpr RNG HUSH_RNG = {0, 5, 9, 7}; +constexpr int SLIDE_LEGS_MASK = 0xf; +constexpr int SLIDE_LEGS_MARK = 0x10; +constexpr int CURVE_REPEAT_PICKS = 3; +constexpr float FACE_ROAR_VOLUME = 0.5f; + +// The face volleys: three faces, each a table of up to 16 rings of shots at its own period and offset, rebuilt each +// frame from i2's seed. 1.2 shots of 2 damage from 5 up, floating, every 7 frames, 5 at 5, unless a pattern changes it. +// The attack lasts 150 frames. +constexpr int FACE_COUNT = 3; +constexpr int FACE_VOLLEY_LIMIT = 16; +constexpr int FACE_MODES = 3; +constexpr float VOLLEY_HEIGHT = 5; +constexpr float VOLLEY_FALL_SPEED = -2; +constexpr float VOLLEY_FALL_ACCEL = -0.09f; +constexpr float VOLLEY_SCALE = 1.2f; +constexpr float VOLLEY_DAMAGE = 2; +constexpr int VOLLEYS_FRAMES = 150; +constexpr float FACE_DEPTH = 20; +constexpr float FACE_DEPTH_UP = 30; +constexpr std::array, FACE_COUNT> FACE_TINTS = {{{0.4f, 0.2f, 0}, {0, 0.2f, 0.4f}, {0.2f, 0.2f, 0}}}; + +// The volley patterns, with each face's turn spread across the active ones: aimed single shots speeding up or slowing, +// a turning fan of 4 to 2, an aimed arc of 16 to 8, two curving rings, a decelerating ring turning into a curve, a +// near ring with a gap, and a turning curving ring of 16 to 8. +constexpr float AIMED_SPEED = 7; +constexpr float FAN_SPIN = 4.3039823f; +constexpr float FAN_STEP = 0.06283186f; +constexpr std::array FAN_COUNTS = {4, 3, 2}; +constexpr std::array FAN_PERIODS = {20, 25, 30}; +constexpr std::array RING_COUNTS = {20, 16, 12}; +constexpr std::array SPIRAL_COUNTS = {5, 4, 3}; +constexpr std::array WIDE_COUNTS = {16, 12, 8}; +constexpr float ARC_DEPTH = 7; +constexpr int ARC_PERIOD = 90; +constexpr float RING_SPIN = 0.31415927f; +constexpr float VOLLEY_RING_CURVE = 0.003f; +constexpr float VOLLEY_RING_SPEED = 4; +constexpr float RING_FALL = -0.085f; +constexpr int RING_PERIOD = 60; +constexpr int RING_SECOND_DELAY = 30; +constexpr float SPIRAL_SPIN = 0.6911504f; +constexpr float SPIRAL_ACCELERATION = 1.03f; +constexpr float SPIRAL_SPEED = 6; +constexpr int SPIRAL_CHANGE_FRAMES = 105; +constexpr int SPIRAL_PERIOD = 15; +constexpr int GAP_COUNT = 60; +constexpr std::array GAP_PERIODS = {80, 120, 160}; +constexpr int GAP_TRIES = 10; +constexpr float GAP_TURN = 90; +constexpr float GAP_REACH = 120; +constexpr float GAP_MARGIN = 20; +constexpr float GAP_DOT_LIMIT = -0.94f; +constexpr float GAP_SPEED = 4; +constexpr float SWIRL_SPEED = 6; +constexpr float SWIRL_CURVE = 0.02f; +constexpr float SWIRL_FALL = -0.07f; +constexpr int SWIRL_PERIOD = 90; +constexpr float VOLLEY_SPIN_PERIOD = 30; + +// The spit: three 3x bursting shots from his faces on frame 10, up left, up right and down. +constexpr int SPIT_FRAME = 10; +constexpr float SPIT_SCALE = 3; +constexpr float HUSH_SPIT_FALL_ACCEL = -0.2f; +constexpr float HUSH_SPIT_FALL_SPEED = 3.2f; +constexpr float HUSH_SPIT_DEPTH = 20; +static const std::array SPIT_VELOCITIES = {vector_make(-1, -1.5f), vector_make(1, -1.5f), + vector_make(0, 1)}; + +// The curves: every 7 frames each face fires a 1.5 accelerating shot at 6 into one of three spreads, the outer two +// curving one way and then wiggling the other after 32 to 80 frames, for 60 to 179 frames, 1 to 3 times running. +constexpr float CURVE_SPEED = 6; +constexpr float CURVE_SCALE = 1.5f; +constexpr float CURVE_ACCELERATION = 1.006f; +constexpr float CURVE_FALL = -0.18f; +constexpr float CURVE_FALL_UP = -0.17f; +constexpr int CURVE_INTERVAL = 7; +constexpr float CURVE_STRENGTH = 0.0026f; +constexpr float CURVE_STRENGTH_SIDE = 0.0014f; +constexpr int CURVE_LOOP_MIN = 60; +constexpr int CURVE_LOOP_RANGE = 120; +constexpr std::array, 3> CURVE_SPREADS = { + {{-1.0471976f, 1.0471976f, 0}, {-0.83775806f, 0.83775806f, 0.13962634f}, {-0.6108653f, 0.6108653f, -0.13962634f}}}; +constexpr std::array CURVE_CHANGES = {52, 40, 32}; +constexpr std::array CURVE_CHANGES_SIDE = {80, 68, 56}; + +// The gapers: 12 to 27 of them, one roll in 4 a frame, thrown from his mouth 7 toward a spot below him. Delirium's +// have 10 health. +constexpr int GAPERS_MIN = 12; +constexpr float GAPER_SPREAD = 8; +constexpr float GAPER_SPREAD_LEFT = 3; +constexpr float GAPER_AIM_SPREAD = 27; +constexpr float GAPER_AIM_LEFT = 17; +constexpr float GAPER_AIM_DROP = 64.61539f; +constexpr float GAPER_THROW = 7; +constexpr float HUSH_GAPER_SPEED = 3; +constexpr float DELIRIUM_GAPER_HEALTH = 10; + +// The lasers: a shake and a charge on frame 3, two beams from his eyes, then wiggling rings of 5 from his mouth every +// 30 frames and two lasers that hunt his target, alive 60 to 179 frames, gone 10 frames before the beams end. +constexpr int LASER_CHARGE_FRAME = 3; +constexpr int LASER_CHARGE_SHAKE = 10; +constexpr int LASER_SOUND_DELAY = 30; +constexpr int LASER_START_SHAKE = 20; +constexpr int LASER_DELAY_MIN = 10; +constexpr int LASER_DELAY_RANGE = 10; +constexpr float BEAM_DEPTH = 1000; +constexpr int MOUTH_LAYER = 2; +constexpr int MOUTH_INTERVAL = 30; +constexpr float MOUTH_SCALE = 1.5f; +constexpr float MOUTH_FALL_ACCEL = -0.075f; +constexpr float MOUTH_FALL_SPEED = -3.2f; +constexpr float MOUTH_DEPTH = 60; +constexpr int MOUTH_WIGGLE_RANGE = 15; +static const Vector MOUTH_RING = vector_make(3, 5); +constexpr int HUNT_MIN = 60; +constexpr int HUNT_RANGE = 120; +constexpr int BEAMS_END_FRAME = 10; + +// The creep: from frame 4 to 20, red creep 2 to 3 big near a random wall, up to 60 out, with a shake of 4. +constexpr int CREEP_FIRST_FRAME = 4; +constexpr int CREEP_LAST_FRAME = 20; +constexpr int CREEP_SOUND_DELAY = 20; +constexpr float CREEP_REACH = 60; +constexpr float CREEP_SCALE_MIN = 2; +constexpr int CREEP_SHAKE = 4; + +// Sliding concave: while one is near he pops back out. A turn ends once few of his shots are left (after 30 frames, +// or 180 at most). A slide ends at its spot or with few gapers, a volley slide at each spot (or after 90 frames), and +// one roll in 8 every 10 frames while moving he leaves a boil 30 behind. +constexpr float POP_REACH_SCALE = 0.75f; +constexpr int TURN_MIN_FRAMES = 30; +constexpr int TURN_MAX_FRAMES = 180; +constexpr int TURN_SHOT_ODDS = 10; +constexpr float SLIDE_ARRIVED = 10; +constexpr int SLIDE_VOLLEY_FRAMES = 90; +constexpr int BOIL_SPACING = 10; +constexpr int BOIL_ODDS_MASK = 7; +constexpr float BOIL_MIN_SPEED = 0.5f; +constexpr int BOIL_CROWD = 10; +constexpr float BOIL_BEHIND = 30; +constexpr float BOIL_TURN = 90; +constexpr int BOIL_POOF_SUBTYPE = 3; + +// The flies: a ring of up to 10 about him (group 1, shapes 2 and 6, his size plus 40 out), or a swarm of their own +// group heading off 20 degrees from his target at 2 (shapes 1 to 6, 80 out), homing or not. One roll in 3 a frame he +// coughs up 1 to 4, flung at 30 from 10 above him, while the group has fewer than 20. +constexpr int FLY_RING = 0; +constexpr int FLY_SWARM = 1; +constexpr int FLY_HOMING_SWARM = 2; +constexpr int FLY_WEIGHT = 100; +constexpr int FLY_RING_GROUP = 1; +constexpr size_t HUSH_FLY_RING_LIMIT = 10; +constexpr int FLY_RNG_SKIP = 10; +constexpr float FLY_HEADING = 2; +constexpr float FLY_TURN = 0.34906584f; +constexpr int FLY_SHAPES = 6; +constexpr int FLY_RING_FIRST_SHAPE = 2; +constexpr int FLY_RING_SECOND_SHAPE = 6; +constexpr int FLY_SWARM_REACH = 80; +constexpr float FLY_RING_REACH = 40; +constexpr int FLY_SPAWN_ODDS = 3; +constexpr size_t FLY_GROUP_LIMIT = 20; +constexpr int FLY_COUGH_DELAY = 30; +constexpr float FLY_COUGH_PITCH = 0.3f; +constexpr float FLY_MOUTH_RISE = 10; +constexpr float FLY_MOUTH_REACH = 9.5f; +constexpr float FLY_THROW = 30; + +// One ring a face fires in the face volleys: every period frames from its offset, count shots at speed. +struct FaceVolley +{ + ProjectileParams params; + float speed = 5; + int count = 5; + int offset = 0; + int period = 7; +}; + +// The three faces' volleys for a frame, built from i2's seed: each face's rings and the pattern it picked (-1 quiet). +struct FaceVolleys +{ + std::array volleys; + std::array counts = {1, 1, 1}; + std::array patterns = {-1, -1, -1}; +}; + +// The entities his frame looks at: his gapers and boils, and his hunting lasers and eye beams. +struct HushSurroundings +{ + std::vector gapers; + std::vector boils; + std::vector lasers; + std::vector beams; +}; + +static bool is_concave_state(int state) +{ + return state == NPC_STATE_SPECIAL || state == HUSH_SLIDE || state == HUSH_SLIDE_VOLLEYS || + state == HUSH_CHASE_VOLLEYS; +} + +static bool anim_is(const Entity_NPC& npc, std::string_view name) +{ + const AnimationData* data = npc.sprite.animState.animData; + return data && data->name == name; +} + +// Where one of his faces is, from its null, as his shots leave it. +static Vector face_offset(const NullFrame& face) +{ + return vector_make(face.pos.x / HUSH_SPRITE_SCALE, face.pos.y / HUSH_SPRITE_SCALE + HUSH_FACE_DROP); +} + +// A face's null in his current frame, or none. +static const NullFrame* face_null(Entity_NPC& npc, int face) +{ + if (!npc.sprite.animState.animData) return nullptr; + return npc.sprite.animState.GetNullFrameById(face); +} + +// Ends an attack: idle again for a while, remembering it. +static void idle_return(Entity_NPC& npc, int wait) +{ + npc.i2 = npc.state; + npc.state = NPC_STATE_IDLE; + npc.stateFrame = wait; +} + +// Back out of the floor: convex and idle where he is. +static void pop_out(Entity_NPC& npc) +{ + npc.sprite.Play("BecomeConvex"); + npc.state = NPC_STATE_IDLE; + npc.stateFrame = IDLE_WAIT; + npc.targetPosition = npc.pos; +} + +// The first update: he rises from the floor, low enough in the room, untouchable while he does, with a low roar. +static void hush_init(Entity_NPC& npc) +{ + npc.pos.y = std::max(npc.pos.y, HUSH_TOP); + npc.targetPosition = npc.pos; + npc.stateFrame = 0; + npc.i1 = FACE_DOWN; + npc.state = NPC_STATE_APPEAR_CUSTOM; + npc_anim_loop(npc.sprite, "Appear"); + npc.ClearEntityFlags(FLAG_APPEAR); + npc.entityCollisionClass = ENTCOLL_ENEMIES; + npc.sortingLayer = SORTING_BACKGROUND; + npc.isInvincible = true; + npc.renderZOffset = HUSH_BURIED_Z; + npc_sound_play(SOUND_HUSH_LOW_ROAR, 1, 2, 1); +} + +// Rising: the camera fixes on him, and he idles once risen. +static void appear_update(Entity_NPC& npc) +{ + npc_anim_loop(npc.sprite, "Appear"); + g_game->room->camera->SetFocusPosition(npc.pos); + if (!npc_anim_is_done(npc)) return; + + npc.state = NPC_STATE_IDLE; + npc_anim_loop(npc.sprite, "Idle"); +} + +// Dying: three roars and a shake, and every boss enemy and shot in the room goes with him (only Delirium's own for +// Delirium's form, its boils spared). +static void hush_die(Entity_NPC& npc) +{ + npc.AddEntityFlags(FLAG_NO_STATUS_EFFECTS); + npc.RemoveStatusEffects(); + game_shake_screen(HUSH_DEATH_SHAKE); + for (int sound : {SOUND_HUSH_LOW_ROAR, SOUND_HUSH_ROAR, SOUND_HUSH_GROWL}) + npc_sound_play(sound, 1, HUSH_ROAR_DELAY, random_unit() * ROAR_PITCH_RANGE + ROAR_PITCH_MIN); + + bool isDelirium = npc.HasEntityFlags(FLAG_DELIRIUM_FORM); + for (Entity* entity : std::vector(g_game->room->entityList.updateEL)) + { + if (isDelirium && (!entity->HasEntityFlags(FLAG_DELIRIUM_FORM) || entity->type == ENTITY_HUSH_BOIL)) continue; + if (entity->is_valid_boss_enemy()) entity->Kill(EntityRef(&npc)); + if (entity->type == ENTITY_PROJECTILE) entity->isDead = true; + } +} + +// Shots passing in front of his top half draw over him. +static void shots_layer(Entity_NPC& npc) +{ + float left = npc.pos.x - SHOT_LAYER_LEFT; + float right = npc.pos.x + SHOT_LAYER_RIGHT; + float top = npc.pos.y - SHOT_LAYER_TOP; + float bottom = npc.pos.y + SHOT_LAYER_BOTTOM; + for (Entity* shot : entity_query(ENTITY_PROJECTILE, -1)) + { + float depth = 0; + Vector drawn = vector_add(shot->pos, shot->posOffset); + bool isOver = drawn.x >= left && drawn.x <= right && drawn.y >= top && drawn.y <= bottom; + if (shot->pos.y < npc.pos.y && isOver) depth = npc.pos.y - shot->pos.y + SHOT_LAYER_LIFT; + shot->renderDepthOffset = depth; + } +} + +// Buried while concave, back in the room otherwise (unless still becoming convex). +static void layer_update(Entity_NPC& npc) +{ + if (is_concave_state(npc.state)) + { + npc.sortingLayer = SORTING_BACKGROUND; + npc.isInvincible = true; + npc.renderZOffset = HUSH_BURIED_Z; + return; + } + bool isRising = npc.sprite.animState.isPlaying && anim_is(npc, "BecomeConvex"); + if (npc.state == NPC_STATE_APPEAR_CUSTOM || isRising) return; + npc.sortingLayer = SORTING_NORMAL; + npc.isInvincible = false; + npc.renderZOffset = 0; +} + +// Popping out of the floor: solid again, he eats the boils he touches and throws back players and gapers. +static void pop_events_update(Entity_NPC& npc) +{ + if (!npc.sprite.animState.animData) return; + + if (npc.sprite.IsEventTriggered("PopOut")) + { + npc.entityCollisionClass = ENTCOLL_ALL; + npc.sortingLayer = SORTING_NORMAL; + npc.isInvincible = false; + npc.renderZOffset = 0; + npc_sound_play(SOUND_SKIN_PULL, 1, 2, 1); + game_shake_screen(POP_SHAKE); + for (Entity* entity : entity_query_radius(npc.pos, npc.size, QUERY_ALL)) + { + Vector away = vector_normalized(vector_sub(entity->pos, npc.pos)); + if (entity->type == ENTITY_HUSH_BOIL) + { + entity->Kill(EntityRef(&npc)); + if (!npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + npc.health = std::min(entity->maxHitPoints * BOIL_HEAL_SCALE + npc.health, npc.maxHitPoints); + } + else if (entity->type == ENTITY_PLAYER) npc_push(*entity, vector_scale(away, POP_PLAYER_PUSH)); + else if (entity->type == ENTITY_HUSH_GAPER) npc_push(*entity, vector_scale(away, POP_GAPER_PUSH)); + } + } + if (npc.sprite.animState.animData && npc.sprite.IsEventTriggered("SkinPull")) + { + npc_sound_play(SOUND_SKIN_PULL, 1, 2, 1); + game_shake_screen(POP_SHAKE); + } +} + +// Restlessness, his phase from his health (turning concave as it rises), and his slide toward his spot. His phase. +static int phase_update(Entity_NPC& npc) +{ + Entity_Player* nearest = game_nearest_player(npc.pos); + if (vector_length(vector_sub(npc.pos, nearest->pos)) <= RESTLESS_REACH) + npc.v1.x *= npc_friction_scaled(RESTLESS_CALM, npc.speedMultiplier); + else npc.v1.x += npc.speedMultiplier / RESTLESS_RATE; + + float healthLeft = npc.health / npc.maxHitPoints; + if (PHASE_FIRST - npc.v1.y * PHASE_STEP >= healthLeft && npc.v1.y < PHASE_LAST) + { + npc.v1.y += 1; + npc.state = NPC_STATE_SPECIAL; + npc_anim_loop(npc.sprite, "TurnConcave"); + npc_sound_play(SOUND_HUSH_GROWL, 1, 2, 1); + npc.stateFrame = 0; + } + + npc.velocity = vector_sub(npc.targetPosition, npc.pos); + if (vector_length(npc.velocity) > HUSH_SLIDE_SPEED) npc.velocity = vector_resized(npc.velocity, HUSH_SLIDE_SPEED); + return (int)npc.v1.y; +} + +// The attack roll's weights, by his phase and his last attack. +static WeightedOutcomePicker attack_weights(Entity_NPC& npc, int phase, int gapers) +{ + WeightedOutcomePicker picker; + int last = npc.i2; + bool isDelirium = npc.HasEntityFlags(FLAG_DELIRIUM_FORM); + bool isAfterVolleys = last == HUSH_VOLLEYS || last == HUSH_SLIDE_VOLLEYS || last == HUSH_CHASE_VOLLEYS; + if (phase < 3) picker.AddOutcomeWeight(HUSH_VOLLEYS, isAfterVolleys ? WEIGHT_VOLLEYS_AGAIN : WEIGHT_VOLLEYS); + if (phase >= 1 && phase <= 3 && !isDelirium) + picker.AddOutcomeWeight(HUSH_FLIES, last == HUSH_FLIES ? WEIGHT_FLIES_AGAIN : WEIGHT_FLIES); + if (phase > 1) + { + if (last != HUSH_CURVES) picker.AddOutcomeWeight(HUSH_CURVES, WEIGHT_CURVES); + bool isAfterMouth = last != HUSH_CURVES && (last == HUSH_GAPERS || last == HUSH_SLIDE || last == HUSH_SLIDE_VOLLEYS); + bool isBlocked = isAfterMouth || last == HUSH_CHASE_VOLLEYS || gapers > GAPER_CROWD; + if ((!isBlocked || isDelirium) && (!isDelirium || gapers == 0)) + picker.AddOutcomeWeight(HUSH_GAPERS, WEIGHT_GAPERS); + } + if (phase > 2) + { + bool isAfterSlide = last == HUSH_SLIDE_VOLLEYS || last == HUSH_CHASE_VOLLEYS; + picker.AddOutcomeWeight(HUSH_SLIDE_VOLLEYS, isAfterSlide ? WEIGHT_SLIDE_AGAIN : WEIGHT_SLIDE); + if (npc.v1.x > CHASE_RESTLESS) picker.AddOutcomeWeight(HUSH_CHASE_VOLLEYS, WEIGHT_CHASE); + picker.AddOutcomeWeight(HUSH_SPIT, last == HUSH_SPIT ? WEIGHT_SPIT_AGAIN : WEIGHT_SPIT); + } + if (phase > 3 && !isDelirium) + { + picker.AddOutcomeWeight(HUSH_LASERS, last == HUSH_LASERS ? WEIGHT_LASERS_AGAIN : WEIGHT_LASERS); + if (last == NPC_STATE_SPECIAL) picker.AddOutcomeWeight(HUSH_LASERS, WEIGHT_LASERS_AFTER_TURN); + } + return picker; +} + +// Picks his next attack and starts it. +static void attack_pick(Entity_NPC& npc, int phase, int gapers) +{ + WeightedOutcomePicker picker = attack_weights(npc, phase, gapers); + RNG rng = HUSH_RNG; + rng._seed = Random() | 1; + npc.state = picker.PickOutcome(rng); + + switch (npc.state) + { + case HUSH_FLIES: + npc_anim_loop(npc.sprite, "Tell1"); + npc.i2 = (int)(Random() | 1); + return; + case HUSH_SLIDE_VOLLEYS: + case HUSH_CHASE_VOLLEYS: + { + npc.sprite.Play("TurnConcave"); + npc.targetPosition = g_game->room->GetRandomPosition(npc.size * HUSH_SPOT_MARGIN); + npc.i2 = (int)((Random() & ~SLIDE_LEGS_MASK) | SLIDE_LEGS_MARK); + uint32_t legs = npc.state == HUSH_CHASE_VOLLEYS ? (Random() & 1) + 1 : Random() % 3; + npc.i2 += (int)legs; + return npc_sound_play(SOUND_HUSH_GROWL, 1, 2, 1); + } + case HUSH_SPIT: + npc.sprite.Play("Spit"); + return npc_sound_play(SOUND_HUSH_ROAR, 1, 2, 1); + case HUSH_CURVES: + { + npc.sprite.Play(FACE_VANISH[npc.i1]); + float pitch = random_unit() * ROAR_PITCH_RANGE + ROAR_PITCH_MIN; + npc_sound_play(SOUND_HUSH_LOW_ROAR, FACE_ROAR_VOLUME, 2, pitch); + npc.i2 = (int)(Random() % CURVE_REPEAT_PICKS) + 1; + return; + } + case HUSH_VOLLEYS: + { + npc.sprite.Play(FACE_VANISH[npc.i1]); + npc.i2 = (int)(Random() | 1); + float pitch = random_unit() * ROAR_PITCH_RANGE + ROAR_PITCH_MIN; + return npc_sound_play(SOUND_HUSH_LOW_ROAR, FACE_ROAR_VOLUME, 2, pitch); + } + case HUSH_LASERS: + return npc.sprite.Play("LaserStart"); + case HUSH_GAPERS: + return npc.sprite.Play("OpenMouth"); + case HUSH_CREEP: + return npc.sprite.Play("Puffed"); + } +} + +// Idle: his face settles back down, he wiggles (or drifts down to the middle on his first phase), and at a wiggle's +// start rolls for an attack once his wait is over. +static void idle_update(Entity_NPC& npc, int ticks, int phase, int gapers) +{ + if (npc.stateFrame > 0) npc.stateFrame = std::max(npc.stateFrame - ticks, 0); + + const AnimationState& anim = npc.sprite.animState; + if (anim_is(npc, FACE_VANISH[npc.i1])) + { + if (!anim.isPlaying) + { + npc.i1 = FACE_DOWN; + npc_anim_loop(npc.sprite, "FaceAppearDown"); + } + } + else if (!anim.animData || !anim.isPlaying) + { + bool isDrifting = phase == 1 && npc.targetPosition.y < Room::GetCenterPos().y; + npc_anim_loop(npc.sprite, isDrifting ? "Moving" : "Wiggle"); + } + else if (anim_is(npc, "Moving")) + { + npc.targetPosition.y += DRIFT_DOWN; + if (Room::GetCenterPos().y <= npc.targetPosition.y) npc_anim_loop(npc.sprite, "Wiggle"); + } + + float healthLeft = npc.health / npc.maxHitPoints; + bool isReady = npc.stateFrame < 1 || healthLeft < DESPERATE_HEALTH; + if (!isReady || !anim.isPlaying || !anim_is(npc, "Wiggle")) return; + if ((int)std::floor(anim.animFrame) != 0) return; + if ((Random() & 1) == 0 || healthLeft < DESPERATE_HEALTH) attack_pick(npc, phase, gapers); +} + +// What a face's pattern builds from: the face, how many faces fire (mode 1 one, 2 the other two, 3 all), its turn +// among them, his phase, and the aim from it at his target. +struct FaceAim +{ + Vector aim{}; + float angle = 0; + int face = 0; + int mode = 1; + int phase = 0; + int turn = 0; +}; + +// The rings of an active face, by the pattern it picks among those of his phase. +static void face_pattern_build(Entity_NPC& npc, FaceVolleys& faces, RNG& rng, const FaceAim& f) +{ + int first = f.phase == 1 ? 1 : f.phase == 2 ? 3 : 0; + int last = f.phase == 1 ? 5 : f.phase == 2 ? 6 : 3; + int pattern = (int)rng.RandomInt((uint32_t)(last - first + 1)) + first; + faces.patterns[f.face] = pattern; + FaceVolley* volleys = &faces.volleys[f.face * FACE_VOLLEY_LIMIT]; + int& count = faces.counts[f.face]; + int mode = f.mode - 1; + float frame = (float)npc.stateFrame; + + switch (pattern) + { + case 0: + { + count = 6 - f.mode; + int half = count / 2; + int period = (count + half) * (f.mode * 2 + 2); + for (int i = 0; i < count; i++) + { + FaceVolley& volley = volleys[i]; + volley.params.circleAngle = f.angle; + volley.count = 1; + volley.speed = AIMED_SPEED; + if (f.face == 0) volley.params.bulletFlags |= PROJECTILE_ACCELERATE; + else if (f.face == 1) volley.params.bulletFlags |= PROJECTILE_DECELERATE; + volley.period = period; + volley.offset = period / f.mode * f.turn + period / (count + half) * i; + } + return; + } + case 1: + { + count = 4; + volleys[0].params.circleAngle = (float)(f.face * 2) * PI_F / (float)f.mode + frame * FAN_SPIN / VOLLEY_SPIN_PERIOD; + bool isFlipped = f.face == 2 ? (rng.Next() & 1) != 0 : f.face == 1; + for (int i = 0; i < count; i++) + { + FaceVolley& volley = volleys[i]; + if (i > 0) volley.params.circleAngle = volleys[i - 1].params.circleAngle - FAN_STEP; + volley.count = FAN_COUNTS[mode]; + volley.period = FAN_PERIODS[mode]; + volley.offset = volley.period / f.mode * f.turn + i * 2; + } + if (isFlipped) + for (int i = 0; i < count; i++) volleys[i].params.circleAngle *= -1; + return; + } + case 2: + count = WIDE_COUNTS[mode]; + for (int i = 0; i < count; i++) + { + float across = (float)i / (float)(count - 1) * 2 - 1; + float depth = 1 - across * across + ARC_DEPTH; + volleys[i].speed = std::sqrt(across * across + depth * depth); + volleys[i].params.circleAngle = std::atan2(across, depth) + f.angle; + volleys[i].count = 1; + volleys[i].period = ARC_PERIOD; + volleys[i].offset = ARC_PERIOD / f.mode * f.turn; + } + return; + case 3: + count = 2; + for (int i = 0; i < count; i++) + { + FaceVolley& volley = volleys[i]; + volley.count = RING_COUNTS[mode]; + volley.params.circleAngle = frame * RING_SPIN / VOLLEY_SPIN_PERIOD; + volley.params.curvingStrength = VOLLEY_RING_CURVE; + volley.params.bulletFlags |= (i == 0 ? PROJECTILE_CURVE_LEFT : PROJECTILE_CURVE_RIGHT) | + PROJECTILE_NO_WALL_COLLIDE; + volley.speed = VOLLEY_RING_SPEED; + volley.params.fallingAccelModifier = RING_FALL; + volley.period = RING_PERIOD; + volley.offset = RING_PERIOD / f.mode * f.turn + (i != 0 ? RING_SECOND_DELAY : 0); + } + return; + case 4: + { + count = 1; + FaceVolley& volley = volleys[0]; + volley.count = SPIRAL_COUNTS[mode]; + volley.params.circleAngle = frame * SPIRAL_SPIN / VOLLEY_SPIN_PERIOD; + volley.params.acceleration = SPIRAL_ACCELERATION; + volley.speed = SPIRAL_SPEED; + volley.params.bulletFlags |= PROJECTILE_DECELERATE | PROJECTILE_CHANGE_FLAGS_AFTER_TIMEOUT | + PROJECTILE_CHANGE_VELOCITY_AFTER_TIMEOUT; + volley.params.changeTimeout = SPIRAL_CHANGE_FRAMES; + volley.params.changeFlags = PROJECTILE_CURVE_LEFT; + volley.params.changeVelocity = SPIRAL_SPEED; + volley.params.curvingStrength = VOLLEY_RING_CURVE; + volley.period = SPIRAL_PERIOD; + volley.offset = SPIRAL_PERIOD / f.mode * f.turn; + return; + } + case 5: + { + count = 1; + FaceVolley& volley = volleys[0]; + volley.count = GAP_COUNT; + volley.period = GAP_PERIODS[mode]; + float distance = vector_length(f.aim); + int tries = GAP_TRIES; + bool isInRoom = false; + do + { + Vector away = distance > 0 ? vector_scale(f.aim, -1 / distance) : f.aim; + float turn = (random_unit() - 0.5f) * GAP_TURN * DEGREES_TO_RADIANS; + float cosine = std::cos(turn); + float sine = std::sin(turn); + away = vector_make(away.x * cosine - away.y * sine, away.y * cosine + away.x * sine); + volley.params.fireDirectionLimit = away; + tries--; + Vector probe = vector_sub(npc.pos, vector_scale(away, npc.size + GAP_REACH)); + isInRoom = g_game->room->IsPositionInRoom(probe, GAP_MARGIN); + } while (!isInRoom && tries > 0); + if (tries == 0) volley.count = 0; + volley.params.dotProductLimit = GAP_DOT_LIMIT; + volley.speed = GAP_SPEED; + volley.offset = volley.period / f.mode * f.turn; + return; + } + case 6: + count = WIDE_COUNTS[mode]; + for (int i = 0; i < count; i++) + { + FaceVolley& volley = volleys[i]; + volley.count = 1; + volley.params.circleAngle = (float)i * PI_F * 2 / (float)count + f.angle + PI_F; + float spread = std::clamp((float)i / (float)count, 0.0f, 1.0f); + volley.params.bulletFlags |= PROJECTILE_CURVE_LEFT | PROJECTILE_NO_WALL_COLLIDE; + volley.params.curvingStrength = spread * SWIRL_CURVE - SWIRL_CURVE / 2; + volley.speed = SWIRL_SPEED; + volley.params.fallingAccelModifier = SWIRL_FALL; + volley.period = SWIRL_PERIOD; + volley.offset = SWIRL_PERIOD / f.mode * f.turn; + } + return; + } +} + +// The face volleys for this frame, from i2's seed: one, two or all three faces each pick a pattern. +static FaceVolleys face_volleys_build(Entity_NPC& npc, int phase) +{ + RNG rng = HUSH_RNG; + rng._seed = (uint32_t)npc.i2; + FaceAim f{.mode = (int)(rng.Next() % FACE_MODES) + 1, .phase = phase}; + int picked = (int)(rng.Next() % FACE_COUNT); + FaceVolleys faces; + for (FaceVolley& volley : faces.volleys) + { + volley.params.heightModifier = VOLLEY_HEIGHT; + volley.params.fallingSpeedModifier = VOLLEY_FALL_SPEED; + volley.params.fallingAccelModifier = VOLLEY_FALL_ACCEL; + volley.params.scale = VOLLEY_SCALE; + volley.params.damage = VOLLEY_DAMAGE; + } + + f.aim = vector_sub(npc.GetPlayerTarget()->pos, npc.pos); + f.angle = std::atan2(f.aim.y, f.aim.x); + for (int face = 0; face < FACE_COUNT; face++) + { + if (const NullFrame* null = face_null(npc, face)) + { + f.aim = vector_sub(npc.GetPlayerTarget()->pos, vector_add(npc.pos, face_offset(*null))); + f.angle = std::atan2(f.aim.y, f.aim.x); + } + bool isActive = f.mode == FACE_MODES || (f.mode == 1 ? face == picked : face != picked); + if (!isActive) continue; + f.face = face; + face_pattern_build(npc, faces, rng, f); + f.turn++; + } + return faces; +} + +// Each face fires the rings due this frame from where it shows. +static void face_volleys_fire(Entity_NPC& npc, const FaceVolleys& faces) +{ + for (int face = 0; face < FACE_COUNT; face++) + { + if (faces.patterns[face] == -1) continue; + const NullFrame* null = face_null(npc, face); + for (int i = 0; i < faces.counts[face]; i++) + { + const FaceVolley& volley = faces.volleys[face * FACE_VOLLEY_LIMIT + i]; + if ((npc.stateFrame - volley.offset) % volley.period != 0 || !null) continue; + + ProjectileParams params = volley.params; + params.variant = PROJECTILE_HUSH; + params.color = {{1, 1, 1, 1}, {0, 0, 0, 0}, {FACE_TINTS[face][0], FACE_TINTS[face][1], FACE_TINTS[face][2]}}; + params.positionOffset = face_offset(*null); + params.depthOffset = npc.i1 != 1 ? FACE_DEPTH : FACE_DEPTH_UP; + params.targetPosition = vector_add(params.positionOffset, npc.pos); + npc.FireProjectiles(npc.pos, vector_make(volley.speed, (float)volley.count), PROJECTILES_RING, params); + } + } +} + +// The face volleys: his face vanishes and reappears toward his target, then fires its rings for 150 frames (sliding +// with his eyes open, until the slide ends). +static void volleys_update(Entity_NPC& npc, int ticks, int phase) +{ + FaceVolleys faces = face_volleys_build(npc, phase); + const AnimationState& anim = npc.sprite.animState; + bool isFiring = anim.isPlaying && (anim_is(npc, FACE_ATTACK[npc.i1]) || anim_is(npc, "MovingConcaveEyesOpen")); + if (!isFiring) + { + if (npc.state != HUSH_VOLLEYS || !anim.animData || anim.isPlaying) return; + if (anim_is(npc, FACE_VANISH[npc.i1])) + { + Vector toward = vector_sub(npc.GetPlayerTarget()->pos, npc.pos); + int face = std::abs(toward.x) <= std::abs(toward.y) ? (toward.y >= 0 ? FACE_DOWN : 1) + : (toward.x < 0 ? 0 : 2); + npc.i1 = face; + npc_anim_loop(npc.sprite, FACE_APPEAR[face]); + } + else if (anim_is(npc, FACE_APPEAR[npc.i1])) + { + npc.sprite.Play(FACE_ATTACK[npc.i1]); + npc.stateFrame = 0; + } + return; + } + if (ticks <= 0) return; + + face_volleys_fire(npc, faces); + npc.stateFrame += ticks; + if (npc.stateFrame <= VOLLEYS_FRAMES || npc.state != HUSH_VOLLEYS) return; + npc_anim_loop(npc.sprite, FACE_VANISH[npc.i1]); + idle_return(npc, IDLE_WAIT); +} + +// The flies: after his tell he coughs up 1 to 4 Hush flies now and then (while their group has fewer than 20), a ring +// about him, a swarm, or a homing swarm, set off at an angle to his target. They take their shape from their bytes. +static void flies_update(Entity_NPC& npc) +{ + RNG rng = HUSH_RNG; + rng._seed = (uint32_t)npc.i2; + uint32_t first = rng.Next(); + int group = (int)(first + first / UINT32_MAX); + + WeightedOutcomePicker picker; + if (Entity_NPC::QueryNPCsGroup(FLY_RING_GROUP).size() < HUSH_FLY_RING_LIMIT) picker.AddOutcomeWeight(FLY_RING, FLY_WEIGHT); + picker.AddOutcomeWeight(FLY_SWARM, FLY_WEIGHT); + picker.AddOutcomeWeight(FLY_HOMING_SWARM, FLY_WEIGHT); + bool isOdd = (g_game->frameCount - npc.spawnFrame) % 2 == 1; + if (isOdd) + for (int i = 0; i < FLY_RNG_SKIP; i++) rng.Next(); + int outcome = picker.PickOutcome(rng); + + Vector toward = vector_resized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos), FLY_HEADING); + float turn = isOdd ? FLY_TURN : -FLY_TURN; + Vector heading = vector_make(std::cos(turn) * toward.x - std::sin(turn) * toward.y, + std::sin(turn) * toward.x + std::cos(turn) * toward.y); + int firstShape = (int)(rng.Next() % FLY_SHAPES) + 1; + int secondShape = (int)(rng.Next() % FLY_SHAPES) + 1; + int reach = FLY_SWARM_REACH; + bool isHoming = false; + if (outcome == FLY_RING) + { + firstShape = FLY_RING_FIRST_SHAPE; + secondShape = FLY_RING_SECOND_SHAPE; + reach = (int)(npc.size + FLY_RING_REACH); + heading = Vector{}; + group = FLY_RING_GROUP; + } + else isHoming = outcome == FLY_HOMING_SWARM; + size_t groupSize = Entity_NPC::QueryNPCsGroup(group).size(); + + const AnimationState& anim = npc.sprite.animState; + if (anim.animData && !anim.isPlaying && anim_is(npc, "Tell1")) return npc.sprite.Play("SpawnFlies"); + if (!anim.animData || !anim.isPlaying) + { + npc.sprite.Play("Idle"); + return idle_return(npc, IDLE_WAIT); + } + if (!anim_is(npc, "SpawnFlies") || Random() % FLY_SPAWN_ODDS != 0 || groupSize >= FLY_GROUP_LIMIT) return; + + npc_sound_play(SOUND_WHEEZY_COUGH, 1, FLY_COUGH_DELAY, FLY_COUGH_PITCH); + int flyCount = (int)(Random() & 3) + 1; + std::vector flies; + for (int i = 0; i < flyCount; i++) + { + uint32_t seed = Random(); + Vector spot = vector_add(vector_make(npc.pos.x, npc.pos.y - FLY_MOUTH_RISE), vector_scale(random_direction(), FLY_MOUTH_REACH)); + flies.push_back(static_cast( + g_game->Spawn({.position = spot, .spawner = &npc, .type = ENTITY_HUSH_FLY, .seed = seed}))); + } + Vector offset = vector_resized(heading, npc.size); + for (auto fly = flies.rbegin(); fly != flies.rend(); fly++) + { + Entity_NPC& spawned = **fly; + spawned.ClearEntityFlags(FLAG_APPEAR); + spawned.entityCollisionClass = ENTCOLL_PLAYEROBJECTS; + spawned.velocity = vector_scale(random_direction(), FLY_THROW); + spawned.parent = &npc; + spawned.Update(); + spawned.groupIdx = group; + spawned.v1 = vector_add(npc.pos, offset); + spawned.v2 = heading; + spawned.i2 = firstShape | secondShape << 8 | (reach & 0xff) << 16 | (int)isHoming << 24; + } +} + +// The spit: three big bursting shots from his faces. +static void spit_update(Entity_NPC& npc) +{ + if (npc_anim_is_done(npc)) + { + npc.sprite.Play("Idle"); + return idle_return(npc, SPIT_WAIT); + } + if (npc.sprite.GetFrame() != SPIT_FRAME) return; + + ProjectileParams params; + params.scale = SPIT_SCALE; + params.fallingAccelModifier = HUSH_SPIT_FALL_ACCEL; + params.fallingSpeedModifier = HUSH_SPIT_FALL_SPEED; + params.depthOffset = HUSH_SPIT_DEPTH; + for (int face = 0; face < FACE_COUNT; face++) + { + const NullFrame* null = face_null(npc, face); + if (!null) continue; + Vector from = face_offset(*null); + params.bulletFlags = PROJECTILE_BURST3; + params.heightModifier = from.y; + npc.FireProjectiles(vector_make(npc.pos.x + from.x, npc.pos.y), SPIT_VELOCITIES[face], PROJECTILES_SINGLE, params); + } +} + +// Two lasers hunting his target, set to either side of the way to it. +static void hunters_spawn(Entity_NPC& npc) +{ + npc.stateFrame = (int)(Random() % HUNT_RANGE) + HUNT_MIN; + Entity* target = npc.GetPlayerTarget(); + Vector toward = vector_sub(target->pos, npc.pos); + float distance = vector_length(toward); + Vector along = vector_normalized(toward); + for (Vector side : {vector_make(-along.y, along.x), vector_make(along.y, -along.x)}) + { + Vector spot = vector_make(distance * (along.x * 0.5f + side.x * 0.5f) + npc.pos.x, + distance * (along.y * 0.5f + side.y * 0.5f) + npc.pos.y); + spot = g_game->room->GetClampedPositionImpl(spot, 0, 0, 0, 0); + auto* laser = static_cast(g_game->Spawn({.position = spot, .spawner = &npc, + .type = ENTITY_EFFECT, .variant = HUSH_LASER_VARIANT, + .seed = Random()})); + laser->SetTimeout(-1); + laser->parent = &npc; + laser->target = target; + laser->Update(); + } +} + +// The lasers: he charges, opens his eyes into two beams, sends wiggling rings from his mouth and lasers after his +// target, then closes them. +static void lasers_update(Entity_NPC& npc, int ticks, HushSurroundings& around) +{ + if (npc.sprite.IsPlaying("LaserStart") && npc.sprite.GetFrame() == LASER_CHARGE_FRAME) + { + game_shake_screen(LASER_CHARGE_SHAKE); + npc_sound_play(SOUND_HUSH_CHARGE, 1, LASER_SOUND_DELAY, 1); + } + const AnimationState& anim = npc.sprite.animState; + if (anim.animData && !anim.isPlaying && anim_is(npc, "LaserStart")) + { + npc.sprite.Play("LaserLoop"); + npc.stateFrame = -LASER_DELAY_MIN - (int)(Random() % LASER_DELAY_RANGE); + for (int eye = 0; eye < 2; eye++) + { + const NullFrame* null = face_null(npc, eye); + if (!null) continue; + auto* beam = static_cast(g_game->Spawn({.position = npc.pos, .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = HUSH_BEAM_VARIANT, .seed = Random()})); + beam->sprite.offset = null->pos; + beam->renderDepthOffset = BEAM_DEPTH; + beam->SetTimeout(-1); + beam->parent = &npc; + beam->Update(); + } + npc_sound_play(SOUND_HUSH_ROAR, 1, 2, 1); + return game_shake_screen(LASER_START_SHAKE); + } + + if (!npc.sprite.IsPlaying("LaserLoop")) + { + if (npc.sprite.IsFinished("LaserEnd")) idle_return(npc, npc.stateFrame); + return; + } + const AnimationFrame* mouth = anim.animData ? anim.GetLayerFrame(MOUTH_LAYER) : nullptr; + if (npc.GetIntervalTicks(MOUTH_INTERVAL, 0) && mouth) + { + ProjectileParams params; + params.scale = MOUTH_SCALE; + params.fallingAccelModifier = MOUTH_FALL_ACCEL; + params.fallingSpeedModifier = MOUTH_FALL_SPEED; + params.depthOffset = MOUTH_DEPTH; + params.bulletFlags = PROJECTILE_MEGA_WIGGLE; + params.wiggleFrameOffset = (int)(Random() % MOUTH_WIGGLE_RANGE); + params.positionOffset = mouth->pos; + npc.FireProjectiles(npc.pos, MOUTH_RING, PROJECTILES_RING, params); + } + for (size_t i = 0; i < around.beams.size(); i++) + if (const NullFrame* null = face_null(npc, i != 0)) around.beams[i]->sprite.offset = null->pos; + + if (npc.stateFrame < 1) + { + if (npc.stateFrame >= 0) return; + npc.stateFrame += ticks; + if (npc.stateFrame == 0 && around.lasers.empty()) hunters_spawn(npc); + return; + } + npc.stateFrame -= ticks; + if (npc.stateFrame == BEAMS_END_FRAME) + for (Entity* beam : around.beams) beam->isDead = true; + else if (npc.stateFrame == 0) + { + for (Entity* laser : around.lasers) laser->isDead = true; + npc.sprite.Play("LaserEnd"); + } +} + +// The gapers: his mouth opens and throws out gapers toward a spot below him, then he closes it and slides concave. +static void gapers_update(Entity_NPC& npc, int ticks) +{ + if (npc.sprite.IsPlaying("OpenMouth") && npc.sprite.IsEventTriggered("SkinPull")) + npc_sound_play(SOUND_HUSH_ROAR, 1, 2, 1); + if (npc.sprite.IsFinished("OpenMouth")) + { + npc.sprite.Play("OpenMouthLoop"); + npc.i2 = (int)(Random() & 0xf) + GAPERS_MIN; + } + + bool isThrowing = npc.sprite.IsPlaying("OpenMouthLoop") && ticks >= 1 && (Random() & 3) == 0; + if (!isThrowing) + { + if (!npc.sprite.IsFinished("CloseMouth")) return; + npc.state = HUSH_SLIDE; + npc.sprite.Play("TurnConcave"); + npc.targetPosition = g_game->room->GetRandomPosition(npc.size * HUSH_SPOT_MARGIN); + npc.i2 = (int)(Random() | 1); + return; + } + + float spread = std::clamp(random_unit(), 0.0f, 1.0f); + Vector spot = vector_make((spread * GAPER_SPREAD - GAPER_SPREAD_LEFT) / HUSH_SPRITE_SCALE + npc.pos.x, npc.pos.y); + spot = room_free_pickup_position_find({.position = spot, .isAvoidActiveEntities = true}); + Vector velocity = vector_scale(vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos)), HUSH_GAPER_SPEED); + Entity* gaper = g_game->Spawn({.position = spot, .velocity = velocity, .spawner = &npc, .type = ENTITY_HUSH_GAPER, + .variant = HUSH_GAPER_VARIANT, .seed = Random()}); + float aim = std::clamp(random_unit(), 0.0f, 1.0f); + Vector throwTo = vector_make((aim * GAPER_AIM_SPREAD - GAPER_AIM_LEFT) / HUSH_SPRITE_SCALE + npc.pos.x - spot.x, + npc.pos.y + GAPER_AIM_DROP - spot.y); + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + { + gaper->health = DELIRIUM_GAPER_HEALTH; + gaper->maxHitPoints = DELIRIUM_GAPER_HEALTH; + } + gaper->entityCollisionClass = ENTCOLL_NONE; + gaper->Update(); + gaper->velocity = vector_resized(throwTo, GAPER_THROW); + if (npc.i2 < 1) npc.sprite.Play("CloseMouth"); + npc.i2--; +} + +// The curves: his face vanishes and reappears (toward his target first, then anywhere), each face sending curving +// shots in spreads while it shows, 1 to 3 times. +static void curves_update(Entity_NPC& npc, int ticks) +{ + const char* vanish = FACE_VANISH[npc.i1]; + const char* attack = FACE_ATTACK[npc.i1]; + if (!npc.sprite.IsPlaying(attack)) + { + if (npc.sprite.IsFinished(vanish)) + { + int face = npc.i2 == 0 ? (int)vector_to_direction(vector_sub(npc.GetPlayerTarget()->pos, npc.pos)) + : (int)(Random() & 3); + npc.i1 = face; + npc.sprite.Play(FACE_APPEAR[face]); + } + else if (npc.sprite.IsFinished(FACE_APPEAR[npc.i1])) + { + npc.sprite.Play(attack); + npc.stateFrame = (int)(Random() % CURVE_LOOP_RANGE) + CURVE_LOOP_MIN; + } + return; + } + + if (npc.GetIntervalTicks(CURVE_INTERVAL, 0)) + { + ProjectileParams params; + params.fallingAccelModifier = npc.i1 == 0 || npc.i1 == 2 ? CURVE_FALL : CURVE_FALL_UP; + params.variant = PROJECTILE_HUSH; + params.bulletFlags = PROJECTILE_ACCELERATE | PROJECTILE_CONTINUUM; + params.acceleration = CURVE_ACCELERATION; + params.color = COLOR_DEFAULT; + params.scale = CURVE_SCALE; + int spread = (g_game->frameCount - npc.spawnFrame) / CURVE_INTERVAL % 3; + bool isSideways = npc.i1 & 1; + for (int face = 0; face < FACE_COUNT; face++) + { + const NullFrame* null = face_null(npc, face); + if (!null) continue; + float angle = (float)(npc.i1 - 2) * PI_F / 2 + CURVE_SPREADS[spread][face]; + params.bulletFlags &= ~(PROJECTILE_CURVE_LEFT | PROJECTILE_CURVE_RIGHT | PROJECTILE_CHANGE_FLAGS_AFTER_TIMEOUT); + if (face < 2) + { + params.changeFlags = params.bulletFlags | PROJECTILE_MEGA_WIGGLE; + params.changeTimeout = (isSideways ? CURVE_CHANGES_SIDE : CURVE_CHANGES)[spread]; + params.wiggleFrameOffset = -params.changeTimeout; + params.curvingStrength = isSideways ? CURVE_STRENGTH_SIDE : CURVE_STRENGTH; + params.bulletFlags |= (face == 1 ? PROJECTILE_CURVE_LEFT : PROJECTILE_CURVE_RIGHT) | + PROJECTILE_CHANGE_FLAGS_AFTER_TIMEOUT; + } + params.depthOffset = npc.i1 != 1 ? FACE_DEPTH : FACE_DEPTH_UP; + params.positionOffset = face_offset(*null); + Vector velocity = vector_make(std::cos(angle) * CURVE_SPEED, std::sin(angle) * CURVE_SPEED); + npc.FireProjectiles(npc.pos, velocity, PROJECTILES_SINGLE, params); + } + } + npc.stateFrame -= ticks; + if (npc.stateFrame >= 1) return; + npc.sprite.Play(vanish); + if (npc.i2 > 0) npc.i2--; + else idle_return(npc, IDLE_WAIT); +} + +// The creep: puffed, he blows red creep near a random wall for a few frames. +static void creep_update(Entity_NPC& npc) +{ + if (npc.sprite.IsFinished()) + { + npc.i2 = HUSH_CREEP; + npc.state = NPC_STATE_IDLE; + npc.stateFrame = IDLE_WAIT; + return; + } + int frame = npc.sprite.GetFrame(); + if (frame < CREEP_FIRST_FRAME || frame > CREEP_LAST_FRAME) return; + + npc_sound_play(SOUND_LOW_INHALE, 1, CREEP_SOUND_DELAY, 1); + Room& room = *g_game->room; + Vector topLeft = room.topLeftPos; + Vector bottomRight = room.bottomRightPos; + Vector spot{}; + float from = 0; + float to = 0; + switch (Random() & 3) + { + case 0: + spot = vector_make(topLeft.x, (bottomRight.y - topLeft.y) * random_unit() + topLeft.y); + from = -PI_F / 2; + to = PI_F / 2; + break; + case 1: + spot = vector_make((bottomRight.x - topLeft.x) * random_unit() + topLeft.x, topLeft.y); + to = PI_F; + break; + case 2: + spot = vector_make(bottomRight.x, (bottomRight.y - topLeft.y) * random_unit() + topLeft.y); + from = PI_F / 2; + to = PI_F * 3 / 2; + break; + case 3: + spot = vector_make((bottomRight.x - topLeft.x) * random_unit() + topLeft.x, bottomRight.y); + from = PI_F; + to = PI_F * 2; + break; + } + float angle = random_unit() * (to - from) + from; + float reach = random_unit() * CREEP_REACH; + spot = vector_add(spot, vector_make(std::cos(angle) * reach, std::sin(angle) * reach)); + Entity* creep = g_game->Spawn({.position = spot, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_CREEP_RED, + .seed = Random()}); + float scale = random_unit() + CREEP_SCALE_MIN; + creep->sprite.scale = vector_make(scale, scale); + creep->Update(); + game_shake_screen(CREEP_SHAKE); +} + +// Leaves a boil behind him as he slides, a little to either side. +static void boil_drop(Entity_NPC& npc) +{ + float speed = vector_length(npc.velocity); + Vector behind = speed > 0 ? vector_scale(npc.velocity, -(npc.size + BOIL_BEHIND) / speed) : npc.velocity; + float turn = (std::clamp(random_unit(), 0.0f, 1.0f) * BOIL_TURN - BOIL_TURN / 2) * DEGREES_TO_RADIANS; + float cosine = std::cos(turn); + float sine = std::sin(turn); + Vector spot = vector_make(behind.x * cosine - behind.y * sine + npc.pos.x, + behind.y * cosine + behind.x * sine + npc.pos.y); + g_game->Spawn({.position = spot, .subType = BOIL_POOF_SUBTYPE, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, + .seed = Random()}); + npc.PlaySound(SOUND_SUMMONSOUND, 1, 2, false, 1); + g_game->Spawn({.position = spot, .spawner = &npc, .type = ENTITY_HUSH_BOIL, .seed = Random()}); +} + +// The shots of his still in the room, which hold a turn concave. +static int own_shots_count(Entity_NPC& npc) +{ + int count = 0; + for (Entity* entity : g_game->room->entityList.updateEL) + if (entity->type == ENTITY_PROJECTILE && entity->spawnerType == npc.type && !entity->isDead && + g_game->room->IsPositionInRoom(entity->pos, 0)) + count++; + return count; +} + +// Concave: a near player makes him pop out. A turn ends once his shots are nearly gone, a slide at its spot, a volley +// slide after its legs, each leg to a new spot. Moving, he leaves boils behind. +static void concave_update(Entity_NPC& npc, int ticks, size_t boils) +{ + const AnimationState& anim = npc.sprite.animState; + bool isTurned = !anim.isPlaying || !anim_is(npc, "TurnConcave"); + for (Entity_Player* player : g_game->playerManager.playerList) + { + float reach = npc.size * POP_REACH_SCALE + player->size; + if (vector_length_squared(vector_sub(npc.pos, player->pos)) >= reach * reach) continue; + if (!isTurned) break; + npc.i2 = npc.state; + return pop_out(npc); + } + + if (npc.state == NPC_STATE_SPECIAL) + { + npc.stateFrame += ticks; + int shots = own_shots_count(npc); + int odds = (int)(Random() % TURN_SHOT_ODDS); + bool isHeld = shots - odds > 0 || !isTurned || npc.stateFrame <= TURN_MIN_FRAMES; + if (isHeld && npc.stateFrame <= TURN_MAX_FRAMES) return; + return pop_out(npc); + } + + bool isMoving = vector_length(npc.velocity) > BOIL_MIN_SPEED; + if (npc.IsFrame(BOIL_SPACING, 0) && (Random() & BOIL_ODDS_MASK) == 0 && isMoving && boils < BOIL_CROWD) + boil_drop(npc); + if (npc.state == HUSH_CHASE_VOLLEYS) + { + npc.targetPosition = npc.CalcTargetPosition(0); + npc.v1.x = 0; + } + + float distance = vector_length(vector_sub(npc.pos, npc.targetPosition)); + bool isLegDone = false; + if (npc.state == HUSH_SLIDE) + { + bool isSliding = distance >= SLIDE_ARRIVED && entity_query(ENTITY_HUSH_GAPER, -1).size() > GAPER_CROWD; + if (!isSliding) return pop_out(npc); + } + else if (npc.state == HUSH_SLIDE_VOLLEYS) isLegDone = distance < SLIDE_ARRIVED || npc.stateFrame > SLIDE_VOLLEY_FRAMES; + else isLegDone = npc.stateFrame > SLIDE_VOLLEY_FRAMES; + + if (!isLegDone) + { + if (isTurned) npc.sprite.Play(npc.state == HUSH_SLIDE ? "MovingConcave" : "MovingConcaveEyesOpen"); + return; + } + if ((npc.i2 & SLIDE_LEGS_MASK) == 0) return pop_out(npc); + npc.i2--; + npc.i2 = (int)((Random() & ~SLIDE_LEGS_MASK) ^ (uint32_t)npc.i2) | SLIDE_LEGS_MARK; + npc.targetPosition = g_game->room->GetRandomPosition(npc.size * HUSH_SPOT_MARGIN); +} + +// 004bfd30 Hush (407): he rises, then turns concave and slides about at each fifth of his health, attacking from his +// faces with volleys, curves and a spit, from his mouth with gapers, flies and lasers. Dying he takes every enemy and +// shot with him. +void boss_hush_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) return hush_init(npc); + if (npc.state == NPC_STATE_APPEAR_CUSTOM) appear_update(npc); + if (npc.isDead) hush_die(npc); + + HushSurroundings around{.gapers = entity_query(ENTITY_HUSH_GAPER, -1), + .boils = entity_query(ENTITY_HUSH_BOIL, -1), + .lasers = entity_query(ENTITY_EFFECT, HUSH_LASER_VARIANT), + .beams = entity_query(ENTITY_EFFECT, HUSH_BEAM_VARIANT)}; + shots_layer(npc); + if (npc.state != HUSH_LASERS || npc.isDead) + for (Entity* laser : around.lasers) laser->Kill(EntityRef()); + if (npc.isDead) return; + + layer_update(npc); + pop_events_update(npc); + int phase = phase_update(npc); + int ticks = npc_ticks_get(npc); + switch (npc.state) + { + case NPC_STATE_IDLE: + idle_update(npc, ticks, phase, (int)around.gapers.size()); + break; + case HUSH_VOLLEYS: + case HUSH_SLIDE: + case HUSH_SLIDE_VOLLEYS: + case HUSH_CHASE_VOLLEYS: + volleys_update(npc, ticks, phase); + break; + case HUSH_FLIES: + flies_update(npc); + break; + case HUSH_SPIT: + spit_update(npc); + break; + case HUSH_LASERS: + lasers_update(npc, ticks, around); + break; + case HUSH_GAPERS: + gapers_update(npc, ticks); + break; + case HUSH_CURVES: + curves_update(npc, ticks); + break; + case HUSH_CREEP: + creep_update(npc); + break; + } + if (is_concave_state(npc.state)) concave_update(npc, ticks, around.boils.size()); +} diff --git a/src/boss_isaac.cpp b/src/boss_isaac.cpp new file mode 100644 index 0000000..f1892bd --- /dev/null +++ b/src/boss_isaac.cpp @@ -0,0 +1,1276 @@ +#include "boss_ai.h" +#include "entity_config.h" +#include "entity_list.h" +#include "entity_player.h" +#include "manager.h" +#include "music_manager.h" +#include "npc_caves.h" +#include "room_grid.h" +#include "room_render.h" +#include "sfx_manager.h" +#include +#include +#include +#include + +// His phases: sitting, standing, then winged. Isaac rises one winged phase more for each light wall he calls. +enum IsaacPhase +{ + ISAAC_SITTING, + ISAAC_STANDING, + ISAAC_WINGED +}; + +// The three bytes he keeps in i2: his phase, the slant of his light walls and the frames until his next attack. +enum IsaacByte +{ + BYTE_PHASE, + BYTE_WALL_SLANT, + BYTE_COOLDOWN +}; + +// His ??? teleport (JUMP) and Isaac's light walls (ATTACK2) go through these steps in i1: vanishing, appearing, and +// a wall sweeping down from the left or the right, counted in frames from 1000 or 2000. +constexpr int STEP_VANISH = 0; +constexpr int STEP_APPEAR = 1; +constexpr int WALL_FROM_LEFT = 1000; +constexpr int WALL_FROM_RIGHT = 2000; +constexpr int WALL_END = 3000; + +// The angelic babies he calls and the summons ??? throws out. +constexpr int BABY_ANGELIC = 1; +constexpr int SUMMON_SUBTYPE = 1; +constexpr int SUMMON_SUBTYPE_POOTER = 2; +constexpr int BEAM_SUBTYPE = 2; + +// Health thresholds: he stands below 75% (??? below 70%), takes wings below half, and Isaac calls a wall at each +// tenth of his health below that, down to a tenth. ??? summons below 90% and curves his shots there. +constexpr float STAND_THRESHOLD = 0.75f; +constexpr float BLUE_STAND_THRESHOLD = 0.7f; +constexpr float WINGS_THRESHOLD = 0.5f; +constexpr int WALL_PHASE_LAST = 6; +constexpr std::array WALL_THRESHOLDS = {0.5f, 0.4f, 0.3f, 0.2f, 0.1f}; +constexpr float BLUE_SUMMON_THRESHOLD = 0.9f; +constexpr float POOTER_THRESHOLD = 0.7f; + +// Sitting he whimpers one time in 20, 45 to 144 frames later, and is held to his spot. Winged he drifts freely. +constexpr int WHIMPER_ODDS = 20; +constexpr int ISAAC_WHIMPER_DELAY_MIN = 45; +constexpr int ISAAC_WHIMPER_DELAY_RANGE = 100; +constexpr float HELD_FRICTION = 0.6f; +constexpr float WINGED_FRICTION = 0.9f; + +// His aimed shots: every 20 frames (30 standing, 25 or 12 winged, half for ???), at 8 (6 standing, three quarters +// for ???), a tenth off true. Hits taken since his last shots add up to 200, and past 100 and 150 fire a second and +// third shot, each spending 10 (5 for ???) of them. One ??? shot in 10 is a big homing one. +constexpr int SHOT_INTERVAL = 20; +constexpr int SHOT_INTERVAL_STANDING = 30; +constexpr int SHOT_INTERVAL_WINGED = 25; +constexpr int SHOT_INTERVAL_WINGED_BLUE = 12; +constexpr float ISAAC_SHOT_SPEED = 8; +constexpr float SHOT_SPEED_STANDING = 6; +constexpr float BLUE_SHOT_SPEED_SCALE = 0.75f; +constexpr float SHOT_WOBBLE = 0.1f; +constexpr float SHOT_FALL = -0.1f; +constexpr float SHOT_HOMING_SCALE = 1.2f; +constexpr int SHOT_HOMING_ODDS = 10; +constexpr float HITS_CAP = 200; +constexpr float HITS_SECOND_SHOT = 100; +constexpr float HITS_THIRD_SHOT = 150; +constexpr float HITS_PER_SHOT = 10; +constexpr float BLUE_HITS_PER_SHOT = 5; +constexpr float SHOT_LEAD = 0.3f; +constexpr float BLUE_SHOT_LEAD = 0.6f; + +// ??? summons every 30 frames, one roll in 8, while fewer than 9 enemies are about: 2 to 5 flies (a Moter one time in +// 4, a Pooter 3 times in 4 below 70%) thrown 15 out at 3. +constexpr int SUMMON_INTERVAL = 30; +constexpr int SUMMON_ODDS_MASK = 7; +constexpr int BLUE_SUMMON_CROWD = 9; +constexpr int SUMMON_COUNT_MIN = 2; +constexpr float BLUE_SUMMON_REACH = 15; +constexpr float SUMMON_SPEED = 3; + +// Standing Isaac's light beams: one roll in 4 starts two, 5 frames apart, at a random spot or one roll in 3 where his +// target heads, 40 frames between rolls. One roll in 10 with at most one enemy left calls two angelic babies 100 out +// instead, 120 frames before the next. +constexpr int BEAMS_ODDS_MASK = 3; +constexpr int BEAMS_FRAMES = 10; +constexpr int BEAMS_SPACING = 5; +constexpr int BEAMS_COOLDOWN = 40; +constexpr int BEAM_AIM_ODDS = 3; +constexpr float BEAM_SPOT_MARGIN = 20; +constexpr float BEAM_JITTER = 20; +constexpr float BEAM_AIM_LEAD = 0.2f; +constexpr float BEAM_SIZE = 10; +constexpr int BABIES_ODDS = 10; +constexpr int BABIES_CROWD = 2; +constexpr int BABIES_COUNT = 2; +constexpr int BABIES_COOLDOWN = 120; +constexpr float BABIES_REACH = 100; +constexpr float BABIES_JITTER = 10; + +// His cell is marked so walkers keep off, below the paths the room already blocks. +constexpr int ISAAC_PATH_LIMIT = 951; + +// Idle he waits 60 to 119 frames first, then 15 to 104 after each attack (a third for Hush's ???). +constexpr int FIRST_COOLDOWN_MIN = 60; +constexpr int FIRST_COOLDOWN_RANGE = 60; +constexpr int COOLDOWN_MIN = 15; +constexpr int COOLDOWN_RANGE = 90; +constexpr int HUSH_COOLDOWN_DIVISOR = 3; +constexpr int ISAAC_ATTACK_FRAMES = 40; +constexpr int ATTACK_PICKS = 6; +constexpr int ATTACK_PATTERNS = 5; +constexpr float G_FUEL_SHIELD = 90; + +// His shot rings: waves after 3 frames (19 winged, past the wings' rise), i1 / 5 + 3 of them, 3 to 6 frames apart. +// Isaac's ring pattern is i1 % 5: 10 shots at 7 curving left, right or straight, 8 turned a half step on even waves, +// or 8 at 12 through walls. The curving ones fire a second ring at 11 curving the other way. +constexpr int WAVE_DELAY = 3; +constexpr int WAVE_DELAY_WINGED = 19; +constexpr int WAVES_MIN = 3; +constexpr float WAVE_SPACING_MIN = 3; +constexpr float WAVE_SPACING_RANGE = 3; +constexpr float WAVE_SPACING_PICKS = 5; +constexpr float ISAAC_RING_SPEED = 7; +constexpr float RING_SPEED_FAST = 12; +constexpr float RING_SPEED_SECOND = 11; +constexpr float RING_COUNT = 10; +constexpr float RING_COUNT_SMALL = 8; +constexpr float RING_FALL_ACCEL = -0.06f; +constexpr float RING_CURVE = 0.002f; +constexpr float RING_CURVE_FAST = 0.009f; +constexpr float RING_CURVE_SECOND = 0.015f; +constexpr float RING_FALL_ACCEL_SECOND = 0.15f; +constexpr float RING_HALF_STEP = 0.3926991f; +constexpr float WAVE_VOLUME = 0.5f; + +// ???'s bursts: 6 to 9 shots at 7 from 20 below him, curving below 90%, one in 5 big and homing in the first 3 +// patterns. +constexpr int BURST_COUNT_MIN = 6; +constexpr int BURST_COUNT_PICKS = 4; +constexpr float BLUE_BURST_SPEED = 7; +constexpr float BURST_DROP = 20; +constexpr float BLUE_BURST_FALL_ACCEL = -0.05f; +constexpr float BURST_FALL_ACCEL_HUSH = -0.15f; +constexpr float BURST_CURVE = 0.007f; +constexpr float BURST_CURVE_HUSH = 0.0035f; +constexpr int BURST_BIG_PICKS = 3; +constexpr int BURST_BIG_ODDS = 5; +constexpr float BURST_BIG_SCALE = 1.5f; + +// Standing, his attack is a ring of 1.5 shots on frame 6: 4 at 7 bursting (Isaac) or 4 at 10 homing (???), or 8 at +// 10 (Isaac) or 8 at 8 homing (???). +constexpr float STAND_RING_FRAME = 6; +constexpr float STAND_RING_SCALE = 1.5f; +static const Vector STAND_RING_BURST = vector_make(7, 4); +static const Vector STAND_RING_WIDE = vector_make(10, 8); +static const Vector BLUE_STAND_RING_FEW = vector_make(10, 4); +static const Vector BLUE_STAND_RING_WIDE = vector_make(8, 8); + +// The animation frames his sounds play on. +constexpr float STAND_SOUND_FRAME = 20; +constexpr float EVOLVE_SOUND_FRAME = 17; +constexpr float VANISH_SOUND_FRAME = 19; +constexpr float CHARGE_SOUND_FRAME = 17; + +// Winged he keeps 120 to 200 from his target (??? right on it), along its axis for Isaac, every 15 frames, and steps +// 1.3 (0.175 of it for ???) along the nearest of 8 directions while 32 away. +constexpr int DRIFT_INTERVAL = 15; +constexpr float DRIFT_DISTANCE_MIN = 120; +constexpr float DRIFT_DISTANCE_RANGE = 80; +constexpr float DRIFT_SLACK = 32; +constexpr float DRIFT_SPEED = 1.3f; +constexpr float BLUE_DRIFT_SCALE = 0.175f; +constexpr float OCTANT = 0.7853982f; + +// ??? teleports every 100 frames one roll in 2, near his target: 151 out along its heading, or around it on further +// rings, keeping 150 from every player, in 20 tries. Isaac reappears anywhere 100 from every player. +constexpr int TELEPORT_INTERVAL = 100; +constexpr float TELEPORT_REACH = 151; +constexpr float TELEPORT_CLEARANCE = 150; +constexpr float TELEPORT_RING_STEP = 12.5f; +constexpr float TELEPORT_TURN = 90; +constexpr float TELEPORT_FULL_TURN = 360; +constexpr int TELEPORT_TURNS = 4; +constexpr int ISAAC_TELEPORT_TRIES = 20; +constexpr float ISAAC_TELEPORT_CLEARANCE = 100; + +// The light walls: from the top corner 10 in, a line of 11 beams 60 apart slanting down and across, moving 75 (plus +// up to 20 of jitter) further every 8 frames and shifted along its slant by up to 75 times root 2, until no beam fits +// in the room. Then Isaac reappears and fires pattern 27. +constexpr float WALL_INSET = 10; +constexpr float WALL_STEP = 75; +constexpr float WALL_JITTER = 20; +constexpr float WALL_BEAM_SPACING = 60; +constexpr int WALL_STEP_FRAMES = 8; +constexpr int WALL_BEAM_FIRST = -1; +constexpr int WALL_BEAM_END = 10; +constexpr float WALL_SLANT_SCALE = 255; +constexpr float WALL_BEAM_MARGIN = 10; +constexpr int WALL_ATTACK_PATTERN = 27; +constexpr RNG WALL_JITTER_RNG = {0, 1, 11, 6}; + +// Hush rises 60 below the room's top when Hush's ??? dies, and every shot within 1000 is gone. +constexpr float HUSH_DROP = 60; +constexpr float SHOT_CLEAR_RADIUS = 1000; +constexpr float HUSH_MUSIC_FADE = 0.08f; + +// Logs a line with one number, as KAGE_LogMessage's callers format it. +static void isaac_log(const char* format, int value) +{ + char line[64]; + std::snprintf(line, sizeof(line), format, value); + KAGE_LogMessage(LOG_INFO, (uint8_t*)line); +} + +// One of the bytes Isaac keeps in i2. +static int byte_get(const Entity_NPC& npc, IsaacByte index) +{ + return npc.i2 >> (index * 8) & 0xff; +} + +static void byte_set(Entity_NPC& npc, IsaacByte index, int value) +{ + int shift = index * 8; + npc.i2 = (npc.i2 & ~(0xff << shift)) | (value & 0xff) << shift; +} + +// Whether his animation reached a frame on this update. +static bool anim_frame_crossed(Entity_NPC& npc, float frame) +{ + const AnimationState& anim = npc.sprite.animState; + float current = anim.animData ? anim.animFrame : ANIMATION_FRAME_UNSET; + return current - npc.speedMultiplier * npc.sprite.playbackSpeed < frame && anim.animData && frame <= current; +} + +// Marks a spot's cell so walkers keep off it, unless the room blocks it already. +static void grid_path_claim(Vector position) +{ + Room& room = *g_game->room; + int cell = room.GetGridIndex(position); + if (cell >= 0 && cell < ROOM_GRID_CELLS && room.gridPaths[cell] < ISAAC_PATH_LIMIT) + room.gridPaths[cell] = GRID_PATH_FREED; +} + +static bool is_blue(const Entity_NPC& npc) +{ + return npc.variant == ISAAC_FORM_CHEST || npc.variant == ISAAC_FORM_HUSH; +} + +// A light beam of his at a spot, hurting from where it lands. +static Entity* light_beam_spawn(Entity_NPC& npc, Vector position) +{ + return g_game->Spawn({.position = position, .spawner = &npc, .subType = BEAM_SUBTYPE, .type = ENTITY_EFFECT, + .variant = EFFECT_CRACK_THE_SKY, .seed = Random()}); +} + +// The first update: he sits where he is, ready to attack after a minute or two. ??? takes a shield on G-Fuel. +static void isaac_init(Entity_NPC& npc) +{ + npc.targetPosition = npc.pos; + byte_set(npc, BYTE_PHASE, ISAAC_SITTING); + npc.stateFrame = 0; + npc.state = NPC_STATE_IDLE; + byte_set(npc, BYTE_COOLDOWN, Random() % FIRST_COOLDOWN_RANGE + FIRST_COOLDOWN_MIN); + if (npc.variant == ISAAC_FORM_CHEST && g_game->seedEffects.HasSeedEffect(SEED_G_FUEL)) + npc.shieldStrength = G_FUEL_SHIELD; +} + +// Below his thresholds he stands (??? calling two eternal flies), then takes his wings. +static void phase_update(Entity_NPC& npc) +{ + bool isIsaac = npc.variant == ISAAC_FORM_CATHEDRAL; + if (!isIsaac && !is_blue(npc)) return; + + float stand = npc.maxHitPoints * (isIsaac ? STAND_THRESHOLD : BLUE_STAND_THRESHOLD); + if (npc.health < stand && byte_get(npc, BYTE_PHASE) == ISAAC_SITTING) + { + byte_set(npc, BYTE_PHASE, ISAAC_STANDING); + npc.state = NPC_STATE_SPECIAL; + if (is_blue(npc)) + for (int i = 0; i < 2; i++) + { + uint32_t seed = Random(); + Entity* fly = + g_game->Spawn({.position = npc.pos, .spawner = &npc, .type = ENTITY_ETERNALFLY, .seed = seed}); + fly->parent = &npc; + } + } + if (npc.health < npc.maxHitPoints * WINGS_THRESHOLD && byte_get(npc, BYTE_PHASE) == ISAAC_STANDING) + { + byte_set(npc, BYTE_PHASE, ISAAC_WINGED); + npc.state = NPC_STATE_SPECIAL; + } +} + +// His aimed shots, one to three by the hits he took, straight along an axis for winged Isaac and leading with his own +// drift once winged. +static void aimed_shots_fire(Entity_NPC& npc, int phase, float speed) +{ + ProjectileParams params; + if (Random() % SHOT_HOMING_ODDS == 0 && is_blue(npc)) + { + params.bulletFlags |= PROJECTILE_SMART; + params.scale = SHOT_HOMING_SCALE; + } + else params.variant = PROJECTILE_TEAR; + params.fallingSpeedModifier = SHOT_FALL; + params.fallingAccelModifier = SHOT_FALL; + + int count = npc.v2.y > HITS_THIRD_SHOT ? 3 : npc.v2.y > HITS_SECOND_SHOT ? 2 : 1; + for (int i = 0; i < count; i++) + { + Vector aim = vector_sub(npc.GetPlayerTarget()->pos, npc.pos); + if (phase >= ISAAC_WINGED && npc.variant == ISAAC_FORM_CATHEDRAL) + { + if (std::abs(aim.x) <= std::abs(aim.y)) aim.x = 0; + else aim.y = 0; + } + aim = vector_add(vector_normalized(aim), vector_scale(random_direction(), SHOT_WOBBLE)); + Vector velocity = vector_resized(aim, speed); + if (phase >= ISAAC_WINGED && npc.variant == ISAAC_FORM_CATHEDRAL) + velocity = vector_add(velocity, vector_scale(npc.velocity, SHOT_LEAD)); + else if (phase >= ISAAC_WINGED && is_blue(npc)) + velocity = vector_add(velocity, vector_scale(npc.velocity, BLUE_SHOT_LEAD)); + npc.FireProjectiles(npc.pos, velocity, PROJECTILES_SINGLE, params); + } + npc.v2.y -= count * (is_blue(npc) ? BLUE_HITS_PER_SHOT : HITS_PER_SHOT); +} + +// Hits since his last shots pile up, and he shoots on his interval (winged, only while idle). +static void aimed_shots_update(Entity_NPC& npc) +{ + if (npc.v2.x > npc.health) npc.v2.y = std::min(npc.v2.x - npc.health + npc.v2.y, HITS_CAP); + + int phase = byte_get(npc, BYTE_PHASE); + int interval = phase == ISAAC_STANDING ? SHOT_INTERVAL_STANDING : SHOT_INTERVAL; + float speed = ISAAC_SHOT_SPEED; + if (phase < ISAAC_WINGED) + { + if (is_blue(npc)) interval /= 2; + if (phase == ISAAC_STANDING) speed = SHOT_SPEED_STANDING; + } + else interval = is_blue(npc) ? SHOT_INTERVAL_WINGED_BLUE : SHOT_INTERVAL_WINGED; + if (is_blue(npc)) speed *= BLUE_SHOT_SPEED_SCALE; + + bool isShooting = npc.state != NPC_STATE_ATTACK && (phase < ISAAC_WINGED || npc.state == NPC_STATE_IDLE); + if (isShooting && npc.GetIntervalTicks((float)interval, 0)) aimed_shots_fire(npc, phase, speed); + npc.v2.y = std::max(npc.v2.y, 0.0f); +} + +// ??? throws out flies now and then below 90%, keeping the room under 10 enemies. +static void blue_summons_update(Entity_NPC& npc, int enemies) +{ + if (!is_blue(npc) || !npc.GetIntervalTicks(SUMMON_INTERVAL, 0)) return; + if ((Random() & SUMMON_ODDS_MASK) != 0 || enemies >= BLUE_SUMMON_CROWD) return; + if (npc.health >= npc.maxHitPoints * BLUE_SUMMON_THRESHOLD) return; + + int extra = (int)(Random() & 3) + SUMMON_COUNT_MIN; + int count = enemies + extra < BLUE_SUMMON_CROWD + 1 ? extra : BLUE_SUMMON_CROWD - enemies; + float angle = random_unit() * PI_F * 2; + float step = 2 * PI_F / (float)count; + for (int i = 0; i < count; i++, angle += step) + { + int type = (Random() & 3) == 0 ? ENTITY_MOTER : ENTITY_ATTACKFLY; + int subType = SUMMON_SUBTYPE; + if (npc.health < npc.maxHitPoints * POOTER_THRESHOLD && (Random() & 3) != 0) + { + subType = SUMMON_SUBTYPE_POOTER; + type = ENTITY_POOTER; + } + Vector direction = vector_make(std::cos(angle), std::sin(angle)); + uint32_t seed = Random(); + Entity* fly = g_game->Spawn({.position = vector_add(npc.pos, vector_scale(direction, BLUE_SUMMON_REACH)), + .velocity = vector_scale(direction, SUMMON_SPEED), + .spawner = &npc, + .subType = subType, + .type = type, + .seed = seed}); + fly->ClearEntityFlags(FLAG_APPEAR); + fly->isKillOnTouch = true; + } +} + +// Standing Isaac rolls for two light beams, or for two angelic babies once his helpers are gone. +static void standing_powers_roll(Entity_NPC& npc, int ticks) +{ + if (npc.projectileCooldown >= 0) + { + npc.projectileCooldown -= ticks; + return; + } + if ((Random() & BEAMS_ODDS_MASK) == 0) + { + npc.stateFrame = BEAMS_FRAMES; + npc.projectileCooldown = BEAMS_COOLDOWN; + return; + } + if (Random() % BABIES_ODDS != 0 || g_game->room->GetAliveEnemiesCount() >= BABIES_CROWD) return; + + npc.projectileCooldown = BABIES_COOLDOWN; + for (int i = 0; i < BABIES_COUNT; i++) + { + Vector around = vector_add(npc.pos, vector_scale(random_direction(), BABIES_REACH)); + Vector spot = room_free_pickup_position_find({.position = around, .isAvoidActiveEntities = true, + .isAllowPits = true}); + Vector jitter = random_direction(); + float reach = random_unit() * BABIES_JITTER; + Vector position = vector_add(spot, vector_scale(jitter, reach)); + g_game->Spawn({.position = position, .spawner = &npc, .type = ENTITY_BABY, .variant = BABY_ANGELIC, + .seed = Random()}); + } +} + +// While standing, his beam countdown drops a light beam every 5 frames, at a random spot or where his target heads. +static void standing_beams_update(Entity_NPC& npc, int ticks) +{ + Room& room = *g_game->room; + for (; ticks > 0; ticks--) + { + if (byte_get(npc, BYTE_PHASE) != ISAAC_STANDING) continue; + if (npc.stateFrame-- <= 0 || npc.stateFrame % BEAMS_SPACING != 0) continue; + + Vector spot = room_free_pickup_position_find({.position = room.GetRandomPosition(BEAM_SPOT_MARGIN)}); + Vector jitter = random_direction(); + spot = vector_add(spot, vector_scale(jitter, random_unit() * BEAM_JITTER)); + if (Random() % BEAM_AIM_ODDS == 0) + { + Entity& target = *npc.GetPlayerTarget(); + float lead = vector_length(vector_sub(npc.pos, target.pos)) * BEAM_AIM_LEAD; + spot = room.GetClampedPositionImpl(vector_add(target.pos, vector_scale(target.velocity, lead)), + BEAM_SPOT_MARGIN, BEAM_SPOT_MARGIN, BEAM_SPOT_MARGIN, + BEAM_SPOT_MARGIN); + } + grid_path_claim(spot); + Entity* beam = light_beam_spawn(npc, spot); + beam->SetSize(BEAM_SIZE, vector_make(-1, -1), -1); + beam->Update(); + } +} + +// Winged he drifts toward a spot by his target (along its axis for Isaac), stepping along the nearest of 8 +// directions. Feared or shrunk he flees it, confused he wanders. +static void winged_drift(Entity_NPC& npc) +{ + if (npc.GetIntervalTicks(DRIFT_INTERVAL, 0)) + { + if (npc.variant == ISAAC_FORM_CATHEDRAL) npc.v1.y = random_unit() * DRIFT_DISTANCE_RANGE + DRIFT_DISTANCE_MIN; + if (npc.variant == ISAAC_FORM_CHEST) npc.v1.y = 0; + } + Vector targetPos = npc.GetPlayerTarget()->pos; + Vector away = vector_sub(npc.pos, targetPos); + if (npc.variant == ISAAC_FORM_CATHEDRAL) + { + if (std::abs(away.x) <= std::abs(away.y)) away.x = 0; + else away.y = 0; + } + Vector goal = vector_sub(vector_add(targetPos, vector_scale(vector_normalized(away), npc.v1.y)), npc.pos); + + if (npc.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK)) + { + if (is_blue(npc)) npc.friction = HELD_FRICTION; + npc.pathfinder.EvadeTarget(targetPos, STATUS_OBEYED); + return; + } + if (npc.HasEntityFlags(FLAG_CONFUSION)) + { + if (is_blue(npc)) npc.friction = HELD_FRICTION; + int moves = npc.variant == ISAAC_FORM_CATHEDRAL ? 3 : 1; + for (int i = 0; i < moves; i++) npc.pathfinder.MoveRandomly(STATUS_OBEYED); + return; + } + if (vector_length(goal) <= DRIFT_SLACK) return; + + float angle = std::floor(std::atan2(goal.y, goal.x) / OCTANT + 0.5f) * OCTANT; + Vector step = vector_scale(vector_normalized(vector_make(std::cos(angle), std::sin(angle))), DRIFT_SPEED); + npc_push(npc, is_blue(npc) ? vector_scale(step, BLUE_DRIFT_SCALE) : step); +} + +// Idle he waits out his cooldown (only once hurt), then picks an attack. Isaac calls a wall at each tenth of his +// health below half, ??? teleports now and then, and winged he drifts about his target. +static void idle_update(Entity_NPC& npc, int ticks) +{ + int phase = byte_get(npc, BYTE_PHASE); + npc_anim_loop(npc.sprite, phase == ISAAC_SITTING ? "1Idle" : phase == ISAAC_STANDING ? "2Idle" : "3Idle"); + + int cooldown = byte_get(npc, BYTE_COOLDOWN); + if (cooldown - ticks < 1 && npc.health < npc.maxHitPoints) + { + npc.state = NPC_STATE_ATTACK; + npc.projectileCooldown = ISAAC_ATTACK_FRAMES; + byte_set(npc, BYTE_COOLDOWN, 0); + if (phase != ISAAC_STANDING) + { + uint32_t picks = Random(); + npc.i1 = (int)(Random() % ATTACK_PATTERNS + picks % ATTACK_PICKS * ATTACK_PATTERNS); + } + else npc.i1 = (npc.i1 + 1) % 2; + npc.v1.x = random_unit() * PI_F; + } + else byte_set(npc, BYTE_COOLDOWN, std::max(cooldown - ticks, 0)); + + if (is_blue(npc) && phase >= ISAAC_WINGED && (g_game->frameCount - npc.spawnFrame) % TELEPORT_INTERVAL == 0 && + (Random() & 1) == 0) + { + npc.state = NPC_STATE_JUMP; + npc.i1 = STEP_VANISH; + } + if (npc.variant == ISAAC_FORM_CATHEDRAL && phase >= ISAAC_WINGED && phase <= WALL_PHASE_LAST && + npc.health < npc.maxHitPoints * WALL_THRESHOLDS[phase - ISAAC_WINGED]) + { + byte_set(npc, BYTE_PHASE, phase + 1); + npc.state = NPC_STATE_ATTACK2; + npc.i1 = STEP_VANISH; + } + if (phase >= ISAAC_WINGED) winged_drift(npc); +} + +// Isaac's ring wave, by his pattern: curving one way then the other, straight, turning by waves, or through walls. +static void isaac_wave_fire(Entity_NPC& npc, int wave) +{ + ProjectileParams params; + params.circleAngle = npc.v1.x; + params.variant = PROJECTILE_TEAR; + params.fallingSpeedModifier = SHOT_FALL; + params.fallingAccelModifier = RING_FALL_ACCEL; + params.curvingStrength = RING_CURVE; + Vector ring = vector_make(ISAAC_RING_SPEED, RING_COUNT); + int pattern = npc.i1 % ATTACK_PATTERNS; + switch (pattern) + { + case 0: + params.bulletFlags = PROJECTILE_CURVE_LEFT; + break; + case 1: + params.bulletFlags = PROJECTILE_CURVE_RIGHT; + break; + case 3: + ring.y = RING_COUNT_SMALL; + if (wave % 2 == 0) params.circleAngle += RING_HALF_STEP; + break; + case 4: + ring = vector_make(RING_SPEED_FAST, RING_COUNT_SMALL); + params.bulletFlags |= PROJECTILE_CURVE_LEFT | PROJECTILE_NO_WALL_COLLIDE; + params.curvingStrength = RING_CURVE_FAST; + break; + } + npc.FireProjectiles(npc.pos, ring, PROJECTILES_RING, params); + if (pattern > 1) return; + + params.bulletFlags = pattern == 0 ? PROJECTILE_CURVE_RIGHT : PROJECTILE_CURVE_LEFT; + params.curvingStrength = RING_CURVE_SECOND; + params.fallingAccelModifier = RING_FALL_ACCEL_SECOND; + npc.FireProjectiles(npc.pos, vector_make(RING_SPEED_SECOND, ring.y), PROJECTILES_RING, params); +} + +// ???'s burst: an even spread from below him, curving once he is hurt, now and then big and homing. +static void blue_burst_fire(Entity_NPC& npc) +{ + int count = (int)npc.v1.x % BURST_COUNT_PICKS + BURST_COUNT_MIN; + float step = 2 * PI_F / (float)count; + float angle = npc.v1.x; + for (int i = 0; i < count; i++) + { + angle += step; + Vector velocity = vector_make(std::cos(angle) * BLUE_BURST_SPEED, std::sin(angle) * BLUE_BURST_SPEED); + ProjectileParams params; + if (is_blue(npc)) + { + params.fallingAccelModifier = npc.variant == ISAAC_FORM_CHEST ? BLUE_BURST_FALL_ACCEL : BURST_FALL_ACCEL_HUSH; + params.fallingSpeedModifier = SHOT_FALL; + } + if (npc.health < npc.maxHitPoints * BLUE_SUMMON_THRESHOLD) + { + params.bulletFlags = PROJECTILE_CURVE_RIGHT; + if (npc.variant == ISAAC_FORM_CHEST) params.curvingStrength = BURST_CURVE; + else if (npc.variant == ISAAC_FORM_HUSH) params.curvingStrength = BURST_CURVE_HUSH; + } + if (npc.i1 < BURST_BIG_PICKS && Random() % BURST_BIG_ODDS == 0) + { + params.bulletFlags |= PROJECTILE_SMART; + params.scale = BURST_BIG_SCALE; + } + else params.variant = PROJECTILE_TEAR; + npc.FireProjectiles(vector_make(npc.pos.x, npc.pos.y + BURST_DROP), velocity, PROJECTILES_SINGLE, params); + } +} + +// One wave of his attack, with its cries. Sitting he restarts his attack pose, winged he lowers his arms on the last. +static void wave_fire(Entity_NPC& npc, int wave, int waves) +{ + float pitch = champion_pitch_get(npc); + npc_sound_play(SOUND_THUMBS_DOWN, WAVE_VOLUME, 2, pitch); + npc_sound_play(SOUND_BLOODSHOOT, 1, 2, pitch); + if (npc.variant == ISAAC_FORM_CATHEDRAL) isaac_wave_fire(npc, wave); + else blue_burst_fire(npc); + + int phase = byte_get(npc, BYTE_PHASE); + if (phase == ISAAC_SITTING) npc_anim_restart(npc.sprite, "1Attack"); + if (phase >= ISAAC_WINGED && waves == wave + 1) npc_anim_loop(npc.sprite, "3FBAttack4End"); +} + +// Standing, his attack is a single ring of big shots as he throws his arms up. +static void standing_ring_fire(Entity_NPC& npc) +{ + npc.sprite.Play("2Attack"); + if (!anim_frame_crossed(npc, STAND_RING_FRAME)) return; + + npc.PlaySound(SOUND_THUMBSUP, 1, 2, false, 1); + npc.PlaySound(SOUND_BLOODSHOOT, 1, 2, false, 1); + ProjectileParams params; + params.circleAngle = npc.v1.x; + params.scale = STAND_RING_SCALE; + if (npc.i1 != 0 && npc.i1 != 1) return; + + Vector ring = npc.i1 == 0 ? BLUE_STAND_RING_FEW : BLUE_STAND_RING_WIDE; + if (npc.variant == ISAAC_FORM_CATHEDRAL) + { + params.variant = PROJECTILE_TEAR; + if (npc.i1 == 0) params.bulletFlags |= PROJECTILE_BURST; + ring = npc.i1 == 0 ? STAND_RING_BURST : STAND_RING_WIDE; + } + else params.bulletFlags |= PROJECTILE_SMART; + npc.FireProjectiles(npc.pos, ring, PROJECTILES_RING, params); +} + +// Winged, he raises his arms (a chime on frame 17), holds them up through his waves, then lowers them. +static void winged_pose_update(Entity_NPC& npc) +{ + if (byte_get(npc, BYTE_COOLDOWN) == 0) npc_anim_loop(npc.sprite, "3FBAttack4Start"); + const AnimationState& anim = npc.sprite.animState; + if (!anim.animData || anim.animData->name != "3FBAttack4Start") return; + + if (!anim.isPlaying) npc_anim_loop(npc.sprite, "3FBAttack4Loop"); + else if (anim_frame_crossed(npc, CHARGE_SOUND_FRAME)) npc.PlaySound(SOUND_POWERUP2, 1, 2, false, 1); +} + +// An attack: waves of shots counted up from the start, then back to idle with a fresh cooldown once its pose ends. +static void attack_update(Entity_NPC& npc, int ticks) +{ + int phase = byte_get(npc, BYTE_PHASE); + bool isLowered = false; + if (phase == ISAAC_STANDING) standing_ring_fire(npc); + else + { + if (phase == ISAAC_SITTING) npc_anim_loop(npc.sprite, "1Attack"); + else winged_pose_update(npc); + const AnimationState& anim = npc.sprite.animState; + isLowered = anim.animData && !anim.isPlaying && anim.animData->name == "3FBAttack4End"; + + for (; ticks > 0; ticks--) + { + int count = byte_get(npc, BYTE_COOLDOWN); + int delay = byte_get(npc, BYTE_PHASE) < ISAAC_WINGED ? WAVE_DELAY : WAVE_DELAY_WINGED; + int waves = npc.i1 / ATTACK_PATTERNS + WAVES_MIN; + int since = count - delay; + float picks = std::clamp((float)npc.i1 / WAVE_SPACING_PICKS / WAVE_SPACING_PICKS, 0.0f, 1.0f); + int spacing = (int)(picks * WAVE_SPACING_RANGE + WAVE_SPACING_MIN); + if (count > delay && since % spacing == 0 && since / spacing < waves) wave_fire(npc, since / spacing, waves); + byte_set(npc, BYTE_COOLDOWN, count + 1); + } + } + + if ((byte_get(npc, BYTE_PHASE) < ISAAC_WINGED && npc_anim_is_done(npc)) || isLowered) + { + npc.state = NPC_STATE_IDLE; + int cooldown = (int)(Random() % COOLDOWN_RANGE) + COOLDOWN_MIN; + byte_set(npc, BYTE_COOLDOWN, npc.variant == ISAAC_FORM_HUSH ? cooldown / HUSH_COOLDOWN_DIVISOR : cooldown); + } +} + +// Standing up (a chime on frame 20) or taking his wings (on frame 17), then idle. +static void rise_update(Entity_NPC& npc) +{ + int phase = byte_get(npc, BYTE_PHASE); + if (phase == ISAAC_STANDING) + { + npc.sprite.Play("1StandUp"); + if (anim_frame_crossed(npc, STAND_SOUND_FRAME)) npc.PlaySound(SOUND_HOLY, 1, 2, false, 1); + } + else if (phase >= ISAAC_WINGED) + { + npc.sprite.Play("2Evolve"); + if (anim_frame_crossed(npc, EVOLVE_SOUND_FRAME)) npc.PlaySound(SOUND_SUPERHOLY, 1, 2, false, 1); + } + if (npc_anim_is_done(npc)) npc.state = NPC_STATE_IDLE; +} + +// Fading out through a portal. True once gone. +static bool vanish_update(Entity_NPC& npc) +{ + npc.sprite.Play("3FBAttack3"); + if (anim_frame_crossed(npc, VANISH_SOUND_FRAME)) npc.PlaySound(SOUND_HELL_PORTAL2, 1, 2, false, 1); + return npc_anim_is_done(npc); +} + +static bool is_player_near(Vector spot, float distance) +{ + for (Entity_Player* player : g_game->playerManager.playerList) + if (vector_length(vector_sub(player->pos, spot)) < distance) return true; + return false; +} + +// ??? reappears ahead of his target, or on rings around it while a player stands within 150. +static void blue_teleport(Entity_NPC& npc) +{ + float reach = std::max(npc.v1.y, TELEPORT_REACH); + Entity& target = *npc.GetPlayerTarget(); + Vector heading = vector_is_zero(target.velocity) ? random_direction() : vector_normalized(target.velocity); + Room& room = *g_game->room; + Vector spot = room.GetClampedPosition(vector_add(target.pos, vector_scale(heading, reach)), npc.size); + + int tries = 0; + float turn = random_unit() * TELEPORT_FULL_TURN; + while (is_player_near(spot, TELEPORT_CLEARANCE)) + { + float angle = (float)(tries % TELEPORT_TURNS) * TELEPORT_TURN + turn; + float ring = (float)tries * TELEPORT_RING_STEP + TELEPORT_REACH; + spot = room.GetClampedPositionImpl(vector_add(target.pos, vector_scale(vector_from_angle(angle), ring)), + npc.size, npc.size, npc.size, npc.size); + if (++tries >= ISAAC_TELEPORT_TRIES) break; + } + isaac_log("??? teleport: %d tries\n", tries); + npc.pos = spot; + npc.PlaySound(SOUND_HELL_PORTAL1, 1, 2, false, 1); +} + +// ???'s teleport: he vanishes, then reappears near his target and goes back to idle. +static void blue_jump_update(Entity_NPC& npc) +{ + if (npc.i1 == STEP_VANISH) + { + if (vanish_update(npc)) npc.i1 = STEP_APPEAR; + return; + } + if (npc.i1 != STEP_APPEAR) return; + + npc.sprite.Play("3Appear"); + if (anim_frame_crossed(npc, 0)) blue_teleport(npc); + if (!npc_anim_is_done(npc)) return; + npc.i1 = STEP_VANISH; + npc.state = NPC_STATE_IDLE; +} + +// Isaac reappears anywhere in the room 100 from every player, in 20 tries. +static void isaac_teleport(Entity_NPC& npc) +{ + npc.isVisible = true; + npc.entityCollisionClass = ENTCOLL_ALL; + Room& room = *g_game->room; + int tries = 0; + do + { + float y = (room.bottomRightPos.y - room.topLeftPos.y) * random_unit() + room.topLeftPos.y; + float x = (room.bottomRightPos.x - room.topLeftPos.x) * random_unit() + room.topLeftPos.x; + npc.pos = vector_make(x, y); + } while (is_player_near(npc.pos, ISAAC_TELEPORT_CLEARANCE) && ++tries < ISAAC_TELEPORT_TRIES); + isaac_log("Isaac teleport: %d tries\n", tries); + npc_sound_play(SOUND_HELL_PORTAL1, 1, 2, champion_pitch_get(npc)); +} + +// One frame of a light wall: every 8 frames a slanted line of beams one step further across. False once none fits. +static bool wall_step(Entity_NPC& npc) +{ + Room& room = *g_game->room; + bool isLeft = npc.i1 < WALL_FROM_RIGHT; + int frame = npc.i1 - (isLeft ? WALL_FROM_LEFT : WALL_FROM_RIGHT); + Vector origin = vector_make(isLeft ? room.topLeftPos.x + WALL_INSET : room.bottomRightPos.x - WALL_INSET, + room.topLeftPos.y + WALL_INSET); + Vector line = vector_make(isLeft ? -WALL_BEAM_SPACING : WALL_BEAM_SPACING, WALL_BEAM_SPACING); + + RNG rng = WALL_JITTER_RNG; + rng._seed = (uint32_t)npc.projectileDelay; + Vector jitter = RandomVector((uint32_t)npc.projectileDelay); + float reach = rng.RandomFloat() * WALL_JITTER; + Vector step = vector_make((isLeft ? WALL_STEP : -WALL_STEP) + reach * jitter.x, reach * jitter.y); + if (frame % WALL_STEP_FRAMES != 0) return true; + + int index = frame / WALL_STEP_FRAMES; + float slant = (float)byte_get(npc, BYTE_WALL_SLANT) / WALL_SLANT_SCALE * (float)index; + Vector shift = vector_scale(vector_normalized(line), slant * WALL_STEP * std::sqrt(2.0f)); + Vector start = vector_add(vector_scale(step, (float)index), origin); + EntityConfig_Entity* config = g_manager->entityConfig.GetEntity(ENTITY_EFFECT, EFFECT_CRACK_THE_SKY, 0); + bool isInRoom = false; + for (int beam = WALL_BEAM_FIRST; beam < WALL_BEAM_END; beam++) + { + Vector spot = vector_add(vector_add(shift, vector_scale(line, (float)beam)), start); + if (!room.IsPositionInRoom(spot, WALL_BEAM_MARGIN)) continue; + isInRoom = true; + light_beam_spawn(npc, spot)->SetSize(BEAM_SIZE, config->collisionRadiusMulti, config->gridCollisionPoints); + } + return isInRoom; +} + +// Isaac's light walls: he vanishes, a wall sweeps the room from one top corner, then he reappears and attacks. +static void wall_update(Entity_NPC& npc, int ticks) +{ + if (byte_get(npc, BYTE_PHASE) < ISAAC_WINGED) return; + + if (npc.i1 == STEP_VANISH) + { + if (!vanish_update(npc)) return; + npc.i1 = (int)((Random() & 1) + 1) * WALL_FROM_LEFT; + byte_set(npc, BYTE_WALL_SLANT, (int)Random()); + npc.projectileDelay = (int)Random(); + npc.isVisible = false; + npc.entityCollisionClass = ENTCOLL_NONE; + npc.pos = Vector{}; + npc.velocity = Vector{}; + return; + } + if (npc.i1 == STEP_APPEAR) + { + npc.sprite.Play("3Appear"); + if (anim_frame_crossed(npc, 0)) isaac_teleport(npc); + if (!npc_anim_is_done(npc)) return; + npc.i1 = WALL_ATTACK_PATTERN; + npc.state = NPC_STATE_ATTACK; + byte_set(npc, BYTE_COOLDOWN, 0); + return; + } + + for (; ticks > 0 && npc.i1 >= WALL_FROM_LEFT && npc.i1 < WALL_END; ticks--, npc.i1++) + if (!wall_step(npc)) + { + npc.i1 = STEP_APPEAR; + return; + } +} + +// Hush's ??? dies into Hush: the shots about are gone and Hush rises at the top of the room to his own music. +static void hush_call(Entity_NPC& npc) +{ + Room& room = *g_game->room; + Vector position = vector_make(Room::GetCenterPos().x, room.topLeftPos.y + HUSH_DROP); + npc.maxHitPoints = 0; + room.entityList.bossMaxHealth = 0; + for (Entity* shot : entity_query_radius(npc.pos, SHOT_CLEAR_RADIUS, QUERY_PROJECTILES)) shot->isDead = true; + + Entity* hush = g_game->Spawn({.position = position, .spawner = &npc, .type = ENTITY_HUSH, .seed = Random()}); + hush->ClearEntityFlags(FLAG_APPEAR); + hush->Update(); + g_manager->musicManager.Crossfade(MUSIC_HUSH_BOSS, HUSH_MUSIC_FADE); +} + +// 00463100 Isaac (102.0), ??? (102.1) and Hush's ??? (102.2): sitting, standing and winged, with aimed shots, rings +// and bursts, light beams and walls, angelic babies, summons and teleports. Hush's ??? calls Hush as he dies. +void boss_isaac_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) return isaac_init(npc); + + int ticks = npc_ticks_get(npc); + if (byte_get(npc, BYTE_PHASE) == ISAAC_SITTING && Random() % WHIMPER_ODDS == 0) + npc.PlaySound(SOUND_SCARED_WHIMPER, 1, (int)(Random() % ISAAC_WHIMPER_DELAY_RANGE) + ISAAC_WHIMPER_DELAY_MIN, false, 1); + if (npc.pendingDamage > 0) + for (DamageEvent& event : npc.damageEvents) + if (event.source.type == ENTITY_EFFECT && event.source.variant == EFFECT_CRACK_THE_SKY) event.damage = 0; + + phase_update(npc); + if (byte_get(npc, BYTE_PHASE) < ISAAC_WINGED) + { + npc.velocity = vector_sub(npc.targetPosition, npc.pos); + npc.friction *= HELD_FRICTION; + } + else npc.friction *= WINGED_FRICTION; + + aimed_shots_update(npc); + blue_summons_update(npc, g_game->room->GetAliveEnemiesCount()); + if (byte_get(npc, BYTE_PHASE) == ISAAC_STANDING && npc.variant == ISAAC_FORM_CATHEDRAL) standing_powers_roll(npc, ticks); + standing_beams_update(npc, ticks); + + switch (npc.state) + { + case NPC_STATE_IDLE: + idle_update(npc, ticks); + break; + case NPC_STATE_ATTACK: + attack_update(npc, ticks); + break; + case NPC_STATE_ATTACK2: + wall_update(npc, ticks); + break; + case NPC_STATE_SPECIAL: + rise_update(npc); + break; + case NPC_STATE_JUMP: + blue_jump_update(npc); + break; + } + + if (npc.isDead && npc.variant == ISAAC_FORM_HUSH) hush_call(npc); + npc.v2.x = npc.health; +} + +// The babies, by variant: the plain baby, the angelic baby Isaac calls and Ultra Pride's baby. The Imp shares them. +enum BabyVariant +{ + BABY_PLAIN, + BABY_ANGELIC_VARIANT, + BABY_ULTRA_PRIDE, + BABY_WRINKLY +}; + +// Babies drift 0.33 toward their target and splat now and then. One within 200 in line shoots (Ultra Pride's a big +// homing shot, a summoned angelic baby two) at 8 (10 in hard mode), 35 frames apart. +constexpr float BABY_FRICTION = 0.7f; +constexpr float BABY_DRIFT = 0.33f; +constexpr float BABY_CONTROLLED_DRIFT = 0.1f; +constexpr float BABY_CONTROL_REACH = 100; +constexpr int BABY_SPLAT_ODDS = 10; +constexpr float BABY_SPLAT_MIN = 0.2f; +constexpr float BABY_SPLAT_RANGE = 0.3f; +constexpr float ANGEL_SHOT_RANGE = 200; +constexpr int BABY_SHOT_FRAMES = 7; +constexpr int BABY_SHOT_COOLDOWN = 35; +constexpr float BABY_SHOT_VOLUME = 0.85f; +constexpr float BABY_SHOT_FALL_ACCEL = -0.05f; +constexpr float BABY_SHOT_SPEED_MULTI = 1.07f; +constexpr float ANGEL_SHOT_SPEED = 8; +constexpr float BABY_SHOT_SPEED_HARD = 10; +constexpr float BABY_BIG_SCALE = 1.5f; +constexpr int BABY_SUMMONED = 1; + +// They blink away once restless: 20 after a hit, gaining one a frame while their target is near in line (within 20 +// on an axis and 400 away) and a little each frame. Past 20 they pick a spot 60 to 310 away (50 to 120 from the +// target for an angelic baby, else 200 off its axes) on a free cell, in two tries, and past 40 they vanish to it, +// reappearing 24 frames later. +constexpr float RESTLESS_HIT = 20; +constexpr float RESTLESS_LINE = 20; +constexpr float RESTLESS_NEAR = 400; +constexpr float RESTLESS_DRIFT = 0.1f; +constexpr float RESTLESS_PICK = 20; +constexpr float RESTLESS_BLINK = 40; +constexpr int BLINK_TRIES = 2; +constexpr float BLINK_REACH_MIN = 60; +constexpr float BLINK_REACH_RANGE = 250; +constexpr float ANGELIC_BLINK_MIN = 50; +constexpr float ANGELIC_BLINK_MAX = 120; +constexpr float BLINK_AXIS_SLACK = 20; +constexpr float BLINK_TARGET_MIN = 200; +constexpr int BLINK_PATH_LIMIT = 499; +constexpr int BABY_BLINK_FRAMES = 24; +constexpr int GRID_COLUMN_ORIGIN = 40; +constexpr int GRID_ROW_ORIGIN = 120; +constexpr int BABY_GRID_CELL = 40; + +// The Imp growls one time in 90 a second later and, one roll in 20 while it may attack, shoots every 10 frames for 20 +// to 49 frames (50 controlled) at 10, its target's lead 5 frames ahead, then rests 30. Shots within 100 push it aside. +constexpr int IMP_GROWL_ODDS = 90; +constexpr int IMP_GROWL_DELAY = 60; +constexpr int IMP_ATTACK_ODDS = 20; +constexpr float IMP_CONTROLLED_RANGE = 1000; +constexpr int IMP_ATTACK_MIN = 20; +constexpr int IMP_ATTACK_RANGE = 30; +constexpr int IMP_ATTACK_CONTROLLED = 50; +constexpr int IMP_SHOT_SPACING = 10; +constexpr float IMP_SHOT_SPEED = 10; +constexpr float IMP_SHOT_LEAD = 5; +constexpr int IMP_REST = 30; +constexpr float IMP_DODGE_RADIUS = 100; +constexpr float IMP_DODGE_REACH_SQUARED = 10000; +constexpr float IMP_DODGE_MIN = 2; +constexpr float IMP_CHARGE_RATE = 0.05f; +constexpr float IMP_CHARGE_PUSH = 1.6f; +constexpr float IMP_RECHARGE_RATE = 0.1f; +constexpr int CONTROL_ACTION_DASH = 8; +constexpr int CONTROL_ACTION_BLINK = 9; +constexpr int CONTROL_TARGET_BLINK = 2; +constexpr float BLINK_PATH_SPEED = 4; + +static bool is_imp(const Entity_NPC& npc) +{ + return npc.type == ENTITY_IMP; +} + +// A blink spot: a random one 60 to 310 out, kept if it suits the baby and lies on a free cell, snapped to its center. +static void blink_spot_pick(Entity_NPC& npc) +{ + for (int tries = 0; vector_is_zero(npc.targetPosition) && tries < BLINK_TRIES; tries++) + { + float angle = random_unit() * RANDOM_HALF_TURN * 2; + float reach = random_unit() * BLINK_REACH_RANGE + BLINK_REACH_MIN; + Vector spot = vector_make(std::cos(angle) * reach + npc.pos.x, std::sin(angle) * reach + npc.pos.y); + Vector fromTarget = vector_sub(npc.GetPlayerTarget()->pos, spot); + float distance = vector_length(fromTarget); + bool isSuited = npc.variant == BABY_ANGELIC_VARIANT + ? distance > ANGELIC_BLINK_MIN && distance < ANGELIC_BLINK_MAX + : std::abs(fromTarget.x) > BLINK_AXIS_SLACK && std::abs(fromTarget.y) > BLINK_AXIS_SLACK && + distance > BLINK_TARGET_MIN; + if (!isSuited) continue; + + Room& room = *g_game->room; + int column = (int)((spot.x - GRID_COLUMN_ORIGIN) / BABY_GRID_CELL + 0.5f); + int row = (int)((spot.y - GRID_ROW_ORIGIN) / BABY_GRID_CELL + 0.5f); + if (column < 0 || column >= room.gridWidth || row < 0 || row >= room.gridHeight) continue; + int cell = row * room.gridWidth + column; + if (cell < 0 || (cell < ROOM_GRID_CELLS && room.gridPaths[cell] > BLINK_PATH_LIMIT)) continue; + if (room.GetGridCollision(cell) != 0) continue; + npc.targetPosition = vector_make((float)(cell % room.gridWidth * BABY_GRID_CELL + GRID_COLUMN_ORIGIN), + (float)(cell / room.gridWidth * BABY_GRID_CELL + GRID_ROW_ORIGIN)); + } +} + +// Starts a blink: the Vanish animation, no shadow, and the Imp's warp sound. +static void blink_start(Entity_NPC& npc) +{ + npc.state = NPC_STATE_JUMP; + npc.stateFrame = 0; + npc_anim_restart(npc.sprite, "Vanish"); + npc.shadowSize = 0; +} + +// The Imp rolls to attack while hostile (controlled, while aiming), then counts down its rest. +static void imp_move_update(Entity_NPC& npc, int ticks) +{ + if (Random() % IMP_GROWL_ODDS == 0) npc_sound_play(SOUND_IMP_GROWL, 1, IMP_GROWL_DELAY, 1); + if (npc.projectileDelay < 1) + { + bool isAttacking = false; + if (npc.controllerID != -1) isAttacking = npc.IsTargetInAttackRange(IMP_CONTROLLED_RANGE, BABY_SHOT_FRAMES, false); + else if (Random() % IMP_ATTACK_ODDS == 0) isAttacking = npc.IsHostileTo(npc.GetPlayerTarget()); + if (isAttacking) + { + npc.state = NPC_STATE_ATTACK; + npc.projectileCooldown = + npc.controllerID == -1 ? (int)(Random() % IMP_ATTACK_RANGE) + IMP_ATTACK_MIN : IMP_ATTACK_CONTROLLED; + npc.SpawnControlTarget(0, -1); + } + } + if (npc.projectileDelay > 0) npc.projectileDelay -= ticks; +} + +// A baby splats now and then and shoots its target once in range and rested. +static void baby_move_update(Entity_NPC& npc, int ticks) +{ + if (Random() % BABY_SPLAT_ODDS == 0) npc.MakeSplat(random_unit() * BABY_SPLAT_RANGE + BABY_SPLAT_MIN); + if (npc.projectileCooldown < 1 && npc.IsTargetInAttackRange(ANGEL_SHOT_RANGE, BABY_SHOT_FRAMES, false)) + { + npc.projectileCooldown = BABY_SHOT_COOLDOWN; + npc_anim_restart(npc.sprite, "Attack"); + npc.UpdateControllerMovement(true); + } + if (npc.sprite.animState.animData && npc.sprite.IsEventTriggered("Shoot")) + { + npc.UpdateControllerMovement(false); + npc.PlaySound(SOUND_FLOATY_BABY_ROAR, BABY_SHOT_VOLUME, 2, false, 1); + ProjectileParams params; + params.fallingAccelModifier = BABY_SHOT_FALL_ACCEL; + params.velocityMulti = BABY_SHOT_SPEED_MULTI; + ProjectilesMode mode = PROJECTILES_SINGLE; + if (npc.variant == BABY_ULTRA_PRIDE) + { + params.bulletFlags |= PROJECTILE_SMART; + params.scale = BABY_BIG_SCALE; + } + else if (npc.variant == BABY_ANGELIC_VARIANT && npc.subtype != BABY_SUMMONED) mode = PROJECTILES_TWO; + float speed = game_is_hard_mode() ? BABY_SHOT_SPEED_HARD : ANGEL_SHOT_SPEED; + Vector aim = vector_sub(npc.GetPlayerTarget()->pos, npc.pos); + if (npc.controllerID != -1 && !vector_is_zero(npc.controllerMovement)) aim = npc.controllerMovement; + npc.FireProjectiles(npc.pos, vector_scale(vector_normalized(aim), speed), mode, params); + } + if (npc.projectileCooldown > 0) npc.projectileCooldown -= ticks; +} + +// Moving: attacks, the Move loop, and growing restless until a blink. +static void baby_wander_update(Entity_NPC& npc, int ticks, Vector toTarget) +{ + npc.entityCollisionClass = ENTCOLL_ALL; + if (is_imp(npc)) imp_move_update(npc, ticks); + else baby_move_update(npc, ticks); + if (npc_anim_is_done(npc)) npc_anim_loop(npc.sprite, "Move"); + + if (npc.pendingDamage > 0) npc.v1.x = RESTLESS_HIT; + bool isInLine = std::abs(toTarget.x) < RESTLESS_LINE || std::abs(toTarget.y) < RESTLESS_LINE; + if (isInLine && vector_length(toTarget) < RESTLESS_NEAR) npc.v1.x += 1; + npc.v1.x += random_unit() * RESTLESS_DRIFT; + + if (npc.controllerID != -1) + { + if (!npc.IsControllerActionPressed(CONTROL_ACTION_BLINK)) return; + blink_start(npc); + npc.targetPosition = npc.pos; + return; + } + if (npc.v1.x > RESTLESS_PICK) blink_spot_pick(npc); + if (npc.v1.x <= RESTLESS_BLINK || vector_is_zero(npc.targetPosition)) return; + blink_start(npc); + if (is_imp(npc)) npc_sound_play(SOUND_IMP_WARP_OUT, 1, 2, 1); +} + +// Blinking: gone and harmless, then back at its spot 24 frames on, and moving again once the animation ends. +static void baby_blink_update(Entity_NPC& npc) +{ + if (npc.controllerID != -1 && !vector_is_zero(npc.targetPosition)) + { + npc.SpawnControlTarget(CONTROL_TARGET_BLINK, -1); + npc.pathfinder.FindGridPath(Vector{}, BLINK_PATH_SPEED, 0, DIRECT_PATH_FAR); + npc.targetPosition = npc.pos; + } + npc.entityCollisionClass = ENTCOLL_NONE; + if (npc.stateFrame > BABY_BLINK_FRAMES && !vector_is_zero(npc.targetPosition)) + { + npc.shadowSize = npc.config->shadowSize; + npc_anim_restart(npc.sprite, "Vanish2"); + npc.stateFrame = 0; + npc.pos = npc.targetPosition; + npc.targetPosition = Vector{}; + npc.v1.x = 0; + npc.ClearChild(); + if (is_imp(npc)) npc_sound_play(SOUND_IMP_WARP_IN, 1, 2, 1); + return; + } + if (npc_anim_is_done(npc) && vector_is_zero(npc.targetPosition)) npc.state = NPC_STATE_MOVE; +} + +// The Imp's volley: a shot every 10 frames at its target's lead (controlled, at its aim mark), then a rest. +static void imp_attack_update(Entity_NPC& npc, int ticks) +{ + npc.SpawnControlTarget(0, -1); + for (; ticks > 0; ticks--) + { + if (npc.projectileCooldown < 1) + { + npc.state = NPC_STATE_MOVE; + npc.projectileDelay = IMP_REST; + return; + } + if (--npc.projectileCooldown % IMP_SHOT_SPACING != 0) continue; + + npc_anim_restart(npc.sprite, "Attack"); + Entity& target = *npc.GetPlayerTarget(); + Vector aim = vector_add(target.pos, vector_scale(target.velocity, IMP_SHOT_LEAD)); + if (npc.controllerID != -1) aim = npc.aimTargetEffect.get() ? npc.aimTargetEffect->pos : npc.pos; + ProjectileParams params; + npc.FireProjectiles(npc.pos, vector_scale(vector_normalized(vector_sub(aim, npc.pos)), IMP_SHOT_SPEED), + PROJECTILES_SINGLE, params); + if (is_imp(npc)) npc_sound_play(SOUND_IMP_SHOOT, 1, 2, 1); + } +} + +// The Imp sidesteps the player's tears within 100, more the further its target is. +static void imp_dodge(Entity_NPC& npc, float targetDistanceSquared) +{ + std::vector tears = entity_query_radius(npc.pos, IMP_DODGE_RADIUS, QUERY_TEARS); + if (tears.empty()) return; + + float urgency = std::clamp(targetDistanceSquared, 0.0f, IMP_DODGE_REACH_SQUARED) / IMP_DODGE_REACH_SQUARED; + Vector dodge{}; + int count = 0; + for (Entity* tear : tears) + { + Vector away = vector_sub(npc.pos, tear->pos); + if (vector_dot(away, tear->velocity) <= 0) continue; + + float falloff = 1 - vector_length_squared(away) / IMP_DODGE_REACH_SQUARED; + Vector side = vector_make(tear->velocity.y, -tear->velocity.x); + if (vector_dot(away, side) < 0) side = vector_scale(side, -1); + float push = (random_unit() * 2 + IMP_DODGE_MIN) * falloff * urgency; + dodge = vector_add(dodge, vector_resized(side, push)); + count++; + } + if (count > 0) npc.velocity = vector_add(npc.velocity, vector_scale(dodge, npc.speedMultiplier / (float)count)); +} + +// A controlled Imp dashes while its action is held, slowing as its charge fills, and recharges once released. +static void imp_dash(Entity_NPC& npc, Vector toTarget) +{ + if (!npc.IsControllerActionPressed(CONTROL_ACTION_DASH)) + { + if (npc.v2.x > 0) npc.v2.x = -1; + return; + } + if (npc.v2.x < 0) return; + + npc.v2.x = std::min(npc.speedMultiplier * IMP_CHARGE_RATE + npc.v2.x, 1.0f); + npc_push(npc, vector_scale(vector_normalized(toTarget), IMP_CHARGE_PUSH * (1 - npc.v2.x))); +} + +// 0052ae30 The baby (38) and the Imp (259): drifting, shooting and blinking about, the Wrinkly Baby apart. +void npc_baby_update(Entity_NPC& npc) +{ + if (npc.type == ENTITY_BABY && npc.variant == BABY_WRINKLY) return (void)NpcAI::ENTITY_WRINKLY_BABY(&npc); + if (npc.state == NPC_STATE_INIT) + { + npc.sprite.Play("Move"); + npc.state = NPC_STATE_MOVE; + return; + } + + int ticks = npc_ticks_get(npc); + grid_path_claim(npc.pos); + npc.friction *= BABY_FRICTION; + Vector toTarget = vector_sub(npc.CalcTargetPosition(0), npc.pos); + if (npc.controllerID != -1) toTarget = vector_scale(npc.GetControllerInput(0), BABY_CONTROL_REACH); + + switch (npc.state) + { + case NPC_STATE_MOVE: + baby_wander_update(npc, ticks, toTarget); + break; + case NPC_STATE_JUMP: + baby_blink_update(npc); + break; + case NPC_STATE_ATTACK: + imp_attack_update(npc, ticks); + break; + } + + if (is_imp(npc) && npc.v2.x < 0) npc.v2.x = std::min(npc.speedMultiplier * IMP_RECHARGE_RATE + npc.v2.x, 0.0f); + if (npc.projectileCooldown < 1) + { + npc_push(npc, vector_scale(vector_normalized(toTarget), BABY_DRIFT)); + if (is_imp(npc) && npc.controllerID == -1) imp_dodge(npc, vector_length_squared(toTarget)); + else if (is_imp(npc)) imp_dash(npc, toTarget); + } + else if (npc.controllerID != -1) npc_push(npc, vector_scale(vector_normalized(toTarget), BABY_CONTROLLED_DRIFT)); + npc.stateFrame += ticks; +} + +// The flies Isaac's summons hold around him: a Pooter 85 out and turned back, an attack fly or Moter 55 out and turned +// ahead, both easing toward their spot at 6 or 8. With no Isaac left they turn into plain flies. +constexpr float ORBIT_REACH = 100; +constexpr float ORBIT_REACH_POOTER = 85; +constexpr float ORBIT_REACH_FLY = 55; +constexpr float ISAAC_ORBIT_TURN = 20; +constexpr float ISAAC_ORBIT_SPEED = 10; +constexpr float ORBIT_SPEED_POOTER = 6; +constexpr float ORBIT_SPEED_FLY = 8; +constexpr float ISAAC_ORBIT_EASE = 0.39999998f; + +// 004568d0 A fly Isaac summoned circles the nearest Isaac, or becomes a plain fly once none is left. +void npc_isaac_fly_update(Entity_NPC& npc) +{ + std::vector isaacs = entity_query(ENTITY_ISAAC_BOSS, -1); + if (isaacs.empty()) + { + npc.spawnerType = 0; + npc.subtype = 0; + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + return; + } + + Vector center = isaacs.front()->pos; + Vector offset = vector_sub(center, npc.pos); + Vector toward = vector_normalized(offset); + Vector around = vector_make(-offset.x, -offset.y); + float reach = ORBIT_REACH; + float speed = ISAAC_ORBIT_SPEED; + if (npc.subtype == SUMMON_SUBTYPE_POOTER || npc.subtype == SUMMON_SUBTYPE) + { + bool isPooter = npc.subtype == SUMMON_SUBTYPE_POOTER; + float turn = isPooter ? -ISAAC_ORBIT_TURN : ISAAC_ORBIT_TURN; + around = vector_make(around.x + toward.y * turn, around.y - toward.x * turn); + reach = isPooter ? ORBIT_REACH_POOTER : ORBIT_REACH_FLY; + speed = isPooter ? ORBIT_SPEED_POOTER : ORBIT_SPEED_FLY; + } + npc.targetPosition = vector_add(center, vector_resized(around, reach)); + + Vector step = vector_sub(npc.targetPosition, npc.pos); + if (vector_length(step) > speed) step = vector_resized(step, speed); + float ease = 1 - npc_friction_scaled(ISAAC_ORBIT_EASE, npc.speedMultiplier); + npc.velocity = vector_make(npc.velocity.x + (step.x - npc.velocity.x) * ease, + npc.velocity.y + (step.y - npc.velocity.y) * ease); + npc.entityGridCollisionClass = GRIDCOLL_NONE; +} diff --git a/src/boss_lamb.cpp b/src/boss_lamb.cpp new file mode 100644 index 0000000..94c0610 --- /dev/null +++ b/src/boss_lamb.cpp @@ -0,0 +1,621 @@ +#include "boss_ai.h" +#include "entity_laser.h" +#include "npc_caves.h" +#include "sfx_manager.h" +#include +#include + +// The Lamb's parts, by variant: the Lamb (his head once split) and the body he leaves behind. +enum LambVariant +{ + LAMB_HEAD, + LAMB_BODY = 10 +}; + +// His form (i1): whole, or a head flying alone once his body falls away. +enum LambForm +{ + LAMB_WHOLE = 1, + LAMB_HEADLESS +}; + +// Attacks (states): a spread of shots, a head dash, a long pattern of shots and the head's cross of beams. +enum LambAttack +{ + LAMB_SHOTS = NPC_STATE_ATTACK, + LAMB_DASH = NPC_STATE_ATTACK2, + LAMB_PATTERN = NPC_STATE_ATTACK3, + LAMB_BEAMS = NPC_STATE_ATTACK4 +}; + +// He walks at 2, rolling for an attack every 60 to 89 frames (whole, the spread or the pattern evenly; alone, a +// quarter each for the spread, the pattern, the beams and a dash). He splits below half health, his body rising. +constexpr float LAMB_SPEED = 2; +constexpr int LAMB_ROLL_MIN = 60; +constexpr int LAMB_ROLL_RANGE = 30; +constexpr int WHOLE_ROLL_RANGE = 100; +constexpr int WHOLE_SHOTS_ODDS = 50; +constexpr int HEAD_ROLL_RANGE = 99; +constexpr int HEAD_SHOTS_ODDS = 25; +constexpr int HEAD_PATTERN_ODDS = 50; +constexpr int HEAD_BEAMS_ODDS = 75; +constexpr float SPLIT_THRESHOLD = 0.5f; +constexpr int LAMB_CRY_DELAY = 60; +constexpr ColorMod LAMB_SPLAT_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0.1f, 0.1f, 0.15f}}; + +// The head dashes at 7.5, 10 or 12 (or flies past its target, half again as far, in 8 frames) for 30 frames, along +// whichever axis its target is within 20 of (the nearer one while the body rages), homing by twice its speed. +constexpr int DASH_SPEED_PICKS = 6; +constexpr float DASH_SPEEDS[] = {7.5f, 10, 12}; +constexpr float DASH_AXIS_SLACK = 20; +constexpr int HEAD_DASH_FRAMES = 30; +constexpr int DASH_PAST_FRAMES = 8; +constexpr float DASH_PAST_SCALE = 0.5f; +constexpr int DASH_CRY_DELAY = 50; +constexpr float DASH_HOMING = 2; + +// The spreads: whole, 12 exploding shots about him; alone, 15 big homing ones at his target. The body sends 12 and up +// to 4 attack flies at 10. +constexpr int SWARM_SHOTS = 12; +constexpr int HEAD_SHOTS = 15; +constexpr float HEAD_SHOT_SCALE = 1.5f; +constexpr int BODY_FLY_PICKS = 5; +constexpr float BODY_FLY_SPEED = 10; +constexpr ColorMod LAMB_SHOT_COLOR = {{1, 1, 1, 1}, {0.7f, 0.7f, 1, 1}, {0, 0, 0}}; + +// The long pattern lasts 120 frames, one of 10 picked as it starts. In the first four he drifts at a third of his +// speed and, whole, one roll in 2 every 30 frames throws an attack fly at 10 while fewer than 15 others are about. +constexpr int PATTERN_PICKS = 10; +constexpr int PATTERN_DRIFTING = 4; +constexpr float PATTERN_DRIFT = 0.333f; +constexpr int PATTERN_FLY_SPACING = 30; +constexpr int PATTERN_FLY_CROWD = 15; +constexpr int PATTERN_FRAMES = 120; + +// The pattern's rings are 1.8 shots from 5 up, floating. Turning rings of 5 at 12 every 3 frames, a turn each 240 +// frames, bursting triples at 8 or rings of 10 at 9 every 22. The homing fans: 7 at 9 every 8 frames within a +// cone, wavering a twentieth turn or swinging over 30 frames, 8 every 13 in a half turn, and triples every 10. +constexpr float PATTERN_HEIGHT = 5; +constexpr float PATTERN_SCALE = 1.8f; +constexpr float PATTERN_FALL_ACCEL = -0.06f; +constexpr float PATTERN_FALL_SPEED = -2; +constexpr int TURNING_SPACING = 3; +constexpr float TURNING_RATE = 0.125f; +constexpr float TURNING_PERIOD = 30; +constexpr float TURNING_SPEED = 12; +constexpr int TURNING_COUNT = 5; +constexpr int RING_SPACING = 22; +constexpr float BURSTING_SPEED = 8; +constexpr int BURSTING_COUNT = 3; +constexpr int WIDE_RING_COUNT = 10; +constexpr float FAN_SPEED = 9; +constexpr int FAN_COUNT = 7; +constexpr int FAN_SPACING = 8; +constexpr float FAN_HOMING = 0.3f; +constexpr float LAMB_FAN_DOT_LIMIT = 0.4f; +constexpr float FAN_WAVER = 0.1f; +constexpr float FAN_HALF_STEP = 0.44879895f; +constexpr int WIDE_FAN_SPACING = 13; +constexpr int WIDE_FAN_COUNT = 8; +constexpr int TRIPLE_SPACING = 10; +constexpr int TRIPLE_COUNT = 3; +constexpr float TRIPLE_HOMING = 0.65f; +constexpr float PATTERN_VOLUME = 0.6f; +constexpr int PATTERN_CRY_MIN = 20; +constexpr int PATTERN_CRY_RANGE = 30; + +// The head's beams: four 30 above him with their ends 20 up, held 60 to 89 frames (90 when straight or off the +// room's middle), straight or turning 2 a frame either way after a 15 to 44 frame pause. +constexpr int BEAMS_MODES = 3; +constexpr int BEAMS_TIMEOUT_MIN = 60; +constexpr int BEAMS_TIMEOUT_RANGE = 30; +constexpr int BEAMS_TIMEOUT_STRAIGHT = 90; +constexpr int BEAMS_HOLD_SLACK = 15; +constexpr float BEAMS_ROOM_MARGIN = 70; +constexpr float BEAMS_RISE = 30; +constexpr float BEAMS_END_RISE = -20; +constexpr float BEAMS_DEPTH = 1000; +constexpr float BEAMS_TURN = 90; +constexpr float BEAMS_TURN_SPEED = 2; +constexpr int BEAMS_DELAY_MIN = 15; + +// The body: it sways in place with a ghostly flame 4 across and 2 down, and rolls to attack every 15 frames (one in 8, +// or one in 2 while raging, spending 4 of its rage) while the head is free. Hits on it pile up as rage, up to 35, +// draining a quarter a frame, raging past 5. Dying, it darkens the room for 600 frames and stays as a husk. +constexpr float BODY_SPRITE_OFFSET = -4; +static const Vector BODY_FLAME_OFFSET = vector_make(4, 2); +constexpr ColorMod BODY_FLAME_COLOR = {{1, 1, 1, 0.5f}, {0, 0, 0, 0}, {0, 0, 1}}; +constexpr int BODY_ROLL_SPACING = 15; +constexpr int BODY_ROLL_MASK = 7; +constexpr float BODY_RAGE = 5; +constexpr float BODY_RAGE_SPENT = 4; +constexpr float RAGE_CAP = 35; +constexpr float RAGE_DRAIN = 0.25f; +constexpr int BODY_DARKNESS_FRAMES = 600; +constexpr float BODY_POOF_RISE = -10; +constexpr float BODY_DEATH_VOLUME = 0.85f; + +// The attacks are off while he is confused, feared or shrunk. +constexpr uint64_t LAMB_STUNNED = FLAG_CONFUSION | FLAG_FEAR | FLAG_SHRINK; + +static bool anim_is(const Entity_NPC& npc, std::string_view name) +{ + const AnimationData* data = npc.sprite.animState.animData; + return data && data->name == name; +} + +// Whether his animation stopped playing on a given one. +static bool anim_ended(const Entity_NPC& npc, std::string_view name) +{ + return anim_is(npc, name) && !npc.sprite.animState.isPlaying; +} + +// Restarts an animation once the current one stops, unless it is that one and does not loop. +static void anim_resume(Entity_NPC& npc, std::string_view name) +{ + const AnimationState& anim = npc.sprite.animState; + if (anim.animData && anim.isPlaying) return; + if (anim.animData && anim.animData->name == name && !anim.animData->isLooping) return; + npc_anim_restart(npc.sprite, name); +} + +// The first of his parts of a variant in the room, if any. +static Entity_NPC* lamb_part_find(int variant) +{ + std::vector parts = entity_query(ENTITY_THE_LAMB, variant); + return parts.empty() ? nullptr : static_cast(parts.front()); +} + +// Back to walking, idle, with a fresh wait before the next attack. +static void walk_resume(Entity_NPC& npc, std::string_view idle) +{ + npc.state = NPC_STATE_MOVE; + if (!idle.empty()) npc.sprite.Play(idle); + npc.stateFrame = (int)(Random() % LAMB_ROLL_RANGE) + LAMB_ROLL_MIN; +} + +// Below half health the whole Lamb splits: his head rises out of reach as his body falls away and stands. +static void lamb_split(Entity_NPC& npc) +{ + npc.i1 = LAMB_HEADLESS; + npc.state = NPC_STATE_SPECIAL; + npc_anim_restart(npc.sprite, "Death"); + g_game->Spawn({.position = npc.pos, .spawner = &npc, .type = ENTITY_THE_LAMB, .variant = LAMB_BODY, + .seed = Random()}); + npc.isInvincible = true; + npc.PlaySound(SOUND_MONSTER_YELL_B, 1, LAMB_CRY_DELAY, false, 1); + npc.isDead = false; + npc.health = std::max(npc.health, 0.0f); +} + +// The first update: the Lamb starts walking, his body stands where it fell with its ghostly flame. Both splat black. +static void lamb_init(Entity_NPC& npc) +{ + if (npc.variant == LAMB_BODY) + { + npc.state = NPC_STATE_SPECIAL; + npc.targetPosition = npc.pos; + npc.sprite.offset = vector_make(BODY_SPRITE_OFFSET, 0); + Entity* flame = g_game->Spawn({.position = vector_add(npc.pos, BODY_FLAME_OFFSET), .spawner = &npc, + .type = ENTITY_EFFECT, .variant = EFFECT_BLUE_FLAME, .seed = Random()}); + flame->SetColor(BODY_FLAME_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + flame->SetCollisionDamage(0); + flame->Update(); + npc.child = flame; + npc_anim_loop(npc.sprite, "Body"); + } + else + { + npc.state = NPC_STATE_MOVE; + npc.aiFloat = LAMB_SPEED; + uint32_t wait = Random(); + npc.i1 = LAMB_WHOLE; + npc.stateFrame = (int)(wait % LAMB_ROLL_RANGE) + LAMB_ROLL_MIN; + } + npc.v2.x = npc.health; + npc.splatColor = LAMB_SPLAT_COLOR; +} + +// The head alone, rolling for a dash: along the axis its target is near, or past the target when it rolls no speed. +static void head_dash_roll(Entity_NPC& npc, Vector toTarget, bool isBodyRaging) +{ + if (npc.HasEntityFlags(LAMB_STUNNED)) return; + + uint32_t pick = Random() % DASH_SPEED_PICKS; + float speed = pick < std::size(DASH_SPEEDS) ? DASH_SPEEDS[pick] : 0; + float across = std::abs(toTarget.x); + float along = std::abs(toTarget.y); + if (across < DASH_AXIS_SLACK || (isBodyRaging && across < along)) + { + npc.state = LAMB_DASH; + npc.sprite.Play(toTarget.y >= 0 ? "HeadDashDown" : "HeadDashUp"); + npc.v1 = vector_make(0, toTarget.y >= 0 ? speed : -speed); + npc.stateFrame = HEAD_DASH_FRAMES; + } + else if (along < DASH_AXIS_SLACK || (isBodyRaging && along < across)) + { + npc.state = LAMB_DASH; + npc.sprite.Play("HeadDashSide"); + npc.v1 = vector_make(toTarget.x < 0 ? -speed : speed, 0); + npc.stateFrame = HEAD_DASH_FRAMES; + } + if (!vector_is_zero(npc.v1)) return; + + Vector targetPos = npc.GetPlayerTarget()->pos; + npc.targetPosition = vector_add(targetPos, vector_scale(toTarget, DASH_PAST_SCALE)); + npc.stateFrame = DASH_PAST_FRAMES; +} + +// Walking toward his target until his wait runs out, then picking an attack. +static void walk_update(Entity_NPC& npc, bool isBodyRaging) +{ + bool isWhole = npc.i1 == LAMB_WHOLE; + anim_resume(npc, isWhole ? "Idle" : "HeadIdle"); + Vector toTarget = vector_sub(npc.CalcTargetPosition(0), npc.pos); + npc.velocity = vector_scale(vector_normalized(toTarget), npc.aiFloat); + if (npc.stateFrame-- > 0) return; + + if (isWhole) + { + bool isShots = Random() % WHOLE_ROLL_RANGE < WHOLE_SHOTS_ODDS; + npc.state = isShots ? LAMB_SHOTS : LAMB_PATTERN; + if (!isShots) npc.stateFrame = 0; + npc.sprite.Play("Charge"); + return; + } + uint32_t pick = Random() % HEAD_ROLL_RANGE; + if (pick >= HEAD_BEAMS_ODDS) return head_dash_roll(npc, toTarget, isBodyRaging); + + npc.state = pick < HEAD_SHOTS_ODDS ? LAMB_SHOTS : pick < HEAD_PATTERN_ODDS ? LAMB_PATTERN : LAMB_BEAMS; + if (npc.state == LAMB_PATTERN) npc.stateFrame = 0; + npc.sprite.Play("HeadCharge"); +} + +// The spreads once charged: whole, exploding shots all about, alone, big homing ones at his target. The body, its +// own spread with a few attack flies. +static void shots_update(Entity_NPC& npc) +{ + npc.velocity = Vector{}; + if (npc.sprite.animState.isPlaying && (anim_is(npc, "Charge") || anim_is(npc, "HeadCharge"))) + npc.PlaySound(SOUND_MONSTER_GRUNT_2, 1, LAMB_CRY_DELAY, false, 1); + + if (npc.variant == LAMB_BODY) + { + npc.sprite.Play("BodyAttack"); + if (npc.sprite.IsEventTriggered("Shoot")) + { + ProjectileParams params; + params.color = LAMB_SHOT_COLOR; + npc.FireBossProjectiles(SWARM_SHOTS, Vector{}, 0, params); + npc.PlaySound(SOUND_MEATHEADSHOOT, 1, 2, false, 1); + for (uint32_t flies = Random() % BODY_FLY_PICKS; flies > 0; flies--) + { + uint32_t seed = Random(); + Vector velocity = vector_scale(random_direction(), BODY_FLY_SPEED); + g_game->Spawn({.position = npc.pos, .velocity = velocity, .spawner = &npc, + .type = ENTITY_ATTACKFLY, .seed = seed}); + } + } + if (npc_anim_is_done(npc)) npc.state = NPC_STATE_SPECIAL; + return; + } + if (npc.i1 != LAMB_WHOLE && npc.variant != LAMB_HEAD) return; + + bool isWhole = npc.i1 == LAMB_WHOLE; + if (npc_anim_is_done(npc) && anim_is(npc, isWhole ? "Charge" : "HeadCharge")) + { + ProjectileParams params; + Vector target{}; + int count = SWARM_SHOTS; + if (isWhole) + { + npc.sprite.Play("Swarm"); + params.bulletFlags |= PROJECTILE_EXPLODE; + params.color = LAMB_SHOT_COLOR; + } + else + { + npc.sprite.Play("HeadShoot"); + params.bulletFlags |= PROJECTILE_SMART; + params.scale = HEAD_SHOT_SCALE; + count = HEAD_SHOTS; + } + npc.PlaySound(SOUND_BOSS_GURGLE_ROAR, 1, LAMB_CRY_DELAY, false, 1); + if (!isWhole) target = npc.GetPlayerTarget()->pos; + npc.FireBossProjectiles(count, target, 0, params); + return; + } + if (npc_anim_is_done(npc)) walk_resume(npc, isWhole ? "Idle" : "HeadIdle"); +} + +// The head's dash: crying, it flies along its dash homing a little, or past its target, until it hits a wall. +static void dash_update(Entity_NPC& npc) +{ + npc.velocity = Vector{}; + if (npc.i1 == LAMB_WHOLE) return; + if (npc.stateFrame-- <= 0 || npc.HasEntityFlags(LAMB_STUNNED)) + { + npc.entityCollisionClass = ENTCOLL_ALL; + return walk_resume(npc, "HeadIdle"); + } + + npc.PlaySound(SOUND_MONSTER_YELL_A, 1, DASH_CRY_DELAY, false, 1); + if (vector_is_zero(npc.v1)) + { + npc.entityCollisionClass = ENTCOLL_NONE; + npc.sprite.isFlipX = false; + if (npc.isCollidesWithGrid) npc.stateFrame = 0; + npc.velocity = vector_sub(npc.targetPosition, npc.pos); + if (npc.stateFrame != 0) npc.velocity = vector_scale(npc.velocity, 1 / (float)npc.stateFrame); + return; + } + npc.velocity = npc.v1; + if (npc.isCollidesWithGrid) npc.stateFrame = 0; + npc.sprite.isFlipX = npc.v1.x < 0; + Vector homing = vector_normalized(vector_sub(npc.CalcTargetPosition(0), npc.pos)); + npc.velocity = vector_add(npc.velocity, vector_scale(homing, npc.aiFloat * DASH_HOMING * npc.speedMultiplier)); +} + +// 004830e0 One frame of the Lamb's long pattern, its shots every few frames: turning rings, rings bursting or wide, +// then homing fans aimed at his target (straight, turned, wavering or swinging), a fan of 8, and homing triples. +static void lamb_pattern_fire(Entity_NPC& npc, int pattern, int frame) +{ + ProjectileParams params; + params.heightModifier = PATTERN_HEIGHT; + params.scale = PATTERN_SCALE; + params.fallingAccelModifier = PATTERN_FALL_ACCEL; + params.fallingSpeedModifier = PATTERN_FALL_SPEED; + Vector aim = vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos)); + float aimAngle = std::atan2(aim.y, aim.x); + float speed = FAN_SPEED; + int count = FAN_COUNT; + + if (pattern < PATTERN_DRIFTING) + { + params.color = LAMB_SHOT_COLOR; + if (pattern <= 1) + { + if (frame % TURNING_SPACING != 0) return; + float turn = (float)frame * (pattern == 0 ? TURNING_RATE : -TURNING_RATE); + speed = TURNING_SPEED; + count = TURNING_COUNT; + params.circleAngle = turn / TURNING_PERIOD * 2 * PI_F; + } + else + { + if (frame % RING_SPACING != 0) return; + bool isBursting = pattern == 2; + speed = isBursting ? BURSTING_SPEED : FAN_SPEED; + count = isBursting ? BURSTING_COUNT : WIDE_RING_COUNT; + if (isBursting) + { + params.bulletFlags |= PROJECTILE_BURST; + params.fallingSpeedModifier = 0; + params.fallingAccelModifier = 0; + } + } + } + else + { + params.bulletFlags |= PROJECTILE_SMART; + params.homingStrength = FAN_HOMING; + if (pattern <= 7) + { + if (frame % FAN_SPACING != 0) return; + params.fireDirectionLimit = aim; + params.dotProductLimit = LAMB_FAN_DOT_LIMIT; + if (pattern == 4) params.circleAngle = 0; + else if (pattern == 5) params.circleAngle = aimAngle; + else if (pattern == 6) + params.circleAngle = (random_unit() - 0.5f) * PI_F * FAN_WAVER + aimAngle + FAN_HALF_STEP; + else + params.circleAngle = + std::sin((float)(frame + frame) / TURNING_PERIOD) * FAN_HALF_STEP + aimAngle + FAN_HALF_STEP; + } + else if (pattern == 8) + { + if (frame % WIDE_FAN_SPACING != 0) return; + count = WIDE_FAN_COUNT; + params.fireDirectionLimit = aim; + params.dotProductLimit = 0; + } + else if (pattern == 9) + { + if (frame % TRIPLE_SPACING != 0) return; + count = TRIPLE_COUNT; + params.homingStrength = TRIPLE_HOMING; + params.circleAngle = (float)frame * -TURNING_RATE / TURNING_PERIOD * 2 * PI_F; + } + else return; + } + npc_sound_play(SOUND_MONSTER_ROAR_1, PATTERN_VOLUME, (int)(Random() % PATTERN_CRY_RANGE) + PATTERN_CRY_MIN, + champion_pitch_get(npc)); + npc.FireProjectiles(npc.pos, vector_make(speed, (float)count), PROJECTILES_RING, params); +} + +// One frame of the long pattern: drifting and calling flies in the gentler ones, then winding down after 120. +static void pattern_step(Entity_NPC& npc) +{ + if (npc.i2 < PATTERN_DRIFTING) + { + Vector toTarget = vector_normalized(vector_sub(npc.CalcTargetPosition(0), npc.pos)); + npc.velocity = vector_scale(toTarget, npc.aiFloat * PATTERN_DRIFT); + Room& room = *g_game->room; + int others = room.GetAliveEnemiesCount() - room.GetAliveBossesCount(); + if (npc.i1 == LAMB_WHOLE && npc.stateFrame % PATTERN_FLY_SPACING == 0 && (Random() & 1) == 0 && + others < PATTERN_FLY_CROWD) + { + uint32_t seed = Random(); + Vector velocity = vector_add(vector_scale(random_direction(), BODY_FLY_SPEED), npc.velocity); + Entity* fly = g_game->Spawn({.position = npc.pos, .velocity = velocity, .spawner = &npc, + .type = ENTITY_ATTACKFLY, .seed = seed}); + fly->ClearEntityFlags(FLAG_APPEAR); + } + } + lamb_pattern_fire(npc, npc.i2, npc.stateFrame); + if (npc.stateFrame > PATTERN_FRAMES) npc.sprite.Play(npc.i1 == LAMB_WHOLE ? "Swarm2End" : "HeadShoot2End"); + npc.stateFrame++; +} + +// The long pattern: once charged it picks one of 10, loops while firing it, and ends back to walking. +static void pattern_update(Entity_NPC& npc) +{ + bool isWhole = npc.i1 == LAMB_WHOLE; + const AnimationState& anim = npc.sprite.animState; + if (anim.isPlaying && (anim_is(npc, "Charge") || anim_is(npc, "HeadCharge"))) + npc.PlaySound(SOUND_MONSTER_GRUNT_1, 1, LAMB_CRY_DELAY, false, 1); + npc.velocity = Vector{}; + + bool isFiring = false; + if (!anim.animData) isFiring = npc.sprite.WasEventTriggered("Shoot"); + else + { + if (!anim.isPlaying && (anim_is(npc, "Charge") || anim_is(npc, "HeadCharge"))) + { + npc.sprite.Play(isWhole ? "Swarm2Start" : "HeadShoot2Start"); + npc.i2 = (int)(Random() % PATTERN_PICKS); + } + else if (anim_ended(npc, "Swarm2Start")) npc.sprite.Play(isWhole ? "Swarm2Loop" : "HeadShoot2Loop"); + + bool isLooping = anim.isPlaying && (anim_is(npc, "Swarm2Loop") || anim_is(npc, "HeadShoot2Loop")); + isFiring = isLooping || npc.sprite.WasEventTriggered("Shoot"); + } + if (isFiring) pattern_step(npc); + + if (anim_ended(npc, "Swarm2End") || anim_ended(npc, "HeadShoot2End")) walk_resume(npc, isWhole ? "Idle" : "HeadIdle"); +} + +// The head's four beams from just above it, straight or turning together. +static void beams_fire(Entity_NPC& npc) +{ + uint32_t mode = Random() % BEAMS_MODES; + uint32_t hold = Random() % BEAMS_TIMEOUT_RANGE; + if (!g_game->room->IsPositionInRoom(npc.pos, BEAMS_ROOM_MARGIN)) mode = 0; + int timeout = mode == 0 ? BEAMS_TIMEOUT_STRAIGHT : (int)hold + BEAMS_TIMEOUT_MIN; + npc.stateFrame = timeout - BEAMS_HOLD_SLACK; + + for (int beam = 0; beam < 4; beam++) + { + Entity_Laser* laser = Entity_Laser::ShootAngle({.position = vector_make(npc.pos.x, npc.pos.y - BEAMS_RISE), + .posOffset = vector_make(0, BEAMS_END_RISE), + .source = &npc, + .angleDegrees = (float)beam * 90 - 180, + .timeout = timeout, + .variant = LASER_THICK_RED}); + laser->renderDepthOffset = BEAMS_DEPTH; + if (mode != 0) + { + float side = mode == 1 ? 1 : -1; + laser->rotationDegrees = side * BEAMS_TURN; + laser->rotationSpd = side * BEAMS_TURN_SPEED; + laser->timeout = (int)hold + BEAMS_TIMEOUT_MIN + 1; + laser->rotationDelay = (int)hold + BEAMS_DELAY_MIN; + laser->isActiveRotating = true; + } + laser->Update(); + } +} + +// The head's cross of beams: charging, raising its head, firing on Shoot, then holding until the beams fade. +static void beams_update(Entity_NPC& npc) +{ + npc.velocity = Vector{}; + if (anim_ended(npc, "Charge2")) npc.sprite.Play("Blast"); + if (anim_ended(npc, "HeadCharge")) npc.sprite.Play("HeadShoot2Start"); + else if (anim_ended(npc, "HeadShoot2Start")) npc.sprite.Play("HeadShoot2Loop"); + + if (npc.sprite.IsEventTriggered("Shoot")) return beams_fire(npc); + + const AnimationState& anim = npc.sprite.animState; + bool isHolding = anim.isPlaying ? anim_is(npc, "Blast") || anim_is(npc, "HeadShoot2Loop") || + anim_is(npc, "HeadShoot2End") + : anim_is(npc, "HeadShoot2End"); + if (!isHolding || npc.stateFrame-- > 0) return; + + if (npc.i1 == LAMB_WHOLE || anim_ended(npc, "HeadShoot2End")) walk_resume(npc, {}); + else npc.sprite.Play("HeadShoot2End"); +} + +// The body standing: it sways in place, its flame following, and rolls to attack while the head is free. +static void body_update(Entity_NPC& npc, Entity_NPC* head, bool isBodyRaging) +{ + npc.sprite.Play("Body"); + npc.velocity = vector_sub(npc.targetPosition, npc.pos); + if (npc.child) npc.child->pos = vector_add(npc.pos, BODY_FLAME_OFFSET); + + bool isRolled = npc.health > 0 && npc.stateFrame % BODY_ROLL_SPACING == 0 && + ((Random() & BODY_ROLL_MASK) == 0 || (isBodyRaging && (Random() & 1) == 0)); + if (isRolled && !npc.HasEntityFlags(LAMB_STUNNED) && (!head || head->state == NPC_STATE_MOVE)) + { + npc.state = LAMB_SHOTS; + if (isBodyRaging) npc.v2.y -= BODY_RAGE_SPENT; + } + npc.stateFrame++; +} + +// The body's death: the room goes dark and it stays as a harmless husk, steaming, its flame out. +static void body_die(Entity_NPC& npc) +{ + g_game->darknessStrength = 1; + g_game->darknessTimeout = BODY_DARKNESS_FRAMES; + npc.collisionDamage = 0; + npc.isDead = false; + npc.isInvincible = true; + npc.isCanShutDoors = false; + npc.isBoss = false; + npc.health = 0; + npc.entityCollisionClass = ENTCOLL_PLAYERONLY; + npc.RemoveStatusEffects(); + bool isBossDeathDone = npc.HasEntityFlags(FLAG_BOSSDEATH_TRIGGERED); + npc.AddEntityFlags(FLAG_NO_STATUS_EFFECTS); + if (g_game->room->GetAliveBossesCount() > 0 && !isBossDeathDone) g_game->room->TriggerBossDeath(npc); + + g_game->Spawn({.position = vector_make(npc.pos.x, npc.pos.y + BODY_POOF_RISE), .spawner = &npc, + .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); + npc.PlaySound(SOUND_STEAM_HALFSEC, BODY_DEATH_VOLUME, 2, false, 1); + if (npc.child) npc.child->Remove(); +} + +// 00483710 The Lamb (273.0) and his body (273.10): walking whole with his spreads and long patterns, then split below +// half health into a head that dashes and fires beams, and a body that attacks and is left a husk when it falls. +void boss_lamb_update(Entity_NPC& npc) +{ + Entity_NPC* head = lamb_part_find(LAMB_HEAD); + Entity_NPC* body = lamb_part_find(LAMB_BODY); + bool isBodyRaging = body && body->v2.y > BODY_RAGE; + if (npc.variant == LAMB_HEAD && npc.i1 == LAMB_WHOLE && npc.health < npc.maxHitPoints * SPLIT_THRESHOLD) + lamb_split(npc); + if (npc.state == NPC_STATE_INIT) return lamb_init(npc); + + switch (npc.state) + { + case NPC_STATE_MOVE: + walk_update(npc, isBodyRaging); + break; + case LAMB_SHOTS: + shots_update(npc); + break; + case LAMB_DASH: + dash_update(npc); + break; + case LAMB_PATTERN: + pattern_update(npc); + break; + case LAMB_BEAMS: + beams_update(npc); + break; + case NPC_STATE_SPECIAL: + if (npc.variant == LAMB_BODY) body_update(npc, head, isBodyRaging); + else if (npc.variant == LAMB_HEAD && npc_anim_is_done(npc)) + { + npc.isInvincible = false; + walk_resume(npc, "HeadIdle"); + } + break; + } + + if (npc.variant == LAMB_BODY && npc.isDead) body_die(npc); + if (npc.health < npc.v2.x) npc.v2.y = std::min(npc.v2.x - npc.health + npc.v2.y, RAGE_CAP); + npc.v2.y = std::max(npc.v2.y - RAGE_DRAIN, 0.0f); + npc.v2.x = npc.health; +} diff --git a/src/boss_polycephalus.cpp b/src/boss_polycephalus.cpp index 6c8b7b7..656a109 100644 --- a/src/boss_polycephalus.cpp +++ b/src/boss_polycephalus.cpp @@ -1,7 +1,10 @@ #include "boss_ai.h" +#include "entity_effect_combat.h" +#include "loot_list.h" #include "npc_caves.h" #include "room_grid.h" #include "sfx_manager.h" +#include #include // Polycephalus's subtypes (the red one, and the pair) and the Stain's grey one. Variant 1 is the Pile. @@ -350,11 +353,371 @@ static void polycephalus_surface(Entity_NPC& npc, bool isGrey) if (npc_anim_is_done(npc)) npc.state = NPC_STATE_IDLE; } +// The Pile's moves (the outcomes it draws among), and its burrow phases (i1's second byte). +enum PileMove +{ + PILE_CHARGE, + PILE_SPIKES, + PILE_SUMMON, + PILE_BURROW +}; + +// The Pile's rests, burrow and surfacing spot (away from players, near its target), shots, charge and spikes. +constexpr uint32_t PILE_REST_SPREAD = 30; +constexpr int PILE_REST_MIN = 30; +constexpr float PILE_WANDER_SPEED = 0.3f; +constexpr float PILE_FRICTION = 0.8f; +constexpr int PILE_ENEMY_LIMIT = 3; +constexpr int PILE_BURROWS = 3; +constexpr int PILE_SINK_FRAMES = 10; +constexpr int PILE_DIG_STEP = 3; +constexpr float PILE_PLAYER_REACH = 5000; +constexpr float PILE_CLEARANCE_SQUARED = 6400; +constexpr float PILE_SPOT_BEST = 10000; +constexpr int PILE_SPOT_TRIES = 10; +constexpr float PILE_SPOT_REACH = 120; +constexpr float PILE_SPOT_REACH_SPREAD = 0.2f; +constexpr float PILE_SPOT_REACH_MIN = 0.8f; +constexpr float PILE_SPOT_FREE_STEP = 40; +constexpr float PILE_SPOT_NEAR_CAP = 22500; +constexpr float PILE_DIG_SPAN = 100; +constexpr int PILE_DIG_FRAMES = 6; +constexpr float PILE_DIG_SPEED = 2; +constexpr float PILE_SHOT_SPEED = 10; +constexpr int PILE_LAST_BURROW = 2; +constexpr int PILE_DIG_DELAY = 10; +constexpr float PILE_CHARGE_SPEED = 4; +constexpr int PILE_ROAR_DELAY = 20; +constexpr int PILE_CRASH_SHAKE = 15; +constexpr float PILE_CRASH_VOLUME = 2; +constexpr int PILE_CRASH_SHOTS = 20; +constexpr int PILE_CRACKS = 4; +constexpr float PILE_CRACK_STEP = 90; +constexpr float PILE_CRACK_START = 45; +constexpr int PILE_CRACK_SUBTYPE = 2; +constexpr int PILE_DUST_COUNT = 2; +constexpr float PILE_DUST_SPEED = 6; +constexpr float PILE_DUST_HEIGHT = 100000; +constexpr int PILE_DUST_SUBTYPE = 0x20000; +constexpr float PILE_BONY_REACH = 60; +constexpr int PILE_SPIKE_COOLDOWN = 6; +constexpr float PILE_CELL = 40; +constexpr float PILE_CELL_ROUND = 0.5f; +constexpr ColorMod PILE_SPIKE_COLOR = {{1, 1, 1, 1}, {1, 1, 1, 1}, {0, 0, 0}}; + +// The Pile's first move never charges or raises spikes. It only summons with few enemies about. +static void pile_move_pick(Entity_NPC& npc) +{ + WeightedOutcomePicker picker; + bool isFirst = npc.i1 & 0xff; + if (!isFirst) + { + picker.AddOutcomeWeight(PILE_CHARGE, 1); + picker.AddOutcomeWeight(PILE_SPIKES, 1); + } + if (g_game->room->GetAliveEnemiesCount() < PILE_ENEMY_LIMIT) picker.AddOutcomeWeight(PILE_SUMMON, 1); + picker.AddOutcomeWeight(PILE_BURROW, 1); + + switch (picker.PickOutcome({Random() | 1, 5, 9, 7})) + { + case PILE_CHARGE: + npc.state = NPC_STATE_ATTACK2; + npc.projectileCooldown = 0; + break; + case PILE_SPIKES: + { + Room& room = *g_game->room; + int column = (int)((npc.pos.x - PILE_CELL) / PILE_CELL + PILE_CELL_ROUND); + int row = (int)((npc.pos.y - PILE_CELL * 3) / PILE_CELL + PILE_CELL_ROUND); + int reach = std::max({row, column, room.gridWidth - column - 1, room.gridHeight - row - 1}); + npc.state = NPC_STATE_SUMMON2; + npc.projectileDelay = reach * 2; + npc.projectileCooldown = PILE_SPIKE_COOLDOWN; + npc.PlaySound(SOUND_GRROOWL, 1, 2, false, 1); + break; + } + case PILE_SUMMON: + npc.state = NPC_STATE_SUMMON; + break; + default: + npc.state = NPC_STATE_JUMP; + npc.projectileDelay = PILE_BURROWS; + npc.i1 &= ~0xff00; + npc_sound_play(SOUND_MAGGOT_ENTER_GROUND, 1, PILE_DIG_DELAY, 1); + } + npc.i1 &= ~0xff; +} + +// A random spot about a center, a fraction of the Pile's reach away. +static Vector pile_spot_roll(Vector center) +{ + float angle = random_unit() * RANDOM_HALF_TURN; + angle += angle; + float reach = (random_unit() * PILE_SPOT_REACH_SPREAD + PILE_SPOT_REACH_MIN) * PILE_SPOT_REACH; + return vector_make(std::cos(angle) * reach + center.x, std::sin(angle) * reach + center.y); +} + +// Where to surface: the best of ten free spots near its target, kept away from the players and from itself. +static void pile_surface_pick(Entity_NPC& npc) +{ + Room& room = *g_game->room; + Vector center = npc.CalcTargetPosition(0); + Vector best{}; + float bestScore = 0; + for (int i = 0; i < PILE_SPOT_TRIES; i++) + { + Vector spot = room_free_pickup_position_find( + {.position = pile_spot_roll(center), .isAvoidActiveEntities = true}); + if (!room.IsPositionInRoom(spot, 0) || room_grid_collision_at(spot) != 0) continue; + Entity* player = game_nearest_target_player(spot, &npc, false, false, PILE_PLAYER_REACH); + if (!player) continue; + float playerDistance = vector_length_squared(vector_sub(player->pos, spot)); + if (playerDistance <= PILE_CLEARANCE_SQUARED) continue; + float score = std::min(vector_length_squared(vector_sub(npc.pos, spot)), PILE_SPOT_NEAR_CAP) + + playerDistance + playerDistance; + if (bestScore >= score) continue; + best = spot; + bestScore = score; + } + npc.targetPosition = best; + float span = std::max(vector_length(vector_sub(npc.pos, best)) / PILE_DIG_SPAN, 1.0f); + npc.projectileCooldown = (int)(span * PILE_DIG_FRAMES); +} + +// Digging toward its spot: one a player nears is swapped for the nearest of ten clear ones about that player. +static void pile_dig(Entity_NPC& npc, int ticks) +{ + npc.projectileCooldown = std::max(npc.projectileCooldown - ticks, 0); + if (npc.projectileCooldown == 0 || (ticks > 0 && npc.projectileCooldown % PILE_DIG_STEP == 0)) + { + Room& room = *g_game->room; + Vector old = npc.targetPosition; + Entity* player = game_nearest_target_player(old, &npc, false, false, PILE_PLAYER_REACH); + if (vector_length_squared(vector_sub(player->pos, old)) <= PILE_CLEARANCE_SQUARED) + { + float bestDistance = PILE_SPOT_BEST; + for (int i = 0; i < PILE_SPOT_TRIES; i++) + { + Vector spot = room_free_pickup_position_find( + {.position = pile_spot_roll(player->pos), .step = PILE_SPOT_FREE_STEP, .isAvoidActiveEntities = true}); + if (!room.IsPositionInRoom(spot, 0) || room_grid_collision_at(spot) != 0 || + vector_length_squared(vector_sub(player->pos, spot)) <= PILE_CLEARANCE_SQUARED) + continue; + float distance = vector_length_squared(vector_sub(old, spot)); + if (distance >= bestDistance) continue; + npc.targetPosition = spot; + bestDistance = distance; + } + npc.projectileCooldown = std::max(npc.projectileCooldown, 1); + } + } + npc.pathfinder.FindGridPath(npc.targetPosition, PILE_DIG_SPEED, 0, DIRECT_PATH_FAR); +} + +// Its burrow: under it goes, digs to a spot away from the players, and comes up there to shoot. +static void pile_burrow(Entity_NPC& npc, int ticks) +{ + npc.UpdateDirtColor(false); + if (!(npc.i1 & 0xff00)) + { + npc.sprite.Play("GoUnder"); + if (!npc.sprite.IsFinished("GoUnder")) return; + npc.targetPosition = {}; + npc.v1 = npc.pos; + npc.i1 |= 0x100; + npc.projectileCooldown = PILE_SINK_FRAMES; + return; + } + if (npc.projectileCooldown >= 1) + { + npc.sprite.Play("DirtShrink"); + npc.entityCollisionClass = ENTCOLL_NONE; + if (vector_is_zero(npc.targetPosition)) pile_surface_pick(npc); + else pile_dig(npc, ticks); + return; + } + if (npc.projectileCooldown == 0) + { + npc.pos = npc.targetPosition; + npc.sprite.Play("ComeUp"); + npc.projectileCooldown = -1; + npc.UpdateDirtColor(true); + return; + } + if (npc.sprite.GetFrame() == 1) npc.entityCollisionClass = ENTCOLL_ALL; + if (!npc.sprite.IsFinished("ComeUp")) return; + npc.targetPosition = npc.GetPlayerTarget()->pos; + npc.state = NPC_STATE_ATTACK; +} + +// Surfaced, it spits five bones at its target, then burrows again (three times in all, the last with Attack3). +static void pile_shoot(Entity_NPC& npc) +{ + const char* anim = npc.projectileDelay < PILE_LAST_BURROW ? "Attack3" : "Attack1"; + npc.sprite.Play(anim); + if (npc.sprite.IsEventTriggered("Shoot")) + { + npc.PlaySound(SOUND_GHOST_SHOOT, 1, 2, false, 1); + ProjectileParams params; + params.variant = PROJECTILE_BONE; + Vector aim = vector_scale(vector_normalized(vector_sub(npc.targetPosition, npc.pos)), PILE_SHOT_SPEED); + npc.FireProjectiles(npc.pos, aim, PROJECTILES_FIVE, params); + } + if (!npc.sprite.IsFinished(anim)) return; + npc.i1 &= ~0xff00; + if (--npc.projectileDelay < 1) + { + npc.stateFrame = (int)(Random() % PILE_REST_SPREAD) + PILE_REST_MIN; + npc.state = NPC_STATE_IDLE; + return; + } + npc.state = NPC_STATE_JUMP; + npc_sound_play(SOUND_MAGGOT_ENTER_GROUND, 1, PILE_DIG_DELAY, 1); +} + +// Its charge: it rolls at its target, kicking up dirt, until it hits a wall, which cracks the floor four ways and +// rains bones on its target. +static void pile_charge(Entity_NPC& npc, int ticks) +{ + npc.UpdateDirtColor(false); + if (npc.projectileCooldown == 0) + { + npc.sprite.Play("ChargeBegin"); + if (!npc.sprite.IsEventTriggered("StartCharge")) return; + npc.v1 = vector_scale(vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos)), PILE_CHARGE_SPEED); + npc.PlaySound(SOUND_MONSTER_ROAR_0, 1, PILE_ROAR_DELAY, false, 1); + npc_sound_play(SOUND_MAGGOT_BURST_OUT, 1, PILE_ROAR_DELAY, 1); + npc.projectileCooldown = 1; + return; + } + if (npc.projectileCooldown == 1) + { + if (npc_anim_is_done(npc)) npc.sprite.Play("ChargeLoop"); + if (ticks > 0) + { + g_game->Spawn({.position = npc.pos, .type = ENTITY_EFFECT, .variant = EFFECT_DIRT_PILE, .seed = Random()}); + game_particles_spawn({.position = vector_add(vector_add(npc.velocity, npc.velocity), npc.pos), + .height = PILE_DUST_HEIGHT, + .speed = PILE_DUST_SPEED, + .count = PILE_DUST_COUNT, + .subType = PILE_DUST_SUBTYPE, + .variant = EFFECT_ROCK_PARTICLE}); + } + npc.AddVelocity_divided(npc.v1, false); + if (!npc.isCollidesWithGrid) return; + + npc_sound_play(SOUND_HELLBOSS_GROUNDPOUND, PILE_CRASH_VOLUME, 2, 1); + game_shake_screen(PILE_CRASH_SHAKE); + npc.projectileDelay = PILE_CRASH_SHOTS; + for (int i = 0; i < PILE_CRACKS; i++) + { + auto* crack = static_cast(g_game->Spawn({.position = npc.pos, .spawner = &npc, + .subType = PILE_CRACK_SUBTYPE, + .type = ENTITY_EFFECT, + .variant = EFFECT_CRACKWAVE, .seed = Random()})); + crack->parent = &npc; + crack->rotation = (float)i * PILE_CRACK_STEP + PILE_CRACK_START; + } + npc.velocity = {}; + npc.sprite.Play("ChargeEnd"); + npc.projectileCooldown = 2; + return; + } + for (int i = 0; i < ticks && npc.projectileDelay != 0; i++) + { + if (--npc.projectileDelay & 1) continue; + Entity* target = npc.GetPlayerTarget(); + ProjectileParams params; + params.variant = PROJECTILE_BONE; + for (int shots = (int)(Random() & 1) + 1; shots != 0; shots--) + npc.FireBossProjectiles(1, target->pos, 1, params); + } +} + +// Its spikes: rings of spikes ripple out from it a cell at a time, along the four axes. +static void pile_spikes(Entity_NPC& npc, int ticks) +{ + if (npc.projectileCooldown != 0) npc.projectileCooldown = std::max(npc.projectileCooldown - ticks, 0); + else + { + Room& room = *g_game->room; + for (int i = 0; i < ticks && npc.projectileDelay >= 1; i++, npc.projectileDelay--) + { + if (npc.projectileDelay & 1) continue; + Vector cell = room.GetGridPosition(room.GetGridIndex(npc.pos)); + for (int direction = 0; direction < 4; direction++) + { + float reach = (float)(npc.projectileDelay / 2) * PILE_CELL; + Vector spot = vector_add(cell, vector_scale(vector_from_direction(direction), reach)); + if (!room.IsPositionInRoom(spot, 0) || room_grid_collision_at(spot) != 0) continue; + Entity* spike = g_game->Spawn({.position = spot, .spawner = &npc, .type = ENTITY_EFFECT, + .variant = EFFECT_SPIKE, .seed = Random()}); + spike->sprite.color = PILE_SPIKE_COLOR; + spike->Update(); + } + } + } + npc.sprite.Play("Summon"); + if (!npc_anim_is_done(npc)) return; + if (npc.projectileDelay != 0) return npc.sprite.Play("Idle"); + npc.stateFrame = (int)(Random() % PILE_REST_SPREAD) + PILE_REST_MIN; + npc.state = NPC_STATE_IDLE; +} + +// 005983f0 NpcAI::ENTITY_POLYCEPHALUS_the_pile: the Pile wanders, then burrows to surface and spit bones, charges a +// wall, raises rings of spikes, or digs up a Bony. +static void pile_update(Entity_NPC& npc) +{ + int ticks = npc_ticks_get(npc); + npc.friction *= PILE_FRICTION; + switch (npc.state) + { + case NPC_STATE_INIT: + npc.state = NPC_STATE_IDLE; + npc.stateFrame = (int)(Random() % PILE_REST_SPREAD) + PILE_REST_MIN; + npc.i1 = (npc.i1 & ~0xff) | 1; + npc.AddEntityFlags(FLAG_NO_BLOOD_SPLASH); + return; + case NPC_STATE_IDLE: + npc.UpdateDirtColor(false); + npc.sprite.Play("Idle"); + npc.pathfinder.MoveRandomlyAxisAligned(PILE_WANDER_SPEED, STATUS_OBEYED); + if (npc.stateFrame < 1) pile_move_pick(npc); + else npc.stateFrame -= ticks; + return; + case NPC_STATE_JUMP: + return pile_burrow(npc, ticks); + case NPC_STATE_ATTACK: + return pile_shoot(npc); + case NPC_STATE_ATTACK2: + if (npc.projectileCooldown < 2) return pile_charge(npc, ticks); + pile_charge(npc, ticks); + break; + case NPC_STATE_SUMMON: + npc.sprite.Play("Attack3"); + if (npc.sprite.IsEventTriggered("Shoot")) + { + npc_sound_play(SOUND_SUMMONSOUND, 1, 2, 1); + uint32_t seed = Random(); + Vector spot = vector_add(vector_scale(random_direction(), PILE_BONY_REACH), npc.pos); + g_game->Spawn({.position = spot, .spawner = &npc, .type = ENTITY_BONY, .seed = seed})->Update(); + } + break; + case NPC_STATE_SUMMON2: + return pile_spikes(npc, ticks); + default: + return; + } + if (!npc_anim_is_done(npc)) return; + npc.stateFrame = (int)(Random() % PILE_REST_SPREAD) + PILE_REST_MIN; + npc.state = NPC_STATE_IDLE; +} + // 00489ca0 NpcAI::ENTITY_POLYCEPHALUS: Polycephalus and the Stain burrow about and surface near their target to // shoot, spray creep, spin rings of shots or summon. The Pile (variant 1) has its own AI. void boss_polycephalus_update(Entity_NPC& npc) { - if (npc.variant == POLYCEPHALUS_PILE) return (void)NpcAI::ENTITY_POLYCEPHALUS_the_pile(&npc); + if (npc.variant == POLYCEPHALUS_PILE) return pile_update(npc); bool isGrey = npc.type == ENTITY_STAIN && npc.subtype == STAIN_GREY; npc.i2++; diff --git a/src/console_commands.cpp b/src/console_commands.cpp index 5dc1d0e..8f3045c 100644 --- a/src/console_commands.cpp +++ b/src/console_commands.cpp @@ -7,6 +7,7 @@ #include "entity_npc.h" #include "entity_pickup.h" #include "entity_player.h" +#include "entity_slot.h" #include "game.h" #include "grid_entity.h" #include "hud.h" @@ -754,7 +755,7 @@ static void cutscene_run(ConsoleCommand& command) static void restock_run(ConsoleCommand& command) { - reconstruction_missing("Room::ShopRestockFull 00815ae0"); + room_shop_restock_full(); command_print(command, "Shop is fully restocked.\n"); } diff --git a/src/cutscene.cpp b/src/cutscene.cpp index 691a30e..1808b42 100644 --- a/src/cutscene.cpp +++ b/src/cutscene.cpp @@ -331,6 +331,8 @@ void Cutscene::VideoPart::Start() } // 0095fbd0 Moves the subtitles on to the part's frame (30 a second) every other frame. The clip plays itself. +// The original also restarts the clip's clock once two frames are cached again. Frames decode as they are due here, +// so the clock never waits on them. void Cutscene::VideoPart::Update() { if (g_manager->framecount & 1) return; @@ -348,10 +350,10 @@ void Cutscene::VideoPart::Render(Vector offset) // 0095fd40 Whether the clip played to its end, or none opened. bool Cutscene::VideoPart::IsFinished() { return player->is_finished(); } -// (0095c930, 0095c960) The canvas the clip is drawn for. With no clip open the original gives 0 by 0, which zeroes the -// screen scale for the frame the part shows, so the default canvas stands in. -int Cutscene::VideoPart::GetWidth() { return CANVAS_DEFAULT.width; } -int Cutscene::VideoPart::GetHeight() { return CANVAS_DEFAULT.height; } +// (0095c930, 0095c960) The canvas the clip is drawn for, its coded frame size. With no clip open the original gives 0 +// by 0, which zeroes the screen scale for the frame the part shows, so the default canvas stands in. +int Cutscene::VideoPart::GetWidth() { return player->clip ? player->width_get() : CANVAS_DEFAULT.width; } +int Cutscene::VideoPart::GetHeight() { return player->clip ? player->height_get() : CANVAS_DEFAULT.height; } // 0095fd70 Loads the title and body fonts, as mods may replace them. void Cutscene::TemporaryPart::Load() @@ -670,6 +672,9 @@ void Cutscene::Update() g_manager->popupButtons.buttons[1].targetSlideOffset = POPUP_BUTTON_HIDDEN_OFFSET; } +// 0095dee0 Whether a cutscene plays a video that has not shown its last frame. +bool Cutscene::is_video_playing() { return state == CUTSCENE_PLAYING && !videoPlayer.is_finished(); } + // Draws the cutscene over its fade color: the current part, or the last once they ran out, and over it the fade, // its alpha the fade's progress. (Inlined in Manager::Render 009555c0, state 3.) void Cutscene::Render() diff --git a/src/cutscene.h b/src/cutscene.h index 4978d35..5b82918 100644 --- a/src/cutscene.h +++ b/src/cutscene.h @@ -156,5 +156,6 @@ struct Cutscene void Show(int cutsceneId); void Update(); void Render(); + bool is_video_playing(); Size canvas_size_get(); }; diff --git a/src/entity.cpp b/src/entity.cpp index f212eff..b5624a6 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -810,7 +810,7 @@ void Entity::Update() Room& room = *g_game->room; if (!HasEntityFlags(FLAG_INTERPOLATION_UPDATE) && room.waterAmount > 0 && g_manager->optionsConfig.render.isWaterSurfaceEnabled) - reconstruction_missing("Entity::Update 006ae820: the water ripples it leaves (get_water_splash_variant)"); + water_ripples_update(); if (std::fabs(pos.x) + std::fabs(pos.y) >= POSITION_LIMIT) log_format(LOG_ASSERT, "Invalid entity position detected: %.2f, %.2f (%d.%d.%d)\n", pos.x, pos.y, type, variant, @@ -1256,12 +1256,6 @@ void Entity::GetNullCapsule(Capsule&, std::string_view) reconstruction_missing("Entity::GetNullCapsule 006b6c20"); } -// 006b6ed0 -int Entity::get_water_splash_variant() -{ - reconstruction_missing("Entity::get_water_splash_variant 006b6ed0"); -} - // 007079c0 void Entity::RemoveWithPoof(Entity*) { diff --git a/src/entity.h b/src/entity.h index b476bd6..e469a30 100644 --- a/src/entity.h +++ b/src/entity.h @@ -95,13 +95,16 @@ enum EntityType : int ENTITY_GURDY_JR = 99, ENTITY_WIDOW = 100, ENTITY_DADDYLONGLEGS = 101, + ENTITY_ISAAC = 102, ENTITY_ISAAC_BOSS = 102, ENTITY_BRIMSTONE_HEAD = 203, + ENTITY_MOBILE_HOST = 204, ENTITY_BABY_LONG_LEGS = 206, ENTITY_CRAZY_LONG_LEGS = 207, ENTITY_FATTY = 208, ENTITY_BLUBBER = 210, ENTITY_DEATHS_HEAD = 212, + ENTITY_MOMS_HAND = 213, ENTITY_SWINGER = 216, ENTITY_DIP = 217, ENTITY_WALL_HUGGER = 218, @@ -123,8 +126,10 @@ enum EntityType : int ENTITY_CONJOINED_SPITTY = 243, ENTITY_ROUND_WORM = 244, ENTITY_POOP = 245, + ENTITY_FLESH_MOBILE_HOST = 247, ENTITY_NIGHT_CRAWLER = 255, ENTITY_DART_FLY = 256, + ENTITY_IMP = 259, ENTITY_GATE = 263, ENTITY_MEGA_FATTY = 264, ENTITY_CAGE = 265, @@ -139,7 +144,9 @@ enum EntityType : int ENTITY_BLACK_GLOBIN = 278, ENTITY_BLACK_GLOBIN_HEAD = 279, ENTITY_BLACK_GLOBIN_BODY = 280, + ENTITY_RED_GHOST = 285, ENTITY_FLESH_DEATHS_HEAD = 286, + ENTITY_MOMS_DEAD_HAND = 287, ENTITY_ULCER = 289, ENTITY_MEATBALL = 290, ENTITY_PITFALL = 291, @@ -147,6 +154,7 @@ enum EntityType : int ENTITY_CORN_MINE = 295, ENTITY_HUSH_FLY = 296, ENTITY_HUSH_GAPER = 297, + ENTITY_HUSH_BOIL = 298, ENTITY_POISON_MIND = 301, ENTITY_STONEY = 302, ENTITY_BLISTER = 303, @@ -174,6 +182,7 @@ enum EntityType : int ENTITY_STRIDER = 814, ENTITY_FISSURE = 815, ENTITY_POLTY = 816, + ENTITY_PREY = 817, ENTITY_ROCK_SPIDER = 818, ENTITY_FLY_BOMB = 819, ENTITY_BLASTER = 821, @@ -366,6 +375,29 @@ enum EntityCollisionClass : int ENTCOLL_ALL }; +// How water clips around an entity or grid entity (REPENTOGON's WaterClipInfo): which water passes draw it, and how far +// its reflection sits. +struct WaterClipInfo +{ + uint32_t flags = 0; + float value = 0; +}; + +// The water passes' clip flags: drawn under the water, in it, over it (not under), mirrored not at all, kept out of the +// refraction and above, and leaving ripples whatever it collides with. +enum WaterClipFlag : uint32_t +{ + WATER_CLIP_UNDER = 1 << 1, + WATER_CLIP_INSIDE = 1 << 2, + WATER_CLIP_ABOVE = 1 << 3, + WATER_CLIP_NO_REFLECTION = 1 << 5, + WATER_CLIP_SURFACE = 1 << 6, + WATER_CLIP_RIPPLES = 1 << 7 +}; + +// The small leech swims under the water below this height. +constexpr float SMALL_LEECH_SURFACE = -3; + // Lua's SortingLayer: where an entity draws among the others. enum SortingLayer : int { @@ -755,7 +787,8 @@ struct Entity Entity_Effect* MakeBloodPoofAtPos(const ColorMod& poofColor, float scale); Entity_NPC* GiveMinecart(const Vector& position, const Vector& cartVelocity); void convert_shot_for_enemy_owner(Entity* shot); - int get_water_splash_variant(); + WaterClipInfo GetWaterClipInfo(); + void water_ripples_update(); void* GetDebugShape(bool isUnknown); void* GetData(void* outRef); diff --git a/src/entity_bomb.cpp b/src/entity_bomb.cpp index 9cc30a6..8289b66 100644 --- a/src/entity_bomb.cpp +++ b/src/entity_bomb.cpp @@ -1,6 +1,10 @@ #include "entity_bomb.h" #include "data.h" #include "entity_config.h" +#include "entity_effect.h" +#include "entity_familiar.h" +#include "entity_knife.h" +#include "entity_laser.h" #include "entity_player.h" #include "entity_tear.h" #include "game.h" @@ -103,6 +107,42 @@ constexpr float PLAYER_PUSH = 0.4f; constexpr float PUSH_MIN_DISTANCE = 0.0001f; constexpr int HIT_COUNTDOWN = 30; +// Hydrobounce's bounce: how much of the fall it keeps, its splash's reach and share of the damage, and its sound. +constexpr float BOUNCE_KEEP = -0.7f; +constexpr float BOUNCE_AREA_RADIUS = 40; +constexpr float BOUNCE_AREA_DAMAGE = 0.25f; +constexpr float BOUNCE_VOLUME = 0.5f; + +// Dr. Fetus' bombs in flight: Wiggle Worm's sway, Tractor Beam's pull toward its line, the boomerang's pull back, and +// a rocket's wiggle, thrust and steering, and the smoke it trails. +constexpr float RIGHT_ANGLE = 90; +constexpr float HALF_TURN = 180; +constexpr float FETUS_WIGGLE_RATE = 0.7f; +constexpr float TRACTOR_PULL = 0.01f; +constexpr float TRACTOR_PULL_MAX = 2; +constexpr float FETUS_BOOMERANG_LIFT = 2; +constexpr float FETUS_BOOMERANG_PULL = 0.6f; +constexpr float ROCKET_WIGGLE_PUSH = 6; +constexpr float ROCKET_WIGGLE_RATE = 0.8f; +constexpr float ROCKET_WIGGLE_LAG = 0.5f; +constexpr float ROCKET_WIGGLE_TURN = 25; +constexpr float ROCKET_FRICTION_RAMP = 0.0625f; +constexpr float ROCKET_FRICTION_GAIN = 0.19f; +constexpr float ROCKET_FRICTION = 0.8f; +constexpr float ROCKET_THRUST_RAMP = 0.125f; +constexpr float ROCKET_BOOMERANG_START = 1; +constexpr float ROCKET_BOOMERANG_RAMP = 9; +constexpr float ROCKET_BOOMERANG_TURN = 0.5f; +constexpr float ROCKET_SMOKE_INTERVAL = 2; +constexpr float ROCKET_SMOKE_SPEED = 0.14f; +constexpr float ROCKET_SMOKE_BACK = 5; +constexpr float ROCKET_SMOKE_SPIN = 10; +constexpr float ROCKET_SMOKE_SPIN_MIN = 2; +constexpr int ROCKET_SMOKE_LIFE = 15; +constexpr float ROCKET_SMOKE_SCALE = 0.4f; +constexpr float ROCKET_SMOKE_DEPTH = -18; +constexpr ColorMod ROCKET_SMOKE_COLOR = {{1, 1, 1, 0.3f}, {}, {}}; + // The running number each player bomb takes on its first frame (the original's 00c7ec64). static int g_bombIndexCounter = 0; @@ -219,7 +259,17 @@ void Entity_Bomb::fall_update(bool isBouncy) if (height < 0) return; if (isBouncy && fallSpeed > BOUNCE_SPEED_MIN && bounceCount <= BOUNCE_MAX) - reconstruction_missing("Entity_Bomb::Update 006a24d0: Hydrobounce's bounce (tear_flags_area_apply)"); + { + bounceCount++; + posOffset.y = 0; + fallSpeed *= BOUNCE_KEEP; + Entity* ripple = g_game->Spawn({.position = pos, .type = ENTITY_EFFECT, .variant = EFFECT_RIPPLE_POOF, .seed = Random()}); + ripple->SetColor(sprite.color, -1, COLOR_PRIORITY_DEFAULT, false, true); + ripple->Update(); + grid_sound_play(SOUND_TEAR_IMPACTS, {.volume = BOUNCE_VOLUME}); + tear_flags_area_apply(pos, this, BOUNCE_AREA_RADIUS, explosionDamage * BOUNCE_AREA_DAMAGE, tearFlags); + return; + } posOffset.y = 0; fallSpeed = 0; collisionDamage = 0; @@ -260,8 +310,6 @@ void Entity_Bomb::Update() return; } if (isLoadCostumes) update_sparks(); - if (isFetus || IsRocket()) reconstruction_missing("Entity_Bomb::Update 006a24d0: Dr. Fetus bombs and rockets"); - bool isBouncy = tearFlags[TEAR_HYDROBOUNCE]; if (g_game->frameCount - spawnFrame == 1) { @@ -302,21 +350,33 @@ void Entity_Bomb::Update() if (isVisible && pitfallState == 0 && (posOffset.y < 0 || fallSpeed < 0)) fall_update(isBouncy); Entity_Player* spawner = spawnerEntity && spawnerEntity->is_player() ? spawnerEntity->ToPlayer() : nullptr; bool isOneShotPlaying = sprite.animState.animData && sprite.animState.isPlaying && !sprite.animState.IsLoopingAnimation(); - if (!isOneShotPlaying && variant != BOMB_DECOY && pitfallState == 0) sprite.Play("Pulse"); + if (IsRocket() && HasEntityFlags(FLAG_HELD)) + { + sprite.rotation = 0; + sprite.Play("Idle"); + rocketSpeed = 0; + } + else if (!isOneShotPlaying && variant != BOMB_DECOY && pitfallState == 0) sprite.Play("Pulse"); pulse_update(spawner); + float shownAngle = fetus_flight_update(); flag_check(*this, TEAR_BURN, "Entity_Bomb::Update 006a24d0: Hot Bombs' burn"); flag_check(*this, TEAR_OCCULT, "Entity_Bomb::Update 006a24d0: the Occult's steering"); + if (IsRocket()) rocket_thrust_update(); Entity::Update(); + if (IsRocket() && tearFlags[TEAR_BOOMERANG] && parent) rocket_boomerang_update(); if (spawnerType == ENTITY_PLAYER) { flag_check(*this, TEAR_HOMING, "Entity_Bomb::Update 006a24d0: Bobby-Bomb's homing"); flag_check(*this, TEAR_CREEP_TRAIL, "Entity_Bomb::Update 006a24d0: Bob's Bladder's creep"); } - velocity = vector_scale(velocity, SLIDE_FRICTION); - if (vector_length_squared(velocity) < 1) velocity = vector_scale(velocity, SLIDE_STOP); + if (!IsRocket() && (posOffset.y >= 0 || !isFetus)) + { + velocity = vector_scale(velocity, SLIDE_FRICTION); + if (vector_length_squared(velocity) < 1) velocity = vector_scale(velocity, SLIDE_STOP); + } flag_check(*this, TEAR_STICKY, "Entity_Bomb::Update 006a24d0: Sticky Bombs' hold"); - if (fuse_update(spawner)) late_update(); + if (fuse_update(spawner)) late_update(shownAngle); } // Burns the fuse down, or keeps it at its end while the Remote Detonator waits, and explodes. Safety Scissors defuse a @@ -326,7 +386,7 @@ bool Entity_Bomb::fuse_update(Entity_Player* spawner) bool isRemoteSet = spawner && spawner->temporaryEffects.HasCollectibleEffect(COLLECTIBLE_REMOTE_DETONATOR); if (explosionCountdown >= 1 && !(spawnerType == ENTITY_PLAYER && isRemoteSet)) { - explosionCountdown--; + if (!IsRocket() || !HasEntityFlags(FLAG_HELD)) explosionCountdown--; flag_check(*this, TEAR_ATTRACTOR, "Entity_Bomb::Update 006a24d0: Strange Attractor (Game::AttractEntities)"); bool isTroll = variant == BOMB_TROLL || variant == BOMB_SUPERTROLL || variant == BOMB_HOT || @@ -367,15 +427,22 @@ void Entity_Bomb::explode(Entity_Player* spawner) updateDelay = GIGA_UPDATE_DELAY; } explosion_effects({.tearFlags = flags, .color = sprite.color, .position = pos, .source = this, - .damageFlags = DAMAGE_EXPLOSION | DAMAGE_IGNORE_ARMOR, .damage = explosionDamage, + .damageFlags = isFetus ? DAMAGE_EXPLOSION : DAMAGE_EXPLOSION | DAMAGE_IGNORE_ARMOR, + .damage = explosionDamage, .radiusMultiplier = radiusMultiplier}); flag_check(*this, TEAR_SCATTER_BOMB, "Entity_Bomb::Update 006a24d0: Scatter Bombs' bomblets"); flag_check(*this, TEAR_GHOST_BOMB, "Entity_Bomb::Update 006a24d0: Ghost Bombs' ghost"); isDead = true; if (pitfallState == 0) sprite.Play("Explode"); - flag_check(*this, TEAR_STICKY, "Entity_Bomb::Update 006a24d0: Sticky Bombs' spiders"); - if (variant != BOMB_THROWABLE && spawner && spawner->HasTrinket(TRINKET_BLASTING_CAP)) + if (isFetus) + { + flag_check(*this, TEAR_PERSISTENT, "Entity_Bomb::Update 006a24d0: a Dr. Fetus bomb that throws another"); + flag_check(*this, TEAR_SPLIT, "Entity_Bomb::Update 006a24d0: Dr. Fetus' split bombs"); + flag_check(*this, TEAR_QUADSPLIT, "Entity_Bomb::Update 006a24d0: Dr. Fetus' quad split bombs"); + } + else flag_check(*this, TEAR_STICKY, "Entity_Bomb::Update 006a24d0: Sticky Bombs' spiders"); + if (!isFetus && variant != BOMB_THROWABLE && spawner && spawner->HasTrinket(TRINKET_BLASTING_CAP)) { RNG& rng = spawner->GetTrinketRNG(TRINKET_BLASTING_CAP); if (rng.RandomInt(BLASTING_CAP_CHANCE / spawner->GetTrinketMultiplier(TRINKET_BLASTING_CAP)) == 0) @@ -403,7 +470,7 @@ void Entity_Bomb::explode(Entity_Player* spawner) // The rest of the frame: a super troll bomb chases the nearest player, the cooldowns run, the bomb turns solid, falls // in a crawlspace, the brimstone bomb beeps, the drop sound plays and the costumes animate. -void Entity_Bomb::late_update() +void Entity_Bomb::late_update(float shownAngle) { if (variant == BOMB_SUPERTROLL) { @@ -421,7 +488,7 @@ void Entity_Bomb::late_update() int age = g_game->frameCount - spawnFrame; if (age > SOLID_AFTER_FRAMES && entityCollisionClass == ENTCOLL_PLAYERONLY) entityCollisionClass = ENTCOLL_ALL; if (explosionCountdown < age && entityCollisionClass == ENTCOLL_NONE) entityCollisionClass = ENTCOLL_ALL; - if (g_game->room->roomType == ROOM_DUNGEON) velocity.y += CRAWLSPACE_GRAVITY; + if (g_game->room->roomType == ROOM_DUNGEON && !IsRocket()) velocity.y += CRAWLSPACE_GRAVITY; if (variant == BOMB_BRIMSTONE) { if (posOffset.y >= 0 && fallSpeed >= 0) friction *= BRIMSTONE_FRICTION; @@ -450,9 +517,122 @@ void Entity_Bomb::late_update() } if (isHasCostumes) for (ANM2& costume : bombCostumesSprites) costume.Update(); + if (IsRocket()) rocket_sprite_update(shownAngle); lua_engine_get().PostBombUpdate(this); } +// Pulls a bomb flying ahead of the player onto the Tractor Beam's line, at most 2 a frame. +void Entity_Bomb::tractor_beam_pull() +{ + Entity_Player* player = parent && parent->is_player() ? parent->ToPlayer() : nullptr; + Entity* beam = player ? player->tractorBeam.get() : nullptr; + if (!beam || beam->type != ENTITY_LASER) return; + + Vector offset = vector_sub(pos, player->pos); + Vector line = vector_from_angle(static_cast(beam)->angleDegrees); + float along = vector_dot(line, offset); + if (along <= 0) return; + + Vector pull = vector_scale(vector_sub(vector_add(vector_scale(line, along), player->pos), pos), TRACTOR_PULL); + if (vector_length_squared(pull) > TRACTOR_PULL_MAX * TRACTOR_PULL_MAX) pull = vector_resized(pull, TRACTOR_PULL_MAX); + AddVelocity_divided(pull, false); +} + +// A Dr. Fetus bomb's flight: spectral ones fly over the grid, Wiggle Worm sways a bomb, an explosive one blows on a +// wall, Tractor Beam pulls it onto its line and the boomerang pulls it back. A rocket's wiggle turns its sprite and its +// fall tilts it. The angle the rocket's sprite shows this frame. +float Entity_Bomb::fetus_flight_update() +{ + float shownAngle = rocketAngle; + if (!isFetus) return shownAngle; + if (tearFlags[TEAR_SPECTRAL]) entityGridCollisionClass = GRIDCOLL_WALLS; + + if (IsRocket()) + { + if (tearFlags[TEAR_WIGGLE]) + { + float wave = (updateTime - 1) * ROCKET_WIGGLE_RATE; + Vector push = vector_scale(vector_from_angle(rocketAngle + RIGHT_ANGLE), ROCKET_WIGGLE_PUSH * std::sin(wave)); + velocity = vector_add(velocity, vector_scale(push, speedMultiplier)); + shownAngle = std::sin(wave - ROCKET_WIGGLE_LAG) * ROCKET_WIGGLE_TURN + rocketAngle; + } + if (fallAcceleration != 0) + { + float speed = vector_length(velocity); + Vector heading = vector_from_angle(shownAngle); + shownAngle = vector_angle(vector_make(heading.x * speed, fallSpeed + heading.y * speed)); + } + return shownAngle; + } + + if (tearFlags[TEAR_WIGGLE]) + { + Vector side = vector_normalized(vector_make(velocity.y, -velocity.x)); + float wave = std::sin((float)g_game->frameCount * FETUS_WIGGLE_RATE + (float)index); + pos = vector_add(pos, vector_scale(side, vector_length(velocity) * wave)); + } + if (isCollidesWithGrid && tearFlags[TEAR_EXPLOSIVE]) explosionCountdown = 0; + if (tearFlags[TEAR_TRACTOR_BEAM]) tractor_beam_pull(); + if (tearFlags[TEAR_BOOMERANG] && parent) + { + Vector away = vector_normalized(vector_sub(pos, vector_make(parent->pos.x, parent->pos.y + FETUS_BOOMERANG_LIFT))); + velocity = vector_sub(velocity, vector_scale(away, FETUS_BOOMERANG_PULL)); + } + return shownAngle; +} + +// A rocket's thrust: it speeds up along its angle as its speed builds (a small rocket twice as hard), with less drag, +// and a wall it flies into sets it off where it was. +void Entity_Bomb::rocket_thrust_update() +{ + float ramp = std::clamp(rocketSpeed * ROCKET_FRICTION_RAMP, 0.0f, 1.0f); + float thrust = variant == BOMB_ROCKET_GIGA ? ramp : std::clamp(rocketSpeed * ROCKET_THRUST_RAMP, 0.0f, 1.0f) * 2; + friction = ramp * ROCKET_FRICTION_GAIN + ROCKET_FRICTION; + rocketSpeed += speedMultiplier; + velocity = vector_add(velocity, vector_scale(vector_from_angle(rocketAngle), thrust * speedMultiplier)); + if (!isCollidesWithGrid) return; + + explosionCountdown = 0; + pos = vector_sub(pos, vector_scale(velocity, speedMultiplier)); +} + +// A boomerang rocket turns back toward its parent, harder as it speeds up. +void Entity_Bomb::rocket_boomerang_update() +{ + float turn = angle_wrap(vector_angle(vector_sub(parent->pos, pos)) - rocketAngle); + float share = std::clamp((rocketSpeed - ROCKET_BOOMERANG_START) / ROCKET_BOOMERANG_RAMP, 0.0f, 1.0f); + rocketAngle += share * ROCKET_BOOMERANG_TURN * turn * speedMultiplier; +} + +// Points the rocket's sprite along its flight (flipped when it flies left, level while held) and trails smoke every +// other frame while it shows. +void Entity_Bomb::rocket_sprite_update(float shownAngle) +{ + float angle = angle_wrap(shownAngle); + sprite.isFlipX = false; + if (HasEntityFlags(FLAG_HELD)) angle = 0; + else if (angle > RIGHT_ANGLE || angle < -RIGHT_ANGLE) + { + angle = HALF_TURN - angle; + sprite.isFlipX = true; + } + sprite.rotation = angle; + if (GetIntervalTicks(ROCKET_SMOKE_INTERVAL, 0) == 0 || !isVisible) return; + + uint32_t seed = Random(); + Vector back = vector_scale(vector_from_angle(shownAngle), ROCKET_SMOKE_BACK * scale); + Entity* spawned = g_game->Spawn({.position = vector_sub(pos, back), .velocity = vector_scale(velocity, ROCKET_SMOKE_SPEED), + .type = ENTITY_EFFECT, .variant = EFFECT_DUST_CLOUD, .seed = seed}); + auto& smoke = *static_cast(spawned); + smoke.SetColor(ROCKET_SMOKE_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + smoke.rotation = random_unit() * ROCKET_SMOKE_SPIN + ROCKET_SMOKE_SPIN_MIN; + smoke.timeout = (int)(Random() % ROCKET_SMOKE_LIFE) + ROCKET_SMOKE_LIFE; + smoke.lifespan = smoke.timeout; + smoke.renderDepthOffset = ROCKET_SMOKE_DEPTH; + smoke.sprite.scale = vector_make(scale * ROCKET_SMOKE_SCALE, scale * ROCKET_SMOKE_SCALE); + smoke.posOffset = posOffset; +} + // 006a5a60 Draws the bomb at its place: with costumes, the back costume, the bomb, then the others, each following the // bomb's first layer. // The original reads the first layer's frame without checking for one. Without one, the costumes are left out. diff --git a/src/entity_bomb.h b/src/entity_bomb.h index 915eddf..e69946a 100644 --- a/src/entity_bomb.h +++ b/src/entity_bomb.h @@ -100,7 +100,12 @@ private: void pulse_update(Entity_Player* spawner); bool fuse_update(Entity_Player* spawner); void explode(Entity_Player* spawner); - void late_update(); + void late_update(float shownAngle); + void tractor_beam_pull(); + float fetus_flight_update(); + void rocket_thrust_update(); + void rocket_boomerang_update(); + void rocket_sprite_update(float shownAngle); }; void explosion_damage(Explosion explosion); diff --git a/src/entity_combat.cpp b/src/entity_combat.cpp index e9f8e4c..a7b9ef8 100644 --- a/src/entity_combat.cpp +++ b/src/entity_combat.cpp @@ -13,6 +13,7 @@ #include "game.h" #include "lua_engine.h" #include "manager.h" +#include "entity_player_characters.h" #include "npc_ai.h" #include "platform.h" #include "room.h" @@ -66,11 +67,9 @@ constexpr int NULLITEM_TOOTH_AND_NAIL = 59; constexpr int PLAYER_FORM_COUNT_NEEDED = 3; constexpr int BABY_CROW = 12; constexpr int BLUE_FLY_MAX = 30; -constexpr int MAGGY_SWING_READY = 3; // The effects the combat code spawns (Lua's EffectVariant). constexpr int EFFECT_BISHOP_SHIELD = 160; -constexpr int EFFECT_CHAIN_GIB = 163; constexpr int ROCK_PARTICLE_SUBTYPE = 0x10001; // An iced enemy shatters into 3 to 6 shards at 3 to 5, a frozen one into its gibs and up to 2 more as rocks at 5, both @@ -86,7 +85,6 @@ constexpr float FROZEN_SHARD_SPEED = 5; // The sounds the combat code plays (Lua's SoundEffect). constexpr int SOUND_DEATH_BURST_BONE = 27; -constexpr int SOUND_DEATH_BURST_SMALL = 30; constexpr int SOUND_ROCKET_BLAST_DEATH = 141; constexpr int SOUND_GOODEATH = 207; constexpr int SOUND_BONE_BREAK = 500; @@ -1082,8 +1080,8 @@ static float player_contact_damage(Entity_Player& player, Entity& collider, bool return damage; } -// Part of 0078e1f0: the player's ways of touching that are not written yet: shoving an iced enemy, Tainted -// Magdalene's swing, Mega Mush's stomp, Tainted Soul grabbing her body and the suplex grab. +// Part of 0078e1f0: the player's ways of touching, Tainted Magdalene's hug, and those not written yet: shoving an iced +// enemy, Mega Mush's stomp, Tainted Soul grabbing her body and the suplex grab. static void player_contact_missing_check(Entity_Player& player, Entity& collider) { bool isEnemyLike = Entity::is_enemy_type(collider.type) || @@ -1091,9 +1089,7 @@ static void player_contact_missing_check(Entity_Player& player, Entity& collider bool isShoved = isEnemyLike && collider.HasEntityFlags(FLAG_ICE_FROZEN) && !collider.HasEntityFlags(FLAG_KNOCKED_BACK) && vector_length_squared(player.velocity) > ICE_KNOCKBACK_SPEED_SQUARED; if (isShoved) reconstruction_missing("Entity_Player::HandleCollision 0078e1f0: shoving an iced enemy (AddKnockback)"); - if (player.playerType == PLAYER_MAGDALENE_B && collider.IsVulnerableEnemy(nullptr) && - player.maggySwingCooldown < MAGGY_SWING_READY && !collider.IsFriendly()) - reconstruction_missing("Entity_Player::HandleCollision 0078e1f0: Tainted Magdalene's swing"); + tainted_magdalene_hug(player, collider); if (player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_MEGA_MUSH)) reconstruction_missing("Entity_Player::HandleCollision 0078e1f0: Mega Mush's stomp"); if (player.playerType == PLAYER_THESOUL_B && collider.type == ENTITY_PLAYER && diff --git a/src/entity_effect.cpp b/src/entity_effect.cpp index ed5fddc..7294701 100644 --- a/src/entity_effect.cpp +++ b/src/entity_effect.cpp @@ -12,6 +12,7 @@ #include "room.h" #include "sfx_manager.h" #include "mines.h" +#include "weapon_rockets.h" #include #include #include @@ -99,8 +100,8 @@ static const EffectBehaviour* behaviour_find(int variant) std::array table{}; for (auto group : {ambient_effect_behaviours(), hazard_effect_behaviours(), floor_effect_behaviours(), beam_effect_behaviours(), player_effect_behaviours(), mines_effect_behaviours(), - trail_effect_behaviours(), spike_effect_behaviours(), - std::span(TIMER_BEHAVIOURS)}) + trail_effect_behaviours(), spike_effect_behaviours(), boss_effect_behaviours(), + weapon_effect_behaviours(), std::span(TIMER_BEHAVIOURS)}) for (const EffectBehaviour& behaviour : group) table[behaviour.variant] = behaviour; return table; }(); diff --git a/src/entity_effect.h b/src/entity_effect.h index 7ee74d4..87c7095 100644 --- a/src/entity_effect.h +++ b/src/entity_effect.h @@ -47,12 +47,14 @@ enum EffectVariant : int EFFECT_DEVIL = 6, EFFECT_BLOOD_SPLAT = 7, 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_TINY_BUG = 21, EFFECT_CREEP_RED = 22, @@ -61,6 +63,8 @@ enum EffectVariant : int EFFECT_CREEP_WHITE = 25, EFFECT_CREEP_BLACK = 26, EFFECT_WOOD_PARTICLE = 27, + EFFECT_TARGET = 30, + EFFECT_ROCKET = 31, EFFECT_PLAYER_CREEP_LEMON_MISHAP = 32, EFFECT_TINY_FLY = 33, EFFECT_FART = 34, @@ -76,6 +80,7 @@ enum EffectVariant : int 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, @@ -108,6 +113,7 @@ enum EffectVariant : int EFFECT_PENTAGRAM_BLACKPOWDER = 93, EFFECT_CREEP_SLIPPERY_BROWN = 94, EFFECT_WATER_SPLASH = 99, + EFFECT_FIREWORKS = 104, EFFECT_ENEMY_BRIMSTONE_SWIRL = 110, EFFECT_HAEMO_TRAIL = 111, EFFECT_HALLOWED_GROUND = 112, @@ -129,13 +135,16 @@ enum EffectVariant : int EFFECT_PEDESTAL_RIPPLE = 134, EFFECT_RAIN_DROP = 135, EFFECT_GRID_ENTITY_PROJECTILE_HELPER = 136, + EFFECT_MIST = 138, 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, @@ -145,10 +154,15 @@ enum EffectVariant : int 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_GENERIC_TRACER = 198, - EFFECT_PLAYER_CREEP_YELLOW = 204 + EFFECT_PLAYER_CREEP_YELLOW = 204, + EFFECT_MAMA_MEGA_EXPLOSION = 127, + EFFECT_CHAIN_GIB = 163 }; // Construction and destruction (005cd9f0, 005cd960) are the defaults, the extra data shared with its other holders. @@ -217,6 +231,7 @@ std::span hazard_effect_behaviours(); std::span floor_effect_behaviours(); std::span beam_effect_behaviours(); std::span spike_effect_behaviours(); +std::span boss_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. diff --git a/src/entity_effect_boss.cpp b/src/entity_effect_boss.cpp new file mode 100644 index 0000000..ce33b60 --- /dev/null +++ b/src/entity_effect_boss.cpp @@ -0,0 +1,133 @@ +#include "entity_effect.h" +#include "game.h" +#include "npc_ai.h" +#include "room_grid.h" +#include "sfx_manager.h" + +// A beam of light from above (Crack the Sky, Isaac's and the Holy Eye's beams): a spotlight that strikes on its Hit +// event, then hurts what stands in it every third frame its beam shows. Subtype 1 is the player's, which takes subtype +// 10 after its first strike, 2 a delayed one and 3 a delayed one that also fires a cross of lasers. +enum CrackSubtype +{ + CRACK_PLAYER = 1, + CRACK_DELAYED = 2, + CRACK_DELAYED_CROSS = 3, + CRACK_PLAYER_STRUCK = 10 +}; + +// It strikes for 20. A beam that is not a player's hurts players and enemies for 2, one of +// a player's or a friendly one hurts enemies for its own damage, every 3 frames, 30 frames apart per victim. +constexpr float CRACK_STRIKE_DAMAGE = 20; +constexpr float CRACK_HOSTILE_DAMAGE = 2; +constexpr int CRACK_HIT_SPACING = 3; +constexpr int CRACK_HIT_COUNTDOWN = 30; +constexpr int CRACK_SHAKE = 5; +// The crater it leaves. +constexpr int CRACK_CRATER_SUBTYPE = 1; +constexpr float CRACK_CRATER_SCALE = 0.5f; +constexpr int CRACK_BEAM_LAYER = 0; +constexpr int CRACK_STRUCK = 1; +constexpr int CRACK_NPC_TYPE_FIRST = 10; + +// Part of 005cdb20 (Init's case 19) A beam strikes for 20. +static void crack_init(Entity_Effect& crack) +{ + crack.collisionDamage = CRACK_STRIKE_DAMAGE; +} + +// Hurts what stands in the beam, its source spared: players when it is not a player's, enemies always. +static void crack_hit(Entity_Effect& crack) +{ + Entity* source = crack.parent ? crack.parent.get() : &crack; + bool isVersus = g_game->deathmatchManager.is_active(); + bool isHostile = source->type != ENTITY_PLAYER; + if (isVersus) isHostile = true; + else if (source->HasEntityFlags(FLAG_DELIRIUM_FORM)) isHostile = false; + + for (Entity* entity : entity_query_radius(crack.pos, crack.size, QUERY_ALL)) + { + if (entity == source || entity->isDead || entity->entityCollisionClass == ENTCOLL_NONE) continue; + if (entity->maxHitPoints <= 0 || (!isVersus && entity->type == source->type)) continue; + + if (entity->type == ENTITY_PLAYER && isHostile) + { + if (isVersus) reconstruction_missing("Entity_Effect::Update 005d4380: a versus mode beam's hit"); + entity->TakeDamage(CRACK_HOSTILE_DAMAGE, 0, EntityRef(source), CRACK_HIT_COUNTDOWN); + } + else if (entity->type >= CRACK_NPC_TYPE_FIRST) + { + float damage = isHostile ? CRACK_HOSTILE_DAMAGE : crack.collisionDamage; + entity->TakeDamage(damage, 0, EntityRef(source), CRACK_HIT_COUNTDOWN); + } + } + if (crack.subtype == CRACK_PLAYER) crack.subtype = CRACK_PLAYER_STRUCK; +} + +// 005e96b5 (Update's case 19) The spotlight charges, strikes with a crater and a shake, hurts every third frame its +// beam shows, and goes once its animation ends. +static void crack_update(Entity_Effect& crack) +{ + if (crack.state == 0) + { + crack.sprite.Play(crack.subtype == CRACK_DELAYED_CROSS ? "SpotlightDelayed2" + : crack.subtype == CRACK_DELAYED ? "SpotlightDelayed" + : "Spotlight"); + crack.state++; + } + if (crack.subtype == CRACK_DELAYED_CROSS) + reconstruction_missing("Entity_Effect::Update 005d4380: the delayed beam with a cross of lasers"); + + if (crack.sprite.IsEventTriggered("Sound")) npc_sound_play(SOUND_LIGHTBOLT_CHARGE, 1, 2, 1); + if (crack.sprite.IsEventTriggered("Hit")) + { + npc_sound_play(SOUND_LIGHTBOLT, 1, 2, 1); + game_shake_screen(CRACK_SHAKE); + Entity* crater = g_game->Spawn({.position = crack.pos, .subType = CRACK_CRATER_SUBTYPE, .type = ENTITY_EFFECT, + .variant = EFFECT_BOMB_CRATER, .seed = crack.dropRNG.Next()}); + crater->sprite.scale = vector_make(CRACK_CRATER_SCALE, CRACK_CRATER_SCALE); + crater->Update(); + crack.state = CRACK_STRUCK; + } + + const AnimationFrame* beam = crack.sprite.animState.GetLayerFrame(CRACK_BEAM_LAYER); + if (crack.subtype < CRACK_PLAYER_STRUCK && beam && beam->isVisible) + { + if ((crack.state - 1) % CRACK_HIT_SPACING == 0) crack_hit(crack); + crack.state++; + } + if (crack.sprite.IsFinished()) crack.Remove(); +} + +// The ghostly flame the Lamb's body burns with. Fires the players set (and their familiars') are not reconstructed. +constexpr float FLAME_FRICTION = 0.95f; +constexpr int FLAME_HIT_RESET_FRAMES = 5; + +// Part of 005cdb20 (Init's fire case) A flame keeps off pits, owned by whoever fired the tear or bomb that set it. +static void flame_init(Entity_Effect& flame) +{ + flame.entityGridCollisionClass = GRIDCOLL_NOPITS; + Entity* spawner = flame.spawnerEntity.get(); + bool isShot = spawner && (spawner->type == ENTITY_TEAR || spawner->type == ENTITY_BOMB); + if (isShot && spawner->spawnerEntity) flame.spawnerEntity = spawner->spawnerEntity.get(); +} + +// 005f021a (Update's fire case) A flame slows, forgets what it burned every 5 frames, and goes once dead. +static void flame_update(Entity_Effect& flame) +{ + flame.friction *= FLAME_FRICTION; + if (flame.IsFrame(FLAME_HIT_RESET_FRAMES, (int)flame.index)) flame.hitList.clear(); + if (flame.spawnerType == ENTITY_PLAYER || flame.spawnerType == ENTITY_FAMILIAR) + reconstruction_missing("Entity_Effect::Update 005d4380: a player's fire burning what it touches"); + flame.state++; + if (flame.isDead) flame.Remove(); +} + +constexpr auto BOSS_EFFECT_BEHAVIOURS = std::to_array({ + {EFFECT_BLUE_FLAME, flame_init, effect_finishing, nullptr}, + {EFFECT_CRACK_THE_SKY, crack_init, effect_finishing, nullptr}, +}); + +std::span boss_effect_behaviours() +{ + return BOSS_EFFECT_BEHAVIOURS; +} diff --git a/src/entity_factory.cpp b/src/entity_factory.cpp index fc40bdf..8dd53ab 100644 --- a/src/entity_factory.cpp +++ b/src/entity_factory.cpp @@ -22,6 +22,8 @@ #include constexpr uint64_t NS_PER_MS = 1000000; +// The seed of a pedestal's Flip item comes from its own with this shift. +constexpr uint32_t FLIP_SEED_SHIFT_INDEX = 39; // An entity made by a Delirium form (by the original's use: Delirium's look and lowered thresholds), which its own // spawns inherit. @@ -1006,7 +1008,14 @@ static bool entity_entry_spawn(Room& room, RoomEntry& entry, const RoomEntrySpaw pickup->variant == PICKUP_COLLECTIBLE; if (game.playerManager.FirstCollectibleOwner(COLLECTIBLE_FLIP, LAZARUS_SHARE_CHECK) && !pickup->isDead && isFlippable) - reconstruction_missing("Room::SpawnEntry 007ed310: Flip's ghost item (EntitySaveState)"); + { + auto other = std::make_shared(); + other->type = pickup->type; + other->variant = pickup->variant; + other->initSeed = rng_make(pickup->initSeed, FLIP_SEED_SHIFT_INDEX).Next(); + other->subtype = game.itemPool.GetSeededCollectible(other->initSeed, true, *room.descriptor); + pickup->flipSaveState = other; + } pickup->altPedestalANM2.Reset(); } if (entity_type_is_saved(type, entry.variant, entry.subtype, 0, false)) diff --git a/src/entity_familiar.cpp b/src/entity_familiar.cpp index ec0ac58..def6174 100644 --- a/src/entity_familiar.cpp +++ b/src/entity_familiar.cpp @@ -1,4 +1,5 @@ #include "entity_familiar.h" +#include "active_items.h" #include "boss_ai.h" #include "entity_effect.h" #include "entity_list.h" @@ -14,6 +15,7 @@ #include "room_grid.h" #include "sfx_manager.h" #include +#include // The familiars that join the following line, and the ones that trail the player's path instead (Init 0060de70). constexpr int FOLLOWER_VARIANTS[] = {1, 2, 4, 5, 6, 7, 9, 10, 11, 20, 21, 22, 23, 40, 41, 3, @@ -45,6 +47,28 @@ constexpr int KEEP_HIT_LIST_VARIANTS[] = {24, 102}; constexpr int SACK_VARIANTS[] = {20, 21, 22, 23, 57, 82, 91, 114}; constexpr int FLOAT_DOWN_VARIANTS[] = {20, 21, 22, 57, 82, 91, 114}; +// The familiars that only follow. +constexpr int FOLLOW_ONLY_VARIANTS[] = {26, 27, 40, 41, 103}; + +// Guppy's Hairball: its cord's slack and pull, its drag, mass and damage by size, and how far apart hairballs keep. +constexpr float HAIRBALL_CORD_SQUARED = 900; +constexpr float HAIRBALL_CORD_BASE = 15; +constexpr float HAIRBALL_CORD_PUSH = 1.4f; +constexpr float HAIRBALL_CORD_PULL = 0.07f; +constexpr float HAIRBALL_DRAG = 0.87f; +constexpr float HAIRBALL_DRAG_STEP = 0.01f; +constexpr float HAIRBALL_MASS_STEP = 3; +constexpr float HAIRBALL_DAMAGE = 3; +constexpr float HAIRBALL_SPACING = 20; +constexpr float HAIRBALL_SPACING_PUSH = 0.1f; +constexpr size_t HAIRBALL_ANIM_SIZE = 50; + +// BBF's growth back in, Blue Baby's soul's drag, Dry Baby's Necronomicon and its page, and Mongo Baby's Demon Baby. +constexpr float BBF_GROWTH = 0.05f; +constexpr float BLUE_BABY_SOUL_DRAG = 0.8f; +constexpr int DRY_BABY_GIANTBOOK = 1; +constexpr int MONGO_MIMIC_DEMON_BABY = 1; + // The followers that shoot, and the orbitals that only circle. constexpr int SHOOTER_VARIANTS[] = {1, 4, 5, 6, 7, 9, 10, 11, 12, 54, 81, 92, 97, 209, 220}; constexpr int ORBITAL_VARIANTS[] = {30, 31, 32, 33, 35, 44, 60, 65, 69, 84, 117, 121, 126}; @@ -531,6 +555,90 @@ static void creep_drop(Entity_Familiar& familiar, int creepVariant) trail_finish(*creep, trail_scale()); } +// Part of 0061da10: Guppy's Hairball swings on its cord, bigger, heavier and harder with each size (its subtype), and +// keeps off the other hairballs. +static void hairball_update(Entity_Familiar& hairball) +{ + unsigned size = (unsigned)hairball.subtype + 1; + char name[HAIRBALL_ANIM_SIZE]; + std::snprintf(name, sizeof(name), vector_length_squared(hairball.velocity) >= 1 ? "Idle%u" : "Float%u", size); + hairball.sprite.Play(name); + + float sizeF = (float)size; + Vector fromPlayer = vector_sub(hairball.pos, hairball.player->pos); + if (vector_length_squared(fromPlayer) > HAIRBALL_CORD_SQUARED) + { + float slack = std::min(sizeF + sizeF + HAIRBALL_CORD_BASE - vector_length(fromPlayer), HAIRBALL_CORD_PUSH); + hairball.velocity = + vector_add(hairball.velocity, vector_scale(vector_normalized(fromPlayer), slack * HAIRBALL_CORD_PULL)); + } + hairball.velocity = vector_scale(hairball.velocity, sizeF * HAIRBALL_DRAG_STEP + HAIRBALL_DRAG); + hairball.mass = sizeF * HAIRBALL_MASS_STEP + HAIRBALL_MASS_STEP; + hairball.collisionDamage = sizeF + sizeF + HAIRBALL_DAMAGE; + + for (Entity_Familiar* other : familiar_query(hairball.variant)) + { + if (!other->isExists || other == &hairball) continue; + + Vector apart = vector_sub(hairball.pos, other->pos); + float push = std::max(HAIRBALL_SPACING - vector_length(apart), 0.0f); + hairball.velocity = vector_add(hairball.velocity, vector_resized(apart, push * HAIRBALL_SPACING_PUSH)); + } +} + +// Part of 0061da10: BBF bounces about growing in, hurting enemies once full grown. After its blast it hides, and comes +// back on the player when its counter runs out. +static void bbf_update(Entity_Familiar& bbf) +{ + bbf.entityGridCollisionClass = GRIDCOLL_WALLS; + LayerState* body = bbf.sprite.GetLayer(0); + if (bbf.subtype == 0) + { + float grown = body->size.x; + if (grown >= 1) bbf.entityCollisionClass = ENTCOLL_ENEMIES; + else + { + grown = std::min(grown + BBF_GROWTH, 1.0f); + body->size = vector_make(grown, grown); + } + bbf.isVisible = true; + return bbf.MoveDiagonally(1); + } + + bbf.entityCollisionClass = ENTCOLL_NONE; + bbf.isVisible = false; + body->size = {}; + bbf.velocity = {}; + if (bbf.counter > 0 && --bbf.counter < 1) + { + bbf.subtype = 0; + if (bbf.player) bbf.pos = bbf.player->pos; + } +} + +// Part of 0061da10: Dry Baby, once its hit plays out, reads the Necronomicon with its big page. It follows, counting +// its cooldown down. +static void dry_baby_update(Entity_Familiar& baby) +{ + if (baby.sprite.IsFinished("Hit")) + { + baby.sprite.Play("Idle"); + baby.player->UseActiveItem({.item = COLLECTIBLE_NECRONOMICON, .flags = USE_NOANIM}); + g_game->itemOverlay.Show(DRY_BABY_GIANTBOOK, 0, nullptr); + } + baby.FollowParent(); + if (baby.fireCooldown > 0) baby.fireCooldown--; +} + +// Part of 0061da10: Abel follows the player's mirror image across the room's centre and shoots. +static void abel_update(Entity_Familiar& abel) +{ + Vector center = Room::GetCenterPos(); + Vector fromCenter = vector_sub(abel.player->pos, center); + abel.FollowPosition(vector_sub(center, fromCenter)); + abel.Shoot(); +} + // The behaviours of 0061da10 by variant. The familiars not reconstructed yet stop the game. void Entity_Familiar::variant_update() { @@ -550,16 +658,32 @@ void Entity_Familiar::variant_update() if (sprite.IsFinished("Spawn")) sprite.Play(variant == RELIC ? "Float" : "FloatDown"); return; } + if (familiar_listed(FOLLOW_ONLY_VARIANTS, variant)) return FollowParent(); switch (variant) { case DEMON_BABY: return ai_auto_shooter(); + case ABEL: return abel_update(*this); + case BLUE_BABY_SOUL: + MoveDiagonally(1); + velocity = vector_scale(velocity, BLUE_BABY_SOUL_DRAG); + return Shoot(); + case DADDY_LONGLEGS: return ai_daddy_longlegs(); + case PEEPER: + case PEEPER_2: + MoveDiagonally(1); + return sprite.Play("Float"); case BUM_FRIEND: case DARK_BUM: case KEY_BUM: case SUPER_BUM: return ai_pickup_sack(); case HOLY_WATER: case BIG_CHUBBY: return ai_charger(); + case GUPPYS_HAIRBALL: return hairball_update(*this); + case CUBE_OF_MEAT_2: + case BALL_OF_BANDAGES_2: + velocity = vector_sub(GetOrbitPosition(player->pos), pos); + return Shoot(); case CUBE_OF_MEAT_3: case CUBE_OF_MEAT_4: case LEECH: return ai_walker(); @@ -567,6 +691,7 @@ void Entity_Familiar::variant_update() case BALL_OF_BANDAGES_4: ai_walker(); return Shoot(); + case DRY_BABY: return dry_baby_update(*this); case HEADLESS_BABY: FollowParent(); if (IsFrame(HEADLESS_SPLAT_INTERVAL, 0)) @@ -584,14 +709,32 @@ void Entity_Familiar::variant_update() FollowParent(); if (IsFrame(JUICY_SACK_CREEP_INTERVAL, 0)) creep_drop(*this, EFFECT_PLAYER_CREEP_WHITE); return; + case BBF: return bbf_update(*this); case LITTLE_CHUBBY: case BOBS_BRAIN: return ai_charger(); case DEAD_BIRD: case EVES_BIRD_FOOT: case LIL_HAUNT: return ai_flying_bird(); + case LIL_BRIMSTONE: + case LIL_MONSTRO: + case LIL_ABADDON: + FollowParent(); + return ai_incubus_shot(); + case BLUE_SPIDER: return blue_spider_update(*this); + case MONGO_BABY: + if (subtype == MONGO_MIMIC_DEMON_BABY || + (player->HasCollectible(COLLECTIBLE_DEMON_BABY) && player->fireDirection == DIRECTION_NONE)) + return ai_auto_shooter(); + FollowParent(); + return Shoot(); + case CAINS_OTHER_EYE: case INCUBUS: FollowParent(); return update_weapon(false); + case ACID_BABY: + FollowParent(); + if (sprite.IsFinished()) sprite.Play("Idle"); + return; case BLUE_FLY: return ai_blue_fly(); case FORGOTTEN_BODY: return forgotten_body_update(*this); default: reconstruction_missing("Entity_Familiar::Update 0061da10 (this familiar's behaviour)"); @@ -656,11 +799,12 @@ void Entity_Familiar::update_tail() } // 00624a80 Moves between frames: the orbit's spin carried for the move only. Incubus aims and fires between frames too, -// the other variants that act on interpolation stop the game. +// Lil Brimstone charges, and the other variants that act on interpolation stop the game. void Entity_Familiar::Interpolate() { - if (variant == LIL_BRIMSTONE || variant == DAMOCLES || variant == BLOOD_BABY || variant == UMBILICAL_BABY) + if (variant == DAMOCLES || variant == BLOOD_BABY || variant == UMBILICAL_BABY) reconstruction_missing("Entity_Familiar::Interpolate 00624a80 (this familiar's interpolation)"); + if (variant == LIL_BRIMSTONE) ai_incubus_shot(); if (variant == INCUBUS) update_weapon(true); float savedAngle = orbitAngleOffset; diff --git a/src/entity_familiar.h b/src/entity_familiar.h index 62f3efe..4f40916 100644 --- a/src/entity_familiar.h +++ b/src/entity_familiar.h @@ -33,6 +33,13 @@ enum FireMode FIRE_EXACT }; +// Whether FireBrimstone's beam is the familiar's own shot (tinted, linked and shown on its head) or a bare beam. +enum BrimstoneLook +{ + BRIMSTONE_OWN, + BRIMSTONE_BARE +}; + // PickEnemyTarget's flags. enum TargetFlag : uint32_t { @@ -147,23 +154,27 @@ struct Entity_Familiar : Entity MULTIDIMENSIONAL_BABY = 101, SUPER_BUM = 102, TONSIL = 103, + DEPRESSION = 105, BIG_CHUBBY = 104, SHADE = 106, HUSHY = 107, LIL_MONSTRO = 108, KING_BABY = 109, YO_LISTEN = 111, + ACID_BABY = 112, SPIDER_BABY = 113, BROWN_NUGGET_POOTER = 115, BLOODSHOT_EYE = 116, ANGRY_FLY = 118, BUDDY_IN_A_BOX = 119, SPRINKLER = 120, + MOMS_RAZOR = 117, LEPROSY = 121, LIL_HARBINGERS = 122, MYSTERY_EGG = 124, LIL_SPEWER = 125, SLIPPED_RIB = 126, + POINTY_RIB = 127, BONE_ORBITAL = 128, HALLOWED_GROUND = 129, JAW_BONE = 130, @@ -172,6 +183,7 @@ struct Entity_Familiar : Entity DIP = 201, DAMOCLES = 202, BLOOD_OATH = 203, + PSY_FLY = 204, WISP = 206, PEEPER_2 = 207, BOILED_BABY = 208, @@ -331,7 +343,7 @@ struct Entity_Familiar : Entity Entity_Tear* FireProjectile(const Vector& aimDirection, FireMode mode); bool TryFireTear(Entity_Tear* tear); void shot_owner_convert(Entity* shot); - bool apply_baby_bender(Entity_Tear* tear); + bool apply_baby_bender(Entity_Laser& laser); bool apply_baby_bender_tear_params(TearFlags& flags, ColorMod& color, float* height, float* fallingSpeed, float* range, bool isLaser); bool CanPlayerFire(); @@ -359,6 +371,8 @@ struct Entity_Familiar : Entity void ai_samsons_chains(); void update_weapon(bool isInterpolated); void ai_lil_gurdy(); + void ai_incubus_shot(); + void charged_shot_fire(Vector aim, FireMode mode); void store_backup(FamiliarData* backup); void RestoreState(const FamiliarData& saved); void MoveDelayed(int numFrames); @@ -373,7 +387,7 @@ struct Entity_Familiar : Entity void update_angry_fly(); void ai_lil_spewer(); void ai_lil_harbingers(); - Entity_Laser* FireBrimstone(const Vector& aimDirection, uint8_t unk); + Entity_Laser* FireBrimstone(const Vector& aimDirection, BrimstoneLook look); static Entity* ThrowDip(int subType, const Vector& position, Entity* spawner); Entity_Laser* sprinkler_shoot_laser(float angle, float distance); void update_idle_anim_by_size(); @@ -406,6 +420,8 @@ private: void blood_puppy_restore(float bodyHealth); bool collision_block(Entity& collider, bool isIgnored); bool collision_contact(Entity& collider, float damageMultiplier, float damage); + void collision_hurt(Entity& collider, float damageMultiplier, float dealt); + float collision_multiplier(Entity& collider); bool solid_check(Entity& collider, bool isIgnored); }; @@ -438,3 +454,5 @@ void familiar_check(Entity_Player& player, const FamiliarCount& familiars); void familiars_evaluate(Entity_Player& player); int familiar_lullaby_delay(Entity_Familiar& familiar, int fireDelay); bool bum_pickup_collect(Entity_Familiar& bum, Entity_Pickup& pickup); +void blue_spider_update(Entity_Familiar& spider); +Entity_Familiar* spawn_blue_spider(const Vector& position, Entity* spawner, Vector target); diff --git a/src/entity_list.cpp b/src/entity_list.cpp index 9d64584..204c297 100644 --- a/src/entity_list.cpp +++ b/src/entity_list.cpp @@ -15,6 +15,9 @@ #include constexpr const char* SHADOW_PNG = "gfx/shadow.png"; + +// How much lower a walking player's reflection sits in the water. +constexpr float PLAYER_REFLECTION_DROP = 4; constexpr int BOMB_ROCKET = 19; constexpr int BOMB_ROCKET_GIGA = 20; constexpr int KNIFE_MAIN = 0; @@ -726,18 +729,44 @@ void EntityList::sort_by_render_z() } } +// Draws an entity upside down in the water's reflection, its offset mirrored, a walking player's 4 lower. +static void reflection_render(Entity& entity, const Vector& offset) +{ + bool isWalkingPlayer = entity.type == ENTITY_PLAYER && entity.entityGridCollisionClass <= GRIDCOLL_WALLS; + Vector saved = entity.posOffset; + + entity.posOffset.y = -saved.y; + DAT_00c7977d = 1; + entity.Render(vector_make(offset.x, offset.y + (isWalkingPlayer ? PLAYER_REFLECTION_DROP : 0))); + DAT_00c7977d = 0; + entity.posOffset = saved; +} + // 004199d0 Draws the render list from the cursor up to a depth, as the room's render pass asks: normally, or only -// what shows above, through or mirrored in its water. +// what shows above the water, refracted under it or mirrored in it, by how the water clips each entity. void EntityList::render_up_to(uint32_t maxDepth, const Vector& offset) { for (; renderCursor < renderEL.size(); renderCursor++) { Entity* entity = renderEL[renderCursor]; if ((uint32_t)entity->GetRenderZ() >= maxDepth) return; - if (renderMode == RENDER_SKIP) continue; - if (renderMode >= RENDER_WATER_ABOVE && renderMode <= RENDER_WATER_REFLECT) - reconstruction_missing("EntityList::render_up_to 004199d0: the water passes (get_water_splash_variant)"); - entity->Render(offset); + + uint32_t clip = renderMode >= RENDER_WATER_ABOVE ? entity->GetWaterClipInfo().flags : 0; + switch (renderMode) + { + case RENDER_SKIP: break; + case RENDER_WATER_ABOVE: + if ((clip & (WATER_CLIP_UNDER | WATER_CLIP_SURFACE)) != WATER_CLIP_UNDER) entity->Render(offset); + break; + case RENDER_WATER_REFRACT: + if (!(clip & (WATER_CLIP_ABOVE | WATER_CLIP_SURFACE)) && clip & (WATER_CLIP_UNDER | WATER_CLIP_INSIDE)) + entity->Render(offset); + break; + case RENDER_WATER_REFLECT: + if (!(clip & (WATER_CLIP_NO_REFLECTION | WATER_CLIP_SURFACE))) reflection_render(*entity, offset); + break; + default: entity->Render(offset); + } } } diff --git a/src/entity_npc.cpp b/src/entity_npc.cpp index 4e271c5..ce5b8e1 100644 --- a/src/entity_npc.cpp +++ b/src/entity_npc.cpp @@ -1,6 +1,7 @@ #include "entity_npc.h" #include "boss_ai.h" #include "boss_death.h" +#include "entity_bomb.h" #include "entity_config.h" #include "entity_effect.h" #include "entity_familiar.h" @@ -42,15 +43,34 @@ constexpr int APPEAR_OVERLAY_KEPT_TYPE = 266; constexpr int APPEAR_SOUND_TYPE_A = 401; constexpr int APPEAR_SOUND_TYPE_B = 403; constexpr std::array APPEAR_EVENT_TYPES = {404, 912, 913, 917}; -constexpr std::array DEATH_EVENT_TYPES = {102, 900, 907, 908, 912, 913, 915, 921}; constexpr std::array FLUSH_TYPES = {217, 220, 223, 261, 402, 870, 871, 872, 914}; constexpr int FLUSH_PROP_TYPE = 237; constexpr int FLUSH_PROP_VARIANT = 2; constexpr int FLUSH_RENDER_Z = 5000; + +// The bosses' death events: Isaac's cry, Baby Plum's last ring, Singe's blast, Mother's slam and Clutch's explosions. +constexpr int ISAAC_DEATH_CRY_FRAME = 17; +constexpr float ISAAC_DEATH_CRY_VOLUME = 2; +constexpr float PLUM_RING_FALL = 0.099f; +constexpr float PLUM_RING_SPEED = 6; +constexpr float PLUM_RING_SHOTS = 10; +constexpr float SINGE_BLAST_DAMAGE = 80; +constexpr float SINGE_BLAST_REACH = 1.5f; +constexpr int MOTHER_SLAM_VARIANT = 10; +constexpr int MOTHER_SLAM_SHAKE = 20; +constexpr float MOTHER_SLAM_PITCH = 0.5f; +constexpr int CLUTCH_BLAST_SUBTYPE = 3; +constexpr float CLUTCH_BLAST_RAISE = -20; +constexpr float CLUTCH_BLAST_SCALE = 1.5f; +constexpr float CLUTCH_BLAST_DAMAGE = 80; +constexpr float CLUTCH_BLAST_VOLUME = 1.25f; +constexpr float CLUTCH_PITCH = 0.9f; +constexpr float CLUTCH_PITCH_SPREAD = 0.2f; +constexpr int CLUTCH_BLAST_SHAKE = 14; +constexpr float CLUTCH_BLAST_SPIN = 360; constexpr int ENTITY_FORWARD_NONE = 45; constexpr int ENTITY_FORWARD_DOWN_A = 262; constexpr int ENTITY_FORWARD_DOWN_B = 263; -constexpr int DEATH_HEAD_LAYER_TYPE = 405; constexpr int DEATH_NO_BURST_FIRST = 74; constexpr int DEATH_NO_BURST_LAST = 76; constexpr int MULLIGAN_VARIANT_FLEEING = 2; @@ -459,14 +479,25 @@ static int line_cell_collision(Room& room, int column, int row) return path >= GRID_PATH_SOLID ? COLLISION_SOLID : COLLISION_NONE; } +// Whether a blast stops at a cell: walls (but an unlocked lock or a door) and solid blocks. +static bool line_cell_is_blast_wall(Room& room, int cellIndex) +{ + uint32_t collision = room.GetGridCollision(cellIndex); + bool isKnown = cellIndex >= 0 && cellIndex < ROOM_GRID_CELLS; + GridEntity* grid = isKnown ? room.gridEntities[cellIndex] : nullptr; + if (collision == COLLISION_NONE) return false; + if (!grid) return collision == COLLISION_WALL; + if (grid->type == GRID_ROCKB) return true; + if (grid->type == GRID_LOCK && g_game->playerManager.AnyoneHasTrinket(TRINKET_BROKEN_PADLOCK)) return false; + return grid->type != GRID_DOOR && collision == COLLISION_WALL; +} + // 007f0df0 Whether a line from start to end is clear, walked in steps of 10: mode 0 checks a 10 wide band for grid // collision and for more than 8 cells walked past their grid path threshold, mode 1 the same on the line's own cells, -// mode 3 the band for shots (which fly over pits). The other modes, crushable rocks and the stop position are left -// to come. +// mode 2 the line's own cells for what stops a blast, mode 3 the band for shots (which fly over pits). Crushable +// rocks and the stop position are left to come. bool room_check_line(const Vector& start, const Vector& end, int mode, int gridPathThreshold) { - if (mode != LINE_MODE_GROUND && mode != LINE_MODE_CELL && mode != LINE_MODE_PROJECTILE) - reconstruction_missing("Room::CheckLine 007f0df0: the single cell modes"); Room& room = *g_game->room; Vector step = vector_sub(start, end); @@ -488,6 +519,15 @@ bool room_check_line(const Vector& start, const Vector& end, int mode, int gridP for (float walked = 0; walked < length; walked += LINE_STEP) { at = vector_sub(at, step); + if (mode == LINE_MODE_EXPLOSION) + { + int column = cellOf(at.x, GRID_CELL); + int row = cellOf(at.y, GRID_TOP); + bool isInside = column >= 0 && column < room.gridWidth && row >= 0 && row < room.gridHeight; + int cellIndex = isInside ? row * room.gridWidth + column : -1; + if (line_cell_is_blast_wall(room, cellIndex)) return false; + continue; + } if (mode == LINE_MODE_CELL) { int column = cellOf(at.x, GRID_CELL); @@ -1489,6 +1529,66 @@ void Entity_NPC::appear_init() if (IsBoss() && !parent) game_encountered_boss_add(type, variant); } +// Rag Man keeps its head through its death only if the head shows on the frame it died on. +static void death_head_layer_keep(ANM2& sprite) +{ + LayerState* head = sprite.GetLayer("Head"); + if (!head) return; + const AnimationFrame* frame = sprite.animState.GetLayerFrame(head->layerData ? head->layerData->id : -1); + head->isVisible = frame && frame->isVisible; +} + +// Part of 006c4b30: what the bosses with death events do as they die: Isaac's cry, Baby Plum's spit and last ring, +// Reap Creep losing its overlay, Singe's blast, Mother's slam, Clutch's explosions and Gideon's own. +static void death_events_update(Entity_NPC& npc) +{ + switch (npc.type) + { + case ENTITY_ISAAC: + if (npc.variant != ISAAC_FORM_HUSH && npc.stateFrame == ISAAC_DEATH_CRY_FRAME) + npc.PlaySound(SOUND_SUPERHOLY, ISAAC_DEATH_CRY_VOLUME, 2, false, 1); + return; + case ENTITY_BABY_PLUM: + { + if (npc.sprite.IsEventTriggered("Shoot")) npc_sound_play(SOUND_MEAT_JUMPS, 1, 2, 1); + if (!npc.sprite.IsFinished() || !npc.isDead) return; + ProjectileParams params; + params.fallingAccelModifier -= PLUM_RING_FALL; + return npc.FireProjectiles(npc.pos, vector_make(PLUM_RING_SPEED, PLUM_RING_SHOTS), PROJECTILES_RING, params); + } + case ENTITY_GIDEON: + return NpcHelper::gideon_update_death(&npc); + case ENTITY_REAP_CREEP: + if (npc.sprite.overlayAnimState.animData) npc.sprite.RemoveOverlay(); + return; + case ENTITY_SINGE: + if (npc.sprite.IsFinished() && npc.isDead) + explosion_effects({.position = npc.pos, .source = &npc, .damage = SINGE_BLAST_DAMAGE, + .radiusMultiplier = SINGE_BLAST_REACH}); + return; + case ENTITY_MIN_MIN: + if (npc.sprite.IsEventTriggered("Shoot") && npc.sprite.GetNullFrame("BloodGuide")) + reconstruction_missing("Entity_NPC::Update 006c4b30: Min-Min's death bursts"); + return; + case ENTITY_MOTHER: + if (npc.variant != MOTHER_SLAM_VARIANT || !npc.sprite.IsEventTriggered("Shoot")) return; + game_shake_screen(MOTHER_SLAM_SHAKE); + return npc.PlaySound(SOUND_DEATH_REVERSE, 1, 2, false, MOTHER_SLAM_PITCH); + case ENTITY_CLUTCH: + { + if (!npc.sprite.IsEventTriggered("Explosion")) return; + Entity* blast = spawn_at(ENTITY_EFFECT, EFFECT_ENEMY_GHOST, CLUTCH_BLAST_SUBTYPE, npc.pos, nullptr); + blast->posOffset = vector_make(0, CLUTCH_BLAST_RAISE); + blast->sprite.rotation = random_unit() * CLUTCH_BLAST_SPIN; + blast->sprite.scale = vector_make(CLUTCH_BLAST_SCALE, CLUTCH_BLAST_SCALE); + blast->SetCollisionDamage(CLUTCH_BLAST_DAMAGE); + blast->Update(); + npc_sound_play(SOUND_DEMON_HIT, CLUTCH_BLAST_VOLUME, 2, random_unit() * CLUTCH_PITCH_SPREAD + CLUTCH_PITCH); + return game_shake_screen(CLUTCH_BLAST_SHAKE); + } + } +} + // Part of 006c4b30: a boss or Chub dying through its death animations, which ends it (trigger_kill_item_effects). void Entity_NPC::death_animation_update() { @@ -1497,8 +1597,7 @@ void Entity_NPC::death_animation_update() friction *= APPEAR_FRICTION; if (stateFrame == 0) death_animation_start(); stateFrame++; - if (std::ranges::find(DEATH_EVENT_TYPES, type) != DEATH_EVENT_TYPES.end()) - reconstruction_missing("Entity_NPC::Update 006c4b30: a boss's death animation events"); + death_events_update(*this); if (const NullFrame* bloodGuide = sprite.GetNullFrame("BloodGuide")) npc_blood_guide_update(*this, *bloodGuide); if (type == ENTITY_HUSH && sprite.IsEventTriggered("ash")) @@ -1526,8 +1625,9 @@ void Entity_NPC::death_animation_start() if (sprite.GetAnimationData("Death")) { - if (type == ENTITY_BIG_HORN || type == DEATH_HEAD_LAYER_TYPE) - reconstruction_missing("Entity_NPC::Update 006c4b30: Big Horn's and its kin's death animations"); + if (type == ENTITY_BIG_HORN) + return reconstruction_missing("Entity_NPC::Update 006c4b30: Big Horn's death animations"); + if (type == ENTITY_RAG_MAN) death_head_layer_keep(sprite); sprite.Play("Death"); return; } @@ -2689,18 +2789,6 @@ void Entity_NPC::render_overlay(const Vector&, bool) reconstruction_missing("Entity_NPC::render_overlay 004e9b10"); } -// 00548f30 -int Entity_NPC::FindTargetPit(const Vector&, const Vector&, uint32_t) -{ - reconstruction_missing("Entity_NPC::FindTargetPit 00548f30"); -} - -// 0055cef0 -Entity_NPC* Entity_NPC::ThrowStrider(const Vector&, Entity*, const Vector&) -{ - reconstruction_missing("Entity_NPC::ThrowStrider 0055cef0"); -} - // 0059bed0 void Entity_NPC::RenderSegmentLink(const Vector&, bool) { diff --git a/src/entity_npc.h b/src/entity_npc.h index b6ff0e8..618684b 100644 --- a/src/entity_npc.h +++ b/src/entity_npc.h @@ -365,12 +365,14 @@ struct Entity_NPC : Entity 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). +// Room::CheckLine's modes: a 10 wide band for walkers, the line's own cells, those cells for blasts, 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_EXPLOSION = 2, LINE_MODE_PROJECTILE = 3 }; constexpr int LINE_CHECK_THRESHOLD = 999; diff --git a/src/entity_npc_render.cpp b/src/entity_npc_render.cpp index b777630..5c6d81e 100644 --- a/src/entity_npc_render.cpp +++ b/src/entity_npc_render.cpp @@ -43,9 +43,6 @@ constexpr float LAMB_AFTERIMAGE_FADE = 0.9f; constexpr float LAMB_AFTERIMAGE_BASE = 0.1f; constexpr float LAMB_COPY_ALPHA = 0.2f; -// The small leech hides above water while it swims below this height. -constexpr float SMALL_LEECH_SURFACE = -3; - // A pickup held at the Item null rides a little lower. constexpr float HELD_PICKUP_DROP = 6.5f; diff --git a/src/entity_npc_rewards.cpp b/src/entity_npc_rewards.cpp index e2bdcd0..6f9db96 100644 --- a/src/entity_npc_rewards.cpp +++ b/src/entity_npc_rewards.cpp @@ -221,10 +221,9 @@ static void kill_item_rewards(Entity_NPC& npc) kill_flag_drops(npc); kill_source_rewards(npc); - if (players.RandomCollectibleOwner(COLLECTIBLE_INFESTATION_2, npc.initSeed, nullptr) && - !is_killed_by(npc, ENTITY_FAMILIAR, Entity_Familiar::BLUE_SPIDER)) - reconstruction_missing( - "Entity_NPC::trigger_death_rewards 006bbdc0: Infestation 2 (spawn_blue_spider 00638e30)"); + Entity_Player* infested = players.RandomCollectibleOwner(COLLECTIBLE_INFESTATION_2, npc.initSeed, nullptr); + if (infested && !is_killed_by(npc, ENTITY_FAMILIAR, Entity_Familiar::BLUE_SPIDER)) + infested->ThrowBlueSpider(npc.pos, {}); Entity_Player* spurs = players.RandomCollectibleOwner(COLLECTIBLE_BONE_SPURS, npc.initSeed, nullptr); if (spurs && !is_killed_by(npc, ENTITY_FAMILIAR, Entity_Familiar::BONE_SPUR)) bone_spurs_spawn(npc, *spurs); if (players.RandomCollectibleOwner(COLLECTIBLE_HUNGRY_SOUL, npc.initSeed, nullptr) && diff --git a/src/entity_pickup.cpp b/src/entity_pickup.cpp index f994c91..e06df17 100644 --- a/src/entity_pickup.cpp +++ b/src/entity_pickup.cpp @@ -59,6 +59,7 @@ constexpr int TRINKET_BLOODY_PENNY = 49; constexpr int TRINKET_FLAT_PENNY = 51; constexpr int TRINKET_SUPER_MAGNET = 68; constexpr int TRINKET_BLESSED_PENNY = 131; +constexpr float VERSUS_CHEST_VOLUME = 0.7f; constexpr int TRINKET_APPLE_OF_SODOM = 140; constexpr int TRINKET_CHARGED_PENNY = 147; constexpr int TRINKET_NUH_UH = 165; @@ -1902,10 +1903,50 @@ bool Entity_Pickup::IsChest(int pickupVariant) // The rest of Entity_Pickup is not reconstructed yet. -// 006edda0 -bool Entity_Pickup::TakeDamage(float, uint64_t, const EntityRef&, int) +// 006edda0 An explosion or a crush hitting a pickup: it opens a stone chest (any chest with Broken Padlock, which in a +// versus match only counts for the hitting player), the mega chest losing a lock first, and a chest blown in a +// challenge room starts its ambush. A sticky nickel comes loose. A pickup never counts as damaged. +bool Entity_Pickup::TakeDamage(float damage, uint64_t damageFlags, const EntityRef& source, int) { - reconstruction_missing("Entity_Pickup::TakeDamage 006edda0"); + if (damage <= 0 || !(damageFlags & (DAMAGE_EXPLOSION | DAMAGE_CRUSH))) return false; + + bool isPadlocked = g_game->playerManager.AnyoneHasTrinket(TRINKET_BROKEN_PADLOCK); + if (g_game->deathmatchManager.is_active()) + { + Entity* ancestor = source.entity ? source.entity->GetPlayerAncestor() : nullptr; + isPadlocked = ancestor && ancestor->ToPlayer()->HasTrinket(TRINKET_BROKEN_PADLOCK); + } + bool isBlownOpen = variant == PICKUP_BOMBCHEST || + (isPadlocked && is_listed({PICKUP_LOCKEDCHEST, PICKUP_CHEST, PICKUP_REDCHEST, PICKUP_ETERNALCHEST, + PICKUP_SPIKEDCHEST, PICKUP_MIMICCHEST, PICKUP_OLDCHEST, PICKUP_MEGACHEST}, + variant)); + if (isBlownOpen && subtype != 0) + { + Entity* spawner = source.entity ? source.entity->GetLastSpawner() : nullptr; + Entity_Player* player = spawner && spawner->is_player() ? spawner->ToPlayer() : nullptr; + if (variant == PICKUP_MEGACHEST && subtype > 1) + { + subtype--; + return false; + } + if (TryOpenChest(player) && g_game->deathmatchManager.is_active()) + { + g_game->Spawn({.position = pos, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); + int sound = SOUND_SUMMONSOUND; + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound, {.volume = VERSUS_CHEST_VOLUME}); + Remove(); + } + int roomType = g_game->room->roomType; + if (roomType == ROOM_CHALLENGE || roomType == ROOM_BOSSRUSH) g_game->ambush.StartChallenge(); + } + else if (variant == PICKUP_COIN && subtype == COIN_STICKYNICKEL) + { + subtype = COIN_NICKEL; + collisionCooldown = 0; + sprite.Play("Idle"); + } + return false; } // 005832c0 @@ -1914,12 +1955,6 @@ void Entity_Pickup::GetLootList(const Vector&) reconstruction_missing("Entity_Pickup::GetLootList 005832c0"); } -// 006e1640 -bool Entity_Pickup::TryFlip(Entity_Player*, uint32_t) -{ - reconstruction_missing("Entity_Pickup::TryFlip 006e1640"); -} - // 006e1e60 void Entity_Pickup::SetForceBlind(uint8_t) { diff --git a/src/entity_pickup.h b/src/entity_pickup.h index 8d23d4e..78d4b79 100644 --- a/src/entity_pickup.h +++ b/src/entity_pickup.h @@ -232,6 +232,7 @@ private: void pedestal_start(); void pedestal_update(); void pedestal_render(const Vector& offset); + void flip_item_load(bool isShown); bool is_collectible_refused(Entity_Player& player); bool collectible_collect(Entity_Player& player); void collectible_sound_play(); diff --git a/src/entity_pickup_chest.cpp b/src/entity_pickup_chest.cpp index 785e62c..a898224 100644 --- a/src/entity_pickup_chest.cpp +++ b/src/entity_pickup_chest.cpp @@ -717,9 +717,7 @@ static bool red_chest_entry_spawn(Entity_Pickup& chest, const LootEntry& entry, if (entry.type != ENTITY_FAMILIAR) return false; if (entry.variant == FAMILIAR_BLUE_FLY) player.AddBlueFlies(1, chest.pos, nullptr); - else if (entry.variant == FAMILIAR_BLUE_SPIDER) - reconstruction_missing( - "Entity_Pickup::TryOpenChest 006e6e40: a red chest's blue spiders (spawn_blue_spider 00638e30)"); + else if (entry.variant == FAMILIAR_BLUE_SPIDER) player.ThrowBlueSpider(chest.pos, {}); return true; } diff --git a/src/entity_pickup_morph.cpp b/src/entity_pickup_morph.cpp index f4c493b..caca21d 100644 --- a/src/entity_pickup_morph.cpp +++ b/src/entity_pickup_morph.cpp @@ -32,7 +32,7 @@ struct MorphKept // 006e30a0 Turns a pickup into another in place (Lua's EntityPickup:Morph): a new seed unless kept, its place, links, // index, flags and timers kept, its price kept or dropped, an active's initial charge, and its pedestal. Entities // pointing at it forget it. The deathmatch's swaps, a devil deal keeping its sacrifice item, a priced shop item's -// reroll, a Mega Chest's halves and Flip's other item are not written yet. +// reroll and a Mega Chest's halves are not written yet. Flip's other item stays while the pickup keeps its kind. void Entity_Pickup::Morph(int entityType, int entityVariant, int entitySubType, bool isKeepPrice, bool isKeepSeed, bool isIgnoreModifiers) { @@ -43,8 +43,9 @@ void Entity_Pickup::Morph(int entityType, int entityVariant, int entitySubType, } if (g_game->deathmatchManager.is_active()) reconstruction_missing("Entity_Pickup::Morph 006e30a0 (the deathmatch's blacklist)"); - if (megaChestCollectible[0] || megaChestCollectible[1] || flipSaveState) - reconstruction_missing("Entity_Pickup::Morph 006e30a0 (a Mega Chest's halves or Flip's other item)"); + if (megaChestCollectible[0] || megaChestCollectible[1]) + reconstruction_missing("Entity_Pickup::Morph 006e30a0 (a Mega Chest's halves)"); + std::shared_ptr flipOther = flipSaveState; MorphKept saved = {.child = child, .parent = parent, @@ -110,4 +111,5 @@ void Entity_Pickup::Morph(int entityType, int entityVariant, int entitySubType, if (variant == PICKUP_COLLECTIBLE && subtype != 0 && isBlindChanged) UpdateSprite(false); for (EntityPtr* referrer : referrers) referrer->forget(); referrers.clear(); + if (flipOther && flipOther->type == type && flipOther->variant == variant) flipSaveState = flipOther; } diff --git a/src/entity_player.cpp b/src/entity_player.cpp index 22d0efc..10c09ad 100644 --- a/src/entity_player.cpp +++ b/src/entity_player.cpp @@ -2,6 +2,7 @@ #include "data.h" #include "entity_effect.h" #include "entity_familiar.h" +#include "entity_laser.h" #include "entity_npc.h" #include "entity_slot.h" #include "game.h" @@ -72,6 +73,8 @@ constexpr int PICKUP_HEART = 10; constexpr float PICKUP_SPAWN_RADIUS = 40; constexpr int POCKET_ACTIVE_SLOT = 2; constexpr float RANDOM_FLOAT_SCALE = 2.3283064e-10f; +// A removed player lets go of what it holds at a tenth of its speed. +constexpr float HELD_RELEASE_SPEED = 0.1f; constexpr int RED_REDEMPTION_KEY_CHARGES = 20; constexpr uint8_t WOODEN_CROSS_STACK = 0x10; constexpr std::string_view COSTUMES_DIR = "costumes"; @@ -528,6 +531,8 @@ void Entity_Player::links_reset() suplexTargetPos = {}; suplexLandPos = {}; bagOfCraftingContent.fill(0); + bagOfCraftingOutput = 0; + bagOfCraftingPool = -1; bagOfCraftingHoldFrames = 0; poopSpellQueue.fill(0); poopMana = 0; @@ -1415,6 +1420,63 @@ void Entity_Player::ClearReferences() release_weapons_and_effects(false); } +// Forgets an entity the player spawned, removing it first when asked. +template static void link_release(Link& link, bool isRemoveEntities) +{ + if (isRemoveEntities && link) static_cast(link)->Remove(); + link = nullptr; +} + +// 00757ac0 Lets go of the weapons, then of the effects the player spawned (removed when asked), the held entity (thrown +// on removal) and, unless it is being replaced, its stored helper players and its twin, removing its co-op players. +void Entity_Player::release_weapons_and_effects(bool isRemoveEntities) +{ + for (size_t slot = 1; slot <= weapons.size(); slot++) + { + WeaponPtr& weapon = weapons[slot % weapons.size()]; + if (weapon) weapon->ClearReferences(); + weapon.reset(); + } + link_release(azazelsRageLaser, isRemoveEntities); + link_release(breathOfLifeEffect, isRemoveEntities); + link_release(megaBlastLaser, isRemoveEntities); + link_release(markedTarget, isRemoveEntities); + link_release(forgottenBody, isRemoveEntities); + link_release(babyFamiliar, isRemoveEntities); + link_release(salvationEffect, isRemoveEntities); + link_release(tetheredEffect, isRemoveEntities); + link_release(astralProjectionBody, isRemoveEntities); + link_release(montezumaLaser, isRemoveEntities); + link_release(darkArtsLastSnare, isRemoveEntities); + link_release(darkEsau, isRemoveEntities); + moveToTarget = {}; + if (isRemoveEntities) ThrowHeldEntity(vector_make(velocity.x * HELD_RELEASE_SPEED, velocity.y * HELD_RELEASE_SPEED)); + heldEntity = nullptr; + if (replacedPlayer) return; + + for (Entity_Player** helper : {&subPlayer, &backupPlayer}) + { + if (!*helper || (*helper)->isValid || (helper == &subPlayer && !isValid)) continue; + (*helper)->ClearReferences(); + delete std::exchange(*helper, nullptr); + } + PlayerManager& players = g_game->playerManager; + Entity_Player* twin = twin_get(); + if (isRemoveEntities && twin && (twin->playerIndex == -1 || playerIndex <= twin->playerIndex || twin == this)) + players.RemoveCoPlayer(twin); + twinPlayer = nullptr; + if (!isRemoveEntities) return; + + for (size_t i = 0; i < players.playerList.size(); i++) + { + Entity_Player* each = players.playerList[i]; + Entity* owner = each->parent && each->parent->type == ENTITY_PLAYER ? (Entity*)each->parent + : each->variant == PLAYER_VARIANT_COOP_BABY ? players.playerList[0] + : nullptr; + if (owner == this && each->parent) players.RemoveCoPlayer(each); + } +} + // 0065cf60 Whether the player is a co-op baby still blinking in after joining. bool Entity_Player::IsP2Appearing() { diff --git a/src/entity_player.h b/src/entity_player.h index 1f397da..869c6b1 100644 --- a/src/entity_player.h +++ b/src/entity_player.h @@ -218,6 +218,7 @@ enum PlayerItemId : int COLLECTIBLE_MOMS_EYE = 55, COLLECTIBLE_BOOK_OF_SHADOWS = 58, COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE = 59, + COLLECTIBLE_CHARM_VAMPIRE = 62, COLLECTIBLE_BATTERY = 63, COLLECTIBLE_STEAM_SALE = 64, COLLECTIBLE_HOURGLASS = 66, @@ -314,6 +315,8 @@ enum PlayerItemId : int COLLECTIBLE_WOODEN_NICKEL = 349, COLLECTIBLE_TOXIC_SHOCK = 350, COLLECTIBLE_GLASS_CANNON = 352, + COLLECTIBLE_CAR_BATTERY = 356, + COLLECTIBLE_THE_WIZ = 358, COLLECTIBLE_INCUBUS = 360, COLLECTIBLE_SWORN_PROTECTOR = 363, COLLECTIBLE_EPIPHORA = 368, @@ -349,6 +352,7 @@ enum PlayerItemId : int COLLECTIBLE_BELLY_BUTTON = 458, COLLECTIBLE_GLAUCOMA = 460, COLLECTIBLE_GLYPH_OF_BALANCE = 464, + COLLECTIBLE_ANALOG_STICK = 465, COLLECTIBLE_BROKEN_GLASS_CANNON = 474, COLLECTIBLE_SMELTER = 479, COLLECTIBLE_DATAMINER = 481, @@ -566,7 +570,11 @@ enum PlayerItemId : int PILLEFFECT_HEALTH_UP = 7, PILLEFFECT_TELEPILLS = 19, PILLEFFECT_LARGER = 32, - PILLEFFECT_SMALLER = 33 + PILLEFFECT_SMALLER = 33, + COLLECTIBLE_BROTHER_BOBBY = 8, + COLLECTIBLE_ABYSS = 706, + COLLECTIBLE_LEMEGETON = 712, + COLLECTIBLE_ANIMA_SOLA = 722 }; // The unlocks the player's code checks or grants (Lua's Achievement). @@ -925,6 +933,8 @@ public: std::array poopSpellQueue{}; QueueItemData queuedItem; int bagOfCraftingHoldFrames = 0; + int bagOfCraftingOutput = 0; + int bagOfCraftingPool = -1; int extensionCordIndex = -1; int itemHoldCooldown = 0; int itemState = 0; @@ -961,7 +971,6 @@ public: int playerIndex = -1; int shootHeldFrames = 0; int slipperyTimer = 0; - int tractorBeam = 0; Direction fireDirection = DIRECTION_NONE; Direction headDirection = DIRECTION_DOWN; Direction moveDirection = DIRECTION_NONE; @@ -984,6 +993,7 @@ public: bool isHurtPending = false; bool isHurtThisRoom = false; + std::shared_ptr unlistedRestoreState; std::shared_ptr playerHUD; std::vector contactHitList; std::vector darkArtsHitList; @@ -997,6 +1007,7 @@ public: EntityPtr darkEsau; EntityPtr salvationEffect; EntityPtr tetheredEffect; + EntityPtr tractorBeam; EntityPtr twinPlayer; Entity_Player* backupPlayer = nullptr; Entity_Player* replacedPlayer = nullptr; @@ -1004,7 +1015,7 @@ public: Entity* darkArtsLastSnare = nullptr; Entity* heldEntity = nullptr; Entity* montezumaLaser = nullptr; - Entity_Effect* markedTarget = nullptr; + EntityPtr markedTarget; Entity_Familiar* forgottenBody = nullptr; Entity_Laser* megaBlastLaser = nullptr; Vector forgottenBodyPos{}; @@ -1547,7 +1558,8 @@ public: void SetPocketActiveItem(int collectible, int slot, bool keepInPools); void get_salvation_scale(); void update_suplex(); - uint32_t bag_of_crafting_collect(Entity_Pickup* pickup); + bool bag_of_crafting_collect(Entity_Pickup* pickup); + void tainted_cain_pedestal_burst(Vector position, uint32_t seed, int poolType); static int GetMaxPoopMana(); void AddPoopMana(int amount); void poop_spell_roll(); @@ -1565,7 +1577,7 @@ public: void RevivePlayerGhost(); void MorphToCoopGhost(); void reset_body_sprite(); - static uint32_t* CalculateBagOfCraftingOutput(uint32_t* output, const char* bagContent, bool isUnused); + static CraftingRecipe CalculateBagOfCraftingOutput(const std::array& bag); void SpawnClot(Vector pos, bool isUnknown); bool TryForgottenThrow(Vector dir); void ResetPlayer(); diff --git a/src/entity_player_actives.cpp b/src/entity_player_actives.cpp index 45f3b94..eae43af 100644 --- a/src/entity_player_actives.cpp +++ b/src/entity_player_actives.cpp @@ -1,5 +1,6 @@ #include "entity_player.h" #include "entity_player_characters.h" +#include "entity_player_crafting.h" #include "console.h" #include "entity_familiar.h" #include "npc_ai.h" @@ -22,6 +23,7 @@ #include "npc_basement.h" #include "room.h" #include "room_special.h" +#include "tainted_characters.h" #include #include #include @@ -46,7 +48,6 @@ enum ActiveItemId : int COLLECTIBLE_D100 = 283, COLLECTIBLE_D4 = 284, COLLECTIBLE_MAGIC_FINGERS = 295, - COLLECTIBLE_CAR_BATTERY = 356, COLLECTIBLE_D12 = 386, COLLECTIBLE_D8 = 406, COLLECTIBLE_MINE_CRAFTER = 427, @@ -55,7 +56,6 @@ enum ActiveItemId : int COLLECTIBLE_HALLOWED_GROUND = 543, COLLECTIBLE_SHARP_KEY = 623, COLLECTIBLE_STITCHES = 635, - COLLECTIBLE_ANIMA_SOLA = 722, TRINKET_BROKEN_REMOTE = 4, TRINKET_M = 138, @@ -220,20 +220,6 @@ struct ActiveRelease constexpr ActiveRelease ACTIVE_RELEASES[] = { {346, "Rebirth"}, {441, "Afterbirth"}, {552, "Afterbirth+"}, {COLLECTIBLE_VANILLA_COUNT - 1, "Repentance"}}; -// One active item use as its effect runs: the request, the item, and what the effect leaves for the end of the use. -struct ItemUse -{ - Entity_Player& player; - const ActiveUse& request; - ItemConfig_Item* item = nullptr; - UseResult result{}; - int id = 0; - bool isAddEffect = true; - bool isLuaAnimationAllowed = false; - bool isShowAnimation = false; - bool isWispAllowed = false; -}; - // Plays a sound at the player's volume, unless the seeds swap it for a fart. static void sound_play_local(Entity_Player& player, int sound) { @@ -698,8 +684,13 @@ void Entity_Player::DischargeActiveItem(uint32_t slot, bool isRemoved) isActiveUsed = false; if (active.item == COLLECTIBLE_ESAU_JR) reconstruction_missing("Entity_Player::DischargeActiveItem 007ac7e0 (Esau Jr.'s swap)"); - if (active.item == COLLECTIBLE_FLIP && slot == ACTIVE_SLOT_POCKET && (twinPlayer || backupPlayer)) - reconstruction_missing("Entity_Player::DischargeActiveItem 007ac7e0 (Flip's item for the other Lazarus)"); + Entity_Player* otherLazarus = twin_get() ? twin_get() : backupPlayer; + if (active.item == COLLECTIBLE_FLIP && slot == ACTIVE_SLOT_POCKET && otherLazarus) + { + otherLazarus->activeItems[ACTIVE_SLOT_POCKET] = active; + active_used_post(slot, isRemoved, chargeBefore); + return; + } active_used_post(slot, isRemoved, chargeBefore); if (slot == ACTIVE_SLOT_POCKET2) SetPocketActiveItem(0, ACTIVE_SLOT_POCKET2, false); @@ -801,13 +792,6 @@ static void book_of_belial_use(ItemUse& use) use_animate(use); } -// Whether a grid entity covers the floor in a way a poop must not hide: a trapdoor, stairs, a pressure plate or a -// teleporter, as the original's is_grid_type_floor_special tells. -static bool is_grid_floor_special(GridEntityType type) -{ - return type == GRID_TRAPDOOR || type == GRID_STAIRS || type == GRID_PRESSURE_PLATE || type == GRID_TELEPORTER; -} - // The Poop: a poop where the player stands, white with Hallowed Ground, black from Meconium, golden from Midas' Touch, // and a fart. The candles of Bird's Eye and Ghost Pepper fire too. static void poop_use(ItemUse& use) @@ -1305,6 +1289,20 @@ static void item_effect_run(ItemUse& use) return metronome_use(use); case COLLECTIBLE_DELIRIOUS: return delirious_use(use); + case COLLECTIBLE_ABYSS: + return abyss_use(use); + case COLLECTIBLE_FLIP: + return flip_use(use); + case COLLECTIBLE_LEMEGETON: + return lemegeton_use(use); + case COLLECTIBLE_ANIMA_SOLA: + return anima_sola_use(use); + case COLLECTIBLE_BAG_OF_CRAFTING: + { + const char* animation = bag_of_crafting_use(use.player, use.request.slot); + if (animation && use.isShowAnimation) use.player.AnimateCollectible(use.id, animation, "PlayerPickupSparkle"); + return; + } } if (std::ranges::find(CASED_ACTIVES, use.id) == std::end(CASED_ACTIVES)) return; @@ -1514,9 +1512,10 @@ static void active_trigger(Entity_Player& player, int slot) player.temporaryEffects.RemoveCollectibleEffect(COLLECTIBLE_NOTCHED_AXE, -1); player.AnimateCollectible(COLLECTIBLE_NOTCHED_AXE, "HideItem", "PlayerPickupSparkle"); } - else if (item == COLLECTIBLE_ANIMA_SOLA || item == COLLECTIBLE_DECAP_ATTACK) - reconstruction_missing("Entity_Player::ControlActiveItem 00791a40 (Anima Sola's and Decap Attack's recall)"); - else if (item != 0) active_slot_use(player, slot, itemStateBefore); + else if (item == COLLECTIBLE_DECAP_ATTACK) + reconstruction_missing("Entity_Player::ControlActiveItem 00791a40 (Decap Attack's recall)"); + else if (item != 0 && !(item == COLLECTIBLE_ANIMA_SOLA && anima_chain_recall(player))) + active_slot_use(player, slot, itemStateBefore); if (player.itemState == 0 || player.itemState != itemStateBefore || player.itemStateCooldown >= 1) return; int costumeItem = player.itemState == SHOOP_DA_WHOOP ? SHOOP_DA_WHOOP : player.activeItems[slot].item; @@ -1557,9 +1556,9 @@ void Entity_Player::ControlActiveItem(int slot) reconstruction_missing("Entity_Player::ControlActiveItem 00791a40 (Breath of Life and Spin to Win held down)"); if (item == COLLECTIBLE_BAG_OF_CRAFTING && slot == ACTIVE_SLOT_POCKET && !isInterpolating) { - if (itemState == COLLECTIBLE_BAG_OF_CRAFTING && AreControlsEnabled() && isPressed) - reconstruction_missing("Entity_Player::ControlActiveItem 00791a40 (crafting with the Bag of Crafting)"); - bagOfCraftingHoldFrames = 0; + if (itemState == COLLECTIBLE_BAG_OF_CRAFTING && AreControlsEnabled() && isPressed && bagOfCraftingOutput != 0) + bag_of_crafting_craft(*this); + else bagOfCraftingHoldFrames = 0; } if (slot == ACTIVE_SLOT_PRIMARY && !isInterpolating) timed_items_recharge(*this); @@ -1568,9 +1567,10 @@ void Entity_Player::ControlActiveItem(int slot) } // The temporary effects the plain frame, stats and tears are written for: the first floor's actives that leave one, -// Whore of Babylon and Tainted Eve's, Dead Bird, Bloody Lust and Bloody Gust, Lazarus' boost, and Metronome's and -// Delirious' marks (the item Metronome lends counts as owned, so its own checks still apply). Book of Belial and -// Razor Blade change the damage and tears, which are not written for effects yet. +// Whore of Babylon and Tainted Eve's, Dead Bird, Bloody Lust and Bloody Gust, Lazarus' boost, Jacob's curse, +// Metronome's and Delirious' marks (the item Metronome lends counts as owned, so its own checks still apply), and the +// marks of the Bag of Crafting, Abyss, Flip, Lemegeton and Anima Sola. Book of Belial and Razor Blade change the +// damage and tears, which are not written for effects yet. bool is_temporary_effect_plain(const TemporaryEffect& effect) { constexpr int PLAIN_EFFECT_ITEMS[] = {COLLECTIBLE_BIBLE, @@ -1591,10 +1591,16 @@ bool is_temporary_effect_plain(const TemporaryEffect& effect) COLLECTIBLE_BLOODY_LUST, COLLECTIBLE_BLOODY_GUST, COLLECTIBLE_METRONOME, - COLLECTIBLE_DELIRIOUS}; + COLLECTIBLE_DELIRIOUS, + COLLECTIBLE_BAG_OF_CRAFTING, + COLLECTIBLE_ABYSS, + COLLECTIBLE_FLIP, + COLLECTIBLE_LEMEGETON, + COLLECTIBLE_ANIMA_SOLA}; if (effect.item->type == ITEM_NULL) - return effect.item->id == NULLITEM_LAZARUS_BOOST || effect.item->id == NULLITEM_BLOODY_BABYLON; + return effect.item->id == NULLITEM_LAZARUS_BOOST || effect.item->id == NULLITEM_BLOODY_BABYLON || + effect.item->id == NULLITEM_JACOBS_CURSE; return effect.item->IsCollectible() && std::ranges::find(PLAIN_EFFECT_ITEMS, effect.item->id) != std::end(PLAIN_EFFECT_ITEMS); } diff --git a/src/entity_player_bombs.cpp b/src/entity_player_bombs.cpp index 818e5aa..42521a2 100644 --- a/src/entity_player_bombs.cpp +++ b/src/entity_player_bombs.cpp @@ -1,6 +1,7 @@ #include "entity_player.h" #include "active_items.h" #include "entity_bomb.h" +#include "entity_laser.h" #include "entity_tear.h" #include "game.h" #include "log.h" @@ -47,6 +48,34 @@ constexpr int CONSUMABLE_GIGA_BOMBS = 1 << 6; constexpr int SOUND_GLITTER_FUSE = 867; constexpr int PLACE_SOUND_DELAY = 4; +// Dr. Fetus' bombs: their fuse (longer with Tiny Planet, shorter with Short Fuse, a rocket's after its flight), the +// throw Tiny Planet and Cricket's Body speed up, their size and damage by the tear's, and Tech X's ring around them. +constexpr int FETUS_FUSE = 30; +constexpr int FETUS_FUSE_TINY_PLANET = 40; +constexpr int FETUS_FUSE_SHORT = 15; +constexpr int FETUS_ROCKET_FLIGHT = 60; +constexpr float FETUS_TINY_PLANET_SPEED = 2.4f; +constexpr float FETUS_TINY_PLANET_SPREAD = 0.2f; +constexpr float FETUS_CRICKETS_BODY_SPEED = 1.2f; +constexpr float FETUS_TEAR_HEIGHT = 23.75f; +constexpr float FETUS_SMALL_TEAR = 0.55f; +constexpr float FETUS_MEDIUM_TEAR = 0.75f; +constexpr float FETUS_LARGE_TEAR = 2; +constexpr float FETUS_SMALL_SCALE = 0.45f; +constexpr float FETUS_SMALL_RADIUS = 0.65f; +constexpr float FETUS_MEDIUM_SCALE = 0.6f; +constexpr float FETUS_MEDIUM_RADIUS = 0.8f; +constexpr float FETUS_LARGE_SCALE = 1.2f; +constexpr float FETUS_DAMAGE_SCALE = 10; +constexpr float FETUS_DAMAGE_SLOPE = 5; +constexpr float FETUS_DAMAGE_BASE = 30; +constexpr float FETUS_BIG_SCALE = 1.5f; +constexpr float FETUS_BIG_DAMAGE = 25; +constexpr float FETUS_PIERCING_DAMAGE = 2.5f; +constexpr float FETUS_RING_LIFT = -5; +constexpr float FETUS_RING_DEPTH = 3000; +constexpr float FETUS_RING_RADIUS = 50; + // A bomb item's tear effect: always, or by a chance out of 100 that luck raises, when the chances are rolled. struct BombItem { @@ -223,3 +252,79 @@ void Entity_Player::update_bomb_input() bomb.Update(); } } + +// 007a0970 Throws a Dr. Fetus bomb from a spot past the player's tear offset (a rocket with Rocket in a Jar), at the +// velocity scaled by the tear height (and Tiny Planet or Cricket's Body): its fuse, size and damage come from the +// player's bomb tear (Lua's FireBomb). The bomb carries the tear's flags and color, and Tech X circles it with a ring. +Entity_Bomb* Entity_Player::FireBomb(Vector position, Vector throwVelocity, Entity* source) +{ + Vector spawnPosition = vector_add(position, tearsOffset); + int fuse = FETUS_FUSE; + if (HasCollectible(COLLECTIBLE_TINY_PLANET)) + { + fuse = FETUS_FUSE_TINY_PLANET; + throwVelocity = vector_scale(throwVelocity, random_unit() * FETUS_TINY_PLANET_SPREAD + FETUS_TINY_PLANET_SPEED); + } + if (HasCollectible(COLLECTIBLE_CRICKETS_BODY)) throwVelocity = vector_scale(throwVelocity, FETUS_CRICKETS_BODY_SPEED); + + TearParams params = GetTearHitParams(WEAPON_BOMBS, 1, tearDisplacement, source); + float scale = check_bomb_tearflags(params.tearFlags); + float radiusMultiplier = 1; + if (params.tearScale <= FETUS_SMALL_TEAR) + { + scale *= FETUS_SMALL_SCALE; + radiusMultiplier = FETUS_SMALL_RADIUS; + } + else if (params.tearScale <= FETUS_MEDIUM_TEAR) + { + scale *= FETUS_MEDIUM_SCALE; + radiusMultiplier = FETUS_MEDIUM_RADIUS; + } + else if (params.tearScale > FETUS_LARGE_TEAR) scale *= FETUS_LARGE_SCALE; + float damage = std::min(params.tearDamage * FETUS_DAMAGE_SCALE, params.tearDamage * FETUS_DAMAGE_SLOPE + FETUS_DAMAGE_BASE); + if (scale >= FETUS_BIG_SCALE) damage += FETUS_BIG_DAMAGE; + + int variant = HasCollectible(COLLECTIBLE_ROCKET_IN_A_JAR) ? BOMB_ROCKET : BOMB_NORMAL; + Vector velocity = vector_scale(throwVelocity, -tearHeight / FETUS_TEAR_HEIGHT); + Entity* spawned = g_game->Spawn({.position = spawnPosition, .velocity = velocity, .spawner = this, + .type = ENTITY_BOMB, .variant = variant, .seed = Random()}); + Entity_Bomb& bomb = *static_cast(spawned); + bomb.AddEntityFlags(FLAG_NO_KNOCKBACK); + bomb.entityGridCollisionClass = GRIDCOLL_NOPITS; + + // The original also counts a Short Fuse the online item queue is adding or taking away, which offline is none. + if (GetTrinketMultiplier(TRINKET_SHORT_FUSE) > 0) fuse -= FETUS_FUSE_SHORT; + bomb.tearFlags = params.tearFlags; + bomb.isLoadCostumes = true; + bomb.SetExplosionCountdown(fuse); + bomb.scale = scale; + bomb.explosionDamage = damage; + bomb.radiusMultiplier = radiusMultiplier; + bomb.isFetus = true; + bomb.SetColor(params.tearColor, -1, COLOR_PRIORITY_DEFAULT, false, true); + bomb.parent = this; + if (bomb.tearFlags[TEAR_PIERCING]) bomb.SetCollisionDamage(params.tearDamage * FETUS_PIERCING_DAMAGE); + if (bomb.IsRocket()) + { + bomb.rocketAngle = vector_angle(throwVelocity); + bomb.SetExplosionCountdown(fuse + FETUS_ROCKET_FLIGHT); + } + + if (HasCollectible(COLLECTIBLE_TECH_X)) + { + int ringVariant = HasCollectible(COLLECTIBLE_BRIMSTONE) ? LASER_THICK_RED : LASER_THIN_RED; + Entity* ring = g_game->Spawn({.position = spawnPosition, .spawner = this, .subType = LASER_SUBTYPE_RING_FOLLOW_PARENT, + .type = ENTITY_LASER, .variant = ringVariant, .seed = Random()}); + Entity_Laser& laser = *static_cast(ring); + laser.posOffset = vector_make(0, FETUS_RING_LIFT); + laser.parent = &bomb; + laser.renderDepthOffset = FETUS_RING_DEPTH; + laser.tearFlags = tearFlags; + laser.SetColor(laserColor, -1, COLOR_PRIORITY_DEFAULT, false, true); + laser.SetCollisionDamage(this->damage); + laser.radius = FETUS_RING_RADIUS; + laser.spawnerEntity = this; + } + if (bomb.IsRocket()) bomb.Update(); + return &bomb; +} diff --git a/src/entity_player_characters.cpp b/src/entity_player_characters.cpp index bf1cb48..8af5943 100644 --- a/src/entity_player_characters.cpp +++ b/src/entity_player_characters.cpp @@ -1,6 +1,8 @@ #include "entity_player_characters.h" +#include "boss_ai.h" #include "entity_effect.h" #include "entity_familiar.h" +#include "entity_knife.h" #include "entity_player_tainted.h" #include "game.h" #include "hud.h" @@ -29,6 +31,23 @@ constexpr int DEATHMATCH_WHORE_RED_HEARTS = 16; constexpr int NULLITEM_SLOW_A = 62; constexpr int NULLITEM_SLOW_B = 65; constexpr float AZAZELS_STUMP_DAMAGE_SCALE = 1.5f; +constexpr int MAGGY_HEART_LIMIT = 4; +constexpr int MAGGY_BIRTHRIGHT_HEART_LIMIT = 6; +constexpr int MAGGY_DRAIN_FRAMES = 300; +constexpr int MAGGY_DRIP_ODDS = 5; +constexpr float MAGGY_DRIP_SCALE_SPREAD = 0.5f; +constexpr float MAGGY_DRIP_SCALE_BASE = 0.2f; +constexpr int MAGGY_HUG_READY = 3; +constexpr int MAGGY_HUG_FRAMES = 9; +constexpr int MAGGY_HUG_SUBTYPE = 4; +constexpr float MAGGY_HUG_REACH = 6; +constexpr float MAGGY_HUG_RISE = -14; +constexpr int COLOR_PRIORITY_HUG = 255; +constexpr int BERSERK_CHARGE_MAX = 99999; +constexpr float BERSERK_CHARGE_PER_DAMAGE = 50000; +constexpr float DEATHMATCH_DAMAGE_CHARGE_SCALE = 0.1f; +constexpr float DAMAGE_CHARGE_PER_STAGE = 20; +constexpr float DAMAGE_CHARGE_BASE = 40; constexpr float TWIN_SPEED_MAX = 2; constexpr float TWIN_SPEED_MIN = 0.1f; constexpr float TWIN_SPAWN_OFFSET = 20; @@ -88,16 +107,22 @@ bool is_azazel(Entity_Player& player) // Whether the frame and the stat evaluation are reconstructed for the player's character: the normal ones and the // tainted ones the frame (00782af0, 00794e50) has no branch for. Tainted Judas's and Tainted Keeper's Birthright have -// one. +// one, and so has Tainted Lazarus's, which keeps both forms in the room. bool is_character_reconstructed(Entity_Player& player) { switch (player.playerType) { case PLAYER_JUDAS_B: case PLAYER_KEEPER_B: + case PLAYER_LAZARUS_B: + case PLAYER_LAZARUS2_B: return !player.HasCollectible(COLLECTIBLE_BIRTHRIGHT); + case PLAYER_JACOB_B: + case PLAYER_JACOB2_B: case PLAYER_ISAAC_B: + case PLAYER_MAGDALENE_B: case PLAYER_CAIN_B: + case PLAYER_SAMSON_B: case PLAYER_EVE_B: case PLAYER_AZAZEL_B: case PLAYER_EDEN_B: @@ -1022,3 +1047,142 @@ void character_items_hit(Entity_Player& player) if (isGust) effects.AddCollectibleEffect(COLLECTIBLE_BLOODY_GUST, true, 1); player.bloodLustCounter++; } + +// 007d4320 The red hearts Tainted Magdalene keeps for good: two hearts, three with Birthright. +int maggy_heart_limit(Entity_Player& player) +{ + return player.HasCollectible(COLLECTIBLE_BIRTHRIGHT) ? MAGGY_BIRTHRIGHT_HEART_LIMIT : MAGGY_HEART_LIMIT; +} + +// Whether Tainted Magdalene holds health that drains: red hearts above her lasting ones, or soul hearts beyond the +// last half heart. +bool is_maggy_draining(Entity_Player& player) +{ + return player.redHearts > maggy_heart_limit(player) || player.soulHearts > 1 || + (player.soulHearts == 1 && player.redHearts + player.boneHearts > 0); +} + +// Tainted Magdalene's drain, part of 00782af0: health above her lasting hearts loses half a heart every 300 frames, +// red before soul. Anyone else's drain timer stays at 0. +static void maggy_health_drain(Entity_Player& player) +{ + if (player.playerType != PLAYER_MAGDALENE_B || !is_maggy_draining(player)) + { + player.maggyHealthDrainCooldown = 0; + return; + } + if (player.maggyHealthDrainCooldown == 0) + { + player.maggyHealthDrainCooldown = MAGGY_DRAIN_FRAMES; + return; + } + if (--player.maggyHealthDrainCooldown >= 1) return; + + if (player.redHearts > maggy_heart_limit(player)) player.AddHearts(-1, false, false); + else if (is_maggy_draining(player)) player.AddSoulHearts(-1, false); + player.maggyHealthDrainCooldown = MAGGY_DRAIN_FRAMES; +} + +// Tainted Magdalene's part of 00794e50: while her health drains, one frame in five drops a small spot of red creep. +static void maggy_blood_drip(Entity_Player& player) +{ + if (player.playerType != PLAYER_MAGDALENE_B || player.maggyHealthDrainCooldown <= 0 || + random_below(MAGGY_DRIP_ODDS) != 0) + return; + uint32_t seed = Random(); + Entity* drip = g_game->Spawn({.position = player.pos, .spawner = &player, .type = ENTITY_EFFECT, + .variant = EFFECT_PLAYER_CREEP_RED, .seed = seed}); + float scale = random_unit() * MAGGY_DRIP_SCALE_SPREAD + MAGGY_DRIP_SCALE_BASE; + drip->sprite.scale = vector_make(scale, scale); + drip->Update(); +} + +// 007d9200 Adds to Tainted Samson's berserk charge (held below full during a suplex). A full charge empties into +// Berserk!, roaring, which reopens the backwards path's stages. The color is reevaluated. +void Entity_Player::add_samson_berserk_charge(int amount) +{ + samsonBerserkCharge += amount; + if (suplexState != 0) samsonBerserkCharge = std::min(samsonBerserkCharge, BERSERK_CHARGE_MAX); + if (samsonBerserkCharge > BERSERK_CHARGE_MAX) + { + samsonBerserkCharge = 0; + if (ItemConfig_Item* berserk = g_manager->itemConfig.GetCollectible(COLLECTIBLE_BERSERK)) + temporaryEffects.AddEffect(TemporaryEffect(berserk), true, 1); + for (int sound : {SOUND_BERSERK_START, SOUND_ISAAC_ROAR}) + { + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound); + } + g_game->UpdateBackwardsPathStages(); + } + cacheFlags |= CACHE_COLOR; + temporaryEffects.isEvaluateCachePending = true; +} + +// 007d3560 How much charge a point of damage dealt is worth: a tenth in a versus match, else less the deeper the +// floor (the alternate floors count one deeper). +float damage_charge_scale() +{ + Game& game = *g_game; + if (game.deathmatchManager.is_active()) return DEATHMATCH_DAMAGE_CHARGE_SCALE; + bool isDeeper = game.stageType == STAGETYPE_REPENTANCE || game.stageType == STAGETYPE_REPENTANCE_B; + return 1 / ((float)(game.stage + (isDeeper ? 1 : 0)) * DAMAGE_CHARGE_PER_STAGE + DAMAGE_CHARGE_BASE); +} + +// The Berserk! charge part of 00794e50: out of Berserk!, the damage enemies took this frame charges Tainted Samson's +// berserk bar and any Berserk! held in an active slot. +static void berserk_charge_update(Entity_Player& player) +{ + bool isCharging = player.HasCollectible(COLLECTIBLE_BERSERK) || player.playerType == PLAYER_SAMSON_B; + if (!isCharging || player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_BERSERK)) return; + if (g_game->deathmatchManager.is_active()) + reconstruction_missing("Entity_Player::update_effects 00794e50 (the versus damage dealt)"); + float dealt = g_game->room->entityList.enemyDamageInflicted; + if (dealt <= 0) return; + + int charge = (int)(damage_charge_scale() * dealt * BERSERK_CHARGE_PER_DAMAGE); + if (player.playerType == PLAYER_SAMSON_B) player.add_samson_berserk_charge(charge); + for (int slot = 0; slot < ACTIVE_SLOT_COUNT && charge > 0; slot++) + if (player.activeItems[slot].item == COLLECTIBLE_BERSERK) + charge -= player.AddActiveCharge(charge, slot, false, false, true); +} + +// The characters' pieces of a whole frame the plain frame runs, with the items' frame (00794e50): Tainted Magdalene's +// drain and its drip, and the Berserk! charge. +void character_frame_update(Entity_Player& player) +{ + maggy_health_drain(player); + maggy_blood_drip(player); + berserk_charge_update(player); +} + +// Tainted Magdalene's hug, part of 0078e1f0: touching a vulnerable enemy that is not a friend, with the last swing +// nearly over, swings a bone club at it (along its main axis) with her melee damage doubled against her damage, the +// tear look of a bone swing, and a 9 frame cooldown. +void tainted_magdalene_hug(Entity_Player& player, Entity& collider) +{ + if (player.playerType != PLAYER_MAGDALENE_B || !collider.IsVulnerableEnemy(nullptr) || + player.maggySwingCooldown >= MAGGY_HUG_READY || collider.HasEntityFlags(FLAG_FRIENDLY)) + return; + + float damageScale = player.meleeDamage + player.meleeDamage; + int displacement = (int)(Random() & 1) * 2 - 1; + TearParams params = player.GetTearHitParams(WEAPON_BONE, damageScale / player.damage, displacement, nullptr); + uint32_t seed = Random(); + auto* club = static_cast(g_game->Spawn({.position = player.pos, .spawner = &player, + .subType = MAGGY_HUG_SUBTYPE, .type = ENTITY_KNIFE, + .variant = KNIFE_BONE_CLUB, .seed = seed})); + club->parent = &player; + club->targetPosition = vector_make(MAGGY_HUG_REACH, 0); + club->rotation = vector_angle(vector_cardinal(vector_sub(collider.pos, player.pos))); + club->posOffset = vector_make(0, MAGGY_HUG_RISE); + club->SetColor(params.tearColor, -1, COLOR_PRIORITY_HUG, false, true); + club->sprite.scale = player.sprite.scale; + club->tearFlags = params.tearFlags; + club->SetCollisionDamage(params.tearDamage); + // The club carries the entity flag the player's code reads as bleeding out (bit 34). + club->AddEntityFlags(FLAG_BLEED_OUT); + club->SetAttackAnimation(); + club->Update(); + player.maggySwingCooldown = MAGGY_HUG_FRAMES; +} diff --git a/src/entity_player_characters.h b/src/entity_player_characters.h index 8fe2f39..b6ae8cc 100644 --- a/src/entity_player_characters.h +++ b/src/entity_player_characters.h @@ -41,3 +41,14 @@ void revived_players_settle(std::vector& players, int oldType); // Eve's Dead Bird and Samson's Bloody Lust answering a hit (007729d0). void character_items_hit(Entity_Player& player); + +// Tainted Magdalene's lasting red hearts (007d4320) and whether health above them is draining away. +int maggy_heart_limit(Entity_Player& player); +bool is_maggy_draining(Entity_Player& player); + +// The characters' own parts of a whole frame (00782af0, 00794e50) and Tainted Magdalene's part of a touch (0078e1f0). +void character_frame_update(Entity_Player& player); +void tainted_magdalene_hug(Entity_Player& player, Entity& collider); + +// What a point of damage dealt adds to a damage charge (007d3560). +float damage_charge_scale(); diff --git a/src/entity_player_collectibles.cpp b/src/entity_player_collectibles.cpp index 2e4a090..91a6ee0 100644 --- a/src/entity_player_collectibles.cpp +++ b/src/entity_player_collectibles.cpp @@ -135,9 +135,13 @@ static void doubled_costume_remove(Entity_Player& player, int collectibleId) } // 00793970 An item's temporary effect ran out or was taken: a collectible's costume comes off unless the item keeps -// it, the doubled ones with it. The items whose end does more, and trinket and null item effects, are not written yet. +// it, the doubled ones with it, and a null effect's costume comes off. The items whose end does more, and trinket +// effects and the null effects whose end does more, are not written yet. void Entity_Player::trigger_collectible_effect_removed(ItemConfig_Item* item, int) { + constexpr int NULL_EFFECTS_WITH_ENDS[] = {50, 62, 63, 66, 67, 70, 71, 101}; + if (item->type == ITEM_NULL && std::ranges::find(NULL_EFFECTS_WITH_ENDS, item->id) == std::end(NULL_EFFECTS_WITH_ENDS)) + return RemoveCostume(g_manager->itemConfig.GetNullItem(item->id)); if (!item->IsCollectible()) reconstruction_missing("Entity_Player::trigger_collectible_effect_removed 00793970 (a trinket or null effect)"); doubled_costume_remove(*this, item->id); diff --git a/src/entity_player_costumes.cpp b/src/entity_player_costumes.cpp index 869c672..0853d48 100644 --- a/src/entity_player_costumes.cpp +++ b/src/entity_player_costumes.cpp @@ -3,6 +3,7 @@ #include "log.h" #include "manager.h" #include "room_render.h" +#include #include #include #include @@ -14,6 +15,13 @@ constexpr float HEAD_LIFT_PER_HEAD_SCALE = 2.5f; constexpr float HEAD_LIFT_PER_SQUASH = 8; constexpr std::string_view SUB_ANIM_PREFIX = "SubAnim"; +// Tainted Magdalene's squash and stretch over a hug's last frames (the exe's table at 00b6bc98), and how far it lifts +// her head. +constexpr float MAGGY_HUG_SQUASH[] = {1.2f, 1.05f, 0.9f, 0.98f, 1.05f, 1.025f, 1.0f}; +constexpr int MAGGY_HUG_SQUASH_FRAMES = 8; +constexpr int MAGGY_HUG_SQUASH_LAST = 6; +constexpr float MAGGY_HUG_LIFT = 4; + // How the player's layers draw this frame (the frame's tints and squashes): the head and body tints, the head's // offset and size from the body costume's HeadTransform null and the head costume's frame, and the squashes the // effects add. @@ -63,13 +71,22 @@ static void layer_look_read(Entity_Player& player, LayerLook& look) bool isEffectLook = isAdrenaline || isGolden || player.HasCollectible(COLLECTIBLE_MARS) || player.bladderCharge > 0 || player.ibsChargeBar > 0 || player.flashCountdown > 0 || effects.GetCollectibleEffectNum(COLLECTIBLE_AZAZELS_RAGE) == 4 || - player.maggySwingCooldown > 0 || player.jellyBellyBounceTimer > 0 || + player.jellyBellyBounceTimer > 0 || (chariot && chariot->cooldown < REVERSE_CHARIOT_FLASH_FRAMES) || player.reverseChariotMoveCooldown > 1 || effects.HasCollectibleEffect(COLLECTIBLE_BERSERK) || g_game->challenge == CHALLENGE_HOT_POTATO || !player.IsLocalPlayer(); if (isEffectLook) reconstruction_missing("Entity_Player::Update 00782af0 (the effects that tint or squash the player)"); + if (player.maggySwingCooldown > 0) + { + if (!player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE)) player.maggySwingCooldown--; + int step = std::clamp(MAGGY_HUG_SQUASH_FRAMES - player.maggySwingCooldown, 0, MAGGY_HUG_SQUASH_LAST); + float squash = MAGGY_HUG_SQUASH[step]; + look.headSquash = vector_make(look.headSquash.x * (2 - squash), look.headSquash.y * squash); + look.bodySquash = vector_make(look.bodySquash.x * (2 - squash), look.bodySquash.y * squash); + look.headLift += (squash - 1) * MAGGY_HUG_LIFT; + } PlayerCostumeMap& body = player.playerCostumeMap[PLAYER_LAYER_BODY]; if (body.index >= 0) diff --git a/src/entity_player_crafting.cpp b/src/entity_player_crafting.cpp new file mode 100644 index 0000000..29de210 --- /dev/null +++ b/src/entity_player_crafting.cpp @@ -0,0 +1,641 @@ +#include "entity_player_crafting.h" +#include "entity_effect.h" +#include "entity_familiar.h" +#include "entity_knife.h" +#include "entity_pickup.h" +#include "game.h" +#include "hud.h" +#include "item_pool.h" +#include "manager.h" +#include "npc_ai.h" +#include "room.h" +#include "room_grid.h" +#include "seeds.h" +#include +#include + +// The pickups the bag holds (REPENTOGON's BagOfCraftingPickup), in recipes.xml's symbol order. +enum BagPickup : uint8_t +{ + BAG_NONE, + BAG_RED_HEART, + BAG_SOUL_HEART, + BAG_BLACK_HEART, + BAG_ETERNAL_HEART, + BAG_GOLD_HEART, + BAG_BONE_HEART, + BAG_ROTTEN_HEART, + BAG_PENNY, + BAG_NICKEL, + BAG_DIME, + BAG_LUCKY_PENNY, + BAG_KEY, + BAG_GOLDEN_KEY, + BAG_CHARGED_KEY, + BAG_BOMB, + BAG_GOLDEN_BOMB, + BAG_GIGA_BOMB, + BAG_MICRO_BATTERY, + BAG_LIL_BATTERY, + BAG_MEGA_BATTERY, + BAG_CARD, + BAG_PILL, + BAG_RUNE, + BAG_DICE_SHARD, + BAG_CRACKED_KEY, + BAG_GOLDEN_PENNY, + BAG_GOLDEN_PILL, + BAG_GOLDEN_BATTERY, + BAG_POOP, + BAG_PICKUP_COUNT = 31 +}; + +// What a pickup puts in the bag: up to two of the bag's pickups, by variant and subtype (any subtype for -1). Rows are +// matched in order, and a row putting nothing in keeps the pickup out of the bag. +struct BagIngredient +{ + int variant = 0; + int subType = 0; + std::array pickups{}; +}; + +constexpr int ANY_SUBTYPE = -1; +constexpr int HEART_SOUL_SUBTYPE = 3; +constexpr int HEART_BLACK_SUBTYPE = 6; +constexpr int HEART_GOLDEN_SUBTYPE = 7; +constexpr int HEART_BONE_SUBTYPE = 11; +constexpr int HEART_ROTTEN_SUBTYPE = 12; +constexpr int BOMB_DOUBLEPACK_SUBTYPE = 2; +constexpr int BOMB_GOLDEN_SUBTYPE = 4; +constexpr int BOMB_GIGA_SUBTYPE = 7; +constexpr int BATTERY_NORMAL_SUBTYPE = 1; +constexpr int BATTERY_MEGA_SUBTYPE = 3; +constexpr int BATTERY_GOLDEN_SUBTYPE = 4; +constexpr int DICE_SHARD_CARD = 49; +constexpr int CRACKED_KEY_CARD = 78; + +constexpr BagIngredient BAG_INGREDIENTS[] = {{PICKUP_HEART, HEART_SOUL_SUBTYPE, {BAG_SOUL_HEART}}, + {PICKUP_HEART, HEART_ETERNAL, {BAG_ETERNAL_HEART}}, + {PICKUP_HEART, HEART_DOUBLEPACK, {BAG_RED_HEART, BAG_RED_HEART}}, + {PICKUP_HEART, HEART_BLACK_SUBTYPE, {BAG_BLACK_HEART}}, + {PICKUP_HEART, HEART_GOLDEN_SUBTYPE, {BAG_GOLD_HEART}}, + {PICKUP_HEART, HEART_HALF_SOUL, {BAG_SOUL_HEART}}, + {PICKUP_HEART, HEART_BLENDED, {BAG_SOUL_HEART, BAG_RED_HEART}}, + {PICKUP_HEART, HEART_BONE_SUBTYPE, {BAG_BONE_HEART}}, + {PICKUP_HEART, HEART_ROTTEN_SUBTYPE, {BAG_ROTTEN_HEART}}, + {PICKUP_HEART, ANY_SUBTYPE, {BAG_RED_HEART}}, + {PICKUP_COIN, COIN_NICKEL, {BAG_NICKEL}}, + {PICKUP_COIN, COIN_DIME, {BAG_DIME}}, + {PICKUP_COIN, COIN_DOUBLEPACK, {BAG_PENNY, BAG_PENNY}}, + {PICKUP_COIN, COIN_LUCKYPENNY, {BAG_LUCKY_PENNY}}, + {PICKUP_COIN, COIN_STICKYNICKEL, {}}, + {PICKUP_COIN, COIN_GOLDEN, {BAG_GOLDEN_PENNY}}, + {PICKUP_COIN, ANY_SUBTYPE, {BAG_PENNY}}, + {PICKUP_KEY, KEY_GOLDEN, {BAG_GOLDEN_KEY}}, + {PICKUP_KEY, KEY_DOUBLEPACK, {BAG_KEY, BAG_KEY}}, + {PICKUP_KEY, KEY_CHARGED, {BAG_CHARGED_KEY}}, + {PICKUP_KEY, ANY_SUBTYPE, {BAG_KEY}}, + {PICKUP_BOMB, BOMB_DOUBLEPACK_SUBTYPE, {BAG_BOMB, BAG_BOMB}}, + {PICKUP_BOMB, BOMB_GOLDEN_SUBTYPE, {BAG_GOLDEN_BOMB}}, + {PICKUP_BOMB, BOMB_GIGA_SUBTYPE, {BAG_GIGA_BOMB}}, + {PICKUP_BOMB, ANY_SUBTYPE, {BAG_BOMB}}, + {PICKUP_POOP, ANY_SUBTYPE, {BAG_POOP}}, + {PICKUP_LIL_BATTERY, BATTERY_NORMAL_SUBTYPE, {BAG_LIL_BATTERY}}, + {PICKUP_LIL_BATTERY, BATTERY_MEGA_SUBTYPE, {BAG_MEGA_BATTERY}}, + {PICKUP_LIL_BATTERY, BATTERY_GOLDEN_SUBTYPE, {BAG_GOLDEN_BATTERY}}, + {PICKUP_LIL_BATTERY, ANY_SUBTYPE, {BAG_MICRO_BATTERY}}}; + +// How much each bag pickup adds to the craft's quality score (the exe's table at 00b6ba30). +constexpr std::array BAG_PICKUP_SCORES = {0, 1, 4, 5, 5, 5, 5, 1, 1, 3, 5, 8, 2, 7, 5, 2, + 7, 10, 2, 4, 8, 2, 2, 4, 4, 2, 7, 7, 7, 0, 1}; + +// The quality range a score allows: from a score on, the lowest and highest item quality. +struct ScoreQuality +{ + int score = 0; + int minQuality = 0; + int maxQuality = 0; +}; +constexpr ScoreQuality SCORE_QUALITIES[] = {{35, 4, 4}, {27, 3, 4}, {23, 2, 4}, {19, 2, 3}, + {15, 1, 2}, {9, 0, 2}, {0, 0, 1}}; + +// A pool weighed in the craft: its weight per bag pickup counted, or a fixed one. +struct PoolWeight +{ + int pool = 0; + float weight = 0; +}; + +constexpr int BLACK_HEART_ODDS = 8; +constexpr int BELIAL_RNG_SHIFT = 6; +constexpr int CRAFT_RNG_SHIFT = 7; +constexpr int CRAFT_PICK_TRIES = 20; +constexpr int CRAFT_FALLBACK = 25; +constexpr int SPECIAL_POOL_SCORE_PENALTY = 5; +constexpr float WEIGHT_PER_PICKUP = 10; +constexpr float SECRET_WEIGHT_PER_BONE_HEART = 5; +constexpr float CRAFT_FLOAT_SCALE = 2.3283062e-10f; +constexpr int CRAFT_HOLD_FRAMES = 30; +constexpr float CRAFT_DROP_STEP = 40; +constexpr float BAG_SWING_REACH = 6; +constexpr float BAG_SWING_RISE = -14; +constexpr int BAG_SWING_COOLDOWN = 5; +constexpr float BAG_SWING_PITCH_SPREAD = 0.2f; +constexpr float BAG_SWING_PITCH_BASE = 0.9f; +constexpr ColorMod BLACKENED_POOF = {{0.12f, 0.12f, 0.12f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr int POOF_COLOR_PRIORITY = 255; +constexpr int POOF_SUBTYPE_SMALL = 1; + +constexpr int BURST_RNG_SHIFT = 13; +constexpr int BURST_PICK_RNG_SHIFT = 35; +constexpr int BURST_MIN_PICKUPS = 4; +constexpr int BURST_PICKUP_BASE = 3; +constexpr int BURST_LUCKY_TOE_ODDS = 3; +constexpr int BURST_COIN_MAX = 3; +constexpr float BURST_COINS_BELOW = 0.35f; +constexpr float BURST_HEART_BELOW = 0.55f; +constexpr float BURST_KEY_BELOW = 0.7f; +constexpr int BURST_TRINKET_ODDS = 100; +constexpr int BURST_TRINKET_CHANCES[] = {33, 66, 100}; +constexpr int ACHIEVEMENT_BONE_HEART_UNLOCK = 391; +constexpr int ACHIEVEMENT_ROTTEN_HEART_UNLOCK = 411; +constexpr int ACHIEVEMENT_RED_KEY_UNLOCK = 415; +constexpr int ACHIEVEMENT_GOLD_BOMB_UNLOCK = 226; + +// A trinket that may add one pickup to the burst, in the order they roll, with that pickup's variant. +struct BurstTrinket +{ + int trinket = 0; + int variant = 0; +}; +constexpr BurstTrinket BURST_TRINKETS[] = {{TRINKET_ACE_OF_SPADES, PICKUP_TAROTCARD}, + {TRINKET_SAFETY_CAP, PICKUP_PILL}, + {TRINKET_CHILDS_HEART, PICKUP_HEART}, + {TRINKET_MATCH_STICK, PICKUP_BOMB}, + {TRINKET_RUSTED_KEY, PICKUP_KEY}}; + +// A pickup the burst's first draw may give for the pedestal's pool, and its weight. +struct BurstPickup +{ + int variant = 0; + int subType = 0; + int weight = 0; +}; + +// Plays a sound for everyone, unless the seeds swap it for a fart. +static void crafting_sound_play(int sound) +{ + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound); +} + +// The bag pickups a pickup gives, or none for one the bag cannot take (a heart Book of Belial blackened comes in as a +// black heart). +static std::optional> bag_ingredients_get(int variant, int subType) +{ + if (variant == PICKUP_PILL) + return std::array{(subType & PILL_COLOR_MASK) == PILL_COLOR_GOLD ? BAG_GOLDEN_PILL : BAG_PILL}; + if (variant == PICKUP_TAROTCARD) + { + if (subType == DICE_SHARD_CARD) return std::array{BAG_DICE_SHARD}; + if (subType == CRACKED_KEY_CARD) return std::array{BAG_CRACKED_KEY}; + ItemConfig_Card* card = g_manager->itemConfig.GetCard(subType); + return std::array{card && card->cardType == CARD_RUNE ? BAG_RUNE : BAG_CARD}; + } + + for (const BagIngredient& row : BAG_INGREDIENTS) + { + if (row.variant != variant || (row.subType != ANY_SUBTYPE && row.subType != subType)) continue; + if (row.pickups[0] == BAG_NONE) return std::nullopt; + return row.pickups; + } + return std::nullopt; +} + +// 007d5170 Takes a pickup the bag's swing touched into Tainted Cain's bag: its one or two bag pickups push out the +// oldest when full, it poofs (black when Book of Belial turned a red heart black), dies into its "Collect" animation +// and is paid for, and a full bag works out what it crafts. Whether the bag took it. +bool Entity_Player::bag_of_crafting_collect(Entity_Pickup* pickup) +{ + int variant = pickup->variant; + int subType = pickup->subtype; + bool isBlackened = false; + + if (pickup->price != 0 && !pickup->CanPickupShopItem(*this)) return false; + bool isBelialHeart = subType == HEART_HALF || subType == HEART_FULL || subType == HEART_DOUBLEPACK; + if (variant == PICKUP_HEART && isBelialHeart && HasCollectible(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE) && + rng_make(pickup->initSeed, BELIAL_RNG_SHIFT).RandomInt(BLACK_HEART_ODDS) == 0) + { + subType = HEART_BLACK_SUBTYPE; + isBlackened = true; + } + std::optional> ingredients = bag_ingredients_get(variant, subType); + if (!ingredients) return false; + + size_t count = std::ranges::find(bagOfCraftingContent, BAG_NONE) - bagOfCraftingContent.begin(); + for (uint8_t ingredient : *ingredients) + { + if (ingredient == BAG_NONE) continue; + if (count >= BAG_OF_CRAFTING_SIZE) + { + std::shift_left(bagOfCraftingContent.begin(), bagOfCraftingContent.end(), 1); + bagOfCraftingContent.back() = BAG_NONE; + count = BAG_OF_CRAFTING_SIZE - 1; + } + bagOfCraftingContent[count++] = (char)ingredient; + } + + uint32_t seed = Random(); + Entity* poof = g_game->Spawn({.position = pickup->pos, + .subType = POOF_SUBTYPE_SMALL, + .type = ENTITY_EFFECT, + .variant = EFFECT_POOF01, + .seed = seed}); + if (isBlackened) poof->SetColor(BLACKENED_POOF, -1, POOF_COLOR_PRIORITY, false, true); + poof->Update(); + pickup->RemoveOtherOptions(); + pickup->velocity = {}; + pickup->entityCollisionClass = ENTCOLL_NONE; + pickup->entityGridCollisionClass = GRIDCOLL_WALLS; + pickup->sprite.Play("Collect"); + pickup->isDead = true; + crafting_sound_play(isBlackened ? SOUND_DEVILROOM_DEAL : SOUND_SCAMPER); + if (pickup->price != 0) pickup->TriggerShopPurchase(*this, 0); + + CraftingRecipe output = {0, -1}; + if (count >= BAG_OF_CRAFTING_SIZE) output = CalculateBagOfCraftingOutput(bagOfCraftingContent); + bagOfCraftingOutput = output.output; + bagOfCraftingPool = output.pool; + g_game->hud.InvalidateCraftingItem(this); + return true; +} + +// The pools a craft draws from and their weights: the treasure, shop and boss pools always, the angel, devil, secret, +// golden chest, curse, red chest and shell game pools by the eternal, black, bone, golden and rotten hearts, cracked +// keys and poops counted, and the planetarium by runes when no red heart, penny, key or bomb went in. +static std::vector craft_pool_weights(const std::array& counts) +{ + auto weighed = [&](int pickup) { + return (float)counts[pickup] * WEIGHT_PER_PICKUP; + }; + std::vector pools = {{POOL_TREASURE, 1}, + {POOL_SHOP, 2}, + {POOL_BOSS, 2}, + {POOL_ANGEL, weighed(BAG_ETERNAL_HEART)}, + {POOL_DEVIL, weighed(BAG_BLACK_HEART)}, + {POOL_SECRET, (float)counts[BAG_BONE_HEART] * SECRET_WEIGHT_PER_BONE_HEART}, + {POOL_GOLDEN_CHEST, weighed(BAG_GOLD_HEART)}, + {POOL_CURSE, weighed(BAG_ROTTEN_HEART)}, + {POOL_RED_CHEST, weighed(BAG_CRACKED_KEY)}, + {POOL_SHELL_GAME, weighed(BAG_POOP)}}; + if (counts[BAG_RED_HEART] + counts[BAG_PENNY] + counts[BAG_KEY] + counts[BAG_BOMB] == 0) + pools.push_back({POOL_PLANETARIUM, weighed(BAG_RUNE)}); + return pools; +} + +// 007d9d00 (00753660) What eight bag pickups craft, and the pool the item counts as from: a recipes.xml recipe when its +// item may appear, else a draw. The start seed steps once per pickup by that pickup's shift, the score sets a quality +// range (5 less for the angel, devil and secret pools), and every pool item in range weighs its pool's weight times its +// own. Up to 20 draws look for an item that may appear, else Breakfast. +CraftingRecipe Entity_Player::CalculateBagOfCraftingOutput(const std::array& bag) +{ + ItemConfig& items = g_manager->itemConfig; + std::array sorted{}; + std::array counts{}; + uint64_t key = 0; + int score = 0; + + std::ranges::transform(bag, sorted.begin(), [](char pickup) { return (uint8_t)pickup; }); + std::ranges::sort(sorted); + for (size_t i = 0; i < sorted.size(); i++) + { + key |= (uint64_t)sorted[i] << (i * 8); + counts[sorted[i]]++; + score += BAG_PICKUP_SCORES[sorted[i]]; + } + if (auto recipe = items.recipes.find(key); recipe != items.recipes.end()) + { + ItemConfig_Item* item = items.GetCollectible(recipe->second.output); + if (item && item->IsAvailableEx(AVAILABLE_ALL)) return recipe->second; + } + + RNG rng = rng_make(g_game->seedEffects.GetStartSeed(), 0); + for (int pickup = 0; pickup < BAG_PICKUP_COUNT; pickup++) + { + rng.SetSeed(rng._seed, pickup + 1); + for (int step = 0; step < counts[pickup]; step++) rng.Next(); + } + + std::vector weights(items.collectibles.size()); + float totalWeight = 0; + for (const PoolWeight& pool : craft_pool_weights(counts)) + { + if (pool.weight <= 0) continue; + bool isSpecial = pool.pool == POOL_ANGEL || pool.pool == POOL_DEVIL || pool.pool == POOL_SECRET; + int poolScore = isSpecial ? score - SPECIAL_POOL_SCORE_PENALTY : score; + const ScoreQuality& range = + *std::ranges::find_if(SCORE_QUALITIES, [&](auto& each) { return poolScore >= each.score; }); + for (const PoolItem& entry : g_game->itemPool.pools[pool.pool].poolList) + { + ItemConfig_Item* item = items.GetCollectible(entry.itemId); + if (!item || !item->IsAvailableEx(AVAILABLE_RUN_RULES) || item->craftingQuality < range.minQuality || + item->craftingQuality > range.maxQuality) + continue; + // A glitched item's negative id indexes before the weights in the original. Here it weighs nothing. + if (item->id < 0 || item->id >= (int)weights.size()) continue; + float weight = pool.weight * entry.initialWeight; + totalWeight += weight; + weights[item->id] += weight; + } + } + + rng.SetSeed(rng._seed, CRAFT_RNG_SHIFT); + for (int attempt = 0; totalWeight > 0 && attempt < CRAFT_PICK_TRIES; attempt++) + { + int chosen = CRAFT_FALLBACK; + float roll = (float)rng.Next() * CRAFT_FLOAT_SCALE * totalWeight; + for (size_t id = 0; id < weights.size(); id++) + { + if (roll < weights[id]) + { + chosen = (int)id; + break; + } + roll -= weights[id]; + } + ItemConfig_Item* item = items.GetCollectible(chosen); + if (item && item->IsAvailableEx(AVAILABLE_UNLOCKED | AVAILABLE_CHARACTERS)) + return {chosen, g_game->itemPool.GetFirstItemPoolForCollectible(chosen)}; + } + return {CRAFT_FALLBACK, g_game->itemPool.GetFirstItemPoolForCollectible(CRAFT_FALLBACK)}; +} + +// Rolls the pickup trinkets for the burst's bonus pickup, for the first player holding each (a Lazarus twin's own copy +// counts for globally shared ones): Daemon's Tail passes Child's Heart one time in five, and one, two or three copies +// add their pickup a third, two thirds or every time. The first to pass spawns its pickup and ends the roll. +static void burst_trinket_roll(Entity_Player& player, RNG& rng, Vector position) +{ + PlayerManager& players = g_game->playerManager; + auto holder = [&](int trinket) { + ItemConfig_Item* config = g_manager->itemConfig.GetTrinket(trinket); + bool isShared = config && config->HasTags(TAG_LAZ_SHARED_GLOBAL); + return std::ranges::any_of(players.playerList, [&](Entity_Player* each) { + return each->variant == PLAYER_VARIANT_PLAYER && + (each->HasTrinket(trinket) || + (isShared && each->backupPlayer && each->backupPlayer->HasTrinket(trinket))); + }); + }; + + for (const BurstTrinket& bonus : BURST_TRINKETS) + { + if (!holder(bonus.trinket)) continue; + if (bonus.trinket == TRINKET_CHILDS_HEART && holder(TRINKET_DAEMONS_TAIL) && + rng.Next() % DAEMONS_TAIL_ODDS != 0) + continue; + int copies = std::clamp(players.GetTrinketMultiplier(bonus.trinket), 1, (int)std::size(BURST_TRINKET_CHANCES)); + if ((int)(rng.Next() % BURST_TRINKET_ODDS) >= BURST_TRINKET_CHANCES[copies - 1]) continue; + + Vector velocity = Entity_Pickup::GetRandomPickupVelocity(position, nullptr, 0); + uint32_t seed = player.GetTrinketRNG(bonus.trinket).Next(); + g_game->Spawn({.position = position, + .velocity = velocity, + .type = ENTITY_PICKUP, + .variant = bonus.variant, + .seed = seed}); + return; + } +} + +// The pickup the burst's first draw gives for the pedestal's pool: black hearts for the devil's, eternal ones for the +// angel's, bone hearts for the secret ones, cracked keys for the red chest and ultra secret pools, rotten hearts for +// the curse ones, a rune for the planetarium, and for any other a weighed soul heart, nickel, dime, golden key or +// golden bomb, or nothing (variant 0). Unlocks gate the special ones. +static BurstPickup burst_pool_pickup(Entity_Player& player, RNG& rng, int poolType) +{ + auto gated = [](int achievement, BurstPickup pickup) { + return is_run_unlocked(achievement) ? pickup : BurstPickup{}; + }; + switch (poolType) + { + case POOL_DEVIL: + case POOL_GREED_DEVIL: + return {PICKUP_HEART, HEART_BLACK_SUBTYPE}; + case POOL_ANGEL: + case POOL_GREED_ANGEL: + return {PICKUP_HEART, HEART_ETERNAL}; + case POOL_SECRET: + case POOL_GREED_SECRET: + return gated(ACHIEVEMENT_BONE_HEART_UNLOCK, {PICKUP_HEART, HEART_BONE_SUBTYPE}); + case POOL_RED_CHEST: + return gated(ACHIEVEMENT_RED_KEY_UNLOCK, {PICKUP_TAROTCARD, CRACKED_KEY_CARD}); + case POOL_CURSE: + case POOL_GREED_CURSE: + return gated(ACHIEVEMENT_ROTTEN_HEART_UNLOCK, {PICKUP_HEART, HEART_ROTTEN_SUBTYPE}); + case POOL_ULTRA_SECRET: + return {PICKUP_TAROTCARD, CRACKED_KEY_CARD}; + case POOL_PLANETARIUM: + return {PICKUP_TAROTCARD, ItemPool::GetCardEx((int)rng.Next(), 0, -1, 0, true)}; + default: + break; + } + + int soulWeight = 10; + if (player.HasTrinket(TRINKET_DAEMONS_TAIL)) + soulWeight = player.GetTrinketRNG(TRINKET_DAEMONS_TAIL).Next() % DAEMONS_TAIL_ODDS == 0 ? 10 : 0; + std::array table = { + {{PICKUP_HEART, HEART_SOUL_SUBTYPE, soulWeight}, + {PICKUP_COIN, COIN_NICKEL, 10}, + {PICKUP_COIN, COIN_DIME, 5}, + {PICKUP_KEY, KEY_GOLDEN, 1}, + {PICKUP_BOMB, BOMB_GOLDEN_SUBTYPE, is_run_unlocked(ACHIEVEMENT_GOLD_BOMB_UNLOCK) ? 1 : 0}, + {0, 0, 30}}}; + WeightedOutcomePicker picker; + for (int outcome = 0; outcome < (int)table.size(); outcome++) + if (table[outcome].weight > 0) picker.outcomes.push_back({outcome, table[outcome].weight}); + uint32_t seed = rng.Next(); + return table[picker.PickOutcome(rng_make(seed, BURST_PICK_RNG_SHIFT))]; +} + +// 007d58f0 Tainted Cain breaks a pedestal (or a crafted active pushes out the held one) into four to seven pickups, one +// more with Lucky Toe two times in three, after a pickup trinket's bonus pickup, doubled with Birthright. The first +// draw may give a pickup for the pool, any other gives coins below 0.35, a heart below 0.55 (which may not count), a +// key below 0.7, else a bomb. A pool of -1 is the room's. +void Entity_Player::tainted_cain_pedestal_burst(Vector position, uint32_t seed, int poolType) +{ + RNG rng = rng_make(seed, BURST_RNG_SHIFT); + int count = std::max(BURST_MIN_PICKUPS, (int)(rng.Next() & 3) + BURST_PICKUP_BASE); + if (rng.Next() % BURST_LUCKY_TOE_ODDS != 0 && HasTrinket(TRINKET_LUCKY_TOE)) count++; + burst_trinket_roll(*this, rng, position); + if (HasCollectible(COLLECTIBLE_BIRTHRIGHT) && playerType == PLAYER_CAIN_B) count *= 2; + + auto spawn = [&](int variant, int subType) { + Vector velocity = Entity_Pickup::GetRandomPickupVelocity(position, nullptr, 0); + uint32_t pickupSeed = rng.Next(); + g_game->Spawn({.position = position, + .velocity = velocity, + .subType = subType, + .type = ENTITY_PICKUP, + .variant = variant, + .seed = pickupSeed}); + }; + for (int drawn = 0; drawn < count; drawn++) + { + int countBefore = count; + float roll = (float)rng.Next() * CRAFT_FLOAT_SCALE; + if (drawn == 0) + { + if (poolType == -1) poolType = g_game->itemPool.GetPoolForRoom(g_game->room->roomType, rng.Next()); + BurstPickup pickup = burst_pool_pickup(*this, rng, poolType); + if (pickup.variant != 0) + { + spawn(pickup.variant, pickup.subType); + continue; + } + } + + bool isHeart = roll >= BURST_COINS_BELOW && roll < BURST_HEART_BELOW; + if (isHeart && HasTrinket(TRINKET_DAEMONS_TAIL)) + isHeart = GetTrinketRNG(TRINKET_DAEMONS_TAIL).Next() % DAEMONS_TAIL_ODDS == 0; + if (roll < BURST_COINS_BELOW) + { + for (int coins = (int)(rng.Next() % BURST_COIN_MAX) + 1; coins > 0; coins--) spawn(PICKUP_COIN, 0); + } + else if (isHeart) + { + spawn(PICKUP_HEART, 0); + if ((rng.Next() & 1) == 0) count = countBefore - 1; + } + else + spawn(roll < BURST_KEY_BELOW ? PICKUP_KEY : PICKUP_BOMB, 0); + } +} + +// The Bag of Crafting part of 005b39d0: used from a main slot with a craft ready, the bag drops the crafted item on a +// pedestal (counted from its pool, with a wisp under Book of Virtues) and empties with a thumbs up. From the pocket it +// is lifted to swing. The animation the player shows, none for a co-op baby. The Cantripped challenge's card bag is not +// written yet. +const char* bag_of_crafting_use(Entity_Player& player, int slot) +{ + if (player.variant != PLAYER_VARIANT_PLAYER) return nullptr; + crafting_sound_play(SOUND_BAG_OF_CRAFTING); + if (g_game->challenge == CHALLENGE_CANTRIPPED) + reconstruction_missing("Entity_Player::UseActiveItem 005b39d0 (the Cantripped bag's cards)"); + if ((slot != ACTIVE_SLOT_PRIMARY && slot != ACTIVE_SLOT_SECONDARY) || player.bagOfCraftingOutput == 0) + { + player.SetItemState(COLLECTIBLE_BAG_OF_CRAFTING); + return "LiftItem"; + } + + if (g_manager->itemConfig.GetCollectible(player.bagOfCraftingOutput)) + { + RNG& rng = player.GetCollectibleRNG(COLLECTIBLE_BAG_OF_CRAFTING); + g_pickupIgnoreModifiers++; + uint32_t seed = rng.Next(); + Vector spot = room_free_pickup_position_find({player.pos, CRAFT_DROP_STEP, true}); + auto* pedestal = static_cast(g_game->Spawn({.position = spot, + .subType = player.bagOfCraftingOutput, + .type = ENTITY_PICKUP, + .variant = PICKUP_COLLECTIBLE, + .seed = seed})); + g_pickupIgnoreModifiers--; + pedestal->itemPoolType = player.bagOfCraftingPool; + if (player.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES)) + player.AddWisp(Entity_Familiar::GetRandomWisp(&rng), player.pos, false, false); + } + player.bagOfCraftingHoldFrames = 0; + player.bagOfCraftingOutput = 0; + player.bagOfCraftingPool = -1; + player.bagOfCraftingContent.fill(BAG_NONE); + g_game->hud.InvalidateCraftingItem(&player); + crafting_sound_play(SOUND_THUMBSUP); + return "UseItem"; +} + +// The crafting part of 00791a40: the lifted bag held for 30 frames with a craft ready makes it. The item is held up and +// queued, an active crafted over a held one (but Book of Virtues, or with a free Schoolbag slot) bursts the held one +// into pickups like a pedestal, Book of Virtues adds a wisp, and the bag empties with a power up sound. +void bag_of_crafting_craft(Entity_Player& player) +{ + if (++player.bagOfCraftingHoldFrames < CRAFT_HOLD_FRAMES) return; + + player.ResetItemState(); + int crafted = player.bagOfCraftingOutput; + if (ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(crafted)) + { + player.AnimateCollectible(crafted, "Pickup", "PlayerPickupSparkle"); + if (item->type == ITEM_ACTIVE) + { + player.FlushQueueItem(); + auto isKeptActive = [](int held) { + return !ItemConfig::IsValidCollectible(held) || held == COLLECTIBLE_BOOK_OF_VIRTUES; + }; + int held = player.activeItems[ACTIVE_SLOT_PRIMARY].item; + bool isSchoolbagFree = player.HasCollectible(COLLECTIBLE_SCHOOLBAG) && + isKeptActive(player.activeItems[ACTIVE_SLOT_SECONDARY].item); + if (!isKeptActive(held) && !isSchoolbagFree) + { + player.RemoveCollectible(held, false, ACTIVE_SLOT_PRIMARY, false); + int pool = g_game->IsGreedMode() ? POOL_GREED_TREASURE : POOL_TREASURE; + player.tainted_cain_pedestal_burst(player.pos, player.GetCollectibleRNG(held).Next(), pool); + } + } + g_game->hud.ShowItemText(&player, item); + // The original queues the item with the pool it first appears in. The queue here keeps no pool. + player.SetQueuedItem({item, item->initCharge, 0, 0}); + if (player.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES)) + player.AddWisp(Entity_Familiar::GetRandomWisp(&player.GetCollectibleRNG(COLLECTIBLE_BAG_OF_CRAFTING)), + player.pos, false, false); + } + player.bagOfCraftingHoldFrames = 0; + player.bagOfCraftingOutput = 0; + player.bagOfCraftingPool = -1; + player.bagOfCraftingContent.fill(BAG_NONE); + g_game->hud.InvalidateCraftingItem(&player); + crafting_sound_play(SOUND_POWERUP_SPEWER); +} + +// The Bag of Crafting part of 0077b020: the lifted bag stays raised, and a shot swings it as a knife toward the aim, +// which takes the pickups it touches (Entity_Knife's swing hits). The bag lowers and its state lapses after 5 frames. +void bag_of_crafting_swing(Entity_Player& player, Vector aim, bool isSwung) +{ + if (player.IsExtraAnimationFinished()) + { + player.PlayExtraAnimation("LiftItem", false); + player.bodySprite.SetLastFrame(); + } + if (!isSwung) return; + + uint32_t seed = Random(); + auto* bag = static_cast(g_game->Spawn({.position = player.pos, + .spawner = &player, + .type = ENTITY_KNIFE, + .variant = KNIFE_BAG_OF_CRAFTING, + .seed = seed})); + bag->parent = &player; + bag->targetPosition = vector_make(BAG_SWING_REACH, 0); + bag->rotation = vector_angle(aim); + bag->posOffset = vector_make(0, BAG_SWING_RISE); + bag->sprite.scale = player.sprite.scale; + bag->SetAttackAnimation(); + bag->swingEffects = 1; + bag->swingTick = 0; + bag->isAttacking = false; + bag->SetCollisionDamage(1); + bag->Update(); + + player.itemStateCooldown = BAG_SWING_COOLDOWN; + if (int slot = player.GetActiveItemSlot(COLLECTIBLE_BAG_OF_CRAFTING); slot >= 0) + player.DischargeActiveItem(slot, false); + player.blinkTime = 1; + player.PlayExtraAnimation("HideItem", false); + int sound = SOUND_BIRD_FLAP; + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound, {.pitch = random_unit() * BAG_SWING_PITCH_SPREAD + BAG_SWING_PITCH_BASE}); +} + +// 0075ea20 Holds an item up as the player's item state, adding the queued item first. +void Entity_Player::SetItemState(int collectibleId) +{ + FlushQueueItem(); + itemState = collectibleId; +} diff --git a/src/entity_player_crafting.h b/src/entity_player_crafting.h new file mode 100644 index 0000000..b0adc82 --- /dev/null +++ b/src/entity_player_crafting.h @@ -0,0 +1,10 @@ +#pragma once + +#include "entity_player.h" + +// Tainted Cain's Bag of Crafting outside Entity_Player's own methods: the bag used from a slot (part of 005b39d0), +// which names the animation the player holds it up with (none for a co-op baby), and the bag held up long enough to +// craft (part of 00791a40), and the lifted bag swung by the shoot buttons (part of 0077b020). +const char* bag_of_crafting_use(Entity_Player& player, int slot); +void bag_of_crafting_craft(Entity_Player& player); +void bag_of_crafting_swing(Entity_Player& player, Vector aim, bool isSwung); diff --git a/src/entity_player_damage.cpp b/src/entity_player_damage.cpp index eb6ee6f..e437f29 100644 --- a/src/entity_player_damage.cpp +++ b/src/entity_player_damage.cpp @@ -73,6 +73,8 @@ constexpr int SOUND_FRAME_DELAY = 2; constexpr uint64_t DAMAGE_INVINCIBLE_IGNORED = 1ull << 13; constexpr uint64_t DAMAGE_FAKE = 1ull << 21; constexpr uint64_t DAMAGE_IGNORED = 1ull << 34; +// Tainted Jacob turned ghost by Dark Esau cannot be hurt for 90 frames. +constexpr int JACOB_GHOST_COOLDOWN = 90; constexpr uint64_t DAMAGE_NO_HURT_EFFECTS = 0x100d0400; constexpr uint64_t DAMAGE_ISAACS_HEART_PIERCE = 0x2820; constexpr uint64_t DAMAGE_UNPENALIZED = DAMAGE_NO_PENALTIES | DAMAGE_RED_HEARTS; @@ -347,9 +349,9 @@ static int red_hearts_remove(Entity_Player& player, int amount, bool isRedFirst, player.AddHearts(-amount, false, false); bool isKeeper = player.playerType == PLAYER_KEEPER || player.playerType == PLAYER_KEEPER_B; - if (player.playerType == PLAYER_MAGDALENE_B) - reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Tainted Magdalene's red heart damage)"); - if (isRedLost && !isKeeper && !player.parent && isPenalized && amount > 0 && player.redHearts < player.maxHearts) + bool isTemporaryRed = player.playerType == PLAYER_MAGDALENE_B && player.redHearts >= maggy_heart_limit(player); + if (isRedLost && !isKeeper && !player.parent && isPenalized && amount > 0 && player.redHearts < player.maxHearts && + !isTemporaryRed) { int multiplier = player.GetTrinketMultiplier(TRINKET_CROW_HEART); uint32_t keptChance = multiplier == 2 ? CROW_HEART_KEEP_2 : multiplier >= 3 ? CROW_HEART_KEEP_3 : 0; @@ -495,7 +497,12 @@ bool Entity_Player::TakeDamage(float damage, uint64_t damageFlags, const EntityR if (!lua_engine_get().EntityTakeDamage(this, (float)amount, damageFlags, source, damageCountdown)) return false; if (try_end_astral_projection()) return false; if (playerType == PLAYER_JACOB_B && source.type == ENTITY_DARK_ESAU) - reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Tainted Jacob's ghost form)"); + { + spawn_ghost_corpse(); + ChangePlayerType(PLAYER_JACOB2_B, false); + SetMinDamageCooldown(JACOB_GHOST_COOLDOWN); + return false; + } Entity* attacker = source.entity ? source.entity->GetPlayerAncestor() : nullptr; if (attacker) Player_stats_add(game.onlinePlayerStats, ONLINE_STAT_PLAYER_DAMAGE_DEALT, (Entity_Player*)attacker, amount); @@ -509,9 +516,7 @@ bool Entity_Player::TakeDamage(float damage, uint64_t damageFlags, const EntityR if (isPenalized) { roomDamageTaken += amount; - if (playerType == PLAYER_MAGDALENE_B) - reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Tainted Magdalene's damage taken)"); - totalDamageTaken += amount; + if (playerType != PLAYER_MAGDALENE_B || !is_maggy_draining(*this)) totalDamageTaken += amount; } if (source.type >= ENTITY_FIRST_ENEMY && source.type <= ENEMY_TYPE_LAST) bestiary_count_add(g_manager->persistentGameData.bestiary.hits, source.type, source.variant); @@ -789,6 +794,16 @@ bool Entity_Player::IsBoneHeart(int heart) return boneHearts > 0 && (boneHeartsMask & 1 << heart); } +// 007591e0 Turns the black heart holding a soul heart, counted in halves from 0, back into a soul heart. +void Entity_Player::RemoveBlackHeart(int soulHeartIndex) +{ + if (soulHeartIndex > soulHearts || soulHeartIndex < 0) return; + + blackHearts &= ~(1u << (soulHeartIndex >> 1 & 31)); + ClampGoldenHearts(false); + update_bone_hearts(); +} + // 00759220 Whether a soul heart, counted in halves from 1, is the first half of a black heart. bool Entity_Player::IsBlackHeart(int heart) { @@ -889,6 +904,13 @@ void Entity_Player::PlayExtraAnimation(std::string_view animName) isPlayingExtraAnimation = true; } +// 007abcc0 Plays the teleport out (up, with the portal's sound) or in. +void Entity_Player::AnimateTeleport(bool isUp) +{ + PlayExtraAnimation(isUp ? "TeleportUp" : "TeleportDown"); + if (isUp) sound_play(SOUND_HELL_PORTAL2); +} + // 007abe90 Plays an animation of the player's sprite on its body sprite, as picking items up does. void Entity_Player::PlayExtraAnimation(std::string_view animation, bool) { diff --git a/src/entity_player_death.cpp b/src/entity_player_death.cpp index 5a51590..271a106 100644 --- a/src/entity_player_death.cpp +++ b/src/entity_player_death.cpp @@ -15,7 +15,6 @@ #include #include -constexpr int COLLECTIBLE_CHARM_VAMPIRE = 62; constexpr int COLLECTIBLE_ANKH = 161; constexpr int COLLECTIBLE_JUDAS_SHADOW = 311; constexpr int COLLECTIBLE_POLYDACTYLY = 454; diff --git a/src/entity_player_evaluate.cpp b/src/entity_player_evaluate.cpp index e0f2577..3cfb2a2 100644 --- a/src/entity_player_evaluate.cpp +++ b/src/entity_player_evaluate.cpp @@ -1045,7 +1045,7 @@ void Entity_Player::EvaluateItems() // The collectibles the frame (00782af0) looks at itself, which its plain path does not cover yet. The weapon items are // not among them: the frame and its items' part (update_effects 00794e50) never ask for them, their weapons do. -constexpr std::array FRAME_ITEMS = {375, 397, 465, 493, 497, 534, 575, 593, 619, 632, 641, 59, 202, 210, 399}; +constexpr std::array FRAME_ITEMS = {375, 465, 493, 497, 534, 575, 593, 619, 632, 641, 59, 202, 210, 399}; // Whether the player's frame runs its plain path: a plain character holding none of the items the frame handles. bool Entity_Player::is_frame_plain() diff --git a/src/entity_player_forgotten.cpp b/src/entity_player_forgotten.cpp index a62be3a..e24960b 100644 --- a/src/entity_player_forgotten.cpp +++ b/src/entity_player_forgotten.cpp @@ -1,4 +1,5 @@ #include "entity_player_forgotten.h" +#include "tainted_characters.h" #include "entity_familiar.h" #include "entity_npc.h" #include "entity_pickup.h" @@ -637,6 +638,7 @@ static EffectUpdateEnd forgotten_chain_update(Entity_Effect& chain) constexpr auto PLAYER_EFFECT_BEHAVIOURS = std::to_array({ {EFFECT_FORGOTTEN_CHAIN, nullptr, forgotten_chain_update, nullptr}, + {EFFECT_ANIMA_CHAIN, anima_chain_init, anima_chain_update, nullptr}, }); std::span player_effect_behaviours() diff --git a/src/entity_player_frame.cpp b/src/entity_player_frame.cpp index b07dee0..ca5808d 100644 --- a/src/entity_player_frame.cpp +++ b/src/entity_player_frame.cpp @@ -1,4 +1,7 @@ #include "entity_player.h" +#include "entity_player_characters.h" +#include "entity_player_crafting.h" +#include "tainted_characters.h" #include "entity_effect.h" #include "game.h" #include "key_configs.h" @@ -6,8 +9,10 @@ #include "lua_engine.h" #include "manager.h" #include "menu_manager.h" +#include "npc_ai.h" #include "platform.h" #include "room.h" +#include "weapon_lasers.h" #include #include @@ -44,6 +49,15 @@ constexpr int SHOOP_BLINK = 10; constexpr int SHOOT_HISTORY_SIZE = 3; constexpr int SPECIAL_DAILY_BUTTER_BEAN = 41; constexpr int SUPLEX_LANDING = 2; +constexpr int SUPLEX_TARGET_VARIANT = 30; +constexpr float MARKED_SPAWN_REACH = 5; +constexpr float MARKED_STEER_SPEED = 8; +constexpr float SUPLEX_TARGET_REACH = 60; +constexpr float SUPLEX_TARGET_PULL = 0.1f; +constexpr float MARKED_STATUE_MASS = 1000; +constexpr uint32_t DEAD_EYE_CHARGE_LIMIT = 8; +constexpr uint32_t DEAD_EYE_RESET_CHANCES[] = {50, 20, 33}; +constexpr uint32_t DEAD_EYE_RESET_CERTAIN = 100; constexpr int COLLECTIBLE_HOW_TO_JUMP = 282; constexpr int COLLECTIBLE_POINTY_RIB = 544; @@ -484,6 +498,106 @@ void Entity_Player::shoot_input_read(ShootInput& input) input.isPressed = false; } +// The raw aim that steers a Marked target, with whether the update interpolates and the shoot button is held. +struct MarkedAim +{ + Vector direction{}; + bool isInterpolation = false; + bool isShootHeld = false; +}; + +static void marked_target_remove(Entity_Player& player) +{ + player.markedTarget->Remove(); + player.markedTarget = nullptr; +} + +// The Marked target part of 0077b020, also the suplex's landing target: the drop button clears it, a new target +// variant replaces it and an aim spawns it. The aim steers it and a suplex pulls it within reach. Whether a held +// target shoots on its own, which it does unless Gnawed Leaf has turned the player to stone. +static bool marked_target_update(Entity_Player& player, const MarkedAim& aim) +{ + bool isSuplex = player.suplexState == SUPLEX_LANDING; + int variant = player.weapons[1] ? player.weapons[1]->GetMarkedTargetVariant() : 0; + if (isSuplex) variant = SUPLEX_TARGET_VARIANT; + + if (variant == 0) + { + if (player.markedTarget && !aim.isInterpolation) marked_target_remove(player); + return false; + } + if (player.markedTarget && input_is_action_triggered(ACTION_DROP, player.controllerIndex, &player) && !isSuplex) + marked_target_remove(player); + if (!aim.isInterpolation && !(player.markedTarget && player.markedTarget->variant == variant)) + { + if (player.markedTarget) marked_target_remove(player); + if (!is_zero(aim.direction) || isSuplex) + { + uint32_t seed = Random(); + Vector spot = vector_add(player.pos, vector_scale(aim.direction, MARKED_SPAWN_REACH)); + Entity* spawned = g_game->Spawn({.position = spot, .spawner = &player, .type = ENTITY_EFFECT, + .variant = variant, .seed = seed}); + + // The original writes the timeout of a spawn that failed or was replaced. Here that spawn is dropped. + auto* target = spawned && spawned->type == ENTITY_EFFECT ? static_cast(spawned) : nullptr; + if (target) + { + target->timeout = 0; + target->lifespan = 0; + } + player.markedTarget = target; + } + } + + Entity* target = player.markedTarget; + if (!target || (player.itemState != 0 && !isSuplex)) return false; + if (aim.isShootHeld) + { + Vector steer = vector_length_squared(aim.direction) > 1 ? vector_normalized(aim.direction) : aim.direction; + target->velocity = vector_add(target->velocity, vector_scale(steer, MARKED_STEER_SPEED)); + } + if (isSuplex) + { + Vector toward = vector_sub(player.pos, target->pos); + float distance = vector_length(toward); + if (distance > SUPLEX_TARGET_REACH) + { + float excess = distance - SUPLEX_TARGET_REACH; + target->velocity.x += toward.x / distance * excess * SUPLEX_TARGET_PULL; + target->velocity.y += toward.y / distance * excess * SUPLEX_TARGET_PULL; + } + } + return !player.HasCollectible(COLLECTIBLE_GNAWED_LEAF) || player.mass != MARKED_STATUE_MASS; +} + +// 007c78b0 A Dead Eye hit: one more charge (8 at most) and the misses forgotten. +void Entity_Player::AddDeadEyeCharge() +{ + if (deadEyeCharges < DEAD_EYE_CHARGE_LIMIT) + { + cacheFlags |= CACHE_DAMAGE; + deadEyeCharges++; + EvaluateItems(); + } + deadEyeMisses = 0; +} + +// 007c78e0 A Dead Eye miss: the charges reset at 20, 33 then 50% odds by misses in a row, always with a bone weapon. +void Entity_Player::ClearDeadEyeCharge() +{ + if (deadEyeCharges == 0) return; + deadEyeMisses++; + uint32_t chance = deadEyeMisses < std::size(DEAD_EYE_RESET_CHANCES) ? DEAD_EYE_RESET_CHANCES[deadEyeMisses] + : DEAD_EYE_RESET_CHANCES[0]; + if (weaponTypes[WEAPON_BONE]) chance = DEAD_EYE_RESET_CERTAIN; + if (Random() % DEAD_EYE_RESET_CERTAIN >= chance) return; + + cacheFlags |= CACHE_DAMAGE; + deadEyeMisses = 0; + deadEyeCharges = 0; + EvaluateItems(); +} + // 0077b020 Shooting, each frame: reads the shoot input, turns the head to the shot (or to the walk when idle), counts // the weapons' delays down and fires them, blinks the eyes while shooting and keeps the recent shot directions. The // items, item states and characters that change shooting stop the game until reached. @@ -516,6 +630,7 @@ void Entity_Player::update_shooting() itemState != HELD_ITEM_STATE_SUPLEX) reconstruction_missing("Entity_Player::update_shooting 0077b020 (dropping the held entity)"); + Vector markedAim = input.direction; TemporaryEffect* taurus = temporaryEffects.GetCollectibleEffect(COLLECTIBLE_TAURUS); bool isShootingBlocked = std::ranges::any_of(NO_SHOOT_EFFECTS, [&](int id) { return temporaryEffects.HasCollectibleEffect(id); }) || @@ -525,7 +640,15 @@ void Entity_Player::update_shooting() input.direction = {}; input.isPressed = false; } - if (itemStateCooldown > 0) reconstruction_missing("Entity_Player::update_shooting 0077b020 (item state cooldown)"); + if (itemStateCooldown > 0 && !isInterpolation && --itemStateCooldown < 1) + { + if (ItemConfig::is_held_active(itemState)) + { + temporaryEffects.RemoveCollectibleEffect(itemState, 1); + TryRemoveCollectibleCostume(itemState, false); + } + ResetItemState(); + } if (itemStateCooldown != 0) input.direction = {}; Vector shootDirection = input.direction; @@ -536,13 +659,7 @@ void Entity_Player::update_shooting() bool canFire = isCoopGhost || canShoot; Vector headAim = shootDirection; - if ((weapons[1] && weapons[1]->GetMarkedTargetVariant()) || suplexState == SUPLEX_LANDING) - reconstruction_missing("Entity_Player::update_shooting 0077b020 (Marked and suplex targets)"); - if (markedTarget && !isInterpolation) - { - markedTarget->Remove(); - markedTarget = nullptr; - } + if (marked_target_update(*this, {markedAim, isInterpolation, isShootHeld})) isShootHeld = true; if (game.dailyChallenge._specialDailyId == SPECIAL_DAILY_BUTTER_BEAN) reconstruction_missing("Entity_Player::update_shooting 0077b020 (the Butter Bean daily)"); @@ -562,7 +679,17 @@ void Entity_Player::update_shooting() if (headDirectionTime < 0) { - if (GetFocusEntity()) reconstruction_missing("Entity_Player::update_shooting 0077b020 (aiming at a focus)"); + if (Entity* focus = GetFocusEntity()) + { + Vector aimed = isInterpolation ? vector_scale(vector_add(focus->pos, focus->prevPosition), 0.5f) + : focus->prevPosition; + headAim = vector_sub(aimed, pos); + if (focus == markedTarget && itemState == 0) + { + shootDirection = headAim; + isDirectionHeld = !is_zero(shootDirection); + } + } if (!is_zero(headAim)) head_turn(headAim); } if (fireBlockCooldown < 1) @@ -610,7 +737,9 @@ void Entity_Player::update_shooting() reconstruction_missing("Entity_Player::update_shooting 0077b020 (the headless blood spray)"); if (HasTrinket(TRINKET_TEARDROP_CHARM)) reconstruction_missing("Entity_Player::update_shooting 0077b020 (the luck trinket)"); - if (itemState != 0) reconstruction_missing("Entity_Player::update_shooting 0077b020 (item states)"); + if (itemState == COLLECTIBLE_BAG_OF_CRAFTING) + bag_of_crafting_swing(*this, shootDirection, !isInterpolation && isShootHeld); + else if (itemState != 0) reconstruction_missing("Entity_Player::update_shooting 0077b020 (item states)"); if (canFire && isFireReady) trigger_fire_item_effects(shootDirection, isShootHeld); if (!isShootHeld && blinkTime < 0 && headDirectionTime < 0 && game.roomTransition.mode == TRANSITION_NONE) @@ -661,7 +790,9 @@ static void temporary_effects_update(Entity_Player& player) effects.isEvaluateCachePending = false; if (player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE)) return; + tainted_frame_update(player); effects.Update(); + character_frame_update(player); lua_engine_get().PostPEffectUpdate(&player); } @@ -701,6 +832,7 @@ void Entity_Player::Update() ControlActiveItem(ACTIVE_SLOT_PRIMARY); pocket_use_input(); update_shooting(); + tractor_beam_update(*this); pockets_rotate(); temporary_effects_update(*this); walk_animation_update(); diff --git a/src/entity_player_missing.cpp b/src/entity_player_missing.cpp index 2965d7b..d75bca5 100644 --- a/src/entity_player_missing.cpp +++ b/src/entity_player_missing.cpp @@ -9,10 +9,6 @@ Entity_Familiar* Entity_Player::AddWisp(int, Vector, bool, bool) { reconstruction_missing("Entity_Player::AddWisp 005c93b0"); } -void Entity_Player::SetMinDamageCooldown(int) -{ - reconstruction_missing("Entity_Player::SetMinDamageCooldown 004361d0"); -} void Entity_Player::StopExtraAnimation() { reconstruction_missing("Entity_Player::StopExtraAnimation 0058e230"); } void Entity_Player::moms_bracelet_grab() { reconstruction_missing("Entity_Player::moms_bracelet_grab 005b1a20"); } void Entity_Player::UseRedKey() { reconstruction_missing("Entity_Player::UseRedKey 005b2360"); } @@ -21,10 +17,6 @@ int Entity_Player::reroll_collectibles_on_damage(RNG*, bool) { reconstruction_missing("Entity_Player::reroll_collectibles_on_damage 005c88a0"); } -Entity_Familiar* Entity_Player::AddItemWisp(int, Vector, bool) -{ - reconstruction_missing("Entity_Player::AddItemWisp 005c96f0"); -} void Entity_Player::ResetDamageCooldown() { reconstruction_missing("Entity_Player::ResetDamageCooldown 0060d090"); } Vector Entity_Player::SpriteScale() { reconstruction_missing("Entity_Player::SpriteScale 0060d0a0"); } void Entity_Player::set_last_damage(uint64_t, const EntityRef&) @@ -35,16 +27,11 @@ void Entity_Player::QueueExtraAnimation(std::string_view) { reconstruction_missing("Entity_Player::QueueExtraAnimation 007539c0"); } -void Entity_Player::release_weapons_and_effects(bool) -{ - reconstruction_missing("Entity_Player::release_weapons_and_effects 00757ac0"); -} void Entity_Player::cycle_spectate_target() { reconstruction_missing("Entity_Player::cycle_spectate_target 007585b0"); } void Entity_Player::trigger_max_hearts_removed(int) { reconstruction_missing("Entity_Player::trigger_max_hearts_removed 00758850"); } -void Entity_Player::RemoveBlackHeart(int) { reconstruction_missing("Entity_Player::RemoveBlackHeart 007591e0"); } void Entity_Player::AddGoldenKey() { reconstruction_missing("Entity_Player::AddGoldenKey 00759620"); } void Entity_Player::RemoveGoldenKey() { reconstruction_missing("Entity_Player::RemoveGoldenKey 00759660"); } void Entity_Player::RemoveBlueFly() { reconstruction_missing("Entity_Player::RemoveBlueFly 00759b80"); } @@ -55,7 +42,6 @@ Entity* Entity_Player::AddSwarmFlyOrbital(Vector) reconstruction_missing("Entity_Player::AddSwarmFlyOrbital 00759bf0"); } void Entity_Player::AddNullCostume(int) { reconstruction_missing("Entity_Player::AddNullCostume 0075d800"); } -void Entity_Player::SetItemState(int) { reconstruction_missing("Entity_Player::SetItemState 0075ea20"); } void Entity_Player::RespawnFamiliars() { reconstruction_missing("Entity_Player::RespawnFamiliars 00770600"); } void Entity_Player::GetNPCTarget() { reconstruction_missing("Entity_Player::GetNPCTarget 00770610"); } bool Entity_Player::VoidHasCollectible(int) { reconstruction_missing("Entity_Player::VoidHasCollectible 007711a0"); } @@ -78,10 +64,6 @@ void Entity_Player::RemoveCollectibleByHistoryIndex(int, bool) } void Entity_Player::update_effects() { reconstruction_missing("Entity_Player::update_effects 00794e50"); } void Entity_Player::update_ladder() { reconstruction_missing("Entity_Player::update_ladder 0079f3c0"); } -Entity_Bomb* Entity_Player::FireBomb(Vector, Vector, Entity*) -{ - reconstruction_missing("Entity_Player::FireBomb 007a0970"); -} void Entity_Player::ReviveFromTrinket(uint32_t) { reconstruction_missing("Entity_Player::ReviveFromTrinket 007a3430"); } void Entity_Player::remove_twin() { reconstruction_missing("Entity_Player::remove_twin 007a37c0"); } void Entity_Player::AnimateTrinket(int, std::string_view, std::string_view) @@ -92,7 +74,6 @@ void Entity_Player::AnimateTrapdoor() { reconstruction_missing("Entity_Player::A // 007abc10 Plays the rise up a beam of light. void Entity_Player::AnimateLightTravel() { PlayExtraAnimation("LightTravel"); } void Entity_Player::AnimateAppear() { reconstruction_missing("Entity_Player::AnimateAppear 007abcb0"); } -void Entity_Player::AnimateTeleport(bool) { reconstruction_missing("Entity_Player::AnimateTeleport 007abcc0"); } void Entity_Player::AddPrettyFly() { reconstruction_missing("Entity_Player::AddPrettyFly 007abdf0"); } void Entity_Player::TryRemoveTrinketCostume(int) { @@ -136,12 +117,6 @@ Entity_Laser* Entity_Player::FireDelayedBrimstone(float, Entity*) { reconstruction_missing("Entity_Player::FireDelayedBrimstone 007bf1a0"); } -void Entity_Player::AddBlueSpider(Vector) { reconstruction_missing("Entity_Player::AddBlueSpider 007bf5f0"); } -Entity_Familiar* Entity_Player::ThrowBlueSpider(Vector, Vector) -{ - reconstruction_missing("Entity_Player::ThrowBlueSpider 007bf640"); -} -void Entity_Player::RemoveBlueSpider() { reconstruction_missing("Entity_Player::RemoveBlueSpider 007bf660"); } uint32_t Entity_Player::GetGlitchBabySubType() { reconstruction_missing("Entity_Player::GetGlitchBabySubType 007c2e90"); @@ -149,8 +124,6 @@ uint32_t Entity_Player::GetGlitchBabySubType() void Entity_Player::SetShootingCooldown(int) { reconstruction_missing("Entity_Player::SetShootingCooldown 007c37f0"); } void Entity_Player::add_random_stat_up(RNG*) { reconstruction_missing("Entity_Player::add_random_stat_up 007c3980"); } bool Entity_Player::CanUsePill(int) { reconstruction_missing("Entity_Player::CanUsePill 007c40e0"); } -void Entity_Player::AddDeadEyeCharge() { reconstruction_missing("Entity_Player::AddDeadEyeCharge 007c78b0"); } -void Entity_Player::ClearDeadEyeCharge() { reconstruction_missing("Entity_Player::ClearDeadEyeCharge 007c78e0"); } void Entity_Player::trigger_immaculate_conception(bool) { reconstruction_missing("Entity_Player::trigger_immaculate_conception 007c7d70"); @@ -211,10 +184,6 @@ void Entity_Player::AddGigaBombs(int) { reconstruction_missing("Entity_Player::A void Entity_Player::fire_saturnus_tears() { reconstruction_missing("Entity_Player::fire_saturnus_tears 007d3e40"); } void Entity_Player::get_salvation_scale() { reconstruction_missing("Entity_Player::get_salvation_scale 007d4340"); } void Entity_Player::update_suplex() { reconstruction_missing("Entity_Player::update_suplex 007d4390"); } -uint32_t Entity_Player::bag_of_crafting_collect(Entity_Pickup*) -{ - reconstruction_missing("Entity_Player::bag_of_crafting_collect 007d5170"); -} void Entity_Player::poop_spell_roll() { reconstruction_missing("Entity_Player::poop_spell_roll 007d6670"); } void Entity_Player::UsePoopSpell(uint32_t) { reconstruction_missing("Entity_Player::UsePoopSpell 007d7290"); } void Entity_Player::RecomputeWispCollectibles(Entity_Familiar*) @@ -231,19 +200,10 @@ void Entity_Player::spawn_lil_clot_familiars() reconstruction_missing("Entity_Player::spawn_lil_clot_familiars 007d83f0"); } void Entity_Player::creep_contact_add(int, int) { reconstruction_missing("Entity_Player::creep_contact_add 007d8740"); } -bool Entity_Player::spawn_ghost_corpse() { reconstruction_missing("Entity_Player::spawn_ghost_corpse 007d87a0"); } void Entity_Player::AttachMinecart(Entity_NPC*) { reconstruction_missing("Entity_Player::AttachMinecart 007d9180"); } -void Entity_Player::add_samson_berserk_charge(int) -{ - reconstruction_missing("Entity_Player::add_samson_berserk_charge 007d9200"); -} void Entity_Player::RevivePlayerGhost() { reconstruction_missing("Entity_Player::RevivePlayerGhost 007d93b0"); } void Entity_Player::MorphToCoopGhost() { reconstruction_missing("Entity_Player::MorphToCoopGhost 007d96f0"); } void Entity_Player::reset_body_sprite() { reconstruction_missing("Entity_Player::reset_body_sprite 007d9b70"); } -uint32_t* Entity_Player::CalculateBagOfCraftingOutput(uint32_t*, const char*, bool) -{ - reconstruction_missing("Entity_Player::CalculateBagOfCraftingOutput 007d9d00"); -} void Entity_Player::SpawnClot(Vector, bool) { reconstruction_missing("Entity_Player::SpawnClot 007da810"); } bool Entity_Player::TryForgottenThrow(Vector) { reconstruction_missing("Entity_Player::TryForgottenThrow 007dac80"); } void Entity_Player::ResetPlayer() { reconstruction_missing("Entity_Player::ResetPlayer 007daed0"); } diff --git a/src/entity_player_pockets.cpp b/src/entity_player_pockets.cpp index 0378266..4eaf5d3 100644 --- a/src/entity_player_pockets.cpp +++ b/src/entity_player_pockets.cpp @@ -81,7 +81,6 @@ constexpr int CHALLENGE_RANDOM_POCKETS = 32; constexpr int COLLECTIBLE_ECHO_CHAMBER = 700; constexpr int DELAYED_SFX_FRAMES = 2; constexpr int GULP_UNLOCK_USES = 4; -constexpr int PILL_COLOR_GOLD = 14; constexpr int PLAYING_CARD_EMPTY = 2; constexpr int CARD_HEART_COUNT = 2; constexpr int BOMBS_ARE_KEYS_CHANGED = 0x1e; diff --git a/src/entity_player_weapons.cpp b/src/entity_player_weapons.cpp index ab37df9..180112f 100644 --- a/src/entity_player_weapons.cpp +++ b/src/entity_player_weapons.cpp @@ -81,7 +81,6 @@ constexpr int COLLECTIBLE_EYE_SORE = 558; constexpr int COLLECTIBLE_INNER_EYE = 2; constexpr int COLLECTIBLE_LARGE_ZIT = 502; constexpr int COLLECTIBLE_NEPTUNUS = 597; -constexpr int COLLECTIBLE_THE_WIZ = 358; constexpr int NULLITEM_DARK_ARTS = 111; // The items GetWeaponModifiers turns into modifier bits, in the order it asks. diff --git a/src/entity_projectile.cpp b/src/entity_projectile.cpp index 6254591..bbfe06e 100644 --- a/src/entity_projectile.cpp +++ b/src/entity_projectile.cpp @@ -1,5 +1,6 @@ #include "entity_projectile.h" #include "entity_bomb.h" +#include "entity_combat.h" #include "entity_effect.h" #include "entity_effect_combat.h" #include "entity_familiar.h" @@ -11,6 +12,7 @@ #include "lua_engine.h" #include "manager.h" #include "npc_ai.h" +#include "npc_basement.h" #include "room.h" #include #include @@ -86,6 +88,44 @@ constexpr int ANIM_KEY_CORN = 300; constexpr int ANIM_KEY_COIN = 400; constexpr int ANIM_KEY_MEAT = 600; constexpr int ANIM_KEY_FCUK = 700; +constexpr int ANIM_KEY_ROCK = 500; +constexpr int ANIM_KEY_WING = 800; +constexpr int ANIM_KEY_LAVA = 900; +constexpr int ANIM_KEY_HEAD = 1000; +constexpr int ANIM_KEY_PEEP = 1100; + +// The rock's spin by size, the heads' strip of faces and tilt, and the Peeper's red trail. +constexpr float ROCK_STEP_SCALE = 2; +constexpr int ROCK_STEP_MAX = 6; +constexpr float PEEP_HALF_TURN = 180; +constexpr float PEEP_QUARTER_TURN = 90; +constexpr uint32_t HEAD_FACES = 4; +constexpr float HEAD_FACE_WIDTH = 48; +constexpr float HEAD_TILT = 10; +constexpr float HEAD_SPIN = 2; +constexpr ColorMod PEEP_TRAIL_COLOR = {{0.9f, 0, 0, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr float PEEP_TRAIL_RADIUS = 0.15f; +constexpr float PEEP_TRAIL_ALPHA = 0.5f; + +// The splashes: a thrown grid entity's packed subtype, the rock's poof tint and chips, the meat ball's Globin and the +// head's gibs. +constexpr int GRID_TYPE_SHIFT = 16; +constexpr int GRID_VARIANT_MASK = 0xffff; +constexpr ColorMod ROCK_POOF_COLOR = {{140 / 255.0f, 123 / 255.0f, 123 / 255.0f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr float ROCK_SOUND_MARGIN = -20; +constexpr float ROCK_CHIPS_SCALE = 4; +constexpr int ROCK_CHIPS_MAX = 16; +constexpr float ROCK_CHIP_SPEED = 2; +constexpr int ROCK_CHIP_SUBTYPE = 1; +constexpr float ROCK_CHIP_TURN = 360; +constexpr int MEAT_BURST_SUBTYPE = 2; +constexpr uint32_t MEAT_GAZING_ODDS = 10; +constexpr float MEAT_GLOBIN_PUSH = 0.1f; +constexpr float MEAT_GLOBIN_HEALTH = 24; +constexpr int MEAT_GLOBIN_SHRINK = -150; +constexpr int HEAD_GIBS = 8; +constexpr float HEAD_GIB_SPREAD = 40; +constexpr uint32_t HEAD_GIB_FLAGS = GIB_FLAG_BLOOD | GIB_FLAG_BONE | GIB_FLAG_GUT | GIB_FLAG_EYE; constexpr float DOGMA_DEPTH_OFFSET = 300; constexpr uint64_t DOGMA_ELECTRIC_FLAGS = PROJECTILE_SHIELDED | PROJECTILE_BLUE_FIRE_SPAWN; @@ -236,7 +276,6 @@ constexpr int COLOR_PRIORITY_NONE = -1; constexpr int ENTITY_MR_FRED = 270; constexpr int ENTITY_MEGA_SATAN_2 = 275; -constexpr int ENTITY_RED_GHOST = 285; constexpr int ENTITY_TARBOY = 307; constexpr int ENTITY_NECRO = 828; constexpr int ENTITY_SHADY = 888; @@ -340,6 +379,19 @@ static void layer_additive_set(ANM2& sprite, int layerId) layer->blendMode[BLEND_ALPHA_DEST] = BLEND_FACTOR_ONE; } +// Makes a sprite layer cover what is under it by its alpha (BlendMode::SetMode's normal mode). +static void layer_normal_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_MINUS_SRC_ALPHA; + layer->blendMode[BLEND_ALPHA_SOURCE] = BLEND_FACTOR_ONE; + layer->blendMode[BLEND_ALPHA_DEST] = BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; +} + // Spawns an effect at a position. Game::Spawn returning nothing crashes the original. Callers skip what it sets. static Entity_Effect* effect_spawn(int variant, const Vector& position, Entity* spawner, int subType = 0) { @@ -576,11 +628,49 @@ void Entity_Projectile::animation_update() animKey = ANIM_KEY_FCUK; break; case PROJECTILE_ROCK: + if (animKey == ANIM_KEY_ROCK) break; + std::snprintf(name, sizeof(name), "Rotate%d", + std::min((int)(scale * ROCK_STEP_SCALE + 1), ROCK_STEP_MAX)); + sprite.Play(name); + animKey = ANIM_KEY_ROCK; + break; case PROJECTILE_WING: case PROJECTILE_LAVA: + { + int key = variant == PROJECTILE_WING ? ANIM_KEY_WING : ANIM_KEY_LAVA; + if (animKey != key) + { + sprite.Play("Move"); + sprite.isFlipY = dropRNG._seed & 1; + frame_randomize(); + animKey = key; + if (variant == PROJECTILE_WING) sprite.bitflags |= ANIM_RENDER_STATIC; + sprite.scale = vector_make(scale, scale); + } + sprite.rotation = (vector_angle(velocity) + PEEP_HALF_TURN) * (sprite.isFlipY ? -1 : 1); + break; + } case PROJECTILE_HEAD: + if (animKey == ANIM_KEY_HEAD) break; + sprite.Play("Idle"); + sprite.isFlipX = dropRNG._seed & 1; + sprite.GetLayer(0)->cropOffset.x = (float)dropRNG.RandomInt(HEAD_FACES) * HEAD_FACE_WIDTH; + sprite.rotation = random_unit() * HEAD_TILT * 2 - HEAD_TILT; + animKey = ANIM_KEY_HEAD; + sprite.scale = vector_make(scale, scale); + break; case PROJECTILE_PEEP: - reconstruction_missing("Entity_Projectile::Update 00653070: this projectile variant's animation"); + { + int key = sizeStep + ANIM_KEY_PEEP; + if (animKey != key) + { + std::snprintf(name, sizeof(name), "RegularTear%d", sizeStep); + sprite.Play(name); + animKey = key; + } + peep_update(); + break; + } } // A shot without a config crashes the original here. This leaves its shadow. @@ -611,6 +701,114 @@ void Entity_Projectile::first_frame_update() aura->Update(); } +// The Peeper's eye: it faces along its flight, upright either way, and drags a red trail at half its alpha. +void Entity_Projectile::peep_update() +{ + float angle = vector_angle(velocity); + bool isBackward = angle < -PEEP_QUARTER_TURN || angle > PEEP_QUARTER_TURN; + sprite.isFlipX = isBackward; + sprite.rotation = isBackward ? PEEP_HALF_TURN - angle : angle; + + if (!child) + { + auto* trail = static_cast(g_game->Spawn({.position = pos, .spawner = this, + .type = ENTITY_EFFECT, + .variant = EFFECT_SPRITE_TRAIL, .seed = Random()})); + trail->sprite.color = PEEP_TRAIL_COLOR; + layer_normal_set(trail->sprite, 0); + trail->sprite.scale = vector_make(scale + scale, scale + scale); + trail->SetRadii(PEEP_TRAIL_RADIUS, PEEP_TRAIL_RADIUS); + trail->parent = this; + trail->Update(); + child = trail; + } + + Entity* trail = child.get(); + if (!isVisible) + { + trail->sprite.color._tint[3] = 0; + return; + } + trail->sprite.color._tint[3] = sprite.color._tint[3] * PEEP_TRAIL_ALPHA; + trail->pos = vector_add(pos, posOffset); + trail->velocity = velocity; +} + +// The splash of a thrown grid entity: it breaks where it lands as the rock its subtype packs (type high, variant +// low), keeping the shot's health and seed. +void Entity_Projectile::grid_splash() +{ + sprite.color = COLOR_DEFAULT; + GridEntityDesc desc{}; + desc._type = (int)((uint32_t)subtype >> GRID_TYPE_SHIFT); + desc._variant = subtype & GRID_VARIANT_MASK; + desc._state = (int)health; + desc._spawnSeed = initSeed; + desc._varData = HasEntityFlags(FLAG_NO_DEATH_TRIGGER); + DestroyRockGridAt(pos, &desc, this, wiggleFrameOffset); +} + +// A rock's splash: a poof its size in its own color, and, in the room, a crumble and a handful of rock-tinted chips. +void Entity_Projectile::rock_splash() +{ + ColorMod color = ROCK_POOF_COLOR; + color_multiply(color, sprite.color); + Entity* poof = effect_spawn(EFFECT_ROCK_POOF, pos, this); + poof->posOffset = posOffset; + poof->SetColor(this->color, COLOR_PRIORITY_NONE, COLOR_PRIORITY, false, true); + poof->Update(); + poof->sprite.scale = vector_make(scale, scale); + poof->sprite.rotation = 0; + if (!g_game->room->IsPositionInRoom(pos, ROCK_SOUND_MARGIN)) return; + + sound_play(SOUND_ROCK_CRUMBLE, 1, 1); + int chips = std::min(std::max((int)(scale * ROCK_CHIPS_SCALE * (random_unit() * HALF + 1)), 1), ROCK_CHIPS_MAX); + for (int i = 0; i < chips; i++) + { + Vector direction = vector_from_angle(random_unit() * ROCK_CHIP_TURN); + float speed = random_unit() * ROCK_CHIP_SPEED + 1; + Vector spot = vector_add(pos, vector_scale(direction, random_unit() * size)); + Entity* chip = g_game->Spawn({.position = spot, .velocity = vector_scale(direction, speed), + .subType = ROCK_CHIP_SUBTYPE, .type = ENTITY_EFFECT, + .variant = EFFECT_TOOTH_PARTICLE, .seed = Random()}); + chip->posOffset = posOffset; + chip->SetColor(color, COLOR_PRIORITY_NONE, COLOR_PRIORITY, false, true); + chip->Update(); + } +} + +// A meat ball's splash: a blood burst, then, off the grid, a Globin (one in ten a Gazing one) pulling itself back +// together, shrunk if the shot was. +void Entity_Projectile::meat_splash() +{ + Entity* burst = effect_spawn(EFFECT_BLOOD_EXPLOSION, pos, nullptr, MEAT_BURST_SUBTYPE); + burst->posOffset = posOffset; + sound_play(SOUND_SPLATTER, 1, 1); + if (room_grid_collision_at(pos) != 0) return; + + int globinVariant = initSeed % MEAT_GAZING_ODDS == 0; + auto* globin = static_cast(g_game->Spawn({.position = pos, + .velocity = vector_scale(velocity, MEAT_GLOBIN_PUSH), + .spawner = spawnerEntity, .type = ENTITY_GLOBIN, + .variant = globinVariant, .seed = Random()})); + globin->ClearEntityFlags(FLAG_APPEAR); + globin->health = MEAT_GLOBIN_HEALTH; + globin->sprite.Play("ReGenProjectile"); + globin->state = NPC_STATE_IDLE; + if (HasEntityFlags(FLAG_SHRINK)) globin->AddShrink(EntityRef(this), MEAT_GLOBIN_SHRINK, false); +} + +// A head's splash: a green burst, a small death burst's sound and green gibs. +void Entity_Projectile::head_splash() +{ + Entity* burst = effect_spawn(EFFECT_BLOOD_EXPLOSION, pos, nullptr, BLOOD_EXPLOSION_SPLASH); + burst->SetColor(COLOR_GREEN_SPLAT, COLOR_PRIORITY_NONE, COLOR_PRIORITY, false, true); + burst->Update(); + npc_sound_play(SOUND_DEATH_BURST_SMALL, 1, 2, 1); + gibs_spawn({.color = COLOR_GREEN_SPLAT, .position = pos, .spawner = this, .spread = HEAD_GIB_SPREAD, + .amount = HEAD_GIBS, .gibFlags = HEAD_GIB_FLAGS}); +} + // The trails the late bosses' shots leave, which are not reconstructed. void Entity_Projectile::trails_update() { @@ -631,6 +829,7 @@ void Entity_Projectile::death_update() death_poof_spawn(); death_flags_apply(); death_bursts_spawn(); + if (variant == PROJECTILE_HEAD) head_splash(); Remove(); if (variant == PROJECTILE_FIRE && spawnerType == ENTITY_BEAST) npc_sound_play(SOUND_BEAST_FIRE, 1, 2, 1); } @@ -721,8 +920,9 @@ void Entity_Projectile::death_poof_spawn() .variant = EFFECT_COIN_PARTICLE}); sound_play(SOUND_COIN_IMPACT, random_unit() * COIN_SOUND_PITCH_SPREAD + COIN_SOUND_PITCH, COIN_SOUND_VOLUME); } - else if (variant == PROJECTILE_GRID || variant == PROJECTILE_ROCK || variant == PROJECTILE_MEAT) - reconstruction_missing("Entity_Projectile::Update 00653070: this projectile variant's splash"); + else if (variant == PROJECTILE_GRID) grid_splash(); + else if (variant == PROJECTILE_ROCK) rock_splash(); + else if (variant == PROJECTILE_MEAT) meat_splash(); if (!(projectileFlags & PROJECTILE_EXPLODE) && (projectileFlags & PROJECTILE_CREEP_BROWN)) { @@ -1184,6 +1384,7 @@ void Entity_Projectile::fall_update() fallingSpeed = speedMultiplier * fallingAccel + speedMultiplier * GRAVITY_PULL + timescale_factor(FALL_DRAG, speedMultiplier) * fallingSpeed; height = fallingSpeed * speedMultiplier + height; + if (variant == PROJECTILE_HEAD) sprite.rotation = angle_wrap(sprite.rotation + fallingSpeed * HEAD_SPIN); if (!is_crawlspace()) return; if (fallingAccel >= CRAWLSPACE_MIN_ACCEL) velocity.y = fallingAccel * speedMultiplier + velocity.y; diff --git a/src/entity_projectile.h b/src/entity_projectile.h index 1fd88a2..123adbc 100644 --- a/src/entity_projectile.h +++ b/src/entity_projectile.h @@ -161,11 +161,16 @@ private: bool modem_freeze_update(); void animation_update(); void first_frame_update(); + void peep_update(); void trails_update(); void death_update(); void death_poof_spawn(); void death_flags_apply(); void death_bursts_spawn(); + void grid_splash(); + void rock_splash(); + void meat_splash(); + void head_splash(); void homing_update(); void orbit_update(); void steering_update(); diff --git a/src/entity_slot.cpp b/src/entity_slot.cpp index 45c3b9b..6eb19b7 100644 --- a/src/entity_slot.cpp +++ b/src/entity_slot.cpp @@ -7,14 +7,17 @@ #include "entity_player.h" #include "game.h" #include "grid_entity_door.h" +#include "hud.h" #include "log.h" #include "manager.h" #include "npc_basement.h" #include "npc_caves.h" #include "persistent_game_data.h" #include "room.h" +#include "room_config.h" #include "room_grid.h" #include "room_render.h" +#include "room_special.h" #include #include @@ -151,6 +154,13 @@ constexpr float FORTUNE_CHANCE = 0.65f; constexpr float HARD_FORTUNE_CHANCE = 0.85f; constexpr float LUCKY_FORTUNE = 0.46f; constexpr float SEED_FORTUNE_CHANCE = 0.002f; + +// A full restock: the scale of a spawn's pick, the reach inside which pickups are pushed aside, how far, and how long +// they wait before they can be taken. +constexpr float SPAWN_PICK_SCALE = 2.3283062e-10f; +constexpr float RESTOCK_CLEAR_SQUARED = 900; +constexpr float RESTOCK_ASIDE_STEP = 10; +constexpr int RESTOCK_PICKUP_WAIT = 20; constexpr float CONFESSIONAL_CHANCE = 0.3f; constexpr float HARD_CONFESSIONAL_CHANCE = 0.25f; constexpr float LUCKY_CONFESSIONAL = 1.5f; @@ -252,17 +262,60 @@ static Vector throw_velocity_get(const Vector& from, RNG* rng) return velocity; } -// Game::ShowFortuneText 009807a0: a random line of a fortune category on the fortune paper. -static void fortune_show(const char* category) +// 00815ae0 (Room::ShopRestockFull) Restocks a shop or black market: forgets the bought-out slots, chooses its wares +// again, takes away every ware still for sale and spawns each shop spot of the room's layout anew in a poof, pushing +// any pickup lying there aside. Elsewhere the first player rolls the room's pedestals with the D6. +void room_shop_restock_full() { - reconstruction_missing(category[8] == 'S' ? "Game::ShowFortuneText 009807a0 (Fortune_Seeds)" - : "Game::ShowFortuneText 009807a0 (Fortune_General)"); -} + Room& room = *g_game->room; + if (room.roomType != ROOM_SHOP && room.roomType != ROOM_BLACK_MARKET) + { + g_game->GetPlayer(0)->UseActiveItem({.item = COLLECTIBLE_D6, .flags = USE_NOANIM}); + return; + } -// Room::ShopRestockFull 00815ae0: restocks every shop item in the room. -static void room_shop_restock_full() -{ - reconstruction_missing("Room::ShopRestockFull 00815ae0"); + room.shopRestockTimer = -1; + room.shopRestocks.clear(); + room_shop_slots_init(room); + RNG rng = {room.descriptor->spawnSeed, 2, 7, 7}; + log_printf(LOG_INFO, "SpawnRNG seed: %u\n", rng._seed); + for (Entity* entity : entity_query(ENTITY_PICKUP, -1)) + if (static_cast(entity)->price != 0) entity->Remove(); + + RoomConfig_Room& layout = *room.descriptor->data; + for (RoomSpawn& spawn : layout.spawns) + { + uint32_t seed = rng.Next(); + int gridIndex = (spawn.x + 1) + (spawn.y + 1) * room.gridWidth; + if (spawn.entries.empty()) continue; + + RoomEntry entry = *spawn.PickEntry((float)seed * SPAWN_PICK_SCALE); + room_entry_transform(room, entry, gridIndex, seed); + if (entry.type != ENTITY_PICKUP || entry.variant != PICKUP_SHOPITEM) continue; + + Vector position = room.GetGridPosition(gridIndex); + if ((uint32_t)gridIndex < ROOM_GRID_CELLS && room.gridEntities[gridIndex]) + room.gridEntities[gridIndex]->Destroy(true, EntityRef()); + for (Entity* pickup : entity_query(ENTITY_PICKUP, -1)) + { + if (vector_length_squared(vector_sub(position, pickup->pos)) >= RESTOCK_CLEAR_SQUARED) continue; + + Vector aside = room_free_pickup_position_find({.position = position, .step = RESTOCK_ASIDE_STEP}); + pickup->pos = aside; + pickup->targetPosition = aside; + static_cast(pickup)->wait = RESTOCK_PICKUP_WAIT; + } + RNG wareRng = {seed, 5, 9, 7}; + Entity* ware = g_game->Spawn({.position = position, + .subType = entry.subtype, + .type = (int)entry.type, + .variant = entry.variant, + .seed = wareRng.Next()}); + ware->spawnGridIndex = gridIndex; + g_game->Spawn({.position = position, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); + log_printf(LOG_INFO, "Spawn Entity with Type(%d), Variant(%d), Pos(%.2f,%.2f)\n", (int)entry.type, + (int)entry.variant, (double)position.x, (double)position.y); + } } // A Battery Bum's charge (the timer callback 0065d930 and FUN_007919c0): one charge to its player's active items, @@ -903,7 +956,7 @@ void Entity_Slot::fortune_pay(Entity_Player& player, RNG& prizeRng, int count) (player.HasTrinket(TRINKET_POKER_CHIP) && dropRNG.RandomInt(5) == 0); if (isLucky) chance *= LUCKY_FORTUNE; float roll = dropRNG.RandomFloat(); - if (roll < chance) return fortune_show(roll >= SEED_FORTUNE_CHANCE ? "Fortune_General" : "Fortune_Seeds"); + if (roll < chance) return fortune_show(roll >= SEED_FORTUNE_CHANCE ? FORTUNE_GENERAL : FORTUNE_SEEDS); npc_sound_play(SOUND_SLOTSPAWN, 1, 2, 1); if (dropRNG.RandomInt(20) == 0) return explode(); diff --git a/src/entity_slot.h b/src/entity_slot.h index 1ea0178..38c74d2 100644 --- a/src/entity_slot.h +++ b/src/entity_slot.h @@ -110,3 +110,4 @@ private: Vector room_pickup_position_random(bool isAvoidActiveEntities, bool isAllowPits); Vector collectible_spawn_position(Vector target); +void room_shop_restock_full(); diff --git a/src/entity_tear.cpp b/src/entity_tear.cpp index 4f4ba69..e4ad161 100644 --- a/src/entity_tear.cpp +++ b/src/entity_tear.cpp @@ -1,6 +1,7 @@ #include "entity_tear.h" #include "entity_effect.h" #include "entity_familiar.h" +#include "entity_laser.h" #include "entity_player.h" #include "game.h" #include "grid_entity.h" @@ -38,6 +39,7 @@ 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; +constexpr float FULL_TURN = 360; // 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; @@ -116,6 +118,65 @@ constexpr float PULSE_STRENGTH = 0.3f; constexpr float PULSE_RATE = 0.7f; constexpr float PULSE_BASE = 0.6f; constexpr float PULSE_OFFSET = 0.7f; + +// Technology Zero: the reach it links another tear within, its electric beam's lift, life and share of the damage. +constexpr float TECH_ZERO_REACH = 350; +constexpr float TECH_ZERO_REACH_SQUARED = 129600; +constexpr float TECH_ZERO_LIFT = -15; +constexpr int TECH_ZERO_TIMEOUT = 3; +constexpr float TECH_ZERO_DAMAGE = 0.3f; + +// Eye of the Occult: Marked's pull share, the steering's strength (less under Ludovico or a boomerang) and drags. +constexpr float OCCULT_MARKED_SHARE = 10; +constexpr float OCCULT_STEER = 3; +constexpr float OCCULT_LUDOVICO_SCALE = 0.4f; +constexpr float OCCULT_BOOMERANG_SCALE = 0.5f; +constexpr float OCCULT_FRICTION = 0.8f; +constexpr float OCCULT_HOMING_FRICTION = 0.9f; + +// Ludovico's tears: the circling and Monstro's Lung's ones (and their own bit), the fast one, their drag, the reach +// of their hits' refresh without a player, a fast tear's speed bonus and Spectral, the familiar's smaller tear, the +// circling tears' ring and spin, the cloud's sway, a familiar tear's push off another, and the fast tear's leash. +constexpr int LUDOVICO_LUNG_BIT = 1; +constexpr int LUDOVICO_FAST = 2; +constexpr int LUDOVICO_CHILD = 4; +constexpr float LUDOVICO_FRICTION = 0.7f; +constexpr float LUDOVICO_FAST_FRICTION = 0.98f; +constexpr float LUDOVICO_INTERVAL_DEFAULT = 10; +constexpr float LUDOVICO_FAMILIAR_SCALE = 0.75f; +constexpr float LUDOVICO_FAST_SPEED_MIN = 10; +constexpr float LUDOVICO_FAST_SPEED_MAX = 20; +constexpr float LUDOVICO_FAST_SCALE_MIN = 0.9f; +constexpr float LUDOVICO_FAST_SCALE_MAX = 2; +constexpr float LUDOVICO_FAST_DAMAGE_MAX = 6; +constexpr float LUDOVICO_FAST_BONUS_SPEED = 15; +constexpr float LUDOVICO_GROW_REACH = 700; +constexpr float LUDOVICO_SHRINK_SPAN = 900; +constexpr float LUDOVICO_OCCULT_SPEED = 10; +constexpr uint32_t LUDOVICO_OCCULT_FIRE_FLAGS = 7; +constexpr float LUDOVICO_ORBIT_SPIN = 5; +constexpr int LUDOVICO_RING_GROW_FRAMES = 50; +constexpr float LUDOVICO_CHILD_SCALE = 0.5f; +constexpr float LUDOVICO_SWAY_RATE = 0.08f; +constexpr float LUDOVICO_SWAY_INDEX = 50; +constexpr float LUDOVICO_SWAY = 0.5f; +constexpr float LUDOVICO_DRIFT_STEP = 0.1f; +constexpr float LUDOVICO_DRIFT_BASE = -4; +constexpr float LUDOVICO_DRIFT_HALF = 0.5f; +constexpr float LUDOVICO_DRIFT_HALF_BASE = 2; +constexpr int LUDOVICO_DRIFT_SPREAD = 10; +constexpr float LUDOVICO_SPACING = 24; +constexpr float LUDOVICO_SPACING_PUSH = 4; +constexpr float LUDOVICO_LEASH_SQUARED = 1600; +constexpr float LUDOVICO_LEASH_FRICTION = 0.9f; +constexpr float LUDOVICO_LEASH_PULL = 0.1f; + +// The tear variants that keep their own sprite through a Ludovico variant change, and those whose sprite turns with +// their rotation. +constexpr std::array TEAR_OWN_SPRITE_VARIANTS = {TEAR_TOOTH, TEAR_STONE, TEAR_BOOGER, TEAR_EGG, + TEAR_RAZOR, TEAR_BONE, TEAR_BLACK_TOOTH, TEAR_SPORE}; +constexpr std::array TEAR_TURNED_VARIANTS = {TEAR_FIRE_MIND, TEAR_DARK_MATTER, TEAR_MYSTERIOUS, + TEAR_COIN, TEAR_EYE, TEAR_EYE_BLOOD}; constexpr float SQUARE_SPEED_SHARE = 0.5f; constexpr float BOOMERANG_REACH_SHARE = 0.5f; constexpr float FLAT_STRETCH = 0.5f; @@ -270,10 +331,8 @@ struct UnhandledFlag const char* name = nullptr; }; -constexpr std::array UPDATE_UNHANDLED_FLAGS = {{ - {TEAR_LUDOVICO, "Entity_Tear::Update 006670f0: a Ludovico tear"}, +constexpr std::array UPDATE_UNHANDLED_FLAGS = {{ {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"}, @@ -281,7 +340,6 @@ constexpr std::array UPDATE_UNHANDLED_FLAGS = {{ {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"}, @@ -291,7 +349,6 @@ constexpr std::array UPDATE_UNHANDLED_FLAGS = {{ {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"}, @@ -380,10 +437,10 @@ static void streak_end(Entity_Player& player) 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) +// Vector::Rotated: a vector turned by an angle in degrees. +static Vector vector_rotate(Vector v, float degrees) { - float angle = RIGHT_ANGLE * DEGREES_TO_RADIANS; + float angle = degrees * 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)); } @@ -481,6 +538,7 @@ void Entity_Tear::Update() play_fire_sound(); isFireSoundPending = false; } + if (tearFlags[TEAR_LUDOVICO] && (subtype & LUDOVICO_CHILD) && !parent) return Remove(); if (!is_listed(TEAR_PLAIN_VARIANTS, variant)) reconstruction_missing("Entity_Tear::Update 006670f0: this tear variant's flight and splash"); @@ -489,7 +547,8 @@ void Entity_Tear::Update() if (room.HasSlowDown()) speedMultiplier *= ROOM_SLOWDOWN_SCALE; if (hold_update()) return; - if (is_crawlspace() && height >= CRAWLSPACE_HEIGHT_MAX && updateTime > tearRange * CRAWLSPACE_RANGE_SHARE) + if (is_crawlspace() && height >= CRAWLSPACE_HEIGHT_MAX && updateTime > tearRange * CRAWLSPACE_RANGE_SHARE && + !tearFlags[TEAR_LUDOVICO]) { isDead = true; deathFlags = TEAR_DEATH_FORCED; @@ -498,6 +557,7 @@ void Entity_Tear::Update() unhandled_check(tearFlags, UPDATE_UNHANDLED_FLAGS); wait_update(); death_creep_spawn(); + tech_zero_update(); if (laserShotLaser) { isVisible = true; @@ -716,6 +776,7 @@ void Entity_Tear::flight_update() Entity_Player* player = GetRootPlayer(); square_turn(); homing_update(); + occult_steer(); float scaleFactor = size_flags_update(); spectral_update(); boomerang_pull(); @@ -734,9 +795,13 @@ void Entity_Tear::flight_update() 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(); + tractor_beam_follow(); + bool isLudovico = tearFlags[TEAR_LUDOVICO]; + bool isBouncing = tearFlags[TEAR_BOUNCE] || variant == TEAR_FIRE; + if (height > TEAR_FLOOR_HEIGHT && !isLudovico) floor_hit(); + else if ((isBouncing && !g_game->room->IsBeastDungeon()) || (isLudovico && (subtype & LUDOVICO_FAST))) bounce_hit(); else grid_hit(); + if (isLudovico) scaleFactor *= ludovico_update(); if (g_game->deathmatchManager.is_active()) reconstruction_missing("Entity_Tear::Update 006670f0: the versus mode's tear reflections"); @@ -748,8 +813,294 @@ void Entity_Tear::flight_update() Vector previous = pos; Entity::Update(); turn_horizontal_update(previous); + if (isLudovico && is_not_familiar_spawned() && !tearFlags[TEAR_CONTINUUM]) pos = g_game->room->GetClampedPosition(pos, 0); posDisplacement = vector_sub(pos, previous); - fall_update(); + if (!isLudovico) fall_update(); +} + +// Technology Zero: a tear links to the nearest other tear (one not linked back to it) with an electric beam its player +// fires, which follows it toward the other tear, breaks past 350 and goes when either dies. Without the beam the tear +// loses the flag. +void Entity_Tear::tech_zero_update() +{ + if (!tearFlags[TEAR_LASER]) return; + Entity_Player* player = GetRootPlayer(); + bool isNew = false; + if (!techZeroTarget) + { + Entity_Tear* nearest = nullptr; + float best = TECH_ZERO_REACH_SQUARED; + for (Entity* other : entity_query_radius(pos, TECH_ZERO_REACH, QUERY_TEARS)) + { + if (other == this || other->type != ENTITY_TEAR) continue; + float distance = vector_length_squared(vector_sub(other->pos, pos)); + if (distance >= best) continue; + nearest = other->ToTear(); + best = distance; + } + if (nearest && nearest->techZeroTarget.get() != this && player) + { + if (!techZeroLaser) + { + Vector toTarget = vector_sub(vector_add(nearest->pos, nearest->posOffset), vector_add(vector_add(pos, velocity), posOffset)); + Entity_Laser* laser = Entity_Laser::ShootAngle({.position = pos, .posOffset = vector_make(0, TECH_ZERO_LIFT), + .source = player, .angleDegrees = vector_angle(toTarget), + .timeout = TECH_ZERO_TIMEOUT, .variant = LASER_ELECTRIC, + .isPoolKept = true}); + if (!laser) + { + tearFlags.reset(TEAR_LASER); + techZeroTarget = nullptr; + return; + } + TearParams params = player->GetTearHitParams(WEAPON_LASER, 1, random_below(2) * 2 - 1, nullptr); + laser->SetCollisionDamage(params.tearDamage * TECH_ZERO_DAMAGE); + laser->set_scale(params.tearScale); + laser->subtype = LASER_SUBTYPE_NO_IMPACT; + laser->tearFlags = TearFlags().set(TEAR_SPECTRAL); + laser->mass = 0; + laser->parent = this; + laser->isDisableFollowParent = true; + techZeroLaser = laser; + isNew = true; + } + techZeroTarget = nearest; + } + } + + Entity* linked = techZeroTarget; + if (techZeroLaser && (isDead || !linked || linked->isDead)) + { + techZeroLaser->Remove(); + techZeroLaser = nullptr; + techZeroTarget = nullptr; + return; + } + if (!techZeroLaser || !linked) return; + tech_zero_aim(); + auto& laser = *static_cast(techZeroLaser.get()); + laser.timeout = TECH_ZERO_TIMEOUT; + if (laser.maxDistance > TECH_ZERO_REACH) laser.Remove(); + if (isNew) laser.Update(); +} + +// Points Technology Zero's beam from the tear's next spot at its linked tear, as long as the gap. +void Entity_Tear::tech_zero_aim() +{ + auto& laser = *static_cast(techZeroLaser.get()); + Entity* linked = techZeroTarget; + Vector from = vector_add(vector_add(pos, velocity), posOffset); + Vector toTarget = vector_sub(vector_add(linked->pos, linked->posOffset), from); + laser.set_aim_angle(vector_angle(toTarget)); + laser.maxDistance = vector_length(toTarget); + laser.pos = vector_sub(from, laser.posOffset); +} + +// Tractor Beam: a tear its player fired (not Ludovico's, nor one stuck in an enemy) rides the player's beam, at its +// distance and speed along it, a boomerang coming back the other way. +void Entity_Tear::tractor_beam_follow() +{ + Entity* owner = parent; + if (!tearFlags[TEAR_TRACTOR_BEAM] || tearFlags[TEAR_LUDOVICO] || !owner || !owner->is_player() || stickTarget) return; + Entity* beam = owner->ToPlayer()->tractorBeam; + if (!beam || beam->type != ENTITY_LASER) return; + + Vector offset = vector_sub(pos, owner->pos); + float way = tearFlags[TEAR_BOOMERANG] && vector_dot(velocity, offset) < 0 ? -1 : 1; + Vector along = vector_from_angle(static_cast(beam)->angleDegrees); + velocity = vector_scale(along, vector_length(velocity) * way); + pos = vector_add(owner->pos, vector_scale(along, vector_length(offset))); +} + +// Eye of the Occult: a flying tear (not Ludovico's or a fetus) is steered by its player's shots, or pulled toward +// Marked's target, and drags harder. Without a steer a boomerang tear keeps its speed and a homing one drags less. +void Entity_Tear::occult_steer() +{ + Entity_Player* player = GetRootPlayer(); + if (!tearFlags[TEAR_OCCULT] || tearFlags[TEAR_LUDOVICO] || tearFlags[TEAR_FETUS_FLAG] || !player) return; + + Vector aim{}; + if (Entity* marked = player->markedTarget) + { + aim = vector_scale(vector_sub(marked->pos, pos), 1 / OCCULT_MARKED_SHARE); + if (vector_length(aim) > 1) aim = vector_normalized(aim); + } + else + { + aim = player->GetShootingJoystick(); + player->GetMouseAimTarget(aim, false); + } + float steer = player->shotSpeed * OCCULT_STEER; + if (player->HasWeaponType(WEAPON_LUDOVICO_TECHNIQUE)) steer *= OCCULT_LUDOVICO_SCALE; + else if (tearFlags[TEAR_BOOMERANG]) steer *= OCCULT_BOOMERANG_SCALE; + + if (!vector_is_zero(aim)) velocity = vector_add(velocity, vector_scale(vector_normalized(aim), steer)); + else if (tearFlags[TEAR_BOOMERANG]) + { + friction = 1; + return; + } + else if (tearFlags[TEAR_HOMING]) + { + friction = OCCULT_HOMING_FRICTION; + return; + } + friction = OCCULT_FRICTION; +} + +// Switches the tear to another variant, reloading its config and sprite unless the variant keeps its own. +void Entity_Tear::variant_switch(int newVariant, bool isTurnReset) +{ + variant = newVariant; + if (is_listed(TEAR_OWN_SPRITE_VARIANTS, variant)) return; + + LoadEntityConfig(); + if (isTurnReset) entityGridCollisionClass = GRIDCOLL_NONE; + if (!config) return; + sprite.Load(config->anm2Path, GRAPHICS_LOAD); + sprite.Play(sprite.GetDefaultAnimationName()); + if (isTurnReset) sprite.rotation = 0; + ResetSpriteScale(); +} + +// Ludovico's main tear on its interval: its hits refresh, the grid it touches breaks, and it takes the player's +// Ludovico tear afresh (its variant, damage, color and flags; a fast tear hits harder and flies over the grid), +// Lump of Coal and Proptosis scaling the damage by its distance from its parent, and Eye of the Occult fires a tear +// from it in a random direction per tick while the player shoots. +void Entity_Tear::ludovico_refresh(Entity_Player* player, float speed, int ticks) +{ + hitList.clear(); + try_make_bridges(pos); + if (!player) return; + + TearParams params = player->GetTearHitParams(WEAPON_LUDOVICO_TECHNIQUE, 1, random_below(2) * 2 - 1, spawnerEntity); + stickTimer = 0; + if (variant != params.tearVariant) variant_switch(params.tearVariant, true); + if ((subtype & LUDOVICO_FAST) && speed > LUDOVICO_FAST_SPEED_MIN) + { + params.tearDamage *= lerp_clamped(speed, LUDOVICO_FAST_SPEED_MIN, LUDOVICO_FAST_SPEED_MAX, 1, LUDOVICO_FAST_DAMAGE_MAX); + params.tearDamage += lerp_clamped(speed, LUDOVICO_FAST_SPEED_MIN, LUDOVICO_FAST_BONUS_SPEED, 0, LUDOVICO_FAST_DAMAGE_MAX); + params.tearFlags.set(TEAR_SPECTRAL); + } + collisionDamage = params.tearDamage; + SetColor(params.tearColor, -1, COLOR_PRIORITY_TOP, false, true); + TearFlags flags = params.tearFlags; + flags.reset(TEAR_BOUNCE); + flags.set(TEAR_LUDOVICO); + SetTearFlags(flags); + + if (is_not_familiar_spawned() && parent) + { + float distance = vector_length(vector_sub(parent->pos, pos)); + if (tearFlags[TEAR_GROW]) collisionDamage *= std::clamp(distance, 1.0f, LUDOVICO_GROW_REACH) / LUDOVICO_GROW_REACH + 1; + if (tearFlags[TEAR_SHRINK]) + collisionDamage *= 1 - std::clamp(distance, 0.0f, LUDOVICO_GROW_REACH) / LUDOVICO_SHRINK_SPAN; + } + if (!tearFlags[TEAR_OCCULT] || player->fireDirection == DIRECTION_NONE) return; + for (int i = 0; i < ticks; i++) + player->FireTear({pos, vector_scale(random_direction(), player->shotSpeed * LUDOVICO_OCCULT_SPEED)}, + LUDOVICO_OCCULT_FIRE_FLAGS, this, 1); +} + +// A tear circling Ludovico's main tear or in Monstro's Lung's cloud: it takes the main tear's variant, turns its +// sprite, a cloud tear sways around it, and one without a parent goes. +void Entity_Tear::ludovico_child_update() +{ + Entity* main = parent; + if (main && main->type == ENTITY_TEAR && variant != main->variant) variant_switch(main->variant, false); + if (is_listed(TEAR_TURNED_VARIANTS, variant) || tearFlags[TEAR_FLAT]) sprite.rotation = rotation; + if ((subtype & LUDOVICO_LUNG_BIT) && main) + { + float sway = std::sin(((float)FrameCount() + (float)index * LUDOVICO_SWAY_INDEX) * LUDOVICO_SWAY_RATE); + pos = vector_add(main->pos, vector_resized(parentOffset, vector_length(parentOffset) * (sway * LUDOVICO_SWAY + 1))); + float drift = ((float)(index % LUDOVICO_DRIFT_SPREAD) + 0) * LUDOVICO_DRIFT_STEP + LUDOVICO_DRIFT_BASE; + parentOffset = vector_rotate(parentOffset, drift); + } + if (!parent) Remove(); +} + +// Ludovico's main tear keeps the tears chained from it on a ring around it (growing over their first frames), sized, +// colored and flagged like it. A familiar's tear keeps off the other ones, a fast one is leashed to its parent, and a +// player who lost Ludovico takes the ring away. +void Entity_Tear::ludovico_ring_update() +{ + std::vector ring; + for (Entity* link = child; link; link = link->child) ring.push_back(static_cast(link)); + for (size_t i = 0; i < ring.size(); i++) + { + Entity_Tear& orbiter = *ring[i]; + orbiter.velocity = velocity; + float angle = (float)i * FULL_TURN / (float)ring.size() + (float)FrameCount() * LUDOVICO_ORBIT_SPIN; + float radius = size + size; + if (orbiter.FrameCount() < LUDOVICO_RING_GROW_FRAMES) radius *= (float)orbiter.FrameCount() / LUDOVICO_RING_GROW_FRAMES; + Vector spot = vector_add(pos, vector_scale(vector_from_angle(angle), radius)); + orbiter.AddVelocity_divided(vector_sub(spot, orbiter.pos), false); + orbiter.SetScale(fScale * LUDOVICO_CHILD_SCALE); + orbiter.SetColor(sprite.color, -1, COLOR_PRIORITY_TOP, false, true); + TearFlags flags = tearFlags; + flags.reset(TEAR_EXPLOSIVE); + orbiter.SetTearFlags(flags); + orbiter.entityGridCollisionClass = GRIDCOLL_NONE; + orbiter.SetCollisionDamage(collisionDamage); + orbiter.rotation = angle_wrap(angle + RIGHT_ANGLE); + } + + if (parent && parent->IsFamiliar()) + for (Entity* other : entity_query_radius(pos, LUDOVICO_SPACING, QUERY_TEARS)) + { + Entity_Tear* tear = other->ToTear(); + if (!tear || tear == this || !tear->tearFlags[TEAR_LUDOVICO] || !tear->is_not_familiar_spawned()) continue; + Vector away = vector_sub(pos, tear->pos); + float distance = vector_length(away); + float push = distance >= LUDOVICO_SPACING ? 0 : LUDOVICO_SPACING_PUSH / (distance + 1); + if (vector_is_zero(away)) away = random_direction(); + if (push > 0) AddVelocity_divided(vector_scale(vector_normalized(away), push), false); + } + + // The original reads the parent without checking for one: a tear without one keeps its ring. + if (!parent) return; + if (subtype & LUDOVICO_FAST) + { + Vector toParent = vector_sub(parent->pos, pos); + if (vector_length_squared(toParent) <= LUDOVICO_LEASH_SQUARED) friction *= LUDOVICO_LEASH_FRICTION; + else AddVelocity_divided(vector_scale(vector_normalized(toParent), LUDOVICO_LEASH_PULL), false); + return; + } + if (!parent->is_player() || parent->ToPlayer()->HasWeaponType(WEAPON_LUDOVICO_TECHNIQUE)) return; + for (Entity* link = child; link;) + { + Entity* next = link->child; + link->Remove(); + link = next; + } +} + +// A Ludovico tear's frame: it drags (less when fast), loses Flat Worm's stretch, and the main tear refreshes on its +// player's fire delay and keeps its ring, the others follow it. A familiar's tear is smaller and a fast one grows with +// its speed. The factor its scale draws at. +float Entity_Tear::ludovico_update() +{ + bool isMain = is_not_familiar_spawned(); + float speed = vector_length(velocity); + float scaleFactor = 1; + friction *= (subtype & LUDOVICO_FAST) ? LUDOVICO_FAST_FRICTION : LUDOVICO_FRICTION; + Entity_Player* player = GetRootPlayer(); + // The original reads a missing player's trinkets here and crashes: a tear without one loses the stretch too. + if (tearFlags[TEAR_FLAT]) + { + sizeMulti = vector_make(1, 1); + tearFlags.flip(TEAR_FLAT); + } + if (parent && parent->IsFamiliar()) scaleFactor *= LUDOVICO_FAMILIAR_SCALE; + if (subtype & LUDOVICO_FAST) + scaleFactor *= lerp_clamped(speed, LUDOVICO_FAST_SPEED_MIN, LUDOVICO_FAST_SPEED_MAX, LUDOVICO_FAST_SCALE_MIN, + LUDOVICO_FAST_SCALE_MAX); + + int ticks = GetIntervalTicks(player ? player->maxFireDelay : LUDOVICO_INTERVAL_DEFAULT, 0); + if (ticks != 0) ludovico_refresh(player, speed, ticks); + if (isMain) ludovico_ring_update(); + else ludovico_child_update(); + return scaleFactor; } // Hook Worm: from its third frame the tear turns a right angle (its first one), then keeps turning left and right on @@ -827,12 +1178,13 @@ void Entity_Tear::homing_update() float Entity_Tear::size_flags_update() { float scaleFactor = 1; - if (tearFlags[TEAR_GROW] && waitFrames < 1) + bool isLudovico = tearFlags[TEAR_LUDOVICO]; + if (tearFlags[TEAR_GROW] && waitFrames < 1 && !isLudovico) { collisionDamage += vector_length(posDisplacement) * GROW_DAMAGE; baseScale += GROW_SCALE; } - if (tearFlags[TEAR_SHRINK] && waitFrames < 1 && updateTime > SHRINK_START) + if (tearFlags[TEAR_SHRINK] && waitFrames < 1 && updateTime > SHRINK_START && !isLudovico) { float rate = baseDamage / SHRINK_FAST_SHARE < collisionDamage ? SHRINK_FAST : SHRINK_SLOW; collisionDamage = std::max(collisionDamage - rate * baseDamage, SHRINK_DAMAGE_MIN); @@ -941,7 +1293,8 @@ void Entity_Tear::grid_hit() bool isPlayerWall = collision == COLLISION_WALL_EXCEPT_PLAYER && gridPath < GRID_PATH_TEAR_WALL; if (!isCollidesWithGrid) return; - if (height <= TEAR_GRID_HIT_HEIGHT && !isWall && !isPlayerWall) return; + bool isBlockedOnly = height <= TEAR_GRID_HIT_HEIGHT || tearFlags[TEAR_LUDOVICO]; + if (isBlockedOnly && !isWall && !isPlayerWall) return; if (tearFlags[TEAR_SPECTRAL] && variant != TEAR_BOBS_HEAD) return; isDead = true; @@ -989,7 +1342,7 @@ void Entity_Tear::turn_horizontal_update(Vector previous) if (after < TURN_AWAY && before < TURN_AWAY && !tearFlags[TEAR_HOMING]) target = nullptr; return; } - Vector turned = vector_quarter_turn(direction); + Vector turned = vector_rotate(direction, RIGHT_ANGLE); if (vector_dot(turned, toTarget) < 0) turned = vector_scale(turned, -1); velocity = vector_scale(turned, vector_length(velocity)); tearFlags.reset(TEAR_TURN_HORIZONTAL); @@ -1015,8 +1368,10 @@ void Entity_Tear::fall_update() 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"); + if (tearFlags[TEAR_HYDROBOUNCE]) reconstruction_missing("Entity_Tear::Interpolate 00679400: the tear flags' motion"); + tractor_beam_follow(); + if (tearFlags[TEAR_LASER] && techZeroLaser && techZeroTarget) tech_zero_aim(); + if (tearFlags[TEAR_LUDOVICO]) return ludovico_interpolate(); Entity_Player* player = GetRootPlayer(); if (tearFlags[TEAR_WIGGLE]) wiggle_apply(worm_multiplier_get(player, TEAR_WIGGLE)); @@ -1028,6 +1383,34 @@ void Entity_Tear::Interpolate() : get_height_offset_y(fallingSpeed * speedMultiplier * 0.5f + height); } +// The Ludovico part of 00679400: a fast tear may skip a step, the tear moves half its step, the main tear stays in +// the room (unless it wraps) and a cloud tear sways around the main one. Its height stays. +void Entity_Tear::ludovico_interpolate() +{ + if ((subtype & LUDOVICO_FAST) && HasEntityFlags(FLAG_NO_INTERPOLATE)) + { + ClearEntityFlags(FLAG_NO_INTERPOLATE); + return; + } + preInterpolatePos = pos; + pos = vector_add(pos, vector_scale(velocity, friction * speedMultiplier * HALF_FRAME)); + isInterpolating = true; + + Entity* main = parent; + if (!main || main->type != ENTITY_TEAR) + { + if (!tearFlags[TEAR_CONTINUUM]) pos = g_game->room->GetClampedPositionImpl(pos, 0, 0, 0, 0); + } + else if (subtype & LUDOVICO_LUNG_BIT) + { + float drift = (float)(index % LUDOVICO_DRIFT_SPREAD) * LUDOVICO_DRIFT_STEP * LUDOVICO_DRIFT_HALF + LUDOVICO_DRIFT_HALF_BASE; + Vector offset = vector_rotate(parentOffset, drift); + float frame = (float)(g_game->frameCount - spawnFrame) + HALF_FRAME + (float)index * LUDOVICO_SWAY_INDEX; + float sway = std::sin(frame * LUDOVICO_SWAY_RATE); + pos = vector_add(main->pos, vector_resized(offset, vector_length(offset) * (sway * LUDOVICO_SWAY + 1))); + } +} + // 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) { diff --git a/src/entity_tear.h b/src/entity_tear.h index 3254d4a..b9e10a1 100644 --- a/src/entity_tear.h +++ b/src/entity_tear.h @@ -313,6 +313,16 @@ private: void fall_update(); void split_fire(bool isRising); void bone_shards_fire(bool isRising); + void tech_zero_update(); + void tech_zero_aim(); + void occult_steer(); + void tractor_beam_follow(); + void variant_switch(int newVariant, bool isTurnReset); + void ludovico_refresh(Entity_Player* player, float speed, int ticks); + void ludovico_child_update(); + void ludovico_ring_update(); + float ludovico_update(); + void ludovico_interpolate(); void child_setup(Entity_Tear& child, TearFlags flags, float alpha); }; diff --git a/src/entity_water.cpp b/src/entity_water.cpp new file mode 100644 index 0000000..c840aca --- /dev/null +++ b/src/entity_water.cpp @@ -0,0 +1,137 @@ +#include "entity.h" +#include "entity_effect.h" +#include "entity_pickup.h" +#include "entity_player.h" +#include "game.h" +#include "grid_entity.h" +#include "manager.h" +#include "room.h" +#include +#include + +// The entities the water clips its own way: the Gemini familiar, Wormwood and the Mullighoul. +constexpr int FAMILIAR_GEMINI = 79; +constexpr int PIN_VARIANT_WORMWOOD = 3; +constexpr int PREY_VARIANT_MULLIGHOUL = 1; + +// The clips entities have besides the grid entities' flat, raised and solid ones: on the surface, a door's, half sunk, +// a Wraith's ghost's, wading and a strider's. +constexpr uint32_t CLIP_SURFACE = WATER_CLIP_SURFACE; +constexpr uint32_t CLIP_DOOR = 0x25; +constexpr uint32_t CLIP_SUNK = 0x24; +constexpr uint32_t CLIP_GHOST = 0x1b; +constexpr uint32_t CLIP_WADING = WATER_CLIP_RIPPLES; +constexpr uint32_t CLIP_STRIDER = 0x99; + +// How far reflections sit: above the water, below it, a pedestal's. +constexpr float REFLECTION_ABOVE = 2; +constexpr float REFLECTION_BELOW = -2; +constexpr float REFLECTION_PEDESTAL = -5; + +// How deep Wormwood dives before the water hides it, and the ripple a moving entity leaves every 20 units it covers. +constexpr float WORMWOOD_DIVE = -16; +constexpr float RIPPLE_DISTANCE = 20; +constexpr float RIPPLE_MIN_SPEED = 0.01f; + +// The effects the water shows on its surface, flat, in it or not at all. +static WaterClipInfo effect_clip_get(Entity& effect, bool& isClipped) +{ + isClipped = true; + switch (effect.variant) + { + case EFFECT_WATER_RIPPLE: + case EFFECT_PEDESTAL_RIPPLE: + case EFFECT_MIST: + case EFFECT_WATER_SPLASH: + case EFFECT_TARGET: + case EFFECT_OCCULT_TARGET: return {CLIP_SURFACE, 0}; + case EFFECT_WHIRLPOOL: + if (effect.subtype == 0) return {CLIP_SURFACE, 0}; + break; + case EFFECT_TADPOLE: return {WATER_CLIP_FLAT, 0}; + case EFFECT_COLOSTOMIA_PUDDLE: + case EFFECT_POOF02: + case EFFECT_PORTAL_TELEPORT: + case EFFECT_PURGATORY: return {WATER_CLIP_RAISED, 0}; + } + isClipped = false; + return {}; +} + +// 006b6ed0 How the water clips the entity: surface effects and shop items on the surface, background entities flat +// and door ones like doors, tears, projectiles, lasers and effects raised with their reflection above, creeps raised, +// a leech or fissure sunk until it surfaces, Wormwood by its dive, Charm of the Vampire's players solid, flying players +// raised, a pedestal by its overlay, and anything else raised with its reflection below. +WaterClipInfo Entity::GetWaterClipInfo() +{ + bool isClipped = false; + + if (type == ENTITY_EFFECT) + { + WaterClipInfo clip = effect_clip_get(*this, isClipped); + if (isClipped) return clip; + } + else if (type == ENTITY_LASER) return {WATER_CLIP_RAISED, REFLECTION_ABOVE}; + + if (sortingLayer == SORTING_BACKGROUND) return {WATER_CLIP_FLAT, 0}; + if (sortingLayer == SORTING_DOOR) return {CLIP_DOOR, 0}; + if (type == ENTITY_PICKUP && static_cast(this)->price != 0) return {CLIP_SURFACE, 0}; + if (type == ENTITY_EFFECT && variant == EFFECT_POOF01 && spawnerType == ENTITY_WRAITH && !Room::IsMirrorWorld()) + return {CLIP_GHOST, REFLECTION_BELOW}; + if (type == ENTITY_TEAR || type == ENTITY_PROJECTILE || type == ENTITY_EFFECT || + (type == ENTITY_FAMILIAR && variant == FAMILIAR_GEMINI)) + return {WATER_CLIP_RAISED, REFLECTION_ABOVE}; + + switch (type) + { + case ENTITY_WALL_CREEP: + case ENTITY_RAGE_CREEP: + case ENTITY_BLIND_CREEP: + case ENTITY_THE_THING: return {WATER_CLIP_RAISED, 0}; + case ENTITY_FIREPLACE: + if (health <= 1) return {WATER_CLIP_FLAT, 0}; + break; + case ENTITY_SMALL_LEECH: + if (posOffset.y > SMALL_LEECH_SURFACE) return {CLIP_SUNK, 0}; + break; + case ENTITY_STRIDER: return {CLIP_STRIDER, 0}; + case ENTITY_DRIP: + case ENTITY_SPLURT: return {CLIP_WADING, 0}; + case ENTITY_PREY: + if (variant == PREY_VARIANT_MULLIGHOUL) return {WATER_CLIP_RAISED, 0}; + break; + case ENTITY_FISSURE: + if (posOffset.y > 0) return {CLIP_SUNK, 0}; + break; + case ENTITY_PIN: + if (variant != PIN_VARIANT_WORMWOOD) break; + if (posOffset.y >= 0) return {WATER_CLIP_FLAT, REFLECTION_BELOW}; + return {posOffset.y < WORMWOOD_DIVE ? WATER_CLIP_RAISED : CLIP_WADING, REFLECTION_BELOW}; + case ENTITY_PLAYER: + if (static_cast(this)->HasCollectible(COLLECTIBLE_CHARM_VAMPIRE)) + return {WATER_CLIP_SOLID, REFLECTION_BELOW}; + if (IsFlying()) return {WATER_CLIP_RAISED, 0}; + break; + case ENTITY_PICKUP: + { + AnimationState& overlay = sprite.overlayAnimState; + if (variant == PICKUP_COLLECTIBLE && (!overlay.animData || (int)overlay.animFrame != 0)) + return {WATER_CLIP_RAISED, REFLECTION_PEDESTAL}; + break; + } + } + return {WATER_CLIP_RAISED, REFLECTION_BELOW}; +} + +// Part of 006ae820 (Entity::Update) The ripples an entity leaves moving through the water surface: walking on the +// ground (or wading), one every 20 units it covers. +void Entity::water_ripples_update() +{ + WaterClipInfo clip = GetWaterClipInfo(); + bool isWalking = entityCollisionClass != ENTCOLL_NONE && entityGridCollisionClass == GRIDCOLL_GROUND; + float speed = std::sqrt(velocity.x * velocity.x + velocity.y * velocity.y); + + if ((!isWalking && !(clip.flags & WATER_CLIP_RIPPLES)) || speed <= RIPPLE_MIN_SPEED) return; + if (GetIntervalTicks((float)std::max(1, (int)(RIPPLE_DISTANCE / speed)), 0)) + g_game->Spawn({.position = pos, .type = ENTITY_EFFECT, .variant = EFFECT_WATER_RIPPLE, .seed = Random()}); +} diff --git a/src/familiar_ai.cpp b/src/familiar_ai.cpp index a5be166..5d02f99 100644 --- a/src/familiar_ai.cpp +++ b/src/familiar_ai.cpp @@ -104,6 +104,13 @@ constexpr int SACK_DROP_SHIFT_3 = 13; constexpr int SOUND_LITTLE_CHAD = 219; constexpr int ROOM_CLEAR_CYCLE = 1024; +// Juicy Sack's blue spiders on a clear, and Spider Mod's odds of a spider or a battery. +constexpr int JUICY_SACK_SPIDERS = 2; +constexpr int JUICY_SACK_BFFS_SPIDERS = 3; +constexpr uint32_t SPIDER_MOD_ROLL = 100; +constexpr uint32_t SPIDER_MOD_BFFS_ROLL = 80; +constexpr int SPIDER_MOD_DROP_ODDS = 10; + // 00615030 Picks what to chase: the best scored enemy in reach (closer, near the player, weaker or healthier as asked, // inside a cone if one is given, the current one preferred), checked every few frames. A pacifist room drops the // target, an enemy given up on (a versus match's long chase) is skipped, and a charmed familiar turns on the player. @@ -468,7 +475,7 @@ void Entity_Familiar::ai_charger() } // The pickup a sack drops on a clear, or none (part of 0062aab0). Lil Chest and Mystery Sack roll theirs, Bumbo counts -// its clears. Juicy Sack and Spider Mod's spiders wait for their takeover. +// its clears. Juicy Sack throws blue spiders, Spider Mod now and then a spider or a battery. static SackDrop sack_drop_roll(Entity_Familiar& familiar, bool hasBffs) { for (const SackDrop& drop : SACK_DROPS) @@ -482,8 +489,28 @@ static SackDrop sack_drop_roll(Entity_Familiar& familiar, bool hasBffs) switch (familiar.variant) { case Entity_Familiar::JUICY_SACK: + for (int spider = hasBffs ? JUICY_SACK_BFFS_SPIDERS : JUICY_SACK_SPIDERS; spider > 0; spider--) + { + familiar.player->numBlueSpiders++; + Vector spot = room_free_pickup_position_find({.position = familiar.pos}); + familiar.shot_owner_convert(spawn_blue_spider(spot, familiar.player, {})); + } + return {}; case Entity_Familiar::SPIDER_MOD: - reconstruction_missing("Entity_Familiar::TriggerRoomClear 0062aab0 (blue spiders)"); + { + int roll = (int)rng.RandomInt(hasBffs ? SPIDER_MOD_BFFS_ROLL : SPIDER_MOD_ROLL); + if (isBethanyB) roll = roll * 4 / 3; + if (roll >= SPIDER_MOD_DROP_ODDS) return {}; + + if (rng.RandomInt(3) == 0) + g_game->Spawn({.position = familiar.pos, .type = ENTITY_PICKUP, .variant = PICKUP_LIL_BATTERY, .seed = Random()}); + else + { + familiar.player->numBlueSpiders++; + familiar.shot_owner_convert(spawn_blue_spider(familiar.pos, familiar.player, {})); + } + return {}; + } case Entity_Familiar::MYSTERY_SACK: { float chance = hasBffs ? 0.22f : 0.18f; diff --git a/src/familiar_bums.cpp b/src/familiar_bums.cpp index 32ddba9..f715fa2 100644 --- a/src/familiar_bums.cpp +++ b/src/familiar_bums.cpp @@ -199,9 +199,8 @@ static void dark_bum_pay(Entity_Familiar& bum, int drops) Entity_NPC::ThrowSpider(bum.pos, &bum, spot, false, BUM_SPIDER_HEIGHT); return; } - Vector still{}; bum.player->numBlueSpiders++; - spawn_blue_spider(&spot, bum.player, &still); + bum.shot_owner_convert(spawn_blue_spider(spot, bum.player, {})); return; } default: diff --git a/src/familiar_collision.cpp b/src/familiar_collision.cpp index fb6da36..94edba1 100644 --- a/src/familiar_collision.cpp +++ b/src/familiar_collision.cpp @@ -3,13 +3,18 @@ #include "entity_familiar.h" #include "entity_list.h" #include "entity_npc.h" +#include "entity_pickup.h" #include "entity_player.h" #include "entity_projectile.h" #include "game.h" #include "log.h" #include "lua_engine.h" +#include "manager.h" #include "npc_ai.h" #include "room.h" +#include "room_grid.h" +#include "weapon.h" +#include // The enemies a contact familiar swats outright: the flies (a Pooter only of its first kinds). constexpr int SWATTED_TYPES[] = {13, 18, 80, 222, 256, 296, 281, 868}; @@ -20,12 +25,87 @@ constexpr int CONTACT_VARIANTS[] = {33, 60, 15, 14, 79, 77, 3, 104, 44, 4 32, 83, 121, 126, 226, 224, 210, 218, 206, 237, 229, 204}; // The familiars whose touch, block or hit has an effect of its own not reconstructed yet. -constexpr int UNWRITTEN_TOUCH_VARIANTS[] = {87, 94, 113, 243, 200, 239, 105, 127, 206, 66, 131, 204, 231, - 237, 25, 93, 42, 63, 117, 130, 106, 121, 128, 234, 232, 223}; -constexpr int UNWRITTEN_BLOCK_VARIANTS[] = {51, 95, 83, 121, 128, 229, 234, 228, 238, 201, 216, 217, 231}; +constexpr int UNWRITTEN_TOUCH_VARIANTS[] = {87, 243, 200, 105, 127, 206, 131, 204, 231, 237, 93}; +constexpr int UNWRITTEN_BLOCK_VARIANTS[] = {228, 238, 201, 216, 217, 231}; constexpr int UNWRITTEN_ENEMY_TOUCH_VARIANTS[] = {228, 238, 201, 216, 217, 206, 237}; constexpr int UNWRITTEN_DEATH_VARIANTS[] = {128, 216, 217, 206, 237, 229, 234, 201, 238}; +// The familiars whose contact damage stays off until their dash or throw (a cooldown of -1), or while they rest. +constexpr int DASHING_VARIANTS[] = {130, 232, 223}; + +// The chargers whose dash breaks fireplaces and poop. +constexpr int BUMPING_VARIANTS[] = {3, 59, 104, 25}; + +// Spider Mod's and Spider Baby's curses on what they bite: how long, and how long they rest after. +constexpr int SPIDER_CURSE_KINDS = 8; +constexpr int SPIDER_SLOW_FRAMES = 60; +constexpr float SPIDER_SLOWING = 0.9f; +constexpr ColorMod SPIDER_SLOW_COLOR = {{1, 1, 1.3f, 1}, {0, 0, 0, 0}, {0.15686275f, 0.15686275f, 0.15686275f}}; +constexpr int SPIDER_POISON_FRAMES = 40; +constexpr int SPIDER_FREEZE_FRAMES = 50; +constexpr int SPIDER_CHARM_FRAMES = 150; +constexpr int SPIDER_CONFUSION_FRAMES = 150; +constexpr int SPIDER_CONFUSION_RANGE = 30; +constexpr int SPIDER_FEAR_FRAMES = -150; +constexpr int SPIDER_BURN_FRAMES = 40; +constexpr int SPIDER_SHRINK_FRAMES = -150; +constexpr int SPIDER_REST_STEPS = 3; +constexpr int SPIDER_REST_STEP_FRAMES = 30; + +// Sissy Longlegs' charm and how often it may charm the same enemy again. +constexpr int SISSY_CHARM_FRAMES = 150; +constexpr int SISSY_HIT_INTERVAL = 7; + +// Lil Haunt's scare, Mom's Razor's bleed, the Shade's and the bones' wear, and their push. +constexpr int HAUNT_FEAR_ODDS = 10; +constexpr int HAUNT_FEAR_FRAMES = -150; +constexpr int RAZOR_BLEED_FRAMES = 150; +constexpr int LEPROSY_HITS = 30; +constexpr int LEPROSY_BLOCK_WEAR = 10; +constexpr int BONE_WEAR = 3; +constexpr int BONE_WEAR_LIMIT = 5; +constexpr float BONE_PUSH = 10; + +// Holy Water's break: BFFS!'s blue flame, how long it burns and what it deals. +constexpr ColorMod HOLY_FLAME_COLOR = {{1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0.2f, 0}}; +constexpr float HOLY_FLAME_DAMAGE = 6; +constexpr int HOLY_FLAME_FRAMES = 290; +constexpr float HOLY_SPLASH_SPEED = 0.2f; + +// Dry Baby's and Farting Baby's chance to answer a block (a versus match's rarer), and their rest after. +constexpr int DRY_BABY_ODDS = 4; +constexpr int DRY_BABY_VERSUS_ODDS = 25; +constexpr int DRY_BABY_REST_FRAMES = 150; +constexpr int FARTING_BABY_ODDS = 5; +constexpr int FARTING_BABY_REST_FRAMES = 210; + +// The eternal heart Sworn Protector gives for its tenth block, and how far from the player it looks for room. +constexpr int SWORN_PROTECTOR_BLOCKS = 10; +constexpr float SWORN_PROTECTOR_SPOT_STEP = 40; + +// Lil Gurdy's damage by its dash speed (faster in a versus match). +constexpr float LIL_GURDY_SPEED = 10; +constexpr float LIL_GURDY_VERSUS_SPEED = 14; +constexpr float LIL_GURDY_SPEED_CAP = 4; + +// Decap Attack's thrown head and the damage Intruder deals by its speed (less to bosses). +constexpr float DECAP_THROWN_MULTIPLIER = 6; +constexpr float INTRUDER_SPEED_SCALE = 0.25f; +constexpr float INTRUDER_BOSS_SPEED_SCALE = 0.1f; +constexpr float INTRUDER_BASE = 0.1f; + +// Cube Baby: the damage its speed adds, the player's kick, and the slowing and ice of its hits. +constexpr float CUBE_SPEED_STEP = 3; +constexpr float CUBE_SPEED_CAP = 5; +constexpr float CUBE_KICK_MIN_SPEED = 2; +constexpr float CUBE_KICK_SCALE = 3; +constexpr float CUBE_KICK_CAP = 14; +constexpr int CUBE_SLOW_FRAMES = 15; +constexpr int CUBE_VERSUS_SLOW_FRAMES = 120; +constexpr float CUBE_SLOWING = 0.9f; +constexpr ColorMod CUBE_SLOW_COLOR = {{1, 1, 1, 1}, {0, 0, 0, 0}, {0.15686275f, 0.15686275f, 0.15686275f}}; +constexpr int CUBE_ICE_FRAMES = 8; + // The breakables a dashing charger bumps into, and what each bump deals. constexpr int CHARGER_BREAKABLE_TYPES[] = {ENTITY_FIREPLACE, ENTITY_MOVABLE_TNT, ENTITY_POOP}; constexpr float CHARGER_BUMP_DAMAGE = 3.5f; @@ -40,6 +120,7 @@ constexpr float SPIN_HIT_BASE = 6; // The blue flies' and spiders' pop, and the locusts' tear effects. constexpr int SOUND_INSECT_POP = 1015; constexpr int SOUND_POP_DELAY = 15; +constexpr int DEATH_LOCUST_COUNTDOWN = 30; constexpr float WRATH_EXPLOSION_DAMAGE = 60; constexpr float WRATH_EXPLOSION_SCALE = 0.6f; constexpr int PESTILENCE_POISON_FRAMES = 40; @@ -78,8 +159,8 @@ enum LocustKind LOCUST_DEATH }; -// A blue fly popping on what it hit: a puff, then its locust's effect (an explosion, poison, slowing or death). -static void blue_fly_pop(Entity_Familiar& fly, Entity& collider, float damageMultiplier) +// A blue fly popping on what it hit: a puff, then its locust's effect (an explosion, poison, slowing or a hard hit). +static void blue_fly_pop(Entity_Familiar& fly, Entity& collider, float damageMultiplier, float damage) { g_game->Spawn({.position = fly.pos, .type = ENTITY_EFFECT, .variant = EFFECT_FLY_EXPLOSION, .seed = Random()}); fly.Remove(); @@ -97,7 +178,7 @@ static void blue_fly_pop(Entity_Familiar& fly, Entity& collider, float damageMul case LOCUST_FAMINE: collider.AddSlowing(EntityRef(&fly), FAMINE_SLOW_FRAMES, FAMINE_SLOWING, FAMINE_SLOW_COLOR, false); break; - case LOCUST_DEATH: collider.Kill(EntityRef(&fly)); break; + case LOCUST_DEATH: collider.TakeDamage(damage * damageMultiplier, 0, EntityRef(&fly), DEATH_LOCUST_COUNTDOWN); break; } familiar_sound_play(SOUND_INSECT_POP, {.frameDelay = SOUND_POP_DELAY}); } @@ -129,30 +210,128 @@ static void brain_explode(Entity_Familiar& brain, Entity& collider, float damage } } +// Holy Water breaking on an enemy: a splash and its holy creep, with BFFS! a lasting flame too. It shows its broken +// look until it refills. +static void holy_water_break(Entity_Familiar& water) +{ + water.shadowSize = 0; + familiar_sound_play(SOUND_GLASS_BREAK, {.frameDelay = 2}); + familiar_sound_play(SOUND_GASCAN_POUR, {.frameDelay = 2}); + for (int effect : {EFFECT_TEAR_POOF_B, EFFECT_PLAYER_CREEP_HOLYWATER}) + g_game->Spawn({.position = water.pos, .spawner = &water, .type = ENTITY_EFFECT, .variant = effect, .seed = Random()}) + ->Update(); + g_game->Spawn({.position = water.pos, + .velocity = vector_scale(water.velocity, HOLY_SPLASH_SPEED), + .spawner = &water, + .type = ENTITY_EFFECT, + .variant = EFFECT_TEAR_POOF_A, + .seed = Random()}) + ->Update(); + if (water.player->HasCollectible(COLLECTIBLE_BFFS)) + { + auto* flame = static_cast(g_game->Spawn({.position = water.pos, + .spawner = water.player, + .type = ENTITY_EFFECT, + .variant = EFFECT_BLUE_FLAME, + .seed = Random()})); + flame->SetColor(HOLY_FLAME_COLOR, -1, 255, false, true); + flame->SetCollisionDamage(HOLY_FLAME_DAMAGE); + flame->timeout = HOLY_FLAME_FRAMES; + flame->lifespan = HOLY_FLAME_FRAMES; + flame->Update(); + } + water.subtype = 1; + water.state = 0; + water.sprite.Play("Break"); +} + +// A bone familiar's wear (Bone Spur's, the bone orbital's): pushes the enemy off from the player (Bone Spur bouncing +// back), and breaks after its second hit. +static void bone_wear(Entity_Familiar& bone, Entity& collider) +{ + Vector away = vector_scale(vector_normalized(vector_sub(collider.pos, bone.player->pos)), BONE_PUSH); + collider.AddVelocity_divided(away, false); + if (bone.variant == Entity_Familiar::BONE_SPUR) bone.AddVelocity_divided(vector_scale(away, -1), false); + bone.state += BONE_WEAR; + if (bone.state > BONE_WEAR_LIMIT) bone.Kill(EntityRef()); +} + +// After a familiar's hit hurts an enemy (part of 006261f0): Cube Baby's slowing ice, the Shade's and the bones' wear, +// Leprosy's, then Guppy's Hairball calling a blue fly where the challenge forbids shooting, Lil Haunt's scare and Mom's +// Razor's bleed. +void Entity_Familiar::collision_hurt(Entity& collider, float damageMultiplier, float dealt) +{ + if (variant == CUBE_BABY && damageMultiplier > 0) + { + hitList.clear(); + hit_list_insert(hitList, collider); + int frames = familiar_versus() ? CUBE_VERSUS_SLOW_FRAMES : CUBE_SLOW_FRAMES; + collider.AddSlowing(EntityRef(this), frames, CUBE_SLOWING, CUBE_SLOW_COLOR, false); + collider.AddIce(EntityRef(this), CUBE_ICE_FRAMES); + } + if (variant == LEECH && familiar_versus()) reconstruction_missing("Entity_Familiar::HandleCollision 006261f0 (a versus Leech)"); + if (variant == LIL_GURDY && damageMultiplier > 0) + reconstruction_missing("Entity_Familiar::HandleCollision 006261f0 (Lil Gurdy's bounce)"); + + if (variant == SHADE) state += (int)dealt; + else if (variant == LEPROSY && ++state >= LEPROSY_HITS) + { + player->numLeprosy--; + Kill(EntityRef()); + } + else if (variant == BONE_ORBITAL || variant == BONE_SPUR) bone_wear(*this, collider); +} + // A familiar's hit on an enemy (part of 006261f0): swats a fly outright when it hurts by touch, else hurts it unless a -// blue fly or spider bounces off an enemy too fast for it, then the blue flies and spiders pop and the brains blow. +// blue fly or spider bounces off an enemy too fast for it (the orbiting flies and Mom's Razor never, the dashers and Lil +// Gurdy only as they dash). Then the blue flies and spiders pop, the brains blow and Holy Water breaks. bool Entity_Familiar::collision_contact(Entity& collider, float damageMultiplier, float damage) { hit_list_insert(hitList, collider); bool isIgnored = true; - bool isSwatted = false; - if (familiar_listed(CONTACT_VARIANTS, variant)) + bool isDashing = fireCooldown == -1; + bool isContact = familiar_listed(CONTACT_VARIANTS, variant) || (familiar_listed(DASHING_VARIANTS, variant) && isDashing) || + (variant == LIL_GURDY && fireCooldown > 0); + bool isPooter = collider.type == ENTITY_POOTER && collider.variant != POOTER_SUPER; + bool isHurting = true; + if (isContact && (isPooter || familiar_listed(SWATTED_TYPES, collider.type))) { - bool isPooter = collider.type == ENTITY_POOTER && collider.variant != POOTER_SUPER; - isSwatted = isPooter || familiar_listed(SWATTED_TYPES, collider.type); - if (isSwatted) collider.Kill(EntityRef(this)); + collider.Kill(EntityRef(this)); + isHurting = false; } - if (!isSwatted && variant != FLY_ORBITAL) + else if (variant == JAW_BONE && !isDashing) isHurting = false; + if (variant == FLY_ORBITAL || variant == MOMS_RAZOR) isHurting = false; + + if (isHurting) { Entity_NPC* npc = dynamic_cast(&collider); bool isVelocityDamaging = !npc || npc->CanBeDamagedFromVelocity(velocity); + float dealt = damage * damageMultiplier; if ((variant != BLUE_FLY && variant != BLUE_SPIDER) || isVelocityDamaging) - collider.TakeDamage(damage * damageMultiplier, 0, EntityRef(this), 0); + { + collider.TakeDamage(dealt, 0, EntityRef(this), 0); + collision_hurt(collider, damageMultiplier, dealt); + } + if (variant == GUPPYS_HAIRBALL) + { + bool isNoShooting = g_game->challenge != 0 && !g_manager->GetChallengeParams(g_game->challenge).isCanShoot; + if (isNoShooting && player && player->variant == PLAYER_VARIANT_PLAYER) + player->AddBlueFlies(1, player->pos, &collider); + } } + if (variant == LIL_HAUNT && Random() % HAUNT_FEAR_ODDS == 0) + collider.AddFear(EntityRef(this), HAUNT_FEAR_FRAMES, false); + if (variant == MOMS_RAZOR) + { + collider.AddBleeding(EntityRef(this), RAZOR_BLEED_FRAMES); + TearParams hit = player->GetTearHitParams(WEAPON_TEARS, 1, 1, nullptr); + collider.TakeDamage(hit.tearDamage, 0, EntityRef(this), 0); + } + if (variant == JAW_BONE && isHurting) fireCooldown = -2; if (variant == BLUE_FLY) { - blue_fly_pop(*this, collider, damageMultiplier); + blue_fly_pop(*this, collider, damageMultiplier, damage); return true; } if (variant == BLUE_SPIDER) @@ -163,11 +342,14 @@ bool Entity_Familiar::collision_contact(Entity& collider, float damageMultiplier return true; } if (variant == BBF || variant == BOBS_BRAIN) brain_explode(*this, collider, damageMultiplier); + if (variant == HOLY_WATER && subtype == 0) holy_water_break(*this); return isIgnored; } // A projectile or tear meeting a familiar (part of 006261f0): one that cannot be stopped passes, a blocking familiar -// stops it. Slipped Rib's reflection and the familiars that react to a block stop the game. +// stops it. Dry Baby may answer with the Necronomicon and Farting Baby with a fart, Sworn Protector counts its blocks +// for an eternal heart, Leprosy and Bone Spur wear and the bone and swarm orbitals break. Slipped Rib's reflection and +// the familiars hurt by a block stop the game. bool Entity_Familiar::collision_block(Entity& collider, bool isIgnored) { if (collider.type == ENTITY_PROJECTILE && @@ -180,18 +362,122 @@ bool Entity_Familiar::collision_block(Entity& collider, bool isIgnored) } if (familiar_listed(UNWRITTEN_BLOCK_VARIANTS, variant)) reconstruction_missing("Entity_Familiar::HandleCollision 006261f0 (this familiar's block)"); + + if (variant == DRY_BABY) + { + if (fireCooldown < 1 && random_below(familiar_versus() ? DRY_BABY_VERSUS_ODDS : DRY_BABY_ODDS) == 0) + { + sprite.Play("Hit"); + fireCooldown = DRY_BABY_REST_FRAMES; + } + } + else if (variant == FARTING_BABY && Random() % FARTING_BABY_ODDS == 0 && fireCooldown < 1) + { + sprite.Play("Hit"); + fireCooldown = FARTING_BABY_REST_FRAMES; + familiar_sound_play(SOUND_FART, {.frameDelay = 2}); + } + if (variant == SWORN_PROTECTOR && ++coins == SWORN_PROTECTOR_BLOCKS && !familiar_versus()) + { + Vector spot = player ? room_free_pickup_position_find({.position = player->pos, .step = SWORN_PROTECTOR_SPOT_STEP}) + : pos; + g_game->Spawn({.position = spot, + .spawner = this, + .subType = HEART_ETERNAL, + .type = ENTITY_PICKUP, + .variant = PICKUP_HEART, + .seed = Random()}); + } + if (variant == LEPROSY && (state += LEPROSY_BLOCK_WEAR) >= LEPROSY_HITS) + { + player->numLeprosy--; + Kill(EntityRef()); + } + else if (variant == BONE_ORBITAL || variant == SWARM_FLY_ORBITAL || + (variant == BONE_SPUR && (state += BONE_WEAR) > BONE_WEAR_LIMIT)) + Kill(EntityRef()); collider.isDead = true; return isIgnored; } -// 006261f0 What a familiar does on touching an entity, after the mods. Friendly and charmed ones, and all in a pacifist -// room, leave enemies alone. A dashing charger breaks fireplaces and poop, a spinning orbital hits, Skatole and -// Beelzebub keep the flies off the player, a familiar with contact damage hurts enemies (once per hit list) and a -// blocking one stops shots. Returns whether the touch is ignored. A versus match and the familiars with their own touch -// stop the game. +// Part of 006261f0: how much harder a familiar's touch hits: BFFS!, then Lil Gurdy by its dash, a thrown Decap +// Attack head, Intruder by its speed and Cube Baby by its own. A player kicks a resting Cube Baby off with a thud. +float Entity_Familiar::collision_multiplier(Entity& collider) +{ + float multiplier = GetMultiplier(); + float speed = vector_length(velocity); + if (variant == LIL_GURDY) + { + float full = familiar_versus() ? LIL_GURDY_VERSUS_SPEED : LIL_GURDY_SPEED; + return state == 1 ? std::clamp(speed / full, 0.0f, LIL_GURDY_SPEED_CAP) * multiplier : 0; + } + if (variant == DECAP_ATTACK && (HasEntityFlags(FLAG_THROWN) || state > 0)) return DECAP_THROWN_MULTIPLIER; + if (variant == INTRUDER) + { + if (state < 1) return 0; + return (collider.IsBoss() ? INTRUDER_BOSS_SPEED_SCALE : INTRUDER_SPEED_SCALE) * speed + INTRUDER_BASE; + } + if (variant != CUBE_BABY) return multiplier; + + multiplier *= std::clamp(speed / CUBE_SPEED_STEP, 0.0f, CUBE_SPEED_CAP); + float kick = vector_length(collider.velocity); + if (collider.type == ENTITY_PLAYER && fireCooldown < 1 && orbitSpeed >= 0 && kick > CUBE_KICK_MIN_SPEED) + { + velocity = vector_add(velocity, vector_resized(vector_sub(pos, collider.pos), std::min(kick * CUBE_KICK_SCALE, CUBE_KICK_CAP))); + familiar_sound_play(SOUND_CUBE_BABY_KICK, {.frameDelay = 2}); + } + return multiplier; +} + +// Part of 006261f0: Spider Mod and Spider Baby curse what they bite with one of eight ailments, then rest. +static void spider_curse(Entity_Familiar& spider, Entity& collider) +{ + EntityRef source(&spider); + switch (Random() % SPIDER_CURSE_KINDS) + { + case 0: collider.AddSlowing(source, SPIDER_SLOW_FRAMES, SPIDER_SLOWING, SPIDER_SLOW_COLOR, false); break; + case 1: collider.AddPoison(source, SPIDER_POISON_FRAMES, 0, false); break; + case 2: collider.AddFreeze(source, SPIDER_FREEZE_FRAMES, false); break; + case 3: collider.AddCharmed(source, SPIDER_CHARM_FRAMES, false, false); break; + case 4: collider.AddConfusion(source, (int)(Random() % SPIDER_CONFUSION_RANGE) + SPIDER_CONFUSION_FRAMES, false); break; + case 5: collider.AddFear(source, SPIDER_FEAR_FRAMES, false); break; + case 6: collider.AddBurn(source, SPIDER_BURN_FRAMES, 0, false); break; + case 7: collider.AddShrink(source, SPIDER_SHRINK_FRAMES, false); break; + } + spider.fireCooldown = (int)(Random() % SPIDER_REST_STEPS + SPIDER_REST_STEPS) * SPIDER_REST_STEP_FRAMES; +} + +// Part of 006261f0: Sissy Longlegs charms each enemy it touches, once a hit list, and never blocks. +static bool sissy_charm(Entity_Familiar& sissy, Entity& collider) +{ + if (sissy.IsFrame(SISSY_HIT_INTERVAL, sissy.index)) sissy.hitList.clear(); + if (EntityList::HitListContains(sissy.hitList, collider)) return true; + + hit_list_insert(sissy.hitList, collider); + if (!collider.IsVulnerableEnemy(nullptr) || collider.IsDescendantOf(sissy.spawnerEntity)) return true; + + collider.AddCharmed(EntityRef(&sissy), SISSY_CHARM_FRAMES, false, false); + familiar_sound_play(SOUND_SISSYLONGLEG_CHARM, {.frameDelay = SISSY_CHARM_FRAMES}); + return true; +} + +// 006261f0 What a familiar does on touching an entity, after the mods. In a versus match players and other players' +// tears always count as low. Friendly and charmed ones, and all in a pacifist room, leave enemies alone. A resting Cube +// Baby lets players by, the spiders curse, Sissy Longlegs charms, a dashing charger breaks fireplaces and poop, a +// spinning orbital hits, Skatole and Beelzebub keep the flies off the player, a familiar with contact damage hurts +// enemies (once per hit list) and a blocking one stops shots. Returns whether the touch is ignored. The familiars with +// their own touch still unwritten stop the game. bool Entity_Familiar::HandleCollision(Entity* collider, bool isLow) { - if (familiar_versus()) reconstruction_missing("Entity_Familiar::HandleCollision 006261f0 (a versus match)"); + if (familiar_versus()) + { + if (collider->type == ENTITY_PLAYER && collider != spawnerEntity) isLow = true; + else if (collider->type == ENTITY_TEAR) + { + if (collider->IsDescendantOf(spawnerEntity)) return true; + isLow = true; + } + } LuaResult result = lua_engine_get().PreFamiliarCollision(this, collider, isLow); if (result == LUA_RESULT_TRUE) return true; if (result == LUA_RESULT_FALSE) return false; @@ -200,18 +486,28 @@ bool Entity_Familiar::HandleCollision(Entity* collider, bool isLow) if (isEnemy && (collider->HasEntityFlags(FLAG_FRIENDLY) || HasEntityFlags(FLAG_CHARM) || g_game->room->isPacifist)) return true; if (variant == UMBILICAL_BABY) return true; + bool isIgnored = true; + if (variant == CUBE_BABY && collider->type != ENTITY_FAMILIAR) + { + if (collider->type == ENTITY_PLAYER && orbitSpeed < 0) return true; + isIgnored = false; + } if (familiar_listed(UNWRITTEN_TOUCH_VARIANTS, variant) || sirenHelper) reconstruction_missing("Entity_Familiar::HandleCollision 006261f0 (this familiar's touch)"); - bool isIgnored = true; - float damageMultiplier = GetMultiplier(); - bool isCharger = variant == LITTLE_CHUBBY || variant == BOBS_BRAIN || variant == BIG_CHUBBY; - if (isCharger && subtype == 0 && fireCooldown < 0 && familiar_listed(CHARGER_BREAKABLE_TYPES, collider->type)) + float damageMultiplier = collision_multiplier(*collider); + bool isSpider = variant == SPIDER_MOD || variant == SPIDER_BABY; + if (isSpider && fireCooldown < 1 && collider->IsVulnerableEnemy(nullptr) && !IsDescendantOf(collider)) + spider_curse(*this, *collider); + + if (familiar_listed(BUMPING_VARIANTS, variant) && subtype == 0 && fireCooldown < 0 && + familiar_listed(CHARGER_BREAKABLE_TYPES, collider->type)) { collider->TakeDamage(CHARGER_BUMP_DAMAGE, 0, EntityRef(this), 0); velocity = vector_scale(velocity, 0.5f); if (--fireCooldown < CHARGER_BUMP_LIMIT) fireCooldown = CHARGER_BUMP_RECOVER; } + if (variant == SISSY_LONGLEGS) return sissy_charm(*this, *collider); if (isLow && HasEntityFlags(FLAG_SPIN) && collider->IsVulnerableEnemy(nullptr) && !EntityList::HitListContains(hitList, *collider)) @@ -230,8 +526,7 @@ bool Entity_Familiar::HandleCollision(Entity* collider, bool isLow) if (isOwnersFoe && collider->IsActiveEnemy(DEAD_EXCLUDED) && (collider->IsVulnerableEnemy(nullptr) || collider->CanShutDoors()) && familiar_listed(UNWRITTEN_ENEMY_TOUCH_VARIANTS, variant)) - reconstruction_missing("Entity_Familiar::HandleCollision 006261f0 (this " - "familiar's enemy touch)"); + reconstruction_missing("Entity_Familiar::HandleCollision 006261f0 (this familiar's enemy touch)"); if (collider->type == ENTITY_PLAYER) { @@ -254,10 +549,11 @@ bool Entity_Familiar::HandleCollision(Entity* collider, bool isLow) } if (!isLow) return solid_check(*collider, isIgnored); - bool isTouching = - collider->IsVulnerableEnemy(nullptr) && (damage > 0 || variant == FLY_ORBITAL) && - !EntityList::HitListContains(hitList, *collider) && - (variant != DADDY_LONGLEGS || entityCollisionClass == ENTCOLL_ENEMIES || entityCollisionClass == ENTCOLL_ALL); + bool isTouching = collider->IsVulnerableEnemy(nullptr) && + (damage > 0 || variant == FLY_ORBITAL || variant == SLIPPED_RIB) && + !EntityList::HitListContains(hitList, *collider) && + (variant != DADDY_LONGLEGS || entityCollisionClass == ENTCOLL_ENEMIES || + entityCollisionClass == ENTCOLL_ALL); if (isTouching) isIgnored = collision_contact(*collider, damageMultiplier, damage); if (collider->type == ENTITY_PROJECTILE || collider->type == ENTITY_TEAR) isIgnored = collision_block(*collider, isIgnored); diff --git a/src/familiar_evaluate.cpp b/src/familiar_evaluate.cpp index b85ed4d..47c5910 100644 --- a/src/familiar_evaluate.cpp +++ b/src/familiar_evaluate.cpp @@ -72,6 +72,12 @@ constexpr int COLLECTIBLE_SPRINKLER = 516; constexpr int COLLECTIBLE_KEY_BUM = 388; constexpr int COLLECTIBLE_BUM_FRIEND = 144; constexpr int COLLECTIBLE_LIL_DELIRIUM = 519; + +// Super Bum's arrival: the state flag that shows its page once, the page, and the three bums it takes the place of. +constexpr int GIANTBOOK_SUPER_BUM = 38; +constexpr std::pair SUPER_BUM_PARTS[] = {{COLLECTIBLE_KEY_BUM, Entity_Familiar::KEY_BUM}, + {COLLECTIBLE_DARK_BUM, Entity_Familiar::DARK_BUM}, + {COLLECTIBLE_BUM_FRIEND, Entity_Familiar::BUM_FRIEND}}; constexpr int COLLECTIBLE_BIRD_CAGE = 610; constexpr int COLLECTIBLE_PEEPER_2 = 605; constexpr int TRINKET_ISAACS_HEAD = 54; @@ -166,7 +172,8 @@ static void stages_check(Entity_Player& p, int collectible, int firstVariant, in if (full > 0) g_manager->persistentGameData.TryUnlock(achievement); } -// The shared pieces (the key and knife pieces counted across players) and Super Bum's trio wait for their takeover. +// The shared pieces (the key and knife pieces counted across players) wait for their takeover. Holding Key Bum, +// Dark Bum and Bum Friend together makes Super Bum (with its page the first time) in place of the three. static void shared_pieces_check(Entity_Player& p) { for (Entity_Player* other : g_game->playerManager.playerList) @@ -176,13 +183,26 @@ static void shared_pieces_check(Entity_Player& p) other->GetCollectibleNum(COLLECTIBLE_KNIFE_PIECE_2))) reconstruction_missing("Entity_Player::EvaluateItems 00763570 (the key and knife pieces)"); - if (p.HasCollectible(COLLECTIBLE_KEY_BUM) && p.HasCollectible(COLLECTIBLE_DARK_BUM) && - p.HasCollectible(COLLECTIBLE_BUM_FRIEND)) - reconstruction_missing("Entity_Player::EvaluateItems 00763570 (Super Bum)"); - familiar_check(p, {.rng = &p.GetCollectibleRNG(COLLECTIBLE_BUM_FRIEND), .variant = Entity_Familiar::SUPER_BUM}); - source_check(p, {COLLECTIBLE_KEY_BUM, Entity_Familiar::KEY_BUM}); - source_check(p, {COLLECTIBLE_DARK_BUM, Entity_Familiar::DARK_BUM}); - source_check(p, {COLLECTIBLE_BUM_FRIEND, Entity_Familiar::BUM_FRIEND}); + if (!p.HasCollectible(COLLECTIBLE_KEY_BUM) || !p.HasCollectible(COLLECTIBLE_DARK_BUM) || + !p.HasCollectible(COLLECTIBLE_BUM_FRIEND)) + { + familiar_check(p, {.rng = &p.GetCollectibleRNG(COLLECTIBLE_BUM_FRIEND), .variant = Entity_Familiar::SUPER_BUM}); + source_check(p, {COLLECTIBLE_KEY_BUM, Entity_Familiar::KEY_BUM}); + source_check(p, {COLLECTIBLE_DARK_BUM, Entity_Familiar::DARK_BUM}); + source_check(p, {COLLECTIBLE_BUM_FRIEND, Entity_Familiar::BUM_FRIEND}); + return; + } + + if (!g_game->GetStateFlag(GAME_STATE_SUPERBUM_APPEARED)) + { + g_game->gameStateFlags |= 1ull << GAME_STATE_SUPERBUM_APPEARED; + g_game->itemOverlay.Show(GIANTBOOK_SUPER_BUM, 0, nullptr); + } + familiar_check(p, {.rng = &p.GetCollectibleRNG(COLLECTIBLE_BUM_FRIEND), .count = 1, .variant = Entity_Familiar::SUPER_BUM}); + for (auto [collectible, variant] : SUPER_BUM_PARTS) + familiar_check(p, {.item = g_manager->itemConfig.GetCollectible(collectible), + .rng = &p.GetCollectibleRNG(collectible), + .variant = variant}); } // Lil Delirium's familiars, Found Soul's and the Strawman's co-op babies wait for their takeovers. diff --git a/src/familiar_follow.cpp b/src/familiar_follow.cpp index b83000f..42ba64e 100644 --- a/src/familiar_follow.cpp +++ b/src/familiar_follow.cpp @@ -1,4 +1,5 @@ #include "entity_familiar.h" +#include "entity_effect.h" #include "entity_player.h" #include "game.h" #include "log.h" @@ -524,3 +525,70 @@ void Entity_Familiar::ResolveOrbitConflict() if (other != this && !other->is_formation_exempt() && other->player == player) other->formationMode = FORMATION_NONE; } + +// MoveDiagonally: a still familiar's kick, its drag, its diagonal push and the push back from the walls, and the +// Peepers' tears and Peeper 2's creep. +constexpr float DIAGONAL_KICK = 10; +constexpr float DIAGONAL_DRAG = 0.7f; +constexpr float DIAGONAL_ANGLE = 0.7853982f; +constexpr float DIAGONAL_WALL_PUSH = 3; +constexpr float PEEPER_TEAR_SCALE = 0.3f; +constexpr float PEEPER_TEAR_SCALE_MIN = 0.1f; +constexpr float PEEPER_CREEP_SCALE = 0.5f; +constexpr float PEEPER_CREEP_SCALE_MIN = 0.2f; +constexpr int DIAGONAL_TURN_RANGE = 31; +constexpr int DIAGONAL_TURN_HALF = 15; + +// Spawns a scaled effect under a familiar and runs its first frame. +static void diagonal_trail(Entity_Familiar& familiar, int effectVariant, Entity* spawner, float scale) +{ + Entity* effect = g_game->Spawn( + {.position = familiar.pos, .spawner = spawner, .type = ENTITY_EFFECT, .variant = effectVariant, .seed = Random()}); + effect->sprite.scale = vector_make(scale, scale); + effect->Update(); +} + +// 006312f0 Bounces about the room diagonally: a still familiar gets a random kick, a moving one keeps its diagonal at +// a tilt its fire cooldown holds (fixed for Cain's Other Eye and BBF), pushed back inside the walls. The tilt changes +// when the familiar turns. The Peepers leave tears, Peeper 2 creep too. A permanent familiar stays put. +void Entity_Familiar::MoveDiagonally(float speed) +{ + bool isFixedAngle = variant == CAINS_OTHER_EYE || variant == BBF; + if (isSubtype55555) + { + pos = formationOffset; + velocity = {}; + return; + } + if (vector_is_zero(velocity)) + { + float angle = random_unit() * RANDOM_HALF_TURN; + angle += angle; + velocity = vector_make(std::cos(angle) * DIAGONAL_KICK, std::sin(angle) * DIAGONAL_KICK); + return; + } + + velocity = vector_scale(velocity, DIAGONAL_DRAG); + float angle = isFixedAngle ? DIAGONAL_ANGLE : (float)fireCooldown * PI_F / 180 + DIAGONAL_ANGLE; + float push = std::sqrt(2.0f) * speed; + velocity.x += velocity.x <= 0 ? -push * std::cos(angle) : push * std::cos(angle); + velocity.y += velocity.y <= 0 ? -std::sin(angle) * push : std::sin(angle) * push; + + Vector inside = g_game->room->GetClampedPositionImpl(pos, 0, 0, 0, 0); + if (pos.x > inside.x) velocity.x -= speed * DIAGONAL_WALL_PUSH; + else if (pos.x < inside.x) velocity.x += speed * DIAGONAL_WALL_PUSH; + if (pos.y > inside.y) velocity.y -= speed * DIAGONAL_WALL_PUSH; + else if (pos.y < inside.y) velocity.y += speed * DIAGONAL_WALL_PUSH; + + if ((Random() & 3) == 0 && (variant == PEEPER || variant == PEEPER_2)) + diagonal_trail(*this, EFFECT_BLOOD_SPLAT, nullptr, random_unit() * PEEPER_TEAR_SCALE + PEEPER_TEAR_SCALE_MIN); + if (variant == PEEPER_2 && !HasEntityFlags(FLAG_INTERPOLATION_UPDATE) && !g_game->IsPaused() && + (g_game->frameCount & 1) == 0 && Random() % 5 > 1) + diagonal_trail(*this, EFFECT_PLAYER_CREEP_RED, this, random_unit() * PEEPER_CREEP_SCALE + PEEPER_CREEP_SCALE_MIN); + + if (isFixedAngle) return; + + if ((velocity.x > 0 && targetPosition.x <= 0) || (velocity.y > 0 && targetPosition.y <= 0)) + fireCooldown = (int)(Random() % DIAGONAL_TURN_RANGE) - DIAGONAL_TURN_HALF; + targetPosition = velocity; +} diff --git a/src/familiar_missing.cpp b/src/familiar_missing.cpp index 8632fee..45ca261 100644 --- a/src/familiar_missing.cpp +++ b/src/familiar_missing.cpp @@ -81,18 +81,6 @@ void Entity_Familiar::AddToDelayed() reconstruction_missing("Entity_Familiar::AddToDelayed 00613fe0"); } -// 006142e0 -void Entity_Familiar::PlayChargeAnim(int) -{ - reconstruction_missing("Entity_Familiar::PlayChargeAnim 006142e0"); -} - -// 006341a0 -bool Entity_Familiar::apply_baby_bender(Entity_Tear*) -{ - reconstruction_missing("Entity_Familiar::apply_baby_bender 006341a0"); -} - // 0062a8f0 bool Entity_Familiar::CanPlayerFire() { @@ -105,12 +93,6 @@ void Entity_Familiar::ai_blue_babys_only_friend() reconstruction_missing("Entity_Familiar::ai_blue_babys_only_friend 0061a240"); } -// 0061bd50 -void Entity_Familiar::ai_daddy_longlegs() -{ - reconstruction_missing("Entity_Familiar::ai_daddy_longlegs 0061bd50"); -} - // 0061c150 void Entity_Familiar::ai_orbital_variant_50() { @@ -147,12 +129,6 @@ void Entity_Familiar::MoveDelayed(int) reconstruction_missing("Entity_Familiar::MoveDelayed 00631050"); } -// 006312f0 -void Entity_Familiar::MoveDiagonally(float) -{ - reconstruction_missing("Entity_Familiar::MoveDiagonally 006312f0"); -} - // 00631850 void Entity_Familiar::move_to_parent_offset() { @@ -207,12 +183,6 @@ void Entity_Familiar::ai_lil_harbingers() reconstruction_missing("Entity_Familiar::ai_lil_harbingers 006378c0"); } -// 00638c10 -Entity_Laser* Entity_Familiar::FireBrimstone(const Vector&, uint8_t) -{ - reconstruction_missing("Entity_Familiar::FireBrimstone 00638c10"); -} - // 0063aef0 Entity_Laser* Entity_Familiar::sprinkler_shoot_laser(float, float) { diff --git a/src/familiar_shoot.cpp b/src/familiar_shoot.cpp index bb28126..c63fc32 100644 --- a/src/familiar_shoot.cpp +++ b/src/familiar_shoot.cpp @@ -1,5 +1,6 @@ #include "entity_effect.h" #include "entity_familiar.h" +#include "entity_laser.h" #include "entity_player.h" #include "entity_tear.h" #include "game.h" @@ -32,6 +33,44 @@ constexpr int MIMIC_ROBO_BABY = 4; constexpr int MIMIC_ROTTEN_BABY = 9; constexpr float ROTTEN_FLY_RANGE = 200; +// The charged shots: how long a charge takes, its flash, the beam's spot at the mouth, damage, size, timeout and +// depth, the dead zone of the player's aim, how fast a mark turns a beam, and the whip's head time. +constexpr int CHARGE_ANIM_FRAMES = 30; +constexpr int CHARGE_FLASH_INTERVAL = 5; +constexpr int CHARGE_FLASH_FRAMES = 2; +constexpr ColorMod CHARGE_FLASH = {{1, 0.5f, 0.5f, 1}, {0, 0, 0, 0}, {0.19607843f, 0, 0}}; +constexpr float BRIMSTONE_MOUTH_X = 10; +constexpr float BRIMSTONE_MOUTH_Y = -19; +constexpr float BRIMSTONE_MOUTH_DROP = 4; +constexpr float BRIMSTONE_DAMAGE = 3; +constexpr float BRIMSTONE_SCALE = 0.5f; +constexpr int FAMILIAR_BEAM_TIMEOUT = 8; +constexpr float BRIMSTONE_BEHIND_Y = -0.5f; +constexpr float BRIMSTONE_DEPTH_BEHIND = -10; +constexpr float BRIMSTONE_DEPTH_FRONT = 3000; +constexpr int BRIMSTONE_HEAD_FRAMES = 30; +constexpr float BRIMSTONE_AIM_DEADZONE = 0.5f; +constexpr float BRIMSTONE_TURN_SPEED = 8; +constexpr int WHIP_HEAD_FRAMES = 4; +constexpr ColorMod DELIRIUM_LASER_COLOR = {{0.2f, 1, 0, 1}, {0, 0, 0, 0}, {1, 1, 0}}; + +// Robo-Baby's beam: its eye's spot (a wisp's), timeout and damage. +constexpr float ROBO_EYE_SIDE = 9; +constexpr float ROBO_EYE_Y = -23; +constexpr float ROBO_EYE_DROP = -8; +constexpr float ROBO_WISP_EYE_Y = -18; +constexpr int ROBO_LASER_TIMEOUT = 3; +constexpr float ROBO_LASER_DAMAGE = 3.5f; + +// Lil Monstro's spray: its tears, their speed, the gurgle's volume and the head's time. +constexpr int MONSTRO_SPRAY_TEARS = 12; +constexpr float MONSTRO_SPRAY_SCALE = 0.7f; +constexpr float MONSTRO_SPRAY_VOLUME = 0.7f; +constexpr int MONSTRO_HEAD_FRAMES = 20; + +// The collectibles of the babies Mongo Baby mimics, by its subtype (Brother Bobby first, Demon Baby second). +constexpr int MONGO_MIMICS[] = {8, 113, 99, 100, 95, 67, 163, 167, 174, 268, 435, 608}; + // A shot's base: its speed, how much of the player's motion it takes, damage and size. constexpr float SHOT_SPEED = 10; constexpr float SHOT_INHERIT = 0.6f; @@ -286,10 +325,22 @@ void Entity_Familiar::Shoot() headFrameDelay--; } -// 0062d290 Mongo Baby moves on to mimicking the next baby the player owns. +// 0062d290 Mongo Baby moves on to mimicking the next baby the player owns, in the table's order (none, 0, owning +// none of them). void Entity_Familiar::mongo_baby_pick_next_mimic() { - if (variant == MONGO_BABY) reconstruction_missing("Entity_Familiar::mongo_baby_pick_next_mimic 0062d290"); + if (variant != MONGO_BABY) return; + + int mimic = subtype; + subtype = 0; + for (size_t tries = 0; tries < std::size(MONGO_MIMICS); tries++) + { + mimic = (mimic + 1) % (int)std::size(MONGO_MIMICS); + if (!player->HasCollectible(MONGO_MIMICS[mimic])) continue; + + subtype = mimic; + return; + } } // The shot of a familiar by variant (or by the baby Mongo Baby mimics, or the roll of Rainbow Baby): its flags, look, @@ -547,12 +598,35 @@ void Entity_Familiar::shot_owner_convert(Entity* shot) if (HasEntityFlags(FLAG_CHARM) && owner && Entity::is_enemy_type(owner->type)) convert_shot_for_enemy_owner(shot); } -// 00613c20 Robo-Baby's laser, which waits for Entity_Laser::ShootAngle's takeover. -Entity_Laser* Entity_Familiar::fire_robo_baby_laser(const Vector&) +// 00613c20 Robo-Baby's laser (a wisp's too): a short thin beam from its eye, hitting once and staying where it was +// fired, three and a half damage times BFFS!, drawn behind it when aimed up or left. Lil Delirium tints it, a hologram +// fades it, Baby-Bender bends it and the Siren turns it on the player. None for a dead player. +Entity_Laser* Entity_Familiar::fire_robo_baby_laser(const Vector& direction) { if (player->isDead) return nullptr; - reconstruction_missing("Entity_Familiar::fire_robo_baby_laser 00613c20 " - "(Entity_Laser::ShootAngle 0096f310)"); + + Vector offset = vector_make(direction.x + direction.x - direction.y * ROBO_EYE_SIDE, + ROBO_EYE_Y + ROBO_EYE_DROP - (direction.x + direction.x)); + if (variant == WISP) offset = vector_make(0, ROBO_WISP_EYE_Y); + Entity_Laser* laser = Entity_Laser::ShootAngle({.position = pos, + .posOffset = offset, + .source = this, + .angleDegrees = vector_angle(direction), + .timeout = ROBO_LASER_TIMEOUT, + .variant = LASER_THIN_RED}); + laser->isOneHit = true; + laser->isDisableFollowParent = true; + laser->SetCollisionDamage(GetMultiplier() * ROBO_LASER_DAMAGE); + bool isBehind = direction.y < BRIMSTONE_BEHIND_Y || direction.x < BRIMSTONE_BEHIND_Y; + laser->renderDepthOffset = isBehind ? BRIMSTONE_DEPTH_BEHIND : BRIMSTONE_DEPTH_FRONT; + + ColorMod color = isLilDelirium ? DELIRIUM_LASER_COLOR : COLOR_DEFAULT; + if (player->IsHologram()) color._tint[3] = HOLOGRAM_ALPHA; + laser->SetColor(color, -1, 255, false, true); + laser->Update(); + apply_baby_bender(*laser); + shot_owner_convert(laser); + return laser; } // 0062e620 Keeps a copying familiar's weapon (Incubus' and the like) the kind its player's is, then aims and fires it @@ -618,3 +692,157 @@ void Entity_Familiar::update_weapon(bool isInterpolated) if (fireCooldown > 0) fireCooldown--; if (isLullaby && fireCooldown > 0) fireCooldown--; } + +// 006142e0 Shows its charge toward a direction, the frame following the cooldown (only once a charge shows), and a +// flash every five frames once charged. +void Entity_Familiar::PlayChargeAnim(int direction) +{ + sprite.isFlipX = false; + const AnimationData* shown = sprite.animState.animData; + float charge = 1 - (float)fireCooldown / (float)CHARGE_ANIM_FRAMES; + int frame = shown && shown->name.find("Charge") != std::string::npos ? (int)(charge * (float)shown->length) : 0; + switch (direction) + { + case DIRECTION_LEFT: + sprite.isFlipX = true; + sprite.SetFrame("FloatChargeSide", frame); + break; + case DIRECTION_RIGHT: sprite.SetFrame("FloatChargeSide", frame); break; + case DIRECTION_UP: sprite.SetFrame("FloatChargeUp", frame); break; + case DIRECTION_DOWN: sprite.SetFrame("FloatChargeDown", frame); break; + } + + int length = sprite.animState.animData ? sprite.animState.animData->length : 0; + if (frame >= length && fireCooldown < 0 && !HasEntityFlags(FLAG_INTERPOLATION_UPDATE) && !g_game->IsPaused() && + g_game->frameCount % CHARGE_FLASH_INTERVAL == 0) + SetColor(CHARGE_FLASH, CHARGE_FLASH_FRAMES, 0, true, true); +} + +// 006341a0 Baby-Bender on a familiar's beam: homing with its purple look. False without the trinket. +bool Entity_Familiar::apply_baby_bender(Entity_Laser& laser) +{ + if (!player->HasTrinket(TRINKET_BABY_BENDER)) return false; + + TearFlags flags = laser.tearFlags; + ColorMod color = laser.sprite.color; + float height = 0; + float fallingSpeed = 0; + float range = 0; + apply_baby_bender_tear_params(flags, color, &height, &fallingSpeed, &range, true); + laser.tearFlags = flags; + laser.SetColor(color, -1, 255, false, true); + return true; +} + +// 00638c10 Fires a familiar's Brimstone beam along a direction (none for a dead player): a short thin beam from its +// mouth, a third of Brimstone's damage times BFFS!, drawn behind it when aimed up. Its own beam is tinted for Lil +// Delirium, bent by Baby-Bender, turned on the player by the Siren, linked to it and shown on its head. +Entity_Laser* Entity_Familiar::FireBrimstone(const Vector& aimDirection, BrimstoneLook look) +{ + if (player->isDead) return nullptr; + + Vector offset = vector_make(aimDirection.x * BRIMSTONE_MOUTH_X, BRIMSTONE_MOUTH_Y - std::fabs(aimDirection.x) * BRIMSTONE_MOUTH_DROP); + Entity_Laser* laser = Entity_Laser::ShootAngle({.position = pos, + .posOffset = offset, + .source = this, + .angleDegrees = vector_angle(aimDirection), + .timeout = FAMILIAR_BEAM_TIMEOUT, + .variant = LASER_THICK_RED}); + laser->SetCollisionDamage(GetMultiplier() * BRIMSTONE_DAMAGE); + laser->scale = BRIMSTONE_SCALE; + laser->ResetSpriteScale(); + laser->renderDepthOffset = aimDirection.y < BRIMSTONE_BEHIND_Y ? BRIMSTONE_DEPTH_BEHIND : BRIMSTONE_DEPTH_FRONT; + if (look == BRIMSTONE_BARE) return laser; + + if (isLilDelirium) laser->SetColor(DELIRIUM_LASER_COLOR, -1, 255, false, true); + apply_baby_bender(*laser); + shot_owner_convert(laser); + laser->Update(); + linkedEntity = laser; + headFrameDelay = BRIMSTONE_HEAD_FRAMES; + if (std::fabs(aimDirection.x) <= std::fabs(aimDirection.y)) + PlayShootAnim(aimDirection.y >= 0 ? DIRECTION_DOWN : DIRECTION_UP); + else PlayShootAnim(aimDirection.x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT); + return laser; +} + +// Whether a familiar's linked beam is a plain Brimstone one, which a mark may turn. +static bool brimstone_beam_turnable(Entity* beam) +{ + return beam && beam->type == ENTITY_LASER && beam->variant != LASER_THICK_RED && beam->variant != LASER_THIN_RED && + beam->variant != LASER_SHOOP; +} + +// 0062d300 (misnamed: it is the charged shot of Lil Brimstone, Lil Monstro and Lil Abaddon) Charges while the player +// shoots and fires on release: Lil Monstro a spray of tears, Lil Brimstone a beam. A mark aims the shot (and turns a +// beam already firing), and a charmed familiar lets go of its charge. Runs on every other frame, interpolation +// included, and not while the player is busy. Tainted Lilith's hidden Incubus keeps its whip showing the head. +void Entity_Familiar::ai_incubus_shot() +{ + bool isSkippedFrame = (g_manager->framecount & 1) != 0; + int direction = player->fireDirection; + if (vector_length(player->aimDirection) < BRIMSTONE_AIM_DEADZONE && !player->areOpposingShootDirectionsPressed) + direction = DIRECTION_NONE; + + Vector aim = direction_unit(lastDirection); + FireMode mode = FIRE_INHERIT_MOTION; + if (TryAimAtMarkedTarget(aim, lastDirection, nullptr)) + { + if (fireCooldown < 0) direction = DIRECTION_NONE; + mode = FIRE_EXACT; + Entity* beam = linkedEntity; + if (brimstone_beam_turnable(beam)) + static_cast(beam)->RotateToAngle(vector_angle(aim), BRIMSTONE_TURN_SPEED); + } + if (HasEntityFlags(FLAG_CHARM) && fireCooldown < 0) direction = DIRECTION_NONE; + if (isSkippedFrame) return; + + bool isPlayerBusy = player->isPlayingExtraAnimation || player->isPlayingItemAnimation || + g_game->stageTransition.state != STAGE_TRANSITION_NONE || !player->isControlsEnabled || + player->controlsCooldown > 0; + if (!isPlayerBusy) + { + if (direction == DIRECTION_NONE) + { + if (fireCooldown < 0 && !vector_is_zero(aim)) charged_shot_fire(aim, mode); + fireCooldown = familiar_lullaby_delay(*this, CHARGE_ANIM_FRAMES); + } + else + { + if (headFrameDelay <= HEAD_FLOAT_FRAME) fireCooldown--; + lastDirection = direction; + } + + if (headFrameDelay > HEAD_FLOAT_FRAME) headFrameDelay--; + else + { + if (direction == DIRECTION_NONE) PlayFloatAnim(player->headDirection); + else PlayChargeAnim(lastDirection); + headFrameDelay = HEAD_FLOAT_FRAME; + } + } + + if (!linkedEntity || !IsLilithBirthrightIncubus()) return; + + if (Entity_Familiar* whip = dynamic_cast(get_incubus_umbilical_whip())) + whip->headFrameDelay = std::max(whip->headFrameDelay, WHIP_HEAD_FRAMES); +} + +// Part of 0062d300: the released shot. Lil Monstro sprays twelve tears with a splat, Lil Brimstone fires its beam. +// Lil Abaddon's ring stops the game. +void Entity_Familiar::charged_shot_fire(Vector aim, FireMode mode) +{ + if (variant == LIL_ABADDON) return reconstruction_missing("Entity_Familiar::ai_incubus_shot 0062d300 (Lil Abaddon)"); + if (variant != LIL_MONSTRO) + { + FireBrimstone(aim, BRIMSTONE_OWN); + return; + } + + Vector spray = vector_scale(aim, MONSTRO_SPRAY_SCALE); + for (int tear = 0; tear < MONSTRO_SPRAY_TEARS; tear++) FireProjectile(spray, mode); + int sound = (~Random() & 1) + SOUND_BOSS_GURGLE_ROAR; + familiar_sound_play(sound, {.volume = MONSTRO_SPRAY_VOLUME, .frameDelay = 2}); + headFrameDelay = MONSTRO_HEAD_FRAMES; + PlayShootAnim(lastDirection); +} diff --git a/src/familiar_walker.cpp b/src/familiar_walker.cpp index e9e2d77..4f4c750 100644 --- a/src/familiar_walker.cpp +++ b/src/familiar_walker.cpp @@ -3,7 +3,11 @@ #include "entity_familiar.h" #include "entity_player.h" #include "game.h" +#include "entity_npc.h" +#include "grid_entity.h" #include "npc_ai.h" +#include "room.h" +#include "room_grid.h" #include // The walkers' hunt: their reach grows with their contact damage, and they head home once this far from the one @@ -104,3 +108,243 @@ void Entity_Familiar::ai_walker() friction *= WALKER_FRICTION; walker_animate(*this, isChasing); } + +// A blue spider's search: its reach and how often, a player's jitter, and how far a wandering spider strays. +constexpr float SPIDER_TARGET_RANGE = 240; +constexpr int SPIDER_TARGET_INTERVAL = 13; +constexpr float SPIDER_PLAYER_JITTER = 30; +constexpr int SPIDER_IDLE_FRAMES = 13; +constexpr float SPIDER_CHASE_REACH = 100; +constexpr float SPIDER_WANDER_MIN = 70; +constexpr float SPIDER_WANDER_RANGE = 40; +constexpr int SPIDER_WALK_FRAMES = 15; +constexpr int SPIDER_SHORTCUT_ODDS = 20; +constexpr float SPIDER_LEAD = 5; + +// Its walk: the margins its wandering stays inside, when it arrives or gives up, its push and friction. +constexpr float SPIDER_MARGIN_TOP = 70; +constexpr float SPIDER_MARGIN_RIGHT = 40; +constexpr float SPIDER_MARGIN_BOTTOM = 60; +constexpr float SPIDER_MARGIN_LEFT = 60; +constexpr float SPIDER_ARRIVED = 14; +constexpr float SPIDER_STUCK_SPEED = 3; +constexpr float SPIDER_PUSH = 6; +constexpr float BLUE_SPIDER_FRICTION = 0.6f; + +// A thrown blue spider: its lift, the fall back, and where a throw with no target lands. +constexpr float SPIDER_THROW_LIFT = -8; +constexpr float SPIDER_FALL = 0.7f; +constexpr float SPIDER_THROW_SPEED = 0.04f; +constexpr float SPIDER_THROW_SPOT_STEP = 80; +constexpr float SPIDER_THROW_SCATTER = 20; + +// Whether the floor is free at a position. +static bool spider_floor_free(Room& room, Vector position) +{ + return room.GetGridCollision(room.GetGridIndex(position)) == COLLISION_NONE; +} + +// Where a blue spider heads when it has waited long enough: near its goal and in sight, it leads the goal's motion +// (the player's twice as far), else it wanders to a free spot in sight, now and then one only half in sight. +static void spider_destination_pick(Entity_Familiar& spider, Vector goal) +{ + Room& room = *g_game->room; + float distance = vector_length(vector_sub(goal, spider.pos)); + if (random_unit() * SPIDER_CHASE_REACH + SPIDER_CHASE_REACH > distance && + room_check_line(spider.pos, goal, LINE_MODE_CELL, 0)) + { + Entity* lead = spider.target ? spider.target : spider.player; + if (!lead) return; + + float scale = spider.target ? SPIDER_LEAD : SPIDER_LEAD * 2; + spider.targetPosition = vector_add(goal, vector_scale(lead->velocity, scale)); + return; + } + + Vector direction = random_direction(); + Vector spot = vector_add(spider.pos, vector_scale(direction, random_unit() * SPIDER_WANDER_RANGE + SPIDER_WANDER_MIN)); + spot = room.GetClampedPositionImpl(spot, SPIDER_MARGIN_TOP, SPIDER_MARGIN_RIGHT, SPIDER_MARGIN_BOTTOM, + SPIDER_MARGIN_LEFT); + if (!spider_floor_free(room, spot)) return; + + bool isInSight = room_check_line(spot, spider.pos, LINE_MODE_GROUND, 0); + if (!isInSight && Random() % SPIDER_SHORTCUT_ODDS == 0) + { + Vector near = vector_add(vector_scale(spider.pos, 0.9f), vector_scale(spot, 0.1f)); + Vector far = vector_add(vector_scale(spider.pos, 0.1f), vector_scale(spot, 0.9f)); + isInSight = room_check_line(far, near, LINE_MODE_CELL, 0); + } + if (!isInSight) return; + + spider.targetPosition = spot; + spider.counter = SPIDER_WALK_FRAMES; +} + +// 00616050 FamiliarAI::blue_spider: a thrown spider arcs down first. Then it picks an enemy now and then, waits a +// little, and walks to a spot near its enemy (or the nearest player) or wanders off. +void blue_spider_update(Entity_Familiar& spider) +{ + if (spider.posOffset.y < 0 || spider.orbitSpeed < 0) + { + spider.entityGridCollisionClass = GRIDCOLL_WALLS; + spider.entityCollisionClass = ENTCOLL_NONE; + spider.velocity = spider.orbitDistance; + spider.orbitSpeed += SPIDER_FALL; + spider.posOffset.y += spider.orbitSpeed; + if (spider.posOffset.y <= -spider.orbitSpeed) return; + + spider.posOffset.y = 0; + spider.orbitSpeed = 0; + spider.targetPosition = {}; + spider.entityCollisionClass = ENTCOLL_ENEMIES; + spider.entityGridCollisionClass = GRIDCOLL_GROUND; + return; + } + if (spider.sprite.IsPlaying("Appear")) return; + + if (Random() % 3 == 0) spider.PickEnemyTarget({.range = SPIDER_TARGET_RANGE, .frameInterval = SPIDER_TARGET_INTERVAL}); + Entity_Player* nearest = game_nearest_player(spider.pos); + Vector goal{}; + if (spider.target) goal = spider.target->pos; + else + { + goal.y = (random_unit() * 2 - 1) * SPIDER_PLAYER_JITTER + nearest->pos.y; + goal.x = (random_unit() * 2 - 1) * SPIDER_PLAYER_JITTER + nearest->pos.x; + } + + bool isVersus = familiar_versus(); + if (vector_is_zero(spider.targetPosition)) + { + spider.sprite.Play(isVersus ? "Idle_Deathmatch" : "Idle"); + if (spider.counter++ > SPIDER_IDLE_FRAMES) spider_destination_pick(spider, goal); + } + else + { + spider.counter--; + spider.sprite.Play(isVersus ? "Walk_Deathmatch" : "Walk"); + Vector way = vector_sub(spider.targetPosition, spider.pos); + if (vector_length(way) < SPIDER_ARRIVED || + (vector_length(spider.velocity) < SPIDER_STUCK_SPEED && spider.counter < 0)) + { + spider.targetPosition = {}; + spider.counter = 0; + } + spider.velocity = vector_add(spider.velocity, vector_scale(vector_normalized(way), SPIDER_PUSH / spider.friction)); + spider.sprite.isFlipX = spider.velocity.x < 0; + } + spider.friction *= BLUE_SPIDER_FRICTION; + spider.entityCollisionClass = ENTCOLL_ENEMIES; + spider.entityGridCollisionClass = GRIDCOLL_GROUND; +} + +// 00638e30 Throws a blue spider from a position toward a target (a scattered free spot near the position for none): it +// arcs there untouchable, without its appear poof. +Entity_Familiar* spawn_blue_spider(const Vector& position, Entity* spawner, Vector target) +{ + if (vector_is_zero(target)) + { + Vector spot = room_free_pickup_position_find( + {.position = position, .step = SPIDER_THROW_SPOT_STEP, .isAvoidActiveEntities = true}); + float angle = random_unit() * RANDOM_HALF_TURN; + angle += angle; + float distance = random_unit(); + target = vector_add(spot, vector_scale(vector_make(std::cos(angle), std::sin(angle)), distance * SPIDER_THROW_SCATTER)); + } + + Vector velocity = vector_scale(vector_sub(target, position), SPIDER_THROW_SPEED); + auto* spider = static_cast(g_game->Spawn({.position = position, + .velocity = velocity, + .spawner = spawner, + .type = ENTITY_FAMILIAR, + .variant = Entity_Familiar::BLUE_SPIDER, + .seed = Random()})); + spider->flags &= ~FLAG_APPEAR; + spider->targetPosition = target; + spider->orbitSpeed = SPIDER_THROW_LIFT; + spider->orbitDistance = velocity; + spider->entityCollisionClass = ENTCOLL_NONE; + return spider; +} + +// 007bf5f0 Adds a blue spider at a position, without its appear poof. +void Entity_Player::AddBlueSpider(Vector position) +{ + numBlueSpiders++; + Entity* spider = g_game->Spawn({.position = position, + .spawner = this, + .type = ENTITY_FAMILIAR, + .variant = Entity_Familiar::BLUE_SPIDER, + .seed = Random()}); + spider->flags &= ~FLAG_APPEAR; +} + +// 007bf640 Throws a blue spider of the player's from a position toward a target. +Entity_Familiar* Entity_Player::ThrowBlueSpider(Vector position, Vector target) +{ + numBlueSpiders++; + return spawn_blue_spider(position, this, target); +} + +// 007bf660 Forgets one of the player's blue spiders. +void Entity_Player::RemoveBlueSpider() +{ + numBlueSpiders--; +} + +// Daddy Longlegs: its reach and search, the lead it gives its target, the stomp's range and the frames it hurts on, +// the time it stays put after a stomp, and how far it strays from the player. +constexpr float LONGLEGS_RANGE = 365; +constexpr int LONGLEGS_TARGET_INTERVAL = 13; +constexpr float LONGLEGS_LEAD = 5; +constexpr float LONGLEGS_STOMP_REACH_SQUARED = 900; +constexpr int LONGLEGS_HIT_FIRST = 10; +constexpr int LONGLEGS_HIT_LAST = 31; +constexpr int LONGLEGS_VERSUS_LIFT_FRAME = 17; +constexpr int LONGLEGS_REST_FRAMES = 100; +constexpr float LONGLEGS_LEASH_SQUARED = 6400; +constexpr float LONGLEGS_STOMP_DRAG = 0.5f; +constexpr float LONGLEGS_DRAG = 0.9f; + +// 0061bd50 Daddy Longlegs: rested, it hunts an enemy, leading it, and stomps (an arm or a leg, flipped at random) once +// close. Without a target or while resting it keeps near the player. Its stomp hurts on the frames its foot is down +// (in a versus match only until it lifts), and it rests after. +void Entity_Familiar::ai_daddy_longlegs() +{ + if (fireCooldown == 0) + { + PickEnemyTarget({.range = LONGLEGS_RANGE, .frameInterval = LONGLEGS_TARGET_INTERVAL}); + if (target) + { + Vector toTarget = vector_sub(target->pos, pos); + Vector lead = vector_add(vector_sub(vector_scale(target->velocity, LONGLEGS_LEAD), + vector_scale(velocity, LONGLEGS_LEAD)), + toTarget); + velocity = vector_add(velocity, vector_normalized(lead)); + if (vector_length_squared(toTarget) < LONGLEGS_STOMP_REACH_SQUARED && sprite.IsPlaying("Idle")) + { + sprite.Play(Random() & 1 ? "StompArm" : "StompLeg"); + sprite.isFlipX = (Random() & 1) == 0; + } + } + } + if (!target || (fireCooldown >= 1 && fireCooldown <= LONGLEGS_REST_FRAMES - 2)) + { + Vector toPlayer = vector_sub(player->pos, pos); + if (vector_length_squared(toPlayer) > LONGLEGS_LEASH_SQUARED) + velocity = vector_add(velocity, vector_normalized(toPlayer)); + } + if (!sprite.animState.animData || !sprite.animState.isPlaying) sprite.Play("Idle"); + if (fireCooldown > 0) fireCooldown--; + + int frame = sprite.animState.animData ? (int)std::floor(sprite.animState.animFrame) : 0; + if (frame >= LONGLEGS_HIT_FIRST && frame <= LONGLEGS_HIT_LAST) + { + bool isLifted = familiar_versus() && sprite.GetFrame() >= LONGLEGS_VERSUS_LIFT_FRAME; + entityCollisionClass = isLifted ? ENTCOLL_NONE : ENTCOLL_ENEMIES; + fireCooldown = LONGLEGS_REST_FRAMES; + velocity = vector_scale(velocity, LONGLEGS_STOMP_DRAG); + return; + } + entityCollisionClass = ENTCOLL_NONE; + velocity = vector_scale(velocity, LONGLEGS_DRAG); +} diff --git a/src/game.h b/src/game.h index fcb64d6..21a0ee7 100644 --- a/src/game.h +++ b/src/game.h @@ -67,6 +67,7 @@ enum GameStateFlag : int GAME_STATE_HEAVEN_PATH = 19, GAME_STATE_KRAMPUS_SPAWNED = 29, GAME_STATE_BOSSRUSH_DONE = 33, + GAME_STATE_SUPERBUM_APPEARED = 37, GAME_STATE_BOSSRUSH_DOOR_SPAWNED = 38, GAME_STATE_BLUEWOMB_DOOR_SPAWNED = 39, GAME_STATE_BLUEWOMB_DONE = 40, diff --git a/src/game_restore.cpp b/src/game_restore.cpp index fa94414..5a9613a 100644 --- a/src/game_restore.cpp +++ b/src/game_restore.cpp @@ -597,6 +597,8 @@ void Entity_Player::RestoreGameState(GameStatePlayer& saved) for (PocketItem item : saved.echoChamberItems) echoChamberItems.push_back(item.id); std::ranges::copy(saved.bagOfCraftingContent | std::views::take(bagOfCraftingContent.size()), bagOfCraftingContent.begin()); + bagOfCraftingOutput = saved.bagOfCraftingOutput; + bagOfCraftingPool = saved.bagOfCraftingPool; std::ranges::copy(saved.poopSpellQueue | std::views::take(poopSpellQueue.size()), poopSpellQueue.begin()); poopMana = saved.poopMana; effectiveBloodCharge = saved.effectiveBloodCharge; diff --git a/src/game_save.cpp b/src/game_save.cpp index 2cd3242..c7a7261 100644 --- a/src/game_save.cpp +++ b/src/game_save.cpp @@ -406,6 +406,8 @@ void Entity_Player::StoreGameState(GameStatePlayer* saveState, bool isSaveTempor state.echoChamberItems.clear(); for (int item : echoChamberItems) state.echoChamberItems.push_back({.id = item}); std::copy(bagOfCraftingContent.begin(), bagOfCraftingContent.end(), state.bagOfCraftingContent.begin()); + state.bagOfCraftingOutput = bagOfCraftingOutput; + state.bagOfCraftingPool = bagOfCraftingPool; std::copy(poopSpellQueue.begin(), poopSpellQueue.end(), state.poopSpellQueue.begin()); state.poopMana = poopMana; state.effectiveBloodCharge = effectiveBloodCharge; diff --git a/src/grid_entity.cpp b/src/grid_entity.cpp index 8efd235..df55306 100644 --- a/src/grid_entity.cpp +++ b/src/grid_entity.cpp @@ -263,6 +263,13 @@ bool GridEntity::IsBreakableRock() } } +// 0070bf80 Whether a grid entity covers the floor in a way nothing may hide: a trapdoor, stairs, a pressure plate or a +// teleporter. +bool is_grid_floor_special(GridEntityType type) +{ + return type == GRID_TRAPDOOR || type == GRID_STAIRS || type == GRID_PRESSURE_PLATE || type == GRID_TELEPORTER; +} + // 0070bec0 Whether a crushing entity walks through without harm: a free cell, a breakable rock or poop but red poop. bool GridEntity::IsEasyCrushableOrWalkable() { diff --git a/src/grid_entity.h b/src/grid_entity.h index aab82ef..7cfd4a3 100644 --- a/src/grid_entity.h +++ b/src/grid_entity.h @@ -59,13 +59,6 @@ constexpr int GRID_PATH_SOLID = 1000; constexpr uint32_t GRID_SEED_DEFAULT = 0x16a9de81; constexpr RNG GRID_RNG_DEFAULT = {0xaa17414f, 5, 9, 7}; -// How water clips around a grid entity (REPENTOGON's WaterClipInfo): which sides, and how far. -struct WaterClipInfo -{ - uint32_t flags = 0; - float value = 0; -}; - // The water clips the grid entities use. constexpr uint32_t WATER_CLIP_SOLID = 0x39; constexpr uint32_t WATER_CLIP_FLAT = 0x26; @@ -132,4 +125,5 @@ struct GridEntity }; GridEntity* CreateGridEntity(GridEntityType type, int gridIndex); +bool is_grid_floor_special(GridEntityType type); void grid_sound_play(int sound, SoundPlay play = {}); diff --git a/src/grid_entity_rock.cpp b/src/grid_entity_rock.cpp index 4ed301d..95f6586 100644 --- a/src/grid_entity_rock.cpp +++ b/src/grid_entity_rock.cpp @@ -1,9 +1,11 @@ #include "grid_entity_rock.h" #include "entity_bomb.h" #include "entity_effect_combat.h" +#include "entity_familiar.h" #include "entity_pickup.h" #include "entity_player.h" #include "npc_ai.h" +#include "npc_alt.h" #include "game.h" #include "log.h" #include "manager.h" @@ -97,6 +99,7 @@ constexpr float TINTED_SOUL_CHANCE = 0.6f; constexpr float TINTED_KEY_CHANCE = 0.7f; constexpr float TINTED_CHEST_CHANCE = 0.71f; constexpr float TINTED_LOCKED_CHEST_CHANCE = 0.9f; +constexpr float TINTED_SPIDER_HEIGHT = -10; constexpr uint32_t KEEPERS_KIN_SPIDERS = 3; constexpr int DIMENSION_DEATH_CERTIFICATE_ROCKS = 2; @@ -895,8 +898,7 @@ static void tinted_drops_spawn(const Vector& position, GridEntityType type, RNG& if (roll < TINTED_SOUL_CHANCE && (!tail || tail->Next() % DAEMONS_TAIL_ODDS == 0)) { if (is_mines_stage() && (dropRng._seed & 1) == 0) - reconstruction_missing("GridEntity_Rock::SpawnDrops 0071b410: a tinted rock's rock spider " - "(Entity_NPC::ThrowRockSpider 004f9920)"); + rock_spider_throw(position, velocity, nullptr, SPIDER_THROW_TINTED, TINTED_SPIDER_HEIGHT); else g_game->Spawn({.position = position, .velocity = velocity, .subType = HEART_SOUL, .type = ENTITY_PICKUP, .variant = PICKUP_HEART, .seed = dropRng.Next()}) @@ -941,9 +943,7 @@ static void keepers_kin_spiders_spawn(const Vector& position, uint32_t seed, Ent for (; spiders > 0; spiders--) { owner->numBlueSpiders++; - Vector at = position; - Vector still{}; - spawn_blue_spider(&at, owner, &still); + spawn_blue_spider(position, owner, {}); } } diff --git a/src/homing_laser.cpp b/src/homing_laser.cpp index 999b3ad..0bf2d45 100644 --- a/src/homing_laser.cpp +++ b/src/homing_laser.cpp @@ -1,6 +1,7 @@ #include "homing_laser.h" #include "boss_ai.h" #include "entity_familiar.h" +#include "entity_knife.h" #include "entity_laser.h" #include "entity_player.h" #include "entity_tear.h" @@ -27,6 +28,19 @@ constexpr size_t HUNT_MAX_POINTS = 25; constexpr float HUNT_TENSION = 0.4f; constexpr float HUNT_MIN_LENGTH_SQUARED = 0.01f; +// A homing path: up to six points, pulled only off segments at least 120 long and not within 80 of their ends. +constexpr size_t HOMING_MAX_POINTS = 6; +constexpr float HOMING_SEGMENT_MIN_SQUARED = 14400; +constexpr float HOMING_END_CLEARANCE_SQUARED = 6400; + +// Eye of the Occult's bend: the thirds of the curve, the margin its end keeps from the wall, its handles' length and +// the kink near the start of a player's loop. +constexpr float OCCULT_THIRD = 0.333f; +constexpr float OCCULT_TWO_THIRDS = 0.666f; +constexpr float OCCULT_WALL_MARGIN = 20; +constexpr float OCCULT_HANDLE = 50; +constexpr float OCCULT_KINK = 35; + // A point on the cubic curve from one bezier point to the next, t from 0 to 1. static Vector bezier_evaluate(const BezierPoint& from, const BezierPoint& to, float t) { @@ -165,9 +179,122 @@ static void homing_hunt(HomingLaser& path, const std::vector& targets) path.compute_bezier_handles(HUNT_TENSION); } +// Eye of the Occult's bend for a laser no player aims: a curve through the target, a third and two thirds of the way +// along the straight beam stretched to the target's distance, going on past the target to the wall. +static void occult_curve(HomingLaser& path, const Vector& target) +{ + Vector origin = path.origin; + Vector toTarget = vector_sub(target, origin); + Vector line = vector_sub(path.endPoint, origin); + float lineLength = vector_length(line); + if (lineLength > 0) line = vector_scale(line, vector_length(toTarget) / lineLength); + + Vector stretched = vector_sub(vector_add(origin, line), origin); + auto blend = [&](float t) { + Vector along = vector_add(vector_scale(stretched, t), origin); + return vector_add(vector_scale(vector_sub(vector_add(vector_scale(toTarget, t), origin), along), t), along); + }; + Vector first = blend(OCCULT_THIRD); + Vector second = blend(OCCULT_TWO_THIRDS); + path.endPoint = Entity_Laser::CalculateEndPoint(target, vector_sub(target, second), {}, nullptr, OCCULT_WALL_MARGIN); + + Vector beyond = vector_sub(path.endPoint, target); + path.bezier.clear(); + path.bezier.push_back({origin, origin, first}); + path.bezier.push_back({target, second, vector_add(vector_scale(beyond, OCCULT_THIRD), target)}); + path.bezier.push_back({path.endPoint, vector_add(vector_scale(beyond, OCCULT_TWO_THIRDS), target), path.endPoint}); +} + +// Eye of the Occult's bend for a player's laser: the path's last point is swung out past a kink near its start, then +// through the target and back to where it ended, with axis-aligned handles. +static void occult_loop(HomingLaser& path, const Vector& target) +{ + size_t count = path.bezier.size(); + Vector start = count < 2 ? path.origin : path.bezier[count - 2].point; + Vector last = count == 0 ? path.endPoint : path.bezier[count - 1].point; + Vector toTarget = vector_normalized(vector_sub(target, start)); + Vector back = vector_normalized(vector_sub(last, target)); + Vector line = vector_normalized(vector_sub(last, start)); + Vector handle = vector_scale(line, OCCULT_HANDLE); + if (count > 1) path.bezier.pop_back(); + if (path.bezier.empty()) path.bezier.push_back({start, start, vector_add(start, handle)}); + + Vector kink = vector_add(vector_add(vector_make(-line.y, line.x), vector_scale(line, OCCULT_KINK)), start); + path.bezier.push_back({kink, vector_sub(kink, handle), vector_add(kink, vector_scale(toTarget, OCCULT_HANDLE))}); + path.bezier.push_back({target, vector_sub(target, handle), vector_add(target, handle)}); + path.bezier.push_back({last, vector_sub(last, vector_scale(back, OCCULT_HANDLE)), last}); + path.compute_axis_bezier_handles(); +} + +// Eye of the Occult: a laser carrying it bends toward its target position, or its player's Marked target. +static void occult_bend(HomingLaser& path) +{ + Entity_Laser* laser = path.owner && path.owner->type == ENTITY_LASER ? static_cast(path.owner) : nullptr; + if (!laser || !laser->tearFlags[TEAR_OCCULT]) return; + + Vector target = laser->targetPosition; + Entity* spawner = laser->spawnerEntity; + Entity_Player* player = spawner && spawner->is_player() ? spawner->ToPlayer() : nullptr; + if (player && player->markedTarget) target = player->markedTarget->pos; + if (vector_is_zero(target)) return; + if (player) occult_loop(path, target); + else occult_curve(path, target); +} + +// A homing straight path pulls a point onto each target it passes near (closer than the reach, ahead of the point and +// not within 80 of either end of a segment at least 120 long), up to six points. A longer path moves its inner points +// onto the targets they pass near instead. +static void homing_bend(HomingLaser& path, std::vector& targets) +{ + float reachSquared = path.reach * path.reach; + float unusedT = 0; + if (path.bezier.size() != 2) + { + bool isMoved = false; + for (size_t i = 1; i + 1 < path.bezier.size(); i++) + for (auto target = targets.begin(); target != targets.end(); target++) + { + Vector spot = (*target)->pos; + if (bezier_closest_point(spot, path.bezier[i], path.bezier[i + 1], unusedT) >= reachSquared) continue; + path.bezier[i].point = spot; + targets.erase(target); + isMoved = true; + break; + } + if (isMoved) path.compute_axis_bezier_handles(); + return; + } + + bool isInserted = true; + while (isInserted && path.bezier.size() < HOMING_MAX_POINTS) + { + isInserted = false; + for (size_t segment = 0; segment + 1 < path.bezier.size() && !isInserted; segment++) + { + BezierPoint& from = path.bezier[segment]; + Vector to = path.bezier[segment + 1].point; + if (vector_length_squared(vector_sub(to, from.point)) < HOMING_SEGMENT_MIN_SQUARED) continue; + for (auto target = targets.begin(); target != targets.end(); target++) + { + Vector spot = (*target)->pos; + if (bezier_closest_point(spot, from, path.bezier[segment + 1], unusedT) >= reachSquared) continue; + bool isAhead = vector_dot(vector_sub(from.handleOut, from.point), vector_sub(spot, from.point)) > 0; + if (!isAhead || vector_length_squared(vector_sub(spot, from.point)) <= HOMING_END_CLEARANCE_SQUARED || + vector_length_squared(vector_sub(spot, to)) <= HOMING_END_CLEARANCE_SQUARED) + continue; + path.bezier.insert(path.bezier.begin() + (long)segment + 1, {spot, {}, {}}); + targets.erase(target); + isInserted = true; + path.compute_axis_bezier_handles(); + break; + } + } + } +} + // 0099c790 Lays out the path's bezier points: a straight one from the origin to the end unless some are already -// there, then for a path that hits players one hunting its targets. Eye of the Occult's bend and the homing and -// other types' bends toward their targets are not reconstructed yet. +// there, bent by Eye of the Occult, then toward its targets for a homing path, through every target of another type +// for that path type, or hunting its targets for a path that hits players. void HomingLaser::build_bezier_path(BezierPathType pathType, Entity* source) { if (bezier.empty()) @@ -179,12 +306,14 @@ void HomingLaser::build_bezier_path(BezierPathType pathType, Entity* source) std::vector targets; if (pathType != BEZIER_PATH_STRAIGHT) targets = homing_targets_get(pathType, source); - Entity_Laser* laser = owner && owner->type == ENTITY_LASER ? static_cast(owner) : nullptr; - if (laser && laser->tearFlags[TEAR_OCCULT]) - reconstruction_missing("HomingLaser::build_bezier_path 0099c790: Eye of the Occult's bend"); - if (pathType == BEZIER_PATH_HOMING || pathType == BEZIER_PATH_OTHER_TYPES) - reconstruction_missing("HomingLaser::build_bezier_path 0099c790: a homing path"); - if (pathType == BEZIER_PATH_WITH_PLAYERS && bezier.size() == 2) homing_hunt(*this, targets); + occult_bend(*this); + if (pathType == BEZIER_PATH_HOMING) homing_bend(*this, targets); + else if (pathType == BEZIER_PATH_OTHER_TYPES && bezier.size() == 2) + { + for (Entity* target : targets) bezier.insert(bezier.end() - 1, {target->pos, {}, {}}); + compute_axis_bezier_handles(); + } + else if (pathType == BEZIER_PATH_WITH_PLAYERS && bezier.size() == 2) homing_hunt(*this, targets); } // 0099e360 Samples the bezier path evenly along its length, then eases the kept samples toward them: a ring all at @@ -361,12 +490,46 @@ Entity* HomingLaser::find_targets(Vector& outPosition, Vector& outDirection, int return nullptr; } -// The path shapes of the tear flags and homing are not reconstructed yet. +// The axis a vector leans along most, keeping its length along it (vertical on a tie). +static Vector vector_axis_part(Vector v) +{ + return std::fabs(v.x) <= std::fabs(v.y) ? vector_make(0, v.y) : vector_make(v.x, 0); +} -// 0099dca0 +// 0099dca0 Gives the path right-angled handles: the first point's out handle runs along the axis its handle leans +// along, half way to the next point. Each inner point's handles run across the axis its neighbours' directions add +// up along, toward the previous point, half way to each neighbour (twice as far when the previous point's handle +// points away from it). The last point's in handle runs half way along the axis toward the point before it. void HomingLaser::compute_axis_bezier_handles() { - reconstruction_missing("HomingLaser::compute_axis_bezier_handles 0099dca0"); + if (bezier.size() < 2) return; + + BezierPoint& first = bezier[0]; + Vector firstAxis = vector_cardinal(vector_sub(first.handleOut, first.point)); + Vector firstReach = vector_scale(firstAxis, vector_length(vector_sub(bezier[1].point, first.point)) * BEZIER_HALF); + first.handleOut = vector_add(first.point, firstReach); + bezier[1].handleIn = vector_sub(bezier[1].point, firstReach); + + for (size_t i = 1; i + 1 < bezier.size(); i++) + { + BezierPoint& previous = bezier[i - 1]; + BezierPoint& point = bezier[i]; + Vector toPrevious = vector_sub(previous.point, point.point); + Vector toNext = vector_sub(bezier[i + 1].point, point.point); + float nextLength = vector_length(toNext); + Vector sum = vector_add(vector_normalized(toNext), vector_normalized(toPrevious)); + Vector axis = vector_cardinal(sum); + Vector across = vector_make(axis.y, -axis.x); + if (vector_dot(toPrevious, across) < 0) across = vector_scale(across, -1); + if (vector_dot(vector_sub(previous.handleOut, previous.point), vector_sub(point.point, previous.point)) < 0) + across = vector_scale(across, 2); + point.handleOut = vector_add(point.point, vector_scale(across, -nextLength * BEZIER_HALF)); + point.handleIn = vector_add(point.point, vector_scale(across, vector_length(toPrevious) * BEZIER_HALF)); + } + + BezierPoint& last = bezier.back(); + Vector toPrevious = vector_axis_part(vector_sub(bezier[bezier.size() - 2].point, last.point)); + last.handleIn = vector_add(last.point, vector_scale(toPrevious, BEZIER_HALF)); } // 0099e160 Smooths the path: each point's handles lie along the line from its neighbours, scaled by the tension diff --git a/src/hud.cpp b/src/hud.cpp index 53f15d1..df3385a 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -9,9 +9,13 @@ #include "platform.h" #include "render_passes.h" #include "room.h" +#include "string_table.h" #include #include +#include #include +#include +#include constexpr const char* MPLUS_FONT = "font/MPlus_12b.fnt"; constexpr const char* KOREAN_FONT = "font/KR_Font14.fnt"; @@ -68,6 +72,14 @@ constexpr KAGE::Graphics::BlendMode BLEND_MODE_PREMULTIPLIED = { constexpr int FILTER_LINEAR = 1; constexpr int CHARGE_BAR_FLASH_FRAMES = 8; constexpr int SOUND_FORTUNE_PAPER = 252; + +// The fortune paper's writing: the width a wrapped line fits, the line height, the size past which the text halves, +// and the mark that breaks a fortune's lines. +constexpr int FORTUNE_LINE_WIDTH = 270; +constexpr float FORTUNE_LINE_HEIGHT = 21; +constexpr int FORTUNE_MAX_WIDTH = 273; +constexpr float FORTUNE_MAX_HEIGHT = 63; +constexpr char FORTUNE_LINE_BREAK = '|'; constexpr float FORTUNE_SOUND_VOLUME = 0.5f; constexpr float FORTUNE_SLIDE_IN_PITCH = 1.5f; constexpr float STATS_ALPHA = 0.5f; @@ -650,27 +662,131 @@ void HUD::ShowStackedItemTextCustom(const char* title, const char* subtitle) } // 0085eca0 Lua's HUD:ShowFortuneText: shows a fortune's lines on the fortune paper. -void HUD::ShowFortuneText(const std::vector&) +void HUD::ShowFortuneText(const std::vector& lines) { - reconstruction_missing("HUD::ShowFortuneText 0085eca0"); + render_fortune_text(lines); } -// 009a3590 Shows one fortune line. -void HUD::show_fortune_line(const char*) +// 009a3590 Shows one line on the fortune paper (a curse's name, a notice). +void HUD::show_fortune_line(const char* text) { - reconstruction_missing("HUD::show_fortune_line 009a3590"); + render_fortune_text({text}); } -// 009a36d0 Splits a fortune into lines and shows them. -void HUD::show_fortune_text_impl(const char*) +// The font the fortune paper writes in: the HUD's own, the Korean one, or Upheaval when neither loaded. +static Font& fortune_font(HUD& hud) { - reconstruction_missing("HUD::show_fortune_text_impl 009a36d0"); + if (hud.font.isLoaded) return hud.font; + return hud.fontKR.isLoaded ? hud.fontKR : g_manager->font7_Upheaval; } -// 009a3ac0 Draws a fortune's lines into the fortune surface. -void HUD::render_fortune_text(const std::vector&) +// 009a36d0 Shows a text on the fortune paper wrapped into lines that fit it, breaking after the last space before the +// edge, or inside a word with no space. +void HUD::show_fortune_text_impl(const char* text) { - reconstruction_missing("HUD::render_fortune_text 009a3ac0"); + Font& font = fortune_font(*this); + std::vector lines; + const char* end = text + std::strlen(text); + const char* lineStart = text; + const char* lastSpace = text; + int width = 0; + for (const char* cursor = text; cursor < end;) + { + uint32_t character = 0; + const char* next = utf8_decode_next(cursor, &character, end); + if (!character) break; + + if (std::iswspace((wint_t)character)) lastSpace = cursor; + width += font.GetStringWidth(std::string_view(cursor, (size_t)(next - cursor))); + if (width <= FORTUNE_LINE_WIDTH) + { + cursor = next; + continue; + } + + bool isAtSpace = lastSpace != lineStart; + lines.emplace_back(lineStart, isAtSpace ? lastSpace : cursor); + if (isAtSpace) cursor = utf8_decode_next(lastSpace, &character, end); + lineStart = cursor; + lastSpace = cursor; + width = 0; + } + lines.emplace_back(lineStart, end); + render_fortune_text(lines); +} + +// 009a3ac0 Writes a fortune's lines centred into the fortune surface in black, at half size when they are too wide or +// too many, and plays the paper that fits them (Text, Text2 or Text3). No lines leave the plain paper, empty. +void HUD::render_fortune_text(const std::vector& lines) +{ + KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; + Font& font = fortune_font(*this); + float textScale = 1; + float lineHeight = FORTUNE_LINE_HEIGHT; + int maxWidth = 0; + for (const std::string& line : lines) maxWidth = std::max(maxWidth, font.GetStringWidth(line)); + + float textHeight = (float)lines.size() * FORTUNE_LINE_HEIGHT; + if (maxWidth > FORTUNE_MAX_WIDTH || textHeight > FORTUNE_MAX_HEIGHT) + { + textScale = 0.5f; + lineHeight = FORTUNE_LINE_HEIGHT * 0.5f; + textHeight *= 0.5f; + } + const char* paper = textHeight > FORTUNE_LINE_HEIGHT * 2 ? "Text3" : textHeight > FORTUNE_LINE_HEIGHT ? "Text2" : "Text"; + fortuneSprite.Play(lines.empty() ? "Text" : paper, PLAY_FORCED); + if (!fortuneTextImage) return; + + graphics.render_target_push(fortuneTextImage.get(), KAGE::Graphics::TARGET_OWN_SIZE, KAGE::Graphics::PRESENT_FLUSH); + graphics.Clear(); + if (!lines.empty()) + { + graphics.blendMode = BLEND_MODE_PREMULTIPLIED; + FontSettings settings(ALIGN_TOP_CENTER); + float centerX = (float)fortuneTextImage->width * 0.5f; + float y = 0; + for (const std::string& line : lines) + { + font.DrawString(line, vector_make(centerX, y), vector_make(textScale, textScale), BLACK, settings); + y += lineHeight; + } + graphics.Present(KAGE::Graphics::PRESENT_FINISH); + } + graphics.render_target_pop(KAGE::Graphics::PRESENT_FLUSH); +} + +// 009807a0 (Game::ShowFortuneText) A random line of a string table category on the fortune paper, its '|' marks +// starting new lines. +void fortune_text_show(RNG& rng, std::string_view category) +{ + StringTable& table = g_manager->stringTable; + std::string key(category); + std::ranges::transform(key, key.begin(), [](unsigned char c) { return (char)std::tolower(c); }); + auto found = table.categories.find(key); + size_t count = found == table.categories.end() ? 0 : found->second.keys.size(); + std::string_view text = table.get_string_by_index(category, table.language, rng.RandomInt((uint32_t)count)); + + std::vector lines; + std::string line; + for (char character : text) + { + if (character != FORTUNE_LINE_BREAK) + { + line += character; + continue; + } + lines.push_back(line); + line.clear(); + } + if (!line.empty()) lines.push_back(line); + g_game->hud.render_fortune_text(lines); +} + +// (005b1870, 0065d070, 00753d00 Game::ShowFortune, the seeds' fortune and Game::ShowRule) A line of a fortune category +// from the run's fortune generator. +void fortune_show(std::string_view category) +{ + fortune_text_show(g_game->fortuneRNG, category); } // 009a3eb0 Draws the HUD unless it is hidden or the run plays "No HUD": the recent items and minimap, the Boss Rush diff --git a/src/hud.h b/src/hud.h index b7f7b0b..c66620c 100644 --- a/src/hud.h +++ b/src/hud.h @@ -15,6 +15,8 @@ #include #include +struct RNG; + constexpr int MESSAGE_STACK_COUNT = 6; constexpr int HISTORY_PLAYER_COUNT = 2; constexpr float BOSS_BAR_HIDDEN = -1; @@ -178,7 +180,7 @@ public: void ShowFortuneText(const std::vector& lines); void show_fortune_line(const char* text); void show_fortune_text_impl(const char* text); - void render_fortune_text(const std::vector& lines); + void render_fortune_text(const std::vector& lines); void Render(); void render_counters(Vector& cursor, Vector shake); @@ -197,3 +199,11 @@ public: int count_player_huds(); void AssignPlayerHUDs(); }; + +// The stringtable categories a fortune is drawn from. +constexpr std::string_view FORTUNE_GENERAL = "Fortune_General"; +constexpr std::string_view FORTUNE_SEEDS = "Fortune_Seeds"; +constexpr std::string_view FORTUNE_RULES = "Fortune_Rules"; + +void fortune_text_show(RNG& rng, std::string_view category); +void fortune_show(std::string_view category); diff --git a/src/item_config.h b/src/item_config.h index 0934ede..2131020 100644 --- a/src/item_config.h +++ b/src/item_config.h @@ -182,8 +182,9 @@ using ColorPresets = std::map>; struct ItemConfig_Item; struct ModEntry; -// A pill subtype's color bits and its horse pill bit. +// A pill subtype's color bits, the golden pill's color and its horse pill bit. constexpr int PILL_COLOR_MASK = 0x7ff; +constexpr int PILL_COLOR_GOLD = 14; constexpr uint32_t PILL_HORSE_FLAG = 0x800; // A costume an item, form or null item puts on the player: its .anm2 and how it draws over the others. diff --git a/src/item_pickup.cpp b/src/item_pickup.cpp index d7d83d5..8ec8a27 100644 --- a/src/item_pickup.cpp +++ b/src/item_pickup.cpp @@ -14,8 +14,10 @@ #include "room.h" #include "room_grid.h" #include "room_special.h" +#include "room_state.h" #include "seeds.h" #include +#include #include // The items, characters, rooms and unlocks the pedestals ask about. @@ -25,6 +27,8 @@ constexpr int COLLECTIBLE_PEDESTAL_POLAROID = 327; constexpr int COLLECTIBLE_PEDESTAL_NEGATIVE = 328; constexpr float RESTOCK_PEDESTAL_STEP = 10; constexpr int RESTOCK_PEDESTAL_WAIT = 20; +constexpr float CAIN_POOF_DROP = 10; +constexpr int CAIN_PEDESTAL_TIMEOUT = 2; constexpr int COLLECTIBLE_BROKEN_SHOVEL_A = 550; constexpr int COLLECTIBLE_BROKEN_SHOVEL_B = 551; constexpr int COLLECTIBLE_KNIFE_PIECE_A = 626; @@ -42,6 +46,15 @@ constexpr int PEDESTAL_MEGA_CHEST_B = 19; constexpr int PEDESTAL_LAYER = 1; constexpr int PEDESTAL_WAIT = 20; constexpr int PEDESTAL_INVISIBLE_FRAMES = 3; +// Flip's other item flickers at 5 to 20% over the pedestal, drawn 2.6 pixels up and left, the item shifted as far down. +constexpr float FLIP_ALPHA_MIN = 0.05f; +constexpr float FLIP_ALPHA_RANGE = 0.15f; +constexpr float FLIP_GHOST_SHIFT = 2.6f; +constexpr float FLIP_RANDOM_UNIT = 2.3283062e-10f; +constexpr uint32_t FLIP_FLICKER_SEED = 0x194fc4ad; +constexpr uint32_t FLIP_FLICKER_SHIFTS[3] = {4, 3, 27}; +// Flip gives a pedestal its other item's drop seed with this shift. +constexpr uint32_t FLIP_DROP_SHIFT_INDEX = 35; // The cycles a pedestal starts with: Isaac's Birthright and Tainted Isaac add one item, Glitched Crown four. constexpr int CYCLE_BIRTHRIGHT = 1; @@ -66,7 +79,6 @@ constexpr int COLLECTIBLE_UNFILTERED_GFX = 633; // The sounds an item makes when taken, by the room it was in. constexpr int SOUND_1UP = 1; constexpr int SOUND_CHOIR_UNLOCK = 23; -constexpr int SOUND_POWERUP2 = 129; constexpr int SOUND_POWERUP3 = 130; constexpr int SOUND_BAND_AID_PICK_UP = 169; constexpr int ONE_UP_FRAME_DELAY = 30; @@ -210,7 +222,11 @@ void Entity_Pickup::pedestal_start() bool isKeeperPriced = players.FirstPlayerByType(PLAYER_KEEPER_B) && !g_pickupIgnoreModifiers && price == 0 && !room.isInitialized && !ItemConfig::IsQuestItem(subtype); - if (isKeeperPriced) reconstruction_missing("Entity_Pickup::Init 006e02f0: Tainted Keeper's prices"); + if (!isKeeperPriced) return; + + shopItemId = -1; + ShopOffer offer = {.shopItemId = shopItemId, .subType = subtype, .variant = PICKUP_COLLECTIBLE}; + price = room_shop_discount(room, shopItemId, room_shop_item_price(room, offer, nullptr), nullptr); } // 006e1e90 Shows a collectible's image on a layer of a sprite: the question mark when blind, a procedural item's icon @@ -288,19 +304,29 @@ uint8_t Entity_Pickup::empty_pedestal() if (variant != PICKUP_COLLECTIBLE || subtype == 0) return false; subtype = 0; - if (price != 0) + if (price == 0) { - if (!flipSaveState || !altPedestalANM2.isLoaded) + if (sprite.SetAnimation("Empty") && sprite.animState.animData) { - Remove(); - return true; + sprite.animState.SetFrameFloat(0); + sprite.animState.isPlaying = false; } - reconstruction_missing("Entity_Pickup::empty_pedestal 006ed580: Flip's bought item"); } - if (sprite.SetAnimation("Empty") && sprite.animState.animData) + else if (!flipSaveState || !altPedestalANM2.isLoaded) { - sprite.animState.SetFrameFloat(0); - sprite.animState.isPlaying = false; + Remove(); + return true; + } + else + { + update_price_sprite(0); + SetAlternatePedestal(0); + sprite.SetFrame("Empty", 0); + if (altPedestalANM2.SetAnimation("Idle")) + { + altPedestalANM2.animState.Rewind(); + altPedestalANM2.animState.isPlaying = true; + } } if (LayerState* shadow = sprite.GetLayer("itemshadow")) shadow->isVisible = false; return true; @@ -320,16 +346,31 @@ void Entity_Pickup::pedestal_update() if (!isVisible && entityCollisionClass != ENTCOLL_NONE && ++invisibleFrames > PEDESTAL_INVISIBLE_FRAMES) isVisible = true; - bool isFlipShown = flipSaveState && is_anyone_owning(COLLECTIBLE_FLIP); - if (isFlipShown) reconstruction_missing("Entity_Pickup::Update 006e3940: Flip's other item"); - if (altPedestalANM2.isLoaded) altPedestalANM2.Reset(); + bool isFlipShown = flipSaveState && g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_FLIP, LAZARUS_SHARE_CHECK); + if (isFlipShown != altPedestalANM2.isLoaded) flip_item_load(isFlipShown); + if (altPedestalANM2.isLoaded) + { + altPedestalANM2.animState.Update(altPedestalANM2.playbackSpeed); + altPedestalANM2.overlayAnimState.Update(altPedestalANM2.playbackSpeed); + } if (subtype == COLLECTIBLE_BROKEN_SHOVEL_A && isTouched) reconstruction_missing("Entity_Pickup::Update 006e3940: the broken shovel"); if (megaChestCollectible[0]) reconstruction_missing("Entity_Pickup::Update 006e3940: a Mega Chest's item"); } +// The flicker of Flip's other item, the original's own static generator. +static RNG flip_flicker_rng() +{ + RNG rng; + rng._seed = FLIP_FLICKER_SEED; + rng._shift1 = FLIP_FLICKER_SHIFTS[0]; + rng._shift2 = FLIP_FLICKER_SHIFTS[1]; + rng._shift3 = FLIP_FLICKER_SHIFTS[2]; + return rng; +} + // The pedestal part of 006e69b0: the pedestal and its Alternates frame at the snapped position, then the item layer -// over them. +// over them. Flip's other item flickers behind the item, which moves aside for it. void Entity_Pickup::pedestal_render(const Vector& offset) { if (megaChestCollectible[0] || megaChestCollectible[1]) @@ -338,15 +379,69 @@ void Entity_Pickup::pedestal_render(const Vector& offset) Vector snapped = render_position_get(vector_make(pos.x + posOffset.x, pos.y + posOffset.y), RENDER_SNAPPED); renderPosition = vector_make(snapped.x + offset.x, snapped.y + offset.y); SpriteDraw draw = {renderPosition, {}, {}}; - if (altPedestalANM2.isLoaded) - reconstruction_missing("Entity_Pickup::Render 006e69b0: Flip's other item"); + float flipShift = 0; + if (altPedestalANM2.isLoaded && g_game->room->entityList.renderMode != RENDER_WATER_REFLECT) + { + static RNG flickerRng = flip_flicker_rng(); + altPedestalANM2.color._tint[3] = (float)flickerRng.Next() * FLIP_RANDOM_UNIT * FLIP_ALPHA_RANGE + FLIP_ALPHA_MIN; + float ghostShift = subtype != 0 ? -FLIP_GHOST_SHIFT : 0; + altPedestalANM2.RenderLayer(PEDESTAL_LAYER, + {vector_make(renderPosition.x + ghostShift, renderPosition.y + ghostShift), {}, {}}); + flipShift = FLIP_GHOST_SHIFT; + } LayerState* item = sprite.GetLayer(PEDESTAL_LAYER); if (item) item->isVisible = false; sprite.overlayAnimState.Render(draw, sprite); sprite.animState.Render(draw, sprite); if (item) item->isVisible = true; - sprite.RenderLayer(PEDESTAL_LAYER, draw); + sprite.RenderLayer(PEDESTAL_LAYER, {vector_make(renderPosition.x + flipShift, renderPosition.y + flipShift), {}, {}}); +} + +// The Flip part of 006e3940: Flip's other item shows over the pedestal while someone holds Flip, a copy of the pedestal +// with the other item's sprite in the same animation, blind under the curse. +void Entity_Pickup::flip_item_load(bool isShown) +{ + if (!isShown) return altPedestalANM2.Reset(); + + altPedestalANM2 = sprite; + bool isBlind = g_game->currentDimensionIdx != DIMENSION_DEATH_CERTIFICATE && + ((g_game->GetCurses() & CURSE_OF_BLIND) || isForceBlind); + load_collectible_gfx(altPedestalANM2, PEDESTAL_LAYER, flipSaveState->subtype, flipSaveState->initSeed, isBlind); + altPedestalANM2.LoadGraphics(); + if (altPedestalANM2.SetAnimation(sprite.GetAnimation())) + { + altPedestalANM2.animState.Rewind(); + altPedestalANM2.animState.isPlaying = true; + } +} + +// 006e1640 Flip on a pedestal holding another item: it turns into that item (its seeds, look, touch and cycle) and +// keeps the one it showed as its other item, unless that was an empty pedestal. +bool Entity_Pickup::TryFlip(Entity_Player*, uint32_t) +{ + if (!flipSaveState || variant != PICKUP_COLLECTIBLE) return false; + + EntitySaveState shown; + entity_state_save(*g_game->room, *this, shown, MINECART_REFUSED); + std::shared_ptr other = flipSaveState; + dropRNG.SetSeed(other->dropSeed, FLIP_DROP_SHIFT_INDEX); + initSeed = other->initSeed; + Morph(other->type, other->variant, other->subtype, true, true, true); + isTouched = other->boolStorage1; + if (other->extraData) + { + auto cycle = std::bit_cast>(*other->extraData); + cycleCollectibleCount = 0; + for (uint32_t collectible : cycle) + { + if (collectible == 0) break; + cycleCollectibleList[cycleCollectibleCount++] = collectible; + } + } + flipSaveState = shown.subtype != 0 ? std::make_shared(shown) : nullptr; + altPedestalANM2.Reset(); + return true; } // The collectible refusals of 006e8ae0: Book of Belial for a player who has its passive, and anything Strawman and @@ -363,6 +458,37 @@ bool Entity_Pickup::is_collectible_refused(Entity_Player& player) return !item || item->type == ITEM_ACTIVE; } +// A bought item's shop slot restocks under Restock or in Greed mode, its pedestal moved aside to wait. Taken, always. +static bool shop_restock_after_take(Entity_Pickup& pickup) +{ + Game& game = *g_game; + bool isRestocked = game.playerManager.AnyoneHasCollectible(COLLECTIBLE_RESTOCK) || game.IsGreedMode(); + if (pickup.price == 0 || !isRestocked || game.room->roomType != ROOM_SHOP) return true; + + room_restock_trigger(*game.room, game.room->GetGridIndex(pickup.pos), pickup.shopItemId); + pickup.pos = room_free_pickup_position_find({pickup.pos, RESTOCK_PEDESTAL_STEP}); + pickup.targetPosition = pickup.pos; + pickup.wait = RESTOCK_PEDESTAL_WAIT; + return true; +} + +// The Tainted Cain part of 006e8ae0: his touch bursts the pedestal into pickups (007d58f0) from the room's pool and +// empties it with a poof at his feet and a thumbs down, adding what he held queued. +static bool tainted_cain_pedestal_break(Entity_Pickup& pickup, Entity_Player& player) +{ + player.tainted_cain_pedestal_burst(pickup.pos, pickup.dropRNG.Next(), POOL_NONE); + pickup.empty_pedestal(); + uint32_t seed = Random(); + g_game->Spawn({.position = vector_make(player.pos.x, player.pos.y + CAIN_POOF_DROP), .type = ENTITY_EFFECT, + .variant = EFFECT_POOF01, .seed = seed}); + pickup.timeout = CAIN_PEDESTAL_TIMEOUT; + int sound = SOUND_THUMBS_DOWN; + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound); + player.FlushQueueItem(); + return shop_restock_after_take(pickup); +} + // The collectible part of 006e8ae0: a free hand takes the item off its pedestal. The item leaves the pools, its sound // and name play, the player lifts it in the pedestal's sprite and queues it to be added, and the pedestal empties, or // takes the active it was exchanged for. Whether it was taken. @@ -380,7 +506,7 @@ bool Entity_Pickup::collectible_collect(Entity_Player& player) game.challenge == CHALLENGE_CANTRIPPED || game.currentDimensionIdx == DIMENSION_DEATH_CERTIFICATE || game.currentRoomIdx == ROOM_GENESIS_IDX; - if (!isKept) reconstruction_missing("Entity_Pickup::HandleCollision 006e8ae0: Tainted Cain's pedestal burst"); + if (!isKept) return tainted_cain_pedestal_break(*this, player); } if (collectibleId == COLLECTIBLE_DADS_NOTE) reconstruction_missing("Entity_Pickup::HandleCollision 006e8ae0: Dad's Note"); @@ -437,14 +563,7 @@ bool Entity_Pickup::collectible_collect(Entity_Player& player) } cycleCollectibleCount = 0; isForceBlind = false; - bool isRestocked = game.playerManager.AnyoneHasCollectible(COLLECTIBLE_RESTOCK) || game.IsGreedMode(); - if (price == 0 || !isRestocked || game.room->roomType != ROOM_SHOP) return true; - - room_restock_trigger(*game.room, game.room->GetGridIndex(pos), shopItemId); - pos = room_free_pickup_position_find({pos, RESTOCK_PEDESTAL_STEP}); - targetPosition = pos; - wait = RESTOCK_PEDESTAL_WAIT; - return true; + return shop_restock_after_take(*this); } // The collectible part of 006e7dc0: a bought item rings like a pickup, 1up and the mushrooms and Super Bandage have diff --git a/src/level.cpp b/src/level.cpp index b4adc5f..a86b4e3 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -2373,9 +2373,17 @@ static void ultra_secret_door_open(Level& level) if (!other || !other->data || other->group != -1 || other->data->type == ROOM_CURSE) continue; if (!level.MakeRedRoomDoor(safeIdx, slot)) break; - if (room.doors[slot]) - reconstruction_missing("Level::load_room 0073e0a0: opening the ultra secret room's red door " - "(GridEntity_Door::TryBlowOpen 0070fb60, its open animation)"); + + GridEntity_Door* door = room.doors[slot]; + if (!door) return; + door->TryBlowOpen(false, nullptr); + if ((room.descriptor->flags & ROOM_DESCRIPTOR_FLAG_CLEAR) || door->state == DOOR_STATE_CLOSED) return; + door->state = DOOR_STATE_CLOSED; + door->UpdateAnimation(); + bool isSecretSide = std::ranges::any_of(std::array{door->currentRoomType, door->targetRoomType}, [](int type) { + return type == ROOM_SECRET || type == ROOM_SUPERSECRET || type == ROOM_ULTRASECRET; + }); + if (isSecretSide) door->openAnimation = "Open"; return; } } diff --git a/src/lua_api_entity_player.cpp b/src/lua_api_entity_player.cpp index bc474e1..92a0e42 100644 --- a/src/lua_api_entity_player.cpp +++ b/src/lua_api_entity_player.cpp @@ -392,11 +392,7 @@ static void player_state_register(lua_State* state) lua_method(state, "GetItemState", [](Entity_Player& player) { return player.itemState; }); lua_method(state, "ResetItemState", [](Entity_Player& player) { player.ResetItemState(); }); lua_method(state, "GetTearRangeModifier", [](Entity_Player& player) { return player.tearRangeModifier; }); - lua_method(state, "GetTractorBeam", [](Entity_Player& player) -> Entity* { - if (player.tractorBeam) - reconstruction_missing("Entity_Player::GetTractorBeam 00665c10 (the beam is an int here)"); - return nullptr; - }); + lua_method(state, "GetTractorBeam", [](Entity_Player& player) -> Entity* { return player.tractorBeam; }); lua_method(state, "GetLastActionTriggers", [](Entity_Player& player) { return player.lastActionTriggers; }); lua_field<&Entity_Player::blinkTime>(state, "HeadFrameDelay"); lua_method(state, "GetNPCTarget", [](Entity_Player&) -> Entity* { diff --git a/src/lua_api_game.cpp b/src/lua_api_game.cpp index 973fe07..dcc30b1 100644 --- a/src/lua_api_game.cpp +++ b/src/lua_api_game.cpp @@ -188,8 +188,8 @@ static void game_effects_register(lua_State* state) lua_method(state, "GetFont", [](Game&) { return &g_manager->font2_TeamMeatEx12; }); lua_method(state, "GetAmbush", [](Game&) { return LuaOpaque{}; }); lua_method(state, "GetItemOverlay", [](Game&) { return LuaOpaque{}; }); - lua_method(state, "ShowFortune", [](Game&) { reconstruction_missing("Game::ShowFortuneText 009807a0"); }); - lua_method(state, "ShowRule", [](Game&) { reconstruction_missing("Game::ShowFortuneText 009807a0"); }); + lua_method(state, "ShowFortune", [](Game&) { fortune_show(FORTUNE_GENERAL); }); + lua_method(state, "ShowRule", [](Game&) { fortune_show(FORTUNE_RULES); }); } // (00704f20, 006f9770) Registers how Game moves the run on: its frame and draw, room and floor changes, rerolls, diff --git a/src/lua_api_room.cpp b/src/lua_api_room.cpp index c6d2677..937bdff 100644 --- a/src/lua_api_room.cpp +++ b/src/lua_api_room.cpp @@ -1,6 +1,7 @@ #include "classes.h" #include "entity_knife.h" #include "entity_npc.h" +#include "entity_slot.h" #include "game.h" #include "item_pool.h" #include "grid_entity.h" @@ -266,7 +267,7 @@ static void room_state_register(lua_State* state) return g_game->itemPool.GetSeededCollectible(seed, isNoDecrease, *room.descriptor); }); lua_method(state, "ShopRestockPartial", [](Room& room) { room_restock_partial(room); }); - lua_method(state, "ShopRestockFull", [](Room&) { reconstruction_missing("Room::ShopRestockFull 00815ae0"); }); + lua_method(state, "ShopRestockFull", [](Room&) { room_shop_restock_full(); }); lua_method(state, "ShopReshuffle", [](Room&, bool, bool) { reconstruction_missing("Room::ShopReshuffle 00816000"); }); lua_method(state, "SpawnClearAward", [](Room& room) { room_clear_award_spawn(room); }); diff --git a/src/manager.cpp b/src/manager.cpp index 7a15763..9952b71 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -59,8 +59,8 @@ constexpr int DEFAULT_STAGE = 1; constexpr float SFX_VOLUME_MODIFIER_STEP = 0.005f; constexpr uint64_t NS_PER_MS = 1000000; -// The graphics capability bit Manager::Init needs for the water surface. Its setter is not found yet. -constexpr uint32_t GRAPHICS_CAPABILITY_WATER_SURFACE = 1; +// The shader Manager::Init needs loaded to keep the water surface option on. +constexpr const char* WATER_SURFACE_V1_SHADER = "WaterSurface"; // The shaders FUN_00680080 builds from resources/shaders/, each from its vertex and fragment files. constexpr const char* SHADERS_FOLDER = "shaders/"; @@ -117,7 +117,7 @@ constexpr GameShader GAME_SHADERS[] = { {"Dizzy", TEXTURED_ATTRIBUTES, TEXTURED_VERTEX, "dizzy", "Dizzy Shader"}, {"HeatWave", COLORED_TEXTURED_ATTRIBUTES, COLORED_TEXTURED_VERTEX, "heat_wave", "Heat Wave Shader"}, {"Mirror", TEXTURED_ATTRIBUTES, TEXTURED_VERTEX, "mirror", "Mirror Shader"}, - {"WaterSurface", COLORED_TEXTURED_ATTRIBUTES, COLORED_TEXTURED_VERTEX, "water", "Water Surface Shader"}, + {WATER_SURFACE_V1_SHADER, COLORED_TEXTURED_ATTRIBUTES, COLORED_TEXTURED_VERTEX, "water", "Water Surface Shader"}, {"WaterSurfaceV2", COLORED_TEXTURED_ATTRIBUTES, COLORED_TEXTURED_VERTEX, "water_v2", "Water Surface V2 Shader"}}; constexpr const char* SHADER_BANNER = "***************************************\n"; @@ -329,7 +329,7 @@ void Manager::Init() manager.cursorSprite.Play(CURSOR_ANIMATION); manager.cursorVisibleTimer = 0; } - if (!(DAT_00c796bc & GRAPHICS_CAPABILITY_WATER_SURFACE)) options.render.isWaterSurfaceEnabled = false; + if (!KAGE::Graphics::manager.shader_find(WATER_SURFACE_V1_SHADER)) options.render.isWaterSurfaceEnabled = false; manager.isMenuPending = false; manager.isStarting = false; @@ -630,15 +630,6 @@ static CutscenePart* cutscene_part_get(Cutscene& cutscene) return isPlaying ? entry.parts[entry.currentPart].get() : nullptr; } -// Whether a cutscene's video keeps the HQ4X filter off: while it plays, the original checks its clip's next frame -// against the clip's length, which needs the video player. -static bool is_video_unfiltered(Cutscene& cutscene) -{ - bool isVideo = cutscene.state == CUTSCENE_PLAYING && cutscene.entries[cutscene.currentCutsceneId].hasVideo; - if (isVideo) reconstruction_missing("Manager::Render 009555c0: the video clip's frame against its length"); - return false; -} - // Empties the nightmare scene before nightmares.xml is read (again): not showing, no nightmares, every stage icon // empty. // The original also zeroes three counters (+4, +0x35c, +0x360) and a flag (+0x5e8) NightmareScene does not name yet. @@ -1584,7 +1575,7 @@ void Manager::Render() graphics.SetRenderTarget(nullptr, KAGE::Graphics::TARGET_OWN_SIZE); bool isResized = state != MANAGER_STATE_CUTSCENE && platform.framebuffer_size_get().width != g_framebufferWidth; bool isFiltered = optionsConfig.render.isFilterEnabled && optionsConfig.isFilterEnabled && - !is_video_unfiltered(cutsceneManager); + !cutsceneManager.is_video_playing(); bool isColorCorrected = optionsConfig.render.isColorCorrectionEnabled; if (isResized) graphics.render_target_push(renderSurface.get(), TARGET_SCREEN_SIZE, PRESENT_FLUSH); if (isFiltered) graphics.render_target_push(hq4xSurface.get(), TARGET_SCREEN_SIZE, PRESENT_FLUSH); diff --git a/src/music_manager.h b/src/music_manager.h index 02f7219..940fd46 100644 --- a/src/music_manager.h +++ b/src/music_manager.h @@ -53,6 +53,7 @@ enum MusicId : int MUSIC_DARK_ROOM_BOSS = 24, MUSIC_CHEST_BOSS = 25, MUSIC_BOSS2 = 26, + MUSIC_HUSH_BOSS = 27, MUSIC_ULTRA_GREED_BOSS = 28, MUSIC_LIBRARY_ROOM = 30, MUSIC_SECRET_ROOM = 31, diff --git a/src/npc_ai.cpp b/src/npc_ai.cpp index 6a59ac0..65239ea 100644 --- a/src/npc_ai.cpp +++ b/src/npc_ai.cpp @@ -7,6 +7,7 @@ #include "room_special.h" #include "sfx_manager.h" #include "mines.h" +#include "tainted_characters.h" // The Beast's forms, by variant: its stalactites, rocks and soul, the four ultra horsemen and their summons, and // the background beasts. @@ -157,12 +158,12 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 33: return npc_fireplace_update(npc); case 35: - return (void)NpcAI::ENTITY_MRMAW(&npc); + return npc_mr_maw_update(npc); case 36: return boss_gurdy_update(npc); case 38: case 259: - return (void)NpcAI::ENTITY_BABY(&npc); + return npc_baby_update(npc); case 39: case 49: case 836: @@ -181,7 +182,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 236: return npc_stonehead_update(npc); case 44: - return (void)NpcAI::ENTITY_POKY(&npc); + return npc_poky_update(npc); case 45: return boss_mom_update(npc); case 46: @@ -252,7 +253,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 88: return npc_walking_boil_update(npc); case 90: - return (void)NpcAI::ENTITY_HANGER(&npc); + return npc_hanger_update(npc); case 91: case 229: case 230: @@ -276,14 +277,14 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 101: return boss_daddy_long_legs_update(npc); case 102: - return (void)NpcAI::ENTITY_ISAAC(&npc); + return boss_isaac_update(npc); case 201: return (void)NpcAI::ENTITY_STONE_EYE(&npc); case 202: return npc_stone_shooter_update(npc); case 204: case 247: - return (void)NpcAI::ENTITY_MOBILE_HOST(&npc); + return npc_mobile_host_update(npc); case 206: case 207: return npc_baby_long_legs_update(npc); @@ -294,7 +295,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) return npc_deaths_head_update(npc); case 213: case 287: - return (void)NpcAI::ENTITY_MOMS_HAND(&npc); + return npc_moms_hand_update(npc); case 216: return npc_swinger_update(npc); case 217: @@ -302,12 +303,12 @@ static void npc_ai_routine_run(Entity_NPC& npc) return npc_dip_update(npc); case 219: case 285: - return (void)NpcAI::ENTITY_WIZOOB(&npc); + return npc_wizoob_update(npc); case 220: case 871: return npc_squirt_update(npc); case 221: - return (void)NpcAI::ENTITY_COD_WORM(&npc); + return npc_cod_worm_update(npc); case 222: return npc_ring_fly_update(npc); case 224: @@ -370,7 +371,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 272: return (void)NpcAI::ENTITY_URIEL(&npc); case 273: - return (void)NpcAI::ENTITY_THE_LAMB(&npc); + return boss_lamb_update(npc); case 274: case 275: if (npc.variant != 0) return NpcAI::ENTITY_MEGA_SATAN_hand(&npc); @@ -396,11 +397,11 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 296: return (void)NpcAI::ENTITY_HUSH_FLY(&npc); case 297: - return (void)NpcAI::ENTITY_HUSH_GAPER(&npc); + return npc_hush_gaper_update(npc); case 298: return (void)NpcAI::ENTITY_HUSH_BOIL(&npc); case 299: - return (void)NpcAI::ENTITY_GREED_GAPER(&npc); + return npc_greed_gaper_update(npc); case 300: return npc_mushroom_update(npc); case 303: @@ -428,7 +429,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 406: return (void)NpcAI::ENTITY_ULTRA_GREED(&npc); case 407: - return (void)NpcAI::ENTITY_HUSH(&npc); + return boss_hush_update(npc); case 409: return (void)NpcAI::ENTITY_RAG_MEGA(&npc); case 410: @@ -460,13 +461,13 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 813: return npc_blurb_update(npc); case 814: - return (void)NpcAI::ENTITY_STRIDER(&npc); + return npc_strider_update(npc); case 815: return (void)NpcAI::ENTITY_FISSURE(&npc); case 816: return (void)NpcAI::ENTITY_POLTY(&npc); case 818: - return (void)NpcAI::ENTITY_ROCK_SPIDER(&npc); + return npc_rock_spider_update(npc); case 820: return (void)NpcAI::ENTITY_DANNY(&npc); case 821: @@ -478,7 +479,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 824: return (void)NpcAI::ENTITY_GYRO(&npc); case 825: - return (void)NpcAI::ENTITY_FIRE_WORM(&npc); + return npc_fire_worm_update(npc); case 826: return npc_hardy_update(npc); case 827: @@ -534,7 +535,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 865: return (void)NpcAI::ENTITY_EVIS(&npc); case 866: - return (void)NpcAI::ENTITY_DARK_ESAU(&npc); + return npc_dark_esau_update(npc); case 867: return (void)NpcAI::ENTITY_MOTHERS_SHADOW(&npc); case 868: diff --git a/src/npc_alt.h b/src/npc_alt.h index 488d98b..7ed9487 100644 --- a/src/npc_alt.h +++ b/src/npc_alt.h @@ -2,21 +2,27 @@ #include "npc_depths.h" +// The splat of the stone and lava enemies: black, lifted a little. +constexpr ColorMod ROCK_SPLAT_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {30 / 255.0f, 30 / 255.0f, 30 / 255.0f}}; + // The alt path enemies' AIs (the Downpour, Dross, Mines and Ashpit) the dispatcher (npc_ai_update) runs by type. void npc_blaster_update(Entity_NPC& npc); void npc_quakey_update(Entity_NPC& npc); void npc_hardy_update(Entity_NPC& npc); -// The variants rock_spider_throw throws: a small, big or tinted rock spider, or a coal spider (a fireplace). +// What rock_spider_throw throws: a rock, tinted or coal rock spider (their variants), or a coal fire (a fireplace). enum RockSpiderKind { - SPIDER_THROW_SMALL, - SPIDER_THROW_BIG, + SPIDER_THROW_ROCK, SPIDER_THROW_TINTED, - SPIDER_THROW_COAL + SPIDER_THROW_COAL, + SPIDER_THROW_COAL_FIRE }; Entity_NPC* rock_spider_throw(const Vector& position, const Vector& velocity, Entity* spawner, RockSpiderKind kind, float height); void npc_bomb_grimace_update(Entity_NPC& npc); void npc_quake_grimace_update(Entity_NPC& npc); +void npc_strider_update(Entity_NPC& npc); +void npc_fire_worm_update(Entity_NPC& npc); +void npc_rock_spider_update(Entity_NPC& npc); diff --git a/src/npc_blaster.cpp b/src/npc_blaster.cpp index 9807f17..934aedf 100644 --- a/src/npc_blaster.cpp +++ b/src/npc_blaster.cpp @@ -5,7 +5,6 @@ // 70 while fewer than 4 fly bombs fly, facing its prey. constexpr float BLASTER_ARMOR = 0.75f; constexpr uint64_t BLASTER_UNARMORED = DAMAGE_EXPLOSION | DAMAGE_CRUSH; -constexpr ColorMod BLASTER_SPLAT_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {30 / 255.0f, 30 / 255.0f, 30 / 255.0f}}; constexpr float BLASTER_WALK_THRESHOLD = 0.1f; constexpr float BLASTER_FRICTION = 0.7f; constexpr uint32_t BLASTER_ATTACK_ODDS = 70; @@ -78,7 +77,7 @@ void npc_blaster_update(Entity_NPC& npc) { npc.state = NPC_STATE_MOVE; npc.sprite.Play("WalkVert"); - npc.splatColor = BLASTER_SPLAT_COLOR; + npc.splatColor = ROCK_SPLAT_COLOR; npc.aiCallFlags = AI_CALL_PRE_UPDATE; } else if (npc.state == NPC_STATE_MOVE) diff --git a/src/npc_clotty.cpp b/src/npc_clotty.cpp index e4f0ed8..2a1e413 100644 --- a/src/npc_clotty.cpp +++ b/src/npc_clotty.cpp @@ -13,7 +13,6 @@ constexpr int CLOT = 1; constexpr int I_BLOB = 2; constexpr int GRILLED_CLOTTY = 3; -constexpr int SOUND_ANIMAL_SQUISH = 166; constexpr int BLOOD_EXPLOSION_SPURT = 2; // They hop around (a Mega Clotty wading through more friction) and attack once a hop ends while the target is in diff --git a/src/npc_cod_worm.cpp b/src/npc_cod_worm.cpp new file mode 100644 index 0000000..adb903b --- /dev/null +++ b/src/npc_cod_worm.cpp @@ -0,0 +1,159 @@ +#include "boss_ai.h" +#include "npc_depths.h" + +// Its burrow: how near a target keeps it under, and how long it stays out. +constexpr float COD_WORM_HIDE_REACH_SQUARED = 22500; +constexpr uint32_t COD_WORM_OUT_SPREAD = 40; +constexpr int COD_WORM_OUT_MIN = 80; +constexpr float COD_WORM_FRICTION = 0.7f; + +// Its spit, and the anger hits on its shell stoke. +constexpr float COD_WORM_CONTROL_REACH = 180; +constexpr float COD_WORM_ARC = 10; +constexpr uint32_t COD_WORM_SHOTS_SPREAD = 3; +constexpr int COD_WORM_SHOTS_MIN = 5; +constexpr int COD_WORM_ANGER_MAX = 30; + +// A controlled worm's charge: it builds under cover with no player near, and drains out of it. +constexpr float COD_WORM_CHARGE_FRAMES = 150; +constexpr float COD_WORM_CHARGE_DRAIN = 1.5f; +constexpr float COD_WORM_CHARGE_REACH = 150; +constexpr float COD_WORM_CHARGE_ATTACK = 0.8f; +constexpr float COD_WORM_CHARGE_COST = 0.2f; +constexpr float COD_WORM_CONTROL_RANGE = 1000; +constexpr int COD_WORM_RANGE_FRAMES = 7; +constexpr float COD_WORM_CONTROL_DEADZONE = 0.1f; + +// Under its shell it pulses, and comes out (for a while) once its target is away or out of sight. Confused, it always +// comes out. +static void cod_worm_hide(Entity_NPC& npc) +{ + npc.sprite.Play("Pulse"); + if (npc.stateFrame > 0) npc.stateFrame -= npc_ticks_get(npc); + + bool isStaying; + if (npc.controllerID == -1) + { + Entity* target = npc.GetPlayerTarget(); + bool isWatched = vector_length_squared(vector_sub(target->pos, npc.pos)) <= COD_WORM_HIDE_REACH_SQUARED && + room_check_line(npc.pos, npc.GetPlayerTarget()->pos, LINE_MODE_PROJECTILE, + LINE_CHECK_THRESHOLD); + isStaying = isWatched || npc.stateFrame > 0; + } + else isStaying = npc.v1.x < 1 && !npc.IsControllerActionPressed(CONTROLLER_ACTION_SHOOT); + if (isStaying && !npc.HasEntityFlags(FLAG_CONFUSION)) return; + + npc.state = NPC_STATE_JUMP; + npc.stateFrame = (int)(Random() % COD_WORM_OUT_SPREAD) + COD_WORM_OUT_MIN; + npc.sprite.Play("DigOut"); +} + +// Out of its shell it pulses, open to hits, then digs back in (a controlled one when it attacks again). +static void cod_worm_out(Entity_NPC& npc) +{ + if (npc_anim_is_done(npc)) npc.sprite.Play("PulseOut"); + npc.stateFrame -= npc_ticks_get(npc); + + bool isDigging; + if (npc.controllerID == -1) isDigging = npc.stateFrame < 1; + else + { + const AnimationData* data = npc.sprite.animState.animData; + isDigging = data && data->isLooping && npc.v1.x < COD_WORM_CHARGE_ATTACK && + (npc.IsControllerActionPressed(CONTROLLER_ACTION_SHOOT) || + npc.IsTargetInAttackRange(COD_WORM_CONTROL_RANGE, COD_WORM_RANGE_FRAMES, false)); + } + if (!isDigging) return; + npc.state = NPC_STATE_STOMP; + npc.sprite.Play("DigIn"); + npc.v1.x = std::max(npc.v1.x - COD_WORM_CHARGE_COST, 0.0f); +} + +// Its spit: a burst of five to eight shots lobbed at its target (or where its controller points). +static void cod_worm_spit(Entity_NPC& npc) +{ + npc.sprite.Play("Attack"); + npc.UpdateControllerMovement(false); + if (npc.sprite.animState.animData) + { + if (npc.sprite.animState.IsEventTriggered("Shoot")) + { + npc.PlaySound(SOUND_BLOODSHOOT, 1, 2, false, 1); + Vector aim = npc.GetPlayerTarget()->pos; + if (npc.controllerID != -1) + aim = vector_add(vector_scale(npc.controllerMovement, COD_WORM_CONTROL_REACH), npc.pos); + float arc = random_unit() * COD_WORM_ARC; + int count = (int)(Random() & COD_WORM_SHOTS_SPREAD) + COD_WORM_SHOTS_MIN; + npc.FireBossProjectiles(count, aim, arc, ProjectileParams()); + } + if (!npc_anim_is_done(npc)) return; + } + npc.state = NPC_STATE_IDLE; + npc.sprite.Play("Pulse"); +} + +// Hits on its shell do nothing but anger it into spitting, longer for harder hits. +static void cod_worm_shell_hit(Entity_NPC& npc, bool isShielded) +{ + float blocked = 0; + if (isShielded) + for (DamageEvent& event : npc.damageEvents) + { + if (event.damageFlags & DAMAGE_POISON_BURN) continue; + blocked += event.damage; + event.damage = 0; + } + bool isAngered = (npc.state == NPC_STATE_IDLE || npc.state == NPC_STATE_ATTACK) && blocked > 0 && + !npc.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK); + if (npc.controllerID != -1 || !isAngered) return; + npc.state = NPC_STATE_ATTACK; + npc.stateFrame = std::min(npc.stateFrame + (int)blocked * 2, COD_WORM_ANGER_MAX); +} + +// A controlled worm spits when its target is in range, and charges under cover away from the players. +static void cod_worm_control_update(Entity_NPC& npc, bool isShielded) +{ + npc.UpdateChargeBar(1, 0, npc.v1.x, true); + if (npc.state == NPC_STATE_IDLE && npc.IsTargetInAttackRange(COD_WORM_CONTROL_RANGE, COD_WORM_RANGE_FRAMES, false)) + { + npc.controllerMovement = npc.GetControllerMovementInput(COD_WORM_CONTROL_DEADZONE); + npc.state = NPC_STATE_ATTACK; + } + + float rate = npc.speedMultiplier / COD_WORM_CHARGE_FRAMES; + if (!isShielded) npc.v1.x = std::max(npc.v1.x - rate * COD_WORM_CHARGE_DRAIN, 0.0f); + else if (npc.IsPlayerInRadius(npc.pos, COD_WORM_CHARGE_REACH)) npc.v1.x = std::max(npc.v1.x - rate, 0.0f); + else npc.v1.x = std::min(npc.v1.x + rate, 1.0f); +} + +// 00531350 NpcAI::ENTITY_COD_WORM: the Cod Worm hides in its invincible shell while watched, pops out when left +// alone, and spits bursts of shots when hit. +void npc_cod_worm_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.state = NPC_STATE_IDLE; + npc.targetPosition = npc.pos; + npc.isInvincible = true; + return; + } + + npc.isInvincible = false; + npc.velocity = vector_sub(npc.targetPosition, npc.pos); + npc.friction *= COD_WORM_FRICTION; + if (npc.state == NPC_STATE_IDLE) cod_worm_hide(npc); + else if (npc.state == NPC_STATE_ATTACK) cod_worm_spit(npc); + else if (npc.state == NPC_STATE_JUMP) cod_worm_out(npc); + else if (npc.state == NPC_STATE_STOMP && npc_anim_is_done(npc)) npc.state = NPC_STATE_IDLE; + + const AnimationData* data = npc.sprite.animState.animData; + bool isShielded = npc.state == NPC_STATE_IDLE || npc.state == NPC_STATE_ATTACK || npc.state == NPC_STATE_STOMP || + (npc.state == NPC_STATE_JUMP && (!data || !data->isLooping)); + if (npc.pendingDamage > 0) cod_worm_shell_hit(npc, isShielded); + if (npc.controllerID != -1) cod_worm_control_update(npc, isShielded); + + if (npc.state == NPC_STATE_JUMP) npc.ClearEntityFlags(FLAG_NO_TARGET); + else npc.AddEntityFlags(FLAG_NO_TARGET); + if (npc.sprite.animState.animData && npc.sprite.animState.IsEventTriggered("Dig")) + npc_sound_play(SOUND_BIRD_FLAP, 1, 2, champion_pitch_get(npc)); +} diff --git a/src/npc_collision.cpp b/src/npc_collision.cpp index 34434c3..1b983bf 100644 --- a/src/npc_collision.cpp +++ b/src/npc_collision.cpp @@ -8,6 +8,7 @@ #include "entity_tear.h" #include "boss_ai.h" #include "game.h" +#include "npc_alt.h" #include "room.h" #include #include @@ -16,7 +17,6 @@ // The NPC types whose contacts differ from the generic ones. constexpr int ENTITY_DEATH = 66; constexpr int ENTITY_HORSEMAN_HEAD = 83; -constexpr int ENTITY_MOMS_HAND = 213; constexpr int ENTITY_BEGOTTEN = 251; constexpr int ENTITY_THE_HAUNT = 260; constexpr int ENTITY_DINGLE = 261; @@ -45,7 +45,6 @@ constexpr int DEATH_SCYTHE_VARIANT = 20; constexpr int PIN_SCOLEX_VARIANT = 3; constexpr int SUCKER_BULB_FIRST = 5; constexpr int SUCKER_BULB_LAST = 6; -constexpr int ROCK_SPIDER_TINTED = 2; constexpr int BEAST_SOUL_VARIANT = 10; constexpr int SCOURGE_CHAIN_VARIANT = 10; constexpr int SMALL_MAGGOT_FALLING = 2; @@ -231,7 +230,7 @@ static Verdict contact_pairs(Contact& contact) return true; if (npc.type == ENTITY_ROCK_SPIDER && npc.variant == 0 && collider.type == ENTITY_FIREPLACE) { - npc.Morph(ENTITY_ROCK_SPIDER, ROCK_SPIDER_TINTED, npc.subtype, -1); + npc.Morph(ENTITY_ROCK_SPIDER, SPIDER_THROW_COAL, npc.subtype, -1); return false; } bool isRockKind = collider.type == ENTITY_ROCK_SPIDER || isColliderMovableFire; @@ -541,9 +540,9 @@ static Verdict contact_player(Contact& contact, Entity_Player& player) int npcType = contact.npcType; PlayerManager& players = g_game->playerManager; - bool isTintedRockSpider = npcType == ENTITY_ROCK_SPIDER && contact.npcVariant == ROCK_SPIDER_TINTED; + bool isCoalSpider = npcType == ENTITY_ROCK_SPIDER && contact.npcVariant == SPIDER_THROW_COAL; bool isSpared = (npc.config->tags & ENTITY_TAG_FLY) && players.AnyoneHasCollectible(COLLECTIBLE_SKATOLE); - if (!isSpared && (npc.config->tags & ENTITY_TAG_SPIDER) && !isTintedRockSpider) + if (!isSpared && (npc.config->tags & ENTITY_TAG_SPIDER) && !isCoalSpider) isSpared = players.AnyoneHasCollectible(COLLECTIBLE_BURSTING_SACK); if (npcType == ENTITY_NEEDLE) isSpared = isSpared || npc.state != NPC_STATE_JUMP; if (npcType == ENTITY_CLICKETY_CLACK) isSpared = isSpared || npc.HasEntityFlags(FLAG_NO_TARGET); @@ -660,6 +659,26 @@ static Verdict contact_touch(Contact& contact) return std::nullopt; } +// Mom's hand closing on a player it can take, to carry off untouchable. The rest it bumps. +static Verdict moms_hand_player_grab(Contact& contact, bool& isBumpNext) +{ + Entity_NPC& npc = contact.npc; + auto& player = static_cast(contact.collider); + if (!player.isControlsEnabled || player.HasInvincibility(0, EntityRef())) + { + isBumpNext = true; + return std::nullopt; + } + npc.state = NPC_STATE_SPECIAL; + npc.RemoveStatusEffects(); + npc.AddEntityFlags(FLAG_NO_STATUS_EFFECTS); + npc.isInvincible = true; + npc.entityCollisionClass = ENTCOLL_NONE; + npc.stateFrame = 0; + reconstruction_missing("Entity_NPC::HandleCollision 006cd410: Mom's hand taking a player (Entity_Player 0x189c)"); + return contact.isIgnored; +} + // Mom's hand grabbing, rings of flies and hoppers passing their kin, Brownie eating dips and the corn mines. // Whether the contact skips to the enemy bumps. static Verdict contact_late_kinds(Contact& contact, bool& isBumpNext) @@ -670,8 +689,19 @@ static Verdict contact_late_kinds(Contact& contact, bool& isBumpNext) switch (contact.npcType) { case ENTITY_MOMS_HAND: - if (npc.state == HAND_GRAB_STATE) - reconstruction_missing("Entity_NPC::HandleCollision 006cd410: Mom's hand grabbing"); + if (npc.state != HAND_GRAB_STATE) break; + npc.i1 = colliderType; + npc.i2 = contact.colliderVariant; + if (colliderType == ENTITY_PLAYER) return moms_hand_player_grab(contact, isBumpNext); + if ((npc.HasEntityFlags(FLAG_CHARM) || collider.HasEntityFlags(FLAG_BAITED)) && + collider.IsVulnerableEnemy(nullptr) && !collider.IsBoss()) + { + collider.Remove(); + npc.state = NPC_STATE_SPECIAL; + npc.isInvincible = true; + npc.stateFrame = 0; + return contact.isIgnored; + } break; case ENTITY_RING_OF_FLIES: if (colliderType != ENTITY_RING_OF_FLIES) break; diff --git a/src/npc_dark_esau.cpp b/src/npc_dark_esau.cpp new file mode 100644 index 0000000..0ceeca4 --- /dev/null +++ b/src/npc_dark_esau.cpp @@ -0,0 +1,587 @@ +#include "tainted_characters.h" +#include "boss_ai.h" +#include "entity_config.h" +#include "entity_effect.h" +#include "entity_npc.h" +#include "entity_player.h" +#include "entity_projectile.h" +#include "game.h" +#include "level.h" +#include "npc_ai.h" +#include "room.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include +#include + +// Dark Esau's own states, and the hole he climbs out of (variant 1). +enum DarkEsauVariant +{ + DARK_ESAU, + DARK_ESAU_HOLE +}; + +constexpr uint64_t DARK_ESAU_FLAGS = + FLAG_NO_STATUS_EFFECTS | FLAG_NO_TARGET | FLAG_BOSSDEATH_TRIGGERED | FLAG_DONT_COUNT_BOSS_HP; +constexpr uint64_t DARK_ESAU_HOLE_FLAGS = + FLAG_NO_STATUS_EFFECTS | FLAG_NO_TARGET | FLAG_HIDE_HP_BAR | FLAG_NO_PLAYER_CONTROL; + +// The hole stays open 150 frames, shaking the screen as it opens. +constexpr int ESAU_HOLE_OPEN_FRAMES = 150; +constexpr int ESAU_HOLE_SHAKE = 6; + +// He drifts toward a spot 40 pixels short of his target (80 while his player is held, 20 short of his twin when the +// twin is nearer), at up to 3 a frame (4 for a twin over 300 pixels off) eased over 200 pixels. +constexpr float CHASE_GAP = 40; +constexpr float CHASE_GAP_FROZEN = 80; +constexpr float CHASE_GAP_TWIN = 20; +constexpr float CHASE_ACCEL = 3; +constexpr float CHASE_ACCEL_FAR_TWIN = 4; +constexpr float CHASE_FAR_TWIN_SQUARED = 90000; +constexpr float CHASE_EASE = 200; +constexpr float CHASE_STEP = 0.01f; + +// Within 120 pixels and lined up within 20 he charges, after a rest of 60 frames (30 after a dash cut short, 90 after +// a full one). A twin charges with him when resting and within 200 pixels of his spot. +constexpr float CHARGE_RANGE = 120; +constexpr float CHARGE_LINE = 20; +constexpr float CHARGE_TWIN_RANGE_SQUARED = 40000; +constexpr int REST_FROZEN = 60; +constexpr int REST_SHORT = 30; +constexpr int REST_DASH = 90; + +// The wind-up backs away at 0.8 for 14 frames, then the dash runs at 6 a frame for 12 frames (60 for a chained one, +// which also ends against a wall after 13), leaving a dust trail every third frame. +constexpr int WINDUP_FRAMES = 14; +constexpr float WINDUP_BACK = 0.8f; +constexpr float WINDUP_STEER = 0.2f; +constexpr float ESAU_DASH_SPEED = 6; +constexpr int ESAU_DASH_FRAMES = 12; +constexpr int ESAU_DASH_FRAMES_CHAINED = 60; +constexpr float ESAU_DASH_WALL_MARGIN = -100; +constexpr int ESAU_DASH_TRAIL_INTERVAL = 3; +constexpr float ESAU_TRAIL_SPREAD = 0.1f; +constexpr float ESAU_TRAIL_RISE = 2; +constexpr float ESAU_TRAIL_RISE_RANGE = 6; +constexpr float ESAU_TRAIL_ROTATION = 2; +constexpr float ESAU_TRAIL_ROTATION_RANGE = 10; +constexpr uint32_t ESAU_TRAIL_LIFE = 10; +constexpr float ESAU_TRAIL_SCALE = 0.4f; +constexpr float ESAU_TRAIL_SCALE_RANGE = 0.3f; +constexpr int ESAU_TRAIL_DEPTH = -2000; +constexpr ColorMod ESAU_TRAIL_COLOR = {{5, 0.5f, 0.2f, 1}, {}, {}}; +constexpr ColorMod ESAU_TRAIL_COLOR_TWIN = {{5, 0.2f, 0.21f, 1}, {}, {}}; +constexpr float ESAU_FRICTION_DASH = 0.8f; +constexpr float ESAU_FRICTION_IDLE = 0.9f; +constexpr float ESAU_FRICTION_SPLIT = 0.7f; +constexpr float ESAU_HOLE_DAMPING = 0.4f; +constexpr float CHAINED_PULL = 1.4f; +constexpr int CHAINED_DASH_START = 30; + +// The dash burns: every other frame the enemies within 50 take the floor's number plus 9 and 150 frames of burning, +// and enemy shots that may hit the player go. +constexpr int BURN_INTERVAL = 2; +constexpr float BURN_RADIUS = 50; +constexpr float BURN_DAMAGE_BASE = 9; +constexpr int BURN_FRAMES = 150; +constexpr float BURN_TICK = 5; +constexpr int ESAU_HIT_COUNTDOWN = 30; +constexpr float ESAU_CONTACT_DAMAGE = 30; + +// Climbing out, he shakes the screen and sprays 12 rings of 8 shots at speed 8. +constexpr int APPEAR_SHAKE = 10; +constexpr int APPEAR_RINGS = 12; +constexpr int APPEAR_RING_INTERVAL = 2; +constexpr float APPEAR_SHOT_SPEED = 8; +constexpr float APPEAR_SHOT_COUNT = 8; +constexpr float APPEAR_SHOT_FALL = 0.3f; +constexpr ColorMod APPEAR_SHOT_COLOR_TWIN = {{2, 1.2f, 1.2f, 1}, {}, {0, -0.5f, -0.2f}}; + +// Splitting (Birthright), the twins stand 10 pixels either side of him, blacked out for 20 frames. +constexpr float ESAU_TWIN_OFFSET = 10; +constexpr int SPLIT_WINDUP = -8; +constexpr ColorMod SPLIT_FLASH = {{0, 0, 0, 1}, {}, {}}; +constexpr int SPLIT_FLASH_FRAMES = 20; +constexpr ColorMod SPLIT_POOF_COLOR = {{0.2f, 0.2f, 0.2f, 0.6f}, {1, 1, 1, 1}, {}}; +constexpr float SPLIT_PITCH = 0.6f; +constexpr int ESAU_STATE_SPLIT = NPC_STATE_SUMMON; +constexpr int ESAU_STATE_CHAINED = NPC_STATE_SUICIDE; +// The entity types he hurts: the enemies' range. +constexpr int ESAU_NPC_TYPE_FIRST = 10; +constexpr int ESAU_NPC_TYPE_LAST = 999; +constexpr float ESAU_ROOM_MARGIN = -40; +constexpr int ESAU_ROOM_SETTLE_FRAMES = 3; + +// The player whose Dark Esau this is: the spawner, while it still names him. +static Entity_Player* dark_esau_owner(Entity_NPC& npc) +{ + Entity* spawner = npc.spawnerEntity; + if (!spawner || spawner->type != ENTITY_PLAYER) return nullptr; + auto* player = static_cast(spawner); + return player->darkEsau == &npc ? player : nullptr; +} + +// The other Dark Esau of a split pair, if it is an enemy. +static Entity* dark_esau_twin(Entity_NPC& npc) +{ + Entity* twin = npc.parent && npc.parent->IsEnemy() ? (Entity*)npc.parent : (Entity*)npc.child; + bool isTarget = twin && ((g_game->deathmatchManager.state >= DEATHMATCH_INTRO && twin->type == ENTITY_PLAYER) || + (twin->type >= ESAU_NPC_TYPE_FIRST && twin->type <= ESAU_NPC_TYPE_LAST)); + return isTarget ? twin : nullptr; +} + +// A twin of a split pair, 10 pixels to his right, starting where he is. +static Entity_NPC* dark_esau_twin_spawn(Entity_NPC& npc, Entity* spawner) +{ + Vector at = vector_make(npc.pos.x + ESAU_TWIN_OFFSET, npc.pos.y); + auto* twin = static_cast( + g_game->Spawn({at, {}, spawner, DARK_ESAU_HOLE, ENTITY_DARK_ESAU, DARK_ESAU, Random()})); + npc.child = twin; + twin->parent = &npc; + twin->ClearEntityFlags(FLAG_APPEAR); + twin->Update(); + return twin; +} + +// Every other frame of a dash: nearby enemies burn and enemy shots meant for the player go. +static void dash_burn(Entity_NPC& npc) +{ + npc.hitList.clear(); + if (!npc.GetIntervalTicks(BURN_INTERVAL, 0)) return; + + Game& game = *g_game; + bool isAltPath = game.stageType == STAGETYPE_REPENTANCE || game.stageType == STAGETYPE_REPENTANCE_B; + float damage = (float)(game.stage + isAltPath) + BURN_DAMAGE_BASE; + for (Entity* entity : entity_query_radius(npc.pos, BURN_RADIUS, QUERY_PROJECTILES | QUERY_ENEMIES)) + { + if (entity->IsVulnerableEnemy(nullptr) && entity != &npc && !entity->HasEntityFlags(FLAG_FRIENDLY)) + { + entity->TakeDamage(damage, DAMAGE_IGNORE_ARMOR, EntityRef(&npc), ESAU_HIT_COUNTDOWN); + entity->AddBurn(EntityRef(npc.parent), BURN_FRAMES, BURN_TICK, false); + continue; + } + auto* shot = entity->type == ENTITY_PROJECTILE ? static_cast(entity) : nullptr; + if (shot && !shot->isDead && !(shot->projectileFlags & PROJECTILE_CANT_HIT_PLAYER)) + { + shot->projectileFlags = 0; + shot->isDead = true; + } + } +} + +// The phase before the update: he takes no damage, a dash burns, and his death animation opens the floor under his +// player. +static void dark_esau_pre_update(Entity_NPC& npc) +{ + if (npc.pendingDamage > 0) + { + npc.pendingDamage = 0; + npc.damageEvents.clear(); + } + bool isDashing = npc.state == NPC_STATE_ATTACK || npc.state == NPC_STATE_ATTACK2; + if (isDashing && npc.sprite.animState.animData && npc.sprite.animState.IsLoopingAnimation()) dash_burn(npc); + + ANM2& sprite = npc.sprite; + bool isDying = npc.state == NPC_STATE_DEATH && sprite.animState.animData && sprite.animState.isPlaying && + sprite.GetAnimation() == "Death"; + if (!isDying) return; + if (sprite.IsEventTriggered("Sound")) sound_play(SOUND_DARK_ESAU_DEATH_OPEN); + if (!sprite.IsEventTriggered("Shoot")) return; + + Entity* blast = g_game->Spawn({npc.pos, {}, npc.spawnerEntity, 2, ENTITY_EFFECT, EFFECT_MAMA_MEGA_EXPLOSION, Random()}); + blast->targetPosition = npc.pos; + blast->parent = &npc; + blast->Update(); + if (Entity* spawner = npc.spawnerEntity) + spawner->TakeDamage(0, DAMAGE_INVINCIBLE | DAMAGE_NO_MODIFIERS | DAMAGE_NO_PENALTIES, EntityRef(&npc), + ESAU_HIT_COUNTDOWN); +} + +// The collision phase: he hurts an enemy (or a deathmatch player) he touches once a dash, letting the touch through. +static void dark_esau_collide(Entity_NPC& npc, Entity_Player* owner) +{ + if (owner && owner->isCoopGhost) return; + Entity* other = npc.collisionEntity; + bool isTarget = (g_game->deathmatchManager.state >= DEATHMATCH_INTRO && other->type == ENTITY_PLAYER) || + (other->type >= ESAU_NPC_TYPE_FIRST && other->type <= ESAU_NPC_TYPE_LAST); + if (!isTarget || EntityList::HitListContains(npc.hitList, *other)) return; + + hit_list_insert(npc.hitList, *other); + other->TakeDamage(ESAU_CONTACT_DAMAGE, 0, EntityRef(&npc), ESAU_HIT_COUNTDOWN); + npc.collisionResult = 0; +} + +// The hole he climbs out of: it opens with a roar, shakes the screen, and closes after 150 frames. +static void dark_esau_hole_update(Entity_NPC& npc, int ticks) +{ + switch (npc.state) + { + case NPC_STATE_INIT: + sound_play(SOUND_DARK_ESAU_OPEN); + npc.sprite.Play("HoleOpen"); + npc.state = NPC_STATE_IDLE; + npc.stateFrame = 0; + npc.AddEntityFlags(DARK_ESAU_HOLE_FLAGS); + npc.ClearEntityFlags(FLAG_APPEAR); + npc.isInvincible = true; + npc.entityCollisionClass = ENTCOLL_NONE; + npc.entityGridCollisionClass = GRIDCOLL_NONE; + npc.isCanShutDoors = false; + npc.sortingLayer = SORTING_BACKGROUND; + break; + case NPC_STATE_IDLE: + if (npc.sprite.IsEventTriggered("Shoot")) game_shake_screen(ESAU_HOLE_SHAKE); + if (npc.sprite.IsFinished()) npc.sprite.Play("HoleIdle"); + npc.stateFrame += ticks; + if (npc.stateFrame > ESAU_HOLE_OPEN_FRAMES) + { + npc.sprite.Play("HoleClose"); + npc.state = NPC_STATE_SPECIAL; + } + break; + case NPC_STATE_SPECIAL: + if (npc.sprite.IsFinished()) npc.Remove(); + break; + } +} + +// First frame: he either stands in the room or climbs out of a new hole, and stays from room to room. +static void dark_esau_init(Entity_NPC& npc) +{ + int collision = ENTCOLL_ALL; + if (!npc.HasEntityFlags(FLAG_APPEAR)) + { + npc.sprite.Play("Idle"); + npc.state = NPC_STATE_IDLE; + } + else + { + npc.sprite.Play("Appear"); + npc.ClearEntityFlags(FLAG_APPEAR); + npc.AddEntityFlags(FLAG_NO_TARGET); + npc.shadowSize = 0; + Entity* hole = g_game->Spawn({npc.pos, {}, nullptr, 0, npc.type, DARK_ESAU_HOLE, Random()}); + hole->child = &npc; + npc.entityRef = hole; + hole->Update(); + collision = ENTCOLL_NONE; + npc.state = NPC_STATE_SPECIAL; + } + npc.entityCollisionClass = collision; + npc.entityGridCollisionClass = GRIDCOLL_NONE; + npc.AddEntityFlags(DARK_ESAU_FLAGS); + npc.aiCallFlags = AI_CALL_PRE_UPDATE | AI_CALL_COLLISION; + npc.isInvincible = true; + g_game->room->GetEntities()->AddPersistentEntity(&npc); +} + +// Resting: he drifts after his target (or his twin), and charges when lined up and close. +static void dark_esau_chase(Entity_NPC& npc, Entity_Player* owner, Entity* twin, bool isOwnerFrozen, int ticks) +{ + AnimationState& anim = npc.sprite.animState; + if (!anim.animData || !anim.IsLoopingAnimation()) + { + npc.friction *= ESAU_FRICTION_IDLE; + if (!anim.animData || !anim.isPlaying) npc.sprite.Play("Idle"); + return; + } + + npc.friction *= ESAU_FRICTION_DASH; + Entity* target = owner ? (Entity*)owner : npc.GetPlayerTarget(); + Vector aim = npc.CalcTargetPosition(0); + Vector toAim = vector_sub(aim, npc.pos); + float distance = vector_length(toAim); + if (npc.i1 > 0) npc.i1 -= ticks; + float friction = npc.friction * ESAU_FRICTION_DASH; + npc.projectileDelay -= ticks; + npc.friction = friction; + + Vector chase = aim; + float gap = isOwnerFrozen ? CHASE_GAP_FROZEN : CHASE_GAP; + float accel = CHASE_ACCEL; + if (Entity* leader = npc.parent) + { + if (vector_length_squared(vector_sub(npc.pos, leader->pos)) < vector_length_squared(vector_sub(npc.pos, target->pos))) + { + chase = leader->pos; + gap = CHASE_GAP_TWIN; + if (vector_length_squared(vector_sub(chase, npc.pos)) > CHASE_FAR_TWIN_SQUARED) accel = CHASE_ACCEL_FAR_TWIN; + } + } + Vector spot = vector_add(chase, vector_resized(vector_sub(npc.pos, chase), gap)); + Vector toSpot = vector_sub(spot, npc.pos); + float ease = std::clamp(vector_length(toSpot) / CHASE_EASE, 0.0f, 1.0f); + Vector push = vector_resized(vector_scale(toSpot, CHASE_STEP), accel * ease); + if (friction != 0) npc.velocity = vector_add(npc.velocity, vector_scale(push, npc.speedMultiplier / friction)); + + auto* twinNpc = twin ? dynamic_cast(twin) : nullptr; + bool isTwinReady = !twin || (twinNpc && twinNpc->state == NPC_STATE_IDLE && twinNpc->i1 < 1 && + vector_length_squared(vector_sub(spot, twin->pos)) < CHARGE_TWIN_RANGE_SQUARED); + bool isReady = (!owner || !owner->isCoopGhost) && npc.i1 < 1 && isTwinReady && !isOwnerFrozen && + distance < CHARGE_RANGE; + if (!isReady || std::min(std::abs(toAim.x), std::abs(toAim.y)) >= CHARGE_LINE) return; + + npc.sprite.Play("Charge"); + npc.state = NPC_STATE_ATTACK; + npc.stateFrame = 0; + npc.target = target; + npc.targetPosition = {}; + npc.PlaySound(SOUND_MONSTER_GRUNT_4, 1, 2, false, 1); + if (!twinNpc) return; + twinNpc->sprite.Play("Charge"); + twinNpc->state = NPC_STATE_ATTACK; + twinNpc->stateFrame = 0; + twinNpc->target = target; + twinNpc->targetPosition = {}; +} + +// A dust puff behind a dash, red for him and darker for his twin. +static void dash_trail_spawn(Entity_NPC& npc) +{ + Vector null = npc.GetNullOffset("*0"); + Vector at = vector_make(npc.pos.x + npc.posOffset.x + null.x, npc.pos.y + npc.posOffset.y + null.y); + uint32_t seed = Random(); + Vector drift = vector_make(npc.velocity.x * ESAU_TRAIL_SPREAD, + -ESAU_TRAIL_RISE - random_unit() * ESAU_TRAIL_RISE_RANGE + npc.velocity.y * ESAU_TRAIL_SPREAD); + auto* dust = static_cast( + g_game->Spawn({at, drift, &npc, 0, ENTITY_EFFECT, EFFECT_DUST_CLOUD, seed})); + LayerState* layer = dust->sprite.GetLayer(0); + layer_additive_set(*layer); + layer->color = npc.subtype == 0 ? ESAU_TRAIL_COLOR : ESAU_TRAIL_COLOR_TWIN; + dust->rotation = random_unit() * ESAU_TRAIL_ROTATION_RANGE + ESAU_TRAIL_ROTATION; + dust->timeout = (int)(Random() % ESAU_TRAIL_LIFE + ESAU_TRAIL_LIFE); + dust->lifespan = dust->timeout; + float scale = random_unit() * ESAU_TRAIL_SCALE_RANGE + ESAU_TRAIL_SCALE; + dust->renderZOffset = ESAU_TRAIL_DEPTH; + dust->sprite.scale = vector_make(scale, scale); +} + +// The dash: a wind-up backing away from the target that picks the direction, then a straight run with a trail that +// ends after its frames (or at a wall for a chained one), resting him. +static void dark_esau_dash(Entity_NPC& npc, int ticks) +{ + Room& room = *g_game->room; + if (!npc.sprite.animState.IsLoopingAnimation()) + { + if (room.GetFrameCount() < ESAU_ROOM_SETTLE_FRAMES) + { + npc.sprite.Play("DashEnd"); + npc.state = NPC_STATE_IDLE; + npc.i1 = REST_SHORT; + return; + } + npc.friction *= ESAU_FRICTION_DASH; + Vector aim; + if (!npc.target) aim = npc.GetPlayerTarget()->pos; + else + { + aim = npc.CalcTargetPosition(0); + npc.AddVelocity_divided(vector_resized(vector_scale(vector_sub(aim, npc.pos), CHASE_STEP), WINDUP_STEER), false); + } + if (npc.stateFrame >= 0) + { + npc.stateFrame += ticks; + if (npc.stateFrame > WINDUP_FRAMES && npc.targetPosition.x == 0 && npc.targetPosition.y == 0) + npc.targetPosition = vector_normalized(vector_sub(aim, npc.pos)); + npc.velocity = vector_add(npc.velocity, vector_scale(vector_resized(vector_sub(npc.pos, aim), WINDUP_BACK), + npc.speedMultiplier)); + } + if (npc.sprite.animState.animData && npc.sprite.animState.isPlaying) return; + + Vector heading = npc.targetPosition; + bool isVertical = std::abs(heading.x) <= std::abs(heading.y); + npc.sprite.Play(isVertical ? (heading.y >= 0 ? "DashDown" : "DashUp") : "DashHori"); + npc.sprite.isFlipX = !isVertical && heading.x < 0; + if (npc.stateFrame >= 0) + { + npc.PlaySound(SOUND_MONSTER_YELL_A, 1, 2, false, 1); + npc.PlaySound(SOUND_FLAME_BURST, 1, 2, false, 1); + } + npc.stateFrame = std::abs(npc.stateFrame); + return; + } + + npc.friction *= ESAU_FRICTION_DASH; + npc.velocity = vector_add(npc.velocity, vector_scale(npc.targetPosition, ESAU_DASH_SPEED * npc.speedMultiplier)); + if (npc.GetIntervalTicks(ESAU_DASH_TRAIL_INTERVAL, 0)) dash_trail_spawn(npc); + npc.stateFrame += ticks; + Vector clamped = room.GetClampedPosition(npc.pos, ESAU_DASH_WALL_MARGIN); + bool isAgainstWall = (clamped.x != npc.pos.x || clamped.y != npc.pos.y) && + vector_dot(vector_normalized(vector_sub(clamped, npc.pos)), npc.targetPosition) < 0; + if (!npc.isCollidesWithGrid && room.GetFrameCount() >= ESAU_ROOM_SETTLE_FRAMES) + { + int frames = npc.state == NPC_STATE_ATTACK2 ? ESAU_DASH_FRAMES_CHAINED : ESAU_DASH_FRAMES; + bool isChainedWall = npc.stateFrame > ESAU_DASH_FRAMES && npc.state == NPC_STATE_ATTACK2 && isAgainstWall; + if (npc.stateFrame <= frames && !isChainedWall) return; + } + if (room.GetFrameCount() < ESAU_ROOM_SETTLE_FRAMES) npc.velocity = vector_scale(npc.velocity, ESAU_HOLE_DAMPING); + npc.sprite.Play("DashEnd"); + npc.state = NPC_STATE_IDLE; + npc.i1 = REST_DASH; +} + +// Chained by Anima Sola: he strains away from his player until the chain goes, then dashes at him. +static void dark_esau_chained(Entity_NPC& npc) +{ + npc.sprite.Play("Chained"); + npc.friction *= ESAU_FRICTION_DASH; + Entity* anchor = npc.spawnerEntity ? (Entity*)npc.spawnerEntity : npc.GetPlayerTarget(); + npc.friction *= ESAU_FRICTION_DASH; + Vector pull = vector_resized(vector_scale(vector_sub(anchor->pos, npc.pos), CHASE_STEP), CHAINED_PULL); + npc.AddVelocity_divided(vector_make(-pull.x, -pull.y), false); + if (npc.entityRef && !npc.entityRef->isDead) return; + + npc.sprite.Play("Charge"); + npc.sprite.SetLastFrame(); + npc.state = NPC_STATE_ATTACK2; + npc.stateFrame = CHAINED_DASH_START; + npc.target = anchor; + npc.targetPosition = {}; +} + +// Birthright's split: once the split animation ends, a twin stands beside him and both charge out sideways. +static void dark_esau_split(Entity_NPC& npc, Entity_Player* owner) +{ + npc.friction *= ESAU_FRICTION_SPLIT; + bool isPlaying = npc.sprite.animState.animData && npc.sprite.animState.isPlaying; + if (isPlaying || !owner || npc.child) return; + + Entity_NPC* twin = dark_esau_twin_spawn(npc, npc.spawnerEntity); + npc.pos.x -= ESAU_TWIN_OFFSET; + for (auto [esau, side] : {std::pair{&npc, -1.0f}, std::pair{twin, 1.0f}}) + { + esau->sprite.Play("Charge"); + esau->sprite.SetLastFrame(); + esau->state = NPC_STATE_ATTACK; + esau->stateFrame = SPLIT_WINDUP; + esau->target = nullptr; + esau->targetPosition = vector_make(side, 0); + esau->SetColor(SPLIT_FLASH, SPLIT_FLASH_FRAMES, COLOR_PRIORITY_DEFAULT, true, true); + } + npc.MakeGroundPoofAtSelf(SPLIT_POOF_COLOR, 1); + npc.PlaySound(SOUND_GHOST_ROAR, 1, 2, false, 1); + npc.PlaySound(SOUND_FLAME_BURST, 1, 2, false, 1); + npc.PlaySound(SOUND_BERSERK_START, 1, 2, false, SPLIT_PITCH); +} + +// Climbing out of the hole: the landing shakes the screen and turns him solid, then rings of shots while his player +// can act, and he rests once out. +static void dark_esau_appear(Entity_NPC& npc, Entity_Player* owner) +{ + npc.friction *= ESAU_FRICTION_DASH; + if (npc.sprite.IsEventTriggered("Shoot")) + { + npc.PlaySound(SOUND_GHOST_ROAR, 1, 2, false, 1); + game_shake_screen(APPEAR_SHAKE); + npc.entityCollisionClass = ENTCOLL_ALL; + npc.shadowSize = npc.config->shadowSize; + npc.stateFrame = APPEAR_RINGS; + } + Entity* spawner = npc.spawnerEntity; + bool isOwnerActive = !owner || static_cast(spawner)->AreControlsEnabled(); + if (npc.sprite.WasEventTriggered("Shoot") && npc.GetIntervalTicks(APPEAR_RING_INTERVAL, 0) && npc.stateFrame > 0 && + isOwnerActive) + { + ProjectileParams params; + params.variant = PROJECTILE_FIRE; + params.bulletFlags = PROJECTILE_HIT_ENEMIES; + params.fallingAccelModifier = APPEAR_SHOT_FALL; + if (npc.subtype != 0) params.color = APPEAR_SHOT_COLOR_TWIN; + npc.FireProjectiles(npc.pos, vector_make(APPEAR_SHOT_SPEED, APPEAR_SHOT_COUNT), PROJECTILES_RING, params); + npc.stateFrame--; + } + if (npc.sprite.animState.animData && npc.sprite.animState.isPlaying) return; + + npc.entityRef = nullptr; + npc.state = NPC_STATE_IDLE; + npc.sprite.Play("Idle"); +} + +// With Birthright, Dark Esau splits in two as he comes in: a twin climbs out beside him, or he splits where he stands. +static void dark_esau_birthright_split(Entity_NPC& npc, Entity_Player* owner) +{ + if (npc.state == NPC_STATE_INIT) + { + if (!npc.HasEntityFlags(FLAG_APPEAR)) dark_esau_twin_spawn(npc, owner); + return; + } + if (npc.state != NPC_STATE_SPECIAL) + { + npc.state = ESAU_STATE_SPLIT; + npc.sprite.Play("Split"); + return; + } + if (!npc.sprite.IsPlaying("Appear") || npc.sprite.GetFrame() >= 6) return; + + Entity_NPC* twin = dark_esau_twin_spawn(npc, owner); + twin->sprite.Play("Appear"); + twin->sprite.animState.SetFrameFloat((float)npc.sprite.GetFrame()); + twin->AddEntityFlags(FLAG_NO_TARGET); + twin->shadowSize = 0; + twin->entityRef = npc.entityRef; + twin->state = NPC_STATE_SPECIAL; + twin->entityCollisionClass = ENTCOLL_NONE; + twin->entityGridCollisionClass = GRIDCOLL_NONE; + npc.pos.x -= ESAU_TWIN_OFFSET; +} + +// 005542e0 Dark Esau (866), Tainted Jacob's pursuer: invincible, he climbs out of a hole, drifts after Jacob and +// charges at him when lined up, burning enemies and clearing shots on the way. Anima Sola chains him, Birthright +// splits him in two, and his death opens the floor. +void npc_dark_esau_update(Entity_NPC& npc) +{ + int ticks = (int)npc.updateTime - (int)npc.prevUpdateTime; + Entity_Player* owner = dark_esau_owner(npc); + if (npc.aiCallPhase == AI_PHASE_PRE_UPDATE) return dark_esau_pre_update(npc); + if (npc.aiCallPhase == AI_PHASE_COLLISION) return dark_esau_collide(npc, owner); + if (npc.variant != DARK_ESAU) + { + dark_esau_hole_update(npc, ticks); + if (npc.isDead) npc.velocity = {}; + return; + } + + bool isOwnerFrozen = owner && (!owner->isControlsEnabled || owner->controlsCooldown >= 1); + if ((npc.state == NPC_STATE_ATTACK || npc.state == NPC_STATE_ATTACK2) && isOwnerFrozen) + { + npc.state = NPC_STATE_IDLE; + npc.sprite.Play("Idle"); + npc.i1 = REST_FROZEN; + } + bool isSplitting = npc.state == ESAU_STATE_SPLIT || npc.state == ESAU_STATE_CHAINED; + if (!isSplitting && g_game->room->IsPositionInRoom(npc.pos, ESAU_ROOM_MARGIN) && owner && + owner->HasCollectible(COLLECTIBLE_BIRTHRIGHT) && !npc.child) + dark_esau_birthright_split(npc, owner); + + Entity* twin = dark_esau_twin(npc); + switch (npc.state) + { + case NPC_STATE_INIT: + dark_esau_init(npc); + break; + case NPC_STATE_IDLE: + dark_esau_chase(npc, owner, twin, isOwnerFrozen, ticks); + break; + case ESAU_STATE_CHAINED: + dark_esau_chained(npc); + break; + case NPC_STATE_ATTACK: + case NPC_STATE_ATTACK2: + dark_esau_dash(npc, ticks); + break; + case ESAU_STATE_SPLIT: + dark_esau_split(npc, owner); + break; + case NPC_STATE_SPECIAL: + dark_esau_appear(npc, owner); + break; + } + + Entity* hole = npc.entityRef; + if (hole && hole->type == ENTITY_DARK_ESAU) + { + float x = hole->pos.x + (npc.child ? -ESAU_TWIN_OFFSET : npc.parent ? ESAU_TWIN_OFFSET : 0); + npc.velocity = vector_make(x - npc.pos.x, hole->pos.y - npc.pos.y); + } + if (npc.isDead) npc.velocity = {}; +} diff --git a/src/npc_depths.h b/src/npc_depths.h index 94aa445..1c3fcdf 100644 --- a/src/npc_depths.h +++ b/src/npc_depths.h @@ -19,3 +19,12 @@ void npc_fred_update(Entity_NPC& npc); void npc_eye_update(Entity_NPC& npc); void npc_meatball_update(Entity_NPC& npc); void npc_wall_creep_update(Entity_NPC& npc); +void npc_poky_update(Entity_NPC& npc); +void npc_hanger_update(Entity_NPC& npc); +void npc_mobile_host_update(Entity_NPC& npc); +void npc_wizoob_update(Entity_NPC& npc); +void npc_mr_maw_update(Entity_NPC& npc); +void npc_cod_worm_update(Entity_NPC& npc); +void npc_moms_hand_update(Entity_NPC& npc); +void npc_hush_gaper_update(Entity_NPC& npc); +void npc_greed_gaper_update(Entity_NPC& npc); diff --git a/src/npc_fire_worm.cpp b/src/npc_fire_worm.cpp new file mode 100644 index 0000000..0a607fa --- /dev/null +++ b/src/npc_fire_worm.cpp @@ -0,0 +1,184 @@ +#include "npc_alt.h" +#include "boss_ai.h" +#include "npc_caves.h" +#include "npc_fireplace.h" + +// The Fire Worm lives in the lava pits: it digs out of a free pit, spits a fireball at 14 when it sees its prey, digs +// in, and comes out of another pit (half the time, while its prey is off the pits or over 100 away and within 1000). +// A worm without a pit, or whose pit is gone, dies. +constexpr float FIRE_WORM_FRICTION = 0.8f; +constexpr float FIRE_WORM_SPIT_SPEED = 14; +constexpr float FIRE_WORM_SPIT_REACH = 10; +constexpr float FIRE_WORM_NEAR = 100; +constexpr float FIRE_WORM_FAR = 1000; +constexpr int16_t FIRE_WORM_PIT_TIMER = 5; +constexpr int FIRE_SPIT_SUBTYPE = 1; + +// How FindTargetPit scores a pit: closer to the first spot is better, the second spot's pit (and within 60 of it) +// worse, a pit in the middle of pits better, with a random 500 added. +constexpr float PIT_SCORE_NONE = -1e6f; +constexpr float PIT_SCORE_BASE = 2000; +constexpr float PIT_SCORE_AWAY = 3; +constexpr float PIT_SCORE_SURROUNDED = 200; +constexpr float PIT_SCORE_RANDOM = 500; +constexpr float PIT_TOO_CLOSE = 60; + +// Whether the pit beside a cell is a pit too, by a column and row step. +static bool is_pit_beside(Room& room, int cell, int columnStep, int rowStep) +{ + return room.GetGridCollision(room.GetGridIndexByTile(cell % room.gridWidth + columnStep, + cell / room.gridWidth + rowStep)) == COLLISION_PIT; +} + +// 00548f30 The best free, unbusy pit to come out of: the nearest to pos1, or with a pit to leave (pitIndex) one away +// from pos2 and from that pit, liked in the middle of pits, chosen with some chance. -1 without one. +int Entity_NPC::FindTargetPit(const Vector& pos1, const Vector& pos2, uint32_t pitIndex) +{ + Room& room = *g_game->room; + int best = -1; + float bestScore = PIT_SCORE_NONE; + + for (int cell = 0; cell < room.gridWidth * room.gridHeight; cell++) + { + GridEntity* pit = cell < ROOM_GRID_CELLS ? room.gridEntities[cell] : nullptr; + if (!pit || pit->type != GRID_PIT || pit->state != 0 || room.gridTimers[cell] != 0) continue; + + Vector spot = room.GetGridPosition(pit->gridIndex); + float score = PIT_SCORE_BASE - vector_length(vector_sub(pos1, spot)); + if ((int)pitIndex >= 0) + { + float away = vector_length(vector_sub(pos2, spot)); + if (away < PIT_TOO_CLOSE) continue; + + score -= away * PIT_SCORE_AWAY; + if ((uint32_t)cell == pitIndex) score -= PIT_SCORE_BASE; + // The original looks below twice and never above. + if (is_pit_beside(room, cell, 1, 0) && is_pit_beside(room, cell, -1, 0) && is_pit_beside(room, cell, 0, 1) && + is_pit_beside(room, cell, 0, 1)) + score += PIT_SCORE_SURROUNDED; + score += random_unit() * PIT_SCORE_RANDOM; + } + if (score > bestScore) + { + best = cell; + bestScore = score; + } + } + return best; +} + +// Comes up in a pit: there, its cell busy for a while. +static void fire_worm_surface(Entity_NPC& npc, int pit) +{ + Room& room = *g_game->room; + + npc.i1 = pit; + if (pit < ROOM_GRID_CELLS) room.gridTimers[pit] = FIRE_WORM_PIT_TIMER; + npc.pos = room.GetGridPosition(pit); + npc.targetPosition = npc.pos; +} + +// Out of its pit: it dies once the pit is no pit (and always in Home's dungeon), keeps the pit busy, and spits a +// fireball at its prey on Shoot when it sees it, unless confused or afraid. Whether it still lives. +static bool fire_worm_out(Entity_NPC& npc) +{ + Room& room = *g_game->room; + + npc.sprite.Play("DigOut"); + npc.entityCollisionClass = ENTCOLL_ALL; + if (npc.i1 >= 0) + { + if (room.GetGridCollision(npc.i1) != COLLISION_PIT) + { + npc.Kill(EntityRef()); + return false; + } + if (npc.i1 < ROOM_GRID_CELLS) room.gridTimers[npc.i1] = FIRE_WORM_PIT_TIMER; + } + + Vector prey = npc.GetPlayerTarget()->pos; + bool isSpitting = npc.sprite.animState.animData && npc.sprite.IsEventTriggered("Shoot") && + !npc.HasEntityFlags(FLAG_CONFUSION | FLAG_FEAR | FLAG_SHRINK) && + room_check_line(npc.pos, prey, LINE_MODE_PROJECTILE, LINE_CHECK_THRESHOLD); + if (isSpitting) + { + npc.PlaySound(SOUND_WORM_SPIT, 1, 2, false, 1); + Vector way = vector_normalized(vector_sub(prey, npc.pos)); + uint32_t seed = Random(); + Entity* fire = g_game->Spawn({.position = vector_add(vector_scale(way, FIRE_WORM_SPIT_REACH), npc.pos), + .velocity = vector_scale(way, FIRE_WORM_SPIT_SPEED), + .spawner = &npc, + .subType = FIRE_SPIT_SUBTYPE, + .type = ENTITY_FIREPLACE, + .variant = FIRE_MOVEABLE, + .seed = seed}); + fire->parent = &npc; + } + if (npc_anim_is_done(npc)) npc.state = NPC_STATE_IDLE; + return true; +} + +// Under the lava: it picks the next pit away from its prey's way and comes up there, at once half the time. +static void fire_worm_under(Entity_NPC& npc) +{ + Room& room = *g_game->room; + int pit = Entity_NPC::FindTargetPit(npc.pos, npc.CalcTargetPosition(0), (uint32_t)room.GetGridIndex(npc.pos)); + if (pit < 0) return npc.Remove(); + + Vector spot = room.GetGridPosition(pit); + Entity* prey = npc.GetPlayerTarget(); + bool isPreyOnPit = room.GetGridCollision(room.GetGridIndex(prey->pos)) == COLLISION_PIT; + float distance = vector_length(vector_sub(npc.pos, prey->pos)); + if ((Random() & 1) == 0 && (!isPreyOnPit || distance > FIRE_WORM_NEAR) && distance < FIRE_WORM_FAR) + { + npc.targetPosition = spot; + npc.pos = spot; + } + if (vector_is_zero(npc.targetPosition)) return; + + npc.i1 = pit; + if (pit < ROOM_GRID_CELLS) room.gridTimers[pit] = FIRE_WORM_PIT_TIMER; + npc.state = NPC_STATE_JUMP; + npc.isVisible = true; +} + +// 00500990 (NpcAI::ENTITY_FIRE_WORM) The Fire Worm: it starts in the pit nearest it, digs in (staying down for good +// once dying), moves under the lava and digs out, held at its pit. +void npc_fire_worm_update(Entity_NPC& npc) +{ + switch (npc.state) + { + case NPC_STATE_INIT: + { + npc.state = NPC_STATE_IDLE; + npc.targetPosition = npc.pos; + npc.splatColor = ROCK_SPLAT_COLOR; + int pit = Entity_NPC::FindTargetPit(npc.pos, npc.pos, UINT32_MAX); + if (pit < 0) npc.Remove(); + else fire_worm_surface(npc, pit); + break; + } + case NPC_STATE_IDLE: + npc.sprite.Play("DigIn"); + if (!npc_anim_is_done(npc)) break; + npc.i1 = -1; + if (npc.pendingDamage >= npc.health) + { + npc.state = NPC_STATE_JUMP; + break; + } + npc.state = NPC_STATE_MOVE; + npc.targetPosition = Vector{}; + npc.entityCollisionClass = ENTCOLL_NONE; + npc.isVisible = false; + break; + case NPC_STATE_MOVE: fire_worm_under(npc); break; + case NPC_STATE_JUMP: + if (!fire_worm_out(npc)) return; + break; + } + if (vector_is_zero(npc.targetPosition)) return; + + npc.velocity = vector_sub(npc.targetPosition, npc.pos); + npc.friction *= FIRE_WORM_FRICTION; +} diff --git a/src/npc_fireplace.cpp b/src/npc_fireplace.cpp index 3f4a86d..82715b2 100644 --- a/src/npc_fireplace.cpp +++ b/src/npc_fireplace.cpp @@ -6,6 +6,7 @@ #include "entity_projectile.h" #include "game.h" #include "npc_ai.h" +#include "npc_alt.h" #include "room.h" #include @@ -81,7 +82,6 @@ constexpr float RELIGHT_OFFSET = 0.35f; constexpr float RELIGHT_BLUE = 0.5f; // The sounds of a fire: lit again, and put out. -constexpr int SOUND_STEAM_HALFSEC = 261; constexpr float PUT_OUT_VOLUME = 0.85f; // What a fire drops: one time in four (one in ten on Hard), from normal fires a heart one time in four and else a @@ -391,7 +391,7 @@ void npc_fireplace_update(Entity_NPC& npc) { if (!is_magic_fire(npc.variant) && g_game->room->waterAmount > FIRE_WATER_LEVEL && npc.IsFrame(FIRE_WATER_FRAMES, (int)npc.index)) npc.TakeDamage(1, 0, EntityRef(), FIRE_WATER_DAMAGE_COUNTDOWN); - if (npc.variant == FIRE_COAL) return NpcAI::ENTITY_ROCK_SPIDER(&npc); + if (npc.variant == FIRE_COAL) return npc_rock_spider_update(npc); if (npc.variant == FIRE_MOVEABLE || npc.variant == FIRE_MOVEABLE_BLUE || npc.variant == FIRE_MOVEABLE_PURPLE) return NpcHelper::fireplace_moveable_update(&npc); diff --git a/src/npc_fly.cpp b/src/npc_fly.cpp index 467f913..5c47440 100644 --- a/src/npc_fly.cpp +++ b/src/npc_fly.cpp @@ -1,4 +1,5 @@ #include "npc_basement.h" +#include "boss_ai.h" #include "entity_bomb.h" #include "entity_config.h" #include "entity_player.h" @@ -571,7 +572,7 @@ void npc_fly_update(Entity_NPC& npc) if (npc.type == ENTITY_POOTER && !isSkatoleActive) pooter_attack_update(npc); bool isIsaacsFly = npc.spawnerType == ENTITY_ISAAC_BOSS && npc.subtype != 0; - if (isIsaacsFly) NpcAI::ENTITY_FLY_isaac_spawned(&npc); + if (isIsaacsFly) npc_isaac_fly_update(npc); else if (npc.spawnerType == ENTITY_ORBIT_SPAWNER) return NpcAI::ENTITY_FLY_orbit_parent(&npc); else { diff --git a/src/npc_hanger.cpp b/src/npc_hanger.cpp new file mode 100644 index 0000000..587d138 --- /dev/null +++ b/src/npc_hanger.cpp @@ -0,0 +1,111 @@ +#include "boss_ai.h" +#include "npc_depths.h" + +// The Keeper's four faces, its spit's reach, pause and spread, and how it hangs. +constexpr uint32_t HANGER_FACES = 4; +constexpr ColorMod HANGER_SPLAT_COLOR = {{0.4f, 0.2f, 0.2f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr float HANGER_WALL_MARGIN = 30; +constexpr float HANGER_TOP_MARGIN = 10; +constexpr uint32_t HANGER_DRIP_ODDS = 10; +constexpr float HANGER_DRIP_SIZE = 0.5f; +constexpr float HANGER_DRIP_MIN = 0.4f; +constexpr float HANGER_TARGET_REACH = 10; +constexpr float HANGER_CONTROL_REACH = 100; +constexpr float HANGER_RANGE = 260; +constexpr int HANGER_RANGE_FRAMES = 7; +constexpr int HANGER_COOLDOWN_UNIT = 7; +constexpr int HANGER_COOLDOWN_MIN = 6; +constexpr float HANGER_CONTROL_DEADZONE = 0.1f; +constexpr float HANGER_MIN_FRICTION = 0.01f; +constexpr float HANGER_MIN_DISTANCE = 0.1f; +constexpr float HANGER_ACCEL = 0.13f; +constexpr float HANGER_SHOT_HEIGHT = -20; +constexpr float HANGER_SHOT_FALL = 2; +constexpr float HANGER_SHOT_SPEED = 7; +constexpr float HANGER_FRICTION = 0.93f; + +// Its face's idle and spitting animations. +static std::string face_animation_get(Entity_NPC& npc, std::string_view kind) +{ + return std::string(kind) + "0" + std::to_string(npc.i1 + 1); +} + +// The aim toward its target, or its controller's steer. +static Vector hanger_aim_get(Entity_NPC& npc, Vector target) +{ + if (npc.controllerID == -1) return vector_sub(target, npc.pos); + return vector_scale(npc.controllerMovement, HANGER_CONTROL_REACH); +} + +// Hanging, it drifts toward its target and starts spitting once it is in range and its cooldown is over. +static void hanger_drift(Entity_NPC& npc) +{ + Vector aim = vector_sub(npc.CalcTargetPosition(HANGER_TARGET_REACH), npc.pos); + if (npc.controllerID != -1) aim = vector_scale(npc.GetControllerInput(0), HANGER_CONTROL_REACH); + + bool isReady = npc.projectileCooldown < 1 || (npc.projectileCooldown -= npc_ticks_get(npc)) < 1; + if (isReady && npc.IsTargetInAttackRange(HANGER_RANGE, HANGER_RANGE_FRAMES, false)) + { + npc.controllerMovement = + npc.controllerID == -1 ? Vector{} : npc.GetControllerMovementInput(HANGER_CONTROL_DEADZONE); + npc_anim_restart(npc.sprite, face_animation_get(npc, "AttackHead")); + npc.sprite.isFlipX = (npc.controllerID == -1 ? aim.x : npc.controllerMovement.x) > 0; + npc.state = NPC_STATE_ATTACK; + npc.projectileCooldown = (int)((Random() & 1) + HANGER_COOLDOWN_MIN) * HANGER_COOLDOWN_UNIT; + } + + if (std::abs(npc.friction) <= HANGER_MIN_FRICTION) return; + float distance = vector_length(aim); + float push = std::abs(distance) <= HANGER_MIN_DISTANCE ? 0 : HANGER_ACCEL / distance; + npc_push(npc, vector_scale(aim, push)); +} + +// Spitting, it fires three shots at its target on the Shoot event, then hangs again once the animation ends. +static void hanger_spit(Entity_NPC& npc) +{ + if (npc.controllerID == -1) npc.controllerMovement = {}; + else + { + Vector input = npc.GetControllerMovementInput(HANGER_CONTROL_DEADZONE); + if (!vector_is_zero(input)) npc.controllerMovement = input; + } + + if (npc.sprite.animState.animData) + { + if (npc.sprite.animState.IsEventTriggered("Shoot")) + { + npc_sound_play(SOUND_BLOODSHOOT, 1, 2, champion_pitch_get(npc)); + ProjectileParams params; + params.heightModifier += HANGER_SHOT_HEIGHT; + params.fallingSpeedModifier += HANGER_SHOT_FALL; + Vector aim = hanger_aim_get(npc, npc.GetPlayerTarget()->pos); + Vector velocity = vector_scale(vector_normalized(aim), HANGER_SHOT_SPEED); + npc.FireProjectiles(npc.pos, velocity, PROJECTILES_THREE, params); + } + if (!npc_anim_is_done(npc)) return; + } + npc_anim_restart(npc.sprite, face_animation_get(npc, "Head")); + npc.state = NPC_STATE_MOVE; +} + +// 0051cb30 NpcAI::ENTITY_HANGER: the Keeper, a hanging head with an eternal fly that drifts after its target, kept +// near the top wall, and spits three shots at it when in range. +void npc_hanger_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.state = NPC_STATE_MOVE; + Entity* fly = g_game->Spawn({.position = npc.pos, .spawner = &npc, .type = ENTITY_ETERNALFLY, .seed = Random()}); + fly->parent = &npc; + npc.splatColor = HANGER_SPLAT_COLOR; + RNG faces = {npc.initSeed, 5, 9, 7}; + npc.i1 = (int)faces.RandomInt(HANGER_FACES); + npc_anim_loop(npc.sprite, face_animation_get(npc, "Head")); + } + + npc.pos = g_game->room->GetClampedPositionImpl(npc.pos, HANGER_WALL_MARGIN, 0, HANGER_TOP_MARGIN, 0); + if (Random() % HANGER_DRIP_ODDS == 0) npc.MakeSplat(random_unit() * HANGER_DRIP_SIZE + HANGER_DRIP_MIN); + if (npc.state != NPC_STATE_ATTACK) hanger_drift(npc); + else hanger_spit(npc); + npc.friction *= HANGER_FRICTION; +} diff --git a/src/npc_hardy.cpp b/src/npc_hardy.cpp index a0502d5..9d76569 100644 --- a/src/npc_hardy.cpp +++ b/src/npc_hardy.cpp @@ -12,7 +12,6 @@ constexpr float HARDY_FRICTION = 0.95f; constexpr float HARDY_REST_FRICTION = 0.5f; constexpr float HARDY_CRASH_FRICTION = 0.6f; constexpr float HARDY_BRAKE_FRICTION = 0.8f; -constexpr ColorMod HARDY_SPLAT_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {30 / 255.0f, 30 / 255.0f, 30 / 255.0f}}; constexpr uint32_t HARDY_START_ODDS = 5; constexpr int HARDY_START_FRAMES = 5; constexpr int HARDY_REST_FRAMES = 60; @@ -66,13 +65,13 @@ static void hardy_play(Entity_NPC& npc, std::string_view name) npc.sprite.Play(std::string(name) + std::to_string(npc.subtype + 1)); } -// 004f9920 (Entity_NPC::ThrowRockSpider) Throws a rock spider (a coal spider, a fireplace, for the coal kind) at a +// 004f9920 (Entity_NPC::ThrowRockSpider) Throws a rock spider (a coal fire, a fireplace, for the coal fire kind) at a // velocity from a height, landing in its jump, charmed with a charmed spawner. Thrown high it passes over everything. Entity_NPC* rock_spider_throw(const Vector& position, const Vector& velocity, Entity* spawner, RockSpiderKind kind, float height) { - int type = kind == SPIDER_THROW_COAL ? ENTITY_FIREPLACE : ENTITY_ROCK_SPIDER; - int variant = kind == SPIDER_THROW_COAL ? (int)FIRE_COAL : (int)kind; + int type = kind == SPIDER_THROW_COAL_FIRE ? ENTITY_FIREPLACE : ENTITY_ROCK_SPIDER; + int variant = kind == SPIDER_THROW_COAL_FIRE ? (int)FIRE_COAL : (int)kind; auto* spider = static_cast( g_game->Spawn({.position = position, .spawner = spawner, .type = type, .variant = variant, .seed = Random()})); spider->ClearEntityFlags(FLAG_APPEAR); @@ -147,7 +146,7 @@ static void hardy_crash(Entity_NPC& npc, Vector contact) Vector direction = vector_make(cosine * back.x - sine * back.y, cosine * back.y + sine * back.x); Vector position = vector_add(vector_scale(direction, HARDY_SPIDER_REACH), npc.pos); float speed = random_unit() * 2 + 1; - rock_spider_throw(position, vector_scale(direction, speed), &npc, SPIDER_THROW_SMALL, HARDY_SPIDER_HEIGHT); + rock_spider_throw(position, vector_scale(direction, speed), &npc, SPIDER_THROW_ROCK, HARDY_SPIDER_HEIGHT); } } npc.state = NPC_STATE_SPECIAL; @@ -220,7 +219,7 @@ void npc_hardy_update(Entity_NPC& npc) case NPC_STATE_INIT: npc.stateFrame = 0; npc.state = NPC_STATE_IDLE; - npc.splatColor = HARDY_SPLAT_COLOR; + npc.splatColor = ROCK_SPLAT_COLOR; break; case NPC_STATE_IDLE: hardy_rest(npc); break; case NPC_STATE_MOVE: diff --git a/src/npc_hush_gaper.cpp b/src/npc_hush_gaper.cpp new file mode 100644 index 0000000..dc193c8 --- /dev/null +++ b/src/npc_hush_gaper.cpp @@ -0,0 +1,105 @@ +#include "boss_ai.h" +#include "npc_depths.h" + +// The Blue and Greed Gapers' walk, and the groan it lets out now and then while it sees its target. +constexpr float HUSH_GAPER_WALK_SPEED = 0.1f; +constexpr float HUSH_GAPER_AI_FLOAT = 0.6f; +constexpr float HUSH_GAPER_PATH_SPEED = 0.6f; +constexpr int HUSH_GAPER_PATH_MARKER = 900; +constexpr float HUSH_GAPER_EVADE_FRICTION = 0.8f; +constexpr uint32_t HUSH_GAPER_GROAN_ODDS = 30; +constexpr int HUSH_GAPER_GROAN_DELAY = 120; + +// Stops a sprite's animation on its first frame, the way the AIs set one up to walk. +static void anim_first_frame_set(ANM2& sprite, std::string_view name) +{ + if (!sprite.SetAnimation(name, SWITCH_KEEP_FRAME) || !sprite.animState.animData) return; + sprite.animState.SetFrameFloat(0); + sprite.animState.isPlaying = false; +} + +// The walk the Blue and Greed Gapers share: after their target (fleeing while scared), groaning now and then while +// they see it. +static void gaper_kin_walk(Entity_NPC& npc) +{ + npc.AnimWalkFrame("WalkHori", "WalkVert", HUSH_GAPER_WALK_SPEED); + npc.aiFloat = HUSH_GAPER_AI_FLOAT; + if (!npc.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK)) + npc.pathfinder.FindGridPath(npc.CalcTargetPosition(0), HUSH_GAPER_PATH_SPEED, HUSH_GAPER_PATH_MARKER, + DIRECT_PATH_FAR); + else + { + npc.pathfinder.EvadeTarget(npc.GetPlayerTarget()->pos, STATUS_OBEYED); + npc.friction *= HUSH_GAPER_EVADE_FRICTION; + } + if (!npc.pathfinder.hasDirectPath || Random() % HUSH_GAPER_GROAN_ODDS != 0) return; + npc_sound_play(SOUND_ZOMBIE_WALKER_KID, 1, HUSH_GAPER_GROAN_DELAY, champion_pitch_get(npc)); +} + +// It walks with its head on. +static void hush_gaper_walk_start(Entity_NPC& npc) +{ + npc.state = NPC_STATE_MOVE; + npc.stateFrame = 0; + anim_first_frame_set(npc.sprite, "WalkVert"); + if (npc.sprite.SetOverlayAnimation("Head", SWITCH_KEEP_FRAME) && npc.sprite.overlayAnimState.animData) + npc.sprite.overlayAnimState.SetFrameFloat(0); +} + +// 004bee40 NpcAI::ENTITY_HUSH_GAPER: the Blue Gaper rises (unless the room just started) and walks after its target, +// groaning. Shots from its own kind pass it by. +void npc_hush_gaper_update(Entity_NPC& npc) +{ + if (npc.pendingDamage > 0) + for (DamageEvent& event : npc.damageEvents) + if (event.source.spawnerType == npc.type) event.damage = 0; + + if (npc.state == NPC_STATE_INIT) + { + if (g_game->room->GetFrameCount() == 0) hush_gaper_walk_start(npc); + else + { + npc.ClearEntityFlags(FLAG_APPEAR); + npc.state = NPC_STATE_SPECIAL; + npc_anim_loop(npc.sprite, "WalkVertAppear"); + npc_overlay_loop(npc.sprite, "HeadAppear"); + npc.entityCollisionClass = ENTCOLL_NONE; + } + } + if (npc.state == NPC_STATE_SPECIAL) + { + if (!npc_anim_is_done(npc)) return; + hush_gaper_walk_start(npc); + npc.entityCollisionClass = ENTCOLL_ALL; + return; + } + + gaper_kin_walk(npc); +} + +// The Greed Gaper's four heads. +constexpr const char* GREED_GAPER_HEADS[] = {"Head1", "Head2", "Head3", "Head4"}; +constexpr uint32_t GREED_GAPER_HEAD_MASK = 3; + +// 005a6b80 NpcAI::ENTITY_GREED_GAPER: the Greed Gaper wears one of four heads and walks after its target, groaning. +// Shots from its own kind pass it by. +void npc_greed_gaper_update(Entity_NPC& npc) +{ + if (npc.pendingDamage > 0) + for (DamageEvent& event : npc.damageEvents) + if (event.source.spawnerType == npc.type) event.damage = 0; + + if (npc.state == NPC_STATE_INIT) + { + if (g_game->room->GetFrameCount() == 0) anim_first_frame_set(npc.sprite, "WalkVert"); + else + { + npc.ClearEntityFlags(FLAG_APPEAR); + npc.entityCollisionClass = ENTCOLL_ALL; + } + npc_overlay_loop(npc.sprite, GREED_GAPER_HEADS[npc.index & GREED_GAPER_HEAD_MASK]); + npc.state = NPC_STATE_MOVE; + } + else if (npc.state != NPC_STATE_MOVE) return; + gaper_kin_walk(npc); +} diff --git a/src/npc_mobile_host.cpp b/src/npc_mobile_host.cpp new file mode 100644 index 0000000..e1e0776 --- /dev/null +++ b/src/npc_mobile_host.cpp @@ -0,0 +1,202 @@ +#include "boss_ai.h" +#include "npc_depths.h" + +// The Mobile Host (armored unless subtype 99) and the Flesh Mobile Host. +constexpr int MOBILE_HOST_UNARMORED = 99; + +// Its shell: how hits shake it shut, the blast that knocks its skull loose, and the charge a controlled one builds. +constexpr float MOBILE_HOST_SHAKE_LOSS = 0.05f; +constexpr int MOBILE_HOST_SHAKE_MAX = 10; +constexpr float MOBILE_HOST_ROUND = 0.5f; +constexpr float MOBILE_HOST_BOMBED_DAMAGE = 20; +constexpr float MOBILE_HOST_CHARGE_FRAMES = 90; +constexpr float MOBILE_HOST_CHARGE_FAST = 2; +constexpr uint64_t MOBILE_HOST_PASSED_DAMAGE = DAMAGE_POISON_BURN; +constexpr uint64_t MOBILE_HOST_UNCOUNTED_DAMAGE = DAMAGE_POISON_BURN | DAMAGE_BOOGER; + +// Its walk and spit. +constexpr float MOBILE_HOST_WALK_SPEED = 0.1f; +constexpr float MOBILE_HOST_PATH_SPEED = 0.5f; +constexpr int MOBILE_HOST_PATH_MARKER = 300; +constexpr float MOBILE_HOST_EVADE_FRICTION = 0.8f; +constexpr uint32_t MOBILE_HOST_PANIC_ODDS = 50; +constexpr uint32_t MOBILE_HOST_SPIT_ODDS = 3; +constexpr float MOBILE_HOST_RANGE = 240; +constexpr float MOBILE_HOST_CONTROL_RANGE = 1000; +constexpr int MOBILE_HOST_RANGE_FRAMES = 7; +constexpr int MOBILE_HOST_COOLDOWN = 70; +constexpr float MOBILE_HOST_CALM_FRAMES = 7; +constexpr float MOBILE_HOST_SHOT_SPEED = 7; +constexpr float MOBILE_HOST_POOF_SCALE = 0.65f; +constexpr float MOBILE_HOST_POOF_RAISE = -6; +constexpr float MOBILE_HOST_POOF_SIZE = 0.75f; +constexpr float MOBILE_HOST_POOF_DEPTH = 100; +constexpr float MOBILE_HOST_MOVE_FRICTION = 0.8f; +constexpr float MOBILE_HOST_ATTACK_FRICTION = 0.5f; + +// Hits on its closed shell do nothing. Enough of them shake it shut for longer, and a blast knocks its skull loose. +static void mobile_host_shell_hit(Entity_NPC& npc) +{ + const AnimationState& overlay = npc.sprite.overlayAnimState; + bool isClosed = npc.state == NPC_STATE_MOVE || + (npc.state == NPC_STATE_ATTACK && + (overlay.WasEventTriggered("Invincible") || !overlay.WasEventTriggered("Destructible"))); + float blocked = 0; + if (isClosed) + for (DamageEvent& event : npc.damageEvents) + { + if (event.damageFlags & MOBILE_HOST_PASSED_DAMAGE) continue; + if (!(event.damageFlags & MOBILE_HOST_UNCOUNTED_DAMAGE)) blocked += event.damage; + event.damage = 0; + } + if (npc.state != NPC_STATE_MOVE || blocked <= 0) return; + + npc.stateFrame = std::min(npc.stateFrame + (int)(npc.pendingDamage + MOBILE_HOST_ROUND) / 2, MOBILE_HOST_SHAKE_MAX); + npc.v2.x = std::max(npc.v2.x - npc.pendingDamage * MOBILE_HOST_SHAKE_LOSS, 0.0f); + if (blocked <= MOBILE_HOST_BOMBED_DAMAGE) return; + npc.sprite.PlayOverlay("Bombed"); + npc.v2.x = 0; +} + +// A controlled one's charge: it builds while its armored shell is shut (faster while distracted) and drains otherwise. +static void mobile_host_charge_update(Entity_NPC& npc, bool isArmored) +{ + const AnimationState& overlay = npc.sprite.overlayAnimState; + bool isBombed = overlay.animData && overlay.isPlaying && overlay.animData->name == "Bombed"; + float charge = 0; + if (npc.HasEntityFlags(FLAG_NO_TARGET) && !isBombed && isArmored) + { + float rate = npc.HasEntityFlags(FLAG_DISTRACTED) ? MOBILE_HOST_CHARGE_FAST : 1; + charge = std::min(rate * npc.speedMultiplier / MOBILE_HOST_CHARGE_FRAMES + npc.v2.y, 1.0f); + } + else if (isArmored) + charge = std::max(npc.v2.y - (npc.speedMultiplier + npc.speedMultiplier) / MOBILE_HOST_CHARGE_FRAMES, 0.0f); + npc.v2.y = charge; + npc.UpdateChargeBar(1, 0, charge, true); +} + +// It walks after its target (fleeing while scared) with its shell shut, and opens up to spit when in range. +static void mobile_host_walk(Entity_NPC& npc, bool isArmored) +{ + if (isArmored) npc.AddEntityFlags(FLAG_NO_TARGET); + Vector target = npc.GetPlayerTarget()->pos; + if (!npc.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK) || npc.controllerID != -1) + npc.pathfinder.FindGridPath(target, MOBILE_HOST_PATH_SPEED, MOBILE_HOST_PATH_MARKER, DIRECT_PATH_FAR); + else + { + npc.pathfinder.EvadeTarget(target, STATUS_OBEYED); + if (npc.pathfinder.evadeMovementCountdown > 0) npc.friction *= MOBILE_HOST_EVADE_FRICTION; + } + if (npc.stateFrame < 1) npc.sprite.PlayOverlay("Idle"); + + bool isSpitting = false; + if (npc.controllerID == -1) + { + if (npc.stateFrame < 1 && npc.HasEntityFlags(FLAG_CONFUSION | FLAG_FEAR | FLAG_SHRINK) && + Random() % MOBILE_HOST_PANIC_ODDS == 0) + { + npc.state = NPC_STATE_ATTACK2; + npc.stateFrame = 0; + } + isSpitting = npc.stateFrame < 1 && Random() % MOBILE_HOST_SPIT_ODDS == 0 && + (npc.projectileCooldown < 1 || (npc.projectileCooldown -= npc_ticks_get(npc)) < 1) && + npc.IsTargetInAttackRange(MOBILE_HOST_RANGE, MOBILE_HOST_RANGE_FRAMES, false); + } + else if (npc.v2.y >= 1 || npc.IsTargetInAttackRange(MOBILE_HOST_CONTROL_RANGE, MOBILE_HOST_RANGE_FRAMES, false)) + { + npc.controllerMovement = {}; + isSpitting = true; + } + if (isSpitting) + { + npc.projectileCooldown = MOBILE_HOST_COOLDOWN; + npc.stateFrame = 0; + npc.state = NPC_STATE_ATTACK; + } + + if (npc.state != NPC_STATE_ATTACK && npc.GetIntervalTicks(MOBILE_HOST_CALM_FRAMES, 0) && npc.stateFrame > 0) + npc.stateFrame--; + npc.friction *= MOBILE_HOST_MOVE_FRICTION; +} + +// Its spit: three shots (five from the Flesh one) at its target, and a puff of blood where its skull opens. +static void mobile_host_spit(Entity_NPC& npc) +{ + AnimationState& overlay = npc.sprite.overlayAnimState; + if (overlay.IsEventTriggered("Shoot")) + { + Vector aim = npc.controllerID == -1 ? vector_sub(npc.GetPlayerTarget()->pos, npc.pos) : npc.controllerMovement; + if (!vector_is_zero(aim)) + { + npc.PlaySound(SOUND_BLOODSHOOT, 1, 2, false, 1); + ProjectilesMode mode = npc.type == ENTITY_MOBILE_HOST ? PROJECTILES_THREE : PROJECTILES_FIVE; + npc.FireProjectiles(npc.pos, vector_resized(aim, MOBILE_HOST_SHOT_SPEED), mode, ProjectileParams()); + } + } + if (!overlay.IsEventTriggered("Poof") || (npc.controllerID != -1 && vector_is_zero(npc.controllerMovement))) return; + + const NullFrame* poof = overlay.GetNullFrame("PoofPos"); + Vector spot = poof ? poof->pos : Vector{}; + Vector at = vector_add(vector_scale(spot, 1 / MOBILE_HOST_POOF_SCALE), npc.pos); + Entity* blood = blood_explosion_spawn(1, at, vector_make(0, MOBILE_HOST_POOF_RAISE), COLOR_DEFAULT, {}); + blood->sprite.scale = vector_make(MOBILE_HOST_POOF_SIZE, MOBILE_HOST_POOF_SIZE); + blood->renderDepthOffset = MOBILE_HOST_POOF_DEPTH; +} + +// Opening up: its skull opens (spitting, in ATTACK), then it shuts and walks again once the animation ends. +static void mobile_host_open(Entity_NPC& npc, bool isArmored) +{ + AnimationState& overlay = npc.sprite.overlayAnimState; + if (overlay.IsEventTriggered("Destructible")) npc.PlaySound(SOUND_ANIMAL_SQUISH, 1, 2, false, 1); + bool isAiming = npc.state == NPC_STATE_ATTACK && npc.controllerID != -1; + if (isAiming && !overlay.WasEventTriggered("Shoot")) + { + npc.controllerMovement = {}; + if (!npc.HasEntityFlags(FLAG_DISTRACTED)) + { + npc.SpawnControlTarget(0, -1); + npc.controllerMovement = vector_sub(npc.GetAimTargetPosition(), npc.pos); + } + } + npc.stateFrame++; + if (isArmored) npc.ClearEntityFlags(FLAG_NO_TARGET); + npc.sprite.PlayOverlay("Shoot"); + float facing = isAiming ? npc.controllerMovement.x : npc.GetPlayerTarget()->pos.x - npc.pos.x; + npc.sprite.isFlipX = facing < 0; + + if (npc.state == NPC_STATE_ATTACK) + { + if (npc.projectileCooldown > 0) npc.projectileCooldown -= npc_ticks_get(npc); + mobile_host_spit(npc); + } + if (overlay.animData && overlay.isPlaying) return; + if (npc.state == NPC_STATE_ATTACK) npc.v2.y = 0; + npc.state = NPC_STATE_MOVE; + npc.stateFrame = 0; + npc.sprite.PlayOverlay("Idle"); +} + +// 005321d0 NpcAI::ENTITY_MOBILE_HOST: the Mobile Host walks after its target with its skull shut (hits on it do +// nothing) and opens it to spit shots. The Flesh Mobile Host spits five and has no shell. +void npc_mobile_host_update(Entity_NPC& npc) +{ + bool isArmored = npc.type == ENTITY_MOBILE_HOST && npc.subtype != MOBILE_HOST_UNARMORED; + if (npc.state == NPC_STATE_INIT) + { + npc.state = NPC_STATE_MOVE; + npc.stateFrame = 0; + if (isArmored) npc.isInvincible = true; + return; + } + + npc.isInvincible = false; + if (!npc.sprite.overlayAnimState.animData) npc.sprite.PlayOverlay("Idle"); + npc.AnimWalkFrame("WalkHori", "WalkVert", MOBILE_HOST_WALK_SPEED); + if (isArmored && npc.pendingDamage > 0) mobile_host_shell_hit(npc); + if (npc.controllerID != -1) mobile_host_charge_update(npc, isArmored); + + if (npc.state == NPC_STATE_MOVE) return mobile_host_walk(npc, isArmored); + if (npc.state != NPC_STATE_ATTACK && npc.state != NPC_STATE_ATTACK2) return; + mobile_host_open(npc, isArmored); + npc.friction *= MOBILE_HOST_ATTACK_FRICTION; +} diff --git a/src/npc_moms_hand.cpp b/src/npc_moms_hand.cpp new file mode 100644 index 0000000..672be4d --- /dev/null +++ b/src/npc_moms_hand.cpp @@ -0,0 +1,182 @@ +#include "boss_ai.h" +#include "npc_depths.h" +#include "room_grid.h" +#include "room_transition.h" + +// Its fall: the frames it hovers (a random wait first) and the size its shadow grows to. +constexpr uint32_t HAND_WAIT_SPREAD = 150; +constexpr int HAND_FOLLOW_FRAMES = 78; +constexpr int HAND_DROP_FRAMES = 90; +constexpr float HAND_SHADOW_SIZE = 0.43333334f; +constexpr float HAND_FOLLOW_DROP = 1; +constexpr float HAND_CONTROL_SPEED = 1.6f; +constexpr float HAND_CONTROL_SLOW_SPEED = 0.1f; +constexpr int HAND_SHAKE = 10; +constexpr int HAND_LAUGH_DELAY = 10; +constexpr float HAND_FRICTION = 0.6f; + +// On the floor: how long it lies stunned, how its shadow fades as it rises, and how long effects on it hold. +constexpr int HAND_STUN_FRAMES = 51; +constexpr float HAND_SHADOW_FADE = 0.7f; +constexpr int HAND_STATUS_HOLD = 3; + +// Mom's Dead Hand: the cracks its landing sends out, and the spiders it leaves. +constexpr uint32_t HAND_CRACK_SPREAD = 1; +constexpr float HAND_CRACK_MIN = 3; +constexpr float HAND_CRACK_TURN = 360; +constexpr uint32_t HAND_SPIDER_SPREAD = 1; +constexpr int HAND_SPIDER_MIN = 2; +constexpr float HAND_SPIDER_REACH = 80; +constexpr float HAND_SPIDER_HEIGHT = -30; + +// While it falls, lies or rises, the charm, confusion, fear and shrink on it never run out. +static void moms_hand_status_hold(Entity_NPC& npc) +{ + EntityRef self(&npc); + if (npc.HasEntityFlags(FLAG_CHARM) && npc.charmedCountdown < HAND_STATUS_HOLD) npc.AddCharmed(self, 1, false, false); + if (npc.HasEntityFlags(FLAG_CONFUSION) && npc.confusionCountdown < HAND_STATUS_HOLD) npc.AddConfusion(self, 1, false); + if (npc.HasEntityFlags(FLAG_FEAR) && npc.fearCountdown < HAND_STATUS_HOLD) npc.AddFear(self, 1, false); + if (npc.HasEntityFlags(FLAG_SHRINK) && npc.shrinkCountdown < HAND_STATUS_HOLD) npc.AddShrink(self, 1, false); +} + +// Hovering, its shadow grows over its target (or drifts where its controller steers, faster while it shoots) until +// it drops. +static void moms_hand_hover(Entity_NPC& npc) +{ + npc.shadowSize = std::min((float)npc.stateFrame / HAND_DROP_FRAMES * HAND_SHADOW_SIZE, HAND_SHADOW_SIZE); + if (npc.controllerID != -1) + { + float speed = npc.stateFrame < HAND_DROP_FRAMES ? HAND_CONTROL_SPEED : HAND_CONTROL_SLOW_SPEED; + npc.pathfinder.FindGridPath({}, speed, 0, DIRECT_PATH_FAR); + if (npc.IsControllerActionPressed(CONTROLLER_ACTION_SHOOT)) npc.stateFrame += npc_ticks_get(npc) * 2; + } + else if (npc.stateFrame < HAND_FOLLOW_FRAMES && !npc.HasEntityFlags(FLAG_DISTRACTED)) + npc.pos = vector_add(npc.GetPlayerTarget()->pos, vector_make(0, HAND_FOLLOW_DROP)); + else if (npc.stateFrame < HAND_FOLLOW_FRAMES) + { + Vector away = vector_sub(npc.CalcTargetPosition(0), npc.pos); + if (vector_length_squared(away) > 0) npc.pos = vector_add(vector_normalized(away), npc.pos); + } + + if (npc.stateFrame <= HAND_DROP_FRAMES - 1) return; + npc_sound_play(SOUND_BIRD_FLAP, 1, 2, champion_pitch_get(npc)); + npc.state = NPC_STATE_STOMP; + npc.stateFrame = 0; + npc_anim_restart(npc.sprite, "JumpDown"); +} + +// Landing: it can be hit once down (the Dead Hand sends out three or four cracks), then lies stunned. +static void moms_hand_land(Entity_NPC& npc) +{ + AnimationState& anim = npc.sprite.animState; + if (anim.animData) + { + if (anim.IsEventTriggered("Land")) + { + npc.PlaySound(SOUND_FORESTBOSS_STOMPS, 1, 2, false, 1); + if (npc.type == ENTITY_MOMS_DEAD_HAND) + { + float step = HAND_CRACK_TURN / ((float)(Random() & HAND_CRACK_SPREAD) + HAND_CRACK_MIN); + for (float angle = 0; angle < HAND_CRACK_TURN; angle += step) + { + auto* crack = static_cast(g_game->Spawn({.position = npc.pos, .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = EFFECT_CRACKWAVE, + .seed = Random()})); + crack->parent = &npc; + crack->rotation = angle; + } + } + } + if (anim.animData && anim.WasEventTriggered("Land")) npc.entityCollisionClass = ENTCOLL_ALL; + if (!npc_anim_is_done(npc)) return; + } + npc.state = NPC_STATE_IDLE; + npc.stateFrame = 0; + npc_anim_loop(npc.sprite, "Stunned"); +} + +// Rising back to hover: it slips out of reach on the Jump event. +static void moms_hand_rise(Entity_NPC& npc) +{ + AnimationState& anim = npc.sprite.animState; + if (anim.animData && anim.WasEventTriggered("Jump")) + { + npc.entityCollisionClass = ENTCOLL_NONE; + npc.shadowSize *= HAND_SHADOW_FADE; + } + if (!npc_anim_is_done(npc)) return; + npc.state = NPC_STATE_MOVE; + npc.stateFrame = 0; + npc.sprite.SetFrame("JumpDown", 0); +} + +// Carrying off what it grabbed: untouchable while it lifts, then, a player in hand, back to the floor's first room. +static void moms_hand_carry(Entity_NPC& npc) +{ + npc.AddEntityFlags(FLAG_NO_STATUS_EFFECTS); + npc.isInvincible = true; + npc.health = npc.maxHitPoints; + npc_anim_loop(npc.sprite, "Grab"); + if (!npc_anim_is_done(npc)) return; + + npc.ClearEntityFlags(FLAG_NO_STATUS_EFFECTS); + npc.isInvincible = false; + if (npc.i1 == ENTITY_PLAYER && npc.i2 == 0) + reconstruction_missing("NpcAI::ENTITY_MOMS_HAND 00533b80: releasing grabbed players (Entity_Player 0x189c)"); + npc.entityCollisionClass = ENTCOLL_NONE; + npc.shadowSize *= HAND_SHADOW_FADE; + npc.state = NPC_STATE_MOVE; + npc.stateFrame = 0; + npc.sprite.SetFrame("JumpDown", 0); +} + +// 00533b80 NpcAI::ENTITY_MOMS_HAND: Mom's Hand and Mom's Dead Hand hover over their target, slam down, lie stunned +// and rise again. A hand that grabs carries it off. The Dead Hand cracks the floor and leaves spiders. +void npc_moms_hand_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.state = NPC_STATE_MOVE; + npc.entityGridCollisionClass = GRIDCOLL_NONE; + npc.entityCollisionClass = ENTCOLL_NONE; + npc.stateFrame = -(int)(Random() % HAND_WAIT_SPREAD); + if (npc.sprite.SetAnimation("JumpDown", SWITCH_KEEP_FRAME) && npc.sprite.animState.animData) + { + npc.sprite.animState.SetFrameFloat(0); + npc.sprite.animState.isPlaying = false; + } + npc.ClearEntityFlags(FLAG_APPEAR); + npc.shadowSize = 0; + npc_sound_play(SOUND_MOM_VOX_EVILLAUGH, 1, HAND_LAUGH_DELAY, champion_pitch_get(npc)); + game_shake_screen(HAND_SHAKE); + return; + } + + if (npc.pendingDamage > 0) + for (DamageEvent& event : npc.damageEvents) + if ((event.damageFlags & DAMAGE_EXPLOSION) && event.source.type == ENTITY_MOMS_DEAD_HAND) event.damage = 0; + npc.stateFrame += npc_ticks_get(npc); + npc.friction *= HAND_FRICTION; + if (npc.state == NPC_STATE_JUMP || npc.state == NPC_STATE_MOVE || npc.state == NPC_STATE_STOMP) + moms_hand_status_hold(npc); + + if (npc.state == NPC_STATE_MOVE) moms_hand_hover(npc); + else if (npc.state == NPC_STATE_STOMP) moms_hand_land(npc); + else if (npc.state == NPC_STATE_IDLE && npc.stateFrame >= HAND_STUN_FRAMES) + { + npc.state = NPC_STATE_JUMP; + npc.stateFrame = 0; + npc_anim_loop(npc.sprite, "JumpUp"); + } + else if (npc.state == NPC_STATE_JUMP) moms_hand_rise(npc); + else if (npc.state == NPC_STATE_SPECIAL) moms_hand_carry(npc); + + if (!npc.isDead || npc.type != ENTITY_MOMS_DEAD_HAND) return; + int spiders = (int)(Random() & HAND_SPIDER_SPREAD) + HAND_SPIDER_MIN; + for (int i = 0; i < spiders; i++) + { + Vector spot = room_free_pickup_position_find({.position = npc.pos, .step = random_unit() * HAND_SPIDER_REACH}); + Entity_NPC::ThrowSpider(npc.pos, &npc, spot, false, HAND_SPIDER_HEIGHT); + } +} diff --git a/src/npc_mr_maw.cpp b/src/npc_mr_maw.cpp new file mode 100644 index 0000000..ccf79cb --- /dev/null +++ b/src/npc_mr_maw.cpp @@ -0,0 +1,274 @@ +#include "boss_ai.h" +#include "npc_depths.h" +#include + +// Mr. Maw's parts by variant: the body, its head, the red body and head, and the neck's segments. +constexpr int MR_MAW_BODY = 0; +constexpr int MR_MAW_HEAD = 1; +constexpr int MR_MAW_RED_BODY = 2; +constexpr int MR_MAW_RED_HEAD = 3; +constexpr int MR_MAW_NECK = 10; +constexpr int MR_MAW_NECK_SEGMENTS = 8; + +// The head's lunge: how often it may, its reach, speed and pull back, and the cooldown it shares with the body. +constexpr float MR_MAW_HEAD_DEPTH = 10; +constexpr int MR_MAW_NECK_DEPTH = 2000; +constexpr uint32_t MR_MAW_DETACH_ODDS = 1000; +constexpr uint32_t MR_MAW_DRIP_ODDS = 10; +constexpr float MR_MAW_DRIP_SIZE = 0.5f; +constexpr float MR_MAW_DRIP_MIN = 0.2f; +constexpr int MR_MAW_COOLDOWN_MIN = -30; +constexpr int MR_MAW_LUNGE_COOLDOWN = 30; +constexpr int MR_MAW_LUNGE_FRAMES = 4; +constexpr float MR_MAW_LUNGE_LEAD = 3; +constexpr float MR_MAW_LUNGE_REACH_SQUARED = 16900; +constexpr float MR_MAW_LUNGE_SPEED = 14; +constexpr float MR_MAW_RETURN_NEAR = 5; +constexpr int MR_MAW_RETURN_COOLDOWN = 15; +constexpr float MR_MAW_RETURN_SPAN = 45; +constexpr float MR_MAW_RETURN_FAST = 1.4f; +constexpr float MR_MAW_RETURN_SLOWDOWN = 0.7f; +constexpr float MR_MAW_RETURN_FRICTION = 0.0028f; +constexpr float MR_MAW_RETURN_FRICTION_MIN = 0.9f; +constexpr float MR_MAW_RING_SPEED = 8; + +// The body's walk, and the tints of the Gusher a headless body becomes. +constexpr float MR_MAW_WALK_SPEED = 0.1f; +constexpr float MR_MAW_PATH_SPEED = 0.6f; +constexpr float MR_MAW_RED_PATH_SPEED = 0.8f; +constexpr float MR_MAW_LUNGE_PATH_SPEED = 0.3f; +constexpr float MR_MAW_RED_LUNGE_PATH_SPEED = 0.4f; +constexpr int MR_MAW_PATH_MARKER = 900; +constexpr float MR_MAW_EVADE_FRICTION = 0.8f; +constexpr float MR_MAW_LUNGE_FRICTION = 0.7f; +constexpr uint32_t MR_MAW_GROAN_ODDS = 3; +constexpr int MR_MAW_GROAN_DELAY = 40; +constexpr float RED_BODY_TINT_RED = 1.0784315f; +constexpr float RED_BODY_TINT = 0.882353f; +constexpr float BODY_TINT = 1.3882353f; + +// The neck's sag and reach between body and head. +constexpr float NECK_SEGMENT_SHARE = 0.125f; +constexpr float NECK_SEGMENT_LAST = 7; +constexpr float NECK_SAG_MIDDLE = 4; +constexpr float NECK_SAG_SPAN = 16; +constexpr float NECK_SAG_REACH = 100; +constexpr float NECK_RISE = 31; +constexpr float NECK_DROP = 5; + +// A headless body carries on as a Gusher, lightened (reddened under the red head). +static void mr_maw_gusher_morph(Entity_NPC& body, int variant) +{ + body.Morph(ENTITY_GUSHER, 0, 0, body.championColorIdx); + body.health = body.maxHitPoints; + ColorMod& tint = body.sprite.GetLayer(0)->color; + tint._tint[3] = 1; + if (variant == MR_MAW_RED_HEAD) + { + tint._tint[0] = RED_BODY_TINT_RED; + tint._tint[1] = RED_BODY_TINT; + tint._tint[2] = RED_BODY_TINT; + return; + } + tint._tint[0] = BODY_TINT; + tint._tint[1] = BODY_TINT; + tint._tint[2] = BODY_TINT; +} + +// A bodiless head carries on as a Maw (a Red Maw from the red one). +static void mr_maw_maw_morph(Entity_NPC& head, bool isRed) +{ + head.Morph(ENTITY_MAW, isRed, 0, head.championColorIdx); + head.entityCollisionClass = ENTCOLL_ALL; + head.health = head.maxHitPoints; +} + +// The body sets out its head (with it as the head's child) and the eight segments of its neck. +static void mr_maw_init(Entity_NPC& body) +{ + auto* head = static_cast(g_game->Spawn( + {.position = body.pos, .spawner = &body, .type = ENTITY_MRMAW, .variant = body.variant + 1, .seed = Random()})); + head->child = &body; + head->entityCollisionClass = ENTCOLL_PLAYEROBJECTS; + head->entityGridCollisionClass = GRIDCOLL_WALLS; + body.parent = head; + head->renderDepthOffset = MR_MAW_HEAD_DEPTH; + head->Update(); + + for (int i = 0; i < MR_MAW_NECK_SEGMENTS; i++) + { + auto* segment = static_cast(g_game->Spawn( + {.position = body.pos, .spawner = &body, .type = ENTITY_MRMAW, .variant = MR_MAW_NECK, .seed = Random()})); + segment->parent = &body; + segment->entityCollisionClass = ENTCOLL_NONE; + segment->shadowSize = 0; + segment->renderZOffset = MR_MAW_NECK_DEPTH; + segment->ClearEntityFlags(FLAG_APPEAR); + segment->AddEntityFlags(FLAG_NO_DEATH_TRIGGER); + segment->isVisible = false; + segment->v1.x = (float)i; + } +} + +// The head flies back to its body after a lunge, faster as the cooldown runs out, and rests on it once close. +static void mr_maw_head_return(Entity_NPC& head, Entity_NPC& body) +{ + Vector away = vector_sub(body.pos, head.pos); + float distance = vector_length(away); + if (distance < MR_MAW_RETURN_NEAR && body.projectileCooldown < MR_MAW_RETURN_COOLDOWN) + { + body.state = NPC_STATE_MOVE; + return; + } + if (distance <= 0) return; + + float share = std::clamp((body.projectileCooldown - MR_MAW_COOLDOWN_MIN) / MR_MAW_RETURN_SPAN, 0.0f, 1.0f); + npc_push(head, vector_scale(away, (MR_MAW_RETURN_FAST - share * MR_MAW_RETURN_SLOWDOWN) / distance)); + head.friction *= body.projectileCooldown * MR_MAW_RETURN_FRICTION + MR_MAW_RETURN_FRICTION_MIN; +} + +// The head lunges at where its target is heading (near and in sight), or where the body's controller points. +static void mr_maw_head_lunge(Entity_NPC& head, Entity_NPC& body) +{ + if (head.HasEntityFlags(FLAG_DISTRACTED)) return; + if (body.controllerID == -1) + { + if (!head.IsFrame(MR_MAW_LUNGE_FRAMES, 0)) return; + Entity* target = head.GetPlayerTarget(); + Vector aim = vector_sub(vector_add(target->pos, vector_scale(target->velocity, MR_MAW_LUNGE_LEAD)), head.pos); + float distanceSquared = vector_length_squared(aim); + if (distanceSquared >= MR_MAW_LUNGE_REACH_SQUARED || vector_is_zero(aim)) return; + if (!room_check_line(head.pos, head.GetPlayerTarget()->pos, LINE_MODE_EXPLOSION, 0)) return; + head.PlaySound(SOUND_MEATHEADSHOOT, 1, 2, false, 1); + head.velocity = vector_scale(aim, MR_MAW_LUNGE_SPEED / std::sqrt(distanceSquared) / head.friction); + } + else + { + body.UpdateControllerMovement(true); + if (vector_is_zero(body.controllerMovement)) return; + head.PlaySound(SOUND_MEATHEADSHOOT, 1, 2, false, 1); + head.velocity = vector_scale(vector_resized(body.controllerMovement, MR_MAW_LUNGE_SPEED), 1 / head.friction); + } + body.projectileCooldown = MR_MAW_LUNGE_COOLDOWN; + body.state = NPC_STATE_ATTACK; +} + +// The head rides its body and lunges. Bodiless or dead, or one time in a thousand, they part: the body as a Gusher, +// the head as a Maw (the red head's death fires a cross of shots). +static void mr_maw_head_update(Entity_NPC& head) +{ + if (Random() % MR_MAW_DRIP_ODDS == 0) head.MakeSplat(random_unit() * MR_MAW_DRIP_SIZE + MR_MAW_DRIP_MIN); + + Entity_NPC* body = head.ChildNPC(); + bool isKept = !head.isDead && (Random() % MR_MAW_DETACH_ODDS != 0 || (body && body->controllerID != -1)); + if (isKept && body) + { + body->projectileCooldown = std::max(body->projectileCooldown - npc_ticks_get(head), MR_MAW_COOLDOWN_MIN); + if (body->state == NPC_STATE_MOVE) mr_maw_head_lunge(head, *body); + else if (body->state == NPC_STATE_ATTACK) mr_maw_head_return(head, *body); + return; + } + if (!isKept && body) + { + mr_maw_gusher_morph(*body, head.variant); + body->entityCollisionClass = ENTCOLL_ALL; + } + if (head.isDead && head.variant == MR_MAW_RED_HEAD) + { + head.FireProjectiles(head.pos, vector_make(MR_MAW_RING_SPEED, 0), PROJECTILES_PLUS, ProjectileParams()); + head.PlaySound(SOUND_SHAKEY_KID_ROAR, 1, 2, false, 1); + } + head.ClearEntityFlags(FLAG_NO_DEATH_TRIGGER); + mr_maw_maw_morph(head, head.variant != MR_MAW_HEAD); +} + +// A neck segment hangs between body and head while the head lunges, sagging in the middle, and is gone with them. +static void mr_maw_neck_update(Entity_NPC& segment) +{ + Entity* parent = segment.parent.get(); + if (!parent || parent->type != ENTITY_MRMAW || !parent->parent) + { + segment.Remove(); + return; + } + Entity_NPC* body = segment.ParentNPC(); + if (body->state != NPC_STATE_ATTACK) + { + segment.isVisible = false; + return; + } + if (!body->parent) return; + + segment.isVisible = true; + Vector neck = vector_sub(body->pos, body->ParentNPC()->pos); + float share = (NECK_SEGMENT_LAST - segment.v1.x) * NECK_SEGMENT_SHARE; + float middle = std::abs(segment.v1.x - NECK_SAG_MIDDLE); + float sag = std::max(NECK_SAG_REACH - vector_length(neck), 0.0f) * (NECK_SAG_SPAN - middle * middle) / NECK_SAG_REACH; + segment.pos.x = body->pos.x - share * neck.x; + segment.pos.y = sag + (body->pos.y - share * neck.y - NECK_RISE) + segment.v1.x + NECK_DROP; +} + +// The body walks after its target (fleeing while scared), groaning, and drags its head along. While the head lunges +// it stops (a controlled one slows). +static void mr_maw_body_update(Entity_NPC& body) +{ + bool isRed = body.variant == MR_MAW_RED_BODY; + if (body.state != NPC_STATE_MOVE) + { + body.friction *= MR_MAW_LUNGE_FRICTION; + if (body.controllerID == -1) + { + if (body.sprite.animState.animData) body.sprite.SetFrame(body.sprite.GetAnimation(), 0); + } + else + { + body.AnimWalkFrame("MrMawBodyHori", "MrMawBodyVert", MR_MAW_WALK_SPEED); + float speed = isRed ? MR_MAW_RED_LUNGE_PATH_SPEED : MR_MAW_LUNGE_PATH_SPEED; + body.pathfinder.FindGridPath(body.CalcTargetPosition(0), speed, MR_MAW_PATH_MARKER, DIRECT_PATH_FAR); + } + return; + } + + body.AnimWalkFrame("MrMawBodyHori", "MrMawBodyVert", MR_MAW_WALK_SPEED); + if (!body.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK) || body.controllerID != -1) + { + float speed = isRed ? MR_MAW_RED_PATH_SPEED : MR_MAW_PATH_SPEED; + body.pathfinder.FindGridPath(body.CalcTargetPosition(0), speed, MR_MAW_PATH_MARKER, DIRECT_PATH_FAR); + } + else + { + body.pathfinder.EvadeTarget(body.GetPlayerTarget()->pos, STATUS_OBEYED); + body.friction *= MR_MAW_EVADE_FRICTION; + } + + bool isGroaning = body.controllerID == -1 + ? body.IsHostileTo(body.GetPlayerTarget()) && body.pathfinder.hasDirectPath && + body.variant == MR_MAW_BODY && Random() % MR_MAW_GROAN_ODDS == 0 + : body.IsControllerActionTriggered(CONTROLLER_ACTION_GROAN); + if (isGroaning) body.PlaySound(SOUND_ZOMBIE_WALKER_KID, 1, MR_MAW_GROAN_DELAY, false, 1); + + if (!body.parent) return; + Entity_NPC* head = body.ParentNPC(); + head->velocity = vector_sub(vector_add(body.velocity, body.pos), head->pos); + head->sprite.isFlipX = body.sprite.isFlipX; +} + +// 00517de0 NpcAI::ENTITY_MRMAW: Mr. Maw, a walking body whose head lunges at its target on a sagging neck and flies +// back. Parted, the body goes on as a Gusher and the head as a Maw. +void npc_mr_maw_update(Entity_NPC& npc) +{ + bool isBody = npc.variant == MR_MAW_BODY || npc.variant == MR_MAW_RED_BODY; + if (npc.state == NPC_STATE_INIT) + { + if (isBody) mr_maw_init(npc); + npc.state = NPC_STATE_MOVE; + return; + } + if (npc.variant == MR_MAW_HEAD || npc.variant == MR_MAW_RED_HEAD) return mr_maw_head_update(npc); + if (npc.variant == MR_MAW_NECK) return mr_maw_neck_update(npc); + if (!isBody) return; + + mr_maw_body_update(npc); + if (!npc.isDead && !npc.parent) mr_maw_gusher_morph(npc, npc.variant); + else if (npc.isDead && npc.parent) mr_maw_maw_morph(*npc.ParentNPC(), npc.variant != MR_MAW_BODY); +} diff --git a/src/npc_mulligan.cpp b/src/npc_mulligan.cpp index 6cb9278..86ec59a 100644 --- a/src/npc_mulligan.cpp +++ b/src/npc_mulligan.cpp @@ -8,8 +8,6 @@ constexpr int MULLIGOON = 1; constexpr int MULLIBOOM = 2; -constexpr int EFFECT_BOMB_CRATER = 18; -constexpr int SOUND_SCARED_WHIMPER = 143; constexpr int CONTROLLER_ACTION_ITEM = 9; constexpr int CONTROLLER_ACTION_WHIMPER = 10; diff --git a/src/npc_poky.cpp b/src/npc_poky.cpp new file mode 100644 index 0000000..18fab60 --- /dev/null +++ b/src/npc_poky.cpp @@ -0,0 +1,167 @@ +#include "boss_ai.h" +#include "entity_player.h" +#include "game.h" +#include "npc_depths.h" +#include "room.h" +#include "room_descriptor.h" + +// The Poky, and the Slide, which keeps to its spot and dashes faster. +constexpr int POKY = 0; +constexpr int POKY_SLIDE = 1; + +// Its dash: the lane it must be in, how far it sees, how fast the Slide goes and how hard it snaps to the lane. +constexpr float POKY_LANE_WIDTH = 20; +constexpr float POKY_SIGHT = 200; +constexpr float POKY_LEAD = 16; +constexpr float POKY_ROOM_MARGIN = 20; +constexpr float SLIDE_DASH_SPEED = 2.7225f; +constexpr float POKY_DASH_FRICTION = 0.8f; +constexpr float POKY_LANE_SNAP = 0.5f; + +// Its rest: the Slide's pull home, the speed it counts as settled at, and the frames before it may first dash. +constexpr float SLIDE_HOME_PULL = 10; +constexpr float SLIDE_HOME_SPEED = 1.8f; +constexpr float SLIDE_SETTLED_SPEED = 0.4f; +constexpr float POKY_MIN_DISTANCE = 0.001f; +constexpr float POKY_WANDER_SPEED = 1; +constexpr float POKY_MOVE_FRICTION = 0.8f; +constexpr float POKY_IDLE_FRICTION = 0.9f; +constexpr int POKY_SIGHT_FRAMES = 3; +constexpr float POKY_WARMUP_FRAMES = 30; +constexpr float POKY_CONTROL_DEADZONE = 0.1f; + +// Its retreat: the frames the room must be cleared for, and the trinket that blunts them. +constexpr int POKY_CLEAR_FRAMES = 80; +constexpr int POKY_SPLAT_SUBTYPE = 2; +constexpr ColorMod POKY_SPLAT_COLOR = {{1, 1, 1, 1}, {1, 1, 1, 1}, {0, 0, 0}}; + +// Picks the dash along the axis its target lines up with: on its lane, near and in sight. Whether it found one. +static bool poky_dash_pick(Entity_NPC& npc) +{ + Room& room = *g_game->room; + Entity* target = npc.GetPlayerTarget(); + Vector lead = vector_add(target->pos, vector_scale(npc.GetPlayerTarget()->velocity, random_unit() * POKY_LEAD)); + lead = room.GetClampedPositionImpl(lead, POKY_ROOM_MARGIN, POKY_ROOM_MARGIN, POKY_ROOM_MARGIN, POKY_ROOM_MARGIN); + Vector cell = room.GetGridPosition(npc.pathfinder.gridIndex); + Vector away = vector_sub(cell, lead); + + bool isOnLane = std::abs(away.x) < POKY_LANE_WIDTH || std::abs(away.y) < POKY_LANE_WIDTH; + if (!isOnLane || vector_length(away) >= POKY_SIGHT || !room_check_line(cell, lead, LINE_MODE_GROUND, 0)) + return false; + if (std::abs(away.x) <= std::abs(away.y)) npc.targetPosition = vector_make(0, away.y < 0 ? 1 : -1); + else npc.targetPosition = vector_make(away.x < 0 ? 1 : -1, 0); + return true; +} + +// At rest it wanders its rows (the Slide drifts home), then dashes at a target that lines up with it, or where its +// controller points. +static void poky_rest(Entity_NPC& npc) +{ + bool isSettled = true; + if (npc.variant == POKY) npc.pathfinder.MoveRandomlyAxisAligned(POKY_WANDER_SPEED, STATUS_OBEYED); + else + { + Vector away = vector_sub(npc.pos, npc.v1); + float distance = vector_length(away); + if (distance == 0) distance = POKY_MIN_DISTANCE; + float speed = std::min(distance / SLIDE_HOME_PULL, SLIDE_HOME_SPEED); + isSettled = speed < SLIDE_SETTLED_SPEED; + npc_push(npc, vector_scale(away, -speed / distance)); + } + npc.friction *= POKY_MOVE_FRICTION; + + bool isControlled = npc.controllerID != -1; + if ((!isControlled && !npc.IsFrame(POKY_SIGHT_FRAMES, npc.index)) || !isSettled || + npc.updateTime <= POKY_WARMUP_FRAMES || npc.HasEntityFlags(FLAG_DISTRACTED)) + return; + + if (!isControlled) + { + if (!poky_dash_pick(npc)) return; + } + else + { + if (npc.variant != POKY_SLIDE) return; + Vector input = npc.GetControllerInput(POKY_CONTROL_DEADZONE); + if (vector_is_zero(input)) return; + npc.targetPosition = vector_cardinal(input); + } + npc.state = NPC_STATE_ATTACK; + if (npc.variant == POKY_SLIDE) npc.targetPosition = vector_scale(npc.targetPosition, SLIDE_DASH_SPEED); +} + +// The dash: it speeds along its axis held to its lane's middle, until it hits a wall or anything. +static void poky_dash(Entity_NPC& npc) +{ + if (npc.isCollidesWithGrid || npc.isCollidesWithEntity) + { + npc.pathfinder.movementTarget = {}; + npc.pathfinder.moveDirection = {}; + npc.state = NPC_STATE_MOVE; + npc.targetPosition = {}; + return; + } + + npc.friction *= POKY_DASH_FRICTION; + npc_push(npc, npc.targetPosition); + Vector cell = g_game->room->GetGridPosition(npc.pathfinder.gridIndex); + float snap = npc_friction_scaled(POKY_LANE_SNAP, npc.speedMultiplier); + if (std::abs(npc.targetPosition.x) <= std::abs(npc.targetPosition.y)) + { + npc.pos.x = npc.pos.x * POKY_LANE_SNAP + cell.x * POKY_LANE_SNAP; + npc.velocity.x *= snap; + } + else + { + npc.pos.y = npc.pos.y * POKY_LANE_SNAP + cell.y * POKY_LANE_SNAP; + npc.velocity.y *= snap; + } +} + +// Whether its spikes go down for good: the room's enemies are gone (plates done), its plates are pressed, or a player +// carries the Flat File. +static bool poky_is_retracted(Entity_NPC& npc) +{ + Room& room = *g_game->room; + bool isRoomDone = npc.GetAliveEnemyCount() < 1 && room.GetFrameCount() > POKY_CLEAR_FRAMES && + npc.variant != POKY_SLIDE && !room.isTriggerPressurePlates; + return isRoomDone || (room.descriptor->flags & ROOM_DESCRIPTOR_FLAG_PRESSURE_PLATES_TRIGGERED) || + g_game->playerManager.AnyoneHasTrinket(TRINKET_FLAT_FILE); +} + +// 00521ab0 NpcAI::ENTITY_POKY: Poky and Slide, invincible spikes that wander their rows (Slide its spot) and dash +// along the axis their target lines up with, gone for good once the room is done. +void npc_poky_update(Entity_NPC& npc) +{ + Room& room = *g_game->room; + if (npc.state == NPC_STATE_INIT) + { + npc.AddEntityFlags(FLAG_HIDE_HP_BAR | FLAG_NO_STATUS_EFFECTS | FLAG_NO_BLOOD_SPLASH); + npc.ClearEntityFlags(FLAG_APPEAR); + npc.state = NPC_STATE_MOVE; + npc.isInvincible = true; + npc.v1 = room.GetGridPosition(room.GetGridIndex(npc.pos)); + if (room.GetFrameCount() == 0 && (room.descriptor->flags & ROOM_DESCRIPTOR_FLAG_PRESSURE_PLATES_TRIGGERED)) + npc.Remove(); + npc.splatColor = POKY_SPLAT_COLOR; + return; + } + + npc.pathfinder.UpdateGridIndex(); + if (npc.state == NPC_STATE_MOVE) poky_rest(npc); + else if (npc.state == NPC_STATE_ATTACK) poky_dash(npc); + else if (npc.state == NPC_STATE_SPECIAL) + { + npc.sprite.Play("No-Spikes"); + npc.collisionDamage = 0; + npc.friction *= POKY_IDLE_FRICTION; + } + + if (poky_is_retracted(npc)) npc.state = NPC_STATE_SPECIAL; + if (!npc.isDead) return; + if (npc.spawnGridIndex >= 0) + g_game->GetRoomByIdx(g_game->currentRoomIdx, -1)->restrictedGridIndexes.insert(npc.spawnGridIndex); + if (npc.variant == POKY) + g_game->Spawn({.position = npc.pos, .spawner = &npc, .subType = POKY_SPLAT_SUBTYPE, .type = ENTITY_EFFECT, + .variant = EFFECT_POOF01, .seed = Random()}); +} diff --git a/src/npc_rock_spider.cpp b/src/npc_rock_spider.cpp new file mode 100644 index 0000000..18fdf5c --- /dev/null +++ b/src/npc_rock_spider.cpp @@ -0,0 +1,346 @@ +#include "npc_alt.h" +#include "boss_ai.h" +#include "entity_pickup.h" +#include "entity_player.h" +#include "manager.h" +#include "npc_caves.h" +#include "npc_fireplace.h" +#include "room_grid.h" +#include +#include + +// The Rock Spider (a tinted or a coal one by variant), which the coal fire (a fireplace) shares: thrown as a rock, it +// falls bouncing a third back up and wakes now and then once it rests, then scuttles at its prey (a tinted or coal +// one faster), 5 times in 6 (3 in 4 for those) or wanders, turning up to 15 degrees aside, every 12 frames. +constexpr float ROCK_SPIDER_FRICTION = 0.6f; +constexpr float ROCK_SPIDER_REACH = 60; +constexpr float ROCK_SPIDER_STEP = 20; +constexpr int ROCK_SPIDER_TRIES = 10; +constexpr float ROCK_SPIDER_SWERVE = 30; +constexpr float ROCK_SPIDER_CONTROL_REACH = 100; +constexpr std::array ROCK_SPIDER_TURN_FRAMES = {12, 24, 36}; +constexpr int ROCK_SPIDER_CONTROL_FRAMES = 40; +constexpr int ROCK_SPIDER_WALK_FRAMES = 47; +constexpr float ROCK_SPIDER_SPEED = 3; +constexpr float ROCK_SPIDER_SPEED_TINTED = 5.1000004f; +constexpr float ROCK_SPIDER_SPEED_COAL = 1.8f; +constexpr float ROCK_SPIDER_SPEED_COAL_GIDEON = 1.6f; + +// The rock's flight: 100 heavy, falling 0.5 faster each frame, bouncing back 0.3 of its fall over 1, slowed to 0.8 on +// landing. Above 50 it passes over everything, landing (under 4) it walks the ground, and resting it wakes one time in +// 4 below a speed of 2. +constexpr float ROCK_MASS = 100; +constexpr float ROCK_GRAVITY = 0.5f; +constexpr float ROCK_BOUNCE = -0.3f; +constexpr float ROCK_BOUNCE_MIN = 1; +constexpr float ROCK_LANDING_FRICTION = 0.8f; +constexpr float ROCK_HIGH = -50; +constexpr float ROCK_LOW = -4; +constexpr float ROCK_REST_FALL = 0.6f; +constexpr float ROCK_WAKE_SPEED = 2; +constexpr float COAL_REST_FRICTION = 0.9f; + +// A coal fire burns down a point (two thirds of the time) every 30 frames, takes hits of 1 to 3, and goes out with a +// hiss at 1 or when the room is all but clear. Its look dims as it burns, its sparks fly one frame in 5. +constexpr int COAL_BURN_FRAMES = 30; +constexpr float COAL_BIG_HIT = 10; +constexpr float COAL_OUT_HEALTH = 1.5f; +constexpr float COAL_HISS_VOLUME = 0.85f; +constexpr int COAL_ROOM_CLEARING = 3; +constexpr float SPARK_RISE = -1.2800001f; +constexpr float SPARK_DRIFT = 0.4f; +constexpr float SPARK_SPREAD = 4; +constexpr float SPARK_CARRY = 0.2f; +constexpr uint32_t SPARK_ODDS = 5; + +// The splats of the rock and tinted spiders, and the coal fire a coal spider leaves dying. +constexpr ColorMod ROCK_SPIDER_SPLAT = {{0, 0, 0, 1}, {0, 0, 0, 0}, {30 / 255.0f, 22 / 255.0f, 18 / 255.0f}}; +constexpr ColorMod TINTED_SPIDER_SPLAT = {{0, 0, 0, 1}, {0, 0, 0, 0}, {30 / 255.0f, 38 / 255.0f, 60 / 255.0f}}; +constexpr float COAL_LEFT_HEIGHT = -1; +constexpr int SPIDER_SUBTYPES = 3; + +static bool is_quick_spider(Entity_NPC& npc) +{ + return npc.variant == SPIDER_THROW_TINTED || npc.variant == SPIDER_THROW_COAL; +} + +// Its look by its health: the second layer shrinking, the first reddening and darkening. +static void rock_spider_look(Entity_NPC& npc) +{ + float ratio = std::clamp(npc.health / npc.maxHitPoints, 0.f, 1.f); + + npc.sprite.GetLayer(1)->size = vector_make(ratio, ratio); + ColorMod& color = npc.sprite.GetLayer(0)->color; + color._tint[3] = 1; + color._tint[0] = ratio * 0.5f + 0.5f; + color._tint[1] = ratio * 0.8f + 0.2f; + color._tint[2] = ratio * 0.8f + 0.2f; +} + +// The rock coming in: its subtype rolled when unset, no appear poof once the room has run a frame, its splat. +static void rock_spider_init(Entity_NPC& npc) +{ + Room& room = *g_game->room; + + if (npc.subtype == 0) + { + npc.subtype = (int)(npc.initSeed % SPIDER_SUBTYPES) + 1; + npc.LoadEntityConfig(); + } + if (!room.isInitialized || g_game->frameCount - room.enterFrame < 2) npc.ClearEntityFlags(FLAG_APPEAR); + npc.state = NPC_STATE_SPECIAL; + npc.sprite.Play("IdleRock"); + if (npc.type == ENTITY_FIREPLACE || npc.variant == SPIDER_THROW_COAL) npc.splatColor = ROCK_SPLAT_COLOR; + else npc.splatColor = npc.variant == SPIDER_THROW_TINTED ? TINTED_SPIDER_SPLAT : ROCK_SPIDER_SPLAT; + npc.v1.x = 0; + if (npc.HasEntityFlags(FLAG_APPEAR)) + { + g_game->Spawn({.position = npc.pos, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); + npc.ClearEntityFlags(FLAG_APPEAR); + } + if (npc.type == ENTITY_FIREPLACE) rock_spider_look(npc); +} + +// Picks its way: its prey's (straight, or along the room's paths when it cannot see it), its controller's, or a +// random one it can take 20 of, then turns it up to 15 degrees aside. +static void rock_spider_turn(Entity_NPC& npc, bool isBurstingSack) +{ + Vector target = npc.CalcTargetPosition(ROCK_SPIDER_REACH); + bool isChasing = false; + + if (!isBurstingSack) isChasing = (is_quick_spider(npc) ? Random() & 3 : Random() % 6) != 0; + if (npc.controllerID != -1) + { + isChasing = true; + target = vector_add(vector_scale(npc.GetControllerInput(0), ROCK_SPIDER_CONTROL_REACH), npc.pos); + } + if (!npc.forcedTarget && !npc.HasEntityFlags(FLAG_CHARM) && !isChasing) + { + for (int tries = 0; tries < ROCK_SPIDER_TRIES; tries++) + { + npc.targetPosition = random_direction(); + Vector step = vector_add(vector_scale(npc.targetPosition, ROCK_SPIDER_STEP), npc.pos); + if (room_check_line(npc.pos, step, LINE_MODE_CELL, LINE_CHECK_THRESHOLD)) break; + } + return; + } + + Vector way = vector_sub(target, npc.pos); + if (npc.controllerID == -1 && !npc.forcedTarget && !room_check_line(npc.pos, target, LINE_MODE_CELL, LINE_CHECK_THRESHOLD)) + { + npc.pathfinder.Reset(); + npc.pathfinder.FindGridPath(target, 1, 0, DIRECT_PATH_FAR); + way = npc.velocity; + } + if (vector_length(way) > 0) way = vector_normalized(way); + + float swerve = (random_unit() - 0.5f) * ROCK_SPIDER_SWERVE * DEGREES_TO_RADIANS; + float cosine = std::cos(swerve); + float sine = std::sin(swerve); + npc.targetPosition = vector_make(way.x * cosine - way.y * sine, way.y * cosine + way.x * sine); +} + +// Scuttling: its way picked every 12 frames (each frame when controlled or forced), walking it, resting after 47. +static void rock_spider_walk(Entity_NPC& npc, bool isBurstingSack) +{ + npc.friction *= ROCK_SPIDER_FRICTION; + if (npc.controllerID != -1 && vector_is_zero(npc.GetControllerInput(0))) npc.stateFrame = 0; + for (int ticks = npc_ticks_get(npc); ticks > 0; ticks--) + { + npc.stateFrame += is_quick_spider(npc) ? 2 : 1; + bool isTurn = std::ranges::find(ROCK_SPIDER_TURN_FRAMES, npc.stateFrame) != ROCK_SPIDER_TURN_FRAMES.end(); + if (isTurn || npc.controllerID != -1 || npc.forcedTarget) rock_spider_turn(npc, isBurstingSack); + if ((Random() & 1) == 0 && (npc.stateFrame & 1)) npc.stateFrame++; + } + if (npc.controllerID != -1 && npc.stateFrame > ROCK_SPIDER_CONTROL_FRAMES) npc.targetPosition = Vector{}; + + if (vector_is_zero(npc.targetPosition)) npc.sprite.Play("Idle"); + else + { + npc.sprite.Play("Walk"); + float speed = ROCK_SPIDER_SPEED; + if (!isBurstingSack && npc.variant == SPIDER_THROW_TINTED) speed = ROCK_SPIDER_SPEED_TINTED; + else if (!isBurstingSack && npc.variant == SPIDER_THROW_COAL) + speed = (npc.spawnerType == ENTITY_GIDEON ? ROCK_SPIDER_SPEED_COAL_GIDEON : ROCK_SPIDER_SPEED_COAL) * speed; + npc.velocity = vector_add(npc.velocity, vector_scale(npc.targetPosition, speed * npc.speedMultiplier)); + npc.sprite.isFlipX = npc.velocity.x <= 0; + } + if (npc.stateFrame <= ROCK_SPIDER_WALK_FRAMES) return; + + npc.stateFrame = 0; + npc.targetPosition = Vector{}; +} + +// A coal fire burning: it cannot be hurt but by its own burning and hits it counts itself, going out at 1 or with the +// room. Whether its look changed. +static bool coal_burn(Entity_NPC& npc) +{ + bool isLookChanged = false; + + npc.AddEntityFlags(FLAG_NO_STATUS_EFFECTS | FLAG_NO_DAMAGE_BLINK); + npc.isInvincible = true; + if (npc.IsFrame(COAL_BURN_FRAMES, 0) && Random() % 3 != 0) npc.TakeDamage(1, 0, EntityRef(), COAL_BURN_FRAMES); + if (npc.pendingDamage > 0) + { + bool isOut = npc.pendingDamageFlags & (DAMAGE_EXPLOSION | DAMAGE_CRUSH); + if (isOut) npc.health = 1; + else + { + for (DamageEvent& event : npc.damageEvents) + { + if (event.damage > COAL_BIG_HIT) npc.health -= Random() % 3 == 0 ? 3 : 2; + else if (event.damage > 0) npc.health -= Random() % 3 == 0 ? 2 : 1; + } + npc.health = std::max(npc.health, 1.f); + isOut = npc.health < COAL_OUT_HEALTH; + } + if (isOut) + { + int hiss = SOUND_STEAM_HALFSEC; + seed_fart_sound_override(&hiss); + g_manager->sfxManager.Play(hiss, {.volume = COAL_HISS_VOLUME}); + npc.Kill(EntityRef()); + } + isLookChanged = true; + } + if (npc.GetAliveEnemyCount() < 1 && g_game->room->roomClearDelay < COAL_ROOM_CLEARING) npc.Kill(EntityRef()); + return isLookChanged; +} + +// A thrown rock: it falls and bounces, killed landing off the floor, solid near the ground, and once resting on it +// wakes (or a coal fire settles). +static void rock_fall(Entity_NPC& npc) +{ + npc.sprite.Play("IdleRock"); + npc.mass = ROCK_MASS; + + float fall = npc.v1.x; + npc.posOffset.y += fall * npc.speedMultiplier; + if (npc.posOffset.y > 0) + { + npc.posOffset.y = 0; + if (g_game->room->GetGridCollision(g_game->room->GetGridIndex(npc.pos)) != COLLISION_NONE) + return npc.Kill(EntityRef()); + npc.velocity = vector_scale(npc.velocity, ROCK_LANDING_FRICTION); + fall = std::abs(fall) <= ROCK_BOUNCE_MIN ? 0 : fall * ROCK_BOUNCE; + } + if (npc.posOffset.y >= ROCK_HIGH) + { + npc.entityCollisionClass = ENTCOLL_ALL; + npc.entityGridCollisionClass = npc.posOffset.y >= ROCK_LOW ? GRIDCOLL_GROUND : GRIDCOLL_WALLS; + } + else + { + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + npc.entityCollisionClass = ENTCOLL_NONE; + } + npc.v1.x = npc.speedMultiplier * ROCK_GRAVITY + fall; + + bool isLookChanged = npc.type == ENTITY_FIREPLACE && coal_burn(npc); + if (npc.entityGridCollisionClass == GRIDCOLL_GROUND && std::abs(npc.v1.x) < ROCK_REST_FALL) + { + if (npc.type == ENTITY_FIREPLACE) + { + npc.mass = npc.config->mass; + npc.friction *= COAL_REST_FRICTION; + } + else if (vector_length(npc.velocity) < ROCK_WAKE_SPEED && (Random() & 3) == 0) + { + npc.state = NPC_STATE_STOMP; + npc.mass = npc.config->mass; + } + } + if (isLookChanged) rock_spider_look(npc); +} + +// A coal spider's or coal fire's sparks, one frame in 5: an ember near it, rising, carried a little by its motion. +static void coal_sparks(Entity_NPC& npc) +{ + if ((npc.variant != SPIDER_THROW_COAL && npc.type != ENTITY_FIREPLACE) || Random() % SPARK_ODDS != 0) return; + + float rise = random_unit() * SPARK_RISE; + float drift = (random_unit() - 0.5f) * SPARK_DRIFT; + float angle = random_unit() * RANDOM_HALF_TURN; + angle += angle; + float reach = random_unit(); + Vector position = vector_make(std::cos(angle) * reach * SPARK_SPREAD + npc.pos.x, + std::sin(angle) * reach * SPARK_SPREAD + npc.pos.y); + uint32_t seed = Random(); + Vector velocity = vector_make(npc.velocity.x * SPARK_CARRY + drift, npc.velocity.y * SPARK_CARRY + rise); + g_game->Spawn({.position = position, .velocity = velocity, .type = ENTITY_EFFECT, .variant = EFFECT_EMBER_PARTICLE, + .seed = seed}); +} + +// What a dying spider leaves: on the floor a tinted one a soul heart, a coal one a coal fire, any other a spider (it +// becomes one). Over a pit or such only a tinted one's soul heart, at a free spot. +static void rock_spider_remains(Entity_NPC& npc) +{ + Room& room = *g_game->room; + Vector position = npc.pos; + Vector velocity = npc.velocity; + + if (room.GetGridCollision(room.GetGridIndex(npc.pos)) != COLLISION_NONE) + { + if (npc.variant != SPIDER_THROW_TINTED) return; + position = room_free_pickup_position_find({.position = npc.pos}); + velocity = Vector{}; + } + else if (npc.variant == SPIDER_THROW_COAL) + { + Entity* coal = g_game->Spawn({.position = npc.pos, .velocity = vector_scale(npc.velocity, 0.5f), .spawner = &npc, + .subType = npc.subtype, .type = ENTITY_FIREPLACE, .variant = FIRE_COAL, + .seed = npc.initSeed}); + coal->ClearEntityFlags(FLAG_APPEAR); + coal->Update(); + coal->posOffset.y = COAL_LEFT_HEIGHT; + static_cast(coal)->v1.x = COAL_LEFT_HEIGHT - random_unit(); + return; + } + else if (npc.variant != SPIDER_THROW_TINTED) + { + npc.PlayDeathEffects(); + npc.Morph(ENTITY_SPIDER, 0, 0, -1); + npc.state = NPC_STATE_INIT; + npc.health = npc.maxHitPoints; + npc.isDead = false; + npc.splatColor = COLOR_DEFAULT; + npc.posOffset = Vector{}; + npc.targetPosition = Vector{}; + npc.Update(); + return; + } + g_game->Spawn({.position = position, .velocity = velocity, .subType = HEART_SOUL, .type = ENTITY_PICKUP, + .variant = PICKUP_HEART, .seed = npc.initSeed}); +} + +// 004f9ad0 (NpcAI::ENTITY_ROCK_SPIDER) The rock spider and the coal fire: coming in as a thrown rock, falling and +// waking, appearing, scuttling, sparking when coal, leaving its remains on death, and a plain one catching fire (fire +// hurts none of them). +void npc_rock_spider_update(Entity_NPC& npc) +{ + bool isBurstingSack = g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_BURSTING_SACK, LAZARUS_SHARE_CHECK); + + switch (npc.state) + { + case NPC_STATE_INIT: rock_spider_init(npc); break; + case NPC_STATE_IDLE: rock_spider_walk(npc, isBurstingSack); break; + case NPC_STATE_STOMP: + npc.sprite.Play("Appear"); + npc.friction *= ROCK_SPIDER_FRICTION; + if (npc_anim_is_done(npc)) npc.state = NPC_STATE_IDLE; + break; + case NPC_STATE_SPECIAL: rock_fall(npc); break; + } + coal_sparks(npc); + if (npc.isDead && npc.type != ENTITY_FIREPLACE) rock_spider_remains(npc); + + for (DamageEvent& event : npc.damageEvents) + { + if (!(event.damageFlags & DAMAGE_FIRE)) continue; + + npc.pendingDamage -= event.damage; + event.damage = 0; + if (npc.type == ENTITY_ROCK_SPIDER && npc.variant == SPIDER_THROW_ROCK) + npc.Morph(ENTITY_ROCK_SPIDER, SPIDER_THROW_COAL, npc.subtype, -1); + } +} diff --git a/src/npc_strider.cpp b/src/npc_strider.cpp new file mode 100644 index 0000000..56f41cf --- /dev/null +++ b/src/npc_strider.cpp @@ -0,0 +1,187 @@ +#include "npc_alt.h" +#include "boss_ai.h" +#include "entity_familiar.h" +#include "npc_caves.h" +#include + +// The Strider skates over the water: idle, then every 4th frame on average it picks a way (toward its prey half the +// time when it sees it, else one time in 3 anywhere) and rows that way, turning a fifth of the way each frame, each +// stroke pushing it 6 to 9 (9 controlled). It hovers 8 above the floor, flying over pits. +constexpr float STRIDER_HOVER = -8; +constexpr float STRIDER_HEADING_START = 90; +constexpr float STRIDER_TURN = 0.2f; +constexpr float STRIDER_ROW_MIN = 6; +constexpr float STRIDER_ROW_RANGE = 3; +constexpr float STRIDER_ROW_CONTROLLED = 9; +constexpr float STRIDER_CONFUSED_ROW = 0.5f; +constexpr float STRIDER_FRICTION = 0.95f; +constexpr float STRIDER_CONTROL_DRIFT = 0.97f; +constexpr float STRIDER_DEADZONE = 0.1f; + +// Thrown, it flies at a 25th of the way a frame from 8 up, falling 0.7 faster each frame, and marks where it lands. +constexpr float STRIDER_THROW_PULL = 0.04f; +constexpr float STRIDER_THROW_LIFT = -8; +constexpr float STRIDER_GRAVITY = 0.7f; +constexpr int STRIDER_PATH_LANDING = 900; +constexpr int STRIDER_PATH_PIT_LANDING = 3900; +constexpr int STRIDER_PATH_PIT = 3000; + +constexpr std::array STRIDER_IDLE = {"IdleLeft", "IdleUp", "IdleRight", "IdleDown"}; +constexpr std::array STRIDER_WALK = {"WalkLeft", "WalkUp", "WalkRight", "WalkDown"}; + +// 0055c6a0 Which way its heading faces (left, up, right or down), and how far the sprite turns from that way. +static int strider_facing(Entity_NPC& npc, float& rotation) +{ + float heading = angle_wrap(npc.v1.x); + + for (int facing = 1; facing < 4; facing++) + { + float facingAngle = (float)(facing - 2) * 90; + if (heading >= facingAngle - 45 && heading < facingAngle + 45) + { + rotation = heading - facingAngle; + return facing; + } + } + rotation = angle_wrap(heading - 180); + return 0; +} + +// Picking a way to row: its controller's input, or every 4th frame on average its prey's way (when it sees it, one +// time in 2) or a random one (one time in 3, or always when confused). +static void strider_idle(Entity_NPC& npc) +{ + float rotation = 0; + npc.sprite.Play(STRIDER_IDLE[strider_facing(npc, rotation)]); + npc.sprite.rotation = rotation; + + if (npc.controllerID != -1) + { + if (vector_is_zero(npc.GetControllerInput(STRIDER_DEADZONE))) return; + npc.v2 = npc.GetControllerInput(STRIDER_DEADZONE); + } + else + { + if (Random() & 3) return; + + Entity* target = npc.GetPlayerTarget(); + if (!npc.HasEntityFlags(FLAG_CONFUSION)) + { + if ((Random() & 1) == 0 && room_check_line(npc.pos, target->pos, LINE_MODE_PROJECTILE, 0)) + { + npc.v2 = Vector{}; + npc.state = NPC_STATE_MOVE; + return; + } + if (Random() % 3 != 0) return; + } + npc.v2 = random_direction(); + } + npc.state = NPC_STATE_MOVE; +} + +// Rowing: it turns toward its way (its prey's, away when afraid) and each Row event pushes it along, until its stroke +// ends. +static void strider_row(Entity_NPC& npc) +{ + float rotation = 0; + const char* walk = STRIDER_WALK[strider_facing(npc, rotation)]; + const AnimationData* data = npc.sprite.animState.animData; + + if ((!data || !data->isLooping) && npc.sprite.GetAnimation() == walk) npc.sprite.SetAnimation(walk); + else npc.sprite.Play(walk); + npc.sprite.rotation = rotation; + + if (npc.controllerID != -1) + { + Vector input = npc.GetControllerInput(STRIDER_DEADZONE); + float drift = npc.speedMultiplier == 1 + ? STRIDER_CONTROL_DRIFT + : STRIDER_CONTROL_DRIFT / (npc.speedMultiplier + STRIDER_CONTROL_DRIFT - + npc.speedMultiplier * STRIDER_CONTROL_DRIFT); + npc.v2 = vector_is_zero(input) ? vector_scale(npc.v2, drift) : input; + } + + Vector way = npc.v2; + if (vector_is_zero(way)) + { + way = vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos)); + if (npc.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK)) way = vector_scale(way, -1); + } + if (npc.HasEntityFlags(FLAG_CONFUSION) && npc.controllerID == -1) way = vector_scale(way, STRIDER_CONFUSED_ROW); + + float turn = angle_wrap(std::atan2(way.y, way.x) * RADIANS_TO_DEGREES - npc.v1.x); + npc.v1.x = angle_wrap(turn * STRIDER_TURN + npc.v1.x); + if (npc.sprite.animState.animData && npc.sprite.IsEventTriggered("Row")) + { + float stroke = npc.controllerID == -1 ? random_unit() * STRIDER_ROW_RANGE + STRIDER_ROW_MIN : STRIDER_ROW_CONTROLLED; + npc.velocity = vector_add(npc.velocity, vector_scale(way, stroke * npc.speedMultiplier)); + } + if (!npc_anim_is_done(npc)) return; + npc.state = NPC_STATE_IDLE; +} + +// Flying where it was thrown, falling, until it lands back at its hovering height, solid again. +static void strider_thrown(Entity_NPC& npc) +{ + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + npc.entityCollisionClass = ENTCOLL_NONE; + npc.velocity = npc.v2; + npc.v1.x += npc.speedMultiplier * STRIDER_GRAVITY; + + float fall = npc.speedMultiplier * npc.v1.x; + npc.posOffset.y += fall; + if (npc.posOffset.y + fall <= STRIDER_HOVER) return npc.sprite.Play("IdleDown"); + + npc.v1.x = STRIDER_HEADING_START; + npc.posOffset.y = STRIDER_HOVER; + npc.targetPosition = Vector{}; + npc.entityGridCollisionClass = GRIDCOLL_NOPITS; + npc.entityCollisionClass = ENTCOLL_ALL; + npc.state = NPC_STATE_IDLE; +} + +// 0055c810 (NpcAI::ENTITY_STRIDER) The Strider: hovering, it idles, rows and lands from a throw, slowing every frame. +void npc_strider_update(Entity_NPC& npc) +{ + switch (npc.state) + { + case NPC_STATE_INIT: + npc.entityGridCollisionClass = GRIDCOLL_NOPITS; + npc.posOffset.y = STRIDER_HOVER; + npc.v1.x = STRIDER_HEADING_START; + npc.state = NPC_STATE_IDLE; + break; + case NPC_STATE_IDLE: strider_idle(npc); break; + case NPC_STATE_MOVE: strider_row(npc); break; + case NPC_STATE_JUMP: strider_thrown(npc); break; + } + npc.friction *= STRIDER_FRICTION; +} + +// 0055cef0 Throws a Strider at a spot from a spawner: it flies there from 8 up, its landing cell marked on the room's +// paths (a pit's cell as a pit's). +Entity_NPC* Entity_NPC::ThrowStrider(const Vector& pos, Entity* spawner, const Vector& targetPos) +{ + Room& room = *g_game->room; + auto* strider = static_cast( + g_game->Spawn({.position = pos, .spawner = spawner, .type = ENTITY_STRIDER, .seed = Random()})); + + strider->ClearEntityFlags(FLAG_APPEAR); + strider->targetPosition = targetPos; + int cell = room.GetGridIndex(targetPos); + if (cell >= 0 && cell < ROOM_GRID_CELLS) + { + int& path = room.gridPaths[cell]; + if (path <= STRIDER_PATH_LANDING) path = STRIDER_PATH_LANDING; + else if ((uint32_t)(path - STRIDER_PATH_PIT) <= STRIDER_PATH_LANDING) path = STRIDER_PATH_PIT_LANDING; + } + strider->posOffset.y = STRIDER_THROW_LIFT; + strider->v1.x = STRIDER_THROW_LIFT; + strider->state = NPC_STATE_JUMP; + strider->entityGridCollisionClass = GRIDCOLL_WALLS; + strider->entityCollisionClass = ENTCOLL_NONE; + strider->v2 = vector_scale(vector_sub(strider->targetPosition, strider->pos), STRIDER_THROW_PULL); + strider->velocity = strider->v2; + return strider; +} diff --git a/src/npc_wizoob.cpp b/src/npc_wizoob.cpp new file mode 100644 index 0000000..de62f19 --- /dev/null +++ b/src/npc_wizoob.cpp @@ -0,0 +1,199 @@ +#include "boss_ai.h" +#include "entity_laser.h" +#include "entity_familiar.h" +#include "npc_depths.h" +#include "room_grid.h" + +// The ghost's four facings (left, up, right, down) and their animations. +constexpr const char* WIZOOB_APPEAR[] = {"AppearLeft", "AppearUp", "AppearRight", "AppearDown"}; +constexpr const char* WIZOOB_SHOOT[] = {"ShootLeft", "ShootUp", "ShootRight", "ShootDown"}; +constexpr const char* WIZOOB_VANISH[] = {"VanishLeft", "VanishUp", "VanishRight", "VanishDown"}; +constexpr int WIZOOB_FACING_UP = 1; + +// Its fade, haunt and shots, and the Red Ghost's beam and its warning. +constexpr ColorMod WIZOOB_SPLAT_COLOR = {{0, 0, 0, 0.3f}, {0, 0, 0, 0}, {0.8f, 0.8f, 0.8f}}; +constexpr int WIZOOB_REST_FRAMES = 60; +constexpr uint32_t WIZOOB_HAUNT_ODDS = 30; +constexpr float WIZOOB_HAUNT_REACH = 120; +constexpr float WIZOOB_NULL_SCALE = 0.65f; +constexpr float WIZOOB_SHOT_VELOCITY = 1.5f; +constexpr float WIZOOB_SHOT_FALL = 10; +constexpr uint32_t WIZOOB_SHOTS_SPREAD = 3; +constexpr int WIZOOB_SHOTS_MIN = 6; +constexpr float WIZOOB_SHOT_ARC = 7; +constexpr float FACING_ANGLE_STEP = 90; +constexpr float FACING_ANGLE_START = -180; +constexpr int RED_GHOST_BEAM_FRAMES = 25; +constexpr float RED_GHOST_BEAM_BEHIND = -10; +constexpr float RED_GHOST_BEAM_FRONT = 3000; +constexpr ColorMod RED_GHOST_WARNING_COLOR = {{0.6f, 0.05f, 0, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr float RED_GHOST_WARNING_HEIGHT = -26; +constexpr int RED_GHOST_WARNING_FRAMES = 30; +constexpr float RED_GHOST_WARNING_SCALE = 4; + +// A controlled ghost's charge, its drift and its reach. +constexpr float WIZOOB_CHARGE_FRAMES = 150; +constexpr float WIZOOB_DRAIN_FRAMES = 90; +constexpr float WIZOOB_CONTROL_FRICTION = 0.95f; +constexpr float WIZOOB_CONTROL_SPEED = 1.4f; +constexpr float WIZOOB_CONTROL_RANGE = 1000; +constexpr int WIZOOB_RANGE_FRAMES = 7; +constexpr float WIZOOB_CONTROL_REACH = 160; +constexpr float WIZOOB_FRICTION = 0.1f; + +// The facing (left, up, right, down) of the axis an offset leans along most. +static int wizoob_facing_get(Vector offset) +{ + if (std::abs(offset.x) <= std::abs(offset.y)) return offset.y >= 0 ? 3 : 1; + return offset.x < 0 ? 0 : 2; +} + +// The angle of a facing, left at -180. +static float wizoob_facing_angle(int facing) +{ + return angle_wrap((float)facing * FACING_ANGLE_STEP + FACING_ANGLE_START); +} + +// Its attack on the Shoot event: a lobbed burst at the spot it marked, or the Red Ghost's beam the way it faces. +static void wizoob_shoot(Entity_NPC& npc) +{ + // The original reads the ShootPos null blindly. Without one this shoots from the ghost's center. + const NullFrame* shootPos = npc.sprite.GetNullFrame("ShootPos"); + Vector offset = shootPos ? vector_scale(shootPos->pos, 1 / WIZOOB_NULL_SCALE) : Vector{}; + if (npc.type == ENTITY_RED_GHOST) + { + Entity_Laser* beam = Entity_Laser::ShootAngle({.position = npc.pos, + .posOffset = offset, + .source = &npc, + .angleDegrees = wizoob_facing_angle(npc.i1), + .timeout = RED_GHOST_BEAM_FRAMES, + .variant = 1}); + beam->renderDepthOffset = npc.i1 == WIZOOB_FACING_UP ? RED_GHOST_BEAM_BEHIND : RED_GHOST_BEAM_FRONT; + beam->Update(); + return; + } + + npc.PlaySound(SOUND_WEIRD_WORM_SPIT, 1, 2, false, 1); + ProjectileParams params; + params.positionOffset = vector_make(offset.x, 0); + params.heightModifier = offset.y; + params.bulletFlags |= PROJECTILE_GHOST; + params.velocityMulti = WIZOOB_SHOT_VELOCITY; + params.fallingSpeedModifier += WIZOOB_SHOT_FALL; + int count = (int)(Random() & WIZOOB_SHOTS_SPREAD) + WIZOOB_SHOTS_MIN; + npc.FireBossProjectiles(count, npc.targetPosition, WIZOOB_SHOT_ARC, params); +} + +// Unseen, it waits out its rest, then haunts a free spot near its target (or where its controller sends it) facing +// it, the Red Ghost warning where its beam will go. +static void wizoob_hide(Entity_NPC& npc) +{ + npc.entityCollisionClass = ENTCOLL_NONE; + npc.isVisible = false; + if (npc.controllerID != -1) + { + npc.SpawnControlTarget(2, -1); + npc.friction *= WIZOOB_CONTROL_FRICTION; + npc.pathfinder.FindGridPath({}, WIZOOB_CONTROL_SPEED, 0, DIRECT_PATH_FAR); + if (npc.v2.x < 1 && !npc.IsTargetInAttackRange(WIZOOB_CONTROL_RANGE, WIZOOB_RANGE_FRAMES, false)) return; + + npc.state = NPC_STATE_MOVE; + Vector aim = vector_scale(npc.GetControllerMovementInput(0), WIZOOB_CONTROL_REACH); + if (vector_is_zero(aim)) aim = vector_scale(random_direction(), WIZOOB_CONTROL_REACH); + npc.targetPosition = vector_add(npc.pos, aim); + npc.i1 = wizoob_facing_get(aim); + return; + } + + if (npc.stateFrame >= 1) + { + npc.stateFrame -= npc_ticks_get(npc); + return; + } + if (Random() % WIZOOB_HAUNT_ODDS != 0) return; + npc.pos = room_free_pickup_position_find( + {.position = npc.GetPlayerTarget()->pos, .step = WIZOOB_HAUNT_REACH, .isAvoidActiveEntities = true}); + npc.state = NPC_STATE_MOVE; + npc.targetPosition = npc.GetPlayerTarget()->pos; + npc.i1 = wizoob_facing_get(vector_sub(npc.targetPosition, npc.pos)); + if (npc.type != ENTITY_RED_GHOST) return; + following_effect_spawn(npc, {.offset = vector_make(0, RED_GHOST_WARNING_HEIGHT), + .targetPosition = vector_from_angle(wizoob_facing_angle(npc.i1)), + .color = RED_GHOST_WARNING_COLOR, + .scale = RED_GHOST_WARNING_SCALE, + .timeout = RED_GHOST_WARNING_FRAMES}); +} + +// Seen: it fades in toward its facing, shoots, and fades out to rest. +static void wizoob_show(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_MOVE) + { + npc.isVisible = true; + npc_anim_loop(npc.sprite, WIZOOB_APPEAR[npc.i1]); + if (npc_anim_is_done(npc)) npc.state = NPC_STATE_ATTACK; + } + else if (npc.state == NPC_STATE_ATTACK) + { + npc.entityCollisionClass = ENTCOLL_PLAYEROBJECTS; + npc_anim_loop(npc.sprite, WIZOOB_SHOOT[npc.i1]); + if (npc.sprite.animState.animData) + { + if (npc.sprite.animState.IsEventTriggered("Shoot") && !npc.HasEntityFlags(FLAG_DISTRACTED)) + wizoob_shoot(npc); + if (!npc_anim_is_done(npc)) return; + } + npc.state = NPC_STATE_ATTACK2; + } + else if (npc.state == NPC_STATE_ATTACK2) + { + npc.sprite.Play(WIZOOB_VANISH[npc.i1]); + if (!npc_anim_is_done(npc)) return; + npc.state = NPC_STATE_IDLE; + npc.stateFrame = WIZOOB_REST_FRAMES; + npc.v2.x = 0; + } +} + +// Its first moments: it rises (AppearDown) and vanishes before it starts haunting. Whether it is now resting. +static bool wizoob_arrive(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_SUMMON) + { + if (!npc_anim_is_done(npc)) return false; + npc.state = NPC_STATE_SPECIAL; + } + npc_anim_loop(npc.sprite, "VanishDown"); + if (!npc_anim_is_done(npc)) return false; + npc.state = NPC_STATE_IDLE; + return true; +} + +// 005374a0 NpcAI::ENTITY_WIZOOB: the Wizoob and the Red Ghost haunt spots near their target, fade in to lob a burst +// of shots (the Red Ghost a beam), and fade away again. +void npc_wizoob_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.state = NPC_STATE_SUMMON; + npc_anim_restart(npc.sprite, "AppearDown"); + npc.ClearEntityFlags(FLAG_APPEAR); + npc.entityCollisionClass = ENTCOLL_NONE; + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + if (npc.type != ENTITY_RED_GHOST) npc.splatColor = WIZOOB_SPLAT_COLOR; + return; + } + + bool isResting = npc.state == NPC_STATE_IDLE; + if (npc.controllerID != -1) + { + npc.UpdateChargeBar(1, 0, npc.v2.x, true); + if (isResting) npc.v2.x = std::min(npc.speedMultiplier / WIZOOB_CHARGE_FRAMES + npc.v2.x, 1.0f); + else npc.v2.x = std::max(npc.v2.x - npc.speedMultiplier / WIZOOB_DRAIN_FRAMES, 0.0f); + } + if (npc.state == NPC_STATE_SUMMON || npc.state == NPC_STATE_SPECIAL) isResting = wizoob_arrive(npc); + if (isResting) wizoob_hide(npc); + else wizoob_show(npc); + + if (npc.controllerID == -1 || npc.state != NPC_STATE_IDLE) npc.friction *= WIZOOB_FRICTION; +} diff --git a/src/platform.cpp b/src/platform.cpp index 933438f..30c0cd9 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -4,6 +4,7 @@ #include "kage_graphics.h" #include "kage_input.h" #include "kage_sound.h" +#include "manager.h" #include "options_config.h" #include #include @@ -518,7 +519,7 @@ int Platform::frame_begin() // Holds the frame to 60 Hz unless vsync paces it: sleeps the whole milliseconds left but one, then spins. A long run // of frames with nothing left to sleep turns the forced pacing back off. -// The original spins without sleeping while a cutscene video is behind (0095dee0). No video plays yet. +// The original spins without sleeping while a cutscene video plays (0095dee0). void Platform::frame_wait() { if (!isPacingForced && isVsync) return; @@ -527,7 +528,7 @@ void Platform::frame_wait() if (sleepMs > 0) { fullFrameCount = 0; - SDL_DelayNS(sleepMs * SDL_NS_PER_MS); + if (!g_manager || !g_manager->cutsceneManager.is_video_playing()) SDL_DelayNS(sleepMs * SDL_NS_PER_MS); } else if (++fullFrameCount > PACING_SWITCH_FRAMES) { diff --git a/src/player_hud.cpp b/src/player_hud.cpp index 91bd3f7..55108f7 100644 --- a/src/player_hud.cpp +++ b/src/player_hud.cpp @@ -18,6 +18,7 @@ constexpr const char* HEARTS_PNG = "gfx/ui/ui_hearts.png"; constexpr const char* HEARTS_SMALL_PNG = "gfx/ui/ui_hearts_small.png"; +constexpr std::string_view CRAFTING_BLIND_GFX = "gfx/Items/Collectibles/questionmark.png"; constexpr const char* COLOR_OFFSET_SHADER = "ColorOffset"; constexpr const char* COLOR_OFFSET_GOLD_SHADER = "ColorOffsetGold"; constexpr const char* ANIMATION_CURSE_HEART = "CurseHeart"; @@ -384,8 +385,9 @@ void PlayerHUD::Update() if (isCraftingItemDirty) { craftingResultImage.reset(); - if (std::ranges::any_of(shown.bagOfCraftingContent, [](char pickup) { return pickup != 0; })) - reconstruction_missing("PlayerHUD::Update 00842230: the crafting bag's result (Entity_Player +0x1f4c)"); + if (ItemConfig_Item* crafted = g_manager->itemConfig.GetCollectible(shown.bagOfCraftingOutput)) + craftingResultImage = Manager::LoadImage((g_game->GetCurses() & CURSE_OF_BLIND) ? CRAFTING_BLIND_GFX + : crafted->gfxFilename); isCraftingItemDirty = false; } diff --git a/src/player_manager.cpp b/src/player_manager.cpp index e3527f6..fa93000 100644 --- a/src/player_manager.cpp +++ b/src/player_manager.cpp @@ -3,7 +3,10 @@ #include "entity_familiar.h" #include "entity_npc.h" #include "entity_player.h" +#include "boss_ai.h" #include "game.h" +#include "game_state_player.h" +#include "hud.h" #include "item_config.h" #include "kage_input.h" #include "log.h" @@ -804,9 +807,140 @@ void PlayerManager::trigger_new_room_effects() } void PlayerManager::RemoveCoPlayer(Entity_Player*) { reconstruction_missing("PlayerManager::RemoveCoPlayer 009ba000"); } -bool PlayerManager::replace_player(Entity_Player*, Entity_Player*) + +// 0083bed0 Has the recent items HUD follow a player replaced by another: the two trade their entries, each refreshed. +static void history_player_swap(HistoryHUD& history, Entity_Player* oldPlayer, Entity_Player* newPlayer) { - reconstruction_missing("PlayerManager::replace_player 009bee80"); + for (HistoryHUDPlayer& entry : history.players) + { + if (entry.player != oldPlayer && entry.player != newPlayer) continue; + entry.player = entry.player == oldPlayer ? newPlayer : oldPlayer; + if (entry.player) entry.isDirty = true; + } +} + +// Moves what links a player to its room onto the player taking its place in the list: the twin, Tainted Lazarus's +// other form, the Forgotten's body, every link to it, its place and motion, and its familiars (followers go). +static void player_links_move(Entity_Player& oldPlayer, Entity_Player& newPlayer) +{ + newPlayer.twinPlayer = oldPlayer.twinPlayer; + if (Entity_Player* twin = oldPlayer.twin_get()) twin->twinPlayer = &newPlayer; + if (&newPlayer != oldPlayer.backupPlayer) + { + newPlayer.backupPlayer = oldPlayer.backupPlayer; + if (newPlayer.backupPlayer) newPlayer.backupPlayer->backupPlayer = &newPlayer; + oldPlayer.backupPlayer = nullptr; + } + if (oldPlayer.forgottenBody) + { + newPlayer.forgottenBody = std::exchange(oldPlayer.forgottenBody, nullptr); + newPlayer.forgottenBody->set_player(&newPlayer); + newPlayer.forgottenBodyRoomIdx = std::exchange(oldPlayer.forgottenBodyRoomIdx, FORGOTTEN_BODY_ROOM_NONE); + newPlayer.forgottenBodyPos = std::exchange(oldPlayer.forgottenBodyPos, Vector{}); + } + for (EntityPtr* referrer : std::vector(oldPlayer.referrers)) *referrer = &newPlayer; + + newPlayer.isExists = true; + g_game->room->GetEntities()->AddEntity(&newPlayer); + newPlayer.SetControllerIndex(oldPlayer.controllerIndex, true); + newPlayer.pos = oldPlayer.pos; + newPlayer.velocity = oldPlayer.velocity; + newPlayer.forgottenBHeight = oldPlayer.forgottenBHeight; + newPlayer.forgottenBHeightVelocity = oldPlayer.forgottenBHeightVelocity; + newPlayer.heightVelocity = oldPlayer.heightVelocity; + newPlayer.posOffset = oldPlayer.posOffset; + newPlayer.flags = oldPlayer.flags; + newPlayer.entityCollisionClass = oldPlayer.entityCollisionClass; + newPlayer.entityGridCollisionClass = oldPlayer.entityGridCollisionClass; + newPlayer.isVisible = !(oldPlayer.flags & FLAG_HELD); + for (Entity* entity : entity_query(ENTITY_FAMILIAR, -1)) + { + auto* familiar = static_cast(entity); + if (familiar->player != &oldPlayer) continue; + if (!familiar->isNotCountedAsFollower && familiar->variant != Entity_Familiar::VANISHING_TWIN) familiar->Remove(); + else familiar->set_player(&newPlayer); + } +} + +// The HUD's look at a replaced pair, and both players' stats and weapons evaluated anew. +static void players_refresh(Entity_Player& oldPlayer, Entity_Player& newPlayer) +{ + HUD& hud = g_game->hud; + hud.statHUD.update_player(&oldPlayer, &newPlayer); + history_player_swap(hud.historyHUD, &oldPlayer, &newPlayer); + hud.AssignPlayerHUDs(); + hud.mark_all_slots_dirty(HISTORY_REBUILD_ICONS, HISTORY_KEEP_ITEMS); +} + +// Has a player evaluate every stat and weapon anew. +static void player_evaluate_all(Entity_Player& player) +{ + player.cacheFlags = CACHE_ALL; + player.weaponTypes.fill(false); + player.EvaluateItems(); +} + +// 009bee80 Puts one player in another's place (Tainted Lazarus's Flip, Esau Jr.): a player outside the list takes the +// other's slot, links, place and familiars while the other is stored away, and two listed players trade slots. +// Whether the players changed places. +bool PlayerManager::replace_player(Entity_Player* oldPlayer, Entity_Player* newPlayer) +{ + oldPlayer->replacedPlayer = newPlayer; + newPlayer->replacedPlayer = oldPlayer; + if (newPlayer->isValid) + { + std::swap(playerList[oldPlayer->playerIndex], playerList[newPlayer->playerIndex]); + std::swap(oldPlayer->playerIndex, newPlayer->playerIndex); + players_refresh(*oldPlayer, *newPlayer); + player_evaluate_all(*oldPlayer); + player_evaluate_all(*newPlayer); + oldPlayer->replacedPlayer = nullptr; + newPlayer->replacedPlayer = nullptr; + return true; + } + + auto slot = std::ranges::find(playerList, oldPlayer); + if (slot == playerList.end()) + { + oldPlayer->replacedPlayer = nullptr; + newPlayer->replacedPlayer = nullptr; + return false; + } + *slot = newPlayer; + oldPlayer->room_exit(false); + oldPlayer->unlistedRestoreState = std::make_shared(); + oldPlayer->StoreGameState(oldPlayer->unlistedRestoreState.get(), false); + newPlayer->playerIndex = oldPlayer->playerIndex; + player_links_move(*oldPlayer, *newPlayer); + oldPlayer->release_weapons_and_effects(true); + oldPlayer->isValid = false; + oldPlayer->isExists = false; + oldPlayer->playerIndex = -1; + players_refresh(*oldPlayer, *newPlayer); + + if (std::shared_ptr saved = std::exchange(newPlayer->unlistedRestoreState, nullptr)) + { + newPlayer->RestoreGameState(*saved); + newPlayer->RestoreGameState_PostLevelInit(*saved); + } + if (!newPlayer->isPostLevelInitFinished) newPlayer->InitPostLevelInitStats(); + newPlayer->canFly = oldPlayer->canFly; + newPlayer->cacheFlags = CACHE_ALL; + newPlayer->weaponTypes.fill(false); + newPlayer->TriggerNewRoom_TemporaryEffects(); + for (Entity* entity : g_game->room->GetEntities()->updateEL) + { + auto* familiar = entity->type == ENTITY_FAMILIAR ? static_cast(entity) : nullptr; + bool isRoomEffect = familiar && (familiar->variant == FAMILIAR_BLOOD_OATH || + familiar->variant == FAMILIAR_PASCHAL_CANDLE); + if (isRoomEffect && familiar->player == newPlayer) + reconstruction_missing("FUN_0062c8a0, the new room effects of Blood Oath and Paschal Candle"); + } + newPlayer->RemoveStatusEffects(); + newPlayer->EvaluateItems(); + oldPlayer->replacedPlayer = nullptr; + newPlayer->replacedPlayer = nullptr; + return true; } Entity_Player* PlayerManager::get_player_by_user_id(uint64_t) { diff --git a/src/room.cpp b/src/room.cpp index 55c403a..b89928c 100644 --- a/src/room.cpp +++ b/src/room.cpp @@ -12,6 +12,8 @@ #include "manager.h" #include "menu_options.h" #include "mines.h" +#include "npc_fireplace.h" +#include "room_path.h" #include "room_render.h" #include "seeds.h" #include "texture_cache.h" @@ -69,6 +71,10 @@ constexpr ColorMod GREY_COLOR = {{1, 1, 1, 1}, {1, 1, 1, -1}, {0, 0, 0}}; // The entity types, variants and subtypes Room checks. constexpr int EFFECT_WOMB_TELEPORT = 82; +// The Stairway's ladder stands in the second row's eleventh cell of a room at least 11 wide. +constexpr int STAIRWAY_MIN_WIDTH = 11; +constexpr int STAIRWAY_COLUMN = 10; + // The room layout spawns Init reads before spawning anything (entities2.xml types 825 to 970). constexpr int SPAWN_WATER = 825; constexpr int SPAWN_DRY = 829; @@ -385,6 +391,21 @@ static void miniboss_title_show(RoomConfig_Room& config) g_game->hud.ShowStackedItemTextCustom(title.c_str(), ""); } +// The purple fireplaces of the Heretic's or Raglich's room: frail (1 health), theirs, and worth no reward. The original +// also emptied a static list here that only their AIs read. +static void boss_fireplaces_bind(Room& room, bool isHeretic) +{ + for (Entity* entity : room.entityList.updateEL) + { + if (entity->type != ENTITY_FIREPLACE || entity->variant != FIRE_PURPLE) continue; + + entity->health = 1; + entity->spawnerVariant = 0; + entity->AddEntityFlags(FLAG_NO_REWARD); + entity->spawnerType = isHeretic ? ENTITY_HERETIC : ENTITY_RAGLICH; + } +} + // 007f2800 Enters a room: resets what a visit keeps, lays out the config's grid, doors, walls and entities from the // descriptor's seeds (what a past visit saved restored on top), floods, darkens or tints it as its backdrop and // flags say, decorates a first visit, and sets the camera on it. @@ -485,8 +506,7 @@ void Room::Init(RoomConfig_Room& config, RoomDescriptor& roomDescriptor) for (int i = 0; i < gridHeight * gridWidth; i++) if (gridEntities[i]) gridEntities[i]->PostInit(); attach_minecarts(); - if (spawnFlags.isHeretic || spawnFlags.isRaglich) - reconstruction_missing("Room::Init 007f2800: the Heretic and Raglich fireplaces"); + if (spawnFlags.isHeretic || spawnFlags.isRaglich) boss_fireplaces_bind(*this, spawnFlags.isHeretic); RestoreState(); if (!descriptor->savedEffects.empty()) reconstruction_missing("Room::Init 007f2800: respawning the saved effects (EntitySaveState)"); @@ -979,6 +999,21 @@ void Room::init_decorations(RoomConfig_Room& config) reconstruction_missing("Room::Init 007f2800: Greed's rocks around the center (GridEntity stays generated)"); } +// The Stairway's ladder in the starting room's top right, with a path carved to it from the entrance. A ladder off +// the grid carves nothing, where the original searched from a cell before the grid. +static void stairway_place(Room& room) +{ + uint32_t seed = Random(); + int cell = room.gridWidth >= STAIRWAY_MIN_WIDTH && room.gridHeight >= 2 ? room.gridWidth + STAIRWAY_COLUMN : -1; + Vector position = vector_make((float)(cell % room.gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_X, + (float)(cell / room.gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_Y); + Entity* ladder = entity_spawn(ENTITY_EFFECT, EFFECT_TALL_LADDER, position, 1, seed); + int start = room.GetGridIndex(g_game->GetPlayer(0)->GetEnterPosition()); + int goal = room.GetGridIndex(ladder->pos); + if (start >= 0 && goal >= 0) + is_grid_path_valid(room, {start, goal, GRID_PATH_PLAYER_WALLS | GRID_PATH_TELEPORTERS | GRID_PATH_CARVE}); +} + // The first visit's items in the starting room: Isaac's Tomb's old chest, the pre-items seed's collectibles (two // under the Curse of the Labyrinth), and Luna's light in secret rooms. void Room::init_first_visit_items() @@ -989,8 +1024,7 @@ void Room::init_first_visit_items() { if (players.FirstCollectibleOwner(COLLECTIBLE_CARD_READING, LAZARUS_SHARE_CHECK) && !is_greed()) reconstruction_missing("Room::Init 007f2800: the starting room's portals (FUN_00737c10)"); - if (players.FirstCollectibleOwner(COLLECTIBLE_THE_STAIRWAY, LAZARUS_SHARE_CHECK)) - reconstruction_missing("Room::Init 007f2800: effect 156's path to the entrance (is_obstacle_path_valid)"); + if (players.FirstCollectibleOwner(COLLECTIBLE_THE_STAIRWAY, LAZARUS_SHARE_CHECK)) stairway_place(*this); if (players.FirstCollectibleOwner(COLLECTIBLE_ISAACS_TOMB, LAZARUS_SHARE_CHECK)) { RNG rng = {descriptor->decorationSeed, 9, 21, 16}; diff --git a/src/room.h b/src/room.h index 154e9fe..be9cbb4 100644 --- a/src/room.h +++ b/src/room.h @@ -288,6 +288,7 @@ public: Vector GetRandomPosition(float margin); int GetRandomTileIndex(uint32_t seed); bool IsPositionInRoom(Vector position, float margin); + bool CanSpawnObstacleAtPosition(int gridIndex, bool isForced); uint32_t GetGridCollision(int gridIndex); uint32_t GetSpawnSeed(); uint32_t GetDecorationSeed(); diff --git a/src/room_clear.cpp b/src/room_clear.cpp index 5125d5f..3358291 100644 --- a/src/room_clear.cpp +++ b/src/room_clear.cpp @@ -532,9 +532,12 @@ static void award_pickups_spawn(ClearAward& award) .type = ENTITY_PICKUP, .variant = variant, .seed = award.rng.Next()})); if (!Entity_Pickup::IsChest(pickup->variant)) award.subType = pickup->subtype; - if (pickup->variant == PICKUP_SPIKEDCHEST || pickup->variant == PICKUP_MIMICCHEST) - reconstruction_missing("Room::SpawnClearAward 007fb250: a spiked chest's spot (Room::" - "CanSpawnObstacleAtPosition 00822820)"); + bool isTrapChest = pickup->variant == PICKUP_SPIKEDCHEST || pickup->variant == PICKUP_MIMICCHEST; + if (isTrapChest && !g_game->room->CanSpawnObstacleAtPosition(g_game->room->GetGridIndex(spot), false)) + { + pickup->Morph(ENTITY_PICKUP, PICKUP_CHEST, 1, false, false, false); + award.subType = 1; + } if (award.isGlitched && i == 0) pickup->AddEntityFlags(FLAG_GLITCH); if (players.FirstCollectibleOwner(COLLECTIBLE_OPTIONS, LAZARUS_SHARE_CHECK)) reconstruction_missing("Room::SpawnClearAward 007fb250: Options' alternative (Room::" diff --git a/src/room_lighting.cpp b/src/room_lighting.cpp index 7f71c7d..e50553f 100644 --- a/src/room_lighting.cpp +++ b/src/room_lighting.cpp @@ -90,25 +90,12 @@ constexpr int VISAGE_HEART_STATE_LIT = 113; constexpr int VISAGE_HEART_STATE_FLARE = 104; constexpr int VISAGE_MASK_STATE_LIT = 105; constexpr int BOSS_ID_WIDOW = 51; -constexpr int ENTITY_PREY = 817; constexpr int FLAMING_VARIANT = 2; constexpr int FLAMING_TYPES[] = {10, 208, 226}; constexpr const char* NULL_LIGHT = "Light"; constexpr const char* LAYER_SPARKS = "sparks"; constexpr const char* LAYER_FLAME = "flame"; -// The effect variants with lights that EffectVariant does not name yet. -enum LightVariant : int -{ - EFFECT_BLUE_FLAME = 10, - EFFECT_TARGET = 30, - EFFECT_RED_CANDLE_FLAME = 52, - EFFECT_FIREWORKS = 104, - EFFECT_OCCULT_TARGET = 153, - EFFECT_KINETI_BEAM = 175, - EFFECT_REVERSE_EXPLOSION = 177 -}; - // The lights' colors: lasers by variant, the explosions' grey lift, and the effects' and enemies' lights. constexpr ColorMod LASER_LIGHT_BLUE = {{0.6f, 0.8f, 1, 1}, {0, 0, 0, 0}, {0, 0, 0}}; constexpr ColorMod LASER_LIGHT_PRIDE = {{0.9f, 0.9f, 1, 1}, {0, 0, 0, 0}, {0, 0, 0}}; diff --git a/src/room_path.cpp b/src/room_path.cpp index 9fc2ae0..20b23c9 100644 --- a/src/room_path.cpp +++ b/src/room_path.cpp @@ -2,6 +2,8 @@ #include "game.h" #include "grid_entity_pit.h" #include "grid_entity_teleporter.h" +#include "entity_pickup.h" +#include "entity_effect.h" #include "log.h" #include #include @@ -13,6 +15,10 @@ constexpr int PATH_BLOCKED = 1000; constexpr float PATH_HEURISTIC_SCALE = 10; constexpr uint16_t PATH_NO_CELL = 0xffff; +// The sides CanSpawnObstacleAtPosition keeps joined around a new obstacle, and its mark for a door beside it. +constexpr std::array, 4> OBSTACLE_SIDES = {{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}}; +constexpr int OBSTACLE_BESIDE_DOOR = -2; + // The obstacles a carving search may cross and break: the rocks but blocks and pillars, and the pits it fills. static bool is_carvable(GridEntityType type) { @@ -164,3 +170,73 @@ bool is_reachable_from_player(Room& room, const Reach& reach) return goal >= 0 && isStartOpen && is_grid_path_valid(room, {start, goal, GRID_PATH_PLAYER_WALLS | GRID_PATH_TELEPORTERS}); } + +// Whether two cells lie less than two steps apart along the grid. +static bool is_cell_near(Room& room, int cell, int other) +{ + return std::abs(cell % room.gridWidth - other % room.gridWidth) + std::abs(cell / room.gridWidth - other / room.gridWidth) < + 2; +} + +// Whether a cell beside a new obstacle is one the paths around it must still join: a free cell, or a grid entity a +// walker passes (TNT and poop always) but a trapdoor, stairs, plate or teleporter. A door beside it forbids it (-2). +static int obstacle_neighbor_get(Room& room, int cell) +{ + GridEntity* grid = room.gridEntities[cell]; + if (!grid) return room.gridPaths[cell] < PATH_BLOCKED ? cell : -1; + if (grid->type == GRID_DOOR) return OBSTACLE_BESIDE_DOOR; + + bool isPassable = (uint32_t)grid->gridIndex >= ROOM_GRID_CELLS || room.gridPaths[grid->gridIndex] < PATH_BLOCKED || + grid->type == GRID_TNT || grid->type == GRID_POOP; + return isPassable && !is_grid_floor_special(grid->type) ? cell : -1; +} + +// 00822820 Whether an obstacle may go on a cell: inside the room (not a crawlspace), on a free or walkable cell that is +// not floor special, under no grounded player (unless forced), two steps from the doors, the Stairway's ladder and the +// shop items, and leaving the cells around it joined. +bool Room::CanSpawnObstacleAtPosition(int gridIndex, bool isForced) +{ + if ((uint32_t)gridIndex >= ROOM_GRID_CELLS || !IsPositionInRoom(GetGridPosition(gridIndex), 0) || + roomType == ROOM_DUNGEON) + return false; + + GridEntity* grid = gridEntities[gridIndex]; + bool isWalkable = grid && (grid->IsEasyCrushableOrWalkable() || grid->IsDangerousCrushableOrWalkable()); + if (grid && (!isWalkable || is_grid_floor_special(grid->type))) return false; + + for (Entity_Player* player : g_game->playerManager.playerList) + { + bool isGrounded = player->entityGridCollisionClass > GRIDCOLL_WALLS; + if (!isForced && isGrounded && GetGridIndex(player->pos) == gridIndex) return false; + } + for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++) + { + bool isDoor = descriptor->data && descriptor->data->doors & (1u << slot); + if (isDoor && is_cell_near(*this, doorGridPositions[slot], gridIndex)) return false; + } + for (Entity* entity : entityList.updateEL) + { + bool isKept = (entity->type == ENTITY_EFFECT && entity->variant == EFFECT_TALL_LADDER) || + (entity->type == ENTITY_PICKUP && static_cast(entity)->price != 0); + int cell = isKept ? GetGridIndex(entity->pos) : -1; + if (cell >= 0 && is_cell_near(*this, cell, gridIndex)) return false; + } + + std::vector neighbors; + for (auto [column, row] : OBSTACLE_SIDES) + { + int cell = GetGridIndexByTile(gridIndex % gridWidth + column, gridIndex / gridWidth + row); + int neighbor = cell >= 0 ? obstacle_neighbor_get(*this, cell) : -1; + if (neighbor == OBSTACLE_BESIDE_DOOR) return false; + if (neighbor >= 0) neighbors.push_back(neighbor); + } + + int savedPath = gridPaths[gridIndex]; + bool isJoined = true; + gridPaths[gridIndex] = PATH_BLOCKED; + for (size_t i = 0; i + 1 < neighbors.size() && isJoined; i++) + for (size_t j = i + 1; j < neighbors.size() && isJoined; j++) + isJoined = is_grid_path_valid(*this, {neighbors[i], neighbors[j], 0}); + gridPaths[gridIndex] = savedPath; + return isJoined; +} diff --git a/src/room_render.cpp b/src/room_render.cpp index 04ce3c9..79facaf 100644 --- a/src/room_render.cpp +++ b/src/room_render.cpp @@ -54,6 +54,21 @@ constexpr float SHOCKWAVE_SCREEN_HEIGHT = 280; constexpr float SHOCKWAVE_FADE_POWER = 0.4f; constexpr float SHOCKWAVE_IDLE_X = -150; +// The water surface's shader and uniforms, G FUEL!'s blue water, an L room's corner part of the floor, and a flooded +// Dross floor's brightening under its water. +constexpr const char* WATER_SURFACE_SHADER = "WaterSurfaceV2"; +constexpr const char* TIME_UNIFORM = "Time"; +constexpr const char* COLOR_MUL_UNIFORM = "ColorMul"; +constexpr const char* CURRENT_DIR_UNIFORM = "CurrentDir"; +constexpr const char* TEXTURE_SIZE_UNIFORM = "TextureSize"; +constexpr const char* PIXELATION_UNIFORM = "PixelationAmount"; +constexpr KColor GFUEL_WATER_COLOR = kcolor_rgba(0.5f, 0.7f, 1, 0.5f); +constexpr KColor GFUEL_WATER_MULTIPLIER = kcolor_rgba(0.5f, 0.7f, 1, 1); +constexpr float WATER_L_WIDTH = 338; +constexpr float WATER_L_HEIGHT = 182; +constexpr float DROSS_WATER_BRIGHTNESS = 0.6f; +constexpr std::array DROSS_WATER_OFFSET = {0.08f, 0.06f, 0.03f}; + // A grid cell on screen: the room's floor sits two cells in from the render surface's corner. constexpr float GRID_SCREEN_CELL = 26; constexpr float FLOOR_MARGIN = 52; @@ -186,7 +201,6 @@ constexpr int ROOM_IDX_BLUE_WOMB_LIGHT = -9; constexpr int BOSS_MOM_MAUSOLEUM = 89; constexpr int DIMENSION_DEATH_CERTIFICATE = 2; constexpr uint32_t ROOM_DESCRIPTOR_FLAG_LIT_DOOR = 1u << 18; -constexpr uint32_t WATER_CLIP_UNDER = 1 << 1; constexpr uint32_t DEBUG_FLAG_GRID_VALUES = 1 << 1; constexpr uint32_t DEBUG_FLAG_ROOM_INFO = 1 << 4; constexpr uint32_t DEBUG_FLAG_GRID_INDICES = 1 << 10; @@ -322,6 +336,13 @@ KColor kcolor_apply(const ColorMod& color, const KColor& input) color._tint[3] * input._alpha); } +// A color part way to another, channel by channel. +static KColor kcolor_lerp(const KColor& from, const KColor& to, float t) +{ + return kcolor_rgba((to._red - from._red) * t + from._red, (to._green - from._green) * t + from._green, + (to._blue - from._blue) * t + from._blue, (to._alpha - from._alpha) * t + from._alpha); +} + static bool is_curse_of_darkness() { uint32_t curses = Seeds::GetForcedCurses() | g_game->debugCurses | g_game->curses; @@ -607,10 +628,86 @@ static void water_render(Room& room, WaterPass) graphics.shader_default_set(); } -// 00821950 Draws the floor through the water surface. Not reconstructed yet. -static void water_shader_render(Room&, Vector) +// A part of the floor the water surface covers: where it sits on the floor's surface, and its size. +struct WaterQuad { - reconstruction_missing("Room::render_water_shader 00821950"); + Vector position{}; + Vector size{}; +}; + +// The floor's parts under the water by the room's shape: the whole floor, a narrow room's strip, or an L's two parts. +static std::vector water_quads_get(Room& room) +{ + Vector size = vector_make(room.floorScreenBottomRight.x - room.floorScreenTopLeft.x, + room.floorScreenBottomRight.y - room.floorScreenTopLeft.y); + Vector corner = vector_make(WATER_L_WIDTH, WATER_L_HEIGHT); + Vector wide = vector_make(size.x - WATER_L_WIDTH, size.y); + Vector near = vector_make(FLOOR_MARGIN, FLOOR_MARGIN); + Vector right = vector_make(FLOOR_MARGIN + WATER_L_WIDTH, FLOOR_MARGIN); + float low = FLOOR_MARGIN + WATER_L_HEIGHT; + RoomConfig_Room* data = room.descriptor ? room.descriptor->data : nullptr; + + switch (data ? data->shape : ROOMSHAPE_NULL) + { + case ROOMSHAPE_IH: + case ROOMSHAPE_IIH: return {{vector_make(FLOOR_MARGIN, FLOOR_MARGIN * 2), vector_make(size.x, size.y - FLOOR_MARGIN * 2)}}; + case ROOMSHAPE_IV: + case ROOMSHAPE_IIV: return {{vector_make(FLOOR_MARGIN * 3, FLOOR_MARGIN), vector_make(size.x - FLOOR_MARGIN * 4, size.y)}}; + case ROOMSHAPE_LTL: return {{right, wide}, {vector_make(FLOOR_MARGIN, low), corner}}; + case ROOMSHAPE_LTR: return {{near, wide}, {vector_make(right.x, low), corner}}; + case ROOMSHAPE_LBL: return {{right, wide}, {near, corner}}; + case ROOMSHAPE_LBR: return {{near, wide}, {right, corner}}; + default: return {{near, size}}; + } +} + +// 00821950 Draws the floor's water surface through the water shader: what lies under the water rippling, refracted +// and tinted by the floor's water color (G FUEL!'s blue, or the room's color while it changes), as strong as the +// room's water. +static void water_shader_render(Room& room, Vector renderOffset) +{ + KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; + KAGE::Graphics::ImageBase& surface = *roomSurfaces.floorWaterV2; + Game& game = *g_game; + FXParams& params = room.fxLayers.fxParams; + KColor color = params.waterColor; + KColor multiplier = params.waterColorMultiplier; + float amount = room.waterAmount; + + graphics.blend_set(KAGE::Graphics::BLEND_NORMAL); + shader_select(WATER_SURFACE_SHADER); + if (game.seedEffects.HasSeedEffect(SEED_G_FUEL)) + { + color = GFUEL_WATER_COLOR; + multiplier = GFUEL_WATER_MULTIPLIER; + } + if (room.waterLerpColorDuration >= 0) + { + float duration = (float)room.waterLerpColorDuration; + float t = room.waterLerpColorDuration ? std::clamp(1 - (float)room.waterLerpColorCountdown / duration, 0.f, 1.f) : 1; + + color = kcolor_lerp(room.waterColor, room.waterLerpTargetColor, t); + multiplier = kcolor_lerp(room.waterColorMultiplier, room.waterLerpTargetColorMult, t); + } + color._alpha *= amount; + + KAGE::Graphics::Shader& shader = *graphics.currentShader; + float time = (float)game.frameCount + (float)game.frameCount; + std::array colorMul = {(multiplier._red - 1) * amount + 1, (multiplier._green - 1) * amount + 1, + (multiplier._blue - 1) * amount + 1}; + std::array textureSize = {(float)surface.textureWidth, (float)surface.textureHeight}; + + shader.set_uniform(TIME_UNIFORM, KAGE::Graphics::UNIFORM_FLOAT, &time); + shader.set_uniform(COLOR_MUL_UNIFORM, KAGE::Graphics::UNIFORM_VEC3, colorMul.data()); + shader.set_uniform(CURRENT_DIR_UNIFORM, KAGE::Graphics::UNIFORM_VEC2, &room.waterCurrent); + shader.set_uniform(TEXTURE_SIZE_UNIFORM, KAGE::Graphics::UNIFORM_VEC2, textureSize.data()); + shader.set_uniform(PIXELATION_UNIFORM, KAGE::Graphics::UNIFORM_FLOAT, &spriteShaderParams.pixelationAmount); + for (const WaterQuad& quad : water_quads_get(room)) + { + surface.Render(KAGE::Graphics::source_quad_rect(quad.position, quad.size), + KAGE::Graphics::color_quad_rect(vector_add(quad.position, renderOffset), quad.size, WHITE), color); + } + graphics.shader_default_set(); } // 007135d0 Draws a pit's first layer at its cell of a room surface with another image in place of its sheet. @@ -627,6 +724,20 @@ static void pit_mask_render(GridEntity& pit, KAGE::Graphics::ImagePtr image) layer->spriteSheet = sheet; } +// The flooded Mines' pits over their lava: each pit without its first layer. +static void mines_pits_render(Room& room, Vector offset) +{ + for (int i = 0; i < room.gridWidth * room.gridHeight; i++) + { + GridEntity* pit = room.gridEntities[i]; + if (!is_grid_type(pit, GRID_PIT)) continue; + + pit->sprite.GetLayer(0)->isVisible = false; + pit->Render(offset); + pit->sprite.GetLayer(0)->isVisible = true; + } +} + // 00826f80 Draws the flooded Mines' lava pits (the textured pit surface render_lava_pit_mask fills) over the floor. static void water_overlay_render(Room& room, Vector surfaceOffset) { @@ -680,11 +791,90 @@ static void lava_pit_mask_render(Room& room) graphics.shader_default_set(); } -// 00820fd0 Draws the floor under the water surface into its surface. Not reconstructed yet past its check. +// Draws the entities down the grid rows to each row's top, then those just past the last row. +static void water_rows_render(EntityList& list, Room& room, Vector offset) +{ + uint32_t depth = DEPTH_GRID; + + for (int row = 0; row < room.gridHeight; row++) + { + float top = (float)row * GRID_CELL_SIZE + GRID_ORIGIN_Y - DEPTH_ROW_BOTTOM; + depth = (uint32_t)std::floor(top * DEPTH_ROW_SCALE + DEPTH_ROW_BASE + 0.5f); + list.render_up_to(depth, offset); + } + list.render_up_to(depth + DEPTH_AFTER_ROWS, offset); +} + +// The post renders of the entities drawn since the render cursor went back to the first. +static void entities_post_render(EntityList& list) +{ + for (uint32_t i = 0; i < list.renderCursor; i++) list.renderEL[i]->PostRender(); +} + +// 00820fd0 Draws what lies under the water into the water surface, at the surface's own origin and unshaken: the floor +// (brighter in a flooded Dross room), the decorations, the floor's entities refracted, the walls in the floor's color, +// the rails and the grid entities under the water, a flooded Mines room's lava and pits (the pits twice), the pit +// rails, the underwater layers, then the entities refracted and reflected down the grid rows. static void floor_water_render(Room& room) { - if (room.waterAmount > 0 && g_manager->optionsConfig.render.isWaterSurfaceEnabled) - reconstruction_missing("Room::render_floor_water 00820fd0"); + if (room.waterAmount <= 0 || !g_manager->optionsConfig.render.isWaterSurfaceEnabled) return; + + KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; + Game& game = *g_game; + EntityList& list = room.entityList; + KAGE::Graphics::BlendMode savedBlend = graphics.blendMode; + Vector savedShake = game.screenShakeOffset; + Vector offset = vector_make(-room.renderSurfaceTopLeft.x, -room.renderSurfaceTopLeft.y); + ColorMod floorColor = room.floorColor; + float amount = room.waterAmount; + + game.screenShakeOffset = Vector{}; + graphics.render_target_push(roomSurfaces.floorWaterV2.get(), KAGE::Graphics::TARGET_OWN_SIZE, + KAGE::Graphics::PRESENT_FLUSH); + graphics.isCullOffscreen = false; + graphics.Clear(); + if (room.backdropType == BACKDROP_DROSS) + { + for (int channel = 0; channel < 3; channel++) + { + floorColor._tint[channel] *= amount * DROSS_WATER_BRIGHTNESS + 1; + floorColor._offset[channel] += amount * DROSS_WATER_OFFSET[channel]; + } + } + room.backdrop.RenderFloor(Vector{}, floorColor); + grids_render(room, offset, [](const GridEntity& grid) { return grid.type == GRID_DECORATION; }); + list.renderCursor = 0; + list.renderMode = RENDER_WATER_REFRACT; + list.render_up_to(DEPTH_FLOOR, offset); + + room.backdrop.RenderWalls(Vector{}, room.floorColor); + room.railManager.Render(offset); + grids_render(room, offset, [](GridEntity& grid) { return !(grid.GetWaterClipInfo().flags & WATER_CLIP_ABOVE); }); + if (room.backdropType == BACKDROP_MINES && room.descriptor->flags & ROOM_DESCRIPTOR_FLAG_HAS_WATER) + { + water_overlay_render(room, Vector{}); + mines_pits_render(room, offset); + mines_pits_render(room, offset); + } + pit_rails_render(room, offset); + room.fxLayers.underwater_layers_render(); + water_rows_render(list, room, offset); + entities_post_render(list); + + list.renderCursor = 0; + list.renderMode = RENDER_SKIP; + list.render_up_to(DEPTH_FLOOR, offset); + list.renderMode = RENDER_WATER_REFLECT; + water_rows_render(list, room, offset); + list.render_up_to(UINT_MAX, offset); + entities_post_render(list); + list.renderMode = RENDER_NULL; + + graphics.shader_default_set(); + graphics.blendMode = savedBlend; + graphics.isCullOffscreen = true; + graphics.render_target_pop(KAGE::Graphics::PRESENT_FLUSH); + game.screenShakeOffset = savedShake; } // The floor's backing quad: the Greed shop's brown, or the floor color's change of black. @@ -752,15 +942,7 @@ static void walls_render(Room& room, Vector surfaceOffset, bool isWaterShown, KA if (room.backdropType == BACKDROP_MINES && room.descriptor->flags & ROOM_DESCRIPTOR_FLAG_HAS_WATER) { water_overlay_render(room, surfaceOffset); - for (int i = 0; i < room.gridWidth * room.gridHeight; i++) - { - GridEntity* pit = room.gridEntities[i]; - if (!is_grid_type(pit, GRID_PIT)) continue; - - pit->sprite.GetLayer(0)->isVisible = false; - pit->Render(scroll); - pit->sprite.GetLayer(0)->isVisible = true; - } + mines_pits_render(room, scroll); } pit_rails_render(room, scroll); } @@ -818,7 +1000,7 @@ static void depth_render(Room& room, bool isWaterShown) } if (isWaterShown) list.renderMode = RENDER_NORMAL; list.render_up_to(UINT_MAX, scroll); - for (uint32_t i = 0; i < list.renderCursor; i++) list.renderEL[i]->PostRender(); + entities_post_render(list); list.renderMode = RENDER_NULL; } diff --git a/src/room_update.cpp b/src/room_update.cpp index 2626bd9..a110cf8 100644 --- a/src/room_update.cpp +++ b/src/room_update.cpp @@ -101,6 +101,44 @@ constexpr int ALARM_DELAY = 10; constexpr float ALARM_PAN_FRAMES = 60; constexpr int MAP_WIDTH = 13; +// The ambient mist: a puff every 210 frames (five on entering), spread over the room and 40 above and below it, or +// starting 600 right of it, drifting left at 0.25 to 0.75, its alpha from 0.7, tinted by the stage. +constexpr int MIST_FRAMES = 210; +constexpr int MIST_ENTER_PUFFS = 5; +constexpr float MIST_MARGIN_Y = 40; +constexpr float MIST_SPREAD = 500; +constexpr float MIST_START_X = 600; +constexpr float MIST_SPEED_MIN = 0.25f; +constexpr float MIST_SPEED_RANGE = 0.5f; +constexpr float MIST_ALPHA_MIN = 0.7f; +constexpr float MIST_ALPHA_RANGE = 0.3f; +constexpr const char* MIST_ANIMATION = "Idle"; +constexpr std::array MIST_TINT_DOWNPOUR = {0.87843144f, 0.9607844f, 0.97647065f}; +constexpr std::array MIST_TINT_CORPSE = {0.54901963f, 0.16470589f, 0.16470589f}; +constexpr std::array MIST_TINT_BLUE_WOMB = {0.83921576f, 0.9176471f, 0.97647065f}; +constexpr std::array MIST_TINT_DROSS = {0.21960786f, 0.27450982f, 0.08627451f}; +constexpr std::array MIST_TINT_MINES = {0.3921569f, 0.3137255f, 0.50980395f}; +constexpr std::array MIST_TINT_DEATH_CERTIFICATE = {0.47058827f, 0.47058827f, 0.47058827f}; +constexpr std::array MIST_TINT_DEFAULT = {0.43921572f, 0.54901963f, 0.1764706f}; + +// A water current pushes the grounded at 0.4, splashing 2 to 4 times every 3 frames at 4 to 10 along it, and the +// water past a wall foams half a cell back, at twice the size. +constexpr float CURRENT_PUSH = 0.4f; +constexpr int CURRENT_SPLASH_FRAMES = 3; +constexpr uint32_t CURRENT_SPLASH_RANGE = 3; +constexpr int CURRENT_SPLASH_MIN = 2; +constexpr float CURRENT_SPLASH_SPEED_MIN = 4; +constexpr float CURRENT_SPLASH_SPEED_RANGE = 6; +constexpr float CURRENT_WALL_BACK = 0.54f; +constexpr float CURRENT_HALF_TURN = 3.14f; + +// Where a current's splashes start: around a wading entity (its spawner), or past a wall. +struct CurrentSplash +{ + Vector position{}; + Entity* wader = nullptr; +}; + // The run, room and stage values Update tells apart. constexpr ColorMod POOP_FX_COLOR = {{1, 1, 1, 3}, {0.7f, 0.1f, 0.9f, 1}, {0, 0, 0}}; constexpr int NULL_EFFECT_POOP_CLOUD = 64; @@ -110,7 +148,7 @@ constexpr int SOUND_THUNDER = 472; constexpr int SOUND_ALARM = 460; constexpr int PLAYER_THE_FORGOTTEN_B = 35; constexpr int DIMENSION_DEATH_CERTIFICATE = 2; -constexpr int BOSS_THE_BEAST_ROOM = 91; +constexpr int BOSS_MIN_MIN = 91; constexpr int ROOM_IDX_DUNGEON_BEAST = -16; constexpr int GREED_LAST_STAGE = 5; constexpr int GREED_LAST_STAGE_ID = 10; @@ -585,31 +623,131 @@ static void lightning_update() g_manager->sfxManager.Play(sound, {.volume = 1, .frameDelay = THUNDER_DELAY, .pitch = pitch}); } -// 00824a70 The drifting particles of the Corpse, Dross, the Beast's room, the Beast's crawlspace and the mineshaft: -// five on entering and one every 210 frames, drifting left across the room. Not reconstructed yet past its checks. +// 00824a70 The mist drifting through the Dross and the Corpse (and Min-Min's room, the Beast's arena, a mirrored +// mineshaft, the Death Certificate floor or any other dimension): five puffs over the room on entering, then one from the right every 210 +// frames, each a random frame of its drift, flipped at random, tinted by the stage and a little see through. static void ambient_effects_update(Room& room) { Game& game = *g_game; int stageId = room_stage_id(); bool isStage = game.currentDimensionIdx == DIMENSION_DEATH_CERTIFICATE || stageId == STAGE_ID_CORPSE || stageId == STAGE_ID_DROSS; - bool isBeastRoom = room.roomType == ROOM_BOSS && room.bossId == BOSS_THE_BEAST_ROOM; + bool isMinMinRoom = room.roomType == ROOM_BOSS && room.bossId == BOSS_MIN_MIN; bool isMineshaft = game.HasAbandonedMineshaft() && game.currentDimensionIdx == DIMENSION_MIRROR; - if (!isStage && !isBeastRoom && game.currentRoomIdx != ROOM_IDX_DUNGEON_BEAST && !isMineshaft && + if (!isStage && !isMinMinRoom && game.currentRoomIdx != ROOM_IDX_DUNGEON_BEAST && !isMineshaft && game.currentDimensionIdx == 0) return; int frames = room.GetFrameCount(); - if (frames != 0 && game.frameCount % 210 != 0) return; - reconstruction_missing("Room::update_ambient_effects 00824a70"); + if (frames != 0 && game.frameCount % MIST_FRAMES != 0) return; + + float top = room.topLeftPos.y - MIST_MARGIN_Y; + std::array tint = MIST_TINT_DEFAULT; + if (stageId == STAGE_ID_DOWNPOUR) tint = MIST_TINT_DOWNPOUR; + else if (room.backdropType == BACKDROP_CORPSE2 || room.backdropType == BACKDROP_CORPSE3) tint = MIST_TINT_CORPSE; + else if (room.backdropType == BACKDROP_BLUE_WOMB) tint = MIST_TINT_BLUE_WOMB; + else if (stageId == STAGE_ID_DROSS) tint = MIST_TINT_DROSS; + else if (stageId == STAGE_ID_MINES || stageId == STAGE_ID_ASHPIT) tint = MIST_TINT_MINES; + else if (game.currentDimensionIdx == DIMENSION_DEATH_CERTIFICATE) tint = MIST_TINT_DEATH_CERTIFICATE; + + for (int puff = 0; puff < (frames == 0 ? MIST_ENTER_PUFFS : 1); puff++) + { + float y = (room.bottomRightPos.y + MIST_MARGIN_Y - top) * random_unit() + top; + float x = (room.bottomRightPos.x + MIST_SPREAD - room.topLeftPos.x) * random_unit() + room.topLeftPos.x; + Vector velocity = vector_make(-MIST_SPEED_MIN - random_unit() * MIST_SPEED_RANGE, 0); + Entity* mist = entity_spawn(ENTITY_EFFECT, EFFECT_MIST, + vector_make(frames == 0 ? x : room.bottomRightPos.x + MIST_START_X, y), velocity, + Random()); + ANM2& sprite = mist->sprite; + const AnimationData* idle = sprite.GetAnimationData(MIST_ANIMATION); + int frame = idle && idle->length ? (int)(Random() % (uint32_t)idle->length) : 0; + + if (sprite.SetAnimation(MIST_ANIMATION, SWITCH_KEEP_FRAME) && sprite.animState.animData) + { + sprite.animState.SetFrameFloat((float)frame); + sprite.animState.isPlaying = false; + } + sprite.isFlipX = Random() & 1; + sprite.isFlipY = Random() & 1; + sprite.GetLayer(0)->color = {{tint[0], tint[1], tint[2], random_unit() * MIST_ALPHA_RANGE + MIST_ALPHA_MIN}, + {0, 0, 0, 0}, + {0, 0, 0}}; + mist->Update(); + } } -// 00824ee0 A water current carries the pickups, enemies and players standing in it along, and stirs ripples. -// Not reconstructed yet past its check. +// 2 to 4 splashes thrown along the current from a spot, the spray of a wading entity or of the water past a wall. +static void current_splashes_spawn(Room& room, const CurrentSplash& splash) +{ + Vector current = room.waterCurrent; + + for (int count = (int)(Random() % CURRENT_SPLASH_RANGE) + CURRENT_SPLASH_MIN; count > 0; count--) + { + Vector position = splash.position; + if (splash.wader) + { + float angle = random_unit() * CURRENT_HALF_TURN * 2; + float reach = random_unit(); + position = vector_make(std::cos(angle) * splash.wader->size * reach + position.x, + std::sin(angle) * splash.wader->size * reach + position.y); + } + uint32_t seed = Random(); + float speed = random_unit() * CURRENT_SPLASH_SPEED_RANGE + CURRENT_SPLASH_SPEED_MIN; + float angle = random_unit() * CURRENT_HALF_TURN * 2; + Vector velocity = vector_make(std::cos(angle) + current.x * speed, std::sin(angle) + current.y * speed); + if (!splash.wader) + { + float side = random_unit() - 0.5f; + float along = random_unit(); + Vector cell = vector_make(current.x * GRID_CELL_SIZE, current.y * GRID_CELL_SIZE); + position = vector_make(side * cell.y + (position.x - cell.x * CURRENT_WALL_BACK) + current.x * 3 * along, + side * cell.x + (position.y - cell.y * CURRENT_WALL_BACK) + current.y * 3 * along); + } + Entity* spray = g_game->Spawn({.position = position, .velocity = velocity, .spawner = splash.wader, + .subType = 1, .type = ENTITY_EFFECT, .variant = EFFECT_WATER_SPLASH, + .seed = seed}); + if (!splash.wader) spray->sprite.scale = vector_make(spray->sprite.scale.x * 2, spray->sprite.scale.y * 2); + spray->Update(); + } +} + +// 00824ee0 A water current carries the pickups, bombs, players and enemies on the ground along, the walking ones +// splashing every 3 frames, and the water foams past the walls it flows from every 3 frames of the room. static void water_current_update(Room& room) { - if (room.waterCurrent.x != 0 || room.waterCurrent.y != 0) - reconstruction_missing("Room::update_water_current 00824ee0"); + Vector current = room.waterCurrent; + if (current.x == 0 && current.y == 0) return; + + for (Entity* entity : room.entityList.updateEL) + { + bool isWalker = entity->type == ENTITY_PLAYER || (entity->type >= ENTITY_FIRST_ENEMY && entity->type < ENTITY_EFFECT); + bool isCarried = isWalker || entity->type == ENTITY_BOMB || + (entity->type == ENTITY_PICKUP && entity->entityCollisionClass != ENTCOLL_NONE); + int grid = entity->entityGridCollisionClass; + if (!isCarried || (grid != GRIDCOLL_GROUND && grid != GRIDCOLL_NOPITS)) continue; + + entity->velocity = vector_make(current.x * CURRENT_PUSH + entity->velocity.x, + current.y * CURRENT_PUSH + entity->velocity.y); + if (!entity->HasEntityFlags(FLAG_INTERPOLATION_UPDATE) && !g_game->IsPaused() && + g_game->frameCount % CURRENT_SPLASH_FRAMES == 0 && isWalker) + current_splashes_spawn(room, {entity->pos, entity}); + } + + if (!room.isInitialized || (g_game->frameCount - room.enterFrame) % CURRENT_SPLASH_FRAMES != 0) return; + for (int i = 0; i < room.gridWidth * room.gridHeight; i++) + { + if (!room.gridEntities[i] || room.gridEntities[i]->type != GRID_WALL) continue; + + Vector cell = room.GetGridPosition(i); + Vector spot = vector_make(cell.x + current.x * GRID_CELL_SIZE, cell.y + current.y * GRID_CELL_SIZE); + Vector clamped = room.GetClampedPositionImpl(spot, 0, 0, 0, 0); + bool isInside = room.IsLShapedRoom() + ? clamped.x == spot.x && clamped.y == spot.y + : spot.x >= room.topLeftPos.x && spot.x <= room.bottomRightPos.x && + spot.y >= room.topLeftPos.y && spot.y <= room.bottomRightPos.y; + if (isInside && room.GetGridCollision(room.GetGridIndex(spot)) <= COLLISION_PIT) + current_splashes_spawn(room, {spot, nullptr}); + } } // The walls bleeding for a while: blood particles burst from random points of the room's edge each frame, green in diff --git a/src/sfx_manager.h b/src/sfx_manager.h index f68ab41..3d5fbbc 100644 --- a/src/sfx_manager.h +++ b/src/sfx_manager.h @@ -44,13 +44,16 @@ enum SoundId : int SOUND_DEATH_BURST_LARGE = 28, SOUND_BOSS1_EXPLOSIONS = 28, SOUND_DEATH_REVERSE = 29, + SOUND_DEATH_BURST_SMALL = 30, SOUND_FART = 37, SOUND_FETUS_JUMP = 38, SOUND_FETUS_LAND = 40, SOUND_FIREDEATH_HISS = 43, SOUND_COIN_INSERT = 45, SOUND_FORESTBOSS_STOMPS = 48, + SOUND_GASCAN_POUR = 51, SOUND_HELLBOSS_GROUNDPOUND = 52, + SOUND_GLASS_BREAK = 53, SOUND_HOLY = 54, SOUND_ISAAC_HURT_GRUNT = 55, SOUND_CHILD_ANGRY_ROAR = 57, @@ -83,12 +86,14 @@ enum SoundId : int SOUND_MONSTER_YELL_A = 119, SOUND_MONSTER_YELL_B = 122, SOUND_POWERUP1 = 128, + SOUND_POWERUP2 = 129, SOUND_POWERUP_SPEWER = 132, SOUND_REDLIGHTNING_ZAP = 133, SOUND_REDLIGHTNING_ZAP_WEAK = 134, SOUND_REDLIGHTNING_ZAP_STRONG = 135, SOUND_ROCK_CRUMBLE = 137, SOUND_SMB_LARGE_CHEWS_4 = 142, + SOUND_SCARED_WHIMPER = 143, SOUND_SHAKEY_KID_ROAR = 146, SOUND_SINK_DRAIN_GURGLE = 149, SOUND_TEAR_IMPACTS = 150, @@ -98,6 +103,7 @@ enum SoundId : int SOUND_WHEEZY_COUGH = 158, SOUND_SPIDER_COUGH = 159, SOUND_ZOMBIE_WALKER_KID = 165, + SOUND_ANIMAL_SQUISH = 166, SOUND_ANGRY_GURGLE = 167, SOUND_BATTERYCHARGE = 170, SOUND_BEEP = 171, @@ -131,6 +137,7 @@ enum SoundId : int SOUND_SHELLGAME = 252, SOUND_SLOTSPAWN = 255, SOUND_SPLATTER = 258, + SOUND_STEAM_HALFSEC = 261, SOUND_STONESHOOT = 262, SOUND_WEIRD_WORM_SPIT = 263, SOUND_SUMMONSOUND = 265, @@ -195,6 +202,7 @@ enum SoundId : int SOUND_VAMP_DOUBLE = 614, SOUND_GFUEL_AIR_HORN = 828, SOUND_DARK_BUM_PAYOUT = 853, + SOUND_DRSREMOTE_WARNING = 855, SOUND_POOP_THROW = 865, SOUND_SUMMON_WAVE = 872, SOUND_PRIDE_ZAP = 903, @@ -261,8 +269,10 @@ enum SoundId : int SOUND_MONSTERS_NEXT_DOOR = 1008, SOUND_IMMACULATE_CONCEPTION = 1010, SOUND_SHINYROCK_SHIMMER = 1014, + SOUND_SISSYLONGLEG_CHARM = 1016, SOUND_NECROMANCER = 1049, SOUND_TRAP_DOOR_LEVEL = 1052, + SOUND_BAG_OF_CRAFTING = 1074, SOUND_GIANT_CHEST_OPEN = 1075, SOUND_BRAIN_MOVE = 1080, SOUND_POISON_MIND_HURT = 1081, @@ -272,7 +282,30 @@ enum SoundId : int SOUND_CUBE_BABY_KICK = 852, SOUND_OCCULAR_RIFT_PORTAL = 1088, SOUND_ROCKET_LAUNCH_SHORT = 585, - SOUND_ROCKET_LAUNCH_TINY = 586 + SOUND_ROCKET_LAUNCH_TINY = 586, + SOUND_FLOATY_BABY_ROAR = 44, + SOUND_IMP_GROWL = 1076, + SOUND_IMP_SHOOT = 1077, + SOUND_IMP_WARP_OUT = 1078, + SOUND_IMP_WARP_IN = 1079, + SOUND_LIGHTBOLT = 172, + SOUND_LIGHTBOLT_CHARGE = 173, + SOUND_HUSH_ROAR = 421, + SOUND_HUSH_GROWL = 422, + SOUND_HUSH_LOW_ROAR = 423, + SOUND_HUSH_CHARGE = 425, + SOUND_LAZARUS_FLIP_DEAD = 582, + SOUND_LAZARUS_FLIP_ALIVE = 583, + SOUND_BERSERK_START = 592, + SOUND_ISAAC_ROAR = 650, + SOUND_ANIMA_TRAP = 611, + SOUND_ANIMA_BREAK = 613, + SOUND_DARK_ESAU_OPEN = 616, + SOUND_DARK_ESAU_DEATH_OPEN = 617, + SOUND_ABYSS = 834, + SOUND_FLIP_POOF = 856, + SOUND_VOID_FAIL = 1072, + SOUND_ABYSS_SUCCESS = 1073 }; // Construction, copies and destruction (00a2a990, 00a2aa60, 00a2ab40, 00a2ac90) are the defaults. diff --git a/src/tainted_characters.cpp b/src/tainted_characters.cpp new file mode 100644 index 0000000..0e36eb9 --- /dev/null +++ b/src/tainted_characters.cpp @@ -0,0 +1,607 @@ +#include "tainted_characters.h" +#include "boss_ai.h" +#include "entity_slot.h" +#include "entity_effect.h" +#include "entity_familiar.h" +#include "entity_npc.h" +#include "npc_caves.h" +#include "entity_pickup.h" +#include "entity_player.h" +#include "game.h" +#include "hud.h" +#include "item_pool.h" +#include "log.h" +#include "loot_list.h" +#include "manager.h" +#include "npc_ai.h" +#include "player_manager.h" +#include "room.h" +#include "sfx_manager.h" +#include +#include +#include +#include +#include + +// Dark Esau is called when Jacob's curse has this many frames left (Anima Sola with nothing to chain sets it there). +constexpr int DARK_ESAU_CALL_FRAMES = 10; + +// The body Tainted Jacob leaves when Dark Esau turns him ghost: six frames into its death, a still effect. +constexpr float GHOST_CORPSE_FRAME = 6; +constexpr int GHOST_CORPSE_STATE = 10; + +// Anima Sola chains for 150 frames (200 with Tainted Jacob's Birthright), a split Dark Esau's chains 10 pixels either +// side of the pair's middle. A chained enemy counts a million farther off. +constexpr int ANIMA_FRAMES = 150; +constexpr int ANIMA_FRAMES_BIRTHRIGHT = 200; +constexpr float ANIMA_PAIR_OFFSET = 10; +constexpr float ANIMA_REACH_NONE = 1e9f; +constexpr float ANIMA_CHAINED_PENALTY = 1e6f; + +// A chain is a head on its target and three pegs 80 pixels (plus the target's size) around it, a third of a turn +// apart, lifted 15 pixels. The head shows after 6 frames with a shake, holds its target 4 frames at a time and slows it +// to 0.9. Under 90 frames left it blinks red every 30 frames, every 8 under 30, every 3 under 16. A peg's link reaches +// the head over 15 frames, tugging the target at 0.06. A broken peg leaves gibs every 15 pixels at 2 to 8. +enum AnimaChainPart +{ + ANIMA_CHAIN_HEAD, + ANIMA_CHAIN_PEG +}; + +constexpr float ANIMA_PEG_REACH = 80; +constexpr float ANIMA_FULL_TURN = 360; +constexpr float ANIMA_PEG_TURN = 120; +constexpr int ANIMA_PEG_COUNT = 3; +constexpr float ANIMA_HEAD_LIFT = -15; +constexpr float ANIMA_HEAD_DEPTH = 6; +constexpr float ANIMA_SHOW_FRAMES = 6; +constexpr int ANIMA_SHAKE = 8; +constexpr int ANIMA_HOLD_FRAMES = 4; +constexpr float ANIMA_SLOW = 0.9f; +constexpr int ANIMA_BLINK_START = 90; +constexpr int ANIMA_BLINK_SLOW_END = 30; +constexpr int ANIMA_BLINK_FAST_END = 16; +constexpr int ANIMA_BLINK_SLOW = 30; +constexpr int ANIMA_BLINK_MID = 8; +constexpr int ANIMA_BLINK_FAST = 3; +constexpr int ANIMA_BLINK_FRAMES = 2; +constexpr ColorMod ANIMA_BLINK_COLOR = {{1, 0.3f, 0.3f, 1}, {}, {0.4f, 0, 0}}; +constexpr float ANIMA_REACH_FRAMES = 15; +constexpr float ANIMA_TUG = 0.06f; +constexpr float ANIMA_GIB_SPACING = 15; +constexpr float ANIMA_GIB_SPEED = 2; +constexpr float ANIMA_GIB_SPEED_RANGE = 6; +constexpr ColorMod ANIMA_GIB_COLOR = {{1, 1, 1, 1}, {1, 1, 1, 1}, {}}; + +// One Anima Sola chain: where it starts, what it holds, the chain already on it and its time. +struct AnimaChain +{ + Vector position{}; + Entity* target = nullptr; + Entity_Effect* existing = nullptr; + int duration = 0; +}; + +// Lemegeton's wisp config under Book of Virtues, among the extra wisp configs. +constexpr int LEMEGETON_VIRTUES_WISP = 0x10012; +// How many wisps each of the three wisp rings holds, from the innermost. +constexpr std::array WISP_RING_CAPACITY = {6, 8, 12}; +constexpr int WISP_RING_FIRST_LAYER = 7; +constexpr int WISP_PRIORITY_NONE = 9999; + +// A locust flies out at a random angle, 6 to 10 pixels a frame, in one of its two flying states. +constexpr float LOCUST_TURN = 3.14f * 2; +constexpr float LOCUST_SPEED_MIN = 6; +constexpr float LOCUST_SPEED_RANGE = 4; +constexpr int LOCUST_STATE_FIRST = 4; +constexpr float LOCUST_POOF_DROP = 10; +constexpr ColorMod LOCUST_POOF_COLOR = {{0.1f, 0.1f, 0.1f, 1}, {}, {}}; + +// One in this many Lemegeton uses draws from the room's pool, the others from a weighted pool. +constexpr int LEMEGETON_ROOM_POOL_CHANCE = 4; +constexpr uint32_t LEMEGETON_PICK_SHIFT = 35; + +// A Lemegeton pool and its weight. +struct PoolWeight +{ + int pool = 0; + int weight = 0; +}; + +constexpr PoolWeight LEMEGETON_POOLS[] = {{POOL_TREASURE, 100}, {POOL_SHOP, 30}, {POOL_BOSS, 30}, {POOL_DEVIL, 4}, + {POOL_ANGEL, 4}, {POOL_SECRET, 2}, {POOL_PLANETARIUM, 2}, {POOL_CURSE, 2}}; +constexpr PoolWeight LEMEGETON_GREED_POOLS[] = {{POOL_GREED_TREASURE, 100}, {POOL_GREED_SHOP, 50}, + {POOL_GREED_BOSS, 30}, {POOL_GREED_DEVIL, 4}, + {POOL_GREED_ANGEL, 4}, {POOL_PLANETARIUM, 2}}; + +// Holds the used item up, unless the use hides it. +static void use_animate(ItemUse& use) +{ + if (use.isShowAnimation) use.player.AnimateCollectible(use.id, "UseItem", "PlayerPickupSparkle"); +} + +// A black poof where an item turned into locusts or a Lazarus flipped, updated at once. +static Entity* poof_spawn(Vector position) +{ + Entity* poof = g_game->Spawn({position, {}, nullptr, 0, ENTITY_EFFECT, EFFECT_POOF01, Random()}); + return poof; +} + +// 005b35c0 Turns a collectible into its Abyss locusts around a place: each locust config of the item (Breakfast's for +// an item without one) sends out its count of locusts, then a dark poof shows. +void locust_spawn(Entity_Player& player, int collectibleType, Vector position) +{ + ItemConfig& config = g_manager->itemConfig; + ItemConfig_Item* item = config.GetCollectible(collectibleType); + if (!item || item->locusts.empty()) item = config.GetCollectible(COLLECTIBLE_BREAKFAST); + + for (size_t index = 0; index < item->locusts.size(); index++) + { + for (int i = 0; i < item->locusts[index].count; i++) + { + float angle = random_unit() * LOCUST_TURN; + float speed = random_unit() * LOCUST_SPEED_RANGE + LOCUST_SPEED_MIN; + Vector velocity = vector_make(std::cos(angle) * speed, std::sin(angle) * speed); + auto* locust = static_cast(g_game->Spawn( + {position, velocity, &player, collectibleType, ENTITY_FAMILIAR, Entity_Familiar::ABYSS_LOCUST, Random()})); + locust->state = (int)(Random() & 1) + LOCUST_STATE_FIRST; + locust->item = config.GetCollectible(collectibleType); + locust->set_locust_config_index((int)index); + locust->Update(); + } + } + if (item->locusts.empty()) return; + + Entity* poof = poof_spawn(vector_make(position.x, position.y + LOCUST_POOF_DROP)); + poof->SetColor(LOCUST_POOF_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + poof->Update(); +} + +// Abyss: the held item and every free pedestal item of the room become locusts, with the success sounds, and eating +// starts a challenge room's or the boss rush's waves. +void abyss_use(ItemUse& use) +{ + Entity_Player& player = use.player; + if (player.variant == PLAYER_VARIANT_PLAYER) + { + bool isEaten = false; + ItemConfig_Item* held = player.queuedItem.item; + if (held && held->IsCollectible() && !held->HasTags(TAG_QUEST)) + { + locust_spawn(player, held->id, player.pos); + player.ClearQueueItem(); + isEaten = true; + } + + PlayerManager& players = g_game->playerManager; + for (Entity* entity : g_game->room->GetEntities()->updateEL) + { + if (entity->type != ENTITY_PICKUP || entity->isDead) continue; + auto& pickup = static_cast(*entity); + if (!pickup.CanReroll() || pickup.IsShopItem() || pickup.variant != PICKUP_COLLECTIBLE || + pickup.subtype == 0 || pickup.timeout >= 1) + continue; + + locust_spawn(player, pickup.subtype, pickup.pos); + pickup.Remove(); + pickup.RemoveOtherOptions(); + if (players.IsCoopPlay() && pickup.coopDuplicateIndex != -1 && + pickup.coopDuplicateIndex + 1 < players.GetNumAlivePlayers()) + reconstruction_missing("Abyss in Entity_Player::UseActiveItem 005b39d0 (a co-op duplicate's item)"); + isEaten = true; + } + + if (!isEaten) sound_play(SOUND_VOID_FAIL); + else + { + sound_play(SOUND_ABYSS); + sound_play(SOUND_ABYSS_SUCCESS); + RoomType type = g_game->room->roomType; + if (type == ROOM_CHALLENGE || type == ROOM_BOSSRUSH) g_game->ambush.StartChallenge(); + } + } + use_animate(use); +} + +// Flip: Tainted Lazarus trades places with his other form (both blink in with Birthright), then outside the Genesis +// room every pedestal of the room shows its other item. A car battery's second use flips nothing. +void flip_use(ItemUse& use) +{ + Entity_Player& player = use.player; + uint32_t flags = use.request.flags; + bool isLazarus = player.playerType == PLAYER_LAZARUS_B || player.playerType == PLAYER_LAZARUS2_B; + + Entity_Player* twin = player.twin_get(); + Entity_Player* other = twin ? twin : player.backupPlayer; + if (player.isValid && !player.isCoopGhost && isLazarus && !(flags & USE_CARBATTERY) && other) + { + sound_play(other->playerType == PLAYER_LAZARUS2_B ? SOUND_LAZARUS_FLIP_DEAD : SOUND_LAZARUS_FLIP_ALIVE); + other->isControlsEnabled = false; + g_game->playerManager.replace_player(&player, other); + poof_spawn(player.pos)->Update(); + player.SyncConsumables(other, UINT32_MAX); + other->PlayExtraAnimation("Sad"); + other->isControlsEnabled = true; + other->controlsCooldown = 1; + other->entityCollisionClass = ENTCOLL_ALL; + if (twin) + { + player.PlayExtraAnimation("Sad"); + player.controlsCooldown = 1; + poof_spawn(other->pos)->Update(); + player.entityCollisionClass = ENTCOLL_NONE; + use.isLuaAnimationAllowed = false; + } + } + if ((flags & (USE_OWNED | USE_CARBATTERY)) != USE_OWNED) return; + if (isLazarus && g_game->currentRoomIdx == ROOM_GENESIS_IDX) + { + use.result.isDischarge = false; + return; + } + + g_game->itemPool.ResetRoomBlacklist(); + RNG& rng = player.GetCollectibleRNG(COLLECTIBLE_FLIP); + for (Entity* entity : entity_query(ENTITY_PICKUP, PICKUP_COLLECTIBLE)) + { + if (entity->isDead || !static_cast(entity)->TryFlip(&player, rng.Next())) continue; + g_game->Spawn({entity->pos, {}, nullptr, 0, ENTITY_EFFECT, EFFECT_POOF01, Random()}); + sound_play(SOUND_FLIP_POOF); + } + if (use.isLuaAnimationAllowed) player.AnimateCollectible(use.id, "UseItem", "PlayerPickupSparkle"); +} + +// 005b3990 The items Lemegeton may summon: every item but the passives, actives and familiars not tagged summonable. +static bool is_summonable(ItemConfig_Item& item) +{ + bool isWispKind = item.type == ITEM_PASSIVE || item.type == ITEM_ACTIVE || item.type == ITEM_FAMILIAR; + return !isWispKind || item.HasTags(TAG_SUMMONABLE); +} + +// Lemegeton: a summonable item from the room's pool one time in four, else from a weighted pool, joins the player as +// an item wisp, with its name shown. +void lemegeton_use(ItemUse& use) +{ + Entity_Player& player = use.player; + Game& game = *g_game; + use_animate(use); + + std::vector& filters = g_manager->itemConfig.availabilityFilters; + filters.push_back(is_summonable); + RNG& rng = player.GetCollectibleRNG(COLLECTIBLE_LEMEGETON); + int collectible = 0; + if (rng.RandomInt(LEMEGETON_ROOM_POOL_CHANCE) == 0) + collectible = game.itemPool.GetSeededCollectible(rng.Next(), true, *game.room->descriptor); + else + { + WeightedOutcomePicker picker; + for (PoolWeight each : game.IsGreedMode() ? std::span(LEMEGETON_GREED_POOLS) + : std::span(LEMEGETON_POOLS)) + picker.AddOutcomeWeight(each.pool, each.weight); + int pool = picker.PickOutcome(rng_make(rng.Next(), LEMEGETON_PICK_SHIFT)); + collectible = game.itemPool.GetCollectible((ItemPoolType)pool, rng.Next(), 0, COLLECTIBLE_BROTHER_BOBBY, 0); + } + if (game.deathmatchManager.is_active()) + reconstruction_missing("Lemegeton in Entity_Player::UseActiveItem 005b39d0 (the deathmatch's redraws)"); + filters.pop_back(); + + player.AddItemWisp(collectible, player.pos, true); + if (ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(collectible)) game.hud.ShowItemText(&player, item); + sound_play(SOUND_DEVILROOM_DEAL); +} + +// 005c96f0 Adds an item wisp of a collectible on Lemegeton's ring (or Book of Virtues' Lemegeton ring): a full ring +// passes it on to the next unless the layer is fixed, and a ring still full loses its least important wisp. +Entity_Familiar* Entity_Player::AddItemWisp(int collectibleId, Vector position, bool isAdjustOrbitLayer) +{ + ItemConfig& config = g_manager->itemConfig; + WispEntry* own = config.wisp_config_get(HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES) ? LEMEGETON_VIRTUES_WISP + : COLLECTIBLE_LEMEGETON); + int ring = own->layer; + if (ring >= 0) + { + std::array weakest{}; + std::array lowestPriority = {WISP_PRIORITY_NONE, WISP_PRIORITY_NONE, WISP_PRIORITY_NONE}; + std::array counts{}; + for (Entity* entity : g_game->room->GetEntities()->updateEL) + { + auto* wisp = entity && entity->type == ENTITY_FAMILIAR ? static_cast(entity) : nullptr; + bool isWisp = wisp && (wisp->variant == Entity_Familiar::WISP || wisp->variant == Entity_Familiar::ITEM_WISP); + if (!isWisp || wisp->player != this) continue; + + int wispItem = wisp->variant == Entity_Familiar::ITEM_WISP ? wisp->wispCollectibleType : wisp->subtype; + int layer = wisp->orbitLayer - WISP_RING_FIRST_LAYER; + if (layer < 0 || layer >= 3) continue; + int priority = config.wisp_config_get(wispItem)->priority; + if (wisp->variant == Entity_Familiar::WISP || priority < lowestPriority[layer]) + { + lowestPriority[layer] = priority; + weakest[layer] = wisp; + } + counts[layer]++; + } + for (int i = 0; isAdjustOrbitLayer && i < 3 && counts[ring] >= WISP_RING_CAPACITY[ring]; i++) + ring = (ring + 1) % 3; + if (counts[ring] >= WISP_RING_CAPACITY[ring] && weakest[ring]) weakest[ring]->Remove(); + } + + uint32_t seed = GetCollectibleRNG(COLLECTIBLE_LEMEGETON).Next(); + auto* wisp = static_cast( + g_game->Spawn({position, {}, this, collectibleId, ENTITY_FAMILIAR, Entity_Familiar::ITEM_WISP, seed})); + if (isAdjustOrbitLayer && ring >= 0) wisp->AddToOrbit(ring + WISP_RING_FIRST_LAYER); + wisp->Update(); + return wisp; +} + +// The Tainted Jacob part of update_effects 00794e50: when Jacob's curse runs down to its last 10 frames, Dark Esau +// (again) climbs out of a hole somewhere in the room, held off while Jacob cannot act. +void tainted_frame_update(Entity_Player& player) +{ + if (player.playerType != PLAYER_JACOB_B) return; + if (g_game->challenge == CHALLENGE_RED_REDEMPTION) + reconstruction_missing("Entity_Player::update_effects 00794e50 (Red Redemption's Dark Esau waves)"); + + TemporaryEffect* curse = player.temporaryEffects.GetNullEffect(NULLITEM_JACOBS_CURSE); + if (!curse || curse->cooldown > DARK_ESAU_CALL_FRAMES) return; + if (!player.isControlsEnabled) + { + curse->cooldown = DARK_ESAU_CALL_FRAMES; + return; + } + + player.temporaryEffects.RemoveNullEffect(NULLITEM_JACOBS_CURSE, -1); + if (player.darkEsau) player.darkEsau->Remove(); + Vector spot = room_pickup_position_random(true, false); + Entity* esau = g_game->Spawn({spot, {}, &player, 0, ENTITY_DARK_ESAU, 0, Random()}); + player.darkEsau = esau; + esau->Update(); +} + +// 004361d0 Keeps the player unhurtable for at least this many frames. +void Entity_Player::SetMinDamageCooldown(int cooldown) +{ + damageCooldown = std::max(cooldown, damageCooldown); +} + +// 007d87a0 Leaves the player's body where it stood: an effect wearing its sprite (the ghost layer hidden) six frames +// into its death, kept as its astral projection body. +bool Entity_Player::spawn_ghost_corpse() +{ + Entity* corpse = g_game->Spawn({pos, {}, this, 0, ENTITY_EFFECT, EFFECT_DEVIL, Random()}); + ANM2& look = corpse->sprite; + look = sprite; + if (LayerState* ghost = look.GetLayer("ghost")) ghost->isVisible = false; + look.overlayAnimState.SetAnimationData(nullptr); + look.playbackSpeed = 1; + AnimationState& anim = look.animState; + bool isDying = anim.animData && look.GetAnimation() == "Death" && (!anim.IsLoopingAnimation() || anim.isPlaying); + if (!isDying && look.SetAnimation("Death")) + { + anim.Rewind(); + anim.isPlaying = true; + } + if (anim.animData) anim.SetFrameFloat(GHOST_CORPSE_FRAME); + corpse->AddEntityFlags(FLAG_DONT_OVERWRITE); + static_cast(corpse)->state = GHOST_CORPSE_STATE; + corpse->Update(); + astralProjectionBody = corpse; + return true; +} + +// Chains an entity with Anima Sola for a time, longer by the time left on a chain it already has. +static void anima_chain_spawn(Entity_Player& player, AnimaChain chain) +{ + uint32_t seed = player.GetCollectibleRNG(COLLECTIBLE_ANIMA_SOLA).Next(); + auto* effect = static_cast( + g_game->Spawn({chain.position, {}, &player, 0, ENTITY_EFFECT, EFFECT_ANIMA_CHAIN, seed})); + effect->target = chain.target; + effect->SetTimeout(chain.duration + (chain.existing ? chain.existing->timeout : 0)); + effect->Update(); +} + +// Anima Sola: the nearest enemy (Jacob's Dark Esau first, enemies already chained last) is chained down for 150 frames +// (200 with Tainted Jacob's Birthright, half in a deathmatch), a split Dark Esau with both halves. With nothing to +// chain, Dark Esau comes at once and the charge stays. +void anima_sola_use(ItemUse& use) +{ + Entity_Player& player = use.player; + use_animate(use); + + std::vector candidates; + std::map chains; + for (Entity* entity : g_game->room->GetEntities()->updateEL) + { + if (entity == &player) continue; + if (entity->IsActiveEnemy(DEAD_EXCLUDED) && entity->entityCollisionClass != ENTCOLL_NONE && + !entity->HasEntityFlags(FLAG_FRIENDLY)) + { + candidates.push_back(entity); + continue; + } + if (entity->type != ENTITY_EFFECT || entity->variant != EFFECT_ANIMA_CHAIN || !entity->target) continue; + auto* chain = static_cast(entity); + Entity_Effect*& longest = chains[chain->target]; + if (!longest || chain->timeout > longest->timeout) longest = chain; + } + + Entity* chosen = nullptr; + float best = ANIMA_REACH_NONE; + for (Entity* candidate : candidates) + { + bool isOwnEsau = candidate->type == ENTITY_DARK_ESAU && candidate->spawnerEntity == &player; + float score = isOwnEsau ? -1 : vector_length_squared(vector_sub(candidate->pos, player.pos)); + if (chains.contains(candidate)) score += ANIMA_CHAINED_PENALTY; + if (score >= best) continue; + best = score; + chosen = candidate; + if (score < 0) break; + } + if (!chosen) + { + if (use.request.flags & USE_CARBATTERY) return; + if (TemporaryEffect* curse = player.temporaryEffects.GetNullEffect(NULLITEM_JACOBS_CURSE)) + curse->cooldown = DARK_ESAU_CALL_FRAMES; + use.result.isDischarge = false; + return; + } + + bool isJacob = player.playerType == PLAYER_JACOB_B || player.playerType == PLAYER_JACOB2_B; + int duration = isJacob && player.HasCollectible(COLLECTIBLE_BIRTHRIGHT) ? ANIMA_FRAMES_BIRTHRIGHT : ANIMA_FRAMES; + if (g_game->deathmatchManager.is_active()) duration /= 2; + auto chained = [&](Entity* entity) { return chains.contains(entity) ? chains[entity] : nullptr; }; + + Vector position = chosen->pos; + if (chosen->type == ENTITY_DARK_ESAU) + { + Entity* other = chosen->parent && chosen->parent->IsEnemy() ? (Entity*)chosen->parent : (Entity*)chosen->child; + Entity* partner = other ? other->to_npc_or_coop_player() : nullptr; + if (partner) + { + Vector middle = vector_scale(vector_add(chosen->pos, partner->pos), 0.5f); + Vector apart = vector_scale(vector_normalized(vector_sub(chosen->pos, partner->pos)), ANIMA_PAIR_OFFSET); + position = vector_add(middle, apart); + anima_chain_spawn(player, {vector_sub(middle, apart), partner, chained(partner), duration}); + } + } + anima_chain_spawn(player, {position, chosen, chained(chosen), duration}); + if (player.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES) && use.isWispAllowed) + if (Entity_Familiar* wisp = player.AddWisp(COLLECTIBLE_ANIMA_SOLA, player.pos, false, true)) + { + wisp->parent = chosen; + wisp->Update(); + } +} + +// The Anima Sola part of 00791a40 (ControlActiveItem): pressing the item again breaks the nearest chain the player +// cast. Whether one broke, which spends the press. +bool anima_chain_recall(Entity_Player& player) +{ + Entity* nearest = nullptr; + float best = ANIMA_REACH_NONE; + for (Entity* chain : entity_query(ENTITY_EFFECT, EFFECT_ANIMA_CHAIN)) + { + if (chain->subtype != 0 || chain->spawnerEntity != &player) continue; + float distance = vector_length_squared(vector_sub(player.pos, chain->pos)); + if (distance >= best) continue; + best = distance; + nearest = chain; + } + if (nearest) nearest->isDead = true; + return nearest; +} + +// The Anima Sola chain part of 005cdb20 (Init): the chain's anchor shows only its head, its three pegs only their link. +void anima_chain_init(Entity_Effect& chain) +{ + chain.state = 0; + chain.sprite.Play("Idle"); + if (chain.subtype == ANIMA_CHAIN_HEAD) chain.isVisible = false; + chain.sprite.GetLayer(chain.subtype == ANIMA_CHAIN_HEAD ? 1 : 0)->isVisible = false; +} + +// The head's first frame: three pegs around the target (80 pixels plus its size out, at thirds of a turn from a random +// start), with the trap's sound. +static void anima_chain_pegs_spawn(Entity_Effect& chain) +{ + chain.targetPosition = chain.pos; + float reach = ANIMA_PEG_REACH + (chain.target ? chain.target->size : 0); + float start = random_unit() * ANIMA_FULL_TURN; + for (int i = 0; i < ANIMA_PEG_COUNT; i++) + { + uint32_t seed = Random(); + Vector at = vector_add(chain.pos, vector_scale(vector_from_angle((float)i * ANIMA_PEG_TURN + start), reach)); + auto* peg = static_cast( + g_game->Spawn({at, {}, chain.spawnerEntity, ANIMA_CHAIN_PEG, ENTITY_EFFECT, EFFECT_ANIMA_CHAIN, seed})); + peg->parent = &chain; + peg->minRadius = 0; + peg->targetPosition = peg->pos; + peg->Update(); + } + chain.posOffset.y = ANIMA_HEAD_LIFT; + sound_play(SOUND_ANIMA_TRAP); +} + +// The head holding its target: it rides on it, shakes the screen when it shows, holds an enemy still (Dark Esau goes +// into his chained state) and slows it, blinking red ever faster as its time runs out. A lost target breaks it. +static EffectUpdateEnd anima_chain_head_update(Entity_Effect& chain) +{ + Entity* target = chain.target; + if (!target || chain.isDead) + { + sound_play(SOUND_ANIMA_BREAK); + chain.Remove(); + return EFFECT_UPDATE_RETURN; + } + chain.velocity = vector_sub(target->pos, chain.pos); + chain.renderDepthOffset = ANIMA_HEAD_DEPTH; + if (chain.updateTime < ANIMA_SHOW_FRAMES) return EFFECT_UPDATE_FINISH; + + if (!chain.isVisible) + { + chain.isVisible = true; + game_shake_screen(ANIMA_SHAKE); + } + if (target->type != ENTITY_DARK_ESAU) + { + if (!target->isDead) static_cast(target)->hold_set(ANIMA_HOLD_FRAMES, {}); + } + else if (auto* esau = static_cast(target->to_npc_or_coop_player()); esau && !esau->isDead && + esau->state != NPC_STATE_APPEAR && + esau->state != NPC_STATE_DEATH) + { + esau->targetPosition = {}; + esau->state = NPC_STATE_SUICIDE; + esau->entityRef = &chain; + esau->entityCollisionClass = ENTCOLL_ALL; + } + target->velocity = vector_scale(target->velocity, npc_friction_scaled(ANIMA_SLOW, target->speedMultiplier)); + if (chain.timeout <= 0 || chain.timeout > ANIMA_BLINK_START) return EFFECT_UPDATE_FINISH; + + int interval = chain.timeout >= ANIMA_BLINK_SLOW_END ? ANIMA_BLINK_SLOW + : chain.timeout >= ANIMA_BLINK_FAST_END ? ANIMA_BLINK_MID + : ANIMA_BLINK_FAST; + if (chain.IsFrame(interval, 0)) chain.SetColor(ANIMA_BLINK_COLOR, ANIMA_BLINK_FRAMES, COLOR_PRIORITY_DEFAULT, false, true); + return EFFECT_UPDATE_FINISH; +} + +// A peg: its link reaches out toward the head over its first 15 frames and tugs the target toward the peg. A peg left +// without its head breaks into gibs along its link and goes. +static EffectUpdateEnd anima_chain_peg_update(Entity_Effect& peg) +{ + Entity* head = peg.parent; + if (!head) + { + Vector link = vector_sub(peg.targetPosition, peg.pos); + float length = vector_length(link); + if (length > 0) link = vector_scale(link, 1 / length); + for (float along = 0; along <= length; along += ANIMA_GIB_SPACING) + { + uint32_t seed = Random(); + Vector at = vector_add(peg.pos, vector_scale(link, along)); + Vector fling = vector_scale(random_direction(), random_unit() * ANIMA_GIB_SPEED_RANGE + ANIMA_GIB_SPEED); + Entity* gib = g_game->Spawn({at, fling, nullptr, 0, ENTITY_EFFECT, EFFECT_CHAIN_GIB, seed}); + gib->sprite.color = ANIMA_GIB_COLOR; + gib->Update(); + } + peg.Remove(); + return EFFECT_UPDATE_FINISH; + } + + peg.minRadius = lerp_clamped(peg.updateTime, 0, ANIMA_REACH_FRAMES, 0, 1); + peg.targetPosition = vector_add(peg.pos, vector_scale(vector_sub(head->pos, peg.pos), peg.minRadius)); + if (head->isVisible && head->target) + head->target->AddVelocity(vector_scale(vector_sub(peg.pos, head->target->pos), ANIMA_TUG), false); + return EFFECT_UPDATE_FINISH; +} + +// The Anima Sola chain part of 005d4380 (Update): the head's first frame sets its pegs, then the head holds its target +// and the pegs pull at it. +EffectUpdateEnd anima_chain_update(Entity_Effect& chain) +{ + if (chain.state == 0) + { + if (chain.subtype == ANIMA_CHAIN_HEAD) anima_chain_pegs_spawn(chain); + chain.state = 1; + } + return chain.subtype == ANIMA_CHAIN_HEAD ? anima_chain_head_update(chain) : anima_chain_peg_update(chain); +} diff --git a/src/tainted_characters.h b/src/tainted_characters.h new file mode 100644 index 0000000..fde0045 --- /dev/null +++ b/src/tainted_characters.h @@ -0,0 +1,21 @@ +#pragma once + +#include "active_items.h" +#include "entity_effect.h" + +struct Entity_NPC; + +// The second half of the tainted characters: the pocket actives the active item dispatch runs for Abyss (Tainted +// Apollyon), Flip (Tainted Lazarus), Lemegeton (Tainted Bethany) and Anima Sola (Tainted Jacob), their frame's +// character part, and Tainted Jacob's Dark Esau. +void abyss_use(ItemUse& use); +void flip_use(ItemUse& use); +void lemegeton_use(ItemUse& use); +void anima_sola_use(ItemUse& use); +void tainted_frame_update(Entity_Player& player); +bool anima_chain_recall(Entity_Player& player); +void anima_chain_init(Entity_Effect& chain); +EffectUpdateEnd anima_chain_update(Entity_Effect& chain); + +void locust_spawn(Entity_Player& player, int collectibleType, Vector position); +void npc_dark_esau_update(Entity_NPC& npc); diff --git a/src/video_player.cpp b/src/video_player.cpp index 6b015ca..6378b28 100644 --- a/src/video_player.cpp +++ b/src/video_player.cpp @@ -1,19 +1,402 @@ #include "video_player.h" +#include "data.h" +#include "fx_layers.h" +#include "gl.h" +#include "kage_sound.h" +#include "log.h" #include "manager.h" #include "platform.h" +#include +#include +#include +#include +#include +#include +#include -// 009f2ee0 Opens an .ogv (or a mod's replacement) to play at a volume. With no decoder it only logs the video. -void VideoPlayer::play(std::string_view fileName, float volume) +// Xiph's libraries replace the copies linked into the exe: Ogg (00aabed0, 00aac110, 00aac240, 00aac3e0, 00aac5c0) +// and (00aac8f0, 00aac980, 00ab6ee0), Vorbis (00aa9c20, 00aaa150, 00aacf20, 00aad330, 00aad3b0) +// and Theora (00ade980, 00ade9f0, 00adebd0, 00ae2060). +constexpr const char* IMAGE_NAME = "VideoPlayerImage"; +constexpr int READ_SIZE = 4096; +// Theora and Vorbis both open with three header packets. +constexpr int HEADER_COUNT = 3; +// The seconds of sound kept queued ahead of the device. +constexpr double AUDIO_AHEAD = 0.5; +constexpr double NS_PER_SECOND = 1e9; +constexpr int RGBA_CHANNELS = 4; + +// BT.601 studio range YCbCr to RGB, the factors in 16.16 fixed point. +constexpr int LUMA_BLACK = 16; +constexpr int CHROMA_ZERO = 128; +constexpr int FIXED_SHIFT = 16; +constexpr int FIXED_HALF = 1 << (FIXED_SHIFT - 1); +constexpr int LUMA_SCALE = 76309; +constexpr int CR_TO_RED = 104597; +constexpr int CB_TO_GREEN = 25675; +constexpr int CR_TO_GREEN = 53279; +constexpr int CB_TO_BLUE = 132201; + +// An open .ogv: theoraplayer's VideoClip_Theora with KAGE's file data source and audio interface. It holds the Ogg +// pages read so far, the Theora decoder with the frame it decoded last, and the Vorbis decoder feeding a stream on the +// game's audio device. Frames are decoded on the main thread when the clip's time reaches them, not ahead on threads. +// Its time is the sound the device took, run on by the clock between the device's reads, or the clock alone. +struct VideoClip { - file = g_manager->modManager.TryRedirectPath(fileName); - log_printf(LOG_INFO, "VideoPlayer: no decoder for %s (volume %.2f), skipped\n", file.c_str(), volume); + std::ifstream file; + std::vector samples; + std::vector texels; + ogg_sync_state sync = {}; + ogg_stream_state theoraStream = {}; + ogg_stream_state vorbisStream = {}; + th_comment theoraComment = {}; + th_info theoraInfo = {}; + th_dec_ctx* theoraDecoder = nullptr; + th_setup_info* theoraSetup = nullptr; + vorbis_block vorbisBlock = {}; + vorbis_comment vorbisComment = {}; + vorbis_dsp_state vorbisDsp = {}; + vorbis_info vorbisInfo = {}; + SDL_AudioStream* audio = nullptr; + double frameDuration = 0; + double frameTime = 0; + double playedTime = 0; + float volume = 1; + uint64_t audioFrames = 0; + uint64_t startTime = 0; + uint64_t syncTime = 0; + int theoraHeaders = 0; + int vorbisHeaders = 0; + bool hasFrame = false; + bool isEnd = false; + bool isFrameShown = false; + + VideoClip(); + ~VideoClip(); + bool page_next(ogg_page& page); + bool page_read(); + bool headers_load(); + void start(); + double time_get(); + bool frame_decode(); + void frame_upload(KAGE::Graphics::ImageBase& image); + bool audio_decode(); + void audio_feed(); +}; + +// Readies the page reader and the header records. +VideoClip::VideoClip() +{ + ogg_sync_init(&sync); + th_comment_init(&theoraComment); + th_info_init(&theoraInfo); + vorbis_comment_init(&vorbisComment); + vorbis_info_init(&vorbisInfo); } -// 00a62880 Closes the clip. -void VideoPlayer::unload() { file.clear(); } +// Stops the sound and frees the decoders. +VideoClip::~VideoClip() +{ + if (audio) + { + SDL_DestroyAudioStream(audio); + vorbis_block_clear(&vorbisBlock); + vorbis_dsp_clear(&vorbisDsp); + } + th_decode_free(theoraDecoder); + th_setup_free(theoraSetup); + ogg_stream_clear(&theoraStream); + ogg_stream_clear(&vorbisStream); + th_comment_clear(&theoraComment); + th_info_clear(&theoraInfo); + vorbis_comment_clear(&vorbisComment); + vorbis_info_clear(&vorbisInfo); + ogg_sync_clear(&sync); +} -// 00a62b10 Draws the clip's current frame at an offset. There is none without a decoder. -void VideoPlayer::render(Vector) {} +// Takes the next page, reading more of the file as needed. False at its end. +bool VideoClip::page_next(ogg_page& page) +{ + while (ogg_sync_pageout(&sync, &page) != 1) + { + char* buffer = ogg_sync_buffer(&sync, READ_SIZE); + file.read(buffer, READ_SIZE); + if (file.gcount() <= 0) return false; + ogg_sync_wrote(&sync, (long)file.gcount()); + } + return true; +} -// Whether the clip played to its end, or none is open. Without a decoder none ever is. -bool VideoPlayer::is_finished() { return true; } +// Hands the next page to the stream it belongs to. False at the file's end. +bool VideoClip::page_read() +{ + ogg_page page; + if (!page_next(page)) return false; + + ogg_stream_pagein(&theoraStream, &page); + ogg_stream_pagein(&vorbisStream, &page); + return true; +} + +// (00a8e530) Finds the Theora and Vorbis streams on the starting pages, skipping any other, then reads their header +// packets. False without a Theora stream or with a broken header. +bool VideoClip::headers_load() +{ + ogg_page page; + ogg_packet packet; + bool isPage = page_next(page); + + for (; isPage && ogg_page_bos(&page); isPage = page_next(page)) + { + ogg_stream_state stream; + ogg_stream_init(&stream, ogg_page_serialno(&page)); + ogg_stream_pagein(&stream, &page); + ogg_stream_packetout(&stream, &packet); + + if (!theoraHeaders && th_decode_headerin(&theoraInfo, &theoraComment, &theoraSetup, &packet) > 0) + { + theoraStream = stream; + theoraHeaders = 1; + } + else if (!vorbisHeaders && !vorbis_synthesis_headerin(&vorbisInfo, &vorbisComment, &packet)) + { + vorbisStream = stream; + vorbisHeaders = 1; + } + else ogg_stream_clear(&stream); + } + if (!isPage || !theoraHeaders) return false; + ogg_stream_pagein(&theoraStream, &page); + ogg_stream_pagein(&vorbisStream, &page); + + while (theoraHeaders < HEADER_COUNT || (vorbisHeaders && vorbisHeaders < HEADER_COUNT)) + { + if (theoraHeaders < HEADER_COUNT && ogg_stream_packetout(&theoraStream, &packet) > 0) + { + if (th_decode_headerin(&theoraInfo, &theoraComment, &theoraSetup, &packet) <= 0) return false; + theoraHeaders++; + } + else if (vorbisHeaders && vorbisHeaders < HEADER_COUNT && ogg_stream_packetout(&vorbisStream, &packet) > 0) + { + if (vorbis_synthesis_headerin(&vorbisInfo, &vorbisComment, &packet)) return false; + vorbisHeaders++; + } + else if (!page_read()) return false; + } + + theoraDecoder = th_decode_alloc(&theoraInfo, theoraSetup); + frameDuration = (double)theoraInfo.fps_denominator / theoraInfo.fps_numerator; + return theoraDecoder != nullptr; +} + +// Starts the clock and opens a stream for the sound on the game's audio device, silent when the game is muted. +// Without a device or a sound track the clip runs on the clock alone. +void VideoClip::start() +{ + SDL_AudioStream* output = KAGE::Sound::manager.output; + + startTime = GetTimeNs(); + syncTime = startTime; + if (vorbisHeaders < HEADER_COUNT || !output) return; + + SDL_AudioSpec spec = {SDL_AUDIO_F32, vorbisInfo.channels, (int)vorbisInfo.rate}; + audio = SDL_OpenAudioDeviceStream(SDL_GetAudioStreamDevice(output), &spec, nullptr, nullptr); + if (!audio) return; + if (vorbis_synthesis_init(&vorbisDsp, &vorbisInfo)) + { + SDL_DestroyAudioStream(audio); + audio = nullptr; + return; + } + + vorbis_block_init(&vorbisDsp, &vorbisBlock); + if (KAGE::Sound::manager.isMuted) volume = 0; + SDL_ResumeAudioStreamDevice(audio); +} + +// The clip's time in seconds: the sound the device took, run on by the clock since that last moved. +double VideoClip::time_get() +{ + uint64_t now = GetTimeNs(); + if (!audio) return (double)(now - startTime) / NS_PER_SECOND; + + uint64_t queuedFrames = (uint64_t)SDL_GetAudioStreamQueued(audio) / (sizeof(float) * vorbisInfo.channels); + double played = (double)(audioFrames - queuedFrames) / (double)vorbisInfo.rate; + if (played != playedTime) + { + playedTime = played; + syncTime = now; + } + return playedTime + (double)(now - syncTime) / NS_PER_SECOND; +} + +// Decodes the next video packet into the decoder's frame, with the time it shows at. False at the video's end. +bool VideoClip::frame_decode() +{ + ogg_packet packet; + ogg_int64_t granule = 0; + + do + { + while (ogg_stream_packetout(&theoraStream, &packet) <= 0) + { + if (page_read()) continue; + isEnd = true; + return false; + } + } while (th_decode_packetin(theoraDecoder, &packet, &granule) < 0); + + frameTime = (double)th_granule_frame(theoraDecoder, granule) * frameDuration; + hasFrame = true; + return true; +} + +// A 16.16 fixed point channel as a byte. +static uint8_t channel_get(int value) +{ + return (uint8_t)std::clamp(value >> FIXED_SHIFT, 0, UINT8_MAX); +} + +// Converts the decoded frame, its padding included, to opaque RGBA and uploads it to the render target. +void VideoClip::frame_upload(KAGE::Graphics::ImageBase& image) +{ + th_ycbcr_buffer planes; + th_decode_ycbcr_out(theoraDecoder, planes); + + int height = planes[0].height; + int width = planes[0].width; + int xShift = planes[1].width < width; + int yShift = planes[1].height < height; + texels.resize((size_t)width * height * RGBA_CHANNELS); + uint8_t* texel = texels.data(); + + for (int y = 0; y < height; y++) + { + const uint8_t* luma = planes[0].data + (ptrdiff_t)y * planes[0].stride; + const uint8_t* blue = planes[1].data + (ptrdiff_t)(y >> yShift) * planes[1].stride; + const uint8_t* red = planes[2].data + (ptrdiff_t)(y >> yShift) * planes[2].stride; + for (int x = 0; x < width; x++) + { + int base = (luma[x] - LUMA_BLACK) * LUMA_SCALE + FIXED_HALF; + int cb = blue[x >> xShift] - CHROMA_ZERO; + int cr = red[x >> xShift] - CHROMA_ZERO; + texel[0] = channel_get(base + CR_TO_RED * cr); + texel[1] = channel_get(base - CB_TO_GREEN * cb - CR_TO_GREEN * cr); + texel[2] = channel_get(base + CB_TO_BLUE * cb); + texel[3] = UINT8_MAX; + texel += RGBA_CHANNELS; + } + } + + gl.BindTexture(GL_TEXTURE_2D, image.texture); + gl.TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, texels.data()); + hasFrame = false; + isFrameShown = true; +} + +// Queues the sound decoded next at the clip's volume, clamped as OpenAL's 16-bit buffers took it, or decodes another +// packet when none is left. False at the sound's end. +bool VideoClip::audio_decode() +{ + float** pcm = nullptr; + int frames = vorbis_synthesis_pcmout(&vorbisDsp, &pcm); + int channels = vorbisInfo.channels; + + if (frames > 0) + { + samples.resize((size_t)frames * channels); + for (int frame = 0; frame < frames; frame++) + for (int channel = 0; channel < channels; channel++) + samples[(size_t)frame * channels + channel] = std::clamp(pcm[channel][frame] * volume, -1.0f, 1.0f); + SDL_PutAudioStreamData(audio, samples.data(), (int)(samples.size() * sizeof(float))); + vorbis_synthesis_read(&vorbisDsp, frames); + audioFrames += (uint64_t)frames; + return true; + } + + ogg_packet packet; + while (ogg_stream_packetout(&vorbisStream, &packet) <= 0) + if (!page_read()) return false; + if (!vorbis_synthesis(&vorbisBlock, &packet)) vorbis_synthesis_blockin(&vorbisDsp, &vorbisBlock); + return true; +} + +// Keeps half a second of sound queued ahead of the device. +void VideoClip::audio_feed() +{ + if (!audio) return; + + double frameSize = (double)sizeof(float) * vorbisInfo.channels; + while (SDL_GetAudioStreamQueued(audio) / frameSize / (double)vorbisInfo.rate < AUDIO_AHEAD && audio_decode()) {} +} + +VideoPlayer::~VideoPlayer() = default; + +// 00a62910 (00a8ab60) Opens the .ogv at a path as the clip, closing the one before, with a render target of its +// frame's size filtered linearly. Its texels start cleared, as the original clears it once made. +// False when the file is missing or holds no Theora video. +bool VideoPlayer::load(const std::string& path) +{ + unload(); + + auto video = std::make_unique(); + video->file.open(resource_path(path), std::ios::binary); + if (!video->file || !video->headers_load()) + { + log_printf(LOG_INFO, "ERROR: Failed creating video clip: %s\n", path.c_str()); + return false; + } + + KAGE::Graphics::RenderTargetDesc desc; + desc.name = IMAGE_NAME; + desc.width = (int)video->theoraInfo.frame_width; + desc.height = (int)video->theoraInfo.frame_height; + image = KAGE::Graphics::manager.render_target_create(desc); + image->filter_set(1, 1); + clip = std::move(video); + return true; +} + +// 009f2ee0 Opens the .ogv at a path (or a mod's replacement) and plays it from its start, its sound at a volume +// clamped to 0 to 1. Nothing plays when it does not open. +void VideoPlayer::play(std::string_view fileName, float volume) +{ + load(g_manager->modManager.TryRedirectPath(fileName)); + if (!clip) return; + + clip->volume = std::clamp(volume, 0.0f, 1.0f); + clip->start(); + isPlaying = true; +} + +// 00a62880 (00a8b190) Closes the clip and lets its render target go. +void VideoPlayer::unload() +{ + clip.reset(); + image.reset(); + isPlaying = false; +} + +// 00a62b10 (00aaa450, 00aaaae0) Draws the clip's frame at an offset. Frames already over by the clip's time are decoded +// past, keeping the last, and the next is uploaded once its time comes, the first at once. +void VideoPlayer::render(Vector offset) +{ + if (!clip) return; + + VideoClip& video = *clip; + double time = video.time_get(); + + video.audio_feed(); + while ((!video.hasFrame || video.frameTime + video.frameDuration < time) && video.frame_decode()) {} + if (video.hasFrame && (time >= video.frameTime || !video.isFrameShown)) video.frame_upload(*image); + image->Render(offset, kcolor_rgba(1, 1, 1, 1)); +} + +// Whether the clip showed its last frame, or none is open. +bool VideoPlayer::is_finished() { return !clip || (clip->isEnd && !clip->hasFrame); } + +// The clip's coded frame width, padding included, or 0 without one. +int VideoPlayer::width_get() { return clip ? (int)clip->theoraInfo.frame_width : 0; } + +// The clip's coded frame height, padding included, or 0 without one. +int VideoPlayer::height_get() { return clip ? (int)clip->theoraInfo.frame_height : 0; } diff --git a/src/video_player.h b/src/video_player.h index 22701f2..8d578e6 100644 --- a/src/video_player.h +++ b/src/video_player.h @@ -1,18 +1,28 @@ #pragma once #include "classes.h" +#include "kage_graphics.h" +#include #include #include -// Copies, assignment and destruction are the defaults. -// The cutscene player's video clip. The game carries no Theora decoder yet, so a clip never opens: play logs the -// video asked for, and the clip counts as finished at once, as a video the original fails to open does. +struct VideoClip; + +// Copies and assignment are deleted. Destruction is the default, out of line for the clip. +// The cutscene player's video: the open .ogv clip and the render target its frames are uploaded to, drawn at the +// frame's full coded size. isPlaying holds once a clip started. struct VideoPlayer { - std::string file; + std::unique_ptr clip; + KAGE::Graphics::ImagePtr image; + bool isPlaying = false; + ~VideoPlayer(); + bool load(const std::string& path); void play(std::string_view fileName, float volume); void unload(); void render(Vector offset); bool is_finished(); + int width_get(); + int height_get(); }; diff --git a/src/weapon.cpp b/src/weapon.cpp index 9a44968..4ec6835 100644 --- a/src/weapon.cpp +++ b/src/weapon.cpp @@ -2,6 +2,9 @@ #include "weapon_lasers.h" #include "weapon_bombs.h" #include "weapon_knives.h" +#include "weapon_fetus.h" +#include "weapon_ludovico.h" +#include "weapon_rockets.h" #include "entity_familiar.h" #include "entity_player.h" #include "entity_tear.h" @@ -43,12 +46,13 @@ constexpr int SEEDED_VARIANT_SPEEDY = 2; constexpr int COLLECTIBLE_EYE_DROPS = 600; constexpr int COLLECTIBLE_KIDNEY_STONE_WEAPON = 440; -constexpr int COLLECTIBLE_ANALOG_STICK = 465; constexpr int COLLECTIBLE_TECHNOLOGY_2 = 152; constexpr int COLLECTIBLE_ISAACS_TEARS = 323; constexpr int TRINKET_TORN_CARD = 157; constexpr int BABY_SPIN = 8; constexpr int MARKED_TARGET = 30; +constexpr std::string_view C_SECTION_SUB_ANIM = "SubAnim"; +constexpr float C_SECTION_FRAME_PLAY = -1; constexpr int MARKED_OCCULT_TARGET = 153; // The items that react to each tear fired: Mom's Wig, Immaculate Heart, Bird's Eye, Ghost Pepper, Eye of Greed and Lead // Pencil. @@ -87,15 +91,17 @@ static Vector vector_scale(Vector v, float scale) { return vector_make(v.x * sca static bool is_zero(Vector v) { return v.x == 0 && v.y == 0; } -// 009f9020 Makes the weapon of a type for an owner through the type's maker, written for tears (009f9260), the -// lasers (weapon_laser_make), the knife and clubs (weapon_knife_make) and Dr. Fetus (weapon_bomb_make). +// 009f9020 Makes the weapon of a type for an owner through the type's maker: tears (009f9260), the lasers +// (weapon_laser_make), the knife and clubs (weapon_knife_make), Dr. Fetus (weapon_bomb_make), Epic Fetus +// (weapon_rocket_make), Ludovico (weapon_ludovico_make) and C Section (weapon_fetus_make). WeaponPtr weapon_create(WeaponType type, Entity* owner) { - Weapon* made = type == WEAPON_TEARS ? new Weapon_Tears() : weapon_laser_make(type); - if (!made) made = weapon_knife_make(type); - if (!made) made = weapon_bomb_make(type); - if (!made) - reconstruction_missing("Isaac::CreateWeapon 009f9020 (Epic Fetus, Ludovico, C Section and the rest)"); + Weapon* made = type == WEAPON_TEARS ? new Weapon_Tears() : nullptr; + for (auto make : {weapon_laser_make, weapon_knife_make, weapon_bomb_make, weapon_rocket_make, weapon_ludovico_make, + weapon_fetus_make}) + if (!made) made = make(type); + if (!made) reconstruction_missing("Isaac::CreateWeapon 009f9020 (Monstro's Lung, the Spirit Sword, the Urn of Souls, " + "the umbilical whip and the versus weapon)"); WeaponPtr weapon(made); @@ -582,10 +588,57 @@ bool Weapon::IsItemAnimFinished(int collectibleId) return isAllFinished; } -bool Weapon::is_c_section_anim_finished() { reconstruction_missing("Weapon::is_c_section_anim_finished 009f5510"); } -void Weapon::update_c_section_charge_anim(HeadCharge, const Vector&, float) +// The C Section costumes on the owning player's body. +static std::vector c_section_costumes_get(Entity_Player& player) { - reconstruction_missing("Weapon::update_c_section_charge_anim 009f52c0"); + std::vector costumes; + ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(COLLECTIBLE_C_SECTION); + for (PlayerCostumeMap& map : player.playerCostumeMap) + { + if (map.index < 0 || !map.isBodyLayer) continue; + CostumeSpriteDesc& costume = player.costumeSpriteDescs[map.index]; + if (costume.item == item) costumes.push_back(&costume); + } + return costumes; +} + +// 009f5510 Whether C Section's charge animation ended: no C Section costume on the owning player's body still plays +// a SubAnim overlay, or a familiar's item animation ended. +bool Weapon::is_c_section_anim_finished() +{ + if (!owner || !owner->is_player()) return IsItemAnimFinished(COLLECTIBLE_C_SECTION); + + for (CostumeSpriteDesc* costume : c_section_costumes_get(*owner->ToPlayer())) + { + AnimationState& overlay = costume->sprite.overlayAnimState; + if (overlay.isPlaying && overlay.animData && overlay.GetAnimation().starts_with(C_SECTION_SUB_ANIM)) return false; + } + return true; +} + +// 009f52c0 Shows C Section's charge on the owning player's body costumes: charging at a frame, fully charged or the +// throw (played afresh), kept on its frame below -1. A familiar's head charges as an item's does. +void Weapon::update_c_section_charge_anim(HeadCharge chargeType, const Vector& aim, float chargeFrame) +{ + if (!owner || !owner->is_player()) + return UpdateHeadChargeAnimation(COLLECTIBLE_C_SECTION, chargeType, aim, chargeFrame); + + std::string_view animName = chargeType == HEAD_CHARGE_CHARGING ? "SubAnim_Charge" + : chargeType == HEAD_CHARGE_CHARGED ? "SubAnim_Charged" + : chargeType == HEAD_CHARGE_SHOOT ? "SubAnim_Shoot" + : ""; + PlayMode mode = chargeType == HEAD_CHARGE_SHOOT ? PLAY_FORCED : PLAY_UNFORCED; + for (CostumeSpriteDesc* costume : c_section_costumes_get(*owner->ToPlayer())) + { + ANM2& sprite = costume->sprite; + if (chargeFrame >= 0) + { + if (sprite.SetOverlayAnimation(animName, SWITCH_KEEP_FRAME) && sprite.overlayAnimState.animData) + sprite.overlayAnimState.SetFrameFloat((float)(int)chargeFrame); + } + else if (chargeFrame >= C_SECTION_FRAME_PLAY) sprite.PlayOverlay(animName, mode); + else sprite.SetOverlayAnimation(animName, SWITCH_RESET); + } } // 00a0d870 Counts both eyes' fire delays down at the owner's speed, outside interpolation frames. diff --git a/src/weapon.h b/src/weapon.h index 25f071f..814e898 100644 --- a/src/weapon.h +++ b/src/weapon.h @@ -296,6 +296,7 @@ struct Weapon_Tears : Weapon }; WeaponPtr weapon_create(WeaponType type, Entity* owner); +Vector weapon_steer_aim(Entity_Player* player, Vector aim); void costume_item_anim_set(Entity_Player& player, ItemConfig_Item* item, std::string_view animName, int frame); void costume_item_frame_set(Entity_Player& player, ItemConfig_Item* item, std::string_view animName, int frame); int costume_item_frame_get(Entity_Player& player, ItemConfig_Item* item); diff --git a/src/weapon_fetus.cpp b/src/weapon_fetus.cpp new file mode 100644 index 0000000..12b5d99 --- /dev/null +++ b/src/weapon_fetus.cpp @@ -0,0 +1,130 @@ +#include "weapon_fetus.h" +#include "boss_ai.h" +#include "entity_player.h" +#include "entity_tear.h" +#include "item_config.h" +#include "log.h" +#include "manager.h" +#include "npc_ai.h" +#include +#include + +// C Section's charge (three fire delays, never quite none), its throw speed and spread, the fire delay a throw leaves, +// a familiar's blink, and the sideways overlay its costume plays. +constexpr float FETUS_CHARGE_DELAYS = 3; +constexpr float FETUS_CHARGE_MIN = 0.001f; +constexpr float FETUS_NO_CHARGE = -1000; +constexpr float FETUS_SHOT_SPEED = 1.25f; +constexpr float FETUS_THROW_SPEED = 10; +constexpr float FETUS_RANDOM_SPREAD = 50; +constexpr int FETUS_BLINK_BASE = 7; +constexpr float FETUS_BLINK_SHARE = -0.15f; +constexpr int FETUS_BLINK_MIN = 11; +constexpr float C_SECTION_FRAME_KEEP = -1; + +// 009f9020's maker for C Section's weapon (009f95d0), or none for the other types. +Weapon* weapon_fetus_make(WeaponType type) +{ + return type == WEAPON_FETUS ? new Weapon_Fetus() : nullptr; +} + +// 00a03f60 The charge a throw takes: three fire delays. +float Weapon_Fetus::GetMaxCharge() +{ + return std::max(maxFireDelay * FETUS_CHARGE_DELAYS, FETUS_CHARGE_MIN); +} + +// Marked's target (Weapon_Bombs::GetMarkedTargetVariant 009fa1b0). +int Weapon_Fetus::GetMarkedTargetVariant() +{ + return marked_target_variant(); +} + +// 009f6e60 +Entity_Tear* fire_fetus_tear(Weapon&, const FetusShot&) +{ + reconstruction_missing("fire_fetus_tear 009f6e60"); +} + +// Throws the fetuses of a full charge: the fire delay restarts at a third of the charge (a familiar blinks), the tear +// effects trigger, and one fetus goes per shot of the volley with the backward, mirrored and random ones, all at the +// aim plus the owner's movement. The C Section costumes on a player's body play its throw, a familiar shoots. +// The original's sideways fetuses mirror the throw on each axis instead of turning it: kept. +void Weapon_Fetus::release(const Vector& shootDirection, const Vector& aim, float maxCharge, float shotSpeed) +{ + fireDelay = maxCharge / FETUS_CHARGE_DELAYS; + if (!owner || !owner->is_player()) + SetBlinkTime(std::max(FETUS_BLINK_BASE - (int)(maxCharge * FETUS_BLINK_SHARE), FETUS_BLINK_MIN)); + TriggerTearEffects(aim, 1); + Vector from = get_owner_position(); + Vector throwVelocity = vector_add(vector_scale(aim, FETUS_THROW_SPEED), get_tear_movement_inheritance(aim)); + Weapon_MultiShotParams params = GetMultiShotParams(); + auto fire = [&](Vector position, Vector velocity) { + fire_fetus_tear(*this, {.position = position, .velocity = velocity, .source = owner})->Update(); + }; + + Vector v = throwVelocity; + if (params.isShootingBackwards) fire(from, vector_scale(vector_make(-v.x, -v.y), shotSpeed)); + if (params.isShootingSideways) + { + fire(from, vector_scale(vector_make(v.x, -v.y), shotSpeed)); + fire(from, vector_scale(vector_make(-v.x, v.y), shotSpeed)); + } + for (int i = 0; i < params.numRandomDirTears; i++) + { + float turn = (random_unit() * FETUS_RANDOM_SPREAD - FETUS_RANDOM_SPREAD / 2) * DEGREES_TO_RADIANS; + float c = std::cos(turn); + float s = std::sin(turn); + fire(from, vector_scale(vector_make(v.x * c - v.y * s, v.x * s + v.y * c), shotSpeed)); + } + // The original spreads the lanes as Tech X's rings do. + for (int i = 0; i < params.numTears; i++) + { + PosVel lane = Entity_Player::GetMultiShotPositionVelocity(i, WEAPON_TECH_X, v, shotSpeed, params); + fire(vector_add(from, lane.position), lane.velocity); + } + + update_c_section_charge_anim(HEAD_CHARGE_SHOOT, shootDirection, C_SECTION_FRAME_KEEP); +} + +// 00a036e0 C Section: while shooting the charge grows at the owner's speed (the head shows it, or its full charge), +// and the aim follows the shots. A full charge also releases itself. On release a full charge throws (release), a +// short one is lost, and the head goes back to charging from nothing. The body turns to the shots. +// The original also works out whether a Marked target or fixed aim leads, and leaves it unused. +void Weapon_Fetus::Fire(const Vector& shootDirection, bool isShooting, bool isInterpolated) +{ + Weapon::Fire(shootDirection, isShooting, isInterpolated); + Entity_Player* player = owner_player(); + float shotSpeed = (player ? player->shotSpeed : 1) * FETUS_SHOT_SPEED; + float maxCharge = GetMaxCharge(); + float releaseCharge = maxCharge; + if (owner && owner->is_player() && owner->ToPlayer()->peeBurstCooldown > 0) releaseCharge = std::max(maxCharge, 1.0f); + bool isCharging = isShooting && !(releaseCharge > FETUS_NO_CHARGE && charge >= releaseCharge); + + Vector aim = IsAxisAligned() ? vector_cardinal(direction) : vector_normalized(direction); + if (!isCharging) + { + if (!isInterpolated) + { + if (charge >= std::max(maxCharge, 1.0f)) release(shootDirection, aim, maxCharge, shotSpeed); + charge = 0; + if (is_c_section_anim_finished()) update_c_section_charge_anim(HEAD_CHARGE_CHARGING, shootDirection, 0); + } + if (is_c_section_anim_finished()) bodyDirection = shootDirection; + return; + } + + if (charge < maxCharge) + { + if (!isInterpolated) charge += owner ? owner->speedMultiplier : 1; + if (is_c_section_anim_finished()) + update_c_section_charge_anim(HEAD_CHARGE_CHARGING, shootDirection, charge / maxCharge * HEAD_CHARGE_FRAMES); + } + else update_c_section_charge_anim(HEAD_CHARGE_CHARGED, shootDirection, C_SECTION_FRAME_KEEP); + if (!isInterpolated) + { + SetBlinkTime(1); + direction = get_aim_direction(shootDirection); + } + bodyDirection = shootDirection; +} diff --git a/src/weapon_fetus.h b/src/weapon_fetus.h new file mode 100644 index 0000000..832696a --- /dev/null +++ b/src/weapon_fetus.h @@ -0,0 +1,29 @@ +#pragma once + +#include "weapon.h" + +// A fetus to fire (fire_fetus_tear's arguments): from a position at a velocity, the shooter, the FireTear flags and +// the damage multiplier. +struct FetusShot +{ + Vector position{}; + Vector velocity{}; + Entity* source = nullptr; + float damageMultiplier = 1; + uint32_t fireFlags = 0; +}; + +// Destruction (009f3260) is the base's. +// C Section's weapon: the shots charge the head (three fire delays), and on release a full charge throws fetuses, +// one per shot of the volley and the extra backward, sideways and random ones. +struct Weapon_Fetus : Weapon +{ + void Fire(const Vector& shootDirection, bool isShooting, bool isInterpolated) override; + float GetMaxCharge() override; + int GetMarkedTargetVariant() override; + + void release(const Vector& shootDirection, const Vector& aim, float maxCharge, float shotSpeed); +}; + +Weapon* weapon_fetus_make(WeaponType type); +Entity_Tear* fire_fetus_tear(Weapon& weapon, const FetusShot& shot); diff --git a/src/weapon_lasers.cpp b/src/weapon_lasers.cpp index 32a06ce..79116e8 100644 --- a/src/weapon_lasers.cpp +++ b/src/weapon_lasers.cpp @@ -8,6 +8,7 @@ #include "log.h" #include "manager.h" #include "npc_ai.h" +#include "npc_basement.h" #include "sfx_manager.h" #include @@ -57,6 +58,11 @@ constexpr int HELD_BEAM_TIMEOUT = 8; constexpr int HELD_BEAM_MIN_TIMEOUT = 4; constexpr int FAMILIAR_BEAM_BLINK = 10; constexpr float LUDOVICO_RING_LIFT = -20; +constexpr float TRACTOR_BEAM_REACH = 12; +constexpr float TRACTOR_BEAM_UP = -0.5f; +constexpr float TRACTOR_BEAM_DEPTH_UP = -10; +constexpr float TRACTOR_BEAM_DEPTH = 3000; +constexpr int TRACTOR_BEAM_BLINK = 5; constexpr float LUDOVICO_RETURN_PUSH = 0.15f; constexpr float LUDOVICO_RETURN_DISTANCE_SQUARED = 10000; constexpr float NO_RELEASE_CHARGE = -1000; @@ -913,6 +919,38 @@ void Weapon_TechX::fire_rings(const Vector& aim, float shotSpeed) else if (owner && owner->is_player()) owner->ToPlayer()->stop_costume_item_anims(); } +// The Tractor Beam part of 00782af0: a plain player holding it with a weapon that rides it keeps a beam from its +// Tractor Beam spot along its aim (or the way its head faces), drawn under it when aiming up and hidden while an +// item animation plays or an item is held, and keeps its eyes open. Otherwise the beam goes. +void tractor_beam_update(Entity_Player& player) +{ + if (player.variant != PLAYER_VARIANT_PLAYER || player.isCoopGhost) return; + Weapon* weapon = player.weapons[1].get(); + if (!player.HasCollectible(COLLECTIBLE_TRACTOR_BEAM) || !weapon || !weapon->SupportsTractorBeam()) + { + if (Entity* beam = player.tractorBeam) beam->Remove(); + return; + } + + Vector aim = player.aimDirection; + bool isFreeAim = !vector_is_zero(aim) && player.HasCollectible(COLLECTIBLE_ANALOG_STICK); + aim = player.markedTarget || isFreeAim ? vector_normalized(aim) : vector_from_direction(player.headDirection); + if (!player.tractorBeam) + { + Entity* spawned = g_game->Spawn({.position = player.pos, .spawner = &player, .type = ENTITY_LASER, + .variant = LASER_TRACTOR_BEAM, .seed = Random()}); + spawned->parent = &player; + spawned->Update(); + player.tractorBeam = spawned; + } + auto& beam = *static_cast(player.tractorBeam.get()); + beam.posOffset = player.GetLaserOffset(LASER_OFFSET_TRACTOR_BEAM, vector_scale(aim, TRACTOR_BEAM_REACH)); + beam.set_aim_angle(angle_wrap(vector_angle(aim))); + beam.renderDepthOffset = aim.y <= TRACTOR_BEAM_UP ? TRACTOR_BEAM_DEPTH_UP : TRACTOR_BEAM_DEPTH; + beam.isVisible = player.IsExtraAnimationFinished() && !player.IsHoldingItem(); + player.blinkTime = std::max(player.blinkTime, TRACTOR_BEAM_BLINK); +} + // 009f6980 Fires a Tech X ring: the owning player's, or a plain one from the owner. Entity_Laser* Weapon::fire_tech_x_laser(const TechXShot& shot) { diff --git a/src/weapon_lasers.h b/src/weapon_lasers.h index cbf9357..32f11d1 100644 --- a/src/weapon_lasers.h +++ b/src/weapon_lasers.h @@ -75,3 +75,4 @@ struct Weapon_TechX : Weapon }; Weapon* weapon_laser_make(WeaponType type); +void tractor_beam_update(Entity_Player& player); diff --git a/src/weapon_ludovico.cpp b/src/weapon_ludovico.cpp new file mode 100644 index 0000000..19a6f8e --- /dev/null +++ b/src/weapon_ludovico.cpp @@ -0,0 +1,250 @@ +#include "weapon_ludovico.h" +#include "entity_player.h" +#include "entity_tear.h" +#include "game.h" +#include "npc_ai.h" +#include "room.h" +#include "room_grid.h" +#include +#include +#include + +// The tear's hover: where it appears below the owner, its height (the crawlspace's own), how hard the aim pushes it, +// and its size by its damage. +constexpr float TEAR_APPEAR_DROP = 5; +constexpr float TEAR_HOVER_HEIGHT = -40; +constexpr float CRAWLSPACE_HOVER_OFFSET = -18; +constexpr float TEAR_STEER = 3; +constexpr float LUDOVICO_SCALE_ROOT = 0.15f; +constexpr float LUDOVICO_SCALE_DAMAGE = 0.04f; +constexpr float LUDOVICO_SCALE_BASE = 1.5f; +constexpr float LUDOVICO_SCALE_MIN = 0.01f; + +// The orbiting tears' half size, Monstro's Lung's cloud (five tears at a random reach and size), and Loki's Horns' +// and Mom's Eye's chances, which luck raises, and their shot speed. +constexpr float ORBIT_TEAR_SCALE = 0.5f; +constexpr int LUNG_TEAR_COUNT = 5; +constexpr float LUNG_REACH = 20; +constexpr float LUNG_REACH_MIN = 5; +constexpr float LUNG_SCALE = 0.75f; +constexpr float LUNG_SCALE_MIN = 0.5f; +constexpr float LOKIS_HORNS_ODDS = 100; +constexpr float MOMS_EYE_ODDS = 50; +constexpr float ODDS_PER_LUCK = 5; +constexpr float EXTRA_SHOT_SPEED = 10; + +constexpr float WIZ_TURN = 0.7853982f; + +// The Ludovico tears' subtypes: the main tear, one circling it, and one of Monstro's Lung's cloud. +enum LudovicoTearKind +{ + LUDOVICO_MAIN = 0, + LUDOVICO_ORBIT = 4, + LUDOVICO_LUNG = 5 +}; + +// The aim a steered weapon (Ludovico's tear, Epic Fetus' target) pushes with: at most a unit long, turned an eighth +// of a turn by The Wiz unless 20/20 straightens it. +Vector weapon_steer_aim(Entity_Player* player, Vector aim) +{ + if (vector_length_squared(aim) > 1) aim = vector_normalized(aim); + if (!player || !player->HasCollectible(COLLECTIBLE_THE_WIZ) || player->HasCollectible(COLLECTIBLE_20_20)) return aim; + + float c = std::cos(WIZ_TURN); + float s = std::sin(WIZ_TURN); + return vector_make(aim.x * c - aim.y * s, aim.y * c + aim.x * s); +} + +// 009f9020's maker for Ludovico's weapon (009f9440), or none for the other types. +Weapon* weapon_ludovico_make(WeaponType type) +{ + return type == WEAPON_LUDOVICO_TECHNIQUE ? new Weapon_Ludovico() : nullptr; +} + +// 00a063b0 Removes Technology 2's laser and the tear, and forgets them (Weapon_Laser::ClearReferences). +void Weapon_Ludovico::ClearReferences() +{ + for (EntityPtr* held : {&technology2Laser, &tear}) + { + if (!*held) continue; + (*held)->Remove(); + *held = nullptr; + } +} + +// Spawns a Ludovico tear at a spot, hovering at its height. The original crashes when the spawn is not a tear: here +// it is none. +Entity_Tear* Weapon_Ludovico::tear_spawn(const Vector& position, int variant, int subType) +{ + uint32_t seed = Random(); + Entity* spawned = g_game->Spawn({.position = position, .spawner = owner, + .subType = subType, .type = ENTITY_TEAR, .variant = variant, .seed = seed}); + Entity_Tear* made = spawned ? spawned->ToTear() : nullptr; + if (!made) return nullptr; + + made->height = TEAR_HOVER_HEIGHT; + made->posOffset.y = made->get_height_offset_y(TEAR_HOVER_HEIGHT); + if (g_game->room->roomType == ROOM_DUNGEON) made->posOffset.y = CRAWLSPACE_HOVER_OFFSET; + return made; +} + +// A copy of the main tear for its orbiting and Lung tears: its damage, its flags but explosive, its color and a share +// of its size, flying over the grid. +static void tear_copy(Entity_Tear& made, Entity_Tear& main, float scale) +{ + made.SetCollisionDamage(main.collisionDamage); + TearFlags flags = main.tearFlags; + flags.reset(TEAR_EXPLOSIVE); + made.SetTearFlags(flags); + made.SetColor(main.sprite.color, -1, COLOR_PRIORITY_DEFAULT, false, true); + made.baseScale = std::max(scale, LUDOVICO_SCALE_MIN); + made.fScale = made.baseScale; + made.ResetSpriteScale(); + made.entityGridCollisionClass = GRIDCOLL_NONE; +} + +// Makes the tear afresh below the owner with the player's Ludovico tear: its damage and color, its flags with +// Ludovico's, sized by the damage. +void Weapon_Ludovico::tear_make() +{ + if (tear) tear->Remove(); + TearParams params; + if (Entity_Player* player = owner_player()) + params = player->GetTearHitParams(WEAPON_LUDOVICO_TECHNIQUE, 1, tear_displacement(), owner); + + Entity_Tear* made = tear_spawn(vector_add(get_owner_position(), vector_make(0, TEAR_APPEAR_DROP)), params.tearVariant, + LUDOVICO_MAIN); + if (!made) return; + made->parent = owner; + made->SetCollisionDamage(params.tearDamage); + TearFlags flags = params.tearFlags; + flags.set(TEAR_LUDOVICO); + made->SetTearFlags(flags); + made->SetColor(params.tearColor, -1, COLOR_PRIORITY_DEFAULT, false, true); + float damage = params.tearDamage; + float scale = std::sqrt(damage) * LUDOVICO_SCALE_ROOT + damage * LUDOVICO_SCALE_DAMAGE + LUDOVICO_SCALE_BASE; + made->baseScale = std::max(scale, LUDOVICO_SCALE_MIN); + made->fScale = made->baseScale; + made->ResetSpriteScale(); + made->Update(); + tear = made; +} + +// Keeps one orbiting tear per extra shot of the volley, chained from the main tear: missing ones are spawned at it, +// extra ones removed. A tear spawned this frame updates at once. +void Weapon_Ludovico::orbit_tears_update(int count) +{ + auto* main = static_cast(tear.get()); + std::vector chain; + for (Entity* link = main->child; link; link = link->child) chain.push_back(link); + if ((int)chain.size() == count) return; + + if ((int)chain.size() > count) + { + for (size_t i = count; i < chain.size(); i++) chain[i]->Remove(); + chain.resize(count); + } + else + { + TearParams params; + if (Entity_Player* player = owner_player()) + params = player->GetTearHitParams(WEAPON_LUDOVICO_TECHNIQUE, 1, tear_displacement(), owner); + while ((int)chain.size() < count) + { + Entity_Tear* made = tear_spawn(vector_add(main->pos, vector_make(0, TEAR_APPEAR_DROP)), params.tearVariant, + LUDOVICO_ORBIT); + if (!made) break; + made->parent = main; + tear_copy(*made, *main, main->fScale * ORBIT_TEAR_SCALE); + chain.push_back(made); + } + } + + Entity* previous = main; + for (Entity* link : chain) + { + previous->child = link; + if (g_game->frameCount == link->spawnFrame) link->Update(); + previous = link; + } +} + +// Monstro's Lung: once none of its tears is left around the main tear, five small ones gather at random spots near it. +void Weapon_Ludovico::lung_tears_update() +{ + Entity* main = tear; + for (Entity* other : g_game->room->entityList.updateEL) + if (other->IsType(ENTITY_TEAR, -1, LUDOVICO_LUNG) && other->parent.get() == main) return; + + Entity_Player* player = owner_player(); + TearParams params = player->GetTearHitParams(WEAPON_LUDOVICO_TECHNIQUE, 1, tear_displacement(), owner); + auto& mainTear = *static_cast(main); + for (int i = 0; i < LUNG_TEAR_COUNT; i++) + { + float angle = random_unit() * RANDOM_HALF_TURN; + angle += angle; + float sine = std::sin(angle); + float reach = random_unit() * LUNG_REACH + LUNG_REACH_MIN; + Vector offset = vector_make(std::cos(angle) * reach, reach * sine); + Entity_Tear* made = tear_spawn(vector_add(offset, main->pos), params.tearVariant, LUDOVICO_LUNG); + if (!made) continue; + made->parentOffset = offset; + made->parent = main; + tear_copy(*made, mainTear, (random_unit() * LUNG_SCALE + LUNG_SCALE_MIN) * mainTear.fScale); + } +} + +// Loki's Horns' four tears along the axes and Mom's Eye's one tear in a random direction, from the tear, by chances +// luck raises. +void Weapon_Ludovico::extra_shots_fire(float luck, float shotSpeed) +{ + Entity_Player* player = owner_player(); + Vector from = tear->pos; + float speed = shotSpeed * EXTRA_SHOT_SPEED; + auto is_rolled = [luck](float odds) { + uint32_t chance = (uint32_t)std::max(odds - luck * ODDS_PER_LUCK, 1.0f); + return chance == 0 || Random() % chance == 0; + }; + + if (player->HasCollectible(COLLECTIBLE_LOKIS_HORNS) && is_rolled(LOKIS_HORNS_ODDS)) + for (Vector way : {vector_make(speed, shotSpeed * 0), vector_make(-speed, shotSpeed * 0), + vector_make(shotSpeed * 0, speed), vector_make(shotSpeed * 0, -speed)}) + fire_tear({from, way}, TEAR_FIRE_EXTRA_SHOT, 1, 0); + if (player->HasCollectible(COLLECTIBLE_MOMS_EYE) && is_rolled(MOMS_EYE_ODDS)) + fire_tear({from, vector_scale(random_direction(), speed)}, TEAR_FIRE_EXTRA_SHOT, 1, 0); +} + +// 00a06a30 Ludovico: without a tear (or once it stopped being one) a new one is made. Otherwise the shots push it +// (turned by The Wiz), the fire delay triggers the tear effects toward it, the volley's extra tears circle it, +// Monstro's Lung keeps a cloud around it, and Loki's Horns and Mom's Eye fire from it. +void Weapon_Ludovico::Fire(const Vector& shootDirection, bool isShooting, bool isInterpolated) +{ + Weapon::Fire(shootDirection, isShooting, isInterpolated); + Entity_Player* player = owner_player(); + float luck = player ? player->luck : 0; + float shotSpeed = player ? player->shotSpeed : 1; + Entity* main = tear; + if (!main || main->type != ENTITY_TEAR) + { + if (!isInterpolated) tear_make(); + return; + } + if (isInterpolated) return; + + if (isShooting && main->friction != 0) + { + Vector aim = weapon_steer_aim(player, shootDirection); + float push = main->speedMultiplier * shotSpeed * TEAR_STEER / main->friction; + main->velocity = vector_add(main->velocity, vector_scale(aim, push)); + } + if (owner && owner->GetIntervalTicks(maxFireDelay, 0) != 0) + { + bool isApart = main->pos.x != owner->pos.x || main->pos.y != owner->pos.y; + TriggerTearEffects(isApart ? vector_normalized(vector_sub(main->pos, owner->pos)) : random_direction(), 1); + } + orbit_tears_update(std::max(GetMultiShotParams().numTears - 1, 0)); + if (!player) return; + + if (player->HasCollectible(COLLECTIBLE_MONSTROS_LUNG)) lung_tears_update(); + if (player->GetIntervalTicks(maxFireDelay, 0) != 0) extra_shots_fire(luck, shotSpeed); +} diff --git a/src/weapon_ludovico.h b/src/weapon_ludovico.h new file mode 100644 index 0000000..738b428 --- /dev/null +++ b/src/weapon_ludovico.h @@ -0,0 +1,27 @@ +#pragma once + +#include "weapon.h" + +// Destruction (009f9880) is the default. +// The Ludovico Technique: one big tear that hovers in front of the owner and is steered by the shots, with the +// volley's extra tears circling it, Monstro's Lung's cloud of small ones around it, and Loki's Horns' and Mom's +// Eye's shots from it. +struct Weapon_Ludovico : Weapon +{ + EntityPtr tear; + + void Fire(const Vector& shootDirection, bool isShooting, bool isInterpolated) override; + void ClearReferences() override; + // 009f3150 The camera follows the tear. + Entity* GetFocusEntity() override { return tear; } + // 009f3150 The weapon fires as its tear. + Entity* GetMainEntity() override { return tear; } + + Entity_Tear* tear_spawn(const Vector& position, int variant, int subType); + void tear_make(); + void orbit_tears_update(int count); + void lung_tears_update(); + void extra_shots_fire(float luck, float shotSpeed); +}; + +Weapon* weapon_ludovico_make(WeaponType type); diff --git a/src/weapon_rockets.cpp b/src/weapon_rockets.cpp new file mode 100644 index 0000000..c11b396 --- /dev/null +++ b/src/weapon_rockets.cpp @@ -0,0 +1,388 @@ +#include "weapon_rockets.h" +#include "entity_bomb.h" +#include "entity_effect.h" +#include "entity_familiar.h" +#include "entity_player.h" +#include "entity_projectile.h" +#include "game.h" +#include "grid_entity.h" +#include "log.h" +#include "npc_ai.h" +#include "room.h" +#include "room_grid.h" +#include + +// Epic Fetus' aim and blink, the targets' fuse (five frames a rocket plus twenty, doubled), a familiar's smaller +// target, the random targets' spread, and the homing pull's reach. +constexpr float ROCKET_TARGET_SPEED = 8; +constexpr int ROCKET_BLINK = 10; +constexpr int TARGET_FRAMES_PER_ROCKET = 5; +constexpr int TARGET_FRAMES_BASE = 20; +constexpr float FAMILIAR_TARGET_SCALE = 0.8f; +constexpr float RANDOM_TARGET_REACH = 80; +constexpr float RANDOM_TARGET_MIN = 10; +constexpr float HOMING_TARGET_REACH = 200; + +// The targets' frame: their drag (a Lil Gurdy's milder), the frames each rocket falls behind the last, the warning +// before them, the blink, the spin of a random target, and the Marked line's drawn share of its length. +constexpr float TARGET_FRICTION = 0.5f; +constexpr float TARGET_FRICTION_FAMILIAR = 0.95f; +constexpr int FAMILIAR_LIL_GURDY = 120; +constexpr int ROCKET_FALL_FRAMES = 10; +constexpr int ROCKET_WARNING_FRAMES = 12; +constexpr int BLINK_MIN_PERIOD = 2; +constexpr int PROJECTILE_BLINK_PERIOD = 20; +constexpr int PROJECTILE_BLINK_FAST = 4; +constexpr float PROJECTILE_BLINK_HEIGHT = -100; +constexpr int MARKED_BLINK_PERIOD = 30; +constexpr float RANDOM_TARGET_SPIN = 5; +constexpr float MARKED_LINE_SHARE = 0.65f; + +// The rockets' fall, their landing frames and blast: twenty times the tear's damage, 80 without a player. +constexpr float ROCKET_FALL_HEIGHT = 100; +constexpr int ROCKET_LANDING_FRAMES = 3; +constexpr float ROCKET_DAMAGE_SCALE = 20; +constexpr float ROCKET_DAMAGE_DEFAULT = 80; + +// The targets a volley adds around the main one: behind it, to each side, or at a random spot it circles. +enum TargetKind +{ + TARGET_MAIN, + TARGET_BACK, + TARGET_LEFT, + TARGET_RIGHT, + TARGET_RANDOM, + TARGET_PROJECTILE = 10 +}; + +constexpr int CULTIST_BONE_ORBITAL = 10; + +// 009f9020's maker for Epic Fetus' weapon (009f9350), or none for the other types. +Weapon* weapon_rocket_make(WeaponType type) +{ + return type == WEAPON_ROCKETS ? new Weapon_Rockets() : nullptr; +} + +// 00a063b0 Removes Technology 2's laser and the target, and forgets them (Weapon_Laser::ClearReferences). +void Weapon_Rockets::ClearReferences() +{ + for (EntityPtr* held : {&technology2Laser, &target}) + { + if (!*held) continue; + (*held)->Remove(); + *held = nullptr; + } +} + +// 00a099a0 Marked's target. Without a player the original crashes: here it places none. +int Weapon_Rockets::GetMarkedTargetVariant() +{ + Entity_Player* player = owner_player(); + return player && player->HasCollectible(COLLECTIBLE_MARKED) ? EFFECT_TARGET : 0; +} + +// Drops a target for a volley of rockets at a spot: they fall on it from its timeout down. +Entity_Effect* Weapon_Rockets::target_spawn(const Vector& position, int rockets, float scale) +{ + Entity* spawned = g_game->Spawn( + {.position = position, .spawner = owner, .type = ENTITY_EFFECT, .variant = EFFECT_TARGET, .seed = Random()}); + auto* placed = static_cast(spawned); + placed->sprite.scale = vector_make(scale, scale); + placed->state = rockets; + placed->timeout = (rockets * TARGET_FRAMES_PER_ROCKET + TARGET_FRAMES_BASE) * 2; + placed->lifespan = placed->timeout; + return placed; +} + +// Whether Epic Fetus' homing pulls its target toward an entity: a live enemy that is not a fireplace, shopkeeper, +// movable TNT, poop, prop, minecart or Blood Cultist's bone orbital, or any live player in a versus match. +static bool is_homing_target(Entity& entity) +{ + if (entity.isDead) return false; + if (g_game->deathmatchManager.is_active() && entity.is_player()) return true; + switch (entity.type) + { + case ENTITY_FIREPLACE: + case ENTITY_SHOPKEEPER: + case ENTITY_MOVABLE_TNT: + case ENTITY_POOP: + case ENTITY_GENERIC_PROP: + case ENTITY_MINECART: + return false; + case ENTITY_CULTIST: + return entity.variant != CULTIST_BONE_ORBITAL; + default: + return entity.type >= ENTITY_GAPER && entity.type < ENTITY_EFFECT; + } +} + +// 00a08d40 Epic Fetus: the aim steers the target (rotated by The Wiz), or Marked sets it on its own target. Once the +// fire delay passed (or as Doctor's Remote's shot) a shot drops a target and the volley's extra ones, Strange +// Attractor pulls at them and homing draws the target to the nearest enemy. A finished target restarts the delay and +// ends Doctor's Remote. +void Weapon_Rockets::Fire(const Vector& shootDirection, bool isShooting, bool isInterpolated) +{ + Weapon::Fire(shootDirection, isShooting, isInterpolated); + Entity_Player* player = owner_player(); + Entity* familiar = owner && owner->IsFamiliar() ? owner : nullptr; + bool isOverride = modifiers & WEAPON_MOD_OVERRIDE; + Entity* marked = player ? static_cast(player->markedTarget) : nullptr; + bool isMarked = !isOverride && marked && player->HasCollectible(COLLECTIBLE_MARKED); + + if (Entity* aimed = target) + { + if (isMarked) + { + Vector spot = marked->pos; + if (familiar) spot = vector_add(spot, vector_sub(familiar->pos, player->pos)); + aimed->pos = spot; + } + else + { + Vector aim = weapon_steer_aim(player, shootDirection); + aimed->velocity = vector_add(aimed->velocity, vector_scale(aim, ROCKET_TARGET_SPEED * aimed->speedMultiplier)); + } + } + if (isInterpolated) return; + + Weapon_MultiShotParams params = GetMultiShotParams(); + int rockets = params.numTears; + if (isOverride && player && player->HasCollectible(COLLECTIBLE_CAR_BATTERY)) rockets *= 2; + if (isShooting || isMarked) + { + SetBlinkTime(ROCKET_BLINK); + bool isFree = !target || (isMarked && target->isDead); + if (isFree && (fireDelay < 0 || isOverride)) + { + Vector spot = isMarked ? marked->pos : get_owner_position(); + float scale = familiar ? FAMILIAR_TARGET_SCALE : 1; + Entity_Effect* main = target_spawn(spot, rockets, scale); + if (isMarked && !familiar) main->isVisible = false; + target = main; + + auto extra = [&](int kind) { + Entity_Effect* added = target_spawn(spot, rockets, scale); + added->parent = main; + added->subtype = kind; + return added; + }; + if (params.isShootingBackwards) extra(TARGET_BACK); + if (params.isShootingSideways) + { + extra(TARGET_LEFT); + extra(TARGET_RIGHT); + } + for (int i = 0; i < params.numRandomDirTears; i++) + { + Entity_Effect* added = extra(TARGET_RANDOM); + float angle = random_unit() * RANDOM_HALF_TURN; + angle += angle; + float sine = std::sin(angle); + float reach = random_unit() * RANDOM_TARGET_REACH + RANDOM_TARGET_MIN; + added->posOffset = vector_make(std::cos(angle) * reach, reach * sine); + } + fireDelay = maxFireDelay; + } + } + + if (Entity* aimed = target) + { + TearFlags flags = get_owner_tear_flags(); + if (flags[TEAR_ATTRACTOR]) + reconstruction_missing("Weapon_Rockets::Fire 00a08d40 (Strange Attractor, Game::AttractEntities)"); + if (flags[TEAR_HOMING]) + { + Entity* nearest = nullptr; + float best = 999999; + for (Entity* entity : entity_query_radius(aimed->pos, HOMING_TARGET_REACH, QUERY_ENEMIES)) + { + if (!is_homing_target(*entity)) continue; + float distance = vector_length_squared(vector_sub(aimed->pos, entity->pos)); + if (distance >= best) continue; + best = distance; + nearest = entity; + } + if (nearest && aimed->friction != 0) + { + Vector pull = vector_normalized(vector_sub(nearest->pos, aimed->pos)); + aimed->velocity = vector_add(aimed->velocity, vector_scale(pull, aimed->speedMultiplier / aimed->friction)); + } + } + } + if (owner && owner->GetIntervalTicks(maxFireDelay, 0) != 0) + { + Entity* aimed = target; + bool isApart = aimed && (aimed->pos.x != owner->pos.x || aimed->pos.y != owner->pos.y); + TriggerTearEffects(isApart ? vector_normalized(vector_sub(aimed->pos, owner->pos)) : random_direction(), 1); + } + if (target && target->isDead) + { + fireDelay = maxFireDelay; + Entity_Player* holder = owner && owner->is_player() ? owner->ToPlayer() : nullptr; + if (isOverride && holder) holder->ResetItemState(); + } +} + +// The Marked target's look: the line to its spawner (an overlay whose second layer turns toward the spawner and +// stretches to it) tinted like the target. +static void marked_line_update(Entity_Effect& effect, Entity& spawner) +{ + if (!effect.sprite.overlayAnimState.animData) effect.sprite.PlayOverlay("Line"); + if (effect.sprite.animState.GetLayerFrame(0) && effect.sprite.layerStates.size() > 1) + { + ColorMod tint = effect.sprite.layerStates[0].color; + color_multiply(tint, effect.sprite.animState.GetLayerFrame(0)->color); + effect.sprite.layerStates[1].color = tint; + } + Vector toSpawner = vector_sub(spawner.pos, effect.pos); + if (effect.sprite.layerStates.size() > 1) effect.sprite.layerStates[1].rotation = vector_angle(toSpawner); + effect.scale = vector_length(toSpawner); +} + +// The blink frame of a target: a projectile's target blinks fast as the shot nears the floor, Marked's on a slow loop, +// a rocket's ever faster as its rockets near. +static int target_blink_frame(Entity_Effect& effect) +{ + if (effect.subtype == TARGET_PROJECTILE) + { + Entity* parent = effect.parent; + auto* shot = parent && parent->IsProjectile() ? static_cast(parent) : nullptr; + if (shot && shot->fallingSpeed > 0 && shot->height > PROJECTILE_BLINK_HEIGHT) + return effect.FrameCount() % PROJECTILE_BLINK_FAST < 2; + return effect.FrameCount() % PROJECTILE_BLINK_PERIOD < PROJECTILE_BLINK_PERIOD / 2; + } + if (effect.lifespan == 0) return effect.FrameCount() % MARKED_BLINK_PERIOD < MARKED_BLINK_PERIOD / 2; + int period = std::max(BLINK_MIN_PERIOD, (int)std::sqrt((float)effect.timeout)); + return effect.timeout % period < period / 2; +} + +// 005d4380 (variants 30 and 153) A target: it slides to a stop inside the room, a timed one goes, Marked's draws its +// line to its spawner, a volley's extra targets keep their place around the main one (a random one circling it), it +// blinks, and at its rockets' time it calls them down one after another with a warning before. +static EffectUpdateEnd target_update(Entity_Effect& effect) +{ + Entity* spawner = effect.spawnerEntity; + bool isLilGurdy = effect.spawnerType == ENTITY_FAMILIAR && effect.spawnerVariant == FAMILIAR_LIL_GURDY; + effect.friction *= isLilGurdy ? TARGET_FRICTION_FAMILIAR : TARGET_FRICTION; + if (effect.varData[1] != 0 && --effect.varData[1] == 0) effect.Remove(); + + if (effect.subtype == TARGET_MAIN) + { + effect.pos = g_game->room->GetClampedPosition(effect.pos, 0); + if (spawner && (spawner->is_player() || spawner->IsEnemy()) && effect.lifespan == 0) + marked_line_update(effect, *spawner); + } + else + { + if (effect.parent && spawner) + { + Vector ahead = vector_sub(effect.parent->pos, spawner->pos); + switch (effect.subtype) + { + case TARGET_BACK: + effect.pos = vector_sub(spawner->pos, ahead); + break; + case TARGET_LEFT: + effect.pos = vector_add(spawner->pos, vector_make(-ahead.y, ahead.x)); + break; + case TARGET_RIGHT: + effect.pos = vector_add(spawner->pos, vector_make(ahead.y, -ahead.x)); + break; + case TARGET_RANDOM: + { + effect.pos = effect.parent->pos; + float turn = RANDOM_TARGET_SPIN * DEGREES_TO_RADIANS; + Vector offset = effect.posOffset; + effect.posOffset = vector_make(offset.x * std::cos(turn) - offset.y * std::sin(turn), + offset.y * std::cos(turn) + offset.x * std::sin(turn)); + break; + } + } + } + if (effect.subtype == TARGET_PROJECTILE && !effect.parent) effect.Remove(); + } + + if (effect.isDead) + { + effect.sprite.SetFrame("Blink", 0); + effect.Remove(); + return EFFECT_UPDATE_FINISH; + } + effect.sprite.SetFrame("Blink", target_blink_frame(effect)); + if (effect.subtype == TARGET_PROJECTILE) return EFFECT_UPDATE_FINISH; + + int rockets = effect.state; + if (effect.timeout == rockets * ROCKET_FALL_FRAMES) + { + for (int i = 1; i <= rockets; i++) + { + uint32_t seed = Random(); + Entity* spawned = g_game->Spawn({.position = vector_add(effect.pos, effect.posOffset), .spawner = spawner, + .type = ENTITY_EFFECT, .variant = EFFECT_ROCKET, .seed = seed}); + auto* rocket = static_cast(spawned); + rocket->sprite.scale = effect.sprite.scale; + rocket->SetTimeout(i * ROCKET_FALL_FRAMES); + rocket->Update(); + rocket->parent = &effect; + } + } + else if (effect.timeout == rockets * ROCKET_FALL_FRAMES + ROCKET_WARNING_FRAMES) + grid_sound_play(SOUND_DRSREMOTE_WARNING); + return EFFECT_UPDATE_FINISH; +} + +// 00607620 (variants 30 and 153) Draws a target, and Marked's line cropped to its length. +static void target_render(Entity_Effect& effect, const Vector&) +{ + SpriteDraw draw = {effect.renderPosition, {}, {}}; + effect.sprite.Render(draw); + const AnimationFrame* frame = effect.sprite.overlayAnimState.animData + ? effect.sprite.overlayAnimState.GetLayerFrame(1) + : nullptr; + if (!frame) return; + + AnimationLayer line = {.frames = {*frame}, .layerId = 1, .isVisible = true}; + line.frames[0].width = effect.scale * MARKED_LINE_SHARE; + line.RenderFrame(draw, 0, effect.sprite); +} + +// 005d4380 (variant 31) A rocket falling on its target: it drops toward it, shows its landing frame at the end, and +// blows up with its player's tear effects and twenty times its damage (Brimstone, Mom's Knife, Technology and Tech X +// add a burst of their shots). +static EffectUpdateEnd rocket_update(Entity_Effect& effect) +{ + effect.posOffset.y = (float)-effect.timeout * ROCKET_FALL_HEIGHT; + if (effect.timeout < ROCKET_LANDING_FRAMES) effect.sprite.SetFrame("Falling", 1); + if (effect.parent && !effect.parent->isDead) effect.pos = vector_add(effect.parent->pos, effect.parent->posOffset); + if (!effect.isDead) return EFFECT_UPDATE_FINISH; + + Entity* spawner = effect.spawnerEntity; + Entity_Player* player = spawner ? spawner->ToPlayer() : nullptr; + if (!player && spawner) player = spawner->GetLastSpawner()->ToPlayer(); + Explosion blast = {.position = effect.pos, .source = &effect, .damage = ROCKET_DAMAGE_DEFAULT}; + if (player) + { + TearParams params = player->GetTearHitParams(WEAPON_ROCKETS, 1, random_below(2) * 2 - 1, spawner); + bool isBurst = player->HasCollectible(COLLECTIBLE_BRIMSTONE) || player->HasWeaponType(WEAPON_BRIMSTONE) || + player->HasCollectible(COLLECTIBLE_MOMS_KNIFE) || player->HasWeaponType(WEAPON_KNIFE) || + player->HasCollectible(COLLECTIBLE_TECHNOLOGY) || player->HasWeaponType(WEAPON_LASER) || + player->HasCollectible(COLLECTIBLE_TECH_X) || player->HasWeaponType(WEAPON_TECH_X); + if (isBurst) params.tearFlags.set(TEAR_SAD_BOMB); + blast.tearFlags = params.tearFlags; + blast.color = params.tearColor; + blast.damage = params.tearDamage * ROCKET_DAMAGE_SCALE; + } + explosion_effects(blast); + effect.Remove(); + return EFFECT_UPDATE_FINISH; +} + +constexpr EffectBehaviour WEAPON_BEHAVIOURS[] = {{EFFECT_TARGET, nullptr, target_update, target_render}, + {EFFECT_ROCKET, nullptr, rocket_update, nullptr}, + {EFFECT_OCCULT_TARGET, nullptr, target_update, target_render}}; + +// The effects Epic Fetus and Marked place, for Entity_Effect's behaviour table. +std::span weapon_effect_behaviours() +{ + return WEAPON_BEHAVIOURS; +} diff --git a/src/weapon_rockets.h b/src/weapon_rockets.h new file mode 100644 index 0000000..d7a0a76 --- /dev/null +++ b/src/weapon_rockets.h @@ -0,0 +1,27 @@ +#pragma once + +#include "weapon.h" +#include + +struct EffectBehaviour; + +// Destruction (009f9880) is the default. +// Epic Fetus' weapon: a shot drops a target (four more for the volley's backward, sideways and random shots), steered +// by the aim or set on Marked's target, and the rockets it calls down fall on it. Doctor's Remote fires it once. +struct Weapon_Rockets : Weapon +{ + EntityPtr target; + + void Fire(const Vector& shootDirection, bool isShooting, bool isInterpolated) override; + void ClearReferences() override; + // 009f3150 The camera follows the target. + Entity* GetFocusEntity() override { return target; } + // 009f3150 The weapon fires as its target. + Entity* GetMainEntity() override { return target; } + int GetMarkedTargetVariant() override; + + Entity_Effect* target_spawn(const Vector& position, int rockets, float scale); +}; + +Weapon* weapon_rocket_make(WeaponType type); +std::span weapon_effect_behaviours();