2020-03-30 07:05:16 +00:00
|
|
|
#include "Runtime/MP1/World/CBouncyGrenade.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CPlayerState.hpp"
|
|
|
|
#include "Runtime/CSimplePool.hpp"
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
2022-02-25 07:45:25 +00:00
|
|
|
#include "Runtime/Graphics/CCubeRenderer.hpp"
|
2020-03-30 07:05:16 +00:00
|
|
|
#include "Runtime/World/CPlayer.hpp"
|
|
|
|
#include "Runtime/Collision/CCollisionActor.hpp"
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce::MP1 {
|
2020-03-30 07:05:16 +00:00
|
|
|
CBouncyGrenade::CBouncyGrenade(TUniqueId uid, std::string_view name, const CEntityInfo& info,
|
|
|
|
const zeus::CTransform& xf, CModelData&& mData, const CActorParameters& actParams,
|
|
|
|
TUniqueId parentId, const SBouncyGrenadeData& data, float velocity,
|
|
|
|
float explodePlayerDistance)
|
2020-04-01 05:38:48 +00:00
|
|
|
: CPhysicsActor(uid, true, name, info, xf, std::move(mData), {EMaterialTypes::Projectile, EMaterialTypes::Solid},
|
2020-04-01 19:32:38 +00:00
|
|
|
mData.GetBounds(), SMoverData{data.GetUnkStruct().GetMass()}, actParams, 0.3f, 0.1f)
|
2020-03-30 07:05:16 +00:00
|
|
|
, x258_data(data)
|
2020-03-31 00:40:38 +00:00
|
|
|
, x294_numBounces(data.GetNumBounces())
|
2020-03-30 07:05:16 +00:00
|
|
|
, x298_parentId(parentId)
|
2020-12-18 11:05:22 +00:00
|
|
|
, x2a0_elementGenCombat(std::make_unique<CElementGen>(g_SimplePool->GetObj({'PART', data.GetElementGenId1()})))
|
|
|
|
, x2a4_elementGenXRay(std::make_unique<CElementGen>(g_SimplePool->GetObj({'PART', data.GetElementGenId2()})))
|
|
|
|
, x2a8_elementGenThermal(std::make_unique<CElementGen>(g_SimplePool->GetObj({'PART', data.GetElementGenId3()})))
|
2020-03-31 00:40:38 +00:00
|
|
|
, x2ac_elementGen4(std::make_unique<CElementGen>(g_SimplePool->GetObj({'PART', data.GetElementGenId4()})))
|
2020-04-21 07:22:41 +00:00
|
|
|
, x2b0_explodePlayerDistance(explodePlayerDistance) {
|
2020-03-30 07:05:16 +00:00
|
|
|
SetMomentumWR({0.f, 0.f, -GravityConstant() * GetMass()});
|
|
|
|
SetVelocityWR(velocity * xf.frontVector());
|
2020-12-18 11:05:22 +00:00
|
|
|
x2a0_elementGenCombat->SetParticleEmission(false);
|
|
|
|
x2a4_elementGenXRay->SetParticleEmission(false);
|
|
|
|
x2a8_elementGenThermal->SetParticleEmission(false);
|
2020-03-30 07:05:16 +00:00
|
|
|
x2ac_elementGen4->SetParticleEmission(true);
|
|
|
|
CMaterialFilter filter = GetMaterialFilter();
|
|
|
|
filter.ExcludeList().Add(EMaterialTypes::Character);
|
|
|
|
SetMaterialFilter(CMaterialFilter::MakeIncludeExclude(filter.IncludeList(), filter.ExcludeList()));
|
|
|
|
}
|
|
|
|
|
2020-04-05 11:54:02 +00:00
|
|
|
void CBouncyGrenade::AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mgr) {
|
2020-03-30 07:05:16 +00:00
|
|
|
CActor::AddToRenderer(frustum, mgr);
|
|
|
|
if (!x2b4_24_exploded) {
|
|
|
|
g_Renderer->AddParticleGen(*x2ac_elementGen4);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto visor = mgr.GetPlayerState()->GetActiveVisor(mgr);
|
|
|
|
if (visor == CPlayerState::EPlayerVisor::Combat || visor == CPlayerState::EPlayerVisor::Scan) {
|
2020-12-18 11:05:22 +00:00
|
|
|
g_Renderer->AddParticleGen(*x2a0_elementGenCombat);
|
2020-03-30 07:05:16 +00:00
|
|
|
} else if (visor == CPlayerState::EPlayerVisor::XRay || visor == CPlayerState::EPlayerVisor::Thermal) {
|
2020-12-18 11:05:22 +00:00
|
|
|
g_Renderer->AddParticleGen(*x2a8_elementGenThermal);
|
2020-03-30 07:05:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBouncyGrenade::CollidedWith(TUniqueId id, const CCollisionInfoList& list, CStateManager& mgr) {
|
|
|
|
constexpr auto matList = CMaterialList{
|
|
|
|
EMaterialTypes::Solid,
|
|
|
|
EMaterialTypes::Ceiling,
|
|
|
|
EMaterialTypes::Floor,
|
|
|
|
EMaterialTypes::Character,
|
|
|
|
};
|
|
|
|
|
|
|
|
bool shouldExplode = false;
|
|
|
|
if (x298_parentId != id) {
|
|
|
|
const CEntity* const entity = mgr.GetObjectById(id);
|
|
|
|
if (entity != nullptr) {
|
|
|
|
if (TCastToConstPtr<CCollisionActor> actor = entity) {
|
|
|
|
shouldExplode = actor->GetOwnerId() != x298_parentId;
|
|
|
|
} else {
|
|
|
|
shouldExplode = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (shouldExplode) {
|
|
|
|
Explode(mgr, id);
|
|
|
|
} else {
|
|
|
|
for (const auto& info : list) {
|
|
|
|
if (info.GetMaterialLeft().SharesMaterials(matList)) {
|
|
|
|
if (x294_numBounces == 0) {
|
|
|
|
Explode(mgr, kInvalidUniqueId);
|
|
|
|
} else {
|
|
|
|
const zeus::CVector3f* normal = &info.GetNormalLeft();
|
|
|
|
if (GetVelocity().dot(info.GetNormalLeft()) > 0.f) {
|
|
|
|
normal = &info.GetNormalRight();
|
|
|
|
}
|
2020-03-31 00:40:38 +00:00
|
|
|
const zeus::CVector3f impulse =
|
|
|
|
(x258_data.GetUnkStruct().GetSpeed() * GetConstantForce().magnitude()) * *normal;
|
|
|
|
const zeus::CVector3f angle = -x258_data.GetUnkStruct().GetSpeed() * GetAngularMomentum();
|
2020-03-30 07:05:16 +00:00
|
|
|
ApplyImpulseWR(impulse, angle);
|
2020-03-31 00:40:38 +00:00
|
|
|
CSfxManager::AddEmitter(x258_data.GetBounceSfx(), GetTranslation(), zeus::skUp, false, false, 0x7f,
|
2020-03-30 07:05:16 +00:00
|
|
|
GetAreaIdAlways());
|
2020-04-01 19:01:44 +00:00
|
|
|
--x294_numBounces;
|
2020-03-30 07:05:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CPhysicsActor::CollidedWith(id, list, mgr);
|
|
|
|
}
|
|
|
|
|
2020-03-31 00:40:38 +00:00
|
|
|
std::optional<zeus::CAABox> CBouncyGrenade::GetTouchBounds() const { return GetModelData()->GetBounds(GetTransform()); }
|
2020-03-30 07:05:16 +00:00
|
|
|
|
2020-04-09 17:28:20 +00:00
|
|
|
void CBouncyGrenade::Render(CStateManager& mgr) {
|
2020-03-30 07:05:16 +00:00
|
|
|
if (!x2b4_24_exploded) {
|
|
|
|
GetModelData()->Render(mgr, GetTransform(), nullptr, {0, 0, 3, zeus::skWhite});
|
|
|
|
} else if (mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::XRay) {
|
2020-09-14 00:35:35 +00:00
|
|
|
CElementGen::SetSubtractBlend(true);
|
|
|
|
CElementGen::SetMoveRedToAlphaBuffer(true);
|
2020-03-30 07:05:16 +00:00
|
|
|
CGraphics::SetFog(ERglFogMode::PerspLin, 0.f, 75.f, zeus::skBlack);
|
2020-12-18 11:05:22 +00:00
|
|
|
x2a4_elementGenXRay->Render();
|
2020-03-30 07:05:16 +00:00
|
|
|
mgr.SetupFogForArea(GetAreaIdAlways());
|
2020-09-14 00:35:35 +00:00
|
|
|
CElementGen::SetSubtractBlend(false);
|
|
|
|
CElementGen::SetMoveRedToAlphaBuffer(false);
|
2020-03-30 07:05:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBouncyGrenade::Think(float dt, CStateManager& mgr) {
|
|
|
|
if (GetActive()) {
|
|
|
|
const zeus::CTransform& orientation = GetTransform().getRotation();
|
|
|
|
const zeus::CVector3f& translation = GetTranslation();
|
|
|
|
const zeus::CVector3f& scale = GetModelData()->GetScale();
|
2021-06-07 19:29:18 +00:00
|
|
|
auto UpdateElementGen = [orientation, translation, scale, dt](CElementGen& gen) {
|
2020-03-30 07:05:16 +00:00
|
|
|
gen.SetOrientation(orientation);
|
|
|
|
gen.SetGlobalTranslation(translation);
|
|
|
|
gen.SetGlobalScale(scale);
|
|
|
|
gen.Update(dt);
|
|
|
|
};
|
|
|
|
if (x2b4_24_exploded) {
|
|
|
|
Stop();
|
2020-12-18 11:05:22 +00:00
|
|
|
UpdateElementGen(*x2a0_elementGenCombat);
|
|
|
|
UpdateElementGen(*x2a4_elementGenXRay);
|
|
|
|
UpdateElementGen(*x2a8_elementGenThermal);
|
2020-03-30 07:05:16 +00:00
|
|
|
} else {
|
|
|
|
UpdateElementGen(*x2ac_elementGen4);
|
|
|
|
}
|
|
|
|
x29c_ += dt;
|
|
|
|
if (x29c_ > 0.3f) {
|
|
|
|
x2b4_25_ = true;
|
|
|
|
}
|
|
|
|
const zeus::CVector3f& playerDistance = mgr.GetPlayer().GetTranslation() +
|
|
|
|
zeus::CVector3f{0.f, 0.f, 0.5f * mgr.GetPlayer().GetEyeHeight()} -
|
|
|
|
translation;
|
|
|
|
if (playerDistance.magSquared() < x2b0_explodePlayerDistance * x2b0_explodePlayerDistance) {
|
|
|
|
Explode(mgr, kInvalidUniqueId);
|
|
|
|
}
|
|
|
|
}
|
2020-12-18 11:05:22 +00:00
|
|
|
if (x2a0_elementGenCombat->IsSystemDeletable() && x2a4_elementGenXRay->IsSystemDeletable() &&
|
|
|
|
x2a8_elementGenThermal->IsSystemDeletable()) {
|
2020-03-30 07:05:16 +00:00
|
|
|
mgr.FreeScriptObject(GetUniqueId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBouncyGrenade::Touch(CActor& act, CStateManager& mgr) { CActor::Touch(act, mgr); }
|
|
|
|
|
|
|
|
void CBouncyGrenade::Explode(CStateManager& mgr, TUniqueId uid) {
|
2020-03-30 23:31:14 +00:00
|
|
|
if (x2b4_24_exploded) {
|
2020-03-30 07:05:16 +00:00
|
|
|
return;
|
2020-03-30 23:31:14 +00:00
|
|
|
}
|
2020-03-30 07:05:16 +00:00
|
|
|
|
|
|
|
x2b4_24_exploded = true;
|
2020-03-31 00:40:38 +00:00
|
|
|
CSfxManager::AddEmitter(x258_data.GetExplodeSfx(), GetTranslation(), zeus::skUp, false, false, 0x7f,
|
2020-03-30 07:05:16 +00:00
|
|
|
GetAreaIdAlways());
|
2020-12-18 11:05:22 +00:00
|
|
|
x2a0_elementGenCombat->SetParticleEmission(true);
|
|
|
|
x2a4_elementGenXRay->SetParticleEmission(true);
|
|
|
|
x2a8_elementGenThermal->SetParticleEmission(true);
|
2020-03-30 07:05:16 +00:00
|
|
|
x2ac_elementGen4->SetParticleEmission(false);
|
|
|
|
|
2020-03-31 00:40:38 +00:00
|
|
|
const CDamageInfo& dInfo = x258_data.GetDamageInfo();
|
2020-03-30 07:05:16 +00:00
|
|
|
{
|
|
|
|
bool isParent = x298_parentId == uid;
|
|
|
|
if (TCastToConstPtr<CCollisionActor> actor = mgr.GetObjectById(uid)) {
|
|
|
|
isParent = x298_parentId == actor->GetOwnerId();
|
|
|
|
}
|
|
|
|
if (uid != kInvalidUniqueId && !isParent) {
|
|
|
|
mgr.ApplyDamage(GetUniqueId(), uid, GetUniqueId(), dInfo, CMaterialFilter::MakeInclude({EMaterialTypes::Solid}),
|
|
|
|
zeus::skZero3f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const float radius = dInfo.GetRadius();
|
|
|
|
if (radius > 1.f) {
|
|
|
|
const zeus::CVector3f& pos = GetTranslation();
|
|
|
|
const CMaterialFilter filter = CMaterialFilter::MakeInclude({EMaterialTypes::Player, EMaterialTypes::Character});
|
2021-06-07 00:07:45 +00:00
|
|
|
EntityList nearList;
|
2020-03-30 07:05:16 +00:00
|
|
|
mgr.BuildNearList(nearList, {pos - radius, pos + radius}, filter, nullptr);
|
|
|
|
|
|
|
|
for (const auto& id : nearList) {
|
|
|
|
bool isParent = x298_parentId == id;
|
|
|
|
if (TCastToConstPtr<CCollisionActor> cActor = mgr.GetObjectById(id)) {
|
|
|
|
isParent = x298_parentId == cActor->GetOwnerId();
|
|
|
|
}
|
2020-03-30 23:31:14 +00:00
|
|
|
if (isParent) {
|
2020-03-30 07:05:16 +00:00
|
|
|
continue;
|
2020-03-30 23:31:14 +00:00
|
|
|
}
|
2020-03-30 07:05:16 +00:00
|
|
|
|
2020-03-30 23:31:14 +00:00
|
|
|
const auto* actor = static_cast<const CActor*>(mgr.GetObjectById(id));
|
|
|
|
if (actor == nullptr) {
|
2020-03-30 07:05:16 +00:00
|
|
|
continue;
|
2020-03-30 23:31:14 +00:00
|
|
|
}
|
2020-03-30 07:05:16 +00:00
|
|
|
|
|
|
|
const float magnitude = (actor->GetTranslation() - GetTranslation()).magnitude();
|
2020-03-30 23:31:14 +00:00
|
|
|
if (radius <= magnitude) {
|
2020-03-30 07:05:16 +00:00
|
|
|
continue;
|
2020-03-30 23:31:14 +00:00
|
|
|
}
|
2020-03-30 07:05:16 +00:00
|
|
|
|
|
|
|
float scale = (radius - magnitude) / radius;
|
|
|
|
const CDamageInfo info{dInfo.GetWeaponMode(), scale * dInfo.GetDamage(), radius,
|
|
|
|
scale * dInfo.GetKnockBackPower()};
|
|
|
|
mgr.ApplyDamage(GetUniqueId(), id, GetUniqueId(), info, CMaterialFilter::MakeInclude({EMaterialTypes::Solid}),
|
|
|
|
zeus::skZero3f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce::MP1
|