summaryrefslogtreecommitdiff
path: root/game/server/tf/entity_training_annotations.cpp
blob: f349ca204461d05acd2b2cb22bc53f8e7a430b76 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: CTrainingAnnotation Entity.  This entity is used to place
//          annotations on maps.
//=============================================================================//

#include "cbase.h"
#include "entity_training_annotations.h"

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

//-----------------------------------------------------------------------------
// Purpose: Show an anotation in 3D space in the hud to point out things of
//			interest to the player.
//-----------------------------------------------------------------------------
BEGIN_DATADESC( CTrainingAnnotation )
	DEFINE_KEYFIELD( m_displayText, FIELD_STRING, "display_text" ),
	DEFINE_KEYFIELD( m_flLifetime,  FIELD_FLOAT, "lifetime" ),
	DEFINE_KEYFIELD( m_flVerticalOffset,  FIELD_FLOAT, "offset" ),
	DEFINE_INPUTFUNC( FIELD_VOID, "Show", InputShow ),
	DEFINE_INPUTFUNC( FIELD_VOID, "Hide", InputHide ),
END_DATADESC()

LINK_ENTITY_TO_CLASS( training_annotation, CTrainingAnnotation );

CTrainingAnnotation::CTrainingAnnotation()
	: m_flLifetime(1.0f),
	  m_flVerticalOffset(0.0f)
{

}

void CTrainingAnnotation::Show()
{
	IGameEvent *pEvent = gameeventmanager->CreateEvent( "show_annotation" );
	if ( pEvent )
	{
		Vector location = GetAbsOrigin();

		pEvent->SetString( "text", STRING( m_displayText ) );
		pEvent->SetInt( "id", (long)this );
		pEvent->SetFloat( "worldPosX", location.x );
		pEvent->SetFloat( "worldPosY", location.y );
		pEvent->SetFloat( "worldPosZ", location.z + m_flVerticalOffset );
		pEvent->SetFloat( "lifetime", m_flLifetime );
		pEvent->SetInt( "follow_entindex", 0 );

		gameeventmanager->FireEvent( pEvent );
	}
}

void CTrainingAnnotation::Hide()
{
	IGameEvent *pEvent = gameeventmanager->CreateEvent( "hide_annotation" );
	if ( pEvent )
	{
		pEvent->SetInt( "id", (long)this );
		gameeventmanager->FireEventClientSide( pEvent );
	}
}