2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/Weapon/CEnergyProjectile.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CSimplePool.hpp"
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
#include "Runtime/Camera/CGameCamera.hpp"
|
|
|
|
#include "Runtime/Particle/CDecalManager.hpp"
|
|
|
|
#include "Runtime/World/CExplosion.hpp"
|
|
|
|
#include "Runtime/World/CGameLight.hpp"
|
|
|
|
#include "Runtime/World/CIceImpact.hpp"
|
|
|
|
#include "Runtime/World/CPlayer.hpp"
|
|
|
|
#include "Runtime/World/CScriptPlatform.hpp"
|
|
|
|
#include "Runtime/World/CWorld.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2017-06-12 04:23:34 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2017-06-12 04:23:34 +00:00
|
|
|
|
|
|
|
CEnergyProjectile::CEnergyProjectile(bool active, const TToken<CWeaponDescription>& desc, EWeaponType type,
|
2018-03-15 00:27:45 +00:00
|
|
|
const zeus::CTransform& xf, EMaterialTypes excludeMat, const CDamageInfo& damage,
|
2017-09-05 03:00:19 +00:00
|
|
|
TUniqueId uid, TAreaId aid, TUniqueId owner, TUniqueId homingTarget,
|
|
|
|
EProjectileAttrib attribs, bool underwater, const zeus::CVector3f& scale,
|
2020-04-11 04:49:02 +00:00
|
|
|
const std::optional<TLockedToken<CGenDescription>>& visorParticle, u16 visorSfx,
|
|
|
|
bool sendCollideMsg)
|
2020-09-26 13:41:50 +00:00
|
|
|
: CGameProjectile(active, desc, "GameProjectile"sv, type, xf, excludeMat, damage, uid, aid, owner, homingTarget, attribs,
|
2018-12-08 05:30:43 +00:00
|
|
|
underwater, scale, visorParticle, visorSfx, sendCollideMsg)
|
2020-04-11 04:49:02 +00:00
|
|
|
, x2ec_dir(xf.frontVector())
|
2018-12-08 05:30:43 +00:00
|
|
|
, x2f8_mag(x2ec_dir.magnitude())
|
2020-09-26 13:41:50 +00:00
|
|
|
, x2fc_camShake(CCameraShakeData::BuildProjectileCameraShake(0.5f, 0.75f)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
xe6_27_thermalVisorFlags = 2;
|
2017-06-12 04:23:34 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEnergyProjectile::PlayImpactSound(const zeus::CVector3f& pos, EWeaponCollisionResponseTypes type) {
|
2020-04-14 19:46:08 +00:00
|
|
|
const s32 sfxId = x170_projectile.GetSoundIdForCollision(type);
|
|
|
|
if (sfxId < 0) {
|
|
|
|
return;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-14 19:46:08 +00:00
|
|
|
|
|
|
|
CAudioSys::C3DEmitterParmData parmData = {};
|
|
|
|
parmData.x18_maxDist = x170_projectile.GetAudibleRange();
|
|
|
|
parmData.x1c_distComp = x170_projectile.GetAudibleFallOff();
|
|
|
|
parmData.x20_flags = 0x1; // Continuous parameter update
|
|
|
|
parmData.x24_sfxId = CSfxManager::TranslateSFXID(u16(sfxId));
|
|
|
|
parmData.x26_maxVol = 1.f;
|
|
|
|
parmData.x27_minVol = 0.16f;
|
|
|
|
parmData.x29_prio = 0x7f;
|
|
|
|
|
|
|
|
const CSfxHandle hnd = CSfxManager::AddEmitter(parmData, true, 0x7f, false, kInvalidAreaId);
|
|
|
|
if (!x2e4_26_waterUpdate) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSfxManager::PitchBend(hnd, -1.f);
|
2018-02-11 05:27:00 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEnergyProjectile::ChangeProjectileOwner(TUniqueId owner, CStateManager& mgr) {
|
2020-04-14 19:46:08 +00:00
|
|
|
const TCastToConstPtr<CActor> act = mgr.GetObjectById(owner);
|
|
|
|
if (!act) {
|
|
|
|
return;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-14 19:46:08 +00:00
|
|
|
|
|
|
|
const float rDam = g_tweakPlayerGun->GetRichochetDamage(u32(x110_origDamageInfo.GetWeaponMode().GetType()));
|
|
|
|
x110_origDamageInfo.MultiplyDamageAndRadius(rDam);
|
|
|
|
mgr.RemoveWeaponId(xec_ownerId, xf0_weaponType);
|
|
|
|
xec_ownerId = owner;
|
|
|
|
mgr.AddWeaponId(xec_ownerId, xf0_weaponType);
|
|
|
|
|
|
|
|
/* Can now damage Player */
|
|
|
|
xf8_filter.ExcludeList().Add(EMaterialTypes::Character);
|
|
|
|
xf8_filter.ExcludeList().Remove(EMaterialTypes::Player);
|
|
|
|
xf8_filter = CMaterialFilter::MakeIncludeExclude(xf8_filter.GetIncludeList(), xf8_filter.GetExcludeList());
|
2018-02-11 05:27:00 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEnergyProjectile::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) {
|
|
|
|
switch (msg) {
|
|
|
|
case EScriptObjectMessage::Deleted:
|
2020-04-14 19:46:08 +00:00
|
|
|
if (x2e4_24_active) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.RemoveWeaponId(xec_ownerId, xf0_weaponType);
|
2020-04-14 19:46:08 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x2e8_sfx) {
|
|
|
|
CSfxManager::RemoveEmitter(x2e8_sfx);
|
|
|
|
x2e8_sfx.reset();
|
2018-02-11 05:27:00 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Registered: {
|
2020-04-14 19:46:08 +00:00
|
|
|
if (CElementGen* ps1 = x170_projectile.GetAttachedPS1()) {
|
|
|
|
if (ps1->SystemHasLight()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CreateProjectileLight("ProjectileLight_GameProjectile", ps1->GetLight(), mgr);
|
2020-04-14 19:46:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const TLockedToken<CWeaponDescription> desc = x170_projectile.GetWeaponDescription();
|
|
|
|
const s32 sfx = desc->xa8_PJFX;
|
2018-12-08 05:30:43 +00:00
|
|
|
if (sfx != -1) {
|
|
|
|
float range = 50.f;
|
|
|
|
float falloff = 0.2f;
|
2020-04-14 19:46:08 +00:00
|
|
|
if (CRealElement* rnge = desc->xac_RNGE.get()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
rnge->GetValue(0, range);
|
2020-04-14 19:46:08 +00:00
|
|
|
}
|
|
|
|
if (CRealElement* foff = desc->xb0_FOFF.get()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
foff->GetValue(0, falloff);
|
2020-04-14 19:46:08 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
CAudioSys::C3DEmitterParmData parmData = {};
|
|
|
|
parmData.x0_pos = x170_projectile.GetTranslation();
|
|
|
|
parmData.xc_dir = x170_projectile.GetVelocity();
|
|
|
|
parmData.x18_maxDist = range;
|
|
|
|
parmData.x1c_distComp = falloff;
|
|
|
|
parmData.x20_flags = 0x9; // Continuous parameter update, doppler
|
|
|
|
parmData.x24_sfxId = CSfxManager::TranslateSFXID(sfx);
|
|
|
|
parmData.x26_maxVol = 1.f;
|
|
|
|
parmData.x27_minVol = 0.16f;
|
|
|
|
parmData.x29_prio = 0x7f;
|
|
|
|
x2e8_sfx = CSfxManager::AddEmitter(parmData, true, 0x7f, false, kInvalidAreaId);
|
2018-02-11 05:27:00 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.AddWeaponId(xec_ownerId, xf0_weaponType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
CGameProjectile::AcceptScriptMsg(msg, sender, mgr);
|
2018-02-11 05:27:00 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEnergyProjectile::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
2018-02-11 05:27:00 +00:00
|
|
|
|
|
|
|
/* Material surface types only (not meta flags) */
|
|
|
|
static constexpr u64 kCheckMaterial = 0xE3FFFE;
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEnergyProjectile::ResolveCollisionWithWorld(const CRayCastResult& res, CStateManager& mgr) {
|
2020-04-14 19:46:08 +00:00
|
|
|
const auto crType = CCollisionResponseData::GetWorldCollisionResponseType(
|
2018-12-08 05:30:43 +00:00
|
|
|
CMaterialList::BitPosition((res.GetMaterial().GetValue() & 0xffffffff) & kCheckMaterial));
|
2020-04-14 19:46:08 +00:00
|
|
|
|
|
|
|
if ((xe8_projectileAttribs & (EProjectileAttrib::Wave | EProjectileAttrib::ComboShot)) ==
|
2018-12-08 05:30:43 +00:00
|
|
|
(EProjectileAttrib::Wave | EProjectileAttrib::ComboShot)) {
|
2020-04-14 19:46:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not wavebuster
|
|
|
|
if (Explode(res.GetPoint(), res.GetPlane().normal(), crType, mgr, CDamageVulnerability::NormalVulnerabilty(),
|
|
|
|
kInvalidUniqueId)) {
|
|
|
|
mgr.ApplyDamageToWorld(xec_ownerId, *this, res.GetPoint(), x12c_curDamageInfo, xf8_filter);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-14 19:46:08 +00:00
|
|
|
|
|
|
|
x2c2_lastResolvedObj = kInvalidUniqueId;
|
2018-02-11 05:27:00 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEnergyProjectile::ResolveCollisionWithActor(const CRayCastResult& res, CActor& act, CStateManager& mgr) {
|
|
|
|
x2c2_lastResolvedObj = act.GetUniqueId();
|
2020-04-14 19:46:08 +00:00
|
|
|
const auto crType = act.GetCollisionResponseType(res.GetPoint(), x34_transform.basis[1].normalized(),
|
|
|
|
x12c_curDamageInfo.GetWeaponMode(), xe8_projectileAttribs);
|
2018-12-08 05:30:43 +00:00
|
|
|
act.Touch(*this, mgr);
|
|
|
|
const CDamageVulnerability* dVuln = act.GetDamageVulnerability();
|
|
|
|
if (!Explode(res.GetPoint(), res.GetPlane().normal(), crType, mgr, *dVuln, act.GetUniqueId())) {
|
|
|
|
mgr.SendScriptMsg(&act, GetUniqueId(), EScriptObjectMessage::Touched);
|
|
|
|
act.SendScriptMsgs(EScriptObjectState::ReflectedDamage, mgr, EScriptObjectMessage::None);
|
|
|
|
} else {
|
|
|
|
CGameProjectile::ResolveCollisionWithActor(res, act, mgr);
|
|
|
|
ApplyDamageToActors(mgr, x12c_curDamageInfo);
|
|
|
|
}
|
2020-04-14 19:46:08 +00:00
|
|
|
if (const TCastToPtr<CEnergyProjectile> proj = act) {
|
2020-09-26 14:38:22 +00:00
|
|
|
proj->SetHitProjectileOwner(xec_ownerId);
|
2018-12-08 05:30:43 +00:00
|
|
|
proj->Explode(GetTranslation(), x34_transform.basis[1], EWeaponCollisionResponseTypes::OtherProjectile, mgr,
|
|
|
|
*GetDamageVulnerability(), GetUniqueId());
|
|
|
|
}
|
2018-02-11 05:27:00 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEnergyProjectile::Think(float dt, CStateManager& mgr) {
|
|
|
|
CWeapon::Think(dt, mgr);
|
|
|
|
if (mgr.GetWorld()->GetCurrentAreaId() != GetAreaIdAlways() &&
|
2020-04-14 19:46:08 +00:00
|
|
|
(xe8_projectileAttribs & EProjectileAttrib::ArmCannon) == EProjectileAttrib::ArmCannon) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.SetActorAreaId(*this, mgr.GetWorld()->GetCurrentAreaId());
|
2020-04-14 19:46:08 +00:00
|
|
|
}
|
2018-02-12 05:30:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdateProjectileMovement(dt, mgr);
|
|
|
|
TUniqueId id = kInvalidUniqueId;
|
2020-04-14 19:46:08 +00:00
|
|
|
const CRayCastResult res = DoCollisionCheck(id, mgr);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (res.IsValid()) {
|
2020-04-14 19:46:08 +00:00
|
|
|
if (const TCastToPtr<CActor> act = mgr.ObjectById(id)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ResolveCollisionWithActor(res, *act, mgr);
|
2020-04-14 19:46:08 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
ResolveCollisionWithWorld(res, mgr);
|
2020-04-14 19:46:08 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-02-12 05:30:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x170_projectile.UpdateParticleFX();
|
2020-04-14 19:46:08 +00:00
|
|
|
if (x2e4_24_active && x3d0_26_) {
|
2019-02-24 07:15:54 +00:00
|
|
|
Explode(GetTranslation(), zeus::skUp, EWeaponCollisionResponseTypes::Default, mgr,
|
2018-12-08 05:30:43 +00:00
|
|
|
CDamageVulnerability::NormalVulnerabilty(), kInvalidUniqueId);
|
2020-04-14 19:46:08 +00:00
|
|
|
}
|
2018-02-12 05:30:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x2c8_projectileLight != kInvalidUniqueId) {
|
2020-04-14 19:46:08 +00:00
|
|
|
if (const TCastToPtr<CGameLight> light = mgr.ObjectById(x2c8_projectileLight)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
light->SetTransform(GetTransform());
|
|
|
|
light->SetTranslation(GetTranslation());
|
2020-04-14 19:46:08 +00:00
|
|
|
if (CElementGen* ps1 = x170_projectile.GetAttachedPS1()) {
|
|
|
|
if (ps1->SystemHasLight()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
light->SetLight(ps1->GetLight());
|
2020-04-14 19:46:08 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-12 05:30:21 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-02-11 05:27:00 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x2e8_sfx) {
|
|
|
|
CSfxManager::UpdateEmitter(x2e8_sfx, x170_projectile.GetTranslation(), x170_projectile.GetVelocity(), 1.f);
|
|
|
|
CSfxManager::PitchBend(x2e8_sfx, x2e4_26_waterUpdate ? -1.f : 0.f);
|
|
|
|
}
|
2018-02-12 05:30:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x3d4_curTime += dt;
|
2020-04-14 19:46:08 +00:00
|
|
|
if (x3d4_curTime > 45.f || x170_projectile.IsSystemDeletable() || x3d0_24_dead) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.FreeScriptObject(GetUniqueId());
|
2020-04-14 19:46:08 +00:00
|
|
|
}
|
2018-02-11 05:27:00 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 17:28:20 +00:00
|
|
|
void CEnergyProjectile::Render(CStateManager& mgr) {
|
2020-04-11 22:51:39 +00:00
|
|
|
SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CEnergyProjectile::Render WPSC_{}"), x2cc_wpscId).c_str(), zeus::skOrange);
|
2019-07-21 08:42:52 +00:00
|
|
|
|
2020-04-14 19:46:08 +00:00
|
|
|
const auto visor = mgr.GetPlayerState()->GetActiveVisor(mgr);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (visor == CPlayerState::EPlayerVisor::Combat) {
|
|
|
|
if ((xe8_projectileAttribs & EProjectileAttrib::Charged) == EProjectileAttrib::Charged ||
|
|
|
|
(xe8_projectileAttribs & EProjectileAttrib::ComboShot) == EProjectileAttrib::ComboShot) {
|
2020-04-14 19:46:08 +00:00
|
|
|
const float warpTime = 1.f - float(x170_projectile.GameTime());
|
|
|
|
if (warpTime > 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.DrawSpaceWarp(GetTranslation(), warpTime * 0.75f);
|
2020-04-14 19:46:08 +00:00
|
|
|
}
|
2018-02-12 05:30:21 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-02-11 05:27:00 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (visor == CPlayerState::EPlayerVisor::XRay) {
|
|
|
|
CElementGen::SetSubtractBlend((xe8_projectileAttribs & EProjectileAttrib::Ice) != EProjectileAttrib::Ice);
|
2019-02-24 07:15:54 +00:00
|
|
|
CGraphics::SetFog(ERglFogMode::PerspLin, 0.f, 75.f, zeus::skBlack);
|
2018-12-08 05:30:43 +00:00
|
|
|
x170_projectile.RenderParticles();
|
|
|
|
CGameProjectile::Render(mgr);
|
|
|
|
mgr.SetupFogForArea(GetAreaIdAlways());
|
|
|
|
CElementGen::SetSubtractBlend(false);
|
|
|
|
} else if ((xe8_projectileAttribs & EProjectileAttrib::Ice) == EProjectileAttrib::Ice &&
|
|
|
|
mgr.GetThermalDrawFlag() == EThermalDrawFlag::Hot) {
|
|
|
|
CElementGen::SetSubtractBlend(true);
|
|
|
|
x170_projectile.RenderParticles();
|
|
|
|
CGameProjectile::Render(mgr);
|
|
|
|
mgr.SetupFogForArea(GetAreaIdAlways());
|
|
|
|
CElementGen::SetSubtractBlend(false);
|
|
|
|
} else {
|
|
|
|
CGameProjectile::Render(mgr);
|
|
|
|
}
|
2018-02-11 05:27:00 +00:00
|
|
|
}
|
|
|
|
|
2020-04-05 11:54:02 +00:00
|
|
|
void CEnergyProjectile::AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mgr) {
|
2020-04-14 19:46:08 +00:00
|
|
|
const auto bounds = x170_projectile.GetBounds();
|
|
|
|
if (bounds && !frustum.aabbFrustumTest(*bounds)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-04-14 19:46:08 +00:00
|
|
|
}
|
2018-02-11 05:27:00 +00:00
|
|
|
|
2020-04-14 19:46:08 +00:00
|
|
|
const auto visor = mgr.GetPlayerState()->GetActiveVisor(mgr);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (visor != CPlayerState::EPlayerVisor::XRay &&
|
|
|
|
((xe8_projectileAttribs & EProjectileAttrib::Ice) != EProjectileAttrib::Ice ||
|
2020-04-05 11:54:02 +00:00
|
|
|
mgr.GetThermalDrawFlag() != EThermalDrawFlag::Hot)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x170_projectile.AddToRenderer();
|
2020-04-05 11:54:02 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
EnsureRendered(mgr);
|
2018-02-11 05:27:00 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEnergyProjectile::Touch(CActor& act, CStateManager& mgr) {
|
|
|
|
// Empty
|
2018-02-11 05:27:00 +00:00
|
|
|
}
|
|
|
|
|
2018-02-12 05:30:21 +00:00
|
|
|
bool CEnergyProjectile::Explode(const zeus::CVector3f& pos, const zeus::CVector3f& normal,
|
2018-02-11 05:27:00 +00:00
|
|
|
EWeaponCollisionResponseTypes type, CStateManager& mgr,
|
2018-12-08 05:30:43 +00:00
|
|
|
const CDamageVulnerability& dVuln, TUniqueId hitActor) {
|
|
|
|
zeus::CVector3f offsetPos = pos + normal * 0.01f;
|
|
|
|
bool done = true;
|
|
|
|
bool retargetPlayer = false;
|
|
|
|
bool deflect = false;
|
|
|
|
zeus::CVector3f targetPos;
|
2020-04-14 19:46:08 +00:00
|
|
|
const EVulnerability vulnType = dVuln.GetVulnerability(x12c_curDamageInfo.GetWeaponMode(), false);
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (vulnType == EVulnerability::Deflect) {
|
|
|
|
deflect = true;
|
2019-07-16 15:54:07 +00:00
|
|
|
EDeflectType deflectType = dVuln.GetDeflectionType(x12c_curDamageInfo.GetWeaponMode());
|
2018-12-08 05:30:43 +00:00
|
|
|
switch (deflectType) {
|
2019-07-16 15:54:07 +00:00
|
|
|
case EDeflectType::None:
|
2018-12-08 05:30:43 +00:00
|
|
|
deflect = false;
|
|
|
|
break;
|
2019-07-16 15:54:07 +00:00
|
|
|
case EDeflectType::Two:
|
|
|
|
case EDeflectType::Three:
|
|
|
|
if (deflectType != EDeflectType::Two ||
|
2018-12-08 05:30:43 +00:00
|
|
|
(xf0_weaponType != EWeaponType::Missile &&
|
2020-04-14 19:46:08 +00:00
|
|
|
(xe8_projectileAttribs & EProjectileAttrib::ComboShot) != EProjectileAttrib::ComboShot)) {
|
|
|
|
if (xf8_filter.GetExcludeList().HasMaterial(EMaterialTypes::Player)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
retargetPlayer = true;
|
2020-04-14 19:46:08 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2018-02-12 05:30:21 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (retargetPlayer) {
|
2020-04-14 19:46:08 +00:00
|
|
|
const float ang = mgr.GetActiveRandom()->Range(0.f, 2.f * M_PIF);
|
|
|
|
const float y = std::sin(ang);
|
|
|
|
const float x = std::cos(ang);
|
2018-12-08 05:30:43 +00:00
|
|
|
targetPos = mgr.GetPlayer().GetAimPosition(mgr, 0.f) + zeus::CVector3f(x, 0.f, y);
|
|
|
|
ChangeProjectileOwner(hitActor, mgr);
|
2018-02-12 05:30:21 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-02-12 05:30:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (vulnType != EVulnerability::Immune && !deflect) {
|
|
|
|
deflect =
|
|
|
|
(type == EWeaponCollisionResponseTypes::Unknown15 || type == EWeaponCollisionResponseTypes::EnemyShielded ||
|
2020-04-14 19:46:08 +00:00
|
|
|
(type >= EWeaponCollisionResponseTypes::Unknown69 &&
|
|
|
|
type <= EWeaponCollisionResponseTypes::AtomicAlphaReflect));
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-02-12 05:30:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
SetTranslation(offsetPos);
|
|
|
|
|
|
|
|
if (deflect) {
|
|
|
|
done = false;
|
|
|
|
x2c0_homingTargetId = kInvalidUniqueId;
|
|
|
|
x3d0_25_ = false;
|
|
|
|
} else {
|
|
|
|
StopProjectile(mgr);
|
|
|
|
if (x3d0_27_camShakeDirty) {
|
|
|
|
x2fc_camShake.SetSfxPositionAndDistance(pos, 50.f);
|
|
|
|
mgr.GetCameraManager()->AddCameraShaker(x2fc_camShake, false);
|
2018-02-12 05:30:21 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-02-12 05:30:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
PlayImpactSound(pos, type);
|
|
|
|
mgr.InformListeners(pos, EListenNoiseType::ProjectileExplode);
|
|
|
|
if (auto particle = x170_projectile.CollisionOccured(type, !done, retargetPlayer, offsetPos, normal, targetPos)) {
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CTransform particleXf = zeus::lookAt(zeus::skZero3f, normal);
|
2018-12-08 05:30:43 +00:00
|
|
|
particleXf.origin = offsetPos;
|
|
|
|
if (xf0_weaponType != EWeaponType::Power || !xf8_filter.GetExcludeList().HasMaterial(EMaterialTypes::Player) ||
|
|
|
|
!x2e4_27_inWater) {
|
|
|
|
if (auto decal = x170_projectile.GetDecalForCollision(type)) {
|
|
|
|
CDecalManager::AddDecal(*decal, particleXf,
|
|
|
|
(xe8_projectileAttribs & EProjectileAttrib::Ice) != EProjectileAttrib::Ice, mgr);
|
|
|
|
}
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CVector3f scale = zeus::skOne3f;
|
2018-12-08 05:30:43 +00:00
|
|
|
bool camClose = false;
|
|
|
|
if (mgr.GetPlayer().GetCameraState() == CPlayer::EPlayerCameraState::FirstPerson) {
|
2020-04-14 19:46:08 +00:00
|
|
|
const float mag = (offsetPos - mgr.GetCameraManager()->GetCurrentCamera(mgr)->GetTranslation()).magnitude();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (mag < 4.f) {
|
|
|
|
scale = zeus::CVector3f(0.75f * (mag * 0.25f) + 0.25f);
|
|
|
|
camClose = true;
|
2018-02-12 05:30:21 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
u32 explodeFlags = 0x8;
|
2020-04-14 19:46:08 +00:00
|
|
|
if ((xe8_projectileAttribs & EProjectileAttrib::Ice) == EProjectileAttrib::Ice) {
|
2018-12-08 05:30:43 +00:00
|
|
|
explodeFlags |= 0x4;
|
2020-04-14 19:46:08 +00:00
|
|
|
}
|
|
|
|
if (camClose) {
|
2018-12-08 05:30:43 +00:00
|
|
|
explodeFlags |= 0x2;
|
2020-04-14 19:46:08 +00:00
|
|
|
}
|
|
|
|
const CEntityInfo explosionInfo(GetAreaIdAlways(), CEntity::NullConnectionList);
|
|
|
|
auto* explosion = new CExplosion(*particle, mgr.AllocateUniqueId(), true, explosionInfo,
|
|
|
|
"Projectile collision response", particleXf, explodeFlags, scale, zeus::skWhite);
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.AddObject(explosion);
|
2020-04-14 19:46:08 +00:00
|
|
|
if (const TCastToPtr<CActor> hActor = mgr.ObjectById(hitActor)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bool validPlat = false;
|
|
|
|
CScriptPlatform* plat = TCastToPtr<CScriptPlatform>(hActor.GetPtr()).GetPtr();
|
|
|
|
validPlat = plat != nullptr;
|
|
|
|
if (!validPlat && hActor->GetMaterialList().HasMaterial(EMaterialTypes::Bomb)) {
|
|
|
|
for (CEntity* ent : mgr.GetPlatformAndDoorObjectList()) {
|
2020-04-14 19:46:08 +00:00
|
|
|
if (const TCastToPtr<CScriptPlatform> otherPlat = ent) {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (otherPlat->IsSlave(hitActor)) {
|
|
|
|
plat = otherPlat.GetPtr();
|
|
|
|
validPlat = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-12 05:30:21 +00:00
|
|
|
}
|
2020-04-14 19:46:08 +00:00
|
|
|
if (validPlat) {
|
2018-12-08 05:30:43 +00:00
|
|
|
plat->AddSlave(explosion->GetUniqueId(), mgr);
|
2020-04-14 19:46:08 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
x3d0_24_dead = true;
|
|
|
|
}
|
2018-02-12 05:30:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if ((xe8_projectileAttribs & (EProjectileAttrib::ComboShot | EProjectileAttrib::Ice)) ==
|
|
|
|
(EProjectileAttrib::ComboShot | EProjectileAttrib::Ice)) {
|
2020-04-14 19:46:08 +00:00
|
|
|
// Ice Spreader
|
|
|
|
const TLockedToken<CGenDescription> iceSpreadParticle = g_SimplePool->GetObj("IceSpread1");
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
u32 flags = (xe6_27_thermalVisorFlags & 0x2) == 0 ? 1 : 0;
|
|
|
|
flags |= 0x2;
|
2020-04-14 19:46:08 +00:00
|
|
|
|
|
|
|
auto* iceImpact = new CIceImpact(iceSpreadParticle, mgr.AllocateUniqueId(), GetAreaIdAlways(), true,
|
|
|
|
"Ice spread explosion", particleXf, flags, zeus::skOne3f, zeus::skWhite);
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.AddObject(iceImpact);
|
2018-02-12 05:30:21 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-02-12 05:30:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return done;
|
2018-02-11 05:27:00 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEnergyProjectile::StopProjectile(CStateManager& mgr) {
|
|
|
|
DeleteProjectileLight(mgr);
|
|
|
|
mgr.RemoveWeaponId(xec_ownerId, xf0_weaponType);
|
|
|
|
x2e4_24_active = false;
|
|
|
|
x68_material = CMaterialList();
|
|
|
|
mgr.UpdateActorInSortedLists(*this);
|
|
|
|
if (x2e8_sfx) {
|
|
|
|
CSfxManager::RemoveEmitter(x2e8_sfx);
|
|
|
|
x2e8_sfx.reset();
|
|
|
|
}
|
2018-02-11 05:27:00 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|