Setters for IVs and EVs.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-08-08 17:52:57 +02:00
parent 66aea09e80
commit 2a884a0a8b
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
3 changed files with 47 additions and 12 deletions

View File

@ -14,10 +14,11 @@ export Pokemon* PkmnLib_Pokemon_Construct(const BattleLibrary* library, const Pk
std::string nick(nickname);
std::vector<CreatureLib::Battling::LearnedAttack*> cMoves(moves, moves + moveCount);
return new Pokemon(library, species, forme, level, experience, uid, gender, coloring, heldItem, nick,
return new Pokemon(
library, species, forme, level, experience, uid, gender, coloring, heldItem, nick,
CreatureLib::Library::TalentIndex(hiddenAbility, abilityIndex), cMoves,
CreatureLib::Library::StatisticSet<uint8_t>(hpIv, attIv, defIv, sAtIv, sDeIv, spIv),
CreatureLib::Library::StatisticSet<uint8_t>(hpEv, attEv, defEv, sAtEv, sDeEv, spEv), nature);
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 31>(hpIv, attIv, defIv, sAtIv, sDeIv, spIv),
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 252>(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(); }
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); }

View File

@ -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<uint8_t, 0, 31>(_ivHp, _ivAttack, _ivDefense, _ivSpAtt,
_ivSpDef, _ivSpeed);
auto evs = CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 252>(_evHp, _evAttack, _evDefense, _evSpAtt,
_evSpDef, _evSpeed);
if (_nature.IsEmpty()) {
_nature = _library->GetNatureLibrary()->GetRandomNatureName(rand);

View File

@ -10,11 +10,12 @@
namespace PkmnLib::Battling {
class Pokemon : public CreatureLib::Battling::Creature {
private:
CreatureLib::Library::StatisticSet<uint8_t> _individualValues;
CreatureLib::Library::StatisticSet<uint8_t> _effortValues;
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 31> _individualValues;
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 252> _effortValues;
ArbUt::BorrowedPtr<const PkmnLib::Library::Nature> _nature;
std::unique_ptr<CreatureLib::Battling::Script> _statusScript = nullptr;
uint8_t _friendship = 0;
public:
Pokemon(ArbUt::BorrowedPtr<const BattleLibrary> library,
@ -24,15 +25,16 @@ namespace PkmnLib::Battling {
ArbUt::BorrowedPtr<const Library::Item> heldItem, const std::string& nickname,
const CreatureLib::Library::TalentIndex& talent,
const std::vector<CreatureLib::Battling::LearnedAttack*>& moves,
CreatureLib::Library::StatisticSet<uint8_t> individualValues,
CreatureLib::Library::StatisticSet<uint8_t> effortValues,
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 31> individualValues,
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 252> 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),
_individualValues(individualValues), _effortValues(effortValues), _nature(nature) {}
_individualValues(individualValues), _effortValues(effortValues), _nature(nature),
_friendship(species->GetBaseHappiness()) {}
const ArbUt::BorrowedPtr<const Library::PokemonForme> GetForme() const {
return _variant.As<const Library::PokemonForme>();
@ -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<const PkmnLib::Library::PokemonSpecies> GetPokemonSpecies() const noexcept {
return _species.As<const PkmnLib::Library::PokemonSpecies>();
@ -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;
}
};
}