metaforce/Runtime/MP1/World/CPuddleToadGamma.cpp

337 lines
14 KiB
C++
Raw Normal View History

2018-02-11 05:27:00 +00:00
#include "CPuddleToadGamma.hpp"
2018-12-01 00:44:33 +00:00
#include "GameGlobalObjects.hpp"
#include "CSimplePool.hpp"
#include "CStateManager.hpp"
#include "World/CPlayer.hpp"
#include "Collision/CGameCollision.hpp"
#include "Weapon/CBomb.hpp"
2018-12-01 00:44:33 +00:00
#include "TCastTo.hpp"
2018-02-11 05:27:00 +00:00
2018-12-08 05:30:43 +00:00
namespace urde::MP1 {
2018-02-11 05:27:00 +00:00
2018-12-01 00:44:33 +00:00
const zeus::CVector3f CPuddleToadGamma::skBellyOffset(0.f, 0.1f, -.3f);
2018-02-11 05:27:00 +00:00
CPuddleToadGamma::CPuddleToadGamma(TUniqueId uid, std::string_view name, EFlavorType flavor, const CEntityInfo& info,
const zeus::CTransform& xf, CModelData&& mData, const CPatternedInfo& pInfo,
const CActorParameters& aParms, float suckForceMultiplier, float suckAngle,
float playerSuckRange, const zeus::CVector3f& localShootDir, float playerShootSpeed,
float shouldAttackWaitTime, float spotPlayerWaitTime,
const CDamageInfo& playerShootDamage, const CDamageInfo& dInfo2, CAssetId dcln)
2018-12-08 05:30:43 +00:00
: CPatterned(ECharacter::PuddleToad, uid, name, flavor, info, xf, std::move(mData), pInfo, EMovementType::Flyer,
EColliderType::Zero, EBodyType::Restricted, aParms, EKnockBackVariant::Large)
, x570_playerShootDamage(playerShootDamage)
2018-12-08 05:30:43 +00:00
, x58c_(dInfo2)
, x5a8_suckForceMultiplier(suckForceMultiplier)
, x5ac_minSuckAngleProj(std::cos(zeus::degToRad(suckAngle * 0.5f)))
, x5b0_playerSuckRange(playerSuckRange)
, x5b4_localShootDir(localShootDir)
, x5c0_playerShootSpeed(playerShootSpeed)
, x5c4_shouldAttackWaitTime(shouldAttackWaitTime)
, x5c8_spotPlayerWaitTime(spotPlayerWaitTime)
, x5e8_24_playerInside(false)
, x5e8_25_waitTimerActive(false)
, x5e8_26_shotPlayer(false) {
2018-12-08 05:30:43 +00:00
x401_26_disableMove = true;
x460_knockBackController.SetEnableBurn(false);
x460_knockBackController.SetEnableLaggedBurnDeath(false);
x460_knockBackController.SetEnableShock(false);
x460_knockBackController.SetX81_31(false);
SetMovable(false);
if (dcln.IsValid() && g_ResFactory->GetResourceTypeById(dcln) != 0) {
TLockedToken<CCollidableOBBTreeGroupContainer> container = g_SimplePool->GetObj({FOURCC('DCLN'), dcln});
x5e4_collisionTreePrim.reset(new CCollidableOBBTreeGroup(container.GetObj(), GetMaterialList()));
}
2018-12-01 00:44:33 +00:00
}
2018-12-08 05:30:43 +00:00
void CPuddleToadGamma::SetSolid(CStateManager& mgr, bool solid) {
if (solid) {
AddMaterial(EMaterialTypes::Solid, mgr);
RemoveMaterial(EMaterialTypes::NonSolidDamageable, mgr);
} else {
RemoveMaterial(EMaterialTypes::Solid, mgr);
AddMaterial(EMaterialTypes::NonSolidDamageable, mgr);
}
2018-12-01 00:44:33 +00:00
}
2018-12-08 05:30:43 +00:00
const CCollisionPrimitive* CPuddleToadGamma::GetCollisionPrimitive() const {
if (!x5e4_collisionTreePrim)
return CPhysicsActor::GetCollisionPrimitive();
return x5e4_collisionTreePrim.get();
2018-12-01 00:44:33 +00:00
}
2018-12-08 05:30:43 +00:00
zeus::CTransform CPuddleToadGamma::GetPrimitiveTransform() const {
zeus::CTransform xf = GetTransform();
xf.origin += GetPrimitiveOffset();
return xf;
2018-12-01 00:44:33 +00:00
}
2018-12-08 05:30:43 +00:00
void CPuddleToadGamma::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
CPatterned::AcceptScriptMsg(msg, uid, mgr);
if (msg == EScriptObjectMessage::Registered) {
x450_bodyController->Activate(mgr);
zeus::CTransform bellyXf = GetLctrTransform(mBellyLocatorName);
zeus::CVector3f bellyOffset = GetTransform().rotate(skBellyOffset);
x5d8_damageablePoint = x5cc_suckPoint = bellyXf.origin + bellyOffset;
2018-12-08 05:30:43 +00:00
RemoveMaterial(EMaterialTypes::Target, EMaterialTypes::Orbit, mgr);
AddMaterial(EMaterialTypes::Immovable, mgr);
AddMaterial(EMaterialTypes::SolidCharacter);
}
2018-12-01 00:44:33 +00:00
}
2018-12-08 05:30:43 +00:00
void CPuddleToadGamma::Think(float dt, CStateManager& mgr) {
CPatterned::Think(dt, mgr);
if (x5e8_25_waitTimerActive)
x56c_waitTimer += dt;
2018-12-01 00:44:33 +00:00
}
std::optional<zeus::CAABox> CPuddleToadGamma::GetTouchBounds() const {
2018-12-08 05:30:43 +00:00
if (!GetActive())
return {};
2018-12-01 00:44:33 +00:00
2018-12-08 05:30:43 +00:00
return (x5e4_collisionTreePrim ? x5e4_collisionTreePrim->CalculateAABox(GetTransform()) : GetBoundingBox());
2018-12-01 00:44:33 +00:00
}
2018-12-08 05:30:43 +00:00
void CPuddleToadGamma::CenterPlayer(CStateManager& mgr, const zeus::CVector3f& pos, float dt) {
zeus::CVector3f dir = (pos - mgr.GetPlayer().GetTranslation()).normalized();
2018-12-08 05:30:43 +00:00
mgr.GetPlayer().SetVelocityWR((1.f / (2.f * dt)) * dir);
2018-12-01 00:44:33 +00:00
}
const CDamageVulnerability* CPuddleToadGamma::GetDamageVulnerability(const zeus::CVector3f& pos,
const zeus::CVector3f& dir,
2018-12-08 05:30:43 +00:00
const CDamageInfo& dInfo) const {
if (x5e8_24_playerInside && (x5d8_damageablePoint - pos).magSquared() < 4.f)
2018-12-08 05:30:43 +00:00
return CAi::GetDamageVulnerability();
2018-12-01 00:44:33 +00:00
2018-12-08 05:30:43 +00:00
return &CDamageVulnerability::ImmuneVulnerabilty();
2018-12-01 00:44:33 +00:00
}
2018-12-08 05:30:43 +00:00
void CPuddleToadGamma::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node, EUserEventType type, float dt) {
if (type == EUserEventType::Projectile) {
ShootPlayer(mgr, x5c0_playerShootSpeed);
2018-12-08 05:30:43 +00:00
return;
}
2018-12-01 00:44:33 +00:00
2018-12-08 05:30:43 +00:00
CPatterned::DoUserAnimEvent(mgr, node, type, dt);
2018-12-01 00:44:33 +00:00
}
bool CPuddleToadGamma::SpotPlayer(CStateManager&, float arg) { return x56c_waitTimer >= x5c8_spotPlayerWaitTime; }
2018-12-01 00:44:33 +00:00
bool CPuddleToadGamma::ShouldAttack(CStateManager&, float) { return x56c_waitTimer >= x5c4_shouldAttackWaitTime; }
2018-12-01 00:44:33 +00:00
2018-12-08 05:30:43 +00:00
bool CPuddleToadGamma::LostInterest(CStateManager& mgr, float) {
zeus::CAABox box = *GetTouchBounds();
zeus::CAABox plBox = mgr.GetPlayer().GetBoundingBox();
return !box.intersects(plBox);
2018-12-01 00:44:33 +00:00
}
void CPuddleToadGamma::ShootPlayer(CStateManager& mgr, float speed) {
zeus::CVector3f shootDir = x34_transform.rotate(x5b4_localShootDir.normalized());
mgr.GetPlayer().SetLeaveMorphBallAllowed(true);
if (mgr.GetPlayer().GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Morphed) {
x5e8_26_shotPlayer = true;
mgr.GetPlayer().Stop();
mgr.GetPlayer().SetVelocityWR(zeus::skZero3f);
mgr.GetPlayer().ApplyImpulseWR(mgr.GetPlayer().GetMass() * shootDir * speed, {});
mgr.GetPlayer().SetMoveState(CPlayer::EPlayerMovementState::ApplyJump, mgr);
mgr.ApplyDamage(GetUniqueId(), mgr.GetPlayer().GetUniqueId(), GetUniqueId(), x570_playerShootDamage,
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), zeus::skZero3f);
mgr.GetPlayer().GetMorphBall()->SetAsProjectile();
rstl::reserved_vector<TUniqueId, 1024> nearList;
mgr.BuildNearList(nearList, GetBoundingBox(), CMaterialFilter::MakeInclude({EMaterialTypes::Bomb}), this);
for (TUniqueId id : nearList) {
if (TCastToPtr<CBomb> bomb = mgr.ObjectById(id)) {
bomb->SetVelocityWR((mgr.GetActiveRandom()->Float() * 5.f + 20.f) * shootDir);
bomb->SetConstantAccelerationWR({0.f, 0.f, -CPhysicsActor::GravityConstant()});
}
}
}
}
2018-12-01 00:44:33 +00:00
2018-12-08 05:30:43 +00:00
bool CPuddleToadGamma::InAttackPosition(CStateManager& mgr, float) {
return mgr.GetPlayer().GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Morphed &&
PlayerInVortexArea(mgr);
2018-12-01 00:44:33 +00:00
}
2018-12-08 05:30:43 +00:00
static CMaterialFilter kSolidFilter =
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {EMaterialTypes::Character, EMaterialTypes::Player,
EMaterialTypes::ProjectilePassthrough});
bool CPuddleToadGamma::PlayerInVortexArea(const CStateManager& mgr) {
CPlayer& player = mgr.GetPlayer();
zeus::CTransform xf = GetLctrTransform(mMouthLocatorName);
zeus::CVector3f playerOffset =
player.GetTranslation() + zeus::CVector3f{0.f, 0.f, player.GetMorphBall()->GetBallRadius()};
zeus::CVector3f rotatedDir = GetTransform().rotate(zeus::skForward);
2018-12-08 05:30:43 +00:00
zeus::CVector3f suckPointToPlayer = (playerOffset - (xf.origin - (1.f * rotatedDir)));
float suckProj = suckPointToPlayer.normalized().dot(rotatedDir);
float playerDist = suckPointToPlayer.magnitude();
float suckAngleProj = (player.GetTranslation() - (xf.origin - (4.f * rotatedDir))).normalized().dot(rotatedDir);
if (playerDist > 2.f) {
2018-12-08 05:30:43 +00:00
CRayCastResult result =
mgr.RayStaticIntersection(suckPointToPlayer, 1.f / playerDist * suckPointToPlayer,
playerDist - player.GetMorphBall()->GetBallRadius(), kSolidFilter);
2018-12-08 05:30:43 +00:00
if (result.IsValid())
return false;
}
return (playerDist < x5b0_playerSuckRange && suckProj > 0.f && suckAngleProj > x5ac_minSuckAngleProj);
2018-12-01 00:44:33 +00:00
}
2018-12-08 05:30:43 +00:00
void CPuddleToadGamma::InActive(CStateManager& mgr, EStateMsg msg, float) {
if (msg == EStateMsg::Activate) {
x450_bodyController->SetLocomotionType(pas::ELocomotionType::Relaxed);
SetSolid(mgr, true);
mgr.GetPlayer().SetLeaveMorphBallAllowed(true);
2018-12-08 05:30:43 +00:00
x330_stateMachineState.SetDelay(2.f);
}
2018-12-01 00:44:33 +00:00
}
2018-12-08 05:30:43 +00:00
void CPuddleToadGamma::Active(CStateManager& mgr, EStateMsg msg, float) {
if (msg == EStateMsg::Activate) {
x450_bodyController->SetLocomotionType(pas::ELocomotionType::Lurk);
zeus::CTransform xf = GetLctrTransform(mBellyLocatorName);
x5cc_suckPoint = xf.origin + GetTransform().rotate(skBellyOffset);
x56c_waitTimer = 0.f;
x5e8_25_waitTimerActive = true;
2018-12-08 05:30:43 +00:00
SetSolid(mgr, true);
mgr.GetPlayer().SetLeaveMorphBallAllowed(true);
2018-12-08 05:30:43 +00:00
} else if (msg == EStateMsg::Deactivate) {
x5e8_25_waitTimerActive = false;
2018-12-08 05:30:43 +00:00
}
2018-12-01 00:44:33 +00:00
}
2018-12-08 05:30:43 +00:00
void CPuddleToadGamma::Suck(CStateManager& mgr, EStateMsg msg, float arg) {
if (msg == EStateMsg::Activate) {
SetSolid(mgr, false);
mgr.GetPlayer().SetLeaveMorphBallAllowed(false);
2018-12-08 05:30:43 +00:00
mgr.GetPlayer().GetMorphBall()->DisableHalfPipeStatus();
} else if (msg == EStateMsg::Update) {
if (x568_stateProg == 0) {
2018-12-08 05:30:43 +00:00
if (x450_bodyController->GetBodyStateInfo().GetCurrentStateId() == pas::EAnimationState::LoopReaction) {
x568_stateProg = 1;
2018-12-01 00:44:33 +00:00
return;
2018-12-08 05:30:43 +00:00
}
x450_bodyController->GetCommandMgr().DeliverCmd(CBCLoopReactionCmd(pas::EReactionType::Zero));
} else if (x568_stateProg == 1)
2018-12-08 05:30:43 +00:00
SuckPlayer(mgr, arg);
} else if (msg == EStateMsg::Deactivate) {
x450_bodyController->GetCommandMgr().DeliverCmd(CBodyStateCmd(EBodyStateCmd::ExitState));
}
2018-12-01 00:44:33 +00:00
}
2018-12-08 05:30:43 +00:00
void CPuddleToadGamma::SuckPlayer(CStateManager& mgr, float arg) {
CPlayer& player = mgr.GetPlayer();
if (player.GetMorphballTransitionState() != CPlayer::EPlayerMorphBallState::Morphed)
return;
2018-12-01 00:44:33 +00:00
zeus::CVector3f posDiff = player.GetTranslation() - x5cc_suckPoint;
float posMag = posDiff.magnitude();
if (posMag < 3.f) {
2018-12-01 00:44:33 +00:00
player.Stop();
CenterPlayer(mgr, x5cc_suckPoint, arg);
2018-12-08 05:30:43 +00:00
return;
}
2018-12-01 00:44:33 +00:00
float forceMag = x5a8_suckForceMultiplier * (x5b0_playerSuckRange / (posMag * posMag));
zeus::CVector3f force = forceMag * (player.GetMass() * -posDiff);
player.ApplyForceWR(force, zeus::CAxisAngle());
2018-12-08 05:30:43 +00:00
}
2018-12-01 00:44:33 +00:00
2018-12-08 05:30:43 +00:00
void CPuddleToadGamma::Attack(CStateManager& mgr, EStateMsg msg, float) {
if (msg == EStateMsg::Activate) {
mgr.GetPlayer().Stop();
mgr.GetPlayer().SetVelocityWR({});
x450_bodyController->GetCommandMgr().DeliverCmd(CBCMeleeAttackCmd(pas::ESeverity::One));
x5e8_26_shotPlayer = false;
2018-12-08 05:30:43 +00:00
mgr.GetPlayer().GetMorphBall()->SetBombJumpState(CMorphBall::EBombJumpState::BombJumpDisabled);
} else if (msg == EStateMsg::Update) {
if (!x5e8_26_shotPlayer) {
2018-12-08 05:30:43 +00:00
zeus::CTransform xf = GetLctrTransform(mBellyLocatorName);
x5cc_suckPoint = xf.origin + GetTransform().rotate(skBellyOffset);
SetPlayerPosition(mgr, x5cc_suckPoint);
2018-12-08 05:30:43 +00:00
} else if (LostInterest(mgr, 0.f))
SetSolid(mgr, true);
} else if (msg == EStateMsg::Deactivate) {
SetSolid(mgr, true);
mgr.GetPlayer().SetLeaveMorphBallAllowed(true);
2018-12-08 05:30:43 +00:00
mgr.GetPlayer().GetMorphBall()->SetBombJumpState(CMorphBall::EBombJumpState::BombJumpAvailable);
x5e8_24_playerInside = false;
2018-12-08 05:30:43 +00:00
}
}
2018-12-01 00:44:33 +00:00
2018-12-08 05:30:43 +00:00
void CPuddleToadGamma::SetPlayerPosition(CStateManager& mgr, const zeus::CVector3f& targetPos) {
float preThinkDt = x500_preThinkDt;
CPlayer& player = mgr.GetPlayer();
player.Stop();
player.SetVelocityWR({});
bool hadPlayerMaterial = player.GetMaterialList().HasMaterial(EMaterialTypes::Player);
if (hadPlayerMaterial)
player.RemoveMaterial(EMaterialTypes::GroundCollider, mgr);
player.RemoveMaterial(EMaterialTypes::Player, mgr);
bool hadSolidMaterial = GetMaterialList().HasMaterial(EMaterialTypes::Solid);
if (hadSolidMaterial)
RemoveMaterial(EMaterialTypes::Solid, mgr);
CPhysicsState physState = player.GetPhysicsState();
player.Stop();
player.MoveToWR(targetPos, preThinkDt);
CGameCollision::Move(mgr, player, preThinkDt, nullptr);
physState.SetTranslation(player.GetTranslation());
player.SetPhysicsState(physState);
if (hadPlayerMaterial)
player.AddMaterial(EMaterialTypes::GroundCollider, mgr);
player.AddMaterial(EMaterialTypes::Player, mgr);
if (hadSolidMaterial)
AddMaterial(EMaterialTypes::Solid, mgr);
2018-12-01 00:44:33 +00:00
}
2018-12-08 05:30:43 +00:00
bool CPuddleToadGamma::Inside(CStateManager& mgr, float) {
if (mgr.GetPlayer().GetMorphballTransitionState() != CPlayer::EPlayerMorphBallState::Morphed)
return false;
2018-12-01 00:44:33 +00:00
zeus::CVector3f posDiff = mgr.GetPlayer().GetTranslation() - x5cc_suckPoint;
2018-12-08 05:30:43 +00:00
return posDiff.dot(GetTransform().frontVector()) <= 0.f && posDiff.magSquared() < 2.f;
2018-12-01 00:44:33 +00:00
}
2018-12-08 05:30:43 +00:00
void CPuddleToadGamma::Crouch(CStateManager& mgr, EStateMsg msg, float) {
if (msg == EStateMsg::Activate) {
x568_stateProg = 0;
x56c_waitTimer = 0.f;
x5e8_25_waitTimerActive = true;
x5e8_24_playerInside = true;
2018-12-08 05:30:43 +00:00
mgr.GetPlayer().Stop();
mgr.GetPlayer().SetVelocityWR({});
SendScriptMsgs(EScriptObjectState::Inside, mgr, EScriptObjectMessage::None);
if (!mgr.GetPlayer().AttachActorToPlayer(GetUniqueId(), false))
x56c_waitTimer = 100.f;
2018-12-08 05:30:43 +00:00
SetSolid(mgr, false);
mgr.GetPlayer().SetLeaveMorphBallAllowed(false);
2018-12-08 05:30:43 +00:00
mgr.GetPlayer().GetMorphBall()->DisableHalfPipeStatus();
SetSolid(mgr, false);
} else if (msg == EStateMsg::Update) {
zeus::CTransform xf = GetLctrTransform(mBellyLocatorName);
x5cc_suckPoint = xf.origin + GetTransform().rotate(skBellyOffset);
SetPlayerPosition(mgr, x5cc_suckPoint);
if (x568_stateProg == 0) {
2018-12-08 05:30:43 +00:00
if (x450_bodyController->GetBodyStateInfo().GetCurrentStateId() == pas::EAnimationState::Locomotion)
x568_stateProg = 1;
2018-12-08 05:30:43 +00:00
else
x450_bodyController->SetLocomotionType(pas::ELocomotionType::Crouch);
2018-12-01 00:44:33 +00:00
}
2018-12-08 05:30:43 +00:00
} else if (msg == EStateMsg::Deactivate) {
if (mgr.GetPlayer().GetAttachedActor() == GetUniqueId())
mgr.GetPlayer().DetachActorFromPlayer();
mgr.GetPlayer().SetLeaveMorphBallAllowed(true);
x5e8_25_waitTimerActive = false;
2018-12-08 05:30:43 +00:00
}
2018-02-11 05:27:00 +00:00
}
2018-12-08 05:30:43 +00:00
} // namespace urde::MP1