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.

98 lines
2.6 KiB

  1. // NextBotComponentInterface.h
  2. // Interface for all components
  3. // Author: Michael Booth, May 2006
  4. // Copyright (c) 2006 Turtle Rock Studios, Inc. - All Rights Reserved
  5. #ifndef _NEXT_BOT_COMPONENT_INTERFACE_H_
  6. #define _NEXT_BOT_COMPONENT_INTERFACE_H_
  7. #include "NextBotEventResponderInterface.h"
  8. class INextBot;
  9. class Path;
  10. class CGameTrace;
  11. class CTakeDamageInfo;
  12. //--------------------------------------------------------------------------------------------------------------------------
  13. /**
  14. * Various processes can invoke a "reply" (ie: callback) via instances of this interface
  15. */
  16. class INextBotReply
  17. {
  18. public:
  19. virtual void OnSuccess( INextBot *bot ) { } // invoked when process completed successfully
  20. enum FailureReason
  21. {
  22. DENIED,
  23. INTERRUPTED,
  24. FAILED
  25. };
  26. virtual void OnFail( INextBot *bot, FailureReason reason ) { } // invoked when process failed
  27. };
  28. //--------------------------------------------------------------------------------------------------------------------------
  29. /**
  30. * Next Bot component interface
  31. */
  32. class INextBotComponent : public INextBotEventResponder
  33. {
  34. public:
  35. INextBotComponent( INextBot *bot );
  36. virtual ~INextBotComponent() { }
  37. virtual void Reset( void ) { m_lastUpdateTime = 0; m_curInterval = TICK_INTERVAL; } // reset to initial state
  38. virtual void Update( void ) = 0; // update internal state
  39. virtual void Upkeep( void ) { } // lightweight update guaranteed to occur every server tick
  40. inline bool ComputeUpdateInterval(); // return false is no time has elapsed (interval is zero)
  41. inline float GetUpdateInterval();
  42. virtual INextBot *GetBot( void ) const { return m_bot; }
  43. private:
  44. float m_lastUpdateTime;
  45. float m_curInterval;
  46. friend class INextBot;
  47. INextBot *m_bot;
  48. INextBotComponent *m_nextComponent; // simple linked list of components in the bot
  49. };
  50. inline bool INextBotComponent::ComputeUpdateInterval()
  51. {
  52. if ( m_lastUpdateTime )
  53. {
  54. float interval = gpGlobals->curtime - m_lastUpdateTime;
  55. const float minInterval = 0.0001f;
  56. if ( interval > minInterval )
  57. {
  58. m_curInterval = interval;
  59. m_lastUpdateTime = gpGlobals->curtime;
  60. return true;
  61. }
  62. return false;
  63. }
  64. // First update - assume a reasonable interval.
  65. // We need the very first update to do work, for cases
  66. // where the bot was just created and we need to propagate
  67. // an event to it immediately.
  68. m_curInterval = 0.033f;
  69. m_lastUpdateTime = gpGlobals->curtime - m_curInterval;
  70. return true;
  71. }
  72. inline float INextBotComponent::GetUpdateInterval()
  73. {
  74. return m_curInterval;
  75. }
  76. #endif // _NEXT_BOT_COMPONENT_INTERFACE_H_