summaryrefslogtreecommitdiff
path: root/game/client/tf2/hud_technologytreedoc.cpp
blob: 5ec1859397f0f6d64467df59859697d87c717e65 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "hud_technologytreedoc.h"
#include "hud.h"
#include "hud_macros.h"
#include "techtree.h"
#include "iclientmode.h"
#include "hud_commander_statuspanel.h"
#include "clientmode_commander.h"
#include "commanderoverlaypanel.h"
#include "tf_hints.h"
#include "c_tf_hintmanager.h"

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

static CTechnologyTreeDoc s_TechnologyTreeDoc;

// Hook network messages
DECLARE_MESSAGE( s_TechnologyTreeDoc, Technology )

// Create object singleton on stack
CTechnologyTreeDoc& GetTechnologyTreeDoc()
{
	return s_TechnologyTreeDoc;
}


//-----------------------------------------------------------------------------
// Purpose: Construction
//-----------------------------------------------------------------------------
CTechnologyTreeDoc::CTechnologyTreeDoc( void )
{
	m_pTree = NULL;
}

//-----------------------------------------------------------------------------
// Purpose: Destruction
//-----------------------------------------------------------------------------
CTechnologyTreeDoc::~CTechnologyTreeDoc( void )
{
	delete m_pTree;
}

//-----------------------------------------------------------------------------
// Purpose: Initialize the panel
//-----------------------------------------------------------------------------
void CTechnologyTreeDoc::Init( void )
{
	ReloadTechTree();
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTechnologyTreeDoc::LevelInit( void )
{
	if ( m_pTree )
	{
		m_pTree->SetPreferredTechnology( NULL );
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTechnologyTreeDoc::LevelShutdown( void )
{
	if ( m_pTree )
	{
		m_pTree->SetPreferredTechnology( NULL );
	}
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTechnologyTreeDoc::ReloadTechTree( void )
{
	// FIXME, CTechnologyTreeDoc should be an entity /MO
	HOOK_HUD_MESSAGE( s_TechnologyTreeDoc, Technology );

	// Reconstruct the tech tree
	delete m_pTree;

	// FIXME: If we reactivate this, we'll need to revisit team number here...
	m_pTree = new CTechnologyTree( ::filesystem, 0);
	Assert( m_pTree );

	m_pTree->SetPreferredTechnology( NULL );
}


//-----------------------------------------------------------------------------
// Purpose: Receive hud update message from server
// Input  : *pszName - 
//			iSize - 
//			*pbuf - 
// Output : int
//-----------------------------------------------------------------------------
int CTechnologyTreeDoc::MsgFunc_Technology(bf_read &msg)
{
	int index;
	int available;
	int voters;
	float resourcelevel;
	bool preferred;

	// Which tech
	index		= msg.ReadByte();
	// Available to this team?
	available	= msg.ReadByte();
	// # of players indicating this as their preferred tech for new spending
	voters		= msg.ReadByte();

	preferred = ( voters & 0x80 ) ? true : false;
	voters &= 0x7f;

	resourcelevel = (float)msg.ReadShort();
	
	// Look it up by index
	CBaseTechnology *item = m_pTree->GetTechnology( index );
	if ( item )
	{	
		bool wasactive = item->GetActive();

		bool justactivated = !wasactive && available;

		// Set data elements
		item->SetActive( available ? true : false );
		item->SetVoters( voters );
		item->SetResourceLevel( resourcelevel );

		// If this is the tech I am voting for, clear my vote
		if ( preferred )
		{
			// Sets the flag on the item, too
			m_pTree->SetPreferredTechnology( item );
		}
		else
		{
			// Force deselection in case there is no active preference on the server any more
			item->SetPreferred( false );
		}

		if ( justactivated && item->GetLevel() > 0 && !item->GetHintsGiven( TF_HINT_NEWTECHNOLOGY ) )
		{
			// So we only give this hint once this game, even if we respawn, etc.
			item->SetHintsGiven( TF_HINT_NEWTECHNOLOGY, true );
			// Note, only show a max of three or 4 newtechnology hints at a time
			CreateGlobalHint( TF_HINT_NEWTECHNOLOGY, item->GetPrintName(), index, 3 );
		}
	}
	
	return 1;
}

//-----------------------------------------------------------------------------
// Purpose: Add a file of technologies to the technology tree
//-----------------------------------------------------------------------------
void CTechnologyTreeDoc::AddTechnologyFile( char *sFilename )
{
	// Add the technologies to the tech list
	if ( m_pTree )
	{
		// FIXME: If we reactivate this, we'll need to revisit team number here...
		m_pTree->AddTechnologyFile( ::filesystem, 0, sFilename );
	}
}