From 75e1e3f144556d0676650f8018c26563cef696a1 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Fri, 21 Oct 2022 19:00:19 +0300 Subject: [PATCH] Match and link CScriptAiJumpPoint Former-commit-id: de4370288f0db84d273e0fee12f84a7928530204 --- .../ScriptObjects/CScriptAiJumpPoint.s | 12 ++-- configure.py | 2 +- .../ScriptObjects/CScriptAiJumpPoint.hpp | 33 ++++++++++ obj_files.mk | 2 +- .../ScriptObjects/CScriptAiJumpPoint.cpp | 62 +++++++++++++++++++ 5 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 include/MetroidPrime/ScriptObjects/CScriptAiJumpPoint.hpp create mode 100644 src/MetroidPrime/ScriptObjects/CScriptAiJumpPoint.cpp diff --git a/asm/MetroidPrime/ScriptObjects/CScriptAiJumpPoint.s b/asm/MetroidPrime/ScriptObjects/CScriptAiJumpPoint.s index 5a239487..41fdd9f3 100644 --- a/asm/MetroidPrime/ScriptObjects/CScriptAiJumpPoint.s +++ b/asm/MetroidPrime/ScriptObjects/CScriptAiJumpPoint.s @@ -3,8 +3,8 @@ .section .data .balign 8 -.global lbl_803E6398 -lbl_803E6398: +.global __vt__18CScriptAiJumpPoint +__vt__18CScriptAiJumpPoint: # ROM: 0x3E3398 .4byte 0 .4byte 0 @@ -56,9 +56,9 @@ __dt__18CScriptAiJumpPointFv: /* 801EF200 001EC160 93 C1 00 08 */ stw r30, 8(r1) /* 801EF204 001EC164 7C 7E 1B 79 */ or. r30, r3, r3 /* 801EF208 001EC168 41 82 00 3C */ beq lbl_801EF244 -/* 801EF20C 001EC16C 3C 60 80 3E */ lis r3, lbl_803E6398@ha +/* 801EF20C 001EC16C 3C 60 80 3E */ lis r3, __vt__18CScriptAiJumpPoint@ha /* 801EF210 001EC170 34 1E 00 EC */ addic. r0, r30, 0xec -/* 801EF214 001EC174 38 03 63 98 */ addi r0, r3, lbl_803E6398@l +/* 801EF214 001EC174 38 03 63 98 */ addi r0, r3, __vt__18CScriptAiJumpPoint@l /* 801EF218 001EC178 90 1E 00 00 */ stw r0, 0(r30) /* 801EF21C 001EC17C 41 82 00 0C */ beq lbl_801EF228 /* 801EF220 001EC180 38 00 00 00 */ li r0, 0 @@ -290,9 +290,9 @@ Accept__18CScriptAiJumpPointFR8IVisitor: /* 801EF524 001EC484 38 61 00 B8 */ addi r3, r1, 0xb8 /* 801EF528 001EC488 38 80 FF FF */ li r4, -1 /* 801EF52C 001EC48C 4B F2 75 21 */ bl __dt__10CModelDataFv -/* 801EF530 001EC490 3C 80 80 3E */ lis r4, lbl_803E6398@ha +/* 801EF530 001EC490 3C 80 80 3E */ lis r4, __vt__18CScriptAiJumpPoint@ha /* 801EF534 001EC494 38 61 00 38 */ addi r3, r1, 0x38 -/* 801EF538 001EC498 38 04 63 98 */ addi r0, r4, lbl_803E6398@l +/* 801EF538 001EC498 38 04 63 98 */ addi r0, r4, __vt__18CScriptAiJumpPoint@l /* 801EF53C 001EC49C 38 81 00 2C */ addi r4, r1, 0x2c /* 801EF540 001EC4A0 90 1F 00 00 */ stw r0, 0(r31) /* 801EF544 001EC4A4 38 A1 00 20 */ addi r5, r1, 0x20 diff --git a/configure.py b/configure.py index 5a393c27..a95b1638 100755 --- a/configure.py +++ b/configure.py @@ -298,7 +298,7 @@ LIBS = [ "MetroidPrime/Enemies/CThardus", "MetroidPrime/CActorParticles", "MetroidPrime/Enemies/CWallCrawlerSwarm", - "MetroidPrime/ScriptObjects/CScriptAiJumpPoint", + ["MetroidPrime/ScriptObjects/CScriptAiJumpPoint", True], "MetroidPrime/CMessageScreen", "MetroidPrime/Enemies/CFlaahgraTentacle", "MetroidPrime/Weapons/GunController/CGSFidget", diff --git a/include/MetroidPrime/ScriptObjects/CScriptAiJumpPoint.hpp b/include/MetroidPrime/ScriptObjects/CScriptAiJumpPoint.hpp new file mode 100644 index 00000000..4c370b92 --- /dev/null +++ b/include/MetroidPrime/ScriptObjects/CScriptAiJumpPoint.hpp @@ -0,0 +1,33 @@ +#ifndef _CSCRIPTAIJUMPPOINT +#define _CSCRIPTAIJUMPPOINT + +#include "MetroidPrime/CActor.hpp" + +class CScriptAiJumpPoint : public CActor { +private: + float xe8_apex; + rstl::optional_object xec_touchBounds; + bool x108_24_inUse : 1; + TUniqueId x10a_occupant; + TUniqueId x10c_currentWaypoint; + TUniqueId x10e_nextWaypoint; + float x110_timeRemaining; + +public: + CScriptAiJumpPoint(TUniqueId, const rstl::string&, const CEntityInfo&, const CTransform4f&, bool, + float); + ~CScriptAiJumpPoint(); + + void Accept(IVisitor& visitor) override; + void Think(float, CStateManager&) override; + void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&) override; + void AddToRenderer(const CFrustumPlanes&, const CStateManager&) const override; + void Render(const CStateManager&) const override; + rstl::optional_object< CAABox > GetTouchBounds() const override; + bool GetInUse(TUniqueId uid) const; + TUniqueId GetJumpPoint() const { return x10c_currentWaypoint; } + TUniqueId GetJumpTarget() const { return x10e_nextWaypoint; } + float GetJumpApex() const { return xe8_apex; } +}; + +#endif // _CSCRIPTAIJUMPPOINT diff --git a/obj_files.mk b/obj_files.mk index d5db3146..01dbafdf 100644 --- a/obj_files.mk +++ b/obj_files.mk @@ -263,7 +263,7 @@ METROIDPRIME :=\ $(BUILD_DIR)/asm/MetroidPrime/Enemies/CThardus.o\ $(BUILD_DIR)/asm/MetroidPrime/CActorParticles.o\ $(BUILD_DIR)/asm/MetroidPrime/Enemies/CWallCrawlerSwarm.o\ - $(BUILD_DIR)/asm/MetroidPrime/ScriptObjects/CScriptAiJumpPoint.o\ + $(BUILD_DIR)/src/MetroidPrime/ScriptObjects/CScriptAiJumpPoint.o\ $(BUILD_DIR)/asm/MetroidPrime/CMessageScreen.o\ $(BUILD_DIR)/asm/MetroidPrime/Enemies/CFlaahgraTentacle.o\ $(BUILD_DIR)/asm/MetroidPrime/Weapons/GunController/CGSFidget.o\ diff --git a/src/MetroidPrime/ScriptObjects/CScriptAiJumpPoint.cpp b/src/MetroidPrime/ScriptObjects/CScriptAiJumpPoint.cpp new file mode 100644 index 00000000..72fe56cc --- /dev/null +++ b/src/MetroidPrime/ScriptObjects/CScriptAiJumpPoint.cpp @@ -0,0 +1,62 @@ +#include "MetroidPrime/ScriptObjects/CScriptAiJumpPoint.hpp" + +#include "MetroidPrime/CActorParameters.hpp" +#include "MetroidPrime/ScriptObjects/CScriptWaypoint.hpp" + +CScriptAiJumpPoint::CScriptAiJumpPoint(TUniqueId uid, const rstl::string& name, + const CEntityInfo& info, const CTransform4f& xf, bool active, + float apex) +: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(kMT_NoStepLogic), + CActorParameters::None(), kInvalidUniqueId) +, xe8_apex(apex) +, xec_touchBounds(CAABox(xf.GetTranslation(), xf.GetTranslation())) +, x108_24_inUse(false) +, x10a_occupant(kInvalidUniqueId) +, x10c_currentWaypoint(kInvalidUniqueId) +, x10e_nextWaypoint(kInvalidUniqueId) +, x110_timeRemaining(0.f) {} + +void CScriptAiJumpPoint::Accept(IVisitor& visitor) { visitor.Visit(*this); } + +void CScriptAiJumpPoint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId other, + CStateManager& mgr) { + CActor::AcceptScriptMsg(msg, other, mgr); + + switch (msg) { + case kSM_InitializedInArea: + rstl::vector< SConnection >::const_iterator conn = x20_conns.begin(); + for (; conn != x20_conns.end(); ++conn) { + if (conn->x0_state != kSS_Arrived || conn->x4_msg != kSM_Next) { + continue; + } + TUniqueId id = mgr.GetIdForScript(conn->x8_objId); + if (const CScriptWaypoint* wpnt = TCastToConstPtr< CScriptWaypoint >(mgr.GetObjectById(id))) { + x10c_currentWaypoint = id; + x10e_nextWaypoint = wpnt->NextWaypoint(mgr); + return; + } + } + } +} + +bool CScriptAiJumpPoint::GetInUse(TUniqueId uid) const { + return x108_24_inUse || x110_timeRemaining > 0.f || + (x10a_occupant != kInvalidUniqueId && uid != kInvalidUniqueId && uid != x10a_occupant); +} + +void CScriptAiJumpPoint::Think(float dt, CStateManager&) { + if (x110_timeRemaining > 0) { + x110_timeRemaining -= dt; + } +} + +void CScriptAiJumpPoint::AddToRenderer(const CFrustumPlanes&, const CStateManager&) const override { +} + +void CScriptAiJumpPoint::Render(const CStateManager&) const override {} + +rstl::optional_object< CAABox > CScriptAiJumpPoint::GetTouchBounds() const { + return xec_touchBounds; +} + +CScriptAiJumpPoint::~CScriptAiJumpPoint() {}