diff --git a/SPID/include/Defs.h b/SPID/include/Defs.h index 57c23f5..e762db1 100644 --- a/SPID/include/Defs.h +++ b/SPID/include/Defs.h @@ -97,7 +97,23 @@ using Index = std::int32_t; using Count = std::int32_t; using RandomCount = Range; using IndexOrCount = std::variant; -using Chance = std::uint32_t; + +/// +/// A chance that is represented as a decimal value between 0 and 1. +/// For example, 0.5 would be 50%. +/// +/// This one is used in a processed Data for filtering. +/// +using DecimalChance = double; + +/// +/// A chance that is represented as a percent value between 0 and 100. +/// It also can be decimal, but would describe fraction of a percent. +/// So that 0.5 would be 0.5%. +/// +/// This is used during parsing of INI files. +/// +using PercentChance = double; /// A standardized way of converting any object to string. /// diff --git a/SPID/include/LinkedDistribution.h b/SPID/include/LinkedDistribution.h index e862e62..537b1fd 100644 --- a/SPID/include/LinkedDistribution.h +++ b/SPID/include/LinkedDistribution.h @@ -14,8 +14,8 @@ namespace LinkedDistribution /// Raw filters in RawLinkedForm only use MATCH, there is no meaning for ALL or NOT, so they are ignored. Filters formIDs{}; - IndexOrCount idxOrCount{ RandomCount(1, 1) }; - Chance chance{ 100 }; + IndexOrCount idxOrCount{ RandomCount(1, 1) }; + PercentChance chance{ 100 }; std::string path{}; }; @@ -66,7 +66,7 @@ namespace LinkedDistribution RECORD::TYPE type; FormsMap forms{}; - void Link(Form* form, const FormVec& linkedForms, const IndexOrCount& idxOrCount, const Chance& chance, const std::string& path); + void Link(Form* form, const FormVec& linkedForms, const IndexOrCount& idxOrCount, const PercentChance& chance, const std::string& path); }; class Manager : public ISingleton @@ -215,7 +215,7 @@ namespace LinkedDistribution } template - void LinkedForms
::Link(Form* form, const FormVec& linkedForms, const IndexOrCount& idxOrCount, const Chance& chance, const std::string& path) + void LinkedForms::Link(Form* form, const FormVec& linkedForms, const IndexOrCount& idxOrCount, const PercentChance& chance, const std::string& path) { for (const auto& linkedForm : linkedForms) { if (std::holds_alternative(linkedForm)) { diff --git a/SPID/include/LookupConfigs.h b/SPID/include/LookupConfigs.h index d2d7013..d4c10fe 100644 --- a/SPID/include/LookupConfigs.h +++ b/SPID/include/LookupConfigs.h @@ -91,7 +91,7 @@ namespace INI LevelFilters levelFilters{}; Traits traits{}; IndexOrCount idxOrCount{ RandomCount(1, 1) }; - Chance chance{ 100 }; + PercentChance chance{ 100 }; std::string path{}; }; diff --git a/SPID/include/LookupFilters.h b/SPID/include/LookupFilters.h index cf2b448..5da1012 100644 --- a/SPID/include/LookupFilters.h +++ b/SPID/include/LookupFilters.h @@ -16,13 +16,14 @@ namespace Filter struct Data { - Data(StringFilters a_strings, FormFilters a_formFilters, LevelFilters a_level, Traits a_traits, Chance a_chance); + // Note that chance passed to this constructor is expected to be in percent. It will be converted to a decimal chance during by the constructor. + Data(StringFilters a_strings, FormFilters a_formFilters, LevelFilters a_level, Traits a_traits, PercentChance a_chance); StringFilters strings{}; FormFilters forms{}; LevelFilters levels{}; Traits traits{}; - Chance chance{ 100 }; + DecimalChance chance{ 1 }; bool hasLeveledFilters; diff --git a/SPID/src/LinkedDistribution.cpp b/SPID/src/LinkedDistribution.cpp index bcdf193..b0b7886 100644 --- a/SPID/src/LinkedDistribution.cpp +++ b/SPID/src/LinkedDistribution.cpp @@ -84,7 +84,7 @@ namespace LinkedDistribution if (kChance < size) { if (const auto& str = sections[kChance]; distribution::is_valid_entry(str)) { - item.chance = string::to_num(str); + item.chance = string::to_num(str); } } diff --git a/SPID/src/LookupConfigs.cpp b/SPID/src/LookupConfigs.cpp index a6539ae..8d4f869 100644 --- a/SPID/src/LookupConfigs.cpp +++ b/SPID/src/LookupConfigs.cpp @@ -270,7 +270,7 @@ namespace INI //CHANCE if (kChance < size) { if (const auto& str = sections[kChance]; distribution::is_valid_entry(str)) { - data.chance = string::to_num(str); + data.chance = string::to_num(str); } } diff --git a/SPID/src/LookupFilters.cpp b/SPID/src/LookupFilters.cpp index ba60729..bdf528c 100644 --- a/SPID/src/LookupFilters.cpp +++ b/SPID/src/LookupFilters.cpp @@ -3,12 +3,12 @@ namespace Filter { - Data::Data(StringFilters a_strings, FormFilters a_formFilters, LevelFilters a_level, Traits a_traits, Chance a_chance) : + Data::Data(StringFilters a_strings, FormFilters a_formFilters, LevelFilters a_level, Traits a_traits, PercentChance a_chance) : strings(std::move(a_strings)), forms(std::move(a_formFilters)), levels(std::move(a_level)), traits(a_traits), - chance(a_chance) + chance(a_chance / 100) { hasLeveledFilters = HasLevelFiltersImpl(); } @@ -192,11 +192,12 @@ namespace Filter Result Data::PassedFilters(const NPCData& a_npcData) const { // Fail chance first to avoid running unnecessary checks - if (chance < 100) { - const auto randNum = RNG().generate(0, 100); + if (chance < 1) { + double randNum = RNG().generate(); if (randNum > chance) { return Result::kFailRNG; } + std::string res = "passed"; } if (passed_string_filters(a_npcData) == Result::kFail) { diff --git a/cmake/ports/clib-util/portfile.cmake b/cmake/ports/clib-util/portfile.cmake index 23f1474..e099051 100644 --- a/cmake/ports/clib-util/portfile.cmake +++ b/cmake/ports/clib-util/portfile.cmake @@ -2,8 +2,8 @@ vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO powerof3/CLibUtil - REF a491e2f7919211eac6d32dd2814b7908134ec1b2 - SHA512 e6b830a061d7fc99115ee7d28de0165b8c6281006df6d053342e6b5b85606a46a846ebb30f3e4598aa976c25cfe7a9dffd1c4eb72942829d1a4615d81e62cf3c + REF 88d78d94464a04e582669beac56346edbbc4a662 + SHA512 960cf62e5317356f7c0d994e49f56effb89c415377e9c865e801c5ec28b57e9ec0fd2a9fd54136cd2382addedb6745cd5cc062c46cab5cccb1f634999491c9e1 HEAD_REF master )