diff --git a/asm/MetroidPrime/ScriptLoader.s b/asm/MetroidPrime/ScriptLoader.s index f2673159..87049178 100644 --- a/asm/MetroidPrime/ScriptLoader.s +++ b/asm/MetroidPrime/ScriptLoader.s @@ -21341,7 +21341,7 @@ lbl_800D8718: /* 800D88A0 000D5800 39 21 00 9C */ addi r9, r1, 0x9c /* 800D88A4 000D5804 39 41 00 38 */ addi r10, r1, 0x38 /* 800D88A8 000D5808 93 E1 00 14 */ stw r31, 0x14(r1) -/* 800D88AC 000D580C 48 09 C4 E5 */ bl "__ct__12CScriptSteamF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfoRC9CVector3fRC6CAABoxRC11CDamageInfoRC9CVector3fUibUiffff" +/* 800D88AC 000D580C 48 09 C4 E5 */ bl "__ct__12CScriptSteamF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfoRC9CVector3fRC6CAABoxRC11CDamageInfoRC9CVector3fUibUiffffb" /* 800D88B0 000D5810 7C 7B 1B 78 */ mr r27, r3 lbl_800D88B4: /* 800D88B4 000D5814 38 61 00 5C */ addi r3, r1, 0x5c diff --git a/asm/MetroidPrime/ScriptObjects/CScriptSteam.s b/asm/MetroidPrime/ScriptObjects/CScriptSteam.s index e4aae251..87d17c54 100644 --- a/asm/MetroidPrime/ScriptObjects/CScriptSteam.s +++ b/asm/MetroidPrime/ScriptObjects/CScriptSteam.s @@ -3,8 +3,8 @@ .section .data .balign 8 -.global lbl_803E3DA8 -lbl_803E3DA8: +.global __vt__12CScriptSteam +__vt__12CScriptSteam: # ROM: 0x3E0DA8 .4byte 0 .4byte 0 @@ -202,9 +202,9 @@ __dt__12CScriptSteamFv: /* 80174D44 00171CA4 93 C1 00 08 */ stw r30, 8(r1) /* 80174D48 00171CA8 7C 7E 1B 79 */ or. r30, r3, r3 /* 80174D4C 00171CAC 41 82 00 28 */ beq lbl_80174D74 -/* 80174D50 00171CB0 3C A0 80 3E */ lis r5, lbl_803E3DA8@ha +/* 80174D50 00171CB0 3C A0 80 3E */ lis r5, __vt__12CScriptSteam@ha /* 80174D54 00171CB4 38 80 00 00 */ li r4, 0 -/* 80174D58 00171CB8 38 05 3D A8 */ addi r0, r5, lbl_803E3DA8@l +/* 80174D58 00171CB8 38 05 3D A8 */ addi r0, r5, __vt__12CScriptSteam@l /* 80174D5C 00171CBC 90 1E 00 00 */ stw r0, 0(r30) /* 80174D60 00171CC0 4B F0 1F 21 */ bl __dt__14CScriptTriggerFv /* 80174D64 00171CC4 7F E0 07 35 */ extsh. r0, r31 @@ -220,8 +220,8 @@ lbl_80174D74: /* 80174D88 00171CE8 38 21 00 10 */ addi r1, r1, 0x10 /* 80174D8C 00171CEC 4E 80 00 20 */ blr -.global "__ct__12CScriptSteamF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfoRC9CVector3fRC6CAABoxRC11CDamageInfoRC9CVector3fUibUiffff" -"__ct__12CScriptSteamF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfoRC9CVector3fRC6CAABoxRC11CDamageInfoRC9CVector3fUibUiffff": +.global "__ct__12CScriptSteamF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfoRC9CVector3fRC6CAABoxRC11CDamageInfoRC9CVector3fUibUiffffb" +"__ct__12CScriptSteamF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfoRC9CVector3fRC6CAABoxRC11CDamageInfoRC9CVector3fUibUiffffb": /* 80174D90 00171CF0 94 21 FF 90 */ stwu r1, -0x70(r1) /* 80174D94 00171CF4 7C 08 02 A6 */ mflr r0 /* 80174D98 00171CF8 90 01 00 74 */ stw r0, 0x74(r1) @@ -255,8 +255,8 @@ lbl_80174D74: /* 80174E08 00171D68 90 01 00 14 */ stw r0, 0x14(r1) /* 80174E0C 00171D6C 4B F0 1F 4D */ bl "__ct__14CScriptTriggerF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfoRC9CVector3fRC6CAABoxRC11CDamageInfoRC9CVector3fUibbb" /* 80174E10 00171D70 EC 5E E8 24 */ fdivs f2, f30, f29 -/* 80174E14 00171D74 3C 60 80 3E */ lis r3, lbl_803E3DA8@ha -/* 80174E18 00171D78 38 03 3D A8 */ addi r0, r3, lbl_803E3DA8@l +/* 80174E14 00171D74 3C 60 80 3E */ lis r3, __vt__12CScriptSteam@ha +/* 80174E18 00171D78 38 03 3D A8 */ addi r0, r3, __vt__12CScriptSteam@l /* 80174E1C 00171D7C C0 02 A1 50 */ lfs f0, lbl_805ABE70@sda21(r2) /* 80174E20 00171D80 90 1C 00 00 */ stw r0, 0(r28) /* 80174E24 00171D84 9B FC 01 50 */ stb r31, 0x150(r28) diff --git a/include/MetroidPrime/CEnvFxManager.hpp b/include/MetroidPrime/CEnvFxManager.hpp index 1cc9c522..160358d9 100644 --- a/include/MetroidPrime/CEnvFxManager.hpp +++ b/include/MetroidPrime/CEnvFxManager.hpp @@ -40,6 +40,7 @@ class CEnvFxManager { public: static void Initialize(); void SetFxDensity(int, float); + void SetSplashRate(float f) { xb54_baseSplashRate = f; } private: CAABox x0_particleBounds; diff --git a/include/MetroidPrime/Cameras/CCameraManager.hpp b/include/MetroidPrime/Cameras/CCameraManager.hpp index a404b628..36671151 100644 --- a/include/MetroidPrime/Cameras/CCameraManager.hpp +++ b/include/MetroidPrime/Cameras/CCameraManager.hpp @@ -31,6 +31,8 @@ public: bool IsInCinematicCamera() const; static float DefaultThirdPersonFov(); + + int GetFluidCounter() const { return x74_fluidCounter; } private: TUniqueId x0_curCameraId; diff --git a/include/MetroidPrime/Player/CPlayer.hpp b/include/MetroidPrime/Player/CPlayer.hpp index 3694f6e4..873d85cf 100644 --- a/include/MetroidPrime/Player/CPlayer.hpp +++ b/include/MetroidPrime/Player/CPlayer.hpp @@ -150,6 +150,7 @@ public: virtual bool IsTransparent(); CVector3f GetBallPosition() const; + CVector3f GetEyePosition() const; CTransform4f CreateTransformFromMovementDirection() const; EPlayerOrbitState GetOrbitState() const { return x304_orbitState; } const CVector3f& GetMovementDirection() const { return x50c_moveDir; } @@ -187,6 +188,7 @@ public: void Teleport(const CTransform4f& xf, CStateManager& mgr, bool resetBallCam); void SetSpawnedMorphBallState(EPlayerMorphBallState state, CStateManager& mgr); + void SetVisorSteam(float targetAlpha, float alphaInDur, float alphaOutDir, CAssetId txtr, bool affectsThermal); CVector3f GetDampedClampedVelocityWR() const; float GetAverageSpeed() const; diff --git a/include/MetroidPrime/ScriptObjects/CScriptSteam.hpp b/include/MetroidPrime/ScriptObjects/CScriptSteam.hpp index 90cf62b2..e69a36d9 100644 --- a/include/MetroidPrime/ScriptObjects/CScriptSteam.hpp +++ b/include/MetroidPrime/ScriptObjects/CScriptSteam.hpp @@ -4,8 +4,23 @@ #include "MetroidPrime/ScriptObjects/CScriptTrigger.hpp" class CScriptSteam : public CScriptTrigger { - public: + bool x150_; + CAssetId x154_texture; + float x158_; + float x15c_alphaInDur; + float x160_alphaOutDur; + float x164_; + float x168_; + +public: + CScriptSteam(TUniqueId, const rstl::string& name, const CEntityInfo& info, const CVector3f& pos, + const CAABox&, const CDamageInfo& dInfo, const CVector3f& orientedForce, + unsigned int flags, bool active, CAssetId, float, float, float, float, bool); + ~CScriptSteam(); + + void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&); + void Think(float, CStateManager&); + void Accept(IVisitor&); }; - #endif // _CSCRIPTSTEAM diff --git a/src/MetroidPrime/ScriptObjects/CScriptSteam.cpp b/src/MetroidPrime/ScriptObjects/CScriptSteam.cpp index 8b177251..230c3e61 100644 --- a/src/MetroidPrime/ScriptObjects/CScriptSteam.cpp +++ b/src/MetroidPrime/ScriptObjects/CScriptSteam.cpp @@ -1 +1,69 @@ #include "MetroidPrime/ScriptObjects/CScriptSteam.hpp" + +#include "MetroidPrime/CEnvFxManager.hpp" +#include "MetroidPrime/CStateManager.hpp" +#include "MetroidPrime/Cameras/CCameraManager.hpp" +#include "MetroidPrime/Player/CPlayer.hpp" + +#include "Kyoto/Math/CloseEnough.hpp" + +CScriptSteam::CScriptSteam(TUniqueId uid, const rstl::string& name, const CEntityInfo& info, + const CVector3f& pos, const CAABox& aabb, const CDamageInfo& dInfo, + const CVector3f& orientedForce, unsigned int flags, bool active, + CAssetId texture, float f1, float f2, float f3, float f4, bool b1) +: CScriptTrigger(uid, name, info, pos, aabb, dInfo, orientedForce, flags, active, false, false) +, x150_(b1) +, x154_texture(texture) +, x158_(f1) +, x15c_alphaInDur(f2 / f1) +, x160_alphaOutDur(f3 / f1) { + float r3 = (aabb.GetMaxPoint().GetZ() < aabb.GetMaxPoint().GetY() ? aabb.GetMaxPoint().GetZ() + : aabb.GetMaxPoint().GetY()); + r3 = (r3 < aabb.GetMaxPoint().GetX() ? r3 : aabb.GetMaxPoint().GetX()); + + if (close_enough(f4, 0.f)) { + r3 = (r3 < f2 ? r3 : f4); + } + + x164_ = r3; + x168_ = 1.f / x164_; +} + +CScriptSteam::~CScriptSteam() {} + +void CScriptSteam::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) { + switch (msg) { + case kSM_Deactivate: + mgr.Player()->SetVisorSteam(0.f, x15c_alphaInDur, x160_alphaOutDur, kInvalidAssetId, x150_); + break; + } + + CScriptTrigger::AcceptScriptMsg(msg, uid, mgr); +} + +void CScriptSteam::Think(float dt, CStateManager& mgr) { + if (!GetActive()) { + return; + } + + CScriptTrigger::Think(dt, mgr); + + if (x148_28_playerTriggerProc && mgr.GetCameraManager()->GetFluidCounter() == 0) { + const CVector3f& eyePos = mgr.GetPlayer()->GetEyePosition(); + const CVector3f& posDiff = (GetTranslation() - eyePos); + const float mag = posDiff.Magnitude(); + + const float distance = + (mag >= x164_ ? 0.f : x158_ * CMath::FastCosR((1.5707964f * mag) * x168_)); + mgr.Player()->SetVisorSteam(distance, x15c_alphaInDur, x160_alphaOutDur, x154_texture, + x150_ == true); + if (x150_) { + mgr.EnvFxManager()->SetSplashRate(2.f * distance); + } + } else { + mgr.Player()->SetVisorSteam(0.f, x15c_alphaInDur, x160_alphaOutDur, kInvalidAssetId, + x150_ == true); + } +} + +void CScriptSteam::Accept(IVisitor& visitor) { visitor.Visit(*this); }