metaforce/Runtime/MP1/World/CMetaree.cpp

181 lines
6.2 KiB
C++
Raw Normal View History

#include "Runtime/MP1/World/CMetaree.hpp"
#include "Runtime/CPlayerState.hpp"
#include "Runtime/CStateManager.hpp"
#include "Runtime/Weapon/CGameProjectile.hpp"
#include "Runtime/World/CPlayer.hpp"
2018-11-18 05:10:06 +00:00
#include "TCastTo.hpp" // Generated file, do not modify include path
2018-11-18 05:10:06 +00:00
2021-04-10 08:42:06 +00:00
namespace metaforce::MP1 {
2017-11-13 06:19:18 +00:00
CMetaree::CMetaree(TUniqueId uid, std::string_view name, EFlavorType flavor, const CEntityInfo& info,
2018-12-08 05:30:43 +00:00
const zeus::CTransform& xf, CModelData&& mData, const CPatternedInfo& pInfo,
const CDamageInfo& dInfo, float f1, const zeus::CVector3f& v1, float f2, EBodyType bodyType,
float f3, float f4, const CActorParameters& aParms)
2017-08-21 00:29:59 +00:00
: CPatterned(ECharacter::Metaree, uid, name, flavor, info, xf, std::move(mData), pInfo, EMovementType::Flyer,
2018-11-06 06:16:12 +00:00
EColliderType::Zero, bodyType, aParms, EKnockBackVariant::Small)
2018-11-18 05:10:06 +00:00
, x568_delay(f3)
2020-05-14 15:27:13 +00:00
, x56c_haltDelay(f4)
2018-11-18 05:10:06 +00:00
, x570_dropHeight(f1)
, x574_offset(v1)
, x580_attackSpeed(f2)
2020-01-03 00:54:59 +00:00
, x5ac_damageInfo(dInfo)
2017-08-21 00:29:59 +00:00
, x5ca_24_(true)
2018-11-18 05:10:06 +00:00
, x5ca_25_started(false)
2018-12-08 05:30:43 +00:00
, x5ca_26_deactivated(false) {}
2017-08-21 00:29:59 +00:00
2018-12-08 05:30:43 +00:00
void CMetaree::Accept(IVisitor& visitor) { visitor.Visit(this); }
2017-08-21 00:29:59 +00:00
2018-12-08 05:30:43 +00:00
void CMetaree::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
CPatterned::AcceptScriptMsg(msg, uid, mgr);
2017-08-21 00:29:59 +00:00
2020-05-14 15:27:13 +00:00
if (msg == EScriptObjectMessage::Start) {
2018-12-08 05:30:43 +00:00
x5ca_25_started = true;
2020-05-14 15:27:13 +00:00
} else if (msg == EScriptObjectMessage::Registered) {
2018-12-08 05:30:43 +00:00
x450_bodyController->Activate(mgr);
2020-05-14 15:27:13 +00:00
}
2017-08-21 00:29:59 +00:00
}
2018-11-18 05:10:06 +00:00
2018-12-08 05:30:43 +00:00
void CMetaree::Think(float dt, CStateManager& mgr) {
bool target = true;
if (mgr.GetPlayerState()->GetCurrentVisor() != CPlayerState::EPlayerVisor::Thermal &&
mgr.GetPlayerState()->GetCurrentVisor() != CPlayerState::EPlayerVisor::Scan) {
target = x5ca_26_deactivated;
}
xe7_31_targetable = target;
CPatterned::Think(dt, mgr);
2018-11-18 05:10:06 +00:00
}
2018-12-08 05:30:43 +00:00
void CMetaree::Explode(CStateManager& mgr, EStateMsg msg, float) {
2020-05-14 15:27:13 +00:00
if (msg != EStateMsg::Activate) {
2018-12-08 05:30:43 +00:00
return;
2020-05-14 15:27:13 +00:00
}
2018-11-18 05:10:06 +00:00
2020-01-03 00:54:59 +00:00
mgr.ApplyDamage(GetUniqueId(), mgr.GetPlayer().GetUniqueId(), GetUniqueId(), x5ac_damageInfo,
2018-12-08 05:30:43 +00:00
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), {});
MassiveDeath(mgr);
2018-11-18 05:10:06 +00:00
}
2018-12-08 05:30:43 +00:00
void CMetaree::Touch(CActor& act, CStateManager& mgr) {
2020-05-14 15:27:13 +00:00
if (!x400_25_alive) {
2018-12-08 05:30:43 +00:00
return;
2020-05-14 15:27:13 +00:00
}
2018-11-18 05:10:06 +00:00
2018-12-08 05:30:43 +00:00
if (TCastToPtr<CGameProjectile> projectile = act) {
2020-05-14 15:27:13 +00:00
if (projectile->GetOwnerId() != mgr.GetPlayer().GetUniqueId()) {
2018-12-08 05:30:43 +00:00
return;
2020-05-14 15:27:13 +00:00
}
2018-11-18 05:10:06 +00:00
2018-12-08 05:30:43 +00:00
x400_24_hitByPlayerProjectile = true;
x590_projectileDelta = projectile->GetTranslation() - projectile->GetPreviousPos();
}
2018-11-18 05:10:06 +00:00
}
2019-02-08 07:56:54 +00:00
void CMetaree::CollidedWith(TUniqueId id, const CCollisionInfoList& colList, CStateManager& mgr) {
2020-05-14 15:27:13 +00:00
if (!x400_25_alive || colList.GetCount() <= 0) {
2018-12-08 05:30:43 +00:00
return;
2020-05-14 15:27:13 +00:00
}
2018-11-18 05:10:06 +00:00
2020-01-03 00:54:59 +00:00
mgr.ApplyDamageToWorld(GetUniqueId(), *this, GetTranslation(), x5ac_damageInfo,
2018-12-08 05:30:43 +00:00
CMaterialFilter::MakeInclude({EMaterialTypes::Player}));
SendScriptMsgs(EScriptObjectState::Arrived, mgr, EScriptObjectMessage::None);
MassiveDeath(mgr);
2018-11-18 05:10:06 +00:00
}
2018-12-08 05:30:43 +00:00
void CMetaree::Flee(CStateManager& mgr, EStateMsg msg, float) {
if (msg == EStateMsg::Activate) {
2020-05-14 15:27:13 +00:00
ApplyImpulseWR(5.f * (GetMass() * (x590_projectileDelta * zeus::CVector3f{1.f, 1.f, 0.f})), zeus::CAxisAngle());
2018-11-18 05:10:06 +00:00
2018-12-08 05:30:43 +00:00
SetMomentumWR({0.f, 0.f, -GetGravityConstant() * GetMass()});
SetTranslation(GetTranslation());
x5a8_ = 0;
} else if (msg == EStateMsg::Update) {
2020-05-14 15:27:13 +00:00
if (x5a8_ != 0) {
2018-12-08 05:30:43 +00:00
return;
2020-05-14 15:27:13 +00:00
}
2018-11-18 05:10:06 +00:00
2018-12-08 05:30:43 +00:00
if (x450_bodyController->GetBodyStateInfo().GetCurrentStateId() == pas::EAnimationState::LieOnGround) {
x5a8_ = 1;
return;
2018-11-18 05:10:06 +00:00
}
2018-12-08 05:30:43 +00:00
x450_bodyController->GetCommandMgr().DeliverCmd(CBCKnockDownCmd({0.f, 1.f, 0.f}, pas::ESeverity::Zero));
}
}
void CMetaree::Dead(CStateManager& mgr, EStateMsg msg, float) {
2020-05-14 15:27:13 +00:00
if (msg != EStateMsg::Activate) {
2018-12-08 05:30:43 +00:00
return;
2020-05-14 15:27:13 +00:00
}
2018-12-08 05:30:43 +00:00
2020-01-03 00:54:59 +00:00
mgr.ApplyDamageToWorld(GetUniqueId(), *this, GetTranslation(), x5ac_damageInfo,
2018-12-08 05:30:43 +00:00
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Player}, {}));
DeathDelete(mgr);
}
void CMetaree::Attack(CStateManager&, EStateMsg msg, float) {
if (msg == EStateMsg::Activate) {
x5a8_ = 0;
zeus::CVector3f dir = (x584_lookPos - GetTranslation()).normalized();
SetVelocityWR(x580_attackSpeed * dir);
CSfxManager::AddEmitter(x5c8_attackSfx, GetTranslation(), {}, true, false, 127, kInvalidAreaId);
x450_bodyController->SetLocomotionType(pas::ELocomotionType::Combat);
x59c_velocity = x580_attackSpeed * dir;
} else if (msg == EStateMsg::Update) {
2020-05-14 15:27:13 +00:00
if (x450_bodyController->GetPercentageFrozen() == 0.f) {
2018-12-08 05:30:43 +00:00
SetVelocityWR(x59c_velocity);
2020-05-14 15:27:13 +00:00
} else {
2018-12-08 05:30:43 +00:00
Stop();
SetVelocityWR({});
2018-11-18 05:10:06 +00:00
}
2018-12-08 05:30:43 +00:00
}
}
void CMetaree::Halt(CStateManager& mgr, EStateMsg msg, float) {
2020-05-14 15:27:13 +00:00
if (msg != EStateMsg::Activate) {
2018-12-08 05:30:43 +00:00
return;
2020-05-14 15:27:13 +00:00
}
2018-12-08 05:30:43 +00:00
Stop();
2020-05-14 15:27:13 +00:00
SetVelocityWR(zeus::skZero3f);
SetMomentumWR(zeus::skZero3f);
2018-12-08 05:30:43 +00:00
x450_bodyController->SetLocomotionType(pas::ELocomotionType::Lurk);
x584_lookPos = x574_offset + mgr.GetPlayer().GetTranslation();
SetTransform(zeus::lookAt(GetTranslation(), x584_lookPos));
2020-05-14 15:27:13 +00:00
x330_stateMachineState.SetDelay(x56c_haltDelay);
2018-12-08 05:30:43 +00:00
}
void CMetaree::Active(CStateManager& mgr, EStateMsg msg, float) {
if (msg == EStateMsg::Activate) {
x400_24_hitByPlayerProjectile = false;
x584_lookPos = GetTranslation() - zeus::CVector3f{0.f, 0.f, x570_dropHeight};
x450_bodyController->GetCommandMgr().DeliverCmd(CBCGenerateCmd(pas::EGenerateType::Zero, x584_lookPos));
SetMomentumWR({0.f, 0.f, -GetGravityConstant() * GetMass()});
} else if (msg == EStateMsg::Update) {
2020-03-13 20:22:39 +00:00
x450_bodyController->GetCommandMgr().DeliverTargetVector(
2018-12-08 05:30:43 +00:00
(mgr.GetPlayer().GetTranslation() - GetTranslation()).normalized());
} else if (msg == EStateMsg::Deactivate) {
SetMomentumWR({});
}
2018-11-18 05:10:06 +00:00
}
2018-12-08 05:30:43 +00:00
void CMetaree::InActive(CStateManager&, EStateMsg msg, float) {
if (msg == EStateMsg::Activate) {
2020-05-14 15:27:13 +00:00
const auto locomotionType = x5ca_26_deactivated ? pas::ELocomotionType::Crouch : pas::ELocomotionType::Relaxed;
x450_bodyController->SetLocomotionType(locomotionType);
2018-12-08 05:30:43 +00:00
} else if (msg == EStateMsg::Deactivate) {
x5ca_26_deactivated = true;
}
2018-11-18 05:10:06 +00:00
}
2018-12-08 05:30:43 +00:00
bool CMetaree::InRange(CStateManager& mgr, float arg) {
2020-05-14 15:27:13 +00:00
if (x5ca_25_started) {
2018-12-08 05:30:43 +00:00
return true;
2020-05-14 15:27:13 +00:00
}
2018-11-18 05:10:06 +00:00
2018-12-08 05:30:43 +00:00
return CPatterned::InRange(mgr, arg);
2018-11-18 05:10:06 +00:00
}
2018-12-08 05:30:43 +00:00
bool CMetaree::ShouldAttack(CStateManager&, float) { return GetTranslation().z() < x584_lookPos.z(); }
2021-04-10 08:42:06 +00:00
} // namespace metaforce::MP1