metaforce/Runtime/World/CAi.cpp

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

#include "Runtime/World/CAi.hpp"
#include "Runtime/CSimplePool.hpp"
#include "Runtime/CStateManager.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Character/CModelData.hpp"
#include "Runtime/World/CScriptWater.hpp"
#include "Runtime/World/CStateMachine.hpp"
2021-04-10 08:42:06 +00:00
namespace metaforce {
2018-12-08 05:30:43 +00:00
static CMaterialList MakeAiMaterialList(const CMaterialList& in) {
CMaterialList ret = in;
ret.Add(EMaterialTypes::AIBlock);
ret.Add(EMaterialTypes::CameraPassthrough);
return ret;
2016-04-24 02:46:13 +00:00
}
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,
2018-12-08 05:30:43 +00:00
const CDamageVulnerability& dmgVuln, const CMaterialList& list, CAssetId fsm,
const CActorParameters& actorParams, 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)
2018-12-08 05:30:43 +00:00
, x2c8_stateMachine(g_SimplePool->GetObj({FOURCC('AFSM'), fsm})) {
_CreateShadow();
2018-12-08 05:30:43 +00:00
if (x94_simpleShadow) {
CreateShadow(true);
x94_simpleShadow->SetAlwaysCalculateRadius(false);
}
2018-12-08 05:30:43 +00:00
if (x90_actorLights)
x90_actorLights->SetCastShadows(true);
}
2018-12-08 05:30:43 +00:00
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));
}
2018-12-08 05:30:43 +00:00
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&,
2021-04-10 08:42:06 +00:00
const metaforce::CWeaponMode&,
metaforce::EProjectileAttrib) const {
2018-12-08 05:30:43 +00:00
return EWeaponCollisionResponseTypes::EnemyNormal;
2018-09-07 05:24:55 +00:00
}
2021-04-10 08:42:06 +00:00
void CAi::FluidFXThink(EFluidState state, CScriptWater& water, metaforce::CStateManager& mgr) {
2018-12-08 05:30:43 +00:00
if (state == EFluidState::EnteredFluid || state == EFluidState::LeftFluid) {
float dt = mgr.GetFluidPlaneManager()->GetLastSplashDeltaTime(GetUniqueId());
if (dt >= 0.02f) {
float vel = (0.5f * GetMass()) * GetVelocity().magSquared();
2018-09-07 05:24:55 +00:00
2018-12-08 05:30:43 +00:00
if (vel > 500.f) {
zeus::CVector3f pos = x34_transform.origin;
pos.z() = float(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);
}
2018-09-07 05:24:55 +00:00
}
2018-12-08 05:30:43 +00:00
}
2018-09-07 05:24:55 +00:00
2018-12-08 05:30:43 +00:00
if (mgr.GetFluidPlaneManager()->GetLastRippleDeltaTime(GetUniqueId()) <
(GetHealthInfo(mgr)->GetHP() > 0.f ? 0.2f : 0.7f))
return;
2018-09-07 05:24:55 +00:00
2018-12-08 05:30:43 +00:00
zeus::CVector3f pos = x34_transform.origin;
zeus::CVector3f center = pos;
center.z() = float(water.GetTriggerBoundsWR().max.z());
pos.normalize();
water.GetFluidPlane().AddRipple(GetMass(), GetUniqueId(), center, GetVelocity(), water, mgr, pos);
2018-09-07 05:24:55 +00:00
}
CAiStateFunc CAi::GetStateFunc(std::string_view func) { return m_FuncMap->GetStateFunc(func); }
2016-04-24 02:46:13 +00:00
CAiTriggerFunc CAi::GetTriggerFunc(std::string_view 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;
2021-04-10 08:42:06 +00:00
} // namespace metaforce