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.

345 lines
12 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef SCENEENTITY_CLASS_H
  8. #define SCENEENTITY_CLASS_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "ichoreoeventcallback.h"
  13. class CSceneListManager;
  14. //-----------------------------------------------------------------------------
  15. // Purpose: FIXME, need to deal with save/restore
  16. //-----------------------------------------------------------------------------
  17. class CSceneEntity : public CPointEntity, public IChoreoEventCallback
  18. {
  19. friend class CInstancedSceneEntity;
  20. public:
  21. enum
  22. {
  23. SCENE_ACTION_UNKNOWN = 0,
  24. SCENE_ACTION_CANCEL,
  25. SCENE_ACTION_RESUME,
  26. };
  27. enum
  28. {
  29. SCENE_BUSYACTOR_DEFAULT = 0,
  30. SCENE_BUSYACTOR_WAIT,
  31. SCENE_BUSYACTOR_INTERRUPT,
  32. SCENE_BUSYACTOR_INTERRUPT_CANCEL,
  33. };
  34. DECLARE_CLASS( CSceneEntity, CPointEntity );
  35. DECLARE_SERVERCLASS();
  36. CSceneEntity( void );
  37. ~CSceneEntity( void );
  38. // From IChoreoEventCallback
  39. virtual void StartEvent( float currenttime, CChoreoScene *scene, CChoreoEvent *event );
  40. virtual void EndEvent( float currenttime, CChoreoScene *scene, CChoreoEvent *event );
  41. virtual void ProcessEvent( float currenttime, CChoreoScene *scene, CChoreoEvent *event );
  42. virtual bool CheckEvent( float currenttime, CChoreoScene *scene, CChoreoEvent *event );
  43. virtual int UpdateTransmitState();
  44. virtual int ShouldTransmit( const CCheckTransmitInfo *pInfo );
  45. void SetRecipientFilter( IRecipientFilter *filter );
  46. virtual void Activate();
  47. virtual void Precache( void );
  48. virtual void Spawn( void );
  49. virtual void UpdateOnRemove( void );
  50. virtual void OnRestore();
  51. virtual void OnLoaded();
  52. virtual int DrawDebugTextOverlays();
  53. DECLARE_DATADESC();
  54. virtual void OnSceneFinished( bool canceled, bool fireoutput );
  55. virtual void DoThink( float frametime );
  56. virtual void PauseThink( void );
  57. bool IsPlayingBack() const { return m_bIsPlayingBack; }
  58. bool IsPaused() const { return m_bPaused; }
  59. bool IsMultiplayer() const { return m_bMultiplayer; }
  60. bool IsInterruptable();
  61. virtual void ClearInterrupt();
  62. virtual void CheckInterruptCompletion();
  63. virtual bool InterruptThisScene( CSceneEntity *otherScene );
  64. void RequestCompletionNotification( CSceneEntity *otherScene );
  65. virtual void NotifyOfCompletion( CSceneEntity *interruptor );
  66. void AddListManager( CSceneListManager *pManager );
  67. void ClearActivatorTargets( void );
  68. void SetBreakOnNonIdle( bool bBreakOnNonIdle ) { m_bBreakOnNonIdle = bBreakOnNonIdle; }
  69. bool ShouldBreakOnNonIdle( void ) { return m_bBreakOnNonIdle; }
  70. // Inputs
  71. void InputStartPlayback( inputdata_t &inputdata );
  72. void InputPausePlayback( inputdata_t &inputdata );
  73. void InputResumePlayback( inputdata_t &inputdata );
  74. void InputCancelPlayback( inputdata_t &inputdata );
  75. void InputCancelAtNextInterrupt( inputdata_t &inputdata );
  76. void InputPitchShiftPlayback( inputdata_t &inputdata );
  77. void InputTriggerEvent( inputdata_t &inputdata );
  78. // If the scene is playing, finds an actor in the scene who can respond to the specified concept token
  79. void InputInterjectResponse( inputdata_t &inputdata );
  80. // If this scene is waiting on an actor, give up and quit trying.
  81. void InputStopWaitingForActor( inputdata_t &inputdata );
  82. virtual void StartPlayback( void );
  83. virtual void PausePlayback( void );
  84. virtual void ResumePlayback( void );
  85. virtual void CancelPlayback( void );
  86. virtual void PitchShiftPlayback( float fPitch );
  87. virtual void QueueResumePlayback( void );
  88. bool ValidScene() const;
  89. // Scene load/unload
  90. static CChoreoScene *LoadScene( const char *filename, IChoreoEventCallback *pCallback );
  91. void UnloadScene( void );
  92. struct SpeakEventSound_t
  93. {
  94. CUtlSymbol m_Symbol;
  95. float m_flStartTime;
  96. };
  97. static bool SpeakEventSoundLessFunc( const SpeakEventSound_t& lhs, const SpeakEventSound_t& rhs );
  98. bool GetSoundNameForPlayer( CChoreoEvent *event, CBasePlayer *player, char *buf, size_t buflen );
  99. void BuildSortedSpeakEventSoundsPrefetchList(
  100. CChoreoScene *scene,
  101. CUtlSymbolTable& table,
  102. CUtlRBTree< SpeakEventSound_t >& soundnames,
  103. float timeOffset );
  104. void PrefetchSpeakEventSounds( CUtlSymbolTable& table, CUtlRBTree< SpeakEventSound_t >& soundnames );
  105. // Event handlers
  106. virtual void DispatchStartExpression( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
  107. virtual void DispatchEndExpression( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
  108. virtual void DispatchStartFlexAnimation( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
  109. virtual void DispatchEndFlexAnimation( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
  110. virtual void DispatchStartGesture( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
  111. virtual void DispatchEndGesture( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
  112. virtual void DispatchStartLookAt( CChoreoScene *scene, CBaseFlex *actor, CBaseEntity *actor2, CChoreoEvent *event );
  113. virtual void DispatchEndLookAt( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
  114. virtual void DispatchStartMoveTo( CChoreoScene *scene, CBaseFlex *actor, CBaseEntity *actor2, CChoreoEvent *event );
  115. virtual void DispatchEndMoveTo( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
  116. virtual void DispatchStartSpeak( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event, soundlevel_t iSoundlevel );
  117. virtual void DispatchEndSpeak( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
  118. virtual void DispatchStartFace( CChoreoScene *scene, CBaseFlex *actor, CBaseEntity *actor2, CChoreoEvent *event );
  119. virtual void DispatchEndFace( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
  120. virtual void DispatchStartSequence( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
  121. virtual void DispatchEndSequence( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
  122. virtual void DispatchStartSubScene( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
  123. virtual void DispatchStartInterrupt( CChoreoScene *scene, CChoreoEvent *event );
  124. virtual void DispatchEndInterrupt( CChoreoScene *scene, CChoreoEvent *event );
  125. virtual void DispatchStartGeneric( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
  126. virtual void DispatchEndGeneric( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
  127. // NPC can play interstitial vcds (such as responding to the player doing something during a scene)
  128. virtual void DispatchStartPermitResponses( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
  129. virtual void DispatchEndPermitResponses( CChoreoScene *scene, CBaseFlex *actor, CChoreoEvent *event );
  130. // Global events
  131. virtual void DispatchProcessLoop( CChoreoScene *scene, CChoreoEvent *event );
  132. virtual void DispatchPauseScene( CChoreoScene *scene, const char *parameters );
  133. virtual void DispatchStopPoint( CChoreoScene *scene, const char *parameters );
  134. virtual float EstimateLength( void );
  135. void CancelIfSceneInvolvesActor( CBaseEntity *pActor );
  136. bool InvolvesActor( CBaseEntity *pActor ); // NOTE: returns false if scene hasn't loaded yet
  137. void GenerateSoundScene( CBaseFlex *pActor, const char *soundname );
  138. virtual float GetPostSpeakDelay() { return 1.0; }
  139. bool HasUnplayedSpeech( void );
  140. bool HasFlexAnimation( void );
  141. void SetCurrentTime( float t, bool forceClientSync );
  142. void InputScriptPlayerDeath( inputdata_t &inputdata );
  143. // Data
  144. public:
  145. string_t m_iszSceneFile;
  146. string_t m_iszResumeSceneFile;
  147. EHANDLE m_hWaitingForThisResumeScene;
  148. bool m_bWaitingForResumeScene;
  149. string_t m_iszTarget1;
  150. string_t m_iszTarget2;
  151. string_t m_iszTarget3;
  152. string_t m_iszTarget4;
  153. string_t m_iszTarget5;
  154. string_t m_iszTarget6;
  155. string_t m_iszTarget7;
  156. string_t m_iszTarget8;
  157. EHANDLE m_hTarget1;
  158. EHANDLE m_hTarget2;
  159. EHANDLE m_hTarget3;
  160. EHANDLE m_hTarget4;
  161. EHANDLE m_hTarget5;
  162. EHANDLE m_hTarget6;
  163. EHANDLE m_hTarget7;
  164. EHANDLE m_hTarget8;
  165. CNetworkVar( bool, m_bIsPlayingBack );
  166. CNetworkVar( bool, m_bPaused );
  167. CNetworkVar( bool, m_bMultiplayer );
  168. CNetworkVar( float, m_flForceClientTime );
  169. float m_flCurrentTime;
  170. float m_flFrameTime;
  171. bool m_bCancelAtNextInterrupt;
  172. float m_fPitch;
  173. bool m_bAutomated;
  174. int m_nAutomatedAction;
  175. float m_flAutomationDelay;
  176. float m_flAutomationTime;
  177. // A pause from an input requires another input to unpause (it's a hard pause)
  178. bool m_bPausedViaInput;
  179. // Waiting for the actor to be able to speak.
  180. bool m_bWaitingForActor;
  181. // Waiting for a point at which we can interrupt our actors
  182. bool m_bWaitingForInterrupt;
  183. bool m_bInterruptedActorsScenes;
  184. bool m_bBreakOnNonIdle;
  185. public:
  186. virtual CBaseFlex *FindNamedActor( int index );
  187. virtual CBaseFlex *FindNamedActor( CChoreoActor *pChoreoActor );
  188. virtual CBaseFlex *FindNamedActor( const char *name );
  189. virtual CBaseEntity *FindNamedEntity( const char *name, CBaseEntity *pActor = NULL, bool bBaseFlexOnly = false, bool bUseClear = false );
  190. virtual CBaseEntity *FindNamedEntityFallback( const char *name, CBaseEntity *pActor = NULL, bool bBaseFlexOnly = false, bool bUseClear = false );
  191. CBaseEntity *FindNamedTarget( string_t iszTarget, bool bBaseFlexOnly = false );
  192. virtual CBaseEntity *FindNamedEntityClosest( const char *name, CBaseEntity *pActor = NULL, bool bBaseFlexOnly = false, bool bUseClear = false, const char *pszSecondary = NULL );
  193. EOZ_Hacks::ResponseFollowup m_followup;
  194. private:
  195. CUtlVector< CHandle< CBaseFlex > > m_hActorList;
  196. CUtlVector< CHandle< CBaseEntity > > m_hRemoveActorList;
  197. private:
  198. inline void SetRestoring( bool bRestoring );
  199. // Prevent derived classed from using this!
  200. virtual void Think( void ) {};
  201. void ClearSceneEvents( CChoreoScene *scene, bool canceled );
  202. void ClearSchedules( CChoreoScene *scene );
  203. float GetSoundSystemLatency( void );
  204. void PrecacheScene( CChoreoScene *scene );
  205. CChoreoScene *GenerateSceneForSound( CBaseFlex *pFlexActor, const char *soundname );
  206. bool CheckActors();
  207. void PrefetchAnimBlocks( CChoreoScene *scene );
  208. bool ShouldNetwork() const;
  209. // Set if we tried to async the scene but the FS returned that the data was not loadable
  210. bool m_bSceneMissing;
  211. CChoreoScene *m_pScene;
  212. CNetworkVar( int, m_nSceneStringIndex );
  213. const ConVar *m_pcvSndMixahead;
  214. COutputEvent m_OnStart;
  215. COutputEvent m_OnCompletion;
  216. COutputEvent m_OnCanceled;
  217. COutputEvent m_OnTrigger1;
  218. COutputEvent m_OnTrigger2;
  219. COutputEvent m_OnTrigger3;
  220. COutputEvent m_OnTrigger4;
  221. COutputEvent m_OnTrigger5;
  222. COutputEvent m_OnTrigger6;
  223. COutputEvent m_OnTrigger7;
  224. COutputEvent m_OnTrigger8;
  225. COutputEvent m_OnTrigger9;
  226. COutputEvent m_OnTrigger10;
  227. COutputEvent m_OnTrigger11;
  228. COutputEvent m_OnTrigger12;
  229. COutputEvent m_OnTrigger13;
  230. COutputEvent m_OnTrigger14;
  231. COutputEvent m_OnTrigger15;
  232. COutputEvent m_OnTrigger16;
  233. int m_nInterruptCount;
  234. bool m_bInterrupted;
  235. CHandle< CSceneEntity > m_hInterruptScene;
  236. bool m_bCompletedEarly;
  237. bool m_bInterruptSceneFinished;
  238. CUtlVector< CHandle< CSceneEntity > > m_hNotifySceneCompletion;
  239. CUtlVector< CHandle< CSceneListManager > > m_hListManagers;
  240. bool m_bRestoring;
  241. bool m_bGenerated;
  242. string_t m_iszSoundName;
  243. CHandle< CBaseFlex > m_hActor;
  244. EHANDLE m_hActivator;
  245. int m_BusyActor;
  246. int m_iPlayerDeathBehavior;
  247. CRecipientFilter *m_pRecipientFilter;
  248. public:
  249. void SetBackground( bool bIsBackground );
  250. bool IsBackground( void );
  251. };
  252. #endif // SCENEENTITY_CLASS_H