Guest User

Untitled

a guest
Oct 21st, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.10 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "Entities/Helpers/ISimpleExtension.h"
  4.  
  5. #include <CryAISystem/IAISystem.h>
  6. #include <CryAISystem/IMovementSystem.h>
  7.  
  8. #include <CryAISystem/MovementRequest.h>
  9.  
  10. class CCharacter;
  11.  
  12. ////////////////////////////////////////////////////////
  13. // Player extension to manage movement
  14. ////////////////////////////////////////////////////////
  15. class CCharacterPath
  16.     : public CGameObjectExtensionHelper<CCharacterPath, ISimpleExtension>
  17.     , public IMovementActorAdapter
  18.     , public IAIPathAgent
  19. {
  20.     // Dummy implementation so we can use IAISystem::CreateAndReturnNewDefaultPathFollower
  21.     class CPathObstacles
  22.         : public IPathObstacles
  23.     {
  24.         // IPathObstacles
  25.         virtual bool IsPathIntersectingObstacles(const NavigationMeshID meshID, const Vec3& start, const Vec3& end, float radius) const { return false; }
  26.         virtual bool IsPointInsideObstacles(const Vec3& position) const { return false; }
  27.         virtual bool IsLineSegmentIntersectingObstaclesOrCloseToThem(const Lineseg& linesegToTest, float maxDistanceToConsiderClose) const override { return false; }
  28.         // ~IPathObstacles
  29.     };
  30. public:
  31.     CCharacterPath();
  32.     virtual ~CCharacterPath();
  33.  
  34.     //ISimpleExtension
  35.     virtual void PostInit(IGameObject* pGameObject) override;
  36.     //~ISimpleExtension
  37.  
  38.     // IMovementActorAdapter
  39.     virtual void                  OnMovementPlanProduced() override {}
  40.  
  41.     virtual NavigationAgentTypeID GetNavigationAgentTypeID() const override { return m_navigationAgentTypeId; }
  42.     virtual Vec3                  GetPhysicsPosition() const override { return GetEntity()->GetWorldPos(); }
  43.     virtual Vec3                  GetVelocity() const override;
  44.     virtual Vec3                  GetMoveDirection() const override { return GetVelocity().GetNormalized(); }
  45.     virtual Vec3                  GetAnimationBodyDirection() const override { return m_requestedTargetBodyDirection; }
  46.     virtual EActorTargetPhase     GetActorPhase() const override { return eATP_None; }
  47.     virtual void SetMovementOutputValue(const PathFollowResult& result) override;
  48.     virtual void                  SetBodyTargetDirection(const Vec3& direction) override { m_requestedTargetBodyDirection = direction; }
  49.     virtual void                  ResetMovementContext() override {}
  50.     virtual void                  ClearMovementState() override;
  51.     virtual void                  ResetBodyTarget() override {}
  52.     virtual void                  ResetActorTargetRequest() override {}
  53.     virtual bool                  IsMoving() const override { return !GetVelocity().IsZero(0.01f); }
  54.  
  55.     virtual void                  RequestExactPosition(const SAIActorTargetRequest* request, const bool lowerPrecision) override {}
  56.  
  57.     virtual bool                  IsClosestToUseTheSmartObject(const OffMeshLink_SmartObject& smartObjectLink) const override { return false; }
  58.     virtual bool                  PrepareNavigateSmartObject(CSmartObject* pSmartObject, OffMeshLink_SmartObject* pSmartObjectLink) override { return false; }
  59.     virtual void                  InvalidateSmartObjectLink(CSmartObject* pSmartObject, OffMeshLink_SmartObject* pSmartObjectLink) override {}
  60.  
  61.     virtual void                  SetInCover(const bool inCover) override {}
  62.     virtual void                  UpdateCoverLocations() override {}
  63.     virtual void                  InstallInLowCover(const bool inCover) override {}
  64.     virtual void                  SetupCoverInformation() override {}
  65.     virtual bool                  IsInCover() const override { return false; }
  66.  
  67.     virtual bool                  GetDesignedPath(SShape& pathShape) const override { return false; }
  68.     virtual void                  CancelRequestedPath() override {}
  69.     virtual void                  ConfigurePathfollower(const MovementStyle& style) override {}
  70.  
  71.     virtual void                  SetActorPath(const MovementStyle& style, const INavPath& navPath) override {}
  72.     virtual void                  SetActorStyle(const MovementStyle& style, const INavPath& navPath) override {}
  73.     virtual void                  SetStance(const MovementStyle::Stance stance) override {}
  74.  
  75.     virtual std::shared_ptr<Vec3> CreateLookTarget() override { return nullptr; }
  76.     virtual void                  SetLookTimeOffset(float lookTimeOffset) override {}
  77.     virtual void UpdateLooking(float updateTime, std::shared_ptr<Vec3> lookTarget, const bool targetReachable, const float pathDistanceToEnd, const Vec3& followTargetPosition, const MovementStyle& style) override {}
  78.     // ~IMovementActorAdapter
  79.  
  80.     // IAIPathAgent
  81.     virtual IEntity *GetPathAgentEntity() const override { return GetEntity(); }
  82.     virtual const char *GetPathAgentName() const override { return GetEntity()->GetClass()->GetName(); }
  83.  
  84.     virtual unsigned short GetPathAgentType() const override { return AIOBJECT_ACTOR; }
  85.  
  86.     virtual float GetPathAgentPassRadius() const override { return 1.f; }
  87.     virtual Vec3 GetPathAgentPos() const override { return GetPathAgentEntity()->GetWorldPos(); }
  88.     virtual Vec3 GetPathAgentVelocity() const override { return GetVelocity(); }
  89.  
  90.     virtual const AgentMovementAbility& GetPathAgentMovementAbility() const override { return m_movementAbility; }
  91.  
  92.     virtual void GetPathAgentNavigationBlockers(NavigationBlockers& blockers, const PathfindRequest* pRequest) override {}
  93.  
  94.     virtual unsigned int GetPathAgentLastNavNode() const override { return 0; }
  95.     virtual void SetPathAgentLastNavNode(unsigned int lastNavNode) override {}
  96.  
  97.     virtual void SetPathToFollow(const char* pathName) override {}
  98.     virtual void         SetPathAttributeToFollow(bool bSpline) override {}
  99.  
  100.     virtual void SetPFBlockerRadius(int blockerType, float radius) override {}
  101.  
  102.     virtual ETriState CanTargetPointBeReached(CTargetPointRequest& request) override
  103.     {
  104.         request.SetResult(eTS_false);
  105.         return eTS_false;
  106.     }
  107.  
  108.     virtual bool UseTargetPointRequest(const CTargetPointRequest& request) override { return false; }
  109.  
  110.     virtual bool GetValidPositionNearby(const Vec3& proposedPosition, Vec3& adjustedPosition) const override { return false; }
  111.     virtual bool GetTeleportPosition(Vec3& teleportPos) const override { return false; }
  112.  
  113.     virtual IPathFollower *GetPathFollower() const override { return m_pPathFollower.get(); }
  114.  
  115.     virtual bool IsPointValidForAgent(const Vec3& pos, uint32 flags) const override { return true; }
  116.     // ~IAIPathAgent
  117.  
  118.     void RequestMoveTo(const Vec3 &position);
  119.     void CancelCurrentRequest();
  120.     bool IsProcessingRequest() { return m_movementRequestId != 0; }
  121.     void Reset();
  122.     void InitAI();
  123.  
  124.  
  125. protected:
  126.     void MovementRequestCallback(const MovementRequestResult &result) {}
  127.  
  128.     INavPath *GetINavPath() { return m_pFoundPath; };
  129.     Movement::PathfinderState GetPathfinderState() { return m_state; }
  130.     void RequestPathTo(MNMPathRequest& request);
  131.  
  132.     void OnMNMPathResult(const MNM::QueuedPathID& requestId, MNMPathRequestResult& result);
  133.  
  134. protected:
  135.     CCharacter *m_pCharacter;
  136.  
  137.     NavigationAgentTypeID m_navigationAgentTypeId;
  138.     MovementActorCallbacks m_callbacks;
  139.  
  140.     MovementRequestID m_movementRequestId;
  141.     uint32 m_pathFinderRequestId;
  142.  
  143.     std::shared_ptr<IPathFollower> m_pPathFollower;
  144.     CPathObstacles m_pathObstacles;
  145.  
  146.     Movement::PathfinderState m_state;
  147.     INavPath *m_pFoundPath;
  148.  
  149.     AgentMovementAbility m_movementAbility;
  150.  
  151.     Vec3 m_requestedTargetBodyDirection;
  152.  
  153. };
Add Comment
Please, Sign In to add comment