2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CScriptPlatform.hpp"
|
|
|
|
|
2020-04-12 19:11:21 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/Collision/CCollidableOBBTreeGroup.hpp"
|
|
|
|
#include "Runtime/Collision/CGameCollision.hpp"
|
|
|
|
#include "Runtime/Collision/CMaterialList.hpp"
|
2022-02-25 07:45:25 +00:00
|
|
|
#include "Runtime/Graphics/CCubeRenderer.hpp"
|
2020-05-07 06:19:58 +00:00
|
|
|
#include "Runtime/World/CActorParameters.hpp"
|
2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CPlayer.hpp"
|
|
|
|
#include "Runtime/World/CScriptColorModulate.hpp"
|
|
|
|
#include "Runtime/World/CScriptTrigger.hpp"
|
|
|
|
#include "Runtime/World/CScriptWaypoint.hpp"
|
|
|
|
#include "Runtime/World/CWorld.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2018-06-29 20:21:36 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-04-12 18:11:02 +00:00
|
|
|
constexpr auto skPlatformMaterialList =
|
|
|
|
CMaterialList{EMaterialTypes::Solid, EMaterialTypes::Immovable, EMaterialTypes::Platform, EMaterialTypes::Occluder};
|
2016-04-20 21:44:18 +00:00
|
|
|
|
2020-04-07 19:41:26 +00:00
|
|
|
CScriptPlatform::CScriptPlatform(TUniqueId uid, std::string_view name, const CEntityInfo& info,
|
|
|
|
const zeus::CTransform& xf, CModelData&& mData, const CActorParameters& actParms,
|
|
|
|
const zeus::CAABox& aabb, float speed, bool detectCollision, float xrayAlpha,
|
|
|
|
bool active, const CHealthInfo& hInfo, const CDamageVulnerability& dVuln,
|
2020-05-07 06:19:58 +00:00
|
|
|
std::optional<TLockedToken<CCollidableOBBTreeGroupContainer>> dcln, bool rainSplashes,
|
|
|
|
u32 maxRainSplashes, u32 rainGenRate)
|
2020-04-12 18:11:02 +00:00
|
|
|
: CPhysicsActor(uid, active, name, info, xf, std::move(mData), skPlatformMaterialList, aabb, SMoverData(15000.f),
|
2016-09-02 15:26:29 +00:00
|
|
|
actParms, 0.3f, 0.1f)
|
2018-06-29 20:21:36 +00:00
|
|
|
, x25c_currentSpeed(speed)
|
2020-05-07 06:19:58 +00:00
|
|
|
, x268_fadeInTime(actParms.GetFadeInTime())
|
|
|
|
, x26c_fadeOutTime(actParms.GetFadeOutTime())
|
2018-06-08 21:00:18 +00:00
|
|
|
, x28c_initialHealth(hInfo)
|
|
|
|
, x294_health(hInfo)
|
|
|
|
, x29c_damageVuln(dVuln)
|
2020-05-07 06:19:58 +00:00
|
|
|
, x304_treeGroupContainer(std::move(dcln))
|
|
|
|
, x348_xrayAlpha(xrayAlpha)
|
|
|
|
, x34c_maxRainSplashes(maxRainSplashes)
|
|
|
|
, x350_rainGenRate(rainGenRate)
|
|
|
|
, x356_26_detectCollision(detectCollision)
|
|
|
|
, x356_28_rainSplashes(rainSplashes) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CActor::SetMaterialFilter(CMaterialFilter::MakeIncludeExclude(
|
|
|
|
CMaterialList(EMaterialTypes::Solid),
|
|
|
|
CMaterialList(EMaterialTypes::NoStaticCollision, EMaterialTypes::NoPlatformCollision, EMaterialTypes::Platform)));
|
|
|
|
xf8_24_movable = false;
|
2020-04-12 18:54:47 +00:00
|
|
|
if (HasModelData() && GetModelData()->HasAnimData()) {
|
2019-08-14 14:58:54 +00:00
|
|
|
GetModelData()->GetAnimationData()->EnableLooping(true);
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
|
|
|
if (x304_treeGroupContainer) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x314_treeGroup = std::make_unique<CCollidableOBBTreeGroup>(x304_treeGroupContainer->GetObj(), x68_material);
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2016-04-20 21:44:18 +00:00
|
|
|
}
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2017-06-11 05:49:27 +00:00
|
|
|
void CScriptPlatform::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
|
|
|
|
2021-06-06 23:53:41 +00:00
|
|
|
void CScriptPlatform::DragSlave(CStateManager& mgr, rstl::reserved_vector<u16, kMaxEntities>& draggedSet, CActor* actor,
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CVector3f& delta) {
|
2020-04-12 18:54:47 +00:00
|
|
|
if (std::find(draggedSet.begin(), draggedSet.end(), actor->GetUniqueId().Value()) != draggedSet.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
draggedSet.push_back(actor->GetUniqueId().Value());
|
|
|
|
zeus::CTransform newXf = actor->GetTransform();
|
|
|
|
newXf.origin += delta;
|
|
|
|
actor->SetTransform(newXf);
|
|
|
|
if (const TCastToPtr<CScriptPlatform> plat = actor) {
|
|
|
|
plat->DragSlaves(mgr, draggedSet, delta);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
|
|
|
|
2021-06-06 23:53:41 +00:00
|
|
|
void CScriptPlatform::DragSlaves(CStateManager& mgr, rstl::reserved_vector<u16, kMaxEntities>& draggedSet,
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CVector3f& delta) {
|
2020-04-12 18:54:47 +00:00
|
|
|
for (SRiders& rider : x328_slavesStatic) {
|
|
|
|
if (const TCastToPtr<CActor> act = mgr.ObjectById(rider.x0_uid)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
DragSlave(mgr, draggedSet, act.GetPtr(), delta);
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
for (auto it = x338_slavesDynamic.begin(); it != x338_slavesDynamic.end();) {
|
2020-04-12 18:54:47 +00:00
|
|
|
if (const TCastToPtr<CActor> act = mgr.ObjectById(it->x0_uid)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
DragSlave(mgr, draggedSet, act.GetPtr(), delta);
|
|
|
|
++it;
|
2020-04-12 18:54:47 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
it = x338_slavesDynamic.erase(it);
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptPlatform::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
|
|
|
|
switch (msg) {
|
|
|
|
case EScriptObjectMessage::InitializedInArea:
|
|
|
|
BuildSlaveList(mgr);
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::AddPlatformRider:
|
|
|
|
AddRider(x318_riders, uid, this, mgr);
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Stop: {
|
|
|
|
x25c_currentSpeed = 0.f;
|
|
|
|
Stop();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EScriptObjectMessage::Next: {
|
|
|
|
x25a_targetWaypoint = GetNext(x258_currentWaypoint, mgr);
|
2020-04-12 18:54:47 +00:00
|
|
|
if (x25a_targetWaypoint == kInvalidUniqueId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.SendScriptMsg(this, GetUniqueId(), EScriptObjectMessage::Stop);
|
2020-04-12 18:54:47 +00:00
|
|
|
} else if (const TCastToPtr<CScriptWaypoint> wp = mgr.ObjectById(x25a_targetWaypoint)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x25c_currentSpeed = 0.f;
|
|
|
|
Stop();
|
|
|
|
x270_dragDelta = wp->GetTranslation() - GetTranslation();
|
|
|
|
SetTranslation(wp->GetTranslation());
|
|
|
|
|
|
|
|
x258_currentWaypoint = x25a_targetWaypoint;
|
|
|
|
x25a_targetWaypoint = GetNext(x258_currentWaypoint, mgr);
|
|
|
|
mgr.SendScriptMsg(wp, GetUniqueId(), EScriptObjectMessage::Arrived);
|
|
|
|
if (!x328_slavesStatic.empty() || !x338_slavesDynamic.empty()) {
|
2021-06-06 23:53:41 +00:00
|
|
|
rstl::reserved_vector<u16, kMaxEntities> draggedSet;
|
2018-12-08 05:30:43 +00:00
|
|
|
DragSlaves(mgr, draggedSet, x270_dragDelta);
|
|
|
|
}
|
2019-02-24 07:15:54 +00:00
|
|
|
x270_dragDelta = zeus::skZero3f;
|
2018-06-08 21:00:18 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EScriptObjectMessage::Start: {
|
|
|
|
x25a_targetWaypoint = GetNext(x258_currentWaypoint, mgr);
|
2020-04-12 18:54:47 +00:00
|
|
|
if (x25a_targetWaypoint == kInvalidUniqueId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.SendScriptMsg(this, GetUniqueId(), EScriptObjectMessage::Stop);
|
2020-04-12 18:54:47 +00:00
|
|
|
} else if (const TCastToConstPtr<CScriptWaypoint> wp = mgr.ObjectById(x25a_targetWaypoint)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x25c_currentSpeed = wp->GetSpeed();
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EScriptObjectMessage::Reset: {
|
|
|
|
x356_24_dead = false;
|
|
|
|
x294_health = x28c_initialHealth;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EScriptObjectMessage::Increment: {
|
2020-05-07 06:19:58 +00:00
|
|
|
if (!GetActive()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.SendScriptMsg(this, GetUniqueId(), EScriptObjectMessage::Activate);
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2020-05-07 06:19:58 +00:00
|
|
|
CScriptColorModulate::FadeInHelper(mgr, GetUniqueId(), x268_fadeInTime);
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EScriptObjectMessage::Decrement:
|
|
|
|
CScriptColorModulate::FadeOutHelper(mgr, GetUniqueId(), x26c_fadeOutTime);
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Deleted:
|
2020-02-01 04:53:36 +00:00
|
|
|
DecayRiders(x318_riders, 1.66666675f, mgr);
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPhysicsActor::AcceptScriptMsg(msg, uid, mgr);
|
2018-06-08 21:00:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptPlatform::DecayRiders(std::vector<SRiders>& riders, float dt, CStateManager& mgr) {
|
|
|
|
for (auto it = riders.begin(); it != riders.end();) {
|
|
|
|
it->x4_decayTimer -= dt;
|
|
|
|
if (it->x4_decayTimer <= 0.f) {
|
|
|
|
mgr.SendScriptMsgAlways(it->x0_uid, kInvalidUniqueId, EScriptObjectMessage::AddPlatformRider);
|
|
|
|
it = riders.erase(it);
|
|
|
|
continue;
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
++it;
|
|
|
|
}
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptPlatform::MoveRiders(CStateManager& mgr, float dt, bool active, std::vector<SRiders>& riders,
|
|
|
|
std::vector<SRiders>& collidedRiders, const zeus::CTransform& oldXf,
|
|
|
|
const zeus::CTransform& newXf, const zeus::CVector3f& dragDelta,
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CQuaternion& rotDelta) {
|
|
|
|
for (auto it = riders.begin(); it != riders.end();) {
|
|
|
|
if (active) {
|
|
|
|
if (TCastToPtr<CPhysicsActor> act = mgr.ObjectById(it->x0_uid)) {
|
|
|
|
if (act->GetActive()) {
|
|
|
|
zeus::CVector3f delta =
|
|
|
|
newXf.rotate(it->x8_transform.origin) - oldXf.rotate(it->x8_transform.origin) + dragDelta;
|
|
|
|
zeus::CVector3f newPos = act->GetTranslation() + delta;
|
|
|
|
act->MoveCollisionPrimitive(delta);
|
|
|
|
bool collision = CGameCollision::DetectStaticCollisionBoolean(
|
|
|
|
mgr, *act->GetCollisionPrimitive(), act->GetPrimitiveTransform(), act->GetMaterialFilter());
|
2019-02-24 07:15:54 +00:00
|
|
|
act->MoveCollisionPrimitive(zeus::skZero3f);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (collision) {
|
|
|
|
AddRider(collidedRiders, act->GetUniqueId(), act.GetPtr(), mgr);
|
|
|
|
it = riders.erase(it);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
act->SetTranslation(newPos);
|
2020-04-12 18:54:47 +00:00
|
|
|
if (const TCastToConstPtr<CPlayer> player = act.GetPtr()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (player->GetOrbitState() != CPlayer::EPlayerOrbitState::NoOrbit) {
|
|
|
|
++it;
|
|
|
|
continue;
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
zeus::CTransform xf = (rotDelta * zeus::CQuaternion(act->GetTransform().basis)).toTransform();
|
|
|
|
xf.origin = act->GetTranslation();
|
|
|
|
act->SetTransform(xf);
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
++it;
|
|
|
|
}
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 19:29:18 +00:00
|
|
|
EntityList CScriptPlatform::BuildNearListFromRiders(CStateManager& mgr, const std::vector<SRiders>& movedRiders) {
|
2021-06-07 00:07:45 +00:00
|
|
|
EntityList ret;
|
2020-04-12 18:54:47 +00:00
|
|
|
for (const SRiders& rider : movedRiders) {
|
|
|
|
if (const TCastToConstPtr<CActor> act = mgr.ObjectById(rider.x0_uid)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ret.push_back(act->GetUniqueId());
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return ret;
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptPlatform::PreThink(float dt, CStateManager& mgr) {
|
|
|
|
DecayRiders(x318_riders, dt, mgr);
|
|
|
|
x264_collisionRecoverDelay -= dt;
|
|
|
|
x260_moveDelay -= dt;
|
|
|
|
if (x260_moveDelay <= 0.f) {
|
2019-02-24 07:15:54 +00:00
|
|
|
x270_dragDelta = zeus::skZero3f;
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CTransform oldXf = x34_transform;
|
|
|
|
CMotionState mState = GetMotionState();
|
|
|
|
if (GetActive()) {
|
2020-04-12 18:54:47 +00:00
|
|
|
for (SRiders& rider : x318_riders) {
|
|
|
|
if (const TCastToConstPtr<CPhysicsActor> act = mgr.ObjectById(rider.x0_uid)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
rider.x8_transform.origin = x34_transform.transposeRotate(act->GetTranslation() - GetTranslation());
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
x27c_rotDelta = Move(dt, mgr);
|
|
|
|
}
|
2018-06-29 20:21:36 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x270_dragDelta = x34_transform.origin - oldXf.origin;
|
|
|
|
|
|
|
|
std::vector<SRiders> collidedRiders;
|
|
|
|
MoveRiders(mgr, dt, GetActive(), x318_riders, collidedRiders, oldXf, x34_transform, x270_dragDelta, x27c_rotDelta);
|
|
|
|
x356_27_squishedRider = false;
|
|
|
|
if (!collidedRiders.empty()) {
|
2021-06-07 00:07:45 +00:00
|
|
|
EntityList nearList = BuildNearListFromRiders(mgr, collidedRiders);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (CGameCollision::DetectDynamicCollisionBoolean(*GetCollisionPrimitive(), GetPrimitiveTransform(), nearList,
|
|
|
|
mgr)) {
|
|
|
|
SetMotionState(mState);
|
|
|
|
Stop();
|
|
|
|
x260_moveDelay = 0.035f;
|
|
|
|
MoveRiders(mgr, dt, GetActive(), x318_riders, collidedRiders, x34_transform, oldXf, -x270_dragDelta,
|
|
|
|
x27c_rotDelta.inverse());
|
2019-02-24 07:15:54 +00:00
|
|
|
x270_dragDelta = zeus::skZero3f;
|
2018-12-08 05:30:43 +00:00
|
|
|
SendScriptMsgs(EScriptObjectState::Modify, mgr, EScriptObjectMessage::None);
|
|
|
|
x356_27_squishedRider = true;
|
|
|
|
}
|
2018-06-08 21:00:18 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-06-08 21:00:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptPlatform::Think(float dt, CStateManager& mgr) {
|
2020-04-12 18:54:47 +00:00
|
|
|
if (!GetActive()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2018-06-08 21:00:18 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (HasModelData() && GetModelData()->HasAnimData()) {
|
2020-04-12 18:54:47 +00:00
|
|
|
if (!x356_25_controlledAnimation) {
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdateAnimation(dt, mgr, true);
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x356_28_rainSplashes && mgr.GetWorld()->GetNeededEnvFx() == EEnvFxType::Rain) {
|
2019-03-05 08:34:43 +00:00
|
|
|
if (HasModelData() && !GetModelData()->IsNull() && mgr.GetEnvFxManager()->IsSplashActive() &&
|
2020-04-12 18:54:47 +00:00
|
|
|
mgr.GetEnvFxManager()->GetRainMagnitude() != 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.GetActorModelParticles()->AddRainSplashGenerator(*this, mgr, x34c_maxRainSplashes, x350_rainGenRate, 0.f);
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-06-08 21:00:18 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!x328_slavesStatic.empty() || !x338_slavesDynamic.empty()) {
|
2021-06-06 23:53:41 +00:00
|
|
|
rstl::reserved_vector<u16, kMaxEntities> draggedSet;
|
2018-12-08 05:30:43 +00:00
|
|
|
DragSlaves(mgr, draggedSet, x270_dragDelta);
|
|
|
|
}
|
2018-06-08 21:00:18 +00:00
|
|
|
|
2020-04-12 18:54:47 +00:00
|
|
|
if (x356_24_dead) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (HealthInfo(mgr)->GetHP() <= 0.f) {
|
|
|
|
x356_24_dead = true;
|
|
|
|
SendScriptMsgs(EScriptObjectState::Dead, mgr, EScriptObjectMessage::None);
|
|
|
|
}
|
2018-06-08 21:00:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptPlatform::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) {
|
|
|
|
CActor::PreRender(mgr, frustum);
|
2020-04-12 18:54:47 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!xe4_30_outOfFrustum && !zeus::close_enough(x348_xrayAlpha, 1.f)) {
|
2020-04-12 18:54:47 +00:00
|
|
|
const CModelFlags flags(5, 0, 3, {1.f, x348_xrayAlpha});
|
2018-12-08 05:30:43 +00:00
|
|
|
if (mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::XRay && !x356_30_disableXrayAlpha) {
|
|
|
|
xb4_drawFlags = flags;
|
|
|
|
x356_29_setXrayDrawFlags = true;
|
|
|
|
} else if (x356_29_setXrayDrawFlags) {
|
|
|
|
x356_29_setXrayDrawFlags = false;
|
2020-04-12 18:54:47 +00:00
|
|
|
if (xb4_drawFlags == flags && !x356_30_disableXrayAlpha) {
|
2019-02-24 07:15:54 +00:00
|
|
|
xb4_drawFlags = CModelFlags(0, 0, 3, zeus::skWhite);
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-12 18:54:47 +00:00
|
|
|
|
|
|
|
if (!mgr.GetObjectById(x354_boundsTrigger)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x354_boundsTrigger = kInvalidUniqueId;
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 17:28:20 +00:00
|
|
|
void CScriptPlatform::Render(CStateManager& mgr) {
|
2020-04-12 18:54:47 +00:00
|
|
|
const bool xray = mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::XRay;
|
|
|
|
if (xray && !x356_31_xrayFog) {
|
2019-02-24 07:15:54 +00:00
|
|
|
g_Renderer->SetWorldFog(ERglFogMode::None, 0.f, 1.f, zeus::skBlack);
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CPhysicsActor::Render(mgr);
|
2020-04-12 18:54:47 +00:00
|
|
|
|
|
|
|
if (xray && !x356_31_xrayFog) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.SetupFogForArea(x4_areaId);
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
|
|
|
|
2019-06-12 02:05:17 +00:00
|
|
|
std::optional<zeus::CAABox> CScriptPlatform::GetTouchBounds() const {
|
2020-04-12 18:54:47 +00:00
|
|
|
if (x314_treeGroup) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return {x314_treeGroup->CalculateAABox(GetTransform())};
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return {CPhysicsActor::GetBoundingBox()};
|
2017-06-11 05:49:27 +00:00
|
|
|
}
|
2017-06-18 01:58:13 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CTransform CScriptPlatform::GetPrimitiveTransform() const {
|
|
|
|
zeus::CTransform ret = GetTransform();
|
|
|
|
ret.origin += GetPrimitiveOffset();
|
|
|
|
return ret;
|
2018-06-24 02:39:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const CCollisionPrimitive* CScriptPlatform::GetCollisionPrimitive() const {
|
2020-04-12 18:54:47 +00:00
|
|
|
if (!x314_treeGroup) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return CPhysicsActor::GetCollisionPrimitive();
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return x314_treeGroup.get();
|
2018-06-24 02:39:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f CScriptPlatform::GetOrbitPosition(const CStateManager& mgr) const { return GetAimPosition(mgr, 0.f); }
|
2018-06-29 20:21:36 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f CScriptPlatform::GetAimPosition(const CStateManager& mgr, float dt) const {
|
2020-04-12 18:54:47 +00:00
|
|
|
if (auto tb = GetTouchBounds()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return {tb->center()};
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return CPhysicsActor::GetAimPosition(mgr, dt);
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CAABox CScriptPlatform::GetSortingBounds(const CStateManager& mgr) const {
|
2020-04-12 18:54:47 +00:00
|
|
|
if (x354_boundsTrigger != kInvalidUniqueId) {
|
|
|
|
if (const TCastToConstPtr<CScriptTrigger> trig = mgr.GetObjectById(x354_boundsTrigger)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return trig->GetTriggerBoundsWR();
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return CActor::GetSortingBounds(mgr);
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CScriptPlatform::IsRider(TUniqueId id) const {
|
2020-04-12 19:11:21 +00:00
|
|
|
return std::any_of(x318_riders.cbegin(), x318_riders.cend(), [id](const auto& rider) { return rider.x0_uid == id; });
|
2017-06-18 01:58:13 +00:00
|
|
|
}
|
2018-02-12 05:30:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CScriptPlatform::IsSlave(TUniqueId id) const {
|
|
|
|
auto search = std::find_if(x328_slavesStatic.begin(), x328_slavesStatic.end(),
|
|
|
|
[id](const SRiders& rider) { return rider.x0_uid == id; });
|
2020-04-12 18:54:47 +00:00
|
|
|
if (search != x328_slavesStatic.end()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
search = std::find_if(x338_slavesDynamic.begin(), x338_slavesDynamic.end(),
|
|
|
|
[id](const SRiders& rider) { return rider.x0_uid == id; });
|
|
|
|
return search != x338_slavesDynamic.end();
|
2018-02-12 05:30:21 +00:00
|
|
|
}
|
2018-06-08 21:00:18 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptPlatform::BuildSlaveList(CStateManager& mgr) {
|
|
|
|
x328_slavesStatic.reserve(GetConnectionList().size());
|
|
|
|
for (const SConnection& conn : GetConnectionList()) {
|
|
|
|
if (conn.x0_state == EScriptObjectState::Play && conn.x4_msg == EScriptObjectMessage::Activate) {
|
2020-04-12 18:54:47 +00:00
|
|
|
if (const TCastToPtr<CActor> act = mgr.ObjectById(mgr.GetIdForScript(conn.x8_objId))) {
|
2018-12-08 05:30:43 +00:00
|
|
|
act->AddMaterial(EMaterialTypes::PlatformSlave, mgr);
|
|
|
|
zeus::CTransform xf = act->GetTransform();
|
|
|
|
xf.origin = act->GetTranslation() - GetTranslation();
|
|
|
|
x328_slavesStatic.emplace_back(act->GetUniqueId(), 0.166667f, xf);
|
|
|
|
}
|
|
|
|
} else if (conn.x0_state == EScriptObjectState::InheritBounds && conn.x4_msg == EScriptObjectMessage::Activate) {
|
|
|
|
auto list = mgr.GetIdListForScript(conn.x8_objId);
|
2020-04-12 18:54:47 +00:00
|
|
|
for (auto it = list.first; it != list.second; ++it) {
|
|
|
|
if (TCastToConstPtr<CScriptTrigger>(mgr.GetObjectById(it->second))) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x354_boundsTrigger = it->second;
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-06-08 21:00:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptPlatform::AddRider(std::vector<SRiders>& riders, TUniqueId riderId, const CPhysicsActor* ridee,
|
|
|
|
CStateManager& mgr) {
|
2020-04-07 19:41:26 +00:00
|
|
|
const auto& search =
|
|
|
|
std::find_if(riders.begin(), riders.end(), [riderId](const SRiders& r) { return r.x0_uid == riderId; });
|
2018-12-08 05:30:43 +00:00
|
|
|
if (search == riders.end()) {
|
|
|
|
zeus::CTransform xf;
|
2020-04-12 18:54:47 +00:00
|
|
|
if (const TCastToPtr<CPhysicsActor> act = mgr.ObjectById(riderId)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
xf.origin = ridee->GetTransform().transposeRotate(act->GetTranslation() - ridee->GetTranslation());
|
|
|
|
mgr.SendScriptMsg(act.GetPtr(), ridee->GetUniqueId(), EScriptObjectMessage::AddPlatformRider);
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
riders.emplace_back(riderId, 0.166667f, xf);
|
|
|
|
} else {
|
|
|
|
search->x4_decayTimer = 0.166667f;
|
|
|
|
}
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
2018-06-08 21:00:18 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptPlatform::AddSlave(TUniqueId id, CStateManager& mgr) {
|
2020-04-07 19:41:26 +00:00
|
|
|
const auto& search = std::find_if(x338_slavesDynamic.begin(), x338_slavesDynamic.end(),
|
2020-05-07 06:19:58 +00:00
|
|
|
[id](const SRiders& r) { return r.x0_uid == id; });
|
2020-04-12 18:54:47 +00:00
|
|
|
if (search != x338_slavesDynamic.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const TCastToPtr<CActor> act = mgr.ObjectById(id)) {
|
|
|
|
act->AddMaterial(EMaterialTypes::PlatformSlave, mgr);
|
|
|
|
const zeus::CTransform localXf = x34_transform.inverse() * act->GetTransform();
|
|
|
|
x338_slavesDynamic.emplace_back(id, 0.166667f, localXf);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-06-08 21:00:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
TUniqueId CScriptPlatform::GetNext(TUniqueId uid, CStateManager& mgr) {
|
2020-04-12 18:54:47 +00:00
|
|
|
const TCastToConstPtr<CScriptWaypoint> nextWp = mgr.GetObjectById(uid);
|
|
|
|
if (!nextWp) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return GetWaypoint(mgr);
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2018-06-08 21:00:18 +00:00
|
|
|
|
2020-04-12 18:54:47 +00:00
|
|
|
const TUniqueId next = nextWp->NextWaypoint(mgr);
|
|
|
|
if (const TCastToConstPtr<CScriptWaypoint> wp = mgr.GetObjectById(next)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x25c_currentSpeed = wp->GetSpeed();
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2018-06-08 21:00:18 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return next;
|
2018-06-08 21:00:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
TUniqueId CScriptPlatform::GetWaypoint(CStateManager& mgr) {
|
|
|
|
for (const SConnection& conn : x20_conns) {
|
2020-04-12 18:54:47 +00:00
|
|
|
if (conn.x4_msg == EScriptObjectMessage::Follow) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return mgr.GetIdForScript(conn.x8_objId);
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-06-08 21:00:18 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return kInvalidUniqueId;
|
2018-06-08 21:00:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptPlatform::SplashThink(const zeus::CAABox&, const CFluidPlane&, float, CStateManager&) const {
|
|
|
|
// Empty
|
2018-06-08 21:00:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CQuaternion CScriptPlatform::Move(float dt, CStateManager& mgr) {
|
|
|
|
TUniqueId nextWaypoint = x25a_targetWaypoint;
|
2020-04-12 18:54:47 +00:00
|
|
|
if (x25a_targetWaypoint == kInvalidUniqueId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
nextWaypoint = GetNext(x258_currentWaypoint, mgr);
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2018-06-08 21:00:18 +00:00
|
|
|
|
2020-04-12 18:54:47 +00:00
|
|
|
const TCastToConstPtr<CScriptWaypoint> wp = mgr.ObjectById(nextWaypoint);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x258_currentWaypoint != kInvalidUniqueId && wp && !wp->GetActive()) {
|
|
|
|
nextWaypoint = GetNext(x258_currentWaypoint, mgr);
|
2020-04-12 18:54:47 +00:00
|
|
|
if (nextWaypoint == kInvalidUniqueId) {
|
|
|
|
if (const TCastToConstPtr<CScriptWaypoint> wp2 = mgr.ObjectById(x258_currentWaypoint)) {
|
|
|
|
if (wp2->GetActive()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
nextWaypoint = x258_currentWaypoint;
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-06-29 20:21:36 +00:00
|
|
|
|
2020-04-12 18:54:47 +00:00
|
|
|
if (nextWaypoint == kInvalidUniqueId) {
|
2019-02-24 07:15:54 +00:00
|
|
|
return zeus::CQuaternion();
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2018-06-29 20:21:36 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
while (nextWaypoint != kInvalidUniqueId) {
|
2020-04-12 18:54:47 +00:00
|
|
|
if (const TCastToPtr<CScriptWaypoint> wp2 = mgr.ObjectById(nextWaypoint)) {
|
|
|
|
const zeus::CVector3f platToWp = wp2->GetTranslation() - GetTranslation();
|
2019-02-24 07:15:54 +00:00
|
|
|
if (zeus::close_enough(platToWp, zeus::skZero3f)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x258_currentWaypoint = nextWaypoint;
|
2020-04-12 18:54:47 +00:00
|
|
|
mgr.SendScriptMsg(wp2.GetPtr(), GetUniqueId(), EScriptObjectMessage::Arrived);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (zeus::close_enough(x25c_currentSpeed, 0.f, 0.02)) {
|
|
|
|
nextWaypoint = GetNext(x258_currentWaypoint, mgr);
|
|
|
|
x25c_currentSpeed = 0.f;
|
|
|
|
Stop();
|
|
|
|
} else {
|
|
|
|
nextWaypoint = GetNext(x258_currentWaypoint, mgr);
|
|
|
|
}
|
2018-06-29 20:21:36 +00:00
|
|
|
|
2020-04-12 18:54:47 +00:00
|
|
|
if (nextWaypoint != kInvalidUniqueId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
mgr.SendScriptMsg(this, GetUniqueId(), EScriptObjectMessage::Stop);
|
|
|
|
}
|
|
|
|
|
2019-02-24 07:15:54 +00:00
|
|
|
if (zeus::close_enough(platToWp, zeus::skZero3f)) {
|
2020-04-12 18:54:47 +00:00
|
|
|
x270_dragDelta = wp2->GetTranslation() - GetTranslation();
|
2018-12-08 05:30:43 +00:00
|
|
|
MoveToWR(GetTranslation(), dt);
|
|
|
|
} else if ((platToWp.normalized() * x25c_currentSpeed * dt).magSquared() > platToWp.magSquared()) {
|
2020-04-12 18:54:47 +00:00
|
|
|
x270_dragDelta = wp2->GetTranslation() - GetTranslation();
|
|
|
|
MoveToWR(wp2->GetTranslation(), dt);
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
x270_dragDelta = platToWp.normalized() * x25c_currentSpeed * dt;
|
|
|
|
MoveToWR(GetTranslation() + x270_dragDelta, dt);
|
|
|
|
}
|
|
|
|
|
2021-06-07 00:07:45 +00:00
|
|
|
EntityList nearList;
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.BuildColliderList(nearList, *this, GetMotionVolume(dt));
|
2021-06-07 00:07:45 +00:00
|
|
|
EntityList nonRiders;
|
2020-04-12 18:54:47 +00:00
|
|
|
for (TUniqueId id : nearList) {
|
|
|
|
if (!IsRider(id) && !IsSlave(id)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
nonRiders.push_back(id);
|
2020-04-12 18:54:47 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (x356_26_detectCollision) {
|
2020-04-12 18:54:47 +00:00
|
|
|
const CMotionState mState = PredictMotion(dt);
|
2018-12-08 05:30:43 +00:00
|
|
|
MoveCollisionPrimitive(mState.x0_translation);
|
2020-04-12 18:54:47 +00:00
|
|
|
const bool collision = CGameCollision::DetectDynamicCollisionBoolean(*GetCollisionPrimitive(),
|
|
|
|
GetPrimitiveTransform(), nonRiders, mgr);
|
2019-02-24 07:15:54 +00:00
|
|
|
MoveCollisionPrimitive(zeus::skZero3f);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (collision || x356_27_squishedRider) {
|
|
|
|
if (x356_26_detectCollision) {
|
|
|
|
if (x264_collisionRecoverDelay <= 0.f && !x356_27_squishedRider) {
|
|
|
|
x264_collisionRecoverDelay = 0.035f;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
x356_27_squishedRider = false;
|
2020-04-12 18:54:47 +00:00
|
|
|
const TUniqueId prevWaypoint = nextWaypoint;
|
2018-12-08 05:30:43 +00:00
|
|
|
nextWaypoint = GetNext(nextWaypoint, mgr);
|
|
|
|
if (x25a_targetWaypoint == nextWaypoint || x25a_targetWaypoint == prevWaypoint) {
|
|
|
|
x260_moveDelay = 0.035f;
|
2018-06-29 20:21:36 +00:00
|
|
|
break;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
2018-06-29 20:21:36 +00:00
|
|
|
break;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
AddMotionState(mState);
|
|
|
|
break;
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
xf8_24_movable = true;
|
|
|
|
CGameCollision::Move(mgr, *this, dt, &nonRiders);
|
|
|
|
xf8_24_movable = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nextWaypoint = kInvalidUniqueId;
|
|
|
|
break;
|
2018-06-29 20:21:36 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-06-29 20:21:36 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x25a_targetWaypoint = nextWaypoint;
|
2019-02-24 07:15:54 +00:00
|
|
|
return zeus::CQuaternion();
|
2018-06-08 21:00:18 +00:00
|
|
|
}
|
2018-06-29 20:21:36 +00:00
|
|
|
|
2021-01-17 03:33:03 +00:00
|
|
|
void CScriptPlatform::DebugDraw() {
|
|
|
|
if (!m_boxFilter) {
|
|
|
|
m_boxFilter = {CAABoxShader()};
|
|
|
|
}
|
|
|
|
|
|
|
|
m_boxFilter->setAABB(*GetTouchBounds());
|
|
|
|
m_boxFilter->draw({1.f, 0.f, 1.f, .5f});
|
|
|
|
}
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|