From c8560022f07b3f93d2e377f0bcfb41680f5325ff Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Thu, 20 Oct 2022 09:16:55 -0700 Subject: [PATCH] Match and link CAmbientAI --- configure.py | 2 +- src/MetroidPrime/CActor.cpp | 4 +- src/MetroidPrime/Enemies/CAmbientAI.cpp | 70 ++++++++++++++----------- 3 files changed, 42 insertions(+), 34 deletions(-) diff --git a/configure.py b/configure.py index 7495d2b8..858c834e 100755 --- a/configure.py +++ b/configure.py @@ -346,7 +346,7 @@ LIBS = [ ["MetroidPrime/CGBASupport", True], "MetroidPrime/Player/CSaveWorld", "MetroidPrime/ScriptObjects/CScriptCameraHintTrigger", - ["MetroidPrime/Enemies/CAmbientAI", False], + ["MetroidPrime/Enemies/CAmbientAI", True], ["MetroidPrime/CMemoryCardDriver", False], "MetroidPrime/CSaveGameScreen", "MetroidPrime/Enemies/CAtomicBeta", diff --git a/src/MetroidPrime/CActor.cpp b/src/MetroidPrime/CActor.cpp index a5702947..afcdc01a 100644 --- a/src/MetroidPrime/CActor.cpp +++ b/src/MetroidPrime/CActor.cpp @@ -104,8 +104,8 @@ CActor::CActor(TUniqueId uid, bool active, const rstl::string& name, const CEnti CActor::~CActor() { RemoveEmitter(); } -CAdvancementDeltas CActor::UpdateAnimation(float dt, CStateManager& mgr, bool advTree) { - CAdvancementDeltas result = ModelData()->AdvanceAnimation(dt, mgr, GetAreaId(), advTree); +SAdvancementDeltas CActor::UpdateAnimation(float dt, CStateManager& mgr, bool advTree) { + SAdvancementDeltas result = ModelData()->AdvanceAnimation(dt, mgr, GetAreaId(), advTree); ModelData()->AdvanceParticles(GetTransform(), dt, mgr); UpdateSfxEmitters(); if (HasAnimation()) { diff --git a/src/MetroidPrime/Enemies/CAmbientAI.cpp b/src/MetroidPrime/Enemies/CAmbientAI.cpp index ca2bf61e..1cd7e876 100644 --- a/src/MetroidPrime/Enemies/CAmbientAI.cpp +++ b/src/MetroidPrime/Enemies/CAmbientAI.cpp @@ -2,9 +2,12 @@ #include "MetroidPrime/CAnimData.hpp" #include "MetroidPrime/CModelData.hpp" +#include "MetroidPrime/Player/CPlayer.hpp" #include "MetroidPrime/TCastTo.hpp" +#include "Kyoto/Animation/IAnimReader.hpp" + CAmbientAI::CAmbientAI(TUniqueId uid, const rstl::string& name, const CEntityInfo& info, const CTransform4f& xf, const CModelData& mData, const CAABox& aabox, const CMaterialList& materialList, float mass, const CHealthInfo& hInfo, @@ -45,56 +48,63 @@ void CAmbientAI::RandomizePlaybackRate(CStateManager& mgr) { } void CAmbientAI::Think(float dt, CStateManager& mgr) { -#if 0 - if (!GetActive()) + if (!GetActive()) return; - if (GetModelData() && GetModelData()->GetAnimationData()) { - bool hasAnimTime = GetModelData()->GetAnimationData()->IsAnimTimeRemaining(dt - FLT_EPSILON, rstl::string_l("Whole Body")); + if (HasAnimation()) { + bool hasAnimTime = GetModelData()->GetAnimationData()->IsAnimTimeRemaining( + dt - FLT_EPSILON, rstl::string_l("Whole Body")); bool isLooping = GetModelData()->GetIsLoop(); if (hasAnimTime || isLooping) { x2e8_25_animating = true; - SAdvancementDeltas deltas = UpdateAnimation(dt, mgr, x2e8_25_animating); - MoveToOR(deltas.x0_posDelta, dt); - RotateToOR(deltas.xc_rotDelta, dt); + CAdvancementDeltas deltas = UpdateAnimation(dt, mgr, true); + MoveToOR(deltas.GetOffsetDelta(), dt); + RotateToOR(deltas.GetOrientationDelta(), dt); } - if (!hasAnimTime || (x2e8_25_animating && !isLooping)) { + if (hasAnimTime) { + } else if (x2e8_25_animating && !isLooping) { SendScriptMsgs(kSS_MaxReached, mgr, kSM_None); x2e8_25_animating = false; } } - bool inAlertRange = (mgr.GetPlayer().GetTranslation() - GetTranslation()).magnitude() < x2d4_alertRange; - bool inImpactRange = (mgr.GetPlayer().GetTranslation() - GetTranslation()).magnitude() < x2d8_impactRange; + bool inAlertRange = + (mgr.GetPlayer()->GetTranslation() - GetTranslation()).Magnitude() < x2d4_alertRange; + bool inImpactRange = + (mgr.GetPlayer()->GetTranslation() - GetTranslation()).Magnitude() < x2d8_impactRange; switch (x2d0_animState) { - case kSA_Ready: { + case kAS_Ready: { if (inAlertRange) { - x2d0_animState = kSA_Alert; - ModelData()->AnimationData()->SetAnimation(CAnimPlaybackParms(x2e0_alertAnim, -1, 1.f, true), false); + x2d0_animState = kAS_Alert; + ModelData()->AnimationData()->SetAnimation(CAnimPlaybackParms(x2e0_alertAnim, -1, 1.f, true), + false); ModelData()->EnableLooping(true); RandomizePlaybackRate(mgr); } break; } - case kSA_Alert: { + case kAS_Alert: { if (!inAlertRange) { - x2d0_animState = kSA_Ready; - ModelData()->AnimationData()->SetAnimation(CAnimPlaybackParms(x2dc_defaultAnim, -1, 1.f, true), false); + x2d0_animState = kAS_Ready; + ModelData()->AnimationData()->SetAnimation( + CAnimPlaybackParms(x2dc_defaultAnim, -1, 1.f, true), false); ModelData()->EnableLooping(true); RandomizePlaybackRate(mgr); } else if (inImpactRange) { SendScriptMsgs(kSS_Dead, mgr, kSM_None); + RemoveEmitter(); SetActive(false); } break; } - case kSA_Impact: { + case kAS_Impact: { if (!x2e8_25_animating) { - x2d0_animState = kSA_Ready; - ModelData()->AnimationData()->SetAnimation(CAnimPlaybackParms(x2dc_defaultAnim, -1, 1.f, true), false); + x2d0_animState = kAS_Ready; + ModelData()->AnimationData()->SetAnimation( + CAnimPlaybackParms(x2dc_defaultAnim, -1, 1.f, true), false); ModelData()->EnableLooping(true); RandomizePlaybackRate(mgr); } @@ -102,16 +112,16 @@ void CAmbientAI::Think(float dt, CStateManager& mgr) { } } - if (!x2e8_24_dead) { - CHealthInfo* hInfo = HealthInfo(mgr); - if (hInfo->GetHP() <= 0.f) { - x2e8_24_dead = true; - SendScriptMsgs(EScriptObjectState::Dead, mgr, EScriptObjectMessage::None); - RemoveEmitter(); - SetActive(false); - } + if (x2e8_24_dead) { + return; + } + CHealthInfo* hInfo = HealthInfo(mgr); + if (hInfo->GetHP() <= 0.f) { + x2e8_24_dead = true; + SendScriptMsgs(kSS_Dead, mgr, kSM_None); + RemoveEmitter(); + SetActive(false); } -#endif } void CAmbientAI::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) { @@ -147,6 +157,4 @@ void CAmbientAI::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CState CPhysicsActor::AcceptScriptMsg(msg, uid, mgr); } -void CAmbientAI::Accept(IVisitor& visitor) { - visitor.Visit(*this); -} +void CAmbientAI::Accept(IVisitor& visitor) { visitor.Visit(*this); }