From 48660f3a4c21b8b77d909b70286ad5d99f58476b Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 9 Aug 2020 11:48:40 +0200 Subject: [PATCH] Adds getter for UniqueIdentifier Signed-off-by: Deukhoofd --- CInterface/Battling/Creature.cpp | 4 ++++ src/Battling/Models/Creature.hpp | 10 ++++++++++ src/Library/CreatureData/CreatureSpecies.cpp | 4 +++- tests/LibraryTests/SpeciesTest.cpp | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/LibraryTests/SpeciesTest.cpp diff --git a/CInterface/Battling/Creature.cpp b/CInterface/Battling/Creature.cpp index 59ee0f4..01c5eaf 100644 --- a/CInterface/Battling/Creature.cpp +++ b/CInterface/Battling/Creature.cpp @@ -28,6 +28,7 @@ export uint8_t CreatureLib_Creature_ChangeVariant(Creature* p, const CreatureLib SIMPLE_GET_FUNC(Creature, GetLevel, uint8_t); SIMPLE_GET_FUNC(Creature, GetExperience, uint32_t); +SIMPLE_GET_FUNC(Creature, GetUniqueIdentifier, uint32_t); SIMPLE_GET_FUNC(Creature, GetGender, CreatureLib::Library::Gender); SIMPLE_GET_FUNC(Creature, GetColoring, uint8_t); @@ -85,6 +86,9 @@ export bool CreatureLib_Creature_HasVolatileScript(Creature* p, const char* scri } export size_t CreatureLib_Creature_GetAttacksCount(Creature* p) { return p->GetAttacks().Count(); } export LearnedAttack* const* CreatureLib_Creature_GetAttacks(Creature* p) { return p->GetAttacks().RawData(); } +export bool CreatureLib_Creature_HasAttack(Creature* p, const char* scriptName) { + return p->HasAttack(ArbUt::StringView(scriptName)); +} BORROWED_GET_FUNC(Creature, GetDisplaySpecies, const CreatureLib::Library::CreatureSpecies*); BORROWED_GET_FUNC(Creature, GetDisplayVariant, const CreatureLib::Library::SpeciesVariant*); export void CreatureLib_Creature_SetDisplaySpecies(Creature* p, const CreatureLib::Library::CreatureSpecies* species) { diff --git a/src/Battling/Models/Creature.hpp b/src/Battling/Models/Creature.hpp index 0398426..2647ce8 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -88,6 +88,7 @@ namespace CreatureLib::Battling { virtual void ChangeVariant(ArbUt::BorrowedPtr variant); inline uint8_t GetLevel() const noexcept { return _level; } inline uint32_t GetExperience() const noexcept { return _experience; } + inline uint32_t GetUniqueIdentifier() const noexcept { return _uniqueIdentifier; } inline Library::Gender GetGender() const noexcept { return _gender; } inline uint8_t GetColoring() const noexcept { return _coloring; } inline bool HasHeldItem(const ArbUt::BasicStringView& name) const noexcept { @@ -137,6 +138,15 @@ namespace CreatureLib::Battling { bool HasVolatileScript(const ArbUt::BasicStringView& name) const; const ArbUt::UniquePtrList& GetAttacks() noexcept { return _attacks; } + bool HasAttack(const ArbUt::StringView& name) { + for (auto& a : _attacks) { + if (a == nullptr) + continue; + if (a->GetAttack()->GetName() == name) + return true; + } + return false; + } ArbUt::BorrowedPtr GetDisplaySpecies() const noexcept; ArbUt::BorrowedPtr GetDisplayVariant() const noexcept; diff --git a/src/Library/CreatureData/CreatureSpecies.cpp b/src/Library/CreatureData/CreatureSpecies.cpp index 98851e3..998c8c0 100644 --- a/src/Library/CreatureData/CreatureSpecies.cpp +++ b/src/Library/CreatureData/CreatureSpecies.cpp @@ -20,8 +20,10 @@ bool CreatureSpecies::TryGetVariant(uint32_t hash, ArbUt::BorrowedPtr(variant)}); - _variantsList.Append(variant); } Gender CreatureSpecies::GetRandomGender(ArbUt::Random& rand) const noexcept { diff --git a/tests/LibraryTests/SpeciesTest.cpp b/tests/LibraryTests/SpeciesTest.cpp new file mode 100644 index 0000000..0148fa1 --- /dev/null +++ b/tests/LibraryTests/SpeciesTest.cpp @@ -0,0 +1,15 @@ +#ifdef TESTS_BUILD + +#include "../../extern/catch.hpp" +#include "../../src/Library/CreatureData/CreatureSpecies.hpp" + +using namespace CreatureLib::Library; + +TEST_CASE("Set Variant", "[Library]") { + auto defaultVariant = new SpeciesVariant("default", 0, 0, 0, {0, 1}, StatisticSet(), {}, {}, nullptr); + auto c = CreatureSpecies(0, "foo", defaultVariant, 0, "", 0); + auto secondVariant = new SpeciesVariant("second", 0, 0, 0, {0, 1}, StatisticSet(), {}, {}, nullptr); + c.SetVariant("second"_cnc, secondVariant); +} + +#endif \ No newline at end of file