2019-10-03 05:30:04 +00:00
|
|
|
#include "Runtime/MP1/World/CAtomicBeta.hpp"
|
|
|
|
|
2019-10-03 05:32:30 +00:00
|
|
|
#include <array>
|
|
|
|
|
2019-10-03 05:30:04 +00:00
|
|
|
#include "Runtime/CSimplePool.hpp"
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
#include "Runtime/Particle/CWeaponDescription.hpp"
|
|
|
|
#include "Runtime/Weapon/CElectricBeamProjectile.hpp"
|
|
|
|
#include "Runtime/Weapon/CPlayerGun.hpp"
|
|
|
|
#include "Runtime/World/CPlayer.hpp"
|
2019-01-23 05:59:53 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce::MP1 {
|
2019-10-03 05:32:30 +00:00
|
|
|
constexpr std::array skBombLocators{
|
|
|
|
"bomb2_LCTR"sv,
|
|
|
|
"bomb3_LCTR"sv,
|
|
|
|
"bomb4_LCTR"sv,
|
|
|
|
};
|
2019-01-23 05:59:53 +00:00
|
|
|
|
|
|
|
CAtomicBeta::CAtomicBeta(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf,
|
|
|
|
CModelData&& mData, const CActorParameters& actParms, const CPatternedInfo& pInfo,
|
|
|
|
CAssetId electricId, CAssetId weaponId, const CDamageInfo& dInfo, CAssetId particleId,
|
2019-01-31 20:44:05 +00:00
|
|
|
float f1, float beamRadius, float f3, const CDamageVulnerability& dVuln, float f4, float f5,
|
|
|
|
float f6, s16 sId1, s16 sId2, s16 sId3, float f7)
|
2019-01-23 05:59:53 +00:00
|
|
|
: CPatterned(ECharacter::AtomicBeta, uid, name, EFlavorType::Zero, info, xf, std::move(mData), pInfo,
|
|
|
|
EMovementType::Flyer, EColliderType::One, EBodyType::RestrictedFlyer, actParms, EKnockBackVariant::Small)
|
2020-08-24 07:59:30 +00:00
|
|
|
, x578_minSpeed(f5)
|
|
|
|
, x57c_maxSpeed(f6)
|
|
|
|
, x580_speedStep(f7)
|
|
|
|
, x584_currentSpeed(x578_minSpeed)
|
2019-01-23 05:59:53 +00:00
|
|
|
, x588_frozenDamage(dVuln)
|
2020-08-24 07:59:30 +00:00
|
|
|
, x5f0_moveSpeed(f4)
|
2019-01-23 05:59:53 +00:00
|
|
|
, x5f4_(xf.basis[1])
|
|
|
|
, x600_electricWeapon(g_SimplePool->GetObj({SBIG('ELSC'), electricId}))
|
|
|
|
, x608_(g_SimplePool->GetObj({SBIG('WPSC'), weaponId}))
|
|
|
|
, x610_projectileDamage(dInfo)
|
|
|
|
, x62c_beamParticle(particleId)
|
|
|
|
, x630_(f1)
|
|
|
|
, x634_beamRadius(beamRadius)
|
|
|
|
, x638_(f3)
|
|
|
|
, x644_(CSfxManager::TranslateSFXID(sId1))
|
|
|
|
, x646_(CSfxManager::TranslateSFXID(sId2))
|
|
|
|
, x648_(CSfxManager::TranslateSFXID(sId3)) {
|
|
|
|
x460_knockBackController.SetAutoResetImpulse(false);
|
|
|
|
x460_knockBackController.SetEnableFreeze(false);
|
|
|
|
x460_knockBackController.SetX82_24(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CAtomicBeta::CreateBeams(CStateManager& mgr) {
|
|
|
|
const SElectricBeamInfo beamInfo{x600_electricWeapon, 50.f, x634_beamRadius, 10.f, x62c_beamParticle, x630_, x638_};
|
|
|
|
|
2019-10-03 05:32:30 +00:00
|
|
|
for (size_t i = 0; i < kBombCount; ++i) {
|
2020-04-22 02:04:37 +00:00
|
|
|
const TUniqueId id = mgr.AllocateUniqueId();
|
|
|
|
x568_projectileIds.push_back(id);
|
2019-01-23 05:59:53 +00:00
|
|
|
mgr.AddObject(new CElectricBeamProjectile(x608_, EWeaponType::AI, beamInfo, {}, EMaterialTypes::Character,
|
2020-04-22 02:04:37 +00:00
|
|
|
x610_projectileDamage, id, GetAreaIdAlways(), GetUniqueId(),
|
|
|
|
EProjectileAttrib::None));
|
2019-01-23 05:59:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CAtomicBeta::UpdateBeams(CStateManager& mgr, bool fireBeam) {
|
2019-10-03 05:32:30 +00:00
|
|
|
if (x574_beamFired == fireBeam) {
|
2019-01-23 05:59:53 +00:00
|
|
|
return;
|
2019-10-03 05:32:30 +00:00
|
|
|
}
|
2019-01-23 05:59:53 +00:00
|
|
|
|
2020-04-22 02:04:37 +00:00
|
|
|
for (size_t i = 0; i < x568_projectileIds.size(); ++i) {
|
|
|
|
// zeus::CTransform xf = GetTransform() * GetScaledLocatorTransform(skBombLocators[i]);
|
|
|
|
// zeus::CTransform newXf = zeus::lookAt(xf.origin, xf.origin + xf.basis[1], zeus::skUp);
|
2019-10-03 05:32:30 +00:00
|
|
|
if (auto* const proj = static_cast<CElectricBeamProjectile*>(mgr.ObjectById(x568_projectileIds[i]))) {
|
|
|
|
if (fireBeam) {
|
2019-01-23 05:59:53 +00:00
|
|
|
proj->Fire(GetTransform() * GetScaledLocatorTransform(skBombLocators[i]), mgr, false);
|
2019-10-03 05:32:30 +00:00
|
|
|
} else {
|
2019-01-23 05:59:53 +00:00
|
|
|
proj->ResetBeam(mgr, false);
|
2019-10-03 05:32:30 +00:00
|
|
|
}
|
2019-01-23 05:59:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
x574_beamFired = fireBeam;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CAtomicBeta::FreeBeams(CStateManager& mgr) {
|
|
|
|
for (TUniqueId uid : x568_projectileIds) {
|
|
|
|
mgr.FreeScriptObject(uid);
|
|
|
|
}
|
|
|
|
x568_projectileIds.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CAtomicBeta::UpdateOrCreateEmitter(CSfxHandle& handle, u16 id, const zeus::CVector3f& pos, float maxVol) {
|
|
|
|
if (handle)
|
|
|
|
CSfxManager::UpdateEmitter(handle, pos, {}, maxVol);
|
|
|
|
else
|
|
|
|
handle = CSfxManager::AddEmitter(id, pos, {}, maxVol, true, true, 0x7F, GetAreaIdAlways());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CAtomicBeta::DestroyEmitter(CSfxHandle& handle) {
|
|
|
|
if (handle) {
|
|
|
|
CSfxManager::RemoveEmitter(handle);
|
|
|
|
handle.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CAtomicBeta::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
|
|
|
|
if (msg == EScriptObjectMessage::Registered) {
|
|
|
|
x450_bodyController->Activate(mgr);
|
|
|
|
CreateBeams(mgr);
|
|
|
|
} else if (msg == EScriptObjectMessage::Deactivate) {
|
|
|
|
UpdateBeams(mgr, false);
|
|
|
|
DestroyEmitter(x650_);
|
|
|
|
DestroyEmitter(x654_);
|
|
|
|
DestroyEmitter(x64c_);
|
|
|
|
} else if (msg == EScriptObjectMessage::Deleted) {
|
|
|
|
FreeBeams(mgr);
|
|
|
|
}
|
|
|
|
CPatterned::AcceptScriptMsg(msg, uid, mgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CAtomicBeta::Think(float dt, CStateManager& mgr) {
|
|
|
|
CPatterned::Think(dt, mgr);
|
|
|
|
zeus::CVector3f movementVec = x450_bodyController->GetCommandMgr().GetMoveVector();
|
|
|
|
x450_bodyController->GetCommandMgr().ClearLocomotionCmds();
|
|
|
|
if (!movementVec.isZero())
|
|
|
|
x450_bodyController->GetCommandMgr().DeliverCmd(CBCLocomotionCmd(movementVec, x5f4_, 1.f));
|
|
|
|
|
2020-02-12 09:57:03 +00:00
|
|
|
const float mag =
|
|
|
|
x63c_ * std::max(1.f - (mgr.GetPlayer().GetTranslation() - GetTranslation()).magSquared() / (x640_ * x640_), 0.f);
|
2019-01-23 05:59:53 +00:00
|
|
|
if (!zeus::close_enough(mag, 0.f))
|
|
|
|
mgr.GetPlayerState()->GetStaticInterference().AddSource(GetUniqueId(), mag, 0.5f);
|
|
|
|
|
|
|
|
if (InMaxRange(mgr, dt)) {
|
|
|
|
UpdateBeams(mgr, true);
|
|
|
|
UpdateOrCreateEmitter(x650_, x646_, GetTranslation(), 96 / 127.f);
|
|
|
|
UpdateOrCreateEmitter(x654_, x648_, GetTranslation(), 96 / 127.f);
|
|
|
|
DestroyEmitter(x64c_);
|
|
|
|
} else {
|
2020-04-22 02:04:37 +00:00
|
|
|
UpdateBeams(mgr, false);
|
2019-01-23 05:59:53 +00:00
|
|
|
DestroyEmitter(x650_);
|
|
|
|
DestroyEmitter(x654_);
|
|
|
|
UpdateOrCreateEmitter(x64c_, x644_, GetTranslation(), 96 / 127.f);
|
|
|
|
}
|
|
|
|
|
2020-04-22 02:04:37 +00:00
|
|
|
// was hardcoded to 3 (kBombCount), but that segfaults after FreeBeams
|
|
|
|
for (size_t i = 0; i < x568_projectileIds.size(); ++i) {
|
2019-10-03 05:32:30 +00:00
|
|
|
if (auto* const proj = static_cast<CElectricBeamProjectile*>(mgr.ObjectById(x568_projectileIds[i]))) {
|
|
|
|
if (!proj->GetActive()) {
|
2019-01-23 05:59:53 +00:00
|
|
|
continue;
|
2019-10-03 05:32:30 +00:00
|
|
|
}
|
|
|
|
const zeus::CTransform xf = GetTransform() * GetScaledLocatorTransform(skBombLocators[i]);
|
2020-04-22 02:04:37 +00:00
|
|
|
proj->UpdateFx(zeus::lookAt(xf.origin, xf.origin + xf.frontVector(), zeus::skUp), dt, mgr);
|
2019-01-23 05:59:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-24 07:59:30 +00:00
|
|
|
float speed = x580_speedStep * (dt * (IsPlayerBeamChargedEnough(mgr) ? 1.f : -1.f)) + x584_currentSpeed;
|
|
|
|
x584_currentSpeed = zeus::clamp(x578_minSpeed, speed, x57c_maxSpeed);
|
|
|
|
x3b4_speed = x584_currentSpeed;
|
|
|
|
x450_bodyController->SetRestrictedFlyerMoveSpeed(x5f0_moveSpeed * x584_currentSpeed);
|
2019-01-23 05:59:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const CDamageVulnerability* CAtomicBeta::GetDamageVulnerability() const {
|
|
|
|
if (zeus::close_enough(x450_bodyController->GetPercentageFrozen(), 0.f))
|
|
|
|
return CPatterned::GetDamageVulnerability();
|
|
|
|
return &x588_frozenDamage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CAtomicBeta::Death(CStateManager& mgr, const zeus::CVector3f& dir, EScriptObjectState state) {
|
|
|
|
UpdateBeams(mgr, false);
|
|
|
|
DestroyEmitter(x650_);
|
|
|
|
DestroyEmitter(x654_);
|
|
|
|
DestroyEmitter(x64c_);
|
|
|
|
CPatterned::Death(mgr, dir, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CAtomicBeta::IsPlayerBeamChargedEnough(const CStateManager& mgr) {
|
|
|
|
const CPlayerGun* gun = mgr.GetPlayer().GetPlayerGun();
|
2020-04-22 02:04:37 +00:00
|
|
|
return (gun->IsCharging() ? gun->GetChargeBeamFactor() : 0.f) > 0.1f;
|
2019-01-23 05:59:53 +00:00
|
|
|
}
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce::MP1
|