2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CScriptCoverPoint.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/World/CActorParameters.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2016-04-25 05:46:28 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2018-12-08 05:30:43 +00:00
|
|
|
CScriptCoverPoint::CScriptCoverPoint(TUniqueId uid, std::string_view name, const CEntityInfo& info, zeus::CTransform xf,
|
|
|
|
bool active, u32 flags, bool crouch, float horizontalAngle, float verticalAngle,
|
|
|
|
float coverTime)
|
|
|
|
: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(EMaterialTypes::NoStepLogic),
|
|
|
|
CActorParameters::None(), kInvalidUniqueId)
|
2020-04-11 05:50:10 +00:00
|
|
|
, xe8_26_landHere((flags & 0x20) != 0u)
|
|
|
|
, xe8_27_wallHang((flags & 0x10) != 0u)
|
|
|
|
, xe8_28_stay((flags & 0x8) != 0u)
|
2020-04-11 06:02:28 +00:00
|
|
|
, xe8_29_((flags & 0x4) != 0u)
|
|
|
|
, xe8_30_attackDirection((flags & 0x2) != 0u)
|
2020-04-11 05:50:10 +00:00
|
|
|
, xf4_coverTime(coverTime)
|
2020-04-20 04:57:50 +00:00
|
|
|
, xf8_24_crouch(crouch) {
|
2018-12-08 05:30:43 +00:00
|
|
|
xec_cosHorizontalAngle = std::cos(zeus::degToRad(horizontalAngle) * 0.5f);
|
|
|
|
xf0_sinVerticalAngle = std::sin(zeus::degToRad(verticalAngle) * 0.5f);
|
|
|
|
x100_touchBounds.emplace(xf.origin, xf.origin);
|
2016-04-25 05:46:28 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptCoverPoint::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptCoverPoint::Think(float delta, CStateManager&) {
|
|
|
|
if (x11c_timeLeft <= 0.f)
|
|
|
|
return;
|
|
|
|
x11c_timeLeft -= delta;
|
2016-04-25 05:46:28 +00:00
|
|
|
}
|
|
|
|
|
2019-06-12 02:05:17 +00:00
|
|
|
std::optional<zeus::CAABox> CScriptCoverPoint::GetTouchBounds() const {
|
2020-02-01 03:28:25 +00:00
|
|
|
if (x100_touchBounds) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return x100_touchBounds;
|
2020-02-01 03:28:25 +00:00
|
|
|
}
|
2016-04-25 05:46:28 +00:00
|
|
|
|
2020-02-01 03:28:25 +00:00
|
|
|
return std::nullopt;
|
2016-04-25 05:46:28 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptCoverPoint::SetInUse(bool inUse) {
|
|
|
|
xf8_25_inUse = inUse;
|
|
|
|
if (inUse)
|
|
|
|
x11c_timeLeft = xf4_coverTime;
|
2016-04-25 05:46:28 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CScriptCoverPoint::GetInUse(TUniqueId uid) const {
|
|
|
|
if (xf8_25_inUse || x11c_timeLeft > 0.f)
|
|
|
|
return true;
|
2016-04-25 05:46:28 +00:00
|
|
|
|
2020-03-06 15:16:55 +00:00
|
|
|
return !(xfa_occupant == kInvalidUniqueId || uid == kInvalidUniqueId || xfa_occupant == uid);
|
2016-04-25 05:46:28 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CScriptCoverPoint::Blown(const zeus::CVector3f& point) const {
|
|
|
|
if (!x30_24_active)
|
|
|
|
return true;
|
2016-04-25 05:46:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (ShouldWallHang()) {
|
|
|
|
zeus::CVector3f posDif = point - x34_transform.origin;
|
|
|
|
posDif *= zeus::CVector3f(1.f / posDif.magnitude());
|
|
|
|
zeus::CVector3f normDif = posDif.normalized();
|
2016-04-25 05:46:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f frontVec = x34_transform.frontVector();
|
|
|
|
frontVec.normalize();
|
2016-04-25 05:46:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (frontVec.dot(normDif) <= GetCosHorizontalAngle() || (posDif.z() * posDif.z()) >= GetSinSqVerticalAngle())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2016-04-25 05:46:28 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float CScriptCoverPoint::GetSinSqVerticalAngle() const { return xf0_sinVerticalAngle * xf0_sinVerticalAngle; }
|
2016-04-25 05:46:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptCoverPoint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
|
|
|
|
CActor::AcceptScriptMsg(msg, uid, mgr);
|
2016-04-25 05:46:28 +00:00
|
|
|
|
2022-11-08 15:42:55 +00:00
|
|
|
if (msg == EScriptObjectMessage::InitializedInArea) {
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const SConnection& con : x20_conns)
|
|
|
|
if (con.x0_state == EScriptObjectState::Retreat) {
|
|
|
|
xfc_retreating = mgr.GetIdForScript(con.x8_objId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-04-25 05:46:28 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|