Additional work on CMorphBall

This commit is contained in:
Jack Andersen 2017-09-11 19:51:17 -10:00
parent c2f3e02702
commit c0d5cee8b1
10 changed files with 380 additions and 137 deletions

View File

@ -10,11 +10,13 @@ struct ITweakBall : ITweak
virtual float GetMaxBallTranslationAcceleration(int s) const=0; virtual float GetMaxBallTranslationAcceleration(int s) const=0;
virtual float GetBallTranslationFriction(int s) const=0; virtual float GetBallTranslationFriction(int s) const=0;
virtual float GetBallTranslationMaxSpeed(int s) const=0; virtual float GetBallTranslationMaxSpeed(int s) const=0;
virtual float GetSpiderBallRollSpeed() const=0; virtual float GetBallGravity() const=0;
virtual float GetBallWaterGravity() const=0;
virtual float GetBallCameraControlDistance() const=0; virtual float GetBallCameraControlDistance() const=0;
virtual float GetLeftStickDivisor() const=0; virtual float GetLeftStickDivisor() const=0;
virtual float GetRightStickDivisor() const=0; virtual float GetRightStickDivisor() const=0;
virtual float GetBallTouchRadius() const=0; virtual float GetBallTouchRadius() const=0;
virtual float GetBoostBallMinRelativeSpeedForDamage() const=0;
}; };
} }

View File

@ -79,10 +79,10 @@ void CTweakBall::read(athena::io::IStreamReader& __dna_reader)
xc4_[6] = __dna_reader.readFloatBig(); xc4_[6] = __dna_reader.readFloatBig();
/* xc4_[7] */ /* xc4_[7] */
xc4_[7] = __dna_reader.readFloatBig(); xc4_[7] = __dna_reader.readFloatBig();
/* xe4_spiderBallRollSpeed */ /* xe4_ballGravity */
xe4_spiderBallRollSpeed = __dna_reader.readFloatBig(); xe4_ballGravity = __dna_reader.readFloatBig();
/* xe8_ */ /* xe8_ballWaterGravity */
xe8_ = __dna_reader.readFloatBig(); xe8_ballWaterGravity = __dna_reader.readFloatBig();
/* x14c_ */ /* x14c_ */
x14c_ = __dna_reader.readFloatBig(); x14c_ = __dna_reader.readFloatBig();
/* x150_ */ /* x150_ */
@ -210,7 +210,7 @@ void CTweakBall::read(athena::io::IStreamReader& __dna_reader)
/* x218_ */ /* x218_ */
x218_ = __dna_reader.readFloatBig(); x218_ = __dna_reader.readFloatBig();
/* x21c_ */ /* x21c_ */
x21c_ = __dna_reader.readFloatBig(); x21c_boostBallMinRelativeSpeedForDamage = __dna_reader.readFloatBig();
/* x220_ */ /* x220_ */
x220_ = __dna_reader.readFloatBig(); x220_ = __dna_reader.readFloatBig();
/* x224_ */ /* x224_ */
@ -299,10 +299,10 @@ void CTweakBall::write(athena::io::IStreamWriter& __dna_writer) const
__dna_writer.writeFloatBig(xc4_[6]); __dna_writer.writeFloatBig(xc4_[6]);
/* xc4_[7] */ /* xc4_[7] */
__dna_writer.writeFloatBig(xc4_[7]); __dna_writer.writeFloatBig(xc4_[7]);
/* xe4_spiderBallRollSpeed */ /* xe4_ballGravity */
__dna_writer.writeFloatBig(xe4_spiderBallRollSpeed); __dna_writer.writeFloatBig(xe4_ballGravity);
/* xe8_ */ /* xe8_ballWaterGravity */
__dna_writer.writeFloatBig(xe8_); __dna_writer.writeFloatBig(xe8_ballWaterGravity);
/* x14c_ */ /* x14c_ */
__dna_writer.writeFloatBig(x14c_); __dna_writer.writeFloatBig(x14c_);
/* x150_ */ /* x150_ */
@ -430,7 +430,7 @@ void CTweakBall::write(athena::io::IStreamWriter& __dna_writer) const
/* x218_ */ /* x218_ */
__dna_writer.writeFloatBig(x218_); __dna_writer.writeFloatBig(x218_);
/* x21c_ */ /* x21c_ */
__dna_writer.writeFloatBig(x21c_); __dna_writer.writeFloatBig(x21c_boostBallMinRelativeSpeedForDamage);
/* x220_ */ /* x220_ */
__dna_writer.writeFloatBig(x220_); __dna_writer.writeFloatBig(x220_);
/* x224_ */ /* x224_ */
@ -539,10 +539,10 @@ void CTweakBall::read(athena::io::YAMLDocReader& __dna_docin)
/* xc4_[7] */ /* xc4_[7] */
xc4_[7] = __dna_docin.readFloat("xc4_"); xc4_[7] = __dna_docin.readFloat("xc4_");
} }
/* xe4_spiderBallRollSpeed */ /* xe4_ballGravity */
xe4_spiderBallRollSpeed = __dna_docin.readFloat("xe4_spiderBallRollSpeed"); xe4_ballGravity = __dna_docin.readFloat("xe4_ballGravity");
/* xe8_ */ /* xe8_ballWaterGravity */
xe8_ = __dna_docin.readFloat("xe8_"); xe8_ballWaterGravity = __dna_docin.readFloat("xe8_ballWaterGravity");
/* x14c_ */ /* x14c_ */
x14c_ = __dna_docin.readFloat("x14c_"); x14c_ = __dna_docin.readFloat("x14c_");
/* x150_ */ /* x150_ */
@ -670,7 +670,7 @@ void CTweakBall::read(athena::io::YAMLDocReader& __dna_docin)
/* x218_ */ /* x218_ */
x218_ = __dna_docin.readFloat("x218_"); x218_ = __dna_docin.readFloat("x218_");
/* x21c_ */ /* x21c_ */
x21c_ = __dna_docin.readFloat("x21c_"); x21c_boostBallMinRelativeSpeedForDamage = __dna_docin.readFloat("x21c_");
/* x220_ */ /* x220_ */
x220_ = __dna_docin.readFloat("x220_"); x220_ = __dna_docin.readFloat("x220_");
/* x224_ */ /* x224_ */
@ -775,10 +775,10 @@ void CTweakBall::write(athena::io::YAMLDocWriter& __dna_docout) const
/* xc4_[7] */ /* xc4_[7] */
__dna_docout.writeFloat("xc4_", xc4_[7]); __dna_docout.writeFloat("xc4_", xc4_[7]);
} }
/* xe4_spiderBallRollSpeed */ /* xe4_ballGravity */
__dna_docout.writeFloat("xe4_spiderBallRollSpeed", xe4_spiderBallRollSpeed); __dna_docout.writeFloat("xe4_ballGravity", xe4_ballGravity);
/* xe8_ */ /* xe8_ballWaterGravity */
__dna_docout.writeFloat("xe8_", xe8_); __dna_docout.writeFloat("xe8_ballWaterGravity", xe8_ballWaterGravity);
/* x14c_ */ /* x14c_ */
__dna_docout.writeFloat("x14c_", x14c_); __dna_docout.writeFloat("x14c_", x14c_);
/* x150_ */ /* x150_ */
@ -906,7 +906,7 @@ void CTweakBall::write(athena::io::YAMLDocWriter& __dna_docout) const
/* x218_ */ /* x218_ */
__dna_docout.writeFloat("x218_", x218_); __dna_docout.writeFloat("x218_", x218_);
/* x21c_ */ /* x21c_ */
__dna_docout.writeFloat("x21c_", x21c_); __dna_docout.writeFloat("x21c_", x21c_boostBallMinRelativeSpeedForDamage);
/* x220_ */ /* x220_ */
__dna_docout.writeFloat("x220_", x220_); __dna_docout.writeFloat("x220_", x220_);
/* x224_ */ /* x224_ */

