metaforce/Runtime/Weapon/CBeamProjectile.cpp

98 lines
3.9 KiB
C++
Raw Permalink Normal View History

#include "Runtime/Weapon/CBeamProjectile.hpp"
#include "Runtime/CStateManager.hpp"
#include "TCastTo.hpp" // Generated file, do not modify include path
2021-04-10 08:42:06 +00:00
namespace metaforce {
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,
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)
, 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
std::optional<zeus::CAABox> CBeamProjectile::GetTouchBounds() const {
if (!GetActive()) {
return std::nullopt;
}
2019-01-03 03:47:28 +00:00
if (x464_25_enableTouchDamage) {
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
}
return std::nullopt;
}
2019-01-03 03:47:28 +00:00
void CBeamProjectile::CalculateRenderBounds() { x9c_renderBounds = x354_.getTransformedAABox(x324_xf); }
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());
}
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},
2021-06-07 19:29:18 +00:00
zeus::CVector3f{x2f4_beamRadius, x300_intBeamLength, x2f4_beamRadius})
.getTransformedAABox(xf);
EntityList nearList;
2019-01-03 03:47:28 +00:00
mgr.BuildNearList(nearList, x36c_, CMaterialFilter::MakeExclude({EMaterialTypes::ProjectilePassthrough}), nullptr);
TUniqueId collideId = kInvalidUniqueId;
2021-06-07 19:29:18 +00:00
CRayCastResult res =
RayCollisionCheckWithWorld(collideId, x298_previousPos, beamEnd, x300_intBeamLength, nearList, mgr);
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