From a7b87ab4f84e698bb6efec457fd874a960f365d9 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 22 Mar 2020 10:11:53 +0100 Subject: [PATCH] Merge Core library into Library, as with its utility functionality merged into Arbutils, it's becoming less and less useful. --- CInterface/Battling/BattleStatCalculator.cpp | 4 +- CInterface/Battling/Creature.cpp | 11 ++- CInterface/Library/SpeciesVariant.cpp | 8 +- CMakeLists.txt | 11 --- src/Battling/Flow/TurnHandler.cpp | 2 +- src/Battling/Flow/TurnOrdering.cpp | 4 +- src/Battling/Library/BattleStatCalculator.cpp | 42 +++++----- src/Battling/Library/BattleStatCalculator.hpp | 10 +-- src/Battling/Library/DamageLibrary.cpp | 12 +-- src/Battling/Models/Battle.cpp | 2 +- src/Battling/Models/BattleSide.cpp | 2 +- src/Battling/Models/Creature.cpp | 14 ++-- src/Battling/Models/Creature.hpp | 22 ++--- .../ScriptHandling/ScriptAggregator.hpp | 2 +- src/Core/StatisticSet.hpp | 81 ------------------- src/Library/CreatureData/SpeciesVariant.cpp | 4 +- src/Library/CreatureData/SpeciesVariant.hpp | 8 +- .../Exceptions/CreatureException.hpp | 0 .../Exceptions/NotImplementedException.hpp | 0 .../Exceptions/NotReachableException.hpp | 0 src/Library/GrowthRates/GrowthRateLibrary.cpp | 2 +- src/{Core => Library}/Statistic.hpp | 2 +- src/Library/StatisticSet.hpp | 81 +++++++++++++++++++ tests/ExceptionTests.cpp | 2 +- tests/Integration/BattleIntegrations.cpp | 4 +- tests/LibraryTests/CreatureTests.cpp | 4 +- tests/TestLibrary/TestLibrary.cpp | 1 - tests/TestLibrary/TestLibrary.hpp | 1 - 28 files changed, 162 insertions(+), 174 deletions(-) delete mode 100644 src/Core/StatisticSet.hpp rename src/{Core => Library}/Exceptions/CreatureException.hpp (100%) rename src/{Core => Library}/Exceptions/NotImplementedException.hpp (100%) rename src/{Core => Library}/Exceptions/NotReachableException.hpp (100%) rename src/{Core => Library}/Statistic.hpp (88%) create mode 100644 src/Library/StatisticSet.hpp diff --git a/CInterface/Battling/BattleStatCalculator.cpp b/CInterface/Battling/BattleStatCalculator.cpp index 5f83c1b..de3f989 100644 --- a/CInterface/Battling/BattleStatCalculator.cpp +++ b/CInterface/Battling/BattleStatCalculator.cpp @@ -7,10 +7,10 @@ export const BattleStatCalculator* CreatureLib_BattleStatCalculator_Construct() export void CreatureLib_BattleStatCalculator_Destruct(const BattleStatCalculator* p) { delete p; } export uint32_t CreatureLib_BattleStatCalculator_CalculateFlatStat(const BattleStatCalculator* p, Creature* creature, - CreatureLib::Core::Statistic stat) { + CreatureLib::Library::Statistic stat) { return p->CalculateFlatStat(creature, stat); } export uint32_t CreatureLib_BattleStatCalculator_CalculateBoostedStat(const BattleStatCalculator* p, Creature* creature, - CreatureLib::Core::Statistic stat) { + CreatureLib::Library::Statistic stat) { return p->CalculateBoostedStat(creature, stat); } \ No newline at end of file diff --git a/CInterface/Battling/Creature.cpp b/CInterface/Battling/Creature.cpp index 216d0a3..be8c4ca 100644 --- a/CInterface/Battling/Creature.cpp +++ b/CInterface/Battling/Creature.cpp @@ -85,21 +85,20 @@ export void CreatureLib_Creature_SetDisplaySpecies(Creature* p, const CreatureLi export void CreatureLib_Creature_SetDisplayVariant(Creature* p, const CreatureLib::Library::SpeciesVariant* variant) { return p->SetDisplayVariant(variant); } -export void CreatureLib_Creature_ChangeStatBoost(Creature* p, CreatureLib::Core::Statistic stat, int8_t diffAmount){ +export void CreatureLib_Creature_ChangeStatBoost(Creature* p, CreatureLib::Library::Statistic stat, int8_t diffAmount) { p->ChangeStatBoost(stat, diffAmount); } -export uint32_t CreatureLib_Creature_GetFlatStat(Creature* p, CreatureLib::Core::Statistic stat){ +export uint32_t CreatureLib_Creature_GetFlatStat(Creature* p, CreatureLib::Library::Statistic stat) { return p->GetFlatStat(stat); } -export uint32_t CreatureLib_Creature_GetBoostedStat(Creature* p, CreatureLib::Core::Statistic stat){ +export uint32_t CreatureLib_Creature_GetBoostedStat(Creature* p, CreatureLib::Library::Statistic stat) { return p->GetBoostedStat(stat); } -export uint32_t CreatureLib_Creature_GetBaseStat(Creature* p, CreatureLib::Core::Statistic stat){ +export uint32_t CreatureLib_Creature_GetBaseStat(Creature* p, CreatureLib::Library::Statistic stat) { return p->GetBaseStat(stat); } -export int8_t CreatureLib_Creature_GetStatBoost(Creature* p, CreatureLib::Core::Statistic stat){ +export int8_t CreatureLib_Creature_GetStatBoost(Creature* p, CreatureLib::Library::Statistic stat) { return p->GetStatBoost(stat); } - #undef SIMPLE_GET_FUNC \ No newline at end of file diff --git a/CInterface/Library/SpeciesVariant.cpp b/CInterface/Library/SpeciesVariant.cpp index b78f473..17d4b16 100644 --- a/CInterface/Library/SpeciesVariant.cpp +++ b/CInterface/Library/SpeciesVariant.cpp @@ -21,9 +21,9 @@ export SpeciesVariant* CreatureLib_SpeciesVariant_Construct( return new SpeciesVariant(Arbutils::CaseInsensitiveConstString(name), height, weight, baseExperience, std::vector(types, types + typeLength), - CreatureLib::Core::StatisticSet(baseHealth, baseAttack, baseDefense, - baseMagicalAttack, baseMagicalDefense, - baseSpeed), + CreatureLib::Library::StatisticSet(baseHealth, baseAttack, baseDefense, + baseMagicalAttack, baseMagicalDefense, + baseSpeed), talentsWrapped, secretTalentsWrapped, attacks); } @@ -38,7 +38,7 @@ 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) { +export uint32_t CreatureLib_SpeciesVariant_GetStatistic(SpeciesVariant* p, CreatureLib::Library::Statistic stat) { return p->GetStatistic(stat); } SIMPLE_GET_FUNC(SpeciesVariant, GetTalentCount, size_t); diff --git a/CMakeLists.txt b/CMakeLists.txt index 4122811..72608eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,11 +31,6 @@ if (WINDOWS) ADD_DEFINITIONS(-D WINDOWS=1) endif (WINDOWS) -# Create Core library with files in src/Core -file(GLOB_RECURSE CORE_SRC_FILES "src/Core/*.cpp" "src/Core/*.hpp" "CInterface/Core/*.cpp") -add_library(CreatureLibCore SHARED ${CORE_SRC_FILES}) -set_target_properties(CreatureLibCore PROPERTIES LINKER_LANGUAGE CXX) - # Create main Library library with files in src/Library file(GLOB_RECURSE LIBRARY_SRC_FILES "src/Library/*.cpp" "src/Library/*.hpp" "CInterface/Library/*.cpp") add_library(CreatureLibLibrary SHARED ${LIBRARY_SRC_FILES}) @@ -50,14 +45,9 @@ if (NOT DEFINED CONAN_EXPORTED) add_executable(CreatureLibTests ${TEST_FILES} extern/catch.hpp) endif () -# Link the core library to the individual other libraries -target_link_libraries(CreatureLibLibrary CreatureLibCore) -target_link_libraries(CreatureLibBattling CreatureLibCore) - # Link the library data to the Battling library target_link_libraries(CreatureLibBattling CreatureLibLibrary) -target_link_libraries(CreatureLibCore Arbutils) target_link_libraries(CreatureLibLibrary Arbutils) target_link_libraries(CreatureLibBattling Arbutils) @@ -71,7 +61,6 @@ if (WINDOWS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L ${CMAKE_BINARY_DIR}/bin") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -Wa,-mbig-obj -Wl,-allow-multiple-definition") # Statically link libraries we need in Windows. - target_link_libraries(CreatureLibCore -static-libgcc -static-libstdc++) target_link_libraries(CreatureLibLibrary -static-libgcc -static-libstdc++) target_link_libraries(CreatureLibBattling -static-libgcc -static-libstdc++) if (NOT DEFINED CONAN_EXPORTED) diff --git a/src/Battling/Flow/TurnHandler.cpp b/src/Battling/Flow/TurnHandler.cpp index 3634205..9667656 100644 --- a/src/Battling/Flow/TurnHandler.cpp +++ b/src/Battling/Flow/TurnHandler.cpp @@ -1,5 +1,5 @@ #include "TurnHandler.hpp" -#include "../../Core/Exceptions/NotImplementedException.hpp" +#include "../../Library/Exceptions/NotImplementedException.hpp" #include "../Models/Battle.hpp" #include "../ScriptHandling/ScriptMacros.hpp" diff --git a/src/Battling/Flow/TurnOrdering.cpp b/src/Battling/Flow/TurnOrdering.cpp index cc543f2..a1a582d 100644 --- a/src/Battling/Flow/TurnOrdering.cpp +++ b/src/Battling/Flow/TurnOrdering.cpp @@ -17,8 +17,8 @@ bool ___ChoiceOrderFunc(const BaseTurnChoice* a, const BaseTurnChoice* b, Arbuti if (aPriority != bPriority) return aPriority > bPriority; } - auto aSpeed = a->GetUser()->GetBoostedStat(Core::Statistic::Speed); - auto bSpeed = b->GetUser()->GetBoostedStat(Core::Statistic::Speed); + auto aSpeed = a->GetUser()->GetBoostedStat(Library::Statistic::Speed); + auto bSpeed = b->GetUser()->GetBoostedStat(Library::Statistic::Speed); if (aSpeed != bSpeed) return aSpeed > bSpeed; diff --git a/src/Battling/Library/BattleStatCalculator.cpp b/src/Battling/Library/BattleStatCalculator.cpp index c5c8d42..d9334b3 100644 --- a/src/Battling/Library/BattleStatCalculator.cpp +++ b/src/Battling/Library/BattleStatCalculator.cpp @@ -1,46 +1,48 @@ #include "BattleStatCalculator.hpp" -#include "../../Core/Exceptions/NotImplementedException.hpp" +#include "../../Library/Exceptions/NotImplementedException.hpp" #include "../Models/Creature.hpp" using namespace CreatureLib; -Core::StatisticSet Battling::BattleStatCalculator::CalculateFlatStats(Battling::Creature* creature) const { - return Core::StatisticSet(CalculateFlatStat(creature, Core::Statistic::Health), - CalculateFlatStat(creature, Core::Statistic::PhysicalAttack), - CalculateFlatStat(creature, Core::Statistic::PhysicalDefense), - CalculateFlatStat(creature, Core::Statistic::MagicalAttack), - CalculateFlatStat(creature, Core::Statistic::MagicalDefense), - CalculateFlatStat(creature, Core::Statistic::Speed)); +Library::StatisticSet Battling::BattleStatCalculator::CalculateFlatStats(Battling::Creature* creature) const { + return Library::StatisticSet(CalculateFlatStat(creature, Library::Statistic::Health), + CalculateFlatStat(creature, Library::Statistic::PhysicalAttack), + CalculateFlatStat(creature, Library::Statistic::PhysicalDefense), + CalculateFlatStat(creature, Library::Statistic::MagicalAttack), + CalculateFlatStat(creature, Library::Statistic::MagicalDefense), + CalculateFlatStat(creature, Library::Statistic::Speed)); } -Core::StatisticSet Battling::BattleStatCalculator::CalculateBoostedStats(Battling::Creature* creature) const { - return Core::StatisticSet(CalculateBoostedStat(creature, Core::Statistic::Health), - CalculateBoostedStat(creature, Core::Statistic::PhysicalAttack), - CalculateBoostedStat(creature, Core::Statistic::PhysicalDefense), - CalculateBoostedStat(creature, Core::Statistic::MagicalAttack), - CalculateBoostedStat(creature, Core::Statistic::MagicalDefense), - CalculateBoostedStat(creature, Core::Statistic::Speed)); +Library::StatisticSet +Battling::BattleStatCalculator::CalculateBoostedStats(Battling::Creature* creature) const { + return Library::StatisticSet(CalculateBoostedStat(creature, Library::Statistic::Health), + CalculateBoostedStat(creature, Library::Statistic::PhysicalAttack), + CalculateBoostedStat(creature, Library::Statistic::PhysicalDefense), + CalculateBoostedStat(creature, Library::Statistic::MagicalAttack), + CalculateBoostedStat(creature, Library::Statistic::MagicalDefense), + CalculateBoostedStat(creature, Library::Statistic::Speed)); } uint32_t CalculateHealthStat(Battling::Creature* creature) { auto level = creature->GetLevel(); - auto a = (creature->GetBaseStat(Core::Statistic::Health)) * 2 * level; + auto a = (creature->GetBaseStat(Library::Statistic::Health)) * 2 * level; return floor(a / 100) + level + 10; } -uint32_t CalculateOtherStat(Battling::Creature* creature, Core::Statistic stat) { +uint32_t CalculateOtherStat(Battling::Creature* creature, Library::Statistic stat) { auto level = creature->GetLevel(); auto a = (creature->GetBaseStat(stat)) * 2 * level; return floor(a / 100) + 10; } -uint32_t Battling::BattleStatCalculator::CalculateFlatStat(Battling::Creature* creature, Core::Statistic stat) const { - if (stat == Core::Statistic::Health) +uint32_t Battling::BattleStatCalculator::CalculateFlatStat(Battling::Creature* creature, + Library::Statistic stat) const { + if (stat == Library::Statistic::Health) return CalculateHealthStat(creature); return CalculateOtherStat(creature, stat); } uint32_t Battling::BattleStatCalculator::CalculateBoostedStat(Battling::Creature* creature, - Core::Statistic stat) const { + Library::Statistic stat) const { return creature->GetFlatStat(stat) + (creature->GetBoostedStat(stat)); } diff --git a/src/Battling/Library/BattleStatCalculator.hpp b/src/Battling/Library/BattleStatCalculator.hpp index 01513b0..e736fe6 100644 --- a/src/Battling/Library/BattleStatCalculator.hpp +++ b/src/Battling/Library/BattleStatCalculator.hpp @@ -1,7 +1,7 @@ #ifndef CREATURELIB_BATTLESTATCALCULATOR_HPP #define CREATURELIB_BATTLESTATCALCULATOR_HPP -#include "../../Core/StatisticSet.hpp" +#include "../../Library/StatisticSet.hpp" namespace CreatureLib::Battling { // predeclare BattleCreature class @@ -11,10 +11,10 @@ namespace CreatureLib::Battling { public: virtual ~BattleStatCalculator() = default; - virtual Core::StatisticSet CalculateFlatStats(Creature* creature) const; - virtual Core::StatisticSet CalculateBoostedStats(Creature* creature) const; - virtual uint32_t CalculateFlatStat(Creature* creature, Core::Statistic stat) const; - virtual uint32_t CalculateBoostedStat(Creature* creature, Core::Statistic stat) const; + virtual Library::StatisticSet CalculateFlatStats(Creature* creature) const; + virtual Library::StatisticSet CalculateBoostedStats(Creature* creature) const; + virtual uint32_t CalculateFlatStat(Creature* creature, Library::Statistic stat) const; + virtual uint32_t CalculateBoostedStat(Creature* creature, Library::Statistic stat) const; }; } diff --git a/src/Battling/Library/DamageLibrary.cpp b/src/Battling/Library/DamageLibrary.cpp index 0a448f7..fc5cb4f 100644 --- a/src/Battling/Library/DamageLibrary.cpp +++ b/src/Battling/Library/DamageLibrary.cpp @@ -24,14 +24,14 @@ float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target, auto user = attack->GetUser(); HOOK(ChangeDamageStatsUser, attack, attack, target, hitIndex, &user); auto hit = attack->GetAttackDataForTarget(target)->GetHit(hitIndex); - Core::Statistic offensiveStat; - Core::Statistic defensiveStat; + Library::Statistic offensiveStat; + Library::Statistic defensiveStat; if (attack->GetAttack()->GetAttack()->GetCategory() == Library::AttackCategory::Physical) { - offensiveStat = Core::Statistic::PhysicalAttack; - defensiveStat = Core::Statistic::PhysicalDefense; + offensiveStat = Library::Statistic::PhysicalAttack; + defensiveStat = Library::Statistic::PhysicalDefense; } else { - offensiveStat = Core::Statistic::MagicalAttack; - defensiveStat = Core::Statistic::MagicalDefense; + offensiveStat = Library::Statistic::MagicalAttack; + defensiveStat = Library::Statistic::MagicalDefense; } auto bypassDefensive = hit->IsCritical() && target->GetStatBoost(defensiveStat) > 0; diff --git a/src/Battling/Models/Battle.cpp b/src/Battling/Models/Battle.cpp index d13afe8..df507a9 100644 --- a/src/Battling/Models/Battle.cpp +++ b/src/Battling/Models/Battle.cpp @@ -1,5 +1,5 @@ #include "Battle.hpp" -#include "../../Core/Exceptions/NotImplementedException.hpp" +#include "../../Library/Exceptions/NotImplementedException.hpp" #include "../Flow/TurnHandler.hpp" #include "../Flow/TurnOrdering.hpp" diff --git a/src/Battling/Models/BattleSide.cpp b/src/Battling/Models/BattleSide.cpp index d9a5aea..d686f7d 100644 --- a/src/Battling/Models/BattleSide.cpp +++ b/src/Battling/Models/BattleSide.cpp @@ -1,6 +1,6 @@ #include "BattleSide.hpp" #include -#include "../../Core/Exceptions/CreatureException.hpp" +#include "../../Library/Exceptions/CreatureException.hpp" #include "Battle.hpp" using namespace CreatureLib::Battling; diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index 51bdccd..edd5599 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -42,7 +42,7 @@ void Battling::Creature::SetBattleData(Battling::Battle* battle, Battling::Battl // region Stat APIs -void Battling::Creature::ChangeStatBoost(Core::Statistic stat, int8_t diffAmount) { +void Battling::Creature::ChangeStatBoost(Library::Statistic stat, int8_t diffAmount) { if (diffAmount > 0) this->_statBoost.IncreaseStatBy(stat, diffAmount); else @@ -50,13 +50,13 @@ void Battling::Creature::ChangeStatBoost(Core::Statistic stat, int8_t diffAmount this->RecalculateBoostedStat(stat); } -uint32_t Battling::Creature::GetFlatStat(Core::Statistic stat) const { return _flatStats.GetStat(stat); } +uint32_t Battling::Creature::GetFlatStat(Library::Statistic stat) const { return _flatStats.GetStat(stat); } -uint32_t Battling::Creature::GetBoostedStat(Core::Statistic stat) const { return _boostedStats.GetStat(stat); } +uint32_t Battling::Creature::GetBoostedStat(Library::Statistic stat) const { return _boostedStats.GetStat(stat); } -uint32_t Battling::Creature::GetBaseStat(Core::Statistic stat) const { return _variant->GetStatistic(stat); } +uint32_t Battling::Creature::GetBaseStat(Library::Statistic stat) const { return _variant->GetStatistic(stat); } -int8_t Battling::Creature::GetStatBoost(Core::Statistic stat) const { return _statBoost.GetStat(stat); } +int8_t Battling::Creature::GetStatBoost(Library::Statistic stat) const { return _statBoost.GetStat(stat); } void Battling::Creature::RecalculateFlatStats() { auto statCalc = this->_library->GetStatCalculator(); @@ -67,13 +67,13 @@ void Battling::Creature::RecalculateBoostedStats() { this->_boostedStats = this->_library->GetStatCalculator()->CalculateFlatStats(this); } -void Battling::Creature::RecalculateFlatStat(Core::Statistic stat) { +void Battling::Creature::RecalculateFlatStat(Library::Statistic stat) { auto s = this->_library->GetStatCalculator()->CalculateFlatStat(this, stat); this->_flatStats.SetStat(stat, s); RecalculateBoostedStat(stat); } -void Battling::Creature::RecalculateBoostedStat(Core::Statistic stat) { +void Battling::Creature::RecalculateBoostedStat(Library::Statistic stat) { auto s = this->_library->GetStatCalculator()->CalculateBoostedStat(this, stat); this->_boostedStats.SetStat(stat, s); } diff --git a/src/Battling/Models/Creature.hpp b/src/Battling/Models/Creature.hpp index 71e35a1..beaf3c8 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -33,9 +33,9 @@ namespace CreatureLib::Battling { const Library::Item* _heldItem; uint32_t _currentHealth; - Core::StatisticSet _statBoost; - Core::StatisticSet _flatStats; - Core::StatisticSet _boostedStats; + Library::StatisticSet _statBoost; + Library::StatisticSet _flatStats; + Library::StatisticSet _boostedStats; Battle* _battle = nullptr; BattleSide* _side = nullptr; @@ -73,7 +73,7 @@ namespace CreatureLib::Battling { virtual void Initialize() { RecalculateFlatStats(); - _currentHealth = GetBoostedStat(Core::Statistic::Health); + _currentHealth = GetBoostedStat(Library::Statistic::Health); } inline const Library::CreatureSpecies* GetSpecies() const { return _species; } @@ -136,15 +136,15 @@ namespace CreatureLib::Battling { // region Stat APIs - void ChangeStatBoost(Core::Statistic stat, int8_t diffAmount); - [[nodiscard]] uint32_t GetFlatStat(Core::Statistic stat) const; - [[nodiscard]] uint32_t GetBoostedStat(Core::Statistic stat) const; - [[nodiscard]] uint32_t GetBaseStat(Core::Statistic stat) const; - [[nodiscard]] int8_t GetStatBoost(Core::Statistic stat) const; + void ChangeStatBoost(Library::Statistic stat, int8_t diffAmount); + [[nodiscard]] uint32_t GetFlatStat(Library::Statistic stat) const; + [[nodiscard]] uint32_t GetBoostedStat(Library::Statistic stat) const; + [[nodiscard]] uint32_t GetBaseStat(Library::Statistic stat) const; + [[nodiscard]] int8_t GetStatBoost(Library::Statistic stat) const; void RecalculateFlatStats(); void RecalculateBoostedStats(); - void RecalculateFlatStat(Core::Statistic); - void RecalculateBoostedStat(Core::Statistic); + void RecalculateFlatStat(Library::Statistic); + void RecalculateBoostedStat(Library::Statistic); // endregion }; diff --git a/src/Battling/ScriptHandling/ScriptAggregator.hpp b/src/Battling/ScriptHandling/ScriptAggregator.hpp index 20f06d8..ee0a8be 100644 --- a/src/Battling/ScriptHandling/ScriptAggregator.hpp +++ b/src/Battling/ScriptHandling/ScriptAggregator.hpp @@ -3,7 +3,7 @@ #include #include -#include "../../Core/Exceptions/NotReachableException.hpp" +#include "../../Library/Exceptions/NotReachableException.hpp" #include "Script.hpp" #include "ScriptSet.hpp" #include "ScriptWrapper.hpp" diff --git a/src/Core/StatisticSet.hpp b/src/Core/StatisticSet.hpp deleted file mode 100644 index 39e9747..0000000 --- a/src/Core/StatisticSet.hpp +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef CREATURELIB_STATISTICSET_HPP -#define CREATURELIB_STATISTICSET_HPP -#include -#include -#include "Exceptions/NotReachableException.hpp" -#include "Statistic.hpp" - -namespace CreatureLib::Core { - template class StatisticSet { - protected: - T _health; - T _physicalAttack; - T _physicalDefense; - T _magicalAttack; - T _magicalDefense; - T _speed; - - public: - StatisticSet(T health, T physicalAttack, T physicalDefense, T magicalAttack, T magicalDefense, T speed) - : _health(health), _physicalAttack(physicalAttack), _physicalDefense(physicalDefense), - _magicalAttack(magicalAttack), _magicalDefense(magicalDefense), _speed(speed) {} - StatisticSet() - : _health(0), _physicalAttack(0), _physicalDefense(0), _magicalAttack(0), _magicalDefense(0), _speed(0) {} - - inline T GetHealth() const { return _health; } - inline T GetPhysicalAttack() const { return _physicalAttack; } - inline T GetPhysicalDefense() const { return _physicalDefense; } - inline T GetMagicalAttack() const { return _magicalAttack; } - inline T GetMagicalDefense() const { return _magicalDefense; } - inline T GetSpeed() const { return _speed; } - - [[nodiscard]] inline T GetStat(Statistic stat) const { - switch (stat) { - case CreatureLib::Core::Statistic::Health: return _health; - case CreatureLib::Core::Statistic::PhysicalAttack: return _physicalAttack; - case CreatureLib::Core::Statistic::PhysicalDefense: return _physicalDefense; - case CreatureLib::Core::Statistic::MagicalAttack: return _magicalAttack; - case CreatureLib::Core::Statistic::MagicalDefense: return _magicalDefense; - case CreatureLib::Core::Statistic::Speed: return _speed; - default: throw NotReachableException(); - } - } - - inline void SetStat(Statistic stat, T value) { - switch (stat) { - case CreatureLib::Core::Statistic::Health: _health = value; break; - case CreatureLib::Core::Statistic::PhysicalAttack: _physicalAttack = value; break; - case CreatureLib::Core::Statistic::PhysicalDefense: _physicalDefense = value; break; - case CreatureLib::Core::Statistic::MagicalAttack: _magicalAttack = value; break; - case CreatureLib::Core::Statistic::MagicalDefense: _magicalDefense = value; break; - case CreatureLib::Core::Statistic::Speed: _speed = value; break; - default: throw NotReachableException(); - } - } - - inline void IncreaseStatBy(Statistic stat, T amount) { - switch (stat) { - case CreatureLib::Core::Statistic::Health: _health += amount; break; - case CreatureLib::Core::Statistic::PhysicalAttack: _physicalAttack += amount; break; - case CreatureLib::Core::Statistic::PhysicalDefense: _physicalDefense += amount; break; - case CreatureLib::Core::Statistic::MagicalAttack: _magicalAttack += amount; break; - case CreatureLib::Core::Statistic::MagicalDefense: _magicalDefense += amount; break; - case CreatureLib::Core::Statistic::Speed: _speed += amount; break; - default: throw NotReachableException(); - } - } - inline void DecreaseStatBy(Statistic stat, T amount) { - switch (stat) { - case CreatureLib::Core::Statistic::Health: _health -= amount; break; - case CreatureLib::Core::Statistic::PhysicalAttack: _physicalAttack -= amount; break; - case CreatureLib::Core::Statistic::PhysicalDefense: _physicalDefense -= amount; break; - case CreatureLib::Core::Statistic::MagicalAttack: _magicalAttack -= amount; break; - case CreatureLib::Core::Statistic::MagicalDefense: _magicalDefense -= amount; break; - case CreatureLib::Core::Statistic::Speed: _speed -= amount; break; - default: throw NotReachableException(); - } - } - }; -} - -#endif // CREATURELIB_STATISTICSET_HPP diff --git a/src/Library/CreatureData/SpeciesVariant.cpp b/src/Library/CreatureData/SpeciesVariant.cpp index 7174572..9abe62a 100644 --- a/src/Library/CreatureData/SpeciesVariant.cpp +++ b/src/Library/CreatureData/SpeciesVariant.cpp @@ -8,7 +8,7 @@ size_t CreatureLib::Library::SpeciesVariant::GetTypeCount() const { return _type uint8_t CreatureLib::Library::SpeciesVariant::GetType(size_t index) const { return _types[index]; } -uint32_t CreatureLib::Library::SpeciesVariant::GetStatistic(CreatureLib::Core::Statistic stat) const { +uint32_t CreatureLib::Library::SpeciesVariant::GetStatistic(CreatureLib::Library::Statistic stat) const { return _baseStatistics.GetStat(stat); } @@ -37,7 +37,7 @@ const CreatureLib::Library::LearnableAttacks* CreatureLib::Library::SpeciesVaria CreatureLib::Library::SpeciesVariant::SpeciesVariant(ConstString name, float height, float weight, uint32_t baseExperience, std::vector types, - CreatureLib::Core::StatisticSet baseStats, + CreatureLib::Library::StatisticSet baseStats, std::vector talents, std::vector secretTalents, const LearnableAttacks* attacks) diff --git a/src/Library/CreatureData/SpeciesVariant.hpp b/src/Library/CreatureData/SpeciesVariant.hpp index 8edadf5..0e99672 100644 --- a/src/Library/CreatureData/SpeciesVariant.hpp +++ b/src/Library/CreatureData/SpeciesVariant.hpp @@ -4,7 +4,7 @@ #include #include #include -#include "../../Core/StatisticSet.hpp" +#include "../StatisticSet.hpp" #include "CreatureMoves.hpp" #include "LearnableAttacks.hpp" #include "TalentIndex.hpp" @@ -23,14 +23,14 @@ namespace CreatureLib::Library { private: std::vector _types; - const Core::StatisticSet _baseStatistics; + const Library::StatisticSet _baseStatistics; std::vector _talents; std::vector _secretTalents; const LearnableAttacks* _attacks; public: SpeciesVariant(ConstString name, float height, float weight, uint32_t baseExperience, - std::vector types, Core::StatisticSet baseStats, + std::vector types, Library::StatisticSet baseStats, std::vector talents, std::vector secretTalents, const LearnableAttacks* attacks); @@ -44,7 +44,7 @@ namespace CreatureLib::Library { [[nodiscard]] size_t GetTypeCount() const; [[nodiscard]] uint8_t GetType(size_t index) const; [[nodiscard]] const std::vector& GetTypes() const; - [[nodiscard]] uint32_t GetStatistic(Core::Statistic stat) const; + [[nodiscard]] uint32_t GetStatistic(Library::Statistic stat) 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 { diff --git a/src/Core/Exceptions/CreatureException.hpp b/src/Library/Exceptions/CreatureException.hpp similarity index 100% rename from src/Core/Exceptions/CreatureException.hpp rename to src/Library/Exceptions/CreatureException.hpp diff --git a/src/Core/Exceptions/NotImplementedException.hpp b/src/Library/Exceptions/NotImplementedException.hpp similarity index 100% rename from src/Core/Exceptions/NotImplementedException.hpp rename to src/Library/Exceptions/NotImplementedException.hpp diff --git a/src/Core/Exceptions/NotReachableException.hpp b/src/Library/Exceptions/NotReachableException.hpp similarity index 100% rename from src/Core/Exceptions/NotReachableException.hpp rename to src/Library/Exceptions/NotReachableException.hpp diff --git a/src/Library/GrowthRates/GrowthRateLibrary.cpp b/src/Library/GrowthRates/GrowthRateLibrary.cpp index 6c1f36d..0d582ea 100644 --- a/src/Library/GrowthRates/GrowthRateLibrary.cpp +++ b/src/Library/GrowthRates/GrowthRateLibrary.cpp @@ -1,5 +1,5 @@ #include "GrowthRateLibrary.hpp" -#include "../../Core/Exceptions/CreatureException.hpp" +#include "../Exceptions/CreatureException.hpp" uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const ConstString& growthRate, uint32_t experience) const { diff --git a/src/Core/Statistic.hpp b/src/Library/Statistic.hpp similarity index 88% rename from src/Core/Statistic.hpp rename to src/Library/Statistic.hpp index 8d42b82..ad438f1 100644 --- a/src/Core/Statistic.hpp +++ b/src/Library/Statistic.hpp @@ -4,7 +4,7 @@ #include #include -namespace CreatureLib::Core { +namespace CreatureLib::Library { ENUM(Statistic, uint8_t, Health, PhysicalAttack, PhysicalDefense, MagicalAttack, MagicalDefense, Speed) } diff --git a/src/Library/StatisticSet.hpp b/src/Library/StatisticSet.hpp new file mode 100644 index 0000000..74e048f --- /dev/null +++ b/src/Library/StatisticSet.hpp @@ -0,0 +1,81 @@ +#ifndef CREATURELIB_STATISTICSET_HPP +#define CREATURELIB_STATISTICSET_HPP +#include +#include +#include "Exceptions/NotReachableException.hpp" +#include "Statistic.hpp" + +namespace CreatureLib::Library { + template class StatisticSet { + protected: + T _health; + T _physicalAttack; + T _physicalDefense; + T _magicalAttack; + T _magicalDefense; + T _speed; + + public: + StatisticSet(T health, T physicalAttack, T physicalDefense, T magicalAttack, T magicalDefense, T speed) + : _health(health), _physicalAttack(physicalAttack), _physicalDefense(physicalDefense), + _magicalAttack(magicalAttack), _magicalDefense(magicalDefense), _speed(speed) {} + StatisticSet() + : _health(0), _physicalAttack(0), _physicalDefense(0), _magicalAttack(0), _magicalDefense(0), _speed(0) {} + + inline T GetHealth() const { return _health; } + inline T GetPhysicalAttack() const { return _physicalAttack; } + inline T GetPhysicalDefense() const { return _physicalDefense; } + inline T GetMagicalAttack() const { return _magicalAttack; } + inline T GetMagicalDefense() const { return _magicalDefense; } + inline T GetSpeed() const { return _speed; } + + [[nodiscard]] inline T GetStat(Statistic stat) const { + switch (stat) { + case CreatureLib::Library::Statistic::Health: return _health; + case CreatureLib::Library::Statistic::PhysicalAttack: return _physicalAttack; + case CreatureLib::Library::Statistic::PhysicalDefense: return _physicalDefense; + case CreatureLib::Library::Statistic::MagicalAttack: return _magicalAttack; + case CreatureLib::Library::Statistic::MagicalDefense: return _magicalDefense; + case CreatureLib::Library::Statistic::Speed: return _speed; + default: throw NotReachableException(); + } + } + + inline void SetStat(Statistic stat, T value) { + switch (stat) { + case CreatureLib::Library::Statistic::Health: _health = value; break; + case CreatureLib::Library::Statistic::PhysicalAttack: _physicalAttack = value; break; + case CreatureLib::Library::Statistic::PhysicalDefense: _physicalDefense = value; break; + case CreatureLib::Library::Statistic::MagicalAttack: _magicalAttack = value; break; + case CreatureLib::Library::Statistic::MagicalDefense: _magicalDefense = value; break; + case CreatureLib::Library::Statistic::Speed: _speed = value; break; + default: throw NotReachableException(); + } + } + + inline void IncreaseStatBy(Statistic stat, T amount) { + switch (stat) { + case CreatureLib::Library::Statistic::Health: _health += amount; break; + case CreatureLib::Library::Statistic::PhysicalAttack: _physicalAttack += amount; break; + case CreatureLib::Library::Statistic::PhysicalDefense: _physicalDefense += amount; break; + case CreatureLib::Library::Statistic::MagicalAttack: _magicalAttack += amount; break; + case CreatureLib::Library::Statistic::MagicalDefense: _magicalDefense += amount; break; + case CreatureLib::Library::Statistic::Speed: _speed += amount; break; + default: throw NotReachableException(); + } + } + inline void DecreaseStatBy(Statistic stat, T amount) { + switch (stat) { + case CreatureLib::Library::Statistic::Health: _health -= amount; break; + case CreatureLib::Library::Statistic::PhysicalAttack: _physicalAttack -= amount; break; + case CreatureLib::Library::Statistic::PhysicalDefense: _physicalDefense -= amount; break; + case CreatureLib::Library::Statistic::MagicalAttack: _magicalAttack -= amount; break; + case CreatureLib::Library::Statistic::MagicalDefense: _magicalDefense -= amount; break; + case CreatureLib::Library::Statistic::Speed: _speed -= amount; break; + default: throw NotReachableException(); + } + } + }; +} + +#endif // CREATURELIB_STATISTICSET_HPP diff --git a/tests/ExceptionTests.cpp b/tests/ExceptionTests.cpp index c4f6612..f48fe7c 100644 --- a/tests/ExceptionTests.cpp +++ b/tests/ExceptionTests.cpp @@ -1,7 +1,7 @@ #ifdef TESTS_BUILD #include #include "../extern/catch.hpp" -#include "../src/Core/Exceptions/CreatureException.hpp" +#include "../src/Library/Exceptions/CreatureException.hpp" TEST_CASE("When throwing exception, what() is readable", "[Utilities]") { bool hasCaught = false; diff --git a/tests/Integration/BattleIntegrations.cpp b/tests/Integration/BattleIntegrations.cpp index 2feadf3..79d49c2 100644 --- a/tests/Integration/BattleIntegrations.cpp +++ b/tests/Integration/BattleIntegrations.cpp @@ -205,8 +205,8 @@ TEST_CASE("Switch Creature in, but have attack aimed at it. Attack should hit ne battle.TrySetChoice(new SwitchTurnChoice(c1, c2)); battle.TrySetChoice(new AttackTurnChoice(c3, c3->GetAttacks()[0], CreatureIndex(0, 0))); - REQUIRE(c2->GetCurrentHealth() < c2->GetBoostedStat(Core::Statistic::Health)); - REQUIRE(c1->GetCurrentHealth() == c1->GetBoostedStat(Core::Statistic::Health)); + REQUIRE(c2->GetCurrentHealth() < c2->GetBoostedStat(Library::Statistic::Health)); + REQUIRE(c1->GetCurrentHealth() == c1->GetBoostedStat(Library::Statistic::Health)); } TEST_CASE("Switch Creature in, mark as seen opponent for opponent", "[Integrations]") { diff --git a/tests/LibraryTests/CreatureTests.cpp b/tests/LibraryTests/CreatureTests.cpp index dc4cf18..5b9d50b 100644 --- a/tests/LibraryTests/CreatureTests.cpp +++ b/tests/LibraryTests/CreatureTests.cpp @@ -41,8 +41,8 @@ TEST_CASE("Get creature nickname when unset", "[Library]") { TEST_CASE("Increase creature stat boost", "[Library]") { auto library = TestLibrary::Get(); auto creature = CreateCreature(library, "testSpecies1", 1).Create(); - creature->ChangeStatBoost(CreatureLib::Core::Statistic::PhysicalAttack, 6); - REQUIRE(creature->GetStatBoost(CreatureLib::Core::Statistic::PhysicalAttack) == 6); + creature->ChangeStatBoost(CreatureLib::Library::Statistic::PhysicalAttack, 6); + REQUIRE(creature->GetStatBoost(CreatureLib::Library::Statistic::PhysicalAttack) == 6); delete creature; } diff --git a/tests/TestLibrary/TestLibrary.cpp b/tests/TestLibrary/TestLibrary.cpp index afa3361..cde89a4 100644 --- a/tests/TestLibrary/TestLibrary.cpp +++ b/tests/TestLibrary/TestLibrary.cpp @@ -3,7 +3,6 @@ #include "TestLibrary.hpp" #include "../../src/Library/GrowthRates/LookupGrowthRate.hpp" -using namespace CreatureLib::Core; using namespace CreatureLib::Library; using namespace CreatureLib::Battling; BattleLibrary* TestLibrary::_library = nullptr; diff --git a/tests/TestLibrary/TestLibrary.hpp b/tests/TestLibrary/TestLibrary.hpp index 9adb7a5..3df5240 100644 --- a/tests/TestLibrary/TestLibrary.hpp +++ b/tests/TestLibrary/TestLibrary.hpp @@ -5,7 +5,6 @@ #include "../../src/Battling/Library/BattleLibrary.hpp" -using namespace CreatureLib::Core; using namespace CreatureLib::Library; using namespace CreatureLib::Battling;