Team Fortress 2 Source Code as on 22/4/2020
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.

645 lines
19 KiB

  1. //========= Copyright 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. UTIL_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. UTIL_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, 255 );
  291. }
  292. //-----------------------------------------------------------------------------
  293. // Purpose:
  294. // Output : SporeTrail*
  295. //-----------------------------------------------------------------------------
  296. SporeTrail* SporeTrail::CreateSporeTrail()
  297. {
  298. CBaseEntity *pEnt = CreateEntityByName( SPORETRAIL_ENTITYNAME );
  299. if(pEnt)
  300. {
  301. SporeTrail *pSpore = dynamic_cast<SporeTrail*>(pEnt);
  302. if ( pSpore )
  303. {
  304. pSpore->Activate();
  305. return pSpore;
  306. }
  307. else
  308. {
  309. UTIL_Remove( pEnt );
  310. }
  311. }
  312. return NULL;
  313. }
  314. //==================================================
  315. // SporeExplosion
  316. //==================================================
  317. IMPLEMENT_SERVERCLASS_ST( SporeExplosion, DT_SporeExplosion )
  318. SendPropFloat (SENDINFO(m_flSpawnRate), 8, 0, 1, 1024),
  319. SendPropFloat (SENDINFO(m_flParticleLifetime), 16, SPROP_ROUNDUP, 0.1, 100),
  320. SendPropFloat (SENDINFO(m_flStartSize), -1, SPROP_NOSCALE),
  321. SendPropFloat (SENDINFO(m_flEndSize), -1, SPROP_NOSCALE),
  322. SendPropFloat (SENDINFO(m_flSpawnRadius), -1, SPROP_NOSCALE),
  323. SendPropBool (SENDINFO(m_bEmit) ),
  324. SendPropBool (SENDINFO(m_bDontRemove) ),
  325. END_SEND_TABLE()
  326. LINK_ENTITY_TO_CLASS( env_sporeexplosion, SporeExplosion );
  327. BEGIN_DATADESC( SporeExplosion )
  328. DEFINE_KEYFIELD( m_flSpawnRate, FIELD_FLOAT, "spawnrate" ),
  329. DEFINE_FIELD( m_flParticleLifetime, FIELD_FLOAT ),
  330. DEFINE_FIELD( m_flStartSize, FIELD_FLOAT ),
  331. DEFINE_FIELD( m_flEndSize, FIELD_FLOAT ),
  332. DEFINE_FIELD( m_flSpawnRadius, FIELD_FLOAT ),
  333. DEFINE_FIELD( m_bEmit, FIELD_BOOLEAN ),
  334. DEFINE_KEYFIELD( m_bDisabled, FIELD_BOOLEAN, "startdisabled" ),
  335. DEFINE_FIELD( m_bDontRemove, FIELD_BOOLEAN ),
  336. DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
  337. DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
  338. END_DATADESC()
  339. SporeExplosion::SporeExplosion( void )
  340. {
  341. m_flSpawnRate = 100.0f;
  342. m_flParticleLifetime = 1.0f;
  343. m_flStartSize = 1.0f;
  344. m_flEndSize = 0.0f;
  345. m_flSpawnRadius = 16.0f;
  346. SetRenderColor( 255, 255, 255, 255 );
  347. m_bEmit = true;
  348. m_bDisabled = false;
  349. }
  350. //-----------------------------------------------------------------------------
  351. //-----------------------------------------------------------------------------
  352. void SporeExplosion::Spawn( void )
  353. {
  354. BaseClass::Spawn();
  355. m_bEmit = false;
  356. }
  357. //-----------------------------------------------------------------------------
  358. // Purpose:
  359. // Output : SporeExplosion*
  360. //-----------------------------------------------------------------------------
  361. SporeExplosion *SporeExplosion::CreateSporeExplosion()
  362. {
  363. CBaseEntity *pEnt = CreateEntityByName( SPOREEXPLOSION_ENTITYNAME );
  364. if ( pEnt )
  365. {
  366. SporeExplosion *pSpore = dynamic_cast<SporeExplosion*>(pEnt);
  367. if ( pSpore )
  368. {
  369. pSpore->Activate();
  370. return pSpore;
  371. }
  372. else
  373. {
  374. UTIL_Remove( pEnt );
  375. }
  376. }
  377. return NULL;
  378. }
  379. void SporeExplosion::InputEnable( inputdata_t &inputdata )
  380. {
  381. m_bDontRemove = true;
  382. m_bDisabled = false;
  383. m_bEmit = true;
  384. }
  385. void SporeExplosion::InputDisable( inputdata_t &inputdata )
  386. {
  387. m_bDontRemove = true;
  388. m_bDisabled = true;
  389. m_bEmit = false;
  390. }
  391. BEGIN_DATADESC( CFireTrail )
  392. DEFINE_FIELD( m_flLifetime, FIELD_FLOAT ),
  393. DEFINE_FIELD( m_nAttachment, FIELD_INTEGER ),
  394. END_DATADESC()
  395. IMPLEMENT_SERVERCLASS_ST( CFireTrail, DT_FireTrail )
  396. SendPropInt( SENDINFO( m_nAttachment ), 32 ),
  397. SendPropFloat( SENDINFO( m_flLifetime ), 0, SPROP_NOSCALE ),
  398. END_SEND_TABLE()
  399. LINK_ENTITY_TO_CLASS( env_fire_trail, CFireTrail );
  400. void CFireTrail::Precache( void )
  401. {
  402. PrecacheMaterial( "sprites/flamelet1" );
  403. PrecacheMaterial( "sprites/flamelet2" );
  404. PrecacheMaterial( "sprites/flamelet3" );
  405. PrecacheMaterial( "sprites/flamelet4" );
  406. PrecacheMaterial( "sprites/flamelet5" );
  407. PrecacheMaterial( "particle/particle_smokegrenade" );
  408. PrecacheMaterial( "particle/particle_noisesphere" );
  409. }
  410. //-----------------------------------------------------------------------------
  411. // Purpose: Attach the smoke trail to an entity or point
  412. // Input : index - entity that has the attachment
  413. // attachment - point to attach to
  414. //-----------------------------------------------------------------------------
  415. void CFireTrail::FollowEntity( CBaseEntity *pEntity, const char *pAttachmentName )
  416. {
  417. // For attachments
  418. if ( pAttachmentName && pEntity && pEntity->GetBaseAnimating() )
  419. {
  420. m_nAttachment = pEntity->GetBaseAnimating()->LookupAttachment( pAttachmentName );
  421. }
  422. else
  423. {
  424. m_nAttachment = 0;
  425. }
  426. BaseClass::FollowEntity( pEntity );
  427. }
  428. //-----------------------------------------------------------------------------
  429. // Purpose: Create and return a new fire trail entity
  430. //-----------------------------------------------------------------------------
  431. CFireTrail *CFireTrail::CreateFireTrail( void )
  432. {
  433. CBaseEntity *pEnt = CreateEntityByName( "env_fire_trail" );
  434. if ( pEnt )
  435. {
  436. CFireTrail *pTrail = dynamic_cast<CFireTrail*>(pEnt);
  437. if ( pTrail )
  438. {
  439. pTrail->Activate();
  440. return pTrail;
  441. }
  442. else
  443. {
  444. UTIL_Remove( pEnt );
  445. }
  446. }
  447. return NULL;
  448. }
  449. //-----------------------------------------------------------------------------
  450. //Data table
  451. //-----------------------------------------------------------------------------
  452. IMPLEMENT_SERVERCLASS_ST(DustTrail, DT_DustTrail)
  453. SendPropFloat(SENDINFO(m_SpawnRate), 8, 0, 1, 1024),
  454. SendPropVector(SENDINFO(m_Color), 8, 0, 0, 1),
  455. SendPropFloat(SENDINFO(m_ParticleLifetime), 16, SPROP_ROUNDUP, 0.1, 100),
  456. SendPropFloat(SENDINFO(m_StopEmitTime), 0, SPROP_NOSCALE),
  457. SendPropFloat(SENDINFO(m_MinSpeed), -1, SPROP_NOSCALE),
  458. SendPropFloat(SENDINFO(m_MaxSpeed), -1, SPROP_NOSCALE),
  459. SendPropFloat(SENDINFO(m_MinDirectedSpeed), -1, SPROP_NOSCALE),
  460. SendPropFloat(SENDINFO(m_MaxDirectedSpeed), -1, SPROP_NOSCALE),
  461. SendPropFloat(SENDINFO(m_StartSize), -1, SPROP_NOSCALE),
  462. SendPropFloat(SENDINFO(m_EndSize), -1, SPROP_NOSCALE),
  463. SendPropFloat(SENDINFO(m_SpawnRadius), -1, SPROP_NOSCALE),
  464. SendPropBool(SENDINFO(m_bEmit) ),
  465. SendPropFloat(SENDINFO(m_Opacity), -1, SPROP_NOSCALE),
  466. END_SEND_TABLE()
  467. LINK_ENTITY_TO_CLASS( env_dusttrail, DustTrail);
  468. BEGIN_DATADESC( DustTrail )
  469. DEFINE_FIELD( m_Color, FIELD_VECTOR ),
  470. DEFINE_KEYFIELD( m_Opacity, FIELD_FLOAT, "opacity" ),
  471. DEFINE_KEYFIELD( m_SpawnRate, FIELD_FLOAT, "spawnrate" ),
  472. DEFINE_KEYFIELD( m_ParticleLifetime, FIELD_FLOAT, "lifetime" ),
  473. DEFINE_FIELD( m_StopEmitTime, FIELD_TIME ),
  474. DEFINE_KEYFIELD( m_MinSpeed, FIELD_FLOAT, "minspeed" ),
  475. DEFINE_KEYFIELD( m_MaxSpeed, FIELD_FLOAT, "maxspeed" ),
  476. DEFINE_KEYFIELD( m_MinDirectedSpeed, FIELD_FLOAT, "mindirectedspeed" ),
  477. DEFINE_KEYFIELD( m_MaxDirectedSpeed, FIELD_FLOAT, "maxdirectedspeed" ),
  478. DEFINE_KEYFIELD( m_StartSize, FIELD_FLOAT, "startsize" ),
  479. DEFINE_KEYFIELD( m_EndSize, FIELD_FLOAT, "endsize" ),
  480. DEFINE_KEYFIELD( m_SpawnRadius, FIELD_FLOAT, "spawnradius" ),
  481. DEFINE_FIELD( m_bEmit, FIELD_BOOLEAN ),
  482. DEFINE_FIELD( m_nAttachment, FIELD_INTEGER ),
  483. END_DATADESC()
  484. //-----------------------------------------------------------------------------
  485. // Purpose:
  486. // Output :
  487. //-----------------------------------------------------------------------------
  488. DustTrail::DustTrail()
  489. {
  490. m_SpawnRate = 10;
  491. m_Color.GetForModify().Init(0.5, 0.5, 0.5);
  492. m_ParticleLifetime = 5;
  493. m_StopEmitTime = 0; // Don't stop emitting particles
  494. m_MinSpeed = 2;
  495. m_MaxSpeed = 4;
  496. m_MinDirectedSpeed = m_MaxDirectedSpeed = 0;
  497. m_StartSize = 35;
  498. m_EndSize = 55;
  499. m_SpawnRadius = 2;
  500. m_bEmit = true;
  501. m_Opacity = 0.5f;
  502. }
  503. //-----------------------------------------------------------------------------
  504. // Parse data from a map file
  505. //-----------------------------------------------------------------------------
  506. bool DustTrail::KeyValue( const char *szKeyName, const char *szValue )
  507. {
  508. if ( FStrEq( szKeyName, "color" ) )
  509. {
  510. color32 tmp;
  511. UTIL_StringToColor32( &tmp, szValue );
  512. m_Color.GetForModify().Init( tmp.r / 255.0f, tmp.g / 255.0f, tmp.b / 255.0f );
  513. return true;
  514. }
  515. if ( FStrEq( szKeyName, "emittime" ) )
  516. {
  517. m_StopEmitTime = gpGlobals->curtime + atof( szValue );
  518. return true;
  519. }
  520. return BaseClass::KeyValue( szKeyName, szValue );
  521. }
  522. //-----------------------------------------------------------------------------
  523. // Purpose :
  524. // Input :
  525. // Output :
  526. //-----------------------------------------------------------------------------
  527. void DustTrail::SetEmit(bool bVal)
  528. {
  529. m_bEmit = bVal;
  530. }
  531. //-----------------------------------------------------------------------------
  532. // Purpose:
  533. // Output : DustTrail*
  534. //-----------------------------------------------------------------------------
  535. DustTrail* DustTrail::CreateDustTrail()
  536. {
  537. CBaseEntity *pEnt = CreateEntityByName(DUSTTRAIL_ENTITYNAME);
  538. if(pEnt)
  539. {
  540. DustTrail *pDust = dynamic_cast<DustTrail*>(pEnt);
  541. if(pDust)
  542. {
  543. pDust->Activate();
  544. return pDust;
  545. }
  546. else
  547. {
  548. UTIL_Remove(pEnt);
  549. }
  550. }
  551. return NULL;
  552. }