2016-04-25 05:46:28 +00:00
|
|
|
#include "CScriptCoverPoint.hpp"
|
|
|
|
#include "CActorParameters.hpp"
|
|
|
|
#include "CStateManager.hpp"
|
2017-01-15 03:07:01 +00:00
|
|
|
#include "TCastTo.hpp"
|
2016-04-25 05:46:28 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
2017-11-13 06:19:18 +00:00
|
|
|
CScriptCoverPoint::CScriptCoverPoint(TUniqueId uid, std::string_view name, const CEntityInfo &info,
|
2016-04-25 05:46:28 +00:00
|
|
|
zeus::CTransform xf, bool active, u32 flags, bool crouch, float horizontalAngle, float verticalAngle, float coverTime)
|
|
|
|
: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(),
|
2016-12-29 21:38:59 +00:00
|
|
|
CMaterialList(EMaterialTypes::Unknown), CActorParameters::None(), kInvalidUniqueId),
|
2016-04-25 05:46:28 +00:00
|
|
|
xe8_flags(flags),
|
2017-01-25 04:40:19 +00:00
|
|
|
xf4_coverTime(coverTime)
|
2016-04-25 05:46:28 +00:00
|
|
|
{
|
2017-01-25 04:40:19 +00:00
|
|
|
xf8_24_crouch = crouch;
|
2016-04-25 05:46:28 +00:00
|
|
|
xec_cosHorizontalAngle = std::cos(zeus::degToRad(horizontalAngle) * 0.5f);
|
|
|
|
xf0_sinVerticalAngle = std::sin(zeus::degToRad(verticalAngle) * 0.5f);
|
2016-10-01 19:08:08 +00:00
|
|
|
x100_touchBounds.emplace(xf.origin, xf.origin);
|
2016-04-25 05:46:28 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 03:07:01 +00:00
|
|
|
void CScriptCoverPoint::Accept(IVisitor& visitor)
|
|
|
|
{
|
|
|
|
visitor.Visit(this);
|
|
|
|
}
|
|
|
|
|
2016-04-25 05:46:28 +00:00
|
|
|
void CScriptCoverPoint::Think(float delta, CStateManager&)
|
|
|
|
{
|
|
|
|
if (x11c_timeLeft <= 0.f)
|
|
|
|
return;
|
|
|
|
x11c_timeLeft -= delta;
|
|
|
|
}
|
|
|
|
|
2016-04-29 10:08:46 +00:00
|
|
|
rstl::optional_object<zeus::CAABox> CScriptCoverPoint::GetTouchBounds() const
|
2016-04-25 05:46:28 +00:00
|
|
|
{
|
|
|
|
if (x100_touchBounds)
|
2016-04-29 10:08:46 +00:00
|
|
|
return x100_touchBounds;
|
2016-04-25 05:46:28 +00:00
|
|
|
|
2016-04-29 10:08:46 +00:00
|
|
|
return {};
|
2016-04-25 05:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptCoverPoint::SetInUse(bool inUse)
|
|
|
|
{
|
|
|
|
xf8_25_inUse = inUse;
|
|
|
|
if (inUse)
|
|
|
|
x11c_timeLeft = xf4_coverTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CScriptCoverPoint::GetInUse(TUniqueId uid) const
|
|
|
|
{
|
|
|
|
if (xf8_25_inUse || x11c_timeLeft > 0.f)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (xfa_occupant == kInvalidUniqueId || uid == kInvalidUniqueId || xfa_occupant == uid)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CScriptCoverPoint::Blown(const zeus::CVector3f& point) const
|
|
|
|
{
|
|
|
|
if (!x30_24_active)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (ShouldWallHang())
|
|
|
|
{
|
2016-10-01 19:08:08 +00:00
|
|
|
zeus::CVector3f posDif = point - x34_transform.origin;
|
2016-04-25 05:46:28 +00:00
|
|
|
posDif *= (1.0 / posDif.magnitude());
|
|
|
|
zeus::CVector3f normDif = posDif.normalized();
|
|
|
|
|
2016-10-01 19:08:08 +00:00
|
|
|
zeus::CVector3f frontVec = x34_transform.frontVector();
|
|
|
|
frontVec.normalize();
|
2016-04-25 05:46:28 +00:00
|
|
|
|
2016-10-01 19:08:08 +00:00
|
|
|
if (frontVec.dot(normDif) <= GetCosHorizontalAngle() || (posDif.z * posDif.z) >= GetSinSqVerticalAngle())
|
2016-04-25 05:46:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
float CScriptCoverPoint::GetSinSqVerticalAngle() const
|
|
|
|
{
|
|
|
|
return xf0_sinVerticalAngle * xf0_sinVerticalAngle;
|
|
|
|
}
|
|
|
|
|
|
|
|
float CScriptCoverPoint::GetCosHorizontalAngle() const
|
|
|
|
{
|
|
|
|
return xec_cosHorizontalAngle;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CScriptCoverPoint::ShouldLandHere() const
|
|
|
|
{
|
|
|
|
return xe8_26_landHere;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CScriptCoverPoint::ShouldWallHang() const
|
|
|
|
{
|
|
|
|
return xe8_27_wallHang;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CScriptCoverPoint::ShouldStay() const
|
|
|
|
{
|
|
|
|
return xe8_28_stay;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CScriptCoverPoint::ShouldCrouch() const
|
|
|
|
{
|
|
|
|
return xf8_24_crouch;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 CScriptCoverPoint::GetAttackDirection() const
|
|
|
|
{
|
|
|
|
return xe8_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptCoverPoint::Reserve(TUniqueId id)
|
|
|
|
{
|
|
|
|
xfa_occupant = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptCoverPoint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr)
|
|
|
|
{
|
|
|
|
CActor::AcceptScriptMsg(msg, uid, mgr);
|
|
|
|
|
2016-07-25 06:24:57 +00:00
|
|
|
if (msg == EScriptObjectMessage::InternalMessage14)
|
2016-04-25 05:46:28 +00:00
|
|
|
{
|
|
|
|
for (const SConnection& con : x20_conns)
|
|
|
|
if (con.x0_state == EScriptObjectState::Retreat)
|
|
|
|
{
|
2017-01-04 04:08:30 +00:00
|
|
|
xfc_retreating = mgr.GetIdForScript(con.x8_objId);
|
2016-04-25 05:46:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|