From 7aa29e4543eb6f72fe83b75cacc155d23c982645 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Thu, 13 Feb 2020 18:00:23 +0100 Subject: [PATCH] Update CreatureLib, handle getting formes cleaner. --- conanfile.py | 2 +- src/Battling/Pokemon/CreatePokemon.cpp | 11 +++++++++-- src/Battling/Pokemon/Pokemon.hpp | 1 + src/Library/Species/PokemonSpecies.hpp | 6 ++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/conanfile.py b/conanfile.py index 151d989..3abcd89 100644 --- a/conanfile.py +++ b/conanfile.py @@ -44,7 +44,7 @@ class PkmnLibConan(ConanFile): self.options["AngelScript"].link_std_statically = True def requirements(self): - self.requires("CreatureLib/611198009b81f58f72011887ecc0e1bf2c93e342@creaturelib/master") + self.requires("CreatureLib/667821df28235613bf46549734a2799b5537566f@creaturelib/master") if self.options.script_handler == "angelscript": self.requires("AngelScript/2.34@AngelScript/Deukhoofd") else: diff --git a/src/Battling/Pokemon/CreatePokemon.cpp b/src/Battling/Pokemon/CreatePokemon.cpp index 90c5f41..b4249a1 100644 --- a/src/Battling/Pokemon/CreatePokemon.cpp +++ b/src/Battling/Pokemon/CreatePokemon.cpp @@ -41,9 +41,16 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() { auto rand = CreatureLib::Core::Random(); const PkmnLib::Library::PokemonSpecies* species = nullptr; if (!this->_library->GetSpeciesLibrary()->TryGetPkmnSpecies(this->_species, species)) { - throw CreatureException("Invalid species: " + _species); + std::stringstream err; + err << "Invalid species '" << _species << "'."; + throw CreatureException(err.str()); + } + const PkmnLib::Library::PokemonForme* forme; + if (!species->TryGetForme(this->_forme, forme)){ + std::stringstream err; + err << "Invalid forme '" << _forme << "' for species '" << _forme << "'."; + throw CreatureException(err.str()); } - auto forme = species->GetForme(this->_forme); int8_t ability; if (this->_ability.empty()) { ability = forme->GetRandomTalent(&rand); diff --git a/src/Battling/Pokemon/Pokemon.hpp b/src/Battling/Pokemon/Pokemon.hpp index 0cbb6e3..6da108f 100644 --- a/src/Battling/Pokemon/Pokemon.hpp +++ b/src/Battling/Pokemon/Pokemon.hpp @@ -29,6 +29,7 @@ namespace PkmnLib::Battling { heldItem, nickname, talent, std::move(moves)), _individualValues(individualValues), _effortValues(effortValues), _nature(nature) {} + const Library::PokemonForme* GetForme() const { return dynamic_cast(GetVariant()); } diff --git a/src/Library/Species/PokemonSpecies.hpp b/src/Library/Species/PokemonSpecies.hpp index c52f444..da7d148 100644 --- a/src/Library/Species/PokemonSpecies.hpp +++ b/src/Library/Species/PokemonSpecies.hpp @@ -24,6 +24,12 @@ namespace PkmnLib::Library { return reinterpret_cast(CreatureSpecies::GetVariant("default")); } + inline bool HasForme(const std::string& key) const { return HasVariant(key); } + + inline bool TryGetForme(const std::string& key, const PokemonForme*& forme) const { + return TryGetVariant(key, (const CreatureLib::Library::SpeciesVariant*&)forme); + } + inline const PokemonForme* GetForme(const std::string& key) const { return reinterpret_cast(CreatureSpecies::GetVariant(key)); }