Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
7.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef AI_MOVEPROBE_H
  7. #define AI_MOVEPROBE_H
  8. #include "ai_component.h"
  9. #include "ai_navtype.h"
  10. #include "ai_movetypes.h"
  11. #if defined( _WIN32 )
  12. #pragma once
  13. #endif
  14. //-----------------------------------------------------------------------------
  15. // Purpose: Set of basic tools for probing box movements through space.
  16. // No moves actually take place
  17. //-----------------------------------------------------------------------------
  18. enum AI_TestGroundMoveFlags_t
  19. {
  20. AITGM_DEFAULT = 0,
  21. AITGM_IGNORE_FLOOR = 0x01,
  22. AITGM_IGNORE_INITIAL_STAND_POS = 0x02,
  23. AITGM_2D = 0x04,
  24. AITGM_DRAW_RESULTS = 0x08,
  25. AITGM_CRAWL_LARGE_STEPS = 0x10,
  26. };
  27. enum AI_MoveLimitFlags_t
  28. {
  29. AIMLF_DEFAULT = 0,
  30. AIMLF_2D = 0x01,
  31. AIMLF_DRAW_RESULTS = 0x02,
  32. AIMLF_IGNORE_TRANSIENTS = 0x04,
  33. AIMLF_QUICK_REJECT = 0x08,
  34. };
  35. class CAI_MoveProbe : public CAI_Component
  36. {
  37. public:
  38. CAI_MoveProbe( CAI_BaseNPC *pOuter );
  39. ~CAI_MoveProbe();
  40. // ----------------------------------------------------
  41. // Queries & probes
  42. // ----------------------------------------------------
  43. bool MoveLimit( Navigation_t navType, const Vector &vecStart, const Vector &vecEnd, unsigned int collisionMask, const CBaseEntity *pTarget, AIMoveTrace_t* pMove = NULL );
  44. bool MoveLimit( Navigation_t navType, const Vector &vecStart, const Vector &vecEnd, unsigned int collisionMask, const CBaseEntity *pTarget, float pctToCheckStandPositions, AIMoveTrace_t* pMove = NULL );
  45. bool MoveLimit( Navigation_t navType, const Vector &vecStart, const Vector &vecEnd, unsigned int collisionMask, const CBaseEntity *pTarget, float pctToCheckStandPositions, unsigned flags, AIMoveTrace_t* pMove = NULL );
  46. bool CheckStandPosition( const Vector &vecStart, unsigned int collisionMask ) const;
  47. bool FloorPoint( const Vector &vecStart, unsigned int collisionMask, float flStartZ, float flEndZ, Vector *pVecResult ) const;
  48. // --------------------------------
  49. // Tracing tools
  50. // --------------------------------
  51. void TraceLine( const Vector &vecStart, const Vector &vecEnd, unsigned int mask,
  52. bool bUseCollisionGroup, trace_t *pResult ) const;
  53. void TraceHull( const Vector &vecStart, const Vector &vecEnd, const Vector &hullMin,
  54. const Vector &hullMax, unsigned int mask,
  55. trace_t *ptr ) const;
  56. void TraceHull( const Vector &vecStart, const Vector &vecEnd, unsigned int mask,
  57. trace_t *ptr ) const;
  58. // --------------------------------
  59. // Checks a ground-based movement
  60. // --------------------------------
  61. bool TestGroundMove( const Vector &vecActualStart, const Vector &vecDesiredEnd,
  62. unsigned int collisionMask, unsigned flags, AIMoveTrace_t *pMoveTrace ) const;
  63. bool TestGroundMove( const Vector &vecActualStart, const Vector &vecDesiredEnd,
  64. unsigned int collisionMask, float pctToCheckStandPositions, unsigned flags, AIMoveTrace_t *pMoveTrace ) const;
  65. bool ShouldBrushBeIgnored( CBaseEntity *pEntity );
  66. void ClearBlockingEntity() { m_hLastBlockingEnt = NULL; }
  67. CBaseEntity * GetBlockingEntity() { return m_hLastBlockingEnt; }
  68. private:
  69. struct CheckStepArgs_t
  70. {
  71. Vector vecStart;
  72. Vector vecStepDir;
  73. float stepSize;
  74. float stepHeight;
  75. float stepDownMultiplier;
  76. float minStepLanding;
  77. unsigned collisionMask;
  78. StepGroundTest_t groundTest;
  79. unsigned flags;
  80. };
  81. struct CheckStepResult_t
  82. {
  83. Vector endPoint;
  84. Vector hitNormal;
  85. bool fStartSolid;
  86. CBaseEntity * pBlocker;
  87. bool bCrawling;
  88. };
  89. bool CheckStep( const CheckStepArgs_t &args, CheckStepResult_t *pResult ) const;
  90. void SetupCheckStepTraceListData( const CheckStepArgs_t &args ) const;
  91. void ResetTraceListData() const { if ( m_pTraceListData ) const_cast<CAI_MoveProbe *>(this)->m_pTraceListData->Reset(); }
  92. bool OldCheckStandPosition( const Vector &vecStart, unsigned int collisionMask ) const;
  93. // these check connections between positions in space, regardless of routes
  94. void GroundMoveLimit( const Vector &vecStart, const Vector &vecEnd, unsigned int collisionMask, const CBaseEntity *pTarget, unsigned testGroundMoveFlags, float pctToCheckStandPositions, AIMoveTrace_t* pMoveTrace ) const;
  95. void FlyMoveLimit( const Vector &vecStart, const Vector &vecEnd, unsigned int collisionMask, const CBaseEntity *pTarget, AIMoveTrace_t* pMoveTrace) const;
  96. void JumpMoveLimit( const Vector &vecStart, const Vector &vecEnd, unsigned int collisionMask, const CBaseEntity *pTarget, AIMoveTrace_t* pMoveTrace) const;
  97. void ClimbMoveLimit( const Vector &vecStart, const Vector &vecEnd, const CBaseEntity *pTarget, AIMoveTrace_t* pMoveTrace) const;
  98. // A floorPoint that is useful only in the contect of iterative movement
  99. bool IterativeFloorPoint( const Vector &vecStart, unsigned int collisionMask, Vector *pVecResult ) const;
  100. bool IterativeFloorPoint( const Vector &vecStart, unsigned int collisionMask, float flAddedStep, Vector *pVecResult ) const;
  101. bool IsJumpLegal( const Vector &startPos, const Vector &apex, const Vector &endPos ) const;
  102. public:
  103. Vector CalcJumpLaunchVelocity(const Vector &startPos, const Vector &endPos, float gravity, float *pminHeight, float maxHorzVelocity, Vector *vecApex ) const;
  104. private:
  105. void CheckStepOverLargeCrawl( CheckStepResult_t *pResult, const CheckStepArgs_t &args, const Vector &vecStart, const Vector &vecEnd, const trace_t &blockedTrace ) const;
  106. // Confirm 3D connectivity between 2 nodes
  107. bool Confirm3DConnectivity( AIMoveTrace_t *pMoveTrace, unsigned flags, const Vector &vecDesiredEnd ) const;
  108. // Common services provided by CAI_BaseNPC, Convenience methods to simplify code
  109. float StepHeight() const;
  110. bool CanStandOn( CBaseEntity *pSurface ) const;
  111. bool m_bIgnoreTransientEntities;
  112. ITraceListData * m_pTraceListData;
  113. EHANDLE m_hLastBlockingEnt;
  114. DECLARE_SIMPLE_DATADESC();
  115. };
  116. // ----------------------------------------------------------------------------
  117. inline bool CAI_MoveProbe::MoveLimit( Navigation_t navType, const Vector &vecStart, const Vector &vecEnd, unsigned int collisionMask, const CBaseEntity *pTarget, float pctToCheckStandPositions, AIMoveTrace_t* pMove)
  118. {
  119. return MoveLimit( navType, vecStart, vecEnd, collisionMask, pTarget, pctToCheckStandPositions, AIMLF_DEFAULT, pMove);
  120. }
  121. // ------------------------------------
  122. inline bool CAI_MoveProbe::MoveLimit( Navigation_t navType, const Vector &vecStart, const Vector &vecEnd, unsigned int collisionMask, const CBaseEntity *pTarget, AIMoveTrace_t* pMove)
  123. {
  124. return MoveLimit( navType, vecStart, vecEnd, collisionMask, pTarget, 100.0f, AIMLF_DEFAULT, pMove);
  125. }
  126. // ------------------------------------
  127. inline bool CAI_MoveProbe::TestGroundMove( const Vector &vecActualStart, const Vector &vecDesiredEnd, unsigned int collisionMask, unsigned flags, AIMoveTrace_t *pMoveTrace ) const
  128. {
  129. return TestGroundMove( vecActualStart, vecDesiredEnd, collisionMask, 100, flags, pMoveTrace ); // floor ignore flag will override 100%
  130. }
  131. #endif // AI_MOVEPROBE_H