CDamageVulnerability: Use matching functions for WeaponHits/Hurts

This commit is contained in:
Phillip Stephens 2022-04-03 12:18:36 -07:00
parent 6c449ca146
commit 75630c87bd
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
1 changed files with 34 additions and 81 deletions

View File

@ -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<EVulnerability>(static_cast<u32>(vuln) - static_cast<u32>(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<EVulnerability>((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<EVulnerability>((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<EVulnerability>((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;
}