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.

325 lines
10 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 Valve Corporation, 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 GetHeadAimTrackingInterval( void ) const; // return how often we should sample our target's position and velocity to update our aim tracking, to allow realistic slop in tracking
  54. virtual void ClearPendingAimReply( void ) { } // clear out currently pending replyWhenAimed callback
  55. virtual float GetMaxHeadAngularVelocity( void ) const; // return max turn rate of head in degrees/second
  56. enum ActivityType
  57. {
  58. MOTION_CONTROLLED_XY = 0x0001, // XY position and orientation of the bot is driven by the animation.
  59. MOTION_CONTROLLED_Z = 0x0002, // Z position of the bot is driven by the animation.
  60. ACTIVITY_UNINTERRUPTIBLE= 0x0004, // activity can't be changed until animation finishes
  61. ACTIVITY_TRANSITORY = 0x0008, // a short animation that takes over from the underlying animation momentarily, resuming it upon completion
  62. ENTINDEX_PLAYBACK_RATE = 0x0010, // played back at different rates based on entindex
  63. };
  64. /**
  65. * Begin an animation activity, return false if we cant do that right now.
  66. */
  67. virtual bool StartActivity( Activity act, unsigned int flags = 0 );
  68. virtual int SelectAnimationSequence( Activity act ) const; // given an Activity, select and return a specific animation sequence within it
  69. virtual Activity GetActivity( void ) const; // return currently animating activity
  70. virtual bool IsActivity( Activity act ) const; // return true if currently animating activity matches the given one
  71. virtual bool HasActivityType( unsigned int flags ) const; // return true if currently animating activity has any of the given flags
  72. enum PostureType
  73. {
  74. STAND,
  75. CROUCH,
  76. SIT,
  77. CRAWL,
  78. LIE
  79. };
  80. virtual void SetDesiredPosture( PostureType posture ) { } // request a posture change
  81. virtual PostureType GetDesiredPosture( void ) const; // get posture body is trying to assume
  82. virtual bool IsDesiredPosture( PostureType posture ) const; // return true if body is trying to assume this posture
  83. virtual bool IsInDesiredPosture( void ) const; // return true if body's actual posture matches its desired posture
  84. virtual PostureType GetActualPosture( void ) const; // return body's current actual posture
  85. virtual bool IsActualPosture( PostureType posture ) const; // return true if body is actually in the given posture
  86. virtual bool IsPostureMobile( void ) const; // return true if body's current posture allows it to move around the world
  87. virtual bool IsPostureChanging( void ) const; // return true if body's posture is in the process of changing to new posture
  88. /**
  89. * "Arousal" is the level of excitedness/arousal/anxiety of the body.
  90. * Is changes instantaneously to avoid complex interactions with posture transitions.
  91. */
  92. enum ArousalType
  93. {
  94. NEUTRAL,
  95. ALERT,
  96. INTENSE
  97. };
  98. virtual void SetArousal( ArousalType arousal ) { } // arousal level change
  99. virtual ArousalType GetArousal( void ) const; // get arousal level
  100. virtual bool IsArousal( ArousalType arousal ) const; // return true if body is at this arousal level
  101. virtual float GetHullWidth( void ) const; // width of bot's collision hull in XY plane
  102. virtual float GetHullHeight( void ) const; // height of bot's current collision hull based on posture
  103. virtual float GetStandHullHeight( void ) const; // height of bot's collision hull when standing
  104. virtual float GetCrouchHullHeight( void ) const; // height of bot's collision hull when crouched
  105. virtual const Vector &GetHullMins( void ) const; // return current collision hull minimums based on actual body posture
  106. virtual const Vector &GetHullMaxs( void ) const; // return current collision hull maximums based on actual body posture
  107. 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)
  108. virtual unsigned int GetCollisionGroup( void ) const;
  109. };
  110. inline bool IBody::IsHeadSteady( void ) const
  111. {
  112. return true;
  113. }
  114. inline float IBody::GetHeadSteadyDuration( void ) const
  115. {
  116. return 0.0f;
  117. }
  118. inline float IBody::GetHeadAimSubjectLeadTime( void ) const
  119. {
  120. return 0.0f;
  121. }
  122. inline float IBody::GetHeadAimTrackingInterval( void ) const
  123. {
  124. return 0.0f;
  125. }
  126. inline float IBody::GetMaxHeadAngularVelocity( void ) const
  127. {
  128. return 1000.0f;
  129. }
  130. inline bool IBody::StartActivity( Activity act, unsigned int flags )
  131. {
  132. return false;
  133. }
  134. inline int IBody::SelectAnimationSequence( Activity act ) const
  135. {
  136. return 0;
  137. }
  138. inline Activity IBody::GetActivity( void ) const
  139. {
  140. return ACT_INVALID;
  141. }
  142. inline bool IBody::IsActivity( Activity act ) const
  143. {
  144. return false;
  145. }
  146. inline bool IBody::HasActivityType( unsigned int flags ) const
  147. {
  148. return false;
  149. }
  150. inline IBody::PostureType IBody::GetDesiredPosture( void ) const
  151. {
  152. return IBody::STAND;
  153. }
  154. inline bool IBody::IsDesiredPosture( PostureType posture ) const
  155. {
  156. return true;
  157. }
  158. inline bool IBody::IsInDesiredPosture( void ) const
  159. {
  160. return true;
  161. }
  162. inline IBody::PostureType IBody::GetActualPosture( void ) const
  163. {
  164. return IBody::STAND;
  165. }
  166. inline bool IBody::IsActualPosture( PostureType posture ) const
  167. {
  168. return true;
  169. }
  170. inline bool IBody::IsPostureMobile( void ) const
  171. {
  172. return true;
  173. }
  174. inline bool IBody::IsPostureChanging( void ) const
  175. {
  176. return false;
  177. }
  178. inline IBody::ArousalType IBody::GetArousal( void ) const
  179. {
  180. return IBody::NEUTRAL;
  181. }
  182. inline bool IBody::IsArousal( ArousalType arousal ) const
  183. {
  184. return true;
  185. }
  186. //---------------------------------------------------------------------------------------------------------------------------
  187. /**
  188. * Width of bot's collision hull in XY plane
  189. */
  190. inline float IBody::GetHullWidth( void ) const
  191. {
  192. return 26.0f;
  193. }
  194. //---------------------------------------------------------------------------------------------------------------------------
  195. /**
  196. * Height of bot's current collision hull based on posture
  197. */
  198. inline float IBody::GetHullHeight( void ) const
  199. {
  200. switch( GetActualPosture() )
  201. {
  202. case LIE:
  203. return 16.0f;
  204. case SIT:
  205. case CROUCH:
  206. return GetCrouchHullHeight();
  207. case STAND:
  208. default:
  209. return GetStandHullHeight();
  210. }
  211. }
  212. //---------------------------------------------------------------------------------------------------------------------------
  213. /**
  214. * Height of bot's collision hull when standing
  215. */
  216. inline float IBody::GetStandHullHeight( void ) const
  217. {
  218. return 68.0f;
  219. }
  220. //---------------------------------------------------------------------------------------------------------------------------
  221. /**
  222. * Height of bot's collision hull when crouched
  223. */
  224. inline float IBody::GetCrouchHullHeight( void ) const
  225. {
  226. return 32.0f;
  227. }
  228. //---------------------------------------------------------------------------------------------------------------------------
  229. /**
  230. * Return current collision hull minimums based on actual body posture
  231. */
  232. inline const Vector &IBody::GetHullMins( void ) const
  233. {
  234. static Vector hullMins;
  235. hullMins.x = -GetHullWidth()/2.0f;
  236. hullMins.y = hullMins.x;
  237. hullMins.z = 0.0f;
  238. return hullMins;
  239. }
  240. //---------------------------------------------------------------------------------------------------------------------------
  241. /**
  242. * Return current collision hull maximums based on actual body posture
  243. */
  244. inline const Vector &IBody::GetHullMaxs( void ) const
  245. {
  246. static Vector hullMaxs;
  247. hullMaxs.x = GetHullWidth()/2.0f;
  248. hullMaxs.y = hullMaxs.x;
  249. hullMaxs.z = GetHullHeight();
  250. return hullMaxs;
  251. }
  252. inline unsigned int IBody::GetSolidMask( void ) const
  253. {
  254. return MASK_NPCSOLID;
  255. }
  256. inline unsigned int IBody::GetCollisionGroup( void ) const
  257. {
  258. return COLLISION_GROUP_NONE;
  259. }
  260. #endif // _NEXT_BOT_BODY_INTERFACE_H_