2020-01-15 12:07:48 +00:00
|
|
|
#include "Runtime/Character/CBodyState.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/Character/CBodyController.hpp"
|
|
|
|
#include "Runtime/Character/CPASAnimParmData.hpp"
|
|
|
|
#include "Runtime/World/CActor.hpp"
|
|
|
|
#include "Runtime/World/CPatterned.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2017-07-10 04:55:51 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
void CBSAttack::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const auto* cmd = static_cast<const CBCMeleeAttackCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::MeleeAttack));
|
2018-12-08 05:30:43 +00:00
|
|
|
const CPASDatabase& pasDatabase = bc.GetPASDatabase();
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::MeleeAttack, CPASAnimParm::FromEnum(s32(cmd->GetAttackSeverity())),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromEnum(s32(bc.GetLocomotionType())));
|
|
|
|
const std::pair<float, s32> best = pasDatabase.FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
|
|
|
if (cmd->HasAttackTargetPos()) {
|
|
|
|
x20_targetPos = cmd->GetAttackTargetPos();
|
|
|
|
|
|
|
|
CCharAnimTime evTime = bc.GetOwner().GetModelData()->GetAnimationData()->GetTimeOfUserEvent(
|
|
|
|
EUserEventType::AlignTargetPosStart, CCharAnimTime::Infinity());
|
|
|
|
x2c_alignTargetPosStartTime = (evTime != CCharAnimTime::Infinity()) ? evTime.GetSeconds() : 0.f;
|
|
|
|
|
|
|
|
evTime = bc.GetOwner().GetModelData()->GetAnimationData()->GetTimeOfUserEvent(EUserEventType::AlignTargetPos,
|
|
|
|
CCharAnimTime::Infinity());
|
|
|
|
x30_alignTargetPosTime = (evTime != CCharAnimTime::Infinity()) ? evTime.GetSeconds() : bc.GetAnimTimeRemaining();
|
|
|
|
} else {
|
2019-02-24 07:15:54 +00:00
|
|
|
x20_targetPos = zeus::skZero3f;
|
2018-12-08 05:30:43 +00:00
|
|
|
x2c_alignTargetPosStartTime = -1.f;
|
|
|
|
x30_alignTargetPosTime = -1.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
x4_nextState = pas::EAnimationState::Locomotion;
|
|
|
|
x34_curTime = 0.f;
|
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
pas::EAnimationState CBSAttack::GetBodyStateTransition(float dt, const CBodyController& bc) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Hurled;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockDown)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Fall;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopHitReaction)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopReaction;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockBack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::KnockBack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Locomotion)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (const auto* cmd = static_cast<const CBCSlideCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Slide))) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x8_slide = *cmd;
|
|
|
|
x4_nextState = pas::EAnimationState::Slide;
|
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Generate)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Generate;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (bc.IsAnimationOver()) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::MeleeAttack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::MeleeAttack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::ProjectileAttack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::ProjectileAttack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopAttack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopAttack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return x4_nextState;
|
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::NextState)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return x4_nextState;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
void CBSAttack::UpdatePhysicsActor(const CBodyController& bc, float dt) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (x20_targetPos.isZero()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x34_curTime < x2c_alignTargetPosStartTime || x34_curTime > x30_alignTargetPosTime) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (const TCastToPtr<CPhysicsActor> act = bc.GetOwner()) {
|
|
|
|
zeus::CVector3f delta = x20_targetPos - act->GetTranslation();
|
|
|
|
const float dur = x30_alignTargetPosTime - x2c_alignTargetPosStartTime;
|
|
|
|
if (dur > 0.f) {
|
|
|
|
delta *= zeus::CVector3f(dt / dur);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
const zeus::CVector3f localDelta = act->GetTransform().transposeRotate(delta);
|
|
|
|
act->ApplyImpulseWR(act->GetMoveToORImpulseWR(localDelta, dt), zeus::CAxisAngle());
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSAttack::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
|
|
|
x34_curTime += dt;
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (st == pas::EAnimationState::Invalid) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (!bc.GetCommandMgr().GetTargetVector().isZero()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.FaceDirection(bc.GetCommandMgr().GetTargetVector(), dt);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdatePhysicsActor(bc, dt);
|
|
|
|
} else if (st == pas::EAnimationState::Slide) {
|
|
|
|
bc.GetCommandMgr().DeliverCmd(x8_slide);
|
|
|
|
}
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSProjectileAttack::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const auto* cmd =
|
2018-12-08 05:30:43 +00:00
|
|
|
static_cast<const CBCProjectileAttackCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::ProjectileAttack));
|
|
|
|
zeus::CVector3f localDelta =
|
|
|
|
bc.GetOwner().GetTransform().transposeRotate(cmd->GetTargetPosition() - bc.GetOwner().GetTranslation());
|
|
|
|
zeus::CRelAngle angle = std::atan2(localDelta.y(), localDelta.x());
|
2018-12-17 03:52:51 +00:00
|
|
|
angle.makeRel();
|
2020-04-05 06:30:17 +00:00
|
|
|
const float attackAngle = angle.asDegrees();
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(
|
|
|
|
pas::EAnimationState::ProjectileAttack, CPASAnimParm::FromEnum(s32(cmd->GetAttackSeverity())),
|
|
|
|
CPASAnimParm::FromReal32(angle.asDegrees()), CPASAnimParm::FromEnum(s32(bc.GetLocomotionType())));
|
2020-04-05 06:30:17 +00:00
|
|
|
const std::pair<float, s32> best1 = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (cmd->BlendTwoClosest()) {
|
2020-04-22 09:08:02 +00:00
|
|
|
const std::pair<float, s32> best2 =
|
|
|
|
bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), best1.second);
|
|
|
|
const CPASAnimState* projAttackState = bc.GetPASDatabase().GetAnimState(pas::EAnimationState::ProjectileAttack);
|
2018-12-08 05:30:43 +00:00
|
|
|
float angle1 = projAttackState->GetAnimParmData(best1.second, 1).GetReal32Value();
|
|
|
|
float angle2 = projAttackState->GetAnimParmData(best2.second, 1).GetReal32Value();
|
2020-04-05 06:30:17 +00:00
|
|
|
if (angle1 - angle2 > 180.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
angle2 += 360.f;
|
2020-04-05 06:30:17 +00:00
|
|
|
} else if (angle2 - angle1 > 180.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
angle1 += 360.f;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
const CAnimPlaybackParms playParms(best1.second, best2.second, (angle1 - attackAngle) / (angle1 - angle2), true);
|
2017-07-10 04:55:51 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(best1.second, -1, 1.f, true);
|
2017-07-10 04:55:51 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
pas::EAnimationState CBSProjectileAttack::GetBodyStateTransition(float dt, const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Hurled;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockDown)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Fall;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopHitReaction)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopReaction;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockBack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::KnockBack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Locomotion)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.IsAnimationOver() || bc.GetCommandMgr().GetCmd(EBodyStateCmd::NextState)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSProjectileAttack::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
|
|
|
if (st == pas::EAnimationState::Invalid) {
|
|
|
|
if (!bc.GetCommandMgr().GetTargetVector().isZero()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.FaceDirection(bc.GetCommandMgr().GetTargetVector(), dt);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSDie::Start(CBodyController& bc, CStateManager& mgr) {
|
|
|
|
bool shouldReset = true;
|
|
|
|
if (bc.ShouldPlayDeathAnims()) {
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Death, CPASAnimParm::FromEnum(s32(bc.GetFallState())));
|
2020-04-05 06:30:17 +00:00
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (best.first > 0.f) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
|
|
|
x4_remTime = bc.GetAnimTimeRemaining();
|
|
|
|
shouldReset = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldReset) {
|
|
|
|
bc.EnableAnimation(false);
|
|
|
|
x4_remTime = bc.ShouldPlayDeathAnims() ? 3.f : 4.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
x8_isDead = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSDie::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
|
|
|
x4_remTime -= dt;
|
|
|
|
if (x4_remTime <= 0.f) {
|
|
|
|
bc.EnableAnimation(false);
|
|
|
|
x8_isDead = true;
|
|
|
|
}
|
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSFall::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const auto* cmd = static_cast<const CBCKnockDownCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockDown));
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f localDir = bc.GetOwner().GetTransform().transposeRotate(cmd->GetHitDirection());
|
2022-10-28 13:38:55 +00:00
|
|
|
zeus::CRelAngle angle = std::atan2(localDir.y(), localDir.x());
|
2018-12-17 03:52:51 +00:00
|
|
|
angle.makeRel();
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Fall, CPASAnimParm::FromReal32(angle.asDegrees()),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromEnum(s32(cmd->GetHitSeverity())));
|
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimState* knockdownState = bc.GetPASDatabase().GetAnimState(pas::EAnimationState::Fall);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!knockdownState->GetAnimParmData(best.second, 2).GetBoolValue()) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const float animAngle = zeus::degToRad(knockdownState->GetAnimParmData(best.second, 0).GetReal32Value());
|
2017-07-10 04:55:51 +00:00
|
|
|
zeus::CRelAngle delta1 = angle - animAngle;
|
2018-12-17 03:52:51 +00:00
|
|
|
delta1.makeRel();
|
2017-07-10 04:55:51 +00:00
|
|
|
zeus::CRelAngle delta2 = animAngle - angle;
|
2018-12-17 03:52:51 +00:00
|
|
|
delta2.makeRel();
|
2020-04-05 06:30:17 +00:00
|
|
|
const float minAngle = std::min(float(delta1), float(delta2));
|
2018-12-08 05:30:43 +00:00
|
|
|
x8_remTime = 0.15f * bc.GetAnimTimeRemaining();
|
2020-04-05 06:30:17 +00:00
|
|
|
const float flippedAngle = (delta1 > M_PIF) ? -minAngle : minAngle;
|
2018-12-08 05:30:43 +00:00
|
|
|
x4_rotateSpeed = (x8_remTime > FLT_EPSILON) ? flippedAngle / x8_remTime : flippedAngle;
|
|
|
|
} else {
|
|
|
|
x8_remTime = 0.f;
|
|
|
|
x4_rotateSpeed = 0.f;
|
|
|
|
}
|
|
|
|
xc_fallState = pas::EFallState(knockdownState->GetAnimParmData(best.second, 3).GetEnumValue());
|
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
pas::EAnimationState CBSFall::GetBodyStateTransition(float dt, const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.IsAnimationOver()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LieOnGround;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSFall::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (st == pas::EAnimationState::Invalid && x8_remTime > 0.f) {
|
|
|
|
zeus::CQuaternion quat;
|
|
|
|
quat.rotateZ(x4_rotateSpeed * dt);
|
|
|
|
bc.SetDeltaRotation(quat);
|
|
|
|
x8_remTime -= dt;
|
|
|
|
}
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSFall::Shutdown(CBodyController& bc) { bc.SetFallState(xc_fallState); }
|
|
|
|
|
|
|
|
void CBSGetup::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const auto* cmd = static_cast<const CBCGetupCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Getup));
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Getup, CPASAnimParm::FromEnum(s32(bc.GetFallState())),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromEnum(s32(cmd->GetGetupType())));
|
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (best.first > FLT_EPSILON) {
|
|
|
|
if (best.second != bc.GetCurrentAnimId()) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
|
|
|
}
|
2020-04-22 09:08:02 +00:00
|
|
|
x4_fallState = pas::EFallState(
|
|
|
|
bc.GetPASDatabase().GetAnimState(pas::EAnimationState::Getup)->GetAnimParmData(best.second, 2).GetEnumValue());
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
x4_fallState = pas::EFallState::Zero;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
pas::EAnimationState CBSGetup::GetBodyStateTransition(float dt, const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Hurled;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockDown)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Fall;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (bc.IsAnimationOver()) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (x4_fallState == pas::EFallState::Zero) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Getup;
|
|
|
|
}
|
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSGetup::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
|
|
|
return GetBodyStateTransition(dt, bc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSGetup::Shutdown(CBodyController& bc) { bc.SetFallState(x4_fallState); }
|
|
|
|
|
|
|
|
void CBSKnockBack::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const auto* cmd = static_cast<const CBCKnockBackCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockBack));
|
|
|
|
const zeus::CVector3f localDir = bc.GetOwner().GetTransform().transposeRotate(cmd->GetHitDirection());
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CRelAngle angle = std::atan2(localDir.y(), localDir.x());
|
2018-12-17 03:52:51 +00:00
|
|
|
angle.makeRel();
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::KnockBack, CPASAnimParm::FromReal32(angle.asDegrees()),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromEnum(s32(cmd->GetHitSeverity())));
|
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimState* knockbackState = bc.GetPASDatabase().GetAnimState(pas::EAnimationState::KnockBack);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!knockbackState->GetAnimParmData(best.second, 2).GetBoolValue()) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const float animAngle = zeus::degToRad(knockbackState->GetAnimParmData(best.second, 0).GetReal32Value());
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CRelAngle delta1 = angle - animAngle;
|
2018-12-17 03:52:51 +00:00
|
|
|
delta1.makeRel();
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CRelAngle delta2 = animAngle - angle;
|
2018-12-17 03:52:51 +00:00
|
|
|
delta2.makeRel();
|
2020-04-05 06:30:17 +00:00
|
|
|
const float minAngle = std::min(float(delta1), float(delta2));
|
|
|
|
const float flippedAngle = (delta1 > M_PIF) ? -minAngle : minAngle;
|
2018-12-08 05:30:43 +00:00
|
|
|
xc_remTime = 0.15f * bc.GetAnimTimeRemaining();
|
|
|
|
x8_rotateSpeed = (xc_remTime > FLT_EPSILON) ? flippedAngle / xc_remTime : flippedAngle;
|
|
|
|
} else {
|
|
|
|
xc_remTime = 0.f;
|
|
|
|
x8_rotateSpeed = 0.f;
|
|
|
|
}
|
|
|
|
x4_curTime = 0.f;
|
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
pas::EAnimationState CBSKnockBack::GetBodyStateTransition(float dt, const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Hurled;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockDown)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Fall;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopHitReaction)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopReaction;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockBack) && x4_curTime > 0.2f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::KnockBack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.IsAnimationOver()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSKnockBack::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (st == pas::EAnimationState::Invalid) {
|
|
|
|
x4_curTime += dt;
|
|
|
|
if (xc_remTime > 0.f) {
|
|
|
|
zeus::CQuaternion quat;
|
|
|
|
quat.rotateZ(x8_rotateSpeed * dt);
|
|
|
|
bc.SetDeltaRotation(quat);
|
|
|
|
xc_remTime -= dt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
CBSLieOnGround::CBSLieOnGround(CActor& actor) {
|
2020-04-22 09:08:02 +00:00
|
|
|
x4_24_hasGroundHit = actor.GetModelData()->GetAnimationData()->GetCharacterInfo().GetPASDatabase().HasState(
|
|
|
|
pas::EAnimationState::GroundHit);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBSLieOnGround::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::LieOnGround, CPASAnimParm::FromEnum(s32(bc.GetFallState())));
|
2020-04-05 06:30:17 +00:00
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (best.first > 0.f) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, true, false);
|
|
|
|
} else {
|
|
|
|
bc.EnableAnimation(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
pas::EAnimationState CBSLieOnGround::GetBodyStateTransition(float dt, const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Die)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Death;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (x4_24_hasGroundHit && bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockBack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::GroundHit;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (!bc.GetCommandMgr().GetCmd(EBodyStateCmd::Locomotion) && bc.GetCommandMgr().GetCmd(EBodyStateCmd::Getup)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Getup;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSLieOnGround::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
|
|
|
return GetBodyStateTransition(dt, bc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSLieOnGround::Shutdown(CBodyController& bc) { bc.EnableAnimation(true); }
|
|
|
|
|
|
|
|
void CBSStep::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const auto* cmd = static_cast<const CBCStepCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Step));
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Step, CPASAnimParm::FromEnum(s32(cmd->GetStepDirection())),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromEnum(s32(cmd->GetStepType())));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.PlayBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
pas::EAnimationState CBSStep::GetBodyStateTransition(float dt, const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Hurled;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockDown)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Fall;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopHitReaction)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopReaction;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockBack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::KnockBack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Locomotion)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Generate)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Generate;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::MeleeAttack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::MeleeAttack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::ProjectileAttack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::ProjectileAttack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopAttack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopAttack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Jump)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Jump;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopReaction)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopReaction;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Scripted)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Scripted;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.IsAnimationOver() || bc.GetCommandMgr().GetCmd(EBodyStateCmd::NextState)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSStep::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
|
|
|
if (st == pas::EAnimationState::Invalid && !bc.GetCommandMgr().GetTargetVector().isZero()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.FaceDirection(bc.GetCommandMgr().GetTargetVector(), dt);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSTurn::Start(CBodyController& bc, CStateManager& mgr) {
|
|
|
|
const zeus::CVector3f& lookDir = bc.GetOwner().GetTransform().basis[1];
|
2020-04-05 06:30:17 +00:00
|
|
|
const zeus::CVector2f lookDir2d(lookDir.toVec2f());
|
2018-12-08 05:30:43 +00:00
|
|
|
x8_dest = zeus::CVector2f(bc.GetCommandMgr().GetFaceVector().toVec2f());
|
2020-04-05 06:30:17 +00:00
|
|
|
const float deltaAngle = zeus::radToDeg(zeus::CVector2f::getAngleDiff(lookDir2d, x8_dest));
|
2018-12-08 05:30:43 +00:00
|
|
|
x10_turnDir = pas::ETurnDirection(zeus::CVector2f(lookDir2d.y(), -lookDir2d.x()).dot(x8_dest) > 0.f);
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Turn, CPASAnimParm::FromEnum(s32(x10_turnDir)),
|
|
|
|
CPASAnimParm::FromReal32(deltaAngle),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromEnum(s32(bc.GetLocomotionType())));
|
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
2020-04-22 09:08:02 +00:00
|
|
|
const float animAngle =
|
|
|
|
bc.GetPASDatabase().GetAnimState(pas::EAnimationState::Turn)->GetAnimParmData(best.second, 1).GetReal32Value();
|
2018-12-08 05:30:43 +00:00
|
|
|
x4_rotateSpeed =
|
|
|
|
zeus::degToRad((x10_turnDir == pas::ETurnDirection::Left) ? animAngle - deltaAngle : deltaAngle - animAngle);
|
2020-04-05 06:30:17 +00:00
|
|
|
const float timeRem = bc.GetAnimTimeRemaining();
|
|
|
|
if (timeRem > 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x4_rotateSpeed /= timeRem;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
bool CBSTurn::FacingDest(const CBodyController& bc) const {
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CVector3f& lookDir = bc.GetOwner().GetTransform().basis[1];
|
2020-04-05 06:30:17 +00:00
|
|
|
const zeus::CVector2f lookDir2d(lookDir.toVec2f());
|
|
|
|
const zeus::CVector2f leftDir(lookDir2d.y(), -lookDir2d.x());
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x10_turnDir == pas::ETurnDirection::Left) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (leftDir.dot(x8_dest) < 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (leftDir.dot(x8_dest) > 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-14 10:04:11 +00:00
|
|
|
pas::EAnimationState CBSTurn::GetBodyStateTransition(float dt, CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Hurled;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockDown)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Fall;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopHitReaction)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopReaction;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockBack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::KnockBack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Locomotion)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Generate)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Generate;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::MeleeAttack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::MeleeAttack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::ProjectileAttack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::ProjectileAttack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopAttack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopAttack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopReaction)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopReaction;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Jump)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Jump;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Step)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Step;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Scripted)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Scripted;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.IsAnimationOver() || FacingDest(bc) || !bc.GetCommandMgr().GetMoveVector().isZero()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSTurn::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (st == pas::EAnimationState::Invalid) {
|
|
|
|
zeus::CQuaternion quat;
|
|
|
|
quat.rotateZ(x4_rotateSpeed * dt);
|
|
|
|
bc.SetDeltaRotation(quat);
|
|
|
|
}
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSFlyerTurn::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-22 09:08:02 +00:00
|
|
|
if (bc.GetPASDatabase().GetAnimState(pas::EAnimationState::Turn)->HasAnims()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CBSTurn::Start(bc, mgr);
|
|
|
|
} else {
|
|
|
|
x8_dest = zeus::CVector2f(bc.GetCommandMgr().GetFaceVector().toVec2f());
|
|
|
|
const zeus::CVector3f& lookDir = bc.GetOwner().GetTransform().basis[1];
|
2020-04-05 06:30:17 +00:00
|
|
|
const zeus::CVector2f lookDir2d(lookDir.toVec2f());
|
2018-12-08 05:30:43 +00:00
|
|
|
x10_turnDir = pas::ETurnDirection(zeus::CVector2f(lookDir2d.y(), -lookDir2d.x()).dot(x8_dest) > 0.f);
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Locomotion, CPASAnimParm::FromEnum(0),
|
|
|
|
CPASAnimParm::FromEnum(s32(bc.GetLocomotionType())));
|
2020-04-05 06:30:17 +00:00
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (best.second != bc.GetCurrentAnimId()) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, true, false);
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
pas::EAnimationState CBSFlyerTurn::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-22 09:08:02 +00:00
|
|
|
if (bc.GetPASDatabase().GetAnimState(pas::EAnimationState::Turn)->HasAnims()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return CBSTurn::UpdateBody(dt, bc, mgr);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
|
|
|
if (st == pas::EAnimationState::Invalid) {
|
|
|
|
if (!bc.GetCommandMgr().GetFaceVector().isZero()) {
|
|
|
|
x8_dest = zeus::CVector2f(bc.GetCommandMgr().GetFaceVector().toVec2f());
|
|
|
|
const zeus::CVector3f& lookDir = bc.GetOwner().GetTransform().basis[1];
|
|
|
|
const zeus::CVector2f lookDir2d(lookDir.toVec2f());
|
|
|
|
x10_turnDir = pas::ETurnDirection(zeus::CVector2f(lookDir2d.y(), -lookDir2d.x()).dot(x8_dest) > 0.f);
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
bc.FaceDirection(zeus::CVector3f(x8_dest.x(), x8_dest.y(), 0.f), dt);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
return st;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBSLoopAttack::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const auto* cmd = static_cast<const CBCLoopAttackCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopAttack));
|
2018-12-08 05:30:43 +00:00
|
|
|
x8_loopAttackType = cmd->GetAttackType();
|
|
|
|
xc_24_waitForAnimOver = cmd->WaitForAnimOver();
|
|
|
|
xc_25_advance = false;
|
2020-04-05 06:30:17 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (bc.GetLocomotionType() == pas::ELocomotionType::Crouch) {
|
2022-11-14 01:05:35 +00:00
|
|
|
x4_state = pas::ELoopState::Loop;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::LoopAttack, CPASAnimParm::FromEnum(s32(x4_state)),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromEnum(s32(x8_loopAttackType)));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.LoopBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
} else {
|
|
|
|
x4_state = pas::ELoopState::Begin;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::LoopAttack, CPASAnimParm::FromEnum(s32(x4_state)),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromEnum(s32(x8_loopAttackType)));
|
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (best.first > FLT_EPSILON) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
|
|
|
} else {
|
|
|
|
x4_state = pas::ELoopState::Loop;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData loopParms(pas::EAnimationState::LoopAttack, CPASAnimParm::FromEnum(s32(x4_state)),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromEnum(s32(x8_loopAttackType)));
|
|
|
|
bc.LoopBestAnimation(loopParms, *mgr.GetActiveRandom());
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
pas::EAnimationState CBSLoopAttack::GetBodyStateTransition(float dt, const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Hurled;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockDown)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Fall;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopHitReaction)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopReaction;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockBack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::KnockBack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Locomotion)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x4_state == pas::ELoopState::End) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::MeleeAttack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::MeleeAttack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::ProjectileAttack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::ProjectileAttack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopAttack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopAttack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Step)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Step;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (!bc.GetCommandMgr().GetMoveVector().isZero()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (!bc.GetCommandMgr().GetFaceVector().isZero()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Turn;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSLoopAttack::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (st == pas::EAnimationState::Invalid) {
|
|
|
|
xc_25_advance |= bc.GetCommandMgr().GetCmd(EBodyStateCmd::ExitState) != nullptr;
|
|
|
|
switch (x4_state) {
|
|
|
|
case pas::ELoopState::Begin:
|
|
|
|
if (xc_25_advance && (!xc_24_waitForAnimOver || bc.IsAnimationOver())) {
|
|
|
|
x4_state = pas::ELoopState::Invalid;
|
2017-07-10 04:55:51 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
if (bc.IsAnimationOver()) {
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::LoopAttack, CPASAnimParm::FromEnum(1),
|
|
|
|
CPASAnimParm::FromEnum(s32(x8_loopAttackType)));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.LoopBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
x4_state = pas::ELoopState::Loop;
|
|
|
|
} else if (!bc.GetCommandMgr().GetTargetVector().isZero()) {
|
2017-07-10 04:55:51 +00:00
|
|
|
bc.FaceDirection(bc.GetCommandMgr().GetTargetVector(), dt);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case pas::ELoopState::Loop:
|
|
|
|
if (xc_25_advance && (!xc_24_waitForAnimOver || bc.IsAnimationOver())) {
|
|
|
|
if (bc.GetLocomotionType() != pas::ELocomotionType::Crouch) {
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::LoopAttack, CPASAnimParm::FromEnum(2),
|
|
|
|
CPASAnimParm::FromEnum(s32(x8_loopAttackType)));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.PlayBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
x4_state = pas::ELoopState::End;
|
|
|
|
} else {
|
|
|
|
x4_state = pas::ELoopState::Invalid;
|
|
|
|
return pas::EAnimationState::Locomotion;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case pas::ELoopState::End:
|
|
|
|
if (bc.IsAnimationOver()) {
|
|
|
|
x4_state = pas::ELoopState::Invalid;
|
2017-07-10 04:55:51 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSLoopReaction::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const auto* cmd =
|
2018-12-08 05:30:43 +00:00
|
|
|
static_cast<const CBCLoopReactionCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopReaction))) {
|
|
|
|
x8_reactionType = cmd->GetReactionType();
|
|
|
|
xc_24_loopHit = false;
|
|
|
|
} else {
|
2020-04-05 06:30:17 +00:00
|
|
|
const auto* hcmd =
|
2018-12-08 05:30:43 +00:00
|
|
|
static_cast<const CBCLoopHitReactionCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopHitReaction));
|
|
|
|
x8_reactionType = hcmd->GetReactionType();
|
|
|
|
xc_24_loopHit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
x4_state = pas::ELoopState::Begin;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::LoopReaction, CPASAnimParm::FromEnum(s32(x8_reactionType)),
|
|
|
|
CPASAnimParm::FromEnum(s32(x4_state)));
|
2020-04-05 06:30:17 +00:00
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (best.first > FLT_EPSILON) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
|
|
|
} else {
|
|
|
|
x4_state = pas::ELoopState::Loop;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData loopParms(pas::EAnimationState::LoopReaction, CPASAnimParm::FromEnum(s32(x8_reactionType)),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromEnum(s32(x4_state)));
|
2022-11-21 23:16:36 +00:00
|
|
|
// Intentionally using parms instead of loopParms
|
|
|
|
bc.LoopBestAnimation(parms, *mgr.GetActiveRandom());
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
pas::EAnimationState CBSLoopReaction::GetBodyStateTransition(float dt, const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Hurled;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockDown)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Fall;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockBack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::KnockBack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (!xc_24_loopHit && bc.GetCommandMgr().GetCmd(EBodyStateCmd::Locomotion)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x4_state == pas::ELoopState::End) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::MeleeAttack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::MeleeAttack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::ProjectileAttack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::ProjectileAttack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopAttack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopAttack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Step)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Step;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (!bc.GetCommandMgr().GetMoveVector().isZero()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (!bc.GetCommandMgr().GetFaceVector().isZero()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Turn;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CBSLoopReaction::PlayExitAnimation(CBodyController& bc, CStateManager& mgr) const {
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::LoopReaction, CPASAnimParm::FromEnum(int(x8_reactionType)),
|
|
|
|
CPASAnimParm::FromEnum(2));
|
2020-04-05 06:30:17 +00:00
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (best.first > 0.f) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSLoopReaction::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (st == pas::EAnimationState::Invalid) {
|
|
|
|
switch (x4_state) {
|
|
|
|
case pas::ELoopState::Begin:
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::ExitState)) {
|
|
|
|
if (PlayExitAnimation(bc, mgr)) {
|
|
|
|
x4_state = pas::ELoopState::End;
|
|
|
|
} else {
|
|
|
|
x4_state = pas::ELoopState::Invalid;
|
|
|
|
return pas::EAnimationState::Locomotion;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
if (bc.IsAnimationOver()) {
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::LoopReaction, CPASAnimParm::FromEnum(s32(x8_reactionType)),
|
|
|
|
CPASAnimParm::FromEnum(1));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.LoopBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
x4_state = pas::ELoopState::Loop;
|
|
|
|
} else if (!bc.GetCommandMgr().GetTargetVector().isZero()) {
|
|
|
|
bc.FaceDirection(bc.GetCommandMgr().GetTargetVector(), dt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case pas::ELoopState::Loop:
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::ExitState)) {
|
|
|
|
if (PlayExitAnimation(bc, mgr)) {
|
|
|
|
x4_state = pas::ELoopState::End;
|
|
|
|
} else {
|
|
|
|
x4_state = pas::ELoopState::Invalid;
|
|
|
|
return pas::EAnimationState::Locomotion;
|
|
|
|
}
|
|
|
|
} else if (!bc.GetCommandMgr().GetTargetVector().isZero()) {
|
|
|
|
bc.FaceDirection(bc.GetCommandMgr().GetTargetVector(), dt);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case pas::ELoopState::End:
|
|
|
|
if (bc.IsAnimationOver()) {
|
|
|
|
x4_state = pas::ELoopState::Invalid;
|
|
|
|
return pas::EAnimationState::Locomotion;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSGroundHit::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const auto* cmd = static_cast<const CBCKnockBackCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockBack));
|
|
|
|
const zeus::CVector3f localDir = bc.GetOwner().GetTransform().transposeRotate(cmd->GetHitDirection());
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CRelAngle angle = std::atan2(localDir.y(), localDir.x());
|
2018-12-17 03:52:51 +00:00
|
|
|
angle.makeRel();
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::GroundHit, CPASAnimParm::FromEnum(s32(bc.GetFallState())),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromReal32(angle.asDegrees()));
|
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimState* groundHitState = bc.GetPASDatabase().GetAnimState(pas::EAnimationState::GroundHit);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!groundHitState->GetAnimParmData(best.second, 2).GetBoolValue()) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const float animAngle = zeus::degToRad(groundHitState->GetAnimParmData(best.second, 1).GetReal32Value());
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CRelAngle delta1 = angle - animAngle;
|
2018-12-17 03:52:51 +00:00
|
|
|
delta1.makeRel();
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CRelAngle delta2 = animAngle - angle;
|
2018-12-17 03:52:51 +00:00
|
|
|
delta2.makeRel();
|
2020-04-05 06:30:17 +00:00
|
|
|
const float minAngle = std::min(float(delta1), float(delta2));
|
|
|
|
const float flippedAngle = (delta1 > M_PIF) ? -minAngle : minAngle;
|
2018-12-08 05:30:43 +00:00
|
|
|
x8_remTime = 0.15f * bc.GetAnimTimeRemaining();
|
|
|
|
x4_rotateSpeed = (x8_remTime > FLT_EPSILON) ? flippedAngle / x8_remTime : flippedAngle;
|
|
|
|
} else {
|
|
|
|
x8_remTime = 0.f;
|
|
|
|
x4_rotateSpeed = 0.f;
|
|
|
|
}
|
|
|
|
xc_fallState = pas::EFallState(groundHitState->GetAnimParmData(best.second, 3).GetEnumValue());
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
pas::EAnimationState CBSGroundHit::GetBodyStateTransition(float dt, const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (!bc.IsAnimationOver()) {
|
|
|
|
return pas::EAnimationState::Invalid;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Die)) {
|
|
|
|
return pas::EAnimationState::Death;
|
|
|
|
}
|
|
|
|
return pas::EAnimationState::LieOnGround;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSGroundHit::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (st == pas::EAnimationState::Invalid && x8_remTime > 0.f) {
|
|
|
|
zeus::CQuaternion quat;
|
|
|
|
quat.rotateZ(x4_rotateSpeed * dt);
|
|
|
|
bc.SetDeltaRotation(quat);
|
|
|
|
x8_remTime -= dt;
|
|
|
|
}
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSGroundHit::Shutdown(CBodyController& bc) { bc.SetFallState(xc_fallState); }
|
|
|
|
|
|
|
|
void CBSGenerate::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const auto* cmd = static_cast<const CBCGenerateCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Generate));
|
2018-12-08 05:30:43 +00:00
|
|
|
s32 anim;
|
|
|
|
if (!cmd->UseSpecialAnimId()) {
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Generate, CPASAnimParm::FromEnum(s32(cmd->GetGenerateType())));
|
2020-04-05 06:30:17 +00:00
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
2018-12-08 05:30:43 +00:00
|
|
|
anim = best.second;
|
|
|
|
} else {
|
|
|
|
anim = cmd->GetSpecialAnimId();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmd->HasExitTargetPos()) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(anim, nullptr, &cmd->GetExitTargetPos(), &bc.GetOwner().GetTransform(),
|
|
|
|
&bc.GetOwner().GetModelData()->GetScale(), false);
|
2017-07-10 04:55:51 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(anim, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
pas::EAnimationState CBSGenerate::GetBodyStateTransition(float dt, const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Hurled;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockDown)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Fall;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Generate)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Generate;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.IsAnimationOver() || bc.GetCommandMgr().GetCmd(EBodyStateCmd::NextState)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSGenerate::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
|
|
|
if (st == pas::EAnimationState::Invalid) {
|
|
|
|
if (!bc.GetCommandMgr().GetTargetVector().isZero()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.FaceDirection(bc.GetCommandMgr().GetTargetVector(), dt);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSJump::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const auto* cmd = static_cast<const CBCJumpCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Jump));
|
2018-12-08 05:30:43 +00:00
|
|
|
x8_jumpType = cmd->GetJumpType();
|
|
|
|
xc_waypoint1 = cmd->GetJumpTarget();
|
|
|
|
x24_waypoint2 = cmd->GetSecondJumpTarget();
|
|
|
|
x30_25_wallJump = cmd->IsWallJump();
|
|
|
|
x30_28_startInJumpLoop = cmd->StartInJumpLoop();
|
|
|
|
x30_24_bodyForceSet = false;
|
|
|
|
x30_27_wallBounceComplete = false;
|
2020-04-05 06:30:17 +00:00
|
|
|
if (x30_25_wallJump) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x30_26_wallBounceRight =
|
2020-04-05 06:30:17 +00:00
|
|
|
(xc_waypoint1 - bc.GetOwner().GetTranslation()).cross(zeus::skUp).dot(x24_waypoint2 - xc_waypoint1) < 0.f;
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!cmd->StartInJumpLoop()) {
|
|
|
|
x4_state = pas::EJumpState::IntoJump;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Jump, CPASAnimParm::FromEnum(s32(x4_state)),
|
|
|
|
CPASAnimParm::FromEnum(s32(x8_jumpType)));
|
2017-07-10 04:55:51 +00:00
|
|
|
bc.PlayBestAnimation(parms, *mgr.GetActiveRandom());
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
PlayJumpLoop(mgr, bc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
pas::EAnimationState CBSJump::GetBodyStateTransition(float dt, const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Hurled;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockDown)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Fall;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Jump) && bc.GetBodyType() == EBodyType::WallWalker) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Jump;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CBSJump::CheckForWallJump(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (!x30_25_wallJump || x30_27_wallBounceComplete) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const TCastToPtr<CPatterned> act = bc.GetOwner()) {
|
|
|
|
const float distToWall = (xc_waypoint1 - act->GetTranslation()).magnitude();
|
|
|
|
const zeus::CAABox aabb = act->GetBoundingBox();
|
|
|
|
const float xExtent = (aabb.max.x() - aabb.min.x()) * 0.5f;
|
|
|
|
if (distToWall < 1.414f * xExtent || (act->MadeSolidCollision() && distToWall < 3.f * xExtent)) {
|
|
|
|
x4_state = x30_26_wallBounceRight ? pas::EJumpState::WallBounceRight : pas::EJumpState::WallBounceLeft;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Jump, CPASAnimParm::FromEnum(s32(x4_state)),
|
|
|
|
CPASAnimParm::FromEnum(s32(x8_jumpType)));
|
2020-04-05 06:30:17 +00:00
|
|
|
bc.PlayBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
mgr.SendScriptMsg(act.GetPtr(), kInvalidUniqueId, EScriptObjectMessage::OnFloor);
|
|
|
|
return true;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CBSJump::CheckForLand(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToPtr<CPatterned> act = bc.GetOwner()) {
|
2019-01-03 03:47:28 +00:00
|
|
|
if (act->MadeSolidCollision() || act->IsOnGround()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x4_state = pas::EJumpState::OutOfJump;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Jump, CPASAnimParm::FromEnum(s32(x4_state)),
|
|
|
|
CPASAnimParm::FromEnum(s32(x8_jumpType)));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.PlayBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
mgr.SendScriptMsg(act.GetPtr(), kInvalidUniqueId, EScriptObjectMessage::OnFloor);
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CBSJump::PlayJumpLoop(CStateManager& mgr, CBodyController& bc) {
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Jump, CPASAnimParm::FromEnum(1),
|
|
|
|
CPASAnimParm::FromEnum(s32(x8_jumpType)));
|
2020-04-05 06:30:17 +00:00
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (best.first > 99.f) {
|
|
|
|
x4_state = pas::EJumpState::AmbushJump;
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
|
|
|
} else {
|
|
|
|
x4_state = pas::EJumpState::Loop;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData loopParms(pas::EAnimationState::Jump, CPASAnimParm::FromEnum(s32(x4_state)),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromEnum(s32(x8_jumpType)));
|
|
|
|
bc.LoopBestAnimation(loopParms, *mgr.GetActiveRandom());
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToPtr<CPhysicsActor> act = bc.GetOwner()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.SendScriptMsg(act.GetPtr(), kInvalidUniqueId, EScriptObjectMessage::Falling);
|
|
|
|
mgr.SendScriptMsg(act.GetPtr(), kInvalidUniqueId, EScriptObjectMessage::Jumped);
|
|
|
|
x30_24_bodyForceSet = false;
|
|
|
|
x18_velocity = act->GetVelocity();
|
|
|
|
}
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
pas::EAnimationState CBSJump::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (st == pas::EAnimationState::Invalid) {
|
|
|
|
switch (x4_state) {
|
|
|
|
case pas::EJumpState::IntoJump:
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.IsAnimationOver()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
PlayJumpLoop(mgr, bc);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
case pas::EJumpState::AmbushJump:
|
|
|
|
if (!x30_24_bodyForceSet) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToPtr<CPhysicsActor> act = bc.GetOwner()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
act->SetConstantForce(act->GetMass() * x18_velocity);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
x30_24_bodyForceSet = true;
|
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
if (!bc.GetCommandMgr().GetTargetVector().isZero()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.FaceDirection(bc.GetCommandMgr().GetTargetVector(), dt);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (bc.IsAnimationOver()) {
|
|
|
|
x4_state = pas::EJumpState::Loop;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Jump, CPASAnimParm::FromEnum(s32(x4_state)),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromEnum(s32(x8_jumpType)));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.LoopBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
} else {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (!CheckForWallJump(bc, mgr)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CheckForLand(bc, mgr);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case pas::EJumpState::Loop:
|
|
|
|
if (!x30_24_bodyForceSet) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToPtr<CPhysicsActor> act = bc.GetOwner()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
act->SetConstantForce(act->GetMass() * x18_velocity);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
x30_24_bodyForceSet = true;
|
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
if (!bc.GetCommandMgr().GetTargetVector().isZero()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.FaceDirection(bc.GetCommandMgr().GetTargetVector(), dt);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (!CheckForWallJump(bc, mgr)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CheckForLand(bc, mgr);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
case pas::EJumpState::WallBounceLeft:
|
|
|
|
case pas::EJumpState::WallBounceRight:
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToPtr<CPhysicsActor> act = bc.GetOwner()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
act->Stop();
|
2019-02-24 07:15:54 +00:00
|
|
|
act->SetMomentumWR(zeus::skZero3f);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
if (bc.IsAnimationOver()) {
|
|
|
|
mgr.SendScriptMsg(&bc.GetOwner(), kInvalidUniqueId, EScriptObjectMessage::Falling);
|
|
|
|
x4_state = pas::EJumpState::Loop;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Jump, CPASAnimParm::FromEnum(s32(x4_state)),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromEnum(s32(x8_jumpType)));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.LoopBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
x30_27_wallBounceComplete = true;
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToPtr<CPatterned> act = bc.GetOwner()) {
|
|
|
|
const zeus::CVector3f toFinal = x24_waypoint2 - act->GetTranslation();
|
|
|
|
const float tmp = std::sqrt(act->GetGravityConstant() / (2.f * toFinal.z()));
|
2018-12-08 05:30:43 +00:00
|
|
|
act->SetVelocityWR(zeus::CVector3f(tmp * toFinal.x(), tmp * toFinal.y(), 0.f));
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case pas::EJumpState::OutOfJump:
|
|
|
|
if (bc.IsAnimationOver()) {
|
|
|
|
x4_state = pas::EJumpState::Invalid;
|
|
|
|
return pas::EAnimationState::Locomotion;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
return st;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CBSJump::ApplyAnimationDeltas() const {
|
2020-04-22 09:08:02 +00:00
|
|
|
return !(x4_state == pas::EJumpState::AmbushJump || x4_state == pas::EJumpState::Loop);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CBSJump::IsInAir(const CBodyController& bc) const {
|
|
|
|
return x4_state == pas::EJumpState::AmbushJump || x4_state == pas::EJumpState::Loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CBSJump::CanShoot() const { return x4_state == pas::EJumpState::AmbushJump || x4_state == pas::EJumpState::Loop; }
|
|
|
|
|
|
|
|
void CBSHurled::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const auto* cmd = static_cast<const CBCHurledCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled));
|
2018-12-08 05:30:43 +00:00
|
|
|
x4_state = pas::EHurledState(cmd->GetSkipLaunchState());
|
2020-04-05 06:30:17 +00:00
|
|
|
const zeus::CVector3f localDir = bc.GetOwner().GetTransform().transposeRotate(cmd->GetHitDirection());
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CRelAngle angle = std::atan2(localDir.y(), localDir.x());
|
2018-12-17 03:52:51 +00:00
|
|
|
angle.makeRel();
|
2018-12-08 05:30:43 +00:00
|
|
|
x8_knockAngle = angle.asDegrees();
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Hurled, CPASAnimParm::FromInt32(-1),
|
|
|
|
CPASAnimParm::FromReal32(x8_knockAngle), CPASAnimParm::FromEnum(s32(x4_state)));
|
2020-04-05 06:30:17 +00:00
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimState* hurledState = bc.GetPASDatabase().GetAnimState(pas::EAnimationState::Hurled);
|
2018-12-08 05:30:43 +00:00
|
|
|
xc_animSeries = hurledState->GetAnimParmData(best.second, 0).GetInt32Value();
|
|
|
|
mgr.SendScriptMsg(&bc.GetOwner(), kInvalidUniqueId, EScriptObjectMessage::Falling);
|
|
|
|
mgr.SendScriptMsg(&bc.GetOwner(), kInvalidUniqueId, EScriptObjectMessage::Jumped);
|
2020-04-05 06:30:17 +00:00
|
|
|
if (!zeus::close_enough(cmd->GetLaunchVelocity(), zeus::skZero3f, 0.0001f)) {
|
|
|
|
if (const TCastToPtr<CPhysicsActor> act = bc.GetOwner()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
act->SetConstantForce(act->GetMass() * cmd->GetLaunchVelocity());
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const float animAngle = zeus::degToRad(hurledState->GetAnimParmData(best.second, 1).GetReal32Value());
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CRelAngle delta1 = angle - animAngle;
|
2018-12-17 03:52:51 +00:00
|
|
|
delta1.makeRel();
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CRelAngle delta2 = animAngle - angle;
|
2018-12-17 03:52:51 +00:00
|
|
|
delta2.makeRel();
|
2020-04-05 06:30:17 +00:00
|
|
|
const float minAngle = std::min(float(delta1), float(delta2));
|
2018-12-08 05:30:43 +00:00
|
|
|
x14_remTime = 0.15f * bc.GetAnimTimeRemaining();
|
2020-04-05 06:30:17 +00:00
|
|
|
const float flippedAngle = (delta1 > M_PIF) ? -minAngle : minAngle;
|
2018-12-08 05:30:43 +00:00
|
|
|
x10_rotateSpeed = (x14_remTime > FLT_EPSILON) ? flippedAngle / x14_remTime : flippedAngle;
|
|
|
|
x18_curTime = 0.f;
|
|
|
|
x2c_24_needsRecover = false;
|
|
|
|
}
|
|
|
|
|
2019-08-14 10:04:11 +00:00
|
|
|
pas::EAnimationState CBSHurled::GetBodyStateTransition(float dt, CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::NextState)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LieOnGround;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2020-04-05 07:20:52 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x18_curTime > 0.25f) {
|
2020-04-05 07:20:52 +00:00
|
|
|
if (auto* cmd = static_cast<CBCHurledCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled))) {
|
|
|
|
cmd->SetSkipLaunchState(true);
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Hurled;
|
|
|
|
}
|
|
|
|
}
|
2020-04-05 07:20:52 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSHurled::Recover(CStateManager& mgr, CBodyController& bc, pas::EHurledState state) {
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Hurled, CPASAnimParm::FromInt32(xc_animSeries),
|
|
|
|
CPASAnimParm::FromReal32(x8_knockAngle), CPASAnimParm::FromEnum(s32(state)));
|
2020-04-05 06:30:17 +00:00
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (best.first > FLT_EPSILON) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
|
|
|
x4_state = state;
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToPtr<CPhysicsActor> act = bc.GetOwner()) {
|
2019-02-24 07:15:54 +00:00
|
|
|
act->SetMomentumWR(zeus::skZero3f);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
x2c_24_needsRecover = false;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CBSHurled::PlayStrikeWallAnimation(CBodyController& bc, CStateManager& mgr) {
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Hurled, CPASAnimParm::FromInt32(xc_animSeries),
|
|
|
|
CPASAnimParm::FromReal32(x8_knockAngle), CPASAnimParm::FromEnum(3));
|
2020-04-05 06:30:17 +00:00
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
|
|
|
|
|
|
|
if (best.first <= FLT_EPSILON) {
|
|
|
|
return;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
|
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
|
|
|
x4_state = pas::EHurledState::StrikeWall;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBSHurled::PlayLandAnimation(CBodyController& bc, CStateManager& mgr) {
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Hurled, CPASAnimParm::FromInt32(xc_animSeries),
|
|
|
|
CPASAnimParm::FromReal32(x8_knockAngle), CPASAnimParm::FromEnum(s32(x4_state)));
|
2020-04-05 06:30:17 +00:00
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimState* hurledState = bc.GetPASDatabase().GetAnimState(pas::EAnimationState::Hurled);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetFallState(pas::EFallState(hurledState->GetAnimParmData(best.second, 3).GetEnumValue()));
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToPtr<CPhysicsActor> act = bc.GetOwner()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.SendScriptMsg(act.GetPtr(), kInvalidUniqueId, EScriptObjectMessage::OnFloor);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
2020-05-26 02:20:02 +00:00
|
|
|
bool CBSHurled::ShouldStartStrikeWall(const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToConstPtr<CPatterned> ai = bc.GetOwner()) {
|
|
|
|
if (ai->MadeSolidCollision()) {
|
|
|
|
if (!ai->IsOnGround()) {
|
2017-07-10 04:55:51 +00:00
|
|
|
return true;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-26 02:20:02 +00:00
|
|
|
bool CBSHurled::ShouldStartLand(float dt, const CBodyController& bc) const {
|
2018-12-08 05:30:43 +00:00
|
|
|
bool ret = true;
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToConstPtr<CPatterned> ai = bc.GetOwner()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ret = false;
|
2020-04-05 06:30:17 +00:00
|
|
|
if (ai->IsOnGround()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (zeus::close_enough(ai->GetTranslation(), x1c_lastTranslation, 0.0001f) && ai->GetVelocity().z() < 0.f) {
|
|
|
|
x28_landedDur += dt;
|
2020-04-05 06:30:17 +00:00
|
|
|
if (x28_landedDur >= 0.25f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ret = true;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
x28_landedDur = 0.f;
|
|
|
|
}
|
|
|
|
x1c_lastTranslation = ai->GetTranslation();
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSHurled::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (st == pas::EAnimationState::Invalid) {
|
|
|
|
x18_curTime += dt;
|
|
|
|
if (x14_remTime > 0.f) {
|
|
|
|
zeus::CQuaternion quat;
|
|
|
|
quat.rotateZ(x10_rotateSpeed * dt);
|
|
|
|
bc.SetDeltaRotation(quat);
|
|
|
|
x14_remTime -= dt;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::ExitState)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x2c_24_needsRecover = true;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
switch (x4_state) {
|
|
|
|
case pas::EHurledState::KnockIntoAir: {
|
|
|
|
if (bc.IsAnimationOver()) {
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Hurled, CPASAnimParm::FromInt32(xc_animSeries),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromReal32(x8_knockAngle), CPASAnimParm::FromEnum(1));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.LoopBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
x4_state = pas::EHurledState::KnockLoop;
|
|
|
|
x28_landedDur = 0.f;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case pas::EHurledState::KnockLoop:
|
|
|
|
if (ShouldStartLand(dt, bc)) {
|
|
|
|
x4_state = pas::EHurledState::KnockDown;
|
|
|
|
PlayLandAnimation(bc, mgr);
|
|
|
|
} else if (ShouldStartStrikeWall(bc)) {
|
|
|
|
PlayStrikeWallAnimation(bc, mgr);
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToPtr<CPatterned> ai = bc.GetOwner()) {
|
2019-02-24 07:15:54 +00:00
|
|
|
ai->SetVelocityWR(zeus::skDown * (2.f * dt * ai->GetGravityConstant()));
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else if (x2c_24_needsRecover) {
|
|
|
|
Recover(mgr, bc, pas::EHurledState::Six);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case pas::EHurledState::StrikeWall:
|
|
|
|
if (bc.IsAnimationOver()) {
|
|
|
|
x4_state = pas::EHurledState::StrikeWallFallLoop;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Hurled, CPASAnimParm::FromInt32(xc_animSeries),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromReal32(x8_knockAngle), CPASAnimParm::FromEnum(s32(x4_state)));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.LoopBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
x28_landedDur = 0.f;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case pas::EHurledState::StrikeWallFallLoop:
|
|
|
|
if (ShouldStartLand(dt, bc)) {
|
|
|
|
x4_state = pas::EHurledState::OutOfStrikeWall;
|
|
|
|
PlayLandAnimation(bc, mgr);
|
|
|
|
} else if (x2c_24_needsRecover) {
|
|
|
|
Recover(mgr, bc, pas::EHurledState::Seven);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case pas::EHurledState::Six:
|
|
|
|
case pas::EHurledState::Seven:
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToPtr<CPhysicsActor> act = bc.GetOwner()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
act->SetVelocityWR(act->GetVelocity() * std::pow(0.9, 60.0 * dt));
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (bc.IsAnimationOver()) {
|
|
|
|
x4_state = pas::EHurledState::Invalid;
|
|
|
|
return pas::EAnimationState::Locomotion;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case pas::EHurledState::KnockDown:
|
|
|
|
case pas::EHurledState::OutOfStrikeWall:
|
|
|
|
if (bc.IsAnimationOver()) {
|
|
|
|
x4_state = pas::EHurledState::Invalid;
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetFallState() == pas::EFallState::Zero) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LieOnGround;
|
|
|
|
}
|
|
|
|
break;
|
2017-07-10 04:55:51 +00:00
|
|
|
default:
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSSlide::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const auto* cmd = static_cast<const CBCSlideCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Slide));
|
|
|
|
const zeus::CVector3f localDir = bc.GetOwner().GetTransform().transposeRotate(cmd->GetSlideDirection());
|
|
|
|
const float angle = std::atan2(localDir.y(), localDir.x());
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Slide, CPASAnimParm::FromEnum(s32(cmd->GetSlideType())),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromReal32(zeus::radToDeg(angle)));
|
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
2020-04-05 06:30:17 +00:00
|
|
|
const float timeRem = bc.GetAnimTimeRemaining();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (timeRem > FLT_EPSILON) {
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimState* slideState = bc.GetPASDatabase().GetAnimState(pas::EAnimationState::Slide);
|
2020-04-05 06:30:17 +00:00
|
|
|
const float animAngle = zeus::degToRad(slideState->GetAnimParmData(best.second, 1).GetReal32Value());
|
|
|
|
const float delta1 = zeus::CRelAngle(angle - animAngle).asRel();
|
|
|
|
const float flippedAngle = (delta1 > M_PIF) ? delta1 - 2.f * M_PIF : delta1;
|
2018-12-08 05:30:43 +00:00
|
|
|
x4_rotateSpeed = flippedAngle / timeRem;
|
|
|
|
} else {
|
|
|
|
x4_rotateSpeed = 0.f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
pas::EAnimationState CBSSlide::GetBodyStateTransition(float dt, const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Hurled;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockDown)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Fall;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopHitReaction)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopReaction;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockBack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::KnockBack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.IsAnimationOver()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSSlide::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (st == pas::EAnimationState::Invalid && x4_rotateSpeed != 0.f) {
|
|
|
|
zeus::CQuaternion quat;
|
|
|
|
quat.rotateZ(x4_rotateSpeed * dt);
|
|
|
|
bc.SetDeltaRotation(quat);
|
|
|
|
}
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSTaunt::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const auto* cmd = static_cast<const CBCTauntCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Taunt));
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Taunt, CPASAnimParm::FromEnum(s32(cmd->GetTauntType())));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.PlayBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
pas::EAnimationState CBSTaunt::GetBodyStateTransition(float dt, const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Hurled;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockDown)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Fall;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopHitReaction)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopReaction;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockBack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::KnockBack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Locomotion)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.IsAnimationOver()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSTaunt::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
|
|
|
if (st == pas::EAnimationState::Invalid && !bc.GetCommandMgr().GetTargetVector().isZero()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.FaceDirection(bc.GetCommandMgr().GetTargetVector(), dt);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSScripted::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const auto* cmd = static_cast<const CBCScriptedCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Scripted));
|
2018-12-08 05:30:43 +00:00
|
|
|
x4_24_loopAnim = cmd->IsLooped();
|
|
|
|
x4_25_timedLoop = cmd->GetUseLoopDuration();
|
|
|
|
x8_remTime = cmd->GetLoopDuration();
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(cmd->GetAnimId(), -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, cmd->IsLooped(), false);
|
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
pas::EAnimationState CBSScripted::GetBodyStateTransition(float dt, const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Hurled;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockDown)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Fall;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopHitReaction)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopReaction;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockBack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::KnockBack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Scripted)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Scripted;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2022-10-28 11:22:58 +00:00
|
|
|
if (x4_24_loopAnim) {
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::ExitState)) {
|
|
|
|
return pas::EAnimationState::Locomotion;
|
|
|
|
}
|
|
|
|
} else if (bc.IsAnimationOver()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSScripted::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (st == pas::EAnimationState::Invalid) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (!bc.GetCommandMgr().GetTargetVector().isZero()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.FaceDirection(bc.GetCommandMgr().GetTargetVector(), dt);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x4_24_loopAnim && x4_25_timedLoop) {
|
|
|
|
x8_remTime -= dt;
|
2020-04-05 06:30:17 +00:00
|
|
|
if (x8_remTime <= 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSCover::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const auto* cmd = static_cast<const CBCCoverCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Cover));
|
2018-12-08 05:30:43 +00:00
|
|
|
x8_coverDirection = cmd->GetDirection();
|
|
|
|
x4_state = pas::ECoverState::IntoCover;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Cover, CPASAnimParm::FromEnum(s32(x4_state)),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromEnum(s32(x8_coverDirection)));
|
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
|
|
|
const zeus::CQuaternion orientDelta =
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CQuaternion::lookAt(zeus::skForward, cmd->GetAlignDirection(), 2.f * M_PIF);
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(best.second, &orientDelta, &cmd->GetTarget(), &bc.GetOwner().GetTransform(),
|
|
|
|
&bc.GetOwner().GetModelData()->GetScale(), false);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
|
|
|
xc_needsExit = false;
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::ExitState)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
xc_needsExit = true;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
pas::EAnimationState CBSCover::GetBodyStateTransition(float dt, const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Hurled;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockDown)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Fall;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopHitReaction)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopReaction;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockBack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::KnockBack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Locomotion)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSCover::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (st == pas::EAnimationState::Invalid) {
|
|
|
|
switch (x4_state) {
|
|
|
|
case pas::ECoverState::Lean:
|
|
|
|
case pas::ECoverState::IntoCover:
|
|
|
|
if (bc.IsAnimationOver()) {
|
|
|
|
x4_state = pas::ECoverState::Cover;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Cover, CPASAnimParm::FromEnum(s32(x4_state)),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromEnum(s32(x8_coverDirection)));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.LoopBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::ExitState)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
xc_needsExit = true;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
case pas::ECoverState::Cover:
|
2020-04-05 06:30:17 +00:00
|
|
|
if (!bc.GetCommandMgr().GetTargetVector().isZero()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.FaceDirection(bc.GetCommandMgr().GetTargetVector(), dt);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::ExitState) || xc_needsExit) {
|
|
|
|
xc_needsExit = false;
|
|
|
|
x4_state = pas::ECoverState::OutOfCover;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Cover, CPASAnimParm::FromEnum(s32(x4_state)),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromEnum(s32(x8_coverDirection)));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.PlayBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
} else if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LeanFromCover)) {
|
|
|
|
x4_state = pas::ECoverState::Lean;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Cover, CPASAnimParm::FromEnum(s32(x4_state)),
|
2020-04-05 06:30:17 +00:00
|
|
|
CPASAnimParm::FromEnum(s32(x8_coverDirection)));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.PlayBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case pas::ECoverState::OutOfCover:
|
|
|
|
if (bc.IsAnimationOver()) {
|
|
|
|
x4_state = pas::ECoverState::Invalid;
|
|
|
|
return pas::EAnimationState::Locomotion;
|
|
|
|
}
|
|
|
|
break;
|
2017-07-10 04:55:51 +00:00
|
|
|
default:
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSWallHang::Start(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const auto* cmd = static_cast<const CBCWallHangCmd*>(bc.GetCommandMgr().GetCmd(EBodyStateCmd::WallHang));
|
2018-12-08 05:30:43 +00:00
|
|
|
x4_state = pas::EWallHangState::IntoJump;
|
|
|
|
x8_wpId = cmd->GetTarget();
|
|
|
|
x18_25_needsExit = false;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state)));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.PlayBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
}
|
|
|
|
|
2020-04-05 07:10:32 +00:00
|
|
|
pas::EAnimationState CBSWallHang::GetBodyStateTransition(float dt, const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Hurled;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockDown)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Fall;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSWallHang::FixInPlace(CBodyController& bc) {
|
2022-08-16 21:48:26 +00:00
|
|
|
if (const TCastToPtr<CPatterned> ai = bc.GetOwner()) {
|
2019-02-24 07:15:54 +00:00
|
|
|
ai->SetConstantForce(zeus::skZero3f);
|
|
|
|
ai->SetVelocityWR(zeus::skZero3f);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CBSWallHang::CheckForLand(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToPtr<CPatterned> ai = bc.GetOwner()) {
|
2019-01-03 03:47:28 +00:00
|
|
|
if (ai->MadeSolidCollision() || ai->IsOnGround()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x4_state = pas::EWallHangState::DetachOutOfJump;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state)));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.PlayBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
mgr.SendScriptMsg(ai.GetPtr(), kInvalidUniqueId, EScriptObjectMessage::OnFloor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CBSWallHang::CheckForWall(CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToPtr<CPatterned> ai = bc.GetOwner()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
float magSq = 10.f;
|
2020-04-05 06:30:17 +00:00
|
|
|
const TCastToConstPtr<CActor> wp = mgr.ObjectById(x8_wpId);
|
|
|
|
if (wp) {
|
2018-12-08 05:30:43 +00:00
|
|
|
magSq = (wp->GetTranslation() - ai->GetTranslation()).magSquared();
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2019-01-03 03:47:28 +00:00
|
|
|
if (magSq < 1.f || ai->MadeSolidCollision()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x4_state = pas::EWallHangState::IntoWallHang;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state)));
|
2020-04-05 06:30:17 +00:00
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CVector3f& target = wp ? wp->GetTranslation() : ai->GetTranslation();
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(best.second, nullptr, &target, &bc.GetOwner().GetTransform(),
|
|
|
|
&bc.GetOwner().GetModelData()->GetScale(), false);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
2019-02-24 07:15:54 +00:00
|
|
|
ai->SetVelocityWR(zeus::skZero3f);
|
|
|
|
ai->SetMomentumWR(zeus::skZero3f);
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.SendScriptMsg(ai.GetPtr(), kInvalidUniqueId, EScriptObjectMessage::OnFloor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSWallHang::SetLaunchVelocity(CBodyController& bc) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (x18_24_launched) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const TCastToPtr<CPhysicsActor> act = bc.GetOwner()) {
|
|
|
|
act->SetVelocityWR(xc_launchVel);
|
|
|
|
act->SetConstantForce(xc_launchVel * act->GetMass());
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
|
|
|
|
x18_24_launched = true;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSWallHang::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (st == pas::EAnimationState::Invalid) {
|
|
|
|
switch (x4_state) {
|
|
|
|
case pas::EWallHangState::IntoJump: {
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(1));
|
2020-04-05 06:30:17 +00:00
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (best.first > 0.f) {
|
|
|
|
x4_state = pas::EWallHangState::JumpArc;
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
|
|
|
} else {
|
|
|
|
x4_state = pas::EWallHangState::JumpAirLoop;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData loopParms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state)));
|
2020-04-05 06:30:17 +00:00
|
|
|
bc.LoopBestAnimation(loopParms, *mgr.GetActiveRandom());
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToPtr<CPhysicsActor> act = bc.GetOwner()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.SendScriptMsg(act.GetPtr(), kInvalidUniqueId, EScriptObjectMessage::Jumped);
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToConstPtr<CActor> wp = mgr.ObjectById(x8_wpId)) {
|
|
|
|
const zeus::CVector3f toWp = wp->GetTranslation() - act->GetTranslation();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (toWp.z() > 0.f) {
|
|
|
|
float tmp = -act->GetMomentum().z() / act->GetMass();
|
2020-04-05 06:30:17 +00:00
|
|
|
const float tmp2 = std::sqrt(tmp * 2.f * toWp.z());
|
2018-12-08 05:30:43 +00:00
|
|
|
tmp = 1.f / (tmp2 / tmp);
|
|
|
|
xc_launchVel = zeus::CVector3f(tmp * toWp.x(), tmp * toWp.y(), tmp2);
|
|
|
|
x18_24_launched = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case pas::EWallHangState::JumpArc: {
|
|
|
|
SetLaunchVelocity(bc);
|
|
|
|
if (bc.IsAnimationOver()) {
|
|
|
|
x4_state = pas::EWallHangState::JumpAirLoop;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state)));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.LoopBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
} else {
|
|
|
|
CheckForWall(bc, mgr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case pas::EWallHangState::JumpAirLoop: {
|
|
|
|
SetLaunchVelocity(bc);
|
2020-04-05 06:30:17 +00:00
|
|
|
if (!CheckForWall(bc, mgr)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CheckForLand(bc, mgr);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case pas::EWallHangState::IntoWallHang: {
|
|
|
|
if (bc.IsAnimationOver()) {
|
|
|
|
x4_state = pas::EWallHangState::WallHang;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state)));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.LoopBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
} else if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::ExitState)) {
|
|
|
|
x18_25_needsExit = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case pas::EWallHangState::WallHang: {
|
|
|
|
if (!bc.GetCommandMgr().GetTargetVector().isZero()) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToConstPtr<CActor> wp = mgr.ObjectById(x8_wpId)) {
|
|
|
|
if (const TCastToConstPtr<CActor> act = bc.GetOwner()) {
|
|
|
|
const zeus::CVector3f lookDir = bc.GetCommandMgr().GetTargetVector().normalized();
|
|
|
|
const float actorDotWp = act->GetTransform().basis[1].dot(wp->GetTransform().basis[1]);
|
|
|
|
const float lookDotWp = lookDir.dot(wp->GetTransform().basis[1]);
|
|
|
|
if (actorDotWp < -0.5f || lookDotWp > 0.5f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.FaceDirection(lookDir, dt);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::ExitState) || x18_25_needsExit) {
|
|
|
|
x4_state = pas::EWallHangState::OutOfWallHang;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state)));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.PlayBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
}
|
|
|
|
FixInPlace(bc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case pas::EWallHangState::Five: {
|
|
|
|
if (bc.IsAnimationOver()) {
|
|
|
|
x4_state = pas::EWallHangState::WallHang;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state)));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.LoopBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
}
|
|
|
|
FixInPlace(bc);
|
|
|
|
break;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
case pas::EWallHangState::OutOfWallHang: {
|
|
|
|
if (bc.IsAnimationOver()) {
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(7));
|
2020-04-05 06:30:17 +00:00
|
|
|
const std::pair<float, s32> best = bc.GetPASDatabase().FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (best.first > 0.f) {
|
|
|
|
x4_state = pas::EWallHangState::OutOfWallHangTurn;
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(best.second, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, false, false);
|
|
|
|
} else {
|
|
|
|
x4_state = pas::EWallHangState::DetachJumpLoop;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData loopParms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state)));
|
2020-04-05 06:30:17 +00:00
|
|
|
bc.LoopBestAnimation(loopParms, *mgr.GetActiveRandom());
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToPtr<CPhysicsActor> act = bc.GetOwner()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.SendScriptMsg(act.GetPtr(), kInvalidUniqueId, EScriptObjectMessage::Jumped);
|
|
|
|
x18_24_launched = false;
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToConstPtr<CActor> wp = mgr.ObjectById(x8_wpId)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
xc_launchVel = 15.f * wp->GetTransform().basis[1];
|
|
|
|
xc_launchVel.z() = 5.f;
|
|
|
|
} else {
|
|
|
|
xc_launchVel = -15.f * act->GetTransform().basis[1];
|
|
|
|
}
|
2019-02-24 07:15:54 +00:00
|
|
|
act->SetAngularMomentum(zeus::CAxisAngle());
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case pas::EWallHangState::OutOfWallHangTurn: {
|
|
|
|
SetLaunchVelocity(bc);
|
|
|
|
if (bc.IsAnimationOver()) {
|
|
|
|
x4_state = pas::EWallHangState::DetachJumpLoop;
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::WallHang, CPASAnimParm::FromEnum(s32(x4_state)));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.LoopBestAnimation(parms, *mgr.GetActiveRandom());
|
|
|
|
} else {
|
|
|
|
CheckForLand(bc, mgr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case pas::EWallHangState::DetachJumpLoop: {
|
|
|
|
SetLaunchVelocity(bc);
|
|
|
|
CheckForLand(bc, mgr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case pas::EWallHangState::DetachOutOfJump: {
|
|
|
|
if (bc.IsAnimationOver()) {
|
|
|
|
x4_state = pas::EWallHangState::Invalid;
|
|
|
|
return pas::EAnimationState::Locomotion;
|
|
|
|
}
|
|
|
|
break;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
return st;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CBSWallHang::IsInAir(const CBodyController& bc) const {
|
|
|
|
switch (x4_state) {
|
|
|
|
case pas::EWallHangState::JumpArc:
|
|
|
|
case pas::EWallHangState::JumpAirLoop:
|
|
|
|
case pas::EWallHangState::OutOfWallHangTurn:
|
|
|
|
case pas::EWallHangState::DetachJumpLoop:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CBSWallHang::ApplyAnimationDeltas() const {
|
|
|
|
switch (x4_state) {
|
|
|
|
case pas::EWallHangState::IntoJump:
|
|
|
|
case pas::EWallHangState::IntoWallHang:
|
|
|
|
case pas::EWallHangState::WallHang:
|
|
|
|
case pas::EWallHangState::Five:
|
|
|
|
case pas::EWallHangState::OutOfWallHang:
|
|
|
|
case pas::EWallHangState::DetachOutOfJump:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CBSWallHang::ApplyHeadTracking() const {
|
|
|
|
switch (x4_state) {
|
|
|
|
case pas::EWallHangState::WallHang:
|
|
|
|
case pas::EWallHangState::Five:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CBSWallHang::ApplyGravity() const {
|
|
|
|
switch (x4_state) {
|
|
|
|
case pas::EWallHangState::WallHang:
|
|
|
|
case pas::EWallHangState::IntoWallHang:
|
|
|
|
case pas::EWallHangState::OutOfWallHang:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-14 10:04:11 +00:00
|
|
|
float CBSLocomotion::GetStartVelocityMagnitude(const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToConstPtr<CPhysicsActor> act = bc.GetOwner()) {
|
|
|
|
const float maxSpeed = bc.GetBodyStateInfo().GetMaxSpeed();
|
2018-12-08 05:30:43 +00:00
|
|
|
float ret = 0.f;
|
2020-04-05 06:30:17 +00:00
|
|
|
if (maxSpeed > 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ret = act->GetVelocity().magnitude() / maxSpeed;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return std::min(1.f, ret);
|
|
|
|
}
|
|
|
|
return 0.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSLocomotion::ReStartBodyState(CBodyController& bc, bool maintainVel) {
|
|
|
|
UpdateLocomotionAnimation(0.f, maintainVel ? GetStartVelocityMagnitude(bc) : 0.f, bc, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
float CBSLocomotion::ComputeWeightPercentage(const std::pair<s32, float>& a, const std::pair<s32, float>& b,
|
|
|
|
float f) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
const float range = b.second - a.second;
|
|
|
|
if (range > FLT_EPSILON) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return std::max(0.f, std::min(1.f, (f - a.second) / range));
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return 0.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSLocomotion::Start(CBodyController& bc, CStateManager& mgr) {
|
|
|
|
x4_locomotionType = bc.GetLocomotionType();
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::MaintainVelocity)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ReStartBodyState(bc, true);
|
2020-04-05 06:30:17 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
ReStartBodyState(bc, false);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSLocomotion::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
|
|
|
if (st == pas::EAnimationState::Invalid) {
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdateLocomotionAnimation(dt, ApplyLocomotionPhysics(dt, bc), bc, false);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSLocomotion::Shutdown(CBodyController& bc) { bc.MultiplyPlaybackRate(1.f); }
|
|
|
|
|
|
|
|
float CBSLocomotion::ApplyLocomotionPhysics(float dt, CBodyController& bc) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToConstPtr<CPhysicsActor> act = bc.GetOwner()) {
|
|
|
|
const zeus::CVector3f vec = (zeus::close_enough(bc.GetCommandMgr().GetFaceVector(), zeus::skZero3f, 0.0001f))
|
|
|
|
? bc.GetCommandMgr().GetMoveVector()
|
|
|
|
: bc.GetCommandMgr().GetFaceVector();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (vec.canBeNormalized()) {
|
|
|
|
if (IsPitchable()) {
|
|
|
|
zeus::CVector3f tmp = vec;
|
|
|
|
tmp.z() = 0.f;
|
|
|
|
zeus::CVector3f lookVec = act->GetTransform().basis[1];
|
|
|
|
lookVec.z() = 0.f;
|
|
|
|
lookVec.normalize();
|
|
|
|
bc.FaceDirection3D(tmp, lookVec, dt);
|
|
|
|
zeus::CVector3f lookVec2 = act->GetTransform().basis[1];
|
|
|
|
lookVec2.z() = float(vec.z());
|
|
|
|
lookVec2.normalize();
|
|
|
|
if (!zeus::close_enough(lookVec, lookVec2, 0.0001f)) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const zeus::CRelAngle pitchAngle =
|
2018-12-08 05:30:43 +00:00
|
|
|
std::min(bc.GetBodyStateInfo().GetMaximumPitch(), zeus::CVector3f::getAngleDiff(vec, tmp));
|
|
|
|
lookVec2 = zeus::CVector3f::slerp(lookVec, lookVec2, pitchAngle);
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.FaceDirection3D(lookVec2, act->GetTransform().basis[1], dt);
|
|
|
|
zeus::CVector3f lookVec3 = act->GetTransform().basis[1];
|
|
|
|
lookVec3.z() = 0.f;
|
|
|
|
bc.FaceDirection3D(lookVec3, act->GetTransform().basis[1], dt);
|
|
|
|
} else {
|
|
|
|
bc.FaceDirection(vec.normalized(), dt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return std::min(1.f, bc.GetCommandMgr().GetMoveVector().magnitude());
|
|
|
|
}
|
|
|
|
return 0.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSLocomotion::GetBodyStateTransition(float, CBodyController& bc) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Hurled;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockDown)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Fall;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopHitReaction)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopReaction;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::KnockBack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::KnockBack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Locomotion)) {
|
|
|
|
bc.GetCommandMgr().ClearLocomotionCmds();
|
2017-07-10 04:55:51 +00:00
|
|
|
return pas::EAnimationState::Invalid;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Slide)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Slide;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Generate)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Generate;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::MeleeAttack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::MeleeAttack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::ProjectileAttack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::ProjectileAttack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopAttack)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopAttack;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::LoopReaction)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::LoopReaction;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Jump)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Jump;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Taunt)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Taunt;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Step)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Step;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Cover)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Cover;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::WallHang)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::WallHang;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::Scripted)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Scripted;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (bc.GetCommandMgr().GetMoveVector().isZero()) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (!bc.GetCommandMgr().GetFaceVector().isZero()) {
|
|
|
|
if (!IsMoving()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Turn;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
if (x4_locomotionType != bc.GetLocomotionType()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Locomotion;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return pas::EAnimationState::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
CBSBiPedLocomotion::CBSBiPedLocomotion(CActor& actor) {
|
|
|
|
const CPASDatabase& pasDatabase = actor.GetModelData()->GetAnimationData()->GetCharacterInfo().GetPASDatabase();
|
|
|
|
for (int i = 0; i < 14; ++i) {
|
2020-03-13 20:32:24 +00:00
|
|
|
rstl::reserved_vector<std::pair<s32, float>, 8>& innerVec = x8_anims.emplace_back();
|
2018-12-08 05:30:43 +00:00
|
|
|
for (int j = 0; j < 8; ++j) {
|
2021-03-07 09:43:03 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Locomotion, CPASAnimParm::FromEnum(j),
|
2020-04-22 09:08:02 +00:00
|
|
|
CPASAnimParm::FromEnum(i));
|
2020-04-05 06:30:17 +00:00
|
|
|
const std::pair<float, s32> best = pasDatabase.FindBestAnimation(parms, -1);
|
2018-12-08 05:30:43 +00:00
|
|
|
float avgVel = 0.f;
|
|
|
|
if (best.second != -1) {
|
|
|
|
avgVel = actor.GetAverageAnimVelocity(best.second);
|
2020-04-05 06:30:17 +00:00
|
|
|
if (j == 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
avgVel = 0.f;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
innerVec.push_back({best.second, avgVel});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBSBiPedLocomotion::Start(CBodyController& bc, CStateManager& mgr) {
|
|
|
|
x3c8_primeTime = 0.f;
|
|
|
|
CBSLocomotion::Start(bc, mgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
pas::EAnimationState CBSBiPedLocomotion::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (x3c8_primeTime < 0.2f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x3c8_primeTime += dt;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return CBSLocomotion::UpdateBody(dt, bc, mgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
float CBSBiPedLocomotion::GetLocomotionSpeed(pas::ELocomotionType type, pas::ELocomotionAnim anim) const {
|
|
|
|
return GetLocoAnimation(type, anim).second;
|
|
|
|
}
|
|
|
|
|
|
|
|
float CBSBiPedLocomotion::UpdateRun(float vel, CBodyController& bc, pas::ELocomotionAnim anim) {
|
|
|
|
const std::pair<s32, float>& walk = GetLocoAnimation(x4_locomotionType, pas::ELocomotionAnim::Walk);
|
|
|
|
const std::pair<s32, float>& run = GetLocoAnimation(x4_locomotionType, pas::ELocomotionAnim::Run);
|
2020-04-05 06:30:17 +00:00
|
|
|
const float perc = ComputeWeightPercentage(walk, run, vel);
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (perc < 0.4f) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const float rate = walk.second > 0.f ? vel / walk.second : 1.f;
|
2018-12-08 05:30:43 +00:00
|
|
|
if (anim != pas::ELocomotionAnim::Walk && bc.GetCurrentAnimId() != walk.first) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(walk.first, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, true, false);
|
|
|
|
x3c8_primeTime = 0.f;
|
|
|
|
}
|
|
|
|
bc.MultiplyPlaybackRate(rate);
|
|
|
|
x3c4_anim = pas::ELocomotionAnim::Walk;
|
|
|
|
return rate;
|
|
|
|
} else {
|
2020-04-05 06:30:17 +00:00
|
|
|
const float rate = std::min(1.f, vel / run.second);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (anim != pas::ELocomotionAnim::Run && bc.GetCurrentAnimId() != run.first) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(run.first, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, true, false);
|
|
|
|
x3c8_primeTime = 0.f;
|
|
|
|
}
|
|
|
|
bc.MultiplyPlaybackRate(rate);
|
|
|
|
x3c4_anim = pas::ELocomotionAnim::Run;
|
|
|
|
return rate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float CBSBiPedLocomotion::UpdateWalk(float vel, CBodyController& bc, pas::ELocomotionAnim anim) {
|
|
|
|
if (anim != pas::ELocomotionAnim::Walk) {
|
2017-07-10 04:55:51 +00:00
|
|
|
const std::pair<s32, float>& walk = GetLocoAnimation(x4_locomotionType, pas::ELocomotionAnim::Walk);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (bc.GetCurrentAnimId() != walk.first) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(walk.first, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, true, false);
|
|
|
|
x3c8_primeTime = 0.f;
|
|
|
|
}
|
|
|
|
x3c4_anim = pas::ELocomotionAnim::Walk;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::pair<s32, float>& idle = GetLocoAnimation(x4_locomotionType, pas::ELocomotionAnim::Idle);
|
|
|
|
const std::pair<s32, float>& walk = GetLocoAnimation(x4_locomotionType, pas::ELocomotionAnim::Walk);
|
2020-04-05 06:30:17 +00:00
|
|
|
const float perc = std::max(0.5f, ComputeWeightPercentage(idle, walk, vel));
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.MultiplyPlaybackRate(perc);
|
|
|
|
return perc;
|
|
|
|
}
|
|
|
|
|
2020-04-05 06:30:17 +00:00
|
|
|
constexpr std::array Strafes{
|
|
|
|
pas::ELocomotionAnim::StrafeRight, pas::ELocomotionAnim::StrafeLeft, pas::ELocomotionAnim::Walk,
|
|
|
|
pas::ELocomotionAnim::BackUp, pas::ELocomotionAnim::StrafeUp, pas::ELocomotionAnim::StrafeDown,
|
|
|
|
};
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
float CBSBiPedLocomotion::UpdateStrafe(float vel, CBodyController& bc, pas::ELocomotionAnim anim) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToConstPtr<CPhysicsActor> act = bc.GetOwner()) {
|
|
|
|
const zeus::CVector3f localVec = act->GetTransform().transposeRotate(bc.GetCommandMgr().GetMoveVector());
|
|
|
|
const zeus::CVector3f localVecSq = localVec * localVec;
|
2018-12-08 05:30:43 +00:00
|
|
|
int maxComp = 0;
|
2020-04-05 06:30:17 +00:00
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
if (localVecSq[i] >= localVecSq[maxComp]) {
|
2018-12-08 05:30:43 +00:00
|
|
|
maxComp = i;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-16 05:49:53 +00:00
|
|
|
const int strafeKey = maxComp * 2 + (localVec[maxComp] > 0.f ? 0 : 1);
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::ELocomotionAnim strafeType = Strafes[strafeKey];
|
|
|
|
const float rate = vel * GetLocomotionSpeed(x4_locomotionType, strafeType);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (anim != strafeType) {
|
|
|
|
const std::pair<s32, float>& strafe = GetLocoAnimation(x4_locomotionType, strafeType);
|
|
|
|
if (bc.GetCurrentAnimId() != strafe.first) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(strafe.first, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, true, false);
|
|
|
|
x3c8_primeTime = 0.f;
|
|
|
|
}
|
|
|
|
x3c4_anim = strafeType;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
|
|
|
const std::pair<s32, float>& idle = GetLocoAnimation(x4_locomotionType, pas::ELocomotionAnim::Idle);
|
2018-12-08 05:30:43 +00:00
|
|
|
const std::pair<s32, float>& strafe = GetLocoAnimation(x4_locomotionType, strafeType);
|
2020-04-05 06:30:17 +00:00
|
|
|
const float perc = std::max(0.5f, ComputeWeightPercentage(idle, strafe, rate));
|
2017-07-10 04:55:51 +00:00
|
|
|
bc.MultiplyPlaybackRate(perc);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
return 1.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
float CBSBiPedLocomotion::UpdateLocomotionAnimation(float dt, float velMag, CBodyController& bc, bool init) {
|
|
|
|
if (init || x3c8_primeTime >= 0.2f) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const auto anim = init ? pas::ELocomotionAnim::Invalid : x3c4_anim;
|
|
|
|
const float maxSpeed = velMag * GetLocomotionSpeed(x4_locomotionType, pas::ELocomotionAnim::Run);
|
|
|
|
if (IsStrafing(bc) && velMag >= 0.01f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return UpdateStrafe(velMag, bc, anim);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (maxSpeed < 0.01f) {
|
|
|
|
if (anim != pas::ELocomotionAnim::Idle || init) {
|
|
|
|
if (!bc.GetBodyStateInfo().GetLocoAnimChangeAtEndOfAnimOnly() || bc.GetAnimTimeRemaining() <= dt || init) {
|
|
|
|
const std::pair<s32, float>& best = GetLocoAnimation(x4_locomotionType, pas::ELocomotionAnim::Idle);
|
|
|
|
if (bc.GetCurrentAnimId() != best.first) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(best.first, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, true, false);
|
|
|
|
x3c8_primeTime = 0.f;
|
|
|
|
}
|
|
|
|
x3c4_anim = pas::ELocomotionAnim::Idle;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const std::pair<s32, float>& best = GetLocoAnimation(x4_locomotionType, pas::ELocomotionAnim::Walk);
|
2020-04-05 06:30:17 +00:00
|
|
|
if (maxSpeed < best.second) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return UpdateWalk(maxSpeed, bc, anim);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return UpdateRun(maxSpeed, bc, anim);
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
|
2020-04-05 07:24:53 +00:00
|
|
|
return 1.0f;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CBSBiPedLocomotion::IsStrafing(const CBodyController& bc) const {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (!zeus::close_enough(bc.GetCommandMgr().GetMoveVector(), zeus::skZero3f, 0.0001f)) {
|
|
|
|
if (!zeus::close_enough(bc.GetCommandMgr().GetFaceVector(), zeus::skZero3f, 0.0001f)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CBSFlyerLocomotion::CBSFlyerLocomotion(CActor& actor, bool pitchable)
|
2018-12-08 05:30:43 +00:00
|
|
|
: CBSBiPedLocomotion(actor), x3cc_pitchable(pitchable) {}
|
|
|
|
|
|
|
|
float CBSFlyerLocomotion::ApplyLocomotionPhysics(float dt, CBodyController& bc) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const float ret = CBSLocomotion::ApplyLocomotionPhysics(dt, bc);
|
|
|
|
if (const TCastToPtr<CPhysicsActor> act = bc.GetOwner()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (std::fabs(bc.GetCommandMgr().GetMoveVector().z()) > 0.01f &&
|
|
|
|
(!x3cc_pitchable || bc.GetBodyStateInfo().GetMaximumPitch() < 0.17453292f)) {
|
|
|
|
zeus::CVector3f dir;
|
|
|
|
dir.z() = dt * bc.GetBodyStateInfo().GetMaxSpeed() * bc.GetCommandMgr().GetMoveVector().z();
|
2019-02-24 07:15:54 +00:00
|
|
|
act->ApplyImpulseWR(act->GetMoveToORImpulseWR(dir, dt), zeus::CAxisAngle());
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
CBSWallWalkerLocomotion::CBSWallWalkerLocomotion(CActor& actor) : CBSBiPedLocomotion(actor) {}
|
|
|
|
|
|
|
|
float CBSWallWalkerLocomotion::ApplyLocomotionPhysics(float dt, CBodyController& bc) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToConstPtr<CPhysicsActor> act = bc.GetOwner()) {
|
|
|
|
const float maxSpeed = bc.GetBodyStateInfo().GetMaxSpeed();
|
|
|
|
const zeus::CVector3f scaledMove = bc.GetCommandMgr().GetMoveVector() * maxSpeed;
|
2019-02-08 01:08:15 +00:00
|
|
|
if ((zeus::CVector3f::getAngleDiff(bc.GetCommandMgr().GetFaceVector(), scaledMove) < (M_PIF / 2.f)
|
|
|
|
? scaledMove
|
2018-12-08 05:30:43 +00:00
|
|
|
: bc.GetCommandMgr().GetFaceVector())
|
2020-04-05 06:30:17 +00:00
|
|
|
.canBeNormalized()) {
|
2019-02-08 01:08:15 +00:00
|
|
|
bc.FaceDirection3D(scaledMove.normalized(), act->GetTransform().basis[1], dt);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2019-02-08 01:08:15 +00:00
|
|
|
zeus::CVector3f impulse = act->GetMoveToORImpulseWR(act->GetTransform().transposeRotate(scaledMove * dt), dt);
|
2018-12-08 05:30:43 +00:00
|
|
|
impulse = act->GetMass() > FLT_EPSILON ? impulse / act->GetMass()
|
|
|
|
: zeus::CVector3f(0.f, act->GetVelocity().magnitude(), 0.f);
|
2020-04-05 06:30:17 +00:00
|
|
|
if (maxSpeed > FLT_EPSILON) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return std::min(1.f, impulse.magnitude() / maxSpeed);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
return 0.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
CBSNewFlyerLocomotion::CBSNewFlyerLocomotion(CActor& actor) : CBSBiPedLocomotion(actor) {}
|
|
|
|
|
|
|
|
float CBSNewFlyerLocomotion::ApplyLocomotionPhysics(float dt, CBodyController& bc) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (TCastToConstPtr<CPhysicsActor>(bc.GetOwner())) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.FaceDirection(bc.GetCommandMgr().GetFaceVector(), dt);
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return 0.f;
|
|
|
|
}
|
|
|
|
|
2020-04-05 06:30:17 +00:00
|
|
|
constexpr std::array RunStrafes{
|
|
|
|
pas::ELocomotionAnim::StrafeRight, pas::ELocomotionAnim::StrafeLeft, pas::ELocomotionAnim::Run,
|
|
|
|
pas::ELocomotionAnim::BackUp, pas::ELocomotionAnim::StrafeUp, pas::ELocomotionAnim::StrafeDown,
|
|
|
|
};
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
float CBSNewFlyerLocomotion::UpdateLocomotionAnimation(float dt, float velMag, CBodyController& bc, bool init) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToConstPtr<CPhysicsActor> act = bc.GetOwner()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
pas::ELocomotionAnim strafeType = pas::ELocomotionAnim::Idle;
|
|
|
|
if (bc.GetCommandMgr().GetMoveVector().canBeNormalized()) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const zeus::CVector3f localVec = act->GetTransform().transposeRotate(bc.GetCommandMgr().GetMoveVector());
|
|
|
|
const zeus::CVector3f localVecSq = localVec * localVec;
|
2018-12-08 05:30:43 +00:00
|
|
|
int maxComp = 0;
|
2020-04-05 06:30:17 +00:00
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
if (localVecSq[i] >= localVecSq[maxComp]) {
|
2018-12-08 05:30:43 +00:00
|
|
|
maxComp = i;
|
2020-04-05 06:30:17 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-16 05:45:07 +00:00
|
|
|
const int strafeKey = maxComp * 2 + (localVec[maxComp] > 0.f ? 0 : 1);
|
2018-12-08 05:30:43 +00:00
|
|
|
strafeType = RunStrafes[strafeKey];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (init || strafeType != x3c4_anim) {
|
|
|
|
const std::pair<s32, float>& strafe = GetLocoAnimation(x4_locomotionType, strafeType);
|
|
|
|
if (init || bc.GetCurrentAnimId() != strafe.first) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(strafe.first, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, true, false);
|
|
|
|
}
|
|
|
|
x3c4_anim = strafeType;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-05 06:30:17 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return 1.f;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CBSRestrictedLocomotion::CBSRestrictedLocomotion(CActor& actor) {
|
|
|
|
const CPASDatabase& pasDatabase = actor.GetModelData()->GetAnimationData()->GetCharacterInfo().GetPASDatabase();
|
|
|
|
for (int i = 0; i < 14; ++i) {
|
2020-04-22 09:08:02 +00:00
|
|
|
const CPASAnimParmData parms(pas::EAnimationState::Locomotion, CPASAnimParm::FromEnum(0),
|
|
|
|
CPASAnimParm::FromEnum(i));
|
2020-04-05 06:30:17 +00:00
|
|
|
const std::pair<float, s32> best = pasDatabase.FindBestAnimation(parms, -1);
|
2018-12-08 05:30:43 +00:00
|
|
|
x8_anims.push_back(best.second);
|
|
|
|
}
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float CBSRestrictedLocomotion::UpdateLocomotionAnimation(float dt, float velMag, CBodyController& bc, bool init) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const pas::ELocomotionAnim anim = init ? pas::ELocomotionAnim::Invalid : x44_anim;
|
2018-12-08 05:30:43 +00:00
|
|
|
if (anim != pas::ELocomotionAnim::Idle) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const s32 newAnim = x8_anims[int(x4_locomotionType)];
|
2018-12-08 05:30:43 +00:00
|
|
|
if (newAnim != bc.GetCurrentAnimId()) {
|
2020-04-05 06:30:17 +00:00
|
|
|
const CAnimPlaybackParms playParms(newAnim, -1, 1.f, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.SetCurrentAnimation(playParms, true, false);
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
x44_anim = pas::ELocomotionAnim::Idle;
|
|
|
|
}
|
|
|
|
return 1.f;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CBSRestrictedFlyerLocomotion::CBSRestrictedFlyerLocomotion(CActor& actor) : CBSRestrictedLocomotion(actor) {}
|
2017-07-10 04:55:51 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float CBSRestrictedFlyerLocomotion::ApplyLocomotionPhysics(float dt, CBodyController& bc) {
|
2020-04-05 06:30:17 +00:00
|
|
|
if (const TCastToPtr<CPhysicsActor> act = bc.GetOwner()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bc.FaceDirection(bc.GetCommandMgr().GetFaceVector(), dt);
|
|
|
|
act->ApplyImpulseWR(bc.GetCommandMgr().GetMoveVector() * bc.GetRestrictedFlyerMoveSpeed() * act->GetMass(),
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CAxisAngle());
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
return 0.f;
|
2017-07-10 04:55:51 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|