View File

@ -38,8 +38,8 @@ struct CTweakBall final : public ITweakBall
Value<float> xbc_; Value<float> xbc_;
Value<float> xc0_; Value<float> xc0_;
Value<float> xc4_[8]; Value<float> xc4_[8];
Value<float> xe4_spiderBallRollSpeed; Value<float> xe4_ballGravity;
Value<float> xe8_; Value<float> xe8_ballWaterGravity;
float xec_ = 10000.f; float xec_ = 10000.f;
float xf0_ = 1000.f; float xf0_ = 1000.f;
float xf4_ = 40000.f; float xf4_ = 40000.f;
@ -110,7 +110,7 @@ struct CTweakBall final : public ITweakBall
float x208_; float x208_;
Value<float> x20c_; Value<float> x20c_;
Value<float> x218_; Value<float> x218_;
Value<float> x21c_; Value<float> x21c_boostBallMinRelativeSpeedForDamage;
Value<float> x220_; Value<float> x220_;
Value<float> x224_; Value<float> x224_;
Value<float> x210_; Value<float> x210_;
@ -140,11 +140,13 @@ struct CTweakBall final : public ITweakBall
float GetMaxBallTranslationAcceleration(int s) const { return x4_maxTranslationAcceleration[s]; } float GetMaxBallTranslationAcceleration(int s) const { return x4_maxTranslationAcceleration[s]; }
float GetBallTranslationFriction(int s) const { return x24_translationFriction[s]; } float GetBallTranslationFriction(int s) const { return x24_translationFriction[s]; }
float GetBallTranslationMaxSpeed(int s) const { return x44_translationMaxSpeed[s]; } float GetBallTranslationMaxSpeed(int s) const { return x44_translationMaxSpeed[s]; }
float GetSpiderBallRollSpeed() const { return xe4_spiderBallRollSpeed; } float GetBallGravity() const { return xe4_ballGravity; }
float GetBallWaterGravity() const { return xe8_ballWaterGravity; }
float GetBallCameraControlDistance() const { return x1d0_ballCameraControlDistance; } float GetBallCameraControlDistance() const { return x1d0_ballCameraControlDistance; }
float GetLeftStickDivisor() const { return x1e4_leftStickDivisor; } float GetLeftStickDivisor() const { return x1e4_leftStickDivisor; }
float GetRightStickDivisor() const { return x1e8_rightStickDivisor; } float GetRightStickDivisor() const { return x1e8_rightStickDivisor; }
float GetBallTouchRadius() const { return x204_ballTouchRadius; } float GetBallTouchRadius() const { return x204_ballTouchRadius; }
float GetBoostBallMinRelativeSpeedForDamage() const { return x21c_boostBallMinRelativeSpeedForDamage; }
}; };
} }
} }

View File

@ -15,7 +15,7 @@ public:
void GetAverageLeftNormal() const; void GetAverageLeftNormal() const;
void GetAveragePoint() const; void GetAveragePoint() const;
void GetUnionOfAllLeftMaterials() const; void GetUnionOfAllLeftMaterials() const;
s32 GetCount() const { return x0_list.size(); } size_t GetCount() const { return x0_list.size(); }
void Swap(s32); void Swap(s32);
void Add(const CCollisionInfo& info, bool swap) void Add(const CCollisionInfo& info, bool swap)

View File

