metaforce/Runtime/World/CDamageVulnerability.cpp

209 lines
8.2 KiB
C++
Raw Normal View History

#include "Runtime/World/CDamageVulnerability.hpp"
2021-04-10 08:42:06 +00:00
namespace metaforce {
2020-05-27 17:02:20 +00:00
const CDamageVulnerability CDamageVulnerability::sNormalVulnerability(
2017-03-01 03:42:06 +00:00
EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal,
EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal,
EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal,
EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal,
EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal,
EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EDeflectType::None);
2017-03-01 03:42:06 +00:00
2020-05-27 17:02:20 +00:00
const CDamageVulnerability CDamageVulnerability::sImmuneVulnerability(
2018-02-12 05:30:21 +00:00
EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect,
EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect,
EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect,
EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect,
EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect,
EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EDeflectType::None);
2020-05-27 17:02:20 +00:00
const CDamageVulnerability CDamageVulnerability::sReflectVulnerability(
2018-02-12 05:30:21 +00:00
EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect,
EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect,
EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect,
EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect,
EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect,
EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EDeflectType::One);
2017-03-01 03:42:06 +00:00
2020-05-27 17:02:20 +00:00
const CDamageVulnerability CDamageVulnerability::sPassThroughVulnerability(
2017-03-01 03:42:06 +00:00
EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough,
EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough,
EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough,
EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough,
EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough,
EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough, EDeflectType::None);
2021-05-09 03:14:38 +00:00
static constexpr bool is_deflect_direct(EVulnerability vuln) {
2022-03-31 06:40:11 +00:00
return vuln == EVulnerability::Deflect ||
(EVulnerability(u32(vuln) - u32(EVulnerability::DirectWeak)) < EVulnerability::Deflect) ||
vuln == EVulnerability::DirectImmune;
}
static constexpr bool is_normal_or_weak(EVulnerability vuln) {
2021-05-09 03:14:38 +00:00
return vuln == EVulnerability::Weak || vuln == EVulnerability::Normal;
}
2021-06-07 19:29:18 +00:00
static constexpr bool is_not_deflect(EVulnerability vuln) { return vuln != EVulnerability::Deflect; }
2018-11-19 01:19:44 +00:00
2018-12-08 05:30:43 +00:00
void CDamageVulnerability::ConstructNew(CInputStream& in, int propCount) {
propCount -= 3;
2021-05-09 03:14:38 +00:00
for (int i = 0; i < std::min(propCount, 15); ++i) {
x0_normal[i] = EVulnerability(in.ReadLong());
2021-05-09 03:14:38 +00:00
}
2018-12-08 05:30:43 +00:00
if (propCount < 15) {
2021-05-09 03:14:38 +00:00
for (int i = propCount; i < 15; ++i) {
x0_normal[i] = EVulnerability::Deflect;
}
2018-12-08 05:30:43 +00:00
}
2021-05-09 03:14:38 +00:00
for (int i = 15; i < propCount; ++i) {
in.ReadLong();
2021-05-09 03:14:38 +00:00
}
x5c_deflected = EDeflectType(in.ReadLong());
in.ReadLong();
2021-05-09 03:14:38 +00:00
for (int i = 0; i < 4; ++i) {
x3c_charged[i] = EVulnerability(in.ReadLong());
2021-05-09 03:14:38 +00:00
}
2018-12-08 05:30:43 +00:00
x60_chargedDeflected = EDeflectType(in.ReadLong());
in.ReadLong();
2021-05-09 03:14:38 +00:00
for (int i = 0; i < 4; ++i) {
x4c_combo[i] = EVulnerability(in.ReadLong());
2021-05-09 03:14:38 +00:00
}
x64_comboDeflected = EDeflectType(in.ReadLong());
}
2018-12-08 05:30:43 +00:00
CDamageVulnerability::CDamageVulnerability(CInputStream& in) {
u32 propCount = in.ReadLong();
2018-12-08 05:30:43 +00:00
if (propCount == 11) {
2021-05-09 03:14:38 +00:00
for (int i = 0; i < 15; ++i) {
x0_normal[i] = EVulnerability(in.ReadLong());
2021-05-09 03:14:38 +00:00
}
2018-12-08 05:30:43 +00:00
x5c_deflected = EDeflectType(in.ReadLong());
2021-05-09 03:14:38 +00:00
x3c_charged[0] = x0_normal[0];
x4c_combo[0] = x0_normal[0];
x3c_charged[1] = x0_normal[1];
x4c_combo[1] = x0_normal[1];
x3c_charged[2] = x0_normal[2];
x4c_combo[2] = x0_normal[2];
x3c_charged[3] = x0_normal[3];
x4c_combo[3] = x0_normal[3];
} else {
2018-12-08 05:30:43 +00:00
ConstructNew(in, propCount);
2021-05-09 03:14:38 +00:00
}
}
EDeflectType CDamageVulnerability::GetDeflectionType(const CWeaponMode& mode) const {
2021-05-09 03:14:38 +00:00
if (mode.IsCharged()) {
2018-12-08 05:30:43 +00:00
return x60_chargedDeflected;
2021-05-09 03:14:38 +00:00
}
if (mode.IsComboed()) {
2018-12-08 05:30:43 +00:00
return x64_comboDeflected;
2021-05-09 03:14:38 +00:00
}
2018-12-08 05:30:43 +00:00
return x5c_deflected;
2017-03-01 03:42:06 +00:00
}
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);
}
2018-12-08 05:30:43 +00:00
bool CDamageVulnerability::WeaponHurts(const CWeaponMode& mode, bool ignoreDirect) const {
if (mode.GetType() < EWeaponType::Power || mode.GetType() > EWeaponType::OrangePhazon) {
2018-12-08 05:30:43 +00:00
return false;
2021-05-09 03:14:38 +00:00
}
2021-05-09 03:14:38 +00:00
if (mode.IsInstantKill()) {
2018-12-08 05:30:43 +00:00
return true;
2021-05-09 03:14:38 +00:00
}
2018-12-08 05:30:43 +00:00
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;
return (normalHurts && !mode.IsCharged() && !mode.IsComboed()) || (chargedHurts && mode.IsCharged()) ||
(comboedHurts && mode.IsComboed());
}
2018-12-08 05:30:43 +00:00
static inline bool check_hits(EVulnerability vuln, bool direct) {
if (!direct) {
return is_not_deflect(vuln);
2021-05-09 03:14:38 +00:00
}
if (vuln == EVulnerability::Deflect ||
(static_cast<EVulnerability>(static_cast<u32>(vuln) - static_cast<u32>(EVulnerability::DirectWeak)) <=
EVulnerability::Normal) ||
vuln == EVulnerability::DirectImmune) {
return false;
2018-12-08 05:30:43 +00:00
}
return true;
}
2018-12-08 05:30:43 +00:00
bool CDamageVulnerability::WeaponHits(const CWeaponMode& mode, bool checkDirect) const {
if (mode.GetType() < EWeaponType::Power || mode.GetType() > EWeaponType::OrangePhazon) {
return false;
2020-05-17 16:25:04 +00:00
}
if (mode.IsInstantKill()) {
2018-12-08 05:30:43 +00:00
return true;
2020-05-17 16:25:04 +00:00
}
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;
2020-05-17 16:25:04 +00:00
}
2021-05-09 03:14:38 +00:00
return (normalHits && !mode.IsCharged() && !mode.IsComboed()) || (chargedHits && mode.IsCharged()) ||
(comboedHits && mode.IsComboed());
}
inline EVulnerability direct_to_normal(EVulnerability vuln) {
if (vuln == EVulnerability::DirectWeak) {
return EVulnerability::Weak;
}
if (vuln == EVulnerability::DirectNormal) {
return EVulnerability::Normal;
}
if (vuln == EVulnerability::DirectImmune) {
return EVulnerability::Immune;
}
return vuln;
}
2018-12-08 05:30:43 +00:00
EVulnerability CDamageVulnerability::GetVulnerability(const CWeaponMode& mode, bool ignoreDirect) const {
if (mode.GetType() < EWeaponType::Power || mode.GetType() > EWeaponType::OrangePhazon) {
2018-12-08 05:30:43 +00:00
return EVulnerability::Deflect;
}
if (mode.IsInstantKill()) {
2018-12-08 05:30:43 +00:00
return EVulnerability::Normal;
}
EVulnerability vuln = x0_normal[u32(mode.GetType())];
EWeaponType type = mode.GetType();
2018-12-08 05:30:43 +00:00
if (mode.IsCharged()) {
vuln = type < EWeaponType::Bomb ? x3c_charged[u32(type)] : EVulnerability::Normal;
2018-12-08 05:30:43 +00:00
}
2018-12-08 05:30:43 +00:00
if (mode.IsComboed()) {
vuln = type < EWeaponType::Bomb ? x4c_combo[u32(type)] : EVulnerability::Normal;
2018-12-08 05:30:43 +00:00
}
if (ignoreDirect == 1) {
return vuln;
}
return direct_to_normal(vuln);
}
2021-04-10 08:42:06 +00:00
} // namespace metaforce