359 lines
16 KiB
C++
359 lines
16 KiB
C++
#include "grid_entity_trap_door.h"
|
|
#include "boss_pool.h"
|
|
#include "entity_effect.h"
|
|
#include "entity_familiar.h"
|
|
#include "entity_list.h"
|
|
#include "entity_player.h"
|
|
#include "game.h"
|
|
#include "level.h"
|
|
#include "log.h"
|
|
#include "manager.h"
|
|
#include "npc_ai.h"
|
|
#include "room.h"
|
|
#include "room_render.h"
|
|
#include "seeds.h"
|
|
#include "stage_transition.h"
|
|
#include <cmath>
|
|
#include <strings.h>
|
|
|
|
constexpr const char* TRAPDOOR_ANM2 = "gfx/grid/Door_11_TrapDoor.anm2";
|
|
constexpr const char* VOID_ANM2 = "gfx/grid/VoidTrapdoor.anm2";
|
|
constexpr const char* DOWNPOUR_ANM2 = "gfx/grid/trapdoor_downpour.anm2";
|
|
constexpr const char* MINES_ANM2 = "gfx/grid/trapdoor_mines.anm2";
|
|
constexpr const char* MAUSOLEUM_ANM2 = "gfx/grid/trapdoor_mausoleum.anm2";
|
|
constexpr const char* CORPSE_BIG_ANM2 = "gfx/grid/trapdoor_corpse_big.anm2";
|
|
constexpr const char* WOMBHOLE_ANM2 = "gfx/grid/Door_11_Wombhole.anm2";
|
|
constexpr const char* WOMBHOLE_BLUE_PNG = "gfx/grid/door_11_wombhole_blue.png";
|
|
constexpr const char* CORPSEHOLE_PNG = "gfx/grid/door_11_corpsehole.png";
|
|
constexpr std::string_view TRAPDOOR_SHEET_PREFIX = "gfx/grid/Door_11_TrapDoor";
|
|
|
|
constexpr std::string_view ANIM_CLOSED = "Closed";
|
|
constexpr std::string_view ANIM_OPENING = "Open Animation";
|
|
constexpr std::string_view ANIM_OPENED = "Opened";
|
|
constexpr std::string_view ANIM_PLAYER_FALL = "Trapdoor";
|
|
|
|
// The stages (with a labyrinth counted as the next) whose exits are holes in the floor or the Void's portal.
|
|
constexpr int STAGE_LAST_CHAPTER = 10;
|
|
|
|
constexpr int GAME_STATE_BACKWARDS_PATH_INIT = 47;
|
|
|
|
// Mother's boss room in the special rooms.
|
|
constexpr int MINES_LAYER_HIDDEN = 1;
|
|
|
|
constexpr float PLAYER_FAR = 1e9f;
|
|
constexpr float PLAYER_CLEARANCE = 50;
|
|
constexpr float REACH = 21;
|
|
constexpr float MOTHER_HOLE_REACH = 34;
|
|
constexpr float FORGOTTEN_BODY_RADIUS = 20;
|
|
|
|
constexpr int VOID_SHOCKWAVE_FRAMES = 15;
|
|
constexpr float VOID_SHOCKWAVE_AMPLITUDE = 0.05f;
|
|
constexpr float MEGA_SATAN_SHOCKWAVE_AMPLITUDE = 0.03f;
|
|
constexpr float CLOSED_SHOCKWAVE_SCALE = 0.2f;
|
|
constexpr float SHOCKWAVE_SPEED = 0.013f;
|
|
constexpr int VOID_SHOCKWAVE_DURATION = 13;
|
|
constexpr int MEGA_SATAN_SHOCKWAVE_DURATION = 6;
|
|
|
|
static bool room_is_cleared(Room& room)
|
|
{
|
|
return room.descriptor->flags & ROOM_DESCRIPTOR_FLAG_CLEAR;
|
|
}
|
|
|
|
// The labyrinth's stage, counted as the next one but in Greed.
|
|
static int labyrinth_stage_get(bool isGreedIgnored)
|
|
{
|
|
Game& game = *g_game;
|
|
bool isLabyrinth = game.filter_curses(CURSE_OF_LABYRINTH);
|
|
bool isGreed = game.difficulty == DIFFICULTY_GREED || game.difficulty == DIFFICULTY_GREEDIER;
|
|
return (int)game.stage + (isLabyrinth && !(isGreedIgnored && isGreed) ? 1 : 0);
|
|
}
|
|
|
|
// 0071f630 Loads the trapdoor for where it leads: the Void's portal, the secret exits' holes, Mother's big hole, the
|
|
// womb holes (blue to the Blue Womb, the corpse's on the alternate path) or the plain trapdoor, closed.
|
|
void GridEntity_TrapDoor::subclass_init()
|
|
{
|
|
Game& game = *g_game;
|
|
Room& room = *game.room;
|
|
int stage = labyrinth_stage_get(true);
|
|
bool isGreed = game.difficulty == DIFFICULTY_GREED || game.difficulty == DIFFICULTY_GREEDIER;
|
|
RoomConfig_Room* config = room.descriptor->data;
|
|
|
|
if ((stage == STAGE_BLUE_WOMB && game.currentRoomIdx == ROOM_THE_VOID_IDX) || varData == TRAPDOOR_VOID_PORTAL)
|
|
{
|
|
sprite.Load(VOID_ANM2, GRAPHICS_LOAD);
|
|
variant = 1;
|
|
}
|
|
else if (room.roomType == ROOM_SECRET_EXIT)
|
|
{
|
|
int exit = config ? config->subtype : 0;
|
|
if (exit == SECRET_EXIT_DOWNPOUR) sprite.Load(DOWNPOUR_ANM2, GRAPHICS_LOAD);
|
|
else if (exit == SECRET_EXIT_MINES)
|
|
{
|
|
sprite.Load(MINES_ANM2, GRAPHICS_LOAD);
|
|
if (sprite.layerStates.size() > MINES_LAYER_HIDDEN) sprite.GetLayer(MINES_LAYER_HIDDEN)->isVisible = false;
|
|
sprite.Play(ANIM_CLOSED);
|
|
auto* cover = static_cast<Entity_Effect*>(g_game->Spawn({.position = Position(),
|
|
.type = ENTITY_EFFECT,
|
|
.variant = EFFECT_MINES_TRAPDOOR_COVER,
|
|
.seed = Random()}));
|
|
cover->state = gridIndex;
|
|
cover->Update();
|
|
}
|
|
else sprite.Load(exit == SECRET_EXIT_MAUSOLEUM ? MAUSOLEUM_ANM2 : TRAPDOOR_ANM2, GRAPHICS_LOAD);
|
|
}
|
|
else if (room.roomType == ROOM_BOSS && config->stageId == STAGE_ID_SPECIAL_ROOMS && config->subtype == BOSS_MOTHER)
|
|
sprite.Load(CORPSE_BIG_ANM2, GRAPHICS_LOAD);
|
|
else if (((stage == STAGE_DEPTHS_II || stage == STAGE_WOMB_I) && !isGreed) || (stage == STAGE_CAVES_I && isGreed) ||
|
|
game.currentRoomIdx == ROOM_BLUE_WOMB_IDX)
|
|
{
|
|
sprite.Load(WOMBHOLE_ANM2, GRAPHICS_DEFER);
|
|
bool isCorpse =
|
|
game.IsMausoleumHeartStage() || (stage == STAGE_WOMB_I && game.IsAltPath()) ||
|
|
((stage == STAGE_DEPTHS_II || (stage == STAGE_DEPTHS_I && game.filter_curses(CURSE_OF_LABYRINTH))) &&
|
|
game.GetChallengeParams().pathType == PATH_TYPE_REPENTANCE);
|
|
if (game.currentRoomIdx == ROOM_BLUE_WOMB_IDX) sprite.ReplaceSpritesheet(0, WOMBHOLE_BLUE_PNG);
|
|
else if (isCorpse) sprite.ReplaceSpritesheet(0, CORPSEHOLE_PNG);
|
|
sprite.LoadGraphics();
|
|
}
|
|
else sprite.Load(TRAPDOOR_ANM2, GRAPHICS_LOAD);
|
|
|
|
state = 0;
|
|
sprite.Play(ANIM_CLOSED);
|
|
}
|
|
|
|
// Whether The Forgotten's body lies on the trapdoor (EntityList::QueryRadius over the familiars).
|
|
bool is_forgotten_body_on(const Vector& position)
|
|
{
|
|
EntityList& list = g_game->room->entityList;
|
|
EntityList_EL found;
|
|
|
|
list.partitions[PARTITION_FAMILIARS].query_box(found, position,
|
|
vector_make(FORGOTTEN_BODY_RADIUS, FORGOTTEN_BODY_RADIUS));
|
|
for (Entity* entity : found)
|
|
{
|
|
float reach = FORGOTTEN_BODY_RADIUS + entity->size;
|
|
bool isNear = vector_length_squared(vector_sub(entity->pos, position)) < reach * reach;
|
|
if (isNear && !entity->HasEntityFlags(FLAG_NO_QUERY) && entity->type == ENTITY_FAMILIAR &&
|
|
entity->variant == Entity_Familiar::FORGOTTEN_BODY)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Whether Mother's room holds the hole to the Corpse's last floor.
|
|
static bool is_mother_hole(GridEntity_TrapDoor& trapDoor)
|
|
{
|
|
Room& room = *g_game->room;
|
|
RoomConfig_Room* config = room.descriptor->data;
|
|
return room.roomType == ROOM_BOSS && config->stageId == STAGE_ID_SPECIAL_ROOMS && config->subtype == BOSS_MOTHER &&
|
|
trapDoor.varData != TRAPDOOR_VOID_PORTAL;
|
|
}
|
|
|
|
// Whether the alternate path's knife pieces are missing: the first on Downpour or Dross II, the second on Mines or
|
|
// Ashpit II.
|
|
static bool is_knife_piece_missing()
|
|
{
|
|
Game& game = *g_game;
|
|
bool isLabyrinth = game.filter_curses(CURSE_OF_LABYRINTH);
|
|
int stage = (int)game.stage;
|
|
bool isFirstPieceFloor = game.IsAltPath() && (stage == 2 || (stage == 1 && isLabyrinth));
|
|
bool isSecondPieceFloor = game.IsAltPath() && (stage == 4 || (stage == 3 && isLabyrinth));
|
|
PlayerManager& players = game.playerManager;
|
|
|
|
if (isFirstPieceFloor && !players.FirstCollectibleOwner(COLLECTIBLE_KNIFE_PIECE_1, LAZARUS_SHARE_CHECK))
|
|
return true;
|
|
return isSecondPieceFloor && !players.FirstCollectibleOwner(COLLECTIBLE_KNIFE_PIECE_2, LAZARUS_SHARE_CHECK);
|
|
}
|
|
|
|
// Whether something keeps an unopened trapdoor shut: Broken Shovel's floor before Mom's Shovel is dug up, an uncleared
|
|
// secret exit, the Ascent, or on Repentance's path a missing knife piece at a secret exit and the Depths' exit on the
|
|
// alternate path.
|
|
static bool is_held_shut()
|
|
{
|
|
Game& game = *g_game;
|
|
Room& room = *game.room;
|
|
bool isGreed = game.difficulty == DIFFICULTY_GREED || game.difficulty == DIFFICULTY_GREEDIER;
|
|
int stage = labyrinth_stage_get(false);
|
|
|
|
if (!isGreed && game.playerManager.FirstCollectibleOwner(COLLECTIBLE_BROKEN_SHOVEL_1, LAZARUS_SHARE_CHECK) &&
|
|
room.roomType != ROOM_ERROR && stage == STAGE_DEPTHS_II &&
|
|
!(game.GetRoomByIdx(ROOM_BOSSRUSH_IDX)->flags & ROOM_DESCRIPTOR_FLAG_CHALLENGE_DONE))
|
|
return true;
|
|
if (room.roomType == ROOM_SECRET_EXIT && !room_is_cleared(room)) return true;
|
|
if (game.IsAscent()) return true;
|
|
if (game.GetChallengeParams().pathType != PATH_TYPE_REPENTANCE) return false;
|
|
|
|
bool isAlt = game.IsAltPath();
|
|
if (room.roomType == ROOM_SECRET_EXIT)
|
|
{
|
|
bool isLabyrinth = game.filter_curses(CURSE_OF_LABYRINTH);
|
|
bool isFirstPieceFloor = stage == 2 || (isLabyrinth && stage == 1);
|
|
bool isSecondPieceFloor = stage == 4 || (isLabyrinth && stage == 3);
|
|
PlayerManager& players = game.playerManager;
|
|
if (isFirstPieceFloor && isAlt &&
|
|
!players.FirstCollectibleOwner(COLLECTIBLE_KNIFE_PIECE_1, LAZARUS_SHARE_CHECK))
|
|
return true;
|
|
return isSecondPieceFloor && isAlt &&
|
|
!players.FirstCollectibleOwner(COLLECTIBLE_KNIFE_PIECE_2, LAZARUS_SHARE_CHECK);
|
|
}
|
|
bool isDepthsExit = stage == STAGE_DEPTHS_II || (game.filter_curses(CURSE_OF_LABYRINTH) && stage == STAGE_DEPTHS_I);
|
|
return isDepthsExit && isAlt && !game.IsMausoleumHeartStage() && room.roomType != ROOM_ISAACS &&
|
|
room.roomType != ROOM_ERROR;
|
|
}
|
|
|
|
// Opens an unopened trapdoor (not in Backasswards), its plain sprite scraping as it starts, and marks it open once the
|
|
// animation ends.
|
|
static void trapdoor_open_update(GridEntity_TrapDoor& trapDoor)
|
|
{
|
|
ANM2& sprite = trapDoor.sprite;
|
|
if (g_game->challenge == CHALLENGE_BACKASSWARDS) return;
|
|
|
|
if (!sprite.animState.animData || sprite.animState.animData->name != ANIM_OPENING)
|
|
sprite.Play(ANIM_OPENING, PLAY_FORCED);
|
|
bool isPlainSheet =
|
|
strncasecmp(sprite.filename.c_str(), TRAPDOOR_SHEET_PREFIX.data(), TRAPDOOR_SHEET_PREFIX.size()) == 0;
|
|
if (sprite.IsPlaying(ANIM_OPENING) && (int)std::floor(sprite.animState.animFrame) == 1 && isPlainSheet)
|
|
grid_sound_play(SOUND_SHOVEL_HOLE_OPEN);
|
|
if (!sprite.animState.animData || !sprite.animState.isPlaying) trapDoor.state = 1;
|
|
}
|
|
|
|
// Every main player drops into the hole: the trapdoor animation, aimed at its center.
|
|
static void players_fall(const Vector& position)
|
|
{
|
|
for (Entity_Player* player : g_game->playerManager.playerList)
|
|
{
|
|
if (player->variant != 0) continue;
|
|
player->PlayExtraAnimation(ANIM_PLAYER_FALL);
|
|
player->moveToTarget = position;
|
|
}
|
|
}
|
|
|
|
// Where an open trapdoor takes the player who falls in: Mother's hole to the Corpse's secret exit, the Lil Portal
|
|
// room's back, the knife's start room when a piece is missing on Repentance's path, else the next floor (the same one
|
|
// again in the endless basement, the Void through its portal). A secret exit or the Mausoleum's heart floor marks the
|
|
// secret path, and the Ascent's with the photo door.
|
|
static void trapdoor_enter(GridEntity_TrapDoor& trapDoor, Entity_Player& player, const Vector& position)
|
|
{
|
|
Game& game = *g_game;
|
|
|
|
if (is_mother_hole(trapDoor))
|
|
{
|
|
grid_sound_play(SOUND_TRAP_DOOR_LEVEL);
|
|
game.leaveDoor = -1;
|
|
game.StartRoomTransition({.player = &player,
|
|
.animation = TRANSITION_TRAPDOOR,
|
|
.direction = DIRECTION_NONE,
|
|
.roomIndex = ROOM_SECRET_EXIT_IDX});
|
|
return players_fall(position);
|
|
}
|
|
|
|
if (game.currentRoomIdx == ROOM_LIL_PORTAL_IDX)
|
|
game.StartRoomTransition({.player = &player,
|
|
.animation = TRANSITION_PIXELATION,
|
|
.direction = DIRECTION_NONE,
|
|
.roomIndex = ROOM_ERROR_IDX});
|
|
else
|
|
{
|
|
grid_sound_play(SOUND_TRAP_DOOR_LEVEL);
|
|
if (game.room->roomType == ROOM_SECRET_EXIT || game.IsMausoleumHeartStage())
|
|
{
|
|
game.gameStateFlags |= 1ull << GAME_STATE_SECRET_PATH;
|
|
if (game.HasPhotoDoor()) game.gameStateFlags |= 1ull << GAME_STATE_BACKWARDS_PATH_INIT;
|
|
}
|
|
|
|
bool isRepentancePath =
|
|
game.GetChallengeParams().pathType == PATH_TYPE_REPENTANCE && game.challenge != CHALLENGE_RED_REDEMPTION;
|
|
if (game.seedEffects.HasSeedEffect(SEED_INFINITE_BASEMENT))
|
|
game.stageTransition.start({.type = STAGE_TRANSITION_NEXT, .isSameStage = true});
|
|
else
|
|
{
|
|
if ((int)game.stage > STAGE_LAST_CHAPTER)
|
|
game.seedEffects.ForgetStageSeed(game.stage_depth_get());
|
|
if (trapDoor.varData == TRAPDOOR_VOID_PORTAL) game.stageTransition.start({.type = STAGE_TRANSITION_VOID});
|
|
else if (!isRepentancePath || !is_knife_piece_missing())
|
|
game.stageTransition.start({.type = STAGE_TRANSITION_NEXT});
|
|
else
|
|
{
|
|
game.StartRoomTransition({.player = &player,
|
|
.animation = TRANSITION_TRAPDOOR,
|
|
.direction = DIRECTION_NONE,
|
|
.dimension = 0,
|
|
.roomIndex = game.startingRoomIdx});
|
|
players_fall(position);
|
|
}
|
|
}
|
|
}
|
|
player.PlayExtraAnimation(ANIM_PLAYER_FALL);
|
|
player.moveToTarget = position;
|
|
}
|
|
|
|
// 00703770 Game::MakeShockwave: starts the next of the room's two ripples at a position.
|
|
void shockwave_make(const Vector& position, float amplitude, float speed, int duration)
|
|
{
|
|
Room& room = *g_game->room;
|
|
Shockwave& wave = roomShockwaves[++room.unknown70fc % SHOCKWAVE_COUNT];
|
|
|
|
wave = {.position = position, .amplitude = amplitude, .speed = speed, .duration = duration};
|
|
}
|
|
|
|
// The Void's portal (and the Blue Womb's way to it) ripples the room every 15 frames, faintly while shut.
|
|
static void void_portal_ripple(GridEntity_TrapDoor& trapDoor)
|
|
{
|
|
Game& game = *g_game;
|
|
Room& room = *game.room;
|
|
bool isVoidRoom = game.stage == STAGE_BLUE_WOMB && game.currentRoomIdx == ROOM_THE_VOID_IDX;
|
|
|
|
if (!room.isInitialized || (game.frameCount - room.enterFrame) % VOID_SHOCKWAVE_FRAMES != 0) return;
|
|
if (!isVoidRoom && trapDoor.varData != TRAPDOOR_VOID_PORTAL) return;
|
|
|
|
bool isMegaSatan = game.currentRoomIdx == ROOM_MEGA_SATAN_IDX;
|
|
float amplitude = isMegaSatan ? MEGA_SATAN_SHOCKWAVE_AMPLITUDE : VOID_SHOCKWAVE_AMPLITUDE;
|
|
if (trapDoor.state != 1) amplitude *= CLOSED_SHOCKWAVE_SCALE;
|
|
shockwave_make(trapDoor.Position(), amplitude, SHOCKWAVE_SPEED,
|
|
isMegaSatan ? MEGA_SATAN_SHOCKWAVE_DURATION : VOID_SHOCKWAVE_DURATION);
|
|
}
|
|
|
|
// 0071fef0 Stays shut while the nearest player stands within 50 of it (or something else holds it shut), opens once
|
|
// they step off, and takes the nearest player who walks onto the open hole. Greed shuts it again in an uncleared wave.
|
|
// The original also opened it for a netplay boss room's late joiners, which the offline game never has.
|
|
void GridEntity_TrapDoor::Update()
|
|
{
|
|
Game& game = *g_game;
|
|
Room& room = *game.room;
|
|
Vector position = Position();
|
|
Entity_Player* player = main_player_nearest(position);
|
|
float distance = player ? vector_length(vector_sub(position, player->pos)) : PLAYER_FAR;
|
|
float reach = is_mother_hole(*this) ? MOTHER_HOLE_REACH : REACH;
|
|
bool isShut = (player && distance < PLAYER_CLEARANCE) || is_forgotten_body_on(position) || is_held_shut();
|
|
bool isGreed = game.difficulty == DIFFICULTY_GREED || game.difficulty == DIFFICULTY_GREEDIER;
|
|
|
|
frameCount++;
|
|
if (isShut && state == 0) sprite.Play(ANIM_CLOSED);
|
|
else if (state != 1) trapdoor_open_update(*this);
|
|
|
|
if (isGreed && !room_is_cleared(room) && spawnFrame <= room.enterFrame)
|
|
{
|
|
sprite.Play(ANIM_CLOSED);
|
|
state = 0;
|
|
}
|
|
if (state == 1)
|
|
{
|
|
if (!game.IsMausoleumHeartStage() || varData != 0) sprite.Play(ANIM_OPENED);
|
|
else sprite.SetFrame(ANIM_OPENED, 0);
|
|
}
|
|
|
|
bool isBusy = player && (player->isPlayingExtraAnimation || player->isPlayingItemAnimation);
|
|
bool isHoldingTwin = player && player->heldEntity && player->heldEntity == player->twinPlayer.get();
|
|
if (player && distance < reach && state == 1 && (!isBusy || isHoldingTwin))
|
|
trapdoor_enter(*this, *player, position);
|
|
|
|
void_portal_ripple(*this);
|
|
sprite.Update();
|
|
}
|
|
|
|
// 00714750 Water lies flat over the trapdoor.
|
|
WaterClipInfo GridEntity_TrapDoor::GetWaterClipInfo()
|
|
{
|
|
return {WATER_CLIP_FLAT, 0};
|
|
}
|