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.

83 lines
2.3 KiB

  1. // SharedFunctorUtils.cpp
  2. // Useful functors
  3. // Copyright 2006 Turtle Rock Studios, Inc.
  4. #include "cbase.h"
  5. #include "SharedFunctorUtils.h"
  6. #include "collisionutils.h"
  7. // #ifdef CLIENT_DLL
  8. // #include "ClientTerrorPlayer.h"
  9. // #else
  10. // #include "TerrorPlayer.h"
  11. // #endif
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. #if 0
  15. //--------------------------------------------------------------------------------------------------------
  16. bool AvoidActors::operator()( CBaseCombatCharacter *obj )
  17. {
  18. if ( !obj || ( obj == m_owner ) || ( obj->GetTeamNumber() != m_owner->GetTeamNumber() ) )
  19. return true;
  20. #ifdef CLIENT_DLL
  21. if ( obj->IsDormant() )
  22. return true;
  23. #endif
  24. if ( obj->IsSolidFlagSet( FSOLID_NOT_SOLID ) )
  25. return true;
  26. CTerrorPlayer *player = ToTerrorPlayer( obj );
  27. if ( !player )
  28. return true;
  29. if ( player->IsIncapacitatedRevivable() )
  30. return true;
  31. if ( player->IsGhost() )
  32. return true;
  33. Vector objOrigin = obj->GetAbsOrigin();
  34. Vector vObjMins = objOrigin + obj->WorldAlignMins();
  35. Vector vObjMaxs = objOrigin + obj->WorldAlignMaxs();
  36. Vector vOwnerMins = *m_dest + m_owner->WorldAlignMins();
  37. Vector vOwnerMaxs = *m_dest + m_owner->WorldAlignMaxs();
  38. if ( !IsBoxIntersectingBox( vOwnerMins, vOwnerMaxs, vObjMins, vObjMaxs ) )
  39. return true;
  40. float objWidth = vObjMaxs.x - vObjMins.x;
  41. float ownerWidth = vOwnerMaxs.x - vOwnerMins.x;
  42. float idealDistance = (objWidth + ownerWidth) * 0.5f * m_scale;
  43. Vector vDelta = objOrigin - *m_dest;
  44. vDelta.z = 0;
  45. float fDist = vDelta.NormalizeInPlace();
  46. if ( fDist > idealDistance )
  47. return true;
  48. Vector rayOrigin = m_origin;
  49. Vector rayDelta = *m_dest - m_origin;
  50. Vector sphereCenter = objOrigin;
  51. float sphereRadius = idealDistance;
  52. rayOrigin.z = rayDelta.z = sphereCenter.z = 0.0f;
  53. float t1, t2;
  54. if ( IntersectRayWithSphere( rayOrigin, rayDelta, sphereCenter, sphereRadius, &t1, &t2 ) )
  55. {
  56. Vector sphereToDest = *m_dest - sphereCenter;
  57. sphereToDest.z = 0.0f;
  58. if ( !sphereToDest.IsZero() )
  59. {
  60. float radius = sphereToDest.NormalizeInPlace();
  61. sphereToDest *= (idealDistance - radius);
  62. *m_dest += sphereToDest;
  63. m_avoidedActors.AddToTail( obj );
  64. }
  65. }
  66. return true;
  67. }
  68. //--------------------------------------------------------------------------------------------------------
  69. #endif