diff --git a/CInterface/Battling/Pokemon.cpp b/CInterface/Battling/Pokemon.cpp index c1be863..7c52e24 100644 --- a/CInterface/Battling/Pokemon.cpp +++ b/CInterface/Battling/Pokemon.cpp @@ -14,10 +14,11 @@ export Pokemon* PkmnLib_Pokemon_Construct(const BattleLibrary* library, const Pk std::string nick(nickname); std::vector cMoves(moves, moves + moveCount); - return new Pokemon(library, species, forme, level, experience, uid, gender, coloring, heldItem, nick, - CreatureLib::Library::TalentIndex(hiddenAbility, abilityIndex), cMoves, - CreatureLib::Library::StatisticSet(hpIv, attIv, defIv, sAtIv, sDeIv, spIv), - CreatureLib::Library::StatisticSet(hpEv, attEv, defEv, sAtEv, sDeEv, spEv), nature); + return new Pokemon( + 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); }; export void PkmnLib_Pokemon_Destruct(const Pokemon* p) { delete p; } @@ -28,10 +29,21 @@ SIMPLE_GET_FUNC_SMART_PTR(Pokemon, GetNature, const PkmnLib::Library::Nature*) export uint8_t 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) { 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 const char* PkmnLib_Pokemon_GetStatusName(Pokemon* p) { return p->GetStatusName().c_str(); } \ No newline at end of file +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); } diff --git a/src/Battling/Pokemon/CreatePokemon.cpp b/src/Battling/Pokemon/CreatePokemon.cpp index 15898d2..e0d7570 100644 --- a/src/Battling/Pokemon/CreatePokemon.cpp +++ b/src/Battling/Pokemon/CreatePokemon.cpp @@ -81,8 +81,10 @@ namespace PkmnLib::Battling { else 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); + auto ivs = CreatureLib::Library::ClampedStatisticSet(_ivHp, _ivAttack, _ivDefense, _ivSpAtt, + _ivSpDef, _ivSpeed); + auto evs = CreatureLib::Library::ClampedStatisticSet(_evHp, _evAttack, _evDefense, _evSpAtt, + _evSpDef, _evSpeed); if (_nature.IsEmpty()) { _nature = _library->GetNatureLibrary()->GetRandomNatureName(rand); diff --git a/src/Battling/Pokemon/Pokemon.hpp b/src/Battling/Pokemon/Pokemon.hpp index 3f2a2da..9b8ff47 100644 --- a/src/Battling/Pokemon/Pokemon.hpp +++ b/src/Battling/Pokemon/Pokemon.hpp @@ -10,11 +10,12 @@ namespace PkmnLib::Battling { class Pokemon : public CreatureLib::Battling::Creature { private: - CreatureLib::Library::StatisticSet _individualValues; - CreatureLib::Library::StatisticSet _effortValues; + CreatureLib::Library::ClampedStatisticSet _individualValues; + CreatureLib::Library::ClampedStatisticSet _effortValues; ArbUt::BorrowedPtr _nature; std::unique_ptr _statusScript = nullptr; + uint8_t _friendship = 0; public: Pokemon(ArbUt::BorrowedPtr library, @@ -24,15 +25,16 @@ namespace PkmnLib::Battling { ArbUt::BorrowedPtr heldItem, const std::string& nickname, const CreatureLib::Library::TalentIndex& talent, const std::vector& moves, - CreatureLib::Library::StatisticSet individualValues, - CreatureLib::Library::StatisticSet effortValues, + CreatureLib::Library::ClampedStatisticSet individualValues, + CreatureLib::Library::ClampedStatisticSet effortValues, ArbUt::BorrowedPtr nature, bool allowedExperienceGain = true) : CreatureLib::Battling::Creature(library.ForceAs(), species.ForceAs(), forme.As(), level, experience, uid, gender, coloring, heldItem.As(), nickname, talent, moves, allowedExperienceGain), - _individualValues(individualValues), _effortValues(effortValues), _nature(nature) {} + _individualValues(individualValues), _effortValues(effortValues), _nature(nature), + _friendship(species->GetBaseHappiness()) {} const ArbUt::BorrowedPtr GetForme() const { return _variant.As(); @@ -48,9 +50,15 @@ namespace PkmnLib::Battling { inline uint8_t GetIndividualValue(CreatureLib::Library::Statistic stat) const { return _individualValues.GetStat(stat); } + inline void SetIndividualValue(CreatureLib::Library::Statistic stat, uint8_t value) { + return _individualValues.SetStat(stat, value); + } inline uint8_t GetEffortValue(CreatureLib::Library::Statistic stat) const { return _effortValues.GetStat(stat); } + inline void SetEffortValue(CreatureLib::Library::Statistic stat, uint8_t value) { + return _effortValues.SetStat(stat, value); + } inline ArbUt::BorrowedPtr GetPokemonSpecies() const noexcept { return _species.As(); @@ -66,6 +74,19 @@ namespace PkmnLib::Battling { return ArbUt::StringView::EmptyString(); return _statusScript->GetName(); } + + uint8_t GetFriendship() const noexcept { return _friendship; } + void SetFriendship(uint8_t value) noexcept { _friendship = value; } + void ChangeFriendship(int8_t amount) noexcept { + uint8_t newValue; + if (__builtin_add_overflow(_friendship, amount, &newValue)) { + if (amount < 0) + newValue = 0; + else + newValue = 255; + } + _friendship = newValue; + } }; }