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.

311 lines
9.7 KiB

  1. // NextBotBodyInterface.h
  2. // Control and information about the bot's body state (posture, animation state, etc)
  3. // Author: Michael Booth, April 2006
  4. // Copyright (c) 2006 Turtle Rock Studios, Inc. - All Rights Reserved
  5. #ifndef _NEXT_BOT_BODY_INTERFACE_H_
  6. #define _NEXT_BOT_BODY_INTERFACE_H_
  7. #include "animation.h"
  8. #include "NextBotComponentInterface.h"
  9. class INextBot;
  10. struct animevent_t;
  11. //----------------------------------------------------------------------------------------------------------------
  12. /**
  13. * The interface for control and information about the bot's body state (posture, animation state, etc)
  14. */
  15. class IBody : public INextBotComponent
  16. {
  17. public:
  18. IBody( INextBot *bot ) : INextBotComponent( bot ) { }
  19. virtual ~IBody() { }
  20. virtual void Reset( void ) { INextBotComponent::Reset(); } // reset to initial state
  21. virtual void Update( void ) { } // update internal state
  22. /**
  23. * Move the bot to a new position.
  24. * If the body is not currently movable or if it
  25. * is in a motion-controlled animation activity
  26. * the position will not be changed and false will be returned.
  27. */
  28. virtual bool SetPosition( const Vector &pos );
  29. virtual const Vector &GetEyePosition( void ) const; // return the eye position of the bot in world coordinates
  30. virtual const Vector &GetViewVector( void ) const; // return the view unit direction vector in world coordinates
  31. enum LookAtPriorityType
  32. {
  33. BORING,
  34. INTERESTING, // last known enemy location, dangerous sound location
  35. IMPORTANT, // a danger
  36. CRITICAL, // an active threat to our safety
  37. MANDATORY // nothing can interrupt this look at - two simultaneous look ats with this priority is an error
  38. };
  39. virtual void AimHeadTowards( const Vector &lookAtPos,
  40. LookAtPriorityType priority = BORING,
  41. float duration = 0.0f,
  42. INextBotReply *replyWhenAimed = NULL,
  43. const char *reason = NULL ); // aim the bot's head towards the given goal
  44. virtual void AimHeadTowards( CBaseEntity *subject,
  45. LookAtPriorityType priority = BORING,
  46. float duration = 0.0f,
  47. INextBotReply *replyWhenAimed = NULL,
  48. const char *reason = NULL ); // continually aim the bot's head towards the given subject
  49. virtual bool IsHeadAimingOnTarget( void ) const; // return true if the bot's head has achieved its most recent lookat target
  50. virtual bool IsHeadSteady( void ) const; // return true if head is not rapidly turning to look somewhere else
  51. virtual float GetHeadSteadyDuration( void ) const; // return the duration that the bot's head has not been rotating
  52. virtual float GetHeadAimSubjectLeadTime( void ) const; // return how far into the future we should predict our moving subject's position to aim at when tracking subject look-ats
  53. virtual float GetMaxHeadAngularVelocity( void ) const; // return max turn rate of head in degrees/second
  54. enum ActivityType
  55. {
  56. MOTION_CONTROLLED_XY = 0x0001, // XY position and orientation of the bot is driven by the animation.
  57. MOTION_CONTROLLED_Z = 0x0002, // Z position of the bot is driven by the animation.
  58. ACTIVITY_UNINTERRUPTIBLE= 0x0004, // activity can't be changed until animation finishes
  59. ACTIVITY_TRANSITORY = 0x0008, // a short animation that takes over from the underlying animation momentarily, resuming it upon completion
  60. ENTINDEX_PLAYBACK_RATE = 0x0010, // played back at different rates based on entindex
  61. };
  62. /**
  63. * Begin an animation activity, return false if we cant do that right now.
  64. */
  65. virtual bool StartActivity( Activity act, unsigned int flags = 0 );
  66. virtual int SelectAnimationSequence( Activity act ) const; // given an Activity, select and return a specific animation sequence within it
  67. virtual Activity GetActivity( void ) const; // return currently animating activity
  68. virtual bool IsActivity( Activity act ) const; // return true if currently animating activity matches the given one
  69. virtual bool HasActivityType( unsigned int flags ) const; // return true if currently animating activity has any of the given flags
  70. enum PostureType
  71. {
  72. STAND,
  73. CROUCH,
  74. SIT,
  75. CRAWL,
  76. LIE
  77. };
  78. virtual void SetDesiredPosture( PostureType posture ) { } // request a posture change
  79. virtual PostureType GetDesiredPosture( void ) const; // get posture body is trying to assume
  80. virtual bool IsDesiredPosture( PostureType posture ) const; // return true if body is trying to assume this posture
  81. virtual bool IsInDesiredPosture( void ) const; // return true if body's actual posture matches its desired posture
  82. virtual PostureType GetActualPosture( void ) const; // return body's current actual posture
  83. virtual bool IsActualPosture( PostureType posture ) const; // return true if body is actually in the given posture
  84. virtual bool IsPostureMobile( void ) const; // return true if body's current posture allows it to move around the world
  85. virtual bool IsPostureChanging( void ) const; // return true if body's posture is in the process of changing to new posture
  86. /**
  87. * "Arousal" is the level of excitedness/arousal/anxiety of the body.
  88. * Is changes instantaneously to avoid complex interactions with posture transitions.
  89. */
  90. enum ArousalType
  91. {
  92. NEUTRAL,
  93. ALERT,
  94. INTENSE
  95. };
  96. virtual void SetArousal( ArousalType arousal ) { } // arousal level change
  97. virtual ArousalType GetArousal( void ) const; // get arousal level
  98. virtual bool IsArousal( ArousalType arousal ) const; // return true if body is at this arousal level
  99. virtual float GetHullWidth( void ) const; // width of bot's collision hull in XY plane
  100. virtual float GetHullHeight( void ) const; // height of bot's current collision hull based on posture
  101. virtual float GetStandHullHeight( void ) const; // height of bot's collision hull when standing
  102. virtual float GetCrouchHullHeight( void ) const; // height of bot's collision hull when crouched
  103. virtual const Vector &GetHullMins( void ) const; // return current collision hull minimums based on actual body posture
  104. virtual const Vector &GetHullMaxs( void ) const; // return current collision hull maximums based on actual body posture
  105. 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)
  106. };
  107. inline bool IBody::IsHeadSteady( void ) const
  108. {
  109. return true;
  110. }
  111. inline float IBody::GetHeadSteadyDuration( void ) const
  112. {
  113. return 0.0f;
  114. }
  115. inline float IBody::GetHeadAimSubjectLeadTime( void ) const
  116. {
  117. return 0.0f;
  118. }
  119. inline float IBody::GetMaxHeadAngularVelocity( void ) const
  120. {
  121. return 100.0f;
  122. }
  123. inline bool IBody::StartActivity( Activity act, unsigned int flags )
  124. {
  125. return false;
  126. }
  127. inline int IBody::SelectAnimationSequence( Activity act ) const
  128. {
  129. return 0;
  130. }
  131. inline Activity IBody::GetActivity( void ) const
  132. {
  133. return ACT_INVALID;
  134. }
  135. inline bool IBody::IsActivity( Activity act ) const
  136. {
  137. return false;
  138. }
  139. inline bool IBody::HasActivityType( unsigned int flags ) const
  140. {
  141. return false;
  142. }
  143. inline IBody::PostureType IBody::GetDesiredPosture( void ) const
  144. {
  145. return IBody::STAND;
  146. }
  147. inline bool IBody::IsDesiredPosture( PostureType posture ) const
  148. {
  149. return true;
  150. }
  151. inline bool IBody::IsInDesiredPosture( void ) const
  152. {
  153. return true;
  154. }
  155. inline IBody::PostureType IBody::GetActualPosture( void ) const
  156. {
  157. return IBody::STAND;
  158. }
  159. inline bool IBody::IsActualPosture( PostureType posture ) const
  160. {
  161. return true;
  162. }
  163. inline bool IBody::IsPostureMobile( void ) const
  164. {
  165. return true;
  166. }
  167. inline bool IBody::IsPostureChanging( void ) const
  168. {
  169. return false;
  170. }
  171. inline IBody::ArousalType IBody::GetArousal( void ) const
  172. {
  173. return IBody::NEUTRAL;
  174. }
  175. inline bool IBody::IsArousal( ArousalType arousal ) const
  176. {
  177. return true;
  178. }
  179. //---------------------------------------------------------------------------------------------------------------------------
  180. /**
  181. * Width of bot's collision hull in XY plane
  182. */
  183. inline float IBody::GetHullWidth( void ) const
  184. {
  185. return 26.0f;
  186. }
  187. //---------------------------------------------------------------------------------------------------------------------------
  188. /**
  189. * Height of bot's current collision hull based on posture
  190. */
  191. inline float IBody::GetHullHeight( void ) const
  192. {
  193. switch( GetActualPosture() )
  194. {
  195. case LIE:
  196. return 16.0f;
  197. case SIT:
  198. case CROUCH:
  199. return GetCrouchHullHeight();
  200. case STAND:
  201. default:
  202. return GetStandHullHeight();
  203. }
  204. }
  205. //---------------------------------------------------------------------------------------------------------------------------
  206. /**
  207. * Height of bot's collision hull when standing
  208. */
  209. inline float IBody::GetStandHullHeight( void ) const
  210. {
  211. return 68.0f;
  212. }
  213. //---------------------------------------------------------------------------------------------------------------------------
  214. /**
  215. * Height of bot's collision hull when crouched
  216. */
  217. inline float IBody::GetCrouchHullHeight( void ) const
  218. {
  219. return 32.0f;
  220. }
  221. //---------------------------------------------------------------------------------------------------------------------------
  222. /**
  223. * Return current collision hull minimums based on actual body posture
  224. */
  225. inline const Vector &IBody::GetHullMins( void ) const
  226. {
  227. static Vector hullMins;
  228. hullMins.x = -GetHullWidth()/2.0f;
  229. hullMins.y = hullMins.x;
  230. hullMins.z = 0.0f;
  231. return hullMins;
  232. }
  233. //---------------------------------------------------------------------------------------------------------------------------
  234. /**
  235. * Return current collision hull maximums based on actual body posture
  236. */
  237. inline const Vector &IBody::GetHullMaxs( void ) const
  238. {
  239. static Vector hullMaxs;
  240. hullMaxs.x = GetHullWidth()/2.0f;
  241. hullMaxs.y = hullMaxs.x;
  242. hullMaxs.z = GetHullHeight();
  243. return hullMaxs;
  244. }
  245. inline unsigned int IBody::GetSolidMask( void ) const
  246. {
  247. return MASK_NPCSOLID;
  248. }
  249. #endif // _NEXT_BOT_BODY_INTERFACE_H_