From f51de6d86a5cac27871e94c9918f58cc88ae921d Mon Sep 17 00:00:00 2001 From: Nick Stefan Date: Tue, 9 Jul 2024 23:33:03 -0600 Subject: [PATCH] do regular swap when baseFormID1,baseFormID2|swapFormID|etc value set util build clean up build --- src/SwapData.cpp | 40 +++++++++++++++++++++++++--------------- src/Util.cpp | 2 ++ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/SwapData.cpp b/src/SwapData.cpp index 3871562..6e0713e 100644 --- a/src/SwapData.cpp +++ b/src/SwapData.cpp @@ -94,27 +94,37 @@ namespace FormSwap } } else if (const auto baseFormIDs = util::GetFormIDOrderedSet(formPair[0]); !baseFormIDs.empty()) { if (auto swapFormIDs = util::GetFormIDOrderedSet(formPair[1]); !swapFormIDs.empty()) { - if (baseFormIDs.size() > swapFormIDs.size()) { - logger::error("\t\t\t\tfail : [{}] (SWAP formID set must be equal or larger than BASE formID set)", a_str); - return; - } auto properties = formPair.size() > 2 ? formPair[2] : std::string{}; auto chance = formPair.size() > 3 ? formPair[3] : std::string{}; - auto a_chance = Chance(chance); - auto a_rng = BOS_RNG(a_chance); - - // randomly assign each baseFormID to a unique swapFormID - for (auto itBaseFormID : baseFormIDs) { - const auto setEnd = std::distance(swapFormIDs.begin(), swapFormIDs.end()) - 1; - const auto randIt = a_rng.generate(0, setEnd); - auto swapFormID = swapFormIDs.extract(*std::next(swapFormIDs.begin(), randIt)); - if (swapFormID) { - const Input input(properties, std::string{}, a_str, a_path); - SwapFormData swapFormData(swapFormID.value(), input); + // assign each baseFormID the same swapFormID + if (swapFormIDs.size() == 1) { + auto swapFormID = *(swapFormIDs.begin()); + for (auto itBaseFormID : baseFormIDs) { + const Input input(properties, chance, a_str, a_path); + SwapFormData swapFormData(swapFormID, input); a_func(itBaseFormID, swapFormData); } + + // randomly assign each baseFormID to a unique swapFormID + } else if (swapFormIDs.size() >= baseFormIDs.size()) { + auto a_chance = Chance(chance); + auto a_rng = BOS_RNG(a_chance); + + for (auto itBaseFormID : baseFormIDs) { + const auto setEnd = std::distance(swapFormIDs.begin(), swapFormIDs.end()) - 1; + const auto randIt = a_rng.generate(0, setEnd); + auto swapFormID = swapFormIDs.extract(*std::next(swapFormIDs.begin(), randIt)); + if (swapFormID) { + const Input input(properties, std::string{}, a_str, a_path); + SwapFormData swapFormData(swapFormID.value(), input); + + a_func(itBaseFormID, swapFormData); + } + } + } else { + logger::error("\t\t\t\tfail : [{}] (SWAP formIDSet.size() must be 1 OR equal/greater than BASE formIDSet.size())", a_str); } } else { logger::error("\t\t\t\tfail : [{}] (SWAP formID set not found)", a_str); diff --git a/src/Util.cpp b/src/Util.cpp index d54039c..7eea24c 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -69,6 +69,8 @@ namespace util } } return set; + } else if (auto formID = GetFormID(a_str); formID != 0) { + set.emplace(formID); } return set; }