Skip to content

Commit e987ec7

Browse files
committed
Type Clarity
- Replace a couple "auto" types with their names for clarity (especially when making a copy) - More const - Some more references when we don't need a separate copy
1 parent f89189e commit e987ec7

4 files changed

Lines changed: 18 additions & 19 deletions

File tree

logic/Fill.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static FillError fastFill(ItemPool& items, LocationPool& locations)
4242

4343
while (!items.empty() && !locations.empty())
4444
{
45-
auto item = popRandomElement(items);
45+
Item item = popRandomElement(items);
4646
auto location = popRandomElement(locations);
4747
location->currentItem = item;
4848
LOG_TO_DEBUG("Placed " + item.getName() + " at " + location->getName() + " in world " + std::to_string(location->world->getWorldId() + 1));
@@ -294,9 +294,9 @@ void placeVanillaItems(WorldPool& worlds)
294294
// Place vanilla items depending on settings and remove placed vanilla items from the item pool
295295
for (auto location : world.getLocations())
296296
{
297-
const auto vanillaItem = location->originalItem;
298-
const auto& vanillaItemName = vanillaItem.getName();
299-
const auto locationName = location->getName();
297+
const Item& vanillaItem = location->originalItem;
298+
const std::string& vanillaItemName = vanillaItem.getName();
299+
const std::string& locationName = location->getName();
300300

301301
if ((settings.dungeon_small_keys == PlacementOption::Vanilla && vanillaItem.isSmallKey()) ||
302302
(settings.dungeon_big_keys == PlacementOption::Vanilla && vanillaItem.isBigKey()) ||

logic/Hints.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static HintError calculatePossiblePathLocations(WorldPool& worlds)
5656
{
5757
for (auto& potentialPathLocation : world.getLocations(true))
5858
{
59-
auto itemAtLocation = potentialPathLocation->currentItem;
59+
const Item itemAtLocation = potentialPathLocation->currentItem;
6060
if (itemAtLocation.isJunkItem())
6161
{
6262
continue;
@@ -143,7 +143,7 @@ static HintError calculatePossibleBarrenRegions(WorldPool& worlds)
143143
// For the purposes of barren hints, if a major item cannot possibly lead to any
144144
// required items, then it will not block the region it's in from being considered
145145
// barren.
146-
auto chainLocations = location->currentItem.getChainLocations();
146+
const auto& chainLocations = location->currentItem.getChainLocations();
147147
if (!chainLocations.empty())
148148
{
149149
// If all of this item's chain locations' are barren as chain locations, then this item is barren too.
@@ -199,8 +199,8 @@ static HintError calculatePossibleBarrenRegions(WorldPool& worlds)
199199
for (auto& locAccess : location->accessPoints)
200200
{
201201
auto area = locAccess->area;
202-
auto generalHintRegions = area->findHintRegions(/*onlyNonIslands = */true);
203-
auto islands = area->findIslands();
202+
const auto& generalHintRegions = area->findHintRegions(/*onlyNonIslands = */true);
203+
const auto& islands = area->findIslands();
204204
for (auto hintRegions : {generalHintRegions, islands})
205205
{
206206
for (auto& hintRegion : hintRegions)
@@ -351,8 +351,7 @@ static HintError generatePathHintLocations(World& world, std::list<Hint>& hints)
351351

352352
// Filter out known vanilla items, and expected items, and triforce shards if Ho Ho is hinting them
353353
filterAndEraseFromPool(possiblePathLocations, [settings = world.getSettings()](auto location){
354-
auto& item = location->currentItem;
355-
return (location->hasKnownVanillaItem || location->hasExpectedItem || (settings.ho_ho_triforce_hints && item.isTriforceShard()));
354+
return (location->hasKnownVanillaItem || location->hasExpectedItem || (settings.ho_ho_triforce_hints && location->currentItem.isTriforceShard()));
356355
});
357356

358357
auto hintLocation = getHintableLocation(possiblePathLocations);
@@ -721,7 +720,7 @@ static HintError assignHoHoHints(World& world, WorldPool& worlds, std::list<Hint
721720
auto location = hint.location;
722721
// Remove this item from the world and see which Ho Ho are available
723722
// to be hinted at
724-
auto itemAtLocation = location->currentItem;
723+
const Item itemAtLocation = location->currentItem;
725724
location->currentItem = Item(GameItem::INVALID, &world);
726725

727726
// Find all accessible locations without the item

logic/Location.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ bool Location::isBarrenAsChainLocation() const
192192

193193
std::u16string Location::generateImportanceText(const std::string& language)
194194
{
195-
auto& item = currentItem;
195+
const Item& item = currentItem;
196196

197197
std::u16string required = u"required";
198198
std::u16string possiblyRequired = u"possibly required";
@@ -230,7 +230,7 @@ std::u16string Location::generateImportanceText(const std::string& language)
230230
}
231231

232232
// If this item is on the path to Ganondorf, then it is required
233-
auto& requiredLocations = world->locationTable["Ganon's Tower - Defeat Ganondorf"]->pathLocations;
233+
const auto& requiredLocations = world->locationTable["Ganon's Tower - Defeat Ganondorf"]->pathLocations;
234234
if (elementInPool(this, requiredLocations))
235235
{
236236
return u" (" + TEXT_COLOR_GREEN + required + TEXT_COLOR_DEFAULT + u")";

logic/Search.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ LocationPool search(const SearchMode& searchMode, WorldPool& worlds, ItemPool it
266266
for (auto location : accessibleThisIteration)
267267
{
268268
accessibleLocations.push_back(location);
269-
const auto& item = location->currentItem;
269+
const Item& item = location->currentItem;
270270
if (item.getGameItemId() != GameItem::INVALID && !item.isJunkItem())
271271
{
272272
ownedItems.emplace(item);
@@ -335,23 +335,23 @@ static void pareDownPlaythrough(WorldPool& worlds)
335335

336336
for (auto& sphere : playthroughSpheres)
337337
{
338-
for (auto loc = sphere.begin(); loc != sphere.end(); )
338+
for (auto locIt = sphere.begin(); locIt != sphere.end(); )
339339
{
340340
// Remove the item at the current location and check if the game is still beatable
341-
auto location = *loc;
342-
auto itemAtLocation = location->currentItem;
341+
auto location = *locIt;
342+
const Item itemAtLocation = location->currentItem;
343343
location->currentItem = {GameItem::INVALID, location->world};
344344
if (gameBeatable(worlds))
345345
{
346346
// If the game is still beatable, then this location is not required
347347
// and we can erase it from the playthrough
348-
loc = sphere.erase(loc);
348+
locIt = sphere.erase(locIt);
349349
nonRequiredLocations.insert({location, itemAtLocation});
350350
}
351351
else
352352
{
353353
location->currentItem = itemAtLocation;
354-
loc++; // Only increment if we don't erase
354+
locIt++; // Only increment if we don't erase
355355
}
356356
}
357357
}

0 commit comments

Comments
 (0)