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.

647 lines
19 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "smoke_trail.h"
  10. #include "dt_send.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. #define SMOKETRAIL_ENTITYNAME "env_smoketrail"
  14. #define SPORETRAIL_ENTITYNAME "env_sporetrail"
  15. #define SPOREEXPLOSION_ENTITYNAME "env_sporeexplosion"
  16. #define DUSTTRAIL_ENTITYNAME "env_dusttrail"
  17. //-----------------------------------------------------------------------------
  18. //Data table
  19. //-----------------------------------------------------------------------------
  20. IMPLEMENT_SERVERCLASS_ST(SmokeTrail, DT_SmokeTrail)
  21. SendPropFloat(SENDINFO(m_SpawnRate), 8, 0, 1, 1024),
  22. SendPropVector(SENDINFO(m_StartColor), 8, 0, 0, 1),
  23. SendPropVector(SENDINFO(m_EndColor), 8, 0, 0, 1),
  24. SendPropFloat(SENDINFO(m_ParticleLifetime), 16, SPROP_ROUNDUP, 0.1, 100),
  25. SendPropFloat(SENDINFO(m_StopEmitTime), 0, SPROP_NOSCALE),
  26. SendPropFloat(SENDINFO(m_MinSpeed), -1, SPROP_NOSCALE),
  27. SendPropFloat(SENDINFO(m_MaxSpeed), -1, SPROP_NOSCALE),
  28. SendPropFloat(SENDINFO(m_MinDirectedSpeed), -1, SPROP_NOSCALE),
  29. SendPropFloat(SENDINFO(m_MaxDirectedSpeed), -1, SPROP_NOSCALE),
  30. SendPropFloat(SENDINFO(m_StartSize), -1, SPROP_NOSCALE),
  31. SendPropFloat(SENDINFO(m_EndSize), -1, SPROP_NOSCALE),
  32. SendPropFloat(SENDINFO(m_SpawnRadius), -1, SPROP_NOSCALE),
  33. SendPropBool(SENDINFO(m_bEmit) ),
  34. SendPropInt(SENDINFO(m_nAttachment), 32 ),
  35. SendPropFloat(SENDINFO(m_Opacity), -1, SPROP_NOSCALE),
  36. END_SEND_TABLE()
  37. LINK_ENTITY_TO_CLASS(env_smoketrail, SmokeTrail);
  38. BEGIN_DATADESC( SmokeTrail )
  39. DEFINE_FIELD( m_StartColor, FIELD_VECTOR ),
  40. DEFINE_FIELD( m_EndColor, FIELD_VECTOR ),
  41. DEFINE_KEYFIELD( m_Opacity, FIELD_FLOAT, "opacity" ),
  42. DEFINE_KEYFIELD( m_SpawnRate, FIELD_FLOAT, "spawnrate" ),
  43. DEFINE_KEYFIELD( m_ParticleLifetime, FIELD_FLOAT, "lifetime" ),
  44. DEFINE_FIELD( m_StopEmitTime, FIELD_TIME ),
  45. DEFINE_KEYFIELD( m_MinSpeed, FIELD_FLOAT, "minspeed" ),
  46. DEFINE_KEYFIELD( m_MaxSpeed, FIELD_FLOAT, "maxspeed" ),
  47. DEFINE_KEYFIELD( m_MinDirectedSpeed, FIELD_FLOAT, "mindirectedspeed" ),
  48. DEFINE_KEYFIELD( m_MaxDirectedSpeed, FIELD_FLOAT, "maxdirectedspeed" ),
  49. DEFINE_KEYFIELD( m_StartSize, FIELD_FLOAT, "startsize" ),
  50. DEFINE_KEYFIELD( m_EndSize, FIELD_FLOAT, "endsize" ),
  51. DEFINE_KEYFIELD( m_SpawnRadius, FIELD_FLOAT, "spawnradius" ),
  52. DEFINE_FIELD( m_bEmit, FIELD_BOOLEAN ),
  53. DEFINE_FIELD( m_nAttachment, FIELD_INTEGER ),
  54. END_DATADESC()
  55. //-----------------------------------------------------------------------------
  56. // Purpose:
  57. // Output :
  58. //-----------------------------------------------------------------------------
  59. SmokeTrail::SmokeTrail()
  60. {
  61. m_SpawnRate = 10;
  62. m_StartColor.GetForModify().Init(0.5, 0.5, 0.5);
  63. m_EndColor.GetForModify().Init(0,0,0);
  64. m_ParticleLifetime = 5;
  65. m_StopEmitTime = 0; // Don't stop emitting particles
  66. m_MinSpeed = 2;
  67. m_MaxSpeed = 4;
  68. m_MinDirectedSpeed = m_MaxDirectedSpeed = 0;
  69. m_StartSize = 35;
  70. m_EndSize = 55;
  71. m_SpawnRadius = 2;
  72. m_bEmit = true;
  73. m_nAttachment = 0;
  74. m_Opacity = 0.5f;
  75. }
  76. //-----------------------------------------------------------------------------
  77. // Parse data from a map file
  78. //-----------------------------------------------------------------------------
  79. bool SmokeTrail::KeyValue( const char *szKeyName, const char *szValue )
  80. {
  81. if ( FStrEq( szKeyName, "startcolor" ) )
  82. {
  83. color32 tmp;
  84. V_StringToColor32( &tmp, szValue );
  85. m_StartColor.GetForModify().Init( tmp.r / 255.0f, tmp.g / 255.0f, tmp.b / 255.0f );
  86. return true;
  87. }
  88. if ( FStrEq( szKeyName, "endcolor" ) )
  89. {
  90. color32 tmp;
  91. V_StringToColor32( &tmp, szValue );
  92. m_EndColor.GetForModify().Init( tmp.r / 255.0f, tmp.g / 255.0f, tmp.b / 255.0f );
  93. return true;
  94. }
  95. if ( FStrEq( szKeyName, "emittime" ) )
  96. {
  97. m_StopEmitTime = gpGlobals->curtime + atof( szValue );
  98. return true;
  99. }
  100. return BaseClass::KeyValue( szKeyName, szValue );
  101. }
  102. //-----------------------------------------------------------------------------
  103. // Purpose :
  104. // Input :
  105. // Output :
  106. //-----------------------------------------------------------------------------
  107. void SmokeTrail::SetEmit(bool bVal)
  108. {
  109. m_bEmit = bVal;
  110. }
  111. //-----------------------------------------------------------------------------
  112. // Purpose:
  113. // Output : SmokeTrail*
  114. //-----------------------------------------------------------------------------
  115. SmokeTrail* SmokeTrail::CreateSmokeTrail()
  116. {
  117. CBaseEntity *pEnt = CreateEntityByName(SMOKETRAIL_ENTITYNAME);
  118. if(pEnt)
  119. {
  120. SmokeTrail *pSmoke = dynamic_cast<SmokeTrail*>(pEnt);
  121. if(pSmoke)
  122. {
  123. pSmoke->Activate();
  124. return pSmoke;
  125. }
  126. else
  127. {
  128. UTIL_Remove(pEnt);
  129. }
  130. }
  131. return NULL;
  132. }
  133. //-----------------------------------------------------------------------------
  134. // Purpose: Attach the smoke trail to an entity or point
  135. // Input : index - entity that has the attachment
  136. // attachment - point to attach to
  137. //-----------------------------------------------------------------------------
  138. void SmokeTrail::FollowEntity( CBaseEntity *pEntity, const char *pAttachmentName )
  139. {
  140. // For attachments
  141. if ( pAttachmentName && pEntity && pEntity->GetBaseAnimating() )
  142. {
  143. m_nAttachment = pEntity->GetBaseAnimating()->LookupAttachment( pAttachmentName );
  144. }
  145. else
  146. {
  147. m_nAttachment = 0;
  148. }
  149. BaseClass::FollowEntity( pEntity );
  150. }
  151. //==================================================
  152. // RocketTrail
  153. //==================================================
  154. //Data table
  155. IMPLEMENT_SERVERCLASS_ST(RocketTrail, DT_RocketTrail)
  156. SendPropFloat(SENDINFO(m_SpawnRate), 8, 0, 1, 1024),
  157. SendPropVector(SENDINFO(m_StartColor), 8, 0, 0, 1),
  158. SendPropVector(SENDINFO(m_EndColor), 8, 0, 0, 1),
  159. SendPropFloat(SENDINFO(m_ParticleLifetime), 16, SPROP_ROUNDUP, 0.1, 100),
  160. SendPropFloat(SENDINFO(m_StopEmitTime), 0, SPROP_NOSCALE),
  161. SendPropFloat(SENDINFO(m_MinSpeed), -1, SPROP_NOSCALE),
  162. SendPropFloat(SENDINFO(m_MaxSpeed), -1, SPROP_NOSCALE),
  163. SendPropFloat(SENDINFO(m_StartSize), -1, SPROP_NOSCALE),
  164. SendPropFloat(SENDINFO(m_EndSize), -1, SPROP_NOSCALE),
  165. SendPropFloat(SENDINFO(m_SpawnRadius), -1, SPROP_NOSCALE),
  166. SendPropBool(SENDINFO(m_bEmit)),
  167. SendPropInt(SENDINFO(m_nAttachment), 32 ),
  168. SendPropFloat(SENDINFO(m_Opacity), -1, SPROP_NOSCALE),
  169. SendPropInt (SENDINFO(m_bDamaged), 1, SPROP_UNSIGNED),
  170. SendPropFloat(SENDINFO(m_flFlareScale), -1, SPROP_NOSCALE),
  171. END_SEND_TABLE()
  172. LINK_ENTITY_TO_CLASS( env_rockettrail, RocketTrail );
  173. BEGIN_DATADESC( RocketTrail )
  174. DEFINE_FIELD( m_StartColor, FIELD_VECTOR ),
  175. DEFINE_FIELD( m_EndColor, FIELD_VECTOR ),
  176. DEFINE_FIELD( m_Opacity, FIELD_FLOAT ),
  177. DEFINE_FIELD( m_SpawnRate, FIELD_FLOAT ),
  178. DEFINE_FIELD( m_ParticleLifetime, FIELD_FLOAT ),
  179. DEFINE_FIELD( m_StopEmitTime, FIELD_TIME ),
  180. DEFINE_FIELD( m_MinSpeed, FIELD_FLOAT ),
  181. DEFINE_FIELD( m_MaxSpeed, FIELD_FLOAT ),
  182. DEFINE_FIELD( m_StartSize, FIELD_FLOAT ),
  183. DEFINE_FIELD( m_EndSize, FIELD_FLOAT ),
  184. DEFINE_FIELD( m_SpawnRadius, FIELD_FLOAT ),
  185. DEFINE_FIELD( m_bEmit, FIELD_BOOLEAN ),
  186. DEFINE_FIELD( m_nAttachment, FIELD_INTEGER ),
  187. DEFINE_FIELD( m_bDamaged, FIELD_BOOLEAN ),
  188. DEFINE_FIELD( m_flFlareScale, FIELD_FLOAT ),
  189. END_DATADESC()
  190. //-----------------------------------------------------------------------------
  191. // Purpose:
  192. // Output :
  193. //-----------------------------------------------------------------------------
  194. RocketTrail::RocketTrail()
  195. {
  196. m_SpawnRate = 10;
  197. m_StartColor.GetForModify().Init(0.5, 0.5, 0.5);
  198. m_EndColor.GetForModify().Init(0,0,0);
  199. m_ParticleLifetime = 5;
  200. m_StopEmitTime = 0; // Don't stop emitting particles
  201. m_MinSpeed = 2;
  202. m_MaxSpeed = 4;
  203. m_StartSize = 35;
  204. m_EndSize = 55;
  205. m_SpawnRadius = 2;
  206. m_bEmit = true;
  207. m_nAttachment = 0;
  208. m_Opacity = 0.5f;
  209. m_flFlareScale = 1.5;
  210. }
  211. //------------------------------------------------------------------------------
  212. // Purpose :
  213. // Input :
  214. // Output :
  215. //------------------------------------------------------------------------------
  216. void RocketTrail::SetEmit(bool bVal)
  217. {
  218. m_bEmit = bVal;
  219. }
  220. //-----------------------------------------------------------------------------
  221. // Purpose:
  222. // Output : SmokeTrail*
  223. //-----------------------------------------------------------------------------
  224. RocketTrail* RocketTrail::CreateRocketTrail()
  225. {
  226. CBaseEntity *pEnt = CreateEntityByName( "env_rockettrail" );
  227. if( pEnt != NULL )
  228. {
  229. RocketTrail *pTrail = dynamic_cast<RocketTrail*>(pEnt);
  230. if( pTrail != NULL )
  231. {
  232. pTrail->Activate();
  233. return pTrail;
  234. }
  235. else
  236. {
  237. UTIL_Remove( pEnt );
  238. }
  239. }
  240. return NULL;
  241. }
  242. //-----------------------------------------------------------------------------
  243. // Purpose: Attach the smoke trail to an entity or point
  244. // Input : index - entity that has the attachment
  245. // attachment - point to attach to
  246. //-----------------------------------------------------------------------------
  247. void RocketTrail::FollowEntity( CBaseEntity *pEntity, const char *pAttachmentName )
  248. {
  249. // For attachments
  250. if ( pAttachmentName && pEntity && pEntity->GetBaseAnimating() )
  251. {
  252. m_nAttachment = pEntity->GetBaseAnimating()->LookupAttachment( pAttachmentName );
  253. }
  254. else
  255. {
  256. m_nAttachment = 0;
  257. }
  258. BaseClass::FollowEntity( pEntity );
  259. }
  260. //==================================================
  261. // SporeTrail
  262. //==================================================
  263. IMPLEMENT_SERVERCLASS_ST( SporeTrail, DT_SporeTrail )
  264. SendPropFloat (SENDINFO(m_flSpawnRate), 8, 0, 1, 1024),
  265. SendPropVector (SENDINFO(m_vecEndColor), 8, 0, 0, 1),
  266. SendPropFloat (SENDINFO(m_flParticleLifetime), 16, SPROP_ROUNDUP, 0.1, 100),
  267. SendPropFloat (SENDINFO(m_flStartSize), -1, SPROP_NOSCALE),
  268. SendPropFloat (SENDINFO(m_flEndSize), -1, SPROP_NOSCALE),
  269. SendPropFloat (SENDINFO(m_flSpawnRadius), -1, SPROP_NOSCALE),
  270. SendPropBool (SENDINFO(m_bEmit)),
  271. END_SEND_TABLE()
  272. LINK_ENTITY_TO_CLASS(env_sporetrail, SporeTrail);
  273. BEGIN_DATADESC( SporeTrail )
  274. DEFINE_FIELD( m_vecEndColor, FIELD_VECTOR ),
  275. DEFINE_FIELD( m_flSpawnRate, FIELD_FLOAT ),
  276. DEFINE_FIELD( m_flParticleLifetime, FIELD_FLOAT ),
  277. DEFINE_FIELD( m_flStartSize, FIELD_FLOAT ),
  278. DEFINE_FIELD( m_flEndSize, FIELD_FLOAT ),
  279. DEFINE_FIELD( m_flSpawnRadius, FIELD_FLOAT ),
  280. DEFINE_FIELD( m_bEmit, FIELD_BOOLEAN ),
  281. END_DATADESC()
  282. SporeTrail::SporeTrail( void )
  283. {
  284. m_vecEndColor.GetForModify().Init();
  285. m_flSpawnRate = 100.0f;
  286. m_flParticleLifetime = 1.0f;
  287. m_flStartSize = 1.0f;
  288. m_flEndSize = 0.0f;
  289. m_flSpawnRadius = 16.0f;
  290. SetRenderColor( 255, 255, 255 );
  291. SetRenderAlpha( 255 );
  292. }
  293. //-----------------------------------------------------------------------------
  294. // Purpose:
  295. // Output : SporeTrail*
  296. //-----------------------------------------------------------------------------
  297. SporeTrail* SporeTrail::CreateSporeTrail()
  298. {
  299. CBaseEntity *pEnt = CreateEntityByName( SPORETRAIL_ENTITYNAME );
  300. if(pEnt)
  301. {
  302. SporeTrail *pSpore = dynamic_cast<SporeTrail*>(pEnt);
  303. if ( pSpore )
  304. {
  305. pSpore->Activate();
  306. return pSpore;
  307. }
  308. else
  309. {
  310. UTIL_Remove( pEnt );
  311. }
  312. }
  313. return NULL;
  314. }
  315. //==================================================
  316. // SporeExplosion
  317. //==================================================
  318. IMPLEMENT_SERVERCLASS_ST( SporeExplosion, DT_SporeExplosion )
  319. SendPropFloat (SENDINFO(m_flSpawnRate), 8, 0, 1, 1024),
  320. SendPropFloat (SENDINFO(m_flParticleLifetime), 16, SPROP_ROUNDUP, 0.1, 100),
  321. SendPropFloat (SENDINFO(m_flStartSize), -1, SPROP_NOSCALE),
  322. SendPropFloat (SENDINFO(m_flEndSize), -1, SPROP_NOSCALE),
  323. SendPropFloat (SENDINFO(m_flSpawnRadius), -1, SPROP_NOSCALE),
  324. SendPropBool (SENDINFO(m_bEmit) ),
  325. SendPropBool (SENDINFO(m_bDontRemove) ),
  326. END_SEND_TABLE()
  327. LINK_ENTITY_TO_CLASS( env_sporeexplosion, SporeExplosion );
  328. BEGIN_DATADESC( SporeExplosion )
  329. DEFINE_KEYFIELD( m_flSpawnRate, FIELD_FLOAT, "spawnrate" ),
  330. DEFINE_FIELD( m_flParticleLifetime, FIELD_FLOAT ),
  331. DEFINE_FIELD( m_flStartSize, FIELD_FLOAT ),
  332. DEFINE_FIELD( m_flEndSize, FIELD_FLOAT ),
  333. DEFINE_FIELD( m_flSpawnRadius, FIELD_FLOAT ),
  334. DEFINE_FIELD( m_bEmit, FIELD_BOOLEAN ),
  335. DEFINE_KEYFIELD( m_bDisabled, FIELD_BOOLEAN, "startdisabled" ),
  336. DEFINE_FIELD( m_bDontRemove, FIELD_BOOLEAN ),
  337. DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
  338. DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
  339. END_DATADESC()
  340. SporeExplosion::SporeExplosion( void )
  341. {
  342. m_flSpawnRate = 100.0f;
  343. m_flParticleLifetime = 1.0f;
  344. m_flStartSize = 1.0f;
  345. m_flEndSize = 0.0f;
  346. m_flSpawnRadius = 16.0f;
  347. SetRenderColor( 255, 255, 255 );
  348. SetRenderAlpha( 255 );
  349. m_bEmit = true;
  350. m_bDisabled = false;
  351. }
  352. //-----------------------------------------------------------------------------
  353. //-----------------------------------------------------------------------------
  354. void SporeExplosion::Spawn( void )
  355. {
  356. BaseClass::Spawn();
  357. m_bEmit = false;
  358. }
  359. //-----------------------------------------------------------------------------
  360. // Purpose:
  361. // Output : SporeExplosion*
  362. //-----------------------------------------------------------------------------
  363. SporeExplosion *SporeExplosion::CreateSporeExplosion()
  364. {
  365. CBaseEntity *pEnt = CreateEntityByName( SPOREEXPLOSION_ENTITYNAME );
  366. if ( pEnt )
  367. {
  368. SporeExplosion *pSpore = dynamic_cast<SporeExplosion*>(pEnt);
  369. if ( pSpore )
  370. {
  371. pSpore->Activate();
  372. return pSpore;
  373. }
  374. else
  375. {
  376. UTIL_Remove( pEnt );
  377. }
  378. }
  379. return NULL;
  380. }
  381. void SporeExplosion::InputEnable( inputdata_t &inputdata )
  382. {
  383. m_bDontRemove = true;
  384. m_bDisabled = false;
  385. m_bEmit = true;
  386. }
  387. void SporeExplosion::InputDisable( inputdata_t &inputdata )
  388. {
  389. m_bDontRemove = true;
  390. m_bDisabled = true;
  391. m_bEmit = false;
  392. }
  393. BEGIN_DATADESC( CFireTrail )
  394. DEFINE_FIELD( m_flLifetime, FIELD_FLOAT ),
  395. DEFINE_FIELD( m_nAttachment, FIELD_INTEGER ),
  396. END_DATADESC()
  397. IMPLEMENT_SERVERCLASS_ST( CFireTrail, DT_FireTrail )
  398. SendPropInt( SENDINFO( m_nAttachment ), 32 ),
  399. SendPropFloat( SENDINFO( m_flLifetime ), 0, SPROP_NOSCALE ),
  400. END_SEND_TABLE()
  401. LINK_ENTITY_TO_CLASS( env_fire_trail, CFireTrail );
  402. void CFireTrail::Precache( void )
  403. {
  404. PrecacheMaterial( "sprites/flamelet1" );
  405. PrecacheMaterial( "sprites/flamelet2" );
  406. PrecacheMaterial( "sprites/flamelet3" );
  407. PrecacheMaterial( "sprites/flamelet4" );
  408. PrecacheMaterial( "sprites/flamelet5" );
  409. PrecacheMaterial( "particle/particle_smokegrenade" );
  410. PrecacheMaterial( "particle/particle_noisesphere" );
  411. }
  412. //-----------------------------------------------------------------------------
  413. // Purpose: Attach the smoke trail to an entity or point
  414. // Input : index - entity that has the attachment
  415. // attachment - point to attach to
  416. //-----------------------------------------------------------------------------
  417. void CFireTrail::FollowEntity( CBaseEntity *pEntity, const char *pAttachmentName )
  418. {
  419. // For attachments
  420. if ( pAttachmentName && pEntity && pEntity->GetBaseAnimating() )
  421. {
  422. m_nAttachment = pEntity->GetBaseAnimating()->LookupAttachment( pAttachmentName );
  423. }
  424. else
  425. {
  426. m_nAttachment = 0;
  427. }
  428. BaseClass::FollowEntity( pEntity );
  429. }
  430. //-----------------------------------------------------------------------------
  431. // Purpose: Create and return a new fire trail entity
  432. //-----------------------------------------------------------------------------
  433. CFireTrail *CFireTrail::CreateFireTrail( void )
  434. {
  435. CBaseEntity *pEnt = CreateEntityByName( "env_fire_trail" );
  436. if ( pEnt )
  437. {
  438. CFireTrail *pTrail = dynamic_cast<CFireTrail*>(pEnt);
  439. if ( pTrail )
  440. {
  441. pTrail->Activate();
  442. return pTrail;
  443. }
  444. else
  445. {
  446. UTIL_Remove( pEnt );
  447. }
  448. }
  449. return NULL;
  450. }
  451. //-----------------------------------------------------------------------------
  452. //Data table
  453. //-----------------------------------------------------------------------------
  454. IMPLEMENT_SERVERCLASS_ST(DustTrail, DT_DustTrail)
  455. SendPropFloat(SENDINFO(m_SpawnRate), 8, 0, 1, 1024),
  456. SendPropVector(SENDINFO(m_Color), 8, 0, 0, 1),
  457. SendPropFloat(SENDINFO(m_ParticleLifetime), 16, SPROP_ROUNDUP, 0.1, 100),
  458. SendPropFloat(SENDINFO(m_StopEmitTime), 0, SPROP_NOSCALE),
  459. SendPropFloat(SENDINFO(m_MinSpeed), -1, SPROP_NOSCALE),
  460. SendPropFloat(SENDINFO(m_MaxSpeed), -1, SPROP_NOSCALE),
  461. SendPropFloat(SENDINFO(m_MinDirectedSpeed), -1, SPROP_NOSCALE),
  462. SendPropFloat(SENDINFO(m_MaxDirectedSpeed), -1, SPROP_NOSCALE),
  463. SendPropFloat(SENDINFO(m_StartSize), -1, SPROP_NOSCALE),
  464. SendPropFloat(SENDINFO(m_EndSize), -1, SPROP_NOSCALE),
  465. SendPropFloat(SENDINFO(m_SpawnRadius), -1, SPROP_NOSCALE),
  466. SendPropBool(SENDINFO(m_bEmit) ),
  467. SendPropFloat(SENDINFO(m_Opacity), -1, SPROP_NOSCALE),
  468. END_SEND_TABLE()
  469. LINK_ENTITY_TO_CLASS( env_dusttrail, DustTrail);
  470. BEGIN_DATADESC( DustTrail )
  471. DEFINE_FIELD( m_Color, FIELD_VECTOR ),
  472. DEFINE_KEYFIELD( m_Opacity, FIELD_FLOAT, "opacity" ),
  473. DEFINE_KEYFIELD( m_SpawnRate, FIELD_FLOAT, "spawnrate" ),
  474. DEFINE_KEYFIELD( m_ParticleLifetime, FIELD_FLOAT, "lifetime" ),
  475. DEFINE_FIELD( m_StopEmitTime, FIELD_TIME ),
  476. DEFINE_KEYFIELD( m_MinSpeed, FIELD_FLOAT, "minspeed" ),
  477. DEFINE_KEYFIELD( m_MaxSpeed, FIELD_FLOAT, "maxspeed" ),
  478. DEFINE_KEYFIELD( m_MinDirectedSpeed, FIELD_FLOAT, "mindirectedspeed" ),
  479. DEFINE_KEYFIELD( m_MaxDirectedSpeed, FIELD_FLOAT, "maxdirectedspeed" ),
  480. DEFINE_KEYFIELD( m_StartSize, FIELD_FLOAT, "startsize" ),
  481. DEFINE_KEYFIELD( m_EndSize, FIELD_FLOAT, "endsize" ),
  482. DEFINE_KEYFIELD( m_SpawnRadius, FIELD_FLOAT, "spawnradius" ),
  483. DEFINE_FIELD( m_bEmit, FIELD_BOOLEAN ),
  484. DEFINE_FIELD( m_nAttachment, FIELD_INTEGER ),
  485. END_DATADESC()
  486. //-----------------------------------------------------------------------------
  487. // Purpose:
  488. // Output :
  489. //-----------------------------------------------------------------------------
  490. DustTrail::DustTrail()
  491. {
  492. m_SpawnRate = 10;
  493. m_Color.GetForModify().Init(0.5, 0.5, 0.5);
  494. m_ParticleLifetime = 5;
  495. m_StopEmitTime = 0; // Don't stop emitting particles
  496. m_MinSpeed = 2;
  497. m_MaxSpeed = 4;
  498. m_MinDirectedSpeed = m_MaxDirectedSpeed = 0;
  499. m_StartSize = 35;
  500. m_EndSize = 55;
  501. m_SpawnRadius = 2;
  502. m_bEmit = true;
  503. m_Opacity = 0.5f;
  504. }
  505. //-----------------------------------------------------------------------------
  506. // Parse data from a map file
  507. //-----------------------------------------------------------------------------
  508. bool DustTrail::KeyValue( const char *szKeyName, const char *szValue )
  509. {
  510. if ( FStrEq( szKeyName, "color" ) )
  511. {
  512. color32 tmp;
  513. V_StringToColor32( &tmp, szValue );
  514. m_Color.GetForModify().Init( tmp.r / 255.0f, tmp.g / 255.0f, tmp.b / 255.0f );
  515. return true;
  516. }
  517. if ( FStrEq( szKeyName, "emittime" ) )
  518. {
  519. m_StopEmitTime = gpGlobals->curtime + atof( szValue );
  520. return true;
  521. }
  522. return BaseClass::KeyValue( szKeyName, szValue );
  523. }
  524. //-----------------------------------------------------------------------------
  525. // Purpose :
  526. // Input :
  527. // Output :
  528. //-----------------------------------------------------------------------------
  529. void DustTrail::SetEmit(bool bVal)
  530. {
  531. m_bEmit = bVal;
  532. }
  533. //-----------------------------------------------------------------------------
  534. // Purpose:
  535. // Output : DustTrail*
  536. //-----------------------------------------------------------------------------
  537. DustTrail* DustTrail::CreateDustTrail()
  538. {
  539. CBaseEntity *pEnt = CreateEntityByName(DUSTTRAIL_ENTITYNAME);
  540. if(pEnt)
  541. {
  542. DustTrail *pDust = dynamic_cast<DustTrail*>(pEnt);
  543. if(pDust)
  544. {
  545. pDust->Activate();
  546. return pDust;
  547. }
  548. else
  549. {
  550. UTIL_Remove(pEnt);
  551. }
  552. }
  553. return NULL;
  554. }