From f40c4e6555ae3ed22f7e38c8563b3c22082fd82c Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Sun, 2 Oct 2022 00:38:53 +0300 Subject: [PATCH] Add CDamageInfo --- include/MetroidPrime/CDamageInfo.hpp | 58 +++++++++++++++++++ include/MetroidPrime/Weapons/WeaponTypes.hpp | 2 +- src/MetroidPrime/CDamageInfo.cpp | 61 ++++++++++++++++++++ 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 include/MetroidPrime/CDamageInfo.hpp create mode 100644 src/MetroidPrime/CDamageInfo.cpp diff --git a/include/MetroidPrime/CDamageInfo.hpp b/include/MetroidPrime/CDamageInfo.hpp new file mode 100644 index 00000000..50e33cc1 --- /dev/null +++ b/include/MetroidPrime/CDamageInfo.hpp @@ -0,0 +1,58 @@ +#ifndef _CDAMAGEINFO_HPP +#define _CDAMAGEINFO_HPP + +#include "MetroidPrime/TGameTypes.hpp" +#include "MetroidPrime/Weapons/WeaponTypes.hpp" + +struct SShotParam; +class CDamageVulnerability; + +class CDamageInfo { + CWeaponMode x0_weaponMode; + float x8_damage; + float xc_radiusDamage; + float x10_radius; + float x14_knockback; + bool x18_24_noImmunity : 1; + +public: + CDamageInfo() + : x0_weaponMode(), x8_damage(0.f), xc_radiusDamage(0.f), x10_radius(0.f), x14_knockback(0.f), x18_24_noImmunity(false) {} + + explicit CDamageInfo(CInputStream& in); + + CDamageInfo(const CWeaponMode& mode, float damage, float radius, float knockback) + : x0_weaponMode(mode), x8_damage(damage), xc_radiusDamage(damage), x10_radius(radius), x14_knockback(knockback), x18_24_noImmunity(false) {} + + CDamageInfo(const CDamageInfo&, float); + explicit CDamageInfo(const SShotParam& other); + CDamageInfo& operator=(const SShotParam& other); + + const CWeaponMode& GetWeaponMode() const { return x0_weaponMode; } + void SetWeaponMode(const CWeaponMode& mode) { x0_weaponMode = mode; } + float GetRadius() const { return x10_radius; } + void SetRadius(float r) { x10_radius = r; } + float GetKnockBackPower() const { return x14_knockback; } + void SetKnockBackPower(float k) { x14_knockback = k; } + float GetDamage() const { return x8_damage; } + void SetDamage(float d) { x8_damage = d; } + float GetDamage(const CDamageVulnerability& dVuln) const; + float GetRadiusDamage() const { return xc_radiusDamage; } + void SetRadiusDamage(float r) { xc_radiusDamage = r; } + float GetRadiusDamage(const CDamageVulnerability& dVuln) const; + bool NoImmunity() const { return x18_24_noImmunity; } + void SetNoImmunity(bool b) { x18_24_noImmunity = b; } + void MultiplyDamage(float m) { + x8_damage *= m; + xc_radiusDamage *= m; + x14_knockback *= m; + } + void MultiplyDamageAndRadius(float m) { + x8_damage *= m; + xc_radiusDamage *= m; + x10_radius *= m; + x14_knockback *= m; + } +}; + +#endif diff --git a/include/MetroidPrime/Weapons/WeaponTypes.hpp b/include/MetroidPrime/Weapons/WeaponTypes.hpp index 05a614a1..9463c8de 100644 --- a/include/MetroidPrime/Weapons/WeaponTypes.hpp +++ b/include/MetroidPrime/Weapons/WeaponTypes.hpp @@ -28,9 +28,9 @@ class CWeaponMode { bool x4_26_instantKill : 1; public: - //constexpr CWeaponMode() = default; explicit CWeaponMode(EWeaponType type = kWT_None, bool charged = false, bool comboed = false, bool instaKill = false) : x0_weaponType(type), x4_24_charged(charged), x4_25_comboed(comboed), x4_26_instantKill(instaKill) {} + EWeaponType GetType() const { return x0_weaponType; } bool IsCharged() const { return x4_24_charged; } diff --git a/src/MetroidPrime/CDamageInfo.cpp b/src/MetroidPrime/CDamageInfo.cpp new file mode 100644 index 00000000..f7e48daf --- /dev/null +++ b/src/MetroidPrime/CDamageInfo.cpp @@ -0,0 +1,61 @@ +#include "MetroidPrime/CDamageInfo.hpp" + +#include "Kyoto/Streams/CInputStream.hpp" +#include "MetroidPrime/CDamageVulnerability.hpp" + +CDamageInfo::CDamageInfo(CInputStream& in) : x18_24_noImmunity(false) { + in.ReadLong(); + x0_weaponMode = CWeaponMode(EWeaponType(in.ReadLong())); + x8_damage = in.ReadFloat(); + xc_radiusDamage = x8_damage; + x10_radius = in.ReadFloat(); + x14_knockback = in.ReadFloat(); +} + +// CDamageInfo::CDamageInfo(const SShotParam& other) +// : x0_weaponMode(CWeaponMode(EWeaponType(other.x0_weaponType), other.x4_24_charged, +// other.x4_25_combo, other.x4_26_instaKill)) , x8_damage(other.x8_damage) , +// xc_radiusDamage(other.xc_radiusDamage) , x10_radius(other.x10_radius) , +// x14_knockback(other.x14_knockback) , x18_24_noImmunity(other.x18_24_noImmunity) {} + +// CDamageInfo& CDamageInfo::operator=(const SShotParam& other) { +// x0_weaponMode = +// CWeaponMode(EWeaponType(other.x0_weaponType), other.x4_24_charged, other.x4_25_combo, +// other.x4_26_instaKill); +// x8_damage = other.x8_damage; +// xc_radiusDamage = other.xc_radiusDamage; +// x10_radius = other.x10_radius; +// x14_knockback = other.x14_knockback; +// x18_24_noImmunity = other.x18_24_noImmunity; +// return *this; +// } + +float CDamageInfo::GetDamage(const CDamageVulnerability& dVuln) const { + EVulnerability vuln = dVuln.GetVulnerability(x0_weaponMode, false); + if (vuln == kVN_Deflect) + return 0.f; + else if (vuln == kVN_Weak) + return 2.f * x8_damage; + + return x8_damage; +} + +float CDamageInfo::GetRadiusDamage(const CDamageVulnerability& dVuln) const { + EVulnerability vuln = dVuln.GetVulnerability(x0_weaponMode, false); + if (vuln == kVN_Deflect) { + return 0.f; + } + if (vuln == kVN_Weak) { + return 2.f * xc_radiusDamage; + } + + return xc_radiusDamage; +} + +CDamageInfo::CDamageInfo(const CDamageInfo& other, float dt) +: x0_weaponMode(other.x0_weaponMode) +, x8_damage(other.x8_damage * (60 * dt)) +, xc_radiusDamage(x8_damage) +, x10_radius(other.x10_radius) +, x14_knockback(other.x14_knockback) +, x18_24_noImmunity(true) {}