metaforce/Runtime/Weapon/CWaveBeam.cpp

168 lines
5.7 KiB
C++
Raw Permalink Normal View History

#include "Runtime/Weapon/CWaveBeam.hpp"
#include <array>
#include "Runtime/CSimplePool.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Weapon/CEnergyProjectile.hpp"
2021-04-10 08:42:06 +00:00
namespace metaforce {
namespace {
constexpr float skShotAnglePitch = 120.f;
constexpr std::array<u16, 2> kSoundId{
SFXwpn_fire_wave_normal,
SFXwpn_fire_wave_charged,
};
} // Anonymous namespace
2018-12-08 05:30:43 +00:00
CWaveBeam::CWaveBeam(CAssetId characterId, EWeaponType type, TUniqueId playerId, EMaterialTypes playerMaterial,
const zeus::CVector3f& scale)
: CGunWeapon(characterId, type, playerId, playerMaterial, scale) {
x21c_waveBeam = g_SimplePool->GetObj("WaveBeam");
x228_wave2nd1 = g_SimplePool->GetObj("Wave2nd_1");
x234_wave2nd2 = g_SimplePool->GetObj("Wave2nd_2");
x240_wave2nd3 = g_SimplePool->GetObj("Wave2nd_3");
2017-09-07 03:55:31 +00:00
}
2018-12-08 05:30:43 +00:00
void CWaveBeam::PostRenderGunFx(const CStateManager& mgr, const zeus::CTransform& xf) {
if (x1cc_enabledSecondaryEffect != ESecondaryFxType::None) {
if (x254_chargeFx)
x254_chargeFx->Render();
if (x250_chargeElec)
x250_chargeElec->Render();
}
CGunWeapon::PostRenderGunFx(mgr, xf);
2017-09-07 03:55:31 +00:00
}
2018-12-08 05:30:43 +00:00
void CWaveBeam::UpdateGunFx(bool shotSmoke, float dt, const CStateManager& mgr, const zeus::CTransform& xf) {
if (x1cc_enabledSecondaryEffect != ESecondaryFxType::None) {
if (x258_25_effectTimerActive && x24c_effectTimer < 0.f) {
x1cc_enabledSecondaryEffect = ESecondaryFxType::None;
x24c_effectTimer = 0.f;
x258_25_effectTimerActive = false;
} else {
if (x254_chargeFx) {
x254_chargeFx->SetGlobalTranslation(xf.origin);
x254_chargeFx->SetGlobalOrientation(xf.getRotation());
x254_chargeFx->Update(dt);
}
if (x250_chargeElec) {
x250_chargeElec->SetGlobalTranslation(xf.origin);
x250_chargeElec->SetGlobalOrientation(xf.getRotation());
x250_chargeElec->Update(dt);
}
2017-09-07 03:55:31 +00:00
}
2018-12-08 05:30:43 +00:00
if (x258_25_effectTimerActive && x24c_effectTimer > 0.f)
x24c_effectTimer -= 0.f;
}
CGunWeapon::UpdateGunFx(shotSmoke, dt, mgr, xf);
2017-09-07 03:55:31 +00:00
}
void CWaveBeam::Fire(bool underwater, float dt, EChargeState chargeState, const zeus::CTransform& xf,
2018-12-08 05:30:43 +00:00
CStateManager& mgr, TUniqueId homingTarget, float chargeFactor1, float chargeFactor2) {
if (chargeState == EChargeState::Charged) {
CGunWeapon::Fire(underwater, dt, chargeState, xf, mgr, homingTarget, chargeFactor1, chargeFactor2);
} else {
float randAng = mgr.GetActiveRandom()->Float() * 360.f;
auto& weaponDesc = x144_weapons[int(chargeState)];
for (int i = 0; i < 3; ++i) {
zeus::CTransform shotXf = xf * zeus::CTransform::RotateY(zeus::degToRad((randAng + i) * skShotAnglePitch));
CEnergyProjectile* proj = new CEnergyProjectile(
true, weaponDesc, x1c0_weaponType, shotXf, x1c8_playerMaterial,
GetDamageInfo(mgr, chargeState, chargeFactor1), mgr.AllocateUniqueId(), kInvalidAreaId, x1c4_playerId,
homingTarget, EProjectileAttrib::ArmCannon, underwater, zeus::skOne3f, {}, -1, false);
2018-12-08 05:30:43 +00:00
mgr.AddObject(proj);
proj->Think(dt, mgr);
2017-09-07 03:55:31 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-09-07 03:55:31 +00:00
2018-12-08 05:30:43 +00:00
if (chargeState == EChargeState::Charged)
x218_25_enableCharge = true;
2017-09-07 03:55:31 +00:00
NWeaponTypes::play_sfx(kSoundId[size_t(chargeState)], underwater, false, 0.165f);
const CAnimPlaybackParms parms(skShootAnim[size_t(chargeState)], -1, 1.f, true);
x10_solidModelData->GetAnimationData()->EnableLooping(false);
x10_solidModelData->GetAnimationData()->SetAnimation(parms, false);
2017-09-07 03:55:31 +00:00
}
2018-12-08 05:30:43 +00:00
void CWaveBeam::EnableSecondaryFx(ESecondaryFxType type) {
switch (type) {
case ESecondaryFxType::None:
x1cc_enabledSecondaryEffect = ESecondaryFxType::None;
break;
case ESecondaryFxType::CancelCharge:
if (x1cc_enabledSecondaryEffect == ESecondaryFxType::None)
break;
2019-02-18 05:47:46 +00:00
[[fallthrough]];
2018-12-08 05:30:43 +00:00
default:
if (x1cc_enabledSecondaryEffect != ESecondaryFxType::ToCombo) {
auto& fx = type == ESecondaryFxType::Charge ? x228_wave2nd1 : x234_wave2nd2;
x250_chargeElec = std::make_unique<CParticleElectric>(fx);
x250_chargeElec->SetGlobalScale(x4_scale);
}
switch (type) {
case ESecondaryFxType::Charge:
x254_chargeFx.reset();
break;
2017-09-07 03:55:31 +00:00
case ESecondaryFxType::CancelCharge:
2018-12-08 05:30:43 +00:00
if (x1cc_enabledSecondaryEffect != ESecondaryFxType::CancelCharge) {
x258_25_effectTimerActive = true;
x24c_effectTimer = 3.f;
if (x254_chargeFx)
x254_chargeFx->SetParticleEmission(false);
}
break;
case ESecondaryFxType::ToCombo:
x254_chargeFx = std::make_unique<CElementGen>(x240_wave2nd3);
x254_chargeFx->SetGlobalScale(x4_scale);
x24c_effectTimer = 0.f;
x258_25_effectTimerActive = true;
2019-02-18 05:47:46 +00:00
break;
2017-09-07 03:55:31 +00:00
default:
2018-12-08 05:30:43 +00:00
break;
2017-09-07 03:55:31 +00:00
}
2018-12-08 05:30:43 +00:00
x1cc_enabledSecondaryEffect = type;
}
2017-09-07 03:55:31 +00:00
}
2018-12-08 05:30:43 +00:00
void CWaveBeam::Update(float dt, CStateManager& mgr) {
CGunWeapon::Update(dt, mgr);
if (IsLoaded())
return;
2017-09-07 03:55:31 +00:00
2018-12-08 05:30:43 +00:00
if (CGunWeapon::IsLoaded() && !x258_24_loaded) {
x258_24_loaded =
x228_wave2nd1.IsLoaded() && x234_wave2nd2.IsLoaded() && x240_wave2nd3.IsLoaded() && x21c_waveBeam.IsLoaded();
}
2017-09-07 03:55:31 +00:00
}
2018-12-08 05:30:43 +00:00
void CWaveBeam::Load(CStateManager& mgr, bool subtypeBasePose) {
CGunWeapon::Load(mgr, subtypeBasePose);
x228_wave2nd1.Lock();
x234_wave2nd2.Lock();
x240_wave2nd3.Lock();
x21c_waveBeam.Lock();
2017-09-07 03:55:31 +00:00
}
2018-12-08 05:30:43 +00:00
void CWaveBeam::ReInitVariables() {
x24c_effectTimer = 0.f;
x250_chargeElec.reset();
x254_chargeFx.reset();
x258_24_loaded = false;
x258_25_effectTimerActive = false;
x1cc_enabledSecondaryEffect = ESecondaryFxType::None;
2017-09-07 03:55:31 +00:00
}
2018-12-08 05:30:43 +00:00
void CWaveBeam::Unload(CStateManager& mgr) {
CGunWeapon::Unload(mgr);
x21c_waveBeam.Unlock();
x240_wave2nd3.Unlock();
x234_wave2nd2.Unlock();
x228_wave2nd1.Unlock();
ReInitVariables();
2017-09-07 03:55:31 +00:00
}
2018-12-08 05:30:43 +00:00
bool CWaveBeam::IsLoaded() const { return CGunWeapon::IsLoaded() && x258_24_loaded; }
2021-04-10 08:42:06 +00:00
} // namespace metaforce