Bring Library class in line with style lines.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2020-06-20 18:50:55 +02:00
parent add77325a4
commit 14458ec30c
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
21 changed files with 133 additions and 166 deletions

View File

@ -8,10 +8,3 @@ CreatureLib::Library::AttackData::AttackData(const ArbUt::CaseInsensitiveConstSt
const SecondaryEffect* effect, std::unordered_set<uint32_t> flags)
: _name(name), _type(type), _category(category), _basePower(power), _accuracy(accuracy), _baseUsages(baseUsage),
_target(target), _priority(priority), _effect(effect), _flags(std::move(flags)) {}
bool CreatureLib::Library::AttackData::HasFlag(const ArbUt::CaseInsensitiveConstString& key) const noexcept {
return this->_flags.find(key) != this->_flags.end();
}
bool CreatureLib::Library::AttackData::HasFlag(uint32_t key) const noexcept {
return this->_flags.find(key) != this->_flags.end();
}

View File

@ -42,8 +42,12 @@ namespace CreatureLib::Library {
}
inline const std::unique_ptr<const SecondaryEffect>& GetSecondaryEffect() const noexcept { return _effect; }
bool HasFlag(const ArbUt::CaseInsensitiveConstString& key) const noexcept;
bool HasFlag(uint32_t keyHash) const noexcept;
inline bool HasFlag(const ArbUt::CaseInsensitiveConstString& key) const noexcept {
return this->_flags.find(key) != this->_flags.end();
}
inline bool HasFlag(uint32_t keyHash) const noexcept {
return this->_flags.find(keyHash) != this->_flags.end();
}
};
}

View File

