Support getting distinct level attacks from LearnableAttacks.
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
b2931c0964
commit
f3d22f7ba9
|
@ -17,4 +17,12 @@ export const AttackData* const* CreatureLib_LearnableAttacks_GetAttacksForLevel(
|
|||
}
|
||||
export size_t CreatureLib_LearnableAttacks_GetAttacksForLevelCount(LearnableAttacks* p, uint8_t level) {
|
||||
return p->GetAttacksForLevel(level).Count();
|
||||
}
|
||||
|
||||
export size_t CreatureLib_LearnableAttacks_GetDistinctLevelAttacksCount(LearnableAttacks* p) {
|
||||
return p->GetDistinctLevelAttacks().size();
|
||||
}
|
||||
|
||||
export const AttackData* const* CreatureLib_LearnableAttacks_GetDistinctLevelAttacks(LearnableAttacks* p) {
|
||||
return p->GetDistinctLevelAttacks().cbegin().operator->();
|
||||
}
|
|
@ -10,5 +10,5 @@ void LearnableAttacks::AddLevelAttack(uint8_t level, const AttackData* attack) {
|
|||
levelData = {attack};
|
||||
_learnedByLevel.Insert(level, levelData);
|
||||
}
|
||||
_distinctAttacks.insert(attack);
|
||||
_distinctLevelAttacks.insert(attack);
|
||||
}
|
|
@ -12,7 +12,7 @@ namespace CreatureLib::Library {
|
|||
class LearnableAttacks {
|
||||
protected:
|
||||
ArbUt::Dictionary<uint8_t, ArbUt::List<const AttackData*>> _learnedByLevel;
|
||||
std::unordered_set<const AttackData*> _distinctAttacks;
|
||||
std::unordered_set<const AttackData*> _distinctLevelAttacks;
|
||||
|
||||
public:
|
||||
explicit LearnableAttacks(size_t levelAttackCapacity)
|
||||
|
@ -20,7 +20,7 @@ namespace CreatureLib::Library {
|
|||
for (auto kv : _learnedByLevel) {
|
||||
for (auto attack : kv.second) {
|
||||
AssertNotNull(attack)
|
||||
_distinctAttacks.insert(attack);
|
||||
_distinctLevelAttacks.insert(attack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,12 +33,16 @@ namespace CreatureLib::Library {
|
|||
return _learnedByLevel.Get(level);
|
||||
}
|
||||
|
||||
inline const std::unordered_set<const AttackData*>& GetDistinctLevelAttacks() const noexcept {
|
||||
return _distinctLevelAttacks;
|
||||
}
|
||||
|
||||
virtual const AttackData* GetRandomAttack(ArbUt::Random& rand) const {
|
||||
if (_distinctAttacks.empty()) {
|
||||
if (_distinctLevelAttacks.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
auto val = rand.Get(_distinctAttacks.size());
|
||||
auto it = _distinctAttacks.begin();
|
||||
auto val = rand.Get(_distinctLevelAttacks.size());
|
||||
auto it = _distinctLevelAttacks.begin();
|
||||
std::advance(it, val);
|
||||
return *it;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue