Reworked retrieving talent, new method is cleaner and harder to misunderstand.
continuous-integration/drone/push Build was killed
Details
continuous-integration/drone/push Build was killed
Details
This commit is contained in:
parent
bfc049a97c
commit
0c1580ade6
|
@ -28,3 +28,20 @@ export SpeciesVariant* CreatureLib_SpeciesVariant_Construct(
|
|||
}
|
||||
|
||||
export void CreatureLib_SpeciesVariant_Destruct(SpeciesVariant* p) { delete p; }
|
||||
|
||||
#define SIMPLE_GET_FUNC(type, name, returnType) \
|
||||
export returnType CreatureLib_##type##_##name(const CreatureLib::Library::type* p) { return p->name(); }
|
||||
|
||||
export const char* CreatureLib_SpeciesVariant_GetName(SpeciesVariant* p) { return p->GetName().c_str(); }
|
||||
SIMPLE_GET_FUNC(SpeciesVariant, GetHeight, float);
|
||||
SIMPLE_GET_FUNC(SpeciesVariant, GetWeight, float);
|
||||
SIMPLE_GET_FUNC(SpeciesVariant, GetBaseExperience, uint32_t);
|
||||
SIMPLE_GET_FUNC(SpeciesVariant, GetTypeCount, size_t);
|
||||
export uint8_t CreatureLib_SpeciesVariant_GetType(SpeciesVariant* p, size_t index) { return p->GetType(index); }
|
||||
export uint32_t CreatureLib_SpeciesVariant_GetStatistic(SpeciesVariant* p, CreatureLib::Core::Statistic stat) {
|
||||
return p->GetStatistic(stat);
|
||||
}
|
||||
SIMPLE_GET_FUNC(SpeciesVariant, GetTalentCount, size_t);
|
||||
SIMPLE_GET_FUNC(SpeciesVariant, GetSecretTalentCount, size_t);
|
||||
|
||||
#undef SIMPLE_GET_FUNC
|
||||
|
|
|
@ -34,8 +34,8 @@ Creature* CreateCreature::Create() {
|
|||
auto rand = Arbutils::Random();
|
||||
auto species = this->_library->GetSpeciesLibrary()->Get(this->_species);
|
||||
auto variant = species->GetVariant(this->_variant);
|
||||
int8_t talent;
|
||||
if (this->_talent.empty()) {
|
||||
TalentIndex talent;
|
||||
if (this->_talent.Empty()) {
|
||||
talent = variant->GetRandomTalent(&rand);
|
||||
} else {
|
||||
talent = variant->GetTalentIndex(this->_talent);
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace CreatureLib::Battling {
|
|||
uint8_t _level;
|
||||
std::string _nickname = "";
|
||||
|
||||
std::string _talent = "";
|
||||
Arbutils::CaseInsensitiveConstString _talent = ""_cnc;
|
||||
Library::Gender _gender = static_cast<Library::Gender>(-1);
|
||||
uint8_t _coloring = 0;
|
||||
Arbutils::CaseInsensitiveConstString _heldItem = ""_cnc;
|
||||
|
|
|
@ -9,7 +9,7 @@ using namespace CreatureLib;
|
|||
Battling::Creature::Creature(const BattleLibrary* library, const Library::CreatureSpecies* species,
|
||||
const Library::SpeciesVariant* variant, uint8_t level, uint32_t experience, uint32_t uid,
|
||||
Library::Gender gender, uint8_t coloring, const Library::Item* heldItem,
|
||||
std::string nickname, int8_t talent, std::vector<LearnedAttack*> attacks)
|
||||
std::string nickname, const TalentIndex& talent, std::vector<LearnedAttack*> attacks)
|
||||
: _library(library), _species(species), _variant(variant), _level(level), _experience(experience),
|
||||
_uniqueIdentifier(uid), _gender(gender), _coloring(coloring), _heldItem(heldItem), _nickname(std::move(nickname)),
|
||||
_talentIndex(talent), _hasOverridenTalent(false), _attacks(std::move(attacks)) {
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace CreatureLib::Battling {
|
|||
bool _onBattleField = false;
|
||||
|
||||
std::string _nickname = "";
|
||||
int8_t _talentIndex;
|
||||
TalentIndex _talentIndex;
|
||||
Script* _activeTalent = nullptr;
|
||||
|
||||
bool _hasOverridenTalent;
|
||||
|
@ -61,7 +61,7 @@ namespace CreatureLib::Battling {
|
|||
Creature(const BattleLibrary* library, const Library::CreatureSpecies* species,
|
||||
const Library::SpeciesVariant* variant, uint8_t level, uint32_t experience, uint32_t uid,
|
||||
Library::Gender gender, uint8_t coloring, const Library::Item* heldItem, std::string nickname,
|
||||
int8_t talent, std::vector<LearnedAttack*> attacks);
|
||||
const TalentIndex& talent, std::vector<LearnedAttack*> attacks);
|
||||
|
||||
virtual ~Creature() {
|
||||
for (auto attack : _attacks) {
|
||||
|
|
|
@ -12,28 +12,22 @@ uint32_t CreatureLib::Library::SpeciesVariant::GetStatistic(CreatureLib::Core::S
|
|||
return _baseStatistics.GetStat(stat);
|
||||
}
|
||||
|
||||
const ConstString& CreatureLib::Library::SpeciesVariant::GetTalent(int32_t index) const {
|
||||
if (index < 0) {
|
||||
index = -index - 1;
|
||||
return _secretTalents[index];
|
||||
const TalentIndex CreatureLib::Library::SpeciesVariant::GetTalentIndex(const ConstString& talent) const {
|
||||
for (size_t i = 0; i < _talents.size(); i++) {
|
||||
if (_talents.at(i) == talent) {
|
||||
return TalentIndex(false, i);
|
||||
}
|
||||
}
|
||||
return _talents[index];
|
||||
}
|
||||
|
||||
int8_t CreatureLib::Library::SpeciesVariant::GetTalentIndex(const std::string& talent) const {
|
||||
auto i = std::find(_talents.begin(), _talents.end(), talent);
|
||||
if (i != _talents.end()) {
|
||||
return std::distance(_talents.begin(), i);
|
||||
}
|
||||
i = std::find(_secretTalents.begin(), _secretTalents.end(), talent);
|
||||
if (i != _secretTalents.end()) {
|
||||
return std::distance(_secretTalents.begin(), i);
|
||||
for (size_t i = 0; i < _secretTalents.size(); i++) {
|
||||
if (_secretTalents.at(i) == talent) {
|
||||
return TalentIndex(true, i);
|
||||
}
|
||||
}
|
||||
throw CreatureException("The given talent is not a valid talent for this creature.");
|
||||
}
|
||||
|
||||
int8_t CreatureLib::Library::SpeciesVariant::GetRandomTalent(Arbutils::Random* rand) const {
|
||||
return rand->Get(_talents.size());
|
||||
TalentIndex CreatureLib::Library::SpeciesVariant::GetRandomTalent(Arbutils::Random* rand) const {
|
||||
return TalentIndex(false, rand->Get(_talents.size()));
|
||||
}
|
||||
|
||||
const CreatureLib::Library::LearnableAttacks* CreatureLib::Library::SpeciesVariant::GetLearnableAttacks() const {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "../../Core/StatisticSet.hpp"
|
||||
#include "CreatureMoves.hpp"
|
||||
#include "LearnableAttacks.hpp"
|
||||
#include "TalentIndex.hpp"
|
||||
using ConstString = Arbutils::CaseInsensitiveConstString;
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
|
@ -44,10 +45,17 @@ namespace CreatureLib::Library {
|
|||
[[nodiscard]] uint8_t GetType(size_t index) const;
|
||||
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const;
|
||||
[[nodiscard]] uint32_t GetStatistic(Core::Statistic stat) const;
|
||||
[[nodiscard]] const ConstString& GetTalent(int32_t index) const;
|
||||
[[nodiscard]] const size_t GetTalentCount() const { return _talents.size(); }
|
||||
[[nodiscard]] const size_t GetSecretTalentCount() const { return _secretTalents.size(); }
|
||||
[[nodiscard]] const ConstString& GetTalent(const TalentIndex& index) const {
|
||||
if (index.IsSecret())
|
||||
return _secretTalents.at(index.GetIndex());
|
||||
return _talents.at(index.GetIndex());
|
||||
}
|
||||
[[nodiscard]] const TalentIndex GetTalentIndex(const ConstString& talent) const;
|
||||
|
||||
[[nodiscard]] const LearnableAttacks* GetLearnableAttacks() const;
|
||||
[[nodiscard]] int8_t GetTalentIndex(const std::string& talent) const;
|
||||
[[nodiscard]] int8_t GetRandomTalent(Arbutils::Random* rand) const;
|
||||
[[nodiscard]] TalentIndex GetRandomTalent(Arbutils::Random* rand) const;
|
||||
[[nodiscard]] inline const std::vector<ConstString>& GetTalents() const { return _talents; }
|
||||
[[nodiscard]] inline const std::vector<ConstString>& GetSecretTalents() const { return _secretTalents; }
|
||||
};
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef CREATURELIB_TALENTINDEX_HPP
|
||||
#define CREATURELIB_TALENTINDEX_HPP
|
||||
|
||||
#include <cstdint>
|
||||
class TalentIndex {
|
||||
bool _secret;
|
||||
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; }
|
||||
};
|
||||
|
||||
#endif // CREATURELIB_TALENTINDEX_HPP
|
Loading…
Reference in New Issue