Rework LearnableAttacks to use ArbUt::BorrowedPtr
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
7ac63839b8
commit
2c4c0f2277
|
@ -13,7 +13,7 @@ export void CreatureLib_LearnableAttacks_AddLevelAttack(LearnableAttacks* p, uin
|
|||
}
|
||||
|
||||
export const AttackData* const* CreatureLib_LearnableAttacks_GetAttacksForLevel(LearnableAttacks* p, uint8_t level) {
|
||||
return p->GetAttacksForLevel(level).RawData();
|
||||
return reinterpret_cast<const AttackData* const*>(p->GetAttacksForLevel(level).RawData());
|
||||
}
|
||||
export bool CreatureLib_LearnableAttacks_HasAttacksForLevel(LearnableAttacks* p, uint8_t level) {
|
||||
return p->HasAttacksForLevel(level);
|
||||
|
@ -27,5 +27,5 @@ export size_t CreatureLib_LearnableAttacks_GetDistinctLevelAttacksCount(Learnabl
|
|||
}
|
||||
|
||||
export const AttackData* const* CreatureLib_LearnableAttacks_GetDistinctLevelAttacks(LearnableAttacks* p) {
|
||||
return p->GetDistinctLevelAttacks().RawData();
|
||||
return reinterpret_cast<const AttackData* const*>(p->GetDistinctLevelAttacks().RawData());
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
void LearnableAttacks::AddLevelAttack(uint8_t level, const AttackData* attack) {
|
||||
void LearnableAttacks::AddLevelAttack(uint8_t level, ArbUt::BorrowedPtr<const AttackData> attack) {
|
||||
if (_learnedByLevel.Has(level)) {
|
||||
_learnedByLevel[level].Append(attack);
|
||||
} else {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <Arbutils/Assert.hpp>
|
||||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
||||
#include <Arbutils/Random.hpp>
|
||||
#include <unordered_map>
|
||||
#include "../Attacks/AttackData.hpp"
|
||||
|
@ -11,30 +12,31 @@
|
|||
namespace CreatureLib::Library {
|
||||
class LearnableAttacks {
|
||||
protected:
|
||||
ArbUt::Dictionary<uint8_t, ArbUt::List<const AttackData*>> _learnedByLevel;
|
||||
ArbUt::List<const AttackData*> _distinctLevelAttacks;
|
||||
ArbUt::Dictionary<uint8_t, ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>> _learnedByLevel;
|
||||
ArbUt::List<ArbUt::BorrowedPtr<const AttackData>> _distinctLevelAttacks;
|
||||
|
||||
public:
|
||||
explicit LearnableAttacks(size_t levelAttackCapacity)
|
||||
: _learnedByLevel(ArbUt::Dictionary<uint8_t, ArbUt::List<const AttackData*>>(levelAttackCapacity)) {}
|
||||
: _learnedByLevel(
|
||||
ArbUt::Dictionary<uint8_t, ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>>(levelAttackCapacity)) {}
|
||||
|
||||
virtual ~LearnableAttacks() = default;
|
||||
|
||||
void AddLevelAttack(uint8_t level, const AttackData* attack);
|
||||
void AddLevelAttack(uint8_t level, ArbUt::BorrowedPtr<const AttackData> attack);
|
||||
|
||||
inline bool HasAttacksForLevel(uint8_t level) const noexcept { return _learnedByLevel.Has(level); }
|
||||
inline const ArbUt::List<const AttackData*>& GetAttacksForLevel(uint8_t level) const {
|
||||
inline const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& GetAttacksForLevel(uint8_t level) const {
|
||||
if (!_learnedByLevel.Has(level)) {
|
||||
THROW_CREATURE("No attacks found for level " << (uint32_t)level << ".");
|
||||
}
|
||||
return _learnedByLevel.Get(level);
|
||||
}
|
||||
|
||||
inline const ArbUt::List<const AttackData*>& GetDistinctLevelAttacks() const noexcept {
|
||||
inline const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& GetDistinctLevelAttacks() const noexcept {
|
||||
return _distinctLevelAttacks;
|
||||
}
|
||||
|
||||
virtual const AttackData* GetRandomAttack(ArbUt::Random& rand) const {
|
||||
virtual ArbUt::BorrowedPtr<const AttackData> GetRandomAttack(ArbUt::Random& rand) const {
|
||||
if (_distinctLevelAttacks.Count() == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue