summaryrefslogtreecommitdiff
path: root/game/shared/dod/dod_player_shared.h
blob: 9d982d384a9f5d0b608a9bb2765632e7a749b32e (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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#ifndef DOD_PLAYER_SHARED_H
#define DOD_PLAYER_SHARED_H
#ifdef _WIN32
#pragma once
#endif


#include "networkvar.h"
#include "weapon_dodbase.h"


#ifdef CLIENT_DLL
	class C_DODPlayer;
#else
	class CDODPlayer;
#endif

// Entity Messages
#define DOD_PLAYER_POP_HELMET		1
#define DOD_PLAYER_REMOVE_DECALS	2

class CViewOffsetAnimation
{
public:
	CViewOffsetAnimation( CBasePlayer *pPlayer )
	{
		m_pPlayer = pPlayer;
		m_vecStart = vec3_origin;
		m_vecDest = vec3_origin;
		m_flLength = 0.0;
		m_flEndTime = 0.0;
		m_eViewAnimType = VIEW_ANIM_LINEAR_Z_ONLY;
		m_bActive = false;
	}

	static CViewOffsetAnimation *CreateViewOffsetAnim( CBasePlayer *pPlayer )
	{
		CViewOffsetAnimation *p = new CViewOffsetAnimation( pPlayer );

		Assert( p );

		return p;
	}

	void StartAnimation( Vector vecStart, Vector vecDest, float flTime, ViewAnimationType type )
	{
		m_vecStart = vecStart;
		m_vecDest = vecDest;
		m_flLength = flTime;
		m_flEndTime = gpGlobals->curtime + flTime;
		m_eViewAnimType = type;
		m_bActive = true;
	}

	void Reset( void ) 
	{
		m_bActive = false;
	}

	void Think( void )
	{
		if ( !m_bActive )
			return;

		if ( IsFinished() )
		{
			m_bActive = false;
			return;
		}

		float flFraction = ( m_flEndTime - gpGlobals->curtime ) / m_flLength;

		Assert( m_pPlayer );

		if ( m_pPlayer )
		{
			Vector vecCurrentView = m_pPlayer->GetViewOffset();

			switch ( m_eViewAnimType )
			{
			case VIEW_ANIM_LINEAR_Z_ONLY:
				vecCurrentView.z = flFraction * m_vecStart.z + ( 1.0 - flFraction ) * m_vecDest.z;
				break;

			case VIEW_ANIM_SPLINE_Z_ONLY:
				vecCurrentView.z = SimpleSplineRemapVal( flFraction, 1.0, 0.0, m_vecStart.z, m_vecDest.z );
				break;

			case VIEW_ANIM_EXPONENTIAL_Z_ONLY:
				{
					float flBias = Bias( flFraction, 0.2 );
					vecCurrentView.z = flBias * m_vecStart.z + ( 1.0 - flBias ) * m_vecDest.z;
				}
				break;
			}

			m_pPlayer->SetViewOffset( vecCurrentView );
		}		
	}

	bool IsFinished( void )
	{
		return ( gpGlobals->curtime > m_flEndTime || m_pPlayer == NULL );
	}

private:
	CBasePlayer *m_pPlayer;
	Vector		m_vecStart;
	Vector		m_vecDest;
	float		m_flEndTime;
	float		m_flLength;
	ViewAnimationType m_eViewAnimType;
	bool		m_bActive;
};


// Data in the DoD player that is accessed by shared code.
// This data isn't necessarily transmitted between client and server.
class CDODPlayerShared
{
public:

#ifdef CLIENT_DLL
	friend class C_DODPlayer;
	typedef C_DODPlayer OuterClass;
	DECLARE_PREDICTABLE();
#else
	friend class CDODPlayer;
	typedef CDODPlayer OuterClass;
#endif
	
	DECLARE_EMBEDDED_NETWORKVAR()
	DECLARE_CLASS_NOBASE( CDODPlayerShared );


	CDODPlayerShared();
	~CDODPlayerShared();

	void	SetStamina( float stamina );
	float	GetStamina( void ) { return m_flStamina; }
	
	void	Init( OuterClass *pOuter );

	bool	IsProne() const;
	bool	IsGettingUpFromProne() const;	
	bool	IsGoingProne() const;
	void	SetProne( bool bProne, bool bNoAnimation = false );

	bool	IsBazookaDeployed( void ) const;
	bool	IsBazookaOnlyDeployed( void ) const;
	bool	IsSniperZoomed( void ) const;
	bool	IsInMGDeploy( void ) const;
	bool	IsProneDeployed( void ) const;
	bool	IsSandbagDeployed( void ) const;
	bool	IsDucking( void ) const; 
	
	void	SetDesiredPlayerClass( int playerclass );
	int		DesiredPlayerClass( void );

	void	SetPlayerClass( int playerclass );
	int		PlayerClass( void );

	CWeaponDODBase* GetActiveDODWeapon() const;

	void	SetDeployed( bool bDeployed, float flHeight = -1 );

	QAngle	GetDeployedAngles( void ) const;
	float	GetDeployedHeight( void ) const;

	void	SetDeployedYawLimits( float flLeftYaw, float flRightYaw );
	void	ClampDeployedAngles( QAngle *vecTestAngles );

	void	SetSlowedTime( float t );
	float	GetSlowedTime( void ) const;

	void	StartGoingProne( void );
	void	StandUpFromProne( void );

	bool	CanChangePosition( void );

	bool	IsJumping( void ) { return m_bJumping; }
	void	SetJumping( bool bJumping );

	bool	IsSprinting( void ) { return m_bIsSprinting; }

	void	ForceUnzoom( void );

	void	SetSprinting( bool bSprinting );
	void	StartSprinting( void );
	void	StopSprinting( void );

	void	SetCPIndex( int index );
	int		GetCPIndex( void ) { return m_iCPIndex; }

	void SetLastViewAnimTime( float flTime );
	float GetLastViewAnimTime( void );

	void ViewAnimThink( void );

	void ResetViewOffsetAnimation( void );
	void ViewOffsetAnimation( Vector vecDest, float flTime, ViewAnimationType type );

	void ResetSprintPenalty( void );

	void SetPlanting( bool bPlanting )
	{
		m_bPlanting = bPlanting;
	}

	bool IsPlanting( void ) { return m_bPlanting; } 

	void SetDefusing( bool bDefusing )
	{
		m_bDefusing = bDefusing;
	}

	bool IsDefusing( void ) { return m_bDefusing; }

	void ComputeWorldSpaceSurroundingBox( Vector *pVecWorldMins, Vector *pVecWorldMaxs );

	void	SetPlayerDominated( CDODPlayer *pPlayer, bool bDominated );
	bool	IsPlayerDominated( int iPlayerIndex );
	bool	IsPlayerDominatingMe( int iPlayerIndex );
	void	SetPlayerDominatingMe( CDODPlayer *pPlayer, bool bDominated );

private:

	CNetworkVar( bool, m_bProne );

	CNetworkVar( int, m_iPlayerClass );
	CNetworkVar( int, m_iDesiredPlayerClass );

	CNetworkVar( float, m_flStamina );

	CNetworkVar( float, m_flSlowedUntilTime );

	CNetworkVar( bool, m_bIsSprinting );

	CNetworkVar( float, m_flDeployedYawLimitLeft );
	CNetworkVar( float, m_flDeployedYawLimitRight );

	CNetworkVar( bool, m_bPlanting );
	CNetworkVar( bool, m_bDefusing );

	bool m_bGaveSprintPenalty;

public:
	float m_flNextProneCheck; // Prevent it switching their prone state constantly.

	QAngle m_vecDeployedAngles;
	//float m_flDeployedHeight;
	CNetworkVar( float, m_flDeployedHeight );

	CNetworkVar( float, m_flUnProneTime );
	CNetworkVar( float, m_flGoProneTime );

	CNetworkVar( float, m_flDeployChangeTime );
	
	CNetworkVar( bool, m_bForceProneChange );

	CNetworkVar( int, m_iCPIndex );

	bool m_bJumping;

	float m_flLastViewAnimationTime;

	CViewOffsetAnimation *m_pViewOffsetAnim;

	CNetworkArray( bool, m_bPlayerDominated, MAX_PLAYERS+1 );		// array of state per other player whether player is dominating other players
	CNetworkArray( bool, m_bPlayerDominatingMe, MAX_PLAYERS+1 );	// array of state per other player whether other players are dominating this player

private:
	
	OuterClass *m_pOuter;
};			   



#endif // DOD_PLAYER_SHARED_H