Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions src/SwapData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::int64_t>(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<std::int64_t>(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);
Expand Down
2 changes: 2 additions & 0 deletions src/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ namespace util
}
}
return set;
} else if (auto formID = GetFormID(a_str); formID != 0) {
set.emplace(formID);
}
return set;
}
Expand Down