metaforce/Runtime/Weapon/CGunController.cpp

177 lines
5.9 KiB
C++
Raw Normal View History

#include "CGunController.hpp"
2016-08-23 03:12:50 +00:00
#include "Character/CCharLayoutInfo.hpp"
#include "Character/CPASAnimParmData.hpp"
#include "CStateManager.hpp"
2018-12-08 05:30:43 +00:00
namespace urde {
2018-12-08 05:30:43 +00:00
void CGunController::LoadFidgetAnimAsync(CStateManager& mgr, s32 type, s32 gunId, s32 animSet) {
x30_fidget.LoadAnimAsync(*x0_modelData.GetAnimationData(), type, gunId, animSet, mgr);
}
2018-12-08 05:30:43 +00:00
void CGunController::EnterFidget(CStateManager& mgr, s32 type, s32 gunId, s32 animSet) {
x54_curAnimId = x30_fidget.SetAnim(*x0_modelData.GetAnimationData(), type, gunId, animSet, mgr);
2018-12-08 05:30:43 +00:00
x50_gunState = EGunState::Fidget;
}
2018-12-08 05:30:43 +00:00
void CGunController::EnterFreeLook(CStateManager& mgr, s32 gunId, s32 setId) {
if (x50_gunState != EGunState::ComboFire && !x58_25_enteredComboFire)
x54_curAnimId = x4_freeLook.SetAnim(*x0_modelData.GetAnimationData(), gunId, setId, 0, mgr, 0.f);
2018-12-08 05:30:43 +00:00
else
x4_freeLook.SetLoopState(x1c_comboFire.GetLoopState());
x50_gunState = EGunState::FreeLook;
}
2018-12-08 05:30:43 +00:00
void CGunController::EnterComboFire(CStateManager& mgr, s32 gunId) {
if (x50_gunState != EGunState::FreeLook)
x54_curAnimId = x1c_comboFire.SetAnim(*x0_modelData.GetAnimationData(), gunId, 0, mgr, 0.f);
2018-12-08 05:30:43 +00:00
else
x1c_comboFire.SetLoopState(x4_freeLook.GetLoopState());
x50_gunState = EGunState::ComboFire;
x58_25_enteredComboFire = true;
}
2018-12-08 05:30:43 +00:00
void CGunController::EnterStruck(CStateManager& mgr, float angle, bool bigStrike, bool b2) {
switch (x50_gunState) {
case EGunState::Default:
case EGunState::ComboFire:
case EGunState::Idle:
case EGunState::Strike:
case EGunState::BigStrike:
return;
case EGunState::FreeLook:
x4_freeLook.SetIdle(true);
break;
default:
break;
}
const CPASDatabase& pasDatabase = x0_modelData.GetAnimationData()->GetCharacterInfo().GetPASDatabase();
2018-12-08 05:30:43 +00:00
CPASAnimParmData parms(2, CPASAnimParm::FromInt32(x4_freeLook.GetGunId()), CPASAnimParm::FromReal32(angle),
CPASAnimParm::FromBool(bigStrike), CPASAnimParm::FromBool(b2));
std::pair<float, s32> anim = pasDatabase.FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
x0_modelData.GetAnimationData()->EnableLooping(false);
2018-12-08 05:30:43 +00:00
CAnimPlaybackParms aparms(anim.second, -1, 1.f, true);
x0_modelData.GetAnimationData()->SetAnimation(aparms, false);
2018-12-08 05:30:43 +00:00
x54_curAnimId = anim.second;
x58_25_enteredComboFire = false;
x50_gunState = bigStrike ? EGunState::BigStrike : EGunState::Strike;
}
2018-12-08 05:30:43 +00:00
void CGunController::EnterIdle(CStateManager& mgr) {
CPASAnimParm parm = CPASAnimParm::NoParameter();
switch (x50_gunState) {
case EGunState::FreeLook:
parm = CPASAnimParm::FromEnum(1);
x4_freeLook.SetIdle(true);
break;
case EGunState::ComboFire:
parm = CPASAnimParm::FromEnum(1);
x1c_comboFire.SetIdle(true);
break;
default:
return;
}
const CPASDatabase& pasDatabase = x0_modelData.GetAnimationData()->GetCharacterInfo().GetPASDatabase();
2018-12-08 05:30:43 +00:00
CPASAnimParmData parms(5, parm);
std::pair<float, s32> anim = pasDatabase.FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
x0_modelData.GetAnimationData()->EnableLooping(false);
2018-12-08 05:30:43 +00:00
CAnimPlaybackParms aparms(anim.second, -1, 1.f, true);
x0_modelData.GetAnimationData()->SetAnimation(aparms, false);
2018-12-08 05:30:43 +00:00
x54_curAnimId = anim.second;
x50_gunState = EGunState::Idle;
x58_25_enteredComboFire = false;
}
2018-12-08 05:30:43 +00:00
bool CGunController::Update(float dt, CStateManager& mgr) {
CAnimData& animData = *x0_modelData.GetAnimationData();
2018-12-08 05:30:43 +00:00
switch (x50_gunState) {
case EGunState::FreeLook: {
x58_24_animDone = x4_freeLook.Update(animData, dt, mgr);
if (!x58_24_animDone || !x58_25_enteredComboFire)
break;
EnterComboFire(mgr, x4_freeLook.GetGunId());
x58_24_animDone = false;
break;
}
case EGunState::ComboFire:
x58_24_animDone = x1c_comboFire.Update(animData, dt, mgr);
break;
case EGunState::Fidget:
x58_24_animDone = x30_fidget.Update(animData, dt, mgr);
break;
case EGunState::Strike: {
if (animData.IsAnimTimeRemaining(0.001f, "Whole Body"))
break;
x54_curAnimId = x4_freeLook.SetAnim(animData, x4_freeLook.GetGunId(), x4_freeLook.GetSetId(), 0, mgr, 0.f);
x50_gunState = EGunState::FreeLook;
break;
}
case EGunState::BigStrike:
x58_24_animDone = !animData.IsAnimTimeRemaining(0.001f, "Whole Body");
break;
default:
break;
}
if (!x58_24_animDone)
return false;
x50_gunState = EGunState::Inactive;
x58_25_enteredComboFire = false;
return true;
}
2018-12-08 05:30:43 +00:00
void CGunController::ReturnToDefault(CStateManager& mgr, float dt, bool setState) {
CAnimData& animData = *x0_modelData.GetAnimationData();
2018-12-08 05:30:43 +00:00
switch (x50_gunState) {
case EGunState::Strike:
x50_gunState = EGunState::FreeLook;
2019-02-18 05:47:46 +00:00
[[fallthrough]];
2018-12-08 05:30:43 +00:00
case EGunState::Idle:
x4_freeLook.SetIdle(false);
2019-02-18 05:47:46 +00:00
[[fallthrough]];
2018-12-08 05:30:43 +00:00
case EGunState::FreeLook:
2017-08-26 04:36:25 +00:00
if (setState)
2018-12-08 05:30:43 +00:00
break;
x54_curAnimId = x4_freeLook.SetAnim(animData, x4_freeLook.GetGunId(), x4_freeLook.GetSetId(), 2, mgr, dt);
2017-08-26 04:36:25 +00:00
x58_25_enteredComboFire = false;
2018-12-08 05:30:43 +00:00
break;
case EGunState::ComboFire:
x54_curAnimId = x1c_comboFire.SetAnim(animData, x1c_comboFire.GetGunId(), 2, mgr, dt);
break;
case EGunState::Fidget:
ReturnToBasePosition(mgr, dt);
break;
case EGunState::BigStrike:
x4_freeLook.SetIdle(false);
break;
default:
break;
}
if (setState)
x50_gunState = EGunState::Default;
}
2018-12-08 05:30:43 +00:00
void CGunController::ReturnToBasePosition(CStateManager& mgr, float) {
const CPASDatabase& pasDatabase = x0_modelData.GetAnimationData()->GetCharacterInfo().GetPASDatabase();
2018-12-08 05:30:43 +00:00
std::pair<float, s32> anim = pasDatabase.FindBestAnimation(CPASAnimParmData(6), *mgr.GetActiveRandom(), -1);
x0_modelData.GetAnimationData()->EnableLooping(false);
2018-12-08 05:30:43 +00:00
CAnimPlaybackParms parms(anim.second, -1, 1.f, true);
x0_modelData.GetAnimationData()->SetAnimation(parms, false);
2018-12-08 05:30:43 +00:00
x54_curAnimId = anim.second;
x58_25_enteredComboFire = false;
}
2018-12-08 05:30:43 +00:00
void CGunController::Reset() {
x58_24_animDone = true;
x58_25_enteredComboFire = false;
x50_gunState = EGunState::Inactive;
}
2018-12-08 05:30:43 +00:00
} // namespace urde