Support for finding the previous evolution step of a Pokemon.

This commit is contained in:
2020-08-11 21:46:22 +02:00
parent 9274b675e9
commit 5e917b7047
3 changed files with 33 additions and 0 deletions

View File

@@ -1 +1,20 @@
#include "SpeciesLibrary.hpp"
namespace PkmnLib::Library {
ArbUt::BorrowedPtr<const PokemonSpecies>
SpeciesLibrary::FindPreEvolution(const ArbUt::BorrowedPtr<const PokemonSpecies>& species) const noexcept {
if (_preEvolutionCache.Has(species)) {
return _preEvolutionCache[species];
}
for (auto& s : _values) {
auto pkmn = (PokemonSpecies*)s.second.get();
for (auto& evo : pkmn->GetEvolutions()) {
if (evo->GetNewSpecies() == species) {
auto non_const = const_cast<SpeciesLibrary*>(this);
non_const->_preEvolutionCache[species] = pkmn;
return pkmn;
}
}
}
return nullptr;
}
}