diff --git a/src/Battling/Models/CreateCreature.cpp b/src/Battling/Models/CreateCreature.cpp index 1e58650..695aef6 100644 --- a/src/Battling/Models/CreateCreature.cpp +++ b/src/Battling/Models/CreateCreature.cpp @@ -5,8 +5,8 @@ using namespace CreatureLib::Battling; -CreateCreature* CreateCreature::WithVariant(std::string variant) { - this->_variant = std::move(variant); +CreateCreature* CreateCreature::WithVariant(const Arbutils::CaseInsensitiveConstString& variant) { + this->_variant = variant; return this; } @@ -20,18 +20,19 @@ CreateCreature* CreateCreature::WithGender(Library::Gender gender) { return this; } -CreateCreature* CreateCreature::WithAttack(const std::string& attackName, AttackLearnMethod learnMethod) { +CreateCreature* CreateCreature::WithAttack(const Arbutils::CaseInsensitiveConstString& attackName, + AttackLearnMethod learnMethod) { if (_attacks.size() >= _library->GetSettings()->GetMaximalMoves()) throw CreatureException("You have already set the maximum amount of allowed moves."); - auto attackData = _library->GetAttackLibrary()->Get(attackName.c_str()); + auto attackData = _library->GetAttackLibrary()->Get(attackName); _attacks.emplace_back(attackData, learnMethod); return this; } Creature* CreateCreature::Create() { auto rand = Arbutils::Random(); - auto species = this->_library->GetSpeciesLibrary()->Get(this->_species.c_str()); + auto species = this->_library->GetSpeciesLibrary()->Get(this->_species); auto variant = species->GetVariant(this->_variant); int8_t talent; if (this->_talent.empty()) { @@ -48,8 +49,8 @@ Creature* CreateCreature::Create() { gender = species->GetRandomGender(rand); } const Library::Item* heldItem = nullptr; - if (!this->_heldItem.empty()) { - if (!_library->GetItemLibrary()->TryGet(this->_heldItem.c_str(), heldItem)) { + if (!this->_heldItem.Empty()) { + if (!_library->GetItemLibrary()->TryGet(this->_heldItem, heldItem)) { throw CreatureException("Invalid held item."); } } diff --git a/src/Battling/Models/CreateCreature.hpp b/src/Battling/Models/CreateCreature.hpp index ff7a274..a55943d 100644 --- a/src/Battling/Models/CreateCreature.hpp +++ b/src/Battling/Models/CreateCreature.hpp @@ -7,15 +7,15 @@ namespace CreatureLib::Battling { class CreateCreature { const BattleLibrary* _library; - std::string _species; - std::string _variant = "default"; + Arbutils::CaseInsensitiveConstString _species; + Arbutils::CaseInsensitiveConstString _variant = "default"_cnc; uint8_t _level; std::string _nickname = ""; std::string _talent = ""; Library::Gender _gender = static_cast(-1); uint8_t _coloring = 0; - std::string _heldItem = ""; + Arbutils::CaseInsensitiveConstString _heldItem = ""_cnc; uint32_t _identifier = 0; std::vector> _attacks = {}; @@ -23,10 +23,11 @@ namespace CreatureLib::Battling { CreateCreature(const BattleLibrary* library, std::string species, uint8_t level) : _library(library), _species(std::move(species)), _level(level) {} - CreateCreature* WithVariant(std::string variant); + CreateCreature* WithVariant(const Arbutils::CaseInsensitiveConstString& variant); CreateCreature* WithNickname(std::string nickname); CreateCreature* WithGender(Library::Gender gender); - CreateCreature* WithAttack(const std::string& attackName, AttackLearnMethod learnMethod); + CreateCreature* WithAttack(const Arbutils::CaseInsensitiveConstString& attackName, + AttackLearnMethod learnMethod); Creature* Create(); }; diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index d89cef4..14276bf 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -13,7 +13,11 @@ Battling::Creature::Creature(const BattleLibrary* library, const Library::Creatu : _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)) { + _activeTalent = _library->LoadScript(ScriptCategory::Talent, GetActiveTalent()); + if (_nickname.empty()) { + _nickname = species->GetName().std_str(); + } } void Battling::Creature::ChangeLevel(int8_t amount) { @@ -21,12 +25,6 @@ void Battling::Creature::ChangeLevel(int8_t amount) { RecalculateFlatStats(); } -const std::string& Battling::Creature::GetNickname() const { - if (_nickname.empty()) - return _species->GetName(); - return _nickname; -} - const std::string& Battling::Creature::GetActiveTalent() const { if (_hasOverridenTalent) { return _overridenTalentName; @@ -178,7 +176,7 @@ const Library::SpeciesVariant* Battling::Creature::GetDisplayVariant() const { variant = _variant; return variant; } -void Battling::Creature::SetHeldItem(const std::string& itemName) { +void Battling::Creature::SetHeldItem(const Arbutils::CaseInsensitiveConstString& itemName) { const Library::Item* item; if (!_library->GetItemLibrary()->TryGet(itemName, item)) { throw CreatureException("Item not found."); diff --git a/src/Battling/Models/Creature.hpp b/src/Battling/Models/Creature.hpp index 2df8012..2f96afb 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -86,7 +86,7 @@ namespace CreatureLib::Battling { return _heldItem != nullptr && _heldItem->GetName() == name; } inline const Library::Item* GetHeldItem() const { return _heldItem; } - void SetHeldItem(const std::string& itemName); + void SetHeldItem(const Arbutils::CaseInsensitiveConstString& itemName); inline void SetHeldItem(const Library::Item* item) { _heldItem = item; }; inline uint32_t GetCurrentHealth() const { return _currentHealth; } @@ -97,7 +97,7 @@ namespace CreatureLib::Battling { void SetOnBattleField(bool value) { _onBattleField = value; } bool IsOnBattleField() const { return _onBattleField; } - const std::string& GetNickname() const; + const std::string& GetNickname() const { return _nickname; } const std::string& GetActiveTalent() const; [[nodiscard]] bool IsFainted() const; diff --git a/src/Library/Attacks/AttackData.cpp b/src/Library/Attacks/AttackData.cpp index c860790..0483814 100644 --- a/src/Library/Attacks/AttackData.cpp +++ b/src/Library/Attacks/AttackData.cpp @@ -5,10 +5,10 @@ CreatureLib::Library::AttackData::AttackData(std::string name, uint8_t type, CreatureLib::Library::AttackCategory category, uint8_t power, uint8_t accuracy, uint8_t baseUsage, CreatureLib::Library::AttackTarget target, int8_t priority, - std::unordered_set flags) + std::unordered_set flags) : _name(std::move(name)), _type(type), _category(category), _basePower(power), _accuracy(accuracy), _baseUsages(baseUsage), _target(target), _priority(priority), _flags(std::move(flags)) {} -bool CreatureLib::Library::AttackData::HasFlag(const std::string& key) const { +bool CreatureLib::Library::AttackData::HasFlag(const Arbutils::CaseInsensitiveConstString& key) const { return this->_flags.find(key) != this->_flags.end(); } diff --git a/src/Library/Attacks/AttackData.hpp b/src/Library/Attacks/AttackData.hpp index 303d451..b6fd44f 100644 --- a/src/Library/Attacks/AttackData.hpp +++ b/src/Library/Attacks/AttackData.hpp @@ -1,6 +1,7 @@ #ifndef CREATURELIB_ATTACKDATA_HPP #define CREATURELIB_ATTACKDATA_HPP +#include #include #include #include "AttackCategory.hpp" @@ -17,11 +18,12 @@ namespace CreatureLib::Library { uint8_t _baseUsages; AttackTarget _target; int8_t _priority; - std::unordered_set _flags; + std::unordered_set _flags; public: AttackData(std::string name, uint8_t type, AttackCategory category, uint8_t power, uint8_t accuracy, - uint8_t baseUsage, AttackTarget target, int8_t priority, std::unordered_set flags); + uint8_t baseUsage, AttackTarget target, int8_t priority, + std::unordered_set flags); virtual ~AttackData() = default; inline const std::string& GetName() const { return _name; } @@ -33,7 +35,7 @@ namespace CreatureLib::Library { inline AttackTarget GetTarget() const { return _target; } inline int8_t GetPriority() const { return _priority; } - bool HasFlag(const std::string& key) const; + bool HasFlag(const Arbutils::CaseInsensitiveConstString& key) const; }; } diff --git a/src/Library/BaseLibrary.hpp b/src/Library/BaseLibrary.hpp index 399b591..19ab643 100644 --- a/src/Library/BaseLibrary.hpp +++ b/src/Library/BaseLibrary.hpp @@ -1,16 +1,13 @@ #ifndef CREATURELIB_BASELIBRARY_HPP #define CREATURELIB_BASELIBRARY_HPP +#include #include #include #include + namespace CreatureLib::Library { template class BaseLibrary { - inline static constexpr char charToLower(const char c) { return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c; } - inline static uint32_t constexpr Hash(char const* input) { - return charToLower(*input) ? static_cast(charToLower(*input)) + 33 * Hash(input + 1) : 5381; - } - std::unordered_map _values; public: @@ -23,14 +20,13 @@ namespace CreatureLib::Library { _values.clear(); } - inline void Insert(const char* key, const T* value) { _values.insert({Hash(key), value}); } - inline void Insert(const std::string& key, const T* value) { Insert(key.c_str(), value); } + inline void Insert(const Arbutils::CaseInsensitiveConstString& key, const T* value) { + _values.insert({key.GetHash(), value}); + } + inline void Delete(const Arbutils::CaseInsensitiveConstString& key) { _values.erase(key.GetHash()); } - inline void Delete(const char* key) { _values.erase(Hash(key)); } - inline void Delete(const std::string& key) { Delete(key.c_str()); } - - bool TryGet(const char* name, const T*& out) const { - auto find = this->_values.find(Hash(name)); + bool TryGet(const Arbutils::CaseInsensitiveConstString& name, const T*& out) const { + auto find = this->_values.find(name.GetHash()); if (find == this->_values.end()) { out = nullptr; return false; @@ -38,16 +34,10 @@ namespace CreatureLib::Library { out = find->second; return true; } - bool TryGet(const std::string& name, const T*& out) const { - return TryGet(name.c_str(), out); + inline const T* Get(const Arbutils::CaseInsensitiveConstString& name) const { + return _values.at(name.GetHash()); } - - inline const T* Get(const char* name) const { return _values.at(Hash(name)); } - inline const T* Get(const std::string& name) const { return Get(name.c_str()); } - - inline const T* operator[](const char* name) const { return Get(name); } - inline const T* operator[](const std::string& name) const { return Get(name.c_str()); } - + inline const T* operator[](const Arbutils::CaseInsensitiveConstString& name) const { return Get(name); } inline const std::unordered_map& GetIterator() const { return _values; } size_t GetCount() const { return _values.size(); } diff --git a/src/Library/CreatureData/CreatureSpecies.cpp b/src/Library/CreatureData/CreatureSpecies.cpp index 387b6d9..baf8ccd 100644 --- a/src/Library/CreatureData/CreatureSpecies.cpp +++ b/src/Library/CreatureData/CreatureSpecies.cpp @@ -2,21 +2,19 @@ using namespace CreatureLib::Library; -CreatureSpecies::CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant, float genderRatio, - std::string growthRate, uint8_t captureRate) - : _id(id), _genderRate(genderRatio), _growthRate(std::move(growthRate)), _captureRate(captureRate), - _variants({{"default", defaultVariant}}), _name(std::move(name)) {} +CreatureSpecies::CreatureSpecies(uint16_t id, const Arbutils::CaseInsensitiveConstString& name, + const SpeciesVariant* defaultVariant, float genderRatio, + const Arbutils::CaseInsensitiveConstString& growthRate, uint8_t captureRate) + : _id(id), _genderRate(genderRatio), _growthRate(growthRate), _captureRate(captureRate), + _variants({{"default"_cnc, defaultVariant}}), _name(name) {} -bool CreatureSpecies::HasVariant(const std::string& name) const { - auto key = name; - std::transform(key.begin(), key.end(), key.begin(), ::tolower); - return _variants.find(key) != _variants.end(); +bool CreatureSpecies::HasVariant(const Arbutils::CaseInsensitiveConstString& name) const { + return _variants.find(name) != _variants.end(); } -bool CreatureSpecies::TryGetVariant(const std::string& name, const SpeciesVariant*& out) const { - auto key = name; - std::transform(key.begin(), key.end(), key.begin(), ::tolower); - auto find = _variants.find(key); +bool CreatureSpecies::TryGetVariant(const Arbutils::CaseInsensitiveConstString& name, + const SpeciesVariant*& out) const { + auto find = _variants.find(name); if (find != _variants.end()) { out = find->second; return true; @@ -24,20 +22,17 @@ bool CreatureSpecies::TryGetVariant(const std::string& name, const SpeciesVarian return false; } -const SpeciesVariant* CreatureSpecies::GetVariant(const std::string& name) const { +const SpeciesVariant* CreatureSpecies::GetVariant(const Arbutils::CaseInsensitiveConstString& name) const { auto key = name; - std::transform(key.begin(), key.end(), key.begin(), ::tolower); return _variants.at(key); } -void CreatureSpecies::SetVariant(const std::string& name, const SpeciesVariant* variant) { - auto key = name; - std::transform(key.begin(), key.end(), key.begin(), ::tolower); - auto find = _variants.find(key); +void CreatureSpecies::SetVariant(const Arbutils::CaseInsensitiveConstString& name, const SpeciesVariant* variant) { + auto find = _variants.find(name); if (find != _variants.end()) { delete find->second; } - _variants[key] = variant; + _variants[name] = variant; } Gender CreatureSpecies::GetRandomGender(Arbutils::Random& rand) const { @@ -46,6 +41,4 @@ Gender CreatureSpecies::GetRandomGender(Arbutils::Random& rand) const { if (val >= this->_genderRate) return Gender ::Female; return Gender ::Male; -} - -const std::string& CreatureSpecies::GetName() const { return _name; } +} \ No newline at end of file diff --git a/src/Library/CreatureData/CreatureSpecies.hpp b/src/Library/CreatureData/CreatureSpecies.hpp index d959261..3ae734b 100644 --- a/src/Library/CreatureData/CreatureSpecies.hpp +++ b/src/Library/CreatureData/CreatureSpecies.hpp @@ -1,6 +1,7 @@ #ifndef CREATURELIB_CREATURESPECIES_HPP #define CREATURELIB_CREATURESPECIES_HPP +#include #include #include #include "../Gender.hpp" @@ -14,16 +15,17 @@ namespace CreatureLib::Library { class CreatureSpecies { uint16_t _id; float _genderRate; - std::string _growthRate; + const Arbutils::CaseInsensitiveConstString _growthRate; uint8_t _captureRate; private: - std::unordered_map _variants; - std::string _name; + std::unordered_map _variants; + Arbutils::CaseInsensitiveConstString _name; public: - CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant, float genderRatio, - std::string growthRate, uint8_t captureRate); + CreatureSpecies(uint16_t id, const Arbutils::CaseInsensitiveConstString& name, + const SpeciesVariant* defaultVariant, float genderRatio, + const Arbutils::CaseInsensitiveConstString& growthRate, uint8_t captureRate); virtual ~CreatureSpecies() { for (auto v : _variants) @@ -33,18 +35,22 @@ namespace CreatureLib::Library { inline uint16_t GetId() const { return _id; } inline float GetGenderRate() const { return _genderRate; } - inline const std::string& GetGrowthRate() const { return _growthRate; } + inline const Arbutils::CaseInsensitiveConstString& GetGrowthRate() const { return _growthRate; } inline uint8_t GetCaptureRate() const { return _captureRate; } - [[nodiscard]] bool HasVariant(const std::string& key) const; - [[nodiscard]] bool TryGetVariant(const std::string& name, const SpeciesVariant*& out) const; - [[nodiscard]] const SpeciesVariant* GetVariant(const std::string& key) const; + [[nodiscard]] bool HasVariant(const Arbutils::CaseInsensitiveConstString& key) const; + [[nodiscard]] bool TryGetVariant(const Arbutils::CaseInsensitiveConstString& name, + const SpeciesVariant*& out) const; + [[nodiscard]] const SpeciesVariant* GetVariant(const Arbutils::CaseInsensitiveConstString& key) const; [[nodiscard]] Gender GetRandomGender(Arbutils::Random& rand) const; - [[nodiscard]] const std::string& GetName() const; + [[nodiscard]] const Arbutils::CaseInsensitiveConstString& GetName() const { return _name; } - void SetVariant(const std::string& name, const SpeciesVariant* variant); + void SetVariant(const Arbutils::CaseInsensitiveConstString& name, const SpeciesVariant* variant); - const std::unordered_map& GetVariantsIterator() const { return _variants; } + const std::unordered_map& + GetVariantsIterator() const { + return _variants; + } }; } diff --git a/src/Library/GrowthRates/GrowthRateLibrary.cpp b/src/Library/GrowthRates/GrowthRateLibrary.cpp index cb46eb5..6b6e7b0 100644 --- a/src/Library/GrowthRates/GrowthRateLibrary.cpp +++ b/src/Library/GrowthRates/GrowthRateLibrary.cpp @@ -2,30 +2,25 @@ #include #include "../../Core/Exceptions/CreatureException.hpp" -uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const std::string& growthRate, +uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const Arbutils::CaseInsensitiveConstString& growthRate, uint32_t experience) const { - auto g = growthRate; - std::transform(g.begin(), g.end(), g.begin(), ::tolower); - auto find = _growthRates.find(g); + auto find = _growthRates.find(growthRate); if (find == _growthRates.end()) { throw CreatureException("Invalid growth rate was requested."); } return find->second->CalculateLevel(experience); } -uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const std::string& growthRate, - uint8_t level) const { - auto g = growthRate; - std::transform(g.begin(), g.end(), g.begin(), ::tolower); - auto find = _growthRates.find(g); +uint32_t +CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const Arbutils::CaseInsensitiveConstString& growthRate, + uint8_t level) const { + auto find = _growthRates.find(growthRate); if (find == _growthRates.end()) { throw CreatureException("Invalid growth rate was requested."); } return find->second->CalculateExperience(level); } -void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const std::string& name, +void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const Arbutils::CaseInsensitiveConstString& name, CreatureLib::Library::GrowthRate* rate) { - auto g = name; - std::transform(g.begin(), g.end(), g.begin(), ::tolower); - _growthRates.insert({g, rate}); + _growthRates.insert({name, rate}); } diff --git a/src/Library/GrowthRates/GrowthRateLibrary.hpp b/src/Library/GrowthRates/GrowthRateLibrary.hpp index 21fccf9..5b10bc8 100644 --- a/src/Library/GrowthRates/GrowthRateLibrary.hpp +++ b/src/Library/GrowthRates/GrowthRateLibrary.hpp @@ -1,6 +1,7 @@ #ifndef CREATURELIB_GROWTHRATELIBRARY_HPP #define CREATURELIB_GROWTHRATELIBRARY_HPP +#include #include #include #include @@ -9,11 +10,11 @@ namespace CreatureLib::Library { class GrowthRateLibrary { private: - std::unordered_map _growthRates; + std::unordered_map _growthRates; public: GrowthRateLibrary(size_t initialCapacity = 10) - : _growthRates(std::unordered_map(initialCapacity)) {} + : _growthRates(std::unordered_map(initialCapacity)) {} virtual ~GrowthRateLibrary() { for (auto gr : _growthRates) { @@ -21,10 +22,12 @@ namespace CreatureLib::Library { } } - [[nodiscard]] uint8_t CalculateLevel(const std::string& growthRate, uint32_t experience) const; - [[nodiscard]] uint32_t CalculateExperience(const std::string& growthRate, uint8_t level) const; + [[nodiscard]] uint8_t CalculateLevel(const Arbutils::CaseInsensitiveConstString& growthRate, + uint32_t experience) const; + [[nodiscard]] uint32_t CalculateExperience(const Arbutils::CaseInsensitiveConstString& growthRate, + uint8_t level) const; - void AddGrowthRate(const std::string& name, GrowthRate* rate); + void AddGrowthRate(const Arbutils::CaseInsensitiveConstString& name, GrowthRate* rate); }; } diff --git a/src/Library/Items/Item.cpp b/src/Library/Items/Item.cpp index 4af4377..4c4b049 100644 --- a/src/Library/Items/Item.cpp +++ b/src/Library/Items/Item.cpp @@ -1,9 +1,9 @@ #include "Item.hpp" -bool CreatureLib::Library::Item::HasFlag(const std::string& flag) const { +bool CreatureLib::Library::Item::HasFlag(const Arbutils::CaseInsensitiveConstString& flag) const { return this->_flags.find(flag) != this->_flags.end(); } CreatureLib::Library::Item::Item(std::string name, CreatureLib::Library::ItemCategory category, CreatureLib::Library::BattleItemCategory battleCategory, int32_t price, - std::unordered_set flags) + std::unordered_set flags) : _name(name), _category(category), _battleCategory(battleCategory), _price(price), _flags(flags) {} diff --git a/src/Library/Items/Item.hpp b/src/Library/Items/Item.hpp index d141126..ffac227 100644 --- a/src/Library/Items/Item.hpp +++ b/src/Library/Items/Item.hpp @@ -1,6 +1,7 @@ #ifndef CREATURELIB_ITEM_HPP #define CREATURELIB_ITEM_HPP +#include #include #include #include "BattleItemCategory.hpp" @@ -13,18 +14,18 @@ namespace CreatureLib::Library { ItemCategory _category; BattleItemCategory _battleCategory; int32_t _price; - std::unordered_set _flags; + std::unordered_set _flags; public: Item(std::string name, ItemCategory category, BattleItemCategory battleCategory, int32_t price, - std::unordered_set flags); + std::unordered_set flags); inline const std::string& GetName() const { return _name; } inline ItemCategory GetCategory() const { return _category; } inline BattleItemCategory GetBattleCategory() const { return _battleCategory; } inline const int32_t GetPrice() const { return _price; } - bool HasFlag(const std::string& flag) const; + bool HasFlag(const Arbutils::CaseInsensitiveConstString& flag) const; }; } diff --git a/tests/BattleTests/TurnOrderTests.cpp b/tests/BattleTests/TurnOrderTests.cpp index 1e548cd..53b07cd 100644 --- a/tests/BattleTests/TurnOrderTests.cpp +++ b/tests/BattleTests/TurnOrderTests.cpp @@ -28,8 +28,8 @@ TEST_CASE("Turn ordering: Attack before pass", "[Battling]") { TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]") { auto l = TestLibrary::Get()->GetAttackLibrary(); - auto a1 = new LearnedAttack(l->Get("standard"), AttackLearnMethod::Unknown); - auto a2 = new LearnedAttack(l->Get("highPriority"), AttackLearnMethod::Unknown); + auto a1 = new LearnedAttack(l->Get("standard"_cnc), AttackLearnMethod::Unknown); + auto a2 = new LearnedAttack(l->Get("highPriority"_cnc), AttackLearnMethod::Unknown); auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0)); auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0)); auto vec = std::vector{choice1, choice2}; @@ -50,8 +50,8 @@ TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]") TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling]") { auto l = TestLibrary::Get()->GetAttackLibrary(); - auto a1 = new LearnedAttack(l->Get("highPriority"), AttackLearnMethod::Unknown); - auto a2 = new LearnedAttack(l->Get("higherPriority"), AttackLearnMethod::Unknown); + auto a1 = new LearnedAttack(l->Get("highPriority"_cnc), AttackLearnMethod::Unknown); + auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc), AttackLearnMethod::Unknown); auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0)); auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0)); auto vec = std::vector{choice1, choice2}; @@ -72,8 +72,8 @@ TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]") { auto l = TestLibrary::Get()->GetAttackLibrary(); - auto a1 = new LearnedAttack(l->Get("lowPriority"), AttackLearnMethod::Unknown); - auto a2 = new LearnedAttack(l->Get("higherPriority"), AttackLearnMethod::Unknown); + auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc), AttackLearnMethod::Unknown); + auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc), AttackLearnMethod::Unknown); auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0)); auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0)); auto vec = std::vector{choice1, choice2}; @@ -94,8 +94,8 @@ TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]") TEST_CASE("Turn ordering: No priority goes before low priority", "[Battling]") { auto l = TestLibrary::Get()->GetAttackLibrary(); - auto a1 = new LearnedAttack(l->Get("lowPriority"), AttackLearnMethod::Unknown); - auto a2 = new LearnedAttack(l->Get("standard"), AttackLearnMethod::Unknown); + auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc), AttackLearnMethod::Unknown); + auto a2 = new LearnedAttack(l->Get("standard"_cnc), AttackLearnMethod::Unknown); auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0)); auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0)); auto vec = std::vector{choice1, choice2}; diff --git a/tests/Integration/BattleIntegrations.cpp b/tests/Integration/BattleIntegrations.cpp index 4c62864..906495e 100644 --- a/tests/Integration/BattleIntegrations.cpp +++ b/tests/Integration/BattleIntegrations.cpp @@ -13,7 +13,8 @@ using namespace Battling; TEST_CASE("Create Party", "[Integrations]") { auto library = TestLibrary::Get(); - auto c1 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c1 = + CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party1{c1}; auto battleParty = BattleParty(&party1, {CreatureIndex(0, 0)}); REQUIRE(battleParty.GetParty()->GetAtIndex(0) == c1); @@ -21,10 +22,12 @@ TEST_CASE("Create Party", "[Integrations]") { TEST_CASE("Create Battle", "[Integrations]") { auto library = TestLibrary::Get(); - auto c1 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c1 = + CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party1{c1}; auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)}); - auto c2 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c2 = + CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party2{c2}; auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)}); @@ -33,10 +36,12 @@ TEST_CASE("Create Battle", "[Integrations]") { TEST_CASE("Use damaging move", "[Integrations]") { auto library = TestLibrary::Get(); - auto c1 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c1 = + CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party1{c1}; auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)}); - auto c2 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c2 = + CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party2{c2}; auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)}); @@ -53,10 +58,12 @@ TEST_CASE("Use damaging move", "[Integrations]") { TEST_CASE("Finish battle when all battle of one side have fainted", "[Integrations]") { auto library = TestLibrary::Get(); - auto c1 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c1 = + CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party1{c1}; auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)}); - auto c2 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c2 = + CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party2{c2}; auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)}); @@ -86,10 +93,12 @@ TEST_CASE("Finish battle when all battle of one side have fainted", "[Integratio TEST_CASE("When creature is dealt enough damage, faint it and mark battle as ended", "[Integrations]") { auto library = TestLibrary::Get(); - auto c1 = CreateCreature(library, "testSpecies1", 100).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c1 = + CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party1{c1}; auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)}); - auto c2 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c2 = + CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party2{c2}; auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)}); @@ -113,11 +122,14 @@ TEST_CASE("When creature is dealt enough damage, faint it and mark battle as end TEST_CASE("When another creature is available on faint, make sure the battle hasn't ended", "[Integrations]") { auto library = TestLibrary::Get(); - auto c1 = CreateCreature(library, "testSpecies1", 100).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c1 = + CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party1{c1}; auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)}); - auto c2 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); - auto c3 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c2 = + CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); + auto c3 = + CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party2{c2, c3}; auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)}); @@ -148,11 +160,14 @@ TEST_CASE("When another creature is available on faint, make sure the battle has TEST_CASE("Switch Creature in", "[Integrations]") { auto library = TestLibrary::Get(); - auto c1 = CreateCreature(library, "testSpecies1", 100).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); - auto c2 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c1 = + CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); + auto c2 = + CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party1{c1, c2}; auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)}); - auto c3 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c3 = + CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party2{c3}; auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)}); @@ -171,11 +186,14 @@ TEST_CASE("Switch Creature in", "[Integrations]") { TEST_CASE("Switch Creature in, but have attack aimed at it. Attack should hit new creature", "[Integrations]") { auto library = TestLibrary::Get(); - auto c1 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); - auto c2 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c1 = + CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); + auto c2 = + CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party1{c1, c2}; auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)}); - auto c3 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c3 = + CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party2{c3}; auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)}); @@ -193,11 +211,14 @@ TEST_CASE("Switch Creature in, but have attack aimed at it. Attack should hit ne TEST_CASE("Switch Creature in, mark as seen opponent for opponent", "[Integrations]") { auto library = TestLibrary::Get(); - auto c1 = CreateCreature(library, "testSpecies1", 100).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); - auto c2 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c1 = + CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); + auto c2 = + CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party1{c1, c2}; auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)}); - auto c3 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c3 = + CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party2{c3}; auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)}); @@ -229,10 +250,12 @@ TEST_CASE("Switch Creature in, mark as seen opponent for opponent", "[Integratio TEST_CASE("Flee Battle", "[Integrations]") { auto library = TestLibrary::Get(); - auto c1 = CreateCreature(library, "testSpecies1", 100).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c1 = + CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party1{c1}; auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)}); - auto c2 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create(); + auto c2 = + CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create(); CreatureParty party2{c2}; auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)}); diff --git a/tests/LibraryTests/CreatureTests.cpp b/tests/LibraryTests/CreatureTests.cpp index 1166647..dc4cf18 100644 --- a/tests/LibraryTests/CreatureTests.cpp +++ b/tests/LibraryTests/CreatureTests.cpp @@ -13,7 +13,7 @@ TEST_CASE("Create basic creature", "[Library]") { TEST_CASE("Get creature species", "[Library]") { auto library = TestLibrary::Get(); auto creature = CreateCreature(library, "testSpecies1", 1).Create(); - REQUIRE(creature->GetSpecies()->GetName() == "testSpecies1"); + REQUIRE(creature->GetSpecies()->GetName() == "testSpecies1"_cnc); delete creature; } diff --git a/tests/TestLibrary/TestLibrary.cpp b/tests/TestLibrary/TestLibrary.cpp index c21c881..f8a2889 100644 --- a/tests/TestLibrary/TestLibrary.cpp +++ b/tests/TestLibrary/TestLibrary.cpp @@ -22,25 +22,25 @@ BattleLibrary* TestLibrary::Get() { SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() { auto l = new SpeciesLibrary(); - l->Insert("testSpecies1", - new CreatureSpecies(0, "testSpecies1", + l->Insert("testSpecies1"_cnc, + new CreatureSpecies(0, "testSpecies1"_cnc, new SpeciesVariant("default", 1, 1, 10, {0, 1}, StatisticSet(10, 10, 10, 10, 10, 10), {"testTalent"}, {"testSecretTalent"}, new LearnableAttacks(100)), - 0.5f, "testGrowthRate", 5)); + 0.5f, "testGrowthRate"_cnc, 5)); return l; } AttackLibrary* TestLibrary::BuildAttackLibrary() { auto l = new AttackLibrary(); - l->Insert("standard", new AttackData("standard", 0, AttackCategory::Physical, 20, 100, 30, - AttackTarget::AdjacentOpponent, 0, {})); - l->Insert("highPriority", new AttackData("highPriority", 0, AttackCategory::Physical, 20, 100, 30, - AttackTarget::AdjacentOpponent, 1, {})); - l->Insert("higherPriority", new AttackData("higherPriority", 0, AttackCategory::Physical, 20, 100, 30, - AttackTarget::AdjacentOpponent, 2, {})); - l->Insert("lowPriority", new AttackData("lowPriority", 0, AttackCategory::Physical, 20, 100, 30, - AttackTarget::AdjacentOpponent, -1, {})); + l->Insert("standard"_cnc, new AttackData("standard", 0, AttackCategory::Physical, 20, 100, 30, + AttackTarget::AdjacentOpponent, 0, {})); + l->Insert("highPriority"_cnc, new AttackData("highPriority", 0, AttackCategory::Physical, 20, 100, 30, + AttackTarget::AdjacentOpponent, 1, {})); + l->Insert("higherPriority"_cnc, new AttackData("higherPriority", 0, AttackCategory::Physical, 20, 100, 30, + AttackTarget::AdjacentOpponent, 2, {})); + l->Insert("lowPriority"_cnc, new AttackData("lowPriority", 0, AttackCategory::Physical, 20, 100, 30, + AttackTarget::AdjacentOpponent, -1, {})); return l; } @@ -51,7 +51,7 @@ ItemLibrary* TestLibrary::BuildItemLibrary() { GrowthRateLibrary* TestLibrary::BuildGrowthRateLibrary() { auto l = new GrowthRateLibrary(); - l->AddGrowthRate("testGrowthRate", new LookupGrowthRate()); + l->AddGrowthRate("testGrowthRate"_cnc, new LookupGrowthRate()); return l; }