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