aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/server/grenadethrown.cpp
blob: ed688027c821426ab198f280a1c2ed931ca6faf5 (plain) (blame)
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//
//=============================================================================//
/*

===== grenade_base.cpp ========================================================

  Base Handling for all the player's grenades

*/
#include "cbase.h"
#include "grenadethrown.h"
#include "ammodef.h"
#include "vstdlib/random.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

// Precaches a grenade and ensures clients know of it's "ammo"
void UTIL_PrecacheOtherGrenade( const char *szClassname )
{
	CBaseEntity *pEntity = CreateEntityByName( szClassname );
	if ( !pEntity )
	{
		Msg( "NULL Ent in UTIL_PrecacheOtherGrenade\n" );
		return;
	}
	
	CThrownGrenade *pGrenade = dynamic_cast<CThrownGrenade *>( pEntity );

	if (pGrenade)
	{
		pGrenade->Precache( );
	}

	UTIL_Remove( pEntity );
}

//-----------------------------------------------------------------------------
// Purpose: Setup basic values for Thrown grens
//-----------------------------------------------------------------------------
void CThrownGrenade::Spawn( void )
{
	// point sized, solid, bouncing
	SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE );
	SetSolid( SOLID_BBOX );
	UTIL_SetSize(this, vec3_origin, vec3_origin);

	// Movement
	SetGravity( UTIL_ScaleForGravity( 648 ) );
	SetFriction(0.6);
	QAngle angles;
	VectorAngles( GetAbsVelocity(), angles );
	SetLocalAngles( angles );
	QAngle vecAngVel( random->RandomFloat ( -100, -500 ), 0, 0 );
	SetLocalAngularVelocity( vecAngVel );
	
	SetTouch( &CThrownGrenade::BounceTouch );
}

//-----------------------------------------------------------------------------
// Purpose: Throw the grenade.
// Input  : vecOrigin - Starting position
//			vecVelocity - Starting velocity
//			flExplodeTime - Time at which to detonate
//-----------------------------------------------------------------------------
void CThrownGrenade::Thrown( Vector vecOrigin, Vector vecVelocity, float flExplodeTime )
{
	// Throw
	SetLocalOrigin( vecOrigin );
	SetAbsVelocity( vecVelocity );

	// Explode in 3 seconds
	SetThink( &CThrownGrenade::Detonate );
	SetNextThink( gpGlobals->curtime + flExplodeTime );
}