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.

85 lines
2.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "playerandobjectenumerator.h"
  9. #include "c_ai_basenpc.h"
  10. #ifdef INVASION_CLIENT_DLL
  11. #include "tf_shareddefs.h"
  12. #endif
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. // Enumator class for ragdolls being affected by explosive forces
  16. CPlayerAndObjectEnumerator::CPlayerAndObjectEnumerator( float radius )
  17. {
  18. m_flRadiusSquared = radius * radius;
  19. m_Objects.RemoveAll();
  20. m_pLocal = C_BasePlayer::GetLocalPlayer();
  21. }
  22. int CPlayerAndObjectEnumerator::GetObjectCount()
  23. {
  24. return m_Objects.Count();
  25. }
  26. C_BaseEntity *CPlayerAndObjectEnumerator::GetObject( int index )
  27. {
  28. if ( index < 0 || index >= GetObjectCount() )
  29. return NULL;
  30. return m_Objects[ index ];
  31. }
  32. // Actual work code
  33. IterationRetval_t CPlayerAndObjectEnumerator::EnumElement( IHandleEntity *pHandleEntity )
  34. {
  35. if ( !m_pLocal )
  36. return ITERATION_STOP;
  37. C_BaseEntity *pEnt = ClientEntityList().GetBaseEntityFromHandle( pHandleEntity->GetRefEHandle() );
  38. if ( pEnt == NULL )
  39. return ITERATION_CONTINUE;
  40. if ( pEnt == m_pLocal )
  41. return ITERATION_CONTINUE;
  42. if ( !pEnt->IsPlayer() &&
  43. !pEnt->IsNPC() )
  44. {
  45. return ITERATION_CONTINUE;
  46. }
  47. if ( pEnt->IsNPC() )
  48. {
  49. C_AI_BaseNPC *pNPC = (C_AI_BaseNPC *)pEnt;
  50. if ( !pNPC->ShouldAvoidObstacle() )
  51. return ITERATION_CONTINUE;
  52. }
  53. // Ignore vehicles, since they have vcollide collisions that's push me away
  54. if ( pEnt->GetCollisionGroup() == COLLISION_GROUP_VEHICLE )
  55. return ITERATION_CONTINUE;
  56. #ifdef INVASION_CLIENT_DLL
  57. // If it's solid to player movement, don't steer around it since we'll just bump into it
  58. if ( pEnt->GetCollisionGroup() == TFCOLLISION_GROUP_OBJECT_SOLIDTOPLAYERMOVEMENT )
  59. return ITERATION_CONTINUE;
  60. #endif
  61. Vector deltaPos = pEnt->GetAbsOrigin() - m_pLocal->GetAbsOrigin();
  62. if ( deltaPos.LengthSqr() > m_flRadiusSquared )
  63. return ITERATION_CONTINUE;
  64. CHandle< C_BaseEntity > h;
  65. h = pEnt;
  66. m_Objects.AddToTail( h );
  67. return ITERATION_CONTINUE;
  68. }