Adds getter for UniqueIdentifier
continuous-integration/drone/push Build is passing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2020-08-09 11:48:40 +02:00
parent fb56d0920d
commit 48660f3a4c
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
4 changed files with 32 additions and 1 deletions

View File

@ -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) {

View File

@ -88,6 +88,7 @@ namespace CreatureLib::Battling {
virtual void ChangeVariant(ArbUt::BorrowedPtr<const Library::SpeciesVariant> 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<LearnedAttack>& 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<const Library::CreatureSpecies> GetDisplaySpecies() const noexcept;
ArbUt::BorrowedPtr<const Library::SpeciesVariant> GetDisplayVariant() const noexcept;

View File

@ -20,8 +20,10 @@ bool CreatureSpecies::TryGetVariant(uint32_t hash, ArbUt::BorrowedPtr<const Spec
}
void CreatureSpecies::SetVariant(const ArbUt::StringView& name, const SpeciesVariant* variant) {
Assert(!name.IsEmpty())
AssertNotNull(variant)
_variantsList.CreateBack(variant);
_variantsLookup.GetStdMap().insert({name, std::unique_ptr<const SpeciesVariant>(variant)});
_variantsList.Append(variant);
}
Gender CreatureSpecies::GetRandomGender(ArbUt::Random& rand) const noexcept {

View File

@ -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<uint16_t>(), {}, {}, nullptr);
auto c = CreatureSpecies(0, "foo", defaultVariant, 0, "", 0);
auto secondVariant = new SpeciesVariant("second", 0, 0, 0, {0, 1}, StatisticSet<uint16_t>(), {}, {}, nullptr);
c.SetVariant("second"_cnc, secondVariant);
}
#endif