metaforce/Runtime/World/CScriptActor.cpp

211 lines
7.0 KiB
C++
Raw Normal View History

2016-04-19 00:17:49 +00:00
#include "CScriptActor.hpp"
2017-02-03 23:32:15 +00:00
#include "CStateManager.hpp"
#include "CScriptTrigger.hpp"
#include "Camera/CGameCamera.hpp"
2017-02-03 23:32:15 +00:00
#include "CDamageVulnerability.hpp"
2017-02-11 00:52:52 +00:00
#include "CPlayerState.hpp"
#include "CScriptColorModulate.hpp"
#include "Character/IAnimReader.hpp"
2017-01-15 03:07:01 +00:00
#include "TCastTo.hpp"
2016-04-19 00:17:49 +00:00
namespace urde
{
2017-11-13 06:19:18 +00:00
CScriptActor::CScriptActor(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf,
CModelData&& mData, const zeus::CAABox& aabb, float mass, float zMomentum,
2017-02-03 23:32:15 +00:00
const CMaterialList& matList, const CHealthInfo& hInfo, const CDamageVulnerability& dVuln,
const CActorParameters& actParms, bool looping, bool active, u32 w1, float f3, bool b2,
bool castsShadow, bool b4, bool b5)
: CPhysicsActor(uid, active, name, info, xf, std::move(mData), matList, aabb, SMoverData(mass), actParms, 0.3f, 0.1f)
2017-02-03 23:32:15 +00:00
, x258_initialHealth(hInfo)
, x260_currentHealth(hInfo)
, x268_damageVulnerability(dVuln)
, x2d8_(w1)
2017-02-11 00:52:52 +00:00
, x2dc_xrayAlpha(f3)
2017-02-03 23:32:15 +00:00
, x2e2_24_(b2)
2017-02-13 00:00:07 +00:00
, x2e2_25_dead(false)
, x2e2_26_animating(true)
2017-07-09 09:11:59 +00:00
, x2e2_27_(std::fabs(1.f - f3) > 0.00001)
2017-02-03 23:32:15 +00:00
, x2e2_28_(false)
2017-02-13 00:00:07 +00:00
, x2e2_29_((x2e2_24_ && x2e2_25_dead && x2d8_ != 0))
, x2e2_30_transposeRotate(b4)
2017-02-03 23:32:15 +00:00
, x2e2_31_(b5)
2017-11-24 08:23:28 +00:00
, x2e3_24_cameraMoveIntoAlpha(false)
2016-04-19 00:17:49 +00:00
{
2017-02-03 23:32:15 +00:00
if (x64_modelData && (x64_modelData->HasAnimData() || x64_modelData->HasNormalModel()) && castsShadow)
CreateShadow(true);
if (x64_modelData && x64_modelData->HasAnimData())
x64_modelData->EnableLooping(looping);
x150_momentum = zeus::CVector3f(0.f, 0.f, zMomentum);
2016-04-19 00:17:49 +00:00
}
2017-01-15 03:07:01 +00:00
2017-02-03 23:32:15 +00:00
void CScriptActor::Accept(IVisitor& visitor) { visitor.Visit(this); }
2017-02-11 00:52:52 +00:00
void CScriptActor::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr)
{
if (msg == EScriptObjectMessage::Reset)
{
2017-02-13 00:00:07 +00:00
x2e2_25_dead = false;
2017-02-11 00:52:52 +00:00
x260_currentHealth = x258_initialHealth;
}
else if (msg == EScriptObjectMessage::Increment && !GetActive())
{
mgr.SendScriptMsg(this, x8_uid, EScriptObjectMessage::Activate);
2017-02-13 00:00:07 +00:00
CScriptColorModulate::FadeInHelper(mgr, x8_uid, x2d0_alphaMax);
2017-02-11 00:52:52 +00:00
}
else if (msg == EScriptObjectMessage::Decrement)
{
2017-02-13 00:00:07 +00:00
CScriptColorModulate::FadeOutHelper(mgr, x8_uid, x2d4_alphaMin);
2017-02-11 00:52:52 +00:00
}
2017-03-24 05:30:16 +00:00
else if (msg == EScriptObjectMessage::InitializedInArea)
2017-02-11 00:52:52 +00:00
{
for (const SConnection& conn : x20_conns)
{
if (conn.x0_state != EScriptObjectState::InheritBounds || conn.x4_msg != EScriptObjectMessage::Activate)
continue;
auto search = mgr.GetIdListForScript(conn.x8_objId);
for (auto it = search.first; it != search.second; ++it)
{
if (TCastToConstPtr<CScriptTrigger>(mgr.GetObjectById(it->second)))
{
x2e0_triggerId = it->second;
break;
}
}
}
2017-02-03 23:32:15 +00:00
2017-02-11 00:52:52 +00:00
if (x2e2_31_)
CActor::AddMaterial(EMaterialTypes::Unknown54, mgr);
}
2017-02-03 23:32:15 +00:00
2017-02-11 00:52:52 +00:00
CActor::AcceptScriptMsg(msg, uid, mgr);
}
void CScriptActor::Think(float dt, CStateManager& mgr)
{
if (!GetActive())
return;
if (HasModelData() && x64_modelData->HasAnimData())
{
2017-02-13 00:00:07 +00:00
bool timeRemaining = x64_modelData->GetAnimationData()->IsAnimTimeRemaining(dt - FLT_EPSILON, "Whole Body");
2017-02-11 00:52:52 +00:00
bool loop = x64_modelData->GetIsLoop();
2017-02-13 00:00:07 +00:00
SAdvancementDeltas deltas = CActor::UpdateAnimation(dt, mgr, true);
if (timeRemaining || loop)
{
x2e2_26_animating = true;
if (x2e2_30_transposeRotate)
MoveToOR(
x34_transform.rotate(x64_modelData->GetScale() * x34_transform.transposeRotate(deltas.x0_posDelta)),
dt);
else
MoveToOR(deltas.x0_posDelta, dt);
RotateToOR(deltas.xc_rotDelta, dt);
}
if (!timeRemaining && x2e2_26_animating && !loop)
{
SendScriptMsgs(EScriptObjectState::MaxReached, mgr, EScriptObjectMessage::None);
x2e2_26_animating = false;
}
}
2017-08-20 05:23:22 +00:00
if (!x2e2_25_dead && HealthInfo(mgr)->GetHP() <= 0.f)
2017-02-13 00:00:07 +00:00
{
x2e2_25_dead = true;
SendScriptMsgs(EScriptObjectState::Dead, mgr, EScriptObjectMessage::None);
2017-02-11 00:52:52 +00:00
}
}
2017-02-13 00:00:07 +00:00
void CScriptActor::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum)
{
CActor::PreRender(mgr, frustum);
2017-08-13 07:56:35 +00:00
if (xe4_30_outOfFrustum && TCastToPtr<CCinematicCamera>(mgr.GetCameraManager()->GetCurrentCamera(mgr)))
xe4_30_outOfFrustum = false;
2017-02-13 00:00:07 +00:00
2017-08-13 07:56:35 +00:00
if (xe4_30_outOfFrustum && !x2e2_29_ && !x2e2_27_)
2017-02-13 00:00:07 +00:00
{
zeus::CColor col(1.f, 1.f, x2dc_xrayAlpha);
if (mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::XRay)
{
2017-03-20 05:09:53 +00:00
xb4_drawFlags.x0_blendMode = 5;
xb4_drawFlags.x1_matSetIdx = 0;
xb4_drawFlags.x2_flags = 3;
xb4_drawFlags.x4_color = col;
2017-02-13 00:00:07 +00:00
x2e2_28_ = true;
}
2017-03-20 05:09:53 +00:00
else if (x2e2_28_)
2017-02-13 00:00:07 +00:00
{
x2e2_28_ = false;
2017-03-20 05:09:53 +00:00
if (xb4_drawFlags.x0_blendMode != 5 && xb4_drawFlags.x1_matSetIdx != 0 &&
xb4_drawFlags.x2_flags != 3 && xb4_drawFlags.x4_color != col)
2017-02-13 00:00:07 +00:00
{
2017-03-20 05:09:53 +00:00
xb4_drawFlags.x0_blendMode = 5;
xb4_drawFlags.x1_matSetIdx = 0;
xb4_drawFlags.x2_flags = 3;
xb4_drawFlags.x4_color = col;
2017-02-13 00:00:07 +00:00
}
}
2017-08-13 07:56:35 +00:00
if (!x2e2_24_ && xe6_27_renderVisorFlags == 2 &&
2017-02-13 00:00:07 +00:00
mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::XRay)
{
2017-03-20 05:09:53 +00:00
xb4_drawFlags.x2_flags &= ~3;
2017-02-13 00:00:07 +00:00
}
else
{
2017-03-20 05:09:53 +00:00
xb4_drawFlags.x2_flags |= 3;
2017-02-13 00:00:07 +00:00
}
if (x2d8_ != 0)
2017-03-20 05:09:53 +00:00
xb4_drawFlags.x1_matSetIdx = 0;
2017-02-13 00:00:07 +00:00
}
if (mgr.GetObjectById(x2e0_triggerId) == nullptr)
x2e0_triggerId = kInvalidUniqueId;
}
2017-02-03 23:32:15 +00:00
zeus::CAABox CScriptActor::GetSortingBounds(const CStateManager& mgr) const
2017-01-15 03:07:01 +00:00
{
2017-02-11 00:52:52 +00:00
if (x2e0_triggerId != kInvalidUniqueId)
2017-02-03 23:32:15 +00:00
{
2017-02-11 00:52:52 +00:00
TCastToConstPtr<CScriptTrigger> trigger(mgr.GetObjectById(x2e0_triggerId));
2017-02-03 23:32:15 +00:00
if (trigger)
return trigger->GetTriggerBoundsWR();
}
return CActor::GetSortingBounds(mgr);
2017-01-15 03:07:01 +00:00
}
2017-02-03 23:32:15 +00:00
EWeaponCollisionResponseTypes
2017-08-13 05:26:14 +00:00
CScriptActor::GetCollisionResponseType(const zeus::CVector3f& v1, const zeus::CVector3f& v2, const
CWeaponMode& wMode, int w) const
2017-02-03 23:32:15 +00:00
{
const CDamageVulnerability* dVuln = GetDamageVulnerability();
2017-02-11 00:52:52 +00:00
if (dVuln->GetVulnerability(wMode, false) == EVulnerability::Reflect)
{
EVulnerability phazonVuln = dVuln->GetPhazonVulnerability(wMode);
if (phazonVuln < EVulnerability::PassThrough && phazonVuln >= EVulnerability::Normal)
return EWeaponCollisionResponseTypes::Unknown15;
}
2017-02-03 23:32:15 +00:00
return CActor::GetCollisionResponseType(v1, v2, wMode, w);
}
rstl::optional_object<zeus::CAABox> CScriptActor::GetTouchBounds() const
{
if (GetActive() && x68_material.HasMaterial(EMaterialTypes::Solid))
return {CPhysicsActor::GetBoundingBox()};
return {};
}
2017-02-11 00:52:52 +00:00
void CScriptActor::Touch(CActor&, CStateManager&) {}
2016-04-19 00:17:49 +00:00
}