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.

198 lines
5.1 KiB

  1. // NextBotManager.h
  2. // Author: Michael Booth, May 2006
  3. // Copyright (c) 2006 Turtle Rock Studios, Inc. - All Rights Reserved
  4. #ifndef _NEXT_BOT_MANAGER_H_
  5. #define _NEXT_BOT_MANAGER_H_
  6. #include "NextBotInterface.h"
  7. class CTerrorPlayer;
  8. //----------------------------------------------------------------------------------------------------------------
  9. /**
  10. * The NextBotManager manager
  11. */
  12. class NextBotManager
  13. {
  14. public:
  15. NextBotManager( void );
  16. ~NextBotManager();
  17. void Reset( void ); // reset to initial state
  18. void Update( void );
  19. bool ShouldUpdate( INextBot *bot );
  20. void NotifyBeginUpdate( INextBot *bot );
  21. void NotifyEndUpdate( INextBot *bot );
  22. int GetNextBotCount( void ) const; // How many nextbots are alive right now?
  23. /**
  24. * Execute functor for each NextBot in the system.
  25. * If a functor returns false, stop iteration early
  26. * and return false.
  27. */
  28. template < typename Functor >
  29. bool ForEachBot( Functor &func )
  30. {
  31. for( int i=m_botList.Head(); i != m_botList.InvalidIndex(); i = m_botList.Next( i ) )
  32. {
  33. if ( !func( m_botList[i] ) )
  34. {
  35. return false;
  36. }
  37. }
  38. return true;
  39. }
  40. /**
  41. * Execute functor for each NextBot in the system as
  42. * a CBaseCombatCharacter.
  43. * If a functor returns false, stop iteration early
  44. * and return false.
  45. */
  46. template < typename Functor >
  47. bool ForEachCombatCharacter( Functor &func )
  48. {
  49. for( int i=m_botList.Head(); i != m_botList.InvalidIndex(); i = m_botList.Next( i ) )
  50. {
  51. if ( !func( m_botList[i]->GetEntity() ) )
  52. {
  53. return false;
  54. }
  55. }
  56. return true;
  57. }
  58. /**
  59. * Return closest bot to given point that passes the given filter
  60. */
  61. template < typename Filter >
  62. INextBot *GetClosestBot( const Vector &pos, Filter &filter )
  63. {
  64. INextBot *close = NULL;
  65. float closeRangeSq = FLT_MAX;
  66. for( int i=m_botList.Head(); i != m_botList.InvalidIndex(); i = m_botList.Next( i ) )
  67. {
  68. float rangeSq = ( m_botList[i]->GetEntity()->GetAbsOrigin() - pos ).LengthSqr();
  69. if ( rangeSq < closeRangeSq && filter( m_botList[i] ) )
  70. {
  71. closeRangeSq = rangeSq;
  72. close = m_botList[i];
  73. }
  74. }
  75. return close;
  76. }
  77. /**
  78. * Event propagators
  79. */
  80. void OnMapLoaded( void ); // when the server has changed maps
  81. void OnRoundRestart( void ); // when the scenario restarts
  82. void OnBeginChangeLevel( void ); // when the server is about to change maps
  83. virtual void OnKilled( CBaseCombatCharacter *victim, const CTakeDamageInfo &info ); // when an actor is killed
  84. virtual void OnSound( CBaseEntity *source, const Vector &pos, KeyValues *keys ); // when an entity emits a sound
  85. virtual void OnSpokeConcept( CBaseCombatCharacter *who, AIConcept_t concept, AI_Response *response ); // when an Actor speaks a concept
  86. virtual void OnWeaponFired( CBaseCombatCharacter *whoFired, CBaseCombatWeapon *weapon ); // when someone fires a weapon
  87. /**
  88. * Debugging
  89. */
  90. bool IsDebugging( unsigned int type ) const; // return true if debugging system is on for the given type(s)
  91. void SetDebugTypes( NextBotDebugType type ); // start displaying debug info of the given type(s)
  92. void DebugFilterAdd( int index ); // add given entindex to the debug filter
  93. void DebugFilterAdd( const char *name ); // add given name to the debug filter
  94. void DebugFilterRemove( int index ); // remove given entindex from the debug filter
  95. void DebugFilterRemove( const char *name ); // remove given name from the debug filter
  96. void DebugFilterClear( void ); // clear the debug filter (remove all entries)
  97. bool IsDebugFilterMatch( const INextBot *bot ) const; // return true if the given bot matches the debug filter
  98. void Select( INextBot *bot ); // mark bot as selected for further operations
  99. void DeselectAll( void );
  100. INextBot *GetSelected( void ) const;
  101. INextBot *GetBotUnderCrosshair( CBasePlayer *picker ); // Get the bot under the given player's crosshair
  102. //
  103. // Put these in a derived class
  104. //
  105. void OnSurvivorVomitedUpon( CTerrorPlayer *victim ); // when a Survivor has been hit by Boomer Vomit
  106. private:
  107. friend class INextBot;
  108. int Register( INextBot *bot );
  109. void UnRegister( INextBot *bot );
  110. CUtlLinkedList< INextBot * > m_botList; // list of all active NextBots
  111. int m_iUpdateTickrate;
  112. double m_CurUpdateStartTime;
  113. double m_SumFrameTime;
  114. unsigned int m_debugType; // debug flags
  115. struct DebugFilter
  116. {
  117. int index; // entindex
  118. enum { MAX_DEBUG_NAME_SIZE = 128 };
  119. char name[ MAX_DEBUG_NAME_SIZE ];
  120. };
  121. CUtlVector< DebugFilter > m_debugFilterList;
  122. INextBot *m_selectedBot; // selected bot for further debug operations
  123. };
  124. inline int NextBotManager::GetNextBotCount( void ) const
  125. {
  126. return m_botList.Count();
  127. }
  128. inline bool NextBotManager::IsDebugging( unsigned int type ) const
  129. {
  130. if ( type & m_debugType )
  131. {
  132. return true;
  133. }
  134. return false;
  135. }
  136. inline void NextBotManager::SetDebugTypes( NextBotDebugType type )
  137. {
  138. m_debugType = (unsigned int)type;
  139. }
  140. inline void NextBotManager::Select( INextBot *bot )
  141. {
  142. m_selectedBot = bot;
  143. }
  144. inline void NextBotManager::DeselectAll( void )
  145. {
  146. m_selectedBot = NULL;
  147. }
  148. inline INextBot *NextBotManager::GetSelected( void ) const
  149. {
  150. return m_selectedBot;
  151. }
  152. // singleton accessor
  153. extern NextBotManager &TheNextBots( void );
  154. #endif // _NEXT_BOT_MANAGER_H_