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.

228 lines
6.5 KiB

  1. //===== Copyright � 1996-2009, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: Plays a movie and reports on finish
  4. //
  5. //===========================================================================//
  6. #include "cbase.h"
  7. //-----------------------------------------------------------------------------
  8. // Purpose:
  9. //-----------------------------------------------------------------------------
  10. class CLogicPlayMovie : public CLogicalEntity
  11. {
  12. public:
  13. DECLARE_CLASS( CLogicPlayMovie, CLogicalEntity );
  14. DECLARE_DATADESC();
  15. CLogicPlayMovie( void ) { }
  16. ~CLogicPlayMovie( void ) { }
  17. virtual void Precache( void );
  18. virtual void Spawn( void );
  19. private:
  20. void InputPlayMovie( inputdata_t &data );
  21. void InputPlayMovieForAllPlayers( inputdata_t &data );
  22. void InputPlayLevelTransitionMovie( inputdata_t &data );
  23. void InputFadeAllMovies( inputdata_t &data );
  24. void InputMovieFinished( inputdata_t &data );
  25. string_t m_strMovieFilename;
  26. bool m_bAllowUserSkip;
  27. bool m_bLoopVideo;
  28. float m_bFadeInTime;
  29. COutputEvent m_OnPlaybackFinished;
  30. };
  31. LINK_ENTITY_TO_CLASS( logic_playmovie, CLogicPlayMovie );
  32. BEGIN_DATADESC( CLogicPlayMovie )
  33. DEFINE_KEYFIELD( m_strMovieFilename, FIELD_STRING, "MovieFilename" ),
  34. DEFINE_KEYFIELD( m_bAllowUserSkip, FIELD_BOOLEAN, "allowskip" ),
  35. DEFINE_KEYFIELD( m_bLoopVideo, FIELD_BOOLEAN, "loopvideo" ),
  36. DEFINE_KEYFIELD( m_bFadeInTime, FIELD_FLOAT, "fadeintime" ),
  37. DEFINE_INPUTFUNC( FIELD_VOID, "PlayMovie", InputPlayMovie ),
  38. DEFINE_INPUTFUNC( FIELD_VOID, "PlayMovieForAllPlayers", InputPlayMovieForAllPlayers ),
  39. DEFINE_INPUTFUNC( FIELD_VOID, "PlayLevelTransitionMovie", InputPlayLevelTransitionMovie ),
  40. DEFINE_INPUTFUNC( FIELD_VOID, "FadeAllMovies", InputFadeAllMovies ),
  41. DEFINE_INPUTFUNC( FIELD_VOID, "__MovieFinished", InputMovieFinished ),
  42. DEFINE_OUTPUT( m_OnPlaybackFinished, "OnPlaybackFinished" ),
  43. END_DATADESC()
  44. //-----------------------------------------------------------------------------
  45. // Purpose:
  46. //-----------------------------------------------------------------------------
  47. void CLogicPlayMovie::Precache( void )
  48. {
  49. }
  50. //-----------------------------------------------------------------------------
  51. // Purpose:
  52. //-----------------------------------------------------------------------------
  53. void CLogicPlayMovie::Spawn( void )
  54. {
  55. }
  56. static bool Helper_BIsValidMovieFileString( char const *szFileString )
  57. {
  58. if ( !szFileString || !*szFileString )
  59. return false;
  60. char const *szFileStringStart = szFileString;
  61. while ( *szFileString )
  62. {
  63. if ( !V_isalnum( *szFileString ) ) switch( *szFileString )
  64. {
  65. case '-':
  66. case '_':
  67. case '/':
  68. case '.':
  69. ++ szFileString;
  70. continue;
  71. default:
  72. DevWarning( "logic_playmovie has invalid movie filename char '%c' in \"%s\"\n", *szFileString, szFileStringStart );
  73. return false;
  74. }
  75. }
  76. return true;
  77. }
  78. //-----------------------------------------------------------------------------
  79. // Purpose:
  80. //-----------------------------------------------------------------------------
  81. void CLogicPlayMovie::InputPlayMovie( inputdata_t &data )
  82. {
  83. if ( !Helper_BIsValidMovieFileString( STRING(m_strMovieFilename) ) )
  84. return;
  85. const char *szVideoCommand = ( m_bAllowUserSkip ) ? "playvideo_exitcommand" : "playvideo_exitcommand_nointerrupt";
  86. // Build the hacked string
  87. char szClientCmd[256];
  88. Q_snprintf( szClientCmd, sizeof(szClientCmd),
  89. "%s %s end_movie %s\n",
  90. szVideoCommand,
  91. STRING(m_strMovieFilename),
  92. GetEntityNameAsCStr() );
  93. // Send it on
  94. engine->ServerCommand( szClientCmd );
  95. }
  96. //-----------------------------------------------------------------------------
  97. // Purpose: Plays a bink movie for all connected players
  98. //-----------------------------------------------------------------------------
  99. void CLogicPlayMovie::InputPlayMovieForAllPlayers( inputdata_t &data )
  100. {
  101. if ( !Helper_BIsValidMovieFileString( STRING( m_strMovieFilename ) ) )
  102. return;
  103. const char *szVideoCommand = ( m_bAllowUserSkip ) ? "playvideo_exitcommand" : "playvideo_exitcommand_nointerrupt";
  104. // Build the hacked string
  105. char szClientCmd[256];
  106. Q_snprintf( szClientCmd, sizeof(szClientCmd),
  107. "%s %s end_movie %s\n",
  108. szVideoCommand,
  109. STRING(m_strMovieFilename),
  110. GetEntityNameAsCStr() );
  111. bool bSplit = false;
  112. // Find out if we are in splitscreen first
  113. for( int i = 1; i <= gpGlobals->maxClients; ++i )
  114. {
  115. CBasePlayer *pToPlayer = UTIL_PlayerByIndex( i );
  116. if ( pToPlayer )
  117. {
  118. if ( engine->IsSplitScreenPlayer( pToPlayer->entindex() ) )
  119. {
  120. bSplit = true;
  121. break;
  122. }
  123. }
  124. }
  125. // Send it on
  126. for( int i = 1; i <= gpGlobals->maxClients; ++i )
  127. {
  128. CBasePlayer *pToPlayer = UTIL_PlayerByIndex( i );
  129. if ( pToPlayer )
  130. {
  131. engine->ClientCommand( pToPlayer->edict(), "%s", szClientCmd );
  132. // if we are in split screen, just play one movie
  133. if ( bSplit )
  134. return;
  135. }
  136. }
  137. }
  138. //-----------------------------------------------------------------------------
  139. // Purpose:
  140. //-----------------------------------------------------------------------------
  141. void CLogicPlayMovie::InputPlayLevelTransitionMovie( inputdata_t &data )
  142. {
  143. if ( !Helper_BIsValidMovieFileString( STRING( m_strMovieFilename ) ) )
  144. return;
  145. const char *szVideoCommand = "playvideo_end_level_transition";
  146. m_bFadeInTime = MAX( 0.1f, m_bFadeInTime );
  147. char szClientCmd[256];
  148. Q_snprintf( szClientCmd, sizeof(szClientCmd),
  149. "%s %s %f\n",
  150. szVideoCommand,
  151. STRING(m_strMovieFilename),
  152. m_bFadeInTime );
  153. // Send it on
  154. for( int i = 1; i <= gpGlobals->maxClients; ++i )
  155. {
  156. CBasePlayer *pToPlayer = UTIL_PlayerByIndex( i );
  157. if ( pToPlayer )
  158. {
  159. engine->ClientCommand( pToPlayer->edict(), "%s", szClientCmd );
  160. }
  161. }
  162. }
  163. //-----------------------------------------------------------------------------
  164. // Purpose:
  165. //-----------------------------------------------------------------------------
  166. void CLogicPlayMovie::InputFadeAllMovies( inputdata_t &data )
  167. {
  168. // TODO: HAX FOR PAX
  169. const char *szVideoCommand = "stopvideos_fadeout";
  170. char szClientCmd[256];
  171. Q_snprintf( szClientCmd, sizeof(szClientCmd),
  172. "%s %f\n",
  173. szVideoCommand,
  174. 1.0f );
  175. // Send it on
  176. for( int i = 1; i <= gpGlobals->maxClients; ++i )
  177. {
  178. CBasePlayer *pToPlayer = UTIL_PlayerByIndex( i );
  179. if ( pToPlayer )
  180. {
  181. engine->ClientCommand( pToPlayer->edict(), "%s", szClientCmd );
  182. }
  183. }
  184. }
  185. //-----------------------------------------------------------------------------
  186. // Purpose:
  187. //-----------------------------------------------------------------------------
  188. void CLogicPlayMovie::InputMovieFinished( inputdata_t &data )
  189. {
  190. // Simply fire our output
  191. m_OnPlaybackFinished.FireOutput( this, this );
  192. }