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.

70 lines
1.5 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef PLAYERENUMERATOR_H
  8. #define PLAYERENUMERATOR_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "utlvector.h"
  13. #include "ehandle.h"
  14. #include "ispatialpartition.h"
  15. class C_BaseEntity;
  16. class CPlayerEnumerator : public IPartitionEnumerator
  17. {
  18. DECLARE_CLASS_NOBASE( CPlayerEnumerator );
  19. public:
  20. //Forced constructor
  21. CPlayerEnumerator( float radius, Vector vecOrigin )
  22. {
  23. m_flRadiusSquared = radius * radius;
  24. m_vecOrigin = vecOrigin;
  25. m_Objects.RemoveAll();
  26. }
  27. int GetObjectCount() { return m_Objects.Count(); }
  28. C_BaseEntity *GetObject( int index )
  29. {
  30. if ( index < 0 || index >= GetObjectCount() )
  31. return NULL;
  32. return m_Objects[ index ];
  33. }
  34. //Actual work code
  35. virtual IterationRetval_t EnumElement( IHandleEntity *pHandleEntity )
  36. {
  37. C_BaseEntity *pEnt = ClientEntityList().GetBaseEntityFromHandle( pHandleEntity->GetRefEHandle() );
  38. if ( pEnt == NULL )
  39. return ITERATION_CONTINUE;
  40. if ( !pEnt->IsPlayer() )
  41. return ITERATION_CONTINUE;
  42. Vector deltaPos = pEnt->GetAbsOrigin() - m_vecOrigin;
  43. if ( deltaPos.LengthSqr() > m_flRadiusSquared )
  44. return ITERATION_CONTINUE;
  45. CHandle< C_BaseEntity > h;
  46. h = pEnt;
  47. m_Objects.AddToTail( h );
  48. return ITERATION_CONTINUE;
  49. }
  50. public:
  51. //Data members
  52. float m_flRadiusSquared;
  53. Vector m_vecOrigin;
  54. CUtlVector< CHandle< C_BaseEntity > > m_Objects;
  55. };
  56. #endif // PLAYERENUMERATOR_H