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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "cbase.h"
#include "baseprojectile.h"
BEGIN_DATADESC( CBaseProjectile )
DEFINE_FIELD( m_flDamage, FIELD_FLOAT ),
DEFINE_FIELD( m_iDamageType, FIELD_INTEGER ),
DEFINE_FIELD( m_flDamageScale, FIELD_FLOAT ),
DEFINE_FUNCTION( ProjectileTouch ),
DEFINE_THINKFUNC( FlyThink ),
END_DATADESC()
LINK_ENTITY_TO_CLASS( proj_base, CBaseProjectile );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseProjectile::Spawn( void )
{
Precache();
SetModel( STRING( GetModelName() ) );
SetSolid( SOLID_BBOX );
SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_CUSTOM );
AddFlag( FL_OBJECT );
UTIL_SetSize( this, -Vector( 1.0f, 1.0f, 1.0f ), Vector( 1.0f, 1.0f, 1.0f ) );
// Setup attributes.
SetGravity( 0.001f );
m_takedamage = DAMAGE_NO;
// Setup the touch and think functions.
SetTouch( &CBaseProjectile::ProjectileTouch );
SetThink( &CBaseProjectile::FlyThink );
SetNextThink( gpGlobals->curtime );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseProjectile::Precache( void )
{
BaseClass::Precache();
PrecacheModel( STRING( GetModelName() ) );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CBaseProjectile *CBaseProjectile::Create( baseprojectilecreate_t &pCreate )
{
CBaseProjectile *pProjectile = static_cast<CBaseProjectile*>( CBaseEntity::CreateNoSpawn( "proj_base", pCreate.vecOrigin, vec3_angle, pCreate.pOwner ) );
if ( !pProjectile )
return NULL;
pProjectile->SetModelName( pCreate.iszModel );
pProjectile->SetDamage( pCreate.flDamage );
pProjectile->SetDamageType( pCreate.iDamageType );
pProjectile->SetDamageScale( pCreate.flDamageScale );
pProjectile->SetAbsVelocity( pCreate.vecVelocity );
// Setup the initial angles.
QAngle angles;
VectorAngles( -pCreate.vecVelocity, angles );
pProjectile->SetAbsAngles( angles );
// Spawn & Activate
DispatchSpawn( pProjectile );
pProjectile->Activate();
return pProjectile;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
unsigned int CBaseProjectile::PhysicsSolidMaskForEntity( void ) const
{
return BaseClass::PhysicsSolidMaskForEntity() | CONTENTS_HITBOX;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseProjectile::ProjectileTouch( CBaseEntity *pOther )
{
// Verify a correct "other."
Assert( pOther );
if ( !pOther->IsSolid() || pOther->IsSolidFlagSet( FSOLID_VOLUME_CONTENTS ) )
return;
// Handle hitting skybox (disappear).
const trace_t *pTrace = &CBaseEntity::GetTouchTrace();
trace_t *pNewTrace = const_cast<trace_t*>( pTrace );
if( pTrace->surface.flags & SURF_SKY )
{
UTIL_Remove( this );
return;
}
CTakeDamageInfo info;
info.SetAttacker( GetOwnerEntity() );
info.SetInflictor( this );
info.SetDamage( GetDamage() );
info.SetDamageType( GetDamageType() );
CalculateMeleeDamageForce( &info, GetAbsVelocity(), GetAbsOrigin(), GetDamageScale() );
Vector dir;
AngleVectors( GetAbsAngles(), &dir );
pOther->DispatchTraceAttack( info, dir, pNewTrace );
ApplyMultiDamage();
UTIL_Remove( this );
}
//-----------------------------------------------------------------------------
// Purpose: Orient the projectile along its velocity
//-----------------------------------------------------------------------------
void CBaseProjectile::FlyThink( void )
{
QAngle angles;
VectorAngles( -(GetAbsVelocity()), angles );
SetAbsAngles( angles );
SetNextThink( gpGlobals->curtime + 0.1f );
}
|