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.

153 lines
7.1 KiB

  1. // NextBotPlayerBody.h
  2. // Control and information about the bot's body state (posture, animation state, etc)
  3. // Author: Michael Booth, October 2006
  4. //========= Copyright Valve Corporation, All rights reserved. ============//
  5. #ifndef _NEXT_BOT_PLAYER_BODY_H_
  6. #define _NEXT_BOT_PLAYER_BODY_H_
  7. #include "NextBotBodyInterface.h"
  8. //----------------------------------------------------------------------------------------------------------------
  9. /**
  10. * A useful reply for IBody::AimHeadTowards. When the
  11. * head is aiming on target, press the fire button.
  12. */
  13. class PressFireButtonReply : public INextBotReply
  14. {
  15. public:
  16. virtual void OnSuccess( INextBot *bot ); // invoked when process completed successfully
  17. };
  18. //----------------------------------------------------------------------------------------------------------------
  19. /**
  20. * A useful reply for IBody::AimHeadTowards. When the
  21. * head is aiming on target, press the alt-fire button.
  22. */
  23. class PressAltFireButtonReply : public INextBotReply
  24. {
  25. public:
  26. virtual void OnSuccess( INextBot *bot ); // invoked when process completed successfully
  27. };
  28. //----------------------------------------------------------------------------------------------------------------
  29. /**
  30. * A useful reply for IBody::AimHeadTowards. When the
  31. * head is aiming on target, press the jump button.
  32. */
  33. class PressJumpButtonReply : public INextBotReply
  34. {
  35. public:
  36. virtual void OnSuccess( INextBot *bot ); // invoked when process completed successfully
  37. };
  38. //----------------------------------------------------------------------------------------------------------------
  39. /**
  40. * The interface for control and information about the bot's body state (posture, animation state, etc)
  41. */
  42. class PlayerBody : public IBody
  43. {
  44. public:
  45. PlayerBody( INextBot *bot );
  46. virtual ~PlayerBody();
  47. virtual void Reset( void ); // reset to initial state
  48. virtual void Upkeep( void ); // lightweight update guaranteed to occur every server tick
  49. virtual bool SetPosition( const Vector &pos );
  50. virtual const Vector &GetEyePosition( void ) const; // return the eye position of the bot in world coordinates
  51. virtual const Vector &GetViewVector( void ) const; // return the view unit direction vector in world coordinates
  52. virtual void AimHeadTowards( const Vector &lookAtPos,
  53. LookAtPriorityType priority = BORING,
  54. float duration = 0.0f,
  55. INextBotReply *replyWhenAimed = NULL,
  56. const char *reason = NULL ); // aim the bot's head towards the given goal
  57. virtual void AimHeadTowards( CBaseEntity *subject,
  58. LookAtPriorityType priority = BORING,
  59. float duration = 0.0f,
  60. INextBotReply *replyWhenAimed = NULL,
  61. const char *reason = NULL ); // continually aim the bot's head towards the given subject
  62. virtual bool IsHeadAimingOnTarget( void ) const; // return true if the bot's head has achieved its most recent lookat target
  63. virtual bool IsHeadSteady( void ) const; // return true if head is not rapidly turning to look somewhere else
  64. virtual float GetHeadSteadyDuration( void ) const; // return the duration that the bot's head has been on-target
  65. virtual void ClearPendingAimReply( void ); // clear out currently pending replyWhenAimed callback
  66. virtual float GetMaxHeadAngularVelocity( void ) const; // return max turn rate of head in degrees/second
  67. virtual bool StartActivity( Activity act, unsigned int flags );
  68. virtual Activity GetActivity( void ) const; // return currently animating activity
  69. virtual bool IsActivity( Activity act ) const; // return true if currently animating activity matches the given one
  70. virtual bool HasActivityType( unsigned int flags ) const; // return true if currently animating activity has any of the given flags
  71. virtual void SetDesiredPosture( PostureType posture ); // request a posture change
  72. virtual PostureType GetDesiredPosture( void ) const; // get posture body is trying to assume
  73. virtual bool IsDesiredPosture( PostureType posture ) const; // return true if body is trying to assume this posture
  74. virtual bool IsInDesiredPosture( void ) const; // return true if body's actual posture matches its desired posture
  75. virtual PostureType GetActualPosture( void ) const; // return body's current actual posture
  76. virtual bool IsActualPosture( PostureType posture ) const; // return true if body is actually in the given posture
  77. virtual bool IsPostureMobile( void ) const; // return true if body's current posture allows it to move around the world
  78. virtual bool IsPostureChanging( void ) const; // return true if body's posture is in the process of changing to new posture
  79. virtual void SetArousal( ArousalType arousal ); // arousal level change
  80. virtual ArousalType GetArousal( void ) const; // get arousal level
  81. virtual bool IsArousal( ArousalType arousal ) const; // return true if body is at this arousal level
  82. virtual float GetHullWidth( void ) const; // width of bot's collision hull in XY plane
  83. virtual float GetHullHeight( void ) const; // height of bot's current collision hull based on posture
  84. virtual float GetStandHullHeight( void ) const; // height of bot's collision hull when standing
  85. virtual float GetCrouchHullHeight( void ) const; // height of bot's collision hull when crouched
  86. virtual const Vector &GetHullMins( void ) const; // return current collision hull minimums based on actual body posture
  87. virtual const Vector &GetHullMaxs( void ) const; // return current collision hull maximums based on actual body posture
  88. virtual unsigned int GetSolidMask( void ) const; // return the bot's collision mask (hack until we get a general hull trace abstraction here or in the locomotion interface)
  89. virtual CBaseEntity *GetEntity( void ); // get the entity
  90. private:
  91. CBasePlayer *m_player;
  92. PostureType m_posture;
  93. ArousalType m_arousal;
  94. mutable Vector m_eyePos; // for use with GetEyePosition() ONLY
  95. mutable Vector m_viewVector; // for use with GetViewVector() ONLY
  96. mutable Vector m_hullMins; // for use with GetHullMins() ONLY
  97. mutable Vector m_hullMaxs; // for use with GetHullMaxs() ONLY
  98. Vector m_lookAtPos; // if m_lookAtSubject is non-NULL, it continually overwrites this position with its own
  99. EHANDLE m_lookAtSubject;
  100. Vector m_lookAtVelocity; // world velocity of lookat point, for tracking moving subjects
  101. CountdownTimer m_lookAtTrackingTimer;
  102. LookAtPriorityType m_lookAtPriority;
  103. CountdownTimer m_lookAtExpireTimer; // how long until this lookat expired
  104. IntervalTimer m_lookAtDurationTimer; // how long have we been looking at this target
  105. INextBotReply *m_lookAtReplyWhenAimed;
  106. bool m_isSightedIn; // true if we are looking at our last lookat target
  107. bool m_hasBeenSightedIn; // true if we have hit the current lookat target
  108. IntervalTimer m_headSteadyTimer;
  109. QAngle m_priorAngles; // last update's head angles
  110. QAngle m_desiredAngles;
  111. CountdownTimer m_anchorRepositionTimer; // the time is takes us to recenter our virtual mouse
  112. Vector m_anchorForward;
  113. };
  114. inline bool PlayerBody::IsHeadAimingOnTarget( void ) const
  115. {
  116. // TODO: Calling this immediately after AimHeadTowards will always return false until next Upkeep() (MSB)
  117. return m_isSightedIn;
  118. }
  119. #endif // _NEXT_BOT_PLAYER_BODY_H_