metaforce/Runtime/Weapon/CGunMotion.cpp

90 lines
3.0 KiB
C++
Raw Permalink Normal View History

#include "Runtime/Weapon/CGunMotion.hpp"
#include "Runtime/CStateManager.hpp"
#include "Runtime/Character/CPASAnimParmData.hpp"
#include "Runtime/Weapon/WeaponCommon.hpp"
2021-04-10 08:42:06 +00:00
namespace metaforce {
2017-08-26 04:36:25 +00:00
CGunMotion::CGunMotion(CAssetId ancsId, const zeus::CVector3f& scale)
2018-12-08 05:30:43 +00:00
: x0_modelData(CAnimRes(ancsId, 0, scale, 0, false), 1), x4c_gunController(x0_modelData) {
LoadAnimations();
2017-08-26 04:36:25 +00:00
}
2018-12-08 05:30:43 +00:00
void CGunMotion::LoadAnimations() {
NWeaponTypes::get_token_vector(*x0_modelData.GetAnimationData(), 0, 14, xa8_anims, true);
2017-08-26 04:36:25 +00:00
}
2018-12-08 05:30:43 +00:00
bool CGunMotion::PlayPasAnim(SamusGun::EAnimationState state, CStateManager& mgr, float angle, bool bigStrike) {
const CPASDatabase& pas = x0_modelData.GetAnimationData()->GetCharacterInfo().GetPASDatabase();
2017-08-26 04:36:25 +00:00
2018-12-08 05:30:43 +00:00
s32 animId = -1;
bool loop = true;
switch (state) {
case SamusGun::EAnimationState::Wander: {
2020-04-22 09:08:02 +00:00
CPASAnimParmData parms((pas::EAnimationState(state)));
2018-12-08 05:30:43 +00:00
auto anim = pas.FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
animId = anim.second;
break;
}
case SamusGun::EAnimationState::Idle: {
2020-04-22 09:08:02 +00:00
CPASAnimParmData parms(pas::EAnimationState(state), CPASAnimParm::FromEnum(0));
2018-12-08 05:30:43 +00:00
auto anim = pas.FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
animId = anim.second;
break;
}
case SamusGun::EAnimationState::Struck: {
2020-04-22 09:08:02 +00:00
CPASAnimParmData parms(pas::EAnimationState(state), CPASAnimParm::FromInt32(0), CPASAnimParm::FromReal32(angle),
2018-12-08 05:30:43 +00:00
CPASAnimParm::FromBool(bigStrike), CPASAnimParm::FromBool(false));
auto anim = pas.FindBestAnimation(parms, *mgr.GetActiveRandom(), -1);
animId = anim.second;
loop = false;
break;
}
case SamusGun::EAnimationState::FreeLook:
x4c_gunController.EnterFreeLook(mgr, 0, -1);
break;
case SamusGun::EAnimationState::ComboFire:
x4c_gunController.EnterComboFire(mgr, 0);
break;
default:
break;
}
2017-08-26 04:36:25 +00:00
2018-12-08 05:30:43 +00:00
if (animId != -1) {
x0_modelData.GetAnimationData()->EnableLooping(loop);
2018-12-08 05:30:43 +00:00
CAnimPlaybackParms aparms(animId, -1, 1.f, true);
x0_modelData.GetAnimationData()->SetAnimation(aparms, false);
2018-12-08 05:30:43 +00:00
}
2018-12-08 05:30:43 +00:00
return loop;
}
2018-12-08 05:30:43 +00:00
void CGunMotion::ReturnToDefault(CStateManager& mgr, bool setState) {
x4c_gunController.ReturnToDefault(mgr, 0.f, setState);
2017-08-26 04:36:25 +00:00
}
2017-08-25 06:18:09 +00:00
2018-12-08 05:30:43 +00:00
void CGunMotion::BasePosition(bool bigStrikeReset) {
x0_modelData.GetAnimationData()->EnableLooping(false);
2018-12-08 05:30:43 +00:00
CAnimPlaybackParms aparms(bigStrikeReset ? 6 : 0, -1, 1.f, true);
x0_modelData.GetAnimationData()->SetAnimation(aparms, false);
2017-08-26 04:36:25 +00:00
}
2018-12-08 05:30:43 +00:00
void CGunMotion::EnterFidget(CStateManager& mgr, SamusGun::EFidgetType type, s32 parm2) {
xb8_24_animPlaying = true;
x4c_gunController.EnterFidget(mgr, s32(type), 0, parm2);
2017-08-26 04:36:25 +00:00
}
2018-12-08 05:30:43 +00:00
void CGunMotion::Update(float dt, CStateManager& mgr) {
x0_modelData.AdvanceAnimation(dt, mgr, kInvalidAreaId, true);
if (x4c_gunController.Update(dt, mgr))
xb8_24_animPlaying = false;
2017-08-26 04:36:25 +00:00
}
void CGunMotion::Draw(const CStateManager& mgr, const zeus::CTransform& xf) {
constexpr CModelFlags flags(0, 0, 3, zeus::skWhite);
2018-12-08 05:30:43 +00:00
x0_modelData.Render(mgr, xf, nullptr, flags);
2017-08-25 06:18:09 +00:00
}
2021-04-10 08:42:06 +00:00
} // namespace metaforce