Update to latest Arbutils, use new integer defines
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#include <Arbutils/Enum.hpp>
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
ENUM(AttackCategory, uint8_t, Physical, Magical, Status)
|
||||
ENUM(AttackCategory, u8, Physical, Magical, Status)
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_ATTACKCATEGORY_HPP
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#include "AttackData.hpp"
|
||||
|
||||
CreatureLib::Library::AttackData::AttackData(const ArbUt::StringView& name, uint8_t type,
|
||||
CreatureLib::Library::AttackCategory category, uint8_t power,
|
||||
uint8_t accuracy, uint8_t baseUsage,
|
||||
CreatureLib::Library::AttackTarget target, int8_t priority,
|
||||
const SecondaryEffect* effect, std::unordered_set<uint32_t> flags)
|
||||
CreatureLib::Library::AttackData::AttackData(const ArbUt::StringView& name, u8 type,
|
||||
CreatureLib::Library::AttackCategory category, u8 power, u8 accuracy,
|
||||
u8 baseUsage, CreatureLib::Library::AttackTarget target, i8 priority,
|
||||
const SecondaryEffect* effect, std::unordered_set<u32> flags)
|
||||
: _name(name), _type(type), _category(category), _basePower(power), _accuracy(accuracy), _baseUsages(baseUsage),
|
||||
_target(target), _priority(priority), _effect(effect), _flags(std::move(flags)) {}
|
||||
|
||||
@@ -10,30 +10,29 @@ namespace CreatureLib::Library {
|
||||
class AttackData {
|
||||
protected:
|
||||
ArbUt::StringView _name;
|
||||
uint8_t _type;
|
||||
u8 _type;
|
||||
AttackCategory _category;
|
||||
uint8_t _basePower;
|
||||
uint8_t _accuracy;
|
||||
uint8_t _baseUsages;
|
||||
u8 _basePower;
|
||||
u8 _accuracy;
|
||||
u8 _baseUsages;
|
||||
AttackTarget _target;
|
||||
int8_t _priority;
|
||||
i8 _priority;
|
||||
std::unique_ptr<const SecondaryEffect> _effect = nullptr;
|
||||
std::unordered_set<uint32_t> _flags;
|
||||
std::unordered_set<u32> _flags;
|
||||
|
||||
public:
|
||||
AttackData(const ArbUt::StringView& name, uint8_t type, AttackCategory category, uint8_t power,
|
||||
uint8_t accuracy, uint8_t baseUsage, AttackTarget target, int8_t priority,
|
||||
const SecondaryEffect* effect, std::unordered_set<uint32_t> flags);
|
||||
AttackData(const ArbUt::StringView& name, u8 type, AttackCategory category, u8 power, u8 accuracy, u8 baseUsage,
|
||||
AttackTarget target, i8 priority, const SecondaryEffect* effect, std::unordered_set<u32> flags);
|
||||
virtual ~AttackData() = default;
|
||||
|
||||
inline const ArbUt::StringView& GetName() const noexcept { return _name; }
|
||||
inline uint8_t GetType() const noexcept { return _type; }
|
||||
inline u8 GetType() const noexcept { return _type; }
|
||||
inline AttackCategory GetCategory() const noexcept { return _category; }
|
||||
inline uint8_t GetBasePower() const noexcept { return _basePower; }
|
||||
inline uint8_t GetAccuracy() const noexcept { return _accuracy; }
|
||||
inline uint8_t GetBaseUsages() const noexcept { return _baseUsages; }
|
||||
inline u8 GetBasePower() const noexcept { return _basePower; }
|
||||
inline u8 GetAccuracy() const noexcept { return _accuracy; }
|
||||
inline u8 GetBaseUsages() const noexcept { return _baseUsages; }
|
||||
inline AttackTarget GetTarget() const noexcept { return _target; }
|
||||
inline int8_t GetPriority() const noexcept { return _priority; }
|
||||
inline i8 GetPriority() const noexcept { return _priority; }
|
||||
inline bool HasSecondaryEffect() const noexcept {
|
||||
return _effect != nullptr && !_effect->GetEffectName().IsEmpty();
|
||||
}
|
||||
@@ -42,9 +41,7 @@ namespace CreatureLib::Library {
|
||||
inline bool HasFlag(const ArbUt::StringView& 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();
|
||||
}
|
||||
inline bool HasFlag(u32 keyHash) const noexcept { return this->_flags.find(keyHash) != this->_flags.end(); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <Arbutils/Enum.hpp>
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
ENUM(AttackTarget, uint8_t, Adjacent, AdjacentAlly, AdjacentAllySelf, AdjacentOpponent,
|
||||
ENUM(AttackTarget, u8, Adjacent, AdjacentAlly, AdjacentAllySelf, AdjacentOpponent,
|
||||
|
||||
All, AllAdjacent, AllAdjacentOpponent, AllAlly, AllOpponent,
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
namespace CreatureLib::Library {
|
||||
template <class T> class BaseLibrary {
|
||||
protected:
|
||||
ArbUt::Dictionary<uint32_t, std::unique_ptr<const T>> _values;
|
||||
ArbUt::List<uint32_t> _listValues;
|
||||
ArbUt::Dictionary<u32, std::unique_ptr<const T>> _values;
|
||||
ArbUt::List<u32> _listValues;
|
||||
|
||||
public:
|
||||
BaseLibrary(size_t initialCapacity = 32) : _values(initialCapacity), _listValues(initialCapacity) {}
|
||||
@@ -23,7 +23,7 @@ namespace CreatureLib::Library {
|
||||
_values.GetStdMap().insert({key.GetHash(), std::unique_ptr<const T>(value)});
|
||||
_listValues.Append(key);
|
||||
}
|
||||
inline virtual void Insert(uint32_t hashedKey, const T* value) {
|
||||
inline virtual void Insert(u32 hashedKey, const T* value) {
|
||||
EnsureNotNull(value)
|
||||
_values.GetStdMap().insert({hashedKey, std::unique_ptr<const T>(value)});
|
||||
_listValues.Append(hashedKey);
|
||||
@@ -32,18 +32,22 @@ namespace CreatureLib::Library {
|
||||
inline void Delete(const ArbUt::StringView& key) noexcept {
|
||||
_values.erase(key.GetHash());
|
||||
auto k = _listValues.IndexOf(key);
|
||||
_listValues.Remove(k);
|
||||
if (k.has_value()) {
|
||||
_listValues.Remove(k.value());
|
||||
}
|
||||
}
|
||||
inline void Delete(uint32_t hashedKey) noexcept {
|
||||
inline void Delete(u32 hashedKey) noexcept {
|
||||
_values.Remove(hashedKey);
|
||||
auto k = _listValues.IndexOf(hashedKey);
|
||||
_listValues.Remove(k);
|
||||
if (k.has_value()) {
|
||||
_listValues.Remove(k.value());
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<ArbUt::BorrowedPtr<const T>> TryGet(const ArbUt::BasicStringView& name) const noexcept {
|
||||
return TryGet(name.GetHash());
|
||||
}
|
||||
std::optional<ArbUt::BorrowedPtr<const T>> TryGet(uint32_t hashedKey) const noexcept {
|
||||
std::optional<ArbUt::BorrowedPtr<const T>> TryGet(u32 hashedKey) const noexcept {
|
||||
auto find = _values.GetStdMap().find(hashedKey);
|
||||
if (find == _values.GetStdMap().end())
|
||||
return {};
|
||||
@@ -53,29 +57,25 @@ namespace CreatureLib::Library {
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> Get(const ArbUt::BasicStringView& name) const {
|
||||
return _values.Get(name.GetHash());
|
||||
}
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> Get(uint32_t hashedKey) const {
|
||||
return _values.Get(hashedKey);
|
||||
}
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> Get(u32 hashedKey) const { return _values.Get(hashedKey); }
|
||||
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> operator[](const ArbUt::BasicStringView& name) const {
|
||||
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>>&
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> operator[](u32 hashedKey) const { return Get(hashedKey); }
|
||||
[[nodiscard]] inline const ArbUt::Dictionary<u32, const std::unique_ptr<const T>>&
|
||||
GetIterator() const noexcept {
|
||||
return _values;
|
||||
}
|
||||
|
||||
using const_iterator = typename std::unordered_map<uint32_t, ArbUt::BorrowedPtr<const T>>::const_iterator;
|
||||
using const_iterator = typename std::unordered_map<u32, ArbUt::BorrowedPtr<const T>>::const_iterator;
|
||||
|
||||
inline const_iterator begin() const {
|
||||
return reinterpret_cast<const std::unordered_map<uint32_t, ArbUt::BorrowedPtr<const T>>&>(
|
||||
_values.GetStdMap())
|
||||
return reinterpret_cast<const std::unordered_map<u32, ArbUt::BorrowedPtr<const T>>&>(_values.GetStdMap())
|
||||
.begin();
|
||||
}
|
||||
inline const_iterator end() const {
|
||||
return reinterpret_cast<const std::unordered_map<uint32_t, ArbUt::BorrowedPtr<const T>>&>(
|
||||
_values.GetStdMap())
|
||||
return reinterpret_cast<const std::unordered_map<u32, ArbUt::BorrowedPtr<const T>>&>(_values.GetStdMap())
|
||||
.end();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,17 +5,17 @@ using namespace CreatureLib::Library;
|
||||
|
||||
struct CreatureSpecies::impl {
|
||||
const ArbUt::StringView _name;
|
||||
uint16_t _id;
|
||||
u16 _id;
|
||||
float _genderRate;
|
||||
const ArbUt::StringView _growthRate;
|
||||
uint8_t _captureRate;
|
||||
u8 _captureRate;
|
||||
|
||||
ArbUt::Dictionary<uint32_t, ArbUt::UniquePtr<const SpeciesVariant>> _variantsLookup;
|
||||
ArbUt::Dictionary<u32, ArbUt::UniquePtr<const SpeciesVariant>> _variantsLookup;
|
||||
ArbUt::List<ArbUt::BorrowedPtr<const SpeciesVariant>> _variantsList;
|
||||
std::unordered_set<uint32_t> _flags;
|
||||
std::unordered_set<u32> _flags;
|
||||
|
||||
impl(uint16_t id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant, float genderRatio,
|
||||
const ArbUt::StringView& growthRate, uint8_t captureRate, std::unordered_set<uint32_t> flags)
|
||||
impl(u16 id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant, float genderRatio,
|
||||
const ArbUt::StringView& growthRate, u8 captureRate, std::unordered_set<u32> flags)
|
||||
: _name(name), _id(id), _genderRate(genderRatio), _growthRate(growthRate), _captureRate(captureRate),
|
||||
_variantsLookup(1), _variantsList(1), _flags(std::move(flags)) {
|
||||
EnsureNotNull(defaultVariant)
|
||||
@@ -24,20 +24,20 @@ struct CreatureSpecies::impl {
|
||||
|
||||
~impl() { _variantsLookup.Clear(); }
|
||||
|
||||
inline uint16_t GetId() const noexcept { return _id; }
|
||||
inline u16 GetId() const noexcept { return _id; }
|
||||
inline float GetGenderRate() const noexcept { return _genderRate; }
|
||||
inline const ArbUt::StringView& GetGrowthRate() const noexcept { return _growthRate; }
|
||||
inline uint8_t GetCaptureRate() const noexcept { return _captureRate; }
|
||||
inline u8 GetCaptureRate() const noexcept { return _captureRate; }
|
||||
|
||||
[[nodiscard]] inline bool HasVariant(const ArbUt::BasicStringView& key) const noexcept {
|
||||
return _variantsLookup.Has(key);
|
||||
}
|
||||
[[nodiscard]] inline bool HasVariant(uint32_t hash) const noexcept { return _variantsLookup.Has(hash); }
|
||||
[[nodiscard]] inline bool HasVariant(u32 hash) const noexcept { return _variantsLookup.Has(hash); }
|
||||
[[nodiscard]] inline std::optional<ArbUt::BorrowedPtr<const SpeciesVariant>>
|
||||
TryGetVariant(const ArbUt::BasicStringView& name) const noexcept {
|
||||
return TryGetVariant(name.GetHash());
|
||||
}
|
||||
[[nodiscard]] std::optional<ArbUt::BorrowedPtr<const SpeciesVariant>> TryGetVariant(uint32_t hash) const noexcept {
|
||||
[[nodiscard]] std::optional<ArbUt::BorrowedPtr<const SpeciesVariant>> TryGetVariant(u32 hash) const noexcept {
|
||||
auto find = _variantsLookup.GetStdMap().find(hash);
|
||||
if (find == _variantsLookup.end())
|
||||
return {};
|
||||
@@ -46,7 +46,7 @@ struct CreatureSpecies::impl {
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(const ArbUt::BasicStringView& key) const {
|
||||
return _variantsLookup.Get(key).GetRaw();
|
||||
}
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(uint32_t key) const {
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(u32 key) const {
|
||||
return _variantsLookup.Get(key).GetRaw();
|
||||
}
|
||||
[[nodiscard]] Gender GetRandomGender(ArbUt::Random& rand) const noexcept {
|
||||
@@ -73,40 +73,38 @@ struct CreatureSpecies::impl {
|
||||
inline bool HasFlag(const ArbUt::StringView& 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(); }
|
||||
inline bool HasFlag(u32 keyHash) const noexcept { return this->_flags.find(keyHash) != this->_flags.end(); }
|
||||
};
|
||||
|
||||
CreatureSpecies::CreatureSpecies(uint16_t id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant,
|
||||
float genderRatio, const ArbUt::StringView& growthRate, uint8_t captureRate,
|
||||
std::unordered_set<uint32_t> flags)
|
||||
CreatureSpecies::CreatureSpecies(u16 id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant,
|
||||
float genderRatio, const ArbUt::StringView& growthRate, u8 captureRate,
|
||||
std::unordered_set<u32> flags)
|
||||
: _impl(new impl(id, name, defaultVariant, genderRatio, growthRate, captureRate, flags)) {}
|
||||
|
||||
#define ImplGetter(type, func) \
|
||||
type CreatureSpecies::func() const noexcept { return _impl->func(); }
|
||||
|
||||
CreatureSpecies::~CreatureSpecies() = default;
|
||||
ImplGetter(uint16_t, GetId);
|
||||
ImplGetter(u16, GetId);
|
||||
ImplGetter(float, GetGenderRate);
|
||||
ImplGetter(const ArbUt::StringView&, GetGrowthRate);
|
||||
ImplGetter(uint8_t, GetCaptureRate);
|
||||
ImplGetter(u8, GetCaptureRate);
|
||||
ImplGetter(const ArbUt::StringView&, GetName);
|
||||
|
||||
bool CreatureSpecies::HasVariant(const ArbUt::BasicStringView& key) const noexcept { return _impl->HasVariant(key); }
|
||||
bool CreatureSpecies::HasVariant(uint32_t hash) const noexcept { return _impl->HasVariant(hash); }
|
||||
bool CreatureSpecies::HasVariant(u32 hash) const noexcept { return _impl->HasVariant(hash); }
|
||||
|
||||
std::optional<ArbUt::BorrowedPtr<const SpeciesVariant>>
|
||||
CreatureSpecies::TryGetVariant(const ArbUt::BasicStringView& name) const noexcept {
|
||||
return _impl->TryGetVariant(name);
|
||||
}
|
||||
std::optional<ArbUt::BorrowedPtr<const SpeciesVariant>> CreatureSpecies::TryGetVariant(uint32_t hash) const noexcept {
|
||||
std::optional<ArbUt::BorrowedPtr<const SpeciesVariant>> CreatureSpecies::TryGetVariant(u32 hash) const noexcept {
|
||||
return _impl->TryGetVariant(hash);
|
||||
}
|
||||
ArbUt::BorrowedPtr<const SpeciesVariant> CreatureSpecies::GetVariant(const ArbUt::BasicStringView& key) const {
|
||||
return _impl->GetVariant(key);
|
||||
}
|
||||
ArbUt::BorrowedPtr<const SpeciesVariant> CreatureSpecies::GetVariant(uint32_t key) const {
|
||||
return _impl->GetVariant(key);
|
||||
}
|
||||
ArbUt::BorrowedPtr<const SpeciesVariant> CreatureSpecies::GetVariant(u32 key) const { return _impl->GetVariant(key); }
|
||||
Gender CreatureSpecies::GetRandomGender(ArbUt::Random& rand) const noexcept { return _impl->GetRandomGender(rand); }
|
||||
void CreatureSpecies::SetVariant(const ArbUt::StringView& name, const SpeciesVariant* variant) {
|
||||
_impl->SetVariant(name, variant);
|
||||
@@ -116,4 +114,4 @@ const ArbUt::List<ArbUt::BorrowedPtr<const SpeciesVariant>>& CreatureSpecies::Ge
|
||||
}
|
||||
|
||||
bool CreatureSpecies::HasFlag(const ArbUt::StringView& key) const noexcept { return _impl->HasFlag(key); }
|
||||
bool CreatureSpecies::HasFlag(uint32_t keyHash) const noexcept { return _impl->HasFlag(keyHash); }
|
||||
bool CreatureSpecies::HasFlag(u32 keyHash) const noexcept { return _impl->HasFlag(keyHash); }
|
||||
|
||||
@@ -23,15 +23,14 @@ namespace CreatureLib::Library {
|
||||
/// @param captureRate The chance to capture the creature species, between 0 and 255. 255 means instant capture,
|
||||
/// 0 means impossible to capture.
|
||||
/// @param flags A set of flags for use by the developer. These can be used for easy grouping.
|
||||
CreatureSpecies(uint16_t id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant,
|
||||
float genderRatio, const ArbUt::StringView& growthRate, uint8_t captureRate,
|
||||
std::unordered_set<uint32_t> flags = {});
|
||||
CreatureSpecies(u16 id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant, float genderRatio,
|
||||
const ArbUt::StringView& growthRate, u8 captureRate, std::unordered_set<u32> flags = {});
|
||||
|
||||
virtual ~CreatureSpecies();
|
||||
|
||||
/// @brief Returns the unique id of the creature species.
|
||||
/// @return The unique id of the creature species
|
||||
uint16_t GetId() const noexcept;
|
||||
u16 GetId() const noexcept;
|
||||
/// @brief Returns the name of the species.
|
||||
/// @return The name of the species.
|
||||
[[nodiscard]] const ArbUt::StringView& GetName() const noexcept;
|
||||
@@ -45,7 +44,7 @@ namespace CreatureLib::Library {
|
||||
/// @brief Returns the capture rate of the creature species.
|
||||
/// @return The base capture rate of the creature species. 255 means instant capture, 0 means impossible to
|
||||
/// capture.
|
||||
uint8_t GetCaptureRate() const noexcept;
|
||||
u8 GetCaptureRate() const noexcept;
|
||||
|
||||
/// @brief Checks whether the species contains a variant with a specific name.
|
||||
/// @param key The name of the variant that's being looked for.
|
||||
@@ -55,7 +54,7 @@ namespace CreatureLib::Library {
|
||||
/// @param hash The string hash of the variant that's being looked for. This hash can be retrieved from the
|
||||
/// StringView class.
|
||||
/// @return True if the species contains the variant, false otherwise.
|
||||
[[nodiscard]] bool HasVariant(uint32_t hash) const noexcept;
|
||||
[[nodiscard]] bool HasVariant(u32 hash) const noexcept;
|
||||
/// @brief Try to get a variant of the species with a specific name.
|
||||
/// @param name The name of the variant that's being looked for.
|
||||
/// @param out If a variant is found, it will be put in this variable. If not, this will remain unchanged.
|
||||
@@ -67,8 +66,7 @@ namespace CreatureLib::Library {
|
||||
/// StringView class.
|
||||
/// @param out If a variant is found, it will be put in this variable. If not, this will remain unchanged.
|
||||
/// @return True if the species contains the variant, false otherwise.
|
||||
[[nodiscard]] std::optional<ArbUt::BorrowedPtr<const SpeciesVariant>>
|
||||
TryGetVariant(uint32_t hash) const noexcept;
|
||||
[[nodiscard]] std::optional<ArbUt::BorrowedPtr<const SpeciesVariant>> TryGetVariant(u32 hash) const noexcept;
|
||||
/// @brief Returns a variant with a specific name. Throws if no variant with the name exists.
|
||||
/// @param key The name of the variant that's being looked for.
|
||||
/// @return The specified variant.
|
||||
@@ -76,7 +74,7 @@ namespace CreatureLib::Library {
|
||||
/// @brief Returns a variant with a specific name. Throws if no variant with the name exists.
|
||||
/// @param key The string hash of the variant that's being looked for.
|
||||
/// @return The specified variant.
|
||||
[[nodiscard]] ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(uint32_t key) const;
|
||||
[[nodiscard]] ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(u32 key) const;
|
||||
/// @brief Returns a random gender based on the gender ratio of the species.
|
||||
/// @param rand A random number generator class.
|
||||
/// @return A random gender. If gender ratio is -1 this will return Genderless, otherwise it will be either male
|
||||
@@ -99,7 +97,7 @@ namespace CreatureLib::Library {
|
||||
/// @brief Checks whether the species has a specific flag.
|
||||
/// @param keyHash The flag to check for.
|
||||
/// @return True if the species has the flag, false otherwise.
|
||||
bool HasFlag(uint32_t keyHash) const noexcept;
|
||||
bool HasFlag(u32 keyHash) const noexcept;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace CreatureLib::Library {
|
||||
inline bool HasAttacksForLevel(level_int_t level) const noexcept { return _learnedByLevel.Has(level); }
|
||||
inline const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& GetAttacksForLevel(level_int_t level) const {
|
||||
if (!_learnedByLevel.Has(level)) {
|
||||
THROW("No attacks found for level ", (uint32_t)level, ".");
|
||||
THROW("No attacks found for level ", (u32)level, ".");
|
||||
}
|
||||
return _learnedByLevel.Get(level);
|
||||
}
|
||||
|
||||
@@ -6,20 +6,19 @@ namespace CreatureLib::Library {
|
||||
ArbUt::StringView _name;
|
||||
float _height;
|
||||
float _weight;
|
||||
uint32_t _baseExperience;
|
||||
ArbUt::List<uint8_t> _types;
|
||||
Library::StatisticSet<uint16_t> _baseStatistics;
|
||||
u32 _baseExperience;
|
||||
ArbUt::List<u8> _types;
|
||||
Library::StatisticSet<u16> _baseStatistics;
|
||||
ArbUt::List<ArbUt::BorrowedPtr<const Talent>> _talents;
|
||||
ArbUt::List<ArbUt::BorrowedPtr<const Talent>> _secretTalents;
|
||||
std::unique_ptr<const LearnableAttacks> _attacks;
|
||||
std::unordered_set<uint32_t> _flags;
|
||||
std::unordered_set<u32> _flags;
|
||||
|
||||
public:
|
||||
impl(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience,
|
||||
ArbUt::List<uint8_t> types, Library::StatisticSet<uint16_t> baseStats,
|
||||
ArbUt::List<ArbUt::BorrowedPtr<const Talent>> talents,
|
||||
impl(const ArbUt::StringView& name, float height, float weight, u32 baseExperience, ArbUt::List<u8> types,
|
||||
Library::StatisticSet<u16> baseStats, ArbUt::List<ArbUt::BorrowedPtr<const Talent>> talents,
|
||||
ArbUt::List<ArbUt::BorrowedPtr<const Talent>> secretTalents, const LearnableAttacks* attacks,
|
||||
std::unordered_set<uint32_t> flags)
|
||||
std::unordered_set<u32> flags)
|
||||
: _name(name), _height(height), _weight(weight), _baseExperience(baseExperience),
|
||||
_types(std::move((types))), _baseStatistics(baseStats), _talents(std::move(talents)),
|
||||
_secretTalents(std::move(secretTalents)), _attacks(attacks), _flags(std::move(flags)){};
|
||||
@@ -27,14 +26,12 @@ namespace CreatureLib::Library {
|
||||
inline const ArbUt::StringView& GetName() const { return _name; }
|
||||
inline float GetHeight() const { return _height; }
|
||||
inline float GetWeight() const { return _weight; }
|
||||
inline uint32_t GetBaseExperience() const { return _baseExperience; }
|
||||
inline u32 GetBaseExperience() const { return _baseExperience; }
|
||||
|
||||
[[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 u8 GetType(size_t index) const { return _types[index]; }
|
||||
[[nodiscard]] inline const ArbUt::List<u8>& GetTypes() const { return _types; }
|
||||
[[nodiscard]] inline u16 GetStatistic(Library::Statistic stat) const { return _baseStatistics.GetStat(stat); }
|
||||
[[nodiscard]] inline size_t GetTalentCount() const noexcept { return _talents.Count(); }
|
||||
[[nodiscard]] inline size_t GetSecretTalentCount() const noexcept { return _secretTalents.Count(); }
|
||||
[[nodiscard]] const ArbUt::BorrowedPtr<const Talent>& GetTalent(const TalentIndex& index) const {
|
||||
@@ -95,16 +92,14 @@ namespace CreatureLib::Library {
|
||||
inline bool HasFlag(const ArbUt::StringView& 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();
|
||||
}
|
||||
inline bool HasFlag(u32 keyHash) const noexcept { return this->_flags.find(keyHash) != this->_flags.end(); }
|
||||
};
|
||||
|
||||
SpeciesVariant::SpeciesVariant(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience,
|
||||
const ArbUt::List<uint8_t>& types, StatisticSet<uint16_t> baseStats,
|
||||
SpeciesVariant::SpeciesVariant(const ArbUt::StringView& name, float height, float weight, u32 baseExperience,
|
||||
const ArbUt::List<u8>& types, StatisticSet<u16> baseStats,
|
||||
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& talents,
|
||||
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& secretTalents,
|
||||
const LearnableAttacks* attacks, const std::unordered_set<uint32_t>& flags)
|
||||
const LearnableAttacks* attacks, const std::unordered_set<u32>& flags)
|
||||
: _impl(new impl(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, attacks,
|
||||
flags)) {}
|
||||
SpeciesVariant::~SpeciesVariant() = default;
|
||||
@@ -115,11 +110,11 @@ namespace CreatureLib::Library {
|
||||
ImplGetter(const ArbUt::StringView&, GetName);
|
||||
ImplGetter(float, GetHeight);
|
||||
ImplGetter(float, GetWeight);
|
||||
ImplGetter(uint32_t, GetBaseExperience);
|
||||
ImplGetter(u32, GetBaseExperience);
|
||||
ImplGetter(size_t, GetTypeCount);
|
||||
uint8_t SpeciesVariant::GetType(size_t index) const { return _impl->GetType(index); }
|
||||
ImplGetter(const ArbUt::List<uint8_t>&, GetTypes);
|
||||
uint16_t SpeciesVariant::GetStatistic(Library::Statistic stat) const noexcept { return _impl->GetStatistic(stat); }
|
||||
u8 SpeciesVariant::GetType(size_t index) const { return _impl->GetType(index); }
|
||||
ImplGetter(const ArbUt::List<u8>&, GetTypes);
|
||||
u16 SpeciesVariant::GetStatistic(Library::Statistic stat) const noexcept { return _impl->GetStatistic(stat); }
|
||||
|
||||
ImplGetter(size_t, GetTalentCount);
|
||||
ImplGetter(size_t, GetSecretTalentCount);
|
||||
@@ -140,5 +135,5 @@ namespace CreatureLib::Library {
|
||||
ImplGetter(const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>&, GetSecretTalents);
|
||||
|
||||
bool SpeciesVariant::HasFlag(const ArbUt::StringView& key) const noexcept { return _impl->HasFlag(key); }
|
||||
bool SpeciesVariant::HasFlag(uint32_t keyHash) const noexcept { return _impl->HasFlag(keyHash); }
|
||||
bool SpeciesVariant::HasFlag(u32 keyHash) const noexcept { return _impl->HasFlag(keyHash); }
|
||||
}
|
||||
|
||||
@@ -27,11 +27,11 @@ namespace CreatureLib::Library {
|
||||
/// scripts when battling.
|
||||
/// @param attacks The attacks that this variant can learn.
|
||||
/// @param flags A set of flags for use by the developer. These can be used for easy grouping.
|
||||
SpeciesVariant(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience,
|
||||
const ArbUt::List<uint8_t>& types, Library::StatisticSet<uint16_t> baseStats,
|
||||
SpeciesVariant(const ArbUt::StringView& name, float height, float weight, u32 baseExperience,
|
||||
const ArbUt::List<u8>& types, Library::StatisticSet<u16> baseStats,
|
||||
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& talents,
|
||||
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& secretTalents,
|
||||
const LearnableAttacks* attacks, const std::unordered_set<uint32_t>& flags = {});
|
||||
const LearnableAttacks* attacks, const std::unordered_set<u32>& flags = {});
|
||||
virtual ~SpeciesVariant();
|
||||
|
||||
/// @brief Returns the unique name of the variant.
|
||||
@@ -45,7 +45,7 @@ namespace CreatureLib::Library {
|
||||
float GetWeight() const noexcept;
|
||||
/// @brief Returns the amount of base experience gained when defeating a creature with this variant.
|
||||
/// @return The amount of base experience gained when defeating a creature with this variant.
|
||||
uint32_t GetBaseExperience() const noexcept;
|
||||
u32 GetBaseExperience() const noexcept;
|
||||
|
||||
/// @brief Returns the amount of types this variant has.
|
||||
/// @return The amount of types this variant has.
|
||||
@@ -53,14 +53,14 @@ namespace CreatureLib::Library {
|
||||
/// @brief Returns a type index at a specified index.
|
||||
/// @param index The index of the type requested.
|
||||
/// @return A type index, as defined in TypeLibrary.
|
||||
[[nodiscard]] uint8_t GetType(size_t index) const;
|
||||
[[nodiscard]] u8 GetType(size_t index) const;
|
||||
/// @brief Returns a list of the types on this variant.
|
||||
/// @return A list of types on the variant,
|
||||
[[nodiscard]] const ArbUt::List<uint8_t>& GetTypes() const noexcept;
|
||||
[[nodiscard]] const ArbUt::List<u8>& GetTypes() const noexcept;
|
||||
/// @brief Returns the value of a base statistic.
|
||||
/// @param stat The desired statistic.
|
||||
/// @return The base statistic value.
|
||||
[[nodiscard]] uint16_t GetStatistic(Library::Statistic stat) const noexcept;
|
||||
[[nodiscard]] u16 GetStatistic(Library::Statistic stat) const noexcept;
|
||||
|
||||
/// @brief Returns the amount of talents this variant has.
|
||||
/// @return The amount of talents this variant has.
|
||||
@@ -102,7 +102,7 @@ namespace CreatureLib::Library {
|
||||
/// @brief Checks whether the species has a specific flag.
|
||||
/// @param keyHash The flag to check for.
|
||||
/// @return True if the species has the flag, false otherwise.
|
||||
bool HasFlag(uint32_t keyHash) const noexcept;
|
||||
bool HasFlag(u32 keyHash) const noexcept;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,17 +10,17 @@ namespace CreatureLib::Library {
|
||||
/// @brief Initialises a Talent Index from whether or not this is a secret talent, and it's index.
|
||||
/// @param secret Whether or not this is a secret talent.
|
||||
/// @param index The index of the talent on the species variant.
|
||||
inline TalentIndex(bool secret, uint8_t index) noexcept : _secret(secret), _index(index) {}
|
||||
inline TalentIndex(bool secret, u8 index) noexcept : _secret(secret), _index(index) {}
|
||||
/// @brief Returns whether or not this is a secret talent.
|
||||
/// @return Whether or not this is a secret talent.
|
||||
[[nodiscard]] constexpr inline bool IsSecret() const noexcept { return _secret; }
|
||||
/// @brief Returns the index of the talent on the species variant.
|
||||
/// @return The index of the talent on the species variant.
|
||||
[[nodiscard]] constexpr inline uint8_t GetIndex() const noexcept { return _index; }
|
||||
[[nodiscard]] constexpr inline u8 GetIndex() const noexcept { return _index; }
|
||||
|
||||
private:
|
||||
bool _secret = false;
|
||||
uint8_t _index;
|
||||
u8 _index;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -12,12 +12,12 @@ namespace CreatureLib::Library {
|
||||
class EffectParameter {
|
||||
private:
|
||||
EffectParameterType _type = EffectParameterType::None;
|
||||
std::variant<bool, int64_t, float, ArbUt::StringView> _value;
|
||||
std::variant<bool, i64, float, ArbUt::StringView> _value;
|
||||
|
||||
public:
|
||||
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(i64 i) : _type(EffectParameterType::Int), _value(i){};
|
||||
inline explicit EffectParameter(float f) : _type(EffectParameterType::Float), _value(f){};
|
||||
inline explicit EffectParameter(const ArbUt::StringView& s) : _type(EffectParameterType::String), _value(s){};
|
||||
EffectParameter(const EffectParameter& other) = delete;
|
||||
@@ -30,19 +30,19 @@ namespace CreatureLib::Library {
|
||||
}
|
||||
return std::get<bool>(_value);
|
||||
}
|
||||
int64_t AsInt() const {
|
||||
i64 AsInt() const {
|
||||
if (_type != EffectParameterType::Int) {
|
||||
if (_type == EffectParameterType::Float) {
|
||||
return static_cast<int64_t>(std::get<float>(_value));
|
||||
return static_cast<i64>(std::get<float>(_value));
|
||||
}
|
||||
THROW("Cast effect parameter to int, but was ", EffectParameterTypeHelper::ToString(_type));
|
||||
}
|
||||
return std::get<int64_t>(_value);
|
||||
return std::get<i64>(_value);
|
||||
}
|
||||
float AsFloat() const {
|
||||
if (_type != EffectParameterType::Float) {
|
||||
if (_type == EffectParameterType::Int) {
|
||||
return static_cast<float>(std::get<int64_t>(_value));
|
||||
return static_cast<float>(std::get<i64>(_value));
|
||||
}
|
||||
THROW("Cast effect parameter to float, but was ", EffectParameterTypeHelper::ToString(_type));
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace CreatureLib::Library {
|
||||
\brief Might be somewhat controversial nowadays, but as many creature battling games only have two genders, we'll
|
||||
hardcode those.
|
||||
*/
|
||||
ENUM(Gender, uint8_t, Male, Female, Genderless)
|
||||
ENUM(Gender, u8, Male, Female, Genderless)
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_GENDER_HPP
|
||||
|
||||
@@ -7,18 +7,18 @@
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
class ExternGrowthRate : public GrowthRate {
|
||||
level_int_t (*_calcLevel)(uint32_t experience);
|
||||
uint32_t (*_calcExperience)(level_int_t level);
|
||||
level_int_t (*_calcLevel)(u32 experience);
|
||||
u32 (*_calcExperience)(level_int_t level);
|
||||
|
||||
public:
|
||||
inline ExternGrowthRate(level_int_t (*calcLevel)(uint32_t), uint32_t (*calcExperience)(level_int_t level))
|
||||
inline ExternGrowthRate(level_int_t (*calcLevel)(u32), u32 (*calcExperience)(level_int_t level))
|
||||
: _calcLevel(calcLevel), _calcExperience(calcExperience) {
|
||||
EnsureNotNull(calcLevel)
|
||||
EnsureNotNull(calcExperience)
|
||||
}
|
||||
|
||||
level_int_t CalculateLevel(uint32_t experience) const override { return _calcLevel(experience); }
|
||||
uint32_t CalculateExperience(level_int_t level) const override { return _calcExperience(level); }
|
||||
level_int_t CalculateLevel(u32 experience) const override { return _calcLevel(experience); }
|
||||
u32 CalculateExperience(level_int_t level) const override { return _calcExperience(level); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ namespace CreatureLib::Library {
|
||||
public:
|
||||
virtual ~GrowthRate() = default;
|
||||
|
||||
[[nodiscard]] virtual level_int_t CalculateLevel(uint32_t experience) const = 0;
|
||||
[[nodiscard]] virtual uint32_t CalculateExperience(level_int_t level) const = 0;
|
||||
[[nodiscard]] virtual level_int_t CalculateLevel(u32 experience) const = 0;
|
||||
[[nodiscard]] virtual u32 CalculateExperience(level_int_t level) const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include <Arbutils/Exception.hpp>
|
||||
#include "../Exceptions/CreatureException.hpp"
|
||||
|
||||
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const ArbUt::BasicStringView& growthRate,
|
||||
uint32_t experience) const {
|
||||
u8 CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const ArbUt::BasicStringView& growthRate,
|
||||
u32 experience) const {
|
||||
auto find = _growthRates.find(growthRate);
|
||||
if (find == _growthRates.end()) {
|
||||
THROW("Invalid growth rate was requested.");
|
||||
@@ -11,7 +11,7 @@ uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const ArbUt::Bas
|
||||
return find->second->CalculateLevel(experience);
|
||||
}
|
||||
|
||||
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(uint32_t hash, uint32_t experience) const {
|
||||
u8 CreatureLib::Library::GrowthRateLibrary::CalculateLevel(u32 hash, u32 experience) const {
|
||||
auto find = _growthRates.find(hash);
|
||||
if (find == _growthRates.end()) {
|
||||
THROW("Invalid growth rate was requested.");
|
||||
@@ -19,8 +19,8 @@ uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(uint32_t hash, u
|
||||
return find->second->CalculateLevel(experience);
|
||||
}
|
||||
|
||||
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ArbUt::BasicStringView& growthRate,
|
||||
level_int_t level) const {
|
||||
u32 CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ArbUt::BasicStringView& growthRate,
|
||||
level_int_t level) const {
|
||||
auto find = _growthRates.find(growthRate);
|
||||
if (find == _growthRates.end()) {
|
||||
THROW("Invalid growth rate was requested.");
|
||||
@@ -28,7 +28,7 @@ uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ArbU
|
||||
return find->second->CalculateExperience(level);
|
||||
}
|
||||
|
||||
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(uint32_t hash, level_int_t level) const {
|
||||
u32 CreatureLib::Library::GrowthRateLibrary::CalculateExperience(u32 hash, level_int_t level) const {
|
||||
auto find = _growthRates.find(hash);
|
||||
if (find == _growthRates.end()) {
|
||||
THROW("Invalid growth rate was requested.");
|
||||
@@ -41,6 +41,6 @@ void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const ArbUt::StringV
|
||||
_growthRates.insert({name, std::unique_ptr<const GrowthRate>(rate)});
|
||||
}
|
||||
|
||||
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(uint32_t hash, CreatureLib::Library::GrowthRate* rate) {
|
||||
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(u32 hash, CreatureLib::Library::GrowthRate* rate) {
|
||||
_growthRates.insert({hash, std::unique_ptr<const GrowthRate>(rate)});
|
||||
}
|
||||
|
||||
@@ -8,20 +8,20 @@
|
||||
namespace CreatureLib::Library {
|
||||
class GrowthRateLibrary {
|
||||
private:
|
||||
std::unordered_map<uint32_t, std::unique_ptr<const GrowthRate>> _growthRates;
|
||||
std::unordered_map<u32, std::unique_ptr<const GrowthRate>> _growthRates;
|
||||
|
||||
public:
|
||||
GrowthRateLibrary(size_t initialCapacity = 10)
|
||||
: _growthRates(std::unordered_map<uint32_t, std::unique_ptr<const GrowthRate>>(initialCapacity)) {}
|
||||
: _growthRates(std::unordered_map<u32, std::unique_ptr<const GrowthRate>>(initialCapacity)) {}
|
||||
|
||||
virtual ~GrowthRateLibrary() = default;
|
||||
|
||||
[[nodiscard]] level_int_t CalculateLevel(const ArbUt::BasicStringView& growthRate, uint32_t experience) const;
|
||||
[[nodiscard]] level_int_t CalculateLevel(uint32_t hash, uint32_t experience) const;
|
||||
[[nodiscard]] uint32_t CalculateExperience(const ArbUt::BasicStringView& growthRate, level_int_t level) const;
|
||||
[[nodiscard]] uint32_t CalculateExperience(uint32_t hash, level_int_t level) const;
|
||||
[[nodiscard]] level_int_t CalculateLevel(const ArbUt::BasicStringView& growthRate, u32 experience) const;
|
||||
[[nodiscard]] level_int_t CalculateLevel(u32 hash, u32 experience) const;
|
||||
[[nodiscard]] u32 CalculateExperience(const ArbUt::BasicStringView& growthRate, level_int_t level) const;
|
||||
[[nodiscard]] u32 CalculateExperience(u32 hash, level_int_t level) const;
|
||||
|
||||
void AddGrowthRate(uint32_t hash, GrowthRate* rate);
|
||||
void AddGrowthRate(u32 hash, GrowthRate* rate);
|
||||
void AddGrowthRate(const ArbUt::StringView& name, GrowthRate* rate);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
namespace CreatureLib::Library {
|
||||
class LookupGrowthRate : public GrowthRate {
|
||||
protected:
|
||||
ArbUt::List<uint32_t> _experience;
|
||||
ArbUt::List<u32> _experience;
|
||||
|
||||
public:
|
||||
LookupGrowthRate(const ArbUt::List<uint32_t>& experience) : _experience(experience) {}
|
||||
LookupGrowthRate(const ArbUt::List<u32>& experience) : _experience(experience) {}
|
||||
|
||||
level_int_t CalculateLevel(uint32_t experience) const override {
|
||||
level_int_t CalculateLevel(u32 experience) const override {
|
||||
for (level_int_t i = 0; i < (level_int_t)_experience.Count(); i++) {
|
||||
if (_experience[i] > experience) {
|
||||
return i;
|
||||
@@ -21,7 +21,7 @@ namespace CreatureLib::Library {
|
||||
return _experience.Count() - 1;
|
||||
}
|
||||
|
||||
uint32_t CalculateExperience(level_int_t level) const override { return _experience[level - 1]; }
|
||||
u32 CalculateExperience(level_int_t level) const override { return _experience[level - 1]; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define CREATURELIB_BATTLEITEMCATEGORY_HPP
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
ENUM(BattleItemCategory, uint8_t, None, Healing, StatusHealing, CaptureDevice, MiscBattleItem)
|
||||
ENUM(BattleItemCategory, u8, None, Healing, StatusHealing, CaptureDevice, MiscBattleItem)
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_BATTLEITEMCATEGORY_HPP
|
||||
|
||||
@@ -5,41 +5,41 @@ namespace CreatureLib::Library {
|
||||
ArbUt::StringView _name;
|
||||
ItemCategory _category;
|
||||
BattleItemCategory _battleCategory;
|
||||
int32_t _price;
|
||||
i32 _price;
|
||||
|
||||
ArbUt::OptionalUniquePtr<const SecondaryEffect> _effect = nullptr;
|
||||
ArbUt::OptionalUniquePtr<const SecondaryEffect> _battleTriggerEffect = nullptr;
|
||||
std::unordered_set<uint32_t> _flags;
|
||||
std::unordered_set<u32> _flags;
|
||||
|
||||
public:
|
||||
inline impl(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory,
|
||||
int32_t price, const SecondaryEffect* effect, const SecondaryEffect* battleTriggerEffect,
|
||||
const std::unordered_set<uint32_t>& flags) noexcept
|
||||
inline impl(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, i32 price,
|
||||
const SecondaryEffect* effect, const SecondaryEffect* battleTriggerEffect,
|
||||
const std::unordered_set<u32>& flags) noexcept
|
||||
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _effect(effect),
|
||||
_battleTriggerEffect(battleTriggerEffect), _flags(flags) {}
|
||||
|
||||
inline const ArbUt::StringView& GetName() const noexcept { return _name; }
|
||||
inline ItemCategory GetCategory() const noexcept { return _category; }
|
||||
inline BattleItemCategory GetBattleCategory() const noexcept { return _battleCategory; }
|
||||
inline int32_t GetPrice() const noexcept { return _price; }
|
||||
inline i32 GetPrice() const noexcept { return _price; }
|
||||
inline const ArbUt::OptionalUniquePtr<const SecondaryEffect>& GetEffect() const noexcept { return _effect; }
|
||||
inline const ArbUt::OptionalUniquePtr<const SecondaryEffect>& GetBattleTriggerEffect() const noexcept {
|
||||
return _battleTriggerEffect;
|
||||
}
|
||||
|
||||
inline bool HasFlag(const ArbUt::BasicStringView& flag) const noexcept { return this->_flags.contains(flag); }
|
||||
inline bool HasFlag(uint32_t flag) const noexcept { return this->_flags.contains(flag); }
|
||||
inline bool HasFlag(u32 flag) const noexcept { return this->_flags.contains(flag); }
|
||||
};
|
||||
Item::Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, int32_t price,
|
||||
Item::Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, i32 price,
|
||||
const SecondaryEffect* effect, const SecondaryEffect* battleTriggerEffect,
|
||||
const std::unordered_set<uint32_t>& flags) noexcept
|
||||
const std::unordered_set<u32>& flags) noexcept
|
||||
: _impl(new impl(name, category, battleCategory, price, effect, battleTriggerEffect, flags)) {}
|
||||
|
||||
Item::~Item() = default;
|
||||
const ArbUt::StringView& Item::GetName() const noexcept { return _impl->GetName(); }
|
||||
ItemCategory Item::GetCategory() const noexcept { return _impl->GetCategory(); }
|
||||
BattleItemCategory Item::GetBattleCategory() const noexcept { return _impl->GetBattleCategory(); }
|
||||
int32_t Item::GetPrice() const noexcept { return _impl->GetPrice(); }
|
||||
i32 Item::GetPrice() const noexcept { return _impl->GetPrice(); }
|
||||
const ArbUt::OptionalUniquePtr<const SecondaryEffect>& Item::GetEffect() const noexcept {
|
||||
return _impl->GetEffect();
|
||||
}
|
||||
@@ -48,6 +48,6 @@ namespace CreatureLib::Library {
|
||||
}
|
||||
|
||||
bool Item::HasFlag(const ArbUt::BasicStringView& flag) const noexcept { return _impl->HasFlag(flag); }
|
||||
bool Item::HasFlag(uint32_t flag) const noexcept { return _impl->HasFlag(flag); }
|
||||
bool Item::HasFlag(u32 flag) const noexcept { return _impl->HasFlag(flag); }
|
||||
|
||||
}
|
||||
@@ -15,9 +15,9 @@ namespace CreatureLib::Library {
|
||||
std::unique_ptr<impl> _impl;
|
||||
|
||||
public:
|
||||
Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, int32_t price,
|
||||
Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, i32 price,
|
||||
const SecondaryEffect* effect, const SecondaryEffect* battleTriggerEffect,
|
||||
const std::unordered_set<uint32_t>& flags) noexcept;
|
||||
const std::unordered_set<u32>& flags) noexcept;
|
||||
NO_COPY_OR_MOVE(Item)
|
||||
|
||||
virtual ~Item();
|
||||
@@ -25,12 +25,12 @@ namespace CreatureLib::Library {
|
||||
const ArbUt::StringView& GetName() const noexcept;
|
||||
ItemCategory GetCategory() const noexcept;
|
||||
BattleItemCategory GetBattleCategory() const noexcept;
|
||||
int32_t GetPrice() const noexcept;
|
||||
i32 GetPrice() const noexcept;
|
||||
|
||||
const ArbUt::OptionalUniquePtr<const SecondaryEffect>& GetEffect() const noexcept;
|
||||
const ArbUt::OptionalUniquePtr<const SecondaryEffect>& GetBattleTriggerEffect() const noexcept;
|
||||
bool HasFlag(const ArbUt::BasicStringView& flag) const noexcept;
|
||||
bool HasFlag(uint32_t flag) const noexcept;
|
||||
bool HasFlag(u32 flag) const noexcept;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define CREATURELIB_ITEMCATEGORY_HPP
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
ENUM(ItemCategory, uint8_t, MiscItem, CaptureDevice, Medicine, Berry, MoveLearner, VariantChanger, KeyItem, Mail)
|
||||
ENUM(ItemCategory, u8, MiscItem, CaptureDevice, Medicine, Berry, MoveLearner, VariantChanger, KeyItem, Mail)
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_ITEMCATEGORY_HPP
|
||||
|
||||
@@ -3,20 +3,20 @@
|
||||
namespace CreatureLib::Library {
|
||||
struct LibrarySettings::impl {
|
||||
level_int_t _maximalLevel;
|
||||
uint8_t _maximalAttacks;
|
||||
u8 _maximalAttacks;
|
||||
|
||||
public:
|
||||
impl(level_int_t maximalLevel, uint8_t maximalAttacks)
|
||||
impl(level_int_t maximalLevel, u8 maximalAttacks)
|
||||
: _maximalLevel(maximalLevel), _maximalAttacks(maximalAttacks) {}
|
||||
|
||||
[[nodiscard]] inline level_int_t GetMaximalLevel() const noexcept { return _maximalLevel; }
|
||||
|
||||
[[nodiscard]] inline uint8_t GetMaximalAttacks() const noexcept { return _maximalAttacks; }
|
||||
[[nodiscard]] inline u8 GetMaximalAttacks() const noexcept { return _maximalAttacks; }
|
||||
};
|
||||
LibrarySettings::LibrarySettings(level_int_t maximalLevel, uint8_t maximalAttacks)
|
||||
LibrarySettings::LibrarySettings(level_int_t maximalLevel, u8 maximalAttacks)
|
||||
: _impl(new impl(maximalLevel, maximalAttacks)) {}
|
||||
LibrarySettings::~LibrarySettings() = default;
|
||||
|
||||
level_int_t LibrarySettings::GetMaximalLevel() const noexcept { return _impl->GetMaximalLevel(); }
|
||||
uint8_t LibrarySettings::GetMaximalAttacks() const noexcept { return _impl->GetMaximalAttacks(); }
|
||||
u8 LibrarySettings::GetMaximalAttacks() const noexcept { return _impl->GetMaximalAttacks(); }
|
||||
}
|
||||
@@ -14,7 +14,7 @@ namespace CreatureLib::Library {
|
||||
/// @brief Initialises LibrarySettings.
|
||||
/// @param maximalLevel The maximal level a creature can be.
|
||||
/// @param maximalAttacks The maximal number of attacks a creature can have.
|
||||
LibrarySettings(level_int_t maximalLevel, uint8_t maximalAttacks);
|
||||
LibrarySettings(level_int_t maximalLevel, u8 maximalAttacks);
|
||||
virtual ~LibrarySettings();
|
||||
|
||||
/// @brief Returns the maximal level a creature can be in the current library.
|
||||
@@ -22,7 +22,7 @@ namespace CreatureLib::Library {
|
||||
[[nodiscard]] level_int_t GetMaximalLevel() const noexcept;
|
||||
/// @brief Returns the maximal number of attacks a creature can have.
|
||||
/// @return The maximal number of attacks a creature can have.
|
||||
[[nodiscard]] uint8_t GetMaximalAttacks() const noexcept;
|
||||
[[nodiscard]] u8 GetMaximalAttacks() const noexcept;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace CreatureLib::Library {
|
||||
class SpeciesLibrary : public BaseLibrary<CreatureSpecies> {
|
||||
private:
|
||||
ArbUt::Dictionary<uint16_t, ArbUt::BorrowedPtr<const CreatureSpecies>> _valuesById;
|
||||
ArbUt::Dictionary<u16, ArbUt::BorrowedPtr<const CreatureSpecies>> _valuesById;
|
||||
|
||||
public:
|
||||
SpeciesLibrary(size_t initialCapacity = 32) : BaseLibrary(initialCapacity){};
|
||||
@@ -16,12 +16,12 @@ namespace CreatureLib::Library {
|
||||
BaseLibrary::Insert(key, value);
|
||||
_valuesById.Insert(value->GetId(), value);
|
||||
}
|
||||
void Insert(uint32_t hashedKey, const CreatureSpecies* value) override {
|
||||
void Insert(u32 hashedKey, const CreatureSpecies* value) override {
|
||||
BaseLibrary::Insert(hashedKey, value);
|
||||
_valuesById.Insert(value->GetId(), value);
|
||||
}
|
||||
|
||||
const ArbUt::BorrowedPtr<const CreatureSpecies>& GetById(uint16_t id) const { return _valuesById[id]; }
|
||||
const ArbUt::BorrowedPtr<const CreatureSpecies>& GetById(u16 id) const { return _valuesById[id]; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <Arbutils/Enum.hpp>
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
ENUM(Statistic, uint8_t, Health, PhysicalAttack, PhysicalDefense, MagicalAttack, MagicalDefense, Speed)
|
||||
ENUM(Statistic, u8, Health, PhysicalAttack, PhysicalDefense, MagicalAttack, MagicalDefense, Speed)
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_STATISTIC_HPP
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
uint8_t TypeLibrary::RegisterType(const ArbUt::StringView& key) {
|
||||
u8 TypeLibrary::RegisterType(const ArbUt::StringView& key) {
|
||||
_types.Insert(key, _types.Count());
|
||||
_effectiveness.Resize(_types.Count());
|
||||
for (auto& eff : _effectiveness) {
|
||||
@@ -11,14 +11,14 @@ uint8_t TypeLibrary::RegisterType(const ArbUt::StringView& key) {
|
||||
return _types.Count() - 1;
|
||||
}
|
||||
|
||||
void TypeLibrary::SetEffectiveness(uint8_t attacking, uint8_t defensive, float effectiveness) {
|
||||
void TypeLibrary::SetEffectiveness(u8 attacking, u8 defensive, float effectiveness) {
|
||||
_effectiveness[attacking][defensive] = effectiveness;
|
||||
}
|
||||
const ArbUt::StringView& TypeLibrary::GetTypeName(uint8_t type) const {
|
||||
const ArbUt::StringView& TypeLibrary::GetTypeName(u8 type) const {
|
||||
for (auto& kv : _types) {
|
||||
if (kv.second == type) {
|
||||
return kv.first;
|
||||
}
|
||||
}
|
||||
THROW("Name requested for unknown type: ", (uint32_t)type);
|
||||
THROW("Name requested for unknown type: ", (u32)type);
|
||||
}
|
||||
|
||||
@@ -16,25 +16,25 @@ namespace CreatureLib::Library {
|
||||
public:
|
||||
TypeLibrary(size_t initialCapacity = 20) : _types(ArbUt::Dictionary<ArbUt::StringView, u8>(initialCapacity)) {}
|
||||
|
||||
inline uint8_t GetTypeId(const ArbUt::StringView& key) const { return _types.Get(key); }
|
||||
inline u8 GetTypeId(const ArbUt::StringView& key) const { return _types.Get(key); }
|
||||
[[nodiscard]] inline float GetSingleEffectiveness(u8 attacking, u8 defensive) const {
|
||||
try {
|
||||
return _effectiveness[attacking][defensive];
|
||||
} catch (const std::exception& e) {
|
||||
THROW("Unknown type indices were requested for effectiveness: ", (uint32_t)attacking, " and ",
|
||||
(uint32_t)defensive);
|
||||
THROW("Unknown type indices were requested for effectiveness: ", (u32)attacking, " and ",
|
||||
(u32)defensive);
|
||||
}
|
||||
}
|
||||
[[nodiscard]] inline float GetEffectiveness(uint8_t attacking, const std::vector<u8>& defensive) const {
|
||||
[[nodiscard]] inline float GetEffectiveness(u8 attacking, const std::vector<u8>& defensive) const {
|
||||
return std::accumulate(defensive.begin(), defensive.end(), (float)1,
|
||||
[this, attacking](float init, uint8_t defense) {
|
||||
[this, attacking](float init, u8 defense) {
|
||||
return init * GetSingleEffectiveness(attacking, defense);
|
||||
});
|
||||
}
|
||||
const ArbUt::StringView& GetTypeName(u8 type) const;
|
||||
|
||||
uint8_t RegisterType(const ArbUt::StringView& typeName);
|
||||
void SetEffectiveness(uint8_t attacking, u8 defensive, float effectiveness);
|
||||
u8 RegisterType(const ArbUt::StringView& typeName);
|
||||
void SetEffectiveness(u8 attacking, u8 defensive, float effectiveness);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user