metaforce/Runtime/Weapon/CGunController.cpp

196 lines
6.2 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"
namespace urde
{
2017-09-04 02:22:46 +00:00
void CGunController::LoadFidgetAnimAsync(CStateManager& mgr, s32 type, s32 gunId, s32 animSet)
{
2017-09-04 02:22:46 +00:00
x30_fidget.LoadAnimAsync(*x0_modelData.AnimationData(), type, gunId, animSet, mgr);
}
2017-09-04 02:22:46 +00:00
void CGunController::EnterFidget(CStateManager& mgr, s32 type, s32 gunId, s32 animSet)
{
2017-09-04 02:22:46 +00:00
x54_curAnimId = x30_fidget.SetAnim(*x0_modelData.AnimationData(), type, gunId, animSet, mgr);
2017-08-26 04:36:25 +00:00
x50_gunState = EGunState::Fidget;
}
2017-08-26 04:36:25 +00:00
void CGunController::EnterFreeLook(CStateManager& mgr, s32 gunId, s32 setId)
{
2017-08-26 04:36:25 +00:00
if (x50_gunState != EGunState::ComboFire && !x58_25_enteredComboFire)
x54_curAnimId = x4_freeLook.SetAnim(*x0_modelData.AnimationData(), gunId, setId, 0, mgr, 0.f);
else
x4_freeLook.SetLoopState(x1c_comboFire.GetLoopState());
x50_gunState = EGunState::FreeLook;
}
2017-08-26 04:36:25 +00:00
void CGunController::EnterComboFire(CStateManager& mgr, s32 gunId)
{
2017-08-26 04:36:25 +00:00
if (x50_gunState != EGunState::FreeLook)
x54_curAnimId = x1c_comboFire.SetAnim(*x0_modelData.AnimationData(), gunId, 0, mgr, 0.f);
else
x1c_comboFire.SetLoopState(x4_freeLook.GetLoopState());
x50_gunState = EGunState::ComboFire;
x58_25_enteredComboFire = true;
}
2017-08-26 04:36:25 +00:00
void CGunController::EnterStruck(CStateManager& mgr, float angle, bool bigStrike, bool b2)
{
2017-08-26 04:36:25 +00:00
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;
}
2017-08-26 04:36:25 +00:00
const CPASDatabase& pasDatabase = x0_modelData.AnimationData()->GetCharacterInfo().GetPASDatabase();
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.AnimationData()->EnableLooping(false);
CAnimPlaybackParms aparms(anim.second, -1, 1.f, true);
x0_modelData.AnimationData()->SetAnimation(aparms, false);
x54_curAnimId = anim.second;
x58_25_enteredComboFire = false;
x50_gunState = bigStrike ? EGunState::BigStrike : EGunState::Strike;
}
2017-08-26 04:36:25 +00:00
void CGunController::EnterIdle(CStateManager& mgr)
{
2017-08-26 04:36:25 +00:00
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;
}
2017-08-26 04:36:25 +00:00
const CPASDatabase& pasDatabase = x0_modelData.AnimationData()->GetCharacterInfo().GetPASDatabase();
CPASAnimParmData parms(5, parm);
std::pair<float, s32> anim =
pasDatabase.FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
x0_modelData.AnimationData()->EnableLooping(false);
CAnimPlaybackParms aparms(anim.second, -1, 1.f, true);
x0_modelData.AnimationData()->SetAnimation(aparms, false);
x54_curAnimId = anim.second;
x50_gunState = EGunState::Idle;
x58_25_enteredComboFire = false;
}
bool CGunController::Update(float dt, CStateManager& mgr)
{
CAnimData& animData = *x0_modelData.AnimationData();
switch (x50_gunState)
{
case EGunState::FreeLook:
{
2017-08-26 04:36:25 +00:00
x58_24_animDone = x4_freeLook.Update(animData, dt, mgr);
if (!x58_24_animDone || !x58_25_enteredComboFire)
break;
2017-08-26 04:36:25 +00:00
EnterComboFire(mgr, x4_freeLook.GetGunId());
x58_24_animDone = false;
break;
}
case EGunState::ComboFire:
2017-08-26 04:36:25 +00:00
x58_24_animDone = x1c_comboFire.Update(animData, dt, mgr);
break;
case EGunState::Fidget:
2017-08-26 04:36:25 +00:00
x58_24_animDone = x30_fidget.Update(animData, dt, mgr);
break;
2017-08-26 04:36:25 +00:00
case EGunState::Strike:
{
if (animData.IsAnimTimeRemaining(0.001f, "Whole Body"))
break;
2017-08-26 04:36:25 +00:00
x54_curAnimId = x4_freeLook.SetAnim(animData, x4_freeLook.GetGunId(), x4_freeLook.GetSetId(), 0, mgr, 0.f);
x50_gunState = EGunState::FreeLook;
break;
}
2017-08-26 04:36:25 +00:00
case EGunState::BigStrike:
x58_24_animDone = !animData.IsAnimTimeRemaining(0.001f, "Whole Body");
break;
default:
break;
}
2017-08-26 04:36:25 +00:00
if (!x58_24_animDone)
return false;
2017-08-26 04:36:25 +00:00
x50_gunState = EGunState::Inactive;
x58_25_enteredComboFire = false;
return true;
}
2017-08-26 04:36:25 +00:00
void CGunController::ReturnToDefault(CStateManager& mgr, float dt, bool setState)
{
2017-08-26 04:36:25 +00:00
CAnimData& animData = *x0_modelData.AnimationData();
switch (x50_gunState)
{
case EGunState::Strike:
x50_gunState = EGunState::FreeLook;
case EGunState::Idle:
x4_freeLook.SetIdle(false);
case EGunState::FreeLook:
if (setState)
break;
x54_curAnimId = x4_freeLook.SetAnim(animData, x4_freeLook.GetGunId(), x4_freeLook.GetSetId(), 2, mgr, dt);
x58_25_enteredComboFire = false;
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;
}
2017-08-26 04:36:25 +00:00
if (setState)
x50_gunState = EGunState::Default;
}
void CGunController::ReturnToBasePosition(CStateManager& mgr, float)
{
const CPASDatabase& pasDatabase = x0_modelData.AnimationData()->GetCharacterInfo().GetPASDatabase();
std::pair<float, s32> anim =
2017-08-26 04:36:25 +00:00
pasDatabase.FindBestAnimation(CPASAnimParmData(6), *mgr.GetActiveRandom(), -1);
x0_modelData.AnimationData()->EnableLooping(false);
CAnimPlaybackParms parms(anim.second, -1, 1.f, true);
x0_modelData.AnimationData()->SetAnimation(parms, false);
x54_curAnimId = anim.second;
x58_25_enteredComboFire = false;
}
void CGunController::Reset()
{
2017-08-26 04:36:25 +00:00
x58_24_animDone = true;
x58_25_enteredComboFire = false;
x50_gunState = EGunState::Inactive;
}
}