3278 lines
145 KiB
C++
3278 lines
145 KiB
C++
#include "level.h"
|
|
#include "boss_pool.h"
|
|
#include "entity_familiar.h"
|
|
#include "entity_player.h"
|
|
#include "game.h"
|
|
#include "grid_entity_door.h"
|
|
#include "hud.h"
|
|
#include "lua_engine.h"
|
|
#include "menu_special_seeds.h"
|
|
#include "music_manager.h"
|
|
#include "manager.h"
|
|
#include "platform.h"
|
|
#include "room.h"
|
|
#include "room_transition.h"
|
|
#include "texture_cache.h"
|
|
#include <algorithm>
|
|
#include <bit>
|
|
#include <bitset>
|
|
#include <cmath>
|
|
#include <iterator>
|
|
#include <utility>
|
|
|
|
// Where GetEnterPosition puts the players: a crawlspace's ladder down and its ladder back up, the Black Market's
|
|
// stairs, and the spots of the secret shop and the two off-map rooms between it and the Black Market.
|
|
constexpr float DUNGEON_ENTRY_X = 120;
|
|
constexpr float DUNGEON_ENTRY_Y = 160;
|
|
constexpr float DUNGEON_EXIT_X = 480;
|
|
constexpr float DUNGEON_EXIT_Y = 280;
|
|
constexpr float BLACK_MARKET_EXIT_X = 560;
|
|
constexpr float SECRET_SHOP_ENTRY_X = 440;
|
|
constexpr float SECRET_SHOP_ENTRY_Y = 168;
|
|
constexpr int ROOM_OFF_MAP_14_IDX = -14;
|
|
constexpr float OFF_MAP_14_ENTRY_X = 320;
|
|
constexpr float OFF_MAP_14_ENTRY_Y = 160;
|
|
constexpr int ROOM_OFF_MAP_15_IDX = -15;
|
|
constexpr float OFF_MAP_15_ENTRY_X = 80;
|
|
constexpr float OFF_MAP_15_ENTRY_Y = 400;
|
|
|
|
constexpr uint32_t ASCENT_LAST_STAGE = 6;
|
|
constexpr int VOID_STAGE_ID_LAST = 17;
|
|
|
|
constexpr uint32_t CHALLENGE_XXXXXXXXL = 21;
|
|
|
|
// The Ascent's music: the alternate path's stages take the layers past the chapters'.
|
|
constexpr int ALT_PATH_LAYER_FIRST = 3;
|
|
constexpr int DIMENSION_MINESHAFT = 2;
|
|
constexpr int ENEMY_TYPE_LAST = 999;
|
|
|
|
// The enemies' health that makes a room's music intense, growing with the floor (a Greed floor counting as two).
|
|
constexpr float INTENSE_HEALTH_BASE = 40;
|
|
constexpr float INTENSE_HEALTH_PER_STAGE = 14;
|
|
constexpr float INTENSE_HEALTH_ALWAYS = 10000;
|
|
constexpr float MINESHAFT_HEALTH_PER_PIT = 3;
|
|
constexpr int GREED_STAGE_LAST_PAIRED = 4;
|
|
constexpr int GREED_STAGE_SHOP = 5;
|
|
constexpr int GREED_DEPTH_SHOP = 10;
|
|
|
|
// The endless basement's floor number as roman numerals, and the counts its jokes start at.
|
|
struct RomanNumeral
|
|
{
|
|
int value;
|
|
const char* text;
|
|
};
|
|
constexpr RomanNumeral ROMAN_NUMERALS[] = {{1000, "M"}, {900, "CM"}, {500, "D"}, {400, "CD"}, {100, "C"}, {90, "XC"},
|
|
{50, "L"}, {40, "XL"}, {10, "X"}, {9, "IX"}, {5, "V"}, {4, "IV"},
|
|
{1, "I"}};
|
|
constexpr uint32_t NUMERAL_QUESTION = 3;
|
|
constexpr uint32_t NUMERAL_EXCLAIM = 4;
|
|
constexpr uint32_t NUMERAL_ELLIPSIS = 5;
|
|
constexpr uint32_t NUMERAL_SPIKES = 1001;
|
|
constexpr std::string_view DEATHMATCH_NAME_KEY = "Online/DEATHMATCH_NAME";
|
|
constexpr uint32_t SPECIAL_DAILY_NO_CURSES = 18;
|
|
constexpr uint32_t SPECIAL_DAILY_DEALS = 17;
|
|
constexpr uint32_t SPECIAL_DAILY_CURSED = 37;
|
|
constexpr uint32_t SPECIAL_DAILY_CURSES = CURSE_OF_THE_LOST | CURSE_OF_THE_UNKNOWN | CURSE_OF_BLIND;
|
|
|
|
constexpr int ACHIEVEMENT_EVERYTHING_IS_TERRIBLE = 33;
|
|
constexpr int ACHIEVEMENT_STRANGE_DOOR = 635;
|
|
constexpr int ACHIEVEMENT_SOMETHING_FROM_THE_FUTURE = 16;
|
|
constexpr int ACHIEVEMENT_SOMETHING_CUTE = 17;
|
|
constexpr int ACHIEVEMENT_SOMETHING_STICKY = 18;
|
|
constexpr int ACHIEVEMENT_SOMETHING_ICKY = 68;
|
|
constexpr int ACHIEVEMENT_STORE_UPGRADE_1 = 151;
|
|
constexpr int ACHIEVEMENT_STORE_UPGRADE_2 = 152;
|
|
constexpr int ACHIEVEMENT_STORE_UPGRADE_3 = 153;
|
|
constexpr int ACHIEVEMENT_STORE_UPGRADE_4 = 154;
|
|
constexpr int ACHIEVEMENT_SOMETHING_WICKED = 346;
|
|
constexpr int ACHIEVEMENT_SOMETHING_WICKED_PLUS = 347;
|
|
constexpr int ACHIEVEMENT_THE_FORGOTTEN = 390;
|
|
constexpr int ACHIEVEMENT_PLANETARIUMS = 406;
|
|
constexpr int EVENT_COUNTER_SUPER_SINS_A = 24;
|
|
constexpr int EVENT_COUNTER_SUPER_SINS_B = 25;
|
|
constexpr int EVENT_COUNTER_CURSE_ODDS = 11;
|
|
constexpr int COLLECTIBLE_XRAY_VISION = 76;
|
|
constexpr int COLLECTIBLE_CRYSTAL_BALL = 158;
|
|
constexpr int COLLECTIBLE_MAGIC_8_BALL = 194;
|
|
constexpr int COLLECTIBLE_MOMS_SHOVEL = 552;
|
|
constexpr int TRINKET_GOLDEN_HORSE_SHOE = 82;
|
|
constexpr int TRINKET_FRAGMENTED_CARD = 102;
|
|
constexpr int TRINKET_SILVER_DOLLAR = 110;
|
|
constexpr int TRINKET_PAY_TO_WIN = 112;
|
|
constexpr int TRINKET_TELESCOPE_LENS = 152;
|
|
constexpr int COLLECTIBLE_VOODOO_HEAD = 599;
|
|
constexpr int TRINKET_MYOSOTIS = 137;
|
|
constexpr int TRINKET_DEVILS_CROWN = 146;
|
|
constexpr int TREASURE_SUBTYPE_KNIFE_PIECE = 34;
|
|
constexpr int LIL_PORTAL_ROOM_VARIANT = 2;
|
|
constexpr int GRID_SPAWN_PIT_FIRST = 3000;
|
|
constexpr int GRID_SPAWN_PIT_END = 3010;
|
|
constexpr int ROOM_INDEX_OTHER_DIMENSION = -100;
|
|
constexpr int ROOM_INDEX_MIRRORED_START = -101;
|
|
constexpr int MIRROR_START_GRID_INDEX = 162;
|
|
constexpr int MIRROR_START_SUBTYPE = 10;
|
|
constexpr int BOSS_RUSH_PAR_TIME = 36000;
|
|
constexpr int BOSS_RUSH_PAR_TIME_ALT = 45000;
|
|
constexpr uint32_t BACKWARDS_STAGE_END = 8;
|
|
constexpr size_t BACKWARDS_ROOMS_KEPT = 2;
|
|
constexpr uint32_t RANDOM_ROOM_SHIFT_INDEX = 16;
|
|
constexpr uint32_t BLACK_MARKET_TELEPORT_ODDS = 50;
|
|
constexpr int CHALLENGE_SUBTYPE_BOSS = 1;
|
|
constexpr int CHALLENGE_LOW_HEALTH = 2;
|
|
|
|
constexpr int STATE_GREED_SPAWNED = 15;
|
|
constexpr int STATE_SUPER_GREED_SPAWNED = 16;
|
|
constexpr int STATE_DONATION_SLOT_BLOWN = 30;
|
|
constexpr int STATE_SHOPKEEPER_KILLED = 31;
|
|
constexpr int STATE_ULTRA_PRIDE_SPAWNED = 32;
|
|
constexpr int DEATH_CERTIFICATE_DIMENSION = 2;
|
|
constexpr int ROOM_SCREEN_WIDTH = 13;
|
|
constexpr int ROOM_SCREEN_HEIGHT = 7;
|
|
constexpr int START_ROOM_VARIANT = 2;
|
|
constexpr int ULTRA_SECRET_GROUP = 99;
|
|
constexpr int BOSS_MEGA_SATAN = 55;
|
|
constexpr int BOSS_MOTHER = 88;
|
|
constexpr int BOSS_MOTHER_HEART = 89;
|
|
constexpr int BOSS_ROOM_RETRIES = 50;
|
|
constexpr int BOSS_ROOM_VARIANTS = 50;
|
|
constexpr int BOSS_ROOM_REROLL_FIRST = 3700;
|
|
constexpr int BOSS_ROOM_REROLL_END = 3850;
|
|
constexpr int VOID_EXTRA_BOSS_ROLL = 4;
|
|
constexpr int VOID_EXTRA_BOSSES_MIN = 5;
|
|
constexpr int SHOP_LEVEL_MAX = 4;
|
|
constexpr int SHOP_SUBTYPE_RARE = 10;
|
|
constexpr int SHOP_SUBTYPE_STORE_KEY = 11;
|
|
constexpr int SHOP_SUBTYPE_TAINTED_KEEPER = 100;
|
|
constexpr int TREASURE_SUBTYPE_OPTIONS = 1;
|
|
constexpr int TREASURE_SUBTYPE_PAY_TO_WIN = 2;
|
|
constexpr int TREASURE_SUBTYPE_OPTIONS_PAY_TO_WIN = 3;
|
|
constexpr uint32_t TREASURE_OPTIONS_ODDS = 100;
|
|
constexpr uint32_t HORSE_SHOE_PERIOD = 100;
|
|
constexpr uint32_t HORSE_SHOE_HITS = 15;
|
|
constexpr uint32_t SPECIAL_DAILY_TREASURE_OPTIONS = 19;
|
|
constexpr uint32_t DICE_ROOM_ODDS = 50;
|
|
constexpr uint32_t DICE_ROOM_KEY_ODDS = 5;
|
|
constexpr uint32_t SACRIFICE_ROOM_ODDS = 7;
|
|
constexpr uint32_t LIBRARY_ODDS = 20;
|
|
constexpr int SUPER_SIN_ODDS = 80;
|
|
constexpr int SUPER_SIN_ODDS_WOMB = 30;
|
|
constexpr int SUPER_SIN_ODDS_TERRIBLE = 10;
|
|
constexpr int SUPER_SIN_ODDS_EVENT = 5;
|
|
constexpr uint32_t ULTRA_PRIDE_ODDS = 10;
|
|
constexpr int SIN_ULTRA_PRIDE = 14;
|
|
constexpr uint32_t CHEST_ROOM_ODDS = 10;
|
|
constexpr uint32_t CHEST_ROOM_KEY_ODDS = 3;
|
|
constexpr uint32_t BEDROOM_ODDS = 50;
|
|
constexpr uint32_t BEDROOM_DYING_ODDS = 5;
|
|
constexpr int MIRROR_ROOM_SUBTYPE = 34;
|
|
constexpr int MINESHAFT_ENTRANCE_SUBTYPE = 10;
|
|
constexpr int SPECIAL_DOOR_PUZZLE_SUBTYPE = 1;
|
|
constexpr uint32_t DARK_ROOM_EXTRA_VARIANT_FIRST = 3;
|
|
constexpr uint32_t DARK_ROOM_EXTRA_VARIANT_LAST = 9;
|
|
constexpr int TAKEOVER_COINS = 20;
|
|
constexpr float TAKEOVER_CHANCE_RICH = 1.05f;
|
|
constexpr int TAKEOVER_DONATIONS_MAX = 5;
|
|
constexpr float TAKEOVER_DONATION_PENALTY = 0.05f;
|
|
constexpr float TAKEOVER_SHARE = 0.33333334f;
|
|
constexpr uint32_t TAKEOVER_BOTH_ODDS = 1000;
|
|
constexpr float PLANETARIUM_CHANCE_MIN = 0.01f;
|
|
constexpr float PLANETARIUM_SKIPPED_BONUS = 0.2f;
|
|
constexpr float PLANETARIUM_ITEM_BONUS = 0.15f;
|
|
constexpr float PLANETARIUM_SAUSAGE_BONUS = 0.069f;
|
|
constexpr float PLANETARIUM_LENS = 0.09f;
|
|
constexpr float PLANETARIUM_LENS_ONE = 0.18f;
|
|
constexpr float PLANETARIUM_LENS_BOTH = 0.33f;
|
|
|
|
// The bosses the Void may add boss rooms for, in the order they are shuffled from.
|
|
constexpr std::array<int, 31> VOID_BOSS_IDS = {0, 5, 7, 8, 11, 12, 15, 16, 19, 22, 24, 25, 30, 31, 33, 35,
|
|
38, 39, 40, 41, 42, 46, 48, 49, 51, 53, 54, 58, 59, 66, 68};
|
|
|
|
// The run state flags that raise Greed's takeover chance once, each cleared as it counts.
|
|
constexpr std::array<std::pair<int, float>, 2> TAKEOVER_BONUSES = {
|
|
{{STATE_DONATION_SLOT_BLOWN, 0.1f}, {STATE_SHOPKEEPER_KILLED, 0.02f}}};
|
|
|
|
// A sin a miniboss room fights: the run state flag of meeting it, and its normal and super subtypes.
|
|
struct MinibossSin
|
|
{
|
|
int flag = 0;
|
|
int subtype = 0;
|
|
int superSubtype = 0;
|
|
};
|
|
|
|
// The sins, in the order a miniboss room draws them: Wrath, Gluttony, Lust, Sloth, Envy, Pride.
|
|
constexpr std::array<MinibossSin, 6> MINIBOSS_SINS = {
|
|
{{9, 2, 9}, {10, 3, 10}, {11, 1, 8}, {12, 0, 7}, {13, 5, 12}, {14, 6, 13}}};
|
|
|
|
// A Double Trouble pairing (boss room subtypes firstSubtype to lastSubtype) an achievement unlocks.
|
|
struct DoubleTroubleLock
|
|
{
|
|
int achievement = 0;
|
|
int firstSubtype = 0;
|
|
int lastSubtype = 0;
|
|
|
|
bool is_locked(int subtype) const
|
|
{
|
|
return subtype >= firstSubtype && subtype <= lastSubtype &&
|
|
!g_manager->persistentGameData.Unlocked(achievement);
|
|
}
|
|
};
|
|
|
|
constexpr std::array<DoubleTroubleLock, 6> DOUBLE_TROUBLE_LOCKS = {{{ACHIEVEMENT_SOMETHING_FROM_THE_FUTURE, 20, 20},
|
|
{ACHIEVEMENT_SOMETHING_CUTE, 21, 21},
|
|
{ACHIEVEMENT_SOMETHING_STICKY, 19, 19},
|
|
{ACHIEVEMENT_SOMETHING_ICKY, 42, 42},
|
|
{ACHIEVEMENT_SOMETHING_WICKED, 57, 66},
|
|
{ACHIEVEMENT_SOMETHING_WICKED_PLUS, 67, 72}}};
|
|
|
|
constexpr int DEVILS_CROWN_TRIES = 10;
|
|
|
|
// The deal room draws ten times among the first 100 variants (the Womb's special one is 100). Krampus waits in 1 in
|
|
// 20 devil rooms after a visited one, 3 with a deal taken, 10 more on the deals daily.
|
|
constexpr int DEAL_ROOM_TRIES = 10;
|
|
constexpr uint32_t DEAL_VARIANT_LAST = 99;
|
|
constexpr uint32_t DEAL_VARIANT_WOMB = 100;
|
|
constexpr uint32_t KRAMPUS_ROLL = 20;
|
|
constexpr uint32_t KRAMPUS_ODDS_VISITED = 1;
|
|
constexpr uint32_t KRAMPUS_ODDS_DEAL = 3;
|
|
constexpr uint32_t KRAMPUS_ODDS_DEALS_DAILY = 10;
|
|
|
|
// The angel chance starts at 1 (half after Famine or a visited devil room) and each item adds a quarter of what is
|
|
// left, ten donations half, a beggar left a tenth. Eucharist sets it past 1.
|
|
constexpr float ANGEL_CHANCE_HALVED = 0.5f;
|
|
constexpr float ANGEL_ITEM_SHARE = 0.25f;
|
|
constexpr float ANGEL_DONATION_SHARE = 0.5f;
|
|
constexpr float ANGEL_BEGGAR_SHARE = 0.1f;
|
|
constexpr int ANGEL_DONATIONS = 10;
|
|
constexpr float ANGEL_CHANCE_EUCHARIST = 77;
|
|
constexpr uint32_t DEVILS_CROWN_VARIANT_LAST = 99;
|
|
constexpr int GREED_SUBTYPE = 4;
|
|
constexpr int GREED_SUBTYPE_SUPER = 11;
|
|
constexpr int GREED_SUBTYPE_DEVIL = 15;
|
|
constexpr int RED_ROOM_DOOR_TARGET = -2;
|
|
constexpr int HUD_REFRESH_FRAMES = 2;
|
|
constexpr int EFFECT_VARIANT_BLOOD_SPLAT = 7;
|
|
constexpr uint32_t TRANSITION_FLAG_TREASURE_REROLL = 1 << 0;
|
|
constexpr uint32_t TRANSITION_FLAG_NO_TAKEOVER = 1 << 1;
|
|
constexpr int SPLAT_COUNT = 9;
|
|
constexpr float SPLAT_STEP = 0.125f;
|
|
constexpr float SPLAT_DOOR_OFFSET = 20;
|
|
constexpr float SPLAT_LENGTH = 128;
|
|
constexpr float SPLAT_SPREAD = 40;
|
|
constexpr float SPLAT_SCALE_RANGE = 5;
|
|
constexpr float SPLAT_SCALE_MIN = 0.5f;
|
|
constexpr float QUARTER_TURN = 1.5707964f;
|
|
constexpr ColorMod SPLAT_COLOR = {{0.8f, 0.8f, 0.8f, 1}, {0, 0, 0, 0}, {0, 0, 0}};
|
|
|
|
// The cell offsets of the four sides: left, up, right, down.
|
|
constexpr std::array<XY, 4> CARDINAL_OFFSETS = {{{-1, 0}, {0, -1}, {1, 0}, {0, 1}}};
|
|
|
|
// The rooms off the map whose entry door leads back to the room the players came from.
|
|
constexpr std::array<int, 9> OFF_MAP_ENTRY_ROOMS = {ROOM_DEVIL_IDX, ROOM_BLACK_MARKET_IDX, ROOM_DEBUG_IDX,
|
|
ROOM_BOSSRUSH_IDX, ROOM_BLUE_WOMB_IDX, ROOM_THE_VOID_IDX,
|
|
ROOM_SECRET_EXIT_IDX, ROOM_EXTRA_BOSS_IDX, ROOM_ANGEL_SHOP_IDX};
|
|
|
|
// The rooms whose doors out of a Corpse room get blood splats when they use the alternate backdrop.
|
|
constexpr std::array<int, 4> CORPSE_SPLAT_ROOM_TYPES = {ROOM_DEFAULT, ROOM_TREASURE, ROOM_MINIBOSS, ROOM_BOSS};
|
|
|
|
constexpr XY START_POSITION = {6, 6};
|
|
constexpr XY PHOTO_DOOR_CELL = {6, 5};
|
|
constexpr int START_GRID_INDEX = 84;
|
|
constexpr float DUNGEON_RETURN_X = 320;
|
|
constexpr float DUNGEON_RETURN_Y = 280;
|
|
constexpr int ROOM_COUNT_MAX = 20;
|
|
constexpr int ROOM_COUNT_LABYRINTH_MAX = 45;
|
|
constexpr double ROOM_COUNT_LABYRINTH_SCALE = 1.8;
|
|
constexpr int ROOM_COUNT_LOST_BONUS = 4;
|
|
constexpr int ROOM_COUNT_ALT_EXTRA_DIMENSION = 3;
|
|
constexpr int ROOM_COUNT_XXXXXXXXL = 40;
|
|
constexpr int ROOM_COUNT_VOID = 50;
|
|
constexpr int ROOM_COUNT_ROLL = 5;
|
|
constexpr int ROOM_COUNT_HARD_BONUS = 2;
|
|
constexpr int ROOM_COUNT_GIANT_MIN = 4;
|
|
constexpr int ROOM_COUNT_RETRY_MAX = 64;
|
|
constexpr int ROOM_POOL_MIN = 20;
|
|
constexpr int RETRIES_LOGGED = 99;
|
|
constexpr int RETRIES_BEFORE_GROWTH = 9;
|
|
constexpr int RETRY_GROWTH_PERIOD = 5;
|
|
constexpr int DIFFICULTY_EASY = 1;
|
|
constexpr int DIFFICULTY_MEDIUM = 5;
|
|
constexpr int DIFFICULTY_HARD_MAX = 10;
|
|
constexpr int DIFFICULTY_MAX = 15;
|
|
constexpr int CURSE_PICKS = 6;
|
|
constexpr int DEAD_ENDS_BASE = 5;
|
|
constexpr int DEAD_ENDS_VOID_BONUS = 2;
|
|
constexpr int ROOM_COUNT_BASE = 5;
|
|
constexpr int ROOM_COUNT_STAGE_TENTHS = 10;
|
|
constexpr int ROOM_COUNT_STAGE_DIVISOR = 3;
|
|
constexpr int GIANT_ROOM_SHARE = 3;
|
|
constexpr int GIANT_ROOM_DIVISOR = 5;
|
|
constexpr int CORPSE_BACKDROP_ODDS = 5;
|
|
constexpr uint32_t GENERATION_SHIFT_INDEX = 35;
|
|
constexpr uint32_t DEVIL_ANGEL_SHIFT_INDEX = 2;
|
|
constexpr uint32_t ROOM_SEEDS_SHIFT_INDEX = 12;
|
|
constexpr uint32_t LIL_PORTAL_SHIFT_INDEX = 25;
|
|
constexpr uint32_t CORPSE_BACKDROP_SHIFT_INDEX = 7;
|
|
|
|
// The curse odds (1 in n) by unlock, for normal and hard runs.
|
|
constexpr std::array<int, 2> CURSE_ODDS_START = {80, 40};
|
|
constexpr std::array<int, 2> CURSE_ODDS_WOMB = {30, 20};
|
|
constexpr std::array<int, 2> CURSE_ODDS_TERRIBLE = {10, 6};
|
|
constexpr std::array<int, 2> CURSE_ODDS_DAILY = {5, 3};
|
|
|
|
// Whether a run state flag is set.
|
|
static bool game_flag_get(int flag)
|
|
{
|
|
return g_game->gameStateFlags >> flag & 1;
|
|
}
|
|
|
|
// Sets or clears a run state flag.
|
|
static void game_flag_set(int flag, bool isSet)
|
|
{
|
|
g_game->gameStateFlags = isSet ? g_game->gameStateFlags | 1ull << flag : g_game->gameStateFlags & ~(1ull << flag);
|
|
}
|
|
|
|
static bool is_greed()
|
|
{
|
|
return g_game->difficulty == DIFFICULTY_GREED || g_game->difficulty == DIFFICULTY_GREEDIER;
|
|
}
|
|
|
|
static bool is_unlocked(int achievement)
|
|
{
|
|
return g_manager->persistentGameData.Unlocked(achievement);
|
|
}
|
|
|
|
// 0074d8d0 Whether a room is a treasure room Devil's Crown turns: not a knife piece room, not visited yet, and in
|
|
// Greed only the floor's treasure room.
|
|
static bool is_devils_crown_room(Level& level, RoomDescriptor& room)
|
|
{
|
|
return room.data->type == ROOM_TREASURE && room.data->subtype != TREASURE_SUBTYPE_KNIFE_PIECE &&
|
|
(!is_greed() || (uint32_t)room.gridIndex == level.greedModeTreasureRoomIdx) && room.visitedCount == 0;
|
|
}
|
|
|
|
// 00744940 Lays out the floor: seeds its RNGs from the stage seed, rolls its curse, loads the stage's rooms, generates
|
|
// the layout the floor calls for, then enters the start room (or the boss room on the Ascent) and starts the floor.
|
|
void Level::Init(bool isResetLilPortalRoom)
|
|
{
|
|
Game& game = *g_game;
|
|
bool isMyosotis = game.playerManager.AnyoneHasTrinket(TRINKET_MYOSOTIS);
|
|
bool isHard = game.difficulty == DIFFICULTY_HARD;
|
|
uint32_t effectiveStage = stage + (IsAltPath() ? 1 : 0);
|
|
|
|
game.gameStateFlags &= ~(1ull << LEVEL_GAME_STATE_MAX_COINS_OBTAINED);
|
|
myosotisPickups.clear();
|
|
if (isMyosotis) reconstruction_missing("Level::Init 00744940: Myosotis's pickups need EntitySaveState's fields");
|
|
|
|
currentRoomMap = roomMap.data();
|
|
isLevelGenerating = true;
|
|
currentDimensionIdx = 0;
|
|
lastRoomDimensionIdx = 0;
|
|
levelStateFlags = 0;
|
|
ventricleRazorPortals[0].roomIndex = PORTAL_ROOM_NONE;
|
|
ventricleRazorPortals[1].roomIndex = PORTAL_ROOM_NONE;
|
|
greedWavesClearedWithoutRedHeartDamage = 0;
|
|
isHeartPicked = false;
|
|
isCanSeeEverything = false;
|
|
isDevilRoomDisabled = false;
|
|
bombPickupsSpawned = 0;
|
|
game.donationModAngel = 0;
|
|
|
|
uint32_t stageSeed = game.seedEffects.GetStageSeed((int)effectiveStage);
|
|
|
|
generationRNG.SetSeed(stageSeed, GENERATION_SHIFT_INDEX);
|
|
devilAngelRoomRNG.SetSeed(stageSeed, DEVIL_ANGEL_SHIFT_INDEX);
|
|
generationRNG.Next();
|
|
if (game.challenge == CHALLENGE_RED_REDEMPTION) InitStageSeeds();
|
|
reset_room_list(isResetLilPortalRoom);
|
|
if (isResetLilPortalRoom) lil_portal_room_init();
|
|
log_printf(LOG_INFO, "Level::Init m_Stage %d, m_StageType %d Seed %u\n", stage, stageType, generationRNG._seed);
|
|
generationRNG.Next();
|
|
|
|
// The words at Game+0x188fc..0x1890c this also resets are not modeled yet.
|
|
isBossChallenge = stage > 0 && stage <= STAGE_WOMB_II && stage % 2 == 0;
|
|
enterDoor = DOOR_NONE;
|
|
leaveDoor = DOOR_NONE;
|
|
startingRoomIdx = START_GRID_INDEX;
|
|
firstBossRoomListIdx = -1;
|
|
dungeonReturnRoomIndex = START_GRID_INDEX;
|
|
dungeonReturnPosition.x = DUNGEON_RETURN_X;
|
|
dungeonReturnPosition.y = DUNGEON_RETURN_Y;
|
|
greedModeWave = 0;
|
|
greedLastBeatenWave = 0;
|
|
greedLastPaidWave = 0;
|
|
greedModeTreasureRoomIdx = (uint32_t)-1;
|
|
angelRoomChance = 0;
|
|
|
|
int curseOdds = CURSE_ODDS_START[isHard];
|
|
|
|
if (is_unlocked(ACHIEVEMENT_THE_WOMB)) curseOdds = CURSE_ODDS_WOMB[isHard];
|
|
if (is_unlocked(ACHIEVEMENT_EVERYTHING_IS_TERRIBLE)) curseOdds = CURSE_ODDS_TERRIBLE[isHard];
|
|
if (g_manager->persistentGameData.eventCounters[EVENT_COUNTER_CURSE_ODDS] != 0 || game.dailyChallenge._id != 0)
|
|
curseOdds = CURSE_ODDS_DAILY[isHard];
|
|
if (stage == STAGE_BASEMENT_I && !is_unlocked(ACHIEVEMENT_EVERYTHING_IS_TERRIBLE)) curseOdds = 0;
|
|
|
|
RNG curseRng{};
|
|
|
|
curseRng.SetSeed(generationRNG._seed, GENERATION_SHIFT_INDEX);
|
|
bool isCurseRolled = stage != STAGE_HOME && !IsAscent() && curseOdds != 0 &&
|
|
!game.playerManager.FirstCollectibleOwner(COLLECTIBLE_BLACK_CANDLE, LAZARUS_SHARE_CHECK) &&
|
|
game.dailyChallenge._specialDailyId != SPECIAL_DAILY_NO_CURSES;
|
|
|
|
curses = CURSE_NONE;
|
|
if (isCurseRolled)
|
|
{
|
|
if (curseRng.RandomInt((uint32_t)curseOdds) == 0)
|
|
{
|
|
switch (curseRng.Next() % CURSE_PICKS)
|
|
{
|
|
case 0:
|
|
if (CanStageHaveCurseOfLabyrinth(stage))
|
|
{
|
|
curses |= CURSE_OF_LABYRINTH;
|
|
log_printf(LOG_INFO, "Curse of the Labyrinth!\n");
|
|
}
|
|
break;
|
|
case 1:
|
|
if (!is_greed() && game.challenge != CHALLENGE_RED_REDEMPTION)
|
|
{
|
|
curses |= CURSE_OF_THE_LOST;
|
|
log_printf(LOG_INFO, "Curse of the Lost!\n");
|
|
}
|
|
break;
|
|
case 2:
|
|
curses |= CURSE_OF_DARKNESS;
|
|
log_printf(LOG_INFO, "Curse of Darkness!\n");
|
|
break;
|
|
case 3:
|
|
curses |= CURSE_OF_THE_UNKNOWN;
|
|
log_printf(LOG_INFO, "Curse of the Unknown\n");
|
|
break;
|
|
case 4:
|
|
if (!is_greed())
|
|
{
|
|
curses |= CURSE_OF_MAZE;
|
|
log_printf(LOG_INFO, "Curse of Maze\n");
|
|
}
|
|
break;
|
|
case 5:
|
|
if (game.dailyChallenge._id == 0)
|
|
{
|
|
curses |= CURSE_OF_BLIND;
|
|
log_printf(LOG_INFO, "Curse of Blind\n");
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
curses = lua_engine_get().PostCurseEval(curses);
|
|
}
|
|
|
|
if (game.dailyChallenge._specialDailyId == SPECIAL_DAILY_CURSED) curses |= SPECIAL_DAILY_CURSES;
|
|
if (game.challenge != 0)
|
|
{
|
|
ChallengeParam& params = g_manager->GetChallengeParams((int)game.challenge);
|
|
|
|
curses = (curses | params.getCurse) & ~params.curseFilter;
|
|
if (game.challenge == CHALLENGE_RED_REDEMPTION || stage % 2 == 0 || stage >= STAGE_WOMB_II || is_greed())
|
|
curses &= ~CURSE_OF_LABYRINTH;
|
|
}
|
|
if (stage == STAGE_BLUE_WOMB || game.victoryLap > 2) curses &= ~CURSE_OF_DARKNESS;
|
|
|
|
game.hud.InvalidateCraftingItem(nullptr);
|
|
game.roomConfig.ClearGeneratedRooms();
|
|
if (stage == STAGE_VOID)
|
|
{
|
|
for (int stageId = 1; stageId <= VOID_STAGE_ID_LAST; stageId++)
|
|
if (stageId != STAGE_ID_BLUE_WOMB) game.roomConfig.ResetRoomWeights(stageId, ROOM_MODE_CURRENT);
|
|
}
|
|
else
|
|
game.roomConfig.ResetRoomWeights(RoomConfig::GetStageID((int)stage, (int)stageType, ROOM_MODE_CURRENT),
|
|
ROOM_MODE_CURRENT);
|
|
if (HasAbandonedMineshaft()) game.roomConfig.ResetRoomWeights(STAGE_ID_MINES, ROOM_MODE_CURRENT);
|
|
|
|
if (is_greed())
|
|
{
|
|
game.roomConfig.ResetRoomWeights(STAGE_ID_SPECIAL_ROOMS, ROOM_MODE_CURRENT);
|
|
generate_greed();
|
|
}
|
|
else if (stage == STAGE_HOME) generate_home_level();
|
|
else if (stage <= ASCENT_LAST_STAGE && game_flag_get(LEVEL_GAME_STATE_BACKWARDS_PATH)) generate_backwards();
|
|
else if (game.challenge == CHALLENGE_RED_REDEMPTION) generate_random_layout();
|
|
else if (stage == STAGE_BLUE_WOMB) generate_home();
|
|
else
|
|
{
|
|
game.roomConfig.ResetRoomWeights(STAGE_ID_SPECIAL_ROOMS, ROOM_MODE_CURRENT);
|
|
generate_dungeon(curseRng);
|
|
}
|
|
update_all_room_doors();
|
|
dungeonPlacementSeed = generationRNG.Next();
|
|
|
|
if (!is_greed() && stage == STAGE_VOID && firstBossRoomListIdx >= 0)
|
|
reconstruction_missing("Level::Init 00744940: the Void's Delirium distances (get_rooms_within_two_doors)");
|
|
|
|
currentRoomIdx = startingRoomIdx;
|
|
lastRoomIdx = startingRoomIdx;
|
|
if (IsAscent())
|
|
{
|
|
currentRoomIdx = roomList[lastBossRoomListIdx].safeGridIndex;
|
|
lastRoomIdx = currentRoomIdx;
|
|
dungeonReturnRoomIndex = currentRoomIdx;
|
|
}
|
|
log_printf(LOG_INFO, "CURRENT ROOM INDEX %d %08x\n", currentRoomIdx, GetRoomByIdx(currentRoomIdx)->listIndex);
|
|
|
|
bool isBackasswardsEnd = game.challenge == CHALLENGE_BACKASSWARDS && stage == STAGE_DARK_ROOM;
|
|
|
|
if (isBackasswardsEnd)
|
|
{
|
|
currentRoomIdx = ROOM_MEGA_SATAN_IDX;
|
|
lastRoomIdx = ROOM_MEGA_SATAN_IDX;
|
|
}
|
|
load_room();
|
|
if (isBackasswardsEnd) room->Update();
|
|
room->PlayMusic();
|
|
if (game.challenge != CHALLENGE_BACKASSWARDS || stage == STAGE_DARK_ROOM) UpdateVisibility();
|
|
if (stage == STAGE_DARK_ROOM && game.GetChallengeParams().isMegaSatan &&
|
|
game.challenge != CHALLENGE_BACKASSWARDS)
|
|
for (int keyPiece : {COLLECTIBLE_KEY_PIECE_1, COLLECTIBLE_KEY_PIECE_2})
|
|
if (!game.playerManager.FirstCollectibleOwner(keyPiece, LAZARUS_SHARE_CHECK))
|
|
reconstruction_missing("Level::Init 00744940: a Mega Satan challenge's Key Pieces (AddCollectible)");
|
|
|
|
uint32_t voiceStage = effectiveStage + ((GetCurses() & CURSE_OF_LABYRINTH) && effectiveStage % 2 == 0 ? 1 : 0);
|
|
|
|
if (IsAscent() && g_manager->optionsConfig.isAscentVoiceover && voiceStage % 2 == 1 &&
|
|
voiceStage <= STAGE_WOMB_I)
|
|
reconstruction_missing("Level::Init 00744940: the Ascent's voiceover timer (Entity_Effect::CreateTimer)");
|
|
|
|
game.playerManager.trigger_level_start();
|
|
game.itemPool.unkFloat674 = game.itemPool.unkFloat678;
|
|
room->camera->position_center();
|
|
room->camera->DoUpdate(false);
|
|
TextureCache::Purge();
|
|
lua_engine_get().PostNewLevel();
|
|
isLevelGenerating = false;
|
|
}
|
|
|
|
// 00738650 Resets every room descriptor (the Lil Portal room's only when asked), numbering them and giving the rooms
|
|
// off the map their negative indices, then clears the stairs and trapdoors the Lil Portal room saved.
|
|
void Level::reset_room_list(bool isResetLilPortalRoom)
|
|
{
|
|
for (int i = 0; i < ROOM_DESCRIPTOR_COUNT; i++)
|
|
{
|
|
RoomDescriptor& desc = roomList[i];
|
|
|
|
if (!isResetLilPortalRoom && i == ROOM_DESCRIPTOR_COUNT - 1) continue;
|
|
desc = RoomDescriptor{};
|
|
desc.listIndex = i;
|
|
if (i >= ROOM_MAP_CELLS)
|
|
{
|
|
desc.gridIndex = ROOM_MAP_CELLS - 1 - i;
|
|
desc.safeGridIndex = desc.gridIndex;
|
|
}
|
|
}
|
|
|
|
for (GridEntityDesc& grid : GetRoomByIdx(ROOM_LIL_PORTAL_IDX)->savedGridEntities)
|
|
if (grid._type == GRID_STAIRS || grid._type == GRID_TRAPDOOR) grid._type = 0;
|
|
}
|
|
|
|
// 00745b70 Gives the Lil Portal room its layout from the special rooms the first time, seeded from the start seed.
|
|
void Level::lil_portal_room_init()
|
|
{
|
|
RoomDescriptor& desc = *GetRoomByIdx(ROOM_LIL_PORTAL_IDX);
|
|
|
|
if (desc.data) return;
|
|
|
|
RNG rng{};
|
|
|
|
rng.SetSeed(g_game->seedEffects.GetStartSeed(), LIL_PORTAL_SHIFT_INDEX);
|
|
desc.InitSeeds(rng);
|
|
desc.data = g_game->roomConfig.GetRoomByStageTypeAndVariant(STAGE_ID_SPECIAL_ROOMS, ROOM_DEFAULT,
|
|
LIL_PORTAL_ROOM_VARIANT, ROOM_MODE_NORMAL);
|
|
}
|
|
|
|
// 00740e10 Generates the floor's normal layout until its special rooms fit: the room count by stage and curses, the
|
|
// dead ends it needs, the shapes and difficulties its normal rooms come in, the photo door's cell kept free, then
|
|
// the mirror world or the mineshaft on the alternate path.
|
|
void Level::generate_dungeon(RNG& curseRng)
|
|
{
|
|
Game& game = *g_game;
|
|
bool isLabyrinth = GetCurses() & CURSE_OF_LABYRINTH;
|
|
bool isHard = game.difficulty == DIFFICULTY_HARD;
|
|
int stageRooms = (int)stage * ROOM_COUNT_STAGE_TENTHS / ROOM_COUNT_STAGE_DIVISOR + ROOM_COUNT_BASE;
|
|
int roomCount = std::min(ROOM_COUNT_MAX, stageRooms + (int)(generationRNG.Next() & 1));
|
|
|
|
if (IsAltPath() && (HasAbandonedMineshaft() || HasMirrorDimension())) roomCount -= ROOM_COUNT_ALT_EXTRA_DIMENSION;
|
|
if (isLabyrinth) roomCount = std::min(ROOM_COUNT_LABYRINTH_MAX, (int)(roomCount * ROOM_COUNT_LABYRINTH_SCALE));
|
|
else if (GetCurses() & CURSE_OF_THE_LOST) roomCount += ROOM_COUNT_LOST_BONUS;
|
|
if (game.challenge == CHALLENGE_XXXXXXXXL)
|
|
roomCount = (int)(generationRNG.Next() % ROOM_COUNT_ROLL) + ROOM_COUNT_XXXXXXXXL;
|
|
if (stage == STAGE_VOID) roomCount = (int)(generationRNG.Next() % ROOM_COUNT_ROLL) + ROOM_COUNT_VOID;
|
|
if (uint32_t flip = curseRng.Next() & 1; isHard) roomCount += ROOM_COUNT_HARD_BONUS + (int)flip;
|
|
if (GetCurses() & CURSE_OF_GIANT)
|
|
roomCount = std::max(ROOM_COUNT_GIANT_MIN, roomCount * GIANT_ROOM_SHARE / GIANT_ROOM_DIVISOR);
|
|
|
|
int deadEndCount = DEAD_ENDS_BASE + (stage != STAGE_BASEMENT_I) + isLabyrinth +
|
|
(stage == STAGE_VOID ? DEAD_ENDS_VOID_BONUS : 0);
|
|
|
|
if (game.playerManager.FirstCollectibleOwner(COLLECTIBLE_VOODOO_HEAD, LAZARUS_SHARE_CHECK)) deadEndCount++;
|
|
if (HasAbandonedMineshaft() || HasMirrorDimension()) deadEndCount++;
|
|
|
|
LevelGenerator generator(generationRNG.Next());
|
|
int minDifficulty = isHard ? DIFFICULTY_MEDIUM : DIFFICULTY_EASY;
|
|
int maxDifficulty = isHard ? DIFFICULTY_MAX : DIFFICULTY_HARD_MAX;
|
|
|
|
if (!isLabyrinth && stage < STAGE_BLUE_WOMB)
|
|
{
|
|
bool isEven = stage % 2 == 0;
|
|
|
|
if (isHard)
|
|
{
|
|
minDifficulty = isEven ? DIFFICULTY_HARD_MAX : DIFFICULTY_MEDIUM;
|
|
maxDifficulty = isEven ? DIFFICULTY_MAX : DIFFICULTY_HARD_MAX;
|
|
}
|
|
else
|
|
{
|
|
minDifficulty = isEven ? DIFFICULTY_MEDIUM : DIFFICULTY_EASY;
|
|
maxDifficulty = isEven ? DIFFICULTY_HARD_MAX : DIFFICULTY_MEDIUM;
|
|
}
|
|
}
|
|
|
|
bool isVoid = stage == STAGE_VOID;
|
|
int stageId = RoomConfig::GetStageID((int)stage, (int)stageType, ROOM_MODE_CURRENT);
|
|
auto rooms_collect = [&]() {
|
|
std::vector<RoomConfig_Room*> rooms;
|
|
|
|
for (int id = isVoid ? 1 : stageId; id <= (isVoid ? VOID_STAGE_ID_LAST : stageId); id++)
|
|
{
|
|
RoomQuery query = {.maxDifficulty = maxDifficulty, .minDifficulty = minDifficulty, .stageId = id};
|
|
|
|
if (isVoid && id == STAGE_ID_BLUE_WOMB) continue;
|
|
std::ranges::copy(game.roomConfig.GetRooms(query), std::back_inserter(rooms));
|
|
}
|
|
return rooms;
|
|
};
|
|
|
|
if (isVoid)
|
|
{
|
|
minDifficulty = DIFFICULTY_MEDIUM;
|
|
maxDifficulty = DIFFICULTY_MAX;
|
|
}
|
|
|
|
std::vector<RoomConfig_Room*> normalRooms = rooms_collect();
|
|
|
|
if (normalRooms.size() < ROOM_POOL_MIN)
|
|
{
|
|
minDifficulty = DIFFICULTY_EASY;
|
|
maxDifficulty = DIFFICULTY_MAX;
|
|
normalRooms = rooms_collect();
|
|
}
|
|
|
|
GenerationSettings settings = {.allowedShapes = 0, .deadEndCount = deadEndCount, .roomCount = roomCount};
|
|
|
|
for (RoomConfig_Room* config : normalRooms)
|
|
if (config->shape >= 0 && config->shape < ROOMSHAPE_ANY) settings.allowedShapes |= 1u << config->shape;
|
|
if (GetCurses() & CURSE_OF_GIANT)
|
|
settings.allowedShapes &= ~(1u << ROOMSHAPE_1x1 | 1u << ROOMSHAPE_IH | 1u << ROOMSHAPE_IV);
|
|
settings.isChapter6 = stage == STAGE_DARK_ROOM;
|
|
settings.isVoid = isVoid;
|
|
settings.isXL = isLabyrinth || game.challenge == CHALLENGE_XXXXXXXXL;
|
|
|
|
bool isStandardPath =
|
|
(game.challenge == 0 && game.dailyChallenge._id == 0) || game.GetChallengeParams().pathType == PATH_TYPE_HOME;
|
|
LevelGenerator_Room startRoom;
|
|
|
|
startRoom.position = START_POSITION;
|
|
|
|
for (int retries = 0;; retries++)
|
|
{
|
|
game.bossPool.blacklist_clear();
|
|
if (retries > RETRIES_LOGGED) log_printf(LOG_ASSERT, "failed to generate level too often, giving up\n");
|
|
log_printf(LOG_INFO, "generate...\n");
|
|
generator.blockedPositions = {};
|
|
if (HasPhotoDoor() && isStandardPath && is_unlocked(ACHIEVEMENT_STRANGE_DOOR))
|
|
generator.block_cell(PHOTO_DOOR_CELL);
|
|
|
|
settings.roomCount = roomCount;
|
|
generator.Generate(settings, startRoom);
|
|
if ((int)generator.deadEnds.size() < deadEndCount)
|
|
{
|
|
log_printf(LOG_INFO, "not enough dead ends (%d/%d)\n", (int)generator.deadEnds.size(), deadEndCount);
|
|
if (retries + 1 > RETRIES_BEFORE_GROWTH && (retries + 1) % RETRY_GROWTH_PERIOD == 0 &&
|
|
roomCount < ROOM_COUNT_RETRY_MAX)
|
|
roomCount++;
|
|
continue;
|
|
}
|
|
|
|
log_printf(LOG_INFO, "placing rooms...\n");
|
|
roomMap.fill(-1);
|
|
nbRooms = 0;
|
|
if (!place_special_rooms(generator, minDifficulty, maxDifficulty))
|
|
{
|
|
reset_room_list(false);
|
|
continue;
|
|
}
|
|
if (HasMirrorDimension()) generate_mirror_world();
|
|
else if (HasAbandonedMineshaft()) generate_mineshaft();
|
|
log_printf(LOG_INFO, "Map Generated in %d Loops\n", retries + 1);
|
|
break;
|
|
}
|
|
lil_portal_room_init();
|
|
game.bossPool.blacklist_commit();
|
|
}
|
|
|
|
// 00738ab0 Configures the next room descriptor from a layout room and its config on the current dimension's map:
|
|
// its seeds, cells and doors, Devil's Crown's treasure rooms, and Corpse's rooms without pits that take the alternate
|
|
// backdrop 1 in 5 times.
|
|
bool Level::place_room(const LevelGenerator_Room& slot, RoomConfig_Room* data, uint32_t seed, RoomDescriptor** outDesc)
|
|
{
|
|
if (!data) log_printf(LOG_ASSERT, "Level::place_room data is NULL!\n");
|
|
if (nbRooms >= ROOM_MAP_CELLS)
|
|
log_printf(LOG_INFO, "[warn] Could not place room, limit of %d exceeded!\n", ROOM_MAP_CELLS);
|
|
|
|
RoomDescriptor& desc = roomList[nbRooms];
|
|
RNG rng{};
|
|
|
|
rng.SetSeed(seed, ROOM_SEEDS_SHIFT_INDEX);
|
|
|
|
desc.InitSeeds(rng);
|
|
desc.data = data;
|
|
desc.gridIndex = slot.position.ToGridIdx();
|
|
desc.safeGridIndex = desc.gridIndex + (data->shape == ROOMSHAPE_LTL ? 1 : 0);
|
|
desc.overrideData = nullptr;
|
|
desc.dimension = currentDimensionIdx;
|
|
desc.allowedDoors = slot.doors;
|
|
if (g_game->playerManager.AnyoneHasTrinket(TRINKET_DEVILS_CROWN) && is_devils_crown_room(*this, desc))
|
|
desc.flags |= ROOM_DESCRIPTOR_FLAG_DEVIL_TREASURE;
|
|
|
|
if (data->type == ROOM_DEFAULT &&
|
|
RoomConfig::GetStageID((int)stage, GetRoomStageType(desc.gridIndex), ROOM_MODE_CURRENT) == STAGE_ID_CORPSE)
|
|
{
|
|
RNG backdropRng{};
|
|
|
|
backdropRng.SetSeed(desc.decorationSeed, CORPSE_BACKDROP_SHIFT_INDEX);
|
|
auto is_pit = [](const RoomEntry& entry) {
|
|
return entry.type >= GRID_SPAWN_PIT_FIRST && entry.type < GRID_SPAWN_PIT_END;
|
|
};
|
|
bool isPit = std::ranges::any_of(
|
|
data->spawns, [&](const RoomSpawn& spawn) { return std::ranges::any_of(spawn.entries, is_pit); });
|
|
|
|
if (backdropRng.Next() % CORPSE_BACKDROP_ODDS == 0 && !isPit)
|
|
desc.flags |= ROOM_DESCRIPTOR_FLAG_USE_ALTERNATE_BACKDROP;
|
|
}
|
|
|
|
for (XY offset : LevelGenerator::get_room_placement_offsets(data->shape))
|
|
{
|
|
int cell = (slot.position + offset).ToGridIdx();
|
|
|
|
if (cell < 0) log_printf(LOG_ASSERT, "[Level] place_room: invalid room pos/size\n");
|
|
else roomMap[desc.dimension * LEVEL_GRID_CELLS + cell] = desc.listIndex;
|
|
}
|
|
nbRooms++;
|
|
if (outDesc) *outDesc = &desc;
|
|
return true;
|
|
}
|
|
|
|
// 00740bc0 (00740da0) A room by index on a dimension's map (the current one by default): a negative index is a room
|
|
// off the map, -100 the same room on the other dimension, -101 the mirror world's start room. Anything else is a
|
|
// shared blank descriptor.
|
|
RoomDescriptor* Level::GetRoomByIdx(int idx, int dimension)
|
|
{
|
|
static RoomDescriptor invalid{};
|
|
|
|
if (dimension < 0) dimension = currentDimensionIdx;
|
|
if ((uint32_t)dimension >= DIMENSION_COUNT) return &invalid;
|
|
if (idx == ROOM_INDEX_OTHER_DIMENSION)
|
|
return currentRoomIdx >= 0 ? GetRoomByIdx(currentRoomIdx, dimension == 0 ? 1 : 0) : &invalid;
|
|
if (idx == ROOM_INDEX_MIRRORED_START)
|
|
{
|
|
if (currentRoomIdx < 0) return &invalid;
|
|
if (dimension == 0) return GetRoomByIdx(MIRROR_START_GRID_INDEX, 1);
|
|
for (int i = 0; i < nbRooms; i++)
|
|
{
|
|
RoomDescriptor& desc = roomList[i];
|
|
|
|
if (desc.dimension == 0 && desc.data && desc.data->type == ROOM_DEFAULT &&
|
|
desc.data->subtype == MIRROR_START_SUBTYPE)
|
|
return &desc;
|
|
}
|
|
return &invalid;
|
|
}
|
|
if (idx < -OFF_MAP_ROOM_COUNT || idx >= LEVEL_GRID_CELLS) return &invalid;
|
|
if (idx < 0) return &roomList[ROOM_MAP_CELLS - 1 - idx];
|
|
|
|
uint32_t listIdx = (uint32_t)roomMap[dimension * LEVEL_GRID_CELLS + idx];
|
|
|
|
return listIdx < ROOM_DESCRIPTOR_COUNT ? &roomList[listIdx] : &invalid;
|
|
}
|
|
|
|
// 00740db0 The room the players are in.
|
|
RoomDescriptor* Level::GetCurrentRoomDesc()
|
|
{
|
|
return GetRoomByIdx(currentRoomIdx, currentDimensionIdx);
|
|
}
|
|
|
|
// 00740dd0 The room the players were in before.
|
|
RoomDescriptor* Level::GetLastRoomDesc()
|
|
{
|
|
return GetRoomByIdx(lastRoomIdx, lastRoomDimensionIdx);
|
|
}
|
|
|
|
// 0073e040 Refreshes the doors of every placed room and of the rooms off the map.
|
|
void Level::update_all_room_doors()
|
|
{
|
|
for (int i = 0; i < nbRooms; i++) update_room_doors(roomList[i]);
|
|
for (int i = ROOM_MAP_CELLS; i < ROOM_DESCRIPTOR_COUNT; i++) update_room_doors(roomList[i]);
|
|
}
|
|
|
|
// 00748490 The floor's curses with the debug and seed forced ones, less the ones the seeds prevent.
|
|
uint32_t Level::GetCurses()
|
|
{
|
|
return ~Seeds::GetPreventedCurses() & (Seeds::GetForcedCurses() | g_game->debugCurses | curses);
|
|
}
|
|
|
|
// 0071f600 The floor's curses within mask.
|
|
uint32_t Level::filter_curses(uint32_t mask)
|
|
{
|
|
return GetCurses() & mask;
|
|
}
|
|
|
|
// 007385c0 Whether a stage may roll the Curse of the Labyrinth: the first floor of a chapter up to the Womb, outside
|
|
// Greed and Red Redemption.
|
|
bool Level::CanStageHaveCurseOfLabyrinth(uint32_t levelStage)
|
|
{
|
|
return g_game->challenge != CHALLENGE_RED_REDEMPTION && levelStage % 2 == 1 && levelStage < STAGE_WOMB_II &&
|
|
!is_greed();
|
|
}
|
|
|
|
// 004f88f0 Whether one of the floor's state flags is set, the flag clamped to the known ones.
|
|
bool Level::GetStateFlag(int flag)
|
|
{
|
|
return levelStateFlags >> std::clamp(flag, 0, (int)LEVEL_STATE_LAST) & 1;
|
|
}
|
|
|
|
// 00428a80 Sets or clears one of the floor's state flags, the flag clamped to the known ones.
|
|
void Level::SetStateFlag(int flag, bool isSet)
|
|
{
|
|
uint32_t mask = 1u << std::clamp(flag, 0, (int)LEVEL_STATE_LAST);
|
|
|
|
levelStateFlags = isSet ? levelStateFlags | mask : levelStateFlags & ~mask;
|
|
}
|
|
|
|
// 0074b5b0 Notes red heart damage taken on the floor, which also breaks Greed's streak of clean waves.
|
|
void Level::SetRedHeartDamage()
|
|
{
|
|
levelStateFlags |= 1u << LEVEL_STATE_REDHEART_DAMAGED;
|
|
greedWavesClearedWithoutRedHeartDamage = 0;
|
|
}
|
|
|
|
// A room the Ascent keeps: its descriptor, with its config named apart.
|
|
static SavedRoom backwards_room_save(const RoomDescriptor& desc)
|
|
{
|
|
SavedRoom saved{desc, {}};
|
|
|
|
if (desc.data) room_config_ref_save(*desc.data, saved.config, nullptr);
|
|
saved.desc.data = nullptr;
|
|
return saved;
|
|
}
|
|
|
|
// 00708050 Keeps a stage's rooms for the Ascent as the floor is left: its stage type, the last boss room first, then
|
|
// up to one more boss room and two treasure rooms of the main dimension. A second boss room makes the stage an XL one,
|
|
// which clears the next stage's rooms. A stage outside 1 to 7 is only logged, as the original writes past the stages.
|
|
void Game::SaveBackwardsStage(int stage)
|
|
{
|
|
Game& game = *g_game;
|
|
|
|
if (stage < 1 || stage > BACKWARDS_STAGE_COUNT) return log_printf(LOG_ASSERT, "Invalid backwards path stage ID");
|
|
|
|
BackwardsStageDesc& saved = game.backwardsStages[stage - 1];
|
|
|
|
saved.stageType = game.stageType;
|
|
saved.bossRooms = {backwards_room_save(game.roomList[game.lastBossRoomListIdx])};
|
|
saved.treasureRooms.clear();
|
|
for (int i = 0; i < game.nbRooms; i++)
|
|
{
|
|
RoomDescriptor& desc = game.roomList[i];
|
|
|
|
if (!desc.data || desc.dimension != 0) continue;
|
|
if (desc.data->type == ROOM_BOSS)
|
|
{
|
|
if (i != game.lastBossRoomListIdx && saved.bossRooms.size() < BACKWARDS_ROOMS_KEPT)
|
|
saved.bossRooms.push_back(backwards_room_save(desc));
|
|
}
|
|
else if (desc.data->type == ROOM_TREASURE && saved.treasureRooms.size() < BACKWARDS_ROOMS_KEPT)
|
|
saved.treasureRooms.push_back(backwards_room_save(desc));
|
|
}
|
|
|
|
saved.isXL = saved.bossRooms.size() > 1;
|
|
if (saved.isXL && stage < BACKWARDS_STAGE_COUNT)
|
|
{
|
|
game.backwardsStages[stage].bossRooms.clear();
|
|
game.backwardsStages[stage].treasureRooms.clear();
|
|
}
|
|
}
|
|
|
|
// 007466d0 Moves to a stage and type (clamped to the game's), recording the stage left for the Ascent, the stage for
|
|
// the nightmare scenes, and Boss Rush's par time (longer on the alternate path's first six stages).
|
|
void Level::SetStage(int stageId, int alt)
|
|
{
|
|
uint32_t newStage = (uint32_t)std::clamp(stageId, 0, (int)STAGE_HOME);
|
|
uint32_t newType = (uint32_t)std::clamp(alt, 0, (int)STAGETYPE_REPENTANCE_B);
|
|
|
|
if (stage > 0 && !IsAscent() && stage + (IsAltPath() ? 1 : 0) < BACKWARDS_STAGE_END)
|
|
Game::SaveBackwardsStage((int)stage + (IsAltPath() ? 1 : 0));
|
|
|
|
stage = newStage;
|
|
stageType = newType;
|
|
g_manager->nightmareScene.record_stage((int)stage, (int)stageType);
|
|
g_game->bossRushParTime =
|
|
is_greed() || stage > ASCENT_LAST_STAGE || !IsAltPath() ? BOSS_RUSH_PAR_TIME : BOSS_RUSH_PAR_TIME_ALT;
|
|
}
|
|
|
|
// 006b9bb0 The stage id of the current room's rooms: Downpour's or Dross's for their backdrops, a Void room's own
|
|
// stage.
|
|
uint32_t Level::GetStageID()
|
|
{
|
|
Room& current = *g_game->room;
|
|
|
|
if (current.backdropType == BACKDROP_DOWNPOUR || current.backdropType == BACKDROP_DOWNPOUR_ENTRANCE)
|
|
return STAGE_ID_DOWNPOUR;
|
|
if (current.backdropType == BACKDROP_DROSS) return STAGE_ID_DROSS;
|
|
|
|
int stageId = g_game->GetStageID();
|
|
RoomConfig_Room* data = current.descriptor ? current.descriptor->data : nullptr;
|
|
|
|
return stageId == STAGE_ID_VOID && data && data->stageId != 0 ? (uint32_t)data->stageId : (uint32_t)stageId;
|
|
}
|
|
|
|
// 0074f690 The stage type a room's layout comes from: the floor's, but for Red Redemption's mixed floors.
|
|
int Level::GetRoomStageType(int)
|
|
{
|
|
if (g_game->challenge == CHALLENGE_RED_REDEMPTION)
|
|
reconstruction_missing("Level::GetRoomStageType 0074f690: Red Redemption's stage type noise");
|
|
return (int)stageType;
|
|
}
|
|
|
|
// 00738610 Updates the current room.
|
|
void Level::Update()
|
|
{
|
|
room->Update();
|
|
}
|
|
|
|
// 0042a2c0 Whether the floor is not its chapter's original stage type.
|
|
bool Level::IsAltStage()
|
|
{
|
|
return stageType != STAGETYPE_ORIGINAL;
|
|
}
|
|
|
|
// 0074bac0 Whether the floor is on Repentance's alternate path.
|
|
bool Level::IsAltPath()
|
|
{
|
|
return stageType == STAGETYPE_REPENTANCE || stageType == STAGETYPE_REPENTANCE_B;
|
|
}
|
|
|
|
// 0074f090 Whether the floor is one of the Ascent's.
|
|
bool Level::IsAscent()
|
|
{
|
|
return stage >= 1 && stage <= ASCENT_LAST_STAGE && game_flag_get(LEVEL_GAME_STATE_BACKWARDS_PATH);
|
|
}
|
|
|
|
// Whether the floor is outside Greed and the Ascent on a normal or alternate path, as the secret path checks ask.
|
|
static bool is_path_stage(Level& level, bool isAltPath)
|
|
{
|
|
return !is_greed() && !level.IsAscent() && level.IsAltPath() == isAltPath;
|
|
}
|
|
|
|
// Whether the floor is a chapter's second, or its first on an XL floor.
|
|
static bool is_chapter_second_floor(Level& level, uint32_t firstStage)
|
|
{
|
|
return level.stage == firstStage + 1 || (level.stage == firstStage && (level.GetCurses() & CURSE_OF_LABYRINTH));
|
|
}
|
|
|
|
// The stage counted one deeper for an XL floor, as the Mausoleum's checks count it.
|
|
static uint32_t stage_with_labyrinth(Level& level)
|
|
{
|
|
return level.stage + ((level.GetCurses() & CURSE_OF_LABYRINTH) ? 1 : 0);
|
|
}
|
|
|
|
// 0074ea50 Whether the run is about to start the Ascent: Mausoleum II (or an XL Mausoleum) after its heart was killed.
|
|
bool Level::IsPreAscent()
|
|
{
|
|
return is_path_stage(*this, true) && stage_with_labyrinth(*this) == STAGE_DEPTHS_II &&
|
|
game_flag_get(LEVEL_GAME_STATE_MAUSOLEUM_HEART_KILLED);
|
|
}
|
|
|
|
// 0074e9b0 Whether the floor is Mausoleum II (or an XL Mausoleum) holding Mother's heart room.
|
|
bool Level::IsMausoleumHeartStage()
|
|
{
|
|
return is_path_stage(*this, true) && stage_with_labyrinth(*this) == STAGE_DEPTHS_II &&
|
|
game_flag_get(LEVEL_GAME_STATE_MAUSOLEUM_HEART_ROOM);
|
|
}
|
|
|
|
// 0074ef70 Whether the floor has Dross or Downpour II's mirror world (or an XL first one).
|
|
bool Level::HasMirrorDimension()
|
|
{
|
|
return is_path_stage(*this, true) && is_chapter_second_floor(*this, STAGE_BASEMENT_I);
|
|
}
|
|
|
|
// 0074efd0 Whether the floor has the Mines or Ashpit II's abandoned mineshaft (or an XL first one).
|
|
bool Level::HasAbandonedMineshaft()
|
|
{
|
|
return is_path_stage(*this, true) && is_chapter_second_floor(*this, STAGE_CAVES_I);
|
|
}
|
|
|
|
// 0074f030 Whether the floor has Depths II's strange door (or an XL Depths).
|
|
bool Level::HasPhotoDoor()
|
|
{
|
|
return is_path_stage(*this, false) && is_chapter_second_floor(*this, STAGE_DEPTHS_I);
|
|
}
|
|
|
|
// What placing a floor's special rooms shares between its steps: the layout, the room types the run's challenge leaves
|
|
// out, the floor's stage id and the stage counted one deeper on the alternate path, the seed the secret rooms start
|
|
// from, the shop and secret room Greed may take over, and how many normal rooms the floor's special doors take.
|
|
// The curse room step leaves its last config and end room behind. The miniboss step reuses them when every sin was met.
|
|
struct SpecialRoomPlacement
|
|
{
|
|
Level& level;
|
|
LevelGenerator& generator;
|
|
std::set<int>& excludedTypes;
|
|
RoomConfig_Room* config = nullptr;
|
|
LevelGenerator_Room* endRoom = nullptr;
|
|
uint32_t secretSeed = 0;
|
|
int effectiveStage = 0;
|
|
int secretIdx = -1;
|
|
int shopIdx = -1;
|
|
int specialDoorRooms = 0;
|
|
int stageId = 0;
|
|
bool isTakeoverAllowed = true;
|
|
|
|
bool is_excluded(int type) { return excludedTypes.contains(type); }
|
|
};
|
|
|
|
// A normal room placed on the layout, with the layout room it took.
|
|
struct PlacedRoom
|
|
{
|
|
RoomDescriptor* descriptor = nullptr;
|
|
LevelGenerator_Room* room = nullptr;
|
|
};
|
|
|
|
// A query for a room type of a stage, of any shape and difficulty 1 to 10.
|
|
static RoomQuery room_query(int stageId, int type, int subtype)
|
|
{
|
|
return {.maxDifficulty = DIFFICULTY_HARD_MAX,
|
|
.minDifficulty = DIFFICULTY_EASY,
|
|
.stageId = stageId,
|
|
.subtype = subtype,
|
|
.type = type};
|
|
}
|
|
|
|
// A room drawn for a query, its weight lowered unless asked not to.
|
|
static RoomConfig_Room* random_room_get(uint32_t seed, RoomQuery query, WeightReduction reduction = WEIGHT_REDUCE)
|
|
{
|
|
return g_game->roomConfig.GetRandomRoom(seed, reduction, query);
|
|
}
|
|
|
|
// A room drawn for a query, from a fallback stage when the query's has none.
|
|
static RoomConfig_Room* fallback_room_get(uint32_t seed, RoomQuery query, int fallbackStageId)
|
|
{
|
|
return g_game->roomConfig.GetRandomRoomWithFallbackStage(seed, WEIGHT_REDUCE, query, fallbackStageId);
|
|
}
|
|
|
|
// The farthest dead end grown into a config's shape and doors, taken off the dead end list. None for no config, where
|
|
// the original crashed.
|
|
static LevelGenerator_Room* end_room_take(LevelGenerator& generator, RoomConfig_Room* config)
|
|
{
|
|
return config ? generator.GetNewEndRoom(config->shape, config->doors) : nullptr;
|
|
}
|
|
|
|
// Gives a dead end a step took but did not use back to the dead end list, at its end.
|
|
static void end_room_return(LevelGenerator& generator, LevelGenerator_Room* room)
|
|
{
|
|
if (room) generator.deadEnds.push_back(room->generationIndex);
|
|
}
|
|
|
|
// Places a layout room with its config when there is one.
|
|
static void room_place(Level& level, LevelGenerator_Room* room, RoomConfig_Room* config, uint32_t seed)
|
|
{
|
|
if (room && config) level.place_room(*room, config, seed, nullptr);
|
|
}
|
|
|
|
// The trinket of the floor's crown: Wicked Crown on Sheol, Holy Crown on the Cathedral, none elsewhere.
|
|
static int crown_trinket_get(Level& level)
|
|
{
|
|
if (level.stage != STAGE_SHEOL) return 0;
|
|
if (level.stageType == STAGETYPE_ORIGINAL) return TRINKET_WICKED_CROWN;
|
|
return level.stageType == STAGETYPE_WOTL ? TRINKET_HOLY_CROWN : 0;
|
|
}
|
|
|
|
// How strong the floor's crown trinket is on its first owner, 0 without one.
|
|
static int crown_multiplier_get(Level& level)
|
|
{
|
|
int trinket = crown_trinket_get(level);
|
|
Entity_Player* owner = trinket ? g_game->playerManager.FirstTrinketOwner(trinket) : nullptr;
|
|
|
|
return owner ? owner->GetTrinketMultiplier(trinket) : 0;
|
|
}
|
|
|
|
// Whether a trinket's first owner holds it at least minMultiplier strong.
|
|
static bool is_trinket_strong(int trinket, int minMultiplier)
|
|
{
|
|
Entity_Player* owner = g_game->playerManager.FirstTrinketOwner(trinket);
|
|
|
|
return owner && owner->GetTrinketMultiplier(trinket) >= minMultiplier;
|
|
}
|
|
|
|
// Whether the floor keeps its shop or treasure room past the Depths: on the Womb with the Womb trinket (Silver Dollar,
|
|
// Bloody Crown), on Sheol and the Cathedral with their crown.
|
|
static bool is_deal_floor(Level& level, int wombTrinket)
|
|
{
|
|
PlayerManager& players = g_game->playerManager;
|
|
int crown = crown_trinket_get(level);
|
|
|
|
if (level.stage < STAGE_WOMB_I) return true;
|
|
if (level.stage < STAGE_BLUE_WOMB && players.AnyoneHasTrinket(wombTrinket)) return true;
|
|
return crown && players.AnyoneHasTrinket(crown);
|
|
}
|
|
|
|
// A boss room config for bossId drawn from the generation RNG, logged when the stage has none.
|
|
static RoomConfig_Room* boss_config_get(Level& level, int bossId)
|
|
{
|
|
RoomConfig_Room* config = Level::pick_boss_room_config(bossId, level.generationRNG.Next());
|
|
|
|
if (!config)
|
|
log_printf(LOG_INFO, "[warn] could not find matching boss room (boss id: %d) for the current stage\n", bossId);
|
|
return config;
|
|
}
|
|
|
|
// Places a layout room as the floor's last boss room.
|
|
static void boss_room_commit(Level& level, LevelGenerator_Room& room, RoomConfig_Room* config)
|
|
{
|
|
level.lastBossRoomListIdx = level.nbRooms;
|
|
level.place_room(room, config, level.generationRNG._seed, nullptr);
|
|
}
|
|
|
|
// The boss room of the pool's boss on the farthest fitting dead end. The Void adds five to eight more of the bosses it
|
|
// allows (failing below five), an XL floor its second from the next stage's pool with the generation RNG put back
|
|
// after. The cells around the last one are blocked. A Mega Satan challenge's Dark Room ends in the Mega Satan room.
|
|
static bool boss_rooms_place(SpecialRoomPlacement& placement)
|
|
{
|
|
Level& level = placement.level;
|
|
Game& game = *g_game;
|
|
LevelGenerator& generator = placement.generator;
|
|
|
|
if (game.GetChallengeParams().isMegaSatan && level.stage == STAGE_DARK_ROOM)
|
|
{
|
|
level.lastBossRoomListIdx = level.GetRoomByIdx(ROOM_MEGA_SATAN_IDX)->listIndex;
|
|
return true;
|
|
}
|
|
|
|
RoomConfig_Room* config = boss_config_get(level, game.bossPool.GetBossId((int)level.stage, (int)level.stageType));
|
|
LevelGenerator_Room* bossRoom =
|
|
config ? generator.place_boss_room(config->shape, config->doors, BOSS_ROOM_NEXT) : nullptr;
|
|
|
|
if (!bossRoom) return false;
|
|
level.firstBossRoomListIdx = level.nbRooms;
|
|
boss_room_commit(level, *bossRoom, config);
|
|
|
|
if (level.stage == STAGE_VOID)
|
|
{
|
|
int extraCount = (int)level.generationRNG.RandomInt(VOID_EXTRA_BOSS_ROLL) + VOID_EXTRA_BOSSES_MIN;
|
|
std::vector<int> bossIds(VOID_BOSS_IDS.begin(), VOID_BOSS_IDS.end());
|
|
|
|
RNG::Shuffle(&level.generationRNG, bossIds.data(), bossIds.data() + bossIds.size());
|
|
for (int i = 0; i < extraCount; i++)
|
|
{
|
|
if (!(config = boss_config_get(level, bossIds[i]))) return false;
|
|
bossRoom = generator.place_boss_room(config->shape, config->doors, BOSS_ROOM_DETERMINE);
|
|
if (!bossRoom && i < VOID_EXTRA_BOSSES_MIN) return false;
|
|
if (!bossRoom) break;
|
|
boss_room_commit(level, *bossRoom, config);
|
|
}
|
|
}
|
|
|
|
if (level.GetCurses() & CURSE_OF_LABYRINTH)
|
|
{
|
|
uint32_t savedSeed = level.generationRNG._seed;
|
|
|
|
if (!(config = boss_config_get(level, game.bossPool.GetBossId((int)level.stage + 1, (int)level.stageType))))
|
|
return false;
|
|
if (!(bossRoom = generator.place_boss_room(config->shape, config->doors, BOSS_ROOM_NEXT))) return false;
|
|
boss_room_commit(level, *bossRoom, config);
|
|
level.generationRNG.SetSeed(savedSeed, GENERATION_SHIFT_INDEX);
|
|
}
|
|
if (bossRoom) generator.block_room_area(*bossRoom);
|
|
return true;
|
|
}
|
|
|
|
// The super secret room (a second with Luna) on dead ends, drawn from a copy of the generation RNG. The first is
|
|
// required.
|
|
static bool super_secret_rooms_place(SpecialRoomPlacement& placement)
|
|
{
|
|
Level& level = placement.level;
|
|
|
|
if (placement.is_excluded(ROOM_SUPERSECRET)) return true;
|
|
|
|
RNG rng = {level.generationRNG.Next(), 2, 5, 15};
|
|
int count = g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_LUNA, LAZARUS_SHARE_CHECK) ? 2 : 1;
|
|
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
uint32_t seed = rng.Next();
|
|
RoomConfig_Room* config = random_room_get(seed, room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_SUPERSECRET, -1));
|
|
LevelGenerator_Room* room = end_room_take(placement.generator, config);
|
|
|
|
if (!room) return i > 0;
|
|
level.place_room(*room, config, seed, nullptr);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// A shop's subtype: its level from the Store Upgrade unlocks (random below the top on hard and Greedier runs), then
|
|
// from a copy of the generation RNG maybe the rare shop or one level up for Store Key, a strong crown or Silver
|
|
// Dollar, and Tainted Keeper's own kind. crownMultiplier is how strong the floor's crown is when it was asked.
|
|
static int shop_subtype_get(Level& level, int& crownMultiplier)
|
|
{
|
|
Game& game = *g_game;
|
|
RNG rng = {level.generationRNG.Next(), 3, 3, 26};
|
|
uint32_t lowLevels = 1 + is_unlocked(ACHIEVEMENT_STORE_UPGRADE_1) + is_unlocked(ACHIEVEMENT_STORE_UPGRADE_3);
|
|
uint32_t highLevels = 1 + is_unlocked(ACHIEVEMENT_STORE_UPGRADE_2) + is_unlocked(ACHIEVEMENT_STORE_UPGRADE_4);
|
|
uint32_t lowLevel = rng.Next() % lowLevels;
|
|
int subtype = (int)(lowLevel + rng.Next() % highLevels);
|
|
bool isRandomLevel =
|
|
(rng.Next() & 1) && (game.difficulty == DIFFICULTY_HARD || game.difficulty == DIFFICULTY_GREEDIER);
|
|
Entity_Player* storeKeyOwner = game.playerManager.FirstTrinketOwner(TRINKET_STORE_KEY);
|
|
int storeKey = storeKeyOwner ? storeKeyOwner->GetTrinketMultiplier(TRINKET_STORE_KEY) : 0;
|
|
uint32_t roll = rng.Next();
|
|
auto is_lucky = [&]() {
|
|
crownMultiplier = crown_multiplier_get(level);
|
|
return crownMultiplier >= 2 || ((level.stage == STAGE_WOMB_I || level.stage == STAGE_WOMB_II) &&
|
|
is_trinket_strong(TRINKET_SILVER_DOLLAR, 2));
|
|
};
|
|
bool isLucky = false;
|
|
|
|
if (!isRandomLevel) subtype = (int)(lowLevels + highLevels) - 2;
|
|
if ((roll & 0xff) == 1 && subtype >= 2) subtype = SHOP_SUBTYPE_RARE;
|
|
else if ((roll & 0xff) == 0 && storeKey < 2)
|
|
{
|
|
subtype = SHOP_SUBTYPE_STORE_KEY;
|
|
isLucky = is_lucky();
|
|
}
|
|
else isLucky = storeKey >= 3 || is_lucky();
|
|
|
|
if (isLucky && subtype != SHOP_LEVEL_MAX && (rng.Next() & 3))
|
|
subtype = subtype == SHOP_SUBTYPE_STORE_KEY ? 0 : std::min(subtype + 1, SHOP_LEVEL_MAX);
|
|
else if (isLucky) subtype = SHOP_SUBTYPE_RARE;
|
|
|
|
for (Entity_Player* player : game.playerManager.playerList)
|
|
if (player->variant == PLAYER_VARIANT_PLAYER && !player->isCoopGhost && player->playerType == PLAYER_KEEPER_B)
|
|
return subtype + SHOP_SUBTYPE_TAINTED_KEEPER;
|
|
return subtype;
|
|
}
|
|
|
|
// The shop on a dead end, required where the floor has one (is_deal_floor) unless the challenge leaves it out or after
|
|
// a third victory lap. A golden crown reveals it.
|
|
static bool shop_place(SpecialRoomPlacement& placement)
|
|
{
|
|
Level& level = placement.level;
|
|
int crownMultiplier = 0;
|
|
|
|
if (!is_deal_floor(level, TRINKET_SILVER_DOLLAR) || placement.is_excluded(ROOM_SHOP) || g_game->victoryLap >= 3)
|
|
return true;
|
|
|
|
int subtype = shop_subtype_get(level, crownMultiplier);
|
|
RoomConfig_Room* config =
|
|
random_room_get(level.generationRNG.Next(), room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_SHOP, subtype));
|
|
LevelGenerator_Room* room = end_room_take(placement.generator, config);
|
|
RoomDescriptor* desc = nullptr;
|
|
|
|
if (!room) return false;
|
|
placement.shopIdx = level.nbRooms;
|
|
level.place_room(*room, config, level.generationRNG._seed, &desc);
|
|
if (crownMultiplier >= 3) desc->displayFlags |= ROOM_DISPLAY_ICON;
|
|
return true;
|
|
}
|
|
|
|
// A treasure room's subtype: 1 in 100 (or at Golden Horse Shoe's odds while someone holds it, or in the special
|
|
// daily) the more options kind, else the plain one, each the Pay to Win kind while someone holds it.
|
|
static int treasure_subtype_get(RNG& rng)
|
|
{
|
|
PlayerManager& players = g_game->playerManager;
|
|
bool isOptions = rng.Next() % TREASURE_OPTIONS_ODDS == 0;
|
|
|
|
if (!isOptions)
|
|
{
|
|
uint32_t period =
|
|
HORSE_SHOE_PERIOD / (uint32_t)std::max(1, players.GetTrinketMultiplier(TRINKET_GOLDEN_HORSE_SHOE));
|
|
bool isHorseShoe = rng.Next() % std::max(period, 1u) < HORSE_SHOE_HITS || period == 0;
|
|
|
|
isOptions =
|
|
(isHorseShoe && players.FirstTrinketOwner(TRINKET_GOLDEN_HORSE_SHOE, nullptr, LAZARUS_SHARE_CHECK)) ||
|
|
g_game->dailyChallenge._specialDailyId == SPECIAL_DAILY_TREASURE_OPTIONS;
|
|
}
|
|
|
|
bool isPayToWin = players.FirstTrinketOwner(TRINKET_PAY_TO_WIN, nullptr, LAZARUS_SHARE_CHECK);
|
|
|
|
return isOptions ? (isPayToWin ? TREASURE_SUBTYPE_OPTIONS_PAY_TO_WIN : TREASURE_SUBTYPE_OPTIONS)
|
|
: (isPayToWin ? TREASURE_SUBTYPE_PAY_TO_WIN : 0);
|
|
}
|
|
|
|
// The treasure room (two on XL floors, the second's draws undone) on dead ends where the floor has one, required. A
|
|
// golden crown reveals it. A floor without one gets the Repentance path's mirror world treasure room instead.
|
|
static bool treasure_rooms_place(SpecialRoomPlacement& placement)
|
|
{
|
|
Level& level = placement.level;
|
|
LevelGenerator_Room* room = nullptr;
|
|
RoomConfig_Room* config = nullptr;
|
|
uint32_t firstSeed = 0;
|
|
|
|
if (!is_deal_floor(level, TRINKET_BLOODY_CROWN) || placement.is_excluded(ROOM_TREASURE))
|
|
{
|
|
if (g_game->GetChallengeParams().pathType != PATH_TYPE_REPENTANCE || !level.HasMirrorDimension()) return true;
|
|
config = fallback_room_get(level.generationRNG.Next(), room_query(placement.stageId, ROOM_TREASURE, 0),
|
|
STAGE_ID_SPECIAL_ROOMS);
|
|
if (!(room = end_room_take(placement.generator, config))) return false;
|
|
level.place_room(*room, config, level.generationRNG._seed, nullptr);
|
|
return true;
|
|
}
|
|
|
|
for (int i = 0; i == 0 || (i < 2 && (level.GetCurses() & CURSE_OF_LABYRINTH)); i++)
|
|
{
|
|
int subtype = treasure_subtype_get(level.generationRNG);
|
|
RoomDescriptor* desc = nullptr;
|
|
|
|
config = fallback_room_get(level.generationRNG.Next(), room_query(placement.stageId, ROOM_TREASURE, subtype),
|
|
STAGE_ID_SPECIAL_ROOMS);
|
|
if (!(room = end_room_take(placement.generator, config))) return false;
|
|
level.place_room(*room, config, level.generationRNG._seed, &desc);
|
|
if (crown_multiplier_get(level) >= 3) desc->displayFlags |= ROOM_DISPLAY_ICON;
|
|
if (i == 0) firstSeed = level.generationRNG._seed;
|
|
}
|
|
level.generationRNG.SetSeed(firstSeed, GENERATION_SHIFT_INDEX);
|
|
return true;
|
|
}
|
|
|
|
// The planetarium at its chance once unlocked, unless the challenge leaves out planetariums or treasure rooms. Its
|
|
// dead end is taken (and given back) either way.
|
|
static void planetarium_place(SpecialRoomPlacement& placement)
|
|
{
|
|
Level& level = placement.level;
|
|
float chance = level.GetPlanetariumChance();
|
|
RoomConfig_Room* config =
|
|
random_room_get(level.generationRNG.Next(), room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_PLANETARIUM, -1));
|
|
LevelGenerator_Room* room = end_room_take(placement.generator, config);
|
|
bool isExcluded = placement.is_excluded(ROOM_PLANETARIUM) || placement.is_excluded(ROOM_TREASURE);
|
|
|
|
if (!isExcluded && room && level.generationRNG.RandomFloat() < chance && is_unlocked(ACHIEVEMENT_PLANETARIUMS))
|
|
level.place_room(*room, config, level.generationRNG._seed, nullptr);
|
|
else end_room_return(placement.generator, room);
|
|
}
|
|
|
|
// The dice room 1 in 50 (or 1 in 5 with two keys) unless left out, else the sacrifice room, placed 1 in 7, or 1 in 4
|
|
// at full health or as Lazarus.
|
|
static void sacrifice_room_place(SpecialRoomPlacement& placement)
|
|
{
|
|
Level& level = placement.level;
|
|
RNG& rng = level.generationRNG;
|
|
PlayerManager& players = g_game->playerManager;
|
|
bool isDice = rng.Next() % DICE_ROOM_ODDS == 0 ||
|
|
(rng.Next() % DICE_ROOM_KEY_ODDS == 0 && g_game->GetPlayer(0)->numKeys >= 2);
|
|
int type = isDice && !placement.is_excluded(ROOM_DICE) ? ROOM_DICE : ROOM_SACRIFICE;
|
|
RoomConfig_Room* config = random_room_get(rng.Next(), room_query(STAGE_ID_SPECIAL_ROOMS, type, -1));
|
|
LevelGenerator_Room* room = end_room_take(placement.generator, config);
|
|
auto is_placed = [&]() {
|
|
if (rng.Next() % SACRIFICE_ROOM_ODDS == 0) return true;
|
|
rng.Next();
|
|
if (rng._seed & 3) return false;
|
|
return players.check_full_health(HEALTH_CHECK_ANY) || players.FirstPlayerByType(PLAYER_LAZARUS) ||
|
|
players.FirstPlayerByType(PLAYER_LAZARUS2);
|
|
};
|
|
|
|
if (!placement.is_excluded(ROOM_SACRIFICE) && is_placed()) room_place(level, room, config, rng._seed);
|
|
else end_room_return(placement.generator, room);
|
|
}
|
|
|
|
// The library, its level from the Store Upgrade unlocks and its config's weight kept, placed 1 in 20, or 1 in 4 once a
|
|
// book was picked up.
|
|
static void library_place(SpecialRoomPlacement& placement)
|
|
{
|
|
Level& level = placement.level;
|
|
RNG& rng = level.generationRNG;
|
|
int maxLevel = is_unlocked(ACHIEVEMENT_STORE_UPGRADE_4) ? 4
|
|
: is_unlocked(ACHIEVEMENT_STORE_UPGRADE_3) ? 3
|
|
: is_unlocked(ACHIEVEMENT_STORE_UPGRADE_2) ? 2
|
|
: is_unlocked(ACHIEVEMENT_STORE_UPGRADE_1);
|
|
int subtype = (int)rng.RandomInt((uint32_t)maxLevel + 1);
|
|
RoomConfig_Room* config =
|
|
random_room_get(rng.Next(), room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_LIBRARY, subtype), WEIGHT_KEEP);
|
|
LevelGenerator_Room* room = end_room_take(placement.generator, config);
|
|
auto is_placed = [&]() {
|
|
if (rng.Next() % LIBRARY_ODDS == 0) return true;
|
|
rng.Next();
|
|
return (rng._seed & 3) == 0 && game_flag_get(LEVEL_GAME_STATE_BOOK_PICKED_UP);
|
|
};
|
|
|
|
if (!placement.is_excluded(ROOM_LIBRARY) && is_placed()) room_place(level, room, config, rng._seed);
|
|
else end_room_return(placement.generator, room);
|
|
}
|
|
|
|
// The curse room (two with Voodoo Head, which prefers its own kind) on every floor that has a dead end for it, drawn
|
|
// from a copy of the generation RNG.
|
|
static void curse_rooms_place(SpecialRoomPlacement& placement)
|
|
{
|
|
RNG rng = {placement.level.generationRNG.Next(), 11, 7, 12};
|
|
bool isVoodoo = g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_VOODOO_HEAD, LAZARUS_SHARE_CHECK);
|
|
|
|
for (int i = 0; i < (isVoodoo ? 2 : 1); i++)
|
|
{
|
|
RoomConfig_Room*& config = placement.config;
|
|
|
|
config = isVoodoo ? random_room_get(rng.Next(), room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_CURSE, 1)) : nullptr;
|
|
if (!config) config = random_room_get(rng.Next(), room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_CURSE, 0));
|
|
placement.endRoom = end_room_take(placement.generator, config);
|
|
if (placement.is_excluded(ROOM_CURSE)) end_room_return(placement.generator, placement.endRoom);
|
|
else
|
|
{
|
|
if (rng.Next() & 1) rng.Next();
|
|
room_place(placement.level, placement.endRoom, config, rng._seed);
|
|
}
|
|
}
|
|
}
|
|
|
|
// The sin a miniboss room fights: Ultra Pride 1 in 10 from the third floor once a run, else one of the sins not met
|
|
// this run, its super version at odds that shorten with the unlocks from the third floor. -1 when every sin was met.
|
|
static int miniboss_sin_get(SpecialRoomPlacement& placement)
|
|
{
|
|
RNG& rng = placement.level.generationRNG;
|
|
PersistentGameData& data = g_manager->persistentGameData;
|
|
int superOdds = 0;
|
|
bool isSuper = false;
|
|
std::vector<int> sins;
|
|
|
|
if (placement.effectiveStage > 2)
|
|
{
|
|
superOdds = is_unlocked(ACHIEVEMENT_THE_WOMB) ? SUPER_SIN_ODDS_WOMB : SUPER_SIN_ODDS;
|
|
if (is_unlocked(ACHIEVEMENT_EVERYTHING_IS_TERRIBLE)) superOdds = SUPER_SIN_ODDS_TERRIBLE;
|
|
if (data.eventCounters[EVENT_COUNTER_SUPER_SINS_A] + data.eventCounters[EVENT_COUNTER_SUPER_SINS_B] != 0)
|
|
superOdds = SUPER_SIN_ODDS_EVENT;
|
|
if (rng.Next() % ULTRA_PRIDE_ODDS == 0 && !game_flag_get(STATE_ULTRA_PRIDE_SPAWNED))
|
|
{
|
|
rng.Next();
|
|
return SIN_ULTRA_PRIDE;
|
|
}
|
|
}
|
|
|
|
isSuper = superOdds != 0 && rng.RandomInt((uint32_t)superOdds) == 0;
|
|
for (MinibossSin sin : MINIBOSS_SINS)
|
|
if (!game_flag_get(sin.flag)) sins.push_back(isSuper ? sin.superSubtype : sin.subtype);
|
|
return sins.empty() ? -1 : sins[rng.RandomInt((uint32_t)sins.size())];
|
|
}
|
|
|
|
// The sin miniboss room, placed 1 in 4, or 1 in 3 of the rest on the first floor. It marks its sin met and keeps Greed
|
|
// from taking over the floor. With every sin met the original goes on with the curse room's last config and end room.
|
|
static void miniboss_room_place(SpecialRoomPlacement& placement)
|
|
{
|
|
Level& level = placement.level;
|
|
RNG& rng = level.generationRNG;
|
|
int difficulty = level.stage < STAGE_WOMB_I ? DIFFICULTY_EASY : DIFFICULTY_HARD_MAX;
|
|
int sin = miniboss_sin_get(placement);
|
|
|
|
if (sin >= 0)
|
|
{
|
|
RoomQuery query = room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_MINIBOSS, sin);
|
|
|
|
query.minDifficulty = query.maxDifficulty = difficulty;
|
|
if (!(placement.config = random_room_get(rng.Next(), query)))
|
|
placement.config = random_room_get(rng.Next(), room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_MINIBOSS, sin));
|
|
placement.endRoom = end_room_take(placement.generator, placement.config);
|
|
}
|
|
|
|
bool isPlaced = !placement.is_excluded(ROOM_MINIBOSS) &&
|
|
((rng.Next() & 3) == 0 || (rng.Next() % 3 == 0 && placement.effectiveStage == 1));
|
|
|
|
if (!isPlaced) return end_room_return(placement.generator, placement.endRoom);
|
|
if (!placement.endRoom) return;
|
|
level.place_room(*placement.endRoom, placement.config, rng._seed, nullptr);
|
|
placement.isTakeoverAllowed = false;
|
|
for (MinibossSin entry : MINIBOSS_SINS)
|
|
if (sin == entry.subtype || sin == entry.superSubtype) game_flag_set(entry.flag, true);
|
|
if (sin == SIN_ULTRA_PRIDE) game_flag_set(STATE_ULTRA_PRIDE_SPAWNED, true);
|
|
}
|
|
|
|
// The challenge room (the boss challenge on even floors) at full health from the second floor, on the second only 1
|
|
// in 2.
|
|
static void challenge_room_place(SpecialRoomPlacement& placement)
|
|
{
|
|
Level& level = placement.level;
|
|
RNG& rng = level.generationRNG;
|
|
RoomConfig_Room* config =
|
|
random_room_get(rng.Next(), room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_CHALLENGE, level.isBossChallenge ? 1 : 0));
|
|
LevelGenerator_Room* room = end_room_take(placement.generator, config);
|
|
bool isPlaced = !placement.is_excluded(ROOM_CHALLENGE) && (!(rng.Next() & 1) || placement.effectiveStage >= 3) &&
|
|
g_game->playerManager.check_full_health(HEALTH_CHECK_ANY) && placement.effectiveStage >= 2;
|
|
|
|
if (isPlaced) room_place(level, room, config, rng._seed);
|
|
else end_room_return(placement.generator, room);
|
|
}
|
|
|
|
// The chest room 1 in 10 (or 1 in 3 with two keys) unless left out, else the arcade (Cain's Birthright's kind for
|
|
// Cain). The arcade needs five coins and the chest two keys, both on even floors (any floor before the Dark Room with
|
|
// Cain's Birthright).
|
|
static void arcade_place(SpecialRoomPlacement& placement)
|
|
{
|
|
Level& level = placement.level;
|
|
RNG& rng = level.generationRNG;
|
|
Entity_Player& player = *g_game->GetPlayer(0);
|
|
bool isCainBirthright = g_game->playerManager.FirstBirthrightOwner(PLAYER_CAIN);
|
|
bool isChest = rng.Next() % CHEST_ROOM_ODDS == 0 || (rng.Next() % CHEST_ROOM_KEY_ODDS == 0 && player.numKeys >= 2);
|
|
RoomConfig_Room* config = nullptr;
|
|
|
|
if (isChest && !placement.is_excluded(ROOM_CHEST) && !isCainBirthright)
|
|
config = random_room_get(rng.Next(), room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_CHEST, -1));
|
|
if (!config && isCainBirthright)
|
|
config = random_room_get(rng.Next(), room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_ARCADE, 1));
|
|
if (!config) config = random_room_get(rng.Next(), room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_ARCADE, 0));
|
|
|
|
LevelGenerator_Room* room = end_room_take(placement.generator, config);
|
|
int stage = placement.effectiveStage;
|
|
bool isEvenFloor = stage == 2 || stage == 4 || stage == 6 || stage == 8;
|
|
bool isAffordable = config && ((config->type == ROOM_ARCADE && (player.numCoins >= 5 || isCainBirthright)) ||
|
|
(config->type == ROOM_CHEST && player.numKeys >= 2));
|
|
|
|
if (config && !placement.is_excluded(config->type) && isAffordable &&
|
|
(isEvenFloor || (isCainBirthright && stage < (int)STAGE_DARK_ROOM)))
|
|
room_place(level, room, config, rng._seed);
|
|
else end_room_return(placement.generator, room);
|
|
}
|
|
|
|
// Isaac's bedroom, or the barren one 1 in 2 where a trapdoor may spawn (always when Isaac's is left out), placed 1 in
|
|
// 50, or 1 in 5 while a player is close to dying.
|
|
static void bedroom_place(SpecialRoomPlacement& placement)
|
|
{
|
|
Level& level = placement.level;
|
|
RNG& rng = level.generationRNG;
|
|
bool isIsaacsExcluded = placement.is_excluded(ROOM_ISAACS);
|
|
bool isBarrenAllowed = !placement.is_excluded(ROOM_BARREN) && level.CanSpawnTrapDoor();
|
|
bool isBarren = ((rng.Next() & 1) && isBarrenAllowed) || isIsaacsExcluded;
|
|
RoomConfig_Room* config =
|
|
random_room_get(rng.Next(), room_query(STAGE_ID_SPECIAL_ROOMS, isBarren ? ROOM_BARREN : ROOM_ISAACS, -1));
|
|
LevelGenerator_Room* room = end_room_take(placement.generator, config);
|
|
bool isDying = false;
|
|
|
|
for (Entity_Player* player : g_game->playerManager.playerList)
|
|
{
|
|
if (player->variant != PLAYER_VARIANT_PLAYER) continue;
|
|
|
|
HealthType healthType = player->GetHealthType();
|
|
int containers = player->maxHearts;
|
|
|
|
if (healthType != HEALTH_SOUL && healthType != HEALTH_NO_HEALTH) containers += player->boneHearts * 2;
|
|
isDying = (player->redHearts < 2 && player->soulHearts < 1) || (containers < 1 && player->soulHearts < 3);
|
|
if (isDying) break;
|
|
}
|
|
|
|
if (rng.Next() % BEDROOM_ODDS == 0 || (rng.Next() % BEDROOM_DYING_ODDS == 0 && isDying))
|
|
room_place(level, room, config, rng._seed);
|
|
else end_room_return(placement.generator, room);
|
|
}
|
|
|
|
// The rooms behind the alternate path's special doors: the mirror on Downpour II and Dross II, and the mineshaft
|
|
// entrance on Mines II and Ashpit II with the first knife piece, required. It counts the normal rooms the floor's
|
|
// special door puzzle needs (the strange door's once unlocked).
|
|
static bool special_door_rooms_place(SpecialRoomPlacement& placement)
|
|
{
|
|
Level& level = placement.level;
|
|
RNG& rng = level.generationRNG;
|
|
RoomConfig_Room* config = nullptr;
|
|
LevelGenerator_Room* room = nullptr;
|
|
|
|
if (level.HasMirrorDimension())
|
|
{
|
|
RoomQuery query = room_query(placement.stageId, ROOM_DEFAULT, MIRROR_ROOM_SUBTYPE);
|
|
|
|
query.minDifficulty = query.maxDifficulty = 0;
|
|
config = random_room_get(rng.Next(), query);
|
|
if (!(room = end_room_take(placement.generator, config))) return false;
|
|
level.place_room(*room, config, rng._seed, nullptr);
|
|
placement.specialDoorRooms = 1;
|
|
}
|
|
else if (level.HasAbandonedMineshaft())
|
|
{
|
|
if (!g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_KNIFE_PIECE_1, LAZARUS_SHARE_CHECK)) return true;
|
|
|
|
RNG entranceRng = {rng._seed, 5, 7, 22};
|
|
uint32_t seed = entranceRng.Next();
|
|
RoomQuery query = room_query(placement.stageId, ROOM_DEFAULT, MINESHAFT_ENTRANCE_SUBTYPE);
|
|
|
|
query.minDifficulty = query.maxDifficulty = 0;
|
|
config = fallback_room_get(seed, query, STAGE_ID_MINES);
|
|
if (!(room = end_room_take(placement.generator, config))) return false;
|
|
level.place_room(*room, config, seed, nullptr);
|
|
placement.specialDoorRooms = 2;
|
|
}
|
|
else if (level.HasPhotoDoor() && is_unlocked(ACHIEVEMENT_STRANGE_DOOR)) placement.specialDoorRooms = 1;
|
|
return true;
|
|
}
|
|
|
|
// The secret room (a second with Fragmented Card, one more with Luna) on the best scoring cells, from the seed drawn
|
|
// after the super secret rooms. A golden Fragmented Card reveals the first, a stronger one the first two.
|
|
static void secret_rooms_place(SpecialRoomPlacement& placement)
|
|
{
|
|
if (placement.is_excluded(ROOM_SECRET)) return;
|
|
|
|
Level& level = placement.level;
|
|
PlayerManager& players = g_game->playerManager;
|
|
Entity_Player* cardOwner = players.FirstTrinketOwner(TRINKET_FRAGMENTED_CARD);
|
|
int cardMultiplier = cardOwner ? cardOwner->GetTrinketMultiplier(TRINKET_FRAGMENTED_CARD) : 0;
|
|
int count = (cardOwner ? 2 : 1) + (players.FirstCollectibleOwner(COLLECTIBLE_LUNA, LAZARUS_SHARE_CHECK) ? 1 : 0);
|
|
RNG rng = {placement.secretSeed, 1, 5, 16};
|
|
|
|
for (int i = 0; i < count; i++, rng.Next())
|
|
{
|
|
RoomConfig_Room* config =
|
|
fallback_room_get(rng._seed, room_query(placement.stageId, ROOM_SECRET, -1), STAGE_ID_SPECIAL_ROOMS);
|
|
LevelGenerator_Room* room = placement.generator.place_secret_room(level.get_secret_room_excluded_cells());
|
|
RoomDescriptor* desc = nullptr;
|
|
bool isRevealed = cardMultiplier == 2 ? i == 0 : cardMultiplier > 2 && i < 2;
|
|
|
|
if (!room || !config) continue;
|
|
placement.secretIdx = level.nbRooms;
|
|
level.place_room(*room, config, rng._seed, &desc);
|
|
if (isRevealed) desc->displayFlags |= ROOM_DISPLAY_ICON;
|
|
}
|
|
}
|
|
|
|
// The Dark Room's extra special room (any of variants 3 to 9 once unlocked, else variant 3), required.
|
|
static bool dark_room_extra_place(SpecialRoomPlacement& placement)
|
|
{
|
|
Level& level = placement.level;
|
|
|
|
if (level.stage != STAGE_DARK_ROOM || level.stageType != STAGETYPE_ORIGINAL) return true;
|
|
|
|
uint32_t seed = level.generationRNG.Next();
|
|
RoomQuery query = room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_DEFAULT, -1);
|
|
RoomConfig_Room* config = nullptr;
|
|
LevelGenerator_Room* room = nullptr;
|
|
|
|
query.minVariant = DARK_ROOM_EXTRA_VARIANT_FIRST;
|
|
query.maxVariant = DARK_ROOM_EXTRA_VARIANT_LAST;
|
|
config = is_unlocked(ACHIEVEMENT_THE_FORGOTTEN)
|
|
? random_room_get(seed, query)
|
|
: g_game->roomConfig.GetRoomByStageTypeAndVariant(STAGE_ID_SPECIAL_ROOMS, ROOM_DEFAULT,
|
|
DARK_ROOM_EXTRA_VARIANT_FIRST, ROOM_MODE_CURRENT);
|
|
if (!(room = end_room_take(placement.generator, config))) return false;
|
|
level.place_room(*room, config, seed, nullptr);
|
|
return true;
|
|
}
|
|
|
|
// The cells the door slots of the placed rooms lead into (an L shape's inner slots into its missing corner), for the
|
|
// slots isWanted picks. Cells off the grid are left out.
|
|
template <typename Wanted> static std::set<int> door_targets_collect(Level& level, Wanted isWanted)
|
|
{
|
|
std::set<int> cells;
|
|
|
|
for (int i = 0; i < level.nbRooms; i++)
|
|
{
|
|
RoomDescriptor& room = level.roomList[i];
|
|
|
|
if (!room.data || room.gridIndex < 0) continue;
|
|
for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++)
|
|
{
|
|
XY target = LevelGenerator::get_door_target_position(XY::NewFromGridIdx(room.gridIndex), room.data->shape,
|
|
slot, THIN_SHAPES_IGNORED);
|
|
|
|
if (target.ToGridIdx() >= 0 && isWanted(*room.data, slot)) cells.insert(target.ToGridIdx());
|
|
}
|
|
}
|
|
return cells;
|
|
}
|
|
|
|
// The ultra secret room, beside the rooms only through their closed sides or their boss, secret, super secret and
|
|
// curse rooms' doors. It joins no group's random teleports.
|
|
static void ultra_secret_room_place(SpecialRoomPlacement& placement)
|
|
{
|
|
Level& level = placement.level;
|
|
RNG rng = {placement.secretSeed, 13, 3, 17};
|
|
uint32_t seed = rng.Next();
|
|
RoomConfig_Room* config = nullptr;
|
|
|
|
if (placement.is_excluded(ROOM_ULTRASECRET)) return;
|
|
config = fallback_room_get(seed, room_query(placement.stageId, ROOM_ULTRASECRET, -1), STAGE_ID_SPECIAL_ROOMS);
|
|
if (!config) return;
|
|
|
|
std::set<int> doorCells = door_targets_collect(level, [](RoomConfig_Room& data, int slot) {
|
|
return !(data.doors >> slot & 1) || data.type == ROOM_BOSS || data.type == ROOM_SUPERSECRET ||
|
|
data.type == ROOM_SECRET || data.type == ROOM_CURSE;
|
|
});
|
|
|
|
if (LevelGenerator_Room* room = placement.generator.try_place_room(&doorCells))
|
|
{
|
|
level.place_room(*room, config, seed, nullptr);
|
|
level.roomList[level.nbRooms - 1].group = ULTRA_SECRET_GROUP;
|
|
}
|
|
}
|
|
|
|
// The normal rooms on every layout room left: the start room the stage's own (the Dark Room and Chest's, else the
|
|
// special set's variant 2), the others drawn in their shape and doors, 1 in 8 as easy as the easiest. Each one placed
|
|
// is listed with its layout room. Fails on a layout room no config fits.
|
|
static bool normal_rooms_place(SpecialRoomPlacement& placement, int minDifficulty, int maxDifficulty,
|
|
std::vector<PlacedRoom>& placed)
|
|
{
|
|
Level& level = placement.level;
|
|
RNG& rng = level.generationRNG;
|
|
std::vector<LevelGenerator_Room*> rooms = placement.generator.get_all_rooms();
|
|
bool isDarkRoomFloor = level.stage == STAGE_DARK_ROOM;
|
|
|
|
placed.reserve(rooms.size());
|
|
for (LevelGenerator_Room* room : rooms)
|
|
{
|
|
RoomQuery query = room_query(placement.stageId, ROOM_DEFAULT, 0);
|
|
RoomConfig_Room* config = nullptr;
|
|
|
|
query.minDifficulty = minDifficulty > 1 && (rng._seed & 7) == 0 ? DIFFICULTY_EASY : minDifficulty;
|
|
query.maxDifficulty = maxDifficulty;
|
|
if (room->position.ToGridIdx() == level.startingRoomIdx && room->distanceFromStart == 0)
|
|
{
|
|
bool isChapter6Start = isDarkRoomFloor && level.stageType <= STAGETYPE_WOTL;
|
|
int stageId = !isChapter6Start ? STAGE_ID_SPECIAL_ROOMS
|
|
: level.stageType == STAGETYPE_ORIGINAL ? STAGE_ID_DARK_ROOM
|
|
: STAGE_ID_CHEST;
|
|
|
|
config = g_game->roomConfig.GetRoomByStageTypeAndVariant(
|
|
stageId, ROOM_DEFAULT, isChapter6Start ? 0 : START_ROOM_VARIANT, ROOM_MODE_CURRENT);
|
|
}
|
|
else
|
|
{
|
|
query.requiredDoors = room->doors;
|
|
query.shape = room->shape;
|
|
query.minVariant = isDarkRoomFloor ? 1 : 0;
|
|
config = random_room_get(rng.Next(), query);
|
|
}
|
|
|
|
if (!config)
|
|
{
|
|
log_printf(LOG_INFO,
|
|
"[warn] LevelGenerator could not find a required room (type=ROOM_DEFAULT, shape=%d, "
|
|
"difficulty=%d-%d, doors=%s.\n",
|
|
room->shape, query.minDifficulty, query.maxDifficulty,
|
|
std::bitset<DOOR_SLOT_COUNT>(room->doors).to_string().c_str());
|
|
return false;
|
|
}
|
|
level.place_room(*room, config, rng._seed, nullptr);
|
|
placed.push_back({&level.roomList[level.nbRooms - 1], room});
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// The normal rooms of the floor's special door puzzle: placed rooms in a shuffled order (not the start room), then new
|
|
// dead ends away from every door, each turned into a puzzle room (subtype 1) of its shape and doors from the floor's
|
|
// stage or its chapter's original. A copy of the generation RNG draws them. Fails when the dead ends run out.
|
|
static bool special_door_puzzle_place(SpecialRoomPlacement& placement, std::vector<PlacedRoom>& placed,
|
|
int minDifficulty, int maxDifficulty)
|
|
{
|
|
Level& level = placement.level;
|
|
RNG rng = {level.generationRNG._seed, 5, 21, 12};
|
|
int fallbackStageId = placement.stageId == STAGE_ID_DROSS ? STAGE_ID_DOWNPOUR
|
|
: placement.stageId == STAGE_ID_ASHPIT ? STAGE_ID_MINES
|
|
: placement.stageId == STAGE_ID_NECROPOLIS || placement.stageId == STAGE_ID_DANK_DEPTHS
|
|
? STAGE_ID_DEPTHS
|
|
: placement.stageId;
|
|
int needed = placement.specialDoorRooms;
|
|
int tries = (int)placed.size() + needed;
|
|
|
|
for (size_t i = placed.size() - 1; i > 0 && i < placed.size(); i--)
|
|
std::swap(placed[i], placed[rng.RandomInt((uint32_t)i + 1)]);
|
|
|
|
std::set<int> doorCells = level.get_door_neighbor_indices();
|
|
|
|
for (int i = 0; i < tries && needed > 0; i++)
|
|
{
|
|
PlacedRoom entry = i < (int)placed.size() ? placed[i] : PlacedRoom{};
|
|
|
|
if (entry.descriptor && entry.descriptor->gridIndex == level.startingRoomIdx) continue;
|
|
if (!entry.descriptor && !(entry.room = placement.generator.try_add_dead_end(&doorCells))) return false;
|
|
|
|
RoomQuery query = room_query(placement.stageId, ROOM_DEFAULT, SPECIAL_DOOR_PUZZLE_SUBTYPE);
|
|
|
|
query.minDifficulty = minDifficulty > 1 && (rng._seed & 7) == 0 ? DIFFICULTY_EASY : minDifficulty;
|
|
query.maxDifficulty = maxDifficulty;
|
|
query.requiredDoors = entry.room->doors;
|
|
query.shape = entry.room->shape;
|
|
|
|
RoomConfig_Room* config = fallback_room_get(rng.Next(), query, fallbackStageId);
|
|
|
|
query.minDifficulty = DIFFICULTY_EASY;
|
|
query.maxDifficulty = DIFFICULTY_HARD_MAX;
|
|
if (!config && !(config = fallback_room_get(rng.Next(), query, fallbackStageId))) continue;
|
|
needed--;
|
|
if (!entry.descriptor) level.place_room(*entry.room, config, rng.Next(), nullptr);
|
|
else
|
|
{
|
|
entry.descriptor->data = config;
|
|
entry.descriptor->allowedDoors = config->doors;
|
|
}
|
|
}
|
|
return needed <= 0;
|
|
}
|
|
|
|
// Greed's takeover: with the Greed minibosses not both met and no miniboss room on the floor, the secret room (past the
|
|
// Caves) and then the shop (past the Basement) are taken over at a third of 1 (1.05 with 20 coins, more after a
|
|
// donation machine blew up or a shopkeeper died, less per Greed donation). The secret room's leaves the shop alone
|
|
// 999 in 1000 times.
|
|
static void greed_takeover_roll(SpecialRoomPlacement& placement)
|
|
{
|
|
Level& level = placement.level;
|
|
Game& game = *g_game;
|
|
bool isAllowed = placement.isTakeoverAllowed &&
|
|
!(game_flag_get(STATE_GREED_SPAWNED) && game_flag_get(STATE_SUPER_GREED_SPAWNED));
|
|
float chance = game.GetPlayer(0)->numCoins >= TAKEOVER_COINS ? TAKEOVER_CHANCE_RICH : 1;
|
|
|
|
for (auto [flag, bonus] : TAKEOVER_BONUSES)
|
|
if (game_flag_get(flag))
|
|
{
|
|
game_flag_set(flag, false);
|
|
chance += bonus;
|
|
}
|
|
chance = (chance - (float)std::min(game.donationModGreed, TAKEOVER_DONATIONS_MAX) * TAKEOVER_DONATION_PENALTY) *
|
|
TAKEOVER_SHARE;
|
|
game.donationModGreed = 0;
|
|
|
|
if (level.generationRNG.RandomFloat() < chance && isAllowed && placement.secretIdx >= 0 &&
|
|
level.stage > STAGE_CAVES_II)
|
|
{
|
|
RNG takeoverRng = {level.generationRNG._seed, 2, 7, 9};
|
|
|
|
if (takeoverRng.RandomInt(TAKEOVER_BOTH_ODDS) != 0) isAllowed = false;
|
|
level.roomList[placement.secretIdx].flags |= ROOM_DESCRIPTOR_FLAG_SURPRISE_MINIBOSS;
|
|
}
|
|
if (level.generationRNG.RandomFloat() < chance && isAllowed && placement.shopIdx >= 0 &&
|
|
level.stage > STAGE_CAVES_I)
|
|
level.roomList[placement.shopIdx].flags |= ROOM_DESCRIPTOR_FLAG_SURPRISE_MINIBOSS;
|
|
}
|
|
|
|
// Seeds a room off the map from rng and draws its config.
|
|
static void off_map_room_init(Level& level, int idx, RNG& rng, RoomQuery query)
|
|
{
|
|
RoomDescriptor& desc = *level.GetRoomByIdx(idx);
|
|
|
|
desc.InitSeeds(rng);
|
|
desc.data = random_room_get(rng.Next(), query);
|
|
}
|
|
|
|
// The rooms off the map: the error room, black market, crawl space, Boss Rush (Mom's shovel's own with the Broken
|
|
// Shovel), Mega Satan's, the Blue Womb's entrance (the Void's on the Blue Womb), the Member Card's shop and the angel
|
|
// shop, and on the alternate path's last Womb floor the secret exit's boss room.
|
|
static void off_map_rooms_init(SpecialRoomPlacement& placement)
|
|
{
|
|
Level& level = placement.level;
|
|
RNG& rng = level.generationRNG;
|
|
RoomConfig& roomConfig = g_game->roomConfig;
|
|
RoomQuery query = room_query(STAGE_ID_BLUE_WOMB, ROOM_DEFAULT, 1);
|
|
|
|
off_map_room_init(level, ROOM_ERROR_IDX, rng, room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_ERROR, -1));
|
|
off_map_room_init(level, ROOM_BLACK_MARKET_IDX, rng, room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_BLACK_MARKET, -1));
|
|
off_map_room_init(level, ROOM_DUNGEON_IDX, rng, room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_DUNGEON, -1));
|
|
if (g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_BROKEN_SHOVEL_1, LAZARUS_SHARE_CHECK))
|
|
{
|
|
RoomDescriptor& bossRush = *level.GetRoomByIdx(ROOM_BOSSRUSH_IDX);
|
|
|
|
bossRush.InitSeeds(rng);
|
|
rng.Next();
|
|
bossRush.data =
|
|
roomConfig.GetRoomByStageTypeAndVariant(STAGE_ID_SPECIAL_ROOMS, ROOM_BOSSRUSH, 0, ROOM_MODE_CURRENT);
|
|
}
|
|
else off_map_room_init(level, ROOM_BOSSRUSH_IDX, rng, room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_BOSSRUSH, -1));
|
|
off_map_room_init(level, ROOM_MEGA_SATAN_IDX, rng, room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_BOSS, BOSS_MEGA_SATAN));
|
|
query.minDifficulty = query.maxDifficulty = 0;
|
|
off_map_room_init(level, placement.stageId == STAGE_ID_BLUE_WOMB ? ROOM_THE_VOID_IDX : ROOM_BLUE_WOMB_IDX, rng,
|
|
query);
|
|
|
|
RNG shopRng = {rng.Next(), 3, 3, 26};
|
|
uint32_t highLevel = shopRng.RandomInt(1 + is_unlocked(ACHIEVEMENT_STORE_UPGRADE_3));
|
|
uint32_t lowLevel =
|
|
shopRng.RandomInt(1 + is_unlocked(ACHIEVEMENT_STORE_UPGRADE_2) + is_unlocked(ACHIEVEMENT_STORE_UPGRADE_4));
|
|
|
|
off_map_room_init(level, ROOM_SECRET_SHOP_IDX, shopRng,
|
|
room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_SHOP, (int)(highLevel + lowLevel)));
|
|
|
|
RNG angelRng = {rng.Next(), 3, 3, 28};
|
|
|
|
off_map_room_init(level, ROOM_ANGEL_SHOP_IDX, angelRng, room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_ANGEL, 1));
|
|
if (level.IsAltPath() && (level.stage == STAGE_WOMB_II ||
|
|
(level.stage == STAGE_WOMB_I && (level.GetCurses() & CURSE_OF_LABYRINTH))))
|
|
{
|
|
rng.Next();
|
|
off_map_room_init(level, ROOM_SECRET_EXIT_IDX, rng, room_query(placement.stageId, ROOM_BOSS, BOSS_MOTHER));
|
|
}
|
|
}
|
|
|
|
// 00739370 Places the floor's rooms on its layout: the boss room, super secret, shop, treasure and planetarium rooms,
|
|
// below the Dark Room the sacrifice or dice room, library, curse, miniboss, challenge and arcade or chest rooms, below
|
|
// the Womb the bedroom, the alternate path's special door rooms, the secret, Dark Room and ultra secret rooms, then the
|
|
// normal rooms and the special door puzzle's, Greed's takeover and the rooms off the map. A room that loses its roll
|
|
// gives its dead end back. False when a required room has no dead end, for the layout to be generated again.
|
|
bool Level::place_special_rooms(LevelGenerator& generator, int minDifficulty, int maxDifficulty)
|
|
{
|
|
SpecialRoomPlacement placement = {
|
|
.level = *this, .generator = generator, .excludedTypes = g_game->GetChallengeParams().roomset};
|
|
std::vector<PlacedRoom> placed;
|
|
|
|
placement.stageId = RoomConfig::GetStageID((int)stage, (int)stageType, ROOM_MODE_CURRENT);
|
|
placement.effectiveStage = (int)stage + (IsAltPath() ? 1 : 0);
|
|
if (!boss_rooms_place(placement) || !super_secret_rooms_place(placement)) return false;
|
|
placement.secretSeed = generationRNG.Next();
|
|
if (!shop_place(placement) || !treasure_rooms_place(placement)) return false;
|
|
planetarium_place(placement);
|
|
if (stage < STAGE_DARK_ROOM)
|
|
{
|
|
sacrifice_room_place(placement);
|
|
library_place(placement);
|
|
curse_rooms_place(placement);
|
|
miniboss_room_place(placement);
|
|
challenge_room_place(placement);
|
|
arcade_place(placement);
|
|
}
|
|
if (stage < STAGE_WOMB_I) bedroom_place(placement);
|
|
if (!special_door_rooms_place(placement)) return false;
|
|
secret_rooms_place(placement);
|
|
if (!dark_room_extra_place(placement)) return false;
|
|
ultra_secret_room_place(placement);
|
|
if (!normal_rooms_place(placement, minDifficulty, maxDifficulty, placed)) return false;
|
|
for (size_t i = placed.size(); i < generator.rooms.size(); i++) generationRNG.Next();
|
|
if (placement.specialDoorRooms && !special_door_puzzle_place(placement, placed, minDifficulty, maxDifficulty))
|
|
return false;
|
|
greed_takeover_roll(placement);
|
|
off_map_rooms_init(placement);
|
|
return true;
|
|
}
|
|
|
|
// 00739080 A boss room config for bossId, drawn from seed: a negative id is the Double Trouble rooms from its variant,
|
|
// redrawn up to 50 times while one is a pairing not unlocked yet. Mother's heart room after her kill is the stage's
|
|
// own. Any other boss's rooms are redrawn up to 50 times while they are the 3700 to 3849 variants.
|
|
RoomConfig_Room* Level::pick_boss_room_config(int bossId, uint32_t seed)
|
|
{
|
|
RNG rng = {seed, 5, 15, 17};
|
|
RoomConfig_Room* room = nullptr;
|
|
int retries = BOSS_ROOM_RETRIES;
|
|
|
|
if (bossId < 0)
|
|
{
|
|
RoomQuery query = room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_BOSS, -1);
|
|
|
|
query.minVariant = (uint32_t)-bossId;
|
|
query.maxVariant = query.minVariant + BOSS_ROOM_VARIANTS - 1;
|
|
while (!room || std::ranges::any_of(DOUBLE_TROUBLE_LOCKS, [&](const DoubleTroubleLock& lock) {
|
|
return lock.is_locked(room->subtype);
|
|
}))
|
|
{
|
|
room = random_room_get(rng.Next(), query);
|
|
if (retries-- < 1 || !room) return room;
|
|
}
|
|
return room;
|
|
}
|
|
if (bossId == BOSS_MOTHER_HEART && game_flag_get(LEVEL_GAME_STATE_MAUSOLEUM_HEART_KILLED))
|
|
return fallback_room_get(rng.Next(), room_query(g_game->GetStageID(), ROOM_BOSS, BOSS_MOTHER_HEART),
|
|
STAGE_ID_MAUSOLEUM);
|
|
do room = random_room_get(rng.Next(), room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_BOSS, bossId));
|
|
while (retries > 0 && room && room->type == ROOM_BOSS &&
|
|
(retries--, room->variant >= BOSS_ROOM_REROLL_FIRST && room->variant < BOSS_ROOM_REROLL_END));
|
|
return room;
|
|
}
|
|
|
|
// Whether a door slot leads somewhere a secret room may not border for the secret room exclusions: only the near
|
|
// halves of a one cell 1x1, 1x2 or 2x1 side.
|
|
static bool is_secret_exclusion_slot(RoomShape shape, int slot)
|
|
{
|
|
switch (shape)
|
|
{
|
|
case ROOMSHAPE_1x1:
|
|
return slot < DOOR_LEFT1;
|
|
case ROOMSHAPE_1x2:
|
|
return slot != DOOR_UP1 && slot != DOOR_DOWN1;
|
|
case ROOMSHAPE_2x1:
|
|
return slot != DOOR_LEFT1 && slot != DOOR_RIGHT1;
|
|
default:
|
|
return true;
|
|
}
|
|
}
|
|
|
|
// The cells beside a placed room by its size alone, by door slot, -1 off the grid.
|
|
static std::array<int, DOOR_SLOT_COUNT> door_cells_get(RoomDescriptor& room)
|
|
{
|
|
XY position = XY::NewFromGridIdx(room.gridIndex);
|
|
XY size = {room.data->width / ROOM_SCREEN_WIDTH, room.data->height / ROOM_SCREEN_HEIGHT};
|
|
std::array<XY, DOOR_SLOT_COUNT> offsets = {
|
|
{{-1, 0}, {0, -1}, {size.x, 0}, {0, size.y}, {-1, 1}, {1, -1}, {size.x, 1}, {1, size.y}}};
|
|
std::array<int, DOOR_SLOT_COUNT> cells{};
|
|
|
|
for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++) cells[slot] = (position + offsets[slot]).ToGridIdx();
|
|
return cells;
|
|
}
|
|
|
|
// 00738d70 The cells no secret room may take: beside a boss, secret or super secret room, beside a side of a placed
|
|
// room without a door there, and on the Dark Room and Chest's chapter the cells around the start room.
|
|
std::set<int> Level::get_secret_room_excluded_cells()
|
|
{
|
|
std::set<int> cells;
|
|
|
|
if (stage == STAGE_DARK_ROOM)
|
|
for (int offset : {1, -1, LEVEL_GRID_WIDTH, -LEVEL_GRID_WIDTH})
|
|
if (startingRoomIdx + offset >= 0 && startingRoomIdx + offset < LEVEL_GRID_CELLS)
|
|
cells.insert(startingRoomIdx + offset);
|
|
for (int i = 0; i < nbRooms; i++)
|
|
{
|
|
RoomDescriptor& room = roomList[i];
|
|
|
|
if (!room.data || room.gridIndex < 0) continue;
|
|
|
|
RoomConfig_Room& data = *room.data;
|
|
std::array<int, DOOR_SLOT_COUNT> doorCells = door_cells_get(room);
|
|
bool isGuarded = data.type == ROOM_BOSS || data.type == ROOM_SUPERSECRET || data.type == ROOM_SECRET;
|
|
|
|
for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++)
|
|
if (is_secret_exclusion_slot(data.shape, slot) && (!(data.doors >> slot & 1) || isGuarded) &&
|
|
doorCells[slot] >= 0)
|
|
cells.insert(doorCells[slot]);
|
|
}
|
|
return cells;
|
|
}
|
|
|
|
// 00752460 The cells every door slot of the placed rooms leads to, but for the open doors of plain normal rooms.
|
|
std::set<int> Level::get_door_neighbor_indices()
|
|
{
|
|
return door_targets_collect(*this, [](RoomConfig_Room& data, int slot) {
|
|
return !(data.doors >> slot & 1) || data.type != ROOM_DEFAULT || data.subtype != 0;
|
|
});
|
|
}
|
|
|
|
// 0073dae0 Points a room's door slots at the cells beside it (an L shape's inner slots at its missing corner), drops
|
|
// the slots its shape lacks unless its config has the door, then opens each door on both sides where the room behind
|
|
// has a door back and closes it on both sides otherwise. A room off the map takes its config's doors.
|
|
void Level::update_room_doors(RoomDescriptor& room)
|
|
{
|
|
if (room.gridIndex < 0)
|
|
{
|
|
if (room.data) room.allowedDoors = room.data->doors;
|
|
return;
|
|
}
|
|
|
|
RoomConfig_Room& data = *room.data;
|
|
std::array<int, DOOR_SLOT_COUNT> cells = door_cells_get(room);
|
|
int* map = room.dimension < 0 ? currentRoomMap : &roomMap[room.dimension * LEVEL_GRID_CELLS];
|
|
bool isLShape = data.shape >= ROOMSHAPE_LTL && data.shape <= ROOMSHAPE_LBR;
|
|
|
|
for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++)
|
|
{
|
|
if (isLShape)
|
|
cells[slot] = LevelGenerator::get_door_target_position(XY::NewFromGridIdx(room.gridIndex), data.shape, slot,
|
|
THIN_SHAPES_IGNORED)
|
|
.ToGridIdx();
|
|
if (!LevelGenerator::has_shape_slot(data.shape, slot, THIN_SHAPES_RESTRICTED) && !(data.doors >> slot & 1))
|
|
cells[slot] = -1;
|
|
}
|
|
|
|
for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++)
|
|
{
|
|
int cell = room.doors[slot] = cells[slot];
|
|
RoomDescriptor* neighbor = cell >= 0 && map[cell] >= 0 ? &roomList[map[cell]] : nullptr;
|
|
int backSlot = (slot + 2) % DIRECTION_COUNT;
|
|
|
|
if (cell < 0) continue;
|
|
if (neighbor)
|
|
{
|
|
int offset = cell - GetRoomByIdx(cell, room.dimension)->gridIndex;
|
|
|
|
if (backSlot % 2 ? offset % LEVEL_GRID_WIDTH > 0 : offset / LEVEL_GRID_WIDTH > 0)
|
|
backSlot += DIRECTION_COUNT;
|
|
if ((data.doors >> slot & 1) && (neighbor->data->doors >> backSlot & 1))
|
|
{
|
|
room.allowedDoors |= 1u << slot;
|
|
neighbor->allowedDoors |= 1u << backSlot;
|
|
continue;
|
|
}
|
|
}
|
|
room.allowedDoors &= ~(1u << slot);
|
|
if (neighbor) neighbor->allowedDoors &= ~(1u << backSlot);
|
|
}
|
|
}
|
|
|
|
// 0074b5d0 Whether a trapdoor may lead on from the floor: not in the mirror world, not out of Mother's heart room
|
|
// before the Ascent, not on the Ascent, on the Repentance path only from its first floors (or the secret exit's room,
|
|
// or Red Redemption), and only where a next stage exists (Womb II only when the run goes past it).
|
|
bool Level::CanSpawnTrapDoor()
|
|
{
|
|
Game& game = *g_game;
|
|
int effectiveStage = (int)stage + ((GetCurses() & CURSE_OF_LABYRINTH) ? 1 : 0);
|
|
bool isRepentanceStart = IsAltPath() && (effectiveStage == 1 || effectiveStage == 3 || effectiveStage == 5 ||
|
|
effectiveStage == STAGE_WOMB_I);
|
|
|
|
if (HasMirrorDimension() && currentDimensionIdx == 1) return false;
|
|
if (!isLevelGenerating && room && room->roomType == ROOM_BOSS &&
|
|
room->descriptor->data->subtype == BOSS_MOTHER_HEART && IsPreAscent())
|
|
return false;
|
|
if (stage >= 1 && stage <= ASCENT_LAST_STAGE && game_flag_get(LEVEL_GAME_STATE_BACKWARDS_PATH)) return false;
|
|
if (game.GetChallengeParams().pathType == PATH_TYPE_REPENTANCE && !isRepentanceStart &&
|
|
currentRoomIdx != ROOM_SECRET_EXIT_IDX && game.challenge != CHALLENGE_RED_REDEMPTION)
|
|
return false;
|
|
if (is_greed()) return IsNextStageAvailable();
|
|
if (!IsNextStageAvailable()) return false;
|
|
return game.stage < STAGE_WOMB_II ||
|
|
(game.stage == STAGE_WOMB_II && IsStageWithinEnd(STAGE_SHEOL, false));
|
|
}
|
|
|
|
// 0074b710 Whether the run goes on past the floor: not from Home's stage, the pre-Ascent floor, the Dark Room, the Void
|
|
// or Home, Greed's Womb, the Repentance path's Corpse II, Home's challenge path before the Ascent, or a challenge's
|
|
// last stage. An XL floor counts as the one after it.
|
|
bool Level::IsNextStageAvailable()
|
|
{
|
|
Game& game = *g_game;
|
|
int nextStage = (int)stage;
|
|
bool isRedRedemption = game.challenge == CHALLENGE_RED_REDEMPTION;
|
|
int type = isRedRedemption ? GetRoomStageType(currentRoomIdx) : (int)stageType;
|
|
ChallengeParam& params = game.GetChallengeParams();
|
|
|
|
if ((isRedRedemption || currentDimensionIdx != DEATH_CERTIFICATE_DIMENSION) &&
|
|
RoomConfig::GetStageID(nextStage, type, ROOM_MODE_CURRENT) == STAGE_ID_BACKWARDS)
|
|
return false;
|
|
if (IsPreAscent() || nextStage >= (int)STAGE_DARK_ROOM ||
|
|
(is_greed() && nextStage == (int)STAGE_WOMB_I))
|
|
return false;
|
|
if ((curses & CURSE_OF_LABYRINTH) && nextStage % 2 == 1 && nextStage <= (int)STAGE_WOMB_I) nextStage++;
|
|
if (nextStage == STAGE_WOMB_II && IsAltPath()) return false;
|
|
if ((nextStage == STAGE_DEPTHS_II ||
|
|
(nextStage == STAGE_DEPTHS_I && filter_curses(CURSE_OF_LABYRINTH))) &&
|
|
params.pathType == PATH_TYPE_HOME && !game_flag_get(LEVEL_GAME_STATE_BACKWARDS_PATH))
|
|
return false;
|
|
return (game.challenge == 0 && game.dailyChallenge._id == 0) || nextStage < params.endStage;
|
|
}
|
|
|
|
// 0074b830 Whether a stage is within the run's end: Greed's Womb, else the challenge's end stage (the Void once
|
|
// unlocked outside challenges, else the Dark Room and Chest's chapter). The Sheol or Cathedral chapter with a
|
|
// shovel only on the path the challenge sets. A Home path challenge never is.
|
|
bool Level::IsStageWithinEnd(int levelStage, bool isAltPath)
|
|
{
|
|
Game& game = *g_game;
|
|
ChallengeParam& params = game.GetChallengeParams();
|
|
bool isChallenge = game.challenge != 0 || game.dailyChallenge._id != 0;
|
|
int endStage = params.endStage == STAGE_VOID || (!isChallenge && is_unlocked(ACHIEVEMENT_THE_VOID))
|
|
? STAGE_VOID
|
|
: STAGE_DARK_ROOM;
|
|
bool isChapter5 = levelStage == STAGE_SHEOL || levelStage == STAGE_DARK_ROOM;
|
|
auto is_shovel = [&]() {
|
|
return game.playerManager.FirstCollectibleOwner(COLLECTIBLE_BROKEN_SHOVEL_1, LAZARUS_SHARE_CHECK) ||
|
|
game.playerManager.FirstCollectibleOwner(COLLECTIBLE_MOMS_SHOVEL, LAZARUS_SHARE_CHECK);
|
|
};
|
|
|
|
if (is_greed()) return levelStage <= (int)STAGE_WOMB_I;
|
|
if (isChapter5 && isAltPath && is_shovel() && (!params.isPathTypeSet || params.pathType != PATH_TYPE_CATHEDRAL))
|
|
return false;
|
|
if (!params.isPathTypeSet) return levelStage <= endStage;
|
|
if (isChapter5 && isAltPath != (params.pathType == PATH_TYPE_CATHEDRAL)) return false;
|
|
if (params.endStage != 0) endStage = params.endStage;
|
|
return params.pathType != PATH_TYPE_HOME && levelStage <= endStage;
|
|
}
|
|
|
|
// 0074dbd0 The chance the floor has a planetarium: none past Sheol, past the Depths without Telescope Lens or past the
|
|
// Womb without a golden one or Mom's Box. Before the first planetarium it grows by a fifth per treasure room skipped
|
|
// (sure with Crystal Ball), with Magic 8 Ball, Crystal Ball, Sausage and the Lens adding to it. After, only the Lens
|
|
// does. Kept between 0.01 and 1. Lua's Game:GetPlanetariumChance.
|
|
float Level::GetPlanetariumChance()
|
|
{
|
|
Game& game = *g_game;
|
|
PlayerManager& players = game.playerManager;
|
|
int effectiveStage = (int)stage + (IsAltPath() ? 1 : 0);
|
|
Entity_Player* lensOwner = players.FirstTrinketOwner(TRINKET_TELESCOPE_LENS);
|
|
bool isLens = lensOwner && lensOwner->HasTrinket(TRINKET_TELESCOPE_LENS);
|
|
bool isGoldenLens = lensOwner && lensOwner->HasGoldenTrinket(TRINKET_TELESCOPE_LENS);
|
|
bool isMomsBox = lensOwner && lensOwner->HasCollectible(COLLECTIBLE_MOMS_BOX);
|
|
auto is_owned = [&](int collectible) {
|
|
return players.FirstCollectibleOwner(collectible, LAZARUS_SHARE_CHECK);
|
|
};
|
|
float chance = PLANETARIUM_CHANCE_MIN;
|
|
|
|
if (stage > STAGE_SHEOL || (stage > STAGE_DEPTHS_II && !isLens) ||
|
|
(stage > STAGE_WOMB_II && !isGoldenLens && !isMomsBox))
|
|
return 0;
|
|
if (game.planetariumsVisited == 0)
|
|
{
|
|
if (!game.GetChallengeParams().roomset.contains(ROOM_TREASURE) &&
|
|
game.treasureRoomsVisited < effectiveStage - 1)
|
|
{
|
|
chance = (float)(effectiveStage - game.treasureRoomsVisited - 1) * PLANETARIUM_SKIPPED_BONUS +
|
|
PLANETARIUM_CHANCE_MIN;
|
|
if (is_owned(COLLECTIBLE_CRYSTAL_BALL)) chance += 1;
|
|
}
|
|
if (is_owned(COLLECTIBLE_MAGIC_8_BALL)) chance += PLANETARIUM_ITEM_BONUS;
|
|
if (is_owned(COLLECTIBLE_CRYSTAL_BALL)) chance += PLANETARIUM_ITEM_BONUS;
|
|
if (is_owned(COLLECTIBLE_SAUSAGE)) chance += PLANETARIUM_SAUSAGE_BONUS;
|
|
if (isLens) chance += PLANETARIUM_ITEM_BONUS;
|
|
}
|
|
if (isLens)
|
|
chance += isGoldenLens == isMomsBox ? (isGoldenLens ? PLANETARIUM_LENS_BOTH : PLANETARIUM_LENS)
|
|
: PLANETARIUM_LENS_ONE;
|
|
return std::clamp(chance, PLANETARIUM_CHANCE_MIN, 1.0f);
|
|
}
|
|
|
|
// Devil's Crown's turn of an unvisited treasure room into a devil treasure room: 1 in 4 golden, 1 in 3 stronger, from
|
|
// up to ten draws of a devil room with the treasure room's doors.
|
|
static void devils_crown_room_roll(Level& level, RoomDescriptor& desc)
|
|
{
|
|
Entity_Player* owner = g_game->playerManager.FirstTrinketOwner(TRINKET_DEVILS_CROWN);
|
|
int multiplier = owner ? owner->GetTrinketMultiplier(TRINKET_DEVILS_CROWN) : 0;
|
|
RoomQuery query = room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_DEVIL, 1);
|
|
|
|
if (multiplier < 2 || owner->GetTrinketRNG(TRINKET_DEVILS_CROWN).RandomInt(multiplier == 2 ? 4 : 3) != 0) return;
|
|
query.maxVariant = DEVILS_CROWN_VARIANT_LAST;
|
|
query.requiredDoors = desc.allowedDoors;
|
|
for (int tries = DEVILS_CROWN_TRIES; tries > 0; tries--)
|
|
if (RoomConfig_Room* config = random_room_get(level.devilAngelRoomRNG.Next(), query))
|
|
{
|
|
desc.flags |= ROOM_DESCRIPTOR_FLAG_DEVIL_TREASURE;
|
|
desc.data = config;
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Whether an unvisited treasure room is redrawn as its more options kind: always with More Options or a strong crown
|
|
// (Wicked or Holy on their floor, Bloody on the Womb), 1 in 2 per Broken Glasses off the alternate path, or when a
|
|
// transition asks for it.
|
|
static bool is_treasure_reroll(Level& level, RoomDescriptor& desc)
|
|
{
|
|
Game& game = *g_game;
|
|
PlayerManager& players = game.playerManager;
|
|
bool isWomb = level.stage == STAGE_WOMB_I || level.stage == STAGE_WOMB_II;
|
|
bool isStrongCrown = desc.data->type == ROOM_TREASURE && desc.visitedCount == 0 &&
|
|
(crown_multiplier_get(level) >= 2 || (isWomb && is_trinket_strong(TRINKET_BLOODY_CROWN, 2)));
|
|
|
|
if (players.FirstCollectibleOwner(COLLECTIBLE_MORE_OPTIONS, LAZARUS_SHARE_CHECK) || isStrongCrown) return true;
|
|
if (players.AnyoneHasTrinket(TRINKET_BROKEN_GLASSES) && !level.IsAltPath())
|
|
{
|
|
RNG rng = {desc.spawnSeed, 9, 5, 25};
|
|
|
|
if ((int)rng.RandomInt(2) < players.GetTrinketMultiplier(TRINKET_BROKEN_GLASSES)) return true;
|
|
}
|
|
return game.roomTransition.mode != TRANSITION_NONE && (game.roomTransition.flags & TRANSITION_FLAG_TREASURE_REROLL);
|
|
}
|
|
|
|
// Redraws an unvisited plain or Pay to Win treasure room as its more options kind of the same shape and doors.
|
|
static void treasure_room_reroll(RoomDescriptor& desc)
|
|
{
|
|
RoomConfig_Room& data = *desc.data;
|
|
RNG rng = {desc.spawnSeed, 1, 5, 16};
|
|
RoomQuery query = room_query(g_game->GetStageID(), ROOM_TREASURE, -1);
|
|
|
|
if (data.type != ROOM_TREASURE || desc.visitedCount != 0) return;
|
|
if (data.subtype != 0 && data.subtype != TREASURE_SUBTYPE_PAY_TO_WIN) return;
|
|
query.subtype = data.subtype == 0 ? TREASURE_SUBTYPE_OPTIONS : TREASURE_SUBTYPE_OPTIONS_PAY_TO_WIN;
|
|
query.shape = data.shape;
|
|
query.requiredDoors = data.doors;
|
|
if (RoomConfig_Room* config = fallback_room_get(rng.Next(), query, STAGE_ID_SPECIAL_ROOMS)) desc.data = config;
|
|
}
|
|
|
|
// The config a room taken over by Greed plays: its saved one, else a Greed miniboss room of its shape and doors (Super
|
|
// Greed once Greed was met, and in a devil room Ultra Greed's), which marks that Greed met. Without one the takeover is
|
|
// dropped.
|
|
static RoomConfig_Room* greed_takeover_config_get(RoomDescriptor& desc)
|
|
{
|
|
RoomConfig_Room* config = desc.overrideData;
|
|
RNG rng = {desc.spawnSeed, 1, 5, 16};
|
|
int subtype = GREED_SUBTYPE_DEVIL;
|
|
|
|
if (config && config->stageId == STAGE_ID_SPECIAL_ROOMS && config->type == ROOM_MINIBOSS) return config;
|
|
if (desc.data->type != ROOM_DEVIL)
|
|
{
|
|
if (!desc.greedSubType)
|
|
desc.greedSubType = game_flag_get(STATE_GREED_SPAWNED) ? GREED_SUBTYPE_SUPER : GREED_SUBTYPE;
|
|
subtype = desc.greedSubType;
|
|
if (subtype == GREED_SUBTYPE) game_flag_set(STATE_GREED_SPAWNED, true);
|
|
else if (subtype == GREED_SUBTYPE_SUPER) game_flag_set(STATE_SUPER_GREED_SPAWNED, true);
|
|
}
|
|
|
|
RoomQuery query = room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_MINIBOSS, subtype);
|
|
|
|
query.maxDifficulty = DIFFICULTY_EASY;
|
|
query.mode = ROOM_MODE_NORMAL;
|
|
query.shape = desc.data->shape;
|
|
query.requiredDoors = desc.data->doors;
|
|
config = random_room_get(rng.Next(), query);
|
|
if (!config)
|
|
{
|
|
config = desc.data;
|
|
desc.flags &= ~ROOM_DESCRIPTOR_FLAG_SURPRISE_MINIBOSS;
|
|
}
|
|
return desc.overrideData = config;
|
|
}
|
|
|
|
// Opens a door of a room off the map toward where the players came from: the door they entered through when the room
|
|
// has it, else the first door it has from a random slot. The error room, crawl space, Mega Satan's, Genesis's and the
|
|
// Member Card's shop keep their doors, and the black market opens only from the crawl space.
|
|
static void off_map_room_door_open(Level& level, RoomDescriptor& desc)
|
|
{
|
|
int type = desc.data->type;
|
|
int lastType = level.GetLastRoomDesc()->data->type;
|
|
int idx = level.currentRoomIdx;
|
|
|
|
desc.allowedDoors = 0;
|
|
if (type == ROOM_ERROR || type == ROOM_DUNGEON || idx == ROOM_MEGA_SATAN_IDX || idx == ROOM_GENESIS_IDX ||
|
|
idx == ROOM_SECRET_SHOP_IDX || (type == ROOM_BLACK_MARKET && lastType != ROOM_DUNGEON))
|
|
return;
|
|
if (level.enterDoor < 0 || !(desc.data->doors >> level.enterDoor & 1))
|
|
{
|
|
uint32_t start = Random() % DOOR_SLOT_COUNT;
|
|
|
|
level.enterDoor = DOOR_NONE;
|
|
for (int i = 0; i < DOOR_SLOT_COUNT && level.enterDoor < 0; i++)
|
|
if (desc.data->doors >> ((start + i) % DOOR_SLOT_COUNT) & 1)
|
|
level.enterDoor = (int)((start + i) % DOOR_SLOT_COUNT);
|
|
}
|
|
// The original threw out_of_range here without a door. The room is entered without one instead.
|
|
if (level.enterDoor < 0)
|
|
log_printf(LOG_ASSERT, "Level::load_room: could not choose a door from where to enter off grid room\n");
|
|
else desc.allowedDoors |= 1u << level.enterDoor;
|
|
}
|
|
|
|
// Opens a red room door from an ultra secret room without doors, through the first slot whose neighbour has a room
|
|
// beside it that is not a curse room and joins no group.
|
|
static void ultra_secret_door_open(Level& level)
|
|
{
|
|
Room& room = *level.room;
|
|
int safeIdx = room.descriptor->safeGridIndex;
|
|
|
|
if (std::ranges::any_of(room.doors, [](GridEntity_Door* door) { return door; }) || safeIdx < 0) return;
|
|
for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++)
|
|
{
|
|
int neighbor = level.GetNeighborRoomIdx(safeIdx, slot);
|
|
|
|
if (neighbor < 0) continue;
|
|
for (XY direction : CARDINAL_OFFSETS)
|
|
{
|
|
int cell = (XY::NewFromGridIdx(neighbor) + direction).ToGridIdx();
|
|
RoomDescriptor* other = cell >= 0 && cell != safeIdx ? level.GetRoomByIdx(cell) : nullptr;
|
|
|
|
if (!other || !other->data || other->group != -1 || other->data->type == ROOM_CURSE) continue;
|
|
if (!level.MakeRedRoomDoor(safeIdx, slot)) break;
|
|
if (room.doors[slot])
|
|
reconstruction_missing("Level::load_room 0073e0a0: opening the ultra secret room's red door "
|
|
"(GridEntity_Door::TryBlowOpen 0070fb60, its open animation)");
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Points the room's doors at the rooms behind them: a room off the map's entry door back at the room left, the others'
|
|
// at their descriptor's neighbours (-2 for a red room door not opened yet).
|
|
static void doors_target(Level& level, RoomDescriptor& desc)
|
|
{
|
|
std::array<GridEntity_Door*, DOOR_SLOT_COUNT>& doors = level.room->doors;
|
|
int type = desc.data->type;
|
|
|
|
if (std::ranges::find(OFF_MAP_ENTRY_ROOMS, level.currentRoomIdx) != OFF_MAP_ENTRY_ROOMS.end())
|
|
{
|
|
if (level.enterDoor < 0 || !doors[level.enterDoor]) return;
|
|
|
|
GridEntity_Door& door = *doors[level.enterDoor];
|
|
|
|
door.slot = level.enterDoor;
|
|
door.SetRoomTypes(type, ROOM_DEFAULT);
|
|
door.targetRoomIdx = level.lastRoomIdx;
|
|
return;
|
|
}
|
|
for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++)
|
|
{
|
|
GridEntity_Door* door = doors[slot];
|
|
int target = desc.doors[slot];
|
|
bool isRedDoor = target == RED_ROOM_DOOR_TARGET;
|
|
|
|
if (!door || (!isRedDoor && (target < 0 || level.currentRoomMap[target] < 0))) continue;
|
|
door->slot = slot;
|
|
door->targetRoomIdx = target;
|
|
door->SetRoomTypes(type, isRedDoor ? ROOM_DEFAULT : level.GetRoomByIdx(target)->data->type);
|
|
}
|
|
}
|
|
|
|
// The blood splats at a Corpse room's doors into normal, treasure, miniboss and boss rooms that use the alternate
|
|
// backdrop: nine along the way out of each, scattered and scaled from the room behind's decoration seed, grayed.
|
|
static void corpse_door_splats_spawn(Level& level)
|
|
{
|
|
Room& room = *level.room;
|
|
float rotationCos = std::cos(QUARTER_TURN);
|
|
float rotationSin = std::sin(QUARTER_TURN);
|
|
|
|
for (GridEntity_Door* door : room.doors)
|
|
{
|
|
if (!door || std::ranges::find(CORPSE_SPLAT_ROOM_TYPES, door->targetRoomType) == CORPSE_SPLAT_ROOM_TYPES.end())
|
|
continue;
|
|
|
|
RoomDescriptor& target = *level.GetRoomByIdx(door->targetRoomIdx);
|
|
|
|
if (!(target.flags & ROOM_DESCRIPTOR_FLAG_USE_ALTERNATE_BACKDROP)) continue;
|
|
|
|
RNG rng = {target.decorationSeed, 2, 15, 17};
|
|
Vector direction = direction_unit(door->direction);
|
|
int gridIndex = (int)door->gridIndex;
|
|
|
|
Vector out = {-direction.x, -direction.y};
|
|
Vector across = {out.x * rotationCos - out.y * rotationSin, out.x * rotationSin + out.y * rotationCos};
|
|
float baseX = out.x * SPLAT_DOOR_OFFSET + (float)(gridIndex % room.gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_X;
|
|
float baseY = out.y * SPLAT_DOOR_OFFSET + (float)(gridIndex / room.gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_Y;
|
|
|
|
for (int i = 0; i < SPLAT_COUNT; i++)
|
|
{
|
|
float along = (float)i * SPLAT_STEP;
|
|
uint32_t seed = Random();
|
|
float rowY = baseY + out.y * along * SPLAT_LENGTH;
|
|
float rowX = baseX + along * SPLAT_LENGTH * out.x;
|
|
float spread = (rng.RandomFloat() - 0.5f) * along * SPLAT_SPREAD;
|
|
EntitySpawn spawn = {.position = {across.x * spread + rowX, rowY + spread * across.y},
|
|
.type = ENTITY_EFFECT,
|
|
.variant = EFFECT_VARIANT_BLOOD_SPLAT,
|
|
.seed = seed};
|
|
Entity& splat = *g_game->Spawn(spawn);
|
|
float scale = rng.RandomFloat() * (1 - along) * SPLAT_SCALE_RANGE + SPLAT_SCALE_MIN;
|
|
|
|
splat.sprite.scale = vector_make(scale, scale);
|
|
splat.sprite.color = SPLAT_COLOR;
|
|
splat.Update();
|
|
}
|
|
}
|
|
}
|
|
|
|
// 0073e0a0 Builds the room the players are in from its descriptor: Devil's Crown's devil treasure rooms, the treasure
|
|
// room rerolls, Greed's takeover config and a door into rooms off the map first, then the room itself, its doors and
|
|
// the special doors a cleared room spawns, the mineshaft entrance's bridged pits, Genesis's reset, and the players'
|
|
// entry, with the entities spawned this frame updated once.
|
|
void Level::load_room()
|
|
{
|
|
Game& game = *g_game;
|
|
RoomDescriptor& desc = *GetRoomByIdx(currentRoomIdx);
|
|
bool isGreed = is_greed();
|
|
|
|
if (game.playerManager.AnyoneHasTrinket(TRINKET_RIB_OF_GREED) && desc.data->type != ROOM_DEVIL)
|
|
desc.flags &= ~ROOM_DESCRIPTOR_FLAG_SURPRISE_MINIBOSS;
|
|
if (game.roomTransition.mode != TRANSITION_NONE && (game.roomTransition.flags & TRANSITION_FLAG_NO_TAKEOVER) &&
|
|
desc.data->type == ROOM_SHOP)
|
|
desc.flags &= ~ROOM_DESCRIPTOR_FLAG_SURPRISE_MINIBOSS;
|
|
if (desc.visitedCount == 0 && (desc.flags & ROOM_DESCRIPTOR_FLAG_DEVIL_TREASURE))
|
|
devils_crown_room_roll(*this, desc);
|
|
if (is_treasure_reroll(*this, desc)) treasure_room_reroll(desc);
|
|
|
|
RoomConfig_Room* config =
|
|
desc.flags & ROOM_DESCRIPTOR_FLAG_SURPRISE_MINIBOSS ? greed_takeover_config_get(desc) : desc.data;
|
|
|
|
if (desc.listIndex >= ROOM_MAP_CELLS && desc.gridIndex != ROOM_BLUE_ROOM_IDX) off_map_room_door_open(*this, desc);
|
|
room->Init(*config, desc);
|
|
if (room->roomType == ROOM_ULTRASECRET) ultra_secret_door_open(*this);
|
|
|
|
bool isMineshaftFloor =
|
|
stage == STAGE_CAVES_II || (stage == STAGE_CAVES_I && (GetCurses() & CURSE_OF_LABYRINTH));
|
|
bool isMineshaftEntrance = desc.data->type == ROOM_DEFAULT && desc.data->subtype == MINESHAFT_ENTRANCE_SUBTYPE &&
|
|
(desc.flags & ROOM_DESCRIPTOR_FLAG_SACRIFICE_DONE) && !desc.data->spawns.empty();
|
|
|
|
if (!isGreed && !IsAscent() && IsAltPath() && isMineshaftFloor && isMineshaftEntrance)
|
|
reconstruction_missing("Level::load_room 0073e0a0: the mineshaft entrance's bridged pits (Room+0x746d)");
|
|
doors_target(*this, desc);
|
|
if (GetRoomByIdx(currentRoomIdx)->flags & ROOM_DESCRIPTOR_FLAG_CLEAR)
|
|
{
|
|
if (!isGreed)
|
|
{
|
|
room->TrySpawnSecretExit(false, false);
|
|
room->TrySpawnDevilRoomDoor(false, false);
|
|
room->TrySpawnBossRushDoor(false, false);
|
|
room->TrySpawnTheVoidDoor(false);
|
|
}
|
|
room->TrySpawnBlueWombDoor(false, false, false);
|
|
}
|
|
for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++)
|
|
{
|
|
RoomShape shape = room->descriptor && room->descriptor->data ? room->descriptor->data->shape : ROOMSHAPE_1x1;
|
|
int gridIndex = room_shape_get_door_grid_index(slot, room->gridWidth, room->gridHeight, shape);
|
|
GridEntity* entity = gridIndex >= 0 && gridIndex < ROOM_GRID_CELLS ? room->gridEntities[gridIndex] : nullptr;
|
|
|
|
if (room->doors[slot] || !entity || entity->type != GRID_DOOR) continue;
|
|
if (static_cast<GridEntity_Door*>(entity)->direction != DIRECTION_NONE) continue;
|
|
room->doors[slot] = static_cast<GridEntity_Door*>(entity);
|
|
room->RemoveDoor(slot);
|
|
}
|
|
room->TrySpawnSecretShop(false);
|
|
|
|
int roomStageType = game.challenge == CHALLENGE_RED_REDEMPTION ? GetRoomStageType(currentRoomIdx) : (int)stageType;
|
|
bool isCorpse = RoomConfig::GetStageID((int)stage, roomStageType, ROOM_MODE_CURRENT) == STAGE_ID_CORPSE;
|
|
|
|
if ((game.challenge == CHALLENGE_RED_REDEMPTION || currentDimensionIdx != DEATH_CERTIFICATE_DIMENSION) &&
|
|
isCorpse && room->backdropType != BACKDROP_CORPSE3)
|
|
corpse_door_splats_spawn(*this);
|
|
if (currentRoomIdx == ROOM_GENESIS_IDX && room->descriptor->visitedCount == 1)
|
|
reconstruction_missing("Level::load_room 0073e0a0: Genesis's reset of the players (FUN_007dad80, "
|
|
"Game::reset_players_for_greed)");
|
|
if (!game.deathmatchManager.is_active()) game.playerManager.enter_level();
|
|
room->fxLayers.Update(PLAYER_FOLLOW_SNAP);
|
|
room->UpdateRedKey();
|
|
|
|
bool isHomePathBoss =
|
|
game.GetChallengeParams().pathType == PATH_TYPE_HOME &&
|
|
(stage == STAGE_DEPTHS_II || (stage == STAGE_DEPTHS_I && (GetCurses() & CURSE_OF_LABYRINTH)));
|
|
|
|
if (isHomePathBoss && GetRoomByIdx(currentRoomIdx)->listIndex == lastBossRoomListIdx &&
|
|
(room->descriptor->flags & ROOM_DESCRIPTOR_FLAG_CLEAR))
|
|
reconstruction_missing("Level::load_room 0073e0a0: the Home path's Boss Rush door (Room::update_door_targets "
|
|
"00802670, TrySpawnBossRushDoor 007f9960)");
|
|
|
|
EntityList_EL& updated = room->entityList.updateEL;
|
|
|
|
for (size_t i = 0; i < updated.size(); i++)
|
|
{
|
|
Entity& entity = *updated[i];
|
|
bool isUpdated = (game.deathmatchManager.is_active() && entity.type == ENTITY_PLAYER) ||
|
|
(entity.type >= ENTITY_FIRST_ENEMY && entity.type < ENTITY_EFFECT);
|
|
|
|
if (isUpdated && game.frameCount == entity.spawnFrame) entity.Update();
|
|
}
|
|
lua_engine_get().PostNewRoom();
|
|
if (!game.deathmatchManager.is_active()) return;
|
|
game.deathmatchManager.type->Init();
|
|
game.dizzyTargetIntensity = 0;
|
|
game.dizzyIntensity = 0;
|
|
}
|
|
|
|
// 0073f940 Shows the room the players are in on the minimap (with its mirror world twin) and the rooms behind its
|
|
// doors, then redraws both maps and has the HUD refresh the players' part.
|
|
void Level::UpdateVisibility()
|
|
{
|
|
RoomDescriptor& current = *GetRoomByIdx(currentRoomIdx);
|
|
HUD& hud = g_game->hud;
|
|
|
|
current.displayFlags |= ROOM_DISPLAY_BOX | ROOM_DISPLAY_ICON;
|
|
if (currentRoomIdx >= 0 && HasMirrorDimension())
|
|
GetRoomByIdx(currentRoomIdx, 1 - currentDimensionIdx)->displayFlags |= ROOM_DISPLAY_BOX | ROOM_DISPLAY_ICON;
|
|
for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++)
|
|
if (GridEntity_Door* door = room->doors[slot]; door && door->targetRoomIdx >= 0)
|
|
reveal_room_visibility(*GetRoomByIdx(door->targetRoomIdx), ¤t, slot);
|
|
for (MinimapConfig& config : g_game->minimap.configs) config.refresh();
|
|
if (hud.hudRefreshType == HUD_REFRESH_FULL) return;
|
|
hud.hudRefreshType = HUD_REFRESH_PLAYER;
|
|
hud.hudRefreshCountdown = HUD_REFRESH_FRAMES;
|
|
}
|
|
|
|
// Adds display flags to a room and its mirror world twin.
|
|
static void room_display_add(Level& level, RoomDescriptor& room, uint32_t displayFlags)
|
|
{
|
|
room.displayFlags |= displayFlags;
|
|
if (room.safeGridIndex >= 0 && level.HasMirrorDimension())
|
|
level.GetRoomByIdx(room.safeGridIndex, 1 - level.currentDimensionIdx)->displayFlags |= displayFlags;
|
|
}
|
|
|
|
// 0073f620 Shows a room beside fromRoom on the minimap. A secret room, or any room seen from one, only shows through a
|
|
// busted door, X-Ray Vision, Spelunker Hat or the floor seen whole (X-Ray Vision opening a hidden door from the room
|
|
// the players are in). Without Spelunker Hat a miniboss room, bedroom or secret room shows as a locked box, any other
|
|
// room with its icon. Spelunker Hat goes on to the rooms beside it, and a red room always shows its icon.
|
|
void Level::reveal_room_visibility(RoomDescriptor& target, RoomDescriptor* fromRoom, int doorSlot)
|
|
{
|
|
PlayerManager& players = g_game->playerManager;
|
|
RoomDescriptor* current = room->descriptor;
|
|
auto is_secret = [](RoomDescriptor& desc) {
|
|
return desc.data->type == ROOM_SECRET || desc.data->type == ROOM_SUPERSECRET;
|
|
};
|
|
bool isSecret = is_secret(target) || (fromRoom && is_secret(*fromRoom));
|
|
auto is_xray = [&]() {
|
|
return players.FirstCollectibleOwner(COLLECTIBLE_XRAY_VISION, LAZARUS_SHARE_CHECK) || isCanSeeEverything;
|
|
};
|
|
auto is_spelunker = [&]() {
|
|
return players.FirstCollectibleOwner(COLLECTIBLE_SPELUNKER_HAT, LAZARUS_SHARE_CHECK);
|
|
};
|
|
bool isShown = !isSecret;
|
|
|
|
if (isSecret && fromRoom == current && doorSlot != -1)
|
|
{
|
|
GridEntity_Door& door = *room->doors[doorSlot];
|
|
|
|
if (is_xray() && door.variant == DOOR_HIDDEN)
|
|
reconstruction_missing("Level::reveal_room_visibility 0073f620: X-Ray Vision's hidden door opening "
|
|
"(Game::SpawnEx 006fe410)");
|
|
isShown = door.isBusted;
|
|
}
|
|
if (!isShown) isShown = is_xray() || is_spelunker();
|
|
if (isShown)
|
|
{
|
|
int type = target.data->type;
|
|
bool isLocked = type == ROOM_MINIBOSS || type == ROOM_ISAACS || type == ROOM_BARREN || isSecret;
|
|
|
|
room_display_add(*this, target,
|
|
!is_spelunker() && isLocked ? ROOM_DISPLAY_BOX | ROOM_DISPLAY_LOCK
|
|
: ROOM_DISPLAY_BOX | ROOM_DISPLAY_ICON);
|
|
if (is_spelunker() && fromRoom == current && fromRoom != &target)
|
|
for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++)
|
|
{
|
|
int neighbor = GetNeighborRoomIdx(target.safeGridIndex, slot);
|
|
|
|
if (neighbor >= 0 && GetRoomByIdx(neighbor)->data)
|
|
reveal_room_visibility(*GetRoomByIdx(neighbor), &target, slot);
|
|
}
|
|
}
|
|
if (target.flags & ROOM_DESCRIPTOR_FLAG_RED_ROOM) target.displayFlags |= ROOM_DISPLAY_BOX | ROOM_DISPLAY_ICON;
|
|
}
|
|
|
|
// 00742ef0 Lays out an Ascent floor.
|
|
void Level::generate_backwards()
|
|
{
|
|
reconstruction_missing("Level::generate_backwards 00742ef0");
|
|
}
|
|
|
|
// (00743550, 0074378b, 00743fc3) Lays out a Greed floor.
|
|
void Level::generate_greed()
|
|
{
|
|
reconstruction_missing("Level::generate_greed 00743550");
|
|
}
|
|
|
|
// 0074a500 Lays out the Blue Womb.
|
|
void Level::generate_home()
|
|
{
|
|
reconstruction_missing("Level::generate_home 0074a500");
|
|
}
|
|
|
|
// 0074de30 Lays out Home.
|
|
void Level::generate_home_level()
|
|
{
|
|
reconstruction_missing("Level::generate_home_level 0074de30");
|
|
}
|
|
|
|
// 007508c0 Lays out a Red Redemption floor.
|
|
void Level::generate_random_layout()
|
|
{
|
|
reconstruction_missing("Level::generate_random_layout 007508c0");
|
|
}
|
|
|
|
// 0074f0c0 Lays out the mirror world.
|
|
void Level::generate_mirror_world()
|
|
{
|
|
reconstruction_missing("Level::generate_mirror_world 0074f0c0");
|
|
}
|
|
|
|
// 0074f360 Lays out the abandoned mineshaft.
|
|
void Level::generate_mineshaft()
|
|
{
|
|
reconstruction_missing("Level::generate_mineshaft 0074f360");
|
|
}
|
|
|
|
// 00751650 Lays out the Death Certificate area.
|
|
void Level::generate_dark_closet()
|
|
{
|
|
reconstruction_missing("Level::generate_dark_closet 00751650");
|
|
}
|
|
|
|
// 007515c0 Enters the Death Certificate area.
|
|
void Level::enter_dark_closet()
|
|
{
|
|
reconstruction_missing("Level::enter_dark_closet 007515c0");
|
|
}
|
|
|
|
// 0074f820 Seeds Red Redemption's stage type noise.
|
|
void Level::InitStageSeeds()
|
|
{
|
|
reconstruction_missing("Level::InitStageSeeds 0074f820");
|
|
}
|
|
|
|
// 0074fbe0 Places one room of a Red Redemption floor.
|
|
bool Level::try_place_random_room(LevelGenerator&)
|
|
{
|
|
reconstruction_missing("Level::try_place_random_room 0074fbe0");
|
|
}
|
|
|
|
// 007523e0 Adjusts the stage a boss count is read for.
|
|
bool Level::boss_count_adjust(int&, int&)
|
|
{
|
|
reconstruction_missing("Level::boss_count_adjust 007523e0");
|
|
}
|
|
|
|
// 0073fa20 Enters a room config directly, for debugging.
|
|
void Level::DEBUG_goto_room(RoomConfig_Room* roomConfig)
|
|
{
|
|
RoomDescriptor& debug = *GetRoomByIdx(ROOM_DEBUG_IDX);
|
|
|
|
for (GridEntityDesc& grid : debug.savedGridEntities) grid._type = 0;
|
|
debug.flags &= ~ROOM_DESCRIPTOR_FLAG_CLEAR;
|
|
debug.visitedCount = 0;
|
|
debug.savedEntities.clear();
|
|
debug.restrictedGridIndexes.clear();
|
|
debug.savedEffects.clear();
|
|
debug.allowedDoors = roomConfig->doors;
|
|
debug.data = roomConfig;
|
|
debug.spawnSeed = Random();
|
|
debug.decorationSeed = Random();
|
|
debug.awardSeed = Random();
|
|
debug.bossDeathSeed = Random();
|
|
debug.shopItemDiscountIdx = -1;
|
|
debug.shopItemIdx = -1;
|
|
g_game->StartRoomTransition({.animation = TRANSITION_WALK, .roomIndex = ROOM_DEBUG_IDX});
|
|
}
|
|
|
|
// The floor's state flags the map effects keep, by bit, so they apply again.
|
|
enum MapEffectFlag : int
|
|
{
|
|
MAP_EFFECT_COMPASS = 7,
|
|
MAP_EFFECT_MAP = 8,
|
|
MAP_EFFECT_BLUE_MAP = 9,
|
|
MAP_EFFECT_FULL_MAP = 10,
|
|
MAP_EFFECT_BOSS_ROOM = 18,
|
|
MAP_EFFECT_SECRET_ROOM = 20
|
|
};
|
|
|
|
// Marks the floor's rooms whose type a map effect shows with display flags, redraws the map and keeps the effect in a
|
|
// floor state flag (none for -1).
|
|
// The original reads the config of a room without one after logging it. Here that room is skipped.
|
|
template <class Shows>
|
|
static void map_effect_apply(Level& level, uint32_t display, Shows isShown, int stateFlag)
|
|
{
|
|
for (int i = 0; i < level.nbRooms; i++)
|
|
{
|
|
RoomDescriptor& room = level.roomList[i];
|
|
if (!room.data) log_printf(LOG_ERROR, "[error] Room %d is not initialized\n", i);
|
|
else if (isShown(room.data->type)) room.displayFlags |= display;
|
|
}
|
|
g_game->minimap.Refresh();
|
|
if (stateFlag >= 0) level.levelStateFlags |= 1u << stateFlag;
|
|
}
|
|
|
|
// Whether a room type is one of the secret rooms.
|
|
static bool is_secret_type(int type)
|
|
{
|
|
return type == ROOM_SECRET || type == ROOM_SUPERSECRET || type == ROOM_ULTRASECRET;
|
|
}
|
|
|
|
// 00748860 The map: every room but the secret ones shows its outline.
|
|
void Level::ApplyMapEffect()
|
|
{
|
|
map_effect_apply(*this, ROOM_DISPLAY_BOX, [](int type) { return !is_secret_type(type); }, MAP_EFFECT_MAP);
|
|
}
|
|
|
|
// 007488d0 The Blue Map: the secret and super secret rooms show their icons.
|
|
void Level::ApplyBlueMapEffect()
|
|
{
|
|
auto isShown = [](int type) { return type == ROOM_SECRET || type == ROOM_SUPERSECRET; };
|
|
map_effect_apply(*this, ROOM_DISPLAY_ICON, isShown, MAP_EFFECT_BLUE_MAP);
|
|
}
|
|
|
|
// 00748940 The Compass: the special rooms (not the normal or secret ones) show their icons, kept for the floor when
|
|
// persistent.
|
|
void Level::ApplyCompassEffect(bool isPersistent)
|
|
{
|
|
auto isShown = [](int type) { return type != ROOM_DEFAULT && !is_secret_type(type); };
|
|
map_effect_apply(*this, ROOM_DISPLAY_ICON, isShown, isPersistent ? MAP_EFFECT_COMPASS : -1);
|
|
}
|
|
|
|
// 007489c0 The whole map: every room but the super and ultra secret ones shows its outline and icon.
|
|
void Level::ShowMap()
|
|
{
|
|
auto isShown = [](int type) { return type != ROOM_SUPERSECRET && type != ROOM_ULTRASECRET; };
|
|
map_effect_apply(*this, ROOM_DISPLAY_BOX | ROOM_DISPLAY_ICON, isShown, MAP_EFFECT_FULL_MAP);
|
|
}
|
|
|
|
// 00748a70 Luna's reveal: the first secret room shows its icon.
|
|
void Level::reveal_secret_room()
|
|
{
|
|
bool isRevealed = false;
|
|
auto isShown = [&](int type) { return type == ROOM_SECRET && !std::exchange(isRevealed, true); };
|
|
map_effect_apply(*this, ROOM_DISPLAY_ICON, isShown, MAP_EFFECT_SECRET_ROOM);
|
|
}
|
|
|
|
// 00748ae0 Hides the rooms only a temporary compass showed, then applies again the map effects the floor keeps: the
|
|
// map, the Blue Map, the Compass, the whole map, the boss room's icon and the secret room's.
|
|
void Level::RemoveCompassEffect()
|
|
{
|
|
for (int i = 0; i < nbRooms; i++)
|
|
if (roomList[i].displayFlags == ROOM_DISPLAY_ICON) roomList[i].displayFlags = 0;
|
|
|
|
if (levelStateFlags & 1u << MAP_EFFECT_MAP) ApplyMapEffect();
|
|
if (levelStateFlags & 1u << MAP_EFFECT_BLUE_MAP) ApplyBlueMapEffect();
|
|
if (levelStateFlags & 1u << MAP_EFFECT_COMPASS) ApplyCompassEffect(true);
|
|
if (levelStateFlags & 1u << MAP_EFFECT_FULL_MAP) ShowMap();
|
|
if (levelStateFlags & 1u << MAP_EFFECT_BOSS_ROOM)
|
|
{
|
|
if (lastBossRoomListIdx >= 0) roomList[lastBossRoomListIdx].displayFlags |= ROOM_DISPLAY_ICON;
|
|
g_game->minimap.Refresh();
|
|
}
|
|
if (levelStateFlags & 1u << MAP_EFFECT_SECRET_ROOM) reveal_secret_room();
|
|
g_game->minimap.Refresh();
|
|
}
|
|
|
|
// 00740860 A random room by a seed among those of the current dimension and group but the players' own. The error
|
|
// room's teleport may also land in the error room (while a next floor exists) or, one seed in 50, the Black Market.
|
|
// With no room to pick the original reads past an empty list, so the players stay where they are.
|
|
int Level::GetRandomRoomIndex(bool isErrorRoom, uint32_t seed)
|
|
{
|
|
RoomDescriptor& current = *room->descriptor;
|
|
std::vector<int> candidates;
|
|
RNG rng{};
|
|
|
|
rng.SetSeed(seed, RANDOM_ROOM_SHIFT_INDEX);
|
|
if (isErrorRoom && IsNextStageAvailable())
|
|
{
|
|
candidates.push_back(ROOM_ERROR_IDX);
|
|
if (rng.Next() % BLACK_MARKET_TELEPORT_ODDS == 0) candidates.push_back(ROOM_BLACK_MARKET_IDX);
|
|
}
|
|
|
|
for (int cell = 0; cell < LEVEL_GRID_CELLS; cell++)
|
|
{
|
|
int listIndex = currentRoomMap[cell];
|
|
|
|
if (listIndex < 0 || listIndex == current.listIndex) continue;
|
|
RoomDescriptor& desc = roomList[listIndex];
|
|
if (desc.dimension == currentDimensionIdx && (desc.group == -1 || desc.group == current.group))
|
|
candidates.push_back(cell);
|
|
}
|
|
if (candidates.empty()) return currentRoomIdx;
|
|
return candidates[rng.Next() % candidates.size()];
|
|
}
|
|
|
|
// 00740a60 A room not cleared yet.
|
|
int Level::GetNonCompleteRoomIndex()
|
|
{
|
|
reconstruction_missing("Level::GetNonCompleteRoomIndex 00740a60");
|
|
}
|
|
|
|
// 007484c0 A room of a type.
|
|
int Level::QueryRoomTypeIndex(int, bool, RNG&, bool)
|
|
{
|
|
reconstruction_missing("Level::QueryRoomTypeIndex 007484c0");
|
|
}
|
|
|
|
// 0074a090 Where the players enter the current room when no door brings them: a crawlspace's ladder (by the
|
|
// Black Market's or a room's), the secret shop's and the off-map rooms' spots, or back where a crawlspace was entered.
|
|
// Elsewhere none, the origin.
|
|
Vector Level::GetEnterPosition()
|
|
{
|
|
if (currentRoomIdx == ROOM_DUNGEON_IDX || currentRoomIdx == ROOM_GIDEON_DUNGEON_IDX)
|
|
{
|
|
if (lastRoomIdx >= 0) return vector_make(DUNGEON_ENTRY_X, DUNGEON_ENTRY_Y);
|
|
return vector_make(lastRoomIdx == ROOM_BLACK_MARKET_IDX ? BLACK_MARKET_EXIT_X : DUNGEON_EXIT_X, DUNGEON_EXIT_Y);
|
|
}
|
|
if (currentRoomIdx == ROOM_SECRET_SHOP_IDX) return vector_make(SECRET_SHOP_ENTRY_X, SECRET_SHOP_ENTRY_Y);
|
|
if (currentRoomIdx == ROOM_OFF_MAP_14_IDX) return vector_make(OFF_MAP_14_ENTRY_X, OFF_MAP_14_ENTRY_Y);
|
|
if (currentRoomIdx == ROOM_OFF_MAP_15_IDX) return vector_make(OFF_MAP_15_ENTRY_X, OFF_MAP_15_ENTRY_Y);
|
|
if (currentRoomIdx >= 0 && currentRoomIdx == dungeonReturnRoomIndex)
|
|
{
|
|
RoomDescriptor* last = GetRoomByIdx(lastRoomIdx);
|
|
bool isFromDungeon = last->data && last->data->type == ROOM_DUNGEON;
|
|
if (isFromDungeon || lastRoomIdx == ROOM_SECRET_SHOP_IDX || lastRoomIdx == ROOM_ANGEL_SHOP_IDX)
|
|
return dungeonReturnPosition;
|
|
}
|
|
return g_vectorZero;
|
|
}
|
|
|
|
// 0074c160 The cell a door leads to.
|
|
XY Level::get_door_neighbor_pos(XY, RoomShape, int)
|
|
{
|
|
reconstruction_missing("Level::get_door_neighbor_pos 0074c160");
|
|
}
|
|
|
|
// 0074c540 The room a door leads to.
|
|
int Level::GetNeighborRoomIdx(int, int)
|
|
{
|
|
reconstruction_missing("Level::GetNeighborRoomIdx 0074c540");
|
|
}
|
|
|
|
// 0074c9e0 The slots a red room would open toward.
|
|
uint32_t Level::get_red_room_neighbor_slots(int, int, int*)
|
|
{
|
|
reconstruction_missing("Level::get_red_room_neighbor_slots 0074c9e0");
|
|
}
|
|
|
|
// 0074cb50 The layout room a red room door would make.
|
|
LevelGenerator_Room Level::get_door_neighbor_room(int, int)
|
|
{
|
|
reconstruction_missing("Level::get_door_neighbor_room 0074cb50");
|
|
}
|
|
|
|
// 0074cd70 Whether a Red Key outline shows on a door.
|
|
bool Level::CanSpawnDoorOutline(int, int)
|
|
{
|
|
reconstruction_missing("Level::CanSpawnDoorOutline 0074cd70");
|
|
}
|
|
|
|
// 0074cea0 A red room's type.
|
|
int Level::roll_red_room_type()
|
|
{
|
|
reconstruction_missing("Level::roll_red_room_type 0074cea0");
|
|
}
|
|
|
|
// 0074d010 Opens a red room through a door.
|
|
bool Level::MakeRedRoomDoor(int, int)
|
|
{
|
|
reconstruction_missing("Level::MakeRedRoomDoor 0074d010");
|
|
}
|
|
|
|
// 0074d780 Adds a second boss room.
|
|
bool Level::TryInitializeExtraBossRoom(uint32_t)
|
|
{
|
|
reconstruction_missing("Level::TryInitializeExtraBossRoom 0074d780");
|
|
}
|
|
|
|
// 0074d920 Refreshes the treasure rooms' doors for a trinket.
|
|
void Level::update_treasure_room_doors_for_trinket()
|
|
{
|
|
reconstruction_missing("Level::update_treasure_room_doors_for_trinket 0074d920");
|
|
}
|
|
|
|
// 0074beb0 Sets up Rotgut's room.
|
|
void Level::init_rotgut_dungeon_room()
|
|
{
|
|
reconstruction_missing("Level::init_rotgut_dungeon_room 0074beb0");
|
|
}
|
|
|
|
// 008e11b0 Sets up Genesis's room.
|
|
void Level::InitializeGenesisRoom()
|
|
{
|
|
reconstruction_missing("Level::InitializeGenesisRoom 008e11b0");
|
|
}
|
|
|
|
// 00748760 Whether a challenge room's door opens: once its challenge is done, for a boss challenge while every player
|
|
// has a heart or less (or no player is left), for a normal one at full health, and always through a red room.
|
|
bool Level::CanOpenChallengeRoom(int roomIdx)
|
|
{
|
|
RoomDescriptor& desc = *GetRoomByIdx(roomIdx);
|
|
PlayerManager& players = g_game->playerManager;
|
|
bool isOpen = false;
|
|
|
|
if (!desc.data) return false;
|
|
if (desc.flags & ROOM_DESCRIPTOR_FLAG_CHALLENGE_DONE) return true;
|
|
if (desc.data->subtype == CHALLENGE_SUBTYPE_BOSS)
|
|
{
|
|
isOpen = true;
|
|
for (int i = 0; i < (int)players.playerList.size() && isOpen; i++)
|
|
{
|
|
Entity_Player& player = *players.GetPlayer(i);
|
|
|
|
if (player.variant == PLAYER_VARIANT_PLAYER && player.soulHearts + player.redHearts > CHALLENGE_LOW_HEALTH)
|
|
isOpen = false;
|
|
}
|
|
}
|
|
else isOpen = players.check_full_health(HEALTH_CHECK_ALL);
|
|
|
|
return isOpen || (room->descriptor->flags & ROOM_DESCRIPTOR_FLAG_RED_ROOM) ||
|
|
(desc.flags & ROOM_DESCRIPTOR_FLAG_RED_ROOM);
|
|
}
|
|
|
|
// 007481d0 Forces a horseman boss.
|
|
bool Level::ForceHorsemanBoss(uint32_t)
|
|
{
|
|
reconstruction_missing("Level::ForceHorsemanBoss 007481d0");
|
|
}
|
|
|
|
// 00749830 Whether the floor's last boss room may open a deal door: not in Red Redemption, Mausoleum II, before the
|
|
// Ascent or on the way back up; past Basement I (but for the surprise miniboss daily) and up to the Womb, Depths II
|
|
// once the Womb is unlocked (any floor in Greed); and only when the boss room has two door slots or more.
|
|
bool Level::CanSpawnDevilRoom()
|
|
{
|
|
Game& game = *g_game;
|
|
if (game.challenge == CHALLENGE_RED_REDEMPTION) return false;
|
|
|
|
int labyrinthStage = (int)stage_with_labyrinth(*this);
|
|
bool isAltStage = stageType == STAGETYPE_REPENTANCE || stageType == STAGETYPE_REPENTANCE_B;
|
|
bool isMausoleumTwo = !is_greed() && isAltStage && labyrinthStage == (int)STAGE_WOMB_II;
|
|
bool isBackwards = stage - 1 < ASCENT_LAST_STAGE && game_flag_get(LEVEL_GAME_STATE_BACKWARDS_PATH);
|
|
if (isMausoleumTwo || IsPreAscent() || isBackwards) return false;
|
|
|
|
int dealStage = labyrinthStage + (isAltStage ? 1 : 0);
|
|
if (!is_greed())
|
|
{
|
|
if (dealStage == (int)STAGE_BASEMENT_I && game.dailyChallenge._specialDailyId != SPECIAL_DAILY_DEALS)
|
|
return false;
|
|
if (dealStage != (int)STAGE_BASEMENT_I && dealStage > (int)STAGE_WOMB_II) return false;
|
|
if (dealStage == (int)STAGE_DEPTHS_II && !is_unlocked(ACHIEVEMENT_THE_WOMB)) return false;
|
|
}
|
|
return std::popcount(roomList[lastBossRoomListIdx].data->doors & 0xff) > 1;
|
|
}
|
|
|
|
// 007f96f0 The chance the floor's deal room is an angel room: halved after Famine or a visited devil room, raised
|
|
// by the Key Pieces, Book of Virtues, donations and a killed evil beggar, moved a tenth by a beggar left or an evil
|
|
// one left, and scaled by the floor's own chance (none without it, unless no deal was taken since a devil room
|
|
// spawned). Eucharist makes it sure.
|
|
float get_angel_room_chance()
|
|
{
|
|
Game& game = *g_game;
|
|
PlayerManager& players = game.playerManager;
|
|
auto isHeld = [&](int item) { return players.FirstCollectibleOwner(item, LAZARUS_SHARE_CHECK) != nullptr; };
|
|
auto raise = [](float chance, float share) { return chance + (1 - chance) * share; };
|
|
bool isFamineOrVisited = game.gameStateFlags & (1ull << GAME_STATE_FAMINE_SPAWNED | 1ull << GAME_STATE_DEVILROOM_VISITED);
|
|
bool isDevilSpawned = game.gameStateFlags & (1ull << GAME_STATE_DEVILROOM_SPAWNED);
|
|
|
|
float chance = isFamineOrVisited ? ANGEL_CHANCE_HALVED : 1;
|
|
if (isHeld(COLLECTIBLE_KEY_PIECE_1)) chance = raise(chance, ANGEL_ITEM_SHARE);
|
|
if (isHeld(COLLECTIBLE_KEY_PIECE_2)) chance = raise(chance, ANGEL_ITEM_SHARE);
|
|
if (isHeld(COLLECTIBLE_BOOK_OF_VIRTUES)) chance = raise(chance, ANGEL_ITEM_SHARE);
|
|
if (game.donationModAngel >= ANGEL_DONATIONS) chance = raise(chance, ANGEL_DONATION_SHARE);
|
|
|
|
uint32_t flags = game.levelStateFlags;
|
|
bool isBumLeft = flags & (1u << LEVEL_STATE_BUM_LEFT);
|
|
bool isEvilBumLeft = flags & (1u << LEVEL_STATE_EVIL_BUM_LEFT);
|
|
if (flags & (1u << LEVEL_STATE_EVIL_BUM_KILLED)) chance = raise(chance, ANGEL_ITEM_SHARE);
|
|
if (isBumLeft != isEvilBumLeft) chance = raise(chance, isBumLeft ? ANGEL_BEGGAR_SHARE : -ANGEL_BEGGAR_SHARE);
|
|
|
|
bool isScaled = game.angelRoomChance > 0 || (isHeld(COLLECTIBLE_ACT_OF_CONTRITION) && isDevilSpawned) ||
|
|
isHeld(COLLECTIBLE_BOOK_OF_VIRTUES);
|
|
if (isScaled) chance = raise(chance, game.angelRoomChance);
|
|
else if (!isDevilSpawned || game.devilRoomDeals != 0) chance = 0;
|
|
if (isHeld(COLLECTIBLE_EUCHARIST)) chance = ANGEL_CHANCE_EUCHARIST;
|
|
return std::clamp(chance, 0.0f, 1.0f);
|
|
}
|
|
|
|
// How many of a boss room's doors could lead to a deal room: a slot the boss room has whose side the deal room has.
|
|
static int deal_door_matches(uint32_t bossDoors, uint32_t dealDoors, int startSlot)
|
|
{
|
|
int matches = 0;
|
|
for (int i = 0; i < DOOR_SLOT_COUNT; i++)
|
|
{
|
|
int slot = (startSlot + i) & (DOOR_SLOT_COUNT - 1);
|
|
if ((bossDoors & (1u << slot)) && (dealDoors & (1u << ((slot - 2) & 3)))) matches++;
|
|
}
|
|
return matches;
|
|
}
|
|
|
|
// 007499a0 Picks the floor's deal room once: an angel room on the angel roll (or when forced), else a devil room
|
|
// (Number Magnet's kind with one). The Womb's first deal is the special one until It Lives! is unlocked. Up to ten
|
|
// draws look for one that fits two of the last boss room's doors. Krampus may wait in a devil room once unlocked:
|
|
// 1 in 20 after a visited devil room, 3 with a deal taken (10 more on the deals daily).
|
|
void Level::InitializeDevilAngelRoom(bool isForceAngel, bool isForceDevil)
|
|
{
|
|
RoomDescriptor& desc = *GetRoomByIdx(ROOM_DEVIL_IDX);
|
|
if (desc.data) return;
|
|
|
|
float angelChance = get_angel_room_chance();
|
|
bool isAngelRoll = devilAngelRoomRNG.RandomFloat() < angelChance;
|
|
int effectiveStage = (int)stage + (filter_curses(CURSE_OF_LABYRINTH) ? 1 : 0);
|
|
RoomQuery query = room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_DEVIL, 0);
|
|
query.maxVariant = DEAL_VARIANT_LAST;
|
|
if (effectiveStage == (int)STAGE_WOMB_II && IsStageWithinEnd(STAGE_SHEOL, isAngelRoll) &&
|
|
!is_unlocked(ACHIEVEMENT_IT_LIVES))
|
|
query.minVariant = query.maxVariant = DEAL_VARIANT_WOMB;
|
|
if (isAngelRoll || isForceAngel) query.type = ROOM_ANGEL;
|
|
if (isForceDevil) query.type = ROOM_DEVIL;
|
|
if (query.type == ROOM_DEVIL) query.subtype = g_game->playerManager.AnyoneHasTrinket(TRINKET_NUMBER_MAGNET) ? 1 : 0;
|
|
|
|
desc.InitSeeds(devilAngelRoomRNG);
|
|
for (int tries = DEAL_ROOM_TRIES; tries > 0; tries--)
|
|
{
|
|
desc.data = random_room_get(devilAngelRoomRNG.Next(), query, WEIGHT_KEEP);
|
|
if (!CanSpawnDevilRoom()) break;
|
|
|
|
int startSlot = (int)(Random() & (DOOR_SLOT_COUNT - 1));
|
|
if (deal_door_matches(roomList[lastBossRoomListIdx].data->doors, desc.data->doors, startSlot) >= 2) break;
|
|
}
|
|
|
|
Game& game = *g_game;
|
|
bool isKrampusFree = is_unlocked(ACHIEVEMENT_KRAMPUS) && !(game.gameStateFlags & (1ull << GAME_STATE_KRAMPUS_SPAWNED));
|
|
if (query.type != ROOM_DEVIL || !isKrampusFree || query.subtype != 0) return;
|
|
|
|
uint32_t odds = 0;
|
|
if (game.gameStateFlags & (1ull << GAME_STATE_DEVILROOM_VISITED | 1ull << GAME_STATE_KRAMPUS_SPAWNED))
|
|
odds = game.devilRoomDeals > 0 ? KRAMPUS_ODDS_DEAL : KRAMPUS_ODDS_VISITED;
|
|
bool isDealsDaily = game.dailyChallenge._specialDailyId == SPECIAL_DAILY_DEALS;
|
|
if (isDealsDaily) odds += KRAMPUS_ODDS_DEALS_DAILY;
|
|
if (devilAngelRoomRNG.Next() % KRAMPUS_ROLL >= odds || query.minVariant >= DEAL_VARIANT_WOMB) return;
|
|
|
|
desc.flags |= ROOM_DESCRIPTOR_FLAG_SURPRISE_MINIBOSS;
|
|
if (!isDealsDaily) game.gameStateFlags |= 1ull << GAME_STATE_KRAMPUS_SPAWNED;
|
|
}
|
|
|
|
// 0074ba00 Starts Mama Mega's explosion.
|
|
void Level::StartMamaMega(Vector&, Entity_Player*)
|
|
{
|
|
reconstruction_missing("Level::StartMamaMega 0074ba00");
|
|
}
|
|
|
|
// 0074eaf0 Raises the mineshaft's rail.
|
|
void Level::raise_mineshaft_rail()
|
|
{
|
|
reconstruction_missing("Level::raise_mineshaft_rail 0074eaf0");
|
|
}
|
|
|
|
// The music layer the Ascent turns on for a stage it climbs through: one per chapter, the alternate paths' past them.
|
|
static int backwards_layer_get(int ascentStage)
|
|
{
|
|
uint32_t stageType = g_game->backwardsStages[ascentStage - 1].stageType;
|
|
bool isAltPath = stageType == STAGETYPE_REPENTANCE || stageType == STAGETYPE_REPENTANCE_B;
|
|
return isAltPath ? (ascentStage - 2) / 2 + ALT_PATH_LAYER_FIRST : (ascentStage - 1) / 2;
|
|
}
|
|
|
|
// 007eb870 Sets the current track's layers for the room the players are in (the original's this is the room). On the
|
|
// Ascent each layer is a stage climbed through outside its boss room. Elsewhere the intense layer plays while the
|
|
// room's enemies have health enough for the floor (always from the Blue Womb on, and with Berserk), the Mines' chase
|
|
// counting its pits. Nothing changes in the Home's dungeon or in Home's alternate. True when a layer plays.
|
|
bool Level::UpdateBackwardsPathStages()
|
|
{
|
|
Game& game = *g_game;
|
|
MusicManager& music = g_manager->musicManager;
|
|
RoomDescriptor* descriptor = room->descriptor;
|
|
RoomConfig_Room* data = descriptor->data;
|
|
|
|
if (data && data->type == ROOM_DUNGEON && data->stageId == STAGE_ID_HOME) return false;
|
|
int floor = (int)game.stage;
|
|
bool isAscentFloor = floor >= (int)STAGE_BASEMENT_I && floor <= (int)ASCENT_LAST_STAGE;
|
|
if (isAscentFloor && (game.gameStateFlags >> LEVEL_GAME_STATE_BACKWARDS_PATH & 1))
|
|
{
|
|
bool isAltPath = game.stageType == STAGETYPE_REPENTANCE || game.stageType == STAGETYPE_REPENTANCE_B;
|
|
int first = floor + (isAltPath ? 1 : 0);
|
|
uint32_t layers = 0;
|
|
for (int ascentStage = first; ascentStage <= BACKWARDS_STAGE_COUNT; ascentStage++)
|
|
if (ascentStage != first || game.room->descriptor->listIndex != game.lastBossRoomListIdx)
|
|
layers |= 1u << backwards_layer_get(ascentStage);
|
|
for (int layer = 0; layer < MUSIC_LAYER_COUNT; layer++)
|
|
layers >> layer & 1 ? music.EnableLayer(layer, LAYER_FADE) : music.DisableLayer(layer);
|
|
return layers != 0;
|
|
}
|
|
if (!isAscentFloor && floor == (int)STAGE_HOME && game.stageType == STAGETYPE_WOTL) return true;
|
|
|
|
int depth = floor;
|
|
if (game.IsGreedMode()) depth = floor <= GREED_STAGE_LAST_PAIRED ? floor * 2 - 1 : floor == GREED_STAGE_SHOP ? GREED_DEPTH_SHOP : 0;
|
|
float threshold = (float)depth * INTENSE_HEALTH_PER_STAGE + INTENSE_HEALTH_BASE;
|
|
float health = 0;
|
|
for (size_t i = 0; i < game.playerManager.playerList.size(); i++)
|
|
if (game.GetPlayer((int)i)->temporaryEffects.HasCollectibleEffect(COLLECTIBLE_BERSERK))
|
|
{
|
|
health = INTENSE_HEALTH_ALWAYS;
|
|
break;
|
|
}
|
|
|
|
if (floor < (int)STAGE_BLUE_WOMB)
|
|
{
|
|
for (Entity* entity : room->entityList.updateEL)
|
|
{
|
|
bool isCounted = (game.deathmatchManager.is_active() && entity->type == ENTITY_PLAYER) ||
|
|
(entity->type >= ENTITY_FIRST_ENEMY && entity->type <= ENEMY_TYPE_LAST);
|
|
if (isCounted && entity->CanShutDoors() && !entity->isDead && !entity->HasEntityFlags(FLAG_NO_TARGET))
|
|
health += entity->health;
|
|
}
|
|
if (health > 0)
|
|
{
|
|
bool isMineshaft = false;
|
|
if (game.challenge == CHALLENGE_RED_REDEMPTION)
|
|
isMineshaft = RoomConfig::GetStageID(floor, GetRoomStageType(currentRoomIdx), ROOM_MODE_CURRENT) == STAGE_ID_MINES;
|
|
else if (game.currentDimensionIdx != DIMENSION_MINESHAFT)
|
|
isMineshaft = RoomConfig::GetStageID(floor, (int)game.stageType, ROOM_MODE_CURRENT) == STAGE_ID_MINES;
|
|
uint32_t flags = descriptor->flags;
|
|
bool isChase = isMineshaft && !(flags & ROOM_DESCRIPTOR_FLAG_CLEAR) && (flags & ROOM_DESCRIPTOR_FLAG_HAS_WATER) &&
|
|
!(flags & ROOM_DESCRIPTOR_FLAG_FLOODED);
|
|
if (isChase) health += (float)descriptor->pitsCount * MINESHAFT_HEALTH_PER_PIT;
|
|
}
|
|
}
|
|
else if (!(descriptor->flags & ROOM_DESCRIPTOR_FLAG_CLEAR)) health += INTENSE_HEALTH_ALWAYS;
|
|
|
|
bool isIntense = health >= threshold;
|
|
isIntense ? music.EnableLayer(0, LAYER_FADE) : music.DisableLayer(0);
|
|
return isIntense;
|
|
}
|
|
|
|
// 0074b960 The stage counted as in normal runs.
|
|
int Level::GetAbsoluteStage()
|
|
{
|
|
if (g_game->difficulty != DIFFICULTY_GREED && g_game->difficulty != DIFFICULTY_GREEDIER) return (int)stage;
|
|
if (stage < STAGE_GREED_SHEOL) return (int)stage * 2 - 1;
|
|
return stage == STAGE_GREED_SHEOL ? STAGE_SHEOL : 0;
|
|
}
|
|
|
|
// 0074bae0 The secret exit the floor's depth calls for, an XL floor counting as its second stage and the alternate path
|
|
// as one deeper. None in Greed, nor on the alternate path's first floors.
|
|
int Level::get_secret_exit_kind()
|
|
{
|
|
bool isLabyrinth = curses & CURSE_OF_LABYRINTH;
|
|
if (is_greed() || ((stage & 1) && IsAltPath() && !isLabyrinth)) return SECRET_EXIT_NONE;
|
|
|
|
switch (stage + isLabyrinth + IsAltPath())
|
|
{
|
|
case 1:
|
|
case 2:
|
|
return SECRET_EXIT_DOWNPOUR;
|
|
case 3:
|
|
case 4:
|
|
return SECRET_EXIT_MINES;
|
|
case 5:
|
|
return SECRET_EXIT_MAUSOLEUM;
|
|
case 7:
|
|
return IsAltPath() ? SECRET_EXIT_MOMS_HEART : SECRET_EXIT_NONE;
|
|
default:
|
|
return SECRET_EXIT_NONE;
|
|
}
|
|
}
|
|
|
|
// 0074bba0 The secret exit's room.
|
|
RoomDescriptor* Level::get_secret_exit_room(int)
|
|
{
|
|
reconstruction_missing("Level::get_secret_exit_room 0074bba0");
|
|
}
|
|
|
|
// 00745ca0 A stage's display name in the current language: stages.xml's, then the endless basement's roman numeral and
|
|
// its jokes, then " I" or " II" for a chapter's floor or " XL" for a labyrinth, scrambled for dyslexia. Greed and Red
|
|
// Redemption add no floor number. Empty for no stage.
|
|
std::string Level::get_stage_display_name(const StageNameQuery& query)
|
|
{
|
|
if (query.stage == 0) return "";
|
|
|
|
Game& game = *g_game;
|
|
RoomMode mode = query.mode;
|
|
if (mode == ROOM_MODE_CURRENT) mode = g_game && g_game->IsGreedMode() ? ROOM_MODE_GREED : ROOM_MODE_NORMAL;
|
|
int stageId = RoomConfig::GetStageID(query.stage, query.stageType, mode);
|
|
std::string name = game.roomConfig.stages[stageId].GetDisplayName(LANGUAGE_CURRENT);
|
|
|
|
if (query.numeral > 0)
|
|
{
|
|
name += ' ';
|
|
int remaining = query.numeral;
|
|
for (const RomanNumeral& numeral : ROMAN_NUMERALS)
|
|
for (; remaining >= numeral.value; remaining -= numeral.value) name += numeral.text;
|
|
|
|
uint32_t count = (uint32_t)game.stageNameNumeral;
|
|
if (count == NUMERAL_QUESTION) name += "?";
|
|
if (count == NUMERAL_EXCLAIM) name += "?!";
|
|
if (count == NUMERAL_ELLIPSIS) name += "...";
|
|
if (count == NUMERAL_SPIKES) name += " Spikes";
|
|
if (count % 1000 == 0) name += "... Please stop.";
|
|
else if (count % 500 == 0) name += "!V";
|
|
else if (count % 100 == 0) name += "!!!";
|
|
else if (count % 50 == 0) name += "!!";
|
|
else if (count % 10 == 0) name += "!";
|
|
}
|
|
|
|
bool isNumbered = mode != ROOM_MODE_GREED && game.challenge != CHALLENGE_RED_REDEMPTION;
|
|
if (isNumbered && (query.curses & CURSE_OF_LABYRINTH)) name += " XL";
|
|
else if (isNumbered && query.numeral == 0 && query.stage >= 1 && query.stage <= (int)STAGE_WOMB_II)
|
|
name += query.stage & 1 ? " I" : " II";
|
|
return query.isScrambled ? string_scramble_seeded(name) : name;
|
|
}
|
|
|
|
// 007460b0 The floor's name, with Red Redemption's room stage type, the endless basement's numeral and dyslexia.
|
|
std::string Level::GetName()
|
|
{
|
|
Game& game = *g_game;
|
|
bool isRedRedemption = game.challenge == CHALLENGE_RED_REDEMPTION;
|
|
|
|
return get_stage_display_name({.stage = (int)stage,
|
|
.stageType = isRedRedemption ? GetRoomStageType(currentRoomIdx) : (int)stageType,
|
|
.curses = GetCurses(),
|
|
.numeral = game.seedEffects.HasSeedEffect(SEED_INFINITE_BASEMENT) ? game.stageNameNumeral : 0,
|
|
.isScrambled = game.seedEffects.HasSeedEffect(SEED_DYSLEXIA),
|
|
.mode = ROOM_MODE_CURRENT});
|
|
}
|
|
|
|
// 00746260 The name of the floor's first curse, scrambled for dyslexia. Empty for none.
|
|
std::string Level::GetCurseName()
|
|
{
|
|
Game& game = *g_game;
|
|
std::string name;
|
|
|
|
for (uint32_t curse = 0; curse < game.roomConfig.curses.size(); curse++)
|
|
if (GetCurses() & 1u << curse)
|
|
{
|
|
name = game.roomConfig.GetCurseName(curse + 1);
|
|
break;
|
|
}
|
|
return game.seedEffects.HasSeedEffect(SEED_DYSLEXIA) ? string_scramble_seeded(name) : name;
|
|
}
|
|
|
|
// 00746560 Shows the floor's name and curse in the HUD's banner, hiding by itself unless sticky. Versus shows its own.
|
|
void Level::ShowName(bool isSticky)
|
|
{
|
|
std::string name = GetName();
|
|
std::string curse = GetCurseName();
|
|
|
|
if (g_game->deathmatchManager.is_active())
|
|
{
|
|
name = g_manager->stringTable.translate(DEATHMATCH_NAME_KEY);
|
|
curse.clear();
|
|
}
|
|
g_game->hud.messageMain.Show(name.c_str(), curse.c_str(), !isSticky, !curse.empty());
|
|
}
|