From 94de55f933d8c75b91babcf9589a5115b4ac7695 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 19 Jun 2021 12:44:05 +0200 Subject: [PATCH] Adds Pokemon::IsEgg function, make eggs not usable in battle. --- CInterface/Battling/Pokemon.cpp | 35 ++++++++++++++++++-------------- src/Battling/Pokemon/Pokemon.cpp | 6 ++++++ src/Battling/Pokemon/Pokemon.hpp | 9 ++++++-- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/CInterface/Battling/Pokemon.cpp b/CInterface/Battling/Pokemon.cpp index 36eb848..1f9fd73 100644 --- a/CInterface/Battling/Pokemon.cpp +++ b/CInterface/Battling/Pokemon.cpp @@ -2,13 +2,15 @@ #include "../Core.hpp" using namespace PkmnLib::Battling; -export uint8_t PkmnLib_Pokemon_Construct( - Pokemon*& out, const BattleLibrary* library, const PkmnLib::Library::PokemonSpecies* species, - const PkmnLib::Library::PokemonForme* forme, uint8_t level, uint32_t experience, uint32_t uid, - CreatureLib::Library::Gender gender, uint8_t coloring, const PkmnLib::Library::Item* heldItem, const char* nickname, - bool hiddenAbility, uint8_t abilityIndex, CreatureLib::Battling::LearnedAttack* const* moves, size_t moveCount, - uint8_t hpIv, uint8_t attIv, uint8_t defIv, uint8_t sAtIv, uint8_t sDeIv, 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) { +export uint8_t +PkmnLib_Pokemon_Construct(Pokemon*& out, const BattleLibrary* library, const PkmnLib::Library::PokemonSpecies* species, + const PkmnLib::Library::PokemonForme* forme, uint8_t level, uint32_t experience, uint32_t uid, + CreatureLib::Library::Gender gender, uint8_t coloring, const PkmnLib::Library::Item* heldItem, + const char* nickname, bool hiddenAbility, uint8_t abilityIndex, + CreatureLib::Battling::LearnedAttack* const* moves, size_t moveCount, uint8_t hpIv, + uint8_t attIv, uint8_t defIv, uint8_t sAtIv, uint8_t sDeIv, 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, bool allowedExperienceGain, bool isEgg) { Try({ if (nickname == nullptr) { nickname = ""; @@ -20,7 +22,8 @@ export uint8_t PkmnLib_Pokemon_Construct( library, species, forme, level, experience, uid, gender, coloring, heldItem, nick, CreatureLib::Library::TalentIndex(hiddenAbility, abilityIndex), cMoves, CreatureLib::Library::ClampedStatisticSet(hpIv, attIv, defIv, sAtIv, sDeIv, spIv), - CreatureLib::Library::ClampedStatisticSet(hpEv, attEv, defEv, sAtEv, sDeEv, spEv), nature); + CreatureLib::Library::ClampedStatisticSet(hpEv, attEv, defEv, sAtEv, sDeEv, spEv), nature, + allowedExperienceGain, isEgg); }) }; @@ -29,29 +32,31 @@ export void PkmnLib_Pokemon_Destruct(const Pokemon* p) { delete p; } SIMPLE_GET_FUNC(Pokemon, IsShiny, bool) SIMPLE_GET_FUNC_SMART_PTR(Pokemon, GetNature, const PkmnLib::Library::Nature*) -export uint8_t PkmnLib_Pokemon_GetIndividualValue(const Pokemon* p, CreatureLib::Library::Statistic stat) { +export u8 PkmnLib_Pokemon_GetIndividualValue(const Pokemon* p, CreatureLib::Library::Statistic stat) { return p->GetIndividualValue(stat); } export void PkmnLib_Pokemon_SetIndividualValue(Pokemon* p, CreatureLib::Library::Statistic stat, uint8_t value) { p->SetIndividualValue(stat, value); } -export uint8_t PkmnLib_Pokemon_GetEffortValue(const Pokemon* p, CreatureLib::Library::Statistic stat) { +export u8 PkmnLib_Pokemon_GetEffortValue(const Pokemon* p, CreatureLib::Library::Statistic stat) { return p->GetEffortValue(stat); } export void PkmnLib_Pokemon_SetEffortValue(Pokemon* p, CreatureLib::Library::Statistic stat, uint8_t value) { p->SetEffortValue(stat, value); } -export uint8_t PkmnLib_Pokemon_SetStatus(Pokemon* p, const char* name) { Try(p->SetStatus(ArbUt::StringView(name))); }; -export uint8_t PkmnLib_Pokemon_ClearStatus(Pokemon* p) { Try(p->ClearStatus()); }; +export u8 PkmnLib_Pokemon_SetStatus(Pokemon* p, const char* name) { Try(p->SetStatus(ArbUt::StringView(name))); }; +export u8 PkmnLib_Pokemon_ClearStatus(Pokemon* p) { Try(p->ClearStatus()); }; export const char* PkmnLib_Pokemon_GetStatusName(Pokemon* p) { return p->GetStatusName().c_str(); } SIMPLE_GET_FUNC(Pokemon, GetFriendship, uint8_t) -export void PkmnLib_Pokemon_SetFriendship(Pokemon* p, uint8_t value) { p->SetFriendship(value); } -export void PkmnLib_Pokemon_ChangeFriendship(Pokemon* p, int8_t amount) { p->ChangeFriendship(amount); } +export void PkmnLib_Pokemon_SetFriendship(Pokemon* p, u8 value) { p->SetFriendship(value); } +export void PkmnLib_Pokemon_ChangeFriendship(Pokemon* p, i8 amount) { p->ChangeFriendship(amount); } +SIMPLE_GET_FUNC(Pokemon, IsEgg, bool) -export uint8_t PkmnLib_Pokemon_Evolve(Pokemon* p, const PkmnLib::Library::PokemonSpecies* species, + +export u8 PkmnLib_Pokemon_Evolve(Pokemon* p, const PkmnLib::Library::PokemonSpecies* species, const PkmnLib::Library::PokemonForme* forme) { Try(p->Evolve(species, forme);) } \ No newline at end of file diff --git a/src/Battling/Pokemon/Pokemon.cpp b/src/Battling/Pokemon/Pokemon.cpp index 55efc28..8d7d4f8 100644 --- a/src/Battling/Pokemon/Pokemon.cpp +++ b/src/Battling/Pokemon/Pokemon.cpp @@ -91,3 +91,9 @@ CreatureLib::Battling::Creature* PkmnLib::Battling::Pokemon::Clone() const { return c; } +bool PkmnLib::Battling::Pokemon::IsUsable() const noexcept { + if (IsEgg()) { + return false; + } + return Creature::IsUsable(); +} diff --git a/src/Battling/Pokemon/Pokemon.hpp b/src/Battling/Pokemon/Pokemon.hpp index bdd0f4c..7dba165 100644 --- a/src/Battling/Pokemon/Pokemon.hpp +++ b/src/Battling/Pokemon/Pokemon.hpp @@ -16,6 +16,7 @@ namespace PkmnLib::Battling { ArbUt::BorrowedPtr _nature; std::unique_ptr _statusScript = nullptr; uint8_t _friendship = 0; + bool _isEgg; public: Pokemon(ArbUt::BorrowedPtr library, @@ -27,14 +28,15 @@ namespace PkmnLib::Battling { const std::vector& moves, CreatureLib::Library::ClampedStatisticSet individualValues, CreatureLib::Library::ClampedStatisticSet effortValues, - ArbUt::BorrowedPtr nature, bool allowedExperienceGain = true) + ArbUt::BorrowedPtr nature, bool allowedExperienceGain = true, + bool isEgg = false) : CreatureLib::Battling::Creature( library.ForceAs(), species.ForceAs(), forme.ForceAs(), level, experience, uid, gender, coloring, heldItem.ForceAs(), nickname, talent, moves, allowedExperienceGain), _individualValues(individualValues), _effortValues(effortValues), _nature(nature), - _friendship(species->GetBaseHappiness()) {} + _friendship(species->GetBaseHappiness()), _isEgg(isEgg) {} const ArbUt::BorrowedPtr GetForme() const { return _variant.ForceAs(); @@ -59,6 +61,7 @@ namespace PkmnLib::Battling { inline void SetEffortValue(CreatureLib::Library::Statistic stat, uint8_t value) { return _effortValues.SetStat(stat, value); } + inline bool IsEgg() const noexcept { return _isEgg; } inline ArbUt::BorrowedPtr GetPokemonSpecies() const noexcept { return _species.As(); @@ -88,6 +91,8 @@ namespace PkmnLib::Battling { _friendship = newValue; } + bool IsUsable() const noexcept override; + Creature* Clone() const override; }; }