summaryrefslogtreecommitdiff
path: root/game/server/tf2/tf_shield.h
blob: 14bc7fc2896dfad0deff44f9298a2f5e12bd4b62 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#ifndef TF_SHIELD_H
#define TF_SHIELD_H

#ifdef _WIN32
#pragma once
#endif

#include "baseentity.h"
#include "utlvector.h"


//-----------------------------------------------------------------------------
// forward declarations
//-----------------------------------------------------------------------------
class Vector;
class CGameTrace;
typedef CGameTrace trace_t;
struct edict_t;


//-----------------------------------------------------------------------------
// Base class for shield entities
//-----------------------------------------------------------------------------
class CShield : public CBaseEntity
{
public:
	DECLARE_CLASS( CShield, CBaseEntity );
	DECLARE_SERVERCLASS();

	CShield();
	~CShield();

public:
	void Precache();
	void Spawn( void );

	virtual void Think( void );

	// Sets the desired center direction
	virtual void SetCenterAngles( const QAngle &angles ) {}
	virtual void SetAlwaysOrient( bool bOrient ) {}
	virtual bool IsAlwaysOrienting( ) { return false; }

	// Used by the mobile shield.
		
		// Change the angular spring constant. This affects how fast the shield rotates to face the angles
		// given in SetAngles. Higher numbers are more responsive, but if you go too high (around 40), it will
		// jump past the specified angles and wiggle a little bit.
		virtual void SetAngularSpringConstant( float flConstant ) {}

		// Move the shield out a certain amount.
		virtual void SetFrontDistance( float flDistance ) {}

	// Called when we hit something that we deflect...
	void RegisterDeflection(const Vector& vecDir, int bitsDamageType, trace_t *ptr);

	// Called when we hit something that we let through...
	void RegisterPassThru(const Vector& vecDir, int bitsDamageType, trace_t *ptr);

	// Activates/deactivates a shield for collision purposes
	void ActivateCollisions( bool activate );

	// Does this shield protect from a particular damage type?
	float ProtectionAmount( int weaponType ) const;

	// Deactivates all shields of players on a particular team
	// If you don't specify a team, it'll affect all shields
	static void ActivateShields( bool activate, int team = -1 );

	// For collision testing
	bool TestCollision( const Ray_t& ray, unsigned int mask, trace_t& trace );

	// Called when the shield has moved
	virtual void ShieldMoved() {}

	// Called when the shield is EMPed (or de-EMPed)
	virtual void SetEMPed( bool isEmped );

	// Indicates the visual center of the shape, may not be the actual center
	// (best example is the dome: it projects from a point which is not
	// at the center of the hemisphere).
	virtual void SetGeometryOffset( const Vector& vector ) {};

	// Shield power & recharging
	void	SetupRecharge( float flPower, float flDelay, float flAmount, float flTickTime );
	float	GetPower( void ) { return m_flPower; }
	void	SetPower( float flPower );
	// Make the shield recharge it's health
	void	ShieldRechargeThink( void );

	// Is this ray blocked by any shields?
	static bool IsBlockedByShields( const Vector& src, const Vector& end );

	virtual void SetOwnerEntity( CBaseEntity *pOwner );
	
	virtual void SetThetaPhi( float flTheta, float flPhi ) { }
	virtual void SetAttachmentIndex( int nAttachmentIndex ) {}

protected:
	//
	// derived classes must implement these
	//
	virtual int Width() { return 0; }
	virtual int Height() { return 0; }
	virtual bool IsPanelActive( int x, int y ) { return true; }
	virtual const Vector& GetPoint( int x, int y ) { return vec3_origin; }
	bool IsEMPed() const { return m_bIsEMPed; }

	float			m_flPower;
	float			m_flMaxPower;
	CNetworkVar( float, m_flPowerLevel );		// m_flPower mapped to 0->1 range for networking
	float			m_flRechargeDelay;
	float			m_flRechargeAmount;
	float			m_flRechargeTime;
	float			m_flNextRechargeTime;

private:
	int				m_iBuckshotHitsThisFrame;
	float			m_flLastProbeTime;
	CNetworkVar( bool, m_bIsEMPed );
	CNetworkVar( int, m_nOwningPlayerIndex );

	// List of all active shields
	static CUtlVector< CShield* >	s_Shields;
};


//-----------------------------------------------------------------------------
// Class factory methods to create the various versions of the shield
//-----------------------------------------------------------------------------
CShield* CreateMobileShield( CBaseEntity *owner, float flFrontDistance = 0 );


//-----------------------------------------------------------------------------
// Returns true if the entity is a shield
//-----------------------------------------------------------------------------
bool IsShield( CBaseEntity *pEnt );

#endif // TF_SHIELD_H