From 4fbd536e742d8f5fe42380d69a7586e4fac47509 Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Mon, 7 Aug 2023 19:23:17 -0700 Subject: [PATCH] add movementAI on load --- dGame/Entity.cpp | 16 ++++++++-------- dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp | 8 +++++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 237cfa73..33cef963 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -702,20 +702,20 @@ void Entity::Initialize() { const Path* path = Game::zoneManager->GetZone()->GetPath(pathName); //Check to see if we have an attached path and add the appropiate component to handle it: - if (path){ + 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) { + } else if (path->pathType == PathType::Movement) { + Game::logger->Log("Entity", "is movement %i", GetLOT()); auto movementAIcomp = GetComponent(); - if (movementAIcomp){ - // TODO: set path in existing movementAIComp - } else { - // TODO: create movementAIcomp and set path + if (!movementAIcomp) { + movementAIcomp = new MovementAIComponent(this, {}); + m_Components.insert(std::make_pair(eReplicaComponentType::MOVEMENT_AI, movementAIcomp)); } - }*/ + movementAIcomp->SetupPath(pathName); + } } 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); diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp index 112636cb..6312d4f6 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp @@ -287,9 +287,11 @@ void SGCannon::OnActivityTimerDone(Entity* self, const std::string& name) { auto* enemy = Game::entityManager->CreateEntity(info, nullptr, self); Game::entityManager->ConstructEntity(enemy); - auto* movementAI = new MovementAIComponent(enemy, {}); - - enemy->AddComponent(eReplicaComponentType::MOVEMENT_AI, movementAI); + auto* movementAI = enemy->GetComponent(); + if (!movementAI) { + movementAI = new MovementAIComponent(enemy, {}); + enemy->AddComponent(eReplicaComponentType::MOVEMENT_AI, movementAI); + } movementAI->SetMaxSpeed(toSpawn.initialSpeed); movementAI->SetCurrentSpeed(toSpawn.initialSpeed);