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.

94 lines
2.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "func_flag_alert.h"
  8. #include "entity_capture_flag.h"
  9. #include "tf_player.h"
  10. #include "tf_gamerules.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. LINK_ENTITY_TO_CLASS( func_flag_alert, CFuncFlagAlertZone );
  14. BEGIN_DATADESC( CFuncFlagAlertZone )
  15. DEFINE_KEYFIELD( m_bPlaySound, FIELD_BOOLEAN, "playsound" ),
  16. DEFINE_KEYFIELD( m_nAlertDelay, FIELD_INTEGER, "alert_delay" ),
  17. DEFINE_OUTPUT( m_OnTriggeredByTeam1, "OnTriggeredByTeam1" ),
  18. DEFINE_OUTPUT( m_OnTriggeredByTeam2, "OnTriggeredByTeam2" ),
  19. END_DATADESC();
  20. //-----------------------------------------------------------------------------
  21. // Purpose:
  22. //-----------------------------------------------------------------------------
  23. CFuncFlagAlertZone::CFuncFlagAlertZone()
  24. {
  25. for ( int i = 0 ; i < TF_TEAM_COUNT ; i++ )
  26. {
  27. m_flNextAlertTime[i] = 0.0f;
  28. }
  29. m_bPlaySound = true;
  30. m_nAlertDelay = 10;
  31. }
  32. //-----------------------------------------------------------------------------`
  33. // Purpose:
  34. //-----------------------------------------------------------------------------
  35. void CFuncFlagAlertZone::Spawn( void )
  36. {
  37. AddSpawnFlags( SF_TRIGGER_ALLOW_ALL );
  38. BaseClass::Spawn();
  39. InitTrigger();
  40. }
  41. //-----------------------------------------------------------------------------
  42. // Purpose:
  43. //-----------------------------------------------------------------------------
  44. void CFuncFlagAlertZone::StartTouch( CBaseEntity *pOther )
  45. {
  46. if ( !m_bDisabled )
  47. {
  48. if ( pOther && pOther->IsPlayer() && ( pOther->GetTeamNumber() != GetTeamNumber() ) )
  49. {
  50. CTFPlayer *pPlayer = ToTFPlayer( pOther );
  51. if ( pPlayer && pPlayer->HasTheFlag() )
  52. {
  53. int iTeamNum = pPlayer->GetTeamNumber();
  54. if ( gpGlobals->curtime > m_flNextAlertTime[iTeamNum] )
  55. {
  56. if ( m_bPlaySound && TFGameRules() )
  57. {
  58. int iBroadcastTeam = ( iTeamNum == TF_TEAM_RED ) ? TF_TEAM_BLUE : TF_TEAM_RED;
  59. TFGameRules()->BroadcastSound( iBroadcastTeam, "Announcer.SecurityAlert" );
  60. }
  61. switch( iTeamNum )
  62. {
  63. case TF_TEAM_RED:
  64. m_OnTriggeredByTeam1.FireOutput( this, this );
  65. break;
  66. case TF_TEAM_BLUE:
  67. m_OnTriggeredByTeam2.FireOutput( this, this );
  68. break;
  69. default:
  70. break;
  71. }
  72. m_flNextAlertTime[iTeamNum] = gpGlobals->curtime + m_nAlertDelay;
  73. }
  74. }
  75. }
  76. }
  77. BaseClass::StartTouch( pOther );
  78. }