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.

82 lines
2.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "tf_passtime_ball.h"
  9. #include "tf_passtime_logic.h"
  10. #include "trigger_passtime_ball.h"
  11. #include "tf_player.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. //----------------------------------------------------------------------
  15. LINK_ENTITY_TO_CLASS( trigger_passtime_ball, CTriggerPasstimeBall );
  16. //-----------------------------------------------------------------------------
  17. BEGIN_DATADESC( CTriggerPasstimeBall )
  18. DEFINE_OUTPUT( m_onBallEnter, "OnBallEnter" ),
  19. DEFINE_OUTPUT( m_onBallExit, "OnBallExit" ),
  20. END_DATADESC()
  21. //-----------------------------------------------------------------------------
  22. void CTriggerPasstimeBall::Spawn()
  23. {
  24. m_bPresent = false;
  25. BaseClass::Spawn();
  26. SetSolid( SOLID_BSP );
  27. AddSolidFlags( FSOLID_NOT_SOLID | FSOLID_TRIGGER );
  28. SetMoveType( MOVETYPE_NONE );
  29. SetModel( STRING( GetModelName() ) ); // set size and link into world
  30. AddEffects( EF_NODRAW );
  31. SetThink( &CTriggerPasstimeBall::Update );
  32. SetNextThink( gpGlobals->curtime );
  33. }
  34. //-----------------------------------------------------------------------------
  35. static CBaseEntity *s_EntitiesInSphere[32];
  36. bool CTriggerPasstimeBall::BTouching( CBaseEntity *pEnt )
  37. {
  38. Ray_t ray;
  39. trace_t tr;
  40. ICollideable *pCollide = CollisionProp();
  41. ray.Init( pEnt->GetAbsOrigin(), pEnt->GetAbsOrigin() );
  42. enginetrace->ClipRayToCollideable( ray, MASK_ALL, pCollide, &tr );
  43. return ( tr.startsolid );
  44. }
  45. //-----------------------------------------------------------------------------
  46. void CTriggerPasstimeBall::Update()
  47. {
  48. // This is a crappy way to do this, but I couldn't find any way to make
  49. // a normal trigger do what I want because I want enter/exit to be handled
  50. // correctly when the ball is hidden.
  51. // It would be more efficient to have the ball do this, but I'm
  52. // trying to isolate this hack to where it makes the most sense.
  53. SetNextThink( gpGlobals->curtime );
  54. if ( !g_pPasstimeLogic || !g_pPasstimeLogic->GetBall() )
  55. return;
  56. CPasstimeBall *pBall = g_pPasstimeLogic->GetBall();
  57. CBaseEntity *pEnt = pBall->GetCarrier();
  58. if ( !pEnt ) pEnt = pBall;
  59. bool bPresentNow = (pEnt && BTouching( pEnt ));
  60. if ( bPresentNow && !m_bPresent )
  61. {
  62. m_onBallEnter.FireOutput( this, this );
  63. }
  64. else if ( !bPresentNow && m_bPresent )
  65. {
  66. m_onBallExit.FireOutput( this, this );
  67. }
  68. m_bPresent = bPresentNow;
  69. }