From e23165d48926a94df4c3be13bcced2eecb6b1a6a Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 25 Apr 2020 16:59:27 +0200 Subject: [PATCH] Update to latest CreatureLib, improved DamageLibrary performance. --- src/Battling/Library/DamageLibrary.cpp | 31 +++++++++++++------------- src/Battling/Library/DamageLibrary.hpp | 12 ++++++---- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/Battling/Library/DamageLibrary.cpp b/src/Battling/Library/DamageLibrary.cpp index 0673e24..f76579e 100644 --- a/src/Battling/Library/DamageLibrary.cpp +++ b/src/Battling/Library/DamageLibrary.cpp @@ -1,29 +1,31 @@ #include "DamageLibrary.hpp" #include "../Pokemon/Pokemon.hpp" +using HitData = const CreatureLib::Battling::ExecutingAttack::HitData; + uint32_t PkmnLib::Battling::DamageLibrary::GetDamage(CreatureLib::Battling::ExecutingAttack* attack, - CreatureLib::Battling::Creature* target, uint8_t hitIndex) const { + CreatureLib::Battling::Creature* target, uint8_t hitIndex, + const HitData& hitData) const { auto levelMod = static_cast(2 * attack->GetUser()->GetLevel()); - auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex); - auto bp = hit.GetBasePower(); - auto statMod = GetStatModifier(attack, target, hitIndex); + auto bp = hitData.GetBasePower(); + auto statMod = GetStatModifier(attack, target, hitIndex, hitData); // HOOK: Modify stat modifier int damage = static_cast((((levelMod * static_cast(bp) * statMod) / 50) + 2) * - GetDamageModifier(attack, target, hitIndex)); + GetDamageModifier(attack, target, hitIndex, hitData)); // HOOK: Override damage return damage; } uint8_t PkmnLib::Battling::DamageLibrary::GetBasePower(CreatureLib::Battling::ExecutingAttack* attack, - CreatureLib::Battling::Creature* target, uint8_t hitIndex) const { + CreatureLib::Battling::Creature* target, uint8_t hitIndex, + const HitData& hitData) const { auto bp = attack->GetAttack()->GetAttack()->GetBasePower(); // HOOK: modify base power. return bp; } float PkmnLib::Battling::DamageLibrary::GetStatModifier(CreatureLib::Battling::ExecutingAttack* attack, - CreatureLib::Battling::Creature* target, - uint8_t hitIndex) const { + CreatureLib::Battling::Creature* target, uint8_t hitIndex, + const HitData& hitData) const { auto user = attack->GetUser(); // HOOK: allow overriding for which users stat we use. - auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex); CreatureLib::Library::Statistic offensiveStat; CreatureLib::Library::Statistic defensiveStat; auto learnedMove = static_cast(attack->GetAttack()); @@ -36,9 +38,9 @@ float PkmnLib::Battling::DamageLibrary::GetStatModifier(CreatureLib::Battling::E defensiveStat = Library::Statistic::SpecialDefense; } - auto bypassDefensive = hit.IsCritical() && target->GetStatBoost(defensiveStat) > 0; + auto bypassDefensive = hitData.IsCritical() && target->GetStatBoost(defensiveStat) > 0; // HOOK: allow bypassing defensive stat modifiers. - auto bypassOffensive = hit.IsCritical() && user->GetStatBoost(offensiveStat) < 0; + auto bypassOffensive = hitData.IsCritical() && user->GetStatBoost(offensiveStat) < 0; // HOOK: Allow bypassing offensive stat modifiers. float offensiveValue; @@ -58,11 +60,10 @@ float PkmnLib::Battling::DamageLibrary::GetStatModifier(CreatureLib::Battling::E return offensiveValue / defensiveValue; } float PkmnLib::Battling::DamageLibrary::GetDamageModifier(CreatureLib::Battling::ExecutingAttack* attack, - CreatureLib::Battling::Creature* target, - uint8_t hitIndex) const { + CreatureLib::Battling::Creature* target, uint8_t hitIndex, + const HitData& hitData) const { float mod = 1; - auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex); - mod *= hit.GetEffectiveness(); + mod *= hitData.GetEffectiveness(); // HOOK: Modify damage modifier. return mod; } diff --git a/src/Battling/Library/DamageLibrary.hpp b/src/Battling/Library/DamageLibrary.hpp index 8ef3e48..ddd14a0 100644 --- a/src/Battling/Library/DamageLibrary.hpp +++ b/src/Battling/Library/DamageLibrary.hpp @@ -6,14 +6,18 @@ namespace PkmnLib::Battling { class DamageLibrary : public CreatureLib::Battling::DamageLibrary { public: uint32_t GetDamage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, - uint8_t hitIndex) const override; + uint8_t hitIndex, + const CreatureLib::Battling::ExecutingAttack::HitData& hitData) const override; uint8_t GetBasePower(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, - uint8_t hitIndex) const override; + uint8_t hitIndex, + const CreatureLib::Battling::ExecutingAttack::HitData& hitData) const override; float GetStatModifier(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, - uint8_t hitIndex) const override; + uint8_t hitIndex, + const CreatureLib::Battling::ExecutingAttack::HitData& hitData) const override; float GetDamageModifier(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, - uint8_t hitIndex) const override; + uint8_t hitIndex, + const CreatureLib::Battling::ExecutingAttack::HitData& hitData) const override; }; }