metaforce/Runtime/World/CAi.cpp

99 lines
3.6 KiB
C++
Raw Normal View History

#include "CAi.hpp"
2016-04-24 02:46:13 +00:00
#include "Character/CModelData.hpp"
#include "CStateManager.hpp"
2016-09-17 06:40:45 +00:00
#include "CStateMachine.hpp"
#include "GameGlobalObjects.hpp"
#include "CSimplePool.hpp"
2018-09-07 05:24:55 +00:00
#include "CScriptWater.hpp"
2016-03-04 23:04:53 +00:00
namespace urde
{
2016-04-24 02:46:13 +00:00
static CMaterialList MakeAiMaterialList(const CMaterialList& in)
{
CMaterialList ret = in;
2016-12-29 21:38:59 +00:00
ret.Add(EMaterialTypes::AIBlock);
ret.Add(EMaterialTypes::CameraPassthrough);
2016-04-24 02:46:13 +00:00
return ret;
}
2017-11-13 06:19:18 +00:00
CAi::CAi(TUniqueId uid, bool active, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf,
2016-09-01 09:31:18 +00:00
CModelData&& mData, const zeus::CAABox& box, float mass, const CHealthInfo& hInfo,
2017-08-13 05:26:14 +00:00
const CDamageVulnerability& dmgVuln, const CMaterialList& list, CAssetId fsm, const CActorParameters& actorParams,
2016-09-01 09:31:18 +00:00
float stepUp, float stepDown)
: CPhysicsActor(uid, active, name, info, xf, std::move(mData), MakeAiMaterialList(list), box, SMoverData(mass),
actorParams, stepUp, stepDown)
, x258_healthInfo(hInfo)
, x260_damageVulnerability(dmgVuln)
, x2c8_stateMachine(g_SimplePool->GetObj({FOURCC('AFSM'), fsm}))
2016-04-24 02:46:13 +00:00
{
_CreateShadow();
if (x94_simpleShadow)
{
CreateShadow(true);
x94_simpleShadow->SetAlwaysCalculateRadius(false);
}
if (x90_actorLights)
x260_damageVulnerability.SetX38_25(true);
}
void CAi::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr)
{
if (msg == EScriptObjectMessage::InitializedInArea)
{
CMaterialList exclude = GetMaterialFilter().GetExcludeList();
CMaterialList include = GetMaterialFilter().GetIncludeList();
include.Add(EMaterialTypes::AIBlock);
SetMaterialFilter(CMaterialFilter::MakeIncludeExclude(include, exclude));
}
CActor::AcceptScriptMsg(msg, uid, mgr);
2016-04-24 02:46:13 +00:00
}
2018-09-07 05:24:55 +00:00
EWeaponCollisionResponseTypes CAi::GetCollisionResponseType(const zeus::CVector3f&, const zeus::CVector3f&,
const urde::CWeaponMode&, urde::EProjectileAttrib) const
{
return EWeaponCollisionResponseTypes::EnemyNormal;
}
void CAi::FluidFXThink(EFluidState state, CScriptWater& water, urde::CStateManager& mgr)
{
if (state == EFluidState::EnteredFluid || state == EFluidState::LeftFluid)
{
float dt = mgr.GetFluidPlaneManager()->GetLastSplashDeltaTime(GetUniqueId());
if (dt >= 0.02f)
{
float vel = (0.5f * GetMass()) * GetVelocity().magSquared();
if (vel > 500.f)
{
zeus::CVector3f pos = x34_transform.origin;
pos.z = water.GetTriggerBoundsWR().max.z;
mgr.GetFluidPlaneManager()->CreateSplash(GetUniqueId(), mgr, water, pos,
0.1f + ((0.4f * zeus::min(vel, 30000.f) - 500.f) / 29500.f),
true);
}
}
}
if (mgr.GetFluidPlaneManager()->GetLastRippleDeltaTime(GetUniqueId()) < (GetHealthInfo(mgr)->GetHP() > 0.f ? 0.2f : 0.7f))
return;
zeus::CVector3f pos = x34_transform.origin;
zeus::CVector3f center = pos;
center.z = water.GetTriggerBoundsWR().max.z;
pos.normalize();
water.GetFluidPlane().AddRipple(GetMass(), GetUniqueId(), center, GetVelocity(), water, mgr, pos);
}
CAiStateFunc CAi::GetStateFunc(const char* func) { return m_FuncMap->GetStateFunc(func); }
2016-04-24 02:46:13 +00:00
CAiTriggerFunc CAi::GetTrigerFunc(const char* func) { return m_FuncMap->GetTriggerFunc(func); }
2016-09-17 06:40:45 +00:00
const CStateMachine* CAi::GetStateMachine() const { return x2c8_stateMachine.GetObj(); }
void CAi::CreateFuncLookup(CAiFuncMap* funcMap) { m_FuncMap = funcMap; }
2016-04-24 02:46:13 +00:00
CAiFuncMap* CAi::m_FuncMap = nullptr;
}