2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/Weapon/CTargetableProjectile.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/World/CPlayer.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2018-02-11 05:27:00 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2018-02-11 05:27:00 +00:00
|
|
|
|
|
|
|
CTargetableProjectile::CTargetableProjectile(
|
2018-12-08 05:30:43 +00:00
|
|
|
const TToken<CWeaponDescription>& desc, EWeaponType type, const zeus::CTransform& xf, EMaterialTypes materials,
|
|
|
|
const CDamageInfo& damage, const CDamageInfo& damage2, TUniqueId uid, TAreaId aid, TUniqueId owner,
|
2019-03-24 05:45:47 +00:00
|
|
|
const TLockedToken<CWeaponDescription>& weapDesc, TUniqueId homingTarget, EProjectileAttrib attribs,
|
2019-06-12 02:05:17 +00:00
|
|
|
const std::optional<TLockedToken<CGenDescription>>& visorParticle, u16 visorSfx, bool sendCollideMsg)
|
2018-02-11 05:27:00 +00:00
|
|
|
: CEnergyProjectile(true, desc, type, xf, materials, damage, uid, aid, owner, homingTarget,
|
|
|
|
attribs | EProjectileAttrib::BigProjectile | EProjectileAttrib::PartialCharge |
|
2018-12-08 05:30:43 +00:00
|
|
|
EProjectileAttrib::PlasmaProjectile,
|
2019-02-24 07:15:54 +00:00
|
|
|
false, zeus::skOne3f, visorParticle, visorSfx, sendCollideMsg)
|
2019-03-24 05:45:47 +00:00
|
|
|
, x3d8_weaponDesc(weapDesc)
|
|
|
|
, x3e0_damage(damage2) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x68_material.Add(EMaterialTypes::Target);
|
|
|
|
x68_material.Add(EMaterialTypes::Orbit);
|
2018-02-11 05:27:00 +00:00
|
|
|
}
|
|
|
|
|
2019-03-24 05:45:47 +00:00
|
|
|
void CTargetableProjectile::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
|
|
|
|
|
|
|
zeus::CVector3f CTargetableProjectile::GetAimPosition(const CStateManager& mgr, float dt) const {
|
|
|
|
static constexpr float tickRecip = 1.f / CProjectileWeapon::GetTickPeriod();
|
|
|
|
return (dt * dt * 0.5f * tickRecip * x170_projectile.GetGravity()) +
|
|
|
|
(dt * tickRecip * x170_projectile.GetVelocity() + GetTranslation());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CTargetableProjectile::Explode(const zeus::CVector3f& pos, const zeus::CVector3f& normal,
|
|
|
|
EWeaponCollisionResponseTypes type, CStateManager& mgr,
|
|
|
|
const CDamageVulnerability& dVuln, TUniqueId hitActor) {
|
|
|
|
bool ret = CEnergyProjectile::Explode(pos, normal, type, mgr, dVuln, hitActor);
|
|
|
|
|
2020-09-26 14:38:22 +00:00
|
|
|
if (x2e4_24_active || x2c4_hitProjectileOwner == kInvalidUniqueId ||
|
|
|
|
x2c4_hitProjectileOwner != mgr.GetPlayer().GetUniqueId()) {
|
2019-03-24 05:45:47 +00:00
|
|
|
return ret;
|
2020-09-25 18:14:24 +00:00
|
|
|
}
|
2019-03-24 05:45:47 +00:00
|
|
|
|
|
|
|
if (TCastToConstPtr<CActor> act = mgr.GetObjectById(xec_ownerId)) {
|
|
|
|
TUniqueId uid = mgr.AllocateUniqueId();
|
2020-09-25 18:14:24 +00:00
|
|
|
zeus::CTransform xf = zeus::lookAt(x170_projectile.GetTranslation(), act->GetAimPosition(mgr, 0.f), zeus::skUp);
|
|
|
|
auto* projectile = new CEnergyProjectile(true, x3d8_weaponDesc, xf0_weaponType, xf, EMaterialTypes::Player,
|
2020-09-26 14:38:22 +00:00
|
|
|
x3e0_damage, uid, GetAreaIdAlways(), x2c4_hitProjectileOwner, xec_ownerId,
|
2020-09-25 18:14:24 +00:00
|
|
|
EProjectileAttrib::None, false, zeus::skOne3f, {}, 0xFFFF, false);
|
2019-03-24 05:45:47 +00:00
|
|
|
mgr.AddObject(projectile);
|
|
|
|
projectile->AddMaterial(EMaterialTypes::Orbit);
|
|
|
|
mgr.GetPlayer().ResetAimTargetPrediction(uid);
|
|
|
|
mgr.GetPlayer().SetOrbitTargetId(uid, mgr);
|
2020-09-26 14:38:22 +00:00
|
|
|
x2c4_hitProjectileOwner = kInvalidUniqueId;
|
2019-03-24 05:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-09-25 18:14:24 +00:00
|
|
|
void CTargetableProjectile::ResolveCollisionWithActor(const CRayCastResult& res, CActor& act, CStateManager& mgr) {
|
2022-11-11 02:25:18 +00:00
|
|
|
zeus::CTransform xf = zeus::lookAt(GetTranslation(), GetAimPosition(mgr, 0.1f));
|
|
|
|
xf.origin = GetTranslation();
|
|
|
|
SetTransform(xf);
|
2020-09-25 18:14:24 +00:00
|
|
|
CEnergyProjectile::ResolveCollisionWithActor(res, act, mgr);
|
|
|
|
}
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|