Team Fortress 2 Source Code as on 22/4/2020
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.

130 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. // nav_entities.h
  9. // Navigation entities
  10. // Author: Michael S. Booth ([email protected]), January 2003
  11. #ifndef NAV_ENTITIES_H
  12. #define NAV_ENTITIES_H
  13. //-----------------------------------------------------------------------------------------------------
  14. /**
  15. * An entity that modifies pathfinding cost to all areas it overlaps, to allow map designers
  16. * to tell bots to avoid/prefer certain regions.
  17. */
  18. class CFuncNavCost : public CBaseEntity
  19. {
  20. public:
  21. DECLARE_DATADESC();
  22. DECLARE_CLASS( CFuncNavCost, CBaseEntity );
  23. virtual void Spawn( void );
  24. virtual void UpdateOnRemove( void );
  25. void InputEnable( inputdata_t &inputdata );
  26. void InputDisable( inputdata_t &inputdata );
  27. bool IsEnabled( void ) const { return !m_isDisabled; }
  28. void CostThink( void );
  29. bool IsApplicableTo( CBaseCombatCharacter *who ) const; // Return true if this cost applies to the given actor
  30. virtual float GetCostMultiplier( CBaseCombatCharacter *who ) const { return 1.0f; }
  31. protected:
  32. int m_team;
  33. bool m_isDisabled;
  34. string_t m_iszTags;
  35. static CUtlVector< CHandle< CFuncNavCost > > gm_masterCostVector;
  36. static CountdownTimer gm_dirtyTimer;
  37. void UpdateAllNavCostDecoration( void );
  38. CUtlVector< CFmtStr > m_tags;
  39. bool HasTag( const char *groupname ) const;
  40. };
  41. //-----------------------------------------------------------------------------------------------------
  42. class CFuncNavAvoid : public CFuncNavCost
  43. {
  44. public:
  45. DECLARE_CLASS( CFuncNavAvoid, CFuncNavCost );
  46. virtual float GetCostMultiplier( CBaseCombatCharacter *who ) const; // return pathfind cost multiplier for the given actor
  47. };
  48. //-----------------------------------------------------------------------------------------------------
  49. class CFuncNavPrefer : public CFuncNavCost
  50. {
  51. public:
  52. DECLARE_CLASS( CFuncNavPrefer, CFuncNavCost );
  53. virtual float GetCostMultiplier( CBaseCombatCharacter *who ) const; // return pathfind cost multiplier for the given actor
  54. };
  55. //-----------------------------------------------------------------------------------------------------
  56. /**
  57. * An entity that can block/unblock nav areas. This is meant for semi-transient areas that block
  58. * pathfinding but can be ignored for longer-term queries like computing L4D flow distances and
  59. * escape routes.
  60. */
  61. class CFuncNavBlocker : public CBaseEntity
  62. {
  63. DECLARE_DATADESC();
  64. DECLARE_CLASS( CFuncNavBlocker, CBaseEntity );
  65. public:
  66. void Spawn();
  67. virtual void UpdateOnRemove( void );
  68. void InputBlockNav( inputdata_t &inputdata );
  69. void InputUnblockNav( inputdata_t &inputdata );
  70. inline bool IsBlockingNav( int teamNumber ) const
  71. {
  72. if ( teamNumber == TEAM_ANY )
  73. {
  74. bool isBlocked = false;
  75. for ( int i=0; i<MAX_NAV_TEAMS; ++i )
  76. {
  77. isBlocked |= m_isBlockingNav[ i ];
  78. }
  79. return isBlocked;
  80. }
  81. teamNumber = teamNumber % MAX_NAV_TEAMS;
  82. return m_isBlockingNav[ teamNumber ];
  83. }
  84. int DrawDebugTextOverlays( void );
  85. bool operator()( CNavArea *area ); // functor that blocks areas in our extent
  86. static bool CalculateBlocked( bool *pResultByTeam, const Vector &vecMins, const Vector &vecMaxs );
  87. private:
  88. void UpdateBlocked();
  89. static CUtlLinkedList<CFuncNavBlocker *> gm_NavBlockers;
  90. void BlockNav( void );
  91. void UnblockNav( void );
  92. bool m_isBlockingNav[MAX_NAV_TEAMS];
  93. int m_blockedTeamNumber;
  94. bool m_bDisabled;
  95. Vector m_CachedMins, m_CachedMaxs;
  96. };
  97. #endif // NAV_ENTITIES_H