2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/Weapon/CBeamProjectile.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2016-12-22 19:57:21 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2016-12-22 19:57:21 +00:00
|
|
|
|
2017-11-13 06:19:18 +00:00
|
|
|
CBeamProjectile::CBeamProjectile(const TToken<CWeaponDescription>& wDesc, std::string_view name, EWeaponType wType,
|
2019-01-03 03:47:28 +00:00
|
|
|
const zeus::CTransform& xf, s32 maxLength, float beamRadius, float travelSpeed,
|
|
|
|
EMaterialTypes matType, const CDamageInfo& dInfo, TUniqueId uid, TAreaId aid,
|
|
|
|
TUniqueId owner, EProjectileAttrib attribs, bool growingBeam)
|
2017-09-05 03:00:19 +00:00
|
|
|
: CGameProjectile(false, wDesc, name, wType, xf, matType, dInfo, uid, aid, owner, kInvalidUniqueId, attribs, false,
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::skOne3f, {}, 0xffff, false)
|
2019-01-03 03:47:28 +00:00
|
|
|
, x2e8_intMaxLength(std::abs(maxLength))
|
|
|
|
, x2ec_maxLength(x2e8_intMaxLength)
|
|
|
|
, x2f0_invMaxLength(1.f / x2ec_maxLength)
|
|
|
|
, x2f4_beamRadius(beamRadius)
|
|
|
|
, x300_intBeamLength(growingBeam ? 0.f : x2ec_maxLength)
|
|
|
|
, x304_beamLength(x2ec_maxLength)
|
|
|
|
, x308_travelSpeed(travelSpeed)
|
2020-04-20 04:57:50 +00:00
|
|
|
, x464_24_growingBeam(growingBeam) {
|
2019-01-03 03:47:28 +00:00
|
|
|
x384_.resize(10);
|
|
|
|
x400_pointCache.resize(8);
|
|
|
|
}
|
2018-09-16 23:22:35 +00:00
|
|
|
|
2019-06-12 02:05:17 +00:00
|
|
|
std::optional<zeus::CAABox> CBeamProjectile::GetTouchBounds() const {
|
2020-03-21 05:46:56 +00:00
|
|
|
if (!GetActive()) {
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
2019-01-03 03:47:28 +00:00
|
|
|
if (x464_25_enableTouchDamage) {
|
2020-03-21 05:46:56 +00:00
|
|
|
const zeus::CVector3f pos = GetTranslation();
|
2019-01-03 03:47:28 +00:00
|
|
|
return {{pos - 0.1f, pos + 0.1f}};
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-03-21 05:46:56 +00:00
|
|
|
|
|
|
|
return std::nullopt;
|
2016-12-22 19:57:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 03:47:28 +00:00
|
|
|
void CBeamProjectile::CalculateRenderBounds() { x9c_renderBounds = x354_.getTransformedAABox(x324_xf); }
|
2016-12-22 19:57:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CBeamProjectile::ResetBeam(CStateManager&, bool) {
|
2019-01-03 03:47:28 +00:00
|
|
|
if (x464_24_growingBeam)
|
|
|
|
x300_intBeamLength = 0.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBeamProjectile::SetCollisionResultData(EDamageType dType, CRayCastResult& res, TUniqueId id) {
|
|
|
|
x2f8_damageType = dType;
|
|
|
|
x304_beamLength = res.GetT();
|
|
|
|
x318_collisionPoint = res.GetPoint();
|
|
|
|
x30c_collisionNormal = res.GetPlane().normal();
|
|
|
|
x2fe_collisionActorId = dType == EDamageType::Actor ? id : kInvalidUniqueId;
|
|
|
|
SetTranslation(res.GetPoint());
|
2016-12-22 19:57:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 03:47:28 +00:00
|
|
|
void CBeamProjectile::UpdateFx(const zeus::CTransform& xf, float dt, CStateManager& mgr) {
|
|
|
|
if (!GetActive())
|
|
|
|
return;
|
|
|
|
|
|
|
|
SetTransform(xf.getRotation());
|
|
|
|
if (x464_24_growingBeam) {
|
|
|
|
x300_intBeamLength += x308_travelSpeed * dt;
|
|
|
|
if (x300_intBeamLength > x2ec_maxLength)
|
|
|
|
x300_intBeamLength = x2ec_maxLength;
|
|
|
|
}
|
|
|
|
x304_beamLength = x300_intBeamLength;
|
|
|
|
x2f8_damageType = EDamageType::None;
|
|
|
|
x298_previousPos = xf.origin;
|
|
|
|
zeus::CVector3f beamEnd = xf.basis[1].normalized() * x300_intBeamLength + xf.origin;
|
|
|
|
SetTranslation(beamEnd);
|
|
|
|
x354_ = zeus::CAABox(zeus::CVector3f{-x2f4_beamRadius, 0.f, -x2f4_beamRadius},
|
|
|
|
zeus::CVector3f{x2f4_beamRadius, x304_beamLength, x2f4_beamRadius});
|
|
|
|
x36c_ = zeus::CAABox(zeus::CVector3f{-x2f4_beamRadius, 0.f, -x2f4_beamRadius},
|
|
|
|
zeus::CVector3f{x2f4_beamRadius, x300_intBeamLength, x2f4_beamRadius}).getTransformedAABox(xf);
|
|
|
|
rstl::reserved_vector<TUniqueId, 1024> nearList;
|
|
|
|
mgr.BuildNearList(nearList, x36c_, CMaterialFilter::MakeExclude({EMaterialTypes::ProjectilePassthrough}), nullptr);
|
|
|
|
TUniqueId collideId = kInvalidUniqueId;
|
|
|
|
CRayCastResult res = RayCollisionCheckWithWorld(collideId, x298_previousPos, beamEnd, x300_intBeamLength, nearList, mgr);
|
2020-05-10 02:27:54 +00:00
|
|
|
if (TCastToConstPtr<CActor>(mgr.ObjectById(collideId))) {
|
2019-01-03 03:47:28 +00:00
|
|
|
SetCollisionResultData(EDamageType::Actor, res, collideId);
|
|
|
|
if (x464_25_enableTouchDamage)
|
|
|
|
ApplyDamageToActors(mgr, CDamageInfo(x12c_curDamageInfo, dt));
|
|
|
|
} else if (res.IsValid()) {
|
|
|
|
SetCollisionResultData(EDamageType::World, res, kInvalidUniqueId);
|
|
|
|
if (x464_25_enableTouchDamage)
|
|
|
|
mgr.ApplyDamageToWorld(xec_ownerId, *this, res.GetPoint(), CDamageInfo(x12c_curDamageInfo, dt), xf8_filter);
|
|
|
|
} else {
|
|
|
|
x318_collisionPoint = xf * zeus::CVector3f(x2f4_beamRadius, x304_beamLength, x2f4_beamRadius);
|
|
|
|
SetTranslation(x318_collisionPoint);
|
|
|
|
}
|
|
|
|
x324_xf = xf;
|
|
|
|
}
|
2017-01-15 03:59:37 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
void CBeamProjectile::Accept(metaforce::IVisitor& visitor) { visitor.Visit(this); }
|
2017-01-15 03:59:37 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|