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.

344 lines
8.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Volumetric dust motes.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "func_dust_shared.h"
  9. #include "te_particlesystem.h"
  10. #include "IEffects.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. class CFunc_Dust : public CBaseEntity
  14. {
  15. public:
  16. DECLARE_CLASS( CFunc_Dust, CBaseEntity );
  17. DECLARE_SERVERCLASS();
  18. DECLARE_DATADESC();
  19. CFunc_Dust();
  20. virtual ~CFunc_Dust();
  21. // CBaseEntity overrides.
  22. public:
  23. virtual void Spawn();
  24. virtual void Activate();
  25. virtual void Precache();
  26. virtual bool KeyValue( const char *szKeyName, const char *szValue );
  27. // Input handles.
  28. public:
  29. void InputTurnOn( inputdata_t &inputdata );
  30. void InputTurnOff( inputdata_t &inputdata );
  31. // FGD properties.
  32. public:
  33. CNetworkVar( color32, m_Color );
  34. CNetworkVar( int, m_SpawnRate );
  35. CNetworkVar( float, m_flSizeMin );
  36. CNetworkVar( float, m_flSizeMax );
  37. CNetworkVar( int, m_SpeedMax );
  38. CNetworkVar( int, m_LifetimeMin );
  39. CNetworkVar( int, m_LifetimeMax );
  40. CNetworkVar( int, m_DistMax );
  41. CNetworkVar( float, m_FallSpeed );
  42. CNetworkVar( bool, m_bAffectedByWind );
  43. public:
  44. CNetworkVar( int, m_DustFlags ); // Combination of DUSTFLAGS_
  45. private:
  46. int m_iAlpha;
  47. };
  48. class CFunc_DustMotes : public CFunc_Dust
  49. {
  50. DECLARE_CLASS( CFunc_DustMotes, CFunc_Dust );
  51. public:
  52. CFunc_DustMotes();
  53. };
  54. class CFunc_DustCloud : public CFunc_Dust
  55. {
  56. DECLARE_CLASS( CFunc_DustCloud, CFunc_Dust );
  57. public:
  58. };
  59. // Changing this will break demos. Peeling it out to clamp post creation to fix some shipped maps that specify out of range lifetimes.
  60. #define DUST_LIFETIME_NETWORK_BITS 4
  61. IMPLEMENT_SERVERCLASS_ST_NOBASE( CFunc_Dust, DT_Func_Dust )
  62. SendPropInt( SENDINFO(m_Color), 32, SPROP_UNSIGNED, SendProxy_Color32ToInt32 ),
  63. SendPropInt( SENDINFO(m_SpawnRate), 12, SPROP_UNSIGNED ),
  64. SendPropInt( SENDINFO(m_SpeedMax), 12, SPROP_UNSIGNED ),
  65. SendPropFloat( SENDINFO(m_flSizeMin), 0, SPROP_NOSCALE ),
  66. SendPropFloat( SENDINFO(m_flSizeMax), 0, SPROP_NOSCALE ),
  67. SendPropInt( SENDINFO(m_DistMax), 16, SPROP_UNSIGNED ),
  68. SendPropInt( SENDINFO( m_LifetimeMin ), DUST_LIFETIME_NETWORK_BITS, SPROP_UNSIGNED ),
  69. SendPropInt( SENDINFO( m_LifetimeMax ), DUST_LIFETIME_NETWORK_BITS, SPROP_UNSIGNED ),
  70. SendPropInt( SENDINFO(m_DustFlags), DUST_NUMFLAGS, SPROP_UNSIGNED ),
  71. SendPropModelIndex( SENDINFO(m_nModelIndex) ),
  72. SendPropFloat( SENDINFO(m_FallSpeed), 0, SPROP_NOSCALE ),
  73. SendPropBool( SENDINFO(m_bAffectedByWind) ),
  74. SendPropDataTable( SENDINFO_DT( m_Collision ), &REFERENCE_SEND_TABLE(DT_CollisionProperty) ),
  75. END_SEND_TABLE()
  76. BEGIN_DATADESC( CFunc_Dust )
  77. DEFINE_FIELD( m_DustFlags,FIELD_INTEGER ),
  78. DEFINE_KEYFIELD( m_Color, FIELD_COLOR32, "Color" ),
  79. DEFINE_KEYFIELD( m_SpawnRate, FIELD_INTEGER, "SpawnRate" ),
  80. DEFINE_KEYFIELD( m_flSizeMin, FIELD_FLOAT, "SizeMin" ),
  81. DEFINE_KEYFIELD( m_flSizeMax, FIELD_FLOAT, "SizeMax" ),
  82. DEFINE_KEYFIELD( m_SpeedMax, FIELD_INTEGER, "SpeedMax" ),
  83. DEFINE_KEYFIELD( m_LifetimeMin, FIELD_INTEGER, "LifetimeMin" ),
  84. DEFINE_KEYFIELD( m_LifetimeMax, FIELD_INTEGER, "LifetimeMax" ),
  85. DEFINE_KEYFIELD( m_DistMax, FIELD_INTEGER, "DistMax" ),
  86. DEFINE_FIELD( m_iAlpha, FIELD_INTEGER ),
  87. DEFINE_KEYFIELD( m_FallSpeed, FIELD_FLOAT, "FallSpeed" ),
  88. DEFINE_KEYFIELD( m_bAffectedByWind, FIELD_BOOLEAN, "AffectedByWind" ),
  89. DEFINE_INPUTFUNC( FIELD_VOID, "TurnOn", InputTurnOn ),
  90. DEFINE_INPUTFUNC( FIELD_VOID, "TurnOff", InputTurnOff )
  91. END_DATADESC()
  92. LINK_ENTITY_TO_CLASS( func_dustmotes, CFunc_DustMotes );
  93. LINK_ENTITY_TO_CLASS( func_dustcloud, CFunc_DustCloud );
  94. // ------------------------------------------------------------------------------------- //
  95. // CFunc_DustMotes implementation.
  96. // ------------------------------------------------------------------------------------- //
  97. CFunc_DustMotes::CFunc_DustMotes()
  98. {
  99. m_DustFlags |= DUSTFLAGS_SCALEMOTES;
  100. }
  101. // ------------------------------------------------------------------------------------- //
  102. // CFunc_Dust implementation.
  103. // ------------------------------------------------------------------------------------- //
  104. CFunc_Dust::CFunc_Dust()
  105. {
  106. m_DustFlags = DUSTFLAGS_ON;
  107. m_FallSpeed = 0.0f;
  108. }
  109. CFunc_Dust::~CFunc_Dust()
  110. {
  111. }
  112. void CFunc_Dust::Spawn()
  113. {
  114. Precache();
  115. // Bind to our bmodel.
  116. SetModel( STRING( GetModelName() ) );
  117. //AddSolidFlags( FSOLID_NOT_SOLID );
  118. AddSolidFlags( FSOLID_VOLUME_CONTENTS );
  119. // Clamp to values in a networkable range... can't up the networked bits without breaking demos.
  120. const int unMaxLifetimeVal = (1 << (DUST_LIFETIME_NETWORK_BITS) ) - 1;
  121. m_LifetimeMin = Clamp( m_LifetimeMin.Get(), 0, unMaxLifetimeVal );
  122. m_LifetimeMax = Clamp( m_LifetimeMax.Get(), 0, unMaxLifetimeVal );
  123. //Since keyvalues can arrive in any order, and UTIL_StringToColor32 stomps alpha,
  124. //install the alpha value here.
  125. color32 clr = { m_Color.m_Value.r, m_Color.m_Value.g, m_Color.m_Value.b, m_iAlpha };
  126. m_Color.Set( clr );
  127. BaseClass::Spawn();
  128. }
  129. void CFunc_Dust::Precache()
  130. {
  131. PrecacheMaterial( "particle/sparkles" );
  132. }
  133. void CFunc_Dust::Activate()
  134. {
  135. BaseClass::Activate();
  136. }
  137. bool CFunc_Dust::KeyValue( const char *szKeyName, const char *szValue )
  138. {
  139. if( stricmp( szKeyName, "StartDisabled" ) == 0 )
  140. {
  141. if( szValue[0] == '1' )
  142. m_DustFlags &= ~DUSTFLAGS_ON;
  143. else
  144. m_DustFlags |= DUSTFLAGS_ON;
  145. return true;
  146. }
  147. else if( stricmp( szKeyName, "Alpha" ) == 0 )
  148. {
  149. m_iAlpha = atoi( szValue );
  150. return true;
  151. }
  152. else if( stricmp( szKeyName, "Frozen" ) == 0 )
  153. {
  154. if( szValue[0] == '1' )
  155. m_DustFlags |= DUSTFLAGS_FROZEN;
  156. else
  157. m_DustFlags &= ~DUSTFLAGS_FROZEN;
  158. return true;
  159. }
  160. else
  161. {
  162. return BaseClass::KeyValue( szKeyName, szValue );
  163. }
  164. }
  165. void CFunc_Dust::InputTurnOn( inputdata_t &inputdata )
  166. {
  167. if( !(m_DustFlags & DUSTFLAGS_ON) )
  168. {
  169. m_DustFlags |= DUSTFLAGS_ON;
  170. }
  171. }
  172. void CFunc_Dust::InputTurnOff( inputdata_t &inputdata )
  173. {
  174. if( m_DustFlags & DUSTFLAGS_ON )
  175. {
  176. m_DustFlags &= ~DUSTFLAGS_ON;
  177. }
  178. }
  179. //
  180. // Dust
  181. //
  182. class CTEDust : public CTEParticleSystem
  183. {
  184. public:
  185. DECLARE_CLASS( CTEDust, CTEParticleSystem );
  186. DECLARE_SERVERCLASS();
  187. CTEDust( const char *name );
  188. virtual ~CTEDust( void );
  189. virtual void Test( const Vector& current_origin, const QAngle& current_angles ) { };
  190. CNetworkVar( float, m_flSize );
  191. CNetworkVar( float, m_flSpeed );
  192. CNetworkVector( m_vecDirection );
  193. };
  194. CTEDust::CTEDust( const char *name ) : BaseClass( name )
  195. {
  196. m_flSize = 1.0f;
  197. m_flSpeed = 1.0f;
  198. m_vecDirection.Init();
  199. }
  200. CTEDust::~CTEDust( void )
  201. {
  202. }
  203. IMPLEMENT_SERVERCLASS_ST( CTEDust, DT_TEDust )
  204. SendPropFloat( SENDINFO(m_flSize), -1, SPROP_COORD ),
  205. SendPropFloat( SENDINFO(m_flSpeed), -1, SPROP_COORD ),
  206. SendPropVector( SENDINFO(m_vecDirection), 4, 0, -1.0f, 1.0f ), // cheap normal
  207. END_SEND_TABLE()
  208. static CTEDust g_TEDust( "Dust" );
  209. //-----------------------------------------------------------------------------
  210. // Purpose:
  211. // Input : &pos -
  212. // &angles -
  213. //-----------------------------------------------------------------------------
  214. void TE_Dust( IRecipientFilter& filter, float delay,
  215. const Vector &pos, const Vector &dir, float size, float speed )
  216. {
  217. g_TEDust.m_vecOrigin = pos;
  218. g_TEDust.m_vecDirection = dir;
  219. g_TEDust.m_flSize = size;
  220. g_TEDust.m_flSpeed = speed;
  221. Assert( dir.Length() < 1.01 ); // make sure it's a normal
  222. //Send it
  223. g_TEDust.Create( filter, delay );
  224. }
  225. class CEnvDustPuff : public CPointEntity
  226. {
  227. DECLARE_CLASS( CEnvDustPuff, CPointEntity );
  228. public:
  229. DECLARE_DATADESC();
  230. protected:
  231. // Input handlers
  232. void InputSpawnDust( inputdata_t &inputdata );
  233. float m_flScale;
  234. color32 m_rgbaColor;
  235. };
  236. LINK_ENTITY_TO_CLASS( env_dustpuff, CEnvDustPuff );
  237. BEGIN_DATADESC( CEnvDustPuff )
  238. DEFINE_KEYFIELD( m_flScale, FIELD_FLOAT, "scale" ),
  239. DEFINE_KEYFIELD( m_rgbaColor, FIELD_COLOR32, "color" ),
  240. // Function Pointers
  241. DEFINE_INPUTFUNC( FIELD_VOID, "SpawnDust", InputSpawnDust ),
  242. END_DATADESC()
  243. //-----------------------------------------------------------------------------
  244. // Purpose:
  245. // Input : &inputdata -
  246. //-----------------------------------------------------------------------------
  247. void CEnvDustPuff::InputSpawnDust( inputdata_t &inputdata )
  248. {
  249. Vector dir;
  250. AngleVectors( GetAbsAngles(), &dir );
  251. VectorNormalize( dir );
  252. g_pEffects->Dust( GetAbsOrigin(), dir, m_flScale, m_flSpeed );
  253. }