Documents LearnableAttacks
continuous-integration/drone/push Build is passing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2020-09-27 11:17:13 +02:00
parent 4006d63872
commit e14f747d48
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 33 additions and 12 deletions

View File

@ -3,13 +3,13 @@
namespace CreatureLib::Library { namespace CreatureLib::Library {
struct LearnableAttacks::impl { struct LearnableAttacks::impl {
private: private:
ArbUt::Dictionary<uint8_t, ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>> _learnedByLevel; ArbUt::Dictionary<level_int_t, ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>> _learnedByLevel;
ArbUt::List<ArbUt::BorrowedPtr<const AttackData>> _distinctLevelAttacks; ArbUt::List<ArbUt::BorrowedPtr<const AttackData>> _distinctLevelAttacks;
public: public:
explicit impl(size_t levelAttackCapacity) explicit impl(level_int_t levelAttackCapacity)
: _learnedByLevel( : _learnedByLevel(ArbUt::Dictionary<level_int_t, ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>>(
ArbUt::Dictionary<uint8_t, ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>>(levelAttackCapacity)) {} levelAttackCapacity)) {}
~impl() = default; ~impl() = default;
@ -24,8 +24,8 @@ namespace CreatureLib::Library {
} }
} }
inline bool HasAttacksForLevel(uint8_t level) const noexcept { return _learnedByLevel.Has(level); } inline bool HasAttacksForLevel(level_int_t level) const noexcept { return _learnedByLevel.Has(level); }
inline const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& GetAttacksForLevel(uint8_t level) const { inline const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& GetAttacksForLevel(level_int_t level) const {
if (!_learnedByLevel.Has(level)) { if (!_learnedByLevel.Has(level)) {
THROW("No attacks found for level " << (uint32_t)level << "."); THROW("No attacks found for level " << (uint32_t)level << ".");
} }
@ -47,14 +47,17 @@ namespace CreatureLib::Library {
} }
}; };
LearnableAttacks::LearnableAttacks(size_t levelAttackCapacity) : _impl(new impl(levelAttackCapacity)) {} LearnableAttacks::LearnableAttacks(level_int_t levelAttackCapacity) : _impl(new impl(levelAttackCapacity)) {}
LearnableAttacks::~LearnableAttacks() = default; LearnableAttacks::~LearnableAttacks() = default;
void LearnableAttacks::AddLevelAttack(level_int_t level, ArbUt::BorrowedPtr<const AttackData> attack) { void LearnableAttacks::AddLevelAttack(level_int_t level, ArbUt::BorrowedPtr<const AttackData> attack) {
_impl->AddLevelAttack(level, attack); _impl->AddLevelAttack(level, attack);
} }
bool LearnableAttacks::HasAttacksForLevel(uint8_t level) const noexcept { return _impl->HasAttacksForLevel(level); } bool LearnableAttacks::HasAttacksForLevel(level_int_t level) const noexcept {
const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& LearnableAttacks::GetAttacksForLevel(uint8_t level) const { return _impl->HasAttacksForLevel(level);
}
const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>&
LearnableAttacks::GetAttacksForLevel(level_int_t level) const {
return _impl->GetAttacksForLevel(level); return _impl->GetAttacksForLevel(level);
} }
const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>&

View File

@ -5,19 +5,37 @@
#include "../Attacks/AttackData.hpp" #include "../Attacks/AttackData.hpp"
namespace CreatureLib::Library { namespace CreatureLib::Library {
/// @brief Data class for holding the different attacks a creature can learn.
class LearnableAttacks { class LearnableAttacks {
private: private:
struct impl; struct impl;
std::unique_ptr<impl> _impl; std::unique_ptr<impl> _impl;
public: public:
explicit LearnableAttacks(size_t levelAttackCapacity); /// @brief Initialise the class using the maximum level a creature can reach.
/// @param levelAttackCapacity The maximum level a creature can reach
explicit LearnableAttacks(level_int_t levelAttackCapacity);
virtual ~LearnableAttacks(); virtual ~LearnableAttacks();
/// @brief Add an attack that can be learned at a certain level.
/// @param level The level the attack can be learned at.
/// @param attack A pointer to the attack data that can be learned/
void AddLevelAttack(level_int_t level, ArbUt::BorrowedPtr<const AttackData> attack); void AddLevelAttack(level_int_t level, ArbUt::BorrowedPtr<const AttackData> attack);
bool HasAttacksForLevel(uint8_t level) const noexcept; /// @brief Returns whether or not a specific level has learnable attacks.
const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& GetAttacksForLevel(uint8_t level) const; /// @param level The level to check for.
/// @return Whether or not a specific level has learnable attacks.
bool HasAttacksForLevel(level_int_t level) const noexcept;
/// @brief Returns a list of the attacks that can be learned at a specific level.
/// @param level The level to get the attacks from.
/// @return A list of the attacks that can be learned at a specific level.
/// @warning Note that this will throw if the level has no learnable attacks. Use HasAttacksForLevel first.
const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& GetAttacksForLevel(level_int_t level) const;
/// @brief Returns a list of distinct attacks that can be learned through levelling up.
/// @return A list of distinct attacks that can be learned through levelling up.
const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& GetDistinctLevelAttacks() const noexcept; const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& GetDistinctLevelAttacks() const noexcept;
/// @brief Returns a random attack that can be learned.
/// @param rand A random number generator.
/// @return A random attack that can be learned.
virtual ArbUt::BorrowedPtr<const AttackData> GetRandomAttack(ArbUt::Random& rand) const; virtual ArbUt::BorrowedPtr<const AttackData> GetRandomAttack(ArbUt::Random& rand) const;
}; };
} }