Smart pointers for most library and battle classes.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
1d1dc877a0
commit
2d3a2fc63b
|
@ -8,8 +8,8 @@ export uint8_t PkmnLib_ExperienceLibrary_HandleExperienceGain(ExperienceLibrary*
|
|||
CreatureLib::Battling::Creature* faintedMon,
|
||||
CreatureLib::Battling::Creature* const* opponents,
|
||||
size_t numberOfOpponents) {
|
||||
Try(p->HandleExperienceGain(
|
||||
faintedMon, std::unordered_set<CreatureLib::Battling::Creature*>(opponents, opponents + numberOfOpponents));)
|
||||
Try(p->HandleExperienceGain(faintedMon, std::unordered_set<ArbUt::BorrowedPtr<CreatureLib::Battling::Creature>>(
|
||||
opponents, opponents + numberOfOpponents));)
|
||||
}
|
||||
|
||||
export void PkmnLib_ExperienceLibrary_Destruct(ExperienceLibrary* p) { delete p; }
|
||||
|
|
|
@ -12,7 +12,7 @@ export Pokemon* PkmnLib_Pokemon_Construct(const BattleLibrary* library, const Pk
|
|||
uint8_t spIv, uint8_t hpEv, uint8_t attEv, uint8_t defEv, uint8_t sAtEv,
|
||||
uint8_t sDeEv, uint8_t spEv, const PkmnLib::Library::Nature* nature) {
|
||||
std::string nick(nickname);
|
||||
ArbUt::List<CreatureLib::Battling::LearnedAttack*> cMoves(moves, moves + moveCount);
|
||||
std::vector<CreatureLib::Battling::LearnedAttack*> cMoves(moves, moves + moveCount);
|
||||
|
||||
return new Pokemon(library, species, forme, level, experience, uid, gender, coloring, heldItem, nick,
|
||||
CreatureLib::Library::TalentIndex(hiddenAbility, abilityIndex), cMoves,
|
||||
|
@ -24,9 +24,11 @@ export void PkmnLib_Pokemon_Destruct(const Pokemon* p) { delete p; }
|
|||
|
||||
#define SIMPLE_GET_FUNC(type, name, returnType) \
|
||||
export returnType PkmnLib_##type##_##name(const PkmnLib::Battling::type* p) { return p->name(); }
|
||||
#define SIMPLE_GET_FUNC_SMART_PTR(type, name, returnType) \
|
||||
export returnType PkmnLib_##type##_##name(const PkmnLib::Battling::type* p) { return p->name().operator->(); }
|
||||
|
||||
SIMPLE_GET_FUNC(Pokemon, IsShiny, bool)
|
||||
SIMPLE_GET_FUNC(Pokemon, GetNature, const PkmnLib::Library::Nature*)
|
||||
SIMPLE_GET_FUNC_SMART_PTR(Pokemon, GetNature, const PkmnLib::Library::Nature*)
|
||||
|
||||
#undef SIMPLE_GET_FUNC
|
||||
|
||||
|
@ -36,3 +38,6 @@ export uint8_t PkmnLib_Pokemon_GetIndividualValue(const Pokemon* p, CreatureLib:
|
|||
export uint8_t PkmnLib_Pokemon_GetEffortValue(const Pokemon* p, CreatureLib::Library::Statistic stat) {
|
||||
return p->GetEffortValue(stat);
|
||||
}
|
||||
|
||||
#undef SIMPLE_GET_FUNC
|
||||
#undef SIMPLE_GET_FUNC_SMART_PTR
|
|
@ -49,16 +49,16 @@ export const EvolutionData* PkmnLib_Evolution_CreateTradeWithSpeciesEvolution(co
|
|||
}
|
||||
export const EvolutionData* PkmnLib_Evolution_CreateCustomEvolution(const CreatureLib::Library::EffectParameter** data,
|
||||
size_t dataLength, const PokemonSpecies* into) {
|
||||
auto list = ArbUt::List<const CreatureLib::Library::EffectParameter*>(data, data + dataLength);
|
||||
auto list = std::vector<const CreatureLib::Library::EffectParameter*>(data, data + dataLength);
|
||||
return EvolutionData::CreateCustomEvolution(list, into);
|
||||
}
|
||||
|
||||
export EvolutionMethod PkmnLib_Evolution_GetMethod(const EvolutionData* data) { return data->GetMethod(); }
|
||||
export const PokemonSpecies* PkmnLib_Evolution_GetNewSpecies(const EvolutionData* data) {
|
||||
return data->GetNewSpecies();
|
||||
return data->GetNewSpecies().GetRaw();
|
||||
}
|
||||
export size_t PkmnLib_Evolution_GetDataCount(const EvolutionData* data) { return data->GetDataCount(); }
|
||||
export uint8_t PkmnLib_Evolution_GetData(const EvolutionData* data, size_t index,
|
||||
const CreatureLib::Library::EffectParameter*& out) {
|
||||
Try(out = data->GetData(index));
|
||||
Try(out = data->GetData(index).GetRaw());
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ export uint8_t PkmnLib_NatureLibrary_LoadNature(NatureLibrary* p, const char* na
|
|||
Try(p->LoadNature(ArbUt::CaseInsensitiveConstString(name), nature);)
|
||||
}
|
||||
export uint8_t PkmnLib_NatureLibrary_GetNatureByName(NatureLibrary* p, const char* name, const Nature*& out) {
|
||||
Try(out = p->GetNatureByName(ArbUt::CaseInsensitiveConstString(name)));
|
||||
Try(out = p->GetNatureByName(ArbUt::CaseInsensitiveConstString(name)).GetRaw());
|
||||
}
|
||||
|
||||
export const char* PkmnLib_NatureLibrary_GetRandomNatureName(NatureLibrary* p, ArbUt::Random* rand) {
|
||||
|
|
|
@ -12,5 +12,5 @@ export uint8_t PkmnLib_PokemonLibrary_Construct(PokemonLibrary*& out, PkmnLib::L
|
|||
|
||||
export void PkmnLib_PokemonLibrary_Destruct(const PokemonLibrary* p) { delete p; }
|
||||
export const NatureLibrary* PkmnLib_PokemonLibrary_GetNatureLibrary(const PokemonLibrary* p) {
|
||||
return p->GetNatureLibrary();
|
||||
return p->GetNatureLibrary().GetRaw();
|
||||
}
|
|
@ -24,5 +24,5 @@ export void PkmnLib_PokemonSpecies_AddEvolution(PokemonSpecies* p, EvolutionData
|
|||
export size_t PkmnLib_PokemonSpecies_GetEvolutionCount(const PokemonSpecies* p) { return p->GetEvolutions().Count(); }
|
||||
|
||||
export uint8_t PkmnLib_PokemonSpecies_GetEvolution(const PokemonSpecies* p, size_t index, const EvolutionData*& out) {
|
||||
Try(out = p->GetEvolutions().At(index));
|
||||
Try(out = p->GetEvolutions().At(index).GetRaw());
|
||||
}
|
|
@ -2,14 +2,13 @@
|
|||
void PkmnLib::Battling::Battle::SetWeather(const ArbUt::CaseInsensitiveConstString& name) {
|
||||
if (_weatherScript != nullptr) {
|
||||
_weatherScript->OnRemove();
|
||||
delete _weatherScript;
|
||||
}
|
||||
_weatherScript = _library->LoadScript(static_cast<ScriptCategory>(PkmnScriptCategory::Weather), name);
|
||||
_weatherScript = std::unique_ptr<CreatureLib::Battling::Script>(
|
||||
_library->LoadScript(static_cast<ScriptCategory>(PkmnScriptCategory::Weather), name));
|
||||
_eventHook.TriggerEvent(new WeatherChangeEvent(name));
|
||||
}
|
||||
void PkmnLib::Battling::Battle::ClearWeather() {
|
||||
_weatherScript->OnRemove();
|
||||
delete _weatherScript;
|
||||
_weatherScript = nullptr;
|
||||
_eventHook.TriggerEvent(new WeatherChangeEvent(""_cnc));
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
namespace PkmnLib::Battling {
|
||||
class Battle : public CreatureLib::Battling::Battle {
|
||||
private:
|
||||
CreatureLib::Battling::Script* _weatherScript = nullptr;
|
||||
std::unique_ptr<CreatureLib::Battling::Script> _weatherScript = nullptr;
|
||||
|
||||
public:
|
||||
Battle(const BattleLibrary* library, const ArbUt::List<CreatureLib::Battling::BattleParty*>& parties,
|
||||
|
|
|
@ -40,7 +40,9 @@ namespace PkmnLib::Battling {
|
|||
return reinterpret_cast<const std::unique_ptr<const Library::ItemLibrary>&>(_staticLib->GetItemLibrary());
|
||||
}
|
||||
|
||||
const Library::NatureLibrary* GetNatureLibrary() const { return GetStaticLib()->GetNatureLibrary(); }
|
||||
const ArbUt::BorrowedPtr<const Library::NatureLibrary> GetNatureLibrary() const {
|
||||
return GetStaticLib()->GetNatureLibrary();
|
||||
}
|
||||
|
||||
static CreatureLib::Battling::ScriptResolver* CreateScriptResolver();
|
||||
};
|
||||
|
|
|
@ -28,7 +28,7 @@ float PkmnLib::Battling::DamageLibrary::GetStatModifier(CreatureLib::Battling::E
|
|||
// HOOK: allow overriding for which users stat we use.
|
||||
CreatureLib::Library::Statistic offensiveStat;
|
||||
CreatureLib::Library::Statistic defensiveStat;
|
||||
auto learnedMove = static_cast<LearnedMove*>(attack->GetAttack());
|
||||
auto learnedMove = attack->GetAttack().ForceAs<LearnedMove>();
|
||||
auto moveData = learnedMove->GetMoveData();
|
||||
if (moveData->GetCategory() == Library::MoveCategory::Physical) {
|
||||
offensiveStat = Library::Statistic::PhysicalAttack;
|
||||
|
|
|
@ -3,20 +3,21 @@
|
|||
#include "../PkmnScriptHook.hpp"
|
||||
#include "../Pokemon/Pokemon.hpp"
|
||||
|
||||
static inline uint32_t CalculateDynamicExperience(uint8_t level, float v1, CreatureLib::Battling::Creature* op,
|
||||
CreatureLib::Battling::Creature* faintedMon) {
|
||||
static inline uint32_t CalculateDynamicExperience(uint8_t level, float v1,
|
||||
ArbUt::BorrowedPtr<CreatureLib::Battling::Creature> op,
|
||||
ArbUt::BorrowedPtr<CreatureLib::Battling::Creature> faintedMon) {
|
||||
float a = 2 * level + 10;
|
||||
float b = level + op->GetLevel() + 10;
|
||||
float v2 = (a * a * sqrt(a)) / (b * b * sqrt(b));
|
||||
uint32_t experienceGain = v1 * v2 + 1;
|
||||
// TODO: Check owner and international
|
||||
PKMN_HOOK(ModifyExperienceGain, op, faintedMon, op, &experienceGain);
|
||||
PKMN_HOOK(ModifyExperienceGain, op, faintedMon.GetRaw(), op.GetRaw(), &experienceGain);
|
||||
return experienceGain;
|
||||
}
|
||||
|
||||
void PkmnLib::Battling::ExperienceLibrary::HandleExperienceGain(
|
||||
CreatureLib::Battling::Creature* faintedMon,
|
||||
const std::unordered_set<CreatureLib::Battling::Creature*>& opponents) const {
|
||||
const std::unordered_set<ArbUt::BorrowedPtr<CreatureLib::Battling::Creature>>& opponents) const {
|
||||
|
||||
auto fainted = dynamic_cast<Pokemon*>(faintedMon);
|
||||
auto expGain = fainted->GetForme()->GetBaseExperience();
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
namespace PkmnLib::Battling {
|
||||
class ExperienceLibrary : public CreatureLib::Battling::ExperienceLibrary {
|
||||
public:
|
||||
void HandleExperienceGain(CreatureLib::Battling::Creature* faintedMon,
|
||||
const std::unordered_set<CreatureLib::Battling::Creature*>& opponents) const override;
|
||||
void HandleExperienceGain(
|
||||
CreatureLib::Battling::Creature* faintedMon,
|
||||
const std::unordered_set<ArbUt::BorrowedPtr<CreatureLib::Battling::Creature>>& opponents) const override;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -7,24 +7,22 @@
|
|||
|
||||
namespace PkmnLib::Battling {
|
||||
class MiscLibrary : public CreatureLib::Battling::MiscLibrary {
|
||||
PkmnLib::Library::MoveData* _struggleData =
|
||||
new PkmnLib::Library::MoveData("struggle"_cnc, 0, PkmnLib::Library::MoveCategory::Physical, 50, 255, 10,
|
||||
std::unique_ptr<const PkmnLib::Library::MoveData> _struggleData = std::make_unique<PkmnLib::Library::MoveData>(
|
||||
"struggle"_cnc, 0, PkmnLib::Library::MoveCategory::Physical, 50, 255, 10,
|
||||
CreatureLib::Library::AttackTarget::Any, 0,
|
||||
new CreatureLib::Library::SecondaryEffect(-1, "struggle"_cnc, {}), {});
|
||||
new CreatureLib::Library::SecondaryEffect(-1, "struggle"_cnc, {}), std::unordered_set<uint32_t>());
|
||||
;
|
||||
CreatureLib::Battling::LearnedAttack* _struggle =
|
||||
new PkmnLib::Battling::LearnedMove(_struggleData, CreatureLib::Battling::AttackLearnMethod::Unknown);
|
||||
std::unique_ptr<CreatureLib::Battling::LearnedAttack> _struggle =
|
||||
std::make_unique<PkmnLib::Battling::LearnedMove>(_struggleData,
|
||||
CreatureLib::Battling::AttackLearnMethod::Unknown);
|
||||
|
||||
[[nodiscard]] CreatureLib::Battling::LearnedAttack* GetReplacementAttack() const {
|
||||
[[nodiscard]] ArbUt::BorrowedPtr<CreatureLib::Battling::LearnedAttack> GetReplacementAttack() const {
|
||||
_struggle->RestoreAllUses();
|
||||
return _struggle;
|
||||
}
|
||||
|
||||
public:
|
||||
~MiscLibrary() override {
|
||||
delete _struggle;
|
||||
delete _struggleData;
|
||||
};
|
||||
~MiscLibrary() override = default;
|
||||
bool IsCritical(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||
uint8_t hit) const override;
|
||||
bool CanFlee(CreatureLib::Battling::FleeTurnChoice* switchChoice) const override;
|
||||
|
|
|
@ -74,14 +74,14 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
|||
}
|
||||
auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level);
|
||||
|
||||
auto attacks = ArbUt::List<CreatureLib::Battling::LearnedAttack*>(_attacks.Count());
|
||||
auto attacks = std::vector<CreatureLib::Battling::LearnedAttack*>(_attacks.Count());
|
||||
for (size_t i = 0; i < _attacks.Count(); i++) {
|
||||
auto& kv = _attacks[i];
|
||||
auto move = kv.Move;
|
||||
if (move != nullptr)
|
||||
attacks.Append(new LearnedMove(move, kv.LearnMethod));
|
||||
attacks[i] = new LearnedMove(move, kv.LearnMethod);
|
||||
else
|
||||
attacks.Append(nullptr);
|
||||
attacks[i] = nullptr;
|
||||
}
|
||||
auto ivs = CreatureLib::Library::StatisticSet(_ivHp, _ivAttack, _ivDefense, _ivSpAtt, _ivSpDef, _ivSpeed);
|
||||
auto evs = CreatureLib::Library::StatisticSet(_evHp, _evAttack, _evDefense, _evSpAtt, _evSpDef, _evSpeed);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
namespace PkmnLib::Battling {
|
||||
class CreatePokemon {
|
||||
private:
|
||||
const BattleLibrary* _library;
|
||||
ArbUt::BorrowedPtr<const BattleLibrary> _library;
|
||||
ArbUt::CaseInsensitiveConstString _species = ""_cnc;
|
||||
ArbUt::CaseInsensitiveConstString _forme = "default"_cnc;
|
||||
uint8_t _level;
|
||||
|
|
|
@ -13,21 +13,23 @@ namespace PkmnLib::Battling {
|
|||
CreatureLib::Library::StatisticSet<uint8_t> _individualValues;
|
||||
CreatureLib::Library::StatisticSet<uint8_t> _effortValues;
|
||||
|
||||
const PkmnLib::Library::Nature* _nature;
|
||||
ArbUt::BorrowedPtr<const PkmnLib::Library::Nature> _nature;
|
||||
|
||||
const BattleLibrary* GetLibrary() const { return reinterpret_cast<const BattleLibrary*>(_library); }
|
||||
ArbUt::BorrowedPtr<const BattleLibrary> GetLibrary() const { return _library.ForceAs<const BattleLibrary>(); }
|
||||
|
||||
public:
|
||||
Pokemon(const BattleLibrary* library, const ArbUt::BorrowedPtr<const Library::PokemonSpecies>& species,
|
||||
Pokemon(ArbUt::BorrowedPtr<const BattleLibrary> library,
|
||||
const ArbUt::BorrowedPtr<const Library::PokemonSpecies>& species,
|
||||
const ArbUt::BorrowedPtr<const Library::PokemonForme>& forme, uint8_t level, uint32_t experience,
|
||||
uint32_t uid, CreatureLib::Library::Gender gender, uint8_t coloring,
|
||||
ArbUt::BorrowedPtr<const Library::Item> heldItem, const std::string& nickname,
|
||||
const CreatureLib::Library::TalentIndex& talent,
|
||||
const ArbUt::List<CreatureLib::Battling::LearnedAttack*>& moves,
|
||||
const std::vector<CreatureLib::Battling::LearnedAttack*>& moves,
|
||||
CreatureLib::Library::StatisticSet<uint8_t> individualValues,
|
||||
CreatureLib::Library::StatisticSet<uint8_t> effortValues, const PkmnLib::Library::Nature* nature,
|
||||
bool allowedExperienceGain = true)
|
||||
: CreatureLib::Battling::Creature(library, species.As<const CreatureLib::Library::CreatureSpecies>(),
|
||||
CreatureLib::Library::StatisticSet<uint8_t> effortValues,
|
||||
ArbUt::BorrowedPtr<const PkmnLib::Library::Nature> nature, bool allowedExperienceGain = true)
|
||||
: CreatureLib::Battling::Creature(library.ForceAs<const CreatureLib::Battling::BattleLibrary>(),
|
||||
species.ForceAs<const CreatureLib::Library::CreatureSpecies>(),
|
||||
forme.As<const CreatureLib::Library::SpeciesVariant>(), level, experience,
|
||||
uid, gender, coloring, heldItem.As<const CreatureLib::Library::Item>(),
|
||||
nickname, talent, moves, allowedExperienceGain),
|
||||
|
@ -43,7 +45,7 @@ namespace PkmnLib::Battling {
|
|||
return reinterpret_cast<const ArbUt::List<LearnedMove*>&>(_attacks);
|
||||
}
|
||||
|
||||
inline const Library::Nature* GetNature() const noexcept { return _nature; }
|
||||
inline const ArbUt::BorrowedPtr<const PkmnLib::Library::Nature>& GetNature() const noexcept { return _nature; }
|
||||
inline uint8_t GetIndividualValue(CreatureLib::Library::Statistic stat) const {
|
||||
return _individualValues.GetStat(stat);
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ namespace PkmnLib::Battling {
|
|||
PokemonParty(std::initializer_list<CreatureLib::Battling::Creature*> party)
|
||||
: CreatureLib::Battling::CreatureParty(party) {}
|
||||
|
||||
Pokemon* GetAtIndex(int index) const {
|
||||
return dynamic_cast<Pokemon*>(CreatureLib::Battling::CreatureParty::GetAtIndex(index));
|
||||
ArbUt::BorrowedPtr<Pokemon> GetAtIndex(int index) const {
|
||||
return CreatureLib::Battling::CreatureParty::GetAtIndex(index).As<Pokemon>();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2,12 +2,15 @@
|
|||
#define PKMNLIB_EVOLUTIONDATA_HPP
|
||||
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
||||
#include <Arbutils/Memory/UniquePtrList.hpp>
|
||||
#include <CreatureLib/Library/EffectParameter.hpp>
|
||||
#include <CreatureLib/Library/Gender.hpp>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include "../TimeOfDay.hpp"
|
||||
#include "EvolutionMethod.hpp"
|
||||
|
||||
namespace PkmnLib::Library {
|
||||
class PokemonSpecies;
|
||||
class MoveData;
|
||||
|
@ -15,20 +18,16 @@ namespace PkmnLib::Library {
|
|||
|
||||
class EvolutionData {
|
||||
private:
|
||||
const PokemonSpecies* _evolvesInto;
|
||||
ArbUt::BorrowedPtr<const PokemonSpecies> _evolvesInto;
|
||||
EvolutionMethod _method;
|
||||
ArbUt::List<const CreatureLib::Library::EffectParameter*> _evolutionData;
|
||||
ArbUt::UniquePtrList<const CreatureLib::Library::EffectParameter> _evolutionData;
|
||||
|
||||
EvolutionData(EvolutionMethod method, ArbUt::List<const CreatureLib::Library::EffectParameter*> data,
|
||||
EvolutionData(EvolutionMethod method, std::vector<const CreatureLib::Library::EffectParameter*> data,
|
||||
const PokemonSpecies* next)
|
||||
: _evolvesInto(next), _method(method), _evolutionData(std::move(data)) {}
|
||||
|
||||
public:
|
||||
~EvolutionData() {
|
||||
for (auto v : _evolutionData) {
|
||||
delete v;
|
||||
}
|
||||
}
|
||||
~EvolutionData() = default;
|
||||
|
||||
static inline const EvolutionData* CreateLevelEvolution(uint8_t level, const PokemonSpecies* into) {
|
||||
return new EvolutionData(EvolutionMethod::Level,
|
||||
|
@ -67,15 +66,18 @@ namespace PkmnLib::Library {
|
|||
static const EvolutionData* CreateTradeWithSpeciesEvolution(const PokemonSpecies* traded,
|
||||
const PokemonSpecies* into);
|
||||
static inline const EvolutionData*
|
||||
CreateCustomEvolution(const ArbUt::List<const CreatureLib::Library::EffectParameter*>& data,
|
||||
CreateCustomEvolution(const std::vector<const CreatureLib::Library::EffectParameter*>& data,
|
||||
const PokemonSpecies* into) {
|
||||
return new EvolutionData(EvolutionMethod::Custom, data, into);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline const PokemonSpecies* GetNewSpecies() const noexcept { return _evolvesInto; }
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const PokemonSpecies> GetNewSpecies() const noexcept {
|
||||
return _evolvesInto;
|
||||
}
|
||||
[[nodiscard]] inline EvolutionMethod GetMethod() const noexcept { return _method; }
|
||||
[[nodiscard]] inline size_t GetDataCount() const noexcept { return _evolutionData.Count(); }
|
||||
[[nodiscard]] inline const CreatureLib::Library::EffectParameter* GetData(size_t index) const {
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const CreatureLib::Library::EffectParameter>
|
||||
GetData(size_t index) const {
|
||||
return _evolutionData.At(index);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -4,49 +4,44 @@
|
|||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
||||
#include <Arbutils/Random.hpp>
|
||||
#include <CreatureLib/Library/Exceptions/CreatureException.hpp>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include "Nature.hpp"
|
||||
|
||||
namespace PkmnLib::Library {
|
||||
class NatureLibrary {
|
||||
private:
|
||||
ArbUt::Dictionary<ArbUt::CaseInsensitiveConstString, const Nature*> _items;
|
||||
std::unordered_map<ArbUt::CaseInsensitiveConstString, std::unique_ptr<const Nature>> _items;
|
||||
|
||||
public:
|
||||
explicit NatureLibrary(size_t size = 32) noexcept
|
||||
: _items(ArbUt::Dictionary<ArbUt::CaseInsensitiveConstString, const Nature*>(size)) {}
|
||||
explicit NatureLibrary(size_t size = 32) noexcept : _items(size) {}
|
||||
|
||||
~NatureLibrary() {
|
||||
for (auto& kv : _items) {
|
||||
delete kv.second;
|
||||
}
|
||||
}
|
||||
~NatureLibrary() = default;
|
||||
|
||||
inline void LoadNature(const ArbUt::CaseInsensitiveConstString& name, const Nature* nature) {
|
||||
_items.Insert(name, nature);
|
||||
_items.insert({name, std::unique_ptr<const Nature>(nature)});
|
||||
}
|
||||
|
||||
inline const Nature* GetNatureByName(const ArbUt::CaseInsensitiveConstString& name) const {
|
||||
return _items[name];
|
||||
inline ArbUt::BorrowedPtr<const Nature> GetNatureByName(const ArbUt::CaseInsensitiveConstString& name) const {
|
||||
return _items.at(name);
|
||||
}
|
||||
|
||||
inline const ArbUt::CaseInsensitiveConstString&
|
||||
GetRandomNatureName(ArbUt::Random rand = ArbUt::Random()) const {
|
||||
auto i = rand.Get(_items.Count());
|
||||
auto& map = _items.GetStdMap();
|
||||
return std::next(std::begin(map), i)->first;
|
||||
auto i = rand.Get(_items.size());
|
||||
return std::next(std::begin(_items), i)->first;
|
||||
}
|
||||
inline const ArbUt::CaseInsensitiveConstString& GetRandomNatureName(ArbUt::Random* rand) const {
|
||||
auto i = rand->Get(_items.Count());
|
||||
auto& map = _items.GetStdMap();
|
||||
return std::next(std::begin(map), i)->first;
|
||||
auto i = rand->Get(_items.size());
|
||||
return std::next(std::begin(_items), i)->first;
|
||||
}
|
||||
|
||||
inline ArbUt::CaseInsensitiveConstString GetNatureName(const Nature* nature) {
|
||||
inline ArbUt::CaseInsensitiveConstString GetNatureName(ArbUt::BorrowedPtr<const Nature> nature) {
|
||||
for (const auto& v : _items) {
|
||||
if (v.second == nature) {
|
||||
if (v.second.get() == nature.GetRaw()) {
|
||||
return v.first;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
namespace PkmnLib::Library {
|
||||
class PokemonLibrary : public CreatureLib::Library::DataLibrary {
|
||||
private:
|
||||
const NatureLibrary* _natures;
|
||||
std::unique_ptr<const NatureLibrary> _natures;
|
||||
|
||||
public:
|
||||
~PokemonLibrary() override { delete _natures; }
|
||||
~PokemonLibrary() override = default;
|
||||
|
||||
PokemonLibrary(PkmnLib::Library::LibrarySettings* settings, SpeciesLibrary* species, MoveLibrary* moves,
|
||||
ItemLibrary* items, CreatureLib::Library::GrowthRateLibrary* growthRates,
|
||||
|
@ -37,7 +37,7 @@ namespace PkmnLib::Library {
|
|||
return (const std::unique_ptr<const ItemLibrary>&)CreatureLib::Library::DataLibrary::GetItemLibrary();
|
||||
}
|
||||
|
||||
[[nodiscard]] const NatureLibrary* GetNatureLibrary() const noexcept { return _natures; }
|
||||
[[nodiscard]] ArbUt::BorrowedPtr<const NatureLibrary> GetNatureLibrary() const noexcept { return _natures; }
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#ifndef PKMNLIB_POKEMONSPECIES_HPP
|
||||
#define PKMNLIB_POKEMONSPECIES_HPP
|
||||
#include <Arbutils/Memory/UniquePtrList.hpp>
|
||||
#include <CreatureLib/Battling/Models/Creature.hpp>
|
||||
#include "../Evolutions/EvolutionData.hpp"
|
||||
#include "PokemonForme.hpp"
|
||||
|
@ -8,7 +9,7 @@ namespace PkmnLib::Library {
|
|||
class PokemonSpecies : public CreatureLib::Library::CreatureSpecies {
|
||||
private:
|
||||
uint8_t _baseHappiness;
|
||||
ArbUt::List<const EvolutionData*> _evolutions;
|
||||
ArbUt::UniquePtrList<const EvolutionData> _evolutions;
|
||||
|
||||
public:
|
||||
PokemonSpecies(uint16_t id, const ArbUt::CaseInsensitiveConstString& name, const PokemonForme* defaultForme,
|
||||
|
@ -17,11 +18,7 @@ namespace PkmnLib::Library {
|
|||
: CreatureSpecies(id, name, defaultForme, genderRatio, growthRate, captureRate),
|
||||
_baseHappiness(baseHappiness) {}
|
||||
|
||||
~PokemonSpecies() override {
|
||||
for (auto evo : _evolutions) {
|
||||
delete evo;
|
||||
}
|
||||
}
|
||||
~PokemonSpecies() override = default;
|
||||
|
||||
inline uint8_t GetBaseHappiness() const { return _baseHappiness; }
|
||||
|
||||
|
@ -44,7 +41,7 @@ namespace PkmnLib::Library {
|
|||
}
|
||||
|
||||
inline void AddEvolution(const EvolutionData* data) noexcept { _evolutions.Append(data); }
|
||||
const ArbUt::List<const EvolutionData*>& GetEvolutions() const noexcept { return _evolutions; }
|
||||
const ArbUt::UniquePtrList<const EvolutionData>& GetEvolutions() const noexcept { return _evolutions; }
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ TEST_CASE("Able to set and get evolution", "library") {
|
|||
0.5f, "testGrowthRate"_cnc, 100, 100);
|
||||
|
||||
species->AddEvolution(PkmnLib::Library::EvolutionData::CreateLevelEvolution(16, species2));
|
||||
auto evolutions = species->GetEvolutions();
|
||||
auto& evolutions = species->GetEvolutions();
|
||||
REQUIRE(evolutions.Count() == 1);
|
||||
auto evo = evolutions[0];
|
||||
CHECK(evo->GetMethod() == PkmnLib::Library::EvolutionMethod::Level);
|
||||
|
|
Loading…
Reference in New Issue