#include "boss_ai.h" #include "entity_bomb.h" #include "entity_config.h" #include "entity_laser.h" #include "entity_player.h" #include "grid_entity_trap_door.h" #include "entity_tear.h" #include "npc_caves.h" #include "room_grid.h" #include "sfx_manager.h" #include // Mom's colors (her subtype): the plain one, the blue one that summons spiders, the red one that stomps fast and // shoots from her eyes, and the Mausoleum's that fires lasers. enum MomSubtype { MOM_PLAIN, MOM_BLUE, MOM_RED, MOM_MAUSOLEUM }; // The foot stomping in the middle of the room (its variant). The parts in the doors keep variant 0. constexpr int MOM_STOMP = 10; // Where Mom's parts look in through the doors: left, top, right and bottom, 15 into the room. static const std::array MOM_DOOR_SPOTS = {vector_make(40, 280), vector_make(320, 120), vector_make(600, 280), vector_make(320, 440)}; constexpr float DOOR_SPOT_REACH = 50; constexpr float DOOR_SPOT_INSET = 15; constexpr float PLAYER_NEAR_DOOR = 70; // Where the players start: the first in front of the bottom door, the others 20 around it. static const Vector MOM_PLAYER_START = vector_make(320, 370); constexpr float MOM_PLAYER_SCATTER = 20; // The stomp: a crushing blast, a ripple and grey dust. Hard stomps come 1 in 15 instead of 1 in 40, every stomp in // the first two seconds, and laughs instead one time in three or with a player near a door. constexpr float STOMP_DAMAGE = 300; constexpr float STOMP_RADIUS = 50; constexpr float STOMP_RIPPLE_AMPLITUDE = 0.04f; constexpr float STOMP_RIPPLE_SPEED = 0.25f; constexpr int STOMP_RIPPLE_FRAMES = 13; constexpr ColorMod STOMP_DUST_COLOR = {{0.62f, 0.62f, 0.62f, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}}; constexpr ColorMod QUICK_STOMP_FLASH = {{1, 1, 1, 1}, {0, 0, 0, 0}, {1, 0.2f, 0.2f}}; constexpr int QUICK_STOMP_FLASH_FRAMES = 8; constexpr int STOMP_ODDS = 40; constexpr int STOMP_ODDS_RED = 15; constexpr int ROOM_SETTLE_FRAMES = 6; constexpr int ROOM_START_FRAMES = 60; constexpr int STOMP_COOLDOWN = 80; constexpr int STOMP_COOLDOWN_RED = 50; constexpr int QUICK_STOMP_COOLDOWN = 180; constexpr int QUICK_STOMPS = 2; constexpr int LAUGH_COOLDOWN = 30; constexpr int LAUGH_DELAY_MIN = 45; constexpr uint32_t LAUGH_DELAY_SPREAD = 120; constexpr float QUICK_STOMP_PULL = 0.2f; constexpr int CRACKWAVES = 4; constexpr int CRACKWAVE_MOM = 10; // The red Mom's stomp skips from frame 10, and again over frames 40 to 49. constexpr float RED_STOMP_START = 10; constexpr int RED_STOMP_SKIP_FROM = 39; constexpr int RED_STOMP_SKIP_TO = 50; constexpr int RED_STOMP_SKIP = 10; // The parts in the doors: an arm reaches for a player within 46 across and 90 out from the door (10 frames ahead), // an eye looks one check in 100, a summon one in 50 (in 4 or 5 with few enemies). constexpr int PART_CHECK_FRAMES = 4; constexpr float ARM_REACH_ACROSS = 46; constexpr float ARM_REACH_OUT = 90; constexpr float PLAYER_LEAD_FRAMES = 10; constexpr uint32_t ARM_ODDS_MASK = 7; constexpr float ARM_SIZE_SCALE = 1.35f; constexpr float ARM_SLAP_REACH = 45; constexpr float ARM_SLAP_RADIUS = 35; constexpr float ARM_SLAP_DAMAGE = 25; constexpr float ARM_SLAP_STRONG = 50; constexpr float ARM_VOLUME = 1.5f; constexpr uint32_t EYE_ODDS = 100; constexpr uint32_t MOM_SUMMON_ODDS = 50; constexpr int SUMMON_CROWD = 7; constexpr int SUMMON_CROWD_SOON = 5; constexpr int SUMMON_COOLDOWN = 100; constexpr float SUMMON_DOOR_DEPTH = 18; constexpr float SUMMON_VOLUME_MIN = 0.8f; constexpr float SUMMON_VOLUME_SPREAD = 0.4f; constexpr int EYE_COOLDOWN_RED = 100; constexpr int EYE_SHOT_SETTLE_FRAMES = 121; constexpr float EYE_SHOT_SPEED = 10; // The Mausoleum's eye lasers: two beams that sweep 6 apart, then 12 the other way after 5 and back after 15 frames. constexpr int EYE_LASER_VARIANT = 1; constexpr int EYE_LASER_TIMEOUT = 20; constexpr float EYE_LASER_SWEEP = 6; constexpr float EYE_LASER_SWEEP_SPEED = 2; constexpr float EYE_LASER_TURN = 12; constexpr float EYE_LASER_DEPTH = 1000; constexpr uint32_t EYE_LASER_TURN_FRAMES = 5; constexpr uint32_t EYE_LASER_BACK_FRAMES = 15; // Mom's death: every enemy left takes 100, and blood runs down the walls. constexpr float DEATH_DAMAGE = 100; constexpr int DEATH_DAMAGE_COUNTDOWN = 30; constexpr int DEATH_BLOOD_FRAMES = 20; constexpr int DEATH_BLOOD_DROPS = 6; // Her voice when hurt by more than 10 to 29 at once, 25 to 54 frames later, higher for a tiny Mom, lower for a giant. constexpr int HURT_VOICE_MIN = 10; constexpr uint32_t HURT_VOICE_SPREAD = 20; constexpr int HURT_VOICE_DELAY = 25; constexpr uint32_t HURT_VOICE_DELAY_SPREAD = 30; constexpr int LAUGH_START_DELAY = 45; constexpr float MOM_TINY_PITCH = 1.5f; constexpr float MOM_GIANT_PITCH = 0.5f; // The enemies each color calls through a door, as type and variant. constexpr std::array, 12> MOM_SUMMONS = { {{10, 0}, {11, 0}, {12, 0}, {14, 0}, {15, 0}, {16, 0}, {18, 0}, {21, 0}, {23, 0}, {24, 0}, {26, 0}, {26, 1}}}; constexpr std::array, 5> MOM_SUMMONS_BLUE = {{{85, 0}, {94, 0}, {89, 0}, {86, 0}, {29, 1}}}; constexpr std::array, 6> MOM_SUMMONS_MAUSOLEUM = { {{18, 0}, {61, 0}, {248, 0}, {886, 1}, {246, 1}, {24, 3}}}; constexpr std::pair CURSED_GLOBIN = {24, 3}; constexpr int CURSED_GLOBINS_MAX = 2; constexpr int ENTITY_ATTACK_FLY = 18; // DamageRadius hurts with a 30 frame countdown, and passes 3.5 to the tear effects. Enemies are types 10 to 999. constexpr int RADIUS_DAMAGE_COUNTDOWN = 30; constexpr float RADIUS_TEAR_DAMAGE = 3.5f; constexpr int ENTITY_NPC_FIRST = 10; constexpr int ENTITY_NPC_LAST = 999; // 006fed60 Game::DamageRadius: everything collidable within reach of a spot is hurt, players and familiars by 1 (2 // for a hit of the threshold or more) unless a friendly enemy dealt it, enemies (with the tear effects) only when a // player, a familiar, a charmed or friendly source or the caller asks. Poison spares a player immune to it. void damage_radius(const RadiusDamage& hit) { Entity* source = hit.source; EntityRef sourceRef(source); bool isPlayerSource = source && (source->type == ENTITY_PLAYER || (source->type == ENTITY_FAMILIAR && !source->HasEntityFlags(FLAG_CHARM))); bool isHitPlayers = isPlayerSource ? hit.isHitAll : !(source && source->HasEntityFlags(FLAG_FRIENDLY)); bool isAllied = source && (isPlayerSource || source->HasEntityFlags(FLAG_CHARM) || source->HasEntityFlags(FLAG_FRIENDLY)); bool isDamageEnemies = isAllied || hit.isHitAll; for (Entity* entity : entity_query_radius(hit.position, hit.radius, QUERY_ALL)) { if (entity->entityCollisionClass == ENTCOLL_NONE) continue; bool isPlayerSide = entity->type == ENTITY_PLAYER || entity->type == ENTITY_FAMILIAR; if (isPlayerSide && isHitPlayers) { bool isPoisonSpared = hit.tearFlags[TEAR_POISON] && entity->type == ENTITY_PLAYER && static_cast(entity)->HasPoisonImmunity(); if (isPoisonSpared) continue; float damage = hit.damage < hit.playerDamageThreshold ? 1 : 2; entity->TakeDamage(damage, hit.damageFlags, sourceRef, RADIUS_DAMAGE_COUNTDOWN); } else if (entity->type >= ENTITY_NPC_FIRST && entity->type <= ENTITY_NPC_LAST && isDamageEnemies) { entity->TakeDamage(hit.damage, hit.damageFlags, sourceRef, RADIUS_DAMAGE_COUNTDOWN); Entity_Tear::ApplyTearFlagEffects(entity, hit.position, hit.tearFlags, source, RADIUS_TEAR_DAMAGE); } } } // The frames since the room started, or -1 before it did. static int room_frames_get() { Room& room = *g_game->room; return room.isInitialized ? g_game->frameCount - room.enterFrame : -1; } // The pitch Mom's voice takes for her champion size. static float voice_pitch_get(Entity_NPC& npc) { if (npc.championColorIdx == CHAMPION_TINY) return MOM_TINY_PITCH; if (npc.championColorIdx == CHAMPION_GIANT) return MOM_GIANT_PITCH; return 1; } // The Mausoleum's Mom wears the "_mausoleum" spritesheet on every layer but the shadow. static void mausoleum_sheets_load(ANM2& sprite) { for (int i = 0; i < (int)sprite.layerStates.size(); i++) { if (i == sprite.shadowLayerIndex) continue; const LayerData* data = sprite.GetLayer(i)->layerData; // A layer with no sheet would trim past its empty path in the original. Here it is skipped. if (!data || data->spriteSheetPath.size() < 4) continue; std::string path = data->spriteSheetPath; path.resize(path.size() - 4); sprite.ReplaceSpritesheet(i, path + "_mausoleum.png"); } sprite.LoadGraphics(); } // The foot takes every other part of Mom without a parent as its own, numbering them from 1 and giving them its color. static void parts_gather(Entity_NPC& foot) { int index = 1; for (Entity* entity : entity_query(ENTITY_MOM, -1)) { auto* part = static_cast(entity); if (part == &foot || part->parent) continue; part->Morph(part->type, part->variant, foot.subtype, -1); part->health = part->maxHitPoints; part->parent = &foot; part->i1 = index++; } } // Every player stands in front of the bottom door: the first right there, the others scattered around it. static void players_place() { PlayerManager& players = g_game->playerManager; for (size_t i = 0; i < players.playerList.size(); i++) { Vector spot = MOM_PLAYER_START; if (i != 0) spot = vector_add(MOM_PLAYER_START, vector_scale(random_direction(), MOM_PLAYER_SCATTER)); players.playerList[i]->Teleport(spot, false, false); } } // The first frame: a part placed in a door turns to face the room and sinks 15 into it. The one in the middle // becomes the foot (unless spawned as a part of another), gathers the rest and puts the players at the bottom. static void mom_init(Entity_NPC& npc) { npc_sound_play(SOUND_MOM_VOX_ISAAC, 1, LAUGH_START_DELAY, voice_pitch_get(npc)); npc.AddEntityFlags(FLAG_NO_DEATH_TRIGGER); if (npc.variant == MOM_STOMP) { npc.health = npc.maxHitPoints; npc.i1 = 0; npc.projectileDelay = 0; npc.targetPosition = npc.pos; npc.state = NPC_STATE_IDLE; npc.shadowSize = 0; npc.entityCollisionClass = ENTCOLL_NONE; npc.entityGridCollisionClass = GRIDCOLL_GROUND; return; } bool isFoot = true; for (int i = 0; i < (int)MOM_DOOR_SPOTS.size(); i++) { Vector toSpot = vector_sub(MOM_DOOR_SPOTS[i], npc.pos); if (vector_length_squared(toSpot) >= DOOR_SPOT_REACH * DOOR_SPOT_REACH) continue; float angle = (float)i * 90; npc.sprite.rotation = angle - 90; npc.entityGridCollisionClass = GRIDCOLL_NONE; npc.pos = vector_add(MOM_DOOR_SPOTS[i], vector_scale(vector_from_angle(angle), DOOR_SPOT_INSET)); npc.ClearEntityFlags(FLAG_APPEAR); isFoot = false; break; } npc.targetPosition = npc.pos; if (!npc.parent && isFoot) { npc.Morph(npc.type, MOM_STOMP, npc.subtype, -1); npc.health = npc.maxHitPoints; npc.i1 = 0; npc.projectileDelay = 0; parts_gather(npc); } if (npc.subtype == MOM_MAUSOLEUM) mausoleum_sheets_load(npc.sprite); npc.shadowSize = 0; npc.entityCollisionClass = ENTCOLL_NONE; if (isFoot) { players_place(); npc.entityGridCollisionClass = GRIDCOLL_GROUND; } npc.state = NPC_STATE_IDLE; } // The stomp's landing: a crushing blast where the foot came down and a ripple through the room. static void stomp_land(Entity_NPC& npc) { npc.PlaySound(SOUND_HELLBOSS_GROUNDPOUND, 1, 2, false, 1); explosion_damage({.position = npc.pos, .source = &npc, .damageFlags = DAMAGE_CRUSH, .damage = STOMP_DAMAGE, .radius = STOMP_RADIUS, .isLineCheck = false}); shockwave_make(npc.pos, STOMP_RIPPLE_AMPLITUDE, STOMP_RIPPLE_SPEED, STOMP_RIPPLE_FRAMES); } // Whether a player stands within 70 of a door, where Mom's parts guard instead of the foot. static bool is_player_near_door(Entity_NPC& npc) { for (const Vector& spot : MOM_DOOR_SPOTS) { Vector toPlayer = vector_sub(npc.GetPlayerTarget()->pos, spot); if (vector_length_squared(toPlayer) < PLAYER_NEAR_DOOR * PLAYER_NEAR_DOOR) return true; } return false; } // The foot's next move from rest: a stomp on its target (one where it stands while the room starts), a run of quick // stomps for the Mausoleum's, or a laugh when the roll or a player near a door says no. static void stomp_start(Entity_NPC& npc) { int roomFrames = room_frames_get(); bool isStarting = roomFrames < ROOM_START_FRAMES; bool isWanted = Random() % 3 == 0 || npc.subtype == MOM_RED || isStarting; if (!isStarting && (!isWanted || is_player_near_door(npc))) { npc.PlaySound(SOUND_MOM_VOX_ISAAC, 1, LAUGH_DELAY_MIN + (int)(Random() % LAUGH_DELAY_SPREAD), false, 1); npc.projectileCooldown = LAUGH_COOLDOWN; return; } npc.PlaySound(SOUND_MOM_VOX_GRUNT, 1, 2, false, 1); npc.targetPosition = isStarting ? npc.pos : npc.GetPlayerTarget()->pos; npc.pos = npc.targetPosition; if (npc.subtype == MOM_MAUSOLEUM && !isStarting && npc.projectileDelay <= 0) { npc_anim_restart(npc.sprite, "QuickStompBegin"); npc.state = NPC_STATE_JUMP; npc.i2 = QUICK_STOMPS; npc.projectileCooldown = QUICK_STOMP_COOLDOWN; return; } npc_anim_restart(npc.sprite, "Stomp"); npc.state = NPC_STATE_STOMP; npc.stateFrame = 0; npc.projectileCooldown = STOMP_COOLDOWN; if (npc.subtype != MOM_RED) return; if (npc.sprite.animState.animData) npc.sprite.animState.SetFrameFloat(RED_STOMP_START); npc.stateFrame = (int)RED_STOMP_START; npc.projectileCooldown = STOMP_COOLDOWN_RED; npc.projectileDelay = 0; } // A stomp: the foot is solid from its landing until it lifts, and the red Mom's skips ahead. static void stomp_update(Entity_NPC& npc) { ANM2& sprite = npc.sprite; npc.pos = npc.targetPosition; bool isDown = sprite.animState.animData && sprite.WasEventTriggered("Shoot") && !sprite.WasEventTriggered("Lift"); npc.entityCollisionClass = isDown ? ENTCOLL_ALL : ENTCOLL_NONE; if (sprite.animState.animData && sprite.IsEventTriggered("Shoot")) { stomp_land(npc); npc.MakeGroundPoof(npc.pos, STOMP_DUST_COLOR, 1); } npc.stateFrame += npc_ticks_get(npc); int frame = sprite.GetFrame(); if (npc.subtype != MOM_RED || frame <= RED_STOMP_SKIP_FROM || frame >= RED_STOMP_SKIP_TO) return; if (sprite.animState.animData) sprite.animState.SetFrameFloat(RED_STOMP_SKIP_TO); npc.stateFrame += RED_STOMP_SKIP; } // The next of the quick stomps, the last one's end, or rest once they are done. static void quick_stomp_next(Entity_NPC& npc) { if (npc.i2 < 1) { npc.state = NPC_STATE_IDLE; return; } npc.i2--; npc_anim_restart(npc.sprite, npc.i2 != 0 ? "QuickStomp" : "QuickStompEnd"); } // The Mausoleum's quick stomps: each landing crushes, the last sends four crackwaves out, and between them the foot // slides to its target, flashing red before the last. static void quick_stomp_update(Entity_NPC& npc) { ANM2& sprite = npc.sprite; if (!sprite.animState.animData) quick_stomp_next(npc); else { if (sprite.IsEventTriggered("Shoot")) { npc.entityCollisionClass = ENTCOLL_ALL; stomp_land(npc); npc.targetPosition = npc.pos; if (npc.i2 == 0) { npc.MakeBloodPoof(npc.pos, COLOR_DEFAULT, 1); for (int i = 0; i < CRACKWAVES; i++) { auto* wave = static_cast(g_game->Spawn({.position = npc.pos, .spawner = &npc, .subType = CRACKWAVE_MOM, .type = ENTITY_EFFECT, .variant = EFFECT_CRACKWAVE, .seed = Random()})); wave->parent = &npc; wave->rotation = (float)i * 90; } } else npc.MakeGroundPoof(npc.pos, STOMP_DUST_COLOR, 1); } if (sprite.IsEventTriggered("Lift")) { npc.entityCollisionClass = ENTCOLL_NONE; if (npc.i2 > 0) { npc.targetPosition = npc.GetPlayerTarget()->pos; if (npc.i2 == 1) npc.SetColor(QUICK_STOMP_FLASH, QUICK_STOMP_FLASH_FRAMES, 255, true, true); } } if (npc_anim_is_done(npc)) quick_stomp_next(npc); } if (npc.entityCollisionClass == ENTCOLL_NONE) npc.velocity = vector_scale(vector_sub(npc.targetPosition, npc.pos), QUICK_STOMP_PULL); else npc.pos = npc.targetPosition; } // Mom's death: every enemy left in the room takes 100, blood runs down the walls, and the death counts again. static void mom_death(Entity_NPC& npc) { npc.PlaySound(SOUND_MOM_VOX_DEATH, 1, 2, false, 1); Room& room = *g_game->room; EntityList_EL& entities = room.entityList.updateEL; for (size_t i = 0; i < entities.size(); i++) if (entities[i]->CanShutDoors()) entities[i]->TakeDamage(DEATH_DAMAGE, 0, EntityRef(), DEATH_DAMAGE_COUNTDOWN); room.bloodFromWallsDuration = DEATH_BLOOD_FRAMES; room.bloodFromWallsCount = DEATH_BLOOD_DROPS; npc.ClearEntityFlags(FLAG_NO_DEATH_TRIGGER); } // The foot: from rest it stomps when its cooldown is out, then plays out the stomp. static void foot_update(Entity_NPC& npc) { int roomFrames = room_frames_get(); int odds = npc.subtype == MOM_RED ? STOMP_ODDS_RED : STOMP_ODDS; bool isReady = npc.projectileCooldown == 0 && roomFrames > ROOM_SETTLE_FRAMES && (random_below(odds) == 0 || roomFrames < ROOM_START_FRAMES) && npc.state == NPC_STATE_IDLE; if (isReady) stomp_start(npc); if (npc.state == NPC_STATE_STOMP) stomp_update(npc); else if (npc.state == NPC_STATE_JUMP) quick_stomp_update(npc); else { npc.pos = npc.targetPosition; npc.shadowSize = 0; npc.entityCollisionClass = ENTCOLL_NONE; } if (npc.isDead) mom_death(npc); } // Sets an eye laser sweeping at once by an angle each frame at a speed, if it is still a laser. static void eye_laser_sweep(Entity* entity, float degrees, float speed) { if (!entity || entity->type != ENTITY_LASER) return; auto* laser = static_cast(entity); laser->isActiveRotating = true; laser->rotationDelay = 0; laser->rotationDegrees = degrees; laser->rotationSpd = speed; } // 004d2f50 The eye lasers' first turn: the first sweeps back, the second on. static void eye_lasers_turn(Entity_Effect* timer) { eye_laser_sweep(timer->child, -EYE_LASER_TURN, -EYE_LASER_SWEEP_SPEED); eye_laser_sweep(timer->target, EYE_LASER_TURN, EYE_LASER_SWEEP_SPEED); } // 004d2fd0 The eye lasers' second turn, the other way. static void eye_lasers_back(Entity_Effect* timer) { eye_laser_sweep(timer->child, EYE_LASER_TURN, EYE_LASER_SWEEP_SPEED); eye_laser_sweep(timer->target, -EYE_LASER_TURN, -EYE_LASER_SWEEP_SPEED); } // Fires the Mausoleum's two eye lasers out of the door, sweeping apart, with timers to turn them. static void eye_lasers_fire(Entity_NPC& npc) { float angle = npc.sprite.rotation + 90; float depth = std::sin(angle * DEGREES_TO_RADIANS) >= 0 ? EYE_LASER_DEPTH : 0; std::array lasers{}; for (int i = 0; i < 2; i++) { float side = i == 0 ? 1 : -1; lasers[i] = Entity_Laser::ShootAngle({.position = npc.pos, .source = &npc, .angleDegrees = angle, .timeout = EYE_LASER_TIMEOUT, .variant = EYE_LASER_VARIANT}); lasers[i]->renderDepthOffset = depth; eye_laser_sweep(lasers[i], side * EYE_LASER_SWEEP, side * EYE_LASER_SWEEP_SPEED); lasers[i]->Update(); } Entity_Effect* turn = Entity_Effect::CreateTimer(reinterpret_cast(&eye_lasers_turn), EYE_LASER_TURN_FRAMES, 0, false); turn->child = lasers[0]; turn->target = lasers[1]; Entity_Effect* back = Entity_Effect::CreateTimer(reinterpret_cast(&eye_lasers_back), EYE_LASER_BACK_FRAMES, 0, false); back->child = lasers[0]; back->target = lasers[1]; } // A summon through the door: an enemy of the color's list 18 into the room, the Mausoleum's cursed Globins at most // two (then an attack fly). static void part_summon(Entity_NPC& npc) { Vector inward = vector_resized(vector_sub(npc.pos, Room::GetCenterPos()), SUMMON_DOOR_DEPTH); std::pair summon; if (npc.subtype == MOM_MAUSOLEUM) { summon = MOM_SUMMONS_MAUSOLEUM[Random() % MOM_SUMMONS_MAUSOLEUM.size()]; bool isCrowded = summon == CURSED_GLOBIN && entity_query(CURSED_GLOBIN.first, CURSED_GLOBIN.second).size() >= CURSED_GLOBINS_MAX; if (isCrowded) summon = {ENTITY_ATTACK_FLY, 0}; } else if (npc.subtype == MOM_BLUE) summon = MOM_SUMMONS_BLUE[Random() % MOM_SUMMONS_BLUE.size()]; else summon = MOM_SUMMONS[Random() % MOM_SUMMONS.size()]; npc.PlaySound(SOUND_SUMMONSOUND, random_unit() * SUMMON_VOLUME_SPREAD + SUMMON_VOLUME_MIN, 2, false, 1); g_game->Spawn({.position = vector_sub(npc.pos, inward), .spawner = &npc, .type = summon.first, .variant = summon.second, .seed = Random()}); npc.projectileCooldown = SUMMON_COOLDOWN; } // Whether a player (10 frames ahead) is in an arm's reach of the door, measured along the part's facing. static bool is_player_in_arm_reach(Entity_NPC& npc) { Entity* target = npc.GetPlayerTarget(); Vector ahead = vector_add(target->pos, vector_scale(target->velocity, PLAYER_LEAD_FRAMES)); Vector away = vector_sub(npc.pos, ahead); float angle = -npc.sprite.rotation * DEGREES_TO_RADIANS; float across = away.x * std::cos(angle) - away.y * std::sin(angle); float out = away.y * std::cos(angle) + away.x * std::sin(angle); return std::abs(across) <= ARM_REACH_ACROSS && std::abs(out) <= ARM_REACH_OUT; } // Every 4 frames once the room has run a second, a part picks what to do from rest: an arm for a player in reach // (1 in 8, never the Mausoleum's or while the foot stomps), else 1 in 100 an eye (a laser one for the Mausoleum's), // else sometimes a summon. static void part_choose(Entity_NPC& npc) { Entity_NPC& foot = *npc.ParentNPC(); int roomFrames = room_frames_get(); bool isSettled = roomFrames > ROOM_START_FRAMES; bool isArmReady = npc.state != NPC_STATE_ATTACK2 && npc.state != NPC_STATE_ATTACK4 && foot.state != NPC_STATE_STOMP && foot.state != NPC_STATE_JUMP && npc.subtype != MOM_MAUSOLEUM; if (is_player_in_arm_reach(npc) && isArmReady && (Random() & ARM_ODDS_MASK) == 0 && isSettled) { npc_anim_restart(npc.sprite, "ArmOpen"); npc.state = NPC_STATE_ATTACK2; npc.SetSize(npc.config->collisionRadius * ARM_SIZE_SCALE, npc.config->collisionRadiusMulti, npc.config->gridCollisionPoints); return; } bool isEyeFree = npc.subtype == MOM_RED ? foot.projectileDelay < 1 && foot.projectileCooldown == 0 : foot.projectileDelay < 2; if (Random() % EYE_ODDS == 0 && npc.state == NPC_STATE_IDLE && isEyeFree) { bool isLaser = npc.subtype == MOM_MAUSOLEUM && foot.state != NPC_STATE_JUMP && isSettled; npc_anim_restart(npc.sprite, isLaser ? "EyeLaser" : "Eye"); foot.projectileDelay++; npc.state = isLaser ? NPC_STATE_ATTACK4 : NPC_STATE_ATTACK; if (npc.subtype == MOM_RED) foot.projectileCooldown = EYE_COOLDOWN_RED; return; } int enemies = g_game->room->GetAliveEnemiesCount(); bool isSummonRolled = enemies <= SUMMON_CROWD && Random() % MOM_SUMMON_ODDS == 0; if (!isSummonRolled && (enemies > SUMMON_CROWD_SOON || random_below(4 + (npc.subtype == MOM_MAUSOLEUM)) != 0)) return; bool isSummonFree = npc.projectileCooldown < 1 && npc.state != NPC_STATE_ATTACK4 && foot.projectileCooldown == 0; if (isSummonFree && isSettled && npc.subtype != MOM_RED) { npc.sprite.Play(Random() & 1 ? "Fat02" : "Fat01"); npc.state = NPC_STATE_ATTACK3; } } // A part in a door: it shares the foot's health, dies with it, and slaps, looks, shoots or summons from there. static void part_update(Entity_NPC& npc, int prevState) { Entity_NPC& foot = *npc.ParentNPC(); npc.pos = npc.targetPosition; if (foot.health > npc.health) foot.health = npc.health; else npc.health = foot.health; if (npc.isDead) foot.Kill(EntityRef()); ANM2& sprite = npc.sprite; if (npc.state == NPC_STATE_ATTACK2 && sprite.animState.animData && sprite.IsEventTriggered("Appear")) { npc.PlaySound(SOUND_FORESTBOSS_STOMPS, ARM_VOLUME, 2, false, 1); Vector reach = vector_scale(vector_from_angle(npc.sprite.rotation + 90), ARM_SLAP_REACH); damage_radius({.position = vector_add(npc.pos, reach), .source = &npc, .damage = ARM_SLAP_DAMAGE, .playerDamageThreshold = ARM_SLAP_STRONG, .radius = ARM_SLAP_RADIUS}); } if (npc.state != NPC_STATE_ATTACK2 && npc.size > npc.config->collisionRadius) npc.SetSize(npc.config->collisionRadius, npc.config->collisionRadiusMulti, npc.config->gridCollisionPoints); if (npc.IsFrame(PART_CHECK_FRAMES, (int)npc.index) && room_frames_get() > ROOM_START_FRAMES) part_choose(npc); if (npc.state == NPC_STATE_IDLE) npc.entityCollisionClass = ENTCOLL_NONE; else { bool isOut = sprite.animState.animData && sprite.WasEventTriggered("Appear") && !sprite.WasEventTriggered("Disappear"); npc.entityCollisionClass = isOut ? ENTCOLL_ALL : ENTCOLL_NONE; if (npc.state == NPC_STATE_ATTACK3 && sprite.animState.animData && sprite.IsEventTriggered("Shoot")) part_summon(npc); bool isEyeShot = npc.state == NPC_STATE_ATTACK && npc.subtype == MOM_RED && room_frames_get() >= EYE_SHOT_SETTLE_FRAMES && sprite.IsEventTriggered("Shoot"); if (isEyeShot) { Vector velocity = vector_resized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos), EYE_SHOT_SPEED); npc.FireProjectiles(vector_add(npc.pos, velocity), velocity, PROJECTILES_THREE, ProjectileParams()); } } if (npc.state == NPC_STATE_ATTACK4 && sprite.IsEventTriggered("Shoot")) eye_lasers_fire(npc); bool isEyeDone = prevState != npc.state && (prevState == NPC_STATE_ATTACK || prevState == NPC_STATE_ATTACK4); if (isEyeDone && npc.subtype != MOM_RED) foot.projectileDelay--; } // 004d1290 NpcAI::ENTITY_MOM: Mom's foot stomping in the middle of the room and her eyes and arms in the doors. // Big hits make her cry out, a part whose foot is gone dies, and her own blasts never hurt her. void boss_mom_update(Entity_NPC& npc) { if ((float)(Random() % HURT_VOICE_SPREAD + HURT_VOICE_MIN) < npc.pendingDamage) { int delay = (int)(Random() % HURT_VOICE_DELAY_SPREAD) + HURT_VOICE_DELAY; npc_sound_play(SOUND_MOM_VOX_HURT, 1, delay, voice_pitch_get(npc)); } int prevState = npc.state; bool isFootGone = npc.i1 != 0 && (!npc.parent || npc.parent->isDead); if (npc.state == NPC_STATE_INIT) { bool isFootSpawned = npc.variant == MOM_STOMP; mom_init(npc); if (isFootSpawned) return; } else if (isFootGone) npc.Kill(EntityRef()); else { if (npc_anim_is_done(npc) && prevState != NPC_STATE_JUMP) npc.state = NPC_STATE_IDLE; if (npc.i1 == 0) foot_update(npc); else part_update(npc, prevState); } if (prevState != NPC_STATE_INIT) { if (npc.projectileCooldown > 0) npc.projectileCooldown = std::max(npc.projectileCooldown - npc_ticks_get(npc), 0); npc.friction *= 0.8f; } if (npc.pendingDamage <= 0) return; for (DamageEvent& event : npc.damageEvents) if (event.source.type == ENTITY_MOM) event.damage = 0; }