480 lines
21 KiB
C++
480 lines
21 KiB
C++
#include "entity_player.h"
|
|
#include "active_items.h"
|
|
#include "boss_ai.h"
|
|
#include "entity_config.h"
|
|
#include "entity_effect.h"
|
|
#include "entity_factory.h"
|
|
#include "entity_npc.h"
|
|
#include "entity_pickup.h"
|
|
#include "level.h"
|
|
#include "npc_basement.h"
|
|
#include "room_grid.h"
|
|
#include "game.h"
|
|
#include "log.h"
|
|
#include "loot_list.h"
|
|
#include "lua_engine.h"
|
|
#include "manager.h"
|
|
#include "npc_ai.h"
|
|
#include "pocket_items.h"
|
|
#include "room.h"
|
|
#include "room_config.h"
|
|
#include "room_descriptor.h"
|
|
#include "room_path.h"
|
|
#include "grid_entity_door.h"
|
|
#include <set>
|
|
#include <algorithm>
|
|
#include <cctype>
|
|
|
|
// The shifts of the draw among an entity's devolve list, seeded by the room's decoration.
|
|
constexpr std::array<uint32_t, 3> DEVOLVE_SHIFTS = {4, 3, 27};
|
|
constexpr float DEVOLVE_RANDOM_UNIT = 2.3283062e-10f;
|
|
constexpr int GRID_ENTRY_FIRST = 1000;
|
|
constexpr int ENTRY_EFFECT_OLD = 999;
|
|
|
|
// Whether an entity config walks: a ground grid collision, or none named with collision points.
|
|
static bool is_config_walking(const EntityConfig_Entity* config)
|
|
{
|
|
if (!config) return true;
|
|
std::string_view grid = config->gridCollisionClassString;
|
|
return grid == "ground" || (grid.empty() && config->gridCollisionPoints >= 1);
|
|
}
|
|
|
|
// 00705480 Turns an entity into one of its weaker forms from entities2.xml, drawn by weight on the room's decoration
|
|
// seed: an enemy keeps its health share and champion and is counted with the ambush, a flying one turning into a walker
|
|
// is moved where the players can reach. A grid form replaces it on its cell with a poof. A friendly entity, one a
|
|
// mod keeps or the Delirium cannot change.
|
|
bool game_enemy_devolve(Entity& entity, Entity** outEntity)
|
|
{
|
|
EntityConfig_Entity* config = entity.config;
|
|
if (entity.HasEntityFlags(FLAG_FRIENDLY)) return false;
|
|
if (lua_engine_get().PreEntityDevolve(&entity)) return true;
|
|
if (!config || config->devolve.empty() || entity.type == ENTITY_DELIRIUM) return false;
|
|
|
|
Room& room = *g_game->room;
|
|
float healthShare = 1;
|
|
int champion = CHAMPION_NONE;
|
|
if (entity.IsEnemy())
|
|
{
|
|
champion = static_cast<Entity_NPC&>(entity).championColorIdx;
|
|
if (entity.maxHitPoints > 0) healthShare = std::clamp(entity.health / entity.maxHitPoints, 0.0f, 1.0f);
|
|
}
|
|
float total = 0;
|
|
for (const Devolve& form : config->devolve) total += form.weight;
|
|
bool isFlying = !is_config_walking(config);
|
|
RNG rng = {room.descriptor ? room.descriptor->decorationSeed : 0, DEVOLVE_SHIFTS[0], DEVOLVE_SHIFTS[1],
|
|
DEVOLVE_SHIFTS[2]};
|
|
float roll = (float)rng.Next() * DEVOLVE_RANDOM_UNIT * total;
|
|
|
|
for (const Devolve& form : config->devolve)
|
|
{
|
|
if (roll >= form.weight)
|
|
{
|
|
roll -= form.weight;
|
|
continue;
|
|
}
|
|
if (form.type >= GRID_ENTRY_FIRST)
|
|
{
|
|
int gridIndex = room.GetGridIndex(entity.pos);
|
|
if (gridIndex != -1)
|
|
room_entry_spawn(room, {.type = (uint32_t)form.type, .variant = form.variant},
|
|
{.gridIndex = gridIndex, .seed = Random()});
|
|
if (entity.spawnGridIndex >= 0 && room_entity_is_persistent(entity.type, entity.variant))
|
|
room.descriptor->restrictedGridIndexes.insert(entity.spawnGridIndex);
|
|
entity.Remove();
|
|
Entity* poof = g_game->Spawn({.position = room.GetGridPosition(gridIndex),
|
|
.type = ENTITY_EFFECT,
|
|
.variant = EFFECT_POOF01,
|
|
.seed = Random()});
|
|
poof->Update();
|
|
if (outEntity) *outEntity = poof;
|
|
return true;
|
|
}
|
|
if (form.type == 0) return false;
|
|
|
|
int type = form.type == ENTRY_EFFECT_OLD ? ENTITY_EFFECT : form.type;
|
|
int variant = form.variant;
|
|
Entity_NPC::Redirect(&type, &variant);
|
|
bool isWalking = is_config_walking(g_manager->entityConfig.GetEntity(type, variant, form.subtype));
|
|
if (isFlying && isWalking && !is_reachable_from_player(room, {.position = entity.pos}))
|
|
{
|
|
reconstruction_missing("Game::DevolveEnemy 00705480: Room::find_reachable_position 00823d10");
|
|
entity.velocity = {};
|
|
}
|
|
auto* devolved = static_cast<Entity_NPC*>(g_game->Spawn({.position = entity.pos,
|
|
.velocity = entity.velocity,
|
|
.subType = form.subtype,
|
|
.type = type,
|
|
.variant = variant,
|
|
.seed = Random()}));
|
|
if (devolved->IsEnemy())
|
|
{
|
|
if (champion >= 0) devolved->Morph(devolved->type, devolved->variant, devolved->subtype, champion);
|
|
devolved->AddEntityFlags(FLAG_AMBUSH);
|
|
devolved->health = healthShare * devolved->maxHitPoints;
|
|
}
|
|
devolved->Update();
|
|
devolved->spawnGridIndex = entity.spawnGridIndex;
|
|
if (outEntity) *outEntity = devolved;
|
|
entity.Remove();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// A grid entity or entity the D12 may turn a cell into, with its weight: a negative type is an entity (a fireplace or
|
|
// movable TNT) spawned on a decoration. The soft draw holds only the first fifteen rows (00b62d60).
|
|
struct D12Outcome
|
|
{
|
|
int type = 0;
|
|
int variant = 0;
|
|
int weight = 0;
|
|
};
|
|
|
|
constexpr int D12_SOFT_ROWS = 15;
|
|
constexpr uint32_t D12_SHIFT_INDEX = 17;
|
|
constexpr uint32_t D12_PICK_SHIFT_INDEX = 35;
|
|
constexpr int D12_DECORATION_VARIANT = 1000;
|
|
constexpr int D12_ACHIEVEMENT_HOLY_POOP = 398;
|
|
constexpr int D12_ACHIEVEMENT_CHARMING_POOP = 605;
|
|
constexpr int D12_ACHIEVEMENT_GOLDEN_ROCK = 612;
|
|
constexpr int D12_ACHIEVEMENT_SUPERSTITION_ROCK = 323;
|
|
constexpr std::array<D12Outcome, 29> D12_OUTCOMES = {
|
|
{{GRID_POOP, 0, 500}, {GRID_POOP, 1, 100}, {GRID_POOP, 2, 100},
|
|
{GRID_POOP, 3, 10}, {GRID_POOP, 4, 10}, {GRID_POOP, 5, 50},
|
|
{GRID_POOP, 6, 10}, {GRID_SPIKES_ONOFF, 0, 100}, {GRID_SPIDERWEB, 0, 150},
|
|
{GRID_TNT, 0, 100}, {-ENTITY_FIREPLACE, 0, 300}, {-ENTITY_FIREPLACE, 1, 150},
|
|
{-ENTITY_MOVABLE_TNT, 0, 50}, {GRID_PRESSURE_PLATE, 1, 10}, {GRID_PRESSURE_PLATE, 9, 1},
|
|
{GRID_ROCK, 0, 500}, {GRID_ROCKB, 0, 250}, {GRID_ROCKT, 0, 25},
|
|
{GRID_ROCK_BOMB, 0, 25}, {GRID_ROCK_ALT, 0, 100}, {GRID_ROCK_SPIKED, 0, 100},
|
|
{GRID_ROCK_GOLD, 0, 25}, {GRID_ROCK_SS, 0, 5}, {GRID_SPIKES, 0, 100},
|
|
{GRID_LOCK, 0, 25}, {GRID_TRAPDOOR, 0, 5}, {GRID_STAIRS, 0, 3},
|
|
{-ENTITY_FIREPLACE, 2, 40}, {-ENTITY_FIREPLACE, 3, 40}}};
|
|
|
|
// An outcome as the run allows it (FUN_005c7bf0): locked poops and rocks fall back to plain ones, and a daily run gets
|
|
// a rock for a trapdoor.
|
|
static D12Outcome d12_outcome_allowed(D12Outcome outcome)
|
|
{
|
|
PersistentGameData& data = g_manager->persistentGameData;
|
|
bool isDaily = g_game->dailyChallenge._id != 0;
|
|
if (outcome.type == GRID_POOP && outcome.variant == 6 && !data.Unlocked(D12_ACHIEVEMENT_HOLY_POOP))
|
|
return {GRID_POOP, 0};
|
|
if (outcome.type == GRID_POOP && outcome.variant == 11 && !data.Unlocked(D12_ACHIEVEMENT_CHARMING_POOP))
|
|
return {GRID_POOP, 0};
|
|
if (outcome.type == GRID_ROCK_GOLD && !data.Unlocked(D12_ACHIEVEMENT_GOLDEN_ROCK)) return {GRID_ROCK, 0};
|
|
if (outcome.type == GRID_ROCK_SS && !data.Unlocked(D12_ACHIEVEMENT_SUPERSTITION_ROCK)) return {GRID_ROCKT, 0};
|
|
if (outcome.type == GRID_TRAPDOOR && isDaily) return {GRID_ROCK, 0};
|
|
return outcome;
|
|
}
|
|
|
|
// Which draw a grid entity rerolls with: hard for standing rocks, locks and spikes, soft for webs, on/off spikes and
|
|
// standing TNT or poop, none for anything else.
|
|
static WeightedOutcomePicker* d12_grid_picker(GridEntity& grid, WeightedOutcomePicker& soft,
|
|
WeightedOutcomePicker& hard)
|
|
{
|
|
switch (grid.type)
|
|
{
|
|
case GRID_ROCK:
|
|
case GRID_ROCKB:
|
|
case GRID_ROCKT:
|
|
case GRID_ROCK_ALT:
|
|
case GRID_LOCK:
|
|
case GRID_ROCK_SS:
|
|
case GRID_PILLAR:
|
|
case GRID_ROCK_SPIKED:
|
|
case GRID_ROCK_GOLD:
|
|
return grid.collisionClass != COLLISION_NONE ? &hard : nullptr;
|
|
case GRID_SPIKES:
|
|
return &hard;
|
|
case GRID_SPIKES_ONOFF:
|
|
case GRID_SPIDERWEB:
|
|
return &soft;
|
|
case GRID_TNT:
|
|
case GRID_POOP:
|
|
return grid.collisionClass != COLLISION_NONE ? &soft : nullptr;
|
|
default:
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
// The D12: every rock, poop, web, TNT, spike and fireplace of the room turns into another at random (rocks and spikes
|
|
// from every outcome, the rest from the soft ones), eternal flies without a host leave, and the room's pickups look
|
|
// again.
|
|
void d12_use(ItemUse& use)
|
|
{
|
|
Entity_Player& player = use.player;
|
|
Room& room = *g_game->room;
|
|
if (player.variant != PLAYER_VARIANT_PLAYER) return;
|
|
|
|
WeightedOutcomePicker soft;
|
|
WeightedOutcomePicker hard;
|
|
for (int i = 0; i < (int)D12_OUTCOMES.size(); i++)
|
|
{
|
|
if (i < D12_SOFT_ROWS) soft.AddOutcomeWeight(i, D12_OUTCOMES[i].weight);
|
|
hard.AddOutcomeWeight(i, D12_OUTCOMES[i].weight);
|
|
}
|
|
std::array<int8_t, ROOM_GRID_CELLS> rolled;
|
|
rolled.fill(-1);
|
|
int cells = room.gridWidth * room.gridHeight;
|
|
RNG rng;
|
|
rng.SetSeed(player.GetCollectibleRNG(COLLECTIBLE_D12).Next(), D12_SHIFT_INDEX);
|
|
auto pick = [&](WeightedOutcomePicker& picker) {
|
|
RNG pickRng;
|
|
pickRng.SetSeed(rng.Next(), D12_PICK_SHIFT_INDEX);
|
|
return (int8_t)picker.PickOutcome(pickRng);
|
|
};
|
|
|
|
for (int i = 0; i < cells; i++)
|
|
{
|
|
GridEntity* grid = room.GetGridEntity(i);
|
|
WeightedOutcomePicker* picker = grid ? d12_grid_picker(*grid, soft, hard) : nullptr;
|
|
if (!picker) continue;
|
|
room.RemoveGridEntityImmediate(i, 0, DECORATION_KEPT);
|
|
rolled[i] = pick(*picker);
|
|
}
|
|
|
|
std::vector<Entity*> entities(room_entities().begin(), room_entities().end());
|
|
for (Entity* entity : entities)
|
|
{
|
|
if (entity->type == ENTITY_ETERNALFLY)
|
|
{
|
|
if (!entity->parent) entity->Remove();
|
|
continue;
|
|
}
|
|
bool isFireplace = entity->type == ENTITY_FIREPLACE && entity->entityCollisionClass != ENTCOLL_NONE;
|
|
bool isTnt = entity->type == ENTITY_MOVABLE_TNT && entity->entityCollisionClass != ENTCOLL_NONE;
|
|
if ((!isFireplace || entity->variant > 3) && !isTnt) continue;
|
|
bool isHard = isFireplace && entity->variant >= 2;
|
|
|
|
int i = room.GetGridIndex(entity->pos);
|
|
if (i < 0 || rolled[i] != -1) continue;
|
|
if (GridEntity* grid = room.GetGridEntity(i))
|
|
{
|
|
if (is_grid_floor_special(grid->type)) continue;
|
|
room.RemoveGridEntityImmediate(i, 0, DECORATION_REMOVED);
|
|
}
|
|
entity->Remove();
|
|
rolled[i] = pick(isHard ? hard : soft);
|
|
}
|
|
|
|
for (int i = 0; i < cells; i++)
|
|
{
|
|
if (rolled[i] == -1) continue;
|
|
D12Outcome outcome = d12_outcome_allowed(D12_OUTCOMES[rolled[i]]);
|
|
Vector position = room.GetGridPosition(i);
|
|
if (outcome.type < 0)
|
|
{
|
|
room.SpawnGridEntity(i, GRID_DECORATION, D12_DECORATION_VARIANT, rng.Next(), 0);
|
|
g_game->Spawn(
|
|
{.position = position, .type = -outcome.type, .variant = outcome.variant, .seed = rng.Next()});
|
|
}
|
|
else
|
|
{
|
|
room.SpawnGridEntity(i, (GridEntityType)outcome.type, outcome.variant, rng.Next(), 0);
|
|
if (outcome.type == GRID_POOP) continue;
|
|
}
|
|
g_game->Spawn({.position = position, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()});
|
|
}
|
|
for (int i = 0; i < cells; i++)
|
|
if (rolled[i] != -1)
|
|
if (GridEntity* grid = room.GetGridEntity(i)) grid->PostInit();
|
|
room.isPickupVisionInvalid = true;
|
|
if (use.isShowAnimation)
|
|
{
|
|
sound_play_local(player, SOUND_D6_ROLL);
|
|
player.AnimateCollectible(use.id, "UseItem", "PlayerPickupSparkle");
|
|
}
|
|
}
|
|
|
|
// 0081fd60 Brings back the enemies of the room's layout (a special miniboss room's override layout), each cell drawn
|
|
// again from its spawn seed and never on a restricted cell. Respawned enemies hold the room shut, and whatever still
|
|
// stood on their cells goes. With nothing back the room counts as cleared, else its doors close (secret doors keep
|
|
// opening as holes). The visit counts again.
|
|
void Room::RespawnEnemies()
|
|
{
|
|
constexpr std::array<uint32_t, 3> RESPAWN_SHIFTS = {2, 7, 7};
|
|
constexpr float RESPAWN_RANDOM_UNIT = 2.3283062e-10f;
|
|
RoomDescriptor& room = *descriptor;
|
|
RNG rng = {room.spawnSeed, RESPAWN_SHIFTS[0], RESPAWN_SHIFTS[1], RESPAWN_SHIFTS[2]};
|
|
log_printf(LOG_INFO, "SpawnRNG seed: %u\n", room.spawnSeed);
|
|
|
|
RoomConfig_Room* layout = room.data;
|
|
if (room.overrideData && room.overrideData->stageId == 0 && room.overrideData->type == ROOM_MINIBOSS)
|
|
layout = room.overrideData;
|
|
room.visitedCount++;
|
|
isFirstVisit = false;
|
|
|
|
std::set<int> respawnedCells;
|
|
std::set<Entity*> respawned;
|
|
std::vector<Entity*> spawned;
|
|
for (RoomSpawn& spawn : layout->spawns)
|
|
{
|
|
uint32_t seed = rng.Next();
|
|
int gridIndex = spawn.x + 1 + (spawn.y + 1) * gridWidth;
|
|
if (spawn.entries.empty()) continue;
|
|
RoomEntry* entry = spawn.PickEntry((float)seed * RESPAWN_RANDOM_UNIT);
|
|
if (room.restrictedGridIndexes.contains(gridIndex)) continue;
|
|
Entity* entity = nullptr;
|
|
if (!room_entry_spawn(*this, *entry,
|
|
{.outEntity = &entity, .gridIndex = gridIndex, .seed = seed, .mode = ENTRY_RESPAWN}) ||
|
|
!entity)
|
|
continue;
|
|
respawnedCells.insert(gridIndex);
|
|
respawned.insert(entity);
|
|
spawned.push_back(entity);
|
|
}
|
|
for (Entity* entity : spawned)
|
|
{
|
|
entity->Update();
|
|
if (entity->CanShutDoors()) room.flags &= ~(ROOM_DESCRIPTOR_FLAG_CLEAR | ROOM_DESCRIPTOR_FLAG_NO_REWARD);
|
|
}
|
|
if (respawnedCells.empty())
|
|
{
|
|
room.flags |= ROOM_DESCRIPTOR_FLAG_CLEAR;
|
|
return;
|
|
}
|
|
|
|
for (Entity* entity : entityList.updateEL)
|
|
if (!respawned.contains(entity) && respawnedCells.contains(entity->spawnGridIndex)) entity->Remove();
|
|
for (GridEntity_Door* door : doors)
|
|
{
|
|
if (!door || door->state == DOOR_STATE_CLOSED) continue;
|
|
door->state = DOOR_STATE_CLOSED;
|
|
door->UpdateAnimation();
|
|
bool isSecret = std::ranges::any_of(std::array{door->currentRoomType, door->targetRoomType}, [](int type) {
|
|
return type == ROOM_SECRET || type == ROOM_SUPERSECRET || type == ROOM_ULTRASECRET;
|
|
});
|
|
if (isSecret) door->openAnimation = "Open";
|
|
}
|
|
}
|
|
|
|
// We Need To Go Deeper and Mom's Shovel: a dirt patch under the player is dug up for a chest (Mom's Shovel only once
|
|
// unlocked, else the patch just empties), else the floor is dug where the player stands, kept seventy units off the
|
|
// doors: a crawlspace in a decoration the first time a floor allows it, a trapdoor elsewhere (a womb hole bleeds,
|
|
// tinted green on the Corpse). Book of Virtues gives Mom's Shovel a broken shovel wisp.
|
|
void deeper_use(ItemUse& use)
|
|
{
|
|
constexpr int PATCH_UNDUG = 0;
|
|
constexpr int PATCH_DUG = 1;
|
|
constexpr int PATCH_EMPTIED = 2;
|
|
constexpr int ACHIEVEMENT_MOMS_SHOVEL_DIGS = 390;
|
|
constexpr std::array<int, 3> DIRT_PATCH_CHESTS = {PICKUP_CHEST, PICKUP_LOCKEDCHEST, PICKUP_REDCHEST};
|
|
constexpr float DIRT_CHEST_SPEED = 4;
|
|
constexpr uint32_t DIRT_PATCH_SHIFT_INDEX = 5;
|
|
constexpr float DOOR_CLEARANCE_SQUARED = 4900;
|
|
constexpr float DIG_STEP = 20;
|
|
constexpr int DIG_TRIES = 20;
|
|
constexpr int CRAWLSPACE_DECORATIONS = 31;
|
|
constexpr int WOMB_HOLE_PREFIX = 25;
|
|
constexpr float WOMB_HOLE_TURN = 90;
|
|
constexpr int BLOOD_EXPLOSION_TRAPDOOR = 3;
|
|
Entity_Player& player = use.player;
|
|
Room& room = *g_game->room;
|
|
RNG& rng = player.GetCollectibleRNG(COLLECTIBLE_WE_NEED_TO_GO_DEEPER);
|
|
bool isDig = true;
|
|
if (player.variant != PLAYER_VARIANT_PLAYER) return use_animate(use);
|
|
|
|
int playerCell = room.GetGridIndex(player.pos);
|
|
for (Entity* entity : entity_query(ENTITY_EFFECT, EFFECT_DIRT_PATCH))
|
|
{
|
|
auto* patch = static_cast<Entity_Effect*>(entity);
|
|
if (patch->state != PATCH_UNDUG || room.GetGridIndex(patch->pos) != playerCell) continue;
|
|
isDig = false;
|
|
if (use.id == COLLECTIBLE_MOMS_SHOVEL && !g_manager->persistentGameData.Unlocked(ACHIEVEMENT_MOMS_SHOVEL_DIGS))
|
|
{
|
|
patch->state = PATCH_EMPTIED;
|
|
continue;
|
|
}
|
|
patch->state = PATCH_DUG;
|
|
RNG chestRng;
|
|
chestRng.SetSeed(patch->initSeed, DIRT_PATCH_SHIFT_INDEX);
|
|
Vector velocity = Entity_Pickup::GetRandomPickupVelocity(patch->pos, &chestRng, 0);
|
|
uint32_t seed = chestRng.Next();
|
|
g_game->Spawn({.position = player.pos,
|
|
.velocity = vector_scale(velocity, DIRT_CHEST_SPEED),
|
|
.type = ENTITY_PICKUP,
|
|
.variant = DIRT_PATCH_CHESTS[chestRng.RandomInt(3)],
|
|
.seed = seed});
|
|
sound_play(SOUND_SHOVEL_DIG2);
|
|
sound_play(SOUND_SHOVEL_HOLE_OPEN);
|
|
}
|
|
if (use.id == COLLECTIBLE_MOMS_SHOVEL && player.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES))
|
|
player.AddWisp(COLLECTIBLE_BROKEN_SHOVEL_1, player.pos, false, false);
|
|
if (!isDig || room.roomType == ROOM_DUNGEON) return use_animate(use);
|
|
|
|
Vector digPos = player.pos;
|
|
for (GridEntity_Door* door : room.doors)
|
|
{
|
|
if (!door || vector_length_squared(vector_sub(door->Position(), digPos)) >= DOOR_CLEARANCE_SQUARED) continue;
|
|
for (int tries = DIG_TRIES;
|
|
tries > 0 && vector_length_squared(vector_sub(door->Position(), digPos)) < DOOR_CLEARANCE_SQUARED; tries--)
|
|
digPos = room_free_pickup_position_find({.position = digPos, .step = DIG_STEP});
|
|
break;
|
|
}
|
|
int cell = room.GetGridIndex(digPos);
|
|
GridEntity* grid = room.GetGridEntity(cell);
|
|
if (grid && (grid->type == GRID_TRAPDOOR || grid->type == GRID_STAIRS)) return use_animate(use);
|
|
|
|
bool isCrawlspace = grid && grid->type == GRID_DECORATION && grid->variant < CRAWLSPACE_DECORATIONS &&
|
|
!g_game->Level::GetStateFlag(LEVEL_STATE_DUNGEON_ROCK_BROKEN);
|
|
room_grid_destroy({.source = EntityRef(&player), .gridIndex = cell});
|
|
if (isCrawlspace)
|
|
{
|
|
room.SpawnGridEntity(cell, GRID_STAIRS, 0, rng.Next(), 0);
|
|
g_game->Level::SetStateFlag(LEVEL_STATE_DUNGEON_ROCK_BROKEN, true);
|
|
return use_animate(use);
|
|
}
|
|
if (!g_game->CanSpawnTrapDoor()) return use_animate(use);
|
|
room.SpawnGridEntity(cell, GRID_TRAPDOOR, 0, rng.Next(), 0);
|
|
GridEntity* trapdoor = room.GetGridEntity(cell);
|
|
if (!trapdoor || trapdoor->type != GRID_TRAPDOOR) return use_animate(use);
|
|
|
|
bool isWombHole =
|
|
trapdoor->sprite.filename.size() >= WOMB_HOLE_PREFIX &&
|
|
std::equal(trapdoor->sprite.filename.begin(), trapdoor->sprite.filename.begin() + WOMB_HOLE_PREFIX,
|
|
"gfx/grid/door_11_wombhole", [](char a, char b) { return std::tolower(a) == std::tolower(b); });
|
|
if (!isWombHole)
|
|
{
|
|
sound_play(SOUND_SHOVEL_DIG2);
|
|
return use_animate(use);
|
|
}
|
|
|
|
Entity* blood = g_game->Spawn({.position = trapdoor->Position(),
|
|
.subType = BLOOD_EXPLOSION_TRAPDOOR,
|
|
.type = ENTITY_EFFECT,
|
|
.variant = EFFECT_BLOOD_EXPLOSION,
|
|
.seed = Random()});
|
|
blood->subtype = 0;
|
|
blood->sprite.rotation = (float)random_below(4) * WOMB_HOLE_TURN;
|
|
if (g_game->IsMausoleumHeartStage() || (g_game->stage == STAGE_WOMB_I && g_game->IsAltPath()))
|
|
blood->SetColor(COLOR_GREEN_SPLAT, -1, COLOR_PRIORITY_DEFAULT, false, true);
|
|
blood->Update();
|
|
sound_play(SOUND_MEAT_JUMPS);
|
|
use_animate(use);
|
|
}
|
|
|
|
// 00820910 Mama Mega's blast in the room, marked as done: at a spot, or (entering a room the blast reaches) two hundred
|
|
// units past the first player away from the room's center.
|
|
void Room::MamaMegaExplosion(Vector position, Entity_Player* player)
|
|
{
|
|
constexpr float MAMA_MEGA_ENTRY_REACH = 200;
|
|
descriptor->flags |= ROOM_DESCRIPTOR_FLAG_MAMA_MEGA;
|
|
uint32_t seed = Random();
|
|
Entity_Player* first = g_game->playerManager.playerList[0];
|
|
if (!player) player = first;
|
|
auto* blast = static_cast<Entity_Effect*>(g_game->Spawn({.position = position,
|
|
.spawner = player,
|
|
.type = ENTITY_EFFECT,
|
|
.variant = EFFECT_MAMA_MEGA_EXPLOSION,
|
|
.seed = seed}));
|
|
if (vector_is_zero(position))
|
|
{
|
|
Vector center = vector_add(topLeftPos, vector_scale(vector_sub(bottomRightPos, topLeftPos), 0.5f));
|
|
Vector away = vector_sub(first->pos, center);
|
|
float distance = vector_length(away);
|
|
if (distance > 0) away = vector_scale(away, MAMA_MEGA_ENTRY_REACH / distance);
|
|
position = vector_add(first->pos, away);
|
|
}
|
|
blast->targetPosition = position;
|
|
blast->Update();
|
|
}
|