Skip to content

Commit

Permalink
Merged IndexOrCount into a single variant.
Browse files Browse the repository at this point in the history
  • Loading branch information
adya committed Mar 14, 2024
1 parent 1b99281 commit f944a82
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
13 changes: 3 additions & 10 deletions SPID/include/Distribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,8 @@ namespace Distribute

for (auto& formData : vec) {
if (!a_npcData.HasMutuallyExclusiveForm(formData.form) && detail::passed_filters(a_npcData, a_input, formData)) {
if constexpr (std::is_same_v<RE::TESBoundObject, Form>) {
if (a_callback(formData.form, formData.count.GetRandom())) {
++formData.npcCount;
}
} else {
if (a_callback(formData.form, formData.packageIndex)) {
++formData.npcCount;
}
}
a_callback(formData.form, formData.idxOrCount);
++formData.npcCount;
}
}
}
Expand Down Expand Up @@ -157,7 +150,7 @@ namespace Distribute
if (formData.form->Is(RE::FormType::LeveledItem)) {
hasLeveledItems = true;
}
collectedForms.emplace(formData.form, formData.count.GetRandom());
collectedForms.emplace(formData.form, formData.GetCount().GetRandom());
++formData.npcCount;
}
}
Expand Down
23 changes: 17 additions & 6 deletions SPID/include/FormData.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,20 @@ namespace Forms
{
std::uint32_t index{ 0 };

Form* form{ nullptr };
Index packageIndex{ 0 };
RandomCount count{ 1, 1 };
FilterData filters{};
Form* form{ nullptr };
IndexOrCount idxOrCount{ RandomCount(1, 1) };
FilterData filters{};

std::string path{};
std::uint32_t npcCount{ 0 };

bool operator==(const Data& a_rhs) const;

/// <summary>
/// Unsafely gets a RandomCount from idxOrCount.
/// Onlly call this method when you're sure that idxOrCount is a RandomCount.
/// </summary>
const RandomCount& GetCount() const;
};

template <class Form>
Expand Down Expand Up @@ -392,6 +397,12 @@ bool Forms::Data<Form>::operator==(const Data& a_rhs) const
return form->GetFormID() == a_rhs.form->GetFormID();
}

template <class Form>
const RandomCount& Forms::Data<Form>::GetCount() const
{
return std::get<RandomCount>(idxOrCount);
}

template <class Form>
Forms::Distributables<Form>::operator bool()
{
Expand Down Expand Up @@ -443,7 +454,7 @@ void Forms::Distributables<Form>::LookupForms(RE::TESDataHandler* a_dataHandler,
forms.reserve(a_INIDataVec.size());
std::uint32_t index = 0;

for (auto& [formOrEditorID, strings, filterIDs, level, traits, packageIndex, itemsCount, chance, path] : a_INIDataVec) {
for (auto& [formOrEditorID, strings, filterIDs, level, traits, idxOrCount, chance, path] : a_INIDataVec) {
try {
if (auto form = detail::get_form<Form>(a_dataHandler, formOrEditorID, path); form) {
FormFilters filterForms{};
Expand All @@ -457,7 +468,7 @@ void Forms::Distributables<Form>::LookupForms(RE::TESDataHandler* a_dataHandler,
}

if (validEntry) {
forms.emplace_back(index, form, packageIndex, itemsCount, FilterData(strings, filterForms, level, traits, chance), path);
forms.emplace_back(index, form, idxOrCount, FilterData(strings, filterForms, level, traits, chance), path);
index++;
}
}
Expand Down
3 changes: 1 addition & 2 deletions SPID/include/LookupConfigs.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ namespace INI
Filters<FormOrEditorID> rawFormFilters{};
LevelFilters levelFilters{};
Traits traits{};
Index index{ 0 };
RandomCount count{ 1, 1 };
IndexOrCount idxOrCount{ RandomCount(1, 1) };
Chance chance{ 100 };
std::string path{};
};
Expand Down
13 changes: 8 additions & 5 deletions SPID/src/LookupConfigs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,23 +246,26 @@ namespace INI
}

//ITEMCOUNT/INDEX
if (a_key == "Package") { // reuse item count for package stack index
data.idxOrCount = 0;
}

if (kIdxOrCount < size) {
if (a_key == "Package") { // reuse item count for package stack index
if (a_key == "Package") { // If it's a package, then we only expect a single number.
if (const auto& str = sections[kIdxOrCount]; distribution::is_valid_entry(str)) {
data.index = string::to_num<Index>(str);
data.idxOrCount = string::to_num<Index>(str);
}
} else {
if (const auto& str = sections[kIdxOrCount]; distribution::is_valid_entry(str)) {
if (auto countPair = string::split(str, "/"); countPair.size() > 1) {
if (auto countPair = string::split(str, "-"); countPair.size() > 1) {
auto minCount = string::to_num<Count>(countPair[0]);
auto maxCount = string::to_num<Count>(countPair[1]);

data.count = RandomCount(minCount, maxCount);
data.idxOrCount = RandomCount(minCount, maxCount);
} else {
auto count = string::to_num<Count>(str);

data.count = RandomCount(count, count); // create the exact match range.
data.idxOrCount = RandomCount(count, count); // create the exact match range.
}
}
}
Expand Down

0 comments on commit f944a82

Please sign in to comment.