Add ConstString to several other places where context isn't changed much during runtime.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
469fcfe280
commit
5a05a2f4d3
|
@ -38,6 +38,6 @@ const DamageLibrary* BattleLibrary::GetDamageLibrary() const { return _damageLib
|
||||||
|
|
||||||
const MiscLibrary* BattleLibrary::GetMiscLibrary() const { return _miscLibrary; }
|
const MiscLibrary* BattleLibrary::GetMiscLibrary() const { return _miscLibrary; }
|
||||||
|
|
||||||
Script* BattleLibrary::LoadScript(ScriptCategory category, const std::string& scriptName) const {
|
Script* BattleLibrary::LoadScript(ScriptCategory category, const ConstString& scriptName) const {
|
||||||
return _scriptResolver->LoadScript(category, scriptName);
|
return _scriptResolver->LoadScript(category, scriptName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace CreatureLib::Battling {
|
||||||
[[nodiscard]] const MiscLibrary* GetMiscLibrary() const;
|
[[nodiscard]] const MiscLibrary* GetMiscLibrary() const;
|
||||||
[[nodiscard]] const ExperienceLibrary* GetExperienceLibrary() const { return _experienceLibrary; }
|
[[nodiscard]] const ExperienceLibrary* GetExperienceLibrary() const { return _experienceLibrary; }
|
||||||
|
|
||||||
[[nodiscard]] Script* LoadScript(ScriptCategory category, const std::string& scriptName) const;
|
[[nodiscard]] Script* LoadScript(ScriptCategory category, const ConstString& scriptName) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ void Battle::ValidateBattleState() {
|
||||||
this->_battleResult = BattleResult::Conclusive(winningSide);
|
this->_battleResult = BattleResult::Conclusive(winningSide);
|
||||||
this->_hasEnded = true;
|
this->_hasEnded = true;
|
||||||
}
|
}
|
||||||
void Battle::AddVolatileScript(const std::string& key) {
|
void Battle::AddVolatileScript(const ConstString& key) {
|
||||||
auto script = _volatile.Get(key);
|
auto script = _volatile.Get(key);
|
||||||
if (script != nullptr) {
|
if (script != nullptr) {
|
||||||
script->Stack();
|
script->Stack();
|
||||||
|
@ -129,6 +129,6 @@ void Battle::AddVolatileScript(const std::string& key) {
|
||||||
return _volatile.Add(script);
|
return _volatile.Add(script);
|
||||||
}
|
}
|
||||||
void Battle::AddVolatileScript(Script* script) { return _volatile.Add(script); }
|
void Battle::AddVolatileScript(Script* script) { return _volatile.Add(script); }
|
||||||
void Battle::RemoveVolatileScript(const std::string& name) { _volatile.Remove(name); }
|
void Battle::RemoveVolatileScript(const ConstString& name) { _volatile.Remove(name); }
|
||||||
void Battle::RemoveVolatileScript(Script* script) { _volatile.Remove(script->GetName()); }
|
void Battle::RemoveVolatileScript(Script* script) { _volatile.Remove(script->GetName()); }
|
||||||
void Battle::HasVolatileScript(const std::string& name) const { _volatile.Has(name); }
|
void Battle::HasVolatileScript(const ConstString& name) const { _volatile.Has(name); }
|
||||||
|
|
|
@ -75,12 +75,12 @@ namespace CreatureLib::Battling {
|
||||||
inline const BattleResult& GetResult() const { return _battleResult; }
|
inline const BattleResult& GetResult() const { return _battleResult; }
|
||||||
|
|
||||||
const std::vector<BattleSide*>& GetSides() const { return _sides; }
|
const std::vector<BattleSide*>& GetSides() const { return _sides; }
|
||||||
Script* GetVolatileScript(const std::string& key) const { return _volatile.Get(key); }
|
Script* GetVolatileScript(const ConstString& key) const { return _volatile.Get(key); }
|
||||||
void AddVolatileScript(const std::string& key);
|
void AddVolatileScript(const ConstString& key);
|
||||||
void AddVolatileScript(Script* script);
|
void AddVolatileScript(Script* script);
|
||||||
void RemoveVolatileScript(const std::string& name);
|
void RemoveVolatileScript(const ConstString& name);
|
||||||
void RemoveVolatileScript(Script* script);
|
void RemoveVolatileScript(Script* script);
|
||||||
void HasVolatileScript(const std::string& name) const;
|
void HasVolatileScript(const ConstString& name) const;
|
||||||
|
|
||||||
void RegisterEventListener(EVENT_HOOK_FUNC(listener)) { this->_eventHook.RegisterListener(listener); }
|
void RegisterEventListener(EVENT_HOOK_FUNC(listener)) { this->_eventHook.RegisterListener(listener); }
|
||||||
void TriggerEventListener(EventData* data) { this->_eventHook.TriggerEvent(data); }
|
void TriggerEventListener(EventData* data) { this->_eventHook.TriggerEvent(data); }
|
||||||
|
|
|
@ -25,7 +25,7 @@ void Battling::Creature::ChangeLevel(int8_t amount) {
|
||||||
RecalculateFlatStats();
|
RecalculateFlatStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& Battling::Creature::GetActiveTalent() const {
|
const ConstString& Battling::Creature::GetActiveTalent() const {
|
||||||
if (_hasOverridenTalent) {
|
if (_hasOverridenTalent) {
|
||||||
return _overridenTalentName;
|
return _overridenTalentName;
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ void Battling::Creature::Heal(uint32_t amount) {
|
||||||
_currentHealth = newHealth;
|
_currentHealth = newHealth;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Battling::Creature::OverrideActiveTalent(const std::string& talent) {
|
void Battling::Creature::OverrideActiveTalent(const ConstString& talent) {
|
||||||
_hasOverridenTalent = true;
|
_hasOverridenTalent = true;
|
||||||
_activeTalent->OnRemove();
|
_activeTalent->OnRemove();
|
||||||
delete _activeTalent;
|
delete _activeTalent;
|
||||||
|
@ -183,7 +183,7 @@ void Battling::Creature::SetHeldItem(const Arbutils::CaseInsensitiveConstString&
|
||||||
}
|
}
|
||||||
_heldItem = item;
|
_heldItem = item;
|
||||||
}
|
}
|
||||||
void Battling::Creature::AddVolatileScript(const std::string& name) {
|
void Battling::Creature::AddVolatileScript(const ConstString& name) {
|
||||||
auto script = _volatile.Get(name);
|
auto script = _volatile.Get(name);
|
||||||
if (script != nullptr) {
|
if (script != nullptr) {
|
||||||
script->Stack();
|
script->Stack();
|
||||||
|
@ -194,6 +194,6 @@ void Battling::Creature::AddVolatileScript(const std::string& name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Battling::Creature::AddVolatileScript(Script* script) { _volatile.Add(script); }
|
void Battling::Creature::AddVolatileScript(Script* script) { _volatile.Add(script); }
|
||||||
void Battling::Creature::RemoveVolatileScript(const std::string& name) { _volatile.Remove(name); }
|
void Battling::Creature::RemoveVolatileScript(const ConstString& name) { _volatile.Remove(name); }
|
||||||
void Battling::Creature::RemoveVolatileScript(Battling::Script* script) { _volatile.Remove(script->GetName()); }
|
void Battling::Creature::RemoveVolatileScript(Battling::Script* script) { _volatile.Remove(script->GetName()); }
|
||||||
void Battling::Creature::HasVolatileScript(const std::string& name) const { _volatile.Has(name); }
|
void Battling::Creature::HasVolatileScript(const ConstString& name) const { _volatile.Has(name); }
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace CreatureLib::Battling {
|
||||||
Script* _activeTalent = nullptr;
|
Script* _activeTalent = nullptr;
|
||||||
|
|
||||||
bool _hasOverridenTalent;
|
bool _hasOverridenTalent;
|
||||||
std::string _overridenTalentName = "";
|
ConstString _overridenTalentName = ""_cnc;
|
||||||
std::unordered_set<Creature*> _seenOpponents = {};
|
std::unordered_set<Creature*> _seenOpponents = {};
|
||||||
|
|
||||||
std::vector<LearnedAttack*> _attacks;
|
std::vector<LearnedAttack*> _attacks;
|
||||||
|
@ -98,7 +98,7 @@ namespace CreatureLib::Battling {
|
||||||
bool IsOnBattleField() const { return _onBattleField; }
|
bool IsOnBattleField() const { return _onBattleField; }
|
||||||
|
|
||||||
const std::string& GetNickname() const { return _nickname; }
|
const std::string& GetNickname() const { return _nickname; }
|
||||||
const std::string& GetActiveTalent() const;
|
const ConstString& GetActiveTalent() const;
|
||||||
|
|
||||||
[[nodiscard]] bool IsFainted() const;
|
[[nodiscard]] bool IsFainted() const;
|
||||||
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const;
|
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const;
|
||||||
|
@ -108,7 +108,7 @@ namespace CreatureLib::Battling {
|
||||||
void ChangeLevel(int8_t amount);
|
void ChangeLevel(int8_t amount);
|
||||||
void Damage(uint32_t damage, DamageSource source);
|
void Damage(uint32_t damage, DamageSource source);
|
||||||
void Heal(uint32_t amount);
|
void Heal(uint32_t amount);
|
||||||
void OverrideActiveTalent(const std::string& talent);
|
void OverrideActiveTalent(const ConstString& talent);
|
||||||
void AddExperience(uint32_t amount);
|
void AddExperience(uint32_t amount);
|
||||||
|
|
||||||
void MarkOpponentAsSeen(Creature* creature) { _seenOpponents.insert(creature); }
|
void MarkOpponentAsSeen(Creature* creature) { _seenOpponents.insert(creature); }
|
||||||
|
@ -116,11 +116,11 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override;
|
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override;
|
||||||
void ClearVolatileScripts();
|
void ClearVolatileScripts();
|
||||||
void AddVolatileScript(const std::string& name);
|
void AddVolatileScript(const ConstString& name);
|
||||||
void AddVolatileScript(Script* script);
|
void AddVolatileScript(Script* script);
|
||||||
void RemoveVolatileScript(const std::string& name);
|
void RemoveVolatileScript(const ConstString& name);
|
||||||
void RemoveVolatileScript(Script* script);
|
void RemoveVolatileScript(Script* script);
|
||||||
void HasVolatileScript(const std::string& name) const;
|
void HasVolatileScript(const ConstString& name) const;
|
||||||
|
|
||||||
std::vector<LearnedAttack*>& GetAttacks() { return _attacks; }
|
std::vector<LearnedAttack*>& GetAttacks() { return _attacks; }
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace CreatureLib::Battling {
|
||||||
virtual void Stack(){};
|
virtual void Stack(){};
|
||||||
virtual void OnRemove(){};
|
virtual void OnRemove(){};
|
||||||
|
|
||||||
virtual const std::string& GetName() const = 0;
|
virtual const ConstString& GetName() const = 0;
|
||||||
|
|
||||||
virtual void OnBeforeTurn(const BaseTurnChoice* choice){};
|
virtual void OnBeforeTurn(const BaseTurnChoice* choice){};
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace CreatureLib::Battling {
|
||||||
virtual ~ScriptResolver() = default;
|
virtual ~ScriptResolver() = default;
|
||||||
|
|
||||||
virtual void Initialize(BattleLibrary* library){};
|
virtual void Initialize(BattleLibrary* library){};
|
||||||
virtual Script* LoadScript(ScriptCategory category, const std::string& scriptName) { return nullptr; };
|
virtual Script* LoadScript(ScriptCategory category, const ConstString& scriptName) { return nullptr; };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
namespace CreatureLib::Battling {
|
namespace CreatureLib::Battling {
|
||||||
class ScriptSet {
|
class ScriptSet {
|
||||||
std::vector<Script*> _scripts;
|
std::vector<Script*> _scripts;
|
||||||
std::unordered_map<std::string, size_t> _lookup;
|
std::unordered_map<ConstString, size_t> _lookup;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~ScriptSet() {
|
~ScriptSet() {
|
||||||
|
@ -28,7 +28,7 @@ namespace CreatureLib::Battling {
|
||||||
_lookup.insert({script->GetName(), _scripts.size() - 1});
|
_lookup.insert({script->GetName(), _scripts.size() - 1});
|
||||||
}
|
}
|
||||||
|
|
||||||
Script* Get(const std::string& key) const {
|
Script* Get(const ConstString& key) const {
|
||||||
auto f = _lookup.find(key);
|
auto f = _lookup.find(key);
|
||||||
if (f != _lookup.end()) {
|
if (f != _lookup.end()) {
|
||||||
return _scripts[f->second];
|
return _scripts[f->second];
|
||||||
|
@ -36,7 +36,7 @@ namespace CreatureLib::Battling {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Remove(const std::string& key) {
|
void Remove(const ConstString& key) {
|
||||||
auto find = _lookup.find(key);
|
auto find = _lookup.find(key);
|
||||||
if (find != _lookup.end()) {
|
if (find != _lookup.end()) {
|
||||||
auto script = _scripts[find->second];
|
auto script = _scripts[find->second];
|
||||||
|
@ -55,7 +55,7 @@ namespace CreatureLib::Battling {
|
||||||
_lookup.clear();
|
_lookup.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Has(const std::string& key) const {
|
bool Has(const ConstString& key) const {
|
||||||
auto find = _lookup.find(key);
|
auto find = _lookup.find(key);
|
||||||
return find != _lookup.end();
|
return find != _lookup.end();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,18 +2,14 @@
|
||||||
|
|
||||||
using namespace CreatureLib::Library;
|
using namespace CreatureLib::Library;
|
||||||
|
|
||||||
CreatureSpecies::CreatureSpecies(uint16_t id, const Arbutils::CaseInsensitiveConstString& name,
|
CreatureSpecies::CreatureSpecies(uint16_t id, const ConstString& name, const SpeciesVariant* defaultVariant,
|
||||||
const SpeciesVariant* defaultVariant, float genderRatio,
|
float genderRatio, const ConstString& growthRate, uint8_t captureRate)
|
||||||
const Arbutils::CaseInsensitiveConstString& growthRate, uint8_t captureRate)
|
: _name(name), _id(id), _genderRate(genderRatio), _growthRate(growthRate), _captureRate(captureRate),
|
||||||
: _id(id), _genderRate(genderRatio), _growthRate(growthRate), _captureRate(captureRate),
|
_variants({{"default"_cnc, defaultVariant}}) {}
|
||||||
_variants({{"default"_cnc, defaultVariant}}), _name(name) {}
|
|
||||||
|
|
||||||
bool CreatureSpecies::HasVariant(const Arbutils::CaseInsensitiveConstString& name) const {
|
bool CreatureSpecies::HasVariant(const ConstString& name) const { return _variants.find(name) != _variants.end(); }
|
||||||
return _variants.find(name) != _variants.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CreatureSpecies::TryGetVariant(const Arbutils::CaseInsensitiveConstString& name,
|
bool CreatureSpecies::TryGetVariant(const ConstString& name, const SpeciesVariant*& out) const {
|
||||||
const SpeciesVariant*& out) const {
|
|
||||||
auto find = _variants.find(name);
|
auto find = _variants.find(name);
|
||||||
if (find != _variants.end()) {
|
if (find != _variants.end()) {
|
||||||
out = find->second;
|
out = find->second;
|
||||||
|
@ -22,12 +18,12 @@ bool CreatureSpecies::TryGetVariant(const Arbutils::CaseInsensitiveConstString&
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SpeciesVariant* CreatureSpecies::GetVariant(const Arbutils::CaseInsensitiveConstString& name) const {
|
const SpeciesVariant* CreatureSpecies::GetVariant(const ConstString& name) const {
|
||||||
auto key = name;
|
auto key = name;
|
||||||
return _variants.at(key);
|
return _variants.at(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatureSpecies::SetVariant(const Arbutils::CaseInsensitiveConstString& name, const SpeciesVariant* variant) {
|
void CreatureSpecies::SetVariant(const ConstString& name, const SpeciesVariant* variant) {
|
||||||
auto find = _variants.find(name);
|
auto find = _variants.find(name);
|
||||||
if (find != _variants.end()) {
|
if (find != _variants.end()) {
|
||||||
delete find->second;
|
delete find->second;
|
||||||
|
|
|
@ -7,25 +7,24 @@
|
||||||
#include "../Gender.hpp"
|
#include "../Gender.hpp"
|
||||||
#include "SpeciesVariant.hpp"
|
#include "SpeciesVariant.hpp"
|
||||||
|
|
||||||
|
using ConstString = Arbutils::CaseInsensitiveConstString;
|
||||||
|
|
||||||
namespace CreatureLib::Library {
|
namespace CreatureLib::Library {
|
||||||
/*!
|
/*!
|
||||||
\brief This holds the data required for a species of a creature, so the general data we can describe different
|
\brief This holds the data required for a species of a creature, so the general data we can describe different
|
||||||
creatures with.
|
creatures with.
|
||||||
*/
|
*/
|
||||||
class CreatureSpecies {
|
class CreatureSpecies {
|
||||||
|
const ConstString _name;
|
||||||
uint16_t _id;
|
uint16_t _id;
|
||||||
float _genderRate;
|
float _genderRate;
|
||||||
const Arbutils::CaseInsensitiveConstString _growthRate;
|
const ConstString _growthRate;
|
||||||
uint8_t _captureRate;
|
uint8_t _captureRate;
|
||||||
|
std::unordered_map<ConstString, const SpeciesVariant*> _variants;
|
||||||
private:
|
|
||||||
std::unordered_map<Arbutils::CaseInsensitiveConstString, const SpeciesVariant*> _variants;
|
|
||||||
Arbutils::CaseInsensitiveConstString _name;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CreatureSpecies(uint16_t id, const Arbutils::CaseInsensitiveConstString& name,
|
CreatureSpecies(uint16_t id, const ConstString& name, const SpeciesVariant* defaultVariant, float genderRatio,
|
||||||
const SpeciesVariant* defaultVariant, float genderRatio,
|
const ConstString& growthRate, uint8_t captureRate);
|
||||||
const Arbutils::CaseInsensitiveConstString& growthRate, uint8_t captureRate);
|
|
||||||
|
|
||||||
virtual ~CreatureSpecies() {
|
virtual ~CreatureSpecies() {
|
||||||
for (auto v : _variants)
|
for (auto v : _variants)
|
||||||
|
@ -35,22 +34,18 @@ namespace CreatureLib::Library {
|
||||||
|
|
||||||
inline uint16_t GetId() const { return _id; }
|
inline uint16_t GetId() const { return _id; }
|
||||||
inline float GetGenderRate() const { return _genderRate; }
|
inline float GetGenderRate() const { return _genderRate; }
|
||||||
inline const Arbutils::CaseInsensitiveConstString& GetGrowthRate() const { return _growthRate; }
|
inline const ConstString& GetGrowthRate() const { return _growthRate; }
|
||||||
inline uint8_t GetCaptureRate() const { return _captureRate; }
|
inline uint8_t GetCaptureRate() const { return _captureRate; }
|
||||||
|
|
||||||
[[nodiscard]] bool HasVariant(const Arbutils::CaseInsensitiveConstString& key) const;
|
[[nodiscard]] bool HasVariant(const ConstString& key) const;
|
||||||
[[nodiscard]] bool TryGetVariant(const Arbutils::CaseInsensitiveConstString& name,
|
[[nodiscard]] bool TryGetVariant(const ConstString& name, const SpeciesVariant*& out) const;
|
||||||
const SpeciesVariant*& out) const;
|
[[nodiscard]] const SpeciesVariant* GetVariant(const ConstString& key) const;
|
||||||
[[nodiscard]] const SpeciesVariant* GetVariant(const Arbutils::CaseInsensitiveConstString& key) const;
|
|
||||||
[[nodiscard]] Gender GetRandomGender(Arbutils::Random& rand) const;
|
[[nodiscard]] Gender GetRandomGender(Arbutils::Random& rand) const;
|
||||||
[[nodiscard]] const Arbutils::CaseInsensitiveConstString& GetName() const { return _name; }
|
[[nodiscard]] const ConstString& GetName() const { return _name; }
|
||||||
|
|
||||||
void SetVariant(const Arbutils::CaseInsensitiveConstString& name, const SpeciesVariant* variant);
|
void SetVariant(const ConstString& name, const SpeciesVariant* variant);
|
||||||
|
|
||||||
const std::unordered_map<Arbutils::CaseInsensitiveConstString, const SpeciesVariant*>&
|
const std::unordered_map<ConstString, const SpeciesVariant*>& GetVariantsIterator() const { return _variants; }
|
||||||
GetVariantsIterator() const {
|
|
||||||
return _variants;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ uint32_t CreatureLib::Library::SpeciesVariant::GetStatistic(CreatureLib::Core::S
|
||||||
return _baseStatistics.GetStat(stat);
|
return _baseStatistics.GetStat(stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& CreatureLib::Library::SpeciesVariant::GetTalent(int32_t index) const {
|
const ConstString& CreatureLib::Library::SpeciesVariant::GetTalent(int32_t index) const {
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
index = -index - 1;
|
index = -index - 1;
|
||||||
return _secretTalents[index];
|
return _secretTalents[index];
|
||||||
|
@ -20,10 +20,6 @@ const std::string& CreatureLib::Library::SpeciesVariant::GetTalent(int32_t index
|
||||||
return _talents[index];
|
return _talents[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*const CreatureLib::Library::CreatureMoves *CreatureLib::Library::SpeciesVariant::GetCreatureMoves() const {
|
|
||||||
return &_moves;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
int8_t CreatureLib::Library::SpeciesVariant::GetTalentIndex(const std::string& talent) const {
|
int8_t CreatureLib::Library::SpeciesVariant::GetTalentIndex(const std::string& talent) const {
|
||||||
auto i = std::find(_talents.begin(), _talents.end(), talent);
|
auto i = std::find(_talents.begin(), _talents.end(), talent);
|
||||||
if (i != _talents.end()) {
|
if (i != _talents.end()) {
|
||||||
|
@ -44,11 +40,11 @@ const CreatureLib::Library::LearnableAttacks* CreatureLib::Library::SpeciesVaria
|
||||||
return _attacks;
|
return _attacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
CreatureLib::Library::SpeciesVariant::SpeciesVariant(std::string name, float height, float weight,
|
CreatureLib::Library::SpeciesVariant::SpeciesVariant(ConstString name, float height, float weight,
|
||||||
uint32_t baseExperience, std::vector<uint8_t> types,
|
uint32_t baseExperience, std::vector<uint8_t> types,
|
||||||
CreatureLib::Core::StatisticSet<uint16_t> baseStats,
|
CreatureLib::Core::StatisticSet<uint16_t> baseStats,
|
||||||
std::vector<std::string> talents,
|
std::vector<ConstString> talents,
|
||||||
std::vector<std::string> secretTalents,
|
std::vector<ConstString> secretTalents,
|
||||||
const LearnableAttacks* attacks)
|
const LearnableAttacks* attacks)
|
||||||
: _name(std::move(name)), _height(height), _weight(weight), _baseExperience(baseExperience),
|
: _name(std::move(name)), _height(height), _weight(weight), _baseExperience(baseExperience),
|
||||||
_types(std::move(types)), _baseStatistics(baseStats), _talents(std::move(talents)),
|
_types(std::move(types)), _baseStatistics(baseStats), _talents(std::move(talents)),
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "../../Core/StatisticSet.hpp"
|
#include "../../Core/StatisticSet.hpp"
|
||||||
#include "CreatureMoves.hpp"
|
#include "CreatureMoves.hpp"
|
||||||
#include "LearnableAttacks.hpp"
|
#include "LearnableAttacks.hpp"
|
||||||
|
using ConstString = Arbutils::CaseInsensitiveConstString;
|
||||||
|
|
||||||
namespace CreatureLib::Library {
|
namespace CreatureLib::Library {
|
||||||
/*!
|
/*!
|
||||||
|
@ -14,7 +15,7 @@ namespace CreatureLib::Library {
|
||||||
*/
|
*/
|
||||||
class SpeciesVariant {
|
class SpeciesVariant {
|
||||||
protected:
|
protected:
|
||||||
std::string _name;
|
ConstString _name;
|
||||||
float _height;
|
float _height;
|
||||||
float _weight;
|
float _weight;
|
||||||
uint32_t _baseExperience;
|
uint32_t _baseExperience;
|
||||||
|
@ -22,19 +23,19 @@ namespace CreatureLib::Library {
|
||||||
private:
|
private:
|
||||||
std::vector<uint8_t> _types;
|
std::vector<uint8_t> _types;
|
||||||
const Core::StatisticSet<uint16_t> _baseStatistics;
|
const Core::StatisticSet<uint16_t> _baseStatistics;
|
||||||
std::vector<std::string> _talents;
|
std::vector<ConstString> _talents;
|
||||||
std::vector<std::string> _secretTalents;
|
std::vector<ConstString> _secretTalents;
|
||||||
const LearnableAttacks* _attacks;
|
const LearnableAttacks* _attacks;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SpeciesVariant(std::string name, float height, float weight, uint32_t baseExperience,
|
SpeciesVariant(ConstString name, float height, float weight, uint32_t baseExperience,
|
||||||
std::vector<uint8_t> types, Core::StatisticSet<uint16_t> baseStats,
|
std::vector<uint8_t> types, Core::StatisticSet<uint16_t> baseStats,
|
||||||
std::vector<std::string> talents, std::vector<std::string> secretTalents,
|
std::vector<ConstString> talents, std::vector<ConstString> secretTalents,
|
||||||
const LearnableAttacks* attacks);
|
const LearnableAttacks* attacks);
|
||||||
|
|
||||||
virtual ~SpeciesVariant();
|
virtual ~SpeciesVariant();
|
||||||
|
|
||||||
inline const std::string& GetName() const { return _name; }
|
inline const ConstString& GetName() const { return _name; }
|
||||||
inline float GetHeight() const { return _height; }
|
inline float GetHeight() const { return _height; }
|
||||||
inline float GetWeight() const { return _weight; }
|
inline float GetWeight() const { return _weight; }
|
||||||
inline uint32_t GetBaseExperience() const { return _baseExperience; }
|
inline uint32_t GetBaseExperience() const { return _baseExperience; }
|
||||||
|
@ -43,12 +44,12 @@ namespace CreatureLib::Library {
|
||||||
[[nodiscard]] uint8_t GetType(size_t index) const;
|
[[nodiscard]] uint8_t GetType(size_t index) const;
|
||||||
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const;
|
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const;
|
||||||
[[nodiscard]] uint32_t GetStatistic(Core::Statistic stat) const;
|
[[nodiscard]] uint32_t GetStatistic(Core::Statistic stat) const;
|
||||||
[[nodiscard]] const std::string& GetTalent(int32_t index) const;
|
[[nodiscard]] const ConstString& GetTalent(int32_t index) const;
|
||||||
[[nodiscard]] const LearnableAttacks* GetLearnableAttacks() const;
|
[[nodiscard]] const LearnableAttacks* GetLearnableAttacks() const;
|
||||||
[[nodiscard]] int8_t GetTalentIndex(const std::string& talent) const;
|
[[nodiscard]] int8_t GetTalentIndex(const std::string& talent) const;
|
||||||
[[nodiscard]] int8_t GetRandomTalent(Arbutils::Random* rand) const;
|
[[nodiscard]] int8_t GetRandomTalent(Arbutils::Random* rand) const;
|
||||||
[[nodiscard]] inline const std::vector<std::string>& GetTalents() const { return _talents; }
|
[[nodiscard]] inline const std::vector<ConstString>& GetTalents() const { return _talents; }
|
||||||
[[nodiscard]] inline const std::vector<std::string>& GetSecretTalents() const { return _secretTalents; }
|
[[nodiscard]] inline const std::vector<ConstString>& GetSecretTalents() const { return _secretTalents; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,11 +9,11 @@ using namespace CreatureLib::Battling;
|
||||||
|
|
||||||
class TestScript : public Script {
|
class TestScript : public Script {
|
||||||
private:
|
private:
|
||||||
std::string _name;
|
ConstString _name;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TestScript(std::string name) : _name(std::move(name)){};
|
explicit TestScript(std::string name) : _name(std::move(name)){};
|
||||||
const std::string& GetName() const override { return _name; }
|
const ConstString& GetName() const override { return _name; }
|
||||||
|
|
||||||
void TestMethod(int& runCount) { runCount++; }
|
void TestMethod(int& runCount) { runCount++; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,11 +9,11 @@ using namespace CreatureLib::Battling;
|
||||||
|
|
||||||
class TestScript : public Script {
|
class TestScript : public Script {
|
||||||
private:
|
private:
|
||||||
std::string _name;
|
ConstString _name;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TestScript(std::string name) : _name(std::move(name)){};
|
explicit TestScript(std::string name) : _name(std::move(name)){};
|
||||||
const std::string& GetName() const override { return _name; }
|
const ConstString& GetName() const override { return _name; }
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_CASE("Empty script set count == 0", "[Battling, Scripting]") {
|
TEST_CASE("Empty script set count == 0", "[Battling, Scripting]") {
|
||||||
|
@ -64,7 +64,7 @@ TEST_CASE("Add script to script set, then remove it", "[Battling, Scripting]") {
|
||||||
auto s = new TestScript("foobar");
|
auto s = new TestScript("foobar");
|
||||||
set.Add(s);
|
set.Add(s);
|
||||||
REQUIRE(set.Count() == 1);
|
REQUIRE(set.Count() == 1);
|
||||||
set.Remove("foobar");
|
set.Remove("foobar"_cnc);
|
||||||
REQUIRE(set.Count() == 0);
|
REQUIRE(set.Count() == 0);
|
||||||
auto it = set.GetIterator();
|
auto it = set.GetIterator();
|
||||||
REQUIRE(it->empty());
|
REQUIRE(it->empty());
|
||||||
|
@ -77,7 +77,7 @@ TEST_CASE("Add two scripts to script set, then remove them", "[Battling, Scripti
|
||||||
set.Add(s);
|
set.Add(s);
|
||||||
set.Add(s2);
|
set.Add(s2);
|
||||||
REQUIRE(set.Count() == 2);
|
REQUIRE(set.Count() == 2);
|
||||||
set.Remove("foobar");
|
set.Remove("foobar"_cnc);
|
||||||
REQUIRE(set.Count() == 1);
|
REQUIRE(set.Count() == 1);
|
||||||
auto it = set.GetIterator();
|
auto it = set.GetIterator();
|
||||||
REQUIRE(it->at(0)->GetName() == "foobar2");
|
REQUIRE(it->at(0)->GetName() == "foobar2");
|
||||||
|
|
|
@ -10,11 +10,11 @@ using namespace CreatureLib::Battling;
|
||||||
|
|
||||||
class TestScript : public Script {
|
class TestScript : public Script {
|
||||||
private:
|
private:
|
||||||
std::string _name;
|
ConstString _name;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TestScript(std::string name) : _name(std::move(name)){};
|
explicit TestScript(std::string name) : _name(std::move(name)){};
|
||||||
const std::string& GetName() const override { return _name; }
|
const ConstString& GetName() const override { return _name; }
|
||||||
|
|
||||||
void TestMethod(int& runCount) { runCount++; }
|
void TestMethod(int& runCount) { runCount++; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,9 +24,9 @@ SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() {
|
||||||
auto l = new SpeciesLibrary();
|
auto l = new SpeciesLibrary();
|
||||||
l->Insert("testSpecies1"_cnc,
|
l->Insert("testSpecies1"_cnc,
|
||||||
new CreatureSpecies(0, "testSpecies1"_cnc,
|
new CreatureSpecies(0, "testSpecies1"_cnc,
|
||||||
new SpeciesVariant("default", 1, 1, 10, {0, 1},
|
new SpeciesVariant("default"_cnc, 1, 1, 10, {0, 1},
|
||||||
StatisticSet<uint16_t>(10, 10, 10, 10, 10, 10), {"testTalent"},
|
StatisticSet<uint16_t>(10, 10, 10, 10, 10, 10), {"testTalent"_cnc},
|
||||||
{"testSecretTalent"}, new LearnableAttacks(100)),
|
{"testSecretTalent"_cnc}, new LearnableAttacks(100)),
|
||||||
0.5f, "testGrowthRate"_cnc, 5));
|
0.5f, "testGrowthRate"_cnc, 5));
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue