metaforce/Runtime/MP1/World/CMetroidBeta.cpp

340 lines
13 KiB
C++
Raw Permalink Normal View History

#include "Runtime/MP1/World/CMetroidBeta.hpp"
#include "Runtime/CSimplePool.hpp"
#include "Runtime/CStateManager.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Collision/CCollisionActor.hpp"
#include "Runtime/Collision/CCollisionActorManager.hpp"
#include "Runtime/Particle/CElementGen.hpp"
#include "Runtime/Particle/CParticleSwoosh.hpp"
#include "Runtime/Weapon/CGameProjectile.hpp"
#include "Runtime/World/CGameArea.hpp"
#include "Runtime/World/CPatternedInfo.hpp"
#include "Runtime/World/CPlayer.hpp"
#include "Runtime/World/CTeamAiMgr.hpp"
#include "Runtime/World/CWorld.hpp"
#include "Runtime/World/ScriptLoader.hpp"
2021-04-10 08:42:06 +00:00
namespace metaforce::MP1 {
CMetroidBetaData::CMetroidBetaData(CInputStream& in)
: x0_(in)
, x68_(in)
, xd0_(in.readFloatBig())
, xd4_(in.readFloatBig())
, xd8_(in.readFloatBig())
, xdc_(in.readFloatBig())
, xe0_(in.readFloatBig())
, xe4_(in.readFloatBig())
, xe8_(in.readFloatBig())
, xec_(in.readFloatBig())
, xf0_(in.readFloatBig())
, xf4_(in)
, xf8_(in)
, xfc_(in)
, x100_(in)
, x104_(in)
2018-12-08 05:30:43 +00:00
, x108_24_(in.readBool()) {}
2018-12-08 05:30:43 +00:00
CMetroidBeta::CMetroidBeta(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf,
CModelData&& mData, const CPatternedInfo& pInfo, const CActorParameters& aParms,
const CMetroidBetaData& metroidData)
: CPatterned(ECharacter::MetroidBeta, uid, name, EFlavorType::One, info, xf, std::move(mData), pInfo,
2019-08-11 15:14:52 +00:00
EMovementType::Flyer, EColliderType::One, EBodyType::Flyer, aParms, EKnockBackVariant::Large)
, x56c_metroidBetaData(metroidData)
, x67c_pathFind(nullptr, 3, pInfo.GetPathfindingIndex(), 1.f, 1.f)
, x768_colPrim(GetBoundingBox(), GetMaterialList())
, x7b4_(GetModelData()->GetScale())
, x7c0_(GetModelData()->GetScale())
, x7cc_(GetModelData()->GetScale())
, x7e4_(g_SimplePool->GetObj({FOURCC('PART'), metroidData.xf4_}))
, x7f0_(g_SimplePool->GetObj({FOURCC('SWHC'), metroidData.xf8_}))
, x7fc_(g_SimplePool->GetObj({FOURCC('PART'), metroidData.xfc_}))
, x808_(g_SimplePool->GetObj({FOURCC('PART'), metroidData.x100_}))
, x814_(g_SimplePool->GetObj({FOURCC('PART'), metroidData.x104_}))
, x820_(std::make_unique<CElementGen>(x7e4_))
, x824_(std::make_unique<CParticleSwoosh>(x7f0_, 0))
, x828_(std::make_unique<CElementGen>(x7fc_))
, x82c_(std::make_unique<CElementGen>(x808_))
, x830_(std::make_unique<CElementGen>(x814_)) {
2019-08-11 15:14:52 +00:00
x820_->SetParticleEmission(false);
x828_->SetParticleEmission(false);
x82c_->SetParticleEmission(false);
x824_->DoElectricWarmup();
const float scale = 0.75f * GetModelData()->GetScale().y();
const zeus::CVector3f scaleVec(scale, scale, 2.f * scale);
zeus::CAABox box = {-scaleVec, scaleVec};
SetBoundingBox(box);
x768_colPrim.SetBox(box);
}
void CMetroidBeta::Think(float dt, CStateManager& mgr) {
if (CTeamAiMgr::GetTeamAiRole(mgr, x678_teamMgr, GetUniqueId())) {
AddToTeam(mgr);
}
CPatterned::Think(dt, mgr);
x764_collisionManager->Update(dt, mgr, CCollisionActorManager::EUpdateOptions::ObjectSpace);
// sub801c1928(mgr);
// sub801c0da4(dt, mgr);
// sub801c21b4(dt, mgr);
}
2019-08-11 15:14:52 +00:00
void CMetroidBeta::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
CPatterned::AcceptScriptMsg(msg, uid, mgr);
switch (msg) {
case EScriptObjectMessage::Registered: {
x450_bodyController->Activate(mgr);
CreateCollisionActorManager(mgr);
2021-06-07 19:29:18 +00:00
// sub801c13d4();
2019-08-11 15:14:52 +00:00
x760_ = GetModelData()->GetAnimationData()->GetLocatorSegId("L_Claw_1"sv);
x761_ = GetModelData()->GetAnimationData()->GetLocatorSegId("R_Claw_1"sv);
break;
}
case EScriptObjectMessage::Activate: {
x764_collisionManager->SetActive(mgr, true);
break;
}
case EScriptObjectMessage::Deactivate: {
x764_collisionManager->SetActive(mgr, false);
break;
}
case EScriptObjectMessage::Deleted: {
x764_collisionManager->Destroy(mgr);
RemoveFromTeam(mgr);
break;
}
case EScriptObjectMessage::Damage:
case EScriptObjectMessage::InvulnDamage: {
if (TCastToPtr<CCollisionActor> colAct = mgr.ObjectById(uid)) {
if (TCastToConstPtr<CGameProjectile> proj = mgr.GetObjectById(colAct->GetLastTouchedObject())) {
if (proj->GetOwnerId() != mgr.GetPlayer().GetUniqueId())
break;
// sub801c14b4(proj->GetDamageInfo().GetDamage(), mgr);
const CDamageInfo& dInfo = proj->GetDamageInfo();
if (colAct->GetDamageVulnerability()->WeaponHits(dInfo.GetWeaponMode(), false)) {
if (dInfo.GetWeaponMode().IsCharged() || dInfo.GetWeaponMode().IsComboed() ||
dInfo.GetWeaponMode().GetType() == EWeaponType::Missile) {
x840_31_ = true;
x83c_ += 1.f;
}
KnockBack(proj->GetTranslation() - proj->GetPreviousPos(), mgr, dInfo, EKnockBackType::Direct, false,
2019-08-11 15:14:52 +00:00
dInfo.GetKnockBackPower());
}
if (x840_25_)
x83c_ += 0.1f;
x840_26_ = true;
}
} else if (TCastToConstPtr<CWeapon> weap = mgr.GetObjectById(uid)) {
CDamageInfo info = weap->GetDamageInfo();
info.SetRadius(0.f);
mgr.ApplyDamage(uid, x790_, weap->GetOwnerId(), info,
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), {});
}
break;
}
case EScriptObjectMessage::Alert: {
x840_26_ = true;
break;
}
case EScriptObjectMessage::Touched: {
if (TCastToConstPtr<CCollisionActor> colAct = mgr.GetObjectById(uid)) {
if (HealthInfo(mgr)->GetHP() > 0.f && colAct->GetLastTouchedObject() == mgr.GetPlayer().GetUniqueId() &&
2021-06-07 19:29:18 +00:00
x420_curDamageRemTime <= 0.f) {
CDamageInfo dInfo = GetContactDamage();
dInfo.SetDamage(0.5f * dInfo.GetDamage());
if (x840_29_ && x840_30_)
dInfo = GetContactDamage();
mgr.ApplyDamage(GetUniqueId(), mgr.GetPlayer().GetUniqueId(), GetUniqueId(), dInfo,
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), {});
x420_curDamageRemTime = x424_damageWaitTime;
x840_30_ = false;
}
}
2019-08-11 15:14:52 +00:00
break;
}
case EScriptObjectMessage::InitializedInArea: {
if (x678_teamMgr == kInvalidUniqueId)
x678_teamMgr = CTeamAiMgr::GetTeamAiMgr(*this, mgr);
x67c_pathFind.SetArea(mgr.GetWorld()->GetAreaAlways(GetAreaId())->GetPostConstructed()->x10bc_pathArea);
2019-08-11 15:14:52 +00:00
break;
}
case EScriptObjectMessage::SuspendedMove: {
if (x764_collisionManager)
x764_collisionManager->SetMovable(mgr, false);
break;
}
default:
break;
}
}
void CMetroidBeta::AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mgr) {
2019-08-11 15:14:52 +00:00
CPatterned::AddToRenderer(frustum, mgr);
}
void CMetroidBeta::Render(CStateManager& mgr) { CPatterned::Render(mgr); }
2019-08-11 15:14:52 +00:00
const CDamageVulnerability* CMetroidBeta::GetDamageVulnerability() const { return CAi::GetDamageVulnerability(); }
2019-08-11 15:14:52 +00:00
const CDamageVulnerability* CMetroidBeta::GetDamageVulnerability(const zeus::CVector3f& vec1,
const zeus::CVector3f& vec2,
const CDamageInfo& dInfo) const {
return CActor::GetDamageVulnerability(vec1, vec2, dInfo);
}
2019-08-11 15:14:52 +00:00
void CMetroidBeta::Touch(CActor& act, CStateManager& mgr) { CPatterned::Touch(act, mgr); }
2019-08-11 15:14:52 +00:00
zeus::CVector3f CMetroidBeta::GetAimPosition(const CStateManager& mgr, float dt) const {
return CPatterned::GetAimPosition(mgr, dt);
}
2019-08-11 15:14:52 +00:00
void CMetroidBeta::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node, EUserEventType eType, float dt) {
CPatterned::DoUserAnimEvent(mgr, node, eType, dt);
}
2019-08-11 15:14:52 +00:00
const CCollisionPrimitive* CMetroidBeta::GetCollisionPrimitive() const {
return CPhysicsActor::GetCollisionPrimitive();
}
2019-08-11 15:14:52 +00:00
void CMetroidBeta::CollidedWith(TUniqueId collidee, const CCollisionInfoList& info, CStateManager& mgr) {
CPatterned::CollidedWith(collidee, info, mgr);
}
2019-08-11 15:14:52 +00:00
zeus::CVector3f CMetroidBeta::GetOrigin(const CStateManager& mgr, const CTeamAiRole& role,
const zeus::CVector3f& aimPos) const {
return CAi::GetOrigin(mgr, role, aimPos);
}
2019-08-11 15:14:52 +00:00
void CMetroidBeta::Patrol(CStateManager& mgr, EStateMsg msg, float arg) { CPatterned::Patrol(mgr, msg, arg); }
2019-08-11 15:14:52 +00:00
void CMetroidBeta::PathFind(CStateManager& mgr, EStateMsg msg, float arg) { CPatterned::PathFind(mgr, msg, arg); }
2019-08-11 15:14:52 +00:00
void CMetroidBeta::SelectTarget(CStateManager& mgr, EStateMsg msg, float arg) { CAi::SelectTarget(mgr, msg, arg); }
2019-08-11 15:14:52 +00:00
void CMetroidBeta::TargetPatrol(CStateManager& mgr, EStateMsg msg, float arg) {
CPatterned::TargetPatrol(mgr, msg, arg);
}
2021-06-07 19:29:18 +00:00
void CMetroidBeta::Generate(CStateManager& mgr, EStateMsg msg, float arg) { CAi::Generate(mgr, msg, arg); }
2019-08-11 15:14:52 +00:00
void CMetroidBeta::Attack(CStateManager& mgr, EStateMsg msg, float arg) { CAi::Attack(mgr, msg, arg); }
2019-08-11 15:14:52 +00:00
void CMetroidBeta::TurnAround(CStateManager& mgr, EStateMsg msg, float arg) { CAi::TurnAround(mgr, msg, arg); }
2019-08-11 15:14:52 +00:00
void CMetroidBeta::TelegraphAttack(CStateManager& mgr, EStateMsg msg, float arg) {
CAi::TelegraphAttack(mgr, msg, arg);
}
2019-08-11 15:14:52 +00:00
void CMetroidBeta::WallHang(CStateManager& mgr, EStateMsg msg, float arg) { CAi::WallHang(mgr, msg, arg); }
2019-08-11 15:14:52 +00:00
void CMetroidBeta::SpecialAttack(CStateManager& mgr, EStateMsg msg, float arg) { CAi::SpecialAttack(mgr, msg, arg); }
2019-08-11 15:14:52 +00:00
bool CMetroidBeta::InAttackPosition(CStateManager& mgr, float arg) { return CAi::InAttackPosition(mgr, arg); }
2019-08-11 15:14:52 +00:00
bool CMetroidBeta::Attacked(CStateManager& mgr, float arg) { return CPatterned::Attacked(mgr, arg); }
2019-08-11 15:14:52 +00:00
bool CMetroidBeta::PathShagged(CStateManager& mgr, float arg) { return CPatterned::PathShagged(mgr, arg); }
2019-08-11 15:14:52 +00:00
bool CMetroidBeta::InDetectionRange(CStateManager& mgr, float arg) { return CPatterned::InDetectionRange(mgr, arg); }
2019-08-11 15:14:52 +00:00
bool CMetroidBeta::AnimOver(CStateManager& mgr, float arg) { return CPatterned::AnimOver(mgr, arg); }
2019-08-11 15:14:52 +00:00
bool CMetroidBeta::ShouldAttack(CStateManager& mgr, float arg) { return CAi::ShouldAttack(mgr, arg); }
2019-08-11 15:14:52 +00:00
bool CMetroidBeta::InPosition(CStateManager& mgr, float arg) { return CPatterned::InPosition(mgr, arg); }
2019-08-11 15:14:52 +00:00
bool CMetroidBeta::ShouldTurn(CStateManager& mgr, float arg) { return CAi::ShouldTurn(mgr, arg); }
2019-08-11 15:14:52 +00:00
bool CMetroidBeta::AttackOver(CStateManager& mgr, float arg) { return CAi::AttackOver(mgr, arg); }
2019-08-11 15:14:52 +00:00
bool CMetroidBeta::ShotAt(CStateManager& mgr, float arg) { return CAi::ShotAt(mgr, arg); }
2019-08-11 15:14:52 +00:00
bool CMetroidBeta::ShouldWallHang(CStateManager& mgr, float arg) { return CAi::ShouldWallHang(mgr, arg); }
2019-08-11 15:14:52 +00:00
bool CMetroidBeta::StartAttack(CStateManager& mgr, float arg) { return CAi::StartAttack(mgr, arg); }
2019-08-11 15:14:52 +00:00
bool CMetroidBeta::BreakAttack(CStateManager& mgr, float arg) { return CAi::BreakAttack(mgr, arg); }
2019-08-11 15:14:52 +00:00
bool CMetroidBeta::ShouldSpecialAttack(CStateManager& mgr, float arg) { return CAi::ShouldSpecialAttack(mgr, arg); }
2018-12-08 05:30:43 +00:00
void CMetroidBeta::RenderHitGunEffect() const {}
2017-08-31 02:42:37 +00:00
2018-12-08 05:30:43 +00:00
void CMetroidBeta::RenderHitBallEffect() const {}
2021-06-07 19:29:18 +00:00
static SSphereJointInfo skPelvisInfo[1]{
2019-08-11 15:14:52 +00:00
{"Pelvis", 1.5f},
};
2019-08-11 15:14:52 +00:00
void CMetroidBeta::CreateCollisionActorManager(CStateManager& mgr) {
std::vector<CJointCollisionDescription> joints;
AddSphereJoints(skPelvisInfo, 1, joints);
x764_collisionManager =
std::make_unique<CCollisionActorManager>(mgr, GetUniqueId(), GetAreaIdAlways(), joints, false);
2019-08-11 15:14:52 +00:00
x764_collisionManager->SetActive(mgr, GetActive());
for (u32 i = 0; i < x764_collisionManager->GetNumCollisionActors(); ++i) {
const CJointCollisionDescription& desc = x764_collisionManager->GetCollisionDescFromIndex(i);
if (TCastToPtr<CCollisionActor>(mgr.ObjectById(desc.GetCollisionActorId()))) {
if (desc.GetName() == "Pelvis"sv)
x790_ = desc.GetCollisionActorId();
}
}
SetCollisionActorHealthAndVulnerability(mgr);
SetMaterialFilter(CMaterialFilter::MakeIncludeExclude(
{EMaterialTypes::Solid, EMaterialTypes::Wall, EMaterialTypes::Floor, EMaterialTypes::Ceiling},
{EMaterialTypes::CollisionActor, EMaterialTypes::Player, EMaterialTypes::Character}));
AddMaterial(EMaterialTypes::ProjectilePassthrough, mgr);
x764_collisionManager->AddMaterial(mgr, CMaterialList(EMaterialTypes::AIJoint, EMaterialTypes::CameraPassthrough));
}
void CMetroidBeta::AddSphereJoints(SSphereJointInfo* sphereJoints, s32 count,
2021-06-07 19:29:18 +00:00
std::vector<CJointCollisionDescription>& joints) {
2019-08-11 15:14:52 +00:00
for (s32 i = 0; i < count; ++i) {
const auto& sphereJoint = sphereJoints[i];
const CSegId id = GetModelData()->GetAnimationData()->GetLocatorSegId(sphereJoint.name);
if (id.IsInvalid()) {
2019-08-11 15:14:52 +00:00
continue;
}
2019-08-11 15:14:52 +00:00
joints.push_back(CJointCollisionDescription::SphereCollision(id, sphereJoint.radius, sphereJoint.name, 1000.0f));
2019-08-11 15:14:52 +00:00
}
}
2019-08-11 15:14:52 +00:00
void CMetroidBeta::SetCollisionActorHealthAndVulnerability(CStateManager& mgr) {
CHealthInfo* hInfo = HealthInfo(mgr);
if (TCastToPtr<CCollisionActor> colAct = mgr.ObjectById(x790_)) {
*colAct->HealthInfo(mgr) = *hInfo;
colAct->SetDamageVulnerability(*GetDamageVulnerability());
}
}
2019-08-11 15:14:52 +00:00
void CMetroidBeta::RemoveFromTeam(CStateManager& mgr) {
if (x678_teamMgr == kInvalidUniqueId)
return;
if (TCastToPtr<CTeamAiMgr> teamMgr = mgr.ObjectById(x678_teamMgr)) {
if (teamMgr->IsPartOfTeam(GetUniqueId()))
teamMgr->RemoveTeamAiRole(GetUniqueId());
}
}
2019-08-11 15:14:52 +00:00
void CMetroidBeta::AddToTeam(CStateManager& mgr) {
if (x678_teamMgr == kInvalidUniqueId)
return;
if (TCastToPtr<CTeamAiMgr> teamMgr = mgr.ObjectById(x678_teamMgr)) {
if (!teamMgr->IsPartOfTeam(GetUniqueId()))
teamMgr->AssignTeamAiRole(*this, CTeamAiRole::ETeamAiRole::Ranged, CTeamAiRole::ETeamAiRole::Invalid,
CTeamAiRole::ETeamAiRole::Invalid);
}
}
2021-04-10 08:42:06 +00:00
} // namespace metaforce::MP1