From ee863e70e6e0909aaaa8b5ff7c2bbf21a36b0818 Mon Sep 17 00:00:00 2001 From: shweet Date: Sat, 21 Nov 2026 15:05:20 -0500 Subject: [PATCH] Curation round 19: EvaluateItems and charged shots, actives split into Rebirth and Repentance dispatches, cards and runes, champions and death effects, War, Death, Uriel and the boss sweep, Delirium, T. Lilith's Gello and familiars, effects, price sprites and the devil room --- generated-src/classes.h | 36 +- generated-src/npc_helper.cpp | 1286 ------------------ generated-src/stubs.cpp | 32 - generated-src/umbilical_baby_data.cpp | 12 - generated-src/vector.cpp | 19 - src/active_items.h | 23 + src/boss_ai.h | 14 + src/boss_angel.cpp | 335 +++++ src/boss_big_horn.cpp | 1079 ++++++++++++++- src/boss_dark_one.cpp | 227 ++++ src/boss_death.cpp | 47 +- src/boss_death_horseman.cpp | 520 +++++++ src/boss_delirium.cpp | 1168 ++++++++++++++++ src/boss_famine.cpp | 2 - src/boss_forsaken.cpp | 361 +++++ src/boss_headless_horseman.cpp | 181 +++ src/boss_monstro.cpp | 359 ++++- src/boss_war.cpp | 419 ++++++ src/entity.h | 20 +- src/entity_combat.cpp | 1 - src/entity_effect.cpp | 32 +- src/entity_effect.h | 65 +- src/entity_effect_ambient.cpp | 31 +- src/entity_effect_boss.cpp | 25 - src/entity_effect_items.cpp | 1353 +++++++++++++++++++ src/entity_familiar.cpp | 95 +- src/entity_familiar.h | 1 + src/entity_knife_hits.cpp | 2 +- src/entity_laser.cpp | 43 +- src/entity_npc.cpp | 587 +++----- src/entity_npc.h | 39 +- src/entity_npc_boss.cpp | 13 +- src/entity_npc_champion.cpp | 762 +++++++++++ src/entity_npc_rewards.cpp | 2 +- src/entity_pickup.cpp | 26 +- src/entity_pickup_shop.cpp | 59 +- src/entity_player.cpp | 1 + src/entity_player.h | 115 +- src/entity_player_actives.cpp | 41 +- src/entity_player_actives_rebirth.cpp | 1532 +++++++++++++++++++++ src/entity_player_actives_repentance.cpp | 1577 ++++++++++++++++++++++ src/entity_player_cards.cpp | 961 +++++++++++++ src/entity_player_characters.cpp | 132 +- src/entity_player_characters.h | 6 + src/entity_player_crafting.cpp | 3 +- src/entity_player_damage.cpp | 7 +- src/entity_player_death.cpp | 5 +- src/entity_player_evaluate.cpp | 605 +++++++-- src/entity_player_forgotten.cpp | 6 +- src/entity_player_frame.cpp | 383 +++++- src/entity_player_hits.cpp | 4 +- src/entity_player_items.cpp | 3 +- src/entity_player_missing.cpp | 9 - src/entity_player_passives.cpp | 1 - src/entity_player_pockets.cpp | 2 - src/entity_player_room.cpp | 3 +- src/entity_player_tears.cpp | 10 - src/entity_player_trinkets.cpp | 2 +- src/entity_player_weapons.cpp | 2 - src/entity_projectile.cpp | 236 +++- src/entity_projectile.h | 28 + src/entity_slot.cpp | 2 - src/entity_tear_flags.cpp | 15 +- src/familiar_ai.cpp | 3 +- src/familiar_evaluate.cpp | 2 - src/familiar_follow.cpp | 58 +- src/familiar_gello.cpp | 797 +++++++++++ src/familiar_gello.h | 41 + src/familiar_missing.cpp | 17 +- src/familiar_shoot.cpp | 33 +- src/game_save.cpp | 1 - src/game_state.cpp | 4 +- src/grid_entity_rock.cpp | 1 - src/item_config.h | 34 +- src/item_overlay.h | 2 + src/item_pickup.cpp | 2 +- src/item_pool.cpp | 1 - src/level.cpp | 18 +- src/level.h | 3 + src/lua_api_entity_player.cpp | 7 +- src/lua_api_game.cpp | 8 +- src/npc_ai.cpp | 16 +- src/npc_ai.h | 1 + src/npc_basement.h | 1 + src/npc_boom_fly.cpp | 1 - src/npc_clotty.cpp | 1 - src/npc_collision.cpp | 3 - src/npc_dirt.cpp | 10 + src/npc_hive.cpp | 1 - src/npc_maggot.cpp | 1 - src/persistent_game_data.h | 2 + src/player_hud.cpp | 3 - src/pocket_items.h | 4 + src/room.cpp | 125 +- src/room.h | 4 + src/room_clear.cpp | 1 - src/room_grid.h | 3 + src/room_special.cpp | 1 - src/room_state.cpp | 1 - src/room_transition.cpp | 1 - src/room_update.cpp | 1 - src/sfx_manager.h | 97 +- src/tainted_characters.cpp | 6 - src/temporary_effects.cpp | 2 +- src/weapon.cpp | 247 +++- 105 files changed, 14201 insertions(+), 2331 deletions(-) delete mode 100644 generated-src/umbilical_baby_data.cpp create mode 100644 src/boss_angel.cpp create mode 100644 src/boss_dark_one.cpp create mode 100644 src/boss_death_horseman.cpp create mode 100644 src/boss_delirium.cpp create mode 100644 src/boss_forsaken.cpp create mode 100644 src/boss_headless_horseman.cpp create mode 100644 src/boss_war.cpp create mode 100644 src/entity_effect_items.cpp create mode 100644 src/entity_npc_champion.cpp create mode 100644 src/entity_player_actives_rebirth.cpp create mode 100644 src/entity_player_actives_repentance.cpp create mode 100644 src/familiar_gello.cpp create mode 100644 src/familiar_gello.h diff --git a/generated-src/classes.h b/generated-src/classes.h index e3e9bbc..4ccfd6f 100644 --- a/generated-src/classes.h +++ b/generated-src/classes.h @@ -162,6 +162,7 @@ struct Card; struct CellSpace; struct ChallengeParam; struct ChallengeParams; +struct ChampionLook; struct Checksum; struct ClubSwing; struct CoPlayerState; @@ -184,6 +185,7 @@ struct ControlRow; struct ControllerEntry; struct CoopAward; struct CoopJoinSlot; +struct CordPoint; struct CostumeItem; struct CostumeSpriteDesc; struct CostumeWalk; @@ -393,6 +395,7 @@ struct LayerAnimation; struct LayerData; struct LayerState; struct Leaderboard; +struct LeftFire; struct Level; struct LevelGenerator; struct LevelGenerator_Room; @@ -3993,14 +3996,6 @@ LAYOUT32(offsetof(TypeDescriptor, pVFTable) == 0x0); LAYOUT32(offsetof(TypeDescriptor, spare) == 0x4); LAYOUT32(sizeof(TypeDescriptor) == 0x8); -struct UmbilicalBabyData { - virtual ~UmbilicalBabyData(); // 00431790 slot 0 ::FUN_00431790 - static uint32_t last_point(); // 00435590 - - uint8_t _pad_0x4[0x154]; -}; -LAYOUT32(sizeof(UmbilicalBabyData) == 0x158); - struct UserProfile { void find_or_create(); // 00a23ae0 }; @@ -5735,8 +5730,6 @@ void FUN_00431620(Entity *param_1); // 00431620 void FUN_004316b0(uint32_t param_1); // 004316b0 void FUN_004316c0(); // 004316c0 void FUN_00431700(); // 00431700 -void FUN_00431790(uint8_t param_1); // 00431790 -void FUN_00435130(Vector *param_1); // 00435130 void FUN_00435740(); // 00435740 uint32_t FUN_00435880(uint32_t param_1); // 00435880 uint32_t FUN_004358b0(); // 004358b0 @@ -5786,9 +5779,6 @@ void FUN_0044bfa0(uint32_t param_1); // 0044bfa0 void FUN_00450880(uint32_t param_1); // 00450880 void FUN_004508a0(uint32_t param_1); // 004508a0 uint32_t _ptr_deref_or_minus1(); // 00452be0 -void FUN_00452c60(); // 00452c60 -int FUN_00452d40(); // 00452d40 -void FUN_004530e0(); // 004530e0 void FUN_00456170(int *param_1); // 00456170 void FUN_00456190(uint32_t *param_1); // 00456190 uint8_t str_eq_cstr(std_string *str, uint8_t *cstr); // 004561b0 @@ -5817,7 +5807,6 @@ uint32_t FUN_00499db0(); // 00499db0 uint32_t FUN_0049d100(); // 0049d100 void FUN_004a11b0(); // 004a11b0 int FUN_004a2920(); // 004a2920 -void FUN_004a84f0(); // 004a84f0 void FUN_004aaaa0(void *param_1, int param_2); // 004aaaa0 void FUN_004aaaf0(uint32_t *param_1, uint32_t *param_2, uint32_t *param_3); // 004aaaf0 uint32_t * FUN_004aac80(uint32_t *param_1); // 004aac80 @@ -6226,7 +6215,6 @@ void FUN_00684450(); // 00684450 void FUN_006844a0(); // 006844a0 void sha1_transform(); // 006846c0 void sha1_digest(uint32_t param_1); // 00684920 -KColor * hsv_to_rgb(KColor *outColor, float hue, float saturation, float value, float alpha); // 00684b90 void FUN_00684ce0(uint32_t *param_1); // 00684ce0 int FUN_00684e10(uint32_t param_1); // 00684e10 void FUN_00684e50(uint32_t *param_1); // 00684e50 @@ -6350,7 +6338,6 @@ void FUN_006a1e00(uint32_t *param_1); // 006a1e00 void FUN_006a1fc0(); // 006a1fc0 void FUN_006a6910(uint32_t param_1, uint32_t param_2, uint32_t param_3, uint32_t param_4); // 006a6910 void FUN_006a6930(); // 006a6930 -void FUN_006a6940(); // 006a6940 void FUN_006a7ec0(); // 006a7ec0 void FUN_006a80d0(); // 006a80d0 void FUN_006a8180(uint32_t param_1); // 006a8180 @@ -6358,7 +6345,6 @@ void FUN_006a8210(int param_1); // 006a8210 void FUN_006b5de0(); // 006b5de0 void FUN_006b5f40(); // 006b5f40 void play_sound_with_fart_seed(int soundId, float volume, int frameDelay, uint8_t isLoop, float pitch); // 006b6470 -void * spawn_rock_particles(float *param_1, float *param_2); // 006b68c0 void FUN_006b6e40(float *param_1, int param_2); // 006b6e40 void vector_0x3c_tidy(); // 006b7d40 void FUN_006b7db0(uint32_t *param_1); // 006b7db0 @@ -6551,7 +6537,6 @@ void FUN_00745ad0(int param_1); // 00745ad0 void FUN_00748a30(); // 00748a30 void FUN_0074a280(int param_1, uint32_t param_2, uint8_t param_3); // 0074a280 void FUN_0074b9a0(); // 0074b9a0 -RoomDescriptor * FUN_0074bce0(); // 0074bce0 int * FUN_00752640(int *param_1); // 00752640 void FUN_007526b0(uint32_t *param_1); // 007526b0 void FUN_00752830(int *param_1); // 00752830 @@ -6619,7 +6604,6 @@ uint32_t FUN_007ad720(uint32_t param_1, uint8_t *param_2); // 007ad720 void FUN_007b8c00(int param_1); // 007b8c00 void FUN_007c2e80(); // 007c2e80 uint8_t FUN_007c7b10(uint32_t param_1, int param_2); // 007c7b10 -char FUN_007c9080(); // 007c9080 void FUN_007cb4f0(); // 007cb4f0 void FUN_007cf940(); // 007cf940 long double FUN_007cf9a0(float *param_1, KColor *param_2, uint32_t param_3); // 007cf9a0 @@ -9176,11 +9160,7 @@ void * map_int_ImagePtr_subscript(void *self, int *key); // 009f2e20 void FUN_009f3c10(); // 009f3c10 void FUN_009f3c40(); // 009f3c40 void FUN_009f4130(); // 009f4130 -Entity_Player * FUN_009f4fc0(); // 009f4fc0 void FUN_009f5810(uint8_t param_1); // 009f5810 -uint32_t FUN_009f5830(); // 009f5830 -uint32_t FUN_009f5850(); // 009f5850 -uint32_t FUN_009f5870(); // 009f5870 uint32_t * FUN_009f93d0(); // 009f93d0 uint32_t * FUN_00a06940(void *param_1, uint32_t *param_2); // 00a06940 void * operator_new(uint32_t size); // 00a0f4c0 @@ -20854,7 +20834,6 @@ void blood_puppy(Entity_Familiar *familiar); // 0064fd40 void vanishing_twin(Entity_Familiar *familiar); // 00650610 } namespace FamiliarHelper { -void umbilical_baby_load_graphics(Entity_Familiar *familiar); // 00431830 void wisp_mine_crafter_update(Entity_Familiar *wisp); // 0043d850 Entity_Laser * sprinkler_fire_laser(Entity_Familiar *familiar, float angle, float distance); // 0063acf0 void fly_head_pathfind_move(Entity_Familiar *familiar); // 0063d570 @@ -20908,21 +20887,13 @@ void ENTITY_BEAST_ultra_war(Entity_NPC *npc); // 0044c070 void ENTITY_BEAST_ultra_war_fire_burst(Entity_NPC *npc); // 0044ee60 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_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 void ENTITY_PIN(Entity_NPC *npc); // 00476860 -void ENTITY_FORSAKEN(Entity_NPC *npc); // 0048f110 void ENTITY_BUMBINO(Entity_NPC *npc); // 00499de0 void ENTITY_CHIMERA_head_update(Entity_NPC *npc); // 0049cd90 void ENTITY_CHIMERA_body(Entity_NPC *npc); // 0049d130 uint32_t ENTITY_CHIMERA(Entity_NPC *npc); // 0049fa10 void ENTITY_CLOG(Entity_NPC *npc); // 004a12f0 void ENTITY_COLOSTOMIA(Entity_NPC *npc); // 004a3040 -void ENTITY_DELIRIUM(Entity_NPC *npc); // 004a6500 void ENTITY_DOGMA_update_distortion(Entity_NPC *npc); // 004aaef0 void ENTITY_DOGMA(Entity_NPC *npc); // 004aafa0 void ENTITY_DOGMA_angel(Entity_NPC *npc); // 004ae4d0 @@ -20970,7 +20941,6 @@ void ENTITY_BIG_BONY(Entity_NPC *npc); // 005041d0 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_URIEL(Entity_NPC *npc); // 0051e0f0 void ENTITY_HEART(Entity_NPC *npc); // 0051f2f0 void ENTITY_DOPLE(Entity_NPC *npc); // 00525650 void ENTITY_BLACK_MAW(Entity_NPC *npc); // 0053b2f0 diff --git a/generated-src/npc_helper.cpp b/generated-src/npc_helper.cpp index b196d3a..fa2c232 100644 --- a/generated-src/npc_helper.cpp +++ b/generated-src/npc_helper.cpp @@ -469,1292 +469,6 @@ LAB_004a2fed: return; } -// 004a6240 -void NpcHelper::delirium_remove_minions(int type, int variant, Entity *self, Entity *other) -{ - void *pvVar1; - int *tmpEntity; - uint64_t qVar3; - char cVar4; - uint32_t uVar5; - int iVar6; - uint64_t *allocCounter; - code *freeFn; - uint32_t npcIdx; - EntityList_EL laserList; - EntityList_EL tmpList; - int targetVariant; - int targetType; - void *local_10; - uint8_t *puStack_c; - uint32_t local_8; - int roomEntity; - Entity *tmpEntity; - - local_8 = 0xffffffff; - puStack_c = &LAB_00af30b5; - local_10 = ExceptionList; - uVar5 = __security_cookie ^ GHIDRA_INT(register0x00000010) - 4U; - ExceptionList = &local_10; - npcIdx = 0; - pvVar1 = g_game->_room; - targetVariant = variant; - targetType = type; - if (*GHIDRA_CAST((GHIDRA_CAST(pvVar1) + 0x1264)) != 0) { - do { - tmpEntity = *GHIDRA_CAST((*GHIDRA_CAST((GHIDRA_CAST(pvVar1) + 0x125c)) + npcIdx * 4)); - if ((tmpEntity == self) || - (cVar4 = (**(code **)(*GHIDRA_CAST(tmpEntity) + 0x4c))(uVar5), cVar4 == '\0')) { -LAB_004a62c2: - if (other != GHIDRA_CAST(0x0)) { - iVar6 = *GHIDRA_CAST((GHIDRA_CAST(pvVar1) + 0x125c)); - roomEntity = *GHIDRA_CAST((iVar6 + npcIdx * 4)); - if ((*GHIDRA_CAST((roomEntity + 0x28)) == other->_type) && - (*GHIDRA_CAST((roomEntity + 0x2c)) == other->_variant)) goto LAB_004a62df; - } - } - else { - iVar6 = *GHIDRA_CAST((GHIDRA_CAST(pvVar1) + 0x125c)); - roomEntity = *GHIDRA_CAST((iVar6 + npcIdx * 4)); - if ((*GHIDRA_CAST((roomEntity + 0x28)) != targetType) || - (*GHIDRA_CAST((roomEntity + 0x2c)) != targetVariant)) goto LAB_004a62c2; -LAB_004a62df: - (**(code **)(**GHIDRA_CAST((iVar6 + npcIdx * 4)) + 0x28))(); - } - npcIdx = npcIdx + 1; - } while (npcIdx < *GHIDRA_CAST((GHIDRA_CAST(pvVar1) + 0x1264))); - } - if (targetType == 0x4f) { - EntityList::QuerySublist(GHIDRA_CAST((GHIDRA_INT(g_game->_room) + 0x1218)),&tmpList,0x4f,0x14,-1,0,0); - roomEntity = tmpList._size; - iVar6 = (*GHIDRA_CAST((GHIDRA_CAST(&(tmpList)) + 0x4))); - local_8 = 0; - uVar5 = 0; - if (tmpList._size != 0) { - do { - (**(code **)(**GHIDRA_CAST((iVar6 + uVar5 * 4)) + 0x28))(); - uVar5 = uVar5 + 1; - } while (uVar5 < GHIDRA_UINT(roomEntity)); - } -joined_r0x004a63ae: - local_8 = 0xffffffff; - if ((*GHIDRA_CAST((GHIDRA_CAST(&(tmpList)) + 0x0))) == '\0') { - local_8 = 0xffffffff; - if (g_mainHeap == (void *)0x0) { - allocCounter = &g_allocatedBytesNoHeap; - } - else { - allocCounter = GHIDRA_CAST((GHIDRA_INT(g_mainHeap) + 0x30)); - } - if (iVar6 != 0) { - uVar5 = *GHIDRA_CAST((iVar6 + -4)); - qVar3 = *allocCounter; - *GHIDRA_CAST(allocCounter) = GHIDRA_UINT(*allocCounter) - uVar5; - *GHIDRA_CAST((GHIDRA_CAST(allocCounter) + 4)) = - *GHIDRA_CAST((GHIDRA_CAST(allocCounter) + 4)) - GHIDRA_UINT((GHIDRA_UINT(qVar3) < uVar5)); - free((void *)(iVar6 + -4)); - } - local_8 = 0xffffffff; - } - } - else if (targetType == 0x197) { - EntityList::QuerySublist(GHIDRA_CAST((GHIDRA_INT(g_game->_room) + 0x1218)),&tmpList,1000,0x65,-1,0,0); - roomEntity = tmpList._size; - iVar6 = (*GHIDRA_CAST((GHIDRA_CAST(&(tmpList)) + 0x4))); - local_8 = 2; - uVar5 = 0; - if (tmpList._size != 0) { - do { - (**(code **)(**GHIDRA_CAST((iVar6 + uVar5 * 4)) + 0x28))(); - uVar5 = uVar5 + 1; - } while (uVar5 < GHIDRA_UINT(roomEntity)); - } - goto joined_r0x004a63ae; - } - EntityList::QuerySublist(GHIDRA_CAST((GHIDRA_INT(g_game->_room) + 0x1218)),&laserList,7,-1,-1,0,0); - local_8 = 4; - uVar5 = 0; - if (laserList._size != 0) { - do { - tmpEntity = *GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(laserList)) + 0x4))) + uVar5 * 4)); - if (tmpEntity[0xd] != 1) { - (**(code **)(*tmpEntity + 0x28))(); - } - uVar5 = uVar5 + 1; - } while (uVar5 < GHIDRA_UINT(laserList._size)); - } - EntityList::QuerySublist(GHIDRA_CAST((GHIDRA_INT(g_game->_room) + 0x1218)),&tmpList,0x60,0,-1,0,0); - local_8 = CONCAT31((*GHIDRA_CAST((GHIDRA_CAST(&(local_8)) + 0x1))),5); - uVar5 = 0; - if (tmpList._size != 0) { - do { - (**(code **)(**GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(tmpList)) + 0x4))) + uVar5 * 4)) + 0x28))(); - uVar5 = uVar5 + 1; - } while (uVar5 < GHIDRA_UINT(tmpList._size)); - } - if ((*GHIDRA_CAST((GHIDRA_CAST(&(tmpList)) + 0x0))) == '\0') { - allocCounter = GHIDRA_CAST((GHIDRA_INT(g_mainHeap) + 0x30)); - if (g_mainHeap == (void *)0x0) { - allocCounter = &g_allocatedBytesNoHeap; - } - if ((*GHIDRA_CAST((GHIDRA_CAST(&(tmpList)) + 0x4))) != 0) { - uVar5 = *GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(tmpList)) + 0x4))) + -4)); - qVar3 = *allocCounter; - *GHIDRA_CAST(allocCounter) = GHIDRA_UINT(*allocCounter) - uVar5; - freeFn = free_exref; - *GHIDRA_CAST((GHIDRA_CAST(allocCounter) + 4)) = - *GHIDRA_CAST((GHIDRA_CAST(allocCounter) + 4)) - GHIDRA_UINT((GHIDRA_UINT(qVar3) < uVar5)); - free((void *)((*GHIDRA_CAST((GHIDRA_CAST(&(tmpList)) + 0x4))) + -4)); - goto LAB_004a64bb; - } - } - freeFn = free_exref; -LAB_004a64bb: - if ((*GHIDRA_CAST((GHIDRA_CAST(&(laserList)) + 0x0))) == '\0') { - allocCounter = GHIDRA_CAST((GHIDRA_INT(g_mainHeap) + 0x30)); - if (g_mainHeap == (void *)0x0) { - allocCounter = &g_allocatedBytesNoHeap; - } - if ((*GHIDRA_CAST((GHIDRA_CAST(&(laserList)) + 0x4))) != 0) { - uVar5 = *GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(laserList)) + 0x4))) + -4)); - qVar3 = *allocCounter; - *GHIDRA_CAST(allocCounter) = GHIDRA_UINT(*allocCounter) - uVar5; - *GHIDRA_CAST((GHIDRA_CAST(allocCounter) + 4)) = - *GHIDRA_CAST((GHIDRA_CAST(allocCounter) + 4)) - GHIDRA_UINT((GHIDRA_UINT(qVar3) < uVar5)); - (*freeFn)((*GHIDRA_CAST((GHIDRA_CAST(&(laserList)) + 0x4))) + -4); - } - } - ExceptionList = local_10; - return; -} - -// 004a8680 -void NpcHelper::delirium_spawn_form_parts(Entity_NPC *npc, float maxHealth) -{ - uint32_t *puVar1; - float fVar2; - uint32_t uVar3; - uint8_t bVar4; - uint32_t uVar5; - Entity *target; - Entity_NPC *pEVar6; - void *newBlock; - uint8_t *curAnimChar; - uint32_t uVar7; - char *expectedAnimChar; - bool isCharLess; - float fVar8; - Vector spawnPos; - float dirX; - Entity_NPC *local_24; - float formMaxHealth; - Entity_NPC *formNpc; - int segmentCount; - float segmentIndex; - uint32_t *local_10; - void *local_c; - float dirY; - uint8_t *animData; - uint32_t *linkSlot; - int posBlock; - - formMaxHealth = maxHealth; - formNpc = npc; - if (npc->_type == 0x13) { - uVar5 = Random(); - segmentCount = uVar5 % 6 + 4; - target = Entity_NPC::GetPlayerTarget(npc); - dirY = (npc->_pos).x - (target->_pos).x; - local_c = (void *)((npc->_pos).y - (target->_pos).y); - fVar8 = sqrtf(dirY * dirY + (float)local_c * (float)local_c); - if (0.0 < fVar8) { - dirY = dirY * (1.0 / fVar8); - local_c = (void *)((float)local_c * (1.0 / fVar8)); - } - uVar5 = Random(); - segmentIndex = (float)GHIDRA_INT((uVar5 % 0x5a - 0x2d)) * 0.017453292; - local_10 = GHIDRA_CAST(cos(segmentIndex)); - fVar8 = sin(segmentIndex); - segmentIndex = 1.4013e-45; - dirX = dirY * (float)local_10 - (float)local_c * fVar8; - dirY = dirY * fVar8 + (float)local_c * (float)local_10; - pEVar6 = npc; - if (0 < segmentCount) { - do { - fVar8 = segmentIndex; - spawnPos.y = (float)GHIDRA_INT(segmentIndex) * 20.0 * dirY + (pEVar6->_pos).y; - spawnPos.x = (float)GHIDRA_INT(segmentIndex) * 20.0 * dirX + (pEVar6->_pos).x; - uVar5 = Random(); - local_10 = GHIDRA_CAST((((float)(uVar5 % 5000) + 0.0) / 1000.0)); - uVar5 = Random(); - spawnPos.x = ((float)(uVar5 % 5000) + 0.0) / 1000.0 + spawnPos.x; - spawnPos.y = spawnPos.y + (float)local_10; - uVar5 = Random(); - pEVar6 = (Entity_NPC *) - Game::Spawn(g_game,pEVar6->_type,pEVar6->_variant,&spawnPos,&g_vectorZero, - GHIDRA_CAST(pEVar6),0,uVar5); - if (fVar8 == 1.4013e-45) { - pEVar6->_health = formMaxHealth; - pEVar6->_maxHitPoints = formMaxHealth; - pEVar6->_isInvicible = 1; - } - linkSlot = &pEVar6->_parent; - if (pEVar6->_parent != 0) { - local_10 = linkSlot; - msvc::multiset::erase(&local_10); - } - *linkSlot = npc; - if (npc != GHIDRA_CAST(0x0)) { - msvc::multiset::insert(linkSlot); - } - linkSlot = &npc->_child; - if (npc->_child != 0) { - local_10 = linkSlot; - msvc::multiset::erase(&local_10); - } - *linkSlot = pEVar6; - msvc::multiset::insert(linkSlot); - uVar7 = GHIDRA_UINT(pEVar6->_flags) & 0xfffffffb | 0x80040000; - *GHIDRA_CAST((GHIDRA_INT(&pEVar6->_flags) + 4)) = *GHIDRA_CAST((GHIDRA_INT(&pEVar6->_flags) + 4)); - *GHIDRA_CAST(&pEVar6->_flags) = uVar7; - pEVar6->_state = 4; - uVar5 = (pEVar6->_vectorDeque1)._offset; - if (((uVar5 & 1) == 0) && - ((pEVar6->_vectorDeque1)._mapSize <= (pEVar6->_vectorDeque1)._size + 2 >> 1)) { - msvc::deque::_Growmap(uVar7); - uVar5 = (pEVar6->_vectorDeque1)._offset; - } - uVar7 = (pEVar6->_vectorDeque1)._mapSize; - uVar3 = uVar7 * 2; - uVar5 = uVar3 - 1 & uVar5; - (pEVar6->_vectorDeque1)._offset = uVar5; - if (uVar5 == 0) { - uVar5 = uVar3; - } - uVar5 = uVar5 - 1; - local_c = (void *)(uVar7 - 1 & uVar5 >> 1); - local_10 = (pEVar6->_vectorDeque1)._map; - local_24 = GHIDRA_CAST(uVar5); - if (local_10[GHIDRA_INT(local_c)] == 0) { - newBlock = operator_new(0x10); - *(void **)(GHIDRA_INT((pEVar6->_vectorDeque1)._map) + GHIDRA_INT(local_c) * 4) = newBlock; - local_10 = (pEVar6->_vectorDeque1)._map; - } - fVar8 = (pEVar6->_pos).y; - fVar2 = (pEVar6->_pos).x; - posBlock = local_10[GHIDRA_INT(local_c)]; - *GHIDRA_CAST((posBlock + (uVar5 & 1) * 8)) = fVar2; - *GHIDRA_CAST((posBlock + 4 + (uVar5 & 1) * 8)) = fVar8; - puVar1 = &(pEVar6->_vectorDeque1)._size; - *puVar1 = *puVar1 + 1; - (pEVar6->_vectorDeque1)._offset = GHIDRA_UINT(local_24); - uVar5 = (pEVar6->_vectorDeque2)._offset; - if (((uVar5 & 1) == 0) && - ((pEVar6->_vectorDeque2)._mapSize <= (pEVar6->_vectorDeque2)._size + 2 >> 1)) { - msvc::deque::_Growmap(fVar2); - uVar5 = (pEVar6->_vectorDeque2)._offset; - } - uVar7 = (pEVar6->_vectorDeque2)._mapSize; - uVar3 = uVar7 * 2; - uVar5 = uVar3 - 1 & uVar5; - (pEVar6->_vectorDeque2)._offset = uVar5; - if (uVar5 == 0) { - uVar5 = uVar3; - } - uVar5 = uVar5 - 1; - local_10 = GHIDRA_CAST((uVar7 - 1 & uVar5 >> 1)); - local_c = (pEVar6->_vectorDeque2)._map; - local_24 = GHIDRA_CAST(uVar5); - if (*GHIDRA_CAST((GHIDRA_CAST(local_c) + GHIDRA_INT(local_10) * 4)) == 0) { - newBlock = operator_new(0x10); - *(void **)(GHIDRA_INT((pEVar6->_vectorDeque2)._map) + GHIDRA_INT(local_10) * 4) = newBlock; - local_c = (pEVar6->_vectorDeque2)._map; - } - fVar8 = (pEVar6->_velocity).x; - posBlock = *GHIDRA_CAST((GHIDRA_CAST(local_c) + GHIDRA_INT(local_10) * 4)); - *GHIDRA_CAST((posBlock + 4 + (uVar5 & 1) * 8)) = (pEVar6->_velocity).y; - *GHIDRA_CAST((posBlock + (uVar5 & 1) * 8)) = fVar8; - puVar1 = &(pEVar6->_vectorDeque2)._size; - *puVar1 = *puVar1 + 1; - (pEVar6->_vectorDeque2)._offset = GHIDRA_UINT(local_24); - pEVar6->_groupIdx = formNpc->_groupIdx; - ANM2::LoadDeliriumForm(&pEVar6->_sprite,formNpc->_type,formNpc->_variant,1); - animData = (pEVar6->_sprite)._animState._animData; - local_24 = pEVar6; - if (animData == GHIDRA_CAST(0x0)) { -LAB_004a8acc: - bVar4 = ANM2::SetAnimation(&pEVar6->_sprite,GHIDRA_CAST("WalkBodyHori"),1); - if (bVar4 != 0) { - AnimationState::Rewind(&(pEVar6->_sprite)._animState); - (pEVar6->_sprite)._animState._isPlaying = 1; - } - } - else { - curAnimChar = animData; - if (0xf < *GHIDRA_CAST((animData + 0x14))) { - curAnimChar = *GHIDRA_CAST(animData); - } - expectedAnimChar = "WalkBodyHori"; - do { - bVar4 = *curAnimChar; - isCharLess = bVar4 < (uint8_t)*expectedAnimChar; - if (bVar4 != *expectedAnimChar) { -LAB_004a8ab6: - uVar5 = -GHIDRA_UINT(isCharLess) | 1; - goto LAB_004a8abb; - } - if (bVar4 == 0) break; - bVar4 = curAnimChar[1]; - isCharLess = bVar4 < (uint8_t)expectedAnimChar[1]; - if (bVar4 != expectedAnimChar[1]) goto LAB_004a8ab6; - curAnimChar = curAnimChar + 2; - expectedAnimChar = expectedAnimChar + 2; - } while (bVar4 != 0); - uVar5 = 0; -LAB_004a8abb: - if ((uVar5 != 0) || - ((animData[0x34] != 0 && ((pEVar6->_sprite)._animState._isPlaying == 0)))) - goto LAB_004a8acc; - } - (**(code **)(*GHIDRA_CAST(pEVar6) + 0xc))(); - segmentIndex = (float)(GHIDRA_INT(segmentIndex) + 1); - npc = local_24; - pEVar6 = formNpc; - if (segmentCount < GHIDRA_INT(segmentIndex)) { - return; - } - } while( true ); - } - } - else if (npc->_type == 0x10a) { - uVar5 = Random(); - Game::Spawn(g_game,npc->_type,1,&npc->_pos,&g_vectorZero,GHIDRA_CAST(npc),0,uVar5); - uVar5 = Random(); - Game::Spawn(g_game,npc->_type,2,&npc->_pos,&g_vectorZero,GHIDRA_CAST(npc),0,uVar5); - } - return; -} - -// 004a8b70 -void NpcHelper::delirium_fire_pattern(Entity_NPC *npc) -{ - uint8_t bVar1; - int iVar2; - Entity *target; - int iVar3; - uint32_t uVar4; - uint8_t *animNameCh; - char *expectedNameCh; - char repeatByte; - uint32_t uVar5; - int iVar6; - bool bVar7; - float fVar8; - uint8_t auVar9 [16]; - uint8_t auVar10 [16]; - int fireInterval; - uint32_t keepPatternChance; - uint32_t patternId; - float altColorizeR; - Vector projVelocity; - uint64_t local_16c; - float local_164; - uint32_t repeatsLeft; - int burstCount; - float local_158; - uint32_t extraBulletFlags; - float colorizeB; - float colorizeG; - float colorizeR; - uint32_t local_144; - uint32_t local_140; - uint32_t attackAngle; - char isAlternating; - ProjectileParams projParams; - uint8_t local_9c; - uint8_t *local_98; - uint32_t local_94; - uint8_t local_90; - float angleTable [16]; - int delayTable [17]; - uint32_t local_8; - uint32_t attackId; - uint8_t *curAnimData; - - local_8 = __security_cookie ^ GHIDRA_UINT((delayTable + 0x12)); - if (npc->_type == 0x2d) { - return; - } - if ((npc->_deliriumBossType == 0x54) && (npc->_deliriumBossVariant == 10)) { - return; - } - attackId = npc->_deliriumAttackID; - patternId = attackId & 0xff; - local_140 = attackId >> 8; - keepPatternChance = attackId >> 0x10 & 0xff; - attackAngle = GHIDRA_UINT(npc->_deliriumAttackAngle); - uVar5 = local_140 & 0xff; - repeatsLeft = uVar5; - if (patternId == 0xff) { - patternId = Random(); - patternId = patternId % 0xb; - } - iVar2 = 0; - colorizeB = 0.0; - local_144 = 6; - burstCount = 4; - projVelocity.x = 3.0; - projVelocity.y = 0.0; - isAlternating = '\0'; - local_164 = 1.26117e-44; - local_158 = 1.0; - colorizeR = 1.0; - colorizeG = 0.4; - altColorizeR = 1.0; - if (__isa_available < 2) { - iVar6 = 0; - do { - delayTable[iVar2] = iVar6; - iVar6 = iVar6 + 5; - angleTable[iVar2] = (float)iVar2 * 3.1415927; - iVar2 = iVar2 + 1; - } while (iVar6 < 0x50); - } - else { - iVar2 = 0; - do { - (*GHIDRA_CAST((GHIDRA_CAST(&(auVar10)) + 0x4))) = iVar2 + 1; - (*GHIDRA_CAST((GHIDRA_CAST(&(auVar10)) + 0x0))) = iVar2; - (*GHIDRA_CAST((GHIDRA_CAST(&(auVar10)) + 0x8))) = iVar2 + 2; - (*GHIDRA_CAST((GHIDRA_CAST(&(auVar10)) + 0xc))) = iVar2 + 3; - auVar9 = pmulld(auVar10,_DAT_00bab470); - angleTable[iVar2] = (float)iVar2 * 3.1415927; - angleTable[iVar2 + 1] = (*GHIDRA_CAST((GHIDRA_CAST(&((float)auVar10)) + 0x4))) * 3.1415927; - angleTable[iVar2 + 2] = (*GHIDRA_CAST((GHIDRA_CAST(&((float)auVar10)) + 0x8))) * 3.1415927; - angleTable[iVar2 + 3] = (*GHIDRA_CAST((GHIDRA_CAST(&((float)auVar10)) + 0xc))) * 3.1415927; - delayTable[iVar2] = GHIDRA_INT(((-GHIDRA_UINT(((*GHIDRA_CAST((GHIDRA_CAST(&(auVar9)) + 0x0))) < 0)) & 1) + (*GHIDRA_CAST((GHIDRA_CAST(&(auVar9)) + 0x0))))) >> 1; - delayTable[iVar2 + 1] = GHIDRA_INT(((-GHIDRA_UINT(((*GHIDRA_CAST((GHIDRA_CAST(&(auVar9)) + 0x4))) < 0)) & 1) + (*GHIDRA_CAST((GHIDRA_CAST(&(auVar9)) + 0x4))))) >> 1; - delayTable[iVar2 + 2] = GHIDRA_INT(((-GHIDRA_UINT(((*GHIDRA_CAST((GHIDRA_CAST(&(auVar9)) + 0x8))) < 0)) & 1) + (*GHIDRA_CAST((GHIDRA_CAST(&(auVar9)) + 0x8))))) >> 1; - delayTable[iVar2 + 3] = GHIDRA_INT(((-GHIDRA_UINT(((*GHIDRA_CAST((GHIDRA_CAST(&(auVar9)) + 0xc))) < 0)) & 1) + (*GHIDRA_CAST((GHIDRA_CAST(&(auVar9)) + 0xc))))) >> 1; - (*GHIDRA_CAST((GHIDRA_CAST(&(auVar9)) + 0x4))) = iVar2 + 5; - (*GHIDRA_CAST((GHIDRA_CAST(&(auVar9)) + 0x0))) = iVar2 + 4; - (*GHIDRA_CAST((GHIDRA_CAST(&(auVar9)) + 0x8))) = iVar2 + 6; - (*GHIDRA_CAST((GHIDRA_CAST(&(auVar9)) + 0xc))) = iVar2 + 7; - auVar10 = pmulld(auVar9,_DAT_00bab470); - angleTable[iVar2 + 4] = (float)(iVar2 + 4) * 3.1415927; - angleTable[iVar2 + 5] = (*GHIDRA_CAST((GHIDRA_CAST(&((float)auVar9)) + 0x4))) * 3.1415927; - angleTable[iVar2 + 6] = (*GHIDRA_CAST((GHIDRA_CAST(&((float)auVar9)) + 0x8))) * 3.1415927; - angleTable[iVar2 + 7] = (*GHIDRA_CAST((GHIDRA_CAST(&((float)auVar9)) + 0xc))) * 3.1415927; - delayTable[iVar2 + 4] = GHIDRA_INT(((-GHIDRA_UINT(((*GHIDRA_CAST((GHIDRA_CAST(&(auVar10)) + 0x0))) < 0)) & 1) + (*GHIDRA_CAST((GHIDRA_CAST(&(auVar10)) + 0x0))))) >> 1; - delayTable[iVar2 + 5] = GHIDRA_INT(((-GHIDRA_UINT(((*GHIDRA_CAST((GHIDRA_CAST(&(auVar10)) + 0x4))) < 0)) & 1) + (*GHIDRA_CAST((GHIDRA_CAST(&(auVar10)) + 0x4))))) >> 1; - delayTable[iVar2 + 6] = GHIDRA_INT(((-GHIDRA_UINT(((*GHIDRA_CAST((GHIDRA_CAST(&(auVar10)) + 0x8))) < 0)) & 1) + (*GHIDRA_CAST((GHIDRA_CAST(&(auVar10)) + 0x8))))) >> 1; - delayTable[iVar2 + 7] = GHIDRA_INT(((-GHIDRA_UINT(((*GHIDRA_CAST((GHIDRA_CAST(&(auVar10)) + 0xc))) < 0)) & 1) + (*GHIDRA_CAST((GHIDRA_CAST(&(auVar10)) + 0xc))))) >> 1; - iVar2 = iVar2 + 8; - } while (iVar2 < 0x10); - } - local_16c = 0; - repeatByte = (char)local_140; - switch(patternId) { - case 0: - fireInterval = 0x12; - local_144 = 0x14; - burstCount = 1; - if (uVar5 == 0xff) { - uVar5 = 2; - } - projVelocity.x = 2.5; - isAlternating = '\x01'; - colorizeR = 2.0; - colorizeG = 2.0; - colorizeB = 2.0; - altColorizeR = 3.0; - extraBulletFlags = 0x8000000; - local_158 = 3.0; - break; - case 1: - fireInterval = 0x19; - local_144 = 8; - burstCount = 1; - projVelocity.x = 4.0; - colorizeR = 2.0; - colorizeG = 2.8; - colorizeB = 2.0; - extraBulletFlags = 2; - goto LAB_004a9349; - case 2: - fireInterval = 5; - local_144 = 6; - projVelocity.x = 4.5; - burstCount = 1; - delayTable[0] = 0; - angleTable[0] = 0.3926991; - colorizeR = 2.6; - colorizeG = 2.6; - colorizeB = 2.6; - extraBulletFlags = 0x800000; - goto LAB_004a9349; - case 3: - iVar3 = 0; - local_144 = 1; - fireInterval = 0x19; - iVar6 = 0; - projVelocity.x = 4.0; - burstCount = 0xc; - iVar2 = 0; - do { - *GHIDRA_CAST((GHIDRA_CAST(delayTable) + iVar6)) = iVar3; - *GHIDRA_CAST((GHIDRA_CAST(delayTable) + iVar6 + 0xc)) = iVar3; - iVar3 = iVar3 + 10; - *GHIDRA_CAST((GHIDRA_CAST(delayTable) + iVar6 + 0x18)) = *GHIDRA_CAST((GHIDRA_CAST(delayTable) + iVar6)); - fVar8 = (float)iVar2 * 1.0471976; - *GHIDRA_CAST((GHIDRA_CAST(delayTable) + iVar6 + 0x24)) = *GHIDRA_CAST((GHIDRA_CAST(delayTable) + iVar6)); - *GHIDRA_CAST((GHIDRA_CAST(angleTable) + iVar6)) = fVar8; - *GHIDRA_CAST((GHIDRA_CAST(angleTable) + iVar6 + 0xc)) = fVar8 + 3.1415927; - *GHIDRA_CAST((GHIDRA_CAST(angleTable) + iVar6 + 0x18)) = fVar8 + 1.5707964; - *GHIDRA_CAST((GHIDRA_CAST(angleTable) + iVar6 + 0x24)) = fVar8 + 3.1415927 + 1.5707964; - iVar6 = iVar6 + 4; - iVar2 = iVar2 + 1; - } while (iVar6 < 0xc); - if (repeatByte == -1) { - uVar5 = 3; - } - colorizeR = 3.4; - colorizeG = 3.4; - colorizeB = 3.4; - local_158 = 1.0; - extraBulletFlags = 0; - break; - case 4: - fireInterval = 0x14; - attackAngle = attackAngle + 3; - local_144 = 0x14; - burstCount = 1; - if (repeatByte == -1) { - uVar5 = 4; - } - projVelocity.x = 5.0; - colorizeR = 2.4; - colorizeG = 2.4; - colorizeB = 2.4; - extraBulletFlags = 0x20; - local_158 = 1.0; - repeatsLeft = uVar5; - goto LAB_004a9394; - case 5: - attackAngle = attackAngle + 2; - fireInterval = 0x14; - local_144 = 10; - if (repeatByte == -1) { - uVar5 = 2; - } - burstCount = 1; - isAlternating = '\x01'; - colorizeR = 3.6; - colorizeG = 3.6; - colorizeB = 3.6; - altColorizeR = 2.2; - extraBulletFlags = 0x400000; - local_158 = 2.2; - break; - case 6: - colorizeB = 3.8; - extraBulletFlags = 0x800; - goto LAB_004a9111; - case 7: - colorizeB = 4.0; - extraBulletFlags = 0x1000; -LAB_004a9111: - uVar4 = 2; - projVelocity.x = 5.0; - local_144 = 0xe; - fireInterval = 0x19; -LAB_004a912d: - burstCount = 1; - if (repeatByte == -1) { - uVar5 = uVar4; - } - local_158 = 1.0; - colorizeG = colorizeB; - colorizeR = colorizeB; - break; - case 8: - attackAngle = attackAngle + 4; - fireInterval = 10; - colorizeB = 2.6; - local_144 = 10; - projVelocity.x = 4.0; - uVar4 = 3; - extraBulletFlags = 0x200000; - goto LAB_004a912d; - case 9: - fireInterval = 0x1e; - attackAngle = attackAngle + 2; - local_144 = 0xe; - projVelocity.x = 4.0; - colorizeR = 2.6; - colorizeG = 2.6; - colorizeB = 2.6; - goto LAB_004a933d; - case 10: - burstCount = 1; - fireInterval = 0x12; - target = Entity_NPC::GetPlayerTarget(npc); - local_158 = (target->_pos).y - (npc->_pos).y; - local_164 = (target->_pos).x - (npc->_pos).x; - fVar8 = sqrtf(local_158 * local_158 + local_164 * local_164); - if (0.0 < fVar8) { - local_158 = local_158 * (1.0 / fVar8); - local_164 = local_164 * (1.0 / fVar8); - } - colorizeB = 3.6; - projVelocity.x = local_164 * 4.0; - if ((char)local_140 == -1) { - uVar5 = 4; - } - local_164 = 7.00649e-45; - projVelocity.y = local_158 * 4.0; - local_158 = 1.0; - extraBulletFlags = 0; - colorizeG = colorizeB; - colorizeR = colorizeB; - break; - default: - fireInterval = 10; -LAB_004a933d: - extraBulletFlags = 0; -LAB_004a9349: - isAlternating = '\0'; - local_164 = 1.26117e-44; - altColorizeR = 1.0; - if (uVar5 == 0xff) { - uVar5 = 1; - isAlternating = '\0'; - local_164 = 1.26117e-44; - altColorizeR = 1.0; - break; - } - goto LAB_004a938e; - } - repeatsLeft = uVar5; -LAB_004a938e: -LAB_004a9394: - uVar5 = local_144; - local_140 = 0; - iVar2 = 4; - if (npc->_type == 0x19c) { - iVar2 = 1; - } - bVar7 = false; - iVar6 = 0; - local_16c = (uint64_t)GHIDRA_UINT((((float)GHIDRA_INT(attackAngle) / 255.0) * 6.2831855)) << 0x20; - do { - iVar3 = (attackId >> 0x18) - delayTable[iVar6]; - local_144 = iVar3 / (iVar2 * fireInterval); - if (iVar3 % (iVar2 * fireInterval) == 0) { - (*GHIDRA_CAST((GHIDRA_CAST(&(projParams)) + 0x0))) = 1; - (*GHIDRA_CAST((GHIDRA_CAST(&(projParams)) + 0x4))) = 0; - projParams.FallingSpeedModifier = 0.0; - projParams.FallingAccelModifier = 0.0; - projParams.VelocityMulti = 1.0; - projParams.Scale = 1.0; - uVar4 = Random(); - projParams.Color._offset[0] = 0.0; - projParams.Color._offset[1] = 0.0; - projParams.Color._offset[2] = 0.0; - projParams.DotProductLimit = -1000.0; - projParams.WiggleFrameOffset = 0; - projParams.ChangeVelocity = 0.0; - projParams.PositionOffset.x = g_vectorZero.x; - projParams.TargetPosition.x = g_vectorZero.x; - projParams.FireDirectionLimit.x = g_vectorZero.x; - projParams.ChangeTimeout = 0x1e; - projParams.DepthOffset = 0.0; - projParams.Variant = 0; - local_9c = 0; - local_98 = &DAT_bf800000; - local_94 = 0; - local_90 = 0; - (*GHIDRA_CAST((GHIDRA_CAST(&(projParams)) + 0x4))) = 0x40a00000; - projParams.CircleAngle = - (float)((double)GHIDRA_INT(uVar4) + __uint_to_double_fixup[-(GHIDRA_INT(uVar4) >> 0x1f)]) * - 2.3283064e-10 * 3.1415927; - projParams.HomingStrength = 1.0; - projParams.CurvingStrength = 0.005; - projParams.Acceleration = 1.01; - projParams.Spread = 1.0; - projParams.Color._tint[0] = 1.0; - projParams.Color._tint[1] = 1.0; - projParams.Color._tint[2] = 1.0; - projParams.Color._tint[3] = 1.0; - projParams.Color._colorize[0] = 0.0; - projParams.Color._colorize[1] = 0.0; - projParams.Color._colorize[2] = 0.0; - projParams.Color._colorize[3] = 0.0; - projParams.BulletFlags = 0; - projParams.PositionOffset.y = g_vectorZero.y; - projParams.TargetPosition.y = g_vectorZero.y; - projParams.FireDirectionLimit.y = g_vectorZero.y; - projParams.ChangeFlags = 0; - uVar4 = Random(); - projParams.FallingAccelModifier = -0.06; - projParams.FallingSpeedModifier = -3.2; - (*GHIDRA_CAST((GHIDRA_CAST(&(projParams.BulletFlags)) + 0x0))) = GHIDRA_UINT(projParams.BulletFlags) | extraBulletFlags; - projParams.Color._colorize[3] = 1.0; - projParams.Scale = - (float)((double)GHIDRA_INT((uVar4 % 0xffffffff)) + - __uint_to_double_fixup[-(GHIDRA_INT((uVar4 % 0xffffffff)) >> 0x1f)]) * 2.3283064e-10 + - 1.5; - projParams.TargetPosition.x = (npc->_pos).x; - projParams.TargetPosition.y = (npc->_pos).y; - projParams.CircleAngle = (*GHIDRA_CAST((GHIDRA_CAST(&(local_16c)) + 0x4))) + angleTable[iVar6]; - projParams.Color._colorize[0] = colorizeR; - projParams.Color._colorize[1] = colorizeG; - projParams.Color._colorize[2] = colorizeB; - if (isAlternating != '\0') { - if ((local_144 & 1) == 0) { - (*GHIDRA_CAST((GHIDRA_CAST(&(projParams.BulletFlags)) + 0x0))) = GHIDRA_UINT(projParams.BulletFlags) | 0x80000; - projParams.Color._colorize[0] = altColorizeR; - projParams.Color._colorize[1] = local_158; - projParams.Color._colorize[2] = local_158; - } - else { - (*GHIDRA_CAST((GHIDRA_CAST(&(projParams.BulletFlags)) + 0x0))) = GHIDRA_UINT(projParams.BulletFlags) | 0x40000; - } - } - projParams.BulletFlags = - CONCAT44((*GHIDRA_CAST((GHIDRA_CAST(&(projParams.BulletFlags)) + 0x4))) | local_140,GHIDRA_UINT(projParams.BulletFlags)); - if (local_164 == 1.26117e-44) { - projVelocity.y = (float)GHIDRA_INT(uVar5); - } - Entity_NPC::FireProjectiles(npc,&npc->_pos,&projVelocity,GHIDRA_UINT(local_164),&projParams); - bVar7 = true; - } - uVar4 = repeatsLeft; - iVar6 = iVar6 + 1; - } while (iVar6 < burstCount); - if (!bVar7) goto LAB_004a97bc; - if (npc->_type == 0x19c) { - curAnimData = (npc->_sprite)._animState._animData; - if (curAnimData != GHIDRA_CAST(0x0)) { - animNameCh = curAnimData; - if (0xf < *GHIDRA_CAST((curAnimData + 0x14))) { - animNameCh = *GHIDRA_CAST(curAnimData); - } - expectedNameCh = "Blink"; - do { - bVar1 = *animNameCh; - bVar7 = bVar1 < (uint8_t)*expectedNameCh; - if (bVar1 != *expectedNameCh) { -LAB_004a9717: - uVar5 = -GHIDRA_UINT(bVar7) | 1; - goto LAB_004a971c; - } - if (bVar1 == 0) break; - bVar1 = animNameCh[1]; - bVar7 = bVar1 < (uint8_t)expectedNameCh[1]; - if (bVar1 != expectedNameCh[1]) goto LAB_004a9717; - animNameCh = animNameCh + 2; - expectedNameCh = expectedNameCh + 2; - } while (bVar1 != 0); - uVar5 = 0; -LAB_004a971c: - if ((uVar5 == 0) && ((curAnimData[0x34] == 0 || ((npc->_sprite)._animState._isPlaying != 0)))) - goto LAB_004a9753; - } - bVar1 = ANM2::SetAnimation(&npc->_sprite,GHIDRA_CAST("Blink"),1); - if (bVar1 != 0) { - AnimationState::Rewind(&(npc->_sprite)._animState); - (npc->_sprite)._animState._isPlaying = 1; - } - } -LAB_004a9753: - uVar4 = uVar4 - 1; - if (GHIDRA_INT(uVar4) < 1) { - uVar5 = Random(); - if (uVar5 % 100 < keepPatternChance) { - keepPatternChance = keepPatternChance - 10; - } - else { - do { - uVar5 = Random(); - } while (uVar5 % 0xb == patternId); - keepPatternChance = 0x1e; - attackAngle = Random(); - attackAngle = attackAngle % 0xff; - patternId = uVar5 % 0xb; - } - uVar4 = 0xff; - } -LAB_004a97bc: - *GHIDRA_CAST(&npc->_deliriumAttackAngle) = attackAngle & 0xff; - npc->_deliriumAttackID = - ((((attackId >> 0x18) + 1 & 0xff) << 8 | keepPatternChance & 0xff) << 8 | uVar4 & 0xff) << 8 - | patternId; - /* WARNING: Read-only address (ram,0x00bab470) is written */ - return; -} - -// 004a9860 -void NpcHelper::delirium_morph_update(Entity_NPC *npc) -{ - int iVar1; - uint8_t isAnimSet; - uint32_t nextCycleCount; - int iVar2; - uint32_t uVar3; - uint32_t uVar4; - float fVar5; - float stepFraction; - double dVar6; - float fVar7; - uint8_t *anim; - float local_28; - float local_24; - uint32_t chanceDivisor; - float local_1c; - uint32_t aiUpdateCount; - int step; - float stepVelocityY; - float stepVelocityX; - uint32_t cycleTime; - uint32_t cycleId; - Manager *manager; - - local_28 = npc->_health; - if (local_28 == 0.0) { - return; - } - cycleId = npc->_deliriumCycleID; - local_24 = npc->_maxHitPoints; - uVar4 = cycleId >> 7 & 0xff; - cycleTime = cycleId >> 0x19 | (npc->_deliriumCycleIDHigh & 7U) << 7; - if (local_24 == 0.0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("Start and End parameters cannot be the same!")); - } - local_1c = (float)__ftoui3(); - uVar3 = cycleTime; - stepVelocityX = (npc->_velocity).x; - stepVelocityY = (npc->_velocity).y; - aiUpdateCount = GHIDRA_INT(local_1c) + 1; - chanceDivisor = 3 - GHIDRA_INT(local_1c); - nextCycleCount = uVar4 - 1; - if (uVar4 == 0) { - nextCycleCount = 0; - fVar7 = local_1c; - } - else { - fVar7 = 4.2039e-45; - } - iVar2 = npc->_type; - iVar1 = GHIDRA_INT(fVar7) >> 0x1f; - if (iVar2 < 0x194) { - if (iVar2 == 0x193) { -switchD_004a998d_caseD_45: - fVar5 = (float)((double)GHIDRA_INT(fVar7) + __uint_to_double_fixup[-iVar1]) / 3.0; - stepVelocityX = stepVelocityX * fVar5; - stepVelocityY = stepVelocityY * fVar5; - goto switchD_004a998d_caseD_15; - } - switch(iVar2) { - case 0x13: - case 0x1c: - case 0x61: - case 99: - case 100: - case 0xed: - case 0x10b: - fVar5 = (float)((double)GHIDRA_INT(fVar7) + __uint_to_double_fixup[-iVar1]) / 3.0; - stepVelocityX = stepVelocityX * 0.20000005 * fVar5; - stepVelocityY = stepVelocityY * 0.20000005 * fVar5; - break; - case 0x14: - case 0x52: - goto switchD_004a998d_caseD_14; - case 0x24: - case 0x2b: - case 0x4e: - case 0x106: - if (cycleTime < 0x1e) { - if (npc->_state == 8) { - npc->_state = 3; - } - } - else if (npc->_state != 8) goto LAB_004a9b6d; - local_24 = npc->_maxHitPoints; - local_28 = npc->_health; - if (local_24 == 0.0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("Start and End parameters cannot be the same!")); - } - fVar7 = (float)__ftoui3(); - aiUpdateCount = GHIDRA_INT(fVar7) + 1; - local_1c = fVar7; - goto LAB_004a9b6d; - case 0x2d: - if ((0x3c < cycleTime) && (iVar2 = Isaac::Random(chanceDivisor), iVar2 == 0)) { - npc->_projectileCooldown = 0; - } - local_24 = npc->_maxHitPoints; - local_28 = npc->_health; - if (local_24 == 0.0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("Start and End parameters cannot be the same!")); - } - goto LAB_004a9d83; - case 0x3e: - if (npc->_variant == 0) { - fVar5 = 1.2; - } - else { - fVar5 = 2.0; - } - stepFraction = (float)((double)GHIDRA_INT(fVar7) + __uint_to_double_fixup[-iVar1]) / 3.0; - stepVelocityX = stepVelocityX * (fVar5 - 1.0) * stepFraction; - stepVelocityY = stepVelocityY * (fVar5 - 1.0) * stepFraction; - break; - case 0x3f: - fVar5 = (float)((double)GHIDRA_INT(fVar7) + __uint_to_double_fixup[-iVar1]) / 3.0; - stepVelocityX = stepVelocityX * 1.5 * fVar5; - stepVelocityY = stepVelocityY * 1.5 * fVar5; - break; - case 0x41: - fVar5 = (float)((double)GHIDRA_INT(fVar7) + __uint_to_double_fixup[-iVar1]) / 3.0; - if (npc->_variant == 10) { - stepVelocityX = stepVelocityX * 0.0 * fVar5; - stepVelocityY = stepVelocityY * 0.0 * fVar5; - break; - } - if (npc->_variant == 1) goto LAB_004a9b8f; - stepVelocityX = stepVelocityX * 1.5; - stepVelocityY = stepVelocityY * 1.5; - goto LAB_004a9b9f; - case 0x43: - if (npc->_variant != 1) goto LAB_004aa3d4; -LAB_004a9b6d: - fVar5 = (float)((double)GHIDRA_INT(fVar7) + __uint_to_double_fixup[-(GHIDRA_INT(fVar7) >> 0x1f)]) / 3.0; -LAB_004a9b8f: - stepVelocityX = stepVelocityX * 0.39999998; - stepVelocityY = stepVelocityY * 0.39999998; -LAB_004a9b9f: - stepVelocityX = stepVelocityX * fVar5; - stepVelocityY = stepVelocityY * fVar5; - goto LAB_004aa3d4; - case 0x44: - if (npc->_variant != 1) goto LAB_004aa3d4; - iVar2 = npc->_state; - if (cycleTime < 0x1e) { - if ((iVar2 == 9) || (iVar2 == 10)) { - npc->_state = 3; - } - } - else if ((iVar2 != 9) && (iVar2 != 10)) goto LAB_004aa3d4; - local_24 = npc->_maxHitPoints; - local_28 = npc->_health; - if (local_24 == 0.0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("Start and End parameters cannot be the same!")); - } -LAB_004a9d83: - fVar7 = (float)__ftoui3(); - aiUpdateCount = GHIDRA_INT(fVar7) + 1; - local_1c = fVar7; - goto LAB_004aa3d4; - case 0x45: - goto switchD_004a998d_caseD_45; - case 0x4a: - goto switchD_004a998d_caseD_4a; - case 0x4f: - if (npc->_variant == 2) { - fVar5 = 1.1; - } - else { - fVar5 = 1.2; - } - stepFraction = (float)((double)GHIDRA_INT(fVar7) + __uint_to_double_fixup[-iVar1]) / 3.0; - stepVelocityX = stepVelocityX * (fVar5 - 1.0) * stepFraction; - stepVelocityY = stepVelocityY * (fVar5 - 1.0) * stepFraction; - break; - case 0x51: - npc->_maxHitPoints = npc->_health; - goto switchD_004a998d_caseD_4a; - case 0x54: - if (npc->_variant == 10) { - iVar2 = Isaac::Random(chanceDivisor); - if (iVar2 == 0) { - npc->_stateFrame = 0; - } - fVar7 = (float)((double)GHIDRA_INT(fVar7) + __uint_to_double_fixup[-iVar1]) / 3.0; - stepVelocityX = stepVelocityX * 0.20000005 * fVar7; - stepVelocityY = stepVelocityY * 0.20000005 * fVar7; - local_28 = npc->_health; - local_24 = npc->_maxHitPoints; - if (local_24 == 0.0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("Start and End parameters cannot be the same!")); - } - } - else { - fVar7 = (float)((double)GHIDRA_INT(fVar7) + __uint_to_double_fixup[-iVar1]) / 3.0; - stepVelocityX = stepVelocityX * 0.0 * fVar7; - stepVelocityY = stepVelocityY * 0.0 * fVar7; - local_28 = npc->_health; - local_24 = npc->_maxHitPoints; - if (local_24 == 0.0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("Start and End parameters cannot be the same!")); - } - } - goto LAB_004aa3bf; - case 0x65: - local_1c = 0.0; - break; - case 0x66: - local_24 = npc->_maxHitPoints; - local_28 = npc->_health; - if (local_24 == 0.0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("Start and End parameters cannot be the same!")); - } - fVar7 = (float)__ftoui3(); - fVar5 = (float)((double)GHIDRA_INT(fVar7) + __uint_to_double_fixup[-(GHIDRA_INT(fVar7) >> 0x1f)]) / 3.0; - stepVelocityX = stepVelocityX * 0.6 * fVar5; - stepVelocityY = stepVelocityY * 0.6 * fVar5; - goto LAB_004aa3cc; - case 0x105: - aiUpdateCount = 2; - fVar5 = (float)((double)GHIDRA_INT(fVar7) + __uint_to_double_fixup[-iVar1]) / 3.0; - stepVelocityX = stepVelocityX * 0.20000005 * fVar5; - stepVelocityY = stepVelocityY * 0.20000005 * fVar5; - break; - case 0x107: - dVar6 = __uint_to_double_fixup[-iVar1]; - (npc->_pos).x = (npc->_targetPosition).x; - (npc->_pos).y = (npc->_targetPosition).y; - fVar5 = (float)((double)GHIDRA_INT(fVar7) + dVar6) / 3.0; - stepVelocityX = stepVelocityX * -1.0 * fVar5; - stepVelocityY = stepVelocityY * -1.0 * fVar5; - break; - case 0x109: - if (npc->_state == 6) goto switchD_004aa2e2_caseD_197; - break; - case 0x10c: - fVar7 = (float)((double)GHIDRA_INT(fVar7) + __uint_to_double_fixup[-iVar1]) / 3.0; - stepVelocityX = stepVelocityX * 0.20000005 * fVar7; - stepVelocityY = stepVelocityY * 0.20000005 * fVar7; - local_24 = npc->_health; - local_1c = npc->_maxHitPoints; - if (npc->_state == 8) { - if (local_1c == 0.0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("Start and End parameters cannot be the same!")); - } - } - else if (local_1c == 0.0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("Start and End parameters cannot be the same!")); - } - goto LAB_004aa3bf; - case 0x10f: - case 0x110: - case 0x111: - aiUpdateCount = 1; - fVar5 = (float)((double)GHIDRA_INT(fVar7) + __uint_to_double_fixup[-iVar1]) / 3.0; - stepVelocityX = stepVelocityX * 0.20000005 * fVar5; - stepVelocityY = stepVelocityY * 0.20000005 * fVar5; - } - goto switchD_004a998d_caseD_15; - } - switch(iVar2) { - case 0x194: - fVar7 = (float)((double)GHIDRA_INT(fVar7) + __uint_to_double_fixup[-iVar1]) / 3.0; - stepVelocityX = stepVelocityX * fVar7; - stepVelocityY = stepVelocityY * fVar7; - goto LAB_004aa34b; - case 0x195: -switchD_004a998d_caseD_14: - fVar5 = (float)((double)GHIDRA_INT(fVar7) + __uint_to_double_fixup[-iVar1]) / 3.0; - stepVelocityX = stepVelocityX * 0.39999998 * fVar5; - stepVelocityY = stepVelocityY * 0.39999998 * fVar5; - break; - case 0x197: -switchD_004aa2e2_caseD_197: - local_24 = npc->_maxHitPoints; - local_28 = npc->_health; - if (local_24 == 0.0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("Start and End parameters cannot be the same!")); - } - goto LAB_004aa3bf; - case 0x19a: - fVar7 = (float)((double)GHIDRA_INT(fVar7) + __uint_to_double_fixup[-iVar1]) / 3.0; - stepVelocityX = stepVelocityX * 0.6 * fVar7; - stepVelocityY = stepVelocityY * 0.6 * fVar7; -LAB_004aa34b: - local_28 = npc->_health; - local_24 = npc->_maxHitPoints; - if (local_24 == 0.0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("Start and End parameters cannot be the same!")); - } -LAB_004aa3bf: - fVar7 = (float)__ftoui3(); -LAB_004aa3cc: - aiUpdateCount = GHIDRA_INT(fVar7) + 1; - local_1c = fVar7; - } -switchD_004a998d_caseD_15: - uVar3 = cycleTime; -LAB_004aa3d4: - if (GHIDRA_UINT((GHIDRA_INT(fVar7) * 4)) < uVar3) { - step = 0; - do { - uVar4 = chanceDivisor; - dVar6 = 10.0; - switch(npc->_type) { - case 0x14: - case 0x2b: - if ((npc->_state == 3) && ((chanceDivisor == 0 || (uVar3 = Random(), uVar3 % uVar4 == 0)))) - { - uVar4 = Random(); - if ((uVar4 & 1) == 0) { - npc->_state = 8; - anim = GHIDRA_CAST("Taunt"); - } - else { - if ((uVar4 & 1) != 1) break; - local_24 = 1.0; - npc->_state = 6; - manager = g_manager; - if (npc->_championColorIdx == 0x12) { - local_24 = 1.5; - } - else if (npc->_championColorIdx == 0x13) { - local_24 = 0.5; - } - local_28 = 1.96182e-44; - seed_fart_sound_override(GHIDRA_CAST(&local_28)); - (GHIDRA_CAST((&manager->_sfxManager)))->SoundEffects::Play(GHIDRA_INT(local_28),1.0,2,0,local_24,0.0); - anim = &DAT_00b1e0e4; - } -LAB_004aa517: - isAnimSet = ANM2::SetAnimation(&npc->_sprite,anim,1); - if (isAnimSet != 0) { - AnimationState::Rewind(&(npc->_sprite)._animState); - (npc->_sprite)._animState._isPlaying = 1; - } - } - break; - case 0x1c: - if ((((npc->_variant == 0) && (npc->_state == 4)) && - ((chanceDivisor == 0 || (uVar3 = Random(), uVar3 % uVar4 == 0)))) && - (npc->_stateFrame == 0)) { - npc->_state = 0xd; - } - break; - case 0x40: - if (npc->_state == 4) { - libm_sse2_pow_precise(); - if ((GHIDRA_INT(dVar6) == 0) || (uVar4 = Random(), uVar4 % GHIDRA_UINT(GHIDRA_INT(dVar6)) == 0)) { - uVar4 = Random(); - npc->_stateFrame = 0; - if ((uVar4 & 1) == 0) { - npc->_state = 0xd; - anim = s_Attack2; - if (npc->_i1 != 0) { - anim = GHIDRA_CAST("HeadlessAttack2"); - } - } - else { - npc->_state = 8; - anim = s_Attack1; - if (npc->_i1 != 0) { - anim = GHIDRA_CAST("HeadlessAttack1"); - } - } - goto LAB_004aa517; - } - } - break; - case 0x41: - if ((npc->_state == 4) && (npc->_variant != 10)) { - libm_sse2_pow_precise(); - if ((GHIDRA_INT(dVar6) == 0) || (uVar4 = Random(), uVar4 % GHIDRA_UINT(GHIDRA_INT(dVar6)) == 0)) { - uVar4 = Random(); - if ((uVar4 & 1) == 0) { - npc->_state = 8; - npc->_stateFrame = 0; - anim = s_Attack1; - } - else { - uVar4 = Random(); - manager = g_manager; - local_24 = 1.0; - if (npc->_championColorIdx == 0x12) { - local_24 = 1.5; - } - else if (npc->_championColorIdx == 0x13) { - local_24 = 0.5; - } - local_28 = (float)((uVar4 & 3) + 0x73); - seed_fart_sound_override(GHIDRA_CAST(&local_28)); - (GHIDRA_CAST((&manager->_sfxManager)))->SoundEffects::Play(GHIDRA_INT(local_28),1.0,2,0,local_24,0.0); - npc->_state = 6; - npc->_stateFrame = 0; - anim = s_Attack2; - } - goto LAB_004aa517; - } - } - break; - case 0x42: - if ((npc->_state == 4) && (npc->_variant != 10)) { - libm_sse2_pow_precise(); - if ((GHIDRA_INT(dVar6) == 0) || (uVar4 = Random(), uVar4 % GHIDRA_UINT(GHIDRA_INT(dVar6)) == 0)) { - if (npc->_variant == 0x1e) { -LAB_004aa7f9: - npc->_state = 0xd; - } - else { - uVar4 = Random(); - uVar4 = uVar4 % 3; - if (uVar4 == 0) goto LAB_004aa7f9; - if (uVar4 == 1) { - npc->_state = 8; - } - else if (uVar4 == 2) { - npc->_state = 0xe; - } - } - npc->_stateFrame = 0; - } - } - break; - case 0x4a: - if (npc->_state == 0x10) { - npc->_state = 3; - } - } - if (step != 0) { - if ((GHIDRA_UINT(step) <= GHIDRA_UINT(local_1c)) && ((npc->_sprite)._loaded != 0)) { - AnimationState::Update(&(npc->_sprite)._animState); - AnimationState::Update(&(npc->_sprite)._overlayAnimState); - } - (npc->_pos).x = stepVelocityX + (npc->_pos).x; - (npc->_pos).y = stepVelocityY + (npc->_pos).y; - } - if (GHIDRA_UINT(step) < aiUpdateCount) { - Entity_NPC_UpdateAI_dispatch(npc); - } - step = step + 1; - } while (GHIDRA_UINT(step) <= GHIDRA_UINT(fVar7)); - npc->_deliriumCycleIDHigh = 0; - npc->_deliriumCycleID = - ((cycleId >> 0xf & 0x3ff | cycleTime << 10) << 8 | nextCycleCount & 0xff) << 7 | - cycleId & 0x7f; - } - else if ((npc->_sprite)._loaded != 0) { - AnimationState::Update(&(npc->_sprite)._animState); - AnimationState::Update(&(npc->_sprite)._overlayAnimState); - return; - } - return; -switchD_004a998d_caseD_4a: - fVar5 = (float)((double)GHIDRA_INT(fVar7) + __uint_to_double_fixup[-iVar1]) / 3.0; - stepVelocityX = stepVelocityX * 0.6 * fVar5; - stepVelocityY = stepVelocityY * 0.6 * fVar5; - goto switchD_004a998d_caseD_15; -} - // 004b3af0 Entity * NpcHelper::heretic_spawn_afterimage(Entity_NPC *npc) { diff --git a/generated-src/stubs.cpp b/generated-src/stubs.cpp index bc83112..3638b7c 100644 --- a/generated-src/stubs.cpp +++ b/generated-src/stubs.cpp @@ -8349,7 +8349,6 @@ void Vector::Resize(float length) { generated_stub("Vector::Resize 00a100b0"); } Vector * Vector::Resized(Vector *outVec, float length) { generated_stub("Vector::Resized 00a10100"); } float Vector::Dot(Vector *other) { generated_stub("Vector::Dot 00a10180"); } float Vector::Cross(Vector *other) { generated_stub("Vector::Cross 00a101a0"); } -void Vector::Lerp(Vector *target, float t, uint8_t isClamped) { generated_stub("Vector::Lerp 00a10210"); } void Vector::Rotate(float angleDegrees) { generated_stub("Vector::Rotate 00a10270"); } Vector * Vector::Rotated(Vector *outVec, float angleDegrees) { generated_stub("Vector::Rotated 00a102e0"); } Vector * Vector::FromAngle(Vector *outVec, float angleDegrees) { generated_stub("Vector::FromAngle 00a10350"); } @@ -9225,10 +9224,6 @@ int * NpcHelper::chub_nearest_segment(int *param_1, int param_2) { generated_stu void NpcHelper::chimera_charge_begin(Entity_NPC *npc, Vector *target, float speed) { generated_stub("NpcHelper::chimera_charge_begin 0049f870"); } Vector * NpcHelper::colostomia_pick_target(Entity_NPC *npc, Vector *outTarget, uint8_t *isPlayerPos) { generated_stub("NpcHelper::colostomia_pick_target 004a2940"); } void NpcHelper::colostomia_pick_dive_target(Entity_NPC *npc) { generated_stub("NpcHelper::colostomia_pick_dive_target 004a2ce0"); } -void NpcHelper::delirium_remove_minions(int type, int variant, Entity *self, Entity *other) { generated_stub("NpcHelper::delirium_remove_minions 004a6240"); } -void NpcHelper::delirium_spawn_form_parts(Entity_NPC *npc, float maxHealth) { generated_stub("NpcHelper::delirium_spawn_form_parts 004a8680"); } -void NpcHelper::delirium_fire_pattern(Entity_NPC *npc) { generated_stub("NpcHelper::delirium_fire_pattern 004a8b70"); } -void NpcHelper::delirium_morph_update(Entity_NPC *npc) { generated_stub("NpcHelper::delirium_morph_update 004a9860"); } Entity * NpcHelper::heretic_spawn_afterimage(Entity_NPC *npc) { generated_stub("NpcHelper::heretic_spawn_afterimage 004b3af0"); } int NpcHelper::heretic_count_out_fires() { generated_stub("NpcHelper::heretic_count_out_fires 004b3ec0"); } void NpcHelper::heretic_choose_attack(Entity_NPC *npc) { generated_stub("NpcHelper::heretic_choose_attack 004b40d0"); } @@ -9379,8 +9374,6 @@ uint32_t SteamCloudFile::FUN_00a253e0(uint8_t *param_1) { generated_stub("SteamC void SteamCloudFile::vfunc_11() { generated_stub("SteamCloudFile::vfunc_11 0040c200"); } void SteamCloudFile::FUN_00a25450() { generated_stub("SteamCloudFile::FUN_00a25450 006839b0"); } void TexturePtr::release() { generated_stub("TexturePtr::release 0040c440"); } -UmbilicalBabyData::~UmbilicalBabyData() { generated_stub("UmbilicalBabyData::~UmbilicalBabyData 00431790"); } -uint32_t UmbilicalBabyData::last_point() { generated_stub("UmbilicalBabyData::last_point 00435590"); } void UserProfile::find_or_create() { generated_stub("UserProfile::find_or_create 00a23ae0"); } msvc::exception::~exception() { generated_stub("msvc::exception::~exception 0040ce20"); } char * msvc::exception::FUN_0040d0d0() { generated_stub("msvc::exception::FUN_0040d0d0 0040d0d0"); } @@ -9814,9 +9807,6 @@ void FUN_00431620(Entity *param_1) { generated_stub("FUN_00431620 00431620"); } void FUN_004316b0(uint32_t param_1) { generated_stub("FUN_004316b0 004316b0"); } void FUN_004316c0() { generated_stub("FUN_004316c0 004316c0"); } void FUN_00431700() { generated_stub("FUN_00431700 00431700"); } -void FUN_00431790(uint8_t param_1) { generated_stub("FUN_00431790 00431790"); } -void FamiliarHelper::umbilical_baby_load_graphics(Entity_Familiar *familiar) { generated_stub("FamiliarHelper::umbilical_baby_load_graphics 00431830"); } -void FUN_00435130(Vector *param_1) { generated_stub("FUN_00435130 00435130"); } void FUN_00435740() { generated_stub("FUN_00435740 00435740"); } uint32_t FUN_00435880(uint32_t param_1) { generated_stub("FUN_00435880 00435880"); } uint32_t FUN_004358b0() { generated_stub("FUN_004358b0 004358b0"); } @@ -9881,11 +9871,6 @@ void FUN_00450880(uint32_t param_1) { generated_stub("FUN_00450880 00450880"); } void FUN_004508a0(uint32_t param_1) { generated_stub("FUN_004508a0 004508a0"); } void NpcAI::ENTITY_LIL_BLUB(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_LIL_BLUB 00450da0"); } uint32_t _ptr_deref_or_minus1() { generated_stub("_ptr_deref_or_minus1 00452be0"); } -void FUN_00452c60() { generated_stub("FUN_00452c60 00452c60"); } -int FUN_00452d40() { generated_stub("FUN_00452d40 00452d40"); } -void NpcAI::ENTITY_BIG_HORN_grab_bomb(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BIG_HORN_grab_bomb 00452eb0"); } -void FUN_004530e0() { generated_stub("FUN_004530e0 004530e0"); } -void NpcAI::ENTITY_BIG_HORN(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BIG_HORN 00453140"); } void FUN_00456170(int *param_1) { generated_stub("FUN_00456170 00456170"); } void FUN_00456190(uint32_t *param_1) { generated_stub("FUN_00456190 00456190"); } void * msvc::iterator_copy(void *self, void *outIterator) { generated_stub("msvc::iterator_copy 004561a0"); } @@ -9902,13 +9887,8 @@ 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_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"); } 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_FORSAKEN(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_FORSAKEN 0048f110"); } void FUN_00498f80() { generated_stub("FUN_00498f80 00498f80"); } void _range_to_span(uint32_t *param_1) { generated_stub("_range_to_span 00499270"); } int FUN_00499330() { generated_stub("FUN_00499330 00499330"); } @@ -9927,8 +9907,6 @@ void FUN_004a11b0() { generated_stub("FUN_004a11b0 004a11b0"); } void NpcAI::ENTITY_CLOG(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_CLOG 004a12f0"); } int FUN_004a2920() { generated_stub("FUN_004a2920 004a2920"); } void NpcAI::ENTITY_COLOSTOMIA(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_COLOSTOMIA 004a3040"); } -void NpcAI::ENTITY_DELIRIUM(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_DELIRIUM 004a6500"); } -void FUN_004a84f0() { generated_stub("FUN_004a84f0 004a84f0"); } void FUN_004aaaa0(void *param_1, int param_2) { generated_stub("FUN_004aaaa0 004aaaa0"); } void FUN_004aaaf0(uint32_t *param_1, uint32_t *param_2, uint32_t *param_3) { generated_stub("FUN_004aaaf0 004aaaf0"); } uint32_t * FUN_004aac80(uint32_t *param_1) { generated_stub("FUN_004aac80 004aac80"); } @@ -10048,7 +10026,6 @@ int FUN_00505ca0() { generated_stub("FUN_00505ca0 00505ca0"); } uint32_t * FUN_00505ce0() { generated_stub("FUN_00505ce0 00505ce0"); } void NpcAI::ENTITY_STONE_EYE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_STONE_EYE 00505d00"); } long double FUN_00515290(Vector *param_1, uint32_t param_2, int param_3) { generated_stub("FUN_00515290 00515290"); } -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_DOPLE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_DOPLE 00525650"); } void NpcAI::ENTITY_BLACK_MAW(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BLACK_MAW 0053b2f0"); } @@ -10480,7 +10457,6 @@ void FUN_00684450() { generated_stub("FUN_00684450 00684450"); } void FUN_006844a0() { generated_stub("FUN_006844a0 006844a0"); } void sha1_transform() { generated_stub("sha1_transform 006846c0"); } void sha1_digest(uint32_t param_1) { generated_stub("sha1_digest 00684920"); } -KColor * hsv_to_rgb(KColor *outColor, float hue, float saturation, float value, float alpha) { generated_stub("hsv_to_rgb 00684b90"); } float Math::timescale_factor(float acceleration, float timeScale) { generated_stub("Math::timescale_factor 00684cb0"); } void FUN_00684ce0(uint32_t *param_1) { generated_stub("FUN_00684ce0 00684ce0"); } int FUN_00684e10(uint32_t param_1) { generated_stub("FUN_00684e10 00684e10"); } @@ -10605,7 +10581,6 @@ void FUN_006a1e00(uint32_t *param_1) { generated_stub("FUN_006a1e00 006a1e00"); void FUN_006a1fc0() { generated_stub("FUN_006a1fc0 006a1fc0"); } void FUN_006a6910(uint32_t param_1, uint32_t param_2, uint32_t param_3, uint32_t param_4) { generated_stub("FUN_006a6910 006a6910"); } void FUN_006a6930() { generated_stub("FUN_006a6930 006a6930"); } -void FUN_006a6940() { generated_stub("FUN_006a6940 006a6940"); } void FUN_006a7ec0() { generated_stub("FUN_006a7ec0 006a7ec0"); } void FUN_006a80d0() { generated_stub("FUN_006a80d0 006a80d0"); } void FUN_006a8180(uint32_t param_1) { generated_stub("FUN_006a8180 006a8180"); } @@ -10613,7 +10588,6 @@ void FUN_006a8210(int param_1) { generated_stub("FUN_006a8210 006a8210"); } void FUN_006b5de0() { generated_stub("FUN_006b5de0 006b5de0"); } void FUN_006b5f40() { generated_stub("FUN_006b5f40 006b5f40"); } void play_sound_with_fart_seed(int soundId, float volume, int frameDelay, uint8_t isLoop, float pitch) { generated_stub("play_sound_with_fart_seed 006b6470"); } -void * spawn_rock_particles(float *param_1, float *param_2) { generated_stub("spawn_rock_particles 006b68c0"); } void FUN_006b6e40(float *param_1, int param_2) { generated_stub("FUN_006b6e40 006b6e40"); } int _Entity::GetAncestorField(uint32_t param_1) { generated_stub("_Entity::GetAncestorField 006b7d20"); } void vector_0x3c_tidy() { generated_stub("vector_0x3c_tidy 006b7d40"); } @@ -10809,7 +10783,6 @@ void FUN_00745ad0(int param_1) { generated_stub("FUN_00745ad0 00745ad0"); } void FUN_00748a30() { generated_stub("FUN_00748a30 00748a30"); } void FUN_0074a280(int param_1, uint32_t param_2, uint8_t param_3) { generated_stub("FUN_0074a280 0074a280"); } void FUN_0074b9a0() { generated_stub("FUN_0074b9a0 0074b9a0"); } -RoomDescriptor * FUN_0074bce0() { generated_stub("FUN_0074bce0 0074bce0"); } int * FUN_00752640(int *param_1) { generated_stub("FUN_00752640 00752640"); } void FUN_007526b0(uint32_t *param_1) { generated_stub("FUN_007526b0 007526b0"); } void FUN_00752830(int *param_1) { generated_stub("FUN_00752830 00752830"); } @@ -10877,7 +10850,6 @@ uint32_t FUN_007ad720(uint32_t param_1, uint8_t *param_2) { generated_stub("FUN_ void FUN_007b8c00(int param_1) { generated_stub("FUN_007b8c00 007b8c00"); } void FUN_007c2e80() { generated_stub("FUN_007c2e80 007c2e80"); } uint8_t FUN_007c7b10(uint32_t param_1, int param_2) { generated_stub("FUN_007c7b10 007c7b10"); } -char FUN_007c9080() { generated_stub("FUN_007c9080 007c9080"); } void FUN_007cb4f0() { generated_stub("FUN_007cb4f0 007cb4f0"); } 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"); } @@ -13449,11 +13421,7 @@ void * map_int_ImagePtr_subscript(void *self, int *key) { generated_stub("map_in void FUN_009f3c10() { generated_stub("FUN_009f3c10 009f3c10"); } 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"); } -uint32_t FUN_009f5830() { generated_stub("FUN_009f5830 009f5830"); } -uint32_t FUN_009f5850() { generated_stub("FUN_009f5850 009f5850"); } -uint32_t FUN_009f5870() { generated_stub("FUN_009f5870 009f5870"); } uint32_t * FUN_009f93d0() { generated_stub("FUN_009f93d0 009f93d0"); } 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"); } diff --git a/generated-src/umbilical_baby_data.cpp b/generated-src/umbilical_baby_data.cpp deleted file mode 100644 index 811da09..0000000 --- a/generated-src/umbilical_baby_data.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "classes.h" - -// 00435590 -uint32_t UmbilicalBabyData::last_point() -{ - int in_ECX; - - return *(uint32_t *) - (*GHIDRA_CAST((in_ECX + 4)) + - (*GHIDRA_CAST((in_ECX + 8)) - 1U & (*GHIDRA_CAST((in_ECX + 0x10)) + *GHIDRA_CAST((in_ECX + 0xc))) - 1U) * 4) - ; -} diff --git a/generated-src/vector.cpp b/generated-src/vector.cpp index 99bd0b4..7fdbe7c 100644 --- a/generated-src/vector.cpp +++ b/generated-src/vector.cpp @@ -182,25 +182,6 @@ float Vector::Cross(Vector *other) return other->y * this->x - this->y * other->x; } -// 00a10210 -void Vector::Lerp(Vector *target, float t, uint8_t isClamped) -{ - float targetY; - - if (isClamped != 0) { - if (t <= 0.0) { - t = 0.0; - } - if (1.0 <= t) { - t = 1.0; - } - } - targetY = target->y; - this->x = (target->x - this->x) * t + this->x; - this->y = (targetY - this->y) * t + this->y; - return; -} - // 00a10270 void Vector::Rotate(float angleDegrees) { diff --git a/src/active_items.h b/src/active_items.h index 012e1b1..039f5de 100644 --- a/src/active_items.h +++ b/src/active_items.h @@ -49,6 +49,18 @@ enum UseFlag : uint32_t USE_NOHUD = 1 << 11 }; +// The first active the late Afterbirth, Afterbirth+ and Repentance dispatch (400 and up) cases. +constexpr int FIRST_REPENTANCE_ACTIVE = 400; + +// D Infinity's faces, the face kept in the high half of its slot's data, and Golden Razor's price. +constexpr int D_INFINITY_FACES = 10; +constexpr int D_INFINITY_FACE_SHIFT = 16; +constexpr int D_INFINITY_FACE_MASK = 0xffff; +constexpr int GOLDEN_RAZOR_PRICE = 5; + +// The frames a hit an item deals keeps its target from being hit again. +constexpr int DAMAGE_COUNTDOWN_FRAMES = 30; + // The tears-up uses that unlock an achievement, and the stats the bulb trinkets reread. constexpr int TEARS_UP_UNLOCK_COUNT = 10; constexpr uint32_t BULB_CACHE_FLAGS = @@ -94,6 +106,17 @@ struct ActiveGain int varData = 0; }; +void sound_play_local(Entity_Player& player, int sound); +void use_animate(ItemUse& use); +void use_raise(ItemUse& use); +void sound_raise_use(ItemUse& use, int sound); +EntityList_EL& room_entities(); +bool is_item_target(Entity* entity, Entity_Player& player); +void battery_effect_spawn(Entity_Player& player); +void rebirth_item_effect_run(ItemUse& use); +void repentance_item_effect_run(ItemUse& use); +void active_missing_report(ItemUse& use); + bool input_is_action_pressed(ButtonAction action, int controllerIndex, Entity* entity); bool input_is_action_triggered(ButtonAction action, int controllerIndex, Entity* entity); bool is_active_usable(Entity_Player& player, int item, int slot); diff --git a/src/boss_ai.h b/src/boss_ai.h index da720e6..4c61d80 100644 --- a/src/boss_ai.h +++ b/src/boss_ai.h @@ -68,6 +68,9 @@ inline void npc_push(Entity& entity, Vector push) // Mega Satan's boss id, whose room keeps the horsemen low. constexpr int BOSS_ID_MEGA_SATAN = 55; +// Mega Satan's room holds a horseman or an angel below this line. +constexpr float HORSEMAN_MEGA_SATAN_FLOOR = 320; + void horseman_mega_satan_hold(Entity_NPC& npc); // Whether a segment follows its parent's trail, or only adds to its own. @@ -94,6 +97,9 @@ struct Fart void game_fart(const Fart& fart); +// spawn_rock_particles: water drops thrown from an ellipse about a spot in a flooded room (boss_big_horn.cpp). +void water_drops_spawn(const Vector& position, Vector radii, float speed); + // A tracer following its parent (Entity::SpawnFollowingEffect198's arguments): where from it, the direction it // points, its tint and size, and how long it lasts. struct FollowingEffect @@ -149,20 +155,26 @@ enum IsaacVariant }; void boss_adversary_update(Entity_NPC& npc); +void boss_angel_update(Entity_NPC& npc); void boss_baby_plum_update(Entity_NPC& npc); +void boss_big_horn_update(Entity_NPC& npc); void boss_blastocyst_update(Entity_NPC& npc); void boss_cage_update(Entity_NPC& npc); void boss_chub_update(Entity_NPC& npc); void boss_daddy_long_legs_update(Entity_NPC& npc); +void boss_dark_one_update(Entity_NPC& npc); +void boss_death_update(Entity_NPC& npc); void boss_dingle_update(Entity_NPC& npc); void boss_duke_update(Entity_NPC& npc); void boss_famine_update(Entity_NPC& npc); void boss_fistula_update(Entity_NPC& npc); +void boss_forsaken_update(Entity_NPC& npc); void boss_gate_update(Entity_NPC& npc); void boss_gemini_update(Entity_NPC& npc); void boss_gurdy_update(Entity_NPC& npc); void boss_gurdy_jr_update(Entity_NPC& npc); void boss_haunt_update(Entity_NPC& npc); +void boss_headless_horseman_update(Entity_NPC& npc); void boss_larry_jr_update(Entity_NPC& npc); void boss_little_horn_update(Entity_NPC& npc); void boss_loki_update(Entity_NPC& npc); @@ -178,6 +190,7 @@ void boss_monstro_update(Entity_NPC& npc); void boss_peep_update(Entity_NPC& npc); void boss_pestilence_update(Entity_NPC& npc); void boss_polycephalus_update(Entity_NPC& npc); +void boss_war_update(Entity_NPC& npc); void boss_widow_update(Entity_NPC& npc); void boss_satan_update(Entity_NPC& npc); void boss_fallen_update(Entity_NPC& npc); @@ -197,6 +210,7 @@ void npc_hush_fly_update(Entity_NPC& npc); void npc_hush_boil_update(Entity_NPC& npc); void boss_mega_satan_update(Entity_NPC& npc); void boss_mega_satan_hand_update(Entity_NPC& npc); +void boss_delirium_update(Entity_NPC& npc); // The fly group Hush keeps as a ring about him. constexpr int HUSH_FLY_RING_GROUP = 1; diff --git a/src/boss_angel.cpp b/src/boss_angel.cpp new file mode 100644 index 0000000..b56afa4 --- /dev/null +++ b/src/boss_angel.cpp @@ -0,0 +1,335 @@ +#include "boss_ai.h" +#include "entity_laser.h" +#include "menu_manager.h" +#include "npc_caves.h" +#include "sfx_manager.h" +#include + +// The Fallen Uriel and Gabriel (variant 1) wear the black spritesheets. +constexpr int FALLEN_ANGEL = 1; +constexpr std::string_view ANGEL_SHEET_NAME = "Angel"; +constexpr std::string_view FALLEN_SHEET_END = "Black.png"; +constexpr size_t SHEET_EXTENSION = 4; +constexpr int ANGELIC_BABY = 1; + +// An angel's states: floating about, the spread shot, the beams down or across and on the diagonals, and Gabriel's +// prayer. i1 is 0 while it winds up (Shield, Charging), 1 once it attacks. +constexpr int ANGEL_FLOAT = NPC_STATE_MOVE; +constexpr int ANGEL_SPREAD = NPC_STATE_ATTACK; +constexpr int ANGEL_BEAMS = NPC_STATE_ATTACK2; +constexpr int ANGEL_DIAGONAL_BEAMS = NPC_STATE_ATTACK3; +constexpr int ANGEL_PRAY = NPC_STATE_SUMMON; + +// The attacks a float picks, in the order its roll and its controller number them. +enum AngelAttack +{ + ANGEL_ATTACK_NONE = -1, + ANGEL_ATTACK_SPREAD, + ANGEL_ATTACK_BEAMS, + ANGEL_ATTACK_DIAGONAL_BEAMS, + ANGEL_ATTACK_PRAY +}; + +constexpr float ANGEL_FRICTION = 0.8f; +constexpr float FLOAT_DODGE = -1.2f; +constexpr float URIEL_CEILING_GAP = 30; +constexpr float URIEL_SPEED = 1.5f; +constexpr float GABRIEL_SPEED = 1.65f; +constexpr int ANGEL_ATTACK_EVERY = 30; +constexpr uint32_t ANGEL_ATTACK_ODDS = 3; +constexpr int ANGEL_ATTACKS = 3; +constexpr int PRAY_ENEMY_LIMIT = 3; +constexpr float CONTROL_DEADZONE = 0.1f; +constexpr float URIEL_CHARGE_STEER = 0.375f; +constexpr float GABRIEL_CHARGE_STEER = 0.4125f; + +// The spread: Uriel's five aimed shots, Gabriel's ring of twelve. +constexpr float ANGEL_SPREAD_HEIGHT = -17; +constexpr float SPREAD_FALL = 1.3f; +constexpr float SPREAD_VOLUME = 0.5f; +constexpr float URIEL_SHOT_SPEED = 8; +constexpr float GABRIEL_RING_SPEED = 10; +constexpr float GABRIEL_RING_SHOTS = 12; + +// The beams: charging for 25 frames, then light beams on Shoot, back to floating 51 frames on. Tracers show them first. +constexpr int ANGEL_CHARGE_FRAMES = 25; +constexpr int BEAM_FRAMES = 51; +constexpr int BEAM_TIMEOUT = 30; +constexpr float BEAM_HEIGHT = -50; +constexpr float URIEL_BEAM_DROP = 5; +constexpr float GABRIEL_BEAM_REACH = 7; +constexpr float URIEL_TRACER_HEIGHT = -40; +constexpr float ANGEL_TRACER_SCALE = 4; +constexpr int ANGEL_TRACER_TIMEOUT = 32; +constexpr ColorMod ANGEL_TRACER_COLOR = {{0.6f, 0.6f, 0, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr float URIEL_BEAMS[] = {90}; +constexpr float URIEL_DIAGONAL_BEAMS[] = {45, 135}; +constexpr float GABRIEL_BEAMS[] = {0, 90, 180, 270}; +constexpr float GABRIEL_DIAGONAL_BEAMS[] = {45, 135, 225, 315}; + +// The prayer: an Angelic Baby every 10 frames of the first 20 while few enemies are about. +constexpr int PRAY_EVERY = 10; +constexpr int PRAY_FRAMES = 20; +constexpr float PRAY_VOLUME = 1.5f; + +constexpr float FLAP_VOLUME = 0.65f; + +// The Fallen angels' black sheets, on every layer drawn from an angel sheet. +static void fallen_sheets_load(Entity_NPC& npc) +{ + for (size_t layer = 0; layer < npc.sprite.layerStates.size(); layer++) + { + const LayerData* data = npc.sprite.layerStates[layer].layerData; + std::string sheet = data ? data->spriteSheetPath : ""; + if (sheet.size() <= SHEET_EXTENSION || sheet.find(ANGEL_SHEET_NAME) == std::string::npos) continue; + + sheet.resize(sheet.size() - SHEET_EXTENSION); + npc.sprite.ReplaceSpritesheet((int)layer, sheet.append(FALLEN_SHEET_END)); + } + npc.sprite.LoadGraphics(); +} + +// The beams an attack fires and its tracers show, by angle. +static std::span beam_angles(const Entity_NPC& npc) +{ + bool isDiagonal = npc.state == ANGEL_DIAGONAL_BEAMS; + if (npc.type == ENTITY_URIEL) + return isDiagonal ? std::span(URIEL_DIAGONAL_BEAMS) : std::span(URIEL_BEAMS); + return isDiagonal ? std::span(GABRIEL_DIAGONAL_BEAMS) : std::span(GABRIEL_BEAMS); +} + +// Where a beam leaves from: below Uriel, a little out from Gabriel along it. +static Vector beam_offset(const Entity_NPC& npc, float angle) +{ + if (npc.type == ENTITY_URIEL) return vector_make(0, URIEL_BEAM_DROP); + return vector_scale(vector_from_angle(angle), GABRIEL_BEAM_REACH); +} + +// An attack's start, with the tracers of its beams. +static void attack_start(Entity_NPC& npc, int attack) +{ + constexpr int ATTACK_STATES[] = {ANGEL_SPREAD, ANGEL_BEAMS, ANGEL_DIAGONAL_BEAMS, ANGEL_PRAY}; + npc.state = ATTACK_STATES[attack]; + npc.i1 = 0; + npc.stateFrame = 0; + if (npc.state != ANGEL_BEAMS && npc.state != ANGEL_DIAGONAL_BEAMS) return; + if (npc.type != ENTITY_URIEL && npc.type != ENTITY_GABRIEL) return; + + for (float angle : beam_angles(npc)) + { + Vector offset = npc.type == ENTITY_URIEL ? vector_make(0, URIEL_TRACER_HEIGHT) + : vector_add(beam_offset(npc, angle), vector_make(0, BEAM_HEIGHT)); + following_effect_spawn(npc, {.offset = offset, + .targetPosition = vector_from_angle(angle), + .color = ANGEL_TRACER_COLOR, + .scale = ANGEL_TRACER_SCALE, + .timeout = ANGEL_TRACER_TIMEOUT}); + } +} + +// The attack a controlling player picks: the spread while moving, else the beams, the diagonal beams or Gabriel's +// prayer by button. +static int controlled_attack_get(Entity_NPC& npc) +{ + if (!vector_is_zero(npc.GetControllerMovementInput(CONTROL_DEADZONE))) return ANGEL_ATTACK_SPREAD; + if (npc.IsControllerActionPressed(ACTION_ITEM)) return ANGEL_ATTACK_BEAMS; + if (npc.IsControllerActionPressed(ACTION_PILL_CARD)) return ANGEL_ATTACK_DIAGONAL_BEAMS; + if (npc.IsControllerActionPressed(ACTION_BOMB) && npc.type == ENTITY_GABRIEL && + npc.GetAliveEnemyCount() < PRAY_ENEMY_LIMIT) + return ANGEL_ATTACK_PRAY; + return ANGEL_ATTACK_NONE; +} + +// Floating: it keeps level with its target, backing off upward when level (Uriel stays high, below the ceiling and +// Mega Satan's floor). Every 30 frames one time in three it attacks: Uriel never beams up at a target above it, and +// Gabriel prays only while few enemies are about. +static void angel_float(Entity_NPC& npc, int prevFrame) +{ + npc.sprite.Play("Float"); + Vector toward = vector_sub(npc.GetPlayerTarget()->pos, npc.pos); + if (std::abs(toward.y) < std::abs(toward.x)) + { + toward.y *= FLOAT_DODGE; + if (npc.type == ENTITY_URIEL) + { + toward.y = -vector_length(toward); + Room& room = *g_game->room; + if (npc.pos.y - room.topLeftPos.y < URIEL_CEILING_GAP) toward.y = 0; + if (room.bossId == BOSS_ID_MEGA_SATAN && npc.pos.y - HORSEMAN_MEGA_SATAN_FLOOR < URIEL_CEILING_GAP) + toward.y = 0; + } + } + Vector move = vector_length(toward) > 0 ? vector_normalized(toward) : toward; + if (npc.controllerID != -1) move = npc.GetControllerInput(0); + if (npc.type == ENTITY_URIEL) move = vector_scale(move, URIEL_SPEED); + else if (npc.type == ENTITY_GABRIEL) move = vector_scale(move, GABRIEL_SPEED); + npc.velocity = vector_add(npc.velocity, vector_scale(move, npc.speedMultiplier)); + + int choice = ANGEL_ATTACK_NONE; + if (npc.controllerID == -1) + { + if (npc.stateFrame / ANGEL_ATTACK_EVERY <= prevFrame / ANGEL_ATTACK_EVERY || Random() % ANGEL_ATTACK_ODDS != 0) + return; + } + else if ((choice = controlled_attack_get(npc)) < 0) return; + + int attacks = + npc.type == ENTITY_GABRIEL && npc.GetAliveEnemyCount() < PRAY_ENEMY_LIMIT ? ANGEL_ATTACKS + 1 : ANGEL_ATTACKS; + int attack = (int)(Random() % (uint32_t)attacks); + bool isBeam = attack == ANGEL_ATTACK_BEAMS || attack == ANGEL_ATTACK_DIAGONAL_BEAMS; + if (npc.type == ENTITY_URIEL && isBeam && npc.GetPlayerTarget()->pos.y - npc.pos.y < 0) + attack = ANGEL_ATTACK_SPREAD; + if (npc.controllerID == -1) npc.controllerMovement = {}; + else + { + npc.controllerMovement = npc.GetControllerMovementInput(CONTROL_DEADZONE); + attack = choice; + } + if (attack != ANGEL_ATTACK_NONE) attack_start(npc, attack); +} + +// The spread: shielded until Shield ends, then Uriel's five shots at its target (or its controller's way) or +// Gabriel's ring of twelve on Shoot. +static void angel_spread(Entity_NPC& npc) +{ + npc.UpdateControllerMovement(false); + if (npc.i1 == 0) + { + npc.sprite.Play("Shield"); + if (npc_anim_is_done(npc)) npc.i1 = 1; + return; + } + + npc.sprite.Play("SpreadShot"); + if (npc.sprite.animState.animData && npc.sprite.animState.IsEventTriggered("Shoot")) + { + ProjectileParams params; + params.heightModifier = ANGEL_SPREAD_HEIGHT; + params.fallingSpeedModifier = SPREAD_FALL; + npc.PlaySound(SOUND_THUMBS_DOWN, SPREAD_VOLUME, 2, false, 1); + npc.PlaySound(SOUND_BLOODSHOOT, 1, 2, false, 1); + if (npc.type == ENTITY_URIEL) + { + Vector aim = vector_sub(npc.GetPlayerTarget()->pos, npc.pos); + if (!vector_is_zero(npc.controllerMovement)) aim = npc.controllerMovement; + npc.FireProjectiles(npc.pos, vector_scale(vector_normalized(aim), URIEL_SHOT_SPEED), PROJECTILES_FIVE, + params); + } + else if (npc.type == ENTITY_GABRIEL) + npc.FireProjectiles(npc.pos, vector_make(GABRIEL_RING_SPEED, GABRIEL_RING_SHOTS), PROJECTILES_RING, params); + } + if (!npc_anim_is_done(npc)) return; + + npc.i1 = 0; + npc.stateFrame = 0; + npc.state = ANGEL_FLOAT; +} + +// The prayer: shielded until Shield ends, then praying, an Angelic Baby every 10 frames of the first 20 while few +// enemies are about. +static void angel_pray(Entity_NPC& npc, int prevFrame) +{ + if (npc.i1 == 0) + { + npc.sprite.Play("Shield"); + if (!npc_anim_is_done(npc)) return; + npc.i1 = 1; + npc.stateFrame = 0; + return; + } + + npc.sprite.Play("Pray"); + if (prevFrame / PRAY_EVERY < npc.stateFrame / PRAY_EVERY && npc.stateFrame < PRAY_FRAMES && + npc.GetAliveEnemyCount() < PRAY_ENEMY_LIMIT) + { + npc.PlaySound(SOUND_SUMMONSOUND, PRAY_VOLUME, 2, false, 1); + g_game->Spawn( + {.position = npc.pos, .spawner = &npc, .type = ENTITY_BABY, .variant = ANGELIC_BABY, .seed = Random()}); + } + if (!npc_anim_is_done(npc)) return; + + npc.i1 = 0; + npc.stateFrame = 0; + npc.state = ANGEL_FLOAT; +} + +// The beams: charging (steered by a controlling player), then light beams on Shoot, back to floating after a while. +static void angel_beams(Entity_NPC& npc) +{ + if (npc.i1 == 0) + { + npc.sprite.Play(npc.type == ENTITY_GABRIEL && npc.state == ANGEL_DIAGONAL_BEAMS ? "Charging2" : "Charging"); + if (npc.stateFrame > ANGEL_CHARGE_FRAMES) + { + npc.i1 = 1; + npc.stateFrame = 0; + } + if (npc.controllerID == -1) return; + + float steer = npc.type == ENTITY_URIEL ? URIEL_CHARGE_STEER + : npc.type == ENTITY_GABRIEL ? GABRIEL_CHARGE_STEER + : 1; + npc.velocity = vector_add(npc.velocity, vector_scale(npc.GetControllerInput(0), steer * npc.speedMultiplier)); + return; + } + + npc.sprite.Play("LaserShot"); + if (npc.sprite.animState.animData && npc.sprite.animState.IsEventTriggered("Shoot") && + (npc.type == ENTITY_URIEL || npc.type == ENTITY_GABRIEL)) + { + for (float angle : beam_angles(npc)) + { + Entity_Laser* beam = Entity_Laser::ShootAngle({.position = vector_add(npc.pos, beam_offset(npc, angle)), + .posOffset = vector_make(0, BEAM_HEIGHT), + .source = &npc, + .angleDegrees = angle, + .timeout = BEAM_TIMEOUT, + .variant = LASER_LIGHT_BEAM}); + beam->entityGridCollisionClass = GRIDCOLL_NONE; + beam->Update(); + } + } + if (npc.stateFrame < BEAM_FRAMES) return; + + npc.i1 = 0; + npc.state = ANGEL_FLOAT; +} + +// 0051e0f0 NpcAI::ENTITY_URIEL: Uriel and Gabriel float level with their target and shoot spreads, fire light beams +// (down and on the diagonals for Uriel, across and on the diagonals for Gabriel) and Gabriel prays for Angelic +// Babies. The Fallen ones wear black. Mega Satan's room keeps them below his platform. +void boss_angel_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.state = ANGEL_FLOAT; + npc.stateFrame = 0; + if (npc.variant == FALLEN_ANGEL) fallen_sheets_load(npc); + return; + } + + int prevFrame = npc.stateFrame; + npc.friction = ANGEL_FRICTION; + npc.stateFrame += npc_ticks_get(npc); + switch (npc.state) + { + case ANGEL_FLOAT: + angel_float(npc, prevFrame); + break; + case ANGEL_SPREAD: + angel_spread(npc); + break; + case ANGEL_BEAMS: + case ANGEL_DIAGONAL_BEAMS: + angel_beams(npc); + break; + case ANGEL_PRAY: + angel_pray(npc, prevFrame); + break; + } + + if (npc.sprite.animState.animData && npc.sprite.animState.IsEventTriggered("Flap")) + npc_sound_play(SOUND_ANGEL_WING, FLAP_VOLUME, 2, champion_pitch_get(npc)); + if (g_game->room->bossId == BOSS_ID_MEGA_SATAN && npc.pos.y < HORSEMAN_MEGA_SATAN_FLOOR) + npc.pos.y = HORSEMAN_MEGA_SATAN_FLOOR; +} diff --git a/src/boss_big_horn.cpp b/src/boss_big_horn.cpp index d1a1483..812e8c3 100644 --- a/src/boss_big_horn.cpp +++ b/src/boss_big_horn.cpp @@ -1,10 +1,18 @@ #include "npc_alt.h" #include "boss_ai.h" +#include "capsule.h" +#include "entity_bomb.h" +#include "entity_player.h" +#include "npc_caves.h" #include "room.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include "temporary_effects.h" +#include -// Big Horn's parts, by variant: its head in the big hole, its hand and its bomb ball. +// Big Horn's parts, by variant: Big Horn himself, a small hole with his hand, and a big hole that may bring him up. constexpr int BIG_HORN_HAND = 1; -constexpr int BIG_HORN_BALL = 2; +constexpr int HORN_BIG_HOLE = 2; // Its splash in a flooded room: 12 to 21 drops thrown 3 to 8 fast from about its body, twice as big, rising 4 to 12. constexpr float SPLASH_WATER_MIN = 0.2f; @@ -20,10 +28,11 @@ constexpr float SPLASH_RISE_RANGE = 8; constexpr float BIG_HORN_SPLASH_FALL = 1.5f; // 006c4b30 (Entity_NPC::Update's death start for Big Horn) Its part's death: the hand pulls back into its small hole -// (its HandDeath while its Main layer shows), the ball vanishes, and the head plays its Death unless closing its hole. +// (its HandDeath while its Main layer shows), the big hole vanishes, and the head plays its Death unless closing its +// hole. void big_horn_death_play(Entity_NPC& npc) { - if (npc.variant == BIG_HORN_BALL) + if (npc.variant == HORN_BIG_HOLE) { npc.isVisible = false; return; @@ -64,3 +73,1065 @@ void big_horn_splash(Entity_NPC& npc) drop->Update(); } } + +// Big Horn's states: resting up (popping down after a while), hidden under the floor while his holes open, popped up +// spitting Little Horn balls, and dizzy after a bomb went off in his mouth. +constexpr int HORN_REST = NPC_STATE_IDLE; +constexpr int HORN_HIDDEN = NPC_STATE_MOVE; +constexpr int HORN_SPIT = NPC_STATE_SUMMON; +constexpr int HORN_DIZZY = NPC_STATE_SPECIAL; + +// A hole's states: open (players and bombs fall in), closing, and the hand's slap, bomb throw, bomb spray and +// Little Horn balls. Its subtype picks the hand (odd ones mirrored), 0 or above 8 an open small hole. +constexpr int HOLE_OPEN = NPC_STATE_IDLE; +constexpr int HOLE_CLOSING = NPC_STATE_SUICIDE; +constexpr int HAND_SLAP = NPC_STATE_ATTACK; +constexpr int HAND_THROW = NPC_STATE_ATTACK2; +constexpr int HAND_BOMBS = NPC_STATE_ATTACK3; +constexpr int HAND_HORNS = NPC_STATE_ATTACK4; +constexpr std::array HAND_STATES = {HOLE_OPEN, HAND_SLAP, HAND_SLAP, HAND_THROW, HAND_THROW, + HAND_BOMBS, HAND_BOMBS, HAND_HORNS, HAND_HORNS}; +constexpr int HAND_SLAP_KIND = 1; +constexpr int HAND_THROW_KIND = 3; +constexpr int HAND_BOMBS_KIND = 5; +constexpr int HAND_HORNS_KIND = 7; +constexpr int LITTLE_HORN_BALL = 1; +constexpr int BALL_ROLLING_SUBTYPE = 1; + +constexpr float HOLE_DEPTH = -100; +constexpr float HELD_BOMB_DEPTH = -101; +constexpr int HOLE_OPEN_FRAMES = 30; +constexpr int BIG_HOLE_OPEN_FRAMES = 60; +constexpr int HAND_SLAP_DELAY = 30; +constexpr float HORN_HAND_DAMAGE = 1; +constexpr int HORN_SPOT_TRIES = 50; +constexpr float HAND_HORN_HEALTH = 0.2f; +constexpr int HAND_HORN_I1 = 45; +constexpr float ANY_PLAYER_REACH = 9999999; +constexpr int ONE_BOMB_HAND = 2; +constexpr int BOMBS_HAND = 3; + +// Resting: Big Horn pops down 15 frames after his Idle starts. Hidden: 2 or 3 holes (2 more in a big room) open +// 0.75 of his size off the walls and apart, and 106 frames on a big hole moves him; he pops up once it is open, +// dizzy if he swallowed a bomb, holding his bombs until they go off one each 5 ticks. +constexpr int HORN_REST_FRAMES = 15; +constexpr int HIDDEN_FRAMES = 106; +constexpr int BIG_ROOM_SHAPE = ROOMSHAPE_2x2; +constexpr float HOLE_MARGIN = 0.75f; +constexpr float BIG_HOLE_MARGIN_Y = 0.45f; +constexpr float BIG_HOLE_MARGIN_X = 1.15f; +constexpr uint32_t HAND_ROLL = 100; +constexpr uint32_t HAND_SLAP_ODDS = 50; +constexpr uint32_t HAND_THROW_ODDS = 90; +constexpr uint32_t HAND_HORNS_ODDS = 10; +constexpr float HORNS_ROOM_DROP = 80; +constexpr int HORN_BALL_LIMIT = 2; +constexpr float HELD_BOMB_EVERY = 5; +constexpr int DIZZY_FRAMES = 150; +constexpr float DIZZY_HURT = 1.2f; + +// Spitting: Charge throws one Little Horn ball, Charge2 two rolling ones and Charge3 three, from a dark smoke cloud. +constexpr uint32_t SPIT_ROLL = 100; +constexpr uint32_t SPIT_TWO_ODDS = 35; +constexpr uint32_t SPIT_THREE_ODDS = 40; +constexpr std::array, 3> SPIT_VELOCITIES = {{{5, 5}, {15, 7}, {-15, 7}}}; +constexpr float SPIT_LEAD = 2; +constexpr float HORN_CLOUD_SCALE = 0.8f; +constexpr float HORN_CLOUD_HEIGHT = -25; +constexpr float SPIT_BALL_SIZE = 1.5f; +constexpr float DELIRIUM_BALL_HEALTH = 5; +constexpr std::string_view SPIT_BALL_SHEET = "gfx/effects/Effect_088_DarkSmoke_Big.png"; +constexpr ColorMod HORN_CLOUD_COLOR = {{0, 0, 0, 0.8f}, {0, 0, 0, 0}, {0.15f, 0.15f, 0.15f}}; + +// Bombs: one grabbed rising past his mouth, Big Horn's hand throws one (a Mega Troll Bomb one time in ten, a hot or +// sad blood one in five) or sprays three Troll Bombs with 35 to 44 frame fuses. +constexpr float GRAB_DROP = 30; +constexpr float GRAB_RISE = -0.1f; +constexpr float GRAB_PITCH = 0.8f; +constexpr float GRAB_PITCH_TINY = 1.3f; +constexpr float GRAB_PITCH_GIANT = 0.4f; +constexpr float HELD_BOMB_DROP = 2; +constexpr uint32_t THROW_ROLL = 100; +constexpr uint32_t THROW_MEGA_ODDS = 10; +constexpr uint32_t THROW_SPECIAL_ODDS = 30; +constexpr uint32_t FUSE_RANGE = 10; +constexpr int FUSE_MIN = 35; +constexpr float HORN_THROW_SPEED = 15; +constexpr float HORN_THROW_REACH = 3; +constexpr float THROWN_BOMB_FALL = -4; +constexpr float THROWN_BOMB_HEIGHT = -24; +constexpr float HORN_SPRAY_SPEED = 12; +constexpr float SPRAY_LEAD = 2.5f; +constexpr std::array SPRAY_ANGLES = {-80, 0, 80}; +constexpr float SPRAY_FALL_MIN = -3; +constexpr float SPRAY_FALL_RANGE = 2; + +// The slap: it waits a while, drifts at a random player at 3 between Move and Stop, and its Slam pushes off and hurts +// (1 to players and familiars, 25 to the rest) what its Slam null reaches. +constexpr float SLAP_SPEED = 3; +constexpr float SLAP_PUSH = 5; +constexpr float SLAP_DAMAGE = 25; +constexpr int SLAP_COUNTDOWN = 30; +constexpr float SLAP_POOF_SIZE = 0.5f; +constexpr int SLAP_SHAKE = 6; +constexpr float SLAP_DROPS_X = 60; +constexpr float SLAP_DROPS_Y = 40; +constexpr ColorMod SLAP_POOF_COLOR = {{1, 1, 1, 0.6f}, {0.7f, 0.7f, 0.7f, 1}, {0, 0, 0}}; + +// The Little Horn balls the hand throws: one on each Shoot, 30 degrees round each time, its cough higher. +constexpr float HORNS_ANGLE_START = 90; +constexpr float HORNS_ANGLE_STEP = 30; +constexpr float HORNS_SPEED = 10; +constexpr float HORNS_PITCH_STEP = 0.1f; +constexpr float HORNS_PITCH_BASE = 0.98f; +constexpr float HORNS_PITCH_RANGE = 0.05f; + +// Water thrown up where the hand slams in a flooded room: 8 to 13 drops from an ellipse, bigger past 20 across. +constexpr float DROPS_WATER_MIN = 0.2f; +constexpr int DROPS_MIN = 8; +constexpr uint32_t DROPS_RANGE = 6; +constexpr float DROPS_BIG_RADIUS = 20; +constexpr float DROPS_BIG_SCALE = 2; +constexpr float DROPS_SPEED_MIN = 3; +constexpr float DROPS_SPEED_RANGE = 5; +constexpr int DROPS_SUBTYPE = 1; +constexpr float DROPS_RISE_MIN = -4; +constexpr float DROPS_RISE_RANGE = 8; +constexpr float DROPS_FALL = 1.5f; + +// 006b68c0 spawn_rock_particles: in a flooded room, 8 to 13 water drops thrown out from an ellipse about a spot, +// faster by a factor, twice as big when it is wide. +void water_drops_spawn(const Vector& position, Vector radii, float speed) +{ + if (g_game->room->waterAmount <= DROPS_WATER_MIN) return; + + float narrow = std::min(radii.x, radii.y); + float scale = narrow > DROPS_BIG_RADIUS ? DROPS_BIG_SCALE : 1; + for (int drops = (int)(Random() % DROPS_RANGE) + DROPS_MIN; drops > 0; drops--) + { + float angle = random_unit() * RANDOM_HALF_TURN; + angle += angle; + Vector offset = vector_make(std::cos(angle) * radii.x, std::sin(angle) * radii.y); + float pace = (random_unit() * DROPS_SPEED_RANGE + DROPS_SPEED_MIN) * speed; + auto* drop = static_cast(g_game->Spawn({.position = vector_add(position, offset), + .velocity = vector_scale(offset, pace / narrow), + .subType = DROPS_SUBTYPE, + .type = ENTITY_EFFECT, + .variant = EFFECT_WATER_SPLASH, + .seed = Random()})); + drop->sprite.scale = vector_scale(drop->sprite.scale, scale); + drop->fallingAcceleration = DROPS_FALL; + drop->fallingSpeed = DROPS_RISE_MIN - random_unit() * DROPS_RISE_RANGE; + drop->Update(); + } +} + +// 009be990 NpcHelper::big_horn_is_any_hole_busy Whether a player is falling into a hole or down one. +static bool is_hole_busy() +{ + for (Entity_Player* player : g_game->playerManager.playerList) + if (player->pitfallState != PITFALL_NONE && player->pitfallState != PITFALL_CLIMBING) return true; + return false; +} + +// Whether a position lies in a hole, its size stretched by its size multiplier. +static bool is_in_hole(const Entity& hole, const Vector& position) +{ + float x = position.x / hole.sizeMulti.x - hole.pos.x / hole.sizeMulti.x; + float y = position.y / hole.sizeMulti.y - hole.pos.y / hole.sizeMulti.y; + return y * y + x * x < hole.size * hole.size; +} + +// 00452c60 A grounded player over a hole falls in, but with Mega Mush. +static void hole_player_pull(const Entity_NPC& hole, Entity_Player& player) +{ + int grid = player.entityGridCollisionClass; + if (!is_in_hole(hole, player.pos) || grid == GRIDCOLL_NONE || grid == GRIDCOLL_WALLS || grid == GRIDCOLL_WALLS_X || + grid == GRIDCOLL_WALLS_Y || player.pitfallState != PITFALL_NONE) + return; + if (player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_MEGA_MUSH)) return; + + player.PlayExtraAnimation("FallIn"); + player.isControlsEnabled = false; + player.entityCollisionClass = ENTCOLL_NONE; + player.pitfallState = PITFALL_FALLING; + player.pitfallTimer = 0; +} + +// 006a6940 A bomb starts falling down a pit: untouchable, its Collect animation from the start. +static void bomb_pit_fall(Entity& bomb) +{ + bomb.entityCollisionClass = ENTCOLL_NONE; + bomb.pitfallState = PITFALL_FALLING; + bomb.pitfallTimer = 0; + const AnimationData* shown = bomb.sprite.animState.animData; + if (shown && shown->name == "Collect" && (!shown->isLooping || bomb.sprite.animState.isPlaying)) return; + npc_anim_restart(bomb.sprite, "Collect"); +} + +// 00452d40 The bombs over a hole fall in, let go by whoever held them. How many fell. +static int hole_bombs_take(const Entity_NPC& hole) +{ + int fallen = 0; + for (Entity* bomb : entity_query(ENTITY_BOMB, -1)) + { + if (!is_in_hole(hole, bomb->pos) || bomb->pitfallState != PITFALL_NONE) continue; + bomb_pit_fall(*bomb); + bomb->parent = nullptr; + fallen++; + } + return fallen; +} + +// What falls into an open hole each frame: the players over it, and the bombs it counts. +static void hole_swallow(Entity_NPC& hole) +{ + for (Entity_Player* player : g_game->playerManager.playerList) hole_player_pull(hole, *player); + hole.i1 += hole_bombs_take(hole); +} + +// 004530e0 The bombs Big Horn holds stay in him: untouchable, and once down at his place in front of him. Only his +// first two are walked. +static void held_bombs_keep(Entity_NPC& npc) +{ + Entity* bomb = npc.child; + while (bomb) + { + bomb->entityCollisionClass = ENTCOLL_NONE; + if (bomb->pitfallState == PITFALL_DOWN) + { + bomb->pos = npc.pos; + bomb->renderDepthOffset = HELD_BOMB_DEPTH; + } + Entity* next = npc.child->child; + bomb = next != bomb ? next : nullptr; + } +} + +// A held bomb set off where Big Horn is. +static void held_bomb_explode(Entity* held, const Vector& position) +{ + if (held->type == ENTITY_BOMB) + { + auto* bomb = static_cast(held); + bomb->explosionCountdown = 0; + bomb->explosionCountdown2 = 0; + } + held->pos = position; + held->Update(); +} + +// 00452eb0 NpcAI::ENTITY_BIG_HORN_grab_bomb Big Horn swallows a bomb rising past his mouth (one at a time), dizzy. +static void bomb_grab(Entity_NPC& npc) +{ + if (npc.child) return; + float reach = npc.size * 0.5f; + Vector mouth = vector_make(npc.pos.x, npc.pos.y + GRAB_DROP); + for (Entity* bomb : entity_query(ENTITY_BOMB, -1)) + { + Vector toward = vector_sub(bomb->pos, mouth); + if (vector_length_squared(toward) >= reach * reach || bomb->pitfallState != PITFALL_NONE || + bomb->velocity.y >= GRAB_RISE) + continue; + + npc.i1++; + bomb_pit_fall(*bomb); + npc.child = bomb; + bomb->parent = &npc; + npc.sprite.Play("BombDizzy"); + float pitch = npc.championColorIdx == CHAMPION_TINY ? GRAB_PITCH_TINY + : npc.championColorIdx == CHAMPION_GIANT ? GRAB_PITCH_GIANT + : GRAB_PITCH; + npc_sound_play(SOUND_VAMP_GULP, 1, 0, pitch); + return; + } +} + +// A spot from GetRandomPosition kept a margin off the walls. +static Vector hole_spot_roll(Vector margin) +{ + Room& room = *g_game->room; + return room.GetClampedPositionImpl(room.GetRandomPosition(0), margin.y, margin.x, margin.y, margin.x); +} + +// Whether another small hole is open near a spot. +static bool is_small_hole_near(const Entity_NPC& npc, const Vector& spot) +{ + for (Entity* other : g_game->room->entityList.updateEL) + if (!other->isDead && other->type == ENTITY_BIG_HORN && other->variant == BIG_HORN_HAND && + vector_length_squared(vector_sub(other->pos, spot)) < (npc.size * 2) * (npc.size * 2)) + return true; + return false; +} + +// The small holes opening while Big Horn hides: the first two with hands (a slap one time in two, a throw, a bomb +// spray, or Little Horns when few are about), the others plain holes. Each takes his health. +static void small_holes_open(Entity_NPC& npc) +{ + Room& room = *g_game->room; + int count = (int)(Random() & 1) + 2; + if (room.GetRoomShape() >= BIG_ROOM_SHAPE) count += 2; + float margin = npc.size * HOLE_MARGIN; + for (int index = 0; index < count; index++) + { + Random(); + Vector spot{}; + int tries = 0; + do spot = hole_spot_roll(vector_make(margin, margin)); + while (is_small_hole_near(npc, spot) && ++tries < HORN_SPOT_TRIES); + if (tries >= HORN_SPOT_TRIES) + { + KAGE_LogMessage(LOG_WARN, (uint8_t*)"Failed to find safe spawn location for Big Horn's Small Hole\n"); + continue; + } + + int subtype = 0; + if (index < 2) + { + uint32_t roll = Random() % HAND_ROLL; + int kind = roll < HAND_SLAP_ODDS ? HAND_SLAP_KIND + : roll < HAND_THROW_ODDS ? HAND_THROW_KIND + : HAND_BOMBS_KIND; + if (index == 0 && roll % HAND_HORNS_ODDS == 0 && + room.IsPositionInRoom(vector_make(spot.x, spot.y + HORNS_ROOM_DROP), 0) && + entity_query(ENTITY_LITTLE_HORN, LITTLE_HORN_BALL).size() < HORN_BALL_LIMIT) + kind = HAND_HORNS_KIND; + subtype = kind + index; + } + auto* hole = static_cast(g_game->Spawn({.position = spot, + .spawner = &npc, + .subType = subtype, + .type = ENTITY_BIG_HORN, + .variant = BIG_HORN_HAND, + .seed = Random()})); + hole->ClearEntityFlags(FLAG_APPEAR); + hole->maxHitPoints = npc.maxHitPoints; + hole->health = npc.health; + hole->parent = &npc; + hole->entityCollisionClass = ENTCOLL_NONE; + } +} + +// Whether a spot for Big Horn's big hole is taken by a bomb or another living horn. +static bool is_big_hole_blocked(const Entity_NPC& npc, const Vector& spot) +{ + for (Entity* other : g_game->room->entityList.updateEL) + { + bool isHorn = + (other->type == ENTITY_BIG_HORN || other->type == ENTITY_LITTLE_HORN) && !other->isDead && other != &npc; + if (!isHorn && other->type != ENTITY_BOMB) continue; + float reach = npc.size + other->size; + if (vector_length_squared(vector_sub(other->pos, spot)) < reach * reach) return true; + } + return false; +} + +// Big Horn moves under the floor to a free spot and his big hole opens there. +static void big_hole_move(Entity_NPC& npc) +{ + Vector margin = vector_make(npc.size * BIG_HOLE_MARGIN_X, npc.size * BIG_HOLE_MARGIN_Y); + for (int tries = 0; tries < HORN_SPOT_TRIES; tries++) + { + Vector spot = hole_spot_roll(margin); + if (is_big_hole_blocked(npc, spot)) continue; + npc.sprite.Play("BigHoleOpen"); + npc.pos = spot; + return; + } + KAGE_LogMessage(LOG_WARN, (uint8_t*)"Failed to find safe for big horn to move to\n"); +} + +// Popping up out of the open big hole: spitting, or dizzy if he swallowed a bomb. While he holds bombs they go off +// in him one each 5 ticks instead. +static void horn_pop_up(Entity_NPC& npc) +{ + Entity* held = npc.child; + npc.entityCollisionClass = ENTCOLL_ALL; + npc.isInvincible = false; + if (held) + { + if (npc.GetIntervalTicks(HELD_BOMB_EVERY, 0)) + { + npc.child = held->child; + held_bomb_explode(held, npc.pos); + held->Remove(); + } + return held_bombs_keep(npc); + } + + if (npc.i1 < 1) + { + npc.state = HORN_SPIT; + npc.sprite.Play("PopUp"); + npc.PlaySound(SOUND_BOSS_LITE_ROAR, 1, 2, false, 1); + npc.PlaySound(SOUND_BIGHORN_APPEAR, 1, 2, false, 1); + } + else + { + npc.state = HORN_DIZZY; + npc.sprite.Play("PopUpDizzy"); + npc.i2 = DIZZY_FRAMES; + npc.i1 = 0; + } + npc.stateFrame = 0; + npc.renderDepthOffset = 0; +} + +// Hidden: once under, his holes open and he takes no hurt but from the invincible-piercing kind. Later his big hole +// moves and opens, and he pops up once it is open and nobody is falling. +static void horn_hidden(Entity_NPC& npc, int ticks, bool isBusy) +{ + if (npc.stateFrame == 0) + { + npc.entityCollisionClass = ENTCOLL_NONE; + if (npc_anim_is_done(npc)) + { + npc.renderDepthOffset = HOLE_DEPTH; + npc.stateFrame = 1; + return small_holes_open(npc); + } + if (npc.pendingDamage > 0) + for (DamageEvent& hurt : npc.damageEvents) + if (!(hurt.damageFlags & DAMAGE_INVINCIBLE)) hurt.damage *= 0; + return; + } + + npc.stateFrame += ticks; + bool isOpening = npc.sprite.GetAnimation() == "BigHoleOpen"; + bool isDone = npc_anim_is_done(npc); + if (isOpening && isDone && npc.sprite.animState.animData) + { + if (!isBusy) horn_pop_up(npc); + return; + } + if (npc.stateFrame < HIDDEN_FRAMES) return; + if (!isOpening || isDone) return big_hole_move(npc); + + if (npc.sprite.IsEventTriggered("Crack")) npc_sound_play(SOUND_BIGHORN_CRACK_BIG, 1, 2, 1); + if (npc.sprite.IsEventTriggered("Open")) npc_sound_play(SOUND_BIGHORN_OPEN_BIG, 1, 2, 1); + if (npc.sprite.IsEventTriggered("Shake")) npc_sound_play(SOUND_BIGHORN_SHAKE_BIG, 1, 2, 1); +} + +// Resting: his Idle once up, then he pops down into his big hole and hides (a calm Delirium form idles on). +static void horn_rest(Entity_NPC& npc, int ticks) +{ + npc.renderDepthOffset = 0; + if (npc.stateFrame == 0) + { + if (!npc_anim_is_done(npc)) return; + npc.sprite.Play("Idle"); + npc.entityCollisionClass = ENTCOLL_ALL; + npc.stateFrame += ticks; + npc.isInvincible = false; + return; + } + if (npc.stateFrame < 0) return; + + npc.stateFrame += ticks; + if (npc.stateFrame <= HORN_REST_FRAMES || (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear())) + { + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && npc_anim_is_done(npc)) npc_anim_restart(npc.sprite, "Idle"); + return; + } + if (!npc.sprite.IsPlaying("PopDown")) npc.sprite.Play("PopDown"); + else if (npc.sprite.IsEventTriggered("Hide")) npc_sound_play(SOUND_BIGHORN_HIDE, 1, 2, 1); + if (!npc_anim_is_done(npc)) return; + + npc_sound_play(SOUND_BIGHORN_CLOSE_BIG, 1, 2, 1); + npc.sprite.Play("BigHoleClose"); + npc.state = HORN_HIDDEN; + npc.stateFrame = 0; +} + +// The spit: a dark smoke cloud and one to three Little Horn balls, the plain Charge's aimed at a random player's side +// (two at most for a Delirium form). +static void horn_balls_spit(Entity_NPC& npc) +{ + std::array, 3> throws = SPIT_VELOCITIES; + int count = 1; + if (!npc_anim_is_done(npc)) + { + const std::string& anim = npc.sprite.GetAnimation(); + Entity_Player* prey = anim == "Charge" ? game_random_player(*g_game, npc.pos, ANY_PLAYER_REACH) : nullptr; + if (prey && prey->pos.x < npc.pos.x) throws[0][0] = -throws[0][0]; + count = anim == "Charge2" ? 2 : anim == "Charge3" ? 3 : 1; + } + Entity_Effect* cloud = npc.MakeBloodCloud(npc.pos, HORN_CLOUD_COLOR, HORN_CLOUD_SCALE); + cloud->posOffset = vector_make(0, HORN_CLOUD_HEIGHT); + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + count = HORN_BALL_LIMIT - (int)entity_query(ENTITY_LITTLE_HORN, LITTLE_HORN_BALL).size(); + + int first = count == 2 ? 1 : 0; + for (int i = 0; i < count; i++) + { + Vector velocity = vector_make(throws[first + i][0], throws[first + i][1]); + auto* ball = + static_cast(g_game->Spawn({.position = vector_add(npc.pos, vector_scale(velocity, SPIT_LEAD)), + .velocity = velocity, + .spawner = &npc, + .subType = count == 2 || i > 1 ? BALL_ROLLING_SUBTYPE : 0, + .type = ENTITY_LITTLE_HORN, + .variant = LITTLE_HORN_BALL, + .seed = Random()})); + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + { + ball->health = DELIRIUM_BALL_HEALTH; + ball->maxHitPoints = DELIRIUM_BALL_HEALTH; + } + ball->ClearEntityFlags(FLAG_APPEAR); + ball->sprite.ReplaceSpritesheet(0, SPIT_BALL_SHEET); + ball->sprite.LoadGraphics(); + ball->SetSize(ball->size * SPIT_BALL_SIZE, vector_make(-1, -1), -1); + } + npc.PlaySound(SOUND_BIGHORN_SPIT, 1, 2, false, 1); +} + +// Popped up: one of his three charges (or back to rest when too near the bottom wall), spitting balls on Shoot and +// swallowing a rising bomb. A swallowed bomb goes off in him on BombExplode, leaving him dizzy. +static void horn_spit(Entity_NPC& npc, int ticks) +{ + npc.renderDepthOffset = 0; + if (npc.stateFrame == 0) + { + if (!npc_anim_is_done(npc)) return; + if (g_game->room->bottomRightPos.y - npc.pos.y <= npc.size) npc.state = HORN_REST; + else + { + uint32_t roll = Random() % SPIT_ROLL; + npc.sprite.Play(roll < SPIT_TWO_ODDS ? "Charge2" : roll < SPIT_THREE_ODDS ? "Charge3" : "Charge"); + npc.stateFrame++; + npc_sound_play(SOUND_BIGHORN_PRE_SPIT, 1, 2, 1); + } + npc.isInvincible = false; + npc.entityCollisionClass = ENTCOLL_ALL; + return; + } + + npc.stateFrame += ticks; + if (npc.sprite.IsEventTriggered("Shoot")) horn_balls_spit(npc); + if (npc.sprite.WasEventTriggered("Shoot")) bomb_grab(npc); + held_bombs_keep(npc); + if (npc.child && npc.sprite.WasEventTriggered("BombExplode")) + { + npc_sound_play(SOUND_BIGHORN_HURT, 1, 2, 1); + Entity* held = npc.child->type == ENTITY_BOMB ? npc.child.get() : nullptr; + npc.child = nullptr; + if (held) held_bomb_explode(held, vector_make(npc.pos.x, npc.pos.y + HELD_BOMB_DROP)); + } + if (!npc_anim_is_done(npc)) return; + + Entity* held = npc.child; + if (held) + { + npc.isInvincible = false; + npc.child = nullptr; + held_bomb_explode(held, npc.pos); + held->Remove(); + return; + } + if (npc.i1 < 1) + { + npc.state = HORN_REST; + return; + } + npc.stateFrame = 1; + npc.state = HORN_DIZZY; + npc.sprite.Play("DizzyLoop"); + npc.i2 = DIZZY_FRAMES; + npc.i1 = 0; +} + +// Dizzy: he takes a fifth more hurt until it wears off, then shakes it off and rests. +static void horn_dizzy(Entity_NPC& npc, int ticks) +{ + npc.entityCollisionClass = ENTCOLL_ALL; + npc.renderDepthOffset = 0; + if (npc.stateFrame == 0) + { + if (!npc_anim_is_done(npc)) return; + npc.stateFrame = 1; + npc.sprite.Play("DizzyLoop"); + return; + } + + if (npc.pendingDamage > 0) + for (DamageEvent& hurt : npc.damageEvents) hurt.damage *= DIZZY_HURT; + npc.i2 -= ticks; + if (npc.i2 >= 1) return; + + bool isShaking = npc.sprite.GetAnimation() == "DizzyEnd"; + if (isShaking && npc_anim_is_done(npc)) + { + npc.state = HORN_REST; + npc.stateFrame = 0; + npc.i2 = 0; + return; + } + if (isShaking) return; + npc.sprite.Play("DizzyEnd"); + npc_sound_play(SOUND_BIGHORN_DIZZY_SHAKE, 1, 2, 1); +} + +// Big Horn himself, and on death his held bombs gone and his holes with him. +static void big_horn_head_update(Entity_NPC& npc, int ticks, bool isBusy) +{ + switch (npc.state) + { + case HORN_REST: + horn_rest(npc, ticks); + break; + case HORN_HIDDEN: + horn_hidden(npc, ticks, isBusy); + break; + case HORN_SPIT: + horn_spit(npc, ticks); + break; + case HORN_DIZZY: + horn_dizzy(npc, ticks); + break; + } + if (!npc.isDead) return; + + npc_sound_play(SOUND_BIGHORN_DEATH, 1, 2, 1); + while (Entity* held = npc.child) + { + npc.child = held->child; + held->Remove(); + } + for (Entity* part : entity_query(npc.type, -1)) + if (part != &npc && part->variant != 0 && part->parent == &npc && !part->isDead) part->Kill(EntityRef(&npc)); +} + +// A hole's link to Big Horn: gone without him, sharing the lower health of the two, dying with him. False once gone. +static bool hole_link(Entity_NPC& npc) +{ + Entity* horn = npc.parent; + if (!horn) + { + npc.Remove(); + return false; + } + if (horn->health <= npc.health) npc.health = horn->health; + else horn->health = npc.health; + if (npc.isDead) npc.Kill(EntityRef()); + return true; +} + +static void hole_close(Entity_NPC& npc) +{ + npc.sprite.Play("SmallHoleClose"); + npc_sound_play(SOUND_BIGHORN_CLOSE_SMALL, 1, 2, 1); + npc.state = HOLE_CLOSING; +} + +// Starts a hand's attack once its hole is open: touchable, rising. +static void hand_rise(Entity_NPC& npc, std::string_view anim) +{ + npc.collisionDamage = HORN_HAND_DAMAGE; + npc.entityCollisionClass = ENTCOLL_ALL; + npc.isInvincible = false; + npc.sprite.Play(anim); + npc_sound_play(SOUND_BIGHORN_HAND_APPEAR, 1, 2, 1); + npc.stateFrame++; +} + +// An open small hole: once open, what stands over it falls in, and after 30 frames it closes, or a hand throws the +// bomb that fell in back out (a spray for several). +static void hole_open(Entity_NPC& npc, int ticks, bool isBusy) +{ + npc.renderDepthOffset = HOLE_DEPTH; + if (npc.stateFrame == 0) + { + if (!npc_anim_is_done(npc)) return; + npc.collisionDamage = HORN_HAND_DAMAGE; + npc.stateFrame = 1; + npc.entityCollisionClass = ENTCOLL_ENEMIES; + return; + } + if (npc.sprite.GetAnimation() != "SmallHoleOpen") + { + npc.entityCollisionClass = ENTCOLL_NONE; + if (npc_anim_is_done(npc)) npc.Remove(); + return; + } + + hole_swallow(npc); + npc.stateFrame += ticks; + if (npc.stateFrame <= HOLE_OPEN_FRAMES || isBusy) return; + if (npc.i1 == 1) npc.state = HAND_THROW; + else if (npc.i1 < 2) npc.sprite.Play("SmallHoleClose"); + else npc.state = HAND_BOMBS; + npc.stateFrame = 0; + npc.i1 = 0; + npc_sound_play(SOUND_BIGHORN_CLOSE_SMALL, 1, 2, 1); +} + +// The slap's Slam: what its null reaches is pushed off and hurt, with dust, water and a thud. +static void hand_slam(Entity_NPC& npc) +{ + Capsule slam; + npc.GetNullCapsule(slam, "Slam"); + if (slam.radius > 0) + for (Entity* other : entity_query_radius(slam.center, slam.halfLength + slam.radius, QUERY_ALL)) + { + if (other->entityCollisionClass == ENTCOLL_NONE || other->entityGridCollisionClass == GRIDCOLL_BULLET || + other == &npc || !Capsule::Collide(slam, other->GetCollisionCapsule({}))) + continue; + + Vector away = vector_sub(other->pos, npc.pos); + if (vector_length(away) > 0) away = vector_normalized(away); + other->velocity = vector_add(other->velocity, vector_scale(away, SLAP_PUSH)); + float damage = other->is_player() || other->IsFamiliar() ? HORN_HAND_DAMAGE : SLAP_DAMAGE; + other->TakeDamage(damage, 0, EntityRef(&npc), SLAP_COUNTDOWN); + } + npc.MakeGroundPoof(slam.center, SLAP_POOF_COLOR, SLAP_POOF_SIZE); + water_drops_spawn(slam.center, vector_make(SLAP_DROPS_X, SLAP_DROPS_Y), 1); + game_shake_screen(SLAP_SHAKE); + npc.PlaySound(SOUND_FORESTBOSS_STOMPS, 1, 2, false, 1); +} + +// The slap: after its wait the hand rises at a random player, drifts at it between Move and Stop, and slams. +static void hand_slap(Entity_NPC& npc, int ticks) +{ + int frame = npc.stateFrame; + npc.renderDepthOffset = 0; + if (frame == 0) + { + if (!npc_anim_is_done(npc)) return; + npc.i2 -= ticks; + if (npc.i2 >= 0) return; + npc.isInvincible = false; + npc.entityCollisionClass = ENTCOLL_ALL; + npc.collisionDamage = HORN_HAND_DAMAGE; + npc.sprite.Play("HandSlap"); + npc_sound_play(SOUND_BIGHORN_HAND_APPEAR, 1, 2, 1); + npc.target = game_random_player(*g_game, npc.pos, ANY_PLAYER_REACH); + npc.stateFrame = 1; + return; + } + if (frame < 0) return; + + if (frame != 2) npc.velocity = {}; + else + { + if (Entity* target = npc.target) npc.velocity = vector_sub(target->pos, npc.pos); + npc.velocity = vector_scale(vector_normalized(npc.velocity), SLAP_SPEED); + } + if (npc.sprite.IsEventTriggered("Move")) npc.stateFrame = 2; + else if (npc.sprite.IsEventTriggered("Stop")) npc.stateFrame = 1; + if (npc.sprite.IsEventTriggered("Slam")) hand_slam(npc); + if (npc_anim_is_done(npc)) hole_close(npc); +} + +static int fuse_roll() +{ + return (int)(Random() % FUSE_RANGE) + FUSE_MIN; +} + +// The throw: the hand rises holding a hidden frozen bomb (Troll, Mega Troll, hot or sad blood), and on Shoot throws it +// at the nearest player. +static void hand_throw(Entity_NPC& npc) +{ + npc.renderDepthOffset = 0; + if (npc.stateFrame == 0) + { + if (!npc_anim_is_done(npc)) return; + hand_rise(npc, "HandThrow"); + int kind = BOMB_TROLL; + TearFlags flags{}; + uint32_t roll = Random() % THROW_ROLL; + if (roll < THROW_MEGA_ODDS) kind = BOMB_SUPERTROLL; + else if (roll < THROW_SPECIAL_ODDS) + { + bool isDry = g_game->room->waterAmount <= 0; + kind = isDry ? BOMB_HOT : BOMB_SAD_BLOOD; + flags.set(isDry ? TEAR_BURN : TEAR_SAD_BOMB); + } + auto* bomb = static_cast(g_game->Spawn( + {.position = npc.pos, .spawner = &npc, .type = ENTITY_BOMB, .variant = kind, .seed = Random()})); + bomb->isVisible = false; + bomb->entityCollisionClass = ENTCOLL_NONE; + bomb->entityGridCollisionClass = GRIDCOLL_NONE; + bomb->parent = &npc; + bomb->AddEntityFlags(FLAG_FREEZE); + bomb->isLoadCostumes = true; + bomb->tearFlags = flags; + if (kind == BOMB_TROLL || kind == BOMB_SUPERTROLL) + { + bomb->explosionCountdown = fuse_roll(); + bomb->explosionCountdown2 = bomb->explosionCountdown; + } + npc.entityRef = bomb; + return; + } + if (npc.stateFrame != 1) return; + + if (npc.sprite.IsEventTriggered("Shoot")) + { + Entity* bomb = npc.entityRef; + if (bomb && bomb->type == ENTITY_BOMB) + { + Entity_Player* nearest = game_nearest_player(npc.pos); + Vector throwVelocity = vector_scale(vector_normalized(vector_sub(nearest->pos, npc.pos)), HORN_THROW_SPEED); + bomb->parent = &npc; + bomb->ClearEntityFlags(FLAG_FREEZE); + bomb->pos = vector_make(throwVelocity.x * HORN_THROW_REACH + npc.pos.x, throwVelocity.y + npc.pos.y); + bomb->velocity = throwVelocity; + bomb->entityCollisionClass = ENTCOLL_ALL; + bomb->isVisible = true; + static_cast(bomb)->fallSpeed = THROWN_BOMB_FALL; + bomb->posOffset = vector_make(0, THROWN_BOMB_HEIGHT); + bomb->Update(); + npc.entityRef = nullptr; + } + npc.PlaySound(SOUND_SHELLGAME, 1, 2, false, 1); + } + if (npc_anim_is_done(npc)) hole_close(npc); +} + +// The spray: on Shoot three Troll Bombs fanned 80 degrees apart at the nearest player, already lit. +static void hand_bombs(Entity_NPC& npc) +{ + npc.renderDepthOffset = 0; + if (npc.stateFrame == 0) + { + if (npc_anim_is_done(npc)) hand_rise(npc, "HandBombs"); + return; + } + if (npc.stateFrame != 1) return; + + if (npc.sprite.IsEventTriggered("Shoot")) + { + Entity_Player* nearest = game_nearest_player(npc.pos); + Vector aim = vector_scale(vector_normalized(vector_sub(nearest->pos, npc.pos)), HORN_SPRAY_SPEED); + Vector lead = vector_scale(aim, SPRAY_LEAD); + Vector base = vector_make(aim.x * HORN_THROW_REACH + npc.pos.x, aim.y + npc.pos.y); + for (float degrees : SPRAY_ANGLES) + { + uint32_t seed = Random(); + float angle = degrees * DEGREES_TO_RADIANS; + float c = std::cos(angle); + float s = std::sin(angle); + Vector velocity = vector_make(aim.x * c - aim.y * s, aim.x * s + aim.y * c); + Vector spot = vector_make(lead.x * c - lead.y * s + base.x, lead.y * c + lead.x * s + base.y); + auto* bomb = static_cast(g_game->Spawn({.position = spot, + .velocity = velocity, + .spawner = &npc, + .type = ENTITY_BOMB, + .variant = BOMB_TROLL, + .seed = seed})); + bomb->ClearEntityFlags(FLAG_APPEAR); + bomb->tearFlags.reset(); + bomb->isLoadCostumes = true; + bomb->parent = &npc; + float rise = random_unit(); + bomb->posOffset = vector_make(0, THROWN_BOMB_HEIGHT); + bomb->fallSpeed = SPRAY_FALL_MIN - rise * SPRAY_FALL_RANGE; + bomb->explosionCountdown = fuse_roll(); + bomb->explosionCountdown2 = bomb->explosionCountdown; + if (const AnimationData* anim = bomb->sprite.animState.animData) + bomb->sprite.animState.AdvancePosition(anim->length - 1); + } + npc.PlaySound(SOUND_SHELLGAME, 1, 2, false, 1); + } + if (npc_anim_is_done(npc)) hole_close(npc); +} + +// The Little Horn hand: a ball on each Shoot, 30 degrees round each time, then it hides again on Stop. +static void hand_horns(Entity_NPC& npc) +{ + npc.renderDepthOffset = 0; + if (npc.stateFrame == 0) + { + if (npc_anim_is_done(npc)) hand_rise(npc, "HandLittleHorn"); + return; + } + if (npc.stateFrame < 0) return; + + if (npc.sprite.IsEventTriggered("Move")) npc.PlaySound(SOUND_LITTLE_HORN_GRUNT_1, 1, 2, false, 1); + if (npc.sprite.IsEventTriggered("Shoot")) + { + float pitch = + (float)(npc.stateFrame - 1) * HORNS_PITCH_STEP + HORNS_PITCH_BASE + random_unit() * HORNS_PITCH_RANGE; + npc.PlaySound(SOUND_LITTLE_HORN_COUGH, 1, 2, false, pitch); + auto* ball = static_cast(g_game->Spawn({.position = npc.pos, + .spawner = &npc, + .type = ENTITY_LITTLE_HORN, + .variant = LITTLE_HORN_BALL, + .seed = Random()})); + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + { + ball->health = DELIRIUM_BALL_HEALTH; + ball->maxHitPoints = DELIRIUM_BALL_HEALTH; + } + Vector velocity = vector_scale( + vector_from_angle(HORNS_ANGLE_START - (float)(npc.stateFrame - 2) * HORNS_ANGLE_STEP), HORNS_SPEED); + ball->velocity = velocity; + ball->ClearEntityFlags(FLAG_APPEAR); + ball->pos = vector_add(npc.pos, velocity); + npc.stateFrame++; + } + if (npc.sprite.IsEventTriggered("Stop")) + { + npc.isInvincible = true; + npc.entityCollisionClass = ENTCOLL_NONE; + } + if (npc_anim_is_done(npc)) hole_close(npc); +} + +// A small hole's first frame: opening untouchable, its hand picked by its subtype, sometimes waiting longer to slap. +static void small_hole_init(Entity_NPC& npc) +{ + npc.isCanShutDoors = false; + npc.isInvincible = true; + npc_anim_restart(npc.sprite, "SmallHoleOpen"); + npc.entityCollisionClass = ENTCOLL_NONE; + if (npc.subtype & 1) npc.sprite.isFlipX = true; + npc.state = npc.subtype >= 0 && npc.subtype < (int)HAND_STATES.size() ? HAND_STATES[npc.subtype] : HOLE_OPEN; + if (Random() & 1) npc.i2 = HAND_SLAP_DELAY; + npc.AddEntityFlags(FLAG_NO_BLOOD_SPLASH); +} + +// A small hole: its link to Big Horn (a Little Horn hand killed before its bomb went off frees a weak Little Horn), +// then its state, and its sounds. +static void small_hole_update(Entity_NPC& npc, int ticks, bool isBusy) +{ + if (!hole_link(npc)) return; + if (npc.isDead && (npc.subtype == HAND_HORNS_KIND || npc.subtype == HAND_HORNS_KIND + 1) && + !npc.sprite.WasEventTriggered("BombExplode") && npc.deliriumBossType == 0) + { + auto* horn = static_cast( + g_game->Spawn({.position = npc.pos, .spawner = npc.parent, .type = ENTITY_LITTLE_HORN, .seed = Random()})); + horn->ClearEntityFlags(FLAG_APPEAR); + horn->maxHitPoints *= HAND_HORN_HEALTH; + horn->health = horn->maxHitPoints; + horn->stateFrame = 0; + horn->state = NPC_STATE_IDLE; + horn->entityGridCollisionClass = GRIDCOLL_WALLS; + horn->i1 = HAND_HORN_I1; + horn->Update(); + } + + switch (npc.state) + { + case HOLE_OPEN: + hole_open(npc, ticks, isBusy); + break; + case HOLE_CLOSING: + npc.velocity = {}; + if (npc_anim_is_done(npc)) npc.Remove(); + break; + case HAND_SLAP: + hand_slap(npc, ticks); + break; + case HAND_THROW: + hand_throw(npc); + break; + case HAND_BOMBS: + hand_bombs(npc); + break; + case HAND_HORNS: + hand_horns(npc); + break; + } + if (npc.sprite.IsEventTriggered("Hide")) npc_sound_play(SOUND_BIGHORN_HAND_HIDE, 1, 2, 1); + if (npc.sprite.IsEventTriggered("Crack")) npc_sound_play(SOUND_BIGHORN_CRACK_SMALL, 1, 2, 1); + if (npc.sprite.IsEventTriggered("Open")) npc_sound_play(SOUND_BIGHORN_OPEN_SMALL, 1, 2, 1); + if (npc.sprite.IsEventTriggered("Shake")) npc_sound_play(SOUND_BIGHORN_SHAKE_SMALL, 1, 2, 1); +} + +// A big hole: open for 60 frames swallowing what stands over it, then it closes and frees a hand where the bombs +// that fell in come back (a slap for one, a throw for more). +static void big_hole_update(Entity_NPC& npc, bool isBusy) +{ + npc.renderDepthOffset = HOLE_DEPTH; + if (!hole_link(npc) || npc.state != HOLE_OPEN) return; + if (npc.stateFrame == 0) + { + if (npc_anim_is_done(npc)) npc.stateFrame = 1; + return; + } + if (npc.sprite.GetAnimation() == "BigHoleOpen") + { + hole_swallow(npc); + if (npc.stateFrame++ > BIG_HOLE_OPEN_FRAMES && !isBusy) npc.sprite.Play("BigHoleClose"); + return; + } + if (!npc_anim_is_done(npc)) return; + + npc.Remove(); + if (npc.i1 >= 1) + { + uint32_t seed = Random(); + Vector spot = g_game->room->GetRandomPosition(0); + Entity* hand = g_game->Spawn({.position = spot, + .spawner = &npc, + .subType = npc.i1 >= 2 ? BOMBS_HAND : ONE_BOMB_HAND, + .type = ENTITY_BIG_HORN, + .variant = BIG_HORN_HAND, + .seed = seed}); + hand->ClearEntityFlags(FLAG_APPEAR); + } + npc.i1 = 0; +} + +// The hole helper drawing Big Horn's hole layer at floor depth, made once his Hole layer shows. +static void hole_helper_keep(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT || npc.entityDeque.empty()) npc.entityDeque.resize(1); + LayerState* hole = npc.entityDeque.front() ? nullptr : npc.sprite.GetLayer("Hole"); + if (!hole) return; + + Entity* helper = g_game->Spawn({.position = npc.pos, + .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = EFFECT_BIG_HORN_HOLE_HELPER, + .seed = Random()}); + helper->parent = &npc; + static_cast(helper)->state = hole->layerData ? hole->layerData->id : -1; + npc.entityDeque.front() = helper; + hole->isVisible = false; +} + +// 00453140 NpcAI::ENTITY_BIG_HORN: Big Horn rests up, hides in his big hole while small holes swallow players and +// bombs and his hands slap, throw bombs or Little Horns, then pops up elsewhere spitting Little Horn balls, dizzy for +// a while if he swallowed a bomb. Only a slapping hand moves. +void boss_big_horn_update(Entity_NPC& npc) +{ + int ticks = npc_ticks_get(npc); + bool isBusy = is_hole_busy(); + hole_helper_keep(npc); + + if (npc.variant == BIG_HORN_HAND) + { + if (npc.state == NPC_STATE_INIT) return small_hole_init(npc); + small_hole_update(npc, ticks, isBusy); + if (!npc.parent) return; + } + else if (npc.variant == HORN_BIG_HOLE) + { + if (npc.state == NPC_STATE_INIT) + { + npc.sprite.Play("BigHoleOpen", PLAY_FORCED); + npc.state = HOLE_OPEN; + npc.isCanShutDoors = false; + npc.isInvincible = true; + npc.collisionDamage = 0; + npc.entityCollisionClass = ENTCOLL_ENEMIES; + npc.renderDepthOffset = HOLE_DEPTH; + npc.AddEntityFlags(FLAG_NO_BLOOD_SPLASH); + return; + } + big_hole_update(npc, isBusy); + if (!npc.parent) return; + } + else if (npc.state == NPC_STATE_INIT) + { + npc.sprite.Play("Appear"); + npc.state = HORN_REST; + return; + } + else big_horn_head_update(npc, ticks, isBusy); + + if (npc.variant != BIG_HORN_HAND || npc.state != HAND_SLAP || npc.stateFrame < 1) npc.friction = 0; +} diff --git a/src/boss_dark_one.cpp b/src/boss_dark_one.cpp new file mode 100644 index 0000000..7877726 --- /dev/null +++ b/src/boss_dark_one.cpp @@ -0,0 +1,227 @@ +#include "boss_ai.h" +#include "entity_laser.h" +#include "npc_caves.h" +#include "sfx_manager.h" +#include + +// The Dark One's states: walking about, the ring of shots, the laser down, the charge and the darkness. +constexpr int DARK_ONE_WALK = NPC_STATE_MOVE; +constexpr int DARK_ONE_RING = NPC_STATE_ATTACK; +constexpr int DARK_ONE_LASER = NPC_STATE_ATTACK2; +constexpr int DARK_ONE_CHARGE = NPC_STATE_ATTACK3; +constexpr int DARK_ONE_DARKNESS = NPC_STATE_SPECIAL; + +constexpr uint64_t DARK_ONE_SCARED = FLAG_FEAR | FLAG_SHRINK; +constexpr uint64_t DARK_ONE_DISTRACTED = FLAG_CONFUSION | FLAG_FEAR | FLAG_SHRINK; +constexpr float DARK_ONE_FRICTION = 0.8f; + +// Walking: every 60 frames it may darken the room (always when scared, never while dark), and every 10 frames a ring, +// a charge when in line (more often in the dark) or a laser down at a target below it. +constexpr int DARKNESS_EVERY = 60; +constexpr uint32_t DARKNESS_SKIP = 2; +constexpr int DARK_ONE_ATTACK_EVERY = 10; +constexpr uint32_t DARK_ONE_RING_ODDS = 6; +constexpr uint32_t DARK_CHARGE_ODDS = 5; +constexpr float CHARGE_LINE_BAND = 20; +constexpr float LASER_LINE_BAND = 40; +constexpr float DARKNESS_STRENGTH = 1; +constexpr int DARKNESS_FRAMES = 180; + +// The ring: twelve shots at 9 on Shoot. +constexpr float DARK_ONE_RING_SPEED = 9; +constexpr float DARK_ONE_RING_SHOTS = 12; +constexpr float RING_HEIGHT = -17; +constexpr float DARK_ONE_RING_FALL = 1.3f; + +// The laser: a short thick laser down, shown first by a tracer. +constexpr float LASER_DEGREES = 90; +constexpr float LASER_DROP = 5; +constexpr float DARK_ONE_LASER_HEIGHT = -20; +constexpr int DARK_ONE_LASER_TIMEOUT = 10; +constexpr float DARK_ONE_TRACER_SCALE = 4; +constexpr int DARK_ONE_TRACER_TIMEOUT = 22; +constexpr ColorMod DARK_ONE_TRACER_COLOR = {{0.6f, 0.05f, 0, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}}; + +// The charge: 22 a frame across the room and round 100 past the far wall, steered at the target's line, until it +// passes where it set off after two laps. +constexpr float DARK_ONE_CHARGE_SPEED = 22; +constexpr float CHARGE_STEER_RANGE = 100; +constexpr float CHARGE_STEER_MAX = 0.4f; +constexpr float CHARGE_WRAP_REACH = 100; +constexpr int CHARGE_DONE_LAPS = 3; + +// Restarts an attack's animation unless it already shows (or loops on, stopped). +static void attack_anim_keep(Entity_NPC& npc, std::string_view anim) +{ + const AnimationData* shown = npc.sprite.animState.animData; + if (shown && shown->name == anim && !(shown->isLooping && !npc.sprite.animState.isPlaying)) return; + npc_anim_restart(npc.sprite, anim); +} + +// Walking about at random, and now and then the darkness, the ring, the charge or the laser. +static void dark_one_walk(Entity_NPC& npc, Vector toTarget) +{ + npc.stateFrame++; + npc.sprite.Play("Walk"); + npc.pathfinder.MoveRandomlyBoss(STATUS_OBEYED); + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) return; + + bool isDarkRoll = npc.IsFrame(DARKNESS_EVERY, npc.index) && (Random() & 3) <= DARKNESS_SKIP; + bool isDark = g_game->darknessModifier > 0; + if ((npc.HasEntityFlags(DARK_ONE_SCARED) || isDarkRoll) && !isDark) + { + npc.state = DARK_ONE_DARKNESS; + npc.stateFrame = 0; + npc.PlaySound(SOUND_MONSTER_GRUNT_0, 1, 2, false, 1); + return; + } + if (npc.IsFrame(DARK_ONE_ATTACK_EVERY, npc.index) && Random() % DARK_ONE_RING_ODDS == 0) + { + npc.state = DARK_ONE_RING; + npc.stateFrame = 0; + return; + } + + bool isLineCharge = + std::abs(toTarget.y) < CHARGE_LINE_BAND && npc.IsFrame(DARK_ONE_ATTACK_EVERY, npc.index) && (Random() & 1) == 0; + bool isDarkCharge = + !isLineCharge && isDark && npc.IsFrame(DARK_ONE_ATTACK_EVERY, npc.index) && Random() % DARK_CHARGE_ODDS == 0; + if ((!isLineCharge && !isDarkCharge) || npc.HasEntityFlags(DARK_ONE_DISTRACTED)) + { + if (std::abs(toTarget.x) >= LASER_LINE_BAND || toTarget.y <= 0 || + !npc.IsFrame(DARK_ONE_ATTACK_EVERY, npc.index) || (Random() & 1) != 0) + return; + npc.state = DARK_ONE_LASER; + npc.stateFrame = 0; + following_effect_spawn(npc, {.targetPosition = vector_from_angle(LASER_DEGREES), + .color = DARK_ONE_TRACER_COLOR, + .scale = DARK_ONE_TRACER_SCALE, + .timeout = DARK_ONE_TRACER_TIMEOUT}); + return; + } + + npc.PlaySound(SOUND_MONSTER_YELL_A, 1, 2, false, 1); + npc.sprite.isFlipX = toTarget.x < 0; + npc_anim_restart(npc.sprite, "Charge"); + npc.targetPosition = npc.pos; + npc.state = DARK_ONE_CHARGE; + npc.stateFrame = 0; +} + +// The ring and the laser: the attack's animation, its shot on Shoot, then walking once it ends. +static void dark_one_attack(Entity_NPC& npc) +{ + bool isRing = npc.state == DARK_ONE_RING; + npc.stateFrame++; + attack_anim_keep(npc, isRing ? "Attack1" : "Attack2"); + if (npc.sprite.animState.animData && npc.sprite.animState.IsEventTriggered("Shoot")) + { + if (isRing) + { + npc.PlaySound(SOUND_MONSTER_ROAR_0, 1, 2, false, 1); + ProjectileParams params; + params.heightModifier = RING_HEIGHT; + params.fallingSpeedModifier = DARK_ONE_RING_FALL; + npc.FireProjectiles(npc.pos, vector_make(DARK_ONE_RING_SPEED, DARK_ONE_RING_SHOTS), PROJECTILES_RING, + params); + } + else + { + Entity_Laser* laser = Entity_Laser::ShootAngle({.position = vector_make(npc.pos.x, npc.pos.y + LASER_DROP), + .posOffset = vector_make(0, DARK_ONE_LASER_HEIGHT), + .source = &npc, + .angleDegrees = LASER_DEGREES, + .timeout = DARK_ONE_LASER_TIMEOUT, + .variant = LASER_THICK_RED}); + laser->Update(); + } + } + if (!npc_anim_is_done(npc)) return; + + npc.state = DARK_ONE_WALK; + npc.stateFrame = 0; +} + +// The charge: once Charge fires, straight across the room steered at the target's line, wrapping round past the far +// wall, until it passes where it set off after two laps. +static void dark_one_charge(Entity_NPC& npc, Vector toTarget) +{ + if (npc.sprite.IsEventTriggered("Charge")) npc.stateFrame = 1; + if (npc_anim_is_done(npc)) npc.sprite.Play("Charge Shake"); + + int laps = npc.stateFrame; + if (laps > 0) + { + npc.velocity.x = npc.sprite.isFlipX ? -DARK_ONE_CHARGE_SPEED : DARK_ONE_CHARGE_SPEED; + float steer = std::clamp(-toTarget.y / CHARGE_STEER_RANGE, -CHARGE_STEER_MAX, CHARGE_STEER_MAX); + npc.velocity.y -= npc.speedMultiplier * steer / npc.friction; + } + + Room& room = *g_game->room; + float vx = npc.velocity.x; + if (vx > 0 && npc.pos.x > room.bottomRightPos.x + CHARGE_WRAP_REACH) + { + npc.pos.x = room.topLeftPos.x - CHARGE_WRAP_REACH; + npc.stateFrame = laps + 1; + } + else if (vx < 0 && npc.pos.x < room.topLeftPos.x - CHARGE_WRAP_REACH) + { + npc.pos.x = room.bottomRightPos.x + CHARGE_WRAP_REACH; + npc.stateFrame = laps + 1; + } + if (npc.stateFrame < CHARGE_DONE_LAPS) return; + if ((vx < 0 && npc.targetPosition.x > npc.pos.x) || (vx > 0 && npc.pos.x > npc.targetPosition.x)) + { + npc.state = DARK_ONE_WALK; + npc.stateFrame = 0; + } +} + +// The darkness: once it ends, the room goes dark for 180 frames. +static void dark_one_darkness(Entity_NPC& npc) +{ + npc.sprite.Play("Darkness"); + npc.stateFrame++; + if (!npc_anim_is_done(npc)) return; + + npc.state = DARK_ONE_WALK; + npc.stateFrame = 0; + g_game->darknessStrength = DARKNESS_STRENGTH; + g_game->darknessTimeout = DARKNESS_FRAMES; +} + +// 0045d7d0 NpcAI::ENTITY_DARK_ONE: the Dark One walks about in the room, fires rings of shots and a laser down, +// charges across the room and darkens it. Mega Satan's room keeps it below his platform. +void boss_dark_one_update(Entity_NPC& npc) +{ + npc.entityGridCollisionClass = GRIDCOLL_WALLS_Y; + Vector toTarget = vector_sub(npc.GetPlayerTarget()->pos, npc.pos); + if (npc.state == NPC_STATE_INIT) + { + npc.state = DARK_ONE_WALK; + npc.stateFrame = 0; + return; + } + + npc.friction = DARK_ONE_FRICTION; + if (npc.state != DARK_ONE_CHARGE) + npc.pos = g_game->room->GetClampedPositionImpl(npc.pos, npc.size, npc.size, npc.size, npc.size); + switch (npc.state) + { + case DARK_ONE_WALK: + dark_one_walk(npc, toTarget); + break; + case DARK_ONE_RING: + case DARK_ONE_LASER: + dark_one_attack(npc); + break; + case DARK_ONE_CHARGE: + dark_one_charge(npc, toTarget); + break; + case DARK_ONE_DARKNESS: + dark_one_darkness(npc); + break; + } + if (g_game->room->bossId == BOSS_ID_MEGA_SATAN && npc.pos.y < HORSEMAN_MEGA_SATAN_FLOOR) + npc.pos.y = HORSEMAN_MEGA_SATAN_FLOOR; +} diff --git a/src/boss_death.cpp b/src/boss_death.cpp index 1a77e8b..308b764 100644 --- a/src/boss_death.cpp +++ b/src/boss_death.cpp @@ -25,6 +25,16 @@ constexpr int VARIANT_SUPER = 1; constexpr int VARIANT_ULTRA_PRIDE = 2; constexpr int VARIANT_KRAMPUS = 1; constexpr int VARIANT_THE_PILE = 1; +constexpr int PILE_CHUNKS_MIN = 12; +constexpr int PILE_CHUNKS_RANGE = 12; +constexpr float PILE_CHUNK_SPEED = 5; +constexpr float PILE_CHUNK_SPREAD = 20; +constexpr float PILE_CHUNK_SPIN = 10; +constexpr float PILE_CHUNK_SPIN_MIN = 2; +constexpr int PILE_CHUNK_LIFE_MIN = 15; +constexpr int PILE_CHUNK_LIFE_RANGE = 15; +constexpr float PILE_CHUNK_ALPHA_MIN = 0.2f; +constexpr float PILE_CHUNK_ALPHA_RANGE = 0.5f; constexpr int VARIANT_MOTHER_PHASE_TWO = 10; constexpr int BIG_HORN_SMALL_HOLE = 1; constexpr int BIG_HORN_BIG_HOLE = 2; @@ -39,8 +49,6 @@ constexpr int EFFECT_POOF04 = 17; constexpr int EFFECT_BLOOD_GUSH = 42; constexpr int EFFECT_LARGE_BLOOD_EXPLOSION = 77; -constexpr int COLLECTIBLE_LUMP_OF_COAL = 132; -constexpr int COLLECTIBLE_HEAD_OF_KRAMPUS = 293; constexpr int COLLECTIBLE_QUARTER = 74; constexpr int COLLECTIBLE_FOREVER_ALONE = 128; constexpr int NULL_ITEM_SOL = 56; @@ -700,10 +708,38 @@ static int explosion_size_get(Entity_NPC& npc) return size; } +// Part of 006c4b30: The Pile bursts into 12 to 23 spinning clouds of dust, faint and short lived. +static void pile_chunks_spawn(Entity_NPC& npc, const NullFrame& bloodGuide) +{ + int chunks = random_below(PILE_CHUNKS_RANGE) + PILE_CHUNKS_MIN; + for (int i = 0; i < chunks; i++) + { + Vector heading = random_direction(); + Vector velocity = vector_scale(heading, random_unit() * PILE_CHUNK_SPEED); + uint32_t seed = Random(); + Vector direction = random_direction(); + Vector position = vector_add(npc.pos, vector_scale(direction, random_unit() * PILE_CHUNK_SPREAD)); + auto* chunk = static_cast(g_game->Spawn({.position = position, + .velocity = velocity, + .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = EFFECT_DUST_CLOUD, + .seed = seed})); + Vector side = vector_make(velocity.y, -velocity.x); + float spin = vector_dot(vector_sub(chunk->pos, npc.pos), side) < 0 ? -1.0f : 1.0f; + chunk->sprite.offset = bloodGuide.pos; + chunk->rotation = (random_unit() * PILE_CHUNK_SPIN + PILE_CHUNK_SPIN_MIN) * spin; + chunk->SetTimeout(random_below(PILE_CHUNK_LIFE_RANGE) + PILE_CHUNK_LIFE_MIN); + ColorMod faint = tint_color_make(1, 1, 1, random_unit() * PILE_CHUNK_ALPHA_RANGE + PILE_CHUNK_ALPHA_MIN); + chunk->SetColor(faint, -1, COLOR_PRIORITY_DEFAULT, false, true); + chunk->Update(); + } +} + // Part of 006c4b30: a death animation with a blood guide bleeds along it (update_blood_guide_gibs), and its Explosion // event bursts the boss: a blood explosion at the guide sized to it (with a large one for a boss with large gibs, but -// Pin's tail), its shadow gone and its gibs thrown. G-Fuel's explosions, Mom's Heart's shots and The Pile's chunks are -// not reconstructed yet. +// Pin's tail), Mom's Heart's shots and The Pile's chunks, its shadow gone and its gibs thrown. G-Fuel's explosions +// are not reconstructed yet. void npc_blood_guide_update(Entity_NPC& npc, const NullFrame& bloodGuide) { npc.update_blood_guide_gibs(bloodGuide); @@ -745,8 +781,7 @@ void npc_blood_guide_update(Entity_NPC& npc, const NullFrame& bloodGuide) } } if (npc.type == ENTITY_MOMS_HEART) boss_moms_heart_death_shots(npc); - if (npc.type == ENTITY_POLYCEPHALUS && npc.variant == VARIANT_THE_PILE) - reconstruction_missing("Entity_NPC::Update 006c4b30: The Pile's chunks"); + if (npc.type == ENTITY_POLYCEPHALUS && npc.variant == VARIANT_THE_PILE) pile_chunks_spawn(npc, bloodGuide); npc.shadowSize = 0; npc.BloodExplode(); } diff --git a/src/boss_death_horseman.cpp b/src/boss_death_horseman.cpp new file mode 100644 index 0000000..bc58258 --- /dev/null +++ b/src/boss_death_horseman.cpp @@ -0,0 +1,520 @@ +#include "boss_ai.h" +#include "entity_player.h" +#include "item_config.h" +#include "item_overlay.h" +#include "manager.h" +#include "npc_caves.h" +#include "player_manager.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include + +// Death's variants: Death on his horse, his scythes, his horse once he gets off, and Death on foot. The black Death +// (subtype 1) summons Kamikaze Leeches and Red Maws where the plain one throws scythes and calls Knights. +constexpr int DEATH_SCYTHE = 10; +constexpr int DEATH_HORSE = 20; +constexpr int DEATH_ON_FOOT = 30; +constexpr int DEATH_BLACK = 1; +constexpr int DEATH_KAMIKAZE_LEECH = 1; +constexpr int RED_MAW = 1; + +// Death's states: walking about, the scythe summon, the scythes from the walls, the hourglass, and getting off his +// horse. On foot: rising, walking and summoning. +constexpr int DEATH_WALK = NPC_STATE_MOVE; +constexpr int DEATH_SUMMON = NPC_STATE_SUMMON; +constexpr int DEATH_WALL_SCYTHES = NPC_STATE_SUMMON2; +constexpr int DEATH_HOURGLASS = NPC_STATE_ATTACK; +constexpr int DEATH_DISMOUNT = NPC_STATE_JUMP; +constexpr int DEATH_RISE = NPC_STATE_STOMP; +constexpr int SCYTHE_WAIT = NPC_STATE_IDLE; +constexpr int SCYTHE_FLY = NPC_STATE_MOVE; + +constexpr uint64_t DEATH_SCARED = FLAG_FEAR | FLAG_SHRINK; +constexpr float DEATH_RIDE_FRICTION = 0.8f; +constexpr float DEATH_DISMOUNT_HEALTH = 0.5f; +constexpr float DEATH_WALK_SPEED = 1; +constexpr ColorMod DEATH_SPLAT_COLOR = {{0.15f, 0, 0, 1}, {0, 0, 0, 0}, {0.1f, 0.1f, 0.1f}}; + +// Walking about: now and then a summon while few other enemies are about, the hourglass (the plain Death, while the +// room is not slowed already), or the wall scythes. +constexpr uint32_t SUMMON_ODDS = 90; +constexpr uint32_t HOURGLASS_ODDS = 180; +constexpr uint32_t WALL_SCYTHES_ODDS = 100; +constexpr int WALL_SCYTHES_ENEMY_LIMIT = 4; +constexpr int ON_FOOT_ENEMY_LIMIT = 2; + +// The summon: on frame 20 two scythes at free spots 250 to 350 out and away from the target (Leeches for the black +// Death), over after 48. +constexpr int SUMMON_FRAME = 20; +constexpr int SUMMON_FRAMES = 48; +constexpr float SUMMON_VOLUME = 1.2f; +constexpr int SCYTHE_TRIES = 20; +constexpr int SCYTHES = 2; +constexpr float SCYTHE_REACH_MIN = 250; +constexpr float SCYTHE_REACH_RANGE = 100; +constexpr float SCYTHE_TARGET_GAP = 150; +constexpr int LEECHES = 2; +constexpr int LEECH_LIMIT = 3; +constexpr float LEECH_REACH = 50; + +// The wall scythes: on frame 18 one at each wall in line with Death, but those too near the target. +constexpr int WALL_SCYTHES_FRAME = 18; +constexpr float WALL_SCYTHES_VOLUME = 1.5f; +constexpr float WALL_SCYTHE_TARGET_GAP = 80; + +// The hourglass: on frame 22 every player slowed for 160 frames and the room slowed as long (a charmed Death gives +// the room the Hourglass instead), over after 52. +constexpr int HOURGLASS_FRAME = 22; +constexpr int DEATH_HOURGLASS_FRAMES = 52; +constexpr int DEATH_SLOW_DURATION = 160; +constexpr float DEATH_SLOW_AMOUNT = 0.9f; +constexpr int HOURGLASS_BOOK_DELAY = 3; +constexpr ColorMod DEATH_SLOW_COLOR = {{1, 1, 1.3f, 1}, {0, 0, 0, 0}, {40 / 255.0f, 40 / 255.0f, 40 / 255.0f}}; + +// Getting off: the horse charges on 15 ahead and 8 up of where he stood (with 30 health for a Delirium form). +constexpr float HORSE_SIDE_OFFSET = 15; +constexpr float HORSE_RISE = 8; +constexpr float DELIRIUM_HORSE_HEALTH = 30; + +// A scythe: 15 health, hovering a while longer the nearer its target before it flies at it (a wall scythe waits its +// countdown frozen, then flies straight on and is gone after 180 frames). Gone once 250 out of the room. +constexpr float SCYTHE_FRICTION = 0.975f; +constexpr float SCYTHE_HEALTH = 15; +constexpr int SCYTHE_HOVER_FRAMES = 80; +constexpr float SCYTHE_HOVER_PER_DISTANCE = 0.1f; +constexpr int WALL_SCYTHE = 1; +constexpr int WALL_SCYTHE_FRAMES = 180; +constexpr float SCYTHE_HOMING = 0.5f; +constexpr float WALL_SCYTHE_SPEED = 0.75f; +constexpr float SCYTHE_ESCAPE = 250; + +// The horse: 18 a frame across the room (a quarter faster in hard mode), round 200 past the walls and a lap lower each +// time, whooshing once by the player. It bleeds while healthier than 40 under Death. +constexpr float HORSE_SPEED = 18; +constexpr float HARD_HORSE = 1.25f; +constexpr float HORSE_WRAP_REACH = 200; +constexpr float HORSE_LAP_DROP = 0.3f; +constexpr float HORSE_FLOOR_MARGIN = 40; +constexpr float HORSE_WOOSH_RANGE = 150; +constexpr float HORSE_BLEED_GAP = 40; +constexpr float HORSE_BLEED = 1; +constexpr float HORSE_FLEE_RANGE = 200; +constexpr float HORSE_FLEE_GAIN = 0.03f; +constexpr float HORSE_FLEE_MAX = 1.6f; + +// On foot: on frame 16 of a summon, two Knights (Red Maws for the black Death) 10 out to either side, over after 41. +constexpr int FOOT_SUMMON_FRAME = 16; +constexpr int FOOT_SUMMON_FRAMES = 41; +constexpr int KNIGHTS = 2; +constexpr float KNIGHT_REACH = 10; + +// Plays an attack's animation from its start with Death's cue, unless it already shows. +static void attack_anim_play(Entity_NPC& npc, std::string_view anim, int sound) +{ + if (npc.sprite.GetAnimation() == anim) return; + npc.sprite.Play(anim); + npc_sound_play(sound, 1, 2, 1); +} + +// Death's Vox event, a moan. +static void vox_play(bool isVox) +{ + if (isVox) npc_sound_play(SOUND_DEATH_VOX, 1, 2, 1); +} + +// A scythe of Death's, in his boss colors (a Delirium form's do not persist). +static Entity_NPC* scythe_spawn(Entity_NPC& npc, const Vector& position) +{ + auto* scythe = static_cast(g_game->Spawn( + {.position = position, .spawner = &npc, .type = npc.type, .variant = DEATH_SCYTHE, .seed = Random()})); + scythe->parent = &npc; + scythe->SetBossColorIdx(npc.bosscoloridx, 0); + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) scythe->ClearEntityFlags(FLAG_PERSISTENT); + return scythe; +} + +// A pair of summons to either side of Death, fewer when limited. +static void pair_spawn(Entity_NPC& npc, int type, int variant, Vector offset, int count) +{ + for (float side : {1.0f, -1.0f}) + { + if (count-- < 1) return; + g_game->Spawn({.position = vector_add(npc.pos, vector_scale(offset, side)), + .spawner = &npc, + .type = type, + .variant = variant, + .seed = Random()}); + } +} + +static bool is_few_enemies(int limit) +{ + Room& room = *g_game->room; + return room.GetAliveEnemiesCount() - room.GetAliveBossesCount() < limit; +} + +// Walking about at random, and now and then the summon, the hourglass or the wall scythes. +static void death_walk(Entity_NPC& npc) +{ + npc.AnimWalkFrame("Walk", "Walk", DEATH_WALK_SPEED); + npc.pathfinder.MoveRandomlyBoss(STATUS_OBEYED); + if (Random() % SUMMON_ODDS == 0 && is_few_enemies((int)(Random() & 1) + 1)) + { + npc.state = DEATH_SUMMON; + npc.stateFrame = 0; + return; + } + if (Random() % HOURGLASS_ODDS == 0 && g_game->room->slowdownDuration < 1 && npc.subtype == 0) + { + npc.state = DEATH_HOURGLASS; + npc.stateFrame = 0; + return; + } + if (Random() % WALL_SCYTHES_ODDS != 0 || !is_few_enemies(WALL_SCYTHES_ENEMY_LIMIT)) return; + npc.state = DEATH_WALL_SCYTHES; + npc.stateFrame = 0; +} + +// The summon: two scythes at free spots away from the target, or two Kamikaze Leeches for the black Death. +static void death_summon(Entity_NPC& npc) +{ + attack_anim_play(npc, "Attack01", SOUND_DEATH_SPAWN_PREP); + if (++npc.stateFrame != SUMMON_FRAME) + { + if (npc.stateFrame > SUMMON_FRAMES) npc.state = DEATH_WALK; + return; + } + + npc.PlaySound(SOUND_MONSTER_GRUNT_5, 1, 2, false, 1); + npc.PlaySound(SOUND_SUMMONSOUND, SUMMON_VOLUME, 2, false, 1); + if (npc.subtype == DEATH_BLACK) + { + Vector offset = vector_scale(random_direction(), LEECH_REACH); + int count = npc.HasEntityFlags(FLAG_DELIRIUM_FORM) + ? LEECH_LIMIT - npc.CountRelatedEntities(ENTITY_LEECH, DEATH_KAMIKAZE_LEECH, nullptr) + : LEECHES; + return pair_spawn(npc, ENTITY_LEECH, DEATH_KAMIKAZE_LEECH, offset, count); + } + + for (int tries = 0, spawned = 0; tries < SCYTHE_TRIES && spawned < SCYTHES; tries++) + { + Vector spot = room_free_pickup_position_find( + {.position = npc.pos, .step = random_unit() * SCYTHE_REACH_RANGE + SCYTHE_REACH_MIN}); + if (vector_length(vector_sub(npc.GetPlayerTarget()->pos, spot)) <= SCYTHE_TARGET_GAP) continue; + scythe_spawn(npc, spot); + spawned++; + } +} + +// The wall scythes: one at each wall in line with Death, frozen a while before they fly straight on. +static void death_wall_scythes(Entity_NPC& npc) +{ + attack_anim_play(npc, "Attack04", SOUND_DEATH_SPAWN_PREP); + if (++npc.stateFrame != WALL_SCYTHES_FRAME) + { + if (npc.stateFrame > SUMMON_FRAMES) npc.state = DEATH_WALK; + return; + } + + npc.PlaySound(SOUND_SUMMONSOUND, WALL_SCYTHES_VOLUME, 2, false, 1); + npc.PlaySound(SOUND_MONSTER_GRUNT_0, 1, 2, false, 1); + Room& room = *g_game->room; + Vector walls[] = {vector_make(room.topLeftPos.x, npc.pos.y), vector_make(room.bottomRightPos.x, npc.pos.y), + vector_make(npc.pos.x, room.topLeftPos.y), vector_make(npc.pos.x, room.bottomRightPos.y)}; + for (const Vector& wall : walls) + { + if (vector_length(vector_sub(npc.GetPlayerTarget()->pos, wall)) <= WALL_SCYTHE_TARGET_GAP) continue; + npc_sound_play(SOUND_MONSTER_GRUNT_0, 1, 2, champion_pitch_get(npc)); + scythe_spawn(npc, wall)->i1 = WALL_SCYTHE; + } +} + +// The hourglass: every player and the room slowed, with the Hourglass book, or the room's Hourglass for a charmed +// Death. +static void death_hourglass(Entity_NPC& npc) +{ + attack_anim_play(npc, "Attack02", SOUND_DEATH_LEAN); + if (++npc.stateFrame != HOURGLASS_FRAME) + { + if (npc.stateFrame > DEATH_HOURGLASS_FRAMES) npc.state = DEATH_WALK; + return; + } + + Room& room = *g_game->room; + if (npc.HasEntityFlags(FLAG_CHARM)) + { + if (ItemConfig_Item* hourglass = g_manager->itemConfig.GetCollectible(COLLECTIBLE_HOURGLASS)) + { + TemporaryEffect effect(hourglass); + effect.cooldown = DEATH_SLOW_DURATION; + room.temporaryEffects.AddEffect(effect, false, 1); + } + return; + } + + for (Entity_Player* player : g_game->playerManager.playerList) + player->AddSlowing(EntityRef(&npc), DEATH_SLOW_DURATION, DEATH_SLOW_AMOUNT, DEATH_SLOW_COLOR, false); + g_game->itemOverlay.Show(GIANTBOOK_HOURGLASS, HOURGLASS_BOOK_DELAY, nullptr); + room.slowdownDuration = std::max(room.slowdownDuration, DEATH_SLOW_DURATION); + npc_sound_play(SOUND_DEATH_HOURGLASS, 1, 2, 1); +} + +// Getting off: once DashStart ends Death goes on foot and his horse charges on alone. +static void death_dismount(Entity_NPC& npc) +{ + npc.sprite.Play("DashStart"); + if (!npc_anim_is_done(npc)) return; + + npc.PlaySound(SOUND_MONSTER_YELL_A, 1, 2, false, 1); + npc.PlaySound(SOUND_SUMMONSOUND, WALL_SCYTHES_VOLUME, 2, false, 1); + npc.Morph(npc.type, DEATH_ON_FOOT, npc.subtype, -1); + npc.state = NPC_STATE_INIT; + npc.sprite.Play("Appear"); + + float side = npc.sprite.isFlipX ? -HORSE_SIDE_OFFSET : HORSE_SIDE_OFFSET; + auto* horse = + static_cast(g_game->Spawn({.position = vector_make(npc.pos.x + side, npc.pos.y - HORSE_RISE), + .spawner = &npc, + .type = npc.type, + .variant = DEATH_HORSE, + .seed = Random()})); + horse->scale = npc.scale; + float size = horse->scale * horse->shrinkStatus1; + horse->sprite.scale = vector_make(size, size); + horse->parent = &npc; + horse->SetBossColorIdx(npc.bosscoloridx, 0); + horse->ClearEntityFlags(FLAG_APPEAR); + horse->sprite.isFlipX = npc.sprite.isFlipX; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + { + horse->health = DELIRIUM_HORSE_HEALTH; + horse->maxHitPoints = DELIRIUM_HORSE_HEALTH; + } + horse->entityCollisionClass = ENTCOLL_NONE; + npc_sound_play(SOUND_DEATH_HORSE_ATTACK, 1, 2, 1); +} + +// Death on his horse: his attacks above half health, then he faces his target in the room and gets off. +static void death_ride(Entity_NPC& npc, Vector toTarget) +{ + npc.friction *= DEATH_RIDE_FRICTION; + if (npc.state == NPC_STATE_INIT) + { + npc.state = DEATH_WALK; + return; + } + + if (npc.health / npc.maxHitPoints < DEATH_DISMOUNT_HEALTH) + { + Room& room = *g_game->room; + npc.pos.x = std::min(std::max(npc.pos.x, room.topLeftPos.x), room.bottomRightPos.x); + npc.sprite.isFlipX = toTarget.x < 0; + npc.state = DEATH_DISMOUNT; + death_dismount(npc); + } + else + { + switch (npc.state) + { + case DEATH_WALK: + death_walk(npc); + break; + case DEATH_SUMMON: + death_summon(npc); + break; + case DEATH_WALL_SCYTHES: + death_wall_scythes(npc); + break; + case DEATH_HOURGLASS: + death_hourglass(npc); + break; + case DEATH_DISMOUNT: + death_dismount(npc); + break; + } + } + vox_play(npc.sprite.animState.animData && npc.sprite.animState.IsEventTriggered("Vox")); +} + +// A scythe: dies without Death, hovers then flies at its target (a wall scythe waits frozen, then flies straight on), +// fleeing while scared and wandering while confused, gone when far out of the room. +static void death_scythe(Entity_NPC& npc, Vector toTarget) +{ + if (!npc.parent) npc.Kill(EntityRef()); + npc.friction *= SCYTHE_FRICTION; + if (npc.state == NPC_STATE_INIT) + { + npc.sprite.isFlipX = toTarget.x < 0; + npc.state = SCYTHE_WAIT; + npc.health = SCYTHE_HEALTH; + npc.entityCollisionClass = ENTCOLL_PLAYEROBJECTS; + npc.entityGridCollisionClass = GRIDCOLL_NONE; + npc.stateFrame = SCYTHE_HOVER_FRAMES - (int)(vector_length(toTarget) * SCYTHE_HOVER_PER_DISTANCE); + return; + } + + if (npc.state == SCYTHE_WAIT) + { + if (npc.i1 == WALL_SCYTHE) + { + npc.velocity = {}; + npc.sprite.SetFrame("Throw", 0); + if (--npc.stateFrame > 0) return; + } + else npc.stateFrame = 0; + npc.state = SCYTHE_FLY; + npc_sound_play(SOUND_DEATH_SICKLE, 1, 2, 1); + } + if (npc.state != SCYTHE_FLY) return; + + npc.stateFrame++; + npc.sprite.Play("Throw"); + if (npc.i1 != WALL_SCYTHE) npc.v1 = vector_scale(vector_normalized(toTarget), SCYTHE_HOMING); + else + { + if (npc.stateFrame > WALL_SCYTHE_FRAMES) npc.Remove(); + if (vector_is_zero(npc.v1)) npc.v1 = vector_scale(vector_normalized(toTarget), WALL_SCYTHE_SPEED); + } + + if (npc.HasEntityFlags(FLAG_CONFUSION)) npc.pathfinder.MoveRandomly(STATUS_OBEYED); + else + { + if (npc.HasEntityFlags(DEATH_SCARED)) npc.v1 = vector_scale(npc.v1, -1); + npc_push(npc, npc.v1); + } + Vector inside = g_game->room->GetClampedPositionImpl(npc.pos, 0, 0, 0, 0); + if (vector_length(vector_sub(npc.pos, inside)) > SCYTHE_ESCAPE) npc.Remove(); +} + +// The horse alone: charging across the room lap after lap, lower each time, fleeing while scared. +static void death_horse(Entity_NPC& npc) +{ + if (!npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && npc.parent) + { + Entity_NPC* rider = npc.ParentNPC(); + if (rider && rider->health < npc.health + HORSE_BLEED_GAP) npc.health -= HORSE_BLEED; + } + npc.friction *= DEATH_RIDE_FRICTION; + npc.velocity.x = npc.sprite.isFlipX ? -HORSE_SPEED : HORSE_SPEED; + if (game_is_hard_mode()) npc.velocity.x *= HARD_HORSE; + if (npc.state == NPC_STATE_INIT) + { + npc.entityCollisionClass = ENTCOLL_ALL; + npc.entityGridCollisionClass = GRIDCOLL_WALLS_Y; + npc.state = DEATH_WALK; + npc.sprite.Play("Dash"); + npc.i2 = 0; + return; + } + + if (npc.HasEntityFlags(FLAG_CONFUSION)) npc.pathfinder.MoveRandomly(STATUS_OBEYED); + if (npc.HasEntityFlags(DEATH_SCARED)) + { + Vector away = vector_sub(npc.pos, npc.GetPlayerTarget()->pos); + float push = std::clamp((HORSE_FLEE_RANGE - vector_length(away)) * HORSE_FLEE_GAIN, 0.0f, HORSE_FLEE_MAX); + npc_push(npc, vector_resized(away, push)); + } + if (npc.state != DEATH_WALK) return; + + Room& room = *g_game->room; + float left = room.topLeftPos.x - HORSE_WRAP_REACH; + float right = room.bottomRightPos.x + HORSE_WRAP_REACH; + bool isWrapped = npc.pos.x > right || npc.pos.x < left; + if (isWrapped) npc.pos.x = npc.pos.x > right ? left : right; + + Entity_Player* player = g_game->playerManager.get_first_local_main_player(); + if (player && std::abs(npc.pos.x - player->pos.x) < HORSE_WOOSH_RANGE && npc.i2 != 1) + { + npc.i2 = 1; + npc_sound_play(SOUND_DEATH_HORSE_WOOSH, 1, 2, 1); + } + if (!isWrapped) return; + + float top = room.bossId == BOSS_ID_MEGA_SATAN ? HORSEMAN_MEGA_SATAN_FLOOR : room.topLeftPos.y; + float span = room.bottomRightPos.y - top; + npc.i2 = 0; + npc.pos.y += span * HORSE_LAP_DROP; + if (npc.pos.y > room.bottomRightPos.y - HORSE_FLOOR_MARGIN) npc.pos.y -= span * HORSE_LAP_DROP * 3; +} + +// Death on foot: rising, then walking about and summoning Knights (Red Maws for the black Death). +static void death_on_foot(Entity_NPC& npc) +{ + npc.friction *= DEATH_RIDE_FRICTION; + if (npc.state == NPC_STATE_INIT) + { + npc.state = DEATH_RISE; + npc.stateFrame = 0; + return; + } + + if (npc.state == DEATH_RISE) + { + if (npc.stateFrame == 0) + { + npc.sprite.Play("Appear"); + npc.stateFrame++; + } + if (npc_anim_is_done(npc)) npc.state = DEATH_WALK; + } + + if (npc.state == DEATH_WALK) + { + npc.AnimWalkFrame("Walk", "Walk", DEATH_WALK_SPEED); + npc.pathfinder.MoveRandomlyBoss(STATUS_OBEYED); + if (Random() % SUMMON_ODDS == 0 && is_few_enemies(ON_FOOT_ENEMY_LIMIT)) + { + npc.state = DEATH_SUMMON; + npc.stateFrame = 0; + } + } + else if (npc.state == DEATH_SUMMON) + { + attack_anim_play(npc, "Attack", SOUND_DEATH_SPAWN_PREP); + if (++npc.stateFrame == FOOT_SUMMON_FRAME) + { + npc.PlaySound(SOUND_SUMMONSOUND, SUMMON_VOLUME, 2, false, 1); + npc.PlaySound(SOUND_MONSTER_GRUNT_5, 1, 2, false, 1); + Vector offset = vector_scale(random_direction(), KNIGHT_REACH); + int count = KNIGHTS; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + count = KNIGHTS - npc.CountRelatedEntities(ENTITY_MAW, RED_MAW, nullptr) - + npc.CountRelatedEntities(ENTITY_KNIGHT, 0, nullptr); + if (npc.subtype == DEATH_BLACK) pair_spawn(npc, ENTITY_MAW, RED_MAW, offset, count); + else pair_spawn(npc, ENTITY_KNIGHT, 0, offset, count); + } + else if (npc.stateFrame > FOOT_SUMMON_FRAMES) npc.state = DEATH_WALK; + } + vox_play(npc.sprite.IsEventTriggered("Vox")); +} + +// 00459d20 NpcAI::ENTITY_DEATH: Death rides about summoning scythes, throwing them from the walls and slowing time +// with his hourglass. Below half health he gets off and his horse charges across the room while he summons Knights. +void boss_death_update(Entity_NPC& npc) +{ + Vector toTarget = vector_sub(npc.GetPlayerTarget()->pos, npc.pos); + if (npc.state == NPC_STATE_INIT) + { + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + npc.splatColor = DEATH_SPLAT_COLOR; + } + + bool isInit = npc.state == NPC_STATE_INIT; + switch (npc.variant) + { + case 0: + death_ride(npc, toTarget); + break; + case DEATH_SCYTHE: + death_scythe(npc, toTarget); + break; + case DEATH_HORSE: + death_horse(npc); + break; + case DEATH_ON_FOOT: + death_on_foot(npc); + break; + } + if (isInit) return; + horseman_mega_satan_hold(npc); +} diff --git a/src/boss_delirium.cpp b/src/boss_delirium.cpp new file mode 100644 index 0000000..18b0965 --- /dev/null +++ b/src/boss_delirium.cpp @@ -0,0 +1,1168 @@ +#include "boss_ai.h" +#include "camera.h" +#include "entity_config.h" +#include "entity_player.h" +#include "entity_projectile.h" +#include "manager.h" +#include "platform.h" +#include +#include +#include +#include +#include + +// Delirium's own phases (deliriumState): starting, in a form, about to change form, the hallucinations of his death and +// his last scream. +enum DeliriumState : uint8_t +{ + DELIRIUM_START = 0, + DELIRIUM_FORM = 8, + DELIRIUM_MORPH = 16, + DELIRIUM_DYING = 17, + DELIRIUM_SCREAM = 18 +}; + +// A form lasts a random whole number of seconds between a least and a most, by the fifth of his health he has left. +struct FormSeconds +{ + float least; + float most; +}; +constexpr std::array FORM_SECONDS = {{{1, 3}, {2, 5}, {3, 6}, {4, 7}, {5, 8}, {6, 10}}}; +constexpr float HEALTH_FIFTHS = 5; +constexpr float RANDOM_RANGE = 4294967295.0f; +constexpr int SECOND_FRAMES = 30; + +// Each form makes 2 to 4 attacks. He starts behind a 120 frame shield, and his shield grows to 80 as he weakens. +constexpr uint32_t NPC_STATE_ATTACKS_MIN = 2; +constexpr uint32_t NPC_STATE_ATTACKS_ROLL = 3; +constexpr int START_SHIELD_FRAMES = 120; +constexpr float SHIELD_STRENGTH = 80; + +// He changes into his own form 10 rolls in 100, else into a boss met this run, drawing up to 100 times for one that is +// not himself, Hornfel or Gideon, not tagged nodelirium and not the form he leaves. Mom takes her variant 10, Satan +// his variant 10 one roll in 2, and Mama Gurdy her variant 0. +constexpr uint32_t FORM_ROLL = 100; +constexpr uint32_t OWN_FORM_ODDS = 10; +constexpr int FORM_DRAWS = 100; +constexpr uint32_t ALTERNATE_FORM_VARIANT = 10; + +// Each change adds 10 to the odds of a rage, which lasts 120 frames, tints him and runs his form at full speed. +constexpr uint32_t RAGE_ODDS_STEP = 10; +constexpr uint32_t DELIRIUM_RAGE_FRAMES = 120; +constexpr float RAGE_TINT = 0.7f; +constexpr uint32_t RAGE_STEPS = 3; + +// He teleports every 300 to 899 frames, at most 30 frames after he leaves the camera's sight (checked 100 out from him +// at each corner), the damage he takes cutting it by half. He lands 160 to 320 out from his target along its way (any +// way while it stands still), at least 160 from every player: up to 20 more tries go round his target 90 degrees at a +// time, 40 further out each, from 320. Bosses that stay in place never teleport. +constexpr uint32_t TELEPORT_FRAMES_MIN = 300; +constexpr uint32_t TELEPORT_FRAMES_ROLL = 600; +constexpr uint32_t TELEPORT_HIDDEN_FRAMES = 30; +constexpr float CAMERA_CORNER = 100; +constexpr float TELEPORT_DAMAGE_SHARE = 0.5f; +constexpr float DELIRIUM_TELEPORT_REACH = 160; +constexpr float TELEPORT_RING = 320; +constexpr float DELIRIUM_RING_STEP = DELIRIUM_TELEPORT_REACH * 0.25f; +constexpr int DELIRIUM_TELEPORT_TRIES = 20; +constexpr int TELEPORT_QUARTERS = 4; +constexpr float TELEPORT_QUARTER_DEGREES = 90; +constexpr std::array STILL_BOSSES = {ENTITY_GURDY, ENTITY_MOM, ENTITY_MOMS_HEART, ENTITY_ISAAC, + ENTITY_MEGA_MAW, ENTITY_GATE, ENTITY_MAMA_GURDY, ENTITY_MR_FRED, + ENTITY_THE_LAMB, ENTITY_MATRIARCH}; + +// A form's attacks count down on the frame after it starts one of these states. +constexpr std::array ATTACK_STATES = {NPC_STATE_JUMP, NPC_STATE_STOMP, NPC_STATE_SPECIAL, NPC_STATE_ATTACK, + NPC_STATE_ATTACK2, NPC_STATE_ATTACK3, NPC_STATE_ATTACK4, NPC_STATE_SUMMON, + NPC_STATE_SUMMON2, NPC_STATE_SUMMON3}; + +// His death: five hallucinations, 0.4 seconds per one left (the last one of backdrop 17, the others random), then ten +// double speed loops of "IdleNoLoop" over a deep gurgle and his scream. +constexpr int DEATH_HALLUCINATIONS = 5; +constexpr float HALLUCINATION_SECONDS = 0.4f; +constexpr int HALLUCINATION_RANDOM = 63; +constexpr int HALLUCINATION_LAST = 17; +constexpr int SCREAM_LOOPS = 10; +constexpr float GURGLE_VOLUME = 5; +constexpr float GURGLE_PITCH = 0.1f; +constexpr int DELIRIUM_SOUND_DELAY = 2; +constexpr int MOM_VOICE_DELAY = 45; + +// The speed a form runs at: its extra steps (3 less 3 per health share, all 3 while raging), each moving it on by a +// share of its velocity and calling its AI again while the steps allow. A form calls nothing for its first 4 frames a +// step, and the attacks it may start are forced one roll in (3 less its extra steps), or 10 to that power for the +// horsemen (a quarter more for Death, five times for his variant 30). +constexpr float FULL_STEPS = 3; +constexpr uint32_t STEP_FRAMES = 4; +constexpr int YOUNG_FORM_FRAMES = 30; +constexpr int MOM_FORM_FRAMES = 60; +constexpr double FORCED_ODDS_BASE = 10; +constexpr double DEATH_ODDS_POWER = 0.5; +constexpr double DEATH_30_ODDS_POWER = 2.5; +constexpr int DEATH_RUSH_VARIANT = 30; + +// Larry Jr.'s body: 4 to 9 segments, 20 apart (with up to 5 jitter) back from his target, turned up to 45 degrees. +constexpr uint32_t LARRY_SEGMENTS_MIN = 4; +constexpr uint32_t LARRY_SEGMENTS_ROLL = 6; +constexpr float LARRY_SEGMENT_GAP = 20; +constexpr uint32_t LARRY_TURN_ROLL = 90; +constexpr int LARRY_TURN_MAX = 45; +constexpr uint32_t LARRY_JITTER_ROLL = 5000; +constexpr float LARRY_JITTER_SCALE = 1000; +constexpr int GEMINI_UMBILICAL = 20; +constexpr int PLAYER_SPAWNER = 1; + +// The bosses a form may bring a companion of the other, as pairs with the odds in 100 of either bringing the other. +struct FormPair +{ + int type; + int variant; + int otherType; + int otherVariant; + uint32_t odds; +}; +constexpr std::array FORM_PAIRS = {{ + {19, 0, 19, 1, 20}, {267, 0, 268, 0, 8}, {20, 0, 43, 0, 5}, {43, 0, 43, 1, 8}, {28, 0, 28, 1, 10}, + {36, 0, 237, 1, 8}, {36, 0, 237, 2, 8}, {99, 0, 237, 1, 5}, {99, 0, 237, 2, 5}, {402, 0, 237, 2, 8}, + {402, 0, 261, 1, 15}, {62, 0, 62, 1, 3}, {62, 0, 62, 2, 3}, {67, 0, 67, 1, 15}, {79, 0, 79, 1, 18}, + {79, 0, 79, 2, 10}, {71, 0, 71, 1, 10}, {68, 0, 68, 1, 4}, {263, 0, 265, 0, 8}, {69, 0, 69, 1, 5}, + {100, 0, 100, 1, 12}, {271, 0, 272, 0, 6}, {261, 0, 261, 1, 12}, {404, 0, 411, 0, 4}, {405, 0, 409, 0, 4}, + {74, 0, 74, 0, 18}, {63, 0, 64, 0, 10}, {65, 0, 65, 1, 6}, {63, 0, 82, 0, 10}, {65, 0, 66, 0, 8}, + {64, 0, 66, 0, 6}, {65, 1, 82, 0, 10}, +}}; + +// His shots: 11 patterns, each a burst of shots every interval (a quarter as often in a boss form) for some volleys, +// then he keeps it at the keep odds (10 less each time) or draws another with odds 30 and a new turn. +constexpr int SHOT_PATTERNS = 11; +constexpr uint8_t RANDOM_PATTERN = 0xff; +constexpr uint32_t KEEP_ROLL = 100; +constexpr uint8_t KEEP_ODDS_STEP = 10; +constexpr uint8_t KEEP_ODDS_FRESH = 30; +constexpr uint32_t TURN_STEPS = 255; +constexpr int FORM_SHOT_SLOWDOWN = 4; +constexpr int BURST_DELAY = 5; +constexpr int BURST_SLOTS = 16; +constexpr float SHOT_HEIGHT = 5; +constexpr float DELIRIUM_SHOT_FALL_SPEED = -3.2f; +constexpr float DELIRIUM_SHOT_FALL_ACCEL = -0.06f; +constexpr float DELIRIUM_SHOT_SCALE = 1.5f; +constexpr float AIMED_SHOT_SPEED = 4; + +// A shot pattern: its interval, ring size, burst, volleys, speed, colorize and flags, whether alternate volleys curve +// the other way in another color, how far each volley turns him, and whether it is an aimed fan instead of a ring. +struct ShotPattern +{ + std::array colorize; + std::array alternateColorize; + uint64_t flags; + float speed; + int interval; + int ringSize; + int burst; + uint8_t volleys; + uint8_t turn; + bool isAlternating; + bool isAimed; +}; + +// The health share a form's speed reads, from 0 dead to 1 full. +static float health_share_get(Entity_NPC& npc) +{ + return std::clamp(npc.health / npc.maxHitPoints, 0.0f, 1.0f); +} + +// A whole random number of seconds between a range's ends, in frames. +static uint16_t form_frames_roll(FormSeconds seconds) +{ + float roll = (float)(Random() % UINT32_MAX); + return (uint16_t)((int)(roll / (RANDOM_RANGE / (seconds.most - seconds.least)) + seconds.least) * SECOND_FRAMES); +} + +// Whether an entity is a boss form's: the same type and variant. +static bool is_form(Entity& entity, int type, int variant) +{ + return entity.type == type && entity.variant == variant; +} + +// 004a6240 Removes what a form left behind: other bosses of its kind, its companion's kind, Gemini's cord, Hush's +// rising lasers, every laser not a player's and the Eternal Flies. +static void delirium_minions_remove(int type, int variant, Entity& self, Entity* companion) +{ + std::vector& updated = g_game->room->entityList.updateEL; + + for (size_t i = 0; i < updated.size(); i++) + { + Entity& entity = *updated[i]; + bool isFormBoss = &entity != &self && entity.IsBoss() && is_form(entity, type, variant); + bool isCompanionKind = companion && is_form(entity, companion->type, companion->variant); + if (isFormBoss || isCompanionKind) entity.Remove(); + } + + if (type == ENTITY_GEMINI) + for (Entity* cord : entity_query(ENTITY_GEMINI, GEMINI_UMBILICAL)) cord->Remove(); + else if (type == ENTITY_HUSH) + for (Entity* laser : entity_query(ENTITY_EFFECT, EFFECT_HUSH_LASER_UP)) laser->Remove(); + for (Entity* laser : entity_query(ENTITY_LASER, -1)) + if (laser->spawnerType != PLAYER_SPAWNER) laser->Remove(); + for (Entity* fly : entity_query(ENTITY_ETERNALFLY, 0)) fly->Remove(); +} + +// 004a8680 Grows a form's body: Larry Jr.'s segments trailing back from his target (the first one with the form's +// health) or Mama Gurdy's two hands. +static void delirium_segments_spawn(Entity_NPC& head, float maxHealth) +{ + if (head.type == ENTITY_MAMA_GURDY) + { + spawn_at(head.type, 1, 0, head.pos, &head); + spawn_at(head.type, 2, 0, head.pos, &head); + return; + } + if (head.type != ENTITY_LARRYJR) return; + + int count = (int)(Random() % LARRY_SEGMENTS_ROLL + LARRY_SEGMENTS_MIN); + Vector away = vector_sub(head.pos, head.GetPlayerTarget()->pos); + float length = std::sqrt(away.x * away.x + away.y * away.y); + if (length > 0) away = vector_scale(away, 1 / length); + float turn = (float)((int)(Random() % LARRY_TURN_ROLL) - LARRY_TURN_MAX) * DEGREES_TO_RADIANS; + Vector direction = vector_make(away.x * std::cos(turn) - away.y * std::sin(turn), + away.x * std::sin(turn) + away.y * std::cos(turn)); + Entity_NPC* previous = &head; + + for (int i = 1; i <= count; i++) + { + Vector position = vector_add(head.pos, vector_scale(direction, (float)i * LARRY_SEGMENT_GAP)); + position.y += (float)(Random() % LARRY_JITTER_ROLL) / LARRY_JITTER_SCALE; + position.x += (float)(Random() % LARRY_JITTER_ROLL) / LARRY_JITTER_SCALE; + auto* segment = static_cast(spawn_at(head.type, head.variant, 0, position, &head)); + + if (i == 1) + { + segment->health = maxHealth; + segment->maxHitPoints = maxHealth; + segment->isInvincible = true; + } + segment->parent = previous; + previous->child = segment; + segment->ClearEntityFlags(FLAG_APPEAR); + segment->AddEntityFlags(FLAG_NO_DEATH_TRIGGER | FLAG_DONT_COUNT_BOSS_HP); + segment->state = NPC_STATE_MOVE; + segment->vectorDeque1.push_front(segment->pos); + segment->vectorDeque2.push_front(segment->velocity); + segment->groupIdx = head.groupIdx; + ANM2::LoadDeliriumForm(segment->sprite, head.type, head.variant, true); + segment->sprite.Play("WalkBodyHori"); + segment->Update(); + previous = segment; + } +} + +// 004a84f0 Brings a companion for a form one roll in its pair's odds, somewhere in the room with the form's health: +// the other boss of a pair it belongs to (looked up from either end of the list), taking the form's variant. +static void delirium_companion_spawn(Entity_NPC& npc) +{ + bool isFromEnd = Random() & 1; + const FormPair* found = nullptr; + int otherType = 0; + + for (int i = 0; i < (int)FORM_PAIRS.size() && !found; i++) + { + const FormPair& pair = FORM_PAIRS[isFromEnd ? FORM_PAIRS.size() - 1 - i : i]; + if (is_form(npc, pair.type, pair.variant)) otherType = pair.otherType; + else if (is_form(npc, pair.otherType, pair.otherVariant)) otherType = pair.type; + else continue; + found = &pair; + } + if (!found || Random() % FORM_ROLL >= found->odds) return; + + uint32_t seed = Random(); + auto* companion = static_cast(g_game->Spawn({.position = g_game->room->GetRandomPosition(0), + .spawner = &npc, + .type = otherType, + .variant = npc.variant, + .seed = seed})); + companion->health = npc.maxHitPoints; + companion->AddEntityFlags(FLAG_NO_DEATH_TRIGGER | FLAG_DONT_COUNT_BOSS_HP); + companion->maxHitPoints = npc.maxHitPoints; + ANM2::LoadDeliriumForm(companion->sprite, otherType, npc.variant, true); + delirium_segments_spawn(*companion, npc.maxHitPoints); + npc.deliriumEntity = companion; + companion->Update(); + log_printf(LOG_INFO, "Spawned Delirium companion %d:%u\n", otherType, (uint32_t)npc.variant); +} + +// A shot pattern's settings, by its number. +static ShotPattern shot_pattern_get(int pattern) +{ + switch (pattern) + { + case 0: + return {{2, 2, 2}, {3, 3, 3}, PROJECTILE_ACCELERATE, 2.5f, 18, 20, 1, 2, 0, true, false}; + case 1: + return {{2, 2.8f, 2}, {1, 1, 1}, PROJECTILE_EXPLODE, 4, 25, 8, 1, 1, 0, false, false}; + case 2: + return {{2.6f, 2.6f, 2.6f}, {1, 1, 1}, PROJECTILE_SAWTOOTH_WIGGLE, 4.5f, 5, 6, 1, 1, 0, false, false}; + case 3: + return {{3.4f, 3.4f, 3.4f}, {1, 1, 1}, 0, 4, 25, 1, 12, 3, 0, false, false}; + case 4: + return {{2.4f, 2.4f, 2.4f}, {1, 1, 1}, PROJECTILE_WIGGLE, 5, 20, 20, 1, 4, 3, false, false}; + case 5: + return {{3.6f, 3.6f, 3.6f}, {2.2f, 2.2f, 2.2f}, PROJECTILE_MEGA_WIGGLE, 3, 20, 10, 1, 2, 2, true, false}; + case 6: + return {{3.8f, 3.8f, 3.8f}, {1, 1, 1}, PROJECTILE_ORBIT_CW, 5, 25, 14, 1, 2, 0, false, false}; + case 7: + return {{4, 4, 4}, {1, 1, 1}, PROJECTILE_ORBIT_CCW, 5, 25, 14, 1, 2, 0, false, false}; + case 8: + return {{2.6f, 2.6f, 2.6f}, {1, 1, 1}, PROJECTILE_SINE_VELOCITY, 4, 10, 10, 1, 3, 4, false, false}; + case 9: + return {{2.6f, 2.6f, 2.6f}, {1, 1, 1}, 0, 4, 30, 14, 4, 1, 2, false, false}; + case 10: + return {{3.6f, 3.6f, 3.6f}, {1, 1, 1}, 0, AIMED_SHOT_SPEED, 18, 6, 1, 4, 0, false, true}; + default: + return {{1, 0.4f, 0}, {1, 1, 1}, 0, 3, 10, 6, 4, 1, 0, false, false}; + } +} + +// The burst a pattern fires in, each shot with its frame delay and angle: half turns 5 frames apart, a single shot at +// an eighth of a half turn for pattern 2, or pattern 3's four triple bursts, a third of a half turn apart. +static void burst_fill(int pattern, std::array& delays, std::array& angles) +{ + for (int i = 0; i < BURST_SLOTS; i++) + { + delays[i] = i * BURST_DELAY; + angles[i] = (float)i * PI_F; + } + if (pattern == 2) + { + delays[0] = 0; + angles[0] = PI_F / 8; + } + if (pattern != 3) return; + + for (int i = 0; i < 3; i++) + { + float angle = (float)i * (PI_F / 3); + for (int quarter = 0; quarter < 4; quarter++) delays[i + quarter * 3] = i * 10; + angles[i] = angle; + angles[i + 3] = angle + PI_F; + angles[i + 6] = angle + PI_F / 2; + angles[i + 9] = angle + PI_F + PI_F / 2; + } +} + +// 004a8b70 Fires Delirium's shots (not Mom's or Satan's variant 10 forms): the burst of the pattern on the frames it +// fires, blinking in his own form. A pattern's volleys spent, he keeps it or draws a new one and a new turn. +static void delirium_shots_fire(Entity_NPC& npc) +{ + if (npc.type == ENTITY_MOM) return; + if (npc.deliriumBossType == ENTITY_SATAN && npc.deliriumBossVariant == ALTERNATE_FORM_VARIANT) return; + + int pattern = npc.deliriumAttackPattern; + uint8_t keepOdds = npc.deliriumAttackKeepChance; + uint32_t turn = npc.deliriumAttackAngle; + if (pattern == RANDOM_PATTERN) pattern = (int)(Random() % SHOT_PATTERNS); + + ShotPattern shots = shot_pattern_get(pattern); + Vector velocity = vector_make(shots.speed, 0); + ProjectilesMode mode = PROJECTILES_RING; + int volleys = npc.deliriumAttackRepeats == RANDOM_PATTERN ? shots.volleys : npc.deliriumAttackRepeats; + std::array delays; + std::array angles; + + burst_fill(pattern, delays, angles); + turn += shots.turn; + if (shots.isAimed) + { + velocity = vector_scale(vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos)), shots.speed); + mode = PROJECTILES_FIVE; + } + + int period = (npc.type == ENTITY_DELIRIUM ? 1 : FORM_SHOT_SLOWDOWN) * shots.interval; + float turnAngle = ((float)(int)turn / (float)TURN_STEPS) * PI_F * 2; + bool isFired = false; + for (int i = 0; i < shots.burst; i++) + { + int frame = npc.deliriumAttackFrame - delays[i]; + if (frame % period != 0) continue; + + ProjectileParams params; + params.heightModifier = SHOT_HEIGHT; + params.scale = (float)(Random() % UINT32_MAX) * RANDOM_UNIT_SCALE + DELIRIUM_SHOT_SCALE; + params.fallingAccelModifier = DELIRIUM_SHOT_FALL_ACCEL; + params.fallingSpeedModifier = DELIRIUM_SHOT_FALL_SPEED; + params.bulletFlags |= shots.flags; + params.color = {{1, 1, 1, 1}, {shots.colorize[0], shots.colorize[1], shots.colorize[2], 1}, {0, 0, 0}}; + params.targetPosition = npc.pos; + params.circleAngle = turnAngle + angles[i]; + if (shots.isAlternating && ((frame / period) & 1) == 0) + { + params.bulletFlags |= PROJECTILE_CURVE_RIGHT; + const std::array& tint = shots.alternateColorize; + params.color = {{1, 1, 1, 1}, {tint[0], tint[1], tint[2], 1}, {0, 0, 0}}; + } + else if (shots.isAlternating) params.bulletFlags |= PROJECTILE_CURVE_LEFT; + if (mode == PROJECTILES_RING) velocity.y = (float)shots.ringSize; + npc.FireProjectiles(npc.pos, velocity, mode, params); + isFired = true; + } + + if (isFired) + { + if (npc.type == ENTITY_DELIRIUM) npc.sprite.Play("Blink"); + if (--volleys < 1) + { + if (Random() % KEEP_ROLL < keepOdds) keepOdds -= KEEP_ODDS_STEP; + else + { + uint32_t roll; + do roll = Random(); + while ((int)(roll % SHOT_PATTERNS) == pattern); + keepOdds = KEEP_ODDS_FRESH; + turn = Random() % TURN_STEPS; + pattern = (int)(roll % SHOT_PATTERNS); + } + volleys = RANDOM_PATTERN; + } + } + npc.deliriumAttackAngle = (uint8_t)turn; + npc.deliriumAttackFrame++; + npc.deliriumAttackKeepChance = keepOdds; + npc.deliriumAttackRepeats = (uint8_t)volleys; + npc.deliriumAttackPattern = (uint8_t)pattern; +} + +// How fast a form runs this frame: the extra steps it takes, how many of them step its animations and call its AI, +// and the share of its velocity each extra step moves it by. +struct FormSpeed +{ + Vector stepVelocity{}; + uint32_t aiCalls = 0; + uint32_t animSteps = 0; + uint32_t steps = 0; +}; + +// Sets a form's steps (and with them its AI calls and animation steps) to a count of its own. +static void form_steps_set(FormSpeed& speed, float steps) +{ + speed.steps = (uint32_t)steps; + speed.animSteps = speed.steps; + speed.aiCalls = speed.steps + 1; +} + +// Scales the extra steps' velocity by a factor and the steps' share of a full speed. +static void form_velocity_scale(FormSpeed& speed, float factor) +{ + float share = (float)speed.steps / FULL_STEPS; + speed.stepVelocity = vector_make(speed.stepVelocity.x * factor * share, speed.stepVelocity.y * factor * share); +} + +// The speed each boss runs at as a form, some bosses holding or cutting short their attacks while the form is young. +static FormSpeed form_speed_get(Entity_NPC& npc, float health) +{ + uint32_t aggression = (uint32_t)(FULL_STEPS - health * FULL_STEPS); + uint32_t age = npc.deliriumFormAge; + FormSpeed speed = {npc.velocity, aggression + 1, aggression, npc.deliriumRageTimer ? RAGE_STEPS : aggression}; + uint32_t odds = (uint32_t)FULL_STEPS - aggression; + bool isAttacking = npc.state == NPC_STATE_ATTACK2 || npc.state == NPC_STATE_ATTACK3; + + switch (npc.type) + { + case ENTITY_FORSAKEN: + case ENTITY_LOKI: + form_velocity_scale(speed, 1); + break; + case ENTITY_LARRYJR: + case ENTITY_CHUB: + case ENTITY_MASK_OF_INFAMY: + case ENTITY_GURDY_JR: + case ENTITY_WIDOW: + case ENTITY_GURGLING: + case ENTITY_DARK_ONE: + form_velocity_scale(speed, 0.20000005f); + break; + case ENTITY_MONSTRO: + case ENTITY_HEADLESS_HORSEMAN: + case ENTITY_RAG_MAN: + form_velocity_scale(speed, 0.39999998f); + break; + case ENTITY_GURDY: + case ENTITY_MONSTRO2: + case ENTITY_MOMS_HEART: + case ENTITY_MEGA_MAW: + if (age < YOUNG_FORM_FRAMES && npc.state == NPC_STATE_ATTACK) npc.state = NPC_STATE_IDLE; + if (age < YOUNG_FORM_FRAMES || npc.state == NPC_STATE_ATTACK) form_steps_set(speed, 1); + form_velocity_scale(speed, 0.39999998f); + break; + case ENTITY_MOM: + if (age > MOM_FORM_FRAMES && random_below((int)odds) == 0) npc.projectileCooldown = 0; + form_steps_set(speed, 0); + break; + case ENTITY_PIN: + form_velocity_scale(speed, (npc.variant == 0 ? 1.2f : 2.0f) - 1); + break; + case ENTITY_FAMINE: + form_velocity_scale(speed, 1.5f); + break; + case ENTITY_WAR: + if (npc.variant == ALTERNATE_FORM_VARIANT) form_velocity_scale(speed, 0); + else form_velocity_scale(speed, npc.variant == 1 ? 0.39999998f : 1.5f); + break; + case ENTITY_DUKE: + if (npc.variant == 1) form_velocity_scale(speed, 0.39999998f); + break; + case ENTITY_PEEP: + if (npc.variant != 1) break; + if (age < YOUNG_FORM_FRAMES && isAttacking) npc.state = NPC_STATE_IDLE; + if (age < YOUNG_FORM_FRAMES || isAttacking) form_steps_set(speed, 1); + break; + case ENTITY_FALLEN: + npc.maxHitPoints = npc.health; + form_velocity_scale(speed, 0.6f); + break; + case ENTITY_BLASTOCYST_BIG: + form_velocity_scale(speed, 0.6f); + break; + case ENTITY_GEMINI: + form_velocity_scale(speed, (npc.variant == 2 ? 1.1f : 1.2f) - 1); + break; + case ENTITY_SATAN: + if (npc.variant == ALTERNATE_FORM_VARIANT) + { + if (random_below((int)odds) == 0) npc.stateFrame = 0; + form_velocity_scale(speed, 0.20000005f); + form_steps_set(speed, 0); + break; + } + form_velocity_scale(speed, 0); + form_steps_set(speed, FULL_STEPS - health * FULL_STEPS); + break; + case ENTITY_DADDYLONGLEGS: + speed.animSteps = 0; + break; + case ENTITY_ISAAC: + form_steps_set(speed, 2 - (health + health)); + form_velocity_scale(speed, 0.6f); + break; + case ENTITY_DINGLE: + speed.aiCalls = 2; + form_velocity_scale(speed, 0.20000005f); + break; + case ENTITY_GATE: + npc.pos = npc.targetPosition; + form_velocity_scale(speed, -1); + break; + case ENTITY_CAGE: + if (npc.state == NPC_STATE_JUMP) form_steps_set(speed, 1 - health); + break; + case ENTITY_HUSH: + form_steps_set(speed, 1 - health); + break; + case ENTITY_ADVERSARY: + form_velocity_scale(speed, 0.20000005f); + form_steps_set(speed, npc.state == NPC_STATE_ATTACK ? 1 - health : 2 - (health + health)); + break; + case ENTITY_URIEL: + case ENTITY_GABRIEL: + case ENTITY_THE_LAMB: + speed.aiCalls = 1; + form_velocity_scale(speed, 0.20000005f); + break; + case ENTITY_LITTLE_HORN: + form_velocity_scale(speed, 1); + form_steps_set(speed, 2 - (health + health)); + break; + case ENTITY_SISTERS_VIS: + form_velocity_scale(speed, 0.6f); + form_steps_set(speed, 2 - (health + health)); + break; + default: + break; + } + return speed; +} + +// Whether a forced attack passes its odds: always at none, else one roll in them. +static bool is_forced(uint32_t odds) +{ + return odds == 0 || Random() % odds == 0; +} + +// The horsemen's forced attack odds: 10 to the power of the form's odds scaled. +static uint32_t horseman_odds_get(uint32_t odds, double power) +{ + return (uint32_t)(int)std::pow(FORCED_ODDS_BASE, (double)odds * power); +} + +// Forces an attack a form would wait for: Monstro and Monstro II taunt or jump, Chub charges, the horsemen strike. +static void form_attack_force(Entity_NPC& npc, uint32_t odds) +{ + const char* anim = nullptr; + + switch (npc.type) + { + case ENTITY_MONSTRO: + case ENTITY_MONSTRO2: + if (npc.state != NPC_STATE_IDLE || !is_forced(odds)) return; + if (Random() & 1) + { + npc.state = NPC_STATE_JUMP; + npc_sound_play(SOUND_BOSS_LITE_ROAR, 1, DELIRIUM_SOUND_DELAY, champion_pitch_get(npc)); + anim = "JumpUp"; + } + else + { + npc.state = NPC_STATE_ATTACK; + anim = "Taunt"; + } + break; + case ENTITY_CHUB: + if (npc.variant == 0 && npc.state == NPC_STATE_MOVE && is_forced(odds) && npc.stateFrame == 0) + npc.state = NPC_STATE_SUMMON; + return; + case ENTITY_PESTILENCE: + if (npc.state != NPC_STATE_MOVE || !is_forced(horseman_odds_get(odds, 1))) return; + npc.stateFrame = 0; + if (Random() & 1) + { + npc.state = NPC_STATE_ATTACK; + anim = npc.i1 ? "HeadlessAttack1" : "Attack1"; + } + else + { + npc.state = NPC_STATE_SUMMON; + anim = npc.i1 ? "HeadlessAttack2" : "Attack2"; + } + break; + case ENTITY_WAR: + if (npc.state != NPC_STATE_MOVE || npc.variant == ALTERNATE_FORM_VARIANT) return; + if (!is_forced(horseman_odds_get(odds, 1))) return; + if (Random() & 1) + { + int roar = SOUND_MONSTER_ROAR_0 + (int)(Random() & 3); + npc_sound_play(roar, 1, DELIRIUM_SOUND_DELAY, champion_pitch_get(npc)); + npc.state = NPC_STATE_JUMP; + anim = "Attack2"; + } + else + { + npc.state = NPC_STATE_ATTACK; + anim = "Attack1"; + } + npc.stateFrame = 0; + break; + case ENTITY_DEATH: + { + double power = npc.variant == DEATH_RUSH_VARIANT ? DEATH_30_ODDS_POWER : DEATH_ODDS_POWER; + if (npc.state != NPC_STATE_MOVE || npc.variant == ALTERNATE_FORM_VARIANT) return; + if (!is_forced(horseman_odds_get(odds, power))) return; + + uint32_t pick = npc.variant == DEATH_RUSH_VARIANT ? 0 : Random() % 3; + if (pick == 0) npc.state = NPC_STATE_SUMMON; + else if (pick == 1) npc.state = NPC_STATE_ATTACK; + else npc.state = NPC_STATE_SUMMON2; + npc.stateFrame = 0; + return; + } + case ENTITY_BLASTOCYST_BIG: + if (npc.state == NPC_STATE_SPECIAL) npc.state = NPC_STATE_IDLE; + return; + default: + return; + } + if (anim) npc.sprite.Play(anim, PLAY_FORCED); +} + +// 004a9860 Runs a form's AI at its speed: past its first frames, the steps force its attacks, move it on, step its +// animations and call its AI, counting the rage down. Before that only its animations play. +static void delirium_form_update(Entity_NPC& npc) +{ + if (npc.health == 0) return; + + float health = health_share_get(npc); + uint32_t rage = npc.deliriumRageTimer; + FormSpeed speed = form_speed_get(npc, health); + uint32_t odds = (uint32_t)FULL_STEPS - (uint32_t)(FULL_STEPS - health * FULL_STEPS); + + if (speed.steps * STEP_FRAMES >= npc.deliriumFormAge) return npc.sprite.Update(); + + for (uint32_t step = 0; step <= speed.steps; step++) + { + form_attack_force(npc, odds); + if (step != 0) + { + if (step <= speed.animSteps) npc.sprite.Update(); + npc.pos = vector_add(npc.pos, speed.stepVelocity); + } + if (step < speed.aiCalls) npc_ai_update(npc); + } + npc.deliriumRageTimer = rage ? rage - 1 : 0; +} + +// Whether any corner 100 out from him shows on the camera. +static bool is_seen(Entity_NPC& npc) +{ + Camera& camera = *g_game->room->camera; + + for (float x : {-CAMERA_CORNER, CAMERA_CORNER}) + for (float y : {-CAMERA_CORNER, CAMERA_CORNER}) + if (camera.IsPosVisible(vector_make(npc.pos.x + x, npc.pos.y + y))) return true; + return false; +} + +// Whether a spot lies 160 or more from every player. +static bool is_clear_of_players(Vector spot) +{ + for (Entity_Player* player : g_game->playerManager.playerList) + if (vector_length_squared(vector_sub(player->pos, spot)) < DELIRIUM_TELEPORT_REACH * DELIRIUM_TELEPORT_REACH) return false; + return true; +} + +// Teleports him ahead of his target, away from the players, his shots and form clock starting over. Without a clear +// spot he stays. Either way the next teleport is 300 to 899 frames off. +static void delirium_teleport(Entity_NPC& npc) +{ + Room& room = *g_game->room; + float reach = random_unit() * DELIRIUM_TELEPORT_REACH + DELIRIUM_TELEPORT_REACH; + Entity* target = npc.GetPlayerTarget(); + Vector way = vector_is_zero(target->velocity) ? random_direction() : vector_normalized(target->velocity); + Vector spot = room.GetClampedPositionImpl(vector_add(target->pos, vector_scale(way, reach)), DELIRIUM_TELEPORT_REACH, + DELIRIUM_TELEPORT_REACH, DELIRIUM_TELEPORT_REACH, DELIRIUM_TELEPORT_REACH); + float start = random_unit() * 360; + int tries = 0; + + while (!is_clear_of_players(spot)) + { + if (tries >= DELIRIUM_TELEPORT_TRIES) + { + log_printf(LOG_INFO, "??? teleport: %d tries\n", tries); + npc.deliriumFormAge = npc.deliriumFormAge + 1; + npc.deliriumTeleportTimer = Random() % TELEPORT_FRAMES_ROLL + TELEPORT_FRAMES_MIN; + return; + } + float ring = (float)tries * DELIRIUM_RING_STEP + TELEPORT_RING; + float angle = ((float)(tries % TELEPORT_QUARTERS) * TELEPORT_QUARTER_DEGREES + start) * DEGREES_TO_RADIANS; + Vector around = npc.GetPlayerTarget()->pos; + spot = room.GetClampedPositionImpl( + vector_make(std::cos(angle) * ring + around.x, std::sin(angle) * ring + around.y), DELIRIUM_TELEPORT_REACH, + DELIRIUM_TELEPORT_REACH, DELIRIUM_TELEPORT_REACH, DELIRIUM_TELEPORT_REACH); + tries++; + } + + log_printf(LOG_INFO, "??? teleport: %d tries\n", tries); + npc.pos = spot; + npc_sound_play(SOUND_HELL_PORTAL1, 1, DELIRIUM_SOUND_DELAY, champion_pitch_get(npc)); + npc.deliriumAttackFrame = 0; + npc.deliriumAttackAngle = 0; + npc.deliriumFormAge = 0; + npc.deliriumTeleportTimer = Random() % TELEPORT_FRAMES_ROLL + TELEPORT_FRAMES_MIN; +} + +// Big Horn's hands stay in Delirium's colors when his form comes out of the ground. +static void big_horn_hands_dress() +{ + std::vector& updated = g_game->room->entityList.updateEL; + + for (size_t i = 0; i < updated.size(); i++) + if (is_form(*updated[i], ENTITY_BIG_HORN, 1)) ANM2::LoadDeliriumForm(updated[i]->sprite, ENTITY_BIG_HORN, 1, false); +} + +// Dresses what a form brought out this frame: the parts of the next phase, War's riders and the other legs of +// Daddy Long Legs (made invincible), as they start. +static void form_spawns_dress(Entity_NPC& npc, int previousI1) +{ + if (previousI1 < npc.i1) + for (Entity* part : entity_query(npc.type, npc.variant + (int)ALTERNATE_FORM_VARIANT)) + { + ANM2::LoadDeliriumForm(npc.sprite, npc.type, npc.variant, false); + ANM2::LoadDeliriumForm(part->sprite, npc.type, npc.variant + (int)ALTERNATE_FORM_VARIANT, true); + } + + if (npc.type == ENTITY_WAR) + { + if (npc.variant == 1 && npc.IsFrame(8, 0) && npc.state == NPC_STATE_ATTACK2 && npc.stateFrame == 2 && + npc.spawnerType != ENTITY_WAR) + for (Entity* rider : entity_query(ENTITY_WAR, 1)) + ANM2::LoadDeliriumForm(rider->sprite, npc.type, npc.variant, true); + return; + } + if (npc.type != ENTITY_DADDYLONGLEGS) return; + + for (Entity* leg : entity_query(ENTITY_DADDYLONGLEGS, npc.variant)) + { + if (leg == &npc) continue; + int frame = leg->sprite.animState.animData ? (int)std::floor(leg->sprite.animState.animFrame) : -1; + if (frame != 0) continue; + + std::string anim = leg->sprite.animState.animData ? leg->sprite.animState.animData->name : ""; + ANM2::LoadDeliriumForm(leg->sprite, npc.type, npc.variant, true); + leg->sprite.Play(anim); + leg->isInvincible = true; + } +} + +// Runs a boss form for a frame as the boss it mimics, his own health and pending damage kept out of the boss's hands, +// and redresses him when the boss turns into another. +static void boss_form_update(Entity_NPC& npc) +{ + bool isBigHornRising = npc.type == ENTITY_BIG_HORN && npc.state == NPC_STATE_MOVE && npc.stateFrame == 0 && + (!npc.sprite.animState.animData || !npc.sprite.animState.isPlaying); + int previousI1 = npc.i1; + float health = npc.health; + float maxHealth = npc.maxHitPoints; + std::vector damageEvents = std::move(npc.damageEvents); + float pendingDamage = npc.pendingDamage; + uint64_t pendingDamageFlags = npc.pendingDamageFlags; + + npc.damageEvents.clear(); + npc.pendingDamage = 0; + npc.pendingDamageFlags = 0; + delirium_form_update(npc); + npc.health = health; + npc.maxHitPoints = maxHealth; + npc.damageEvents = std::move(damageEvents); + npc.pendingDamageFlags = pendingDamageFlags; + npc.pendingDamage = pendingDamage; + + if (npc.type == ENTITY_BIG_HORN && isBigHornRising) big_horn_hands_dress(); + uint32_t cut = (uint32_t)(npc.pendingDamage * TELEPORT_DAMAGE_SHARE); + npc.deliriumTeleportTimer = cut <= npc.deliriumTeleportTimer ? npc.deliriumTeleportTimer - cut : 0; + if (npc.deliriumBossType != (uint32_t)npc.type || npc.deliriumBossVariant != (uint32_t)npc.variant) + { + npc.deliriumBossType = npc.type; + npc.deliriumBossVariant = npc.variant; + ANM2::LoadDeliriumForm(npc.sprite, npc.type, npc.variant, false); + } + form_spawns_dress(npc, previousI1); +} + +// His own form between attacks: back to idle after a blink, and quick to teleport once out of sight. +static void own_form_update(Entity_NPC& npc) +{ + if (npc.sprite.IsFinished("Blink")) npc.sprite.Play("Idle"); + npc.velocity = vector_make(0, 0); + if (!is_seen(npc)) npc.deliriumTeleportTimer = std::min(npc.deliriumTeleportTimer, TELEPORT_HIDDEN_FRAMES); +} + +// A form's frame: the boss runs as itself, then his shots, his rage tint, his teleport (bosses that stay in place stay) +// and the attack count. A companion's damage passes to him and it runs and shoots as a form too. +static void form_update(Entity_NPC& npc) +{ + int type = npc.type; + int variant = npc.variant; + + npc.type = (int)npc.deliriumBossType; + npc.variant = (int)npc.deliriumBossVariant; + if (npc.deliriumBossType == ENTITY_DELIRIUM) own_form_update(npc); + else boss_form_update(npc); + delirium_shots_fire(npc); + npc.type = type; + npc.variant = variant; + + float tint = npc.deliriumRageTimer ? RAGE_TINT : 1; + npc.SetColor({{1, tint, tint, 1}, {0, 0, 0, 0}, {0, 0, 0}}, -1, 0xff, false, false); + bool isStill = std::find(STILL_BOSSES.begin(), STILL_BOSSES.end(), (int)npc.deliriumBossType) != STILL_BOSSES.end(); + if (!isStill && npc.deliriumTeleportTimer == 0) delirium_teleport(npc); + else + { + if (!isStill) npc.deliriumTeleportTimer = npc.deliriumTeleportTimer - 1; + npc.deliriumFormAge = npc.deliriumFormAge + 1; + } + + bool isAttackState = std::find(ATTACK_STATES.begin(), ATTACK_STATES.end(), npc.state) != ATTACK_STATES.end(); + if (npc.stateFrame == 1 && isAttackState) npc.deliriumRemainingAttacks--; + + Entity* companion = npc.deliriumEntity; + if (!companion || companion->isDead) return; + + npc.TakeDamage(companion->pendingDamage, companion->pendingDamageFlags, EntityRef(), SECOND_FRAMES); + delirium_form_update(*static_cast(companion)); + delirium_shots_fire(*static_cast(companion)); +} + +// A boss met this run he may change into, or his own form one roll in 10. +// The original reads a missing entity's config through null. A missing one is not usable here. +static BossId form_pick(Entity_NPC& npc) +{ + uint32_t roll = Random() % FORM_ROLL; + BossId form = {ENTITY_DELIRIUM, 0}; + + for (int draws = FORM_DRAWS; draws > 0; draws--) + { + EntityConfig_Entity* config = g_manager->entityConfig.GetEntity(form.type, form.variant, 0); + bool isLeft = form.type == (int)npc.deliriumBossType && form.variant == (int)npc.deliriumBossVariant; + bool isUsable = form.type != ENTITY_DELIRIUM && form.type != ENTITY_HORNFEL && form.type != ENTITY_GIDEON && + config && !(config->tags & ENTITY_TAG_NODELIRIUM) && !isLeft; + if (roll < OWN_FORM_ODDS || isUsable) break; + + std::vector& met = g_game->encounteredBosses; + form = met.empty() ? BossId{} : met[Random() % met.size()]; + } + return form; +} + +// Rolls a rage for the new form (never Mom's or Satan's variant 10), its odds starting over after one. +static void rage_roll(Entity_NPC& npc) +{ + bool isCalm = npc.deliriumBossType == ENTITY_MOM || + (npc.deliriumBossType == ENTITY_SATAN && npc.deliriumBossVariant == ALTERNATE_FORM_VARIANT); + if (isCalm || npc.deliriumRageChance <= Random() % FORM_ROLL) + { + if (!isCalm) npc.deliriumRageChance = npc.deliriumRageChance + RAGE_ODDS_STEP; + npc.deliriumRageTimer = 0; + return; + } + npc.deliriumRageTimer = DELIRIUM_RAGE_FRAMES; + npc.deliriumRageChance = 0; +} + +// Wakes the parts of a chained boss in his colors, Chub's, Pin's and Mom's Heart's sharing the form's health. +static void form_chain_dress(Entity_NPC& npc, bool isShared, float maxHealth) +{ + auto dress = [&](Entity& link) + { + ANM2::LoadDeliriumForm(link.sprite, link.type, link.variant, true); + if (!isShared) return; + link.AddEntityFlags(FLAG_NO_DEATH_TRIGGER | FLAG_DONT_COUNT_BOSS_HP); + link.health = maxHealth; + link.maxHitPoints = maxHealth; + link.isInvincible = true; + }; + + for (Entity* link = npc.child; link; link = link->child) dress(*link); + for (Entity* link = npc.parent; link; link = link->parent) dress(*link); +} + +// Starts the bosses that set up their parts on their first update, dressing the parts in his colors. +static void form_start(Entity_NPC& npc, float maxHealth) +{ + Vector targetPos = npc.GetPlayerTarget()->pos; + if (npc.type == ENTITY_GURDY || npc.type == ENTITY_MOMS_HEART) npc_ai_update(npc); + npc.GetPlayerTarget()->pos = targetPos; + + if (npc.type == ENTITY_MOM) + { + npc.PlaySound(SOUND_MOM_VOX_ISAAC, 1, MOM_VOICE_DELAY, false, 1); + npc.AddEntityFlags(FLAG_NO_DEATH_TRIGGER); + npc.targetPosition = npc.pos; + npc.state = NPC_STATE_IDLE; + npc.subtype = 2; + npc.projectileCooldown = SECOND_FRAMES; + npc.entityCollisionClass = ENTCOLL_NONE; + } + if (npc.type == ENTITY_GEMINI) + { + npc_ai_update(npc); + for (Entity* cord : entity_query(npc.type, GEMINI_UMBILICAL)) + ANM2::LoadDeliriumForm(cord->sprite, cord->type, cord->variant, true); + if (npc.child) ANM2::LoadDeliriumForm(npc.child->sprite, npc.child->type, npc.child->variant, true); + } + if (npc.type == ENTITY_HUSH) + { + npc_ai_update(npc); + npc.state = NPC_STATE_IDLE; + npc.sprite.Play("Idle"); + } + if ((npc.type == ENTITY_LOKI && npc.variant == 1) || npc.type == ENTITY_SISTERS_VIS) + { + npc_ai_update(npc); + for (Entity* other : entity_query(npc.type, npc.variant)) + ANM2::LoadDeliriumForm(other->sprite, other->type, other->variant, true); + } + if (npc.type == ENTITY_SISTERS_VIS) npc.deliriumEntity = npc.child.get(); + if (npc.type == ENTITY_GATE) npc_ai_update(npc); + if (npc.type == ENTITY_MASK_OF_INFAMY) + { + npc_ai_update(npc); + form_chain_dress(npc, false, maxHealth); + } + if (npc.type == ENTITY_THE_LAMB && npc.variant != (int)ALTERNATE_FORM_VARIANT) return; + if (npc.type == ENTITY_THE_LAMB) npc_ai_update(npc); + if (npc.type == ENTITY_CHUB || npc.type == ENTITY_PIN || npc.type == ENTITY_MOMS_HEART) + { + npc_ai_update(npc); + form_chain_dress(npc, true, maxHealth); + } + if (npc.type == ENTITY_CHUB) npc.state = NPC_STATE_IDLE; +} + +// Changes him into his next form: what the last one left goes, the new boss inits in his place (clamped into the +// room) keeping his health, with its body and maybe a companion, and he leaves a poof the size of the boss. +static void delirium_morph(Entity_NPC& npc, FormSeconds seconds) +{ + delirium_minions_remove((int)npc.deliriumBossType, (int)npc.deliriumBossVariant, npc, npc.deliriumEntity); + if (npc.deliriumBossType == ENTITY_THE_LAMB && npc.deliriumBossVariant == ALTERNATE_FORM_VARIANT && npc.child) + npc.child->Remove(); + + BossId form = form_pick(npc); + npc.deliriumBossType = form.type; + npc.deliriumBossVariant = form.variant; + if (form.type == 0) log_printf(LOG_ASSERT, "No form for Delirium"); + rage_roll(npc); + if (form.type == ENTITY_MAMA_GURDY) npc.deliriumBossVariant = 0; + else if (form.type == ENTITY_MOM || (form.type == ENTITY_SATAN && (Random() & 1) == 0)) + npc.deliriumBossVariant = ALTERNATE_FORM_VARIANT; + + int type = npc.type; + int variant = npc.variant; + float health = npc.health; + float maxHealth = npc.maxHitPoints; + Vector spot = g_game->room->GetClampedPositionImpl(npc.pos, npc.size, npc.size, npc.size, npc.size); + + npc.type = (int)npc.deliriumBossType; + npc.variant = (int)npc.deliriumBossVariant; + npc.ClearReferences(); + log_printf(LOG_INFO, "Changed Delirium form to %d:%u.\n", npc.type, (uint32_t)npc.variant); + npc.Init(npc.type, npc.variant, 0, Random()); + npc.pos = spot; + npc.deliriumBossType = npc.type; + npc.state = NPC_STATE_INIT; + npc.deliriumBossVariant = npc.variant; + npc.deliriumTransformationTimer = form_frames_roll(seconds); + npc.deliriumRemainingAttacks = (uint8_t)(Random() % NPC_STATE_ATTACKS_ROLL + NPC_STATE_ATTACKS_MIN); + ANM2::LoadDeliriumForm(npc.sprite, npc.type, npc.variant, true); + delirium_segments_spawn(npc, maxHealth); + delirium_companion_spawn(npc); + npc.deliriumState = DELIRIUM_FORM; + npc.stateFrame = 0; + if (npc.type == ENTITY_SATAN && npc.deliriumBossVariant == ALTERNATE_FORM_VARIANT) + npc.entityCollisionClass = ENTCOLL_NONE; + else if (npc.type == ENTITY_SATAN) + { + npc.i1 = 2; + npc.state = NPC_STATE_MOVE; + } + form_start(npc, maxHealth); + + npc.deliriumFormAge = 0; + npc.health = health; + npc.maxHitPoints = maxHealth; + npc.type = type; + npc.variant = variant; + Entity* cloud = spawn_at(ENTITY_EFFECT, EFFECT_POOF02, poof_size_get(npc, false), npc.pos, &npc); + cloud->posOffset = npc.posOffset; + cloud->renderDepthOffset = npc.posOffset.y + 1; +} + +// His death: every enemy and shot in the room dies with him, and he comes back in his own form, invincible at one +// health, for the hallucinations and the scream. +static void delirium_death_start(Entity_NPC& npc) +{ + Game& game = *g_game; + std::vector& updated = game.room->entityList.updateEL; + + delirium_minions_remove((int)npc.deliriumBossType, (int)npc.deliriumBossVariant, npc, npc.deliriumEntity); + for (size_t i = 0; i < updated.size(); i++) + { + Entity& entity = *updated[i]; + bool isFoe = (game.deathmatchManager.state >= DEATHMATCH_INTRO && entity.type == ENTITY_PLAYER) || + (entity.type >= ENTITY_FIRST_ENEMY && entity.type < ENTITY_EFFECT); + if (isFoe && entity.CanShutDoors() && entity.type != ENTITY_DARK_ESAU && !entity.HasEntityFlags(FLAG_FRIENDLY)) + entity.Kill(EntityRef()); + if (entity.type == ENTITY_PROJECTILE) entity.isDead = true; + } + + npc.isDead = false; + Vector spot = game.room->GetClampedPositionImpl(npc.pos, npc.size, npc.size, npc.size, npc.size); + npc.ClearReferences(); + npc.Init(ENTITY_DELIRIUM, 0, 0, Random()); + npc.pos = spot; + npc.sprite.Play("Idle", PLAY_FORCED); + npc.deliriumState = DELIRIUM_DYING; + npc.deliriumTransformationTimer = DEATH_HALLUCINATIONS; + npc.velocity = vector_make(0, 0); + npc.health = 1; + npc.isInvincible = true; + npc.entityCollisionClass = ENTCOLL_NONE; +} + +// The hallucinations, one each time the last ends (0.4 seconds a one left), then the gurgle. +static void delirium_dying_update(Entity_NPC& npc) +{ + npc.sprite.Update(); + if (g_game->hallucinationTimer > 0) return; + + int left = npc.deliriumTransformationTimer; + g_game->ShowHallucination((int)((float)left * HALLUCINATION_SECONDS * SECOND_FRAMES), + left == 1 ? HALLUCINATION_LAST : HALLUCINATION_RANDOM); + if (--npc.deliriumTransformationTimer != 0) return; + + npc.deliriumState = DELIRIUM_SCREAM; + npc.deliriumTransformationTimer = SCREAM_LOOPS; + npc_sound_play(SOUND_ANGRY_GURGLE, GURGLE_VOLUME, DELIRIUM_SOUND_DELAY, GURGLE_PITCH); + npc.sprite.Play("IdleNoLoop", PLAY_FORCED); +} + +// The double speed loops, then the scream, after which he dies for good. +static void delirium_scream_update(Entity_NPC& npc) +{ + if (npc.sprite.IsPlaying("IdleNoLoop")) + { + npc.sprite.Update(); + npc.sprite.Update(); + } + if (npc.sprite.IsFinished("IdleNoLoop")) + { + if (--npc.deliriumTransformationTimer == 0) npc.sprite.Play("Scream"); + else npc.sprite.Play("IdleNoLoop", PLAY_FORCED); + return; + } + if (npc.sprite.IsFinished("Scream")) npc.isDead = true; +} + +// His first frame: invincible and idle, a shot pattern to draw, a form to change into and a teleport to come. +static void delirium_start(Entity_NPC& npc, FormSeconds seconds) +{ + npc.isInvincible = true; + npc.sprite.Play("Idle"); + npc.deliriumState = DELIRIUM_MORPH; + npc.deliriumBossType = 0; + npc.deliriumBossVariant = 0; + npc.deliriumTransformationTimer = form_frames_roll(seconds); + uint32_t attacks = Random(); + npc.deliriumAttackFrame = 0; + npc.deliriumAttackKeepChance = 0; + npc.deliriumAttackPattern = RANDOM_PATTERN; + npc.deliriumAttackRepeats = 0; + npc.deliriumAttackAngle = 0; + npc.state = NPC_STATE_ATTACK; + npc.deliriumRemainingAttacks = (uint8_t)(attacks % NPC_STATE_ATTACKS_ROLL + NPC_STATE_ATTACKS_MIN); + npc.shieldFrames = START_SHIELD_FRAMES; + npc.deliriumTeleportTimer = Random() % TELEPORT_FRAMES_ROLL + TELEPORT_FRAMES_MIN; +} + +// 004a6500 NpcAI::ENTITY_DELIRIUM: Delirium changes into the bosses met this run (or his own form), each for a few +// seconds and a few attacks, running them faster as he weakens, shooting his own patterns over them and teleporting +// ahead of his target. His death kills the room and plays out in hallucinations and a scream. +void boss_delirium_update(Entity_NPC& npc) +{ + FormSeconds seconds = FORM_SECONDS[(int)(health_share_get(npc) * HEALTH_FIFTHS)]; + + if (npc.isDead) return delirium_death_start(npc); + switch (npc.deliriumState) + { + case DELIRIUM_DYING: + delirium_dying_update(npc); + npc.velocity = vector_make(0, 0); + return; + case DELIRIUM_SCREAM: + delirium_scream_update(npc); + npc.velocity = vector_make(0, 0); + return; + case DELIRIUM_START: + return delirium_start(npc, seconds); + case DELIRIUM_FORM: + if (--npc.deliriumTransformationTimer == 0 || npc.deliriumRemainingAttacks == 0) + { + npc.deliriumState = DELIRIUM_MORPH; + npc.stateFrame = 0; + } + break; + default: + break; + } + + npc.shieldStrength = (1 - npc.health / npc.maxHitPoints) * SHIELD_STRENGTH; + if (npc.deliriumBossType == ENTITY_DELIRIUM) npc.shieldStrength = 0; + if (npc.deliriumState == DELIRIUM_MORPH) return delirium_morph(npc, seconds); + if (npc.deliriumState == DELIRIUM_FORM) form_update(npc); +} diff --git a/src/boss_famine.cpp b/src/boss_famine.cpp index 42b69d3..3660e13 100644 --- a/src/boss_famine.cpp +++ b/src/boss_famine.cpp @@ -45,8 +45,6 @@ constexpr float FAMINE_STEER_MAX = 0.4f; constexpr float FAMINE_WRAP_REACH = 200; constexpr float FAMINE_WRAP_ENTRY = 80; -// Mega Satan's room holds a horseman below this line. -constexpr float HORSEMAN_MEGA_SATAN_FLOOR = 320; constexpr float HORSEMAN_MEGA_SATAN_PULL = 0.5f; // Hurt below a third of its health, it loses its horse in a blood explosion and goes on as a head. diff --git a/src/boss_forsaken.cpp b/src/boss_forsaken.cpp new file mode 100644 index 0000000..776424e --- /dev/null +++ b/src/boss_forsaken.cpp @@ -0,0 +1,361 @@ +#include "boss_ai.h" +#include "deathmatch_manager.h" +#include "entity_laser.h" +#include "entity_player.h" +#include "npc_caves.h" +#include "room_grid.h" +#include "sfx_manager.h" + +// The Forsaken's states: resting, summoning Bonys (Black Bonys for the black one), summoning Death's Heads (the black +// one), the fade cycle, and the laser spin. +constexpr int FORSAKEN_IDLE = NPC_STATE_IDLE; +constexpr int FORSAKEN_SUMMON = NPC_STATE_SUMMON; +constexpr int FORSAKEN_SKULLS = NPC_STATE_SUMMON2; +constexpr int FORSAKEN_FADE = NPC_STATE_SPECIAL; +constexpr int FORSAKEN_BLAST = NPC_STATE_ATTACK; +constexpr int FORSAKEN_BLACK = 1; + +// The fade cycle, by i1: fading out, waiting faded, drifting to the room's center, fading back in. +enum FadeStep +{ + FADE_OUT, + FADE_WAIT, + FADE_DRIFT, + FADE_IN +}; + +// The laser spin, by i1: its start, the spin, its end. +enum BlastStep +{ + BLAST_START, + BLAST_SPIN, + BLAST_END +}; + +constexpr float FORSAKEN_FRICTION = 0.9f; +constexpr float BLAST_FRICTION = 0.7f; +constexpr ColorMod FORSAKEN_SPLAT_COLOR = {{0, 0, 0, 0.3f}, {0, 0, 0, 0}, {0.8f, 0.8f, 0.8f}}; + +// Summons: one Bony at a free spot 70 out (two below a quarter health), Death's Heads two at a time, and while many +// minions are about the fade leads to the lasers instead. +constexpr int IDLE_FRAMES = 150; +constexpr float FORSAKEN_SUMMON_REACH = 70; +constexpr float SUMMON_LOW_HEALTH = 0.25f; +constexpr float DELIRIUM_MINION_HEALTH = 10; +constexpr int DEATHS_HEADS = 2; +constexpr int DEATHS_HEAD_RED = 1; +constexpr int MINIONS_FOR_BLAST = 3; + +// The fade: it waits faded until its minions are gone or a player touches it, drifts to the room's center for at +// most 120 frames, and fades back in. +constexpr float DRIFT_PUSH = 1.2f; +constexpr float DRIFT_MAX_SPEED = 3.2f; +constexpr int DRIFT_FRAMES = 120; +constexpr float DRIFT_ARRIVE = 45; + +// The lasers: three (and the first again) from its hands 120 apart, turned a random 30 either way from its target's +// opposite, spinning together after a random delay, matching another boss's spinning lasers. +constexpr int BLAST_LASERS = 4; +constexpr float BLAST_SPACING = 120; +constexpr float BLAST_HEIGHT = -30; +constexpr int BLAST_TIMEOUT = 120; +constexpr float BLAST_TURN = 1800; +constexpr float BLAST_SPIN_SPEED = 2; +constexpr float BLAST_SPIN_PER_MINION = 0.25f; +constexpr uint32_t BLAST_DELAY_RANGE = 30; +constexpr uint32_t BLAST_DELAY_MIN = 15; +constexpr uint32_t SYNC_DELAY_RANGE = 10; +constexpr uint32_t SYNC_DELAY_MIN = 5; +constexpr int BLAST_SPIN_FRAMES = 120; +constexpr float BLAST_AIM_RANGE = 60; +constexpr float FORSAKEN_TRACER_HEIGHT = -32; +constexpr float FORSAKEN_TRACER_SCALE = 4; +constexpr int FORSAKEN_TRACER_TIMEOUT = 25; +constexpr ColorMod FORSAKEN_TRACER_COLOR = {{0.6f, 0.05f, 0, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}}; + +// What the Forsaken counts each frame: its living minions, all its minions, and the hostile Death's Heads. +struct ForsakenCount +{ + size_t group = 0; + int minions = 0; + int skulls = 0; +}; + +// Restarts an animation unless it already shows (or loops on, stopped). +static void anim_keep(Entity_NPC& npc, std::string_view anim) +{ + const AnimationData* shown = npc.sprite.animState.animData; + if (shown && shown->name == anim && !(shown->isLooping && !npc.sprite.animState.isPlaying)) return; + npc_anim_restart(npc.sprite, anim); +} + +// A random spot 70 out from the Forsaken. +static Vector summon_spot_roll(const Entity_NPC& npc) +{ + float angle = random_unit() * RANDOM_HALF_TURN; + angle += angle; + return vector_make(std::cos(angle) * FORSAKEN_SUMMON_REACH + npc.pos.x, + std::sin(angle) * FORSAKEN_SUMMON_REACH + npc.pos.y); +} + +static int minion_type_get(const Entity_NPC& npc) +{ + return npc.subtype == FORSAKEN_BLACK ? ENTITY_BLACK_BONY : ENTITY_BONY; +} + +static void fade_start(Entity_NPC& npc) +{ + npc.stateFrame = 0; + npc.i1 = FADE_OUT; + npc.state = FORSAKEN_FADE; +} + +// The summon's Summon: laughing as it starts, a Bony (or a Black Bony) while it has too few or was touched while +// faded, at most one for a Delirium form. Then the fade. +static void forsaken_summon(Entity_NPC& npc, const ForsakenCount& count) +{ + if (npc.sprite.GetAnimation() != "Summon") npc_sound_play(SOUND_FORSAKEN_LAUGH, 1, 2, 1); + anim_keep(npc, "Summon"); + + int wanted = npc.health < npc.maxHitPoints * SUMMON_LOW_HEALTH ? 2 : 1; + bool isWanted = count.minions < wanted || npc.i2 != 0; + if (isWanted && npc.sprite.animState.animData && npc.sprite.animState.IsEventTriggered("Summon")) + { + npc.i2 = 0; + Vector spot = room_free_pickup_position_find({.position = summon_spot_roll(npc)}); + int type = minion_type_get(npc); + if (!npc.HasEntityFlags(FLAG_DELIRIUM_FORM) || npc.CountRelatedEntities(type, 0, nullptr) == 0) + { + auto* minion = static_cast( + g_game->Spawn({.position = spot, .spawner = &npc, .type = type, .seed = Random()})); + minion->groupIdx = npc.index; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + { + minion->health = DELIRIUM_MINION_HEALTH; + minion->maxHitPoints = DELIRIUM_MINION_HEALTH; + } + } + } + if (npc_anim_is_done(npc)) fade_start(npc); +} + +// The black Forsaken's other summon: two red Death's Heads about it. Then the fade. +static void forsaken_skulls(Entity_NPC& npc) +{ + if (npc.sprite.GetAnimation() != "Summon") npc_sound_play(SOUND_FORSAKEN_LAUGH, 1, 2, 1); + anim_keep(npc, "Summon"); + if (npc.sprite.animState.animData && npc.sprite.animState.IsEventTriggered("Summon")) + for (int i = 0; i < DEATHS_HEADS; i++) + { + Vector spot = summon_spot_roll(npc); + g_game->Spawn({.position = spot, + .spawner = &npc, + .type = ENTITY_DEATHS_HEAD, + .variant = DEATHS_HEAD_RED, + .seed = Random()}); + } + if (npc_anim_is_done(npc)) fade_start(npc); +} + +// Fading back in: it summons again when touched while faded with few minions, else the black one rests or summons +// skulls and the plain one shows where its lasers will spin. +static void fade_in_end(Entity_NPC& npc, const ForsakenCount& count) +{ + npc.stateFrame = 0; + npc.i1 = 0; + if (npc.i2 != 0 && count.group <= MINIONS_FOR_BLAST) + { + npc.state = FORSAKEN_SUMMON; + return; + } + if (npc.subtype == FORSAKEN_BLACK) + { + npc.state = count.skulls == 0 ? FORSAKEN_SKULLS : FORSAKEN_IDLE; + return; + } + + npc.state = FORSAKEN_BLAST; + npc_sound_play(SOUND_FORSAKEN_SCREAM, 1, 2, 1); + Vector toTarget = vector_sub(npc.GetPlayerTarget()->pos, npc.pos); + float aim = std::atan2(toTarget.y, toTarget.x) * RADIANS_TO_DEGREES; + npc.v1.x = random_unit() * BLAST_AIM_RANGE - BLAST_AIM_RANGE / 2 + aim + HALF_TURN_DEGREES; + for (int i = 0; i < BLAST_LASERS; i++) + following_effect_spawn(npc, {.offset = vector_make(0, FORSAKEN_TRACER_HEIGHT), + .targetPosition = vector_from_angle((float)i * BLAST_SPACING + npc.v1.x), + .color = FORSAKEN_TRACER_COLOR, + .scale = FORSAKEN_TRACER_SCALE, + .timeout = FORSAKEN_TRACER_TIMEOUT}); +} + +// The fade cycle: out (untouchable), waiting, drifting to the center, back in. +static void forsaken_fade(Entity_NPC& npc, const ForsakenCount& count) +{ + switch (npc.i1) + { + case FADE_OUT: + if (npc.sprite.GetAnimation() != "FadeOut") + { + anim_keep(npc, "FadeOut"); + npc.PlaySound(SOUND_FORSAKEN_FADE, 1, 2, false, 1); + } + if (!npc_anim_is_done(npc)) return; + npc.stateFrame = 0; + npc.i1 = FADE_WAIT; + npc.isInvincible = true; + npc.entityCollisionClass = ENTCOLL_NONE; + npc.i2 = 0; + return; + case FADE_WAIT: + { + anim_keep(npc, "Faded"); + Entity_Player* nearest = game_nearest_player(npc.pos); + npc.i2 = vector_length(vector_sub(npc.pos, nearest->pos)) < npc.size + nearest->size; + if (count.minions != 0 && npc.i2 == 0) return; + npc.stateFrame = 0; + npc.i1 = FADE_DRIFT; + return; + } + case FADE_DRIFT: + { + anim_keep(npc, "Faded"); + Vector center = Room::GetCenterPos(); + npc_push(npc, vector_scale(vector_normalized(vector_sub(center, npc.pos)), DRIFT_PUSH)); + if (vector_length(npc.velocity) > DRIFT_MAX_SPEED) + npc.velocity = vector_resized(npc.velocity, DRIFT_MAX_SPEED); + if (npc.stateFrame <= DRIFT_FRAMES && vector_length(vector_sub(npc.pos, center)) >= DRIFT_ARRIVE) return; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && + npc.CountRelatedEntities(minion_type_get(npc), 0, nullptr) != 0) + return; + + npc.stateFrame = 0; + npc.i1 = FADE_IN; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) npc.i2 = 0; + npc.isInvincible = false; + npc.entityCollisionClass = ENTCOLL_ALL; + return; + } + case FADE_IN: + anim_keep(npc, "FadeIn"); + if (npc_anim_is_done(npc)) fade_in_end(npc, count); + return; + } +} + +// The spin's lasers: four from its hands, spinning after a random delay, or in time with another boss's. +static void blast_fire(Entity_NPC& npc, const ForsakenCount& count) +{ + uint32_t delay = Random() % BLAST_DELAY_RANGE + BLAST_DELAY_MIN; + float spin = Random() & 1 ? BLAST_SPIN_SPEED : -BLAST_SPIN_SPEED; + spin *= (float)count.group * BLAST_SPIN_PER_MINION + 1; + for (Entity* other : entity_query(ENTITY_LASER, -1)) + { + auto* laser = static_cast(other); + Entity* owner = laser->parent; + if (!laser->isActiveRotating || laser->rotationSpd == 0 || !owner || owner == &npc) continue; + bool isPlayerOwner = g_game->deathmatchManager.is_active() && owner->type == ENTITY_PLAYER; + if (!isPlayerOwner && (owner->type < ENTITY_FIRST_ENEMY || owner->type > ENTITY_LAST_ENEMY)) continue; + spin = laser->rotationSpd; + delay = Random() % SYNC_DELAY_RANGE + SYNC_DELAY_MIN; + break; + } + + for (int i = 0; i < BLAST_LASERS; i++) + { + Entity_Laser* laser = Entity_Laser::ShootAngle({.position = vector_make(npc.pos.x, npc.pos.y + BLAST_HEIGHT), + .source = &npc, + .angleDegrees = (float)i * BLAST_SPACING + npc.v1.x, + .timeout = BLAST_TIMEOUT, + .variant = LASER_THICK_RED}); + laser->rotationDelay = delay; + laser->isActiveRotating = true; + laser->rotationDegrees = BLAST_TURN; + laser->rotationSpd = spin; + laser->Update(); + } +} + +// The laser spin: its start fires the lasers on Blast, it spins for 120 frames and ends, resting. +static void forsaken_blast(Entity_NPC& npc, const ForsakenCount& count) +{ + switch (npc.i1) + { + case BLAST_START: + anim_keep(npc, "BlastStart"); + if (npc.sprite.animState.animData && npc.sprite.animState.IsEventTriggered("Blast")) blast_fire(npc, count); + if (!npc_anim_is_done(npc)) return; + npc.stateFrame = 0; + npc.i1 = BLAST_SPIN; + return; + case BLAST_SPIN: + npc.friction *= FORSAKEN_FRICTION; + anim_keep(npc, "Blasting"); + if (npc.stateFrame <= BLAST_SPIN_FRAMES) return; + npc.stateFrame = 0; + npc.i1 = BLAST_END; + return; + case BLAST_END: + anim_keep(npc, "BlastEnd"); + if (!npc_anim_is_done(npc)) return; + npc.stateFrame = 0; + npc.i1 = 0; + npc.state = FORSAKEN_IDLE; + return; + } +} + +// 0048f110 NpcAI::ENTITY_FORSAKEN: the Forsaken summons Bonys, fades out until they are gone, drifts to the room's +// center and fades back in to spin four lasers. The black one summons Black Bonys and Death's Heads instead. +void boss_forsaken_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.state = FORSAKEN_SUMMON; + npc.stateFrame = 0; + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + npc.splatColor = FORSAKEN_SPLAT_COLOR; + return; + } + + npc.stateFrame++; + ForsakenCount count; + std::vector group = Entity_NPC::QueryNPCsGroup(npc.index); + count.group = group.size(); + for (Entity_NPC* minion : group) + if (minion->IsActiveEnemy(DEAD_EXCLUDED) && minion->type != ENTITY_FROZEN_ENEMY) count.minions++; + for (Entity* skull : entity_query(ENTITY_DEATHS_HEAD, -1)) + if (!skull->HasEntityFlags(FLAG_FRIENDLY)) count.skulls++; + + if (npc.sprite.animState.animData && npc.sprite.animState.IsEventTriggered("ArmsUp")) + npc_sound_play(SOUND_FORSAKEN_ARMS_UP, 1, 2, champion_pitch_get(npc)); + + bool isStill = false; + switch (npc.state) + { + case FORSAKEN_IDLE: + anim_keep(npc, "Idle"); + if (npc.stateFrame > IDLE_FRAMES) + { + npc.stateFrame = 0; + npc.state = FORSAKEN_SUMMON; + } + break; + case FORSAKEN_SUMMON: + forsaken_summon(npc, count); + break; + case FORSAKEN_SKULLS: + forsaken_skulls(npc); + break; + case FORSAKEN_FADE: + isStill = npc.i1 == FADE_IN; + forsaken_fade(npc, count); + break; + case FORSAKEN_BLAST: + isStill = npc.i1 >= BLAST_START && npc.i1 <= BLAST_END; + forsaken_blast(npc, count); + break; + } + + if (isStill) npc.friction *= BLAST_FRICTION; + else npc.pathfinder.MoveRandomlyBoss(STATUS_OBEYED); + npc.friction *= FORSAKEN_FRICTION; +} diff --git a/src/boss_headless_horseman.cpp b/src/boss_headless_horseman.cpp new file mode 100644 index 0000000..efedd24 --- /dev/null +++ b/src/boss_headless_horseman.cpp @@ -0,0 +1,181 @@ +#include "boss_ai.h" +#include "entity_projectile.h" +#include "npc_caves.h" +#include "sfx_manager.h" + +// The Headless Horseman's states: walking (the head floating), the attack, the head's charge and the head's shot. +constexpr int HORSEMAN_WALK = NPC_STATE_MOVE; +constexpr int HORSEMAN_ATTACK = NPC_STATE_ATTACK; +constexpr int HEAD_CHARGE = NPC_STATE_ATTACK; +constexpr int HEAD_SHOOT = NPC_STATE_ATTACK2; + +constexpr uint64_t HORSEMAN_DISTRACTED = FLAG_CONFUSION | FLAG_FEAR | FLAG_SHRINK; +constexpr float HORSEMAN_FRICTION = 0.8f; +constexpr int HORSEMAN_ATTACK_FRAMES = 31; + +// The body: it walks along the axes at random and now and then lobs a big bursting shot of red creep. +constexpr float BODY_WALK_SPEED = 1; +constexpr float BODY_ANIM_SPEED = 3; +constexpr uint32_t BODY_ATTACK_ODDS = 40; +constexpr int BODY_SHOOT_FRAME = 9; +constexpr float BODY_SHOT_ARC = 10; +constexpr float BODY_SHOT_ACCEL = 0.3f; +constexpr float BODY_SHOT_SCALE = 1.6f; +constexpr float BODY_SHOT_FALL = 0.7f; +constexpr float BODY_SHOT_LIFT = 13; +constexpr float BODY_SHOT_RISE = 27; +constexpr float BODY_SHOT_SLOW = 0.55f; +constexpr float BODY_SHOT_LEAD = 10; + +// The head: it floats about, shoots three at its target's lead when near, and charges across the room one to three +// laps when far off or in line. +constexpr float HEAD_ANIM_SPEED = 2; +constexpr uint32_t HEAD_SHOOT_ODDS = 30; +constexpr float HEAD_SHOOT_RANGE = 200; +constexpr uint32_t HEAD_CHARGE_ODDS = 120; +constexpr float HEAD_LINE_BAND = 20; +constexpr uint32_t HEAD_LINE_CHARGE_ODDS = 80; +constexpr int HEAD_SHOOT_FRAME = 13; +constexpr float HEAD_SHOT_LEAD = 10; +constexpr float HEAD_SHOT_SPEED = 9.2f; +constexpr float HEAD_CHARGE_SPEED = 18; +constexpr float HEAD_HARD_CHARGE = 1.25f; +constexpr float HEAD_WRAP_REACH = 200; +constexpr float HEAD_LAP_DROP = 0.3f; +constexpr float HEAD_FLOOR_MARGIN = 40; + +// The body walking, and now and then its attack. +static void body_update(Entity_NPC& npc) +{ + npc.friction *= HORSEMAN_FRICTION; + if (npc.state == HORSEMAN_WALK) + { + npc.pathfinder.MoveRandomlyAxisAligned(BODY_WALK_SPEED, STATUS_OBEYED); + npc.AnimWalkFrame("Walk", "Walk", BODY_ANIM_SPEED); + if ((npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) || Random() % BODY_ATTACK_ODDS != 0) return; + + npc.state = HORSEMAN_ATTACK; + npc.stateFrame = 0; + npc_anim_restart(npc.sprite, "Attack"); + return; + } + if (npc.state != HORSEMAN_ATTACK) return; + + if (npc.stateFrame++ != BODY_SHOOT_FRAME) + { + if (npc.stateFrame >= HORSEMAN_ATTACK_FRAMES) npc.state = HORSEMAN_WALK; + return; + } + + npc.PlaySound(SOUND_HEARTOUT, 1, 2, false, 1); + ProjectileParams params; + Entity_Projectile* shot = npc.FireBossProjectiles(1, npc.GetPlayerTarget()->pos, BODY_SHOT_ARC, params); + shot->projectileFlags |= PROJECTILE_EXPLODE | PROJECTILE_ACID_RED; + shot->fallingAccel -= BODY_SHOT_ACCEL; + shot->scale = BODY_SHOT_SCALE; + shot->fallingSpeed = shot->fallingSpeed * BODY_SHOT_FALL - BODY_SHOT_LIFT; + shot->height -= BODY_SHOT_RISE; + shot->velocity = vector_scale(shot->velocity, BODY_SHOT_SLOW); + shot->pos.x += npc.sprite.isFlipX ? -BODY_SHOT_LEAD : BODY_SHOT_LEAD; + shot->Update(); +} + +// The head floating about, shooting when near and charging when far off or in line with its target. +static void head_float(Entity_NPC& npc) +{ + npc.pathfinder.MoveRandomlyBoss(STATUS_OBEYED); + npc.AnimWalkFrame("Walk", "Walk", HEAD_ANIM_SPEED); + Vector toTarget = vector_sub(npc.CalcTargetPosition(0), npc.pos); + if (Random() % HEAD_SHOOT_ODDS == 0 && vector_length(toTarget) < HEAD_SHOOT_RANGE) + { + npc.state = HEAD_SHOOT; + npc.stateFrame = 0; + npc_anim_restart(npc.sprite, "Attack"); + return; + } + bool isCharge = Random() % HEAD_CHARGE_ODDS == 0 || + (std::abs(toTarget.y) < HEAD_LINE_BAND && Random() % HEAD_LINE_CHARGE_ODDS == 0); + if (!isCharge || npc.HasEntityFlags(HORSEMAN_DISTRACTED)) return; + + npc.PlaySound(SOUND_MONSTER_YELL_A, 1, 2, false, 1); + npc.sprite.isFlipX = toTarget.x < 0; + npc.state = HEAD_CHARGE; + npc.targetPosition = npc.pos; + npc_anim_restart(npc.sprite, "Charge"); + npc.stateFrame = (int)(Random() % 3) + 1; +} + +// The head's charge: once Charge ends, Charge Shake carries it across the room and round past the far wall, a lap +// lower each time, until it passes where it set off after its last lap. +static void head_charge(Entity_NPC& npc) +{ + if (!npc.sprite.animState.animData) return; + if (!npc.sprite.animState.isPlaying && npc.sprite.GetAnimation() == "Charge") + npc_anim_restart(npc.sprite, "Charge Shake"); + if (npc_anim_is_done(npc) || npc.sprite.GetAnimation() != "Charge Shake") return; + + float speed = npc.sprite.isFlipX ? -HEAD_CHARGE_SPEED : HEAD_CHARGE_SPEED; + if (game_is_hard_mode()) speed *= HEAD_HARD_CHARGE; + npc.velocity.x = speed; + + Room& room = *g_game->room; + float left = room.topLeftPos.x - HEAD_WRAP_REACH; + float right = room.bottomRightPos.x + HEAD_WRAP_REACH; + bool isWrapped = speed > 0 ? npc.pos.x > right : speed < 0 && npc.pos.x < left; + if (isWrapped) + { + npc.pos.x = speed > 0 ? left : right; + npc.stateFrame--; + float drop = (room.bottomRightPos.y - room.topLeftPos.y) * HEAD_LAP_DROP; + npc.pos.y += drop; + if (npc.pos.y > room.bottomRightPos.y - HEAD_FLOOR_MARGIN) npc.pos.y -= drop * 3; + } + if (npc.stateFrame > 0) return; + if ((speed < 0 && npc.pos.x < npc.targetPosition.x) || (speed > 0 && npc.pos.x > npc.targetPosition.x)) + npc.state = HORSEMAN_WALK; +} + +// The head's shot: three at its target's lead on frame 13. +static void head_shoot(Entity_NPC& npc) +{ + if (npc.stateFrame++ != HEAD_SHOOT_FRAME) + { + if (npc.stateFrame >= HORSEMAN_ATTACK_FRAMES) npc.state = HORSEMAN_WALK; + return; + } + + npc.PlaySound(SOUND_MONSTER_GRUNT_2, 1, 2, false, 1); + Entity* prey = npc.GetPlayerTarget(); + Vector lead = vector_sub(vector_add(prey->pos, vector_scale(prey->velocity, HEAD_SHOT_LEAD)), npc.pos); + Vector velocity = vector_scale(vector_normalized(lead), HEAD_SHOT_SPEED); + npc.FireProjectiles(npc.pos, velocity, PROJECTILES_THREE, ProjectileParams()); +} + +// The head shrugs off the hurt its body deals it, floats or charges along the walls. +static void head_update(Entity_NPC& npc) +{ + if (npc.pendingDamage > 0) + for (DamageEvent& hurt : npc.damageEvents) + if (hurt.source.type == ENTITY_HEADLESS_HORSEMAN) hurt.damage = 0; + + npc.entityGridCollisionClass = GRIDCOLL_WALLS_Y; + npc.friction *= HORSEMAN_FRICTION; + if (npc.state == HEAD_CHARGE) return head_charge(npc); + + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + if (npc.state == HORSEMAN_WALK) head_float(npc); + else if (npc.state == HEAD_SHOOT) head_shoot(npc); +} + +// 0045cd60 NpcAI::ENTITY_HEADLESS_HORSEMAN: the body walks along the axes and lobs bursting shots of red creep, its +// head floats about, shoots three at a time and charges across the room lap after lap. +void boss_headless_horseman_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.state = HORSEMAN_WALK; + return; + } + if (npc.type == ENTITY_HEADLESS_HORSEMAN) body_update(npc); + else if (npc.type == ENTITY_HORSEMAN_HEAD) head_update(npc); +} diff --git a/src/boss_monstro.cpp b/src/boss_monstro.cpp index ab979bb..f4e0077 100644 --- a/src/boss_monstro.cpp +++ b/src/boss_monstro.cpp @@ -1,16 +1,22 @@ #include "boss_ai.h" -#include "entity_effect.h" +#include "entity_laser.h" +#include "entity_projectile.h" #include "grid_entity_trap_door.h" +#include "npc_caves.h" #include "room_descriptor.h" +#include "room_grid.h" #include "sfx_manager.h" -constexpr int ENTITY_MONSTRO = 20; +// Monstro's subtypes: a pair of twins, and one that never jumps. A Monstro II or Gish of subtype 1 is the quick one. constexpr int MONSTRO_TWINS = 1; constexpr int MONSTRO_NO_JUMP = 2; +constexpr int MONSTRO2_QUICK = 1; +constexpr int GISH = 1; +constexpr int GISH_CLOT = 1; constexpr int STAGE_ID_JUMP_DOWN = 25; constexpr float TWIN_OFFSET = 24; -// What Monstro does next from its idle pose, rolled in thirds. +// What Monstro does next from its idle pose: a hop, a spit (Monstro II's laser), or a jump off screen. enum MonstroAttack { MONSTRO_HOP, @@ -18,18 +24,24 @@ enum MonstroAttack MONSTRO_JUMP }; -// i1 of a Monstro dropping into the room from above, which lands on its target's way. +// i1 of a jump: the first and the second of Monstro II's pair, or a drop into the room from above, which lands on its +// target's way. +constexpr int JUMP_FIRST = 0; +constexpr int JUMP_SECOND = 1; constexpr int JUMP_DROP_IN = 2; constexpr float MONSTRO_FRICTION = 0.9f; constexpr float MONSTRO_LANDED_FRICTION = 0.8f; constexpr float MONSTRO_HOP_PULL = 1.2f; +constexpr float QUICK_HOP_PULL = 1.5f; +constexpr float QUICK_PLAYBACK = 1.5f; constexpr float HOP_MIN_DISTANCE = 0.001f; constexpr float JUMP_PULL = 0.006f; constexpr float JUMP_PUSH = 0.3f; constexpr float SPIT_CLOUD_HEIGHT = -29; constexpr float SPIT_CLOUD_SCALE = 0.7f; constexpr float HOP_DUST_HEIGHT = 15; +constexpr float DROP_IN_GAP = 5; constexpr int SPIT_SHOTS = 13; constexpr int STOMP_SHOTS = 18; @@ -41,15 +53,80 @@ constexpr float SHOCKWAVE_AMPLITUDE = 0.035f; constexpr float MONSTRO_SHOCKWAVE_SPEED = 0.025f; constexpr int SHOCKWAVE_FRAMES = 10; +// Monstro II: it lines up with its target to fire a laser, crushes its Suckers on landing, sprays eight shots off its +// first jump and frees Suckers off its second. +constexpr float LINE_UP_MIN = 20; +constexpr float LINE_UP_RANGE = 50; +constexpr float REPEAT_REROLL_ODDS = 0.9f; +constexpr float CRUSH_RADIUS = 70; +constexpr float MONSTRO_CRUSH_DAMAGE = 30; +constexpr int CRUSH_COUNTDOWN = 30; +constexpr float MONSTRO_LASER_HEIGHT = -20; +constexpr float LASER_RIGHT_DEGREES = 0; +constexpr float LASER_LEFT_DEGREES = 180; +constexpr int MONSTRO_LASER_TIMEOUT = 30; +constexpr float LASER_DEPTH = 3000; +constexpr float MONSTRO_TRACER_HEIGHT = -18; +constexpr float MONSTRO_TRACER_SCALE = 4; +constexpr int MONSTRO_TRACER_TIMEOUT = 22; +constexpr float MONSTRO_STOMP_RING_SPEED = 10; +constexpr float STOMP_RING_SCALE = 1.4f; +constexpr int SUCKER_ENEMY_LIMIT = 4; +constexpr int SUCKERS = 4; +constexpr int QUICK_SUCKERS = 2; +constexpr float SUCKER_VOLUME = 1.5f; +constexpr float QUICK_SUCKER_VOLUME = 1; +constexpr float SUCKER_VELOCITIES[SUCKERS][2] = {{5, 0}, {-5, 0}, {0, 5}, {0, -5}}; +constexpr ColorMod MONSTRO_TRACER_COLOR = {{0.6f, 0.05f, 0, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}}; + +// Gish: a tar shot that splashes into creep, a pool of creep off its first jump and a Clot to each side off its second. +constexpr float GISH_SHOT_ARC = 10; +constexpr float GISH_SHOT_ACCEL = 0.3f; +constexpr float GISH_SHOT_SCALE = 1.6f; +constexpr float GISH_SHOT_SPEED = 0.7f; +constexpr float GISH_SHOT_LIFT = 13; +constexpr float GISH_CREEP_SCALE = 3; +constexpr int CLOT_ENEMY_LIMIT = 2; +constexpr int CLOT_LIMIT = 2; +constexpr float CLOT_SPEED = 5; +constexpr float CLOT_HEALTH_CUT = 5; +constexpr float CLOT_PAIR_VOLUME = 1.5f; +constexpr ColorMod GISH_SHOT_COLOR = {{1, 1, 1, 1}, {0.5f, 0.5f, 0.5f, 1}, {0, 0, 0}}; +constexpr ColorMod GISH_SPLAT_COLOR = tint_color_make(0.02f, 0.05f, 0.05f, 1); +constexpr ColorMod GISH_POOF_COLOR = {{3, 3, 3, 1}, {0.03f, 0.03f, 0.03f, 1}, {0, 0, 0}}; + constexpr ColorMod HOP_DUST_COLOR = {{0.8f, 0.8f, 0.8f, 0.7f}, {0, 0, 0, 0}, {0, 0, 0}}; constexpr ColorMod SPIT_CLOUD_COLOR = {{1, 1, 1, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}}; -// Restarts an animation from its first frame, as the AIs switch to one (SetAnimation keeping the frame, then Rewind). -static void anim_restart(ANM2& sprite, std::string_view name) +static bool is_monstro2(const Entity_NPC& npc) { - if (!sprite.SetAnimation(name, SWITCH_KEEP_FRAME)) return; - sprite.animState.Rewind(); - sprite.animState.isPlaying = true; + return npc.type == ENTITY_MONSTRO2 && npc.variant == 0; +} + +static bool is_gish(const Entity_NPC& npc) +{ + return npc.type == ENTITY_MONSTRO2 && npc.variant == GISH; +} + +static bool is_quick(const Entity_NPC& npc) +{ + return npc.type == ENTITY_MONSTRO2 && npc.subtype == MONSTRO2_QUICK; +} + +// Gish's squelch as it sets off, none for the others. +static void gish_sound_play(const Entity_NPC& npc, int sound) +{ + if (is_gish(npc)) npc_sound_play(sound, 1, 2, 1); +} + +// Takes off on a jump: JumpUp from its start, Gish's squelch, and the quick one's faster jump. +static void jump_start(Entity_NPC& npc) +{ + npc.state = NPC_STATE_JUMP; + npc.PlaySound(SOUND_BOSS_LITE_ROAR, 1, 2, false, 1); + npc_anim_restart(npc.sprite, "JumpUp"); + gish_sound_play(npc, SOUND_GISH_JUMP_HIGH); + if (is_quick(npc)) npc.sprite.playbackSpeed = QUICK_PLAYBACK; } // Aims at the center of the cell under a position, unless the cell is blocked. Whether it did. @@ -61,12 +138,13 @@ static bool target_cell_set(Entity_NPC& npc, const Vector& position) return true; } -// The first frame: a twin Monstro (subtype 1) brings its brother 24 to its right, and on stage 25 Monstro drops in. +// The first frame: a twin Monstro (subtype 1) brings its brother 24 to its right, Gish takes its tar splat, and on +// stage 25 any of them drops in. static void monstro_init(Entity_NPC& npc) { npc.state = NPC_STATE_IDLE; - npc.i1 = 0; - if (npc.subtype == MONSTRO_TWINS && npc.spawnerType != ENTITY_MONSTRO) + npc.i1 = JUMP_FIRST; + if (npc.type == ENTITY_MONSTRO && npc.subtype == MONSTRO_TWINS && npc.spawnerType != ENTITY_MONSTRO) { g_game->Spawn({.position = vector_make(npc.pos.x + TWIN_OFFSET, npc.pos.y), .velocity = npc.velocity, @@ -77,6 +155,7 @@ static void monstro_init(Entity_NPC& npc) .seed = Random()}); npc.pos.x -= TWIN_OFFSET; } + if (is_gish(npc)) npc.splatColor = GISH_SPLAT_COLOR; if (g_game->GetStageID() != STAGE_ID_JUMP_DOWN) return; npc.ClearEntityFlags(FLAG_APPEAR); @@ -84,11 +163,33 @@ static void monstro_init(Entity_NPC& npc) npc.i1 = JUMP_DROP_IN; const AnimationData* shown = npc.sprite.animState.animData; if (shown && shown->name == "JumpDown" && (!shown->isLooping || npc.sprite.animState.isPlaying)) return; - anim_restart(npc.sprite, "JumpDown"); + npc_anim_restart(npc.sprite, "JumpDown"); } -// The idle pose rolls the next attack: a hop, a spit or a jump (never a jump for subtype 2), only hops for a calm -// Delirium form. +// The next attack: Monstro II spits its laser when in line with its target and else hops or jumps, the others roll +// thirds (never a jump for Monstro's subtype 2). Both of type 43 mostly avoid repeating themselves. +static int attack_roll(Entity_NPC& npc) +{ + int attack; + if (is_monstro2(npc)) + { + Entity* prey = npc.GetPlayerTarget(); + bool isInLine = random_unit() * LINE_UP_RANGE + LINE_UP_MIN > std::abs(npc.pos.y - prey->pos.y); + attack = isInLine ? MONSTRO_SPIT : (Random() & 1 ? MONSTRO_HOP : MONSTRO_JUMP); + } + else + { + attack = (int)(Random() % 3); + if (npc.type == ENTITY_MONSTRO && npc.subtype == MONSTRO_NO_JUMP && attack == MONSTRO_JUMP) + attack = MONSTRO_SPIT; + } + if (npc.type == ENTITY_MONSTRO2 && npc.i2 == attack && random_unit() < REPEAT_REROLL_ODDS) + attack = (attack + (int)(Random() & 1) + 1) % 3; + return attack; +} + +// The idle pose rolls the next attack, only hops for a calm Delirium form. Monstro II's spit shows a tracer where its +// laser will fire. static void monstro_idle(Entity_NPC& npc) { if (npc.sprite.SetAnimation("Walk", SWITCH_KEEP_FRAME) && npc.sprite.animState.animData) @@ -99,31 +200,49 @@ static void monstro_idle(Entity_NPC& npc) npc.entityCollisionClass = ENTCOLL_ALL; npc.entityGridCollisionClass = GRIDCOLL_GROUND; - int attack = (int)(Random() % 3); - if (npc.subtype == MONSTRO_NO_JUMP && attack == MONSTRO_JUMP) attack = MONSTRO_SPIT; + int attack = attack_roll(npc); if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) attack = MONSTRO_HOP; npc.i2 = attack; switch (attack) { + case MONSTRO_JUMP: + return jump_start(npc); case MONSTRO_HOP: npc.state = NPC_STATE_MOVE; npc.PlaySound(SOUND_BOSS_LITE_ROAR, HOP_VOLUME, 2, false, 1); - return anim_restart(npc.sprite, "Walk"); - case MONSTRO_SPIT: - npc.state = NPC_STATE_ATTACK; - anim_restart(npc.sprite, "Taunt"); - npc.sprite.isFlipX = npc.pos.x - npc.GetPlayerTarget()->pos.x < 0; + npc_anim_restart(npc.sprite, "Walk"); + gish_sound_play(npc, SOUND_GISH_JUMP); + if (is_quick(npc)) npc.sprite.playbackSpeed = QUICK_PLAYBACK; return; - case MONSTRO_JUMP: - npc.state = NPC_STATE_JUMP; - npc.PlaySound(SOUND_BOSS_LITE_ROAR, 1, 2, false, 1); - return anim_restart(npc.sprite, "JumpUp"); } + + npc.state = NPC_STATE_ATTACK; + npc_anim_restart(npc.sprite, "Taunt"); + npc.sprite.isFlipX = npc.pos.x - npc.GetPlayerTarget()->pos.x < 0; + if (!is_monstro2(npc)) return; + + following_effect_spawn( + npc, {.offset = vector_make(0, MONSTRO_TRACER_HEIGHT), + .targetPosition = vector_from_angle(npc.sprite.isFlipX ? LASER_RIGHT_DEGREES : LASER_LEFT_DEGREES), + .color = MONSTRO_TRACER_COLOR, + .scale = MONSTRO_TRACER_SCALE, + .timeout = MONSTRO_TRACER_TIMEOUT}); } -// A hop toward its target's cell: pulled there while airborne, dust where it lands, and once the hop ends, another -// one time in two, else back to idle. +// A landing of Monstro II crushes the Suckers under it. +static void suckers_crush(Entity_NPC& npc) +{ + if (!is_monstro2(npc) || (npc.state != NPC_STATE_STOMP && npc.state != NPC_STATE_MOVE)) return; + if (!npc.sprite.animState.animData || !npc.sprite.animState.IsEventTriggered("Land")) return; + + for (Entity* sucker : entity_query_radius(npc.pos, CRUSH_RADIUS, QUERY_ENEMIES)) + if (sucker->type == ENTITY_SUCKER && sucker->variant == 0) + sucker->TakeDamage(MONSTRO_CRUSH_DAMAGE, 0, EntityRef(&npc), CRUSH_COUNTDOWN); +} + +// A hop toward its target's cell: pulled there while airborne (harder for the quick one), dust where it lands, and +// once the hop ends, another one time in two, else back to idle. static void monstro_hop(Entity_NPC& npc, const Vector& target) { if (vector_is_zero(npc.targetPosition)) target_cell_set(npc, target); @@ -160,9 +279,9 @@ static void monstro_hop(Entity_NPC& npc, const Vector& target) Vector toward = vector_sub(npc.targetPosition, npc.pos); float distance = vector_length(toward); if (distance == 0) distance = HOP_MIN_DISTANCE; + float pull = MONSTRO_HOP_PULL / distance * (is_quick(npc) ? QUICK_HOP_PULL : 1); if (npc.friction != 0) - npc.velocity = vector_add(npc.velocity, - vector_scale(toward, MONSTRO_HOP_PULL / distance * npc.speedMultiplier / npc.friction)); + npc.velocity = vector_add(npc.velocity, vector_scale(toward, pull * npc.speedMultiplier / npc.friction)); npc.friction *= MONSTRO_FRICTION; npc.sprite.isFlipX = npc.velocity.x > 0; return; @@ -177,7 +296,8 @@ static void monstro_hop(Entity_NPC& npc, const Vector& target) if (Random() & 1) { npc.PlaySound(SOUND_BOSS_LITE_ROAR, REHOP_VOLUME, 2, false, 1); - return anim_restart(npc.sprite, "Walk"); + npc_anim_restart(npc.sprite, "Walk"); + return gish_sound_play(npc, SOUND_GISH_JUMP); } npc.sprite.playbackSpeed = 1; npc.state = NPC_STATE_IDLE; @@ -194,11 +314,109 @@ static void monstro_jump(Entity_NPC& npc) npc.entityGridCollisionClass = GRIDCOLL_WALLS; npc.state = NPC_STATE_STOMP; npc.targetPosition = {}; - anim_restart(npc.sprite, "JumpDown"); + npc_anim_restart(npc.sprite, "JumpDown"); +} + +// Monstro II's Suckers off its second landing, at most four about (fewer for the quick one or a Delirium form), each +// from a random spot on its edge. +static void suckers_free(Entity_NPC& npc) +{ + if (g_game->room->GetAliveEnemiesCount() > SUCKER_ENEMY_LIMIT) return; + + int count = is_quick(npc) ? QUICK_SUCKERS : SUCKERS; + npc.PlaySound(SOUND_SUMMONSOUND, is_quick(npc) ? QUICK_SUCKER_VOLUME : SUCKER_VOLUME, 2, false, 1); + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + count = std::min(count, SUCKERS - npc.CountRelatedEntities(ENTITY_SUCKER, 0, nullptr)); + + for (int i = 0; i < count; i++) + { + uint32_t seed = Random(); + float angle = random_unit() * RANDOM_HALF_TURN; + angle += angle; + Vector spot = vector_make(std::cos(angle) * npc.size + npc.pos.x, std::sin(angle) * npc.size + npc.pos.y); + Entity* sucker = g_game->Spawn({.position = spot, + .velocity = vector_make(SUCKER_VELOCITIES[i][0], SUCKER_VELOCITIES[i][1]), + .spawner = &npc, + .type = ENTITY_SUCKER, + .seed = seed}); + sucker->isKillOnTouch = true; + } +} + +// A Clot off Gish's second landing, pushed one way, weakened. +static void clot_spawn(Entity_NPC& npc, float speed) +{ + uint32_t seed = Random(); + Entity* clot = g_game->Spawn({.position = npc.pos, + .velocity = vector_make(speed, 0), + .spawner = &npc, + .type = ENTITY_CLOTTY, + .variant = GISH_CLOT, + .seed = seed}); + clot->health -= CLOT_HEALTH_CUT; +} + +// Whether Gish has room for another Clot: few enemies about, and few Clots for a Delirium form. +static bool is_clot_allowed(Entity_NPC& npc) +{ + if (g_game->room->GetAliveEnemiesCount() > CLOT_ENEMY_LIMIT) return false; + return !npc.HasEntityFlags(FLAG_DELIRIUM_FORM) || + npc.CountRelatedEntities(ENTITY_CLOTTY, GISH_CLOT, nullptr) <= CLOT_LIMIT; +} + +// Gish's two Clots off its second landing, the second only while still allowed. +static void clots_free(Entity_NPC& npc) +{ + if (!is_clot_allowed(npc)) return; + + clot_spawn(npc, CLOT_SPEED); + if (!is_clot_allowed(npc)) return npc.PlaySound(SOUND_SUMMONSOUND, 1, 2, false, 1); + npc.PlaySound(SOUND_SUMMONSOUND, CLOT_PAIR_VOLUME, 2, false, 1); + clot_spawn(npc, -CLOT_SPEED); +} + +// What a landing's Shoot fires: Monstro's ring of 18, and for type 43 by which jump of the pair it was, Monstro II's +// eight shots or Suckers, Gish's creep or Clots. +static void stomp_shoot(Entity_NPC& npc) +{ + if (npc.type == ENTITY_MONSTRO) + { + npc.FireBossProjectiles(STOMP_SHOTS, {}, 0, ProjectileParams()); + return; + } + if (npc.type != ENTITY_MONSTRO2) return; + + if (npc.i1 == JUMP_SECOND) + { + if (is_gish(npc)) return clots_free(npc); + if (is_monstro2(npc)) suckers_free(npc); + return; + } + if (npc.i1 != JUMP_FIRST) return; + + if (is_gish(npc)) + { + auto* creep = static_cast(g_game->Spawn({.position = npc.pos, + .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = EFFECT_CREEP_BLACK, + .seed = Random()})); + creep->parent = &npc; + creep->sprite.scale = vector_make(GISH_CREEP_SCALE, GISH_CREEP_SCALE); + creep->timeout = 0; + creep->lifespan = 0; + creep->Update(); + return; + } + if (!is_monstro2(npc)) return; + + ProjectileParams params; + params.scale = STOMP_RING_SCALE; + npc.FireProjectiles(npc.pos, vector_make(MONSTRO_STOMP_RING_SPEED, 0), PROJECTILES_EIGHT, params); } // The fall onto its target's cell (a drop-in lands where the target is heading from): steered there in the air, then -// the landing shakes the ground, poofs blood and sprays 18 shots, and it rests. +// the landing shakes the ground, poofs blood (tar for Gish) and fires. Type 43 jumps twice in a row before it rests. static void monstro_stomp(Entity_NPC& npc, Vector target) { if (vector_is_zero(npc.targetPosition)) @@ -206,7 +424,7 @@ static void monstro_stomp(Entity_NPC& npc, Vector target) if (npc.i1 == JUMP_DROP_IN) { Entity* prey = npc.GetPlayerTarget(); - float gap = prey->size + npc.size + 5; + float gap = prey->size + npc.size + DROP_IN_GAP; target = vector_sub(target, vector_scale(vector_normalized(prey->velocity), gap)); } if (target_cell_set(npc, target) && npc.i1 == JUMP_DROP_IN) npc.pos = npc.targetPosition; @@ -220,8 +438,7 @@ static void monstro_stomp(Entity_NPC& npc, Vector target) npc.entityGridCollisionClass = GRIDCOLL_WALLS; Vector toward = vector_sub(npc.targetPosition, npc.pos); Vector pull = vector_add(vector_scale(toward, JUMP_PULL), vector_scale(vector_normalized(toward), JUMP_PUSH)); - if (npc.friction != 0) - npc.velocity = vector_add(npc.velocity, vector_scale(pull, npc.speedMultiplier / npc.friction)); + npc_push(npc, pull); } if (npc.sprite.animState.animData && npc.sprite.animState.isPlaying) @@ -233,46 +450,84 @@ static void monstro_stomp(Entity_NPC& npc, Vector target) { npc.PlaySound(SOUND_FORESTBOSS_STOMPS, 1, 2, false, 1); shockwave_make(npc.pos, SHOCKWAVE_AMPLITUDE, MONSTRO_SHOCKWAVE_SPEED, SHOCKWAVE_FRAMES); - npc.MakeBloodPoof(npc.pos, COLOR_DEFAULT, 1); + npc.MakeBloodPoof(npc.pos, is_gish(npc) ? GISH_POOF_COLOR : COLOR_DEFAULT, 1); } - if (npc.sprite.IsEventTriggered("Shoot")) npc.FireBossProjectiles(STOMP_SHOTS, {}, 0, ProjectileParams()); + if (npc.sprite.IsEventTriggered("Shoot")) stomp_shoot(npc); return; } npc.targetPosition = {}; - npc.i1 = 0; - npc.state = NPC_STATE_IDLE; - npc.sprite.playbackSpeed = 1; + if (npc.i1 == JUMP_DROP_IN) npc.i1 = JUMP_FIRST; + if (npc.type == ENTITY_MONSTRO2) npc.i1 ^= 1; + if (npc.i1 == JUMP_FIRST) + { + npc.state = NPC_STATE_IDLE; + npc.sprite.playbackSpeed = 1; + return; + } + + npc.state = NPC_STATE_JUMP; + npc.sprite.Play("JumpUp"); + gish_sound_play(npc, SOUND_GISH_JUMP_HIGH); + if (is_quick(npc)) npc.sprite.playbackSpeed = QUICK_PLAYBACK; } -// The spit: 13 shots lobbed at its target on Shoot with a blood cloud from its mouth, then idle once the taunt ends. +// The spit on Shoot: Monstro lobs 13 shots at its target with a blood cloud from its mouth, Monstro II fires its +// laser the way it faces, Gish lobs one big tar shot. Then idle once the taunt ends. static void monstro_spit(Entity_NPC& npc) { - if (npc.sprite.animState.animData) + if (!npc.sprite.animState.animData) { - if (npc.sprite.IsEventTriggered("Shoot")) + npc.state = NPC_STATE_IDLE; + return; + } + + if (npc.sprite.IsEventTriggered("Shoot")) + { + if (npc.type == ENTITY_MONSTRO) { npc.PlaySound(SOUND_BOSS_SPIT_BLOB_BARF, 1, 2, false, 1); - ProjectileParams params; - npc.FireBossProjectiles(SPIT_SHOTS, npc.GetPlayerTarget()->pos, 0, params); + npc.FireBossProjectiles(SPIT_SHOTS, npc.GetPlayerTarget()->pos, 0, ProjectileParams()); Entity_Effect* cloud = npc.MakeBloodCloud(npc.pos, SPIT_CLOUD_COLOR, SPIT_CLOUD_SCALE); cloud->posOffset = vector_make(0, SPIT_CLOUD_HEIGHT); } - if (npc.sprite.animState.animData && npc.sprite.animState.isPlaying) return; + else if (is_monstro2(npc)) + { + Entity_Laser* laser = + Entity_Laser::ShootAngle({.position = npc.pos, + .posOffset = vector_make(0, MONSTRO_LASER_HEIGHT), + .source = &npc, + .angleDegrees = npc.sprite.isFlipX ? LASER_RIGHT_DEGREES : LASER_LEFT_DEGREES, + .timeout = MONSTRO_LASER_TIMEOUT, + .variant = LASER_THICK_RED}); + laser->renderDepthOffset = LASER_DEPTH; + laser->Update(); + } + else if (is_gish(npc)) + { + Entity_Projectile* shot = + npc.FireBossProjectiles(1, npc.GetPlayerTarget()->pos, GISH_SHOT_ARC, ProjectileParams()); + shot->projectileFlags |= PROJECTILE_EXPLODE | PROJECTILE_GOO; + shot->fallingAccel -= GISH_SHOT_ACCEL; + shot->scale = GISH_SHOT_SCALE; + shot->fallingSpeed = shot->fallingSpeed * GISH_SHOT_SPEED - GISH_SHOT_LIFT; + shot->SetColor(GISH_SHOT_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + npc_sound_play(SOUND_GISH_SPIT, 1, 2, 1); + } } - npc.state = NPC_STATE_IDLE; + if (npc_anim_is_done(npc)) npc.state = NPC_STATE_IDLE; } -// 0046c0a0 NpcAI::ENTITY_MONSTRO: Monstro hops after its target, spits a spray of shots, or jumps off screen and -// stomps down in a ring of shots. Monstro II and Gish (type 43), which share it, and a Monstro a player controls are -// not reconstructed yet. +// 0046c0a0 NpcAI::ENTITY_MONSTRO: Monstro, Monstro II and Gish hop after their target, spit (Monstro II fires a laser +// when in line), or jump off screen and stomp down. Type 43 jumps twice in a row, freeing Suckers or Clots. A Monstro +// a player controls is not reconstructed yet. void boss_monstro_update(Entity_NPC& npc) { - if (npc.type != ENTITY_MONSTRO) reconstruction_missing("NpcAI::ENTITY_MONSTRO 0046c0a0: Monstro II and Gish"); if (npc.controllerID != -1) reconstruction_missing("NpcAI::ENTITY_MONSTRO 0046c0a0: a controlled Monstro"); npc.friction *= MONSTRO_FRICTION; Vector target = npc.CalcTargetPosition(0); + suckers_crush(npc); switch (npc.state) { diff --git a/src/boss_war.cpp b/src/boss_war.cpp new file mode 100644 index 0000000..22a999b --- /dev/null +++ b/src/boss_war.cpp @@ -0,0 +1,419 @@ +#include "boss_ai.h" +#include "entity_bomb.h" +#include "entity_config.h" +#include "entity_slot.h" +#include "npc_caves.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include + +// War's variants: War, Conquest (whose clones share its hurt), and War on foot once his horse is gone. The black War +// (subtype 1) throws Mega Troll Bombs and rings of shots. +constexpr int CONQUEST = 1; +constexpr int WAR_ON_FOOT = 10; +constexpr int WAR_BLACK = 1; + +// War's states: riding about (on foot, running), the burst of shots (on foot, the knockdown), the leap off screen that +// rains bombs or light beams, and the charge across the room. +constexpr int WAR_RIDE = NPC_STATE_MOVE; +constexpr int WAR_BURST = NPC_STATE_ATTACK; +constexpr int WAR_LEAP = NPC_STATE_JUMP; +constexpr int WAR_CHARGE = NPC_STATE_ATTACK2; + +constexpr uint64_t WAR_DISTRACTED = FLAG_CONFUSION | FLAG_FEAR | FLAG_SHRINK; +constexpr float WAR_FRICTION = 0.8f; +constexpr float WAR_UNHORSE_HEALTH = 0.5f; +constexpr float WAR_PACE_START = 0.5f; +constexpr float WAR_SHOT_SPEED = 10; +constexpr float HARD_SHOT_SPEED = 12; +constexpr int CLONE_HURT_COUNTDOWN = 30; + +// Riding about: now and then a burst near its target, a charge when far off or in line, or a roar and a leap. +constexpr uint32_t WAR_BURST_ODDS = 90; +constexpr float BURST_RANGE = 200; +constexpr uint32_t FAR_CHARGE_ODDS = 200; +constexpr float FAR_CHARGE_RANGE = 150; +constexpr uint32_t LINE_CHARGE_ODDS = 30; +constexpr float LINE_CHARGE_BAND = 20; +constexpr uint32_t LEAP_ODDS = 180; +constexpr float RIDE_ANIM_SPEED = 2; + +// The burst: eight shots (Conquest four homing big ones) on its fifth frame, over after 38. +constexpr int BURST_SHOOT_FRAME = 5; +constexpr int BURST_FRAMES = 38; +constexpr float WAR_BURST_HEIGHT = -45; +constexpr float BURST_FALL = 7; +constexpr float CONQUEST_SHOT_SCALE = 1.5f; + +// The leap: gone after 20 frames, from frame 32 a drop every 5 (five Troll Bombs, two Mega Troll Bombs for the black +// War, 15 beams for Conquest, every fifth at the target's lead), landing at a side 113 frames after the last. +constexpr int LEAP_VANISH_FRAME = 20; +constexpr int LEAP_DROP_START = 32; +constexpr int LEAP_DROP_EVERY = 5; +constexpr int LEAP_LAND_DELAY = 113; +constexpr int WAR_BOMBS = 5; +constexpr int BLACK_WAR_BOMBS = 2; +constexpr int CONQUEST_BEAMS = 15; +constexpr int WAR_BEAM_SUBTYPE = 2; +constexpr float WAR_BEAM_SIZE = 10; +constexpr float WAR_BEAM_MARGIN = 20; +constexpr float BEAM_SCATTER = 20; +constexpr float BEAM_LEAD = 0.2f; +constexpr int WAR_PATH_MARKER = 900; +constexpr float LEAP_SIDE_X = 320; + +// The charge: 18 a frame (a quarter faster in hard mode), wrapping round 200 past the far wall three times, each lap +// lower down. Conquest sends clones from the far side, the black War drops a Troll Bomb after a lap. +constexpr float WAR_CHARGE_SPEED = 18; +constexpr float HARD_CHARGE = 1.25f; +constexpr float WRAP_REACH = 200; +constexpr int CHARGE_LAPS = 3; +constexpr float LAP_DROP = 0.3f; +constexpr float LAP_FLOOR_MARGIN = 40; +constexpr float CLONE_INTERVAL = 8; +constexpr int CLONE_LAP = 2; +constexpr float CLONE_VOLUME = 0.6f; +constexpr float CLONE_TOP_MARGIN = 40; +constexpr float MEGA_SATAN_CLONE_TOP = 360; +constexpr float MEGA_SATAN_CLONE_SPAN_CUT = 80; +constexpr int CHARGE_BOMB_FRAMES = 40; + +// On foot: it runs at its target ever faster, and after taking 85 hurt since it last cried it is knocked down for 40 +// frames (the black War sprays a ring of six on the third). +constexpr float RUN_PACE_GAIN = 0.1f; +constexpr float RUN_PACE_KEEP = 0.955f; +constexpr float RUN_FRICTION_GAIN = 0.1f; +constexpr float RUN_SPEED_GAIN = 0.4f; +constexpr float RUN_SPEED_BASE = 0.5f; +constexpr int RUN_HEALTH_SETTLE = 10; +constexpr float KNOCKDOWN_HURT = 85; +constexpr float KNOCKDOWN_PACE_EASE = 5; +constexpr int KNOCKDOWN_FRAMES = 40; +constexpr int KNOCKDOWN_RING_FRAME = 3; +constexpr float KNOCKDOWN_RING_SHOTS = 6; + +// A state started on its animation's first frame. +static void attack_start(Entity_NPC& npc, int state, std::string_view anim) +{ + npc.state = state; + npc.stateFrame = 0; + npc_anim_restart(npc.sprite, anim); +} + +// The knockdown: War cries out, as when hurt off his horse. +static void knockdown_start(Entity_NPC& npc) +{ + attack_start(npc, WAR_BURST, "Cry"); + npc.PlaySound(SOUND_WAR_KNOCKDOWN, 1, 2, false, 1); +} + +// Below half health War loses his horse in a blood explosion and goes on on foot (a Delirium form keeps its health). +static void war_unhorse(Entity_NPC& npc) +{ + float maxHealth = npc.maxHitPoints; + g_game->Spawn({.position = npc.pos, + .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = EFFECT_BLOOD_EXPLOSION, + .seed = Random()}); + npc.Morph(npc.type, WAR_ON_FOOT, npc.subtype, -1); + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + { + ANM2::LoadDeliriumForm(npc.sprite, npc.type, npc.variant, true); + npc.maxHitPoints = maxHealth; + } + npc.aiFloat = WAR_PACE_START; + knockdown_start(npc); +} + +// Conquest passes the hurt it takes to its clones, unless the hurt came from a clone. +static void conquest_hurt_share(Entity_NPC& npc) +{ + if (npc.pendingDamage <= 0 || (npc.pendingDamageFlags & DAMAGE_CLONES)) return; + + for (Entity_NPC* clone : Entity_NPC::QueryNPCsGroup(npc.groupIdx)) + if (clone != &npc) clone->TakeDamage(npc.pendingDamage, DAMAGE_CLONES, EntityRef(), CLONE_HURT_COUNTDOWN); +} + +static float shot_speed_get() +{ + return game_is_hard_mode() ? HARD_SHOT_SPEED : WAR_SHOT_SPEED; +} + +// On foot: running at its target, faster the longer it runs, knocked down by enough hurt in a row. +static void war_run(Entity_NPC& npc) +{ + npc.AnimWalkFrame("WalkHori", "WalkVert", RIDE_ANIM_SPEED); + npc.aiFloat = (npc.aiFloat + RUN_PACE_GAIN) * RUN_PACE_KEEP; + npc.friction *= npc.aiFloat * RUN_FRICTION_GAIN + 1; + npc.pathfinder.FindGridPath(npc.CalcTargetPosition(0), npc.aiFloat * RUN_SPEED_GAIN + RUN_SPEED_BASE, + WAR_PATH_MARKER, DIRECT_PATH_FAR); + + if (npc.stateFrame++ < RUN_HEALTH_SETTLE) npc.v1.x = npc.health; + if (npc.health + KNOCKDOWN_HURT - npc.aiFloat * KNOCKDOWN_PACE_EASE < npc.v1.x) knockdown_start(npc); +} + +// The knockdown: it rests where it fell, its hurt counted from now, the black War spraying a ring. +static void war_knockdown(Entity_NPC& npc) +{ + npc.stateFrame++; + npc.v1.x = npc.health; + npc.aiFloat = WAR_PACE_START; + if (npc.stateFrame > KNOCKDOWN_FRAMES) + { + npc.state = WAR_RIDE; + npc.stateFrame = 0; + return; + } + if (npc.stateFrame != KNOCKDOWN_RING_FRAME || npc.subtype != WAR_BLACK) return; + + npc.FireProjectiles(npc.pos, vector_make(shot_speed_get(), KNOCKDOWN_RING_SHOTS), PROJECTILES_RING, + ProjectileParams()); + npc.PlaySound(SOUND_MONSTER_GRUNT_4, 1, 2, false, 1); +} + +// The charge's start: it yells, faces its target, and sets off from where it stands. +static void charge_start(Entity_NPC& npc, Vector toTarget) +{ + npc.PlaySound(SOUND_MONSTER_YELL_A, 1, 2, false, 1); + npc.sprite.isFlipX = toTarget.x < 0; + npc_anim_restart(npc.sprite, "DashStart"); + npc.targetPosition = npc.pos; + npc.state = WAR_CHARGE; + npc.i2 = (int)(Random() % 3); + npc.stateFrame = CHARGE_LAPS; + npc.PlaySound(SOUND_WAR_CHARGE, 1, 2, false, 1); +} + +// Riding about at random, and now and then a burst, a charge or a leap (none while distracted or for a calm Delirium +// form). +static void war_ride(Entity_NPC& npc, Vector toTarget) +{ + npc.pathfinder.MoveRandomlyBoss(STATUS_OBEYED); + npc.AnimWalkFrame("Walk", "Walk", RIDE_ANIM_SPEED); + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) return; + + float distance = vector_length(toTarget); + if (Random() % WAR_BURST_ODDS == 0 && distance < BURST_RANGE) return attack_start(npc, WAR_BURST, "Attack1"); + if ((Random() % FAR_CHARGE_ODDS == 0 && distance > FAR_CHARGE_RANGE) || + (Random() % LINE_CHARGE_ODDS == 0 && std::abs(toTarget.y) < LINE_CHARGE_BAND)) + { + if (!npc.HasEntityFlags(WAR_DISTRACTED)) charge_start(npc, toTarget); + return; + } + if (Random() % LEAP_ODDS != 0 || npc.HasEntityFlags(WAR_DISTRACTED)) return; + + npc.PlaySound(SOUND_MONSTER_ROAR_0 + (int)(Random() & 3), 1, 2, false, 1); + attack_start(npc, WAR_LEAP, "Attack2"); +} + +// The burst: War's eight high arcing shots, Conquest's four big homing ones. +static void war_burst(Entity_NPC& npc) +{ + if (npc.stateFrame++ != BURST_SHOOT_FRAME) + { + if (npc.stateFrame > BURST_FRAMES) npc.state = WAR_RIDE; + return; + } + + ProjectileParams params; + params.heightModifier = WAR_BURST_HEIGHT; + params.fallingSpeedModifier = BURST_FALL; + if (npc.variant == CONQUEST) + { + params.bulletFlags |= PROJECTILE_SMART; + params.scale = CONQUEST_SHOT_SCALE; + } + npc.FireProjectiles(npc.pos, vector_make(shot_speed_get(), 0), + npc.variant == CONQUEST ? PROJECTILES_PLUS : PROJECTILES_EIGHT, params); + npc.PlaySound(SOUND_MONSTER_GRUNT_4, 1, 2, false, 1); +} + +// One drop of the leap: a light beam at a free spot (every fifth at the target's lead) for Conquest, a Troll Bomb +// (Mega for the black War) at a random free spot for War. Paths keep off it. +static void leap_drop(Entity_NPC& npc, int index) +{ + Room& room = *g_game->room; + Vector spot; + if (npc.variant == CONQUEST) + { + spot = room_free_pickup_position_find({.position = room.GetRandomPosition(WAR_BEAM_MARGIN)}); + Vector scatter = random_direction(); + spot = vector_add(spot, vector_scale(scatter, random_unit() * BEAM_SCATTER)); + if ((index + 1) % LEAP_DROP_EVERY == 0) + { + Entity* prey = npc.GetPlayerTarget(); + float lead = vector_length(vector_sub(npc.pos, prey->pos)) * BEAM_LEAD; + spot = room.GetClampedPositionImpl(vector_add(prey->pos, vector_scale(prey->velocity, lead)), + WAR_BEAM_MARGIN, WAR_BEAM_MARGIN, WAR_BEAM_MARGIN, WAR_BEAM_MARGIN); + } + Entity* beam = g_game->Spawn({.position = spot, + .spawner = &npc, + .subType = WAR_BEAM_SUBTYPE, + .type = ENTITY_EFFECT, + .variant = EFFECT_CRACK_THE_SKY, + .seed = Random()}); + beam->SetSize(WAR_BEAM_SIZE, vector_make(-1, -1), -1); + beam->Update(); + } + else + { + spot = room_pickup_position_random(false, false); + g_game->Spawn({.position = spot, + .spawner = &npc, + .type = ENTITY_BOMB, + .variant = npc.subtype == 0 ? BOMB_TROLL : BOMB_SUPERTROLL, + .seed = Random()}); + } + room.SetGridPath(room.GetGridIndex(spot), WAR_PATH_MARKER); +} + +// The leap: off screen once airborne, its drops in turn, then back from the side away from its target, charging. +static void war_leap(Entity_NPC& npc) +{ + int frame = npc.stateFrame++; + if (npc.stateFrame > LEAP_VANISH_FRAME) + { + npc.entityCollisionClass = ENTCOLL_NONE; + npc.shadowSize = 0; + } + + int drops = npc.variant == CONQUEST ? CONQUEST_BEAMS : npc.subtype == 0 ? WAR_BOMBS : BLACK_WAR_BOMBS; + int wave = frame - LEAP_DROP_START; + if (wave >= 0 && wave % LEAP_DROP_EVERY == 0 && wave / LEAP_DROP_EVERY < drops) + leap_drop(npc, wave / LEAP_DROP_EVERY); + if (npc.stateFrame <= drops * LEAP_DROP_EVERY + LEAP_LAND_DELAY) return; + + Room& room = *g_game->room; + npc.entityCollisionClass = ENTCOLL_ALL; + npc.state = WAR_CHARGE; + npc.entityGridCollisionClass = GRIDCOLL_WALLS_Y; + npc.shadowSize = npc.config->shadowSize; + npc.targetPosition = npc.pos; + npc.stateFrame = 0; + bool isFromRight = npc.GetPlayerTarget()->pos.x <= LEAP_SIDE_X; + npc.pos.x = isFromRight ? room.bottomRightPos.x + WRAP_REACH : room.topLeftPos.x - WRAP_REACH; + npc.sprite.isFlipX = isFromRight; +} + +// A Conquest clone charging in from the far side at one of three heights in turn, sharing its health and group. +static void conquest_clone_spawn(Entity_NPC& npc) +{ + Room& room = *g_game->room; + npc.PlaySound(SOUND_MONSTER_YELL_A, CLONE_VOLUME, 2, false, 1); + float x = npc.velocity.x <= 0 ? room.bottomRightPos.x + WRAP_REACH : room.topLeftPos.x - WRAP_REACH; + float half = (room.bottomRightPos.y - room.topLeftPos.y) * 0.5f; + float y = random_unit() * half + (room.topLeftPos.y + CLONE_TOP_MARGIN); + y += (float)(npc.i2++ % 3) * half * 0.5f; + if (room.bossId == BOSS_ID_MEGA_SATAN) + y = random_unit() * (room.bottomRightPos.y - HORSEMAN_MEGA_SATAN_FLOOR - MEGA_SATAN_CLONE_SPAN_CUT) + + MEGA_SATAN_CLONE_TOP; + + auto* clone = static_cast(g_game->Spawn( + {.position = vector_make(x, y), .spawner = &npc, .type = npc.type, .variant = npc.variant, .seed = Random()})); + clone->state = npc.state; + clone->stateFrame = CHARGE_LAPS; + clone->sprite.isFlipX = npc.sprite.isFlipX; + clone->parent = &npc; + clone->AddEntityFlags(FLAG_DONT_COUNT_BOSS_HP); + clone->health = npc.health; + clone->entityGridCollisionClass = GRIDCOLL_NONE; + clone->groupIdx = npc.groupIdx; + clone->Update(); +} + +// The charge: across the room and round past the far wall, each lap lower (back up from the floor), until it passes +// where it set off after its last lap. A Conquest clone is gone once it wraps. +static void war_charge(Entity_NPC& npc) +{ + Room& room = *g_game->room; + npc.entityGridCollisionClass = GRIDCOLL_WALLS_Y; + if (npc.variant == CONQUEST && npc.GetIntervalTicks(CLONE_INTERVAL, 0) && npc.spawnerType != npc.type && + npc.stateFrame == CLONE_LAP) + conquest_clone_spawn(npc); + + float left = room.topLeftPos.x - WRAP_REACH; + float right = room.bottomRightPos.x + WRAP_REACH; + npc.velocity.x = npc.sprite.isFlipX ? -WAR_CHARGE_SPEED : WAR_CHARGE_SPEED; + bool isWrapped = npc.sprite.isFlipX ? npc.pos.x < left : npc.pos.x > right; + if (isWrapped) + { + npc.pos.x = npc.sprite.isFlipX ? right : left; + npc.i1 = 1; + if (npc.variant != CONQUEST) npc.PlaySound(SOUND_WAR_CHARGE, 1, 2, false, 1); + } + if (game_is_hard_mode()) npc.velocity.x *= HARD_CHARGE; + if (isWrapped && npc.spawnerType == npc.type && npc.variant == CONQUEST) npc.Remove(); + + if (npc_anim_is_done(npc)) npc.sprite.Play("Dash"); + if (npc_anim_is_done(npc) || npc.sprite.GetAnimation() != "Dash") npc.velocity.x = 0; + + float top = room.bossId == BOSS_ID_MEGA_SATAN ? HORSEMAN_MEGA_SATAN_FLOOR : room.topLeftPos.y; + float span = room.bottomRightPos.y - top; + if (npc.stateFrame < 1) + { + float vx = npc.velocity.x; + if ((vx < 0 && npc.pos.x < npc.targetPosition.x) || (vx > 0 && npc.pos.x > npc.targetPosition.x)) + npc.state = WAR_RIDE; + } + else if (isWrapped) + { + npc.pos.y += span * LAP_DROP; + if (npc.pos.y > room.bottomRightPos.y - LAP_FLOOR_MARGIN) npc.pos.y -= span * LAP_DROP * 3; + npc.stateFrame--; + } + + if (npc.i1 == 0 || !npc.IsFrame(CHARGE_BOMB_FRAMES, 0) || npc.variant != 0 || npc.subtype != WAR_BLACK) return; + g_game->Spawn({.position = npc.pos, .spawner = &npc, .type = ENTITY_BOMB, .variant = BOMB_TROLL, .seed = Random()}); + npc.i1 = 0; +} + +// 00458870 NpcAI::ENTITY_WAR: War and Conquest ride about, burst shots, charge across the room and leap off screen +// to rain Troll Bombs (Conquest light beams and clones that share its hurt). Below half health War runs on foot. +void boss_war_update(Entity_NPC& npc) +{ + npc.friction *= WAR_FRICTION; + if (npc.state == NPC_STATE_INIT) + { + npc.state = WAR_RIDE; + npc.i1 = 0; + npc.stateFrame = 0; + npc.aiFloat = WAR_PACE_START; + if (npc.variant == CONQUEST) npc.groupIdx = npc.index; + return; + } + + if (npc.variant == 0 && npc.health / npc.maxHitPoints < WAR_UNHORSE_HEALTH) war_unhorse(npc); + else if (npc.variant == CONQUEST) conquest_hurt_share(npc); + + Room& room = *g_game->room; + Vector toTarget = vector_sub(npc.GetPlayerTarget()->pos, npc.pos); + if (npc.state != WAR_CHARGE) npc.pos.x = std::min(std::max(npc.pos.x, room.topLeftPos.x), room.bottomRightPos.x); + + if (npc.variant == WAR_ON_FOOT) + { + npc.entityCollisionClass = ENTCOLL_ALL; + npc.entityGridCollisionClass = GRIDCOLL_GROUND; + if (npc.state == WAR_RIDE) war_run(npc); + else if (npc.state == WAR_BURST) war_knockdown(npc); + return horseman_mega_satan_hold(npc); + } + + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + switch (npc.state) + { + case WAR_RIDE: + war_ride(npc, toTarget); + break; + case WAR_BURST: + war_burst(npc); + break; + case WAR_LEAP: + war_leap(npc); + break; + case WAR_CHARGE: + war_charge(npc); + break; + } + horseman_mega_satan_hold(npc); +} diff --git a/src/entity.h b/src/entity.h index dbada0b..9522063 100644 --- a/src/entity.h +++ b/src/entity.h @@ -30,6 +30,7 @@ enum EntityType : int ENTITY_SHOPKEEPER = 17, ENTITY_ATTACKFLY = 18, ENTITY_LARRYJR = 19, + ENTITY_MONSTRO = 20, ENTITY_MAGGOT = 21, ENTITY_HIVE = 22, ENTITY_CHARGER = 23, @@ -51,6 +52,7 @@ enum EntityType : int ENTITY_GUTS = 40, ENTITY_KNIGHT = 41, ENTITY_STONEHEAD = 42, + ENTITY_MONSTRO2 = 43, ENTITY_POKY = 44, ENTITY_MOM = 45, ENTITY_SLOTH = 46, @@ -74,6 +76,9 @@ enum EntityType : int ENTITY_PESTILENCE = 64, ENTITY_WAR = 65, ENTITY_DEATH = 66, + ENTITY_DUKE = 67, + ENTITY_PEEP = 68, + ENTITY_LOKI = 69, ENTITY_FISTULA_BIG = 71, ENTITY_FISTULA_MEDIUM = 72, ENTITY_FISTULA_SMALL = 73, @@ -85,6 +90,8 @@ enum EntityType : int ENTITY_GEMINI = 79, ENTITY_MOTER = 80, ENTITY_FALLEN = 81, + ENTITY_HEADLESS_HORSEMAN = 82, + ENTITY_HORSEMAN_HEAD = 83, ENTITY_SATAN = 84, ENTITY_SPIDER = 85, ENTITY_KEEPER = 86, @@ -143,10 +150,14 @@ enum EntityType : int ENTITY_IMP = 259, ENTITY_THE_HAUNT = 260, ENTITY_DINGLE = 261, + ENTITY_MEGA_MAW = 262, ENTITY_GATE = 263, ENTITY_MEGA_FATTY = 264, ENTITY_CAGE = 265, ENTITY_MAMA_GURDY = 266, + ENTITY_DARK_ONE = 267, + ENTITY_ADVERSARY = 268, + ENTITY_MR_FRED = 270, ENTITY_POLYCEPHALUS = 269, ENTITY_URIEL = 271, ENTITY_GABRIEL = 272, @@ -203,6 +214,9 @@ enum EntityType : int ENTITY_ROCK_SPIDER = 818, ENTITY_FLY_BOMB = 819, ENTITY_BLASTER = 821, + ENTITY_DANNY = 820, + ENTITY_GURGLE = 87, + ENTITY_NEST = 205, ENTITY_QUAKEY = 823, ENTITY_GYRO = 824, ENTITY_FIRE_WORM = 825, @@ -219,11 +233,14 @@ enum EntityType : int ENTITY_DARK_ESAU = 866, ENTITY_DRIP = 870, ENTITY_SPLURT = 871, + ENTITY_CLOGGY = 872, + ENTITY_CLOG = 914, ENTITY_ORBIT_SPAWNER = 873, ENTITY_GRUDGE = 877, ENTITY_NEEDLE = 881, ENTITY_CULTIST = 885, ENTITY_VIS_FATTY = 886, + ENTITY_CLICKETY_CLACK = 889, ENTITY_BALL_AND_CHAIN = 893, ENTITY_REAP_CREEP = 900, ENTITY_VISAGE = 903, @@ -346,6 +363,7 @@ enum DamageFlag : uint64_t DAMAGE_RED_HEARTS = 1ull << 5, DAMAGE_COUNTDOWN = 1ull << 6, DAMAGE_SPIKES = 1ull << 7, + DAMAGE_CLONES = 1ull << 8, DAMAGE_POOP = 1ull << 9, DAMAGE_DEVIL = 1ull << 10, DAMAGE_ISAAC_HURT = 1ull << 11, @@ -357,6 +375,7 @@ enum DamageFlag : uint64_t DAMAGE_IV_BAG = 1ull << 18, DAMAGE_PITFALL = 1ull << 19, DAMAGE_CHEST = 1ull << 20, + DAMAGE_FAKE = 1ull << 21, DAMAGE_BOOGER = 1ull << 22, DAMAGE_SPAWN_BLACK_HEART = 1ull << 23, DAMAGE_CRUSH = 1ull << 24, @@ -364,7 +383,6 @@ enum DamageFlag : uint64_t DAMAGE_SPAWN_RED_HEART = 1ull << 26, DAMAGE_SPAWN_COIN = 1ull << 27, DAMAGE_NO_PENALTIES = 1ull << 28, - DAMAGE_CLONES = 1ull << 29, DAMAGE_SPAWN_TEMP_HEART = 1ull << 29, DAMAGE_IGNORE_ARMOR = 1ull << 30, DAMAGE_SPAWN_CARD = 1ull << 31, diff --git a/src/entity_combat.cpp b/src/entity_combat.cpp index b9fe239..dba77d5 100644 --- a/src/entity_combat.cpp +++ b/src/entity_combat.cpp @@ -67,7 +67,6 @@ constexpr int BABY_CROW = 12; constexpr int BLUE_FLY_MAX = 30; // The effects the combat code spawns (Lua's EffectVariant). -constexpr int EFFECT_BISHOP_SHIELD = 160; 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 diff --git a/src/entity_effect.cpp b/src/entity_effect.cpp index 7914bb7..a181159 100644 --- a/src/entity_effect.cpp +++ b/src/entity_effect.cpp @@ -31,17 +31,14 @@ constexpr std::array WAVE_CHAIN_CREEPS = {53, 44, 46, 45, 32, 204}; constexpr int FAMILIAR_CREEP_WAVE = 125; constexpr int EFFECT_BLACK_POWDER = 92; -constexpr int EFFECT_BOOMERANG = 60; constexpr int EFFECT_TIMER = 119; constexpr int EFFECT_ENEMY_SOUL = 179; -constexpr int EFFECT_REDEMPTION = 185; // The Hourglass slows Hush's lasers from full speed to half as its effect's cooldown runs from 0 to 30. constexpr float HOURGLASS_COOLDOWN_SPAN = 30; constexpr float HOURGLASS_SLOWEST = 0.5f; constexpr float PAUSE_VELOCITY_DECAY = 0.6f; -constexpr int SOUND_BOOMERANG_LOOP = 837; constexpr int SOUND_PORTAL_ENTITY_LOOP = 846; constexpr int SOUND_CHAIN_LOOP = 503; @@ -97,8 +94,9 @@ static const EffectBehaviour* behaviour_find(int variant) { static const std::array TABLE = [] { std::array table{}; - for (auto group : {ambient_effect_behaviours(), hazard_effect_behaviours(), floor_effect_behaviours(), - beam_effect_behaviours(), player_effect_behaviours(), mines_effect_behaviours(), + for (auto group : {item_effect_behaviours(), ambient_effect_behaviours(), hazard_effect_behaviours(), + floor_effect_behaviours(), beam_effect_behaviours(), player_effect_behaviours(), + mines_effect_behaviours(), trail_effect_behaviours(), spike_effect_behaviours(), boss_effect_behaviours(), weapon_effect_behaviours(), passive_effect_behaviours(), alt_effect_behaviours(), std::span(TIMER_BEHAVIOURS)}) @@ -127,6 +125,13 @@ static float angle_wrapped(float angle) return angle; } +// 00a10210 (Vector::Lerp) Moves a vector t of the way to a target. +void vector_lerp(Vector& v, Vector target, float t) +{ + v.x = (target.x - v.x) * t + v.x; + v.y = (target.y - v.y) * t + v.y; +} + // 00682a50 An angle in degrees turned toward a target by at most a step, reaching it when within the step. float angle_approach(float current, float target, float maxStep) { @@ -336,12 +341,17 @@ void Entity_Effect::Remove() Entity::Remove(); } -// 0060c370 Glowing Hourglass removes a timer, and sets Redemption back to idle. +// 0060c370 Glowing Hourglass removes a timer, and sets Redemption back to waiting, its idle restarted unless shown. void Entity_Effect::TriggerGlowingHourglass() { - if (variant == EFFECT_REDEMPTION) - reconstruction_missing("Entity_Effect::TriggerGlowingHourglass 0060c370: Redemption's idle restart"); if (variant == EFFECT_TIMER) Remove(); + if (variant != EFFECT_REDEMPTION) return; + + state = 0; + if (sprite.animState.animData && sprite.GetAnimation() == "Idle") return; + if (!sprite.SetAnimation("Idle", SWITCH_KEEP_FRAME)) return; + sprite.animState.Rewind(); + sprite.animState.isPlaying = true; } // 0060abb0 Gives an enemy soul to the player it flew to and stops a hidden Anima chain's sound, then lets go of its @@ -367,12 +377,6 @@ void Entity_Effect::FollowParent(Entity* newParent) // The rest of Entity_Effect is not reconstructed yet. -// 00435290 -void Entity_Effect::render_player_target(const Vector&, int) -{ - reconstruction_missing("Entity_Effect::render_player_target 00435290"); -} - // 005d2a70 void Entity_Effect::update_mr_me() { diff --git a/src/entity_effect.h b/src/entity_effect.h index a60ad38..fb3a2ab 100644 --- a/src/entity_effect.h +++ b/src/entity_effect.h @@ -36,6 +36,11 @@ template EffectUpdateEnd effect_finishing(Entit return EFFECT_UPDATE_FINISH; } +// The pulling effect's subtypes: the purple, the grey pulsing and the red pulsing champion's. +constexpr int PULLING_PURPLE = 0; +constexpr int PULLING_GREY = 1; +constexpr int PULLING_RED = 2; + // The effect variants several files name (Lua's EffectVariant). enum EffectVariant : int { @@ -46,6 +51,9 @@ enum EffectVariant : int EFFECT_BLOOD_PARTICLE = 5, EFFECT_DEVIL = 6, EFFECT_BLOOD_SPLAT = 7, + EFFECT_MONSTROS_TOOTH = 28, + EFFECT_WOMB_TELEPORT = 82, + EFFECT_MEGA_BEAN_EXPLOSION = 202, EFFECT_ANGEL = 9, EFFECT_BLUE_FLAME = 10, EFFECT_BULLET_POOF = 11, @@ -123,6 +131,7 @@ enum EffectVariant : int EFFECT_CREEP_SLIPPERY_BROWN = 94, EFFECT_HUSH_LASER = 96, EFFECT_WATER_SPLASH = 99, + EFFECT_HUSH_ASHES = 100, EFFECT_HUSH_LASER_UP = 101, EFFECT_BULLET_POOF_HUSH = 102, EFFECT_FIREWORKS = 104, @@ -173,14 +182,65 @@ enum EffectVariant : int EFFECT_PURGATORY = 189, EFFECT_ANIMA_CHAIN = 193, EFFECT_CREEP_LIQUID_POOP = 195, + EFFECT_DARK_SNARE = 194, + EFFECT_CLEAVER_SLASH = 176, + EFFECT_MR_ME = 108, + EFFECT_DEAD_BIRD = 197, EFFECT_GENERIC_TRACER = 198, + EFFECT_UMBILICAL_CORD_HELPER = 201, EFFECT_PLAYER_CREEP_YELLOW = 204, EFFECT_MAMA_MEGA_EXPLOSION = 127, EFFECT_CHAIN_GIB = 163, EFFECT_BIG_ROCK_EXPLOSION = 149, EFFECT_BIG_CRACKWAVE = 150, EFFECT_BIG_ATTRACT = 151, - EFFECT_FIRE_WAVE = 148 + EFFECT_FIRE_WAVE = 148, + EFFECT_BOOMERANG = 60, + EFFECT_FRIEND_BALL = 81, + EFFECT_BLACK_HOLE = 107, + EFFECT_LADDER = 8, + EFFECT_XRAY_WALL = 36, + EFFECT_STARFLASH = 40, + EFFECT_BUTTERFLY = 69, + EFFECT_BAR_PARTICLE = 75, + EFFECT_SPEAR_OF_DESTINY = 83, + EFFECT_ULTRA_GREED_FOOTPRINT = 89, + EFFECT_ULTRA_GREED_BLING = 103, + EFFECT_BROWN_CLOUD = 105, + EFFECT_FART_RING = 106, + EFFECT_DEATH_SKULL = 109, + EFFECT_OPTION_LINE = 128, + EFFECT_UNUSED_129 = 129, + EFFECT_LEECH_EXPLOSION = 130, + EFFECT_MAGGOT_EXPLOSION = 131, + EFFECT_WORMWOOD_HOLE = 137, + EFFECT_FARTWAVE = 143, + EFFECT_HORNFEL_ROOM_CONTROLLER = 152, + EFFECT_BISHOP_SHIELD = 160, + EFFECT_HERETIC_PENTAGRAM = 162, + EFFECT_SIREN_RING = 164, + EFFECT_CHARM_EFFECT = 165, + EFFECT_CHAIN_LIGHTNING = 167, + EFFECT_DOGMA_DEBRIS = 170, + EFFECT_DOGMA_BLACKHOLE = 171, + EFFECT_DOGMA_ORB = 172, + EFFECT_CRACKED_ORB_POOF = 173, + EFFECT_SHOP_SPIKES = 174, + EFFECT_LAVA_SPAWNER = 181, + EFFECT_BIG_KNIFE = 182, + EFFECT_MOTHER_SHOCKWAVE = 183, + EFFECT_WORM_FRIEND_SNARE = 184, + EFFECT_REDEMPTION = 185, + EFFECT_HUNGRY_SOUL = 186, + EFFECT_EXPLOSION_WAVE = 187, + EFFECT_DIVINE_INTERVENTION = 188, + EFFECT_MOTHER_TRACER = 190, + EFFECT_PICKUP_GHOST = 191, + EFFECT_FISSURE_SPAWNER = 192, + EFFECT_GROUND_GLOW = 196, + EFFECT_ULTRA_DEATH_SCYTHE = 199, + EFFECT_BULLET_POOF_STATIC = 200, + EFFECT_GUN = 205 }; // Construction and destruction (005cd9f0, 005cd960) are the defaults, the extra data shared with its other holders. @@ -228,7 +288,6 @@ struct Entity_Effect : Entity bool CanShutDoors() override; bool HandleCollision(Entity* collider, bool isLow) override; - void render_player_target(const Vector& offset, int segmentMode); void SetTimeout(int frames); void SetRadii(float newMinRadius, float newMaxRadius); void FollowParent(Entity* parent); @@ -251,6 +310,7 @@ std::span beam_effect_behaviours(); std::span spike_effect_behaviours(); std::span boss_effect_behaviours(); std::span alt_effect_behaviours(); +std::span item_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. @@ -263,6 +323,7 @@ void layer_additive_set(LayerState& layer); constexpr float DEGREES_PER_TURN = 360; float angle_approach(float current, float target, float maxStep); +void vector_lerp(Vector& v, Vector target, float t); float lerp_clamped(float value, float inFirst, float inLast, float outFirst, float outLast); // A color tinted, with no colorize or offset (Color::Reset and SetTint). diff --git a/src/entity_effect_ambient.cpp b/src/entity_effect_ambient.cpp index bab4bca..4899504 100644 --- a/src/entity_effect_ambient.cpp +++ b/src/entity_effect_ambient.cpp @@ -20,6 +20,9 @@ #include #include +// The grey pulsing champion's pull fades with its slow pulse. +constexpr float PULLING_PULSE_RATE = 0.1f; + constexpr int ROOM_BARREN_TYPE = 19; constexpr int SOUND_DROPLET_SPLASH = 397; constexpr int SOUND_SPAWNER_SUMMON = 265; @@ -161,12 +164,6 @@ static float angle_normalized(float angle) return angle; } -// Vector::Lerp a10210: moves a vector t of the way to a target. -static void vector_lerp(Vector& v, Vector target, float t) -{ - v.x = (target.x - v.x) * t + v.x; - v.y = (target.y - v.y) * t + v.y; -} static float distance_squared(Vector a, Vector b) { @@ -856,6 +853,26 @@ static void spawner_update(Entity_Effect& spawner) flags &= ~ROOM_DESCRIPTOR_FLAG_CLEAR; } +// Init's pulling case: the pull around a magnetized enemy or a pulling champion plays Effect (Effect2 for any +// subtype), under everything but in a crawlspace. +static void pulling_init(Entity_Effect& pull) +{ + pull.sprite.Play(pull.subtype != 0 ? "Effect2" : "Effect"); + if (g_game->room->roomType != ROOM_DUNGEON) pull.sortingLayer = SORTING_BACKGROUND; +} + +// 005f465f (Update's pulling case) The pull stays on its parent, the grey champion's fading out at the top of its +// slow pulse, and goes once the parent is gone. +static void pulling_update(Entity_Effect& pull) +{ + if (!pull.parent) return pull.Remove(); + + pull.pos = pull.parent->pos; + if (pull.subtype != PULLING_GREY) return; + float pulse = std::clamp(std::sin((float)g_game->room->GetFrameCount() * PULLING_PULSE_RATE) + 0.5f, 0.0f, 1.0f); + pull.sprite.color._tint[3] = 1 - pulse; +} + // The pieces the room keeps through overwrites: lights, decorations, door outlines and ladders. static void kept_init(Entity_Effect& effect) { @@ -1981,6 +1998,8 @@ constexpr auto AMBIENT_BEHAVIOURS = std::to_array({ {EFFECT_RAIN_DROP, rain_drop_init, effect_finishing, nullptr}, {EFFECT_BACKDROP_DECORATION, kept_init, backdrop_decoration_update, nullptr}, {EFFECT_DOOR_OUTLINE, kept_init, nullptr, nullptr}, + {EFFECT_HUSH_ASHES, nullptr, nullptr, nullptr}, + {EFFECT_PULLING_EFFECT, pulling_init, effect_finishing, nullptr}, {EFFECT_TALL_LADDER, kept_init, effect_finishing, nullptr}, {EFFECT_HEAVEN_LIGHT_DOOR, heaven_door_init, effect_finishing, heaven_door_render}, {EFFECT_TADPOLE, tadpole_init, effect_finishing, nullptr}, diff --git a/src/entity_effect_boss.cpp b/src/entity_effect_boss.cpp index afadf01..7275568 100644 --- a/src/entity_effect_boss.cpp +++ b/src/entity_effect_boss.cpp @@ -100,30 +100,6 @@ static void crack_update(Entity_Effect& crack) 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(); -} - // Hush's lasers: the one hunting his target (96) every 10 frames aims 40 to one side of where its target will be in 5, // pushing on at the room's speed (plus 1.1 of a player target's speed) under friction 0.8. Every 2 frames it hurts // players (or, fired by a charmed or friendly Hush, enemies) for 2, and every 5 it leaves blue creep. @@ -238,7 +214,6 @@ static void hush_beam_update(Entity_Effect& beam) // Hush's lasers and the poof of his shots have no Init case of their own. 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}, {EFFECT_HUSH_LASER, nullptr, effect_finishing, nullptr}, {EFFECT_HUSH_LASER_UP, nullptr, effect_finishing, nullptr}, diff --git a/src/entity_effect_items.cpp b/src/entity_effect_items.cpp new file mode 100644 index 0000000..d95b662 --- /dev/null +++ b/src/entity_effect_items.cpp @@ -0,0 +1,1353 @@ +#include "boss_ai.h" +#include "entity_bomb.h" +#include "entity_effect_combat.h" +#include "entity_familiar.h" +#include "entity_npc.h" +#include "entity_pickup.h" +#include "entity_tear.h" +#include "entity_laser.h" +#include "entity_effect.h" +#include "entity_list.h" +#include "entity_player.h" +#include "entity_projectile.h" +#include "game.h" +#include "grid_entity_door.h" +#include "level.h" +#include "manager.h" +#include "npc_ai.h" +#include "npc_basement.h" +#include "room.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include "weapon.h" +#include +#include + +// The effects of items, cards and pickups, and the small effects of no other group: the fires, Mom's stomping foot, +// the shop's spikes, the souls and skulls, and the many that only play their animation. + +// Mom's foot (High Priestess): it follows its target (or its target position) a tenth of the way each frame until frame +// 15 (27 over an enemy), then stomps on frame 27 for its damage around 60, 33 at versus mode's damage scale. +constexpr int FOOT_TRACK_FRAMES = 15; +constexpr int FOOT_STOMP_FRAME = 27; +constexpr int FOOT_RENDER_Z = 1000; +constexpr float FOOT_DAMAGE = 300; +constexpr float FOOT_VERSUS_DAMAGE = 33 / 0.2f; +constexpr float FOOT_PULL = 0.1f; +constexpr float FOOT_RADIUS = 60; +constexpr float FOOT_FRICTION = 0.8f; +constexpr ColorMod FOOT_POOF_COLOR = {{0.62f, 0.62f, 0.62f, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}}; + +// A fire (the blue flame, Hot Bombs' and the Red Candle's): it slows, forgets what it burned every 5 frames and burns +// what it touches for its damage scaled by its size (half at least). The item fires last 300 frames and lose a quarter +// of their size for each hit or shot put out, and one burning on an enemy grows with the enemy's health from 1 to 5. +// A player's blue flame fades over its last 60 frames, hisses louder at stronger enemies and dims over its last 10. +constexpr float FIRE_FRICTION = 0.95f; +constexpr int FIRE_HIT_RESET_FRAMES = 5; +constexpr int FIRE_LIFESPAN = 300; +constexpr int FIRE_HIT_COUNTDOWN = 30; +constexpr float FIRE_SHRINK = 0.25f; +constexpr float FIRE_MIN_DAMAGE_SCALE = 0.5f; +constexpr float FIRE_ENEMY_REACH = 5; +constexpr float FIRE_ENEMY_HEALTH_LOW = 1; +constexpr float FIRE_ENEMY_HEALTH_HIGH = 5; +constexpr float FIRE_STEAM_VOLUME = 0.85f; +constexpr int FLAME_FADE_FRAMES = 60; +constexpr int FLAME_DIM_FRAMES = 10; +constexpr float FLAME_HISS_VOLUME = 0.5f; +constexpr float FLAME_HISS_PER_HEALTH = 0.05f; +constexpr int FLAME_HISS_DELAY = 10; + +// The shop's spikes under a ware priced in spikes sink once their ware is gone, and new ones replace those on their +// cell (or leave a blood stain). +constexpr float SHOP_SPIKES_DEPTH = -100; +constexpr uint32_t SHOP_SPIKES_STAIN_SHIFT = 18; + +// The fire jet hisses as it lights and burns on frames 2 and 4 for its damage within 20 (players take 2 from 30). +constexpr float FIRE_JET_RADIUS = 20; +constexpr float FIRE_JET_PLAYER_THRESHOLD = 30; + +// The Death's List skull rides 30 above its target without an overlay null, lingering 2 frames once it dies. +constexpr float DEATH_SKULL_HEIGHT = -30; +constexpr int DEATH_SKULL_LINGER = 2; + +// Mom's hand from Emergency Contact lands on its target for its damage. +constexpr int MOMS_HAND_HIT_COUNTDOWN = 30; + +// The Ultra Death scythe falls 0.7 faster each frame and goes 120 below the room. +constexpr float SCYTHE_FALL = 0.7f; +constexpr float SCYTHE_FALL_MARGIN = 120; + +// The bishop's shield's target position eases a hundredth of the way after it each frame. +constexpr float BISHOP_SHIELD_EASE = 0.01f; + +// A wall broken by the X-Ray hole, Ultra Greed's coin bling, the whirlpool's ripples, the siren's ring. +constexpr float LADDER_DEPTH = -40; +constexpr float WHIRLPOOL_DEPTH = -14; +constexpr float WHIRLPOOL_PARTICLE_OFFSET = 0.3f; +constexpr int WHIRLPOOL_PARTICLE_IDLES = 4; +constexpr float SIREN_RING_DEPTH = 80; +constexpr float SIREN_RING_ALPHA = 0.6f; +constexpr float SOFT_POOF_DEPTH = 10; +constexpr float GREED_FOOTPRINT_ALPHA = 0.3f; +constexpr std::array BLING_ANIMATIONS = {"Bling1", "Bling2", "Bling3", "Bling4", "Bling5"}; + +// The Forgotten's soul leaving his body unlocks the Forgotten and bone hearts. +constexpr std::array FORGOTTEN_SOUL_UNLOCKS = {390, ACHIEVEMENT_BONE_HEARTS}; +constexpr ColorMod FORGOTTEN_SOUL_COLOR = {{1, 1, 1, 1}, {0, 0, 0, 0}, {0.05f, 0.12f, 0.2f}}; +constexpr int SOUL_LEAVING = -1; + +// The spritesheets Dross gives the leech's burst and Wormwood's holes. +constexpr std::string_view LEECH_DROSS_SHEET = "gfx/monsters/repentance/810.000_small_leech_dross.png"; +constexpr std::string_view WORMWOOD_DROSS_SHEET = "gfx/bosses/repentance/wormwood_wallbreak_dross.png"; + +// Monstro's tooth (Monstro's Tooth): Monstro follows his target a twentieth of the way each frame for 33 frames (a +// player only for 21), then lands with a crushing blast of 120 around 80. +constexpr int MONSTRO_TOOTH_LAND_FRAME = 33; +constexpr int MONSTRO_TOOTH_PLAYER_FRAMES = 21; +constexpr float MONSTRO_TOOTH_PULL = 0.05f; +constexpr float MONSTRO_TOOTH_DAMAGE = 120; +constexpr float MONSTRO_TOOTH_RADIUS = 80; +constexpr float MONSTRO_TOOTH_VOLUME = 0.8f; + +// A broken bar falls from its height (its fall slowing by a tenth, its acceleration added) and, landed, fades over 20 +// frames, sliding to a stop. +constexpr int BAR_FADE_FRAMES = 20; +constexpr int BAR_LIFESPAN = 50; +constexpr float BAR_FALL_ACCELERATION = 1.3f; +constexpr float BAR_FALL_SPEED = 0.5f; +constexpr float BAR_FALL_DRAG = 0.9f; +constexpr float BAR_LANDED_FRICTION = 0.5f; +constexpr float BAR_FRICTION = 0.86f; +constexpr int BAR_DIM_FRAMES = 10; + +// The cleaver's slash splits an enemy it holds from frame 3. +constexpr int CLEAVER_SPLIT_FRAME = 3; +constexpr float CLEAVER_DEPTH = 4; + +// Mother's shockwave cracks 40 further every other tick, swerving 30 degrees one way for four steps and back for +// four, crushing 10 around 20. The explosion wave blasts 60 further every other tick for 30 around 60, cratered. +// Both stop at a wall. +constexpr float MOTHER_WAVE_STEP = 40; +constexpr float MOTHER_WAVE_SWERVE = 30; +constexpr int MOTHER_WAVE_SWERVE_STEPS = 8; +constexpr float MOTHER_WAVE_DAMAGE = 10; +constexpr float MOTHER_WAVE_RADIUS = 20; +constexpr float EXPLOSION_WAVE_STEP = 60; +constexpr float EXPLOSION_WAVE_DAMAGE = 30; +constexpr float EXPLOSION_WAVE_RADIUS = 60; +constexpr uint32_t WAVE_STOPPING_COLLISION = COLLISION_SOLID; + + +// The ground glow under a falling shot brightens from a tenth as the shot comes down from 180 to 10, and fades a +// fifth each frame once alone. +constexpr float GLOW_HEIGHT_HIGH = -180; +constexpr float GLOW_HEIGHT_LOW = -10; +constexpr float GLOW_DIMMEST = 0.1f; +constexpr float GLOW_FADE = 0.2f; + +// A fire wave lights a fire jet 30 further along its angle every other frame, each 3 percent smaller, until one would +// be under a fifth of the size or the way leaves the room or meets a block. The fartwave farts 50 further every third +// frame, swerving up to 75 degrees either way, and leaves a poop half the time (a corny one once for subtype 1). Both +// last 120 frames. +constexpr int SPREADING_WAVE_LIFESPAN = 120; +constexpr float FIRE_WAVE_STEP = 30; +constexpr float FIRE_WAVE_SHRINK = 0.03f; +constexpr float FIRE_WAVE_SMALLEST = 0.2f; +constexpr int FARTWAVE_PERIOD = 3; +constexpr float FARTWAVE_STEP = 50; +constexpr float FARTWAVE_SWERVE_SPAN = 150; +constexpr float FARTWAVE_RADIUS = 60; +constexpr float FARTWAVE_PARTICLE_SPEED = 2; +constexpr int FARTWAVE_PARTICLES = 3; +constexpr int FARTWAVE_FIRST_POOP = 1; +constexpr int FARTWAVE_CORNY_VARIANT = 2; + +// The fart ring hangs 20 up in front, poisoning the vulnerable enemies within 50 every third frame for 40 frames, and +// fades once its player stops firing. +constexpr float FART_RING_HEIGHT = -20; +constexpr int FART_RING_PERIOD = 3; +constexpr float FART_RING_RADIUS = 50; +constexpr int FART_RING_POISON = 40; + +// The Spear of Destiny (a fire sword in the Guardian challenge) hurts the vulnerable enemies and fires within 13 (20) +// for twice (once) the player's knife damage, each once per 7 (2) frames, frightening bosses for 30 frames, and chips +// the grid entity it stands on. +constexpr float SPEAR_REACH = 13; +constexpr float SPEAR_GUARDIAN_REACH = 20; +constexpr int SPEAR_HIT_RESET_FRAMES = 7; +constexpr int SPEAR_GUARDIAN_HIT_RESET_FRAMES = 2; +constexpr float SPEAR_DAMAGE_SCALE = 2; +constexpr int SPEAR_FEAR_FRAMES = 30; +constexpr std::string_view SPEAR_GUARDIAN_SHEET = "gfx/Effects/Effect_101_FireSword.png"; + +// The brown cloud swells from 1 to 2.1 over 300 frames while its damage falls from 1.7 to 0.58 of its player's tear +// damage (3.5 without one), hurting each vulnerable enemy within 50 times its size every 7 frames. Tears blow it +// along (a tenth of their speed, less further out), it drifts to a stop and stays inside the room. +constexpr int BROWN_CLOUD_FRAMES = 300; +constexpr int BROWN_CLOUD_HIT_RESET_FRAMES = 7; +constexpr float BROWN_CLOUD_DAMAGE_FIRST = 1.7f; +constexpr float BROWN_CLOUD_DAMAGE_LAST = 0.58f; +constexpr float BROWN_CLOUD_SIZE_FIRST = 1; +constexpr float BROWN_CLOUD_SIZE_LAST = 2.1f; +constexpr float BROWN_CLOUD_DEFAULT_DAMAGE = 3.5f; +constexpr float BROWN_CLOUD_REACH = 50; +constexpr float BROWN_CLOUD_BLOW = 0.1f; +constexpr float BROWN_CLOUD_DRAG = 0.7f; + +// The boomerang (from its throw, 20 up) grabs the first pickup it touches (only rattling a sticky nickel), hurts and +// freezes each enemy it hits and knocks it along, and turns back at a wall or near the end of its flight, slowing +// over its last 30 frames, homing on its thrower at up to 15 until caught. +constexpr float BOOMERANG_HEIGHT = -20; +constexpr int BOOMERANG_FREEZE = -50; +constexpr int BOOMERANG_SLOWING_FRAMES = 30; +constexpr float BOOMERANG_FRICTION = 0.95f; +constexpr float BOOMERANG_RETURN_SPEED = 15; +constexpr int STICKY_NICKEL_COOLDOWN = 10; + +// Plays a sound through the seeds' fart override. +static void overridden_sound_play(int sound, SoundPlay play = {}) +{ + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound, play); +} + +// Redemption's sign over its player: a damage up and a soul heart's worth (two halves) with a white flash on success, +// a thumbs down and a poof 20 up on failure. +constexpr float REDEMPTION_DEPTH = -10; +constexpr int REDEMPTION_SOUL_HEARTS = 2; +constexpr int REDEMPTION_FLASH_FRAMES = 6; +constexpr float REDEMPTION_POOF_HEIGHT = -20; +constexpr ColorMod REDEMPTION_FLASH = {{1, 1, 1, 1}, {0, 0, 0, 0}, {1, 1, 1}}; + +// Redemption's states: waiting while its player holds an item up, succeeded, failed. +enum RedemptionState +{ + REDEMPTION_WAITING = 1, + REDEMPTION_SUCCESS, + REDEMPTION_FAIL +}; + +// Part of 005cdb20 (Init's fire case) A fire keeps off pits, owned by whoever fired the tear or bomb that set it. The +// item fires burn for 300 frames at full size. +static void fire_init(Entity_Effect& fire) +{ + fire.entityGridCollisionClass = GRIDCOLL_NOPITS; + Entity* spawner = fire.spawnerEntity.get(); + bool isShot = spawner && (spawner->type == ENTITY_TEAR || spawner->type == ENTITY_BOMB); + if (isShot && spawner->spawnerEntity) fire.spawnerEntity = spawner->spawnerEntity.get(); + if (fire.variant == EFFECT_BLUE_FLAME) return; + + fire.scale = 1; + fire.SetTimeout(FIRE_LIFESPAN); +} + +// Whether a fire burns an entity it touches: enemies, and other players in versus mode (never its own spawner's line). +static bool is_fire_target(Entity_Effect& fire, Entity& entity) +{ + if (entity.type >= ENTITY_FIRST_ENEMY) return true; + if (entity.type != ENTITY_PLAYER) return false; + if (fire.spawnerEntity && fire.spawnerEntity->IsDescendantOf(&entity)) return false; + return g_game->deathmatchManager.is_active(); +} + +// Whether a fire puts out a shot it touches: an enemy's shot that may hurt players, within both sizes. +static bool is_shot_put_out(Entity_Effect& fire, Entity& entity) +{ + if (entity.type != ENTITY_PROJECTILE || entity.isDead) return false; + if (static_cast(entity).projectileFlags & PROJECTILE_CANT_HIT_PLAYER) return false; + + float reach = entity.size + fire.size; + return vector_length_squared(vector_sub(entity.pos, fire.pos)) < reach * reach; +} + +// Burns an entity once per hit list reset, true when it took the damage. +static bool fire_hit(Entity_Effect& fire, Entity& entity, float damage, uint64_t damageFlags) +{ + if (EntityList::HitListContains(fire.hitList, entity)) return false; + + hit_list_insert(fire.hitList, entity); + return entity.TakeDamage(damage, damageFlags, EntityRef(&fire), FIRE_HIT_COUNTDOWN); +} + +// Whether a burnable entity is one a fire may hurt now: alive, collidable, not friendly and, for an item fire, no +// effect or poop. +static bool is_fire_hurtable(Entity& entity, bool isItemFire) +{ + if (entity.type == ENTITY_EFFECT || (isItemFire && entity.type == ENTITY_POOP)) return false; + return !entity.isDead && !entity.HasEntityFlags(FLAG_FRIENDLY) && entity.entityCollisionClass != ENTCOLL_NONE; +} + +// 005f021a (Update's case 10) The blue flame slows and forgets what it burned every 5 frames. A player's or a +// familiar's fades and dims toward its end, burns enemies and puts out shots, then it goes once dead. +static void blue_flame_update(Entity_Effect& flame) +{ + flame.friction *= FIRE_FRICTION; + if (flame.IsFrame(FIRE_HIT_RESET_FRAMES, (int)flame.index)) flame.hitList.clear(); + if (flame.spawnerType == ENTITY_PLAYER || flame.spawnerType == ENTITY_FAMILIAR) + { + float fade = std::min((float)flame.timeout / (float)std::min(FLAME_FADE_FRAMES, flame.lifespan), 1.0f); + flame.sprite.GetLayer(0)->size = vector_make(fade * flame.scale, fade * flame.scale); + float damageScale = std::max(flame.scale, FIRE_MIN_DAMAGE_SCALE); + + for (Entity* entity : entity_query_radius(flame.pos, flame.size, QUERY_PROJECTILES | QUERY_ENEMIES)) + { + if (is_fire_target(flame, *entity) && is_fire_hurtable(*entity, false)) + { + if (!fire_hit(flame, *entity, flame.collisionDamage * damageScale, 0)) continue; + + float volume = std::min(entity->health * FLAME_HISS_PER_HEALTH + FLAME_HISS_VOLUME, 1.0f); + overridden_sound_play(SOUND_FIREDEATH_HISS, {.volume = volume, .frameDelay = FLAME_HISS_DELAY}); + } + else if (is_shot_put_out(flame, *entity)) entity->Remove(); + } + if (flame.timeout < FLAME_DIM_FRAMES) flame.sprite.color._tint[3] = (float)flame.timeout / FLAME_DIM_FRAMES; + layer_additive_set(*flame.sprite.GetLayer(0)); + } + flame.state++; + if (flame.isDead) flame.Remove(); +} + +// 005f0895 (Update's case 51 and 52) An item fire slows, burns enemies (and players in versus mode) and puts out shots +// while alive, losing a quarter of its size for each, and once out of size dies with a hiss (over an enemy) and goes. +static void item_fire_update(Entity_Effect& fire) +{ + fire.friction *= FIRE_FRICTION; + if (!fire.isDead) + { + float radius = fire.size; + if (fire.parent && fire.parent->IsEnemy()) + { + radius = fire.parent->size + FIRE_ENEMY_REACH; + fire.scale = lerp_clamped(fire.parent->health, FIRE_ENEMY_HEALTH_LOW, FIRE_ENEMY_HEALTH_HIGH, 0, 1); + } + if (fire.IsFrame(FIRE_HIT_RESET_FRAMES, (int)fire.index)) fire.hitList.clear(); + layer_additive_set(*fire.sprite.GetLayer(0)); + float damageScale = std::max(fire.scale, FIRE_MIN_DAMAGE_SCALE); + + for (Entity* entity : entity_query_radius(fire.pos, radius, QUERY_PROJECTILES | QUERY_ENEMIES)) + { + if (is_fire_target(fire, *entity) && is_fire_hurtable(*entity, true)) + { + if (fire_hit(fire, *entity, fire.collisionDamage * damageScale, DAMAGE_FIRE)) fire.scale -= FIRE_SHRINK; + } + else if (is_shot_put_out(fire, *entity)) + { + entity->isDead = true; + fire.scale -= FIRE_SHRINK; + } + } + } + if (fire.scale < 0) fire.scale = 0; + fire.sprite.GetLayer(0)->size = vector_make(fire.scale, fire.scale); + if (fire.scale <= 0 && !fire.isDead) + { + fire.isDead = true; + if (fire.parent && fire.parent->IsEnemy()) + overridden_sound_play(SOUND_STEAM_HALFSEC, {.volume = FIRE_STEAM_VOLUME}); + } + if (!fire.isDead) return; + + fire.sprite.Play("Disappear"); + if (fire.sprite.IsFinished()) fire.Remove(); +} + +// Part of 005cdb20 (Init's case 29) Mom's foot stomps for 300 on whatever it follows. +static void foot_init(Entity_Effect& foot) +{ + foot.targetPosition = {}; + foot.collisionDamage = FOOT_DAMAGE; +} + +// 005efe6b (Update's case 29) Mom's foot waits its subtype's frames on its first frame, follows its target (or target +// position) while it hangs, stomps on frame 27 with a crushing blast and a poof of dust, then goes when done. +static void foot_update(Entity_Effect& foot) +{ + if (foot.subtype != 0) + { + foot.sprite.SetFrame(0.0f); + foot.subtype--; + } + + int frame = foot.sprite.GetFrame(); + foot.renderZOffset = FOOT_RENDER_Z; + bool isOverEnemy = foot.target && foot.target->IsEnemy() && frame < FOOT_STOMP_FRAME; + if (frame < FOOT_TRACK_FRAMES || isOverEnemy) + { + Vector toward{}; + if (foot.target && foot.state == 0) toward = vector_sub(foot.target->pos, foot.pos); + else if (!foot.target && (foot.targetPosition.x != 0 || foot.targetPosition.y != 0)) + toward = vector_sub(foot.targetPosition, foot.pos); + foot.velocity = vector_add(foot.velocity, vector_scale(toward, FOOT_PULL)); + } + else if (frame == FOOT_STOMP_FRAME) + { + overridden_sound_play(SOUND_HELLBOSS_GROUNDPOUND); + + float damage = g_game->deathmatchManager.is_active() ? FOOT_VERSUS_DAMAGE : foot.collisionDamage; + explosion_damage({.position = foot.pos, .source = &foot, .damageFlags = DAMAGE_CRUSH, .damage = damage, + .radius = FOOT_RADIUS, .isLineCheck = false}); + foot.MakeGroundPoofAtSelf(FOOT_POOF_COLOR, 1); + } + foot.friction *= FOOT_FRICTION; + if (foot.sprite.IsFinished()) foot.Remove(); +} + +// Part of 005cdb20 (Init's case 174) The shop's spikes stand under their ware in the floor. Spikes set out after the +// room's first frame replace those on their cell, or leave a blood stain when there were none. +static void shop_spikes_init(Entity_Effect& spikes) +{ + spikes.AddEntityFlags(FLAG_DONT_OVERWRITE); + spikes.sprite.Play("Idle"); + spikes.renderDepthOffset = SHOP_SPIKES_DEPTH; + Room& room = *g_game->room; + if (room.GetFrameCount() <= 1) return; + + bool isReplaced = false; + for (Entity* other : entity_query(ENTITY_EFFECT, EFFECT_SHOP_SPIKES)) + { + if (!other->parent || room.GetGridIndex(other->pos) != room.GetGridIndex(spikes.pos)) continue; + other->Remove(); + isReplaced = true; + } + if (isReplaced) return; + + RNG rng = rng_make(spikes.initSeed, SHOP_SPIKES_STAIN_SHIFT); + g_game->Spawn({.position = spikes.pos, .type = ENTITY_EFFECT, .variant = EFFECT_BLOOD_SPLAT, .seed = rng.Next()}) + ->Update(); +} + +// 005df70e (Update's case 174) The shop's spikes sink once their ware is gone. +static void shop_spikes_update(Entity_Effect& spikes) +{ + if (spikes.state != 0 || (spikes.parent && !spikes.parent->isDead)) return; + spikes.state = 1; + spikes.sprite.Play("Retract"); +} + +// Part of 005cdb20 (Init's case 8) A ladder stands behind what is on its cell. +static void ladder_init(Entity_Effect& ladder) +{ + ladder.renderDepthOffset = LADDER_DEPTH; +} + +// Part of 005cdb20 (Init's case 89) Ultra Greed's footprint shows a random frame, faint. +static void footprint_init(Entity_Effect& footprint) +{ + AnimationState& anim = footprint.sprite.animState; + int length = anim.animData ? anim.GetAnimationLength() : 0; + int frame = length ? (int)(Random() % (uint32_t)length) : 0; + if (anim.animData) anim.SetFrameFloat((float)frame); + footprint.sprite.color = tint_color_make(1, 1, 1, GREED_FOOTPRINT_ALPHA); +} + +// Part of 005cdb20 (Init's case 128) An idle effect never overwritten. +static void kept_idle_init(Entity_Effect& effect) +{ + effect.AddEntityFlags(FLAG_DONT_OVERWRITE); + effect.sprite.Play("Idle"); +} + +// Part of 005cdb20 (Init's case 130) A leech's burst takes Dross's colors there. +static void leech_explosion_init(Entity_Effect& explosion) +{ + if (g_game->GetStageID() != STAGE_ID_DROSS) return; + explosion.sprite.ReplaceSpritesheet(0, LEECH_DROSS_SHEET); + explosion.sprite.LoadGraphics(); +} + +// Part of 005cdb20 (Init's case 142) The whirlpool and its particles take the water's color, the particles on the +// floor on one of four idles. +static void whirlpool_init(Entity_Effect& whirlpool) +{ + ColorMod& water = g_game->room->fxLayers.fxParams.waterEffectColor; + if (whirlpool.subtype != 1) + { + whirlpool.renderDepthOffset = WHIRLPOOL_DEPTH; + whirlpool.sprite.color = water; + return; + } + + whirlpool.sortingLayer = SORTING_BACKGROUND; + int idle = whirlpool.dropRNG.RandomInt(WHIRLPOOL_PARTICLE_IDLES); + whirlpool.sprite.Play("Idle" + std::to_string(idle)); + whirlpool.sprite.color = water; + for (int i = 0; i < 3; i++) whirlpool.sprite.color._offset[i] = WHIRLPOOL_PARTICLE_OFFSET; +} + +// Part of 005cdb20 (Init's case 162) An effect drawn on the floor. +static void floor_init(Entity_Effect& effect) +{ + effect.sortingLayer = SORTING_BACKGROUND; +} + +// Part of 005cdb20 (Init's case 164) The siren's ring shows in front, faint and additive. +static void siren_ring_init(Entity_Effect& ring) +{ + ring.renderDepthOffset = SIREN_RING_DEPTH; + ring.sprite.color._tint[3] = SIREN_RING_ALPHA; + layer_additive_set(*ring.sprite.GetLayer(0)); +} + +// Part of 005cdb20 (Init's cases 173 and 201) A poof drawn a little in front. +static void soft_poof_init(Entity_Effect& poof) +{ + poof.renderDepthOffset = SOFT_POOF_DEPTH; +} + +// Part of 005cdb20 (Init's case 200) A bullet poof that does not take the room's colors. +static void static_poof_init(Entity_Effect& poof) +{ + poof.sprite.bitflags |= ANIM_RENDER_STATIC; +} + +// Part of 005cdb20 (Init's cases 136, 177, 183, 187 and 192) A helper with nothing to show. +static void hidden_init(Entity_Effect& effect) +{ + effect.isVisible = false; +} + +// 005d65d0 (Update's case 136) The grid projectile helper goes with its grid entity's projectile. +static void parented_update(Entity_Effect& helper) +{ + if (!helper.parent) helper.Remove(); +} + +// Part of 005cdb20 (Init's case 103) Ultra Greed's bling flashes one of five sparkles, additive. +static void bling_init(Entity_Effect& bling) +{ + layer_additive_set(*bling.sprite.GetLayer(0)); + bling.sprite.Play(BLING_ANIMATIONS[random_below((int)BLING_ANIMATIONS.size())]); +} + +// 005fffed (Update's case 103) An effect that goes once its animation ends. +static void finished_update(Entity_Effect& effect) +{ + if (effect.sprite.IsFinished()) effect.Remove(); +} + +// Part of 005cdb20 (Init's case 109) The Death's List skull appears. +static void death_skull_init(Entity_Effect& skull) +{ + skull.sprite.Play("Appear"); +} + +// 006029b5 (Update's case 109) The Death's List skull rides its target's overlay (or 30 above it) while the list is +// open, lingering two frames after its target dies. Without one it dies and goes. +static void death_skull_update(Entity_Effect& skull) +{ + Entity* target = skull.target.get(); + if (target && !g_game->room->isDeathsListDone) + { + if (skull.sprite.IsFinished()) skull.sprite.Play("Idle"); + skull.pos = target->pos; + skull.velocity = target->velocity; + const NullFrame* overlay = target->sprite.GetNullFrame("OverlayEffect"); + skull.posOffset = overlay && overlay->isVisible + ? vector_make(overlay->pos.x / LASER_SCREEN_SCALE, overlay->pos.y / LASER_SCREEN_SCALE) + : vector_make(0, DEATH_SKULL_HEIGHT); + if (!target->isDead) return; + + if (skull.timeout < 1) skull.timeout = DEATH_SKULL_LINGER; + else skull.target = nullptr; + return; + } + skull.sprite.Play("Die"); + if (skull.sprite.IsFinished()) skull.Remove(); +} + +// Part of 005cdb20 (Init's case 117) The Forgotten's soul rises, tinted, from his body. +static void forgotten_soul_init(Entity_Effect& soul) +{ + soul.sprite.color = FORGOTTEN_SOUL_COLOR; + soul.sprite.Play("LostDeath"); + soul.state = 0; +} + +// 006050ad (Update's case 117) The Forgotten's soul leaves once its rise ends, unlocking the Forgotten and bone hearts +// when it rose from his body, and skips the rest of the frame. +static EffectUpdateEnd forgotten_soul_update(Entity_Effect& soul) +{ + if (soul.sprite.IsFinished()) soul.state = SOUL_LEAVING; + if (soul.state != SOUL_LEAVING) return EFFECT_UPDATE_FINISH; + + if (soul.parent) + for (int achievement : FORGOTTEN_SOUL_UNLOCKS) g_manager->persistentGameData.TryUnlock(achievement); + soul.Remove(); + return EFFECT_UPDATE_RETURN; +} + +// Part of 005cdb20 (Init's case 137) Wormwood's hole opens, on the floor (or the spray in the water's color), in +// Dross's colors there. +static void wormwood_hole_init(Entity_Effect& hole) +{ + hole.sprite.Play("Open"); + if (hole.subtype == 0) hole.sortingLayer = SORTING_DOOR; + else if (hole.subtype == 1) hole.sprite.color = g_game->room->fxLayers.fxParams.waterEffectColor; + if (g_game->GetStageID() != STAGE_ID_DROSS) return; + + for (int layer = 0; layer < (int)hole.sprite.layerStates.size(); layer++) + hole.sprite.ReplaceSpritesheet(layer, WORMWOOD_DROSS_SHEET); + hole.sprite.LoadGraphics(); +} + +// 005d65f7 (Update's case 137) Wormwood's hole in a wall goes once the room is clear and a door is set there. +static void wormwood_hole_update(Entity_Effect& hole) +{ + if (hole.subtype != 0 || !g_game->room->IsClear()) return; + + GridEntity* grid = room_grid_entity_at(hole.pos); + if (grid && grid->type == GRID_DOOR && grid->state != 0) hole.Remove(); +} + +// 005d8f47 (Update's case 147) The fire jet lights with a sound, burns around it on frames 2 and 4 (the burning tear +// effect when it burns), and goes once done. A friendly jet (or one from a friendly spawner) spares the players. +static void fire_jet_update(Entity_Effect& jet) +{ + int frame = jet.FrameCount(); + if (frame == 1 && jet.subtype == 0) + { + overridden_sound_play(SOUND_CANDLE_LIGHT); + } + if ((frame == 2 || frame == 4) && jet.collisionDamage > 0) + { + bool isFriendly = (jet.spawnerEntity && jet.spawnerEntity->HasEntityFlags(FLAG_FRIENDLY)) || + jet.HasEntityFlags(FLAG_FRIENDLY); + TearFlags tearFlags{}; + if (jet.HasEntityFlags(FLAG_BURN)) tearFlags.set(TEAR_BURN); + damage_radius({.tearFlags = tearFlags, .position = jet.pos, .source = &jet, .damageFlags = DAMAGE_FIRE, + .damage = jet.collisionDamage, .playerDamageThreshold = FIRE_JET_PLAYER_THRESHOLD, + .radius = FIRE_JET_RADIUS, .isHitAll = !isFriendly}); + } + if (jet.sprite.IsFinished()) jet.Remove(); +} + +// Part of 005cdb20 (Init's case 36) The X-Ray hole shows the room's broken wall, behind what stands there. +static void xray_wall_init(Entity_Effect& hole) +{ + Room& room = *g_game->room; + hole.sprite.ReplaceSpritesheet(0, room.backdrop.configs[room.backdropType].holeInWall); + hole.sortingLayer = SORTING_DOOR; +} + +// 005e95ca (Update's case 36) Once its animation ends the X-Ray hole blows open the door it stands on (shut again +// while enemies remain) and goes. +static void xray_wall_update(Entity_Effect& hole) +{ + if (!hole.sprite.IsFinished()) return; + + GridEntity* grid = room_grid_entity_at(hole.pos); + if (auto* door = grid && grid->type == GRID_DOOR ? dynamic_cast(grid) : nullptr) + { + door->TryBlowOpen(false, nullptr); + if (!g_game->room->IsClear()) door->Close(false); + } + hole.Remove(); +} + +// Part of 005cdb20 (Init's case 91) Mom's hand comes down with a whoosh. +static void moms_hand_init(Entity_Effect& hand) +{ + hand.sprite.Play("JumpDown"); + overridden_sound_play(SOUND_BIRD_FLAP); +} + +// 005ffc5d (Update's case 91) Mom's hand lands on its target for its damage with a stomp, grabs it, and dies (going +// back up) once its target is gone. +static void moms_hand_update(Entity_Effect& hand) +{ + if (hand.sprite.IsEventTriggered("Land") && hand.target && hand.target->isExists) + { + hand.target->TakeDamage(hand.collisionDamage, 0, EntityRef(&hand), MOMS_HAND_HIT_COUNTDOWN); + overridden_sound_play(SOUND_FORESTBOSS_STOMPS); + } + if (hand.sprite.IsFinished("JumpDown")) hand.sprite.Play("Grab"); + if (!hand.target || !hand.target->isExists) hand.isDead = true; + if (!hand.isDead) return; + + hand.sprite.Play("JumpUp"); + if (hand.sprite.IsFinished()) hand.Remove(); +} + +// 005df77a (Update's case 175) The Kineti beam stays on its target, gone with its parent. +static void kineti_beam_update(Entity_Effect& beam) +{ + if (beam.target) beam.pos = beam.target->pos; + beam.velocity = {}; + if (!beam.parent || beam.isDead) beam.Remove(); +} + +// 005d511e (Update's case 184) The worm friend's snare stays on its parent and goes with it. +static void snare_update(Entity_Effect& snare) +{ + if (!snare.parent) + { + snare.Remove(); + return; + } + snare.pos = snare.parent->pos; + snare.velocity = {}; +} + +// Part of 005cdb20 (Init's case 199) Ultra Death's scythe spins. +static void scythe_init(Entity_Effect& scythe) +{ + scythe.sprite.Play("Spin"); +} + +// 005e7cc9 (Update's case 199) Ultra Death's scythe falls ever faster and goes once 120 below the room. +static void scythe_update(Entity_Effect& scythe) +{ + scythe.velocity.y += scythe.speedMultiplier * SCYTHE_FALL; + if (scythe.velocity.y > 0 && scythe.pos.y > g_game->room->bottomRightPos.y + SCYTHE_FALL_MARGIN) scythe.Remove(); +} + +// 005dbba5 (Update's case 160) The bishop's shield stays on its target, its target position easing after it, and goes +// with its target or once its animation ends. +static EffectUpdateEnd bishop_shield_update(Entity_Effect& shield) +{ + if (!shield.target) + { + shield.Remove(); + return EFFECT_UPDATE_RETURN; + } + shield.pos = shield.target->pos; + shield.velocity = shield.target->velocity; + if (shield.targetPosition.x == 0 && shield.targetPosition.y == 0) shield.targetPosition = shield.pos; + else vector_lerp(shield.targetPosition, shield.pos, BISHOP_SHIELD_EASE); + if (shield.sprite.IsFinished()) shield.Remove(); + return EFFECT_UPDATE_FINISH; +} + +// Part of 005cdb20 (Init's case 170) Dogma's debris floats on the floor at a random point of its float and idle, +// mirrored at random, never overwritten. +static void dogma_debris_init(Entity_Effect& debris) +{ + ANM2& sprite = debris.sprite; + RNG& rng = debris.dropRNG; + + debris.sortingLayer = SORTING_BACKGROUND; + sprite.PlayOverlay("Float"); + sprite.SetOverlayFrame(rng.RandomInt(sprite.overlayAnimState.GetAnimationLength())); + sprite.SetFrame("Idle", 0); + sprite.SetFrame((float)rng.RandomInt(sprite.animState.GetAnimationLength())); + sprite.isFlipX = rng.RandomInt(2) != 0; + debris.AddEntityFlags(FLAG_DONT_OVERWRITE); +} + +// 005dc73f (Update's case 170) Dogma's debris moves its layer by its float's first null. +static void dogma_debris_update(Entity_Effect& debris) +{ + const NullFrame* frame = debris.sprite.overlayAnimState.GetNullFrameById(0); + if (!frame) return; + + LayerState& layer = *debris.sprite.GetLayer(0); + layer.pos = frame->pos; + layer.rotation = frame->rotation; + layer.size = frame->scale; +} + +// Part of 005cdb20 (Init's case 152) A hidden effect never overwritten. +static void hidden_kept_init(Entity_Effect& effect) +{ + effect.isVisible = false; + effect.AddEntityFlags(FLAG_DONT_OVERWRITE); +} + +// 005da269 (Update's case 152) Hornfel's room controller. +static void hornfel_controller_update(Entity_Effect& controller) +{ + NpcHelper::hornfel_room_controller(&controller); +} + +// 005efc0b (Update's case 28) Monstro's tooth: Monstro follows his target (a player only so long), jumps back up once +// down and goes once up, landing on frame 33 with a stomp and a crushing blast. +static void tooth_update(Entity_Effect& tooth) +{ + tooth.renderZOffset = FOOT_RENDER_Z; + if (tooth.target && tooth.state < MONSTRO_TOOTH_LAND_FRAME) + { + Vector toward = vector_sub(tooth.target->pos, tooth.pos); + tooth.velocity = vector_add(tooth.velocity, vector_scale(toward, MONSTRO_TOOTH_PULL)); + if (tooth.target->is_player() && tooth.state > MONSTRO_TOOTH_PLAYER_FRAMES) tooth.target = nullptr; + } + if (tooth.sprite.IsFinished("JumpDown")) tooth.sprite.Play("JumpUp"); + else if (tooth.sprite.IsFinished("JumpUp")) tooth.Remove(); + if (tooth.state == MONSTRO_TOOTH_LAND_FRAME) + { + overridden_sound_play(SOUND_FORESTBOSS_STOMPS, {.volume = MONSTRO_TOOTH_VOLUME}); + explosion_damage({.position = tooth.pos, .source = &tooth, .damageFlags = DAMAGE_CRUSH, + .damage = MONSTRO_TOOTH_DAMAGE, .radius = MONSTRO_TOOTH_RADIUS, .isLineCheck = false}); + } + tooth.state++; + tooth.friction *= FOOT_FRICTION; +} + +// Part of 005cdb20 (Init's case 75) A broken bar falls for 50 frames. +static void bar_particle_init(Entity_Effect& bar) +{ + bar.timeout = BAR_LIFESPAN; + bar.fallingAcceleration = BAR_FALL_ACCELERATION; + bar.fallingSpeed = BAR_FALL_SPEED; + bar.sprite.Play("Idle"); +} + +// 005fcd6b (Update's case 75) A broken bar falls to the floor, then stops, slides and fades out. +static void bar_particle_update(Entity_Effect& bar) +{ + float height = vector_length(bar.posOffset); + if (vector_length_squared(bar.posOffset) <= 0) + { + if (!bar.isDead) + { + bar.isDead = true; + bar.timeout = BAR_FADE_FRAMES; + bar.sprite.Stop(); + } + bar.friction *= BAR_LANDED_FRICTION; + } + else + { + bar.fallingSpeed = bar.fallingSpeed * BAR_FALL_DRAG + bar.fallingAcceleration; + bar.posOffset = vector_resized(bar.posOffset, std::max(height - bar.fallingSpeed, 0.0f)); + } + if (bar.isDead) + { + if (bar.timeout < 1) bar.Remove(); + bar.sprite.color._tint[3] = (float)std::min(bar.timeout, BAR_DIM_FRAMES) / BAR_DIM_FRAMES; + } + bar.sprite.rotation = bar.rotation; + bar.friction *= BAR_FRICTION; +} + +// 005df80d (Update's case 176) The cleaver's slash holds its target from frame 3, splitting an enemy for its damage, +// then lets go and goes when done. +static void cleaver_slash_update(Entity_Effect& slash) +{ + slash.renderDepthOffset = CLEAVER_DEPTH; + if (Entity* target = slash.target.get()) + { + slash.pos = target->pos; + slash.velocity = {}; + if (slash.sprite.GetFrame() >= CLEAVER_SPLIT_FRAME) + { + if (target->IsEnemy()) + { + EntityRef source(slash.spawnerEntity.get()); + static_cast(target)->split(slash.collisionDamage, source, false); + } + if (target->type == ENTITY_FAMILIAR && target->variant == Entity_Familiar::WISP) + reconstruction_missing("Entity_Effect::Update 005d4380: the cleaver splitting a wisp (FUN_0043e9f0)"); + slash.target = nullptr; + } + } + if (slash.sprite.IsFinished()) slash.Remove(); +} + +// Whether a wave's next step meets a wall, which removes it. +static bool is_wave_stopped(Entity_Effect& wave, Vector next) +{ + if (room_grid_collision_at(next) <= WAVE_STOPPING_COLLISION) return false; + wave.Remove(); + return true; +} + +// 005e3934 (Update's case 183) Mother's shockwave cracks onward every other tick, swerving, with a rock explosion and a +// crushing blast from Mother at each step, until it meets a wall. +static EffectUpdateEnd mother_shockwave_update(Entity_Effect& wave) +{ + for (int tick = 0; tick < wave.update_ticks_get(); tick++) + { + if (++wave.state % 2 != 0) continue; + + bool isSwervingRight = (wave.state / 2 + 1) % MOTHER_WAVE_SWERVE_STEPS < MOTHER_WAVE_SWERVE_STEPS / 2; + float swerve = isSwervingRight ? MOTHER_WAVE_SWERVE : -MOTHER_WAVE_SWERVE; + Vector heading = tear_vector_rotate(wave.targetPosition, swerve); + Vector next = vector_add(wave.pos, vector_scale(heading, MOTHER_WAVE_STEP)); + if (is_wave_stopped(wave, next)) return EFFECT_UPDATE_RETURN; + + g_game->Spawn({.position = next, .type = ENTITY_EFFECT, .variant = EFFECT_ROCK_EXPLOSION, .seed = Random()}); + explosion_damage({.position = next, .source = wave.parent.get(), .damageFlags = DAMAGE_CRUSH, + .damage = MOTHER_WAVE_DAMAGE, .radius = MOTHER_WAVE_RADIUS, .isLineCheck = false}); + wave.pos = next; + } + return EFFECT_UPDATE_FINISH; +} + +// 005e3bcc (Update's case 187) The explosion wave blasts onward every other tick, each step a bomb's explosion, blast +// and crater, until it meets a wall. +static EffectUpdateEnd explosion_wave_update(Entity_Effect& wave) +{ + for (int tick = 0; tick < wave.update_ticks_get(); tick++) + { + if (++wave.state % 2 != 0) continue; + + Vector next = vector_add(wave.pos, vector_scale(wave.targetPosition, EXPLOSION_WAVE_STEP)); + if (is_wave_stopped(wave, next)) return EFFECT_UPDATE_RETURN; + + auto* blast = static_cast(g_game->Spawn( + {.position = next, .type = ENTITY_EFFECT, .variant = EFFECT_BOMB_EXPLOSION, .seed = Random()})); + blast->state = 1; + explosion_damage({.position = next, .source = &wave, .damage = EXPLOSION_WAVE_DAMAGE, + .radius = EXPLOSION_WAVE_RADIUS, .isLineCheck = false}); + bomb_crater_spawn(next, nullptr, 1); + wave.pos = next; + } + return EFFECT_UPDATE_FINISH; +} + +// Part of 005cdb20 (Init's case 196) The ground glow lies on the floor, additive and smoothly filtered. +static void ground_glow_init(Entity_Effect& glow) +{ + glow.sortingLayer = SORTING_BACKGROUND; + LayerState& layer = *glow.sprite.GetLayer(0); + layer_additive_set(layer); + layer.minFilterMode = 1; + layer.magFilterMode = 1; +} + +// 005e72de (Update's case 196) The ground glow brightens as its falling shot comes down, and fades away once dead or +// alone. +static void ground_glow_update(Entity_Effect& glow) +{ + float& alpha = glow.sprite.GetLayer(0)->color._tint[3]; + if (!glow.isDead && glow.parent) + { + if (glow.parent->type == ENTITY_PROJECTILE) + { + float height = static_cast(*glow.parent).height; + alpha = lerp_clamped(height, GLOW_HEIGHT_HIGH, GLOW_HEIGHT_LOW, GLOW_DIMMEST, 1); + } + return; + } + glow.velocity = {}; + alpha -= GLOW_FADE; + if (alpha <= 0) glow.Remove(); +} + +// Part of 00607620 (Render's case 196) The ground glow under a following shot draws at the shot's place on the floor. +static void ground_glow_render(Entity_Effect& glow, const Vector& offset) +{ + if (!glow.parent || !glow.isFollowing) + { + glow.sprite.Render(SpriteDraw{glow.renderPosition, {}, {}}); + return; + } + Vector screen = render_position_get(glow.parent->pos, RENDER_SNAPPED); + glow.sprite.Render(SpriteDraw{vector_make(screen.x + offset.x, screen.y + offset.y), {}, {}}); +} + +// Part of 005cdb20 (Init's cases 143 and 148) A spreading wave is unseen and lasts 120 frames from where it starts. +static void spreading_wave_init(Entity_Effect& wave) +{ + wave.isVisible = false; + wave.timeout = SPREADING_WAVE_LIFESPAN; + wave.targetPosition = {}; +} + +// The next point of a spreading wave, a step further along an angle from its last (its start at first), and whether it +// stays inside the room. +static bool is_wave_point_inside(Entity_Effect& wave, float angle, float step) +{ + if (wave.targetPosition.x == 0 && wave.targetPosition.y == 0) wave.targetPosition = wave.pos; + wave.targetPosition = vector_add(wave.targetPosition, vector_scale(vector_from_angle(angle), step)); + Vector clamped = g_game->room->GetClampedPosition(wave.targetPosition, 0); + return clamped.x == wave.targetPosition.x && clamped.y == wave.targetPosition.y; +} + +// 005d9154 (Update's case 148) A fire wave lights ever smaller fire jets along its way every other frame, owned like +// itself and in its colors, and goes at the room's edge, a block or once they get too small. +static void fire_wave_update(Entity_Effect& wave) +{ + wave.isVisible = false; + if (wave.FrameCount() % 2 != 0) return; + + bool isInside = is_wave_point_inside(wave, wave.rotation, FIRE_WAVE_STEP); + if (!isInside || room_grid_collision_at(wave.targetPosition) >= COLLISION_OBJECT) + { + wave.Remove(); + return; + } + + float size = 1 - (float)wave.FrameCount() * FIRE_WAVE_SHRINK; + Entity* jet = g_game->Spawn({.position = wave.targetPosition, .spawner = wave.spawnerEntity.get(), + .subType = wave.subtype, .type = ENTITY_EFFECT, .variant = EFFECT_FIRE_JET, + .seed = Random()}); + jet->spawnerType = wave.spawnerType; + jet->spawnerVariant = wave.spawnerVariant; + jet->sprite.scale = vector_make(size, size); + jet->sprite.color = wave.sprite.color; + jet->sprite.isFlipX = random_below(2) != 0; + if (wave.HasEntityFlags(FLAG_FRIENDLY)) jet->AddEntityFlags(FLAG_FRIENDLY); + if (size < FIRE_WAVE_SMALLEST) wave.Remove(); +} + +// 005d742b (Update's case 143) The fartwave farts its way on every third frame, swerving, with a puff, a few poop +// particles and now and then a poop left on free ground (corny for subtype 1's first) worn down at once, until it +// leaves the room. +static void fartwave_update(Entity_Effect& wave) +{ + if (wave.FrameCount() % FARTWAVE_PERIOD != 0) return; + + float swerve = random_unit() * FARTWAVE_SWERVE_SPAN - FARTWAVE_SWERVE_SPAN / 2; + if (!is_wave_point_inside(wave, wave.rotation + swerve, FARTWAVE_STEP)) + { + wave.Remove(); + return; + } + + Vector point = wave.targetPosition; + game_butter_bean_fart({.position = point, .source = wave.parent.get(), .radius = FARTWAVE_RADIUS}); + g_game->Spawn({.position = point, .type = ENTITY_EFFECT, .variant = EFFECT_POOP_EXPLOSION, .seed = Random()}) + ->Update(); + game_particles_spawn({.position = point, + .speed = random_unit() + FARTWAVE_PARTICLE_SPEED, + .count = random_below(FARTWAVE_PARTICLES), + .variant = EFFECT_POOP_PARTICLE}); + + bool isFirstPoop = wave.subtype == FARTWAVE_FIRST_POOP && wave.state > 0; + Room& room = *g_game->room; + if ((wave.dropRNG.RandomInt(2) == 0 || isFirstPoop) && room_grid_collision_at(point) == COLLISION_NONE) + { + int gridIndex = room.GetGridIndex(point); + if (isFirstPoop) wave.subtype = 0; + room.SpawnGridEntity(gridIndex, GRID_POOP, isFirstPoop ? FARTWAVE_CORNY_VARIANT : 0, Random(), 0); + GridEntity* poop = room.GetGridEntity((uint32_t)gridIndex); + if (poop && poop->type == GRID_POOP) + { + poop->varData = 1; + poop->Hurt(random_below(2) + 1, EntityRef(&wave)); + } + } + wave.state++; +} + +// Part of 005cdb20 (Init's case 106) The fart ring appears in front, 20 up. +static void fart_ring_init(Entity_Effect& ring) +{ + ring.sprite.Play("Appear"); + ring.renderZOffset = FOOT_RENDER_Z; + ring.posOffset.y = FART_RING_HEIGHT; +} + +// 0060151c (Update's case 106) The fart ring keeps up with its parent, poisons the vulnerable enemies around it every +// third frame, and dies once its player stops firing, fading out. +static void fart_ring_update(Entity_Effect& ring) +{ + if (ring.parent) ring.velocity = vector_sub(ring.parent->pos, ring.pos); + if (ring.isDead) + { + ring.sprite.Play("Dissappear"); + if (ring.sprite.IsFinished()) ring.Remove(); + return; + } + + if (ring.sprite.IsFinished("Appear")) ring.sprite.Play("Loop"); + if (ring.IsFrame(FART_RING_PERIOD, (int)ring.index)) + { + bool isVersus = g_game->deathmatchManager.is_active(); + for (Entity* entity : entity_query_radius(ring.pos, FART_RING_RADIUS, QUERY_ENEMIES)) + if (entity->IsVulnerableEnemy(nullptr) && !ring.IsDescendantOf(entity)) + entity->AddPoison(EntityRef(&ring), FART_RING_POISON, 0, isVersus); + } + auto* player = dynamic_cast(ring.parent.get()); + if (player && player->fireDirection == DIRECTION_NONE) ring.isDead = true; +} + +// Part of 005cdb20 (Init's case 83) The Spear of Destiny is a fire sword in the Guardian challenge. +static void spear_init(Entity_Effect& spear) +{ + if (g_game->challenge == CHALLENGE_GUARDIAN) spear.sprite.ReplaceSpritesheet(0, SPEAR_GUARDIAN_SHEET); +} + +// 005fea2f (Update's case 83) The Spear of Destiny stabs the vulnerable enemies and fires near its player's spear tip +// with the player's knife damage, frightening bosses, and chips the grid entity under it. +static void spear_update(Entity_Effect& spear) +{ + bool isGuardian = g_game->challenge == CHALLENGE_GUARDIAN; + if (spear.IsFrame(isGuardian ? SPEAR_GUARDIAN_HIT_RESET_FRAMES : SPEAR_HIT_RESET_FRAMES, (int)spear.index)) + spear.hitList.clear(); + + Entity* spawner = spear.spawnerEntity.get(); + if (spawner && spawner->is_player()) + { + float reach = isGuardian ? SPEAR_GUARDIAN_REACH : SPEAR_REACH; + EntityList_EL hits = entity_query_radius(spear.pos, reach, QUERY_ENEMIES); + TearParams params = static_cast(spawner)->GetTearHitParams(WEAPON_KNIFE, 1, + random_below(2) * 2 - 1, nullptr); + for (Entity* entity : hits) + { + bool isHittable = entity->IsVulnerableEnemy(nullptr) || entity->type == ENTITY_FIREPLACE; + if (!isHittable || EntityList::HitListContains(spear.hitList, *entity)) continue; + + float damage = params.tearDamage * (isGuardian ? 1 : SPEAR_DAMAGE_SCALE); + entity->TakeDamage(damage, 0, EntityRef(&spear), FIRE_HIT_COUNTDOWN); + if (entity->IsBoss()) entity->AddFear(EntityRef(spear.parent.get()), SPEAR_FEAR_FRAMES, false); + hit_list_insert(spear.hitList, *entity); + } + } + + int gridIndex = g_game->room->GetGridIndex(spear.pos); + if (gridIndex < 0) return; + if (GridEntity* grid = g_game->room->GetGridEntity((uint32_t)gridIndex)) grid->Hurt(1, EntityRef(spawner)); +} + +// Part of 005cdb20 (Init's case 105) The brown cloud puffs out in front. +static void brown_cloud_init(Entity_Effect& cloud) +{ + cloud.sprite.Play("PoofStart"); + cloud.renderZOffset = FOOT_RENDER_Z; +} + +// The brown cloud's life after its puff: it swells as its sting fades, hurts the vulnerable enemies inside it and is +// blown along by tears, dying after 300 frames. +static void brown_cloud_sting(Entity_Effect& cloud) +{ + if (cloud.IsFrame(BROWN_CLOUD_HIT_RESET_FRAMES, (int)cloud.index)) cloud.hitList.clear(); + float age = (float)cloud.state / BROWN_CLOUD_FRAMES; + float damageScale = BROWN_CLOUD_DAMAGE_FIRST + (BROWN_CLOUD_DAMAGE_LAST - BROWN_CLOUD_DAMAGE_FIRST) * age; + float size = BROWN_CLOUD_SIZE_FIRST + (BROWN_CLOUD_SIZE_LAST - BROWN_CLOUD_SIZE_FIRST) * age; + cloud.sprite.scale = vector_make(size, size); + + Entity* spawner = cloud.spawnerEntity.get(); + float damage = BROWN_CLOUD_DEFAULT_DAMAGE; + if (spawner && spawner->is_player()) + damage = static_cast(spawner)->GetTearHitParams(WEAPON_TEARS, 1, 1, nullptr).tearDamage; + damage *= damageScale; + + float reach = cloud.sprite.scale.x * BROWN_CLOUD_REACH; + for (Entity* entity : entity_query_radius(cloud.pos, reach, QUERY_ENEMIES)) + { + if (!entity->IsVulnerableEnemy(nullptr) || cloud.IsDescendantOf(entity)) continue; + if (EntityList::HitListContains(cloud.hitList, *entity)) continue; + entity->TakeDamage(damage, 0, EntityRef(&cloud), FIRE_HIT_COUNTDOWN); + hit_list_insert(cloud.hitList, *entity); + } + for (Entity* tear : entity_query_radius(cloud.pos, reach, QUERY_TEARS)) + { + if (tear->type != ENTITY_TEAR) continue; + if (g_game->deathmatchManager.is_active() && !cloud.IsDescendantOf(tear->spawnerEntity.get())) continue; + float push = 1 - vector_length(vector_sub(tear->pos, cloud.pos)) / reach; + cloud.velocity = vector_add(cloud.velocity, vector_scale(tear->velocity, push * BROWN_CLOUD_BLOW)); + } + if ((uint32_t)++cloud.state >= BROWN_CLOUD_FRAMES) cloud.isDead = true; +} + +// 00600dfc (Update's case 105) The brown cloud puffs out, then stings (see above) and at last puffs away, drifting to a +// stop inside the room. +static void brown_cloud_update(Entity_Effect& cloud) +{ + if (cloud.isDead) + { + cloud.sprite.Play("PoofEnd"); + if (cloud.sprite.IsFinished()) cloud.Remove(); + } + else if (cloud.state != 0) brown_cloud_sting(cloud); + else if (cloud.sprite.IsFinished()) + { + cloud.sprite.Play("PoofLoop"); + cloud.state++; + } + cloud.velocity = vector_scale(cloud.velocity, BROWN_CLOUD_DRAG); + cloud.pos = g_game->room->GetClampedPosition(cloud.pos, 0); +} + +// Part of 005cdb20 (Init's case 60) The boomerang spins off, 20 up, whirring and stopped by walls. +static void boomerang_init(Entity_Effect& boomerang) +{ + boomerang.entityGridCollisionClass = GRIDCOLL_WALLS; + boomerang.sprite.Play("Rotate"); + boomerang.posOffset = vector_make(0, BOOMERANG_HEIGHT); + overridden_sound_play(SOUND_BOOMERANG_LOOP, {.loop = SOUND_LOOP}); +} + +// The first pickup the boomerang touches that can be taken becomes its catch. A sticky nickel only rattles. +static void boomerang_grab(Entity_Effect& boomerang) +{ + for (Entity* entity : entity_query_radius(boomerang.pos, boomerang.size, QUERY_PICKUPS)) + { + auto* pickup = dynamic_cast(entity); + if (!pickup || !pickup->CanBePickedUp(false)) continue; + if (pickup->variant == PICKUP_COIN && pickup->subtype == COIN_STICKYNICKEL) + { + if (pickup->sprite.IsPlaying("Touched")) continue; + pickup->sprite.Play("Touched"); + pickup->collisionCooldown = STICKY_NICKEL_COOLDOWN; + continue; + } + boomerang.child = pickup; + overridden_sound_play(SOUND_BOOMERANG_HIT); + } +} + +// 005f4971 (Update's case 60) The boomerang carries its catch, hits the enemies it passes, and flies back to its +// thrower to be caught, dropping its catch there. +static void boomerang_update(Entity_Effect& boomerang) +{ + if (!boomerang.child) boomerang_grab(boomerang); + if (Entity* catch_ = boomerang.child.get()) + { + catch_->pos = boomerang.pos; + catch_->velocity = boomerang.velocity; + catch_->entityGridCollisionClass = GRIDCOLL_NONE; + } + + for (Entity* entity : entity_query_radius(boomerang.pos, boomerang.size, QUERY_ENEMIES)) + { + if (!entity->IsEnemy()) continue; + if (boomerang.spawnerEntity && boomerang.spawnerEntity->IsDescendantOf(entity)) continue; + if (entity->isDead || entity->entityCollisionClass == ENTCOLL_NONE) continue; + if (EntityList::HitListContains(boomerang.hitList, *entity)) continue; + + entity->TakeDamage(boomerang.collisionDamage, 0, EntityRef(&boomerang), FIRE_HIT_COUNTDOWN); + entity->AddFreeze(EntityRef(&boomerang), BOOMERANG_FREEZE, false); + entity->AddVelocity(boomerang.velocity, false); + hit_list_insert(boomerang.hitList, *entity); + overridden_sound_play(SOUND_BOOMERANG_HIT); + } + + if (boomerang.isCollidesWithGrid) + { + boomerang.timeout = 1; + overridden_sound_play(SOUND_BOOMERANG_HIT); + } + if (boomerang.timeout < BOOMERANG_SLOWING_FRAMES) boomerang.friction *= BOOMERANG_FRICTION; + if (boomerang.timeout < 2) + { + boomerang.entityGridCollisionClass = GRIDCOLL_NONE; + boomerang.timeout = 2; + if (Entity* thrower = boomerang.parent.get()) + { + float speed = std::min(vector_length(boomerang.velocity) + 1, BOOMERANG_RETURN_SPEED); + boomerang.velocity = vector_scale(vector_normalized(vector_sub(thrower->pos, boomerang.pos)), speed); + float distance = vector_length(vector_sub(thrower->pos, boomerang.pos)); + if (distance <= thrower->size + boomerang.size) + { + boomerang.isDead = true; + overridden_sound_play(SOUND_BOOMERANG_CATCH); + if (boomerang.child) boomerang.child->entityGridCollisionClass = GRIDCOLL_WALLS; + } + } + } + + if (boomerang.isDead) boomerang.Remove(); + else if (!g_manager->sfxManager.IsPlaying(SOUND_BOOMERANG_LOOP)) + overridden_sound_play(SOUND_BOOMERANG_LOOP, {.loop = SOUND_LOOP}); +} + +// Part of 005cdb20 (Init's case 185) Redemption's sign hangs behind its player, its glow additive. +static void redemption_init(Entity_Effect& sign) +{ + layer_additive_set(*sign.sprite.GetLayer(1)); + sign.renderDepthOffset = REDEMPTION_DEPTH; + sign.sprite.Play("Idle"); +} + +// 006056fc (Update's case 185) Redemption's sign rides its player. It fails once the player puts the item away, or +// on success grants a damage up and soul hearts with a flash, then goes. +static void redemption_update(Entity_Effect& sign) +{ + Entity* parent = sign.parent.get(); + Entity_Player* player = parent ? parent->ToPlayer() : nullptr; + if (parent) + { + sign.pos = parent->pos; + sign.velocity = parent->velocity; + sign.posOffset = parent->posOffset; + sign.sprite.scale = parent->sprite.scale; + } + + if (sign.state == REDEMPTION_WAITING) + { + if (!player || player->IsHoldingItem()) return; + sign.state = REDEMPTION_FAIL; + overridden_sound_play(SOUND_THUMBS_DOWN); + } + else if (sign.state == REDEMPTION_SUCCESS) + { + sign.sprite.Play("Success"); + if (!sign.sprite.IsFinished()) return; + if (player) + { + player->bonusDamageUps++; + player->cacheFlags |= CACHE_DAMAGE; + player->EvaluateItems(); + player->AddSoulHearts(REDEMPTION_SOUL_HEARTS, false); + player->AnimateHappy(); + player->SetColor(REDEMPTION_FLASH, REDEMPTION_FLASH_FRAMES, 1, true, true); + overridden_sound_play(SOUND_POWERUP_SPEWER); + } + sign.Remove(); + } + else if (sign.state == REDEMPTION_FAIL) + { + sign.sprite.Play("Fail"); + if (sign.sprite.IsEventTriggered("Poof")) + { + Entity* poof = g_game->Spawn( + {.position = sign.pos, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); + Vector scale = sign.sprite.scale; + poof->posOffset = vector_make(0, REDEMPTION_POOF_HEIGHT * scale.y); + poof->sprite.scale = scale; + poof->Update(); + } + if (sign.sprite.IsFinished()) sign.Remove(); + } +} + +// The variants of this group by their Init, Update and Render. Those that only play their animation share Update's +// poof case. The empty ones have no Init or Update case in the original. +constexpr auto ITEM_EFFECT_BEHAVIOURS = std::to_array({ + {0, nullptr, nullptr, nullptr}, + {EFFECT_LADDER, ladder_init, nullptr, nullptr}, + {EFFECT_BLUE_FLAME, fire_init, effect_finishing, nullptr}, + {EFFECT_SCYTHE_BREAK, nullptr, effect_poof_update, nullptr}, + {EFFECT_MONSTROS_TOOTH, nullptr, effect_finishing, nullptr}, + {EFFECT_MOM_FOOT_STOMP, foot_init, effect_finishing, nullptr}, + {EFFECT_XRAY_WALL, xray_wall_init, effect_finishing, nullptr}, + {EFFECT_STARFLASH, nullptr, effect_poof_update, nullptr}, + {EFFECT_BOOMERANG, boomerang_init, effect_finishing, nullptr}, + {EFFECT_HOT_BOMB_FIRE, fire_init, effect_finishing, nullptr}, + {EFFECT_RED_CANDLE_FLAME, fire_init, effect_finishing, nullptr}, + {EFFECT_BAR_PARTICLE, bar_particle_init, effect_finishing, nullptr}, + {EFFECT_SPEAR_OF_DESTINY, spear_init, effect_finishing, nullptr}, + {EFFECT_ULTRA_GREED_FOOTPRINT, footprint_init, nullptr, nullptr}, + {EFFECT_MOMS_HAND_CONTACT, moms_hand_init, effect_finishing, nullptr}, + {EFFECT_ULTRA_GREED_BLING, bling_init, effect_finishing, nullptr}, + {EFFECT_DEATH_SKULL, death_skull_init, effect_finishing, nullptr}, + {EFFECT_BROWN_CLOUD, brown_cloud_init, effect_finishing, nullptr}, + {EFFECT_FART_RING, fart_ring_init, effect_finishing, nullptr}, + {EFFECT_FORGOTTEN_SOUL, forgotten_soul_init, forgotten_soul_update, nullptr}, + {EFFECT_OPTION_LINE, kept_idle_init, nullptr, nullptr}, + {EFFECT_UNUSED_129, nullptr, nullptr, nullptr}, + {EFFECT_LEECH_EXPLOSION, leech_explosion_init, effect_poof_update, nullptr}, + {EFFECT_MAGGOT_EXPLOSION, nullptr, effect_poof_update, nullptr}, + {EFFECT_GRID_ENTITY_PROJECTILE_HELPER, hidden_init, effect_finishing, nullptr}, + {EFFECT_WORMWOOD_HOLE, wormwood_hole_init, effect_finishing, nullptr}, + {EFFECT_WHIRLPOOL, whirlpool_init, effect_poof_update, nullptr}, + {EFFECT_FARTWAVE, spreading_wave_init, effect_finishing, nullptr}, + {EFFECT_FIRE_JET, nullptr, effect_finishing, nullptr}, + {EFFECT_FIRE_WAVE, spreading_wave_init, effect_finishing, nullptr}, + {EFFECT_HORNFEL_ROOM_CONTROLLER, hidden_kept_init, effect_finishing, nullptr}, + {EFFECT_BISHOP_SHIELD, nullptr, bishop_shield_update, nullptr}, + {EFFECT_HERETIC_PENTAGRAM, floor_init, effect_poof_update, nullptr}, + {EFFECT_SIREN_RING, siren_ring_init, effect_poof_update, nullptr}, + {EFFECT_DOGMA_DEBRIS, dogma_debris_init, effect_finishing, nullptr}, + {EFFECT_CRACKED_ORB_POOF, soft_poof_init, effect_poof_update, nullptr}, + {EFFECT_SHOP_SPIKES, shop_spikes_init, effect_finishing, nullptr}, + {EFFECT_KINETI_BEAM, nullptr, effect_finishing, nullptr}, + {EFFECT_WORM_FRIEND_SNARE, nullptr, effect_finishing, nullptr}, + {EFFECT_CLEAVER_SLASH, nullptr, effect_finishing, nullptr}, + {EFFECT_MOTHER_SHOCKWAVE, hidden_init, mother_shockwave_update, nullptr}, + {EFFECT_EXPLOSION_WAVE, hidden_init, explosion_wave_update, nullptr}, + {EFFECT_GROUND_GLOW, ground_glow_init, effect_finishing, ground_glow_render}, + {EFFECT_REDEMPTION, redemption_init, effect_finishing, nullptr}, + {EFFECT_ULTRA_DEATH_SCYTHE, scythe_init, effect_finishing, nullptr}, + {EFFECT_BULLET_POOF_STATIC, static_poof_init, effect_poof_update, nullptr}, + {EFFECT_GUN, nullptr, nullptr, nullptr}, +}); + +std::span item_effect_behaviours() +{ + return ITEM_EFFECT_BEHAVIOURS; +} diff --git a/src/entity_familiar.cpp b/src/entity_familiar.cpp index d2e0f38..548d57b 100644 --- a/src/entity_familiar.cpp +++ b/src/entity_familiar.cpp @@ -5,6 +5,7 @@ #include "entity_list.h" #include "entity_player.h" #include "entity_player_forgotten.h" +#include "familiar_gello.h" #include "game_state_player.h" #include "log.h" #include "lua_engine.h" @@ -35,8 +36,8 @@ constexpr std::pair ORBIT_LAYERS[] = { {121, 5}, {128, 5}, {84, 4}, {123, 4}, {204, 6}, {216, 6}, {217, 6}, {229, 10}, {237, 8}}; // The familiars whose setup, drawing and links wait for their takeovers. -constexpr int UNWRITTEN_INIT_VARIANTS[] = {48, 62, 121, 122, 128, 131, 228, 231, 233, 234, 236, 238, 239, 240}; -constexpr int UNWRITTEN_RENDER_VARIANTS[] = {48, 68, 75, 78, 79, 231, 240, 243}; +constexpr int UNWRITTEN_INIT_VARIANTS[] = {48, 62, 122, 131, 228, 231, 233, 234, 236, 238, 239}; +constexpr int UNWRITTEN_RENDER_VARIANTS[] = {48, 68, 75, 78, 79, 231, 243}; // The familiars that walk, Init's grid collision for them, and the ones whose hit list survives the reset. constexpr int GROUND_VARIANTS[] = {46, 47, 71, 72, 48, 56, 73}; @@ -158,6 +159,23 @@ constexpr int JUICY_SACK_CREEP_INTERVAL = 4; constexpr float TRAIL_SCALE_RANGE = 0.5f; constexpr float TRAIL_SCALE_MIN = 0.2f; +// Leprosy's four looks. A bone orbital's eight looks, its generator's shifts, how its orbit varies and how it slows +// while appearing. The orbiting flies' lead on the player, their pull and their speed limit as they settle in. +constexpr std::string_view LEPROSY_ANIMS[] = {"Idle", "Idle2", "Idle3", "Idle4"}; +constexpr uint32_t BONE_LOOKS = 8; +constexpr uint32_t BONE_RNG_SHIFT = 13; +constexpr float BONE_ORBIT_MIN = 0.8f; +constexpr float BONE_ORBIT_RANGE = 0.3f; +constexpr float BONE_APPEAR_FRICTION = 0.8f; +constexpr float ORBIT_CHASE_LEAD = 2; +constexpr float ORBIT_CHASE_PULL = 0.5f; +constexpr int ORBIT_CHASE_SETTLE_FRAMES = 40; +constexpr int ORBIT_CHASE_SETTLE_START = 10; +constexpr float ORBIT_CHASE_SETTLE_SPAN = 30; +constexpr float ORBIT_CHASE_SETTLE_MIN = 0.06f; +constexpr float ORBIT_CHASE_LIMIT = 5; +constexpr float ORBIT_CHASE_LIMIT_BASE = 4; + // How much bigger the familiars of BFFS! and Hive Mind look. constexpr float LOCUST_MULTIPLIED_SCALE = 1.1f; constexpr float MULTIPLIED_SCALE = 1.25f; @@ -398,6 +416,23 @@ void Entity_Familiar::Init(int initType, int initVariant, int initSubtype, uint3 variant_finish(); } +// Part of 0060de70: a bone orbital picks one of eight looks (appearing when new), a side and a wider or tighter orbit, +// and hits as hard as the player's melee. +static void bone_orbital_init(Entity_Familiar& bone) +{ + RNG rng; + rng.SetSeed(bone.dropRNG._seed, BONE_RNG_SHIFT); + bool isNew = bone.subtype == 0; + uint32_t look = rng.RandomInt(BONE_LOOKS); + bone.subtype = (int)look + 1; + char name[32]; + std::snprintf(name, sizeof(name), isNew ? "Appear%u" : "Idle%u", look); + bone.sprite.Play(name); + bone.sprite.isFlipX = rng.RandomInt(2) == 0; + bone.orbitDistance = vector_scale(bone.orbitDistance, rng.RandomFloat() * BONE_ORBIT_RANGE + BONE_ORBIT_MIN); + bone.collisionDamage = bone.player->meleeDamage; +} + // Part of 0060de70: what each variant starts with. The rarer familiars stop the game. void Entity_Familiar::variant_init(int initSubtype) { @@ -452,6 +487,11 @@ void Entity_Familiar::variant_init(int initSubtype) maxHitPoints = MILK_HEALTH; health = MILK_HEALTH; break; + case LEPROSY: + subtype = (int)dropRNG.RandomInt((uint32_t)std::size(LEPROSY_ANIMS)); + sprite.Play(LEPROSY_ANIMS[subtype]); + break; + case BONE_ORBITAL: bone_orbital_init(*this); break; } } @@ -476,6 +516,7 @@ void Entity_Familiar::variant_finish() state = 0; break; case BLOOD_PUPPY: state = 0; break; + case UMBILICAL_BABY: umbilical_baby_init(*this); break; } if ((variant == CENSER || variant == SUCCUBUS) && sprite.layerStates.size() > 1) sprite.GetLayer(1)->bitflags = 1; } @@ -635,6 +676,36 @@ static void dry_baby_update(Entity_Familiar& baby) if (baby.fireCooldown > 0) baby.fireCooldown--; } +// Part of 0061da10: the orbiting flies and bones chase their orbit spot ahead of the player's motion, faster as they +// settle in after spawning. +static void orbit_chase(Entity_Familiar& familiar) +{ + Vector goal = familiar.GetOrbitPosition(familiar.player->pos); + Vector lead = vector_scale(familiar.player->velocity, ORBIT_CHASE_LEAD); + Vector pull = vector_scale(vector_sub(goal, vector_add(familiar.pos, lead)), ORBIT_CHASE_PULL); + int age = familiar.FrameCount(); + float settle = std::clamp((float)(age - ORBIT_CHASE_SETTLE_START) / ORBIT_CHASE_SETTLE_SPAN, ORBIT_CHASE_SETTLE_MIN, 1.0f); + float limit = age < ORBIT_CHASE_SETTLE_FRAMES ? 1 / settle + ORBIT_CHASE_LIMIT_BASE : ORBIT_CHASE_LIMIT; + if (vector_length(pull) > limit) pull = vector_resized(pull, limit - 1); + familiar.velocity = vector_scale(vector_add(lead, pull), 1 / familiar.friction); +} + +// Part of 0061da10: a bone orbital slows while it appears and then idles in its look from a random frame, then +// orbits. +static void bone_orbital_update(Entity_Familiar& bone) +{ + ANM2& sprite = bone.sprite; + if (sprite.animState.IsLoopingAnimation()) return orbit_chase(bone); + + bone.friction *= BONE_APPEAR_FRICTION; + if (!sprite.IsFinished()) return; + + char name[32]; + std::snprintf(name, sizeof(name), "Idle%d", bone.subtype - 1); + sprite.Play(name); + sprite.SetFrame((float)random_below(sprite.animState.GetAnimationLength())); +} + // Part of 0061da10: Abel follows the player's mirror image across the room's centre and shoots. static void abel_update(Entity_Familiar& abel) { @@ -745,6 +816,9 @@ void Entity_Familiar::variant_update() case WISP: case ITEM_WISP: return ai_wisp(); case KEY_FULL: return ai_key_full(); + case UMBILICAL_BABY: return ai_umbilical_baby(false); + case BONE_ORBITAL: return bone_orbital_update(*this); + case SWARM_FLY_ORBITAL: return orbit_chase(*this); default: reconstruction_missing("Entity_Familiar::Update 0061da10 (this familiar's behaviour)"); } } @@ -807,13 +881,14 @@ 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, -// Lil Brimstone charges, and the other variants that act on interpolation stop the game. +// Lil Brimstone charges, Gello moves on, and the other variants that act on interpolation stop the game. void Entity_Familiar::Interpolate() { - if (variant == DAMOCLES || variant == BLOOD_BABY || variant == UMBILICAL_BABY) + if (variant == DAMOCLES || variant == BLOOD_BABY) reconstruction_missing("Entity_Familiar::Interpolate 00624a80 (this familiar's interpolation)"); if (variant == LIL_BRIMSTONE) ai_incubus_shot(); if (variant == INCUBUS) update_weapon(true); + if (variant == UMBILICAL_BABY) ai_umbilical_baby(true); float savedAngle = orbitAngleOffset; if (orbitLayer >= 0) @@ -833,7 +908,8 @@ void Entity_Familiar::Interpolate() } // 00624e10 Draws a familiar with its charge bar. The familiars drawn their own way (Isaac's body, Samson's chains, the -// locusts, the co-op babies) and Tainted Lazarus's hologram stop the game. An item wisp shows its item's icon. +// locusts, the co-op babies) and Tainted Lazarus's hologram stop the game. Gello draws its cord first, and an item wisp +// shows its item's icon. void Entity_Familiar::Render(const Vector& offset) { if (IsLilithBirthrightIncubus()) @@ -847,7 +923,8 @@ void Entity_Familiar::Render(const Vector& offset) return reconstruction_missing("Entity_Familiar::Render 00624e10 (this familiar's drawing)"); ColorMod saved = sprite.color; - Entity::Render(offset); + if (variant == UMBILICAL_BABY) umbilical_baby_render(*this, offset); + else Entity::Render(offset); if (variant == ITEM_WISP) item_wisp_icon_render(*this); lua_engine_get().PostFamiliarRender(this, offset); render_charge_indicator(renderPosition); @@ -940,12 +1017,12 @@ void Entity_Familiar::Remove() ResolveOrbitConflict(); } -// 006121d0 Drops its links and its weapon. A Fortune Cookie wisp takes its luck back. Gello's cord stops the game. +// 006121d0 Drops its links and its weapon. Gello removes its cord helper, and a Fortune Cookie wisp takes its luck +// back. void Entity_Familiar::ClearReferences() { if (variant == FORGOTTEN_BODY) forgotten_body_clear(*this); - if (variant == UMBILICAL_BABY) - reconstruction_missing("Entity_Familiar::ClearReferences 006121d0 (Gello's cord)"); + if (variant == UMBILICAL_BABY && linkedEntity) linkedEntity->Remove(); if ((variant == WISP || variant == ITEM_WISP) && subtype == COLLECTIBLE_FORTUNE_COOKIE) { player->cacheFlags |= CACHE_LUCK; diff --git a/src/entity_familiar.h b/src/entity_familiar.h index 88fe704..b40979b 100644 --- a/src/entity_familiar.h +++ b/src/entity_familiar.h @@ -207,6 +207,7 @@ struct Entity_Familiar : Entity TINYTOMA = 216, BOT_FLY = 218, PASCHAL_CANDLE = 221, + STITCHES = 222, KNIFE_FULL = 223, BABY_PLUM = 224, FRUITY_PLUM = 225, diff --git a/src/entity_knife_hits.cpp b/src/entity_knife_hits.cpp index 7a087d6..56bae35 100644 --- a/src/entity_knife_hits.cpp +++ b/src/entity_knife_hits.cpp @@ -469,7 +469,7 @@ static uint64_t swing_damage_flags(Entity_Knife& knife, Entity& enemy, Entity_Pl if (isFly && player->numBlueFlies <= SWING_BLUE_FLY_MAX) flags = DAMAGE_SPAWN_FLY; } if (knife.variant == KNIFE_NOTCHED_AXE) flags |= DAMAGE_CRUSH; - if (knife.HasEntityFlags(FLAG_BLEED_OUT)) flags |= DAMAGE_CLONES; + if (knife.HasEntityFlags(FLAG_BLEED_OUT)) flags |= DAMAGE_SPAWN_TEMP_HEART; if (is_axe_empowered(knife)) flags |= DAMAGE_CHAMPION_REWARD; return flags; } diff --git a/src/entity_laser.cpp b/src/entity_laser.cpp index 47747b8..b11fcbc 100644 --- a/src/entity_laser.cpp +++ b/src/entity_laser.cpp @@ -85,7 +85,6 @@ constexpr int SPAWNER_CAGE = 265; constexpr int SPAWNER_FORSAKEN = 403; constexpr int SPAWNER_MEGA_SATAN = 274; constexpr int SPAWNER_DOGMA = 950; -constexpr int SPAWNER_MONSTRO_2 = 43; constexpr int SPAWNER_MOMS_HEART_LASER = 49; constexpr int SPAWNER_EYE = 60; constexpr int SPAWNER_PIN = 62; @@ -124,45 +123,11 @@ static float random_fraction() return random_unit(); } -// A colorize from a hue in degrees, a saturation and a value at a strength, as hsv_to_rgb makes the color. +// A colorize from a hue in degrees, a saturation and a value at a strength (hsv_to_rgb). static ColorMod colorize_from_hue(float hue, float saturation, float value, float strength) { - float chroma = saturation * value; - float second = (1 - std::abs(std::fmod(hue / 60, 2.0f) - 1)) * chroma; - float red = 0; - float green = 0; - float blue = 0; - switch ((int)(hue / 60) % 6) - { - case 0: - red = chroma; - green = second; - break; - case 1: - red = second; - green = chroma; - break; - case 2: - green = chroma; - blue = second; - break; - case 3: - green = second; - blue = chroma; - break; - case 4: - red = second; - blue = chroma; - break; - case 5: - red = chroma; - blue = second; - break; - default: - break; - } - float base = value - chroma; - return {{1, 1, 1, 1}, {(red + base) * strength, (green + base) * strength, (blue + base) * strength, 1}, {0, 0, 0}}; + KColor color = hsv_to_rgb(hue, saturation, value, 1); + return {{1, 1, 1, 1}, {color._red * strength, color._green * strength, color._blue * strength, 1}, {0, 0, 0}}; } // The player a laser's tears come from: its spawner, or the player of a familiar that fires the player's lasers. @@ -468,7 +433,7 @@ void Entity_Laser::PlayInitSound() case LASER_BRIM_TECH: if (!spawnerEntity) return laser_sound_play(SOUND_BLOOD_LASER, {}); if (spawner == SPAWNER_EYE) return laser_sound_play(SOUND_REDLIGHTNING_ZAP_STRONG, {}); - if (spawner == SPAWNER_MONSTRO_2 || spawner == SPAWNER_MOMS_HEART_LASER) + if (spawner == ENTITY_MONSTRO2 || spawner == SPAWNER_MOMS_HEART_LASER) return laser_sound_play(SOUND_BLOOD_LASER_LARGE, {}); if (spawner == ENTITY_SATAN) return laser_sound_play(SOUND_SATAN_HAND_LASER, {}); if (spawner == SPAWNER_FORSAKEN) return laser_sound_play(SOUND_FORSAKEN_LASER, {.loop = SOUND_LOOP}); diff --git a/src/entity_npc.cpp b/src/entity_npc.cpp index b8d6c02..c0b1762 100644 --- a/src/entity_npc.cpp +++ b/src/entity_npc.cpp @@ -5,6 +5,7 @@ #include "entity_config.h" #include "entity_effect.h" #include "entity_familiar.h" +#include "entity_laser.h" #include "entity_pickup.h" #include "entity_player.h" #include "entity_projectile.h" @@ -37,7 +38,6 @@ constexpr int ENTITY_FEAR_IMMUNE = 205; constexpr int ENTITY_NO_DECOY_TYPE = 213; constexpr uint32_t DOPLE_PICK_SHIFT = 11; constexpr int ENTITY_UNREACHABLE_EXEMPT = 886; -constexpr int ENTITY_FLICKER_TYPE = 252; constexpr int ENTITY_DEATH_SPARK_TYPE = 882; constexpr int ENTITY_DAMAGE_NUMBERS_TYPE = 964; constexpr int ENTITY_ERASE_EXEMPT = 950; @@ -48,6 +48,7 @@ constexpr std::array FLUSH_TYPES = {217, 220, 223, 261, 402, 870, 871, 8 constexpr int FLUSH_PROP_TYPE = 237; constexpr int FLUSH_PROP_VARIANT = 2; constexpr int FLUSH_RENDER_Z = 5000; +constexpr int HUSH_ASH_SHAKE = 30; // 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; @@ -74,7 +75,6 @@ constexpr int ENTITY_FORWARD_DOWN_A = 262; constexpr int ENTITY_FORWARD_DOWN_B = 263; constexpr int DEATH_NO_BURST_FIRST = 74; constexpr int DEATH_NO_BURST_LAST = 76; -constexpr int MULLIGAN_VARIANT_FLEEING = 2; constexpr int CHALLENGE_KILL_CHARGE = 33; constexpr std::string_view BIG_HORN_SPLASH_EVENT = "Poof"; constexpr std::string_view DIRT_LAYER = "dirt"; @@ -88,7 +88,6 @@ constexpr int MORPH_COLOR_PRIORITY = -1000; constexpr ColorMod COLOR_INVISIBLE = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0}}; constexpr int UNREACHABLE_CHECK_FRAMES = 60; constexpr int UNREACHABLE_GRACE_FRAMES = 900; -constexpr int SHRINK_PULSE_FRAMES = 60; constexpr float MIDAS_COIN_SPEED = 3; constexpr float TOXIC_CREEP_SCALE = 0.05f; constexpr int TOXIC_SHOCK_POISON = -40; @@ -116,6 +115,32 @@ constexpr float SHIELD_SECOND = 30; constexpr float SHIELD_BASE = 0.09f; constexpr float SHIELD_FALLOFF = 0.18f; constexpr uint32_t BLACK_HEART_CHANCE = 5; +constexpr uint32_t STICKY_SPIDERS_RANGE = 3; +constexpr uint32_t STICKY_SPIDERS_BLAST_RANGE = 5; +constexpr int JAR_OF_FLIES_MAX = 20; +constexpr float HALF_SPEED = 0.5f; +constexpr float LADDER_FOOT_MARGIN = 0.5f; +constexpr float LADDER_DROP_SPEED = 3.5f; + +// The kill items: Contagion's cloud, Athame's ring at a quarter plus a fortieth of the luck, and the soul wisps +// Book of Virtues takes from a captured enemy by its soul tag. +constexpr float CONTAGION_RADIUS = 85; +constexpr uint32_t ATHAME_RNG_SHIFT_INDEX = 66; +constexpr float ATHAME_BASE_CHANCE = 0.25f; +constexpr float ATHAME_LUCK_CHANCE = 0.025f; +constexpr int ATHAME_RING_TIMEOUT = 60; +constexpr int WISP_SOUL = 0x1000a; +constexpr int WISP_SOUL_EXPLOSIVE = 0x1000b; +constexpr int WISP_SOUL_HOMING = 0x1000c; +constexpr int WISP_SOUL_BRIMSTONE = 0x1000d; + +// A Brimstone marked enemy's burst: its mark and statuses spread within 120 with a hit of 10. +constexpr float MARK_SPREAD_RADIUS = 120; +constexpr int MARK_SPREAD_FRAMES = 150; +constexpr int STATUS_SPREAD_FRAMES = 90; +constexpr float MARK_SPREAD_DAMAGE = 10; +constexpr int MARK_SPREAD_COUNTDOWN = 30; +constexpr ColorMod SPREAD_SLOW_COLOR = {{1, 1, 1.3f, 1}, {0, 0, 0, 0}, {40 / 255.0f, 40 / 255.0f, 40 / 255.0f}}; constexpr int SOUND_POOP_DEATH = 237; constexpr float POOP_DEATH_VOLUME = 0.9f; constexpr uint64_t FLAG_FRIENDLY_BALL_DYING = 1ull << 60; @@ -146,9 +171,6 @@ constexpr int COLLECTIBLE_SOUL_ID = 335; constexpr int COLLECTIBLE_TOXIC_SHOCK_ID = 350; constexpr int COLLECTIBLE_BETRAYAL_ID = 391; constexpr int COLLECTIBLE_SPIDER_MOD_ID = 403; -constexpr int COLLECTIBLE_MAW_OF_THE_VOID_ID = 408; -constexpr int COLLECTIBLE_JAR_OF_FLIES_ID = 434; -constexpr int COLLECTIBLE_CONTAGION_ID = 466; constexpr int COLLECTIBLE_BROKEN_MODEM_ID = 514; constexpr int COLLECTIBLE_GUPPYS_EYE_ID = 665; constexpr int COLLECTIBLE_SALVATION_ID = 696; @@ -249,7 +271,7 @@ void npc_sound_play(int sound, float volume, int frameDelay, float pitch) } // The size class of the poofs and blood bursts an NPC leaves: 1 small to 4 huge, the last only when isHugeAllowed. -static int poof_size_get(Entity& entity, bool isHugeAllowed) +int poof_size_get(Entity& entity, bool isHugeAllowed) { int poof = entity.size < POOF_SMALL_SIZE ? 1 : 2; if (entity.size >= POOF_LARGE_SIZE || entity.shadowSize > POOF_LARGE_SHADOW) poof = 3; @@ -258,7 +280,7 @@ static int poof_size_get(Entity& entity, bool isHugeAllowed) } // Spawns an entity where an NPC stands. -static Entity* spawn_at(int type, int variant, int subType, const Vector& position, Entity* spawner) +Entity* spawn_at(int type, int variant, int subType, const Vector& position, Entity* spawner) { return g_game->Spawn({.position = position, .spawner = spawner, @@ -371,7 +393,7 @@ static float target_score_get(const Vector& position, Entity* source, Entity& ta // 007069a0 What an enemy at a position goes after: the nearest visible player within reach (Dark Esau only Jacob), // else a Punching Bag or a baited enemy. An enemy forced onto a target keeps it. -// The stand-in targets players keep (Entity_Player 0x144c and 0x1450) wait for Entity_Player to name them. +// The stand-in target a player keeps at Entity_Player 0x144c waits for Entity_Player to name it. Entity* game_nearest_target_player(const Vector& position, Entity* source, bool isPlayersOnly, bool isTargetDecoys, float maxDistance) { @@ -396,7 +418,8 @@ Entity* game_nearest_target_player(const Vector& position, Entity* source, bool if (source && source->IsFriendly() && source->IsDamageSourceFriendly(EntityRef(candidate))) continue; Entity* target = candidate; - if (!isPlayersOnly && candidate->darkArtsLastSnare) target = candidate->darkArtsLastSnare->GetLastParent(); + if (!isPlayersOnly && candidate->bestFriend) target = candidate->bestFriend.get(); + else if (!isPlayersOnly && candidate->darkArtsLastSnare) target = candidate->darkArtsLastSnare->GetLastParent(); Entity_Player* player = target && target->type == ENTITY_PLAYER ? static_cast(target) : nullptr; if (!target) continue; @@ -866,247 +889,9 @@ void Entity_NPC::SetBossColorIdx(int bossColorIdx, int) ResetColor(); } -// A champion color's look, the exe's table at 00c354c0: the color its _champion sheets draw in (none without alpha) -// and the color its sprite otherwise shows. -struct ChampionLook -{ - ColorMod sheetColor; - ColorMod spriteColor; -}; - -// A look from its sheet color's channels and its sprite's tint and offset. -constexpr ChampionLook champion_look(float red, float green, float blue, float alpha, ColorMod spriteColor = COLOR_DEFAULT) -{ - return {{{red, green, blue, alpha}, {0, 0, 0, 0}, {0, 0, 0}}, spriteColor}; -} - -constexpr float CHAMPION_GLOW = 30 / 255.0f; -constexpr std::array CHAMPION_LOOKS = {{ - champion_look(1, 0.1f, 0.1f, 1), - champion_look(0.6f, 0.6f, 0, 1), - champion_look(0.1f, 0.8f, 0.2f, 1), - champion_look(1, 0.6f, 0.2f, 1), - champion_look(0.2f, 0.2f, 1, 1), - champion_look(0.03f, 0.24f, 0.24f, 1), - champion_look(1, 1, 1, 1, {{1, 1, 1, 1}, {0, 0, 0, 0}, {90 / 255.0f, 90 / 255.0f, 90 / 255.0f}}), - champion_look(0.5f, 0.5f, 0.5f, 1), - champion_look(1, 1, 1, 1, {{1, 1, 1, 0.6f}, {0, 0, 0, 0}, {120 / 255.0f, 120 / 255.0f, 120 / 255.0f}}), - champion_look(0, 0, 0, 0, {{0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0}}), - champion_look(1, 0, 1, 1), - champion_look(0.75f, 0, 1, 1), - champion_look(0.5f, 0, 0, 1), - champion_look(0.5f, 0.5f, 1, 1), - champion_look(0, 0, 0, 0), - champion_look(0.1f, 0.8f, 0.2f, 1, {{0.9f, 1, 0.9f, 1}, {0, 0, 0, 0}, {0, CHAMPION_GLOW, 0}}), - champion_look(0.5f, 0.5f, 0.5f, 1, {{0.9f, 0.9f, 0.9f, 1}, {0, 0, 0, 0}, {CHAMPION_GLOW, CHAMPION_GLOW, CHAMPION_GLOW}}), - champion_look(0.8f, 0.8f, 0.8f, 1, {{1, 1, 1, 1}, {0, 0, 0, 0}, {50 / 255.0f, 50 / 255.0f, 50 / 255.0f}}), - champion_look(0, 0, 0, 0), - champion_look(0, 0, 0, 0), - champion_look(1, 0.2f, 0.2f, 1, {{1, 0.9f, 0.9f, 1}, {0, 0, 0, 0}, {CHAMPION_GLOW, 0, 0}}), - champion_look(0, 0, 0, 0), - champion_look(0, 0, 0, 0), - champion_look(0.3f, 0.3f, 0.3f, 1, {{0.8f, 0.8f, 0.8f, 1}, {0, 0, 0, 0}, {0, 0, 0}}), - champion_look(0.28f, 0.14f, 0.134f, 1), - champion_look(1, 1, 1, 1), -}}; - -// The colors a seed's champion roll picks among: the common ones (the late stages' with yellow), the rare, the -// pulsing and sized, the late stages' special ones, and the late stages' uncommon ones. -constexpr std::array CHAMPIONS_EARLY = {CHAMPION_RED, CHAMPION_GREEN, CHAMPION_DARK_GREEN, - CHAMPION_GREY, CHAMPION_PINK, CHAMPION_LIGHT_BLUE}; -constexpr std::array CHAMPIONS_LATE = {CHAMPION_RED, CHAMPION_YELLOW, CHAMPION_GREEN, CHAMPION_DARK_GREEN, - CHAMPION_GREY, CHAMPION_PINK, CHAMPION_LIGHT_BLUE}; -constexpr std::array CHAMPIONS_RARE = {CHAMPION_ORANGE, CHAMPION_DARK_BLUE, CHAMPION_DARK_RED}; -constexpr std::array CHAMPIONS_PULSING = {CHAMPION_CAMO, CHAMPION_PULSE_GREEN, CHAMPION_PULSE_GREY, - CHAMPION_FLY_PROTECTED, CHAMPION_TINY, CHAMPION_GIANT}; -constexpr std::array CHAMPIONS_SPECIAL = {CHAMPION_PULSE_RED, CHAMPION_SIZE_PULSE, CHAMPION_KING, - CHAMPION_DEATH}; -constexpr std::array CHAMPIONS_UNCOMMON = {CHAMPION_TRANSPARENT, CHAMPION_FLICKER, CHAMPION_PURPLE, - CHAMPION_BROWN}; -constexpr uint32_t CHAMPION_RNG_SHIFT_INDEX = 33; -constexpr uint32_t CHAMPION_LATE_STAGE = 5; -constexpr uint32_t CHAMPION_YELLOW_STAGE = 3; -constexpr uint32_t CHAMPION_PULSING_EARLY_COUNT = 4; -constexpr float CHAMPION_ROLL_WHITE = 0.005f; -constexpr float CHAMPION_ROLL_RAINBOW = 0.01f; -constexpr float CHAMPION_ROLL_UNCOMMON = 0.05f; -constexpr float CHAMPION_ROLL_RARE = 0.15f; -constexpr float CHAMPION_ROLL_PULSING = 0.3f; -constexpr float CHAMPION_ROLL_SPECIAL = 0.35f; -constexpr std::array CHAMPION_NO_DARK_RED_TYPES = {240, 241, 242, 304}; -constexpr int ENTITY_NO_WHITE_CHAMPION = 889; - -// The champions' health, speed, size and contact damage, and the effect variant some keep around them. -constexpr float CHAMPION_SCALE = 1.15f; -constexpr float CHAMPION_TINY_SCALE = 0.5f; -constexpr float CHAMPION_GIANT_SCALE = 1.5f; -constexpr float CHAMPION_CONTACT_DAMAGE = 2; -constexpr float CHAMPION_DEATH_CONTACT_DAMAGE = 4; -constexpr float CHAMPION_HP_RED = 1.333f; -constexpr float CHAMPION_HP_YELLOW = 0.75f; -constexpr float CHAMPION_HP_GREY = 0.333f; -constexpr float CHAMPION_HP_BIG = 1.5f; -constexpr float CHAMPION_HP_KING = 3; -constexpr float CHAMPION_SPEED_FAST = 1.333f; -constexpr float CHAMPION_SPEED_SLOW = 0.8f; -constexpr float CHAMPION_SPEED_GIANT = 0.9f; -constexpr int CHAMPION_FLICKER_MIN = 60; -constexpr int CHAMPION_FLICKER_RANGE = 30; -constexpr int CHAMPION_SHOT_MIN = 40; -constexpr int CHAMPION_SHOT_RANGE = 20; -constexpr int EFFECT_PULLING = 57; -constexpr int CHAMPION_CREEP_FRAMES = 7; -constexpr int CHAMPION_CREEP_TIMEOUT = 30; -constexpr float CHAMPION_SHOT_SPEED = 5; -constexpr float CHAMPION_SHOT_FALL_ACCEL = 0.3f; -constexpr float CHAMPION_SHOT_FALL_SPEED = -5; -constexpr float FLICKER_FADE = 0.05f; constexpr ColorMod FRIENDLY_COLOR = {{0.8f, 0.8f, 0.8f, 1}, {1, 1, 1, -0.5f}, {0.1f, 0.1f, 0.1f}}; constexpr ColorMod FROZEN_COLOR = {{0.8f, 0.8f, 0.8f, 1}, {1, 1, 1, 0.5f}, {0.3f, 0.5f, 0.8f}}; -// Where a flickering champion is in its fade. -enum FlickerState : int -{ - FLICKER_SHOWN, - FLICKER_FADING_OUT, - FLICKER_FADING_IN, - FLICKER_HIDDEN -}; -constexpr int PULLING_PURPLE = 0; -constexpr int PULLING_GREY = 1; -constexpr int PULLING_RED = 2; -constexpr ColorMod PULLING_RED_COLOR = {{1, 0.2f, 0.2f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; - -// 00505b80 The color a champion shows over a sprite without its sheets: its sheet color laid over its sprite color -// (Color::__mul), or the sprite color for a look drawn on no sheet. -ColorMod champion_sprite_color_get(int championColor) -{ - const ChampionLook& look = CHAMPION_LOOKS[championColor]; - if (look.sheetColor._tint[3] <= 0) return look.spriteColor; - - ColorMod color = look.sheetColor; - const ColorMod& other = look.spriteColor; - for (int i = 0; i < 4; i++) color._tint[i] *= other._tint[i]; - if (other._colorize[0] + other._colorize[1] + other._colorize[2] != 0) - for (int i = 0; i < 4; i++) color._colorize[i] = other._colorize[i]; - for (int i = 0; i < 3; i++) color._offset[i] += other._offset[i]; - return color; -} - -// The sheet color of a champion color's look, or none for a look drawn on no _champion sheet. -const ColorMod* champion_color_get(int championColor) -{ - if (championColor < 0 || championColor >= CHAMPION_COUNT) return nullptr; - const ColorMod& sheetColor = CHAMPION_LOOKS[championColor].sheetColor; - return sheetColor._tint[3] > 0 ? &sheetColor : nullptr; -} - -// Part of 006d03e0: a seed's champion color by the stage: rarely white or rainbow and uncommonly a strange one late, -// else a rare, pulsing or sized, special late, or common one. -static int champion_color_roll(uint32_t seed) -{ - RNG rng; - rng.SetSeed(seed, CHAMPION_RNG_SHIFT_INDEX); - float roll = rng.RandomFloat(); - uint32_t stage = g_game->stage; - bool isLate = stage >= CHAMPION_LATE_STAGE; - - if (roll < CHAMPION_ROLL_RAINBOW && isLate) return roll < CHAMPION_ROLL_WHITE ? CHAMPION_WHITE : CHAMPION_RAINBOW; - if (roll < CHAMPION_ROLL_UNCOMMON && isLate) return CHAMPIONS_UNCOMMON[rng.RandomInt(CHAMPIONS_UNCOMMON.size())]; - if (roll < CHAMPION_ROLL_RARE) return CHAMPIONS_RARE[rng.RandomInt(CHAMPIONS_RARE.size())]; - if (roll < CHAMPION_ROLL_PULSING) - { - uint32_t count = stage >= CHAMPION_YELLOW_STAGE ? CHAMPIONS_PULSING.size() : CHAMPION_PULSING_EARLY_COUNT; - return CHAMPIONS_PULSING[rng.RandomInt(count)]; - } - if (roll < CHAMPION_ROLL_SPECIAL && isLate) return CHAMPIONS_SPECIAL[rng.RandomInt(CHAMPIONS_SPECIAL.size())]; - if (stage < CHAMPION_YELLOW_STAGE) return CHAMPIONS_EARLY[rng.RandomInt(CHAMPIONS_EARLY.size())]; - return CHAMPIONS_LATE[rng.RandomInt(CHAMPIONS_LATE.size())]; -} - -// Part of 006d03e0: what a champion color changes beside the look: health, speed, grid collision, timers, and the -// pulling effect or eternal fly some keep with them. -void Entity_NPC::champion_traits_apply(bool isInit) -{ - switch (championColorIdx) - { - case CHAMPION_RED: maxHitPoints *= CHAMPION_HP_RED; break; - case CHAMPION_YELLOW: - championSpeed = CHAMPION_SPEED_FAST; - maxHitPoints *= CHAMPION_HP_YELLOW; - break; - case CHAMPION_GREY: maxHitPoints *= CHAMPION_HP_GREY; [[fallthrough]]; - case CHAMPION_DARK_BLUE: championSpeed = CHAMPION_SPEED_SLOW; break; - case CHAMPION_TRANSPARENT: entityGridCollisionClass = GRIDCOLL_WALLS; break; - case CHAMPION_FLICKER: flickerTimer = random_below(CHAMPION_FLICKER_RANGE) + CHAMPION_FLICKER_MIN; break; - case CHAMPION_PINK: championTimer = random_below(CHAMPION_SHOT_RANGE) + CHAMPION_SHOT_MIN; break; - case CHAMPION_PURPLE: spawn_at(ENTITY_EFFECT, EFFECT_PULLING, PULLING_PURPLE, pos, this)->parent = this; break; - case CHAMPION_PULSE_GREY: spawn_at(ENTITY_EFFECT, EFFECT_PULLING, PULLING_GREY, pos, this)->parent = this; break; - case CHAMPION_FLY_PROTECTED: - if (!isInit) reconstruction_missing("Entity_NPC::MakeChampion 006d03e0: the fly protected champion's fly"); - break; - case CHAMPION_TINY: - maxHitPoints *= CHAMPION_HP_GREY; - championSpeed *= CHAMPION_SPEED_FAST; - break; - case CHAMPION_GIANT: - maxHitPoints *= CHAMPION_HP_BIG; - championSpeed *= CHAMPION_SPEED_GIANT; - [[fallthrough]]; - case CHAMPION_DEATH: - if (collisionDamage > 0) collisionDamage = CHAMPION_DEATH_CONTACT_DAMAGE; - break; - case CHAMPION_PULSE_RED: - { - Entity* pulling = spawn_at(ENTITY_EFFECT, EFFECT_PULLING, PULLING_RED, pos, this); - pulling->parent = this; - pulling->SetColor(PULLING_RED_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); - break; - } - case CHAMPION_KING: maxHitPoints *= CHAMPION_HP_KING; break; - case CHAMPION_RAINBOW: reconstruction_missing("Entity_NPC::MakeChampion 006d03e0: the rainbow champion"); - default: break; - } -} - -// 006d03e0 Makes it a champion of a color, or of one its seed draws for the stage at -1: twice the health and 2 -// contact damage, its size (half for the tiny, 1.5 for the giant, 1.15 else), its champion sprite and its color's -// traits. Dark red never befalls the slides and white not the fly protected kind. Only Init makes a champion twice. -void Entity_NPC::MakeChampion(uint32_t seed, int championColor, bool isInit) -{ - if (isChampion && !isInit) return; - - float baseMaxHitPoints = maxHitPoints; - maxHitPoints = baseMaxHitPoints + baseMaxHitPoints; - ResetColor(); - if (collisionDamage > 0) collisionDamage = CHAMPION_CONTACT_DAMAGE; - isChampion = true; - championColorIdx = championColor; - if (championColor < 0) championColor = champion_color_roll(seed); - - bool isNoDarkRed = std::ranges::find(CHAMPION_NO_DARK_RED_TYPES, type) != CHAMPION_NO_DARK_RED_TYPES.end(); - if (championColor == CHAMPION_DARK_RED && isNoDarkRed) championColor = CHAMPION_RED; - else if (championColor == CHAMPION_WHITE && type == ENTITY_NO_WHITE_CHAMPION) championColor = CHAMPION_FLY_PROTECTED; - championColorIdx = std::clamp(championColor, (int)CHAMPION_RED, (int)CHAMPION_RAINBOW); - - float championScale = CHAMPION_SCALE; - if (championColorIdx == CHAMPION_TINY) - { - SetSize(size * CHAMPION_TINY_SCALE, sizeMulti, config->gridCollisionPoints); - championScale = CHAMPION_TINY_SCALE; - } - else if (championColorIdx == CHAMPION_GIANT) championScale = CHAMPION_GIANT_SCALE; - scale = championScale; - sprite.scale = vector_make(championScale * shrinkStatus1, championScale * shrinkStatus1); - load_graphics(false); - champion_traits_apply(isInit); - - if (type == ENTITY_MULLIGAN && variant == MULLIGAN_VARIANT_FLEEING) - maxHitPoints = std::min(maxHitPoints, baseMaxHitPoints); - if (!isInit) health = maxHitPoints; - ResetColor(); -} - // The enemy a "random enemy" spawn (type 306) turns into on each stage, on Normal and on Hard. struct StageEnemy { @@ -1608,8 +1393,12 @@ void Entity_NPC::death_animation_update() death_events_update(*this); if (const NullFrame* bloodGuide = sprite.GetNullFrame("BloodGuide")) npc_blood_guide_update(*this, *bloodGuide); - if (type == ENTITY_HUSH && sprite.IsEventTriggered("ash")) - reconstruction_missing("Entity_NPC::Update 006c4b30: the ash a boss leaves"); + if (type == ENTITY_HUSH && sprite.IsEventTriggered("ash") && !HasEntityFlags(FLAG_DELIRIUM_FORM)) + { + if (Entity* ashes = spawn_at(ENTITY_EFFECT, EFFECT_HUSH_ASHES, 0, pos, this)) ashes->Update(); + game_shake_screen(HUSH_ASH_SHAKE); + npc_sound_play(SOUND_SUPERHOLY, 1, 2, 1); + } if (sprite.IsFinished() && isExists) trigger_kill_item_effects(); } @@ -1657,109 +1446,6 @@ void Entity_NPC::decoy_update() else if (decoyTargetTimer != 0) decoyTargetTimer--; } -// Part of 006c4b30: what a champion's color does each frame (the fly-spawning, flickering, regenerating, pulsing, -// creep and shot champions), and Wrath's twin flicker. -void Entity_NPC::champion_update() -{ - const NullFrame* overlay = sprite.animState.animData ? sprite.animState.GetNullFrame("OverlayEffect") : nullptr; - bool isEffectShown = !overlay || overlay->isVisible; - bool isShrunk = HasEntityFlags(FLAG_SHRINK); - int champion = championColorIdx; - - bool isGreen = champion == CHAMPION_GREEN || champion == CHAMPION_RAINBOW; - if (isGreen && isEffectShown && IsFrame(CHAMPION_CREEP_FRAMES, 0) && !isShrunk) - { - Entity_Effect* creep = static_cast(spawn_at(ENTITY_EFFECT, EFFECT_CREEP_GREEN, 0, pos, this)); - creep->SetTimeout(CHAMPION_CREEP_TIMEOUT); - creep->Update(); - } - if (champion == CHAMPION_BROWN) reconstruction_missing("Entity_NPC::Update 006c4b30: the brown champion's poop"); - if (champion == CHAMPION_WHITE) white_champion_update(); - if (champion == CHAMPION_FLICKER || type == ENTITY_FLICKER_TYPE) flicker_update(); - if (champion == CHAMPION_TRANSPARENT) entityGridCollisionClass = GRIDCOLL_WALLS; - else if ((champion == CHAMPION_PINK || champion == CHAMPION_RAINBOW) && --championTimer < 1 && isEffectShown && - !isShrunk) - champion_shot_fire(); - if ((champion == CHAMPION_PURPLE || champion == CHAMPION_RAINBOW) && isEffectShown) - reconstruction_missing("Entity_NPC::Update 006c4b30: the purple champion's pull"); - if (champion == CHAMPION_DARK_RED && (isDead || championRegenTimer != 0)) - reconstruction_missing("Entity_NPC::Update 006c4b30: the dark red champion's regeneration"); - bool isPulsing = champion == CHAMPION_CAMO || champion == CHAMPION_PULSE_GREEN || champion == CHAMPION_PULSE_GREY || - champion == CHAMPION_PULSE_RED || champion == CHAMPION_KING || champion == CHAMPION_RAINBOW; - if (isPulsing) reconstruction_missing("Entity_NPC::Update 006c4b30: the camouflaged, pulsing and king champions"); - if (champion == CHAMPION_SIZE_PULSE && championTimer > 0) championTimer--; - if (isShrunk && shrinkCountdown >= 1 && shrinkCountdown < SHRINK_PULSE_FRAMES) - reconstruction_missing("Entity_NPC::Update 006c4b30: the shrinking pulse"); -} - -// Part of 006c4b30: a white champion cannot be hurt while another enemy holding the doors lives, unless that one is -// white too. -void Entity_NPC::white_champion_update() -{ - isInvincible = false; - ClearEntityFlags(FLAG_NO_STATUS_EFFECTS); - for (Entity* entity : g_game->room->GetEntities()->updateEL) - { - Entity_NPC* npc = entity->IsEnemy() ? dynamic_cast(entity) : nullptr; - if (!npc || !npc->CanShutDoors() || (npc->isChampion && npc->championColorIdx == CHAMPION_WHITE)) continue; - isInvincible = true; - AddEntityFlags(FLAG_NO_STATUS_EFFECTS); - } -} - -// Part of 006c4b30: the flickering champion (and the Flicker kind) waits visible, fades out, hides, then fades back -// in, its sprite's alpha following. -void Entity_NPC::flicker_update() -{ - switch (flickerState) - { - case FLICKER_SHOWN: - if (flickerTimer-- < 0) flickerState = FLICKER_FADING_OUT; - break; - case FLICKER_FADING_OUT: - if (flickerAlpha > 0) flickerAlpha -= FLICKER_FADE; - else - { - flickerState = FLICKER_HIDDEN; - flickerTimer = random_below(CHAMPION_FLICKER_RANGE) + CHAMPION_FLICKER_MIN; - } - break; - case FLICKER_FADING_IN: - if (flickerAlpha < 1) flickerAlpha += FLICKER_FADE; - else - { - flickerState = FLICKER_SHOWN; - flickerTimer = random_below(CHAMPION_FLICKER_RANGE) + CHAMPION_FLICKER_MIN; - } - break; - case FLICKER_HIDDEN: - isVisible = false; - if (flickerTimer-- < 0) - { - isVisible = true; - flickerState = FLICKER_FADING_IN; - } - break; - default: break; - } - sprite.color._tint[3] = flickerAlpha; -} - -// Part of 006c4b30: the pink champion shoots along its walk every 40 to 59 frames while it moves. -void Entity_NPC::champion_shot_fire() -{ - float speed = vector_length(velocity); - if (speed <= 0) return; - - Vector direction = vector_scale(velocity, 1 / speed); - championTimer = random_below(CHAMPION_SHOT_RANGE) + CHAMPION_SHOT_MIN; - ProjectileParams params; - params.fallingAccelModifier = CHAMPION_SHOT_FALL_ACCEL; - params.fallingSpeedModifier = CHAMPION_SHOT_FALL_SPEED; - FireProjectiles(pos, vector_scale(direction, CHAMPION_SHOT_SPEED), PROJECTILES_SINGLE, params); - PlaySound(SOUND_BLOODSHOOT, 1, 2, false, 1); -} - // Part of 006c4b30: in a room that checks it, an enemy no grounded player has a path to stops holding the doors // after its second miss, checked every 60 frames once 900 frames passed. void Entity_NPC::unreachable_update() @@ -1807,8 +1493,22 @@ void Entity_NPC::dead_update() state = NPC_STATE_DEATH; stateFrame = 0; } - if (g_game->room->roomType == ROOM_DUNGEON && !IsFlying()) - reconstruction_missing("Entity_NPC::Update 006c4b30: a crawlspace enemy dropping off its ladder"); + if (g_game->room->roomType == ROOM_DUNGEON && !IsFlying()) ladder_drop(); +} + +// Part of 006c4b30: an enemy dying on a crawlspace ladder keeps its speed sideways and drops off it, unless a wall +// is right under it. +void Entity_NPC::ladder_drop() +{ + GridEntity* cell = room_grid_entity_at(pos); + if (!cell || cell->type != GRID_GRAVITY) return; + + velocity.y *= HALF_SPEED; + if (velocity.x > 0) velocity.x = vector_length(velocity); + else if (velocity.x < 0) velocity.x = -vector_length(velocity); + velocity.y = 0; + Vector below = vector_add(pos, vector_make(0, sizeMulti.y * size + LADDER_FOOT_MARGIN)); + if (room_grid_collision_at(below) != COLLISION_WALL) AddVelocity_divided(vector_make(0, LADDER_DROP_SPEED), false); } // Part of 006c4b30: a gold enemy's coins, one to three (none to two for a coin hearted player). @@ -2151,7 +1851,7 @@ bool Entity_NPC::TakeDamage(float damage, uint64_t damageFlags, const EntityRef& PlayerManager& players = g_game->playerManager; if (source.entity && players.FirstCollectibleOwner(COLLECTIBLE_BETRAYAL_ID, LAZARUS_SHARE_CHECK)) reconstruction_missing("Entity_NPC::TakeDamage 006d60a0: Betrayal"); - if (players.FirstCollectibleOwner(COLLECTIBLE_JAR_OF_FLIES_ID, LAZARUS_SHARE_CHECK)) + if (players.FirstCollectibleOwner(COLLECTIBLE_JAR_OF_FLIES, LAZARUS_SHARE_CHECK)) { bool isBlueFly = source.type == ENTITY_FAMILIAR && source.variant == Entity_Familiar::BLUE_FLY; bool isPlayerKill = source.type == ENTITY_PLAYER || (source.spawnerType == ENTITY_PLAYER && !isBlueFly) || @@ -2160,8 +1860,11 @@ bool Entity_NPC::TakeDamage(float damage, uint64_t damageFlags, const EntityRef& if (isPlayerKill) AddEntityFlags(FLAG_ADD_JAR_FLY); else ClearEntityFlags(FLAG_ADD_JAR_FLY); } - if (championColorIdx == CHAMPION_SIZE_PULSE && !isDead && pendingDamage < health) - reconstruction_missing("Entity_NPC::TakeDamage 006d60a0: the size pulsing champion's flies"); + bool isPlayerHit = source.type == ENTITY_PLAYER || + (source.spawnerType == ENTITY_PLAYER && + (source.type != ENTITY_FAMILIAR || source.variant != Entity_Familiar::BLUE_FLY)); + bool isFlyDue = !isDead && pendingDamage < health && championTimer < 1 && !(damageFlags & DAMAGE_ACID); + if (championColorIdx == CHAMPION_SIZE_PULSE && isFlyDue && isPlayerHit) champion_fly_spawn(); if (!isHurt || HasEntityFlags(FLAG_NO_STATUS_EFFECTS)) return isHurt; Entity* attacker = source.entity; @@ -2229,7 +1932,7 @@ void Entity_NPC::ResetColor() bool isChampionSheet = std::ranges::any_of(sprite.layerStates, [](const LayerState& layer) { return layer.bitflags & LAYER_CHAMPION_SHEET; }); if (championColorIdx >= 0 && championColorIdx < CHAMPION_COUNT) - sprite.color = isChampionSheet ? CHAMPION_LOOKS[championColorIdx].spriteColor + sprite.color = isChampionSheet ? champion_look_get(championColorIdx).spriteColor : champion_sprite_color_get(championColorIdx); } else if (bosscoloridx < 0) sprite.color = color; @@ -2704,49 +2407,155 @@ void Entity_NPC::update_damage_history() } } -// 006d5400 What happens as it leaves for good: a champion's drop or a boss's death, the dead enemy's flags' -// rewards (sticky spiders, black hearts), Jar of Flies' count, its removal, the on-kill items and its record. +// Part of 006d5400: a sticky enemy bursts into blue spiders for the nearest player, one to three (two to six when +// an explosion killed it). +void Entity_NPC::sticky_spiders_spawn() +{ + int spiders = killDamageFlags & DAMAGE_EXPLOSION ? (int)(Random() % STICKY_SPIDERS_BLAST_RANGE) + 2 + : (int)(Random() % STICKY_SPIDERS_RANGE) + 1; + for (int i = 0; i < spiders; i++) + { + Entity_Player* player = game_nearest_player(pos); + player->numBlueSpiders++; + spawn_blue_spider(pos, player, {}); + } +} + +// Part of 006d5400: the rewards of a dead enemy that gives any: one in five a black heart for Black Lipstick's +// sticky kind, and Jar of Flies' count for a fly a player killed, froze or iced. +void Entity_NPC::kill_rewards_spawn() +{ + if (HasEntityFlags(FLAG_SPAWN_BLACK_HP) && dropRNG.Next() % BLACK_HEART_CHANCE == 0) + { + uint32_t seed = Random(); + g_game->Spawn({.position = room_free_tile_position_find(pos, 0), + .subType = HEART_BLACK, + .type = ENTITY_PICKUP, + .variant = PICKUP_HEART, + .seed = seed}); + } + + PlayerManager& players = g_game->playerManager; + Entity_Player* jarOwner = players.RandomCollectibleOwner(COLLECTIBLE_JAR_OF_FLIES, dropRNG.Next(), nullptr); + if (!jarOwner || !(HasEntityFlags(FLAG_ADD_JAR_FLY | FLAG_FREEZE) || HasEntityFlags(FLAG_ICE_FROZEN))) return; + jarOwner->jarFlies = std::min(jarOwner->jarFlies + 1, JAR_OF_FLIES_MAX); + g_game->hud.refresh_request(HUD_REFRESH_PLAYER); +} + +// Part of 006d5400: the items a kill wakes: Contagion's cloud on the first kill of a room or a contagious enemy's, +// spreading the contagion, Athame's ring by the players' luck, a friendly enemy's recharge of the Friendly Ball in +// challenge 33, and a captured enemy's soul wisp for Book of Virtues. +void Entity_NPC::kill_items_trigger() +{ + PlayerManager& players = g_game->playerManager; + Entity_Player* contagion = players.FirstCollectibleOwner(COLLECTIBLE_CONTAGION, LAZARUS_SHARE_IGNORE); + if (contagion && (HasEntityFlags(FLAG_CONTAGIOUS) || !g_game->room->isFirstEnemyDead)) + { + game_fart({.position = pos, .source = contagion, .radius = CONTAGION_RADIUS, .subType = 1}); + for (Entity* enemy : entity_query_radius(pos, CONTAGION_RADIUS, QUERY_ENEMIES)) + if (enemy != this && enemy->IsVulnerableEnemy(nullptr)) enemy->AddEntityFlags(FLAG_CONTAGIOUS); + } + + if (Entity_Player* athame = players.FirstCollectibleOwner(COLLECTIBLE_ATHAME, LAZARUS_SHARE_IGNORE)) + { + RNG rng; + rng.SetSeed(initSeed, ATHAME_RNG_SHIFT_INDEX); + float luck = 0; + for (Entity_Player* player : players.playerList) + if (player->variant == PLAYER_VARIANT_PLAYER && !player->isCoopGhost) luck += player->luck; + if (rng.RandomFloat() < luck * ATHAME_LUCK_CHANCE + ATHAME_BASE_CHANCE) + { + Entity_Laser* ring = athame->SpawnMawOfVoid(ATHAME_RING_TIMEOUT); + ring->pos = pos; + ring->isDisableFollowParent = true; + ring->Update(); + } + } + + bool isFriendlyKill = IsFriendly() && g_game->challenge == CHALLENGE_KILL_CHARGE && + players.FirstCollectibleOwner(COLLECTIBLE_FRIEND_BALL, LAZARUS_SHARE_CHECK) && + (spawnerType == ENTITY_PLAYER || spawnerType == ENTITY_FAMILIAR) && spawnerEntity && + spawnerEntity->type == ENTITY_PLAYER; + if (isFriendlyKill) + { + auto* owner = static_cast(spawnerEntity.get()); + for (int slot = 0; slot < ACTIVE_SLOT_COUNT; slot++) + { + if (owner->activeItems[slot].item != COLLECTIBLE_FRIEND_BALL) continue; + owner->FullCharge(slot, false, false); + break; + } + } + + if (!HasEntityFlags(FLAG_FRIENDLY_BALL)) return; + Entity_Player* virtues = players.RandomCollectibleOwner(COLLECTIBLE_BOOK_OF_VIRTUES, dropRNG.Next(), nullptr); + EntityConfig_Entity* entry = g_manager->entityConfig.GetEntity(type, variant, 0); + if (!virtues || virtues->type != ENTITY_PLAYER || !entry) return; + + int wisp = WISP_SOUL; + if (entry->tags & ENTITY_TAG_HOMING_SOUL) wisp = WISP_SOUL_HOMING; + else if (entry->tags & ENTITY_TAG_EXPLOSIVE_SOUL) wisp = WISP_SOUL_EXPLOSIVE; + else if (entry->tags & ENTITY_TAG_BRIMSTONE_SOUL) wisp = WISP_SOUL_BRIMSTONE; + virtues->AddWisp(wisp, pos, false, false); +} + +// Part of 006d5400: a Brimstone marked enemy's burst marks the vulnerable enemies within 120 for 150 frames, hands +// them its statuses for 90, hits them for 10, and recharges the Hemoptysis of the players with Brimstone. +void Entity_NPC::marked_status_spread() +{ + EntityRef none(nullptr); + for (Entity* enemy : entity_query_radius(pos, MARK_SPREAD_RADIUS, QUERY_ENEMIES)) + { + if (enemy == this || !enemy->IsVulnerableEnemy(nullptr)) continue; + + enemy->AddBrimstoneMark(none, MARK_SPREAD_FRAMES); + if (HasEntityFlags(FLAG_SLOW)) + enemy->AddSlowing(none, STATUS_SPREAD_FRAMES, slowingAmount, SPREAD_SLOW_COLOR, false); + if (HasEntityFlags(FLAG_POISON)) enemy->AddPoison(none, STATUS_SPREAD_FRAMES, poisonTickDamage, false); + if (HasEntityFlags(FLAG_MIDAS_FREEZE)) enemy->AddMidasFreeze(none, STATUS_SPREAD_FRAMES, false); + else if (HasEntityFlags(FLAG_FREEZE)) enemy->AddFreeze(none, STATUS_SPREAD_FRAMES, false); + if (HasEntityFlags(FLAG_SHRINK)) enemy->AddShrink(none, STATUS_SPREAD_FRAMES, false, false); + else if (HasEntityFlags(FLAG_FEAR)) enemy->AddFear(none, STATUS_SPREAD_FRAMES, false); + if (HasEntityFlags(FLAG_CHARM)) enemy->AddCharmed(none, STATUS_SPREAD_FRAMES, false, false); + if (HasEntityFlags(FLAG_CONFUSION)) enemy->AddConfusion(none, STATUS_SPREAD_FRAMES, false); + if (HasEntityFlags(FLAG_BURN)) enemy->AddBurn(none, STATUS_SPREAD_FRAMES, 0, false); + if (HasEntityFlags(FLAG_MAGNETIZED)) enemy->AddMagnetized(none, STATUS_SPREAD_FRAMES); + if (HasEntityFlags(FLAG_ICE)) enemy->AddIce(none, STATUS_SPREAD_FRAMES); + if (HasEntityFlags(FLAG_BAITED)) enemy->AddBaited(none, STATUS_SPREAD_FRAMES); + enemy->TakeDamage(MARK_SPREAD_DAMAGE, 0, none, MARK_SPREAD_COUNTDOWN); + } + MakeBloodPoof(pos, COLOR_DEFAULT, 1); + + for (Entity_Player* player : g_game->playerManager.playerList) + { + Weapon* weapon = player->weapons[0] ? player->weapons[0].get() : player->weapons[1].get(); + if (!weapon || weapon->weaponType != WEAPON_BRIMSTONE) continue; + player->temporaryEffects.RemoveNullEffect(NULLITEM_HEMOPTYSIS_BOOST, -1); + player->temporaryEffects.AddNullEffect(NULLITEM_HEMOPTYSIS_BOOST, true, 1); + } +} + +// 006d5400 What happens as it leaves for good: a champion's drop or a boss's death, Rotgut's death, the sticky +// spiders, its rewards, its removal (Hush stays, drawn on the floor), the items a kill wakes, its record and a +// marked enemy's spreading statuses. void Entity_NPC::trigger_kill_item_effects() { if (isBoss) g_game->room->TriggerBossDeath(*this); else if (isChampion) champion_drop(); if (type == ENTITY_ROTGUT && variant == 1) - reconstruction_missing("Entity_NPC::trigger_kill_item_effects 006d5400: Rotgut's death"); - if (HasEntityFlags(FLAG_SPAWN_STICKY_SPIDERS)) - reconstruction_missing("Entity_NPC::trigger_kill_item_effects 006d5400: the sticky spiders"); - - if (!HasEntityFlags(FLAG_NO_REWARD)) - { - if (HasEntityFlags(FLAG_SPAWN_BLACK_HP) && dropRNG.Next() % BLACK_HEART_CHANCE == 0) - g_game->Spawn({.position = room_free_tile_position_find(pos, 0), - .subType = HEART_BLACK, - .type = ENTITY_PICKUP, - .variant = PICKUP_HEART, - .seed = Random()}); - Entity_Player* jarOwner = - g_game->playerManager.RandomCollectibleOwner(COLLECTIBLE_JAR_OF_FLIES_ID, dropRNG.Next(), nullptr); - if (jarOwner && (HasEntityFlags(FLAG_ADD_JAR_FLY | FLAG_FREEZE) || HasEntityFlags(FLAG_ICE_FROZEN))) - reconstruction_missing("Entity_NPC::trigger_kill_item_effects 006d5400: Jar of Flies' count"); - } + reconstruction_missing("rotgut_death_spawn_effects 00581200: Rotgut's death"); + if (HasEntityFlags(FLAG_SPAWN_STICKY_SPIDERS)) sticky_spiders_spawn(); + if (!HasEntityFlags(FLAG_NO_REWARD)) kill_rewards_spawn(); if (type == ENTITY_HUSH) AddEntityFlags(FLAG_RENDER_FLOOR); else Remove(); - - PlayerManager& players = g_game->playerManager; - bool isKillItem = players.FirstCollectibleOwner(COLLECTIBLE_CONTAGION_ID, LAZARUS_SHARE_IGNORE) || - players.FirstCollectibleOwner(COLLECTIBLE_MAW_OF_THE_VOID_ID, LAZARUS_SHARE_IGNORE) || - (IsFriendly() && g_game->challenge == CHALLENGE_KILL_CHARGE) || - HasEntityFlags(FLAG_FRIENDLY_BALL); - if (isKillItem) - reconstruction_missing( - "Entity_NPC::trigger_kill_item_effects 006d5400: Contagion, Maw of the Void and Lemegeton"); + kill_items_trigger(); g_game->room->isFirstEnemyDead = true; // Room::record_killed_npc 00820d30 waits for Room to hold the list of killed enemies, which nothing reads yet. entityRef = nullptr; aimTargetEffect = nullptr; - if (HasEntityFlags(FLAG_BRIMSTONE_MARKED) && HasEntityFlags(FLAG_EXTRA_GORE)) - reconstruction_missing("Entity_NPC::trigger_kill_item_effects 006d5400: the marked enemy's spreading status"); + if (HasEntityFlags(FLAG_BRIMSTONE_MARKED) && HasEntityFlags(FLAG_EXTRA_GORE)) marked_status_spread(); lua_engine_get().PostNPCDeath(this); } diff --git a/src/entity_npc.h b/src/entity_npc.h index 618684b..36f7434 100644 --- a/src/entity_npc.h +++ b/src/entity_npc.h @@ -65,6 +65,9 @@ enum ProjectilesMode : int PROJECTILES_RING }; +// The Mulligan that runs from the player, which a champion's health never raises. +constexpr int MULLIGAN_VARIANT_FLEEING = 2; + // Lua's ChampionColor values the NPC code tests. enum ChampionColor : int { @@ -164,13 +167,13 @@ struct Entity_NPC : Entity ColorMod dirtColor = COLOR_DEFAULT; ColorMod floorColor = COLOR_DEFAULT; EntityPtr aimTargetEffect; + EntityPtr deliriumEntity; EntityPtr entityRef; EntityPtr forcedTarget; EntityPtr pickupGhostsEntity; EntityPtr salvationTarget; EntityPtr unknownF54; Entity* collisionEntity = nullptr; - Entity* deliriumEntity = nullptr; Entity_Player* sirenPlayerEntity = nullptr; uint64_t killDamageFlags = 0; Vector confusionTargetPos{}; @@ -211,15 +214,24 @@ struct Entity_NPC : Entity int stateFrame = 0; int unknownF2c = 0; uint32_t aiCallFlags = 0; - uint32_t deliriumAttackID = 0; uint32_t deliriumBossType = 0; uint32_t deliriumBossVariant = 0; - uint32_t deliriumCycleID = 0; - uint32_t deliriumCycleIDHigh = 0; + // Delirium's clock (Lua's DeliriumCycleID): his rage odds, the rage's frames left, the frames to his teleport and + // the frames he has been in his form, each wrapping at its width. + uint32_t deliriumRageChance : 7 = 0; + uint32_t deliriumRageTimer : 8 = 0; + uint32_t deliriumTeleportTimer : 10 = 0; + uint32_t deliriumFormAge : 7 = 0; short championRegenCount = 0; uint16_t championRegenTimer = 0; uint16_t deliriumTransformationTimer = 0; uint8_t deliriumAttackAngle = 0; + // Delirium's shots (Lua's DeliriumAttackID): their frame, the odds of keeping the pattern, the pattern (0xff for a + // random one) and the volleys left of it. + uint8_t deliriumAttackFrame = 0; + uint8_t deliriumAttackKeepChance = 0; + uint8_t deliriumAttackPattern = 0; + uint8_t deliriumAttackRepeats = 0; uint8_t deliriumRemainingAttacks = 0; uint8_t deliriumState = 0; bool isBestiaryEncountered = false; @@ -274,10 +286,12 @@ struct Entity_NPC : Entity void white_champion_update(); void flicker_update(); void champion_shot_fire(); + void champion_fly_spawn(); void champion_drop(); void unreachable_update(); void dead_update(); void midas_coins_spawn(); + void ladder_drop(); void toxic_shock_creep_spawn(); void player_aura_update(); void item_effects_update(); @@ -319,6 +333,10 @@ struct Entity_NPC : Entity void PlayDeathEffects(); int death_burst_get(); void trigger_kill_item_effects(); + void sticky_spiders_spawn(); + void kill_rewards_spawn(); + void kill_items_trigger(); + void marked_status_spread(); void trigger_death_rewards(); void KillUnique(); bool CanBeDamagedFromVelocity(Vector velocity); @@ -385,11 +403,24 @@ bool any_player_flying(); Entity* game_nearest_target_player(const Vector& position, Entity* source, bool isPlayersOnly, bool isTargetDecoys, float maxDistance); void game_shake_screen(int timeout); +Entity* spawn_at(int type, int variant, int subType, const Vector& position, Entity* spawner); +int poof_size_get(Entity& entity, bool isHugeAllowed); void game_encountered_boss_add(int bossType, int bossVariant); bool game_is_hard_mode(); uint32_t room_grid_collision_at(const Vector& position); + +// A champion color's look, the exe's table at 00c354c0: the color its _champion sheets draw in (none without alpha) +// and the color its sprite otherwise shows. +struct ChampionLook +{ + ColorMod sheetColor; + ColorMod spriteColor; +}; + +const ChampionLook& champion_look_get(int championColor); ColorMod champion_sprite_color_get(int championColor); const ColorMod* champion_color_get(int championColor); +KColor hsv_to_rgb(float hue, float saturation, float value, float alpha); // A sheet's ".png", which the champion and floor suffixes go before, and the version of a sheet with them that exists. constexpr size_t SHEET_EXTENSION_SIZE = 4; diff --git a/src/entity_npc_boss.cpp b/src/entity_npc_boss.cpp index dcfc6d1..f1af897 100644 --- a/src/entity_npc_boss.cpp +++ b/src/entity_npc_boss.cpp @@ -10,6 +10,11 @@ #include "room_descriptor.h" #include +// Colostomia's landing as it appears: a shake, and in a flooded room water thrown from a 100 by 60 ellipse. +constexpr int COLOSTOMIA_LAND_SHAKE = 8; +constexpr float COLOSTOMIA_DROPS_X = 100; +constexpr float COLOSTOMIA_DROPS_Y = 60; + constexpr float BOSS_SHOT_SPEED = 7; constexpr float BOSS_SHOT_SCATTER = 3.5f; constexpr float BOSS_SHOT_FALL_ACCEL = 0.32f; @@ -324,8 +329,12 @@ void boss_appear_events(Entity_NPC& npc) reconstruction_missing("Entity_NPC::Update 006c4b30: Mother's appear particles (Game::SpawnParticles)"); return; case ENTITY_COLOSTOMIA: - if (npc.sprite.IsEventTriggered("Land")) - reconstruction_missing("Entity_NPC::Update 006c4b30: Colostomia's appear landing (spawn_rock_particles)"); + if (!npc.sprite.IsEventTriggered("Land")) return; + game_shake_screen(COLOSTOMIA_LAND_SHAKE); + npc.entityCollisionClass = ENTCOLL_ALL; + npc.MakeBloodPoofAtPos(npc.splatColor, 1); + water_drops_spawn(npc.pos, vector_make(COLOSTOMIA_DROPS_X, COLOSTOMIA_DROPS_Y), 1); + npc_sound_play(SOUND_FORESTBOSS_STOMPS, 1, 2, 1); return; } } diff --git a/src/entity_npc_champion.cpp b/src/entity_npc_champion.cpp new file mode 100644 index 0000000..fa6e740 --- /dev/null +++ b/src/entity_npc_champion.cpp @@ -0,0 +1,762 @@ +#include "entity_npc.h" +#include "entity_config.h" +#include "entity_effect.h" +#include "entity_player.h" +#include "game.h" +#include "grid_entity_poop.h" +#include "npc_ai.h" +#include "npc_basement.h" +#include "room.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include +#include + +constexpr int ENTITY_FLICKER_TYPE = 252; +constexpr int SHRINK_PULSE_FRAMES = 60; + +// The pulses: a slow and a fast sine over the room's frames, each shifted up by a half and clamped to 0 to 1. +constexpr float PULSE_SLOW_RATE = 0.1f; +constexpr float PULSE_FAST_RATE = 0.3f; +constexpr float PULSE_SHIFT = 0.5f; +constexpr ColorMod SHRINK_PULSE_COLOR = {{1, 1, 1, 1}, {0, 0, 0, 0}, {60 / 255.0f, 60 / 255.0f, 60 / 255.0f}}; + +// The rainbow champion's hue turns once every 90 frames. +constexpr int RAINBOW_HUE_FRAMES = 90; +constexpr float HUE_FULL_TURN = 360; +constexpr float HUE_SEXTANT = 60; +constexpr int HUE_SEXTANTS = 6; + +// The fly protected champion's fly starts shrunk. +constexpr int ETERNAL_FLY_SHRINK_FRAMES = 150; + +// The brown champion's splats every 3 frames and its poop, one in four cells it leaves. +constexpr int BROWN_SPLAT_FRAMES = 3; +constexpr float BROWN_SPLAT_SIZE_MIN = 0.2f; +constexpr float BROWN_SPLAT_SIZE_RANGE = 0.5f; +constexpr ColorMod BROWN_CHAMPION_SPLAT_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0.255f, 0.161f, 0.137f}}; +constexpr int BROWN_POOP_ODDS = 4; + +// The purple champion pulls players and tears from 300 away, the tears harder. +constexpr float PURPLE_PULL_REACH = 300; +constexpr float PURPLE_PULL_TEAR = 0.9f; +constexpr float PURPLE_PULL_PLAYER = 0.8f; + +// The dark red champion lies as a Globin's ball for 90 ticks at 10 health, shrinking to it and growing back. +constexpr float REGEN_HEALTH = 10; +constexpr float CHAMPION_REGEN_FRICTION = 0.8f; +constexpr int REGEN_SHRINK_END = 5; +constexpr int REGEN_GROW_END = 9; +constexpr int REGEN_RISE_START = 80; +constexpr int REGEN_RISE_SHRINK_END = 85; +constexpr int REGEN_END = 90; +constexpr float REGEN_SHRINK = 0.5f; +constexpr float REGEN_GROW = 2; +constexpr int AI_CALL_FLAGS_SHIFT = 16; +constexpr std::string_view REGEN_ANM2 = "gfx/024.000_Globin.anm2"; +constexpr std::array REGEN_TARGET_RESET_TYPES = {ENTITY_LEAPER, ENTITY_KEEPER, ENTITY_FLAMING_HOPPER, + ENTITY_RAGLING, ENTITY_HOPPER}; +constexpr uint64_t CLICKETY_CLACK_REGEN_CLEARED = FLAG_NO_STATUS_EFFECTS | FLAG_NO_TARGET | FLAG_HIDE_HP_BAR; + +// The camouflaged champion is black, its color offset drifting toward the floor under it. +constexpr float CAMO_FLOOR_SHARE = 0.9f; +constexpr float CAMO_DRIFT = 0.3f; + +// The grey pulsing champion pushes the tears within 100 at the bottom of its slow pulse. +constexpr float PULSE_PUSH_REACH = 100; +constexpr float PULSE_PUSH_START = 0.2f; +constexpr float PULSE_PUSH_END = 0.4f; + +// The red pulsing champion heals the enemies of its side by 20 every 30 frames, a red trail running to each. +constexpr int PULSE_HEAL_FRAMES = 30; +constexpr float PULSE_HEAL = 20; +constexpr float HEAL_TRAIL_STEP = 20; +constexpr int HEAL_TRAIL_MIN = 4; +constexpr int HEAL_TRAIL_MAX = 12; +constexpr float HEAL_TRAIL_SPEED_SHARE = 0.1f; +constexpr float HEAL_TRAIL_SPEED_MAX = 4; +constexpr float HEAL_TRAIL_SPREAD = 15; +constexpr float HEAL_TRAIL_SCALE = 0.3f; +constexpr float HEAL_TRAIL_RISE = -16; +constexpr int HEAL_FLASH_FRAMES = 8; +constexpr ColorMod HEAL_TRAIL_COLOR = {{1, 1, 1, 1}, {0, 0, 0, 0}, {0.3f, 0, 0}}; +constexpr ColorMod HEAL_FLASH_COLOR = {{0.7f, 0.7f, 0.7f, 1}, {0, 0, 0, 0}, {0.7f, 0, 0}}; +constexpr uint64_t HEAL_SIDE_FLAGS = FLAG_FRIENDLY | FLAG_CHARM; + +// The king champion crowns the plain enemies around it every 30 frames, and the size pulsing one keeps 5 flies. +constexpr int KING_FRAMES = 30; +constexpr int SIZE_PULSE_FLY_MAX = 4; +constexpr int SIZE_PULSE_FLY_COOLDOWN = 60; + +// A look from its sheet color's channels and its sprite's tint and offset. +constexpr ChampionLook champion_look(float red, float green, float blue, float alpha, + ColorMod spriteColor = COLOR_DEFAULT) +{ + return {{{red, green, blue, alpha}, {0, 0, 0, 0}, {0, 0, 0}}, spriteColor}; +} + +constexpr float CHAMPION_GLOW = 30 / 255.0f; +constexpr std::array CHAMPION_LOOKS = {{ + champion_look(1, 0.1f, 0.1f, 1), + champion_look(0.6f, 0.6f, 0, 1), + champion_look(0.1f, 0.8f, 0.2f, 1), + champion_look(1, 0.6f, 0.2f, 1), + champion_look(0.2f, 0.2f, 1, 1), + champion_look(0.03f, 0.24f, 0.24f, 1), + champion_look(1, 1, 1, 1, {{1, 1, 1, 1}, {0, 0, 0, 0}, {90 / 255.0f, 90 / 255.0f, 90 / 255.0f}}), + champion_look(0.5f, 0.5f, 0.5f, 1), + champion_look(1, 1, 1, 1, {{1, 1, 1, 0.6f}, {0, 0, 0, 0}, {120 / 255.0f, 120 / 255.0f, 120 / 255.0f}}), + champion_look(0, 0, 0, 0, {{0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0}}), + champion_look(1, 0, 1, 1), + champion_look(0.75f, 0, 1, 1), + champion_look(0.5f, 0, 0, 1), + champion_look(0.5f, 0.5f, 1, 1), + champion_look(0, 0, 0, 0), + champion_look(0.1f, 0.8f, 0.2f, 1, {{0.9f, 1, 0.9f, 1}, {0, 0, 0, 0}, {0, CHAMPION_GLOW, 0}}), + champion_look(0.5f, 0.5f, 0.5f, 1, + {{0.9f, 0.9f, 0.9f, 1}, {0, 0, 0, 0}, {CHAMPION_GLOW, CHAMPION_GLOW, CHAMPION_GLOW}}), + champion_look(0.8f, 0.8f, 0.8f, 1, {{1, 1, 1, 1}, {0, 0, 0, 0}, {50 / 255.0f, 50 / 255.0f, 50 / 255.0f}}), + champion_look(0, 0, 0, 0), + champion_look(0, 0, 0, 0), + champion_look(1, 0.2f, 0.2f, 1, {{1, 0.9f, 0.9f, 1}, {0, 0, 0, 0}, {CHAMPION_GLOW, 0, 0}}), + champion_look(0, 0, 0, 0), + champion_look(0, 0, 0, 0), + champion_look(0.3f, 0.3f, 0.3f, 1, {{0.8f, 0.8f, 0.8f, 1}, {0, 0, 0, 0}, {0, 0, 0}}), + champion_look(0.28f, 0.14f, 0.134f, 1), + champion_look(1, 1, 1, 1), +}}; + +// The colors a seed's champion roll picks among: the common ones (the late stages' with yellow), the rare, the +// pulsing and sized, the late stages' special ones, and the late stages' uncommon ones. +constexpr std::array CHAMPIONS_EARLY = {CHAMPION_RED, CHAMPION_GREEN, CHAMPION_DARK_GREEN, + CHAMPION_GREY, CHAMPION_PINK, CHAMPION_LIGHT_BLUE}; +constexpr std::array CHAMPIONS_LATE = {CHAMPION_RED, CHAMPION_YELLOW, CHAMPION_GREEN, CHAMPION_DARK_GREEN, + CHAMPION_GREY, CHAMPION_PINK, CHAMPION_LIGHT_BLUE}; +constexpr std::array CHAMPIONS_RARE = {CHAMPION_ORANGE, CHAMPION_DARK_BLUE, CHAMPION_DARK_RED}; +constexpr std::array CHAMPIONS_PULSING = {CHAMPION_CAMO, CHAMPION_PULSE_GREEN, CHAMPION_PULSE_GREY, + CHAMPION_FLY_PROTECTED, CHAMPION_TINY, CHAMPION_GIANT}; +constexpr std::array CHAMPIONS_SPECIAL = {CHAMPION_PULSE_RED, CHAMPION_SIZE_PULSE, CHAMPION_KING, + CHAMPION_DEATH}; +constexpr std::array CHAMPIONS_UNCOMMON = {CHAMPION_TRANSPARENT, CHAMPION_FLICKER, CHAMPION_PURPLE, + CHAMPION_BROWN}; +constexpr uint32_t CHAMPION_RNG_SHIFT_INDEX = 33; +constexpr uint32_t CHAMPION_LATE_STAGE = 5; +constexpr uint32_t CHAMPION_YELLOW_STAGE = 3; +constexpr uint32_t CHAMPION_PULSING_EARLY_COUNT = 4; +constexpr float CHAMPION_ROLL_WHITE = 0.005f; +constexpr float CHAMPION_ROLL_RAINBOW = 0.01f; +constexpr float CHAMPION_ROLL_UNCOMMON = 0.05f; +constexpr float CHAMPION_ROLL_RARE = 0.15f; +constexpr float CHAMPION_ROLL_PULSING = 0.3f; +constexpr float CHAMPION_ROLL_SPECIAL = 0.35f; +constexpr std::array CHAMPION_NO_DARK_RED_TYPES = {240, 241, 242, 304}; + +// The champions' health, speed, size and contact damage, and the effect variant some keep around them. +constexpr float CHAMPION_SCALE = 1.15f; +constexpr float CHAMPION_TINY_SCALE = 0.5f; +constexpr float CHAMPION_GIANT_SCALE = 1.5f; +constexpr float CHAMPION_CONTACT_DAMAGE = 2; +constexpr float CHAMPION_DEATH_CONTACT_DAMAGE = 4; +constexpr float CHAMPION_HP_RED = 1.333f; +constexpr float CHAMPION_HP_YELLOW = 0.75f; +constexpr float CHAMPION_HP_GREY = 0.333f; +constexpr float CHAMPION_HP_BIG = 1.5f; +constexpr float CHAMPION_HP_KING = 3; +constexpr float CHAMPION_SPEED_FAST = 1.333f; +constexpr float CHAMPION_SPEED_SLOW = 0.8f; +constexpr float CHAMPION_SPEED_GIANT = 0.9f; +constexpr int CHAMPION_FLICKER_MIN = 60; +constexpr int CHAMPION_FLICKER_RANGE = 30; +constexpr int CHAMPION_SHOT_MIN = 40; +constexpr int CHAMPION_SHOT_RANGE = 20; +constexpr int CHAMPION_CREEP_FRAMES = 7; +constexpr int CHAMPION_CREEP_TIMEOUT = 30; +constexpr float CHAMPION_SHOT_SPEED = 5; +constexpr float CHAMPION_SHOT_FALL_ACCEL = 0.3f; +constexpr float CHAMPION_SHOT_FALL_SPEED = -5; +constexpr float FLICKER_FADE = 0.05f; + +// Where a flickering champion is in its fade. +enum FlickerState : int +{ + FLICKER_SHOWN, + FLICKER_FADING_OUT, + FLICKER_FADING_IN, + FLICKER_HIDDEN +}; +constexpr ColorMod PULLING_RED_COLOR = {{1, 0.2f, 0.2f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; + +// A champion color's look. +const ChampionLook& champion_look_get(int championColor) +{ + return CHAMPION_LOOKS[championColor]; +} + +// 00505b80 The color a champion shows over a sprite without its sheets: its sheet color laid over its sprite color +// (Color::__mul), or the sprite color for a look drawn on no sheet. +ColorMod champion_sprite_color_get(int championColor) +{ + const ChampionLook& look = CHAMPION_LOOKS[championColor]; + if (look.sheetColor._tint[3] <= 0) return look.spriteColor; + + ColorMod color = look.sheetColor; + const ColorMod& other = look.spriteColor; + for (int i = 0; i < 4; i++) color._tint[i] *= other._tint[i]; + if (other._colorize[0] + other._colorize[1] + other._colorize[2] != 0) + for (int i = 0; i < 4; i++) color._colorize[i] = other._colorize[i]; + for (int i = 0; i < 3; i++) color._offset[i] += other._offset[i]; + return color; +} + +// The sheet color of a champion color's look, or none for a look drawn on no _champion sheet. +const ColorMod* champion_color_get(int championColor) +{ + if (championColor < 0 || championColor >= CHAMPION_COUNT) return nullptr; + const ColorMod& sheetColor = CHAMPION_LOOKS[championColor].sheetColor; + return sheetColor._tint[3] > 0 ? &sheetColor : nullptr; +} + +// 00684b90 A color from a hue in degrees, a saturation and a value. +KColor hsv_to_rgb(float hue, float saturation, float value, float alpha) +{ + float chroma = saturation * value; + float second = (1 - std::abs(std::fmod(hue / HUE_SEXTANT, 2.0f) - 1)) * chroma; + float red = 0; + float green = 0; + float blue = 0; + switch ((int)(hue / HUE_SEXTANT) % HUE_SEXTANTS) + { + case 0: + red = chroma; + green = second; + break; + case 1: + red = second; + green = chroma; + break; + case 2: + green = chroma; + blue = second; + break; + case 3: + green = second; + blue = chroma; + break; + case 4: + red = second; + blue = chroma; + break; + case 5: + red = chroma; + blue = second; + break; + default: break; + } + float base = value - chroma; + return kcolor_rgba(red + base, green + base, blue + base, alpha); +} + +// A pulse over the room's frames at a rate: a sine shifted up by a half, clamped to 0 to 1. +static float pulse_get(float rate) +{ + return std::clamp(std::sin((float)g_game->room->GetFrameCount() * rate) + PULSE_SHIFT, 0.0f, 1.0f); +} + +// The rainbow champion's champion color: its hue a turn along every 90 frames of the room. +static void rainbow_hue_update(Entity_NPC& npc) +{ + float hue = (float)(g_game->room->GetFrameCount() % RAINBOW_HUE_FRAMES) * HUE_FULL_TURN / RAINBOW_HUE_FRAMES; + KColor color = hsv_to_rgb(hue, 1, 1, 1); + npc.sprite.championColor = tint_color_make(color._red, color._green, color._blue, 1); +} + +// The fly protected champion's eternal fly when it becomes one late, shrunk at once (FUN_006b5de0). +static void shrunk_eternal_fly_spawn(Entity_NPC& npc) +{ + Entity* fly = spawn_at(ENTITY_ETERNALFLY, 0, 0, npc.pos, &npc); + fly->parent = &npc; + fly->AddShrink(EntityRef(&npc), ETERNAL_FLY_SHRINK_FRAMES, true, true); + if (fly->shrinkCountdown <= 0) return; + + fly->AddEntityFlags(FLAG_SHRINK); + fly->shrinkStatus1 = fly->shrinkStatus2; +} + +// Part of 006d03e0: a seed's champion color by the stage: rarely white or rainbow and uncommonly a strange one late, +// else a rare, pulsing or sized, special late, or common one. +static int champion_color_roll(uint32_t seed) +{ + RNG rng; + rng.SetSeed(seed, CHAMPION_RNG_SHIFT_INDEX); + float roll = rng.RandomFloat(); + uint32_t stage = g_game->stage; + bool isLate = stage >= CHAMPION_LATE_STAGE; + + if (roll < CHAMPION_ROLL_RAINBOW && isLate) return roll < CHAMPION_ROLL_WHITE ? CHAMPION_WHITE : CHAMPION_RAINBOW; + if (roll < CHAMPION_ROLL_UNCOMMON && isLate) return CHAMPIONS_UNCOMMON[rng.RandomInt(CHAMPIONS_UNCOMMON.size())]; + if (roll < CHAMPION_ROLL_RARE) return CHAMPIONS_RARE[rng.RandomInt(CHAMPIONS_RARE.size())]; + if (roll < CHAMPION_ROLL_PULSING) + { + uint32_t count = stage >= CHAMPION_YELLOW_STAGE ? CHAMPIONS_PULSING.size() : CHAMPION_PULSING_EARLY_COUNT; + return CHAMPIONS_PULSING[rng.RandomInt(count)]; + } + if (roll < CHAMPION_ROLL_SPECIAL && isLate) return CHAMPIONS_SPECIAL[rng.RandomInt(CHAMPIONS_SPECIAL.size())]; + if (stage < CHAMPION_YELLOW_STAGE) return CHAMPIONS_EARLY[rng.RandomInt(CHAMPIONS_EARLY.size())]; + return CHAMPIONS_LATE[rng.RandomInt(CHAMPIONS_LATE.size())]; +} + +// Part of 006d03e0: what a champion color changes beside the look: health, speed, grid collision, timers, and the +// pulling effect or eternal fly some keep with them. +void Entity_NPC::champion_traits_apply(bool isInit) +{ + switch (championColorIdx) + { + case CHAMPION_RED: maxHitPoints *= CHAMPION_HP_RED; break; + case CHAMPION_YELLOW: + championSpeed = CHAMPION_SPEED_FAST; + maxHitPoints *= CHAMPION_HP_YELLOW; + break; + case CHAMPION_GREY: maxHitPoints *= CHAMPION_HP_GREY; [[fallthrough]]; + case CHAMPION_DARK_BLUE: championSpeed = CHAMPION_SPEED_SLOW; break; + case CHAMPION_TRANSPARENT: entityGridCollisionClass = GRIDCOLL_WALLS; break; + case CHAMPION_FLICKER: flickerTimer = random_below(CHAMPION_FLICKER_RANGE) + CHAMPION_FLICKER_MIN; break; + case CHAMPION_PINK: championTimer = random_below(CHAMPION_SHOT_RANGE) + CHAMPION_SHOT_MIN; break; + case CHAMPION_PURPLE: + spawn_at(ENTITY_EFFECT, EFFECT_PULLING_EFFECT, PULLING_PURPLE, pos, this)->parent = this; + break; + case CHAMPION_PULSE_GREY: + spawn_at(ENTITY_EFFECT, EFFECT_PULLING_EFFECT, PULLING_GREY, pos, this)->parent = this; + break; + case CHAMPION_FLY_PROTECTED: + if (!isInit) shrunk_eternal_fly_spawn(*this); + break; + case CHAMPION_TINY: + maxHitPoints *= CHAMPION_HP_GREY; + championSpeed *= CHAMPION_SPEED_FAST; + break; + case CHAMPION_GIANT: + maxHitPoints *= CHAMPION_HP_BIG; + championSpeed *= CHAMPION_SPEED_GIANT; + [[fallthrough]]; + case CHAMPION_DEATH: + if (collisionDamage > 0) collisionDamage = CHAMPION_DEATH_CONTACT_DAMAGE; + break; + case CHAMPION_PULSE_RED: + { + Entity* pulling = spawn_at(ENTITY_EFFECT, EFFECT_PULLING_EFFECT, PULLING_RED, pos, this); + pulling->parent = this; + pulling->SetColor(PULLING_RED_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + break; + } + case CHAMPION_KING: maxHitPoints *= CHAMPION_HP_KING; break; + case CHAMPION_RAINBOW: + championSpeed = CHAMPION_SPEED_FAST; + maxHitPoints *= CHAMPION_HP_BIG; + championTimer = random_below(CHAMPION_SHOT_RANGE) + CHAMPION_SHOT_MIN; + spawn_at(ENTITY_EFFECT, EFFECT_PULLING_EFFECT, PULLING_PURPLE, pos, this)->parent = this; + if (!isInit) spawn_at(ENTITY_ETERNALFLY, 0, 0, pos, this)->parent = this; + rainbow_hue_update(*this); + break; + default: break; + } +} + +// 006d03e0 Makes it a champion of a color, or of one its seed draws for the stage at -1: twice the health and 2 +// contact damage, its size (half for the tiny, 1.5 for the giant, 1.15 else), its champion sprite and its color's +// traits. Dark red never befalls the slides and white not the fly protected kind. Only Init makes a champion twice. +void Entity_NPC::MakeChampion(uint32_t seed, int championColor, bool isInit) +{ + if (isChampion && !isInit) return; + + float baseMaxHitPoints = maxHitPoints; + maxHitPoints = baseMaxHitPoints + baseMaxHitPoints; + ResetColor(); + if (collisionDamage > 0) collisionDamage = CHAMPION_CONTACT_DAMAGE; + isChampion = true; + championColorIdx = championColor; + if (championColor < 0) championColor = champion_color_roll(seed); + + bool isNoDarkRed = std::ranges::find(CHAMPION_NO_DARK_RED_TYPES, type) != CHAMPION_NO_DARK_RED_TYPES.end(); + if (championColor == CHAMPION_DARK_RED && isNoDarkRed) championColor = CHAMPION_RED; + else if (championColor == CHAMPION_WHITE && type == ENTITY_CLICKETY_CLACK) championColor = CHAMPION_FLY_PROTECTED; + championColorIdx = std::clamp(championColor, (int)CHAMPION_RED, (int)CHAMPION_RAINBOW); + + float championScale = CHAMPION_SCALE; + if (championColorIdx == CHAMPION_TINY) + { + SetSize(size * CHAMPION_TINY_SCALE, sizeMulti, config->gridCollisionPoints); + championScale = CHAMPION_TINY_SCALE; + } + else if (championColorIdx == CHAMPION_GIANT) championScale = CHAMPION_GIANT_SCALE; + scale = championScale; + sprite.scale = vector_make(championScale * shrinkStatus1, championScale * shrinkStatus1); + load_graphics(false); + champion_traits_apply(isInit); + + if (type == ENTITY_MULLIGAN && variant == MULLIGAN_VARIANT_FLEEING) + maxHitPoints = std::min(maxHitPoints, baseMaxHitPoints); + if (!isInit) health = maxHitPoints; + ResetColor(); +} + +// Part of 006c4b30: the brown champion smears brown splats every 3 frames outside a crawlspace, and one in four +// cells it leaves sprouts a poop it stands inside, which rarely drops anything. +static void brown_champion_update(Entity_NPC& npc) +{ + if (npc.IsFrame(BROWN_SPLAT_FRAMES, 0)) + { + Entity_Effect* splat = npc.MakeSplat(random_unit() * BROWN_SPLAT_SIZE_RANGE + BROWN_SPLAT_SIZE_MIN); + splat->SetColor(BROWN_CHAMPION_SPLAT_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + } + + Room& room = *g_game->room; + int gridIndex = room.GetGridIndex(npc.pos); + if (gridIndex == npc.lastGridIndex) return; + + if (random_below(BROWN_POOP_ODDS) == 0 && npc.lastGridIndex >= 0) + { + GridEntity* left = room.GetGridEntity(npc.lastGridIndex); + bool isFree = room.GetGridCollision(npc.lastGridIndex) == COLLISION_NONE && + (!left || !is_grid_floor_special(left->type)); + if (isFree) + { + room.SpawnGridEntity(npc.lastGridIndex, GRID_POOP, 0, Random(), 0); + GridEntity* spawned = room.GetGridEntity(npc.lastGridIndex); + if (spawned && spawned->type == GRID_POOP) + { + auto* poop = static_cast(spawned); + poop->varData = 1; + poop->isEnemyInside = true; + poop->collisionClass = COLLISION_NONE; + } + } + } + npc.lastGridIndex = gridIndex; +} + +// Part of 006c4b30: the purple (and rainbow) champion pulls the players and tears toward it, harder the nearer. +static void purple_champion_pull(Entity_NPC& npc) +{ + EntityList_EL& entities = g_game->room->GetEntities()->updateEL; + for (size_t i = 0; i < entities.size(); i++) + { + Entity* entity = entities[i]; + if (entity->type != ENTITY_PLAYER && entity->type != ENTITY_TEAR) continue; + + Vector direction = vector_normalized(vector_sub(npc.pos, entity->pos)); + float strength = entity->type == ENTITY_PLAYER ? PURPLE_PULL_PLAYER : PURPLE_PULL_TEAR; + float distance = vector_length(vector_sub(npc.pos, entity->pos)); + float pull = std::min(std::max((PURPLE_PULL_REACH - distance) * strength / PURPLE_PULL_REACH, 0.0f), strength); + entity->AddVelocity_divided(vector_scale(direction, pull), false); + } +} + +// Part of 006c4b30: the dark red champion falls as a Globin's ball at 10 health instead of dying, its AI held, then +// shrinks into the ball over 5 ticks, grows back to half, and from tick 80 shrinks and grows again to rise whole +// at tick 90, its AI and graphics back. +static void dark_red_champion_update(Entity_NPC& npc) +{ + if (npc.championRegenTimer == 0) + { + if (!npc.isDead) return; + + npc.championRegenCount++; + npc.championRegenTimer = 1; + npc.isDead = false; + npc.health = REGEN_HEALTH; + npc.isInvincible = false; + npc.entityCollisionClass = ENTCOLL_ALL; + if (npc.entityGridCollisionClass == GRIDCOLL_NONE) npc.entityGridCollisionClass = GRIDCOLL_WALLS; + npc.aiCallFlags <<= AI_CALL_FLAGS_SHIFT; + return; + } + + npc.friction *= CHAMPION_REGEN_FRICTION; + int ticks = npc_ticks_get(npc); + for (int i = ticks; i > 0; i--) + { + int timer = ++npc.championRegenTimer; + bool isShrinking = timer <= REGEN_SHRINK_END || (timer > REGEN_RISE_START && timer <= REGEN_RISE_SHRINK_END); + if (isShrinking) + { + npc.SetScale(npc.scale * REGEN_SHRINK); + if (timer < REGEN_SHRINK_END || timer - ticks >= REGEN_SHRINK_END) continue; + + npc.sprite.Load(REGEN_ANM2, GRAPHICS_LOAD); + npc.sprite.Play("ReGenChamp", PLAY_FORCED); + npc.ResetColor(); + continue; + } + if (timer > REGEN_GROW_END && timer <= REGEN_RISE_SHRINK_END) continue; + + npc.SetScale(npc.scale * REGEN_GROW); + if (timer < REGEN_END) continue; + + npc.load_graphics(true); + npc.state = NPC_STATE_APPEAR; + npc.championRegenTimer = 0; + npc.friction = npc.baseFriction; + npc.aiCallFlags >>= AI_CALL_FLAGS_SHIFT; + bool isTargetReset = std::ranges::find(REGEN_TARGET_RESET_TYPES, npc.type) != REGEN_TARGET_RESET_TYPES.end(); + if (isTargetReset || npc.type == ENTITY_CLICKETY_CLACK) npc.targetPosition = {}; + if (npc.type == ENTITY_CLICKETY_CLACK) + { + npc.ClearEntityFlags(CLICKETY_CLACK_REGEN_CLEARED); + npc.isInvincible = false; + } + npc.pathfinder.Reset(); + npc.ResetColor(); + } +} + +// Part of 006c4b30: the camouflaged champion is black, its color offset drifting toward the floor under it. +static void camo_champion_update(Entity_NPC& npc) +{ + KColor floor = room_floor_texel_get(*g_game->room, npc.pos); + std::array target = {floor._red, floor._green, floor._blue}; + ColorMod camo = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0}}; + for (int i = 0; i < 3; i++) + { + float from = npc.sprite.color._offset[i]; + camo._offset[i] = from + (target[i] * CAMO_FLOOR_SHARE - from) * CAMO_DRIFT; + } + npc.sprite.color = camo; +} + +// Part of 006c4b30: the grey pulsing champion pushes the tears near it away, the nearer the harder. +static void pulse_tears_push(Entity_NPC& npc, float strength) +{ + for (Entity* tear : entity_query_radius(npc.pos, PULSE_PUSH_REACH, QUERY_TEARS)) + { + if (tear->type != ENTITY_TEAR) continue; + + Vector away = vector_sub(tear->pos, npc.pos); + float closeness = 1 - vector_length_squared(away) / (PULSE_PUSH_REACH * PULSE_PUSH_REACH); + tear->AddVelocity_divided(vector_resized(away, (closeness + closeness) * strength), false); + } +} + +// Part of 006c4b30: the red trail from a pulsing champion to an enemy it heals. +static void heal_trail_spawn(Entity_NPC& npc, Entity& healed) +{ + Vector offset = vector_sub(healed.pos, npc.pos); + Vector speed = vector_scale(offset, HEAL_TRAIL_SPEED_SHARE); + if (vector_length(speed) > HEAL_TRAIL_SPEED_MAX) speed = vector_resized(speed, HEAL_TRAIL_SPEED_MAX); + + int count = std::min(std::max((int)std::floor(vector_length(offset) / HEAL_TRAIL_STEP), HEAL_TRAIL_MIN), + HEAL_TRAIL_MAX); + for (int i = 1; i <= count; i++) + { + float along = (float)i / (float)(count + 1); + Vector spot = vector_add(npc.pos, vector_scale(offset, along)); + Vector direction = random_direction(); + spot = vector_add(spot, vector_scale(direction, random_unit() * HEAL_TRAIL_SPREAD)); + uint32_t seed = Random(); + Vector velocity = vector_scale(speed, random_unit() * PULSE_SHIFT + PULSE_SHIFT); + Entity* particle = g_game->Spawn({.position = spot, + .velocity = velocity, + .type = ENTITY_EFFECT, + .variant = EFFECT_HAEMO_TRAIL, + .seed = seed}); + particle->SetColor(HEAL_TRAIL_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + float particleScale = along * (random_unit() * HEAL_TRAIL_SCALE + HEAL_TRAIL_SCALE); + particle->sprite.scale = vector_make(particleScale, particleScale); + particle->posOffset = vector_add(npc.posOffset, vector_make(0, npc.sprite.scale.y * HEAL_TRAIL_RISE)); + } +} + +// Part of 006c4b30: the red pulsing champion heals the hurt enemies of its side by 20, but other red pulsing ones +// and Bishops, each with a heart, a trail and a flash, flashing itself with a slurp if it healed any. +static void pulse_enemies_heal(Entity_NPC& npc) +{ + bool isAnyHealed = false; + EntityList_EL& entities = g_game->room->GetEntities()->updateEL; + for (size_t i = 0; i < entities.size(); i++) + { + Entity* entity = entities[i]; + if (!entity->IsActiveEnemy(DEAD_EXCLUDED) || entity == &npc) continue; + if (entity->HasEntityFlags(FLAG_FRIENDLY) != npc.HasEntityFlags(HEAL_SIDE_FLAGS)) continue; + + // The original reads every enemy as an NPC here. A non-NPC enemy is left out. + auto* other = dynamic_cast(entity); + if (!other || other->championColorIdx == CHAMPION_PULSE_RED) continue; + if (other->health >= other->maxHitPoints || other->IsType(ENTITY_BISHOP, -1, -1)) continue; + + other->health = std::min(other->health + PULSE_HEAL, other->maxHitPoints); + g_game->Spawn({.position = other->pos, .type = ENTITY_EFFECT, .variant = EFFECT_HEART, .seed = Random()}); + heal_trail_spawn(npc, *other); + isAnyHealed = true; + other->SetColor(HEAL_FLASH_COLOR, HEAL_FLASH_FRAMES, COLOR_PRIORITY_DEFAULT, true, true); + } + if (!isAnyHealed) return; + + npc.SetColor(HEAL_FLASH_COLOR, HEAL_FLASH_FRAMES, COLOR_PRIORITY_DEFAULT, true, true); + npc_sound_play(SOUND_VAMP_GULP, 1, 2, 1); +} + +// Part of 006c4b30: a pulsing champion (green, grey or red) fades between its look and its plain colors, the grey +// one pushing tears away low in its pulse and the red one healing its side every 30 frames. +static void pulse_champion_update(Entity_NPC& npc) +{ + float slowPulse = pulse_get(PULSE_SLOW_RATE); + float fastPulse = pulse_get(PULSE_FAST_RATE); + const ChampionLook& look = champion_look_get(npc.championColorIdx); + npc.sprite.color = color_lerp(look.spriteColor, COLOR_DEFAULT, fastPulse); + const float* sheet = look.sheetColor._tint; + npc.sprite.championColor = tint_color_make(sheet[0], sheet[1], sheet[2], 1 - slowPulse); + + if (npc.championColorIdx == CHAMPION_PULSE_GREY && slowPulse < PULSE_PUSH_END) + pulse_tears_push(npc, lerp_clamped(slowPulse, PULSE_PUSH_START, PULSE_PUSH_END, 1, 0)); + else if (npc.championColorIdx == CHAMPION_PULSE_RED && npc.IsFrame(PULSE_HEAL_FRAMES, (int)npc.index)) + pulse_enemies_heal(npc); +} + +// Part of 006c4b30: every 30 frames the king champion makes the plain enemies around it yellow champions in look. +static void king_champion_update(Entity_NPC& npc) +{ + if (!npc.IsFrame(KING_FRAMES, (int)npc.index)) return; + + EntityList_EL& entities = g_game->room->GetEntities()->updateEL; + for (size_t i = 0; i < entities.size(); i++) + { + Entity* entity = entities[i]; + if (!entity->IsActiveEnemy(DEAD_EXCLUDED) || entity->IsBoss() || entity == &npc) continue; + + auto* other = dynamic_cast(entity); + if (!other || other->isChampion) continue; + other->isChampion = true; + other->championColorIdx = CHAMPION_YELLOW; + other->ResetColor(); + } +} + +// Part of 006c4b30: what a champion's color does each frame: green creep, brown poop, the white one's shield, +// the flicker (and Wrath's twin's), pink shots, the purple pull, dark red regeneration, camouflage, the pulses, the +// king's court, the rainbow's hues, and a shrunk enemy's pulse. +void Entity_NPC::champion_update() +{ + const NullFrame* overlay = sprite.animState.animData ? sprite.animState.GetNullFrame("OverlayEffect") : nullptr; + bool isEffectShown = !overlay || overlay->isVisible; + bool isShrunk = HasEntityFlags(FLAG_SHRINK); + int champion = championColorIdx; + + bool isGreen = champion == CHAMPION_GREEN || champion == CHAMPION_RAINBOW; + if (isGreen && isEffectShown && IsFrame(CHAMPION_CREEP_FRAMES, 0) && !isShrunk) + { + Entity_Effect* creep = static_cast(spawn_at(ENTITY_EFFECT, EFFECT_CREEP_GREEN, 0, pos, this)); + creep->SetTimeout(CHAMPION_CREEP_TIMEOUT); + creep->Update(); + } + if (champion == CHAMPION_BROWN && g_game->room->roomType != ROOM_DUNGEON && isEffectShown) + brown_champion_update(*this); + if (champion == CHAMPION_WHITE) white_champion_update(); + if (champion == CHAMPION_FLICKER || type == ENTITY_FLICKER_TYPE) flicker_update(); + if (champion == CHAMPION_TRANSPARENT) entityGridCollisionClass = GRIDCOLL_WALLS; + else if ((champion == CHAMPION_PINK || champion == CHAMPION_RAINBOW) && --championTimer < 1 && isEffectShown && + !isShrunk) + champion_shot_fire(); + if ((champion == CHAMPION_PURPLE || champion == CHAMPION_RAINBOW) && isEffectShown) purple_champion_pull(*this); + + switch (champion) + { + case CHAMPION_DARK_RED: dark_red_champion_update(*this); break; + case CHAMPION_CAMO: camo_champion_update(*this); break; + case CHAMPION_PULSE_GREEN: + case CHAMPION_PULSE_GREY: + case CHAMPION_PULSE_RED: pulse_champion_update(*this); break; + case CHAMPION_KING: king_champion_update(*this); break; + case CHAMPION_SIZE_PULSE: + if (championTimer > 0) championTimer--; + break; + case CHAMPION_RAINBOW: rainbow_hue_update(*this); break; + default: break; + } + + if (!isShrunk || shrinkCountdown < 1 || shrinkCountdown >= SHRINK_PULSE_FRAMES) return; + sprite.color = color_lerp(SHRINK_PULSE_COLOR, COLOR_DEFAULT, pulse_get(PULSE_FAST_RATE)); +} + +// Part of 006d60a0: a size pulsing champion a player hurt (not by acid nor a blue fly) throws out an attack fly +// from its edge, keeping no more than 5 and waiting 60 frames between them. +void Entity_NPC::champion_fly_spawn() +{ + int flies = 0; + for (Entity* entity : g_game->room->GetEntities()->updateEL) + if (entity->spawnerEntity.get() == this) flies++; + if (flies > SIZE_PULSE_FLY_MAX) return; + + uint32_t seed = Random(); + Vector edge = vector_add(pos, vector_scale(random_direction(), size)); + Entity* fly = g_game->Spawn({.position = edge, .spawner = this, .type = ENTITY_ATTACKFLY, .seed = seed}); + fly->isKillOnTouch = true; + fly->spawnerEntity = this; + fly->Update(); + championTimer = SIZE_PULSE_FLY_COOLDOWN; +} +// Part of 006c4b30: a white champion cannot be hurt while another enemy holding the doors lives, unless that one is +// white too. +void Entity_NPC::white_champion_update() +{ + isInvincible = false; + ClearEntityFlags(FLAG_NO_STATUS_EFFECTS); + for (Entity* entity : g_game->room->GetEntities()->updateEL) + { + Entity_NPC* npc = entity->IsEnemy() ? dynamic_cast(entity) : nullptr; + if (!npc || !npc->CanShutDoors() || (npc->isChampion && npc->championColorIdx == CHAMPION_WHITE)) continue; + isInvincible = true; + AddEntityFlags(FLAG_NO_STATUS_EFFECTS); + } +} + +// Part of 006c4b30: the flickering champion (and the Flicker kind) waits visible, fades out, hides, then fades back +// in, its sprite's alpha following. +void Entity_NPC::flicker_update() +{ + switch (flickerState) + { + case FLICKER_SHOWN: + if (flickerTimer-- < 0) flickerState = FLICKER_FADING_OUT; + break; + case FLICKER_FADING_OUT: + if (flickerAlpha > 0) flickerAlpha -= FLICKER_FADE; + else + { + flickerState = FLICKER_HIDDEN; + flickerTimer = random_below(CHAMPION_FLICKER_RANGE) + CHAMPION_FLICKER_MIN; + } + break; + case FLICKER_FADING_IN: + if (flickerAlpha < 1) flickerAlpha += FLICKER_FADE; + else + { + flickerState = FLICKER_SHOWN; + flickerTimer = random_below(CHAMPION_FLICKER_RANGE) + CHAMPION_FLICKER_MIN; + } + break; + case FLICKER_HIDDEN: + isVisible = false; + if (flickerTimer-- < 0) + { + isVisible = true; + flickerState = FLICKER_FADING_IN; + } + break; + default: break; + } + sprite.color._tint[3] = flickerAlpha; +} + +// Part of 006c4b30: the pink champion shoots along its walk every 40 to 59 frames while it moves. +void Entity_NPC::champion_shot_fire() +{ + float speed = vector_length(velocity); + if (speed <= 0) return; + + Vector direction = vector_scale(velocity, 1 / speed); + championTimer = random_below(CHAMPION_SHOT_RANGE) + CHAMPION_SHOT_MIN; + ProjectileParams params; + params.fallingAccelModifier = CHAMPION_SHOT_FALL_ACCEL; + params.fallingSpeedModifier = CHAMPION_SHOT_FALL_SPEED; + FireProjectiles(pos, vector_scale(direction, CHAMPION_SHOT_SPEED), PROJECTILES_SINGLE, params); + PlaySound(SOUND_BLOODSHOOT, 1, 2, false, 1); +} diff --git a/src/entity_npc_rewards.cpp b/src/entity_npc_rewards.cpp index 6f9db96..f5e887b 100644 --- a/src/entity_npc_rewards.cpp +++ b/src/entity_npc_rewards.cpp @@ -1,4 +1,5 @@ #include "boss_ai.h" +#include "entity_effect.h" #include "entity_effect_combat.h" #include "entity_familiar.h" #include "entity_pickup.h" @@ -19,7 +20,6 @@ constexpr int TEAR_SHARP_KEY_SPECTRAL = 44; // Gimpy's half heart: one in a hundred kills of a weak enemy, one in twenty of a sturdier one, one in ten of a strong // one (twice as likely for a champion's reward), one in ten again under Daemon's Tail. constexpr float EXORCIST_ROOM_MARGIN = -10; -constexpr int EFFECT_HUNGRY_SOUL = 186; constexpr float GIMPY_WEAK_HEALTH = 10; constexpr float GIMPY_STRONG_HEALTH = 30; constexpr uint32_t GIMPY_WEAK_ODDS = 100; diff --git a/src/entity_pickup.cpp b/src/entity_pickup.cpp index 8e7ec64..faa49b7 100644 --- a/src/entity_pickup.cpp +++ b/src/entity_pickup.cpp @@ -2054,10 +2054,13 @@ void Entity_Pickup::GetLootList(const Vector&) reconstruction_missing("Entity_Pickup::GetLootList 005832c0"); } -// 006e1e60 -void Entity_Pickup::SetForceBlind(uint8_t) +// 006e1e60 Hides or shows a collectible as a question mark, redrawing an item whose state changed. +void Entity_Pickup::SetForceBlind(uint8_t setBlind) { - reconstruction_missing("Entity_Pickup::SetForceBlind 006e1e60"); + bool isWasBlind = isForceBlind; + + isForceBlind = setBlind; + if (variant == PICKUP_COLLECTIBLE && subtype != 0 && isWasBlind != isForceBlind) UpdateSprite(false); } // 006e3020 @@ -2066,14 +2069,23 @@ void Entity_Pickup::AppearFast() reconstruction_missing("Entity_Pickup::AppearFast 006e3020"); } -// 006ee3f0 +// 006ee3f0 Whether Jera or Diplopia may copy the pickup: a living one that can be rerolled, no pedestal, trinket, +// Jera itself or empty chest. bool Entity_Pickup::CanJeraDuplicate() { - reconstruction_missing("Entity_Pickup::CanJeraDuplicate 006ee3f0"); + if (isDead || variant == PICKUP_COLLECTIBLE || variant == PICKUP_TRINKET) return false; + if (variant == PICKUP_TAROTCARD && subtype == RUNE_JERA) return false; + return CanReroll() && (!IsChest(variant) || subtype != 0); } -// 006eed30 +// 006eed30 Gives the pickup an options index of its own, past every other pickup's and at least 3. int Entity_Pickup::AssignOptionsIndex() { - reconstruction_missing("Entity_Pickup::AssignOptionsIndex 006eed30"); + int highest = 2; + + for (Entity* entity : g_game->room->entityList.updateEL) + if (entity->type == ENTITY_PICKUP && entity != this && !entity->HasEntityFlags(FLAG_NO_QUERY)) + highest = std::max(highest, static_cast(entity)->optionsPickupIndex); + optionsPickupIndex = highest + 1; + return optionsPickupIndex; } diff --git a/src/entity_pickup_shop.cpp b/src/entity_pickup_shop.cpp index 574812a..d418280 100644 --- a/src/entity_pickup_shop.cpp +++ b/src/entity_pickup_shop.cpp @@ -4,6 +4,7 @@ #include "entity_pickup.h" #include "entity_player.h" #include "game.h" +#include "grid_entity_spikes.h" #include "log.h" #include "manager.h" #include "npc_ai.h" @@ -13,8 +14,6 @@ #include constexpr int COLLECTIBLE_KEEPERS_SACK = 716; -constexpr int GRID_SPIKES_OFFER = 28; -constexpr int EFFECT_SPIKE_PRICE = 174; constexpr int ACHIEVEMENT_SHOP_SPENDING = 582; constexpr int SHOP_SPENDING_UNLOCK = 39; constexpr int EVENT_SHOP_PURCHASES = 197; @@ -140,7 +139,7 @@ void Entity_Pickup::price_sprite_load() Entity* spikes = g_game->Spawn({.position = pos, .spawner = this, .type = ENTITY_EFFECT, - .variant = EFFECT_SPIKE_PRICE, + .variant = EFFECT_SHOP_SPIKES, .seed = Random()}); spikes->parent = this; spikes->Update(); @@ -155,6 +154,53 @@ void Entity_Pickup::price_sprite_load() if (priceANM2.animState.animData) priceANM2.animState.SetFrameFloat((float)frame); } +// The spike offer's part of 006e2570 for the cell under a ware. A bought offer poofs and puts its offer spikes away, a +// soul price clears the spikes, a new offer summons offer spikes there (or wakes the idle ones), and any other price +// puts idle offer spikes away. +static void offer_spikes_update(Entity_Pickup& pickup, int oldPrice) +{ + Room& room = *g_game->room; + int below = room.GetGridIndex(pickup.pos) + room.gridWidth; + auto* spikes = dynamic_cast(room.GetGridEntity((uint32_t)below)); + bool isOffer = spikes && spikes->type == GRID_SPIKES_ALT; + + if (oldPrice == PRICE_SPIKES_OFFER && pickup.price == PRICE_SOUL && spikes) + room.RemoveGridEntity(below, GRID_PATH_FREED, DECORATION_KEPT); + if (oldPrice == PRICE_SPIKES_OFFER && pickup.price == 0) + { + int sound = SOUND_BLACK_POOF; + + pickup.sprite.Play("Idle"); + pickup.SetAlternatePedestal(0); + g_game->Spawn({.position = pickup.pos, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound); + if (isOffer) spikes->unsummon(false); + return; + } + if (pickup.price != PRICE_SPIKES_OFFER) + { + if (isOffer && spikes->state == 0) spikes->unsummon(false); + return; + } + + if (isOffer) + { + if (spikes->state != 1) return; + spikes->state = 0; + spikes->sprite.Play("SummonPayment"); + return; + } + GridEntity* standing = room.GetGridEntity((uint32_t)below); + if (standing && standing->type != GRID_DECORATION) + { + room.gridPaths[below] = GRID_PATH_FREED; + room.gridEntities[below] = nullptr; + delete standing; + } + room.SpawnGridEntity(below, GRID_SPIKES_ALT, 0, Random(), 0); +} + // 006e2570 Sets the price and its sprite. A free pickup drops the price sprite and plays idle, a priced one shows its // price and stands still on its shop pedestal. Spike offers keep their price until bought or turned to a soul. void Entity_Pickup::update_price_sprite(int newPrice) @@ -191,12 +237,7 @@ void Entity_Pickup::update_price_sprite(int newPrice) entityCollisionClass = ENTCOLL_PLAYERONLY; } if (price != PRICE_SPIKES && child) child->Remove(); - - GridEntity* below = room.GetGridEntity((uint32_t)(room.GetGridIndex(pos) + room.gridWidth)); - bool isOfferSpikes = below && below->type == GRID_SPIKES_OFFER; - if (oldPrice == PRICE_SPIKES_OFFER || price == PRICE_SPIKES_OFFER || isOfferSpikes) - reconstruction_missing( - "Entity_Pickup::update_price_sprite 006e2570: a spike offer's spikes (GridEntity_Spikes)"); + offer_spikes_update(*this, oldPrice); } // The price part of 006e3940: a ware that follows the shop's prices takes the price the nearest player would pay. diff --git a/src/entity_player.cpp b/src/entity_player.cpp index a11abec..ca1ffc1 100644 --- a/src/entity_player.cpp +++ b/src/entity_player.cpp @@ -1435,6 +1435,7 @@ void Entity_Player::release_weapons_and_effects(bool isRemoveEntities) link_release(azazelsRageLaser, isRemoveEntities); link_release(breathOfLifeEffect, isRemoveEntities); link_release(trinityShield, isRemoveEntities); + link_release(bestFriend, isRemoveEntities); link_release(megaBlastLaser, isRemoveEntities); link_release(markedTarget, isRemoveEntities); link_release(forgottenBody, isRemoveEntities); diff --git a/src/entity_player.h b/src/entity_player.h index 8e48d73..2b18ee1 100644 --- a/src/entity_player.h +++ b/src/entity_player.h @@ -26,6 +26,7 @@ constexpr int COLLECTIBLE_VANILLA_COUNT = 733; constexpr int COOP_BABY_BUFF_COUNT = 8; constexpr int COSTUME_LAYER_COUNT = 15; constexpr int FORGOTTEN_BODY_ROOM_NONE = -99999; +constexpr int HEART_STAT_COUNT = 6; constexpr int DIMENSION_ROOM_COUNT = 169; constexpr int HUD_HEART_FLASH_FRAMES = 4; constexpr int INVENTORY_SIZE = 16; @@ -38,6 +39,9 @@ constexpr uint32_t QUEUED_TOUCHED = 0x1; constexpr uint32_t QUEUED_GOLDEN = 0x2; constexpr uint32_t TRINKET_GOLDEN_FLAG = 0x8000; constexpr uint8_t WILD_CARD_NONE = 0xff; +constexpr uint8_t WILD_CARD_PILL = 0; +constexpr uint8_t WILD_CARD_CARD = 1; +constexpr uint8_t WILD_CARD_ACTIVE = 2; // The characters, by their ids in players.xml (Lua's PlayerType). enum PlayerType : int @@ -97,10 +101,19 @@ enum PlayerVariant : int enum BabySubType : int { BABY_BLOAT = 2, + BABY_PSY = 4, BABY_YBAB = 7, + BABY_SHADOW = 13, + BABY_BEGOTTEN = 21, + BABY_FIGHTING = 23, BABY_GLITCH = 25, BABY_MAGNET = 26, + BABY_SUPER_GREED = 54, BABY_APOLLYON = 56, + BABY_BONE = 57, + BABY_BOUND = 58, + BABY_FOUND_SOUL = 59, + BABY_DOUBLE = 65, BABY_BASIC = 71 }; @@ -128,6 +141,19 @@ enum HeartKind : int // The weight of a player Gnawed Leaf turned to stone. constexpr float STATUE_MASS = 1000; +// The flavours the G FUEL! seed's stacks give (get_seeded_variant): none below two stacks, then Soy Milk's, Mutant +// Spider's slower and wobbly tears, slow tears, rapid weak tears, and slow far reaching ones. +enum SeededVariant : int +{ + SEEDED_VARIANT_NONE = -1, + SEEDED_VARIANT_PLAIN, + SEEDED_VARIANT_SOY_MILK, + SEEDED_VARIANT_MUTANT_SPIDER, + SEEDED_VARIANT_SLOW, + SEEDED_VARIANT_RAPID, + SEEDED_VARIANT_SLOW_FAR +}; + // What the player did this frame (Lua's GetLastActionTriggers): bombed, moved, shot, used a pocket item or an // active, or dropped. enum ActionTrigger : int @@ -207,7 +233,28 @@ enum RenderPass enum PlayerItemId : int { COLLECTIBLE_SAD_ONION = 1, + COLLECTIBLE_MONSTROS_TOOTH = 86, + COLLECTIBLE_BEAN = 111, + COLLECTIBLE_BEST_FRIEND = 136, + COLLECTIBLE_CLEAR_RUNE = 263, + COLLECTIBLE_D10 = 285, + COLLECTIBLE_BOOK_OF_SECRETS = 287, + COLLECTIBLE_BOX_OF_SPIDERS = 288, + COLLECTIBLE_HEAD_OF_KRAMPUS = 293, + COLLECTIBLE_CONVERTER = 296, + COLLECTIBLE_BLUE_BOX = 297, + COLLECTIBLE_ISAACS_TEARS = 323, + COLLECTIBLE_DIPLOPIA = 347, + COLLECTIBLE_PLACEBO = 348, + COLLECTIBLE_MEGA_BEAN = 351, + COLLECTIBLE_BOX_OF_FRIENDS = 357, + COLLECTIBLE_TEAR_DETONATOR = 383, + COLLECTIBLE_VENTRICLE_RAZOR = 396, + COLLECTIBLE_JAR_OF_FLIES = 434, + COLLECTIBLE_D7 = 437, + COLLECTIBLE_VOID = 477, COLLECTIBLE_TRANSCENDENCE = 20, + COLLECTIBLE_INNER_EYE = 2, COLLECTIBLE_SPOON_BENDER = 3, COLLECTIBLE_NUMBER_ONE = 6, COLLECTIBLE_SKATOLE = 9, @@ -328,6 +375,7 @@ enum PlayerItemId : int COLLECTIBLE_FIRE_MIND = 257, COLLECTIBLE_MISSING_NO = 258, COLLECTIBLE_BLACK_CANDLE = 260, + COLLECTIBLE_PROPTOSIS = 261, COLLECTIBLE_MISSING_PAGE_2 = 262, COLLECTIBLE_LEECH = 270, COLLECTIBLE_BEST_BUD = 274, @@ -356,6 +404,7 @@ enum PlayerItemId : int COLLECTIBLE_NEGATIVE = 328, COLLECTIBLE_LUDOVICO = 329, COLLECTIBLE_SOY_MILK = 330, + COLLECTIBLE_GODHEAD = 331, COLLECTIBLE_LAZARUS_RAGS = 332, COLLECTIBLE_MIND = 333, COLLECTIBLE_BOOMERANG = 338, @@ -382,6 +431,7 @@ enum PlayerItemId : int COLLECTIBLE_TECH_X = 395, COLLECTIBLE_TRACTOR_BEAM = 397, COLLECTIBLE_PURITY = 407, + COLLECTIBLE_ATHAME = 408, COLLECTIBLE_EVIL_EYE = 410, COLLECTIBLE_LUSTY_BLOOD = 411, COLLECTIBLE_CAMBION_CONCEPTION = 412, @@ -404,6 +454,7 @@ enum PlayerItemId : int COLLECTIBLE_GLAUCOMA = 460, COLLECTIBLE_GLYPH_OF_BALANCE = 464, COLLECTIBLE_ANALOG_STICK = 465, + COLLECTIBLE_CONTAGION = 466, COLLECTIBLE_BROKEN_GLASS_CANNON = 474, COLLECTIBLE_SMELTER = 479, COLLECTIBLE_DATAMINER = 481, @@ -471,6 +522,14 @@ enum PlayerItemId : int COLLECTIBLE_KNIFE_PIECE_2 = 627, COLLECTIBLE_EVIL_CHARM = 632, COLLECTIBLE_DOGMA = 633, + COLLECTIBLE_CANDY_HEART = 671, + COLLECTIBLE_FRIEND_BALL = 382, + COLLECTIBLE_BLACK_HOLE = 512, + COLLECTIBLE_GELLO = 728, + COLLECTIBLE_NEPTUNUS = 597, + COLLECTIBLE_SOUL_LOCKET = 686, + COLLECTIBLE_MILK = 436, + COLLECTIBLE_PASCHAL_CANDLE = 567, COLLECTIBLE_ERASER = 638, COLLECTIBLE_URN_OF_SOULS = 640, COLLECTIBLE_MAGIC_SKIN = 642, @@ -516,6 +575,34 @@ enum PlayerItemId : int COLLECTIBLE_MEGA_MUSH = 625, COLLECTIBLE_MONTEZUMAS_REVENGE = 680, COLLECTIBLE_ESAU_JR = 703, + COLLECTIBLE_DARK_ARTS = 705, + COLLECTIBLE_JAR_OF_WISPS = 685, + COLLECTIBLE_CHAOS = 402, + COLLECTIBLE_FRUIT_CAKE = 418, + COLLECTIBLE_LUMP_OF_COAL = 132, + COLLECTIBLE_KIDNEY_BEAN = 421, + COLLECTIBLE_MEGA_BLAST = 441, + COLLECTIBLE_PAUSE = 478, + COLLECTIBLE_COMPOST = 480, + COLLECTIBLE_CLICKER = 482, + COLLECTIBLE_MAMA_MEGA = 483, + COLLECTIBLE_CROOKED_PENNY = 485, + COLLECTIBLE_DULL_RAZOR = 486, + COLLECTIBLE_BROWN_NUGGET = 504, + COLLECTIBLE_SHARP_STRAW = 507, + COLLECTIBLE_TELEKINESIS = 522, + COLLECTIBLE_SACRIFICIAL_ALTAR = 536, + COLLECTIBLE_SULFUR = 556, + COLLECTIBLE_FREE_LEMONADE = 578, + COLLECTIBLE_SCOOPER = 605, + COLLECTIBLE_MEAT_CLEAVER = 631, + COLLECTIBLE_R_KEY = 636, + COLLECTIBLE_YUCK_HEART = 639, + COLLECTIBLE_PLUM_FLUTE = 650, + COLLECTIBLE_FRIEND_FINDER = 687, + COLLECTIBLE_SUMPTORIUM = 713, + COLLECTIBLE_KEEPERS_BOX = 719, + COLLECTIBLE_SPINDOWN_DICE = 723, COLLECTIBLE_AZAZELS_RAGE = 699, COLLECTIBLE_BERSERK = 704, COLLECTIBLE_STAPLER = 708, @@ -681,6 +768,13 @@ enum PlayerItemId : int NULLITEM_REVERSE_SUN = 66, NULLITEM_WAVY_CAP_1 = 71, NULLITEM_LUNA = 74, + NULLITEM_BOOMERANG = 30, + NULLITEM_CAMO_BOOST = 48, + NULLITEM_BLOOD_OATH = 54, + NULLITEM_SOL = 56, + NULLITEM_JUDAS_BIRTHRIGHT = 123, + NULLITEM_JUDAS_BIRTHRIGHT_TIMED = 124, + NULLITEM_JUDAS_BIRTHRIGHT_PERMANENT = 130, NULLITEM_ESAU_JR = 100, NULLITEM_SPIRIT_SHACKLES_DISABLED = 102, NULLITEM_FORGOTTEN_BOMB = 106, @@ -697,6 +791,14 @@ enum PlayerItemId : int NULLITEM_REVERSE_STRENGTH = 64, NULLITEM_REVERSE_DEVIL = 67, NULLITEM_REVERSE_TEMPERANCE = 69, + NULLITEM_MEGABLAST = 31, + NULLITEM_REVERSE_CHARIOT_ALT = 68, + NULLITEM_REVERSE_STARS = 70, + NULLITEM_LAZARUS_SOUL_REVIVE = 113, + NULLITEM_SOUL_MAGDALENE = 114, + NULLITEM_SOUL_BLUEBABY = 115, + NULLITEM_SOUL_JUDAS = 128, + NULLITEM_HEMOPTYSIS_BOOST = 127, NULLITEM_ERA_WALK = 42, NULLITEM_HUGE_GROWTH = 41, NULLITEM_PUBERTY = 1, @@ -707,6 +809,7 @@ enum PlayerItemId : int NULLITEM_EXTRA_BIG_FAN = 107, NULLITEM_HORSE_PUBERTY = 119, NULLITEM_I_FOUND_HORSE_PILLS = 118, + NULLITEM_BETHANY_B_BIRTHRIGHT = 122, PILLEFFECT_FULL_HEALTH = 5, PILLEFFECT_HEALTH_UP = 7, @@ -876,13 +979,14 @@ struct CostumeWalk bool isMoving = false; }; -// The item a player holds over its head, picked up and not yet added. +// The item a player holds over its head, picked up and not yet added, with the pool it came from (-1 for none). struct QueueItemData { ItemConfig_Item* item = nullptr; int charge = 0; uint32_t flags = 0; int varData = 0; + int itemPoolType = 0; }; // Which costume sprite draws a layer of the player's sprite, or -1 for the player's own. @@ -1058,6 +1162,7 @@ public: int eternalHearts = 0; int goldenHearts = 0; int jarHearts = 0; + int ventricleRazorPortal = 0; int maxHearts = 0; int redHearts = 0; int rottenHearts = 0; @@ -1080,6 +1185,12 @@ public: bool hasGoldenBomb = false; bool hasGoldenKey = false; + // The stat ups Candy Heart's and Soul Locket's hearts collected (damage, tears, range, shot speed, speed, luck), + // and the damage ups 007d3330 grants. + std::array candyHeartStatUps{}; + std::array soulLocketStatUps{}; + int bonusDamageUps = 0; + TearFlags tearFlags; ColorMod laserColor = COLOR_DEFAULT; ColorMod tearColor = COLOR_DEFAULT; @@ -1235,6 +1346,7 @@ public: EntityDesc friendBallEnemy; EntityPtr astralProjectionBody; EntityPtr babyFamiliar; + EntityPtr bestFriend; EntityPtr breathOfLifeEffect; EntityPtr darkEsau; EntityPtr salvationEffect; @@ -1344,6 +1456,7 @@ public: short numLeprosy = 0; short tonsilCount = 0; short tonsilCounter = 0; + short versusPauseTimer = 0; bool isBrokenRemotePending = false; bool isDarkArtsBlastPending = false; bool isInEvilCharmHazard = false; diff --git a/src/entity_player_actives.cpp b/src/entity_player_actives.cpp index 4fbb67c..c882a09 100644 --- a/src/entity_player_actives.cpp +++ b/src/entity_player_actives.cpp @@ -36,10 +36,8 @@ constexpr int BATTERY_CHARGE = 6; constexpr int BATTERY_MICRO_CHARGE = 2; constexpr int CHARGE_FLASH_MAX = 12; constexpr int EVENT_BATTERIES_COLLECTED = 195; -constexpr int DAMAGE_COUNTDOWN_FRAMES = 30; constexpr int GLOWING_HOUR_GLASS_LIT_USES = 3; constexpr float THE_POOP_FART_RADIUS = 120; -constexpr int GOLDEN_RAZOR_PRICE = 5; constexpr int INPUT_HOOK_PRESSED = 0; constexpr int INPUT_HOOK_TRIGGERED = 1; constexpr int INPUT_RAW_ACTION = 33; @@ -58,7 +56,6 @@ constexpr int TIMED_RECHARGE_STEP = 1; constexpr int UNUSED_COLLECTIBLES[] = {43, 61, 235}; constexpr int YUM_HEART_OTHER_HEARTS = 1; constexpr int YUM_HEART_OWN_HEARTS = 2; -constexpr uint8_t WILD_CARD_ACTIVE = 2; constexpr uint64_t KAMIKAZE_DAMAGE_FLAGS = DAMAGE_EXPLOSION | DAMAGE_NO_PENALTIES | DAMAGE_IGNORE_ARMOR; constexpr uint64_t RAZOR_BLADE_DAMAGE_FLAGS = DAMAGE_RED_HEARTS | DAMAGE_INVINCIBLE; constexpr uint64_t SPIDER_BUTT_DAMAGE_FLAGS = DAMAGE_IGNORE_ARMOR; @@ -85,13 +82,8 @@ constexpr float METRONOME_DEATH_CERTIFICATE_CHANCE = 0.15f; constexpr float METRONOME_GENESIS_CHANCE = 0.25f; // Delirious's friends: the bosses that come in pairs, how far apart, its hallucination and its wisps (00b62c80). -constexpr int DELIRIOUS_LARRY_JR = 19; -constexpr int DELIRIOUS_LOKI = 69; constexpr int DELIRIOUS_LOKII = 1; -constexpr int DELIRIOUS_HEADLESS_HORSEMAN = 82; -constexpr int DELIRIOUS_HORSEMAN_HEAD = 83; constexpr float DELIRIOUS_HORSEMAN_HEAD_HEALTH = 50; -constexpr int DELIRIOUS_GURGLING = 237; constexpr float DELIRIOUS_PAIR_SPACING = 40; constexpr float DELIRIOUS_HALF_TURN = 3.14f; constexpr int DELIRIOUS_HALLUCINATION_FRAMES = 25; @@ -145,7 +137,7 @@ constexpr ActiveRelease ACTIVE_RELEASES[] = { {346, "Rebirth"}, {441, "Afterbirth"}, {552, "Afterbirth+"}, {COLLECTIBLE_VANILLA_COUNT - 1, "Repentance"}}; // 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) +void sound_play_local(Entity_Player& player, int sound) { int id = sound; @@ -154,7 +146,7 @@ static void sound_play_local(Entity_Player& player, int sound) } // Holds the item up for its use animation, unless the use hides it. -static void use_animate(ItemUse& use) +void use_animate(ItemUse& use) { if (use.isShowAnimation) use.player.AnimateCollectible(use.id, "UseItem", "PlayerPickupSparkle"); } @@ -168,19 +160,19 @@ static void glass_cannon_mend(Entity_Player& player, int slot) } // The entities the room updates, as Room::GetEntities lists them. -static EntityList_EL& room_entities() +EntityList_EL& room_entities() { return g_game->room->GetEntities()->updateEL; } // The enemies an item affects: vulnerable ones other than the player. -static bool is_item_target(Entity* entity, Entity_Player& player) +bool is_item_target(Entity* entity, Entity_Player& player) { return entity->IsVulnerableEnemy(nullptr) && entity != &player; } // Spawns the battery spark over the player that an overcharge or a 9 Volt refill shows. -static void battery_effect_spawn(Entity_Player& player) +void battery_effect_spawn(Entity_Player& player) { EntitySpawn spawn = {.position = player.pos, .subType = 1, .type = ENTITY_EFFECT, .variant = EFFECT_HEART, .seed = Random()}; @@ -1052,8 +1044,8 @@ struct DeliriousSpawn // its head) and the Gurglings. static bool is_delirious_pair(const DeliriousBoss& boss) { - return boss.type == DELIRIOUS_LARRY_JR || (boss.type == DELIRIOUS_LOKI && boss.variant == DELIRIOUS_LOKII) || - boss.type == DELIRIOUS_GURGLING || boss.type == DELIRIOUS_HEADLESS_HORSEMAN; + return boss.type == ENTITY_LARRYJR || (boss.type == ENTITY_LOKI && boss.variant == DELIRIOUS_LOKII) || + boss.type == ENTITY_GURGLING || boss.type == ENTITY_HEADLESS_HORSEMAN; } // Gives Delirium's look to the other segments of a chained boss: from its first segment down the children, until the @@ -1105,9 +1097,9 @@ void Entity_Player::console_spawn(const DeliriousBoss& boss, bool isAddWisp) Vector offset = vector_make(std::cos(angle) * DELIRIOUS_PAIR_SPACING, std::sin(angle) * DELIRIOUS_PAIR_SPACING); DeliriousSpawn partner = spawns[0]; partner.position = vector_make(pos.x + offset.x, pos.y + offset.y); - if (boss.type == DELIRIOUS_HEADLESS_HORSEMAN) + if (boss.type == ENTITY_HEADLESS_HORSEMAN) { - partner.type = DELIRIOUS_HORSEMAN_HEAD; + partner.type = ENTITY_HORSEMAN_HEAD; partner.health = DELIRIOUS_HORSEMAN_HEAD_HEALTH; } spawns.push_back(partner); @@ -1168,14 +1160,14 @@ void Game::ShowHallucination(int frames, int backdrop) } // Holds the item up once, so a mod's use does not raise it again. -static void use_raise(ItemUse& use) +void use_raise(ItemUse& use) { use_animate(use); use.isLuaAnimationAllowed = false; } // The books whose effect is all in their room effect: their sound, the item raised. -static void sound_raise_use(ItemUse& use, int sound) +void sound_raise_use(ItemUse& use, int sound) { sound_play(sound); use_raise(use); @@ -1344,8 +1336,7 @@ static void pocket_item_use(ItemUse& use) if (use.isShowAnimation) player.AnimatePill(pill, "UseItem"); } -// Runs an item's own effect. The items without one of their own only add their room effect, and the ones not -// written yet stop the game, named by the release that added them. +// Runs an item's own effect. The Rebirth and early Afterbirth ones (below 400) not cased here run in their own file. static void item_effect_run(ItemUse& use) { switch (use.id) @@ -1441,6 +1432,14 @@ static void item_effect_run(ItemUse& use) return; } } + if (use.id < FIRST_REPENTANCE_ACTIVE) rebirth_item_effect_run(use); + else repentance_item_effect_run(use); +} + +// Stops the game at an active whose own case is not written yet, named by the release that added it. The items without +// a case only add their room effect. +void active_missing_report(ItemUse& use) +{ if (std::ranges::find(CASED_ACTIVES, use.id) == std::end(CASED_ACTIVES)) return; const ActiveRelease* release = std::ranges::find_if(ACTIVE_RELEASES, [&](const ActiveRelease& each) diff --git a/src/entity_player_actives_rebirth.cpp b/src/entity_player_actives_rebirth.cpp new file mode 100644 index 0000000..8140ff3 --- /dev/null +++ b/src/entity_player_actives_rebirth.cpp @@ -0,0 +1,1532 @@ +#include "entity_player.h" +#include "active_items.h" +#include "boss_ai.h" +#include "entity_bomb.h" +#include "entity_effect.h" +#include "entity_familiar.h" +#include "entity_laser.h" +#include "entity_npc.h" +#include "entity_pickup.h" +#include "entity_tear.h" +#include "game.h" +#include "grid_entity_door.h" +#include "hud.h" +#include "item_pool.h" +#include "level.h" +#include "log.h" +#include "loot_list.h" +#include "manager.h" +#include "npc_ai.h" +#include "npc_basement.h" +#include "room.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include +#include +#include + +constexpr float NECRONOMICON_DAMAGE = 40; +constexpr float NECRONOMICON_VERSUS_DAMAGE = 20; +constexpr float NECRONOMICON_VERSUS_PAGE_DAMAGE = 10; +constexpr int NECRONOMICON_SHAKE = 15; +constexpr int NECRONOMICON_PARTICLES_MIN = 3; +constexpr int NECRONOMICON_PARTICLES_RANGE = 5; +constexpr float NECRONOMICON_PARTICLE_SPEED_MIN = 2; +constexpr float NECRONOMICON_PARTICLE_SPEED_RANGE = 4; +constexpr std::array NECRONOMICON_SPLAT_TINT = {0.2f, 0.2f, 0.2f, 1}; +constexpr ColorMod NECRONOMICON_POOF_COLOR = {{0.2f, 0.2f, 0.2f, 0.6f}, {1, 1, 1, 1}, {0, 0, 0}}; +constexpr ColorMod NECRONOMICON_GORE_COLOR = {{0.2f, 0.2f, 0.2f, 1}, {1, 1, 1, 1}, {0, 0, 0}}; +constexpr int BLOOD_EXPLOSION_LARGE = 3; +constexpr float QUARTER_TURN_DEGREES = 90; +constexpr float BELIAL_DAMAGE_SCALE = 1.4f; +constexpr float BELIAL_TEAR_SCALE_BONUS = 0.5f; +constexpr ColorMod FLUSH_POOP_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {39 / 255.0f, 25 / 255.0f, 22 / 255.0f}}; + +constexpr int VERSUS_EFFECT_FRAMES = 450; +constexpr float HOURGLASS_VERSUS_SLOW = 0.9f; + +constexpr int BOOK_OF_SIN_KINDS = 7; +constexpr uint32_t BOOK_OF_SIN_PICK_SHIFT = 35; +constexpr int ACHIEVEMENT_GOLDEN_HEARTS = 224; +constexpr int ACHIEVEMENT_GOLDEN_BATTERIES = 615; + +constexpr float BEAN_FART_RADIUS = 85; +constexpr float BEAN_PUSH_RADIUS = 120; + +constexpr float MONSTER_MANUAL_VOLUME = 0.7f; +constexpr uint32_t MONSTER_MANUAL_SHIFT = 7; +constexpr size_t LEVEL_EFFECT_ITEMS_MAX = 64; + +constexpr int DEAD_SEA_SCROLLS_TRIES = 10; +// The first floor actives Dead Sea Scrolls draws from. +constexpr std::array DEAD_SEA_SCROLLS_ITEMS = {34, 35, 37, 38, 39, 41, 42, 44, 45, 56, 49, + 58, 77, 65, 66, 78, 83, 84, 85, 86, 93, 97, + 107, 102, 47, 123, 136, 146, 158, 160, 171, 192}; + +// Heart and battery subtypes the Book of Sin draws, with their weights. +struct SinWeight +{ + int subType = 0; + int weight = 0; + int achievement = 0; +}; + +constexpr SinWeight BOOK_OF_SIN_HEARTS[] = {{HEART_FULL, 30}, + {HEART_SOUL, 10}, + {HEART_BLACK, 10}, + {HEART_ETERNAL, 2}, + {HEART_GOLDEN, 2, ACHIEVEMENT_GOLDEN_HEARTS}, + {HEART_BONE, 2, ACHIEVEMENT_BONE_HEARTS}, + {HEART_ROTTEN, 4, ACHIEVEMENT_ROTTEN_HEARTS}}; +constexpr SinWeight BOOK_OF_SIN_BATTERIES[] = { + {BATTERY_NORMAL, 50}, {BATTERY_MEGA, 1}, {BATTERY_GOLDEN, 1, ACHIEVEMENT_GOLDEN_BATTERIES}}; + +// Spawns an effect at a position, with no spawner and a fresh seed. +static Entity* effect_spawn(int variant, const Vector& position, const Vector& velocity = {}, int subType = 0) +{ + return g_game->Spawn({.position = position, .velocity = velocity, .subType = subType, .type = ENTITY_EFFECT, + .variant = variant, .seed = Random()}); +} + +// The Necronomicon's gore on an enemy it hurt: a poof, a dark blood burst and splat, and three to seven drops. +static void necronomicon_gore_spawn(Entity& enemy) +{ + Entity* poof = effect_spawn(EFFECT_POOF01, enemy.pos); + poof->SetColor(NECRONOMICON_GORE_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + poof->Update(); + + Entity* burst = effect_spawn(EFFECT_BLOOD_EXPLOSION, enemy.pos, {}, BLOOD_EXPLOSION_LARGE); + burst->SetColor(NECRONOMICON_GORE_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + std::ranges::copy(NECRONOMICON_SPLAT_TINT, burst->sprite.color._tint); + + Entity* splat = effect_spawn(EFFECT_BLOOD_SPLAT, enemy.pos); + splat->SetColor(NECRONOMICON_GORE_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + splat->Update(); + + for (int i = random_below(NECRONOMICON_PARTICLES_RANGE) + NECRONOMICON_PARTICLES_MIN; i > 0; i--) + { + Vector offset = vector_scale(vector_scale(random_direction(), 0.5f), enemy.size); + Vector position = vector_add(enemy.pos, offset); + Vector direction = random_direction(); + Vector velocity = + vector_scale(direction, random_unit() * NECRONOMICON_PARTICLE_SPEED_RANGE + NECRONOMICON_PARTICLE_SPEED_MIN); + Entity* drop = effect_spawn(EFFECT_BLOOD_PARTICLE, position, velocity); + drop->SetColor(NECRONOMICON_GORE_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + drop->splatColor = NECRONOMICON_GORE_COLOR; + drop->Update(); + } +} + +// Necronomicon: 40 damage (more with Missing Page 2 and Missing Page) to every enemy, the screen shaken. A Necromancer's +// filled Necronomicon gives one charge back. +static void necronomicon_use(ItemUse& use) +{ + Entity_Player& player = use.player; + int slot = use.request.slot; + if (player.variant != PLAYER_VARIANT_PLAYER && !(use.request.flags & USE_ALLOWNONMAIN)) return use_animate(use); + + bool isVersus = g_game->deathmatchManager.is_active(); + float pageDamage = isVersus ? NECRONOMICON_VERSUS_PAGE_DAMAGE : NECRONOMICON_DAMAGE; + int pages = player.GetCollectibleNum(COLLECTIBLE_MISSING_PAGE_2) + player.GetTrinketMultiplier(TRINKET_MISSING_PAGE); + float damage = pages * pageDamage + (isVersus ? NECRONOMICON_VERSUS_DAMAGE : NECRONOMICON_DAMAGE); + + sound_play(SOUND_DEATH_CARD); + game_shake_screen(NECRONOMICON_SHAKE); + player.MakeGroundPoofAtSelf(NECRONOMICON_POOF_COLOR, 1); + EntityList_EL& entities = room_entities(); + for (size_t i = 0; i < entities.size(); i++) + { + Entity* entity = entities[i]; + if (!entity->IsEnemy() || entity == &player || entity->HasEntityFlags(FLAG_NO_TARGET)) continue; + if (entity->isInvincible || entity->HasEntityFlags(FLAG_FRIENDLY)) continue; + + entity->TakeDamage(damage, DAMAGE_IGNORE_ARMOR, EntityRef(&player), DAMAGE_COUNTDOWN_FRAMES); + if (player.HasCollectible(COLLECTIBLE_JAR_OF_FLIES)) entity->AddEntityFlags(FLAG_ADD_JAR_FLY); + necronomicon_gore_spawn(*entity); + } + + // The original reads the slot's data for a use from no slot too: here such a use gives no charge back. + if (slot >= 0 && player.HasPlayerForm(PLAYER_FORM_NECROMANCER) && player.activeItems[slot].varData == 1) + { + use.result.isDischarge = false; + player.AddActiveCharge(-1, slot, false, false, false); + if (player.GetActiveItem(slot) < 1) + { + player.activeItems[slot].varData = 0; + g_game->hud.InvalidateActiveItem(&player, slot); + } + player.active_used_post(slot, false, player.activeItems[slot].charge + 1); + } + use_animate(use); +} + +// The Hourglass: the room slowed, the music with it. In a versus match the other players slow down too. +static void hourglass_use(ItemUse& use) +{ + Entity_Player& player = use.player; + + sound_play(SOUND_HOURGLASS); + use_animate(use); + g_game->room->temporaryEffects.AddCollectibleEffect(use.id, true, 1); + g_manager->musicManager.PitchSlide(g_game->room->time_scale_update()); + if (!g_game->deathmatchManager.is_active()) return; + + int duration = g_manager->itemConfig.GetCollectible(use.id)->maxCooldown; + for (Entity_Player* each : g_game->playerManager.playerList) + if (each != &player && each != player.twin_get()) + each->AddSlowing(EntityRef(&player), duration, HOURGLASS_VERSUS_SLOW, COLOR_DEFAULT, false); +} + +// Monstro's Tooth: Monstro falls on the last enemy listed (a vulnerable one first, else any but a fireplace), or a +// player listed later. The room's first entity is never picked, and with no target Monstro falls on the user. +static void monstros_tooth_use(ItemUse& use) +{ + Entity_Player& player = use.player; + EntityList_EL& entities = room_entities(); + if (player.variant != PLAYER_VARIANT_PLAYER || entities.size() == 0) return; + + Entity* target = &player; + bool isVulnerableFound = false; + for (size_t i = 1; i < entities.size(); i++) + { + Entity* entity = entities[i]; + bool isEnemyTarget = entity->IsVulnerableEnemy(nullptr) || + (entity->IsEnemy() && entity->type != ENTITY_FIREPLACE && !isVulnerableFound); + bool isTarget = entity != &player && isEnemyTarget && !entity->isDead; + if ((!isTarget && entity->type != ENTITY_PLAYER) || entity->health <= 0) continue; + + target = entity; + isVulnerableFound = isVulnerableFound || entity->IsVulnerableEnemy(nullptr); + } + Entity* monstro = effect_spawn(EFFECT_MONSTROS_TOOTH, target->pos); + monstro->target = target; + monstro->Update(); + use_animate(use); +} + +// Adds the Book of Sin's weights to a picker: the locked kinds come as a plain one, kept apart from it. +static void sin_weights_add(WeightedOutcomePicker& picker, std::span weights) +{ + for (const SinWeight& weight : weights) + { + if (!weight.achievement) + { + picker.AddOutcomeWeight(weight.subType, weight.weight); + continue; + } + bool isUnlocked = g_manager->persistentGameData.Unlocked(weight.achievement); + picker.outcomes.push_back({isUnlocked ? weight.subType : 1, weight.weight}); + } +} + +// The Book of Sin: a random pickup by the player, a heart, bomb, key, pill, card, coin or battery. Daemon's Tail +// usually turns a heart into another kind. +static void book_of_sin_use(ItemUse& use) +{ + Entity_Player& player = use.player; + if (player.variant != PLAYER_VARIANT_PLAYER) return use_animate(use); + + sound_play(SOUND_BOOK_OF_SIN); + RNG& rng = player.GetCollectibleRNG(use.id); + int kind = (int)rng.RandomInt(BOOK_OF_SIN_KINDS); + uint32_t pickSeed = rng.Next(); + Vector position = room_free_pickup_position_find({.position = player.pos, .step = PICKUP_SPOT_STEP}); + int otherKind = (int)rng.RandomInt(BOOK_OF_SIN_KINDS - 1) + 1; + if (player.HasTrinket(TRINKET_DAEMONS_TAIL) && player.GetTrinketRNG(TRINKET_DAEMONS_TAIL).RandomInt(DAEMONS_TAIL_ODDS)) + kind = otherKind; + + constexpr std::array VARIANTS = {PICKUP_HEART, PICKUP_BOMB, PICKUP_KEY, + PICKUP_PILL, PICKUP_TAROTCARD, PICKUP_COIN, + PICKUP_LIL_BATTERY}; + constexpr std::array SUBTYPES = {0, 1, KEY_NORMAL, 0, 0, 0, 0}; + int subType = SUBTYPES[kind]; + uint32_t seed = rng.Next(); + if (kind == 0 || kind == BOOK_OF_SIN_KINDS - 1) + { + WeightedOutcomePicker picker; + sin_weights_add(picker, kind == 0 ? std::span(BOOK_OF_SIN_HEARTS) : BOOK_OF_SIN_BATTERIES); + subType = picker.PickOutcome(rng_make(pickSeed, BOOK_OF_SIN_PICK_SHIFT)); + } + g_game->Spawn({.position = position, .spawner = &player, .subType = subType, .type = ENTITY_PICKUP, + .variant = VARIANTS[kind], .seed = seed}); + use_animate(use); +} + +// A burst of blood out of the player: a splash the way a pickup would fly, and gore and drops around it. +static void blood_burst_spawn(Entity_Player& player) +{ + constexpr float BLOOD_BURST_VOLUME = 3; + constexpr float BLOOD_BURST_SPEED = 2; + constexpr float BLOOD_BURST_SPREAD = 20; + constexpr int BLOOD_BURST_GORE_MIN = 2; + constexpr int BLOOD_BURST_GORE_RANGE = 3; + constexpr int BLOOD_BURST_DROPS_MIN = 6; + constexpr int BLOOD_BURST_DROPS_RANGE = 6; + constexpr int BLOOD_PARTICLE_DROP = 99; + + g_manager->sfxManager.Play(SOUND_BLOODBANK_SPAWN, {.volume = BLOOD_BURST_VOLUME}); + Vector base = vector_scale(Entity_Pickup::GetRandomPickupVelocity(player.pos, nullptr, 0), BLOOD_BURST_SPEED); + effect_spawn(EFFECT_BLOOD_EXPLOSION, player.pos, base, BLOOD_EXPLOSION_LARGE); + int gore = random_below(BLOOD_BURST_GORE_RANGE) + BLOOD_BURST_GORE_MIN; + int count = random_below(BLOOD_BURST_DROPS_RANGE) + BLOOD_BURST_DROPS_MIN + gore; + for (int i = 0; i < count; i++) + { + Vector direction = tear_vector_rotate(base, random_unit() * BLOOD_BURST_SPREAD - BLOOD_BURST_SPREAD / 2); + Vector velocity = vector_scale(direction, random_unit()); + effect_spawn(EFFECT_BLOOD_PARTICLE, vector_add(player.pos, velocity), velocity, i < gore ? 0 : BLOOD_PARTICLE_DROP) + ->Update(); + } +} + +// Pinking Shears: a burst of blood, and the body walks off as flight for the room (Transcendence's look). In a versus +// match both last 450 frames. +static void pinking_shears_use(ItemUse& use) +{ + Entity_Player& player = use.player; + if (player.variant != PLAYER_VARIANT_PLAYER) return; + + blood_burst_spawn(player); + player.cacheFlags |= use.item->cacheFlags; + for (int item : {use.id, (int)COLLECTIBLE_TRANSCENDENCE}) + { + TemporaryEffect effect(g_manager->itemConfig.GetCollectible(item)); + if (g_game->deathmatchManager.is_active()) effect.cooldown = VERSUS_EFFECT_FRAMES; + player.temporaryEffects.AddEffect(effect, true, 1); + if (item == use.id) player.EvaluateItems(); + } + use.isAddEffect = false; +} + +// The Bean: a poison fart and a push around the player. +static void bean_use(ItemUse& use) +{ + Entity_Player& player = use.player; + + game_fart({.position = player.pos, .source = &player, .radius = BEAN_FART_RADIUS}); + game_butter_bean_fart( + {.position = player.pos, .source = &player, .radius = BEAN_PUSH_RADIUS, .isShowEffect = false}); +} + +// Monster Manual: a familiar for the floor, the one of its tagged items with the highest roll. +static void monster_manual_use(ItemUse& use) +{ + constexpr int MONSTER_MANUAL_DEFAULT = COLLECTIBLE_BROTHER_BOBBY; + + Entity_Player& player = use.player; + if (player.variant != PLAYER_VARIANT_PLAYER) return use_animate(use); + + g_manager->sfxManager.Play(SOUND_SATAN_GROW, {.volume = MONSTER_MANUAL_VOLUME}); + RNG rng = rng_make(player.GetCollectibleRNG(use.id).Next(), MONSTER_MANUAL_SHIFT); + int pick = MONSTER_MANUAL_DEFAULT; + float best = -1; + for (size_t id = 0; id < g_manager->itemConfig.collectibles.size(); id++) + { + if (!ItemConfig::is_collectible_tagged((int)id, TAG_MONSTER_MANUAL)) continue; + float roll = rng.RandomFloat(); + if (roll <= best) continue; + pick = (int)id; + best = roll; + } + if (player.levelEffectItems.size() < LEVEL_EFFECT_ITEMS_MAX) + { + player.temporaryEffects.AddCollectibleEffect(pick, true, 1); + player.levelEffectItems.push_back(pick); + } + use_animate(use); +} + +// Dead Sea Scrolls: one of 32 first floor actives used at once, named over the HUD, with its wisp for Book of +// Virtues. Ten tries skip what Cantripped forbids, then Tammy's Head. +static void dead_sea_scrolls_use(ItemUse& use) +{ + Entity_Player& player = use.player; + if (player.variant == PLAYER_VARIANT_PLAYER) + { + sound_play(SOUND_DEAD_SEA_SCROLLS); + if (player.itemState == 0) + { + int pick = COLLECTIBLE_TAMMYS_HEAD; + if (g_game->deathmatchManager.is_active()) + reconstruction_missing("Entity_Player::UseActiveItem 005b39d0 (Dead Sea Scrolls in a versus match)"); + for (int i = 0; i < DEAD_SEA_SCROLLS_TRIES; i++) + { + int id = DEAD_SEA_SCROLLS_ITEMS[player.GetCollectibleRNG(use.id).RandomInt(DEAD_SEA_SCROLLS_ITEMS.size())]; + if (g_game->challenge == CHALLENGE_CANTRIPPED && ItemConfig::is_collectible_tagged(id, TAG_NO_CANTRIP)) + continue; + pick = id; + break; + } + std::string name = g_manager->itemConfig.GetCollectible(pick)->GetLocalizedName(); + g_game->hud.show_pill_name(&player, name.c_str(), ""); + player.UseActiveItem({.item = pick, .flags = USE_NOANIM}); + player.TriggerBookOfVirtues(pick, 0); + } + } + if (!use.isShowAnimation) return; + bool isHeld = player.itemState != 0 && player.itemState != COLLECTIBLE_SHOOP_DA_WHOOP; + player.AnimateCollectible(use.id, isHeld ? "LiftItem" : "UseItem", "PlayerPickupSparkle"); +} + +// Forget Me Now's timer: the player reappears and the floor starts over on a new seed. +static void forget_me_now_restart(Entity_Effect* timer) +{ + Entity* parent = timer->parent.get(); + if (!parent || parent->type != ENTITY_PLAYER) return; + + Entity_Player* player = static_cast(parent); + bool isAltPath = g_game->stageType == STAGETYPE_REPENTANCE || g_game->stageType == STAGETYPE_REPENTANCE_B; + sound_play(SOUND_FORGET_ME_NOW); + player->PlayExtraAnimation("Appear"); + g_game->seedEffects.ForgetStageSeed(g_game->stage + isAltPath); + g_game->stageTransition.start({.player = player, .type = STAGE_TRANSITION_FORGET_ME_NOW, .isSameStage = true}); +} + +// Forget Me Now: the floor restarts a frame later. It goes once owned, or used through the Void. +static void forget_me_now_use(ItemUse& use) +{ + if (use.player.variant != PLAYER_VARIANT_PLAYER) return; + if (use.request.flags & (USE_OWNED | USE_VOID)) use.result.isRemove = true; + if (g_game->deathmatchManager.is_active()) + reconstruction_missing("Entity_Player::UseActiveItem 005b39d0 (Forget Me Now in a versus match)"); + + Entity_Effect* timer = Entity_Effect::CreateTimer(reinterpret_cast(&forget_me_now_restart), 1, 0, false); + timer->parent = &use.player; +} + +// FUN_0043e990 A wisp turned into a random other one: its look, config and health (kept below the new maximum) reloaded. +static void wisp_reroll(Entity_Familiar& wisp, RNG& rng) +{ + int subType = Entity_Familiar::GetRandomWisp(&rng); + if (subType == wisp.subtype) return; + + wisp.subtype = subType; + wisp.ResetColor(); + wisp.LoadEntityConfig(); + wisp.health = std::min(wisp.health, wisp.maxHitPoints); + wisp.entityGridCollisionClass = GRIDCOLL_NONE; + wisp.WispInit(); +} + +// Game::DevolveEnemy, which the D10 calls, is not written yet. +static void game_enemy_devolve(Entity& enemy) +{ + (void)enemy; + reconstruction_missing("Game::DevolveEnemy 00705480"); +} + +// The items held up until thrown or let go (Glass Cannon, Friend Ball): the item lifted, its sound played. +static void lift_sound_use(ItemUse& use, int sound) +{ + use.player.SetItemState(use.id); + use.player.AnimateCollectible(use.id, "LiftItem", "PlayerPickupSparkle"); + if (sound) sound_play(sound); +} + +// The Boomerang: held ready to throw, with its costume. +static void boomerang_use(ItemUse& use) +{ + use.player.SetItemState(use.id); + use.player.AddCostume(g_manager->itemConfig.GetNullItem(NULLITEM_BOOMERANG), false); +} +// Spawns a pickup at a free spot near the player, the seed drawn before the spot. +static Entity* pickup_spawn(Entity_Player& player, int variant, int subType, uint32_t seed) +{ + Vector position = room_free_pickup_position_find({.position = player.pos, .step = PICKUP_SPOT_STEP}); + return g_game->Spawn({.position = position, .spawner = &player, .subType = subType, .type = ENTITY_PICKUP, + .variant = variant, .seed = seed}); +} + +// Whether Book of Virtues turns this use into wisps. +static bool is_wisp_use(ItemUse& use) +{ + return use.player.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES) && use.isWispAllowed; +} + +// IV Bag: half a heart of blood for one to three coins (one or two in hard mode), PHD adding one. The Keepers pay +// coin hearts instead, for a coin at most half the time (a quarter with PHD's extra, Piggy Bank doubling the odds). +static void iv_bag_use(ItemUse& use) +{ + constexpr float KEEPER_COIN_ODDS = 0.5f; + constexpr float KEEPER_SECOND_COIN_ODDS = 0.25f; + + Entity_Player& player = use.player; + if (player.variant != PLAYER_VARIANT_PLAYER) return use_animate(use); + + sound_play(SOUND_IV_BAG); + uint64_t flags = DAMAGE_RED_HEARTS | DAMAGE_INVINCIBLE | DAMAGE_IV_BAG; + if (g_game->challenge == CHALLENGE_GUARDIAN) flags |= DAMAGE_ISAAC_HURT; + player.damageCooldown = 0; + player.TakeDamage(1, flags, EntityRef(), DAMAGE_COUNTDOWN_FRAMES); + + int coins = 0; + if (player.playerType == PLAYER_KEEPER || player.playerType == PLAYER_KEEPER_B) + { + if (player.HasCollectible(COLLECTIBLE_PHD) && random_below(2) == 0) coins = 1; + float scale = player.HasCollectible(COLLECTIBLE_PIGGY_BANK) ? 2 : 1; + coins += random_unit() * scale <= (coins == 0 ? KEEPER_COIN_ODDS : KEEPER_SECOND_COIN_ODDS); + } + else + { + int roll = (int)player.dropRNG.RandomInt(game_is_hard_mode() ? 2 : 3); + coins = std::max(roll, 1) + player.HasCollectible(COLLECTIBLE_PHD); + } + for (int i = 0; i < coins; i++) pickup_spawn(player, PICKUP_COIN, 0, Random()); + use_animate(use); +} + +// Best Friend: a decoy bomb enemies go after, lit for 150 frames, carrying the bomb effects, bigger and stronger. +static void best_friend_use(ItemUse& use) +{ + constexpr int BEST_FRIEND_FUSE = 150; + constexpr float BEST_FRIEND_SCALE = 1.5f; + constexpr float BEST_FRIEND_DAMAGE_BONUS = 85; + + Entity_Player& player = use.player; + if (player.variant != PLAYER_VARIANT_PLAYER) return; + + Entity* spawned = g_game->Spawn({.position = player.pos, .spawner = &player, .type = ENTITY_BOMB, + .variant = BOMB_DECOY, .seed = Random()}); + Entity_Bomb* bomb = dynamic_cast(spawned); + player.bestFriend = bomb; + if (!bomb) return; + + sound_play(SOUND_BESTFRIEND); + bomb->SetExplosionCountdown(BEST_FRIEND_FUSE); + bomb->tearFlags = player.GetBombFlags(false); + bomb->isLoadCostumes = true; + bomb->scale = BEST_FRIEND_SCALE; + bomb->explosionDamage += BEST_FRIEND_DAMAGE_BONUS; +} + +// Crystal Ball: the map shown, and a card or (half the time, Daemon's Tail usually turning it into a card) a soul heart. +static void crystal_ball_use(ItemUse& use) +{ + Entity_Player& player = use.player; + if (player.variant != PLAYER_VARIANT_PLAYER) return use_animate(use); + + RNG& rng = player.GetCollectibleRNG(use.id); + g_game->ShowMap(); + bool isCard = rng.RandomInt(2) == 0 || + (player.HasTrinket(TRINKET_DAEMONS_TAIL) && + player.GetTrinketRNG(TRINKET_DAEMONS_TAIL).RandomInt(DAEMONS_TAIL_ODDS) != 0); + uint32_t seed = rng.Next(); + if (isCard) pickup_spawn(player, PICKUP_TAROTCARD, 0, seed); + else pickup_spawn(player, PICKUP_HEART, HEART_SOUL, seed); + sound_play(SOUND_CRYSTAL_BALL); + use_animate(use); +} + +// The D6's ending for the dice that reroll a room: the roll's sound and the item raised. +static void dice_end(ItemUse& use) +{ + if (!use.isShowAnimation) return; + sound_play_local(use.player, SOUND_D6_ROLL); + use_animate(use); +} + +// The D20: the shop restocked, and every pickup but the pedestals rerolled. A chest mostly stays a chest (a plain or +// locked one), a shop item stays one. With Book of Virtues the pickups go instead, a fifth of them as wisps. +static void d20_use(ItemUse& use) +{ + constexpr uint32_t D20_REROLL_SHIFT = 61; + constexpr uint32_t D20_WISP_SHIFT = 35; + constexpr int D20_WISP_ODDS = 5; + constexpr int D20_CHEST_KEEP_ODDS = 5; + constexpr int D20_OTHER_ODDS = 10; + constexpr int D20_LOCKED_CHEST_ODDS = 4; + + Entity_Player& player = use.player; + if (player.variant == PLAYER_VARIANT_PLAYER) + { + if (g_game->room->roomType == ROOM_SHOP) + reconstruction_missing("Entity_Player::UseActiveItem 005b39d0 (the D20 in a shop: Room::ShopReshuffle 00816000)"); + for (Entity* entity : entity_query(ENTITY_PICKUP, -1)) + { + if (entity->isDead || entity->variant == PICKUP_COLLECTIBLE) continue; + Entity_Pickup* pickup = dynamic_cast(entity); + if (!pickup || !pickup->CanReroll()) continue; + + if (is_wisp_use(use)) + { + RNG rng = rng_make(pickup->initSeed, D20_WISP_SHIFT); + if (rng.RandomInt(D20_WISP_ODDS) == 0) + player.AddWisp(Entity_Familiar::GetRandomWisp(&rng), pickup->pos, false, false); + pickup->Remove(); + continue; + } + if (pickup->price != 0) + { + pickup->Morph(pickup->type, PICKUP_SHOPITEM, 0, true, false, false); + continue; + } + RNG rng = rng_make(pickup->initSeed, D20_REROLL_SHIFT); + bool isChest = Entity_Pickup::IsChest(pickup->variant); + if ((!isChest || rng.RandomInt(D20_CHEST_KEEP_ODDS) == 0) && rng.RandomInt(D20_OTHER_ODDS) != 0) + pickup->Morph(pickup->type, 0, 0, true, false, false); + else + { + int chest = rng.RandomInt(D20_LOCKED_CHEST_ODDS) != 0 ? PICKUP_CHEST : PICKUP_LOCKEDCHEST; + pickup->Morph(pickup->type, chest, 0, true, false, false); + } + } + } + dice_end(use); +} + +// Whether Dad's Key opens a door: not a mirror, a photo door or the Mom's Heart exit, nor a barred mineshaft. +static bool is_dads_key_door(GridEntity_Door& door) +{ + if (door.doorFlags & (DOOR_FLAG_MIRROR | DOOR_FLAG_PHOTO)) return false; + if ((door.doorFlags & DOOR_FLAG_MINESHAFT) && door.variant == DOOR_LOCKED_BARRED) return false; + return door.get_secret_exit_kind() != SECRET_EXIT_MOMS_HEART; +} + +// Dad's Key: every door of the room unlocked or forced open, for the room. +static void dads_key_use(ItemUse& use) +{ + Entity_Player& player = use.player; + if (player.variant == PLAYER_VARIANT_PLAYER) + { + sound_play(SOUND_GOLDENKEY); + for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++) + { + GridEntity_Door* door = g_game->room->GetDoor(slot); + if (!door || !is_dads_key_door(*door) || door->TryUnlock(player, true)) continue; + door->Open(); + door->TryBlowOpen(false, nullptr); + } + g_game->room->temporaryEffects.AddCollectibleEffect(use.id, true, 1); + } + use_animate(use); +} + +// The Portable Slot's coins: one or two, each with a wisp for Book of Virtues. +static void portable_slot_coins(ItemUse& use) +{ + Entity_Player& player = use.player; + + sound_play(SOUND_PORTABLE_SLOT_WIN); + for (int i = std::max(random_below(3), 1); i > 0; i--) + { + pickup_spawn(player, PICKUP_COIN, 0, Random()); + if (is_wisp_use(use)) player.AddWisp(use.id, player.pos, false, false); + } +} + +// The Portable Slot: a coin for a slot machine's roll (Lucky Foot's luckier one). It pays a fly or pretty fly, a +// bomb, a heart, a key, a pill or coins, or nothing with a sad face. Daemon's Tail turns most hearts into coins. +static void portable_slot_use(ItemUse& use) +{ + constexpr int SLOT_FLY = 3; + constexpr int SLOT_BOMB = 4; + constexpr int SLOT_HEART = 5; + constexpr int SLOT_HEART_TOO = 6; + constexpr int SLOT_KEY = 7; + constexpr int SLOT_PILL = 8; + constexpr int SLOT_SKIPPED = 9; + constexpr int SLOT_COINS_FIRST = 10; + constexpr int SLOT_COINS_LAST = 12; + + struct SlotPrize + { + int outcome = 0; + int variant = 0; + int wisp = 0; + }; + constexpr SlotPrize PRIZES[] = {{SLOT_BOMB, PICKUP_BOMB, COLLECTIBLE_MR_BOOM}, + {SLOT_HEART, PICKUP_HEART, COLLECTIBLE_YUM_HEART}, + {SLOT_HEART_TOO, PICKUP_HEART, COLLECTIBLE_YUM_HEART}, + {SLOT_KEY, PICKUP_KEY, COLLECTIBLE_DADS_KEY}, + {SLOT_PILL, PICKUP_PILL, COLLECTIBLE_MOMS_BOTTLE_OF_PILLS}}; + + Entity_Player& player = use.player; + if (player.variant != PLAYER_VARIANT_PLAYER || player.numCoins < 1) return; + + player.AnimateCollectible(use.id, "UseItem", "PlayerPickupSparkle"); + player.AddCoins(-1); + sound_play_local(player, SOUND_PORTABLE_SLOT_USE); + int roll = random_below(player.HasCollectible(COLLECTIBLE_LUCKY_FOOT) ? 15 : 21); + int outcome = roll + SLOT_FLY < SLOT_SKIPPED ? roll + SLOT_FLY : roll + SLOT_FLY + 1; + bool isCoins = outcome >= SLOT_COINS_FIRST && outcome <= SLOT_COINS_LAST; + if (outcome == SLOT_KEY) isCoins = random_below(3) == 0; + else if ((outcome == SLOT_HEART || outcome == SLOT_HEART_TOO) && player.HasTrinket(TRINKET_DAEMONS_TAIL)) + isCoins = player.GetTrinketRNG(TRINKET_DAEMONS_TAIL).RandomInt(DAEMONS_TAIL_ODDS) != 0; + if (isCoins) return portable_slot_coins(use); + + if (outcome == SLOT_FLY && random_below(3) != 0) + { + uint32_t seed = Random(); + Vector position = room_free_pickup_position_find({.position = player.pos, .step = PICKUP_SPOT_STEP}); + g_game->Spawn({.position = position, .type = ENTITY_FLY, .seed = seed}); + return player.AnimateSad(); + } + if (outcome == SLOT_FLY) + { + player.AddPrettyFly(); + if (is_wisp_use(use)) + for (int i = 0; i < 3; i++) player.AddWisp(COLLECTIBLE_GUPPYS_HEAD, player.pos, false, false); + return sound_play(SOUND_PORTABLE_SLOT_WIN); + } + const SlotPrize* prize = std::ranges::find(PRIZES, outcome, &SlotPrize::outcome); + if (prize == std::end(PRIZES)) return player.PlayExtraAnimation("Sad"); + + sound_play(SOUND_PORTABLE_SLOT_WIN); + pickup_spawn(player, prize->variant, 0, Random()); + if (is_wisp_use(use)) player.AddWisp(prize->wisp, player.pos, false, false); +} + +// Clear Rune: the held rune's effect copied (its charge taken from the rune), remembered for Wild Card. +static void clear_rune_use(ItemUse& use) +{ + Entity_Player& player = use.player; + int card = player.GetCard(0); + ItemConfig_Card* config = g_manager->itemConfig.GetCard(card); + if (player.variant == PLAYER_VARIANT_PLAYER && card != 0 && config && config->IsRune()) + { + const ActiveUse& request = use.request; + if ((request.flags & USE_OWNED) && request.slot >= 0 && player.activeItems[request.slot].item == use.id) + player.activeItems[request.slot].varData = config->mimicCharge; + player.UseCard(card, USE_MIMIC | USE_NOANNOUNCER); + player.wildCardItemType = WILD_CARD_CARD; + player.wildCardItem = card; + player.wildCardVarData = 0; + } + use_animate(use); +} + +// How to Jump: a leap 60 frames along the player's way, pulled back off blocked cells and enemies onto free ground, +// or kept in place. +static void how_to_jump_use(ItemUse& use) +{ + constexpr float JUMP_LOOKAHEAD = 60; + constexpr float JUMP_MARGIN = 20; + constexpr float JUMP_BACK_STEP = 10; + constexpr float JUMP_ENEMY_GAP = 5; + + Entity_Player& player = use.player; + if (player.variant != PLAYER_VARIANT_PLAYER) return; + + Room& room = *g_game->room; + Vector target = room.GetClampedPosition(vector_add(player.pos, vector_scale(player.velocity, JUMP_LOOKAHEAD)), + JUMP_MARGIN); + Vector step = vector_sub(player.pos, target); + float remaining = vector_length(step); + step = vector_scale(vector_normalized(step), JUMP_BACK_STEP); + bool isFound = false; + while (remaining > 0 && !isFound) + { + if (room_grid_collision_at(target) != 0) + { + target = vector_add(target, step); + remaining -= vector_length(step); + continue; + } + isFound = true; + EntityList_EL& entities = room_entities(); + for (size_t i = 0; i < entities.size(); i++) + { + Entity* enemy = entities[i]; + float reach = enemy->size + player.size + JUMP_ENEMY_GAP; + if (!enemy->IsEnemy() || vector_length_squared(vector_sub(enemy->pos, target)) >= reach * reach) continue; + target = vector_add(target, step); + remaining -= vector_length(step); + isFound = false; + } + player.targetPosition = room.GetClampedPosition(target, JUMP_MARGIN); + player.velocity = {}; + player.entityCollisionClass = ENTCOLL_NONE; + player.entityGridCollisionClass = GRIDCOLL_NONE; + } + if (remaining <= 0) player.targetPosition = player.pos; + sound_play(SOUND_HOW_TO_JUMP); + if (!player.canFly) player.PlayExtraAnimation("Jump"); +} + +// The D100: the D6, D20, D10, D12, D7, D8, D1 and D4 at once. Book of Virtues adds a wisp and rerolls the player's +// wisps. +static void d100_use(ItemUse& use) +{ + constexpr int D100_DICE[] = {COLLECTIBLE_D6, COLLECTIBLE_D20, COLLECTIBLE_D10, COLLECTIBLE_D12, + COLLECTIBLE_D7, COLLECTIBLE_D8, COLLECTIBLE_D1, COLLECTIBLE_D4}; + + Entity_Player& player = use.player; + if (player.variant == PLAYER_VARIANT_PLAYER) + for (int die : D100_DICE) player.UseActiveItem({.item = die, .flags = USE_NOANIM}); + if (is_wisp_use(use)) + { + player.AddWisp(COLLECTIBLE_BOOK_OF_VIRTUES, player.pos, false, false); + for (Entity* entity : entity_query(ENTITY_FAMILIAR, Entity_Familiar::WISP)) + { + Entity_Familiar* wisp = static_cast(entity); + if (wisp->player == &player) wisp_reroll(*wisp, player.GetCollectibleRNG(use.id)); + } + } + dice_end(use); +} + +// The D4: the player's items rerolled (the actives too when the use asks to remove them). Book of Virtues trades every +// wisp for new ones, one for every second item in the history, twelve at most. +static void d4_use(ItemUse& use) +{ + constexpr int D4_WISPS_MAX = 12; + + Entity_Player& player = use.player; + if (is_wisp_use(use)) + { + for (Entity* wisp : entity_query(ENTITY_FAMILIAR, Entity_Familiar::WISP)) wisp->Remove(); + int added = 0; + for (size_t i = 0; i < player.history.historyItems.size() && added < D4_WISPS_MAX; i += 2, added++) + player.AddWisp(Entity_Familiar::GetRandomWisp(&player.GetCollectibleRNG(COLLECTIBLE_D4)), player.pos, false, + false); + } + player.reroll_collectibles_on_damage(&player.GetCollectibleRNG(COLLECTIBLE_D4), use.request.flags & USE_REMOVEACTIVE); + dice_end(use); +} + +// The D10: every living enemy that can devolves into a weaker one. +static void d10_use(ItemUse& use) +{ + if (use.player.variant == PLAYER_VARIANT_PLAYER) + { + std::vector enemies; + for (Entity* entity : room_entities()) + if (!entity->HasMortalDamage() && !entity->isDead && entity->CanDevolve()) enemies.emplace_back() = entity; + for (EntityPtr& enemy : enemies) + if (enemy) game_enemy_devolve(*enemy.get()); + } + dice_end(use); +} + +// Blank Card: the held card's effect copied (its charge taken from the card), remembered for Wild Card. A copied +// ? Card goes from the pockets, and not with the Void in the first slot. The Sun unlocks an achievement. +static void blank_card_use(ItemUse& use) +{ + constexpr int ACHIEVEMENT_BLANK_CARD_SUN = 258; + + Entity_Player& player = use.player; + int card = player.GetCard(0); + ItemConfig_Card* config = card ? g_manager->itemConfig.GetCard(card) : nullptr; + bool isVoidQuestion = card == CARD_QUESTIONMARK && player.activeItems[ACTIVE_SLOT_PRIMARY].item == COLLECTIBLE_VOID; + if (player.variant != PLAYER_VARIANT_PLAYER || !config || isVoidQuestion || !config->IsCard()) + return use_animate(use); + + const ActiveUse& request = use.request; + if ((request.flags & USE_OWNED) && request.slot >= 0 && player.activeItems[request.slot].item == use.id) + player.activeItems[request.slot].varData = config->mimicCharge; + player.UseCard(card, USE_MIMIC | USE_NOANNOUNCER); + if (card == CARD_QUESTIONMARK) + { + std::shift_left(player.pocketItems.begin(), player.pocketItems.end(), 1); + player.pocketItems.back() = {.type = player.pocketItems[POCKET_SLOT_COUNT - 2].type}; + use.isLuaAnimationAllowed = false; + return; + } + if (card != CARD_WILD) + { + player.wildCardItemType = WILD_CARD_CARD; + player.wildCardItem = card; + player.wildCardVarData = 0; + } + if (card == CARD_SUN) g_manager->persistentGameData.TryUnlock(ACHIEVEMENT_BLANK_CARD_SUN); + use_animate(use); +} + +// The Book of Secrets: one of the map effects the floor lacks (blue map, compass, map), or the whole floor when it has +// them all. Its room effect lasts 45 frames. +static void book_of_secrets_use(ItemUse& use) +{ + constexpr uint32_t SECRETS_PICK_SHIFT = 35; + constexpr int SECRETS_EFFECT_FRAMES = 45; + constexpr LevelStateFlag SECRETS_FLAGS[] = {LEVEL_STATE_BLUE_MAP_EFFECT, LEVEL_STATE_COMPASS_EFFECT, + LEVEL_STATE_MAP_EFFECT}; + + Entity_Player& player = use.player; + if (player.variant == PLAYER_VARIANT_PLAYER) + { + WeightedOutcomePicker picker; + for (int i = 0; i < 3; i++) + if (!g_game->Level::GetStateFlag(SECRETS_FLAGS[i])) picker.AddOutcomeWeight(i, 1); + if (picker.outcomes.empty()) + { + g_game->isCanSeeEverything = true; + g_game->UpdateVisibility(); + } + else + { + int pick = picker.PickOutcome(rng_make(player.GetCollectibleRNG(use.id).Next(), SECRETS_PICK_SHIFT)); + if (pick == 0) g_game->ApplyBlueMapEffect(); + else if (pick == 1) g_game->ApplyCompassEffect(true); + else g_game->ApplyMapEffect(); + } + TemporaryEffect effect(g_manager->itemConfig.GetCollectible(COLLECTIBLE_BOOK_OF_SECRETS)); + effect.cooldown = SECRETS_EFFECT_FRAMES; + g_game->room->temporaryEffects.AddEffect(effect, true, 1); + } + use_animate(use); +} + +// Box of Spiders: four to eight blue spiders, or as many wisps with Book of Virtues. +static void box_of_spiders_use(ItemUse& use) +{ + Entity_Player& player = use.player; + if (player.variant == PLAYER_VARIANT_PLAYER) + for (int i = random_below(5) + 4; i > 0; i--) + { + if (is_wisp_use(use)) + { + player.AddWisp(use.id, player.pos, false, false); + continue; + } + player.ThrowBlueSpider(player.pos, {}); + sound_play(SOUND_BOX_SPIDERS); + } + use_animate(use); +} + +// Judas' Birthright on The Jar: up to two of its hearts as a pool of blood creep and a burst, sized by them. +static void jar_belial_spill(Entity_Player& player, int hearts) +{ + constexpr float JAR_SCALE_PER_HEART = 0.25f; + constexpr float JAR_SCALE_BASE = 0.5f; + constexpr float JAR_CREEP_SCALE = 3; + constexpr int JAR_CREEP_FRAMES = 450; + constexpr float JAR_BURST_LARGE = 0.75f; + + player.trigger_book_of_belial_passive(COLLECTIBLE_THE_JAR, hearts); + float scale = hearts * JAR_SCALE_PER_HEART + JAR_SCALE_BASE; + Entity_Effect* creep = static_cast( + g_game->Spawn({.position = player.pos, .spawner = &player, .type = ENTITY_EFFECT, + .variant = EFFECT_PLAYER_CREEP_RED, .seed = Random()})); + creep->sprite.scale = vector_make(scale * JAR_CREEP_SCALE, scale * JAR_CREEP_SCALE); + creep->SetTimeout(JAR_CREEP_FRAMES); + creep->Update(); + + Entity_Effect* burst = static_cast( + effect_spawn(EFFECT_BLOOD_EXPLOSION, player.pos, {}, (hearts > JAR_BURST_LARGE) + BLOOD_EXPLOSION_LARGE)); + burst->rotation = random_unit() * FULL_TURN_DEGREES; + burst->sprite.scale = vector_make(scale, scale); + burst->Update(); +} + +// The Jar: the hearts it collected let out as full and half hearts, Judas' Birthright spilling two of them as blood +// from the first slot, Book of Virtues a wisp for each full heart (a half-health one for a half). +static void jar_use(ItemUse& use) +{ + Entity_Player& player = use.player; + int slot = use.request.slot; + if (player.variant != PLAYER_VARIANT_PLAYER || player.jarHearts <= 0) return; + + g_pickupIgnoreModifiers++; + int hearts = player.jarHearts; + bool isDrop = true; + if (slot == ACTIVE_SLOT_PRIMARY) + { + if (player.HasCollectible(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE)) + { + hearts = std::min(hearts, 2); + jar_belial_spill(player, hearts); + isDrop = false; + } + if (is_wisp_use(use)) + { + for (int i = hearts / 2; i > 0; i--) player.AddWisp(use.id, player.pos, false, false); + Entity_Familiar* half = hearts % 2 ? player.AddWisp(use.id, player.pos, false, false) : nullptr; + if (half) half->health = half->maxHitPoints / 2; + isDrop = false; + } + } + for (int i = isDrop ? hearts : 0; i > 0; i -= 2) + { + Vector position = room_free_pickup_position_find({.position = player.pos, .step = PICKUP_SPOT_STEP}); + Entity* heart = g_game->Spawn({.position = position, .spawner = &player, .subType = i > 1 ? HEART_FULL : HEART_HALF, + .type = ENTITY_PICKUP, .variant = PICKUP_HEART, .seed = Random()}); + static_cast(heart)->isTouched = true; + } + player.jarHearts -= hearts; + use_animate(use); + g_pickupIgnoreModifiers--; +} +// Whether an enemy is made of poop (dips, squirts, Dingas, Dingles, Brownies, drips, splurts, clogs and Turdlings). +static bool is_poop_enemy(Entity& npc) +{ + constexpr int POOP_ENEMIES[] = {ENTITY_DIP, ENTITY_SQUIRT, ENTITY_DINGA, ENTITY_DINGLE, ENTITY_BROWNIE, + ENTITY_DRIP, ENTITY_SPLURT, ENTITY_CLOG, ENTITY_CLOGGY}; + + return std::ranges::find(POOP_ENEMIES, npc.type) != std::end(POOP_ENEMIES) || + (npc.type == ENTITY_GURGLING && npc.variant == GURGLING_TURDLING); +} + +// The Flush: a poop enemy dies (a poop boss breaks into up to six dips by its health left), any other enemy that may be +// rerolled turns into poop. Book of Virtues adds a wisp for each. The room is flooded for its effect. +static void flush_npc(ItemUse& use, Entity_NPC& npc) +{ + constexpr float FLUSH_DIPS_MAX = 6; + constexpr int DIP_CORNY = 2; + + Entity_Player& player = use.player; + if (is_poop_enemy(npc)) + { + npc.KillUnique(); + if (!npc.IsBoss()) return; + int dips = (int)lerp_clamped(npc.health, 0, npc.maxHitPoints, 0, FLUSH_DIPS_MAX); + bool isCorny = (npc.type == ENTITY_DINGLE && npc.variant == DANGLE) || npc.type == ENTITY_BROWNIE; + for (int i = 0; i < dips; i++) + { + uint32_t seed = Random(); + Vector offset = vector_scale(vector_scale(random_direction(), random_unit()), npc.size); + g_game->Spawn({.position = vector_add(npc.pos, offset), .spawner = &player, .type = ENTITY_DIP, + .variant = isCorny ? DIP_CORNY : 0, .seed = seed}); + } + return; + } + bool isPoopable = npc.type != ENTITY_POOP && npc.type != ENTITY_CHUB && npc.type != ENTITY_MOMS_HAND; + if (!isPoopable || !npc.IsVulnerableEnemy(nullptr) || !npc.CanReroll()) return; + + npc.Remove(); + Entity* poop = g_game->Spawn({.position = npc.pos, .type = ENTITY_POOP, .seed = Random()}); + poop->splatColor = FLUSH_POOP_COLOR; + if (is_wisp_use(use)) player.AddWisp(use.id, player.pos, false, false); + if (npc.minecart) static_cast(npc.minecart.get())->MinecartUpdateChild(poop); +} + +// The Flush: the room flooded for its effect, and every enemy flushed but the friendly ones. +static void flush_use(ItemUse& use) +{ + Entity_Player& player = use.player; + if (player.variant == PLAYER_VARIANT_PLAYER) + { + g_game->room->temporaryEffects.AddCollectibleEffect(use.id, true, 1); + sound_play(SOUND_FLUSH); + EntityList_EL entities = room_entities(); + for (size_t i = 0; i < entities.size(); i++) + { + Entity_NPC* npc = dynamic_cast(entities[i]); + if (npc && npc->HasEntityFlags(FLAG_FRIENDLY)) continue; + if (entities[i]->is_player() && entities[i] != &player && g_game->deathmatchManager.is_active()) + reconstruction_missing("Entity_Player::UseActiveItem 005b39d0 (the Flush in a versus match)"); + if (npc) flush_npc(use, *npc); + } + } + use_animate(use); +} + +// The Satanic Bible: two black hearts, and the floor's boss reward becomes a devil deal. +static void satanic_bible_use(ItemUse& use) +{ + if (use.player.variant == PLAYER_VARIANT_PLAYER) use.player.AddBlackHearts(2); + sound_play(SOUND_SATANIC_BIBLE); + use_animate(use); + g_game->Level::SetStateFlag(LEVEL_STATE_SATANIC_BIBLE_USED, true); +} + +// Head of Krampus: four thick brimstone beams out of the player's head, the upward one drawn behind it. +static void head_of_krampus_use(ItemUse& use) +{ + const Vector KRAMPUS_DIRECTIONS[] = {vector_make(1, 0), vector_make(0, 1), vector_make(-1, 0), vector_make(0, -1)}; + const Vector KRAMPUS_HEAD = vector_make(0, -20); + constexpr float KRAMPUS_REACH = 10; + constexpr int KRAMPUS_TIMEOUT = 31; + constexpr float KRAMPUS_DAMAGE = 10; + constexpr float KRAMPUS_VERSUS_DAMAGE = 3.5f; + constexpr float KRAMPUS_DEPTH_FRONT = 3000; + constexpr float KRAMPUS_DEPTH_BEHIND = -10; + + Entity_Player& player = use.player; + for (int i = 0; i < 4; i++) + { + Vector direction = KRAMPUS_DIRECTIONS[i]; + Vector offset = vector_add(KRAMPUS_HEAD, vector_scale(direction, KRAMPUS_REACH)); + Entity_Laser* laser = Entity_Laser::ShootAngle({.position = vector_add(player.pos, offset), + .posOffset = KRAMPUS_HEAD, + .source = &player, + .angleDegrees = i * QUARTER_TURN_DEGREES, + .timeout = KRAMPUS_TIMEOUT, + .variant = LASER_THICK_RED}); + laser->renderDepthOffset = direction.y >= 0 ? KRAMPUS_DEPTH_FRONT : KRAMPUS_DEPTH_BEHIND; + laser->SetCollisionDamage(g_game->deathmatchManager.is_active() ? KRAMPUS_VERSUS_DAMAGE : KRAMPUS_DAMAGE); + laser->Update(); + } + use.isLuaAnimationAllowed = false; + if (!use.isShowAnimation) return; + player.AnimateCollectible(use.id, "Pickup", "PlayerPickupSparkle"); + use.isLuaAnimationAllowed = true; +} + +// Magic Fingers: a coin for twice the player's damage plus 10 to every enemy, the screen shaken. +static void magic_fingers_use(ItemUse& use) +{ + constexpr float MAGIC_FINGERS_BONUS = 10; + + Entity_Player& player = use.player; + if (player.variant != PLAYER_VARIANT_PLAYER || player.numCoins <= 0) return; + + sound_play(SOUND_ROCK_CRUMBLE); + player.AddCoins(-1); + game_shake_screen(NECRONOMICON_SHAKE); + EntityList_EL& entities = room_entities(); + for (size_t i = 0; i < entities.size(); i++) + { + Entity* entity = entities[i]; + if (!entity->IsVulnerableEnemy(nullptr) || entity == &player) continue; + float bonus = g_game->deathmatchManager.is_active() ? 0 : MAGIC_FINGERS_BONUS; + entity->TakeDamage(player.damage * 2 + bonus, 0, EntityRef(&player), DAMAGE_COUNTDOWN_FRAMES); + } + if (is_wisp_use(use)) player.AddWisp(use.id, player.pos, false, false); + use_animate(use); +} + +// The Converter: a soul heart's worth (its black hearts firing the Necronomicon) traded for a red heart container, +// or a bone heart for the Forgotten's soul. Without two soul hearts it keeps its charge. +static void converter_use(ItemUse& use) +{ + Entity_Player& player = use.player; + if (player.variant != PLAYER_VARIANT_PLAYER) return; + if (player.soulHearts < 2) + { + use.result.isDischarge = false; + return; + } + + int soulHearts = player.soulHearts; + for (int heart = soulHearts; soulHearts - 2 < heart; heart--) + { + if (player.IsBlackHeart(heart)) + { + player.RemoveBlackHeart(heart); + player.UseActiveItem({.item = COLLECTIBLE_NECRONOMICON, .flags = USE_NOANIM}); + } + soulHearts = player.soulHearts; + } + player.soulHearts = soulHearts - 2; + if (player.playerType == PLAYER_THEFORGOTTEN && player.subPlayer) + { + player.subPlayer->AddBoneHearts(1); + if (player.soulHearts < 1) player.SwapForgottenForm(false, false); + } + else player.AddMaxHearts(2, false); + player.AddHearts(2, false, false); + if (is_wisp_use(use)) player.AddWisp(use.id, player.pos, false, false); + use_animate(use); + sound_play(SOUND_CONVERTER); +} +// FUN_0067d9b0 The blood look of a tear variant (Judas' Birthright's tears), or the same one when it has none. +static int tear_variant_blood(int variant) +{ + switch (variant) + { + case TEAR_BLUE: + return TEAR_BLOOD; + case TEAR_CUPID_BLUE: + return TEAR_CUPID_BLOOD; + case TEAR_NAIL: + return TEAR_NAIL_BLOOD; + case TEAR_PUPULA: + return TEAR_PUPULA_BLOOD; + case TEAR_GODS_FLESH: + return TEAR_GODS_FLESH_BLOOD; + case TEAR_GLAUCOMA: + return TEAR_GLAUCOMA_BLOOD; + case TEAR_EYE: + return TEAR_EYE_BLOOD; + default: + return variant; + } +} + +// Judas' Birthright on a burst of tears: blood tears that pierce and fly through walls. +static void tear_belial_apply(Entity_Tear& tear) +{ + int variant = tear_variant_blood(tear.variant); + if (variant != tear.variant) tear.ChangeVariant(variant); + tear.SetTearFlags(tear.tearFlags | TearFlags().set(TEAR_PIERCING) | TearFlags().set(TEAR_SPECTRAL)); +} + +// Isaac's Tears: a ring of eight tears with 5 bonus damage (ten with 10 and Judas' Birthright's blood tears). Book of +// Virtues trades the player's wisps for them instead, the Birthright firing anyway. +static void isaacs_tears_use(ItemUse& use) +{ + constexpr float ISAACS_TEARS_SPEED = 10; + + Entity_Player& player = use.player; + bool isBelial = player.HasCollectible(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE); + if (is_wisp_use(use)) + for (Entity* wisp : entity_query(ENTITY_FAMILIAR, Entity_Familiar::WISP)) + if (static_cast(wisp)->player == &player) wisp->Remove(); + if (!is_wisp_use(use) || isBelial) + { + int count = isBelial ? 10 : 8; + float bonus = isBelial ? 10 : 5; + for (int i = 0; i < count; i++) + { + float angle = (float)i / (float)count * PI_F * 2; + Vector velocity = vector_scale(vector_make(std::cos(angle), std::sin(angle)), ISAACS_TEARS_SPEED); + Entity_Tear* tear = + player.FireTear({player.pos, velocity}, TEAR_FIRE_EXTRA_SHOT, nullptr, isBelial ? BELIAL_DAMAGE_SCALE : 1); + if (isBelial) + { + tear_belial_apply(*tear); + tear->SetScale(tear->fScale + BELIAL_TEAR_SCALE_BONUS); + } + tear->SetCollisionDamage(tear->collisionDamage + bonus); + } + } + use.isLuaAnimationAllowed = false; + if (!use.isShowAnimation) return; + player.AnimateCollectible(use.id, "HideItem", "PlayerPickupSparkle"); + use.isLuaAnimationAllowed = true; +} + +// The Scissors: the head comes off in a burst of blood and fights on for the room (its room effect). +static void scissors_use(ItemUse& use) +{ + if (use.player.variant == PLAYER_VARIANT_PLAYER) blood_burst_spawn(use.player); +} + +// Placebo: the held pill's effect copied without using it up (its charge taken from the pill), remembered for Wild +// Card, and the player's farting babies fart. +static void placebo_use(ItemUse& use) +{ + Entity_Player& player = use.player; + int pill = player.GetPill(0); + if (player.variant != PLAYER_VARIANT_PLAYER) return; + if (pill == 0) return use_animate(use); + + sound_play(SOUND_MOM_BOTTLE); + for (Entity* entity : entity_query(ENTITY_FAMILIAR, -1)) + { + Entity_Familiar* familiar = static_cast(entity); + if (familiar->player == &player) familiar->farting_baby_fart(); + } + int effect = g_game->itemPool.GetPillEffect(pill, &player); + ItemConfig_Pill* config = g_manager->itemConfig.GetPillEffect(effect); + const ActiveUse& request = use.request; + if ((request.flags & USE_OWNED) && request.slot >= 0 && player.activeItems[request.slot].item == use.id && config) + player.activeItems[request.slot].varData = config->mimicCharge; + player.UsePill(effect, pill, USE_MIMIC | USE_NOANNOUNCER); + player.wildCardItemType = WILD_CARD_PILL; + player.wildCardItem = effect; + player.wildCardVarData = pill; + use_animate(use); +} + +// Wooden Nickel: a penny 52 times in 100, a nickel 6 times, a dime twice. +static void wooden_nickel_use(ItemUse& use) +{ + constexpr int WOODEN_NICKEL_ROLL = 100; + + Entity_Player& player = use.player; + if (player.variant != PLAYER_VARIANT_PLAYER) return; + + sound_play(SOUND_WOODEN_NICKEL); + int roll = (int)player.GetCollectibleRNG(use.id).RandomInt(WOODEN_NICKEL_ROLL); + int coin = roll < 52 ? COIN_PENNY : roll < 58 ? COIN_NICKEL : roll < 60 ? COIN_DIME : 0; + if (coin) + { + pickup_spawn(player, PICKUP_COIN, coin, Random()); + sound_play(SOUND_WOODEN_NICKEL_SPAWN); + } + use_animate(use); +} + +// Mega Bean's wisps for Book of Virtues: each of its living wisps lets out its own blast, turned at random. +static void mega_bean_wisps_blast() +{ + for (Entity* entity : entity_query(ENTITY_FAMILIAR, Entity_Familiar::WISP)) + { + Entity_Familiar* wisp = static_cast(entity); + if (wisp->isDead || wisp->subtype != COLLECTIBLE_MEGA_BEAN) continue; + + Entity_Effect* blast = static_cast(g_game->Spawn( + {.position = wisp->pos, .spawner = wisp->player, .type = ENTITY_EFFECT, .variant = EFFECT_CRACKWAVE, .seed = Random()})); + blast->parent = wisp; + blast->rotation = normalize_angle_degrees(random_unit() * FULL_TURN_DEGREES); + } +} + +// Mega Bean: a huge poison fart and push, and the ground cracking out from the player. +static void mega_bean_use(ItemUse& use) +{ + constexpr float MEGA_BEAN_FART_RADIUS = 160; + constexpr float MEGA_BEAN_FART_SCALE = 2; + constexpr float MEGA_BEAN_PUSH_RADIUS = 200; + + Entity_Player& player = use.player; + game_fart({.position = player.pos, .source = &player, .radius = MEGA_BEAN_FART_RADIUS, .scale = MEGA_BEAN_FART_SCALE}); + game_butter_bean_fart( + {.position = player.pos, .source = &player, .radius = MEGA_BEAN_PUSH_RADIUS, .isShowEffect = false}); + Entity* crack = g_game->Spawn({.position = player.pos, .spawner = &player, .type = ENTITY_EFFECT, + .variant = EFFECT_MEGA_BEAN_EXPLOSION, .seed = Random()}); + crack->targetPosition = player.pos; + crack->Update(); + if (is_wisp_use(use)) mega_bean_wisps_blast(); + use.isLuaAnimationAllowed = false; + if (!use.isShowAnimation) return; + player.AnimateCollectible(use.id, "UseItem", "PlayerPickupSparkle"); + use.isLuaAnimationAllowed = true; +} + +// Box of Friends: a copy of every familiar the player has for the room, the unique ones left out, up to 60 familiars +// in the room; with none a Demon Baby. Book of Virtues copies every wisp too, and adds its own, none of them counted as followers. +static void box_of_friends_use(ItemUse& use) +{ + constexpr int FAMILIARS_MAX = 60; + + Entity_Player& player = use.player; + if (player.variant != PLAYER_VARIANT_PLAYER) return; + + ItemConfig& config = g_manager->itemConfig; + int familiars = (int)std::ranges::count(room_entities(), (int)ENTITY_FAMILIAR, &Entity::type); + bool isFound = false; + for (int id = 1; id < (int)config.collectibles.size(); id++) + { + ItemConfig_Item* item = config.collectibles[id].get(); + if (!item || (item->tags & TAG_UNIQUE_FAMILIAR) || player.GetCollectibleNum(id) <= 0) continue; + if (!ItemConfig::IsValidCollectible(id) || !config.GetCollectible(id) || config.GetCollectible(id)->type != ITEM_FAMILIAR) + continue; + if (++familiars > FAMILIARS_MAX) break; + player.temporaryEffects.AddCollectibleEffect(id, true, 1); + isFound = true; + } + if (!isFound && familiars < FAMILIARS_MAX) player.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_DEMON_BABY, true, 1); + use_animate(use); + if (is_wisp_use(use)) + { + for (Entity* wisp : entity_query(ENTITY_FAMILIAR, Entity_Familiar::WISP)) + if (Entity_Familiar* copy = player.AddWisp(wisp->subtype, player.pos, false, false)) + copy->isNotCountedAsFollower = true; + if (Entity_Familiar* own = player.AddWisp(use.id, player.pos, false, false)) own->isNotCountedAsFollower = true; + } + sound_play(SOUND_BOX_OF_FRIENDS); +} + +// Tear Detonator: every tear bursts into six in a ring turned at random (Judas' Birthright's blood tears with 5 bonus +// damage), aimed back where it was. +static void tear_detonator_use(ItemUse& use) +{ + constexpr float DETONATOR_STEP = 60; + constexpr float DETONATOR_SPEED = 10; + constexpr float DETONATOR_BELIAL_BONUS = 5; + + Entity_Player& player = use.player; + bool isBelial = player.HasCollectible(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE); + for (Entity* tear : entity_query(ENTITY_TEAR, -1)) + { + if (tear->isDead) continue; + sound_play(SOUND_TEAR_DETONATOR); + tear->Remove(); + float turn = random_unit() * FULL_TURN_DEGREES - FULL_TURN_DEGREES / 2; + for (float angle = 0; angle < FULL_TURN_DEGREES; angle += DETONATOR_STEP) + { + Vector velocity = vector_scale(vector_from_angle(angle + turn), player.shotSpeed * DETONATOR_SPEED); + Entity_Tear* shard = + player.FireTear({tear->pos, velocity}, TEAR_FIRE_EXTRA_SHOT, nullptr, isBelial ? BELIAL_DAMAGE_SCALE : 1); + shard->targetPosition = tear->pos; + if (!isBelial) continue; + tear_belial_apply(*shard); + shard->SetCollisionDamage(shard->collisionDamage + DETONATOR_BELIAL_BONUS); + shard->SetScale(shard->fScale + BELIAL_TEAR_SCALE_BONUS); + } + } + use_animate(use); +} +// Undefined: a teleport to a random treasure, secret or super secret room of the floor, or the I AM ERROR room (and, +// once in 100, the black market) when there is a next floor. +static void undefined_use(ItemUse& use) +{ + constexpr int UNDEFINED_ROOM_TYPES[] = {ROOM_TREASURE, ROOM_SECRET, ROOM_SUPERSECRET}; + constexpr int UNDEFINED_BLACK_MARKET_ODDS = 100; + + Entity_Player& player = use.player; + if (player.variant != PLAYER_VARIANT_PLAYER) return; + + Game& game = *g_game; + RNG& rng = player.GetCollectibleRNG(use.id); + std::set seen; + std::vector rooms; + for (int i = 0; i < game.nbRooms; i++) + { + RoomDescriptor& room = game.roomList[i]; + if (!room.data || room.dimension != game.currentDimensionIdx) continue; + if (std::ranges::find(UNDEFINED_ROOM_TYPES, room.data->type) == std::end(UNDEFINED_ROOM_TYPES)) continue; + if (seen.insert(room.gridIndex).second) rooms.push_back(room.gridIndex); + } + if (game.IsNextStageAvailable()) + { + if (game.GetRoomByIdx(ROOM_ERROR_IDX)->data) rooms.push_back(ROOM_ERROR_IDX); + if (rng.RandomInt(UNDEFINED_BLACK_MARKET_ODDS) == 0 && game.GetRoomByIdx(ROOM_BLACK_MARKET_IDX)->data) + rooms.push_back(ROOM_BLACK_MARKET_IDX); + } + if (rooms.empty()) return; + + int roomIndex = rooms[rng.RandomInt((uint32_t)rooms.size())]; + game.StartRoomTransition({.player = &player, .animation = TRANSITION_TELEPORT, .dimension = roomIndex < 0 ? 0 : -1, + .roomIndex = roomIndex}); + sound_play(SOUND_TELEPORT_UNDEFINED); +} + +// Ventricle Razor: a portal on a free cell under the player, the older of the pair moved here (each pair a portal +// back and forth), with a burst of blood in its colour. +static void ventricle_razor_use(ItemUse& use) +{ + constexpr ColorMod PORTAL_ORANGE_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {84 / 255.0f, 49 / 255.0f, 14 / 255.0f}}; + constexpr ColorMod PORTAL_BLUE_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {14 / 255.0f, 56 / 255.0f, 86 / 255.0f}}; + + Entity_Player& player = use.player; + if (player.variant != PLAYER_VARIANT_PLAYER) return; + + int portal = player.ventricleRazorPortal; + sound_play(SOUND_VENTRICLE_RAZOR); + for (Entity* old : entity_query(ENTITY_EFFECT, EFFECT_WOMB_TELEPORT)) + if (old->subtype == portal) old->isDead = true; + Vector position = room_free_pickup_position_find({.position = player.pos}); + g_game->ventricleRazorPortals[portal] = {.gridIndex = g_game->room->GetGridIndex(position), + .roomIndex = g_game->currentRoomIdx, + .isMarked = is_wisp_use(use)}; + g_game->Spawn({.position = position, .spawner = &player, .subType = portal, .type = ENTITY_EFFECT, + .variant = EFFECT_WOMB_TELEPORT, .seed = Random()}) + ->Update(); + + Entity* burst = effect_spawn(EFFECT_BLOOD_EXPLOSION, position, {}, BLOOD_EXPLOSION_LARGE); + burst->subtype = 0; + burst->SetColor(portal ? PORTAL_ORANGE_COLOR : PORTAL_BLUE_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + burst->sprite.rotation = random_below(4) * QUARTER_TURN_DEGREES; + burst->Update(); + sound_play(SOUND_MEAT_JUMPS); + player.ventricleRazorPortal = (portal + 1) % VENTRICLE_RAZOR_PORTAL_COUNT; + use_animate(use); +} +// Diplopia: a copy of every pedestal item and pickup Jera could copy (a trinket redrawn), blind and pooled like it, a +// choice between options mirrored by a new choice. Book of Virtues copies every wisp. It goes once owned. +static void diplopia_use(ItemUse& use) +{ + Entity_Player& player = use.player; + if (player.variant != PLAYER_VARIANT_PLAYER) return; + if (use.request.flags & (USE_OWNED | USE_VOID)) use.result.isRemove = true; + + std::map optionsCopies; + for (Entity* entity : entity_query(ENTITY_PICKUP, -1)) + { + Entity_Pickup& pickup = *static_cast(entity); + bool isPedestal = pickup.variant == PICKUP_COLLECTIBLE; + if (isPedestal ? pickup.subtype == COLLECTIBLE_DIPLOPIA || pickup.subtype == 0 : !pickup.CanJeraDuplicate()) continue; + + int subType = pickup.variant == PICKUP_TRINKET ? 0 : pickup.subtype; + Vector position = room_free_pickup_position_find({.position = pickup.pos, .step = PICKUP_SPOT_STEP}); + Entity_Pickup* copy = static_cast(g_game->Spawn({.position = position, .spawner = &player, + .subType = subType, .type = ENTITY_PICKUP, + .variant = pickup.variant, .seed = pickup.initSeed})); + copy->SetForceBlind(pickup.isForceBlind); + copy->SetAlternatePedestal(pickup.GetAlternatePedestal()); + copy->itemPoolType = pickup.itemPoolType; + sound_play(SOUND_DIPLOPIA); + if (pickup.optionsPickupIndex <= 0) continue; + + auto found = optionsCopies.find(pickup.optionsPickupIndex); + if (found != optionsCopies.end()) copy->optionsPickupIndex = found->second; + else optionsCopies.emplace(pickup.optionsPickupIndex, copy->AssignOptionsIndex()); + } + use_animate(use); + if (is_wisp_use(use)) + for (Entity* wisp : entity_query(ENTITY_FAMILIAR, Entity_Familiar::WISP)) + player.AddWisp(wisp->subtype, player.pos, false, false); +} +// Runs the own effect of a Rebirth or early Afterbirth active (below 400) the main dispatch does not case. The ones not +// written yet stop the game. +void rebirth_item_effect_run(ItemUse& use) +{ + switch (use.id) + { + case COLLECTIBLE_NECRONOMICON: + return necronomicon_use(use); + case COLLECTIBLE_HOURGLASS: + return hourglass_use(use); + case COLLECTIBLE_MONSTROS_TOOTH: + return monstros_tooth_use(use); + case COLLECTIBLE_BOOK_OF_SIN: + return book_of_sin_use(use); + case COLLECTIBLE_PINKING_SHEARS: + return pinking_shears_use(use); + case COLLECTIBLE_BEAN: + return bean_use(use); + case COLLECTIBLE_MONSTER_MANUAL: + return monster_manual_use(use); + case COLLECTIBLE_DEAD_SEA_SCROLLS: + return dead_sea_scrolls_use(use); + case COLLECTIBLE_FORGET_ME_NOW: + return forget_me_now_use(use); + case COLLECTIBLE_IV_BAG: + return iv_bag_use(use); + case COLLECTIBLE_BEST_FRIEND: + return best_friend_use(use); + case COLLECTIBLE_CRYSTAL_BALL: + return crystal_ball_use(use); + case COLLECTIBLE_D20: + return d20_use(use); + case COLLECTIBLE_DADS_KEY: + return dads_key_use(use); + case COLLECTIBLE_PORTABLE_SLOT: + return portable_slot_use(use); + case COLLECTIBLE_CLEAR_RUNE: + return clear_rune_use(use); + case COLLECTIBLE_HOW_TO_JUMP: + return how_to_jump_use(use); + case COLLECTIBLE_D100: + return d100_use(use); + case COLLECTIBLE_D4: + return d4_use(use); + case COLLECTIBLE_D10: + return d10_use(use); + case COLLECTIBLE_BLANK_CARD: + return blank_card_use(use); + case COLLECTIBLE_BOOK_OF_SECRETS: + return book_of_secrets_use(use); + case COLLECTIBLE_BOX_OF_SPIDERS: + return box_of_spiders_use(use); + case COLLECTIBLE_THE_JAR: + return jar_use(use); + case COLLECTIBLE_FLUSH: + return flush_use(use); + case COLLECTIBLE_SATANIC_BIBLE: + return satanic_bible_use(use); + case COLLECTIBLE_HEAD_OF_KRAMPUS: + return head_of_krampus_use(use); + case COLLECTIBLE_BUTTER_BEAN: + return game_butter_bean_fart({.position = use.player.pos, .source = &use.player, .radius = BEAN_PUSH_RADIUS, + .isShowEffect = true, .isSuperKnockback = true}); + case COLLECTIBLE_MAGIC_FINGERS: + return magic_fingers_use(use); + case COLLECTIBLE_CONVERTER: + return converter_use(use); + case COLLECTIBLE_ISAACS_TEARS: + return isaacs_tears_use(use); + case COLLECTIBLE_SCISSORS: + return scissors_use(use); + case COLLECTIBLE_BREATH_OF_LIFE: + use.isAddEffect = false; + return; + case COLLECTIBLE_BOOMERANG: + return boomerang_use(use); + case COLLECTIBLE_PLACEBO: + return placebo_use(use); + case COLLECTIBLE_WOODEN_NICKEL: + return wooden_nickel_use(use); + case COLLECTIBLE_MEGA_BEAN: + return mega_bean_use(use); + case COLLECTIBLE_GLASS_CANNON: + return lift_sound_use(use, 0); + case COLLECTIBLE_BOX_OF_FRIENDS: + return box_of_friends_use(use); + case COLLECTIBLE_FRIEND_BALL: + return lift_sound_use(use, SOUND_FRIENDLYBALL_RAISE); + case COLLECTIBLE_TEAR_DETONATOR: + return tear_detonator_use(use); + case COLLECTIBLE_DIPLOPIA: + return diplopia_use(use); + case COLLECTIBLE_UNDEFINED: + return undefined_use(use); + case COLLECTIBLE_VENTRICLE_RAZOR: + return ventricle_razor_use(use); + default: + return active_missing_report(use); + } +} diff --git a/src/entity_player_actives_repentance.cpp b/src/entity_player_actives_repentance.cpp new file mode 100644 index 0000000..6353daa --- /dev/null +++ b/src/entity_player_actives_repentance.cpp @@ -0,0 +1,1577 @@ +#include "entity_player.h" +#include "active_items.h" +#include "boss_ai.h" +#include "entity_effect.h" +#include "entity_config.h" +#include "entity_familiar.h" +#include "entity_npc.h" +#include "entity_pickup.h" +#include "entity_tear.h" +#include "game.h" +#include "hud.h" +#include "item_overlay.h" +#include "loot_list.h" +#include "npc_basement.h" +#include "pocket_items.h" +#include "procedural_item_manager.h" +#include "log.h" +#include "manager.h" +#include "npc_ai.h" +#include "room.h" +#include "room_config.h" +#include "room_grid.h" +#include +#include + +constexpr int ALABASTER_BOX_DELAY = 30; +constexpr int ALABASTER_EXTRA_WISPS = 4; +constexpr int ALABASTER_ETERNAL_ODDS = 10; +constexpr int ALABASTER_WISPS = 4; +constexpr int ALABASTER_DEVIL_DARK_FRAMES = 75; +constexpr int ALABASTER_ANGEL_SOUND_DELAY = 20; +constexpr int CHARM_FART_FRAMES = 150; +constexpr int CHARM_FART_CONFUSION_FRAMES = 90; +constexpr int D8_BALANCE_PASSES = 5; +constexpr uint32_t D8_CACHE_FLAGS = CACHE_DAMAGE | CACHE_FIREDELAY | CACHE_RANGE | CACHE_SPEED; +constexpr int DULL_RAZOR_COUNTDOWN = 30; +constexpr int EDENS_SOUL_ITEMS = 2; +constexpr int FREE_LEMONADE_FRAMES = 600; +constexpr int MEGA_BLAST_FRAMES = 450; +constexpr int MEGA_BLAST_VERSUS_FRAMES = 150; +constexpr int PAUSE_FRAMES = 900; +constexpr int PAUSE_VERSUS_FRAMES = 240; +constexpr int PLUM_FLUTE_DELAY = 15; +constexpr int SUPLEX_AIM_FRAMES = 16; +constexpr int YUCK_HEART_ROTTEN_HEARTS = 2; +constexpr int JAR_OF_FLIES_PER_WISP = 5; +constexpr int JAR_OF_FLIES_FULL_WISP = 0x10009; +constexpr int JAR_OF_FLIES_PART_WISP = 0x10004; +constexpr int MR_ME_TARGET_FRAMES = 75; +constexpr int WAIT_WHAT_POISON_FRAMES = 60; +constexpr int WAIT_WHAT_RING_FRAMES = 10; +constexpr double FORTUNE_COOKIE_TRINKET_CHANCE = 0.03; +constexpr double FORTUNE_COOKIE_CARD_CHANCE = 0.167; +constexpr double FORTUNE_COOKIE_HEART_CHANCE = 0.333; +constexpr float WAIT_WHAT_RADIUS = 120; +constexpr float WAIT_WHAT_RING_RADIUS = 90; +constexpr float WAIT_WHAT_VERSUS_RADIUS = 80; +constexpr int COMPOST_WISP = 480; +constexpr int MAGIC_SKIN_HEART_COST = 4; +constexpr ColorMod MAGIC_SKIN_POOF_COLOR = {{1, 1, 1, 1}, {2, 0.4f, 0.4f, 1}, {0, 0, 0}}; +// The dice D Infinity turns into, by face (00b1f450), and the giant book the dice with one show. +constexpr std::array D_INFINITY_DICE = {COLLECTIBLE_D1, COLLECTIBLE_D4, COLLECTIBLE_D6, COLLECTIBLE_ETERNAL_D6, + COLLECTIBLE_D7, COLLECTIBLE_D8, COLLECTIBLE_D10, COLLECTIBLE_D12, + COLLECTIBLE_D20, COLLECTIBLE_D100}; +constexpr std::array, 4> D_INFINITY_OVERLAYS = { + {{COLLECTIBLE_D100, 28}, {COLLECTIBLE_D4, 17}, {COLLECTIBLE_D12, 37}, {COLLECTIBLE_D8, 36}}}; +constexpr int DATAMINER_STATS = 6; +constexpr uint32_t DATAMINER_CACHE_FLAGS = 0x41f; +constexpr int PLAN_C_BOSS_DELIRIUM = 70; +constexpr int PLAN_C_BOSS_MOTHER = 88; +constexpr int PLAN_C_DELIRIUM_FRAMES = 300; +constexpr int PLAN_C_MOTHER_FRAMES = 345; +constexpr int PLAN_C_FRAMES = 90; +constexpr int PLAN_C_BLOOD_FRAMES = 30; +constexpr int PLAN_C_BLOOD_DROPS = 5; +constexpr int PLAN_C_SHAKE = 30; +constexpr int PLAN_C_WISPS = 33; +constexpr int PLAN_C_DAMAGE_COUNTDOWN = 30; +constexpr float PLAN_C_DAMAGE = 9999999; +constexpr float FRIEND_FINDER_SPREAD = 10; +// The enemies Friend Finder may bring, by type and variant. +constexpr std::array, 21> FRIEND_FINDER_FRIENDS = { + {{ENTITY_BONY, 0}, {ENTITY_BLACK_BONY, 0}, {ENTITY_BONY, 1}, {ENTITY_DOPLE, 0}, {ENTITY_DOPLE, 1}, + {ENTITY_CLOTTY, 0}, {ENTITY_CLOTTY, 1}, {ENTITY_CLOTTY, 2}, {ENTITY_CLOTTY, 3}, {ENTITY_BLASTER, 0}, + {ENTITY_DANNY, 0}, {ENTITY_DANNY, 1}, {ENTITY_HIVE, 0}, {ENTITY_HIVE, 1}, {ENTITY_HIVE, 2}, + {ENTITY_NEST, 0}, {ENTITY_MAW, 0}, {ENTITY_VIS, 0}, {ENTITY_VIS, 1}, {ENTITY_VIS, 2}, + {ENTITY_GURGLE, 0}}}; +constexpr int LARYNX_MAX_CHARGE = 12; +constexpr int LARYNX_MED_CHARGE = 5; +constexpr int LARYNX_HIGH_CHARGE = 9; +constexpr int LARYNX_EFFECT_EXTRA_FRAMES = 8; +constexpr int LARYNX_SHAKE_BASE = 2; +constexpr int LARYNX_SHAKE_STEP = 3; +constexpr float LARYNX_HIGH_VOLUME_STEP = 0.2f; +constexpr float LARYNX_LOUD_VOLUME = 1.1f; +constexpr float LARYNX_RED_SPAN = 9; +constexpr float LARYNX_RED_RATE = 0.015f; +constexpr float LARYNX_RESTORE_RATE = 0.02f; +constexpr float LARYNX_MIN_RADIUS = 10; +constexpr float LARYNX_RADIUS_BASE = 30; +constexpr float LARYNX_RADIUS_STEP = 50; +constexpr float LARYNX_RADIUS_SQUARED = 0.8f; +constexpr float LARYNX_DAMAGE_BASE = 20; +constexpr float LARYNX_DAMAGE_STEP = 28; +constexpr float LARYNX_VERSUS_DAMAGE_BASE = 4; +constexpr float LARYNX_VERSUS_DAMAGE_STEP = 3.8f; +constexpr float LARYNX_WISP_HEALTH_SCALE = 0.5f; +constexpr ColorModState LARYNX_RED = {2, 0, 0, 1, 0, 1}; +constexpr int ENTITY_NIGHTWATCH = 842; +constexpr int VADE_RETRO_RNG_SHIFT = 13; +constexpr int VADE_RETRO_SHAKE_BASE = 8; +constexpr int VADE_RETRO_SHAKE_MAX = 20; +constexpr int VADE_RETRO_FADE_FRAMES = 10; +constexpr float VADE_RETRO_PITCH_BASE = 0.9f; +constexpr float VADE_RETRO_PITCH_SPREAD = 0.2f; +constexpr ColorMod VADE_RETRO_PURGATORY_COLOR = {{0.2f, 0.2f, 0.2f, 1}, {0, 0, 0, 0}, {0.8f, 0.15f, 0.03f}}; +constexpr int MYSTERY_GIFT_MIN_ROLL = 2; +constexpr int MYSTERY_GIFT_LUCK_ROLL = 12; +constexpr float MYSTERY_GIFT_FART_RADIUS = 85; +constexpr float MYSTERY_GIFT_PUSH_RADIUS = 120; +constexpr int JAR_OF_WISPS_MAX_USES = 12; +constexpr float JAR_OF_WISPS_VIRTUES_CHANCE = 0.67f; +constexpr ColorMod MYSTERY_GIFT_COAL_COLOR = {{0.05f, 0.05f, 0.05f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr int GLOWING_HOUR_GLASS_REWINDS = 3; +constexpr int DOOR_SLOT_LAST = 7; +constexpr int D7_DUNGEON_GIDEON = 2; +constexpr int D7_DUNGEON_ROTGUT = 3; +constexpr int GENESIS_ROOM_SUBTYPE = 99; +constexpr int GENESIS_WISPS = 3; +constexpr RNG GENESIS_RNG_SHIFTS = {0, 3, 3, 26}; +constexpr int R_KEY_RAISE_DELAY = 3; +constexpr int PEELER_BLOOD_SUBTYPE = 3; +constexpr int PEELER_GORE_MIN = 2; +constexpr int PEELER_GORE_RANGE = 3; +constexpr int PEELER_DROPS_MIN = 6; +constexpr int PEELER_DROPS_RANGE = 6; +constexpr int PEELER_DROP_SUBTYPE = 99; +constexpr int PEELER_VERSUS_ANEMIC_FRAMES = 300; +constexpr uint32_t PEELER_CACHE_FLAGS = CACHE_DAMAGE | CACHE_FAMILIARS; +constexpr float PEELER_BURST_SPEED = 2; +constexpr float PEELER_BURST_SPREAD = 20; +constexpr int KEEPERS_BOX_RNG_SHIFT = 35; +// The wares Keeper's Box may sell, by outcome: the pickup and its subtype (0 for the pools' draws). +constexpr std::array, 9> KEEPERS_BOX_WARES = { + {{PICKUP_HEART, HEART_FULL}, {PICKUP_BOMB, 1}, {PICKUP_PILL, 0}, {PICKUP_KEY, KEY_NORMAL}, {PICKUP_HEART, HEART_SOUL}, + {PICKUP_LIL_BATTERY, 1}, {PICKUP_TAROTCARD, 0}, {PICKUP_GRAB_BAG, 0}, {PICKUP_COLLECTIBLE, 0}}}; +constexpr float MEAT_CLEAVER_PITCH = 0.9f; +constexpr int MEGA_MUSH_VERSUS_FRAMES = 300; +constexpr ColorMod MR_ME_TARGET_COLOR = {{0, 0.5882353f, 1, 1}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr uint64_t DULL_RAZOR_DAMAGE_FLAGS = DAMAGE_RED_HEARTS | DAMAGE_FAKE; +constexpr float CHARM_FART_RADIUS = 120; +constexpr float RED_KEY_REACH = 120; +constexpr float D8_MIN_MULTIPLIER = 0.5f; +constexpr float D8_STAT_AVERAGE = 0.5f; +constexpr float DULL_RAZOR_DAMAGE = 2; +constexpr float GIGANTE_FART_SCALE = 2; +constexpr float MEGA_BLAST_CAR_BATTERY_SCALE = 1.5f; +constexpr float MINE_CRAFTER_SPREAD = 0.5f; +constexpr float MINE_CRAFTER_POOF_DROP = 5; +constexpr float SUPLEX_DASH_SPEED = 10; +constexpr float SUPLEX_PITCH_BASE = 0.9f; +constexpr float SUPLEX_PITCH_SPREAD = 0.2f; +constexpr ColorMod CHARM_FART_COLOR = {{1, 1, 1, 1}, {1, 0, 1, 1}, {0, 0, 0}}; +constexpr ColorMod DARK_ARTS_POOF_COLOR = {{0.05f, 0.05f, 0.05f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; + +// The player a timer effect was set on, when it still is one. +static Entity_Player* timer_player(Entity_Effect* timer) +{ + Entity* parent = timer->parent.get(); + return parent && parent->type == ENTITY_PLAYER ? static_cast(parent) : nullptr; +} + +// Whether the use was owned or voided, which takes a single use item away. +static void single_use_remove(ItemUse& use) +{ + if (use.request.flags & (USE_OWNED | USE_VOID)) use.result.isRemove = true; +} + +// Plays a sound at a pitch, unless the seeds swap it for a fart. +static void sound_play_pitched(int sound, float pitch) +{ + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound, {.pitch = pitch}); +} + +// Lifts an item over the head to hold it in its item state until it is thrown. +static void item_state_lift(ItemUse& use, int itemState) +{ + use.player.SetItemState(itemState); + use.player.AnimateCollectible(use.id, "LiftItem", "PlayerPickupSparkle"); +} + +// 00703f90 A fart that charms every vulnerable enemy around a spot for five seconds, never the source or a player it +// came from. Gigante Bean doubles its size, and its golden or doubled forms push and confuse too. Fart candles fire. +void game_charm_fart(const Vector& position, float radius, Entity* source) +{ + Entity_Player* player = source ? static_cast(source->GetPlayerAncestor()) : nullptr; + float scale = 1; + int multiplier = 0; + + if (player && player->HasTrinket(TRINKET_GIGANTE_BEAN)) + { + radius += radius; + scale = GIGANTE_FART_SCALE; + multiplier = player->GetTrinketMultiplier(TRINKET_GIGANTE_BEAN); + } + for (Entity* entity : entity_query_radius(position, radius, QUERY_ALL)) + { + if (entity == source || entity->entityGridCollisionClass == GRIDCOLL_BULLET || entity->mass == 0) continue; + if (!entity->IsVulnerableEnemy(nullptr)) continue; + if (entity->type == ENTITY_PLAYER && source && source->IsDescendantOf(entity)) continue; + + entity->AddCharmed(EntityRef(source), CHARM_FART_FRAMES, false, false); + if (multiplier > 1) reconstruction_missing("Game::CharmFart 00703f90: Gigante Bean's knockback (Entity::AddKnockback)"); + if (multiplier > 2) entity->AddConfusion(EntityRef(source), CHARM_FART_CONFUSION_FRAMES, false); + } + + Entity* cloud = g_game->Spawn({.position = position, .type = ENTITY_EFFECT, .variant = EFFECT_FART, .seed = Random()}); + cloud->SetColor(CHARM_FART_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + cloud->sprite.scale = vector_make(scale, scale); + if (scale > GIGANTE_FART_SCALE - 0.2f) + { + SFXManager& sfx = g_manager->sfxManager; + sfx.Stop(SOUND_FART); + sfx.Play(SOUND_FART, {.frameDelay = 0}); + sfx.Play(SOUND_FART, {.volume = 1.2f, .frameDelay = 20, .pitch = 0.5f}); + game_shake_screen(3); + } + if (source && source->type == ENTITY_PLAYER) static_cast(source)->ShootCandle({}); +} + +// D8: four random stat multipliers, pulled toward an even spread and never below a half, then reread. Book of Virtues' +// D8 wisps reroll their own seeds. +static void d8_use(ItemUse& use) +{ + Entity_Player& player = use.player; + RNG& rng = player.GetCollectibleRNG(COLLECTIBLE_D8); + std::array stats = {&player.d8DamageModifier, &player.d8SpeedModifier, &player.d8RangeModifier, + &player.d8FireDelayModifier}; + + for (float* stat : stats) *stat = rng.RandomFloat(); + for (int pass = 0; pass < D8_BALANCE_PASSES; pass++) + { + float shift = (D8_STAT_AVERAGE * stats.size() - (*stats[0] + *stats[1] + *stats[2] + *stats[3])) / stats.size(); + for (float* stat : stats) *stat = std::clamp(*stat + shift, 0.0f, 1.0f); + } + for (float* stat : stats) *stat += std::max(*stat, D8_MIN_MULTIPLIER); + player.cacheFlags |= D8_CACHE_FLAGS; + player.EvaluateItems(); + + if (player.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES) && use.isWispAllowed) + for (Entity* wisp : entity_query(ENTITY_FAMILIAR, Entity_Familiar::WISP)) + { + if ((int)wisp->subtype != COLLECTIBLE_D8) continue; + uint32_t seed = wisp->dropRNG.Next(); + wisp->dropRNG = DROP_RNG_SAVED; + wisp->dropRNG._seed = seed; + } + if (!use.isShowAnimation) return; + sound_play_local(player, SOUND_D6_ROLL); + use_animate(use); +} + +// Teleport 2.0: off to a room of the floor not visited yet, the devil or angel room made for it when there is none. +static void teleport_2_use(ItemUse& use) +{ + if (use.player.variant != PLAYER_VARIANT_PLAYER) return; + g_game->leaveDoor = -1; + int roomIndex = g_game->GetNonCompleteRoomIndex(); + if (roomIndex == -1) g_game->InitializeDevilAngelRoom(false, false); + g_game->StartRoomTransition({.player = &use.player, .animation = TRANSITION_TELEPORT, .roomIndex = roomIndex}); +} + +// Mine Crafter: a TNT barrel by the player with a poof, its sound and the item raised. +static void mine_crafter_use(ItemUse& use) +{ + sound_play(SOUND_MINECRAFTER); + uint32_t seed = Random(); + Vector position = vector_add(use.player.pos, vector_scale(random_direction(), MINE_CRAFTER_SPREAD)); + Entity* barrel = g_game->Spawn({.position = position, .spawner = &use.player, .subType = 1, .type = ENTITY_MOVABLE_TNT, + .variant = 1, .seed = seed}); + g_game->Spawn({.position = vector_add(barrel->pos, vector_make(0, MINE_CRAFTER_POOF_DROP)), .type = ENTITY_EFFECT, + .variant = EFFECT_POOF01, .seed = Random()}) + ->Update(); + use_animate(use); +} + +// Mom's Box: a random trinket near the player, with its sound and the item raised. +static void moms_box_use(ItemUse& use) +{ + if (use.player.variant != PLAYER_VARIANT_PLAYER) return; + uint32_t seed = use.player.GetCollectibleRNG(COLLECTIBLE_MOMS_BOX).Next(); + Vector position = room_free_pickup_position_find({.position = use.player.pos, .step = 40}); + g_game->Spawn({.position = position, .spawner = &use.player, .type = ENTITY_PICKUP, .variant = PICKUP_TRINKET, .seed = seed}); + if (use.isShowAnimation) sound_play(SOUND_MOMS_BOX); + use_animate(use); +} + +// Mega Blast: the huge laser for fifteen seconds (five in a versus match), half again with Car Battery. +static void mega_blast_use(ItemUse& use) +{ + Entity_Player& player = use.player; + + player.megaBlastDuration = g_game->deathmatchManager.is_active() ? MEGA_BLAST_VERSUS_FRAMES : MEGA_BLAST_FRAMES; + if (player.HasCollectible(COLLECTIBLE_CAR_BATTERY)) + player.megaBlastDuration = (int)(player.megaBlastDuration * (double)MEGA_BLAST_CAR_BATTERY_SCALE); + player.AddCostume(g_manager->itemConfig.GetNullItem(NULLITEM_MEGABLAST), false); +} + +// Pause: the room freezes for fifteen seconds (in a versus match it lifts on its own after four). +static void pause_use(ItemUse& use) +{ + if (use.player.variant == PLAYER_VARIANT_PLAYER) + { + sound_play(SOUND_PAUSE_FREEZE); + g_game->room->SetPauseTimer(PAUSE_FRAMES); + g_game->room->temporaryEffects.AddCollectibleEffect(COLLECTIBLE_PAUSE, true, 1); + use.player.versusPauseTimer = PAUSE_VERSUS_FRAMES; + } + use_animate(use); +} + +// Mama Mega!: the room's explosion, which a golden bomb pays for once (the item stays). +static void mama_mega_use(ItemUse& use) +{ + Entity_Player& player = use.player; + + if (player.variant != PLAYER_VARIANT_PLAYER) return use_animate(use); + if (!player.hasGoldenBomb) single_use_remove(use); + else + { + player.RemoveGoldenBomb(); + use.result.isRemove = false; + } + g_game->StartMamaMega(player.pos, g_game->deathmatchManager.is_active() ? &player : nullptr); + use_animate(use); +} + +// Dull Razor: a fake hit, with its sound and the item raised. +static void dull_razor_use(ItemUse& use) +{ + use.player.TakeDamage(DULL_RAZOR_DAMAGE, DULL_RAZOR_DAMAGE_FLAGS, EntityRef(&use.player), DULL_RAZOR_COUNTDOWN); + sound_play(SOUND_DULL_RAZOR); + use_animate(use); +} + +// Eden's Soul: two pedestal items drawn by the room, the item gone. +static void edens_soul_use(ItemUse& use) +{ + if (use.player.variant == PLAYER_VARIANT_PLAYER) + { + single_use_remove(use); + for (int i = 0; i < EDENS_SOUL_ITEMS; i++) + { + uint32_t seed = use.player.GetCollectibleRNG(COLLECTIBLE_EDENS_SOUL).Next(); + Vector position = room_free_pickup_position_find({.position = use.player.pos, .step = 40}); + g_game->Spawn({.position = position, .spawner = &use.player, .type = ENTITY_PICKUP, .variant = PICKUP_COLLECTIBLE, + .seed = seed}); + } + } + use_animate(use); +} + +// Golden Razor: five coins paid, with the register's sound. The hurt and damage come from the room effect. +static void golden_razor_use(ItemUse& use) +{ + if (use.player.variant == PLAYER_VARIANT_PLAYER) + { + use.player.AddCoins(-GOLDEN_RAZOR_PRICE); + sound_play(SOUND_CASH_REGISTER); + } + use_animate(use); +} + +// Sulfur: Brimstone for the room, worn. +static void sulfur_use(ItemUse& use) +{ + if (use.player.variant == PLAYER_VARIANT_PLAYER) sound_play(SOUND_MONSTER_YELL_A); + use.player.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_BRIMSTONE, false, 1); + use.player.AddCostume(g_manager->itemConfig.GetCollectible(COLLECTIBLE_BRIMSTONE), false); + use_animate(use); +} + +// Free Lemonade: a big pool of lemon creep that lasts ten seconds. +static void free_lemonade_use(ItemUse& use) +{ + sound_play(SOUND_GASCAN_POUR); + auto* creep = static_cast(g_game->Spawn({.position = use.player.pos, .spawner = &use.player, + .type = ENTITY_EFFECT, .variant = EFFECT_PLAYER_CREEP_LEMON_PARTY, + .seed = Random()})); + creep->SetTimeout(FREE_LEMONADE_FRAMES); + creep->Update(); + use_animate(use); +} + +// 005b2360 Red Key: the red room behind the nearest door outline within reach (the first slot's), when there is one. +void Entity_Player::UseRedKey() +{ + std::array& outlines = g_game->room->redDoorOutlines; + + for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++) + { + Entity* outline = outlines[slot].get(); + if (outline && vector_length_squared(vector_sub(pos, outline->pos)) < RED_KEY_REACH * RED_KEY_REACH) + return (void)g_game->MakeRedRoomDoor(g_game->currentRoomIdx, slot); + } +} + +// Red Key: a red room opened, the item raised. In Red Redemption a slot's use carries Jacob's curse. +static void red_key_use(ItemUse& use) +{ + use.player.UseRedKey(); + use_animate(use); + if (use.request.slot >= 0 && g_game->challenge == CHALLENGE_RED_REDEMPTION) + use.player.temporaryEffects.AddNullEffect(NULLITEM_JACOBS_CURSE, true, 1); +} + +// Alabaster Box's reward a moment after its use: soul (or black) hearts and angel (or devil) items, one round more when +// no devil deal was taken (or when one was), with Book of Virtues' wisps, a sound and the player happy. +static void alabaster_box_reward(Entity_Effect* timer) +{ + Entity_Player* player = timer_player(timer); + if (!player) return; + RNG& rng = player->GetCollectibleRNG(COLLECTIBLE_ALABASTER_BOX); + bool isDevil = timer->subtype == 1; + Game& game = *g_game; + int rounds = (isDevil ? game.devilRoomDeals > 0 : game.devilRoomDeals < 1) + 1; + + Vector position = room_free_pickup_position_find({.position = player->pos, .step = 40}); + g_game->Spawn({.position = position, .subType = isDevil ? (int)HEART_BLACK : (int)HEART_SOUL, .type = ENTITY_PICKUP, + .variant = PICKUP_HEART, .seed = rng.Next()}); + for (int round = 0; round < rounds; round++) + { + Vector itemPosition = room_free_pickup_position_find({.position = player->pos, .step = 40}); + int item = game.itemPool.GetCollectible(isDevil ? POOL_DEVIL : POOL_ANGEL, rng.Next(), 0, 0, 0); + g_game->Spawn({.position = itemPosition, .subType = item, .type = ENTITY_PICKUP, .variant = PICKUP_COLLECTIBLE, + .seed = rng.Next()}); + g_game->Spawn({.position = itemPosition, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); + + Vector heartPosition = room_free_pickup_position_find({.position = player->pos, .step = 40}); + uint32_t seed = rng.Next(); + int heart = HEART_BLACK; + if (!isDevil) heart = rng.Next() % ALABASTER_ETERNAL_ODDS != 0 ? (int)HEART_SOUL : (int)HEART_ETERNAL; + g_game->Spawn({.position = heartPosition, .subType = heart, .type = ENTITY_PICKUP, .variant = PICKUP_HEART, .seed = seed}); + } + if (player->HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES)) + for (int i = (game.devilRoomDeals < 1 ? ALABASTER_EXTRA_WISPS : 0) + ALABASTER_WISPS; i > 0; i--) + player->AddWisp(COLLECTIBLE_ALABASTER_BOX, player->pos, false, false); + + int sound = isDevil ? SOUND_SATAN_GROW : SOUND_SUPERHOLY; + if (isDevil) + { + game.darknessStrength = 1; + game.darknessTimeout = ALABASTER_DEVIL_DARK_FRAMES; + } + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound, {.frameDelay = isDevil ? 2 : ALABASTER_ANGEL_SOUND_DELAY}); + sound_play(SOUND_THUMBSUP); + player->PlayExtraAnimation("Happy"); +} + +// Alabaster Box: its reward comes a moment later, a devil's one with Judas' Birthright, and the box is spent. +static void alabaster_box_use(ItemUse& use) +{ + use_animate(use); + single_use_remove(use); + Entity_Effect* timer = Entity_Effect::CreateTimer(reinterpret_cast(&alabaster_box_reward), ALABASTER_BOX_DELAY, 0, true); + timer->parent = &use.player; + if (use.player.HasCollectible(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE)) timer->subtype = 1; +} + +// Damocles: the sword hangs over the player for good, the item spent. +static void damocles_use(ItemUse& use) +{ + use_animate(use); + single_use_remove(use); + use.player.AddCollectible(COLLECTIBLE_DAMOCLES_PASSIVE, 0, true, 0, 0, 0); +} + +// Death Certificate: off to the floor of every item, the certificate spent. +static void death_certificate_use(ItemUse& use) +{ + sound_play(SOUND_FORGET_ME_NOW); + g_game->enter_dark_closet(); + single_use_remove(use); +} + +// Plum Flute's baby plum, a moment after the tune, free to fight at once. +static void plum_flute_spawn(Entity_Effect* timer) +{ + Entity_Player* player = timer_player(timer); + if (!player) return; + uint32_t seed = player->GetCollectibleRNG(COLLECTIBLE_PLUM_FLUTE).Next(); + Vector position = room_free_pickup_position_find({.position = timer->pos, .step = 40, .isAvoidActiveEntities = true}); + Entity* plum = game_spawn({.position = position, .spawner = player, .type = ENTITY_FAMILIAR, + .variant = Entity_Familiar::BABY_PLUM, .seed = seed}, + POOL_OVERWRITE); + plum->flags &= ~FLAG_APPEAR; + plum->Update(); +} + +// Plum Flute: the tune, and a baby plum a moment later where the player stood. +static void plum_flute_use(ItemUse& use) +{ + if (use.isShowAnimation) use.player.AnimateCollectible(COLLECTIBLE_PLUM_FLUTE, "UseItem", "PlayerPickupSparkle"); + sound_play(SOUND_FLUTE); + Entity_Effect* timer = Entity_Effect::CreateTimer(reinterpret_cast(&plum_flute_spawn), PLUM_FLUTE_DELAY, 1, false); + timer->pos = use.player.pos; + timer->parent = &use.player; +} + +// Yuck Heart: a rotten heart, with a gulp (Tainted Magdalene's double one). +static void yuck_heart_use(ItemUse& use) +{ + if (use.player.variant == PLAYER_VARIANT_PLAYER) + { + sound_play(use.player.playerType == PLAYER_MAGDALENE_B ? SOUND_VAMP_DOUBLE : SOUND_VAMP_GULP); + use.player.AddRottenHearts(YUCK_HEART_ROTTEN_HEARTS, false); + } + use_animate(use); +} + +// Urn of Souls: opened or closed. Opening it raises the urn as its room effect, closing it puts the urn away. +static void urn_of_souls_use(ItemUse& use) +{ + TemporaryEffects& effects = use.player.temporaryEffects; + + if (!effects.HasCollectibleEffect(COLLECTIBLE_URN_OF_SOULS)) return sound_play(SOUND_URN_OPEN); + effects.RemoveCollectibleEffect(COLLECTIBLE_URN_OF_SOULS, -1); + if (use.isShowAnimation) use.player.AnimateCollectible(COLLECTIBLE_URN_OF_SOULS, "HideItem", "PlayerPickupSparkle"); + sound_play(SOUND_URN_CLOSE); + use.isAddEffect = false; +} + +// Sumptorium: a blood clot from the player's health, or for Tainted Eve the clots called back. +static void sumptorium_use(ItemUse& use) +{ + Entity_Player& player = use.player; + + if (player.variant != PLAYER_VARIANT_PLAYER) return; + if (player.playerType != PLAYER_EVE_B) + { + use_animate(use); + player.SpawnClot(player.pos, true); + use.isAddEffect = false; + return; + } + if (use.isShowAnimation) player.AnimateCollectible(use.id, "HideItem", "PlayerPickupSparkle"); + player.temporaryEffects.RemoveCollectibleEffect(COLLECTIBLE_SUMPTORIUM, -1); +} + +// Suplex!: a dash the way the player moves, when it moves and is not already grabbing, then the leap waits on an aim. +static void suplex_use(ItemUse& use) +{ + Entity_Player& player = use.player; + + if (player.suplexState != 0 || vector_length_squared(player.velocity) <= 1 || + player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_SUPLEX)) + return; + sound_play(SOUND_SUPLEX_ACTIVATE); + player.velocity = vector_scale(vector_normalized(player.velocity), SUPLEX_DASH_SPEED); + player.suplexState = 1; + player.suplexAimCountdown = SUPLEX_AIM_FRAMES; + player.contactHitList.clear(); + sound_play_pitched(SOUND_SHELLGAME, random_unit() * SUPLEX_PITCH_SPREAD + SUPLEX_PITCH_BASE); + use.isAddEffect = false; +} + +// Dark Arts: a dark poof, the marked target let go, and the snare laid where none is yet. +static void dark_arts_use(ItemUse& use) +{ + Entity_Player& player = use.player; + + g_game->Spawn({.position = player.pos, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}) + ->SetColor(DARK_ARTS_POOF_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + sound_play(SOUND_DARK_ARTS); + if (Entity* marked = player.markedTarget.get()) + { + marked->Remove(); + player.markedTarget = nullptr; + } + if (player.darkArtsLastSnare) return; + Entity* snare = g_game->Spawn({.position = player.pos, .spawner = &player, .type = ENTITY_EFFECT, + .variant = EFFECT_DARK_SNARE, .seed = Random()}); + snare->Update(); + player.darkArtsLastSnare = snare; + player.darkArtsHitList.clear(); + player.darkArtsDamage = 0; +} + +// Jar of Flies: its flies set free, or with Book of Virtues the same flies as wisps (one big wisp for each five). +static void jar_of_flies_use(ItemUse& use) +{ + Entity_Player& player = use.player; + + if (player.variant != PLAYER_VARIANT_PLAYER || player.jarFlies < 1) return; + sound_play(SOUND_JAR_OF_FLIES); + if (!player.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES) || !use.isWispAllowed) + player.AddBlueFlies(player.jarFlies, player.pos, nullptr); + else + { + for (int i = player.jarFlies / JAR_OF_FLIES_PER_WISP; i > 0; i--) + player.AddWisp(JAR_OF_FLIES_FULL_WISP, player.pos, false, false); + int rest = player.jarFlies % JAR_OF_FLIES_PER_WISP; + if (rest != 0) player.AddWisp(rest + JAR_OF_FLIES_PART_WISP, player.pos, false, false); + } + player.jarFlies = 0; + use_animate(use); +} + +// Wait What?: a knockback fart and a shockwave ring around the player. In a versus match it poisons who stands close. +static void wait_what_use(ItemUse& use) +{ + Entity_Player& player = use.player; + + game_butter_bean_fart({.position = player.pos, .source = &player, .radius = WAIT_WHAT_RADIUS}); + if (g_game->deathmatchManager.is_active()) + for (Entity* entity : entity_query_radius(player.pos, WAIT_WHAT_VERSUS_RADIUS, QUERY_ENEMIES)) + if (!entity->IsDescendantOf(&player)) entity->AddPoison(EntityRef(&player), WAIT_WHAT_POISON_FRAMES, 0, false); + auto* ring = static_cast(g_game->Spawn({.position = player.pos, .spawner = &player, .type = ENTITY_EFFECT, + .variant = EFFECT_SHOCKWAVE, .seed = Random()})); + ring->parent = &player; + ring->SetRadii(player.size, WAIT_WHAT_RING_RADIUS); + ring->SetTimeout(WAIT_WHAT_RING_FRAMES); +} + +// Coupon: a random shop item of the room made free. +static void coupon_use(ItemUse& use) +{ + if (use.player.variant == PLAYER_VARIANT_PLAYER) + { + std::vector wares; + for (Entity* entity : room_entities()) + { + auto* pickup = entity->type == ENTITY_PICKUP ? static_cast(entity) : nullptr; + if (pickup && pickup->IsShopItem()) wares.push_back(pickup); + } + if (!wares.empty()) + wares[use.player.GetCollectibleRNG(COLLECTIBLE_COUPON).RandomInt(wares.size())]->update_price_sprite(0); + } + use_animate(use); +} + +// Mr. ME!: the helper comes with a target the player aims, the item held up. +static void mr_me_use(ItemUse& use) +{ + Entity_Player& player = use.player; + + if (player.variant == PLAYER_VARIANT_PLAYER) + { + sound_play(SOUND_MR_ME); + Entity* helper = g_game->Spawn({.position = player.pos, .spawner = &player, .type = ENTITY_EFFECT, .variant = EFFECT_MR_ME, + .seed = player.GetCollectibleRNG(COLLECTIBLE_MR_ME).Next()}); + helper->parent = &player; + auto* target = static_cast(g_game->Spawn({.position = player.pos, .spawner = helper, .type = ENTITY_EFFECT, + .variant = EFFECT_TARGET, .seed = Random()})); + target->SetTimeout(MR_ME_TARGET_FRAMES); + target->SetColor(MR_ME_TARGET_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + helper->target = target; + helper->Update(); + } + if (use.isShowAnimation) player.AnimateCollectible(use.id, "LiftItem", "PlayerPickupSparkle"); +} + +// Fortune Cookie: a fortune, or now and then a soul heart, a card or (rarely) a trinket. +static void fortune_cookie_use(ItemUse& use) +{ + RNG& rng = use.player.GetCollectibleRNG(COLLECTIBLE_FORTUNE_COOKIE); + int variant = PICKUP_HEART; + int subType = 0; + + use_animate(use); + sound_play(SOUND_FORTUNE_COOKIE); + double roll = rng.RandomFloat(); + if (roll >= FORTUNE_COOKIE_HEART_CHANCE) return fortune_show("Fortune_General"); + if (roll < FORTUNE_COOKIE_TRINKET_CHANCE) variant = PICKUP_TRINKET; + else if (roll < FORTUNE_COOKIE_CARD_CHANCE) variant = PICKUP_TAROTCARD; + else subType = HEART_SOUL; + uint32_t seed = rng.Next(); + Vector position = room_free_pickup_position_find({.position = use.player.pos, .step = 40}); + g_game->Spawn({.position = position, .subType = subType, .type = ENTITY_PICKUP, .variant = variant, .seed = seed}); +} + +// D Infinity: the die it shows is used, a random one when the use is not the slot's own (the face kept in the data's +// high half, which the drop button turns). The slot's low half keeps that die's charges. +static void d_infinity_use(ItemUse& use) +{ + Entity_Player& player = use.player; + int slot = use.request.slot; + uint32_t flags = use.request.flags; + int face = 0; + + if (player.variant != PLAYER_VARIANT_PLAYER) return; + bool isOwnSlot = (flags & USE_OWNED) && slot >= 0 && player.activeItems[slot].item == COLLECTIBLE_D_INFINITY; + if (flags & USE_CUSTOMVARDATA) face = (int)((uint32_t)use.request.varData >> D_INFINITY_FACE_SHIFT); + else if (isOwnSlot) face = (int)((uint32_t)player.activeItems[slot].varData >> D_INFINITY_FACE_SHIFT); + else face = (int)(player.GetCollectibleRNG(COLLECTIBLE_D_INFINITY).Next() % D_INFINITY_FACES); + int die = D_INFINITY_DICE[face]; + + if ((flags & USE_OWNED) && slot >= 0 && player.activeItems[slot].item == COLLECTIBLE_D_INFINITY) + { + uint32_t& data = reinterpret_cast(player.activeItems[slot].varData); + data = (data & ~(uint32_t)D_INFINITY_FACE_MASK) | ((uint32_t)g_manager->itemConfig.GetCollectible(die)->maxCharges & (uint32_t)D_INFINITY_FACE_MASK); + } + player.UseActiveItem({.item = die}); + for (auto [item, overlay] : D_INFINITY_OVERLAYS) + if (die == item) g_game->itemOverlay.Show(overlay, 0, nullptr); +} + +// Magic Skin: an item from the room's pool, paid with a heart container (else a bone heart, else two soul hearts) and a +// broken heart. The skin is gone, its uses forgotten, for the Lost, Tainted Lost or once no heart is left to give. +static void magic_skin_use(ItemUse& use) +{ + Entity_Player& player = use.player; + RNG& rng = player.GetCollectibleRNG(COLLECTIBLE_MAGIC_SKIN); + + if (player.variant != PLAYER_VARIANT_PLAYER) return; + use_animate(use); + g_game->magicSkinUses++; + int item = g_game->itemPool.GetSeededCollectible(rng.Next(), 0, *g_game->room->descriptor); + Vector position = room_free_pickup_position_find({.position = player.pos, .step = 40}); + Entity* pedestal = g_game->Spawn({.position = position, .subType = item, .type = ENTITY_PICKUP, .variant = PICKUP_COLLECTIBLE, + .seed = rng.Next()}); + pedestal->flags &= ~FLAG_APPEAR; + pedestal->Update(); + g_game->Spawn({.position = position, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}) + ->SetColor(MAGIC_SKIN_POOF_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + sound_play(SOUND_MAGIC_SKIN); + + if (player.maxHearts > 0) player.AddMaxHearts(-2, false); + else if (player.boneHearts > 0) player.AddBoneHearts(-1); + else player.AddSoulHearts(-MAGIC_SKIN_HEART_COST, false); + bool isLost = player.playerType == PLAYER_THELOST || player.playerType == PLAYER_THELOST_B; + if (!isLost) player.AddBrokenHearts(1); + if (isLost || player.GetHeartLimit(false) < 1) + { + single_use_remove(use); + g_game->magicSkinUses = 0; + } + player.lastDamageFlags = DAMAGE_DEVIL; +} + +// Compost: every blue fly and spider doubled (a random one of the two when there are none), and every free pickup of +// the room turned into one. Book of Virtues' wisp counts the pickups composted. +static void compost_use(ItemUse& use) +{ + Entity_Player& player = use.player; + RNG& rng = player.GetCollectibleRNG(COLLECTIBLE_COMPOST); + int composted = 0; + + if (player.variant != PLAYER_VARIANT_PLAYER) return use_animate(use); + int spiders = player.numBlueSpiders; + if (spiders + player.numBlueFlies == 0) + { + if (rng.RandomInt(2) == 0) player.AddBlueSpider(player.pos); + else player.AddBlueFlies(1, player.pos, nullptr); + } + else + { + if (player.numBlueFlies > 0) + { + player.AddBlueFlies(player.numBlueFlies, player.pos, nullptr); + spiders = player.numBlueSpiders; + } + for (; spiders > 0; spiders--) player.AddBlueSpider(player.pos); + } + + EntityList_EL& entities = room_entities(); + for (size_t i = 0; i < entities.size(); i++) + { + auto* pickup = entities[i]->type == ENTITY_PICKUP && entities[i]->variant != PICKUP_COLLECTIBLE + ? static_cast(entities[i]) + : nullptr; + if (!pickup || pickup->IsShopItem() || !pickup->CanReroll()) continue; + pickup->Remove(); + composted++; + if (rng.RandomInt(2) == 0) player.AddBlueSpider(pickup->pos); + else player.AddBlueFlies(1, pickup->pos, nullptr); + } + + if (player.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES) && use.isWispAllowed && composted > 0) + if (Entity_Familiar* wisp = player.AddWisp(COMPOST_WISP, player.pos, false, false)) + { + wisp->Update(); + wisp->maxHitPoints = (float)composted; + wisp->health = (float)composted; + } + use_animate(use); +} + +// Plan C: every active enemy dies, the player a moment later (later still in Delirium's or Mother's fight), with blood +// from the walls and the screen shaken. Book of Virtues' wisps give way to as many Plan C wisps as fit. +static void plan_c_use(ItemUse& use) +{ + Entity_Player& player = use.player; + + if (player.variant != PLAYER_VARIANT_PLAYER) return use_animate(use); + single_use_remove(use); + int boss = g_game->room->bossId; + if (boss == PLAN_C_BOSS_DELIRIUM) player.planCKillCountdown = PLAN_C_DELIRIUM_FRAMES; + else player.planCKillCountdown = boss == PLAN_C_BOSS_MOTHER ? PLAN_C_MOTHER_FRAMES : PLAN_C_FRAMES; + sound_play(SOUND_PLAN_C); + EntityList_EL& entities = room_entities(); + for (size_t i = 0; i < entities.size(); i++) + if (entities[i]->IsActiveEnemy(DEAD_EXCLUDED) && entities[i] != &player) + entities[i]->TakeDamage(PLAN_C_DAMAGE, 0, EntityRef(&player), PLAN_C_DAMAGE_COUNTDOWN); + g_game->room->bloodFromWallsDuration = PLAN_C_BLOOD_FRAMES; + g_game->room->bloodFromWallsCount = PLAN_C_BLOOD_DROPS; + game_shake_screen(PLAN_C_SHAKE); + + if (player.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES) && use.isWispAllowed) + { + for (Entity* wisp : entity_query(ENTITY_FAMILIAR, Entity_Familiar::WISP)) + if (static_cast(wisp)->player == &player) wisp->Kill(EntityRef()); + for (int i = 0; i < PLAN_C_WISPS && player.AddWisp(COLLECTIBLE_PLAN_C, player.pos, false, false); i++) {} + } + use_animate(use); +} + +// Friend Finder: a random enemy from its list comes as a friend for good, steered by the player's controller. Book of +// Virtues adds a random wisp. +static void friend_finder_use(ItemUse& use) +{ + Entity_Player& player = use.player; + RNG& rng = player.GetCollectibleRNG(COLLECTIBLE_FRIEND_FINDER); + + auto [type, variant] = FRIEND_FINDER_FRIENDS[rng.RandomInt(FRIEND_FINDER_FRIENDS.size())]; + uint32_t seed = rng.Next(); + Vector position = vector_add(player.pos, vector_scale(random_direction(), FRIEND_FINDER_SPREAD)); + Entity* friendly = g_game->Spawn({.position = position, .spawner = &player, .type = type, .variant = variant, .seed = seed}); + friendly->AddCharmed(EntityRef(&player), -1, false, false); + static_cast(friendly)->controllerID = player.controllerIndex; + friendly->Update(); + if (player.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES) && use.isWispAllowed) + player.AddWisp(Entity_Familiar::GetRandomWisp(&rng), player.pos, false, false); + use_animate(use); +} + +// Dataminer: one random stat up and another down, every pedestal item but a quest one turned into a glitched item, and +// the screen's glitch with Fruit Cake's random tears for the room. +static void dataminer_use(ItemUse& use) +{ + Entity_Player& player = use.player; + RNG& rng = player.GetCollectibleRNG(COLLECTIBLE_DATAMINER); + + if (player.variant == PLAYER_VARIANT_PLAYER) + { + std::array stats = {&player.speedModifier, &player.fireDelayModifier, + &player.damageModifier, &player.tearRangeModifier, + &player.shotSpeedModifier, &player.luckModifier}; + for (int i = (int)stats.size() - 1; i > 0; i--) std::swap(stats[i], stats[rng.RandomInt(i + 1)]); + (*stats[0])++; + (*stats[1])--; + player.cacheFlags |= DATAMINER_CACHE_FLAGS; + player.EvaluateItems(); + player.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_DATAMINER, true, 1); + + for (Entity* entity : entity_query(ENTITY_PICKUP, PICKUP_COLLECTIBLE)) + { + if (entity->subtype == 0) continue; + ItemConfig_Item* item = g_manager->itemConfig.GetCollectible((int)entity->subtype); + if (item && item->HasTags(TAG_QUEST)) continue; + auto* pedestal = static_cast(entity); + pedestal->subtype = g_game->proceduralItemManager.CreateProceduralItem(rng.Next(), 0); + pedestal->UpdateSprite(false); + int glitched = ~(int)pedestal->subtype; + auto& items = g_game->proceduralItemManager.proceduralItems; + if ((int)pedestal->subtype < 0 && glitched < (int)items.size() && items[glitched]->item) + pedestal->charge = (int)items[glitched]->item->maxCharges; + } + } + player.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_FRUIT_CAKE, false, 1); + g_game->room->temporaryEffects.AddCollectibleEffect(COLLECTIBLE_DATAMINER, true, 1); + sound_play(SOUND_DATAMINER); + use_animate(use); + use.isAddEffect = false; +} + +// Larynx: a scream as strong as the slot's charge (twelve at most, one from any other use), louder and redder the +// stronger it is: a ring that hurts what it reaches, the screen shaken, and the effect for a few frames more. Book of +// Virtues adds a wisp the scream makes stronger. +static void larynx_use(ItemUse& use) +{ + Entity_Player& player = use.player; + const ActiveUse& request = use.request; + int charge = 1; + + if (request.flags & USE_CUSTOMVARDATA) charge = std::max(request.varData, 1); + else if ((request.flags & USE_OWNED) && request.slot >= 0 && player.activeItems[request.slot].item == COLLECTIBLE_LARYNX) + { + charge = std::min(player.GetTotalActiveCharge(request.slot), LARYNX_MAX_CHARGE); + if (player.wildCardItemType == WILD_CARD_ACTIVE && player.wildCardItem == COLLECTIBLE_LARYNX) + player.wildCardVarData = charge; + } + + if (charge < LARYNX_MED_CHARGE) sound_play(SOUND_LARYNX_SCREAM_LO); + else if (charge < LARYNX_HIGH_CHARGE) + { + int sound = SOUND_LARYNX_SCREAM_MED; + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound, {.volume = LARYNX_LOUD_VOLUME}); + } + else + { + int sound = SOUND_LARYNX_SCREAM_HI; + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound, {.volume = (charge - LARYNX_HIGH_CHARGE) * LARYNX_HIGH_VOLUME_STEP + LARYNX_LOUD_VOLUME}); + } + if (charge > LARYNX_MED_CHARGE) + { + ColorModState red = g_game->room->get_color_modifier(); + float blend = (charge - LARYNX_MED_CHARGE) / LARYNX_RED_SPAN; + red = {red._red + (LARYNX_RED._red - red._red) * blend, red._green + (LARYNX_RED._green - red._green) * blend, + red._blue + (LARYNX_RED._blue - red._blue) * blend, red._amount + (LARYNX_RED._amount - red._amount) * blend, + red._brightness + (LARYNX_RED._brightness - red._brightness) * blend, + red._contrast + (LARYNX_RED._contrast - red._contrast) * blend}; + g_game->SetColorModifier(red, false, LARYNX_RED_RATE); + g_game->SetColorModifier(g_game->room->get_color_modifier(), true, LARYNX_RESTORE_RATE); + } + + game_shake_screen(charge * LARYNX_SHAKE_STEP + LARYNX_SHAKE_BASE + charge * charge / LARYNX_MAX_CHARGE); + auto* ring = static_cast(g_game->Spawn({.position = player.pos, .spawner = &player, .subType = 1, + .type = ENTITY_EFFECT, .variant = EFFECT_MAMA_MEGA_EXPLOSION, + .seed = Random()})); + ring->targetPosition = player.pos; + ring->SetRadii(LARYNX_MIN_RADIUS, charge * LARYNX_RADIUS_STEP + LARYNX_RADIUS_BASE + (float)(charge * charge) * LARYNX_RADIUS_SQUARED); + bool isVersus = g_game->deathmatchManager.is_active(); + ring->SetCollisionDamage(isVersus ? charge * LARYNX_VERSUS_DAMAGE_STEP + LARYNX_VERSUS_DAMAGE_BASE + : charge * LARYNX_DAMAGE_STEP + LARYNX_DAMAGE_BASE); + ring->Update(); + + player.temporaryEffects.RemoveCollectibleEffect(COLLECTIBLE_LARYNX, -1); + TemporaryEffect effect(use.item); + effect.cooldown = charge + LARYNX_EFFECT_EXTRA_FRAMES; + player.temporaryEffects.AddEffect(effect, true, 1); + use.isAddEffect = false; + + if (!player.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES) || !use.isWispAllowed) return; + Entity_Familiar* wisp = player.AddWisp(COLLECTIBLE_LARYNX, player.pos, false, false); + if (!wisp) return; + wisp->maxHitPoints = wisp->maxHitPoints * charge * LARYNX_WISP_HEALTH_SCALE; + wisp->health = wisp->health * charge * LARYNX_WISP_HEALTH_SCALE; + wisp->keys = charge; +} + +// Spindown Dice: every pedestal item free to take turns into the item one id below it that may appear (an empty pedestal +// below the first), with a poof. Book of Virtues' wisps all turn into one random kind, and one more joins. +static void spindown_dice_use(ItemUse& use) +{ + Entity_Player& player = use.player; + + if (player.variant == PLAYER_VARIANT_PLAYER) + { + g_game->itemPool.ResetRoomBlacklist(); + for (Entity* entity : entity_query(ENTITY_PICKUP, PICKUP_COLLECTIBLE)) + { + auto* pedestal = static_cast(entity); + if (pedestal->isDead || pedestal->subtype == 0) continue; + if ((pedestal->optionsPickupIndex != 0 && pedestal->timeout >= 0) || !pedestal->CanReroll()) continue; + + int id = (int)pedestal->subtype; + ItemConfig_Item* item = nullptr; + do + { + id--; + item = id >= 1 ? g_manager->itemConfig.GetCollectible(id) : nullptr; + } while (id >= 1 && (!item || !item->IsAvailableEx(AVAILABLE_RUN_RULES | AVAILABLE_UNLOCKED))); + if (id < 1) pedestal->empty_pedestal(); + else + { + pedestal->Morph(pedestal->type, pedestal->variant, id, true, false, false); + pedestal->isTouched = false; + } + g_game->Spawn({.position = pedestal->pos, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); + } + + if (player.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES) && use.isWispAllowed) + { + int kind = Entity_Familiar::GetRandomWisp(&player.GetCollectibleRNG(COLLECTIBLE_SPINDOWN_DICE)); + for (Entity* wisp : entity_query(ENTITY_FAMILIAR, Entity_Familiar::WISP)) + wisp_morph(static_cast(*wisp), kind); + player.AddWisp(kind, player.pos, false, false); + } + } + if (!use.isShowAnimation) return; + sound_play_local(player, SOUND_D6_ROLL); + use_animate(use); +} + +// Vade Retro: every ghost on screen is banished (sent to purgatory with Judas' Birthright), every Nightwatch and every +// ghost enemy below half health dies. The screen shakes as hard as the ghosts banished were many. +static void vade_retro_use(ItemUse& use) +{ + Entity_Player& player = use.player; + Room& room = *g_game->room; + int banished = 0; + EntityList_EL& entities = room_entities(); + + for (size_t i = 0; i < entities.size(); i++) + { + Entity* entity = entities[i]; + if (!room.camera->IsPosVisible(entity->pos)) continue; + if (entity->IsEnemy() && !entity->isDead) + { + if (entity->type == ENTITY_NIGHTWATCH) entity->Kill(EntityRef(&player)); + if (entity->health < entity->maxHitPoints * 0.5f && (entity->config->tags & ENTITY_TAG_GHOST)) + entity->Kill(EntityRef(&player)); + continue; + } + if (entity->type != ENTITY_EFFECT || entity->variant != EFFECT_ENEMY_GHOST || entity->subtype != 0 || + entity->FrameCount() <= 1 || !entity->isExists) + continue; + if (!player.HasCollectible(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE)) + { + static_cast(entity)->state = 1; + entity->Update(); + banished++; + continue; + } + RNG rng = rng_make(entity->initSeed, VADE_RETRO_RNG_SHIFT); + Entity* purgatory = g_game->Spawn({.position = entity->pos, .spawner = &player, .subType = 1, .type = ENTITY_EFFECT, + .variant = EFFECT_PURGATORY, .seed = rng.Next()}); + purgatory->sprite.SetLastFrame(); + purgatory->SetColor(VADE_RETRO_PURGATORY_COLOR, VADE_RETRO_FADE_FRAMES, COLOR_PRIORITY_DEFAULT, true, true); + purgatory->sprite.scale = entity->sprite.scale; + purgatory->Update(); + entity->Remove(); + } + if (banished <= 0) return; + sound_play_pitched(SOUND_DEMON_HIT, random_unit() * VADE_RETRO_PITCH_SPREAD + VADE_RETRO_PITCH_BASE); + game_shake_screen(std::min(banished + VADE_RETRO_SHAKE_BASE, VADE_RETRO_SHAKE_MAX)); +} + +// Mystery Gift: an item from the room's pool, or with bad luck The Poop (with a fart) or a Lump of Coal (with a dark +// poof). The gift is spent. +static void mystery_gift_use(ItemUse& use) +{ + Entity_Player& player = use.player; + RNG& rng = player.GetCollectibleRNG(COLLECTIBLE_MYSTERY_GIFT); + Entity* gift = nullptr; + + if (player.variant != PLAYER_VARIANT_PLAYER) return use_animate(use); + uint32_t roll = rng.RandomInt(std::max(MYSTERY_GIFT_MIN_ROLL, (int)player.luck + MYSTERY_GIFT_LUCK_ROLL)); + Vector position = room_free_pickup_position_find({.position = player.pos, .step = 40}); + auto giftSpawn = [&](int item) { + return g_game->Spawn({.position = position, .spawner = &player, .subType = item, .type = ENTITY_PICKUP, + .variant = PICKUP_COLLECTIBLE, .seed = rng.Next()}); + }; + if (roll == 0) + { + gift = giftSpawn(COLLECTIBLE_POOP); + game_fart({.position = position, .source = &player, .radius = MYSTERY_GIFT_FART_RADIUS}); + game_butter_bean_fart({.position = position, .source = &player, .radius = MYSTERY_GIFT_PUSH_RADIUS, .isShowEffect = false}); + } + else if (roll == 1) + { + gift = giftSpawn(COLLECTIBLE_LUMP_OF_COAL); + sound_play(SOUND_THUMBS_DOWN); + g_game->Spawn({.position = position, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}) + ->SetColor(MYSTERY_GIFT_COAL_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + } + else + { + gift = giftSpawn(0); + sound_play(SOUND_THUMBSUP); + g_game->Spawn({.position = position, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); + } + gift->flags &= ~FLAG_APPEAR; + gift->Update(); + single_use_remove(use); + use_animate(use); +} + +// Jar of Wisps: as many wisps as the jar was used before, one more each use up to twelve: a random active's wisp, or a +// third of the time Book of Virtues' (the Satanic Bible's with Judas' Birthright). Book of Virtues triples each one. +static void jar_of_wisps_use(ItemUse& use) +{ + Entity_Player& player = use.player; + const ActiveUse& request = use.request; + RNG& rng = player.GetCollectibleRNG(COLLECTIBLE_JAR_OF_WISPS); + ItemConfig& config = g_manager->itemConfig; + int uses = 1; + + use_animate(use); + if (request.flags & USE_CUSTOMVARDATA) uses = request.varData; + else if ((request.flags & USE_OWNED) && request.slot >= 0 && player.activeItems[request.slot].item == COLLECTIBLE_JAR_OF_WISPS) + { + int& data = player.activeItems[request.slot].varData; + uses = data; + data = std::min(uses + 1, JAR_OF_WISPS_MAX_USES); + } + + std::vector actives; + for (int id = 0; id < (int)config.collectibles.size(); id++) + { + ItemConfig_Item* item = config.GetCollectible(id); + if (item && item->type == ITEM_ACTIVE && item->wispConfig && item->wispConfig->count > 0) actives.push_back(id); + } + for (; uses > 0; uses--) + { + ItemConfig_Item* item = nullptr; + if (rng.RandomFloat() < JAR_OF_WISPS_VIRTUES_CHANCE) + { + item = config.GetCollectible(actives[rng.RandomInt((uint32_t)actives.size() - 1)]); + if (item && (!ItemConfig::IsValidCollectible(item->id) || item->type != ITEM_ACTIVE)) item = nullptr; + } + if (!item || !item->wispConfig || item->wispConfig->count < 1) item = config.GetCollectible(COLLECTIBLE_BOOK_OF_VIRTUES); + if (item->id == COLLECTIBLE_BOOK_OF_VIRTUES && player.HasCollectible(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE)) + item = config.GetCollectible(COLLECTIBLE_SATANIC_BIBLE); + int wisps = player.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES) && use.isWispAllowed ? 3 : 1; + for (int i = 0; i < wisps; i++) player.AddWisp(item->id, player.pos, true, false); + } + sound_play(SOUND_CANDLE_LIGHT); +} + +// Glowing Hour Glass: back to the previous room as it was, three times a floor from the slot. Once spent it only slows +// time for the room, as the Hourglass does. +static void glowing_hour_glass_use(ItemUse& use) +{ + Entity_Player& player = use.player; + const ActiveUse& request = use.request; + bool isOwnSlot = (request.flags & USE_OWNED) && request.slot >= 0 && + player.activeItems[request.slot].item == COLLECTIBLE_GLOWING_HOUR_GLASS; + int rewinds = request.flags & USE_CUSTOMVARDATA ? request.varData : isOwnSlot ? player.activeItems[request.slot].varData : 0; + + if (player.variant != PLAYER_VARIANT_PLAYER) return; + if (((request.flags & USE_CUSTOMVARDATA) || isOwnSlot) && rewinds >= GLOWING_HOUR_GLASS_REWINDS) + { + use_animate(use); + g_game->room->temporaryEffects.AddCollectibleEffect(COLLECTIBLE_HOURGLASS, true, 1); + g_manager->musicManager.PitchSlide(g_game->room->time_scale_update()); + return sound_play(SOUND_GLOWING_HOURGLASS_FIZZLE); + } + g_game->leaveDoor = g_game->enterDoor < 0 ? -1 : std::min(g_game->enterDoor, DOOR_SLOT_LAST); + g_game->StartRoomTransition({.player = &player, .animation = TRANSITION_GLOWING_HOURGLASS, .roomIndex = g_game->lastRoomIdx}); + sound_play(SOUND_GLOWING_HOURGLASS_ACTIVATE); +} + +// D7: the room's enemies come back to fight again, never in a boss room, the Beast's dungeon, Gideon's or Rotgut's +// crawl space, or at Home. +static void d7_use(ItemUse& use) +{ + Entity_Player& player = use.player; + Room& room = *g_game->room; + + if (player.variant != PLAYER_VARIANT_PLAYER) return; + if (use.isShowAnimation) + { + sound_play_local(player, SOUND_D6_ROLL); + use_animate(use); + } + RoomConfig_Room* data = room.descriptor->data; + bool isBossDungeon = room.roomType == ROOM_DUNGEON && data && (data->subtype == D7_DUNGEON_GIDEON || data->subtype == D7_DUNGEON_ROTGUT); + if (room.roomType == ROOM_BOSS || room.IsBeastDungeon() || isBossDungeon || g_game->stage == STAGE_HOME) return; + reconstruction_missing("Room::RespawnEnemies 0081fd60 (the D7's respawn)"); + g_game->isRoomRespawned = true; +} + +// Stitches: the player and Stitches trade places, when Stitches floats over a spot the player could stand on (any but a +// wall when flying, a free or pit-free cell when not). Book of Virtues adds a wisp. +static void stitches_use(ItemUse& use) +{ + Entity_Player& player = use.player; + Entity_Familiar* stitches = nullptr; + + for (Entity* entity : entity_query(ENTITY_FAMILIAR, Entity_Familiar::STITCHES)) + if (static_cast(entity)->player == &player) + { + stitches = static_cast(entity); + break; + } + if (!stitches) return; + uint32_t collision = room_grid_collision_at(stitches->pos); + bool isReachable = player.canFly ? collision != COLLISION_WALL : collision == COLLISION_NONE || collision == COLLISION_WALL_EXCEPT_PLAYER; + if (!isReachable) return; + if (player.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES) && use.isWispAllowed) + player.AddWisp(COLLECTIBLE_STITCHES, player.pos, false, false); + stitches->state = 1; + stitches->Update(); +} + +// 0074bce0 The Genesis room made anew: a fresh descriptor with an Isaac's room of the special rooms' subtype 99, +// seeded from the devil room's generator. +static void genesis_room_prepare() +{ + Game& game = *g_game; + RoomDescriptor* genesis = game.GetRoomByIdx(ROOM_GENESIS_IDX); + + *genesis = RoomDescriptor{}; + genesis->listIndex = ROOM_GENESIS_IDX; + RNG rng = GENESIS_RNG_SHIFTS; + rng._seed = game.devilAngelRoomRNG._seed; + genesis->InitSeeds(rng); + RoomQuery query = {.stageId = STAGE_ID_SPECIAL_ROOMS, .subtype = GENESIS_ROOM_SUBTYPE, .type = ROOM_ISAACS}; + genesis->data = game.roomConfig.GetRandomRoom(rng.Next(), WEIGHT_KEEP, query); +} + +// Genesis' three Book of Virtues wisps, once the player stands in the Genesis room. +static void genesis_wisps_add(Entity_Effect* timer) +{ + Entity_Player* player = timer_player(timer); + if (!player) return; + for (int i = 0; i < GENESIS_WISPS; i++) player->AddWisp(COLLECTIBLE_GENESIS, player->pos, false, false); +} + +// Genesis: every item is taken away for the Genesis room, where a choice of new ones waits. The item is spent. +static void genesis_use(ItemUse& use) +{ + Entity_Player& player = use.player; + + if (player.variant != PLAYER_VARIANT_PLAYER) return; + single_use_remove(use); + genesis_room_prepare(); + g_game->leaveDoor = -1; + g_game->StartRoomTransition({.player = player.GetMainTwin(), .animation = TRANSITION_TELEPORT, .dimension = 0, + .roomIndex = ROOM_GENESIS_IDX}); + if (!player.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES) || !use.isWispAllowed) return; + Entity_Effect* timer = Entity_Effect::CreateTimer(reinterpret_cast(&genesis_wisps_add), 1, 1, true); + timer->parent = player.GetMainTwin(); +} + +// R Key's restart a frame after its use: the run starts over from the first floor, items kept. +static void r_key_restart(Entity_Effect*) +{ + reconstruction_missing("r_key_timer_callback 00707ad0 (R Key's restart of the run)"); +} + +// R Key's item raised again a few frames after its use, once the restart has begun. +static void r_key_raise(Entity_Effect* timer) +{ + if (Entity_Player* player = timer_player(timer)) player->AnimateCollectible(COLLECTIBLE_R_KEY, "UseItem", "PlayerPickupSparkle"); +} + +// R Key: the run starts over a frame later, the key spent. The item is raised again once the restart has begun. +static void r_key_use(ItemUse& use) +{ + single_use_remove(use); + Entity_Effect::CreateTimer(reinterpret_cast(&r_key_restart), 1, 0, false)->parent = &use.player; + sound_play(SOUND_R_KEY); + if (!use.isShowAnimation) return; + Entity_Effect* timer = Entity_Effect::CreateTimer(reinterpret_cast(&r_key_raise), R_KEY_RAISE_DELAY, 0, false); + timer->parent = &use.player; + timer->AddEntityFlags(FLAG_PERSISTENT); +} + +// Potato Peeler: a heart container peeled off into a cube of meat (or a ball of bandages, with Ball of Bandages but no +// Cube of Meat), a fake hit in a burst of blood, Anemic's trail for a while and Judas' Birthright's lasting boost. +static void potato_peeler_use(ItemUse& use) +{ + Entity_Player& player = use.player; + + if (player.variant != PLAYER_VARIANT_PLAYER || player.maxHearts <= 0) return; + player.AddMaxHearts(-2, false); + if (!player.HasCollectible(COLLECTIBLE_CUBE_OF_MEAT) && player.HasCollectible(COLLECTIBLE_BALL_OF_BANDAGES)) + player.potatoPeelerBandageCounter++; + else player.potatoPeelerCounter++; + player.cacheFlags |= PEELER_CACHE_FLAGS; + player.EvaluateItems(); + player.TakeDamage(DULL_RAZOR_DAMAGE, DULL_RAZOR_DAMAGE_FLAGS, EntityRef(&player), DULL_RAZOR_COUNTDOWN); + + Vector base = vector_scale(Entity_Pickup::GetRandomPickupVelocity(player.pos, nullptr, 0), PEELER_BURST_SPEED); + sound_play(SOUND_MEATY_DEATHS); + g_game->Spawn({.position = player.pos, .velocity = base, .subType = PEELER_BLOOD_SUBTYPE, .type = ENTITY_EFFECT, + .variant = EFFECT_BLOOD_EXPLOSION, .seed = Random()}); + int gore = random_below(PEELER_GORE_RANGE) + PEELER_GORE_MIN; + int drops = random_below(PEELER_DROPS_RANGE) + PEELER_DROPS_MIN + gore; + for (int i = 0; i < drops; i++) + { + Vector direction = tear_vector_rotate(base, random_unit() * PEELER_BURST_SPREAD - PEELER_BURST_SPREAD / 2); + Vector velocity = vector_scale(direction, random_unit()); + g_game->Spawn({.position = vector_add(player.pos, velocity), .velocity = velocity, .subType = i < gore ? 0 : PEELER_DROP_SUBTYPE, + .type = ENTITY_EFFECT, .variant = EFFECT_BLOOD_PARTICLE, .seed = Random()}) + ->Update(); + } + + player.try_trigger_astral_projection(); + TemporaryEffect anemic(g_manager->itemConfig.GetCollectible(COLLECTIBLE_ANEMIC)); + if (g_game->deathmatchManager.is_active()) anemic.cooldown = PEELER_VERSUS_ANEMIC_FRAMES; + player.temporaryEffects.AddEffect(anemic, true, 1); + if (player.HasCollectible(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE)) + player.temporaryEffects.AddNullEffect(NULLITEM_JUDAS_BIRTHRIGHT_PERMANENT, true, 1); + use_animate(use); +} + +// Keeper's Box: a random ware for sale near the player (a pill, card or shop item drawn from the pools). When every +// player is a Keeper, a heart becomes a bomb or a key. +static void keepers_box_use(ItemUse& use) +{ + Entity_Player& player = use.player; + RNG& rng = player.GetCollectibleRNG(COLLECTIBLE_KEEPERS_BOX); + WeightedOutcomePicker picker; + + use_animate(use); + for (int outcome = 0; outcome < (int)KEEPERS_BOX_WARES.size(); outcome++) picker.AddOutcomeWeight(outcome, 1); + int outcome = picker.PickOutcome(rng_make(rng.Next(), KEEPERS_BOX_RNG_SHIFT)); + auto [variant, subType] = KEEPERS_BOX_WARES[outcome]; + if (variant == PICKUP_PILL) subType = ItemPool::GetPill(rng.Next()); + else if (variant == PICKUP_TAROTCARD) subType = ItemPool::GetCard(rng.Next(), true, false, false); + else if (variant == PICKUP_COLLECTIBLE) + subType = g_game->itemPool.GetCollectible(g_game->IsGreedMode() ? POOL_GREED_SHOP : POOL_SHOP, rng.Next(), 0, 0, 0); + + bool isAllKeepers = std::ranges::none_of(g_game->playerManager.playerList, [](Entity_Player* each) { + return each->variant == PLAYER_VARIANT_PLAYER && each->playerType != PLAYER_KEEPER && each->playerType != PLAYER_KEEPER_B; + }); + if (isAllKeepers && variant == PICKUP_HEART) + { + variant = rng.RandomInt(2) != 0 ? PICKUP_BOMB : PICKUP_KEY; + subType = 1; + } + uint32_t seed = player.GetCollectibleRNG(COLLECTIBLE_KEEPERS_BOX).Next(); + Vector position = room_free_pickup_position_find({.position = player.pos, .step = 40, .isAvoidActiveEntities = true}); + auto* ware = static_cast(g_game->Spawn({.position = position, .subType = subType, .type = ENTITY_PICKUP, + .variant = variant, .seed = seed})); + ware->MakeShopItem(-1); + ware->Update(); + g_game->Spawn({.position = ware->pos, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()})->Update(); +} + +// D1: a copy of a random free pickup of the room that may be rerolled (a chest's copy a random chest, a card's a card of +// its own kind), from its own seed. Book of Virtues adds a wisp when there is nothing to copy. +static void d1_use(ItemUse& use) +{ + Entity_Player& player = use.player; + std::vector pickups; + + if (player.variant == PLAYER_VARIANT_PLAYER) + { + for (Entity* entity : entity_query(ENTITY_PICKUP, -1)) + if (static_cast(entity)->CanReroll() && entity->variant != PICKUP_COLLECTIBLE) + pickups.push_back(static_cast(entity)); + if (pickups.empty()) + { + if (player.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES) && use.isWispAllowed) player.AddWisp(COLLECTIBLE_D1, player.pos, false, false); + } + else + { + Entity_Pickup& copied = *pickups[player.GetCollectibleRNG(COLLECTIBLE_D1).RandomInt(pickups.size())]; + int variant = copied.variant; + int subType = (int)copied.subtype; + if (Entity_Pickup::IsChest(copied.variant)) variant = copied.dropRNG.RandomInt(2) != 0 ? PICKUP_CHEST : PICKUP_LOCKEDCHEST; + if (variant != PICKUP_TAROTCARD) subType = 0; + else if (ItemConfig_Card* card = subType != 0 ? g_manager->itemConfig.GetCard(subType) : nullptr) + { + if (card->cardType == CARD_RUNE) subType = ItemPool::GetCard(copied.dropRNG.Next(), false, false, true); + else if (card->cardType != CARD_OBJECT) subType = ItemPool::GetCard(copied.dropRNG.Next(), true, false, false); + } + copied.UpdateLootPreview(); + uint32_t seed = player.GetCollectibleRNG(COLLECTIBLE_D1).Next(); + Vector position = room_free_pickup_position_find({.position = copied.pos}); + g_game->Spawn({.position = position, .spawner = &player, .subType = subType, .type = ENTITY_PICKUP, .variant = variant, + .seed = seed}); + } + } + if (!use.isShowAnimation) return; + sound_play_local(player, SOUND_D6_ROLL); + use_animate(use); +} + +// Sends Meat Cleaver's slash at a target, which splits it. +static void cleaver_slash_spawn(Entity& target) +{ + Entity* slash = g_game->Spawn({.position = target.pos, .type = ENTITY_EFFECT, .variant = EFFECT_CLEAVER_SLASH, .seed = Random()}); + slash->target = ⌖ + slash->Update(); +} + +// Meat Cleaver: every enemy that keeps the doors shut (and Blood Puppies and Fissures) is slashed in two; a segmented +// boss through its middle vulnerable segment. Book of Virtues' wisps are split as well, and one more joins. +static void meat_cleaver_use(ItemUse& use) +{ + Entity_Player& player = use.player; + EntityList_EL& entities = room_entities(); + + use_animate(use); + for (size_t i = 0; i < entities.size(); i++) + { + Entity* npc = entities[i]->to_npc_or_coop_player(); + if (!npc) continue; + Entity* target = npc; + bool isHead = npc->is_same_segmented_body(nullptr) && npc->GetStatusEffectTarget() == npc; + if (isHead) + { + std::vector segments; + for (Entity* segment = npc; segment; segment = segment->child.get()) + if (segment->IsVulnerableEnemy(nullptr)) segments.push_back(segment); + if (segments.empty()) continue; + target = segments[segments.size() / 2]; + } + else if (!npc->IsVulnerableEnemy(nullptr) || npc->is_same_segmented_body(nullptr) || + !(npc->CanShutDoors() || npc->type == ENTITY_BLOOD_PUPPY || npc->type == ENTITY_FISSURE)) + continue; + cleaver_slash_spawn(*target); + sound_play_pitched(SOUND_SHELLGAME, MEAT_CLEAVER_PITCH); + } + + if (!player.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES) || !use.isWispAllowed) return; + for (Entity* wisp : entity_query(ENTITY_FAMILIAR, Entity_Familiar::WISP)) cleaver_slash_spawn(*wisp); + player.AddWisp(COLLECTIBLE_MEAT_CLEAVER, player.pos, true, false); +} + +// Mega Mush: the player grows huge for a while (five seconds in a versus match). Its giant transform plays over the +// screen with the player's own mushroom costume, the player hidden meanwhile. +static void mega_mush_use(ItemUse& use) +{ + Entity_Player& player = use.player; + TemporaryEffect effect(g_manager->itemConfig.GetCollectible(COLLECTIBLE_MEGA_MUSH)); + + if (g_game->deathmatchManager.is_active()) effect.cooldown = MEGA_MUSH_VERSUS_FRAMES; + player.temporaryEffects.AddEffect(effect, true, 1); + use.isAddEffect = false; + int costume = player.playerCostumeMap[PLAYER_LAYER_HEAD].index; + if (!use.isShowAnimation || costume < 0) return; + CostumeSpriteDesc& desc = player.costumeSpriteDescs[costume]; + if (!desc.item || desc.item->type != ITEM_ACTIVE || desc.item->id != COLLECTIBLE_MEGA_MUSH) return; + + ANM2& overlay = g_game->itemOverlay.megaMushPlayerSprite; + overlay = desc.sprite; + overlay.scale = player.sprite.scale; + overlay.Play("Transform", PLAY_FORCED); + for (LayerState& layer : overlay.layerStates) layer.pos = {}; + g_game->itemOverlay.Show(GIANTBOOK_MEGA_MUSH, 0, &player); + player.isVisible = false; +} + +// Runs the own effect of a late Afterbirth, Afterbirth+ or Repentance active (400 and up) the main dispatch does not +// case. The ones not written yet stop the game. +void repentance_item_effect_run(ItemUse& use) +{ + Entity_Player& player = use.player; + + switch (use.id) + { + case COLLECTIBLE_D8: + return d8_use(use); + case COLLECTIBLE_TELEPORT_2: + return teleport_2_use(use); + case COLLECTIBLE_KIDNEY_BEAN: + return game_charm_fart(player.pos, CHARM_FART_RADIUS, &player); + case COLLECTIBLE_MINE_CRAFTER: + return mine_crafter_use(use); + case COLLECTIBLE_MOMS_BOX: + return moms_box_use(use); + case COLLECTIBLE_MEGA_BLAST: + return mega_blast_use(use); + case COLLECTIBLE_PAUSE: + return pause_use(use); + case COLLECTIBLE_MAMA_MEGA: + return mama_mega_use(use); + case COLLECTIBLE_DULL_RAZOR: + return dull_razor_use(use); + case COLLECTIBLE_EDENS_SOUL: + return edens_soul_use(use); + case COLLECTIBLE_BROWN_NUGGET: + if (use.isShowAnimation) sound_play(SOUND_BROWN_NUGGET); + return use_animate(use); + case COLLECTIBLE_BLACK_HOLE: + sound_play(SOUND_BLACK_HOLE_ACTIVATE); + return item_state_lift(use, COLLECTIBLE_BLACK_HOLE); + case COLLECTIBLE_TELEKINESIS: + if (use.isShowAnimation) sound_play_local(player, SOUND_TELEKENESIS); + return use_animate(use); + case COLLECTIBLE_BROKEN_SHOVEL_1: + if (use.isShowAnimation) sound_play(SOUND_BROKEN_SHOVEL); + return use_animate(use); + case COLLECTIBLE_GOLDEN_RAZOR: + return golden_razor_use(use); + case COLLECTIBLE_SULFUR: + return sulfur_use(use); + case COLLECTIBLE_DAMOCLES: + return damocles_use(use); + case COLLECTIBLE_FREE_LEMONADE: + return free_lemonade_use(use); + case COLLECTIBLE_RED_KEY: + return red_key_use(use); + case COLLECTIBLE_WAVY_CAP: + sound_play(SOUND_VAMP_GULP); + return use_animate(use); + case COLLECTIBLE_ALABASTER_BOX: + return alabaster_box_use(use); + case COLLECTIBLE_MOMS_BRACELET: + return player.moms_bracelet_grab(); + case COLLECTIBLE_SCOOPER: + return sound_play(SOUND_PLOP); + case COLLECTIBLE_SHARP_KEY: + if (player.numKeys > 0) item_state_lift(use, COLLECTIBLE_SHARP_KEY); + return; + case COLLECTIBLE_DEATH_CERTIFICATE: + return death_certificate_use(use); + case COLLECTIBLE_ERASER: + return item_state_lift(use, COLLECTIBLE_ERASER); + case COLLECTIBLE_YUCK_HEART: + return yuck_heart_use(use); + case COLLECTIBLE_URN_OF_SOULS: + return urn_of_souls_use(use); + case COLLECTIBLE_PLUM_FLUTE: + return plum_flute_use(use); + case COLLECTIBLE_ESAU_JR: + return; + case COLLECTIBLE_BERSERK: + sound_play(SOUND_BERSERK_START); + return sound_play(SOUND_ISAAC_ROAR); + case COLLECTIBLE_DARK_ARTS: + return dark_arts_use(use); + case COLLECTIBLE_SUPLEX: + return suplex_use(use); + case COLLECTIBLE_SUMPTORIUM: + return sumptorium_use(use); + case COLLECTIBLE_RECALL: + if (player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_RECALL)) use.isAddEffect = false; + else sound_play(SOUND_RECALL); + return; + case COLLECTIBLE_GELLO: + sound_play(SOUND_GELLO); + return item_state_lift(use, COLLECTIBLE_GELLO); + case COLLECTIBLE_JAR_OF_FLIES: + return jar_of_flies_use(use); + case COLLECTIBLE_WAIT_WHAT: + return wait_what_use(use); + case COLLECTIBLE_COUPON: + return coupon_use(use); + case COLLECTIBLE_MR_ME: + return mr_me_use(use); + case COLLECTIBLE_FORTUNE_COOKIE: + return fortune_cookie_use(use); + case COLLECTIBLE_D_INFINITY: + return d_infinity_use(use); + case COLLECTIBLE_MAGIC_SKIN: + return magic_skin_use(use); + case COLLECTIBLE_COMPOST: + return compost_use(use); + case COLLECTIBLE_PLAN_C: + return plan_c_use(use); + case COLLECTIBLE_FRIEND_FINDER: + return friend_finder_use(use); + case COLLECTIBLE_DATAMINER: + return dataminer_use(use); + case COLLECTIBLE_LARYNX: + return larynx_use(use); + case COLLECTIBLE_SPINDOWN_DICE: + return spindown_dice_use(use); + case COLLECTIBLE_VADE_RETRO: + return vade_retro_use(use); + case COLLECTIBLE_MYSTERY_GIFT: + return mystery_gift_use(use); + case COLLECTIBLE_JAR_OF_WISPS: + return jar_of_wisps_use(use); + case COLLECTIBLE_GLOWING_HOUR_GLASS: + return glowing_hour_glass_use(use); + case COLLECTIBLE_D7: + return d7_use(use); + case COLLECTIBLE_STITCHES: + return stitches_use(use); + case COLLECTIBLE_GENESIS: + return genesis_use(use); + case COLLECTIBLE_R_KEY: + return r_key_use(use); + case COLLECTIBLE_POTATO_PEELER: + return potato_peeler_use(use); + case COLLECTIBLE_KEEPERS_BOX: + return keepers_box_use(use); + case COLLECTIBLE_D1: + return d1_use(use); + case COLLECTIBLE_MEAT_CLEAVER: + return meat_cleaver_use(use); + case COLLECTIBLE_MEGA_MUSH: + return mega_mush_use(use); + case COLLECTIBLE_DECAP_ATTACK: + sound_play(SOUND_DECAP_ACTIVATE); + item_state_lift(use, COLLECTIBLE_DECAP_ATTACK); + use.isAddEffect = false; + return; + case COLLECTIBLE_MOMS_SHOVEL: + return rebirth_item_effect_run(use); + default: + return active_missing_report(use); + } +} diff --git a/src/entity_player_cards.cpp b/src/entity_player_cards.cpp index e37c9d2..3dace13 100644 --- a/src/entity_player_cards.cpp +++ b/src/entity_player_cards.cpp @@ -9,6 +9,7 @@ #include "game.h" #include "hud.h" #include "level_generator.h" +#include "loot_list.h" #include "item_overlay.h" #include "manager.h" #include "npc_ai.h" @@ -16,6 +17,10 @@ #include "room.h" #include "room_grid.h" #include "room_special.h" +#include "boss_ai.h" +#include "deathmatch_manager.h" +#include "grid_entity_door.h" +#include "room_render.h" #include #include #include @@ -64,6 +69,70 @@ constexpr float RECALL_SPEED = 2; constexpr float SUN_DAMAGE = 100; constexpr float WHEEL_VOLUME = 1.2f; constexpr int REVERSE_DEVIL_SOUND = 266; +// The bomb pickup subtypes IX - The Hermit? values higher (Lua's BombSubType, which entity_pickup.cpp keeps). +constexpr int BOMB_SUBTYPE_DOUBLEPACK = 2; +constexpr int BOMB_SUBTYPE_GOLDEN = 4; +constexpr int BOMB_SUBTYPE_GIGA = 7; +constexpr int BLANK_RUNE_KEEP_ODDS = 4; +constexpr int REVERSE_TOWER_RNG_SHIFT = 45; +constexpr int REVERSE_TOWER_FREE_WEIGHT = 5; +constexpr int REVERSE_TOWER_OPEN_WEIGHT = 50; +constexpr int REVERSE_TOWER_SPENT_WEIGHT = 1; +constexpr int REVERSE_TOWER_REACH = 2; +constexpr int REVERSE_TOWER_WAVE_FRAMES = 5; +constexpr int REVERSE_TOWER_LAST_FRAME = 35; +constexpr float REVERSE_TOWER_JITTER = 36; +constexpr float REVERSE_TOWER_RADIUS_SQUARED = 5625; +constexpr int BLACK_RUNE_PEDESTAL_TIMEOUT = 4; +constexpr uint32_t BLACK_RUNE_CACHE_FLAGS = 0x41f; +constexpr int REVERSE_CHARIOT_ALT_ODDS = 10; +constexpr int REVERSE_CHARIOT_DUST_COUNT = 3; +constexpr int REVERSE_CHARIOT_DUST_FRAMES = 15; +constexpr int REVERSE_CHARIOT_GREY_FRAMES = 2; +constexpr int REVERSE_CHARIOT_SHAKE = 4; +constexpr int REVERSE_HERMIT_PENNY_SHIFT = 33; +constexpr int REVERSE_HERMIT_RNG_SHIFT = 16; +constexpr int REVERSE_JUSTICE_MIN = 2; +constexpr int REVERSE_JUSTICE_SPREAD = 3; +constexpr int REVERSE_WHEEL_DARK_FRAMES = 60; +constexpr int REVERSE_WHEEL_SHAKE = 50; +constexpr int SOUL_APOLLYON_KINDS = 5; +constexpr int SOUL_APOLLYON_LOCUSTS = 15; +constexpr int SOUL_APOLLYON_VERSUS_LOCUSTS = 10; +constexpr int SOUL_AZAZEL_FRAMES = 240; +constexpr int SOUL_AZAZEL_VERSUS_FRAMES = 90; +constexpr int SOUL_BETHANY_WISPS = 6; +constexpr int SOUL_BLUEBABY_CREEP_FRAMES = 36; +constexpr int SOUL_EVE_BIRDS = 15; +constexpr int SOUL_EVE_EXTRA_FRAMES = 150; +constexpr int SOUL_EVE_MIN_FRAMES = 300; +constexpr int SOUL_EVE_START_STATES = 90; +constexpr int SOUL_JACOB_TRIES = 10; +constexpr uint32_t SOUL_JACOB_DRAW_FLAGS = 7; +constexpr int SOUL_JUDAS_FRAMES = 90; +constexpr int SOUL_KEEPER_COINS = 25; +constexpr int SOUL_SAMSON_FRAMES = 300; +constexpr float REVERSE_CHARIOT_DUST_ALPHA = 0.5f; +constexpr float REVERSE_CHARIOT_DUST_MIN_ALPHA = 0.2f; +constexpr float REVERSE_CHARIOT_DUST_MIN_TURN = 2; +constexpr float REVERSE_CHARIOT_DUST_SPEED = 5; +constexpr float REVERSE_CHARIOT_DUST_SPREAD = 20; +constexpr float REVERSE_CHARIOT_DUST_TURN = 10; +constexpr float REVERSE_HERMIT_COIN_SPEED = 5; +constexpr float REVERSE_LOVERS_VOLUME = 0.6f; +constexpr float SOUL_BLUEBABY_PITCH = 1.5f; +constexpr float SOUL_EVE_FAR = 1000; +constexpr float SOUL_EVE_MARGIN_SPREAD = 120; +constexpr float SOUL_EVE_MIN_MARGIN = 80; +constexpr float SOUL_LILITH_VOLUME = 0.5f; +constexpr float BLACK_RUNE_POOF_DROP = 10; +constexpr float SOUL_TWIN_DROP = 4; +constexpr ColorMod REVERSE_CHARIOT_FLASH = {{1, 1, 1, 1}, {0, 0, 0, 0}, {0.8f, 0.8f, 0.8f}}; +constexpr ColorMod REVERSE_HERMIT_POOF_COLOR = {{1, 1, 1, 1}, {3, 2.4f, 1, 1}, {0, 0, 0}}; +constexpr ColorMod REVERSE_LOVERS_POOF_COLOR = {{1, 1, 1, 1}, {2, 0.4f, 0.4f, 1}, {0, 0, 0}}; +// The runes Blank Rune picks from (00b6bc20). +constexpr std::array BLANK_RUNE_RUNES = {RUNE_HAGALAZ, RUNE_JERA, RUNE_EHWAZ, RUNE_DAGAZ, RUNE_ANSUZ, + RUNE_PERTHRO, RUNE_BERKANO, RUNE_ALGIZ, RUNE_BLACK}; constexpr std::array ACE_VARIANTS = {PICKUP_BOMB, PICKUP_COIN, PICKUP_KEY, PICKUP_HEART}; constexpr std::array SUICIDE_KING_PICKUP_VARIANTS = {10, 20, 30, 40, 50, 60, 70, 90, 100, 300, 350, 360}; @@ -832,6 +901,835 @@ static PocketUseEnd reverse_devil_use(PocketUse& use) return POCKET_END_ANIMATE; } +// Whether a versus match's rules ban a card. +static bool is_versus_card_banned(int card) +{ + DeathmatchManager& versus = g_game->deathmatchManager; + return versus.is_active() && versus.type->FUN_0042b480(card); +} + +// Whether a versus match's rules ban a collectible. +static bool is_versus_collectible_banned(int item) +{ + DeathmatchManager& versus = g_game->deathmatchManager; + return versus.is_active() && versus.type->FUN_0042b020(item); +} + +// Spawns a pickup near the player that no one spawned, with the card's next seed after its spot is found. +static Entity* card_pickup_spawn(PocketUse& use, int variant, int subType) +{ + Vector position = room_free_pickup_position_find({.position = use.player.pos, .step = 40}); + return g_game->Spawn({.position = position, .subType = subType, .type = ENTITY_PICKUP, .variant = variant, + .seed = use.rng.Next()}); +} + +// Spawns a poof over a spot, tinted unless the color is the plain one. +static Entity* card_poof_spawn(const Vector& position, Entity* spawner) +{ + return g_game->Spawn({.position = position, .spawner = spawner, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, + .seed = Random()}); +} + +// Blank Rune: another rune's effect at random (one a versus match allows), and a quarter of the time a new Blank Rune +// unless the use is mimicked. +static PocketUseEnd blank_rune_use(PocketUse& use) +{ + if (use.rng.RandomInt(BLANK_RUNE_KEEP_ODDS) == 0 && !(use.flags & USE_MIMIC)) + pocket_pickup_spawn(use, PICKUP_TAROTCARD, RUNE_BLANK); + + int rune = BLANK_RUNE_RUNES[use.rng.RandomInt(BLANK_RUNE_RUNES.size())]; + while (is_versus_card_banned(rune)) rune = BLANK_RUNE_RUNES[use.rng.RandomInt(BLANK_RUNE_RUNES.size())]; + use.player.UseCard(rune, 0); + return POCKET_END_ANIMATE; +} + +// Black Rune's stat up: two of the six stats, shuffled with the rune's generator, one step up each. +static void black_rune_stats_raise(Entity_Player& player) +{ + std::array stats = {&player.speedModifier, &player.fireDelayModifier, &player.damageModifier, + &player.tearRangeModifier, &player.shotSpeedModifier, &player.luckModifier}; + + for (int i = (int)stats.size() - 1; i > 0; i--) + std::swap(stats[i], stats[player.GetCardRNG(RUNE_BLACK).RandomInt(i + 1)]); + (*stats[0])++; + (*stats[1])++; +} + +// Black Rune: the item held up and every free pedestal item are eaten for stat ups (a co-op pedestal choice is put back +// rerolled from the boss pool), every other free pickup turns into a blue fly, the Necronomicon hurts the room and a +// challenge room's waves start if anything was eaten. +static PocketUseEnd black_rune_use(PocketUse& use) +{ + Entity_Player& player = use.player; + ItemConfig_Item* queued = player.queuedItem.item; + std::vector coopChoices; + bool isEaten = false; + + if (queued && queued->IsCollectible() && !queued->HasTags(TAG_QUEST)) + { + player.queuedItem.item = nullptr; + player.queuedItem.charge = 0; + black_rune_stats_raise(player); + card_poof_spawn(vector_add(player.pos, vector_make(0, BLACK_RUNE_POOF_DROP)), nullptr); + } + + for (Entity* entity : g_game->room->GetEntities()->updateEL) + { + auto* pickup = entity->type == ENTITY_PICKUP ? static_cast(entity) : nullptr; + if (!pickup || pickup->IsShopItem() || pickup->isDead || !pickup->CanReroll()) continue; + if (pickup->variant == PICKUP_COLLECTIBLE && pickup->subtype != 0 && pickup->timeout < 1) + { + isEaten = true; + black_rune_stats_raise(player); + card_poof_spawn(vector_add(pickup->pos, vector_make(0, BLACK_RUNE_POOF_DROP)), nullptr); + pickup->timeout = BLACK_RUNE_PEDESTAL_TIMEOUT; + pickup->RemoveOtherOptions(); + int duplicate = pickup->coopDuplicateIndex; + if (duplicate != -1 && duplicate + 1 < g_game->playerManager.GetNumAlivePlayers()) coopChoices.push_back(pickup); + } + else if (pickup->variant != PICKUP_COLLECTIBLE && pickup->CanReroll()) + { + pickup->Remove(); + player.AddBlueFlies(1, pickup->pos, nullptr); + } + } + + for (Entity_Pickup* choice : coopChoices) + { + int duplicate = choice->coopDuplicateIndex; + Vector position = choice->pos; + choice->Remove(); + int item = g_game->itemPool.GetCollectible(POOL_BOSS, player.dropRNG.Next(), 0, 0, 0); + auto* pedestal = static_cast(g_game->Spawn( + {.position = position, .subType = item, .type = ENTITY_PICKUP, .variant = PICKUP_COLLECTIBLE, + .seed = player.dropRNG.Next()})); + pedestal->coopDuplicateIndex = duplicate + 1; + if (pedestal->coopDuplicateIndex != 0 && pedestal->coopDuplicateIndex != -1) pedestal->cycleCollectibleCount = 0; + pedestal->Update(); + } + + player.cacheFlags |= BLACK_RUNE_CACHE_FLAGS; + player.EvaluateItems(); + player.UseActiveItem({.item = COLLECTIBLE_NECRONOMICON, .flags = USE_NOANIM}); + RoomType roomType = g_game->room->roomType; + if (isEaten && (roomType == ROOM_CHALLENGE || roomType == ROOM_BOSSRUSH)) g_game->ambush.StartChallenge(); + return POCKET_END_ANIMATE; +} + +// V - The Hierophant?: two bone hearts, three when doubled. +static PocketUseEnd reverse_hierophant_use(PocketUse& use) +{ + if (use.isCarBattery) return POCKET_END_RETURN; + for (int i = use.isDoubled ? 3 : 2; i > 0; i--) pocket_pickup_spawn(use, PICKUP_HEART, HEART_BONE); + return POCKET_END_ANIMATE; +} + +// VI - The Lovers?: an item from the room's pool (two when doubled), each one paid with a heart container (else a bone +// heart, else two soul hearts) and a broken heart, which the Lost and Tainted Lost do not take. A versus match draws +// again while its rules ban the item. +static PocketUseEnd reverse_lovers_use(PocketUse& use) +{ + Entity_Player& player = use.player; + Room& room = *g_game->room; + + if (use.isCarBattery) return POCKET_END_RETURN; + for (int i = use.isDoubled ? 2 : 1; i > 0; i--) + { + uint32_t seed = use.rng.Next(); + int item = g_game->itemPool.GetSeededCollectible(seed, 0, *room.descriptor); + while (is_versus_collectible_banned(item)) item = g_game->itemPool.GetSeededCollectible(seed, 0, *room.descriptor); + Vector position = room_free_pickup_position_find({.position = player.pos, .step = 40}); + g_game->Spawn({.position = position, .subType = item, .type = ENTITY_PICKUP, .variant = PICKUP_COLLECTIBLE, + .seed = use.rng.Next()}); + card_poof_spawn(position, nullptr)->SetColor(REVERSE_LOVERS_POOF_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + card_sound_play(SOUND_DEVILROOM_DEAL, REVERSE_LOVERS_VOLUME); + + if (player.maxHearts > 0) player.AddMaxHearts(-2, false); + else if (player.boneHearts > 0) player.AddBoneHearts(-1); + else player.AddSoulHearts(-4, false); + if (player.playerType != PLAYER_THELOST && player.playerType != PLAYER_THELOST_B) player.AddBrokenHearts(1); + player.lastDamageFlags = DAMAGE_DEVIL; + } + return POCKET_END_ANIMATE; +} + +// A puff of dust VII - The Chariot? throws off the player, turning and fading as it drifts. +static void reverse_chariot_dust_spawn(Entity_Player& player) +{ + Vector direction = random_direction(); + Vector velocity = vector_scale(direction, random_unit() * REVERSE_CHARIOT_DUST_SPEED); + uint32_t seed = Random(); + Vector offsetDirection = random_direction(); + Vector position = vector_add(player.pos, vector_scale(offsetDirection, random_unit() * REVERSE_CHARIOT_DUST_SPREAD)); + auto* dust = static_cast(g_game->Spawn( + {.position = position, .velocity = velocity, .type = ENTITY_EFFECT, .variant = EFFECT_DUST_CLOUD, .seed = seed})); + + Vector side = vector_make(velocity.y, -velocity.x); + float turn = vector_dot(vector_sub(dust->pos, player.pos), side) < 0 ? -1 : 1; + dust->rotation = (random_unit() * REVERSE_CHARIOT_DUST_TURN + REVERSE_CHARIOT_DUST_MIN_TURN) * turn; + dust->SetTimeout(random_below(REVERSE_CHARIOT_DUST_FRAMES) + REVERSE_CHARIOT_DUST_FRAMES); + ColorMod color = {{1, 1, 1, random_unit() * REVERSE_CHARIOT_DUST_ALPHA + REVERSE_CHARIOT_DUST_MIN_ALPHA}, {}, {}}; + dust->SetColor(color, -1, COLOR_PRIORITY_DEFAULT, false, true); + dust->Update(); +} + +// VII - The Chariot?: the player turns to stone for a while, the first time with a crash, dust and a grey flash, and one +// time in ten with the cracked look. +static PocketUseEnd reverse_chariot_use(PocketUse& use) +{ + Entity_Player& player = use.player; + + if (!player.temporaryEffects.HasNullEffect(NULLITEM_REVERSE_CHARIOT)) + { + card_sound_play(SOUND_STONE_IMPACT, 1); + game_shake_screen(REVERSE_CHARIOT_SHAKE); + for (int i = 0; i < REVERSE_CHARIOT_DUST_COUNT; i++) reverse_chariot_dust_spawn(player); + player.SetColor(REVERSE_CHARIOT_FLASH, REVERSE_CHARIOT_GREY_FRAMES, COLOR_PRIORITY_DEFAULT, true, true); + } + player.temporaryEffects.RemoveNullEffect(NULLITEM_REVERSE_CHARIOT, 1); + player.temporaryEffects.AddNullEffect(NULLITEM_REVERSE_CHARIOT, true, 1); + if (use.rng.RandomInt(REVERSE_CHARIOT_ALT_ODDS) == 0) + player.AddCostume(g_manager->itemConfig.GetNullItem(NULLITEM_REVERSE_CHARIOT_ALT), false); + return POCKET_END_SKIP_ANIMATION; +} + +// VIII - Justice?: two to four golden chests, up to seven when doubled. +static PocketUseEnd reverse_justice_use(PocketUse& use) +{ + int count = (int)use.rng.RandomInt((use.isDoubled ? 2 : 1) * REVERSE_JUSTICE_SPREAD) + REVERSE_JUSTICE_MIN; + for (int i = 0; i < count; i++) card_pickup_spawn(use, PICKUP_LOCKEDCHEST, 0); + return POCKET_END_ANIMATE; +} + +// The cents IX - The Hermit? gives for a pickup: a pill, card, battery, trinket, soul heart or common key or bomb is +// worth five, a pedestal fifteen, the better hearts, keys and bombs ten or six, the lesser hearts one to three, a sack +// seven. Zero for what it leaves alone. +static int hermit_pickup_value(Entity_Pickup& pickup) +{ + int subType = (int)pickup.subtype; + + switch (pickup.variant) + { + case PICKUP_HEART: + if (subType == HEART_ETERNAL || subType == HEART_GOLDEN) return 10; + if (subType == HEART_BLACK || subType == HEART_BONE || subType == HEART_DOUBLEPACK) return 6; + if (subType == HEART_SOUL) return 5; + if (subType == HEART_HALF_SOUL || subType == HEART_ROTTEN) return 2; + return subType == HEART_HALF ? 1 : 3; + case PICKUP_KEY: + return subType == KEY_DOUBLEPACK || subType == KEY_GOLDEN || subType == KEY_CHARGED ? 10 : 5; + case PICKUP_BOMB: + return subType == BOMB_SUBTYPE_DOUBLEPACK || subType == BOMB_SUBTYPE_GOLDEN || subType == BOMB_SUBTYPE_GIGA ? 10 : 5; + case PICKUP_GRAB_BAG: + return 7; + case PICKUP_PILL: + case PICKUP_LIL_BATTERY: + case PICKUP_TAROTCARD: + case PICKUP_TRINKET: + return 5; + case PICKUP_COLLECTIBLE: + return subType != 0 ? 15 : 0; + } + return 0; +} + +// Spills coins of a kind out of a pickup, each thrown a random way at up to five speed from the pickup's own generator. +static void hermit_coins_spill(Entity_Pickup& pickup, RNG& rng, int subType, int count) +{ + for (; count > 0; count--) + { + uint32_t seed = rng.Next(); + Vector direction = RandomVector(rng.Next()); + Vector velocity = vector_scale(direction, rng.RandomFloat() * REVERSE_HERMIT_COIN_SPEED); + g_game->Spawn({.position = pickup.pos, .velocity = velocity, .subType = subType, .type = ENTITY_PICKUP, + .variant = PICKUP_COIN, .seed = seed}); + } +} + +// IX - The Hermit?: every free pickup that may be rerolled is sold for its worth in nickels and pennies with a golden +// poof (a pedestal is left empty, its options gone). With nothing sold, a penny drops in the middle of the room. +static PocketUseEnd reverse_hermit_use(PocketUse& use) +{ + int sold = 0; + + for (Entity* entity : entity_query(ENTITY_PICKUP, -1)) + { + auto& pickup = static_cast(*entity); + if (!pickup.isExists || pickup.isDead || pickup.IsShopItem() || !pickup.isVisible || pickup.timeout > 0 || + !pickup.CanReroll()) + continue; + int value = hermit_pickup_value(pickup); + if (value == 0) continue; + + RNG rng = rng_make(pickup.initSeed, REVERSE_HERMIT_RNG_SHIFT); + if (value > 9) + { + int nickels = (value - 5) / 5; + value -= nickels * 5; + hermit_coins_spill(pickup, rng, COIN_NICKEL, nickels); + } + hermit_coins_spill(pickup, rng, COIN_PENNY, value); + card_poof_spawn(pickup.pos, nullptr)->SetColor(REVERSE_HERMIT_POOF_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + if (pickup.variant == PICKUP_COLLECTIBLE) pickup.timeout = BLACK_RUNE_PEDESTAL_TIMEOUT; + else pickup.Remove(); + pickup.RemoveOtherOptions(); + sold++; + } + + if (sold != 0) + { + use.rng.Next(); + return POCKET_END_ANIMATE; + } + RNG rng = rng_make(use.rng.Next(), REVERSE_HERMIT_PENNY_SHIFT); + uint32_t seed = rng.Next(); + Vector position = room_free_pickup_position_find({.position = Room::GetCenterPos()}); + g_game->Spawn({.position = position, .subType = COIN_PENNY, .type = ENTITY_PICKUP, .variant = PICKUP_COIN, .seed = seed}); + return POCKET_END_ANIMATE; +} + +// 00704c50 Rerolls the pickups the floor's other rooms keep: a shop's become shop item spots, the others a random +// pickup kind (a heart only one time in five while someone holds Daemon's Tail), all drawn from the global generator. +void game_level_pickups_reroll(Game& game, uint32_t seed) +{ + ItemConfig_Item* tail = g_manager->itemConfig.GetTrinket(TRINKET_DAEMONS_TAIL); + bool isTailShared = tail && tail->HasTags(TAG_LAZ_SHARED_GLOBAL); + + auto isHeartKept = [&](uint32_t& rerollSeed) + { + for (Entity_Player* player : game.playerManager.playerList) + { + if (player->variant != PLAYER_VARIANT_PLAYER) continue; + Entity_Player* holder = player->HasTrinket(TRINKET_DAEMONS_TAIL) ? player : nullptr; + if (!holder && isTailShared && player->backupPlayer && player->backupPlayer->HasTrinket(TRINKET_DAEMONS_TAIL)) + holder = player->backupPlayer; + if (!holder) continue; + rerollSeed ^= rerollSeed >> 5; + rerollSeed ^= rerollSeed << 9; + rerollSeed ^= rerollSeed >> 7; + return rerollSeed % DAEMONS_TAIL_HEART_ODDS == 0; + } + return true; + }; + + for (int index = 0; index < game.nbRooms; index++) + for (EntitySaveState& saved : game.roomList[index].savedEntities) + { + if (saved.type != ENTITY_PICKUP || saved.variant == PICKUP_COLLECTIBLE || + !Entity_Pickup::CanRerollVariant(saved.variant, saved.subtype)) + continue; + saved.subtype = 0; + if (saved.intStorage3 != 0) + { + saved.variant = PICKUP_SHOPITEM; + continue; + } + + uint32_t rerollSeed = seed; + int variant = 0; + do + { + variant = (int)(Random() % 6 + 1) * 10; + if (variant == PICKUP_LOCKEDCHEST) + { + if ((Random() & 1) == 0) variant = PICKUP_HEART; + } + else if (variant == PICKUP_CHEST && Random() % 3 == 0) variant = PICKUP_COIN; + if (Random() % 10 == 0) variant = (int)((Random() & 1) + 3) * 10; + if (Random() % 15 == 0) variant = PICKUP_TAROTCARD; + if (Random() % 15 == 0) variant = PICKUP_PILL; + if (Random() % 20 == 0) + { + variant = PICKUP_TRINKET; + break; + } + } while (variant == PICKUP_HEART && !isHeartKept(rerollSeed)); + saved.variant = variant; + } +} + +// X - Wheel of Fortune?: the screen darkens and shakes, and one of six rolls: the D4 (which also takes the item away), +// the D20, the D20 with the floor's pickups, the D6 with the floor's items, a new floor, or all of the dice for everyone. +static PocketUseEnd reverse_wheel_use(PocketUse& use) +{ + Entity_Player& player = use.player; + Game& game = *g_game; + + game.darknessStrength = 1; + game.darknessTimeout = REVERSE_WHEEL_DARK_FRAMES; + game_shake_screen(REVERSE_WHEEL_SHAKE); + int roll = (int)use.rng.RandomInt(6); + uint32_t seed = use.rng.Next(); + + if (roll == 0) + { + player.UseActiveItem({.item = COLLECTIBLE_D4, .flags = USE_NOANIM | USE_REMOVEACTIVE}); + return POCKET_END_ANIMATE; + } + if (roll == 1 || roll == 2 || roll == 5) + { + player.UseActiveItem({.item = COLLECTIBLE_D20, .flags = USE_NOANIM}); + if (roll != 1) game_level_pickups_reroll(game, seed); + } + if (roll == 3 || roll == 5) + { + game_level_collectibles_reroll(game); + player.UseActiveItem({.item = COLLECTIBLE_D6, .flags = USE_NOANIM}); + } + if (roll == 4) + { + game.seedEffects.ForgetStageSeed((int)game.stage + (game.IsAltPath() ? 1 : 0)); + game.stageTransition.start({.isSameStage = true}); + } + else if (roll == 5) + for (int i = 0; i < (int)game.playerManager.playerList.size(); i++) + { + Entity_Player* each = game.GetPlayer(i); + if (each->variant == PLAYER_VARIANT_PLAYER) + each->UseActiveItem({.item = COLLECTIBLE_D4, .flags = USE_NOANIM | USE_REMOVEACTIVE}); + } + return POCKET_END_ANIMATE; +} + +// XVII - The Stars?: the oldest passive item that may be rerolled is taken away, held up, and the Stars? effect renewed +// to bring two in its place. Without one nothing happens. +static PocketUseEnd reverse_stars_use(PocketUse& use) +{ + Entity_Player& player = use.player; + int count = (int)player.history.historyItems.size(); + + for (int i = 0; i < count; i++) + { + HistoryItem entry = player.history.historyItems[i]; + if (entry.isTrinket || entry.time <= 0 || !player.CanRerollCollectible(entry.id, false)) continue; + ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(entry.id); + if (!item || item->type == ITEM_ACTIVE || player.collectibleCounts[entry.id] <= 0) continue; + + player.RemoveCollectibleByHistoryIndex(i, true); + player.AnimateCollectible(entry.id, "Pickup", "PlayerPickupSparkle"); + player.temporaryEffects.RemoveNullEffect(NULLITEM_REVERSE_STARS, 1); + player.temporaryEffects.AddNullEffect(NULLITEM_REVERSE_STARS, true, 1); + return POCKET_END_SKIP_ANIMATION; + } + return POCKET_END_ANIMATE; +} + +// XIX - The Sun?: the effect renewed, with its giant book the first time. Red heart containers turn into bone hearts +// for the floor, counted to give them back. In a versus match the red hearts turn into bone hearts for good. +static PocketUseEnd reverse_sun_use(PocketUse& use) +{ + Entity_Player& player = use.player; + bool isVersus = g_game->deathmatchManager.is_active(); + + if (!player.temporaryEffects.HasNullEffect(NULLITEM_REVERSE_SUN)) g_game->itemOverlay.Show(GIANTBOOK_REVERSE_SUN, 0, nullptr); + player.temporaryEffects.RemoveNullEffect(NULLITEM_REVERSE_SUN, 1); + player.temporaryEffects.AddNullEffect(NULLITEM_REVERSE_SUN, true, 1); + + if (player.maxHearts > 0 && player.GetHealthType() == HEALTH_DEFAULT && !isVersus) + { + int bones = player.maxHearts / 2; + player.maxHearts = 0; + player.boneHearts += bones; + player.boneHeartsMask = (player.boneHeartsMask << bones) | ((1 << bones) - 1); + player.UpdateHeartDependentEffects(); + player.reverseSunBoneHearts = bones; + return POCKET_END_ANIMATE; + } + if (isVersus) + { + player.boneHearts += player.redHearts; + player.maxHearts = 0; + player.redHearts = 0; + } + return POCKET_END_ANIMATE; +} + +// XXI - The World?: a crawl space opens under the player, with a poof, when it stands on the room's grid. +static PocketUseEnd reverse_world_use(PocketUse& use) +{ + Room& room = *g_game->room; + int index = room.GetGridIndex(use.player.pos); + + if (index < 0) return POCKET_END_ANIMATE; + room.SpawnGridEntity(index, GRID_STAIRS, 0, Random(), 0); + GridEntity* stairs = room.GetGridEntity(index); + if (!stairs || stairs->type != GRID_STAIRS || stairs->variant != 0) return POCKET_END_ANIMATE; + + g_game->SetStateFlag(LEVEL_STATE_DUNGEON_ROCK_BROKEN, true); + card_poof_spawn(room.GetGridPosition(index), nullptr)->Update(); + return POCKET_END_ANIMATE; +} + +// Wild Card: the last pocket item or active used again, unless mimicked: a card or pill as a mimic, an active as owned +// with its data and a Book of Virtues wisp. +static PocketUseEnd wild_card_use(PocketUse& use) +{ + Entity_Player& player = use.player; + + if (use.flags & USE_MIMIC) return POCKET_END_ANIMATE; + switch (player.wildCardItemType) + { + case WILD_CARD_CARD: + player.UseCard(player.wildCardItem, USE_MIMIC | USE_NOANNOUNCER); + break; + case WILD_CARD_PILL: + player.UsePill(player.wildCardItem, player.wildCardVarData, USE_MIMIC | USE_NOANNOUNCER); + if (player.cacheFlags != 0) + { + player.InvalidateCoPlayerItems(); + player.EvaluateItems(); + } + break; + case WILD_CARD_ACTIVE: + player.UseActiveItem({.item = player.wildCardItem, .flags = USE_OWNED | USE_MIMIC | USE_CUSTOMVARDATA, + .varData = player.wildCardVarData}); + player.TriggerBookOfVirtues(player.wildCardItem, 0); + return POCKET_END_SKIP_ANIMATION; + } + return POCKET_END_ANIMATE; +} + +// Soul of Isaac: every pedestal item that is not one of several options (or is free to take) cycles with a second item +// from the room's pool, with a poof. +static PocketUseEnd soul_isaac_use(PocketUse& use) +{ + for (Entity* entity : entity_query(ENTITY_PICKUP, PICKUP_COLLECTIBLE)) + { + auto& pickup = static_cast(*entity); + if (pickup.isDead || pickup.subtype == 0 || (pickup.optionsPickupIndex != 0 && pickup.timeout >= 0) || + !pickup.CanReroll()) + continue; + int item = g_game->itemPool.GetSeededCollectible(use.rng.Next(), 0, *g_game->room->descriptor); + if (pickup.cycleCollectibleCount < CYCLE_COLLECTIBLE_LIMIT) + pickup.cycleCollectibleList[pickup.cycleCollectibleCount++] = item; + card_poof_spawn(pickup.pos, nullptr)->Update(); + } + return POCKET_END_ANIMATE; +} + +// Soul of Cain: every door of the room opens, the missing ones made as red rooms where they may be, and the room keeps +// Dad's Key's effect. +static PocketUseEnd soul_cain_use(PocketUse& use) +{ + Room& room = *g_game->room; + + card_sound_play(SOUND_GOLDENKEY, 1); + for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++) + { + if (g_game->CanSpawnDoorOutline(g_game->currentRoomIdx, slot)) g_game->MakeRedRoomDoor(g_game->currentRoomIdx, slot); + GridEntity_Door* door = room.GetDoor(slot); + if (!door || (door->doorFlags & DOOR_FLAG_MIRROR) || door->TryUnlock(use.player, true)) continue; + door->Open(); + door->TryBlowOpen(false, nullptr); + } + room.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_DADS_KEY, true, 1); + return POCKET_END_ANIMATE; +} + +// Soul of Judas: Dark Arts for a moment with the room paused, its effect and the Judas soul look. +static PocketUseEnd soul_judas_use(PocketUse& use) +{ + Entity_Player& player = use.player; + TemporaryEffect effect(g_manager->itemConfig.GetCollectible(COLLECTIBLE_DARK_ARTS)); + + effect.cooldown = SOUL_JUDAS_FRAMES - effect.cooldown; + player.temporaryEffects.AddEffect(effect, true, 1); + player.temporaryEffects.AddNullEffect(NULLITEM_SOUL_JUDAS, true, 1); + g_game->room->SetPauseTimer(SOUL_JUDAS_FRAMES); + player.UseActiveItem({.item = COLLECTIBLE_DARK_ARTS, .flags = USE_NOANIM | USE_ALLOWNONMAIN}); + return POCKET_END_ANIMATE; +} + +// Soul of ???: the effect, two farts and a pool of poop creep that follows the player. +static PocketUseEnd soul_bluebaby_use(PocketUse& use) +{ + Entity_Player& player = use.player; + + player.temporaryEffects.AddNullEffect(NULLITEM_SOUL_BLUEBABY, true, 1); + card_sound_play(SOUND_FART, 1); + int sound = SOUND_SINK_DRAIN_GURGLE; + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound, {.pitch = SOUL_BLUEBABY_PITCH}); + auto* creep = static_cast(g_game->Spawn({.position = player.pos, .spawner = &player, .subType = 1, + .type = ENTITY_EFFECT, .variant = EFFECT_CREEP_LIQUID_POOP, + .seed = Random()})); + creep->SetTimeout(SOUL_BLUEBABY_CREEP_FRAMES); + creep->parent = &player; + creep->Update(); + return POCKET_END_ANIMATE; +} + +// Soul of Eve: fifteen dead birds around the room (twice as strong with BFFS!), each leaving after a while. +static PocketUseEnd soul_eve_use(PocketUse& use) +{ + Room& room = *g_game->room; + + for (int i = 0; i < SOUL_EVE_BIRDS; i++) + { + Vector center = vector_add(room.topLeftPos, vector_scale(vector_sub(room.bottomRightPos, room.topLeftPos), 0.5f)); + float margin = -SOUL_EVE_MIN_MARGIN - random_unit() * SOUL_EVE_MARGIN_SPREAD; + Vector position = room.GetClampedPosition(vector_add(center, vector_scale(random_direction(), SOUL_EVE_FAR)), margin); + auto* bird = static_cast(g_game->Spawn( + {.position = position, .spawner = &use.player, .type = ENTITY_EFFECT, .variant = EFFECT_DEAD_BIRD, .seed = Random()})); + bird->SetCollisionDamage(use.player.HasCollectible(COLLECTIBLE_BFFS) ? 2 : 1); + bird->SetTimeout(random_below(SOUL_EVE_EXTRA_FRAMES) + SOUL_EVE_MIN_FRAMES); + bird->state = random_below(SOUL_EVE_START_STATES); + bird->Update(); + } + return POCKET_END_ANIMATE; +} + +// Soul of Samson: Berserk! for ten seconds, with its roar. +static PocketUseEnd soul_samson_use(PocketUse& use) +{ + TemporaryEffect effect(g_manager->itemConfig.GetCollectible(COLLECTIBLE_BERSERK)); + + effect.cooldown = SOUL_SAMSON_FRAMES; + use.player.temporaryEffects.AddEffect(effect, true, 1); + card_sound_play(SOUND_BERSERK_START, 1); + card_sound_play(SOUND_ISAAC_ROAR, 1); + g_game->UpdateBackwardsPathStages(); + return POCKET_END_ANIMATE; +} + +// Soul of Lazarus: the player dies at once to come back with the revival effect, leaving no cause of death. +static PocketUseEnd soul_lazarus_use(PocketUse& use) +{ + Entity_Player& player = use.player; + + player.temporaryEffects.RemoveNullEffect(NULLITEM_LAZARUS_SOUL_REVIVE, -1); + player.temporaryEffects.AddNullEffect(NULLITEM_LAZARUS_SOUL_REVIVE, true, 1); + player.Kill(EntityRef()); + player.lastDamageFlags = 0; + player.lastDamageSource.type = 0; + player.lastDamageSource.variant = 0; + return POCKET_END_SKIP_ANIMATION; +} + +// Soul of Eden: the D6 and the D20 at once, their items drawn as with Chaos. +static PocketUseEnd soul_eden_use(PocketUse& use) +{ + TemporaryEffects& roomEffects = g_game->room->temporaryEffects; + + roomEffects.AddCollectibleEffect(COLLECTIBLE_CHAOS, true, 1); + use.player.UseActiveItem({.item = COLLECTIBLE_D6, .flags = USE_NOANIM}); + use.player.UseActiveItem({.item = COLLECTIBLE_D20, .flags = USE_NOANIM}); + roomEffects.RemoveCollectibleEffect(COLLECTIBLE_CHAOS, -1); + return POCKET_END_ANIMATE; +} + +// Soul of the Lost: the player leaves a body and plays the Lost for the room, with a Holy Mantle unless already the Lost. +static PocketUseEnd soul_lost_use(PocketUse& use) +{ + Entity_Player& player = use.player; + + player.spawn_ghost_corpse(); + player.temporaryEffects.RemoveNullEffect(NULLITEM_LOST_CURSE, -1); + player.temporaryEffects.AddNullEffect(NULLITEM_LOST_CURSE, true, 2); + if (player.playerType == PLAYER_THELOST) return POCKET_END_ANIMATE; + player.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_HOLY_MANTLE, true, 1); + player.PlayCollectibleAnim(COLLECTIBLE_HOLY_MANTLE, true, "Shimmer", -1); + return POCKET_END_ANIMATE; +} + +// Soul of Lilith: a familiar from the baby shop's pool for good (a unique one only when not held yet), held up, with +// its name shown unless the use hides the HUD. A versus match leaves out the ones its rules ban. +static PocketUseEnd soul_lilith_use(PocketUse& use) +{ + Entity_Player& player = use.player; + std::vector familiars; + + for (PoolItem& entry : g_game->itemPool.GetPool(POOL_BABY_SHOP).poolList) + { + if (!entry.isUnlocked || is_versus_collectible_banned(entry.itemId)) continue; + ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(entry.itemId); + if (item && item->type == ITEM_FAMILIAR && (!item->HasTags(TAG_UNIQUE_FAMILIAR) || !player.HasCollectible(item->id))) + familiars.push_back(item->id); + } + if (familiars.empty()) return POCKET_END_ANIMATE; + + ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(familiars[use.rng.RandomInt(familiars.size())]); + if (!(use.flags & USE_NOHUD)) g_game->hud.ShowItemText(&player, item); + card_sound_play(SOUND_POWERUP1, SOUL_LILITH_VOLUME); + player.AnimateCollectible(item->id, "Pickup", "PlayerPickupSparkle"); + player.SetQueuedItem({.item = item, .charge = -1, .itemPoolType = POOL_NONE}); + return POCKET_END_SKIP_ANIMATION; +} + +// Soul of the Keeper: one to twenty-five pennies, dropping one after another. +static PocketUseEnd soul_keeper_use(PocketUse& use) +{ + int count = (int)use.rng.RandomInt(SOUL_KEEPER_COINS) + 1; + + for (int i = 0; i < count; i++) + { + uint32_t seed = use.rng.Next(); + Vector position = room_free_pickup_position_find({.position = use.player.pos, .step = 40}); + auto* coin = static_cast(g_game->Spawn( + {.position = position, .spawner = &use.player, .type = ENTITY_PICKUP, .variant = PICKUP_COIN, .seed = seed})); + coin->dropDelay = i; + coin->Update(); + } + return POCKET_END_ANIMATE; +} + +// Soul of Apollyon: fifteen random locusts around the player, ten in a versus match. +static PocketUseEnd soul_apollyon_use(PocketUse& use) +{ + int count = g_game->deathmatchManager.is_active() ? SOUL_APOLLYON_VERSUS_LOCUSTS : SOUL_APOLLYON_LOCUSTS; + + for (int i = 0; i < count; i++) + { + uint32_t seed = Random(); + int locust = (int)use.rng.RandomInt(SOUL_APOLLYON_KINDS) + 1; + Vector position = vector_add(use.player.pos, random_direction()); + g_game->Spawn({.position = position, .spawner = &use.player, .subType = locust, .type = ENTITY_FAMILIAR, + .variant = Entity_Familiar::BLUE_FLY, .seed = seed}) + ->Update(); + } + return POCKET_END_ANIMATE; +} + +// The twin a soul stone brings for the room under the player's controller, just below it, with its effect. +static Entity_Player* soul_twin_spawn(Entity_Player& player, int playerType, int nullItem) +{ + Entity_Player* twin = g_game->playerManager.SpawnCoPlayer2(playerType); + + twin->SetControllerIndex(player.controllerIndex, false); + twin->parent = &player; + twin->pos = vector_add(player.pos, vector_make(0, SOUL_TWIN_DROP)); + twin->temporaryEffects.AddNullEffect(nullItem, true, 1); + twin->init_forgotten_twin(); + twin->InitPostLevelInitStats(); + return twin; +} + +// Soul of the Forgotten: the Forgotten joins for the room with a bone heart filled. +static PocketUseEnd soul_forgotten_use(PocketUse& use) +{ + Entity_Player* twin = soul_twin_spawn(use.player, PLAYER_THEFORGOTTEN, NULLITEM_SOUL_FORGOTTEN); + + twin->AddBoneHearts(1); + twin->AddHearts(2, true, false); + card_poof_spawn(twin->pos, use.player.forgottenBody)->Update(); + return POCKET_END_ANIMATE; +} + +// Soul of Bethany: six item wisps of random actives, Book of Virtues' for an item that has no wisp. +static PocketUseEnd soul_bethany_use(PocketUse& use) +{ + ItemConfig& config = g_manager->itemConfig; + + for (int i = 0; i < SOUL_BETHANY_WISPS; i++) + { + int id = (int)use.player.GetCollectibleRNG(COLLECTIBLE_JAR_OF_WISPS).RandomInt((uint32_t)config.collectibles.size() - 1) + 1; + ItemConfig_Item* item = config.GetCollectible(id); + if (!item || !ItemConfig::IsValidCollectible(id) || item->type != ITEM_ACTIVE) + item = config.GetCollectible(COLLECTIBLE_BOOK_OF_VIRTUES); + if (!item->wispConfig || item->wispConfig->count < 1) item = config.GetCollectible(COLLECTIBLE_BOOK_OF_VIRTUES); + use.player.AddWisp(item->id, use.player.pos, true, false); + } + card_sound_play(SOUND_CANDLE_LIGHT, 1); + return POCKET_END_ANIMATE; +} + +// Soul of Jacob: Esau joins for the room, taking a copy of each passive item the player holds that may be rerolled, +// drawn again from the pool it came from (never Birthright, ten tries) and listed in his own history. +static PocketUseEnd soul_jacob_use(PocketUse& use) +{ + Entity_Player& player = use.player; + Entity_Player* esau = soul_twin_spawn(player, PLAYER_ESAU, NULLITEM_SOUL_JACOB); + RNG& rng = player.GetCollectibleRNG(COLLECTIBLE_ESAU_JR); + std::vector items = player.history.historyItems; + + esau->history.isLocked = true; + for (HistoryItem entry : items) + { + if (entry.isTrinket || player.collectibleCounts[entry.id] <= 0) continue; + ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(entry.id); + if (item->type == ITEM_ACTIVE || !player.CanRerollCollectible(entry.id, false)) continue; + + entry.id = 0; + for (int tries = 0; tries < SOUL_JACOB_TRIES && entry.id == 0; tries++) + { + entry.id = g_game->itemPool.GetCollectible((ItemPoolType)entry.itemPoolType, rng.Next(), SOUL_JACOB_DRAW_FLAGS, 0, 0); + if (entry.id == COLLECTIBLE_BIRTHRIGHT) entry.id = 0; + } + if (entry.id == 0) continue; + esau->AddCollectible(entry.id, 0, true, 0, 0, 0); + esau->history.historyItems.push_back(entry); + } + esau->history.isLocked = false; + card_poof_spawn(esau->pos, player.forgottenBody)->Update(); + return POCKET_END_ANIMATE; +} + +// XVI - The Tower?: rocks fall in seven waves, each around a random free cell of the room (an open middle cell ten times +// as likely), never on a portal or a special floor. A cell left near a fallen rock is unlikely to be picked again. +static PocketUseEnd reverse_tower_use(PocketUse& use) +{ + Room& room = *g_game->room; + RNG rng = rng_make(use.rng.Next(), REVERSE_TOWER_RNG_SHIFT); + int width = room.gridWidth; + int height = room.gridHeight; + std::vector weights(width * height); + std::vector portals = entity_query(ENTITY_EFFECT, EFFECT_PORTAL_TELEPORT); + + for (int cell = 0; cell < width * height; cell++) + { + if (!room.IsPositionInRoom(room.GetGridPosition(cell), 0) || room.GetGridCollision(cell) != 0) continue; + GridEntity* grid = room.GetGridEntity(cell); + if (grid && is_grid_floor_special(grid->type)) continue; + if (std::ranges::any_of(portals, [&](Entity* portal) { return room.GetGridIndex(portal->pos) == cell; })) continue; + weights[cell] = REVERSE_TOWER_FREE_WEIGHT; + } + for (int column = 1; column < width - 1; column++) + for (int row = 1; row < height - 1; row++) + { + int cell = row * width + column; + if (weights[cell] && weights[cell + 1] && weights[cell - 1] && weights[cell + width] && weights[cell - width]) + weights[cell] = REVERSE_TOWER_OPEN_WEIGHT; + } + + for (int delay = 0; delay < REVERSE_TOWER_LAST_FRAME; delay += REVERSE_TOWER_WAVE_FRAMES) + { + WeightedOutcomePicker picker; + for (int cell = 0; cell < width * height; cell++) + if (weights[cell] != 0) picker.AddOutcomeWeight(cell, weights[cell]); + if (picker.outcomes.empty()) break; + + int picked = picker.PickOutcome(rng); + float jitterY = rng.RandomFloat() * REVERSE_TOWER_JITTER - REVERSE_TOWER_JITTER / 2; + float jitterX = rng.RandomFloat() * REVERSE_TOWER_JITTER - REVERSE_TOWER_JITTER / 2; + Vector center = vector_add(room.GetGridPosition(picked), vector_make(jitterX, jitterY)); + int pickedColumn = picked % width; + int pickedRow = picked / width; + for (int column = std::max(pickedColumn - REVERSE_TOWER_REACH, 0); column <= std::min(pickedColumn + REVERSE_TOWER_REACH, width - 1); column++) + for (int row = std::max(pickedRow - REVERSE_TOWER_REACH, 0); row <= std::min(pickedRow + REVERSE_TOWER_REACH, height - 1); row++) + { + int cell = row * width + column; + if (weights[cell] == 0) continue; + if (vector_length_squared(vector_sub(room.GetGridPosition(cell), center)) > REVERSE_TOWER_RADIUS_SQUARED) + { + weights[cell] = REVERSE_TOWER_SPENT_WEIGHT; + continue; + } + weights[cell] = 0; + uint32_t seed = rng.Next(); + auto* rock = static_cast(g_game->Spawn({.position = room.GetGridPosition(cell), .spawner = &use.player, + .subType = 1, .type = ENTITY_EFFECT, + .variant = EFFECT_REVERSE_EXPLOSION, .seed = seed})); + rock->SetTimeout(delay); + rock->Update(); + } + auto* fall = static_cast(g_game->Spawn({.position = center, .spawner = &use.player, .type = ENTITY_EFFECT, + .variant = EFFECT_REVERSE_EXPLOSION, .seed = rng.Next()})); + fall->SetTimeout(delay); + fall->Update(); + } + return POCKET_END_ANIMATE; +} + // Runs a card's own effect. The ones a car battery's second use skips return at once for it. The cards not written // yet stop the game. PocketUseEnd card_effect_run(PocketUse& use, int card) @@ -977,6 +1875,69 @@ PocketUseEnd card_effect_run(PocketUse& use, int card) case CARD_QUEEN_OF_HEARTS: for (int i = (int)use.rng.RandomInt(20) + 1; i > 0; i--) pocket_pickup_spawn(use, PICKUP_HEART, HEART_RED); return POCKET_END_ANIMATE; + case RUNE_BLANK: + return blank_rune_use(use); + case RUNE_BLACK: + return black_rune_use(use); + case CARD_REVERSE_HIEROPHANT: + return reverse_hierophant_use(use); + case CARD_REVERSE_LOVERS: + return reverse_lovers_use(use); + case CARD_REVERSE_CHARIOT: + return reverse_chariot_use(use); + case CARD_REVERSE_JUSTICE: + return reverse_justice_use(use); + case CARD_REVERSE_HERMIT: + return reverse_hermit_use(use); + case CARD_REVERSE_WHEEL_OF_FORTUNE: + return reverse_wheel_use(use); + case CARD_REVERSE_TOWER: + return reverse_tower_use(use); + case CARD_REVERSE_STARS: + return reverse_stars_use(use); + case CARD_REVERSE_SUN: + return reverse_sun_use(use); + case CARD_REVERSE_WORLD: + return reverse_world_use(use); + case CARD_WILD: + return wild_card_use(use); + case CARD_SOUL_ISAAC: + return soul_isaac_use(use); + case CARD_SOUL_MAGDALENE: + use.player.temporaryEffects.AddNullEffect(NULLITEM_SOUL_MAGDALENE, true, 1); + return POCKET_END_ANIMATE; + case CARD_SOUL_CAIN: + return soul_cain_use(use); + case CARD_SOUL_JUDAS: + return soul_judas_use(use); + case CARD_SOUL_BLUEBABY: + return soul_bluebaby_use(use); + case CARD_SOUL_EVE: + return soul_eve_use(use); + case CARD_SOUL_SAMSON: + return soul_samson_use(use); + case CARD_SOUL_AZAZEL: + use.player.megaBlastDuration = g_game->deathmatchManager.is_active() ? SOUL_AZAZEL_VERSUS_FRAMES : SOUL_AZAZEL_FRAMES; + use.player.AddCostume(g_manager->itemConfig.GetNullItem(NULLITEM_MEGABLAST), false); + return POCKET_END_ANIMATE; + case CARD_SOUL_LAZARUS: + return soul_lazarus_use(use); + case CARD_SOUL_EDEN: + return soul_eden_use(use); + case CARD_SOUL_LOST: + return soul_lost_use(use); + case CARD_SOUL_LILITH: + return soul_lilith_use(use); + case CARD_SOUL_KEEPER: + return soul_keeper_use(use); + case CARD_SOUL_APOLLYON: + return soul_apollyon_use(use); + case CARD_SOUL_FORGOTTEN: + return soul_forgotten_use(use); + case CARD_SOUL_BETHANY: + return soul_bethany_use(use); + case CARD_SOUL_JACOB: + return soul_jacob_use(use); } if (card >= (int)g_manager->itemConfig.cards.size()) log_printf(LOG_WARN, "Warning: Card %d don't exist\n", card); else reconstruction_missing(("Entity_Player::UseCard 007b2230 (card " + std::to_string(card) + ")").c_str()); diff --git a/src/entity_player_characters.cpp b/src/entity_player_characters.cpp index 4ec851f..08b3c19 100644 --- a/src/entity_player_characters.cpp +++ b/src/entity_player_characters.cpp @@ -20,7 +20,6 @@ #include #include -constexpr uint32_t CACHE_TWIN_SPEED = 0x80000000; constexpr int CHARGE_STORE_MAX = 99; constexpr int SOUL_CHARGE_CONSUMABLE = 0x20; constexpr int BLOOD_CHARGE_CONSUMABLE = 0x100; @@ -1193,3 +1192,134 @@ void tainted_magdalene_hug(Entity_Player& player, Entity& collider) club->Update(); player.maggySwingCooldown = MAGGY_HUG_FRAMES; } + +// Cambion Conception's familiars by the flags conceptionFamiliarFlags keeps (Leech to Succubus, then Lil Abaddon and +// Twisted Pair once unlocked), the stages its hits pass, and Immaculate Conception's stage size and costume stages. +constexpr std::array CAMBION_FAMILIAR_FLAGS = {0x1, 0x2, 0x4, 0x8, 0x10, 0x20}; +constexpr uint32_t CAMBION_LIL_ABADDON_FLAG = 0x800; +constexpr uint32_t CAMBION_TWISTED_PAIR_FLAG = 0x1000; +constexpr int ACHIEVEMENT_LIL_ABADDON = 455; +constexpr int ACHIEVEMENT_TWISTED_PAIR = 502; +constexpr std::array CAMBION_STAGE_HITS = {15, 30, 60, 90}; +constexpr int CAMBION_LAST_STAGE_END = 99; +constexpr int CAMBION_COSTUME_STEP = 10; +constexpr int CAMBION_LAST_COSTUME_STEP = 3; +constexpr int CAMBION_FIRST_COSTUME_STEP = 5; +constexpr int IMMACULATE_COSTUME_STEP = 5; +constexpr int IMMACULATE_COSTUME_STEP_VERSUS = 20; +constexpr int IMMACULATE_STAGE_END = 15; +constexpr int IMMACULATE_STAGE_END_VERSUS = 60; +constexpr std::array CAMBION_COSTUMES = { + "gfx/characters/costumes/costume_412_cambionconception_stage1.png", + "gfx/characters/costumes/costume_412_cambionconception_stage2.png", + "gfx/characters/costumes/costume_412_cambionconception_stage3.png"}; +constexpr std::array IMMACULATE_COSTUMES = { + "gfx/characters/costumes/costume_413_immaculateconception_stage1.png", + "gfx/characters/costumes/costume_413_immaculateconception_stage2.png", + "gfx/characters/costumes/costume_413_immaculateconception_stage3.png"}; + +// 007c9080 How many of Cambion Conception's stages the player's hits passed (15, 30, 60 and 90 hits). +static int cambion_stage_get(const Entity_Player& player) +{ + return (int)std::ranges::count_if(CAMBION_STAGE_HITS, [&](int hits) { return player.cambionConceptionState >= hits; }); +} + +// 007c90b0 Cambion Conception's costume stage: a step every five hits up to fifteen, then every ten within each later +// stage, and every three past ninety. +int Entity_Player::GetCambionPregnancyLevel() +{ + int hits = cambionConceptionState; + if (hits < CAMBION_STAGE_HITS[0]) return hits / CAMBION_FIRST_COSTUME_STEP; + if (hits < CAMBION_STAGE_HITS[1]) return (hits - CAMBION_STAGE_HITS[0]) / CAMBION_FIRST_COSTUME_STEP; + if (hits < CAMBION_STAGE_HITS[2]) return (hits - CAMBION_STAGE_HITS[1]) / CAMBION_COSTUME_STEP; + if (hits < CAMBION_STAGE_HITS[3]) return (hits - CAMBION_STAGE_HITS[2]) / CAMBION_COSTUME_STEP; + if (hits < CAMBION_LAST_STAGE_END) return (hits - CAMBION_STAGE_HITS[3]) / CAMBION_LAST_COSTUME_STEP; + return 0; +} + +// 007c7d70 Dresses the player in the conception's costume for its stage, in the player's skin colour. +// The original reads past Immaculate Conception's costumes on a wrong state. This keeps to the last one. +void Entity_Player::trigger_immaculate_conception(bool isCambion) +{ + std::string_view costume; + if (isCambion) costume = CAMBION_COSTUMES[GetCambionPregnancyLevel()]; + else + { + bool isVersus = g_game->deathmatchManager.is_active(); + int step = isVersus ? IMMACULATE_COSTUME_STEP_VERSUS : IMMACULATE_COSTUME_STEP; + if (immaculateConceptionState >= (isVersus ? IMMACULATE_STAGE_END_VERSUS : IMMACULATE_STAGE_END)) + KAGE_LogMessage(LOG_ASSERT, (uint8_t*)"[err] Immaculate has a wrong state!"); + costume = IMMACULATE_COSTUMES[std::min(immaculateConceptionState / step, (int)IMMACULATE_COSTUMES.size() - 1)]; + } + std::string path = costume_path_apply_skin_color(std::string(costume), bodyColor, playerType, nullptr, nullptr); + int item = isCambion ? COLLECTIBLE_CAMBION_CONCEPTION : COLLECTIBLE_IMMACULATE_CONCEPTION; + ReplaceCostumeSprite(g_manager->itemConfig.GetCollectible(item), path); +} + +// Part of 007729d0: Cambion Conception counts the hit. Passing a stage gives a familiar not yet given (from a random +// start), and a new costume stage redresses the player. +void cambion_conception_hit(Entity_Player& player) +{ + int stage = cambion_stage_get(player); + int costume = player.GetCambionPregnancyLevel(); + player.cambionConceptionState++; + if (stage != cambion_stage_get(player)) + { + std::vector flags(CAMBION_FAMILIAR_FLAGS.begin(), CAMBION_FAMILIAR_FLAGS.end()); + if (g_manager->persistentGameData.Unlocked(ACHIEVEMENT_LIL_ABADDON)) flags.push_back(CAMBION_LIL_ABADDON_FLAG); + if (g_manager->persistentGameData.Unlocked(ACHIEVEMENT_TWISTED_PAIR)) flags.push_back(CAMBION_TWISTED_PAIR_FLAG); + uint32_t start = player.GetCollectibleRNG(COLLECTIBLE_CAMBION_CONCEPTION).RandomInt((uint32_t)flags.size()); + for (size_t i = 0; i < flags.size(); i++) + { + uint32_t flag = flags[(start + i) % flags.size()]; + if (player.conceptionFamiliarFlags & flag) continue; + + int sound = SOUND_CAMBION_CONCEPTION; + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound); + player.conceptionFamiliarFlags |= flag; + player.cacheFlags |= CACHE_FAMILIARS; + player.EvaluateItems(); + break; + } + } + if (costume != player.GetCambionPregnancyLevel()) player.trigger_immaculate_conception(true); +} + +// Birthright's lasting gains: Magdalene's, Keeper's and Tainted Magdalene's heart container, Lazarus risen's Red Stew +// time, the slot Tainted Forgotten's Recall takes and Tainted Bethany's effect count. +constexpr int BIRTHRIGHT_HEARTS = 2; +constexpr int BIRTHRIGHT_RED_STEW_FRAMES = 1800; +constexpr int BIRTHRIGHT_RECALL_SLOT = 2; +constexpr int BIRTHRIGHT_BETHANY_EFFECTS = 4; + +// Part of 0075f0e0: what Birthright does as it is picked up, by character. Judas's Book of Belial swap, Eden's three +// items and Jacob and Esau's shared items are not reconstructed yet. +void birthright_gain(Entity_Player& player, bool isFirstTime) +{ + switch (player.playerType) + { + case PLAYER_MAGDALENE: + case PLAYER_KEEPER: + case PLAYER_MAGDALENE_B: + if (!isFirstTime) return; + player.AddMaxHearts(BIRTHRIGHT_HEARTS, false); + player.AddHearts(BIRTHRIGHT_HEARTS, false, false); + return; + case PLAYER_EVE: return player.UpdateHeartDependentEffects(); + case PLAYER_LAZARUS2: + if (isFirstTime) player.redStewBonusDuration = BIRTHRIGHT_RED_STEW_FRAMES; + return; + case PLAYER_EDEN_B: player.edenBirthrightFrame = g_game->frameCount + 1; return; + case PLAYER_THEFORGOTTEN_B: return player.SetPocketActiveItem(COLLECTIBLE_RECALL, BIRTHRIGHT_RECALL_SLOT, false); + case PLAYER_BETHANY_B: + if (isFirstTime) player.temporaryEffects.AddNullEffect(NULLITEM_BETHANY_B_BIRTHRIGHT, false, BIRTHRIGHT_BETHANY_EFFECTS); + return; + case PLAYER_JUDAS: + case PLAYER_BLACKJUDAS: + case PLAYER_EDEN: + case PLAYER_JACOB: + case PLAYER_ESAU: + reconstruction_missing("Entity_Player::AddCollectible 0075f0e0 (this character's Birthright)"); + } +} diff --git a/src/entity_player_characters.h b/src/entity_player_characters.h index 27b9b21..66ae580 100644 --- a/src/entity_player_characters.h +++ b/src/entity_player_characters.h @@ -56,6 +56,12 @@ void tainted_eve_babylon_try(Entity_Player& player); ButtonAction twin_button_action(Entity_Player& player, TwinButton button); bool is_twin_button_blocked(Entity_Player& player, TwinButton button); +// Birthright's pickup effect by character (part of 0075f0e0). +void birthright_gain(Entity_Player& player, bool isFirstTime); + +// Cambion Conception's count of hits (part of 007729d0). +void cambion_conception_hit(Entity_Player& player); + // The end of a death that revived the first of the pair (007a1090). void revived_players_settle(std::vector& players, int oldType); diff --git a/src/entity_player_crafting.cpp b/src/entity_player_crafting.cpp index 29de210..e83fc6b 100644 --- a/src/entity_player_crafting.cpp +++ b/src/entity_player_crafting.cpp @@ -580,8 +580,7 @@ void bag_of_crafting_craft(Entity_Player& player) } } 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}); + player.SetQueuedItem({item, item->initCharge, 0, 0, g_game->itemPool.GetFirstItemPoolForCollectible(item->id)}); if (player.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES)) player.AddWisp(Entity_Familiar::GetRandomWisp(&player.GetCollectibleRNG(COLLECTIBLE_BAG_OF_CRAFTING)), player.pos, false, false); diff --git a/src/entity_player_damage.cpp b/src/entity_player_damage.cpp index 403fc18..46e5e50 100644 --- a/src/entity_player_damage.cpp +++ b/src/entity_player_damage.cpp @@ -18,7 +18,6 @@ constexpr int COLLECTIBLE_BINKY = 438; constexpr int COLLECTIBLE_CONE_HEAD = 457; -constexpr int COLLECTIBLE_DULL_RAZOR = 486; constexpr int COLLECTIBLE_JELLY_BELLY = 690; constexpr int COLLECTIBLE_MARBLES = 538; constexpr int COLLECTIBLE_METAL_PLATE = 449; @@ -28,7 +27,6 @@ constexpr int TRINKET_CROW_HEART = 107; constexpr int TRINKET_FINGER_BONE = 128; constexpr int TRINKET_SWALLOWED_M80 = 178; constexpr int TRINKET_WALNUT = 108; -constexpr int NULLITEM_BOOMERANG = 30; constexpr int NULLITEM_DOUBLE_DAMAGE = 29; constexpr int NULLITEM_SHACKLES_GHOST = 101; constexpr int SAMSON_B_HIT_CHARGE = 10000; @@ -67,7 +65,6 @@ constexpr int SOUND_BOSS_DELAY_MIN = 50; 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; @@ -128,7 +125,6 @@ constexpr int EVIL_CHARM_GRID_VARIANT = 10000; // The temporary effects that make the player invincible to any hit: Gamekid, My Little Unicorn, Unicorn Stump and // Teleport. constexpr int INVINCIBLE_EFFECTS[] = {93, 77, 298, 44}; -constexpr int COLLECTIBLE_DARK_ARTS = 705; constexpr int NULLITEM_INVINCIBLE_SHIELD = 59; constexpr int BLOOD_DONATION_VARIANT = 2; constexpr int BLOOD_BANK_VARIANT = 5; @@ -984,8 +980,7 @@ void Entity_Player::PlayExtraAnimation(std::string_view animation, bool) // 007c36b0 Puts away what the player holds up for an item: its costumes for the hold, and the item over its head. void Entity_Player::ResetItemState() { - if (itemState == COLLECTIBLE_SHOOP_DA_WHOOP) - reconstruction_missing("Entity_Player::ResetItemState 007c36b0 (TryRemoveCollectibleCostume)"); + if (itemState == COLLECTIBLE_SHOOP_DA_WHOOP) TryRemoveCollectibleCostume(COLLECTIBLE_SHOOP_DA_WHOOP, false); else if (itemState == COLLECTIBLE_BOOMERANG) RemoveCostume(g_manager->itemConfig.GetNullItem(NULLITEM_BOOMERANG)); if (variant == PLAYER_VARIANT_PLAYER && !isCoopGhost) diff --git a/src/entity_player_death.cpp b/src/entity_player_death.cpp index 01b086b..20a12f2 100644 --- a/src/entity_player_death.cpp +++ b/src/entity_player_death.cpp @@ -21,10 +21,7 @@ constexpr int TRINKET_BROKEN_ANKH = 28; constexpr int TRINKET_LOCUST_OF_WRATH = 113; constexpr int TRINKET_LOCUST_OF_CONQUEST = 117; constexpr int NULLITEM_BATWING_WINGS = 40; -constexpr int NULLITEM_LAZARUS_SOUL_REVIVE = 113; -constexpr int CARD_SOUL_LAZARUS = 89; constexpr int ACHIEVEMENT_THE_LOST = 82; -constexpr int BABY_FOUND_SOUL = 59; constexpr int CLOT_SUBTYPE_UNCOUNTED = 7; constexpr int SPECIAL_DAILY_SHUFFLED_ITEMS = 7; @@ -369,7 +366,7 @@ bool Entity_Player::FlushQueueItem() else if (queued.item->type != ITEM_NULL) { if (isShuffledDaily) reconstruction_missing("Entity_Player::FlushQueueItem 0075e1d0 (a shuffled daily's item)"); - AddCollectible(queued.item->id, queued.charge, isFirstTime, 0, queued.varData); + AddCollectible(queued.item->id, queued.charge, isFirstTime, 0, queued.varData, queued.itemPoolType); } try_trigger_astral_projection(); return true; diff --git a/src/entity_player_evaluate.cpp b/src/entity_player_evaluate.cpp index f7b505b..ebae5ee 100644 --- a/src/entity_player_evaluate.cpp +++ b/src/entity_player_evaluate.cpp @@ -59,10 +59,6 @@ constexpr int COOP_BUFF_SPEED = 2; constexpr int COOP_BUFF_RANGE = 3; constexpr int COOP_BUFF_LUCK = 4; -// The run states the evaluation is reconstructed for: the stat changes of other characters, effects, seeds, -// challenges, procedural items, wisps and the items below stop the game until reached. -// Candy Heart, Soul Locket, Rock Bottom, the pill items, Mega Mush, Berserk!, Jupiter and Dogma. -constexpr std::array EVALUATION_UNHANDLED_ITEMS = {671, 686, 562, 654, 625, 704, 594, 633, 556}; // The constants of the other sections: the collectibles, trinkets, null items and characters they ask about. constexpr int PILL_TEARS_UP = 16; @@ -70,10 +66,6 @@ constexpr int PILL_LARGER = 32; constexpr int PILL_SMALLER = 33; constexpr int COOP_BUFF_SMALLER = 5; constexpr int COOP_BUFF_LARGER = 6; -constexpr int BABY_SKIN_SPOON = 4; -constexpr int BABY_SKIN_BONE = 57; -constexpr int BABY_SKIN_GHOST_A = 58; -constexpr int BABY_SKIN_GHOST_B = 59; constexpr int NULLITEM_SPIRIT_SHACKLES_SOUL = 101; constexpr int COLLECTIBLE_2SPOOKY = 554; constexpr int SPRITE_SCALE_UNLOCK = 3; @@ -98,6 +90,20 @@ constexpr int PURITY_DAMAGE = 0; constexpr int PURITY_TEARS = 1; constexpr int PURITY_SPEED = 2; constexpr int PURITY_RANGE = 3; +constexpr float BLOOD_RIGHTS_LUST_CAP = 999; +constexpr float BABY_UNARMED_FIRE_DELAY = 10; +constexpr float CHALLENGE_MAX_DAMAGE = 100; +constexpr float CHALLENGE_MIN_SHOT_SPEED = 1; +constexpr float CHALLENGE_BIG_RANGE = 400; +constexpr float SEEDED_SHOT_SPEED = 3; +constexpr float SEEDED_FAR_RANGE = 200; +constexpr float GHOST_DAMAGE_SCALE = 0.25f; +constexpr float JUPITER_SLOW = -0.3f; +constexpr float JUPITER_FAST = 0.2f; +constexpr float DOGMA_MIN_SPEED = 1.1f; +constexpr int DAILY_LUCKY = 23; +constexpr int DAILY_SLOW = 43; +constexpr float DAILY_LUCK_BONUS = 50; // Whether the player owns any of the listed collectibles. static bool is_owning_any(Entity_Player& player, std::span collectibles) @@ -105,6 +111,12 @@ static bool is_owning_any(Entity_Player& player, std::span collectibl return std::ranges::any_of(collectibles, [&](int id) { return player.HasCollectible(id); }); } +// Whether the player has a collectible, or its temporary effect. +static bool is_having(Entity_Player& p, int collectible) +{ + return p.HasCollectible(collectible) || p.temporaryEffects.HasCollectibleEffect(collectible); +} + // How often a pill effect was taken, 0 for one never seen. static float pill_uses(Entity_Player& player, int pillEffect) { @@ -148,20 +160,39 @@ static void bulbs_apply(Entity_Player& p, float& stat, float dimScale, float vib if (p.HasTrinket(TRINKET_VIBRANT_BULB) && isFull) stat = trinket_num(p, TRINKET_VIBRANT_BULB) * vibrantScale + stat; } -// Whether the character and run are ones the evaluation is reconstructed for (see EVALUATION_UNHANDLED_ITEMS), with -// only the temporary effects of the actives and trinkets written for them. +// The temporary effects the frame (00782af0) and its items' (00794e50), shooting (0077b020) and body (00779b40) parts +// ask about by id but do not run yet: collectible effects, null effects and Faded Polaroid's. An effect the frame +// never asks about only counts down there. +constexpr int FRAME_COLLECTIBLE_EFFECTS[] = {28, 65, 130, 147, 160, 181, 282, 325, 326, 409, 475, 478, 493, 497, 522, + 543, 550, 593, 625, 632, 640, 673, 688, 699, 704, 705, 713, 714, 726, 729}; +constexpr int FRAME_NULL_EFFECTS[] = {48, 50, 55, 59, 60, 61, 62, 63, 66, 69, 70, 111, 114, 116, 117, 122, 128}; +constexpr int FRAME_TRINKET_EFFECTS[] = {TRINKET_FADED_POLAROID}; + +// Whether the frame runs a temporary effect: the effects written for it, and those it never asks about. +static bool is_frame_effect_known(const TemporaryEffect& effect) +{ + if (is_temporary_effect_plain(effect) || is_passive_effect_plain(effect) || is_trinket_effect_plain(effect)) + return true; + + std::span unwritten = effect.item->type == ITEM_NULL ? std::span(FRAME_NULL_EFFECTS) + : effect.item->type == ITEM_TRINKET ? std::span(FRAME_TRINKET_EFFECTS) + : std::span(FRAME_COLLECTIBLE_EFFECTS); + return std::ranges::find(unwritten, effect.item->id) == unwritten.end(); +} + +// Whether the character and run are ones the frame is reconstructed for, with only temporary effects it runs. bool Entity_Player::is_character_plain() { Game& game = *g_game; return is_character_reconstructed(*this) && variant == PLAYER_VARIANT_PLAYER && !isCoopGhost && !hasCurseMistEffect && game.challenge == 0 && game.dailyChallenge._id == 0 && game.seedEffects.CountSeedEffects() == 0 && - !game.deathmatchManager.is_active() && - std::ranges::all_of(temporaryEffects.effects, - [](const TemporaryEffect& e) { return is_temporary_effect_plain(e) || is_passive_effect_plain(e) || is_trinket_effect_plain(e); }) && + !game.deathmatchManager.is_active() && std::ranges::all_of(temporaryEffects.effects, is_frame_effect_known) && proceduralItems.empty(); } -// The bonuses Binge Eater's foods give: damage, tears, range, shot speed, speed and luck, each food also slowing. +// What every section of the evaluation starts from: the bonuses Experimental Treatment, Binge Eater's foods, Candy +// Heart and Soul Locket give (damage, tears, range, shot speed, speed and luck), Cracked Crown's scale, and whether +// the curse mist or a co-op ghost drops the pills and stat modifiers. struct StatBonuses { float damage = 0; @@ -170,16 +201,43 @@ struct StatBonuses float shotSpeed = 0; float speed = 0; float luck = 0; + float crownScale = 1; + bool isMistOrGhost = false; }; +// A stat modifier, dropped under the curse mist or as a co-op ghost. +static int modifier_get(const StatBonuses& bonus, int modifier) +{ + return bonus.isMistOrGhost ? 0 : modifier; +} + +// Two pill effects' uses weighed against each other, none under the curse mist or as a co-op ghost. +static float pills_weigh(Entity_Player& p, const StatBonuses& bonus, int up, float upScale, int down, float downScale) +{ + return bonus.isMistOrGhost ? 0 : pill_uses(p, up) * upScale - pill_uses(p, down) * downScale; +} + +// The stat ups Candy Heart (0.1 each) and Soul Locket (0.2 each) collected, in the bonuses' order. +static void heart_stat_ups_add(StatBonuses& bonus, const std::array& ups, float scale) +{ + std::array stats = {&bonus.damage, &bonus.tears, &bonus.range, &bonus.shotSpeed, + &bonus.speed, &bonus.luck}; + for (size_t i = 0; i < stats.size(); i++) *stats[i] = (float)ups[i] * scale + *stats[i]; +} + // The part of 00763570 before the sections: Experimental Treatment's effect deals three stats up and three down in -// an order the room's spawn seed shuffles, then Binge Eater's foods add to the stats it lowers speed for. +// an order the room's spawn seed shuffles, then Binge Eater's foods add to the stats it lowers speed for, then Candy +// Heart's and Soul Locket's ups. static StatBonuses stat_bonuses_get(Entity_Player& player) { constexpr float FOOD_SLOW = 0.15f; constexpr uint32_t SHUFFLE_SHIFT_INDEX = 19; StatBonuses bonus; + bonus.isMistOrGhost = player.hasCurseMistEffect || player.isCoopGhost; + bonus.crownScale = (float)player.GetTrinketMultiplier(TRINKET_CRACKED_CROWN) * 0.2f + 1; + if (player.playerType == PLAYER_BETHANY_B) bonus.crownScale *= TAINTED_BETHANY_STAT_SCALE; + if (player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_EXPERIMENTAL_TREATMENT)) { std::array stats = {&bonus.damage, &bonus.tears, &bonus.range, &bonus.shotSpeed, &bonus.speed, &bonus.luck}; @@ -191,42 +249,89 @@ static StatBonuses stat_bonuses_get(Entity_Player& player) for (uint32_t i = 0; i < values.size() - 1; i++) std::swap(values[i], values[i + rng.RandomInt(values.size() - i)]); for (size_t i = 0; i < values.size(); i++) *stats[i] = values[i]; } - if (!player.HasCollectible(COLLECTIBLE_BINGE_EATER)) return bonus; - auto food = [&](int id, std::initializer_list stats) + if (player.HasCollectible(COLLECTIBLE_BINGE_EATER)) { - float count = (float)player.GetCollectibleNum(id); - for (float* stat : stats) *stat = count + *stat; - bonus.speed = bonus.speed - count * FOOD_SLOW; - }; - food(22, {&bonus.tears, &bonus.range}); - food(23, {&bonus.tears, &bonus.shotSpeed}); - food(24, {&bonus.damage, &bonus.shotSpeed}); - food(25, {&bonus.range, &bonus.shotSpeed}); - food(26, {&bonus.damage, &bonus.range}); - food(346, {&bonus.luck, &bonus.shotSpeed}); - food(456, {&bonus.damage, &bonus.luck}); - food(707, {&bonus.tears, &bonus.luck}); + auto food = [&](int id, std::initializer_list stats) + { + float count = (float)player.GetCollectibleNum(id); + for (float* stat : stats) *stat = count + *stat; + bonus.speed = bonus.speed - count * FOOD_SLOW; + }; + food(22, {&bonus.tears, &bonus.range}); + food(23, {&bonus.tears, &bonus.shotSpeed}); + food(24, {&bonus.damage, &bonus.shotSpeed}); + food(25, {&bonus.range, &bonus.shotSpeed}); + food(26, {&bonus.damage, &bonus.range}); + food(346, {&bonus.luck, &bonus.shotSpeed}); + food(456, {&bonus.damage, &bonus.luck}); + food(707, {&bonus.tears, &bonus.luck}); + } + if (player.HasCollectible(COLLECTIBLE_CANDY_HEART)) heart_stat_ups_add(bonus, player.candyHeartStatUps, 0.1f); + if (player.HasCollectible(COLLECTIBLE_SOUL_LOCKET)) heart_stat_ups_add(bonus, player.soulLocketStatUps, 0.2f); return bonus; } +// A stat glitched items add (GlitchedItemSet::recalculate 009e0500's sums, 00753870 to 007538c0), which TMTRAINER's +// items would give. The procedural items are not reconstructed, so a player holding one stops here. +static float glitched_stat_get(Entity_Player& p) +{ + if (!p.proceduralItems.empty() && p.proceduralItems.begin()->first < 0) + reconstruction_missing("GlitchedItemSet::recalculate 009e0500 (the glitched items' stats)"); + return 0; +} + +// The Decap Attack effect's boost with Judas's Birthright book: a main weapon other than a knife, Ludovico or the +// whip, whose shots Ludovico does not hold. +static bool is_decap_boosted(Entity_Player& p) +{ + if (!p.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_DECAP_ATTACK) || + !p.HasCollectible(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE)) + return false; + + Weapon* weapon = p.weapons[0] ? p.weapons[0].get() : p.weapons[1].get(); + return weapon && weapon->weaponType != WEAPON_LUDOVICO_TECHNIQUE && weapon->weaponType != WEAPON_KNIFE && + weapon->weaponType != WEAPON_UMBILICAL_WHIP && !(weapon->modifiers & WEAPON_MOD_LUDOVICO_TECHNIQUE); +} + +// The challenge the player plays with its own rules (a co-op baby's are its owner's), or null. +static ChallengeParam* challenge_params_get(Entity_Player& p) +{ + if (p.variant != PLAYER_VARIANT_PLAYER || g_game->challenge == 0) return nullptr; + return &g_manager->GetChallengeParams(g_game->challenge); +} + +// Whether a co-op baby's owner cannot shoot, which takes the baby's tears and damage too. +static bool is_baby_unarmed(Entity_Player& p) +{ + Entity_Player* owner = p.variant == PLAYER_VARIANT_COOP_BABY ? p.GetMainPlayer() : nullptr; + return owner && !owner->canShoot; +} + // The fire delay section of 00763570: tears ups through the tears curve, fire rate items, then the multipliers of // the shot changing items, as frames between shots. -static void fire_delay_evaluate(Entity_Player& p, const StatBonuses& bonus, float crownScale) +static void fire_delay_evaluate(Entity_Player& p, const StatBonuses& bonus) { auto n = [&](int id) { return (float)p.GetCollectibleNum(id); }; + auto e = [&](int id) { return (float)p.temporaryEffects.GetCollectibleEffectNum(id); }; auto has = [&](int id) { return p.HasCollectible(id); }; + TemporaryEffects& effects = p.temporaryEffects; + float crownScale = bonus.crownScale; - float tears = pill_uses(p, PILL_TEARS_UP) * 0.5f - pill_uses(p, PILL_TEARS_DOWN) * 0.4f; - for (int id : {32, 80, 381, 1, 370, 341, 342, 183, 394, 547, 601}) tears = n(id) + tears; + float tears = pills_weigh(p, bonus, PILL_TEARS_UP, 0.5f, PILL_TEARS_DOWN, 0.4f); + for (int id : {32, 80, 381, 1}) tears = n(id) + tears; + tears = e(1) + tears; + for (int id : {370, 341, 342}) tears = n(id) + tears; + tears = e(342) + tears; + for (int id : {183, 394, 547, 601}) tears = n(id) + tears; tears = (n(598) + tears) * 0.7f; - tears = n(6) * 1.5f + tears; + tears = (n(6) + e(6)) * 1.5f + tears; tears = (n(669) + n(564) + n(255) + n(115) + n(72)) * 0.5f + tears; int worms = p.GetTrinketMultiplier(TRINKET_WIGGLE_WORM) + (p.GetCollectibleNum(196) - p.GetCollectibleNum(182)) + p.GetTrinketMultiplier(TRINKET_OUROBOROS_WORM) + p.GetTrinketMultiplier(TRINKET_HOOK_WORM) + p.GetTrinketMultiplier(TRINKET_RING_WORM); tears = (float)worms * 0.4f + tears; tears = (float)(p.GetCollectibleNum(189) + p.GetCollectibleNum(101) + p.GetCollectibleNum(90)) * 0.2f + tears; - tears = tears - (float)(p.GetCollectibleNum(331) + p.GetCollectibleNum(237)) * 0.3f; + tears = tears - (e(237) + n(331) + n(237)) * 0.3f; tears = n(438) * 0.75f + tears; tears = n(443) * 0.3f + tears; tears = n(465) * 0.35f + tears; @@ -236,6 +341,7 @@ static void fire_delay_evaluate(Entity_Player& p, const StatBonuses& bonus, floa if (bonusTears < 0) bonusTears *= NEGATIVE_TEARS_SCALE; tears = bonusTears + tears; tears = tears - character_tears_penalty_get(p); + if (effects.HasCollectibleEffect(COLLECTIBLE_MEGA_MUSH)) tears = tears - 1.9f; if (p.HasPlayerForm(PLAYER_FORM_CONJOINED)) tears = tears - 0.3f; if (p.coopBabyBuffTimers[COOP_BUFF_TEARS] > 0) tears = tears + 1; @@ -249,25 +355,37 @@ static void fire_delay_evaluate(Entity_Player& p, const StatBonuses& bonus, floa float zodiacA = p.GetZodiacEffect() == 307 ? 1.0f : 0.0f; float zodiacB = p.GetZodiacEffect() == 309 ? 1.0f : 0.0f; float pairs = (float)(p.GetCollectibleNum(307) + p.GetCollectibleNum(228) + p.GetCollectibleNum(224) + - p.GetCollectibleNum(206)) + zodiacA; - pairs = (n(309) + pairs + zodiacB + (float)p.fireDelayModifier) * 0.5f; + p.GetCollectibleNum(206)) + e(206) + zodiacA; + pairs = (n(309) + pairs + zodiacB + (float)modifier_get(bonus, p.fireDelayModifier)) * 0.5f; float purityTears = is_purity(p, PURITY_TEARS) ? 2.0f : 0.0f; - float crown = p.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_DARK_PRINCES_CROWN) ? 2.0f : 0.0f; + float crown = effects.HasCollectibleEffect(COLLECTIBLE_DARK_PRINCES_CROWN) ? 2.0f : 0.0f; float flat = (float)p.brittleBonesUpgrades * 0.4f + trinket_num(p, TRINKET_CANCER) + purityTears + pairs + crown; - flat = n(397) + flat; - rate = flat + rate; - if (has(120)) rate = n(120) * 0.7f + 1 + rate; + flat = n(397) + e(397) + flat; + flat = (float)effects.GetNullEffectNum(NULLITEM_REVERSE_EMPRESS) * 1.5f + flat; + flat = e(COLLECTIBLE_WAVY_CAP) * 0.75f + flat; + rate = (float)effects.GetNullEffectNum(NULLITEM_WAVY_CAP_1) * 0.3f + flat + rate; + if (has(120) || effects.HasCollectibleEffect(120)) rate = (n(120) + e(120)) * 0.7f + 1 + rate; // The original also counts Equality when a trinket slot only the constructor writes holds it, always empty. - if (p.temporaryEffects.HasTrinketEffect(TRINKET_EQUALITY)) rate = trinket_num(p, TRINKET_EQUALITY) * 2 + rate; + if (effects.HasTrinketEffect(TRINKET_EQUALITY)) rate = trinket_num(p, TRINKET_EQUALITY) * 2 + rate; rate = n(554) * 0.5f + rate; if (!p.HasWeaponType(WEAPON_BRIMSTONE)) rate = n(222) + rate; rate = (float)p.g_fuel_count() * 0.5f + rate; + int seededVariant = p.get_seeded_variant(); + if (seededVariant == SEEDED_VARIANT_SLOW || seededVariant == SEEDED_VARIANT_SLOW_FAR) rate *= 0.4f; + else if (seededVariant == SEEDED_VARIANT_RAPID) rate *= 5.5f; + if (TemporaryEffect* milk = effects.GetCollectibleEffect(COLLECTIBLE_MILK)) rate = (float)milk->count + rate; + if (int hurts = effects.GetNullEffectNum(NULLITEM_IT_HURTS); hurts > 0) rate = (float)hurts * 0.4f + 0.8f + rate; + if (int candle = effects.GetCollectibleEffectNum(COLLECTIBLE_PASCHAL_CANDLE); candle > 0) rate = (float)candle * 0.4f + rate; + if (int luna = effects.GetNullEffectNum(NULLITEM_LUNA); luna > 0) rate = (float)luna * 0.5f + 0.5f + rate; + rate = glitched_stat_get(p) + rate; if (p.grantedCollectibleCountdown > 0) rate = rate + 1.5f; + if (TemporaryEffect* camo = effects.GetNullEffect(NULLITEM_CAMO_BOOST)) rate = rate + (float)camo->count * 0.25f; if (!has(245)) { if (has(153) || (has(169) && !p.HasWeaponType(WEAPON_FETUS))) rate *= 0.42f; - else if (has(2)) rate *= 0.51f; + else if (has(2) || effects.HasCollectibleEffect(2) || effects.HasNullEffect(NULLITEM_REVERSE_HANGED_MAN)) + rate *= 0.51f; } if (has(149) && (p.HasWeaponType(WEAPON_TEARS) || p.HasWeaponType(WEAPON_MONSTROS_LUNGS) || p.HasWeaponType(WEAPON_LASER))) @@ -301,57 +419,142 @@ static void fire_delay_evaluate(Entity_Player& p, const StatBonuses& bonus, floa if (p.hallowedGroundCountdown != 0) rate *= 2.5f; if (has(368) && p.epiphoraCharge > 0) rate *= (float)p.epiphoraCharge / 180 + 1; if (p.peeBurstCooldown > 0) rate = ((float)p.peeBurstCooldown * 5 / (float)p.maxPeeBurstCooldown + 1) * rate; - if (has(695) && !p.temporaryEffects.isDisabled) + if (has(695) && !effects.isDisabled) { float lust = std::clamp((float)p.bloodLustCounter, 0.0f, 6.0f); rate = lust * 0.05f * lust + lust * 0.2f + rate; } + if (effects.HasCollectibleEffect(COLLECTIBLE_BLOOD_RIGHTS) && !effects.isDisabled) + rate = std::clamp((float)p.bloodLustCounter, 0.0f, BLOOD_RIGHTS_LUST_CAP) * 0.15f + 0.33f + rate; + if (seededVariant == SEEDED_VARIANT_MUTANT_SPIDER) rate *= 0.75f; p.maxFireDelay = FIRE_RATE_FRAMES / (rate * p.d8FireDelayModifier) - 1; + if (is_baby_unarmed(p)) p.maxFireDelay = BABY_UNARMED_FIRE_DELAY; + if (ChallengeParam* challenge = challenge_params_get(p); challenge && challenge->minFireRate > 0) + p.maxFireDelay = std::max(challenge->minFireRate, p.maxFireDelay); static_cast(g_luaEngine)->EvaluateItems(&p, CACHE_FIREDELAY); p.maxFireDelay = std::max(p.maxFireDelay, MAX_FIRE_DELAY_MIN); } -// The damage section of 00763570: damage ups through the damage curve on 3.5, then the multiplying items. -static void damage_evaluate(Entity_Player& p, const StatBonuses& bonus, float crownScale) +// The Judas's Birthright nulls' part of the damage: the plain stacks, the timed boost's frames, the stage stacks and +// the permanent ones. +static float judas_birthright_damage_get(TemporaryEffects& effects) { - auto n = [&](int id) { return p.GetCollectibleNum(id); }; - auto has = [&](int id) { return p.HasCollectible(id); }; float damage = 0; - p.meleeDamage = 0; + if (TemporaryEffect* plain = effects.GetNullEffect(NULLITEM_JUDAS_BIRTHRIGHT)) + damage = (float)(plain->count + plain->count) / 3 + damage; + if (TemporaryEffect* timed = effects.GetNullEffect(NULLITEM_JUDAS_BIRTHRIGHT_TIMED)) + damage = (float)(timed->cooldown + timed->cooldown) / 90 + damage; + if (TemporaryEffect* stage = effects.GetNullEffect(NULLITEM_JUDAS_BIRTHRIGHT_STAGE)) + damage = (float)stage->count * 6 / 3 + damage; + if (TemporaryEffect* permanent = effects.GetNullEffect(NULLITEM_JUDAS_BIRTHRIGHT_PERMANENT)) + damage = (float)permanent->count * 0.5f + damage; + return damage; +} + +// The damage a co-op baby's skin adds: the strong babies' flat bonus. +static float baby_skin_damage_get(Entity_Player& p) +{ + if (p.variant != PLAYER_VARIANT_COOP_BABY) return 0; + if (p.babySkin == BABY_SHADOW) return 2; + if (p.babySkin == BABY_FIGHTING) return 1; + return p.babySkin == BABY_SUPER_GREED ? 1.5f : 0; +} + +// The damage section's flat ups before the curve, in the original's order: Book of Belial's effect, the martyr +// items, transformations, Money = Power, False PHD's bad pills, Red Stew, Keeper's Sack, Judas's Birthright, the +// bulbs, the babies and the Babylons. +static float damage_flat_get(Entity_Player& p) +{ + auto has = [&](int id) { return p.HasCollectible(id); }; + bool isDeathmatch = g_game->deathmatchManager.is_active(); + TemporaryEffects& effects = p.temporaryEffects; + float damage = 0; + + if (TemporaryEffect* belial = effects.GetCollectibleEffect(COLLECTIBLE_BOOK_OF_BELIAL)) + damage = (float)(belial->count - 1) + 2 + damage; for (int id : {7, 90, 216}) if (has(id)) damage = damage + 1; if (p.HasPlayerForm(PLAYER_FORM_SPUN)) damage = damage + 2; if (p.HasPlayerForm(PLAYER_FORM_CONJOINED)) damage = damage - 0.3f; - if (has(109)) damage = (float)p.numCoins * 0.04f + damage; - if (p.redStewBonusDuration > 0 && !p.temporaryEffects.isDisabled) - damage = (float)(p.redStewBonusDuration / 10) * 0.04f + damage; + if (has(109)) damage = (float)p.numCoins * (isDeathmatch ? 0.1f : 0.04f) + damage; + if (has(COLLECTIBLE_FALSE_PHD)) + { + int badPills = 0; + for (int pill : {47, 17, 15, 13, 11, 6}) badPills += (int)pill_uses(p, pill); + damage = (float)badPills * 0.6f + damage; + } + if (p.redStewBonusDuration > 0 && !effects.isDisabled) + damage = (float)(p.redStewBonusDuration / 10) * (isDeathmatch ? 0.056f : 0.04f) + damage; if (has(716)) damage = (float)((p.keepersSackBonus / 3 + 2) / 3) * 0.5f + damage; + damage = judas_birthright_damage_get(effects) + damage; + if (is_decap_boosted(p)) damage = damage + 2; bulbs_apply(p, damage, 1.5f, 0.5f); - for (TemporaryEffect* babylon : {p.temporaryEffects.GetCollectibleEffect(COLLECTIBLE_WHORE_OF_BABYLON), - p.temporaryEffects.GetNullEffect(NULLITEM_BLOODY_BABYLON)}) + damage = baby_skin_damage_get(p) + damage; + for (TemporaryEffect* babylon : {effects.GetCollectibleEffect(COLLECTIBLE_WHORE_OF_BABYLON), + effects.GetNullEffect(NULLITEM_BLOODY_BABYLON)}) if (babylon) damage = (float)(babylon->count * babylon->count) * 1.5f + damage; if (p.grantedCollectibleCountdown > 0) damage = damage + 1; + return damage; +} +// What a co-op baby's damage is scaled by: half, unless it is the Found Soul's, whose trinket's golden or doubled +// copies make it three quarters or whole. +static float baby_damage_scale_get(Entity_Player& p) +{ + Entity_Player* owner = p.parent ? p.parent->ToPlayer() : nullptr; + int soul = p.babySkin == BABY_FOUND_SOUL && owner ? owner->GetTrinketMultiplier(TRINKET_FOUND_SOUL) : 0; + if (soul == 2) return 0.75f; + return soul == 3 ? 1.0f : 0.5f; +} + +// The damage section of 00763570: damage ups through the damage curve on 3.5, then the multiplying items. +static void damage_evaluate(Entity_Player& p, const StatBonuses& bonus) +{ + auto n = [&](int id) { return p.GetCollectibleNum(id); }; + auto e = [&](int id) { return p.temporaryEffects.GetCollectibleEffectNum(id); }; + auto has = [&](int id) { return p.HasCollectible(id); }; + TemporaryEffects& effects = p.temporaryEffects; + float crownScale = bonus.crownScale; + + p.meleeDamage = 0; + float damage = damage_flat_get(p); int ups = n(708) + n(592) + n(572) + n(531) + n(345) + n(328) + n(259) + n(208) + n(206) + n(165) + n(121) + - n(79) + n(70) + n(51) + n(50) + std::max(n(118) - 1, 0); - float sum = (float)ups; + n(79) + n(70) + n(51) + n(50) + std::max(n(118) - 1, 0) + e(345) + e(259) + e(206) + e(121) + e(70); + float sum = (float)effects.GetNullEffectNum(NULLITEM_SOL) * 3 + (float)ups; + sum = (float)p.bonusDamageUps + (float)effects.GetNullEffectNum(NULLITEM_REVERSE_SUN) * 1.5f + sum; sum = (float)n(732) + sum; sum = (float)n(730) * 0.75f + sum; sum = (float)p.g_fuel_count() * 0.75f + sum; - sum = (float)((int)has(261) + n(669) + n(331) + n(307) + n(197) + n(80) + n(4)) * 0.5f + sum; - sum = (float)(n(463) + n(445) + n(201) + n(193) + n(189) + n(138) + n(101) + n(62) + n(12)) * 0.3f + sum; - float mushrooms = (float)n(633); - damage = (float)(n(359) + n(237) + n(230) + n(5)) * 1.5f + sum + mushrooms + mushrooms + damage; + int proptosis = (int)has(261) + (int)effects.HasCollectibleEffect(261); + sum = (float)(e(COLLECTIBLE_SANGUINE_BOND) + proptosis + n(669) + n(331) + n(307) + n(197) + n(80) + n(4)) * 0.5f + sum; + sum = (float)(e(12) + n(463) + n(445) + n(201) + n(193) + n(189) + n(138) + n(101) + n(62) + n(12) + e(201)) * 0.3f + + sum; + float dogma = (float)n(COLLECTIBLE_DOGMA); + damage = (float)(e(237) + n(359) + n(237) + n(230) + n(5)) * 1.5f + sum + dogma + dogma + damage; + if (int oath = effects.GetNullEffectNum(NULLITEM_BLOOD_OATH); oath > 0) + damage = ((float)oath / 23) * ((float)oath / 23) * 20 + damage; if (has(694)) damage = (float)p.brokenHearts * 0.25f + damage; - if (has(120)) damage = damage * 0.9f - 0.4f; + if (has(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE)) + damage = (float)effects.GetNullEffectNum(NULLITEM_WAVY_CAP_1) * 0.2f + (float)e(COLLECTIBLE_WAVY_CAP) * 0.2f + damage; + if (ChallengeParam* challenge = g_game->challenge != 0 ? &g_manager->GetChallengeParams(g_game->challenge) : nullptr) + damage = challenge->addDamage + damage; + if (has(120) || effects.HasCollectibleEffect(120)) damage = damage * 0.9f - 0.4f; + if (effects.HasCollectibleEffect(COLLECTIBLE_THE_NAIL)) + damage = (float)(e(COLLECTIBLE_THE_NAIL) + e(COLLECTIBLE_THE_NAIL)) + damage; if (p.coopBabyBuffTimers[COOP_BUFF_DAMAGE] > 0) damage = damage + 2; - if (TemporaryEffect* lock = p.temporaryEffects.GetTrinketEffect(TRINKET_SAMSONS_LOCK)) - damage = std::min(SAMSONS_LOCK_CAP, (float)lock->count * 0.5f) + damage; - if (TemporaryEffect* boost = p.temporaryEffects.GetNullEffect(NULLITEM_LAZARUS_BOOST)) + if (TemporaryEffect* lusty = effects.GetCollectibleEffect(COLLECTIBLE_LUSTY_BLOOD)) + damage = std::min((float)lusty->count * 0.5f, g_game->deathmatchManager.is_active() ? 100.0f : 5.0f) + damage; + if (TemporaryEffect* lock = effects.GetTrinketEffect(TRINKET_SAMSONS_LOCK)) + damage = std::min((float)lock->count * 0.5f, SAMSONS_LOCK_CAP) + damage; + for (int razor : {COLLECTIBLE_RAZOR_BLADE, COLLECTIBLE_GOLDEN_RAZOR}) + if (TemporaryEffect* cut = effects.GetCollectibleEffect(razor)) damage = (float)cut->count * 1.2f + damage; + if (TemporaryEffect* arts = effects.GetNullEffect(NULLITEM_DARK_ARTS)) damage = (float)arts->count * 0.25f + damage; + if (TemporaryEffect* boost = effects.GetNullEffect(NULLITEM_LAZARUS_BOOST)) damage = (float)boost->count * 0.5f + damage; - if (TemporaryEffect* patch = p.temporaryEffects.GetTrinketEffect(TRINKET_RED_PATCH)) + if (TemporaryEffect* camo = effects.GetNullEffect(NULLITEM_CAMO_BOOST)) damage = (float)camo->count * 0.35f + damage; + if (TemporaryEffect* patch = effects.GetTrinketEffect(TRINKET_RED_PATCH)) damage = (float)patch->count * 1.8f + damage; if (p.HasTrinket(TRINKET_BLACK_FEATHER)) { @@ -363,31 +566,38 @@ static void damage_evaluate(Entity_Player& p, const StatBonuses& bonus, float cr damage = std::sqrt(std::max(damage * DAMAGE_CURVE_SCALE + 1, 0.0f)) * DAMAGE_BASE; if (has(169)) - damage = !has(2) && !has(153) && !p.HasWeaponType(WEAPON_FETUS) && !has(245) ? damage + 4 + damage + 4 - : damage + 5; + damage = !has(2) && !has(153) && !effects.HasCollectibleEffect(2) && !p.HasWeaponType(WEAPON_FETUS) && !has(245) + ? damage + 4 + damage + 4 + : damage + 5; damage = damage * character_damage_scale_get(p); + if (p.variant == PLAYER_VARIANT_COOP_BABY && p.babySkin == BABY_BONE) damage = damage * 1.5f; damage = damage + character_damage_get(p); - if (p.playerType == PLAYER_THEFORGOTTEN && p.temporaryEffects.HasNullEffect(NULLITEM_SOUL_FORGOTTEN)) + if (effects.HasNullEffect(NULLITEM_ESAU_JR)) damage = damage + 2; + if (effects.HasCollectibleEffect(COLLECTIBLE_MEGA_MUSH)) damage = damage * 4; + if (p.playerType == PLAYER_THEFORGOTTEN && effects.HasNullEffect(NULLITEM_SOUL_FORGOTTEN)) damage = (damage + 2) * 3; damage = (float)(p.potatoPeelerBandageCounter + p.potatoPeelerCounter) * 0.2f + damage; - damage = std::max((float)p.damageModifier + bonus.damage + damage, DAMAGE_MIN); + damage = std::max((float)modifier_get(bonus, p.damageModifier) + bonus.damage + damage, DAMAGE_MIN); + if (effects.HasCollectibleEffect(COLLECTIBLE_BERSERK)) damage = damage + 3; + damage = glitched_stat_get(p) + damage; float horns = trinket_num(p, TRINKET_CURVED_HORN); damage = horns + horns + damage; if (has(513)) damage = damage + 0.1f; + if (effects.HasNullEffect(NULLITEM_HUGE_GROWTH)) damage = damage + 7; if (p.HasWeaponType(WEAPON_BONE) && has(114)) damage = damage + 4; - if (has(COLLECTIBLE_CROWN_OF_LIGHT) && p.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_CROWN_OF_LIGHT)) + if (has(COLLECTIBLE_CROWN_OF_LIGHT) && effects.HasCollectibleEffect(COLLECTIBLE_CROWN_OF_LIGHT)) damage = damage + damage; if (has(182)) damage = damage * 2.3f + 1; if (has(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE) && has(COLLECTIBLE_PASSIVE_DAMOCLES)) damage = damage * 1.4f + 1; if (has(573) || p.hallowedGroundCountdown > 0) damage = damage * 1.2f; - if (has(COLLECTIBLE_ADRENALINE) || p.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_ADRENALINE)) + if (has(COLLECTIBLE_ADRENALINE) || effects.HasCollectibleEffect(COLLECTIBLE_ADRENALINE)) { uint32_t empty = (uint32_t)((p.boneHearts * 2 - p.redHearts + p.maxHearts) / 2); if (g_game->deathmatchManager.is_active()) empty >>= 3; float hearts = (float)(int)empty; damage = std::pow(hearts + hearts, ADRENALINE_POWER) * 0.1f + damage; } - if (has(157) && !p.temporaryEffects.isDisabled) + if (has(157) && !effects.isDisabled) { float cap = has(COLLECTIBLE_BIRTHRIGHT) && p.playerType == PLAYER_SAMSON ? 10.0f : 6.0f; float lust = std::clamp((float)p.bloodLustCounter, 0.0f, cap); @@ -411,7 +621,8 @@ static void damage_evaluate(Entity_Player& p, const StatBonuses& bonus, float cr damage = damage + (isTears ? 40.0f : 2.0f); melee = melee + 2; } - if (has(4) || has(12)) + if (has(4) || (effects.HasCollectibleEffect(COLLECTIBLE_BOOK_OF_BELIAL) && has(7)) || has(12) || + effects.HasCollectibleEffect(12)) { damage = damage * 1.5f; melee = melee * 1.5f; @@ -427,7 +638,7 @@ static void damage_evaluate(Entity_Player& p, const StatBonuses& bonus, float cr damage = damage * scale; melee = melee * scale; } - if (has(245)) + if (has(245) || p.babySkin == BABY_DOUBLE) { damage = damage * 0.8f; melee = melee * 0.8f; @@ -461,6 +672,11 @@ static void damage_evaluate(Entity_Player& p, const StatBonuses& bonus, float cr static_cast(g_luaEngine)->EvaluateItems(&p, CACHE_DAMAGE); p.damage = trinket_num(p, TRINKET_LAZY_WORM) * 0.5f + p.damage; + if (is_baby_unarmed(p)) p.damage = DAMAGE_BASE; + if (ChallengeParam* challenge = challenge_params_get(p); challenge && challenge->isMaxDamage) + p.damage = std::max(CHALLENGE_MAX_DAMAGE, p.damage); + if (p.variant == PLAYER_VARIANT_COOP_BABY) p.damage = baby_damage_scale_get(p) * p.damage; + if (p.isCoopGhost || p.IsHologram()) p.damage = p.damage * GHOST_DAMAGE_SCALE; if (g_game->debugFlags & DEBUG_HIGH_DAMAGE) { p.damage = p.damage + DEBUG_DAMAGE_BONUS; @@ -471,61 +687,80 @@ static void damage_evaluate(Entity_Player& p, const StatBonuses& bonus, float cr } // The shot speed section of 00763570: shot speed ups and downs on 1. -static void shot_speed_evaluate(Entity_Player& p, const StatBonuses& bonus, float crownScale) +static void shot_speed_evaluate(Entity_Player& p, const StatBonuses& bonus) { auto n = [&](int id) { return p.GetCollectibleNum(id); }; + auto e = [&](int id) { return p.temporaryEffects.GetCollectibleEffectNum(id); }; auto has = [&](int id) { return p.HasCollectible(id); }; + TemporaryEffects& effects = p.temporaryEffects; + float crownScale = bonus.crownScale; - float pills = (float)(int)(pill_uses(p, PILL_SHOT_SPEED_UP) - pill_uses(p, PILL_SHOT_SPEED_DOWN)); + float pills = bonus.isMistOrGhost ? 0 : (float)(int)(pill_uses(p, PILL_SHOT_SPEED_UP) - pill_uses(p, PILL_SHOT_SPEED_DOWN)); int occult = std::min(n(572), 1); int mascara = std::min(n(310), 1); - float ups = (float)(n(176) + n(669) + ((n(183) - occult) - n(342)) + n(397) + n(341) + n(339) + n(194)) * 0.16f; - float drops = (float)(n(564) + n(255) + n(143)) * 0.2f; + float ups = (float)(n(176) + n(669) + (((n(183) - occult) - n(342)) - e(342)) + n(397) + n(341) + n(339) + n(194)) * + 0.16f; + float drops = (float)(e(143) + n(564) + n(255) + n(143)) * 0.2f; float speed = (float)n(165) * 0.23f + 1 + drops + ups + pills * 0.15f; speed = speed - (float)n(182) * 0.25f; speed = speed - (float)n(213) * 0.15f; speed = speed - (float)mascara * 0.5f; speed = speed - (float)n(336) * 0.4f; speed = speed - (float)n(331) * 0.3f; - speed = speed - (float)p.temporaryEffects.GetCollectibleEffectNum(COLLECTIBLE_CROWN_OF_LIGHT) * 0.3f; - speed = ((float)p.shotSpeedModifier + bonus.shotSpeed) * 0.2f + (float)n(329) * 0.2f + speed; + speed = speed - (float)e(COLLECTIBLE_CROWN_OF_LIGHT) * 0.3f; + speed = ((float)modifier_get(bonus, p.shotSpeedModifier) + bonus.shotSpeed) * 0.2f + (float)n(329) * 0.2f + speed; bulbs_apply(p, speed, 0.3f, 0.1f); speed = speed + character_shot_speed_get(p); + speed = glitched_stat_get(p) * 0.2f + speed; if (p.coopBabyBuffTimers[COOP_BUFF_RANGE] > 0) speed = speed + 0.5f; - if (p.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_DARK_PRINCES_CROWN)) speed = speed + 0.2f; + if (effects.HasCollectibleEffect(COLLECTIBLE_DARK_PRINCES_CROWN)) speed = speed + 0.2f; + if (effects.HasNullEffect(NULLITEM_ERA_WALK)) speed = speed - 1; speed = trinket_num(p, TRINKET_WHIP_WORM) * 0.5f + speed; speed = (float)n(554) * 0.2f + speed; - if (has(5)) speed = speed * 1.6f; + if (has(5) || effects.HasCollectibleEffect(5)) speed = speed * 1.6f; if (has(149)) speed = speed * 0.8f; + if (p.variant == PLAYER_VARIANT_COOP_BABY && p.babySkin == BABY_BEGOTTEN) speed = speed * 0.5f; speed = speed - trinket_num(p, TRINKET_LAZY_WORM) * 0.5f; if (crownScale != 1 && speed - 1 > 0) speed = (crownScale - 1) * (speed - 1) + speed; p.shotSpeed = speed; static_cast(g_luaEngine)->EvaluateItems(&p, CACHE_SHOTSPEED); + if (ChallengeParam* challenge = challenge_params_get(p); challenge && challenge->isMinShotSpeed) + p.shotSpeed = std::min(CHALLENGE_MIN_SHOT_SPEED, p.shotSpeed); + if (p.get_seeded_variant() != SEEDED_VARIANT_NONE) p.shotSpeed = std::max(SEEDED_SHOT_SPEED, p.shotSpeed); p.shotSpeed = std::max(p.shotSpeed, SHOT_SPEED_MIN); } // The range section of 00763570: range ups in tiles of 100, the height and fall of the tears, and the range items. -static void range_evaluate(Entity_Player& p, const StatBonuses& bonus, float crownScale) +static void range_evaluate(Entity_Player& p, const StatBonuses& bonus) { auto n = [&](int id) { return (float)p.GetCollectibleNum(id); }; + auto e = [&](int id) { return (float)p.temporaryEffects.GetCollectibleEffectNum(id); }; auto has = [&](int id) { return p.HasCollectible(id); }; + TemporaryEffects& effects = p.temporaryEffects; + float crownScale = bonus.crownScale; p.tearRange = RANGE_BASE + character_range_get(p); p.tearHeight = TEAR_HEIGHT_BASE; p.tearFallingSpeed = 0; p.tearFallingAcceleration = 0; - float pills = pill_uses(p, PILL_RANGE_UP) * 0.5f - pill_uses(p, PILL_RANGE_DOWN) * 0.4f; - float ups = (float)(p.tearRangeModifier + p.GetCollectibleNum(71) + p.GetCollectibleNum(12)) + bonus.range; + float pills = pills_weigh(p, bonus, PILL_RANGE_UP, 0.5f, PILL_RANGE_DOWN, 0.4f); + int modifier = modifier_get(bonus, p.tearRangeModifier); + float ups = (float)(effects.GetCollectibleEffectNum(12) + modifier + p.GetCollectibleNum(71) + p.GetCollectibleNum(12) + + effects.GetCollectibleEffectNum(71)) + bonus.range; ups = n(30) + ups; ups = n(31) * 1.5f + ups; ups = n(397) + ups; ups = n(29) + ups + pills; - for (int id : {339, 345, 14, 370, 189, 455, 355, 659}) ups = n(id) + ups; + ups = n(339) + ups; + ups = e(345) + n(345) + ups; + ups = e(14) + n(14) + ups; + for (int id : {370, 189, 455, 355, 659}) ups = n(id) + ups; ups = (n(669) + ups) * 100; - float tiles = (float)(p.GetCollectibleNum(462) + p.GetCollectibleNum(453) + p.GetCollectibleNum(197) + - p.GetCollectibleNum(121) + p.GetCollectibleNum(110) + p.GetCollectibleNum(101)) * 60 + ups; + float tiles = (float)(effects.GetCollectibleEffectNum(121) + p.GetCollectibleNum(462) + p.GetCollectibleNum(453) + + p.GetCollectibleNum(197) + p.GetCollectibleNum(121) + p.GetCollectibleNum(110) + + p.GetCollectibleNum(101)) * 60 + ups; tiles = tiles - n(336) * 60; tiles = n(369) * 120 + tiles; p.tearRange = n(394) * 120 + tiles + p.tearRange; @@ -536,11 +771,23 @@ static void range_evaluate(Entity_Player& p, const StatBonuses& bonus, float cro p.tearRange = p.tearRange + 80; } if (has(594)) p.tearHeight = p.tearHeight - 8; - if (has(598)) p.tearHeight = p.tearHeight * 0.4f; + if (has(598) || effects.HasCollectibleEffect(COLLECTIBLE_INNER_CHILD)) p.tearHeight = p.tearHeight * 0.4f; if (has(716)) p.tearRange = (float)((p.keepersSackBonus / 3 + 1) / 3) * 10 + p.tearRange; + p.tearRange = glitched_stat_get(p) * 60 + p.tearRange; + if (effects.HasCollectibleEffect(COLLECTIBLE_MEGA_MUSH)) + { + p.tearFallingAcceleration = 0.8f; + p.tearHeight = p.tearHeight - 80; + p.tearRange = p.tearRange + 80; + } if (p.coopBabyBuffTimers[COOP_BUFF_RANGE] > 0) p.tearRange = p.tearRange + 80; bulbs_apply(p, p.tearRange, 60, 30); - if (p.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_DARK_PRINCES_CROWN)) p.tearRange = p.tearRange + 60; + if (effects.HasCollectibleEffect(COLLECTIBLE_DARK_PRINCES_CROWN)) p.tearRange = p.tearRange + 60; + if (effects.HasNullEffect(NULLITEM_HUGE_GROWTH)) + { + p.tearHeight = p.tearHeight - 30; + p.tearRange = p.tearRange + 120; + } if (is_purity(p, PURITY_RANGE)) p.tearRange = p.tearRange + 120; if (has(149) || has(531)) { @@ -557,10 +804,18 @@ static void range_evaluate(Entity_Player& p, const StatBonuses& bonus, float cro p.tearFallingAcceleration = p.tearFallingAcceleration * 0.01f; } if (has(307) || p.GetZodiacEffect() == 307) p.tearRange = p.tearRange + 30; - if (has(COLLECTIBLE_ANEMIC) || p.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_ANEMIC)) p.tearRange = p.tearRange + 60; + if (has(COLLECTIBLE_ANEMIC) || effects.HasCollectibleEffect(COLLECTIBLE_ANEMIC)) p.tearRange = p.tearRange + 60; if (p.HasTrinket(TRINKET_HOOK_WORM) && p.HasWeaponType(WEAPON_TEARS)) p.tearRange = trinket_num(p, TRINKET_HOOK_WORM) * 60 + p.tearRange; if (p.HasTrinket(TRINKET_OUROBOROS_WORM)) p.tearRange = trinket_num(p, TRINKET_OUROBOROS_WORM) * 60 + p.tearRange; + if (g_game->challenge != 0 && g_manager->GetChallengeParams(g_game->challenge).isBigRange) + p.tearRange = p.tearRange + CHALLENGE_BIG_RANGE; + if (effects.HasCollectibleEffect(COLLECTIBLE_TELEPATHY_BOOK)) + { + p.tearHeight = p.tearHeight + p.tearHeight; + p.tearFallingSpeed = p.tearFallingSpeed * 0.5f; + p.tearRange = p.tearRange + 120; + } if (p.HasTrinket(TRINKET_TAPE_WORM)) { float tape = trinket_num(p, TRINKET_TAPE_WORM); @@ -568,13 +823,14 @@ static void range_evaluate(Entity_Player& p, const StatBonuses& bonus, float cro p.tearFallingSpeed = tape * 0.5f * p.tearFallingSpeed; p.tearRange = tape * 120 + p.tearRange; } - if (has(6)) + if (is_having(p, 6)) { p.tearHeight = p.tearHeight + 18; p.tearRange = std::min(p.tearRange, std::max(p.tearRange - 60, 200.0f) * 0.8f); } else if (has(440)) p.tearHeight = p.tearHeight + 18; - if (has(5)) p.tearRange = p.tearRange + p.tearRange + 60; + if (is_having(p, 5)) p.tearRange = p.tearRange + p.tearRange + 60; + if (p.get_seeded_variant() == SEEDED_VARIANT_SLOW_FAR) p.tearRange = p.tearRange + SEEDED_FAR_RANGE; p.tearRange = p.tearRange * p.d8RangeModifier; if (crownScale != 1 && p.tearRange > RANGE_BASE) p.tearRange = (p.tearRange - RANGE_BASE) * (crownScale - 1) + p.tearRange; @@ -586,40 +842,54 @@ static void range_evaluate(Entity_Player& p, const StatBonuses& bonus, float cro } // The speed section of 00763570: speed ups on 1, and the items that set or cap it. -static void speed_evaluate(Entity_Player& p, const StatBonuses& bonus, float crownScale) +static void speed_evaluate(Entity_Player& p, const StatBonuses& bonus) { auto n = [&](int id) { return p.GetCollectibleNum(id); }; + auto e = [&](int id) { return p.temporaryEffects.GetCollectibleEffectNum(id); }; auto has = [&](int id) { return p.HasCollectible(id); }; + TemporaryEffects& effects = p.temporaryEffects; + float crownScale = bonus.crownScale; - float pills = pill_uses(p, PILL_SPEED_UP) * 0.5f - pill_uses(p, PILL_SPEED_DOWN) * 0.4f; - int rollers = p.g_fuel_count() < 1 ? n(143) : 0; - float ups = (float)(n(232) + n(119) + n(28) + n(27)) + pills; - for (int id : {340, 12, 71, 101}) ups = (float)n(id) + ups; - ups = (float)p.temporaryEffects.GetCollectibleEffectNum(COLLECTIBLE_WHORE_OF_BABYLON) + ups; + float pills = pills_weigh(p, bonus, PILL_SPEED_UP, 0.5f, PILL_SPEED_DOWN, 0.4f); + int rollers = p.g_fuel_count() < 1 ? n(143) + e(143) : 0; + int sharp = std::min(n(14) + e(14), 1); + int slow = std::min(n(13) + e(13), 1); + float ups = (float)(e(COLLECTIBLE_HOURGLASS) + n(232) + n(119) + n(28) + n(27)) + pills; + for (int id : {340, 12}) ups = (float)n(id) + ups; + ups = (float)e(12) + ups; + ups = (float)n(71) + ups; + ups = (float)e(71) + ups; + ups = (float)n(101) + ups; + ups = (float)e(COLLECTIBLE_WHORE_OF_BABYLON) + ups; ups = (float)n(120) + ups; - ups = ups + (float)rollers; + ups = (float)e(120) + ups + (float)rollers; ups = (float)n(82) + ups; ups = (float)n(571) + ups; - float quick = ups * 0.3f; - float steady = (float)n(70) * 0.5f; + float quick = ((float)effects.GetNullEffectNum(NULLITEM_BLOODY_BABYLON) + ups) * 0.3f; + float steady = (float)(n(70) + e(70)) * 0.5f; steady = (float)n(590) + steady; - steady = steady * 0.4f; - int sharp = std::min(n(14), 1); - int slow = std::min(n(13), 1); - float speed = (float)((((slow - n(90)) - n(129)) - n(121)) + n(669) + n(189) + n(79)) * 0.2f + + steady = ((float)e(COLLECTIBLE_BERSERK) + steady) * 0.4f; + float speed = (float)(e(COLLECTIBLE_INNER_CHILD) + ((((slow - n(90)) - n(129)) - n(121)) - e(121)) + n(669) + n(189) + + n(79)) * 0.2f + (float)sharp * 0.3f + character_speed_get(p) + 1 + steady + quick; - p.moveSpeed = ((float)p.speedModifier + bonus.speed) * 0.2f + (float)n(445) * 0.1f + speed; + p.moveSpeed = ((float)modifier_get(bonus, p.speedModifier) + bonus.speed) * 0.2f + (float)n(445) * 0.1f + speed; if (is_character_slowed(p)) p.moveSpeed = p.moveSpeed - 0.1f; + if (int oath = effects.GetNullEffectNum(NULLITEM_BLOOD_OATH); oath > 0) p.moveSpeed = (float)oath * 0.05f + p.moveSpeed; + p.moveSpeed = p.moveSpeed - ((float)effects.GetNullEffectNum(NULLITEM_WAVY_CAP_1) * 0.06f + (float)e(COLLECTIBLE_WAVY_CAP) * 0.03f); + if (has(COLLECTIBLE_JUPITER)) p.moveSpeed = JUPITER_SLOW + (JUPITER_FAST - JUPITER_SLOW) * p.jupiterCharge + p.moveSpeed; - if (has(695) && !p.temporaryEffects.isDisabled) + if (has(695) && !effects.isDisabled) { float lust = std::clamp((float)p.bloodLustCounter, 0.0f, 6.0f); p.moveSpeed = lust * 0.02f * lust + lust * 0.05f + p.moveSpeed; } if (has(716)) p.moveSpeed = (float)(p.keepersSackBonus / 9) * 0.03f + p.moveSpeed; + p.moveSpeed = glitched_stat_get(p) * 0.2f + p.moveSpeed; bulbs_apply(p, p.moveSpeed, 0.5f, 0.25f); + if (effects.HasCollectibleEffect(77) || effects.HasCollectibleEffect(298)) p.moveSpeed = p.moveSpeed + 0.28f; if (p.HasTrinket(TRINKET_GOAT_HOOF)) p.moveSpeed = trinket_num(p, TRINKET_GOAT_HOOF) * 0.15f + p.moveSpeed; if (p.coopBabyBuffTimers[COOP_BUFF_SPEED] > 0) p.moveSpeed = p.moveSpeed + 0.15f; + if (effects.HasCollectibleEffect(COLLECTIBLE_THE_NAIL)) p.moveSpeed = p.moveSpeed - 0.18f; if (has(230)) p.moveSpeed = p.moveSpeed + 0.2f; if (p.HasPlayerForm(PLAYER_FORM_SPUN)) p.moveSpeed = p.moveSpeed + 0.15f; if (p.HasPlayerForm(PLAYER_FORM_FLIGHT)) p.moveSpeed = p.moveSpeed + 0.2f; @@ -627,15 +897,20 @@ static void speed_evaluate(Entity_Player& p, const StatBonuses& bonus, float cro if (has(COLLECTIBLE_TAURUS) || p.GetZodiacEffect() == COLLECTIBLE_TAURUS) { p.moveSpeed = p.moveSpeed - 0.3f; - if (p.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_TAURUS)) p.moveSpeed = p.taurusSpeedBonus + p.moveSpeed; + if (effects.HasCollectibleEffect(COLLECTIBLE_TAURUS)) p.moveSpeed = p.taurusSpeedBonus + p.moveSpeed; } if (has(300) || p.GetZodiacEffect() == 300) p.moveSpeed = p.moveSpeed + 0.25f; if (has(306) || p.GetZodiacEffect() == 306) p.moveSpeed = p.moveSpeed + 0.2f; if (has(307) || p.GetZodiacEffect() == 307) p.moveSpeed = p.moveSpeed + 0.1f; if (has(314)) p.moveSpeed = p.moveSpeed - 0.4f; if (is_purity(p, PURITY_SPEED)) p.moveSpeed = p.moveSpeed + 0.5f; + if (effects.HasNullEffect(NULLITEM_ERA_WALK)) p.moveSpeed = p.moveSpeed + 0.5f; + if (effects.HasNullEffect(NULLITEM_SPIN_TO_WIN)) p.moveSpeed = p.moveSpeed + 0.5f; + if (effects.HasCollectibleEffect(COLLECTIBLE_DARK_ARTS)) p.moveSpeed = p.moveSpeed + 1; + else if (effects.HasCollectibleEffect(COLLECTIBLE_CAMO_UNDIES)) p.moveSpeed = p.moveSpeed + 0.5f; p.moveSpeed = p.d8SpeedModifier * p.moveSpeed; if (crownScale != 1 && p.moveSpeed > 1) p.moveSpeed = (p.moveSpeed - 1) * (crownScale - 1) + p.moveSpeed; + if (g_game->dailyChallenge._id == DAILY_SLOW) p.moveSpeed = p.moveSpeed - 1; static_cast(g_luaEngine)->EvaluateItems(&p, CACHE_SPEED); } @@ -645,11 +920,12 @@ static void luck_evaluate(Entity_Player& p, const StatBonuses& bonus) { auto n = [&](int id) { return (float)p.GetCollectibleNum(id); }; - float pills = pill_uses(p, PILL_LUCK_UP) - pill_uses(p, PILL_LUCK_DOWN); - float luck = (float)p.luckModifier + bonus.luck + pills + (float)p.donateLuck + p.edenLuck + n(253); + float pills = bonus.isMistOrGhost ? 0 : pill_uses(p, PILL_LUCK_UP) - pill_uses(p, PILL_LUCK_DOWN); + float luck = (float)modifier_get(bonus, p.luckModifier) + bonus.luck + pills + (float)p.donateLuck + p.edenLuck + n(253); for (int id : {46, 343, 355, 439}) luck = n(id) + luck; luck = luck - n(5); luck = n(669) + luck; + luck = (float)p.temporaryEffects.GetNullEffectNum(NULLITEM_SOL) + luck; luck = (float)(p.GetCollectibleNum(632) * 2) + luck; p.luck = n(730) + luck; if (p.HasTrinket(TRINKET_LUCKY_TOE)) p.luck = trinket_num(p, TRINKET_LUCKY_TOE) + p.luck; @@ -662,10 +938,12 @@ static void luck_evaluate(Entity_Player& p, const StatBonuses& bonus) entity->subtype == COLLECTIBLE_FORTUNE_COOKIE && static_cast(entity)->player == &p) wisps++; p.luck = (float)wisps * 0.2f + p.luck; + p.luck = glitched_stat_get(p) + p.luck; if (p.coopBabyBuffTimers[COOP_BUFF_LUCK] > 0) p.luck = p.luck + 2; bulbs_apply(p, p.luck, 2, 0); if (p.HasCollectible(492)) p.luck = p.luck + 1; bulbs_apply(p, p.luck, 0, 1); + if (g_game->dailyChallenge._id == DAILY_LUCKY) p.luck = p.luck + DAILY_LUCK_BONUS; if (g_game->debugFlags & DEBUG_HIGH_LUCK) p.luck = p.luck + DEBUG_LUCK_BONUS; static_cast(g_luaEngine)->EvaluateItems(&p, CACHE_LUCK); @@ -730,19 +1008,13 @@ constexpr std::array WORM_GRANTS = {{{144, false, TEAR_TURN_HO {12, false, TEAR_FLAT}, {96, false, TEAR_BIG_SPIRAL, TEAR_SPECTRAL}}}; -// Whether the player has a collectible, or its temporary effect. -static bool is_having(Entity_Player& p, int collectible) -{ - return p.HasCollectible(collectible) || p.temporaryEffects.HasCollectibleEffect(collectible); -} - // Whether the player is one of the spirits whose tears and lasers glow and pass through rocks: the Lost and its -// tainted and cursed forms, the Soul, the ghost babies, co-op ghosts, Spirit Shackles' soul, and the nulls doing so. +// tainted and cursed forms, the Soul, the Bound and Found Soul babies, co-op ghosts, Spirit Shackles' soul, and the nulls doing so. static bool is_spirit(Entity_Player& p) { TemporaryEffects& effects = p.temporaryEffects; bool isGhostBaby = p.variant == PLAYER_VARIANT_COOP_BABY && - (p.babySkin == BABY_SKIN_GHOST_B || p.babySkin == BABY_SKIN_GHOST_A); + (p.babySkin == BABY_FOUND_SOUL || p.babySkin == BABY_BOUND); return p.playerType == PLAYER_THELOST || p.playerType == PLAYER_THELOST_B || p.playerType == PLAYER_JACOB2_B || p.playerType == PLAYER_THESOUL || isGhostBaby || p.isCoopGhost || effects.GetCollectibleEffectNum(COLLECTIBLE_ASTRAL_PROJECTION) == 1 || @@ -769,7 +1041,7 @@ static void tear_flags_evaluate(Entity_Player& p) if (p.HasTrinket(grant.collectible)) add({grant.bit, grant.otherBit}); bool isHoming = has(182) || is_having(p, 3) || effects.HasCollectibleEffect(192) || has(331) || - (p.variant == PLAYER_VARIANT_COOP_BABY && p.babySkin == BABY_SKIN_SPOON) || + (p.variant == PLAYER_VARIANT_COOP_BABY && p.babySkin == BABY_PSY) || p.hallowedGroundCountdown > 0; bool isSpectral = has(185) || is_having(p, 115) || has(159) || isLudovico || has(336) || has(379) || is_having(p, 358) || is_spirit(p); @@ -829,7 +1101,7 @@ static ColorMod laser_color_get(Entity_Player& p) { auto has = [&](int id) { return p.HasCollectible(id); }; bool isSpoon = is_having(p, 3) || p.temporaryEffects.HasCollectibleEffect(192) || - (p.variant == PLAYER_VARIANT_COOP_BABY && p.babySkin == BABY_SKIN_SPOON); + (p.variant == PLAYER_VARIANT_COOP_BABY && p.babySkin == BABY_PSY); bool isPoison = has(103) || has(317) || has(305) || p.GetZodiacEffect() == 305 || has(459); return color_pick({{is_having(p, 429), colorized(6, 4, 1)}, @@ -862,10 +1134,8 @@ static ColorMod tear_color_get(Entity_Player& p) { auto has = [&](int id) { return p.HasCollectible(id); }; bool isSpoon = is_having(p, 3) || p.temporaryEffects.HasCollectibleEffect(192) || - (p.variant == PLAYER_VARIANT_COOP_BABY && p.babySkin == BABY_SKIN_SPOON); + (p.variant == PLAYER_VARIANT_COOP_BABY && p.babySkin == BABY_PSY); - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::EvaluateItems 00763570 (the deathmatch's tear colour)"); return color_pick( {{is_having(p, 317), color_make({1, 1, 1, 1}, {0.2f, 1, 0.2f, 1}, {0, 0.2f, 0})}, {is_having(p, 257), color_make({1, 1, 1, 1}, {1.8f, 0.9f, 0.3f, 1}, {0.3f, 0, 0})}, @@ -1054,7 +1324,7 @@ static WeaponType weapon_type_get(Entity_Player& p) bool isAzazel = p.playerType == PLAYER_AZAZEL || effects.HasTrinketEffect(TRINKET_AZAZELS_STUMP) || p.playerType == PLAYER_AZAZEL_B; bool isBone = p.playerType == PLAYER_THEFORGOTTEN || p.playerType == PLAYER_THEFORGOTTEN_B || - (p.variant == PLAYER_VARIANT_COOP_BABY && p.babySkin == BABY_SKIN_BONE) || + (p.variant == PLAYER_VARIANT_COOP_BABY && p.babySkin == BABY_BONE) || effects.HasCollectibleEffect(COLLECTIBLE_BERSERK); if (isBone) return WEAPON_BONE; @@ -1154,27 +1424,69 @@ static void libra_balance(Entity_Player& p) p.cacheFlags |= LIBRA_CACHE; } +// Rock Bottom's part of 00763570: each stat the cache asks for never drops below its best, which it keeps. The +// original also skips it while a trinket slot only the constructor writes holds something, always empty. +static void rock_bottom_hold(Entity_Player& p) +{ + if (!p.HasCollectible(COLLECTIBLE_ROCK_BOTTOM) || p.temporaryEffects.isDisabled) return; + + auto hold = [&](uint32_t flag, float& stat, float& best) + { + if (!(p.cacheFlags & flag)) return; + best = std::max(stat, best); + stat = best; + }; + hold(CACHE_DAMAGE, p.damage, p.rockBottomDamage); + if (p.cacheFlags & CACHE_FIREDELAY) + { + p.rockBottomMaxFireDelay = std::max(FIRE_RATE_FRAMES / (p.maxFireDelay + 1), p.rockBottomMaxFireDelay); + p.maxFireDelay = FIRE_RATE_FRAMES / p.rockBottomMaxFireDelay - 1; + } + hold(CACHE_RANGE, p.tearRange, p.rockBottomTearRange); + hold(CACHE_SPEED, p.moveSpeed, p.rockBottomMoveSpeed); + hold(CACHE_LUCK, p.luck, p.rockBottomLuck); + hold(CACHE_SHOTSPEED, p.shotSpeed, p.rockBottomShotSpeed); +} + +// The end of 00763570's speed: a twin's speed is shared, then a player led by another takes its leader's speed, and a +// leader asks the living players it leads to evaluate their speed again. +static void speed_share(Entity_Player& p) +{ + if ((p.cacheFlags & (CACHE_TWIN_SPEED | CACHE_SPEED)) != CACHE_SPEED) return; + + twins_speed_share(p); + if (p.parent && p.parent->is_player()) + { + p.moveSpeed = p.parent->ToPlayer()->moveSpeed; + return; + } + for (Entity_Player* helper : g_game->playerManager.playerList) + if (helper->parent == &p && !helper->isDead) + { + helper->cacheFlags |= CACHE_SPEED; + helper->temporaryEffects.isEvaluateCachePending = true; + } +} + // 00763570 Recomputes what the cache flags ask for: the weapons, then fire delay, damage, shot speed, range, speed and -// luck from the items, pills, modifiers and Binge Eater's foods, then the tear flags and colours, flight, size and -// colour, each section handed to the mods. Then it clamps the stats and works out how fast tears fall. A shot speed -// change redoes the range. Familiars, other characters, effects and run modifiers stop the game when they have work -// to do. +// luck from the items, effects, pills, modifiers and the bonuses, then the tear flags and colours, flight, familiars, +// luck, size and colour, each section handed to the mods. Libra, Rock Bottom and Dogma then reshape the stats, the +// twins and helpers share their speed, and the stats are clamped and the tears' fall worked out. A shot speed change +// redoes the range. The versus mode's stat hooks stop the game. void Entity_Player::EvaluateItems() { - if (!is_character_plain() || is_owning_any(*this, EVALUATION_UNHANDLED_ITEMS)) - reconstruction_missing("Entity_Player::EvaluateItems 00763570 (characters, effects or special items)"); + if (g_game->deathmatchManager.is_active()) + reconstruction_missing("Entity_Player::EvaluateItems 00763570 (the versus mode's stat hooks)"); StatBonuses bonus = stat_bonuses_get(*this); - float crownScale = (float)GetTrinketMultiplier(TRINKET_CRACKED_CROWN) * 0.2f + 1; - if (playerType == PLAYER_BETHANY_B) crownScale *= TAINTED_BETHANY_STAT_SCALE; if (cacheFlags & CACHE_WEAPON) weapons_evaluate(*this); if (cacheFlags & CACHE_SHOTSPEED) cacheFlags |= CACHE_RANGE; if (is_libra(*this) && (cacheFlags & LIBRA_CACHE)) cacheFlags |= LIBRA_CACHE; - if (cacheFlags & CACHE_FIREDELAY) fire_delay_evaluate(*this, bonus, crownScale); - if (cacheFlags & CACHE_DAMAGE) damage_evaluate(*this, bonus, crownScale); - if (cacheFlags & CACHE_SHOTSPEED) shot_speed_evaluate(*this, bonus, crownScale); - if (cacheFlags & CACHE_RANGE) range_evaluate(*this, bonus, crownScale); - if (cacheFlags & CACHE_SPEED) speed_evaluate(*this, bonus, crownScale); + if (cacheFlags & CACHE_FIREDELAY) fire_delay_evaluate(*this, bonus); + if (cacheFlags & CACHE_DAMAGE) damage_evaluate(*this, bonus); + if (cacheFlags & CACHE_SHOTSPEED) shot_speed_evaluate(*this, bonus); + if (cacheFlags & CACHE_RANGE) range_evaluate(*this, bonus); + if (cacheFlags & CACHE_SPEED) speed_evaluate(*this, bonus); if (cacheFlags & CACHE_TEARFLAG) tear_flags_evaluate(*this); if (cacheFlags & CACHE_TEARCOLOR) tear_color_evaluate(*this); if (cacheFlags & CACHE_FLYING) flying_evaluate(*this); @@ -1183,11 +1495,10 @@ void Entity_Player::EvaluateItems() if ((cacheFlags & CACHE_SIZE) && variant == PLAYER_VARIANT_PLAYER) size_evaluate(*this); if (cacheFlags & CACHE_COLOR) color_evaluate(*this); if (is_libra(*this) && (cacheFlags & LIBRA_CACHE)) libra_balance(*this); + rock_bottom_hold(*this); + if (HasCollectible(COLLECTIBLE_DOGMA) && (cacheFlags & CACHE_SPEED)) moveSpeed = std::max(DOGMA_MIN_SPEED, moveSpeed); + speed_share(*this); - twins_speed_share(*this); - if ((cacheFlags & CACHE_SPEED) && std::ranges::any_of(g_game->playerManager.playerList, - [this](Entity_Player* other) { return other->parent == this; })) - reconstruction_missing("Entity_Player::EvaluateItems 00763570 (the speed of a player's helpers)"); if (cacheFlags & CACHE_PICKUP_VISION) g_game->room->isPickupVisionInvalid = true; if (cacheFlags & CACHE_SPEED) moveSpeed = std::max(SPEED_MIN, std::min(SPEED_MAX, moveSpeed)); shotSpeed = std::max(shotSpeed, SHOT_SPEED_MIN); @@ -1202,10 +1513,12 @@ void Entity_Player::EvaluateItems() cacheFlags = 0; } -// The collectibles the frame (00782af0) looks at itself, which its plain path does not cover yet: Judas's kept Book of -// Belial among them. The weapon items are not: the frame and its items' part (update_effects 00794e50) never ask for -// them, their weapons do. Midas' Touch only tints a Gnawed Leaf statue or a frozen player. -constexpr std::array FRAME_ITEMS = {465, 493, 497, 575, 593, 619, 632, 641, 59, 399}; +// The collectibles the frame (00782af0) and its items' part (update_effects 00794e50) look at, which the plain path +// does not cover yet: Judas's kept Book of Belial among them, Jupiter and Berserk!, and the auras and timers of Linger +// Bean, Dad's Ring, 2Spooky, 120 Volt, Monstrance, Venus, Purgatory, Tooth and Nail and IBS. The weapon items are not: +// the frame never asks for them, their weapons do. Midas' Touch only tints a Gnawed Leaf statue or a frozen player. +constexpr int FRAME_ITEMS[] = {465, 493, 497, 575, 593, 619, 632, 641, 59, 399, 594, 704, + 447, 546, 554, 559, 574, 591, 634, 663, 725}; // The trinkets the items' frame (00794e50) looks at that it does not run yet: Faded Polaroid and Extension Cord. constexpr std::array FRAME_TRINKETS = {69, 125}; @@ -1213,6 +1526,6 @@ constexpr std::array FRAME_TRINKETS = {69, 125}; // 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() { - return is_character_plain() && !is_owning_any(*this, FRAME_ITEMS) && !is_owning_any(*this, EVALUATION_UNHANDLED_ITEMS) && + return is_character_plain() && !is_owning_any(*this, FRAME_ITEMS) && std::ranges::none_of(FRAME_TRINKETS, [this](int trinket) { return HasTrinket(trinket); }); } diff --git a/src/entity_player_forgotten.cpp b/src/entity_player_forgotten.cpp index 103abc9..01c7b0d 100644 --- a/src/entity_player_forgotten.cpp +++ b/src/entity_player_forgotten.cpp @@ -1,6 +1,6 @@ #include "entity_player_forgotten.h" #include "tainted_characters.h" -#include "entity_familiar.h" +#include "familiar_gello.h" #include "entity_npc.h" #include "entity_pickup.h" #include "entity_projectile.h" @@ -18,9 +18,6 @@ constexpr int FORGOTTEN_SWAP_COOLDOWN = 15; constexpr int FORGOTTEN_SWAP_HOLD_COOLDOWN = 10; -constexpr int D_INFINITY_FACES = 10; -constexpr int D_INFINITY_FACE_SHIFT = 16; -constexpr int D_INFINITY_FACE_MASK = 0xffff; constexpr uint32_t DROP_HOLD_FRAMES = 120; constexpr uint32_t SPECIAL_DAILY_NO_DROP = 4; constexpr int DROP_TRINKET_TRIES = 2; @@ -637,6 +634,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}, + {EFFECT_UMBILICAL_CORD_HELPER, umbilical_cord_helper_init, nullptr, umbilical_cord_helper_render}, }); std::span player_effect_behaviours() diff --git a/src/entity_player_frame.cpp b/src/entity_player_frame.cpp index 548dfa3..cb6e6cf 100644 --- a/src/entity_player_frame.cpp +++ b/src/entity_player_frame.cpp @@ -5,6 +5,12 @@ #include "entity_player_passives.h" #include "tainted_characters.h" #include "entity_effect.h" +#include "sfx_manager.h" +#include "pocket_items.h" +#include "entity_familiar.h" +#include "entity_tear.h" +#include "entity_laser.h" +#include "entity_knife.h" #include "game.h" #include "key_configs.h" #include "log.h" @@ -48,6 +54,40 @@ constexpr int HELD_ITEM_STATE_SUPLEX = 709; constexpr float HELD_DROP_SPEED = 0.1f; constexpr float BODY_THROWN_DRAG = 0.97f; constexpr int ITEM_STATE_DOCTORS_REMOTE = 47; +constexpr int ITEM_STATE_END_FRAMES = 5; +constexpr int CANDLE_FLAME_TIMEOUT = 60; +constexpr float CANDLE_FLAME_DAMAGE = 23; +constexpr float BOBS_HEAD_DAMAGE = 185; +constexpr float BOBS_HEAD_FALL_BASE = 1.2f; +constexpr float BOBS_HEAD_FALL_SPREAD = 0.2f; +constexpr float BOBS_HEAD_HEIGHT = -33; +constexpr int SHOOP_STATE_FRAMES = 30; +constexpr int SHOOP_LASER_TIMEOUT = 15; +constexpr float SHOOP_DEPTH_BEHIND = -50; +constexpr float SHOOP_DEPTH_FRONT = 3000; +constexpr int BOOMERANG_STATE_FRAMES = 15; +constexpr float BOOMERANG_THROW_SPEED = 15; +constexpr float BOOMERANG_TIMEOUT_SCALE = 0.75f; +constexpr float GLASS_CANNON_SPEED = 10; +constexpr float GLASS_CANNON_SCALE = 5; +constexpr float GLASS_CANNON_DAMAGE_SCALE = 10; +constexpr float GLASS_CANNON_DAMAGE_BASE = 10; +constexpr float FRIEND_BALL_SPEED = 15; +constexpr int CHALLENGE_FRIEND_BALL_FILLED = 33; +constexpr float HELD_SWING_REACH = 6; +constexpr float HELD_SWING_RISE = -14; +constexpr float HELD_SWING_DAMAGE = 109; +constexpr float BLACK_HOLE_SPEED = 34; +constexpr float KEY_THROW_SPEED = 10; +constexpr float SHARP_KEY_SPEED_SCALE = 1.5f; +constexpr float SHARP_KEY_DAMAGE_BASE = 30; +constexpr float ERASER_DAMAGE = 15; +constexpr float FAMILIAR_THROW_SPEED = 10; +constexpr float FAMILIAR_THROW_INHERITANCE = 0.4f; +constexpr float DECAP_BLOOD_SPEED = 0.35f; +constexpr float DECAP_HEAD_X = -24; +constexpr float DECAP_HEAD_Y = -7; +constexpr float GELLO_SPREAD = 10; constexpr int ITEM_STATE_SHOOP_DA_WHOOP = 49; constexpr int POINTY_RIB_BLINK = 7; constexpr int SHOOP_BLINK = 10; @@ -603,6 +643,336 @@ void Entity_Player::ClearDeadEyeCharge() EvaluateItems(); } +// What the item states of 0077b020 read: where the player shoots and its cardinal axis, and whether it aims and +// holds the shot down. +struct ItemStateShot +{ + Vector direction{}; + Vector cardinal{}; + bool isAiming = false; + bool isShootHeld = false; +}; + +// Holds the item over the player's head while its state lasts. +static void item_lift(Entity_Player& p) +{ + if (!p.IsExtraAnimationFinished()) return; + p.PlayExtraAnimation("LiftItem", false); + p.bodySprite.SetLastFrame(); +} + +// Puts an item away after its throw: the state ends in five frames, the first slot is spent and the eyes blink. +static void item_state_spend(Entity_Player& p) +{ + p.itemStateCooldown = ITEM_STATE_END_FRAMES; + p.DischargeActiveItem(ACTIVE_SLOT_PRIMARY, false); + p.blinkTime = 1; + p.PlayExtraAnimation("HideItem", false); +} + +// Plays a sound the seeds may swap for a fart, at a pitch. +static void item_sound_play(int sound, float pitch) +{ + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound, {.pitch = pitch}); +} + +// Spawns what an item state throws from the player, seeded at random. +static Entity* item_throw_spawn(Entity_Player& p, EntityType type, int variant, Vector velocity, int subType = 0) +{ + uint32_t seed = Random(); + return g_game->Spawn( + {.position = p.pos, .velocity = velocity, .spawner = &p, .subType = subType, .type = type, .variant = variant, .seed = seed}); +} + +// The shot of a thrown item: the aim scaled, with the share of the player's movement tears inherit. +static Vector item_throw_velocity(Entity_Player& p, Vector direction, float speed, float inheritance = 1) +{ + return vector_add(vector_scale(direction, speed), + vector_scale(p.GetTearMovementInheritance(direction, INHERIT_CHECKED), inheritance)); +} + +// The Candle's and Red Candle's flames (one more with the Car Battery) and Bob's Rotten Head, thrown along the axis +// the player shoots on with its movement. +static void candle_throw(Entity_Player& p, const ItemStateShot& shot) +{ + constexpr std::array FLAME_SPEEDS = {14, 7}; + int sound = SOUND_CANDLE_LIGHT; + + if (p.itemState == COLLECTIBLE_CANDLE || p.itemState == COLLECTIBLE_RED_CANDLE) + { + if (g_game->deathmatchManager.is_active() || !p.IsLocalPlayer()) + reconstruction_missing("Entity_Player::update_shooting 0077b020 (an online or versus player's flames)"); + bool isCandle = p.itemState == COLLECTIBLE_CANDLE; + int flames = p.HasCollectible(COLLECTIBLE_CAR_BATTERY) ? 2 : 1; + for (int i = 0; i < flames; i++) + { + Vector velocity = vector_add(vector_scale(shot.cardinal, FLAME_SPEEDS[i]), p.lastVelocity); + Entity* flame = item_throw_spawn(p, ENTITY_EFFECT, isCandle ? EFFECT_BLUE_FLAME : EFFECT_RED_CANDLE_FLAME, + velocity); + if (isCandle) static_cast(flame)->SetTimeout(CANDLE_FLAME_TIMEOUT); + flame->SetCollisionDamage(CANDLE_FLAME_DAMAGE); + flame->Update(); + } + } + else + { + Vector velocity = vector_add(vector_scale(shot.cardinal, FLAME_SPEEDS[0]), p.lastVelocity); + auto* head = static_cast(item_throw_spawn(p, ENTITY_TEAR, TEAR_BOBS_HEAD, velocity)); + TearParams params = p.GetTearHitParams(WEAPON_BOMBS, 1, random_below(2) * 2 - 1, nullptr); + head->SetTearFlags(params.tearFlags | p.GetBombFlags(false) | TearFlags().set(TEAR_EXPLOSIVE).set(TEAR_POISON)); + head->SetCollisionDamage(p.damage + BOBS_HEAD_DAMAGE); + head->fallingSpeed = random_unit() * BOBS_HEAD_FALL_SPREAD + BOBS_HEAD_FALL_BASE; + head->SetHeight(BOBS_HEAD_HEIGHT); + head->parent = &p; + head->Update(); + sound = SOUND_SHELLGAME; + } + item_sound_play(sound, 1); + p.PlayExtraAnimation("HideItem", false); + p.itemStateCooldown = ITEM_STATE_END_FRAMES; + p.DischargeActiveItem(ACTIVE_SLOT_PRIMARY, false); + p.blinkTime = 1; +} + +// Shoop da Whoop!'s beam along the axis the player aims on, drawn behind it when aimed up. +static void shoop_fire(Entity_Player& p, const ItemStateShot& shot) +{ + p.itemStateCooldown = SHOOP_STATE_FRAMES; + item_sound_play(SOUND_BLOOD_LASER, 1); + Vector offset = p.GetLaserOffset(LASER_OFFSET_SHOOP, shot.cardinal); + Entity_Laser* laser = Entity_Laser::ShootAngle({.position = p.pos, + .posOffset = offset, + .source = &p, + .angleDegrees = vector_angle(shot.cardinal), + .timeout = SHOOP_LASER_TIMEOUT, + .variant = LASER_SHOOP}); + laser->SetCollisionDamage(p.damage + p.damage); + laser->renderDepthOffset = shot.cardinal.y <= -0.5f ? SHOOP_DEPTH_BEHIND : SHOOP_DEPTH_FRONT; + laser->Update(); + p.DischargeActiveItem(ACTIVE_SLOT_PRIMARY, false); + p.blinkTime = SHOOP_STATE_FRAMES; +} + +// The Boomerang, thrown along the axis the player aims on, flying as long as its tears fall. +static void boomerang_throw(Entity_Player& p, const ItemStateShot& shot) +{ + p.itemStateCooldown = BOOMERANG_STATE_FRAMES; + Vector velocity = vector_add(vector_scale(shot.cardinal, BOOMERANG_THROW_SPEED), p.lastVelocity); + auto* boomerang = static_cast(item_throw_spawn(p, ENTITY_EFFECT, EFFECT_BOOMERANG, velocity)); + boomerang->SetTimeout((int)(-p.tearHeight * BOOMERANG_TIMEOUT_SCALE)); + boomerang->SetCollisionDamage(p.damage + p.damage); + boomerang->parent = &p; + boomerang->Update(); + sound_fart_play(SOUND_BOOMERANG_THROW); + p.blinkTime = BOOMERANG_STATE_FRAMES; + p.DischargeActiveItem(ACTIVE_SLOT_PRIMARY, false); + p.heldSprite.Reset(); + p.RemoveCostume(g_manager->itemConfig.GetNullItem(NULLITEM_BOOMERANG)); +} + +// The Glass Cannon's huge piercing spectral tear, which pushes the player back. +static void glass_cannon_fire(Entity_Player& p, const ItemStateShot& shot) +{ + Vector velocity = item_throw_velocity(p, shot.direction, GLASS_CANNON_SPEED); + Entity_Tear* tear = p.FireTear({p.pos, vector_scale(velocity, p.shotSpeed)}, TEAR_FIRE_NO_EVIL_EYE, nullptr, 1); + tear->SetScale(tear->fScale * GLASS_CANNON_SCALE); + tear->SetCollisionDamage(tear->collisionDamage * GLASS_CANNON_DAMAGE_SCALE + GLASS_CANNON_DAMAGE_BASE); + tear->SetTearFlags(tear->tearFlags | TearFlags().set(TEAR_PIERCING).set(TEAR_SPECTRAL)); + item_sound_play(SOUND_BULLET_SHOT, 1); + p.AddVelocity_divided(vector_scale(velocity, -0.5f), false); + item_state_spend(p); +} + +// The Friend Ball, thrown empty or with the enemy it caught. The challenge filling it at random is not written. +static void friend_ball_throw(Entity_Player& p, const ItemStateShot& shot) +{ + Vector velocity = item_throw_velocity(p, shot.direction, FRIEND_BALL_SPEED); + if (g_game->challenge == CHALLENGE_FRIEND_BALL_FILLED) + reconstruction_missing("Entity_Player::update_shooting 0077b020 (the Friend Ball's challenge enemy)"); + + Entity* ball = item_throw_spawn(p, ENTITY_EFFECT, EFFECT_FRIEND_BALL, velocity, p.friendBallEnemy.type != 0); + ball->parent = &p; + ball->Update(); + sound_fart_play(SOUND_FRIENDLYBALL_THROW); + item_state_spend(p); +} + +// The held knife swing the state 481 makes, as the Bag of Crafting's. +static void held_knife_swing(Entity_Player& p, const ItemStateShot& shot) +{ + uint32_t seed = Random(); + auto* knife = static_cast(g_game->Spawn( + {.position = p.pos, .spawner = &p, .type = ENTITY_KNIFE, .variant = KNIFE_BERSERK_CLUB, .seed = seed})); + knife->parent = &p; + knife->targetPosition = vector_make(HELD_SWING_REACH, 0); + knife->rotation = vector_angle(shot.direction); + knife->posOffset = vector_make(0, HELD_SWING_RISE); + knife->sprite.scale = p.sprite.scale; + knife->SetAttackAnimation(); + knife->swingEffects = 1; + knife->swingTick = 0; + knife->isAttacking = false; + knife->SetCollisionDamage(HELD_SWING_DAMAGE); + knife->Update(); + + p.itemStateCooldown = ITEM_STATE_END_FRAMES; + if (int slot = p.GetActiveItemSlot(p.itemState); slot >= 0) p.DischargeActiveItem(slot, false); + p.blinkTime = 1; + p.PlayExtraAnimation("HideItem", false); + item_sound_play(SOUND_SHELLGAME, random_unit() * 0.2f + 0.9f); +} + +// The Sharp Key's (spending a key) and the Eraser's thrown tear. +static void key_throw(Entity_Player& p, const ItemStateShot& shot) +{ + bool isKey = p.itemState == COLLECTIBLE_SHARP_KEY; + Vector velocity = item_throw_velocity(p, shot.direction, KEY_THROW_SPEED); + if (isKey) velocity = vector_scale(velocity, p.shotSpeed * SHARP_KEY_SPEED_SCALE); + + TearParams params = p.GetTearHitParams(WEAPON_TEARS, 1, 0, &p); + auto* tear = static_cast(item_throw_spawn(p, ENTITY_TEAR, isKey ? TEAR_KEY_BLOOD : TEAR_ERASER, velocity, 1)); + tear->SetHeight(params.tearHeight); + if (!isKey) tear->SetCollisionDamage(ERASER_DAMAGE); + else + { + bool isVersus = g_game->deathmatchManager.is_active(); + tear->SetCollisionDamage(isVersus ? params.tearDamage * 4 + 5 : params.tearDamage * 5 + SHARP_KEY_DAMAGE_BASE); + tear->SetTearFlags(params.tearFlags | TearFlags().set(TEAR_PIERCING)); + } + tear->parent = &p; + tear->Update(); + p.itemStateCooldown = ITEM_STATE_END_FRAMES; + p.DischargeActiveItem(ACTIVE_SLOT_PRIMARY, false); + p.blinkTime = 1; + p.PlayExtraAnimation("HideItem", false); + item_sound_play(SOUND_SHELLGAME, random_unit() * 0.2f + 0.9f); + if (isKey) p.AddKeys(-1); +} + +// Gello's (two with the Car Battery, ten degrees apart) or Decap Attack's head familiar thrown from the player; the +// head leaves a blood burst and Decap Attack's effect. +static void familiar_throw(Entity_Player& p, const ItemStateShot& shot) +{ + Vector aim = item_throw_velocity(p, shot.direction, FAMILIAR_THROW_SPEED, FAMILIAR_THROW_INHERITANCE); + if (p.itemState == COLLECTIBLE_DECAP_ATTACK) + { + Entity* head = item_throw_spawn(p, ENTITY_FAMILIAR, Entity_Familiar::DECAP_ATTACK, {}); + head->ClearEntityFlags(FLAG_APPEAR); + head->AddEntityFlags(FLAG_THROWN); + head->targetPosition = vector_make(DECAP_HEAD_X, DECAP_HEAD_Y); + head->velocity = aim; + static_cast(head)->isNotCountedAsFollower = true; + head->Update(); + uint32_t seed = Random(); + g_game->Spawn({.position = p.pos, .velocity = vector_scale(aim, DECAP_BLOOD_SPEED), .subType = 2, + .type = ENTITY_EFFECT, .variant = EFFECT_BLOOD_EXPLOSION, .seed = seed})->Update(); + p.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_DECAP_ATTACK, true, 2); + item_sound_play(SOUND_DECAP_THROW, 1); + return item_state_spend(p); + } + + bool isDoubled = p.HasCollectible(COLLECTIBLE_CAR_BATTERY); + std::array spreads = isDoubled ? std::array{-GELLO_SPREAD, GELLO_SPREAD} : std::array{}; + for (int i = 0; i < (isDoubled ? 2 : 1); i++) + { + Entity* gello = item_throw_spawn(p, ENTITY_FAMILIAR, Entity_Familiar::UMBILICAL_BABY, {}); + gello->ClearEntityFlags(FLAG_APPEAR); + gello->targetPosition = tear_vector_rotate(vector_normalized(aim), spreads[i]); + static_cast(gello)->isNotCountedAsFollower = true; + gello->Update(); + } + item_sound_play(SOUND_WHIP, 1); + item_state_spend(p); +} + +// The item states' part of 0077b020: the item held up for a throw or a shot fires once the player shoots, and +// interpolation frames only hold it up. An unknown state is logged. +static void item_state_update(Entity_Player& p, const ItemStateShot& shot) +{ + bool isInterpolation = p.HasEntityFlags(FLAG_INTERPOLATION_UPDATE); + + switch (p.itemState) + { + case COLLECTIBLE_BOBS_ROTTEN_HEAD: + case COLLECTIBLE_CANDLE: + case COLLECTIBLE_RED_CANDLE: + item_lift(p); + if (shot.isShootHeld && !isInterpolation) candle_throw(p, shot); + break; + case COLLECTIBLE_DOCTORS_REMOTE: + item_lift(p); + p.trigger_fire_item_effects(shot.direction, true); + if (p.itemState == 0) p.PlayExtraAnimation("HideItem", false); + break; + case COLLECTIBLE_SHOOP_DA_WHOOP: + if (shot.isAiming && !isInterpolation) shoop_fire(p, shot); + break; + case COLLECTIBLE_BOOMERANG: + if (shot.isAiming && !isInterpolation) boomerang_throw(p, shot); + break; + case COLLECTIBLE_GLASS_CANNON: + item_lift(p); + if (shot.isShootHeld && !isInterpolation) glass_cannon_fire(p, shot); + break; + case COLLECTIBLE_FRIEND_BALL: + if (p.IsExtraAnimationFinished()) + { + item_lift(p); + sound_fart_play(SOUND_FRIENDLYBALL_RAISE); + } + if (shot.isShootHeld && !isInterpolation) friend_ball_throw(p, shot); + break; + case COLLECTIBLE_DATAMINER: + item_lift(p); + if (!isInterpolation && shot.isShootHeld) held_knife_swing(p, shot); + break; + case COLLECTIBLE_BLACK_HOLE: + item_lift(p); + if (shot.isShootHeld && !isInterpolation) + { + Vector velocity = vector_add(vector_scale(shot.cardinal, BLACK_HOLE_SPEED), p.lastVelocity); + item_throw_spawn(p, ENTITY_EFFECT, EFFECT_BLACK_HOLE, velocity)->Update(); + sound_fart_play(SOUND_BLACK_HOLE_THROW); + p.PlayExtraAnimation("HideItem", false); + p.itemStateCooldown = ITEM_STATE_END_FRAMES; + p.DischargeActiveItem(ACTIVE_SLOT_PRIMARY, false); + p.blinkTime = 1; + } + break; + case COLLECTIBLE_MOMS_BRACELET: + p.held_throw_update(shot.direction, shot.isShootHeld); + break; + case COLLECTIBLE_SHARP_KEY: + case COLLECTIBLE_ERASER: + item_lift(p); + if (isInterpolation) break; + if (p.itemState == COLLECTIBLE_SHARP_KEY && p.numKeys < 1 && p.itemStateCooldown == 0) + { + p.itemStateCooldown = ITEM_STATE_END_FRAMES; + p.blinkTime = 1; + p.PlayExtraAnimation("HideItem", false); + } + else if (shot.isShootHeld) key_throw(p, shot); + break; + case HELD_ITEM_STATE_SUPLEX: + break; + case COLLECTIBLE_BAG_OF_CRAFTING: + bag_of_crafting_swing(p, shot.direction, !isInterpolation && shot.isShootHeld); + break; + case COLLECTIBLE_GELLO: + case COLLECTIBLE_DECAP_ATTACK: + item_lift(p); + if (!isInterpolation && shot.isShootHeld) familiar_throw(p, shot); + break; + default: + { + std::string message = "No Such State " + std::to_string(p.itemState) + "\n"; + KAGE_LogMessage(LOG_INFO, (uint8_t*)message.data()); + } + } +} + // The weapon that replaces the player's own for a while (part of 0077b020): Doctor's Remote's rocket, Notched Axe, // the Urn of Souls, and Tainted Lilith's umbilical whip, else none. static WeaponType weapon_override_get(Entity_Player& player) @@ -769,13 +1139,12 @@ void Entity_Player::update_shooting() luck = charms + charms + 2 + luck; } float shotLuck = luck; - if (itemState == COLLECTIBLE_BAG_OF_CRAFTING) - bag_of_crafting_swing(*this, shootDirection, !isInterpolation && isShootHeld); - else if (itemState == COLLECTIBLE_MOMS_BRACELET) held_throw_update(shootDirection, isShootHeld); - else if (itemState != 0) reconstruction_missing("Entity_Player::update_shooting 0077b020 (item states)"); - bool isTechFiveReady = itemState == 0 && (canFire || playerType == PLAYER_LILITH || playerType == PLAYER_LILITH_B); - if (isTechFiveReady) tech_five_update(*this, shot); - if (canFire && isFireReady) trigger_fire_item_effects(shootDirection, isShootHeld); + if (itemState != 0) item_state_update(*this, {shootDirection, vector_cardinal(shootDirection), isAiming, isShootHeld}); + else if (canFire || playerType == PLAYER_LILITH || playerType == PLAYER_LILITH_B) + { + tech_five_update(*this, shot); + if (canFire && isFireReady) trigger_fire_item_effects(shootDirection, isShootHeld); + } if (luck == shotLuck) luck = savedLuck; if (!isShootHeld && blinkTime < 0 && headDirectionTime < 0 && game.roomTransition.mode == TRANSITION_NONE) diff --git a/src/entity_player_hits.cpp b/src/entity_player_hits.cpp index cedc241..60cbd08 100644 --- a/src/entity_player_hits.cpp +++ b/src/entity_player_hits.cpp @@ -5,6 +5,7 @@ #include "entity_familiar.h" #include "entity_pickup.h" #include "entity_player.h" +#include "entity_player_characters.h" #include "entity_tear.h" #include "game.h" #include "grid_entity.h" @@ -437,8 +438,7 @@ bool late_items_hit_trigger(Entity_Player& player, const ItemsHit& hit) effects.RemoveCollectibleEffect(COLLECTIBLE_CROWN_OF_LIGHT, 1); player.crownOfLightSprite.Play("FloatNoGlow"); } - if (player.HasCollectible(COLLECTIBLE_CAMBION_CONCEPTION)) - reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Cambion Conception)"); + if (player.HasCollectible(COLLECTIBLE_CAMBION_CONCEPTION)) cambion_conception_hit(player); if (player.HasCollectible(COLLECTIBLE_SHARD_OF_GLASS)) { diff --git a/src/entity_player_items.cpp b/src/entity_player_items.cpp index e67f9ad..940b4b2 100644 --- a/src/entity_player_items.cpp +++ b/src/entity_player_items.cpp @@ -2,6 +2,7 @@ #include "entity_player_trinkets.h" #include "active_items.h" #include "entity_familiar.h" +#include "entity_player_characters.h" #include "entity_pickup.h" #include "stage_transition.h" #include "entity_player_passives.h" @@ -1372,9 +1373,9 @@ static void collectible_effect_apply(Entity_Player& p, const CollectibleGain& ga case 721: late_collectible_gain(p, gain.type, isFirst); return; + case 619: return birthright_gain(p, isFirst); case 588: case 593: - case 619: case 644: case 732: reconstruction_missing( diff --git a/src/entity_player_missing.cpp b/src/entity_player_missing.cpp index a422f92..e5513c2 100644 --- a/src/entity_player_missing.cpp +++ b/src/entity_player_missing.cpp @@ -3,7 +3,6 @@ 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"); } void Entity_Player::use_card_hagalaz(RNG*) { reconstruction_missing("Entity_Player::use_card_hagalaz 005b23f0"); } void Entity_Player::ResetDamageCooldown() { reconstruction_missing("Entity_Player::ResetDamageCooldown 0060d090"); } Vector Entity_Player::SpriteScale() { reconstruction_missing("Entity_Player::SpriteScale 0060d0a0"); } @@ -75,18 +74,10 @@ 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"); } -void Entity_Player::trigger_immaculate_conception(bool) -{ - reconstruction_missing("Entity_Player::trigger_immaculate_conception 007c7d70"); -} void Entity_Player::dash_impact() { reconstruction_missing("Entity_Player::dash_impact 007c8240"); } Entity_Laser* Entity_Player::SpawnMawOfVoid(int) { reconstruction_missing("Entity_Player::SpawnMawOfVoid 007c8dc0"); } void Entity_Player::AddGoldenBomb() { reconstruction_missing("Entity_Player::AddGoldenBomb 007c8f80"); } void Entity_Player::RemoveGoldenBomb() { reconstruction_missing("Entity_Player::RemoveGoldenBomb 007c8fc0"); } -int Entity_Player::GetCambionPregnancyLevel() -{ - reconstruction_missing("Entity_Player::GetCambionPregnancyLevel 007c90b0"); -} Entity* Entity_Player::ShootRedCandle(Vector) { reconstruction_missing("Entity_Player::ShootRedCandle 007c9130"); } Entity* Entity_Player::ShootBlueCandle(Vector) { reconstruction_missing("Entity_Player::ShootBlueCandle 007c9350"); } void Entity_Player::DoZitEffect(Vector) { reconstruction_missing("Entity_Player::DoZitEffect 007c9590"); } diff --git a/src/entity_player_passives.cpp b/src/entity_player_passives.cpp index cf1ab58..393e827 100644 --- a/src/entity_player_passives.cpp +++ b/src/entity_player_passives.cpp @@ -63,7 +63,6 @@ constexpr float OLD_BANDAGE_CHANCE = 0.2f; constexpr float OLD_BANDAGE_LUCK = 0.01f; constexpr float GIMPY_CHANCE = 0.08f; constexpr float GIMPY_LUCK = 0.02f; -constexpr float PICKUP_SPOT_STEP = 40; constexpr float PIGGY_BANK_SPEED = 2; constexpr int INFESTATION_FLIES_MIN = 2; constexpr int INFESTATION_FLIES_RANGE = 5; diff --git a/src/entity_player_pockets.cpp b/src/entity_player_pockets.cpp index baf91f1..8214a20 100644 --- a/src/entity_player_pockets.cpp +++ b/src/entity_player_pockets.cpp @@ -34,8 +34,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 uint8_t WILD_CARD_PILL = 0; -constexpr uint8_t WILD_CARD_CARD = 1; constexpr float CARD_HELD_RISE = -12; constexpr float POCKET_DROP_STEP = 40; diff --git a/src/entity_player_room.cpp b/src/entity_player_room.cpp index 6e84073..1b896f0 100644 --- a/src/entity_player_room.cpp +++ b/src/entity_player_room.cpp @@ -24,7 +24,6 @@ constexpr int VERSUS_EFFECT_COOLDOWN = 300; constexpr int PLAYER_THE_FORGOTTEN_B = 35; constexpr int PLAYER_NO_DOGMA = 40; constexpr int CHALLENGE_FORGOTTEN_COSTUME = 42; -constexpr int BABY_SKIN_WITH_FOLLOWER = 58; constexpr int BETHS_ESSENCE_WISPS = 5; constexpr int BETHS_ESSENCE_CHANCE_DOUBLE = 50; constexpr int BETHS_ESSENCE_CHANCE_TRIPLE = 100; @@ -193,7 +192,7 @@ static void room_items_apply(Entity_Player& player) if (player.variant == PLAYER_VARIANT_COOP_BABY) { player.hasBabyRoomShield = true; - if (player.babySkin == BABY_SKIN_WITH_FOLLOWER) + if (player.babySkin == BABY_BOUND) reconstruction_missing("Entity_Player::room_enter 007a6c50: the co-op baby's follower effect 1000.114"); } else if (player.variant == PLAYER_VARIANT_PLAYER && room.isFirstVisit) diff --git a/src/entity_player_tears.cpp b/src/entity_player_tears.cpp index e59b1f0..dff2811 100644 --- a/src/entity_player_tears.cpp +++ b/src/entity_player_tears.cpp @@ -127,7 +127,6 @@ constexpr int COLLECTIBLE_MOMS_PERFUME = 228; constexpr int COLLECTIBLE_ABADDON = 230; constexpr int COLLECTIBLE_DEATHS_TOUCH = 237; constexpr int COLLECTIBLE_DARK_MATTER = 259; -constexpr int COLLECTIBLE_PROPTOSIS = 261; constexpr int COLLECTIBLE_SAGITTARIUS = 306; constexpr int COLLECTIBLE_PISCES = 309; constexpr int COLLECTIBLE_DEAD_ONION = 336; @@ -137,7 +136,6 @@ constexpr int COLLECTIBLE_PUPULA_DUPLEX = 379; constexpr int COLLECTIBLE_GODS_FLESH = 398; constexpr int COLLECTIBLE_MAW_OF_THE_VOID = 399; constexpr int COLLECTIBLE_EXPLOSIVO = 401; -constexpr int COLLECTIBLE_FRUIT_CAKE = 418; constexpr int COLLECTIBLE_COMPOUND_FRACTURE = 453; constexpr int COLLECTIBLE_SINUS_INFECTION = 459; constexpr int COLLECTIBLE_PARASITOID = 461; @@ -148,7 +146,6 @@ constexpr int COLLECTIBLE_POP = 529; constexpr int COLLECTIBLE_LACHRYPHAGY = 532; constexpr int COLLECTIBLE_MUCORMYCOSIS = 553; constexpr int COLLECTIBLE_TERRA = 592; -constexpr int COLLECTIBLE_SCOOPER = 605; constexpr int COLLECTIBLE_OCULAR_RIFT = 606; constexpr int COLLECTIBLE_LODESTONE = 617; constexpr int COLLECTIBLE_ROTTEN_TOMATO = 618; @@ -163,13 +160,6 @@ constexpr int TRINKET_SUPER_BALL = 99; constexpr int TRINKET_JAW_BREAKER = 129; constexpr int TRINKET_CHEWED_PEN = 130; constexpr int TRINKET_BRAIN_WORM = 144; -constexpr int NULLITEM_BLOOD_OATH = 54; -constexpr int NULLITEM_JUDAS_BIRTHRIGHT = 123; -constexpr int NULLITEM_JUDAS_BIRTHRIGHT_TIMED = 124; -constexpr int NULLITEM_JUDAS_BIRTHRIGHT_PERMANENT = 130; -constexpr int BABY_SHADOW = 13; -constexpr int BABY_BEGOTTEN = 21; -constexpr int BABY_SUPER_GREED = 54; constexpr int FAMILIAR_FINGER = 110; constexpr int FAMILIAR_TWISTED_BABY = 235; constexpr int RED_STEW_BLOOD_FRAMES = 90; diff --git a/src/entity_player_trinkets.cpp b/src/entity_player_trinkets.cpp index d98f7bd..c33f84d 100644 --- a/src/entity_player_trinkets.cpp +++ b/src/entity_player_trinkets.cpp @@ -453,7 +453,7 @@ bool trinket_collect(Entity_Pickup& pickup, Entity_Player& player) uint32_t flags = pickup.isTouched ? QUEUED_TOUCHED : 0; if (id & TRINKET_GOLDEN_FLAG) flags |= QUEUED_GOLDEN; - player.SetQueuedItem({.item = g_manager->itemConfig.GetTrinket(id), .flags = flags}); + player.SetQueuedItem({.item = g_manager->itemConfig.GetTrinket(id), .flags = flags, .itemPoolType = POOL_NONE}); return true; } diff --git a/src/entity_player_weapons.cpp b/src/entity_player_weapons.cpp index 1b021be..05be56b 100644 --- a/src/entity_player_weapons.cpp +++ b/src/entity_player_weapons.cpp @@ -71,8 +71,6 @@ constexpr int COLLECTIBLE_BRIMSTONE_WEAPON = 118; constexpr int COLLECTIBLE_CURSED_EYE_WEAPON = 316; constexpr int COLLECTIBLE_DEAD_TOOTH = 446; constexpr int COLLECTIBLE_EYE_SORE = 558; -constexpr int COLLECTIBLE_INNER_EYE = 2; -constexpr int COLLECTIBLE_NEPTUNUS = 597; // The items GetWeaponModifiers turns into modifier bits, in the order it asks. constexpr std::pair MODIFIER_ITEMS[] = { diff --git a/src/entity_projectile.cpp b/src/entity_projectile.cpp index 32b7ebb..f23c62d 100644 --- a/src/entity_projectile.cpp +++ b/src/entity_projectile.cpp @@ -4,6 +4,7 @@ #include "entity_effect.h" #include "entity_effect_combat.h" #include "entity_familiar.h" +#include "entity_knife.h" #include "entity_pickup.h" #include "entity_player.h" #include "game.h" @@ -48,9 +49,46 @@ constexpr uint64_t CHANGE_BOTH_FLAGS = constexpr uint64_t BURST3_CHILD_CLEARED = PROJECTILE_CURVE_LEFT | PROJECTILE_CURVE_RIGHT | PROJECTILE_SINE_VELOCITY; // The flags whose effects belong to the late bosses and items, and are not reconstructed. -constexpr uint64_t UNRECONSTRUCTED_FLAGS = PROJECTILE_CONTINUUM | PROJECTILE_STASIS | PROJECTILE_FIRE_WAVE | - PROJECTILE_FIRE_WAVE_X | PROJECTILE_FIRE_SPAWN | PROJECTILE_BLUE_FIRE_SPAWN | - PROJECTILE_LASER_SHOT | PROJECTILE_BROCCOLI | PROJECTILE_SIDE_WAVE; +constexpr uint64_t UNRECONSTRUCTED_FLAGS = + PROJECTILE_STASIS | PROJECTILE_LASER_SHOT | PROJECTILE_BROCCOLI | PROJECTILE_SIDE_WAVE; +constexpr uint64_t FIRE_FLAGS = PROJECTILE_FIRE_WAVE | PROJECTILE_FIRE_WAVE_X | PROJECTILE_FIRE_SPAWN; + +// The glow a fiery, Heretic's, blue fire or side wave shot carries. +constexpr KColor GLOW_FIRE = kcolor_rgba(1, 0.2f, 0, 1); +constexpr KColor GLOW_HERETIC = kcolor_rgba(0.8f, 0.2f, 1, 1); +constexpr KColor GLOW_BLUE_FIRE = kcolor_rgba(0.1f, 0.8f, 1, 1); +constexpr KColor GLOW_SIDE_WAVE = kcolor_rgba(1, 0, 0, 1); +constexpr float GLOW_SCALE = 0.75f; +constexpr int GLOW_FADE_FRAMES = 10; + +// The glowing trails: a particle every other tick, its offset a random 0.3 to 1 of its hue. +constexpr float TRAIL_TICKS = 2; +constexpr float TRAIL_GLOW_MIN = 0.3f; +constexpr float TRAIL_GLOW_RANGE = 0.7f; +constexpr float TRAIL_CYAN_GREEN = 0.7f; +constexpr float TRAIL_PURPLE_RED = 0.4f; +constexpr float TRAIL_PURPLE_GREEN = 0.3f; +constexpr float TRAIL_PURPLE_BLUE = 0.7f; +constexpr float TRAIL_PURPLE_SCALE = 0.66f; +constexpr float TRAIL_DEPTH_OFFSET = -5; + +// The fires shots leave: four waves 90 apart, a jet, and fireplaces or flames of a random share of their health +// or size. +constexpr int FIRE_WAVE_COUNT = 4; +constexpr int FIRE_WAVE_SOUND_DELAY = 45; +constexpr float FIRE_WAVE_DIAGONAL = 45; +constexpr int FIRE_LEAVE_ODDS = 10; +constexpr float FIRE_SHARE_RANGE = 0.2f; +constexpr float FIRE_SHARE = 0.4f; +constexpr float BLUE_FIRE_SHARE = 0.6f; +constexpr float BLUE_FLAME_DAMAGE = 6; +constexpr float RED_FLAME_DAMAGE = 12; +constexpr int BLUE_FLAME_TIMEOUT = 150; +constexpr int RED_FLAME_TIMEOUT_MIN = 300; +constexpr int RED_FLAME_TIMEOUT_RANGE = 120; +constexpr int FIREPLACE_RED_MOVING = 10; +constexpr int FIREPLACE_BLUE_MOVING = 12; +constexpr ColorMod BLUE_FIRE_POOF_COLOR = {{1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0.4f, 0.6f}}; // Time: the share a slowed shot keeps, the near stop of a held or paused one, and the Hourglass's fade. constexpr float SLOW_SCALE = 0.5f; @@ -274,7 +312,21 @@ constexpr float WEAK_SHOT_SCALE = 0.8f; constexpr int COLOR_PRIORITY = 255; constexpr int COLOR_PRIORITY_NONE = -1; -constexpr int ENTITY_MR_FRED = 270; +// A Continuum shot wraps 100 past the edges, its colorize stepping every other frame through nine, black at the +// sixth. +constexpr float CONTINUUM_WRAP_MARGIN = -100; +constexpr int CONTINUUM_COLORS = 9; +constexpr int CONTINUUM_DARK_STEP = 5; +constexpr std::array, CONTINUUM_COLORS> CONTINUUM_COLORIZES = {{{1, 0.33f, 1}, + {1, 0.66f, 1}, + {1, 1, 1}, + {0.66f, 0.66f, 0.66f}, + {0.33f, 0.33f, 0.33f}, + {0, 0, 0}, + {0.33f, 0, 0.33f}, + {0.66f, 0, 0.66f}, + {1, 0, 1}}}; + constexpr int ENTITY_TARBOY = 307; constexpr int ENTITY_NECRO = 828; constexpr int ENTITY_SHADY = 888; @@ -398,6 +450,15 @@ static Entity_Effect* effect_spawn(int variant, const Vector& position, Entity* return static_cast(effect); } +// Spawns a moving effect at a position. +static Entity_Effect* effect_spawn_moving(int variant, const Vector& position, const Vector& velocity, Entity* spawner) +{ + uint32_t seed = Random(); + Entity* effect = g_game->Spawn({.position = position, .velocity = velocity, .spawner = spawner, + .type = ENTITY_EFFECT, .variant = variant, .seed = seed}); + return static_cast(effect); +} + // Spawns a shot from a shot, taking on its spawner type and variant as the splits do. static Entity_Projectile* child_spawn(Entity_Projectile& source, const EntitySpawn& spawn) { @@ -681,11 +742,21 @@ void Entity_Projectile::animation_update() } } -// Its first frame after the base update: a Godhead shot takes its aura. +// Its first frame after the base update: a fiery shot glows orange, the Heretic's exploding one purple, a blue fire +// spawning one blue and a side wave one red, and a Godhead shot without a glow takes its aura. void Entity_Projectile::first_frame_update() { - if ((projectileFlags & PROJECTILE_EXPLODE) && spawnerType == ENTITY_HERETIC) - reconstruction_missing("Entity_Projectile::Update 00653070: the Heretic's glowing shot"); + KColor glow{}; + if (projectileFlags & FIRE_FLAGS) glow = GLOW_FIRE; + else if ((projectileFlags & PROJECTILE_EXPLODE) && spawnerType == ENTITY_HERETIC) glow = GLOW_HERETIC; + else if (projectileFlags & PROJECTILE_BLUE_FIRE_SPAWN) glow = GLOW_BLUE_FIRE; + else if (projectileFlags & PROJECTILE_SIDE_WAVE) glow = GLOW_SIDE_WAVE; + if (glow._alpha > 0) + { + effect_light_create( + {.color = glow, .position = pos, .parent = this, .scale = GLOW_SCALE, .fadeFrames = GLOW_FADE_FRAMES}); + return; + } if (!(projectileFlags & PROJECTILE_GODHEAD)) return; uint32_t seed = Random(); @@ -806,14 +877,44 @@ void Entity_Projectile::head_splash() .amount = HEAD_GIBS, .gibFlags = HEAD_GIB_FLAGS}); } -// The trails the late bosses' shots leave, which are not reconstructed. +// A glowing additive trail particle every other tick: cyan behind a blue fire spawning shot, purple and smaller +// behind a Necro's bone. +void Entity_Projectile::glow_trail_spawn(bool isPurple) +{ + Entity_Effect* particle = effect_spawn_moving(EFFECT_HAEMO_TRAIL, pos, vector_scale(velocity, HALF), this); + layer_additive_set(particle->sprite, 0); + particle->posOffset = vector_add(posOffset, vector_make(0, fallingSpeed * HALF)); + float glow = random_unit() * TRAIL_GLOW_RANGE + TRAIL_GLOW_MIN; + ColorMod color = tint_color_make(0, 0, 0, 1); + if (isPurple) + { + color._offset[0] = glow * TRAIL_PURPLE_RED; + color._offset[1] = glow * TRAIL_PURPLE_GREEN; + color._offset[2] = glow * TRAIL_PURPLE_BLUE; + particle->sprite.scale = vector_make(TRAIL_PURPLE_SCALE, TRAIL_PURPLE_SCALE); + } + else + { + color._offset[1] = glow * TRAIL_CYAN_GREEN; + color._offset[2] = glow; + } + particle->SetColor(color, COLOR_PRIORITY_NONE, COLOR_PRIORITY, false, true); + particle->renderDepthOffset = TRAIL_DEPTH_OFFSET; + particle->Update(); +} + +// The trails shots leave: a blue fire spawning shot's and a Necro bone's glow. The Beast's and Mother's are not +// reconstructed. void Entity_Projectile::trails_update() { - bool isNecroBone = spawnerType == ENTITY_NECRO && variant == PROJECTILE_BONE; + if ((projectileFlags & PROJECTILE_BLUE_FIRE_SPAWN) && GetIntervalTicks(TRAIL_TICKS, 0)) glow_trail_spawn(false); + else if (spawnerType == ENTITY_NECRO && variant == PROJECTILE_BONE && GetIntervalTicks(TRAIL_TICKS, 0)) + glow_trail_spawn(true); + bool isBeastFire = (projectileFlags & PROJECTILE_EXPLODE) && spawnerType == ENTITY_BEAST && spawnerVariant == BEAST_FIRE_BALL; bool isMotherShot = spawnerType == ENTITY_MOTHER && spawnerVariant == 0 && subtype == 1; - if (isNecroBone || isBeastFire || isMotherShot) + if (isBeastFire || isMotherShot) reconstruction_missing("Entity_Projectile::Update 00653070: a late boss's shot trail"); } @@ -826,11 +927,97 @@ void Entity_Projectile::death_update() death_poof_spawn(); death_flags_apply(); death_bursts_spawn(); + if (projectileFlags & PROJECTILE_BLUE_FIRE_SPAWN) blue_fire_spawn(); + if (projectileFlags & PROJECTILE_FIRE_SPAWN) fire_spawn(); if (variant == PROJECTILE_HEAD) head_splash(); Remove(); if (variant == PROJECTILE_FIRE && spawnerType == ENTITY_BEAST) npc_sound_play(SOUND_BEAST_FIRE, 1, 2, 1); } +// Part of 00653070: whether the shot is on the players' side, which its fires take. +bool Entity_Projectile::is_friendly_fire() +{ + return HasEntityFlags(FLAG_FRIENDLY) || (projectileFlags & PROJECTILE_CANT_HIT_PLAYER); +} + +// Part of 00653070: four fire waves from where a fire wave shot landed, along the axes (FIRE_WAVE_X: the diagonals, +// keeping the shot's spawner kind). +void Entity_Projectile::fire_waves_spawn(FireWaveShape shape) +{ + npc_sound_play(SOUND_FLAME_BURST, 1, FIRE_WAVE_SOUND_DELAY, 1); + for (int i = 0; i < FIRE_WAVE_COUNT; i++) + { + Entity_Effect* wave = effect_spawn(EFFECT_FIRE_WAVE, pos, spawnerEntity); + wave->parent = this; + if (shape == FIRE_WAVE_CROSS) + { + wave->spawnerType = spawnerType; + wave->spawnerVariant = spawnerVariant; + } + wave->rotation = (float)i * RIGHT_ANGLE_DEGREES + (shape == FIRE_WAVE_CROSS ? FIRE_WAVE_DIAGONAL : 0); + if (is_friendly_fire()) wave->AddEntityFlags(FLAG_FRIENDLY); + } +} + +// Part of 00653070: a fire a shot leaves inside the room: a moving fireplace for an enemy's shot, a player's flame +// (with a timeout) for a friendly one, its health or size a random share. +void Entity_Projectile::fire_leave(const LeftFire& fire) +{ + if (!is_friendly_fire()) + { + Entity* place = g_game->Spawn({.position = pos, .spawner = this, .type = ENTITY_FIREPLACE, + .variant = fire.fireplaceVariant, .seed = Random()}); + place->targetPosition = pos; + place->health = place->health * (random_unit() * FIRE_SHARE_RANGE + fire.share); + return; + } + + Entity_Effect* flame = effect_spawn(fire.flameVariant, pos, this); + if (fire.flameVariant == EFFECT_BLUE_FLAME) + { + flame->spawnerType = ENTITY_PLAYER; + flame->spawnerVariant = 0; + } + flame->scale = random_unit() * FIRE_SHARE_RANGE + fire.share; + flame->SetCollisionDamage(fire.flameDamage); + flame->SetTimeout(fire.timeoutRange > 0 ? random_below(fire.timeoutRange) + fire.timeoutMin + : fire.timeoutMin); +} + +// Part of 00653070: a blue fire spawning shot (a bone one with a crack) lands in a blue poof and leaves a blue fire. +void Entity_Projectile::blue_fire_spawn() +{ + if (variant == PROJECTILE_BONE) npc_sound_play(SOUND_FORTUNE_COOKIE, 1, 2, 1); + if (!g_game->room->IsPositionInRoom(pos, 0)) return; + + Entity* poof = effect_spawn(EFFECT_POOF01, pos, spawnerEntity); + poof->SetColor(BLUE_FIRE_POOF_COLOR, COLOR_PRIORITY_NONE, COLOR_PRIORITY, false, true); + poof->Update(); + fire_leave({.flameDamage = BLUE_FLAME_DAMAGE, + .share = BLUE_FIRE_SHARE, + .fireplaceVariant = FIREPLACE_BLUE_MOVING, + .flameVariant = EFFECT_BLUE_FLAME, + .timeoutMin = BLUE_FLAME_TIMEOUT}); + npc_sound_play(SOUND_CANDLE_LIGHT, 1, 2, 1); +} + +// Part of 00653070: a fire spawning shot bursts in a fire jet, and one in ten inside the room leaves a fire. +void Entity_Projectile::fire_spawn() +{ + Entity* jet = effect_spawn(EFFECT_FIRE_JET, pos, spawnerEntity); + jet->spawnerType = spawnerType; + jet->spawnerVariant = variant; + if (is_friendly_fire()) jet->AddEntityFlags(FLAG_FRIENDLY); + if (random_below(FIRE_LEAVE_ODDS) != 0 || !g_game->room->IsPositionInRoom(pos, 0)) return; + + fire_leave({.flameDamage = RED_FLAME_DAMAGE, + .share = FIRE_SHARE, + .fireplaceVariant = FIREPLACE_RED_MOVING, + .flameVariant = EFFECT_RED_CANDLE_FLAME, + .timeoutMin = RED_FLAME_TIMEOUT_MIN, + .timeoutRange = RED_FLAME_TIMEOUT_RANGE}); +} + // The poof of a dead shot by its variant, or the explosion of an exploding one, tinted its color. void Entity_Projectile::death_poof_spawn() { @@ -1033,6 +1220,9 @@ void Entity_Projectile::death_bursts_spawn() } } + if (projectileFlags & PROJECTILE_FIRE_WAVE) fire_waves_spawn(FIRE_WAVE_PLUS); + if (projectileFlags & PROJECTILE_FIRE_WAVE_X) fire_waves_spawn(FIRE_WAVE_CROSS); + if (projectileFlags & PROJECTILE_BURST8) { pos = vector_sub(pos, vector_scale(gridCollisionVelocity, 2)); @@ -1164,6 +1354,7 @@ void Entity_Projectile::steering_update() creep->SetTimeout(BROWN_CREEP_TIMEOUT); } } + if (projectileFlags & PROJECTILE_CONTINUUM) continuum_update(); orbit_update(); if (projectileFlags & (PROJECTILE_CURVE_LEFT | PROJECTILE_CURVE_RIGHT)) @@ -1211,6 +1402,31 @@ void Entity_Projectile::steering_update() velocity = vector_scale(direction, speed); } +// Part of 00653070: a Continuum shot wraps around the screen's edges, cycling every other frame through a colorize +// of the nine its age picks (pink to white to grey, black, then purple). +void Entity_Projectile::continuum_update() +{ + pos = room_screen_wrap(pos, CONTINUUM_WRAP_MARGIN); + if (!IsFrame(2, (int)index)) return; + + SetColor(continuum_tint_get((int)(updateTime * HALF)), COLOR_PRIORITY_NONE, COLOR_PRIORITY, false, true); +} + +// The tint a Continuum shot or tear takes at a step of its cycle: a colorize of the nine, or black. +ColorMod continuum_tint_get(int step) +{ + ColorMod tint = COLOR_DEFAULT; + step %= CONTINUUM_COLORS; + if (step == CONTINUUM_DARK_STEP) + { + tint._tint[0] = tint._tint[1] = tint._tint[2] = 0; + return tint; + } + for (int i = 0; i < 3; i++) tint._colorize[i] = CONTINUUM_COLORIZES[step][i]; + tint._colorize[3] = 1; + return tint; +} + // The orbits: it circles its target position (or its parent with ORBIT_PARENT, moving along with it), pulled to its // orbit distance. void Entity_Projectile::orbit_update() diff --git a/src/entity_projectile.h b/src/entity_projectile.h index 123adbc..e27a07c 100644 --- a/src/entity_projectile.h +++ b/src/entity_projectile.h @@ -88,6 +88,27 @@ enum ProjectileFlag : uint64_t PROJECTILE_FADEOUT = 1ull << 57 }; +// The four fire waves a fire wave shot leaves: along the axes, or the diagonals. +enum FireWaveShape : int +{ + FIRE_WAVE_PLUS, + FIRE_WAVE_CROSS +}; + +// A fire a shot leaves in the room: a share of a moving fireplace's health (or a flame's size) above a random +// fifth, and for a friendly shot the flame, its damage and timeout (a random range above its least). +struct LeftFire +{ + float flameDamage = 0; + float share = 0; + int fireplaceVariant = 0; + int flameVariant = 0; + int timeoutMin = 0; + int timeoutRange = 0; +}; + +ColorMod continuum_tint_get(int step); + // When a shot's motion hook runs: on its update, or on the interpolation between two. enum ProjectileStep : int { @@ -172,6 +193,13 @@ private: void meat_splash(); void head_splash(); void homing_update(); + void continuum_update(); + void glow_trail_spawn(bool isPurple); + bool is_friendly_fire(); + void fire_waves_spawn(FireWaveShape shape); + void fire_leave(const LeftFire& fire); + void blue_fire_spawn(); + void fire_spawn(); void orbit_update(); void steering_update(); bool wiggles_update(); diff --git a/src/entity_slot.cpp b/src/entity_slot.cpp index 6eb19b7..e71b06c 100644 --- a/src/entity_slot.cpp +++ b/src/entity_slot.cpp @@ -85,8 +85,6 @@ constexpr std::array, 10> DONATION_UNLOCKS = {{{10, 134}, {900, 59}, {999, 138}}}; constexpr int ACHIEVEMENT_BLOOD_BAG = 147; -constexpr int ACHIEVEMENT_BONE_HEARTS = 391; -constexpr int ACHIEVEMENT_ROTTEN_HEARTS = 411; // The pedestals a slot's collectible stands on. constexpr int FORTUNE_PEDESTAL = 1; diff --git a/src/entity_tear_flags.cpp b/src/entity_tear_flags.cpp index e9f82d0..f679c6a 100644 --- a/src/entity_tear_flags.cpp +++ b/src/entity_tear_flags.cpp @@ -200,8 +200,6 @@ constexpr float STEER_ANGLE_RESET = 0.015f; constexpr ColorMod STEER_TINT = {{1, 1, 1, 1}, {0, 0, 0, 0}, {0.35f, 0.45f, 0.5f}}; constexpr float CONTINUUM_MARGIN = -100; constexpr int CONTINUUM_TINT_FRAMES = 2; -constexpr int CONTINUUM_TINT_STEPS = 9; -constexpr int CONTINUUM_BLACK_STEP = 5; // The sticking tears: their growth while stuck, the end of their hold, Explosivo's blast, and Mucormycosis' cloud and // the spores it throws at the enemies nearby. @@ -1278,18 +1276,7 @@ void Entity_Tear::continuum_update() for (Entity* link = child; link; link = link->child) link->pos = vector_add(link->pos, shift); if (!IsFrame(CONTINUUM_TINT_FRAMES, (int)index)) return; - static constexpr std::array, CONTINUUM_TINT_STEPS> RAINBOW = {{ - {1, 0.33f, 1}, {1, 0.66f, 1}, {1, 1, 1}, {0.66f, 0.66f, 0.66f}, {0.33f, 0.33f, 0.33f}, - {0, 0, 0}, {0.33f, 0, 0.33f}, {0.66f, 0, 0.66f}, {1, 0, 1}}}; - ColorMod tint = COLOR_DEFAULT; - int step = FrameCount() / 2 % CONTINUUM_TINT_STEPS; - for (int i = 0; i < 3; i++) - { - if (step == CONTINUUM_BLACK_STEP) tint._tint[i] = 0; - else tint._colorize[i] = RAINBOW[step][i]; - } - if (step != CONTINUUM_BLACK_STEP) tint._colorize[3] = 1; - SetColor(tint, -1, TEAR_COLOR_PRIORITY, false, true); + SetColor(continuum_tint_get(FrameCount() / 2), -1, TEAR_COLOR_PRIORITY, false, true); } // Black Isaac's seed paints the tear black. diff --git a/src/familiar_ai.cpp b/src/familiar_ai.cpp index 10f7126..d63504e 100644 --- a/src/familiar_ai.cpp +++ b/src/familiar_ai.cpp @@ -4,6 +4,7 @@ #include "entity_pickup.h" #include "entity_player.h" #include "entity_tear.h" +#include "familiar_gello.h" #include "game.h" #include "item_pool.h" #include "log.h" @@ -701,9 +702,9 @@ void Entity_Familiar::room_enter() case SPIDER_BABY: case STAR_OF_BETHLEHEM: case LOST_SOUL: - case UMBILICAL_BABY: case BLOOD_PUPPY: case VANISHING_TWIN: reconstruction_missing("Entity_Familiar::room_enter 0062bb70 (this familiar's new room)"); + case UMBILICAL_BABY: umbilical_baby_room_enter(*this); break; case WISP: case ITEM_WISP: pos = GetOrbitPosition(player->pos); break; } diff --git a/src/familiar_evaluate.cpp b/src/familiar_evaluate.cpp index 8c5523e..e73cbbf 100644 --- a/src/familiar_evaluate.cpp +++ b/src/familiar_evaluate.cpp @@ -60,13 +60,11 @@ constexpr FamiliarSource LATE_FAMILIAR_SOURCES[] = {{565, 241}, {697, 242}}; constexpr int TRINKET_APOLLYONS_BEST_FRIEND = 186; constexpr int NULLITEM_SPIN_TO_WIN_FAMILIAR = 131; constexpr int FAMILIAR_SPIN_TO_WIN = 244; -constexpr int COLLECTIBLE_MILK = 436; constexpr int COLLECTIBLE_HALO_OF_FLIES = 10; constexpr int NULLITEM_HALO_FLY_LOSS = 107; constexpr int HALO_FLY_CAP = 10; constexpr int ACHIEVEMENT_CUBE_OF_MEAT_FULL = 144; constexpr int ACHIEVEMENT_BALL_OF_BANDAGES_FULL = 19; -constexpr int COLLECTIBLE_BROWN_NUGGET = 504; constexpr int COLLECTIBLE_SPRINKLER = 516; constexpr int COLLECTIBLE_KEY_BUM = 388; constexpr int COLLECTIBLE_BUM_FRIEND = 144; diff --git a/src/familiar_follow.cpp b/src/familiar_follow.cpp index 3da82d2..415f18c 100644 --- a/src/familiar_follow.cpp +++ b/src/familiar_follow.cpp @@ -1,6 +1,9 @@ #include "entity_familiar.h" #include "entity_effect.h" +#include "familiar_gello.h" +#include "weapon_umbilical_whip.h" #include "entity_player.h" +#include "entity_tear.h" #include "game.h" #include "log.h" #include "manager.h" @@ -11,7 +14,6 @@ // The items, trinkets, challenge and boss the following line answers to. constexpr int COLLECTIBLE_BIG_FAN = 279; -constexpr int COLLECTIBLE_GELLO = 728; constexpr int SIREN_TYPE = 904; // How far behind its leader a follower keeps, closer for Milk and on Child's Leash, and how hard it catches up. @@ -22,6 +24,17 @@ constexpr float FOLLOW_PULL = 0.2f; constexpr float FOLLOW_FRICTION = 0.8f; constexpr float FOLLOW_POSITION_PULL = 0.1f; +// Tainted Lilith's Birthright: the familiars ride Gello in a ring as wide as the riders behind each one and a few +// more (BFFS! wider) past a share of Gello's size, the knife pieces straight ahead. Each rider's spot comes from its +// seed through two steps of two generators. +constexpr float RIDE_SPREAD_BASE = 5; +constexpr float RIDE_SPREAD_BFFS = 1.5f; +constexpr float RIDE_SIZE_SHARE = 0.3f; +constexpr float RIDE_HALF_TURN = 3.14f; +constexpr uint32_t RIDE_SEED_SHIFT = 35; +constexpr uint32_t RIDE_ANGLE_SHIFT = 18; +constexpr int RIDE_STRAIGHT_VARIANTS[] = {213, 214, 223}; + // The followers' places in the Duct Tape formations: a row, a V and a ring. enum FormationMode : uint8_t { @@ -154,7 +167,41 @@ bool Entity_Familiar::IsLilithBirthrightIncubus() Entity* Entity_Familiar::get_incubus_umbilical_whip() { if (!IsLilithBirthrightIncubus()) return nullptr; - reconstruction_missing("Entity_Familiar::get_incubus_umbilical_whip 00612b50"); + + Weapon* held = player->weapons[0] ? player->weapons[0].get() : player->weapons[1].get(); + auto* whip = dynamic_cast(held); + Entity* gello = whip ? whip->GetMainEntity() : nullptr; + return gello && gello->type == ENTITY_FAMILIAR ? gello : nullptr; +} + +// Part of 00612bb0: Tainted Lilith's Birthright puts a follower on its spot about Gello, turned with Gello's body (at the +// player while no Gello is out). The first in the line becomes Gello's child, so the riders chain from it. +static void ride_gello(Entity_Familiar& rider) +{ + Entity* gello = rider.get_incubus_umbilical_whip(); + Vector spot = rider.player->pos; + if (gello) + { + int behind = 0; + for (Entity* next = rider.child; next; next = next->child) + if (next->type == ENTITY_FAMILIAR && static_cast(next)->is_following()) behind++; + float spread = (float)behind + RIDE_SPREAD_BASE; + if (rider.player->HasCollectible(COLLECTIBLE_BFFS)) spread *= RIDE_SPREAD_BFFS; + + RNG seedRng; + seedRng.SetSeed(rider.initSeed, RIDE_SEED_SHIFT); + RNG angleRng; + angleRng.SetSeed(seedRng.Next(), RIDE_ANGLE_SHIFT); + float turn = angleRng.RandomFloat() * RIDE_HALF_TURN; + float reach = gello->size * RIDE_SIZE_SHARE + spread; + Vector offset = vector_make(std::cos(turn + turn) * reach, std::sin(turn + turn) * reach); + if (familiar_listed(RIDE_STRAIGHT_VARIANTS, rider.variant)) offset = vector_make(gello->size * RIDE_SIZE_SHARE, 0); + + auto* data = dynamic_cast(static_cast(gello)->extraData.get()); + spot = vector_add(gello->pos, tear_vector_rotate(offset, data ? data->bodyAngle : 0)); + if (!rider.parent) gello->child = &rider; + } + rider.velocity = vector_sub(spot, rider.pos); } // 0062db20 Joins its player's following line by priority: behind the first familiar of higher or equal rank, ahead of @@ -272,8 +319,8 @@ static Entity* follow_leader_find(Entity_Familiar& familiar, bool isLilithBirthr } // 00612bb0 Trails its leader at a short distance, catching up the further it falls behind. Permanent familiars stay -// put. Tainted Lilith's Incubus, the Siren's charm, RC Remote, Duct Tape, Friendship Necklace and Lilith's Birthright -// arrange the line their own ways, which stops the game. +// put, and Tainted Lilith's Birthright puts the line on Gello. The Siren's charm, RC Remote, Duct Tape, Friendship +// Necklace and Lilith's Birthright arrange the line their own ways, which stops the game where not written. void Entity_Familiar::FollowParent() { if (isSubtype55555) @@ -282,8 +329,7 @@ void Entity_Familiar::FollowParent() velocity = {}; return; } - if (IsLilithBirthrightIncubus()) - return reconstruction_missing("Entity_Familiar::FollowParent 00612bb0 (Tainted Lilith's Incubus)"); + if (IsLilithBirthrightIncubus()) return ride_gello(*this); if (player->spawnerEntity && player->spawnerEntity->type == SIREN_TYPE && player->spawnerEntity->variant == 0 && player->HasEntityFlags(FLAG_SPAWN_STICKY_SPIDERS)) return reconstruction_missing("Entity_Familiar::FollowParent 00612bb0 (the Siren's charm)"); diff --git a/src/familiar_gello.cpp b/src/familiar_gello.cpp new file mode 100644 index 0000000..2aefded --- /dev/null +++ b/src/familiar_gello.cpp @@ -0,0 +1,797 @@ +#include "familiar_gello.h" +#include "beam_renderer.h" +#include "capsule.h" +#include "deathmatch_manager.h" +#include "entity_bomb.h" +#include "entity_collision.h" +#include "entity_list.h" +#include "entity_pickup.h" +#include "entity_player.h" +#include "entity_projectile.h" +#include "entity_tear.h" +#include "game.h" +#include "item_config.h" +#include "manager.h" +#include "npc_ai.h" +#include "npc_caves.h" +#include "room.h" +#include "room_grid.h" +#include + +// Gello's looks by the player's items: the overlay on the head layer, the eye layer and the body. +constexpr int GELLO_BODY_LAYER = 1; +constexpr int GELLO_EYE_LAYER = 3; +constexpr int GELLO_OVERLAY_LAYER = 4; +constexpr std::string_view GELLO_SHEET_BASE = "gfx/familiar/umbilical_baby/base.png"; +constexpr std::string_view GELLO_SHEET_BRIMSTONE = "gfx/familiar/umbilical_baby/brimstone.png"; +constexpr std::string_view GELLO_SHEET_BRIMSTONE_HORNS = "gfx/familiar/umbilical_baby/brimstone_horns.png"; +constexpr std::string_view GELLO_SHEET_DR_FETUS = "gfx/familiar/umbilical_baby/drfetus.png"; +constexpr std::string_view GELLO_SHEET_GODHEAD = "gfx/familiar/umbilical_baby/godhead.png"; +constexpr std::string_view GELLO_SHEET_INNER_EYE = "gfx/familiar/umbilical_baby/innereye.png"; +constexpr std::string_view GELLO_SHEET_IPECAC = "gfx/familiar/umbilical_baby/ipecac.png"; +constexpr std::string_view GELLO_SHEET_MUTANT_SPIDER = "gfx/familiar/umbilical_baby/mutantspider.png"; +constexpr std::string_view GELLO_SHEET_POLYPHEMUS = "gfx/familiar/umbilical_baby/polyphemus.png"; +constexpr std::string_view GELLO_SHEET_PROPTOSIS = "gfx/familiar/umbilical_baby/proptosis.png"; +constexpr std::string_view GELLO_SHEET_TECH_X = "gfx/familiar/umbilical_baby/techx.png"; + +// The body turned eight ways by its facing (right first, clockwise), the head layers that follow the head null, and how +// far the head leans into the facing. +constexpr std::array GELLO_BODY_ANIMS = {"BodySide", "BodySideDown", "BodyDown", "BodySideDown", + "BodySide", "BodySideUp", "BodyUp", "BodySideUp"}; +constexpr int GELLO_BODY_FACING_UP = 6; +constexpr std::array GELLO_HEAD_COPY_LAYERS = {GELLO_EYE_LAYER, GELLO_OVERLAY_LAYER}; +constexpr float GELLO_HEAD_LEAN = 6; +constexpr float GELLO_HEAD_RAISE = 8; + +// The fling: frames hidden at the player, its end, its reach and swing, its ease, the cord's bend point, and the frame +// its hits start. +constexpr float FLING_HIDDEN_FRAMES = 3; +constexpr float FLING_FRAMES = 6; +constexpr float FLING_END = 10; +constexpr float FLING_REACH = 180; +constexpr float FLING_SWING = 20; +constexpr float FLING_SWING_RATE = 10; +constexpr float FLING_EASE = 0.6f; +constexpr float FLING_OVERSHOOT = 1.2f; +constexpr float FLING_WOBBLE = 0.02f; +constexpr float FLING_BEND_REACH = 234; +constexpr float FLING_HITS_START = 4; + +// The fling's whip along the cord: its frames of growth and fall, and its waves. +constexpr float WHIP_RISE_START = 6; +constexpr float WHIP_END = 15; +constexpr float WHIP_WAVES = 0.4f; + +// Cord heights at the player, its middle and the baby. +constexpr float CORD_HEIGHT_PLAYER = -13; +constexpr float CORD_HEIGHT_MIDDLE = -15; +constexpr float CORD_HEIGHT_BABY = -20; +constexpr float CORD_ROOM_ENTER_DROP = 5; + +// The cord's anchor on the player, moved with the body's walk. +constexpr float ANCHOR_SHIFT_X = 6; +constexpr float ANCHOR_SHIFT_Y = 2; + +// The cord's hits: its width (BFFS! wider), Birthright's links, the damage scale, the grid cells it reaches, the shove +// it gives bombs, shots, tears and pickups, Ludovico tears flung faster, and how high a shot it reflects. +constexpr float CORD_HIT_RADIUS = 16; +constexpr float CORD_BFFS_SCALE = 1.5f; +constexpr float CORD_LINKS_MAX = 30; +constexpr float CORD_LINK_DAMAGE = 3; +constexpr float CORD_DAMAGE_SCALE = 3; +constexpr float CORD_SHOVE = 18; +constexpr float CORD_TEAR_SHOVE = 1.25f; +constexpr float CORD_REFLECT_HEIGHT = -50; +constexpr float CORD_GRID_RADIUS = 20; +constexpr float CORD_FIREPLACE_DAMAGE = 1000; +constexpr int CORD_FIREPLACE_HIT_VARIANT = 11; +constexpr int CORD_HIT_COUNTDOWN = 30; +constexpr float CORD_KNOCKBACK = 900; +constexpr float CORD_KNOCKBACK_MASS = 50; +constexpr float CORD_NEAREST_START = 1000000; +constexpr uint32_t CORD_FLY_ODDS = 6; +constexpr int CORD_FLY_LIMIT = 29; +constexpr float CORD_HIT_PITCH = 1.5f; +constexpr int CORD_HIT_DELAY = 10; +constexpr float GELLO_SPLASH_SPEED = 6; +constexpr float GELLO_SPLASH_HEIGHT = -15; +constexpr int GELLO_SPLASH_SUBTYPE = 2; + +// The rope past the fling: its length, its drag and spring, its gravity and floor, the baby's pull back past its leash, +// its drag, and how hard the aim drags it. +constexpr float ROPE_LENGTH = 90; +constexpr float ROPE_DRAG = 0.1f; +constexpr float ROPE_SPRING = 0.7f; +constexpr float ROPE_GRAVITY = 0.05f; +constexpr float ROPE_FLOOR = 0.5f; +constexpr float GELLO_LEASH = 160; +constexpr float GELLO_LEASH_PULL = 0.2f; +constexpr float BABY_DRAG = 0.85f; +constexpr float AIM_PULL = 2; +constexpr float TURN_RATE = 10; + +// The reel back: frames before it may start, its countdown, its wave and how much of it settles a frame. +constexpr float REEL_AFTER = 20; +constexpr float REEL_FRAMES = 5; +constexpr float REEL_WAVE = 4; +constexpr float REEL_SETTLE = 0.8f; + +// The head: how far it looks for enemies and how often, and the frame its shooting look gives way. +constexpr float GELLO_TARGET_RANGE = 800; +constexpr int GELLO_RETARGET_INTERVAL = 8; +constexpr int GELLO_HEAD_FLOAT_FRAME = 9; + +// The cord helper effect's depth, and the cord's look in a water reflection. +constexpr float CORD_HELPER_DEPTH = 10; +constexpr float CORD_REFLECTION_ALPHA = 0.5f; +constexpr int CORD_SPRITE_LAYER = 2; + +// Which part of the cord a draw covers: all of it, the half by the player (the helper effect's) or the half by Gello. +enum CordPart +{ + CORD_WHOLE, + CORD_NEAR_HALF, + CORD_FAR_HALF +}; + +// The reel's states: out, reeling with its offset kept, and coming in. +enum GelloState +{ + GELLO_OUT, + GELLO_REEL_START, + GELLO_REELING +}; + +// Gello's extra data, made on its first frame. +static UmbilicalBabyData* gello_data(Entity_Familiar& gello) +{ + return dynamic_cast(gello.extraData.get()); +} + +// 00431830 Dresses Gello for the player's items: Dr. Fetus's overlay, an eye (Proptosis, Mutant Spider or Inner Eye) +// and a body (Tech X, Godhead, Ipecac or Polyphemus), Brimstone's body and horns over all. +void umbilical_baby_load_graphics(Entity_Familiar& gello) +{ + Entity_Player& owner = *gello.player; + std::string_view overlay = owner.HasCollectible(COLLECTIBLE_DR_FETUS) ? GELLO_SHEET_DR_FETUS : ""; + std::string_view eye = owner.HasCollectible(COLLECTIBLE_PROPTOSIS) ? GELLO_SHEET_PROPTOSIS + : owner.HasCollectible(COLLECTIBLE_MUTANT_SPIDER) ? GELLO_SHEET_MUTANT_SPIDER + : owner.HasCollectible(COLLECTIBLE_INNER_EYE) ? GELLO_SHEET_INNER_EYE + : ""; + std::string_view body = owner.HasCollectible(COLLECTIBLE_TECH_X) ? GELLO_SHEET_TECH_X + : owner.HasCollectible(COLLECTIBLE_GODHEAD) ? GELLO_SHEET_GODHEAD + : owner.HasCollectible(COLLECTIBLE_IPECAC) ? GELLO_SHEET_IPECAC + : owner.HasCollectible(COLLECTIBLE_POLYPHEMUS) ? GELLO_SHEET_POLYPHEMUS + : GELLO_SHEET_BASE; + if (owner.HasCollectible(COLLECTIBLE_BRIMSTONE)) + { + body = GELLO_SHEET_BRIMSTONE; + overlay = GELLO_SHEET_BRIMSTONE_HORNS; + } + + ANM2& sprite = gello.sprite; + sprite.ReplaceSpritesheet(0, body); + sprite.ReplaceSpritesheet(GELLO_BODY_LAYER, body); + sprite.GetLayer(GELLO_EYE_LAYER)->isVisible = !eye.empty(); + if (!eye.empty()) sprite.ReplaceSpritesheet(GELLO_EYE_LAYER, eye); + sprite.GetLayer(GELLO_OVERLAY_LAYER)->isVisible = !overlay.empty(); + if (!overlay.empty()) sprite.ReplaceSpritesheet(GELLO_OVERLAY_LAYER, overlay); + sprite.LoadGraphics(); +} + +// Part of 0060de70: Gello dressed, and the helper effect that draws the cord's near half spawned on its player. +void umbilical_baby_init(Entity_Familiar& gello) +{ + umbilical_baby_load_graphics(gello); + if (!gello.player) return; + + Entity* helper = g_game->Spawn({.position = gello.player->pos, + .type = ENTITY_EFFECT, + .variant = EFFECT_UMBILICAL_CORD_HELPER, + .seed = Random()}); + helper->parent = &gello; + helper->flags |= FLAG_PERSISTENT; + helper->Update(); + gello.linkedEntity = helper; +} + +// A blood splash where the cord strikes or Gello shows. +static void gello_splash(const Vector& position, const Vector& direction) +{ + Entity* splash = g_game->Spawn({.position = position, + .velocity = vector_scale(direction, GELLO_SPLASH_SPEED), + .subType = GELLO_SPLASH_SUBTYPE, + .type = ENTITY_EFFECT, + .variant = EFFECT_BLOOD_EXPLOSION, + .seed = Random()}); + splash->posOffset = vector_make(0, GELLO_SPLASH_HEIGHT); + splash->Update(); +} + +// Its data on the first frame: the cord sprite from its own file, and the player's bone hit params (their damage its +// contact damage). +static UmbilicalBabyData& gello_data_make(Entity_Familiar& gello) +{ + if (UmbilicalBabyData* data = gello_data(gello)) return *data; + + auto made = std::make_unique(); + UmbilicalBabyData& data = *made; + gello.extraData = std::move(made); + data.cordSprite.Load(gello.sprite.filename, GRAPHICS_LOAD); + data.cordSprite.SetFrame("Cord", 0); + TearParams hit = gello.player->GetTearHitParams(WEAPON_BONE, 1, 1, gello.player); + gello.collisionDamage = hit.tearDamage; + data.tearFlags = hit.tearFlags; + return data; +} + +// Part of 00431be0: the head's weapon kept the player's kind, aimed at its target or the player's aim, and the head +// turned the way it shoots. +static void gello_head_update(Entity_Familiar& gello, UmbilicalBabyData& data, bool isInterpolated) +{ + Entity_Player& owner = *gello.player; + Weapon* playerWeapon = owner.weapons[1].get(); + Vector aim = owner.aimDirection; + int direction = owner.fireDirection; + bool isShooting = owner.fireDirection != DIRECTION_NONE; + if (!gello.CanPlayerFire() || gello.state == GELLO_REELING) return; + + Vector marked{}; + gello.PickEnemyTarget({.range = GELLO_TARGET_RANGE, + .frameInterval = gello.target ? GELLO_RETARGET_INTERVAL : 0, + .flags = TARGET_RETARGET | TARGET_NOT_NEAR_PLAYER | TARGET_NO_STICKINESS}); + if (playerWeapon && gello.weapon) + { + gello.TryAimAtMarkedTarget(aim, direction, &marked); + if (vector_is_zero(marked)) marked = gello.pos; + } + if (gello.counter < 1) + { + if (direction == DIRECTION_NONE && + (gello.headFrameDelay < 1 || (direction = gello.shootDirection) == DIRECTION_NONE)) + direction = DIRECTION_DOWN; + if (Entity* focus = gello.weapon ? gello.weapon->GetFocusEntity() : nullptr) + direction = vector_to_direction(vector_sub(focus->pos, gello.pos)); + gello.shootDirection = direction; + data.headAngle = vector_angle(aim); + } + if (playerWeapon && gello.weapon) + { + gello.weapon->fixedDirection = marked; + gello.weapon->maxFireDelay = playerWeapon->maxFireDelay; + gello.weapon->modifiers = playerWeapon->modifiers; + gello.weapon->Update(isInterpolated); + gello.weapon->Fire(aim, isShooting, isInterpolated); + } + if (gello.fireCooldown == 0) + { + if (gello.headFrameDelay < GELLO_HEAD_FLOAT_FRAME) gello.PlayFloatAnim(gello.shootDirection); + else gello.PlayShootAnim(gello.shootDirection); + } + if (isInterpolated) return; + + if (gello.counter > 0) gello.counter--; + if (gello.headFrameDelay > 0) gello.headFrameDelay--; + if (gello.fireCooldown > 0) gello.fireCooldown--; +} + +// Part of 00431be0: the body faces one of eight ways, under the head unless facing up, and the head layers sit on the +// head null leaning into the facing. +static void gello_body_update(Entity_Familiar& gello, UmbilicalBabyData& data) +{ + ANM2& sprite = gello.sprite; + Vector facing = vector_from_angle(data.bodyAngle); + int way = ((int)std::floor(vector_angle(facing) / 45 + 0.5f) + 8) % 8; + sprite.isOverlayRenderFirst = way != GELLO_BODY_FACING_UP; + sprite.PlayOverlay(GELLO_BODY_ANIMS[way]); + sprite.GetLayer(GELLO_BODY_LAYER)->isFlipX = sprite.isFlipX != (way == 0 || way == 1 || way == 7); + + const NullFrame* head = sprite.overlayAnimState.GetNullFrameById(0); + if (!head) return; + + LayerState& face = *sprite.GetLayer(0); + face.pos = vector_make(head->pos.x + facing.x * GELLO_HEAD_LEAN, + head->pos.y - GELLO_HEAD_RAISE + facing.y * GELLO_HEAD_LEAN); + if (sprite.isFlipX) face.pos.x = -face.pos.x; + face.size = head->scale; + for (int layerId : GELLO_HEAD_COPY_LAYERS) + { + LayerState& copy = *sprite.GetLayer(layerId); + copy.pos = face.pos; + copy.size = face.size; + } +} + +// The fling's ease out along the aim: a half cosine to 1.2 at its end, then a fading wobble about 1. +static float fling_reach(float progress) +{ + if (progress < 1) return (1 - std::cos(progress * PI_F)) * FLING_EASE; + if (progress == 1) return FLING_OVERSHOOT; + float past = progress - 1; + return std::sin(past * FLING_SWING_RATE) * FLING_WOBBLE / (progress * progress * past) + 1; +} + +// Part of 00431be0: through the fling Gello flies out along its aim with a sideways swing, and the cord follows a curve +// from the player through a point far down the aim, whipping as it goes. +static void gello_fling(Entity_Familiar& gello, UmbilicalBabyData& data, const Vector& anchor, bool isInterpolated) +{ + Vector aim = gello.targetPosition; + Vector playerPos = gello.player->pos; + data.bodyAngle = vector_angle(aim); + float frame = gello.updateTime + gello.speedMultiplier * (isInterpolated ? 0.5f : 1); + if (!isInterpolated) + { + float progress = (frame - FLING_HIDDEN_FRAMES) / FLING_FRAMES; + Vector side = tear_vector_rotate(aim, aim.x > 0 ? -90.0f : 90.0f); + float swing = progress == 0 ? 1 : std::sin(progress * FLING_SWING_RATE) / (progress * FLING_SWING_RATE); + Vector goal = vector_add(vector_add(playerPos, vector_scale(aim, fling_reach(progress) * FLING_REACH)), + vector_scale(side, swing * FLING_SWING)); + gello.velocity = vector_sub(goal, gello.pos); + } + + Vector bend = vector_add(playerPos, vector_scale(aim, FLING_BEND_REACH)); + Vector end = vector_add(gello.pos, vector_scale(gello.velocity, gello.speedMultiplier * (isInterpolated ? 0.5f : 1))); + auto& points = data.points; + points[0] = {.x = anchor.x, .y = anchor.y, .z = CORD_HEIGHT_PLAYER}; + for (int i = 1; i < CORD_POINT_COUNT; i++) + { + float u = (float)i / (float)(CORD_POINT_COUNT - 1); + float w = 1 - u; + CordPoint& point = points[i]; + point.x = (end.x * u + anchor.x * w) * u + (bend.x * u + anchor.x * w) * w; + point.y = (end.y * u + anchor.y * w) * u + (bend.y * u + anchor.y * w) * w; + point.z = (w * CORD_HEIGHT_PLAYER + u * CORD_HEIGHT_MIDDLE) * w + (w * CORD_HEIGHT_PLAYER + u * CORD_HEIGHT_BABY) * u; + } + + float falling = WHIP_END - frame; + float amplitude = std::max((frame - WHIP_RISE_START) * falling * 0.5f, 0.0f); + float waves = std::max(falling, 0.0f); + for (int i = 1; i < CORD_POINT_COUNT; i++) + { + Vector along = vector_make(points[i].x - points[i - 1].x, points[i].y - points[i - 1].y); + if (vector_is_zero(along)) continue; + + float size = (float)(CORD_POINT_COUNT - i) * (amplitude + amplitude) / (float)CORD_POINT_COUNT; + Vector normal = vector_scale(vector_normalized(vector_make(-along.y, along.x)), size); + float phase = (float)i * waves * WHIP_WAVES; + float wave = std::sin((phase + phase) * PI_F / (float)CORD_POINT_COUNT); + points[i].x += wave * normal.x; + points[i].y += wave * normal.y; + } +} + +// Part of 00431be0: the grid entities the cord's capsule crosses take a hit. +static void cord_grid_hits(Entity_Familiar& gello, const Capsule& cord) +{ + Room& room = *g_game->room; + Vector low{}; + Vector high{}; + cord.get_bounding_box(low, high); + int firstColumn = std::max((int)((low.x - GRID_ORIGIN_X) / GRID_CELL_SIZE + 0.5f), 0); + int firstRow = std::max((int)((low.y - GRID_ORIGIN_Y) / GRID_CELL_SIZE + 0.5f), 0); + int lastColumn = std::min((int)((high.x - GRID_ORIGIN_X) / GRID_CELL_SIZE + 0.5f), room.gridWidth - 1); + int lastRow = std::min((int)((high.y - GRID_ORIGIN_Y) / GRID_CELL_SIZE + 0.5f), room.gridHeight - 1); + for (int column = firstColumn; column <= lastColumn; column++) + for (int row = firstRow; row <= lastRow; row++) + { + GridEntity* grid = room.GetGridEntity((uint32_t)(room.gridWidth * row + column)); + if (!grid) continue; + + Vector center = vector_make((float)(grid->gridIndex % room.gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_X, + (float)(grid->gridIndex / room.gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_Y); + if (Capsule::Collide(Capsule(center, vector_make(1, 1), 0, CORD_GRID_RADIUS), cord)) + grid->Hurt(1, EntityRef(&gello)); + } +} + +// EntityList::query_player_capsule_hits 0041ab50: the tears, enemies, shots (when asked) and pickups the cord's capsule +// touches. +static EntityList_EL cord_hits_query(const Capsule& cord, bool isShotsHit) +{ + EntityList& list = g_game->room->entityList; + EntityList_EL found; + Vector low{}; + Vector high{}; + cord.get_bounding_box(low, high); + Vector center = vector_scale(vector_add(low, high), 0.5f); + Vector extent = vector_scale(vector_sub(high, low), 0.5f); + list.partitions[PARTITION_SHOTS].query_box(found, center, extent); + list.partitions[PARTITION_ENEMIES].query_box(found, center, extent); + if (isShotsHit) list.partitions[PARTITION_PROJECTILES].query_box(found, center, extent); + list.partitions[PARTITION_PICKUPS].query_box(found, center, extent); + std::erase_if(found, [&](Entity* entity) { + return entity->HasEntityFlags(FLAG_NO_QUERY) || !Capsule::Collide(cord, entity->GetCollisionCapsule({})); + }); + return found; +} + +// What the fling's hits carry between entities: the cord, its damage, the hit point nearest Gello and whether any enemy +// was struck. +struct CordStrike +{ + Capsule cord; + Vector nearest{}; + float damage = 0; + float nearestDistance = CORD_NEAREST_START; + bool isHit = false; +}; + +// Part of 00431be0: an enemy the cord strikes is knocked away from the player and hurt (Guppy or Mulligan may make a +// fly of it), its tear effects applied, and the point of the cord by it kept when nearest Gello. +static void cord_enemy_hit(Entity_Familiar& gello, UmbilicalBabyData& data, Entity& enemy, CordStrike& strike) +{ + Entity_Player& owner = *gello.player; + Vector playerPos = owner.pos; + if (enemy.isDead) return; + + Vector away = vector_normalized(vector_sub(enemy.pos, playerPos)); + if (!enemy.HasEntityFlags(FLAG_NO_KNOCKBACK) && enemy.friction != 0) + { + float push = CORD_KNOCKBACK / (enemy.mass + CORD_KNOCKBACK_MASS); + enemy.velocity = vector_add(enemy.velocity, vector_scale(away, push * enemy.speedMultiplier / enemy.friction)); + } + uint64_t damageFlags = 0; + if (enemy.IsVulnerableEnemy(nullptr) && + (owner.HasPlayerForm(PLAYER_FORM_GUPPY) || + (owner.HasCollectible(COLLECTIBLE_MULLIGAN) && Random() % CORD_FLY_ODDS == 0)) && + owner.numBlueFlies <= CORD_FLY_LIMIT) + damageFlags = DAMAGE_SPAWN_FLY; + if (gello.HasEntityFlags(FLAG_BLEED_OUT)) damageFlags |= DAMAGE_SPAWN_TEMP_HEART; + if (enemy.TakeDamage(strike.damage, damageFlags, EntityRef(&owner), CORD_HIT_COUNTDOWN) && + enemy.IsVulnerableEnemy(nullptr)) + { + int sound = SOUND_MEATY_DEATHS; + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound, {.frameDelay = CORD_HIT_DELAY, .pitch = CORD_HIT_PITCH}); + Entity_Tear::ApplyTearFlagEffects(&enemy, gello.pos, data.tearFlags, &gello, strike.damage); + } + if (enemy.pendingDamage < enemy.health) data.isTargetSurvived = true; + + Vector line = vector_sub(gello.pos, playerPos); + float along = vector_dot(vector_sub(enemy.pos, playerPos), line) / vector_length_squared(line); + Vector onCord = vector_add(playerPos, vector_scale(line, along)); + float distance = vector_length_squared(vector_sub(gello.pos, onCord)); + if (distance < strike.nearestDistance) + { + strike.nearest = onCord; + strike.nearestDistance = distance; + } + strike.isHit = true; +} + +// Part of 00431be0: the cord shoves what is not an enemy: bombs away from the player (not her own Dr. Fetus bombs in +// the air), shots reflected, her Ludovico tear flung on, and free pickups away from Gello. +static void cord_other_hit(Entity_Familiar& gello, Entity& entity) +{ + Vector playerPos = gello.player->pos; + bool isListed = EntityList::HitListContains(gello.hitList, entity); + switch (entity.type) + { + case ENTITY_BOMB: + { + auto& bomb = static_cast(entity); + if ((bomb.parent == gello.player && bomb.isFetus && bomb.posOffset.y < 0) || isListed) return; + + hit_list_insert(gello.hitList, entity); + bomb.AddVelocity_divided(vector_scale(vector_normalized(vector_sub(bomb.pos, playerPos)), CORD_SHOVE), false); + return; + } + case ENTITY_PROJECTILE: + { + auto& shot = static_cast(entity); + if (shot.isDead || shot.height <= CORD_REFLECT_HEIGHT) return; + + shot.Reflect(vector_scale(vector_normalized(vector_sub(shot.pos, playerPos)), CORD_SHOVE)); + return; + } + case ENTITY_TEAR: + if (entity.parent != gello.player || !static_cast(entity).tearFlags[TEAR_LUDOVICO] || isListed) + return; + + hit_list_insert(gello.hitList, entity); + entity.velocity = vector_scale(vector_normalized(vector_sub(entity.pos, gello.pos)), CORD_SHOVE * CORD_TEAR_SHOVE); + return; + case ENTITY_PICKUP: + { + auto& pickup = static_cast(entity); + if (pickup.variant == PICKUP_COLLECTIBLE || pickup.price != 0 || pickup.isDead || + pickup.entityCollisionClass == ENTCOLL_NONE || pickup.HasEntityFlags(FLAG_NO_KNOCKBACK) || isListed) + return; + + hit_list_insert(gello.hitList, entity); + pickup.AddVelocity_divided(vector_scale(vector_normalized(vector_sub(pickup.pos, gello.pos)), CORD_SHOVE), false); + return; + } + } +} + +// Part of 00431be0: from the fling's fifth frame the cord from the player to Gello strikes all it touches once a fling, +// wider with BFFS! and, for Tainted Lilith with Birthright, longer and harder with each familiar on it. The first strike +// of a fling cracks and splashes. +static void gello_fling_hits(Entity_Familiar& gello, UmbilicalBabyData& data) +{ + Entity_Player& owner = *gello.player; + CordStrike strike; + strike.damage = gello.collisionDamage * CORD_DAMAGE_SCALE; + float radius = CORD_HIT_RADIUS; + if (owner.playerType == PLAYER_LILITH_B && owner.HasCollectible(COLLECTIBLE_BIRTHRIGHT) && gello.child) + { + float links = 1; + for (Entity* link = gello.child.get(); link && links < CORD_LINKS_MAX; link = link->child.get()) + { + links = std::min(links + 1, CORD_LINKS_MAX); + strike.damage += CORD_LINK_DAMAGE; + } + radius = links + CORD_HIT_RADIUS; + } + if (owner.HasCollectible(COLLECTIBLE_BFFS)) radius *= CORD_BFFS_SCALE; + strike.cord = Capsule(owner.pos, gello.pos, radius); + cord_grid_hits(gello, strike.cord); + + bool isVersus = g_game->deathmatchManager.state >= DEATHMATCH_INTRO; + for (Entity* entity : cord_hits_query(strike.cord, data.tearFlags[TEAR_SHIELDED])) + { + if (entity->size == 0 || entity->entityCollisionClass == ENTCOLL_NONE) continue; + + for (Entity* link = gello.child.get(); link; link = link->child.get()) Entity::ForceCollide(link, entity, false); + bool isEnemy = (isVersus && entity->type == ENTITY_PLAYER) || + (entity->type >= ENTITY_FIRST_ENEMY && entity->type < ENTITY_EFFECT); + if (!isEnemy || entity->HasEntityFlags(FLAG_FRIENDLY)) + { + cord_other_hit(gello, *entity); + continue; + } + if (EntityList::HitListContains(gello.hitList, *entity)) continue; + + if (entity->type != ENTITY_POOP && entity->type != ENTITY_MOVABLE_TNT) hit_list_insert(gello.hitList, *entity); + if (entity->type == ENTITY_FIREPLACE && entity->variant != CORD_FIREPLACE_HIT_VARIANT) + entity->TakeDamage(CORD_FIREPLACE_DAMAGE, 0, EntityRef(gello.parent.get()), CORD_HIT_COUNTDOWN); + else if (entity->type == ENTITY_FROZEN_ENEMY) Entity::ForceCollide(&owner, entity, true); + else if (entity->type != ENTITY_SHOPKEEPER) cord_enemy_hit(gello, data, *entity, strike); + } + + if (!strike.isHit || data.isHitSoundPlayed) return; + + data.isHitSoundPlayed = true; + int sound = SOUND_WHIP_HIT; + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound); + if (!vector_is_zero(strike.nearest)) gello_splash(strike.nearest, gello.targetPosition); +} + +// Part of 00431be0: fire let go past the fling, Gello is reeled in over five frames along a waving cord, and removed +// once in. +static void gello_reel(Entity_Familiar& gello, UmbilicalBabyData& data, const Vector& anchor, bool isInterpolated) +{ + Vector playerPos = gello.player->pos; + if (gello.state == GELLO_REEL_START) data.reelOffset = vector_sub(gello.pos, playerPos); + data.bodyAngle = angle_approach(data.bodyAngle, vector_angle(data.reelOffset), gello.speedMultiplier * TURN_RATE); + gello.state = GELLO_REELING; + float timer = data.reelTimer - gello.speedMultiplier * (isInterpolated ? 0.5f : 1); + if (!isInterpolated) data.reelTimer = timer; + + float left = lerp_clamped(timer, 0, REEL_FRAMES, 0, 1); + float out = (1 - left) * left + left; + Vector end = vector_add(playerPos, vector_scale(data.reelOffset, out)); + Vector side = tear_vector_rotate(vector_normalized(data.reelOffset), 90); + float wave = (REEL_FRAMES - timer) * REEL_WAVE; + float settle = npc_friction_scaled(1 - left * REEL_SETTLE, gello.speedMultiplier); + auto& points = data.points; + points[0].x = anchor.x; + points[0].y = anchor.y; + points[0].z = CORD_HEIGHT_PLAYER; + for (int i = 1; i < CORD_POINT_COUNT; i++) + { + float u = (float)i / (float)(CORD_POINT_COUNT - 1); + float w = 1 - u; + float swing = std::sin((u * timer + u * timer) * PI_F) * wave; + CordPoint& point = points[i]; + point.x = (side.x * swing + end.x * u + playerPos.x * w) * settle + (1 - settle) * point.x; + point.y = (side.y * swing + end.y * u + playerPos.y * w) * settle + (1 - settle) * point.y; + point.z = (u * CORD_HEIGHT_BABY + w * CORD_HEIGHT_MIDDLE) * settle + (1 - settle) * point.z; + } + gello.velocity = {}; + gello.pos = vector_make(points.back().x, points.back().y); + if (data.reelTimer < 0) gello.Remove(); +} + +// 00434e70 A cord point's pull: drag on its motion, a spring past the rest length toward each neighbour there is, and +// gravity down to the floor. +static CordPoint rope_force(const CordPoint& point, const CordPoint* previous, const CordPoint* next, float restLength) +{ + CordPoint force{.x = point.velocityX * -ROPE_DRAG, .y = point.velocityY * -ROPE_DRAG, .z = point.velocityZ * -ROPE_DRAG}; + for (const CordPoint* neighbour : {previous, next}) + { + if (!neighbour) continue; + + float dx = point.x - neighbour->x; + float dy = point.y - neighbour->y; + float dz = point.z - neighbour->z; + float length = std::sqrt(dx * dx + dy * dy + dz * dz); + float stretch = std::max((length - restLength) * (1 / length), 0.0f); + force.x -= dx * ROPE_SPRING * stretch; + force.y -= dy * ROPE_SPRING * stretch; + force.z -= dz * ROPE_SPRING * stretch; + } + force.z += ROPE_GRAVITY - std::max(point.z * ROPE_FLOOR, 0.0f); + return force; +} + +// The cord a step on: each point's motion and pull at a trial state (positions and velocities moved on by a share of a +// rate). +static std::array rope_rates(const std::array& points, + const std::array& rate, float step) +{ + std::array trial = points; + for (int i = 0; i < CORD_POINT_COUNT; i++) + { + trial[i].x += step * rate[i].x; + trial[i].y += step * rate[i].y; + trial[i].z += step * rate[i].z; + trial[i].velocityX += step * rate[i].velocityX; + trial[i].velocityY += step * rate[i].velocityY; + trial[i].velocityZ += step * rate[i].velocityZ; + } + std::array rates{}; + float restLength = ROPE_LENGTH / (float)CORD_POINT_COUNT; + for (int i = 0; i < CORD_POINT_COUNT; i++) + { + CordPoint force = rope_force(trial[i], i > 0 ? &trial[i - 1] : nullptr, + i < CORD_POINT_COUNT - 1 ? &trial[i + 1] : nullptr, restLength); + rates[i] = {.x = trial[i].velocityX, .y = trial[i].velocityY, .z = trial[i].velocityZ, + .velocityX = force.x, .velocityY = force.y, .velocityZ = force.z}; + } + return rates; +} + +// Part of 00431be0: the cord a frame on as a rope (a fourth order Runge-Kutta step of the speed multiplier). +static void rope_step(std::array& points, float dt) +{ + std::array none{}; + auto first = rope_rates(points, none, 0); + auto second = rope_rates(points, first, dt * 0.5f); + auto third = rope_rates(points, second, dt * 0.5f); + auto fourth = rope_rates(points, third, dt); + float sixth = dt / 6; + for (int i = 0; i < CORD_POINT_COUNT; i++) + { + CordPoint& p = points[i]; + p.x += sixth * (second[i].x + second[i].x + first[i].x + third[i].x + third[i].x + fourth[i].x); + p.y += sixth * (second[i].y + second[i].y + first[i].y + third[i].y + third[i].y + fourth[i].y); + p.z += sixth * (second[i].z + second[i].z + first[i].z + third[i].z + third[i].z + fourth[i].z); + p.velocityX += sixth * (second[i].velocityX + second[i].velocityX + first[i].velocityX + third[i].velocityX + + third[i].velocityX + fourth[i].velocityX); + p.velocityY += sixth * (second[i].velocityY + second[i].velocityY + first[i].velocityY + third[i].velocityY + + third[i].velocityY + fourth[i].velocityY); + p.velocityZ += sixth * (second[i].velocityZ + second[i].velocityZ + first[i].velocityZ + third[i].velocityZ + + third[i].velocityZ + fourth[i].velocityZ); + } +} + +// Part of 00431be0: out on its cord Gello is pulled back past its leash and dragged along the aim while fire is held, +// turning to it, and starts its reel when fire is let go. The cord hangs as a rope between the player and it. +static void gello_hold(Entity_Familiar& gello, UmbilicalBabyData& data, const Vector& anchor, const Vector& aim, + bool isShooting, bool isInterpolated) +{ + auto& points = data.points; + rope_step(points, gello.speedMultiplier); + points[0] = {.x = anchor.x, .y = anchor.y, .z = CORD_HEIGHT_PLAYER}; + + float share = isInterpolated ? 0.5f : 1; + if (!isInterpolated) + { + Vector toPlayer = vector_sub(gello.player->pos, gello.pos); + float distance = vector_length(toPlayer); + float pull = std::max((distance - GELLO_LEASH) * (1 / distance), 0.0f); + float speed = gello.speedMultiplier; + float drag = npc_friction_scaled(BABY_DRAG, speed); + gello.velocity = vector_add(vector_scale(gello.velocity, drag), vector_scale(toPlayer, speed * pull * GELLO_LEASH_PULL)); + if (isShooting) + { + gello.velocity = vector_add(gello.velocity, vector_scale(aim, AIM_PULL * speed)); + data.bodyAngle = angle_approach(data.bodyAngle, vector_angle(aim), speed * TURN_RATE); + } + else if (!gello.isNotCountedAsFollower) gello.state = GELLO_REEL_START; + } + Vector next = vector_add(gello.pos, vector_scale(gello.velocity, gello.speedMultiplier * share)); + points.back() = {.x = next.x, .y = next.y, .z = CORD_HEIGHT_BABY}; +} + +// 00431be0 Tainted Lilith's Gello on its frame: hidden for its first frames, it shows with a splash, flings out along +// the whip's aim striking all the cord touches, then hangs on a rope shooting with the player's weapon until fire is +// let go and it is reeled in. +void Entity_Familiar::ai_umbilical_baby(bool isInterpolated) +{ + if (player->isDead) return; + + UmbilicalBabyData& data = gello_data_make(*this); + if (updateTime < FLING_HIDDEN_FRAMES || (!isVisible && isInterpolated)) + { + isVisible = false; + pos = player->pos; + return; + } + if (!isVisible) gello_splash(pos, targetPosition); + isVisible = true; + Weapon* playerWeapon = player->weapons[1].get(); + if (!isInterpolated && !playerWeapon) weapon.reset(); + else if (!isInterpolated && (!weapon || weapon->weaponType != playerWeapon->weaponType)) + weapon = weapon_create(playerWeapon->weaponType, this); + + Vector aim = player->aimDirection; + bool isShooting = player->fireDirection != DIRECTION_NONE; + Vector walk = player->GetBodyMoveDirection(); + Vector anchor = vector_make(player->pos.x + walk.x * ANCHOR_SHIFT_X, player->pos.y + walk.y * ANCHOR_SHIFT_Y); + gello_head_update(*this, data, isInterpolated); + gello_body_update(*this, data); + + if (updateTime <= FLING_END) + { + gello_fling(*this, data, anchor, isInterpolated); + if (updateTime > FLING_HITS_START) gello_fling_hits(*this, data); + return; + } + if (state > GELLO_OUT && headFrameDelay < 1 && updateTime > REEL_AFTER) return gello_reel(*this, data, anchor, isInterpolated); + gello_hold(*this, data, anchor, aim, isShooting, isInterpolated); +} + +// 00435290 Draws the cord (all of it or one half) as a strip of the cord sprite through its points, flipped and faded +// in a water reflection. Online play's faded remote players are not reconstructed. +static void umbilical_cord_render(Entity_Familiar& gello, const Vector& offset, CordPart part) +{ + UmbilicalBabyData* data = gello_data(gello); + if (!data) return; + + bool isReflected = g_game->room->entityList.renderMode == RENDER_WATER_REFLECT; + ColorMod color = COLOR_DEFAULT; + if (isReflected) color._tint[3] = CORD_REFLECTION_ALPHA; + float heightSign = isReflected ? -1.0f : 1.0f; + int first = part == CORD_FAR_HALF ? CORD_POINT_COUNT / 2 : 0; + int last = part == CORD_NEAR_HALF ? CORD_POINT_COUNT / 2 : CORD_POINT_COUNT - 1; + if (first >= last) return; + + g_beamRenderer.Begin(data->cordSprite, CORD_SPRITE_LAYER, BEAM_FRAME_MAIN, BEAM_COORDINATE_HEIGHTS); + for (int i = first; i <= last; i++) + { + const CordPoint& point = data->points[i]; + Vector screen = render_position_get(vector_make(point.x, heightSign * point.z + point.y), RENDER_SNAPPED); + g_beamRenderer.Add({.color = color, + .pos = vector_add(screen, offset), + .coordinate = (float)i / (float)(CORD_POINT_COUNT - 1), + .width = 1}); + } + g_beamRenderer.End(); +} + +// 00435130 Draws Gello: its cord (the far half when the helper effect draws the near one), then itself. +void umbilical_baby_render(Entity_Familiar& gello, const Vector& offset) +{ + umbilical_cord_render(gello, offset, gello.linkedEntity ? CORD_FAR_HALF : CORD_WHOLE); + gello.Entity::Render(offset); +} + +// Part of 0062bb70: on a new room the cord hangs still on the player, dropping a little toward Gello. +void umbilical_baby_room_enter(Entity_Familiar& gello) +{ + UmbilicalBabyData* data = gello_data(gello); + if (!data) return; + + for (int i = 0; i < CORD_POINT_COUNT; i++) + { + float u = lerp_clamped((float)i, 0, (float)(CORD_POINT_COUNT - 1), 0, 1); + data->points[i] = {.x = gello.player->pos.x, .y = gello.player->pos.y, .z = CORD_HEIGHT_MIDDLE - u * CORD_ROOM_ENTER_DROP}; + } +} + +// Part of 005cdb20: the cord helper draws in front of what stands on its spot. +void umbilical_cord_helper_init(Entity_Effect& helper) +{ + helper.renderDepthOffset = CORD_HELPER_DEPTH; +} + +// Part of 00607620: the cord helper draws the near half of its Gello's cord. +void umbilical_cord_helper_render(Entity_Effect& helper, const Vector& offset) +{ + if (helper.parent && helper.parent->type == ENTITY_FAMILIAR) + umbilical_cord_render(*static_cast(helper.parent.get()), offset, CORD_NEAR_HALF); +} diff --git a/src/familiar_gello.h b/src/familiar_gello.h new file mode 100644 index 0000000..19c09d4 --- /dev/null +++ b/src/familiar_gello.h @@ -0,0 +1,41 @@ +#pragma once + +#include "entity_effect.h" +#include "entity_familiar.h" +#include + +// A point of Gello's cord: where it hangs (z its height, negative up) and how it moves. +struct CordPoint +{ + float x = 0; + float y = 0; + float z = 0; + float velocityX = 0; + float velocityY = 0; + float velocityZ = 0; +}; + +constexpr int CORD_POINT_COUNT = 10; + +// Destruction (00431790) is the default, and last_point (00435590) is points.back(). +// Tainted Lilith's Gello (familiar 240): the cord's points and sprite, the hit params its fling deals, whether the fling +// hit something that lived and played its sound, the reel's countdown and offset, and where the head and body face. +struct UmbilicalBabyData : Entity_Familiar::ExtraData +{ + std::array points{}; + ANM2 cordSprite; + TearFlags tearFlags; + Vector reelOffset{}; + float bodyAngle = 0; + float headAngle = 0; + float reelTimer = 5; + bool isHitSoundPlayed = false; + bool isTargetSurvived = false; +}; + +void umbilical_baby_load_graphics(Entity_Familiar& gello); +void umbilical_baby_init(Entity_Familiar& gello); +void umbilical_baby_render(Entity_Familiar& gello, const Vector& offset); +void umbilical_baby_room_enter(Entity_Familiar& gello); +void umbilical_cord_helper_init(Entity_Effect& helper); +void umbilical_cord_helper_render(Entity_Effect& helper, const Vector& offset); diff --git a/src/familiar_missing.cpp b/src/familiar_missing.cpp index abb2336..fc03ea0 100644 --- a/src/familiar_missing.cpp +++ b/src/familiar_missing.cpp @@ -3,12 +3,6 @@ // The rest of Entity_Familiar, which the familiars this round does not reach call: each stops the game with its name. -// 00431be0 -void Entity_Familiar::ai_umbilical_baby(bool) -{ - reconstruction_missing("Entity_Familiar::ai_umbilical_baby 00431be0"); -} - // 00436330 // 00436fd0 @@ -57,12 +51,6 @@ void Entity_Familiar::AddToDelayed() reconstruction_missing("Entity_Familiar::AddToDelayed 00613fe0"); } -// 0062a8f0 -bool Entity_Familiar::CanPlayerFire() -{ - reconstruction_missing("Entity_Familiar::CanPlayerFire 0062a8f0"); -} - // 0061a240 void Entity_Familiar::ai_blue_babys_only_friend() { @@ -75,10 +63,11 @@ void Entity_Familiar::ai_orbital_variant_50() reconstruction_missing("Entity_Familiar::ai_orbital_variant_50 0061c150"); } -// 0062c8d0 +// 0062c8d0 A pill's effect on the player's familiars: only Acid Baby and Lil Spewer react, which is not written yet. void Entity_Familiar::farting_baby_fart() { - reconstruction_missing("Entity_Familiar::farting_baby_fart 0062c8d0"); + if (variant != ACID_BABY && variant != LIL_SPEWER) return; + reconstruction_missing("Entity_Familiar::farting_baby_fart 0062c8d0 (Acid Baby and Lil Spewer)"); } // 0062e120 diff --git a/src/familiar_shoot.cpp b/src/familiar_shoot.cpp index ec11ce2..47b9f76 100644 --- a/src/familiar_shoot.cpp +++ b/src/familiar_shoot.cpp @@ -33,6 +33,9 @@ constexpr int MIMIC_ROBO_BABY = 4; constexpr int MIMIC_ROTTEN_BABY = 9; constexpr float ROTTEN_FLY_RANGE = 200; +// Gello aims at its own target once its fling is over. +constexpr float GELLO_AIM_AFTER = 10; + // 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; @@ -224,15 +227,12 @@ static Vector target_position(Entity& target) return vector_scale(vector_add(target.prevPosition, target.pos), 0.5f); } -// 006146e0 Aims at what its King Baby targets, else at the mark Marked or Eye of the Occult place, with the direction -// to face. Gello's aim stops the game. +// 006146e0 Aims Gello past its fling at its target, a follower at what its King Baby targets, else at the mark Marked +// or Eye of the Occult place, with the direction to face. bool Entity_Familiar::TryAimAtMarkedTarget(Vector& aimDirection, int& direction, Vector* targetPosition) { - if (variant == UMBILICAL_BABY && updateTime > 10 && target) - reconstruction_missing("Entity_Familiar::TryAimAtMarkedTarget 006146e0 (Gello)"); - - Entity* aimed = nullptr; - if (isFollower) + Entity* aimed = variant == UMBILICAL_BABY && updateTime > GELLO_AIM_AFTER ? target.get() : nullptr; + if (!aimed && isFollower) { Entity* king = IsLilithBirthrightIncubus() ? get_incubus_umbilical_whip() : nullptr; for (Entity* ahead = this; !king && ahead && ahead->type == ENTITY_FAMILIAR; ahead = ahead->parent) @@ -629,13 +629,20 @@ Entity_Laser* Entity_Familiar::fire_robo_baby_laser(const Vector& direction) return laser; } +// 0062a8f0 Whether the player may fire: not in an animation or a stage transition, and in control. +bool Entity_Familiar::CanPlayerFire() +{ + return !player->isPlayingExtraAnimation && !player->isPlayingItemAnimation && + g_game->stageTransition.state == STAGE_TRANSITION_NONE && player->isControlsEnabled && + player->controlsCooldown < 1; +} + // 0062e620 Keeps a copying familiar's weapon (Incubus' and the like) the kind its player's is, then aims and fires it // as the player shoots, unless the player is busy or cannot move: at the player's mark, at random for Cain's Other Eye, // with the player's fire delay (halved by Forgotten Lullaby) and a fixed aim. The head turns to the shot, and the // counters count down on real frames. void Entity_Familiar::update_weapon(bool isInterpolated) { - Game& game = *g_game; if (player->isDead) return; Weapon* playerWeapon = player->weapons[1].get(); @@ -645,10 +652,7 @@ void Entity_Familiar::update_weapon(bool isInterpolated) weapon.reset(); weapon = weapon_create(playerWeapon->weaponType, this); } - bool isPlayerBusy = player->isPlayingExtraAnimation || player->isPlayingItemAnimation || - game.stageTransition.state != STAGE_TRANSITION_NONE || !player->isControlsEnabled || - player->controlsCooldown > 0; - if (isPlayerBusy) return; + if (!CanPlayerFire()) return; Vector aim = player->aimDirection; int direction = player->fireDirection; @@ -797,10 +801,7 @@ void Entity_Familiar::ai_incubus_shot() 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 (CanPlayerFire()) { if (direction == DIRECTION_NONE) { diff --git a/src/game_save.cpp b/src/game_save.cpp index 222a467..a2bf386 100644 --- a/src/game_save.cpp +++ b/src/game_save.cpp @@ -11,7 +11,6 @@ constexpr int CHALLENGE_SPEED = 22; constexpr int CHARGER_MY_SHADOW = 1; constexpr int FAMILIAR_UMBILICAL_BABY = 240; -constexpr int COLLECTIBLE_VENTRICLE_RAZOR = 396; constexpr int REWIND_DOOR_FRAMES = 15; constexpr int ROOM_REF_MODE_SHIFT = 16; constexpr int ROOM_REF_HALF_SHIFT = 16; diff --git a/src/game_state.cpp b/src/game_state.cpp index e89a8ae..d6b9210 100644 --- a/src/game_state.cpp +++ b/src/game_state.cpp @@ -55,8 +55,6 @@ constexpr int HISTORY_KIND_SHIFT = 24; constexpr uint32_t HISTORY_ID_MASK = 0xffffff; constexpr int ITEM_KIND_NULL = 0; constexpr int ITEM_KIND_TRINKET = 2; -constexpr uint8_t WILD_CARD_POCKET = 1; -constexpr uint8_t WILD_CARD_ACTIVE = 2; constexpr int UNSET_PLAYER_WORDS = 2; // The Death Certificate floor's way back as a saved run keeps it: three words and two flags. @@ -1155,7 +1153,7 @@ bool StateReader::player_read(GameStatePlayer& player) "[warn] Invalid active item wildcard effect %d\n")) return false; bool isCardValid = player.wildCardItem <= 0 || items.GetCard(player.wildCardItem); - if (player.wildCardItemType == WILD_CARD_POCKET && !isCardValid) + if (player.wildCardItemType == WILD_CARD_CARD && !isCardValid) return fail(LOG_INFO, "[warn] Invalid pocket item wildcard effect (type: %d, id: %d)\n", player.wildCardItemType, player.wildCardItem); } diff --git a/src/grid_entity_rock.cpp b/src/grid_entity_rock.cpp index 95f6586..0e5039e 100644 --- a/src/grid_entity_rock.cpp +++ b/src/grid_entity_rock.cpp @@ -48,7 +48,6 @@ constexpr uint32_t MIXED_BACKDROP_ODDS = 10; // The Shiny Rock's glint: its period, faster for a stronger rock, the frames it lasts, peaking halfway, and how bright. // The Book of Secrets glows for its effect's last frames. -constexpr int COLLECTIBLE_BOOK_OF_SECRETS = 287; constexpr int COLLECTIBLE_KEEPERS_KIN = 717; constexpr int SHINE_PERIOD = 300; constexpr int SHINE_PERIOD_STRONG = 150; diff --git a/src/item_config.h b/src/item_config.h index b6d5627..ee7e449 100644 --- a/src/item_config.h +++ b/src/item_config.h @@ -82,7 +82,9 @@ enum CacheFlag : uint32_t CACHE_SIZE = 0x800, CACHE_COLOR = 0x1000, CACHE_PICKUP_VISION = 0x2000, - CACHE_ALL = 0xffff + CACHE_ALL = 0xffff, + // Marks the speed a twin evaluates while its twin shares it, so it does not share back. + CACHE_TWIN_SPEED = 0x80000000 }; // An item's tags, as items.xml names them in "tags". @@ -219,20 +221,48 @@ enum CardId : int CARD_ANCIENT_RECALL = 53, CARD_ERA_WALK = 54, RUNE_SHARD = 55, + CARD_REVERSE_FOOL = 56, CARD_REVERSE_MAGICIAN = 57, CARD_REVERSE_HIGH_PRIESTESS = 58, CARD_REVERSE_EMPRESS = 59, CARD_REVERSE_EMPEROR = 60, + CARD_REVERSE_HIEROPHANT = 61, + CARD_REVERSE_LOVERS = 62, + CARD_REVERSE_CHARIOT = 63, + CARD_REVERSE_JUSTICE = 64, + CARD_REVERSE_HERMIT = 65, + CARD_REVERSE_WHEEL_OF_FORTUNE = 66, CARD_REVERSE_STRENGTH = 67, CARD_REVERSE_HANGED_MAN = 68, CARD_REVERSE_DEATH = 69, CARD_REVERSE_TEMPERANCE = 70, CARD_REVERSE_DEVIL = 71, + CARD_REVERSE_TOWER = 72, + CARD_REVERSE_STARS = 73, CARD_REVERSE_MOON = 74, + CARD_REVERSE_SUN = 75, CARD_REVERSE_JUDGEMENT = 76, + CARD_REVERSE_WORLD = 77, CARD_CRACKED_KEY = 78, CARD_QUEEN_OF_HEARTS = 79, - CARD_WILD = 80 + CARD_WILD = 80, + CARD_SOUL_ISAAC = 81, + CARD_SOUL_MAGDALENE = 82, + CARD_SOUL_CAIN = 83, + CARD_SOUL_JUDAS = 84, + CARD_SOUL_BLUEBABY = 85, + CARD_SOUL_EVE = 86, + CARD_SOUL_SAMSON = 87, + CARD_SOUL_AZAZEL = 88, + CARD_SOUL_LAZARUS = 89, + CARD_SOUL_EDEN = 90, + CARD_SOUL_LOST = 91, + CARD_SOUL_LILITH = 92, + CARD_SOUL_KEEPER = 93, + CARD_SOUL_APOLLYON = 94, + CARD_SOUL_FORGOTTEN = 95, + CARD_SOUL_BETHANY = 96, + CARD_SOUL_JACOB = 97 }; // Whether a pill effect is the good (+) or bad (-) side of its class, as pocketitems.xml writes "class". diff --git a/src/item_overlay.h b/src/item_overlay.h index eb2d22f..f5a9ed6 100644 --- a/src/item_overlay.h +++ b/src/item_overlay.h @@ -23,6 +23,7 @@ enum GiantbookOverlay : int { GIANTBOOK_ETERNAL_SOUL_HEART = 6, GIANTBOOK_ETERNAL_HEART = 13, + GIANTBOOK_HOURGLASS = 14, GIANTBOOK_NECRONOMICON = 12, GIANTBOOK_MISSING_PAGE_2 = 31, GIANTBOOK_CLICKER = 39, @@ -40,6 +41,7 @@ enum GiantbookOverlay : int GIANTBOOK_BERKANO = 26, GIANTBOOK_ALGIZ = 27, GIANTBOOK_REVERSE_DEVIL = 10, + GIANTBOOK_REVERSE_SUN = 43, GIANTBOOK_REVERSE_EMPRESS = 42, GIANTBOOK_DEVIL = 34 }; diff --git a/src/item_pickup.cpp b/src/item_pickup.cpp index c6a79b6..f638368 100644 --- a/src/item_pickup.cpp +++ b/src/item_pickup.cpp @@ -544,7 +544,7 @@ bool Entity_Pickup::collectible_collect(Entity_Player& player) reconstruction_missing("Entity_Pickup::HandleCollision 006e8ae0: the deathmatch's items"); SetAlternatePedestal(alternatePedestal); - player.SetQueuedItem({item, heldCharge, isRetaken ? QUEUED_TOUCHED : 0u, heldVarData}); + player.SetQueuedItem({item, heldCharge, isRetaken ? QUEUED_TOUCHED : 0u, heldVarData, itemPoolType}); if (!isRetaken && game.room->roomType == ROOM_ANGEL) g_manager->persistentGameData.IncreaseEventCounter(EVENT_ANGEL_ITEMS_TAKEN, 1); diff --git a/src/item_pool.cpp b/src/item_pool.cpp index 0ebfc29..b8cd47b 100644 --- a/src/item_pool.cpp +++ b/src/item_pool.cpp @@ -93,7 +93,6 @@ constexpr int BOSS_THE_FALLEN = 23; constexpr int HOME_CHEST_SUBTYPE = 2; constexpr int COLLECTIBLE_ROSARY = 72; -constexpr int COLLECTIBLE_CHAOS = 402; constexpr uint32_t CHALLENGE_ONANS_STREAK = 29; constexpr int ACHIEVEMENT_GOLDEN_TRINKETS = 617; constexpr int ACHIEVEMENT_GOLD_PILLS = 603; diff --git a/src/level.cpp b/src/level.cpp index 95a9fca..5d04f86 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -3059,10 +3059,24 @@ int Level::GetRandomRoomIndex(bool isErrorRoom, uint32_t seed) return candidates[rng.Next() % candidates.size()]; } -// 00740a60 A room not cleared yet. +// 00740a60 The safe grid index of a room not cleared yet in the current dimension and room group, the first plain one +// at once, else the first such room. With none, the I AM ERROR room once the devil room was cleared and a next floor +// waits, else the devil room. int Level::GetNonCompleteRoomIndex() { - reconstruction_missing("Level::GetNonCompleteRoomIndex 00740a60"); + int found = -1; + + for (int i = 0; i < nbRooms; i++) + { + RoomDescriptor& desc = roomList[i]; + bool isGroup = desc.group == -1 || desc.group == room->descriptor->group; + if ((desc.flags & ROOM_DESCRIPTOR_FLAG_CLEAR) || desc.dimension != currentDimensionIdx || !isGroup) continue; + if (desc.data->type == ROOM_DEFAULT) return desc.safeGridIndex; + if (found < 0) found = i; + } + if (found >= 0) return roomList[found].safeGridIndex; + bool isDevilCleared = GetRoomByIdx(ROOM_DEVIL_IDX)->flags & ROOM_DESCRIPTOR_FLAG_CLEAR; + return isDevilCleared && IsNextStageAvailable() ? ROOM_ERROR_IDX : ROOM_DEVIL_IDX; } // 007484c0 The safe grid index of a random room of a type in the current dimension and room group (any group when diff --git a/src/level.h b/src/level.h index 0d485a8..be23bde 100644 --- a/src/level.h +++ b/src/level.h @@ -71,6 +71,9 @@ enum LevelStateFlag : int LEVEL_STATE_EVIL_BUM_LEFT = 4, LEVEL_STATE_DAMAGED = 5, LEVEL_STATE_SHOPKEEPER_KILLED = 6, + LEVEL_STATE_COMPASS_EFFECT = 7, + LEVEL_STATE_MAP_EFFECT = 8, + LEVEL_STATE_BLUE_MAP_EFFECT = 9, LEVEL_STATE_GREED_MONSTRO_SPAWNED = 12, LEVEL_STATE_DUNGEON_ROCK_BROKEN = 13, LEVEL_STATE_MAMA_MEGA = 14, diff --git a/src/lua_api_entity_player.cpp b/src/lua_api_entity_player.cpp index 92a0e42..6bd31d2 100644 --- a/src/lua_api_entity_player.cpp +++ b/src/lua_api_entity_player.cpp @@ -5,6 +5,7 @@ #include "entity_pickup.h" #include "entity_player.h" #include "entity_tear.h" +#include "game.h" #include "item_config.h" #include "log.h" #include "lua_api.h" @@ -432,7 +433,11 @@ static void player_actions_register(lua_State* state) { lua_method(state, "QueueItem", [](Entity_Player& player, ItemConfig_Item& item, int charge, int flags, int varData) { - player.SetQueuedItem({.item = &item, .charge = charge, .flags = (uint8_t)flags, .varData = varData}); + player.SetQueuedItem({.item = &item, + .charge = charge, + .flags = (uint8_t)flags, + .varData = varData, + .itemPoolType = g_game->itemPool.lastPool}); }); lua_method(state, "HasFullHeartsAndSoulHearts", [](Entity_Player& player) { return player.maxHearts <= player.soulHearts + player.redHearts; }); diff --git a/src/lua_api_game.cpp b/src/lua_api_game.cpp index 0395ba8..b4db53e 100644 --- a/src/lua_api_game.cpp +++ b/src/lua_api_game.cpp @@ -5,6 +5,7 @@ #include "entity_npc.h" #include "entity_pickup.h" #include "entity_player.h" +#include "pocket_items.h" #include "game.h" #include "game_end.h" #include "grid_entity_trap_door.h" @@ -63,7 +64,7 @@ Entity_Player* game_random_player(Game& game, Vector position, float radius) // 00704b70 Rerolls the collectibles the floor's other rooms keep: each saved pedestal of an item that may be rerolled // becomes a fresh, untouched one. -static void game_level_collectibles_reroll(Game& game) +void game_level_collectibles_reroll(Game& game) { for (int index = 0; index < game.nbRooms; index++) for (EntitySaveState& saved : game.roomList[index].savedEntities) @@ -167,7 +168,7 @@ static void game_effects_register(lua_State* state) lua_method(state, "UpdateStrangeAttractor", [](Game&, Vector, float, float) { reconstruction_missing("Game::AttractEntities 00705b90"); }); lua_method(state, "CharmFart", - [](Game&, Vector, float, Entity*) { reconstruction_missing("Game::CharmFart 00703f90"); }); + [](Game&, Vector position, float radius, Entity* source) { game_charm_fart(position, radius, source); }); lua_method(state, "Darken", [](Game& game, float strength, int timeout) { game.darknessStrength = strength; game.darknessTimeout = timeout; @@ -209,8 +210,7 @@ static void game_flow_register(lua_State* state) }); lua_method(state, "GetRandomPlayer", game_random_player); lua_method(state, "RerollLevelCollectibles", game_level_collectibles_reroll); - lua_method(state, "RerollLevelPickups", - [](Game&, uint32_t) { reconstruction_missing("Game::RerollLevelPickups 00704c50"); }); + lua_method(state, "RerollLevelPickups", game_level_pickups_reroll); lua_method(state, "RerollEnemy", [](Game&, Entity*, bool) { reconstruction_missing("Game::RerollEnemy 007050c0"); return false; diff --git a/src/npc_ai.cpp b/src/npc_ai.cpp index 0f1bac8..f308984 100644 --- a/src/npc_ai.cpp +++ b/src/npc_ai.cpp @@ -283,9 +283,9 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 64: return boss_pestilence_update(npc); case 65: - return (void)NpcAI::ENTITY_WAR(&npc); + return boss_war_update(npc); case 66: - return (void)NpcAI::ENTITY_DEATH(&npc); + return boss_death_update(npc); case 67: return boss_duke_update(npc); case 68: @@ -310,7 +310,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) return boss_fallen_update(npc); case 82: case 83: - return (void)NpcAI::ENTITY_HEADLESS_HORSEMAN(&npc); + return boss_headless_horseman_update(npc); case 84: return boss_satan_update(npc); case 85: @@ -431,7 +431,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 266: return boss_mama_gurdy_update(npc); case 267: - return (void)NpcAI::ENTITY_DARK_ONE(&npc); + return boss_dark_one_update(npc); case 268: return boss_adversary_update(npc); case 269: @@ -441,7 +441,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) return boss_mr_fred_update(npc); case 271: case 272: - return (void)NpcAI::ENTITY_URIEL(&npc); + return boss_angel_update(npc); case 273: return boss_lamb_update(npc); case 274: @@ -493,7 +493,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 402: return boss_brownie_update(npc); case 403: - return (void)NpcAI::ENTITY_FORSAKEN(&npc); + return boss_forsaken_update(npc); case 404: return boss_little_horn_update(npc); case 405: @@ -507,9 +507,9 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 410: return boss_sisters_vis_update(npc); case 411: - return (void)NpcAI::ENTITY_BIG_HORN(&npc); + return boss_big_horn_update(npc); case 412: - return (void)NpcAI::ENTITY_DELIRIUM(&npc); + return boss_delirium_update(npc); case 413: return (void)NpcAI::ENTITY_MATRIARCH(&npc); case 802: diff --git a/src/npc_ai.h b/src/npc_ai.h index 8be9252..93789aa 100644 --- a/src/npc_ai.h +++ b/src/npc_ai.h @@ -14,6 +14,7 @@ constexpr float RANDOM_HALF_TURN = 3.14f; constexpr float DEGREES_TO_RADIANS = 0.017453292f; constexpr float RADIANS_TO_DEGREES = 57.295776f; constexpr float FULL_TURN_DEGREES = 360; +constexpr int GURGLING_TURDLING = 2; constexpr float HALF_TURN_DEGREES = 180; constexpr float RIGHT_ANGLE_DEGREES = 90; diff --git a/src/npc_basement.h b/src/npc_basement.h index 55fb288..ee351fe 100644 --- a/src/npc_basement.h +++ b/src/npc_basement.h @@ -100,6 +100,7 @@ inline Vector vector_from_direction(int direction) // Room::GetFloorColorAt: the floor's color under a world position, sampled over a radius when it has one. KColor room_floor_color_get(Room& room, const Vector& position, float radius); +KColor room_floor_texel_get(Room& room, const Vector& position); // The green of the splats of the sickly enemies (g_colorGreenSplat). diff --git a/src/npc_boom_fly.cpp b/src/npc_boom_fly.cpp index 16343fc..45b4c39 100644 --- a/src/npc_boom_fly.cpp +++ b/src/npc_boom_fly.cpp @@ -104,7 +104,6 @@ constexpr ColorMod TAINTED_DUST_COLOR = {{0.8f, 0.68f, 0.65f, 0.6f}, {0, 0, 0, 0 constexpr int TAINTED_WAVES = 4; constexpr int TAINTED_BLOOM_FRAMES = 6; constexpr float TAINTED_FRICTION = 0.6f; -constexpr int EFFECT_EXPLOSION_WAVE = 187; constexpr float TAINTED_WAVE_TURN = 90; constexpr ColorMod DRAGON_SPLAT_COLOR = {{0, 0, 0, 1.1f}, {0, 0, 0, 0}, {1, 0.5137255f, 0.003921569f}}; diff --git a/src/npc_clotty.cpp b/src/npc_clotty.cpp index 8482a81..634d3a0 100644 --- a/src/npc_clotty.cpp +++ b/src/npc_clotty.cpp @@ -8,7 +8,6 @@ // The clotties this AI runs: the Clotty with its Clot, I.Blob and Grilled variants, the Mega Clotty and the Cloggy. constexpr int ENTITY_GLOBIN_SPAWN = 24; constexpr int ENTITY_MEGA_CLOTTY = 282; -constexpr int ENTITY_CLOGGY = 872; constexpr int CLOT = 1; constexpr int I_BLOB = 2; constexpr int GRILLED_CLOTTY = 3; diff --git a/src/npc_collision.cpp b/src/npc_collision.cpp index a3616d8..4ef5a3f 100644 --- a/src/npc_collision.cpp +++ b/src/npc_collision.cpp @@ -15,8 +15,6 @@ #include // The NPC types whose contacts differ from the generic ones. -constexpr int ENTITY_HORSEMAN_HEAD = 83; -constexpr int ENTITY_MEGA_MAW = 262; constexpr int ENTITY_SWARM = 281; constexpr int ENTITY_ULTRA_COIN = 293; constexpr int ENTITY_FISTULOID = 308; @@ -24,7 +22,6 @@ constexpr int ENTITY_BOUNCER = 822; constexpr int ENTITY_GASBAG = 856; constexpr int ENTITY_ARMYFLY = 868; constexpr int ENTITY_BUTT_SLICKER = 878; -constexpr int ENTITY_CLICKETY_CLACK = 889; constexpr int ENTITY_NERVE_ENDING_2 = 964; // The variants and states some contacts depend on. diff --git a/src/npc_dirt.cpp b/src/npc_dirt.cpp index 738f9fd..77358fa 100644 --- a/src/npc_dirt.cpp +++ b/src/npc_dirt.cpp @@ -35,6 +35,16 @@ static float luma_get(const KColor& color) return color._green * LUMA_GREEN + color._red * LUMA_RED + color._blue * LUMA_BLUE; } +// The floor surface's own texel under a world position, unshaded. A missing floor surface reads as white. +KColor room_floor_texel_get(Room& room, const Vector& position) +{ + KAGE::Graphics::ImageBase* floor = room.backdrop.floorBuffer.get(); + if (!floor) return WHITE; + + Vector screen = vector_sub(render_position_get(position, RENDER_SNAPPED), room.renderSurfaceTopLeft); + return image_pixel_get(*floor, (uint32_t)screen.x, (uint32_t)screen.y); +} + // 00823590 The floor's color under a world position, as the room shows it: the floor surface's texel (with a radius, // the median by luma of five around it), shaded by the room's shading, tinted by its water and its floor color. // A missing floor surface reads as white, where the original crashed. diff --git a/src/npc_hive.cpp b/src/npc_hive.cpp index d1faaa3..b077479 100644 --- a/src/npc_hive.cpp +++ b/src/npc_hive.cpp @@ -6,7 +6,6 @@ #include // The hives this AI runs: the Hive (with its drowned, holy and tainted variants), the Nest and the Willo hive. -constexpr int ENTITY_NEST = 205; constexpr int ENTITY_WILLO_HIVE = 817; constexpr int HIVE_DROWNED = 1; constexpr int HIVE_HOLY = 2; diff --git a/src/npc_maggot.cpp b/src/npc_maggot.cpp index c8305c9..babc6b5 100644 --- a/src/npc_maggot.cpp +++ b/src/npc_maggot.cpp @@ -18,7 +18,6 @@ constexpr int MY_SHADOW_SUBTYPE = 1; constexpr int SPITTY_TAINTED = 1; constexpr int LEECH_HOLY = 2; constexpr int GURGLING_PLAIN = 0; -constexpr int GURGLING_TURDLING = 2; constexpr int GURGLING_PAIR_SUBTYPE = 1; constexpr int GURGLING_BOMBER_SUBTYPE = 2; constexpr int DIP_CORN_VARIANT = 2; diff --git a/src/persistent_game_data.h b/src/persistent_game_data.h index 646a9be..1eb7413 100644 --- a/src/persistent_game_data.h +++ b/src/persistent_game_data.h @@ -13,6 +13,8 @@ constexpr int ACHIEVEMENT_COUNT = 642; // The achievements the game checks by id. constexpr int ACHIEVEMENT_THE_WOMB = 4; constexpr int ACHIEVEMENT_IT_LIVES = 34; +constexpr int ACHIEVEMENT_BONE_HEARTS = 391; +constexpr int ACHIEVEMENT_ROTTEN_HEARTS = 411; constexpr int ACHIEVEMENT_PLANETARIUMS = 406; constexpr int ACHIEVEMENT_THE_POLAROID = 57; constexpr int ACHIEVEMENT_THE_NEGATIVE = 78; diff --git a/src/player_hud.cpp b/src/player_hud.cpp index 75e11fa..de9c357 100644 --- a/src/player_hud.cpp +++ b/src/player_hud.cpp @@ -206,9 +206,6 @@ constexpr float BOOK_ICON_RISE = -7; constexpr int SUBCHARGES_PER_CHARGE = 450; // The actives whose icon shows a counter, a state or a glow of its own. -constexpr int COLLECTIBLE_JAR_OF_FLIES = 434; -constexpr int COLLECTIBLE_MAMA_MEGA = 483; -constexpr int COLLECTIBLE_JAR_OF_WISPS = 685; constexpr int JAR_HEARTS_SHOWN = 10; constexpr int JAR_FLIES_SHOWN = 20; constexpr int JAR_FLIES_PER_ROW = 11; diff --git a/src/pocket_items.h b/src/pocket_items.h index a73349b..a1478da 100644 --- a/src/pocket_items.h +++ b/src/pocket_items.h @@ -6,6 +6,7 @@ #include struct Entity_Player; +class Game; struct RNG; // What a card's or pill's use goes on with after its effect: the item held up, nothing more, or nothing at all. @@ -36,4 +37,7 @@ void sound_fart_play(int sound); void pocket_pickup_spawn(PocketUse& use, int variant, int subType); PocketUseEnd card_effect_run(PocketUse& use, int card); void pill_effect_run(PocketUse& use, int pillEffect, std::string_view name); +void game_level_collectibles_reroll(Game& game); +void game_charm_fart(const Vector& position, float radius, Entity* source); +void game_level_pickups_reroll(Game& game, uint32_t seed); bool teleport_random_room_of_types(Entity_Player& player, std::span roomTypes, bool isPreferUnvisited); diff --git a/src/room.cpp b/src/room.cpp index b48feec..4f7888e 100644 --- a/src/room.cpp +++ b/src/room.cpp @@ -13,11 +13,13 @@ #include "menu_options.h" #include "mines.h" #include "npc_fireplace.h" +#include "room_grid.h" #include "room_path.h" #include "room_render.h" #include "seeds.h" #include "texture_cache.h" #include +#include #include #include @@ -36,6 +38,24 @@ constexpr LRoomTileDesc SHAPE_TILES[ROOMSHAPE_ANY] = { // The cells doors sit on: the rows of the side walls' doors and the columns of the top and bottom walls' doors, for a // room's first and second half. Narrow rooms move their walls in, and L rooms put two doors on the inner corner's walls. +// A crawlspace's items stand lower and right of their cells. Its walls are plain, ladders or a ladder's top. +constexpr float CRAWLSPACE_ITEM_SHIFT_X = 10; +constexpr float CRAWLSPACE_ITEM_SHIFT_Y = 30; +constexpr int CRAWLSPACE_WALL = 0; +constexpr int CRAWLSPACE_LADDER = 1; +constexpr int CRAWLSPACE_LADDER_TOP = 2; + +// A fast room of the Broken Watch speeds its players up like I'm Excited!!! for 2 or 3 times 900 frames, with the +// Belt's effect. +constexpr int BROKEN_WATCH_SPEEDUPS_MIN = 2; +constexpr int BROKEN_WATCH_SPEEDUP_FRAMES = 900; + +// Greed mode's props: 3 to 7 of variant 10 around the fifth row's middle. +constexpr int GREED_PROP_ROWS = 5; +constexpr uint32_t GREED_PROP_SPREAD = 5; +constexpr uint32_t GREED_PROP_MIN = 3; +constexpr int GREED_PROP_VARIANT = 10; + constexpr int DOOR_ROWS[2] = {4, 11}; constexpr int DOOR_COLUMNS[2] = {7, 20}; constexpr int NARROW_ROW_INSET = 3; @@ -69,7 +89,6 @@ constexpr ColorMod ASCENT_COLOR = {{1, 1, 1, 1}, {1.2f, 1.2f, 1.2f, 0.6f}, {0.07 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; @@ -191,7 +210,6 @@ constexpr int DUST_TIMEOUT_MIN = 30; // The Member Card's stairs down to the secret shop (a ladder back up from it), the Red Key's door outlines and the keys // that count as it. constexpr int COLLECTIBLE_MEMBER_CARD = 602; -constexpr int COLLECTIBLE_VOID = 477; constexpr int CARD_SOUL_OF_CAIN = 83; constexpr int SECRET_SHOP_COLUMN = 10; constexpr int EFFECT_SHOP_LADDER = 156; @@ -506,8 +524,13 @@ void Room::Init(RoomConfig_Room& config, RoomDescriptor& roomDescriptor) attach_minecarts(); 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)"); + for (EntitySaveState& saved : descriptor->savedEffects) + { + Entity* effect = entity_spawn(saved.type, saved.variant, saved.targetPosition, saved.subtype, saved.initSeed); + float scale = std::bit_cast(saved.intStorage1); + effect->sprite.scale = vector_make(scale, scale); + effect->Update(); + } for (int i = 0; i < VENTRICLE_RAZOR_PORTAL_COUNT; i++) { @@ -528,13 +551,12 @@ void Room::Init(RoomConfig_Room& config, RoomDescriptor& roomDescriptor) uint32_t seed = Random(); entity_spawn(ENTITY_EFFECT, EFFECT_BROKEN_SHOVEL_SHADOW, GetCenterPos(), 0, seed); } - if (descriptor->data->type == ROOM_DEVIL) reconstruction_missing("Room::Init 007f2800: a devil room's FUN_004d72b0(6, 1)"); + if (descriptor->data->type == ROOM_DEVIL) g_game->gameStateFlags |= 1ull << GAME_STATE_DEVILROOM_VISITED; if (descriptor->data->type == ROOM_TREASURE && descriptor->visitedCount == 0 && descriptor->dimension == 0) g_game->treasureRoomsVisited++; if (descriptor->data->type == ROOM_PLANETARIUM && descriptor->visitedCount == 0 && descriptor->dimension == 0) g_game->planetariumsVisited++; - if (descriptor->visitedCount == 0 && roomType == ROOM_DUNGEON && gridHeight > 1) - reconstruction_missing("Room::Init 007f2800: a crawlspace's ladders (GridEntity stays generated)"); + if (descriptor->visitedCount == 0 && roomType == ROOM_DUNGEON && gridHeight > 1) crawlspace_ladders_make(); if (!is_backwards_path() && is_boss_doors_removed()) for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++) g_game->room->RemoveDoor(slot); @@ -601,7 +623,13 @@ void Room::Init(RoomConfig_Room& config, RoomDescriptor& roomDescriptor) { current.brokenWatchState = BROKEN_WATCH_FAST; g_manager->musicManager.targetPitch = current.time_scale_update(); - reconstruction_missing("Room::Init 007f2800: the Broken Watch's fast rooms (players' pill RNG and effect 28)"); + for (Entity_Player* player : g_game->playerManager.playerList) + { + if (player->variant != 0) continue; + int speedups = player->GetPillRNG(PILLEFFECT_IM_EXCITED).RandomInt(2) + BROKEN_WATCH_SPEEDUPS_MIN; + player->imExcitedSpeedupCountdown = (uint32_t)(speedups * BROKEN_WATCH_SPEEDUP_FRAMES); + player->temporaryEffects.AddCollectibleEffect(COLLECTIBLE_BELT, false, 1); + } } } @@ -956,12 +984,69 @@ bool Room::SpawnGridEntity(int gridIndex, GridEntityType type, int variant, uint return true; } +// Part of 007f2800 (Room::Init) A crawlspace's items stand 10 right and 30 lower, and every free cell is open air +// with gravity. +void Room::crawlspace_walls_make() +{ + for (Entity* item : entityList.updateEL) + { + if (item->type != ENTITY_PICKUP || item->variant != PICKUP_COLLECTIBLE || item->HasEntityFlags(FLAG_NO_QUERY)) + continue; + item->pos = vector_make(item->pos.x + CRAWLSPACE_ITEM_SHIFT_X, item->pos.y + CRAWLSPACE_ITEM_SHIFT_Y); + } + for (int i = 0; i < gridHeight * gridWidth; i++) + if (!gridEntities[i]) SpawnGridEntity(i, GRID_GRAVITY, 0, Random(), 0); +} + +// Part of 007f2800 (Room::Init) On a crawlspace's first visit its blocks and pillars inside the border become walls: +// plain for blocks, ladders for pillars (the ladder's top piece where a ladder stands to its left). +// The original drops the replaced block without freeing it, and sets up a wall that failed to spawn from null. Here the +// block is freed and only a spawned wall is set up. +void Room::crawlspace_ladders_make() +{ + for (int y = 1; y < gridHeight; y++) + for (int x = 1; x < gridWidth; x++) + { + int index = y * gridWidth + x; + GridEntity* block = index < ROOM_GRID_CELLS ? gridEntities[index] : nullptr; + if (!block || (block->type != GRID_ROCKB && block->type != GRID_PILLAR)) continue; + + bool isPillar = block->type == GRID_PILLAR; + gridEntities[index] = nullptr; + delete block; + int variant = isPillar ? CRAWLSPACE_LADDER : CRAWLSPACE_WALL; + GridEntity* left = isPillar ? gridEntities[index - 1] : nullptr; + if (left && left->type == GRID_WALL && left->variant == CRAWLSPACE_LADDER) variant = CRAWLSPACE_LADDER_TOP; + if (SpawnGridEntity(index, GRID_WALL, variant, Random(), 0)) gridEntities[index]->PostInit(); + } +} + +// Part of 007f2800 (Room::Init) Greed mode's normal rooms scatter 3 to 7 props on free spots found from the cell in +// the middle of the fifth row, each spot's path kept free whether it took a prop or not. +// A spot off the grid read the cell before the grid in the original. Here it is skipped. +void Room::greed_decorations_make() +{ + RNG rng = {(descriptor->decorationSeed & INT_MAX) + (uint32_t)descriptor->gridIndex, 5, 9, 7}; + int column = gridWidth / 2; + int center = column < gridWidth && gridHeight >= GREED_PROP_ROWS ? column + gridWidth * (GREED_PROP_ROWS - 1) : -1; + Vector start = vector_make((float)(center % gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_X, + (float)(center / gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_Y); + + for (int count = 0; (int)(rng.Next() % GREED_PROP_SPREAD + GREED_PROP_MIN) > count; count++) + { + int index = GetGridIndex(room_free_pickup_position_find({.position = start})); + if (index < 0) continue; + + if (!gridEntities[index]) SpawnGridEntity(index, GRID_DECORATION, GREED_PROP_VARIANT, rng.Next(), 0); + gridPaths[index] = GRID_PATH_FREED; + } +} + // A first visit's decorations: random props on free cells, more in big rooms, but not in Basement I's first room; // crawlspaces' walls instead; and Greed's rocks around the center of a normal room. void Room::init_decorations(RoomConfig_Room& config) { - if (roomType == ROOM_DUNGEON) - reconstruction_missing("Room::Init 007f2800: a crawlspace's walls and items (GridEntity stays generated)"); + if (roomType == ROOM_DUNGEON) crawlspace_walls_make(); else if (backdropType != BACKDROP_MEGA_SATAN && backdropType != BACKDROP_DARK_ROOM && backdropType != BACKDROP_PLANETARIUM) { bool isAltStage = g_game->stageType == STAGETYPE_REPENTANCE || g_game->stageType == STAGETYPE_REPENTANCE_B; @@ -993,8 +1078,7 @@ void Room::init_decorations(RoomConfig_Room& config) } } } - if (is_greed() && config.type == ROOM_DEFAULT) - reconstruction_missing("Room::Init 007f2800: Greed's rocks around the center (GridEntity stays generated)"); + if (is_greed() && config.type == ROOM_DEFAULT) greed_decorations_make(); } // The Stairway's ladder in the starting room's top right, with a path carved to it from the entrance. A ladder off @@ -1789,6 +1873,23 @@ float Room::time_scale_update() return (float)extraGFuel * TIME_SCALE_PER_GFUEL + timeScale; } +// 007ea1a0 Ends a room effect of a collectible: the Hourglass and Astral Projection give the music its pitch back, and +// Pause lets every enemy and effect (and the players, in versus mode) move again. +void Room::TriggerEffectRemoved(ItemConfig_Item* item) +{ + if (item->type != ITEM_PASSIVE && item->type != ITEM_ACTIVE && item->type != ITEM_FAMILIAR) return; + + if (item->id == COLLECTIBLE_HOURGLASS || item->id == COLLECTIBLE_ASTRAL_PROJECTION) + g_manager->musicManager.targetPitch = time_scale_update(); + else if (item->id == COLLECTIBLE_PAUSE) + for (Entity* entity : entityList.updateEL) + { + bool isVersusPlayer = g_game->deathmatchManager.is_active() && entity->type == ENTITY_PLAYER; + bool isPausable = entity->type >= ENTITY_FIRST_ENEMY && entity->type <= ENTITY_EFFECT; + if (isPausable || isVersusPlayer) entity->pauseTimer = 0; + } +} + // 008206e0 A boss's track when it has none of its own: the alternate path's, or one of two by the room's flag. int Room::boss_music_get() { diff --git a/src/room.h b/src/room.h index be9cbb4..d9425f3 100644 --- a/src/room.h +++ b/src/room.h @@ -322,6 +322,7 @@ public: BrokenWatchState GetBrokenWatchState(); void SetBrokenWatchState(BrokenWatchState state); float time_scale_update(); + void TriggerEffectRemoved(ItemConfig_Item* item); float GetTimeScale(Entity* entity); int boss_music_get(); uint32_t GetBossVictoryJingle(); @@ -340,6 +341,9 @@ public: void LoadBackdropGraphics(); void MakeDoor(int slot); void make_walls(); + void crawlspace_walls_make(); + void crawlspace_ladders_make(); + void greed_decorations_make(); bool SpawnGridEntity(int gridIndex, GridEntityType type, int variant, uint32_t seed, int varData); void RemoveGridEntity(int gridIndex, int pathTrail, DecorationRemoval removal); void RestoreState(); diff --git a/src/room_clear.cpp b/src/room_clear.cpp index 0e6d225..dec1c3b 100644 --- a/src/room_clear.cpp +++ b/src/room_clear.cpp @@ -682,7 +682,6 @@ static bool special_award_pick(Room& room, RNG& rng, int& item, int& trinket) static const std::map BOSS_TRINKETS = {{9, 115}, {10, 114}, {11, 113}, {12, 116}, {38, 117}, {79, 141}, {101, 183}}; constexpr std::array SIN_TRINKETS = {12, 26, 9, 11, 27, 10, 64, 65, 96, 144, 66}; - constexpr int COLLECTIBLE_YUCK_HEART = 639; item = 0; trinket = 0; diff --git a/src/room_grid.h b/src/room_grid.h index 3c535eb..c2cb1e3 100644 --- a/src/room_grid.h +++ b/src/room_grid.h @@ -16,6 +16,9 @@ enum QueryPartition : uint32_t QUERY_ALL = 0xffffffff }; +// The usual first step out a free pickup spot is searched from. +constexpr float PICKUP_SPOT_STEP = 40; + // A search for a free spot for a pickup (Room::FindFreePickupSpawnPosition's arguments): around a position, first // this far out, kept off spots near enemies and players, maybe over pits, and maybe away from the doors. struct FreeSpotSearch diff --git a/src/room_special.cpp b/src/room_special.cpp index 351eaf9..7c046d5 100644 --- a/src/room_special.cpp +++ b/src/room_special.cpp @@ -20,7 +20,6 @@ constexpr int COLLECTIBLE_POUND_OF_FLESH = 672; constexpr int TRINKET_STORE_CREDIT = 13; constexpr int TRINKET_KEEPERS_BARGAIN = 171; constexpr int TRINKET_ADOPTION_PAPERS = 184; -constexpr int CARD_SOUL_LILITH = 92; constexpr int ACHIEVEMENT_HOLY_CARD = 293; constexpr int ACHIEVEMENT_HEART_BONE_SHOP = 391; constexpr int ACHIEVEMENT_HEART_ROTTEN_SHOP = 411; diff --git a/src/room_state.cpp b/src/room_state.cpp index a8048d1..0aeaed3 100644 --- a/src/room_state.cpp +++ b/src/room_state.cpp @@ -22,7 +22,6 @@ constexpr int ROOM_CLEAR_DELAY_PENDING = 8; constexpr int GRID_PATH_RESET = 900; // The effects, slots and enemies whose saves keep more than the common fields. -constexpr int EFFECT_BUTTERFLY = 69; constexpr int HEAVEN_LIGHT_MOONLIGHT = 1; constexpr int GIDEON_TYPE = 907; diff --git a/src/room_transition.cpp b/src/room_transition.cpp index 90ac62a..00a52b2 100644 --- a/src/room_transition.cpp +++ b/src/room_transition.cpp @@ -46,7 +46,6 @@ constexpr int ITEM_STATE_HELD = 604; constexpr int MINECART_RIDDEN = 10; constexpr int NPC_STATE_MINECART_MOVING = 4; constexpr int COLLECTIBLE_GLOWING_HOURGLASS = 422; -constexpr int COLLECTIBLE_D7 = 437; constexpr const char* ANIMATION_APPEAR = "Appear"; constexpr float APPEAR_FRAME = 2; constexpr float SCREEN_CELL_SIZE = 26; diff --git a/src/room_update.cpp b/src/room_update.cpp index ef0415d..6bbc48f 100644 --- a/src/room_update.cpp +++ b/src/room_update.cpp @@ -162,7 +162,6 @@ constexpr int BEAST_FLY_VARIANTS[] = {11, 21}; constexpr int DOGMA_ANGEL = 2; constexpr int DOGMA_ANGEL_STATE = 10; constexpr int LASER_LOOP_VARIANTS[] = {6, 15}; -constexpr int EFFECT_DOGMA_BLACKHOLE = 171; constexpr int BLACKHOLE_STATE_OPEN = 1; // How the sources sound: the reach of the enemies' loops, the flies' buzz (Hush's flies quieter, the whole buzz capped), diff --git a/src/sfx_manager.h b/src/sfx_manager.h index b1da1b4..71fe67d 100644 --- a/src/sfx_manager.h +++ b/src/sfx_manager.h @@ -46,6 +46,27 @@ enum SoundId : int SOUND_DEATH_REVERSE = 29, SOUND_DEATH_BURST_SMALL = 30, SOUND_DEATH_CARD = 33, + SOUND_HOURGLASS = 1039, + SOUND_BOOK_OF_SIN = 1042, + SOUND_DEAD_SEA_SCROLLS = 1034, + SOUND_FORGET_ME_NOW = 1054, + SOUND_IV_BAG = 1056, + SOUND_BESTFRIEND = 1025, + SOUND_CRYSTAL_BALL = 1053, + SOUND_PORTABLE_SLOT_USE = 898, + SOUND_PORTABLE_SLOT_WIN = 899, + SOUND_HOW_TO_JUMP = 1055, + SOUND_BOX_SPIDERS = 1029, + SOUND_FLUSH = 396, + SOUND_SATANIC_BIBLE = 1037, + SOUND_CONVERTER = 848, + SOUND_PANDORAS_BOX = 894, + SOUND_TELEPORT_UNDEFINED = 912, + SOUND_WOODEN_NICKEL = 1065, + SOUND_BOX_OF_FRIENDS = 840, + SOUND_DIPLOPIA = 1061, + SOUND_TEAR_DETONATOR = 1063, + SOUND_VENTRICLE_RAZOR = 1064, SOUND_DEVIL_CARD = 34, SOUND_FART = 37, SOUND_FETUS_JUMP = 38, @@ -158,6 +179,7 @@ enum SoundId : int SOUND_LASERRING = 271, SOUND_LASERRING_WEAK = 272, SOUND_LASERRING_STRONG = 273, + SOUND_ANGEL_WING = 275, SOUND_ANGEL_BEAM = 276, SOUND_MEGA_BLAST_START = 278, SOUND_MEGA_BLAST_END = 280, @@ -223,6 +245,23 @@ enum SoundId : int SOUND_POOP_THROW = 865, SOUND_SUMMON_PENTA = 871, SOUND_SUMMON_WAVE = 872, + SOUND_BIGHORN_APPEAR = 873, + SOUND_BIGHORN_CLOSE_BIG = 874, + SOUND_BIGHORN_CRACK_BIG = 875, + SOUND_BIGHORN_OPEN_BIG = 876, + SOUND_BIGHORN_SHAKE_BIG = 877, + SOUND_BIGHORN_DEATH = 878, + SOUND_BIGHORN_DIZZY_SHAKE = 879, + SOUND_BIGHORN_HAND_APPEAR = 880, + SOUND_BIGHORN_HAND_HIDE = 881, + SOUND_BIGHORN_HIDE = 882, + SOUND_BIGHORN_HURT = 883, + SOUND_BIGHORN_PRE_SPIT = 884, + SOUND_BIGHORN_CLOSE_SMALL = 885, + SOUND_BIGHORN_CRACK_SMALL = 886, + SOUND_BIGHORN_OPEN_SMALL = 887, + SOUND_BIGHORN_SHAKE_SMALL = 888, + SOUND_BIGHORN_SPIT = 889, SOUND_PRIDE_ZAP = 903, SOUND_CAGE_DEATH = 918, SOUND_CAGE_JUMP = 919, @@ -231,6 +270,16 @@ enum SoundId : int SOUND_CAGE_PREP_SHOOT = 922, SOUND_CAGE_ROLL_STOP = 923, SOUND_CAGE_ROLL_BOUNCE = 924, + SOUND_DEATH_HOURGLASS = 925, + SOUND_DEATH_SICKLE = 926, + SOUND_DEATH_LEAN = 927, + SOUND_DEATH_VOX = 928, + SOUND_DEATH_SPAWN_PREP = 929, + SOUND_DEATH_HORSE_ATTACK = 930, + SOUND_DEATH_HORSE_WOOSH = 931, + SOUND_GISH_JUMP = 936, + SOUND_GISH_JUMP_HIGH = 937, + SOUND_GISH_SPIT = 938, SOUND_GURDY_FACE_ATTACK_APPEAR = 939, SOUND_GURDY_FACE_ATTACK_HIDE = 940, SOUND_GURDY_FACE_SMILE_APPEAR = 941, @@ -260,6 +309,8 @@ enum SoundId : int SOUND_TERATOMA_BOUNCE_MEDIUM = 969, SOUND_TERATOMA_BOUNCE_SMALL = 970, SOUND_FORSAKEN_LASER = 971, + SOUND_FORSAKEN_ARMS_UP = 972, + SOUND_FORSAKEN_FADE = 973, SOUND_FISTULA_BOUNCE_LARGE = 974, SOUND_FISTULA_BURST_LARGE = 977, SOUND_FISTULA_GROWL_LARGE = 978, @@ -284,7 +335,10 @@ enum SoundId : int SOUND_HOLLOW_DEATH_1 = 1003, SOUND_HOLLOW_DEATH_2 = 1004, SOUND_HOLLOW_ROAR = 1005, + SOUND_WAR_KNOCKDOWN = 1006, + SOUND_WAR_CHARGE = 1007, SOUND_MONSTERS_NEXT_DOOR = 1008, + SOUND_CAMBION_CONCEPTION = 1009, SOUND_IMMACULATE_CONCEPTION = 1010, SOUND_SHINYROCK_SHIMMER = 1014, SOUND_SISSYLONGLEG_CHARM = 1016, @@ -303,6 +357,7 @@ enum SoundId : int SOUND_RAGMAN_3 = 394, SOUND_RAGMAN_4 = 395, SOUND_FORSAKEN_LAUGH = 417, + SOUND_FORSAKEN_SCREAM = 418, SOUND_OCCULAR_RIFT_PORTAL = 1088, SOUND_ROCKET_LAUNCH_SHORT = 585, SOUND_ROCKET_LAUNCH_TINY = 586, @@ -363,9 +418,49 @@ enum SoundId : int SOUND_FLOATING_KNIGHT_GROWL = 1084, SOUND_KNIGHT_GROWL = 1082, SOUND_SELFLESS_KNIGHT_GROWL = 1083, + SOUND_WHIP = 494, + SOUND_WHIP_HIT = 495, + SOUND_BOOMERANG_THROW = 836, + SOUND_BOOMERANG_LOOP = 837, + SOUND_BOOMERANG_CATCH = 838, + SOUND_BOOMERANG_HIT = 839, + SOUND_FRIENDLYBALL_RAISE = 1022, + SOUND_FRIENDLYBALL_THROW = 1024, + SOUND_DECAP_THROW = 1047, + SOUND_BLACK_HOLE_THROW = 1068, SOUND_FLAMETHROWER_END = 536, SOUND_FLAMETHROWER_LOOP = 535, - SOUND_FLAMETHROWER_START = 534 + SOUND_FLAMETHROWER_START = 534, + SOUND_DULL_RAZOR = 1044, + SOUND_BROKEN_SHOVEL = 1043, + SOUND_CASH_REGISTER = 274, + SOUND_BROWN_NUGGET = 841, + SOUND_RECALL = 574, + SOUND_TELEKENESIS = 909, + SOUND_PAUSE_FREEZE = 895, + SOUND_FLUTE = 479, + SOUND_GELLO = 1050, + SOUND_BLACK_HOLE_ACTIVATE = 1067, + SOUND_URN_OPEN = 572, + SOUND_URN_CLOSE = 573, + SOUND_MOMS_BOX = 890, + SOUND_MINECRAFTER = 1062, + SOUND_R_KEY = 904, + SOUND_SUPLEX_ACTIVATE = 1030, + SOUND_WOODEN_NICKEL_SPAWN = 1066, + SOUND_DARK_ARTS = 1045, + SOUND_FORTUNE_COOKIE = 491, + SOUND_JAR_OF_FLIES = 1060, + SOUND_MR_ME = 1069, + SOUND_MAGIC_SKIN = 1041, + SOUND_DATAMINER = 854, + SOUND_PLAN_C = 897, + SOUND_LARYNX_SCREAM_LO = 575, + SOUND_LARYNX_SCREAM_MED = 576, + SOUND_LARYNX_SCREAM_HI = 577, + SOUND_GLOWING_HOURGLASS_ACTIVATE = 861, + SOUND_GLOWING_HOURGLASS_FIZZLE = 862, + SOUND_DECAP_ACTIVATE = 1046 }; // Construction, copies and destruction (00a2a990, 00a2aa60, 00a2ab40, 00a2ac90) are the defaults. diff --git a/src/tainted_characters.cpp b/src/tainted_characters.cpp index 3d98593..2c84332 100644 --- a/src/tainted_characters.cpp +++ b/src/tainted_characters.cpp @@ -107,12 +107,6 @@ constexpr PoolWeight LEMEGETON_GREED_POOLS[] = {{POOL_GREED_TREASURE, 100}, {POO {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) { diff --git a/src/temporary_effects.cpp b/src/temporary_effects.cpp index c41e1b1..7804375 100644 --- a/src/temporary_effects.cpp +++ b/src/temporary_effects.cpp @@ -32,7 +32,7 @@ template static TemporaryEffect* effect_find(TemporaryEffects& effe void TemporaryEffects::effect_removed(ItemConfig_Item* item, int count) { if (player) player->trigger_collectible_effect_removed(item, count); - else reconstruction_missing("Room::TriggerEffectRemoved 007ea1a0, which the room's takeover has not declared yet"); + else g_game->room->TriggerEffectRemoved(item); isEvaluateCachePending = true; } diff --git a/src/weapon.cpp b/src/weapon.cpp index 2871ab5..d9092a1 100644 --- a/src/weapon.cpp +++ b/src/weapon.cpp @@ -21,6 +21,7 @@ #include "manager.h" #include "menu_manager.h" #include "npc_ai.h" +#include "npc_basement.h" #include #include @@ -37,6 +38,20 @@ constexpr float IPECAC_SPEED_MIN = 0.9f; constexpr float IPECAC_SPEED_RANGE = 0.2f; constexpr float PEE_SPREAD = 24; constexpr float FULL_TURN = 360; +constexpr float CHOCOLATE_MILK_CHARGE = 2.5f; +constexpr float CHOCOLATE_MILK_DAMAGE_MIN = 0.1f; +constexpr float CHOCOLATE_MILK_DAMAGE_MAX = 4; +constexpr int CHOCOLATE_MILK_BLINK = 12; +constexpr int CURSED_EYE_CHARGES = 5; +constexpr float CURSED_EYE_TARGET_STEPS = 4; +constexpr float KIDNEY_STONE_MILK_CHARGE = 5; +constexpr float NEPTUNUS_CHARGE = 12; +constexpr float NEPTUNUS_RATE_RISE = 1.4495001f; +constexpr float NEPTUNUS_DELAY_MIN = 0.25f; +constexpr float NEPTUNUS_SPREAD_MAX = 16; +constexpr float TARGET_REACH_NEAR = 50; +constexpr float TARGET_REACH_SPAN = 250; +constexpr float CHARGE_RELEASE_MIN = 1e-5f; constexpr float SHOT_SPEED_BASE = 10; constexpr float TEAR_SPEED_SPREAD = 0.2f; constexpr float TEAR_SPEED_MIN = 0.8f; @@ -46,8 +61,6 @@ constexpr int FIRE_BLINK_BASE = 7; constexpr int FIRE_BLINK_MIN = 11; constexpr int MAX_SHOTS_PER_FRAME = 8; constexpr int NUMBER_ONE_BLINK = 16; -constexpr int SEEDED_VARIANT_NONE = -1; -constexpr int SEEDED_VARIANT_SPEEDY = 2; constexpr int COLLECTIBLE_EYE_DROPS = 600; constexpr int COLLECTIBLE_KIDNEY_STONE_WEAPON = 440; @@ -63,7 +76,6 @@ constexpr int MOMS_EYE_LASER_CHANCE = 20; constexpr float MOMS_EYE_LASER_LUCK = 1.5f; constexpr int LOKIS_HORNS_LASER_CHANCE = 80; constexpr float LOKIS_HORNS_LASER_LUCK = 5; -constexpr int COLLECTIBLE_ISAACS_TEARS = 323; constexpr int TRINKET_TORN_CARD = 157; constexpr int BABY_SPIN = 8; constexpr int MARKED_TARGET = 30; @@ -408,7 +420,7 @@ Entity_Tear* Weapon::fire_tear(const PosVel& shot, uint32_t fireFlags, float dam tear->Update(); } - if (owner && owner->is_player() && owner->ToPlayer()->get_seeded_variant() == SEEDED_VARIANT_SPEEDY) + if (owner && owner->is_player() && owner->ToPlayer()->get_seeded_variant() == SEEDED_VARIANT_MUTANT_SPIDER) tear->velocity = vector_scale(tear->velocity, random_unit() * TEAR_SPEED_SPREAD + TEAR_SPEED_MIN); tear->pos = vector_add(tear->pos, vector_scale(tear->velocity, positionStep)); if (owner && (!shooter || shooter == owner)) @@ -739,8 +751,6 @@ void Weapon_Tears::Reset() // Cursed Eye, none otherwise. float Weapon_Tears::GetMaxCharge() { - constexpr float NEPTUNUS_CHARGE = 12; - constexpr float CHOCOLATE_MILK_CHARGE = 2.5f; float multiplier = 1; if (modifiers & WEAPON_MOD_NEPTUNUS) multiplier = NEPTUNUS_CHARGE; @@ -770,23 +780,157 @@ bool Weapon_Tears::CanTriggerCursedEyeTeleport() return !(modifiers & WEAPON_MOD_NEPTUNUS) && charge > 0 && charge < GetMaxCharge(); } +// The charges a tear weapon may hold: Chocolate Milk's and Cursed Eye's charge while the shot is held (a charge shot, +// unless Neptunus), and Neptunus' charge while it is not. +struct TearCharge +{ + bool isChocolateMilk = false; + bool isCursedEye = false; + bool isNeptunus = false; + bool isChargeShot = false; +}; + +// Whether a charge shot weapon is full enough to let go at once: a full Chocolate Milk charge, or five Cursed Eye +// charges (one once the charge is spent). +static bool is_charge_full(Weapon_Tears& weapon, const TearCharge& kind) +{ + bool isMilkFull = kind.isChocolateMilk && weapon.charge >= weapon.maxFireDelay * CHOCOLATE_MILK_CHARGE; + bool isEyeFull = kind.isCursedEye && ((weapon.charge > 0 && weapon.cursedEyeCharges >= CURSED_EYE_CHARGES) || + (weapon.charge <= 0 && weapon.cursedEyeCharges >= 1)); + return isMilkFull || isEyeFull; +} + +// Whether the shot is still held this frame (part of 00a0a720): Kidney Stone's burst lets a charge go, a target (Marked's +// or the fixed one) lets go a charge enough for its distance, and a quick release (Soy Milk, no fire delay or G FUEL!) +// lets go a full charge, which then counts as released. +static bool tear_shot_held(Weapon_Tears& weapon, const TearCharge& kind, bool isShooting, bool isInterpolated) +{ + Entity_Player* shooter = weapon.owner && weapon.owner->is_player() ? weapon.owner->ToPlayer() : nullptr; + Entity_Player* player = weapon.owner_player(); + bool isHolding = isShooting; + + if (shooter && shooter->peeBurstCooldown >= 1) + { + bool isMilkReady = kind.isChocolateMilk && + weapon.charge >= std::min(weapon.maxFireDelay * CHOCOLATE_MILK_CHARGE, KIDNEY_STONE_MILK_CHARGE); + if (isMilkReady || (kind.isCursedEye && weapon.cursedEyeCharges >= 1)) isHolding = false; + } + if (isInterpolated || !isHolding) return isHolding; + + Vector target = weapon.fixedDirection; + if (weapon.owner && player && player->markedTarget && player->HasCollectible(COLLECTIBLE_MARKED)) + target = player->markedTarget->pos; + if (!vector_is_zero(target)) + { + float reach = std::clamp((vector_length(vector_sub(target, weapon.get_owner_position())) - TARGET_REACH_NEAR) / + TARGET_REACH_SPAN, + 0.0f, 1.0f); + int needed = weapon.charge <= 0 ? 1 : (int)(reach * CURSED_EYE_TARGET_STEPS + 1); + float milkNeeded = (weapon.maxFireDelay * CHOCOLATE_MILK_CHARGE - KIDNEY_STONE_MILK_CHARGE) * reach + + KIDNEY_STONE_MILK_CHARGE - 1; + bool isMilkShort = !kind.isChocolateMilk || weapon.charge <= milkNeeded; + if (!isMilkShort || (kind.isCursedEye && weapon.cursedEyeCharges >= needed)) return false; + } + + bool isQuick = (weapon.modifiers & WEAPON_MOD_SOY_MILK) || weapon.maxFireDelay <= 0 || + (shooter && shooter->get_seeded_variant() != SEEDED_VARIANT_NONE); + if (!isQuick || !kind.isChargeShot || !is_charge_full(weapon, kind)) return true; + weapon.charge = std::max(weapon.charge, CHARGE_RELEASE_MIN); + weapon.chargeAtRelease = weapon.charge; + return false; +} + +// A charge's step this frame: grown by the owner's speed up to the weapon's full charge, the head showing it. +static float charge_grow(Weapon_Tears& weapon, int collectibleId, const Vector& aim, float headFrame) +{ + float maxCharge = weapon.GetMaxCharge(); + if (maxCharge <= weapon.charge) + { + weapon.UpdateHeadChargeAnimation(collectibleId, HEAD_CHARGE_CHARGED, aim, -1); + return -1; + } + if (headFrame >= 0) weapon.UpdateHeadChargeAnimation(collectibleId, HEAD_CHARGE_CHARGING, aim, headFrame); + return std::min(weapon.charge + (weapon.owner ? weapon.owner->speedMultiplier : 1), maxCharge); +} + +// The charge part of 00a0a720 once the volleys are fired. A released charge shot spends a Cursed Eye charge and the +// charge, and stops the head's charge animations (a familiar's fire cooldown). A held one grows Chocolate Milk's and +// Cursed Eye's charge, Cursed Eye counting its charges out of five. Neptunus charges while the shot is not held, and +// drains faster the fuller it is while it is. +static void tear_charge_update(Weapon_Tears& weapon, const TearCharge& kind, const Vector& aim, bool isHolding) +{ + Entity_Player* shooter = weapon.owner && weapon.owner->is_player() ? weapon.owner->ToPlayer() : nullptr; + float speed = weapon.owner ? weapon.owner->speedMultiplier : 1; + + if (kind.isNeptunus) + { + if (isHolding) + { + float ratio = (weapon.charge + 1) / (weapon.GetMaxCharge() + 1); + float delay = std::max(weapon.maxFireDelay + 1, 1.0f); + weapon.charge = std::max(weapon.charge - speed * ((delay - 1) * ratio * ratio + 1), 0.0f); + } + else + { + Vector head = shooter ? vector_from_direction(shooter->headDirection) : aim; + float headFrame = weapon.charge / weapon.GetMaxCharge() * HEAD_CHARGE_FRAMES; + if (float next = charge_grow(weapon, COLLECTIBLE_NEPTUNUS, head, headFrame); next >= 0) weapon.charge = next; + } + weapon.chargeAtRelease = weapon.charge; + return; + } + if (!kind.isChargeShot) return; + + if (!isHolding) + { + if (weapon.cursedEyeCharges > 0) weapon.cursedEyeCharges--; + weapon.charge = 0; + if (shooter) shooter->stop_costume_item_anims(); + else if (weapon.owner && weapon.owner->IsFamiliar()) static_cast(weapon.owner)->fireCooldown = 0; + return; + } + + float next = weapon.charge; + if (kind.isChocolateMilk) + { + float grown = charge_grow(weapon, COLLECTIBLE_CHOCOLATE_MILK, aim, weapon.charge / weapon.GetMaxCharge() * HEAD_CHARGE_FRAMES); + if (grown >= 0) next = grown; + weapon.SetBlinkTime(1); + } + if (kind.isCursedEye) + { + float maxCharge = weapon.GetMaxCharge(); + float headFrame = !weapon.owner ? -1 : shooter ? 0 : weapon.charge / maxCharge * HEAD_CHARGE_FRAMES; + float grown = charge_grow(weapon, COLLECTIBLE_CURSED_EYE, aim, headFrame); + if (grown >= 0) next = grown; + weapon.SetBlinkTime(1); + weapon.cursedEyeCharges = (int)((next + 1) * CURSED_EYE_CHARGES / (maxCharge + 1)); + } + weapon.charge = next; + weapon.chargeAtRelease = next; +} + // 00a0a720 Fires the tears due this frame: one volley per fire delay passed (at most eight), from each eye Eye Drops // gives, alternating eyes, spread by the multi-shot items, with the extra backward, sideways and random shots. Shots -// fired late in a frame start further along. Cain's one eye shoots from the right, Technology 2 leaves the right eye -// to its laser. A familiar (Incubus, Cain's Other Eye, Twisted Pair) fires its player's volley from itself, with no -// eyes, spread or blink of a player. Charged shots (Chocolate Milk, Cursed Eye, Neptunus) and G FUEL! are not -// written yet. The player field getters and the volley wrapper it calls are inlined (009f5830, 009f5850, 009f5870, -// 009f4230). +// fired late in a frame start further along. Cain's one eye (and Cursed Eye's) shoots from the right, Technology 2 +// leaves the right eye to its laser. A familiar (Incubus, Cain's Other Eye, Twisted Pair) fires its player's volley +// from itself, with no eyes, spread or blink of a player. Chocolate Milk and Cursed Eye fire one shot on release, +// stronger the longer it charged (Chocolate Milk) or as several (Cursed Eye's charges), and Neptunus fires faster and +// wider the fuller its charge. G FUEL! and the laser eye of Cain with Technology 2 are not written yet. The player +// field getters and the volley wrapper it calls are inlined (009f5830, 009f5850, 009f5870, 009f4230, 009f4fc0). void Weapon_Tears::Fire(const Vector& shootDirection, bool isShooting, bool isInterpolated) { Weapon::Fire(shootDirection, isShooting, isInterpolated); Entity_Player* shooter = owner && owner->is_player() ? owner->ToPlayer() : nullptr; Entity_Player* player = owner_player(); - if (modifiers & (WEAPON_MOD_CHOCOLATE_MILK | WEAPON_MOD_CURSED_EYE | WEAPON_MOD_NEPTUNUS)) - reconstruction_missing("Weapon_Tears::Fire 00a0a720 (charged shots)"); + TearCharge kind{.isChocolateMilk = (modifiers & WEAPON_MOD_CHOCOLATE_MILK) != 0, + .isCursedEye = (modifiers & WEAPON_MOD_CURSED_EYE) != 0, + .isNeptunus = (modifiers & WEAPON_MOD_NEPTUNUS) != 0}; + kind.isChargeShot = !kind.isNeptunus && (kind.isChocolateMilk || kind.isCursedEye); if (shooter && shooter->get_seeded_variant() != SEEDED_VARIANT_NONE) reconstruction_missing("Weapon_Tears::Fire 00a0a720 (G FUEL!)"); + bool isHolding = tear_shot_held(*this, kind, isShooting, isInterpolated); Vector aim = isShooting ? shootDirection : direction; if (IsAxisAligned()) @@ -795,11 +939,11 @@ void Weapon_Tears::Fire(const Vector& shootDirection, bool isShooting, bool isIn else if (float length = std::sqrt(aim.x * aim.x + aim.y * aim.y); length > 0) aim = vector_scale(aim, 1 / length); int eyeMode = 0; - if (shooter && (shooter->playerType == PLAYER_CAIN || shooter->playerType == PLAYER_CAIN_B || + if (shooter && (kind.isCursedEye || shooter->playerType == PLAYER_CAIN || shooter->playerType == PLAYER_CAIN_B || shooter->HasCollectible(COLLECTIBLE_LEAD_PENCIL) || shooter->HasCollectible(COLLECTIBLE_STAPLER))) eyeMode = 1; else if (shooter && shooter->HasCollectible(COLLECTIBLE_TECHNOLOGY_2)) eyeMode = -1; - int eyeCount = shooter && eyeMode == 0 && shooter->HasCollectible(COLLECTIBLE_EYE_DROPS) ? 2 : 1; + int eyeCount = !kind.isChargeShot && shooter && eyeMode == 0 && shooter->HasCollectible(COLLECTIBLE_EYE_DROPS) ? 2 : 1; for (int eye = 0; eye < eyeCount; eye++) { @@ -810,27 +954,55 @@ void Weapon_Tears::Fire(const Vector& shootDirection, bool isShooting, bool isIn float rate = SHOTS_PER_SECOND / (maxFireDelay + 1); eyeMaxFireDelay = SHOTS_PER_SECOND / (rate * (eye == 0 ? EYE_DROPS_FAST_RATE : EYE_DROPS_SLOW_RATE)) - 1; } + if (kind.isNeptunus) + { + // The original divides by a zero full charge too. Here a zero fire delay leaves the rate alone. + float fullCharge = maxFireDelay * NEPTUNUS_CHARGE; + float ratio = fullCharge == 0 ? 0 : std::clamp(charge / fullCharge, 0.0f, 1.0f); + float boost = std::pow(ratio * NEPTUNUS_RATE_RISE + 1, 2.0f); + eyeMaxFireDelay = std::max((eyeMaxFireDelay + 1) / boost, NEPTUNUS_DELAY_MIN) - 1; + } int shots = 0; float positionStep = 0; - if (isShooting) + if (!kind.isChargeShot) { - if (isInterpolated) return; - - positionStep = -1 - delay; - while (delay < 0 && shots < MAX_SHOTS_PER_FRAME) + if (isHolding) { - shots++; - delay += eyeMaxFireDelay + 1; + if (isInterpolated) return; + + positionStep = -1 - delay; + while (delay < 0 && shots < MAX_SHOTS_PER_FRAME) + { + shots++; + delay += eyeMaxFireDelay + 1; + } + chargeAtRelease = 0; + } + } + else + { + if (!isHolding && ((kind.isChocolateMilk && charge > 0) || (kind.isCursedEye && cursedEyeCharges > 0))) + shots = 1; + if (isInterpolated) + { + if (shots > 0) SetBlinkTime(1); + return; } - chargeAtRelease = 0; } for (; shots > 0; shots--) { Weapon_MultiShotParams params = GetMultiShotParams(); Vector shotDirection = aim; - SetBlinkTime(std::max(FIRE_BLINK_MIN, FIRE_BLINK_BASE - (int)(maxFireDelay * FIRE_BLINK_SCALE))); + if (kind.isChocolateMilk) SetBlinkTime(CHOCOLATE_MILK_BLINK); + else SetBlinkTime(std::max(FIRE_BLINK_MIN, FIRE_BLINK_BASE - (int)(maxFireDelay * FIRE_BLINK_SCALE))); + if (kind.isNeptunus) + { + float headFrame = (charge + 1) / (maxFireDelay * NEPTUNUS_CHARGE + 1) * HEAD_CHARGE_FRAMES; + if (headFrame == 0) stop_costume_item_anim(COLLECTIBLE_NEPTUNUS); + else UpdateHeadChargeAnimation(COLLECTIBLE_NEPTUNUS, HEAD_CHARGE_SHOOT, aim, headFrame); + } TriggerTearEffects(shotDirection, 1); int eyeSide = 0; @@ -840,8 +1012,8 @@ void Weapon_Tears::Fire(const Vector& shootDirection, bool isShooting, bool isIn else shooter->tearDisplacement = (int8_t)(eyeCount == 2 ? (eye == 0 ? -1 : 1) : -tear_displacement()); eyeSide = tear_displacement(); if (is_shot_rotated()) shotDirection = vector_rotate(shotDirection, (float)eyeSide * SHOT_ROTATION_DEGREES); - if (params.numTears > 1 || shooter->HasCollectible(COLLECTIBLE_POLYPHEMUS) || - shooter->HasCollectible(COLLECTIBLE_IPECAC)) + if (kind.isChocolateMilk || kind.isNeptunus || params.numTears > 1 || + shooter->HasCollectible(COLLECTIBLE_POLYPHEMUS) || shooter->HasCollectible(COLLECTIBLE_IPECAC)) eyeSide = 0; if (shooter->HasCollectible(COLLECTIBLE_NUMBER_ONE) || shooter->temporaryEffects.HasCollectibleEffect(COLLECTIBLE_NUMBER_ONE) || @@ -850,6 +1022,8 @@ void Weapon_Tears::Fire(const Vector& shootDirection, bool isShooting, bool isIn eyeSide = 0; shooter->blinkTime = std::max(shooter->blinkTime, NUMBER_ONE_BLINK); } + if (eyeSide != 0 && eyeMode == 1 && shooter->HasCollectible(COLLECTIBLE_TECHNOLOGY_2)) + reconstruction_missing("Weapon_Tears::Fire 00a0a720 (the laser eye with Technology 2)"); } Vector firePos = owner ? owner->pos : Vector{}; @@ -858,6 +1032,15 @@ void Weapon_Tears::Fire(const Vector& shootDirection, bool isShooting, bool isIn if (player && player->HasCollectible(COLLECTIBLE_IPECAC)) base = vector_scale(base, random_unit() * IPECAC_SPEED_RANGE + IPECAC_SPEED_MIN); + float damageMultiplier = 1; + if (kind.isChocolateMilk) + { + float fullCharge = (maxFireDelay + 1) * (kind.isNeptunus ? NEPTUNUS_CHARGE : CHOCOLATE_MILK_CHARGE); + float charged = kind.isNeptunus ? charge : chargeAtRelease; + damageMultiplier = std::clamp((charged + 1) * CHOCOLATE_MILK_DAMAGE_MAX / fullCharge, + CHOCOLATE_MILK_DAMAGE_MIN, CHOCOLATE_MILK_DAMAGE_MAX); + } + float spreadAngle = 0; if (shooter && shooter->HasCollectible(COLLECTIBLE_EPIPHORA) && shooter->epiphoraCharge > 0) spreadAngle = (float)(shooter->epiphoraCharge / EPIPHORA_FRAMES_PER_STEP) * EPIPHORA_SPREAD / @@ -865,11 +1048,14 @@ void Weapon_Tears::Fire(const Vector& shootDirection, bool isShooting, bool isIn int pee = shooter ? shooter->peeBurstCooldown : 0; int peeMax = shooter ? shooter->maxPeeBurstCooldown : 0; if (pee > 0 && peeMax > 0 && pee < peeMax - 1) spreadAngle += (float)pee * PEE_SPREAD / (float)peeMax; + if (kind.isNeptunus) + spreadAngle += std::clamp(charge * NEPTUNUS_SPREAD_MAX / (maxFireDelay * NEPTUNUS_CHARGE), 0.0f, + NEPTUNUS_SPREAD_MAX); float speed = player ? player->shotSpeed : 1; auto extra_fire = [&](Vector velocity) { - fire_tear({firePos, vector_spread(vector_scale(velocity, speed), spreadAngle)}, TEAR_FIRE_EXTRA_SHOT, 1, - positionStep); + fire_tear({firePos, vector_spread(vector_scale(velocity, speed), spreadAngle)}, TEAR_FIRE_EXTRA_SHOT, + damageMultiplier, positionStep); }; if (params.isShootingBackwards) extra_fire(vector_make(-base.x, -base.y)); if (params.isShootingSideways) @@ -891,9 +1077,12 @@ void Weapon_Tears::Fire(const Vector& shootDirection, bool isShooting, bool isIn PosVel shot = Entity_Player::GetMultiShotPositionVelocity(i, weaponType, base, speed, params); shot.position = vector_add(shot.position, firePos); shot.velocity = vector_spread(shot.velocity, spreadAngle); - fire_tear(shot, 0, 1, positionStep); + fire_tear(shot, 0, damageMultiplier, positionStep); } positionStep -= eyeMaxFireDelay + 1; } } + + tear_charge_update(*this, kind, aim, isHolding); + if (kind.isChargeShot && isShooting) direction = IsAxisAligned() ? aim : get_aim_direction(aim); }