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.

154 lines
5.0 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. // Navigation ladders
  8. // Author: Michael S. Booth ([email protected]), January 2003
  9. #ifndef _NAV_LADDER_H_
  10. #define _NAV_LADDER_H_
  11. #include "nav.h"
  12. class CNavArea;
  13. //--------------------------------------------------------------------------------------------------------------
  14. /**
  15. * The NavLadder represents ladders in the Navigation Mesh, and their connections to adjacent NavAreas
  16. * @todo Deal with ladders that allow jumping off to areas in the middle
  17. */
  18. class CNavLadder
  19. {
  20. public:
  21. CNavLadder( void )
  22. {
  23. m_topForwardArea = NULL;
  24. m_topRightArea = NULL;
  25. m_topLeftArea = NULL;
  26. m_topBehindArea = NULL;
  27. m_bottomArea = NULL;
  28. // set an ID for interactive editing - loads will overwrite this
  29. m_id = m_nextID++;
  30. }
  31. ~CNavLadder();
  32. void OnRoundRestart( void ); ///< invoked when a game round restarts
  33. void Save( CUtlBuffer &fileBuffer, unsigned int version ) const;
  34. void Load( CUtlBuffer &fileBuffer, unsigned int version );
  35. unsigned int GetID( void ) const { return m_id; } ///< return this ladder's unique ID
  36. static void CompressIDs( void ); ///<re-orders ladder ID's so they are continuous
  37. enum LadderDirectionType
  38. {
  39. LADDER_UP = 0,
  40. LADDER_DOWN,
  41. NUM_LADDER_DIRECTIONS
  42. };
  43. Vector m_top; ///< world coords of the top of the ladder
  44. Vector m_bottom; ///< world coords of the top of the ladder
  45. float m_length; ///< the length of the ladder
  46. float m_width;
  47. Vector GetPosAtHeight( float height ) const; ///< Compute x,y coordinate of the ladder at a given height
  48. CNavArea *m_topForwardArea; ///< the area at the top of the ladder
  49. CNavArea *m_topLeftArea;
  50. CNavArea *m_topRightArea;
  51. CNavArea *m_topBehindArea; ///< area at top of ladder "behind" it - only useful for descending
  52. CNavArea *m_bottomArea; ///< the area at the bottom of the ladder
  53. bool IsConnected( const CNavArea *area, LadderDirectionType dir ) const; ///< returns true if given area is connected in given direction
  54. void ConnectGeneratedLadder( float maxHeightAboveTopArea ); ///< Connect a generated ladder to nav areas at the end of nav generation
  55. void ConnectTo( CNavArea *area ); ///< connect this ladder to given area
  56. void Disconnect( CNavArea *area ); ///< disconnect this ladder from given area
  57. void OnSplit( CNavArea *original, CNavArea *alpha, CNavArea *beta ); ///< when original is split into alpha and beta, update our connections
  58. void OnDestroyNotify( CNavArea *dead ); ///< invoked when given area is going away
  59. void DrawLadder( void ) const; ///< Draws ladder and connections
  60. void DrawConnectedAreas( void ); ///< Draws connected areas
  61. void UpdateDangling( void ); ///< Checks if the ladder is dangling (bots cannot go up)
  62. bool IsInUse( const CBasePlayer *ignore = NULL ) const; ///< return true if someone is on this ladder (other than 'ignore')
  63. void SetDir( NavDirType dir );
  64. NavDirType GetDir( void ) const;
  65. const Vector &GetNormal( void ) const;
  66. void Shift( const Vector &shift ); ///< shift the nav ladder
  67. bool IsUsableByTeam( int teamNumber ) const;
  68. CBaseEntity *GetLadderEntity( void ) const;
  69. private:
  70. void FindLadderEntity( void );
  71. EHANDLE m_ladderEntity;
  72. NavDirType m_dir; ///< which way the ladder faces (ie: surface normal of climbable side)
  73. Vector m_normal; ///< surface normal of the ladder surface (or Vector-ized m_dir, if the traceline fails)
  74. enum LadderConnectionType ///< Ladder connection directions, to facilitate iterating over connections
  75. {
  76. LADDER_TOP_FORWARD = 0,
  77. LADDER_TOP_LEFT,
  78. LADDER_TOP_RIGHT,
  79. LADDER_TOP_BEHIND,
  80. LADDER_BOTTOM,
  81. NUM_LADDER_CONNECTIONS
  82. };
  83. CNavArea ** GetConnection( LadderConnectionType dir );
  84. static unsigned int m_nextID; ///< used to allocate unique IDs
  85. unsigned int m_id; ///< unique area ID
  86. };
  87. typedef CUtlVector< CNavLadder * > NavLadderVector;
  88. //--------------------------------------------------------------------------------------------------------------
  89. inline bool CNavLadder::IsUsableByTeam( int teamNumber ) const
  90. {
  91. if ( m_ladderEntity.Get() == NULL )
  92. return true;
  93. int ladderTeamNumber = m_ladderEntity->GetTeamNumber();
  94. return ( teamNumber == ladderTeamNumber || ladderTeamNumber == TEAM_UNASSIGNED );
  95. }
  96. //--------------------------------------------------------------------------------------------------------------
  97. inline CBaseEntity *CNavLadder::GetLadderEntity( void ) const
  98. {
  99. return m_ladderEntity.Get();
  100. }
  101. //--------------------------------------------------------------------------------------------------------------
  102. inline NavDirType CNavLadder::GetDir( void ) const
  103. {
  104. return m_dir;
  105. }
  106. //--------------------------------------------------------------------------------------------------------------
  107. inline const Vector &CNavLadder::GetNormal( void ) const
  108. {
  109. return m_normal;
  110. }
  111. #endif // _NAV_LADDER_H_