#include "entity_player.h" #include "active_items.h" #include "entity_bomb.h" #include "entity_tear.h" #include "game.h" #include "log.h" #include "manager.h" #include "menu_manager.h" #include "npc_ai.h" #include "sfx_manager.h" #include #include #include // The items a player's bombs ask about (Lua's CollectibleType and TrinketType). constexpr int COLLECTIBLE_BOBBY_BOMB = 125; constexpr int COLLECTIBLE_BUTT_BOMBS = 209; constexpr int COLLECTIBLE_SAD_BOMBS = 220; constexpr int COLLECTIBLE_BOMBER_BOY = 353; constexpr int COLLECTIBLE_SCATTER_BOMBS = 366; constexpr int COLLECTIBLE_STICKY_BOMBS = 367; constexpr int COLLECTIBLE_MR_MEGA = 106; constexpr int COLLECTIBLE_GLITTER_BOMBS = 432; constexpr int COLLECTIBLE_FAST_BOMBS = 517; constexpr int COLLECTIBLE_NANCY_BOMBS = 563; constexpr int COLLECTIBLE_ROCKET_IN_A_JAR = 583; constexpr int COLLECTIBLE_BLOOD_BOMBS = 614; constexpr int COLLECTIBLE_BRIMSTONE_BOMBS = 646; constexpr int COLLECTIBLE_GHOST_BOMBS = 727; constexpr int TRINKET_BOBS_BLADDER = 71; constexpr int TRINKET_SHORT_FUSE = 133; constexpr int TRINKET_RING_CAP = 164; // The frames between bombs (one with Fast Bombs), the push a placed bomb keeps, a bigger bomb's scale and extra // damage, the spread of extra bombs, Short Fuse's fuse and extra damage, and the consumables the HUD redraws. constexpr int BOMB_DELAY = 30; constexpr int BOMB_DELAY_FAST = 1; constexpr int BOMB_FUSE = 45; constexpr float BOMB_INHERIT = 0.1f; constexpr float BOMB_SCALE_BIG = 1.5f; constexpr float BOMB_DAMAGE_BIG = 85; constexpr float EXTRA_BOMB_SPREAD = 8; constexpr int SHORT_FUSE = 22; constexpr std::array SHORT_FUSE_DAMAGE = {15.000001f, 30.000002f, 50}; constexpr int BOMBS_MAX = 99; constexpr int CONSUMABLE_BOMBS = 1 << 2; constexpr int CONSUMABLE_GIGA_BOMBS = 1 << 6; constexpr int SOUND_GLITTER_FUSE = 867; constexpr int PLACE_SOUND_DELAY = 4; // A bomb item's tear effect: always, or by a chance out of 100 that luck raises, when the chances are rolled. struct BombItem { int collectible; int flag; int chance; float luckChance; }; constexpr std::array BOMB_ITEMS = {{{COLLECTIBLE_BOBBY_BOMB, TEAR_HOMING, 0, 0}, {COLLECTIBLE_BOBS_CURSE, TEAR_POISON, 0, 0}, {COLLECTIBLE_BUTT_BOMBS, TEAR_BUTT_BOMB, 18, 3}, {COLLECTIBLE_HOT_BOMBS, TEAR_BURN, 25, 6}, {COLLECTIBLE_SAD_BOMBS, TEAR_SAD_BOMB, 10, 3}, {COLLECTIBLE_SCATTER_BOMBS, TEAR_SCATTER_BOMB, 33, 8}, {COLLECTIBLE_STICKY_BOMBS, TEAR_STICKY, 0, 0}, {COLLECTIBLE_GLITTER_BOMBS, TEAR_GLITTER_BOMB, 10, 3}, {COLLECTIBLE_STRANGE_ATTRACTOR, TEAR_ATTRACTOR, 0, 0}, {COLLECTIBLE_BOMBER_BOY, TEAR_CROSS_BOMB, 0, 0}}}; // Whether a chance item's effect comes up: always unrolled, else a roll out of 100 under its chance and luck. static bool is_rolled(const Entity_Player& player, const BombItem& item, bool isRollChances) { if (item.chance == 0 || !isRollChances) return true; return (int)(Random() % 100) <= item.chance - (int)((double)player.luck * -item.luckChance); } // 00780560 The tear effects the player's bombs carry from its items, those with chances rolled when asked (Lua's // GetBombFlags): Bobby-Bomb to Bomber Boy, Bob's Bladder, a golden bomb and Fast Bombs (unrolled only), Blood, // Brimstone and Ghost Bombs, and Nancy Bombs' random picks. TearFlags Entity_Player::GetBombFlags(bool isRollChances) { TearFlags flags; for (const BombItem& item : BOMB_ITEMS) if (HasCollectible(item.collectible) && is_rolled(*this, item, isRollChances)) flags.set(item.flag); if (HasCollectible(COLLECTIBLE_STICKY_BOMBS)) flags.set(TEAR_EGG_FLAG); if (GetTrinketMultiplier(TRINKET_BOBS_BLADDER) > 0) flags.set(TEAR_CREEP_TRAIL); if (hasGoldenBomb && !isRollChances) flags.set(TEAR_GOLDEN_BOMB); if (HasCollectible(COLLECTIBLE_FAST_BOMBS) && !isRollChances) flags.set(TEAR_FAST_BOMB); if (HasCollectible(COLLECTIBLE_BLOOD_BOMBS)) flags.set(TEAR_BLOOD_BOMB); if (HasCollectible(COLLECTIBLE_BRIMSTONE_BOMBS) && is_rolled(*this, {0, 0, 10, 3}, isRollChances)) flags.set(TEAR_BRIMSTONE_BOMB); if (HasCollectible(COLLECTIBLE_GHOST_BOMBS) && is_rolled(*this, {0, 0, 33, 8}, isRollChances)) flags.set(TEAR_GHOST_BOMB); if (HasCollectible(COLLECTIBLE_NANCY_BOMBS) && is_rolled(*this, {0, 0, 50, 8}, isRollChances)) reconstruction_missing("Entity_Player::GetBombFlags 00780560: Nancy Bombs' random effects"); if (flags[TEAR_GHOST_BOMB]) flags.set(TEAR_SPECTRAL); return flags; } // 00780ec0 The scale of the player's bombs: bigger with Mr. Mega, a persistent effect or Black Powder. float Entity_Player::check_bomb_tearflags(const TearFlags& tearFlags) { bool isBig = HasCollectible(COLLECTIBLE_MR_MEGA) || tearFlags[TEAR_PERSISTENT] || HasCollectible(COLLECTIBLE_BLACK_POWDER); return isBig ? BOMB_SCALE_BIG : 1; } // Asks the HUD to redraw the players' corners on the next frame but one, unless a full redraw is pending. static void hud_refresh_players() { HUD& hud = g_game->hud; if (hud.hudRefreshType == HUD_REFRESH_FULL) return; hud.hudRefreshType = HUD_REFRESH_PLAYER; hud.hudRefreshCountdown = 2; } // Plays a sound through the fart seeds. static void bomb_sound_play(int sound, int frameDelay) { seed_fart_sound_override(&sound); g_manager->sfxManager.Play(sound, {.frameDelay = frameDelay}); } // Dresses a placed bomb: its size, effects and costumes, a big bomb's extra damage, a giga bomb lit at its end, Short // Fuse's quick fuse and Fast Bombs' steady footing. static void placed_bomb_setup(Entity_Player& player, Entity_Bomb& bomb, const TearFlags& flags, bool isGiga) { float scale = isGiga ? 1 : player.check_bomb_tearflags(flags); bomb.scale = scale; bomb.rocketAngle = 0; bomb.tearFlags = flags; bomb.isLoadCostumes = true; if (flags[TEAR_GLITTER_BOMB]) bomb_sound_play(SOUND_GLITTER_FUSE, 2); if (scale >= BOMB_SCALE_BIG) bomb.explosionDamage += BOMB_DAMAGE_BIG; if (isGiga) { if (const AnimationData* data = bomb.sprite.animState.animData) bomb.sprite.animState.AdvancePosition(data->length - 1); bomb.SetExplosionCountdown(BOMB_FUSE); } int shortFuse = player.GetTrinketMultiplier(TRINKET_SHORT_FUSE); if (shortFuse > 0) { bomb.SetExplosionCountdown(SHORT_FUSE); if (shortFuse <= (int)SHORT_FUSE_DAMAGE.size()) bomb.explosionDamage += SHORT_FUSE_DAMAGE[shortFuse - 1]; } if (flags[TEAR_FAST_BOMB]) bomb.AddEntityFlags(FLAG_NO_KNOCKBACK); } // Takes the first placed bomb from the player's count, a giga bomb from its giga bombs, unless it was free. static void bomb_count_take(Entity_Player& player, bool isFree) { player.numGigaBombs = std::max(0, std::min(player.numGigaBombs - 1, player.numBombs)); player.ConsumableCountChanged(CONSUMABLE_GIGA_BOMBS); hud_refresh_players(); if (isFree) return; player.numBombs = std::clamp(player.numBombs - 1, 0, BOMBS_MAX); player.ConsumableCountChanged(CONSUMABLE_BOMBS); hud_refresh_players(); } // 00780f40 Places a bomb when the bomb action is pressed and the last one was long enough ago: one from the player's // count, a golden bomb's for free, a giga bomb while it has them, and more spread around with Ring Cap. Tainted ??? // casts poop spells instead, and Tainted Forgotten's soul places none. void Entity_Player::update_bomb_input() { if (isCoopGhost || IsHologram() || playerType == PLAYER_THESOUL_B) return; if (playerType == PLAYER_BLUEBABY_B) { bool isCast = isControlsEnabled && controlsCooldown < 1 && !HasEntityFlags(FLAG_FEAR) && input_is_action_triggered(ACTION_BOMB, controllerIndex, this); if (isCast) lastActionTriggers |= 1; if (isCast && poopMana > 0) reconstruction_missing("Entity_Player::update_bomb_input 00780f40: poop spells"); return; } if (bombPlaceDelay >= 1) { if (!HasEntityFlags(FLAG_INTERPOLATION_UPDATE)) bombPlaceDelay--; return; } if (!AreControlsEnabled() || HasEntityFlags(FLAG_FEAR) || !input_is_action_triggered(ACTION_BOMB, controllerIndex, this)) return; lastActionTriggers |= 1; for (Entity* partner : {twinPlayer.get(), parent && parent->is_player() ? parent.get() : nullptr}) { Entity_Player* other = partner ? partner->ToPlayer() : nullptr; if (other && other->bombPlaceDelay == (other->HasCollectible(COLLECTIBLE_FAST_BOMBS) ? BOMB_DELAY_FAST : BOMB_DELAY)) reconstruction_missing("Entity_Player::update_bomb_input 00780f40: the bomb a twin places with its partner"); } bool isFree = hasGoldenBomb; bool isGiga = numGigaBombs > 0; if (numBombs < 1 && !isFree && HasCollectible(COLLECTIBLE_BLOOD_BOMBS)) reconstruction_missing("Entity_Player::update_bomb_input 00780f40: Blood Bombs' bomb for health"); if (numBombs < 1 && !isFree) return; bombPlaceDelay = HasCollectible(COLLECTIBLE_FAST_BOMBS) ? BOMB_DELAY_FAST : BOMB_DELAY; if (g_game->deathmatchManager.is_active()) reconstruction_missing("Entity_Player::update_bomb_input 00780f40: a versus match's bomb delay"); int bombCount = 1 + (HasTrinket(TRINKET_RING_CAP) ? GetTrinketMultiplier(TRINKET_RING_CAP) : 0); for (int i = 0; i < bombCount; i++) { TearFlags flags = GetBombFlags(false); Vector bombVelocity = vector_scale(velocity, BOMB_INHERIT); bool isAiming = fireDirection != DIRECTION_NONE && !vector_is_zero(aimDirection); if (HasCollectible(COLLECTIBLE_ROCKET_IN_A_JAR) && isAiming) reconstruction_missing("Entity_Player::update_bomb_input 00780f40: Rocket in a Jar's rockets"); Entity* spawned = g_game->Spawn({.position = pos, .velocity = bombVelocity, .spawner = this, .type = ENTITY_BOMB, .variant = isGiga ? BOMB_GIGA : BOMB_NORMAL, .seed = Random()}); Entity_Bomb& bomb = *static_cast(spawned); if (bombCount > 1) { float angle = random_unit() * RANDOM_HALF_TURN; angle += angle; bomb.pos = vector_make(std::cos(angle) * EXTRA_BOMB_SPREAD + pos.x, std::sin(angle) * EXTRA_BOMB_SPREAD + pos.y); } placed_bomb_setup(*this, bomb, flags, isGiga); if (i == 0) { bomb_count_take(*this, isFree); bomb_sound_play(SOUND_FETUS_LAND, PLACE_SOUND_DELAY); } bomb.Update(); } }