aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/server/hl2/ai_goal_police.cpp
blob: a5177ae1fd602264828777a013077693a4e545f0 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#include "cbase.h"
#include "ai_goal_police.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

// ai_goal_police

// Used by police to define a region they should keep a target outside of

LINK_ENTITY_TO_CLASS( ai_goal_police, CAI_PoliceGoal );

BEGIN_DATADESC( CAI_PoliceGoal )

	DEFINE_KEYFIELD( m_flRadius,	FIELD_FLOAT,	"PoliceRadius" ),
	DEFINE_KEYFIELD( m_iszTarget,	FIELD_STRING,	"PoliceTarget" ),
	
	DEFINE_FIELD( m_bOverrideKnockOut, FIELD_BOOLEAN ),
	// m_hTarget

	DEFINE_INPUTFUNC( FIELD_VOID, "EnableKnockOut", InputEnableKnockOut ),
	DEFINE_INPUTFUNC( FIELD_VOID, "DisableKnockOut", InputDisableKnockOut ),

	DEFINE_OUTPUT( m_OnKnockOut,		"OnKnockOut" ),
	DEFINE_OUTPUT( m_OnFirstWarning,	"OnFirstWarning" ),
	DEFINE_OUTPUT( m_OnSecondWarning,	"OnSecondWarning" ),
	DEFINE_OUTPUT( m_OnLastWarning,		"OnLastWarning" ),
	DEFINE_OUTPUT( m_OnSupressingTarget,"OnSupressingTarget" ),

END_DATADESC()

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
CAI_PoliceGoal::CAI_PoliceGoal( void )
{
	m_hTarget = NULL;
	m_bOverrideKnockOut = false;
}

//-----------------------------------------------------------------------------
// Purpose: 
// Output : float
//-----------------------------------------------------------------------------
float CAI_PoliceGoal::GetRadius( void )
{
	return m_flRadius;
}

//-----------------------------------------------------------------------------
// Purpose: 
// Output : CBaseEntity
//-----------------------------------------------------------------------------
CBaseEntity *CAI_PoliceGoal::GetTarget( void )
{
	if ( m_hTarget == NULL )
	{
		CBaseEntity *pTarget = gEntList.FindEntityByName( NULL, m_iszTarget );

		if ( pTarget == NULL )
		{
			DevMsg( "Unable to find ai_goal_police target: %s\n", STRING(m_iszTarget) );
			return NULL;
		}

		m_hTarget = pTarget;
	}

	return m_hTarget;
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : &targetPos - 
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CAI_PoliceGoal::ShouldKnockOutTarget( const Vector &targetPos, bool bTargetVisible )
{
	if ( m_bOverrideKnockOut )
		return true;

	// Must be flagged to do it
	if ( HasSpawnFlags( SF_POLICE_GOAL_KNOCKOUT_BEHIND ) == false )
		return false;

	// If the target's not visible, we don't care about him
	if ( !bTargetVisible )
		return false;

	Vector targetDir = targetPos - GetAbsOrigin();
	VectorNormalize( targetDir );

	Vector	facingDir;
	AngleVectors( GetAbsAngles(), &facingDir );

	// See if it's behind us
	if ( DotProduct( facingDir, targetDir ) < 0 )
		return true;

	return false;
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *pTarget - 
//-----------------------------------------------------------------------------
void CAI_PoliceGoal::KnockOutTarget( CBaseEntity *pTarget )
{
	m_OnKnockOut.FireOutput( pTarget, this );
}

//-----------------------------------------------------------------------------
// Purpose: 
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CAI_PoliceGoal::ShouldRemainAtPost( void )
{
	return HasSpawnFlags( SF_POLICE_GOAL_DO_NOT_LEAVE_POST );
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : level - 
//-----------------------------------------------------------------------------
void CAI_PoliceGoal::FireWarningLevelOutput( int level )
{
	switch( level )
	{
	case 1:
		m_OnFirstWarning.FireOutput( this, this );
		break;

	case 2:
		m_OnSecondWarning.FireOutput( this, this );
		break;

	case 3:
		m_OnLastWarning.FireOutput( this, this );
		break;

	default:
		m_OnSupressingTarget.FireOutput( this, this );
		break;
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : &data - 
//-----------------------------------------------------------------------------
void CAI_PoliceGoal::InputEnableKnockOut( inputdata_t &data )
{
	m_bOverrideKnockOut = true;
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : &data - 
//-----------------------------------------------------------------------------
void CAI_PoliceGoal::InputDisableKnockOut( inputdata_t &data )
{
	m_bOverrideKnockOut = false;
}