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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Flaming bottle thrown from the hand
//
// $Workfile: $
// $Date: $
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "player.h"
#include "ammodef.h"
#include "gamerules.h"
#include "grenade_molotov.h"
#include "weapon_brickbat.h"
#include "soundent.h"
#include "decals.h"
#include "fire.h"
#include "shake.h"
#include "ndebugoverlay.h"
#include "vstdlib/random.h"
#include "engine/IEngineSound.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
extern short g_sModelIndexFireball;
extern ConVar sk_plr_dmg_molotov;
extern ConVar sk_npc_dmg_molotov;
ConVar sk_molotov_radius ( "sk_molotov_radius","0");
#define MOLOTOV_EXPLOSION_VOLUME 1024
BEGIN_DATADESC( CGrenade_Molotov )
DEFINE_FIELD( m_pFireTrail, FIELD_CLASSPTR ),
// Function Pointers
DEFINE_FUNCTION( MolotovTouch ),
DEFINE_FUNCTION( MolotovThink ),
END_DATADESC()
LINK_ENTITY_TO_CLASS( grenade_molotov, CGrenade_Molotov );
void CGrenade_Molotov::Spawn( void )
{
SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE );
SetSolid( SOLID_BBOX );
SetCollisionGroup( COLLISION_GROUP_PROJECTILE );
SetModel( "models/weapons/w_molotov.mdl");
UTIL_SetSize(this, Vector( -6, -6, -2), Vector(6, 6, 2));
SetTouch( MolotovTouch );
SetThink( MolotovThink );
SetNextThink( gpGlobals->curtime + 0.1f );
m_flDamage = sk_plr_dmg_molotov.GetFloat();
m_DmgRadius = sk_molotov_radius.GetFloat();
m_takedamage = DAMAGE_YES;
m_iHealth = 1;
SetGravity( 1.0 );
SetFriction( 0.8 ); // Give a little bounce so can flatten
SetSequence( 1 );
m_pFireTrail = SmokeTrail::CreateSmokeTrail();
if( m_pFireTrail )
{
m_pFireTrail->m_SpawnRate = 48;
m_pFireTrail->m_ParticleLifetime = 1.0f;
m_pFireTrail->m_StartColor.Init( 0.2f, 0.2f, 0.2f );
m_pFireTrail->m_EndColor.Init( 0.0, 0.0, 0.0 );
m_pFireTrail->m_StartSize = 8;
m_pFireTrail->m_EndSize = 32;
m_pFireTrail->m_SpawnRadius = 4;
m_pFireTrail->m_MinSpeed = 8;
m_pFireTrail->m_MaxSpeed = 16;
m_pFireTrail->m_Opacity = 0.25f;
m_pFireTrail->SetLifetime( 20.0f );
m_pFireTrail->FollowEntity( this, "0" );
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input :
// Output :
//-----------------------------------------------------------------------------
void CGrenade_Molotov::MolotovTouch( CBaseEntity *pOther )
{
Detonate();
}
//-----------------------------------------------------------------------------
// Purpose:
//
//
//-----------------------------------------------------------------------------
void CGrenade_Molotov::Detonate( void )
{
SetModelName( NULL_STRING ); //invisible
AddSolidFlags( FSOLID_NOT_SOLID ); // intangible
m_takedamage = DAMAGE_NO;
trace_t trace;
UTIL_TraceLine ( GetAbsOrigin(), GetAbsOrigin() + Vector ( 0, 0, -128 ), MASK_SOLID_BRUSHONLY,
this, COLLISION_GROUP_NONE, &trace);
// Pull out of the wall a bit
if ( trace.fraction != 1.0 )
{
SetLocalOrigin( trace.endpos + (trace.plane.normal * (m_flDamage - 24) * 0.6) );
}
int contents = UTIL_PointContents ( GetAbsOrigin() );
if ( (contents & MASK_WATER) )
{
UTIL_Remove( this );
return;
}
EmitSound( "Grenade_Molotov.Detonate");
// Start some fires
int i;
QAngle vecTraceAngles;
Vector vecTraceDir;
trace_t firetrace;
for( i = 0 ; i < 16 ; i++ )
{
// build a little ray
vecTraceAngles[PITCH] = random->RandomFloat(45, 135);
vecTraceAngles[YAW] = random->RandomFloat(0, 360);
vecTraceAngles[ROLL] = 0.0f;
AngleVectors( vecTraceAngles, &vecTraceDir );
Vector vecStart, vecEnd;
vecStart = GetAbsOrigin() + ( trace.plane.normal * 128 );
vecEnd = vecStart + vecTraceDir * 512;
UTIL_TraceLine( vecStart, vecEnd, MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &firetrace );
Vector ofsDir = ( firetrace.endpos - GetAbsOrigin() );
float offset = VectorNormalize( ofsDir );
if ( offset > 128 )
offset = 128;
//Get our scale based on distance
float scale = 0.1f + ( 0.75f * ( 1.0f - ( offset / 128.0f ) ) );
float growth = 0.1f + ( 0.75f * ( offset / 128.0f ) );
if( firetrace.fraction != 1.0 )
{
FireSystem_StartFire( firetrace.endpos, scale, growth, 30.0f, (SF_FIRE_START_ON|SF_FIRE_SMOKELESS|SF_FIRE_NO_GLOW), (CBaseEntity*) this, FIRE_NATURAL );
}
}
// End Start some fires
CPASFilter filter2( trace.endpos );
te->Explosion( filter2, 0.0,
&trace.endpos,
g_sModelIndexFireball,
2.0,
15,
TE_EXPLFLAG_NOPARTICLES,
m_DmgRadius,
m_flDamage );
CBaseEntity *pOwner;
pOwner = GetOwnerEntity();
SetOwnerEntity( NULL ); // can't traceline attack owner if this is set
UTIL_DecalTrace( &trace, "Scorch" );
UTIL_ScreenShake( GetAbsOrigin(), 25.0, 150.0, 1.0, 750, SHAKE_START );
CSoundEnt::InsertSound ( SOUND_DANGER, GetAbsOrigin(), BASEGRENADE_EXPLOSION_VOLUME, 3.0 );
RadiusDamage( CTakeDamageInfo( this, pOwner, m_flDamage, DMG_BLAST ), GetAbsOrigin(), m_DmgRadius, CLASS_NONE, NULL );
AddEffects( EF_NODRAW );
SetAbsVelocity( vec3_origin );
SetNextThink( gpGlobals->curtime + 0.2 );
if ( m_pFireTrail )
{
UTIL_Remove( m_pFireTrail );
}
UTIL_Remove(this);
}
//------------------------------------------------------------------------------
// Purpose :
// Input :
// Output :
//------------------------------------------------------------------------------
void CGrenade_Molotov::MolotovThink( void )
{
// See if I can lose my owner (has dropper moved out of way?)
// Want do this so owner can throw the brickbat
if (GetOwnerEntity())
{
trace_t tr;
Vector vUpABit = GetAbsOrigin();
vUpABit.z += 5.0;
CBaseEntity* saveOwner = GetOwnerEntity();
SetOwnerEntity( NULL );
UTIL_TraceEntity( this, GetAbsOrigin(), vUpABit, MASK_SOLID, &tr );
if ( tr.startsolid || tr.fraction != 1.0 )
{
SetOwnerEntity( saveOwner );
}
}
SetNextThink( gpGlobals->curtime + 0.1f );
}
void CGrenade_Molotov::Precache( void )
{
BaseClass::Precache();
PrecacheModel("models/weapons/w_bb_bottle.mdl");
UTIL_PrecacheOther("_firesmoke");
PrecacheScriptSound( "Grenade_Molotov.Detonate" );
}
|