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.

83 lines
2.3 KiB

  1. // SharedFunctorUtils.cpp
  2. // Useful functors
  3. //========= Copyright Valve Corporation, All rights reserved. ============//
  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. //--------------------------------------------------------------------------------------------------------
  15. bool AvoidActors::operator()( CBaseCombatCharacter *obj )
  16. {
  17. if ( !obj || ( obj == m_owner ) || ( obj->GetTeamNumber() != m_owner->GetTeamNumber() ) )
  18. return true;
  19. #ifdef CLIENT_DLL
  20. if ( obj->IsDormant() )
  21. return true;
  22. #endif
  23. if ( obj->IsSolidFlagSet( FSOLID_NOT_SOLID ) )
  24. return true;
  25. CTerrorPlayer *player = ToTerrorPlayer( obj );
  26. if ( !player )
  27. return true;
  28. if ( player->IsIncapacitatedRevivable() )
  29. return true;
  30. if ( player->IsGhost() )
  31. return true;
  32. Vector objOrigin = obj->GetAbsOrigin();
  33. Vector vObjMins = objOrigin + obj->WorldAlignMins();
  34. Vector vObjMaxs = objOrigin + obj->WorldAlignMaxs();
  35. Vector vOwnerMins = *m_dest + m_owner->WorldAlignMins();
  36. Vector vOwnerMaxs = *m_dest + m_owner->WorldAlignMaxs();
  37. if ( !IsBoxIntersectingBox( vOwnerMins, vOwnerMaxs, vObjMins, vObjMaxs ) )
  38. return true;
  39. float objWidth = vObjMaxs.x - vObjMins.x;
  40. float ownerWidth = vOwnerMaxs.x - vOwnerMins.x;
  41. float idealDistance = (objWidth + ownerWidth) * 0.5f * m_scale;
  42. Vector vDelta = objOrigin - *m_dest;
  43. vDelta.z = 0;
  44. float fDist = vDelta.NormalizeInPlace();
  45. if ( fDist > idealDistance )
  46. return true;
  47. Vector rayOrigin = m_origin;
  48. Vector rayDelta = *m_dest - m_origin;
  49. Vector sphereCenter = objOrigin;
  50. float sphereRadius = idealDistance;
  51. rayOrigin.z = rayDelta.z = sphereCenter.z = 0.0f;
  52. float t1, t2;
  53. if ( IntersectRayWithSphere( rayOrigin, rayDelta, sphereCenter, sphereRadius, &t1, &t2 ) )
  54. {
  55. Vector sphereToDest = *m_dest - sphereCenter;
  56. sphereToDest.z = 0.0f;
  57. if ( !sphereToDest.IsZero() )
  58. {
  59. float radius = sphereToDest.NormalizeInPlace();
  60. sphereToDest *= (idealDistance - radius);
  61. *m_dest += sphereToDest;
  62. m_avoidedActors.AddToTail( obj );
  63. }
  64. }
  65. return true;
  66. }
  67. //--------------------------------------------------------------------------------------------------------