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.

85 lines
2.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "func_respawnflag.h"
  8. #include "entity_capture_flag.h"
  9. #include "tf_player.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. LINK_ENTITY_TO_CLASS( func_respawnflag, CFuncRespawnFlagZone );
  13. BEGIN_DATADESC( CFuncRespawnFlagZone )
  14. // Functions.
  15. DEFINE_FUNCTION( Touch ),
  16. END_DATADESC();
  17. //-----------------------------------------------------------------------------
  18. // Purpose:
  19. //-----------------------------------------------------------------------------
  20. CFuncRespawnFlagZone::CFuncRespawnFlagZone()
  21. {
  22. }
  23. //-----------------------------------------------------------------------------
  24. // Purpose:
  25. //-----------------------------------------------------------------------------
  26. void CFuncRespawnFlagZone::Spawn( void )
  27. {
  28. AddSpawnFlags( SF_TRIGGER_ALLOW_ALL );
  29. BaseClass::Spawn();
  30. InitTrigger();
  31. SetTouch( &CFuncRespawnFlagZone::Touch );
  32. }
  33. //-----------------------------------------------------------------------------
  34. // Purpose:
  35. //-----------------------------------------------------------------------------
  36. void CFuncRespawnFlagZone::Touch( CBaseEntity *pOther )
  37. {
  38. if ( !m_bDisabled )
  39. {
  40. if ( pOther->IsPlayer() )
  41. {
  42. CTFPlayer *pPlayer = ToTFPlayer( pOther );
  43. if ( pPlayer && pPlayer->HasTheFlag() )
  44. {
  45. CCaptureFlag *pFlag = dynamic_cast<CCaptureFlag*>( pPlayer->GetItem() );
  46. pPlayer->DropFlag();
  47. if ( pFlag )
  48. {
  49. pFlag->ResetFlag();
  50. }
  51. }
  52. }
  53. }
  54. }
  55. //-----------------------------------------------------------------------------
  56. // Purpose: Return true if the specified entity is in a RespawnFlag zone
  57. //-----------------------------------------------------------------------------
  58. bool PointInRespawnFlagZone( const Vector &vecPoint )
  59. {
  60. CBaseEntity *pTempEnt = NULL;
  61. while ( ( pTempEnt = gEntList.FindEntityByClassname( pTempEnt, "func_respawnflag" ) ) != NULL )
  62. {
  63. CFuncRespawnFlagZone *pZone = dynamic_cast<CFuncRespawnFlagZone *>(pTempEnt);
  64. if ( pZone && !pZone->m_bDisabled && pZone->PointIsWithin( vecPoint ) )
  65. {
  66. return true;
  67. }
  68. }
  69. return false;
  70. }