summaryrefslogtreecommitdiff
path: root/game/server/tf/func_capture_zone.cpp
blob: 551d37803d6756dc191f6876ab6d32d88520fc07 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: CTF Flag Capture Zone.
//
//=============================================================================//
#include "cbase.h"
#include "func_capture_zone.h"
#include "tf_player.h"
#include "tf_item.h"
#include "tf_team.h"
#include "tf_gamerules.h"
#include "entity_capture_flag.h"
#include "tf_logic_player_destruction.h"

//=============================================================================
//
// CTF Flag Capture Zone tables.
//

BEGIN_DATADESC( CCaptureZone )

// Keyfields.
DEFINE_KEYFIELD( m_nCapturePoint, FIELD_INTEGER, "CapturePoint" ),
DEFINE_KEYFIELD( m_flCaptureDelay, FIELD_FLOAT, "capture_delay" ),
DEFINE_KEYFIELD( m_flCaptureDelayOffset, FIELD_FLOAT, "capture_delay_offset" ),
DEFINE_KEYFIELD( m_bShouldBlock, FIELD_BOOLEAN, "shouldBlock" ),

// Functions.
DEFINE_FUNCTION( CCaptureZoneShim::Touch ),

// Inputs.
DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),

// Outputs.
DEFINE_OUTPUT( m_outputOnCapture, "OnCapture" ),
DEFINE_OUTPUT( m_OnCapTeam1, "OnCapTeam1" ),
DEFINE_OUTPUT( m_OnCapTeam2, "OnCapTeam2" ),
DEFINE_OUTPUT( m_OnCapTeam1_PD, "OnCapTeam1_PD" ),
DEFINE_OUTPUT( m_OnCapTeam2_PD, "OnCapTeam2_PD" ),

END_DATADESC()

LINK_ENTITY_TO_CLASS( func_capturezone, CCaptureZone );


IMPLEMENT_SERVERCLASS_ST( CCaptureZone, DT_CaptureZone )
	SendPropBool( SENDINFO( m_bDisabled ) ),
END_SEND_TABLE()

IMPLEMENT_AUTO_LIST( ICaptureZoneAutoList );

