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