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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "basehlcombatweapon.h"
#include "basecombatcharacter.h"
#include "player.h"
#include "soundent.h"
#include "te_particlesystem.h"
#include "ndebugoverlay.h"
#include "in_buttons.h"
#include "ai_basenpc.h"
#include "ai_memory.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define MAX_BURN_RADIUS 256
#define RADIUS_GROW_RATE 50.0 // units/sec
#define IMMOLATOR_TARGET_INVALID Vector( FLT_MAX, FLT_MAX, FLT_MAX )
class CWeaponImmolator : public CBaseHLCombatWeapon
{
public:
DECLARE_CLASS( CWeaponImmolator, CBaseHLCombatWeapon );
DECLARE_SERVERCLASS();
CWeaponImmolator( void );
void Precache( void );
void PrimaryAttack( void );
void ItemPostFrame( void );
int CapabilitiesGet( void ) { return bits_CAP_WEAPON_RANGE_ATTACK1; }
void ImmolationDamage( const CTakeDamageInfo &info, const Vector &vecSrcIn, float flRadius, int iClassIgnore );
virtual bool WeaponLOSCondition( const Vector &ownerPos, const Vector &targetPos, bool bSetConditions );
virtual int WeaponRangeAttack1Condition( float flDot, float flDist );
void Update();
void UpdateThink();
void StartImmolating();
void StopImmolating();
bool IsImmolating() { return m_flBurnRadius != 0.0; }
DECLARE_ACTTABLE();
DECLARE_DATADESC();
int m_beamIndex;
float m_flBurnRadius;
float m_flTimeLastUpdatedRadius;
Vector m_vecImmolatorTarget;
};
IMPLEMENT_SERVERCLASS_ST(CWeaponImmolator, DT_WeaponImmolator)
END_SEND_TABLE()
LINK_ENTITY_TO_CLASS( info_target_immolator, CPointEntity );
LINK_ENTITY_TO_CLASS( weapon_immolator, CWeaponImmolator );
PRECACHE_WEAPON_REGISTER( weapon_immolator );
BEGIN_DATADESC( CWeaponImmolator )
DEFINE_FIELD( m_beamIndex, FIELD_INTEGER ),
DEFINE_FIELD( m_flBurnRadius, FIELD_FLOAT ),
DEFINE_FIELD( m_flTimeLastUpdatedRadius, FIELD_TIME ),
DEFINE_FIELD( m_vecImmolatorTarget, FIELD_VECTOR ),
DEFINE_ENTITYFUNC( UpdateThink ),
END_DATADESC()
//-----------------------------------------------------------------------------
// Maps base activities to weapons-specific ones so our characters do the right things.
//-----------------------------------------------------------------------------
acttable_t CWeaponImmolator::m_acttable[] =
{
{ ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_SNIPER_RIFLE, true }
};
IMPLEMENT_ACTTABLE( CWeaponImmolator );
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CWeaponImmolator::CWeaponImmolator( void )
{
m_fMaxRange1 = 4096;
StopImmolating();
}
void CWeaponImmolator::StartImmolating()
{
// Start the radius really tiny because we use radius == 0.0 to
// determine whether the immolator is operating or not.
m_flBurnRadius = 0.1;
m_flTimeLastUpdatedRadius = gpGlobals->curtime;
SetThink( UpdateThink );
SetNextThink( gpGlobals->curtime );
CSoundEnt::InsertSound( SOUND_DANGER, m_vecImmolatorTarget, 256, 5.0, GetOwner() );
}
void CWeaponImmolator::StopImmolating()
{
m_flBurnRadius = 0.0;
SetThink( NULL );
m_vecImmolatorTarget= IMMOLATOR_TARGET_INVALID;
m_flNextPrimaryAttack = gpGlobals->curtime + 5.0;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponImmolator::Precache( void )
{
m_beamIndex = PrecacheModel( "sprites/bluelaser1.vmt" );
BaseClass::Precache();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponImmolator::PrimaryAttack( void )
{
WeaponSound( SINGLE );
if( !IsImmolating() )
{
StartImmolating();
}
}
//-----------------------------------------------------------------------------
// This weapon is said to have Line of Sight when it CAN'T see the target, but
// can see a place near the target than can.
//-----------------------------------------------------------------------------
bool CWeaponImmolator::WeaponLOSCondition( const Vector &ownerPos, const Vector &targetPos, bool bSetConditions )
{
CAI_BaseNPC* npcOwner = GetOwner()->MyNPCPointer();
if( !npcOwner )
{
return false;
}
if( IsImmolating() )
{
// Don't update while Immolating. This is a committed attack.
return false;
}
// Assume we won't find a target.
m_vecImmolatorTarget = targetPos;
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Weapon firing conditions
//-----------------------------------------------------------------------------
int CWeaponImmolator::WeaponRangeAttack1Condition( float flDot, float flDist )
{
if( m_flNextPrimaryAttack > gpGlobals->curtime )
{
// Too soon to attack!
return COND_NONE;
}
if( IsImmolating() )
{
// Once is enough!
return COND_NONE;
}
if( m_vecImmolatorTarget == IMMOLATOR_TARGET_INVALID )
{
// No target!
return COND_NONE;
}
if ( flDist > m_fMaxRange1 )
{
return COND_TOO_FAR_TO_ATTACK;
}
else if ( flDot < 0.5f ) // UNDONE: Why check this here? Isn't the AI checking this already?
{
return COND_NOT_FACING_ATTACK;
}
return COND_CAN_RANGE_ATTACK1;
}
void CWeaponImmolator::UpdateThink( void )
{
CBaseCombatCharacter *pOwner = GetOwner();
if( pOwner && !pOwner->IsAlive() )
{
StopImmolating();
return;
}
Update();
SetNextThink( gpGlobals->curtime + 0.05 );
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CWeaponImmolator::Update()
{
float flDuration = gpGlobals->curtime - m_flTimeLastUpdatedRadius;
if( flDuration != 0.0 )
{
m_flBurnRadius += RADIUS_GROW_RATE * flDuration;
}
// Clamp
m_flBurnRadius = MIN( m_flBurnRadius, MAX_BURN_RADIUS );
CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
Vector vecSrc;
Vector vecAiming;
if( pOwner )
{
vecSrc = pOwner->Weapon_ShootPosition( );
vecAiming = pOwner->GetAutoaimVector(AUTOAIM_2DEGREES);
}
else
{
CBaseCombatCharacter *pOwner = GetOwner();
vecSrc = pOwner->Weapon_ShootPosition( );
vecAiming = m_vecImmolatorTarget - vecSrc;
VectorNormalize( vecAiming );
}
trace_t tr;
UTIL_TraceLine( vecSrc, vecSrc + vecAiming * MAX_TRACE_LENGTH, MASK_SHOT, pOwner, COLLISION_GROUP_NONE, &tr );
int brightness;
brightness = 255 * (m_flBurnRadius/MAX_BURN_RADIUS);
UTIL_Beam( vecSrc,
tr.endpos,
m_beamIndex,
0, //halo index
0, //frame start
2.0f, //framerate
0.1f, //life
20, // width
1, // endwidth
0, // fadelength,
1, // noise
0, // red
255, // green
0, // blue,
brightness, // bright
100 // speed
);
if( tr.DidHitWorld() )
{
int beams;
for( beams = 0 ; beams < 5 ; beams++ )
{
Vector vecDest;
// Random unit vector
vecDest.x = random->RandomFloat( -1, 1 );
vecDest.y = random->RandomFloat( -1, 1 );
vecDest.z = random->RandomFloat( 0, 1 );
// Push out to radius dist.
vecDest = tr.endpos + vecDest * m_flBurnRadius;
UTIL_Beam( tr.endpos,
vecDest,
m_beamIndex,
0, //halo index
0, //frame start
2.0f, //framerate
0.15f, //life
20, // width
1.75, // endwidth
0.75, // fadelength,
15, // noise
0, // red
255, // green
0, // blue,
128, // bright
100 // speed
);
}
// Immolator starts to hurt a few seconds after the effect is seen
if( m_flBurnRadius > 64.0 )
{
ImmolationDamage( CTakeDamageInfo( this, this, 1, DMG_BURN ), tr.endpos, m_flBurnRadius, CLASS_NONE );
}
}
else
{
// The attack beam struck some kind of entity directly.
}
m_flTimeLastUpdatedRadius = gpGlobals->curtime;
if( m_flBurnRadius >= MAX_BURN_RADIUS )
{
StopImmolating();
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponImmolator::ItemPostFrame( void )
{
BaseClass::ItemPostFrame();
}
void CWeaponImmolator::ImmolationDamage( const CTakeDamageInfo &info, const Vector &vecSrcIn, float flRadius, int iClassIgnore )
{
CBaseEntity *pEntity = NULL;
trace_t tr;
Vector vecSpot;
Vector vecSrc = vecSrcIn;
// iterate on all entities in the vicinity.
for ( CEntitySphereQuery sphere( vecSrc, flRadius ); pEntity = sphere.GetCurrentEntity(); sphere.NextEntity() )
{
CBaseCombatCharacter *pBCC;
pBCC = pEntity->MyCombatCharacterPointer();
if ( pBCC && !pBCC->IsOnFire() )
{
// UNDONE: this should check a damage mask, not an ignore
if ( iClassIgnore != CLASS_NONE && pEntity->Classify() == iClassIgnore )
{
continue;
}
if( pEntity == GetOwner() )
{
continue;
}
pBCC->Ignite( random->RandomFloat( 15, 20 ) );
}
}
}
|