//=============================================================================
//
// CTF Flag Capture Zone functions.
//

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CCaptureZone::CCaptureZone()
{
	m_bShouldBlock = true;
	m_flCaptureDelay = 1.1f;
	m_flCaptureDelayOffset = 0.025f;
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCaptureZone::Spawn()
{
	InitTrigger();
	SetTouch( &CCaptureZoneShim::Touch );

	if ( m_bDisabled )
	{
		SetDisabled( true );
	}

	m_flNextTouchingEnemyZoneWarning = -1;
	AddSpawnFlags( SF_TRIGGER_ALLOW_ALL ); // so we can keep track of who is touching us
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CCaptureZone::Activate( void )
{
	BaseClass::Activate();

	if ( TFGameRules() && ( TFGameRules()->GetGameType() == TF_GAMETYPE_PD ) )
	{
		SetThink( &CCaptureZone::PlayerDestructionThink );
		SetNextThink( gpGlobals->curtime + 0.1 );
	}
	else
	{
		SetThink( NULL );
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CCaptureZone::PlayerDestructionThink( void )
{
	SetNextThink( gpGlobals->curtime + 0.1 );

	if ( !IsDisabled() )
	{
		bool bRedInZone = false;
		bool bBlueInZone = false;

		// nothing to do while no-one is touching us
		if ( m_hTouchingEntities.Count() == 0 )
			return;

		// loop through the touching players to figure out the teams involved
		for ( int i = 0; i < m_hTouchingEntities.Count(); i++ )
		{
			CBaseEntity *pEnt = m_hTouchingEntities[i];
			if ( pEnt && pEnt->IsPlayer() )
			{
				CTFPlayer *pTFPlayer = ToTFPlayer( pEnt );
				if ( pTFPlayer && pTFPlayer->IsAlive() )
				{
					if ( pTFPlayer->GetTeamNumber() == TF_TEAM_RED )
					{
						bRedInZone = true;
					}
					else if ( pTFPlayer->GetTeamNumber() == TF_TEAM_BLUE )
					{
						bBlueInZone = true;
					}
				}
			}
		}

		// safety check, but this should have already been caught by the ( m_hTouchingEntities.Count() == 0 ) check above
		if ( !bRedInZone && !bBlueInZone )
			return;

		if ( m_bShouldBlock )
		{
			// both teams are touching the zone and they block each other
			if ( bRedInZone && bBlueInZone )
				return;
		}

		CUtlVector< CTFPlayer* > playerVector;
		CollectPlayers( &playerVector, TF_TEAM_RED );
		CollectPlayers( &playerVector, TF_TEAM_BLUE, false, APPEND_PLAYERS );
		float flCaptureDelay = m_flCaptureDelay	- ( m_flCaptureDelayOffset * playerVector.Count() );

		// let's see if anyone has any player destruction points to capture
		for ( int i = 0; i < m_hTouchingEntities.Count(); i++ )
		{
			CBaseEntity *pEnt = m_hTouchingEntities[i];
			if ( pEnt && pEnt->IsPlayer() )
			{
				CTFPlayer *pTFPlayer = ToTFPlayer( pEnt );
				if ( pTFPlayer && pTFPlayer->IsAlive() )
				{
					// does this capture point have a team number assigned?
					if ( ( GetTeamNumber() != TEAM_UNASSIGNED ) && ( pTFPlayer->GetTeamNumber() != GetTeamNumber() ) )
						continue;

					if ( pTFPlayer->HasTheFlag() && pTFPlayer->CanScorePointForPD() )
					{
						CCaptureFlag *pFlag = dynamic_cast< CCaptureFlag* >( pTFPlayer->GetItem() );

						int nPoints = pFlag->GetPointValue();
						if ( nPoints > 0 )
						{
							// decrease the number of points
							pFlag->AddPointValue( -1 );

							// fire the output
							switch ( pTFPlayer->GetTeamNumber() )
							{
							case TF_TEAM_RED:
								m_OnCapTeam1_PD.FireOutput( this, this );
								break;
							case TF_TEAM_BLUE:
								m_OnCapTeam2_PD.FireOutput( this, this );
								break;
							default:
								break;
							}

							IGameEvent *event = gameeventmanager->CreateEvent( "special_score" );
							if ( event )
							{
								event->SetInt( "player", pTFPlayer->entindex() );
								gameeventmanager->FireEvent( event );
							}
						}

						// remove this flag if this was the last point
						if ( pFlag->GetPointValue() == 0 )
						{
							UTIL_Remove( pFlag );
						}

						if ( CTFPlayerDestructionLogic::GetPlayerDestructionLogic() )
						{
							CTFPlayerDestructionLogic::GetPlayerDestructionLogic()->CalcTeamLeader( pTFPlayer->GetTeamNumber() );
						}

						pTFPlayer->SetNextScorePointForPD( gpGlobals->curtime + flCaptureDelay );
					}
				}
			}
		}
	}
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCaptureZone::ShimTouch( CBaseEntity *pOther )
{
	// Is the zone enabled?
	if ( IsDisabled() )
		return;

	// Get the TF player.
	CTFPlayer *pPlayer = ToTFPlayer( pOther );
	if ( pPlayer )
	{
		// Check to see if the player has the capture flag.
		if ( pPlayer->HasItem() && ( pPlayer->GetItem()->GetItemID() == TF_ITEM_CAPTURE_FLAG ) )
		{
			CCaptureFlag *pFlag = dynamic_cast<CCaptureFlag*>( pPlayer->GetItem() );
			if ( pFlag )
			{
				// we have a special think that will handle the player destruction flags
				if ( pFlag->GetType() == TF_FLAGTYPE_PLAYER_DESTRUCTION )
					return;

				if ( !pFlag->IsCaptured() )
				{
					// does this capture point have a team number assigned?
					if ( GetTeamNumber() != TEAM_UNASSIGNED )
					{
						// Check to see if the capture zone team matches the player's team.
						if ( pPlayer->GetTeamNumber() != TEAM_UNASSIGNED && pPlayer->GetTeamNumber() != GetTeamNumber() )
						{
							if ( pFlag->GetType() == TF_FLAGTYPE_CTF )
							{
								// Do this at most once every 5 seconds
								if ( m_flNextTouchingEnemyZoneWarning < gpGlobals->curtime )
								{
									CSingleUserRecipientFilter filter( pPlayer );
									TFGameRules()->SendHudNotification( filter, HUD_NOTIFY_TOUCHING_ENEMY_CTF_CAP );
									m_flNextTouchingEnemyZoneWarning = gpGlobals->curtime + 5;
								}
							}
		// 						else if ( pFlag->GetGameType() == TF_FLAGTYPE_INVADE )
		// 						{
		// 						}

							return;
						}
					}
				}

				// in MvM, the "flag" is the bomb and is captured when the carrying bot deploys it
				if ( TFGameRules()->FlagsMayBeCapped() && !TFGameRules()->IsMannVsMachineMode() )
				{
					Capture( pOther );
				}
			}
		}
	}
}

void CCaptureZone::Capture( CBaseEntity *pOther )
{
	CTFPlayer *pPlayer = ToTFPlayer( pOther );
	if ( pPlayer )
	{
		// Check to see if the player has the capture flag and flag is allowed to be captured.
		if ( pPlayer->HasItem() && ( pPlayer->GetItem()->GetItemID() == TF_ITEM_CAPTURE_FLAG ) && TFGameRules()->CanFlagBeCaptured( pOther ) )
		{
			CCaptureFlag *pFlag = dynamic_cast< CCaptureFlag* >( pPlayer->GetItem() );
			if ( !pFlag )
				return;

			// we have a special think that will handle the player destruction flags
			if ( pFlag->GetType() == TF_FLAGTYPE_PLAYER_DESTRUCTION )
				return;

			if ( !pFlag->IsCaptured() )
			{
				pFlag->Capture( pPlayer, m_nCapturePoint );

				// Outputs
				m_outputOnCapture.FireOutput( this, this );

				switch ( pPlayer->GetTeamNumber() )
				{
				case TF_TEAM_RED:
					m_OnCapTeam1.FireOutput( this, this );
					break;
				case TF_TEAM_BLUE:
					m_OnCapTeam2.FireOutput( this, this );
					break;
				default:
					break;
				}

				IGameEvent *event = gameeventmanager->CreateEvent( "ctf_flag_captured" );
				if ( event )
				{
					int iCappingTeam = pPlayer->GetTeamNumber();
					int	iCappingTeamScore = 0;
					CTFTeam* pCappingTeam = pPlayer->GetTFTeam();
					if ( pCappingTeam )
					{
						iCappingTeamScore = pCappingTeam->GetFlagCaptures();
					}

					event->SetInt( "capping_team", iCappingTeam );
					event->SetInt( "capping_team_score", iCappingTeamScore );
					event->SetInt( "capper", pPlayer->GetUserID() );
					event->SetInt( "priority", 9 ); // HLTV priority

					gameeventmanager->FireEvent( event );
				}

				if ( TFGameRules() )
				{
					if ( TFGameRules()->IsHolidayActive( kHoliday_EOTL ) )
					{
						TFGameRules()->DropBonusDuck( pPlayer->GetAbsOrigin(), pPlayer, NULL, NULL, false, true );
					}
					else if ( TFGameRules()->IsHolidayActive( kHoliday_Halloween ) )
					{
						TFGameRules()->DropHalloweenSoulPackToTeam( 5, GetAbsOrigin(), pPlayer->GetTeamNumber(), TEAM_SPECTATOR );
					}
				}
			}
		}
		else if ( !TFGameRules()->CanFlagBeCaptured( pOther ) && TFGameRules()->IsPowerupMode() )
		{ 
			ClientPrint( pPlayer, HUD_PRINTCENTER, "Cannot capture - your flag is not at base!" );
		}
	}
}

//-----------------------------------------------------------------------------
// Purpose: The timer is always transmitted to clients
//-----------------------------------------------------------------------------
int CCaptureZone::UpdateTransmitState()
{
	// ALWAYS transmit to all clients.
	return SetTransmitState( FL_EDICT_ALWAYS );
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CCaptureZone::IsDisabled( void )
{
	return m_bDisabled;
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCaptureZone::InputEnable( inputdata_t &inputdata )
{
	SetDisabled( false );
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCaptureZone::InputDisable( inputdata_t &inputdata )
{
	SetDisabled( true );
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCaptureZone::SetDisabled( bool bDisabled )
{
	m_bDisabled.Set( bDisabled );

	if ( bDisabled )
	{
		BaseClass::Disable();
		SetTouch( NULL );
	}
	else
	{
		BaseClass::Enable();
		SetTouch( &CCaptureZoneShim::Touch );
	}
}


//=============================================================================
//
// Flag Detection Zone tables.
//

BEGIN_DATADESC( CFlagDetectionZone )

	DEFINE_KEYFIELD( m_bDisabled,	FIELD_BOOLEAN,	"StartDisabled" ),
	DEFINE_KEYFIELD( m_bShouldAlarm, FIELD_BOOLEAN,	"alarm" ),

	// Inputs.
	DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
	DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
	DEFINE_INPUTFUNC( FIELD_VOID, "Test", InputTest ),

	// Outputs.
	DEFINE_OUTPUT( m_outputOnStartTouchFlag, "OnStartTouchFlag" ),
	DEFINE_OUTPUT( m_outputOnEndTouchFlag, "OnEndTouchFlag" ),
	DEFINE_OUTPUT( m_outputOnDroppedFlag, "OnDroppedFlag" ),
	DEFINE_OUTPUT( m_outputOnPickedUpFlag, "OnPickedUpFlag" ),

END_DATADESC()

LINK_ENTITY_TO_CLASS( func_flagdetectionzone, CFlagDetectionZone );

IMPLEMENT_AUTO_LIST( IFlagDetectionZoneAutoList );


//=============================================================================
//
// Flag Detection Zone functions.
//

CFlagDetectionZone::CFlagDetectionZone()
{
	m_bShouldAlarm = false;
}

void CFlagDetectionZone::Spawn()
{
	InitTrigger();

	if ( m_bDisabled )
	{
		SetDisabled( true );
	}
}

void CFlagDetectionZone::StartTouch( CBaseEntity *pOther )
{
	// Is the zone enabled?
	if ( IsDisabled() )
		return;

	if ( pOther->IsPlayer() )
	{
		EHANDLE hOther;
		hOther = pOther;

		if ( m_hTouchingPlayers.Find( hOther ) == m_hTouchingPlayers.InvalidIndex() )
		{
			m_hTouchingPlayers.AddToTail( hOther );
		}
	}

	if ( EntityIsFlagCarrier( pOther ) )
	{
		EHANDLE hOther;
		hOther = pOther;

		bool bAdded = false;
		if ( m_hTouchingEntities.Find( hOther ) == m_hTouchingEntities.InvalidIndex() )
		{
			m_hTouchingEntities.AddToTail( hOther );
			bAdded = true;
		}

		m_OnStartTouch.FireOutput( pOther, this );

		if ( bAdded && ( m_hTouchingEntities.Count() == 1 ) )
		{
			// First entity to touch us that passes our filters
			m_outputOnStartTouchFlag.FireOutput( pOther, this );
			m_OnStartTouchAll.FireOutput( pOther, this );
		}

		IGameEvent *event = gameeventmanager->CreateEvent( "flag_carried_in_detection_zone" );
		if ( event )
		{
			gameeventmanager->FireEvent( event );
		}
	}
}

void CFlagDetectionZone::EndTouch( CBaseEntity *pOther )
{
	// Is the zone enabled?
	if ( IsDisabled() )
		return;

	if ( pOther->IsPlayer() )
	{
		EHANDLE hOther;
		hOther = pOther;
		
		m_hTouchingPlayers.FindAndRemove( hOther );
	}

	if ( IsTouching( pOther ) )
	{
		EHANDLE hOther;
		hOther = pOther;

		m_hTouchingEntities.FindAndRemove( hOther );

		m_OnEndTouch.FireOutput(pOther, this);

		// If there are no more entities touching this trigger, fire the lost all touches
		// Loop through the touching entities backwards. Clean out old ones, and look for existing
		bool bFoundOtherTouchee = false;
		int iSize = m_hTouchingEntities.Count();
		for ( int i = iSize-1; i >= 0; i-- )
		{
			EHANDLE hOther;
			hOther = m_hTouchingEntities[i];

			if ( !hOther )
			{
				m_hTouchingEntities.Remove( i );
			}
			else if ( hOther->IsPlayer() && !hOther->IsAlive() )
			{
#ifdef STAGING_ONLY
				AssertMsg( false, "Dead player [%s] is still touching this trigger at [%f %f %f]", hOther->GetEntityName().ToCStr(), XYZ( hOther->GetAbsOrigin() ) );
				Warning( "Dead player [%s] is still touching this trigger at [%f %f %f]", hOther->GetEntityName().ToCStr(), XYZ( hOther->GetAbsOrigin() ) );
#endif
				m_hTouchingEntities.Remove( i );
			}
			else
			{
				bFoundOtherTouchee = true;
			}
		}

		//FIXME: Without this, triggers fire their EndTouch outputs when they are disabled!
		// Didn't find one?
		if ( !bFoundOtherTouchee /*&& !m_bDisabled*/ )
		{
			m_outputOnEndTouchFlag.FireOutput( this, this );
			m_OnEndTouchAll.FireOutput( pOther, this);
		}
	}
}

void CFlagDetectionZone::InputEnable( inputdata_t &inputdata )
{
	SetDisabled( false );
}

void CFlagDetectionZone::InputDisable( inputdata_t &inputdata )
{
	SetDisabled( true );
}

void CFlagDetectionZone::InputTest( inputdata_t &inputdata )
{
	// Loop through the touching entities backwards. Clean out old ones, and look for existing
	int iSize = m_hTouchingEntities.Count();
	for ( int i = iSize-1; i >= 0; i-- )
	{
		EHANDLE hOther;
		hOther = m_hTouchingEntities[i];

		if ( !hOther )
		{
			m_hTouchingEntities.Remove( i );
		}
		else if ( hOther->IsPlayer() && !hOther->IsAlive() )
		{
#ifdef STAGING_ONLY
			AssertMsg( false, "Dead player [%s] is still touching this trigger at [%f %f %f]", hOther->GetEntityName().ToCStr(), XYZ( hOther->GetAbsOrigin() ) );
			Warning( "Dead player [%s] is still touching this trigger at [%f %f %f]", hOther->GetEntityName().ToCStr(), XYZ( hOther->GetAbsOrigin() ) );
#endif
			m_hTouchingEntities.Remove( i );
		}
	}

	if ( m_hTouchingEntities.Count() )
	{
		m_OnStartTouch.FireOutput( m_hTouchingEntities[ 0 ], this );
		m_outputOnStartTouchFlag.FireOutput( this, this );
	}
	else
	{
		m_outputOnEndTouchFlag.FireOutput( this, this );
		m_OnEndTouchAll.FireOutput( this, this );
	}
}

void CFlagDetectionZone::SetDisabled( bool bDisabled )
{
	m_bDisabled = bDisabled;

	if ( bDisabled )
	{
		BaseClass::Disable();
		SetTouch( NULL );
	}
	else
	{
		BaseClass::Enable();
	}
}

void CFlagDetectionZone::FlagDropped( CBasePlayer *pPlayer )
{
	EHANDLE hOther;
	hOther = pPlayer;

	if ( m_hTouchingEntities.Find( hOther ) != m_hTouchingEntities.InvalidIndex() )
	{
		m_outputOnDroppedFlag.FireOutput( pPlayer, this );
		EndTouch( pPlayer );

		// Still touching as a non-carrierz
		m_hTouchingPlayers.AddToTail( hOther );
	}
}

void CFlagDetectionZone::FlagPickedUp( CBasePlayer *pPlayer )
{
	EHANDLE hOther;
	hOther = pPlayer;
	
	if ( m_hTouchingPlayers.Find( hOther ) != m_hTouchingPlayers.InvalidIndex() )
	{
		m_outputOnPickedUpFlag.FireOutput( pPlayer, this );
		StartTouch( pPlayer );
	}
}

bool CFlagDetectionZone::EntityIsFlagCarrier( CBaseEntity *pEntity )
{
	// Get the TF player.
	CTFPlayer *pPlayer = ToTFPlayer( pEntity );
	if ( pPlayer )
	{
		// Check to see if the player has the capture flag.
		if ( pPlayer->HasItem() && ( pPlayer->GetItem()->GetItemID() == TF_ITEM_CAPTURE_FLAG ) )
		{
			CCaptureFlag *pFlag = dynamic_cast<CCaptureFlag*>( pPlayer->GetItem() );
			if ( pFlag && !pFlag->IsCaptured() )
			{
				return true;
			}
		}
	}

	return false;
}

void CFlagDetectionZone::FlagCaptured( CBasePlayer *pPlayer )
{
	if ( !pPlayer )
		return;

	if ( FStrEq( "sd_doomsday", STRING( gpGlobals->mapname ) ) )
	{
		EHANDLE hOther;
		hOther = pPlayer;

		if ( m_hTouchingPlayers.Find( hOther ) != m_hTouchingPlayers.InvalidIndex() )
		{
			int nWinningTeam = pPlayer->GetTeamNumber();
			CUtlVector< EHANDLE > winningPlayers;

			for ( int i = 0 ; i < m_hTouchingPlayers.Count() ; i++ )
			{
				EHANDLE hTemp = m_hTouchingPlayers[i];
				if ( hTemp && ( hTemp->GetTeamNumber() == nWinningTeam ) )
				{
					winningPlayers.AddToHead( hTemp );
				}
			}

			// ACHIEVEMENT_TF_MAPS_DOOMSDAY_RIDE_THE_ELEVATOR
			if ( winningPlayers.Count() >= 5 )
			{
				// loop through and award the achievement
				for ( int i = 0 ; i < winningPlayers.Count() ; i++ )
				{
					EHANDLE hTemp = winningPlayers[i];
					if ( hTemp )
					{
						CTFPlayer *pTFPlayer = ToTFPlayer( hTemp );
						if ( pTFPlayer )
						{
							pTFPlayer->AwardAchievement( ACHIEVEMENT_TF_MAPS_DOOMSDAY_RIDE_THE_ELEVATOR );
						}
					}
				}
			}
 		}
	}
}

//-----------------------------------------------------------------------------
// Purpose: Handles if the specified entity is dropped in a detection zone
//-----------------------------------------------------------------------------
void HandleFlagDroppedInDetectionZone( CBasePlayer *pPlayer )
{
	for ( int i=0; i<IFlagDetectionZoneAutoList::AutoList().Count(); ++i )
	{
		CFlagDetectionZone *pZone = static_cast<CFlagDetectionZone *>( IFlagDetectionZoneAutoList::AutoList()[i] );
		if ( !pZone->IsDisabled() )
		{
			pZone->FlagDropped( pPlayer );
		}
	}
}

//-----------------------------------------------------------------------------
// Purpose: Handles if the specified entity is picked up in a detection zone
//-----------------------------------------------------------------------------
void HandleFlagPickedUpInDetectionZone( CBasePlayer *pPlayer )
{
	for ( int i=0; i<IFlagDetectionZoneAutoList::AutoList().Count(); ++i )
	{
		CFlagDetectionZone *pZone = static_cast<CFlagDetectionZone *>( IFlagDetectionZoneAutoList::AutoList()[i] );
		if ( !pZone->IsDisabled() )
		{
			pZone->FlagPickedUp( pPlayer );
		}
	}
}

//-----------------------------------------------------------------------------
// Purpose: Handles if the specified entity is captured in a detection zone 
//-----------------------------------------------------------------------------
void HandleFlagCapturedInDetectionZone( CBasePlayer *pPlayer )
{
	for ( int i=0; i<IFlagDetectionZoneAutoList::AutoList().Count(); ++i )
	{
		CFlagDetectionZone *pZone = static_cast<CFlagDetectionZone *>( IFlagDetectionZoneAutoList::AutoList()[i] );
		if ( !pZone->IsDisabled() )
		{
			pZone->FlagCaptured( pPlayer );
		}
	}
}