Match and link CAmbientAI

This commit is contained in:
Phillip Stephens 2022-10-20 09:16:55 -07:00
parent b8d23f2ff6
commit c8560022f0
3 changed files with 42 additions and 34 deletions

View File

@ -346,7 +346,7 @@ LIBS = [
["MetroidPrime/CGBASupport", True], ["MetroidPrime/CGBASupport", True],
"MetroidPrime/Player/CSaveWorld", "MetroidPrime/Player/CSaveWorld",
"MetroidPrime/ScriptObjects/CScriptCameraHintTrigger", "MetroidPrime/ScriptObjects/CScriptCameraHintTrigger",
["MetroidPrime/Enemies/CAmbientAI", False], ["MetroidPrime/Enemies/CAmbientAI", True],
["MetroidPrime/CMemoryCardDriver", False], ["MetroidPrime/CMemoryCardDriver", False],
"MetroidPrime/CSaveGameScreen", "MetroidPrime/CSaveGameScreen",
"MetroidPrime/Enemies/CAtomicBeta", "MetroidPrime/Enemies/CAtomicBeta",

View File

@ -104,8 +104,8 @@ CActor::CActor(TUniqueId uid, bool active, const rstl::string& name, const CEnti
CActor::~CActor() { RemoveEmitter(); } CActor::~CActor() { RemoveEmitter(); }
CAdvancementDeltas CActor::UpdateAnimation(float dt, CStateManager& mgr, bool advTree) { SAdvancementDeltas CActor::UpdateAnimation(float dt, CStateManager& mgr, bool advTree) {
CAdvancementDeltas result = ModelData()->AdvanceAnimation(dt, mgr, GetAreaId(), advTree); SAdvancementDeltas result = ModelData()->AdvanceAnimation(dt, mgr, GetAreaId(), advTree);
ModelData()->AdvanceParticles(GetTransform(), dt, mgr); ModelData()->AdvanceParticles(GetTransform(), dt, mgr);
UpdateSfxEmitters(); UpdateSfxEmitters();
if (HasAnimation()) { if (HasAnimation()) {

View File

@ -2,9 +2,12 @@
#include "MetroidPrime/CAnimData.hpp" #include "MetroidPrime/CAnimData.hpp"
#include "MetroidPrime/CModelData.hpp" #include "MetroidPrime/CModelData.hpp"
#include "MetroidPrime/Player/CPlayer.hpp"
#include "MetroidPrime/TCastTo.hpp" #include "MetroidPrime/TCastTo.hpp"
#include "Kyoto/Animation/IAnimReader.hpp"
CAmbientAI::CAmbientAI(TUniqueId uid, const rstl::string& name, const CEntityInfo& info, CAmbientAI::CAmbientAI(TUniqueId uid, const rstl::string& name, const CEntityInfo& info,
const CTransform4f& xf, const CModelData& mData, const CAABox& aabox, const CTransform4f& xf, const CModelData& mData, const CAABox& aabox,
const CMaterialList& materialList, float mass, const CHealthInfo& hInfo, const CMaterialList& materialList, float mass, const CHealthInfo& hInfo,
@ -45,56 +48,63 @@ void CAmbientAI::RandomizePlaybackRate(CStateManager& mgr) {
} }
void CAmbientAI::Think(float dt, CStateManager& mgr) { void CAmbientAI::Think(float dt, CStateManager& mgr) {
#if 0
if (!GetActive()) if (!GetActive())
return; return;
if (GetModelData() && GetModelData()->GetAnimationData()) { if (HasAnimation()) {
bool hasAnimTime = GetModelData()->GetAnimationData()->IsAnimTimeRemaining(dt - FLT_EPSILON, rstl::string_l("Whole Body")); bool hasAnimTime = GetModelData()->GetAnimationData()->IsAnimTimeRemaining(
dt - FLT_EPSILON, rstl::string_l("Whole Body"));
bool isLooping = GetModelData()->GetIsLoop(); bool isLooping = GetModelData()->GetIsLoop();
if (hasAnimTime || isLooping) { if (hasAnimTime || isLooping) {
x2e8_25_animating = true; x2e8_25_animating = true;
SAdvancementDeltas deltas = UpdateAnimation(dt, mgr, x2e8_25_animating); CAdvancementDeltas deltas = UpdateAnimation(dt, mgr, true);
MoveToOR(deltas.x0_posDelta, dt); MoveToOR(deltas.GetOffsetDelta(), dt);
RotateToOR(deltas.xc_rotDelta, 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); SendScriptMsgs(kSS_MaxReached, mgr, kSM_None);
x2e8_25_animating = false; x2e8_25_animating = false;
} }
} }
bool inAlertRange = (mgr.GetPlayer().GetTranslation() - GetTranslation()).magnitude() < x2d4_alertRange; bool inAlertRange =
bool inImpactRange = (mgr.GetPlayer().GetTranslation() - GetTranslation()).magnitude() < x2d8_impactRange; (mgr.GetPlayer()->GetTranslation() - GetTranslation()).Magnitude() < x2d4_alertRange;
bool inImpactRange =
(mgr.GetPlayer()->GetTranslation() - GetTranslation()).Magnitude() < x2d8_impactRange;
switch (x2d0_animState) { switch (x2d0_animState) {
case kSA_Ready: { case kAS_Ready: {
if (inAlertRange) { if (inAlertRange) {
x2d0_animState = kSA_Alert; x2d0_animState = kAS_Alert;
ModelData()->AnimationData()->SetAnimation(CAnimPlaybackParms(x2e0_alertAnim, -1, 1.f, true), false); ModelData()->AnimationData()->SetAnimation(CAnimPlaybackParms(x2e0_alertAnim, -1, 1.f, true),
false);
ModelData()->EnableLooping(true); ModelData()->EnableLooping(true);
RandomizePlaybackRate(mgr); RandomizePlaybackRate(mgr);
} }
break; break;
} }
case kSA_Alert: { case kAS_Alert: {
if (!inAlertRange) { if (!inAlertRange) {
x2d0_animState = kSA_Ready; x2d0_animState = kAS_Ready;
ModelData()->AnimationData()->SetAnimation(CAnimPlaybackParms(x2dc_defaultAnim, -1, 1.f, true), false); ModelData()->AnimationData()->SetAnimation(
CAnimPlaybackParms(x2dc_defaultAnim, -1, 1.f, true), false);
ModelData()->EnableLooping(true); ModelData()->EnableLooping(true);
RandomizePlaybackRate(mgr); RandomizePlaybackRate(mgr);
} else if (inImpactRange) { } else if (inImpactRange) {
SendScriptMsgs(kSS_Dead, mgr, kSM_None); SendScriptMsgs(kSS_Dead, mgr, kSM_None);
RemoveEmitter();
SetActive(false); SetActive(false);
} }
break; break;
} }
case kSA_Impact: { case kAS_Impact: {
if (!x2e8_25_animating) { if (!x2e8_25_animating) {
x2d0_animState = kSA_Ready; x2d0_animState = kAS_Ready;
ModelData()->AnimationData()->SetAnimation(CAnimPlaybackParms(x2dc_defaultAnim, -1, 1.f, true), false); ModelData()->AnimationData()->SetAnimation(
CAnimPlaybackParms(x2dc_defaultAnim, -1, 1.f, true), false);
ModelData()->EnableLooping(true); ModelData()->EnableLooping(true);
RandomizePlaybackRate(mgr); RandomizePlaybackRate(mgr);
} }
@ -102,17 +112,17 @@ void CAmbientAI::Think(float dt, CStateManager& mgr) {
} }
} }
if (!x2e8_24_dead) { if (x2e8_24_dead) {
return;
}
CHealthInfo* hInfo = HealthInfo(mgr); CHealthInfo* hInfo = HealthInfo(mgr);
if (hInfo->GetHP() <= 0.f) { if (hInfo->GetHP() <= 0.f) {
x2e8_24_dead = true; x2e8_24_dead = true;
SendScriptMsgs(EScriptObjectState::Dead, mgr, EScriptObjectMessage::None); SendScriptMsgs(kSS_Dead, mgr, kSM_None);
RemoveEmitter(); RemoveEmitter();
SetActive(false); SetActive(false);
} }
} }
#endif
}
void CAmbientAI::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) { void CAmbientAI::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
switch (msg) { switch (msg) {
@ -147,6 +157,4 @@ void CAmbientAI::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CState
CPhysicsActor::AcceptScriptMsg(msg, uid, mgr); CPhysicsActor::AcceptScriptMsg(msg, uid, mgr);
} }
void CAmbientAI::Accept(IVisitor& visitor) { void CAmbientAI::Accept(IVisitor& visitor) { visitor.Visit(*this); }
visitor.Visit(*this);
}