Seven agents took over tear and contact collision, NPC death with blood and gibs, champions, PathFinder, the Gaper's kin, the player's death with the game over screen, item pedestals with collectible pickup, AddCollectible and EvaluateItems, room state save and restore, GameState::read, pressure plates, fireplaces, entity lights, ambient sounds, and one Lua callback enum with gated runners. Integration reconstructed Room::Update's loot preview and Entity_NPC::UpdatePickupGhosts and replaced a leftover Sacred Orb stub that stopped every pedestal roll. Under gdb: Gapers die with blood and gibs, a cleared room opens its doors, the treasure room's item is taken (banner, costume, stats: a Magic Mushroom gives damage 3.5 -> 6.12 and a heart), death leads to the game over diary, and a saved run is read back on the next boot with Continue offered. 3028 functions taken over. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3346 lines
142 KiB
C++
3346 lines
142 KiB
C++
#include "room.h"
|
|
#include "entity_pickup.h"
|
|
#include "entity_player.h"
|
|
#include "entity_effect.h"
|
|
#include "entity_factory.h"
|
|
#include "entity_npc.h"
|
|
#include "game.h"
|
|
#include "grid_entity_door.h"
|
|
#include "log.h"
|
|
#include "lua_engine.h"
|
|
#include "manager.h"
|
|
#include "room_render.h"
|
|
#include "seeds.h"
|
|
#include "texture_cache.h"
|
|
#include <algorithm>
|
|
#include <climits>
|
|
|
|
extern "C"
|
|
{
|
|
#include "lua.h"
|
|
}
|
|
|
|
// REPENTOGON's LRoomTileDesc table at 00c35b80, by shape.
|
|
constexpr LRoomTileDesc SHAPE_TILES[ROOMSHAPE_ANY] = {
|
|
{1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 13, 7, 1, 1, 13, 7}, {1, 3, 13, 5, 1, 3, 13, 5},
|
|
{5, 1, 9, 7, 5, 1, 9, 7}, {1, 1, 13, 14, 1, 1, 13, 14}, {5, 1, 9, 14, 5, 1, 9, 14},
|
|
{1, 1, 26, 7, 1, 1, 26, 7}, {1, 3, 26, 5, 1, 3, 26, 5}, {1, 1, 26, 14, 1, 1, 26, 14},
|
|
{14, 1, 26, 7, 1, 8, 26, 14}, {1, 1, 13, 7, 1, 8, 26, 14}, {1, 1, 26, 7, 14, 8, 26, 14},
|
|
{1, 1, 26, 7, 1, 8, 13, 14}};
|
|
|
|
// 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.
|
|
constexpr int DOOR_ROWS[2] = {4, 11};
|
|
constexpr int DOOR_COLUMNS[2] = {7, 20};
|
|
constexpr int NARROW_ROW_INSET = 3;
|
|
constexpr int NARROW_COLUMN_INSET = 4;
|
|
|
|
struct DoorCell
|
|
{
|
|
int slot;
|
|
int row;
|
|
int column;
|
|
};
|
|
|
|
constexpr DoorCell L_CORNER_DOORS[ROOMSHAPE_ANY - ROOMSHAPE_LTL][2] = {
|
|
{{DOOR_LEFT0, 4, 13}, {DOOR_UP0, 7, 7}},
|
|
{{DOOR_RIGHT0, 4, 14}, {DOOR_UP1, 7, 20}},
|
|
{{DOOR_DOWN0, 8, 7}, {DOOR_LEFT1, 11, 13}},
|
|
{{DOOR_RIGHT1, 11, 14}, {DOOR_DOWN1, 8, 20}}};
|
|
|
|
// The direction a 970.1 water current spawn sets, by its subtype.
|
|
constexpr int WATER_CURRENT_COUNT = 4;
|
|
constexpr float WATER_CURRENTS[WATER_CURRENT_COUNT][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
|
|
|
|
// The light sprites' layer blending: premultiplied alpha.
|
|
constexpr std::array<int, BLEND_PART_COUNT> LIGHT_BLEND = {BLEND_EQUATION_ADD, BLEND_FACTOR_ONE,
|
|
BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, BLEND_FACTOR_ONE,
|
|
BLEND_FACTOR_ONE_MINUS_SRC_ALPHA};
|
|
constexpr unsigned int FILTER_LINEAR = 1;
|
|
|
|
// The Ascent's golden floors and walls, and the pre-items seed's grey Flooded Caves.
|
|
constexpr ColorMod ASCENT_COLOR = {{1, 1, 1, 1}, {1.2f, 1.2f, 1.2f, 0.6f}, {0.0764f, -0.0216f, -0.0884f}};
|
|
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_TINY_BUG = 21;
|
|
constexpr int EFFECT_TINY_FLY = 33;
|
|
constexpr int EFFECT_HEAVEN_LIGHT_DOOR = 39;
|
|
constexpr int EFFECT_WORM = 63;
|
|
constexpr int EFFECT_BEETLE = 64;
|
|
constexpr int EFFECT_WISP = 65;
|
|
constexpr int EFFECT_WALL_BUG = 68;
|
|
constexpr int EFFECT_ISAACS_CARPET = 74;
|
|
constexpr int EFFECT_DICE_FLOOR = 76;
|
|
constexpr int EFFECT_WOMB_TELEPORT = 82;
|
|
constexpr int EFFECT_FALLING_EMBER = 87;
|
|
constexpr int EFFECT_BROKEN_SHOVEL_SHADOW = 115;
|
|
constexpr int EFFECT_TADPOLE = 158;
|
|
constexpr int EFFECT_LIL_GHOST = 159;
|
|
|
|
// The room layout spawns Init reads before spawning anything (entities2.xml types 825 to 970).
|
|
constexpr int SPAWN_WATER = 825;
|
|
constexpr int SPAWN_DRY = 829;
|
|
constexpr int SPAWN_DUMP = 876;
|
|
constexpr int SPAWN_ALT_BACKDROP = 882;
|
|
constexpr int SPAWN_HERETIC = 905;
|
|
constexpr int SPAWN_WATER_ALT = 907;
|
|
constexpr int SPAWN_DUMP_ALT = 918;
|
|
constexpr int SPAWN_RAGLICH = 919;
|
|
constexpr int SPAWN_ROOM_CONFIG = 970;
|
|
constexpr int ROOM_CONFIG_PITCH_BLACK = 0;
|
|
constexpr int ROOM_CONFIG_WATER = 1;
|
|
constexpr int ROOM_CONFIG_CURSED_MIST = 3;
|
|
constexpr int ROOM_CONFIG_VERSUS_SPAWN = 4;
|
|
constexpr int WATER_SUBTYPE_DRY = 20;
|
|
constexpr int WATER_SUBTYPE_FLOODED = 11;
|
|
constexpr int WATER_SUBTYPE_DUMP = 10;
|
|
|
|
// The grid path values: what an entity walking has left, and what blocks spawning.
|
|
constexpr int GRID_PATH_RESET = 900;
|
|
constexpr int GRID_PATH_UNIT = 1000;
|
|
constexpr int GRID_PATH_PIT = 3000;
|
|
constexpr int GRID_PATH_PIT_LAST = 3999;
|
|
|
|
// Lua's GridCollisionClass values GetGridCollision returns.
|
|
constexpr uint32_t GRID_COLLISION_NONE = 0;
|
|
constexpr uint32_t GRID_COLLISION_PIT = 1;
|
|
constexpr uint32_t GRID_COLLISION_SOLID = 3;
|
|
constexpr uint32_t GRID_COLLISION_WALL = 4;
|
|
|
|
// The stages, stage ids, backdrops and bosses Init and PlayMusic tell apart.
|
|
constexpr int STAGE_HOME = 13;
|
|
|
|
// A crawlspace's subtypes: Rotgut's two phases and the Beast's arena.
|
|
constexpr int DUNGEON_GIDEON = 1;
|
|
constexpr int DUNGEON_ROTGUT = 2;
|
|
constexpr int DUNGEON_ROTGUT_HEART = 3;
|
|
constexpr int DUNGEON_BEAST = 4;
|
|
constexpr int STAGE_ID_BLUE_WOMB = 13;
|
|
constexpr int STAGE_BLUE_WOMB = 9;
|
|
constexpr int STAGE_ID_DOWNPOUR = 27;
|
|
constexpr int STAGE_ID_DROSS = 28;
|
|
constexpr int STAGE_ID_ASHPIT = 30;
|
|
constexpr int STAGE_ID_HOME = 35;
|
|
constexpr int BACKDROP_FLOODED_CAVES = 6;
|
|
constexpr int BACKDROP_SCARRED_WOMB = 12;
|
|
constexpr int BACKDROP_DARK_ROOM = 16;
|
|
constexpr int BACKDROP_MEGA_SATAN = 18;
|
|
constexpr int BACKDROP_MINES = 32;
|
|
constexpr int BACKDROP_CORPSE = 34;
|
|
constexpr int BACKDROP_PLANETARIUM = 35;
|
|
constexpr int BACKDROP_CORPSE3 = 44;
|
|
constexpr int BACKDROP_ASHPIT = 46;
|
|
constexpr int BACKDROP_CLOSET_B = 53;
|
|
constexpr int BACKDROP_MINES_SHAFT = 58;
|
|
constexpr int BACKDROP_ASHPIT_SHAFT = 59;
|
|
constexpr int BOSS_MOM = 6;
|
|
constexpr int BOSS_ISAAC = 39;
|
|
constexpr int BOSS_SATAN = 24;
|
|
constexpr int BOSS_MEGA_SATAN = 55;
|
|
constexpr int BOSS_ULTRA_GREED = 62;
|
|
constexpr int BOSS_ROTGUT = 87;
|
|
constexpr int BOSS_MOM_MAUSOLEUM = 89;
|
|
|
|
// The backdrops LoadBackdropGraphics picks beyond the stage's own (backdrops.xml ids), and what picks them: rooms off
|
|
// the map, Home's rooms by subtype, the bosses and stages with their own, and the Void's random ones.
|
|
constexpr int BACKDROP_UTERO = 11;
|
|
constexpr int BACKDROP_BLUE_WOMB = 13;
|
|
constexpr int BACKDROP_SHEOL = 14;
|
|
constexpr int BACKDROP_CATHEDRAL = 15;
|
|
constexpr int BACKDROP_CHEST = 17;
|
|
constexpr int BACKDROP_LIBRARY = 19;
|
|
constexpr int BACKDROP_SHOP = 20;
|
|
constexpr int BACKDROP_ISAAC = 21;
|
|
constexpr int BACKDROP_BARREN = 22;
|
|
constexpr int BACKDROP_SECRET = 23;
|
|
constexpr int BACKDROP_DICE = 24;
|
|
constexpr int BACKDROP_ARCADE = 25;
|
|
constexpr int BACKDROP_ERROR_ROOM = 26;
|
|
constexpr int BACKDROP_BLUE_WOMB_PASS = 27;
|
|
constexpr int BACKDROP_GREED_SHOP = 28;
|
|
constexpr int BACKDROP_DUNGEON = 29;
|
|
constexpr int BACKDROP_SACRIFICE = 30;
|
|
constexpr int BACKDROP_MAUSOLEUM = 33;
|
|
constexpr int BACKDROP_DOWNPOUR_ENTRANCE = 36;
|
|
constexpr int BACKDROP_MAUSOLEUM_ENTRANCE = 38;
|
|
constexpr int BACKDROP_MAUSOLEUM_HEART = 39;
|
|
constexpr int BACKDROP_MAUSOLEUM2 = 40;
|
|
constexpr int BACKDROP_MAUSOLEUM3 = 41;
|
|
constexpr int BACKDROP_MAUSOLEUM4 = 42;
|
|
constexpr int BACKDROP_CORPSE2 = 43;
|
|
constexpr int BACKDROP_ISAACS_BEDROOM = 49;
|
|
constexpr int BACKDROP_HALLWAY = 50;
|
|
constexpr int BACKDROP_MOMS_BEDROOM = 51;
|
|
constexpr int BACKDROP_CLOSET = 52;
|
|
constexpr int BACKDROP_DOGMA = 54;
|
|
constexpr int BACKDROP_DUNGEON_GIDEON = 55;
|
|
constexpr int BACKDROP_DUNGEON_ROTGUT = 56;
|
|
constexpr int BACKDROP_DUNGEON_BEAST = 57;
|
|
constexpr int BACKDROP_DARK_CLOSET = 60;
|
|
constexpr int BACKDROP_DEATHMATCH = 61;
|
|
constexpr int BACKDROP_LIL_PORTAL = 62;
|
|
constexpr int BACKDROP_WOMB = 10;
|
|
constexpr int ROOM_DEATHMATCH_IDX = -19;
|
|
constexpr int DIMENSION_DEATH_CERTIFICATE = 2;
|
|
constexpr int DARK_CLOSET_B_SUBTYPE = 33;
|
|
constexpr int HOME_ISAACS_BEDROOM = 0;
|
|
constexpr int HOME_MOMS_BEDROOM = 2;
|
|
constexpr int HOME_LIVING_ROOM = 3;
|
|
constexpr int HOME_DOGMA = 9;
|
|
constexpr int HOME_CLOSET_LEFT = 10;
|
|
constexpr int BOSS_MAUSOLEUM_HEART = 90;
|
|
constexpr int BOSS_VISAGE = 78;
|
|
constexpr int BOSS_RAINMAKER = 77;
|
|
constexpr int STAGE_DARK_ROOM_CHEST = 11;
|
|
constexpr int STAGE_THE_VOID = 12;
|
|
constexpr int STAGE_MAUSOLEUM_II = 8;
|
|
constexpr int STAGE_ID_LAST_CHAPTER = 12;
|
|
constexpr int STAGE_ID_SHEOL = 14;
|
|
constexpr int STAGE_ID_CHEST = 17;
|
|
constexpr int STAGE_ID_ULTRA_GREED = 24;
|
|
constexpr int STAGE_ID_ULTRA_GREED_EXIT = 25;
|
|
constexpr int STAGE_ID_VOID = 26;
|
|
constexpr int STAGE_ID_FIRST_ALT = 27;
|
|
constexpr int GREED_STAGE_ULTRA_GREED = 6;
|
|
constexpr int VOID_BACKDROPS = 17;
|
|
constexpr uint32_t DELETE_THIS_STAGES = 11;
|
|
constexpr uint32_t DELETE_THIS_STAGE_TYPES = 5;
|
|
|
|
// The Beast's arena's bounds, wider than its grid.
|
|
constexpr float BEAST_ARENA_LEFT = -49.230774f;
|
|
constexpr float BEAST_ARENA_TOP = 72.30768f;
|
|
constexpr float BEAST_ARENA_RIGHT = 689.2308f;
|
|
constexpr float BEAST_ARENA_BOTTOM = 487.69232f;
|
|
|
|
// The deal door's chance: the base, what the items, trinkets, wisps, kills and red heart damage add, how a recent deal
|
|
// cuts it, and Goat Head's certainty. Greed's deal doors open from its eleventh wave (twelfth in Greedier).
|
|
constexpr float DEAL_CHANCE_BASE = 0.01f;
|
|
constexpr float DEAL_CHANCE_PENTAGRAM = 0.11f;
|
|
constexpr float DEAL_CHANCE_BLACK_CANDLE = 0.15f;
|
|
constexpr float DEAL_CHANCE_SECOND_PENTAGRAM = 0.05f;
|
|
constexpr float DEAL_CHANCE_BELIAL = 0.125f;
|
|
constexpr float DEAL_CHANCE_REVELATIONS = 0.175f;
|
|
constexpr float DEAL_CHANCE_BUM_KILLED = 0.35f;
|
|
constexpr float DEAL_CHANCE_UNHURT_BOSS = 0.35f;
|
|
constexpr float DEAL_CHANCE_CONTRITION_BOSS = 0.15f;
|
|
constexpr float DEAL_CHANCE_UNHURT_FLOOR = 0.99f;
|
|
constexpr float DEAL_CHANCE_CONTRITION_FLOOR = 0.4f;
|
|
constexpr float DEAL_CHANCE_SHOPKEEPER_KILLED = 0.1f;
|
|
constexpr float DEAL_CHANCE_SAUSAGE = 0.069f;
|
|
constexpr float DEAL_CHANCE_PER_WISP = 0.1f;
|
|
constexpr float DEAL_CHANCE_GOAT_HEAD = 66.6f;
|
|
constexpr float DEAL_RECENT_SCALE = 0.25f;
|
|
constexpr float DEAL_LAST_SCALE = 0.5f;
|
|
constexpr uint32_t GREED_DEAL_WAVE = 11;
|
|
constexpr int COLLECTIBLE_PENTAGRAM = 51;
|
|
constexpr int COLLECTIBLE_BOOK_OF_BELIAL = 34;
|
|
constexpr int COLLECTIBLE_BOOK_OF_REVELATIONS = 78;
|
|
constexpr int COLLECTIBLE_GOAT_HEAD = 215;
|
|
constexpr int COLLECTIBLE_BLACK_CANDLE = 260;
|
|
constexpr int COLLECTIBLE_SATANIC_BIBLE = 292;
|
|
constexpr int COLLECTIBLE_EUCHARIST = 499;
|
|
constexpr int COLLECTIBLE_ACT_OF_CONTRITION = 601;
|
|
constexpr int COLLECTIBLE_SAUSAGE = 669;
|
|
constexpr int TRINKET_NUMBER_MAGNET = 174;
|
|
constexpr int LEVEL_STATE_BUM_KILLED = 0;
|
|
constexpr int LEVEL_STATE_SHOPKEEPER_KILLED = 6;
|
|
|
|
// The doors of a cleared boss room: what unlocks them and the stages they open on, the secret exit kinds, the deal
|
|
// door's jingles and Greed's deal door slot, Mom's parts the Boss Rush door clears, and the run flags they set.
|
|
constexpr int ACHIEVEMENT_BLUE_WOMB = 234;
|
|
constexpr int ACHIEVEMENT_THE_VOID = 320;
|
|
constexpr int ACHIEVEMENT_SECRET_EXIT = 407;
|
|
constexpr int ACHIEVEMENT_STRANGE_DOOR = 635;
|
|
constexpr int STAGE_DEPTHS_II = 6;
|
|
constexpr int COLLECTIBLE_DUALITY = 498;
|
|
constexpr int TRINKET_ROSARY_BEAD = 7;
|
|
constexpr int TRINKET_STRANGE_KEY = 175;
|
|
constexpr int SOUND_ANGEL_DOOR_APPEAR = 23;
|
|
constexpr int SOUND_DEVIL_DOOR_APPEAR = 320;
|
|
constexpr int GREED_DEAL_DOOR_SLOT = 4;
|
|
constexpr int ENTITY_MOM = 45;
|
|
constexpr float MOM_DOOR_CLEARANCE = 50;
|
|
constexpr uint64_t GAME_STATE_ANGEL_DOOR_BITS = 1ull << 0;
|
|
constexpr uint64_t GAME_STATE_DEVILROOM_SPAWNED_BITS = 1ull << 5;
|
|
constexpr uint32_t LEVEL_STATE_VOID_DOOR_DISABLED = 1u << 21;
|
|
|
|
// The dust a door throws as it appears: how many puffs at least, how fast and far, how they spin and how long they
|
|
// last.
|
|
constexpr int EFFECT_DUST_CLOUD = 59;
|
|
constexpr int DUST_MIN = 5;
|
|
constexpr float DUST_SPEED = 5;
|
|
constexpr float DUST_RADIUS = 20;
|
|
constexpr float DUST_SPIN_RANGE = 10;
|
|
constexpr float DUST_SPIN_MIN = 2;
|
|
constexpr uint32_t DUST_TIMEOUT_RANGE = 10;
|
|
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_CRACKED_KEY = 78;
|
|
constexpr int CARD_SOUL_OF_CAIN = 83;
|
|
constexpr int SECRET_SHOP_COLUMN = 10;
|
|
constexpr int EFFECT_SHOP_LADDER = 156;
|
|
constexpr int EFFECT_DOOR_OUTLINE = 154;
|
|
constexpr int SOUND_SHOP_STAIRS = 916;
|
|
constexpr int STAIRS_SECRET_SHOP = 2;
|
|
constexpr float DOOR_OUTLINE_OFFSET = 15;
|
|
|
|
// The quest doors of the alternate path's second floors: the rooms holding them and the rooms they lead to.
|
|
constexpr int MIRROR_ROOM_SUBTYPE = 34;
|
|
constexpr int MINESHAFT_ROOM_SUBTYPE = 10;
|
|
constexpr int ROOM_MIRROR_IDX = -100;
|
|
constexpr int ROOM_MINESHAFT_IDX = -101;
|
|
constexpr int ACHIEVEMENT_MEGA_SATAN = 155;
|
|
|
|
// The effects pressure plates and rain spawn, and a minecart enemy on its rail.
|
|
constexpr int EFFECT_SPAWNER = 120;
|
|
constexpr int EFFECT_RAIN_DROP = 135;
|
|
constexpr int MINECART_ENEMY = 10;
|
|
constexpr int MINECART_VERTICAL = 4;
|
|
constexpr float MINECART_SPEED = 0.2f;
|
|
|
|
// The rain's spots: kept off the walls, where the light is bright enough, their ellipses' radii, and how fast a
|
|
// stopped rain fades.
|
|
constexpr float RAIN_MARGIN = 20;
|
|
constexpr float RAIN_LIGHT_MIN = 0.6f;
|
|
constexpr float RAIN_RADIUS_MIN = 20;
|
|
constexpr float RAIN_RADIUS_RANGE = 60;
|
|
constexpr float RAIN_FADE = 0.02f;
|
|
constexpr float RAIN_INTENSITY_MIN = 0.01f;
|
|
constexpr float RAIN_PI = 3.14f;
|
|
constexpr float QUARTER_TURN = 1.5707964f;
|
|
constexpr float DEGREES_TO_RADIANS = 0.017453292f;
|
|
|
|
// The screen color: how much secret rooms wash it out, pitch black rooms brighten it and the Mines' lava tints it,
|
|
// and how fast it fades.
|
|
constexpr float SECRET_WASHOUT = 0.75f;
|
|
constexpr float PITCH_BLACK_BRIGHTNESS = 0.03f;
|
|
constexpr float LAVA_TINT = 0.4f;
|
|
constexpr float LAVA_CONTRAST = 0.2f;
|
|
constexpr float LAVA_AMOUNT = 0.45f;
|
|
constexpr float COLOR_MODIFIER_RATE = 0.015f;
|
|
|
|
// The collectibles, trinkets, seeds and challenges Room checks.
|
|
constexpr int COLLECTIBLE_STOP_WATCH = 232;
|
|
constexpr int COLLECTIBLE_HOURGLASS = 66;
|
|
constexpr int COLLECTIBLE_INFESTATION = 148;
|
|
constexpr int COLLECTIBLE_INFESTATION_2 = 234;
|
|
constexpr int COLLECTIBLE_THE_STAIRWAY = 586;
|
|
constexpr int COLLECTIBLE_ISAACS_TOMB = 701;
|
|
constexpr int COLLECTIBLE_SANGUINE_BOND = 692;
|
|
constexpr int COLLECTIBLE_CARD_READING = 660;
|
|
constexpr int COLLECTIBLE_BROKEN_SHOVEL = 550;
|
|
constexpr int COLLECTIBLE_ASTRAL_PROJECTION = 677;
|
|
constexpr int TRINKET_BROKEN_GLASSES = 187;
|
|
constexpr int TRINKET_WICKED_CROWN = 161;
|
|
constexpr int TRINKET_HOLY_CROWN = 155;
|
|
constexpr int TRINKET_BLOODY_CROWN = 111;
|
|
constexpr int COLLECTIBLE_MORE_OPTIONS = 414;
|
|
constexpr int SEED_EFFECT_PRE_ITEMS = 79;
|
|
constexpr int SEED_EFFECT_NO_LAST_BOSS_DOORS = 71;
|
|
constexpr int SPECIAL_DAILY_SURPRISE_MINIBOSS = 17;
|
|
constexpr int CHALLENGE_SPEED = 22;
|
|
constexpr int CHALLENGE_DELETE_THIS = 45;
|
|
constexpr int ACHIEVEMENT_SHOP_LEVEL_2 = 151;
|
|
constexpr int ACHIEVEMENT_SHOP_LEVEL_3 = 152;
|
|
constexpr int ACHIEVEMENT_SHOP_LEVEL_4 = 153;
|
|
constexpr int ACHIEVEMENT_SHOP_LEVEL_5 = 154;
|
|
constexpr int ACHIEVEMENT_STORE_KEY = 379;
|
|
constexpr int EVENT_ARCADES_VISITED = 9;
|
|
constexpr int SHOP_VISITS_FOR_ACHIEVEMENT = 5;
|
|
constexpr int SHOP_LEVEL_MAX = 5;
|
|
|
|
// The run state and floor state bits Init and Update read.
|
|
constexpr uint64_t GAME_STATE_SURPRISE_MINIBOSS_SEEN = 1ull << 29;
|
|
constexpr uint32_t LEVEL_STATE_MINESHAFT_ESCAPE = 1u << 22;
|
|
constexpr uint32_t LEVEL_STATE_SHOVEL_QUEST_TRIGGERED = 1u << 16;
|
|
constexpr uint32_t LEVEL_STATE_BROKEN_WATCH_SLOW = 1u << 24;
|
|
constexpr uint32_t LEVEL_STATE_BROKEN_WATCH_FAST = 1u << 25;
|
|
|
|
// Init's ambient decoration: how many spawn at most, and how the second door chance raises them.
|
|
constexpr int AMBIENT_FLIES = 15;
|
|
constexpr int AMBIENT_DUST = 10;
|
|
constexpr int AMBIENT_DROPLETS = 10;
|
|
constexpr int AMBIENT_RAIN = 50;
|
|
constexpr int AMBIENT_RETRIES = 10;
|
|
constexpr int EMBER_COUNT = 10;
|
|
constexpr float EMBER_HEIGHT = 100;
|
|
constexpr float TREASURE_ITEM_SPACING = 40;
|
|
|
|
// The time scales the watches and effects set.
|
|
constexpr float TIME_SCALE_SLOW = 0.7f;
|
|
constexpr float TIME_SCALE_FAST = 1.43f;
|
|
constexpr float TIME_SCALE_STOP_WATCH = 0.9f;
|
|
constexpr float TIME_SCALE_EASE_FRAMES = 90;
|
|
constexpr float TIME_SCALE_EASE_DEPTH = 0.8f;
|
|
constexpr float TIME_SCALE_EASE_MIN = 0.5f;
|
|
constexpr float TIME_SCALE_PER_GFUEL = 0.1f;
|
|
constexpr float TIME_SCALE_STOP_WATCH_ROOM = 0.8f;
|
|
constexpr float TIME_SCALE_MIN = 0.02f;
|
|
constexpr float SUPER_HOT_SPEED = 4.2f;
|
|
constexpr float SUPER_HOT_SCALE_MAX = 1.75f;
|
|
constexpr uint32_t SEED_EFFECT_SUPER_HOT = 77;
|
|
|
|
// PlayMusic's crossfade rates: the usual one, the slow one between the Downpour and its reversed track, and the instant one.
|
|
constexpr float MUSIC_CROSSFADE = 0.08f;
|
|
constexpr float MUSIC_CROSSFADE_ASCENT = 0.008f;
|
|
constexpr float MUSIC_CROSSFADE_REVERSE = 0.01f;
|
|
constexpr float MUSIC_CROSSFADE_INSTANT = 1;
|
|
|
|
// The music.xml tracks PlayMusic picks from.
|
|
enum MusicId : int
|
|
{
|
|
MUSIC_NULL = 0,
|
|
MUSIC_BOSS = 9,
|
|
MUSIC_MOM_BOSS = 20,
|
|
MUSIC_MOMS_HEART_BOSS = 21,
|
|
MUSIC_ISAAC_BOSS = 22,
|
|
MUSIC_DARK_ROOM_BOSS = 24,
|
|
MUSIC_CHEST_BOSS = 25,
|
|
MUSIC_BOSS2 = 26,
|
|
MUSIC_ULTRA_GREED_BOSS = 28,
|
|
MUSIC_LIBRARY_ROOM = 30,
|
|
MUSIC_SECRET_ROOM = 31,
|
|
MUSIC_SECRET_ROOM_ALT = 32,
|
|
MUSIC_DEVIL_ROOM = 33,
|
|
MUSIC_ANGEL_ROOM = 34,
|
|
MUSIC_SHOP_ROOM = 35,
|
|
MUSIC_ARCADE_ROOM = 36,
|
|
MUSIC_BOSS_OVER = 37,
|
|
MUSIC_CHALLENGE_FIGHT = 38,
|
|
MUSIC_BOSS3 = 41,
|
|
MUSIC_MOTHER_BOSS = 43,
|
|
MUSIC_DOGMA_BOSS = 44,
|
|
MUSIC_BEAST_BOSS = 45,
|
|
MUSIC_PLANETARIUM = 50,
|
|
MUSIC_SECRET_ROOM_ALT_ALT = 51,
|
|
MUSIC_BOSS_OVER_TWISTED = 52,
|
|
MUSIC_REVERSE_GENESIS_START = 64,
|
|
MUSIC_HUSH_TRANSITION = 65,
|
|
MUSIC_ECHOES_REVERSE = 69,
|
|
MUSIC_TREASURE_JINGLE_FIRST = 87,
|
|
MUSIC_GAME_START_JINGLE = 95,
|
|
MUSIC_VOID_BOSS = 103,
|
|
MUSIC_DOWNPOUR = 104,
|
|
MUSIC_DOWNPOUR_REVERSED = 114,
|
|
MUSIC_ABANDONED_MINESHAFT = 116,
|
|
MUSIC_REVERSE_GENESIS = 118
|
|
};
|
|
constexpr int TREASURE_JINGLE_COUNT = 4;
|
|
|
|
static float random_unit()
|
|
{
|
|
return (float)Random() * 2.3283064e-10f;
|
|
}
|
|
|
|
static bool is_greed()
|
|
{
|
|
return g_game->difficulty == DIFFICULTY_GREED || g_game->difficulty == DIFFICULTY_GREEDIER;
|
|
}
|
|
|
|
static bool is_backwards_path()
|
|
{
|
|
return g_game->stage >= 1 && g_game->stage <= 6 && g_game->GetStateFlag(GAME_STATE_BACKWARDS_PATH);
|
|
}
|
|
|
|
static bool is_challenge_or_daily()
|
|
{
|
|
return g_game->challenge != 0 || g_game->dailyChallenge._id != 0;
|
|
}
|
|
|
|
// An achievement unlocked, or every one in a debug or daily run being played.
|
|
static bool is_unlocked(int achievement)
|
|
{
|
|
if (g_manager->persistentGameData.achievements[achievement]) return true;
|
|
return g_manager->state == MANAGER_STATE_GAME && (g_game->dailyChallenge._id != 0 || g_game->isDebug);
|
|
}
|
|
|
|
static bool is_curse_active(uint32_t curse)
|
|
{
|
|
uint32_t curses = Seeds::GetForcedCurses() | g_game->debugCurses | g_game->curses;
|
|
return (~Seeds::GetPreventedCurses() & curses & curse) != 0;
|
|
}
|
|
|
|
static void lua_garbage_collect();
|
|
|
|
// Spawns an entity of the room with no velocity or spawner.
|
|
static Entity* entity_spawn(int type, int variant, Vector position, int subType, uint32_t seed)
|
|
{
|
|
return g_game->Spawn({.position = position, .subType = subType, .type = type, .variant = variant, .seed = seed});
|
|
}
|
|
|
|
// 007e9400 An empty room: the surfaces rooms draw through made, its backdrops read (as a mod redirects
|
|
// backdrops.xml) and its render surface placed for the screen.
|
|
Room::Room()
|
|
{
|
|
room_surfaces_init();
|
|
backdrop.LoadConfig(g_manager->modManager.TryRedirectPath("backdrops.xml"));
|
|
renderSurfaceTopLeft = vector_make((g_screenWidth - 338) * 0.5f - 52, (g_screenHeight - 182) * 0.5f - 52);
|
|
}
|
|
|
|
// 007e9ba0 Deletes the grid entities the room owns.
|
|
Room::~Room()
|
|
{
|
|
for (GridEntity* entity : gridEntities) delete entity;
|
|
}
|
|
|
|
// 007eb010 Empties the room: no entities left in the list but the persistent ones, renumbered, no grid entities or
|
|
// doors, no ambush, the colors back to normal, and not initialized.
|
|
// The original also zeroes Game+0x265f0 after the ambush, which no curated member holds yet.
|
|
static void room_reset(Room& room)
|
|
{
|
|
room.entityList.Reset();
|
|
room.entityIndexCounter = 0;
|
|
for (Entity* entity : room.entityList.updateEL) entity->index = room.entityIndexCounter++;
|
|
room.lastAliveBossCount = 0;
|
|
for (int i = 0; i < ROOM_ITEM_COUNTER_COUNT; i++)
|
|
if (!(ROOM_ITEM_COUNTERS_KEPT >> i & 1)) room.itemCounters[i] = 0;
|
|
|
|
for (GridEntity*& entity : room.gridEntities)
|
|
{
|
|
delete entity;
|
|
entity = nullptr;
|
|
}
|
|
room.doors.fill(nullptr);
|
|
g_game->ambush._isActive = false;
|
|
g_game->ambush._currentWave = 0;
|
|
room.isCardAgainstHumanity = false;
|
|
room.isInitialized = false;
|
|
room.isFirstVisit = false;
|
|
room.renderScrollOffset = vector_make(0, 0);
|
|
room.roomType = ROOM_NULL;
|
|
room.greedWaveTimer = -1;
|
|
room.unknown72fc = -1;
|
|
room.wallColor = COLOR_DEFAULT;
|
|
room.floorColor = COLOR_DEFAULT;
|
|
}
|
|
|
|
// 007f2800 Enters a room: resets what a visit keeps, lays out the config's grid, doors, walls and entities from the
|
|
// descriptor's seeds (what a past visit saved restored on top), floods, darkens or tints it as its backdrop and
|
|
// flags say, decorates a first visit, and sets the camera on it.
|
|
void Room::Init(RoomConfig_Room& config, RoomDescriptor& roomDescriptor)
|
|
{
|
|
temporaryEffects.ClearEffects(false);
|
|
for (int group = 0; group < OUTPUT_GROUP_COUNT; group++)
|
|
{
|
|
outputGroupGridIndices[group].clear();
|
|
outputGroupCallbacks[group].clear();
|
|
}
|
|
// The original empties these lists in every room. DeathmatchManager::Reset gives every run a type, but only a
|
|
// versus arena's spawn points fill them, so outside a match they are already empty.
|
|
if (g_game->deathmatchManager.is_active())
|
|
reconstruction_missing("Room::Init 007f2800: the versus spawn lists of DeathmatchTypeBase (+0x10, +0x18)");
|
|
|
|
waterCurrent = vector_make(0, 0);
|
|
unknown73f0 = 0;
|
|
genesisTimer = 0;
|
|
lavaIntensity = 1;
|
|
isUnknown7769 = false;
|
|
isPickupVisionInvalid = false;
|
|
isUnknown11f6 = true;
|
|
isFirstEnemyDead = false;
|
|
isPacifist = false;
|
|
deathsListTarget = nullptr;
|
|
isDeathsListDone = false;
|
|
deathsListOffset = vector_make(0, 0);
|
|
bloodFromWallsDuration = 0;
|
|
bloodFromWallsCount = 0;
|
|
unknown70fc = 0;
|
|
slowdownDuration = 0;
|
|
unknown7230 = 0;
|
|
unknown721c = 0;
|
|
enterFrame = g_game->frameCount;
|
|
pendingGridRemovals.clear();
|
|
for (auto& [id, entity] : g_manager->entityConfig.entities) entity.isPreloaded = false;
|
|
isUnknown11f5 = true;
|
|
|
|
std::string log = "Room " + std::to_string(config.type) + "." + std::to_string(config.variant) + "(" + config.name +
|
|
")\n";
|
|
KAGE_LogMessage(LOG_INFO, (uint8_t*)log.c_str());
|
|
g_game->itemPool.ResetRoomBlacklist();
|
|
room_reset(*this);
|
|
gridWidth = config.width + 2;
|
|
gridHeight = config.height + 2;
|
|
lighting_load();
|
|
|
|
for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++)
|
|
doorGridPositions[slot] = room_shape_get_door_grid_index(slot, gridWidth, gridHeight, roomDescriptor.data->shape);
|
|
descriptor = &roomDescriptor;
|
|
roomType = (RoomType)roomDescriptor.data->type;
|
|
bossId = 0;
|
|
secondBossId = 0;
|
|
railManager.init();
|
|
beastArena.init();
|
|
if (roomType == ROOM_BOSS) boss_ids_init();
|
|
|
|
isSurpriseMiniboss = descriptor->flags & ROOM_DESCRIPTOR_FLAG_SURPRISE_MINIBOSS;
|
|
if (g_game->dailyChallenge._specialDailyId == SPECIAL_DAILY_SURPRISE_MINIBOSS && isSurpriseMiniboss)
|
|
g_game->gameStateFlags |= GAME_STATE_SURPRISE_MINIBOSS_SEEN;
|
|
isTriggerPressurePlates = false;
|
|
update_bounds(true);
|
|
init_shop_level();
|
|
shopRestockTimer = -1;
|
|
|
|
if (g_manager->netplayManager.is_online())
|
|
{
|
|
std::string frame = "[Frame " + std::to_string(g_game->frameCount) + "] ";
|
|
KAGE_LogMessage(LOG_INFO, (uint8_t*)frame.c_str());
|
|
}
|
|
std::string seedLog = "SpawnRNG seed: " + std::to_string(descriptor->spawnSeed) + "\n";
|
|
KAGE_LogMessage(LOG_INFO, (uint8_t*)seedLog.c_str());
|
|
|
|
SpawnFlags spawnFlags = init_spawn_flags(config);
|
|
LoadBackdropGraphics();
|
|
init_water(spawnFlags);
|
|
if (descriptor->visitedCount == 0) init_first_visit(spawnFlags);
|
|
init_saved_grid();
|
|
if (descriptor->pitsCount > 0 && backdropType == BACKDROP_CORPSE) waterAmount = 0;
|
|
|
|
RNG tintedRng = {descriptor->spawnSeed, 2, 21, 9};
|
|
bool isHardTinted = g_game->difficulty == DIFFICULTY_HARD || g_game->difficulty == DIFFICULTY_GREEDIER;
|
|
tintedRockIdx = tintedRng.RandomInt(isHardTinted ? 2 : 1) == 0 ? GetRandomTileIndex(tintedRng.Next()) : -1;
|
|
|
|
init_spawns(config);
|
|
if (config.type == ROOM_TREASURE) init_treasure_blind(config);
|
|
hold_trigger_output_entities();
|
|
for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++)
|
|
if (descriptor->allowedDoors & 1u << slot) MakeDoor(slot);
|
|
TrySpawnMegaSatanRoomDoor(false);
|
|
TrySpawnSpecialQuestDoor();
|
|
if (g_game->challenge == CHALLENGE_BACKASSWARDS && g_game->currentRoomIdx == ROOM_MEGA_SATAN_IDX)
|
|
reconstruction_missing("Room::Init 007f2800: Backasswards' door from Mega Satan back to the start (GridEntity_Door)");
|
|
make_walls();
|
|
init_dungeon_rock();
|
|
init_decorations(config);
|
|
for (int i = 0; i < gridHeight * gridWidth; i++)
|
|
if (gridEntities[i]) gridEntities[i]->PostInit();
|
|
attach_minecarts();
|
|
if (spawnFlags.isHeretic || spawnFlags.isRaglich)
|
|
reconstruction_missing("Room::Init 007f2800: the Heretic and Raglich fireplaces");
|
|
RestoreState();
|
|
if (!descriptor->savedEffects.empty())
|
|
reconstruction_missing("Room::Init 007f2800: respawning the saved effects (EntitySaveState)");
|
|
|
|
for (int i = 0; i < VENTRICLE_RAZOR_PORTAL_COUNT; i++)
|
|
{
|
|
VentricleRazorPortal& portal = g_game->ventricleRazorPortals[i];
|
|
if (g_game->GetRoomByIdx(portal.roomIndex) != descriptor) continue;
|
|
|
|
uint32_t seed = Random();
|
|
entity_spawn(ENTITY_EFFECT, EFFECT_WOMB_TELEPORT, GetGridPosition(portal.gridIndex), i, seed);
|
|
}
|
|
if (isFirstVisit) init_first_visit_items();
|
|
|
|
Entity_Player* sanguineOwner = g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_SANGUINE_BOND, LAZARUS_SHARE_CHECK);
|
|
if (roomType == ROOM_DEVIL && sanguineOwner && isFirstVisit) spawn_sanguine_bond_spikes(true);
|
|
bool isShovelRemoved = g_game->itemPool.removedCollectibles[COLLECTIBLE_BROKEN_SHOVEL];
|
|
if (g_game->stage == 1 && (g_game->levelStateFlags & LEVEL_STATE_SHOVEL_QUEST_TRIGGERED) &&
|
|
g_game->currentRoomIdx == g_game->startingRoomIdx && !isShovelRemoved)
|
|
{
|
|
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_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 (!is_backwards_path() && is_boss_doors_removed())
|
|
for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++) g_game->room->RemoveDoor(slot);
|
|
|
|
uint32_t stageType = g_game->stageType;
|
|
int effectiveStage = (int)g_game->stage;
|
|
if (is_greed()) effectiveStage = effectiveStage < 5 ? effectiveStage * 2 - 1 : effectiveStage == 5 ? 10 : 0;
|
|
int stageId = g_game->GetStageID();
|
|
brokenWatchState = BROKEN_WATCH_NONE;
|
|
isInitialized = true;
|
|
if (descriptor->visitedCount == 0)
|
|
{
|
|
init_first_visit_effects(config);
|
|
init_ambient_effects(effectiveStage, stageId, stageType);
|
|
}
|
|
|
|
if (g_game->challenge == CHALLENGE_BACKASSWARDS &&
|
|
(g_game->currentRoomIdx == g_game->startingRoomIdx || g_game->currentRoomIdx == ROOM_ERROR_IDX))
|
|
{
|
|
Vector center = GetCenterPos();
|
|
if (g_game->stage == 1) entity_spawn(ENTITY_PICKUP, PICKUP_TROPHY, center, 0, Random());
|
|
else if (isFirstVisit) entity_spawn(ENTITY_EFFECT, EFFECT_HEAVEN_LIGHT_DOOR, center, 0, Random());
|
|
}
|
|
if (!g_game->isRestoringGlowingHourglassState) visit_record();
|
|
if ((effectiveStage == 1 || effectiveStage == 2) && stageType == STAGETYPE_AFTERBIRTH)
|
|
{
|
|
for (int i = 0; i < EMBER_COUNT; i++)
|
|
{
|
|
uint32_t seed = Random();
|
|
Vector position = GetRandomPosition(0);
|
|
Vector start = vector_make(position.x - 0, position.y - EMBER_HEIGHT);
|
|
entity_spawn(ENTITY_EFFECT, EFFECT_FALLING_EMBER, start, 0, seed)->Update();
|
|
}
|
|
}
|
|
|
|
if (GetAliveEnemiesCount() < 1 && roomClearDelay == 0 && !IsClear() &&
|
|
g_game->deathmatchManager.state < DEATHMATCH_INTRO)
|
|
descriptor->flags |= ROOM_DESCRIPTOR_FLAG_CLEAR;
|
|
if (!IsClear() && config.type == ROOM_MINIBOSS)
|
|
reconstruction_missing("Room::Init 007f2800: a miniboss's versus title (HUD::ShowStackedItemTextCustomUTF16)");
|
|
if (IsClear()) isDeathsListDone = true;
|
|
isRedHeartDamaged = false;
|
|
init_rain();
|
|
init_colors();
|
|
|
|
if (descriptor->flags & ROOM_DESCRIPTOR_FLAG_ROTGUT_CLEARED && bossId == BOSS_ROTGUT) bossId = 0;
|
|
color_modifier_apply();
|
|
init_mineshaft_colors();
|
|
update_bounds(false);
|
|
camera = std::make_unique<Camera>(*this);
|
|
for (Shockwave& wave : roomShockwaves) wave.duration = wave.frame;
|
|
backdrop.load_details();
|
|
TextureCache::Purge();
|
|
lua_garbage_collect();
|
|
|
|
if (bossId == BOSS_ULTRA_GREED && g_game->difficulty == DIFFICULTY_GREEDIER && IsClear()) TurnGold();
|
|
|
|
Room& current = *g_game->room;
|
|
if (g_game->levelStateFlags & LEVEL_STATE_BROKEN_WATCH_SLOW)
|
|
{
|
|
current.brokenWatchState = BROKEN_WATCH_SLOW;
|
|
g_manager->musicManager.targetPitch = current.time_scale_update();
|
|
current.slowdownDuration = INT_MAX;
|
|
}
|
|
if (g_game->levelStateFlags & LEVEL_STATE_BROKEN_WATCH_FAST)
|
|
{
|
|
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)");
|
|
}
|
|
}
|
|
|
|
// The light gradient and spotlight sprites, loaded once and played from their default animation. The gradient blends
|
|
// with premultiplied alpha.
|
|
void Room::lighting_load()
|
|
{
|
|
if (!lightSprite.isLoaded)
|
|
{
|
|
lightSprite.Load("gfx/LightGradient.anm2", GRAPHICS_LOAD);
|
|
lightSprite.GetLayer(0)->minFilterMode = FILTER_LINEAR;
|
|
lightSprite.GetLayer(0)->magFilterMode = FILTER_LINEAR;
|
|
lightSprite.Play(lightSprite.GetDefaultAnimationName());
|
|
lightSprite.GetLayer(0)->blendMode = LIGHT_BLEND;
|
|
}
|
|
if (!spotLightSprite.isLoaded)
|
|
{
|
|
spotLightSprite.Load("gfx/SpotLight.anm2", GRAPHICS_LOAD);
|
|
spotLightSprite.GetLayer(0)->minFilterMode = FILTER_LINEAR;
|
|
spotLightSprite.GetLayer(0)->magFilterMode = FILTER_LINEAR;
|
|
spotLightSprite.Play(spotLightSprite.GetDefaultAnimationName());
|
|
}
|
|
}
|
|
|
|
// A boss room's bosses: each spawn's likeliest entry (the first of the highest weight), from the last spawn to the
|
|
// first, whose config names a boss. The first found is the boss, a different later one the second boss.
|
|
// The original reads before the entries of a spawn with none or with only zero weights. Those are skipped.
|
|
void Room::boss_ids_init()
|
|
{
|
|
std::vector<RoomSpawn>& spawns = descriptor->data->spawns;
|
|
|
|
for (auto spawn = spawns.rbegin(); spawn != spawns.rend(); ++spawn)
|
|
{
|
|
float bestWeight = 0;
|
|
RoomEntry* best = nullptr;
|
|
|
|
for (RoomEntry& entry : spawn->entries)
|
|
{
|
|
if (bestWeight >= entry.weight) continue;
|
|
best = &entry;
|
|
bestWeight = entry.weight;
|
|
}
|
|
if (!best) continue;
|
|
|
|
EntityConfig_Entity* entity = g_manager->entityConfig.GetEntity(best->type, best->variant, best->subtype);
|
|
if (!entity || entity->bossID == 0) continue;
|
|
if (bossId == 0) bossId = entity->bossID;
|
|
else if (entity->bossID != bossId) secondBossId = entity->bossID;
|
|
}
|
|
}
|
|
|
|
// The shop's level: by stage in Greed mode, otherwise by the shop upgrades unlocked (all of them in a debug or daily
|
|
// run being played).
|
|
void Room::init_shop_level()
|
|
{
|
|
if (is_greed())
|
|
{
|
|
switch (g_game->stage)
|
|
{
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
case 4:
|
|
case 5:
|
|
shopLevel = (int)g_game->stage;
|
|
break;
|
|
case 6:
|
|
shopLevel = roomType == ROOM_DEFAULT ? SHOP_LEVEL_MAX : 1;
|
|
break;
|
|
}
|
|
return;
|
|
}
|
|
|
|
std::array<bool, ACHIEVEMENT_COUNT>& achievements = g_manager->persistentGameData.achievements;
|
|
bool isAllUnlocked = g_manager->state == MANAGER_STATE_GAME && (g_game->dailyChallenge._id != 0 || g_game->isDebug);
|
|
|
|
shopLevel = 1;
|
|
if (achievements[ACHIEVEMENT_SHOP_LEVEL_5] || isAllUnlocked) shopLevel = 5;
|
|
else if (achievements[ACHIEVEMENT_SHOP_LEVEL_4]) shopLevel = 4;
|
|
else if (achievements[ACHIEVEMENT_SHOP_LEVEL_3]) shopLevel = 3;
|
|
else if (achievements[ACHIEVEMENT_SHOP_LEVEL_2]) shopLevel = 2;
|
|
}
|
|
|
|
// What the layout's spawns say about the room before anything spawns: water, a dump, the Heretic or Raglich, the
|
|
// pitch black, cursed mist and alternate backdrop flags, and a water current. Each spawn draws its entry from the
|
|
// spawn seed, as init_spawns draws them again.
|
|
SpawnFlags Room::init_spawn_flags(RoomConfig_Room& config)
|
|
{
|
|
SpawnFlags flags;
|
|
RNG rng = {descriptor->spawnSeed, 2, 7, 7};
|
|
|
|
for (RoomSpawn& spawn : config.spawns)
|
|
{
|
|
uint32_t seed = rng.Next();
|
|
if (spawn.entries.empty()) continue;
|
|
|
|
RoomEntry& entry = *spawn.PickEntry((float)seed * 2.3283062e-10f);
|
|
bool isDump = false;
|
|
|
|
switch (entry.type)
|
|
{
|
|
case SPAWN_WATER:
|
|
case SPAWN_WATER_ALT:
|
|
flags.isWater = true;
|
|
break;
|
|
case SPAWN_DRY:
|
|
flags.isDry = true;
|
|
break;
|
|
case SPAWN_DUMP:
|
|
case SPAWN_DUMP_ALT:
|
|
isDump = true;
|
|
break;
|
|
case SPAWN_ALT_BACKDROP:
|
|
descriptor->flags |= ROOM_DESCRIPTOR_FLAG_USE_ALTERNATE_BACKDROP;
|
|
break;
|
|
case SPAWN_HERETIC:
|
|
flags.isHeretic = true;
|
|
break;
|
|
case SPAWN_RAGLICH:
|
|
flags.isRaglich = true;
|
|
break;
|
|
case SPAWN_ROOM_CONFIG:
|
|
if (entry.variant == ROOM_CONFIG_PITCH_BLACK) descriptor->flags |= ROOM_DESCRIPTOR_FLAG_PITCH_BLACK;
|
|
else if (entry.variant == ROOM_CONFIG_CURSED_MIST) descriptor->flags |= ROOM_DESCRIPTOR_FLAG_CURSED_MIST;
|
|
else if (entry.variant == ROOM_CONFIG_VERSUS_SPAWN && g_game->deathmatchManager.type)
|
|
reconstruction_missing("Room::Init 007f2800: a 970.4 versus spawn point (DeathmatchTypeBase lists)");
|
|
else if (entry.variant == ROOM_CONFIG_WATER)
|
|
{
|
|
if (entry.subtype == WATER_SUBTYPE_DRY) flags.isDry = true;
|
|
else if (entry.subtype == WATER_SUBTYPE_FLOODED) flags.isFlooded = true;
|
|
else if (entry.subtype == WATER_SUBTYPE_DUMP) isDump = true;
|
|
else if (entry.subtype < WATER_CURRENT_COUNT)
|
|
waterCurrent = vector_make(WATER_CURRENTS[entry.subtype][0], WATER_CURRENTS[entry.subtype][1]);
|
|
}
|
|
break;
|
|
}
|
|
if (!isDump) continue;
|
|
flags.isDump = true;
|
|
descriptor->flags |= ROOM_DESCRIPTOR_FLAG_USE_ALTERNATE_BACKDROP;
|
|
}
|
|
return flags;
|
|
}
|
|
|
|
// How much water the room shows: full in the Flooded Caves and the last Corpse backdrop, a fifth of the Scarred Womb's
|
|
// normal rooms, the Downpour and Dross stages but for their secret exits, and flooded rooms. The Dark Room, the
|
|
// Planetarium, crawlspaces and dumps stay dry. Water puts out the lava.
|
|
void Room::init_water(SpawnFlags& flags)
|
|
{
|
|
int roomBackdrop = g_game->room->backdropType;
|
|
waterAmount = 0;
|
|
|
|
if (roomBackdrop == BACKDROP_FLOODED_CAVES || roomBackdrop == BACKDROP_CORPSE3) waterAmount = 1;
|
|
else if (roomBackdrop == BACKDROP_SCARRED_WOMB && descriptor->data->type == ROOM_DEFAULT)
|
|
{
|
|
RNG rng = {descriptor->decorationSeed, 1, 19, 3};
|
|
if (rng.Next() % 5 == 0) waterAmount = 1;
|
|
}
|
|
waterLerpColorDuration = -1;
|
|
waterLerpColorCountdown = -1;
|
|
|
|
int stageId = g_game->GetStageID();
|
|
if ((stageId == STAGE_ID_DOWNPOUR || stageId == STAGE_ID_DROSS) && roomType != ROOM_SECRET_EXIT) waterAmount = 1;
|
|
if (descriptor->flags & ROOM_DESCRIPTOR_FLAG_FLOODED || flags.isFlooded) waterAmount = 1;
|
|
|
|
bool isDryDump = flags.isDump && !(descriptor->flags & ROOM_DESCRIPTOR_FLAG_FLOODED);
|
|
if (backdropType == BACKDROP_DARK_ROOM || backdropType == BACKDROP_PLANETARIUM || roomType == ROOM_DUNGEON || isDryDump)
|
|
waterAmount = 0;
|
|
if (waterAmount > 0) lavaIntensity = 0;
|
|
}
|
|
|
|
// A first visit's flags from the decoration seed: water pits by the backdrop's chance (or always in the Flooded
|
|
// Caves with the water surface off), the alternate boss music, a shop visit counted, and the backdrops' special cases.
|
|
void Room::init_first_visit(SpawnFlags& flags)
|
|
{
|
|
RNG rng = {descriptor->decorationSeed, 5, 9, 7};
|
|
uint32_t& roomFlags = descriptor->flags;
|
|
|
|
isFirstVisit = true;
|
|
if (backdropType == BACKDROP_FLOODED_CAVES && !g_manager->optionsConfig.render.isWaterSurfaceEnabled)
|
|
roomFlags |= ROOM_DESCRIPTOR_FLAG_HAS_WATER;
|
|
else
|
|
{
|
|
uint8_t mode = backdrop.configs[backdropType].waterPitsMode;
|
|
bool isWater = mode == 2 || (mode == 1 && (rng.Next() & 1) == 0);
|
|
roomFlags = isWater ? roomFlags | ROOM_DESCRIPTOR_FLAG_HAS_WATER : roomFlags & ~ROOM_DESCRIPTOR_FLAG_HAS_WATER;
|
|
}
|
|
bool isAltMusic = (rng.Next() & 1) == 0;
|
|
roomFlags = isAltMusic ? roomFlags | ROOM_DESCRIPTOR_FLAG_ALT_BOSS_MUSIC : roomFlags & ~ROOM_DESCRIPTOR_FLAG_ALT_BOSS_MUSIC;
|
|
|
|
if (roomType == ROOM_SHOP && ++g_game->shopVisits > SHOP_VISITS_FOR_ACHIEVEMENT && !is_greed())
|
|
g_manager->persistentGameData.TryUnlock(ACHIEVEMENT_STORE_KEY);
|
|
|
|
bool isDry = flags.isDry;
|
|
bool isWater = flags.isWater;
|
|
if (backdropType == BACKDROP_MINES)
|
|
{
|
|
if (roomFlags & ROOM_DESCRIPTOR_FLAG_HAS_WATER && roomFlags & ROOM_DESCRIPTOR_FLAG_PITCH_BLACK)
|
|
roomFlags &= ~ROOM_DESCRIPTOR_FLAG_HAS_WATER;
|
|
}
|
|
else if (backdropType == BACKDROP_MINES_SHAFT || backdropType == BACKDROP_ASHPIT_SHAFT)
|
|
{
|
|
if (g_game->levelStateFlags & LEVEL_STATE_MINESHAFT_ESCAPE)
|
|
{
|
|
isDry = false;
|
|
isWater = true;
|
|
}
|
|
roomFlags |= ROOM_DESCRIPTOR_FLAG_CURSED_MIST;
|
|
}
|
|
if (isWater) roomFlags |= ROOM_DESCRIPTOR_FLAG_HAS_WATER;
|
|
if (isDry) roomFlags &= ~ROOM_DESCRIPTOR_FLAG_HAS_WATER;
|
|
if (backdropType == BACKDROP_ASHPIT && roomFlags & ROOM_DESCRIPTOR_FLAG_HAS_WATER)
|
|
roomFlags |= ROOM_DESCRIPTOR_FLAG_USE_ALTERNATE_BACKDROP;
|
|
}
|
|
|
|
// Clears the grid paths and the descriptor's pit and poop counts, then rebuilds the grid entities a past visit saved.
|
|
void Room::init_saved_grid()
|
|
{
|
|
gridPaths.fill(0);
|
|
gridTimers.fill(0);
|
|
roomClearDelay = 0;
|
|
descriptor->pitsCount = 0;
|
|
descriptor->poopCount = 0;
|
|
|
|
for (int i = 0; i < gridHeight * gridWidth; i++)
|
|
{
|
|
GridEntityDesc& saved = descriptor->savedGridEntities[i];
|
|
if (saved._type == 0) continue;
|
|
|
|
delete gridEntities[i];
|
|
gridEntities[i] = CreateGridEntity((GridEntityType)saved._type, i);
|
|
if (gridEntities[i])
|
|
{
|
|
gridEntities[i]->desc_load(saved);
|
|
gridEntities[i]->Init(saved._spawnSeed);
|
|
}
|
|
if (saved._type == GRID_PIT) descriptor->pitsCount++;
|
|
else if (saved._type == GRID_POOP) descriptor->poopCount++;
|
|
}
|
|
}
|
|
|
|
// Spawns the layout's entities, each spawn's entry drawn from the spawn seed, except where the descriptor restricts.
|
|
void Room::init_spawns(RoomConfig_Room& config)
|
|
{
|
|
RNG rng = {descriptor->spawnSeed, 2, 7, 7};
|
|
|
|
for (RoomSpawn& spawn : config.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 * 2.3283062e-10f);
|
|
if (!descriptor->restrictedGridIndexes.contains(gridIndex))
|
|
room_entry_spawn(*this, entry, {.gridIndex = gridIndex, .seed = seed});
|
|
}
|
|
}
|
|
|
|
// A treasure room's blind items: the second of two or more on the alternate path, or with Broken Glasses (whose
|
|
// multiplier may spare it on the alternate path, and which leaves a More Options room alone elsewhere). An alternate
|
|
// path's room frees its third item from the option group. Greed's rooms other than its treasure room drop their
|
|
// co-op duplicates. A backwards run and a daily skip the blind items.
|
|
void Room::init_treasure_blind(RoomConfig_Room& config)
|
|
{
|
|
std::vector<Entity_Pickup*> items;
|
|
for (Entity* entity : entityList.updateEL)
|
|
if (entity->type == ENTITY_PICKUP && entity->variant == PICKUP_COLLECTIBLE)
|
|
items.push_back(static_cast<Entity_Pickup*>(entity));
|
|
|
|
PlayerManager& players = g_game->playerManager;
|
|
bool isAltStage = g_game->stageType == STAGETYPE_REPENTANCE || g_game->stageType == STAGETYPE_REPENTANCE_B;
|
|
bool isMoreOptions = false;
|
|
auto is_multiplied = [&](int trinket)
|
|
{
|
|
Entity_Player* owner = players.FirstTrinketOwner(trinket);
|
|
return owner && owner->GetTrinketMultiplier(trinket) > 1;
|
|
};
|
|
|
|
if (g_game->stage == 10 && g_game->stageType == STAGETYPE_ORIGINAL) isMoreOptions = is_multiplied(TRINKET_WICKED_CROWN);
|
|
if (!isMoreOptions && g_game->stage == 10 && g_game->stageType == STAGETYPE_WOTL)
|
|
isMoreOptions = is_multiplied(TRINKET_HOLY_CROWN);
|
|
if (!isMoreOptions && (g_game->stage == 7 || g_game->stage == 8)) isMoreOptions = is_multiplied(TRINKET_BLOODY_CROWN);
|
|
isMoreOptions = players.FirstCollectibleOwner(COLLECTIBLE_MORE_OPTIONS, LAZARUS_SHARE_CHECK) || isMoreOptions ||
|
|
(g_game->roomTransition.is_active() && g_game->roomTransition.flags & 1);
|
|
|
|
bool isOptionsRoom = (config.subtype == 1 || config.subtype == 3) && isMoreOptions;
|
|
bool isGlasses = players.AnyoneHasTrinket(TRINKET_BROKEN_GLASSES) && g_game->stage != STAGE_BLUE_WOMB && !isOptionsRoom;
|
|
if ((isAltStage || isGlasses) && !is_backwards_path() && items.size() > 1 && g_game->dailyChallenge._id == 0)
|
|
{
|
|
bool isSpared = false;
|
|
if (isAltStage && players.AnyoneHasTrinket(TRINKET_BROKEN_GLASSES))
|
|
{
|
|
RNG rng = {descriptor->spawnSeed, 9, 5, 25};
|
|
isSpared = (int)(rng.Next() & 1) < players.GetTrinketMultiplier(TRINKET_BROKEN_GLASSES);
|
|
}
|
|
Entity_Pickup* item = items[1];
|
|
bool isWasBlind = item->isForceBlind;
|
|
|
|
if (!isSpared) item->isForceBlind = true;
|
|
if (!isSpared && item->variant == PICKUP_COLLECTIBLE && item->subtype != 0 && !isWasBlind) item->UpdateSprite(false);
|
|
}
|
|
if (isAltStage && items.size() > 2 && (config.subtype == 0 || config.subtype == 2)) items[2]->optionsPickupIndex = 0;
|
|
if (is_greed() && descriptor->gridIndex != (int)g_game->greedModeTreasureRoomIdx)
|
|
for (Entity_Pickup* item : items) item->coopDuplicateIndex = 0;
|
|
}
|
|
|
|
// The dungeon rock (the crawlspace's rock): on a room the placement seed picks, avoiding boss, challenge and miniboss
|
|
// rooms, a random cell holding a breakable grid entity.
|
|
void Room::init_dungeon_rock()
|
|
{
|
|
RNG rng = {g_game->dungeonPlacementSeed, 5, 9, 7};
|
|
int roomIndex = -1;
|
|
|
|
dungeonRockIdx = -1;
|
|
for (int i = 0; i < 3 && roomIndex < 0; i++)
|
|
{
|
|
roomIndex = (int)rng.RandomInt(g_game->nbRooms);
|
|
RoomConfig_Room* data = g_game->roomList[roomIndex].data;
|
|
if (data && (data->type == ROOM_BOSS || data->type == ROOM_CHALLENGE || data->type == ROOM_MINIBOSS)) roomIndex = -1;
|
|
}
|
|
if (roomIndex != descriptor->listIndex) return;
|
|
|
|
for (int i = 0; i < AMBIENT_RETRIES && dungeonRockIdx < 0; i++)
|
|
{
|
|
dungeonRockIdx = (int)rng.RandomInt(gridHeight * gridWidth);
|
|
GridEntity* entity = dungeonRockIdx < ROOM_GRID_CELLS ? gridEntities[dungeonRockIdx] : nullptr;
|
|
int type = entity ? entity->type : GRID_NULL;
|
|
|
|
bool isUnbreakable = type == GRID_WALL || type == GRID_ROCKB || type == GRID_ROCK_SS || type == GRID_ROCK_BOMB;
|
|
if (!entity || isUnbreakable) dungeonRockIdx = -1;
|
|
}
|
|
}
|
|
|
|
// 007ebca0 Puts a new grid entity of a type and variant on a cell from a seed, replacing what stood there, when
|
|
// the cell is free: no collision for trapdoors, stairs, pressure plates and teleporters, an unclaimed path for the
|
|
// others. False when it is not or the type has no grid entity.
|
|
bool Room::SpawnGridEntity(int gridIndex, GridEntityType type, int variant, uint32_t seed, int varData)
|
|
{
|
|
if (gridIndex < 0 || gridIndex >= ROOM_GRID_CELLS)
|
|
KAGE_LogMessage(LOG_ASSERT, (uint8_t*)"SpawnGridEntity: Grid index invalid\n");
|
|
if ((uint32_t)gridIndex >= ROOM_GRID_CELLS) return false;
|
|
|
|
bool isFlat = type == GRID_TRAPDOOR || type == GRID_STAIRS || type == GRID_PRESSURE_PLATE || type == GRID_TELEPORTER;
|
|
bool isFree = isFlat ? GetGridCollision(gridIndex) == GRID_COLLISION_NONE : gridPaths[gridIndex] <= GRID_PATH_RESET;
|
|
GridEntity* entity = isFree ? CreateGridEntity(type, gridIndex) : nullptr;
|
|
if (!entity) return false;
|
|
|
|
delete gridEntities[gridIndex];
|
|
gridEntities[gridIndex] = entity;
|
|
entity->variant = variant;
|
|
entity->varData = varData;
|
|
entity->Init(seed);
|
|
return true;
|
|
}
|
|
|
|
// 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)");
|
|
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;
|
|
uint32_t effectiveStage = isAltStage ? g_game->stage + 1 : g_game->stage;
|
|
bool isFirstRoom = effectiveStage == 1 && g_game->startingRoomIdx == g_game->currentRoomIdx;
|
|
|
|
if (!isFirstRoom && !backdrop.configs[backdropType].props.empty())
|
|
{
|
|
RNG rng = {(descriptor->decorationSeed & INT_MAX) + (uint32_t)descriptor->gridIndex, 5, 9, 7};
|
|
int count = (int)(rng.Next() & 3);
|
|
uint32_t seed = rng.Next();
|
|
count += (int)(seed % 5);
|
|
|
|
bool isWide = config.width > 13;
|
|
bool isTall = config.height > 7;
|
|
if (isWide != isTall) count += (int)(rng.Next() % 9);
|
|
if (isWide && isTall)
|
|
{
|
|
count += (int)(rng.Next() % 9);
|
|
count += (int)(rng.Next() % 18);
|
|
}
|
|
for (int attempt = 0; attempt < count * 2; attempt++)
|
|
{
|
|
int gridIndex = GetRandomTileIndex(rng.Next());
|
|
if (gridEntities[gridIndex]) continue;
|
|
|
|
SpawnGridEntity(gridIndex, GRID_DECORATION, 0, Random(), 0);
|
|
attempt++;
|
|
}
|
|
}
|
|
}
|
|
if (is_greed() && config.type == ROOM_DEFAULT)
|
|
reconstruction_missing("Room::Init 007f2800: Greed's rocks around the center (GridEntity stays generated)");
|
|
}
|
|
|
|
// The first visit's items in the starting room: Isaac's Tomb's old chest, the pre-items seed's collectibles (two
|
|
// under the Curse of the Labyrinth), and Luna's light in secret rooms.
|
|
void Room::init_first_visit_items()
|
|
{
|
|
PlayerManager& players = g_game->playerManager;
|
|
|
|
if (g_game->currentRoomIdx == g_game->startingRoomIdx && g_game->stage != STAGE_HOME)
|
|
{
|
|
if (players.FirstCollectibleOwner(COLLECTIBLE_CARD_READING, LAZARUS_SHARE_CHECK) && !is_greed())
|
|
reconstruction_missing("Room::Init 007f2800: the starting room's portals (FUN_00737c10)");
|
|
if (players.FirstCollectibleOwner(COLLECTIBLE_THE_STAIRWAY, LAZARUS_SHARE_CHECK))
|
|
reconstruction_missing("Room::Init 007f2800: effect 156's path to the entrance (is_obstacle_path_valid)");
|
|
if (players.FirstCollectibleOwner(COLLECTIBLE_ISAACS_TOMB, LAZARUS_SHARE_CHECK))
|
|
{
|
|
RNG rng = {descriptor->decorationSeed, 9, 21, 16};
|
|
Vector center = GetCenterPos();
|
|
entity_spawn(ENTITY_PICKUP, PICKUP_OLDCHEST, vector_make(center.x + 0, center.y - 40), 0, rng.Next());
|
|
}
|
|
if (g_game->seedEffects.HasSeedEffect(SEED_EFFECT_PRE_ITEMS))
|
|
{
|
|
RNG rng = {descriptor->decorationSeed, 9, 21, 16};
|
|
Vector center = GetCenterPos();
|
|
Vector position = vector_make(center.x + 0, center.y - 40);
|
|
|
|
if (is_curse_active(CURSE_OF_LABYRINTH))
|
|
{
|
|
uint32_t seed = rng.Next();
|
|
entity_spawn(ENTITY_PICKUP, PICKUP_COLLECTIBLE, vector_make(position.x + TREASURE_ITEM_SPACING, position.y - 0),
|
|
-1, seed);
|
|
position = vector_make(position.x - TREASURE_ITEM_SPACING, position.y + 0);
|
|
}
|
|
entity_spawn(ENTITY_PICKUP, PICKUP_COLLECTIBLE, position, -1, rng.Next());
|
|
}
|
|
}
|
|
if ((roomType == ROOM_SECRET || roomType == ROOM_SUPERSECRET) &&
|
|
players.FirstCollectibleOwner(COLLECTIBLE_LUNA, LAZARUS_SHARE_CHECK))
|
|
{
|
|
RNG rng = {descriptor->decorationSeed, 9, 11, 19};
|
|
uint32_t seed = rng.Next();
|
|
entity_spawn(ENTITY_EFFECT, EFFECT_HEAVEN_LIGHT_DOOR, GetCenterPos(), 1, seed);
|
|
}
|
|
}
|
|
|
|
// Whether a boss room loses its doors: Mom's (unless cleared in Backasswards), Mega Satan's (but in Backasswards),
|
|
// Ultra Greed's, the pre-Ascent Mom's Mausoleum boss, and the last boss room under the no-doors seed.
|
|
bool Room::is_boss_doors_removed()
|
|
{
|
|
bool isBackasswardsClear = g_game->challenge == CHALLENGE_BACKASSWARDS && IsClear();
|
|
|
|
if ((bossId == BOSS_MOM || bossId == BOSS_MOM_MAUSOLEUM) && !isBackasswardsClear) return true;
|
|
if (bossId == BOSS_MEGA_SATAN && g_game->challenge != CHALLENGE_BACKASSWARDS) return true;
|
|
if (bossId == BOSS_ULTRA_GREED) return true;
|
|
if (roomType == ROOM_BOSS && descriptor->data->subtype == BOSS_MOM_MAUSOLEUM && g_game->IsPreAscent()) return true;
|
|
return g_game->seedEffects.HasSeedEffect(SEED_EFFECT_NO_LAST_BOSS_DOORS) &&
|
|
g_game->GetRoomByIdx(g_game->currentRoomIdx)->listIndex == g_game->lastBossRoomListIdx;
|
|
}
|
|
|
|
// A first visit's room type extras: an arcade counted, Isaac's and Barren rooms' carpet, and the dice room's floor.
|
|
void Room::init_first_visit_effects(RoomConfig_Room& config)
|
|
{
|
|
if (config.type == ROOM_ARCADE) g_manager->persistentGameData.IncreaseEventCounter(EVENT_ARCADES_VISITED, 1);
|
|
else if ((config.type == ROOM_ISAACS || config.type == ROOM_BARREN) && g_game->currentRoomIdx != ROOM_GENESIS_IDX)
|
|
{
|
|
uint32_t seed = Random();
|
|
entity_spawn(ENTITY_EFFECT, EFFECT_ISAACS_CARPET, GetCenterPos(), 0, seed)->Update();
|
|
}
|
|
else if (config.type == ROOM_DICE)
|
|
{
|
|
RNG rng = {descriptor->spawnSeed, 5, 9, 7};
|
|
uint32_t seed = Random();
|
|
int face = (int)(rng.Next() % 6);
|
|
entity_spawn(ENTITY_EFFECT, EFFECT_DICE_FLOOR, GetCenterPos(), face, seed)->Update();
|
|
}
|
|
}
|
|
|
|
// A random point of the room's rectangle, its y drawn first.
|
|
static Vector room_random_point(Room& room)
|
|
{
|
|
float y = (room.bottomRightPos.y - room.topLeftPos.y) * random_unit() + room.topLeftPos.y;
|
|
float x = (room.bottomRightPos.x - room.topLeftPos.x) * random_unit() + room.topLeftPos.x;
|
|
return vector_make(x, y);
|
|
}
|
|
|
|
// Spawns an ambient effect at a random point and updates it once.
|
|
static void ambient_spawn(Room& room, int variant, int subType)
|
|
{
|
|
Vector position = room_random_point(room);
|
|
entity_spawn(ENTITY_EFFECT, variant, position, subType, Random())->Update();
|
|
}
|
|
|
|
// A random count below max, then below that plus one, halved in the starting room.
|
|
static int ambient_count(RNG& rng, uint32_t max, int shift)
|
|
{
|
|
return (int)(rng.RandomInt(rng.RandomInt(max) + 1) >> shift);
|
|
}
|
|
|
|
// A first visit's ambient effects from the spawn seed: tiny flies, dust and droplets, wall bugs, embers and falling
|
|
// drops by stage, and the Downpour's tadpoles and ghosts. About half the rooms have none, but the Blue Womb, the super
|
|
// secret room, dark boss rooms, the Dross and the mineshaft always do. A planetarium only has its wisps.
|
|
void Room::init_ambient_effects(int effectiveStage, int stageId, uint32_t stageType)
|
|
{
|
|
RNG rng = {descriptor->spawnSeed, 5, 9, 7};
|
|
|
|
if (backdropType == BACKDROP_PLANETARIUM)
|
|
{
|
|
uint32_t seed = rng.Next();
|
|
int count = (int)rng.RandomInt(seed % 50 + 1);
|
|
for (int i = 0; i < count; i++) ambient_spawn(*this, EFFECT_WISP, 0);
|
|
return;
|
|
}
|
|
|
|
bool isOdd = rng.Next() & 1;
|
|
bool isDarkBoss = is_curse_active(CURSE_OF_DARKNESS) && (roomType == ROOM_BOSS || roomType == ROOM_MINIBOSS);
|
|
bool isMineshaft = g_game->HasAbandonedMineshaft() && g_game->currentDimensionIdx == 1;
|
|
if (isOdd && stageId != STAGE_ID_BLUE_WOMB && roomType != ROOM_SUPERSECRET && !isDarkBoss && stageId != STAGE_ID_DROSS &&
|
|
!isMineshaft)
|
|
return;
|
|
if (bossId == BOSS_MEGA_SATAN || roomType == ROOM_DUNGEON) return;
|
|
|
|
PlayerManager& players = g_game->playerManager;
|
|
bool isMore = players.FirstCollectibleOwner(COLLECTIBLE_INFESTATION, LAZARUS_SHARE_CHECK) ||
|
|
players.FirstCollectibleOwner(COLLECTIBLE_INFESTATION_2, LAZARUS_SHARE_CHECK) ||
|
|
roomType == ROOM_SUPERSECRET || isMineshaft;
|
|
int extra = isMore ? 1 : 0;
|
|
uint32_t flyMax = (extra + 1) * AMBIENT_FLIES;
|
|
int shift = descriptor->gridIndex == g_game->startingRoomIdx ? 1 : 0;
|
|
|
|
int flies = ambient_count(rng, flyMax, shift);
|
|
int dust = ambient_count(rng, (extra + 1) * AMBIENT_DUST, shift);
|
|
int droplets = ambient_count(rng, (extra + 1) * AMBIENT_DROPLETS, 0);
|
|
rng.RandomInt(rng.RandomInt((extra + 2) * AMBIENT_DROPLETS) + 1);
|
|
droplets >>= shift;
|
|
if (backdrop.configs[backdropType].walls == 0) droplets = 0;
|
|
if (effectiveStage == STAGE_BLUE_WOMB) dust = std::max(dust, 5);
|
|
if (stageId == STAGE_ID_DROSS)
|
|
{
|
|
dust *= 2;
|
|
droplets *= 3;
|
|
flies *= 2;
|
|
}
|
|
for (int i = 0; i < flies; i++) ambient_spawn(*this, EFFECT_TINY_BUG, 0);
|
|
for (int i = 0; i < dust; i++) ambient_spawn(*this, EFFECT_TINY_FLY, 0);
|
|
for (int i = 0; i < droplets; i++) entity_spawn(ENTITY_EFFECT, EFFECT_WALL_BUG, g_vectorOne, 0, Random())->Update();
|
|
|
|
bool isBugStage = effectiveStage == 3 || effectiveStage == 4 || effectiveStage == 7 || effectiveStage == 8 ||
|
|
effectiveStage == STAGE_BLUE_WOMB;
|
|
if (isBugStage)
|
|
{
|
|
int bugs = ambient_count(rng, flyMax, shift);
|
|
if (effectiveStage == STAGE_BLUE_WOMB) bugs = std::max(bugs, 5);
|
|
for (int i = 0; i < bugs; i++)
|
|
for (int attempt = 0; attempt < AMBIENT_RETRIES; attempt++)
|
|
{
|
|
Vector position = room_random_point(*this);
|
|
if (GetGridCollision(GetGridIndex(position)) != GRID_COLLISION_NONE) continue;
|
|
entity_spawn(ENTITY_EFFECT, EFFECT_WORM, position, 1, Random())->Update();
|
|
break;
|
|
}
|
|
}
|
|
|
|
bool isRain = false;
|
|
if (effectiveStage == 10)
|
|
{
|
|
if (stageType == STAGETYPE_ORIGINAL)
|
|
{
|
|
int swarms = ambient_count(rng, flyMax, shift);
|
|
for (int i = 0; i < swarms * AMBIENT_RETRIES; i++) ambient_spawn(*this, EFFECT_WORM, 2);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (effectiveStage == 3 || effectiveStage == 5 || effectiveStage == 6)
|
|
{
|
|
int embers = ambient_count(rng, flyMax, shift);
|
|
for (int i = 0; i < embers; i++) ambient_spawn(*this, EFFECT_BEETLE, 0);
|
|
}
|
|
isRain = effectiveStage == 11 && stageType == STAGETYPE_ORIGINAL;
|
|
}
|
|
if (!isRain) isRain = descriptor->data->type == ROOM_SECRET || is_curse_active(CURSE_OF_DARKNESS);
|
|
if (isRain && !(descriptor->flags & ROOM_DESCRIPTOR_FLAG_PITCH_BLACK))
|
|
{
|
|
int drops = ambient_count(rng, extra * 20 + AMBIENT_RAIN, shift);
|
|
for (int i = 0; i < drops; i++) ambient_spawn(*this, EFFECT_WISP, 0);
|
|
}
|
|
|
|
if (stageId != STAGE_ID_DOWNPOUR || waterAmount <= 0) return;
|
|
uint32_t seed = rng.Next();
|
|
int ripples = (int)(rng.RandomInt(seed % 15 + 1) >> shift);
|
|
for (int i = 0; i < ripples; i++)
|
|
{
|
|
Vector position = room_random_point(*this);
|
|
if (!IsPositionInRoom(position, 0) || GetGridCollision(GetGridIndex(position)) >= 2) continue;
|
|
entity_spawn(ENTITY_EFFECT, EFFECT_TADPOLE, position, 0, Random())->Update();
|
|
}
|
|
seed = rng.Next();
|
|
int spawners = (int)(rng.RandomInt((seed & 3) + 1) >> shift);
|
|
for (int i = 0; i < spawners; i++) entity_spawn(ENTITY_EFFECT, EFFECT_LIL_GHOST, g_vectorZero, 0, Random())->Update();
|
|
}
|
|
|
|
// Counts the visit, and scores a first visit for the score sheet: the room type, once per cell of a big shape, at the
|
|
// floor's multiplier.
|
|
void Room::visit_record()
|
|
{
|
|
descriptor->visitedCount++;
|
|
if (descriptor->visitedCount != 1) return;
|
|
|
|
StageVisit visit = {(int)g_game->stage, (int)g_game->stageType, g_game->GetStateFlag(GAME_STATE_BACKWARDS_PATH)};
|
|
float multiplier = g_game->scoreSheet.stage_multiplier_get(visit);
|
|
if (multiplier <= 0) return;
|
|
|
|
RoomScore score = {multiplier, roomType, (descriptor->flags & ROOM_DESCRIPTOR_FLAG_RED_ROOM) != 0};
|
|
int weight = room_shape_weight_get(descriptor->data->shape);
|
|
for (int i = 0; i < weight; i++) g_game->scoreSheet.visitedRooms.push_back(score);
|
|
}
|
|
|
|
// Sets a color's colorize channels.
|
|
static void colorize_set(ColorMod& color, std::array<float, 4> colorize)
|
|
{
|
|
std::copy(colorize.begin(), colorize.end(), color._colorize);
|
|
}
|
|
|
|
// The floor and wall tints: red for a red room (but Ultra Greed's shop) and the ultra secret room, gold on the
|
|
// Ascent, and grey for the pre-items seed's Flooded Caves.
|
|
void Room::init_colors()
|
|
{
|
|
bool isRedRoom = descriptor->flags & ROOM_DESCRIPTOR_FLAG_RED_ROOM && backdropType != BACKDROP_CLOSET_B;
|
|
|
|
if (isRedRoom)
|
|
{
|
|
colorize_set(floorColor, {1, 0, 0, 0.3f});
|
|
colorize_set(wallColor, {1, 0.2f, 0.2f, 0.8f});
|
|
}
|
|
else if (roomType == ROOM_ULTRASECRET)
|
|
{
|
|
colorize_set(floorColor, {1, 0.7f, 0.7f, 0.6f});
|
|
colorize_set(wallColor, {1, 0.4f, 0.4f, 0.6f});
|
|
}
|
|
else if (is_backwards_path())
|
|
{
|
|
floorColor = ASCENT_COLOR;
|
|
wallColor = ASCENT_COLOR;
|
|
}
|
|
else if (backdropType == BACKDROP_FLOODED_CAVES && g_game->seedEffects.HasSeedEffect(SEED_EFFECT_PRE_ITEMS))
|
|
{
|
|
floorColor = GREY_COLOR;
|
|
wallColor = GREY_COLOR;
|
|
}
|
|
if (is_ashpit_rays()) reconstruction_missing("Room::Init 007f2800: Ashpit's light ray textures");
|
|
}
|
|
|
|
// 008242f0 Whether the floor is the Ashpit, whose rooms load light ray textures. The mirror world never is.
|
|
bool Room::is_ashpit_rays()
|
|
{
|
|
if (g_game->challenge == CHALLENGE_RED_REDEMPTION)
|
|
return RoomConfig::GetStageID((int)g_game->stage, g_game->GetRoomStageType(g_game->currentRoomIdx),
|
|
ROOM_MODE_CURRENT) == STAGE_ID_ASHPIT;
|
|
if (g_game->currentDimensionIdx == 2) return false;
|
|
return RoomConfig::GetStageID((int)g_game->stage, (int)g_game->stageType, ROOM_MODE_CURRENT) == STAGE_ID_ASHPIT;
|
|
}
|
|
|
|
// The mineshaft's blue tint, or the super secret room's warm one.
|
|
void Room::init_mineshaft_colors()
|
|
{
|
|
if (g_game->HasAbandonedMineshaft() && g_game->currentDimensionIdx == 1)
|
|
{
|
|
colorize_set(floorColor, {0.9f, 0.8f, 1, floorColor._colorize[3]});
|
|
colorize_set(wallColor, {0.9f, 0.8f, 1, wallColor._colorize[3]});
|
|
}
|
|
else if (roomType == ROOM_SUPERSECRET)
|
|
{
|
|
colorize_set(floorColor, {1, 0.9f, 0.8f, floorColor._colorize[3]});
|
|
colorize_set(wallColor, {1, 0.9f, 0.8f, wallColor._colorize[3]});
|
|
}
|
|
else return;
|
|
wallColor._colorize[3] = 0.5f;
|
|
floorColor._colorize[3] = 0.4f;
|
|
}
|
|
|
|
// 007f20e0 The grid index of a door slot's cell in a room of a shape and size. A slot out of range is the first.
|
|
int room_shape_get_door_grid_index(int doorSlot, int width, int height, int shape)
|
|
{
|
|
int top = 0;
|
|
int bottom = height - 1;
|
|
int left = 0;
|
|
int right = width - 1;
|
|
|
|
if (doorSlot < 0 || doorSlot >= DOOR_SLOT_COUNT) doorSlot = DOOR_LEFT0;
|
|
if (shape >= ROOMSHAPE_LTL && shape <= ROOMSHAPE_LBR)
|
|
for (const DoorCell& door : L_CORNER_DOORS[shape - ROOMSHAPE_LTL])
|
|
if (door.slot == doorSlot) return door.row * width + door.column;
|
|
if (shape == ROOMSHAPE_IH || shape == ROOMSHAPE_IIH)
|
|
{
|
|
top = NARROW_ROW_INSET;
|
|
bottom -= NARROW_ROW_INSET;
|
|
}
|
|
else if (shape == ROOMSHAPE_IV || shape == ROOMSHAPE_IIV)
|
|
{
|
|
left = NARROW_COLUMN_INSET;
|
|
right -= NARROW_COLUMN_INSET;
|
|
}
|
|
|
|
int half = doorSlot >= DOOR_LEFT1 ? 1 : 0;
|
|
switch (doorSlot - half * DOOR_LEFT1)
|
|
{
|
|
case DOOR_UP0: return top * width + DOOR_COLUMNS[half];
|
|
case DOOR_RIGHT0: return DOOR_ROWS[half] * width + right;
|
|
case DOOR_DOWN0: return bottom * width + DOOR_COLUMNS[half];
|
|
default: return DOOR_ROWS[half] * width + left;
|
|
}
|
|
}
|
|
|
|
// Collects Lua's garbage after a room loads and logs what it still uses.
|
|
static void lua_garbage_collect()
|
|
{
|
|
lua_State* state = static_cast<LuaEngine*>(g_luaEngine)->state;
|
|
|
|
lua_gc(state, LUA_GCCOLLECT, 0);
|
|
int bytes = lua_gc(state, LUA_GCCOUNTB, 0);
|
|
int kilobytes = lua_gc(state, LUA_GCCOUNT, 0);
|
|
std::string log = "Lua mem usage: " + std::to_string(kilobytes) + " KB and " + std::to_string(bytes) + " bytes\n";
|
|
KAGE_LogMessage(LOG_INFO, (uint8_t*)log.c_str());
|
|
}
|
|
|
|
// 00428a50 The room's entity list.
|
|
EntityList* Room::GetEntities()
|
|
{
|
|
return &entityList;
|
|
}
|
|
|
|
// 0042a270 The layout's shape, or 1x1 without one.
|
|
int Room::GetRoomShape()
|
|
{
|
|
return descriptor && descriptor->data ? descriptor->data->shape : ROOMSHAPE_1x1;
|
|
}
|
|
|
|
// 004566a0 How many cells the grid has.
|
|
int Room::GetGridSize()
|
|
{
|
|
return gridHeight * gridWidth;
|
|
}
|
|
|
|
// 00436060 The grid entity on a cell, or none past the grid.
|
|
GridEntity* Room::GetGridEntity(uint32_t gridIndex)
|
|
{
|
|
return gridIndex < ROOM_GRID_CELLS ? gridEntities[gridIndex] : nullptr;
|
|
}
|
|
|
|
// 00436020 The door in a slot, or none past the slots. The original's check lets slot 8 read past them. It is none.
|
|
GridEntity_Door* Room::GetDoor(int slot)
|
|
{
|
|
return slot >= 0 && slot < DOOR_SLOT_COUNT ? doors[slot] : nullptr;
|
|
}
|
|
|
|
// 004565c0 A cell's grid path, or 0 past the grid.
|
|
int Room::GetGridPath(int gridIndex)
|
|
{
|
|
return (uint32_t)gridIndex < ROOM_GRID_CELLS ? gridPaths[gridIndex] : 0;
|
|
}
|
|
|
|
// 0042a290 Sets a cell's grid path, unless past the grid.
|
|
bool Room::SetGridPath(int gridIndex, int value)
|
|
{
|
|
if ((uint32_t)gridIndex >= ROOM_GRID_CELLS) return false;
|
|
gridPaths[gridIndex] = value;
|
|
return true;
|
|
}
|
|
|
|
// 00812c90 The cell a world position falls on, or -1 off the grid.
|
|
int Room::GetGridIndex(Vector position)
|
|
{
|
|
int column = (int)((position.x - GRID_ORIGIN_X) / GRID_CELL_SIZE + 0.5f);
|
|
int row = (int)((position.y - GRID_ORIGIN_Y) / GRID_CELL_SIZE + 0.5f);
|
|
return GetGridIndexByTile(column, row);
|
|
}
|
|
|
|
// 00812e60 The cell at a column and row, or -1 off the grid.
|
|
int Room::GetGridIndexByTile(int column, int row)
|
|
{
|
|
if (column < 0 || column >= gridWidth || row < 0 || row >= gridHeight) return -1;
|
|
return gridWidth * row + column;
|
|
}
|
|
|
|
// 00812f00 A cell's center in the world.
|
|
Vector Room::GetGridPosition(int gridIndex)
|
|
{
|
|
return vector_make((float)(gridIndex % gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_X,
|
|
(float)(gridIndex / gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_Y);
|
|
}
|
|
|
|
// 00436090 A position kept a margin inside the room's floor.
|
|
Vector Room::GetClampedPosition(Vector position, float margin)
|
|
{
|
|
return GetClampedPositionImpl(position, margin, margin, margin, margin);
|
|
}
|
|
|
|
// 0081fb20 The floor cells the room's shape lays out.
|
|
LRoomTileDesc Room::GetLRoomTileDesc()
|
|
{
|
|
return SHAPE_TILES[descriptor->data->shape];
|
|
}
|
|
|
|
// 0081f8b0 An L-shaped room's two floor rectangles in the world, or the room's rectangle twice.
|
|
LRoomAreaDesc Room::GetLRoomAreaDesc()
|
|
{
|
|
if (!IsLShapedRoom()) return {topLeftPos, bottomRightPos, topLeftPos, bottomRightPos};
|
|
|
|
LRoomTileDesc tiles = GetLRoomTileDesc();
|
|
float half = GRID_CELL_SIZE / 2;
|
|
Vector topLeftA = GetGridPosition(GetGridIndexByTile(tiles.topLeftAX, tiles.topLeftAY));
|
|
Vector bottomRightA = GetGridPosition(GetGridIndexByTile(tiles.bottomRightAX, tiles.bottomRightAY));
|
|
Vector topLeftB = GetGridPosition(GetGridIndexByTile(tiles.topLeftBX, tiles.topLeftBY));
|
|
Vector bottomRightB = GetGridPosition(GetGridIndexByTile(tiles.bottomRightBX, tiles.bottomRightBY));
|
|
|
|
return {vector_make(topLeftA.x - half, topLeftA.y - half), vector_make(bottomRightA.x + half, bottomRightA.y + half),
|
|
vector_make(topLeftB.x - half, topLeftB.y - half), vector_make(bottomRightB.x + half, bottomRightB.y + half)};
|
|
}
|
|
|
|
// 00812f50 A position kept inside the room's floor by a margin on each side. An L-shaped room pushes a position in
|
|
// its missing corner out along the nearer edge.
|
|
Vector Room::GetClampedPositionImpl(Vector position, float marginTop, float marginRight, float marginBottom,
|
|
float marginLeft)
|
|
{
|
|
if (!descriptor || !descriptor->data) return position;
|
|
|
|
float x = std::min(std::max(position.x, marginLeft + topLeftPos.x), bottomRightPos.x - marginRight);
|
|
float y = std::min(std::max(position.y, marginTop + topLeftPos.y), bottomRightPos.y - marginBottom);
|
|
if (!IsLShapedRoom()) return vector_make(x, y);
|
|
|
|
LRoomAreaDesc area = GetLRoomAreaDesc();
|
|
float leftA = area.topLeftA.x + marginLeft;
|
|
float rightA = area.bottomRightA.x - marginRight;
|
|
float leftB = area.topLeftB.x + marginLeft;
|
|
float rightB = area.bottomRightB.x - marginRight;
|
|
float notchY = rightB - leftB <= rightA - leftA ? area.bottomRightA.y - marginBottom : area.topLeftB.y + marginTop;
|
|
|
|
switch (descriptor->data->shape)
|
|
{
|
|
case ROOMSHAPE_LTL:
|
|
if (leftA <= x || notchY <= y) return vector_make(x, y);
|
|
return leftA - x < notchY - y ? vector_make(leftA, y) : vector_make(x, notchY);
|
|
case ROOMSHAPE_LTR:
|
|
if (x <= rightA || notchY <= y) return vector_make(x, y);
|
|
return x - rightA < notchY - y ? vector_make(rightA, y) : vector_make(x, notchY);
|
|
case ROOMSHAPE_LBL:
|
|
if (leftB <= x || y <= notchY) return vector_make(x, y);
|
|
return leftB - x < y - notchY ? vector_make(leftB, y) : vector_make(x, notchY);
|
|
default:
|
|
if (x <= rightB || y <= notchY) return vector_make(x, y);
|
|
return x - rightB < y - notchY ? vector_make(rightB, y) : vector_make(x, notchY);
|
|
}
|
|
}
|
|
|
|
// 00812d00 The room's center: its rectangle's, or for an L shape the middle of its bigger arm.
|
|
Vector Room::GetCenterPos()
|
|
{
|
|
Room& room = *g_game->room;
|
|
int centerIndex = -1;
|
|
|
|
switch (room.descriptor->data->shape)
|
|
{
|
|
case ROOMSHAPE_LTL:
|
|
centerIndex = 0x148;
|
|
break;
|
|
case ROOMSHAPE_LTR:
|
|
centerIndex = 0x13b;
|
|
break;
|
|
case ROOMSHAPE_LBL:
|
|
centerIndex = 0x84;
|
|
break;
|
|
case ROOMSHAPE_LBR:
|
|
centerIndex = 0x77;
|
|
break;
|
|
default:
|
|
return vector_make((room.bottomRightPos.x - room.topLeftPos.x) * 0.5f + room.topLeftPos.x,
|
|
(room.bottomRightPos.y - room.topLeftPos.y) * 0.5f + room.topLeftPos.y);
|
|
}
|
|
return room.GetGridPosition(centerIndex);
|
|
}
|
|
|
|
// 0081e9d0 A random position on the floor a margin inside it.
|
|
Vector Room::GetRandomPosition(float margin)
|
|
{
|
|
if (!IsLShapedRoom())
|
|
{
|
|
float x = random_unit();
|
|
float y = random_unit();
|
|
Vector position = vector_make((bottomRightPos.x - topLeftPos.x) * x + topLeftPos.x,
|
|
(bottomRightPos.y - topLeftPos.y) * y + topLeftPos.y);
|
|
return GetClampedPositionImpl(position, margin, margin, margin, margin);
|
|
}
|
|
reconstruction_missing("Room::GetRandomPosition 0081e9d0: L-shaped rooms");
|
|
}
|
|
|
|
// 0081ecc0 A random floor cell from a seed. L-shaped rooms are not reconstructed yet.
|
|
int Room::GetRandomTileIndex(uint32_t seed)
|
|
{
|
|
if (IsLShapedRoom()) reconstruction_missing("Room::GetRandomTileIndex 0081ecc0: L-shaped rooms (LRoomTileDesc)");
|
|
|
|
LRoomTileDesc tiles = GetLRoomTileDesc();
|
|
RNG rng = {seed, 1, 9, 29};
|
|
int column = (int)rng.RandomInt(tiles.bottomRightAX - tiles.topLeftAX) + tiles.topLeftAX;
|
|
int row = (int)rng.RandomInt(tiles.bottomRightAY - tiles.topLeftAY) + tiles.topLeftAY;
|
|
return GetGridIndexByTile(column, row);
|
|
}
|
|
|
|
// 00813360 Whether a position lies on the floor a margin inside it.
|
|
bool Room::IsPositionInRoom(Vector position, float margin)
|
|
{
|
|
if (IsLShapedRoom())
|
|
{
|
|
Vector clamped = GetClampedPositionImpl(position, margin, margin, margin, margin);
|
|
return clamped.x == position.x && clamped.y == position.y;
|
|
}
|
|
return margin + topLeftPos.x <= position.x && position.x <= bottomRightPos.x - margin &&
|
|
margin + topLeftPos.y <= position.y && position.y <= bottomRightPos.y - margin;
|
|
}
|
|
|
|
// 007f0800 What a cell blocks (Lua's GridCollisionClass): its grid entity's class, or a pit or nothing by the path
|
|
// left on it. Off the grid is wall, and the Beast's arena blocks nothing.
|
|
uint32_t Room::GetGridCollision(int gridIndex)
|
|
{
|
|
if (IsBeastDungeon()) return GRID_COLLISION_NONE;
|
|
if (gridIndex < 0) return GRID_COLLISION_WALL;
|
|
if (gridEntities[gridIndex]) return (uint32_t)gridEntities[gridIndex]->collisionClass;
|
|
|
|
int path = gridPaths[gridIndex];
|
|
if (path < GRID_PATH_UNIT) return GRID_COLLISION_NONE;
|
|
if (path >= GRID_PATH_PIT && path <= GRID_PATH_PIT_LAST) return GRID_COLLISION_PIT;
|
|
return GRID_COLLISION_SOLID;
|
|
}
|
|
|
|
// 00436050 The descriptor's spawn seed, or 0 without one.
|
|
uint32_t Room::GetSpawnSeed()
|
|
{
|
|
return descriptor ? descriptor->spawnSeed : 0;
|
|
}
|
|
|
|
// 004aae80 The descriptor's decoration seed, or 0 without one.
|
|
uint32_t Room::GetDecorationSeed()
|
|
{
|
|
return descriptor ? descriptor->decorationSeed : 0;
|
|
}
|
|
|
|
// 0085e100 The descriptor's award seed, or 0 without one.
|
|
uint32_t Room::GetAwardSeed()
|
|
{
|
|
return descriptor ? descriptor->awardSeed : 0;
|
|
}
|
|
|
|
// 007537e0 The descriptor's distance from Delirium, or 0 without one.
|
|
int Room::GetDeliriumDistance()
|
|
{
|
|
return descriptor ? descriptor->deliriumDistance : 0;
|
|
}
|
|
|
|
// 007eece0 The stage id of the layout, or the special rooms' (0) without one.
|
|
int Room::GetRoomConfigStage()
|
|
{
|
|
if (descriptor && descriptor->data) return descriptor->data->stageId;
|
|
KAGE_LogMessage(LOG_WARN, (uint8_t*)"Room stage config is missing, returning a default one (SPECIAL)!\n");
|
|
return 0;
|
|
}
|
|
|
|
// 006b8410 Whether the layout has any of a mask's flags.
|
|
bool Room::has_room_config_flag(uint32_t mask)
|
|
{
|
|
return descriptor && descriptor->data && (descriptor->data->flags & mask) != 0;
|
|
}
|
|
|
|
// 00436080 Whether the room is cleared.
|
|
bool Room::IsClear()
|
|
{
|
|
return descriptor->flags & ROOM_DESCRIPTOR_FLAG_CLEAR;
|
|
}
|
|
|
|
// 004aae90 Marks the room cleared or not.
|
|
void Room::SetClear(bool isClear)
|
|
{
|
|
uint32_t& flags = descriptor->flags;
|
|
flags = isClear ? flags | ROOM_DESCRIPTOR_FLAG_CLEAR : flags & ~ROOM_DESCRIPTOR_FLAG_CLEAR;
|
|
}
|
|
|
|
// 005cd650 Whether the sacrifice room paid out.
|
|
bool Room::IsSacrificeDone()
|
|
{
|
|
return descriptor->flags & ROOM_DESCRIPTOR_FLAG_SACRIFICE_DONE;
|
|
}
|
|
|
|
// 004aaeb0 Marks the sacrifice room paid out or not.
|
|
void Room::SetSacrificeDone(bool isDone)
|
|
{
|
|
uint32_t& flags = descriptor->flags;
|
|
flags = isDone ? flags | ROOM_DESCRIPTOR_FLAG_SACRIFICE_DONE : flags & ~ROOM_DESCRIPTOR_FLAG_SACRIFICE_DONE;
|
|
}
|
|
|
|
// 0070c560 Whether the challenge room's ambush is done.
|
|
bool Room::IsAmbushDone()
|
|
{
|
|
return descriptor->flags & ROOM_DESCRIPTOR_FLAG_CHALLENGE_DONE;
|
|
}
|
|
|
|
// 008332c0 Marks the challenge room's ambush done or not.
|
|
void Room::SetAmbushDone(bool isDone)
|
|
{
|
|
uint32_t& flags = descriptor->flags;
|
|
flags = isDone ? flags | ROOM_DESCRIPTOR_FLAG_CHALLENGE_DONE : flags & ~ROOM_DESCRIPTOR_FLAG_CHALLENGE_DONE;
|
|
}
|
|
|
|
// 00505c40 Whether the room's pits are water.
|
|
bool Room::HasWaterPits()
|
|
{
|
|
return descriptor->flags & ROOM_DESCRIPTOR_FLAG_HAS_WATER;
|
|
}
|
|
|
|
// 0059e250 Whether the layout allows a door in a slot.
|
|
bool Room::IsDoorSlotAllowed(int slot)
|
|
{
|
|
return (uint32_t)slot < DOOR_SLOT_COUNT && (descriptor->data->doors & 1u << slot) != 0;
|
|
}
|
|
|
|
// 004566b0 The enemies alive, never below 0.
|
|
int Room::GetAliveEnemiesCount()
|
|
{
|
|
return std::max(entityList.enemyCount + entityList.pendingEnemyCount, 0);
|
|
}
|
|
|
|
// 004566d0 The bosses alive, never below 0.
|
|
int Room::GetAliveBossesCount()
|
|
{
|
|
return std::max(entityList.bossCount + entityList.pendingBossCount, 0);
|
|
}
|
|
|
|
// 00456710 Whether the room is slowed down.
|
|
bool Room::HasSlowDown()
|
|
{
|
|
return slowdownDuration > 0;
|
|
}
|
|
|
|
// 00456720 Slows the room down for at least a duration.
|
|
void Room::SetSlowDown(int duration)
|
|
{
|
|
slowdownDuration = std::max(duration, slowdownDuration);
|
|
}
|
|
|
|
// 00813ce0 How many frames since the room was entered, or -1 before it is initialized.
|
|
int Room::GetFrameCount()
|
|
{
|
|
return isInitialized ? g_game->frameCount - enterFrame : -1;
|
|
}
|
|
|
|
// 0081f890 Whether the layout is one of the four L shapes.
|
|
bool Room::IsLShapedRoom()
|
|
{
|
|
return (uint32_t)(descriptor->data->shape - ROOMSHAPE_LTL) < 4;
|
|
}
|
|
|
|
// 008279a0 Whether the room is the Beast's arena, the Home floor's dungeon.
|
|
bool Room::IsBeastDungeon()
|
|
{
|
|
RoomConfig_Room* data = descriptor->data;
|
|
return data && data->type == ROOM_DUNGEON && data->stageId == STAGE_ID_HOME;
|
|
}
|
|
|
|
// 00827b70 Whether the players are in the mirror world: the second floor of the alternate path's second dimension,
|
|
// or the first floor's under the Curse of the Labyrinth.
|
|
bool Room::IsMirrorWorld()
|
|
{
|
|
bool isAltStage = g_game->stageType == STAGETYPE_REPENTANCE || g_game->stageType == STAGETYPE_REPENTANCE_B;
|
|
if (g_game->currentDimensionIdx != 1 || !isAltStage) return false;
|
|
return g_game->stage == 2 || (g_game->stage == 1 && g_game->GetCurses() & CURSE_OF_LABYRINTH);
|
|
}
|
|
|
|
// 00827bb0 Whether the room has the cursed mist.
|
|
bool Room::HasCurseMist()
|
|
{
|
|
return descriptor->flags & ROOM_DESCRIPTOR_FLAG_CURSED_MIST;
|
|
}
|
|
|
|
// 008208c0 Whether the room shows water.
|
|
bool Room::HasWater()
|
|
{
|
|
return waterAmount > 0;
|
|
}
|
|
|
|
// 008242d0 Whether the room's pits are lava: the Mines backdrop's water pits.
|
|
bool Room::HasLava()
|
|
{
|
|
return backdropType == BACKDROP_MINES && descriptor->flags & ROOM_DESCRIPTOR_FLAG_HAS_WATER;
|
|
}
|
|
|
|
// 008208e0 Whether the players are in the floor's last boss room.
|
|
bool Room::IsCurrentRoomLastBoss()
|
|
{
|
|
return g_game->GetRoomByIdx(g_game->currentRoomIdx)->listIndex == g_game->lastBossRoomListIdx;
|
|
}
|
|
|
|
// 007ea260 Pauses the enemies (and versus players, slots and effects) for a duration.
|
|
void Room::SetPauseTimer(int duration)
|
|
{
|
|
for (Entity* entity : entityList.updateEL)
|
|
{
|
|
bool isVersusPlayer = g_game->deathmatchManager.state >= DEATHMATCH_INTRO && entity->type == ENTITY_PLAYER;
|
|
bool isEnemy = entity->type - 10u < 0x3de;
|
|
if (isVersusPlayer || isEnemy || entity->type == ENTITY_PROJECTILE || entity->type == ENTITY_EFFECT) entity->pauseTimer = duration;
|
|
}
|
|
}
|
|
|
|
// 0081edd0 The Broken Watch's state, always fast in SPEED!.
|
|
BrokenWatchState Room::GetBrokenWatchState()
|
|
{
|
|
return g_game->challenge == CHALLENGE_SPEED ? BROKEN_WATCH_FAST : brokenWatchState;
|
|
}
|
|
|
|
// 0081edf0 Sets the Broken Watch's state and the music's pitch to the time scale.
|
|
void Room::SetBrokenWatchState(BrokenWatchState state)
|
|
{
|
|
brokenWatchState = state;
|
|
g_manager->musicManager.targetPitch = time_scale_update();
|
|
}
|
|
|
|
// 007ea2d0 How fast time runs in the room: eased down by the time slowing effect, slowed by the watches and their
|
|
// effects, sped up by the Broken Watch and SPEED!, plus a tenth per G-Fuel past the first.
|
|
float Room::time_scale_update()
|
|
{
|
|
float timeScale = 1;
|
|
|
|
if (TemporaryEffect* astral = temporaryEffects.GetCollectibleEffect(COLLECTIBLE_ASTRAL_PROJECTION))
|
|
{
|
|
float ease = std::clamp(((float)astral->cooldown - 0) / TIME_SCALE_EASE_FRAMES, 0.0f, 1.0f);
|
|
timeScale = std::max(1 - ease * TIME_SCALE_EASE_DEPTH, TIME_SCALE_EASE_MIN);
|
|
}
|
|
else if (temporaryEffects.HasCollectibleEffect(COLLECTIBLE_STOP_WATCH) ||
|
|
temporaryEffects.HasCollectibleEffect(COLLECTIBLE_HOURGLASS))
|
|
timeScale = TIME_SCALE_SLOW;
|
|
else if (g_game->challenge == CHALLENGE_SPEED || brokenWatchState == BROKEN_WATCH_FAST) timeScale = TIME_SCALE_FAST;
|
|
else if (brokenWatchState == BROKEN_WATCH_SLOW) timeScale = TIME_SCALE_SLOW;
|
|
else if (g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_STOP_WATCH, LAZARUS_SHARE_CHECK))
|
|
timeScale = TIME_SCALE_STOP_WATCH;
|
|
|
|
int extraGFuel = std::max(g_game->playerManager.GetGFuelCount() - 1, 0);
|
|
return (float)extraGFuel * TIME_SCALE_PER_GFUEL + timeScale;
|
|
}
|
|
|
|
// 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()
|
|
{
|
|
if (g_game->stageType == STAGETYPE_REPENTANCE || g_game->stageType == STAGETYPE_REPENTANCE_B) return MUSIC_BOSS3;
|
|
return descriptor->flags & ROOM_DESCRIPTOR_FLAG_ALT_BOSS_MUSIC ? MUSIC_BOSS2 : MUSIC_BOSS;
|
|
}
|
|
|
|
// Crossfades to a track, or plays it at the music volume at once.
|
|
static void music_switch(int music, float crossfade)
|
|
{
|
|
MusicManager& musicManager = g_manager->musicManager;
|
|
|
|
if (crossfade < MUSIC_CROSSFADE_INSTANT) musicManager.Crossfade(music, crossfade);
|
|
else musicManager.Play(music, g_manager->optionsConfig.musicVolume);
|
|
}
|
|
|
|
// The track a room plays by its type, boss and state, or the stage's own, and the jingle a first treasure room
|
|
// plays. The dark closet's Dogma track starts at once.
|
|
static int room_music_get(Room& room, uint32_t stage, uint32_t stageType, int stageId, int& jingle, float& crossfade)
|
|
{
|
|
uint32_t flags = room.descriptor->flags;
|
|
RoomConfig_Room* data = room.descriptor->data;
|
|
int stageMusic = g_game->roomConfig.stages[stageId].musicId;
|
|
|
|
if (room.roomType == ROOM_BOSS)
|
|
{
|
|
if (flags & ROOM_DESCRIPTOR_FLAG_CLEAR) return MUSIC_BOSS_OVER;
|
|
switch (room.bossId)
|
|
{
|
|
case BOSS_MOM:
|
|
return MUSIC_MOM_BOSS;
|
|
case 8:
|
|
case 25:
|
|
return MUSIC_MOMS_HEART_BOSS;
|
|
case BOSS_SATAN:
|
|
case BOSS_MEGA_SATAN:
|
|
return MUSIC_DEVIL_ROOM;
|
|
case BOSS_ISAAC:
|
|
return MUSIC_ISAAC_BOSS;
|
|
case 40:
|
|
case 63:
|
|
return MUSIC_CHEST_BOSS;
|
|
case 54:
|
|
return MUSIC_DARK_ROOM_BOSS;
|
|
case BOSS_ULTRA_GREED:
|
|
return MUSIC_ULTRA_GREED_BOSS;
|
|
case 70:
|
|
return MUSIC_VOID_BOSS;
|
|
case 88:
|
|
return MUSIC_MOTHER_BOSS;
|
|
default:
|
|
return room.boss_music_get();
|
|
}
|
|
}
|
|
if (room.roomType == ROOM_MINIBOSS || g_game->room->isSurpriseMiniboss)
|
|
return flags & ROOM_DESCRIPTOR_FLAG_CLEAR ? MUSIC_BOSS_OVER : MUSIC_CHALLENGE_FIGHT;
|
|
|
|
switch (room.roomType)
|
|
{
|
|
case ROOM_SHOP:
|
|
return MUSIC_SHOP_ROOM;
|
|
case ROOM_LIBRARY:
|
|
return MUSIC_LIBRARY_ROOM;
|
|
case ROOM_ANGEL:
|
|
return MUSIC_ANGEL_ROOM;
|
|
case ROOM_ARCADE:
|
|
return MUSIC_ARCADE_ROOM;
|
|
case ROOM_DEVIL:
|
|
return MUSIC_DEVIL_ROOM;
|
|
case ROOM_SECRET:
|
|
return MUSIC_SECRET_ROOM;
|
|
case ROOM_SUPERSECRET:
|
|
return MUSIC_SECRET_ROOM_ALT;
|
|
case ROOM_ULTRASECRET:
|
|
return MUSIC_SECRET_ROOM_ALT_ALT;
|
|
case ROOM_SECRET_EXIT:
|
|
return MUSIC_BOSS_OVER;
|
|
case ROOM_CHALLENGE:
|
|
if (flags & ROOM_DESCRIPTOR_FLAG_CHALLENGE_DONE) return MUSIC_BOSS_OVER;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (g_game->currentRoomIdx == ROOM_GIDEON_DUNGEON_IDX) return MUSIC_BOSS_OVER;
|
|
if (room.roomType == ROOM_PLANETARIUM) return MUSIC_PLANETARIUM;
|
|
if (room.roomType == ROOM_DUNGEON && data && data->subtype == DUNGEON_BEAST) return MUSIC_BEAST_BOSS;
|
|
if (stage == STAGE_HOME && stageType == STAGETYPE_WOTL)
|
|
{
|
|
if ((flags & (ROOM_DESCRIPTOR_FLAG_CLEAR | ROOM_DESCRIPTOR_FLAG_SACRIFICE_DONE)) != ROOM_DESCRIPTOR_FLAG_SACRIFICE_DONE)
|
|
return stageMusic;
|
|
crossfade = MUSIC_CROSSFADE_INSTANT;
|
|
return MUSIC_DOGMA_BOSS;
|
|
}
|
|
if (room.roomType == ROOM_DUNGEON && data && (data->subtype == DUNGEON_ROTGUT || data->subtype == DUNGEON_ROTGUT_HEART))
|
|
return room.boss_music_get();
|
|
if (room.roomType == ROOM_TREASURE && room.isFirstVisit)
|
|
jingle = (int)(Random() & (TREASURE_JINGLE_COUNT - 1)) + MUSIC_TREASURE_JINGLE_FIRST;
|
|
return stageMusic;
|
|
}
|
|
|
|
// 007eb1b0 Plays the room's track, crossfading from the last one (slowly between Downpour and its reversed track,
|
|
// at once out of the Beast's), and a treasure room's jingle. Floors and dimensions override
|
|
// it: the Blue Womb's own music, the Mausoleum heart's, the death certificate's, the mirror world, the mineshaft and
|
|
// the Ascent. While the game's start jingle plays, the track only queues.
|
|
void Room::PlayMusic()
|
|
{
|
|
uint32_t stage = g_game->stage;
|
|
uint32_t stageType = g_game->stageType;
|
|
|
|
if (g_game->challenge == CHALLENGE_RED_REDEMPTION) stageType = (uint32_t)g_game->GetRoomStageType(g_game->currentRoomIdx);
|
|
if (g_game->challenge == CHALLENGE_DELETE_THIS)
|
|
reconstruction_missing("Room::PlayMusic 007eb1b0: DELETE THIS's random stage music");
|
|
|
|
int jingle = 0;
|
|
float crossfade = MUSIC_CROSSFADE;
|
|
int stageId = RoomConfig::GetStageID((int)stage, (int)stageType, ROOM_MODE_CURRENT);
|
|
int music = room_music_get(*this, stage, stageType, stageId, jingle, crossfade);
|
|
|
|
if (!is_greed() && stage == STAGE_BLUE_WOMB && roomType != ROOM_BOSS)
|
|
{
|
|
music = g_game->roomConfig.stages[stageId].musicId;
|
|
jingle = 0;
|
|
}
|
|
if (g_game->IsMausoleumHeartStage())
|
|
{
|
|
bool isHeartRoom = g_game->currentRoomIdx == ROOM_SECRET_EXIT_IDX;
|
|
if (!isHeartRoom) crossfade = MUSIC_CROSSFADE_INSTANT;
|
|
music = isHeartRoom ? MUSIC_NULL : MUSIC_BOSS_OVER_TWISTED;
|
|
jingle = 0;
|
|
}
|
|
|
|
bool isBossArena = roomType == ROOM_BOSS || roomType == ROOM_MINIBOSS || g_game->room->isSurpriseMiniboss;
|
|
if (g_game->currentDimensionIdx == 2)
|
|
{
|
|
music = MUSIC_ECHOES_REVERSE;
|
|
jingle = 0;
|
|
}
|
|
else if (g_game->HasMirrorDimension() && g_game->currentDimensionIdx == 1 && !isBossArena)
|
|
{
|
|
music = MUSIC_DOWNPOUR_REVERSED + (stageId == STAGE_ID_DROSS ? 1 : 0);
|
|
jingle = 0;
|
|
}
|
|
else if (g_game->HasAbandonedMineshaft() && g_game->currentDimensionIdx == 1)
|
|
{
|
|
jingle = 0;
|
|
music = MUSIC_ABANDONED_MINESHAFT + (g_game->levelStateFlags & LEVEL_STATE_MINESHAFT_ESCAPE ? 1 : 0);
|
|
}
|
|
else if (g_game->stage >= 1 && g_game->stage <= 6 && g_game->GetStateFlag(GAME_STATE_BACKWARDS_PATH))
|
|
{
|
|
music = MUSIC_REVERSE_GENESIS;
|
|
jingle = 0;
|
|
}
|
|
|
|
MusicManager& musicManager = g_manager->musicManager;
|
|
int current = musicManager.currentMusicId;
|
|
int queued = musicManager.queuedMusicId != 0 ? musicManager.queuedMusicId : current;
|
|
bool isDownpourSwap = (current == MUSIC_DOWNPOUR && music == MUSIC_DOWNPOUR_REVERSED) ||
|
|
(current == MUSIC_DOWNPOUR_REVERSED && music == MUSIC_DOWNPOUR);
|
|
|
|
if (isDownpourSwap) crossfade = MUSIC_CROSSFADE_ASCENT;
|
|
else if (current == MUSIC_HUSH_TRANSITION) crossfade = MUSIC_CROSSFADE_REVERSE;
|
|
else if (current == MUSIC_BEAST_BOSS) crossfade = MUSIC_CROSSFADE_INSTANT;
|
|
else if (current == MUSIC_GAME_START_JINGLE || current == MUSIC_REVERSE_GENESIS_START)
|
|
{
|
|
if (musicManager.is_music_id_valid(music)) musicManager.queuedMusicId = music;
|
|
musicManager.targetPitch = time_scale_update();
|
|
return;
|
|
}
|
|
|
|
bool isChange = (queued == 0 && current != music) || queued != music;
|
|
if (jingle != 0)
|
|
{
|
|
musicManager.PlayJingle(jingle);
|
|
if (music != 0 && isChange) music_switch(music, crossfade);
|
|
}
|
|
else if (isChange)
|
|
{
|
|
if (music == 0)
|
|
{
|
|
musicManager.channels[musicManager.currentChannel].targetVolume = 0;
|
|
musicManager.channels[musicManager.currentChannel].fadeRate = MUSIC_CROSSFADE;
|
|
musicManager.queuedMusicId = 0;
|
|
}
|
|
else music_switch(music, crossfade);
|
|
musicManager.jingle.volume = 0;
|
|
musicManager.jingleTimer = JINGLE_TIMER_RESTORE;
|
|
}
|
|
musicManager.targetPitch = time_scale_update();
|
|
}
|
|
|
|
|
|
// The stage of the floor for its deals, an alternate floor counting one deeper.
|
|
static int deal_stage_get_unclamped()
|
|
{
|
|
bool isAltStage = g_game->stageType == STAGETYPE_REPENTANCE || g_game->stageType == STAGETYPE_REPENTANCE_B;
|
|
return (int)g_game->stage + (isAltStage ? 1 : 0);
|
|
}
|
|
|
|
// The stage a deal door last opened on, up to Home.
|
|
static int deal_stage_get()
|
|
{
|
|
return std::clamp(deal_stage_get_unclamped(), 0, STAGE_HOME);
|
|
}
|
|
|
|
// 007f92b0 The chance the floor's last boss room opens a deal door: a base chance raised by the deal items and
|
|
// trinkets, the Satanic Bible's wisps, a bum killed and a shopkeeper killed, more without red heart damage on the
|
|
// floor (or in its boss room) unless Act of Contrition forgives it, cut after a recent deal. None once disabled,
|
|
// certain with Goat Head, Eucharist, Greed's later waves and the surprise miniboss daily.
|
|
float Room::GetDevilRoomChance()
|
|
{
|
|
Game& game = *g_game;
|
|
PlayerManager& players = game.playerManager;
|
|
auto is_owned = [&](int collectible) { return players.FirstCollectibleOwner(collectible, LAZARUS_SHARE_CHECK); };
|
|
float chance = DEAL_CHANCE_BASE;
|
|
|
|
if (is_owned(COLLECTIBLE_PENTAGRAM)) chance = DEAL_CHANCE_PENTAGRAM;
|
|
if (is_owned(COLLECTIBLE_BLACK_CANDLE)) chance += DEAL_CHANCE_BLACK_CANDLE;
|
|
if (players.GetNumCollectibles(COLLECTIBLE_PENTAGRAM) > 1) chance += DEAL_CHANCE_SECOND_PENTAGRAM;
|
|
if (is_owned(COLLECTIBLE_BOOK_OF_BELIAL) || is_owned(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE)) chance += DEAL_CHANCE_BELIAL;
|
|
if (is_owned(COLLECTIBLE_BOOK_OF_REVELATIONS)) chance += DEAL_CHANCE_REVELATIONS;
|
|
if (game.levelStateFlags & 1u << LEVEL_STATE_BUM_KILLED) chance += DEAL_CHANCE_BUM_KILLED;
|
|
|
|
bool isBossRoom = game.lastBossRoomListIdx == game.GetRoomByIdx(game.currentRoomIdx)->listIndex;
|
|
if (!isBossRoom || !game.room->isRedHeartDamaged) chance += DEAL_CHANCE_UNHURT_BOSS;
|
|
else if (is_owned(COLLECTIBLE_ACT_OF_CONTRITION)) chance += DEAL_CHANCE_CONTRITION_BOSS;
|
|
if (!(game.levelStateFlags & 1u << LEVEL_STATE_REDHEART_DAMAGED)) chance += DEAL_CHANCE_UNHURT_FLOOR;
|
|
else if (is_owned(COLLECTIBLE_ACT_OF_CONTRITION)) chance += DEAL_CHANCE_CONTRITION_FLOOR;
|
|
if (game.levelStateFlags & 1u << LEVEL_STATE_SHOPKEEPER_KILLED) chance += DEAL_CHANCE_SHOPKEEPER_KILLED;
|
|
|
|
constexpr float NUMBER_MAGNET_CHANCES[4] = {0, 0.1f, 0.15f, 0.2f};
|
|
constexpr float ROSARY_BEAD_CHANCES[4] = {0, 0, 0.05f, 0.1f};
|
|
if (Entity_Player* owner = players.FirstTrinketOwner(TRINKET_NUMBER_MAGNET))
|
|
if (int multiplier = owner->GetTrinketMultiplier(TRINKET_NUMBER_MAGNET); multiplier >= 1 && multiplier <= 3)
|
|
chance += NUMBER_MAGNET_CHANCES[multiplier];
|
|
if (Entity_Player* owner = players.FirstTrinketOwner(TRINKET_ROSARY_BEAD))
|
|
if (int multiplier = owner->GetTrinketMultiplier(TRINKET_ROSARY_BEAD); multiplier >= 2 && multiplier <= 3)
|
|
chance += ROSARY_BEAD_CHANCES[multiplier];
|
|
if (is_owned(COLLECTIBLE_SAUSAGE)) chance += DEAL_CHANCE_SAUSAGE;
|
|
|
|
int bibleWisps = (int)std::ranges::count_if(game.room->entityList.wispEL,
|
|
[](Entity* wisp) { return wisp->subtype == COLLECTIBLE_SATANIC_BIBLE; });
|
|
chance = (float)bibleWisps * DEAL_CHANCE_PER_WISP + chance;
|
|
if (game.lastDevilRoomStage != 0)
|
|
{
|
|
int sinceDeal = deal_stage_get_unclamped() - game.lastDevilRoomStage;
|
|
if (sinceDeal == 0 || sinceDeal == 1) chance *= DEAL_RECENT_SCALE;
|
|
else if (sinceDeal == 2) chance *= DEAL_LAST_SCALE;
|
|
}
|
|
if (game.isDevilRoomDisabled) chance = 0;
|
|
if (is_owned(COLLECTIBLE_GOAT_HEAD) || temporaryEffects.HasCollectibleEffect(COLLECTIBLE_GOAT_HEAD))
|
|
chance = DEAL_CHANCE_GOAT_HEAD;
|
|
if (game.dailyChallenge._specialDailyId == SPECIAL_DAILY_SURPRISE_MINIBOSS &&
|
|
!(game.gameStateFlags & GAME_STATE_SURPRISE_MINIBOSS_SEEN))
|
|
chance = 1;
|
|
if (is_owned(COLLECTIBLE_EUCHARIST)) chance = 1;
|
|
uint32_t greedDealWave = GREED_DEAL_WAVE + (game.difficulty == DIFFICULTY_GREEDIER ? 1 : 0);
|
|
if (is_greed()) chance = (uint32_t)game.greedModeWave < greedDealWave ? 0 : 1;
|
|
return chance;
|
|
}
|
|
static bool is_narrow_room(Room& room)
|
|
{
|
|
RoomShape shape = room.descriptor->data ? room.descriptor->data->shape : ROOMSHAPE_NULL;
|
|
return shape == ROOMSHAPE_IH || shape == ROOMSHAPE_IV || shape == ROOMSHAPE_IIV || shape == ROOMSHAPE_IIH;
|
|
}
|
|
|
|
static bool is_beast_arena(RoomConfig_Room* config)
|
|
{
|
|
return config && config->type == ROOM_DUNGEON && config->stageId == STAGE_ID_HOME;
|
|
}
|
|
|
|
// 007f2390 The room's bounds in the world, around its first and last floor cells: those of the grid or a narrow
|
|
// room's corridor, or past the columns and rows of them that are only walls and doors. The Beast's arena has fixed
|
|
// bounds wider than its grid.
|
|
void Room::update_bounds(bool isFromGridSize)
|
|
{
|
|
if (is_beast_arena(descriptor->data))
|
|
{
|
|
topLeftPos = vector_make(BEAST_ARENA_LEFT, BEAST_ARENA_TOP);
|
|
bottomRightPos = vector_make(BEAST_ARENA_RIGHT, BEAST_ARENA_BOTTOM);
|
|
return;
|
|
}
|
|
|
|
LRoomTileDesc grid = {1, 1, gridWidth - 2, gridHeight - 2, 1, 1, gridWidth - 2, gridHeight - 2};
|
|
LRoomTileDesc tiles = is_narrow_room(*this) ? GetLRoomTileDesc() : grid;
|
|
int left = tiles.topLeftAX;
|
|
int top = tiles.topLeftAY;
|
|
int right = tiles.bottomRightBX;
|
|
int bottom = tiles.bottomRightBY;
|
|
|
|
if (!isFromGridSize)
|
|
{
|
|
std::vector<bool> isRowWall(gridHeight, true);
|
|
int lastColumn = right;
|
|
int lastRow = bottom;
|
|
|
|
for (int column = left; column <= lastColumn; column++)
|
|
{
|
|
bool isColumnWall = true;
|
|
for (int row = top; row <= lastRow; row++)
|
|
{
|
|
int gridIndex = GetGridIndexByTile(column, row);
|
|
GridEntity* entity = gridIndex >= 0 ? gridEntities[gridIndex] : nullptr;
|
|
if (entity && (entity->type == GRID_WALL || entity->type == GRID_DOOR)) continue;
|
|
|
|
isColumnWall = false;
|
|
isRowWall[row] = false;
|
|
}
|
|
if (!isColumnWall)
|
|
{
|
|
right = lastColumn;
|
|
continue;
|
|
}
|
|
if (column == left) left++;
|
|
if (right == lastColumn) right = column - 1;
|
|
}
|
|
for (int row = top; row <= lastRow; row++)
|
|
{
|
|
if (!isRowWall[row])
|
|
{
|
|
bottom = lastRow;
|
|
continue;
|
|
}
|
|
if (row == top) top++;
|
|
if (bottom == lastRow) bottom = row - 1;
|
|
}
|
|
}
|
|
|
|
float half = GRID_CELL_SIZE / 2;
|
|
Vector topLeft = GetGridPosition(GetGridIndexByTile(left, top));
|
|
Vector bottomRight = GetGridPosition(GetGridIndexByTile(right, bottom));
|
|
topLeftPos = vector_make(topLeft.x - half, topLeft.y - half);
|
|
bottomRightPos = vector_make(bottomRight.x + half, bottomRight.y + half);
|
|
}
|
|
|
|
// The backdrops of the rooms whose type picks their own, by room type, or 0 for the stage's.
|
|
static int backdrop_by_room_type(Room& room)
|
|
{
|
|
RoomConfig_Room& config = *room.descriptor->data;
|
|
|
|
switch (room.roomType)
|
|
{
|
|
case ROOM_SHOP: return g_game->currentRoomIdx == ROOM_SECRET_SHOP_IDX ? BACKDROP_SECRET : BACKDROP_SHOP;
|
|
case ROOM_ERROR: return BACKDROP_ERROR_ROOM;
|
|
case ROOM_SECRET: return BACKDROP_SECRET;
|
|
case ROOM_SUPERSECRET: return config.subtype;
|
|
case ROOM_ARCADE: return BACKDROP_ARCADE;
|
|
case ROOM_CURSE:
|
|
case ROOM_CHALLENGE:
|
|
case ROOM_DEVIL:
|
|
case ROOM_BOSSRUSH:
|
|
case ROOM_BLACK_MARKET: return BACKDROP_SHEOL;
|
|
case ROOM_LIBRARY: return BACKDROP_LIBRARY;
|
|
case ROOM_SACRIFICE: return BACKDROP_SACRIFICE;
|
|
case ROOM_ANGEL: return BACKDROP_CATHEDRAL;
|
|
case ROOM_DUNGEON:
|
|
if (config.subtype == DUNGEON_GIDEON) return BACKDROP_DUNGEON_GIDEON;
|
|
if (config.subtype == DUNGEON_ROTGUT || config.subtype == DUNGEON_ROTGUT_HEART) return BACKDROP_DUNGEON_ROTGUT;
|
|
return config.subtype == DUNGEON_BEAST ? BACKDROP_DUNGEON_BEAST : BACKDROP_DUNGEON;
|
|
case ROOM_ISAACS: return BACKDROP_ISAAC;
|
|
case ROOM_BARREN: return BACKDROP_BARREN;
|
|
case ROOM_CHEST: return BACKDROP_CHEST;
|
|
case ROOM_DICE: return BACKDROP_DICE;
|
|
case ROOM_PLANETARIUM: return BACKDROP_PLANETARIUM;
|
|
case ROOM_SECRET_EXIT:
|
|
if (config.subtype == SECRET_EXIT_DOWNPOUR) return BACKDROP_DOWNPOUR_ENTRANCE;
|
|
return config.subtype == SECRET_EXIT_MAUSOLEUM ? BACKDROP_MAUSOLEUM_ENTRANCE : BACKDROP_SECRET;
|
|
case ROOM_ULTRASECRET: return BACKDROP_HALLWAY;
|
|
default: return 0;
|
|
}
|
|
}
|
|
|
|
// Home's backdrop by its room's subtype: the bedrooms, the hallway, the closet (its red room's B side) and Dogma's.
|
|
static int backdrop_home_get(RoomDescriptor& descriptor)
|
|
{
|
|
int subtype = descriptor.data->subtype;
|
|
|
|
if (subtype == HOME_ISAACS_BEDROOM) return BACKDROP_ISAACS_BEDROOM;
|
|
if (subtype == HOME_MOMS_BEDROOM) return BACKDROP_MOMS_BEDROOM;
|
|
if (subtype > HOME_DOGMA) return descriptor.flags & ROOM_DESCRIPTOR_FLAG_RED_ROOM ? BACKDROP_CLOSET_B : BACKDROP_CLOSET;
|
|
if (subtype == HOME_LIVING_ROOM && descriptor.flags & ROOM_DESCRIPTOR_FLAG_SACRIFICE_DONE) return BACKDROP_DOGMA;
|
|
return subtype == HOME_DOGMA ? BACKDROP_DOGMA : BACKDROP_HALLWAY;
|
|
}
|
|
|
|
// The backdrop of a stage's room: Delete This's random stage, the Void's random backdrop, Home's rooms, Ultra Greed's
|
|
// shop, a devil treasure room, Mom's Heart's room in the Mausoleum, and the stage's own. The stage and stage type the effect
|
|
// layers show change with Delete This and the extra boss room.
|
|
static int backdrop_by_stage(Room& room, int& fxStage, int& stageType)
|
|
{
|
|
Game& game = *g_game;
|
|
RoomDescriptor& descriptor = *room.descriptor;
|
|
int stage = (int)game.stage;
|
|
|
|
if (game.currentRoomIdx == ROOM_EXTRA_BOSS_IDX)
|
|
{
|
|
Level::boss_count_adjust(stage, stageType);
|
|
fxStage = stage;
|
|
}
|
|
if (game.challenge == CHALLENGE_DELETE_THIS)
|
|
{
|
|
RNG rng = {game.dungeonPlacementSeed, 2, 7, 7};
|
|
if ((uint32_t)stage - 1 < DELETE_THIS_STAGES)
|
|
{
|
|
stage = (int)rng.RandomInt(DELETE_THIS_STAGES) + 1;
|
|
fxStage = stage;
|
|
}
|
|
stageType = (int)rng.RandomInt(DELETE_THIS_STAGE_TYPES);
|
|
if (stageType == STAGETYPE_GREEDMODE) stageType = STAGETYPE_REPENTANCE;
|
|
}
|
|
|
|
int stageId = RoomConfig::GetStageID(stage, stageType, ROOM_MODE_CURRENT);
|
|
if (stage == STAGE_THE_VOID && descriptor.data->stageId != 0) stageId = descriptor.data->stageId;
|
|
if (stageId == STAGE_ID_VOID)
|
|
{
|
|
RNG rng = {descriptor.decorationSeed, 1, 21, 20};
|
|
return (int)rng.RandomInt(VOID_BACKDROPS) + 1;
|
|
}
|
|
if (stageId == STAGE_ID_HOME) return backdrop_home_get(descriptor);
|
|
|
|
int backdropId = game.roomConfig.stages[stageId].backdrop;
|
|
bool isGreedBoss = (stageId == STAGE_ID_ULTRA_GREED || stageId == STAGE_ID_ULTRA_GREED_EXIT) &&
|
|
descriptor.data->type == ROOM_BOSS && descriptor.listIndex == game.lastBossRoomListIdx;
|
|
|
|
if (isGreedBoss) backdropId = BACKDROP_GREED_SHOP;
|
|
if (room.roomType == ROOM_TREASURE && descriptor.flags & ROOM_DESCRIPTOR_FLAG_DEVIL_TREASURE) return BACKDROP_SHEOL;
|
|
if (room.roomType == ROOM_BOSS && descriptor.data->subtype == BOSS_MAUSOLEUM_HEART) return BACKDROP_WOMB;
|
|
if (backdropId == BACKDROP_MAUSOLEUM && game.IsMausoleumHeartStage()) return BACKDROP_MAUSOLEUM_HEART;
|
|
return backdropId;
|
|
}
|
|
|
|
// The Mausoleum's and Corpse's variants: Mausoleum's boss rooms, groups and alternates, the Corpse's alternates.
|
|
static int backdrop_variant_get(Room& room, int backdropId)
|
|
{
|
|
RoomDescriptor& descriptor = *room.descriptor;
|
|
bool isEvenSeed = (descriptor.decorationSeed & 1) == 0;
|
|
|
|
if (backdropId == BACKDROP_MAUSOLEUM)
|
|
{
|
|
if (room.bossId == BOSS_VISAGE || room.secondBossId == BOSS_VISAGE) return BACKDROP_MAUSOLEUM4;
|
|
if (descriptor.group >= 1) return BACKDROP_MAUSOLEUM3;
|
|
return isEvenSeed ? BACKDROP_MAUSOLEUM2 : backdropId;
|
|
}
|
|
if (backdropId != BACKDROP_CORPSE) return backdropId;
|
|
if (descriptor.data->type == ROOM_BOSS)
|
|
return descriptor.data->subtype == BOSS_ROTGUT ? BACKDROP_CORPSE2 : backdropId;
|
|
if (descriptor.flags & ROOM_DESCRIPTOR_FLAG_USE_ALTERNATE_BACKDROP) return BACKDROP_CORPSE3;
|
|
return isEvenSeed && descriptor.gridIndex != g_game->startingRoomIdx ? BACKDROP_CORPSE2 : backdropId;
|
|
}
|
|
|
|
// The backdrop of the room: Mega Satan's, the off-map rooms', the room type's or the stage's, then the abandoned
|
|
// mineshaft's and the dark closet dimension's.
|
|
static int backdrop_get(Room& room, int& fxStage, int& stageType)
|
|
{
|
|
Game& game = *g_game;
|
|
int backdropId = 0;
|
|
|
|
if (room.bossId == BOSS_MEGA_SATAN) backdropId = BACKDROP_MEGA_SATAN;
|
|
else if (game.currentRoomIdx == ROOM_BLUE_WOMB_IDX) backdropId = BACKDROP_BLUE_WOMB_PASS;
|
|
else if (game.currentRoomIdx == ROOM_BLUE_ROOM_IDX) backdropId = BACKDROP_BLUE_WOMB;
|
|
else if (game.currentRoomIdx == ROOM_DEATHMATCH_IDX) backdropId = BACKDROP_DEATHMATCH;
|
|
else if (game.currentRoomIdx == ROOM_LIL_PORTAL_IDX) backdropId = BACKDROP_LIL_PORTAL;
|
|
else
|
|
{
|
|
backdropId = backdrop_by_room_type(room);
|
|
bool isOwn = backdropId != 0 || room.roomType == ROOM_SUPERSECRET;
|
|
backdropId = backdrop_variant_get(room, isOwn ? backdropId : backdrop_by_stage(room, fxStage, stageType));
|
|
}
|
|
|
|
if (game.HasAbandonedMineshaft() && game.currentDimensionIdx == 1 &&
|
|
(backdropId == BACKDROP_MINES || backdropId == BACKDROP_ASHPIT))
|
|
return backdropId == BACKDROP_MINES ? BACKDROP_MINES_SHAFT : BACKDROP_ASHPIT_SHAFT;
|
|
if (game.currentDimensionIdx == DIMENSION_DEATH_CERTIFICATE)
|
|
return room.descriptor->data->subtype == DARK_CLOSET_B_SUBTYPE ? BACKDROP_CLOSET_B : BACKDROP_DARK_CLOSET;
|
|
return backdropId;
|
|
}
|
|
|
|
// The stage and stage type a Void room shows the effect layers of: those of the stage its layout comes from.
|
|
static void void_fx_stage_get(int stageId, int& fxStage, int& stageType)
|
|
{
|
|
int stage = 0;
|
|
int type = 0;
|
|
|
|
if (is_greed())
|
|
{
|
|
if (stageId == STAGE_ID_ULTRA_GREED) stage = GREED_STAGE_ULTRA_GREED;
|
|
else if (stageId == STAGE_ID_ULTRA_GREED_EXIT) stage = GREED_STAGE_ULTRA_GREED + 1;
|
|
else if (stageId < STAGE_ID_FIRST_ALT)
|
|
{
|
|
if (stageId > STAGE_ID_LAST_CHAPTER) return;
|
|
stage = (stageId - 1) / 3 + 1;
|
|
type = (stageId - 1) % 3;
|
|
}
|
|
else
|
|
{
|
|
stage = (stageId - STAGE_ID_FIRST_ALT) / 2 + 1;
|
|
type = (stageId - STAGE_ID_FIRST_ALT) % 2 + STAGETYPE_REPENTANCE;
|
|
}
|
|
}
|
|
else if (stageId == 0) return;
|
|
else if (stageId == STAGE_ID_HOME) stage = STAGE_HOME;
|
|
else if (stageId < STAGE_ID_FIRST_ALT)
|
|
{
|
|
if (stageId > STAGE_ID_LAST_CHAPTER)
|
|
{
|
|
if (stageId == STAGE_ID_BLUE_WOMB) stage = STAGE_BLUE_WOMB;
|
|
else if (stageId >= STAGE_ID_SHEOL && stageId <= STAGE_ID_CHEST)
|
|
{
|
|
stage = (stageId - STAGE_ID_SHEOL) / 2 + STAGE_BLUE_WOMB + 1;
|
|
type = (stageId - STAGE_ID_SHEOL) % 2;
|
|
}
|
|
else if (stageId == STAGE_ID_VOID) stage = STAGE_THE_VOID;
|
|
else return;
|
|
}
|
|
else
|
|
{
|
|
stage = (stageId - 1) / 3 * 2 + 1;
|
|
type = (stageId - 1) % 3;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
stage = (stageId - STAGE_ID_FIRST_ALT) / 2 * 2 + 1;
|
|
type = (stageId - STAGE_ID_FIRST_ALT) % 2 + STAGETYPE_REPENTANCE;
|
|
}
|
|
if (stage == 0) return;
|
|
fxStage = stage;
|
|
stageType = type;
|
|
}
|
|
|
|
// The shading image of a room's shape, the Womb's own for the shapes it has one for, or the closet's by its side.
|
|
static std::string_view shading_path_get(Room& room)
|
|
{
|
|
RoomConfig_Room& config = *room.descriptor->data;
|
|
bool isUtero = room.backdrop.backdropId == BACKDROP_UTERO;
|
|
|
|
if (room.backdrop.backdropId == BACKDROP_CLOSET || room.backdrop.backdropId == BACKDROP_CLOSET_B)
|
|
return config.subtype == HOME_CLOSET_LEFT ? "gfx/backdrop/shading_closet_L.png" : "gfx/backdrop/shading_closet_R.png";
|
|
|
|
switch (config.shape)
|
|
{
|
|
case ROOMSHAPE_IH: return "gfx/backdrop/shading_ih.png";
|
|
case ROOMSHAPE_IV: return "gfx/backdrop/shading_iv.png";
|
|
case ROOMSHAPE_1x2: return isUtero ? "gfx/backdrop/shading_1x2_utero.png" : "gfx/backdrop/shading_1x2.png";
|
|
case ROOMSHAPE_IIV: return "gfx/backdrop/shading_iiv.png";
|
|
case ROOMSHAPE_2x1: return isUtero ? "gfx/backdrop/shading_2x1_utero.png" : "gfx/backdrop/shading_2x1.png";
|
|
case ROOMSHAPE_IIH: return "gfx/backdrop/shading_iih.png";
|
|
case ROOMSHAPE_2x2: return isUtero ? "gfx/backdrop/shading_2x2_utero.png" : "gfx/backdrop/shading_2x2.png";
|
|
case ROOMSHAPE_LTL: return "gfx/backdrop/shading_ltl.png";
|
|
case ROOMSHAPE_LTR: return "gfx/backdrop/shading_ltr.png";
|
|
case ROOMSHAPE_LBL: return "gfx/backdrop/shading_lbl.png";
|
|
case ROOMSHAPE_LBR: return "gfx/backdrop/shading_lbr.png";
|
|
default: return isUtero ? "gfx/backdrop/shading_utero.png" : "gfx/backdrop/shading.png";
|
|
}
|
|
}
|
|
|
|
// Loads the shading of a backdrop with walls and no full image, and draws it once into the shading surface.
|
|
static void shading_load(Room& room)
|
|
{
|
|
BackdropConfig& config = room.backdrop.configs[room.backdrop.backdropId];
|
|
|
|
roomSurfaces.shading.reset();
|
|
if (!config.isFullImage && config.walls > 0) roomSurfaces.shading = Manager::LoadImage(shading_path_get(room));
|
|
if (!roomSurfaces.shading) return;
|
|
|
|
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
|
graphics.render_target_push(roomSurfaces.shadingSurface.get(), KAGE::Graphics::TARGET_OWN_SIZE,
|
|
KAGE::Graphics::PRESENT_FLUSH);
|
|
graphics.Clear();
|
|
roomSurfaces.shading->Render(vector_make(0, 0), kcolor_rgba(1, 1, 1, 1));
|
|
graphics.Present(KAGE::Graphics::PRESENT_FINISH);
|
|
graphics.render_target_pop(KAGE::Graphics::PRESENT_FLUSH);
|
|
}
|
|
|
|
// 007f1380 Takes the room's backdrop with its seeds, loads the effect layers of its stage (none in crawlspaces or
|
|
// Mega Satan's room), the radial glow of Mega Satan's and Ultra Greed's rooms, and the shading of its shape.
|
|
// A Void room shows the effect layers of the stage its layout comes from.
|
|
void Room::LoadBackdropGraphics()
|
|
{
|
|
Game& game = *g_game;
|
|
int fxStage = (int)game.stage;
|
|
int stageType = game.challenge == CHALLENGE_RED_REDEMPTION ? game.GetRoomStageType(game.currentRoomIdx)
|
|
: (int)game.stageType;
|
|
int backdropId = backdrop_get(*this, fxStage, stageType);
|
|
|
|
backdrop.seed = descriptor->decorationSeed;
|
|
backdrop.rng = {descriptor->decorationSeed, 5, 9, 7};
|
|
backdrop.Init((uint32_t)backdropId, false);
|
|
backdropType = (int)backdrop.backdropId;
|
|
if (fxStage == STAGE_THE_VOID) void_fx_stage_get(descriptor->data->stageId, fxStage, stageType);
|
|
|
|
bool isNoLayers = roomType == ROOM_DUNGEON || backdropId == BACKDROP_MEGA_SATAN;
|
|
if (isNoLayers) fxLayers.clear();
|
|
else fxLayers.LoadConfig(g_manager->modManager.TryRedirectPath("fxlayers.xml"), fxStage, stageType);
|
|
|
|
if (backdropId == BACKDROP_MEGA_SATAN || (!isNoLayers && backdropId == BACKDROP_GREED_SHOP))
|
|
{
|
|
satanRadialSprite.Load("gfx/Effect_SatanRadial.anm2", GRAPHICS_DEFER);
|
|
if (backdropId == BACKDROP_GREED_SHOP) satanRadialSprite.ReplaceSpritesheet(0, "gfx/satan_radial_ultragreed.png");
|
|
satanRadialSprite.LoadGraphics();
|
|
}
|
|
shading_load(*this);
|
|
}
|
|
|
|
// 007f9df0 Opens Mega Satan's door at the top of the Chest's or Dark Room's starting room, once his door is unlocked
|
|
// (or in a debug or daily run being played), and not in a challenge or daily that leaves Mega Satan out. Forced, it
|
|
// opens anywhere a door fits.
|
|
bool Room::TrySpawnMegaSatanRoomDoor(bool isForce)
|
|
{
|
|
Game& game = *g_game;
|
|
bool isMegaSatan = game.GetChallengeParams().isMegaSatan;
|
|
|
|
if (!isForce)
|
|
{
|
|
bool isStart = game.currentRoomIdx == game.startingRoomIdx && game.stage == STAGE_DARK_ROOM_CHEST &&
|
|
game.currentDimensionIdx == 0;
|
|
if (!isStart || !is_unlocked(ACHIEVEMENT_MEGA_SATAN)) return false;
|
|
if (is_challenge_or_daily() && !isMegaSatan) return false;
|
|
}
|
|
KAGE_LogMessage(LOG_INFO, (uint8_t*)"Spawning Mega Satan door\n");
|
|
if (doors[DOOR_UP0])
|
|
{
|
|
KAGE_LogMessage(LOG_INFO, (uint8_t*)"[warn] no space for Mega Satan door\n");
|
|
return false;
|
|
}
|
|
MakeDoor(DOOR_UP0);
|
|
doors[DOOR_UP0]->targetRoomIdx = ROOM_MEGA_SATAN_IDX;
|
|
doors[DOOR_UP0]->SetRoomTypes(descriptor->data->type, ROOM_BOSS);
|
|
return true;
|
|
}
|
|
|
|
// 008279d0 Opens the quest door of the alternate path's second floors: the Downpour's door to the Mirror (or the
|
|
// Dross's) and the Mines' door to the abandoned mineshaft, on the first quest door slot of their special rooms.
|
|
bool Room::TrySpawnSpecialQuestDoor()
|
|
{
|
|
Game& game = *g_game;
|
|
if (game.stageType != STAGETYPE_REPENTANCE && game.stageType != STAGETYPE_REPENTANCE_B) return false;
|
|
|
|
bool isLabyrinth = is_curse_active(CURSE_OF_LABYRINTH);
|
|
bool isDownpourTwo = game.stage == 2 || (game.stage == 1 && isLabyrinth);
|
|
bool isMinesTwo = game.stage == 4 || (game.stage == 3 && isLabyrinth);
|
|
RoomConfig_Room& config = *descriptor->data;
|
|
int target = 0;
|
|
|
|
if (isDownpourTwo && config.type == ROOM_DEFAULT && config.subtype == MIRROR_ROOM_SUBTYPE) target = ROOM_MIRROR_IDX;
|
|
else if (!isDownpourTwo && isMinesTwo && config.type == ROOM_DEFAULT &&
|
|
(config.subtype == MINESHAFT_ROOM_SUBTYPE || config.subtype == MINESHAFT_ROOM_SUBTYPE + 1))
|
|
target = ROOM_MINESHAFT_IDX;
|
|
if (target == 0) return false;
|
|
|
|
int slot = std::countr_zero(config.questDoors);
|
|
if (slot >= DOOR_SLOT_COUNT || doors[slot]) return false;
|
|
|
|
MakeDoor(slot);
|
|
doors[slot]->targetRoomIdx = target;
|
|
doors[slot]->SetRoomTypes(config.type, config.type);
|
|
return true;
|
|
}
|
|
|
|
// 00822d60 Holds what spawned on a pressure plate's output cells until the plate fires: each enemy (or player in a
|
|
// versus match), bomb and free pickup on a cell of an output group becomes a spawner of the group. Held enemies stay
|
|
// out of the room on later visits.
|
|
void Room::hold_trigger_output_entities()
|
|
{
|
|
std::array<int8_t, ROOM_GRID_CELLS> cellGroups;
|
|
bool isAnyOutput = false;
|
|
|
|
cellGroups.fill(-1);
|
|
for (int group = 0; group < OUTPUT_GROUP_COUNT; group++)
|
|
for (int gridIndex : outputGroupGridIndices[group])
|
|
{
|
|
isAnyOutput = true;
|
|
if (cellGroups[gridIndex] < 0) cellGroups[gridIndex] = (int8_t)group;
|
|
}
|
|
if (!isAnyOutput) return;
|
|
|
|
g_game->room->isUnknown11f5 = false;
|
|
for (size_t i = 0; i < entityList.updateEL.size(); i++)
|
|
{
|
|
Entity& entity = *entityList.updateEL[i];
|
|
int gridIndex = entity.spawnGridIndex;
|
|
if (gridIndex < 0 || cellGroups[gridIndex] < 0) continue;
|
|
|
|
bool isFreePickup = entity.type == ENTITY_PICKUP && static_cast<Entity_Pickup&>(entity).price == 0;
|
|
bool isEnemy = (g_game->deathmatchManager.is_active() && entity.type == ENTITY_PLAYER) ||
|
|
(entity.type >= ENTITY_FIRST_ENEMY && entity.type < ENTITY_EFFECT);
|
|
if (!isFreePickup && !isEnemy && entity.type != ENTITY_BOMB) continue;
|
|
|
|
if (isEnemy) descriptor->restrictedGridIndexes.insert(gridIndex);
|
|
hold_entity_in_spawner(entity, cellGroups[gridIndex]);
|
|
}
|
|
}
|
|
|
|
// 00822fd0 Replaces an entity by a spawner effect holding its type, variant and subtype for an output group, no longer
|
|
// counting it as an enemy or boss.
|
|
Entity* Room::hold_entity_in_spawner(Entity& entity, int group)
|
|
{
|
|
EntitySpawn spawn = {.position = entity.pos, .subType = entity.type, .type = ENTITY_EFFECT,
|
|
.variant = EFFECT_SPAWNER, .seed = entity.initSeed};
|
|
auto* spawner = static_cast<Entity_Effect*>(game_spawn(spawn, POOL_OVERWRITE));
|
|
|
|
spawner->varData[0] = (uint32_t)entity.variant;
|
|
spawner->varData[1] = (uint32_t)entity.subtype;
|
|
spawner->state = group;
|
|
if (entity.CanShutDoors() && entity.type != ENTITY_DARK_ESAU)
|
|
{
|
|
entityList.enemyCount--;
|
|
if (entity.IsBoss()) entityList.bossCount--;
|
|
}
|
|
entity.Remove();
|
|
return spawner;
|
|
}
|
|
|
|
// The way a cart starts along a rail piece: none for a crossing or mineshaft piece, back or forward by its cart bits.
|
|
static int rail_cart_direction(uint8_t rail)
|
|
{
|
|
if (rail == RAIL_NONE || rail & RAIL_MINESHAFT) return 0;
|
|
if (rail & RAIL_CART_BACKWARD) return -1;
|
|
return rail & RAIL_CART_FORWARD ? 1 : 0;
|
|
}
|
|
|
|
// Sets a minecart enemy on a rail, rolling one way, turned upright on a vertical piece.
|
|
static void minecart_snap(Entity_NPC& cart, Vector railPosition, Vector railDirection)
|
|
{
|
|
Room& room = *g_game->room;
|
|
|
|
cart.velocity = railDirection;
|
|
cart.pos = railPosition;
|
|
cart.targetPosition = railPosition;
|
|
|
|
int gridIndex = room.GetGridIndex(cart.pos);
|
|
uint8_t piece = gridIndex >= 0 && gridIndex < ROOM_GRID_CELLS ? room.railManager.rails[gridIndex] : RAIL_NONE;
|
|
uint8_t shape = piece & RAIL_PIECE_MASK;
|
|
bool isVertical = piece != RAIL_NONE && (shape == RAIL_VERTICAL || shape == RAIL_END_UP || shape == RAIL_END_DOWN);
|
|
cart.i1 = isVertical ? MINECART_VERTICAL : 0;
|
|
cart.update_move_direction_anim();
|
|
cart.v2.x = MINECART_SPEED;
|
|
}
|
|
|
|
// 00823f50 Puts the enemies spawned next to a rail with a cart on it into minecarts on that rail, the first neighbor
|
|
// above, below, left or right that has one. A minecart enemy itself snaps onto the nearest rail and rolls along it.
|
|
void Room::attach_minecarts()
|
|
{
|
|
constexpr int NEIGHBORS[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
|
|
|
|
for (size_t i = 0; i < entityList.updateEL.size(); i++)
|
|
{
|
|
Entity& entity = *entityList.updateEL[i];
|
|
bool isCart = entity.type == ENTITY_MINECART && entity.variant == MINECART_ENEMY;
|
|
bool isEnemy = (g_game->deathmatchManager.is_active() && entity.type == ENTITY_PLAYER) ||
|
|
(entity.type >= ENTITY_FIRST_ENEMY && entity.type < ENTITY_EFFECT);
|
|
bool isRider = !(entity.type == ENTITY_MINECART && entity.variant == 0) && !entity.minecart;
|
|
if (!isEnemy || entity.spawnGridIndex < 0 || (!isRider && !isCart)) continue;
|
|
|
|
int column = entity.spawnGridIndex % gridWidth;
|
|
int row = entity.spawnGridIndex / gridWidth;
|
|
for (const auto& [dx, dy] : NEIGHBORS)
|
|
{
|
|
int x = column + dx;
|
|
int y = row + dy;
|
|
if (x <= 0 || y <= 0 || x >= gridWidth - 1 || y >= gridHeight - 1) continue;
|
|
|
|
int gridIndex = GetGridIndexByTile(x, y);
|
|
if (gridIndex < 0 || gridIndex >= ROOM_GRID_CELLS || railManager.rails[gridIndex] & RAIL_HIDDEN) continue;
|
|
|
|
uint8_t rail = railManager.rails[gridIndex];
|
|
int direction = rail_cart_direction(rail);
|
|
if (direction == 0 && !isCart) continue;
|
|
|
|
Vector railDirection = vector_make(0, 0);
|
|
if (direction != 0 && (rail & RAIL_PIECE_MASK) == RAIL_HORIZONTAL) railDirection.x = (float)direction;
|
|
else if (direction != 0) railDirection.y = (float)direction;
|
|
Vector railPosition = GetGridPosition(gridIndex);
|
|
|
|
if (!isCart)
|
|
{
|
|
entity.GiveMinecart(railPosition, railDirection);
|
|
break;
|
|
}
|
|
minecart_snap(static_cast<Entity_NPC&>(entity), railPosition, railDirection);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// How bright the lighting layer is at a point of the room, the light rain falls in: none without the layer.
|
|
// Reading it needs the layer image's pixels, which the renderer does not keep.
|
|
static float fx_light_get(Room& room)
|
|
{
|
|
for (const FXLayer& layer : room.fxLayers.layers)
|
|
if (room.fxLayers.isLoaded && layer.type == FX_LAYER_LIGHTING && !layer.tiles.empty())
|
|
reconstruction_missing("Room::init_rain 00824350: the lighting layer's pixel (FUN_00995f40)");
|
|
return 0;
|
|
}
|
|
|
|
// 00824350 Starts the rain of a watery Downpour, Dross or flooded Corpse room: up to four spots it falls around (four
|
|
// in the Rainmaker's room until it is cleared), placed where the lighting is bright, picked from the decoration seed,
|
|
// then ten frames of it falling.
|
|
void Room::init_rain()
|
|
{
|
|
numRainSpawners = 0;
|
|
rainIntensity = 1;
|
|
isRainStopped = false;
|
|
|
|
int stageId = g_game->GetStageID();
|
|
bool isRainy = stageId == STAGE_ID_DOWNPOUR || stageId == STAGE_ID_DROSS || backdropType == BACKDROP_CORPSE3;
|
|
if (waterAmount <= 0 || !isRainy) return;
|
|
|
|
RNG rng = {descriptor->decorationSeed, 1, 11, 6};
|
|
int spawners = 0;
|
|
if (bossId == BOSS_RAINMAKER) spawners = descriptor->flags & ROOM_DESCRIPTOR_FLAG_CLEAR ? 0 : RAIN_SPAWNER_COUNT;
|
|
else
|
|
{
|
|
uint32_t roll = rng.Next() % 1000;
|
|
spawners = (roll < 300 ? 1 : 0) + (roll < 100 ? 1 : 0) + (roll < 40 ? 1 : 0) + (roll < 10 ? 1 : 0);
|
|
}
|
|
|
|
for (int attempt = 0; attempt < AMBIENT_RETRIES && spawners > 0; attempt++)
|
|
{
|
|
float top = topLeftPos.y + RAIN_MARGIN;
|
|
float y = (bottomRightPos.y - RAIN_MARGIN - top) * (float)rng.Next() * 2.3283062e-10f + top;
|
|
float left = topLeftPos.x + RAIN_MARGIN;
|
|
float x = (bottomRightPos.x - RAIN_MARGIN - left) * (float)rng.Next() * 2.3283062e-10f + left;
|
|
if (fx_light_get(*this) < RAIN_LIGHT_MIN) continue;
|
|
|
|
float angle = (float)rng.Next() * 2.3283062e-10f * 360 * DEGREES_TO_RADIANS;
|
|
float cosine = std::cos(angle);
|
|
float sine = std::sin(angle);
|
|
float radiusA = (float)rng.Next() * 2.3283062e-10f * RAIN_RADIUS_RANGE + RAIN_RADIUS_MIN;
|
|
float quarterCos = std::cos(QUARTER_TURN);
|
|
float quarterSin = std::sin(QUARTER_TURN);
|
|
float radiusB = (float)rng.Next() * 2.3283062e-10f * RAIN_RADIUS_RANGE + RAIN_RADIUS_MIN;
|
|
|
|
RainSpawner& spawner = rainSpawners[numRainSpawners++];
|
|
spawner.position = vector_make(x, y);
|
|
spawner.axisA = vector_make(radiusA * cosine, radiusA * sine);
|
|
spawner.axisB = vector_make(radiusB * (quarterCos * cosine - quarterSin * sine),
|
|
radiusB * (quarterSin * cosine + quarterCos * sine));
|
|
spawners--;
|
|
}
|
|
for (int i = 0; i < AMBIENT_RETRIES; i++) update_ambient_spawns();
|
|
}
|
|
|
|
// 00824800 Rains drops around the rain spots, a drop at a random point of each spot's ellipse that lies in the room,
|
|
// more often the faster time runs and the harder it rains. A stopped rain fades out.
|
|
void Room::update_ambient_spawns()
|
|
{
|
|
if (numRainSpawners <= 0 || rainIntensity <= 0) return;
|
|
|
|
if (isRainStopped) rainIntensity = std::max(rainIntensity - RAIN_FADE, 0.0f);
|
|
if (rainIntensity < RAIN_INTENSITY_MIN)
|
|
{
|
|
rainIntensity = 0;
|
|
return;
|
|
}
|
|
|
|
int interval = (int)(1 / (GetTimeScale(nullptr) * rainIntensity));
|
|
if (interval != 0 && g_game->frameCount % interval >= 1) return;
|
|
|
|
for (int i = 0; i < numRainSpawners; i++)
|
|
{
|
|
RainSpawner& spawner = rainSpawners[i];
|
|
float angle = random_unit() * RAIN_PI;
|
|
angle += angle;
|
|
float radius = random_unit();
|
|
float along = std::cos(angle) * radius;
|
|
float across = std::sin(angle) * radius;
|
|
Vector position = vector_make(along * spawner.axisA.x + spawner.position.x + across * spawner.axisB.x,
|
|
along * spawner.axisA.y + spawner.position.y + across * spawner.axisB.y);
|
|
|
|
bool isInside = false;
|
|
if (IsLShapedRoom())
|
|
{
|
|
Vector clamped = GetClampedPositionImpl(position, 0, 0, 0, 0);
|
|
isInside = clamped.x == position.x && clamped.y == position.y;
|
|
}
|
|
else
|
|
isInside = topLeftPos.x + 0 <= position.x && position.x <= bottomRightPos.x - 0 &&
|
|
topLeftPos.y + 0 <= position.y && position.y <= bottomRightPos.y - 0;
|
|
if (isInside) entity_spawn(ENTITY_EFFECT, EFFECT_RAIN_DROP, position, 0, Random())->Update();
|
|
}
|
|
}
|
|
|
|
// 007ea3e0 How fast time runs for an entity, or for the room without one: slowed by the Stop Watch, following the
|
|
// first player's speed with the Super Hot seed, plus a tenth per G-Fuel past the first. Astral Projection's effect
|
|
// slows the room and speeds up its owner. SPEED! and the Broken Watch's fast rooms run faster.
|
|
float Room::GetTimeScale(Entity* entity)
|
|
{
|
|
Game& game = *g_game;
|
|
bool isPlayer = entity && entity->type == ENTITY_PLAYER;
|
|
float timeScale = 1;
|
|
|
|
if (!isPlayer)
|
|
{
|
|
if (game.playerManager.FirstCollectibleOwner(COLLECTIBLE_STOP_WATCH, LAZARUS_SHARE_CHECK))
|
|
timeScale = TIME_SCALE_STOP_WATCH_ROOM;
|
|
if (game.seedEffects.HasSeedEffect(SEED_EFFECT_SUPER_HOT))
|
|
{
|
|
Vector velocity = game.GetPlayer(0)->velocity;
|
|
float speed = std::sqrt(velocity.y * velocity.y + velocity.x * velocity.x) / SUPER_HOT_SPEED;
|
|
timeScale = std::min(std::max(speed, TIME_SCALE_MIN), SUPER_HOT_SCALE_MAX);
|
|
}
|
|
}
|
|
timeScale += (float)std::max(game.playerManager.GetGFuelCount() - 1, 0) * TIME_SCALE_PER_GFUEL;
|
|
|
|
if (TemporaryEffect* astral = temporaryEffects.GetCollectibleEffect(COLLECTIBLE_ASTRAL_PROJECTION))
|
|
{
|
|
float ease = std::clamp(((float)astral->cooldown - 0) / TIME_SCALE_EASE_FRAMES, 0.0f, 1.0f);
|
|
if (!isPlayer) timeScale = std::max((1 - ease) * timeScale, TIME_SCALE_MIN);
|
|
else if (static_cast<Entity_Player*>(entity)->HasCollectible(COLLECTIBLE_ASTRAL_PROJECTION))
|
|
timeScale *= ease + 1;
|
|
}
|
|
if (game.challenge == CHALLENGE_SPEED || game.room->brokenWatchState == BROKEN_WATCH_FAST) timeScale *= TIME_SCALE_FAST;
|
|
return timeScale;
|
|
}
|
|
|
|
// 00823370 The screen color the room calls for: its stage's, mostly washed out in secret rooms and the abandoned
|
|
// mineshaft, a little brighter when pitch black, and darkened by the Mines' lava as it cools.
|
|
ColorModState Room::get_color_modifier()
|
|
{
|
|
const FXParams& params = fxLayers.fxParams;
|
|
ColorModState color = {params.roomColor._red, params.roomColor._green, params.roomColor._blue,
|
|
params.roomColor._alpha, params.brightness, params.contrast};
|
|
|
|
bool isMineshaft = g_game->HasAbandonedMineshaft() && g_game->currentDimensionIdx == 1;
|
|
if (roomType == ROOM_SECRET || roomType == ROOM_SUPERSECRET || roomType == ROOM_ULTRASECRET || isMineshaft)
|
|
{
|
|
color._red += (1 - color._red) * SECRET_WASHOUT;
|
|
color._brightness += (0 - color._brightness) * SECRET_WASHOUT;
|
|
color._green += (1 - color._green) * SECRET_WASHOUT;
|
|
color._blue += (1 - color._blue) * SECRET_WASHOUT;
|
|
color._contrast += (1 - color._contrast) * SECRET_WASHOUT;
|
|
color._amount += (0 - color._amount) * SECRET_WASHOUT;
|
|
}
|
|
if (descriptor->flags & ROOM_DESCRIPTOR_FLAG_PITCH_BLACK) color._brightness += PITCH_BLACK_BRIGHTNESS;
|
|
if (backdropType == BACKDROP_MINES && descriptor->flags & ROOM_DESCRIPTOR_FLAG_HAS_WATER)
|
|
{
|
|
float darken = (float)descriptor->pitsCount / (float)((gridHeight - 2) * (gridWidth - 2)) * lavaIntensity;
|
|
color._red -= darken;
|
|
color._blue += darken * LAVA_TINT;
|
|
color._green += darken * LAVA_TINT;
|
|
color._contrast += darken * LAVA_CONTRAST;
|
|
color._amount -= darken * LAVA_AMOUNT;
|
|
}
|
|
return color;
|
|
}
|
|
|
|
// 00823540 Fades the screen to the room's color, at once while the floor generates or a saved run starts.
|
|
void Room::color_modifier_apply()
|
|
{
|
|
bool isLerp = !g_game->isLevelGenerating && !g_game->isStartingFromState;
|
|
g_game->SetColorModifier(get_color_modifier(), isLerp, COLOR_MODIFIER_RATE);
|
|
}
|
|
|
|
// 007067c0 Sets the screen color to fade to, at a rate of the distance per frame, or at once.
|
|
void Game::SetColorModifier(const ColorModState& color, bool isLerp, float rate)
|
|
{
|
|
targetColorModifier = color;
|
|
isColorModifierLerped = isLerp;
|
|
if (!isLerp)
|
|
{
|
|
currentColorModifier = targetColorModifier;
|
|
return;
|
|
}
|
|
|
|
const ColorModState& target = targetColorModifier;
|
|
const ColorModState& current = currentColorModifier;
|
|
lerpColorModifier = {std::abs(target._red - current._red) * rate, std::abs(target._green - current._green) * rate,
|
|
std::abs(target._blue - current._blue) * rate, std::abs(target._amount - current._amount) * rate,
|
|
std::abs(target._brightness - current._brightness) * rate,
|
|
std::abs(target._contrast - current._contrast) * rate};
|
|
}
|
|
|
|
// Which door's dust door_dust_spawn throws: the secret exit's, thrown straight out and spinning one way or the other,
|
|
// or a deal door's, thrown across and spinning at random speeds.
|
|
enum DustStyle
|
|
{
|
|
DUST_SECRET_EXIT,
|
|
DUST_DEAL
|
|
};
|
|
|
|
// What door_dust_spawn throws out of a door: its style and the subtype each puff takes, or 1 for the first only.
|
|
struct DoorDust
|
|
{
|
|
DustStyle style = DUST_SECRET_EXIT;
|
|
int subType = 0;
|
|
bool isFirstMarked = false;
|
|
};
|
|
|
|
// Five to eight puffs of dust thrown out of a door as it appears, spread around it and spinning away from it.
|
|
static void door_dust_spawn(Room& room, GridEntity_Door& door, const DoorDust& dust)
|
|
{
|
|
Vector direction{};
|
|
Isaac::GetAxisAlignedUnitVectorFromDir(&direction, door.slot & 3);
|
|
Vector out = vector_make(-direction.x, -direction.y);
|
|
Vector across = vector_make(out.x * std::cos(QUARTER_TURN) - out.y * std::sin(QUARTER_TURN),
|
|
out.x * std::sin(QUARTER_TURN) + out.y * std::cos(QUARTER_TURN));
|
|
Vector doorPosition = room.GetGridPosition(door.gridIndex);
|
|
bool isDeal = dust.style == DUST_DEAL;
|
|
int count = (int)(Random() & 3) + DUST_MIN;
|
|
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
uint32_t seed = Random();
|
|
float speed = random_unit() * (isDeal ? DUST_SPEED : 1);
|
|
float side = random_unit();
|
|
side = side + side - 1;
|
|
Vector velocity = isDeal ? vector_make(side * out.y + out.x * speed, side * -out.x + out.y * speed)
|
|
: vector_make(speed * out.x * DUST_SPEED + across.x * side,
|
|
speed * out.y * DUST_SPEED + across.y * side);
|
|
float angle = random_unit() * RAIN_PI;
|
|
angle += angle;
|
|
float radius = random_unit() * (isDeal ? DUST_RADIUS : 1);
|
|
float scale = isDeal ? 1 : DUST_RADIUS;
|
|
Vector position = vector_make(std::cos(angle) * radius * scale + doorPosition.x,
|
|
std::sin(angle) * radius * scale + doorPosition.y);
|
|
int subType = dust.isFirstMarked ? (i == 0 ? 1 : 0) : dust.subType;
|
|
|
|
EntitySpawn spawn = {.position = position, .velocity = velocity, .subType = subType, .type = ENTITY_EFFECT,
|
|
.variant = EFFECT_DUST_CLOUD, .seed = seed};
|
|
auto* puff = static_cast<Entity_Effect*>(game_spawn(spawn, POOL_OVERWRITE));
|
|
Vector offset = vector_make(puff->pos.x - doorPosition.x, puff->pos.y - doorPosition.y);
|
|
bool isBehind = isDeal ? offset.x * out.y + offset.y * -out.x < 0 : offset.x * out.x + offset.y * out.y < 0;
|
|
float spin = random_unit() * DUST_SPIN_RANGE + DUST_SPIN_MIN;
|
|
// The secret exit's spin is only ever 1 or -1, its random speed lost in the original.
|
|
if (!isDeal) puff->rotation = spin * (float)isBehind == 0 ? 1.0f : -1.0f;
|
|
else puff->rotation = spin * (isBehind ? -1.0f : 1.0f);
|
|
puff->timeout = (int)(Random() % DUST_TIMEOUT_RANGE) + DUST_TIMEOUT_MIN;
|
|
puff->lifespan = puff->timeout;
|
|
puff->Update();
|
|
}
|
|
}
|
|
|
|
// The first door slot from start on, wrapping around, where the layout has a door and none stands. The original
|
|
// falls back on the last slot it tried when none fits, as here.
|
|
static int free_door_slot_get(Room& room, int start)
|
|
{
|
|
int slot = start;
|
|
for (int i = 0; i < DOOR_SLOT_COUNT; i++)
|
|
{
|
|
slot = (start + i) & (DOOR_SLOT_COUNT - 1);
|
|
if (room.descriptor->data->doors & 1u << slot && !room.doors[slot]) break;
|
|
}
|
|
return slot;
|
|
}
|
|
|
|
// The slot a special door opens on: back where the players came from that room, or a free slot from the decoration
|
|
// seed.
|
|
static int special_door_slot_get(Room& room, int fromRoomIdx)
|
|
{
|
|
Game& game = *g_game;
|
|
if (game.lastRoomIdx == fromRoomIdx && game.enterDoor >= 0 && !room.doors[game.enterDoor]) return game.enterDoor;
|
|
|
|
RNG rng = {room.descriptor->decorationSeed, 1, 11, 16};
|
|
return free_door_slot_get(room, (int)(rng.Next() & (DOOR_SLOT_COUNT - 1)));
|
|
}
|
|
|
|
// A door in a slot, made when there is none, leading to a room off the map.
|
|
static GridEntity_Door& special_door_make(Room& room, int slot, int targetRoomIdx)
|
|
{
|
|
if (!room.doors[slot]) room.MakeDoor(slot);
|
|
room.doors[slot]->targetRoomIdx = targetRoomIdx;
|
|
return *room.doors[slot];
|
|
}
|
|
|
|
static bool is_door_to(Room& room, int targetRoomIdx)
|
|
{
|
|
return std::ranges::any_of(room.doors, [&](GridEntity_Door* door) { return door && door->targetRoomIdx == targetRoomIdx; });
|
|
}
|
|
|
|
static int labyrinth_stage_get()
|
|
{
|
|
return (int)g_game->stage + (is_curse_active(CURSE_OF_LABYRINTH) ? 1 : 0);
|
|
}
|
|
|
|
static bool is_last_boss_room()
|
|
{
|
|
return g_game->GetRoomByIdx(g_game->currentRoomIdx)->listIndex == g_game->lastBossRoomListIdx;
|
|
}
|
|
|
|
// Whether the run is past the floors where the boss rooms open their doors to the path: Mom's heart killed before the
|
|
// Ascent, or on the way back up.
|
|
static bool is_path_closed(Room& room)
|
|
{
|
|
Game& game = *g_game;
|
|
bool isMomsHeartRoom = room.roomType == ROOM_BOSS && room.descriptor->data->subtype == BOSS_MOM_MAUSOLEUM;
|
|
|
|
return (isMomsHeartRoom && game.IsPreAscent()) || is_backwards_path();
|
|
}
|
|
|
|
// 007f7a40 Opens a secret exit: the strange door at the top of Depths II's starting room once it is unlocked (outside
|
|
// challenges and dailies, or on the Home path), or a door to the alternate path from the floor's last boss room, which
|
|
// a challenge on that path opens outright. Animated, dust flies out of it.
|
|
bool Room::TrySpawnSecretExit(bool isAnimate, bool isForce)
|
|
{
|
|
Game& game = *g_game;
|
|
if (!isForce && (game.challenge == CHALLENGE_RED_REDEMPTION || is_path_closed(*this))) return false;
|
|
|
|
ChallengeParam& params = game.GetChallengeParams();
|
|
bool isPathUnlocked = params.pathType == PATH_TYPE_HOME ||
|
|
(is_unlocked(ACHIEVEMENT_STRANGE_DOOR) && !is_challenge_or_daily());
|
|
bool isDepthsTwo = labyrinth_stage_get() == STAGE_DEPTHS_II;
|
|
bool isAltStage = game.stageType == STAGETYPE_REPENTANCE || game.stageType == STAGETYPE_REPENTANCE_B;
|
|
|
|
if (isPathUnlocked && isDepthsTwo && game.currentRoomIdx == game.startingRoomIdx && !isAltStage)
|
|
{
|
|
if (doors[DOOR_UP0]) return false;
|
|
MakeDoor(DOOR_UP0);
|
|
RoomDescriptor* exit = game.get_secret_exit_room(SECRET_EXIT_MAUSOLEUM);
|
|
doors[DOOR_UP0]->targetRoomIdx = ROOM_SECRET_EXIT_IDX;
|
|
doors[DOOR_UP0]->SetRoomTypes(descriptor->data->type, exit->data->type);
|
|
return true;
|
|
}
|
|
if (!isForce && !is_last_boss_room()) return false;
|
|
|
|
ChallengeParam& challenge = game.GetChallengeParams();
|
|
bool isAllowed = (!is_challenge_or_daily() || challenge.pathType == PATH_TYPE_REPENTANCE) &&
|
|
is_unlocked(ACHIEVEMENT_SECRET_EXIT);
|
|
if (!isForce && !isAllowed) return false;
|
|
|
|
int kind = game.get_secret_exit_kind();
|
|
if (kind == 0 || (!isForce && kind == SECRET_EXIT_MOMS_HEART && game.IsMausoleumHeartStage())) return false;
|
|
|
|
// Without a free slot away from the neighbours, the original takes the slot it started from, as here.
|
|
RNG rng = {descriptor->spawnSeed, 2, 9, 15};
|
|
int start = (int)(rng.Next() & (DOOR_SLOT_COUNT - 1));
|
|
int slot = start;
|
|
for (int i = 0; i < DOOR_SLOT_COUNT; i++, slot = (slot + 1) & (DOOR_SLOT_COUNT - 1))
|
|
{
|
|
bool isNeighbor = descriptor->allowedDoors & 1u << slot;
|
|
if (descriptor->data->doors & 1u << slot && !doors[slot] && !isNeighbor) break;
|
|
}
|
|
|
|
RoomDescriptor* exit = game.get_secret_exit_room(kind);
|
|
GridEntity_Door& door = special_door_make(*this, slot, ROOM_SECRET_EXIT_IDX);
|
|
door.SetRoomTypes(ROOM_DEFAULT, exit->data->type);
|
|
if (challenge.pathType == PATH_TYPE_REPENTANCE && door.variant != DOOR_UNLOCKED &&
|
|
door.get_secret_exit_kind() != SECRET_EXIT_MOMS_HEART)
|
|
{
|
|
bool isKeyLocked = door.variant == DOOR_LOCKED || door.variant == DOOR_LOCKED_BARRED ||
|
|
door.variant == DOOR_LOCKED_DOUBLE;
|
|
door.TryUnlock(*game.GetPlayer(0), true);
|
|
if (!isKeyLocked)
|
|
{
|
|
door.Open();
|
|
door.TryBlowOpen(false, nullptr);
|
|
}
|
|
}
|
|
if (isAnimate) door_dust_spawn(*this, door, {.style = DUST_SECRET_EXIT});
|
|
return true;
|
|
}
|
|
|
|
static void deal_jingle_play(int sound)
|
|
{
|
|
seed_fart_sound_override(&sound);
|
|
g_manager->sfxManager.Play(sound);
|
|
}
|
|
|
|
// The slot of the deal door, from the decoration seed (the fourth in Greed): first one free whose opposite side the
|
|
// deal room has a door on, else any free one, or none.
|
|
static int deal_door_slot_get(Room& room, RoomConfig_Room& dealRoom)
|
|
{
|
|
RNG rng = {room.descriptor->decorationSeed, 2, 5, 21};
|
|
int start = (int)(rng.Next() & (DOOR_SLOT_COUNT - 1));
|
|
if (is_greed()) start = GREED_DEAL_DOOR_SLOT;
|
|
|
|
auto is_free = [&](int slot) { return room.descriptor->data->doors & 1u << slot && !room.doors[slot]; };
|
|
for (int i = 0; i < DOOR_SLOT_COUNT; i++)
|
|
{
|
|
int slot = (i + start) & (DOOR_SLOT_COUNT - 1);
|
|
int opposite = (slot + 2) & 3;
|
|
if (is_free(slot) && dealRoom.doors & 1u << opposite) return slot;
|
|
}
|
|
for (int i = 0; i < DOOR_SLOT_COUNT; i++)
|
|
if (int slot = (start + i) & (DOOR_SLOT_COUNT - 1); is_free(slot)) return slot;
|
|
return -1;
|
|
}
|
|
|
|
// 007f83b0 Opens the deal door of the floor's last boss room when a deal room may spawn and its chance rolls (the
|
|
// roll keeps the floor's generator as it is): Duality's two doors when the deal room is not picked yet, else the deal
|
|
// room the floor picks, on the slot the players came back through or a free one. Animated, it plays its jingle and
|
|
// throws dust. The floor's deal generator steps on after.
|
|
bool Room::TrySpawnDevilRoomDoor(bool isAnimate, bool isForce)
|
|
{
|
|
Game& game = *g_game;
|
|
if (!isForce && (!game.CanSpawnDevilRoom() || !is_last_boss_room())) return false;
|
|
|
|
float chance = GetDevilRoomChance();
|
|
if (!isForce)
|
|
{
|
|
RNG roll = game.devilAngelRoomRNG;
|
|
roll._shift1 = 2;
|
|
roll._shift2 = 21;
|
|
roll._shift3 = 9;
|
|
if (chance <= (float)roll.Next() * 2.3283062e-10f && chance < 1)
|
|
{
|
|
game.isDevilRoomDisabled = true;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Out of the three dimensions, the original reads a blank descriptor as the deal room, as here.
|
|
RoomDescriptor blank;
|
|
bool isDimension = (uint32_t)game.currentDimensionIdx < DIMENSION_COUNT;
|
|
RoomDescriptor& devilRoom = isDimension ? game.roomList[ROOM_MAP_CELLS] : blank;
|
|
bool isDuality = game.playerManager.FirstCollectibleOwner(COLLECTIBLE_DUALITY, LAZARUS_SHARE_CHECK);
|
|
if (isDuality && !devilRoom.data)
|
|
{
|
|
RNG rng = {descriptor->decorationSeed, 2, 5, 21};
|
|
int start = (int)rng.RandomInt(DOOR_SLOT_COUNT);
|
|
std::vector<int> freeSlots;
|
|
for (int i = 0; i < DOOR_SLOT_COUNT; i++)
|
|
{
|
|
int slot = (start + i) & (DOOR_SLOT_COUNT - 1);
|
|
if (descriptor->data->doors & 1u << slot && !doors[slot]) freeSlots.push_back(slot);
|
|
}
|
|
if (freeSlots.size() > 1)
|
|
{
|
|
RNG::Shuffle(&rng, freeSlots.data(), freeSlots.data() + freeSlots.size());
|
|
bool isAngelPlaced = false;
|
|
for (int i = 0; i < 2; i++)
|
|
{
|
|
int slot = freeSlots[i];
|
|
if (!doors[slot]) MakeDoor(slot);
|
|
|
|
bool isAngel = !isAngelPlaced && (i == 1 || game.playerManager.AnyoneHasTrinket(TRINKET_ROSARY_BEAD));
|
|
isAngelPlaced = isAngelPlaced || isAngel;
|
|
doors[slot]->SetRoomTypes(ROOM_DEFAULT, isAngel ? ROOM_ANGEL : ROOM_DEVIL);
|
|
doors[slot]->targetRoomIdx = ROOM_DEVIL_IDX;
|
|
doors[slot]->Open();
|
|
if (isAnimate) door_dust_spawn(*this, *doors[slot], {.style = DUST_DEAL, .isFirstMarked = true});
|
|
}
|
|
if (isAnimate)
|
|
{
|
|
deal_jingle_play(SOUND_DEVIL_DOOR_APPEAR);
|
|
deal_jingle_play(SOUND_ANGEL_DOOR_APPEAR);
|
|
}
|
|
game.lastDevilRoomStage = deal_stage_get();
|
|
return true;
|
|
}
|
|
}
|
|
|
|
game.InitializeDevilAngelRoom(game.playerManager.AnyoneHasTrinket(TRINKET_ROSARY_BEAD), false);
|
|
int slot = game.enterDoor;
|
|
bool isBackDoor = game.lastRoomIdx == ROOM_DEVIL_IDX && slot >= 0 && descriptor->data->doors & 1u << slot &&
|
|
!doors[slot];
|
|
if (!isBackDoor) slot = deal_door_slot_get(*this, *devilRoom.data);
|
|
if (slot < 0) return false;
|
|
|
|
int type = devilRoom.data->type;
|
|
if (type == ROOM_DEVIL) game.gameStateFlags |= GAME_STATE_DEVILROOM_SPAWNED_BITS;
|
|
else if (type == ROOM_ANGEL) game.gameStateFlags |= GAME_STATE_ANGEL_DOOR_BITS;
|
|
|
|
if (!doors[slot]) MakeDoor(slot);
|
|
doors[slot]->SetRoomTypes(ROOM_DEFAULT, type);
|
|
doors[slot]->targetRoomIdx = ROOM_DEVIL_IDX;
|
|
doors[slot]->Open();
|
|
game.lastDevilRoomStage = deal_stage_get();
|
|
if (isAnimate)
|
|
{
|
|
deal_jingle_play(type == ROOM_DEVIL ? SOUND_DEVIL_DOOR_APPEAR : SOUND_ANGEL_DOOR_APPEAR);
|
|
door_dust_spawn(*this, *doors[slot], {.style = DUST_DEAL, .subType = type == ROOM_DEVIL ? 1 : 0});
|
|
}
|
|
game.devilAngelRoomRNG.Next();
|
|
return true;
|
|
}
|
|
|
|
// 007f9960 Opens the Boss Rush door in Mom's room (Depths II) cleared within the par time, or anytime with Mom's
|
|
// Shovel, once: Mom's leftover parts by the door go away when the time did not count.
|
|
bool Room::TrySpawnBossRushDoor(bool isIgnoreTime, bool isForce)
|
|
{
|
|
Game& game = *g_game;
|
|
bool isAllowed = game.challenge != CHALLENGE_RED_REDEMPTION && !is_path_closed(*this) &&
|
|
game.currentDimensionIdx == 0 && is_last_boss_room() && !game.IsMausoleumHeartStage();
|
|
if (!isForce && !isAllowed) return false;
|
|
if (!isForce && labyrinth_stage_get() != STAGE_DEPTHS_II) return false;
|
|
if (is_door_to(*this, ROOM_BOSSRUSH_IDX)) return false;
|
|
|
|
if (game.playerManager.FirstCollectibleOwner(COLLECTIBLE_BROKEN_SHOVEL, LAZARUS_SHARE_CHECK)) isIgnoreTime = true;
|
|
log_printf(LOG_INFO, "Mom clear time: %d\n", game.timeCounter);
|
|
log_printf(LOG_INFO, "Par time: %d\n", game.bossRushParTime);
|
|
if (game.timeCounter > game.bossRushParTime && !isIgnoreTime && !isForce)
|
|
{
|
|
KAGE_LogMessage(LOG_INFO, (uint8_t*)"Did not meet par time, did not spawn boss rush door.\n");
|
|
return false;
|
|
}
|
|
|
|
KAGE_LogMessage(LOG_INFO, (uint8_t*)"Spawning boss rush door\n");
|
|
int slot = special_door_slot_get(*this, ROOM_BOSSRUSH_IDX);
|
|
if (!doors[slot]) MakeDoor(slot);
|
|
doors[slot]->SetRoomTypes(descriptor->data->type, ROOM_BOSSRUSH);
|
|
doors[slot]->targetRoomIdx = ROOM_BOSSRUSH_IDX;
|
|
doors[slot]->Open();
|
|
doors[slot]->SpawnDust();
|
|
game.gameStateFlags |= 1ull << GAME_STATE_BOSSRUSH_DOOR_SPAWNED;
|
|
if (!isIgnoreTime) return true;
|
|
|
|
Vector doorPosition = GetGridPosition(doors[slot]->gridIndex);
|
|
size_t count = entityList.updateEL.size();
|
|
for (size_t i = 0; i < count; i++)
|
|
{
|
|
Entity& entity = *entityList.updateEL[i];
|
|
if (entity.type != ENTITY_MOM || entity.variant != 0) continue;
|
|
|
|
float dx = doorPosition.x - entity.pos.x;
|
|
float dy = doorPosition.y - entity.pos.y;
|
|
if (dy * dy + dx * dx < MOM_DOOR_CLEARANCE * MOM_DOOR_CLEARANCE) entity.Remove();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// 008204b0 Opens the Void's door at the top right of Blue Womb's boss room on a run that may go there. A run that cannot
|
|
// marks the floor so it stops asking.
|
|
bool Room::TrySpawnTheVoidDoor(bool isForce)
|
|
{
|
|
Game& game = *g_game;
|
|
if (!isForce && game.challenge == CHALLENGE_RED_REDEMPTION) return false;
|
|
|
|
int stage = labyrinth_stage_get();
|
|
if (!isForce)
|
|
{
|
|
if (stage != STAGE_BLUE_WOMB || descriptor->data->type != ROOM_BOSS || game.currentRoomIdx < 0) return false;
|
|
|
|
ChallengeParam& params = game.GetChallengeParams();
|
|
bool isVoidUnlocked = !is_challenge_or_daily() && is_unlocked(ACHIEVEMENT_THE_VOID);
|
|
int endStage = params.endStage == STAGE_THE_VOID || isVoidUnlocked ? STAGE_THE_VOID : STAGE_DARK_ROOM_CHEST;
|
|
bool isClosed = is_greed();
|
|
if (!isClosed && params.isPathTypeSet)
|
|
{
|
|
if (params.endStage != 0) endStage = params.endStage;
|
|
isClosed = params.pathType == PATH_TYPE_HOME;
|
|
}
|
|
if (isClosed || endStage < STAGE_THE_VOID || game.levelStateFlags & LEVEL_STATE_VOID_DOOR_DISABLED)
|
|
{
|
|
game.levelStateFlags |= LEVEL_STATE_VOID_DOOR_DISABLED;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
ChallengeParam& params = game.GetChallengeParams();
|
|
if (!isForce && params.isPathTypeSet && stage >= params.endStage)
|
|
{
|
|
game.levelStateFlags |= LEVEL_STATE_VOID_DOOR_DISABLED;
|
|
return false;
|
|
}
|
|
GridEntity_Door& door = special_door_make(*this, DOOR_UP1, ROOM_THE_VOID_IDX);
|
|
door.SetRoomTypes(descriptor->data->type, ROOM_DEFAULT);
|
|
door.Open();
|
|
return true;
|
|
}
|
|
|
|
// 00820170 Opens Blue Womb's door in the boss room of Womb II (not on the alternate path), once Blue Womb is unlocked,
|
|
// for a clear within the par time, or anytime with the Strange Key or when the time is ignored.
|
|
bool Room::TrySpawnBlueWombDoor(bool isFirstTime, bool isIgnoreTime, bool isForce)
|
|
{
|
|
Game& game = *g_game;
|
|
if (!isForce && (game.challenge == CHALLENGE_RED_REDEMPTION || !is_unlocked(ACHIEVEMENT_BLUE_WOMB))) return false;
|
|
|
|
if (game.playerManager.AnyoneHasTrinket(TRINKET_STRANGE_KEY)) isIgnoreTime = true;
|
|
if (!isForce && !is_last_boss_room()) return false;
|
|
|
|
int stage = labyrinth_stage_get();
|
|
ChallengeParam& params = game.GetChallengeParams();
|
|
bool isAltStage = game.stageType == STAGETYPE_REPENTANCE || game.stageType == STAGETYPE_REPENTANCE_B;
|
|
bool isAllowed = (!params.isPathTypeSet || stage < params.endStage) && stage == STAGE_MAUSOLEUM_II && !isAltStage;
|
|
if (!isForce && !isAllowed) return false;
|
|
if (is_door_to(*this, ROOM_BLUE_WOMB_IDX)) return false;
|
|
if (game.timeCounter > game.blueWombParTime && !isIgnoreTime && !isForce) return false;
|
|
|
|
int slot = special_door_slot_get(*this, ROOM_BLUE_WOMB_IDX);
|
|
GridEntity_Door& door = special_door_make(*this, slot, ROOM_BLUE_WOMB_IDX);
|
|
door.SetRoomTypes(descriptor->data->type, ROOM_DEFAULT);
|
|
door.Open();
|
|
if (isFirstTime) door.SpawnDust();
|
|
game.gameStateFlags |= 1ull << GAME_STATE_BLUEWOMB_DOOR_SPAWNED;
|
|
return true;
|
|
}
|
|
|
|
// 007f8190 Puts the Member Card's stairs down to the secret shop in a shop (a ladder back up in a room off the map),
|
|
// on the top right of the room, with their sound. Forced, anywhere.
|
|
bool Room::TrySpawnSecretShop(bool isForce)
|
|
{
|
|
Game& game = *g_game;
|
|
bool isMemberCard = game.playerManager.FirstCollectibleOwner(COLLECTIBLE_MEMBER_CARD, LAZARUS_SHARE_CHECK);
|
|
if (!isForce && (roomType != ROOM_SHOP || (!isMemberCard && descriptor->gridIndex >= 0))) return false;
|
|
|
|
bool isWide = descriptor->data->shape == ROOMSHAPE_2x1;
|
|
int gridIndex = isWide ? GetGridIndexByTile(SECRET_SHOP_COLUMN * 2, 2) : GetGridIndexByTile(SECRET_SHOP_COLUMN, 1);
|
|
if (descriptor->gridIndex < 0)
|
|
{
|
|
uint32_t seed = Random();
|
|
entity_spawn(ENTITY_EFFECT, EFFECT_SHOP_LADDER, GetGridPosition(gridIndex), 0, seed);
|
|
return true;
|
|
}
|
|
|
|
int sound = SOUND_SHOP_STAIRS;
|
|
seed_fart_sound_override(&sound);
|
|
g_manager->sfxManager.Play(sound);
|
|
uint32_t seed = Random();
|
|
if (gridIndex < 0 || gridIndex >= ROOM_GRID_CELLS)
|
|
KAGE_LogMessage(LOG_ASSERT, (uint8_t*)"SpawnGridEntity: Grid index invalid\n");
|
|
if ((uint32_t)gridIndex >= ROOM_GRID_CELLS || (int)GetGridCollision(gridIndex) >= 1) return true;
|
|
|
|
GridEntity* stairs = CreateGridEntity(GRID_STAIRS, gridIndex);
|
|
delete gridEntities[gridIndex];
|
|
gridEntities[gridIndex] = stairs;
|
|
stairs->variant = STAIRS_SECRET_SHOP;
|
|
stairs->varData = 0;
|
|
stairs->Init(seed);
|
|
return true;
|
|
}
|
|
|
|
// Whether a player holds the Red Key's power: a Cracked Key or Soul of Cain in a pocket, or the Red Key inside the
|
|
// Void.
|
|
static bool is_red_key_held(Entity_Player& player)
|
|
{
|
|
for (int slot = 0; slot < POCKET_SLOT_COUNT; slot++)
|
|
{
|
|
PocketItem& pocket = player.pocketItems[std::clamp(slot, 0, 3)];
|
|
if (pocket.type == POCKET_CARD && (pocket.id == CARD_CRACKED_KEY || pocket.id == CARD_SOUL_OF_CAIN)) return true;
|
|
}
|
|
for (ActiveItemDesc& active : player.activeItems)
|
|
if (active.item == COLLECTIBLE_VOID)
|
|
return std::ranges::find(player.voidedCollectibles, COLLECTIBLE_RED_KEY) != player.voidedCollectibles.end();
|
|
return false;
|
|
}
|
|
|
|
// 008271e0 Shows the outlines of the red doors the Red Key could open, on the room's free door slots that lead
|
|
// somewhere new (not from the floor's last boss room or a room off the map), or removes them when nobody can.
|
|
void Room::UpdateRedKey()
|
|
{
|
|
Game& game = *g_game;
|
|
bool isRedKey = std::ranges::any_of(game.playerManager.playerList, [](Entity_Player* player) { return is_red_key_held(*player); });
|
|
if (!isRedKey && !game.playerManager.FirstCollectibleOwner(COLLECTIBLE_RED_KEY, LAZARUS_SHARE_CHECK))
|
|
{
|
|
for (EntityPtr& outline : redDoorOutlines)
|
|
{
|
|
if (!outline) continue;
|
|
static_cast<Entity*>(outline)->Remove();
|
|
outline.Set(nullptr);
|
|
}
|
|
return;
|
|
}
|
|
|
|
constexpr float DOOR_ANGLES[4] = {-90, 0, 90, 180};
|
|
bool isLastBossRoom = descriptor->data->type == ROOM_BOSS && descriptor->listIndex == game.lastBossRoomListIdx;
|
|
if (isLastBossRoom || descriptor->gridIndex < 0) return;
|
|
|
|
for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++)
|
|
{
|
|
bool isFree = descriptor->data->doors & 1u << slot && !doors[slot];
|
|
if (redDoorOutlines[slot] || !isFree || !game.CanSpawnDoorOutline(descriptor->safeGridIndex, slot)) continue;
|
|
|
|
uint32_t seed = Random();
|
|
Entity* outline = entity_spawn(ENTITY_EFFECT, EFFECT_DOOR_OUTLINE, GetGridPosition(doorGridPositions[slot]), 0, seed);
|
|
float angle = DOOR_ANGLES[slot & 3];
|
|
float radians = (angle + 90) * DEGREES_TO_RADIANS;
|
|
outline->sprite.rotation = angle;
|
|
outline->sprite.offset = vector_make(std::cos(radians) * DOOR_OUTLINE_OFFSET, std::sin(radians) * DOOR_OUTLINE_OFFSET);
|
|
redDoorOutlines[slot].Set(outline);
|
|
}
|
|
}
|
|
|
|
// 00820ac0 Turns the room's grid and pickups gold (Ultra Greedier's room).
|
|
void Room::TurnGold()
|
|
{
|
|
reconstruction_missing("Room::TurnGold 00820ac0");
|
|
}
|
|
|
|
// 00827bf0 Spawns Sanguine Bond's spikes.
|
|
bool Room::spawn_sanguine_bond_spikes(bool)
|
|
{
|
|
reconstruction_missing("Room::spawn_sanguine_bond_spikes 00827bf0");
|
|
}
|
|
|
|
// 008167e0 Removes the door in a slot.
|
|
void Room::RemoveDoor(int)
|
|
{
|
|
reconstruction_missing("Room::RemoveDoor 008167e0");
|
|
}
|
|
|
|
// 007fe220 Fills the room with the Card Against Humanity's poop.
|
|
void Room::card_against_humanity_fill()
|
|
{
|
|
reconstruction_missing("Room::card_against_humanity_fill 007fe220");
|
|
}
|
|
|