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.

268 lines
8.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Entity to control screen overlays on a player
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "shareddefs.h"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. //-----------------------------------------------------------------------------
  11. // Purpose:
  12. //-----------------------------------------------------------------------------
  13. class CEnvScreenOverlay : public CPointEntity
  14. {
  15. DECLARE_CLASS( CEnvScreenOverlay, CPointEntity );
  16. public:
  17. DECLARE_DATADESC();
  18. DECLARE_SERVERCLASS();
  19. CEnvScreenOverlay();
  20. // Always transmit to clients
  21. virtual int UpdateTransmitState();
  22. virtual void Spawn( void );
  23. virtual void Precache( void );
  24. void InputStartOverlay( inputdata_t &inputdata );
  25. void InputStopOverlay( inputdata_t &inputdata );
  26. void InputSwitchOverlay( inputdata_t &inputdata );
  27. void SetActive( bool bActive ) { m_bIsActive = bActive; }
  28. protected:
  29. CNetworkArray( string_t, m_iszOverlayNames, MAX_SCREEN_OVERLAYS );
  30. CNetworkArray( float, m_flOverlayTimes, MAX_SCREEN_OVERLAYS );
  31. CNetworkVar( float, m_flStartTime );
  32. CNetworkVar( int, m_iDesiredOverlay );
  33. CNetworkVar( bool, m_bIsActive );
  34. };
  35. LINK_ENTITY_TO_CLASS( env_screenoverlay, CEnvScreenOverlay );
  36. BEGIN_DATADESC( CEnvScreenOverlay )
  37. // Silence, Classcheck!
  38. // DEFINE_ARRAY( m_iszOverlayNames, FIELD_STRING, MAX_SCREEN_OVERLAYS ),
  39. // DEFINE_ARRAY( m_flOverlayTimes, FIELD_FLOAT, MAX_SCREEN_OVERLAYS ),
  40. DEFINE_KEYFIELD( m_iszOverlayNames[0], FIELD_STRING, "OverlayName1" ),
  41. DEFINE_KEYFIELD( m_iszOverlayNames[1], FIELD_STRING, "OverlayName2" ),
  42. DEFINE_KEYFIELD( m_iszOverlayNames[2], FIELD_STRING, "OverlayName3" ),
  43. DEFINE_KEYFIELD( m_iszOverlayNames[3], FIELD_STRING, "OverlayName4" ),
  44. DEFINE_KEYFIELD( m_iszOverlayNames[4], FIELD_STRING, "OverlayName5" ),
  45. DEFINE_KEYFIELD( m_iszOverlayNames[5], FIELD_STRING, "OverlayName6" ),
  46. DEFINE_KEYFIELD( m_iszOverlayNames[6], FIELD_STRING, "OverlayName7" ),
  47. DEFINE_KEYFIELD( m_iszOverlayNames[7], FIELD_STRING, "OverlayName8" ),
  48. DEFINE_KEYFIELD( m_iszOverlayNames[8], FIELD_STRING, "OverlayName9" ),
  49. DEFINE_KEYFIELD( m_iszOverlayNames[9], FIELD_STRING, "OverlayName10" ),
  50. DEFINE_KEYFIELD( m_flOverlayTimes[0], FIELD_FLOAT, "OverlayTime1" ),
  51. DEFINE_KEYFIELD( m_flOverlayTimes[1], FIELD_FLOAT, "OverlayTime2" ),
  52. DEFINE_KEYFIELD( m_flOverlayTimes[2], FIELD_FLOAT, "OverlayTime3" ),
  53. DEFINE_KEYFIELD( m_flOverlayTimes[3], FIELD_FLOAT, "OverlayTime4" ),
  54. DEFINE_KEYFIELD( m_flOverlayTimes[4], FIELD_FLOAT, "OverlayTime5" ),
  55. DEFINE_KEYFIELD( m_flOverlayTimes[5], FIELD_FLOAT, "OverlayTime6" ),
  56. DEFINE_KEYFIELD( m_flOverlayTimes[6], FIELD_FLOAT, "OverlayTime7" ),
  57. DEFINE_KEYFIELD( m_flOverlayTimes[7], FIELD_FLOAT, "OverlayTime8" ),
  58. DEFINE_KEYFIELD( m_flOverlayTimes[8], FIELD_FLOAT, "OverlayTime9" ),
  59. DEFINE_KEYFIELD( m_flOverlayTimes[9], FIELD_FLOAT, "OverlayTime10" ),
  60. // Class CEnvScreenOverlay:
  61. DEFINE_FIELD( m_iDesiredOverlay, FIELD_INTEGER ),
  62. DEFINE_FIELD( m_flStartTime, FIELD_TIME ),
  63. DEFINE_FIELD( m_bIsActive, FIELD_BOOLEAN ),
  64. DEFINE_INPUTFUNC( FIELD_VOID, "StartOverlays", InputStartOverlay ),
  65. DEFINE_INPUTFUNC( FIELD_VOID, "StopOverlays", InputStopOverlay ),
  66. DEFINE_INPUTFUNC( FIELD_INTEGER, "SwitchOverlay", InputSwitchOverlay ),
  67. END_DATADESC()
  68. void SendProxy_String_tToString( const SendProp *pProp, const void *pStruct, const void *pData, DVariant *pOut, int iElement, int objectID )
  69. {
  70. string_t *pString = (string_t*)pData;
  71. pOut->m_pString = (char*)STRING( *pString );
  72. }
  73. IMPLEMENT_SERVERCLASS_ST( CEnvScreenOverlay, DT_EnvScreenOverlay )
  74. SendPropArray( SendPropString( SENDINFO_ARRAY( m_iszOverlayNames ), 0, SendProxy_String_tToString ), m_iszOverlayNames ),
  75. SendPropArray( SendPropFloat( SENDINFO_ARRAY( m_flOverlayTimes ), 11, SPROP_ROUNDDOWN, -1.0f, 63.0f ), m_flOverlayTimes ),
  76. SendPropFloat( SENDINFO( m_flStartTime ), 32, SPROP_NOSCALE ),
  77. SendPropInt( SENDINFO( m_iDesiredOverlay ), 5 ),
  78. SendPropBool( SENDINFO( m_bIsActive ) ),
  79. END_SEND_TABLE()
  80. //-----------------------------------------------------------------------------
  81. // Purpose:
  82. //-----------------------------------------------------------------------------
  83. CEnvScreenOverlay::CEnvScreenOverlay( void )
  84. {
  85. m_flStartTime = 0;
  86. m_iDesiredOverlay = 0;
  87. m_bIsActive = false;
  88. }
  89. //-----------------------------------------------------------------------------
  90. // Purpose:
  91. //-----------------------------------------------------------------------------
  92. void CEnvScreenOverlay::Spawn( void )
  93. {
  94. Precache();
  95. }
  96. //-----------------------------------------------------------------------------
  97. // Purpose:
  98. //-----------------------------------------------------------------------------
  99. void CEnvScreenOverlay::Precache( void )
  100. {
  101. for ( int i = 0; i < 10; i++ )
  102. {
  103. if ( m_iszOverlayNames[i] == NULL_STRING )
  104. continue;
  105. PrecacheMaterial( STRING( m_iszOverlayNames[i] ) );
  106. }
  107. }
  108. //-----------------------------------------------------------------------------
  109. // Purpose:
  110. // Input : &inputdata -
  111. //-----------------------------------------------------------------------------
  112. void CEnvScreenOverlay::InputStartOverlay( inputdata_t &inputdata )
  113. {
  114. if ( m_iszOverlayNames[0] == NULL_STRING )
  115. {
  116. Warning("env_screenoverlay %s has no overlays to display.\n", STRING(GetEntityName()) );
  117. return;
  118. }
  119. m_flStartTime = gpGlobals->curtime;
  120. m_bIsActive = true;
  121. // Turn off any other screen overlays out there
  122. CBaseEntity *pEnt = NULL;
  123. while ( (pEnt = gEntList.FindEntityByClassname( pEnt, "env_screenoverlay" )) != NULL )
  124. {
  125. if ( pEnt != this )
  126. {
  127. CEnvScreenOverlay *pOverlay = assert_cast<CEnvScreenOverlay*>(pEnt);
  128. pOverlay->SetActive( false );
  129. }
  130. }
  131. }
  132. int CEnvScreenOverlay::UpdateTransmitState()
  133. {
  134. return SetTransmitState( FL_EDICT_ALWAYS );
  135. }
  136. void CEnvScreenOverlay::InputSwitchOverlay( inputdata_t &inputdata )
  137. {
  138. int iNewOverlay = inputdata.value.Int() - 1;
  139. iNewOverlay = abs( iNewOverlay );
  140. if ( m_iszOverlayNames[iNewOverlay] == NULL_STRING )
  141. {
  142. Warning("env_screenoverlay %s has no overlays to display.\n", STRING(GetEntityName()) );
  143. return;
  144. }
  145. m_iDesiredOverlay = iNewOverlay;
  146. m_flStartTime = gpGlobals->curtime;
  147. }
  148. void CEnvScreenOverlay::InputStopOverlay( inputdata_t &inputdata )
  149. {
  150. if ( m_iszOverlayNames[0] == NULL_STRING )
  151. {
  152. Warning("env_screenoverlay %s has no overlays to display.\n", STRING(GetEntityName()) );
  153. return;
  154. }
  155. m_flStartTime = -1;
  156. m_bIsActive = false;
  157. }
  158. // ====================================================================================
  159. //
  160. // Screen-space effects
  161. //
  162. // ====================================================================================
  163. class CEnvScreenEffect : public CPointEntity
  164. {
  165. DECLARE_CLASS( CEnvScreenEffect, CPointEntity );
  166. public:
  167. DECLARE_DATADESC();
  168. DECLARE_SERVERCLASS();
  169. // We always want to be sent to the client
  170. CEnvScreenEffect( void ) { AddEFlags( EFL_FORCE_CHECK_TRANSMIT ); }
  171. virtual int UpdateTransmitState( void ) { return SetTransmitState( FL_EDICT_ALWAYS ); }
  172. virtual void Spawn( void );
  173. virtual void Precache( void );
  174. private:
  175. void InputStartEffect( inputdata_t &inputdata );
  176. void InputStopEffect( inputdata_t &inputdata );
  177. CNetworkVar( float, m_flDuration );
  178. CNetworkVar( int, m_nType );
  179. };
  180. LINK_ENTITY_TO_CLASS( env_screeneffect, CEnvScreenEffect );
  181. // CEnvScreenEffect
  182. BEGIN_DATADESC( CEnvScreenEffect )
  183. DEFINE_FIELD( m_flDuration, FIELD_FLOAT ),
  184. DEFINE_KEYFIELD( m_nType, FIELD_INTEGER, "type" ),
  185. DEFINE_INPUTFUNC( FIELD_FLOAT, "StartEffect", InputStartEffect ),
  186. DEFINE_INPUTFUNC( FIELD_FLOAT, "StopEffect", InputStopEffect ),
  187. END_DATADESC()
  188. IMPLEMENT_SERVERCLASS_ST( CEnvScreenEffect, DT_EnvScreenEffect )
  189. SendPropFloat( SENDINFO( m_flDuration ), 0, SPROP_NOSCALE ),
  190. SendPropInt( SENDINFO( m_nType ), 32, SPROP_UNSIGNED ),
  191. END_SEND_TABLE()
  192. void CEnvScreenEffect::Spawn( void )
  193. {
  194. Precache();
  195. }
  196. void CEnvScreenEffect::Precache( void )
  197. {
  198. PrecacheMaterial( "effects/stun" );
  199. PrecacheMaterial( "effects/introblur" );
  200. }
  201. //-----------------------------------------------------------------------------
  202. // Purpose:
  203. //-----------------------------------------------------------------------------
  204. void CEnvScreenEffect::InputStartEffect( inputdata_t &inputdata )
  205. {
  206. // Take the duration as our value
  207. m_flDuration = inputdata.value.Float();
  208. EntityMessageBegin( this );
  209. WRITE_BYTE( 0 );
  210. MessageEnd();
  211. }
  212. //-----------------------------------------------------------------------------
  213. // Purpose:
  214. //-----------------------------------------------------------------------------
  215. void CEnvScreenEffect::InputStopEffect( inputdata_t &inputdata )
  216. {
  217. m_flDuration = inputdata.value.Float();
  218. // Send the stop notification
  219. EntityMessageBegin( this );
  220. WRITE_BYTE( 1 );
  221. MessageEnd();
  222. }