2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CScriptActor.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/CPlayerState.hpp"
|
|
|
|
#include "Runtime/Camera/CGameCamera.hpp"
|
|
|
|
#include "Runtime/Character/IAnimReader.hpp"
|
|
|
|
#include "Runtime/MP1/World/CActorContraption.hpp"
|
|
|
|
#include "Runtime/World/CActorParameters.hpp"
|
|
|
|
#include "Runtime/World/CDamageVulnerability.hpp"
|
|
|
|
#include "Runtime/World/CScriptColorModulate.hpp"
|
|
|
|
#include "Runtime/World/CScriptTrigger.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2019-12-22 20:04:07 +00:00
|
|
|
|
|
|
|
#include <zeus/CEulerAngles.hpp>
|
2016-04-19 00:17:49 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2016-04-19 00:17:49 +00:00
|
|
|
|
2017-11-13 06:19:18 +00:00
|
|
|
CScriptActor::CScriptActor(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf,
|
2017-02-21 03:29:28 +00:00
|
|
|
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,
|
2018-05-07 00:47:40 +00:00
|
|
|
const CActorParameters& actParms, bool looping, bool active, s32 shaderIdx, float xrayAlpha,
|
2018-02-08 06:18:27 +00:00
|
|
|
bool noThermalHotZ, bool castsShadow, bool scaleAdvancementDelta, bool materialFlag54)
|
2017-02-21 03:29:28 +00:00
|
|
|
: 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)
|
2018-06-02 06:06:25 +00:00
|
|
|
, x2d0_fadeInTime(actParms.x5c_fadeInTime)
|
|
|
|
, x2d4_fadeOutTime(actParms.x60_fadeOutTime)
|
2018-02-08 06:18:27 +00:00
|
|
|
, x2d8_shaderIdx(shaderIdx)
|
2018-12-08 05:30:43 +00:00
|
|
|
, x2dc_xrayAlpha(xrayAlpha) {
|
|
|
|
x2e2_24_noThermalHotZ = noThermalHotZ;
|
|
|
|
x2e2_27_xrayAlphaEnabled = !zeus::close_enough(1.f, xrayAlpha);
|
|
|
|
x2e2_29_processModelFlags = (x2e2_27_xrayAlphaEnabled || x2e2_24_noThermalHotZ || x2d8_shaderIdx != 0);
|
|
|
|
x2e2_30_scaleAdvancementDelta = scaleAdvancementDelta;
|
|
|
|
x2e2_31_materialFlag54 = materialFlag54;
|
|
|
|
|
2020-05-07 12:14:39 +00:00
|
|
|
if (x64_modelData && (x64_modelData->HasAnimData() || x64_modelData->HasNormalModel()) && castsShadow) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CreateShadow(true);
|
2020-05-07 12:14:39 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-05-07 12:14:39 +00:00
|
|
|
if (x64_modelData && x64_modelData->HasAnimData()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x64_modelData->EnableLooping(looping);
|
2020-05-07 12:14:39 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-09-24 00:38:47 +00:00
|
|
|
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); }
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptActor::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
|
|
|
|
switch (msg) {
|
|
|
|
case EScriptObjectMessage::InitializedInArea:
|
|
|
|
for (const SConnection& conn : x20_conns) {
|
2020-05-07 12:14:39 +00:00
|
|
|
if (conn.x0_state != EScriptObjectState::InheritBounds || conn.x4_msg != EScriptObjectMessage::Activate) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-07 12:14:39 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-05-07 12:14:39 +00:00
|
|
|
const auto search = mgr.GetIdListForScript(conn.x8_objId);
|
2018-12-08 05:30:43 +00:00
|
|
|
for (auto it = search.first; it != search.second; ++it) {
|
|
|
|
if (TCastToConstPtr<CScriptTrigger>(mgr.GetObjectById(it->second))) {
|
|
|
|
x2e0_triggerId = it->second;
|
|
|
|
break;
|
2018-05-18 04:16:33 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-02-11 00:52:52 +00:00
|
|
|
}
|
2017-02-03 23:32:15 +00:00
|
|
|
|
2020-05-07 12:14:39 +00:00
|
|
|
if (x2e2_31_materialFlag54) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CActor::AddMaterial(EMaterialTypes::Unknown54, mgr);
|
2020-05-07 12:14:39 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Reset:
|
|
|
|
x2e2_25_dead = false;
|
|
|
|
x260_currentHealth = x258_initialHealth;
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Increment:
|
|
|
|
if (!GetActive()) {
|
|
|
|
mgr.SendScriptMsg(this, x8_uid, EScriptObjectMessage::Activate);
|
|
|
|
CScriptColorModulate::FadeInHelper(mgr, x8_uid, x2d0_fadeInTime);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Decrement:
|
|
|
|
CScriptColorModulate::FadeOutHelper(mgr, x8_uid, x2d4_fadeOutTime);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
CActor::AcceptScriptMsg(msg, uid, mgr);
|
2017-02-11 00:52:52 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptActor::Think(float dt, CStateManager& mgr) {
|
2020-05-07 12:14:39 +00:00
|
|
|
if (!GetActive()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-07 12:14:39 +00:00
|
|
|
}
|
2017-02-11 00:52:52 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (HasModelData() && x64_modelData->HasAnimData()) {
|
2020-05-07 12:14:39 +00:00
|
|
|
const bool timeRemaining = x64_modelData->GetAnimationData()->IsAnimTimeRemaining(dt - FLT_EPSILON, "Whole Body");
|
|
|
|
const bool loop = x64_modelData->GetIsLoop();
|
2017-02-11 00:52:52 +00:00
|
|
|
|
2020-05-07 12:14:39 +00:00
|
|
|
const SAdvancementDeltas deltas = CActor::UpdateAnimation(dt, mgr, true);
|
2017-02-13 00:00:07 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (timeRemaining || loop) {
|
|
|
|
x2e2_26_animating = true;
|
2017-02-13 00:00:07 +00:00
|
|
|
|
2020-05-07 12:14:39 +00:00
|
|
|
if (x2e2_30_scaleAdvancementDelta) {
|
2018-12-08 05:30:43 +00:00
|
|
|
MoveToOR(x34_transform.rotate(x64_modelData->GetScale() * x34_transform.transposeRotate(deltas.x0_posDelta)),
|
|
|
|
dt);
|
2020-05-07 12:14:39 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
MoveToOR(deltas.x0_posDelta, dt);
|
2020-05-07 12:14:39 +00:00
|
|
|
}
|
2017-02-13 00:00:07 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
RotateToOR(deltas.xc_rotDelta, dt);
|
2017-02-13 00:00:07 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!timeRemaining && x2e2_26_animating && !loop) {
|
|
|
|
SendScriptMsgs(EScriptObjectState::MaxReached, mgr, EScriptObjectMessage::None);
|
|
|
|
x2e2_26_animating = false;
|
2017-02-11 00:52:52 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-02-11 00:52:52 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!x2e2_25_dead && HealthInfo(mgr)->GetHP() <= 0.f) {
|
|
|
|
x2e2_25_dead = true;
|
|
|
|
SendScriptMsgs(EScriptObjectState::Dead, mgr, EScriptObjectMessage::None);
|
|
|
|
}
|
|
|
|
}
|
2017-02-13 00:00:07 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptActor::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) {
|
|
|
|
CActor::PreRender(mgr, frustum);
|
|
|
|
|
2020-05-07 12:14:39 +00:00
|
|
|
if (xe4_30_outOfFrustum && TCastToConstPtr<CCinematicCamera>(mgr.GetCameraManager()->GetCurrentCamera(mgr))) {
|
2018-12-08 05:30:43 +00:00
|
|
|
xe4_30_outOfFrustum = false;
|
2020-05-07 12:14:39 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (!xe4_30_outOfFrustum && x2e2_29_processModelFlags) {
|
|
|
|
if (x2e2_27_xrayAlphaEnabled) {
|
2020-05-07 12:14:39 +00:00
|
|
|
const zeus::CColor col(1.f, x2dc_xrayAlpha);
|
|
|
|
const CModelFlags xrayFlags(5, 0, 3, col);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::XRay) {
|
|
|
|
xb4_drawFlags = xrayFlags;
|
|
|
|
x2e2_28_inXrayAlpha = true;
|
|
|
|
} else if (x2e2_28_inXrayAlpha) {
|
|
|
|
x2e2_28_inXrayAlpha = false;
|
2020-05-07 12:14:39 +00:00
|
|
|
if (xb4_drawFlags == xrayFlags) {
|
2019-02-24 07:15:54 +00:00
|
|
|
xb4_drawFlags = CModelFlags(0, 0, 3, zeus::skWhite);
|
2020-05-07 12:14:39 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-13 00:00:07 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x2e2_24_noThermalHotZ && xe6_27_thermalVisorFlags == 2) {
|
2020-05-07 12:14:39 +00:00
|
|
|
if (mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::Thermal) {
|
2018-12-08 05:30:43 +00:00
|
|
|
xb4_drawFlags.x2_flags &= ~3; // Disable Z test/update
|
2020-12-18 11:06:31 +00:00
|
|
|
xb4_drawFlags.m_noZTest = true;
|
2020-05-07 12:14:39 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
xb4_drawFlags.x2_flags |= 3; // Enable Z test/update
|
2020-12-18 11:06:31 +00:00
|
|
|
xb4_drawFlags.m_noZTest = false;
|
2020-05-07 12:14:39 +00:00
|
|
|
}
|
2017-02-13 00:00:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 12:14:39 +00:00
|
|
|
if (x2d8_shaderIdx != 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
xb4_drawFlags.x1_matSetIdx = u8(x2d8_shaderIdx);
|
2020-05-07 12:14:39 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 12:14:39 +00:00
|
|
|
if (mgr.GetObjectById(x2e0_triggerId) == nullptr) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x2e0_triggerId = kInvalidUniqueId;
|
2020-05-07 12:14:39 +00:00
|
|
|
}
|
2017-02-13 00:00:07 +00:00
|
|
|
}
|
2017-02-03 23:32:15 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CAABox CScriptActor::GetSortingBounds(const CStateManager& mgr) const {
|
|
|
|
if (x2e0_triggerId != kInvalidUniqueId) {
|
2020-05-07 12:14:39 +00:00
|
|
|
const TCastToConstPtr<CScriptTrigger> trigger(mgr.GetObjectById(x2e0_triggerId));
|
|
|
|
if (trigger) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return trigger->GetTriggerBoundsWR();
|
2020-05-07 12:14:39 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-02-03 23:32:15 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return CActor::GetSortingBounds(mgr);
|
2017-01-15 03:07:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
EWeaponCollisionResponseTypes CScriptActor::GetCollisionResponseType(const zeus::CVector3f& v1,
|
|
|
|
const zeus::CVector3f& v2,
|
|
|
|
const CWeaponMode& wMode,
|
|
|
|
EProjectileAttrib w) const {
|
|
|
|
const CDamageVulnerability* dVuln = GetDamageVulnerability();
|
|
|
|
if (dVuln->GetVulnerability(wMode, false) == EVulnerability::Deflect) {
|
2020-05-07 12:14:39 +00:00
|
|
|
const EDeflectType deflectType = dVuln->GetDeflectionType(wMode);
|
|
|
|
if (deflectType < EDeflectType::Four && deflectType >= EDeflectType::One) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return EWeaponCollisionResponseTypes::Unknown15;
|
2020-05-07 12:14:39 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
return CActor::GetCollisionResponseType(v1, v2, wMode, w);
|
2017-02-03 23:32:15 +00:00
|
|
|
}
|
|
|
|
|
2019-06-12 02:05:17 +00:00
|
|
|
std::optional<zeus::CAABox> CScriptActor::GetTouchBounds() const {
|
2020-02-01 03:28:25 +00:00
|
|
|
if (GetActive() && x68_material.HasMaterial(EMaterialTypes::Solid)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return {CPhysicsActor::GetBoundingBox()};
|
2020-02-01 03:28:25 +00:00
|
|
|
}
|
|
|
|
return std::nullopt;
|
2017-02-03 23:32:15 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptActor::Touch(CActor&, CStateManager&) {
|
|
|
|
// Empty
|
2016-04-19 00:17:49 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|