From 8738c1f9363b7edb6653feaba83f1c1959cab8af Mon Sep 17 00:00:00 2001 From: Anthony Stewart Date: Tue, 8 Apr 2025 19:57:09 -0500 Subject: [PATCH] Added Randomizer_EntranceDiscovered. --- soh/soh/Enhancements/randomizer/entrance.cpp | 38 ++++++++++++------- soh/soh/Enhancements/randomizer/entrance.h | 1 + .../Enhancements/randomizer/location_access.h | 2 + .../randomizer/randomizer_check_tracker.cpp | 19 ++++------ .../randomizer/randomizer_entrance.c | 1 + .../randomizer/randomizer_entrance_tracker.h | 1 + 6 files changed, 37 insertions(+), 25 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/entrance.cpp b/soh/soh/Enhancements/randomizer/entrance.cpp index 36d90416a..ff9dfa459 100644 --- a/soh/soh/Enhancements/randomizer/entrance.cpp +++ b/soh/soh/Enhancements/randomizer/entrance.cpp @@ -4,6 +4,7 @@ #include "3drando/pool_functions.hpp" #include "3drando/item_pool.hpp" #include "../debugger/performanceTimer.h" +#include "randomizer_check_tracker.h" #include @@ -250,6 +251,8 @@ std::string EntranceNameByRegions(RandomizerRegion parentRegion, RandomizerRegio return RegionTable(parentRegion)->regionName + " -> " + RegionTable(connectedRegion)->regionName; } +std::unordered_map entranceMap; + void SetAllEntrancesData(std::vector& entranceShuffleTable) { auto ctx = Rando::Context::GetInstance(); for (auto& entrancePair : entranceShuffleTable) { @@ -262,6 +265,7 @@ void SetAllEntrancesData(std::vector& entranceShuffleTable) { forwardEntrance->SetIndex(forwardEntry.index); forwardEntrance->SetType(forwardEntry.type); forwardEntrance->SetAsPrimary(); + entranceMap[forwardEntry.index] = forwardEntrance; // When decouple entrances is on, mark the forward entrance if (ctx->GetOption(RSK_DECOUPLED_ENTRANCES)) { @@ -273,6 +277,7 @@ void SetAllEntrancesData(std::vector& entranceShuffleTable) { returnEntrance->SetIndex(returnEntry.index); returnEntrance->SetType(returnEntry.type); forwardEntrance->BindTwoWay(returnEntrance); + entranceMap[returnEntry.index] = returnEntrance; // Mark reverse entrance as decoupled if (ctx->GetOption(RSK_DECOUPLED_ENTRANCES)) { @@ -1667,21 +1672,11 @@ void EntranceShuffler::ParseJson(nlohmann::json spoilerFileJson) { void EntranceShuffler::ApplyEntranceOverrides() { SetAllEntrancesData(entranceShuffleTable); - std::unordered_map entrances; - for (uint32_t rr = RR_NONE; rr < RR_MAX; rr++) { - for (auto& exit : areaTable[rr].exits) { - int16_t index = exit.GetIndex(); - if (index != -1) { - entrances[index] = &exit; - } - } - } - for (size_t i = 0; i < entranceOverrides.size(); i++) { EntranceOverride entranceOverride = entranceOverrides[i]; - Entrance* entrance = entrances[entranceOverride.index]; - Entrance* overrideEntrance = entrances[entranceOverride.override]; + Entrance* entrance = entranceMap[entranceOverride.index]; + Entrance* overrideEntrance = entranceMap[entranceOverride.override]; entrance->Disconnect(); entrance->Connect(overrideEntrance->GetOriginalConnectedRegionKey()); @@ -1689,6 +1684,23 @@ void EntranceShuffler::ApplyEntranceOverrides() { } } // namespace Rando -extern "C" EntranceOverride* Randomizer_GetEntranceOverrides() { +extern "C" { +EntranceOverride* Randomizer_GetEntranceOverrides() { return Rando::Context::GetInstance()->GetEntranceShuffler()->entranceOverrides.data(); } + +void Randomizer_DiscoverRegion(Region* region) { + region->IsDiscovered = true; + + // RANDOTODO: Discover other regions that will be known based on rando settings +} + +void Randomizer_EntranceDiscovered(s16 index) { + Rando::Entrance* entrance = Rando::entranceMap[index]; + Region* region = entrance->GetConnectedRegion(); + + Randomizer_DiscoverRegion(region); + + CheckTracker::RecalculateAvailableChecks(); +} +} \ No newline at end of file diff --git a/soh/soh/Enhancements/randomizer/entrance.h b/soh/soh/Enhancements/randomizer/entrance.h index 6cb631db3..15608c951 100644 --- a/soh/soh/Enhancements/randomizer/entrance.h +++ b/soh/soh/Enhancements/randomizer/entrance.h @@ -153,6 +153,7 @@ class EntranceShuffler { extern "C" { #endif EntranceOverride* Randomizer_GetEntranceOverrides(); +void Randomizer_EntranceDiscovered(s16 index); #ifdef __cplusplus } #endif diff --git a/soh/soh/Enhancements/randomizer/location_access.h b/soh/soh/Enhancements/randomizer/location_access.h index 828c31a08..b9568a8e6 100644 --- a/soh/soh/Enhancements/randomizer/location_access.h +++ b/soh/soh/Enhancements/randomizer/location_access.h @@ -138,6 +138,8 @@ class Region { bool addedToPool = false; ; + bool IsDiscovered = false; + void ApplyTimePass(); bool UpdateEvents(); diff --git a/soh/soh/Enhancements/randomizer/randomizer_check_tracker.cpp b/soh/soh/Enhancements/randomizer/randomizer_check_tracker.cpp index e71f9bf94..2bc85df91 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_check_tracker.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_check_tracker.cpp @@ -1967,11 +1967,13 @@ void RecalculateAvailableChecks() { ResetPerformanceTimer(PT_RECALCULATE_AVAILABLE_CHECKS); StartPerformanceTimer(PT_RECALCULATE_AVAILABLE_CHECKS); + const auto& ctx = Rando::Context::GetInstance(); + std::vector targetLocations; targetLocations.reserve(RR_MAX); for (auto& location : Rando::StaticData::GetLocationTable()) { RandomizerCheck rc = location.GetRandomizerCheck(); - Rando::ItemLocation* itemLocation = OTRGlobals::Instance->gRandoContext->GetItemLocation(rc); + Rando::ItemLocation* itemLocation = ctx->GetItemLocation(rc); itemLocation->SetAvailable(false); if (!itemLocation->HasObtained()) { targetLocations.emplace_back(rc); @@ -1981,17 +1983,10 @@ void RecalculateAvailableChecks() { std::vector availableChecks = ReachabilitySearch(targetLocations, RG_NONE, true); for (auto& rc : availableChecks) { const auto& location = Rando::StaticData::GetLocation(rc); - const auto& itemLocation = OTRGlobals::Instance->gRandoContext->GetItemLocation(rc); + const auto& itemLocation = ctx->GetItemLocation(rc); + const auto& region = areaTable[itemLocation->GetParentRegionKey()]; - bool regionDiscovered = false; - const auto& entrances = areaTable[itemLocation->GetParentRegionKey()].entrances; - for (const auto& entrance : entrances) { - if (IsEntranceDiscovered(entrance->GetIndex())) { - regionDiscovered = true; - break; - } - } - if (!regionDiscovered) { + if (ctx->GetOption(RSK_SHUFFLE_ENTRANCES).Get() && !region.IsDiscovered) { continue; } @@ -2008,7 +2003,7 @@ void RecalculateAvailableChecks() { for (auto& [rcArea, vec] : checksByArea) { areaChecksAvailable[rcArea] = 0; for (auto& rc : vec) { - Rando::ItemLocation* itemLocation = OTRGlobals::Instance->gRandoContext->GetItemLocation(rc); + Rando::ItemLocation* itemLocation = ctx->GetItemLocation(rc); if (itemLocation->IsAvailable() && IsVisibleInCheckTracker(rc) && !IsCheckHidden(rc)) { areaChecksAvailable[rcArea]++; } diff --git a/soh/soh/Enhancements/randomizer/randomizer_entrance.c b/soh/soh/Enhancements/randomizer/randomizer_entrance.c index 11d17e621..0abee702c 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_entrance.c +++ b/soh/soh/Enhancements/randomizer/randomizer_entrance.c @@ -809,6 +809,7 @@ void Entrance_SetEntranceDiscovered(u16 entranceIndex, u8 isReversedEntrance) { if (idx < SAVEFILE_ENTRANCES_DISCOVERED_IDX_COUNT) { u32 entranceBit = 1 << (entranceIndex - (idx * bitsPerIndex)); gSaveContext.ship.stats.entrancesDiscovered[idx] |= entranceBit; + Randomizer_EntranceDiscovered(entranceIndex); // Set reverse entrance when not decoupled if (!Randomizer_GetSettingValue(RSK_DECOUPLED_ENTRANCES) && !isReversedEntrance) { diff --git a/soh/soh/Enhancements/randomizer/randomizer_entrance_tracker.h b/soh/soh/Enhancements/randomizer/randomizer_entrance_tracker.h index 8d6aa7a05..2c130a57c 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_entrance_tracker.h +++ b/soh/soh/Enhancements/randomizer/randomizer_entrance_tracker.h @@ -90,6 +90,7 @@ void InitEntranceTrackingData(); s16 GetLastEntranceOverride(); s16 GetCurrentGrottoId(); const EntranceData* GetEntranceData(s16); +void EntranceDiscovered(s16 index); bool IsEntranceDiscovered(s16 index); class EntranceTrackerSettingsWindow : public Ship::GuiWindow {