@ -5,6 +5,7 @@
#include "zeus/CEulerAngles.hpp" #include "zeus/CEulerAngles.hpp"
#include "Collision/CollisionUtil.hpp" #include "Collision/CollisionUtil.hpp"
#include "Graphics/CBooRenderer.hpp" #include "Graphics/CBooRenderer.hpp"
#include "World/CMorphBall.hpp"
namespace urde namespace urde
{ {
@ -127,19 +128,6 @@ static const u8 BallGlowColors[9][3] =
{0xff, 0xff, 0xff}, {0xff, 0xff, 0xff},
}; };
static const u8 BallTransFlashColors[9][3] =
{
{0xc2, 0x7e, 0x10},
{0x66, 0xc4, 0xff},
{0x60, 0xff, 0x90},
{0x33, 0x33, 0xff},
{0xff, 0x20, 0x20},
{0x0, 0x9d, 0xb6},
{0xd3, 0xf1, 0x0},
{0xa6, 0x86, 0xd8},
{0xfb, 0x98, 0x21}
};
static const u8 BallAuxGlowColors[9][3] = static const u8 BallAuxGlowColors[9][3] =
{ {
{0xc2, 0x7e, 0x10}, {0xc2, 0x7e, 0x10},
@ -609,7 +597,7 @@ void CSamusDoll::Draw(const CStateManager& mgr, float alpha)
{ {
if (x22c_ballInnerGlowGen->GetNumActiveChildParticles() > 0) if (x22c_ballInnerGlowGen->GetNumActiveChildParticles() > 0)
{ {
const u8* c = BallTransFlashColors[x1e8_ballGlowColorIdx]; const u8* c = CMorphBall::BallTransFlashColors[x1e8_ballGlowColorIdx];
zeus::CColor color = {c[0] / 255.f, c[1] / 255.f, c[2] / 255.f, alpha}; zeus::CColor color = {c[0] / 255.f, c[1] / 255.f, c[2] / 255.f, alpha};
x22c_ballInnerGlowGen->GetActiveChildParticle(0).SetModulationColor(color); x22c_ballInnerGlowGen->GetActiveChildParticle(0).SetModulationColor(color);
@ -648,7 +636,7 @@ void CSamusDoll::Draw(const CStateManager& mgr, float alpha)
if (x238_ballTransitionFlashGen) if (x238_ballTransitionFlashGen)
{ {
const u8* c = BallTransFlashColors[x1e8_ballGlowColorIdx]; const u8* c = CMorphBall::BallTransFlashColors[x1e8_ballGlowColorIdx];
zeus::CColor color = {c[0] / 255.f, c[1] / 255.f, c[2] / 255.f, 1.f}; zeus::CColor color = {c[0] / 255.f, c[1] / 255.f, c[2] / 255.f, 1.f};
x238_ballTransitionFlashGen->SetModulationColor(color); x238_ballTransitionFlashGen->SetModulationColor(color);
x238_ballTransitionFlashGen->Render(); x238_ballTransitionFlashGen->Render();

View File

@ -128,7 +128,7 @@ class TReservedAverage : rstl::reserved_vector<T, N>
{ {
public: public:
TReservedAverage() = default; TReservedAverage() = default;
TReservedAverage(const T& t) { resize(N, t); } TReservedAverage(const T& t) { rstl::reserved_vector<T, N>::resize(N, t); }
void AddValue(const T& t) void AddValue(const T& t)
{ {

View File

@ -187,6 +187,7 @@ public:
bool GetIsTargetable() const { return xe7_31_targetable; } bool GetIsTargetable() const { return xe7_31_targetable; }
void SetDrawFlags(const CModelFlags& flags) { xb4_drawFlags = flags; } void SetDrawFlags(const CModelFlags& flags) { xb4_drawFlags = flags; }
void SetModelData(std::unique_ptr<CModelData>&& mData); void SetModelData(std::unique_ptr<CModelData>&& mData);
u8 GetFluidCounter() const { return xe6_24_fluidCounter; }
}; };
} }

View File

@ -4,12 +4,28 @@
#include "CPlayer.hpp" #include "CPlayer.hpp"
#include "CSimplePool.hpp" #include "CSimplePool.hpp"
#include "CGameLight.hpp" #include "CGameLight.hpp"
#include "World/CWorld.hpp"
#include "World/CScriptAreaAttributes.hpp"
#include "TCastTo.hpp"
namespace urde namespace urde
{ {
static float kSpiderBallCollisionRadius; static float kSpiderBallCollisionRadius;
const u8 CMorphBall::BallTransFlashColors[9][3] =
{
{0xc2, 0x7e, 0x10},
{0x66, 0xc4, 0xff},
{0x60, 0xff, 0x90},
{0x33, 0x33, 0xff},
{0xff, 0x20, 0x20},
{0x0, 0x9d, 0xb6},
{0xd3, 0xf1, 0x0},
{0xa6, 0x86, 0xd8},
{0xfb, 0x98, 0x21}
};
CMorphBall::CMorphBall(CPlayer& player, float radius) CMorphBall::CMorphBall(CPlayer& player, float radius)
: x0_player(player), xc_radius(radius), : x0_player(player), xc_radius(radius),
x38_collisionSphere({{0.f, 0.f, radius}, radius}, x38_collisionSphere({{0.f, 0.f, radius}, radius},
@ -41,15 +57,11 @@ CMorphBall::CMorphBall(CPlayer& player, float radius)
x1c14_worldShadow = std::make_unique<CWorldShadow>(16, 16, false); x1c14_worldShadow = std::make_unique<CWorldShadow>(16, 16, false);
x1c18_actorLights = std::make_unique<CActorLights>(8, zeus::CVector3f::skZero, 4, 4, false, false, false, 0.1f); x1c18_actorLights = std::make_unique<CActorLights>(8, zeus::CVector3f::skZero, 4, 4, false, false, false, 0.1f);
x1c1c_rainSplashGen = std::make_unique<CRainSplashGenerator>(x58_ballModel->GetScale(), 40, 2, 0.15f, 0.5f); x1c1c_rainSplashGen = std::make_unique<CRainSplashGenerator>(x58_ballModel->GetScale(), 40, 2, 0.15f, 0.5f);
x1c3c_quats.resize(5);
x1c90_vecs.resize(5);
x1cd0_.resize(15);
x1d10_.resize(15);
x1de4_24 = false; x1de4_24 = false;
x1de4_25 = true; x1de4_25 = true;
x1df8_24 = false; x1df8_24_inHalfPipeMode = false;
x1df8_25 = false; x1df8_25_inHalfPipeModeInAir = false;
x1df8_26 = false; x1df8_26_touchedHalfPipeRecently = false;
x1df8_27 = false; x1df8_27 = false;
x19d4_spiderBallMagnetEffectGen->SetParticleEmission(false); x19d4_spiderBallMagnetEffectGen->SetParticleEmission(false);
@ -174,8 +186,6 @@ void CMorphBall::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CSt
} }
} }
zeus::CVector3f CMorphBall::GetBallContactSurfaceNormal() const { return {}; }
void CMorphBall::DrawBallShadow(const CStateManager& mgr) void CMorphBall::DrawBallShadow(const CStateManager& mgr)
{ {
if (!x1e50_shadow) if (!x1e50_shadow)
@ -284,7 +294,7 @@ void CMorphBall::UpdateMorphBallSounds(float dt)
{ {
float vel = velocity.magnitude(); float vel = velocity.magnitude();
if (x187c_spiderBallState == ESpiderBallState::Active) if (x187c_spiderBallState == ESpiderBallState::Active)
vel += g_tweakBall->GetSpiderBallRollSpeed() * dt * 4.f; vel += g_tweakBall->GetBallGravity() * dt * 4.f;
if (vel > 0.8f) if (vel > 0.8f)
{ {
if (!x1e2c_rollSfxHandle) if (!x1e2c_rollSfxHandle)
@ -347,6 +357,11 @@ void CMorphBall::ForwardInput(const CFinalInput&) const
} }
void CMorphBall::BallTurnInput(const CFinalInput&) const
{
}
void CMorphBall::ComputeBallMovement(const CFinalInput&, CStateManager&, float) void CMorphBall::ComputeBallMovement(const CFinalInput&, CStateManager&, float)
{ {
@ -446,11 +461,6 @@ void CMorphBall::CalculateBallContactInfo(zeus::CVector3f&, zeus::CVector3f&) co
} }
void CMorphBall::BallTurnInput(const CFinalInput&) const
{
}
void CMorphBall::UpdateBallDynamics(CStateManager&, float) void CMorphBall::UpdateBallDynamics(CStateManager&, float)
{ {
@ -615,7 +625,24 @@ void CMorphBall::UpdateMorphBallTransitionFlash(float)
void CMorphBall::RenderMorphBallTransitionFlash(const CStateManager&) const void CMorphBall::RenderMorphBallTransitionFlash(const CStateManager&) const
{ {
if (x19dc_morphBallTransitionFlashGen)
{
const u8* c = BallTransFlashColors[x8_];
zeus::CColor color = {c[0] / 255.f, c[1] / 255.f, c[2] / 255.f, 1.f};
x19dc_morphBallTransitionFlashGen->SetModulationColor(color);
x19dc_morphBallTransitionFlashGen->Render();
}
}
void CMorphBall::UpdateIceBreakEffect(float dt)
{
}
void CMorphBall::RenderIceBreakEffect(const CStateManager& mgr) const
{
if (x19e0_effect_morphBallIceBreakGen)
x19e0_effect_morphBallIceBreakGen->Render();
} }
void CMorphBall::RenderDamageEffects(const CStateManager&, const zeus::CTransform&) const void CMorphBall::RenderDamageEffects(const CStateManager&, const zeus::CTransform&) const
@ -628,39 +655,16 @@ void CMorphBall::UpdateHalfPipeStatus(CStateManager&, float)
} }
bool CMorphBall::GetIsInHalfPipeMode() const
{
return false;
}
void CMorphBall::SetIsInHalfPipeMode(bool)
{
}
void CMorphBall::GetIsInHalfPipeModeInAir() const
{
}
void CMorphBall::SetIsInHalfPipeModeInAir(bool)
{
}
void CMorphBall::GetTouchedHalfPipeRecently() const
{
}
void CMorphBall::SetTouchedHalfPipeRecently(bool)
{
}
void CMorphBall::DisableHalfPipeStatus() void CMorphBall::DisableHalfPipeStatus()
{ {
SetIsInHalfPipeMode(false);
SetIsInHalfPipeModeInAir(false);
SetTouchedHalfPipeRecently(false);
x1dfc_ = 0.f;
x1e00_ = 0.f;
x0_player.SetCollisionAccuracyModifier(1.f);
x1e08_ = zeus::CVector3f::skZero;
x1e14_ = zeus::CVector3f::skZero;
} }
bool CMorphBall::BallCloseToCollision(const CStateManager&, float, const CMaterialFilter& filter) const bool CMorphBall::BallCloseToCollision(const CStateManager&, float, const CMaterialFilter& filter) const
@ -668,14 +672,205 @@ bool CMorphBall::BallCloseToCollision(const CStateManager&, float, const CMateri
return false; return false;
} }
void CMorphBall::CollidedWith(TUniqueId, const CCollisionInfoList&, CStateManager&) void CMorphBall::CollidedWith(TUniqueId id, const CCollisionInfoList& list, CStateManager& mgr)
{ {
x74_collisionInfos = list;
CMaterialList allMats;
for (const CCollisionInfo& info : list)
allMats.Add(info.GetMaterialLeft());
zeus::CVector3f vel = x0_player.GetVelocity();
float velMag = vel.magnitude();
EMaterialTypes wakeMaterial = EMaterialTypes::Unknown;
if (velMag > 7.f && x0_player.GetFluidCounter() == 0)
{
bool hitWall = false;
for (const CCollisionInfo& info : list)
{
if (!hitWall)
{
if (info.GetMaterialLeft().HasMaterial(EMaterialTypes::Wall))
{
hitWall = true;
if (info.GetMaterialLeft().HasMaterial(EMaterialTypes::Stone) ||
info.GetMaterialLeft().HasMaterial(EMaterialTypes::Metal))
{
x19cc_wallSparkGen->SetTranslation(info.GetPoint());
x19cc_wallSparkGen->SetParticleEmission(true);
x1e38_ = 7;
}
}
}
if (wakeMaterial == EMaterialTypes::Unknown)
{
if (info.GetMaterialLeft().HasMaterial(EMaterialTypes::Floor))
{
EMaterialTypes tmpMaterial;
if (info.GetMaterialLeft().HasMaterial(EMaterialTypes::Dirt))
tmpMaterial = EMaterialTypes::Dirt;
else
tmpMaterial = wakeMaterial;
if (info.GetMaterialLeft().HasMaterial(EMaterialTypes::Sand))
tmpMaterial = EMaterialTypes::Sand;
if (info.GetMaterialLeft().HasMaterial(EMaterialTypes::Lava))
tmpMaterial = EMaterialTypes::Lava;
if (info.GetMaterialLeft().HasMaterial(EMaterialTypes::MudSlow))
tmpMaterial = EMaterialTypes::MudSlow;
if (info.GetMaterialLeft().HasMaterial(EMaterialTypes::Snow))
tmpMaterial = EMaterialTypes::Snow;
if (info.GetMaterialLeft().HasMaterial(EMaterialTypes::Phazon))
tmpMaterial = EMaterialTypes::Phazon;
wakeMaterial = tmpMaterial;
if (tmpMaterial != EMaterialTypes::Unknown)
{
int mappedIdx = skWakeEffectMap[int(tmpMaterial)];
if (mappedIdx == 0) // Phazon
{
const CGameArea* area = mgr.GetWorld()->GetAreaAlways(mgr.GetNextAreaId());
if (const CScriptAreaAttributes* attribs =
area->GetPostConstructed()->x10d8_areaAttributes)
if (attribs->GetPhazonType() == EPhazonType::Orange)
mappedIdx = 1; // Orange Phazon
}
if (x1c0c_wakeEffectIdx != mappedIdx)
{
if (x1c0c_wakeEffectIdx != -1)
x1bc8_wakeEffectGens[x1c0c_wakeEffectIdx]->SetParticleEmission(false);
x1c0c_wakeEffectIdx = mappedIdx;
}
x1bc8_wakeEffectGens[x1c0c_wakeEffectIdx]->SetParticleEmission(true);
x1bc8_wakeEffectGens[x1c0c_wakeEffectIdx]->SetTranslation(info.GetPoint());
}
}
}
}
if (hitWall && !CSfxManager::IsPlaying(x1e28_wallHitSfxHandle))
{
x1e28_wallHitSfxHandle = CSfxManager::AddEmitter(1525, x0_player.GetTranslation(),
zeus::CVector3f::skZero,
true, false, 0x7f, kInvalidAreaId);
x0_player.ApplySubmergedPitchBend(x1e28_wallHitSfxHandle);
}
}
if (wakeMaterial == EMaterialTypes::Unknown && x1c0c_wakeEffectIdx != -1)
x1bcc_[int(wakeMaterial)]->SetParticleEmission(false);
x1954_isProjectile = false;
if (allMats.HasMaterial(EMaterialTypes::HalfPipe))
{
x1dfc_ = 4.f;
x1e04_ = 0.05f;
for (const CCollisionInfo& info : list)
{
if (info.GetMaterialLeft().HasMaterial(EMaterialTypes::HalfPipe))
{
if (info.GetNormalLeft().dot(x1e14_) < 0.99)
{
x1e08_ = x1e14_;
x1e14_ = info.GetNormalLeft();
if (zeus::close_enough(x1e08_, zeus::CVector3f::skZero, 0.000011920929f))
x1e08_ = x1e14_;
}
}
}
}
if (x28_ && allMats.HasMaterial(EMaterialTypes::Floor) && allMats.HasMaterial(EMaterialTypes::Wall))
SwitchToMarble();
if (!GetIsInHalfPipeMode() && x1de4_24 && velMag > 3.f)
{
zeus::CVector3f velNorm = vel.normalized();
for (const CCollisionInfo& info : list)
{
if (!info.GetMaterialLeft().HasMaterial(EMaterialTypes::HalfPipe) &&
info.GetNormalLeft().dot(velNorm) < -0.4f)
{
LeaveBoosting();
DampLinearAndAngularVelocities(0.4f, 0.01f);
break;
}
}
}
if (id == kInvalidUniqueId)
{
zeus::CVector3f cvel = x0_player.GetVelocity();
float cvelMag = cvel.magnitude();
zeus::CVector3f pvel = x1c_;
if (pvel.magnitude() > 1000.f && cvelMag > 8.f)
{
zeus::CVector3f pvelNorm = pvel.normalized();
zeus::CVector3f cvelNorm = cvel.normalized();
for (const CCollisionInfo& info : list)
{
if (IsClimbable(info) &&
info.GetNormalLeft().dot(pvelNorm) < -0.4f &&
info.GetNormalLeft().dot(cvelNorm) < -0.6f)
{
float f2 = 0.75f * cvelMag;
float maxSpeed = g_tweakBall->GetBallTranslationMaxSpeed(int(x0_player.GetSurfaceRestraint()));
float f0 = maxSpeed * 0.15f;
float f3 = (f2 - f0) < 0.f ? f2 : f0;
float f4 = maxSpeed * 0.25f;
f4 = (f3 - f4) < 0.f ? f4 : f3;
zeus::CVector3f newVel = cvel + zeus::CVector3f(0.f, 0.f, f4);
x1dd8_ = newVel;
x0_player.SetVelocityWR(newVel);
x1dc8_ += 1;
break;
}
}
}
}
if (list.GetCount() > 2 && list.GetItem(0).GetNormalLeft().z > 0.2f &&
std::fabs(x0_player.GetVelocity().dot(list.GetItem(0).GetNormalLeft())) > 2.f)
{
float accum = 0.f;
int count = 0;
for (auto it = list.begin() + 1 ; it != list.end() ; ++it)
{
const CCollisionInfo& item1 = *it;
for (auto it2 = list.begin() + 1 ; it2 != list.end() ; ++it2)
{
const CCollisionInfo& item2 = *it2;
accum += item1.GetNormalLeft().dot(item2.GetNormalLeft());
count += 1;
}
}
if (accum / float(count) < 0.5f)
x1dc8_ += 1;
}
if (list.GetCount() != 0)
SelectMorphBallSounds(list.GetItem(0).GetMaterialLeft());
} }
bool CMorphBall::IsInFrustum(const zeus::CFrustum&) const bool CMorphBall::IsInFrustum(const zeus::CFrustum& frustum) const
{ {
if (x58_ballModel->IsNull())
return false; return false;
if (x58_ballModel->IsInFrustum(GetBallToWorld(), frustum))
return true;
auto swooshBounds = x19b8_slowBlueTailSwooshGen->GetBounds();
return x19b8_slowBlueTailSwooshGen->GetModulationColor().a != 0.f && swooshBounds &&
frustum.aabbFrustumTest(*swooshBounds);
} }
void CMorphBall::ComputeLiftForces(const zeus::CVector3f&, const zeus::CVector3f&, const CStateManager&) void CMorphBall::ComputeLiftForces(const zeus::CVector3f&, const zeus::CVector3f&, const CStateManager&)
@ -683,33 +878,63 @@ void CMorphBall::ComputeLiftForces(const zeus::CVector3f&, const zeus::CVector3f
} }
void CMorphBall::CalculateSurfaceFriction() const float CMorphBall::CalculateSurfaceFriction() const
{ {
float friction = g_tweakBall->GetBallTranslationFriction(int(x0_player.GetSurfaceRestraint()));
if (x0_player.GetAttachedActor() != kInvalidUniqueId)
friction *= 2.f;
size_t drainSourceCount = x0_player.GetEnergyDrain().GetEnergyDrainSources().size();
if (drainSourceCount > 0)
friction *= drainSourceCount * 1.5f;
return friction;
} }
void CMorphBall::ApplyGravity(CStateManager&) void CMorphBall::ApplyGravity(CStateManager& mgr)
{ {
if (x0_player.CheckSubmerged() && !mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::GravitySuit))
x0_player.SetMomentumWR(zeus::CVector3f(0.f, 0.f, g_tweakBall->GetBallWaterGravity() * x0_player.GetMass()));
else
x0_player.SetMomentumWR(zeus::CVector3f(0.f, 0.f, g_tweakBall->GetBallGravity() * x0_player.GetMass()));
} }
void CMorphBall::SpinToSpeed(float, zeus::CVector3f, float) void CMorphBall::SpinToSpeed(float holdMag, zeus::CVector3f torque, float mag)
{ {
x0_player.ApplyTorqueWR(torque *
((holdMag - x0_player.GetAngularVelocityWR().getVector().magnitude()) * mag));
} }
void CMorphBall::ComputeMaxSpeed() const float CMorphBall::ComputeMaxSpeed() const
{ {
if (GetIsInHalfPipeMode())
return std::min(x0_player.GetVelocity().magnitude() * 1.5f, 95.f);
else
return g_tweakBall->GetBallTranslationMaxSpeed(int(x0_player.GetSurfaceRestraint()));
} }
void CMorphBall::Touch(CActor&, CStateManager&) static const CDamageInfo kBallDamage = { CWeaponMode(EWeaponType::BoostBall), 50000.f, 0.f, 0.f };
{
void CMorphBall::Touch(CActor& actor, CStateManager& mgr)
{
if (TCastToPtr<CPhysicsActor> act = actor)
{
if (x1de4_24 &&
(act->GetVelocity() - x0_player.GetVelocity()).magnitude() >
g_tweakBall->GetBoostBallMinRelativeSpeedForDamage())
{
mgr.ApplyDamage(x0_player.GetUniqueId(), actor.GetUniqueId(), x0_player.GetUniqueId(), kBallDamage,
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), zeus::CVector3f::skZero);
}
}
} }
bool CMorphBall::IsClimbable(const CCollisionInfo&) const bool CMorphBall::IsClimbable(const CCollisionInfo& cinfo) const
{ {
if (std::fabs(cinfo.GetNormalLeft().z) < 0.7f)
{
float pointToBall = GetBallToWorld().origin.z - cinfo.GetPoint().z;
if (pointToBall > 0.1f && pointToBall < GetBallRadius() - 0.05f)
return true;
}
return false; return false;
} }
@ -748,9 +973,12 @@ void CMorphBall::RenderEnergyDrainEffects(const CStateManager&) const
} }
void CMorphBall::TouchModel(const CStateManager&) const void CMorphBall::TouchModel(const CStateManager& mgr) const
{ {
x58_ballModel->Touch(mgr, x5c_ballModelShader);
if (mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::SpiderBall) && x60_spiderBallGlassModel)
x60_spiderBallGlassModel->Touch(mgr, x64_spiderBallGlassModelShader);
x68_lowPolyBallModel->Touch(mgr, x6c_lowPolyBallModelShader);
} }
void CMorphBall::SetAsProjectile(const CDamageInfo&, const CDamageInfo&) void CMorphBall::SetAsProjectile(const CDamageInfo&, const CDamageInfo&)
@ -765,17 +993,33 @@ void CMorphBall::TakeDamage(float)
void CMorphBall::StartLandingSfx() void CMorphBall::StartLandingSfx()
{ {
if (x0_player.GetVelocity().z < -5.f && x1e36_landSfx != 0xffff)
{
float vol = zeus::clamp(0.75f, 0.0125f * x0_player.GetLastVelocity().z + 0.75f, 1.f);
CSfxHandle hnd = CSfxManager::SfxStart(x1e36_landSfx, vol, 0.f, true, 0x7f, false, kInvalidAreaId);
x0_player.ApplySubmergedPitchBend(hnd);
}
} }
void CMorphBall::Stop() void CMorphBall::Stop()
{ {
x19b0_effect_morphBallIceBreak.Lock();
if (x19e0_effect_morphBallIceBreakGen)
x19e0_effect_morphBallIceBreakGen.reset();
} }
void CMorphBall::StopSounds() void CMorphBall::StopSounds()
{ {
if (x1e2c_rollSfxHandle)
{
CSfxManager::SfxStop(x1e2c_rollSfxHandle);
x1e2c_rollSfxHandle.reset();
}
if (x1e30_spiderSfxHandle)
{
CSfxManager::SfxStop(x1e30_spiderSfxHandle);
x1e30_spiderSfxHandle.reset();
}
} }
void CMorphBall::ActorAttached() void CMorphBall::ActorAttached()

View File

@ -12,6 +12,7 @@
#include "CWorldShadow.hpp" #include "CWorldShadow.hpp"
#include "Graphics/CRainSplashGenerator.hpp" #include "Graphics/CRainSplashGenerator.hpp"
#include "CMorphBallShadow.hpp" #include "CMorphBallShadow.hpp"
#include "Collision/CCollisionInfoList.hpp"
namespace urde namespace urde
{ {
@ -59,7 +60,7 @@ private:
std::unique_ptr<CModelData> x68_lowPolyBallModel; std::unique_ptr<CModelData> x68_lowPolyBallModel;
u32 x6c_lowPolyBallModelShader = 0; u32 x6c_lowPolyBallModelShader = 0;
std::unique_ptr<CModelData> x70_frozenBallModel; std::unique_ptr<CModelData> x70_frozenBallModel;
u32 x74_frozenBallModelShader = 0; CCollisionInfoList x74_collisionInfos;
u32 xc78_ = 0; u32 xc78_ = 0;
ESpiderBallState x187c_spiderBallState = ESpiderBallState::Inactive; ESpiderBallState x187c_spiderBallState = ESpiderBallState::Inactive;
zeus::CVector3f x1880_; zeus::CVector3f x1880_;
@ -108,8 +109,8 @@ private:
std::unique_ptr<CElementGen> x19d0_ballInnerGlowGen; std::unique_ptr<CElementGen> x19d0_ballInnerGlowGen;
std::unique_ptr<CElementGen> x19d4_spiderBallMagnetEffectGen; std::unique_ptr<CElementGen> x19d4_spiderBallMagnetEffectGen;
std::unique_ptr<CElementGen> x19d8_boostBallGlowGen; std::unique_ptr<CElementGen> x19d8_boostBallGlowGen;
u32 x19dc_ = 0; std::unique_ptr<CElementGen> x19dc_morphBallTransitionFlashGen;
u32 x19e0_ = 0; std::unique_ptr<CElementGen> x19e0_effect_morphBallIceBreakGen;
rstl::reserved_vector<std::pair<std::unique_ptr<CParticleSwoosh>, bool>, 32> x19e4_spiderElectricGens; rstl::reserved_vector<std::pair<std::unique_ptr<CParticleSwoosh>, bool>, 32> x19e4_spiderElectricGens;
std::list<u32> x1b6c_; std::list<u32> x1b6c_;
CRandom16 x1b80_rand = {99}; CRandom16 x1b80_rand = {99};
@ -128,10 +129,11 @@ private:
float x1c30_ = 0.f; float x1c30_ = 0.f;
float x1c34_ = 0.f; float x1c34_ = 0.f;
float x1c38_ = 0.f; float x1c38_ = 0.f;
rstl::reserved_vector<zeus::CQuaternion, 5> x1c3c_quats; TReservedAverage<zeus::CQuaternion, 5> x1c3c_quats = {{}};
rstl::reserved_vector<zeus::CVector3f, 5> x1c90_vecs; TReservedAverage<zeus::CVector3f, 5> x1c90_vecs = {{}};
rstl::reserved_vector<float, 15> x1cd0_; TReservedAverage<float, 15> x1cd0_ = {{}};
rstl::reserved_vector<zeus::CVector3f, 15> x1d10_; TReservedAverage<zeus::CVector3f, 15> x1d10_ = {{}};
u32 x1dc8_ = 0;
zeus::CVector3f x1dcc_; zeus::CVector3f x1dcc_;
zeus::CVector3f x1dd8_; zeus::CVector3f x1dd8_;
bool x1de4_24 : 1; bool x1de4_24 : 1;
@ -140,9 +142,9 @@ private:
float x1dec_ = 0.f; float x1dec_ = 0.f;
float x1df0_ = 0.f; float x1df0_ = 0.f;
float x1df4_ = 0.f; float x1df4_ = 0.f;
bool x1df8_24 : 1; bool x1df8_24_inHalfPipeMode : 1;
bool x1df8_25 : 1; bool x1df8_25_inHalfPipeModeInAir : 1;
bool x1df8_26 : 1; bool x1df8_26_touchedHalfPipeRecently : 1;
bool x1df8_27 : 1; bool x1df8_27 : 1;
float x1dfc_ = 0.f; float x1dfc_ = 0.f;
float x1e00_ = 0.f; float x1e00_ = 0.f;
@ -151,7 +153,7 @@ private:
zeus::CVector3f x1e14_; zeus::CVector3f x1e14_;
u32 x1e20_ = 0; u32 x1e20_ = 0;
CSfxHandle x1e24_boostSfxHandle; CSfxHandle x1e24_boostSfxHandle;
u32 x1e28_ = 0; CSfxHandle x1e28_wallHitSfxHandle;
CSfxHandle x1e2c_rollSfxHandle; CSfxHandle x1e2c_rollSfxHandle;
CSfxHandle x1e30_spiderSfxHandle; CSfxHandle x1e30_spiderSfxHandle;
u16 x1e34_rollSfx = 0xffff; u16 x1e34_rollSfx = 0xffff;
@ -171,7 +173,6 @@ private:
public: public:
CMorphBall(CPlayer& player, float radius); CMorphBall(CPlayer& player, float radius);
void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr); void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr);
zeus::CVector3f GetBallContactSurfaceNormal() const;
const CCollidableSphere& GetCollidableSphere() const { return x38_collisionSphere; } const CCollidableSphere& GetCollidableSphere() const { return x38_collisionSphere; }
bool IsProjectile() const { return x1954_isProjectile; } bool IsProjectile() const { return x1954_isProjectile; }
void GetBallContactMaterials() const {} void GetBallContactMaterials() const {}
@ -180,7 +181,8 @@ public:
bool IsBoosting() const { return false; } bool IsBoosting() const { return false; }
float GetBallRadius() const; float GetBallRadius() const;
float GetBallTouchRadius() const; float GetBallTouchRadius() const;
void ForwardInput(const CFinalInput&) const; void ForwardInput(const CFinalInput& input) const;
void BallTurnInput(const CFinalInput& input) const;
void ComputeBallMovement(const CFinalInput&, CStateManager&, float); void ComputeBallMovement(const CFinalInput&, CStateManager&, float);
bool IsMovementAllowed() const; bool IsMovementAllowed() const;
void UpdateSpiderBall(const CFinalInput&, CStateManager&, float); void UpdateSpiderBall(const CFinalInput&, CStateManager&, float);
@ -204,7 +206,6 @@ public:
zeus::CTransform GetBallToWorld() const; zeus::CTransform GetBallToWorld() const;
void CalculateSurfaceToWorld(const zeus::CVector3f&, const zeus::CVector3f&, const zeus::CVector3f&) const; void CalculateSurfaceToWorld(const zeus::CVector3f&, const zeus::CVector3f&, const zeus::CVector3f&) const;
void CalculateBallContactInfo(zeus::CVector3f&, zeus::CVector3f&) const; void CalculateBallContactInfo(zeus::CVector3f&, zeus::CVector3f&) const;
void BallTurnInput(const CFinalInput&) const;
void UpdateBallDynamics(CStateManager&, float); void UpdateBallDynamics(CStateManager&, float);
void SwitchToMarble(); void SwitchToMarble();
void SwitchToTire(); void SwitchToTire();
@ -230,26 +231,28 @@ public:
void ResetMorphBallTransitionFlash(); void ResetMorphBallTransitionFlash();
void UpdateMorphBallTransitionFlash(float); void UpdateMorphBallTransitionFlash(float);
void RenderMorphBallTransitionFlash(const CStateManager&) const; void RenderMorphBallTransitionFlash(const CStateManager&) const;
bool IsMorphBallTransitionFlashValid() const { return x19dc_ != 0; } void UpdateIceBreakEffect(float dt);
void RenderIceBreakEffect(const CStateManager& mgr) const;
bool IsMorphBallTransitionFlashValid() const { return x19dc_morphBallTransitionFlashGen != 0; }
void RenderDamageEffects(const CStateManager&, const zeus::CTransform&) const; void RenderDamageEffects(const CStateManager&, const zeus::CTransform&) const;
void UpdateHalfPipeStatus(CStateManager&, float); void UpdateHalfPipeStatus(CStateManager&, float);
bool GetIsInHalfPipeMode() const; bool GetIsInHalfPipeMode() const { return x1df8_24_inHalfPipeMode; }
void SetIsInHalfPipeMode(bool); void SetIsInHalfPipeMode(bool b) { x1df8_24_inHalfPipeMode = b; }
void GetIsInHalfPipeModeInAir() const; bool GetIsInHalfPipeModeInAir() const { return x1df8_25_inHalfPipeModeInAir; }
void SetIsInHalfPipeModeInAir(bool); void SetIsInHalfPipeModeInAir(bool b) { x1df8_25_inHalfPipeModeInAir = b; }
void GetTouchedHalfPipeRecently() const; bool GetTouchedHalfPipeRecently() const { return x1df8_26_touchedHalfPipeRecently; }
void SetTouchedHalfPipeRecently(bool); void SetTouchedHalfPipeRecently(bool b) { x1df8_26_touchedHalfPipeRecently = b; }
void DisableHalfPipeStatus(); void DisableHalfPipeStatus();
bool BallCloseToCollision(const CStateManager&, float, const CMaterialFilter& filter) const; bool BallCloseToCollision(const CStateManager&, float, const CMaterialFilter& filter) const;
void CollidedWith(TUniqueId, const CCollisionInfoList&, CStateManager&); void CollidedWith(TUniqueId id, const CCollisionInfoList& list, CStateManager& mgr);
bool IsInFrustum(const zeus::CFrustum&) const; bool IsInFrustum(const zeus::CFrustum& frustum) const;
void ComputeLiftForces(const zeus::CVector3f&, const zeus::CVector3f&, const CStateManager&); void ComputeLiftForces(const zeus::CVector3f&, const zeus::CVector3f&, const CStateManager&);
void CalculateSurfaceFriction() const; float CalculateSurfaceFriction() const;
void ApplyGravity(CStateManager&); void ApplyGravity(CStateManager& mgr);
void SpinToSpeed(float, zeus::CVector3f, float); void SpinToSpeed(float holdMag, zeus::CVector3f torque, float mag);
void ComputeMaxSpeed() const; float ComputeMaxSpeed() const;
void Touch(CActor&, CStateManager&); void Touch(CActor& actor, CStateManager& mgr);
bool IsClimbable(const CCollisionInfo&) const; bool IsClimbable(const CCollisionInfo& cinfo) const;
void FluidFXThink(CActor::EFluidState, CScriptWater&, CStateManager&); void FluidFXThink(CActor::EFluidState, CScriptWater&, CStateManager&);
void GetMorphBallModel(const std::string&, float); void GetMorphBallModel(const std::string&, float);
void LoadMorphBallModel(CStateManager& mgr); void LoadMorphBallModel(CStateManager& mgr);
@ -257,7 +260,7 @@ public:
void UpdateSpiderBallElectricalEffect(); void UpdateSpiderBallElectricalEffect();
void RenderSpiderBallElectricalEffect() const; void RenderSpiderBallElectricalEffect() const;
void RenderEnergyDrainEffects(const CStateManager&) const; void RenderEnergyDrainEffects(const CStateManager&) const;
void TouchModel(const CStateManager&) const; void TouchModel(const CStateManager& mgr) const;
void SetAsProjectile(const CDamageInfo&, const CDamageInfo&); void SetAsProjectile(const CDamageInfo&, const CDamageInfo&);
EBallBoostState GetBallBoostState() const { return x1e3c_boostState; } EBallBoostState GetBallBoostState() const { return x1e3c_boostState; }
void SetBallBoostState(EBallBoostState state) { x1e3c_boostState = state; } void SetBallBoostState(EBallBoostState state) { x1e3c_boostState = state; }
@ -277,6 +280,8 @@ public:
u32 GetMorphballModelShader() const { return x5c_ballModelShader; } u32 GetMorphballModelShader() const { return x5c_ballModelShader; }
bool GetX1DE4_25() const { return x1de4_25; } bool GetX1DE4_25() const { return x1de4_25; }
void SetX1DE4_25(bool b) { x1de4_25 = b; } void SetX1DE4_25(bool b) { x1de4_25 = b; }
static const u8 BallTransFlashColors[9][3];
}; };
} }

View File

@ -673,6 +673,7 @@ public:
float GetAttachedActorStruggle() const { return xa28_attachedActorStruggle; } float GetAttachedActorStruggle() const { return xa28_attachedActorStruggle; }
float GetDistanceUnderWater() const { return x828_distanceUnderWater; } float GetDistanceUnderWater() const { return x828_distanceUnderWater; }
TUniqueId GetRidingPlatformId() const { return x82e_ridingPlatform; } TUniqueId GetRidingPlatformId() const { return x82e_ridingPlatform; }
const zeus::CVector3f& GetLastVelocity() const { return x794_lastVelocity; }
}; };
} }