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.

134 lines
4.0 KiB

  1. // C_NextBot.h
  2. // Next generation bot system
  3. // Author: Michael Booth, April 2005
  4. //========= Copyright Valve Corporation, All rights reserved. ============//
  5. #ifndef _C_NEXT_BOT_H_
  6. #define _C_NEXT_BOT_H_
  7. #include "c_ai_basenpc.h"
  8. //----------------------------------------------------------------------------------------------------------------
  9. /**
  10. * The interface holding IBody information
  11. */
  12. class IBodyClient
  13. {
  14. public:
  15. enum ActivityType
  16. {
  17. MOTION_CONTROLLED_XY = 0x0001, // XY position and orientation of the bot is driven by the animation.
  18. MOTION_CONTROLLED_Z = 0x0002, // Z position of the bot is driven by the animation.
  19. ACTIVITY_UNINTERRUPTIBLE= 0x0004, // activity can't be changed until animation finishes
  20. ACTIVITY_TRANSITORY = 0x0008, // a short animation that takes over from the underlying animation momentarily, resuming it upon completion
  21. ENTINDEX_PLAYBACK_RATE = 0x0010, // played back at different rates based on entindex
  22. };
  23. };
  24. //--------------------------------------------------------------------------------------------------------
  25. /**
  26. * The client-side implementation of the NextBot
  27. */
  28. class C_NextBotCombatCharacter : public C_BaseCombatCharacter
  29. {
  30. public:
  31. DECLARE_CLASS( C_NextBotCombatCharacter, C_BaseCombatCharacter );
  32. DECLARE_CLIENTCLASS();
  33. C_NextBotCombatCharacter();
  34. virtual ~C_NextBotCombatCharacter();
  35. public:
  36. virtual void Spawn( void );
  37. virtual void UpdateClientSideAnimation( void );
  38. virtual ShadowType_t ShadowCastType( void );
  39. virtual bool IsNextBot() { return true; }
  40. void ForceShadowCastType( bool bForce, ShadowType_t forcedShadowType = SHADOWS_NONE ) { m_bForceShadowType = bForce; m_forcedShadowType = forcedShadowType; }
  41. bool GetForcedShadowCastType( ShadowType_t* pForcedShadowType ) const;
  42. // Local In View Data.
  43. void InitFrustumData( void ) { m_bInFrustum = false; m_flFrustumDistanceSqr = FLT_MAX; m_nInFrustumFrame = gpGlobals->framecount; }
  44. bool IsInFrustumValid( void ) { return ( m_nInFrustumFrame == gpGlobals->framecount ); }
  45. void SetInFrustum( bool bInFrustum ) { m_bInFrustum = bInFrustum; }
  46. bool IsInFrustum( void ) { return m_bInFrustum; }
  47. void SetInFrustumDistanceSqr( float flDistance ) { m_flFrustumDistanceSqr = flDistance; }
  48. float GetInFrustumDistanceSqr( void ) { return m_flFrustumDistanceSqr; }
  49. private:
  50. ShadowType_t m_shadowType; // Are we LOD'd to simple shadows?
  51. CountdownTimer m_shadowTimer; // Timer to throttle checks for shadow LOD
  52. ShadowType_t m_forcedShadowType;
  53. bool m_bForceShadowType;
  54. void UpdateShadowLOD( void );
  55. // Local In View Data.
  56. int m_nInFrustumFrame;
  57. bool m_bInFrustum;
  58. float m_flFrustumDistanceSqr;
  59. private:
  60. C_NextBotCombatCharacter( const C_NextBotCombatCharacter & ); // not defined, not accessible
  61. };
  62. //--------------------------------------------------------------------------------------------------------
  63. /**
  64. * The C_NextBotManager manager
  65. */
  66. class C_NextBotManager
  67. {
  68. public:
  69. C_NextBotManager( void );
  70. ~C_NextBotManager();
  71. /**
  72. * Execute functor for each NextBot in the system.
  73. * If a functor returns false, stop iteration early
  74. * and return false.
  75. */
  76. template < typename Functor >
  77. bool ForEachCombatCharacter( Functor &func )
  78. {
  79. for( int i=0; i < m_botList.Count(); ++i )
  80. {
  81. C_NextBotCombatCharacter *character = m_botList[i];
  82. if ( character->IsPlayer() )
  83. {
  84. continue;
  85. }
  86. if ( character->IsDormant() )
  87. {
  88. continue;
  89. }
  90. if ( !func( character ) )
  91. {
  92. return false;
  93. }
  94. }
  95. return true;
  96. }
  97. int GetActiveCount() { return m_botList.Count(); }
  98. bool SetupInFrustumData( void );
  99. bool IsInFrustumDataValid( void ) { return ( m_nInFrustumFrame == gpGlobals->framecount ); }
  100. private:
  101. friend class C_NextBotCombatCharacter;
  102. void Register( C_NextBotCombatCharacter *bot );
  103. void UnRegister( C_NextBotCombatCharacter *bot );
  104. CUtlVector< C_NextBotCombatCharacter * > m_botList; ///< list of all active NextBots
  105. int m_nInFrustumFrame;
  106. };
  107. // singleton accessor
  108. extern C_NextBotManager &TheClientNextBots( void );
  109. #endif // _C_NEXT_BOT_H_