metaforce/Runtime/Weapon/CWaveBeam.cpp

189 lines
6.1 KiB
C++
Raw Normal View History

#include "CWaveBeam.hpp"
#include "GameGlobalObjects.hpp"
#include "CSimplePool.hpp"
2017-09-07 03:55:31 +00:00
#include "CEnergyProjectile.hpp"
namespace urde
{
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
x258_24_loaded = false;
x258_25_effectTimerActive = false;
}
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);
}
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);
}
}
if (x258_25_effectTimerActive && x24c_effectTimer > 0.f)
x24c_effectTimer -= 0.f;
}
CGunWeapon::UpdateGunFx(shotSmoke, dt, mgr, xf);
}
static const float skShotAnglePitch = 120.f;
static const u16 kSoundId[] = { 1801, 1845 };
void CWaveBeam::Fire(bool underwater, float dt, EChargeState chargeState, const zeus::CTransform& xf,
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, CWeapon::EProjectileAttrib::ArmCannon, underwater,
zeus::CVector3f::skOne, {}, -1, false);
mgr.AddObject(proj);
proj->Think(dt, mgr);
}
}
if (chargeState == EChargeState::Charged)
x218_25_enableCharge = true;
NWeaponTypes::play_sfx(kSoundId[int(chargeState)], underwater, false, 0.165f);
CAnimPlaybackParms parms(skShootAnim[int(chargeState)], -1, 1.f, true);
x10_solidModelData->AnimationData()->EnableLooping(false);
x10_solidModelData->AnimationData()->SetAnimation(parms, false);
}
void CWaveBeam::EnableSecondaryFx(ESecondaryFxType type)
{
switch (type)
{
case ESecondaryFxType::None:
x1cc_enabledSecondaryEffect = ESecondaryFxType::None;
break;
case ESecondaryFxType::CancelCharge:
if (x1cc_enabledSecondaryEffect == ESecondaryFxType::None)
break;
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;
case ESecondaryFxType::CancelCharge:
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);
2017-09-07 03:55:31 +00:00
x254_chargeFx->SetGlobalScale(x4_scale);
x24c_effectTimer = 0.f;
x258_25_effectTimerActive = true;
default:
break;
}
x1cc_enabledSecondaryEffect = type;
}
}
void CWaveBeam::Update(float dt, CStateManager& mgr)
{
CGunWeapon::Update(dt, mgr);
if (IsLoaded())
return;
if (CGunWeapon::IsLoaded() && !x258_24_loaded)
{
x258_24_loaded = x228_wave2nd1.IsLoaded() && x234_wave2nd2.IsLoaded() &&
x240_wave2nd3.IsLoaded() && x21c_waveBeam.IsLoaded();
}
}
void CWaveBeam::Load(CStateManager& mgr, bool subtypeBasePose)
{
CGunWeapon::Load(mgr, subtypeBasePose);
x228_wave2nd1.Lock();
x234_wave2nd2.Lock();
x240_wave2nd3.Lock();
x21c_waveBeam.Lock();
}
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;
}
void CWaveBeam::Unload(CStateManager& mgr)
{
CGunWeapon::Unload(mgr);
x21c_waveBeam.Unlock();
x240_wave2nd3.Unlock();
x234_wave2nd2.Unlock();
x228_wave2nd1.Unlock();
ReInitVariables();
}
bool CWaveBeam::IsLoaded() const
{
return CGunWeapon::IsLoaded() && x258_24_loaded;
}
}