Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirdEyeSqueegee committed Sep 28, 2023
1 parent 478f3bb commit abc523d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ message("Using toolchain file ${CMAKE_TOOLCHAIN_FILE}.")
########################################################################################################################
project(
ContainerItemDistributor
VERSION 1.1.3
VERSION 1.1.4
LANGUAGES CXX
)
set(CMAKE_CXX_STANDARD 23)
Expand Down
16 changes: 8 additions & 8 deletions include/Maps.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ struct FormIDAndPluginName
class Maps : public Singleton<Maps>
{
public:
static int ToInt(const std::string_view& s) { return static_cast<int>(std::strtol(s.data(), nullptr, 0)); }
static auto ToInt(const std::string_view& s) { return static_cast<int>(std::strtol(s.data(), nullptr, 0)); }

static unsigned ToUnsignedInt(const std::string_view& s) { return static_cast<unsigned>(std::strtol(s.data(), nullptr, 0)); }
static auto ToUnsignedInt(const std::string_view& s) { return static_cast<unsigned>(std::strtol(s.data(), nullptr, 0)); }

static std::size_t GetPos(const std::string_view s, const char c)
static auto GetPos(const std::string_view s, const char c)
{
const auto ptr{ std::strrchr(s.data(), c) };

Expand Down Expand Up @@ -116,9 +116,9 @@ inline auto format_as(const DistrObject& obj)
return fmt::format("[Type: {} / Filename: {} / Bound object: {} (0x{:x}) / Leveled list: {} (0x{:x} / Replace with obj: {} (0x{:x}) / Replace with list: {} (0x{:x}) "
"/ Count: {} / Replace count: {} / Container: {} (0x{:x}) ({})]",
type, filename, bound_object ? bound_object->GetName() : "null", bound_object ? bound_object->GetFormID() : 0,
leveled_list ? leveled_list->GetName() : "null", leveled_list ? leveled_list->GetFormID() : 0, replace_with_obj ? replace_with_obj->GetName() : "null",
replace_with_obj ? replace_with_obj->GetFormID() : 0, replace_with_list ? replace_with_list->GetName() : "null",
replace_with_list ? replace_with_list->GetFormID() : 0, count.value_or(-1), replace_with_count.value_or(-1),
container.has_value() ? container.value().container_name : "null", container.has_value() ? container.value().container_form_id : 0,
container.has_value() ? container->container_type : RE::FormType::Container);
leveled_list ? leveled_list->GetFormEditorID() : "null", leveled_list ? leveled_list->GetFormID() : 0,
replace_with_obj ? replace_with_obj->GetName() : "null", replace_with_obj ? replace_with_obj->GetFormID() : 0,
replace_with_list ? replace_with_list->GetName() : "null", replace_with_list ? replace_with_list->GetFormID() : 0, count.value_or(-1),
replace_with_count.value_or(-1), container.has_value() ? container.value().container_name : "null",
container.has_value() ? container.value().container_form_id : 0, container.has_value() ? container->container_type : RE::FormType::Container);
}
20 changes: 19 additions & 1 deletion include/Utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Utility : public Singleton<Utility>
{
static bool IsEditorID(const std::string_view identifier) { return std::strchr(identifier.data(), '~') == nullptr; }
static auto IsEditorID(const std::string_view identifier) { return std::strchr(identifier.data(), '~') == nullptr; }

static FormIDAndPluginName GetFormIDAndPluginName(const std::string_view identifier)
{
Expand Down Expand Up @@ -76,7 +76,25 @@ class Utility : public Singleton<Utility>
return { nullptr, 0, RE::FormType::Container, "" };
}

inline static std::uint16_t player_level{};

public:
static auto CachePlayerLevel() { player_level = RE::PlayerCharacter::GetSingleton()->GetLevel(); }

static auto ResolveLeveledList(RE::TESLevItem* list)
{
RE::BSScrapArray<RE::CALCED_OBJECT> calced_objects{};
list->CalculateCurrentFormList(player_level, 1, calced_objects, 0, true);

std::vector<std::pair<RE::TESBoundObject*, int>> obj_and_counts{};
for (const auto& [form, count, pad0A, pad0C, containerItem] : calced_objects) {
if (const auto bound_obj{form->As<RE::TESBoundObject>()})
obj_and_counts.emplace_back(bound_obj, count);
}

return obj_and_counts;
}

static DistrObject BuildDistrObject(const DistrToken& distr_token) noexcept
{
if (const auto leveled_list{ GetLevItem(distr_token.identifier) }) {
Expand Down
6 changes: 2 additions & 4 deletions src/Conflicts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ void Conflicts::PrepareDistribution() noexcept
PrepareDistributionImpl(Maps::remove_conflict_test_map);
PrepareDistributionImpl(Maps::replace_conflict_test_map);

Utility::CachePlayerLevel();

const auto elapsed{ std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - start_time) };
logger::info("");
logger::info(">-------------------------Finished preparing distribution in {} us-------------------------<", elapsed.count());
Expand All @@ -37,16 +39,12 @@ void Conflicts::PrepareDistributionImpl(const Maps::TConflictTestMap& test_map)
const auto& winning{ matching.back() };
logger::info("\t{} wins for {}", winning.filename, distr_token);
result = Utility::BuildDistrObject(winning);
if (!result.bound_object)
return;
Maps::distr_object_vec.emplace_back(result);
const auto& [ret, last]{ std::ranges::remove_if(distr_token_vec, [&](const DistrToken& d) { return d.identifier <=> identifier == 0; }) };
distr_token_vec.erase(ret, last);
}
else {
result = Utility::BuildDistrObject(distr_token);
if (!result.bound_object)
return;
Maps::distr_object_vec.emplace_back(result);
}
}
Expand Down
18 changes: 12 additions & 6 deletions src/Distributor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ void Distributor::AddDistribute(const Maps::TDistrVec& distr_vec) noexcept
const auto& [cont, cont_form_id, cont_type, cont_name]{ container.value() };
if (bound_object)
cont->AddObjectToContainer(bound_object, count.value(), nullptr);
else if (leveled_list)
cont->AddObjectToContainer(leveled_list, count.value(), nullptr);
else if (leveled_list) {
for (const auto& [lobj, lcount] : Utility::ResolveLeveledList(leveled_list))
cont->AddObjectToContainer(lobj, lcount, nullptr);
}
logger::info("\t+ {}", distr_obj);
}
}
Expand Down Expand Up @@ -99,7 +101,8 @@ void Distributor::ReplaceDistribute(const Maps::TDistrVec& distr_vec) noexcept
}
else if (replace_with_list) {
cont->RemoveObjectFromContainer(bound_object, count.value());
cont->AddObjectToContainer(replace_with_list, replace_with_count.value(), nullptr);
for (const auto& [lobj, lcount] : Utility::ResolveLeveledList(replace_with_list))
cont->AddObjectToContainer(lobj, lcount, nullptr);
}
}
else if (leveled_list) {
Expand All @@ -109,7 +112,8 @@ void Distributor::ReplaceDistribute(const Maps::TDistrVec& distr_vec) noexcept
}
else if (replace_with_list) {
cont->RemoveObjectFromContainer(leveled_list, count.value());
cont->AddObjectToContainer(replace_with_list, replace_with_count.value(), nullptr);
for (const auto& [lobj, lcount] : Utility::ResolveLeveledList(replace_with_list))
cont->AddObjectToContainer(lobj, lcount, nullptr);
}
}
logger::info("\t^ {}", distr_obj);
Expand All @@ -123,7 +127,8 @@ void Distributor::ReplaceDistribute(const Maps::TDistrVec& distr_vec) noexcept
}
else if (replace_with_list) {
cont->RemoveObjectFromContainer(bound_object, num_to_remove);
cont->AddObjectToContainer(replace_with_list, num_to_remove, nullptr);
for (const auto& [lobj, lcount] : Utility::ResolveLeveledList(replace_with_list))
cont->AddObjectToContainer(lobj, lcount, nullptr);
}
}
else if (leveled_list) {
Expand All @@ -133,7 +138,8 @@ void Distributor::ReplaceDistribute(const Maps::TDistrVec& distr_vec) noexcept
}
else if (replace_with_list) {
cont->RemoveObjectFromContainer(leveled_list, num_to_remove);
cont->AddObjectToContainer(replace_with_list, num_to_remove, nullptr);
for (const auto& [lobj, lcount] : Utility::ResolveLeveledList(replace_with_list))
cont->AddObjectToContainer(lobj, lcount, nullptr);
}
}
logger::info("\t^ {}", distr_obj);
Expand Down
2 changes: 1 addition & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"name": "container-item-distributor",
"version-semver": "1.1.3",
"version-semver": "1.1.4",
"dependencies": ["commonlibsse-ng", "simpleini"],
"license": "GPL-3.0-or-later",
"vcpkg-configuration": {
Expand Down

0 comments on commit abc523d

Please sign in to comment.