2020-01-15 12:07:48 +00:00
|
|
|
#include "Runtime/MP1/World/CFireFlea.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CPlayerState.hpp"
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/World/CPatternedInfo.hpp"
|
|
|
|
#include "Runtime/World/CWorld.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2018-10-11 22:57:05 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce::MP1 {
|
2020-04-05 09:25:44 +00:00
|
|
|
namespace {
|
|
|
|
constexpr zeus::CColor skEndFadeColor{1.f, 1.f, 0.5f, 1.f};
|
|
|
|
constexpr zeus::CColor skStartFadeColor{1.f, 0.f, 0.f, 0.f};
|
|
|
|
} // Anonymous namespace
|
2018-10-11 22:57:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
// region Fire Flea Death Camera
|
2018-11-10 02:47:07 +00:00
|
|
|
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CColor CFireFlea::CDeathCameraEffect::sCurrentFadeColor = zeus::skClear;
|
2018-11-10 02:47:07 +00:00
|
|
|
|
|
|
|
CFireFlea::CDeathCameraEffect::CDeathCameraEffect(TUniqueId uid, TAreaId areaId, std::string_view name)
|
2018-12-08 05:30:43 +00:00
|
|
|
: CEntity(uid, CEntityInfo(areaId, CEntity::NullConnectionList), true, name) {}
|
|
|
|
|
|
|
|
void CFireFlea::CDeathCameraEffect::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
|
|
|
|
|
|
|
void CFireFlea::CDeathCameraEffect::PreThink(float dt, CStateManager& mgr) {
|
2022-03-23 05:35:13 +00:00
|
|
|
auto& filterPass = mgr.GetCameraFilterPass(5);
|
2018-12-08 05:30:43 +00:00
|
|
|
u32 r5 = x34_ + x38_;
|
|
|
|
u32 r8 = r5 + x3c_;
|
|
|
|
u32 r31 = r8 + x40_;
|
|
|
|
if (x44_ >= x34_ && x44_ <= r5) {
|
|
|
|
sCurrentFadeColor += zeus::CColor::lerp(skStartFadeColor, skEndFadeColor, x34_ - x44_);
|
|
|
|
filterPass.SetFilter(EFilterType::Blend, EFilterShape::Fullscreen, 0.f, sCurrentFadeColor, CAssetId());
|
|
|
|
} else if (x44_ >= r8 && x44_ <= r31) {
|
|
|
|
sCurrentFadeColor += zeus::CColor::lerp(skEndFadeColor, skStartFadeColor, r8 - x44_);
|
|
|
|
filterPass.SetFilter(EFilterType::Blend, EFilterShape::Fullscreen, 0.f, sCurrentFadeColor, CAssetId());
|
|
|
|
} else if (x44_ > r5) {
|
|
|
|
sCurrentFadeColor = skEndFadeColor;
|
|
|
|
filterPass.SetFilter(EFilterType::Blend, EFilterShape::Fullscreen, 0.f, sCurrentFadeColor, CAssetId());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r31 == x44_) {
|
|
|
|
filterPass.DisableFilter(0.f);
|
|
|
|
mgr.FreeScriptObject(GetUniqueId());
|
|
|
|
x44_ = 0;
|
|
|
|
} else
|
|
|
|
x44_++;
|
|
|
|
|
|
|
|
if (mgr.GetPlayerState()->GetActiveVisor(mgr) != CPlayerState::EPlayerVisor::Thermal)
|
|
|
|
filterPass.DisableFilter(0.f);
|
2018-11-10 02:47:07 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 07:15:54 +00:00
|
|
|
void CFireFlea::CDeathCameraEffect::Think(float dt, CStateManager& mgr) { sCurrentFadeColor = zeus::skClear; }
|
2018-11-10 02:47:07 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
// endregion
|
2018-11-10 02:47:07 +00:00
|
|
|
|
2018-11-17 05:05:57 +00:00
|
|
|
s32 CFireFlea::sLightIdx = 0;
|
|
|
|
|
2018-10-11 22:57:05 +00:00
|
|
|
CFireFlea::CFireFlea(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf,
|
2018-11-17 05:05:57 +00:00
|
|
|
CModelData&& mData, const CActorParameters& actParms, const CPatternedInfo& pInfo, float f1)
|
2018-12-08 05:30:43 +00:00
|
|
|
: CPatterned(ECharacter::FireFlea, uid, name, EFlavorType::Zero, info, xf, std::move(mData), pInfo,
|
2019-01-23 07:52:19 +00:00
|
|
|
EMovementType::Flyer, EColliderType::One, EBodyType::Flyer, actParms, EKnockBackVariant::Small)
|
2018-12-08 05:30:43 +00:00
|
|
|
, x56c_(f1)
|
2020-07-13 03:28:14 +00:00
|
|
|
, xd8c_pathFind(nullptr, 3, pInfo.GetPathfindingIndex(), 1.f, 1.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CMaterialFilter filter = GetMaterialFilter();
|
|
|
|
filter.ExcludeList().Add(EMaterialTypes::Character);
|
|
|
|
SetMaterialFilter(filter);
|
|
|
|
|
2019-08-14 14:58:54 +00:00
|
|
|
GetModelData()->GetAnimationData()->SetParticleLightIdx(sLightIdx);
|
2018-12-08 05:30:43 +00:00
|
|
|
++sLightIdx;
|
2018-11-17 05:05:57 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CFireFlea::Dead(CStateManager& mgr, EStateMsg msg, float dt) {
|
|
|
|
if (msg != EStateMsg::Activate || mgr.GetPlayerState()->GetActiveVisor(mgr) != CPlayerState::EPlayerVisor::Thermal)
|
|
|
|
return;
|
2018-11-17 05:05:57 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.AddObject(new CDeathCameraEffect(mgr.AllocateUniqueId(), GetAreaIdAlways(), ""sv));
|
2018-11-17 05:05:57 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CFireFlea::Delay(CStateManager&, float arg) { return x330_stateMachineState.GetTime() > 0.5f; }
|
2018-10-11 22:57:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CFireFlea::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
|
|
|
|
|
|
|
void CFireFlea::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
|
|
|
|
CPatterned::AcceptScriptMsg(msg, uid, mgr);
|
2018-11-17 05:05:57 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (msg == EScriptObjectMessage::Registered) {
|
|
|
|
x450_bodyController->Activate(mgr);
|
|
|
|
} else if (msg == EScriptObjectMessage::InitializedInArea) {
|
|
|
|
xd8c_pathFind.SetArea(mgr.GetWorld()->GetAreaAlways(GetAreaIdAlways())->GetPostConstructed()->x10bc_pathArea);
|
2020-02-07 21:27:53 +00:00
|
|
|
xd8c_pathFind.SetPadding(50.0f);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-11-17 05:05:57 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CFireFlea::InPosition(CStateManager& mgr, float dt) {
|
|
|
|
if (x2dc_destObj == kInvalidUniqueId)
|
|
|
|
return false;
|
2018-12-10 05:12:55 +00:00
|
|
|
return (xd80_targetPos - GetTranslation()).magnitude() < 25.f;
|
|
|
|
}
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
bool CFireFlea::HearShot(metaforce::CStateManager& mgr, float arg) {
|
2018-12-10 05:12:55 +00:00
|
|
|
x570_nearList.clear();
|
|
|
|
mgr.BuildNearList(x570_nearList, zeus::CAABox(GetTranslation() - 10.f, GetTranslation() + 10.f),
|
|
|
|
CMaterialFilter::MakeInclude({EMaterialTypes::Projectile}), nullptr);
|
|
|
|
|
|
|
|
return !x570_nearList.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFireFlea::TargetPatrol(CStateManager& mgr, EStateMsg msg, float arg) {
|
|
|
|
if (msg == EStateMsg::Activate) {
|
|
|
|
CPatterned::Patrol(mgr, msg, arg);
|
|
|
|
UpdateDest(mgr);
|
|
|
|
xd80_targetPos = x2e0_destPos;
|
|
|
|
} else if (msg == EStateMsg::Update) {
|
|
|
|
if (auto* pathFind = GetSearchPath()) {
|
|
|
|
if (pathFind->GetResult() != CPathFindSearch::EResult::Success) {
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CVector3f closestPoint = zeus::skZero3f;
|
2018-12-10 05:12:55 +00:00
|
|
|
if (pathFind->FindClosestReachablePoint(GetTranslation(), closestPoint) == CPathFindSearch::EResult::Success) {
|
|
|
|
zeus::CVector3f delta = FindSafeRoute(mgr, x45c_steeringBehaviors.Arrival(*this, xd80_targetPos, 5.f));
|
|
|
|
x450_bodyController->GetCommandMgr().DeliverCmd(CBCLocomotionCmd(delta, {}, 1.f));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PathFind(mgr, msg, arg);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
x450_bodyController->GetCommandMgr().DeliverCmd(
|
2019-01-31 20:44:05 +00:00
|
|
|
CBCLocomotionCmd(x45c_steeringBehaviors.Arrival(*this, xd80_targetPos, 5.f), {}, 1.f));
|
2018-12-10 05:12:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-02 09:34:12 +00:00
|
|
|
zeus::CVector3f CFireFlea::FindSafeRoute(CStateManager& mgr, const zeus::CVector3f& forward) const {
|
2020-04-05 09:36:25 +00:00
|
|
|
const float mag = forward.magnitude();
|
|
|
|
if (mag <= 0.f) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const CRayCastResult res = mgr.RayStaticIntersection(GetTranslation(), forward.normalized(), 1.f,
|
|
|
|
CMaterialFilter::MakeInclude({EMaterialTypes::Solid}));
|
|
|
|
if (res.IsInvalid() && !CheckNearWater(mgr, forward.normalized())) {
|
|
|
|
return forward;
|
|
|
|
}
|
|
|
|
|
|
|
|
const zeus::CVector3f right = forward.normalized().cross(zeus::skUp).normalized();
|
|
|
|
const CRayCastResult res1 =
|
|
|
|
mgr.RayStaticIntersection(GetTranslation(), right, 1.f, CMaterialFilter::MakeInclude({EMaterialTypes::Solid}));
|
|
|
|
if (res1.IsInvalid()) {
|
|
|
|
return mag * right;
|
|
|
|
}
|
|
|
|
|
|
|
|
const zeus::CVector3f left = -right;
|
|
|
|
const CRayCastResult res2 =
|
|
|
|
mgr.RayStaticIntersection(GetTranslation(), left, 1.f, CMaterialFilter::MakeInclude({EMaterialTypes::Solid}));
|
|
|
|
if (res2.IsInvalid()) {
|
|
|
|
return mag * left;
|
|
|
|
}
|
|
|
|
|
|
|
|
const zeus::CVector3f up = right.cross(forward.normalized());
|
|
|
|
const CRayCastResult res3 =
|
|
|
|
mgr.RayStaticIntersection(GetTranslation(), up, 1.f, CMaterialFilter::MakeInclude({EMaterialTypes::Solid}));
|
|
|
|
if (res3.IsInvalid()) {
|
|
|
|
return mag * up;
|
|
|
|
}
|
|
|
|
|
|
|
|
const zeus::CVector3f down = -up;
|
|
|
|
const CRayCastResult res4 =
|
|
|
|
mgr.RayStaticIntersection(GetTranslation(), down, 1.f, CMaterialFilter::MakeInclude({EMaterialTypes::Solid}));
|
|
|
|
if (res4.IsInvalid()) {
|
|
|
|
return mag * down;
|
2018-12-10 05:12:55 +00:00
|
|
|
}
|
2020-04-05 09:36:25 +00:00
|
|
|
|
|
|
|
return -forward;
|
2018-12-10 05:12:55 +00:00
|
|
|
}
|
|
|
|
|
2020-08-02 09:34:12 +00:00
|
|
|
bool CFireFlea::CheckNearWater(const CStateManager& mgr, const zeus::CVector3f& dir) const {
|
2021-06-07 00:07:45 +00:00
|
|
|
EntityList nearList;
|
2018-12-10 05:12:55 +00:00
|
|
|
mgr.BuildNearList(nearList, GetTranslation(), dir, 2.f, CMaterialFilter::skPassEverything, nullptr);
|
|
|
|
|
2020-09-18 20:47:59 +00:00
|
|
|
for (const auto& id : nearList) {
|
2019-07-19 08:30:11 +00:00
|
|
|
if (TCastToConstPtr<CScriptWater>(mgr.GetObjectById(id)))
|
2018-12-10 05:12:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFireFlea::Patrol(CStateManager& mgr, EStateMsg msg, float arg) {
|
|
|
|
if (!zeus::close_enough(x310_moveVec, {}))
|
|
|
|
x310_moveVec.normalize();
|
|
|
|
|
|
|
|
x310_moveVec = FindSafeRoute(mgr, x310_moveVec);
|
|
|
|
CPatterned::Patrol(mgr, msg, arg);
|
|
|
|
if (x2d8_patrolState == EPatrolState::Done)
|
|
|
|
mgr.FreeScriptObject(GetUniqueId());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFireFlea::Flee(CStateManager& mgr, EStateMsg msg, float) {
|
|
|
|
if (msg == EStateMsg::Activate) {
|
|
|
|
x450_bodyController->SetLocomotionType(pas::ELocomotionType::Lurk);
|
|
|
|
} else if (msg == EStateMsg::Update) {
|
|
|
|
if (x570_nearList.empty()) {
|
|
|
|
x450_bodyController->GetCommandMgr().DeliverCmd(CBCLocomotionCmd(FindSafeRoute(mgr, xd74_), {}, 1.f));
|
|
|
|
} else {
|
|
|
|
for (TUniqueId id : x570_nearList) {
|
|
|
|
if (const CActor* act = static_cast<const CActor*>(mgr.GetObjectById(id))) {
|
|
|
|
zeus::CVector3f fleeDirection = x45c_steeringBehaviors.Flee(*this, act->GetTranslation());
|
|
|
|
x450_bodyController->GetCommandMgr().DeliverCmd(CBCLocomotionCmd(FindSafeRoute(mgr, fleeDirection), {}, 1.f));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (msg == EStateMsg::Deactivate) {
|
|
|
|
x450_bodyController->SetLocomotionType(pas::ELocomotionType::Relaxed);
|
|
|
|
}
|
2018-10-11 22:57:05 +00:00
|
|
|
}
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce::MP1
|