Skip to content

Commit

Permalink
Attempt to find area problems (HarbourMasters#4494)
Browse files Browse the repository at this point in the history
* Better insulate the code against no areas and fix misc issues

* remove a stray reminder comment
  • Loading branch information
Pepper0ni authored Oct 29, 2024
1 parent 108d506 commit b706532
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion soh/soh/Enhancements/randomizer/3drando/fill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,8 @@ void LookForExternalArea(Region* currentRegion, std::set<Region*> &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<RandomizerArea> 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.
Expand Down
18 changes: 13 additions & 5 deletions soh/soh/Enhancements/randomizer/3drando/hints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -707,7 +707,7 @@ void CreateChildAltarHint() {
}
std::vector<RandomizerArea> 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));
}
Expand All @@ -729,7 +729,7 @@ void CreateAdultAltarHint() {
}
std::vector<RandomizerArea> 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));
}
Expand All @@ -753,7 +753,15 @@ void CreateStaticHintFromData(RandomizerHint hint, StaticHintInfo staticData){
std::vector<RandomizerArea> 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));
Expand All @@ -768,7 +776,7 @@ void CreateStaticItemHint(RandomizerHint hintKey, std::vector<RandomizerHintText
std::vector<RandomizerCheck> locations = FindItemsAndMarkHinted(items, hintChecks);
std::vector<RandomizerArea> 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));
}
Expand Down
1 change: 1 addition & 0 deletions soh/soh/Enhancements/randomizer/3drando/random.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const T RandomElementFromSet(const std::set<T>& set) {
for (uint32_t i = 0; i < rand; i++) {
it++;
}
auto test = *it;
return *it;
}

Expand Down
11 changes: 11 additions & 0 deletions soh/soh/Enhancements/randomizer/item_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions soh/soh/Enhancements/randomizer/item_location.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ItemLocation {
void SetParentRegion (RandomizerRegion region);
std::set<RandomizerArea> GetAreas() const;
RandomizerArea GetFirstArea() const;
RandomizerArea GetRandomArea() const;
void MergeAreas (std::set<RandomizerArea> newAreas);
void PlaceVanillaItem();
void ApplyPlacedItemEffect() const;
Expand Down

0 comments on commit b706532

Please sign in to comment.