diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/server/tf/func_flag_alert.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'game/server/tf/func_flag_alert.cpp')
| -rw-r--r-- | game/server/tf/func_flag_alert.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/game/server/tf/func_flag_alert.cpp b/game/server/tf/func_flag_alert.cpp new file mode 100644 index 0000000..ee7f44a --- /dev/null +++ b/game/server/tf/func_flag_alert.cpp @@ -0,0 +1,94 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#include "cbase.h" +#include "func_flag_alert.h" +#include "entity_capture_flag.h" +#include "tf_player.h" +#include "tf_gamerules.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +LINK_ENTITY_TO_CLASS( func_flag_alert, CFuncFlagAlertZone ); + +BEGIN_DATADESC( CFuncFlagAlertZone ) + + DEFINE_KEYFIELD( m_bPlaySound, FIELD_BOOLEAN, "playsound" ), + DEFINE_KEYFIELD( m_nAlertDelay, FIELD_INTEGER, "alert_delay" ), + + DEFINE_OUTPUT( m_OnTriggeredByTeam1, "OnTriggeredByTeam1" ), + DEFINE_OUTPUT( m_OnTriggeredByTeam2, "OnTriggeredByTeam2" ), + +END_DATADESC(); + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +CFuncFlagAlertZone::CFuncFlagAlertZone() +{ + for ( int i = 0 ; i < TF_TEAM_COUNT ; i++ ) + { + m_flNextAlertTime[i] = 0.0f; + } + + m_bPlaySound = true; + m_nAlertDelay = 10; +} + +//-----------------------------------------------------------------------------` +// Purpose: +//----------------------------------------------------------------------------- +void CFuncFlagAlertZone::Spawn( void ) +{ + AddSpawnFlags( SF_TRIGGER_ALLOW_ALL ); + + BaseClass::Spawn(); + InitTrigger(); +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CFuncFlagAlertZone::StartTouch( CBaseEntity *pOther ) +{ + if ( !m_bDisabled ) + { + if ( pOther && pOther->IsPlayer() && ( pOther->GetTeamNumber() != GetTeamNumber() ) ) + { + CTFPlayer *pPlayer = ToTFPlayer( pOther ); + if ( pPlayer && pPlayer->HasTheFlag() ) + { + int iTeamNum = pPlayer->GetTeamNumber(); + + if ( gpGlobals->curtime > m_flNextAlertTime[iTeamNum] ) + { + if ( m_bPlaySound && TFGameRules() ) + { + int iBroadcastTeam = ( iTeamNum == TF_TEAM_RED ) ? TF_TEAM_BLUE : TF_TEAM_RED; + TFGameRules()->BroadcastSound( iBroadcastTeam, "Announcer.SecurityAlert" ); + } + + switch( iTeamNum ) + { + case TF_TEAM_RED: + m_OnTriggeredByTeam1.FireOutput( this, this ); + break; + case TF_TEAM_BLUE: + m_OnTriggeredByTeam2.FireOutput( this, this ); + break; + default: + break; + } + + m_flNextAlertTime[iTeamNum] = gpGlobals->curtime + m_nAlertDelay; + } + } + } + } + + BaseClass::StartTouch( pOther ); +} |