From b706532754c0e037e844035a75b56c6ea7f832b7 Mon Sep 17 00:00:00 2001 From: Pepper0ni <93387759+Pepper0ni@users.noreply.github.com> Date: Tue, 29 Oct 2024 00:35:36 +0000 Subject: [PATCH] Attempt to find area problems (#4494) * Better insulate the code against no areas and fix misc issues * remove a stray reminder comment --- .../Enhancements/randomizer/3drando/fill.cpp | 2 +- .../Enhancements/randomizer/3drando/hints.cpp | 18 +++++++++++++----- .../Enhancements/randomizer/3drando/random.hpp | 1 + .../Enhancements/randomizer/item_location.cpp | 11 +++++++++++ .../Enhancements/randomizer/item_location.h | 1 + 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/3drando/fill.cpp b/soh/soh/Enhancements/randomizer/3drando/fill.cpp index 29bd91354..833f4d028 100644 --- a/soh/soh/Enhancements/randomizer/3drando/fill.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/fill.cpp @@ -617,8 +617,8 @@ void LookForExternalArea(Region* currentRegion, std::set &alreadyChecke //if this entrance does not pass areas, only process it if we are in low priority mode if ((LowPriorityMode || entrance->DoesSpreadAreas()) && !alreadyChecked.contains(entrance->GetParentRegion())){ std::set otherAreas = entrance->GetParentRegion()->GetAllAreas(); - alreadyChecked.insert(entrance->GetParentRegion()); if (otherAreas.size() == 0) { + alreadyChecked.insert(entrance->GetParentRegion()); LookForExternalArea(entrance->GetParentRegion(), alreadyChecked, areas, LowPriorityMode); //If we find a valid area we should add it. //If it's Links Pocket or RA_NONE, do not propagate those, they are not real areas. diff --git a/soh/soh/Enhancements/randomizer/3drando/hints.cpp b/soh/soh/Enhancements/randomizer/3drando/hints.cpp index 770014dd9..f72212301 100644 --- a/soh/soh/Enhancements/randomizer/3drando/hints.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/hints.cpp @@ -411,7 +411,7 @@ static bool CreateHint(RandomizerCheck location, uint8_t copies, HintType type, return false; } RandomizerCheck gossipStone = RandomElement(gossipStoneLocations); - RandomizerArea area = RandomElementFromSet(ctx->GetItemLocation(location)->GetAreas()); + RandomizerArea area = ctx->GetItemLocation(location)->GetRandomArea(); //Set that hints are accesible ctx->GetItemLocation(location)->SetHintAccesible(); @@ -707,7 +707,7 @@ void CreateChildAltarHint() { } std::vector stoneAreas = {}; for (auto loc : stoneLocs){ - stoneAreas.push_back(RandomElementFromSet(ctx->GetItemLocation(loc)->GetAreas())); + stoneAreas.push_back(ctx->GetItemLocation(loc)->GetRandomArea()); } ctx->AddHint(RH_ALTAR_CHILD, Hint(RH_ALTAR_CHILD, HINT_TYPE_ALTAR_CHILD, {}, stoneLocs, stoneAreas)); } @@ -729,7 +729,7 @@ void CreateAdultAltarHint() { } std::vector medallionAreas = {}; for (auto loc : medallionLocs){ - medallionAreas.push_back(RandomElementFromSet(ctx->GetItemLocation(loc)->GetAreas())); + medallionAreas.push_back(ctx->GetItemLocation(loc)->GetRandomArea()); } ctx->AddHint(RH_ALTAR_ADULT, Hint(RH_ALTAR_ADULT, HINT_TYPE_ALTAR_ADULT, {}, medallionLocs, medallionAreas)); } @@ -753,7 +753,15 @@ void CreateStaticHintFromData(RandomizerHint hint, StaticHintInfo staticData){ std::vector areas = {}; for (auto loc : locations){ ctx->GetItemLocation(loc)->SetHintAccesible(); - areas.push_back(RandomElementFromSet(ctx->GetItemLocation(loc)->GetAreas())); + if (ctx->GetItemLocation(loc)->GetAreas().empty()){ + //If we get to here then it means a location got through with no area assignment, which means something went wrong elsewhere. + SPDLOG_DEBUG("Attempted to hint location with no areas: "); + SPDLOG_DEBUG(Rando::StaticData::GetLocation(loc)->GetName()); + assert(false); + areas.push_back(RA_NONE); + } else { + areas.push_back(ctx->GetItemLocation(loc)->GetRandomArea()); + } } //hintKeys are defaulted to in the hint object and do not need to be specified ctx->AddHint(hint, Hint(hint, staticData.type, {}, locations, areas, {}, staticData.yourPocket, staticData.num)); @@ -768,7 +776,7 @@ void CreateStaticItemHint(RandomizerHint hintKey, std::vector locations = FindItemsAndMarkHinted(items, hintChecks); std::vector areas = {}; for (auto loc : locations){ - areas.push_back(RandomElementFromSet(ctx->GetItemLocation(loc)->GetAreas())); + areas.push_back(ctx->GetItemLocation(loc)->GetRandomArea()); } ctx->AddHint(hintKey, Hint(hintKey, HINT_TYPE_AREA, hintTextKeys, locations, areas, {}, yourPocket)); } diff --git a/soh/soh/Enhancements/randomizer/3drando/random.hpp b/soh/soh/Enhancements/randomizer/3drando/random.hpp index 2d2f11dbe..24ab78dcd 100644 --- a/soh/soh/Enhancements/randomizer/3drando/random.hpp +++ b/soh/soh/Enhancements/randomizer/3drando/random.hpp @@ -40,6 +40,7 @@ const T RandomElementFromSet(const std::set& set) { for (uint32_t i = 0; i < rand; i++) { it++; } + auto test = *it; return *it; } diff --git a/soh/soh/Enhancements/randomizer/item_location.cpp b/soh/soh/Enhancements/randomizer/item_location.cpp index 75d539d04..6b1e3003e 100644 --- a/soh/soh/Enhancements/randomizer/item_location.cpp +++ b/soh/soh/Enhancements/randomizer/item_location.cpp @@ -81,6 +81,17 @@ RandomizerArea ItemLocation::GetFirstArea() const { } } +RandomizerArea ItemLocation::GetRandomArea() const { + if (areas.empty()){ + SPDLOG_DEBUG("Attempted to get random area of location with no areas: "); + SPDLOG_DEBUG(Rando::StaticData::GetLocation(rc)->GetName()); + assert(false); + return RA_NONE; + } else { + return RandomElementFromSet(areas); + } +} + void ItemLocation::PlaceVanillaItem() { placedItem = StaticData::GetLocation(rc)->GetVanillaItem(); } diff --git a/soh/soh/Enhancements/randomizer/item_location.h b/soh/soh/Enhancements/randomizer/item_location.h index 335637261..d49debf5f 100644 --- a/soh/soh/Enhancements/randomizer/item_location.h +++ b/soh/soh/Enhancements/randomizer/item_location.h @@ -24,6 +24,7 @@ class ItemLocation { void SetParentRegion (RandomizerRegion region); std::set GetAreas() const; RandomizerArea GetFirstArea() const; + RandomizerArea GetRandomArea() const; void MergeAreas (std::set newAreas); void PlaceVanillaItem(); void ApplyPlacedItemEffect() const;