summaryrefslogtreecommitdiff
path: root/game/server/tf2/tf_obj_shieldwall.cpp
blob: 37ccc47d857a8f8983e22be5bea558906730b9bf (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Medic's resupply beacon
//
// $NoKeywords: $
//=============================================================================//

#include "cbase.h"
#include "tf_obj.h"
#include "tf_player.h"
#include "tf_team.h"
#include "techtree.h"
#include "tf_shield.h"
#include "VGuiScreen.h"

//-----------------------------------------------------------------------------
// Shield wall defines
//-----------------------------------------------------------------------------

#define SHIELDWALL_MINS				Vector(-20, -20, 0)
#define SHIELDWALL_MAXS				Vector( 20,  20, 100)

#define SHIELD_WALL_PITCH -10.0f


ConVar	obj_shieldwall_health( "obj_shieldwall_health","200", FCVAR_NONE, "Shield wall health" );


//-----------------------------------------------------------------------------
// Shield wall object that's built by the player
//-----------------------------------------------------------------------------
class CObjectShieldWallBase : public CBaseObject
{
DECLARE_CLASS( CObjectShieldWallBase, CBaseObject );

public:
	CObjectShieldWallBase();

	virtual void	UpdateOnRemove( void );

	virtual void	Spawn();

	virtual void	PowerupStart( int iPowerup, float flAmount, CBaseEntity *pAttacker, CDamageModifier *pDamageModifier );
	virtual	void	PowerupEnd( int iPowerup );

	// Team change
	virtual void	ChangeTeam( int nTeamNumber ) OVERRIDE;

public:
	CNetworkHandle( CShield, m_hDeployedShield );
};

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
CObjectShieldWallBase::CObjectShieldWallBase()
{
	m_hDeployedShield.Set(0);
	AddEFlags( EFL_FORCE_CHECK_TRANSMIT );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CObjectShieldWallBase::UpdateOnRemove( void )
{
	if ( m_hDeployedShield.Get() )
	{
		UTIL_Remove( m_hDeployedShield );
		m_hDeployedShield.Set( NULL );
	}

	// Chain at end to mimic destructor unwind order
	BaseClass::UpdateOnRemove();
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CObjectShieldWallBase::Spawn()
{
	m_takedamage = DAMAGE_YES;

	SetType( OBJ_SHIELDWALL );

	BaseClass::Spawn();
}

//-----------------------------------------------------------------------------
// Purpose: Powerup has just started
//-----------------------------------------------------------------------------
void CObjectShieldWallBase::PowerupStart( int iPowerup, float flAmount, CBaseEntity *pAttacker, CDamageModifier *pDamageModifier )
{
	switch( iPowerup )
	{
	case POWERUP_BOOST:
		// Increase our shield's energy
		if ( m_hDeployedShield )
		{
			m_hDeployedShield->SetPower( m_hDeployedShield->GetPower() + (flAmount * 3) );
		}
		break;

	case POWERUP_EMP:
		if (m_hDeployedShield)
		{
			m_hDeployedShield->SetEMPed(true);
		}
		break;

	default:
		break;
	}

	BaseClass::PowerupStart( iPowerup, flAmount, pAttacker, pDamageModifier );
}

//-----------------------------------------------------------------------------
// Purpose: Powerup has just started
//-----------------------------------------------------------------------------
void CObjectShieldWallBase::PowerupEnd( int iPowerup )
{
	switch ( iPowerup )
	{
	case POWERUP_EMP:
		if (m_hDeployedShield)
		{
			m_hDeployedShield->SetEMPed(false);
		}
		break;

	default:
		break;
	}

	BaseClass::PowerupEnd( iPowerup );
}


//-----------------------------------------------------------------------------
// Team change
//-----------------------------------------------------------------------------
void CObjectShieldWallBase::ChangeTeam( int nTeamNumber )
{
	BaseClass::ChangeTeam( nTeamNumber );
	if ( m_hDeployedShield )
	{
		m_hDeployedShield->ChangeTeam( nTeamNumber );
	}
}


//-----------------------------------------------------------------------------
// Shield wall object that's built by the player
//-----------------------------------------------------------------------------
class CObjectShieldWall : public CObjectShieldWallBase
{
DECLARE_CLASS( CObjectShieldWall, CObjectShieldWallBase );

public:
	DECLARE_SERVERCLASS();

					CObjectShieldWall();

	virtual void	Spawn();
	virtual void	Precache();
	virtual void	GetControlPanelInfo( int nPanelIndex, const char *&pPanelName );
	virtual void	ObjectMoved( );
	virtual void	FinishedBuilding( void );
};

IMPLEMENT_SERVERCLASS_ST(CObjectShieldWall, DT_ObjectShieldWall)
	SendPropEHandle(SENDINFO(m_hDeployedShield)),
END_SEND_TABLE();

LINK_ENTITY_TO_CLASS(obj_shieldwall, CObjectShieldWall);
PRECACHE_REGISTER(obj_shieldwall);

CObjectShieldWall::CObjectShieldWall()
{
	UseClientSideAnimation();
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CObjectShieldWall::Spawn()
{
	SetModel( "models/objects/obj_shieldwall.mdl" );
	SetSolid( SOLID_BBOX );
	UTIL_SetSize(this, SHIELDWALL_MINS, SHIELDWALL_MAXS);
	m_iHealth = obj_shieldwall_health.GetInt();
	m_hDeployedShield = NULL;

	SetType( OBJ_SHIELDWALL );

	BaseClass::Spawn();
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CObjectShieldWall::Precache()
{
	PrecacheModel( "models/objects/obj_shieldwall.mdl" );
	PrecacheVGuiScreen( "screen_obj_shieldwall" );
}


//-----------------------------------------------------------------------------
// Purpose: Gets info about the control panels
//-----------------------------------------------------------------------------
void CObjectShieldWall::GetControlPanelInfo( int nPanelIndex, const char *&pPanelName )
{
	pPanelName = "screen_obj_shieldwall";
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CObjectShieldWall::FinishedBuilding( void )
{
	BaseClass::FinishedBuilding();

	int nAttachmentIndex = LookupAttachment( "projectionpoint" );

	m_hDeployedShield = CreateMobileShield( this );
	m_hDeployedShield->SetAlwaysOrient( false );
	m_hDeployedShield->SetAttachmentIndex( nAttachmentIndex );
	m_hDeployedShield->SetAngularSpringConstant( 20 );
	ObjectMoved();
}


//-----------------------------------------------------------------------------
// Called when the builder rotates this object...
//-----------------------------------------------------------------------------
void CObjectShieldWall::ObjectMoved( )
{
	if (m_hDeployedShield)
	{
		VMatrix matangles;
		VMatrix matoffset;
		VMatrix matfinal;

		// This represents how much to pitch the shield up from the attachment point
		QAngle angleOffset( SHIELD_WALL_PITCH, 0, 0 );

		// Get the location and angles of the attachment point
		// Attachment point position is the origin of the shield
		QAngle angles;

		// Rotate the angles of the attachment point by the angle offset
		MatrixFromAngles( GetAbsAngles(), matangles );
		MatrixFromAngles( angleOffset, matoffset );
		MatrixMultiply( matangles, matoffset, matfinal );
		MatrixToAngles( matfinal, angles );
		m_hDeployedShield->SetCenterAngles( angles );

		m_hDeployedShield->ShieldMoved();
	}
	BaseClass::ObjectMoved();
}