summaryrefslogtreecommitdiff
path: root/game/server/tf/func_flag_alert.cpp
blob: ee7f44ae59a03562773d01cda563b9b327e468c9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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 );
}