2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CSnakeWeedSwarm.hpp"
|
|
|
|
|
2020-02-21 04:27:12 +00:00
|
|
|
#include "Runtime/CSimplePool.hpp"
|
2020-02-23 23:30:46 +00:00
|
|
|
#include "Runtime/CStateManager.hpp"
|
2020-02-21 04:27:12 +00:00
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
2020-02-23 23:30:46 +00:00
|
|
|
#include "Runtime/Graphics/CBooRenderer.hpp"
|
|
|
|
#include "Runtime/Graphics/CSkinnedModel.hpp"
|
|
|
|
#include "Runtime/Graphics/CVertexMorphEffect.hpp"
|
|
|
|
#include "Runtime/Weapon/CGameProjectile.hpp"
|
2020-02-21 04:27:12 +00:00
|
|
|
#include "Runtime/World/CActorParameters.hpp"
|
2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CAnimationParameters.hpp"
|
2020-02-23 23:30:46 +00:00
|
|
|
#include "Runtime/World/CPlayer.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-06-23 23:08:16 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2018-06-23 23:08:16 +00:00
|
|
|
|
2020-03-17 00:07:20 +00:00
|
|
|
static constexpr CMaterialFilter skMaterialFilter = CMaterialFilter::MakeInclude({EMaterialTypes::Solid});
|
2020-02-24 07:55:19 +00:00
|
|
|
|
2018-06-23 23:08:16 +00:00
|
|
|
CSnakeWeedSwarm::CSnakeWeedSwarm(TUniqueId uid, bool active, std::string_view name, const CEntityInfo& info,
|
2020-02-21 04:27:12 +00:00
|
|
|
const zeus::CVector3f& pos, const zeus::CVector3f& scale, const CAnimRes& animRes,
|
2020-03-17 00:07:20 +00:00
|
|
|
const CActorParameters& actParms, float spacing, float height, float f3,
|
|
|
|
float weaponDamageRadius, float maxPlayerDistance, float loweredTime,
|
|
|
|
float loweredTimeVariation, float maxZOffset, float speed, float speedVariation,
|
|
|
|
float f11, float scaleMin, float scaleMax, float distanceBelowGround,
|
|
|
|
const CDamageInfo& dInfo, float /*f15*/, u32 sfxId1, u32 sfxId2, u32 sfxId3,
|
|
|
|
CAssetId particleGenDesc1, u32 w5, CAssetId particleGenDesc2, float f16)
|
2018-12-08 05:30:43 +00:00
|
|
|
: CActor(uid, active, name, info, zeus::CTransform::Translate(pos), CModelData::CModelDataNull(),
|
2020-02-21 04:27:12 +00:00
|
|
|
CMaterialList(EMaterialTypes::Trigger, EMaterialTypes::NonSolidDamageable), actParms, kInvalidUniqueId)
|
|
|
|
, xe8_scale(scale)
|
2020-03-17 00:07:20 +00:00
|
|
|
, xf4_boidSpacing(spacing)
|
|
|
|
, xf8_height(height)
|
2020-02-21 04:27:12 +00:00
|
|
|
, xfc_(f3)
|
2020-03-17 00:07:20 +00:00
|
|
|
, x100_weaponDamageRadius(weaponDamageRadius)
|
|
|
|
, x104_maxPlayerDistance(maxPlayerDistance)
|
|
|
|
, x108_loweredTime(loweredTime)
|
|
|
|
, x10c_loweredTimeVariation(loweredTimeVariation)
|
|
|
|
, x110_maxZOffset(maxZOffset)
|
|
|
|
, x114_speed(speed)
|
|
|
|
, x118_speedVariation(speedVariation)
|
2020-02-21 04:27:12 +00:00
|
|
|
, x11c_(std::cos(zeus::degToRad(f11)))
|
2020-03-17 00:07:20 +00:00
|
|
|
, x120_scaleMin(scaleMin)
|
|
|
|
, x124_scaleMax(scaleMax)
|
|
|
|
, x128_distanceBelowGround(distanceBelowGround)
|
2020-02-24 07:55:19 +00:00
|
|
|
, x15c_damageInfo(dInfo)
|
|
|
|
, x1c8_boidPositions(std::make_unique<std::vector<zeus::CVector3f>>())
|
|
|
|
, x1cc_boidPlacement(std::make_unique<std::vector<EBoidPlacement>>())
|
2020-02-21 04:27:12 +00:00
|
|
|
, x1d0_sfx1(CSfxManager::TranslateSFXID(sfxId1))
|
|
|
|
, x1d2_sfx2(CSfxManager::TranslateSFXID(sfxId2))
|
|
|
|
, x1d4_sfx3(CSfxManager::TranslateSFXID(sfxId3))
|
|
|
|
, x1fc_(w5)
|
|
|
|
, x200_(f16) {
|
|
|
|
SetActorLights(actParms.GetLightParameters().MakeActorLights());
|
2020-02-23 23:30:46 +00:00
|
|
|
x1b0_modelData.emplace_back(std::make_unique<CModelData>(animRes));
|
|
|
|
x1b0_modelData.emplace_back(std::make_unique<CModelData>(animRes));
|
|
|
|
x1b0_modelData.emplace_back(std::make_unique<CModelData>(animRes));
|
|
|
|
x1b0_modelData.emplace_back(std::make_unique<CModelData>(animRes));
|
2020-02-21 04:27:12 +00:00
|
|
|
if (actParms.GetXRayAssets().first.IsValid()) {
|
2020-03-17 00:07:20 +00:00
|
|
|
for (const auto& modelData : x1b0_modelData) {
|
|
|
|
modelData->SetXRayModel(actParms.GetXRayAssets());
|
|
|
|
}
|
2020-02-23 23:30:46 +00:00
|
|
|
x140_25_modelAssetDirty = true;
|
2020-02-21 04:27:12 +00:00
|
|
|
}
|
|
|
|
if (actParms.GetThermalAssets().first.IsValid()) {
|
2020-03-17 00:07:20 +00:00
|
|
|
for (const auto& modelData : x1b0_modelData) {
|
|
|
|
modelData->SetInfraModel(actParms.GetThermalAssets());
|
|
|
|
}
|
2020-02-23 23:30:46 +00:00
|
|
|
x140_25_modelAssetDirty = true;
|
2020-02-21 04:27:12 +00:00
|
|
|
}
|
2020-03-17 00:07:20 +00:00
|
|
|
if (particleGenDesc1.IsValid()) {
|
|
|
|
x1dc_particleGenDesc = g_SimplePool->GetObj({FOURCC('PART'), particleGenDesc1});
|
2020-02-24 07:55:19 +00:00
|
|
|
x1ec_particleGen1 = std::make_unique<CElementGen>(x1dc_particleGenDesc);
|
2020-02-21 04:27:12 +00:00
|
|
|
}
|
2020-03-17 00:07:20 +00:00
|
|
|
if (particleGenDesc2.IsValid()) {
|
|
|
|
x1dc_particleGenDesc = g_SimplePool->GetObj({FOURCC('PART'), particleGenDesc2});
|
2020-02-24 07:55:19 +00:00
|
|
|
x1f4_particleGen2 = std::make_unique<CElementGen>(x1dc_particleGenDesc);
|
2020-02-21 04:27:12 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-23 23:08:16 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
void CSnakeWeedSwarm::Accept(metaforce::IVisitor& visitor) { visitor.Visit(this); }
|
2018-06-23 23:08:16 +00:00
|
|
|
|
2020-02-23 23:30:46 +00:00
|
|
|
void CSnakeWeedSwarm::AllocateSkinnedModels(CStateManager& mgr, CModelData::EWhichModel which) {
|
2020-03-17 00:07:20 +00:00
|
|
|
for (int i = 0; i < x1b0_modelData.size(); ++i) {
|
|
|
|
auto& modelData = *x1b0_modelData[i];
|
|
|
|
modelData.EnableLooping(true);
|
|
|
|
const float dt = modelData.GetAnimationData()->GetAnimTimeRemaining("Whole Body"sv) * (i * 0.25f);
|
|
|
|
modelData.AdvanceAnimation(dt, mgr, x4_areaId, true);
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
2020-02-24 07:55:19 +00:00
|
|
|
x1c4_which = which;
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSnakeWeedSwarm::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId id, CStateManager& mgr) {
|
|
|
|
CActor::AcceptScriptMsg(msg, id, mgr);
|
|
|
|
if (msg == EScriptObjectMessage::Deleted) {
|
2020-02-24 07:55:19 +00:00
|
|
|
if (x1d8_sfxHandle) {
|
|
|
|
CSfxManager::RemoveEmitter(x1d8_sfxHandle);
|
|
|
|
x1d8_sfxHandle.reset();
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
} else if (msg == EScriptObjectMessage::InitializedInArea) {
|
|
|
|
AllocateSkinnedModels(mgr, CModelData::EWhichModel::Normal);
|
|
|
|
SetCalculateLighting(true);
|
|
|
|
x90_actorLights->SetCastShadows(true);
|
|
|
|
}
|
|
|
|
}
|
2020-02-24 07:55:19 +00:00
|
|
|
|
2020-02-23 23:30:46 +00:00
|
|
|
void CSnakeWeedSwarm::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) {
|
2020-02-24 07:55:19 +00:00
|
|
|
if (!frustum.aabbFrustumTest(x144_touchBounds)) {
|
2020-03-01 08:05:16 +00:00
|
|
|
xe4_30_outOfFrustum = true;
|
2020-02-24 07:55:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-01 08:05:16 +00:00
|
|
|
xe4_30_outOfFrustum = false;
|
2020-03-01 07:52:17 +00:00
|
|
|
for (const auto& modelData : x1b0_modelData) {
|
|
|
|
modelData->GetAnimationData()->PreRender();
|
2020-02-24 07:55:19 +00:00
|
|
|
}
|
|
|
|
if (x90_actorLights && x140_24_hasGround) {
|
|
|
|
bool buildLights = false;
|
|
|
|
if (xe4_29_actorLightsDirty) {
|
|
|
|
buildLights = true;
|
|
|
|
xe4_29_actorLightsDirty = false;
|
|
|
|
} else if (x90_actorLights->GetIsDirty()) {
|
|
|
|
buildLights = true;
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
2020-02-24 07:55:19 +00:00
|
|
|
if (xe4_31_calculateLighting && x90_actorLights) {
|
|
|
|
auto visor = mgr.GetPlayerState()->GetActiveVisor(mgr);
|
|
|
|
if (visor == CPlayerState::EPlayerVisor::Thermal) {
|
|
|
|
x90_actorLights->BuildConstantAmbientLighting(zeus::skWhite);
|
|
|
|
} else if (buildLights && x4_areaId != kInvalidAreaId) {
|
|
|
|
CGameArea* area = mgr.GetWorld()->GetArea(x4_areaId);
|
|
|
|
if (area != nullptr) {
|
|
|
|
x90_actorLights->BuildAreaLightList(mgr, *area, x144_touchBounds);
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-24 07:55:19 +00:00
|
|
|
x90_actorLights->BuildDynamicLightList(mgr, x144_touchBounds);
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 11:54:02 +00:00
|
|
|
void CSnakeWeedSwarm::AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mgr) {
|
|
|
|
if (xe4_30_outOfFrustum) {
|
2020-02-24 07:55:19 +00:00
|
|
|
return;
|
2020-04-05 11:54:02 +00:00
|
|
|
}
|
2020-02-24 07:55:19 +00:00
|
|
|
|
2020-04-05 11:54:02 +00:00
|
|
|
if (x1ec_particleGen1) {
|
2020-02-24 07:55:19 +00:00
|
|
|
g_Renderer->AddParticleGen(*x1ec_particleGen1);
|
2020-04-05 11:54:02 +00:00
|
|
|
}
|
|
|
|
if (x1f4_particleGen2) {
|
2020-02-24 07:55:19 +00:00
|
|
|
g_Renderer->AddParticleGen(*x1f4_particleGen2);
|
2020-04-05 11:54:02 +00:00
|
|
|
}
|
2020-02-24 07:55:19 +00:00
|
|
|
|
|
|
|
if (x90_actorLights) {
|
2020-03-01 07:52:17 +00:00
|
|
|
for (const auto& modelData : x1b0_modelData) {
|
2020-02-24 07:55:19 +00:00
|
|
|
x90_actorLights->ActivateLights(*modelData->PickAnimatedModel(x1c4_which).GetModelInst());
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
2020-02-24 07:55:19 +00:00
|
|
|
} else {
|
2020-02-23 23:30:46 +00:00
|
|
|
CGraphics::DisableAllLights();
|
2020-03-17 00:07:20 +00:00
|
|
|
CGraphics::SetAmbientColor(zeus::skWhite);
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
2020-02-24 07:55:19 +00:00
|
|
|
|
|
|
|
u32 posesToBuild = -1;
|
2020-04-05 11:54:02 +00:00
|
|
|
for (u32 i = 0; i < x134_boids.size(); ++i) {
|
2020-02-25 19:09:49 +00:00
|
|
|
RenderBoid(i, x134_boids[i], posesToBuild);
|
2020-04-05 11:54:02 +00:00
|
|
|
}
|
2020-02-24 07:55:19 +00:00
|
|
|
CGraphics::DisableAllLights();
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSnakeWeedSwarm::Touch(CActor& actor, CStateManager& mgr) {
|
|
|
|
if (TCastToPtr<CGameProjectile> proj = actor) {
|
2020-03-17 00:07:20 +00:00
|
|
|
if (proj->GetDamageInfo().GetWeaponMode().GetType() != EWeaponType::AI) {
|
2020-02-24 07:55:19 +00:00
|
|
|
HandleRadiusDamage(x100_weaponDamageRadius, mgr, proj->GetTransform().origin);
|
2020-03-17 00:07:20 +00:00
|
|
|
}
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
if (TCastToPtr<CPlayer> player = actor) {
|
2020-03-01 07:52:17 +00:00
|
|
|
for (const auto& boid : x134_boids) {
|
2020-02-23 23:30:46 +00:00
|
|
|
float m = (boid.GetPosition() - player->GetTransform().origin).magnitude();
|
2020-03-17 00:07:20 +00:00
|
|
|
if (m < x104_maxPlayerDistance && boid.GetState() == EBoidState::Raised) {
|
2020-02-23 23:30:46 +00:00
|
|
|
mgr.SendScriptMsg(player, kInvalidUniqueId, EScriptObjectMessage::InSnakeWeed);
|
2020-02-24 07:55:19 +00:00
|
|
|
x140_26_playerTouching = true;
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 07:55:19 +00:00
|
|
|
void CSnakeWeedSwarm::HandleRadiusDamage(float radius, CStateManager& mgr, const zeus::CVector3f& pos) {
|
|
|
|
float radiusSquared = radius * radius;
|
2020-03-01 07:52:17 +00:00
|
|
|
for (auto& boid : x134_boids) {
|
2020-03-17 00:07:20 +00:00
|
|
|
const auto& boidPosition = boid.GetPosition();
|
2020-02-24 07:55:19 +00:00
|
|
|
if ((boidPosition - pos).magSquared() < radiusSquared &&
|
2020-03-01 07:52:17 +00:00
|
|
|
(boid.GetState() == EBoidState::Raised || boid.GetState() == EBoidState::Raising)) {
|
2020-03-17 00:07:20 +00:00
|
|
|
boid.SetState(EBoidState::Lowering);
|
|
|
|
boid.SetSpeed(x118_speedVariation * mgr.GetActiveRandom()->Float() + x114_speed);
|
2020-02-23 23:30:46 +00:00
|
|
|
CSfxManager::AddEmitter(x1d2_sfx2, boidPosition, zeus::skZero3f, true, false, 0x7f, x4_areaId);
|
|
|
|
EmitParticles1(boidPosition);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSnakeWeedSwarm::Think(float dt, CStateManager& mgr) {
|
|
|
|
CEntity::Think(dt, mgr);
|
2020-02-24 07:55:19 +00:00
|
|
|
if (!x30_24_active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (x1ec_particleGen1)
|
|
|
|
x1ec_particleGen1->Update(dt);
|
|
|
|
if (x1f4_particleGen2)
|
|
|
|
x1f4_particleGen2->Update(dt);
|
|
|
|
|
|
|
|
x204_particleTimer -= dt;
|
|
|
|
bool emitParticle = false;
|
|
|
|
if (x204_particleTimer < 0.f) {
|
|
|
|
x204_particleTimer = 0.f;
|
|
|
|
emitParticle = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!x140_24_hasGround)
|
|
|
|
FindGround(mgr);
|
|
|
|
if (x140_24_hasGround && x1c8_boidPositions && !x1c8_boidPositions->empty()) {
|
2020-02-25 19:09:49 +00:00
|
|
|
int n = (u64)(dt * x1cc_boidPlacement->size()) >> 0x20;
|
2020-02-24 07:55:19 +00:00
|
|
|
CreateBoids(mgr, n + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
CModelData::EWhichModel model = CModelData::GetRenderingModel(mgr);
|
|
|
|
if (x140_25_modelAssetDirty && x1c4_which != model)
|
|
|
|
AllocateSkinnedModels(mgr, model);
|
|
|
|
|
2020-03-01 07:52:17 +00:00
|
|
|
for (const auto& modelData : x1b0_modelData) {
|
|
|
|
modelData->GetAnimationData()->SetPlaybackRate(1.f);
|
|
|
|
modelData->AdvanceAnimation(dt, mgr, x4_areaId, true);
|
2020-02-24 07:55:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int raisedBoids = 0;
|
2020-03-01 07:52:17 +00:00
|
|
|
for (auto& boid : x134_boids) {
|
2020-02-24 07:55:19 +00:00
|
|
|
const zeus::CVector3f& pos = boid.GetPosition();
|
2020-03-01 08:05:16 +00:00
|
|
|
const EBoidState state = boid.GetState();
|
2020-02-24 07:55:19 +00:00
|
|
|
if (state == EBoidState::Raised) {
|
|
|
|
raisedBoids++;
|
|
|
|
if (x1f4_particleGen2 && emitParticle) {
|
|
|
|
EmitParticles2(pos);
|
|
|
|
}
|
2020-03-01 07:52:17 +00:00
|
|
|
} else if (state == EBoidState::Raising) {
|
2020-03-17 00:07:20 +00:00
|
|
|
boid.SetZOffset(boid.GetZOffset() - dt * boid.GetSpeed());
|
|
|
|
if (boid.GetZOffset() <= 0.f) {
|
|
|
|
boid.SetZOffset(0.f);
|
2020-02-24 07:55:19 +00:00
|
|
|
boid.SetState(EBoidState::Raised);
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
2020-03-17 00:07:20 +00:00
|
|
|
} else if (state == EBoidState::Lowered) {
|
|
|
|
boid.SetLoweredTimer(boid.GetLoweredTimer() - dt);
|
|
|
|
if (boid.GetLoweredTimer() <= 0.f) {
|
2020-03-01 07:52:17 +00:00
|
|
|
boid.SetState(EBoidState::Raising);
|
2020-02-24 07:55:19 +00:00
|
|
|
CSfxManager::AddEmitter(x1d4_sfx3, pos, zeus::skZero3f, true, false, 0x7f, x4_areaId);
|
|
|
|
EmitParticles1(pos);
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
2020-03-17 00:07:20 +00:00
|
|
|
} else if (state == EBoidState::Lowering) {
|
|
|
|
boid.SetZOffset(boid.GetZOffset() + dt * boid.GetSpeed());
|
|
|
|
const float max = x110_maxZOffset * boid.GetScale();
|
|
|
|
if (boid.GetZOffset() >= max) {
|
|
|
|
boid.SetZOffset(max);
|
|
|
|
boid.SetLoweredTimer(x10c_loweredTimeVariation * mgr.GetActiveRandom()->Float() + x108_loweredTime);
|
|
|
|
boid.SetState(EBoidState::Lowered);
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-24 07:55:19 +00:00
|
|
|
}
|
|
|
|
if (raisedBoids == 0) {
|
|
|
|
if (x1d8_sfxHandle) {
|
|
|
|
CSfxManager::RemoveEmitter(x1d8_sfxHandle);
|
|
|
|
x1d8_sfxHandle.reset();
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
2020-02-24 07:55:19 +00:00
|
|
|
} else if (!x1d8_sfxHandle) {
|
|
|
|
x1d8_sfxHandle =
|
|
|
|
CSfxManager::AddEmitter(x1d0_sfx1, GetTransform().origin, zeus::skZero3f, true, true, 0x7f, x4_areaId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x140_26_playerTouching) {
|
2020-03-17 00:07:20 +00:00
|
|
|
mgr.ApplyDamage(x8_uid, mgr.GetPlayer().GetUniqueId(), x8_uid, {x15c_damageInfo, dt}, skMaterialFilter,
|
2020-02-24 07:55:19 +00:00
|
|
|
zeus::skZero3f);
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
2020-02-24 07:55:19 +00:00
|
|
|
x140_26_playerTouching = false;
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 05:02:14 +00:00
|
|
|
zeus::CAABox CSnakeWeedSwarm::GetBoidBox() const {
|
|
|
|
const auto scale = xe8_scale * 0.75f;
|
2020-03-17 00:07:20 +00:00
|
|
|
return {GetTransform().origin - scale, GetTransform().origin + scale};
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
|
2020-02-24 07:55:19 +00:00
|
|
|
void CSnakeWeedSwarm::FindGround(const CStateManager& mgr) {
|
2020-03-26 05:02:14 +00:00
|
|
|
const auto box = GetBoidBox();
|
|
|
|
const auto result =
|
2020-03-17 00:07:20 +00:00
|
|
|
mgr.RayStaticIntersection(box.center(), zeus::skDown, box.max.z() - box.min.z(), skMaterialFilter);
|
2020-02-23 23:30:46 +00:00
|
|
|
if (result.IsValid()) {
|
2020-02-24 07:55:19 +00:00
|
|
|
int ct = GetNumBoidsX() * GetNumBoidsY();
|
2020-02-23 23:30:46 +00:00
|
|
|
x134_boids.reserve(ct);
|
2020-02-24 07:55:19 +00:00
|
|
|
x1c8_boidPositions->reserve(ct);
|
|
|
|
x1c8_boidPositions->push_back(result.GetPoint());
|
|
|
|
x1cc_boidPlacement->resize(ct, EBoidPlacement::None);
|
|
|
|
x140_24_hasGround = true;
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 05:02:14 +00:00
|
|
|
int CSnakeWeedSwarm::GetNumBoidsY() const {
|
|
|
|
const auto box = GetBoidBox();
|
2020-03-17 00:07:20 +00:00
|
|
|
return static_cast<int>((box.max.y() - box.min.y()) / xf4_boidSpacing) + 1;
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 05:02:14 +00:00
|
|
|
int CSnakeWeedSwarm::GetNumBoidsX() const {
|
|
|
|
const auto box = GetBoidBox();
|
2020-03-17 00:07:20 +00:00
|
|
|
return static_cast<int>((box.max.x() - box.min.x()) / xf4_boidSpacing) + 1;
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
|
2020-02-24 07:55:19 +00:00
|
|
|
void CSnakeWeedSwarm::CreateBoids(CStateManager& mgr, int num) {
|
2020-03-17 00:07:20 +00:00
|
|
|
auto width = GetNumBoidsX();
|
2020-02-24 07:55:19 +00:00
|
|
|
for (int i = 0; i < num; ++i) {
|
|
|
|
if (x1c8_boidPositions->empty())
|
2020-02-23 23:30:46 +00:00
|
|
|
break;
|
2020-03-17 00:07:20 +00:00
|
|
|
const auto pos = x1c8_boidPositions->back();
|
2020-02-24 07:55:19 +00:00
|
|
|
x1c8_boidPositions->pop_back();
|
2020-03-17 00:07:20 +00:00
|
|
|
const auto& idx = GetBoidIndex(pos);
|
2020-02-24 07:55:19 +00:00
|
|
|
if (CreateBoid(pos, mgr)) {
|
|
|
|
x1cc_boidPlacement->at(idx.x + width * idx.y) = EBoidPlacement::Placed;
|
2020-03-17 00:07:20 +00:00
|
|
|
AddBoidPosition({pos.x(), pos.y() - xf4_boidSpacing, pos.z()});
|
|
|
|
AddBoidPosition({pos.x(), xf4_boidSpacing + pos.y(), pos.z()});
|
|
|
|
AddBoidPosition({pos.x() - xf4_boidSpacing, pos.y(), pos.z()});
|
|
|
|
AddBoidPosition({xf4_boidSpacing + pos.x(), pos.y(), pos.z()});
|
2020-02-23 23:30:46 +00:00
|
|
|
} else {
|
2020-02-24 07:55:19 +00:00
|
|
|
x1cc_boidPlacement->at(idx.x + width * idx.y) = EBoidPlacement::Invalid;
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-24 07:55:19 +00:00
|
|
|
CalculateTouchBounds();
|
|
|
|
if (x1c8_boidPositions->empty()) {
|
|
|
|
x1c8_boidPositions = nullptr;
|
|
|
|
x1cc_boidPlacement = nullptr;
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 05:02:14 +00:00
|
|
|
zeus::CVector2i CSnakeWeedSwarm::GetBoidIndex(const zeus::CVector3f& pos) const {
|
|
|
|
const auto box = GetBoidBox();
|
2020-03-17 00:07:20 +00:00
|
|
|
return {static_cast<int>((pos.x() - box.min.x()) / xf4_boidSpacing),
|
|
|
|
static_cast<int>((pos.y() - box.min.y()) / xf4_boidSpacing)};
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CSnakeWeedSwarm::CreateBoid(const zeus::CVector3f& vec, CStateManager& mgr) {
|
2020-03-26 05:02:14 +00:00
|
|
|
const auto pos = vec + zeus::CVector3f(GetBoidOffsetX(vec), GetBoidOffsetY(vec), xf8_height);
|
|
|
|
const auto result = mgr.RayStaticIntersection(pos, zeus::skDown, 2.f * xf8_height, skMaterialFilter);
|
2020-02-24 07:55:19 +00:00
|
|
|
if (result.IsValid() && result.GetPlane().normal().dot(zeus::skUp) > x11c_) {
|
2020-03-26 05:02:14 +00:00
|
|
|
const auto boidPosition = result.GetPoint() - zeus::CVector3f(0.f, 0.f, x128_distanceBelowGround);
|
2020-03-26 05:00:26 +00:00
|
|
|
x134_boids.emplace_back(boidPosition, x110_maxZOffset, x114_speed + x118_speedVariation,
|
|
|
|
(x124_scaleMax - x120_scaleMin) * mgr.GetActiveRandom()->Float() + x120_scaleMin);
|
2020-02-23 23:30:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-02-24 07:55:19 +00:00
|
|
|
return false;
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 05:02:14 +00:00
|
|
|
float CSnakeWeedSwarm::GetBoidOffsetY(const zeus::CVector3f& pos) const {
|
|
|
|
const float f = 2.4729404f * pos.y() + 0.3478602f * pos.x() * pos.x();
|
2020-02-25 19:09:49 +00:00
|
|
|
return xfc_ * (2.f * std::abs(f - std::trunc(f)) - 1.f);
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 05:02:14 +00:00
|
|
|
float CSnakeWeedSwarm::GetBoidOffsetX(const zeus::CVector3f& pos) const {
|
|
|
|
const float f = 8.21395f * pos.x() + 0.112869f * pos.y() * pos.y();
|
2020-02-25 19:09:49 +00:00
|
|
|
return xfc_ * (2.f * std::abs(f - std::trunc(f)) - 1.f);
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
|
2020-02-24 07:55:19 +00:00
|
|
|
void CSnakeWeedSwarm::AddBoidPosition(const zeus::CVector3f& pos) {
|
|
|
|
int x = GetNumBoidsX();
|
|
|
|
int y = GetNumBoidsY();
|
2020-03-17 00:07:20 +00:00
|
|
|
const auto& v = GetBoidIndex(pos);
|
2020-02-23 23:30:46 +00:00
|
|
|
if (-1 < v.x && v.x < x && -1 < v.y && v.y < y) {
|
2020-02-24 07:55:19 +00:00
|
|
|
int idx = v.x + x * v.y;
|
2020-03-17 00:07:20 +00:00
|
|
|
auto& placement = x1cc_boidPlacement->at(idx);
|
|
|
|
if (placement == EBoidPlacement::None) {
|
|
|
|
placement = EBoidPlacement::Ready;
|
2020-02-24 07:55:19 +00:00
|
|
|
x1c8_boidPositions->push_back(pos);
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 07:55:19 +00:00
|
|
|
void CSnakeWeedSwarm::CalculateTouchBounds() {
|
2020-02-23 23:30:46 +00:00
|
|
|
if (x134_boids.empty()) {
|
2020-03-17 00:07:20 +00:00
|
|
|
x144_touchBounds = {x34_transform.origin, x34_transform.origin};
|
2020-02-23 23:30:46 +00:00
|
|
|
} else {
|
2020-02-24 07:55:19 +00:00
|
|
|
x144_touchBounds = zeus::skInvertedBox;
|
2020-03-01 07:52:17 +00:00
|
|
|
for (const auto& boid : x134_boids) {
|
2020-02-24 07:55:19 +00:00
|
|
|
x144_touchBounds.accumulateBounds(boid.GetPosition() - x100_weaponDamageRadius);
|
|
|
|
x144_touchBounds.accumulateBounds(boid.GetPosition() + x100_weaponDamageRadius);
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
xe4_27_notInSortedLists = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSnakeWeedSwarm::EmitParticles1(const zeus::CVector3f& pos) {
|
2020-02-24 07:55:19 +00:00
|
|
|
if (!x1ec_particleGen1)
|
|
|
|
return;
|
|
|
|
|
2020-03-17 00:07:20 +00:00
|
|
|
auto& particleGen = *x1ec_particleGen1;
|
|
|
|
particleGen.SetParticleEmission(true);
|
|
|
|
particleGen.SetTranslation(pos);
|
|
|
|
particleGen.ForceParticleCreation(x1fc_);
|
|
|
|
particleGen.SetParticleEmission(false);
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSnakeWeedSwarm::EmitParticles2(const zeus::CVector3f& pos) {
|
2020-02-24 07:55:19 +00:00
|
|
|
if (!x1f4_particleGen2)
|
|
|
|
return;
|
|
|
|
|
2020-03-17 00:07:20 +00:00
|
|
|
auto& particleGen = *x1f4_particleGen2;
|
|
|
|
particleGen.SetParticleEmission(true);
|
|
|
|
particleGen.SetTranslation(pos);
|
|
|
|
particleGen.ForceParticleCreation(1);
|
|
|
|
particleGen.SetParticleEmission(false);
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
|
2020-02-25 19:09:49 +00:00
|
|
|
void CSnakeWeedSwarm::RenderBoid(u32 idx, const CBoid& boid, u32& posesToBuild) const {
|
|
|
|
const u32 modelIdx = idx & 3;
|
2020-03-17 00:07:20 +00:00
|
|
|
auto& modelData = *x1b0_modelData[modelIdx];
|
|
|
|
auto& model = modelData.PickAnimatedModel(x1c4_which);
|
|
|
|
auto& animData = *modelData.GetAnimationData();
|
2020-04-11 20:53:59 +00:00
|
|
|
constexpr CModelFlags useFlags(0, 0, 3, zeus::skWhite);
|
2020-02-25 19:09:49 +00:00
|
|
|
if (posesToBuild & 1 << modelIdx) {
|
2020-02-24 07:55:19 +00:00
|
|
|
posesToBuild &= ~(1 << modelIdx);
|
2020-03-17 00:07:20 +00:00
|
|
|
animData.BuildPose();
|
|
|
|
model.Calculate(animData.GetPose(), useFlags, std::nullopt, nullptr);
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
2020-03-17 00:07:20 +00:00
|
|
|
CGraphics::SetModelMatrix(
|
|
|
|
zeus::CTransform::Translate(boid.GetPosition() - zeus::CVector3f(0.f, 0.f, boid.GetZOffset())) *
|
|
|
|
zeus::CTransform::Scale(boid.GetScale()));
|
|
|
|
animData.Render(model, useFlags, std::nullopt, nullptr);
|
2020-02-23 23:30:46 +00:00
|
|
|
}
|
|
|
|
|
2020-02-24 05:43:20 +00:00
|
|
|
void CSnakeWeedSwarm::ApplyRadiusDamage(const zeus::CVector3f& pos, const CDamageInfo& info, CStateManager& mgr) {
|
2020-03-17 00:07:20 +00:00
|
|
|
auto type = info.GetWeaponMode().GetType();
|
2020-02-24 07:55:19 +00:00
|
|
|
if (type == EWeaponType::Bomb || type == EWeaponType::PowerBomb)
|
|
|
|
HandleRadiusDamage(info.GetRadius(), mgr, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<zeus::CAABox> CSnakeWeedSwarm::GetTouchBounds() const {
|
|
|
|
if (x140_24_hasGround)
|
|
|
|
return x144_touchBounds;
|
2020-02-25 19:09:49 +00:00
|
|
|
return std::nullopt;
|
2020-02-24 05:43:20 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|