2019-10-19 04:03:01 +00:00
|
|
|
#include "Runtime/Weapon/CGunWeapon.hpp"
|
|
|
|
|
2019-10-19 04:49:22 +00:00
|
|
|
#include <algorithm>
|
2019-10-19 04:06:25 +00:00
|
|
|
#include <array>
|
|
|
|
|
2019-10-19 04:03:01 +00:00
|
|
|
#include "Runtime/CDependencyGroup.hpp"
|
|
|
|
#include "Runtime/CGameState.hpp"
|
|
|
|
#include "Runtime/CSimplePool.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
#include "Runtime/Graphics/CSkinnedModel.hpp"
|
|
|
|
#include "Runtime/Graphics/CVertexMorphEffect.hpp"
|
|
|
|
#include "Runtime/Weapon/CEnergyProjectile.hpp"
|
|
|
|
#include "Runtime/Weapon/CWeapon.hpp"
|
2016-08-14 21:11:44 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2019-10-19 04:06:25 +00:00
|
|
|
namespace {
|
|
|
|
constexpr std::array skBeamXferNames{
|
|
|
|
"PowerXfer", "IceXfer", "WaveXfer", "PlasmaXfer", "PhazonXfer",
|
|
|
|
};
|
2016-12-10 02:35:20 +00:00
|
|
|
|
2019-10-19 04:06:25 +00:00
|
|
|
constexpr std::array skSuitArmNames{
|
2018-12-08 05:30:43 +00:00
|
|
|
"PowerArm", "GravityArm", "VariaArm", "PhazonArm", "FusionArm", "FusionArmG", "FusionArmV", "FusionArmP",
|
2016-12-10 02:35:20 +00:00
|
|
|
};
|
|
|
|
|
2019-10-19 04:06:25 +00:00
|
|
|
constexpr std::array skMuzzleNames{
|
|
|
|
"PowerMuzzle", "PowerCharge", "IceMuzzle", "IceCharge", "PowerMuzzle",
|
|
|
|
"WaveCharge", "PlasmaMuzzle", "PlasmaCharge", "PhazonMuzzle", "EmptyMuzzle",
|
|
|
|
};
|
2017-09-05 03:00:19 +00:00
|
|
|
|
2019-10-19 04:06:25 +00:00
|
|
|
constexpr std::array skFrozenNames{
|
|
|
|
"powerFrozen", "Ice2nd_2", "iceFrozen", "Ice2nd_2", "waveFrozen",
|
|
|
|
"Ice2nd_2", "plasmaFrozen", "Ice2nd_2", "iceFrozen", "Ice2nd_2",
|
|
|
|
};
|
2017-09-05 03:00:19 +00:00
|
|
|
|
2019-10-19 04:06:25 +00:00
|
|
|
constexpr std::array skDependencyNames{
|
|
|
|
"Power_DGRP", "Ice_DGRP", "Wave_DGRP", "Plasma_DGRP", "Phazon_DGRP",
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr std::array skAnimDependencyNames{
|
|
|
|
"Power_Anim_DGRP", "Ice_Anim_DGRP", "Wave_Anim_DGRP", "Plasma_Anim_DGRP", "Phazon_Anim_DGRP",
|
|
|
|
};
|
2017-09-05 03:00:19 +00:00
|
|
|
|
2019-10-19 04:06:25 +00:00
|
|
|
constexpr std::array skAnimTypeList{
|
|
|
|
0, 4, 1, 2, 3, 5, 6, 7, 8, 9, 10,
|
|
|
|
};
|
2017-09-05 03:00:19 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CPlayerState::EBeamId GetWeaponIndex(EWeaponType type) {
|
|
|
|
if (type == EWeaponType::Power)
|
2017-09-05 03:00:19 +00:00
|
|
|
return CPlayerState::EBeamId::Power;
|
2018-12-08 05:30:43 +00:00
|
|
|
else if (type == EWeaponType::Ice)
|
|
|
|
return CPlayerState::EBeamId::Ice;
|
|
|
|
else if (type == EWeaponType::Wave)
|
|
|
|
return CPlayerState::EBeamId::Wave;
|
|
|
|
else if (type == EWeaponType::Plasma)
|
|
|
|
return CPlayerState::EBeamId::Plasma;
|
|
|
|
else if (type == EWeaponType::Phazon)
|
|
|
|
return CPlayerState::EBeamId::Phazon;
|
|
|
|
return CPlayerState::EBeamId::Power;
|
|
|
|
}
|
2019-10-19 04:06:25 +00:00
|
|
|
} // Anonymous namespace
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
CGunWeapon::CGunWeapon(CAssetId ancsId, EWeaponType type, TUniqueId playerId, EMaterialTypes playerMaterial,
|
|
|
|
const zeus::CVector3f& scale)
|
|
|
|
: x4_scale(scale)
|
|
|
|
, x104_gunCharacter(g_SimplePool->GetObj(SObjectTag{FOURCC('ANCS'), ancsId}))
|
|
|
|
, x13c_armCharacter(g_SimplePool->GetObj(skSuitArmNames[0]))
|
2019-10-19 04:06:25 +00:00
|
|
|
, x160_xferEffect(g_SimplePool->GetObj(skBeamXferNames[size_t(GetWeaponIndex(type))]))
|
2018-12-08 05:30:43 +00:00
|
|
|
, x1c0_weaponType(type)
|
|
|
|
, x1c4_playerId(playerId)
|
|
|
|
, x1c8_playerMaterial(playerMaterial)
|
|
|
|
, x200_beamId(GetWeaponIndex(type))
|
|
|
|
, x20c_shaderIdx(u32(x200_beamId))
|
2020-04-20 04:57:50 +00:00
|
|
|
, x214_ancsId(ancsId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
AllocResPools(x200_beamId);
|
|
|
|
BuildDependencyList(x200_beamId);
|
|
|
|
}
|
|
|
|
|
2020-03-12 21:19:33 +00:00
|
|
|
CGunWeapon::~CGunWeapon() = default;
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CGunWeapon::AllocResPools(CPlayerState::EBeamId beam) {
|
2020-02-25 20:43:25 +00:00
|
|
|
const auto& wPair = g_tweakGunRes->GetWeaponPair(beam);
|
2019-10-19 04:06:25 +00:00
|
|
|
const char* const* muzzleNames = &skMuzzleNames[size_t(beam) * 2];
|
|
|
|
const char* const* frozenNames = &skFrozenNames[size_t(beam) * 2];
|
|
|
|
|
|
|
|
for (size_t i = 0; i < x16c_muzzleEffects.capacity(); ++i) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x16c_muzzleEffects.push_back(g_SimplePool->GetObj(muzzleNames[i]));
|
|
|
|
x144_weapons.push_back(g_SimplePool->GetObj(SObjectTag{FOURCC('WPSC'), wPair[i]}));
|
|
|
|
x188_frozenEffects.push_back(g_SimplePool->GetObj(frozenNames[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::FreeResPools() {
|
|
|
|
x160_xferEffect.Unlock();
|
2019-10-19 04:06:25 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < x16c_muzzleEffects.size(); ++i) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x16c_muzzleEffects[i].Unlock();
|
|
|
|
x144_weapons[i].Unlock();
|
|
|
|
x188_frozenEffects[i].Unlock();
|
|
|
|
}
|
2019-10-19 04:06:25 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x10c_anims.clear();
|
|
|
|
x1a4_muzzleGenerators.clear();
|
|
|
|
x1d0_velInfo.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::FillTokenVector(const std::vector<SObjectTag>& tags, std::vector<CToken>& objects) {
|
|
|
|
for (const SObjectTag& tag : tags)
|
|
|
|
objects.push_back(g_SimplePool->GetObj(tag));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::BuildDependencyList(CPlayerState::EBeamId beam) {
|
2019-10-19 04:06:25 +00:00
|
|
|
TLockedToken<CDependencyGroup> deps = g_SimplePool->GetObj(skDependencyNames[size_t(beam)]);
|
|
|
|
TLockedToken<CDependencyGroup> animDeps = g_SimplePool->GetObj(skAnimDependencyNames[size_t(beam)]);
|
2018-12-08 05:30:43 +00:00
|
|
|
x12c_deps.reserve(deps->GetObjectTagVector().size() + animDeps->GetObjectTagVector().size());
|
|
|
|
FillTokenVector(deps->GetObjectTagVector(), x12c_deps);
|
|
|
|
FillTokenVector(animDeps->GetObjectTagVector(), x12c_deps);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::AsyncLoadSuitArm(CStateManager& mgr) {
|
|
|
|
|
2019-06-12 02:05:17 +00:00
|
|
|
xb0_suitArmModelData = std::nullopt;
|
2019-10-19 04:06:25 +00:00
|
|
|
x13c_armCharacter = g_SimplePool->GetObj(skSuitArmNames[size_t(NWeaponTypes::get_current_suit(mgr))]);
|
2018-12-08 05:30:43 +00:00
|
|
|
x13c_armCharacter.Lock();
|
|
|
|
x218_28_suitArmLocked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::Reset(CStateManager& mgr) {
|
|
|
|
if (!x218_26_loaded)
|
|
|
|
return;
|
|
|
|
|
2019-08-14 14:58:54 +00:00
|
|
|
x10_solidModelData->GetAnimationData()->EnableLooping(false);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x218_25_enableCharge)
|
|
|
|
x218_25_enableCharge = false;
|
|
|
|
else
|
|
|
|
x100_gunController->Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::PlayAnim(NWeaponTypes::EGunAnimType type, bool loop) {
|
2019-10-19 04:06:25 +00:00
|
|
|
if (!x218_26_loaded || type < NWeaponTypes::EGunAnimType::BasePosition || type > NWeaponTypes::EGunAnimType::ToBeam) {
|
|
|
|
return;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2019-10-19 04:06:25 +00:00
|
|
|
|
|
|
|
x10_solidModelData->GetAnimationData()->EnableLooping(loop);
|
|
|
|
const CAnimPlaybackParms parms(skAnimTypeList[size_t(type)], -1, 1.f, true);
|
|
|
|
x10_solidModelData->GetAnimationData()->SetAnimation(parms, false);
|
2017-09-05 03:00:19 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CGunWeapon::PreRenderGunFx(const CStateManager& mgr, const zeus::CTransform& xf) {
|
|
|
|
// Empty
|
2017-09-05 03:00:19 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CGunWeapon::PostRenderGunFx(const CStateManager& mgr, const zeus::CTransform& xf) {
|
|
|
|
if (x218_26_loaded && x1b8_frozenGenerator && x204_frozenEffect != EFrozenFxType::None)
|
|
|
|
x1b8_frozenGenerator->Render();
|
2017-09-05 03:00:19 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CGunWeapon::UpdateGunFx(bool shotSmoke, float dt, const CStateManager& mgr, const zeus::CTransform& xf) {
|
|
|
|
if (x218_26_loaded && x204_frozenEffect != EFrozenFxType::None) {
|
|
|
|
if (x204_frozenEffect == EFrozenFxType::Thawed) {
|
|
|
|
if (x1b8_frozenGenerator->IsSystemDeletable()) {
|
2019-06-30 07:29:49 +00:00
|
|
|
x204_frozenEffect = EFrozenFxType::None;
|
2018-12-08 05:30:43 +00:00
|
|
|
x1b8_frozenGenerator.reset();
|
|
|
|
} else {
|
|
|
|
x1b8_frozenGenerator->SetTranslation(xf.origin);
|
|
|
|
x1b8_frozenGenerator->SetOrientation(xf.getRotation());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
x1b8_frozenGenerator->SetGlobalOrientAndTrans(xf);
|
2017-08-26 04:36:25 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x1b8_frozenGenerator)
|
|
|
|
x1b8_frozenGenerator->Update(dt);
|
|
|
|
}
|
2017-08-26 04:36:25 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 15:31:25 +00:00
|
|
|
constexpr std::array<s32, 2> CGunWeapon::skShootAnim{4, 3};
|
2017-08-25 06:18:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CGunWeapon::Fire(bool underwater, float dt, EChargeState chargeState, const zeus::CTransform& xf,
|
|
|
|
CStateManager& mgr, TUniqueId homingTarget, float chargeFactor1, float chargeFactor2) {
|
2021-04-03 16:48:39 +00:00
|
|
|
OPTICK_EVENT();
|
2018-12-08 05:30:43 +00:00
|
|
|
CDamageInfo dInfo = GetDamageInfo(mgr, chargeState, chargeFactor1);
|
|
|
|
zeus::CVector3f scale(chargeState == EChargeState::Normal ? 1.f : chargeFactor2);
|
|
|
|
bool partialCharge = chargeState == EChargeState::Normal ? false : !zeus::close_enough(chargeFactor1, 1.f);
|
|
|
|
EProjectileAttrib attribs = EProjectileAttrib::ArmCannon;
|
|
|
|
if (partialCharge)
|
|
|
|
attribs |= EProjectileAttrib::PartialCharge;
|
|
|
|
if (chargeState == EChargeState::Charged)
|
|
|
|
attribs |= EProjectileAttrib::Charged;
|
|
|
|
|
|
|
|
CEnergyProjectile* proj = new CEnergyProjectile(
|
|
|
|
true, x144_weapons[int(chargeState)], x1c0_weaponType, xf, x1c8_playerMaterial, dInfo, mgr.AllocateUniqueId(),
|
|
|
|
kInvalidAreaId, x1c4_playerId, homingTarget, attribs, underwater, scale, {}, -1, false);
|
|
|
|
mgr.AddObject(proj);
|
|
|
|
proj->Think(dt, mgr);
|
|
|
|
|
|
|
|
if (chargeState == EChargeState::Charged) {
|
|
|
|
x218_25_enableCharge = true;
|
|
|
|
mgr.GetCameraManager()->AddCameraShaker(CCameraShakeData::skChargedShotCameraShakeData, false);
|
|
|
|
}
|
|
|
|
|
2019-08-14 14:58:54 +00:00
|
|
|
x10_solidModelData->GetAnimationData()->EnableLooping(false);
|
2018-12-08 05:30:43 +00:00
|
|
|
CAnimPlaybackParms parms(skShootAnim[int(chargeState)], -1, 1.f, true);
|
2019-08-14 14:58:54 +00:00
|
|
|
x10_solidModelData->GetAnimationData()->SetAnimation(parms, false);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::EnableFx(bool enable) {
|
|
|
|
// Empty
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::EnableSecondaryFx(ESecondaryFxType type) { x1cc_enabledSecondaryEffect = type; }
|
|
|
|
|
|
|
|
void CGunWeapon::EnableFrozenEffect(EFrozenFxType type) {
|
|
|
|
switch (type) {
|
|
|
|
case EFrozenFxType::Thawed:
|
|
|
|
if (x204_frozenEffect == EFrozenFxType::Thawed)
|
|
|
|
break;
|
|
|
|
x1b8_frozenGenerator = std::make_unique<CElementGen>(x188_frozenEffects[1]);
|
|
|
|
x1b8_frozenGenerator->SetGlobalScale(x4_scale);
|
|
|
|
break;
|
|
|
|
case EFrozenFxType::Frozen:
|
|
|
|
if (x204_frozenEffect == EFrozenFxType::Frozen)
|
|
|
|
break;
|
|
|
|
x1b8_frozenGenerator = std::make_unique<CElementGen>(x188_frozenEffects[0]);
|
|
|
|
x1b8_frozenGenerator->SetGlobalScale(x4_scale);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
x204_frozenEffect = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::ActivateCharge(bool enable, bool resetEffect) {
|
|
|
|
x1a4_muzzleGenerators[x208_muzzleEffectIdx]->SetParticleEmission(false);
|
|
|
|
x208_muzzleEffectIdx = u32(enable);
|
|
|
|
if (enable || resetEffect) {
|
|
|
|
x1a4_muzzleGenerators[x208_muzzleEffectIdx] =
|
|
|
|
std::make_unique<CElementGen>(x16c_muzzleEffects[x208_muzzleEffectIdx]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::Touch(const CStateManager& mgr) {
|
|
|
|
if (x10_solidModelData) {
|
|
|
|
x10_solidModelData->Touch(mgr, x20c_shaderIdx);
|
|
|
|
if (xb0_suitArmModelData)
|
|
|
|
xb0_suitArmModelData->Touch(mgr, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::TouchHolo(const CStateManager& mgr) {
|
|
|
|
if (x60_holoModelData)
|
|
|
|
x60_holoModelData->Touch(mgr, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::PointGenerator(void* ctx, const std::vector<std::pair<zeus::CVector3f, zeus::CVector3f>>& vn) {
|
2020-04-12 17:28:09 +00:00
|
|
|
static_cast<CRainSplashGenerator*>(ctx)->GeneratePoints(vn);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::Draw(bool drawSuitArm, const CStateManager& mgr, const zeus::CTransform& xf, const CModelFlags& flags,
|
2020-04-05 12:29:43 +00:00
|
|
|
const CActorLights* lights) {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!x218_26_loaded)
|
|
|
|
return;
|
|
|
|
|
|
|
|
zeus::CTransform armXf = xf * x10_solidModelData->GetScaledLocatorTransform("elbow");
|
|
|
|
|
|
|
|
if (x1bc_rainSplashGenerator && x1bc_rainSplashGenerator->IsRaining())
|
|
|
|
CSkinnedModel::SetPointGeneratorFunc(x1bc_rainSplashGenerator, PointGenerator);
|
|
|
|
|
|
|
|
if (mgr.GetThermalDrawFlag() == EThermalDrawFlag::Hot && x200_beamId != CPlayerState::EBeamId::Ice) {
|
|
|
|
/* Hot Draw */
|
2020-04-11 20:53:59 +00:00
|
|
|
const zeus::CColor mulColor(flags.x4_color.a(), flags.x4_color.a());
|
|
|
|
constexpr zeus::CColor addColor(0.25f, 0.25f);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x218_29_drawHologram) {
|
|
|
|
DrawHologram(mgr, xf, flags);
|
|
|
|
} else {
|
2020-04-11 20:53:59 +00:00
|
|
|
constexpr CModelFlags useFlags(0, 0, 3, zeus::skWhite);
|
2018-12-08 05:30:43 +00:00
|
|
|
x10_solidModelData->RenderThermal(xf, mulColor, addColor, useFlags);
|
2017-09-05 03:00:19 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (drawSuitArm && xb0_suitArmModelData) {
|
2020-04-11 20:53:59 +00:00
|
|
|
constexpr CModelFlags useFlags(0, 0, 3, zeus::skWhite);
|
2018-12-08 05:30:43 +00:00
|
|
|
xb0_suitArmModelData->RenderThermal(xf, mulColor, addColor, useFlags);
|
2017-09-05 03:00:19 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
/* Cold Draw */
|
|
|
|
if (mgr.GetPlayerState()->GetCurrentVisor() != CPlayerState::EPlayerVisor::XRay && !x218_29_drawHologram) {
|
|
|
|
CModelFlags useFlags = flags;
|
|
|
|
useFlags.x1_matSetIdx = u8(x20c_shaderIdx);
|
|
|
|
x10_solidModelData->Render(mgr, xf, lights, useFlags);
|
|
|
|
} else {
|
|
|
|
DrawHologram(mgr, xf, flags);
|
2017-09-05 03:00:19 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (drawSuitArm && xb0_suitArmModelData) {
|
|
|
|
xb0_suitArmModelData->Render(mgr, armXf, lights, flags);
|
2017-09-05 03:00:19 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (x1bc_rainSplashGenerator && x1bc_rainSplashGenerator->IsRaining()) {
|
|
|
|
CSkinnedModel::ClearPointGeneratorFunc();
|
|
|
|
x1bc_rainSplashGenerator->Draw(xf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::DrawMuzzleFx(const CStateManager& mgr) const {
|
2019-10-19 04:56:26 +00:00
|
|
|
if (CElementGen* const effect = x1a4_muzzleGenerators[x208_muzzleEffectIdx].get()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x200_beamId != CPlayerState::EBeamId::Ice &&
|
|
|
|
mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::XRay) {
|
|
|
|
CElementGen::SetSubtractBlend(true);
|
2019-10-19 04:56:26 +00:00
|
|
|
effect->Render();
|
2018-12-08 05:30:43 +00:00
|
|
|
CElementGen::SetSubtractBlend(false);
|
|
|
|
} else {
|
2019-10-19 04:56:26 +00:00
|
|
|
effect->Render();
|
2017-09-05 03:00:19 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-09-05 03:00:19 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CGunWeapon::LoadSuitArm(CStateManager& mgr) {
|
2019-10-19 04:06:25 +00:00
|
|
|
if (!x13c_armCharacter.IsLoaded()) {
|
|
|
|
return;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2019-10-19 04:06:25 +00:00
|
|
|
|
|
|
|
const CAssetId armId =
|
|
|
|
NWeaponTypes::get_asset_id_from_name(skSuitArmNames[size_t(NWeaponTypes::get_current_suit(mgr))]);
|
|
|
|
xb0_suitArmModelData.emplace(CStaticRes(armId, x4_scale));
|
|
|
|
xb0_suitArmModelData->SetSortThermal(true);
|
|
|
|
x218_28_suitArmLocked = false;
|
|
|
|
x13c_armCharacter.Unlock();
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::LoadGunModels(CStateManager& mgr) {
|
|
|
|
s32 defaultAnim = x218_27_subtypeBasePose ? 0 : 9;
|
|
|
|
x10_solidModelData.emplace(CAnimRes(x214_ancsId, 0, x4_scale, defaultAnim, false));
|
|
|
|
x60_holoModelData.emplace(CAnimRes(x214_ancsId, 1, x4_scale, defaultAnim, false));
|
|
|
|
CAnimPlaybackParms parms(defaultAnim, -1, 1.f, true);
|
2019-08-14 14:58:54 +00:00
|
|
|
x10_solidModelData->GetAnimationData()->SetAnimation(parms, true);
|
2018-12-08 05:30:43 +00:00
|
|
|
LoadSuitArm(mgr);
|
|
|
|
x10_solidModelData->SetSortThermal(true);
|
|
|
|
x60_holoModelData->SetSortThermal(true);
|
|
|
|
x100_gunController = std::make_unique<CGunController>(*x10_solidModelData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::LoadAnimations() {
|
|
|
|
NWeaponTypes::get_token_vector(*x10_solidModelData->GetAnimationData(), 0, 15, x10c_anims, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CGunWeapon::IsAnimsLoaded() const {
|
2019-10-19 04:49:22 +00:00
|
|
|
return std::all_of(x10c_anims.cbegin(), x10c_anims.cend(), [](const auto& anim) { return anim.IsLoaded(); });
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::LoadMuzzleFx(float dt) {
|
2019-10-19 04:06:25 +00:00
|
|
|
for (const auto& muzzleEffect : x16c_muzzleEffects) {
|
|
|
|
x1a4_muzzleGenerators.push_back(std::make_unique<CElementGen>(muzzleEffect));
|
2018-12-08 05:30:43 +00:00
|
|
|
x1a4_muzzleGenerators.back()->SetParticleEmission(false);
|
|
|
|
x1a4_muzzleGenerators.back()->Update(dt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::LoadProjectileData(CStateManager& mgr) {
|
|
|
|
CRandom16 random(mgr.GetUpdateFrameIndex());
|
|
|
|
CGlobalRandom grand(random);
|
2019-10-19 04:06:25 +00:00
|
|
|
|
|
|
|
for (const auto& weapon : x144_weapons) {
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f weaponVel;
|
2019-10-19 04:06:25 +00:00
|
|
|
if (const CVectorElement* ivec = weapon->x4_IVEC.get()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ivec->GetValue(0, weaponVel);
|
2019-10-19 04:06:25 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x1d0_velInfo.x0_vel.push_back(weaponVel);
|
|
|
|
float tratVal = 0.f;
|
2019-10-19 04:06:25 +00:00
|
|
|
if (const CRealElement* trat = weapon->x30_TRAT.get()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
trat->GetValue(0, tratVal);
|
2019-10-19 04:06:25 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x1d0_velInfo.x24_trat.push_back(tratVal);
|
2019-10-19 04:06:25 +00:00
|
|
|
x1d0_velInfo.x1c_targetHoming.push_back(weapon->x29_HOMG);
|
|
|
|
if (weaponVel.y() > 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x1d0_velInfo.x0_vel.back() *= zeus::CVector3f(60.f);
|
2019-10-19 04:06:25 +00:00
|
|
|
} else {
|
2019-02-24 07:15:54 +00:00
|
|
|
x1d0_velInfo.x0_vel.back() = zeus::skForward;
|
2019-10-19 04:06:25 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::LoadFxIdle(float dt, CStateManager& mgr) {
|
2019-10-19 04:49:22 +00:00
|
|
|
if (!NWeaponTypes::are_tokens_ready(x12c_deps)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-09-05 03:00:19 +00:00
|
|
|
|
2019-10-19 04:49:22 +00:00
|
|
|
if ((x210_loadFlags & 0x2) != 0 && (x210_loadFlags & 0x4) != 0 && (x210_loadFlags & 0x10) != 0) {
|
|
|
|
return;
|
|
|
|
}
|
2017-09-05 03:00:19 +00:00
|
|
|
|
2019-10-19 04:49:22 +00:00
|
|
|
const bool muzzlesLoaded = std::all_of(x16c_muzzleEffects.cbegin(), x16c_muzzleEffects.cend(),
|
|
|
|
[](const auto& muzzle) { return muzzle.IsLoaded(); });
|
|
|
|
if (!muzzlesLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2019-10-19 04:49:22 +00:00
|
|
|
const bool weaponsLoaded =
|
|
|
|
std::all_of(x144_weapons.cbegin(), x144_weapons.cend(), [](const auto& weapon) { return weapon.IsLoaded(); });
|
|
|
|
if (!weaponsLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool frozenLoaded = std::all_of(x188_frozenEffects.cbegin(), x188_frozenEffects.cend(),
|
|
|
|
[](const auto& effect) { return effect.IsLoaded(); });
|
|
|
|
if (!frozenLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!x160_xferEffect.IsLoaded()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((x210_loadFlags & 0x2) != 0x2) {
|
|
|
|
LoadMuzzleFx(dt);
|
|
|
|
x210_loadFlags |= 0x2;
|
|
|
|
}
|
|
|
|
x210_loadFlags |= 0x10;
|
|
|
|
if ((x210_loadFlags & 0x4) != 0x4) {
|
|
|
|
LoadProjectileData(mgr);
|
|
|
|
x210_loadFlags |= 0x4;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::Update(float dt, CStateManager& mgr) {
|
|
|
|
if (x218_26_loaded) {
|
|
|
|
x10_solidModelData->AdvanceAnimation(dt, mgr, kInvalidAreaId, true);
|
|
|
|
x100_gunController->Update(dt, mgr);
|
|
|
|
if (x218_28_suitArmLocked)
|
|
|
|
LoadSuitArm(mgr);
|
|
|
|
} else {
|
|
|
|
if (x104_gunCharacter) {
|
|
|
|
if (x104_gunCharacter.IsLoaded()) {
|
|
|
|
if ((x210_loadFlags & 0x1) != 0x1) {
|
|
|
|
LoadGunModels(mgr);
|
|
|
|
LoadAnimations();
|
|
|
|
x210_loadFlags |= 0x1;
|
2017-09-05 03:00:19 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if ((x210_loadFlags & 0x8) != 0x8) {
|
|
|
|
if (IsAnimsLoaded())
|
|
|
|
x210_loadFlags |= 0x8;
|
2017-09-05 03:00:19 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LoadFxIdle(dt, mgr);
|
|
|
|
if ((x210_loadFlags & 0x1f) == 0x1f) {
|
|
|
|
if (x10_solidModelData->PickAnimatedModel(CModelData::EWhichModel::Normal)
|
|
|
|
.GetModel()
|
|
|
|
->IsLoaded(x20c_shaderIdx) &&
|
|
|
|
xb0_suitArmModelData->IsLoaded(0))
|
|
|
|
x218_26_loaded = true;
|
|
|
|
}
|
2017-09-05 03:00:19 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::LockTokens(CStateManager& mgr) {
|
|
|
|
AsyncLoadSuitArm(mgr);
|
|
|
|
NWeaponTypes::lock_tokens(x12c_deps);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::UnlockTokens() {
|
|
|
|
x13c_armCharacter.Unlock();
|
|
|
|
NWeaponTypes::unlock_tokens(x12c_deps);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::Load(CStateManager& mgr, bool subtypeBasePose) {
|
|
|
|
LockTokens(mgr);
|
|
|
|
x218_27_subtypeBasePose = subtypeBasePose;
|
|
|
|
x204_frozenEffect = EFrozenFxType::None;
|
|
|
|
x1b8_frozenGenerator.reset();
|
|
|
|
x104_gunCharacter.Lock();
|
|
|
|
x160_xferEffect.Lock();
|
2019-10-19 04:06:25 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < x16c_muzzleEffects.size(); ++i) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x16c_muzzleEffects[i].Lock();
|
|
|
|
x144_weapons[i].Lock();
|
|
|
|
}
|
2019-10-19 04:06:25 +00:00
|
|
|
|
|
|
|
for (auto& frozenEffect : x188_frozenEffects) {
|
|
|
|
frozenEffect.Lock();
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::Unload(CStateManager& mgr) {
|
|
|
|
UnlockTokens();
|
|
|
|
x210_loadFlags = 0;
|
|
|
|
x204_frozenEffect = EFrozenFxType::None;
|
2019-06-12 02:05:17 +00:00
|
|
|
x10_solidModelData = std::nullopt;
|
|
|
|
x60_holoModelData = std::nullopt;
|
|
|
|
xb0_suitArmModelData = std::nullopt;
|
2018-12-08 05:30:43 +00:00
|
|
|
x100_gunController.reset();
|
|
|
|
x1bc_rainSplashGenerator = nullptr;
|
|
|
|
x1b8_frozenGenerator.reset();
|
|
|
|
FreeResPools();
|
|
|
|
x104_gunCharacter.Unlock();
|
|
|
|
x218_26_loaded = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CGunWeapon::IsLoaded() const { return x218_26_loaded; }
|
|
|
|
|
2020-04-05 12:29:43 +00:00
|
|
|
void CGunWeapon::DrawHologram(const CStateManager& mgr, const zeus::CTransform& xf, const CModelFlags& flags) {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!x218_26_loaded)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (x218_29_drawHologram) {
|
|
|
|
CModelFlags useFlags = flags;
|
|
|
|
useFlags.m_extendedShader = EExtendedShader::Flat;
|
|
|
|
x60_holoModelData->Render(CModelData::EWhichModel::Normal, xf, nullptr, useFlags);
|
|
|
|
} else {
|
|
|
|
CGraphics::SetModelMatrix(xf * zeus::CTransform::Scale(x10_solidModelData->GetScale()));
|
|
|
|
// CGraphics::DisableAllLights();
|
2019-02-24 07:15:54 +00:00
|
|
|
// g_Renderer->SetAmbientColor(zeus::skWhite);
|
2020-04-05 12:29:43 +00:00
|
|
|
CSkinnedModel& model = *x60_holoModelData->GetAnimationData()->GetModelData();
|
2019-02-24 07:15:54 +00:00
|
|
|
model.GetModelInst()->ActivateLights({CLight::BuildLocalAmbient({}, zeus::skWhite)});
|
2020-04-05 12:29:43 +00:00
|
|
|
x10_solidModelData->GetAnimationData()->Render(model, flags, std::nullopt, nullptr);
|
2019-02-24 07:15:54 +00:00
|
|
|
// g_Renderer->SetAmbientColor(zeus::skWhite);
|
2018-12-08 05:30:43 +00:00
|
|
|
// CGraphics::DisableAllLights();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::UpdateMuzzleFx(float dt, const zeus::CVector3f& scale, const zeus::CVector3f& pos, bool emitting) {
|
|
|
|
x1a4_muzzleGenerators[x208_muzzleEffectIdx]->SetGlobalTranslation(pos);
|
|
|
|
x1a4_muzzleGenerators[x208_muzzleEffectIdx]->SetGlobalScale(scale);
|
|
|
|
x1a4_muzzleGenerators[x208_muzzleEffectIdx]->SetParticleEmission(emitting);
|
|
|
|
x1a4_muzzleGenerators[x208_muzzleEffectIdx]->Update(dt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGunWeapon::ReturnToDefault(CStateManager& mgr) { x100_gunController->ReturnToDefault(mgr, 0.f, false); }
|
|
|
|
|
|
|
|
bool CGunWeapon::PlayPasAnim(SamusGun::EAnimationState state, CStateManager& mgr, float angle) {
|
|
|
|
switch (state) {
|
|
|
|
case SamusGun::EAnimationState::ComboFire:
|
|
|
|
x100_gunController->EnterComboFire(mgr, s32(x200_beamId));
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
case SamusGun::EAnimationState::Wander:
|
|
|
|
return true;
|
|
|
|
}
|
2017-09-05 03:00:19 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CGunWeapon::UnLoadFidget() { x100_gunController->UnLoadFidget(); }
|
2017-09-05 03:00:19 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CGunWeapon::IsFidgetLoaded() const { return x100_gunController->IsFidgetLoaded(); }
|
2017-09-05 03:00:19 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CGunWeapon::AsyncLoadFidget(CStateManager& mgr, SamusGun::EFidgetType type, s32 animSet) {
|
|
|
|
x100_gunController->LoadFidgetAnimAsync(mgr, s32(type), s32(x200_beamId), animSet);
|
2017-09-05 03:00:19 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CGunWeapon::EnterFidget(CStateManager& mgr, SamusGun::EFidgetType type, s32 parm2) {
|
|
|
|
x100_gunController->EnterFidget(mgr, s32(type), s32(x200_beamId), parm2);
|
2017-09-05 03:00:19 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CDamageInfo CGunWeapon::GetShotDamageInfo(const SShotParam& shotParam, CStateManager& mgr) {
|
|
|
|
CDamageInfo ret(shotParam);
|
|
|
|
if (g_GameState->GetHardMode())
|
|
|
|
ret.MultiplyDamage(g_GameState->GetHardModeWeaponMultiplier());
|
|
|
|
return ret;
|
2017-09-05 03:00:19 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CDamageInfo CGunWeapon::GetDamageInfo(CStateManager& mgr, EChargeState chargeState, float chargeFactor) const {
|
|
|
|
const SWeaponInfo& wInfo = GetWeaponInfo();
|
|
|
|
if (chargeState == EChargeState::Normal) {
|
|
|
|
return GetShotDamageInfo(wInfo.x4_normal, mgr);
|
|
|
|
} else {
|
|
|
|
SShotParam param = wInfo.x20_charged;
|
2022-02-19 13:04:45 +00:00
|
|
|
param.x8_damage *= chargeFactor;
|
|
|
|
param.xc_radiusDamage *= chargeFactor;
|
|
|
|
param.x10_radius *= chargeFactor;
|
|
|
|
param.x14_knockback *= chargeFactor;
|
|
|
|
param.x18_24_noImmunity = false;
|
2018-12-08 05:30:43 +00:00
|
|
|
return GetShotDamageInfo(param, mgr);
|
|
|
|
}
|
2017-08-26 04:36:25 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const SWeaponInfo& CGunWeapon::GetWeaponInfo() const { return g_tweakPlayerGun->GetBeamInfo(s32(x200_beamId)); }
|
2017-08-26 04:36:25 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CAABox CGunWeapon::GetBounds() const {
|
|
|
|
if (x10_solidModelData)
|
|
|
|
return x10_solidModelData->GetBounds();
|
2019-02-24 07:15:54 +00:00
|
|
|
return zeus::skNullBox;
|
2017-08-26 04:36:25 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CAABox CGunWeapon::GetBounds(const zeus::CTransform& xf) const {
|
|
|
|
if (x10_solidModelData)
|
|
|
|
return x10_solidModelData->GetBounds(xf);
|
2019-02-24 07:15:54 +00:00
|
|
|
return zeus::skNullBox;
|
2017-08-31 02:42:37 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CGunWeapon::IsChargeAnimOver() const {
|
|
|
|
return !(x218_25_enableCharge && x10_solidModelData->GetAnimationData()->IsAnimTimeRemaining(0.001f, "Whole Body"));
|
2017-09-02 04:06:05 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|