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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: The Escort's Shield weapon
//
// $Revision: $
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "weapon_shield.h"
#include "in_buttons.h"
#include <float.h>
#include "mathlib/mathlib.h"
#include "engine/IEngineSound.h"
#if defined( CLIENT_DLL )
#include "c_shield.h"
#else
#include "tf_shield.h"
#endif
//-----------------------------------------------------------------------------
// Shield WEAPON
//-----------------------------------------------------------------------------
LINK_ENTITY_TO_CLASS( weapon_shield, CWeaponShield );
PRECACHE_WEAPON_REGISTER(weapon_shield);
IMPLEMENT_NETWORKCLASS_ALIASED( WeaponShield, DT_WeaponShield )
BEGIN_NETWORK_TABLE(CWeaponShield, DT_WeaponShield)
#ifdef CLIENT_DLL
RecvPropEHandle (RECVINFO(m_hDeployedShield)),
#else
SendPropEHandle (SENDINFO(m_hDeployedShield)),
#endif
END_NETWORK_TABLE()
BEGIN_PREDICTION_DATA( CWeaponShield )
DEFINE_FIELD( m_bIsDeployed, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bShieldPositionLocked, FIELD_BOOLEAN ),
END_PREDICTION_DATA()
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CWeaponShield::CWeaponShield( void )
{
SetPredictionEligible( true );
m_bIsDeployed = false;
}
void CWeaponShield::UpdateOnRemove( void )
{
#ifdef GAME_DLL
if ( m_hDeployedShield.Get() )
{
m_hDeployedShield.Get()->Remove( );
m_hDeployedShield.Set( NULL );
}
#endif
// Chain at end to mimic destructor unwind order
BaseClass::UpdateOnRemove();
}
//-----------------------------------------------------------------------------
// Purpose: Given the distance the hit occurred at, return the damage done
//-----------------------------------------------------------------------------
float CWeaponShield::GetDamage( float flDistance, int iLocation )
{
// Can't injure at all over this distance
return 0.0;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
float CWeaponShield::GetFireRate( void )
{
return 1.0;
}
//-----------------------------------------------------------------------------
// Deploy the shield!
//-----------------------------------------------------------------------------
bool CWeaponShield::Deploy( )
{
if ( !BaseClass::Deploy() )
return false;
// NOTE: the underlying system can cause Deploy to be called twice in a row
if ( m_bIsDeployed )
return true;
// We gotta make the actual shield effect....
CBaseTFPlayer *pPlayer = ToBaseTFPlayer( GetOwner() );
if ( !pPlayer )
return false;
#ifdef GAME_DLL
Assert( !m_hDeployedShield.Get().IsValid() );
m_hDeployedShield = CreateMobileShield( pPlayer );
#endif
SetShieldPositionLocked( false );
m_bIsDeployed = true;
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Remove the shield
//-----------------------------------------------------------------------------
bool CWeaponShield::Holster( CBaseCombatWeapon *pSwitchingTo )
{
#ifdef GAME_DLL
if ( m_hDeployedShield.Get() )
{
m_hDeployedShield.Get()->Remove( );
m_hDeployedShield.Set( NULL );
}
#endif
m_bIsDeployed = false;
return BaseClass::Holster( pSwitchingTo );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponShield::ItemPostFrame( void )
{
CBaseTFPlayer *pPlayer = ToBaseTFPlayer( GetOwner() );
if (pPlayer == NULL)
return;
// Disabled
if ( ComputeEMPFireState() )
{
// Handle deployment & pick-up (firing is handled on the client)
if ( pPlayer->m_nButtons & IN_ATTACK2 )
{
if ( gpGlobals->curtime >= m_flNextPrimaryAttack)
{
PrimaryAttack();
}
}
}
WeaponIdle();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponShield::PrimaryAttack( void )
{
CShield *shield = m_hDeployedShield.Get();
if ( shield )
{
SetShieldPositionLocked( !m_bShieldPositionLocked );
#ifdef GAME_DLL
if ( m_bShieldPositionLocked )
{
ClientPrint( ToBasePlayer(GetOwner()), HUD_PRINTCENTER, "Projected Shield Locked" );
}
else
{
ClientPrint( ToBasePlayer(GetOwner()), HUD_PRINTCENTER, "Projected Shield Tracking" );
}
#endif
}
m_flNextPrimaryAttack = gpGlobals->curtime + 0.25f;
}
//-----------------------------------------------------------------------------
// Lock the projected shield
//-----------------------------------------------------------------------------
void CWeaponShield::SetShieldPositionLocked( bool bLocked )
{
m_bShieldPositionLocked = bLocked;
if ( m_hDeployedShield.Get() )
{
if ( bLocked && m_hDeployedShield.Get()->IsAlwaysOrienting() )
{
CBaseTFPlayer *pPlayer = ToBaseTFPlayer( GetOwner() );
m_hDeployedShield.Get()->SetCenterAngles( pPlayer->EyeAngles() );
}
m_hDeployedShield.Get()->SetAlwaysOrient( !bLocked );
}
}
//-----------------------------------------------------------------------------
// Idle processing
//-----------------------------------------------------------------------------
void CWeaponShield::WeaponIdle( void )
{
bool isEmped = IsOwnerEMPed();
if (m_hDeployedShield.Get())
{
m_hDeployedShield.Get()->SetEMPed( isEmped );
}
}
|