BVB Source Codes

CRYENGINE Show BehaviorTreeGraft.cpp Source code

Return Download CRYENGINE: download BehaviorTreeGraft.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4. #include "BehaviorTreeGraft.h"
  5. #include "BehaviorTreeManager.h"
  6. #include <CryAISystem/BehaviorTree/IBehaviorTree.h>
  7.  
  8. namespace BehaviorTree
  9. {
  10. void GraftManager::Reset()
  11. {
  12.         m_activeGraftNodes.clear();
  13.         m_graftModeRequests.clear();
  14.         m_graftBehaviorRequests.clear();
  15. }
  16.  
  17. void GraftManager::GraftNodeReady(EntityId entityId, IGraftNode* graftNode)
  18. {
  19.         std::pair<ActiveGraftNodesContainer::iterator, bool> insertResult = m_activeGraftNodes.insert(std::make_pair(entityId, graftNode));
  20.         if (!insertResult.second)
  21.         {
  22.                 IEntity* entity = gEnv->pEntitySystem->GetEntity(entityId);
  23.                 gEnv->pLog->LogError("Graft Manager: More than one graft node is running for the entity '%s'", entity->GetName());
  24.                 return;
  25.         }
  26.  
  27.         GraftModeRequestsContainer::iterator requestIt = m_graftModeRequests.find(entityId);
  28.         if (requestIt != m_graftModeRequests.end() && requestIt->second != NULL)
  29.         {
  30.                 requestIt->second->GraftModeReady(entityId);
  31.         }
  32.         else
  33.         {
  34.                 IEntity* entity = gEnv->pEntitySystem->GetEntity(entityId);
  35.                 gEnv->pLog->LogError("Graft Manager: A graft node is running for the entity '%s' without a corresponding request.", entity->GetName());
  36.         }
  37. }
  38.  
  39. void GraftManager::GraftNodeTerminated(EntityId entityId)
  40. {
  41.         GraftModeRequestsContainer::iterator graftModeRequestIt = m_graftModeRequests.find(entityId);
  42.         if (graftModeRequestIt != m_graftModeRequests.end() && graftModeRequestIt->second != NULL)
  43.         {
  44.                 graftModeRequestIt->second->GraftModeInterrupted(entityId);
  45.                 m_graftModeRequests.erase(graftModeRequestIt);
  46.         }
  47.  
  48.         ActiveGraftNodesContainer::iterator activeGraftNodeIt = m_activeGraftNodes.find(entityId);
  49.         if (activeGraftNodeIt != m_activeGraftNodes.end())
  50.         {
  51.                 m_activeGraftNodes.erase(activeGraftNodeIt);
  52.         }
  53.  
  54.         m_graftBehaviorRequests.erase(entityId);
  55. }
  56.  
  57. void GraftManager::GraftBehaviorComplete(EntityId entityId)
  58. {
  59.         GraftBehaviorRequestsContainer::iterator graftBehaviorRequestIt = m_graftBehaviorRequests.find(entityId);
  60.         if (graftBehaviorRequestIt != m_graftBehaviorRequests.end() && graftBehaviorRequestIt->second != NULL)
  61.         {
  62.                 graftBehaviorRequestIt->second->GraftBehaviorComplete(entityId);
  63.         }
  64.         else
  65.         {
  66.                 IEntity* entity = gEnv->pEntitySystem->GetEntity(entityId);
  67.                 gEnv->pLog->LogError("Graft Manager: A graft behavior is complete for the entity '%s' without a corresponding request.", entity->GetName());
  68.         }
  69. }
  70.  
  71. bool GraftManager::RunGraftBehavior(EntityId entityId, const char* behaviorName, XmlNodeRef behaviorXml, IGraftBehaviorListener* listener)
  72. {
  73.         m_graftBehaviorRequests[entityId] = listener;
  74.  
  75.         ActiveGraftNodesContainer::iterator activeGraftNodeIt = m_activeGraftNodes.find(entityId);
  76.         if (activeGraftNodeIt != m_activeGraftNodes.end())
  77.         {
  78.                 return activeGraftNodeIt->second->RunBehavior(entityId, behaviorName, behaviorXml);
  79.         }
  80.  
  81.         IEntity* entity = gEnv->pEntitySystem->GetEntity(entityId);
  82.         gEnv->pLog->LogError("Graft Manager: There is no active graft node to run the behavior '%s' by the entity '%s'.", behaviorName, entity->GetName());
  83.         return false;
  84. }
  85.  
  86. bool GraftManager::RequestGraftMode(EntityId entityId, IGraftModeListener* listener)
  87. {
  88.         assert(entityId);
  89.  
  90.         GraftModeRequestsContainer::iterator graftModeRequestIt = m_graftModeRequests.find(entityId);
  91.         const bool graftModeAlreadyRequested = graftModeRequestIt != m_graftModeRequests.end();
  92.         if (graftModeAlreadyRequested)
  93.         {
  94.                 IEntity* entity = gEnv->pEntitySystem->GetEntity(entityId);
  95.                 gEnv->pLog->LogError("Graft Manager: More the one graft mode request was performed for the entity '%s'", entity->GetName());
  96.                 return false;
  97.         }
  98.         else
  99.         {
  100.                 m_graftModeRequests.insert(std::make_pair(entityId, listener));
  101.                 Event graftRequestEvent("OnGraftRequested");
  102.                 gAIEnv.pBehaviorTreeManager->HandleEvent(entityId, graftRequestEvent);
  103.                 return true;
  104.         }
  105. }
  106.  
  107. void GraftManager::CancelGraftMode(EntityId entityId)
  108. {
  109.         m_graftModeRequests.erase(entityId);
  110.         Event graftRequestEvent("OnGraftCanceled");
  111.         gAIEnv.pBehaviorTreeManager->HandleEvent(entityId, graftRequestEvent);
  112. }
  113. }
  114.  
downloadBehaviorTreeGraft.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top