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.

88 lines
2.1 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: Spatial entity with simple radial falloff
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "cbase.h"
  8. #include "c_spatialentity.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. IMPLEMENT_CLIENTCLASS_DT(C_SpatialEntity, DT_SpatialEntity, CSpatialEntity)
  12. RecvPropVector( RECVINFO(m_vecOrigin) ),
  13. RecvPropFloat( RECVINFO(m_minFalloff) ),
  14. RecvPropFloat( RECVINFO(m_maxFalloff) ),
  15. RecvPropFloat( RECVINFO(m_flCurWeight) ),
  16. RecvPropBool( RECVINFO(m_bEnabled) ),
  17. END_RECV_TABLE()
  18. void C_SpatialEntity::OnDataChanged(DataUpdateType_t updateType)
  19. {
  20. BaseClass::OnDataChanged( updateType );
  21. if ( updateType == DATA_UPDATE_CREATED )
  22. {
  23. InitSpatialEntity();
  24. }
  25. }
  26. void C_SpatialEntity::InitSpatialEntity()
  27. {
  28. SetNextClientThink( CLIENT_THINK_ALWAYS );
  29. AddToPersonalSpatialEntityMgr();
  30. m_flWeight = 0.0f;
  31. m_flInfluence = 0.0f;
  32. }
  33. void C_SpatialEntity::UpdateOnRemove( void )
  34. {
  35. BaseClass::UpdateOnRemove();
  36. RemoveFromPersonalSpatialEntityMgr();
  37. }
  38. //------------------------------------------------------------------------------
  39. // We don't draw...
  40. //------------------------------------------------------------------------------
  41. bool C_SpatialEntity::ShouldDraw()
  42. {
  43. return false;
  44. }
  45. void C_SpatialEntity::ClientThink()
  46. {
  47. if( !m_bEnabled && m_flCurWeight == 0.0f )
  48. {
  49. m_flWeight = 0.0f;
  50. return;
  51. }
  52. CBaseEntity *pPlayer = C_BasePlayer::GetLocalPlayer( 0 );
  53. if( !pPlayer )
  54. return;
  55. Vector playerOrigin = pPlayer->GetAbsOrigin();
  56. m_flWeight = 0.0f;
  57. if ( ( m_minFalloff != -1 ) && ( m_maxFalloff != -1 ) && m_minFalloff != m_maxFalloff )
  58. {
  59. float dist = (playerOrigin - m_vecOrigin).Length();
  60. m_flWeight = (dist-m_minFalloff) / (m_maxFalloff-m_minFalloff);
  61. m_flWeight = fpmax( 0.0f, m_flWeight );
  62. m_flWeight = fpmin( 1.0f, m_flWeight );
  63. m_flInfluence = fpmax( 0.0f, m_minFalloff - dist );
  64. }
  65. m_flWeight = m_flCurWeight * ( 1.0f - m_flWeight );
  66. BaseClass::ClientThink();
  67. }