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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "basehlcombatweapon.h"
#include "gamerules.h"
#include "game.h"
#include "in_buttons.h"
#include "extinguisherjet.h"
#include "entitylist.h"
#include "fire.h"
#include "ar2_explosion.h"
#include "ndebugoverlay.h"
#include "engine/IEngineSound.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
ConVar fire_extinguisher_debug( "fire_extinguisher_debug", "0" );
ConVar fire_extinguisher_radius( "fire_extinguisher_radius", "45" );
ConVar fire_extinguisher_distance( "fire_extinguisher_distance", "200" );
ConVar fire_extinguisher_strength( "fire_extinguisher_strength", "0.97" ); //TODO: Stub for real numbers
ConVar fire_extinguisher_explode_radius( "fire_extinguisher_explode_radius", "256" );
ConVar fire_extinguisher_explode_strength( "fire_extinguisher_explode_strength", "0.3" ); //TODO: Stub for real numbers
#define EXTINGUISHER_AMMO_RATE 0.2
extern short g_sModelIndexFireball; // (in combatweapon.cpp) holds the index for the smoke cloud
class CWeaponExtinguisher: public CHLSelectFireMachineGun
{
DECLARE_DATADESC();
public:
DECLARE_CLASS( CWeaponExtinguisher, CHLSelectFireMachineGun );
DECLARE_SERVERCLASS();
CWeaponExtinguisher();
void Spawn( void );
void Precache( void );
void ItemPostFrame( void );
void Event_Killed( const CTakeDamageInfo &info );
void Equip( CBaseCombatCharacter *pOwner );
protected:
void StartJet( void );
void StopJet( void );
CExtinguisherJet *m_pJet;
};
IMPLEMENT_SERVERCLASS_ST(CWeaponExtinguisher, DT_WeaponExtinguisher)
END_SEND_TABLE()
LINK_ENTITY_TO_CLASS( weapon_extinguisher, CWeaponExtinguisher );
PRECACHE_WEAPON_REGISTER( weapon_extinguisher );
//---------------------------------------------------------
// Save/Restore
//---------------------------------------------------------
BEGIN_DATADESC( CWeaponExtinguisher )
DEFINE_FIELD( m_pJet, FIELD_CLASSPTR ),
END_DATADESC()
CWeaponExtinguisher::CWeaponExtinguisher( void )
{
m_pJet = NULL;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponExtinguisher::Precache( void )
{
BaseClass::Precache();
PrecacheScriptSound( "ExtinguisherCharger.Use" );
UTIL_PrecacheOther( "env_extinguisherjet" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponExtinguisher::Spawn( void )
{
BaseClass::Spawn();
m_takedamage = DAMAGE_YES;
m_iHealth = 25;//FIXME: Define
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pOwner -
//-----------------------------------------------------------------------------
void CWeaponExtinguisher::Equip( CBaseCombatCharacter *pOwner )
{
BaseClass::Equip( pOwner );
m_takedamage = DAMAGE_NO;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pInflictor -
// *pAttacker -
// flDamage -
// bitsDamageType -
//-----------------------------------------------------------------------------
void CWeaponExtinguisher::Event_Killed( const CTakeDamageInfo &info )
{
//TODO: Use a real effect
if ( AR2Explosion *pExplosion = AR2Explosion::CreateAR2Explosion( GetAbsOrigin() ) )
{
pExplosion->SetLifetime( 10 );
}
//TODO: Use a real effect
CPASFilter filter( GetAbsOrigin() );
te->Explosion( filter, 0.0,
&GetAbsOrigin(),
g_sModelIndexFireball,
2.0,
15,
TE_EXPLFLAG_NONE,
250,
100 );
//Put out fire in a radius
FireSystem_ExtinguishInRadius( GetAbsOrigin(), fire_extinguisher_explode_radius.GetInt(), fire_extinguisher_explode_strength.GetFloat() );
SetThink( SUB_Remove );
SetNextThink( gpGlobals->curtime + 0.1f );
}
//-----------------------------------------------------------------------------
// Purpose: Turn the jet effect and noise on
//-----------------------------------------------------------------------------
void CWeaponExtinguisher::StartJet( void )
{
//See if the jet needs to be created
if ( m_pJet == NULL )
{
m_pJet = (CExtinguisherJet *) CreateEntityByName( "env_extinguisherjet" );
if ( m_pJet == NULL )
{
Msg( "Unable to create jet for weapon_extinguisher!\n" );
return;
}
//Setup the jet
m_pJet->m_bEmit = false;
UTIL_SetOrigin( m_pJet, GetAbsOrigin() );
m_pJet->SetParent( this );
m_pJet->m_bUseMuzzlePoint = true;
m_pJet->m_bAutoExtinguish = false;
m_pJet->m_nLength = fire_extinguisher_distance.GetInt();
}
//Turn the jet on
if ( m_pJet != NULL )
{
m_pJet->TurnOn();
}
}
//-----------------------------------------------------------------------------
// Purpose: Turn the jet effect and noise off
//-----------------------------------------------------------------------------
void CWeaponExtinguisher::StopJet( void )
{
//Turn the jet off
if ( m_pJet != NULL )
{
m_pJet->TurnOff();
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponExtinguisher::ItemPostFrame( void )
{
CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
if ( pOwner == NULL )
return;
//Only shoot if we have ammo
if ( pOwner->GetAmmoCount(m_iSecondaryAmmoType) <= 0 )
{
StopJet();
return;
}
//See if we should try and extinguish fires
if ( pOwner->m_nButtons & IN_ATTACK )
{
//Drain ammo
if ( m_flNextPrimaryAttack < gpGlobals->curtime )
{
pOwner->RemoveAmmo( 1, m_iSecondaryAmmoType );
m_flNextPrimaryAttack = gpGlobals->curtime + EXTINGUISHER_AMMO_RATE;
}
//If we're just run out...
if ( pOwner->GetAmmoCount(m_iSecondaryAmmoType) <= 0 )
{
StopJet();
return;
}
//Turn the jet on
StartJet();
Vector vTestPos, vMuzzlePos;
Vector vForward, vRight, vUp;
pOwner->EyeVectors( &vForward, &vRight, &vUp );
vMuzzlePos = pOwner->Weapon_ShootPosition( );
//FIXME: Need to get the exact same muzzle point!
//FIXME: This needs to be adjusted so the server collision matches the visuals on the client
vMuzzlePos += vForward * 15.0f;
vMuzzlePos += vRight * 6.0f;
vMuzzlePos += vUp * -4.0f;
QAngle aTmp;
VectorAngles( vForward, aTmp );
aTmp[PITCH] += 10;
AngleVectors( aTmp, &vForward );
vTestPos = vMuzzlePos + ( vForward * fire_extinguisher_distance.GetInt() );
trace_t tr;
UTIL_TraceLine( vMuzzlePos, vTestPos, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr );
//Extinguish the fire where we hit
FireSystem_ExtinguishInRadius( tr.endpos, fire_extinguisher_radius.GetInt(), fire_extinguisher_strength.GetFloat() );
//Debug visualization
if ( fire_extinguisher_debug.GetInt() )
{
int radius = fire_extinguisher_radius.GetInt();
NDebugOverlay::Line( vMuzzlePos, tr.endpos, 0, 0, 128, false, 0.0f );
NDebugOverlay::Box( vMuzzlePos, Vector(-1, -1, -1), Vector(1, 1, 1), 0, 0, 128, false, 0.0f );
NDebugOverlay::Box( tr.endpos, Vector(-2, -2, -2), Vector(2, 2, 2), 0, 0, 128, false, 0.0f );
NDebugOverlay::Box( tr.endpos, Vector(-radius, -radius, -radius), Vector(radius, radius, radius), 0, 0, 255, false, 0.0f );
}
}
else
{
StopJet();
}
}
class CExtinguisherCharger : public CBaseToggle
{
public:
DECLARE_CLASS( CExtinguisherCharger, CBaseToggle );
void Spawn( void );
bool CreateVPhysics();
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
virtual int ObjectCaps( void ) { return (BaseClass::ObjectCaps() | FCAP_CONTINUOUS_USE) & ~FCAP_ACROSS_TRANSITION; }
protected:
float m_flNextCharge;
bool m_bSoundOn;
void TurnOff( void );
DECLARE_DATADESC();
};
LINK_ENTITY_TO_CLASS( func_extinguishercharger, CExtinguisherCharger );
BEGIN_DATADESC( CExtinguisherCharger )
DEFINE_FIELD( m_flNextCharge, FIELD_TIME),
DEFINE_FIELD( m_bSoundOn, FIELD_BOOLEAN ),
DEFINE_FUNCTION( TurnOff ),
END_DATADESC()
//-----------------------------------------------------------------------------
// Purpose: Spawn the object
//-----------------------------------------------------------------------------
void CExtinguisherCharger::Spawn( void )
{
Precache();
SetSolid( SOLID_BSP );
SetMoveType( MOVETYPE_PUSH );
SetModel( STRING( GetModelName() ) );
m_bSoundOn = false;
CreateVPhysics();
}
//-----------------------------------------------------------------------------
bool CExtinguisherCharger::CreateVPhysics()
{
VPhysicsInitStatic();
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pActivator -
// *pCaller -
// useType -
// value -
//-----------------------------------------------------------------------------
void CExtinguisherCharger::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
// Make sure that we have a caller
if ( pActivator == NULL )
return;
// If it's not a player, ignore
if ( pActivator->IsPlayer() == false )
return;
// Turn our sound on, if it's not already
if ( m_bSoundOn == false )
{
EmitSound( "ExtinguisherCharger.Use" );
m_bSoundOn = true;
}
SetNextThink( gpGlobals->curtime + 0.25 );
SetThink( TurnOff );
CBasePlayer *pPlayer = ToBasePlayer( pActivator );
if ( pPlayer )
{
//FIXME: Need a way to do this silently
pPlayer->GiveAmmo( 1, "extinguisher" );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CExtinguisherCharger::TurnOff( void )
{
//Turn the sound off
if ( m_bSoundOn )
{
StopSound( "ExtinguisherCharger.Use" );
m_bSoundOn = false;
}
}
|