Make LearnableAttacks follow PIMPL idiom.
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
@@ -2,45 +2,23 @@
|
||||
#define CREATURELIB_LEARNABLEATTACKS_HPP
|
||||
|
||||
#include <Arbutils/Random.hpp>
|
||||
#include "../../Defines.hpp"
|
||||
#include "../Attacks/AttackData.hpp"
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
class LearnableAttacks {
|
||||
protected:
|
||||
ArbUt::Dictionary<uint8_t, ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>> _learnedByLevel;
|
||||
ArbUt::List<ArbUt::BorrowedPtr<const AttackData>> _distinctLevelAttacks;
|
||||
private:
|
||||
struct impl;
|
||||
std::unique_ptr<impl> _impl;
|
||||
|
||||
public:
|
||||
explicit LearnableAttacks(size_t levelAttackCapacity)
|
||||
: _learnedByLevel(
|
||||
ArbUt::Dictionary<uint8_t, ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>>(levelAttackCapacity)) {}
|
||||
|
||||
virtual ~LearnableAttacks() = default;
|
||||
explicit LearnableAttacks(size_t levelAttackCapacity);
|
||||
virtual ~LearnableAttacks();
|
||||
|
||||
void AddLevelAttack(level_int_t level, ArbUt::BorrowedPtr<const AttackData> attack);
|
||||
|
||||
inline bool HasAttacksForLevel(uint8_t level) const noexcept { return _learnedByLevel.Has(level); }
|
||||
inline const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& 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<ArbUt::BorrowedPtr<const AttackData>>& GetDistinctLevelAttacks() const noexcept {
|
||||
return _distinctLevelAttacks;
|
||||
}
|
||||
|
||||
virtual ArbUt::BorrowedPtr<const AttackData> 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<ArbUt::BorrowedPtr<const AttackData>>& GetAttacksForLevel(uint8_t level) const;
|
||||
const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& GetDistinctLevelAttacks() const noexcept;
|
||||
virtual ArbUt::BorrowedPtr<const AttackData> GetRandomAttack(ArbUt::Random& rand) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user