diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f15e28..0043d94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,12 +8,24 @@ project(CreatureLib) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -if (EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) - include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) - conan_basic_setup() -else () - message(WARNING "The file conanbuildinfo.cmake doesn't exist, you have to run conan install first") +if (NOT EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) + message(WARNING "The file conanbuildinfo.cmake doesn't exist, running conan install.") + string(REPLACE "." ";" VERSION_LIST "${CMAKE_C_COMPILER_VERSION}") + list(GET VERSION_LIST 0 VERSION) + list(GET VERSION_LIST 1 MINOR) + if (NOT MINOR MATCHES 0) + SET(VERSION ${VERSION}.${MINOR}) + endif () + if (NOT WINDOWS) + execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build missing + -s compiler=clang -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION}) + else () + execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build missing + -s compiler=gcc -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION} -s os=Windows) + endif () endif () +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() if (WINDOWS) ADD_DEFINITIONS(-D WINDOWS=1) @@ -22,6 +34,7 @@ endif (WINDOWS) # Create Core library with files in src/Core file(GLOB_RECURSE CORE_SRC_FILES "src/Core/*.cpp" "src/Core/*.hpp") 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") @@ -44,6 +57,11 @@ 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) + + if (NOT DEFINED CONAN_EXPORTED) target_link_libraries(CreatureLibTests CreatureLibLibrary) target_link_libraries(CreatureLibTests CreatureLibBattling) diff --git a/conanfile.py b/conanfile.py index 5be04af..9de7cec 100644 --- a/conanfile.py +++ b/conanfile.py @@ -33,3 +33,6 @@ class CreatureLibConan(ConanFile): def package_info(self): self.cpp_info.libs = ["CreatureLibCore", "CreatureLibLibrary", "CreatureLibBattling"] + + def requirements(self): + self.requires("Arbutils/latest@epsilon/master") diff --git a/src/Battling/Flow/TurnOrdering.cpp b/src/Battling/Flow/TurnOrdering.cpp index 5f2c296..cc543f2 100644 --- a/src/Battling/Flow/TurnOrdering.cpp +++ b/src/Battling/Flow/TurnOrdering.cpp @@ -6,7 +6,7 @@ using namespace CreatureLib; using namespace Battling; -bool ___ChoiceOrderFunc(const BaseTurnChoice* a, const BaseTurnChoice* b, Core::Random& rand) { +bool ___ChoiceOrderFunc(const BaseTurnChoice* a, const BaseTurnChoice* b, Arbutils::Random& rand) { auto aKind = a->GetKind(); auto bKind = b->GetKind(); if (aKind != bKind) @@ -26,7 +26,7 @@ bool ___ChoiceOrderFunc(const BaseTurnChoice* a, const BaseTurnChoice* b, Core:: return randomValue == 0; } -void TurnOrdering::OrderChoices(std::vector& vec, Core::Random& rand) { +void TurnOrdering::OrderChoices(std::vector& vec, Arbutils::Random& rand) { auto comp = [&](const BaseTurnChoice* a, const BaseTurnChoice* b) -> bool { return ___ChoiceOrderFunc(a, b, rand); }; diff --git a/src/Battling/Flow/TurnOrdering.hpp b/src/Battling/Flow/TurnOrdering.hpp index 45c221a..112682f 100644 --- a/src/Battling/Flow/TurnOrdering.hpp +++ b/src/Battling/Flow/TurnOrdering.hpp @@ -1,14 +1,14 @@ #ifndef CREATURELIB_TURNORDERING_HPP #define CREATURELIB_TURNORDERING_HPP +#include #include -#include "../../Core/Random.hpp" #include "../TurnChoices/BaseTurnChoice.hpp" namespace CreatureLib::Battling { class TurnOrdering { public: - static void OrderChoices(std::vector& vec, CreatureLib::Core::Random& rand); + static void OrderChoices(std::vector& vec, Arbutils::Random& rand); }; } diff --git a/src/Battling/Models/BattleRandom.hpp b/src/Battling/Models/BattleRandom.hpp index 25671a0..56275c0 100644 --- a/src/Battling/Models/BattleRandom.hpp +++ b/src/Battling/Models/BattleRandom.hpp @@ -1,7 +1,7 @@ #ifndef CREATURELIB_BATTLERANDOM_HPP #define CREATURELIB_BATTLERANDOM_HPP -#include "../../Core/Random.hpp" +#include namespace CreatureLib::Battling { class ExecutingAttack; @@ -9,7 +9,7 @@ namespace CreatureLib::Battling { class BattleRandom { private: - Core::Random _random; + Arbutils::Random _random; public: BattleRandom() : _random() {} @@ -19,7 +19,7 @@ namespace CreatureLib::Battling { int32_t Get() { return _random.Get(); } int32_t Get(int32_t max) { return _random.Get(max); } int32_t Get(int32_t min, int32_t max) { return _random.Get(min, max); } - Core::Random& GetRNG() { return _random; } + Arbutils::Random& GetRNG() { return _random; } }; } diff --git a/src/Battling/Models/CreateCreature.cpp b/src/Battling/Models/CreateCreature.cpp index 25fb11e..1e58650 100644 --- a/src/Battling/Models/CreateCreature.cpp +++ b/src/Battling/Models/CreateCreature.cpp @@ -30,7 +30,7 @@ CreateCreature* CreateCreature::WithAttack(const std::string& attackName, Attack } Creature* CreateCreature::Create() { - auto rand = Core::Random(); + auto rand = Arbutils::Random(); auto species = this->_library->GetSpeciesLibrary()->Get(this->_species.c_str()); auto variant = species->GetVariant(this->_variant); int8_t talent; diff --git a/src/Battling/ScriptHandling/ScriptResolver.hpp b/src/Battling/ScriptHandling/ScriptResolver.hpp index 7827857..374b77a 100644 --- a/src/Battling/ScriptHandling/ScriptResolver.hpp +++ b/src/Battling/ScriptHandling/ScriptResolver.hpp @@ -1,8 +1,8 @@ #ifndef CREATURELIB_SCRIPTRESOLVER_HPP #define CREATURELIB_SCRIPTRESOLVER_HPP +#include #include -#include "../../Core/Enum.hpp" #include "Script.hpp" #include "ScriptCategory.hpp" diff --git a/src/Core/Enum.hpp b/src/Core/Enum.hpp deleted file mode 100644 index f8f2dc2..0000000 --- a/src/Core/Enum.hpp +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include -#include -#include "Exceptions/NotReachableException.hpp" -#include "MacroUtils.hpp" - -#define ENUM_CASE(x, name) \ - case name::x: \ - return #x; -# -#define ENUM_PARSE_CASE(x, name) \ - case ConstHash(#x): \ - return name::x; -# -#define ENUM_TRY_PARSE_CASE(x, name) \ - case ConstHash(#x): \ - out = name::x; \ - return true; -# -#define ENUM_PARSE_CASE_INSENSITIVE(x, name) \ - case ConstHashCI(#x): \ - return name::x; -# -#define ENUM_TRY_PARSE_CASE_INSENSITIVE(x, name) \ - case ConstHashCI(#x): \ - out = name::x; \ - return true; -# -#define ARRAY_NAME(x, name) name::x, - -#define ENUM(name, type, values...) \ - enum class name : type { values }; \ - class name##Helper { \ - inline static uint32_t constexpr ConstHash(char const* input) { \ - return *input ? static_cast(*input) + 33 * ConstHash(input + 1) : 5381; \ - } \ - inline static constexpr char charToLower(const char c) { \ - return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c; \ - } \ - inline static uint32_t constexpr ConstHashCI(char const* input) { \ - return charToLower(*input) ? static_cast(charToLower(*input)) + 33 * ConstHashCI(input + 1) \ - : 5381; \ - } \ - \ - public: \ - constexpr static const char* ToString(name value) { \ - switch (value) { FOR_EACH(ENUM_CASE, name, values) } \ - throw NotReachableException(); \ - } \ - constexpr static name Parse(const char* input, bool caseInsensitive = false) { \ - if (caseInsensitive) \ - return ParseCaseInsensitive(input); \ - switch (ConstHash(input)) { FOR_EACH(ENUM_PARSE_CASE, name, values) } \ - throw CreatureException("Invalid AttackCategory string."); \ - } \ - constexpr static bool TryParse(const char* input, name& out, bool caseInsensitive = false) { \ - if (caseInsensitive) \ - return TryParseCaseInsensitive(input, out); \ - switch (ConstHash(input)) { FOR_EACH(ENUM_TRY_PARSE_CASE, name, values) } \ - return false; \ - } \ - static std::vector GetValues() { return {FOR_EACH(ARRAY_NAME, name, values)}; } \ - \ - private: \ - static name ParseCaseInsensitive(const char* input) { \ - switch (ConstHashCI(input)) { FOR_EACH(ENUM_PARSE_CASE_INSENSITIVE, name, values) } \ - throw CreatureException("Invalid AttackCategory string."); \ - } \ - static bool TryParseCaseInsensitive(const char* input, name& out) { \ - switch (ConstHashCI(input)) { FOR_EACH(ENUM_TRY_PARSE_CASE_INSENSITIVE, name, values) } \ - return false; \ - } \ - }; diff --git a/src/Core/MacroUtils.hpp b/src/Core/MacroUtils.hpp deleted file mode 100644 index d17d365..0000000 --- a/src/Core/MacroUtils.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#define FE_0(FUNC, arg) -#define FE_1(FUNC, arg, X) FUNC(X, arg) -#define FE_2(FUNC, arg, X, ...) FUNC(X, arg) FE_1(FUNC, arg, __VA_ARGS__) -#define FE_3(FUNC, arg, X, ...) FUNC(X, arg) FE_2(FUNC, arg, __VA_ARGS__) -#define FE_4(FUNC, arg, X, ...) FUNC(X, arg) FE_3(FUNC, arg, __VA_ARGS__) -#define FE_5(FUNC, arg, X, ...) FUNC(X, arg) FE_4(FUNC, arg, __VA_ARGS__) -#define FE_6(FUNC, arg, X, ...) FUNC(X, arg) FE_5(FUNC, arg, __VA_ARGS__) -#define FE_7(FUNC, arg, X, ...) FUNC(X, arg) FE_6(FUNC, arg, __VA_ARGS__) -#define FE_8(FUNC, arg, X, ...) FUNC(X, arg) FE_7(FUNC, arg, __VA_ARGS__) -#define FE_9(FUNC, arg, X, ...) FUNC(X, arg) FE_8(FUNC, arg, __VA_ARGS__) -#define FE_10(FUNC, arg, X, ...) FUNC(X, arg) FE_9(FUNC, arg, __VA_ARGS__) -#define FE_11(FUNC, arg, X, ...) FUNC(X, arg) FE_10(FUNC, arg, __VA_ARGS__) -#define FE_12(FUNC, arg, X, ...) FUNC(X, arg) FE_11(FUNC, arg, __VA_ARGS__) -#define FE_13(FUNC, arg, X, ...) FUNC(X, arg) FE_12(FUNC, arg, __VA_ARGS__) -#define FE_14(FUNC, arg, X, ...) FUNC(X, arg) FE_13(FUNC, arg, __VA_ARGS__) -#define FE_15(FUNC, arg, X, ...) FUNC(X, arg) FE_14(FUNC, arg, __VA_ARGS__) -#define FE_16(FUNC, arg, X, ...) FUNC(X, arg) FE_15(FUNC, arg, __VA_ARGS__) -#define FE_17(FUNC, arg, X, ...) FUNC(X, arg) FE_16(FUNC, arg, __VA_ARGS__) -#define FE_18(FUNC, arg, X, ...) FUNC(X, arg) FE_17(FUNC, arg, __VA_ARGS__) -#define FE_19(FUNC, arg, X, ...) FUNC(X, arg) FE_18(FUNC, arg, __VA_ARGS__) -#define FE_20(FUNC, arg, X, ...) FUNC(X, arg) FE_19(FUNC, arg, __VA_ARGS__) -#define FE_21(FUNC, arg, X, ...) FUNC(X, arg) FE_20(FUNC, arg, __VA_ARGS__) -#define FE_22(FUNC, arg, X, ...) FUNC(X, arg) FE_21(FUNC, arg, __VA_ARGS__) -#define FE_23(FUNC, arg, X, ...) FUNC(X, arg) FE_22(FUNC, arg, __VA_ARGS__) -#define FE_24(FUNC, arg, X, ...) FUNC(X, arg) FE_23(FUNC, arg, __VA_ARGS__) -#define FE_25(FUNC, arg, X, ...) FUNC(X, arg) FE_24(FUNC, arg, __VA_ARGS__) -#define FE_26(FUNC, arg, X, ...) FUNC(X, arg) FE_25(FUNC, arg, __VA_ARGS__) -#define FE_27(FUNC, arg, X, ...) FUNC(X, arg) FE_26(FUNC, arg, __VA_ARGS__) -#define FE_28(FUNC, arg, X, ...) FUNC(X, arg) FE_27(FUNC, arg, __VA_ARGS__) -#define FE_29(FUNC, arg, X, ...) FUNC(X, arg) FE_28(FUNC, arg, __VA_ARGS__) -#define FE_30(FUNC, arg, X, ...) FUNC(X, arg) FE_29(FUNC, arg, __VA_ARGS__) -#define FE_31(FUNC, arg, X, ...) FUNC(X, arg) FE_30(FUNC, arg, __VA_ARGS__) -#define FE_32(FUNC, arg, X, ...) FUNC(X, arg) FE_31(FUNC, arg, __VA_ARGS__) -#define FE_33(FUNC, arg, X, ...) THE_FOREACH_MACRO_CURRENTLY_ONLY_SUPPORTS_UP_TO_32_VALUES FE_32(FUNC, arg, __VA_ARGS__) - -#define GET_MACRO(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, \ - _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, NAME, ...) \ - NAME -#define FOR_EACH(action, arg, ...) \ - GET_MACRO(_0, __VA_ARGS__, FE_33, FE_32, FE_31, FE_30, FE_29, FE_28, FE_27, FE_26, FE_25, FE_24, FE_23, FE_22, \ - FE_21, FE_20, FE_19, FE_18, FE_17, FE_16, FE_15, FE_14, FE_13, FE_12, FE_11, FE_10, FE_9, FE_8, FE_7, \ - FE_6, FE_5, FE_4, FE_3, FE_2, FE_1, FE_0) \ - (action, arg, __VA_ARGS__) diff --git a/src/Core/Random.cpp b/src/Core/Random.cpp deleted file mode 100644 index d9f736f..0000000 --- a/src/Core/Random.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "Random.hpp" -#include - -// Seed parameterless constructor with current milliseconds since epoch. -CreatureLib::Core::Random::Random() - : _rng(std::mt19937(duration_cast(system_clock::now().time_since_epoch()).count())) {} - -float CreatureLib::Core::Random::GetFloat() { - return static_cast(_rng()) / (static_cast(std::mt19937::max() - std::mt19937::min()) - 0.5f); -} - -double CreatureLib::Core::Random::GetDouble() { - return static_cast(_rng()) / ((static_cast(std::mt19937::max()) - std::mt19937::min()) - 0.5); -} - -int32_t CreatureLib::Core::Random::Get() { - return static_cast(GetDouble() * static_cast(std::numeric_limits::max())); -} - -int32_t CreatureLib::Core::Random::Get(int32_t max) { - return static_cast(GetDouble() * static_cast(max)); -} - -int32_t CreatureLib::Core::Random::Get(int32_t min, int32_t max) { - return static_cast(GetDouble() * static_cast(max - min) + min); -} diff --git a/src/Core/Random.hpp b/src/Core/Random.hpp deleted file mode 100644 index e9fa45e..0000000 --- a/src/Core/Random.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef CREATURELIB_RANDOM_HPP -#define CREATURELIB_RANDOM_HPP -#include -#include -#include -using namespace std::chrono; -namespace CreatureLib::Core { - class Random { - private: - std::mt19937 _rng; - - public: - Random(); - explicit Random(int32_t seed) : _rng(seed){}; - - [[nodiscard]] float GetFloat(); - [[nodiscard]] double GetDouble(); - [[nodiscard]] int32_t Get(); - [[nodiscard]] int32_t Get(int32_t max); - [[nodiscard]] int32_t Get(int32_t min, int32_t max); - }; -} - -#endif // CREATURELIB_RANDOM_HPP diff --git a/src/Core/Statistic.hpp b/src/Core/Statistic.hpp index 0f56733..8d42b82 100644 --- a/src/Core/Statistic.hpp +++ b/src/Core/Statistic.hpp @@ -1,8 +1,8 @@ #ifndef CREATURELIB_STATISTIC_HPP #define CREATURELIB_STATISTIC_HPP +#include #include -#include "Enum.hpp" namespace CreatureLib::Core { ENUM(Statistic, uint8_t, Health, PhysicalAttack, PhysicalDefense, MagicalAttack, MagicalDefense, Speed) diff --git a/src/Library/Attacks/AttackCategory.hpp b/src/Library/Attacks/AttackCategory.hpp index 022b7ad..0251254 100644 --- a/src/Library/Attacks/AttackCategory.hpp +++ b/src/Library/Attacks/AttackCategory.hpp @@ -1,8 +1,8 @@ #ifndef CREATURELIB_ATTACKCATEGORY_HPP #define CREATURELIB_ATTACKCATEGORY_HPP +#include #include -#include "../../Core/Enum.hpp" namespace CreatureLib::Library { ENUM(AttackCategory, uint8_t, Physical, Magical, Status) diff --git a/src/Library/Attacks/AttackTarget.hpp b/src/Library/Attacks/AttackTarget.hpp index d9abae6..0f66447 100644 --- a/src/Library/Attacks/AttackTarget.hpp +++ b/src/Library/Attacks/AttackTarget.hpp @@ -1,8 +1,8 @@ #ifndef CREATURELIB_ATTACKTARGET_HPP #define CREATURELIB_ATTACKTARGET_HPP +#include #include -#include "../../Core/Enum.hpp" namespace CreatureLib::Library { ENUM(AttackTarget, uint8_t, Adjacent, AdjacentAlly, AdjacentAllySelf, AdjacentOpponent, diff --git a/src/Library/CreatureData/CreatureSpecies.cpp b/src/Library/CreatureData/CreatureSpecies.cpp index e4006ef..387b6d9 100644 --- a/src/Library/CreatureData/CreatureSpecies.cpp +++ b/src/Library/CreatureData/CreatureSpecies.cpp @@ -40,7 +40,7 @@ void CreatureSpecies::SetVariant(const std::string& name, const SpeciesVariant* _variants[key] = variant; } -Gender CreatureSpecies::GetRandomGender(CreatureLib::Core::Random& rand) const { +Gender CreatureSpecies::GetRandomGender(Arbutils::Random& rand) const { // TODO: Genderless creatures auto val = rand.GetDouble(); if (val >= this->_genderRate) diff --git a/src/Library/CreatureData/CreatureSpecies.hpp b/src/Library/CreatureData/CreatureSpecies.hpp index 0281a9b..d959261 100644 --- a/src/Library/CreatureData/CreatureSpecies.hpp +++ b/src/Library/CreatureData/CreatureSpecies.hpp @@ -39,7 +39,7 @@ namespace CreatureLib::Library { [[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]] Gender GetRandomGender(Core::Random& rand) const; + [[nodiscard]] Gender GetRandomGender(Arbutils::Random& rand) const; [[nodiscard]] const std::string& GetName() const; void SetVariant(const std::string& name, const SpeciesVariant* variant); diff --git a/src/Library/CreatureData/SpeciesVariant.cpp b/src/Library/CreatureData/SpeciesVariant.cpp index 97129b4..0f7090c 100644 --- a/src/Library/CreatureData/SpeciesVariant.cpp +++ b/src/Library/CreatureData/SpeciesVariant.cpp @@ -36,7 +36,7 @@ int8_t CreatureLib::Library::SpeciesVariant::GetTalentIndex(const std::string& t throw CreatureException("The given talent is not a valid talent for this creature."); } -int8_t CreatureLib::Library::SpeciesVariant::GetRandomTalent(CreatureLib::Core::Random* rand) const { +int8_t CreatureLib::Library::SpeciesVariant::GetRandomTalent(Arbutils::Random* rand) const { return rand->Get(_talents.size()); } diff --git a/src/Library/CreatureData/SpeciesVariant.hpp b/src/Library/CreatureData/SpeciesVariant.hpp index b99af3b..2f207e1 100644 --- a/src/Library/CreatureData/SpeciesVariant.hpp +++ b/src/Library/CreatureData/SpeciesVariant.hpp @@ -1,9 +1,9 @@ #ifndef CREATURELIB_SPECIESVARIANT_HPP #define CREATURELIB_SPECIESVARIANT_HPP +#include #include #include -#include "../../Core/Random.hpp" #include "../../Core/StatisticSet.hpp" #include "CreatureMoves.hpp" #include "LearnableAttacks.hpp" @@ -46,7 +46,7 @@ namespace CreatureLib::Library { [[nodiscard]] const std::string& GetTalent(int32_t index) const; [[nodiscard]] const LearnableAttacks* GetLearnableAttacks() const; [[nodiscard]] int8_t GetTalentIndex(const std::string& talent) const; - [[nodiscard]] int8_t GetRandomTalent(Core::Random* rand) const; + [[nodiscard]] int8_t GetRandomTalent(Arbutils::Random* rand) const; [[nodiscard]] inline const std::vector& GetTalents() const { return _talents; } [[nodiscard]] inline const std::vector& GetSecretTalents() const { return _secretTalents; } }; diff --git a/src/Library/Gender.hpp b/src/Library/Gender.hpp index ab1bbf3..8dc4e44 100644 --- a/src/Library/Gender.hpp +++ b/src/Library/Gender.hpp @@ -1,8 +1,8 @@ #ifndef CREATURELIB_GENDER_HPP #define CREATURELIB_GENDER_HPP +#include #include -#include "../Core/Enum.hpp" namespace CreatureLib::Library { /*! diff --git a/src/Library/Items/BattleItemCategory.hpp b/src/Library/Items/BattleItemCategory.hpp index e26f555..0624c93 100644 --- a/src/Library/Items/BattleItemCategory.hpp +++ b/src/Library/Items/BattleItemCategory.hpp @@ -1,8 +1,8 @@ #ifndef CREATURELIB_BATTLEITEMCATEGORY_HPP #define CREATURELIB_BATTLEITEMCATEGORY_HPP +#include #include -#include "../../Core/Enum.hpp" namespace CreatureLib::Library { ENUM(BattleItemCategory, uint8_t, None, Healing, StatusHealing, CaptureDevice, MiscBattleItem) diff --git a/src/Library/Items/ItemCategory.hpp b/src/Library/Items/ItemCategory.hpp index 473b3f4..8cd3992 100644 --- a/src/Library/Items/ItemCategory.hpp +++ b/src/Library/Items/ItemCategory.hpp @@ -1,8 +1,8 @@ #ifndef CREATURELIB_ITEMCATEGORY_HPP #define CREATURELIB_ITEMCATEGORY_HPP +#include #include -#include "../../Core/Enum.hpp" namespace CreatureLib::Library { ENUM(ItemCategory, uint8_t, MiscItem, CaptureDevice, Medicine, Berry, MoveLearner, VariantChanger, KeyItem, Mail) diff --git a/tests/BattleTests/TurnOrderTests.cpp b/tests/BattleTests/TurnOrderTests.cpp index dcdc9b2..1e548cd 100644 --- a/tests/BattleTests/TurnOrderTests.cpp +++ b/tests/BattleTests/TurnOrderTests.cpp @@ -13,7 +13,7 @@ TEST_CASE("Turn ordering: Attack before pass", "[Battling]") { auto choice1 = new PassTurnChoice(nullptr); auto choice2 = new AttackTurnChoice(nullptr, nullptr, CreatureIndex(0, 0)); auto vec = std::vector{choice1, choice2}; - auto rand = Core::Random(); + auto rand = Arbutils::Random(); TurnOrdering::OrderChoices(vec, rand); CHECK(vec[0] == choice2); CHECK(vec[1] == choice1); @@ -33,7 +33,7 @@ TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]") auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0)); auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0)); auto vec = std::vector{choice1, choice2}; - auto rand = Core::Random(); + auto rand = Arbutils::Random(); TurnOrdering::OrderChoices(vec, rand); CHECK(vec[0] == choice2); CHECK(vec[1] == choice1); @@ -55,7 +55,7 @@ TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0)); auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0)); auto vec = std::vector{choice1, choice2}; - auto rand = Core::Random(); + auto rand = Arbutils::Random(); TurnOrdering::OrderChoices(vec, rand); CHECK(vec[0] == choice2); CHECK(vec[1] == choice1); @@ -77,7 +77,7 @@ TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]") auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0)); auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0)); auto vec = std::vector{choice1, choice2}; - auto rand = Core::Random(); + auto rand = Arbutils::Random(); TurnOrdering::OrderChoices(vec, rand); CHECK(vec[0] == choice2); CHECK(vec[1] == choice1); @@ -99,7 +99,7 @@ TEST_CASE("Turn ordering: No priority goes before low priority", "[Battling]") { auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0)); auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0)); auto vec = std::vector{choice1, choice2}; - auto rand = Core::Random(); + auto rand = Arbutils::Random(); TurnOrdering::OrderChoices(vec, rand); CHECK(vec[0] == choice2); CHECK(vec[1] == choice1); diff --git a/tests/EnumTests.cpp b/tests/EnumTests.cpp deleted file mode 100644 index 49d4c42..0000000 --- a/tests/EnumTests.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#ifdef TESTS_BUILD -#include -#include "../extern/catch.hpp" -#include "../src/Core/Enum.hpp" - -ENUM(TestEnum, uint8_t, Val1, Val2, Val3) - -TEST_CASE("Parse Enum case sensitive", "[Utilities]") { - CHECK(TestEnumHelper::Parse("Val1") == TestEnum::Val1); - CHECK(TestEnumHelper::Parse("Val2") == TestEnum::Val2); - CHECK(TestEnumHelper::Parse("Val3") == TestEnum::Val3); - CHECK_THROWS(TestEnumHelper::Parse("Val4")); - CHECK_THROWS(TestEnumHelper::Parse("val1")); -} - -TEST_CASE("Try Parse Enum case sensitive", "[Utilities]") { - TestEnum v = static_cast(255); - REQUIRE(TestEnumHelper::TryParse("Val1", v)); - CHECK(v == TestEnum::Val1); - REQUIRE(TestEnumHelper::TryParse("Val2", v)); - CHECK(v == TestEnum::Val2); - REQUIRE(TestEnumHelper::TryParse("Val3", v)); - CHECK(v == TestEnum::Val3); - CHECK_FALSE(TestEnumHelper::TryParse("Val4", v)); - CHECK_FALSE(TestEnumHelper::TryParse("val1", v)); -} - -TEST_CASE("Parse Enum case insensitive", "[Utilities]") { - CHECK(TestEnumHelper::Parse("Val1", true) == TestEnum::Val1); - CHECK(TestEnumHelper::Parse("Val2", true) == TestEnum::Val2); - CHECK(TestEnumHelper::Parse("Val3", true) == TestEnum::Val3); - CHECK(TestEnumHelper::Parse("val1", true) == TestEnum::Val1); - CHECK(TestEnumHelper::Parse("vAL2", true) == TestEnum::Val2); - CHECK(TestEnumHelper::Parse("VaL3", true) == TestEnum::Val3); - CHECK_THROWS(TestEnumHelper::Parse("Val4", true)); -} - -TEST_CASE("Try Parse Enum case insensitive", "[Utilities]") { - TestEnum v = static_cast(255); - REQUIRE(TestEnumHelper::TryParse("Val1", v, true)); - CHECK(v == TestEnum::Val1); - REQUIRE(TestEnumHelper::TryParse("Val2", v, true)); - CHECK(v == TestEnum::Val2); - REQUIRE(TestEnumHelper::TryParse("Val3", v, true)); - CHECK(v == TestEnum::Val3); - REQUIRE(TestEnumHelper::TryParse("val1", v, true)); - CHECK(v == TestEnum::Val1); - REQUIRE(TestEnumHelper::TryParse("vAL2", v, true)); - CHECK(v == TestEnum::Val2); - REQUIRE(TestEnumHelper::TryParse("VaL3", v, true)); - CHECK(v == TestEnum::Val3); - CHECK_FALSE(TestEnumHelper::TryParse("Val4", v, true)); -} - -TEST_CASE("Enum To String", "[Utilities]") { - CHECK(strcmp(TestEnumHelper::ToString(TestEnum::Val1), "Val1") == 0); - CHECK(strcmp(TestEnumHelper::ToString(TestEnum::Val2), "Val2") == 0); - CHECK(strcmp(TestEnumHelper::ToString(TestEnum::Val3), "Val3") == 0); -} - -TEST_CASE("Enum Get Values", "[Utilities]") { - auto vec = TestEnumHelper::GetValues(); - REQUIRE(vec.size() == 3); - CHECK(vec[0] == TestEnum::Val1); - CHECK(vec[1] == TestEnum::Val2); - CHECK(vec[2] == TestEnum::Val3); -} - -#endif \ No newline at end of file diff --git a/tests/RandomTests.cpp b/tests/RandomTests.cpp deleted file mode 100644 index 72410d2..0000000 --- a/tests/RandomTests.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#ifdef TESTS_BUILD -#include "../extern/catch.hpp" -#include "../src/Core/Exceptions/CreatureException.hpp" -#include "../src/Core/Random.hpp" - -TEST_CASE("Random ints", "[Utilities]") { - auto rand = CreatureLib::Core::Random(10); - CHECK(rand.Get() == 1656398469); - CHECK(rand.Get() == 641584702); - CHECK(rand.Get() == 44564466); - CHECK(rand.Get() == 1062123783); - CHECK(rand.Get() == 1360749216); - CHECK(rand.Get() == 951367352); - CHECK(rand.Get() == 1608044094); - CHECK(rand.Get() == 1786516046); - CHECK(rand.Get() == 1070535660); - CHECK(rand.Get() == 1252673902); -} - -TEST_CASE("Random ints with limit", "[Utilities]") { - auto rand = CreatureLib::Core::Random(10); - CHECK(rand.Get(10) == 7); - CHECK(rand.Get(10) == 2); - CHECK(rand.Get(10) == 0); - CHECK(rand.Get(10) == 4); - CHECK(rand.Get(10) == 6); - CHECK(rand.Get(10) == 4); - CHECK(rand.Get(10) == 7); - CHECK(rand.Get(10) == 8); - CHECK(rand.Get(10) == 4); - CHECK(rand.Get(10) == 5); - - CHECK(rand.Get(2) == 0); - CHECK(rand.Get(2) == 0); - CHECK(rand.Get(2) == 0); - CHECK(rand.Get(2) == 1); - CHECK(rand.Get(2) == 1); - CHECK(rand.Get(2) == 0); - CHECK(rand.Get(2) == 0); - CHECK(rand.Get(2) == 0); - CHECK(rand.Get(2) == 0); -} - -TEST_CASE("Random ints with upper and bottom", "[Utilities]") { - auto rand = CreatureLib::Core::Random(10); - CHECK(rand.Get(10, 30) == 25); - CHECK(rand.Get(10, 30) == 15); - CHECK(rand.Get(10, 30) == 10); - CHECK(rand.Get(10, 30) == 19); - CHECK(rand.Get(10, 30) == 22); - CHECK(rand.Get(10, 30) == 18); - CHECK(rand.Get(10, 30) == 24); - CHECK(rand.Get(10, 30) == 26); - CHECK(rand.Get(10, 30) == 19); - CHECK(rand.Get(10, 30) == 21); -} - -TEST_CASE("Random distribution (max 0, min 1)", "[Utilities]") { - auto rand = CreatureLib::Core::Random(10); - const int size = 100000; - int arr[size]; - for (size_t i = 0; i < size; i++) { - arr[i] = rand.Get(0, 1); - } - for (size_t i = 0; i < size; i++) { - if (arr[i] != 0) - throw CreatureException("We expected a value of 0 here, but got a " + std::to_string(arr[i])); - } -} - -TEST_CASE("Random distribution (max 0, min 2)", "[Utilities]") { - auto rand = CreatureLib::Core::Random(10); - const int size = 100000; - int arr[size]; - for (size_t i = 0; i < size; i++) { - arr[i] = rand.Get(0, 2); - } - auto numZeros = 0; - auto numOnes = 0; - for (size_t i = 0; i < size; i++) { - if (arr[i] != 0 && arr[i] != 1) - throw CreatureException("We expected a value of 0 or 1 here, but got a " + std::to_string(arr[i])); - if (arr[i] == 0) - numZeros++; - else - numOnes++; - } - auto div = static_cast(numZeros) / static_cast(numOnes); - INFO("Distribution: " << numZeros << "/" << numOnes); - CHECK(Approx(div).margin(0.01) == 1); -} - -TEST_CASE("Random distribution (max 0, min 3)", "[Utilities]") { - auto rand = CreatureLib::Core::Random(10); - const int size = 100000; - int arr[size]; - for (size_t i = 0; i < size; i++) { - arr[i] = rand.Get(0, 3); - } - auto numZeros = 0; - auto numOnes = 0; - auto numTwos = 0; - for (size_t i = 0; i < size; i++) { - if (arr[i] != 0 && arr[i] != 1 && arr[i] != 2) - throw CreatureException("We expected a value between 0 and 2 here, but got a " + std::to_string(arr[i])); - if (arr[i] == 0) - numZeros++; - else if (arr[i] == 1) - numOnes++; - else - numTwos++; - } - INFO("Distribution: " << numZeros << "/" << numOnes << "/" << numTwos); - CHECK(Approx(static_cast(numZeros) / static_cast(numOnes)).margin(0.01) == 1); - CHECK(Approx(static_cast(numZeros) / static_cast(numTwos)).margin(0.01) == 1); - CHECK(Approx(static_cast(numOnes) / static_cast(numTwos)).margin(0.01) == 1); -} - -#endif \ No newline at end of file