Return nullptr from LearnableAttacks when trying to retrieve from empty.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-04-19 18:50:32 +02:00
parent b286d1726d
commit 680f949df8
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
1 changed files with 3 additions and 0 deletions

View File

@ -33,6 +33,9 @@ namespace CreatureLib::Library {
const List<const AttackData*>& GetAttacksForLevel(uint8_t level) const; const List<const AttackData*>& GetAttacksForLevel(uint8_t level) const;
virtual const AttackData* GetRandomAttack(Arbutils::Random rand = Arbutils::Random()) const { virtual const AttackData* GetRandomAttack(Arbutils::Random rand = Arbutils::Random()) const {
if (_distinctAttacks.empty()) {
return nullptr;
}
auto val = rand.Get(_distinctAttacks.size()); auto val = rand.Get(_distinctAttacks.size());
return *std::next(_distinctAttacks.begin(), val); return *std::next(_distinctAttacks.begin(), val);
} }