From 75630c87bdd6672887bb235a1d2cc784ebb1de6e Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sun, 3 Apr 2022 12:18:36 -0700 Subject: [PATCH] CDamageVulnerability: Use matching functions for WeaponHits/Hurts --- Runtime/World/CDamageVulnerability.cpp | 115 ++++++++----------------- 1 file changed, 34 insertions(+), 81 deletions(-) diff --git a/Runtime/World/CDamageVulnerability.cpp b/Runtime/World/CDamageVulnerability.cpp index a85fb7326..227ccd6cc 100644 --- a/Runtime/World/CDamageVulnerability.cpp +++ b/Runtime/World/CDamageVulnerability.cpp @@ -108,9 +108,14 @@ EDeflectType CDamageVulnerability::GetDeflectionType(const CWeaponMode& mode) co return x5c_deflected; } +static inline bool check_hurts(EVulnerability vuln, bool direct) { + return direct == 0 + ? (is_normal_or_weak(vuln) || vuln == EVulnerability::DirectWeak || vuln == EVulnerability::DirectNormal) + : is_normal_or_weak(vuln); +} + bool CDamageVulnerability::WeaponHurts(const CWeaponMode& mode, bool ignoreDirect) const { - EWeaponType weaponType = mode.GetType(); - if (weaponType < EWeaponType::Power || weaponType > EWeaponType::OrangePhazon) { + if (mode.GetType() < EWeaponType::Power || mode.GetType() > EWeaponType::OrangePhazon) { return false; } @@ -118,102 +123,50 @@ bool CDamageVulnerability::WeaponHurts(const CWeaponMode& mode, bool ignoreDirec return true; } - EVulnerability vuln = x0_normal[u32(weaponType)]; - bool normalHurts = ignoreDirect == 0 ? (is_normal_or_weak(vuln) || vuln == EVulnerability::DirectWeak || - vuln == EVulnerability::DirectNormal) - : is_normal_or_weak(vuln); + bool normalHurts = check_hurts(x0_normal[u32(mode.GetType())], ignoreDirect); + bool chargedHurts = + (mode.GetType() < EWeaponType::Bomb) ? check_hurts(x3c_charged[u32(mode.GetType())], ignoreDirect) : true; + bool comboedHurts = + (mode.GetType() < EWeaponType::Bomb) ? check_hurts(x4c_combo[u32(mode.GetType())], ignoreDirect) : true; - bool chargedHurts; - if (weaponType < EWeaponType::Bomb) { - vuln = x3c_charged[u32(weaponType)]; - chargedHurts = ignoreDirect == 0 ? (is_normal_or_weak(vuln) || vuln == EVulnerability::DirectWeak || - vuln == EVulnerability::DirectNormal) - : is_normal_or_weak(vuln); - ; - } else { - chargedHurts = true; + return (normalHurts && !mode.IsCharged() && !mode.IsComboed()) || (chargedHurts && mode.IsCharged()) || + (comboedHurts && mode.IsComboed()); +} + +static inline bool check_hits(EVulnerability vuln, bool direct) { + if (!direct) { + return is_not_deflect(vuln); } - - bool comboedHurts; - if (weaponType < EWeaponType::Bomb) { - vuln = x3c_charged[u32(weaponType)]; - comboedHurts = ignoreDirect == 0 ? (is_normal_or_weak(vuln) || vuln == EVulnerability::DirectWeak || - vuln == EVulnerability::DirectNormal) - : is_normal_or_weak(vuln); - ; - } else { - comboedHurts = true; + if (vuln == EVulnerability::Deflect || + (static_cast(static_cast(vuln) - static_cast(EVulnerability::DirectWeak)) <= + EVulnerability::Normal) || + vuln == EVulnerability::DirectImmune) { + return false; } - - bool result = false; - if ((normalHurts && !mode.IsCharged() && !mode.IsComboed()) || (chargedHurts && mode.IsCharged()) || - (comboedHurts && mode.IsComboed())) { - result = true; - } - - return result; + return true; } bool CDamageVulnerability::WeaponHits(const CWeaponMode& mode, bool checkDirect) const { - const EWeaponType weaponType = mode.GetType(); - if (weaponType < EWeaponType::Power || weaponType > EWeaponType::OrangePhazon) { + if (mode.GetType() < EWeaponType::Power || mode.GetType() > EWeaponType::OrangePhazon) { return false; } if (mode.IsInstantKill()) { return true; } - EVulnerability vuln = x0_normal[u32(weaponType)]; - bool normalHits; - if (!checkDirect) { - normalHits = is_not_deflect(vuln); - } else if (vuln == EVulnerability::Deflect || - (static_cast((u32)vuln - (u32)EVulnerability::DirectWeak) <= EVulnerability::Normal) || - vuln == EVulnerability::DirectImmune) { - normalHits = false; - } else { - normalHits = true; - } - - bool chargedHits; - if (weaponType < EWeaponType::Bomb) { - vuln = x3c_charged[u32(weaponType)]; - if (!checkDirect) { - chargedHits = is_not_deflect(vuln); - } else if (vuln == EVulnerability::Deflect || - (static_cast((u32)vuln - (u32)EVulnerability::DirectWeak) <= EVulnerability::Normal) || - vuln == EVulnerability::DirectImmune) { - chargedHits = false; - } else { - chargedHits = true; - } - } else { - chargedHits = true; - } - - bool comboedHits; - if (weaponType < EWeaponType::Bomb) { - vuln = x4c_combo[u32(weaponType)]; - if (!checkDirect) { - comboedHits = is_not_deflect(vuln); - } else if (vuln == EVulnerability::Deflect || - (static_cast((u32)vuln - (u32)EVulnerability::DirectWeak) <= EVulnerability::Normal || - vuln == EVulnerability::DirectImmune)) { - comboedHits = false; - } else { - comboedHits = true; - } - } else { - comboedHits = true; - } - + bool normalHits = check_hits(x0_normal[u32(mode.GetType())], checkDirect); + bool chargedHits = + mode.GetType() < EWeaponType::Bomb ? check_hits(x3c_charged[u32(mode.GetType())], checkDirect) : true; + bool comboedHits = + mode.GetType() < EWeaponType::Bomb ? check_hits(x4c_combo[u32(mode.GetType())], checkDirect) : true; bool result = false; if ((normalHits && !mode.IsCharged() && !mode.IsComboed()) || (chargedHits && mode.IsCharged()) || (comboedHits && mode.IsComboed())) { result = true; } - return result; + return (normalHits && !mode.IsCharged() && !mode.IsComboed()) || (chargedHits && mode.IsCharged()) || + (comboedHits && mode.IsComboed()); } inline EVulnerability direct_to_normal(EVulnerability vuln) { @@ -233,7 +186,7 @@ EVulnerability CDamageVulnerability::GetVulnerability(const CWeaponMode& mode, b if (mode.GetType() < EWeaponType::Power || mode.GetType() > EWeaponType::OrangePhazon) { return EVulnerability::Deflect; } - + if (mode.IsInstantKill()) { return EVulnerability::Normal; }