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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: TF Mirv Grenade.
//
//=============================================================================//
#include "cbase.h"
#include "tf_weaponbase.h"
#include "tf_gamerules.h"
#include "npcevent.h"
#include "engine/IEngineSound.h"
#include "tf_weapon_grenade_mirv.h"
// Server specific.
#ifdef GAME_DLL
#include "tf_player.h"
#include "items.h"
#include "tf_weaponbase_grenadeproj.h"
#include "soundent.h"
#include "KeyValues.h"
#endif
#define GRENADE_MIRV_TIMER 3.0f // seconds
#define GRENADE_MIRV_LEADIN 2.0f
//=============================================================================
//
// TF Demoman Mirv Grenade tables.
//
IMPLEMENT_NETWORKCLASS_ALIASED( TFGrenadeMirv_Demoman, DT_TFGrenadeMirv_Demoman )
BEGIN_NETWORK_TABLE( CTFGrenadeMirv_Demoman, DT_TFGrenadeMirv_Demoman )
END_NETWORK_TABLE()
BEGIN_PREDICTION_DATA( CTFGrenadeMirv_Demoman )
END_PREDICTION_DATA()
LINK_ENTITY_TO_CLASS( tf_weapon_grenade_mirv_demoman, CTFGrenadeMirv_Demoman );
PRECACHE_WEAPON_REGISTER( tf_weapon_grenade_mirv_demoman );
//=============================================================================
//
// TF Mirv Grenade tables.
//
IMPLEMENT_NETWORKCLASS_ALIASED( TFGrenadeMirv, DT_TFGrenadeMirv )
BEGIN_NETWORK_TABLE( CTFGrenadeMirv, DT_TFGrenadeMirv )
END_NETWORK_TABLE()
BEGIN_PREDICTION_DATA( CTFGrenadeMirv )
END_PREDICTION_DATA()
LINK_ENTITY_TO_CLASS( tf_weapon_grenade_mirv, CTFGrenadeMirv );
PRECACHE_WEAPON_REGISTER( tf_weapon_grenade_mirv );
//=============================================================================
//
// TF Mirv Grenade functions.
//
// Server specific.
#ifdef GAME_DLL
BEGIN_DATADESC( CTFGrenadeMirv )
END_DATADESC()
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CTFWeaponBaseGrenadeProj *CTFGrenadeMirv::EmitGrenade( Vector vecSrc, QAngle vecAngles, Vector vecVel,
AngularImpulse angImpulse, CBasePlayer *pPlayer, float flTime, int iflags )
{
return CTFGrenadeMirvProjectile::Create( vecSrc, vecAngles, vecVel, angImpulse,
pPlayer, GetTFWpnData(), flTime );
}
#endif
//=============================================================================
//
// TF Mirv Grenade Projectile functions (Server specific).
//
#ifdef GAME_DLL
BEGIN_DATADESC( CTFGrenadeMirvProjectile )
DEFINE_THINKFUNC( DetonateThink ),
END_DATADESC()
#define GRENADE_MODEL "models/weapons/w_models/w_grenade_mirv.mdl"
LINK_ENTITY_TO_CLASS( tf_weapon_grenade_mirv_projectile, CTFGrenadeMirvProjectile );
PRECACHE_WEAPON_REGISTER( tf_weapon_grenade_mirv_projectile );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CTFGrenadeMirvProjectile* CTFGrenadeMirvProjectile::Create( const Vector &position, const QAngle &angles,
const Vector &velocity, const AngularImpulse &angVelocity,
CBaseCombatCharacter *pOwner, const CTFWeaponInfo &weaponInfo, float timer, int iFlags )
{
CTFGrenadeMirvProjectile *pGrenade = static_cast<CTFGrenadeMirvProjectile*>( CTFWeaponBaseGrenadeProj::Create( "tf_weapon_grenade_mirv_projectile", position, angles, velocity, angVelocity, pOwner, weaponInfo, timer, iFlags ) );
return pGrenade;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFGrenadeMirvProjectile::Spawn()
{
SetModel( GRENADE_MODEL );
BaseClass::Spawn();
m_bPlayedLeadIn = false;
SetThink( &CTFGrenadeMirvProjectile::DetonateThink );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFGrenadeMirvProjectile::Precache()
{
PrecacheModel( GRENADE_MODEL );
PrecacheScriptSound( "Weapon_Grenade_Mirv.LeadIn" );
BaseClass::Precache();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFGrenadeMirvProjectile::BounceSound( void )
{
EmitSound( "Weapon_Grenade_Mirv.Bounce" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFGrenadeMirvProjectile::Detonate()
{
if ( ShouldNotDetonate() )
{
RemoveGrenade();
return;
}
BaseClass::Detonate();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFGrenadeMirvProjectile::DetonateThink( void )
{
if ( !m_bPlayedLeadIn && gpGlobals->curtime > GetDetonateTime() - GRENADE_MIRV_LEADIN )
{
Vector soundPosition = GetAbsOrigin() + Vector( 0, 0, 5 );
CPASAttenuationFilter filter( soundPosition );
EmitSound( filter, entindex(), "Weapon_Grenade_Mirv.LeadIn" );
m_bPlayedLeadIn = true;
}
BaseClass::DetonateThink();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFGrenadeMirvProjectile::Explode( trace_t *pTrace, int bitsDamageType )
{
// Pass through.
BaseClass::Explode( pTrace, bitsDamageType );
m_bPlayedLeadIn = false;
// Server specific.
#ifdef GAME_DLL
// Create the bomblets.
for ( int iBomb = 0; iBomb < TF_WEAPON_GRENADE_MIRV_BOMB_COUNT; ++iBomb )
{
Vector vecSrc = pTrace->endpos + Vector( 0, 0, 1.0f );
Vector vecVelocity( random->RandomFloat( -75.0f, 75.0f ) * 3.0f,
random->RandomFloat( -75.0f, 75.0f ) * 3.0f,
random->RandomFloat( 30.0f, 70.0f ) * 5.0f );
Vector vecZero( 0,0,0 );
CTFPlayer *pPlayer = ToTFPlayer( GetThrower() );
float flTime = 2.0f + random->RandomFloat( 0.0f, 1.0f );
CTFGrenadeMirvBomb::Create( vecSrc, GetAbsAngles(), vecVelocity, vecZero, pPlayer, flTime );
}
#endif
}
//=============================================================================
//
// TF Mirv Bomb functions (Server specific).
//
#define GRENADE_MODEL_BOMBLET "models/weapons/w_models/w_grenade_bomblet.mdl"
#define TF_WEAPON_GRENADE_MIRV_BOMB_GRAVITY 0.5f
#define TF_WEAPON_GRENADE_MIRV_BOMB_FRICTION 0.8f
#define TF_WEAPON_GRENADE_MIRV_BOMB_ELASTICITY 0.45f
LINK_ENTITY_TO_CLASS( tf_weapon_grenade_mirv_bomb, CTFGrenadeMirvBomb );
PRECACHE_WEAPON_REGISTER( tf_weapon_grenade_mirv_bomb );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CTFGrenadeMirvBomb *CTFGrenadeMirvBomb::Create( const Vector &position, const QAngle &angles, const Vector &velocity,
const AngularImpulse &angVelocity, CBaseCombatCharacter *pOwner, float timer )
{
CTFGrenadeMirvBomb *pBomb = static_cast<CTFGrenadeMirvBomb*>( CBaseEntity::Create( "tf_weapon_grenade_mirv_bomb", position, angles, pOwner ) );
if ( pBomb )
{
pBomb->SetDetonateTimerLength( timer );
pBomb->SetupInitialTransmittedGrenadeVelocity( velocity );
pBomb->SetThrower( pOwner );
pBomb->SetOwnerEntity( NULL );
pBomb->SetGravity( TF_WEAPON_GRENADE_MIRV_BOMB_GRAVITY );
pBomb->SetFriction( TF_WEAPON_GRENADE_MIRV_BOMB_GRAVITY );
pBomb->SetElasticity( TF_WEAPON_GRENADE_MIRV_BOMB_ELASTICITY );
pBomb->m_flDamage = 180.0f;
pBomb->m_DmgRadius = 198.0f;
pBomb->ChangeTeam( pOwner->GetTeamNumber() );
pBomb->SetCollisionGroup( TF_COLLISIONGROUP_GRENADES );
IPhysicsObject *pPhysicsObject = pBomb->VPhysicsGetObject();
if ( pPhysicsObject )
{
pPhysicsObject->AddVelocity( &velocity, &angVelocity );
}
}
return pBomb;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFGrenadeMirvBomb::Spawn()
{
SetModel( GRENADE_MODEL_BOMBLET );
BaseClass::Spawn();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFGrenadeMirvBomb::Precache()
{
PrecacheModel( GRENADE_MODEL_BOMBLET );
BaseClass::Precache();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFGrenadeMirvBomb::BounceSound( void )
{
EmitSound( "Weapon_Grenade_MirvBomb.Bounce" );
}
#endif
|