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.

307 lines
10 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef BASEFLEX_H
  8. #define BASEFLEX_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "BaseAnimatingOverlay.h"
  13. #include "utlvector.h"
  14. #include "utlrbtree.h"
  15. #include "sceneentity_shared.h"
  16. struct flexsettinghdr_t;
  17. struct flexsetting_t;
  18. namespace ResponseRules {class CRR_Response;};
  19. typedef ResponseRules::CRR_Response AI_Response;
  20. //-----------------------------------------------------------------------------
  21. // Purpose: A .vfe referenced by a scene during .vcd playback
  22. //-----------------------------------------------------------------------------
  23. class CFlexSceneFile
  24. {
  25. public:
  26. enum
  27. {
  28. MAX_FLEX_FILENAME = 128,
  29. };
  30. char filename[ MAX_FLEX_FILENAME ];
  31. void *buffer;
  32. };
  33. //-----------------------------------------------------------------------------
  34. // Purpose: Animated characters who have vertex flex capability (e.g., facial expressions)
  35. //-----------------------------------------------------------------------------
  36. class CBaseFlex : public CBaseAnimatingOverlay
  37. {
  38. DECLARE_CLASS( CBaseFlex, CBaseAnimatingOverlay );
  39. public:
  40. DECLARE_SERVERCLASS();
  41. DECLARE_DATADESC();
  42. DECLARE_PREDICTABLE();
  43. // script description
  44. DECLARE_ENT_SCRIPTDESC();
  45. // Construction
  46. CBaseFlex( void );
  47. ~CBaseFlex( void );
  48. virtual void SetModel( const char *szModelName );
  49. virtual CStudioHdr *OnNewModel();
  50. void Blink( );
  51. virtual void SetViewtarget( const Vector &viewtarget );
  52. const Vector &GetViewtarget( void ) const;
  53. void SetFlexWeight( char *szName, float value );
  54. void SetFlexWeight( LocalFlexController_t index, float value );
  55. float GetFlexWeight( char *szName );
  56. float GetFlexWeight( LocalFlexController_t index );
  57. // Look up flex controller index by global name
  58. LocalFlexController_t FindFlexController( const char *szName );
  59. void EnsureTranslations( const flexsettinghdr_t *pSettinghdr );
  60. // Keep track of what scenes are being played
  61. void StartChoreoScene( CChoreoScene *scene );
  62. void RemoveChoreoScene( CChoreoScene *scene, bool canceled = false );
  63. // Start the specifics of an scene event
  64. virtual bool StartSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event, CChoreoActor *actor, CBaseEntity *pTarget );
  65. // Manipulation of events for the object
  66. // Should be called by think function to process all scene events
  67. // The default implementation resets m_flexWeight array and calls
  68. // AddSceneEvents
  69. virtual void ProcessSceneEvents( void );
  70. // Assumes m_flexWeight array has been set up, this adds the actual currently playing
  71. // expressions to the flex weights and adds other scene events as needed
  72. virtual bool ProcessSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event );
  73. // Remove all playing events
  74. void ClearSceneEvents( CChoreoScene *scene, bool canceled );
  75. // Stop specifics of event
  76. virtual bool ClearSceneEvent( CSceneEventInfo *info, bool fastKill, bool canceled );
  77. // Add the event to the queue for this actor
  78. void AddSceneEvent( CChoreoScene *scene, CChoreoEvent *event, CBaseEntity *pTarget = NULL, CSceneEntity* pSceneEntity = NULL );
  79. // Remove the event from the queue for this actor
  80. void RemoveSceneEvent( CChoreoScene *scene, CChoreoEvent *event, bool fastKill );
  81. // Checks to see if the event should be considered "completed"
  82. bool CheckSceneEvent( float currenttime, CChoreoScene *scene, CChoreoEvent *event );
  83. // Checks to see if a event should be considered "completed"
  84. virtual bool CheckSceneEventCompletion( CSceneEventInfo *info, float currenttime, CChoreoScene *scene, CChoreoEvent *event );
  85. // Finds the layer priority of the current scene
  86. int GetScenePriority( CChoreoScene *scene );
  87. // Returns true if the actor is not currently in a scene OR if the actor
  88. // is in a scene, but a PERMIT_RESPONSES event is active and the permit time
  89. // period has enough time remaining to handle the response in full.
  90. bool PermitResponse( float response_length );
  91. // Set response end time (0 to clear response blocking)
  92. void SetPermitResponse( float endtime );
  93. void SentenceStop( void ) { EmitSound( "Default.Null" ); }
  94. virtual float PlayScene( const char *pszScene, float flDelay = 0.0f, AI_Response *response = NULL, IRecipientFilter *filter = NULL );
  95. virtual float ScriptPlayScene( const char *pszScene, float flDelay = 0.0f );
  96. virtual float PlayAutoGeneratedSoundScene( const char *soundname );
  97. // Returns the script instance of the scene entity associated with our oldest ("top level") scene event
  98. virtual HSCRIPT ScriptGetOldestScene( void );
  99. virtual HSCRIPT ScriptGetSceneByIndex( int index );
  100. protected:
  101. // For handling .vfe files
  102. // Search list, or add if not in list
  103. const void *FindSceneFile( const char *filename );
  104. // Find setting by name
  105. const flexsetting_t *FindNamedSetting( const flexsettinghdr_t *pSettinghdr, const char *expr );
  106. // Called at the lowest level to actually apply an expression
  107. void AddFlexSetting( const char *expr, float scale, const flexsettinghdr_t *pSettinghdr, bool newexpression );
  108. // Called at the lowest level to actually apply a flex animation
  109. void AddFlexAnimation( CSceneEventInfo *info );
  110. bool HasSceneEvents() const;
  111. bool IsRunningSceneMoveToEvent();
  112. LocalFlexController_t FlexControllerLocalToGlobal( const flexsettinghdr_t *pSettinghdr, int key );
  113. private:
  114. // Starting various expression types
  115. bool RequestStartSequenceSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event, CChoreoActor *actor, CBaseEntity *pTarget );
  116. bool RequestStartGestureSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event, CChoreoActor *actor, CBaseEntity *pTarget );
  117. bool HandleStartSequenceSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event, CChoreoActor *actor );
  118. bool HandleStartGestureSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event, CChoreoActor *actor );
  119. bool StartFacingSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event, CChoreoActor *actor, CBaseEntity *pTarget );
  120. bool StartMoveToSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event, CChoreoActor *actor, CBaseEntity *pTarget );
  121. // Processing various expression types
  122. bool ProcessFlexAnimationSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event );
  123. bool ProcessFlexSettingSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event );
  124. bool ProcessSequenceSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event );
  125. bool ProcessGestureSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event );
  126. bool ProcessFacingSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event );
  127. bool ProcessMoveToSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event );
  128. bool ProcessLookAtSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event );
  129. // Set playing the scene sequence
  130. public:
  131. bool EnterSceneSequence( CChoreoScene *scene, CChoreoEvent *event, bool bRestart = false );
  132. private:
  133. bool ExitSceneSequence( void );
  134. private:
  135. CNetworkArray( float, m_flexWeight, MAXSTUDIOFLEXCTRL ); // indexed by model local flexcontroller
  136. // Vector from actor to eye target
  137. CNetworkVector( m_viewtarget );
  138. // Blink state
  139. CNetworkVar( int, m_blinktoggle );
  140. // Array of active SceneEvents, in order oldest to newest
  141. CUtlVector < CSceneEventInfo > m_SceneEvents;
  142. // Mapping for each loaded scene file used by this actor
  143. struct FS_LocalToGlobal_t
  144. {
  145. explicit FS_LocalToGlobal_t() :
  146. m_Key( 0 ),
  147. m_nCount( 0 ),
  148. m_Mapping( 0 )
  149. {
  150. }
  151. explicit FS_LocalToGlobal_t( const flexsettinghdr_t *key ) :
  152. m_Key( key ),
  153. m_nCount( 0 ),
  154. m_Mapping( 0 )
  155. {
  156. }
  157. void SetCount( int count )
  158. {
  159. Assert( !m_Mapping );
  160. Assert( count > 0 );
  161. m_nCount = count;
  162. m_Mapping = new LocalFlexController_t[ m_nCount ];
  163. Q_memset( m_Mapping, 0, m_nCount * sizeof( int ) );
  164. }
  165. FS_LocalToGlobal_t( const FS_LocalToGlobal_t& src )
  166. {
  167. m_Key = src.m_Key;
  168. delete m_Mapping;
  169. m_Mapping = new LocalFlexController_t[ src.m_nCount ];
  170. Q_memcpy( m_Mapping, src.m_Mapping, src.m_nCount * sizeof( int ) );
  171. m_nCount = src.m_nCount;
  172. }
  173. ~FS_LocalToGlobal_t()
  174. {
  175. delete m_Mapping;
  176. m_nCount = 0;
  177. m_Mapping = 0;
  178. }
  179. const flexsettinghdr_t *m_Key;
  180. int m_nCount;
  181. LocalFlexController_t *m_Mapping;
  182. };
  183. static bool FlexSettingLessFunc( const FS_LocalToGlobal_t& lhs, const FS_LocalToGlobal_t& rhs );
  184. CUtlRBTree< FS_LocalToGlobal_t, unsigned short > m_LocalToGlobal;
  185. // The NPC is in a scene, but another .vcd (such as a short wave to say in response to the player doing something )
  186. // can be layered on top of this actor (assuming duration matches, etc.
  187. float m_flAllowResponsesEndTime;
  188. // List of actively playing scenes
  189. CUtlVector < CChoreoScene * > m_ActiveChoreoScenes;
  190. bool m_bUpdateLayerPriorities;
  191. public:
  192. bool IsSuppressedFlexAnimation( CSceneEventInfo *info );
  193. private:
  194. // last time a foreground flex animation was played
  195. float m_flLastFlexAnimationTime;
  196. public:
  197. void DoBodyLean( void );
  198. virtual void Teleport( const Vector *newPosition, const QAngle *newAngles, const Vector *newVelocity, bool bUseSlowHighAccuracyContacts = true );
  199. #ifdef HL2_DLL
  200. Vector m_vecPrevOrigin;
  201. Vector m_vecPrevVelocity;
  202. CNetworkVector( m_vecLean );
  203. CNetworkVector( m_vecShift );
  204. #endif
  205. };
  206. //-----------------------------------------------------------------------------
  207. // For toggling blinking
  208. //-----------------------------------------------------------------------------
  209. inline void CBaseFlex::Blink()
  210. {
  211. m_blinktoggle = !m_blinktoggle;
  212. }
  213. //-----------------------------------------------------------------------------
  214. // Do we have active expressions?
  215. //-----------------------------------------------------------------------------
  216. inline bool CBaseFlex::HasSceneEvents() const
  217. {
  218. return m_SceneEvents.Count() != 0;
  219. }
  220. //-----------------------------------------------------------------------------
  221. // Other inlines
  222. //-----------------------------------------------------------------------------
  223. inline const Vector &CBaseFlex::GetViewtarget( ) const
  224. {
  225. return m_viewtarget.Get(); // bah
  226. }
  227. inline void CBaseFlex::SetFlexWeight( char *szName, float value )
  228. {
  229. SetFlexWeight( FindFlexController( szName ), value );
  230. }
  231. inline float CBaseFlex::GetFlexWeight( char *szName )
  232. {
  233. return GetFlexWeight( FindFlexController( szName ) );
  234. }
  235. EXTERN_SEND_TABLE(DT_BaseFlex);
  236. #endif // BASEFLEX_H