BVB Source Codes

CRYENGINE Show TargetTrackManager.h Source code

Return Download CRYENGINE: download TargetTrackManager.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*************************************************************************
  4.    -------------------------------------------------------------------------
  5.    $Id$
  6.    $DateTime$
  7.    Description: Manages and updates target track groups for agents to
  8.         determine which target an agent should select
  9.  
  10.    -------------------------------------------------------------------------
  11.    History:
  12.    - 02:01:2010: Created by Kevin Kirst
  13.  
  14. *************************************************************************/
  15.  
  16. #ifndef __TARGET_TRACK_MANAGER_H__
  17. #define __TARGET_TRACK_MANAGER_H__
  18.  
  19. #include <CryAISystem/ITargetTrackManager.h>
  20. #include "TargetTrackCommon.h"
  21.  
  22. class CTargetTrackGroup;
  23. class CTargetTrack;
  24. struct ITargetTrackModifier;
  25.  
  26. struct SAIEVENT;
  27. struct SAIPotentialTarget;
  28.  
  29. class CTargetTrackManager : public ITargetTrackManager
  30. {
  31. public:
  32.         CTargetTrackManager();
  33.         ~CTargetTrackManager();
  34.  
  35.         void Init();
  36.         void Shutdown();
  37.         void Reset(IAISystem::EResetReason reason);
  38.         void DebugDraw();
  39.         bool ReloadConfig();
  40.         void OnObjectRemoved(CAIObject* pObject);
  41.         void Serialize(TSerialize ser);
  42.  
  43.         bool IsEnabled() const;
  44.  
  45.         // Threat modifier
  46.         virtual void                SetTargetTrackThreatModifier(ITargetTrackThreatModifier* pModifier);
  47.         virtual void                ClearTargetTrackThreatModifier();
  48.         ITargetTrackThreatModifier* GetTargetTrackThreatModifier() const { return m_pThreatModifier; }
  49.  
  50.         // Target group accessors
  51.         virtual bool  SetTargetClassThreat(tAIObjectID aiObjectId, float fClassThreat);
  52.         virtual float GetTargetClassThreat(tAIObjectID aiObjectId) const;
  53.         virtual int   GetTargetLimit(tAIObjectID aiObjectId) const;
  54.  
  55.         // Agent registration to use target tracks
  56.         bool RegisterAgent(tAIObjectID aiObjectId, const char* szConfig, int nTargetLimit = 0);
  57.         bool UnregisterAgent(tAIObjectID aiObjectId);
  58.         bool ResetAgent(tAIObjectID aiObjectId);
  59.         bool SetAgentEnabled(tAIObjectID aiObjectId, bool bEnable);
  60.  
  61.         // Incoming stimulus handling
  62.         virtual bool HandleStimulusEventInRange(tAIObjectID aiTargetId, const char* szStimulusName, const TargetTrackHelpers::SStimulusEvent& eventInfo, float fRadius);
  63.         virtual bool HandleStimulusEventForAgent(tAIObjectID aiAgentId, tAIObjectID aiTargetId, const char* szStimulusName, const TargetTrackHelpers::SStimulusEvent& eventInfo);
  64.         virtual bool TriggerPulse(tAIObjectID aiObjectId, tAIObjectID targetId, const char* szStimulusName, const char* szPulseName);
  65.  
  66.         bool         HandleStimulusFromAIEvent(tAIObjectID aiObjectId, const SAIEVENT* pAIEvent, TargetTrackHelpers::EAIEventStimulusType eType);
  67.  
  68.         // Outgoing desired target handling
  69.         void   Update(tAIObjectID aiObjectId);
  70.         void   ShareFreshestTargetData();
  71.         void   PullDownThreatLevel(const tAIObjectID aiObjectIdForTargetTrackGroup, const EAITargetThreat maxAllowedThreat);
  72.         bool   GetDesiredTarget(tAIObjectID aiObjectId, uint32 uDesiredTargetMethod, CWeakRef<CAIObject>& outTarget, SAIPotentialTarget*& pOutTargetInfo);
  73.         uint32 GetBestTargets(tAIObjectID aiObjectId, uint32 uDesiredTargetMethod, tAIObjectID* bestTargets, uint32 maxCount);
  74.         int    GetDesiredTargetCount(tAIObjectID aiTargetId, tAIObjectID aiIgnoreId = 0) const;
  75.         int    GetPotentialTargetCount(tAIObjectID aiTargetId, tAIObjectID aiIgnoreId = 0) const;
  76.         int    GetPotentialTargetCountFromFaction(tAIObjectID aiTargetId, const char* factionName, tAIObjectID aiIgnoreId = 0) const;
  77.  
  78. private:
  79.         // Target track pool management
  80.         CTargetTrack* GetUnusedTargetTrackFromPool();
  81.         void          AddTargetTrackToPool(CTargetTrack* pTrack);
  82.  
  83.         class CTargetTrackPoolProxy : public TargetTrackHelpers::ITargetTrackPoolProxy
  84.         {
  85.         public:
  86.                 CTargetTrackPoolProxy(CTargetTrackManager* pManager) : m_pManager(pManager)
  87.                 {
  88.                         assert(m_pManager);
  89.                 }
  90.  
  91.                 virtual CTargetTrack* GetUnusedTargetTrackFromPool()
  92.                 {
  93.                         return m_pManager->GetUnusedTargetTrackFromPool();
  94.                 }
  95.  
  96.                 virtual void AddTargetTrackToPool(CTargetTrack* pTrack)
  97.                 {
  98.                         m_pManager->AddTargetTrackToPool(pTrack);
  99.                 }
  100.  
  101.         private:
  102.                 CTargetTrackManager* m_pManager;
  103.         };
  104.  
  105. private:
  106.         // Target track config accessing
  107.         bool                        GetTargetTrackConfig(uint32 uNameHash, TargetTrackHelpers::STargetTrackConfig const*& pOutConfig) const;
  108.         bool                        GetTargetTrackStimulusConfig(uint32 uNameHash, uint32 uStimulusHash, TargetTrackHelpers::STargetTrackStimulusConfig const*& pOutConfig) const;
  109.         const ITargetTrackModifier* GetTargetTrackModifier(uint32 uId) const;
  110.  
  111.         class CTargetTrackConfigProxy : public TargetTrackHelpers::ITargetTrackConfigProxy
  112.         {
  113.         public:
  114.                 CTargetTrackConfigProxy(CTargetTrackManager* pManager) : m_pManager(pManager)
  115.                 {
  116.                         assert(m_pManager);
  117.                 }
  118.  
  119.                 bool GetTargetTrackConfig(uint32 uNameHash, TargetTrackHelpers::STargetTrackConfig const*& pOutConfig) const
  120.                 {
  121.                         return m_pManager->GetTargetTrackConfig(uNameHash, pOutConfig);
  122.                 }
  123.  
  124.                 bool GetTargetTrackStimulusConfig(uint32 uNameHash, uint32 uStimulusHash, TargetTrackHelpers::STargetTrackStimulusConfig const*& pOutConfig) const
  125.                 {
  126.                         return m_pManager->GetTargetTrackStimulusConfig(uNameHash, uStimulusHash, pOutConfig);
  127.                 }
  128.  
  129.                 const ITargetTrackModifier* GetTargetTrackModifier(uint32 uId) const
  130.                 {
  131.                         return m_pManager->GetTargetTrackModifier(uId);
  132.                 }
  133.  
  134.                 void ModifyTargetThreat(IAIObject& ownerAI, IAIObject& targetAI, const ITargetTrack& track, float& outThreatRatio, EAITargetThreat& outThreat) const;
  135.  
  136.         private:
  137.                 CTargetTrackManager* m_pManager;
  138.         };
  139.  
  140. private:
  141.         // Config load helpers
  142.         bool LoadConfigs(XmlNodeRef& pRoot);
  143.         bool LoadConfigStimuli(TargetTrackHelpers::STargetTrackConfig* pConfig, XmlNodeRef& pStimuliElement, bool bHasTemplate);
  144.         bool LoadConfigModifiers(TargetTrackHelpers::STargetTrackStimulusConfig* pStimulusConfig, XmlNodeRef& pModifiersElement);
  145.         bool LoadConfigPulses(TargetTrackHelpers::STargetTrackStimulusConfig* pStimulusConfig, XmlNodeRef& pPulsesElement);
  146.         bool LoadConfigReleaseThreatLevels(TargetTrackHelpers::STargetTrackStimulusConfig* pStimulusConfig, XmlNodeRef& pReleaseThreatLevelsElement);
  147.         bool ApplyStimulusTemplates();
  148.         bool ApplyStimulusTemplate(TargetTrackHelpers::STargetTrackConfig* pConfig, const TargetTrackHelpers::STargetTrackConfig* pParent);
  149.  
  150.         // Serialize helpers
  151.         void Serialize_Write(TSerialize ser);
  152.         void Serialize_Read(TSerialize ser);
  153.         bool RegisterAgent(tAIObjectID aiObjectId, uint32 uConfigHash, int nTargetLimit = 0);
  154.  
  155.         // Stimulus helpers
  156.         static tAIObjectID GetAIObjectId(EntityId entityId);
  157.         bool               ShouldStimulusBeHandled(tAIObjectID aiObjectID, const TargetTrackHelpers::SStimulusEvent& stimulusEvent, const float maxRadius = FLT_MAX);
  158.         bool               HandleStimulusEvent(CTargetTrackGroup* pGroup, TargetTrackHelpers::STargetTrackStimulusEvent& stimulusEvent);
  159.         bool               CheckConfigUsesStimulus(uint32 uConfigHash, uint32 uStimulusNameHash) const;
  160.         bool               CheckStimulusHostile(tAIObjectID aiObjectId, tAIObjectID aiTargetId, uint32 uConfigHash, uint32 uStimulusNameHash) const;
  161.         bool               TranslateVisualStimulusIfCanBeHandled(TargetTrackHelpers::STargetTrackStimulusEvent& stimulusEvent, const SAIEVENT* pAIEvent) const;
  162.         bool               TranslateSoundStimulusIfCanBeHandled(TargetTrackHelpers::STargetTrackStimulusEvent& stimulusEvent, const SAIEVENT* pAIEvent) const;
  163.         bool               TranslateBulletRainStimulusIfCanBeHandled(TargetTrackHelpers::STargetTrackStimulusEvent& stimulusEvent, const SAIEVENT* pAIEvent) const;
  164.  
  165.         static uint32      GetConfigNameHash(const char* sName);
  166.         static uint32      GetStimulusNameHash(const char* sStimulus);
  167.         static uint32      GetPulseNameHash(const char* sPulse);
  168.  
  169.         void               PrepareModifiers();
  170.         void               DeleteConfigs();
  171.         void               DeleteAgents();
  172.         void               ResetFreshestTargetData();
  173.  
  174.         typedef std::map<uint32, TargetTrackHelpers::STargetTrackConfig*> TConfigContainer;
  175.         TConfigContainer m_Configs;
  176.  
  177.         typedef std::map<tAIObjectID, CTargetTrackGroup*> TAgentContainer;
  178.         TAgentContainer m_Agents;
  179.  
  180.         typedef std::vector<CTargetTrack*> TTargetTrackPoolContainer;
  181.         TTargetTrackPoolContainer m_TargetTrackPool;
  182.  
  183.         typedef std::vector<ITargetTrackModifier*> TModifierContainer;
  184.         TModifierContainer m_Modifiers;
  185.  
  186.         typedef std::map<tAIObjectID, float> TClassThreatContainer;
  187.         TClassThreatContainer       m_ClassThreatValues;
  188.  
  189.         ITargetTrackThreatModifier* m_pThreatModifier;
  190.  
  191.         CTargetTrackPoolProxy*      m_pTrackPoolProxy;
  192.         CTargetTrackConfigProxy*    m_pTrackConfigProxy;
  193.  
  194.         struct FreshData
  195.         {
  196.                 FreshData()
  197.                         : timeOfFreshestVisualStimulus(0.0f)
  198.                         , freshestVisualPosition(ZERO)
  199.                         , freshestVisualDirection(ZERO)
  200.                 {
  201.                 }
  202.  
  203.                 float timeOfFreshestVisualStimulus;
  204.                 Vec3  freshestVisualPosition;
  205.                 Vec3  freshestVisualDirection;
  206.         };
  207.  
  208.         typedef tAIObjectID                            TargetAIObjectID;
  209.         typedef VectorMap<TargetAIObjectID, FreshData> DataPerTarget;
  210.         DataPerTarget m_dataPerTarget;
  211.  
  212. #ifdef TARGET_TRACK_DEBUG
  213.         void DebugDrawConfig(int nMode);
  214.         void DebugDrawTargets(int nMode, char const* szAgentName);
  215.         void DebugDrawAgent(char const* szAgentName);
  216.  
  217.         // Used to give the agent being debugged one last frame to clean up when debug drawing is turned off for him
  218.         tAIObjectID m_uLastDebugAgent;
  219. #endif //TARGET_TRACK_DEBUG
  220. };
  221.  
  222. #endif //__TARGET_TRACK_MANAGER_H__
  223.  
downloadTargetTrackManager.h 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