@ -19,7 +19,7 @@ namespace CreatureLib::Library {
const ArbUt::List<EffectParameter*>& parameters) noexcept
: _chance(chance), _effectName(effectName), _parameters(parameters) {}
~SecondaryEffect() {
~SecondaryEffect() noexcept {
for (auto p : _parameters) {
delete p;
}

View File

@ -20,7 +20,7 @@ namespace CreatureLib::Library {
public:
BaseLibrary(size_t initialCapacity = 32) : _values(initialCapacity), _listValues(initialCapacity) {}
virtual ~BaseLibrary() { _values.Clear(); }
virtual ~BaseLibrary() noexcept { _values.Clear(); }
inline void Insert(const ArbUt::CaseInsensitiveConstString& key, const T* value) {
AssertNotNull(value)
@ -33,21 +33,21 @@ namespace CreatureLib::Library {
_listValues.Append(hashedKey);
}
inline void Delete(const ArbUt::CaseInsensitiveConstString& key) {
inline void Delete(const ArbUt::CaseInsensitiveConstString& key) noexcept {
_values.erase(key.GetHash());
auto k = _listValues.IndexOf(key);
_listValues.Remove(k);
}
inline void Delete(uint32_t hashedKey) {
inline void Delete(uint32_t hashedKey) noexcept {
_values.Remove(hashedKey);
auto k = _listValues.IndexOf(hashedKey);
_listValues.Remove(k);
}
bool TryGet(const ArbUt::CaseInsensitiveConstString& name, ArbUt::BorrowedPtr<const T>& out) const {
bool TryGet(const ArbUt::CaseInsensitiveConstString& name, ArbUt::BorrowedPtr<const T>& out) const noexcept {
return TryGet(name.GetHash(), out);
}
bool TryGet(uint32_t hashedKey, ArbUt::BorrowedPtr<const T>& out) const {
bool TryGet(uint32_t hashedKey, ArbUt::BorrowedPtr<const T>& out) const noexcept {
auto find = _values.GetStdMap().find(hashedKey);
if (find == _values.GetStdMap().end())
return false;
@ -67,17 +67,18 @@ namespace CreatureLib::Library {
return Get(name);
}
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> operator[](uint32_t hashedKey) const { return Get(hashedKey); }
[[nodiscard]] inline const ArbUt::Dictionary<uint32_t, const std::unique_ptr<const T>>& GetIterator() const {
[[nodiscard]] inline const ArbUt::Dictionary<uint32_t, const std::unique_ptr<const T>>&
GetIterator() const noexcept {
return _values;
}
[[nodiscard]] size_t GetCount() const { return _values.Count(); }
[[nodiscard]] size_t GetCount() const noexcept { return _values.Count(); }
inline ArbUt::BorrowedPtr<const T> GetRandomValue(ArbUt::Random rand = ArbUt::Random()) const {
inline ArbUt::BorrowedPtr<const T> GetRandomValue(ArbUt::Random rand = ArbUt::Random()) const noexcept {
auto i = rand.Get(_listValues.Count());
return _values[_listValues[i]];
}
inline ArbUt::BorrowedPtr<const T> GetRandomValue(ArbUt::Random* rand) const {
inline ArbUt::BorrowedPtr<const T> GetRandomValue(ArbUt::Random* rand) const noexcept {
auto i = rand->Get(_listValues.Count());
return _values[_listValues[i]];
}

View File

@ -14,18 +14,19 @@ namespace CreatureLib::Library {
T _speed;
public:
ClampedStatisticSet(T health, T physicalAttack, T physicalDefense, T magicalAttack, T magicalDefense, T speed)
inline ClampedStatisticSet(T health, T physicalAttack, T physicalDefense, T magicalAttack, T magicalDefense,
T speed) noexcept
: _health(health), _physicalAttack(physicalAttack), _physicalDefense(physicalDefense),
_magicalAttack(magicalAttack), _magicalDefense(magicalDefense), _speed(speed) {}
ClampedStatisticSet()
inline ClampedStatisticSet() noexcept
: _health(0), _physicalAttack(0), _physicalDefense(0), _magicalAttack(0), _magicalDefense(0), _speed(0) {}
inline T GetHealth() const { return _health; }
inline T GetPhysicalAttack() const { return _physicalAttack; }
inline T GetPhysicalDefense() const { return _physicalDefense; }
inline T GetMagicalAttack() const { return _magicalAttack; }
inline T GetMagicalDefense() const { return _magicalDefense; }
inline T GetSpeed() const { return _speed; }
inline T GetHealth() const noexcept { return _health; }
inline T GetPhysicalAttack() const noexcept { return _physicalAttack; }
inline T GetPhysicalDefense() const noexcept { return _physicalDefense; }
inline T GetMagicalAttack() const noexcept { return _magicalAttack; }
inline T GetMagicalDefense() const noexcept { return _magicalDefense; }
inline T GetSpeed() const noexcept { return _speed; }
[[nodiscard]] inline T GetStat(Statistic stat) const {
switch (stat) {

View File

@ -11,13 +11,11 @@ CreatureSpecies::CreatureSpecies(uint16_t id, const ArbUt::CaseInsensitiveConstS
SetVariant("default"_cnc, defaultVariant);
}
bool CreatureSpecies::HasVariant(const ArbUt::CaseInsensitiveConstString& name) const { return _variants.Has(name); }
bool CreatureSpecies::TryGetVariant(const ArbUt::CaseInsensitiveConstString& name,
ArbUt::BorrowedPtr<const SpeciesVariant>& out) const {
ArbUt::BorrowedPtr<const SpeciesVariant>& out) const noexcept {
return TryGetVariant(name.GetHash(), out);
}
bool CreatureSpecies::TryGetVariant(uint32_t hash, ArbUt::BorrowedPtr<const SpeciesVariant>& out) const {
bool CreatureSpecies::TryGetVariant(uint32_t hash, ArbUt::BorrowedPtr<const SpeciesVariant>& out) const noexcept {
auto find = _variants.GetStdMap().find(hash);
if (find == _variants.end())
return false;
@ -25,13 +23,6 @@ bool CreatureSpecies::TryGetVariant(uint32_t hash, ArbUt::BorrowedPtr<const Spec
return true;
}
ArbUt::BorrowedPtr<const SpeciesVariant>
CreatureSpecies::GetVariant(const ArbUt::CaseInsensitiveConstString& name) const {
return _variants.Get(name);
}
ArbUt::BorrowedPtr<const SpeciesVariant> CreatureSpecies::GetVariant(uint32_t key) const { return _variants.Get(key); }
bool CreatureSpecies::HasVariant(uint32_t hash) const { return _variants.Has(hash); }
void CreatureSpecies::SetVariant(const ArbUt::CaseInsensitiveConstString& name, const SpeciesVariant* variant) {
_variants.GetStdMap().insert({name, std::unique_ptr<const SpeciesVariant>(variant)});
}

View File

@ -28,27 +28,33 @@ namespace CreatureLib::Library {
const SpeciesVariant* defaultVariant, float genderRatio,
const ArbUt::CaseInsensitiveConstString& growthRate, uint8_t captureRate);
virtual ~CreatureSpecies() { _variants.Clear(); }
virtual ~CreatureSpecies() noexcept { _variants.Clear(); }
inline uint16_t GetId() const { return _id; }
inline float GetGenderRate() const { return _genderRate; }
inline const ArbUt::CaseInsensitiveConstString& GetGrowthRate() const { return _growthRate; }
inline uint8_t GetCaptureRate() const { return _captureRate; }
inline uint16_t GetId() const noexcept { return _id; }
inline float GetGenderRate() const noexcept { return _genderRate; }
inline const ArbUt::CaseInsensitiveConstString& GetGrowthRate() const noexcept { return _growthRate; }
inline uint8_t GetCaptureRate() const noexcept { return _captureRate; }
[[nodiscard]] bool HasVariant(const ArbUt::CaseInsensitiveConstString& key) const;
[[nodiscard]] bool HasVariant(uint32_t hash) const;
[[nodiscard]] inline bool HasVariant(const ArbUt::CaseInsensitiveConstString& key) const noexcept {
return _variants.Has(key);
}
[[nodiscard]] inline bool HasVariant(uint32_t hash) const noexcept { return _variants.Has(hash); }
[[nodiscard]] bool TryGetVariant(const ArbUt::CaseInsensitiveConstString& name,
ArbUt::BorrowedPtr<const SpeciesVariant>& out) const;
[[nodiscard]] bool TryGetVariant(uint32_t hash, ArbUt::BorrowedPtr<const SpeciesVariant>& out) const;
[[nodiscard]] ArbUt::BorrowedPtr<const SpeciesVariant>
GetVariant(const ArbUt::CaseInsensitiveConstString& key) const;
[[nodiscard]] ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(uint32_t key) const;
[[nodiscard]] Gender GetRandomGender(ArbUt::Random& rand) const;
[[nodiscard]] const ArbUt::CaseInsensitiveConstString& GetName() const { return _name; }
ArbUt::BorrowedPtr<const SpeciesVariant>& out) const noexcept;
[[nodiscard]] bool TryGetVariant(uint32_t hash, ArbUt::BorrowedPtr<const SpeciesVariant>& out) const noexcept;
[[nodiscard]] inline ArbUt::BorrowedPtr<const SpeciesVariant>
GetVariant(const ArbUt::CaseInsensitiveConstString& key) const {
return _variants.Get(key);
}
[[nodiscard]] inline ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(uint32_t key) const {
return _variants.Get(key);
}
[[nodiscard]] Gender GetRandomGender(ArbUt::Random& rand) const noexcept;
[[nodiscard]] inline const ArbUt::CaseInsensitiveConstString& GetName() const { return _name; }
void SetVariant(const ArbUt::CaseInsensitiveConstString& name, const SpeciesVariant* variant);
const ArbUt::Dictionary<uint32_t, std::unique_ptr<const SpeciesVariant>>& GetVariantsIterator() const {
inline const ArbUt::Dictionary<uint32_t, std::unique_ptr<const SpeciesVariant>>& GetVariantsIterator() const {
return _variants;
}
};

View File

@ -12,7 +12,3 @@ void LearnableAttacks::AddLevelAttack(uint8_t level, const AttackData* attack) {
}
_distinctAttacks.insert(attack);
}
const ArbUt::List<const AttackData*>& LearnableAttacks::GetAttacksForLevel(uint8_t level) const {
return _learnedByLevel.Get(level);
}

View File

@ -29,7 +29,9 @@ namespace CreatureLib::Library {
void AddLevelAttack(uint8_t level, const AttackData* attack);
const ArbUt::List<const AttackData*>& GetAttacksForLevel(uint8_t level) const;
inline const ArbUt::List<const AttackData*>& GetAttacksForLevel(uint8_t level) const {
return _learnedByLevel.Get(level);
}
virtual const AttackData* GetRandomAttack(ArbUt::Random& rand) const {
if (_distinctAttacks.empty()) {

View File

@ -1,16 +1,5 @@
#include "SpeciesVariant.hpp"
#include <algorithm>
#include <utility>
const ArbUt::List<uint8_t>& CreatureLib::Library::SpeciesVariant::GetTypes() const { return _types; }
size_t CreatureLib::Library::SpeciesVariant::GetTypeCount() const { return _types.Count(); }
uint8_t CreatureLib::Library::SpeciesVariant::GetType(size_t index) const { return _types[index]; }
uint16_t CreatureLib::Library::SpeciesVariant::GetStatistic(CreatureLib::Library::Statistic stat) const {
return _baseStatistics.GetStat(stat);
}
const CreatureLib::Library::TalentIndex
CreatureLib::Library::SpeciesVariant::GetTalentIndex(const ArbUt::CaseInsensitiveConstString& talent) const {
@ -26,22 +15,3 @@ CreatureLib::Library::SpeciesVariant::GetTalentIndex(const ArbUt::CaseInsensitiv
}
throw CreatureException("The given talent is not a valid talent for this creature.");
}
CreatureLib::Library::TalentIndex CreatureLib::Library::SpeciesVariant::GetRandomTalent(ArbUt::Random* rand) const {
return TalentIndex(false, rand->Get(_talents.Count()));
}
const std::unique_ptr<const CreatureLib::Library::LearnableAttacks>&
CreatureLib::Library::SpeciesVariant::GetLearnableAttacks() const {
return _attacks;
}
CreatureLib::Library::SpeciesVariant::SpeciesVariant(ArbUt::CaseInsensitiveConstString name, float height, float weight,
uint32_t baseExperience, ArbUt::List<uint8_t> types,
CreatureLib::Library::StatisticSet<uint16_t> baseStats,
ArbUt::List<ArbUt::CaseInsensitiveConstString> talents,
ArbUt::List<ArbUt::CaseInsensitiveConstString> secretTalents,
const LearnableAttacks* attacks)
: _name(std::move(name)), _height(height), _weight(weight), _baseExperience(baseExperience),
_types(std::move(types)), _baseStatistics(baseStats), _talents(std::move(talents)),
_secretTalents(std::move(secretTalents)), _attacks(attacks) {}

View File

@ -28,11 +28,14 @@ namespace CreatureLib::Library {
std::unique_ptr<const LearnableAttacks> _attacks;
public:
SpeciesVariant(ArbUt::CaseInsensitiveConstString name, float height, float weight, uint32_t baseExperience,
ArbUt::List<uint8_t> types, Library::StatisticSet<uint16_t> baseStats,
ArbUt::List<ArbUt::CaseInsensitiveConstString> talents,
ArbUt::List<ArbUt::CaseInsensitiveConstString> secretTalents, const LearnableAttacks* attacks);
SpeciesVariant(const ArbUt::CaseInsensitiveConstString& name, float height, float weight,
uint32_t baseExperience, const ArbUt::List<uint8_t>& types,
Library::StatisticSet<uint16_t> baseStats,
const ArbUt::List<ArbUt::CaseInsensitiveConstString>& talents,
const ArbUt::List<ArbUt::CaseInsensitiveConstString>& secretTalents,
const LearnableAttacks* attacks)
: _name(name), _height(height), _weight(weight), _baseExperience(baseExperience), _types((types)),
_baseStatistics(baseStats), _talents(talents), _secretTalents(secretTalents), _attacks(attacks){};
virtual ~SpeciesVariant() = default;
inline const ArbUt::CaseInsensitiveConstString& GetName() const { return _name; }
@ -40,12 +43,14 @@ namespace CreatureLib::Library {
inline float GetWeight() const { return _weight; }
inline uint32_t GetBaseExperience() const { return _baseExperience; }
[[nodiscard]] size_t GetTypeCount() const;
[[nodiscard]] uint8_t GetType(size_t index) const;
[[nodiscard]] const ArbUt::List<uint8_t>& GetTypes() const;
[[nodiscard]] uint16_t GetStatistic(Library::Statistic stat) const;
[[nodiscard]] const size_t GetTalentCount() const { return _talents.Count(); }
[[nodiscard]] const size_t GetSecretTalentCount() const { return _secretTalents.Count(); }
[[nodiscard]] inline size_t GetTypeCount() const { return _types.Count(); }
[[nodiscard]] inline uint8_t GetType(size_t index) const { return _types[index]; }
[[nodiscard]] inline const ArbUt::List<uint8_t>& GetTypes() const { return _types; }
[[nodiscard]] inline uint16_t GetStatistic(Library::Statistic stat) const {
return _baseStatistics.GetStat(stat);
}
[[nodiscard]] inline const size_t GetTalentCount() const noexcept { return _talents.Count(); }
[[nodiscard]] inline const size_t GetSecretTalentCount() const noexcept { return _secretTalents.Count(); }
[[nodiscard]] const ArbUt::CaseInsensitiveConstString& GetTalent(const TalentIndex& index) const {
if (index.IsSecret() && _secretTalents.Count() > 0) {
auto i = index.GetIndex();
@ -60,8 +65,13 @@ namespace CreatureLib::Library {
}
[[nodiscard]] const TalentIndex GetTalentIndex(const ArbUt::CaseInsensitiveConstString& talent) const;
[[nodiscard]] const std::unique_ptr<const CreatureLib::Library::LearnableAttacks>& GetLearnableAttacks() const;
[[nodiscard]] TalentIndex GetRandomTalent(ArbUt::Random* rand) const;
[[nodiscard]] inline ArbUt::BorrowedPtr<const CreatureLib::Library::LearnableAttacks>
GetLearnableAttacks() const {
return _attacks;
}
[[nodiscard]] inline TalentIndex GetRandomTalent(ArbUt::Random* rand) const noexcept {
return TalentIndex(false, rand->Get(_talents.Count()));
}
[[nodiscard]] inline const ArbUt::List<ArbUt::CaseInsensitiveConstString>& GetTalents() const {
return _talents;
}

View File

@ -8,10 +8,10 @@ namespace CreatureLib::Library {
uint8_t _index;
public:
TalentIndex() : _secret(false), _index(0){};
TalentIndex(bool secret, uint8_t index) : _secret(secret), _index(index) {}
constexpr inline bool IsSecret() const { return _secret; }
constexpr inline bool GetIndex() const { return _index; }
inline TalentIndex() noexcept : _secret(false), _index(0){};
inline TalentIndex(bool secret, uint8_t index) noexcept : _secret(secret), _index(index) {}
constexpr inline bool IsSecret() const noexcept { return _secret; }
constexpr inline bool GetIndex() const noexcept { return _index; }
};
}

View File

@ -28,16 +28,24 @@ namespace CreatureLib::Library {
virtual ~DataLibrary() {}
[[nodiscard]] const std::unique_ptr<const LibrarySettings>& GetSettings() const noexcept { return _settings; }
[[nodiscard]] const std::unique_ptr<const SpeciesLibrary>& GetSpeciesLibrary() const noexcept {
[[nodiscard]] inline const std::unique_ptr<const LibrarySettings>& GetSettings() const noexcept {
return _settings;
}
[[nodiscard]] inline const std::unique_ptr<const SpeciesLibrary>& GetSpeciesLibrary() const noexcept {
return _species;
}
[[nodiscard]] const std::unique_ptr<const AttackLibrary>& GetAttackLibrary() const noexcept { return _attacks; }
[[nodiscard]] const std::unique_ptr<const ItemLibrary>& GetItemLibrary() const noexcept { return _items; }
[[nodiscard]] const std::unique_ptr<const GrowthRateLibrary>& GetGrowthRates() const noexcept {
[[nodiscard]] inline const std::unique_ptr<const AttackLibrary>& GetAttackLibrary() const noexcept {
return _attacks;
}
[[nodiscard]] inline const std::unique_ptr<const ItemLibrary>& GetItemLibrary() const noexcept {
return _items;
}
[[nodiscard]] inline const std::unique_ptr<const GrowthRateLibrary>& GetGrowthRates() const noexcept {
return _growthRates;
}
[[nodiscard]] const std::unique_ptr<const TypeLibrary>& GetTypeLibrary() const noexcept { return _typeLibrary; }
[[nodiscard]] inline const std::unique_ptr<const TypeLibrary>& GetTypeLibrary() const noexcept {
return _typeLibrary;
}
};
}

View File

@ -14,16 +14,16 @@ namespace CreatureLib::Library {
std::variant<bool, int64_t, float, ArbUt::CaseInsensitiveConstString> _value;
public:
EffectParameter() : _type(EffectParameterType::None){};
explicit EffectParameter(bool b) : _type(EffectParameterType::Bool), _value(b){};
explicit EffectParameter(int64_t i) : _type(EffectParameterType::Int), _value(i){};
explicit EffectParameter(float f) : _type(EffectParameterType::Float), _value(f){};
explicit EffectParameter(const ArbUt::CaseInsensitiveConstString& s)
inline EffectParameter() : _type(EffectParameterType::None){};
inline explicit EffectParameter(bool b) : _type(EffectParameterType::Bool), _value(b){};
inline explicit EffectParameter(int64_t i) : _type(EffectParameterType::Int), _value(i){};
inline explicit EffectParameter(float f) : _type(EffectParameterType::Float), _value(f){};
inline explicit EffectParameter(const ArbUt::CaseInsensitiveConstString& s)
: _type(EffectParameterType::String), _value(s){};
EffectParameter(const EffectParameter& other) = delete;
EffectParameter& operator=(const EffectParameter& other) = delete;
EffectParameterType GetType() const noexcept { return _type; }
inline EffectParameterType GetType() const noexcept { return _type; }
bool AsBool() const {
if (_type != EffectParameterType::Bool) {
std::stringstream ss;

View File

@ -9,7 +9,7 @@ namespace CreatureLib::Library {
uint32_t (*_calcExperience)(uint8_t level);
public:
ExternGrowthRate(uint8_t (*calcLevel)(uint32_t), uint32_t (*calcExperience)(uint8_t level))
inline ExternGrowthRate(uint8_t (*calcLevel)(uint32_t), uint32_t (*calcExperience)(uint8_t level))
: _calcLevel(calcLevel), _calcExperience(calcExperience) {
AssertNotNull(calcLevel)
AssertNotNull(calcExperience)

View File

@ -1,14 +0,0 @@
#include "Item.hpp"
bool CreatureLib::Library::Item::HasFlag(const ArbUt::CaseInsensitiveConstString& flag) const noexcept {
return this->_flags.find(flag) != this->_flags.end();
}
bool CreatureLib::Library::Item::HasFlag(uint32_t flag) const noexcept {
return this->_flags.find(flag) != this->_flags.end();
}
CreatureLib::Library::Item::Item(const ArbUt::CaseInsensitiveConstString& name,
CreatureLib::Library::ItemCategory category,
CreatureLib::Library::BattleItemCategory battleCategory, int32_t price,
const std::unordered_set<uint32_t>& flags)
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _flags(flags) {}

View File

@ -17,16 +17,20 @@ namespace CreatureLib::Library {
std::unordered_set<uint32_t> _flags;
public:
Item(const ArbUt::CaseInsensitiveConstString& name, ItemCategory category, BattleItemCategory battleCategory,
int32_t price, const std::unordered_set<uint32_t>& flags);
inline Item(const ArbUt::CaseInsensitiveConstString& name, ItemCategory category,
BattleItemCategory battleCategory, int32_t price,
const std::unordered_set<uint32_t>& flags) noexcept
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _flags(flags) {}
inline const ArbUt::CaseInsensitiveConstString& GetName() const noexcept { return _name; }
inline ItemCategory GetCategory() const noexcept { return _category; }
inline BattleItemCategory GetBattleCategory() const noexcept { return _battleCategory; }
inline const int32_t GetPrice() const noexcept { return _price; }
bool HasFlag(const ArbUt::CaseInsensitiveConstString& flag) const noexcept;
bool HasFlag(uint32_t flag) const noexcept;
bool HasFlag(const ArbUt::CaseInsensitiveConstString& flag) const noexcept {
return this->_flags.find(flag) != this->_flags.end();
}
bool HasFlag(uint32_t flag) const noexcept { return this->_flags.find(flag) != this->_flags.end(); }
};
}

View File

@ -12,9 +12,9 @@ namespace CreatureLib::Library {
LibrarySettings(uint8_t maximalLevel, uint8_t maximalMoves)
: _maximalLevel(maximalLevel), _maximalMoves(maximalMoves) {}
inline uint8_t GetMaximalLevel() const { return _maximalLevel; }
inline uint8_t GetMaximalLevel() const noexcept { return _maximalLevel; }
inline uint8_t GetMaximalMoves() const { return _maximalMoves; }
inline uint8_t GetMaximalMoves() const noexcept { return _maximalMoves; }
};
}

View File

@ -16,18 +16,18 @@ namespace CreatureLib::Library {
T _speed;
public:
StatisticSet(T health, T physicalAttack, T physicalDefense, T magicalAttack, T magicalDefense, T speed)
StatisticSet(T health, T physicalAttack, T physicalDefense, T magicalAttack, T magicalDefense, T speed) noexcept
: _health(health), _physicalAttack(physicalAttack), _physicalDefense(physicalDefense),
_magicalAttack(magicalAttack), _magicalDefense(magicalDefense), _speed(speed) {}
StatisticSet()
StatisticSet() noexcept
: _health(0), _physicalAttack(0), _physicalDefense(0), _magicalAttack(0), _magicalDefense(0), _speed(0) {}
inline T GetHealth() const { return _health; }
inline T GetPhysicalAttack() const { return _physicalAttack; }
inline T GetPhysicalDefense() const { return _physicalDefense; }
inline T GetMagicalAttack() const { return _magicalAttack; }
inline T GetMagicalDefense() const { return _magicalDefense; }
inline T GetSpeed() const { return _speed; }
inline T GetHealth() const noexcept { return _health; }
inline T GetPhysicalAttack() const noexcept { return _physicalAttack; }
inline T GetPhysicalDefense() const noexcept { return _physicalDefense; }
inline T GetMagicalAttack() const noexcept { return _magicalAttack; }
inline T GetMagicalDefense() const noexcept { return _magicalDefense; }
inline T GetSpeed() const noexcept { return _speed; }
[[nodiscard]] inline T GetStat(Statistic stat) const {
switch (stat) {

View File

@ -1,22 +1,8 @@
#include "TypeLibrary.hpp"
#include <Arbutils/Assert.hpp>
#include <numeric>
using namespace CreatureLib::Library;
float TypeLibrary::GetEffectiveness(uint8_t attacking, const std::unordered_set<uint8_t>& defensive) const {
return std::accumulate(
defensive.begin(), defensive.end(), (float)1,
[this, attacking](float init, uint8_t defense) { return init * GetSingleEffectiveness(attacking, defense); });
}
float TypeLibrary::GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const {
return _effectiveness[attacking][defensive];
}
uint8_t TypeLibrary::GetTypeId(const ArbUt::CaseInsensitiveConstString& key) const { return _types.Get(key); }
uint8_t TypeLibrary::GetTypeId(uint32_t s) const { return _types.Get(s); }
uint8_t TypeLibrary::RegisterType(const ArbUt::CaseInsensitiveConstString& key) {
_types.Insert(key, _types.Count());
_effectiveness.Resize(_types.Count());

View File

@ -4,6 +4,7 @@
#include <Arbutils/Collections/Dictionary.hpp>
#include <Arbutils/Collections/List.hpp>
#include <Arbutils/ConstString.hpp>
#include <numeric>
#include <unordered_set>
#include <vector>
@ -15,10 +16,18 @@ namespace CreatureLib::Library {
public:
TypeLibrary(size_t initialCapacity = 20) : _types(ArbUt::Dictionary<uint32_t, uint8_t>(initialCapacity)) {}
uint8_t GetTypeId(const ArbUt::CaseInsensitiveConstString& s) const;
uint8_t GetTypeId(uint32_t s) const;
[[nodiscard]] float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const;
[[nodiscard]] float GetEffectiveness(uint8_t attacking, const std::unordered_set<uint8_t>& defensive) const;
inline uint8_t GetTypeId(const ArbUt::CaseInsensitiveConstString& key) const { return _types.Get(key); }
inline uint8_t GetTypeId(uint32_t s) const { return _types.Get(s); }
[[nodiscard]] inline float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const {
return _effectiveness[attacking][defensive];
}
[[nodiscard]] inline float GetEffectiveness(uint8_t attacking,
const std::unordered_set<uint8_t>& defensive) const {
return std::accumulate(defensive.begin(), defensive.end(), (float)1,
[this, attacking](float init, uint8_t defense) {
return init * GetSingleEffectiveness(attacking, defense);
});
}
uint8_t RegisterType(const ArbUt::CaseInsensitiveConstString& typeName);
uint8_t RegisterType(uint32_t typeHash);