diff --git a/src/Library/CreatureData/LearnableAttacks.cpp b/src/Library/CreatureData/LearnableAttacks.cpp index 863cceb..effce02 100644 --- a/src/Library/CreatureData/LearnableAttacks.cpp +++ b/src/Library/CreatureData/LearnableAttacks.cpp @@ -1,13 +1,68 @@ #include "LearnableAttacks.hpp" -using namespace CreatureLib::Library; +namespace CreatureLib::Library { + struct LearnableAttacks::impl { + private: + ArbUt::Dictionary>> _learnedByLevel; + ArbUt::List> _distinctLevelAttacks; -void LearnableAttacks::AddLevelAttack(level_int_t level, ArbUt::BorrowedPtr attack) { - if (_learnedByLevel.Has(level)) { - _learnedByLevel[level].Append(attack); - } else { - _learnedByLevel.Insert(level, {attack}); + public: + explicit impl(size_t levelAttackCapacity) + : _learnedByLevel( + ArbUt::Dictionary>>(levelAttackCapacity)) {} + + ~impl() = default; + + void AddLevelAttack(level_int_t level, const ArbUt::BorrowedPtr& attack) { + if (_learnedByLevel.Has(level)) { + _learnedByLevel[level].Append(attack); + } else { + _learnedByLevel.Insert(level, {attack}); + } + if (!_distinctLevelAttacks.Contains(attack)) { + _distinctLevelAttacks.Append(attack); + } + } + + inline bool HasAttacksForLevel(uint8_t level) const noexcept { return _learnedByLevel.Has(level); } + inline const ArbUt::List>& GetAttacksForLevel(uint8_t level) const { + if (!_learnedByLevel.Has(level)) { + THROW("No attacks found for level " << (uint32_t)level << "."); + } + return _learnedByLevel.Get(level); + } + + inline const ArbUt::List>& GetDistinctLevelAttacks() const noexcept { + return _distinctLevelAttacks; + } + + ArbUt::BorrowedPtr GetRandomAttack(ArbUt::Random& rand) const { + if (_distinctLevelAttacks.Count() == 0) { + return nullptr; + } + auto val = rand.Get(_distinctLevelAttacks.Count()); + auto it = _distinctLevelAttacks.begin(); + std::advance(it, val); + return *it; + } + }; + + LearnableAttacks::LearnableAttacks(size_t levelAttackCapacity) : _impl(new impl(levelAttackCapacity)) {} + LearnableAttacks::~LearnableAttacks() = default; + + void LearnableAttacks::AddLevelAttack(level_int_t level, ArbUt::BorrowedPtr attack) { + _impl->AddLevelAttack(level, attack); } - if (!_distinctLevelAttacks.Contains(attack)) - _distinctLevelAttacks.Append(attack); + bool LearnableAttacks::HasAttacksForLevel(uint8_t level) const noexcept { return _impl->HasAttacksForLevel(level); } + const ArbUt::List>& LearnableAttacks::GetAttacksForLevel(uint8_t level) const { + return _impl->GetAttacksForLevel(level); + } + const ArbUt::List>& + LearnableAttacks::GetDistinctLevelAttacks() const noexcept { + return _impl->GetDistinctLevelAttacks(); + } + ArbUt::BorrowedPtr LearnableAttacks::GetRandomAttack(ArbUt::Random& rand) const { + return _impl->GetRandomAttack(rand); + } + } \ No newline at end of file diff --git a/src/Library/CreatureData/LearnableAttacks.hpp b/src/Library/CreatureData/LearnableAttacks.hpp index 060322e..7c9a418 100644 --- a/src/Library/CreatureData/LearnableAttacks.hpp +++ b/src/Library/CreatureData/LearnableAttacks.hpp @@ -2,45 +2,23 @@ #define CREATURELIB_LEARNABLEATTACKS_HPP #include -#include "../../Defines.hpp" #include "../Attacks/AttackData.hpp" namespace CreatureLib::Library { class LearnableAttacks { - protected: - ArbUt::Dictionary>> _learnedByLevel; - ArbUt::List> _distinctLevelAttacks; + private: + struct impl; + std::unique_ptr _impl; public: - explicit LearnableAttacks(size_t levelAttackCapacity) - : _learnedByLevel( - ArbUt::Dictionary>>(levelAttackCapacity)) {} - - virtual ~LearnableAttacks() = default; + explicit LearnableAttacks(size_t levelAttackCapacity); + virtual ~LearnableAttacks(); void AddLevelAttack(level_int_t level, ArbUt::BorrowedPtr attack); - - inline bool HasAttacksForLevel(uint8_t level) const noexcept { return _learnedByLevel.Has(level); } - inline const ArbUt::List>& GetAttacksForLevel(uint8_t level) const { - if (!_learnedByLevel.Has(level)) { - THROW("No attacks found for level " << (uint32_t)level << "."); - } - return _learnedByLevel.Get(level); - } - - inline const ArbUt::List>& GetDistinctLevelAttacks() const noexcept { - return _distinctLevelAttacks; - } - - virtual ArbUt::BorrowedPtr GetRandomAttack(ArbUt::Random& rand) const { - if (_distinctLevelAttacks.Count() == 0) { - return nullptr; - } - auto val = rand.Get(_distinctLevelAttacks.Count()); - auto it = _distinctLevelAttacks.begin(); - std::advance(it, val); - return *it; - } + bool HasAttacksForLevel(uint8_t level) const noexcept; + const ArbUt::List>& GetAttacksForLevel(uint8_t level) const; + const ArbUt::List>& GetDistinctLevelAttacks() const noexcept; + virtual ArbUt::BorrowedPtr GetRandomAttack(ArbUt::Random& rand) const; }; } diff --git a/src/Library/GrowthRates/LookupGrowthRate.hpp b/src/Library/GrowthRates/LookupGrowthRate.hpp index 1050133..e8d8e4c 100644 --- a/src/Library/GrowthRates/LookupGrowthRate.hpp +++ b/src/Library/GrowthRates/LookupGrowthRate.hpp @@ -12,7 +12,7 @@ namespace CreatureLib::Library { LookupGrowthRate(const ArbUt::List& experience) : _experience(experience) {} level_int_t CalculateLevel(uint32_t experience) const override { - for (level_int_t i = 0; i < _experience.Count(); i++) { + for (level_int_t i = 0; i < (level_int_t)_experience.Count(); i++) { if (_experience[i] > experience) { return i; } diff --git a/src/Precompiled.hxx b/src/Precompiled.hxx index 5a08e73..e76726c 100644 --- a/src/Precompiled.hxx +++ b/src/Precompiled.hxx @@ -30,4 +30,7 @@ #include #include +// CreatureLib +#include "Defines.hpp" + #endif // CREATURELIB_PRECOMPILED_HXX