Skip to content

Commit b8ed704

Browse files
authored
Merge pull request #159 from gymnast86/barren-fix
Fix some items being incorrectly marked barren
2 parents d01341a + 0957ae7 commit b8ed704

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

logic/Hints.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ static HintError calculatePossibleBarrenRegions(WorldPool& worlds)
146146
auto chainLocations = location->currentItem.getChainLocations();
147147
if (!chainLocations.empty())
148148
{
149-
// If all of this item's chain locations' items can be in barren regions (or are nonprogression locations), then this item is junk
150-
if (std::ranges::all_of(chainLocations, [](const Location* loc){ return !loc->progression || loc->currentItemCanBeBarren(); }))
149+
// If all of this item's chain locations' are barren as chain locations, then this item is barren too.
150+
if (std::ranges::all_of(chainLocations, [](const Location* loc){ return loc->isBarrenAsChainLocation(); }))
151151
{
152152
location->currentItem.setAsJunkItem();
153153
LOG_TO_DEBUG(location->currentItem.getName() + " is now junk.");
@@ -176,7 +176,7 @@ static HintError calculatePossibleBarrenRegions(WorldPool& worlds)
176176
newJunkItems = false;
177177
for (Item* item : potentiallyJunkItems)
178178
{
179-
if (!item->isJunkItem() && std::ranges::all_of(item->getChainLocations(), [](const Location* loc){ return !loc->progression || loc->currentItemCanBeBarren(); }))
179+
if (!item->isJunkItem() && std::ranges::all_of(item->getChainLocations(), [](const Location* loc){ return loc->isBarrenAsChainLocation(); }))
180180
{
181181
newJunkItems = true;
182182
item->setAsJunkItem();
@@ -222,7 +222,7 @@ static HintError calculatePossibleBarrenRegions(WorldPool& worlds)
222222
for (auto outsideLoc : location->outsideDependentLocations)
223223
{
224224
// If an outside dependent location is not barren, remove the region from being barren
225-
if (!outsideLoc->currentItemCanBeBarren())
225+
if (!outsideLoc->isBarrenAsChainLocation())
226226
{
227227
LOG_TO_DEBUG("Removed " + hintRegion + " from barren pool due to item " + outsideLoc->currentItem.getName() + " at location " + outsideLoc->getName() + " which is dependent on " + location->getName());
228228
world.barrenRegions.erase(hintRegion);

logic/Location.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,11 @@ bool Location::currentItemCanBeBarren() const
170170
}
171171
}
172172

173-
// If any of the remaining chain locations have an item which can't be barren, then this location's item isn't barren either
173+
// If any of the remaining chain locations have an item which can't be barren, or the location is a required race mode location,
174+
// then this location's item isn't barren.
174175
for (auto& location : chainLocations)
175176
{
176-
if (!location->currentItem.canBeInBarrenRegion())
177+
if (!location->isBarrenAsChainLocation())
177178
{
178179
return false;
179180
}
@@ -182,6 +183,13 @@ bool Location::currentItemCanBeBarren() const
182183
return true;
183184
}
184185

186+
// When a location is being checked for barreness as a chain location, it should not be considered barren
187+
// if it's a required race mode location
188+
bool Location::isBarrenAsChainLocation() const
189+
{
190+
return !progression || (currentItem.canBeInBarrenRegion() && !isRequiredRaceModeLocation);
191+
}
192+
185193
std::u16string Location::generateImportanceText(const std::string& language)
186194
{
187195
auto& item = currentItem;

logic/Location.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class Location
7272
std::unordered_set<LocationCategory> categories;
7373
bool progression;
7474
bool isRaceModeLocation;
75+
bool isRequiredRaceModeLocation;
7576
uint8_t stageId = 0;
7677
bool plandomized;
7778
bool hasBeenHinted;
@@ -112,6 +113,7 @@ class Location
112113
categories({LocationCategory::INVALID}),
113114
progression(false),
114115
isRaceModeLocation(false),
116+
isRequiredRaceModeLocation(false),
115117
stageId(0),
116118
plandomized(false),
117119
hasBeenHinted(false),
@@ -141,6 +143,7 @@ class Location
141143
std::string getName() const;
142144
std::u16string generateImportanceText(const std::string& language);
143145
bool currentItemCanBeBarren() const;
146+
bool isBarrenAsChainLocation() const;
144147
};
145148

146149
using LocationSet = std::set<Location*, PointerLess<Location>>;

logic/World.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ World::WorldLoadingError World::determineRaceModeDungeons(WorldPool& worlds)
552552
if (dungeon.isRequiredDungeon)
553553
{
554554
settings.setRequiredBoss(dungeon.raceModeLocation->getName(), true);
555+
dungeon.raceModeLocation->isRequiredRaceModeLocation = true;
555556
}
556557
}
557558
}

0 commit comments

Comments
 (0)