Import CAmbientAI fixes from decomp

This commit is contained in:
Phillip Stephens 2022-10-20 09:39:16 -07:00
parent d6e8d373ac
commit c55289143f
1 changed files with 29 additions and 20 deletions

View File

@ -29,31 +29,36 @@ void CAmbientAI::Think(float dt, CStateManager& mgr) {
if (!GetActive()) if (!GetActive())
return; return;
if (GetModelData() && GetModelData()->GetAnimationData()) { if (GetModelData() && GetModelData()->GetAnimationData() != nullptr) {
bool hasAnimTime = GetModelData()->GetAnimationData()->IsAnimTimeRemaining(dt - FLT_EPSILON, "Whole Body"sv); bool hasAnimTime = GetModelData()->GetAnimationData()->IsAnimTimeRemaining(
dt - FLT_EPSILON, "Whole Body"sv);
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); SAdvancementDeltas deltas = UpdateAnimation(dt, mgr, true);
MoveToOR(deltas.x0_posDelta, dt); MoveToOR(deltas.x0_posDelta, dt);
RotateToOR(deltas.xc_rotDelta, dt); RotateToOR(deltas.xc_rotDelta, dt);
} }
if (!hasAnimTime || (x2e8_25_animating && !isLooping)) { if (hasAnimTime) {
} else if (x2e8_25_animating && !isLooping) {
SendScriptMsgs(EScriptObjectState::MaxReached, mgr, EScriptObjectMessage::None); SendScriptMsgs(EScriptObjectState::MaxReached, mgr, EScriptObjectMessage::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 EAnimationState::Ready: { case EAnimationState::Ready: {
if (inAlertRange) { if (inAlertRange) {
x2d0_animState = EAnimationState::Alert; x2d0_animState = EAnimationState::Alert;
GetModelData()->GetAnimationData()->SetAnimation(CAnimPlaybackParms(x2e0_alertAnim, -1, 1.f, true), false); GetModelData()->GetAnimationData()->SetAnimation(CAnimPlaybackParms(x2e0_alertAnim, -1, 1.f, true),
false);
GetModelData()->EnableLooping(true); GetModelData()->EnableLooping(true);
RandomizePlaybackRate(mgr); RandomizePlaybackRate(mgr);
} }
@ -62,11 +67,13 @@ void CAmbientAI::Think(float dt, CStateManager& mgr) {
case EAnimationState::Alert: { case EAnimationState::Alert: {
if (!inAlertRange) { if (!inAlertRange) {
x2d0_animState = EAnimationState::Ready; x2d0_animState = EAnimationState::Ready;
GetModelData()->GetAnimationData()->SetAnimation(CAnimPlaybackParms(x2dc_defaultAnim, -1, 1.f, true), false); GetModelData()->GetAnimationData()->SetAnimation(
CAnimPlaybackParms(x2dc_defaultAnim, -1, 1.f, true), false);
GetModelData()->EnableLooping(true); GetModelData()->EnableLooping(true);
RandomizePlaybackRate(mgr); RandomizePlaybackRate(mgr);
} else if (inImpactRange) { } else if (inImpactRange) {
SendScriptMsgs(EScriptObjectState::Dead, mgr, EScriptObjectMessage::None); SendScriptMsgs(EScriptObjectState::Dead, mgr, EScriptObjectMessage::None);
RemoveEmitter();
SetActive(false); SetActive(false);
} }
break; break;
@ -74,7 +81,8 @@ void CAmbientAI::Think(float dt, CStateManager& mgr) {
case EAnimationState::Impact: { case EAnimationState::Impact: {
if (!x2e8_25_animating) { if (!x2e8_25_animating) {
x2d0_animState = EAnimationState::Ready; x2d0_animState = EAnimationState::Ready;
GetModelData()->GetAnimationData()->SetAnimation(CAnimPlaybackParms(x2dc_defaultAnim, -1, 1.f, true), false); GetModelData()->GetAnimationData()->SetAnimation(
CAnimPlaybackParms(x2dc_defaultAnim, -1, 1.f, true), false);
GetModelData()->EnableLooping(true); GetModelData()->EnableLooping(true);
RandomizePlaybackRate(mgr); RandomizePlaybackRate(mgr);
} }
@ -82,7 +90,9 @@ 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;
@ -90,7 +100,6 @@ void CAmbientAI::Think(float dt, CStateManager& mgr) {
RemoveEmitter(); RemoveEmitter();
SetActive(false); SetActive(false);
} }
}
} }
void CAmbientAI::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) { void CAmbientAI::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
@ -106,6 +115,9 @@ void CAmbientAI::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CState
x260_healthInfo = x258_initialHealthInfo; x260_healthInfo = x258_initialHealthInfo;
break; break;
} }
case EScriptObjectMessage::InitializedInArea:
RandomizePlaybackRate(mgr);
break;
case EScriptObjectMessage::Damage: { case EScriptObjectMessage::Damage: {
if (GetActive()) { if (GetActive()) {
x2d0_animState = EAnimationState::Impact; x2d0_animState = EAnimationState::Impact;
@ -115,9 +127,6 @@ void CAmbientAI::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CState
} }
break; break;
} }
case EScriptObjectMessage::InitializedInArea:
RandomizePlaybackRate(mgr);
break;
default: default:
break; break;
} }