2021-12-05 17:54:36 +00:00
|
|
|
/*
|
|
|
|
* Darkflame Universe
|
|
|
|
* Copyright 2019
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "MovingPlatformComponent.h"
|
|
|
|
#include "BitStream.h"
|
|
|
|
#include "GeneralUtils.h"
|
|
|
|
#include "dZoneManager.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "dLogger.h"
|
|
|
|
#include "GameMessages.h"
|
|
|
|
#include "CppScripts.h"
|
|
|
|
#include "SimplePhysicsComponent.h"
|
2023-08-01 08:19:07 +00:00
|
|
|
#include "CDClientManager.h"
|
|
|
|
#include "CDMovingPlatformComponentTable.h"
|
2023-01-07 05:17:05 +00:00
|
|
|
#include "Zone.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-08-01 08:19:07 +00:00
|
|
|
//------------- PlatformSubComponent begin --------------
|
|
|
|
|
|
|
|
PlatformSubComponent::PlatformSubComponent(MovingPlatformComponent* parentComponent) {
|
2023-07-31 09:13:19 +00:00
|
|
|
m_Position = NiPoint3::ZERO;
|
2023-08-01 08:19:07 +00:00
|
|
|
m_ParentComponent = parentComponent;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
m_State = eMovementPlatformState::Stopped | eMovementPlatformState::ReachedDesiredWaypoint;
|
|
|
|
m_DesiredWaypointIndex = 0;
|
|
|
|
m_InReverse = false;
|
|
|
|
m_ShouldStopAtDesiredWaypoint = false;
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2023-08-03 08:50:34 +00:00
|
|
|
m_PercentUntilNextWaypoint = 0.0f;
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
m_CurrentWaypointIndex = 0;
|
|
|
|
m_NextWaypointIndex = 0;
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
m_IdleTimeElapsed = 0.0f;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-08-03 08:50:34 +00:00
|
|
|
void PlatformSubComponent::AdvanceToNextWaypoint() {
|
|
|
|
uint32_t numWaypoints = m_Path->pathWaypoints.size();
|
|
|
|
m_CurrentWaypointIndex = m_NextWaypointIndex;
|
|
|
|
uint32_t nextWaypointIndex = m_CurrentWaypointIndex;
|
|
|
|
if (numWaypoints <= nextWaypointIndex) {
|
|
|
|
PathBehavior behavior = m_Path->pathBehavior;
|
|
|
|
if (behavior == PathBehavior::Once) {
|
|
|
|
nextWaypointIndex = m_Path->pathWaypoints.size() - 1;
|
|
|
|
} else if (behavior == PathBehavior::Bounce) {
|
|
|
|
nextWaypointIndex = m_Path->pathWaypoints.size() - 2;
|
|
|
|
m_InReverse = true;
|
|
|
|
} else {
|
|
|
|
m_NextWaypointIndex = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_NextWaypointIndex = nextWaypointIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlatformSubComponent::AdvanceToNextReverseWaypoint() {
|
|
|
|
uint32_t numWaypoints = m_Path->pathWaypoints.size();
|
|
|
|
m_CurrentWaypointIndex = m_NextWaypointIndex;
|
|
|
|
int32_t nextWaypointIndex = m_CurrentWaypointIndex;
|
|
|
|
if (nextWaypointIndex < 0) {
|
|
|
|
PathBehavior behavior = m_Path->pathBehavior;
|
|
|
|
if (behavior == PathBehavior::Once) {
|
|
|
|
nextWaypointIndex = 0;
|
|
|
|
} else if (behavior == PathBehavior::Bounce) {
|
|
|
|
nextWaypointIndex = 1;
|
|
|
|
m_InReverse = false;
|
|
|
|
} else {
|
|
|
|
nextWaypointIndex = m_Path->pathWaypoints.size() - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_NextWaypointIndex = nextWaypointIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlatformSubComponent::SetupPath(const std::string& pathName, uint32_t startingWaypointIndex, bool startsInReverse) {
|
|
|
|
m_Path = Game::zoneManager->GetZone()->GetPath(pathName);
|
|
|
|
if (!m_Path) {
|
|
|
|
Game::logger->Log("MovingPlatformComponent", "Failed to find path (%s)", pathName.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_InReverse = startsInReverse;
|
|
|
|
m_CurrentWaypointIndex = startingWaypointIndex;
|
|
|
|
m_TimeBasedMovement = m_Path->movingPlatform.timeBasedMovement;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PathWaypoint PlatformSubComponent::GetNextWaypoint() const {
|
|
|
|
DluAssert(m_Path != nullptr);
|
|
|
|
if (m_NextWaypointIndex >= m_Path->pathWaypoints.size()) return PathWaypoint();
|
|
|
|
return m_Path->pathWaypoints.at(m_NextWaypointIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
const PathWaypoint PlatformSubComponent::GetCurrentWaypoint() const {
|
|
|
|
DluAssert(m_Path != nullptr);
|
|
|
|
if (m_CurrentWaypointIndex >= m_Path->pathWaypoints.size()) return PathWaypoint();
|
|
|
|
return m_Path->pathWaypoints.at(m_CurrentWaypointIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
float PlatformSubComponent::CalculateSpeed() const {
|
|
|
|
float speed;
|
|
|
|
if (m_TimeBasedMovement) {
|
|
|
|
float unitizedDirection = 1.0f / (GetNextWaypoint().position - GetCurrentWaypoint().position).Length();
|
|
|
|
speed = unitizedDirection / GetCurrentWaypoint().movingPlatform.speed;
|
|
|
|
} else {
|
|
|
|
speed = (GetNextWaypoint().movingPlatform.speed - GetCurrentWaypoint().movingPlatform.speed) * m_PercentUntilNextWaypoint + GetCurrentWaypoint().movingPlatform.speed;
|
|
|
|
}
|
|
|
|
return speed;
|
|
|
|
}
|
|
|
|
|
|
|
|
NiPoint3 PlatformSubComponent::CalculateLinearVelocity() {
|
|
|
|
return (GetNextWaypoint().position - GetCurrentWaypoint().position).Unitize() * CalculateSpeed();
|
|
|
|
}
|
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
void PlatformSubComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
2023-08-01 08:19:07 +00:00
|
|
|
outBitStream->Write(bIsInitialUpdate || m_IsDirty);
|
|
|
|
if (!(bIsInitialUpdate || m_IsDirty)) return;
|
2023-07-31 09:13:19 +00:00
|
|
|
outBitStream->Write(m_State);
|
|
|
|
outBitStream->Write(m_DesiredWaypointIndex);
|
|
|
|
outBitStream->Write(m_ShouldStopAtDesiredWaypoint);
|
|
|
|
outBitStream->Write(m_InReverse);
|
2023-08-03 08:50:34 +00:00
|
|
|
outBitStream->Write(m_PercentUntilNextWaypoint);
|
2023-07-31 09:13:19 +00:00
|
|
|
outBitStream->Write(m_Position.x);
|
|
|
|
outBitStream->Write(m_Position.y);
|
|
|
|
outBitStream->Write(m_Position.z);
|
|
|
|
outBitStream->Write(m_CurrentWaypointIndex);
|
|
|
|
outBitStream->Write(m_NextWaypointIndex);
|
|
|
|
outBitStream->Write(m_IdleTimeElapsed);
|
|
|
|
outBitStream->Write(m_MoveTimeElapsed);
|
|
|
|
if (!bIsInitialUpdate) m_IsDirty = false;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-08-02 07:02:02 +00:00
|
|
|
void PlatformSubComponent::StartPathing() {
|
|
|
|
m_State |= eMovementPlatformState::Travelling;
|
|
|
|
m_State &= ~eMovementPlatformState::Stopped;
|
|
|
|
m_State &= ~eMovementPlatformState::Waiting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlatformSubComponent::ResumePathing() {
|
|
|
|
if (m_State & eMovementPlatformState::Stopped && (m_State & eMovementPlatformState::ReachedDesiredWaypoint) == 0) {
|
|
|
|
StartPathing();
|
|
|
|
}
|
|
|
|
if (m_State & eMovementPlatformState::Travelling == 0) {
|
|
|
|
m_State |= eMovementPlatformState::Waiting;
|
|
|
|
m_State &= ~eMovementPlatformState::Stopped;
|
|
|
|
m_State &= ~eMovementPlatformState::Travelling;
|
|
|
|
} else {
|
|
|
|
m_State &= eMovementPlatformState::Waiting;
|
|
|
|
m_State &= eMovementPlatformState::Travelling;
|
|
|
|
m_State &= eMovementPlatformState::Stopped;
|
|
|
|
// Set the velocities
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlatformSubComponent::StopPathing() {
|
|
|
|
m_State |= eMovementPlatformState::Stopped;
|
|
|
|
m_State &= ~eMovementPlatformState::Travelling;
|
|
|
|
m_State &= ~eMovementPlatformState::Waiting;
|
|
|
|
m_LinearVelocity = NiPoint3::ZERO;
|
|
|
|
m_AngularVelocity = NiPoint3::ZERO;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlatformSubComponent::Update(float deltaTime) {
|
|
|
|
if (m_TimeBasedMovement && m_State & eMovementPlatformState::Travelling) {
|
|
|
|
m_MoveTimeElapsed += deltaTime;
|
|
|
|
}
|
|
|
|
if (m_State == 0) return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-08-01 08:19:07 +00:00
|
|
|
//------------- PlatformSubComponent end --------------
|
|
|
|
|
|
|
|
//------------- MoverPlatformSubComponent begin --------------
|
|
|
|
|
|
|
|
MoverPlatformSubComponent::MoverPlatformSubComponent(MovingPlatformComponent* parentComponent) : PlatformSubComponent(parentComponent) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------- MoverPlatformSubComponent end --------------
|
|
|
|
|
|
|
|
//------------- RotatorPlatformSubComponent begin --------------
|
|
|
|
|
|
|
|
RotatorPlatformSubComponent::RotatorPlatformSubComponent(MovingPlatformComponent* parentComponent) : PlatformSubComponent(parentComponent) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------- RotatorPlatformSubComponent end --------------
|
|
|
|
|
|
|
|
//------------- SimpleMoverPlatformSubComponent begin --------------
|
|
|
|
|
|
|
|
void SimpleMoverPlatformSubComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
|
|
|
outBitStream->Write(bIsInitialUpdate || m_DirtyStartingPoint);
|
|
|
|
if (bIsInitialUpdate || m_DirtyStartingPoint) {
|
|
|
|
outBitStream->Write(m_HasStartingPoint);
|
|
|
|
if (m_HasStartingPoint) {
|
|
|
|
outBitStream->Write(m_StartingPoint.x);
|
|
|
|
outBitStream->Write(m_StartingPoint.y);
|
|
|
|
outBitStream->Write(m_StartingPoint.z);
|
|
|
|
outBitStream->Write(m_StartingRotation.w);
|
|
|
|
outBitStream->Write(m_StartingRotation.x);
|
|
|
|
outBitStream->Write(m_StartingRotation.y);
|
|
|
|
outBitStream->Write(m_StartingRotation.z);
|
|
|
|
}
|
|
|
|
if (!bIsInitialUpdate) m_DirtyStartingPoint = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
outBitStream->Write(bIsInitialUpdate || m_IsDirty);
|
|
|
|
if (bIsInitialUpdate || m_IsDirty) {
|
|
|
|
outBitStream->Write(m_State);
|
|
|
|
outBitStream->Write(m_CurrentWaypointIndex);
|
|
|
|
outBitStream->Write(m_InReverse);
|
|
|
|
if (!bIsInitialUpdate) m_IsDirty = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleMoverPlatformSubComponent::LoadConfigData() {
|
|
|
|
if (m_ParentComponent->GetParent()->GetVar<bool>(u"dbonly")) return;
|
|
|
|
NiPoint3 platformMove(
|
|
|
|
m_ParentComponent->GetParent()->GetVar<float>(u"platformMoveX"),
|
|
|
|
m_ParentComponent->GetParent()->GetVar<float>(u"platformMoveY"),
|
|
|
|
m_ParentComponent->GetParent()->GetVar<float>(u"platformMoveZ")
|
|
|
|
);
|
|
|
|
m_PlatformMove = platformMove;
|
|
|
|
m_MoveTime = m_ParentComponent->GetParent()->GetVar<float>(u"platformMoveTime");
|
|
|
|
m_StartAtEnd = m_ParentComponent->GetParent()->GetVar<bool>(u"platformStartAtEnd");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleMoverPlatformSubComponent::LoadDataFromTemplate() {
|
|
|
|
if (!m_ParentComponent->GetParent()->GetVar<bool>(u"dbonly")) return;
|
|
|
|
|
|
|
|
auto* movingPlatformTable = CDClientManager::Instance().GetTable<CDMovingPlatformComponentTable>();
|
|
|
|
if (movingPlatformTable == nullptr) return;
|
|
|
|
|
|
|
|
const auto& platformEntry = movingPlatformTable->GetPlatformEntry(m_ParentComponent->GetComponentId());
|
|
|
|
if (!platformEntry || !platformEntry->platformIsSimpleMover) return;
|
|
|
|
|
|
|
|
NiPoint3 platformMove = platformEntry->platformMove;
|
|
|
|
float moveTime = platformEntry->moveTime;
|
2023-08-01 08:36:24 +00:00
|
|
|
m_PlatformMove = platformMove;
|
|
|
|
m_MoveTime = moveTime;
|
2023-08-01 08:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SimpleMoverPlatformSubComponent::SimpleMoverPlatformSubComponent(MovingPlatformComponent* parentComponent, const NiPoint3& platformMove, const bool startsInReverse) : PlatformSubComponent(parentComponent) {
|
|
|
|
m_PlatformMove = platformMove;
|
|
|
|
m_InReverse = startsInReverse;
|
|
|
|
m_HasStartingPoint = true;
|
|
|
|
m_DirtyStartingPoint = true;
|
|
|
|
m_IsDirty = true;
|
|
|
|
m_StartingPoint = m_ParentComponent->GetParent()->GetPosition();
|
|
|
|
m_StartingRotation = m_ParentComponent->GetParent()->GetRotation();
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------- SimpleMoverPlatformSubComponent end --------------
|
|
|
|
|
|
|
|
//------------- MovingPlatformComponent begin --------------
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
MovingPlatformComponent::MovingPlatformComponent(Entity* parent, const std::string& pathName) : Component(parent) {
|
|
|
|
|
2023-08-01 08:19:07 +00:00
|
|
|
}
|
|
|
|
|
2023-08-01 08:36:24 +00:00
|
|
|
void MovingPlatformComponent::LoadDataFromTemplate() {
|
|
|
|
std::for_each(m_Platforms.begin(), m_Platforms.end(), [](const std::unique_ptr<PlatformSubComponent>& platform) { platform->LoadDataFromTemplate(); });
|
|
|
|
}
|
|
|
|
|
2023-08-01 08:19:07 +00:00
|
|
|
void MovingPlatformComponent::LoadConfigData() {
|
2023-07-31 09:13:19 +00:00
|
|
|
if (m_Parent->GetVar<bool>(u"platformIsSimpleMover")) {
|
2023-08-01 08:19:07 +00:00
|
|
|
AddMovingPlatform<SimpleMoverPlatformSubComponent>(NiPoint3::ZERO, false);
|
2023-07-31 09:13:19 +00:00
|
|
|
}
|
|
|
|
if (m_Parent->GetVar<bool>(u"platformIsMover")) {
|
2023-08-01 08:19:07 +00:00
|
|
|
AddMovingPlatform<MoverPlatformSubComponent>();
|
2023-07-31 09:13:19 +00:00
|
|
|
}
|
|
|
|
if (m_Parent->GetVar<bool>(u"platformIsRotater")) {
|
2023-08-01 08:19:07 +00:00
|
|
|
AddMovingPlatform<RotatorPlatformSubComponent>();
|
2023-07-31 09:13:19 +00:00
|
|
|
}
|
2023-08-03 08:50:34 +00:00
|
|
|
m_StartingWaypointIndex = m_Parent->GetVar<uint32_t>(u"attached_path_start");
|
|
|
|
m_StartsIsInReverse = false;
|
2023-07-31 09:13:19 +00:00
|
|
|
m_DirtyPathInfo = true;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MovingPlatformComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
2023-07-31 09:13:19 +00:00
|
|
|
// For some reason we need to write this here instead of later on.
|
|
|
|
outBitStream->Write(!m_Platforms.empty());
|
|
|
|
|
|
|
|
outBitStream->Write(bIsInitialUpdate || m_DirtyPathInfo);
|
|
|
|
if (bIsInitialUpdate || m_DirtyPathInfo) {
|
|
|
|
outBitStream->Write(!m_PathName.empty());
|
|
|
|
if (!m_PathName.empty()) {
|
|
|
|
outBitStream->Write(static_cast<uint16_t>(m_PathName.size()));
|
|
|
|
for (const auto& c : m_PathName) {
|
|
|
|
outBitStream->Write(static_cast<uint16_t>(c));
|
|
|
|
}
|
2023-08-01 08:19:07 +00:00
|
|
|
outBitStream->Write(m_StartingWaypointIndex);
|
|
|
|
outBitStream->Write(m_StartsIsInReverse);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2023-07-31 09:13:19 +00:00
|
|
|
if (!bIsInitialUpdate) m_DirtyPathInfo = false;
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2023-08-01 08:19:07 +00:00
|
|
|
if (m_Platforms.empty()) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
for (const auto& platform : m_Platforms) {
|
|
|
|
outBitStream->Write1(); // Has platform to write
|
|
|
|
outBitStream->Write(platform->GetPlatformType());
|
|
|
|
platform->Serialize(outBitStream, bIsInitialUpdate);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2023-07-31 09:13:19 +00:00
|
|
|
outBitStream->Write0(); // No more platforms to write
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MovingPlatformComponent::OnRebuildInitilized() {
|
2022-07-28 13:39:57 +00:00
|
|
|
StopPathing();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MovingPlatformComponent::OnCompleteRebuild() {
|
2023-07-31 09:13:19 +00:00
|
|
|
if (m_NoAutoStart) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
StartPathing();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-01-07 05:17:05 +00:00
|
|
|
void MovingPlatformComponent::SetMovementState(eMovementPlatformState value) {
|
2023-07-31 09:13:19 +00:00
|
|
|
// auto* subComponent = static_cast<MoverSubComponent*>(m_MoverSubComponent);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// subComponent->mState = value;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// Game::entityManager->SerializeEntity(m_Parent);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void MovingPlatformComponent::GotoWaypoint(uint32_t index, bool stopAtWaypoint) {
|
2023-07-31 09:13:19 +00:00
|
|
|
// auto* subComponent = static_cast<MoverSubComponent*>(m_MoverSubComponent);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// subComponent->mDesiredWaypointIndex = index;
|
|
|
|
// subComponent->mNextWaypointIndex = index;
|
|
|
|
// subComponent->mShouldStopAtDesiredWaypoint = stopAtWaypoint;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// StartPathing();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void MovingPlatformComponent::StartPathing() {
|
2023-08-02 07:02:02 +00:00
|
|
|
std::for_each(m_Platforms.begin(), m_Platforms.end(), [](const std::unique_ptr<PlatformSubComponent>& platform) {
|
|
|
|
platform->StartPathing();
|
|
|
|
});
|
2023-08-01 08:36:24 +00:00
|
|
|
// state == Travelling
|
2023-07-31 09:13:19 +00:00
|
|
|
// //GameMessages::SendStartPathing(m_Parent);
|
|
|
|
// m_PathingStopped = false;
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// auto* subComponent = static_cast<MoverSubComponent*>(m_MoverSubComponent);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// subComponent->mShouldStopAtDesiredWaypoint = true;
|
|
|
|
// subComponent->mState = eMovementPlatformState::Stationary;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// NiPoint3 targetPosition;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// if (m_Path != nullptr) {
|
|
|
|
// const auto& currentWaypoint = m_Path->pathWaypoints[subComponent->mCurrentWaypointIndex];
|
|
|
|
// const auto& nextWaypoint = m_Path->pathWaypoints[subComponent->mNextWaypointIndex];
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// subComponent->mPosition = currentWaypoint.position;
|
|
|
|
// subComponent->mSpeed = currentWaypoint.movingPlatform.speed;
|
|
|
|
// subComponent->mWaitTime = currentWaypoint.movingPlatform.wait;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// targetPosition = nextWaypoint.position;
|
|
|
|
// } else {
|
|
|
|
// subComponent->mPosition = m_Parent->GetPosition();
|
|
|
|
// subComponent->mSpeed = 1.0f;
|
|
|
|
// subComponent->mWaitTime = 2.0f;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// targetPosition = m_Parent->GetPosition() + NiPoint3(0.0f, 10.0f, 0.0f);
|
|
|
|
// }
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// m_Parent->AddCallbackTimer(subComponent->mWaitTime, [this] {
|
|
|
|
// SetMovementState(eMovementPlatformState::Moving);
|
|
|
|
// });
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// const auto travelTime = Vector3::Distance(targetPosition, subComponent->mPosition) / subComponent->mSpeed + 1.5f;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// const auto travelNext = subComponent->mWaitTime + travelTime;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// m_Parent->AddCallbackTimer(travelTime, [subComponent, this] {
|
|
|
|
// for (CppScripts::Script* script : CppScripts::GetEntityScripts(m_Parent)) {
|
|
|
|
// script->OnWaypointReached(m_Parent, subComponent->mNextWaypointIndex);
|
|
|
|
// }
|
|
|
|
// });
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// m_Parent->AddCallbackTimer(travelNext, [this] {
|
|
|
|
// ContinuePathing();
|
|
|
|
// });
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// //GameMessages::SendPlatformResync(m_Parent, UNASSIGNED_SYSTEM_ADDRESS);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// Game::entityManager->SerializeEntity(m_Parent);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void MovingPlatformComponent::ContinuePathing() {
|
2023-08-01 08:36:24 +00:00
|
|
|
// state == Travelling
|
2023-07-31 09:13:19 +00:00
|
|
|
// auto* subComponent = static_cast<MoverSubComponent*>(m_MoverSubComponent);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// subComponent->mState = eMovementPlatformState::Stationary;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// subComponent->mCurrentWaypointIndex = subComponent->mNextWaypointIndex;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// NiPoint3 targetPosition;
|
|
|
|
// uint32_t pathSize;
|
|
|
|
// PathBehavior behavior;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// if (m_Path != nullptr) {
|
|
|
|
// const auto& currentWaypoint = m_Path->pathWaypoints[subComponent->mCurrentWaypointIndex];
|
|
|
|
// const auto& nextWaypoint = m_Path->pathWaypoints[subComponent->mNextWaypointIndex];
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// subComponent->mPosition = currentWaypoint.position;
|
|
|
|
// subComponent->mSpeed = currentWaypoint.movingPlatform.speed;
|
|
|
|
// subComponent->mWaitTime = currentWaypoint.movingPlatform.wait; // + 2;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// pathSize = m_Path->pathWaypoints.size() - 1;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// behavior = static_cast<PathBehavior>(m_Path->pathBehavior);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// targetPosition = nextWaypoint.position;
|
|
|
|
// } else {
|
|
|
|
// subComponent->mPosition = m_Parent->GetPosition();
|
|
|
|
// subComponent->mSpeed = 1.0f;
|
|
|
|
// subComponent->mWaitTime = 2.0f;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// targetPosition = m_Parent->GetPosition() + NiPoint3(0.0f, 10.0f, 0.0f);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// pathSize = 1;
|
|
|
|
// behavior = PathBehavior::Loop;
|
|
|
|
// }
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// if (m_Parent->GetLOT() == 9483) {
|
|
|
|
// behavior = PathBehavior::Bounce;
|
|
|
|
// } else {
|
|
|
|
// return;
|
|
|
|
// }
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// if (subComponent->mCurrentWaypointIndex >= pathSize) {
|
|
|
|
// subComponent->mCurrentWaypointIndex = pathSize;
|
|
|
|
// switch (behavior) {
|
|
|
|
// case PathBehavior::Once:
|
|
|
|
// Game::entityManager->SerializeEntity(m_Parent);
|
|
|
|
// return;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// case PathBehavior::Bounce:
|
|
|
|
// subComponent->mInReverse = true;
|
|
|
|
// break;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// case PathBehavior::Loop:
|
|
|
|
// subComponent->mNextWaypointIndex = 0;
|
|
|
|
// break;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// default:
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// } else if (subComponent->mCurrentWaypointIndex == 0) {
|
|
|
|
// subComponent->mInReverse = false;
|
|
|
|
// }
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// if (subComponent->mInReverse) {
|
|
|
|
// subComponent->mNextWaypointIndex = subComponent->mCurrentWaypointIndex - 1;
|
|
|
|
// } else {
|
|
|
|
// subComponent->mNextWaypointIndex = subComponent->mCurrentWaypointIndex + 1;
|
|
|
|
// }
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// /*
|
|
|
|
// subComponent->mNextWaypointIndex = 0;
|
|
|
|
// subComponent->mCurrentWaypointIndex = 1;
|
|
|
|
// */
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// //GameMessages::SendPlatformResync(m_Parent, UNASSIGNED_SYSTEM_ADDRESS);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// if (subComponent->mCurrentWaypointIndex == subComponent->mDesiredWaypointIndex) {
|
|
|
|
// // TODO: Send event?
|
|
|
|
// StopPathing();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// return;
|
|
|
|
// }
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// m_Parent->CancelCallbackTimers();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// m_Parent->AddCallbackTimer(subComponent->mWaitTime, [this] {
|
|
|
|
// SetMovementState(eMovementPlatformState::Moving);
|
|
|
|
// });
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// auto travelTime = Vector3::Distance(targetPosition, subComponent->mPosition) / subComponent->mSpeed + 1.5;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// if (m_Parent->GetLOT() == 9483) {
|
|
|
|
// travelTime += 20;
|
|
|
|
// }
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// const auto travelNext = subComponent->mWaitTime + travelTime;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// m_Parent->AddCallbackTimer(travelTime, [subComponent, this] {
|
|
|
|
// for (CppScripts::Script* script : CppScripts::GetEntityScripts(m_Parent)) {
|
|
|
|
// script->OnWaypointReached(m_Parent, subComponent->mNextWaypointIndex);
|
|
|
|
// }
|
|
|
|
// });
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// m_Parent->AddCallbackTimer(travelNext, [this] {
|
|
|
|
// ContinuePathing();
|
|
|
|
// });
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// Game::entityManager->SerializeEntity(m_Parent);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void MovingPlatformComponent::StopPathing() {
|
2023-08-01 08:36:24 +00:00
|
|
|
// state == Stopped
|
2022-07-28 13:39:57 +00:00
|
|
|
//m_Parent->CancelCallbackTimers();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// auto* subComponent = static_cast<MoverSubComponent*>(m_MoverSubComponent);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// m_PathingStopped = true;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// subComponent->mState = eMovementPlatformState::Stopped;
|
|
|
|
// subComponent->mDesiredWaypointIndex = -1;
|
|
|
|
// subComponent->mShouldStopAtDesiredWaypoint = false;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// Game::entityManager->SerializeEntity(m_Parent);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
//GameMessages::SendPlatformResync(m_Parent, UNASSIGNED_SYSTEM_ADDRESS);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
bool MovingPlatformComponent::GetNoAutoStart() const {
|
2023-07-31 09:13:19 +00:00
|
|
|
return false;
|
|
|
|
// return m_NoAutoStart;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void MovingPlatformComponent::SetNoAutoStart(const bool value) {
|
2023-07-31 09:13:19 +00:00
|
|
|
// m_NoAutoStart = value;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void MovingPlatformComponent::WarpToWaypoint(size_t index) {
|
2023-07-31 09:13:19 +00:00
|
|
|
// const auto& waypoint = m_Path->pathWaypoints[index];
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// m_Parent->SetPosition(waypoint.position);
|
|
|
|
// m_Parent->SetRotation(waypoint.rotation);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-31 09:13:19 +00:00
|
|
|
// Game::entityManager->SerializeEntity(m_Parent);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
size_t MovingPlatformComponent::GetLastWaypointIndex() const {
|
2023-07-31 09:13:19 +00:00
|
|
|
return 0;
|
|
|
|
// return m_Path->pathWaypoints.size() - 1;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2023-08-01 08:19:07 +00:00
|
|
|
|
|
|
|
//------------- MovingPlatformComponent end --------------
|