Reworked LearnedAttacks class, added C interface.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-03-02 15:23:08 +01:00
parent 60cbc80549
commit 3bca3c0673
3 changed files with 37 additions and 8 deletions

View File

@@ -2,8 +2,15 @@
using namespace CreatureLib::Library;
void LearnableAttacks::AddLevelMove(uint8_t level, AttackData* attack) { _learnedByLevel[level].push_back(attack); }
const std::vector<const AttackData*>& LearnableAttacks::GetMovesForLevel(uint8_t level) const {
return _learnedByLevel[level];
void LearnableAttacks::AddLevelMove(uint8_t level, const AttackData* attack) {
auto find = _learnedByLevel.find(level);
if (find != _learnedByLevel.end()) {
find->second.push_back(attack);
} else {
_learnedByLevel.insert({level, {attack}});
}
}
const std::vector<const AttackData*>& LearnableAttacks::GetAttacksForLevel(uint8_t level) const {
return _learnedByLevel.at(level);
}

View File

@@ -1,19 +1,21 @@
#ifndef CREATURELIB_LEARNABLEATTACKS_HPP
#define CREATURELIB_LEARNABLEATTACKS_HPP
#include <unordered_map>
#include <vector>
#include "../Attacks/AttackData.hpp"
namespace CreatureLib::Library {
class LearnableAttacks {
std::vector<std::vector<const AttackData*>> _learnedByLevel;
std::unordered_map<uint8_t, std::vector<const AttackData*>> _learnedByLevel;
public:
LearnableAttacks(uint8_t maxLevel) : _learnedByLevel(std::vector<std::vector<const AttackData*>>(maxLevel)) {}
LearnableAttacks(size_t levelAttackCapacity)
: _learnedByLevel(std::unordered_map<uint8_t, std::vector<const AttackData*>>(levelAttackCapacity)) {}
void AddLevelMove(uint8_t level, AttackData* attack);
void AddLevelMove(uint8_t level, const AttackData* attack);
const std::vector<const AttackData*>& GetMovesForLevel(uint8_t level) const;
const std::vector<const AttackData*>& GetAttacksForLevel(uint8_t level) const;
};
}