summaryrefslogtreecommitdiff
path: root/game/server/tf/bot/map_entities/tf_bot_hint.cpp
blob: b4dfa115ec8af3f17dc2a11678215f5457d32e0e (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
//========= Copyright Valve Corporation, All rights reserved. ============//
// tf_bot_hint.cpp
// Designer-placed hint for TFBots

#include "cbase.h"
#include "bot/tf_bot.h"
#include "tf_bot_hint.h"

BEGIN_DATADESC( CTFBotHint )
	DEFINE_KEYFIELD( m_team, FIELD_INTEGER, "team" ),
	DEFINE_KEYFIELD( m_hint, FIELD_INTEGER, "hint" ),
	DEFINE_KEYFIELD( m_isDisabled, FIELD_BOOLEAN, "StartDisabled" ),
	DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
	DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
END_DATADESC()

LINK_ENTITY_TO_CLASS( func_tfbot_hint, CTFBotHint );

//
// NOTE: For simplicity and runtime efficiency, this will not 
// play nice with nav area hints stored in the mesh,
// nor will overlapping hints of the same type work well.
//

//------------------------------------------------------------------------------
CTFBotHint::CTFBotHint( void )
{
	m_isDisabled = false;
}


//--------------------------------------------------------------------------------------------------------
// Return true if this hint applies to the given entity
bool CTFBotHint::IsFor( CTFBot *who ) const
{
	if ( m_isDisabled )
	{
		return false;
	}

	if ( m_team > 0 && who->GetTeamNumber() != m_team )
	{
		return false;		
	}

	return true;
}


//--------------------------------------------------------------------------------------------------------
void CTFBotHint::Spawn( void )
{
	BaseClass::Spawn();

	SetSolid( SOLID_BSP );	
	AddSolidFlags( FSOLID_NOT_SOLID );

	SetMoveType( MOVETYPE_NONE );
	SetModel( STRING( GetModelName() ) );
	AddEffects( EF_NODRAW );
	SetCollisionGroup( COLLISION_GROUP_NONE );

	VPhysicsInitShadow( false, false );

	UpdateNavDecoration();
}


//--------------------------------------------------------------------------------------------------------
void CTFBotHint::UpdateOnRemove( void )
{
	BaseClass::UpdateOnRemove();

	UpdateNavDecoration();
}


//--------------------------------------------------------------------------------------------------------
void CTFBotHint::InputEnable( inputdata_t &inputdata )
{
	m_isDisabled = false;
	UpdateNavDecoration();
}


//--------------------------------------------------------------------------------------------------------
void CTFBotHint::InputDisable( inputdata_t &inputdata )
{
	m_isDisabled = true;
	UpdateNavDecoration();
}


//--------------------------------------------------------------------------------------------------------
void CTFBotHint::UpdateNavDecoration( void )
{
	Extent extent;
	extent.Init( this );

	CUtlVector< CTFNavArea * > overlapVector;
	TheNavMesh->CollectAreasOverlappingExtent( extent, &overlapVector );

	int attributeBits = 0;
	switch( m_hint )
	{
	case HINT_SNIPER_SPOT:
		attributeBits = TF_NAV_SNIPER_SPOT;
		break;

	case HINT_SENTRY_SPOT:
		attributeBits = TF_NAV_SENTRY_SPOT;
		break;
	}

	for( int j=0; j<overlapVector.Count(); ++j )
	{
		if ( m_isDisabled )
		{
			overlapVector[j]->ClearAttributeTF( attributeBits );
		}
		else
		{
			overlapVector[j]->SetAttributeTF( attributeBits );
		}
	}
}