Support for adding flags to CreatureSpecies and CreatureVariant.
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
1807e720dd
commit
2ca4f53b0c
|
@ -4,10 +4,14 @@ using namespace CreatureLib::Library;
|
|||
|
||||
export uint8_t CreatureLib_CreatureSpecies_Construct(CreatureSpecies*& out, uint16_t id, const char* name,
|
||||
SpeciesVariant* defaultVariant, float genderRatio,
|
||||
const char* growthRate, uint8_t captureRate) {
|
||||
const char* growthRate, uint8_t captureRate, const char* flags[],
|
||||
size_t flagsCount) {
|
||||
|
||||
Try(out = new CreatureSpecies(id, ArbUt::StringView(name), defaultVariant, genderRatio,
|
||||
ArbUt::StringView(growthRate), captureRate);)
|
||||
Try(std::unordered_set<uint32_t> conversedFlags(flagsCount);
|
||||
for (size_t i = 0; i < flagsCount; i++) { conversedFlags.insert(ArbUt::StringView::CalculateHash(flags[i])); }
|
||||
|
||||
out = new CreatureSpecies(id, ArbUt::StringView(name), defaultVariant, genderRatio,
|
||||
ArbUt::StringView(growthRate), captureRate, conversedFlags);)
|
||||
}
|
||||
|
||||
export void CreatureLib_CreatureSpecies_Destruct(const CreatureSpecies* p) { delete p; }
|
||||
|
@ -61,4 +65,7 @@ export size_t CreatureLib_CreatureSpecies_GetVariantsCount(CreatureSpecies* p) {
|
|||
}
|
||||
export const SpeciesVariant* const* CreatureLib_CreatureSpecies_GetVariants(CreatureSpecies* p) {
|
||||
return reinterpret_cast<const SpeciesVariant* const*>(p->GetVariantsIterator().RawData());
|
||||
}
|
||||
export bool CreatureLib_CreatureSpecies_HasFlag(const CreatureSpecies* p, const char* key) {
|
||||
return p->HasFlag(ArbUt::StringView::CalculateHash(key));
|
||||
}
|
|
@ -3,11 +3,18 @@
|
|||
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
export SpeciesVariant* CreatureLib_SpeciesVariant_Construct(
|
||||
const char* name, float height, float weight, uint32_t baseExperience, uint8_t types[], size_t typeLength,
|
||||
uint16_t baseHealth, uint16_t baseAttack, uint16_t baseDefense, uint16_t baseMagicalAttack,
|
||||
uint16_t baseMagicalDefense, uint16_t baseSpeed, const char* talents[], size_t talentsLength,
|
||||
const char* secretTalents[], size_t secretTalentsLength, const LearnableAttacks* attacks) {
|
||||
export SpeciesVariant*
|
||||
CreatureLib_SpeciesVariant_Construct(const char* name, float height, float weight, uint32_t baseExperience,
|
||||
uint8_t types[], size_t typeLength, uint16_t baseHealth, uint16_t baseAttack,
|
||||
uint16_t baseDefense, uint16_t baseMagicalAttack, uint16_t baseMagicalDefense,
|
||||
uint16_t baseSpeed, const char* talents[], size_t talentsLength,
|
||||
const char* secretTalents[], size_t secretTalentsLength,
|
||||
const LearnableAttacks* attacks, const char* flags[], size_t flagsCount) {
|
||||
|
||||
std::unordered_set<uint32_t> conversedFlags(flagsCount);
|
||||
for (size_t i = 0; i < flagsCount; i++) {
|
||||
conversedFlags.insert(ArbUt::StringView::CalculateHash(flags[i]));
|
||||
}
|
||||
|
||||
auto talentsWrapped = ArbUt::List<ArbUt::StringView>(talentsLength);
|
||||
for (size_t i = 0; i < talentsLength; i++) {
|
||||
|
@ -22,7 +29,7 @@ export SpeciesVariant* CreatureLib_SpeciesVariant_Construct(
|
|||
ArbUt::StringView(name), height, weight, baseExperience, ArbUt::List<uint8_t>(types, types + typeLength),
|
||||
CreatureLib::Library::StatisticSet<uint16_t>(baseHealth, baseAttack, baseDefense, baseMagicalAttack,
|
||||
baseMagicalDefense, baseSpeed),
|
||||
talentsWrapped, secretTalentsWrapped, attacks);
|
||||
talentsWrapped, secretTalentsWrapped, attacks, conversedFlags);
|
||||
}
|
||||
|
||||
export void CreatureLib_SpeciesVariant_Destruct(SpeciesVariant* p) { delete p; }
|
||||
|
@ -47,3 +54,6 @@ export const LearnableAttacks* CreatureLib_SpeciesVariant_GetLearnableAttacks(Sp
|
|||
export uint8_t CreatureLib_SpeciesVariant_GetRandomTalent(SpeciesVariant* p, ArbUt::Random* rand) {
|
||||
return p->GetRandomTalent(*rand).GetIndex();
|
||||
}
|
||||
export bool CreatureLib_SpeciesVariant_HasFlag(const SpeciesVariant* p, const char* key) {
|
||||
return p->HasFlag(ArbUt::StringView::CalculateHash(key));
|
||||
}
|
|
@ -1,12 +1,14 @@
|
|||
#include "CreatureSpecies.hpp"
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include <utility>
|
||||
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
CreatureSpecies::CreatureSpecies(uint16_t id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant,
|
||||
float genderRatio, const ArbUt::StringView& growthRate, uint8_t captureRate)
|
||||
float genderRatio, const ArbUt::StringView& growthRate, uint8_t captureRate,
|
||||
std::unordered_set<uint32_t> flags)
|
||||
: _name(name), _id(id), _genderRate(genderRatio), _growthRate(growthRate), _captureRate(captureRate),
|
||||
_variantsLookup(1), _variantsList(1) {
|
||||
_variantsLookup(1), _variantsList(1), _flags(std::move(flags)) {
|
||||
AssertNotNull(defaultVariant)
|
||||
SetVariant("default"_cnc, defaultVariant);
|
||||
}
|
||||
|
|
|
@ -24,10 +24,12 @@ namespace CreatureLib::Library {
|
|||
|
||||
ArbUt::Dictionary<uint32_t, std::unique_ptr<const SpeciesVariant>> _variantsLookup;
|
||||
ArbUt::List<ArbUt::BorrowedPtr<const SpeciesVariant>> _variantsList;
|
||||
std::unordered_set<uint32_t> _flags;
|
||||
|
||||
public:
|
||||
CreatureSpecies(uint16_t id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant,
|
||||
float genderRatio, const ArbUt::StringView& growthRate, uint8_t captureRate);
|
||||
float genderRatio, const ArbUt::StringView& growthRate, uint8_t captureRate,
|
||||
std::unordered_set<uint32_t> flags = {});
|
||||
|
||||
virtual ~CreatureSpecies() noexcept { _variantsLookup.Clear(); }
|
||||
|
||||
|
@ -60,6 +62,13 @@ namespace CreatureLib::Library {
|
|||
inline const ArbUt::List<ArbUt::BorrowedPtr<const SpeciesVariant>>& GetVariantsIterator() const {
|
||||
return _variantsList;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -27,14 +27,17 @@ namespace CreatureLib::Library {
|
|||
ArbUt::List<ArbUt::StringView> _talents;
|
||||
ArbUt::List<ArbUt::StringView> _secretTalents;
|
||||
std::unique_ptr<const LearnableAttacks> _attacks;
|
||||
std::unordered_set<uint32_t> _flags;
|
||||
|
||||
public:
|
||||
SpeciesVariant(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience,
|
||||
const ArbUt::List<uint8_t>& types, Library::StatisticSet<uint16_t> baseStats,
|
||||
const ArbUt::List<ArbUt::StringView>& talents,
|
||||
const ArbUt::List<ArbUt::StringView>& secretTalents, const LearnableAttacks* attacks)
|
||||
const ArbUt::List<ArbUt::StringView>& secretTalents, const LearnableAttacks* attacks,
|
||||
std::unordered_set<uint32_t> flags = {})
|
||||
: _name(name), _height(height), _weight(weight), _baseExperience(baseExperience), _types((types)),
|
||||
_baseStatistics(baseStats), _talents(talents), _secretTalents(secretTalents), _attacks(attacks){};
|
||||
_baseStatistics(baseStats), _talents(talents), _secretTalents(secretTalents), _attacks(attacks),
|
||||
_flags(flags){};
|
||||
virtual ~SpeciesVariant() = default;
|
||||
|
||||
inline const ArbUt::StringView& GetName() const { return _name; }
|
||||
|
@ -73,6 +76,13 @@ namespace CreatureLib::Library {
|
|||
}
|
||||
[[nodiscard]] inline const ArbUt::List<ArbUt::StringView>& GetTalents() const { return _talents; }
|
||||
[[nodiscard]] inline const ArbUt::List<ArbUt::StringView>& GetSecretTalents() const { return _secretTalents; }
|
||||
|
||||
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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue