From 9d105a287d28916a3e5c6f1eac65bebbb9eb901e Mon Sep 17 00:00:00 2001
From: Aaron Kimbrell <aronwk.aaron@gmail.com>
Date: Sat, 13 May 2023 15:47:28 -0500
Subject: [PATCH] fix: not everything attached to a path is a moving platform
 (#1090)

---
 dGame/Entity.cpp | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp
index 4345d2db..68ab0c7a 100644
--- a/dGame/Entity.cpp
+++ b/dGame/Entity.cpp
@@ -690,11 +690,30 @@ void Entity::Initialize() {
 	}
 
 	std::string pathName = GetVarAsString(u"attached_path");
+	const Path* path = dZoneManager::Instance()->GetZone()->GetPath(pathName);
 
-	int32_t movingPlatformComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MOVING_PLATFORM, -1);
-	if (movingPlatformComponentId >= 0 || !pathName.empty()) {
-		MovingPlatformComponent* plat = new MovingPlatformComponent(this, pathName);
-		m_Components.insert(std::make_pair(eReplicaComponentType::MOVING_PLATFORM, plat));
+	//Check to see if we have an attached path and add the appropiate component to handle it:
+	if (path){
+		// if we have a moving platform path, then we need a moving platform component
+		if (path->pathType == PathType::MovingPlatform) {
+			MovingPlatformComponent* plat = new MovingPlatformComponent(this, pathName);
+			m_Components.insert(std::make_pair(eReplicaComponentType::MOVING_PLATFORM, plat));
+		// else if we are a movement path
+		} /*else if (path->pathType == PathType::Movement) {
+			auto movementAIcomp = GetComponent<MovementAIComponent>();
+			if (movementAIcomp){
+				// TODO: set path in existing movementAIComp
+			} else {
+				// TODO: create movementAIcomp and set path
+			}
+		}*/
+	} else {
+		// else we still need to setup moving platform if it has a moving platform comp but no path
+		int32_t movingPlatformComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MOVING_PLATFORM, -1);
+		if (movingPlatformComponentId >= 0) {
+			MovingPlatformComponent* plat = new MovingPlatformComponent(this, pathName);
+			m_Components.insert(std::make_pair(eReplicaComponentType::MOVING_PLATFORM, plat));
+		}
 	}
 
 	int proximityMonitorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROXIMITY_MONITOR);