2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CDamageVulnerability.hpp"
|
2017-02-10 05:43:07 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2017-02-10 05:43:07 +00:00
|
|
|
|
2020-04-26 05:02:02 +00:00
|
|
|
constexpr 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,
|
2019-07-16 15:54:07 +00:00
|
|
|
EVulnerability::Normal, EVulnerability::Normal, EVulnerability::Normal, EDeflectType::None);
|
2017-03-01 03:42:06 +00:00
|
|
|
|
2020-04-26 05:02:02 +00:00
|
|
|
constexpr 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,
|
2019-07-16 15:54:07 +00:00
|
|
|
EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EDeflectType::None);
|
2020-03-26 07:30:54 +00:00
|
|
|
|
2020-04-26 05:02:02 +00:00
|
|
|
constexpr 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,
|
2020-03-26 07:30:54 +00:00
|
|
|
EVulnerability::Deflect, EVulnerability::Deflect, EVulnerability::Deflect, EDeflectType::One);
|
2017-03-01 03:42:06 +00:00
|
|
|
|
2020-04-26 05:02:02 +00:00
|
|
|
constexpr 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,
|
2019-07-16 15:54:07 +00:00
|
|
|
EVulnerability::PassThrough, EVulnerability::PassThrough, EVulnerability::PassThrough, EDeflectType::None);
|
2017-02-10 05:43:07 +00:00
|
|
|
|
2020-04-26 04:53:50 +00:00
|
|
|
static constexpr bool is_not_immune(EVulnerability vuln) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return vuln != EVulnerability::Immune && vuln != EVulnerability::DirectImmune;
|
2017-02-10 05:43:07 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 04:53:50 +00:00
|
|
|
static constexpr bool is_normal_or_weak(EVulnerability vuln) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return vuln == EVulnerability::Normal || vuln == EVulnerability::Weak;
|
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;
|
|
|
|
EVulnerability* vulns = &x0_power;
|
|
|
|
for (int i = 0; i < std::min(propCount, 15); ++i)
|
|
|
|
vulns[i] = EVulnerability(in.readUint32Big());
|
2017-02-10 05:43:07 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (propCount < 15) {
|
|
|
|
for (int i = propCount; i < 15; ++i)
|
|
|
|
vulns[i] = EVulnerability::Deflect;
|
|
|
|
}
|
2017-02-10 05:43:07 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (int i = 15; i < propCount; ++i)
|
2017-02-10 05:43:07 +00:00
|
|
|
in.readUint32Big();
|
|
|
|
|
2019-07-16 15:54:07 +00:00
|
|
|
x5c_deflected = EDeflectType(in.readUint32Big());
|
2018-12-08 05:30:43 +00:00
|
|
|
EVulnerability* vulns2 = &x3c_chargedPower;
|
|
|
|
in.readUint32Big();
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
|
|
vulns2[i] = EVulnerability(in.readUint32Big());
|
|
|
|
|
2019-07-16 15:54:07 +00:00
|
|
|
x60_chargedDeflected = EDeflectType(in.readUint32Big());
|
2018-12-08 05:30:43 +00:00
|
|
|
EVulnerability* vulns3 = &x4c_superMissile;
|
|
|
|
in.readUint32Big();
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
|
|
vulns3[i] = EVulnerability(in.readUint32Big());
|
2017-02-10 05:43:07 +00:00
|
|
|
|
2019-07-16 15:54:07 +00:00
|
|
|
x64_comboDeflected = EDeflectType(in.readUint32Big());
|
2017-02-10 05:43:07 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CDamageVulnerability::CDamageVulnerability(CInputStream& in) {
|
|
|
|
u32 propCount = in.readUint32Big();
|
|
|
|
if (propCount == 11) {
|
|
|
|
EVulnerability* vulns = &x0_power;
|
|
|
|
for (int i = 0; i < 15; ++i)
|
|
|
|
vulns[i] = EVulnerability(in.readUint32Big());
|
|
|
|
|
|
|
|
if (propCount == 15)
|
2019-07-16 15:54:07 +00:00
|
|
|
x5c_deflected = EDeflectType::None;
|
2017-02-10 05:43:07 +00:00
|
|
|
else
|
2019-07-16 15:54:07 +00:00
|
|
|
x5c_deflected = EDeflectType(in.readUint32Big());
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
x3c_chargedPower = x0_power;
|
|
|
|
x4c_superMissile = x0_power;
|
|
|
|
x40_chargedIce = x4_ice;
|
|
|
|
x50_iceSpreader = x4_ice;
|
|
|
|
x44_chargedWave = x8_wave;
|
|
|
|
x54_wavebuster = x8_wave;
|
|
|
|
x48_chargedPlasma = xc_plasma;
|
|
|
|
x58_flamethrower = xc_plasma;
|
|
|
|
} else
|
|
|
|
ConstructNew(in, propCount);
|
2017-02-10 05:43:07 +00:00
|
|
|
}
|
|
|
|
|
2019-07-16 15:54:07 +00:00
|
|
|
EDeflectType CDamageVulnerability::GetDeflectionType(const CWeaponMode& mode) const {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (mode.IsCharged())
|
|
|
|
return x60_chargedDeflected;
|
|
|
|
if (mode.IsComboed())
|
|
|
|
return x64_comboDeflected;
|
|
|
|
return x5c_deflected;
|
2017-03-01 03:42:06 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CDamageVulnerability::WeaponHurts(const CWeaponMode& mode, bool ignoreDirect) const {
|
|
|
|
if (mode.GetType() == EWeaponType::None || mode.GetType() > EWeaponType::OrangePhazon)
|
|
|
|
return false;
|
|
|
|
if (mode.IsInstantKill())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
EVulnerability normalVuln = (&x0_power)[u32(mode.GetType())];
|
|
|
|
bool normalHurts = true;
|
|
|
|
if (ignoreDirect) {
|
|
|
|
normalHurts = is_normal_or_weak(normalVuln);
|
|
|
|
} else {
|
|
|
|
if (!is_normal_or_weak(normalVuln) &&
|
|
|
|
(normalVuln != EVulnerability::DirectWeak && normalVuln != EVulnerability::DirectNormal))
|
|
|
|
normalHurts = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool chargedHurts = true;
|
|
|
|
bool comboedHurts = true;
|
|
|
|
if (mode.GetType() < EWeaponType::Bomb) {
|
|
|
|
EVulnerability chargedVuln = (&x3c_chargedPower)[u32(mode.GetType())];
|
|
|
|
EVulnerability comboedVuln = (&x4c_superMissile)[u32(mode.GetType())];
|
|
|
|
if (ignoreDirect) {
|
|
|
|
chargedHurts = is_normal_or_weak(chargedVuln);
|
|
|
|
comboedHurts = is_normal_or_weak(comboedVuln);
|
|
|
|
} else {
|
|
|
|
if (!is_normal_or_weak(chargedVuln) &&
|
|
|
|
(chargedVuln != EVulnerability::DirectWeak && chargedVuln != EVulnerability::DirectNormal))
|
|
|
|
chargedHurts = false;
|
|
|
|
if (!is_normal_or_weak(comboedVuln) &&
|
|
|
|
(comboedVuln != EVulnerability::DirectWeak && comboedVuln != EVulnerability::DirectNormal))
|
|
|
|
comboedHurts = false;
|
2017-02-10 05:43:07 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-02-10 05:43:07 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (normalHurts && !mode.IsCharged() && !mode.IsComboed())
|
|
|
|
return true;
|
|
|
|
if (chargedHurts && mode.IsCharged())
|
|
|
|
return true;
|
|
|
|
return comboedHurts && mode.IsComboed();
|
2017-02-10 05:43:07 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CDamageVulnerability::WeaponHits(const CWeaponMode& mode, bool checkDirect) const {
|
|
|
|
if (mode.GetType() == EWeaponType::None || mode.GetType() > EWeaponType::OrangePhazon)
|
2017-02-10 05:43:07 +00:00
|
|
|
return false;
|
2018-12-08 05:30:43 +00:00
|
|
|
if (mode.IsInstantKill())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
bool normalVuln;
|
|
|
|
if (!checkDirect)
|
|
|
|
normalVuln = (&x0_power)[u32(mode.GetType())] != EVulnerability::Immune;
|
|
|
|
else
|
|
|
|
normalVuln = is_not_immune((&x0_power)[u32(mode.GetType())]);
|
|
|
|
|
|
|
|
bool chargedVuln = true;
|
|
|
|
bool comboedVuln = true;
|
|
|
|
|
|
|
|
if (mode.GetType() < EWeaponType::Bomb) {
|
|
|
|
if (!checkDirect) {
|
|
|
|
chargedVuln = (&x3c_chargedPower)[u32(mode.GetType())] != EVulnerability::Immune;
|
|
|
|
comboedVuln = (&x4c_superMissile)[u32(mode.GetType())] != EVulnerability::Immune;
|
|
|
|
} else {
|
|
|
|
chargedVuln = is_not_immune((&x3c_chargedPower)[u32(mode.GetType())]);
|
|
|
|
comboedVuln = is_not_immune((&x4c_superMissile)[u32(mode.GetType())]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (normalVuln && !mode.IsCharged() && !mode.IsComboed())
|
|
|
|
return true;
|
|
|
|
if (chargedVuln && mode.IsCharged())
|
|
|
|
return true;
|
2019-07-16 15:54:07 +00:00
|
|
|
return comboedVuln && mode.IsComboed();
|
2017-02-10 05:43:07 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
EVulnerability CDamageVulnerability::GetVulnerability(const CWeaponMode& mode, bool ignoreDirect) const {
|
2020-04-16 05:26:14 +00:00
|
|
|
if (mode.GetType() == EWeaponType::None || mode.GetType() > EWeaponType::OrangePhazon) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return EVulnerability::Deflect;
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2017-02-10 05:43:07 +00:00
|
|
|
|
2020-04-16 05:26:14 +00:00
|
|
|
if (mode.IsInstantKill()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return EVulnerability::Normal;
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2017-02-10 05:43:07 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
EVulnerability vuln = (&x0_power)[u32(mode.GetType())];
|
|
|
|
if (mode.IsCharged()) {
|
2020-04-16 05:26:14 +00:00
|
|
|
if (mode.GetType() < EWeaponType::Bomb) {
|
2018-12-08 05:30:43 +00:00
|
|
|
vuln = (&x3c_chargedPower)[u32(mode.GetType())];
|
2020-04-16 05:26:14 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
vuln = EVulnerability::Normal;
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-02-10 05:43:07 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (mode.IsComboed()) {
|
2020-04-16 05:26:14 +00:00
|
|
|
if (mode.GetType() < EWeaponType::Bomb) {
|
2018-12-08 05:30:43 +00:00
|
|
|
vuln = (&x3c_chargedPower)[u32(mode.GetType())];
|
2020-04-16 05:26:14 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
vuln = EVulnerability::Normal;
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-02-10 05:43:07 +00:00
|
|
|
|
2020-04-16 05:26:14 +00:00
|
|
|
if (ignoreDirect) {
|
2017-02-10 05:43:07 +00:00
|
|
|
return vuln;
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-04-16 05:26:14 +00:00
|
|
|
if (vuln == EVulnerability::DirectWeak) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return EVulnerability::Weak;
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
|
|
|
if (vuln == EVulnerability::DirectNormal) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return EVulnerability::Normal;
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
|
|
|
if (vuln == EVulnerability::DirectImmune) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return EVulnerability::Immune;
|
2020-04-16 05:26:14 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
return vuln;
|
2017-02-10 05:43:07 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|