BVB Source Codes

CRYENGINE Show Leader.h Source code

Return Download CRYENGINE: download Leader.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /********************************************************************
  4.    -------------------------------------------------------------------------
  5.    File name:   Leader.h
  6.    $Id$
  7.    Description: Header for the CLeader class
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    Created by Kirill Bulatsev
  12.    - 01:06:2005   : serialization support added, related refactoring, moved out to separate files ObstacleAllocator, etc
  13.  
  14.  
  15.  *********************************************************************/
  16.  
  17. #ifndef __Leader_H__
  18. #define __Leader_H__
  19.  
  20. #if _MSC_VER > 1000
  21.         #pragma once
  22. #endif
  23.  
  24. #include "AIActor.h"
  25. #include "LeaderAction.h"
  26. #include <CryEntitySystem/IEntity.h>
  27. #include <list>
  28. #include <map>
  29. #include "ObjectContainer.h"
  30.  
  31. class CAIGroup;
  32. class CLeader;
  33. class CPipeUser;
  34. class CLeaderAction;
  35. struct LeaderActionParams;
  36.  
  37. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  38.  
  39. struct TTarget
  40. {
  41.         Vec3       position;
  42.         CAIObject* object;
  43.         TTarget(Vec3& spot, CAIObject* pObject) : position(spot), object(pObject) {};
  44. };
  45.  
  46. class CLeader :
  47.         public CAIActor//,public ILeader
  48. {
  49.         //      class CUnitAction;
  50.  
  51.         friend class CLeaderAction;
  52.  
  53. public:
  54.  
  55.         typedef std::map<CUnitImg*, Vec3>               CUnitPointMap;
  56.         typedef std::vector<CLeader*>                   TVecLeaders;
  57.         typedef std::vector<CAIObject*>                 TVecTargets;
  58.         typedef std::list<int>                          TUsableObjectList;
  59.         typedef std::multimap<int, TUnitList::iterator> TClassUnitMap;
  60.         typedef std::map<INT_PTR, Vec3>                 TSpotList;
  61.  
  62.         CLeader(int iGroupID);
  63.         ~CLeader(void);
  64.  
  65.         ////////////////////////////////////////////////////////////////////////////////////////////////
  66.         // SYSTEM/AI SYSTEM RELATED FUNCTIONS
  67.         ////////////////////////////////////////////////////////////////////////////////////////////////
  68.  
  69.         void         Update(EObjectUpdate type);
  70.         void         Reset(EObjectResetType type);
  71.         void         OnObjectRemoved(CAIObject* pObject);
  72.         void         Serialize(TSerialize ser);
  73.  
  74.         void         SetAIGroup(CAIGroup* pGroup) { m_pGroup = pGroup; }
  75.         CAIGroup*    GetAIGroup()                 { return m_pGroup; }
  76.         virtual void SetAssociation(CWeakRef<CAIObject> refAssociation);
  77.  
  78.         ////////////////////////////////////////////////////////////////////////////////////////////////
  79.         // CLEADER PROPERTIES FUNCTION
  80.         ////////////////////////////////////////////////////////////////////////////////////////////////
  81.  
  82.         // <Title IsPlayer>
  83.         // Description: returns true if this is associated to the player AI object
  84.         bool IsPlayer() const;
  85.  
  86.         // <Title IsIdle>
  87.         // Description: returns true if there's no LeaderAction active
  88.         bool         IsIdle() const;
  89.  
  90.         virtual bool IsActive() const { return false; }
  91.         virtual bool IsAgent() const  { return false; }
  92.  
  93.         ////////////////////////////////////////////////////////////////////////////////////////////////
  94.         // TEAM MANAGEMENT FUNCTIONS
  95.         ////////////////////////////////////////////////////////////////////////////////////////////////
  96.  
  97.         // <Title GetActiveUnitPlanCount>
  98.         // Description: return the number of units with at least one of the specified properties, which have an active plan (i.e. not idle)
  99.         // Arguments:
  100.         //      uint32 unitPropMask - binary mask of properties (i.e. UPR_COMBAT_GROUND|UPR_COMBAT_RECON)
  101.         //              only the unit with any of the specified properties will be considered
  102.         //              (default = UPR_ALL : all units are checked)
  103.         int GetActiveUnitPlanCount(uint32 unitProp = UPR_ALL) const;
  104.  
  105.         // <Title DeadUnitNotify>
  106.         // Description: to be called when a unit in the group dies
  107.         // Arguments:
  108.         // CAIObject* pObj = Dying AIObject
  109.         void DeadUnitNotify(CAIActor* pAIObj);
  110.  
  111.         // <Title AddUnitNotify>
  112.         // Description: to be called when an AI is added to the leader's group
  113.         // Arguments:
  114.         // CAIObject* pObj = new AIObject joining group
  115.         inline void AddUnitNotify(CAIActor* pAIObj)
  116.         {
  117.                 if (m_pCurrentAction)
  118.                         m_pCurrentAction->AddUnitNotify(pAIObj);
  119.         }
  120.  
  121.         ////////////////////////////////////////////////////////////////////////////////////////////////
  122.         // POSITIONING/TACTICAL FUNCTIONS
  123.         ////////////////////////////////////////////////////////////////////////////////////////////////
  124.  
  125.         // <Title GetPreferedPos>
  126.         // Description: Returns the preferred start position for finding obstacles (Dejan?)
  127.         Vec3 GetPreferedPos() const;
  128.  
  129.         // <Title ForcePreferedPos>
  130.         // Description:
  131.         inline void ForcePreferedPos(const Vec3& pos) { m_vForcedPreferredPos = pos; };
  132.  
  133.         // <Title MarkPosition>
  134.         // Description: marks a given point to be retrieved later
  135.         // Arguments:
  136.         //      Vec3& pos - point to be marked
  137.         inline void MarkPosition(const Vec3& pos) { m_vMarkedPosition = pos; }
  138.  
  139.         // <Title GetMarkedPosition>
  140.         // Description: return the previously marked point
  141.         inline const Vec3& GetMarkedPosition() const { return m_vMarkedPosition; }
  142.  
  143.         // <Title AssignTargetToUnits>
  144.         // Description: redistribute known attention targets amongst the units with the specified properties
  145.         // Arguments:
  146.         //      uint32 unitProp = binary selection mask for unit properties (i.e. UPR_COMBAT_GROUND|UPR_COMBAT_RECON)
  147.         //              only the unit with any of the specified properties will be considered
  148.         //      int maxUnitsPerTarget = specifies the maximum number of units that can have the same attention target
  149.         void AssignTargetToUnits(uint32 unitProp, int maxUnitsPerTarget);
  150.  
  151.         // <Title GetEnemyLeader>
  152.         // Description: returns the leader puppet (CAIOject*) of the current Leader's attention target if there is
  153.         //      (see CLeader::GetAttentionTarget()
  154.         CAIObject* GetEnemyLeader() const;
  155.  
  156.         // <Title GetHidePoint>
  157.         // Description: Find the point to hide for a unit, given the obstacle, using the enemy position as a reference
  158.         // Arguments:
  159.         //      CAIObject* pAIObject - unit's AI object
  160.         //  const CObstacleRef& obstacle - obstacle reference
  161.         // TODO : this method should be moved to the graph
  162.         Vec3 GetHidePoint(const CAIObject* pAIObject, const CObstacleRef& obstacle) const;
  163.  
  164.         // <Title ShootSpotsAvailable>
  165.         // Description: returns true if there are active shoot spots available
  166.         inline bool ShootSpotAvailable() { return false; }
  167.  
  168.         ////////////////////////////////////////////////////////////////////////////////////////////////
  169.         // ACTION RELATED FUNCTIONS
  170.         ////////////////////////////////////////////////////////////////////////////////////////////////
  171.  
  172.         // <Title Attack>
  173.         // Description: starts an attack action (stopping the current one)
  174.         // Arguments:
  175.         //  LeaderActionParams* pParams: leader action parameters - used depending on the action subtype (default: NULL -> default attack)
  176.         //      pParams->subType - leader Action subtype (LAS_ATTACK_FRONT,LAS_ATTACK_ROW etc) see definition of ELeaderActionSubType
  177.         //  pParams->fDuration - maximum duration of the attack action
  178.         //  pParams->unitProperties -  binary selection mask for unit properties (i.e. UPR_COMBAT_GROUND|UPR_COMBAT_RECON)
  179.         //              only the unit with any of the specified properties will be selected for the action
  180.         void Attack(const LeaderActionParams* pParams = NULL);
  181.  
  182.         // <Title Search>
  183.         // Description: starts a search action (stopping the current one)
  184.         // Arguments:
  185.         //      const Vec3& targetPos - last known target position reference
  186.         //      float distance - maximum distance to search (not working yet - it's hardcoded in AI System)
  187.         //      uint32 unitProperties = binary selection mask for unit properties (i.e. UPR_COMBAT_GROUND|UPR_COMBAT_RECON)
  188.         //              only the unit with any of the specified properties will be selected for the action
  189.         void Search(const Vec3& targetPos, float distance, uint32 unitProperties, int searchSpotAIObjectType);
  190.  
  191.         // <Title AbortExecution>
  192.         // Description: clear all units' actions and cancel (delete) the current LeaderAction
  193.         // Arguments:
  194.         //      int priority (default 0) max priority value for the unit actions to be canceled (0 = all priorities)
  195.         //              if an unit action was created with a priority value higher than this value, it won't be canceled
  196.         void AbortExecution(int priority = 0);
  197.  
  198.         // <Title ClearAllPlannings>
  199.         // Description: clear all actions of all the unit with specified unit properties
  200.         // Arguments:
  201.         //      int priority (default 0) max priority value for the unit actions to be canceled (0 = all priorities)
  202.         //              if an unit action was created with a priority value higher than this value, it won't be canceled
  203.         //      uint32 unitProp = binary selection mask for unit properties (i.e. UPR_COMBAT_GROUND|UPR_COMBAT_RECON)
  204.         //              only the unit with any of the specified properties will be considered
  205.         void ClearAllPlannings(uint32 unitProp = UPR_ALL, int priority = 0);
  206.  
  207.         ////////////////////////////////////////////////////////////////////////////////////////////////
  208.         // FORMATION RELATED FUNCTIONS
  209.         ////////////////////////////////////////////////////////////////////////////////////////////////
  210.  
  211.         bool                       LeaderCreateFormation(const char* szFormationName, const Vec3& vTargetPos, bool bIncludeLeader = true, uint32 unitProp = UNIT_ALL, CAIObject* pOwner = NULL);
  212.         bool                       ReleaseFormation();
  213.  
  214.         CWeakRef<CAIObject>        GetNewFormationPoint(CWeakRef<CAIObject> refRequester, int iPointType = 0);
  215.         CWeakRef<CAIObject>        GetFormationOwner(CWeakRef<CAIObject> refRequester) const { return m_refFormationOwner;  }
  216.         CWeakRef<CAIObject>        GetFormationPoint(CWeakRef<CAIObject> refRequester) const;
  217.  
  218.         int                        GetFormationPointIndex(const CAIObject* pAIObject) const;
  219.         CWeakRef<CAIObject>        GetFormationPointSight(const CPipeUser* pRequester) const;
  220.         void                       FreeFormationPoint(CWeakRef<CAIObject> refRequester) const;
  221.  
  222.         inline CWeakRef<CAIObject> GetFormationOwner() const      { return m_refFormationOwner; }
  223.         inline CWeakRef<CAIObject> GetPrevFormationOwner() const  { return m_refPrevFormationOwner; }
  224.  
  225.         inline const char*         GetFormationDescriptor() const { return m_szFormationDescriptor.c_str(); }
  226.         int                        AssignFormationPoints(bool bIncludeLeader = true, uint32 unitProp = UPR_ALL);
  227.         bool                       AssignFormationPoint(CUnitImg& unit, int iTeamSize = 0, bool bAnyClass = false, bool bClosestToOwner = false);
  228.         void                       AssignFormationPointIndex(CUnitImg& unit, int index);
  229.  
  230.         // Called by CAIGroup.
  231.         void OnEnemyStatsUpdated(const Vec3& avgEnemyPos, const Vec3& oldAvgEnemyPos);
  232.  
  233. protected:
  234.         void           UpdateEnemyStats();
  235.         void           ProcessSignal(AISIGNAL& signal);
  236.         CLeaderAction* CreateAction(const LeaderActionParams* params, const char* signalText = NULL);
  237.  
  238. private:
  239.         void ChangeStance(EStance stance);
  240.  
  241. protected:
  242.         CLeaderAction*      m_pCurrentAction;
  243.  
  244.         CWeakRef<CAIObject> m_refFormationOwner;
  245.         CWeakRef<CAIObject> m_refPrevFormationOwner;
  246.         CWeakRef<CAIObject> m_refEnemyTarget;
  247.  
  248.         string              m_szFormationDescriptor;
  249.         Vec3                m_vForcedPreferredPos;
  250.         Vec3                m_vMarkedPosition; //general purpose memory of a position - used in CLeaderAction_Search, as
  251.         // last average units' position when there was a live target
  252.         bool                m_bLeaderAlive;
  253.         bool                m_bKeepEnabled; // if true, CLeader::Update() will be executed even if the leader puppet is dead
  254.  
  255.         CAIGroup*           m_pGroup;
  256. };
  257.  
  258. inline const CLeader* CastToCLeaderSafe(const IAIObject* pAI) { return pAI ? pAI->CastToCLeader() : 0; }
  259. inline CLeader*       CastToCLeaderSafe(IAIObject* pAI)       { return pAI ? pAI->CastToCLeader() : 0; }
  260.  
  261. #endif // __Leader_H__
  262.  
downloadLeader.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