summaryrefslogtreecommitdiff
path: root/game/server/tf2/tf_team.h
blob: 1f90b656d09ef9914986d5dacde43e265430c6ef (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Team management class. Contains all the details for a specific team
//
// $NoKeywords: $
//=============================================================================//

#ifndef TF_TEAM_H
#define TF_TEAM_H

#ifdef _WIN32
#pragma once
#endif


#include "utlvector.h"
#include "tf_shareddefs.h"
#include "techtree.h"
#include "team.h"
#include "order_events.h"

class CBaseTFPlayer;
class CResourceZone;
class CTeamSpawnPoint;
class CBaseTFPlayer;
class CResourceDrop;
class CTechnologyTree;
class CBaseTechnology;
class CObjectResupply;
class CBaseObject;
class COrder;
class CTeamMessage;
class CObjectPowerPack;
class CObjectBuffStation;


enum
{
	COUNTORDERS_TYPE	=	(1<<0),
	COUNTORDERS_TARGET	=	(1<<1),
	COUNTORDERS_OWNER	=	(1<<2)
};


// Maximum total number of objects a team can have.
#define MAX_TEAM_OBJECTS 1024


//-----------------------------------------------------------------------------
// Purpose: Team Manager
//-----------------------------------------------------------------------------
class CTFTeam : public CTeam
{
	DECLARE_CLASS( CTFTeam, CTeam );
public:
	virtual ~CTFTeam( void );

	DECLARE_SERVERCLASS();

	// Initialization
	virtual void Init( const char *pName, int iNumber );
	
	virtual void Precache( void );
	virtual void PrecacheTechnology( CBaseTechnology *pTech );
	virtual void Think( void );

	//-----------------------------------------------------------------------------
	// Data Handling
	//-----------------------------------------------------------------------------
	virtual void UpdateClientData( CBasePlayer *pPlayer );
	virtual void UpdateClientTechnology( int iTechID, CBaseTFPlayer *pPlayer );
	virtual void UpdateTechnologyData( void );
	virtual bool ShouldTransmitToPlayer( CBasePlayer *pRecipient, CBaseEntity* pEntity );
	virtual bool IsEntityVisibleToTactical( CBaseEntity *pEntity );

	//-----------------------------------------------------------------------------
	// Resources
	//-----------------------------------------------------------------------------
	virtual void UpdatePotentialResources( void );

	virtual void AddResourceZone( CResourceZone *pResource );
	virtual void RemoveResourceZone( CResourceZone *pResource );

	// Handling for players joining the team during the game
	float		 GetJoiningPlayerResources( void );
	void		 SetRecentBankSet( float flResources );

	//-----------------------------------------------------------------------------
	// Technology Tree
	//-----------------------------------------------------------------------------
	virtual void InitializeTechTree( void );
	virtual CTechnologyTree *GetTechnologyTree( void );
	virtual void EnableTechnology( CBaseTechnology *technology, bool bStolen = false );		// Give this team a technology
	virtual void EnableAllTechnologies( void );
	virtual void RecomputeTeamResources( void );
	virtual void RecomputePreferences( void );
	virtual void RecomputePurchases( void );
	virtual bool HasNamedTechnology( const char *name );
	virtual void GainedNewTechnology( CBaseTechnology *pTechnology );
	virtual void UpdateTechnologies( void );
	
	//-----------------------------------------------------------------------------
	// Players
	//-----------------------------------------------------------------------------
	virtual void AddPlayer( CBasePlayer *pPlayer );
	virtual void RemovePlayer( CBasePlayer *pPlayer );
	int		GetNumOfClass( TFClass iClass );

	//-----------------------------------------------------------------------------
	// Resource Bank
	//-----------------------------------------------------------------------------
	void	InitializeTeamResources( void );
	float	GetTeamResources( void );
	int		AddTeamResources( float fAmount, int nStat = -1 );
	void	ResourceLoadDeposited( void );
	void	DonateResources( CBaseTFPlayer *pPlayer );

	//-----------------------------------------------------------------------------
	// Objects
	//-----------------------------------------------------------------------------
	void	AddObject( CBaseObject *pObject );
	void	RemoveObject( CBaseObject *pObject );
	bool	IsObjectOnTeam( CBaseObject *pObject ) const;
	void	AddResupply( CObjectResupply *pResupply );
	void	RemoveResupply( CObjectResupply *pResupply );
	int		GetNumObjects( int iObjectType = -1 );
	CBaseObject		*GetObject( int num );
	int		GetNumResupplies( void );
	CObjectResupply *GetResupply( int num );

	// Returns true if the position is covered by a sentry gun.
	bool	IsCoveredBySentryGun( const Vector &vPos );

	int		GetNumShieldWallsCoveringPosition( const Vector &vPos );
	int		GetNumResuppliesCoveringPosition( const Vector &vPos );
	int		GetNumRespawnStationsCoveringPosition( const Vector &vPos );


	//-----------------------------------------------------------------------------
	// Orders
	//-----------------------------------------------------------------------------
	void	InitializeOrders( void );
	
	COrder*	AddOrder( 
		int iOrderType, 
		CBaseEntity *pTarget, 
		CBaseTFPlayer *pPlayer = NULL, 
		float flDistanceToRemove = 1e24, 
		float flLifetime = 60,
		COrder *pDefaultOrder = NULL	// If this is specified, then it is used instead of 
										// asking COrder to allocate an order.
		);
	void	RemoveOrder( COrder *pOrder );
	void	RecalcOrders( void );
	void	UpdateOrders( void );
	void	UpdateOrdersOnEvent( COrderEvent_Base *pEvent );
	
	// Flags is a combination of COUNTORDERS_ flags telling which fields to check.
	int		CountOrders( int flags, int iOrderType, CBaseEntity *pTarget=0, CBaseTFPlayer *pOwner=0 );
	int		CountOrdersOwnedByPlayer( CBaseTFPlayer *pPlayer );

	void	CreatePersonalOrders( void );
	void	CreatePersonalOrder( CBaseTFPlayer *pPlayer );
	void	RemoveOrdersToPlayer( CBaseTFPlayer *pPlayer );

	//-----------------------------------------------------------------------------
	// Messages
	//-----------------------------------------------------------------------------
	void	ClearMessages( void );
	void	PostMessage( int iMessageID, CBaseEntity *pEntity = NULL, char *sData = NULL );
	void	UpdateMessages( void );

	void	UpdatePowerpacks( CObjectPowerPack *pPackToIgnore, CBaseObject *pObjectToTarget );
	void	UpdateBuffStations( CObjectBuffStation *pBuffStationToIgnore, CBaseObject *pObjectToTarget, bool bPlacing );

	//-----------------------------------------------------------------------------
	// Utility funcs
	//-----------------------------------------------------------------------------
	CTFTeam*		GetEnemyTeam();

	// Technology Tree
	CTechnologyTree *m_pTechnologyTree;

	// TEST CODE
	// Remove after Resource Experiment!
	float	m_flTotalResourcesSoFar;

private:
	typedef CHandle<COrder>	OrderHandle;

	// Resource UI data
	CNetworkVar( bool, m_bHaveZone );

	// Resources
	CNetworkVar( float, m_fResources );									// Current amounts of resource
	CNetworkVar( float, m_fPotentialResources );							// Amounts of resource when all collectors have returned
	float	m_flLastBankSetAmount;							// Most recent amount of resources our players had their banks set to
	float	m_flLastBankSetTime;							// Time at which our players last had their banks set

	// Orders
	float	m_flPersonalOrderUpdateTime;

	// Used to distribute resources to a team
	float	m_flNextResourceTime;

	int		m_iLastUpdateSentAt;

	CUtlVector< CResourceZone * >		m_aResourcesBeingCollected;
	CUtlVector< CObjectResupply * >		m_aResupplyBeacons;
	CUtlVector< OrderHandle >			m_aOrders;				// Stored in order of priority
	CUtlVector< CTeamMessage* >			m_aMessages;
	CUtlVector< CBaseObject* >			m_aObjects;
};


extern CTFTeam *GetGlobalTFTeam( int iIndex );


#endif // TF_TEAM_H