summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Dubé <159546+serprex@users.noreply.github.com>2026-07-20 13:31:22 +0000
committerGitHub <noreply@github.com>2026-07-20 13:31:22 +0000
commit29285ed200345a8202cb2ac79af1bda1b095e834 (patch)
treeba86ef43664b03a0b14aa3c1393d3c1e36d924df
parenta236e9ec84fb8b49443e6a167aeda6f98cb8c7fe (diff)
Move AddElementsToPool/ElementInContainer to ShipUtils as generic utilities (#6948)
-rw-r--r--soh/soh/Enhancements/Presets/Presets.cpp3
-rw-r--r--soh/soh/Enhancements/custom-message/CustomMessageManager.cpp11
-rw-r--r--soh/soh/Enhancements/debugger/actorViewer.cpp2
-rw-r--r--soh/soh/Enhancements/mod_menu.cpp4
-rw-r--r--soh/soh/Enhancements/randomizer/3drando/fill.cpp39
-rw-r--r--soh/soh/Enhancements/randomizer/3drando/pool_functions.hpp8
-rw-r--r--soh/soh/Enhancements/randomizer/3drando/starting_inventory.cpp3
-rw-r--r--soh/soh/Enhancements/randomizer/entrance.cpp46
-rw-r--r--soh/soh/util.h11
9 files changed, 65 insertions, 62 deletions
diff --git a/soh/soh/Enhancements/Presets/Presets.cpp b/soh/soh/Enhancements/Presets/Presets.cpp
index d3c75c391..2e2294d83 100644
--- a/soh/soh/Enhancements/Presets/Presets.cpp
+++ b/soh/soh/Enhancements/Presets/Presets.cpp
@@ -106,8 +106,7 @@ void applyPreset(std::string presetName, std::vector<PresetSection> includeSecti
auto& info = presets[presetName];
for (int i = PRESET_SECTION_SETTINGS; i < PRESET_SECTION_MAX; i++) {
if (info.apply[i] && info.presetValues["blocks"].contains(blockInfo[i].names[1])) {
- if (!includeSections.empty() &&
- std::find(includeSections.begin(), includeSections.end(), i) == includeSections.end()) {
+ if (!includeSections.empty() && !SohUtils::Contains(i, includeSections)) {
continue;
}
if (i == PRESET_SECTION_TRACKERS) {
diff --git a/soh/soh/Enhancements/custom-message/CustomMessageManager.cpp b/soh/soh/Enhancements/custom-message/CustomMessageManager.cpp
index 3e5d62b1c..bddadf53b 100644
--- a/soh/soh/Enhancements/custom-message/CustomMessageManager.cpp
+++ b/soh/soh/Enhancements/custom-message/CustomMessageManager.cpp
@@ -218,12 +218,9 @@ void CustomMessage::SetTextBoxPosition(TextBoxPosition boxPos) {
CustomMessage CustomMessage::operator+(const CustomMessage& right) const {
std::vector<std::string> newColors = colors;
- const std::vector<std::string>& rColors = right.GetColors();
- for (const auto& color : rColors) {
- newColors.push_back(color);
- }
+ SohUtils::AppendVector(newColors, right.GetColors());
std::vector<bool> newCapital = capital;
- newCapital.insert(newCapital.end(), right.GetCapital().begin(), right.GetCapital().end());
+ SohUtils::AppendVector(newCapital, right.GetCapital());
return CustomMessage(messages[LANGUAGE_ENG] + right.GetEnglish(MF_RAW),
messages[LANGUAGE_GER] + right.GetGerman(MF_RAW),
messages[LANGUAGE_FRA] + right.GetFrench(MF_RAW), newColors, newCapital, type, position);
@@ -238,8 +235,8 @@ void CustomMessage::operator+=(const CustomMessage& right) {
messages[LANGUAGE_ENG] += right.GetEnglish(MF_RAW);
messages[LANGUAGE_GER] += right.GetGerman(MF_RAW);
messages[LANGUAGE_FRA] += right.GetFrench(MF_RAW);
- colors.insert(colors.end(), right.GetColors().begin(), right.GetColors().end());
- capital.insert(capital.end(), right.GetCapital().begin(), right.GetCapital().end());
+ SohUtils::AppendVector(colors, right.GetColors());
+ SohUtils::AppendVector(capital, right.GetCapital());
}
void CustomMessage::operator+=(const std::string& right) {
diff --git a/soh/soh/Enhancements/debugger/actorViewer.cpp b/soh/soh/Enhancements/debugger/actorViewer.cpp
index 07efb890f..79f730a24 100644
--- a/soh/soh/Enhancements/debugger/actorViewer.cpp
+++ b/soh/soh/Enhancements/debugger/actorViewer.cpp
@@ -1097,7 +1097,7 @@ void ActorViewerWindow::DrawElement() {
PushStyleInput(THEME_COLOR);
ImGui::InputScalar("params", ImGuiDataType_S16, &newActor.params, &one);
PopStyleInput();
- } else if (std::find(noParamsActors.begin(), noParamsActors.end(), newActor.id) == noParamsActors.end()) {
+ } else if (!SohUtils::Contains(newActor.id, noParamsActors)) {
CreateActorSpecificData();
if (actorSpecificData.find(newActor.id) == actorSpecificData.end()) {
PushStyleInput(THEME_COLOR);
diff --git a/soh/soh/Enhancements/mod_menu.cpp b/soh/soh/Enhancements/mod_menu.cpp
index 84280ac19..7d1415281 100644
--- a/soh/soh/Enhancements/mod_menu.cpp
+++ b/soh/soh/Enhancements/mod_menu.cpp
@@ -8,6 +8,7 @@
#include "mod_menu.h"
#include "soh/OTRGlobals.h"
+#include "soh/util.h"
#include "soh/SohGui/MenuTypes.h"
#include "soh/SohGui/SohMenu.h"
#include "soh/SohGui/SohGui.hpp"
@@ -225,8 +226,7 @@ void UpdateModFiles(bool init = false, bool reset = false) {
if (!IsValidExtension(extension)) {
continue;
}
- bool enabled =
- std::find(enabledModFiles.begin(), enabledModFiles.end(), filename) != enabledModFiles.end();
+ bool enabled = SohUtils::Contains(filename, enabledModFiles);
if (!enabled) {
tempMods.emplace(p.path().lexically_normal().generic_string(), filename);
}
diff --git a/soh/soh/Enhancements/randomizer/3drando/fill.cpp b/soh/soh/Enhancements/randomizer/3drando/fill.cpp
index 132b13f9f..623c1fa6d 100644
--- a/soh/soh/Enhancements/randomizer/3drando/fill.cpp
+++ b/soh/soh/Enhancements/randomizer/3drando/fill.cpp
@@ -10,6 +10,7 @@
#include "pool_functions.hpp"
#include "soh/Enhancements/randomizer/static_data.h"
#include "soh/Enhancements/debugger/performanceTimer.h"
+#include "soh/util.h"
#include <vector>
#include <list>
@@ -1077,13 +1078,13 @@ static void RandomizeOwnDungeon(const Rando::DungeonInfo* dungeon) {
FilterAndEraseFromPool(itemPool, [dungeon](const RandomizerGet i) {
return (i == dungeon->GetSmallKey()) || (i == dungeon->GetKeyRing());
});
- AddElementsToPool(dungeonItems, dungeonSmallKeys);
+ SohUtils::AppendVector(dungeonItems, dungeonSmallKeys);
}
if (ctx->GetOption(RSK_SHUFFLE_DUNGEON_REWARDS).Is(RO_DUNGEON_REWARDS_OWN_DUNGEON) &&
dungeon->GetReward() != RG_NONE) {
std::vector<RandomizerGet> dungeonReward =
FilterAndEraseFromPool(itemPool, [dungeon](const RandomizerGet i) { return (i == dungeon->GetReward()); });
- AddElementsToPool(dungeonItems, dungeonReward);
+ SohUtils::AppendVector(dungeonItems, dungeonReward);
}
if ((ctx->GetOption(RSK_BOSS_KEYSANITY).Is(RO_DUNGEON_ITEM_LOC_OWN_DUNGEON) &&
@@ -1092,7 +1093,7 @@ static void RandomizeOwnDungeon(const Rando::DungeonInfo* dungeon) {
dungeon->GetBossKey() == RG_GANONS_CASTLE_BOSS_KEY)) {
auto dungeonBossKey =
FilterAndEraseFromPool(itemPool, [dungeon](const RandomizerGet i) { return i == dungeon->GetBossKey(); });
- AddElementsToPool(dungeonItems, dungeonBossKey);
+ SohUtils::AppendVector(dungeonItems, dungeonBossKey);
}
// randomize boss key, small keys, and rewards together for even distribution
@@ -1131,75 +1132,75 @@ static void RandomizeDungeonItems() {
auto dungeonKeys = FilterAndEraseFromPool(itemPool, [dungeon](const RandomizerGet i) {
return (i == dungeon->GetSmallKey()) || (i == dungeon->GetKeyRing());
});
- AddElementsToPool(anyDungeonItems, dungeonKeys);
+ SohUtils::AppendVector(anyDungeonItems, dungeonKeys);
} else if (ctx->GetOption(RSK_KEYSANITY).Is(RO_DUNGEON_ITEM_LOC_OVERWORLD)) {
auto dungeonKeys = FilterAndEraseFromPool(itemPool, [dungeon](const RandomizerGet i) {
return (i == dungeon->GetSmallKey()) || (i == dungeon->GetKeyRing());
});
- AddElementsToPool(overworldItems, dungeonKeys);
+ SohUtils::AppendVector(overworldItems, dungeonKeys);
}
if (ctx->GetOption(RSK_BOSS_KEYSANITY).Is(RO_DUNGEON_ITEM_LOC_ANY_DUNGEON) &&
dungeon->GetBossKey() != RG_GANONS_CASTLE_BOSS_KEY) {
auto bossKey = FilterAndEraseFromPool(
itemPool, [dungeon](const RandomizerGet i) { return i == dungeon->GetBossKey(); });
- AddElementsToPool(anyDungeonItems, bossKey);
+ SohUtils::AppendVector(anyDungeonItems, bossKey);
} else if (ctx->GetOption(RSK_BOSS_KEYSANITY).Is(RO_DUNGEON_ITEM_LOC_OVERWORLD) &&
dungeon->GetBossKey() != RG_GANONS_CASTLE_BOSS_KEY) {
auto bossKey = FilterAndEraseFromPool(
itemPool, [dungeon](const RandomizerGet i) { return i == dungeon->GetBossKey(); });
- AddElementsToPool(overworldItems, bossKey);
+ SohUtils::AppendVector(overworldItems, bossKey);
}
if (ctx->GetOption(RSK_GANONS_BOSS_KEY).Is(RO_GANON_BOSS_KEY_ANY_DUNGEON)) {
auto ganonBossKey =
FilterAndEraseFromPool(itemPool, [](const auto i) { return i == RG_GANONS_CASTLE_BOSS_KEY; });
- AddElementsToPool(anyDungeonItems, ganonBossKey);
+ SohUtils::AppendVector(anyDungeonItems, ganonBossKey);
} else if (ctx->GetOption(RSK_GANONS_BOSS_KEY).Is(RO_GANON_BOSS_KEY_OVERWORLD)) {
auto ganonBossKey =
FilterAndEraseFromPool(itemPool, [](const auto i) { return i == RG_GANONS_CASTLE_BOSS_KEY; });
- AddElementsToPool(overworldItems, ganonBossKey);
+ SohUtils::AppendVector(overworldItems, ganonBossKey);
}
}
if (ctx->GetOption(RSK_GANONS_SOUL).Is(RO_GANONS_SOUL_ANY_DUNGEON)) {
auto ganonSoul = FilterAndEraseFromPool(itemPool, [](const auto i) { return i == RG_GANON_SOUL; });
- AddElementsToPool(anyDungeonItems, ganonSoul);
+ SohUtils::AppendVector(anyDungeonItems, ganonSoul);
} else if (ctx->GetOption(RSK_GANONS_SOUL).Is(RO_GANONS_SOUL_OVERWORLD)) {
auto ganonSoul = FilterAndEraseFromPool(itemPool, [](const auto i) { return i == RG_GANON_SOUL; });
- AddElementsToPool(overworldItems, ganonSoul);
+ SohUtils::AppendVector(overworldItems, ganonSoul);
}
if (ctx->GetOption(RSK_GERUDO_KEYS).Is(RO_GERUDO_KEYS_ANY_DUNGEON)) {
auto gerudoKeys = FilterAndEraseFromPool(itemPool, [](const auto i) {
return i == RG_GERUDO_FORTRESS_SMALL_KEY || i == RG_GERUDO_FORTRESS_KEY_RING;
});
- AddElementsToPool(anyDungeonItems, gerudoKeys);
+ SohUtils::AppendVector(anyDungeonItems, gerudoKeys);
} else if (ctx->GetOption(RSK_GERUDO_KEYS).Is(RO_GERUDO_KEYS_OVERWORLD)) {
auto gerudoKeys = FilterAndEraseFromPool(itemPool, [](const auto i) {
return i == RG_GERUDO_FORTRESS_SMALL_KEY || i == RG_GERUDO_FORTRESS_KEY_RING;
});
- AddElementsToPool(overworldItems, gerudoKeys);
+ SohUtils::AppendVector(overworldItems, gerudoKeys);
}
if (ctx->GetOption(RSK_SHUFFLE_DUNGEON_REWARDS).Is(RO_DUNGEON_REWARDS_ANY_DUNGEON)) {
auto rewards = FilterAndEraseFromPool(itemPool, [](const auto i) {
return Rando::StaticData::RetrieveItem(i).GetItemType() == ITEMTYPE_DUNGEONREWARD;
});
- AddElementsToPool(anyDungeonItems, rewards);
+ SohUtils::AppendVector(anyDungeonItems, rewards);
} else if (ctx->GetOption(RSK_SHUFFLE_DUNGEON_REWARDS).Is(RO_DUNGEON_REWARDS_OVERWORLD)) {
auto rewards = FilterAndEraseFromPool(itemPool, [](const auto i) {
return Rando::StaticData::RetrieveItem(i).GetItemType() == ITEMTYPE_DUNGEONREWARD;
});
- AddElementsToPool(overworldItems, rewards);
+ SohUtils::AppendVector(overworldItems, rewards);
}
if (ctx->GetOption(RSK_TRIFORCE_HUNT_PIECES_LOCATION).Is(RO_TRIFORCE_HUNT_LOCATION_ANY_DUNGEON)) {
auto triforcePieces = FilterAndEraseFromPool(itemPool, [](const auto i) { return i == RG_TRIFORCE_PIECE; });
- AddElementsToPool(anyDungeonItems, triforcePieces);
+ SohUtils::AppendVector(anyDungeonItems, triforcePieces);
} else if (ctx->GetOption(RSK_TRIFORCE_HUNT_PIECES_LOCATION).Is(RO_TRIFORCE_HUNT_LOCATION_OVERWORLD)) {
auto triforcePieces = FilterAndEraseFromPool(itemPool, [](const auto i) { return i == RG_TRIFORCE_PIECE; });
- AddElementsToPool(overworldItems, triforcePieces);
+ SohUtils::AppendVector(overworldItems, triforcePieces);
}
// Randomize Any Dungeon and Overworld pools
@@ -1233,7 +1234,7 @@ static void RandomizeLinksPocket() {
// select a random one
RandomizerGet startingItem = RandomElement(advancementItems, true);
// add the others back
- AddElementsToPool(itemPool, advancementItems);
+ SohUtils::AppendVector(itemPool, advancementItems);
ctx->PlaceItemInLocation(RC_LINKS_POCKET, startingItem);
} else if (ctx->GetOption(RSK_LINKS_POCKET).Is(RO_LINKS_POCKET_NOTHING)) {
@@ -1290,7 +1291,7 @@ int Fill() {
// Temporarily add shop items to the itemPool so that entrance randomization
// can validate the world using deku/hylian shields
StartPerformanceTimer(PT_ENTRANCE_SHUFFLE);
- AddElementsToPool(itemPool, GetMinVanillaShopItems(8)); // assume worst case shopsanity 7
+ SohUtils::AppendVector(itemPool, GetMinVanillaShopItems(8)); // assume worst case shopsanity 7
if (ctx->GetOption(RSK_SHUFFLE_ENTRANCES)) {
SPDLOG_INFO("Shuffling Entrances...");
if (ctx->GetEntranceShuffler()->ShuffleAllEntrances() == ENTRANCE_SHUFFLE_FAILURE) {
diff --git a/soh/soh/Enhancements/randomizer/3drando/pool_functions.hpp b/soh/soh/Enhancements/randomizer/3drando/pool_functions.hpp
index 2a93f40c3..27479c13e 100644
--- a/soh/soh/Enhancements/randomizer/3drando/pool_functions.hpp
+++ b/soh/soh/Enhancements/randomizer/3drando/pool_functions.hpp
@@ -16,11 +16,3 @@ std::vector<T> FilterAndEraseFromPool(std::vector<T>& vector, Predicate pred) {
std::erase_if(vector, pred);
return filtered;
}
-
-template <typename T, typename FromPool> void AddElementsToPool(std::vector<T>& toPool, const FromPool& fromPool) {
- toPool.insert(toPool.end(), std::cbegin(fromPool), std::cend(fromPool));
-}
-
-template <typename T, typename Container> bool ElementInContainer(T& element, const Container& container) {
- return std::find(container.begin(), container.end(), element) != container.end();
-}
diff --git a/soh/soh/Enhancements/randomizer/3drando/starting_inventory.cpp b/soh/soh/Enhancements/randomizer/3drando/starting_inventory.cpp
index 65ff7a513..d48c071bf 100644
--- a/soh/soh/Enhancements/randomizer/3drando/starting_inventory.cpp
+++ b/soh/soh/Enhancements/randomizer/3drando/starting_inventory.cpp
@@ -5,6 +5,7 @@
#include "../logic.h"
#include "pool_functions.hpp"
#include "soh/Enhancements/randomizer/static_data.h"
+#include "soh/util.h"
std::vector<RandomizerGet> StartingInventory;
uint8_t AdditionalHeartContainers;
@@ -158,7 +159,7 @@ void GenerateStartingInventory() {
bool StartingInventoryHasBottle() {
RandomizerGet bottle = RG_EMPTY_BOTTLE;
- return ElementInContainer(bottle, StartingInventory);
+ return SohUtils::Contains(bottle, StartingInventory);
}
void ApplyStartingInventory() {
diff --git a/soh/soh/Enhancements/randomizer/entrance.cpp b/soh/soh/Enhancements/randomizer/entrance.cpp
index c66617bbc..6340d9682 100644
--- a/soh/soh/Enhancements/randomizer/entrance.cpp
+++ b/soh/soh/Enhancements/randomizer/entrance.cpp
@@ -6,6 +6,7 @@
#include "rng.h"
#include "../debugger/performanceTimer.h"
#include "soh/Enhancements/gameconsole.h"
+#include "soh/util.h"
#include "z64camera.h"
#include "z64scene.h"
@@ -653,13 +654,13 @@ BuildOneWayTargets(std::vector<EntranceType> typesToInclude,
std::vector<Entrance*> oneWayEntrances = {};
// Get all entrances of the specified type
for (EntranceType poolType : typesToInclude) {
- AddElementsToPool(oneWayEntrances, GetShuffleableEntrances(poolType, false));
+ SohUtils::AppendVector(oneWayEntrances, GetShuffleableEntrances(poolType, false));
}
// Filter out any that are passed in the exclusion list
std::erase_if(oneWayEntrances, [&exclude](Entrance* entrance) {
std::pair<RandomizerRegion, RandomizerRegion> entranceBeingChecked(entrance->GetParentRegionKey(),
entrance->GetConnectedRegionKey());
- return ElementInContainer(entranceBeingChecked, exclude);
+ return SohUtils::Contains(entranceBeingChecked, exclude);
});
// The code below is part of the function in ootr, but no use of the function ever provides target_region_names
@@ -729,7 +730,7 @@ static bool AreEntrancesCompatible(Entrance* entrance, Entrance* target, std::ve
auto type = entrance->GetType();
const std::array<EntranceType, 3> oneWayTypes = { EntranceType::OwlDrop, EntranceType::Spawn,
EntranceType::WarpSong };
- if (ElementInContainer(type, oneWayTypes)) {
+ if (SohUtils::Contains(type, oneWayTypes)) {
for (auto& rollback : rollbacks) {
if (rollback.first->GetConnectedRegion()->scene == target->GetConnectedRegion()->scene) {
SPDLOG_DEBUG("A one way entrance already leads to {}. Connection failed.", target->to_string());
@@ -781,7 +782,7 @@ static bool EntranceUnreachableAs(Entrance* entrance, uint8_t age, std::vector<E
for (Entrance* parentEntrance : parentEntrances) {
// if parentEntrance is in alreadyChecked, then continue
- if (ElementInContainer(parentEntrance, alreadyChecked)) {
+ if (SohUtils::Contains(parentEntrance, alreadyChecked)) {
continue;
}
@@ -839,11 +840,11 @@ static bool ValidateWorld(Entrance* entrancePlaced) {
auto replacementName = entrance->GetReplacement()->GetName();
alreadyChecked.push_back(entrance->GetReplacement()->GetReverse());
- if (ElementInContainer(replacementName, childForbidden) &&
+ if (SohUtils::Contains(replacementName, childForbidden) &&
!EntranceUnreachableAs(entrance, RO_AGE_CHILD, alreadyChecked)) {
SPDLOG_DEBUG("{} is replaced by an entrance with a potential child access", replacementName);
return false;
- } else if (ElementInContainer(replacementName, adultForbidden) &&
+ } else if (SohUtils::Contains(replacementName, adultForbidden) &&
!EntranceUnreachableAs(entrance, RO_AGE_ADULT, alreadyChecked)) {
SPDLOG_DEBUG("{} is replaced by an entrance with a potential adult access", replacementName);
return false;
@@ -853,11 +854,11 @@ static bool ValidateWorld(Entrance* entrancePlaced) {
auto name = entrance->GetName();
alreadyChecked.push_back(entrance->GetReverse());
- if (ElementInContainer(name, childForbidden) &&
+ if (SohUtils::Contains(name, childForbidden) &&
!EntranceUnreachableAs(entrance, RO_AGE_CHILD, alreadyChecked)) {
SPDLOG_DEBUG("{} is potentially accessible as child", name);
return false;
- } else if (ElementInContainer(name, adultForbidden) &&
+ } else if (SohUtils::Contains(name, adultForbidden) &&
!EntranceUnreachableAs(entrance, RO_AGE_ADULT, alreadyChecked)) {
SPDLOG_DEBUG("{} is potentially accessible as adult");
return false;
@@ -968,8 +969,8 @@ bool EntranceShuffler::PlaceOneWayPriorityEntrance(
std::vector<Entrance*> availPool = {};
for (auto& pool : oneWayEntrancePools) {
auto entranceType = pool.first;
- if (ElementInContainer(entranceType, allowedTypes)) {
- AddElementsToPool(availPool, pool.second);
+ if (SohUtils::Contains(entranceType, allowedTypes)) {
+ SohUtils::AppendVector(availPool, pool.second);
}
}
Shuffle(availPool);
@@ -993,7 +994,7 @@ bool EntranceShuffler::PlaceOneWayPriorityEntrance(
}
for (Entrance* target : oneWayTargetEntrancePools[entrance->GetType()]) {
RandomizerRegion targetRegionKey = target->GetConnectedRegionKey();
- if (targetRegionKey != RR_NONE && ElementInContainer(targetRegionKey, allowedRegions)) {
+ if (targetRegionKey != RR_NONE && SohUtils::Contains(targetRegionKey, allowedRegions)) {
if (ReplaceEntrance(entrance, target, rollbacks)) {
// Return once the entrance has been replaced
return true;
@@ -1241,9 +1242,10 @@ int EntranceShuffler::ShuffleAllEntrances() {
if (ctx->GetOption(RSK_SHUFFLE_BOSS_ENTRANCES).IsNot(RO_BOSS_ROOM_ENTRANCE_SHUFFLE_OFF)) {
if (ctx->GetOption(RSK_SHUFFLE_BOSS_ENTRANCES).Is(RO_BOSS_ROOM_ENTRANCE_SHUFFLE_FULL)) {
entrancePools[EntranceType::Boss] = GetShuffleableEntrances(EntranceType::ChildBoss);
- AddElementsToPool(entrancePools[EntranceType::Boss], GetShuffleableEntrances(EntranceType::AdultBoss));
+ SohUtils::AppendVector(entrancePools[EntranceType::Boss], GetShuffleableEntrances(EntranceType::AdultBoss));
if (ctx->GetOption(RSK_SHUFFLE_GANONS_TOWER_ENTRANCE)) {
- AddElementsToPool(entrancePools[EntranceType::Boss], GetShuffleableEntrances(EntranceType::GanonTower));
+ SohUtils::AppendVector(entrancePools[EntranceType::Boss],
+ GetShuffleableEntrances(EntranceType::GanonTower));
}
if (ctx->GetOption(RSK_DECOUPLED_ENTRANCES)) {
@@ -1255,8 +1257,8 @@ int EntranceShuffler::ShuffleAllEntrances() {
entrancePools[EntranceType::ChildBoss] = GetShuffleableEntrances(EntranceType::ChildBoss);
entrancePools[EntranceType::AdultBoss] = GetShuffleableEntrances(EntranceType::AdultBoss);
if (ctx->GetOption(RSK_SHUFFLE_GANONS_TOWER_ENTRANCE)) {
- AddElementsToPool(entrancePools[EntranceType::AdultBoss],
- GetShuffleableEntrances(EntranceType::GanonTower));
+ SohUtils::AppendVector(entrancePools[EntranceType::AdultBoss],
+ GetShuffleableEntrances(EntranceType::GanonTower));
}
if (ctx->GetOption(RSK_DECOUPLED_ENTRANCES)) {
@@ -1275,8 +1277,8 @@ int EntranceShuffler::ShuffleAllEntrances() {
entrancePools[EntranceType::Dungeon] = GetShuffleableEntrances(EntranceType::Dungeon);
// Add Ganon's Castle, if set to On + Ganon
if (ctx->GetOption(RSK_SHUFFLE_DUNGEON_ENTRANCES).Is(RO_DUNGEON_ENTRANCE_SHUFFLE_ON_PLUS_GANON)) {
- AddElementsToPool(entrancePools[EntranceType::Dungeon],
- GetShuffleableEntrances(EntranceType::GanonDungeon));
+ SohUtils::AppendVector(entrancePools[EntranceType::Dungeon],
+ GetShuffleableEntrances(EntranceType::GanonDungeon));
}
if (ctx->GetOption(RSK_DECOUPLED_ENTRANCES)) {
for (Entrance* entrance : entrancePools[EntranceType::Dungeon]) {
@@ -1290,8 +1292,8 @@ int EntranceShuffler::ShuffleAllEntrances() {
entrancePools[EntranceType::Interior] = GetShuffleableEntrances(EntranceType::Interior);
// Special interiors
if (ctx->GetOption(RSK_SHUFFLE_INTERIOR_ENTRANCES).Is(RO_INTERIOR_ENTRANCE_SHUFFLE_ALL)) {
- AddElementsToPool(entrancePools[EntranceType::Interior],
- GetShuffleableEntrances(EntranceType::SpecialInterior));
+ SohUtils::AppendVector(entrancePools[EntranceType::Interior],
+ GetShuffleableEntrances(EntranceType::SpecialInterior));
}
if (ctx->GetOption(RSK_DECOUPLED_ENTRANCES)) {
for (Entrance* entrance : entrancePools[EntranceType::Interior]) {
@@ -1397,7 +1399,7 @@ int EntranceShuffler::ShuffleAllEntrances() {
auto type = pool.first;
if (poolsToMix.count(type) > 0) {
- AddElementsToPool(entrancePools[EntranceType::Mixed], pool.second);
+ SohUtils::AppendVector(entrancePools[EntranceType::Mixed], pool.second);
entrancePools[type].clear();
}
}
@@ -1476,7 +1478,7 @@ int EntranceShuffler::ShuffleAllEntrances() {
for (auto& pool : oneWayTargetEntrancePools) {
for (Entrance* remainingTarget : pool.second) {
auto replacement = remainingTarget->GetReplacement();
- if (ElementInContainer(replacement, replacedEntrances)) {
+ if (SohUtils::Contains(replacement, replacedEntrances)) {
DeleteTargetEntrance(remainingTarget);
}
}
@@ -1495,7 +1497,7 @@ int EntranceShuffler::ShuffleAllEntrances() {
for (auto& targetPool : oneWayTargetEntrancePools) {
for (Entrance* remainingTarget : targetPool.second) {
auto replacement = remainingTarget->GetReplacement();
- if (ElementInContainer(replacement, replacedEntrances)) {
+ if (SohUtils::Contains(replacement, replacedEntrances)) {
DeleteTargetEntrance(remainingTarget);
}
}
diff --git a/soh/soh/util.h b/soh/soh/util.h
index 2058a3442..0407d918a 100644
--- a/soh/soh/util.h
+++ b/soh/soh/util.h
@@ -2,6 +2,8 @@
#include <string>
#include <vector>
#include <stdint.h>
+#include <algorithm>
+#include <iterator>
typedef enum FileType { FILE_TYPE_SAVE_VANILLA, FILE_TYPE_SAVE_RANDO, FILE_TYPE_PRESET, FILE_TYPE_SPOILER } FileType;
@@ -28,4 +30,13 @@ bool IsStringEmpty(std::string str);
uint32_t Hash(std::string str);
std::vector<std::string> StringSplit(const std::string& str, const std::string& delimiter);
+
+template <typename T, typename Container> bool Contains(const T& element, const Container& container) {
+ return std::find(container.begin(), container.end(), element) != container.end();
+}
+
+template <typename T, typename FromContainer>
+void AppendVector(std::vector<T>& toVector, const FromContainer& fromContainer) {
+ toVector.insert(toVector.end(), std::cbegin(fromContainer), std::cend(fromContainer));
+}
} // namespace SohUtils